1 /* Subroutines shared by all languages that are variants of C.
2 Copyright (C) 1992-2016 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"
30 #include "gimple-expr.h"
32 #include "stringpool.h"
34 #include "diagnostic.h"
36 #include "stor-layout.h"
40 #include "trans-mem.h"
42 #include "common/common-target.h"
43 #include "langhooks.h"
44 #include "tree-inline.h"
46 #include "tree-iterator.h"
49 #include "substring-locations.h"
50 #include "spellcheck.h"
52 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;
81 tree char16_type_node;
82 tree char32_type_node;
85 tree double_type_node;
86 tree long_double_type_node;
88 tree complex_integer_type_node;
89 tree complex_float_type_node;
90 tree complex_double_type_node;
91 tree complex_long_double_type_node;
93 tree dfloat32_type_node;
94 tree dfloat64_type_node;
95 tree_dfloat128_type_node;
100 tree intDI_type_node;
101 tree intTI_type_node;
103 tree unsigned_intQI_type_node;
104 tree unsigned_intHI_type_node;
105 tree unsigned_intSI_type_node;
106 tree unsigned_intDI_type_node;
107 tree unsigned_intTI_type_node;
109 tree widest_integer_literal_type_node;
110 tree widest_unsigned_literal_type_node;
112 Nodes for types `void *' and `const void *'.
114 tree ptr_type_node, const_ptr_type_node;
116 Nodes for types `char *' and `const char *'.
118 tree string_type_node, const_string_type_node;
120 Type `char[SOMENUMBER]'.
121 Used when an array of char is needed and the size is irrelevant.
123 tree char_array_type_node;
125 Type `wchar_t[SOMENUMBER]' or something like it.
126 Used when a wide string literal is created.
128 tree wchar_array_type_node;
130 Type `char16_t[SOMENUMBER]' or something like it.
131 Used when a UTF-16 string literal is created.
133 tree char16_array_type_node;
135 Type `char32_t[SOMENUMBER]' or something like it.
136 Used when a UTF-32 string literal is created.
138 tree char32_array_type_node;
140 Type `int ()' -- used for implicit declaration of functions.
142 tree default_function_type;
144 A VOID_TYPE node, packaged in a TREE_LIST.
148 The lazily created VAR_DECLs for __FUNCTION__, __PRETTY_FUNCTION__,
149 and __func__. (C doesn't generate __FUNCTION__ and__PRETTY_FUNCTION__
150 VAR_DECLS, but C++ does.)
152 tree function_name_decl_node;
153 tree pretty_function_name_decl_node;
154 tree c99_function_name_decl_node;
156 Stack of nested function name VAR_DECLs.
158 tree saved_function_name_decls;
162 tree c_global_trees
[CTI_MAX
];
164 /* Switches common to the C front ends. */
166 /* Nonzero means don't output line number information. */
168 char flag_no_line_commands
;
170 /* Nonzero causes -E output not to be done, but directives such as
171 #define that have side effects are still obeyed. */
175 /* Nonzero means dump macros in some fashion. */
177 char flag_dump_macros
;
179 /* Nonzero means pass #include lines through to the output. */
181 char flag_dump_includes
;
183 /* Nonzero means process PCH files while preprocessing. */
185 bool flag_pch_preprocess
;
187 /* The file name to which we should write a precompiled header, or
188 NULL if no header will be written in this compile. */
190 const char *pch_file
;
192 /* Nonzero if an ISO standard was selected. It rejects macros in the
196 /* C/ObjC language option variables. */
199 /* Nonzero means allow type mismatches in conditional expressions;
200 just make their values `void'. */
202 int flag_cond_mismatch
;
204 /* Nonzero means enable C89 Amendment 1 features. */
208 /* Nonzero means use the ISO C99 (or C11) dialect of C. */
212 /* Nonzero means use the ISO C11 dialect of C. */
216 /* Nonzero means that we have builtin functions, and main is an int. */
221 /* ObjC language option variables. */
224 /* Tells the compiler that this is a special run. Do not perform any
225 compiling, instead we are to test some platform dependent features
226 and output a C header file with appropriate definitions. */
228 int print_struct_values
;
230 /* Tells the compiler what is the constant string class for ObjC. */
232 const char *constant_string_class_name
;
235 /* C++ language option variables. */
237 /* The reference version of the ABI for -Wabi. */
239 int warn_abi_version
= -1;
241 /* Nonzero means generate separate instantiation control files and
242 juggle them at link time. */
244 int flag_use_repository
;
246 /* The C++ dialect being used. Default set in c_common_post_options. */
248 enum cxx_dialect cxx_dialect
= cxx_unset
;
250 /* Maximum template instantiation depth. This limit exists to limit the
251 time it takes to notice excessively recursive template instantiations.
253 The default is lower than the 1024 recommended by the C++0x standard
254 because G++ runs out of stack before 1024 with highly recursive template
255 argument deduction substitution (g++.dg/cpp0x/enum11.C). */
257 int max_tinst_depth
= 900;
259 /* The elements of `ridpointers' are identifier nodes for the reserved
260 type names and storage classes. It is indexed by a RID_... value. */
263 tree (*make_fname_decl
) (location_t
, tree
, int);
265 /* Nonzero means don't warn about problems that occur when the code is
267 int c_inhibit_evaluation_warnings
;
269 /* Whether we are building a boolean conversion inside
270 convert_for_assignment, or some other late binary operation. If
271 build_binary_op is called for C (from code shared by C and C++) in
272 this case, then the operands have already been folded and the
273 result will not be folded again, so C_MAYBE_CONST_EXPR should not
275 bool in_late_binary_op
;
277 /* Whether lexing has been completed, so subsequent preprocessor
278 errors should use the compiler's input_location. */
279 bool done_lexing
= false;
281 /* Information about how a function name is generated. */
284 tree
*const decl
; /* pointer to the VAR_DECL. */
285 const unsigned rid
; /* RID number for the identifier. */
286 const int pretty
; /* How pretty is it? */
289 /* The three ways of getting then name of the current function. */
291 const struct fname_var_t fname_vars
[] =
293 /* C99 compliant __func__, must be first. */
294 {&c99_function_name_decl_node
, RID_C99_FUNCTION_NAME
, 0},
295 /* GCC __FUNCTION__ compliant. */
296 {&function_name_decl_node
, RID_FUNCTION_NAME
, 0},
297 /* GCC __PRETTY_FUNCTION__ compliant. */
298 {&pretty_function_name_decl_node
, RID_PRETTY_FUNCTION_NAME
, 1},
302 /* Global visibility options. */
303 struct visibility_flags visibility_options
;
305 static tree
check_case_value (location_t
, tree
);
306 static bool check_case_bounds (location_t
, tree
, tree
, tree
*, tree
*,
309 static tree
handle_packed_attribute (tree
*, tree
, tree
, int, bool *);
310 static tree
handle_nocommon_attribute (tree
*, tree
, tree
, int, bool *);
311 static tree
handle_common_attribute (tree
*, tree
, tree
, int, bool *);
312 static tree
handle_noreturn_attribute (tree
*, tree
, tree
, int, bool *);
313 static tree
handle_hot_attribute (tree
*, tree
, tree
, int, bool *);
314 static tree
handle_cold_attribute (tree
*, tree
, tree
, int, bool *);
315 static tree
handle_no_sanitize_address_attribute (tree
*, tree
, tree
,
317 static tree
handle_no_address_safety_analysis_attribute (tree
*, tree
, tree
,
319 static tree
handle_no_sanitize_undefined_attribute (tree
*, tree
, tree
, int,
321 static tree
handle_stack_protect_attribute (tree
*, tree
, tree
, int, bool *);
322 static tree
handle_noinline_attribute (tree
*, tree
, tree
, int, bool *);
323 static tree
handle_noclone_attribute (tree
*, tree
, tree
, int, bool *);
324 static tree
handle_noicf_attribute (tree
*, tree
, tree
, int, bool *);
325 static tree
handle_leaf_attribute (tree
*, tree
, tree
, int, bool *);
326 static tree
handle_always_inline_attribute (tree
*, tree
, tree
, int,
328 static tree
handle_gnu_inline_attribute (tree
*, tree
, tree
, int, bool *);
329 static tree
handle_artificial_attribute (tree
*, tree
, tree
, int, bool *);
330 static tree
handle_flatten_attribute (tree
*, tree
, tree
, int, bool *);
331 static tree
handle_error_attribute (tree
*, tree
, tree
, int, bool *);
332 static tree
handle_used_attribute (tree
*, tree
, tree
, int, bool *);
333 static tree
handle_externally_visible_attribute (tree
*, tree
, tree
, int,
335 static tree
handle_no_reorder_attribute (tree
*, tree
, tree
, int,
337 static tree
handle_const_attribute (tree
*, tree
, tree
, int, bool *);
338 static tree
handle_transparent_union_attribute (tree
*, tree
, tree
,
340 static tree
handle_scalar_storage_order_attribute (tree
*, tree
, tree
,
342 static tree
handle_constructor_attribute (tree
*, tree
, tree
, int, bool *);
343 static tree
handle_destructor_attribute (tree
*, tree
, tree
, int, bool *);
344 static tree
handle_mode_attribute (tree
*, tree
, tree
, int, bool *);
345 static tree
handle_section_attribute (tree
*, tree
, tree
, int, bool *);
346 static tree
handle_aligned_attribute (tree
*, tree
, tree
, int, bool *);
347 static tree
handle_weak_attribute (tree
*, tree
, tree
, int, bool *) ;
348 static tree
handle_noplt_attribute (tree
*, tree
, tree
, int, bool *) ;
349 static tree
handle_alias_ifunc_attribute (bool, tree
*, tree
, tree
, bool *);
350 static tree
handle_ifunc_attribute (tree
*, tree
, tree
, int, bool *);
351 static tree
handle_alias_attribute (tree
*, tree
, tree
, int, bool *);
352 static tree
handle_weakref_attribute (tree
*, tree
, tree
, int, bool *) ;
353 static tree
handle_visibility_attribute (tree
*, tree
, tree
, int,
355 static tree
handle_tls_model_attribute (tree
*, tree
, tree
, int,
357 static tree
handle_no_instrument_function_attribute (tree
*, tree
,
359 static tree
handle_no_profile_instrument_function_attribute (tree
*, tree
,
361 static tree
handle_malloc_attribute (tree
*, tree
, tree
, int, bool *);
362 static tree
handle_returns_twice_attribute (tree
*, tree
, tree
, int, bool *);
363 static tree
handle_no_limit_stack_attribute (tree
*, tree
, tree
, int,
365 static tree
handle_pure_attribute (tree
*, tree
, tree
, int, bool *);
366 static tree
handle_tm_attribute (tree
*, tree
, tree
, int, bool *);
367 static tree
handle_tm_wrap_attribute (tree
*, tree
, tree
, int, bool *);
368 static tree
handle_novops_attribute (tree
*, tree
, tree
, int, bool *);
369 static tree
handle_deprecated_attribute (tree
*, tree
, tree
, int,
371 static tree
handle_vector_size_attribute (tree
*, tree
, tree
, int,
373 static tree
handle_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
374 static tree
handle_nothrow_attribute (tree
*, tree
, tree
, int, bool *);
375 static tree
handle_cleanup_attribute (tree
*, tree
, tree
, int, bool *);
376 static tree
handle_warn_unused_result_attribute (tree
*, tree
, tree
, int,
378 static tree
handle_sentinel_attribute (tree
*, tree
, tree
, int, bool *);
379 static tree
handle_type_generic_attribute (tree
*, tree
, tree
, int, bool *);
380 static tree
handle_alloc_size_attribute (tree
*, tree
, tree
, int, bool *);
381 static tree
handle_alloc_align_attribute (tree
*, tree
, tree
, int, bool *);
382 static tree
handle_assume_aligned_attribute (tree
*, tree
, tree
, int, bool *);
383 static tree
handle_target_attribute (tree
*, tree
, tree
, int, bool *);
384 static tree
handle_target_clones_attribute (tree
*, tree
, tree
, int, bool *);
385 static tree
handle_optimize_attribute (tree
*, tree
, tree
, int, bool *);
386 static tree
ignore_attribute (tree
*, tree
, tree
, int, bool *);
387 static tree
handle_no_split_stack_attribute (tree
*, tree
, tree
, int, bool *);
388 static tree
handle_fnspec_attribute (tree
*, tree
, tree
, int, bool *);
389 static tree
handle_warn_unused_attribute (tree
*, tree
, tree
, int, bool *);
390 static tree
handle_returns_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
391 static tree
handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int,
393 static tree
handle_simd_attribute (tree
*, tree
, tree
, int, bool *);
394 static tree
handle_omp_declare_target_attribute (tree
*, tree
, tree
, int,
396 static tree
handle_designated_init_attribute (tree
*, tree
, tree
, int, bool *);
397 static tree
handle_bnd_variable_size_attribute (tree
*, tree
, tree
, int, bool *);
398 static tree
handle_bnd_legacy (tree
*, tree
, tree
, int, bool *);
399 static tree
handle_bnd_instrument (tree
*, tree
, tree
, int, bool *);
400 static tree
handle_fallthrough_attribute (tree
*, tree
, tree
, int, bool *);
402 static void check_nonnull_arg (void *, tree
, unsigned HOST_WIDE_INT
);
403 static bool nonnull_check_p (tree
, unsigned HOST_WIDE_INT
);
404 static bool get_nonnull_operand (tree
, unsigned HOST_WIDE_INT
*);
405 static int resort_field_decl_cmp (const void *, const void *);
407 /* Reserved words. The third field is a mask: keywords are disabled
408 if they match the mask.
411 C --std=c89: D_C99 | D_CXXONLY | D_OBJC | D_CXX_OBJC
412 C --std=c99: D_CXXONLY | D_OBJC
413 ObjC is like C except that D_OBJC and D_CXX_OBJC are not set
414 C++ --std=c++98: D_CONLY | D_CXX11 | D_OBJC
415 C++ --std=c++11: D_CONLY | D_OBJC
416 ObjC++ is like C++ except that D_OBJC is not set
418 If -fno-asm is used, D_ASM is added to the mask. If
419 -fno-gnu-keywords is used, D_EXT is added. If -fno-asm and C in
420 C89 mode, D_EXT89 is added for both -fno-asm and -fno-gnu-keywords.
421 In C with -Wc++-compat, we warn if D_CXXWARN is set.
423 Note the complication of the D_CXX_OBJC keywords. These are
424 reserved words such as 'class'. In C++, 'class' is a reserved
425 word. In Objective-C++ it is too. In Objective-C, it is a
426 reserved word too, but only if it follows an '@' sign.
428 const struct c_common_resword c_common_reswords
[] =
430 { "_Alignas", RID_ALIGNAS
, D_CONLY
},
431 { "_Alignof", RID_ALIGNOF
, D_CONLY
},
432 { "_Atomic", RID_ATOMIC
, D_CONLY
},
433 { "_Bool", RID_BOOL
, D_CONLY
},
434 { "_Complex", RID_COMPLEX
, 0 },
435 { "_Cilk_spawn", RID_CILK_SPAWN
, 0 },
436 { "_Cilk_sync", RID_CILK_SYNC
, 0 },
437 { "_Cilk_for", RID_CILK_FOR
, 0 },
438 { "_Imaginary", RID_IMAGINARY
, D_CONLY
},
439 { "_Float16", RID_FLOAT16
, D_CONLY
},
440 { "_Float32", RID_FLOAT32
, D_CONLY
},
441 { "_Float64", RID_FLOAT64
, D_CONLY
},
442 { "_Float128", RID_FLOAT128
, D_CONLY
},
443 { "_Float32x", RID_FLOAT32X
, D_CONLY
},
444 { "_Float64x", RID_FLOAT64X
, D_CONLY
},
445 { "_Float128x", RID_FLOAT128X
, D_CONLY
},
446 { "_Decimal32", RID_DFLOAT32
, D_CONLY
| D_EXT
},
447 { "_Decimal64", RID_DFLOAT64
, D_CONLY
| D_EXT
},
448 { "_Decimal128", RID_DFLOAT128
, D_CONLY
| D_EXT
},
449 { "_Fract", RID_FRACT
, D_CONLY
| D_EXT
},
450 { "_Accum", RID_ACCUM
, D_CONLY
| D_EXT
},
451 { "_Sat", RID_SAT
, D_CONLY
| D_EXT
},
452 { "_Static_assert", RID_STATIC_ASSERT
, D_CONLY
},
453 { "_Noreturn", RID_NORETURN
, D_CONLY
},
454 { "_Generic", RID_GENERIC
, D_CONLY
},
455 { "_Thread_local", RID_THREAD
, D_CONLY
},
456 { "__FUNCTION__", RID_FUNCTION_NAME
, 0 },
457 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME
, 0 },
458 { "__alignof", RID_ALIGNOF
, 0 },
459 { "__alignof__", RID_ALIGNOF
, 0 },
460 { "__asm", RID_ASM
, 0 },
461 { "__asm__", RID_ASM
, 0 },
462 { "__attribute", RID_ATTRIBUTE
, 0 },
463 { "__attribute__", RID_ATTRIBUTE
, 0 },
464 { "__auto_type", RID_AUTO_TYPE
, D_CONLY
},
465 { "__bases", RID_BASES
, D_CXXONLY
},
466 { "__builtin_addressof", RID_ADDRESSOF
, D_CXXONLY
},
467 { "__builtin_call_with_static_chain",
468 RID_BUILTIN_CALL_WITH_STATIC_CHAIN
, D_CONLY
},
469 { "__builtin_choose_expr", RID_CHOOSE_EXPR
, D_CONLY
},
470 { "__builtin_complex", RID_BUILTIN_COMPLEX
, D_CONLY
},
471 { "__builtin_shuffle", RID_BUILTIN_SHUFFLE
, 0 },
472 { "__builtin_offsetof", RID_OFFSETOF
, 0 },
473 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P
, D_CONLY
},
474 { "__builtin_va_arg", RID_VA_ARG
, 0 },
475 { "__complex", RID_COMPLEX
, 0 },
476 { "__complex__", RID_COMPLEX
, 0 },
477 { "__const", RID_CONST
, 0 },
478 { "__const__", RID_CONST
, 0 },
479 { "__decltype", RID_DECLTYPE
, D_CXXONLY
},
480 { "__direct_bases", RID_DIRECT_BASES
, D_CXXONLY
},
481 { "__extension__", RID_EXTENSION
, 0 },
482 { "__func__", RID_C99_FUNCTION_NAME
, 0 },
483 { "__has_nothrow_assign", RID_HAS_NOTHROW_ASSIGN
, D_CXXONLY
},
484 { "__has_nothrow_constructor", RID_HAS_NOTHROW_CONSTRUCTOR
, D_CXXONLY
},
485 { "__has_nothrow_copy", RID_HAS_NOTHROW_COPY
, D_CXXONLY
},
486 { "__has_trivial_assign", RID_HAS_TRIVIAL_ASSIGN
, D_CXXONLY
},
487 { "__has_trivial_constructor", RID_HAS_TRIVIAL_CONSTRUCTOR
, D_CXXONLY
},
488 { "__has_trivial_copy", RID_HAS_TRIVIAL_COPY
, D_CXXONLY
},
489 { "__has_trivial_destructor", RID_HAS_TRIVIAL_DESTRUCTOR
, D_CXXONLY
},
490 { "__has_unique_object_representations", RID_HAS_UNIQUE_OBJ_REPRESENTATIONS
,
492 { "__has_virtual_destructor", RID_HAS_VIRTUAL_DESTRUCTOR
, D_CXXONLY
},
493 { "__imag", RID_IMAGPART
, 0 },
494 { "__imag__", RID_IMAGPART
, 0 },
495 { "__inline", RID_INLINE
, 0 },
496 { "__inline__", RID_INLINE
, 0 },
497 { "__is_abstract", RID_IS_ABSTRACT
, D_CXXONLY
},
498 { "__is_base_of", RID_IS_BASE_OF
, D_CXXONLY
},
499 { "__is_class", RID_IS_CLASS
, D_CXXONLY
},
500 { "__is_empty", RID_IS_EMPTY
, D_CXXONLY
},
501 { "__is_enum", RID_IS_ENUM
, D_CXXONLY
},
502 { "__is_final", RID_IS_FINAL
, D_CXXONLY
},
503 { "__is_literal_type", RID_IS_LITERAL_TYPE
, D_CXXONLY
},
504 { "__is_pod", RID_IS_POD
, D_CXXONLY
},
505 { "__is_polymorphic", RID_IS_POLYMORPHIC
, D_CXXONLY
},
506 { "__is_same_as", RID_IS_SAME_AS
, D_CXXONLY
},
507 { "__is_standard_layout", RID_IS_STD_LAYOUT
, D_CXXONLY
},
508 { "__is_trivial", RID_IS_TRIVIAL
, D_CXXONLY
},
509 { "__is_trivially_assignable", RID_IS_TRIVIALLY_ASSIGNABLE
, D_CXXONLY
},
510 { "__is_trivially_constructible", RID_IS_TRIVIALLY_CONSTRUCTIBLE
, D_CXXONLY
},
511 { "__is_trivially_copyable", RID_IS_TRIVIALLY_COPYABLE
, D_CXXONLY
},
512 { "__is_union", RID_IS_UNION
, D_CXXONLY
},
513 { "__label__", RID_LABEL
, 0 },
514 { "__null", RID_NULL
, 0 },
515 { "__real", RID_REALPART
, 0 },
516 { "__real__", RID_REALPART
, 0 },
517 { "__restrict", RID_RESTRICT
, 0 },
518 { "__restrict__", RID_RESTRICT
, 0 },
519 { "__signed", RID_SIGNED
, 0 },
520 { "__signed__", RID_SIGNED
, 0 },
521 { "__thread", RID_THREAD
, 0 },
522 { "__transaction_atomic", RID_TRANSACTION_ATOMIC
, 0 },
523 { "__transaction_relaxed", RID_TRANSACTION_RELAXED
, 0 },
524 { "__transaction_cancel", RID_TRANSACTION_CANCEL
, 0 },
525 { "__typeof", RID_TYPEOF
, 0 },
526 { "__typeof__", RID_TYPEOF
, 0 },
527 { "__underlying_type", RID_UNDERLYING_TYPE
, D_CXXONLY
},
528 { "__volatile", RID_VOLATILE
, 0 },
529 { "__volatile__", RID_VOLATILE
, 0 },
530 { "alignas", RID_ALIGNAS
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
531 { "alignof", RID_ALIGNOF
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
532 { "asm", RID_ASM
, D_ASM
},
533 { "auto", RID_AUTO
, 0 },
534 { "bool", RID_BOOL
, D_CXXONLY
| D_CXXWARN
},
535 { "break", RID_BREAK
, 0 },
536 { "case", RID_CASE
, 0 },
537 { "catch", RID_CATCH
, D_CXX_OBJC
| D_CXXWARN
},
538 { "char", RID_CHAR
, 0 },
539 { "char16_t", RID_CHAR16
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
540 { "char32_t", RID_CHAR32
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
541 { "class", RID_CLASS
, D_CXX_OBJC
| D_CXXWARN
},
542 { "const", RID_CONST
, 0 },
543 { "constexpr", RID_CONSTEXPR
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
544 { "const_cast", RID_CONSTCAST
, D_CXXONLY
| D_CXXWARN
},
545 { "continue", RID_CONTINUE
, 0 },
546 { "decltype", RID_DECLTYPE
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
547 { "default", RID_DEFAULT
, 0 },
548 { "delete", RID_DELETE
, D_CXXONLY
| D_CXXWARN
},
550 { "double", RID_DOUBLE
, 0 },
551 { "dynamic_cast", RID_DYNCAST
, D_CXXONLY
| D_CXXWARN
},
552 { "else", RID_ELSE
, 0 },
553 { "enum", RID_ENUM
, 0 },
554 { "explicit", RID_EXPLICIT
, D_CXXONLY
| D_CXXWARN
},
555 { "export", RID_EXPORT
, D_CXXONLY
| D_CXXWARN
},
556 { "extern", RID_EXTERN
, 0 },
557 { "false", RID_FALSE
, D_CXXONLY
| D_CXXWARN
},
558 { "float", RID_FLOAT
, 0 },
559 { "for", RID_FOR
, 0 },
560 { "friend", RID_FRIEND
, D_CXXONLY
| D_CXXWARN
},
561 { "goto", RID_GOTO
, 0 },
563 { "inline", RID_INLINE
, D_EXT89
},
564 { "int", RID_INT
, 0 },
565 { "long", RID_LONG
, 0 },
566 { "mutable", RID_MUTABLE
, D_CXXONLY
| D_CXXWARN
},
567 { "namespace", RID_NAMESPACE
, D_CXXONLY
| D_CXXWARN
},
568 { "new", RID_NEW
, D_CXXONLY
| D_CXXWARN
},
569 { "noexcept", RID_NOEXCEPT
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
570 { "nullptr", RID_NULLPTR
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
571 { "operator", RID_OPERATOR
, D_CXXONLY
| D_CXXWARN
},
572 { "private", RID_PRIVATE
, D_CXX_OBJC
| D_CXXWARN
},
573 { "protected", RID_PROTECTED
, D_CXX_OBJC
| D_CXXWARN
},
574 { "public", RID_PUBLIC
, D_CXX_OBJC
| D_CXXWARN
},
575 { "register", RID_REGISTER
, 0 },
576 { "reinterpret_cast", RID_REINTCAST
, D_CXXONLY
| D_CXXWARN
},
577 { "restrict", RID_RESTRICT
, D_CONLY
| D_C99
},
578 { "return", RID_RETURN
, 0 },
579 { "short", RID_SHORT
, 0 },
580 { "signed", RID_SIGNED
, 0 },
581 { "sizeof", RID_SIZEOF
, 0 },
582 { "static", RID_STATIC
, 0 },
583 { "static_assert", RID_STATIC_ASSERT
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
584 { "static_cast", RID_STATCAST
, D_CXXONLY
| D_CXXWARN
},
585 { "struct", RID_STRUCT
, 0 },
586 { "switch", RID_SWITCH
, 0 },
587 { "template", RID_TEMPLATE
, D_CXXONLY
| D_CXXWARN
},
588 { "this", RID_THIS
, D_CXXONLY
| D_CXXWARN
},
589 { "thread_local", RID_THREAD
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
590 { "throw", RID_THROW
, D_CXX_OBJC
| D_CXXWARN
},
591 { "true", RID_TRUE
, D_CXXONLY
| D_CXXWARN
},
592 { "try", RID_TRY
, D_CXX_OBJC
| D_CXXWARN
},
593 { "typedef", RID_TYPEDEF
, 0 },
594 { "typename", RID_TYPENAME
, D_CXXONLY
| D_CXXWARN
},
595 { "typeid", RID_TYPEID
, D_CXXONLY
| D_CXXWARN
},
596 { "typeof", RID_TYPEOF
, D_ASM
| D_EXT
},
597 { "union", RID_UNION
, 0 },
598 { "unsigned", RID_UNSIGNED
, 0 },
599 { "using", RID_USING
, D_CXXONLY
| D_CXXWARN
},
600 { "virtual", RID_VIRTUAL
, D_CXXONLY
| D_CXXWARN
},
601 { "void", RID_VOID
, 0 },
602 { "volatile", RID_VOLATILE
, 0 },
603 { "wchar_t", RID_WCHAR
, D_CXXONLY
},
604 { "while", RID_WHILE
, 0 },
606 /* C++ transactional memory. */
607 { "synchronized", RID_SYNCHRONIZED
, D_CXX_OBJC
| D_TRANSMEM
},
608 { "atomic_noexcept", RID_ATOMIC_NOEXCEPT
, D_CXXONLY
| D_TRANSMEM
},
609 { "atomic_cancel", RID_ATOMIC_CANCEL
, D_CXXONLY
| D_TRANSMEM
},
610 { "atomic_commit", RID_TRANSACTION_ATOMIC
, D_CXXONLY
| D_TRANSMEM
},
612 /* Concepts-related keywords */
613 { "concept", RID_CONCEPT
, D_CXX_CONCEPTS_FLAGS
| D_CXXWARN
},
614 { "requires", RID_REQUIRES
, D_CXX_CONCEPTS_FLAGS
| D_CXXWARN
},
616 /* These Objective-C keywords are recognized only immediately after
618 { "compatibility_alias", RID_AT_ALIAS
, D_OBJC
},
619 { "defs", RID_AT_DEFS
, D_OBJC
},
620 { "encode", RID_AT_ENCODE
, D_OBJC
},
621 { "end", RID_AT_END
, D_OBJC
},
622 { "implementation", RID_AT_IMPLEMENTATION
, D_OBJC
},
623 { "interface", RID_AT_INTERFACE
, D_OBJC
},
624 { "protocol", RID_AT_PROTOCOL
, D_OBJC
},
625 { "selector", RID_AT_SELECTOR
, D_OBJC
},
626 { "finally", RID_AT_FINALLY
, D_OBJC
},
627 { "optional", RID_AT_OPTIONAL
, D_OBJC
},
628 { "required", RID_AT_REQUIRED
, D_OBJC
},
629 { "property", RID_AT_PROPERTY
, D_OBJC
},
630 { "package", RID_AT_PACKAGE
, D_OBJC
},
631 { "synthesize", RID_AT_SYNTHESIZE
, D_OBJC
},
632 { "dynamic", RID_AT_DYNAMIC
, D_OBJC
},
633 /* These are recognized only in protocol-qualifier context
635 { "bycopy", RID_BYCOPY
, D_OBJC
},
636 { "byref", RID_BYREF
, D_OBJC
},
637 { "in", RID_IN
, D_OBJC
},
638 { "inout", RID_INOUT
, D_OBJC
},
639 { "oneway", RID_ONEWAY
, D_OBJC
},
640 { "out", RID_OUT
, D_OBJC
},
641 /* These are recognized inside a property attribute list */
642 { "assign", RID_ASSIGN
, D_OBJC
},
643 { "copy", RID_COPY
, D_OBJC
},
644 { "getter", RID_GETTER
, D_OBJC
},
645 { "nonatomic", RID_NONATOMIC
, D_OBJC
},
646 { "readonly", RID_READONLY
, D_OBJC
},
647 { "readwrite", RID_READWRITE
, D_OBJC
},
648 { "retain", RID_RETAIN
, D_OBJC
},
649 { "setter", RID_SETTER
, D_OBJC
},
652 const unsigned int num_c_common_reswords
=
653 sizeof c_common_reswords
/ sizeof (struct c_common_resword
);
655 /* Table of machine-independent attributes common to all C-like languages.
657 All attributes referencing arguments should be additionally processed
658 in chkp_copy_function_type_adding_bounds for correct instrumentation
659 by Pointer Bounds Checker.
660 Current list of processed common attributes: nonnull. */
661 const struct attribute_spec c_common_attribute_table
[] =
663 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
664 affects_type_identity } */
665 { "packed", 0, 0, false, false, false,
666 handle_packed_attribute
, false},
667 { "nocommon", 0, 0, true, false, false,
668 handle_nocommon_attribute
, false},
669 { "common", 0, 0, true, false, false,
670 handle_common_attribute
, false },
671 /* FIXME: logically, noreturn attributes should be listed as
672 "false, true, true" and apply to function types. But implementing this
673 would require all the places in the compiler that use TREE_THIS_VOLATILE
674 on a decl to identify non-returning functions to be located and fixed
675 to check the function type instead. */
676 { "noreturn", 0, 0, true, false, false,
677 handle_noreturn_attribute
, false },
678 { "volatile", 0, 0, true, false, false,
679 handle_noreturn_attribute
, false },
680 { "stack_protect", 0, 0, true, false, false,
681 handle_stack_protect_attribute
, false },
682 { "noinline", 0, 0, true, false, false,
683 handle_noinline_attribute
, false },
684 { "noclone", 0, 0, true, false, false,
685 handle_noclone_attribute
, false },
686 { "no_icf", 0, 0, true, false, false,
687 handle_noicf_attribute
, false },
688 { "leaf", 0, 0, true, false, false,
689 handle_leaf_attribute
, false },
690 { "always_inline", 0, 0, true, false, false,
691 handle_always_inline_attribute
, false },
692 { "gnu_inline", 0, 0, true, false, false,
693 handle_gnu_inline_attribute
, false },
694 { "artificial", 0, 0, true, false, false,
695 handle_artificial_attribute
, false },
696 { "flatten", 0, 0, true, false, false,
697 handle_flatten_attribute
, false },
698 { "used", 0, 0, true, false, false,
699 handle_used_attribute
, false },
700 { "unused", 0, 0, false, false, false,
701 handle_unused_attribute
, false },
702 { "externally_visible", 0, 0, true, false, false,
703 handle_externally_visible_attribute
, false },
704 { "no_reorder", 0, 0, true, false, false,
705 handle_no_reorder_attribute
, false },
706 /* The same comments as for noreturn attributes apply to const ones. */
707 { "const", 0, 0, true, false, false,
708 handle_const_attribute
, false },
709 { "scalar_storage_order", 1, 1, false, false, false,
710 handle_scalar_storage_order_attribute
, false },
711 { "transparent_union", 0, 0, false, false, false,
712 handle_transparent_union_attribute
, false },
713 { "constructor", 0, 1, true, false, false,
714 handle_constructor_attribute
, false },
715 { "destructor", 0, 1, true, false, false,
716 handle_destructor_attribute
, false },
717 { "mode", 1, 1, false, true, false,
718 handle_mode_attribute
, false },
719 { "section", 1, 1, true, false, false,
720 handle_section_attribute
, false },
721 { "aligned", 0, 1, false, false, false,
722 handle_aligned_attribute
, false },
723 { "weak", 0, 0, true, false, false,
724 handle_weak_attribute
, false },
725 { "noplt", 0, 0, true, false, false,
726 handle_noplt_attribute
, false },
727 { "ifunc", 1, 1, true, false, false,
728 handle_ifunc_attribute
, false },
729 { "alias", 1, 1, true, false, false,
730 handle_alias_attribute
, false },
731 { "weakref", 0, 1, true, false, false,
732 handle_weakref_attribute
, false },
733 { "no_instrument_function", 0, 0, true, false, false,
734 handle_no_instrument_function_attribute
,
736 { "no_profile_instrument_function", 0, 0, true, false, false,
737 handle_no_profile_instrument_function_attribute
,
739 { "malloc", 0, 0, true, false, false,
740 handle_malloc_attribute
, false },
741 { "returns_twice", 0, 0, true, false, false,
742 handle_returns_twice_attribute
, false },
743 { "no_stack_limit", 0, 0, true, false, false,
744 handle_no_limit_stack_attribute
, false },
745 { "pure", 0, 0, true, false, false,
746 handle_pure_attribute
, false },
747 { "transaction_callable", 0, 0, false, true, false,
748 handle_tm_attribute
, false },
749 { "transaction_unsafe", 0, 0, false, true, false,
750 handle_tm_attribute
, true },
751 { "transaction_safe", 0, 0, false, true, false,
752 handle_tm_attribute
, true },
753 { "transaction_safe_dynamic", 0, 0, true, false, false,
754 handle_tm_attribute
, false },
755 { "transaction_may_cancel_outer", 0, 0, false, true, false,
756 handle_tm_attribute
, false },
757 /* ??? These two attributes didn't make the transition from the
758 Intel language document to the multi-vendor language document. */
759 { "transaction_pure", 0, 0, false, true, false,
760 handle_tm_attribute
, false },
761 { "transaction_wrap", 1, 1, true, false, false,
762 handle_tm_wrap_attribute
, false },
763 /* For internal use (marking of builtins) only. The name contains space
764 to prevent its usage in source code. */
765 { "no vops", 0, 0, true, false, false,
766 handle_novops_attribute
, false },
767 { "deprecated", 0, 1, false, false, false,
768 handle_deprecated_attribute
, false },
769 { "vector_size", 1, 1, false, true, false,
770 handle_vector_size_attribute
, true },
771 { "visibility", 1, 1, false, false, false,
772 handle_visibility_attribute
, false },
773 { "tls_model", 1, 1, true, false, false,
774 handle_tls_model_attribute
, false },
775 { "nonnull", 0, -1, false, true, true,
776 handle_nonnull_attribute
, false },
777 { "nothrow", 0, 0, true, false, false,
778 handle_nothrow_attribute
, false },
779 { "may_alias", 0, 0, false, true, false, NULL
, false },
780 { "cleanup", 1, 1, true, false, false,
781 handle_cleanup_attribute
, false },
782 { "warn_unused_result", 0, 0, false, true, true,
783 handle_warn_unused_result_attribute
, false },
784 { "sentinel", 0, 1, false, true, true,
785 handle_sentinel_attribute
, false },
786 /* For internal use (marking of builtins) only. The name contains space
787 to prevent its usage in source code. */
788 { "type generic", 0, 0, false, true, true,
789 handle_type_generic_attribute
, false },
790 { "alloc_size", 1, 2, false, true, true,
791 handle_alloc_size_attribute
, false },
792 { "cold", 0, 0, true, false, false,
793 handle_cold_attribute
, false },
794 { "hot", 0, 0, true, false, false,
795 handle_hot_attribute
, false },
796 { "no_address_safety_analysis",
797 0, 0, true, false, false,
798 handle_no_address_safety_analysis_attribute
,
800 { "no_sanitize_address", 0, 0, true, false, false,
801 handle_no_sanitize_address_attribute
,
803 { "no_sanitize_thread", 0, 0, true, false, false,
804 handle_no_sanitize_address_attribute
,
806 { "no_sanitize_undefined", 0, 0, true, false, false,
807 handle_no_sanitize_undefined_attribute
,
809 { "warning", 1, 1, true, false, false,
810 handle_error_attribute
, false },
811 { "error", 1, 1, true, false, false,
812 handle_error_attribute
, false },
813 { "target", 1, -1, true, false, false,
814 handle_target_attribute
, false },
815 { "target_clones", 1, -1, true, false, false,
816 handle_target_clones_attribute
, false },
817 { "optimize", 1, -1, true, false, false,
818 handle_optimize_attribute
, false },
819 /* For internal use only. The leading '*' both prevents its usage in
820 source code and signals that it may be overridden by machine tables. */
821 { "*tm regparm", 0, 0, false, true, true,
822 ignore_attribute
, false },
823 { "no_split_stack", 0, 0, true, false, false,
824 handle_no_split_stack_attribute
, false },
825 /* For internal use (marking of builtins and runtime functions) only.
826 The name contains space to prevent its usage in source code. */
827 { "fn spec", 1, 1, false, true, true,
828 handle_fnspec_attribute
, false },
829 { "warn_unused", 0, 0, false, false, false,
830 handle_warn_unused_attribute
, false },
831 { "returns_nonnull", 0, 0, false, true, true,
832 handle_returns_nonnull_attribute
, false },
833 { "omp declare simd", 0, -1, true, false, false,
834 handle_omp_declare_simd_attribute
, false },
835 { "cilk simd function", 0, -1, true, false, false,
836 handle_omp_declare_simd_attribute
, false },
837 { "simd", 0, 1, true, false, false,
838 handle_simd_attribute
, false },
839 { "omp declare target", 0, 0, true, false, false,
840 handle_omp_declare_target_attribute
, false },
841 { "omp declare target link", 0, 0, true, false, false,
842 handle_omp_declare_target_attribute
, false },
843 { "alloc_align", 1, 1, false, true, true,
844 handle_alloc_align_attribute
, false },
845 { "assume_aligned", 1, 2, false, true, true,
846 handle_assume_aligned_attribute
, false },
847 { "designated_init", 0, 0, false, true, false,
848 handle_designated_init_attribute
, false },
849 { "bnd_variable_size", 0, 0, true, false, false,
850 handle_bnd_variable_size_attribute
, false },
851 { "bnd_legacy", 0, 0, true, false, false,
852 handle_bnd_legacy
, false },
853 { "bnd_instrument", 0, 0, true, false, false,
854 handle_bnd_instrument
, false },
855 { "fallthrough", 0, 0, false, false, false,
856 handle_fallthrough_attribute
, false },
857 { NULL
, 0, 0, false, false, false, NULL
, false }
860 /* Give the specifications for the format attributes, used by C and all
863 All attributes referencing arguments should be additionally processed
864 in chkp_copy_function_type_adding_bounds for correct instrumentation
865 by Pointer Bounds Checker.
866 Current list of processed format attributes: format, format_arg. */
867 const struct attribute_spec c_common_format_attribute_table
[] =
869 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
870 affects_type_identity } */
871 { "format", 3, 3, false, true, true,
872 handle_format_attribute
, false },
873 { "format_arg", 1, 1, false, true, true,
874 handle_format_arg_attribute
, false },
875 { NULL
, 0, 0, false, false, false, NULL
, false }
878 /* Return identifier for address space AS. */
881 c_addr_space_name (addr_space_t as
)
883 int rid
= RID_FIRST_ADDR_SPACE
+ as
;
884 gcc_assert (ridpointers
[rid
]);
885 return IDENTIFIER_POINTER (ridpointers
[rid
]);
888 /* Push current bindings for the function name VAR_DECLS. */
891 start_fname_decls (void)
894 tree saved
= NULL_TREE
;
896 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
898 tree decl
= *fname_vars
[ix
].decl
;
902 saved
= tree_cons (decl
, build_int_cst (integer_type_node
, ix
),
904 *fname_vars
[ix
].decl
= NULL_TREE
;
907 if (saved
|| saved_function_name_decls
)
908 /* Normally they'll have been NULL, so only push if we've got a
909 stack, or they are non-NULL. */
910 saved_function_name_decls
= tree_cons (saved
, NULL_TREE
,
911 saved_function_name_decls
);
914 /* Finish up the current bindings, adding them into the current function's
915 statement tree. This must be done _before_ finish_stmt_tree is called.
916 If there is no current function, we must be at file scope and no statements
917 are involved. Pop the previous bindings. */
920 finish_fname_decls (void)
923 tree stmts
= NULL_TREE
;
924 tree stack
= saved_function_name_decls
;
926 for (; stack
&& TREE_VALUE (stack
); stack
= TREE_CHAIN (stack
))
927 append_to_statement_list (TREE_VALUE (stack
), &stmts
);
931 tree
*bodyp
= &DECL_SAVED_TREE (current_function_decl
);
933 if (TREE_CODE (*bodyp
) == BIND_EXPR
)
934 bodyp
= &BIND_EXPR_BODY (*bodyp
);
936 append_to_statement_list_force (*bodyp
, &stmts
);
940 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
941 *fname_vars
[ix
].decl
= NULL_TREE
;
945 /* We had saved values, restore them. */
948 for (saved
= TREE_PURPOSE (stack
); saved
; saved
= TREE_CHAIN (saved
))
950 tree decl
= TREE_PURPOSE (saved
);
951 unsigned ix
= TREE_INT_CST_LOW (TREE_VALUE (saved
));
953 *fname_vars
[ix
].decl
= decl
;
955 stack
= TREE_CHAIN (stack
);
957 saved_function_name_decls
= stack
;
960 /* Return the text name of the current function, suitably prettified
961 by PRETTY_P. Return string must be freed by caller. */
964 fname_as_string (int pretty_p
)
966 const char *name
= "top level";
969 cpp_string cstr
= { 0, 0 }, strname
;
977 if (current_function_decl
)
978 name
= lang_hooks
.decl_printable_name (current_function_decl
, vrb
);
980 len
= strlen (name
) + 3; /* Two for '"'s. One for NULL. */
982 namep
= XNEWVEC (char, len
);
983 snprintf (namep
, len
, "\"%s\"", name
);
984 strname
.text
= (unsigned char *) namep
;
985 strname
.len
= len
- 1;
987 if (cpp_interpret_string (parse_in
, &strname
, 1, &cstr
, CPP_STRING
))
990 return (const char *) cstr
.text
;
996 /* Return the VAR_DECL for a const char array naming the current
997 function. If the VAR_DECL has not yet been created, create it
998 now. RID indicates how it should be formatted and IDENTIFIER_NODE
999 ID is its name (unfortunately C and C++ hold the RID values of
1000 keywords in different places, so we can't derive RID from ID in
1001 this language independent code. LOC is the location of the
1005 fname_decl (location_t loc
, unsigned int rid
, tree id
)
1008 tree decl
= NULL_TREE
;
1010 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
1011 if (fname_vars
[ix
].rid
== rid
)
1014 decl
= *fname_vars
[ix
].decl
;
1017 /* If a tree is built here, it would normally have the lineno of
1018 the current statement. Later this tree will be moved to the
1019 beginning of the function and this line number will be wrong.
1020 To avoid this problem set the lineno to 0 here; that prevents
1021 it from appearing in the RTL. */
1023 location_t saved_location
= input_location
;
1024 input_location
= UNKNOWN_LOCATION
;
1026 stmts
= push_stmt_list ();
1027 decl
= (*make_fname_decl
) (loc
, id
, fname_vars
[ix
].pretty
);
1028 stmts
= pop_stmt_list (stmts
);
1029 if (!IS_EMPTY_STMT (stmts
))
1030 saved_function_name_decls
1031 = tree_cons (decl
, stmts
, saved_function_name_decls
);
1032 *fname_vars
[ix
].decl
= decl
;
1033 input_location
= saved_location
;
1035 if (!ix
&& !current_function_decl
)
1036 pedwarn (loc
, 0, "%qD is not defined outside of function scope", decl
);
1041 /* Given a STRING_CST, give it a suitable array-of-chars data type. */
1044 fix_string_type (tree value
)
1046 int length
= TREE_STRING_LENGTH (value
);
1048 tree e_type
, i_type
, a_type
;
1050 /* Compute the number of elements, for the array type. */
1051 if (TREE_TYPE (value
) == char_array_type_node
|| !TREE_TYPE (value
))
1054 e_type
= char_type_node
;
1056 else if (TREE_TYPE (value
) == char16_array_type_node
)
1058 nchars
= length
/ (TYPE_PRECISION (char16_type_node
) / BITS_PER_UNIT
);
1059 e_type
= char16_type_node
;
1061 else if (TREE_TYPE (value
) == char32_array_type_node
)
1063 nchars
= length
/ (TYPE_PRECISION (char32_type_node
) / BITS_PER_UNIT
);
1064 e_type
= char32_type_node
;
1068 nchars
= length
/ (TYPE_PRECISION (wchar_type_node
) / BITS_PER_UNIT
);
1069 e_type
= wchar_type_node
;
1072 /* C89 2.2.4.1, C99 5.2.4.1 (Translation limits). The analogous
1073 limit in C++98 Annex B is very large (65536) and is not normative,
1074 so we do not diagnose it (warn_overlength_strings is forced off
1075 in c_common_post_options). */
1076 if (warn_overlength_strings
)
1078 const int nchars_max
= flag_isoc99
? 4095 : 509;
1079 const int relevant_std
= flag_isoc99
? 99 : 90;
1080 if (nchars
- 1 > nchars_max
)
1081 /* Translators: The %d after 'ISO C' will be 90 or 99. Do not
1082 separate the %d from the 'C'. 'ISO' should not be
1083 translated, but it may be moved after 'C%d' in languages
1084 where modifiers follow nouns. */
1085 pedwarn (input_location
, OPT_Woverlength_strings
,
1086 "string length %qd is greater than the length %qd "
1087 "ISO C%d compilers are required to support",
1088 nchars
- 1, nchars_max
, relevant_std
);
1091 /* Create the array type for the string constant. The ISO C++
1092 standard says that a string literal has type `const char[N]' or
1093 `const wchar_t[N]'. We use the same logic when invoked as a C
1094 front-end with -Wwrite-strings.
1095 ??? We should change the type of an expression depending on the
1096 state of a warning flag. We should just be warning -- see how
1097 this is handled in the C++ front-end for the deprecated implicit
1098 conversion from string literals to `char*' or `wchar_t*'.
1100 The C++ front end relies on TYPE_MAIN_VARIANT of a cv-qualified
1101 array type being the unqualified version of that type.
1102 Therefore, if we are constructing an array of const char, we must
1103 construct the matching unqualified array type first. The C front
1104 end does not require this, but it does no harm, so we do it
1106 i_type
= build_index_type (size_int (nchars
- 1));
1107 a_type
= build_array_type (e_type
, i_type
);
1108 if (c_dialect_cxx() || warn_write_strings
)
1109 a_type
= c_build_qualified_type (a_type
, TYPE_QUAL_CONST
);
1111 TREE_TYPE (value
) = a_type
;
1112 TREE_CONSTANT (value
) = 1;
1113 TREE_READONLY (value
) = 1;
1114 TREE_STATIC (value
) = 1;
1118 /* Given a string of type STRING_TYPE, determine what kind of string
1119 token would give an equivalent execution encoding: CPP_STRING,
1120 CPP_STRING16, or CPP_STRING32. Return CPP_OTHER in case of error.
1121 This may not be exactly the string token type that initially created
1122 the string, since CPP_WSTRING is indistinguishable from the 16/32 bit
1123 string type at this point.
1125 This effectively reverses part of the logic in lex_string and
1128 static enum cpp_ttype
1129 get_cpp_ttype_from_string_type (tree string_type
)
1131 gcc_assert (string_type
);
1132 if (TREE_CODE (string_type
) == POINTER_TYPE
)
1133 string_type
= TREE_TYPE (string_type
);
1135 if (TREE_CODE (string_type
) != ARRAY_TYPE
)
1138 tree element_type
= TREE_TYPE (string_type
);
1139 if (TREE_CODE (element_type
) != INTEGER_TYPE
)
1142 int bits_per_character
= TYPE_PRECISION (element_type
);
1143 switch (bits_per_character
)
1146 return CPP_STRING
; /* It could have also been CPP_UTF8STRING. */
1148 return CPP_STRING16
;
1150 return CPP_STRING32
;
1156 /* The global record of string concatentations, for use in
1157 extracting locations within string literals. */
1159 GTY(()) string_concat_db
*g_string_concat_db
;
1161 /* Implementation of LANG_HOOKS_GET_SUBSTRING_LOCATION. */
1164 c_get_substring_location (const substring_loc
&substr_loc
,
1165 location_t
*out_loc
)
1167 enum cpp_ttype tok_type
1168 = get_cpp_ttype_from_string_type (substr_loc
.get_string_type ());
1169 if (tok_type
== CPP_OTHER
)
1170 return "unrecognized string type";
1172 return get_source_location_for_substring (parse_in
, g_string_concat_db
,
1173 substr_loc
.get_fmt_string_loc (),
1175 substr_loc
.get_caret_idx (),
1176 substr_loc
.get_start_idx (),
1177 substr_loc
.get_end_idx (),
1182 /* Fold X for consideration by one of the warning functions when checking
1183 whether an expression has a constant value. */
1186 fold_for_warn (tree x
)
1188 if (c_dialect_cxx ())
1189 return c_fully_fold (x
, /*for_init*/false, /*maybe_constp*/NULL
);
1191 /* The C front-end has already folded X appropriately. */
1195 /* Return true iff T is a boolean promoted to int. */
1198 bool_promoted_to_int_p (tree t
)
1200 return (CONVERT_EXPR_P (t
)
1201 && TREE_TYPE (t
) == integer_type_node
1202 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == BOOLEAN_TYPE
);
1205 /* vector_targets_convertible_p is used for vector pointer types. The
1206 callers perform various checks that the qualifiers are satisfactory,
1207 while OTOH vector_targets_convertible_p ignores the number of elements
1208 in the vectors. That's fine with vector pointers as we can consider,
1209 say, a vector of 8 elements as two consecutive vectors of 4 elements,
1210 and that does not require and conversion of the pointer values.
1211 In contrast, vector_types_convertible_p and
1212 vector_types_compatible_elements_p are used for vector value types. */
1213 /* True if pointers to distinct types T1 and T2 can be converted to
1214 each other without an explicit cast. Only returns true for opaque
1217 vector_targets_convertible_p (const_tree t1
, const_tree t2
)
1219 if (VECTOR_TYPE_P (t1
) && VECTOR_TYPE_P (t2
)
1220 && (TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
1221 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
1227 /* vector_types_convertible_p is used for vector value types.
1228 It could in principle call vector_targets_convertible_p as a subroutine,
1229 but then the check for vector type would be duplicated with its callers,
1230 and also the purpose of vector_targets_convertible_p would become
1232 Where vector_types_convertible_p returns true, a conversion might still be
1233 needed to make the types match.
1234 In contrast, vector_targets_convertible_p is used for vector pointer
1235 values, and vector_types_compatible_elements_p is used specifically
1236 in the context for binary operators, as a check if use is possible without
1238 /* True if vector types T1 and T2 can be converted to each other
1239 without an explicit cast. If EMIT_LAX_NOTE is true, and T1 and T2
1240 can only be converted with -flax-vector-conversions yet that is not
1241 in effect, emit a note telling the user about that option if such
1242 a note has not previously been emitted. */
1244 vector_types_convertible_p (const_tree t1
, const_tree t2
, bool emit_lax_note
)
1246 static bool emitted_lax_note
= false;
1247 bool convertible_lax
;
1249 if ((TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
1250 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
1254 (tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
))
1255 && (TREE_CODE (TREE_TYPE (t1
)) != REAL_TYPE
||
1256 TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
))
1257 && (INTEGRAL_TYPE_P (TREE_TYPE (t1
))
1258 == INTEGRAL_TYPE_P (TREE_TYPE (t2
))));
1260 if (!convertible_lax
|| flag_lax_vector_conversions
)
1261 return convertible_lax
;
1263 if (TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
)
1264 && lang_hooks
.types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
1267 if (emit_lax_note
&& !emitted_lax_note
)
1269 emitted_lax_note
= true;
1270 inform (input_location
, "use -flax-vector-conversions to permit "
1271 "conversions between vectors with differing "
1272 "element types or numbers of subparts");
1278 /* Build a VEC_PERM_EXPR if V0, V1 and MASK are not error_mark_nodes
1279 and have vector types, V0 has the same type as V1, and the number of
1280 elements of V0, V1, MASK is the same.
1282 In case V1 is a NULL_TREE it is assumed that __builtin_shuffle was
1283 called with two arguments. In this case implementation passes the
1284 first argument twice in order to share the same tree code. This fact
1285 could enable the mask-values being twice the vector length. This is
1286 an implementation accident and this semantics is not guaranteed to
1289 c_build_vec_perm_expr (location_t loc
, tree v0
, tree v1
, tree mask
,
1294 bool maybe_const
= false;
1295 bool two_arguments
= false;
1297 if (v1
== NULL_TREE
)
1299 two_arguments
= true;
1303 if (v0
== error_mark_node
|| v1
== error_mark_node
1304 || mask
== error_mark_node
)
1305 return error_mark_node
;
1307 if (!VECTOR_INTEGER_TYPE_P (TREE_TYPE (mask
)))
1310 error_at (loc
, "__builtin_shuffle last argument must "
1311 "be an integer vector");
1312 return error_mark_node
;
1315 if (!VECTOR_TYPE_P (TREE_TYPE (v0
))
1316 || !VECTOR_TYPE_P (TREE_TYPE (v1
)))
1319 error_at (loc
, "__builtin_shuffle arguments must be vectors");
1320 return error_mark_node
;
1323 if (TYPE_MAIN_VARIANT (TREE_TYPE (v0
)) != TYPE_MAIN_VARIANT (TREE_TYPE (v1
)))
1326 error_at (loc
, "__builtin_shuffle argument vectors must be of "
1328 return error_mark_node
;
1331 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (v0
))
1332 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
))
1333 && TYPE_VECTOR_SUBPARTS (TREE_TYPE (v1
))
1334 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
)))
1337 error_at (loc
, "__builtin_shuffle number of elements of the "
1338 "argument vector(s) and the mask vector should "
1340 return error_mark_node
;
1343 if (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (v0
))))
1344 != GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (mask
)))))
1347 error_at (loc
, "__builtin_shuffle argument vector(s) inner type "
1348 "must have the same size as inner type of the mask");
1349 return error_mark_node
;
1352 if (!c_dialect_cxx ())
1354 /* Avoid C_MAYBE_CONST_EXPRs inside VEC_PERM_EXPR. */
1355 v0
= c_fully_fold (v0
, false, &maybe_const
);
1356 wrap
&= maybe_const
;
1359 v1
= v0
= save_expr (v0
);
1362 v1
= c_fully_fold (v1
, false, &maybe_const
);
1363 wrap
&= maybe_const
;
1366 mask
= c_fully_fold (mask
, false, &maybe_const
);
1367 wrap
&= maybe_const
;
1369 else if (two_arguments
)
1370 v1
= v0
= save_expr (v0
);
1372 ret
= build3_loc (loc
, VEC_PERM_EXPR
, TREE_TYPE (v0
), v0
, v1
, mask
);
1374 if (!c_dialect_cxx () && !wrap
)
1375 ret
= c_wrap_maybe_const (ret
, true);
1380 /* Like tree.c:get_narrower, but retain conversion from C++0x scoped enum
1381 to integral type. */
1384 c_common_get_narrower (tree op
, int *unsignedp_ptr
)
1386 op
= get_narrower (op
, unsignedp_ptr
);
1388 if (TREE_CODE (TREE_TYPE (op
)) == ENUMERAL_TYPE
1389 && ENUM_IS_SCOPED (TREE_TYPE (op
)))
1391 /* C++0x scoped enumerations don't implicitly convert to integral
1392 type; if we stripped an explicit conversion to a larger type we
1393 need to replace it so common_type will still work. */
1394 tree type
= c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op
)),
1395 TYPE_UNSIGNED (TREE_TYPE (op
)));
1396 op
= fold_convert (type
, op
);
1401 /* This is a helper function of build_binary_op.
1403 For certain operations if both args were extended from the same
1404 smaller type, do the arithmetic in that type and then extend.
1406 BITWISE indicates a bitwise operation.
1407 For them, this optimization is safe only if
1408 both args are zero-extended or both are sign-extended.
1409 Otherwise, we might change the result.
1410 Eg, (short)-1 | (unsigned short)-1 is (int)-1
1411 but calculated in (unsigned short) it would be (unsigned short)-1.
1414 shorten_binary_op (tree result_type
, tree op0
, tree op1
, bool bitwise
)
1416 int unsigned0
, unsigned1
;
1421 /* Cast OP0 and OP1 to RESULT_TYPE. Doing so prevents
1422 excessive narrowing when we call get_narrower below. For
1423 example, suppose that OP0 is of unsigned int extended
1424 from signed char and that RESULT_TYPE is long long int.
1425 If we explicitly cast OP0 to RESULT_TYPE, OP0 would look
1428 (long long int) (unsigned int) signed_char
1430 which get_narrower would narrow down to
1432 (unsigned int) signed char
1434 If we do not cast OP0 first, get_narrower would return
1435 signed_char, which is inconsistent with the case of the
1437 op0
= convert (result_type
, op0
);
1438 op1
= convert (result_type
, op1
);
1440 arg0
= c_common_get_narrower (op0
, &unsigned0
);
1441 arg1
= c_common_get_narrower (op1
, &unsigned1
);
1443 /* UNS is 1 if the operation to be done is an unsigned one. */
1444 uns
= TYPE_UNSIGNED (result_type
);
1446 /* Handle the case that OP0 (or OP1) does not *contain* a conversion
1447 but it *requires* conversion to FINAL_TYPE. */
1449 if ((TYPE_PRECISION (TREE_TYPE (op0
))
1450 == TYPE_PRECISION (TREE_TYPE (arg0
)))
1451 && TREE_TYPE (op0
) != result_type
)
1452 unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
1453 if ((TYPE_PRECISION (TREE_TYPE (op1
))
1454 == TYPE_PRECISION (TREE_TYPE (arg1
)))
1455 && TREE_TYPE (op1
) != result_type
)
1456 unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
1458 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
1460 /* For bitwise operations, signedness of nominal type
1461 does not matter. Consider only how operands were extended. */
1465 /* Note that in all three cases below we refrain from optimizing
1466 an unsigned operation on sign-extended args.
1467 That would not be valid. */
1469 /* Both args variable: if both extended in same way
1470 from same width, do it in that width.
1471 Do it unsigned if args were zero-extended. */
1472 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
1473 < TYPE_PRECISION (result_type
))
1474 && (TYPE_PRECISION (TREE_TYPE (arg1
))
1475 == TYPE_PRECISION (TREE_TYPE (arg0
)))
1476 && unsigned0
== unsigned1
1477 && (unsigned0
|| !uns
))
1478 return c_common_signed_or_unsigned_type
1479 (unsigned0
, common_type (TREE_TYPE (arg0
), TREE_TYPE (arg1
)));
1481 else if (TREE_CODE (arg0
) == INTEGER_CST
1482 && (unsigned1
|| !uns
)
1483 && (TYPE_PRECISION (TREE_TYPE (arg1
))
1484 < TYPE_PRECISION (result_type
))
1486 = c_common_signed_or_unsigned_type (unsigned1
,
1488 && !POINTER_TYPE_P (type
)
1489 && int_fits_type_p (arg0
, type
))
1492 else if (TREE_CODE (arg1
) == INTEGER_CST
1493 && (unsigned0
|| !uns
)
1494 && (TYPE_PRECISION (TREE_TYPE (arg0
))
1495 < TYPE_PRECISION (result_type
))
1497 = c_common_signed_or_unsigned_type (unsigned0
,
1499 && !POINTER_TYPE_P (type
)
1500 && int_fits_type_p (arg1
, type
))
1506 /* Returns true iff any integer value of type FROM_TYPE can be represented as
1507 real of type TO_TYPE. This is a helper function for unsafe_conversion_p. */
1510 int_safely_convertible_to_real_p (const_tree from_type
, const_tree to_type
)
1512 tree type_low_bound
= TYPE_MIN_VALUE (from_type
);
1513 tree type_high_bound
= TYPE_MAX_VALUE (from_type
);
1514 REAL_VALUE_TYPE real_low_bound
=
1515 real_value_from_int_cst (0, type_low_bound
);
1516 REAL_VALUE_TYPE real_high_bound
=
1517 real_value_from_int_cst (0, type_high_bound
);
1519 return exact_real_truncate (TYPE_MODE (to_type
), &real_low_bound
)
1520 && exact_real_truncate (TYPE_MODE (to_type
), &real_high_bound
);
1523 /* Checks if expression EXPR of complex/real/integer type cannot be converted
1524 to the complex/real/integer type TYPE. Function returns non-zero when:
1525 * EXPR is a constant which cannot be exactly converted to TYPE.
1526 * EXPR is not a constant and size of EXPR's type > than size of TYPE,
1527 for EXPR type and TYPE being both integers or both real, or both
1529 * EXPR is not a constant of complex type and TYPE is a real or
1531 * EXPR is not a constant of real type and TYPE is an integer.
1532 * EXPR is not a constant of integer type which cannot be
1533 exactly converted to real type.
1535 Function allows conversions between types of different signedness and
1536 can return SAFE_CONVERSION (zero) in that case. Function can produce
1537 signedness warnings if PRODUCE_WARNS is true.
1539 Function allows conversions from complex constants to non-complex types,
1540 provided that imaginary part is zero and real part can be safely converted
1543 enum conversion_safety
1544 unsafe_conversion_p (location_t loc
, tree type
, tree expr
, bool produce_warns
)
1546 enum conversion_safety give_warning
= SAFE_CONVERSION
; /* is 0 or false */
1547 tree expr_type
= TREE_TYPE (expr
);
1548 loc
= expansion_point_location_if_in_system_header (loc
);
1550 if (TREE_CODE (expr
) == REAL_CST
|| TREE_CODE (expr
) == INTEGER_CST
)
1552 /* If type is complex, we are interested in compatibility with
1554 if (TREE_CODE (type
) == COMPLEX_TYPE
)
1555 type
= TREE_TYPE (type
);
1557 /* Warn for real constant that is not an exact integer converted
1559 if (TREE_CODE (expr_type
) == REAL_TYPE
1560 && TREE_CODE (type
) == INTEGER_TYPE
)
1562 if (!real_isinteger (TREE_REAL_CST_PTR (expr
), TYPE_MODE (expr_type
)))
1563 give_warning
= UNSAFE_REAL
;
1565 /* Warn for an integer constant that does not fit into integer type. */
1566 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
1567 && TREE_CODE (type
) == INTEGER_TYPE
1568 && !int_fits_type_p (expr
, type
))
1570 if (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)
1571 && tree_int_cst_sgn (expr
) < 0)
1574 warning_at (loc
, OPT_Wsign_conversion
, "negative integer"
1575 " implicitly converted to unsigned type");
1577 else if (!TYPE_UNSIGNED (type
) && TYPE_UNSIGNED (expr_type
))
1580 warning_at (loc
, OPT_Wsign_conversion
, "conversion of unsigned"
1581 " constant value to negative integer");
1584 give_warning
= UNSAFE_OTHER
;
1586 else if (TREE_CODE (type
) == REAL_TYPE
)
1588 /* Warn for an integer constant that does not fit into real type. */
1589 if (TREE_CODE (expr_type
) == INTEGER_TYPE
)
1591 REAL_VALUE_TYPE a
= real_value_from_int_cst (0, expr
);
1592 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
1593 give_warning
= UNSAFE_REAL
;
1595 /* Warn for a real constant that does not fit into a smaller
1597 else if (TREE_CODE (expr_type
) == REAL_TYPE
1598 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
1600 REAL_VALUE_TYPE a
= TREE_REAL_CST (expr
);
1601 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
1602 give_warning
= UNSAFE_REAL
;
1607 else if (TREE_CODE (expr
) == COMPLEX_CST
)
1609 tree imag_part
= TREE_IMAGPART (expr
);
1610 /* Conversion from complex constant with zero imaginary part,
1611 perform check for conversion of real part. */
1612 if ((TREE_CODE (imag_part
) == REAL_CST
1613 && real_zerop (imag_part
))
1614 || (TREE_CODE (imag_part
) == INTEGER_CST
1615 && integer_zerop (imag_part
)))
1616 /* Note: in this branch we use recursive call to unsafe_conversion_p
1617 with different type of EXPR, but it is still safe, because when EXPR
1618 is a constant, it's type is not used in text of generated warnings
1619 (otherwise they could sound misleading). */
1620 return unsafe_conversion_p (loc
, type
, TREE_REALPART (expr
),
1622 /* Conversion from complex constant with non-zero imaginary part. */
1625 /* Conversion to complex type.
1626 Perform checks for both real and imaginary parts. */
1627 if (TREE_CODE (type
) == COMPLEX_TYPE
)
1629 /* Unfortunately, produce_warns must be false in two subsequent
1630 calls of unsafe_conversion_p, because otherwise we could
1631 produce strange "double" warnings, if both real and imaginary
1632 parts have conversion problems related to signedness.
1635 int32_t _Complex a = 0x80000000 + 0x80000000i;
1637 Possible solution: add a separate function for checking
1638 constants and combine result of two calls appropriately. */
1639 enum conversion_safety re_safety
=
1640 unsafe_conversion_p (loc
, type
, TREE_REALPART (expr
), false);
1641 enum conversion_safety im_safety
=
1642 unsafe_conversion_p (loc
, type
, imag_part
, false);
1644 /* Merge the results into appropriate single warning. */
1646 /* Note: this case includes SAFE_CONVERSION, i.e. success. */
1647 if (re_safety
== im_safety
)
1648 give_warning
= re_safety
;
1649 else if (!re_safety
&& im_safety
)
1650 give_warning
= im_safety
;
1651 else if (re_safety
&& !im_safety
)
1652 give_warning
= re_safety
;
1654 give_warning
= UNSAFE_OTHER
;
1656 /* Warn about conversion from complex to real or integer type. */
1658 give_warning
= UNSAFE_IMAGINARY
;
1662 /* Checks for remaining case: EXPR is not constant. */
1665 /* Warn for real types converted to integer types. */
1666 if (TREE_CODE (expr_type
) == REAL_TYPE
1667 && TREE_CODE (type
) == INTEGER_TYPE
)
1668 give_warning
= UNSAFE_REAL
;
1670 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
1671 && TREE_CODE (type
) == INTEGER_TYPE
)
1673 /* Don't warn about unsigned char y = 0xff, x = (int) y; */
1674 expr
= get_unwidened (expr
, 0);
1675 expr_type
= TREE_TYPE (expr
);
1677 /* Don't warn for short y; short x = ((int)y & 0xff); */
1678 if (TREE_CODE (expr
) == BIT_AND_EXPR
1679 || TREE_CODE (expr
) == BIT_IOR_EXPR
1680 || TREE_CODE (expr
) == BIT_XOR_EXPR
)
1682 /* If both args were extended from a shortest type,
1683 use that type if that is safe. */
1684 expr_type
= shorten_binary_op (expr_type
,
1685 TREE_OPERAND (expr
, 0),
1686 TREE_OPERAND (expr
, 1),
1689 if (TREE_CODE (expr
) == BIT_AND_EXPR
)
1691 tree op0
= TREE_OPERAND (expr
, 0);
1692 tree op1
= TREE_OPERAND (expr
, 1);
1693 bool unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
1694 bool unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
1696 /* If one of the operands is a non-negative constant
1697 that fits in the target type, then the type of the
1698 other operand does not matter. */
1699 if ((TREE_CODE (op0
) == INTEGER_CST
1700 && int_fits_type_p (op0
, c_common_signed_type (type
))
1701 && int_fits_type_p (op0
, c_common_unsigned_type (type
)))
1702 || (TREE_CODE (op1
) == INTEGER_CST
1703 && int_fits_type_p (op1
, c_common_signed_type (type
))
1704 && int_fits_type_p (op1
,
1705 c_common_unsigned_type (type
))))
1706 return SAFE_CONVERSION
;
1707 /* If constant is unsigned and fits in the target
1708 type, then the result will also fit. */
1709 else if ((TREE_CODE (op0
) == INTEGER_CST
1711 && int_fits_type_p (op0
, type
))
1712 || (TREE_CODE (op1
) == INTEGER_CST
1714 && int_fits_type_p (op1
, type
)))
1715 return SAFE_CONVERSION
;
1718 /* Warn for integer types converted to smaller integer types. */
1719 if (TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
1720 give_warning
= UNSAFE_OTHER
;
1722 /* When they are the same width but different signedness,
1723 then the value may change. */
1724 else if (((TYPE_PRECISION (type
) == TYPE_PRECISION (expr_type
)
1725 && TYPE_UNSIGNED (expr_type
) != TYPE_UNSIGNED (type
))
1726 /* Even when converted to a bigger type, if the type is
1727 unsigned but expr is signed, then negative values
1729 || (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)))
1731 warning_at (loc
, OPT_Wsign_conversion
, "conversion to %qT from %qT "
1732 "may change the sign of the result",
1736 /* Warn for integer types converted to real types if and only if
1737 all the range of values of the integer type cannot be
1738 represented by the real type. */
1739 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
1740 && TREE_CODE (type
) == REAL_TYPE
)
1742 /* Don't warn about char y = 0xff; float x = (int) y; */
1743 expr
= get_unwidened (expr
, 0);
1744 expr_type
= TREE_TYPE (expr
);
1746 if (!int_safely_convertible_to_real_p (expr_type
, type
))
1747 give_warning
= UNSAFE_OTHER
;
1750 /* Warn for real types converted to smaller real types. */
1751 else if (TREE_CODE (expr_type
) == REAL_TYPE
1752 && TREE_CODE (type
) == REAL_TYPE
1753 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
1754 give_warning
= UNSAFE_REAL
;
1756 /* Check conversion between two complex types. */
1757 else if (TREE_CODE (expr_type
) == COMPLEX_TYPE
1758 && TREE_CODE (type
) == COMPLEX_TYPE
)
1760 /* Extract underlying types (i.e., type of real and imaginary
1761 parts) of expr_type and type. */
1762 tree from_type
= TREE_TYPE (expr_type
);
1763 tree to_type
= TREE_TYPE (type
);
1765 /* Warn for real types converted to integer types. */
1766 if (TREE_CODE (from_type
) == REAL_TYPE
1767 && TREE_CODE (to_type
) == INTEGER_TYPE
)
1768 give_warning
= UNSAFE_REAL
;
1770 /* Warn for real types converted to smaller real types. */
1771 else if (TREE_CODE (from_type
) == REAL_TYPE
1772 && TREE_CODE (to_type
) == REAL_TYPE
1773 && TYPE_PRECISION (to_type
) < TYPE_PRECISION (from_type
))
1774 give_warning
= UNSAFE_REAL
;
1776 /* Check conversion for complex integer types. Here implementation
1777 is simpler than for real-domain integers because it does not
1778 involve sophisticated cases, such as bitmasks, casts, etc. */
1779 else if (TREE_CODE (from_type
) == INTEGER_TYPE
1780 && TREE_CODE (to_type
) == INTEGER_TYPE
)
1782 /* Warn for integer types converted to smaller integer types. */
1783 if (TYPE_PRECISION (to_type
) < TYPE_PRECISION (from_type
))
1784 give_warning
= UNSAFE_OTHER
;
1786 /* Check for different signedness, see case for real-domain
1787 integers (above) for a more detailed comment. */
1788 else if (((TYPE_PRECISION (to_type
) == TYPE_PRECISION (from_type
)
1789 && TYPE_UNSIGNED (to_type
) != TYPE_UNSIGNED (from_type
))
1790 || (TYPE_UNSIGNED (to_type
) && !TYPE_UNSIGNED (from_type
)))
1792 warning_at (loc
, OPT_Wsign_conversion
,
1793 "conversion to %qT from %qT "
1794 "may change the sign of the result",
1797 else if (TREE_CODE (from_type
) == INTEGER_TYPE
1798 && TREE_CODE (to_type
) == REAL_TYPE
1799 && !int_safely_convertible_to_real_p (from_type
, to_type
))
1800 give_warning
= UNSAFE_OTHER
;
1803 /* Warn for complex types converted to real or integer types. */
1804 else if (TREE_CODE (expr_type
) == COMPLEX_TYPE
1805 && TREE_CODE (type
) != COMPLEX_TYPE
)
1806 give_warning
= UNSAFE_IMAGINARY
;
1809 return give_warning
;
1813 /* Convert EXPR to TYPE, warning about conversion problems with constants.
1814 Invoke this function on every expression that is converted implicitly,
1815 i.e. because of language rules and not because of an explicit cast. */
1818 convert_and_check (location_t loc
, tree type
, tree expr
)
1821 tree expr_for_warning
;
1823 /* Convert from a value with possible excess precision rather than
1824 via the semantic type, but do not warn about values not fitting
1825 exactly in the semantic type. */
1826 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
1828 tree orig_type
= TREE_TYPE (expr
);
1829 expr
= TREE_OPERAND (expr
, 0);
1830 expr_for_warning
= convert (orig_type
, expr
);
1831 if (orig_type
== type
)
1832 return expr_for_warning
;
1835 expr_for_warning
= expr
;
1837 if (TREE_TYPE (expr
) == type
)
1840 result
= convert (type
, expr
);
1842 if (c_inhibit_evaluation_warnings
== 0
1843 && !TREE_OVERFLOW_P (expr
)
1844 && result
!= error_mark_node
)
1845 warnings_for_convert_and_check (loc
, type
, expr_for_warning
, result
);
1850 /* A node in a list that describes references to variables (EXPR), which are
1851 either read accesses if WRITER is zero, or write accesses, in which case
1852 WRITER is the parent of EXPR. */
1859 /* Used to implement a cache the results of a call to verify_tree. We only
1860 use this for SAVE_EXPRs. */
1863 struct tlist_cache
*next
;
1864 struct tlist
*cache_before_sp
;
1865 struct tlist
*cache_after_sp
;
1869 /* Obstack to use when allocating tlist structures, and corresponding
1871 static struct obstack tlist_obstack
;
1872 static char *tlist_firstobj
= 0;
1874 /* Keep track of the identifiers we've warned about, so we can avoid duplicate
1876 static struct tlist
*warned_ids
;
1877 /* SAVE_EXPRs need special treatment. We process them only once and then
1878 cache the results. */
1879 static struct tlist_cache
*save_expr_cache
;
1881 static void add_tlist (struct tlist
**, struct tlist
*, tree
, int);
1882 static void merge_tlist (struct tlist
**, struct tlist
*, int);
1883 static void verify_tree (tree
, struct tlist
**, struct tlist
**, tree
);
1884 static int warning_candidate_p (tree
);
1885 static bool candidate_equal_p (const_tree
, const_tree
);
1886 static void warn_for_collisions (struct tlist
*);
1887 static void warn_for_collisions_1 (tree
, tree
, struct tlist
*, int);
1888 static struct tlist
*new_tlist (struct tlist
*, tree
, tree
);
1890 /* Create a new struct tlist and fill in its fields. */
1891 static struct tlist
*
1892 new_tlist (struct tlist
*next
, tree t
, tree writer
)
1895 l
= XOBNEW (&tlist_obstack
, struct tlist
);
1902 /* Add duplicates of the nodes found in ADD to the list *TO. If EXCLUDE_WRITER
1903 is nonnull, we ignore any node we find which has a writer equal to it. */
1906 add_tlist (struct tlist
**to
, struct tlist
*add
, tree exclude_writer
, int copy
)
1910 struct tlist
*next
= add
->next
;
1913 if (!exclude_writer
|| !candidate_equal_p (add
->writer
, exclude_writer
))
1914 *to
= copy
? new_tlist (*to
, add
->expr
, add
->writer
) : add
;
1919 /* Merge the nodes of ADD into TO. This merging process is done so that for
1920 each variable that already exists in TO, no new node is added; however if
1921 there is a write access recorded in ADD, and an occurrence on TO is only
1922 a read access, then the occurrence in TO will be modified to record the
1926 merge_tlist (struct tlist
**to
, struct tlist
*add
, int copy
)
1928 struct tlist
**end
= to
;
1931 end
= &(*end
)->next
;
1937 struct tlist
*next
= add
->next
;
1939 for (tmp2
= *to
; tmp2
; tmp2
= tmp2
->next
)
1940 if (candidate_equal_p (tmp2
->expr
, add
->expr
))
1944 tmp2
->writer
= add
->writer
;
1948 *end
= copy
? new_tlist (NULL
, add
->expr
, add
->writer
) : add
;
1949 end
= &(*end
)->next
;
1956 /* WRITTEN is a variable, WRITER is its parent. Warn if any of the variable
1957 references in list LIST conflict with it, excluding reads if ONLY writers
1961 warn_for_collisions_1 (tree written
, tree writer
, struct tlist
*list
,
1966 /* Avoid duplicate warnings. */
1967 for (tmp
= warned_ids
; tmp
; tmp
= tmp
->next
)
1968 if (candidate_equal_p (tmp
->expr
, written
))
1973 if (candidate_equal_p (list
->expr
, written
)
1974 && !candidate_equal_p (list
->writer
, writer
)
1975 && (!only_writes
|| list
->writer
))
1977 warned_ids
= new_tlist (warned_ids
, written
, NULL_TREE
);
1978 warning_at (EXPR_LOC_OR_LOC (writer
, input_location
),
1979 OPT_Wsequence_point
, "operation on %qE may be undefined",
1986 /* Given a list LIST of references to variables, find whether any of these
1987 can cause conflicts due to missing sequence points. */
1990 warn_for_collisions (struct tlist
*list
)
1994 for (tmp
= list
; tmp
; tmp
= tmp
->next
)
1997 warn_for_collisions_1 (tmp
->expr
, tmp
->writer
, list
, 0);
2001 /* Return nonzero if X is a tree that can be verified by the sequence point
2004 warning_candidate_p (tree x
)
2006 if (DECL_P (x
) && DECL_ARTIFICIAL (x
))
2009 if (TREE_CODE (x
) == BLOCK
)
2012 /* VOID_TYPE_P (TREE_TYPE (x)) is workaround for cp/tree.c
2013 (lvalue_p) crash on TRY/CATCH. */
2014 if (TREE_TYPE (x
) == NULL_TREE
|| VOID_TYPE_P (TREE_TYPE (x
)))
2020 /* No point to track non-const calls, they will never satisfy
2022 if (TREE_CODE (x
) == CALL_EXPR
&& (call_expr_flags (x
) & ECF_CONST
) == 0)
2025 if (TREE_CODE (x
) == STRING_CST
)
2031 /* Return nonzero if X and Y appear to be the same candidate (or NULL) */
2033 candidate_equal_p (const_tree x
, const_tree y
)
2035 return (x
== y
) || (x
&& y
&& operand_equal_p (x
, y
, 0));
2038 /* Walk the tree X, and record accesses to variables. If X is written by the
2039 parent tree, WRITER is the parent.
2040 We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP. If this
2041 expression or its only operand forces a sequence point, then everything up
2042 to the sequence point is stored in PBEFORE_SP. Everything else gets stored
2044 Once we return, we will have emitted warnings if any subexpression before
2045 such a sequence point could be undefined. On a higher level, however, the
2046 sequence point may not be relevant, and we'll merge the two lists.
2048 Example: (b++, a) + b;
2049 The call that processes the COMPOUND_EXPR will store the increment of B
2050 in PBEFORE_SP, and the use of A in PNO_SP. The higher-level call that
2051 processes the PLUS_EXPR will need to merge the two lists so that
2052 eventually, all accesses end up on the same list (and we'll warn about the
2053 unordered subexpressions b++ and b.
2055 A note on merging. If we modify the former example so that our expression
2058 care must be taken not simply to add all three expressions into the final
2059 PNO_SP list. The function merge_tlist takes care of that by merging the
2060 before-SP list of the COMPOUND_EXPR into its after-SP list in a special
2061 way, so that no more than one access to B is recorded. */
2064 verify_tree (tree x
, struct tlist
**pbefore_sp
, struct tlist
**pno_sp
,
2067 struct tlist
*tmp_before
, *tmp_nosp
, *tmp_list2
, *tmp_list3
;
2068 enum tree_code code
;
2069 enum tree_code_class cl
;
2071 /* X may be NULL if it is the operand of an empty statement expression
2077 code
= TREE_CODE (x
);
2078 cl
= TREE_CODE_CLASS (code
);
2080 if (warning_candidate_p (x
))
2081 *pno_sp
= new_tlist (*pno_sp
, x
, writer
);
2090 case TRUTH_ANDIF_EXPR
:
2091 case TRUTH_ORIF_EXPR
:
2092 tmp_before
= tmp_nosp
= tmp_list2
= tmp_list3
= 0;
2093 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
2094 warn_for_collisions (tmp_nosp
);
2095 merge_tlist (pbefore_sp
, tmp_before
, 0);
2096 merge_tlist (pbefore_sp
, tmp_nosp
, 0);
2097 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, &tmp_list2
, NULL_TREE
);
2098 warn_for_collisions (tmp_list2
);
2099 merge_tlist (pbefore_sp
, tmp_list3
, 0);
2100 merge_tlist (pno_sp
, tmp_list2
, 0);
2104 tmp_before
= tmp_list2
= 0;
2105 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_list2
, NULL_TREE
);
2106 warn_for_collisions (tmp_list2
);
2107 merge_tlist (pbefore_sp
, tmp_before
, 0);
2108 merge_tlist (pbefore_sp
, tmp_list2
, 0);
2110 tmp_list3
= tmp_nosp
= 0;
2111 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, &tmp_nosp
, NULL_TREE
);
2112 warn_for_collisions (tmp_nosp
);
2113 merge_tlist (pbefore_sp
, tmp_list3
, 0);
2115 tmp_list3
= tmp_list2
= 0;
2116 verify_tree (TREE_OPERAND (x
, 2), &tmp_list3
, &tmp_list2
, NULL_TREE
);
2117 warn_for_collisions (tmp_list2
);
2118 merge_tlist (pbefore_sp
, tmp_list3
, 0);
2119 /* Rather than add both tmp_nosp and tmp_list2, we have to merge the
2120 two first, to avoid warning for (a ? b++ : b++). */
2121 merge_tlist (&tmp_nosp
, tmp_list2
, 0);
2122 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
2125 case PREDECREMENT_EXPR
:
2126 case PREINCREMENT_EXPR
:
2127 case POSTDECREMENT_EXPR
:
2128 case POSTINCREMENT_EXPR
:
2129 verify_tree (TREE_OPERAND (x
, 0), pno_sp
, pno_sp
, x
);
2133 tmp_before
= tmp_nosp
= tmp_list3
= 0;
2134 verify_tree (TREE_OPERAND (x
, 1), &tmp_before
, &tmp_nosp
, NULL_TREE
);
2135 verify_tree (TREE_OPERAND (x
, 0), &tmp_list3
, &tmp_list3
, x
);
2136 /* Expressions inside the LHS are not ordered wrt. the sequence points
2137 in the RHS. Example:
2139 Despite the fact that the modification of "a" is in the before_sp
2140 list (tmp_before), it conflicts with the use of "a" in the LHS.
2141 We can handle this by adding the contents of tmp_list3
2142 to those of tmp_before, and redoing the collision warnings for that
2144 add_tlist (&tmp_before
, tmp_list3
, x
, 1);
2145 warn_for_collisions (tmp_before
);
2146 /* Exclude the LHS itself here; we first have to merge it into the
2147 tmp_nosp list. This is done to avoid warning for "a = a"; if we
2148 didn't exclude the LHS, we'd get it twice, once as a read and once
2150 add_tlist (pno_sp
, tmp_list3
, x
, 0);
2151 warn_for_collisions_1 (TREE_OPERAND (x
, 0), x
, tmp_nosp
, 1);
2153 merge_tlist (pbefore_sp
, tmp_before
, 0);
2154 if (warning_candidate_p (TREE_OPERAND (x
, 0)))
2155 merge_tlist (&tmp_nosp
, new_tlist (NULL
, TREE_OPERAND (x
, 0), x
), 0);
2156 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 1);
2160 /* We need to warn about conflicts among arguments and conflicts between
2161 args and the function address. Side effects of the function address,
2162 however, are not ordered by the sequence point of the call. */
2164 call_expr_arg_iterator iter
;
2166 tmp_before
= tmp_nosp
= 0;
2167 verify_tree (CALL_EXPR_FN (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
2168 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, x
)
2170 tmp_list2
= tmp_list3
= 0;
2171 verify_tree (arg
, &tmp_list2
, &tmp_list3
, NULL_TREE
);
2172 merge_tlist (&tmp_list3
, tmp_list2
, 0);
2173 add_tlist (&tmp_before
, tmp_list3
, NULL_TREE
, 0);
2175 add_tlist (&tmp_before
, tmp_nosp
, NULL_TREE
, 0);
2176 warn_for_collisions (tmp_before
);
2177 add_tlist (pbefore_sp
, tmp_before
, NULL_TREE
, 0);
2182 /* Scan all the list, e.g. indices of multi dimensional array. */
2185 tmp_before
= tmp_nosp
= 0;
2186 verify_tree (TREE_VALUE (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
2187 merge_tlist (&tmp_nosp
, tmp_before
, 0);
2188 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
2195 struct tlist_cache
*t
;
2196 for (t
= save_expr_cache
; t
; t
= t
->next
)
2197 if (candidate_equal_p (t
->expr
, x
))
2202 t
= XOBNEW (&tlist_obstack
, struct tlist_cache
);
2203 t
->next
= save_expr_cache
;
2205 save_expr_cache
= t
;
2207 tmp_before
= tmp_nosp
= 0;
2208 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
2209 warn_for_collisions (tmp_nosp
);
2212 merge_tlist (&tmp_list3
, tmp_nosp
, 0);
2213 t
->cache_before_sp
= tmp_before
;
2214 t
->cache_after_sp
= tmp_list3
;
2216 merge_tlist (pbefore_sp
, t
->cache_before_sp
, 1);
2217 add_tlist (pno_sp
, t
->cache_after_sp
, NULL_TREE
, 1);
2222 x
= TREE_OPERAND (x
, 0);
2229 /* For other expressions, simply recurse on their operands.
2230 Manual tail recursion for unary expressions.
2231 Other non-expressions need not be processed. */
2232 if (cl
== tcc_unary
)
2234 x
= TREE_OPERAND (x
, 0);
2238 else if (IS_EXPR_CODE_CLASS (cl
))
2241 int max
= TREE_OPERAND_LENGTH (x
);
2242 for (lp
= 0; lp
< max
; lp
++)
2244 tmp_before
= tmp_nosp
= 0;
2245 verify_tree (TREE_OPERAND (x
, lp
), &tmp_before
, &tmp_nosp
, 0);
2246 merge_tlist (&tmp_nosp
, tmp_before
, 0);
2247 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
2254 /* Try to warn for undefined behavior in EXPR due to missing sequence
2258 verify_sequence_points (tree expr
)
2260 struct tlist
*before_sp
= 0, *after_sp
= 0;
2263 save_expr_cache
= 0;
2264 if (tlist_firstobj
== 0)
2266 gcc_obstack_init (&tlist_obstack
);
2267 tlist_firstobj
= (char *) obstack_alloc (&tlist_obstack
, 0);
2270 verify_tree (expr
, &before_sp
, &after_sp
, 0);
2271 warn_for_collisions (after_sp
);
2272 obstack_free (&tlist_obstack
, tlist_firstobj
);
2275 /* Validate the expression after `case' and apply default promotions. */
2278 check_case_value (location_t loc
, tree value
)
2280 if (value
== NULL_TREE
)
2283 if (TREE_CODE (value
) == INTEGER_CST
)
2284 /* Promote char or short to int. */
2285 value
= perform_integral_promotions (value
);
2286 else if (value
!= error_mark_node
)
2288 error_at (loc
, "case label does not reduce to an integer constant");
2289 value
= error_mark_node
;
2292 constant_expression_warning (value
);
2297 /* See if the case values LOW and HIGH are in the range of the original
2298 type (i.e. before the default conversion to int) of the switch testing
2300 TYPE is the promoted type of the testing expression, and ORIG_TYPE is
2301 the type before promoting it. CASE_LOW_P is a pointer to the lower
2302 bound of the case label, and CASE_HIGH_P is the upper bound or NULL
2303 if the case is not a case range.
2304 The caller has to make sure that we are not called with NULL for
2305 CASE_LOW_P (i.e. the default case). OUTSIDE_RANGE_P says whether there
2306 was a case value that doesn't fit into the range of the ORIG_TYPE.
2307 Returns true if the case label is in range of ORIG_TYPE (saturated or
2308 untouched) or false if the label is out of range. */
2311 check_case_bounds (location_t loc
, tree type
, tree orig_type
,
2312 tree
*case_low_p
, tree
*case_high_p
,
2313 bool *outside_range_p
)
2315 tree min_value
, max_value
;
2316 tree case_low
= *case_low_p
;
2317 tree case_high
= case_high_p
? *case_high_p
: case_low
;
2319 /* If there was a problem with the original type, do nothing. */
2320 if (orig_type
== error_mark_node
)
2323 min_value
= TYPE_MIN_VALUE (orig_type
);
2324 max_value
= TYPE_MAX_VALUE (orig_type
);
2326 /* We'll really need integer constants here. */
2327 case_low
= fold (case_low
);
2328 case_high
= fold (case_high
);
2330 /* Case label is less than minimum for type. */
2331 if (tree_int_cst_compare (case_low
, min_value
) < 0
2332 && tree_int_cst_compare (case_high
, min_value
) < 0)
2334 warning_at (loc
, 0, "case label value is less than minimum value "
2336 *outside_range_p
= true;
2340 /* Case value is greater than maximum for type. */
2341 if (tree_int_cst_compare (case_low
, max_value
) > 0
2342 && tree_int_cst_compare (case_high
, max_value
) > 0)
2344 warning_at (loc
, 0, "case label value exceeds maximum value for type");
2345 *outside_range_p
= true;
2349 /* Saturate lower case label value to minimum. */
2350 if (tree_int_cst_compare (case_high
, min_value
) >= 0
2351 && tree_int_cst_compare (case_low
, min_value
) < 0)
2353 warning_at (loc
, 0, "lower value in case label range"
2354 " less than minimum value for type");
2355 *outside_range_p
= true;
2356 case_low
= min_value
;
2359 /* Saturate upper case label value to maximum. */
2360 if (tree_int_cst_compare (case_low
, max_value
) <= 0
2361 && tree_int_cst_compare (case_high
, max_value
) > 0)
2363 warning_at (loc
, 0, "upper value in case label range"
2364 " exceeds maximum value for type");
2365 *outside_range_p
= true;
2366 case_high
= max_value
;
2369 if (*case_low_p
!= case_low
)
2370 *case_low_p
= convert (type
, case_low
);
2371 if (case_high_p
&& *case_high_p
!= case_high
)
2372 *case_high_p
= convert (type
, case_high
);
2377 /* Return an integer type with BITS bits of precision,
2378 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
2381 c_common_type_for_size (unsigned int bits
, int unsignedp
)
2385 if (bits
== TYPE_PRECISION (integer_type_node
))
2386 return unsignedp
? unsigned_type_node
: integer_type_node
;
2388 if (bits
== TYPE_PRECISION (signed_char_type_node
))
2389 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
2391 if (bits
== TYPE_PRECISION (short_integer_type_node
))
2392 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
2394 if (bits
== TYPE_PRECISION (long_integer_type_node
))
2395 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
2397 if (bits
== TYPE_PRECISION (long_long_integer_type_node
))
2398 return (unsignedp
? long_long_unsigned_type_node
2399 : long_long_integer_type_node
);
2401 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
2402 if (int_n_enabled_p
[i
]
2403 && bits
== int_n_data
[i
].bitsize
)
2404 return (unsignedp
? int_n_trees
[i
].unsigned_type
2405 : int_n_trees
[i
].signed_type
);
2407 if (bits
== TYPE_PRECISION (widest_integer_literal_type_node
))
2408 return (unsignedp
? widest_unsigned_literal_type_node
2409 : widest_integer_literal_type_node
);
2411 if (bits
<= TYPE_PRECISION (intQI_type_node
))
2412 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
2414 if (bits
<= TYPE_PRECISION (intHI_type_node
))
2415 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
2417 if (bits
<= TYPE_PRECISION (intSI_type_node
))
2418 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
2420 if (bits
<= TYPE_PRECISION (intDI_type_node
))
2421 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
2426 /* Return a fixed-point type that has at least IBIT ibits and FBIT fbits
2427 that is unsigned if UNSIGNEDP is nonzero, otherwise signed;
2428 and saturating if SATP is nonzero, otherwise not saturating. */
2431 c_common_fixed_point_type_for_size (unsigned int ibit
, unsigned int fbit
,
2432 int unsignedp
, int satp
)
2436 mode
= unsignedp
? UQQmode
: QQmode
;
2438 mode
= unsignedp
? UHAmode
: HAmode
;
2440 for (; mode
!= VOIDmode
; mode
= GET_MODE_WIDER_MODE (mode
))
2441 if (GET_MODE_IBIT (mode
) >= ibit
&& GET_MODE_FBIT (mode
) >= fbit
)
2444 if (mode
== VOIDmode
|| !targetm
.scalar_mode_supported_p (mode
))
2446 sorry ("GCC cannot support operators with integer types and "
2447 "fixed-point types that have too many integral and "
2448 "fractional bits together");
2452 return c_common_type_for_mode (mode
, satp
);
2455 /* Used for communication between c_common_type_for_mode and
2456 c_register_builtin_type. */
2457 tree registered_builtin_types
;
2459 /* Return a data type that has machine mode MODE.
2460 If the mode is an integer,
2461 then UNSIGNEDP selects between signed and unsigned types.
2462 If the mode is a fixed-point mode,
2463 then UNSIGNEDP selects between saturating and nonsaturating types. */
2466 c_common_type_for_mode (machine_mode mode
, int unsignedp
)
2471 if (mode
== TYPE_MODE (integer_type_node
))
2472 return unsignedp
? unsigned_type_node
: integer_type_node
;
2474 if (mode
== TYPE_MODE (signed_char_type_node
))
2475 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
2477 if (mode
== TYPE_MODE (short_integer_type_node
))
2478 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
2480 if (mode
== TYPE_MODE (long_integer_type_node
))
2481 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
2483 if (mode
== TYPE_MODE (long_long_integer_type_node
))
2484 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
2486 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
2487 if (int_n_enabled_p
[i
]
2488 && mode
== int_n_data
[i
].m
)
2489 return (unsignedp
? int_n_trees
[i
].unsigned_type
2490 : int_n_trees
[i
].signed_type
);
2492 if (mode
== TYPE_MODE (widest_integer_literal_type_node
))
2493 return unsignedp
? widest_unsigned_literal_type_node
2494 : widest_integer_literal_type_node
;
2497 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
2500 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
2503 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
2506 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
2508 #if HOST_BITS_PER_WIDE_INT >= 64
2509 if (mode
== TYPE_MODE (intTI_type_node
))
2510 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
2513 if (mode
== TYPE_MODE (float_type_node
))
2514 return float_type_node
;
2516 if (mode
== TYPE_MODE (double_type_node
))
2517 return double_type_node
;
2519 if (mode
== TYPE_MODE (long_double_type_node
))
2520 return long_double_type_node
;
2522 for (i
= 0; i
< NUM_FLOATN_NX_TYPES
; i
++)
2523 if (FLOATN_NX_TYPE_NODE (i
) != NULL_TREE
2524 && mode
== TYPE_MODE (FLOATN_NX_TYPE_NODE (i
)))
2525 return FLOATN_NX_TYPE_NODE (i
);
2527 if (mode
== TYPE_MODE (void_type_node
))
2528 return void_type_node
;
2530 if (mode
== TYPE_MODE (build_pointer_type (char_type_node
)))
2532 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
2533 : make_signed_type (GET_MODE_PRECISION (mode
)));
2535 if (mode
== TYPE_MODE (build_pointer_type (integer_type_node
)))
2537 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
2538 : make_signed_type (GET_MODE_PRECISION (mode
)));
2540 if (COMPLEX_MODE_P (mode
))
2542 machine_mode inner_mode
;
2545 if (mode
== TYPE_MODE (complex_float_type_node
))
2546 return complex_float_type_node
;
2547 if (mode
== TYPE_MODE (complex_double_type_node
))
2548 return complex_double_type_node
;
2549 if (mode
== TYPE_MODE (complex_long_double_type_node
))
2550 return complex_long_double_type_node
;
2552 for (i
= 0; i
< NUM_FLOATN_NX_TYPES
; i
++)
2553 if (COMPLEX_FLOATN_NX_TYPE_NODE (i
) != NULL_TREE
2554 && mode
== TYPE_MODE (COMPLEX_FLOATN_NX_TYPE_NODE (i
)))
2555 return COMPLEX_FLOATN_NX_TYPE_NODE (i
);
2557 if (mode
== TYPE_MODE (complex_integer_type_node
) && !unsignedp
)
2558 return complex_integer_type_node
;
2560 inner_mode
= GET_MODE_INNER (mode
);
2561 inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
2562 if (inner_type
!= NULL_TREE
)
2563 return build_complex_type (inner_type
);
2565 else if (VECTOR_MODE_P (mode
))
2567 machine_mode inner_mode
= GET_MODE_INNER (mode
);
2568 tree inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
2569 if (inner_type
!= NULL_TREE
)
2570 return build_vector_type_for_mode (inner_type
, mode
);
2573 if (mode
== TYPE_MODE (dfloat32_type_node
))
2574 return dfloat32_type_node
;
2575 if (mode
== TYPE_MODE (dfloat64_type_node
))
2576 return dfloat64_type_node
;
2577 if (mode
== TYPE_MODE (dfloat128_type_node
))
2578 return dfloat128_type_node
;
2580 if (ALL_SCALAR_FIXED_POINT_MODE_P (mode
))
2582 if (mode
== TYPE_MODE (short_fract_type_node
))
2583 return unsignedp
? sat_short_fract_type_node
: short_fract_type_node
;
2584 if (mode
== TYPE_MODE (fract_type_node
))
2585 return unsignedp
? sat_fract_type_node
: fract_type_node
;
2586 if (mode
== TYPE_MODE (long_fract_type_node
))
2587 return unsignedp
? sat_long_fract_type_node
: long_fract_type_node
;
2588 if (mode
== TYPE_MODE (long_long_fract_type_node
))
2589 return unsignedp
? sat_long_long_fract_type_node
2590 : long_long_fract_type_node
;
2592 if (mode
== TYPE_MODE (unsigned_short_fract_type_node
))
2593 return unsignedp
? sat_unsigned_short_fract_type_node
2594 : unsigned_short_fract_type_node
;
2595 if (mode
== TYPE_MODE (unsigned_fract_type_node
))
2596 return unsignedp
? sat_unsigned_fract_type_node
2597 : unsigned_fract_type_node
;
2598 if (mode
== TYPE_MODE (unsigned_long_fract_type_node
))
2599 return unsignedp
? sat_unsigned_long_fract_type_node
2600 : unsigned_long_fract_type_node
;
2601 if (mode
== TYPE_MODE (unsigned_long_long_fract_type_node
))
2602 return unsignedp
? sat_unsigned_long_long_fract_type_node
2603 : unsigned_long_long_fract_type_node
;
2605 if (mode
== TYPE_MODE (short_accum_type_node
))
2606 return unsignedp
? sat_short_accum_type_node
: short_accum_type_node
;
2607 if (mode
== TYPE_MODE (accum_type_node
))
2608 return unsignedp
? sat_accum_type_node
: accum_type_node
;
2609 if (mode
== TYPE_MODE (long_accum_type_node
))
2610 return unsignedp
? sat_long_accum_type_node
: long_accum_type_node
;
2611 if (mode
== TYPE_MODE (long_long_accum_type_node
))
2612 return unsignedp
? sat_long_long_accum_type_node
2613 : long_long_accum_type_node
;
2615 if (mode
== TYPE_MODE (unsigned_short_accum_type_node
))
2616 return unsignedp
? sat_unsigned_short_accum_type_node
2617 : unsigned_short_accum_type_node
;
2618 if (mode
== TYPE_MODE (unsigned_accum_type_node
))
2619 return unsignedp
? sat_unsigned_accum_type_node
2620 : unsigned_accum_type_node
;
2621 if (mode
== TYPE_MODE (unsigned_long_accum_type_node
))
2622 return unsignedp
? sat_unsigned_long_accum_type_node
2623 : unsigned_long_accum_type_node
;
2624 if (mode
== TYPE_MODE (unsigned_long_long_accum_type_node
))
2625 return unsignedp
? sat_unsigned_long_long_accum_type_node
2626 : unsigned_long_long_accum_type_node
;
2629 return unsignedp
? sat_qq_type_node
: qq_type_node
;
2631 return unsignedp
? sat_hq_type_node
: hq_type_node
;
2633 return unsignedp
? sat_sq_type_node
: sq_type_node
;
2635 return unsignedp
? sat_dq_type_node
: dq_type_node
;
2637 return unsignedp
? sat_tq_type_node
: tq_type_node
;
2639 if (mode
== UQQmode
)
2640 return unsignedp
? sat_uqq_type_node
: uqq_type_node
;
2641 if (mode
== UHQmode
)
2642 return unsignedp
? sat_uhq_type_node
: uhq_type_node
;
2643 if (mode
== USQmode
)
2644 return unsignedp
? sat_usq_type_node
: usq_type_node
;
2645 if (mode
== UDQmode
)
2646 return unsignedp
? sat_udq_type_node
: udq_type_node
;
2647 if (mode
== UTQmode
)
2648 return unsignedp
? sat_utq_type_node
: utq_type_node
;
2651 return unsignedp
? sat_ha_type_node
: ha_type_node
;
2653 return unsignedp
? sat_sa_type_node
: sa_type_node
;
2655 return unsignedp
? sat_da_type_node
: da_type_node
;
2657 return unsignedp
? sat_ta_type_node
: ta_type_node
;
2659 if (mode
== UHAmode
)
2660 return unsignedp
? sat_uha_type_node
: uha_type_node
;
2661 if (mode
== USAmode
)
2662 return unsignedp
? sat_usa_type_node
: usa_type_node
;
2663 if (mode
== UDAmode
)
2664 return unsignedp
? sat_uda_type_node
: uda_type_node
;
2665 if (mode
== UTAmode
)
2666 return unsignedp
? sat_uta_type_node
: uta_type_node
;
2669 for (t
= registered_builtin_types
; t
; t
= TREE_CHAIN (t
))
2670 if (TYPE_MODE (TREE_VALUE (t
)) == mode
2671 && !!unsignedp
== !!TYPE_UNSIGNED (TREE_VALUE (t
)))
2672 return TREE_VALUE (t
);
2678 c_common_unsigned_type (tree type
)
2680 return c_common_signed_or_unsigned_type (1, type
);
2683 /* Return a signed type the same as TYPE in other respects. */
2686 c_common_signed_type (tree type
)
2688 return c_common_signed_or_unsigned_type (0, type
);
2691 /* Return a type the same as TYPE except unsigned or
2692 signed according to UNSIGNEDP. */
2695 c_common_signed_or_unsigned_type (int unsignedp
, tree type
)
2700 /* This block of code emulates the behavior of the old
2701 c_common_unsigned_type. In particular, it returns
2702 long_unsigned_type_node if passed a long, even when a int would
2703 have the same size. This is necessary for warnings to work
2704 correctly in archs where sizeof(int) == sizeof(long) */
2706 type1
= TYPE_MAIN_VARIANT (type
);
2707 if (type1
== signed_char_type_node
|| type1
== char_type_node
|| type1
== unsigned_char_type_node
)
2708 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
2709 if (type1
== integer_type_node
|| type1
== unsigned_type_node
)
2710 return unsignedp
? unsigned_type_node
: integer_type_node
;
2711 if (type1
== short_integer_type_node
|| type1
== short_unsigned_type_node
)
2712 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
2713 if (type1
== long_integer_type_node
|| type1
== long_unsigned_type_node
)
2714 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
2715 if (type1
== long_long_integer_type_node
|| type1
== long_long_unsigned_type_node
)
2716 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
2718 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
2719 if (int_n_enabled_p
[i
]
2720 && (type1
== int_n_trees
[i
].unsigned_type
2721 || type1
== int_n_trees
[i
].signed_type
))
2722 return (unsignedp
? int_n_trees
[i
].unsigned_type
2723 : int_n_trees
[i
].signed_type
);
2725 if (type1
== widest_integer_literal_type_node
|| type1
== widest_unsigned_literal_type_node
)
2726 return unsignedp
? widest_unsigned_literal_type_node
: widest_integer_literal_type_node
;
2727 #if HOST_BITS_PER_WIDE_INT >= 64
2728 if (type1
== intTI_type_node
|| type1
== unsigned_intTI_type_node
)
2729 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
2731 if (type1
== intDI_type_node
|| type1
== unsigned_intDI_type_node
)
2732 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
2733 if (type1
== intSI_type_node
|| type1
== unsigned_intSI_type_node
)
2734 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
2735 if (type1
== intHI_type_node
|| type1
== unsigned_intHI_type_node
)
2736 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
2737 if (type1
== intQI_type_node
|| type1
== unsigned_intQI_type_node
)
2738 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
2740 #define C_COMMON_FIXED_TYPES(NAME) \
2741 if (type1 == short_ ## NAME ## _type_node \
2742 || type1 == unsigned_short_ ## NAME ## _type_node) \
2743 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
2744 : short_ ## NAME ## _type_node; \
2745 if (type1 == NAME ## _type_node \
2746 || type1 == unsigned_ ## NAME ## _type_node) \
2747 return unsignedp ? unsigned_ ## NAME ## _type_node \
2748 : NAME ## _type_node; \
2749 if (type1 == long_ ## NAME ## _type_node \
2750 || type1 == unsigned_long_ ## NAME ## _type_node) \
2751 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
2752 : long_ ## NAME ## _type_node; \
2753 if (type1 == long_long_ ## NAME ## _type_node \
2754 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
2755 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
2756 : long_long_ ## NAME ## _type_node;
2758 #define C_COMMON_FIXED_MODE_TYPES(NAME) \
2759 if (type1 == NAME ## _type_node \
2760 || type1 == u ## NAME ## _type_node) \
2761 return unsignedp ? u ## NAME ## _type_node \
2762 : NAME ## _type_node;
2764 #define C_COMMON_FIXED_TYPES_SAT(NAME) \
2765 if (type1 == sat_ ## short_ ## NAME ## _type_node \
2766 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
2767 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
2768 : sat_ ## short_ ## NAME ## _type_node; \
2769 if (type1 == sat_ ## NAME ## _type_node \
2770 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
2771 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
2772 : sat_ ## NAME ## _type_node; \
2773 if (type1 == sat_ ## long_ ## NAME ## _type_node \
2774 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
2775 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
2776 : sat_ ## long_ ## NAME ## _type_node; \
2777 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
2778 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
2779 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
2780 : sat_ ## long_long_ ## NAME ## _type_node;
2782 #define C_COMMON_FIXED_MODE_TYPES_SAT(NAME) \
2783 if (type1 == sat_ ## NAME ## _type_node \
2784 || type1 == sat_ ## u ## NAME ## _type_node) \
2785 return unsignedp ? sat_ ## u ## NAME ## _type_node \
2786 : sat_ ## NAME ## _type_node;
2788 C_COMMON_FIXED_TYPES (fract
);
2789 C_COMMON_FIXED_TYPES_SAT (fract
);
2790 C_COMMON_FIXED_TYPES (accum
);
2791 C_COMMON_FIXED_TYPES_SAT (accum
);
2793 C_COMMON_FIXED_MODE_TYPES (qq
);
2794 C_COMMON_FIXED_MODE_TYPES (hq
);
2795 C_COMMON_FIXED_MODE_TYPES (sq
);
2796 C_COMMON_FIXED_MODE_TYPES (dq
);
2797 C_COMMON_FIXED_MODE_TYPES (tq
);
2798 C_COMMON_FIXED_MODE_TYPES_SAT (qq
);
2799 C_COMMON_FIXED_MODE_TYPES_SAT (hq
);
2800 C_COMMON_FIXED_MODE_TYPES_SAT (sq
);
2801 C_COMMON_FIXED_MODE_TYPES_SAT (dq
);
2802 C_COMMON_FIXED_MODE_TYPES_SAT (tq
);
2803 C_COMMON_FIXED_MODE_TYPES (ha
);
2804 C_COMMON_FIXED_MODE_TYPES (sa
);
2805 C_COMMON_FIXED_MODE_TYPES (da
);
2806 C_COMMON_FIXED_MODE_TYPES (ta
);
2807 C_COMMON_FIXED_MODE_TYPES_SAT (ha
);
2808 C_COMMON_FIXED_MODE_TYPES_SAT (sa
);
2809 C_COMMON_FIXED_MODE_TYPES_SAT (da
);
2810 C_COMMON_FIXED_MODE_TYPES_SAT (ta
);
2812 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
2813 the precision; they have precision set to match their range, but
2814 may use a wider mode to match an ABI. If we change modes, we may
2815 wind up with bad conversions. For INTEGER_TYPEs in C, must check
2816 the precision as well, so as to yield correct results for
2817 bit-field types. C++ does not have these separate bit-field
2818 types, and producing a signed or unsigned variant of an
2819 ENUMERAL_TYPE may cause other problems as well. */
2821 if (!INTEGRAL_TYPE_P (type
)
2822 || TYPE_UNSIGNED (type
) == unsignedp
)
2825 #define TYPE_OK(node) \
2826 (TYPE_MODE (type) == TYPE_MODE (node) \
2827 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
2828 if (TYPE_OK (signed_char_type_node
))
2829 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
2830 if (TYPE_OK (integer_type_node
))
2831 return unsignedp
? unsigned_type_node
: integer_type_node
;
2832 if (TYPE_OK (short_integer_type_node
))
2833 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
2834 if (TYPE_OK (long_integer_type_node
))
2835 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
2836 if (TYPE_OK (long_long_integer_type_node
))
2837 return (unsignedp
? long_long_unsigned_type_node
2838 : long_long_integer_type_node
);
2840 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
2841 if (int_n_enabled_p
[i
]
2842 && TYPE_MODE (type
) == int_n_data
[i
].m
2843 && TYPE_PRECISION (type
) == int_n_data
[i
].bitsize
)
2844 return (unsignedp
? int_n_trees
[i
].unsigned_type
2845 : int_n_trees
[i
].signed_type
);
2847 if (TYPE_OK (widest_integer_literal_type_node
))
2848 return (unsignedp
? widest_unsigned_literal_type_node
2849 : widest_integer_literal_type_node
);
2851 #if HOST_BITS_PER_WIDE_INT >= 64
2852 if (TYPE_OK (intTI_type_node
))
2853 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
2855 if (TYPE_OK (intDI_type_node
))
2856 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
2857 if (TYPE_OK (intSI_type_node
))
2858 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
2859 if (TYPE_OK (intHI_type_node
))
2860 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
2861 if (TYPE_OK (intQI_type_node
))
2862 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
2865 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
2868 /* Build a bit-field integer type for the given WIDTH and UNSIGNEDP. */
2871 c_build_bitfield_integer_type (unsigned HOST_WIDE_INT width
, int unsignedp
)
2875 /* Extended integer types of the same width as a standard type have
2876 lesser rank, so those of the same width as int promote to int or
2877 unsigned int and are valid for printf formats expecting int or
2878 unsigned int. To avoid such special cases, avoid creating
2879 extended integer types for bit-fields if a standard integer type
2881 if (width
== TYPE_PRECISION (integer_type_node
))
2882 return unsignedp
? unsigned_type_node
: integer_type_node
;
2883 if (width
== TYPE_PRECISION (signed_char_type_node
))
2884 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
2885 if (width
== TYPE_PRECISION (short_integer_type_node
))
2886 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
2887 if (width
== TYPE_PRECISION (long_integer_type_node
))
2888 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
2889 if (width
== TYPE_PRECISION (long_long_integer_type_node
))
2890 return (unsignedp
? long_long_unsigned_type_node
2891 : long_long_integer_type_node
);
2892 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
2893 if (int_n_enabled_p
[i
]
2894 && width
== int_n_data
[i
].bitsize
)
2895 return (unsignedp
? int_n_trees
[i
].unsigned_type
2896 : int_n_trees
[i
].signed_type
);
2897 return build_nonstandard_integer_type (width
, unsignedp
);
2900 /* The C version of the register_builtin_type langhook. */
2903 c_register_builtin_type (tree type
, const char* name
)
2907 decl
= build_decl (UNKNOWN_LOCATION
,
2908 TYPE_DECL
, get_identifier (name
), type
);
2909 DECL_ARTIFICIAL (decl
) = 1;
2910 if (!TYPE_NAME (type
))
2911 TYPE_NAME (type
) = decl
;
2914 registered_builtin_types
= tree_cons (0, type
, registered_builtin_types
);
2917 /* Print an error message for invalid operands to arith operation
2918 CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
2919 RICHLOC is a rich location for the message, containing either
2920 three separate locations for each of the operator and operands
2925 (C FE), or one location ranging over all over them
2933 binary_op_error (rich_location
*richloc
, enum tree_code code
,
2934 tree type0
, tree type1
)
2941 opname
= "+"; break;
2943 opname
= "-"; break;
2945 opname
= "*"; break;
2947 opname
= "max"; break;
2949 opname
= "min"; break;
2951 opname
= "=="; break;
2953 opname
= "!="; break;
2955 opname
= "<="; break;
2957 opname
= ">="; break;
2959 opname
= "<"; break;
2961 opname
= ">"; break;
2963 opname
= "<<"; break;
2965 opname
= ">>"; break;
2966 case TRUNC_MOD_EXPR
:
2967 case FLOOR_MOD_EXPR
:
2968 opname
= "%"; break;
2969 case TRUNC_DIV_EXPR
:
2970 case FLOOR_DIV_EXPR
:
2971 opname
= "/"; break;
2973 opname
= "&"; break;
2975 opname
= "|"; break;
2976 case TRUTH_ANDIF_EXPR
:
2977 opname
= "&&"; break;
2978 case TRUTH_ORIF_EXPR
:
2979 opname
= "||"; break;
2981 opname
= "^"; break;
2985 error_at_rich_loc (richloc
,
2986 "invalid operands to binary %s (have %qT and %qT)",
2987 opname
, type0
, type1
);
2990 /* Given an expression as a tree, return its original type. Do this
2991 by stripping any conversion that preserves the sign and precision. */
2993 expr_original_type (tree expr
)
2995 STRIP_SIGN_NOPS (expr
);
2996 return TREE_TYPE (expr
);
2999 /* Subroutine of build_binary_op, used for comparison operations.
3000 See if the operands have both been converted from subword integer types
3001 and, if so, perhaps change them both back to their original type.
3002 This function is also responsible for converting the two operands
3003 to the proper common type for comparison.
3005 The arguments of this function are all pointers to local variables
3006 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
3007 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
3009 LOC is the location of the comparison.
3011 If this function returns nonzero, it means that the comparison has
3012 a constant value. What this function returns is an expression for
3016 shorten_compare (location_t loc
, tree
*op0_ptr
, tree
*op1_ptr
,
3017 tree
*restype_ptr
, enum tree_code
*rescode_ptr
)
3020 tree op0
= *op0_ptr
;
3021 tree op1
= *op1_ptr
;
3022 int unsignedp0
, unsignedp1
;
3024 tree primop0
, primop1
;
3025 enum tree_code code
= *rescode_ptr
;
3027 /* Throw away any conversions to wider types
3028 already present in the operands. */
3030 primop0
= c_common_get_narrower (op0
, &unsignedp0
);
3031 primop1
= c_common_get_narrower (op1
, &unsignedp1
);
3033 /* If primopN is first sign-extended from primopN's precision to opN's
3034 precision, then zero-extended from opN's precision to
3035 *restype_ptr precision, shortenings might be invalid. */
3036 if (TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (TREE_TYPE (op0
))
3037 && TYPE_PRECISION (TREE_TYPE (op0
)) < TYPE_PRECISION (*restype_ptr
)
3039 && TYPE_UNSIGNED (TREE_TYPE (op0
)))
3041 if (TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (TREE_TYPE (op1
))
3042 && TYPE_PRECISION (TREE_TYPE (op1
)) < TYPE_PRECISION (*restype_ptr
)
3044 && TYPE_UNSIGNED (TREE_TYPE (op1
)))
3047 /* Handle the case that OP0 does not *contain* a conversion
3048 but it *requires* conversion to FINAL_TYPE. */
3050 if (op0
== primop0
&& TREE_TYPE (op0
) != *restype_ptr
)
3051 unsignedp0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
3052 if (op1
== primop1
&& TREE_TYPE (op1
) != *restype_ptr
)
3053 unsignedp1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
3055 /* If one of the operands must be floated, we cannot optimize. */
3056 real1
= TREE_CODE (TREE_TYPE (primop0
)) == REAL_TYPE
;
3057 real2
= TREE_CODE (TREE_TYPE (primop1
)) == REAL_TYPE
;
3059 /* If first arg is constant, swap the args (changing operation
3060 so value is preserved), for canonicalization. Don't do this if
3061 the second arg is 0. */
3063 if (TREE_CONSTANT (primop0
)
3064 && !integer_zerop (primop1
) && !real_zerop (primop1
)
3065 && !fixed_zerop (primop1
))
3067 std::swap (primop0
, primop1
);
3068 std::swap (op0
, op1
);
3071 std::swap (unsignedp0
, unsignedp1
);
3072 std::swap (real1
, real2
);
3091 *rescode_ptr
= code
;
3094 /* If comparing an integer against a constant more bits wide,
3095 maybe we can deduce a value of 1 or 0 independent of the data.
3096 Or else truncate the constant now
3097 rather than extend the variable at run time.
3099 This is only interesting if the constant is the wider arg.
3100 Also, it is not safe if the constant is unsigned and the
3101 variable arg is signed, since in this case the variable
3102 would be sign-extended and then regarded as unsigned.
3103 Our technique fails in this case because the lowest/highest
3104 possible unsigned results don't follow naturally from the
3105 lowest/highest possible values of the variable operand.
3106 For just EQ_EXPR and NE_EXPR there is another technique that
3107 could be used: see if the constant can be faithfully represented
3108 in the other operand's type, by truncating it and reextending it
3109 and see if that preserves the constant's value. */
3111 if (!real1
&& !real2
3112 && TREE_CODE (TREE_TYPE (primop0
)) != FIXED_POINT_TYPE
3113 && TREE_CODE (primop1
) == INTEGER_CST
3114 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
))
3116 int min_gt
, max_gt
, min_lt
, max_lt
;
3117 tree maxval
, minval
;
3118 /* 1 if comparison is nominally unsigned. */
3119 int unsignedp
= TYPE_UNSIGNED (*restype_ptr
);
3122 type
= c_common_signed_or_unsigned_type (unsignedp0
,
3123 TREE_TYPE (primop0
));
3125 maxval
= TYPE_MAX_VALUE (type
);
3126 minval
= TYPE_MIN_VALUE (type
);
3128 if (unsignedp
&& !unsignedp0
)
3129 *restype_ptr
= c_common_signed_type (*restype_ptr
);
3131 if (TREE_TYPE (primop1
) != *restype_ptr
)
3133 /* Convert primop1 to target type, but do not introduce
3134 additional overflow. We know primop1 is an int_cst. */
3135 primop1
= force_fit_type (*restype_ptr
,
3138 TYPE_PRECISION (*restype_ptr
)),
3139 0, TREE_OVERFLOW (primop1
));
3141 if (type
!= *restype_ptr
)
3143 minval
= convert (*restype_ptr
, minval
);
3144 maxval
= convert (*restype_ptr
, maxval
);
3147 min_gt
= tree_int_cst_lt (primop1
, minval
);
3148 max_gt
= tree_int_cst_lt (primop1
, maxval
);
3149 min_lt
= tree_int_cst_lt (minval
, primop1
);
3150 max_lt
= tree_int_cst_lt (maxval
, primop1
);
3153 /* This used to be a switch, but Genix compiler can't handle that. */
3154 if (code
== NE_EXPR
)
3156 if (max_lt
|| min_gt
)
3157 val
= truthvalue_true_node
;
3159 else if (code
== EQ_EXPR
)
3161 if (max_lt
|| min_gt
)
3162 val
= truthvalue_false_node
;
3164 else if (code
== LT_EXPR
)
3167 val
= truthvalue_true_node
;
3169 val
= truthvalue_false_node
;
3171 else if (code
== GT_EXPR
)
3174 val
= truthvalue_true_node
;
3176 val
= truthvalue_false_node
;
3178 else if (code
== LE_EXPR
)
3181 val
= truthvalue_true_node
;
3183 val
= truthvalue_false_node
;
3185 else if (code
== GE_EXPR
)
3188 val
= truthvalue_true_node
;
3190 val
= truthvalue_false_node
;
3193 /* If primop0 was sign-extended and unsigned comparison specd,
3194 we did a signed comparison above using the signed type bounds.
3195 But the comparison we output must be unsigned.
3197 Also, for inequalities, VAL is no good; but if the signed
3198 comparison had *any* fixed result, it follows that the
3199 unsigned comparison just tests the sign in reverse
3200 (positive values are LE, negative ones GE).
3201 So we can generate an unsigned comparison
3202 against an extreme value of the signed type. */
3204 if (unsignedp
&& !unsignedp0
)
3211 primop1
= TYPE_MIN_VALUE (type
);
3217 primop1
= TYPE_MAX_VALUE (type
);
3224 type
= c_common_unsigned_type (type
);
3227 if (TREE_CODE (primop0
) != INTEGER_CST
3228 /* Don't warn if it's from a (non-system) macro. */
3229 && !(from_macro_expansion_at
3230 (expansion_point_location_if_in_system_header
3231 (EXPR_LOCATION (primop0
)))))
3233 if (val
== truthvalue_false_node
)
3234 warning_at (loc
, OPT_Wtype_limits
,
3235 "comparison is always false due to limited range of data type");
3236 if (val
== truthvalue_true_node
)
3237 warning_at (loc
, OPT_Wtype_limits
,
3238 "comparison is always true due to limited range of data type");
3243 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
3244 if (TREE_SIDE_EFFECTS (primop0
))
3245 return build2 (COMPOUND_EXPR
, TREE_TYPE (val
), primop0
, val
);
3249 /* Value is not predetermined, but do the comparison
3250 in the type of the operand that is not constant.
3251 TYPE is already properly set. */
3254 /* If either arg is decimal float and the other is float, find the
3255 proper common type to use for comparison. */
3256 else if (real1
&& real2
3257 && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0
)))
3258 && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1
))))
3259 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
3261 /* If either arg is decimal float and the other is float, fail. */
3262 else if (real1
&& real2
3263 && (DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0
)))
3264 || DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1
)))))
3267 else if (real1
&& real2
3268 && (TYPE_PRECISION (TREE_TYPE (primop0
))
3269 == TYPE_PRECISION (TREE_TYPE (primop1
))))
3270 type
= TREE_TYPE (primop0
);
3272 /* If args' natural types are both narrower than nominal type
3273 and both extend in the same manner, compare them
3274 in the type of the wider arg.
3275 Otherwise must actually extend both to the nominal
3276 common type lest different ways of extending
3278 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
3280 else if (unsignedp0
== unsignedp1
&& real1
== real2
3281 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
)
3282 && TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (*restype_ptr
))
3284 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
3285 type
= c_common_signed_or_unsigned_type (unsignedp0
3286 || TYPE_UNSIGNED (*restype_ptr
),
3288 /* Make sure shorter operand is extended the right way
3289 to match the longer operand. */
3291 = convert (c_common_signed_or_unsigned_type (unsignedp0
,
3292 TREE_TYPE (primop0
)),
3295 = convert (c_common_signed_or_unsigned_type (unsignedp1
,
3296 TREE_TYPE (primop1
)),
3301 /* Here we must do the comparison on the nominal type
3302 using the args exactly as we received them. */
3303 type
= *restype_ptr
;
3307 if (!real1
&& !real2
&& integer_zerop (primop1
)
3308 && TYPE_UNSIGNED (*restype_ptr
))
3311 /* All unsigned values are >= 0, so we warn. However,
3312 if OP0 is a constant that is >= 0, the signedness of
3313 the comparison isn't an issue, so suppress the
3316 warn_type_limits
&& !in_system_header_at (loc
)
3317 && !(TREE_CODE (primop0
) == INTEGER_CST
3318 && !TREE_OVERFLOW (convert (c_common_signed_type (type
),
3320 /* Do not warn for enumeration types. */
3321 && (TREE_CODE (expr_original_type (primop0
)) != ENUMERAL_TYPE
);
3327 warning_at (loc
, OPT_Wtype_limits
,
3328 "comparison of unsigned expression >= 0 is always true");
3329 value
= truthvalue_true_node
;
3334 warning_at (loc
, OPT_Wtype_limits
,
3335 "comparison of unsigned expression < 0 is always false");
3336 value
= truthvalue_false_node
;
3345 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
3346 if (TREE_SIDE_EFFECTS (primop0
))
3347 return build2 (COMPOUND_EXPR
, TREE_TYPE (value
),
3354 *op0_ptr
= convert (type
, primop0
);
3355 *op1_ptr
= convert (type
, primop1
);
3357 *restype_ptr
= truthvalue_type_node
;
3362 /* Return a tree for the sum or difference (RESULTCODE says which)
3363 of pointer PTROP and integer INTOP. */
3366 pointer_int_sum (location_t loc
, enum tree_code resultcode
,
3367 tree ptrop
, tree intop
, bool complain
)
3371 /* The result is a pointer of the same type that is being added. */
3372 tree result_type
= TREE_TYPE (ptrop
);
3374 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
3376 if (complain
&& warn_pointer_arith
)
3377 pedwarn (loc
, OPT_Wpointer_arith
,
3378 "pointer of type %<void *%> used in arithmetic");
3380 return error_mark_node
;
3381 size_exp
= integer_one_node
;
3383 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
3385 if (complain
&& warn_pointer_arith
)
3386 pedwarn (loc
, OPT_Wpointer_arith
,
3387 "pointer to a function used in arithmetic");
3389 return error_mark_node
;
3390 size_exp
= integer_one_node
;
3393 size_exp
= size_in_bytes_loc (loc
, TREE_TYPE (result_type
));
3395 /* We are manipulating pointer values, so we don't need to warn
3396 about relying on undefined signed overflow. We disable the
3397 warning here because we use integer types so fold won't know that
3398 they are really pointers. */
3399 fold_defer_overflow_warnings ();
3401 /* If what we are about to multiply by the size of the elements
3402 contains a constant term, apply distributive law
3403 and multiply that constant term separately.
3404 This helps produce common subexpressions. */
3405 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
3406 && !TREE_CONSTANT (intop
)
3407 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
3408 && TREE_CONSTANT (size_exp
)
3409 /* If the constant comes from pointer subtraction,
3410 skip this optimization--it would cause an error. */
3411 && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop
, 0))) == INTEGER_TYPE
3412 /* If the constant is unsigned, and smaller than the pointer size,
3413 then we must skip this optimization. This is because it could cause
3414 an overflow error if the constant is negative but INTOP is not. */
3415 && (!TYPE_UNSIGNED (TREE_TYPE (intop
))
3416 || (TYPE_PRECISION (TREE_TYPE (intop
))
3417 == TYPE_PRECISION (TREE_TYPE (ptrop
)))))
3419 enum tree_code subcode
= resultcode
;
3420 tree int_type
= TREE_TYPE (intop
);
3421 if (TREE_CODE (intop
) == MINUS_EXPR
)
3422 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
3423 /* Convert both subexpression types to the type of intop,
3424 because weird cases involving pointer arithmetic
3425 can result in a sum or difference with different type args. */
3426 ptrop
= build_binary_op (EXPR_LOCATION (TREE_OPERAND (intop
, 1)),
3428 convert (int_type
, TREE_OPERAND (intop
, 1)), 1);
3429 intop
= convert (int_type
, TREE_OPERAND (intop
, 0));
3432 /* Convert the integer argument to a type the same size as sizetype
3433 so the multiply won't overflow spuriously. */
3434 if (TYPE_PRECISION (TREE_TYPE (intop
)) != TYPE_PRECISION (sizetype
)
3435 || TYPE_UNSIGNED (TREE_TYPE (intop
)) != TYPE_UNSIGNED (sizetype
))
3436 intop
= convert (c_common_type_for_size (TYPE_PRECISION (sizetype
),
3437 TYPE_UNSIGNED (sizetype
)), intop
);
3439 /* Replace the integer argument with a suitable product by the object size.
3440 Do this multiplication as signed, then convert to the appropriate type
3441 for the pointer operation and disregard an overflow that occurred only
3442 because of the sign-extension change in the latter conversion. */
3444 tree t
= fold_build2_loc (loc
, MULT_EXPR
, TREE_TYPE (intop
), intop
,
3445 convert (TREE_TYPE (intop
), size_exp
));
3446 intop
= convert (sizetype
, t
);
3447 if (TREE_OVERFLOW_P (intop
) && !TREE_OVERFLOW (t
))
3448 intop
= wide_int_to_tree (TREE_TYPE (intop
), intop
);
3451 /* Create the sum or difference. */
3452 if (resultcode
== MINUS_EXPR
)
3453 intop
= fold_build1_loc (loc
, NEGATE_EXPR
, sizetype
, intop
);
3455 ret
= fold_build_pointer_plus_loc (loc
, ptrop
, intop
);
3457 fold_undefer_and_ignore_overflow_warnings ();
3462 /* Wrap a C_MAYBE_CONST_EXPR around an expression that is fully folded
3463 and if NON_CONST is known not to be permitted in an evaluated part
3464 of a constant expression. */
3467 c_wrap_maybe_const (tree expr
, bool non_const
)
3469 bool nowarning
= TREE_NO_WARNING (expr
);
3470 location_t loc
= EXPR_LOCATION (expr
);
3472 /* This should never be called for C++. */
3473 if (c_dialect_cxx ())
3476 /* The result of folding may have a NOP_EXPR to set TREE_NO_WARNING. */
3477 STRIP_TYPE_NOPS (expr
);
3478 expr
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (expr
), NULL
, expr
);
3479 C_MAYBE_CONST_EXPR_NON_CONST (expr
) = non_const
;
3481 TREE_NO_WARNING (expr
) = 1;
3482 protected_set_expr_location (expr
, loc
);
3487 /* Wrap a SAVE_EXPR around EXPR, if appropriate. Like save_expr, but
3488 for C folds the inside expression and wraps a C_MAYBE_CONST_EXPR
3489 around the SAVE_EXPR if needed so that c_fully_fold does not need
3490 to look inside SAVE_EXPRs. */
3493 c_save_expr (tree expr
)
3495 bool maybe_const
= true;
3496 if (c_dialect_cxx ())
3497 return save_expr (expr
);
3498 expr
= c_fully_fold (expr
, false, &maybe_const
);
3499 expr
= save_expr (expr
);
3501 expr
= c_wrap_maybe_const (expr
, true);
3505 /* Return whether EXPR is a declaration whose address can never be
3509 decl_with_nonnull_addr_p (const_tree expr
)
3511 return (DECL_P (expr
)
3512 && (TREE_CODE (expr
) == PARM_DECL
3513 || TREE_CODE (expr
) == LABEL_DECL
3514 || !DECL_WEAK (expr
)));
3517 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
3518 or for an `if' or `while' statement or ?..: exp. It should already
3519 have been validated to be of suitable type; otherwise, a bad
3520 diagnostic may result.
3522 The EXPR is located at LOCATION.
3524 This preparation consists of taking the ordinary
3525 representation of an expression expr and producing a valid tree
3526 boolean expression describing whether expr is nonzero. We could
3527 simply always do build_binary_op (NE_EXPR, expr, truthvalue_false_node, 1),
3528 but we optimize comparisons, &&, ||, and !.
3530 The resulting type should always be `truthvalue_type_node'. */
3533 c_common_truthvalue_conversion (location_t location
, tree expr
)
3535 switch (TREE_CODE (expr
))
3537 case EQ_EXPR
: case NE_EXPR
: case UNEQ_EXPR
: case LTGT_EXPR
:
3538 case LE_EXPR
: case GE_EXPR
: case LT_EXPR
: case GT_EXPR
:
3539 case UNLE_EXPR
: case UNGE_EXPR
: case UNLT_EXPR
: case UNGT_EXPR
:
3540 case ORDERED_EXPR
: case UNORDERED_EXPR
:
3541 if (TREE_TYPE (expr
) == truthvalue_type_node
)
3543 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
3544 TREE_OPERAND (expr
, 0), TREE_OPERAND (expr
, 1));
3547 case TRUTH_ANDIF_EXPR
:
3548 case TRUTH_ORIF_EXPR
:
3549 case TRUTH_AND_EXPR
:
3551 case TRUTH_XOR_EXPR
:
3552 if (TREE_TYPE (expr
) == truthvalue_type_node
)
3554 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
3555 c_common_truthvalue_conversion (location
,
3556 TREE_OPERAND (expr
, 0)),
3557 c_common_truthvalue_conversion (location
,
3558 TREE_OPERAND (expr
, 1)));
3561 case TRUTH_NOT_EXPR
:
3562 if (TREE_TYPE (expr
) == truthvalue_type_node
)
3564 expr
= build1 (TREE_CODE (expr
), truthvalue_type_node
,
3565 c_common_truthvalue_conversion (location
,
3566 TREE_OPERAND (expr
, 0)));
3573 if (TREE_CODE (TREE_TYPE (expr
)) == ENUMERAL_TYPE
3574 && !integer_zerop (expr
)
3575 && !integer_onep (expr
))
3576 warning_at (location
, OPT_Wint_in_bool_context
,
3577 "enum constant in boolean context");
3578 return integer_zerop (expr
) ? truthvalue_false_node
3579 : truthvalue_true_node
;
3582 return real_compare (NE_EXPR
, &TREE_REAL_CST (expr
), &dconst0
)
3583 ? truthvalue_true_node
3584 : truthvalue_false_node
;
3587 return fixed_compare (NE_EXPR
, &TREE_FIXED_CST (expr
),
3588 &FCONST0 (TYPE_MODE (TREE_TYPE (expr
))))
3589 ? truthvalue_true_node
3590 : truthvalue_false_node
;
3593 expr
= build_unary_op (location
, ADDR_EXPR
, expr
, false);
3598 tree inner
= TREE_OPERAND (expr
, 0);
3599 if (decl_with_nonnull_addr_p (inner
))
3601 /* Common Ada/Pascal programmer's mistake. */
3602 warning_at (location
,
3604 "the address of %qD will always evaluate as %<true%>",
3606 return truthvalue_true_node
;
3612 expr
= build_binary_op (EXPR_LOCATION (expr
),
3613 (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1))
3614 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
3615 c_common_truthvalue_conversion (location
,
3616 TREE_OPERAND (expr
, 0)),
3617 c_common_truthvalue_conversion (location
,
3618 TREE_OPERAND (expr
, 1)),
3625 case EXCESS_PRECISION_EXPR
:
3626 /* These don't change whether an object is nonzero or zero. */
3627 return c_common_truthvalue_conversion (location
, TREE_OPERAND (expr
, 0));
3631 /* These don't change whether an object is zero or nonzero, but
3632 we can't ignore them if their second arg has side-effects. */
3633 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1)))
3635 expr
= build2 (COMPOUND_EXPR
, truthvalue_type_node
,
3636 TREE_OPERAND (expr
, 1),
3637 c_common_truthvalue_conversion
3638 (location
, TREE_OPERAND (expr
, 0)));
3642 return c_common_truthvalue_conversion (location
,
3643 TREE_OPERAND (expr
, 0));
3646 warning_at (EXPR_LOCATION (expr
), OPT_Wint_in_bool_context
,
3647 "<< in boolean context, did you mean '<' ?");
3651 if (warn_int_in_bool_context
3652 && !from_macro_definition_at (EXPR_LOCATION (expr
)))
3654 tree val1
= fold_for_warn (TREE_OPERAND (expr
, 1));
3655 tree val2
= fold_for_warn (TREE_OPERAND (expr
, 2));
3656 if (TREE_CODE (val1
) == INTEGER_CST
3657 && TREE_CODE (val2
) == INTEGER_CST
3658 && !integer_zerop (val1
)
3659 && !integer_zerop (val2
)
3660 && (!integer_onep (val1
)
3661 || !integer_onep (val2
)))
3662 warning_at (EXPR_LOCATION (expr
), OPT_Wint_in_bool_context
,
3663 "?: using integer constants in boolean context, "
3664 "the expression will always evaluate to %<true%>");
3665 else if ((TREE_CODE (val1
) == INTEGER_CST
3666 && !integer_zerop (val1
)
3667 && !integer_onep (val1
))
3668 || (TREE_CODE (val2
) == INTEGER_CST
3669 && !integer_zerop (val2
)
3670 && !integer_onep (val2
)))
3671 warning_at (EXPR_LOCATION (expr
), OPT_Wint_in_bool_context
,
3672 "?: using integer constants in boolean context");
3674 /* Distribute the conversion into the arms of a COND_EXPR. */
3675 if (c_dialect_cxx ())
3676 /* Avoid premature folding. */
3680 int w
= warn_int_in_bool_context
;
3681 warn_int_in_bool_context
= 0;
3682 /* Folding will happen later for C. */
3683 expr
= build3 (COND_EXPR
, truthvalue_type_node
,
3684 TREE_OPERAND (expr
, 0),
3685 c_common_truthvalue_conversion (location
,
3686 TREE_OPERAND (expr
, 1)),
3687 c_common_truthvalue_conversion (location
,
3688 TREE_OPERAND (expr
, 2)));
3689 warn_int_in_bool_context
= w
;
3695 tree totype
= TREE_TYPE (expr
);
3696 tree fromtype
= TREE_TYPE (TREE_OPERAND (expr
, 0));
3698 if (POINTER_TYPE_P (totype
)
3699 && !c_inhibit_evaluation_warnings
3700 && TREE_CODE (fromtype
) == REFERENCE_TYPE
)
3706 warning_at (location
,
3708 "the compiler can assume that the address of "
3709 "%qD will always evaluate to %<true%>",
3713 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
3714 since that affects how `default_conversion' will behave. */
3715 if (TREE_CODE (totype
) == REFERENCE_TYPE
3716 || TREE_CODE (fromtype
) == REFERENCE_TYPE
)
3718 /* Don't strip a conversion from C++0x scoped enum, since they
3719 don't implicitly convert to other types. */
3720 if (TREE_CODE (fromtype
) == ENUMERAL_TYPE
3721 && ENUM_IS_SCOPED (fromtype
))
3723 /* If this isn't narrowing the argument, we can ignore it. */
3724 if (TYPE_PRECISION (totype
) >= TYPE_PRECISION (fromtype
))
3725 return c_common_truthvalue_conversion (location
,
3726 TREE_OPERAND (expr
, 0));
3731 if (!TREE_NO_WARNING (expr
)
3732 && warn_parentheses
)
3734 warning_at (location
, OPT_Wparentheses
,
3735 "suggest parentheses around assignment used as "
3737 TREE_NO_WARNING (expr
) = 1;
3745 if (TREE_CODE (TREE_TYPE (expr
)) == COMPLEX_TYPE
)
3747 tree t
= (in_late_binary_op
? save_expr (expr
) : c_save_expr (expr
));
3748 expr
= (build_binary_op
3749 (EXPR_LOCATION (expr
),
3750 (TREE_SIDE_EFFECTS (expr
)
3751 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
3752 c_common_truthvalue_conversion
3754 build_unary_op (location
, REALPART_EXPR
, t
, false)),
3755 c_common_truthvalue_conversion
3757 build_unary_op (location
, IMAGPART_EXPR
, t
, false)),
3762 if (TREE_CODE (TREE_TYPE (expr
)) == FIXED_POINT_TYPE
)
3764 tree fixed_zero_node
= build_fixed (TREE_TYPE (expr
),
3766 (TREE_TYPE (expr
))));
3767 return build_binary_op (location
, NE_EXPR
, expr
, fixed_zero_node
, 1);
3770 return build_binary_op (location
, NE_EXPR
, expr
, integer_zero_node
, 1);
3773 protected_set_expr_location (expr
, location
);
3777 static void def_builtin_1 (enum built_in_function fncode
,
3779 enum built_in_class fnclass
,
3780 tree fntype
, tree libtype
,
3781 bool both_p
, bool fallback_p
, bool nonansi_p
,
3782 tree fnattrs
, bool implicit_p
);
3785 /* Apply the TYPE_QUALS to the new DECL. */
3788 c_apply_type_quals_to_decl (int type_quals
, tree decl
)
3790 tree type
= TREE_TYPE (decl
);
3792 if (type
== error_mark_node
)
3795 if ((type_quals
& TYPE_QUAL_CONST
)
3796 || (type
&& TREE_CODE (type
) == REFERENCE_TYPE
))
3797 /* We used to check TYPE_NEEDS_CONSTRUCTING here, but now a constexpr
3798 constructor can produce constant init, so rely on cp_finish_decl to
3799 clear TREE_READONLY if the variable has non-constant init. */
3800 TREE_READONLY (decl
) = 1;
3801 if (type_quals
& TYPE_QUAL_VOLATILE
)
3803 TREE_SIDE_EFFECTS (decl
) = 1;
3804 TREE_THIS_VOLATILE (decl
) = 1;
3806 if (type_quals
& TYPE_QUAL_RESTRICT
)
3808 while (type
&& TREE_CODE (type
) == ARRAY_TYPE
)
3809 /* Allow 'restrict' on arrays of pointers.
3810 FIXME currently we just ignore it. */
3811 type
= TREE_TYPE (type
);
3813 || !POINTER_TYPE_P (type
)
3814 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type
)))
3815 error ("invalid use of %<restrict%>");
3819 struct c_type_hasher
: ggc_ptr_hash
<tree_node
>
3821 static hashval_t
hash (tree
);
3822 static bool equal (tree
, tree
);
3825 /* Hash function for the problem of multiple type definitions in
3826 different files. This must hash all types that will compare
3827 equal via comptypes to the same value. In practice it hashes
3828 on some of the simple stuff and leaves the details to comptypes. */
3831 c_type_hasher::hash (tree t
)
3836 switch (TREE_CODE (t
))
3838 /* For pointers, hash on pointee type plus some swizzling. */
3840 return hash (TREE_TYPE (t
)) ^ 0x3003003;
3841 /* Hash on number of elements and total size. */
3844 t2
= TYPE_VALUES (t
);
3848 t2
= TYPE_FIELDS (t
);
3850 case QUAL_UNION_TYPE
:
3852 t2
= TYPE_FIELDS (t
);
3856 t2
= TYPE_FIELDS (t
);
3861 /* FIXME: We want to use a DECL_CHAIN iteration method here, but
3862 TYPE_VALUES of ENUMERAL_TYPEs is stored as a TREE_LIST. */
3863 n_elements
= list_length (t2
);
3864 /* We might have a VLA here. */
3865 if (TREE_CODE (TYPE_SIZE (t
)) != INTEGER_CST
)
3868 size
= TREE_INT_CST_LOW (TYPE_SIZE (t
));
3869 return ((size
<< 24) | (n_elements
<< shift
));
3873 c_type_hasher::equal (tree t1
, tree t2
)
3875 return lang_hooks
.types_compatible_p (t1
, t2
);
3878 static GTY(()) hash_table
<c_type_hasher
> *type_hash_table
;
3880 /* Return the typed-based alias set for T, which may be an expression
3881 or a type. Return -1 if we don't do anything special. */
3884 c_common_get_alias_set (tree t
)
3886 /* For VLAs, use the alias set of the element type rather than the
3887 default of alias set 0 for types compared structurally. */
3888 if (TYPE_P (t
) && TYPE_STRUCTURAL_EQUALITY_P (t
))
3890 if (TREE_CODE (t
) == ARRAY_TYPE
)
3891 return get_alias_set (TREE_TYPE (t
));
3895 /* That's all the expressions we handle specially. */
3899 /* The C standard guarantees that any object may be accessed via an
3900 lvalue that has character type. */
3901 if (t
== char_type_node
3902 || t
== signed_char_type_node
3903 || t
== unsigned_char_type_node
)
3906 /* The C standard specifically allows aliasing between signed and
3907 unsigned variants of the same type. We treat the signed
3908 variant as canonical. */
3909 if (TREE_CODE (t
) == INTEGER_TYPE
&& TYPE_UNSIGNED (t
))
3911 tree t1
= c_common_signed_type (t
);
3913 /* t1 == t can happen for boolean nodes which are always unsigned. */
3915 return get_alias_set (t1
);
3918 /* Handle the case of multiple type nodes referring to "the same" type,
3919 which occurs with IMA. These share an alias set. FIXME: Currently only
3920 C90 is handled. (In C99 type compatibility is not transitive, which
3921 complicates things mightily. The alias set splay trees can theoretically
3922 represent this, but insertion is tricky when you consider all the
3923 different orders things might arrive in.) */
3925 if (c_language
!= clk_c
|| flag_isoc99
)
3928 /* Save time if there's only one input file. */
3929 if (num_in_fnames
== 1)
3932 /* Pointers need special handling if they point to any type that
3933 needs special handling (below). */
3934 if (TREE_CODE (t
) == POINTER_TYPE
)
3937 /* Find bottom type under any nested POINTERs. */
3938 for (t2
= TREE_TYPE (t
);
3939 TREE_CODE (t2
) == POINTER_TYPE
;
3940 t2
= TREE_TYPE (t2
))
3942 if (!RECORD_OR_UNION_TYPE_P (t2
)
3943 && TREE_CODE (t2
) != ENUMERAL_TYPE
)
3945 if (TYPE_SIZE (t2
) == 0)
3948 /* These are the only cases that need special handling. */
3949 if (!RECORD_OR_UNION_TYPE_P (t
)
3950 && TREE_CODE (t
) != ENUMERAL_TYPE
3951 && TREE_CODE (t
) != POINTER_TYPE
)
3954 if (TYPE_SIZE (t
) == 0)
3957 /* Look up t in hash table. Only one of the compatible types within each
3958 alias set is recorded in the table. */
3959 if (!type_hash_table
)
3960 type_hash_table
= hash_table
<c_type_hasher
>::create_ggc (1021);
3961 tree
*slot
= type_hash_table
->find_slot (t
, INSERT
);
3964 TYPE_ALIAS_SET (t
) = TYPE_ALIAS_SET ((tree
)*slot
);
3965 return TYPE_ALIAS_SET ((tree
)*slot
);
3968 /* Our caller will assign and record (in t) a new alias set; all we need
3969 to do is remember t in the hash table. */
3975 /* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where
3976 the IS_SIZEOF parameter indicates which operator is being applied.
3977 The COMPLAIN flag controls whether we should diagnose possibly
3978 ill-formed constructs or not. LOC is the location of the SIZEOF or
3979 TYPEOF operator. If MIN_ALIGNOF, the least alignment required for
3980 a type in any context should be returned, rather than the normal
3981 alignment for that type. */
3984 c_sizeof_or_alignof_type (location_t loc
,
3985 tree type
, bool is_sizeof
, bool min_alignof
,
3988 const char *op_name
;
3990 enum tree_code type_code
= TREE_CODE (type
);
3992 op_name
= is_sizeof
? "sizeof" : "__alignof__";
3994 if (type_code
== FUNCTION_TYPE
)
3998 if (complain
&& warn_pointer_arith
)
3999 pedwarn (loc
, OPT_Wpointer_arith
,
4000 "invalid application of %<sizeof%> to a function type");
4002 return error_mark_node
;
4003 value
= size_one_node
;
4009 if (c_dialect_cxx ())
4010 pedwarn (loc
, OPT_Wpedantic
, "ISO C++ does not permit "
4011 "%<alignof%> applied to a function type");
4013 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not permit "
4014 "%<_Alignof%> applied to a function type");
4016 value
= size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
4019 else if (type_code
== VOID_TYPE
|| type_code
== ERROR_MARK
)
4021 if (type_code
== VOID_TYPE
4022 && complain
&& warn_pointer_arith
)
4023 pedwarn (loc
, OPT_Wpointer_arith
,
4024 "invalid application of %qs to a void type", op_name
);
4026 return error_mark_node
;
4027 value
= size_one_node
;
4029 else if (!COMPLETE_TYPE_P (type
)
4030 && (!c_dialect_cxx () || is_sizeof
|| type_code
!= ARRAY_TYPE
))
4033 error_at (loc
, "invalid application of %qs to incomplete type %qT",
4035 return error_mark_node
;
4037 else if (c_dialect_cxx () && type_code
== ARRAY_TYPE
4038 && !COMPLETE_TYPE_P (TREE_TYPE (type
)))
4041 error_at (loc
, "invalid application of %qs to array type %qT of "
4042 "incomplete element type", op_name
, type
);
4043 return error_mark_node
;
4048 /* Convert in case a char is more than one unit. */
4049 value
= size_binop_loc (loc
, CEIL_DIV_EXPR
, TYPE_SIZE_UNIT (type
),
4050 size_int (TYPE_PRECISION (char_type_node
)
4052 else if (min_alignof
)
4053 value
= size_int (min_align_of_type (type
));
4055 value
= size_int (TYPE_ALIGN_UNIT (type
));
4058 /* VALUE will have the middle-end integer type sizetype.
4059 However, we should really return a value of type `size_t',
4060 which is just a typedef for an ordinary integer type. */
4061 value
= fold_convert_loc (loc
, size_type_node
, value
);
4066 /* Implement the __alignof keyword: Return the minimum required
4067 alignment of EXPR, measured in bytes. For VAR_DECLs,
4068 FUNCTION_DECLs and FIELD_DECLs return DECL_ALIGN (which can be set
4069 from an "aligned" __attribute__ specification). LOC is the
4070 location of the ALIGNOF operator. */
4073 c_alignof_expr (location_t loc
, tree expr
)
4077 if (VAR_OR_FUNCTION_DECL_P (expr
))
4078 t
= size_int (DECL_ALIGN_UNIT (expr
));
4080 else if (TREE_CODE (expr
) == COMPONENT_REF
4081 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
, 1)))
4083 error_at (loc
, "%<__alignof%> applied to a bit-field");
4086 else if (TREE_CODE (expr
) == COMPONENT_REF
4087 && TREE_CODE (TREE_OPERAND (expr
, 1)) == FIELD_DECL
)
4088 t
= size_int (DECL_ALIGN_UNIT (TREE_OPERAND (expr
, 1)));
4090 else if (INDIRECT_REF_P (expr
))
4092 tree t
= TREE_OPERAND (expr
, 0);
4094 int bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
4096 while (CONVERT_EXPR_P (t
)
4097 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
4101 t
= TREE_OPERAND (t
, 0);
4102 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
4103 if (thisalign
> bestalign
)
4104 best
= t
, bestalign
= thisalign
;
4106 return c_alignof (loc
, TREE_TYPE (TREE_TYPE (best
)));
4109 return c_alignof (loc
, TREE_TYPE (expr
));
4111 return fold_convert_loc (loc
, size_type_node
, t
);
4114 /* Handle C and C++ default attributes. */
4116 enum built_in_attribute
4118 #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
4119 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
4120 #define DEF_ATTR_STRING(ENUM, VALUE) ENUM,
4121 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
4122 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
4123 #include "builtin-attrs.def"
4124 #undef DEF_ATTR_NULL_TREE
4126 #undef DEF_ATTR_STRING
4127 #undef DEF_ATTR_IDENT
4128 #undef DEF_ATTR_TREE_LIST
4132 static GTY(()) tree built_in_attributes
[(int) ATTR_LAST
];
4134 static void c_init_attributes (void);
4138 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
4139 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
4140 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
4141 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
4142 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
4143 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
4144 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
4145 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4147 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4149 #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4150 ARG6, ARG7, ARG8) NAME,
4151 #define DEF_FUNCTION_TYPE_9(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4152 ARG6, ARG7, ARG8, ARG9) NAME,
4153 #define DEF_FUNCTION_TYPE_10(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4154 ARG6, ARG7, ARG8, ARG9, ARG10) NAME,
4155 #define DEF_FUNCTION_TYPE_11(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4156 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) NAME,
4157 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
4158 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
4159 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
4160 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
4161 #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
4162 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
4164 #define DEF_FUNCTION_TYPE_VAR_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4166 #define DEF_FUNCTION_TYPE_VAR_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4168 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
4169 #include "builtin-types.def"
4170 #undef DEF_PRIMITIVE_TYPE
4171 #undef DEF_FUNCTION_TYPE_0
4172 #undef DEF_FUNCTION_TYPE_1
4173 #undef DEF_FUNCTION_TYPE_2
4174 #undef DEF_FUNCTION_TYPE_3
4175 #undef DEF_FUNCTION_TYPE_4
4176 #undef DEF_FUNCTION_TYPE_5
4177 #undef DEF_FUNCTION_TYPE_6
4178 #undef DEF_FUNCTION_TYPE_7
4179 #undef DEF_FUNCTION_TYPE_8
4180 #undef DEF_FUNCTION_TYPE_9
4181 #undef DEF_FUNCTION_TYPE_10
4182 #undef DEF_FUNCTION_TYPE_11
4183 #undef DEF_FUNCTION_TYPE_VAR_0
4184 #undef DEF_FUNCTION_TYPE_VAR_1
4185 #undef DEF_FUNCTION_TYPE_VAR_2
4186 #undef DEF_FUNCTION_TYPE_VAR_3
4187 #undef DEF_FUNCTION_TYPE_VAR_4
4188 #undef DEF_FUNCTION_TYPE_VAR_5
4189 #undef DEF_FUNCTION_TYPE_VAR_6
4190 #undef DEF_FUNCTION_TYPE_VAR_7
4191 #undef DEF_POINTER_TYPE
4195 typedef enum c_builtin_type builtin_type
;
4197 /* A temporary array for c_common_nodes_and_builtins. Used in
4198 communication with def_fn_type. */
4199 static tree builtin_types
[(int) BT_LAST
+ 1];
4201 /* A helper function for c_common_nodes_and_builtins. Build function type
4202 for DEF with return type RET and N arguments. If VAR is true, then the
4203 function should be variadic after those N arguments.
4205 Takes special care not to ICE if any of the types involved are
4206 error_mark_node, which indicates that said type is not in fact available
4207 (see builtin_type_for_size). In which case the function type as a whole
4208 should be error_mark_node. */
4211 def_fn_type (builtin_type def
, builtin_type ret
, bool var
, int n
, ...)
4214 tree
*args
= XALLOCAVEC (tree
, n
);
4219 for (i
= 0; i
< n
; ++i
)
4221 builtin_type a
= (builtin_type
) va_arg (list
, int);
4222 t
= builtin_types
[a
];
4223 if (t
== error_mark_node
)
4228 t
= builtin_types
[ret
];
4229 if (t
== error_mark_node
)
4232 t
= build_varargs_function_type_array (t
, n
, args
);
4234 t
= build_function_type_array (t
, n
, args
);
4237 builtin_types
[def
] = t
;
4241 /* Build builtin functions common to both C and C++ language
4245 c_define_builtins (tree va_list_ref_type_node
, tree va_list_arg_type_node
)
4247 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
4248 builtin_types[ENUM] = VALUE;
4249 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
4250 def_fn_type (ENUM, RETURN, 0, 0);
4251 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
4252 def_fn_type (ENUM, RETURN, 0, 1, ARG1);
4253 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
4254 def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
4255 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
4256 def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
4257 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
4258 def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
4259 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
4260 def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
4261 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4263 def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
4264 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4266 def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
4267 #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4269 def_fn_type (ENUM, RETURN, 0, 8, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
4271 #define DEF_FUNCTION_TYPE_9(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4272 ARG6, ARG7, ARG8, ARG9) \
4273 def_fn_type (ENUM, RETURN, 0, 9, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
4275 #define DEF_FUNCTION_TYPE_10(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4276 ARG6, ARG7, ARG8, ARG9, ARG10) \
4277 def_fn_type (ENUM, RETURN, 0, 10, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
4278 ARG7, ARG8, ARG9, ARG10);
4279 #define DEF_FUNCTION_TYPE_11(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4280 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) \
4281 def_fn_type (ENUM, RETURN, 0, 11, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
4282 ARG7, ARG8, ARG9, ARG10, ARG11);
4283 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
4284 def_fn_type (ENUM, RETURN, 1, 0);
4285 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
4286 def_fn_type (ENUM, RETURN, 1, 1, ARG1);
4287 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
4288 def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
4289 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
4290 def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
4291 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
4292 def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
4293 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
4294 def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
4295 #define DEF_FUNCTION_TYPE_VAR_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4297 def_fn_type (ENUM, RETURN, 1, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
4298 #define DEF_FUNCTION_TYPE_VAR_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4300 def_fn_type (ENUM, RETURN, 1, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
4301 #define DEF_POINTER_TYPE(ENUM, TYPE) \
4302 builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
4304 #include "builtin-types.def"
4306 #undef DEF_PRIMITIVE_TYPE
4307 #undef DEF_FUNCTION_TYPE_0
4308 #undef DEF_FUNCTION_TYPE_1
4309 #undef DEF_FUNCTION_TYPE_2
4310 #undef DEF_FUNCTION_TYPE_3
4311 #undef DEF_FUNCTION_TYPE_4
4312 #undef DEF_FUNCTION_TYPE_5
4313 #undef DEF_FUNCTION_TYPE_6
4314 #undef DEF_FUNCTION_TYPE_7
4315 #undef DEF_FUNCTION_TYPE_8
4316 #undef DEF_FUNCTION_TYPE_9
4317 #undef DEF_FUNCTION_TYPE_10
4318 #undef DEF_FUNCTION_TYPE_11
4319 #undef DEF_FUNCTION_TYPE_VAR_0
4320 #undef DEF_FUNCTION_TYPE_VAR_1
4321 #undef DEF_FUNCTION_TYPE_VAR_2
4322 #undef DEF_FUNCTION_TYPE_VAR_3
4323 #undef DEF_FUNCTION_TYPE_VAR_4
4324 #undef DEF_FUNCTION_TYPE_VAR_5
4325 #undef DEF_FUNCTION_TYPE_VAR_6
4326 #undef DEF_FUNCTION_TYPE_VAR_7
4327 #undef DEF_POINTER_TYPE
4328 builtin_types
[(int) BT_LAST
] = NULL_TREE
;
4330 c_init_attributes ();
4332 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P, \
4333 NONANSI_P, ATTRS, IMPLICIT, COND) \
4335 def_builtin_1 (ENUM, NAME, CLASS, \
4336 builtin_types[(int) TYPE], \
4337 builtin_types[(int) LIBTYPE], \
4338 BOTH_P, FALLBACK_P, NONANSI_P, \
4339 built_in_attributes[(int) ATTRS], IMPLICIT);
4340 #include "builtins.def"
4342 targetm
.init_builtins ();
4344 build_common_builtin_nodes ();
4347 cilk_init_builtins ();
4350 /* Like get_identifier, but avoid warnings about null arguments when
4351 the argument may be NULL for targets where GCC lacks stdint.h type
4355 c_get_ident (const char *id
)
4357 return get_identifier (id
);
4360 /* Build tree nodes and builtin functions common to both C and C++ language
4364 c_common_nodes_and_builtins (void)
4366 int char16_type_size
;
4367 int char32_type_size
;
4368 int wchar_type_size
;
4369 tree array_domain_type
;
4370 tree va_list_ref_type_node
;
4371 tree va_list_arg_type_node
;
4374 build_common_tree_nodes (flag_signed_char
);
4376 /* Define `int' and `char' first so that dbx will output them first. */
4377 record_builtin_type (RID_INT
, NULL
, integer_type_node
);
4378 record_builtin_type (RID_CHAR
, "char", char_type_node
);
4380 /* `signed' is the same as `int'. FIXME: the declarations of "signed",
4381 "unsigned long", "long long unsigned" and "unsigned short" were in C++
4382 but not C. Are the conditionals here needed? */
4383 if (c_dialect_cxx ())
4384 record_builtin_type (RID_SIGNED
, NULL
, integer_type_node
);
4385 record_builtin_type (RID_LONG
, "long int", long_integer_type_node
);
4386 record_builtin_type (RID_UNSIGNED
, "unsigned int", unsigned_type_node
);
4387 record_builtin_type (RID_MAX
, "long unsigned int",
4388 long_unsigned_type_node
);
4390 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
4394 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
4395 record_builtin_type ((enum rid
)(RID_FIRST_INT_N
+ i
), name
,
4396 int_n_trees
[i
].signed_type
);
4397 sprintf (name
, "__int%d unsigned", int_n_data
[i
].bitsize
);
4398 record_builtin_type (RID_MAX
, name
, int_n_trees
[i
].unsigned_type
);
4401 if (c_dialect_cxx ())
4402 record_builtin_type (RID_MAX
, "unsigned long", long_unsigned_type_node
);
4403 record_builtin_type (RID_MAX
, "long long int",
4404 long_long_integer_type_node
);
4405 record_builtin_type (RID_MAX
, "long long unsigned int",
4406 long_long_unsigned_type_node
);
4407 if (c_dialect_cxx ())
4408 record_builtin_type (RID_MAX
, "long long unsigned",
4409 long_long_unsigned_type_node
);
4410 record_builtin_type (RID_SHORT
, "short int", short_integer_type_node
);
4411 record_builtin_type (RID_MAX
, "short unsigned int",
4412 short_unsigned_type_node
);
4413 if (c_dialect_cxx ())
4414 record_builtin_type (RID_MAX
, "unsigned short",
4415 short_unsigned_type_node
);
4417 /* Define both `signed char' and `unsigned char'. */
4418 record_builtin_type (RID_MAX
, "signed char", signed_char_type_node
);
4419 record_builtin_type (RID_MAX
, "unsigned char", unsigned_char_type_node
);
4421 /* These are types that c_common_type_for_size and
4422 c_common_type_for_mode use. */
4423 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4424 TYPE_DECL
, NULL_TREE
,
4426 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4427 TYPE_DECL
, NULL_TREE
,
4429 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4430 TYPE_DECL
, NULL_TREE
,
4432 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4433 TYPE_DECL
, NULL_TREE
,
4435 #if HOST_BITS_PER_WIDE_INT >= 64
4436 /* Note that this is different than the __int128 type that's part of
4437 the generic __intN support. */
4438 if (targetm
.scalar_mode_supported_p (TImode
))
4439 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4441 get_identifier ("__int128_t"),
4444 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4445 TYPE_DECL
, NULL_TREE
,
4446 unsigned_intQI_type_node
));
4447 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4448 TYPE_DECL
, NULL_TREE
,
4449 unsigned_intHI_type_node
));
4450 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4451 TYPE_DECL
, NULL_TREE
,
4452 unsigned_intSI_type_node
));
4453 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4454 TYPE_DECL
, NULL_TREE
,
4455 unsigned_intDI_type_node
));
4456 #if HOST_BITS_PER_WIDE_INT >= 64
4457 if (targetm
.scalar_mode_supported_p (TImode
))
4458 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4460 get_identifier ("__uint128_t"),
4461 unsigned_intTI_type_node
));
4464 /* Create the widest literal types. */
4465 widest_integer_literal_type_node
4466 = make_signed_type (HOST_BITS_PER_WIDE_INT
* 2);
4467 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4468 TYPE_DECL
, NULL_TREE
,
4469 widest_integer_literal_type_node
));
4471 widest_unsigned_literal_type_node
4472 = make_unsigned_type (HOST_BITS_PER_WIDE_INT
* 2);
4473 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4474 TYPE_DECL
, NULL_TREE
,
4475 widest_unsigned_literal_type_node
));
4477 signed_size_type_node
= c_common_signed_type (size_type_node
);
4480 TREE_TYPE (identifier_global_value (get_identifier (PID_TYPE
)));
4482 record_builtin_type (RID_FLOAT
, NULL
, float_type_node
);
4483 record_builtin_type (RID_DOUBLE
, NULL
, double_type_node
);
4484 record_builtin_type (RID_MAX
, "long double", long_double_type_node
);
4486 if (!c_dialect_cxx ())
4487 for (i
= 0; i
< NUM_FLOATN_NX_TYPES
; i
++)
4488 if (FLOATN_NX_TYPE_NODE (i
) != NULL_TREE
)
4489 record_builtin_type ((enum rid
) (RID_FLOATN_NX_FIRST
+ i
), NULL
,
4490 FLOATN_NX_TYPE_NODE (i
));
4492 /* Only supported decimal floating point extension if the target
4493 actually supports underlying modes. */
4494 if (targetm
.scalar_mode_supported_p (SDmode
)
4495 && targetm
.scalar_mode_supported_p (DDmode
)
4496 && targetm
.scalar_mode_supported_p (TDmode
))
4498 record_builtin_type (RID_DFLOAT32
, NULL
, dfloat32_type_node
);
4499 record_builtin_type (RID_DFLOAT64
, NULL
, dfloat64_type_node
);
4500 record_builtin_type (RID_DFLOAT128
, NULL
, dfloat128_type_node
);
4503 if (targetm
.fixed_point_supported_p ())
4505 record_builtin_type (RID_MAX
, "short _Fract", short_fract_type_node
);
4506 record_builtin_type (RID_FRACT
, NULL
, fract_type_node
);
4507 record_builtin_type (RID_MAX
, "long _Fract", long_fract_type_node
);
4508 record_builtin_type (RID_MAX
, "long long _Fract",
4509 long_long_fract_type_node
);
4510 record_builtin_type (RID_MAX
, "unsigned short _Fract",
4511 unsigned_short_fract_type_node
);
4512 record_builtin_type (RID_MAX
, "unsigned _Fract",
4513 unsigned_fract_type_node
);
4514 record_builtin_type (RID_MAX
, "unsigned long _Fract",
4515 unsigned_long_fract_type_node
);
4516 record_builtin_type (RID_MAX
, "unsigned long long _Fract",
4517 unsigned_long_long_fract_type_node
);
4518 record_builtin_type (RID_MAX
, "_Sat short _Fract",
4519 sat_short_fract_type_node
);
4520 record_builtin_type (RID_MAX
, "_Sat _Fract", sat_fract_type_node
);
4521 record_builtin_type (RID_MAX
, "_Sat long _Fract",
4522 sat_long_fract_type_node
);
4523 record_builtin_type (RID_MAX
, "_Sat long long _Fract",
4524 sat_long_long_fract_type_node
);
4525 record_builtin_type (RID_MAX
, "_Sat unsigned short _Fract",
4526 sat_unsigned_short_fract_type_node
);
4527 record_builtin_type (RID_MAX
, "_Sat unsigned _Fract",
4528 sat_unsigned_fract_type_node
);
4529 record_builtin_type (RID_MAX
, "_Sat unsigned long _Fract",
4530 sat_unsigned_long_fract_type_node
);
4531 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Fract",
4532 sat_unsigned_long_long_fract_type_node
);
4533 record_builtin_type (RID_MAX
, "short _Accum", short_accum_type_node
);
4534 record_builtin_type (RID_ACCUM
, NULL
, accum_type_node
);
4535 record_builtin_type (RID_MAX
, "long _Accum", long_accum_type_node
);
4536 record_builtin_type (RID_MAX
, "long long _Accum",
4537 long_long_accum_type_node
);
4538 record_builtin_type (RID_MAX
, "unsigned short _Accum",
4539 unsigned_short_accum_type_node
);
4540 record_builtin_type (RID_MAX
, "unsigned _Accum",
4541 unsigned_accum_type_node
);
4542 record_builtin_type (RID_MAX
, "unsigned long _Accum",
4543 unsigned_long_accum_type_node
);
4544 record_builtin_type (RID_MAX
, "unsigned long long _Accum",
4545 unsigned_long_long_accum_type_node
);
4546 record_builtin_type (RID_MAX
, "_Sat short _Accum",
4547 sat_short_accum_type_node
);
4548 record_builtin_type (RID_MAX
, "_Sat _Accum", sat_accum_type_node
);
4549 record_builtin_type (RID_MAX
, "_Sat long _Accum",
4550 sat_long_accum_type_node
);
4551 record_builtin_type (RID_MAX
, "_Sat long long _Accum",
4552 sat_long_long_accum_type_node
);
4553 record_builtin_type (RID_MAX
, "_Sat unsigned short _Accum",
4554 sat_unsigned_short_accum_type_node
);
4555 record_builtin_type (RID_MAX
, "_Sat unsigned _Accum",
4556 sat_unsigned_accum_type_node
);
4557 record_builtin_type (RID_MAX
, "_Sat unsigned long _Accum",
4558 sat_unsigned_long_accum_type_node
);
4559 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Accum",
4560 sat_unsigned_long_long_accum_type_node
);
4564 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4566 get_identifier ("complex int"),
4567 complex_integer_type_node
));
4568 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4570 get_identifier ("complex float"),
4571 complex_float_type_node
));
4572 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4574 get_identifier ("complex double"),
4575 complex_double_type_node
));
4576 lang_hooks
.decls
.pushdecl
4577 (build_decl (UNKNOWN_LOCATION
,
4578 TYPE_DECL
, get_identifier ("complex long double"),
4579 complex_long_double_type_node
));
4581 if (!c_dialect_cxx ())
4582 for (i
= 0; i
< NUM_FLOATN_NX_TYPES
; i
++)
4583 if (COMPLEX_FLOATN_NX_TYPE_NODE (i
) != NULL_TREE
)
4586 sprintf (buf
, "complex _Float%d%s", floatn_nx_types
[i
].n
,
4587 floatn_nx_types
[i
].extended
? "x" : "");
4588 lang_hooks
.decls
.pushdecl
4589 (build_decl (UNKNOWN_LOCATION
,
4591 get_identifier (buf
),
4592 COMPLEX_FLOATN_NX_TYPE_NODE (i
)));
4595 if (c_dialect_cxx ())
4596 /* For C++, make fileptr_type_node a distinct void * type until
4597 FILE type is defined. */
4598 fileptr_type_node
= build_variant_type_copy (ptr_type_node
);
4600 record_builtin_type (RID_VOID
, NULL
, void_type_node
);
4602 /* Set the TYPE_NAME for any variants that were built before
4603 record_builtin_type gave names to the built-in types. */
4605 tree void_name
= TYPE_NAME (void_type_node
);
4606 TYPE_NAME (void_type_node
) = NULL_TREE
;
4607 TYPE_NAME (build_qualified_type (void_type_node
, TYPE_QUAL_CONST
))
4609 TYPE_NAME (void_type_node
) = void_name
;
4612 void_list_node
= build_void_list_node ();
4614 /* Make a type to be the domain of a few array types
4615 whose domains don't really matter.
4616 200 is small enough that it always fits in size_t
4617 and large enough that it can hold most function names for the
4618 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
4619 array_domain_type
= build_index_type (size_int (200));
4621 /* Make a type for arrays of characters.
4622 With luck nothing will ever really depend on the length of this
4624 char_array_type_node
4625 = build_array_type (char_type_node
, array_domain_type
);
4627 string_type_node
= build_pointer_type (char_type_node
);
4628 const_string_type_node
4629 = build_pointer_type (build_qualified_type
4630 (char_type_node
, TYPE_QUAL_CONST
));
4632 /* This is special for C++ so functions can be overloaded. */
4633 wchar_type_node
= get_identifier (MODIFIED_WCHAR_TYPE
);
4634 wchar_type_node
= TREE_TYPE (identifier_global_value (wchar_type_node
));
4635 wchar_type_size
= TYPE_PRECISION (wchar_type_node
);
4636 underlying_wchar_type_node
= wchar_type_node
;
4637 if (c_dialect_cxx ())
4639 if (TYPE_UNSIGNED (wchar_type_node
))
4640 wchar_type_node
= make_unsigned_type (wchar_type_size
);
4642 wchar_type_node
= make_signed_type (wchar_type_size
);
4643 record_builtin_type (RID_WCHAR
, "wchar_t", wchar_type_node
);
4646 /* This is for wide string constants. */
4647 wchar_array_type_node
4648 = build_array_type (wchar_type_node
, array_domain_type
);
4650 /* Define 'char16_t'. */
4651 char16_type_node
= get_identifier (CHAR16_TYPE
);
4652 char16_type_node
= TREE_TYPE (identifier_global_value (char16_type_node
));
4653 char16_type_size
= TYPE_PRECISION (char16_type_node
);
4654 if (c_dialect_cxx ())
4656 char16_type_node
= make_unsigned_type (char16_type_size
);
4658 if (cxx_dialect
>= cxx11
)
4659 record_builtin_type (RID_CHAR16
, "char16_t", char16_type_node
);
4662 /* This is for UTF-16 string constants. */
4663 char16_array_type_node
4664 = build_array_type (char16_type_node
, array_domain_type
);
4666 /* Define 'char32_t'. */
4667 char32_type_node
= get_identifier (CHAR32_TYPE
);
4668 char32_type_node
= TREE_TYPE (identifier_global_value (char32_type_node
));
4669 char32_type_size
= TYPE_PRECISION (char32_type_node
);
4670 if (c_dialect_cxx ())
4672 char32_type_node
= make_unsigned_type (char32_type_size
);
4674 if (cxx_dialect
>= cxx11
)
4675 record_builtin_type (RID_CHAR32
, "char32_t", char32_type_node
);
4678 /* This is for UTF-32 string constants. */
4679 char32_array_type_node
4680 = build_array_type (char32_type_node
, array_domain_type
);
4683 TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE
)));
4686 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE
)));
4688 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE
)));
4690 if (SIG_ATOMIC_TYPE
)
4691 sig_atomic_type_node
=
4692 TREE_TYPE (identifier_global_value (c_get_ident (SIG_ATOMIC_TYPE
)));
4695 TREE_TYPE (identifier_global_value (c_get_ident (INT8_TYPE
)));
4698 TREE_TYPE (identifier_global_value (c_get_ident (INT16_TYPE
)));
4701 TREE_TYPE (identifier_global_value (c_get_ident (INT32_TYPE
)));
4704 TREE_TYPE (identifier_global_value (c_get_ident (INT64_TYPE
)));
4707 TREE_TYPE (identifier_global_value (c_get_ident (UINT8_TYPE
)));
4709 c_uint16_type_node
= uint16_type_node
=
4710 TREE_TYPE (identifier_global_value (c_get_ident (UINT16_TYPE
)));
4712 c_uint32_type_node
= uint32_type_node
=
4713 TREE_TYPE (identifier_global_value (c_get_ident (UINT32_TYPE
)));
4715 c_uint64_type_node
= uint64_type_node
=
4716 TREE_TYPE (identifier_global_value (c_get_ident (UINT64_TYPE
)));
4717 if (INT_LEAST8_TYPE
)
4718 int_least8_type_node
=
4719 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST8_TYPE
)));
4720 if (INT_LEAST16_TYPE
)
4721 int_least16_type_node
=
4722 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST16_TYPE
)));
4723 if (INT_LEAST32_TYPE
)
4724 int_least32_type_node
=
4725 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST32_TYPE
)));
4726 if (INT_LEAST64_TYPE
)
4727 int_least64_type_node
=
4728 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST64_TYPE
)));
4729 if (UINT_LEAST8_TYPE
)
4730 uint_least8_type_node
=
4731 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST8_TYPE
)));
4732 if (UINT_LEAST16_TYPE
)
4733 uint_least16_type_node
=
4734 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST16_TYPE
)));
4735 if (UINT_LEAST32_TYPE
)
4736 uint_least32_type_node
=
4737 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST32_TYPE
)));
4738 if (UINT_LEAST64_TYPE
)
4739 uint_least64_type_node
=
4740 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST64_TYPE
)));
4742 int_fast8_type_node
=
4743 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST8_TYPE
)));
4744 if (INT_FAST16_TYPE
)
4745 int_fast16_type_node
=
4746 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST16_TYPE
)));
4747 if (INT_FAST32_TYPE
)
4748 int_fast32_type_node
=
4749 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST32_TYPE
)));
4750 if (INT_FAST64_TYPE
)
4751 int_fast64_type_node
=
4752 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST64_TYPE
)));
4753 if (UINT_FAST8_TYPE
)
4754 uint_fast8_type_node
=
4755 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST8_TYPE
)));
4756 if (UINT_FAST16_TYPE
)
4757 uint_fast16_type_node
=
4758 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST16_TYPE
)));
4759 if (UINT_FAST32_TYPE
)
4760 uint_fast32_type_node
=
4761 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST32_TYPE
)));
4762 if (UINT_FAST64_TYPE
)
4763 uint_fast64_type_node
=
4764 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST64_TYPE
)));
4767 TREE_TYPE (identifier_global_value (c_get_ident (INTPTR_TYPE
)));
4770 TREE_TYPE (identifier_global_value (c_get_ident (UINTPTR_TYPE
)));
4772 default_function_type
4773 = build_varargs_function_type_list (integer_type_node
, NULL_TREE
);
4775 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE
)));
4776 unsigned_ptrdiff_type_node
= c_common_unsigned_type (ptrdiff_type_node
);
4778 lang_hooks
.decls
.pushdecl
4779 (build_decl (UNKNOWN_LOCATION
,
4780 TYPE_DECL
, get_identifier ("__builtin_va_list"),
4781 va_list_type_node
));
4782 if (targetm
.enum_va_list_p
)
4788 for (l
= 0; targetm
.enum_va_list_p (l
, &pname
, &ptype
); ++l
)
4790 lang_hooks
.decls
.pushdecl
4791 (build_decl (UNKNOWN_LOCATION
,
4792 TYPE_DECL
, get_identifier (pname
),
4798 if (TREE_CODE (va_list_type_node
) == ARRAY_TYPE
)
4800 va_list_arg_type_node
= va_list_ref_type_node
=
4801 build_pointer_type (TREE_TYPE (va_list_type_node
));
4805 va_list_arg_type_node
= va_list_type_node
;
4806 va_list_ref_type_node
= build_reference_type (va_list_type_node
);
4809 if (!flag_preprocess_only
)
4810 c_define_builtins (va_list_ref_type_node
, va_list_arg_type_node
);
4812 main_identifier_node
= get_identifier ("main");
4814 /* Create the built-in __null node. It is important that this is
4816 null_node
= make_int_cst (1, 1);
4817 TREE_TYPE (null_node
) = c_common_type_for_size (POINTER_SIZE
, 0);
4819 /* Since builtin_types isn't gc'ed, don't export these nodes. */
4820 memset (builtin_types
, 0, sizeof (builtin_types
));
4823 /* The number of named compound-literals generated thus far. */
4824 static GTY(()) int compound_literal_number
;
4826 /* Set DECL_NAME for DECL, a VAR_DECL for a compound-literal. */
4829 set_compound_literal_name (tree decl
)
4832 ASM_FORMAT_PRIVATE_NAME (name
, "__compound_literal",
4833 compound_literal_number
);
4834 compound_literal_number
++;
4835 DECL_NAME (decl
) = get_identifier (name
);
4838 /* build_va_arg helper function. Return a VA_ARG_EXPR with location LOC, type
4839 TYPE and operand OP. */
4842 build_va_arg_1 (location_t loc
, tree type
, tree op
)
4844 tree expr
= build1 (VA_ARG_EXPR
, type
, op
);
4845 SET_EXPR_LOCATION (expr
, loc
);
4849 /* Return a VA_ARG_EXPR corresponding to a source-level expression
4850 va_arg (EXPR, TYPE) at source location LOC. */
4853 build_va_arg (location_t loc
, tree expr
, tree type
)
4855 tree va_type
= TREE_TYPE (expr
);
4856 tree canon_va_type
= (va_type
== error_mark_node
4858 : targetm
.canonical_va_list_type (va_type
));
4860 if (va_type
== error_mark_node
4861 || canon_va_type
== NULL_TREE
)
4863 if (canon_va_type
== NULL_TREE
)
4864 error_at (loc
, "first argument to %<va_arg%> not of type %<va_list%>");
4866 /* Let's handle things neutrallly, if expr:
4867 - has undeclared type, or
4868 - is not an va_list type. */
4869 return build_va_arg_1 (loc
, type
, error_mark_node
);
4872 if (TREE_CODE (canon_va_type
) != ARRAY_TYPE
)
4874 /* Case 1: Not an array type. */
4876 /* Take the address, to get '&ap'. Note that &ap is not a va_list
4878 mark_addressable (expr
);
4879 expr
= build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (expr
)), expr
);
4881 return build_va_arg_1 (loc
, type
, expr
);
4884 /* Case 2: Array type.
4888 For contrast, let's start with the simple case (case 1). If
4889 canon_va_type is not an array type, but say a char *, then when
4890 passing-by-value a va_list, the type of the va_list param decl is
4891 the same as for another va_list decl (all ap's are char *):
4894 D.1815 = VA_ARG (&ap, 0B, 1);
4900 __builtin_va_start (&ap, 0);
4903 __builtin_va_end (&ap);
4907 However, if canon_va_type is ARRAY_TYPE, then when passing-by-value a
4908 va_list the type of the va_list param decl (case 2b, struct * ap) is not
4909 the same as for another va_list decl (case 2a, struct ap[1]).
4912 D.1844 = VA_ARG (ap, 0B, 0);
4917 __builtin_va_start (&ap, 0);
4919 __builtin_va_end (&ap);
4923 Case 2b is different because:
4924 - on the callee side, the parm decl has declared type va_list, but
4925 grokdeclarator changes the type of the parm decl to a pointer to the
4927 - on the caller side, the pass-by-value uses &ap.
4929 We unify these two cases (case 2a: va_list is array type,
4930 case 2b: va_list is pointer to array elem type), by adding '&' for the
4931 array type case, such that we have a pointer to array elem in both
4934 if (TREE_CODE (va_type
) == ARRAY_TYPE
)
4936 /* Case 2a: va_list is array type. */
4938 /* Take the address, to get '&ap'. Make sure it's a pointer to array
4940 mark_addressable (expr
);
4941 expr
= build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (canon_va_type
)),
4944 /* Verify that &ap is still recognized as having va_list type. */
4945 tree canon_expr_type
4946 = targetm
.canonical_va_list_type (TREE_TYPE (expr
));
4947 gcc_assert (canon_expr_type
!= NULL_TREE
);
4951 /* Case 2b: va_list is pointer to array elem type. */
4952 gcc_assert (POINTER_TYPE_P (va_type
));
4954 /* Comparison as in std_canonical_va_list_type. */
4955 gcc_assert (TYPE_MAIN_VARIANT (TREE_TYPE (va_type
))
4956 == TYPE_MAIN_VARIANT (TREE_TYPE (canon_va_type
)));
4958 /* Don't take the address. We've already got '&ap'. */
4962 return build_va_arg_1 (loc
, type
, expr
);
4966 /* Linked list of disabled built-in functions. */
4968 struct disabled_builtin
4971 struct disabled_builtin
*next
;
4973 static disabled_builtin
*disabled_builtins
= NULL
;
4975 static bool builtin_function_disabled_p (const char *);
4977 /* Disable a built-in function specified by -fno-builtin-NAME. If NAME
4978 begins with "__builtin_", give an error. */
4981 disable_builtin_function (const char *name
)
4983 if (strncmp (name
, "__builtin_", strlen ("__builtin_")) == 0)
4984 error ("cannot disable built-in function %qs", name
);
4987 disabled_builtin
*new_disabled_builtin
= XNEW (disabled_builtin
);
4988 new_disabled_builtin
->name
= name
;
4989 new_disabled_builtin
->next
= disabled_builtins
;
4990 disabled_builtins
= new_disabled_builtin
;
4995 /* Return true if the built-in function NAME has been disabled, false
4999 builtin_function_disabled_p (const char *name
)
5001 disabled_builtin
*p
;
5002 for (p
= disabled_builtins
; p
!= NULL
; p
= p
->next
)
5004 if (strcmp (name
, p
->name
) == 0)
5011 /* Worker for DEF_BUILTIN.
5012 Possibly define a builtin function with one or two names.
5013 Does not declare a non-__builtin_ function if flag_no_builtin, or if
5014 nonansi_p and flag_no_nonansi_builtin. */
5017 def_builtin_1 (enum built_in_function fncode
,
5019 enum built_in_class fnclass
,
5020 tree fntype
, tree libtype
,
5021 bool both_p
, bool fallback_p
, bool nonansi_p
,
5022 tree fnattrs
, bool implicit_p
)
5025 const char *libname
;
5027 if (fntype
== error_mark_node
)
5030 gcc_assert ((!both_p
&& !fallback_p
)
5031 || !strncmp (name
, "__builtin_",
5032 strlen ("__builtin_")));
5034 libname
= name
+ strlen ("__builtin_");
5035 decl
= add_builtin_function (name
, fntype
, fncode
, fnclass
,
5036 (fallback_p
? libname
: NULL
),
5039 set_builtin_decl (fncode
, decl
, implicit_p
);
5042 && !flag_no_builtin
&& !builtin_function_disabled_p (libname
)
5043 && !(nonansi_p
&& flag_no_nonansi_builtin
))
5044 add_builtin_function (libname
, libtype
, fncode
, fnclass
,
5048 /* Nonzero if the type T promotes to int. This is (nearly) the
5049 integral promotions defined in ISO C99 6.3.1.1/2. */
5052 c_promoting_integer_type_p (const_tree t
)
5054 switch (TREE_CODE (t
))
5057 return (TYPE_MAIN_VARIANT (t
) == char_type_node
5058 || TYPE_MAIN_VARIANT (t
) == signed_char_type_node
5059 || TYPE_MAIN_VARIANT (t
) == unsigned_char_type_node
5060 || TYPE_MAIN_VARIANT (t
) == short_integer_type_node
5061 || TYPE_MAIN_VARIANT (t
) == short_unsigned_type_node
5062 || TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
));
5065 /* ??? Technically all enumerations not larger than an int
5066 promote to an int. But this is used along code paths
5067 that only want to notice a size change. */
5068 return TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
);
5078 /* Return 1 if PARMS specifies a fixed number of parameters
5079 and none of their types is affected by default promotions. */
5082 self_promoting_args_p (const_tree parms
)
5085 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
5087 tree type
= TREE_VALUE (t
);
5089 if (type
== error_mark_node
)
5092 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
5098 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
5101 if (c_promoting_integer_type_p (type
))
5107 /* Recursively remove any '*' or '&' operator from TYPE. */
5109 strip_pointer_operator (tree t
)
5111 while (POINTER_TYPE_P (t
))
5116 /* Recursively remove pointer or array type from TYPE. */
5118 strip_pointer_or_array_types (tree t
)
5120 while (TREE_CODE (t
) == ARRAY_TYPE
|| POINTER_TYPE_P (t
))
5125 /* Used to compare case labels. K1 and K2 are actually tree nodes
5126 representing case labels, or NULL_TREE for a `default' label.
5127 Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after
5128 K2, and 0 if K1 and K2 are equal. */
5131 case_compare (splay_tree_key k1
, splay_tree_key k2
)
5133 /* Consider a NULL key (such as arises with a `default' label) to be
5134 smaller than anything else. */
5140 return tree_int_cst_compare ((tree
) k1
, (tree
) k2
);
5143 /* Process a case label, located at LOC, for the range LOW_VALUE
5144 ... HIGH_VALUE. If LOW_VALUE and HIGH_VALUE are both NULL_TREE
5145 then this case label is actually a `default' label. If only
5146 HIGH_VALUE is NULL_TREE, then case label was declared using the
5147 usual C/C++ syntax, rather than the GNU case range extension.
5148 CASES is a tree containing all the case ranges processed so far;
5149 COND is the condition for the switch-statement itself.
5150 OUTSIDE_RANGE_P says whether there was a case value that doesn't
5151 fit into the range of the ORIG_TYPE. Returns the CASE_LABEL_EXPR
5152 created, or ERROR_MARK_NODE if no CASE_LABEL_EXPR is created. */
5155 c_add_case_label (location_t loc
, splay_tree cases
, tree cond
, tree orig_type
,
5156 tree low_value
, tree high_value
, bool *outside_range_p
)
5161 splay_tree_node node
;
5163 /* Create the LABEL_DECL itself. */
5164 label
= create_artificial_label (loc
);
5166 /* If there was an error processing the switch condition, bail now
5167 before we get more confused. */
5168 if (!cond
|| cond
== error_mark_node
)
5171 if ((low_value
&& TREE_TYPE (low_value
)
5172 && POINTER_TYPE_P (TREE_TYPE (low_value
)))
5173 || (high_value
&& TREE_TYPE (high_value
)
5174 && POINTER_TYPE_P (TREE_TYPE (high_value
))))
5176 error_at (loc
, "pointers are not permitted as case values");
5180 /* Case ranges are a GNU extension. */
5182 pedwarn (loc
, OPT_Wpedantic
,
5183 "range expressions in switch statements are non-standard");
5185 type
= TREE_TYPE (cond
);
5188 low_value
= check_case_value (loc
, low_value
);
5189 low_value
= convert_and_check (loc
, type
, low_value
);
5190 if (low_value
== error_mark_node
)
5195 high_value
= check_case_value (loc
, high_value
);
5196 high_value
= convert_and_check (loc
, type
, high_value
);
5197 if (high_value
== error_mark_node
)
5201 if (low_value
&& high_value
)
5203 /* If the LOW_VALUE and HIGH_VALUE are the same, then this isn't
5204 really a case range, even though it was written that way.
5205 Remove the HIGH_VALUE to simplify later processing. */
5206 if (tree_int_cst_equal (low_value
, high_value
))
5207 high_value
= NULL_TREE
;
5208 else if (!tree_int_cst_lt (low_value
, high_value
))
5209 warning_at (loc
, 0, "empty range specified");
5212 /* See if the case is in range of the type of the original testing
5213 expression. If both low_value and high_value are out of range,
5214 don't insert the case label and return NULL_TREE. */
5216 && !check_case_bounds (loc
, type
, orig_type
,
5217 &low_value
, high_value
? &high_value
: NULL
,
5221 /* Look up the LOW_VALUE in the table of case labels we already
5223 node
= splay_tree_lookup (cases
, (splay_tree_key
) low_value
);
5224 /* If there was not an exact match, check for overlapping ranges.
5225 There's no need to do this if there's no LOW_VALUE or HIGH_VALUE;
5226 that's a `default' label and the only overlap is an exact match. */
5227 if (!node
&& (low_value
|| high_value
))
5229 splay_tree_node low_bound
;
5230 splay_tree_node high_bound
;
5232 /* Even though there wasn't an exact match, there might be an
5233 overlap between this case range and another case range.
5234 Since we've (inductively) not allowed any overlapping case
5235 ranges, we simply need to find the greatest low case label
5236 that is smaller that LOW_VALUE, and the smallest low case
5237 label that is greater than LOW_VALUE. If there is an overlap
5238 it will occur in one of these two ranges. */
5239 low_bound
= splay_tree_predecessor (cases
,
5240 (splay_tree_key
) low_value
);
5241 high_bound
= splay_tree_successor (cases
,
5242 (splay_tree_key
) low_value
);
5244 /* Check to see if the LOW_BOUND overlaps. It is smaller than
5245 the LOW_VALUE, so there is no need to check unless the
5246 LOW_BOUND is in fact itself a case range. */
5248 && CASE_HIGH ((tree
) low_bound
->value
)
5249 && tree_int_cst_compare (CASE_HIGH ((tree
) low_bound
->value
),
5252 /* Check to see if the HIGH_BOUND overlaps. The low end of that
5253 range is bigger than the low end of the current range, so we
5254 are only interested if the current range is a real range, and
5255 not an ordinary case label. */
5258 && (tree_int_cst_compare ((tree
) high_bound
->key
,
5263 /* If there was an overlap, issue an error. */
5266 tree duplicate
= CASE_LABEL ((tree
) node
->value
);
5270 error_at (loc
, "duplicate (or overlapping) case value");
5271 error_at (DECL_SOURCE_LOCATION (duplicate
),
5272 "this is the first entry overlapping that value");
5276 error_at (loc
, "duplicate case value") ;
5277 error_at (DECL_SOURCE_LOCATION (duplicate
), "previously used here");
5281 error_at (loc
, "multiple default labels in one switch");
5282 error_at (DECL_SOURCE_LOCATION (duplicate
),
5283 "this is the first default label");
5288 /* Add a CASE_LABEL to the statement-tree. */
5289 case_label
= add_stmt (build_case_label (low_value
, high_value
, label
));
5290 /* Register this case label in the splay tree. */
5291 splay_tree_insert (cases
,
5292 (splay_tree_key
) low_value
,
5293 (splay_tree_value
) case_label
);
5298 /* Add a label so that the back-end doesn't think that the beginning of
5299 the switch is unreachable. Note that we do not add a case label, as
5300 that just leads to duplicates and thence to failure later on. */
5303 tree t
= create_artificial_label (loc
);
5304 add_stmt (build_stmt (loc
, LABEL_EXPR
, t
));
5306 return error_mark_node
;
5309 /* Finish an expression taking the address of LABEL (an
5310 IDENTIFIER_NODE). Returns an expression for the address.
5312 LOC is the location for the expression returned. */
5315 finish_label_address_expr (tree label
, location_t loc
)
5319 pedwarn (input_location
, OPT_Wpedantic
, "taking the address of a label is non-standard");
5321 if (label
== error_mark_node
)
5322 return error_mark_node
;
5324 label
= lookup_label (label
);
5325 if (label
== NULL_TREE
)
5326 result
= null_pointer_node
;
5329 TREE_USED (label
) = 1;
5330 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
5331 /* The current function is not necessarily uninlinable.
5332 Computed gotos are incompatible with inlining, but the value
5333 here could be used only in a diagnostic, for example. */
5334 protected_set_expr_location (result
, loc
);
5341 /* Given a boolean expression ARG, return a tree representing an increment
5342 or decrement (as indicated by CODE) of ARG. The front end must check for
5343 invalid cases (e.g., decrement in C++). */
5345 boolean_increment (enum tree_code code
, tree arg
)
5348 tree true_res
= build_int_cst (TREE_TYPE (arg
), 1);
5350 arg
= stabilize_reference (arg
);
5353 case PREINCREMENT_EXPR
:
5354 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
5356 case POSTINCREMENT_EXPR
:
5357 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
5358 arg
= save_expr (arg
);
5359 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
5360 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
5362 case PREDECREMENT_EXPR
:
5363 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
5364 invert_truthvalue_loc (input_location
, arg
));
5366 case POSTDECREMENT_EXPR
:
5367 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
5368 invert_truthvalue_loc (input_location
, arg
));
5369 arg
= save_expr (arg
);
5370 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
5371 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
5376 TREE_SIDE_EFFECTS (val
) = 1;
5380 /* Built-in macros for stddef.h and stdint.h, that require macros
5381 defined in this file. */
5383 c_stddef_cpp_builtins(void)
5385 builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE
, 0);
5386 builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE
, 0);
5387 builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE
, 0);
5388 builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE
, 0);
5389 builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE
, 0);
5390 builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE
, 0);
5391 builtin_define_with_value ("__CHAR16_TYPE__", CHAR16_TYPE
, 0);
5392 builtin_define_with_value ("__CHAR32_TYPE__", CHAR32_TYPE
, 0);
5393 if (SIG_ATOMIC_TYPE
)
5394 builtin_define_with_value ("__SIG_ATOMIC_TYPE__", SIG_ATOMIC_TYPE
, 0);
5396 builtin_define_with_value ("__INT8_TYPE__", INT8_TYPE
, 0);
5398 builtin_define_with_value ("__INT16_TYPE__", INT16_TYPE
, 0);
5400 builtin_define_with_value ("__INT32_TYPE__", INT32_TYPE
, 0);
5402 builtin_define_with_value ("__INT64_TYPE__", INT64_TYPE
, 0);
5404 builtin_define_with_value ("__UINT8_TYPE__", UINT8_TYPE
, 0);
5406 builtin_define_with_value ("__UINT16_TYPE__", UINT16_TYPE
, 0);
5408 builtin_define_with_value ("__UINT32_TYPE__", UINT32_TYPE
, 0);
5410 builtin_define_with_value ("__UINT64_TYPE__", UINT64_TYPE
, 0);
5411 if (INT_LEAST8_TYPE
)
5412 builtin_define_with_value ("__INT_LEAST8_TYPE__", INT_LEAST8_TYPE
, 0);
5413 if (INT_LEAST16_TYPE
)
5414 builtin_define_with_value ("__INT_LEAST16_TYPE__", INT_LEAST16_TYPE
, 0);
5415 if (INT_LEAST32_TYPE
)
5416 builtin_define_with_value ("__INT_LEAST32_TYPE__", INT_LEAST32_TYPE
, 0);
5417 if (INT_LEAST64_TYPE
)
5418 builtin_define_with_value ("__INT_LEAST64_TYPE__", INT_LEAST64_TYPE
, 0);
5419 if (UINT_LEAST8_TYPE
)
5420 builtin_define_with_value ("__UINT_LEAST8_TYPE__", UINT_LEAST8_TYPE
, 0);
5421 if (UINT_LEAST16_TYPE
)
5422 builtin_define_with_value ("__UINT_LEAST16_TYPE__", UINT_LEAST16_TYPE
, 0);
5423 if (UINT_LEAST32_TYPE
)
5424 builtin_define_with_value ("__UINT_LEAST32_TYPE__", UINT_LEAST32_TYPE
, 0);
5425 if (UINT_LEAST64_TYPE
)
5426 builtin_define_with_value ("__UINT_LEAST64_TYPE__", UINT_LEAST64_TYPE
, 0);
5428 builtin_define_with_value ("__INT_FAST8_TYPE__", INT_FAST8_TYPE
, 0);
5429 if (INT_FAST16_TYPE
)
5430 builtin_define_with_value ("__INT_FAST16_TYPE__", INT_FAST16_TYPE
, 0);
5431 if (INT_FAST32_TYPE
)
5432 builtin_define_with_value ("__INT_FAST32_TYPE__", INT_FAST32_TYPE
, 0);
5433 if (INT_FAST64_TYPE
)
5434 builtin_define_with_value ("__INT_FAST64_TYPE__", INT_FAST64_TYPE
, 0);
5435 if (UINT_FAST8_TYPE
)
5436 builtin_define_with_value ("__UINT_FAST8_TYPE__", UINT_FAST8_TYPE
, 0);
5437 if (UINT_FAST16_TYPE
)
5438 builtin_define_with_value ("__UINT_FAST16_TYPE__", UINT_FAST16_TYPE
, 0);
5439 if (UINT_FAST32_TYPE
)
5440 builtin_define_with_value ("__UINT_FAST32_TYPE__", UINT_FAST32_TYPE
, 0);
5441 if (UINT_FAST64_TYPE
)
5442 builtin_define_with_value ("__UINT_FAST64_TYPE__", UINT_FAST64_TYPE
, 0);
5444 builtin_define_with_value ("__INTPTR_TYPE__", INTPTR_TYPE
, 0);
5446 builtin_define_with_value ("__UINTPTR_TYPE__", UINTPTR_TYPE
, 0);
5450 c_init_attributes (void)
5452 /* Fill in the built_in_attributes array. */
5453 #define DEF_ATTR_NULL_TREE(ENUM) \
5454 built_in_attributes[(int) ENUM] = NULL_TREE;
5455 #define DEF_ATTR_INT(ENUM, VALUE) \
5456 built_in_attributes[(int) ENUM] = build_int_cst (integer_type_node, VALUE);
5457 #define DEF_ATTR_STRING(ENUM, VALUE) \
5458 built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
5459 #define DEF_ATTR_IDENT(ENUM, STRING) \
5460 built_in_attributes[(int) ENUM] = get_identifier (STRING);
5461 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
5462 built_in_attributes[(int) ENUM] \
5463 = tree_cons (built_in_attributes[(int) PURPOSE], \
5464 built_in_attributes[(int) VALUE], \
5465 built_in_attributes[(int) CHAIN]);
5466 #include "builtin-attrs.def"
5467 #undef DEF_ATTR_NULL_TREE
5469 #undef DEF_ATTR_IDENT
5470 #undef DEF_ATTR_TREE_LIST
5473 /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain
5474 identifier as an argument, so the front end shouldn't look it up. */
5477 attribute_takes_identifier_p (const_tree attr_id
)
5479 const struct attribute_spec
*spec
= lookup_attribute_spec (attr_id
);
5481 /* Unknown attribute that we'll end up ignoring, return true so we
5482 don't complain about an identifier argument. */
5484 else if (!strcmp ("mode", spec
->name
)
5485 || !strcmp ("format", spec
->name
)
5486 || !strcmp ("cleanup", spec
->name
))
5489 return targetm
.attribute_takes_identifier_p (attr_id
);
5492 /* Attribute handlers common to C front ends. */
5494 /* Handle a "packed" attribute; arguments as in
5495 struct attribute_spec.handler. */
5498 handle_packed_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
5499 int flags
, bool *no_add_attrs
)
5503 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
5504 *node
= build_variant_type_copy (*node
);
5505 TYPE_PACKED (*node
) = 1;
5507 else if (TREE_CODE (*node
) == FIELD_DECL
)
5509 if (TYPE_ALIGN (TREE_TYPE (*node
)) <= BITS_PER_UNIT
5510 /* Still pack bitfields. */
5511 && ! DECL_INITIAL (*node
))
5512 warning (OPT_Wattributes
,
5513 "%qE attribute ignored for field of type %qT",
5514 name
, TREE_TYPE (*node
));
5516 DECL_PACKED (*node
) = 1;
5518 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
5519 used for DECL_REGISTER. It wouldn't mean anything anyway.
5520 We can't set DECL_PACKED on the type of a TYPE_DECL, because
5521 that changes what the typedef is typing. */
5524 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
5525 *no_add_attrs
= true;
5531 /* Handle a "nocommon" attribute; arguments as in
5532 struct attribute_spec.handler. */
5535 handle_nocommon_attribute (tree
*node
, tree name
,
5536 tree
ARG_UNUSED (args
),
5537 int ARG_UNUSED (flags
), bool *no_add_attrs
)
5540 DECL_COMMON (*node
) = 0;
5543 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
5544 *no_add_attrs
= true;
5550 /* Handle a "common" attribute; arguments as in
5551 struct attribute_spec.handler. */
5554 handle_common_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
5555 int ARG_UNUSED (flags
), bool *no_add_attrs
)
5558 DECL_COMMON (*node
) = 1;
5561 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
5562 *no_add_attrs
= true;
5568 /* Handle a "noreturn" attribute; arguments as in
5569 struct attribute_spec.handler. */
5572 handle_noreturn_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
5573 int ARG_UNUSED (flags
), bool *no_add_attrs
)
5575 tree type
= TREE_TYPE (*node
);
5577 /* See FIXME comment in c_common_attribute_table. */
5578 if (TREE_CODE (*node
) == FUNCTION_DECL
5579 || objc_method_decl (TREE_CODE (*node
)))
5580 TREE_THIS_VOLATILE (*node
) = 1;
5581 else if (TREE_CODE (type
) == POINTER_TYPE
5582 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
5584 = (build_qualified_type
5586 (build_type_variant (TREE_TYPE (type
),
5587 TYPE_READONLY (TREE_TYPE (type
)), 1)),
5588 TYPE_QUALS (type
)));
5591 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
5592 *no_add_attrs
= true;
5598 /* Handle a "hot" and attribute; arguments as in
5599 struct attribute_spec.handler. */
5602 handle_hot_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
5603 int ARG_UNUSED (flags
), bool *no_add_attrs
)
5605 if (TREE_CODE (*node
) == FUNCTION_DECL
5606 || TREE_CODE (*node
) == LABEL_DECL
)
5608 if (lookup_attribute ("cold", DECL_ATTRIBUTES (*node
)) != NULL
)
5610 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
5611 "with attribute %qs", name
, "cold");
5612 *no_add_attrs
= true;
5614 /* Most of the rest of the hot processing is done later with
5615 lookup_attribute. */
5619 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
5620 *no_add_attrs
= true;
5626 /* Handle a "cold" and attribute; arguments as in
5627 struct attribute_spec.handler. */
5630 handle_cold_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
5631 int ARG_UNUSED (flags
), bool *no_add_attrs
)
5633 if (TREE_CODE (*node
) == FUNCTION_DECL
5634 || TREE_CODE (*node
) == LABEL_DECL
)
5636 if (lookup_attribute ("hot", DECL_ATTRIBUTES (*node
)) != NULL
)
5638 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
5639 "with attribute %qs", name
, "hot");
5640 *no_add_attrs
= true;
5642 /* Most of the rest of the cold processing is done later with
5643 lookup_attribute. */
5647 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
5648 *no_add_attrs
= true;
5654 /* Handle a "no_sanitize_address" attribute; arguments as in
5655 struct attribute_spec.handler. */
5658 handle_no_sanitize_address_attribute (tree
*node
, tree name
, tree
, int,
5661 if (TREE_CODE (*node
) != FUNCTION_DECL
)
5663 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
5664 *no_add_attrs
= true;
5670 /* Handle a "no_address_safety_analysis" attribute; arguments as in
5671 struct attribute_spec.handler. */
5674 handle_no_address_safety_analysis_attribute (tree
*node
, tree name
, tree
, int,
5677 if (TREE_CODE (*node
) != FUNCTION_DECL
)
5678 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
5679 else if (!lookup_attribute ("no_sanitize_address", DECL_ATTRIBUTES (*node
)))
5680 DECL_ATTRIBUTES (*node
)
5681 = tree_cons (get_identifier ("no_sanitize_address"),
5682 NULL_TREE
, DECL_ATTRIBUTES (*node
));
5683 *no_add_attrs
= true;
5687 /* Handle a "no_sanitize_undefined" attribute; arguments as in
5688 struct attribute_spec.handler. */
5691 handle_no_sanitize_undefined_attribute (tree
*node
, tree name
, tree
, int,
5694 if (TREE_CODE (*node
) != FUNCTION_DECL
)
5696 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
5697 *no_add_attrs
= true;
5703 /* Handle a "stack_protect" attribute; arguments as in
5704 struct attribute_spec.handler. */
5706 handle_stack_protect_attribute (tree
*node
, tree name
, tree
, int,
5709 if (TREE_CODE (*node
) != FUNCTION_DECL
)
5711 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
5712 *no_add_attrs
= true;
5715 DECL_ATTRIBUTES (*node
)
5716 = tree_cons (get_identifier ("stack_protect"),
5717 NULL_TREE
, DECL_ATTRIBUTES (*node
));
5722 /* Handle a "noinline" attribute; arguments as in
5723 struct attribute_spec.handler. */
5726 handle_noinline_attribute (tree
*node
, tree name
,
5727 tree
ARG_UNUSED (args
),
5728 int ARG_UNUSED (flags
), bool *no_add_attrs
)
5730 if (TREE_CODE (*node
) == FUNCTION_DECL
)
5732 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node
)))
5734 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
5735 "with attribute %qs", name
, "always_inline");
5736 *no_add_attrs
= true;
5739 DECL_UNINLINABLE (*node
) = 1;
5743 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
5744 *no_add_attrs
= true;
5750 /* Handle a "noclone" attribute; arguments as in
5751 struct attribute_spec.handler. */
5754 handle_noclone_attribute (tree
*node
, tree name
,
5755 tree
ARG_UNUSED (args
),
5756 int ARG_UNUSED (flags
), bool *no_add_attrs
)
5758 if (TREE_CODE (*node
) != FUNCTION_DECL
)
5760 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
5761 *no_add_attrs
= true;
5767 /* Handle a "no_icf" attribute; arguments as in
5768 struct attribute_spec.handler. */
5771 handle_noicf_attribute (tree
*node
, tree name
,
5772 tree
ARG_UNUSED (args
),
5773 int ARG_UNUSED (flags
), bool *no_add_attrs
)
5775 if (TREE_CODE (*node
) != FUNCTION_DECL
)
5777 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
5778 *no_add_attrs
= true;
5785 /* Handle a "always_inline" attribute; arguments as in
5786 struct attribute_spec.handler. */
5789 handle_always_inline_attribute (tree
*node
, tree name
,
5790 tree
ARG_UNUSED (args
),
5791 int ARG_UNUSED (flags
),
5794 if (TREE_CODE (*node
) == FUNCTION_DECL
)
5796 if (lookup_attribute ("noinline", DECL_ATTRIBUTES (*node
)))
5798 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
5799 "with %qs attribute", name
, "noinline");
5800 *no_add_attrs
= true;
5802 else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node
)))
5804 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
5805 "with %qs attribute", name
, "target_clones");
5806 *no_add_attrs
= true;
5809 /* Set the attribute and mark it for disregarding inline
5811 DECL_DISREGARD_INLINE_LIMITS (*node
) = 1;
5815 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
5816 *no_add_attrs
= true;
5822 /* Handle a "gnu_inline" attribute; arguments as in
5823 struct attribute_spec.handler. */
5826 handle_gnu_inline_attribute (tree
*node
, tree name
,
5827 tree
ARG_UNUSED (args
),
5828 int ARG_UNUSED (flags
),
5831 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
5833 /* Do nothing else, just set the attribute. We'll get at
5834 it later with lookup_attribute. */
5838 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
5839 *no_add_attrs
= true;
5845 /* Handle a "leaf" attribute; arguments as in
5846 struct attribute_spec.handler. */
5849 handle_leaf_attribute (tree
*node
, tree name
,
5850 tree
ARG_UNUSED (args
),
5851 int ARG_UNUSED (flags
), bool *no_add_attrs
)
5853 if (TREE_CODE (*node
) != FUNCTION_DECL
)
5855 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
5856 *no_add_attrs
= true;
5858 if (!TREE_PUBLIC (*node
))
5860 warning (OPT_Wattributes
, "%qE attribute has no effect on unit local functions", name
);
5861 *no_add_attrs
= true;
5867 /* Handle an "artificial" attribute; arguments as in
5868 struct attribute_spec.handler. */
5871 handle_artificial_attribute (tree
*node
, tree name
,
5872 tree
ARG_UNUSED (args
),
5873 int ARG_UNUSED (flags
),
5876 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
5878 /* Do nothing else, just set the attribute. We'll get at
5879 it later with lookup_attribute. */
5883 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
5884 *no_add_attrs
= true;
5890 /* Handle a "flatten" attribute; arguments as in
5891 struct attribute_spec.handler. */
5894 handle_flatten_attribute (tree
*node
, tree name
,
5895 tree args ATTRIBUTE_UNUSED
,
5896 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
5898 if (TREE_CODE (*node
) == FUNCTION_DECL
)
5899 /* Do nothing else, just set the attribute. We'll get at
5900 it later with lookup_attribute. */
5904 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
5905 *no_add_attrs
= true;
5911 /* Handle a "warning" or "error" attribute; arguments as in
5912 struct attribute_spec.handler. */
5915 handle_error_attribute (tree
*node
, tree name
, tree args
,
5916 int ARG_UNUSED (flags
), bool *no_add_attrs
)
5918 if (TREE_CODE (*node
) == FUNCTION_DECL
5919 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
5920 /* Do nothing else, just set the attribute. We'll get at
5921 it later with lookup_attribute. */
5925 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
5926 *no_add_attrs
= true;
5932 /* Handle a "used" attribute; arguments as in
5933 struct attribute_spec.handler. */
5936 handle_used_attribute (tree
*pnode
, tree name
, tree
ARG_UNUSED (args
),
5937 int ARG_UNUSED (flags
), bool *no_add_attrs
)
5941 if (TREE_CODE (node
) == FUNCTION_DECL
5942 || (VAR_P (node
) && TREE_STATIC (node
))
5943 || (TREE_CODE (node
) == TYPE_DECL
))
5945 TREE_USED (node
) = 1;
5946 DECL_PRESERVE_P (node
) = 1;
5948 DECL_READ_P (node
) = 1;
5952 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
5953 *no_add_attrs
= true;
5959 /* Handle a "unused" attribute; arguments as in
5960 struct attribute_spec.handler. */
5963 handle_unused_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
5964 int flags
, bool *no_add_attrs
)
5970 if (TREE_CODE (decl
) == PARM_DECL
5971 || VAR_OR_FUNCTION_DECL_P (decl
)
5972 || TREE_CODE (decl
) == LABEL_DECL
5973 || TREE_CODE (decl
) == CONST_DECL
5974 || TREE_CODE (decl
) == TYPE_DECL
)
5976 TREE_USED (decl
) = 1;
5977 if (VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
)
5978 DECL_READ_P (decl
) = 1;
5982 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
5983 *no_add_attrs
= true;
5988 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
5989 *node
= build_variant_type_copy (*node
);
5990 TREE_USED (*node
) = 1;
5996 /* Handle a "externally_visible" attribute; arguments as in
5997 struct attribute_spec.handler. */
6000 handle_externally_visible_attribute (tree
*pnode
, tree name
,
6001 tree
ARG_UNUSED (args
),
6002 int ARG_UNUSED (flags
),
6007 if (VAR_OR_FUNCTION_DECL_P (node
))
6009 if ((!TREE_STATIC (node
) && TREE_CODE (node
) != FUNCTION_DECL
6010 && !DECL_EXTERNAL (node
)) || !TREE_PUBLIC (node
))
6012 warning (OPT_Wattributes
,
6013 "%qE attribute have effect only on public objects", name
);
6014 *no_add_attrs
= true;
6019 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6020 *no_add_attrs
= true;
6026 /* Handle the "no_reorder" attribute. Arguments as in
6027 struct attribute_spec.handler. */
6030 handle_no_reorder_attribute (tree
*pnode
,
6038 if (!VAR_OR_FUNCTION_DECL_P (node
)
6039 && !(TREE_STATIC (node
) || DECL_EXTERNAL (node
)))
6041 warning (OPT_Wattributes
,
6042 "%qE attribute only affects top level objects",
6044 *no_add_attrs
= true;
6050 /* Handle a "const" attribute; arguments as in
6051 struct attribute_spec.handler. */
6054 handle_const_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6055 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6057 tree type
= TREE_TYPE (*node
);
6059 /* See FIXME comment on noreturn in c_common_attribute_table. */
6060 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6061 TREE_READONLY (*node
) = 1;
6062 else if (TREE_CODE (type
) == POINTER_TYPE
6063 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
6065 = (build_qualified_type
6067 (build_type_variant (TREE_TYPE (type
), 1,
6068 TREE_THIS_VOLATILE (TREE_TYPE (type
)))),
6069 TYPE_QUALS (type
)));
6072 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6073 *no_add_attrs
= true;
6079 /* Handle a "scalar_storage_order" attribute; arguments as in
6080 struct attribute_spec.handler. */
6083 handle_scalar_storage_order_attribute (tree
*node
, tree name
, tree args
,
6084 int flags
, bool *no_add_attrs
)
6086 tree id
= TREE_VALUE (args
);
6089 if (TREE_CODE (*node
) == TYPE_DECL
6090 && ! (flags
& ATTR_FLAG_CXX11
))
6091 node
= &TREE_TYPE (*node
);
6094 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
)
6096 error ("scalar_storage_order is not supported because endianness "
6101 if (RECORD_OR_UNION_TYPE_P (type
) && !c_dialect_cxx ())
6103 bool reverse
= false;
6105 if (TREE_CODE (id
) == STRING_CST
6106 && strcmp (TREE_STRING_POINTER (id
), "big-endian") == 0)
6107 reverse
= !BYTES_BIG_ENDIAN
;
6108 else if (TREE_CODE (id
) == STRING_CST
6109 && strcmp (TREE_STRING_POINTER (id
), "little-endian") == 0)
6110 reverse
= BYTES_BIG_ENDIAN
;
6113 error ("scalar_storage_order argument must be one of \"big-endian\""
6114 " or \"little-endian\"");
6118 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6121 /* A type variant isn't good enough, since we don't want a cast
6122 to such a type to be removed as a no-op. */
6123 *node
= type
= build_duplicate_type (type
);
6126 TYPE_REVERSE_STORAGE_ORDER (type
) = reverse
;
6130 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6131 *no_add_attrs
= true;
6135 /* Handle a "transparent_union" attribute; arguments as in
6136 struct attribute_spec.handler. */
6139 handle_transparent_union_attribute (tree
*node
, tree name
,
6140 tree
ARG_UNUSED (args
), int flags
,
6145 *no_add_attrs
= true;
6147 if (TREE_CODE (*node
) == TYPE_DECL
6148 && ! (flags
& ATTR_FLAG_CXX11
))
6149 node
= &TREE_TYPE (*node
);
6152 if (TREE_CODE (type
) == UNION_TYPE
)
6154 /* Make sure that the first field will work for a transparent union.
6155 If the type isn't complete yet, leave the check to the code in
6157 if (TYPE_SIZE (type
))
6159 tree first
= first_field (type
);
6160 if (first
== NULL_TREE
6161 || DECL_ARTIFICIAL (first
)
6162 || TYPE_MODE (type
) != DECL_MODE (first
))
6166 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6168 /* If the type isn't complete yet, setting the flag
6169 on a variant wouldn't ever be checked. */
6170 if (!TYPE_SIZE (type
))
6173 /* build_duplicate_type doesn't work for C++. */
6174 if (c_dialect_cxx ())
6177 /* A type variant isn't good enough, since we don't want a cast
6178 to such a type to be removed as a no-op. */
6179 *node
= type
= build_duplicate_type (type
);
6182 for (tree t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
6183 TYPE_TRANSPARENT_AGGR (t
) = 1;
6188 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6192 /* Subroutine of handle_{con,de}structor_attribute. Evaluate ARGS to
6193 get the requested priority for a constructor or destructor,
6194 possibly issuing diagnostics for invalid or reserved
6197 static priority_type
6198 get_priority (tree args
, bool is_destructor
)
6204 return DEFAULT_INIT_PRIORITY
;
6206 if (!SUPPORTS_INIT_PRIORITY
)
6209 error ("destructor priorities are not supported");
6211 error ("constructor priorities are not supported");
6212 return DEFAULT_INIT_PRIORITY
;
6215 arg
= TREE_VALUE (args
);
6216 if (TREE_CODE (arg
) == IDENTIFIER_NODE
)
6218 if (arg
== error_mark_node
)
6219 return DEFAULT_INIT_PRIORITY
;
6220 arg
= default_conversion (arg
);
6221 if (!tree_fits_shwi_p (arg
)
6222 || !INTEGRAL_TYPE_P (TREE_TYPE (arg
)))
6225 pri
= tree_to_shwi (arg
);
6226 if (pri
< 0 || pri
> MAX_INIT_PRIORITY
)
6229 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
6233 "destructor priorities from 0 to %d are reserved "
6234 "for the implementation",
6235 MAX_RESERVED_INIT_PRIORITY
);
6238 "constructor priorities from 0 to %d are reserved "
6239 "for the implementation",
6240 MAX_RESERVED_INIT_PRIORITY
);
6246 error ("destructor priorities must be integers from 0 to %d inclusive",
6249 error ("constructor priorities must be integers from 0 to %d inclusive",
6251 return DEFAULT_INIT_PRIORITY
;
6254 /* Handle a "constructor" attribute; arguments as in
6255 struct attribute_spec.handler. */
6258 handle_constructor_attribute (tree
*node
, tree name
, tree args
,
6259 int ARG_UNUSED (flags
),
6263 tree type
= TREE_TYPE (decl
);
6265 if (TREE_CODE (decl
) == FUNCTION_DECL
6266 && TREE_CODE (type
) == FUNCTION_TYPE
6267 && decl_function_context (decl
) == 0)
6269 priority_type priority
;
6270 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
6271 priority
= get_priority (args
, /*is_destructor=*/false);
6272 SET_DECL_INIT_PRIORITY (decl
, priority
);
6273 TREE_USED (decl
) = 1;
6277 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6278 *no_add_attrs
= true;
6284 /* Handle a "destructor" attribute; arguments as in
6285 struct attribute_spec.handler. */
6288 handle_destructor_attribute (tree
*node
, tree name
, tree args
,
6289 int ARG_UNUSED (flags
),
6293 tree type
= TREE_TYPE (decl
);
6295 if (TREE_CODE (decl
) == FUNCTION_DECL
6296 && TREE_CODE (type
) == FUNCTION_TYPE
6297 && decl_function_context (decl
) == 0)
6299 priority_type priority
;
6300 DECL_STATIC_DESTRUCTOR (decl
) = 1;
6301 priority
= get_priority (args
, /*is_destructor=*/true);
6302 SET_DECL_FINI_PRIORITY (decl
, priority
);
6303 TREE_USED (decl
) = 1;
6307 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6308 *no_add_attrs
= true;
6314 /* Nonzero if the mode is a valid vector mode for this architecture.
6315 This returns nonzero even if there is no hardware support for the
6316 vector mode, but we can emulate with narrower modes. */
6319 vector_mode_valid_p (machine_mode mode
)
6321 enum mode_class mclass
= GET_MODE_CLASS (mode
);
6322 machine_mode innermode
;
6324 /* Doh! What's going on? */
6325 if (mclass
!= MODE_VECTOR_INT
6326 && mclass
!= MODE_VECTOR_FLOAT
6327 && mclass
!= MODE_VECTOR_FRACT
6328 && mclass
!= MODE_VECTOR_UFRACT
6329 && mclass
!= MODE_VECTOR_ACCUM
6330 && mclass
!= MODE_VECTOR_UACCUM
)
6333 /* Hardware support. Woo hoo! */
6334 if (targetm
.vector_mode_supported_p (mode
))
6337 innermode
= GET_MODE_INNER (mode
);
6339 /* We should probably return 1 if requesting V4DI and we have no DI,
6340 but we have V2DI, but this is probably very unlikely. */
6342 /* If we have support for the inner mode, we can safely emulate it.
6343 We may not have V2DI, but me can emulate with a pair of DIs. */
6344 return targetm
.scalar_mode_supported_p (innermode
);
6348 /* Handle a "mode" attribute; arguments as in
6349 struct attribute_spec.handler. */
6352 handle_mode_attribute (tree
*node
, tree name
, tree args
,
6353 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6356 tree ident
= TREE_VALUE (args
);
6358 *no_add_attrs
= true;
6360 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
6361 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6365 const char *p
= IDENTIFIER_POINTER (ident
);
6366 int len
= strlen (p
);
6367 machine_mode mode
= VOIDmode
;
6371 if (len
> 4 && p
[0] == '_' && p
[1] == '_'
6372 && p
[len
- 1] == '_' && p
[len
- 2] == '_')
6374 char *newp
= (char *) alloca (len
- 1);
6376 strcpy (newp
, &p
[2]);
6377 newp
[len
- 4] = '\0';
6381 /* Change this type to have a type with the specified mode.
6382 First check for the special modes. */
6383 if (!strcmp (p
, "byte"))
6385 else if (!strcmp (p
, "word"))
6387 else if (!strcmp (p
, "pointer"))
6389 else if (!strcmp (p
, "libgcc_cmp_return"))
6390 mode
= targetm
.libgcc_cmp_return_mode ();
6391 else if (!strcmp (p
, "libgcc_shift_count"))
6392 mode
= targetm
.libgcc_shift_count_mode ();
6393 else if (!strcmp (p
, "unwind_word"))
6394 mode
= targetm
.unwind_word_mode ();
6396 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
6397 if (!strcmp (p
, GET_MODE_NAME (j
)))
6399 mode
= (machine_mode
) j
;
6403 if (mode
== VOIDmode
)
6405 error ("unknown machine mode %qE", ident
);
6410 switch (GET_MODE_CLASS (mode
))
6413 case MODE_PARTIAL_INT
:
6415 case MODE_DECIMAL_FLOAT
:
6420 valid_mode
= targetm
.scalar_mode_supported_p (mode
);
6423 case MODE_COMPLEX_INT
:
6424 case MODE_COMPLEX_FLOAT
:
6425 valid_mode
= targetm
.scalar_mode_supported_p (GET_MODE_INNER (mode
));
6428 case MODE_VECTOR_INT
:
6429 case MODE_VECTOR_FLOAT
:
6430 case MODE_VECTOR_FRACT
:
6431 case MODE_VECTOR_UFRACT
:
6432 case MODE_VECTOR_ACCUM
:
6433 case MODE_VECTOR_UACCUM
:
6434 warning (OPT_Wattributes
, "specifying vector types with "
6435 "__attribute__ ((mode)) is deprecated");
6436 warning (OPT_Wattributes
,
6437 "use __attribute__ ((vector_size)) instead");
6438 valid_mode
= vector_mode_valid_p (mode
);
6446 error ("unable to emulate %qs", p
);
6450 if (POINTER_TYPE_P (type
))
6452 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
6453 tree (*fn
)(tree
, machine_mode
, bool);
6455 if (!targetm
.addr_space
.valid_pointer_mode (mode
, as
))
6457 error ("invalid pointer mode %qs", p
);
6461 if (TREE_CODE (type
) == POINTER_TYPE
)
6462 fn
= build_pointer_type_for_mode
;
6464 fn
= build_reference_type_for_mode
;
6465 typefm
= fn (TREE_TYPE (type
), mode
, false);
6469 /* For fixed-point modes, we need to test if the signness of type
6470 and the machine mode are consistent. */
6471 if (ALL_FIXED_POINT_MODE_P (mode
)
6472 && TYPE_UNSIGNED (type
) != UNSIGNED_FIXED_POINT_MODE_P (mode
))
6474 error ("signedness of type and machine mode %qs don%'t match", p
);
6477 /* For fixed-point modes, we need to pass saturating info. */
6478 typefm
= lang_hooks
.types
.type_for_mode (mode
,
6479 ALL_FIXED_POINT_MODE_P (mode
) ? TYPE_SATURATING (type
)
6480 : TYPE_UNSIGNED (type
));
6483 if (typefm
== NULL_TREE
)
6485 error ("no data type for mode %qs", p
);
6488 else if (TREE_CODE (type
) == ENUMERAL_TYPE
)
6490 /* For enumeral types, copy the precision from the integer
6491 type returned above. If not an INTEGER_TYPE, we can't use
6492 this mode for this type. */
6493 if (TREE_CODE (typefm
) != INTEGER_TYPE
)
6495 error ("cannot use mode %qs for enumeral types", p
);
6499 if (flags
& ATTR_FLAG_TYPE_IN_PLACE
)
6501 TYPE_PRECISION (type
) = TYPE_PRECISION (typefm
);
6506 /* We cannot build a type variant, as there's code that assumes
6507 that TYPE_MAIN_VARIANT has the same mode. This includes the
6508 debug generators. Instead, create a subrange type. This
6509 results in all of the enumeral values being emitted only once
6510 in the original, and the subtype gets them by reference. */
6511 if (TYPE_UNSIGNED (type
))
6512 typefm
= make_unsigned_type (TYPE_PRECISION (typefm
));
6514 typefm
= make_signed_type (TYPE_PRECISION (typefm
));
6515 TREE_TYPE (typefm
) = type
;
6518 else if (VECTOR_MODE_P (mode
)
6519 ? TREE_CODE (type
) != TREE_CODE (TREE_TYPE (typefm
))
6520 : TREE_CODE (type
) != TREE_CODE (typefm
))
6522 error ("mode %qs applied to inappropriate type", p
);
6532 /* Handle a "section" attribute; arguments as in
6533 struct attribute_spec.handler. */
6536 handle_section_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
6537 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6541 if (!targetm_common
.have_named_sections
)
6543 error_at (DECL_SOURCE_LOCATION (*node
),
6544 "section attributes are not supported for this target");
6548 user_defined_section_attribute
= true;
6550 if (!VAR_OR_FUNCTION_DECL_P (decl
))
6552 error ("section attribute not allowed for %q+D", *node
);
6556 if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
6558 error ("section attribute argument not a string constant");
6563 && current_function_decl
!= NULL_TREE
6564 && !TREE_STATIC (decl
))
6566 error_at (DECL_SOURCE_LOCATION (decl
),
6567 "section attribute cannot be specified for local variables");
6571 /* The decl may have already been given a section attribute
6572 from a previous declaration. Ensure they match. */
6573 if (DECL_SECTION_NAME (decl
) != NULL
6574 && strcmp (DECL_SECTION_NAME (decl
),
6575 TREE_STRING_POINTER (TREE_VALUE (args
))) != 0)
6577 error ("section of %q+D conflicts with previous declaration", *node
);
6582 && !targetm
.have_tls
&& targetm
.emutls
.tmpl_section
6583 && DECL_THREAD_LOCAL_P (decl
))
6585 error ("section of %q+D cannot be overridden", *node
);
6589 set_decl_section_name (decl
, TREE_STRING_POINTER (TREE_VALUE (args
)));
6593 *no_add_attrs
= true;
6597 /* Check whether ALIGN is a valid user-specified alignment. If so,
6598 return its base-2 log; if not, output an error and return -1. If
6599 ALLOW_ZERO then 0 is valid and should result in a return of -1 with
6602 check_user_alignment (const_tree align
, bool allow_zero
)
6606 if (error_operand_p (align
))
6608 if (TREE_CODE (align
) != INTEGER_CST
6609 || !INTEGRAL_TYPE_P (TREE_TYPE (align
)))
6611 error ("requested alignment is not an integer constant");
6614 else if (allow_zero
&& integer_zerop (align
))
6616 else if (tree_int_cst_sgn (align
) == -1
6617 || (i
= tree_log2 (align
)) == -1)
6619 error ("requested alignment is not a positive power of 2");
6622 else if (i
>= HOST_BITS_PER_INT
- LOG2_BITS_PER_UNIT
)
6624 error ("requested alignment is too large");
6630 /* If in c++-11, check if the c++-11 alignment constraint with respect
6631 to fundamental alignment (in [dcl.align]) are satisfied. If not in
6632 c++-11 mode, does nothing.
6636 [* if the constant expression evaluates to a fundamental alignment,
6637 the alignment requirement of the declared entity shall be the
6638 specified fundamental alignment.
6640 * if the constant expression evaluates to an extended alignment
6641 and the implementation supports that alignment in the context
6642 of the declaration, the alignment of the declared entity shall
6645 * if the constant expression evaluates to an extended alignment
6646 and the implementation does not support that alignment in the
6647 context of the declaration, the program is ill-formed]. */
6650 check_cxx_fundamental_alignment_constraints (tree node
,
6654 bool alignment_too_large_p
= false;
6655 unsigned requested_alignment
= (1U << align_log
) * BITS_PER_UNIT
;
6656 unsigned max_align
= 0;
6658 if ((!(flags
& ATTR_FLAG_CXX11
) && !warn_cxx_compat
)
6659 || (node
== NULL_TREE
|| node
== error_mark_node
))
6662 if (cxx_fundamental_alignment_p (requested_alignment
))
6667 if (TREE_STATIC (node
) || DECL_EXTERNAL (node
))
6668 /* For file scope variables and static members, the target supports
6669 alignments that are at most MAX_OFILE_ALIGNMENT. */
6670 max_align
= MAX_OFILE_ALIGNMENT
;
6672 /* For stack variables, the target supports at most
6673 MAX_STACK_ALIGNMENT. */
6674 max_align
= MAX_STACK_ALIGNMENT
;
6675 if (requested_alignment
> max_align
)
6676 alignment_too_large_p
= true;
6678 /* Let's be liberal for types and fields; don't limit their alignment any
6679 more than check_user_alignment already did. */
6681 if (alignment_too_large_p
)
6682 pedwarn (input_location
, OPT_Wattributes
,
6683 "requested alignment %d is larger than %d",
6684 requested_alignment
/ BITS_PER_UNIT
, max_align
/ BITS_PER_UNIT
);
6686 return !alignment_too_large_p
;
6689 /* Handle a "aligned" attribute; arguments as in
6690 struct attribute_spec.handler. */
6693 handle_aligned_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
6694 int flags
, bool *no_add_attrs
)
6696 tree decl
= NULL_TREE
;
6704 align_expr
= TREE_VALUE (args
);
6705 if (align_expr
&& TREE_CODE (align_expr
) != IDENTIFIER_NODE
6706 && TREE_CODE (align_expr
) != FUNCTION_DECL
)
6707 align_expr
= default_conversion (align_expr
);
6710 align_expr
= size_int (ATTRIBUTE_ALIGNED_VALUE
/ BITS_PER_UNIT
);
6715 type
= &TREE_TYPE (decl
);
6716 is_type
= TREE_CODE (*node
) == TYPE_DECL
;
6718 else if (TYPE_P (*node
))
6719 type
= node
, is_type
= 1;
6721 if ((i
= check_user_alignment (align_expr
, true)) == -1
6722 || !check_cxx_fundamental_alignment_constraints (*node
, i
, flags
))
6723 *no_add_attrs
= true;
6726 if ((flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6727 /* OK, modify the type in place. */;
6728 /* If we have a TYPE_DECL, then copy the type, so that we
6729 don't accidentally modify a builtin type. See pushdecl. */
6730 else if (decl
&& TREE_TYPE (decl
) != error_mark_node
6731 && DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
)
6733 tree tt
= TREE_TYPE (decl
);
6734 *type
= build_variant_type_copy (*type
);
6735 DECL_ORIGINAL_TYPE (decl
) = tt
;
6736 TYPE_NAME (*type
) = decl
;
6737 TREE_USED (*type
) = TREE_USED (decl
);
6738 TREE_TYPE (decl
) = *type
;
6741 *type
= build_variant_type_copy (*type
);
6743 SET_TYPE_ALIGN (*type
, (1U << i
) * BITS_PER_UNIT
);
6744 TYPE_USER_ALIGN (*type
) = 1;
6746 else if (! VAR_OR_FUNCTION_DECL_P (decl
)
6747 && TREE_CODE (decl
) != FIELD_DECL
)
6749 error ("alignment may not be specified for %q+D", decl
);
6750 *no_add_attrs
= true;
6752 else if (DECL_USER_ALIGN (decl
)
6753 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
6754 /* C++-11 [dcl.align/4]:
6756 When multiple alignment-specifiers are specified for an
6757 entity, the alignment requirement shall be set to the
6758 strictest specified alignment.
6760 This formally comes from the c++11 specification but we are
6761 doing it for the GNU attribute syntax as well. */
6762 *no_add_attrs
= true;
6763 else if (TREE_CODE (decl
) == FUNCTION_DECL
6764 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
6766 if (DECL_USER_ALIGN (decl
))
6767 error ("alignment for %q+D was previously specified as %d "
6768 "and may not be decreased", decl
,
6769 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
6771 error ("alignment for %q+D must be at least %d", decl
,
6772 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
6773 *no_add_attrs
= true;
6777 SET_DECL_ALIGN (decl
, (1U << i
) * BITS_PER_UNIT
);
6778 DECL_USER_ALIGN (decl
) = 1;
6784 /* Handle a "weak" attribute; arguments as in
6785 struct attribute_spec.handler. */
6788 handle_weak_attribute (tree
*node
, tree name
,
6789 tree
ARG_UNUSED (args
),
6790 int ARG_UNUSED (flags
),
6791 bool * ARG_UNUSED (no_add_attrs
))
6793 if (TREE_CODE (*node
) == FUNCTION_DECL
6794 && DECL_DECLARED_INLINE_P (*node
))
6796 warning (OPT_Wattributes
, "inline function %q+D declared weak", *node
);
6797 *no_add_attrs
= true;
6799 else if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
6801 error ("indirect function %q+D cannot be declared weak", *node
);
6802 *no_add_attrs
= true;
6805 else if (VAR_OR_FUNCTION_DECL_P (*node
))
6806 declare_weak (*node
);
6808 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6813 /* Handle a "noplt" attribute; arguments as in
6814 struct attribute_spec.handler. */
6817 handle_noplt_attribute (tree
*node
, tree name
,
6818 tree
ARG_UNUSED (args
),
6819 int ARG_UNUSED (flags
),
6820 bool * ARG_UNUSED (no_add_attrs
))
6822 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6824 warning (OPT_Wattributes
,
6825 "%qE attribute is only applicable on functions", name
);
6826 *no_add_attrs
= true;
6832 /* Handle an "alias" or "ifunc" attribute; arguments as in
6833 struct attribute_spec.handler, except that IS_ALIAS tells us
6834 whether this is an alias as opposed to ifunc attribute. */
6837 handle_alias_ifunc_attribute (bool is_alias
, tree
*node
, tree name
, tree args
,
6842 if (TREE_CODE (decl
) != FUNCTION_DECL
6843 && (!is_alias
|| !VAR_P (decl
)))
6845 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6846 *no_add_attrs
= true;
6848 else if ((TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INITIAL (decl
))
6849 || (TREE_CODE (decl
) != FUNCTION_DECL
6850 && TREE_PUBLIC (decl
) && !DECL_EXTERNAL (decl
))
6851 /* A static variable declaration is always a tentative definition,
6852 but the alias is a non-tentative definition which overrides. */
6853 || (TREE_CODE (decl
) != FUNCTION_DECL
6854 && ! TREE_PUBLIC (decl
) && DECL_INITIAL (decl
)))
6856 error ("%q+D defined both normally and as %qE attribute", decl
, name
);
6857 *no_add_attrs
= true;
6861 && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
6862 || lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
))))
6864 error ("weak %q+D cannot be defined %qE", decl
, name
);
6865 *no_add_attrs
= true;
6869 /* Note that the very first time we process a nested declaration,
6870 decl_function_context will not be set. Indeed, *would* never
6871 be set except for the DECL_INITIAL/DECL_EXTERNAL frobbery that
6872 we do below. After such frobbery, pushdecl would set the context.
6873 In any case, this is never what we want. */
6874 else if (decl_function_context (decl
) == 0 && current_function_decl
== NULL
)
6878 id
= TREE_VALUE (args
);
6879 if (TREE_CODE (id
) != STRING_CST
)
6881 error ("attribute %qE argument not a string", name
);
6882 *no_add_attrs
= true;
6885 id
= get_identifier (TREE_STRING_POINTER (id
));
6886 /* This counts as a use of the object pointed to. */
6889 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6890 DECL_INITIAL (decl
) = error_mark_node
;
6892 TREE_STATIC (decl
) = 1;
6895 /* ifuncs are also aliases, so set that attribute too. */
6896 DECL_ATTRIBUTES (decl
)
6897 = tree_cons (get_identifier ("alias"), args
, DECL_ATTRIBUTES (decl
));
6901 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6902 *no_add_attrs
= true;
6905 if (decl_in_symtab_p (*node
))
6907 struct symtab_node
*n
= symtab_node::get (decl
);
6908 if (n
&& n
->refuse_visibility_changes
)
6911 error ("%+D declared alias after being used", decl
);
6913 error ("%+D declared ifunc after being used", decl
);
6921 /* Handle an "alias" or "ifunc" attribute; arguments as in
6922 struct attribute_spec.handler. */
6925 handle_ifunc_attribute (tree
*node
, tree name
, tree args
,
6926 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6928 return handle_alias_ifunc_attribute (false, node
, name
, args
, no_add_attrs
);
6931 /* Handle an "alias" or "ifunc" attribute; arguments as in
6932 struct attribute_spec.handler. */
6935 handle_alias_attribute (tree
*node
, tree name
, tree args
,
6936 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6938 return handle_alias_ifunc_attribute (true, node
, name
, args
, no_add_attrs
);
6941 /* Handle a "weakref" attribute; arguments as in struct
6942 attribute_spec.handler. */
6945 handle_weakref_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
6946 int flags
, bool *no_add_attrs
)
6948 tree attr
= NULL_TREE
;
6950 /* We must ignore the attribute when it is associated with
6951 local-scoped decls, since attribute alias is ignored and many
6952 such symbols do not even have a DECL_WEAK field. */
6953 if (decl_function_context (*node
)
6954 || current_function_decl
6955 || !VAR_OR_FUNCTION_DECL_P (*node
))
6957 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6958 *no_add_attrs
= true;
6962 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
6964 error ("indirect function %q+D cannot be declared weakref", *node
);
6965 *no_add_attrs
= true;
6969 /* The idea here is that `weakref("name")' mutates into `weakref,
6970 alias("name")', and weakref without arguments, in turn,
6971 implicitly adds weak. */
6975 attr
= tree_cons (get_identifier ("alias"), args
, attr
);
6976 attr
= tree_cons (get_identifier ("weakref"), NULL_TREE
, attr
);
6978 *no_add_attrs
= true;
6980 decl_attributes (node
, attr
, flags
);
6984 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node
)))
6985 error_at (DECL_SOURCE_LOCATION (*node
),
6986 "weakref attribute must appear before alias attribute");
6988 /* Can't call declare_weak because it wants this to be TREE_PUBLIC,
6989 and that isn't supported; and because it wants to add it to
6990 the list of weak decls, which isn't helpful. */
6991 DECL_WEAK (*node
) = 1;
6994 if (decl_in_symtab_p (*node
))
6996 struct symtab_node
*n
= symtab_node::get (*node
);
6997 if (n
&& n
->refuse_visibility_changes
)
6998 error ("%+D declared weakref after being used", *node
);
7004 /* Handle an "visibility" attribute; arguments as in
7005 struct attribute_spec.handler. */
7008 handle_visibility_attribute (tree
*node
, tree name
, tree args
,
7009 int ARG_UNUSED (flags
),
7010 bool *ARG_UNUSED (no_add_attrs
))
7013 tree id
= TREE_VALUE (args
);
7014 enum symbol_visibility vis
;
7018 if (TREE_CODE (*node
) == ENUMERAL_TYPE
)
7020 else if (!RECORD_OR_UNION_TYPE_P (*node
))
7022 warning (OPT_Wattributes
, "%qE attribute ignored on non-class types",
7026 else if (TYPE_FIELDS (*node
))
7028 error ("%qE attribute ignored because %qT is already defined",
7033 else if (decl_function_context (decl
) != 0 || !TREE_PUBLIC (decl
))
7035 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7039 if (TREE_CODE (id
) != STRING_CST
)
7041 error ("visibility argument not a string");
7045 /* If this is a type, set the visibility on the type decl. */
7048 decl
= TYPE_NAME (decl
);
7051 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
7053 warning (OPT_Wattributes
, "%qE attribute ignored on types",
7059 if (strcmp (TREE_STRING_POINTER (id
), "default") == 0)
7060 vis
= VISIBILITY_DEFAULT
;
7061 else if (strcmp (TREE_STRING_POINTER (id
), "internal") == 0)
7062 vis
= VISIBILITY_INTERNAL
;
7063 else if (strcmp (TREE_STRING_POINTER (id
), "hidden") == 0)
7064 vis
= VISIBILITY_HIDDEN
;
7065 else if (strcmp (TREE_STRING_POINTER (id
), "protected") == 0)
7066 vis
= VISIBILITY_PROTECTED
;
7069 error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
7070 vis
= VISIBILITY_DEFAULT
;
7073 if (DECL_VISIBILITY_SPECIFIED (decl
)
7074 && vis
!= DECL_VISIBILITY (decl
))
7076 tree attributes
= (TYPE_P (*node
)
7077 ? TYPE_ATTRIBUTES (*node
)
7078 : DECL_ATTRIBUTES (decl
));
7079 if (lookup_attribute ("visibility", attributes
))
7080 error ("%qD redeclared with different visibility", decl
);
7081 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
7082 && lookup_attribute ("dllimport", attributes
))
7083 error ("%qD was declared %qs which implies default visibility",
7085 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
7086 && lookup_attribute ("dllexport", attributes
))
7087 error ("%qD was declared %qs which implies default visibility",
7091 DECL_VISIBILITY (decl
) = vis
;
7092 DECL_VISIBILITY_SPECIFIED (decl
) = 1;
7094 /* Go ahead and attach the attribute to the node as well. This is needed
7095 so we can determine whether we have VISIBILITY_DEFAULT because the
7096 visibility was not specified, or because it was explicitly overridden
7097 from the containing scope. */
7102 /* Determine the ELF symbol visibility for DECL, which is either a
7103 variable or a function. It is an error to use this function if a
7104 definition of DECL is not available in this translation unit.
7105 Returns true if the final visibility has been determined by this
7106 function; false if the caller is free to make additional
7110 c_determine_visibility (tree decl
)
7112 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
7114 /* If the user explicitly specified the visibility with an
7115 attribute, honor that. DECL_VISIBILITY will have been set during
7116 the processing of the attribute. We check for an explicit
7117 attribute, rather than just checking DECL_VISIBILITY_SPECIFIED,
7118 to distinguish the use of an attribute from the use of a "#pragma
7119 GCC visibility push(...)"; in the latter case we still want other
7120 considerations to be able to overrule the #pragma. */
7121 if (lookup_attribute ("visibility", DECL_ATTRIBUTES (decl
))
7122 || (TARGET_DLLIMPORT_DECL_ATTRIBUTES
7123 && (lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl
))
7124 || lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl
)))))
7127 /* Set default visibility to whatever the user supplied with
7128 visibility_specified depending on #pragma GCC visibility. */
7129 if (!DECL_VISIBILITY_SPECIFIED (decl
))
7131 if (visibility_options
.inpragma
7132 || DECL_VISIBILITY (decl
) != default_visibility
)
7134 DECL_VISIBILITY (decl
) = default_visibility
;
7135 DECL_VISIBILITY_SPECIFIED (decl
) = visibility_options
.inpragma
;
7136 /* If visibility changed and DECL already has DECL_RTL, ensure
7137 symbol flags are updated. */
7138 if (((VAR_P (decl
) && TREE_STATIC (decl
))
7139 || TREE_CODE (decl
) == FUNCTION_DECL
)
7140 && DECL_RTL_SET_P (decl
))
7141 make_decl_rtl (decl
);
7147 /* Handle an "tls_model" attribute; arguments as in
7148 struct attribute_spec.handler. */
7151 handle_tls_model_attribute (tree
*node
, tree name
, tree args
,
7152 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7156 enum tls_model kind
;
7158 *no_add_attrs
= true;
7160 if (!VAR_P (decl
) || !DECL_THREAD_LOCAL_P (decl
))
7162 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7166 kind
= DECL_TLS_MODEL (decl
);
7167 id
= TREE_VALUE (args
);
7168 if (TREE_CODE (id
) != STRING_CST
)
7170 error ("tls_model argument not a string");
7174 if (!strcmp (TREE_STRING_POINTER (id
), "local-exec"))
7175 kind
= TLS_MODEL_LOCAL_EXEC
;
7176 else if (!strcmp (TREE_STRING_POINTER (id
), "initial-exec"))
7177 kind
= TLS_MODEL_INITIAL_EXEC
;
7178 else if (!strcmp (TREE_STRING_POINTER (id
), "local-dynamic"))
7179 kind
= optimize
? TLS_MODEL_LOCAL_DYNAMIC
: TLS_MODEL_GLOBAL_DYNAMIC
;
7180 else if (!strcmp (TREE_STRING_POINTER (id
), "global-dynamic"))
7181 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
7183 error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
7185 set_decl_tls_model (decl
, kind
);
7189 /* Handle a "no_instrument_function" attribute; arguments as in
7190 struct attribute_spec.handler. */
7193 handle_no_instrument_function_attribute (tree
*node
, tree name
,
7194 tree
ARG_UNUSED (args
),
7195 int ARG_UNUSED (flags
),
7200 if (TREE_CODE (decl
) != FUNCTION_DECL
)
7202 error_at (DECL_SOURCE_LOCATION (decl
),
7203 "%qE attribute applies only to functions", name
);
7204 *no_add_attrs
= true;
7207 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
7212 /* Handle a "no_profile_instrument_function" attribute; arguments as in
7213 struct attribute_spec.handler. */
7216 handle_no_profile_instrument_function_attribute (tree
*node
, tree name
, tree
,
7217 int, bool *no_add_attrs
)
7219 if (TREE_CODE (*node
) != FUNCTION_DECL
)
7221 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7222 *no_add_attrs
= true;
7228 /* Handle a "malloc" attribute; arguments as in
7229 struct attribute_spec.handler. */
7232 handle_malloc_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7233 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7235 if (TREE_CODE (*node
) == FUNCTION_DECL
7236 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node
))))
7237 DECL_IS_MALLOC (*node
) = 1;
7240 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7241 *no_add_attrs
= true;
7247 /* Handle a "alloc_size" attribute; arguments as in
7248 struct attribute_spec.handler. */
7251 handle_alloc_size_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7252 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7254 unsigned arg_count
= type_num_arguments (*node
);
7255 for (; args
; args
= TREE_CHAIN (args
))
7257 tree position
= TREE_VALUE (args
);
7258 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
7259 && TREE_CODE (position
) != FUNCTION_DECL
)
7260 position
= default_conversion (position
);
7262 if (!tree_fits_uhwi_p (position
)
7264 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
7266 warning (OPT_Wattributes
,
7267 "alloc_size parameter outside range");
7268 *no_add_attrs
= true;
7275 /* Handle a "alloc_align" attribute; arguments as in
7276 struct attribute_spec.handler. */
7279 handle_alloc_align_attribute (tree
*node
, tree
, tree args
, int,
7282 unsigned arg_count
= type_num_arguments (*node
);
7283 tree position
= TREE_VALUE (args
);
7284 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
7285 && TREE_CODE (position
) != FUNCTION_DECL
)
7286 position
= default_conversion (position
);
7288 if (!tree_fits_uhwi_p (position
)
7290 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
7292 warning (OPT_Wattributes
,
7293 "alloc_align parameter outside range");
7294 *no_add_attrs
= true;
7300 /* Handle a "assume_aligned" attribute; arguments as in
7301 struct attribute_spec.handler. */
7304 handle_assume_aligned_attribute (tree
*, tree
, tree args
, int,
7307 for (; args
; args
= TREE_CHAIN (args
))
7309 tree position
= TREE_VALUE (args
);
7310 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
7311 && TREE_CODE (position
) != FUNCTION_DECL
)
7312 position
= default_conversion (position
);
7314 if (TREE_CODE (position
) != INTEGER_CST
)
7316 warning (OPT_Wattributes
,
7317 "assume_aligned parameter not integer constant");
7318 *no_add_attrs
= true;
7325 /* Handle a "fn spec" attribute; arguments as in
7326 struct attribute_spec.handler. */
7329 handle_fnspec_attribute (tree
*node ATTRIBUTE_UNUSED
, tree
ARG_UNUSED (name
),
7330 tree args
, int ARG_UNUSED (flags
),
7331 bool *no_add_attrs ATTRIBUTE_UNUSED
)
7334 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
7335 && !TREE_CHAIN (args
));
7339 /* Handle a "bnd_variable_size" attribute; arguments as in
7340 struct attribute_spec.handler. */
7343 handle_bnd_variable_size_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7344 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7346 if (TREE_CODE (*node
) != FIELD_DECL
)
7348 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7349 *no_add_attrs
= true;
7355 /* Handle a "bnd_legacy" attribute; arguments as in
7356 struct attribute_spec.handler. */
7359 handle_bnd_legacy (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7360 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7362 if (TREE_CODE (*node
) != FUNCTION_DECL
)
7364 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7365 *no_add_attrs
= true;
7371 /* Handle a "bnd_instrument" attribute; arguments as in
7372 struct attribute_spec.handler. */
7375 handle_bnd_instrument (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7376 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7378 if (TREE_CODE (*node
) != FUNCTION_DECL
)
7380 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7381 *no_add_attrs
= true;
7387 /* Handle a "warn_unused" attribute; arguments as in
7388 struct attribute_spec.handler. */
7391 handle_warn_unused_attribute (tree
*node
, tree name
,
7392 tree args ATTRIBUTE_UNUSED
,
7393 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
7396 /* Do nothing else, just set the attribute. We'll get at
7397 it later with lookup_attribute. */
7401 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7402 *no_add_attrs
= true;
7408 /* Handle an "omp declare simd" attribute; arguments as in
7409 struct attribute_spec.handler. */
7412 handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int, bool *)
7417 /* Handle a "simd" attribute. */
7420 handle_simd_attribute (tree
*node
, tree name
, tree args
, int, bool *no_add_attrs
)
7422 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7424 if (lookup_attribute ("cilk simd function",
7425 DECL_ATTRIBUTES (*node
)) != NULL
)
7427 error_at (DECL_SOURCE_LOCATION (*node
),
7428 "%<__simd__%> attribute cannot be used in the same "
7429 "function marked as a Cilk Plus SIMD-enabled function");
7430 *no_add_attrs
= true;
7434 tree t
= get_identifier ("omp declare simd");
7435 tree attr
= NULL_TREE
;
7438 tree id
= TREE_VALUE (args
);
7440 if (TREE_CODE (id
) != STRING_CST
)
7442 error ("attribute %qE argument not a string", name
);
7443 *no_add_attrs
= true;
7447 if (strcmp (TREE_STRING_POINTER (id
), "notinbranch") == 0)
7448 attr
= build_omp_clause (DECL_SOURCE_LOCATION (*node
),
7449 OMP_CLAUSE_NOTINBRANCH
);
7451 if (strcmp (TREE_STRING_POINTER (id
), "inbranch") == 0)
7452 attr
= build_omp_clause (DECL_SOURCE_LOCATION (*node
),
7453 OMP_CLAUSE_INBRANCH
);
7456 error ("only %<inbranch%> and %<notinbranch%> flags are "
7457 "allowed for %<__simd__%> attribute");
7458 *no_add_attrs
= true;
7463 DECL_ATTRIBUTES (*node
) = tree_cons (t
,
7464 build_tree_list (NULL_TREE
,
7466 DECL_ATTRIBUTES (*node
));
7471 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7472 *no_add_attrs
= true;
7478 /* Handle an "omp declare target" attribute; arguments as in
7479 struct attribute_spec.handler. */
7482 handle_omp_declare_target_attribute (tree
*, tree
, tree
, int, bool *)
7487 /* Handle a "returns_twice" attribute; arguments as in
7488 struct attribute_spec.handler. */
7491 handle_returns_twice_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7492 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7494 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7495 DECL_IS_RETURNS_TWICE (*node
) = 1;
7498 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7499 *no_add_attrs
= true;
7505 /* Handle a "no_limit_stack" attribute; arguments as in
7506 struct attribute_spec.handler. */
7509 handle_no_limit_stack_attribute (tree
*node
, tree name
,
7510 tree
ARG_UNUSED (args
),
7511 int ARG_UNUSED (flags
),
7516 if (TREE_CODE (decl
) != FUNCTION_DECL
)
7518 error_at (DECL_SOURCE_LOCATION (decl
),
7519 "%qE attribute applies only to functions", name
);
7520 *no_add_attrs
= true;
7522 else if (DECL_INITIAL (decl
))
7524 error_at (DECL_SOURCE_LOCATION (decl
),
7525 "can%'t set %qE attribute after definition", name
);
7526 *no_add_attrs
= true;
7529 DECL_NO_LIMIT_STACK (decl
) = 1;
7534 /* Handle a "pure" attribute; arguments as in
7535 struct attribute_spec.handler. */
7538 handle_pure_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7539 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7541 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7542 DECL_PURE_P (*node
) = 1;
7543 /* ??? TODO: Support types. */
7546 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7547 *no_add_attrs
= true;
7553 /* Digest an attribute list destined for a transactional memory statement.
7554 ALLOWED is the set of attributes that are allowed for this statement;
7555 return the attribute we parsed. Multiple attributes are never allowed. */
7558 parse_tm_stmt_attr (tree attrs
, int allowed
)
7563 for ( ; attrs
; attrs
= TREE_CHAIN (attrs
))
7565 tree a
= TREE_PURPOSE (attrs
);
7568 if (is_attribute_p ("outer", a
))
7569 m
= TM_STMT_ATTR_OUTER
;
7571 if ((m
& allowed
) == 0)
7573 warning (OPT_Wattributes
, "%qE attribute directive ignored", a
);
7582 else if (m_seen
== m
)
7583 warning (OPT_Wattributes
, "%qE attribute duplicated", a
);
7585 warning (OPT_Wattributes
, "%qE attribute follows %qE", a
, a_seen
);
7591 /* Transform a TM attribute name into a maskable integer and back.
7592 Note that NULL (i.e. no attribute) is mapped to UNKNOWN, corresponding
7593 to how the lack of an attribute is treated. */
7596 tm_attr_to_mask (tree attr
)
7600 if (is_attribute_p ("transaction_safe", attr
))
7601 return TM_ATTR_SAFE
;
7602 if (is_attribute_p ("transaction_callable", attr
))
7603 return TM_ATTR_CALLABLE
;
7604 if (is_attribute_p ("transaction_pure", attr
))
7605 return TM_ATTR_PURE
;
7606 if (is_attribute_p ("transaction_unsafe", attr
))
7607 return TM_ATTR_IRREVOCABLE
;
7608 if (is_attribute_p ("transaction_may_cancel_outer", attr
))
7609 return TM_ATTR_MAY_CANCEL_OUTER
;
7614 tm_mask_to_attr (int mask
)
7620 str
= "transaction_safe";
7622 case TM_ATTR_CALLABLE
:
7623 str
= "transaction_callable";
7626 str
= "transaction_pure";
7628 case TM_ATTR_IRREVOCABLE
:
7629 str
= "transaction_unsafe";
7631 case TM_ATTR_MAY_CANCEL_OUTER
:
7632 str
= "transaction_may_cancel_outer";
7637 return get_identifier (str
);
7640 /* Return the first TM attribute seen in LIST. */
7643 find_tm_attribute (tree list
)
7645 for (; list
; list
= TREE_CHAIN (list
))
7647 tree name
= TREE_PURPOSE (list
);
7648 if (tm_attr_to_mask (name
) != 0)
7654 /* Handle the TM attributes; arguments as in struct attribute_spec.handler.
7655 Here we accept only function types, and verify that none of the other
7656 function TM attributes are also applied. */
7657 /* ??? We need to accept class types for C++, but not C. This greatly
7658 complicates this function, since we can no longer rely on the extra
7659 processing given by function_type_required. */
7662 handle_tm_attribute (tree
*node
, tree name
, tree args
,
7663 int flags
, bool *no_add_attrs
)
7665 /* Only one path adds the attribute; others don't. */
7666 *no_add_attrs
= true;
7668 switch (TREE_CODE (*node
))
7672 /* Only tm_callable and tm_safe apply to classes. */
7673 if (tm_attr_to_mask (name
) & ~(TM_ATTR_SAFE
| TM_ATTR_CALLABLE
))
7680 tree old_name
= find_tm_attribute (TYPE_ATTRIBUTES (*node
));
7681 if (old_name
== name
)
7683 else if (old_name
!= NULL_TREE
)
7684 error ("type was previously declared %qE", old_name
);
7686 *no_add_attrs
= false;
7692 /* transaction_safe_dynamic goes on the FUNCTION_DECL, but we also
7693 want to set transaction_safe on the type. */
7694 gcc_assert (is_attribute_p ("transaction_safe_dynamic", name
));
7695 if (!TYPE_P (DECL_CONTEXT (*node
)))
7696 error_at (DECL_SOURCE_LOCATION (*node
),
7697 "%<transaction_safe_dynamic%> may only be specified for "
7698 "a virtual function");
7699 *no_add_attrs
= false;
7700 decl_attributes (&TREE_TYPE (*node
),
7701 build_tree_list (get_identifier ("transaction_safe"),
7709 enum tree_code subcode
= TREE_CODE (TREE_TYPE (*node
));
7710 if (subcode
== FUNCTION_TYPE
|| subcode
== METHOD_TYPE
)
7712 tree fn_tmp
= TREE_TYPE (*node
);
7713 decl_attributes (&fn_tmp
, tree_cons (name
, args
, NULL
), 0);
7714 *node
= build_pointer_type (fn_tmp
);
7721 /* If a function is next, pass it on to be tried next. */
7722 if (flags
& (int) ATTR_FLAG_FUNCTION_NEXT
)
7723 return tree_cons (name
, args
, NULL
);
7726 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7733 /* Handle the TM_WRAP attribute; arguments as in
7734 struct attribute_spec.handler. */
7737 handle_tm_wrap_attribute (tree
*node
, tree name
, tree args
,
7738 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7742 /* We don't need the attribute even on success, since we
7743 record the entry in an external table. */
7744 *no_add_attrs
= true;
7746 if (TREE_CODE (decl
) != FUNCTION_DECL
)
7747 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7750 tree wrap_decl
= TREE_VALUE (args
);
7751 if (error_operand_p (wrap_decl
))
7753 else if (TREE_CODE (wrap_decl
) != IDENTIFIER_NODE
7754 && !VAR_OR_FUNCTION_DECL_P (wrap_decl
))
7755 error ("%qE argument not an identifier", name
);
7758 if (TREE_CODE (wrap_decl
) == IDENTIFIER_NODE
)
7759 wrap_decl
= lookup_name (wrap_decl
);
7760 if (wrap_decl
&& TREE_CODE (wrap_decl
) == FUNCTION_DECL
)
7762 if (lang_hooks
.types_compatible_p (TREE_TYPE (decl
),
7763 TREE_TYPE (wrap_decl
)))
7764 record_tm_replacement (wrap_decl
, decl
);
7766 error ("%qD is not compatible with %qD", wrap_decl
, decl
);
7769 error ("%qE argument is not a function", name
);
7776 /* Ignore the given attribute. Used when this attribute may be usefully
7777 overridden by the target, but is not used generically. */
7780 ignore_attribute (tree
* ARG_UNUSED (node
), tree
ARG_UNUSED (name
),
7781 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
7784 *no_add_attrs
= true;
7788 /* Handle a "no vops" attribute; arguments as in
7789 struct attribute_spec.handler. */
7792 handle_novops_attribute (tree
*node
, tree
ARG_UNUSED (name
),
7793 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
7794 bool *ARG_UNUSED (no_add_attrs
))
7796 gcc_assert (TREE_CODE (*node
) == FUNCTION_DECL
);
7797 DECL_IS_NOVOPS (*node
) = 1;
7801 /* Handle a "deprecated" attribute; arguments as in
7802 struct attribute_spec.handler. */
7805 handle_deprecated_attribute (tree
*node
, tree name
,
7806 tree args
, int flags
,
7809 tree type
= NULL_TREE
;
7811 tree what
= NULL_TREE
;
7814 *no_add_attrs
= true;
7815 else if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
7817 error ("deprecated message is not a string");
7818 *no_add_attrs
= true;
7824 type
= TREE_TYPE (decl
);
7826 if (TREE_CODE (decl
) == TYPE_DECL
7827 || TREE_CODE (decl
) == PARM_DECL
7828 || VAR_OR_FUNCTION_DECL_P (decl
)
7829 || TREE_CODE (decl
) == FIELD_DECL
7830 || TREE_CODE (decl
) == CONST_DECL
7831 || objc_method_decl (TREE_CODE (decl
)))
7832 TREE_DEPRECATED (decl
) = 1;
7836 else if (TYPE_P (*node
))
7838 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7839 *node
= build_variant_type_copy (*node
);
7840 TREE_DEPRECATED (*node
) = 1;
7848 *no_add_attrs
= true;
7849 if (type
&& TYPE_NAME (type
))
7851 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
7852 what
= TYPE_NAME (*node
);
7853 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
7854 && DECL_NAME (TYPE_NAME (type
)))
7855 what
= DECL_NAME (TYPE_NAME (type
));
7858 warning (OPT_Wattributes
, "%qE attribute ignored for %qE", name
, what
);
7860 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7866 /* Handle a "vector_size" attribute; arguments as in
7867 struct attribute_spec.handler. */
7870 handle_vector_size_attribute (tree
*node
, tree name
, tree args
,
7871 int ARG_UNUSED (flags
),
7874 unsigned HOST_WIDE_INT vecsize
, nunits
;
7875 machine_mode orig_mode
;
7876 tree type
= *node
, new_type
, size
;
7878 *no_add_attrs
= true;
7880 size
= TREE_VALUE (args
);
7881 if (size
&& TREE_CODE (size
) != IDENTIFIER_NODE
7882 && TREE_CODE (size
) != FUNCTION_DECL
)
7883 size
= default_conversion (size
);
7885 if (!tree_fits_uhwi_p (size
))
7887 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7891 /* Get the vector size (in bytes). */
7892 vecsize
= tree_to_uhwi (size
);
7894 /* We need to provide for vector pointers, vector arrays, and
7895 functions returning vectors. For example:
7897 __attribute__((vector_size(16))) short *foo;
7899 In this case, the mode is SI, but the type being modified is
7900 HI, so we need to look further. */
7902 while (POINTER_TYPE_P (type
)
7903 || TREE_CODE (type
) == FUNCTION_TYPE
7904 || TREE_CODE (type
) == METHOD_TYPE
7905 || TREE_CODE (type
) == ARRAY_TYPE
7906 || TREE_CODE (type
) == OFFSET_TYPE
)
7907 type
= TREE_TYPE (type
);
7909 /* Get the mode of the type being modified. */
7910 orig_mode
= TYPE_MODE (type
);
7912 if ((!INTEGRAL_TYPE_P (type
)
7913 && !SCALAR_FLOAT_TYPE_P (type
)
7914 && !FIXED_POINT_TYPE_P (type
))
7915 || (!SCALAR_FLOAT_MODE_P (orig_mode
)
7916 && GET_MODE_CLASS (orig_mode
) != MODE_INT
7917 && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode
))
7918 || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
7919 || TREE_CODE (type
) == BOOLEAN_TYPE
)
7921 error ("invalid vector type for attribute %qE", name
);
7925 if (vecsize
% tree_to_uhwi (TYPE_SIZE_UNIT (type
)))
7927 error ("vector size not an integral multiple of component size");
7933 error ("zero vector size");
7937 /* Calculate how many units fit in the vector. */
7938 nunits
= vecsize
/ tree_to_uhwi (TYPE_SIZE_UNIT (type
));
7939 if (nunits
& (nunits
- 1))
7941 error ("number of components of the vector not a power of two");
7945 new_type
= build_vector_type (type
, nunits
);
7947 /* Build back pointers if needed. */
7948 *node
= lang_hooks
.types
.reconstruct_complex_type (*node
, new_type
);
7953 /* Handle the "nonnull" attribute. */
7955 handle_nonnull_attribute (tree
*node
, tree
ARG_UNUSED (name
),
7956 tree args
, int ARG_UNUSED (flags
),
7960 unsigned HOST_WIDE_INT attr_arg_num
;
7962 /* If no arguments are specified, all pointer arguments should be
7963 non-null. Verify a full prototype is given so that the arguments
7964 will have the correct types when we actually check them later.
7965 Avoid diagnosing type-generic built-ins since those have no
7969 if (!prototype_p (type
)
7970 && (!TYPE_ATTRIBUTES (type
)
7971 || !lookup_attribute ("type generic", TYPE_ATTRIBUTES (type
))))
7973 error ("nonnull attribute without arguments on a non-prototype");
7974 *no_add_attrs
= true;
7979 /* Argument list specified. Verify that each argument number references
7980 a pointer argument. */
7981 for (attr_arg_num
= 1; args
; attr_arg_num
++, args
= TREE_CHAIN (args
))
7983 unsigned HOST_WIDE_INT arg_num
= 0, ck_num
;
7985 tree arg
= TREE_VALUE (args
);
7986 if (arg
&& TREE_CODE (arg
) != IDENTIFIER_NODE
7987 && TREE_CODE (arg
) != FUNCTION_DECL
)
7988 arg
= default_conversion (arg
);
7990 if (!get_nonnull_operand (arg
, &arg_num
))
7992 error ("nonnull argument has invalid operand number (argument %lu)",
7993 (unsigned long) attr_arg_num
);
7994 *no_add_attrs
= true;
7998 if (prototype_p (type
))
8000 function_args_iterator iter
;
8003 function_args_iter_init (&iter
, type
);
8004 for (ck_num
= 1; ; ck_num
++, function_args_iter_next (&iter
))
8006 argument
= function_args_iter_cond (&iter
);
8007 if (argument
== NULL_TREE
|| ck_num
== arg_num
)
8012 || TREE_CODE (argument
) == VOID_TYPE
)
8014 error ("nonnull argument with out-of-range operand number (argument %lu, operand %lu)",
8015 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
8016 *no_add_attrs
= true;
8020 if (TREE_CODE (argument
) != POINTER_TYPE
)
8022 error ("nonnull argument references non-pointer operand (argument %lu, operand %lu)",
8023 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
8024 *no_add_attrs
= true;
8033 /* Check the argument list of a function call for null in argument slots
8034 that are marked as requiring a non-null pointer argument. The NARGS
8035 arguments are passed in the array ARGARRAY. */
8038 check_function_nonnull (location_t loc
, tree attrs
, int nargs
, tree
*argarray
)
8043 attrs
= lookup_attribute ("nonnull", attrs
);
8044 if (attrs
== NULL_TREE
)
8048 /* See if any of the nonnull attributes has no arguments. If so,
8049 then every pointer argument is checked (in which case the check
8050 for pointer type is done in check_nonnull_arg). */
8051 if (TREE_VALUE (a
) != NULL_TREE
)
8053 a
= lookup_attribute ("nonnull", TREE_CHAIN (a
));
8054 while (a
!= NULL_TREE
&& TREE_VALUE (a
) != NULL_TREE
);
8057 for (i
= 0; i
< nargs
; i
++)
8058 check_function_arguments_recurse (check_nonnull_arg
, &loc
, argarray
[i
],
8062 /* Walk the argument list. If we encounter an argument number we
8063 should check for non-null, do it. */
8064 for (i
= 0; i
< nargs
; i
++)
8066 for (a
= attrs
; ; a
= TREE_CHAIN (a
))
8068 a
= lookup_attribute ("nonnull", a
);
8069 if (a
== NULL_TREE
|| nonnull_check_p (TREE_VALUE (a
), i
+ 1))
8074 check_function_arguments_recurse (check_nonnull_arg
, &loc
,
8075 argarray
[i
], i
+ 1);
8080 /* Check that the Nth argument of a function call (counting backwards
8081 from the end) is a (pointer)0. The NARGS arguments are passed in the
8085 check_function_sentinel (const_tree fntype
, int nargs
, tree
*argarray
)
8087 tree attr
= lookup_attribute ("sentinel", TYPE_ATTRIBUTES (fntype
));
8094 function_args_iterator iter
;
8097 /* Skip over the named arguments. */
8098 FOREACH_FUNCTION_ARGS (fntype
, t
, iter
)
8105 if (TREE_VALUE (attr
))
8107 tree p
= TREE_VALUE (TREE_VALUE (attr
));
8108 pos
= TREE_INT_CST_LOW (p
);
8111 /* The sentinel must be one of the varargs, i.e.
8112 in position >= the number of fixed arguments. */
8113 if ((nargs
- 1 - pos
) < len
)
8115 warning (OPT_Wformat_
,
8116 "not enough variable arguments to fit a sentinel");
8120 /* Validate the sentinel. */
8121 sentinel
= argarray
[nargs
- 1 - pos
];
8122 if ((!POINTER_TYPE_P (TREE_TYPE (sentinel
))
8123 || !integer_zerop (sentinel
))
8124 /* Although __null (in C++) is only an integer we allow it
8125 nevertheless, as we are guaranteed that it's exactly
8126 as wide as a pointer, and we don't want to force
8127 users to cast the NULL they have written there.
8128 We warn with -Wstrict-null-sentinel, though. */
8129 && (warn_strict_null_sentinel
|| null_node
!= sentinel
))
8130 warning (OPT_Wformat_
, "missing sentinel in function call");
8134 /* Helper for check_function_nonnull; given a list of operands which
8135 must be non-null in ARGS, determine if operand PARAM_NUM should be
8139 nonnull_check_p (tree args
, unsigned HOST_WIDE_INT param_num
)
8141 unsigned HOST_WIDE_INT arg_num
= 0;
8143 for (; args
; args
= TREE_CHAIN (args
))
8145 bool found
= get_nonnull_operand (TREE_VALUE (args
), &arg_num
);
8149 if (arg_num
== param_num
)
8155 /* Check that the function argument PARAM (which is operand number
8156 PARAM_NUM) is non-null. This is called by check_function_nonnull
8157 via check_function_arguments_recurse. */
8160 check_nonnull_arg (void *ctx
, tree param
, unsigned HOST_WIDE_INT param_num
)
8162 location_t
*ploc
= (location_t
*) ctx
;
8164 /* Just skip checking the argument if it's not a pointer. This can
8165 happen if the "nonnull" attribute was given without an operand
8166 list (which means to check every pointer argument). */
8168 if (TREE_CODE (TREE_TYPE (param
)) != POINTER_TYPE
)
8171 if (integer_zerop (param
))
8172 warning_at (*ploc
, OPT_Wnonnull
, "null argument where non-null required "
8173 "(argument %lu)", (unsigned long) param_num
);
8176 /* Helper for nonnull attribute handling; fetch the operand number
8177 from the attribute argument list. */
8180 get_nonnull_operand (tree arg_num_expr
, unsigned HOST_WIDE_INT
*valp
)
8182 /* Verify the arg number is a small constant. */
8183 if (tree_fits_uhwi_p (arg_num_expr
))
8185 *valp
= TREE_INT_CST_LOW (arg_num_expr
);
8192 /* Handle a "nothrow" attribute; arguments as in
8193 struct attribute_spec.handler. */
8196 handle_nothrow_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8197 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8199 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8200 TREE_NOTHROW (*node
) = 1;
8201 /* ??? TODO: Support types. */
8204 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8205 *no_add_attrs
= true;
8211 /* Handle a "cleanup" attribute; arguments as in
8212 struct attribute_spec.handler. */
8215 handle_cleanup_attribute (tree
*node
, tree name
, tree args
,
8216 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8219 tree cleanup_id
, cleanup_decl
;
8221 /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
8222 for global destructors in C++. This requires infrastructure that
8223 we don't have generically at the moment. It's also not a feature
8224 we'd be missing too much, since we do have attribute constructor. */
8225 if (!VAR_P (decl
) || TREE_STATIC (decl
))
8227 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8228 *no_add_attrs
= true;
8232 /* Verify that the argument is a function in scope. */
8233 /* ??? We could support pointers to functions here as well, if
8234 that was considered desirable. */
8235 cleanup_id
= TREE_VALUE (args
);
8236 if (TREE_CODE (cleanup_id
) != IDENTIFIER_NODE
)
8238 error ("cleanup argument not an identifier");
8239 *no_add_attrs
= true;
8242 cleanup_decl
= lookup_name (cleanup_id
);
8243 if (!cleanup_decl
|| TREE_CODE (cleanup_decl
) != FUNCTION_DECL
)
8245 error ("cleanup argument not a function");
8246 *no_add_attrs
= true;
8250 /* That the function has proper type is checked with the
8251 eventual call to build_function_call. */
8256 /* Handle a "warn_unused_result" attribute. No special handling. */
8259 handle_warn_unused_result_attribute (tree
*node
, tree name
,
8260 tree
ARG_UNUSED (args
),
8261 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8263 /* Ignore the attribute for functions not returning any value. */
8264 if (VOID_TYPE_P (TREE_TYPE (*node
)))
8266 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8267 *no_add_attrs
= true;
8273 /* Handle a "sentinel" attribute. */
8276 handle_sentinel_attribute (tree
*node
, tree name
, tree args
,
8277 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8279 if (!prototype_p (*node
))
8281 warning (OPT_Wattributes
,
8282 "%qE attribute requires prototypes with named arguments", name
);
8283 *no_add_attrs
= true;
8287 if (!stdarg_p (*node
))
8289 warning (OPT_Wattributes
,
8290 "%qE attribute only applies to variadic functions", name
);
8291 *no_add_attrs
= true;
8297 tree position
= TREE_VALUE (args
);
8298 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
8299 && TREE_CODE (position
) != FUNCTION_DECL
)
8300 position
= default_conversion (position
);
8302 if (TREE_CODE (position
) != INTEGER_CST
8303 || !INTEGRAL_TYPE_P (TREE_TYPE (position
)))
8305 warning (OPT_Wattributes
,
8306 "requested position is not an integer constant");
8307 *no_add_attrs
= true;
8311 if (tree_int_cst_lt (position
, integer_zero_node
))
8313 warning (OPT_Wattributes
,
8314 "requested position is less than zero");
8315 *no_add_attrs
= true;
8323 /* Handle a "type_generic" attribute. */
8326 handle_type_generic_attribute (tree
*node
, tree
ARG_UNUSED (name
),
8327 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
8328 bool * ARG_UNUSED (no_add_attrs
))
8330 /* Ensure we have a function type. */
8331 gcc_assert (TREE_CODE (*node
) == FUNCTION_TYPE
);
8333 /* Ensure we have a variadic function. */
8334 gcc_assert (!prototype_p (*node
) || stdarg_p (*node
));
8339 /* Handle a "target" attribute. */
8342 handle_target_attribute (tree
*node
, tree name
, tree args
, int flags
,
8345 /* Ensure we have a function type. */
8346 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8348 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8349 *no_add_attrs
= true;
8351 else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node
)))
8353 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
8354 "with %qs attribute", name
, "target_clones");
8355 *no_add_attrs
= true;
8357 else if (! targetm
.target_option
.valid_attribute_p (*node
, name
, args
,
8359 *no_add_attrs
= true;
8364 /* Handle a "target_clones" attribute. */
8367 handle_target_clones_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8368 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8370 /* Ensure we have a function type. */
8371 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8373 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node
)))
8375 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
8376 "with %qs attribute", name
, "always_inline");
8377 *no_add_attrs
= true;
8379 else if (lookup_attribute ("target", DECL_ATTRIBUTES (*node
)))
8381 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
8382 "with %qs attribute", name
, "target");
8383 *no_add_attrs
= true;
8386 /* Do not inline functions with multiple clone targets. */
8387 DECL_UNINLINABLE (*node
) = 1;
8391 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8392 *no_add_attrs
= true;
8397 /* Arguments being collected for optimization. */
8398 typedef const char *const_char_p
; /* For DEF_VEC_P. */
8399 static GTY(()) vec
<const_char_p
, va_gc
> *optimize_args
;
8402 /* Inner function to convert a TREE_LIST to argv string to parse the optimize
8403 options in ARGS. ATTR_P is true if this is for attribute(optimize), and
8404 false for #pragma GCC optimize. */
8407 parse_optimize_options (tree args
, bool attr_p
)
8412 const char **opt_argv
;
8413 struct cl_decoded_option
*decoded_options
;
8414 unsigned int decoded_options_count
;
8417 /* Build up argv vector. Just in case the string is stored away, use garbage
8418 collected strings. */
8419 vec_safe_truncate (optimize_args
, 0);
8420 vec_safe_push (optimize_args
, (const char *) NULL
);
8422 for (ap
= args
; ap
!= NULL_TREE
; ap
= TREE_CHAIN (ap
))
8424 tree value
= TREE_VALUE (ap
);
8426 if (TREE_CODE (value
) == INTEGER_CST
)
8429 sprintf (buffer
, "-O%ld", (long) TREE_INT_CST_LOW (value
));
8430 vec_safe_push (optimize_args
, ggc_strdup (buffer
));
8433 else if (TREE_CODE (value
) == STRING_CST
)
8435 /* Split string into multiple substrings. */
8436 size_t len
= TREE_STRING_LENGTH (value
);
8437 char *p
= ASTRDUP (TREE_STRING_POINTER (value
));
8438 char *end
= p
+ len
;
8442 while (next_p
!= NULL
)
8448 comma
= strchr (p
, ',');
8461 r
= q
= (char *) ggc_alloc_atomic (len2
+ 3);
8463 /* If the user supplied -Oxxx or -fxxx, only allow -Oxxx or -fxxx
8465 if (*p
== '-' && p
[1] != 'O' && p
[1] != 'f')
8469 warning (OPT_Wattributes
,
8470 "bad option %qs to attribute %<optimize%>", p
);
8472 warning (OPT_Wpragmas
,
8473 "bad option %qs to pragma %<optimize%>", p
);
8481 /* Assume that Ox is -Ox, a numeric value is -Ox, a s by
8482 itself is -Os, and any other switch begins with a -f. */
8483 if ((*p
>= '0' && *p
<= '9')
8484 || (p
[0] == 's' && p
[1] == '\0'))
8490 memcpy (r
, p
, len2
);
8492 vec_safe_push (optimize_args
, (const char *) q
);
8498 opt_argc
= optimize_args
->length ();
8499 opt_argv
= (const char **) alloca (sizeof (char *) * (opt_argc
+ 1));
8501 for (i
= 1; i
< opt_argc
; i
++)
8502 opt_argv
[i
] = (*optimize_args
)[i
];
8504 /* Now parse the options. */
8505 decode_cmdline_options_to_array_default_mask (opt_argc
, opt_argv
,
8507 &decoded_options_count
);
8508 /* Drop non-Optimization options. */
8510 for (i
= 1; i
< decoded_options_count
; ++i
)
8512 if (! (cl_options
[decoded_options
[i
].opt_index
].flags
& CL_OPTIMIZATION
))
8516 warning (OPT_Wattributes
,
8517 "bad option %qs to attribute %<optimize%>",
8518 decoded_options
[i
].orig_option_with_args_text
);
8520 warning (OPT_Wpragmas
,
8521 "bad option %qs to pragma %<optimize%>",
8522 decoded_options
[i
].orig_option_with_args_text
);
8526 decoded_options
[j
] = decoded_options
[i
];
8529 decoded_options_count
= j
;
8530 /* And apply them. */
8531 decode_options (&global_options
, &global_options_set
,
8532 decoded_options
, decoded_options_count
,
8533 input_location
, global_dc
);
8535 targetm
.override_options_after_change();
8537 optimize_args
->truncate (0);
8541 /* For handling "optimize" attribute. arguments as in
8542 struct attribute_spec.handler. */
8545 handle_optimize_attribute (tree
*node
, tree name
, tree args
,
8546 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8548 /* Ensure we have a function type. */
8549 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8551 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8552 *no_add_attrs
= true;
8556 struct cl_optimization cur_opts
;
8557 tree old_opts
= DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
);
8559 /* Save current options. */
8560 cl_optimization_save (&cur_opts
, &global_options
);
8562 /* If we previously had some optimization options, use them as the
8565 cl_optimization_restore (&global_options
,
8566 TREE_OPTIMIZATION (old_opts
));
8568 /* Parse options, and update the vector. */
8569 parse_optimize_options (args
, true);
8570 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
)
8571 = build_optimization_node (&global_options
);
8573 /* Restore current options. */
8574 cl_optimization_restore (&global_options
, &cur_opts
);
8580 /* Handle a "no_split_stack" attribute. */
8583 handle_no_split_stack_attribute (tree
*node
, tree name
,
8584 tree
ARG_UNUSED (args
),
8585 int ARG_UNUSED (flags
),
8590 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8592 error_at (DECL_SOURCE_LOCATION (decl
),
8593 "%qE attribute applies only to functions", name
);
8594 *no_add_attrs
= true;
8596 else if (DECL_INITIAL (decl
))
8598 error_at (DECL_SOURCE_LOCATION (decl
),
8599 "can%'t set %qE attribute after definition", name
);
8600 *no_add_attrs
= true;
8606 /* Handle a "returns_nonnull" attribute; arguments as in
8607 struct attribute_spec.handler. */
8610 handle_returns_nonnull_attribute (tree
*node
, tree
, tree
, int,
8613 // Even without a prototype we still have a return type we can check.
8614 if (TREE_CODE (TREE_TYPE (*node
)) != POINTER_TYPE
)
8616 error ("returns_nonnull attribute on a function not returning a pointer");
8617 *no_add_attrs
= true;
8622 /* Handle a "designated_init" attribute; arguments as in
8623 struct attribute_spec.handler. */
8626 handle_designated_init_attribute (tree
*node
, tree name
, tree
, int,
8629 if (TREE_CODE (*node
) != RECORD_TYPE
)
8631 error ("%qE attribute is only valid on %<struct%> type", name
);
8632 *no_add_attrs
= true;
8638 /* Handle a "fallthrough" attribute; arguments as in struct
8639 attribute_spec.handler. */
8642 handle_fallthrough_attribute (tree
*, tree name
, tree
, int,
8645 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8646 *no_add_attrs
= true;
8650 /* Check whether ATTR is a valid attribute fallthrough. */
8653 attribute_fallthrough_p (tree attr
)
8655 tree t
= lookup_attribute ("fallthrough", attr
);
8658 /* This attribute shall appear at most once in each attribute-list. */
8659 if (lookup_attribute ("fallthrough", TREE_CHAIN (t
)))
8660 warning (OPT_Wattributes
, "%<fallthrough%> attribute specified multiple "
8662 /* No attribute-argument-clause shall be present. */
8663 else if (TREE_VALUE (t
) != NULL_TREE
)
8664 warning (OPT_Wattributes
, "%<fallthrough%> attribute specified with "
8666 /* Warn if other attributes are found. */
8667 for (t
= attr
; t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
8669 tree name
= get_attribute_name (t
);
8670 if (!is_attribute_p ("fallthrough", name
))
8671 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8677 /* Check for valid arguments being passed to a function with FNTYPE.
8678 There are NARGS arguments in the array ARGARRAY. LOC should be used for
8681 check_function_arguments (location_t loc
, const_tree fntype
, int nargs
,
8684 /* Check for null being passed in a pointer argument that must be
8685 non-null. We also need to do this if format checking is enabled. */
8688 check_function_nonnull (loc
, TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
8690 /* Check for errors in format strings. */
8692 if (warn_format
|| warn_suggest_attribute_format
)
8693 check_function_format (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
8696 check_function_sentinel (fntype
, nargs
, argarray
);
8699 /* Generic argument checking recursion routine. PARAM is the argument to
8700 be checked. PARAM_NUM is the number of the argument. CALLBACK is invoked
8701 once the argument is resolved. CTX is context for the callback. */
8703 check_function_arguments_recurse (void (*callback
)
8704 (void *, tree
, unsigned HOST_WIDE_INT
),
8705 void *ctx
, tree param
,
8706 unsigned HOST_WIDE_INT param_num
)
8708 if (CONVERT_EXPR_P (param
)
8709 && (TYPE_PRECISION (TREE_TYPE (param
))
8710 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (param
, 0)))))
8712 /* Strip coercion. */
8713 check_function_arguments_recurse (callback
, ctx
,
8714 TREE_OPERAND (param
, 0), param_num
);
8718 if (TREE_CODE (param
) == CALL_EXPR
)
8720 tree type
= TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (param
)));
8722 bool found_format_arg
= false;
8724 /* See if this is a call to a known internationalization function
8725 that modifies a format arg. Such a function may have multiple
8726 format_arg attributes (for example, ngettext). */
8728 for (attrs
= TYPE_ATTRIBUTES (type
);
8730 attrs
= TREE_CHAIN (attrs
))
8731 if (is_attribute_p ("format_arg", TREE_PURPOSE (attrs
)))
8734 tree format_num_expr
;
8737 call_expr_arg_iterator iter
;
8739 /* Extract the argument number, which was previously checked
8741 format_num_expr
= TREE_VALUE (TREE_VALUE (attrs
));
8743 format_num
= tree_to_uhwi (format_num_expr
);
8745 for (inner_arg
= first_call_expr_arg (param
, &iter
), i
= 1;
8747 inner_arg
= next_call_expr_arg (&iter
), i
++)
8748 if (i
== format_num
)
8750 check_function_arguments_recurse (callback
, ctx
,
8751 inner_arg
, param_num
);
8752 found_format_arg
= true;
8757 /* If we found a format_arg attribute and did a recursive check,
8758 we are done with checking this argument. Otherwise, we continue
8759 and this will be considered a non-literal. */
8760 if (found_format_arg
)
8764 if (TREE_CODE (param
) == COND_EXPR
)
8766 /* Simplify to avoid warning for an impossible case. */
8767 param
= fold_for_warn (param
);
8768 if (TREE_CODE (param
) == COND_EXPR
)
8770 /* Check both halves of the conditional expression. */
8771 check_function_arguments_recurse (callback
, ctx
,
8772 TREE_OPERAND (param
, 1),
8774 check_function_arguments_recurse (callback
, ctx
,
8775 TREE_OPERAND (param
, 2),
8781 (*callback
) (ctx
, param
, param_num
);
8784 /* Checks for a builtin function FNDECL that the number of arguments
8785 NARGS against the required number REQUIRED and issues an error if
8786 there is a mismatch. Returns true if the number of arguments is
8787 correct, otherwise false. LOC is the location of FNDECL. */
8790 builtin_function_validate_nargs (location_t loc
, tree fndecl
, int nargs
,
8793 if (nargs
< required
)
8795 error_at (loc
, "too few arguments to function %qE", fndecl
);
8798 else if (nargs
> required
)
8800 error_at (loc
, "too many arguments to function %qE", fndecl
);
8806 /* Helper macro for check_builtin_function_arguments. */
8807 #define ARG_LOCATION(N) \
8808 (arg_loc.is_empty () \
8809 ? EXPR_LOC_OR_LOC (args[(N)], input_location) \
8810 : expansion_point_location (arg_loc[(N)]))
8812 /* Verifies the NARGS arguments ARGS to the builtin function FNDECL.
8813 Returns false if there was an error, otherwise true. LOC is the
8814 location of the function; ARG_LOC is a vector of locations of the
8818 check_builtin_function_arguments (location_t loc
, vec
<location_t
> arg_loc
,
8819 tree fndecl
, int nargs
, tree
*args
)
8821 if (!DECL_BUILT_IN (fndecl
)
8822 || DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_NORMAL
)
8825 switch (DECL_FUNCTION_CODE (fndecl
))
8827 case BUILT_IN_ALLOCA_WITH_ALIGN
:
8829 /* Get the requested alignment (in bits) if it's a constant
8830 integer expression. */
8831 unsigned HOST_WIDE_INT align
8832 = tree_fits_uhwi_p (args
[1]) ? tree_to_uhwi (args
[1]) : 0;
8834 /* Determine if the requested alignment is a power of 2. */
8835 if ((align
& (align
- 1)))
8838 /* The maximum alignment in bits corresponding to the same
8839 maximum in bytes enforced in check_user_alignment(). */
8840 unsigned maxalign
= (UINT_MAX
>> 1) + 1;
8842 /* Reject invalid alignments. */
8843 if (align
< BITS_PER_UNIT
|| maxalign
< align
)
8845 error_at (ARG_LOCATION (1),
8846 "second argument to function %qE must be a constant "
8847 "integer power of 2 between %qi and %qu bits",
8848 fndecl
, BITS_PER_UNIT
, maxalign
);
8854 case BUILT_IN_CONSTANT_P
:
8855 return builtin_function_validate_nargs (loc
, fndecl
, nargs
, 1);
8857 case BUILT_IN_ISFINITE
:
8858 case BUILT_IN_ISINF
:
8859 case BUILT_IN_ISINF_SIGN
:
8860 case BUILT_IN_ISNAN
:
8861 case BUILT_IN_ISNORMAL
:
8862 case BUILT_IN_SIGNBIT
:
8863 if (builtin_function_validate_nargs (loc
, fndecl
, nargs
, 1))
8865 if (TREE_CODE (TREE_TYPE (args
[0])) != REAL_TYPE
)
8867 error_at (ARG_LOCATION (0), "non-floating-point argument in "
8868 "call to function %qE", fndecl
);
8875 case BUILT_IN_ISGREATER
:
8876 case BUILT_IN_ISGREATEREQUAL
:
8877 case BUILT_IN_ISLESS
:
8878 case BUILT_IN_ISLESSEQUAL
:
8879 case BUILT_IN_ISLESSGREATER
:
8880 case BUILT_IN_ISUNORDERED
:
8881 if (builtin_function_validate_nargs (loc
, fndecl
, nargs
, 2))
8883 enum tree_code code0
, code1
;
8884 code0
= TREE_CODE (TREE_TYPE (args
[0]));
8885 code1
= TREE_CODE (TREE_TYPE (args
[1]));
8886 if (!((code0
== REAL_TYPE
&& code1
== REAL_TYPE
)
8887 || (code0
== REAL_TYPE
&& code1
== INTEGER_TYPE
)
8888 || (code0
== INTEGER_TYPE
&& code1
== REAL_TYPE
)))
8890 error_at (loc
, "non-floating-point arguments in call to "
8891 "function %qE", fndecl
);
8898 case BUILT_IN_FPCLASSIFY
:
8899 if (builtin_function_validate_nargs (loc
, fndecl
, nargs
, 6))
8901 for (unsigned int i
= 0; i
< 5; i
++)
8902 if (TREE_CODE (args
[i
]) != INTEGER_CST
)
8904 error_at (ARG_LOCATION (i
), "non-const integer argument %u in "
8905 "call to function %qE", i
+ 1, fndecl
);
8909 if (TREE_CODE (TREE_TYPE (args
[5])) != REAL_TYPE
)
8911 error_at (ARG_LOCATION (5), "non-floating-point argument in "
8912 "call to function %qE", fndecl
);
8919 case BUILT_IN_ASSUME_ALIGNED
:
8920 if (builtin_function_validate_nargs (loc
, fndecl
, nargs
, 2 + (nargs
> 2)))
8922 if (nargs
>= 3 && TREE_CODE (TREE_TYPE (args
[2])) != INTEGER_TYPE
)
8924 error_at (ARG_LOCATION (2), "non-integer argument 3 in call to "
8925 "function %qE", fndecl
);
8932 case BUILT_IN_ADD_OVERFLOW
:
8933 case BUILT_IN_SUB_OVERFLOW
:
8934 case BUILT_IN_MUL_OVERFLOW
:
8935 if (builtin_function_validate_nargs (loc
, fndecl
, nargs
, 3))
8938 for (i
= 0; i
< 2; i
++)
8939 if (!INTEGRAL_TYPE_P (TREE_TYPE (args
[i
])))
8941 error_at (ARG_LOCATION (i
), "argument %u in call to function "
8942 "%qE does not have integral type", i
+ 1, fndecl
);
8945 if (TREE_CODE (TREE_TYPE (args
[2])) != POINTER_TYPE
8946 || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (args
[2]))))
8948 error_at (ARG_LOCATION (2), "argument 3 in call to function %qE "
8949 "does not have pointer to integral type", fndecl
);
8952 else if (TREE_CODE (TREE_TYPE (TREE_TYPE (args
[2]))) == ENUMERAL_TYPE
)
8954 error_at (ARG_LOCATION (2), "argument 3 in call to function %qE "
8955 "has pointer to enumerated type", fndecl
);
8958 else if (TREE_CODE (TREE_TYPE (TREE_TYPE (args
[2]))) == BOOLEAN_TYPE
)
8960 error_at (ARG_LOCATION (2), "argument 3 in call to function %qE "
8961 "has pointer to boolean type", fndecl
);
8968 case BUILT_IN_ADD_OVERFLOW_P
:
8969 case BUILT_IN_SUB_OVERFLOW_P
:
8970 case BUILT_IN_MUL_OVERFLOW_P
:
8971 if (builtin_function_validate_nargs (loc
, fndecl
, nargs
, 3))
8974 for (i
= 0; i
< 3; i
++)
8975 if (!INTEGRAL_TYPE_P (TREE_TYPE (args
[i
])))
8977 error_at (ARG_LOCATION (i
), "argument %u in call to function "
8978 "%qE does not have integral type", i
+ 1, fndecl
);
8981 if (TREE_CODE (TREE_TYPE (args
[2])) == ENUMERAL_TYPE
)
8983 error_at (ARG_LOCATION (2), "argument 3 in call to function "
8984 "%qE has enumerated type", fndecl
);
8987 else if (TREE_CODE (TREE_TYPE (args
[2])) == BOOLEAN_TYPE
)
8989 error_at (ARG_LOCATION (2), "argument 3 in call to function "
8990 "%qE has boolean type", fndecl
);
9002 /* Function to help qsort sort FIELD_DECLs by name order. */
9005 field_decl_cmp (const void *x_p
, const void *y_p
)
9007 const tree
*const x
= (const tree
*const) x_p
;
9008 const tree
*const y
= (const tree
*const) y_p
;
9010 if (DECL_NAME (*x
) == DECL_NAME (*y
))
9011 /* A nontype is "greater" than a type. */
9012 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
9013 if (DECL_NAME (*x
) == NULL_TREE
)
9015 if (DECL_NAME (*y
) == NULL_TREE
)
9017 if (DECL_NAME (*x
) < DECL_NAME (*y
))
9023 gt_pointer_operator new_value
;
9027 /* This routine compares two fields like field_decl_cmp but using the
9028 pointer operator in resort_data. */
9031 resort_field_decl_cmp (const void *x_p
, const void *y_p
)
9033 const tree
*const x
= (const tree
*const) x_p
;
9034 const tree
*const y
= (const tree
*const) y_p
;
9036 if (DECL_NAME (*x
) == DECL_NAME (*y
))
9037 /* A nontype is "greater" than a type. */
9038 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
9039 if (DECL_NAME (*x
) == NULL_TREE
)
9041 if (DECL_NAME (*y
) == NULL_TREE
)
9044 tree d1
= DECL_NAME (*x
);
9045 tree d2
= DECL_NAME (*y
);
9046 resort_data
.new_value (&d1
, resort_data
.cookie
);
9047 resort_data
.new_value (&d2
, resort_data
.cookie
);
9054 /* Resort DECL_SORTED_FIELDS because pointers have been reordered. */
9057 resort_sorted_fields (void *obj
,
9058 void * ARG_UNUSED (orig_obj
),
9059 gt_pointer_operator new_value
,
9062 struct sorted_fields_type
*sf
= (struct sorted_fields_type
*) obj
;
9063 resort_data
.new_value
= new_value
;
9064 resort_data
.cookie
= cookie
;
9065 qsort (&sf
->elts
[0], sf
->len
, sizeof (tree
),
9066 resort_field_decl_cmp
);
9069 /* Subroutine of c_parse_error.
9070 Return the result of concatenating LHS and RHS. RHS is really
9071 a string literal, its first character is indicated by RHS_START and
9072 RHS_SIZE is its length (including the terminating NUL character).
9074 The caller is responsible for deleting the returned pointer. */
9077 catenate_strings (const char *lhs
, const char *rhs_start
, int rhs_size
)
9079 const int lhs_size
= strlen (lhs
);
9080 char *result
= XNEWVEC (char, lhs_size
+ rhs_size
);
9081 strncpy (result
, lhs
, lhs_size
);
9082 strncpy (result
+ lhs_size
, rhs_start
, rhs_size
);
9086 /* Issue the error given by GMSGID, indicating that it occurred before
9087 TOKEN, which had the associated VALUE. */
9090 c_parse_error (const char *gmsgid
, enum cpp_ttype token_type
,
9091 tree value
, unsigned char token_flags
)
9093 #define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2))
9095 char *message
= NULL
;
9097 if (token_type
== CPP_EOF
)
9098 message
= catenate_messages (gmsgid
, " at end of input");
9099 else if (token_type
== CPP_CHAR
9100 || token_type
== CPP_WCHAR
9101 || token_type
== CPP_CHAR16
9102 || token_type
== CPP_CHAR32
9103 || token_type
== CPP_UTF8CHAR
)
9105 unsigned int val
= TREE_INT_CST_LOW (value
);
9127 if (val
<= UCHAR_MAX
&& ISGRAPH (val
))
9128 message
= catenate_messages (gmsgid
, " before %s'%c'");
9130 message
= catenate_messages (gmsgid
, " before %s'\\x%x'");
9132 error (message
, prefix
, val
);
9136 else if (token_type
== CPP_CHAR_USERDEF
9137 || token_type
== CPP_WCHAR_USERDEF
9138 || token_type
== CPP_CHAR16_USERDEF
9139 || token_type
== CPP_CHAR32_USERDEF
9140 || token_type
== CPP_UTF8CHAR_USERDEF
)
9141 message
= catenate_messages (gmsgid
,
9142 " before user-defined character literal");
9143 else if (token_type
== CPP_STRING_USERDEF
9144 || token_type
== CPP_WSTRING_USERDEF
9145 || token_type
== CPP_STRING16_USERDEF
9146 || token_type
== CPP_STRING32_USERDEF
9147 || token_type
== CPP_UTF8STRING_USERDEF
)
9148 message
= catenate_messages (gmsgid
, " before user-defined string literal");
9149 else if (token_type
== CPP_STRING
9150 || token_type
== CPP_WSTRING
9151 || token_type
== CPP_STRING16
9152 || token_type
== CPP_STRING32
9153 || token_type
== CPP_UTF8STRING
)
9154 message
= catenate_messages (gmsgid
, " before string constant");
9155 else if (token_type
== CPP_NUMBER
)
9156 message
= catenate_messages (gmsgid
, " before numeric constant");
9157 else if (token_type
== CPP_NAME
)
9159 message
= catenate_messages (gmsgid
, " before %qE");
9160 error (message
, value
);
9164 else if (token_type
== CPP_PRAGMA
)
9165 message
= catenate_messages (gmsgid
, " before %<#pragma%>");
9166 else if (token_type
== CPP_PRAGMA_EOL
)
9167 message
= catenate_messages (gmsgid
, " before end of line");
9168 else if (token_type
== CPP_DECLTYPE
)
9169 message
= catenate_messages (gmsgid
, " before %<decltype%>");
9170 else if (token_type
< N_TTYPES
)
9172 message
= catenate_messages (gmsgid
, " before %qs token");
9173 error (message
, cpp_type2name (token_type
, token_flags
));
9185 #undef catenate_messages
9188 /* Return the gcc option code associated with the reason for a cpp
9189 message, or 0 if none. */
9192 c_option_controlling_cpp_error (int reason
)
9194 const struct cpp_reason_option_codes_t
*entry
;
9196 for (entry
= cpp_reason_option_codes
; entry
->reason
!= CPP_W_NONE
; entry
++)
9198 if (entry
->reason
== reason
)
9199 return entry
->option_code
;
9204 /* Callback from cpp_error for PFILE to print diagnostics from the
9205 preprocessor. The diagnostic is of type LEVEL, with REASON set
9206 to the reason code if LEVEL is represents a warning, at location
9207 RICHLOC unless this is after lexing and the compiler's location
9208 should be used instead; MSG is the translated message and AP
9209 the arguments. Returns true if a diagnostic was emitted, false
9213 c_cpp_error (cpp_reader
*pfile ATTRIBUTE_UNUSED
, int level
, int reason
,
9214 rich_location
*richloc
,
9215 const char *msg
, va_list *ap
)
9217 diagnostic_info diagnostic
;
9218 diagnostic_t dlevel
;
9219 bool save_warn_system_headers
= global_dc
->dc_warn_system_headers
;
9224 case CPP_DL_WARNING_SYSHDR
:
9227 global_dc
->dc_warn_system_headers
= 1;
9229 case CPP_DL_WARNING
:
9232 dlevel
= DK_WARNING
;
9234 case CPP_DL_PEDWARN
:
9235 if (flag_no_output
&& !flag_pedantic_errors
)
9237 dlevel
= DK_PEDWARN
;
9255 richloc
->set_range (line_table
, 0, input_location
, true);
9256 diagnostic_set_info_translated (&diagnostic
, msg
, ap
,
9258 diagnostic_override_option_index (&diagnostic
,
9259 c_option_controlling_cpp_error (reason
));
9260 ret
= report_diagnostic (&diagnostic
);
9261 if (level
== CPP_DL_WARNING_SYSHDR
)
9262 global_dc
->dc_warn_system_headers
= save_warn_system_headers
;
9266 /* Convert a character from the host to the target execution character
9267 set. cpplib handles this, mostly. */
9270 c_common_to_target_charset (HOST_WIDE_INT c
)
9272 /* Character constants in GCC proper are sign-extended under -fsigned-char,
9273 zero-extended under -fno-signed-char. cpplib insists that characters
9274 and character constants are always unsigned. Hence we must convert
9276 cppchar_t uc
= ((cppchar_t
)c
) & ((((cppchar_t
)1) << CHAR_BIT
)-1);
9278 uc
= cpp_host_to_exec_charset (parse_in
, uc
);
9280 if (flag_signed_char
)
9281 return ((HOST_WIDE_INT
)uc
) << (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
)
9282 >> (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
);
9287 /* Fold an offsetof-like expression. EXPR is a nested sequence of component
9288 references with an INDIRECT_REF of a constant at the bottom; much like the
9289 traditional rendering of offsetof as a macro. Return the folded result. */
9292 fold_offsetof_1 (tree expr
, enum tree_code ctx
)
9295 tree_code code
= TREE_CODE (expr
);
9302 error ("cannot apply %<offsetof%> to static data member %qD", expr
);
9303 return error_mark_node
;
9307 error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded");
9308 return error_mark_node
;
9312 if (!TREE_CONSTANT (TREE_OPERAND (expr
, 0)))
9314 error ("cannot apply %<offsetof%> to a non constant address");
9315 return error_mark_node
;
9317 return TREE_OPERAND (expr
, 0);
9320 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0), code
);
9321 if (base
== error_mark_node
)
9324 t
= TREE_OPERAND (expr
, 1);
9325 if (DECL_C_BIT_FIELD (t
))
9327 error ("attempt to take address of bit-field structure "
9329 return error_mark_node
;
9331 off
= size_binop_loc (input_location
, PLUS_EXPR
, DECL_FIELD_OFFSET (t
),
9332 size_int (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (t
))
9337 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0), code
);
9338 if (base
== error_mark_node
)
9341 t
= TREE_OPERAND (expr
, 1);
9343 /* Check if the offset goes beyond the upper bound of the array. */
9344 if (TREE_CODE (t
) == INTEGER_CST
&& tree_int_cst_sgn (t
) >= 0)
9346 tree upbound
= array_ref_up_bound (expr
);
9347 if (upbound
!= NULL_TREE
9348 && TREE_CODE (upbound
) == INTEGER_CST
9349 && !tree_int_cst_equal (upbound
,
9350 TYPE_MAX_VALUE (TREE_TYPE (upbound
))))
9352 if (ctx
!= ARRAY_REF
&& ctx
!= COMPONENT_REF
)
9353 upbound
= size_binop (PLUS_EXPR
, upbound
,
9354 build_int_cst (TREE_TYPE (upbound
), 1));
9355 if (tree_int_cst_lt (upbound
, t
))
9359 for (v
= TREE_OPERAND (expr
, 0);
9360 TREE_CODE (v
) == COMPONENT_REF
;
9361 v
= TREE_OPERAND (v
, 0))
9362 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v
, 0)))
9365 tree fld_chain
= DECL_CHAIN (TREE_OPERAND (v
, 1));
9366 for (; fld_chain
; fld_chain
= DECL_CHAIN (fld_chain
))
9367 if (TREE_CODE (fld_chain
) == FIELD_DECL
)
9373 /* Don't warn if the array might be considered a poor
9374 man's flexible array member with a very permissive
9375 definition thereof. */
9376 if (TREE_CODE (v
) == ARRAY_REF
9377 || TREE_CODE (v
) == COMPONENT_REF
)
9378 warning (OPT_Warray_bounds
,
9379 "index %E denotes an offset "
9380 "greater than size of %qT",
9381 t
, TREE_TYPE (TREE_OPERAND (expr
, 0)));
9386 t
= convert (sizetype
, t
);
9387 off
= size_binop (MULT_EXPR
, TYPE_SIZE_UNIT (TREE_TYPE (expr
)), t
);
9391 /* Handle static members of volatile structs. */
9392 t
= TREE_OPERAND (expr
, 1);
9393 gcc_assert (VAR_P (t
));
9394 return fold_offsetof_1 (t
);
9400 return fold_build_pointer_plus (base
, off
);
9403 /* Likewise, but convert it to the return type of offsetof. */
9406 fold_offsetof (tree expr
)
9408 return convert (size_type_node
, fold_offsetof_1 (expr
));
9412 /* *PTYPE is an incomplete array. Complete it with a domain based on
9413 INITIAL_VALUE. If INITIAL_VALUE is not present, use 1 if DO_DEFAULT
9414 is true. Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
9415 2 if INITIAL_VALUE was NULL, and 3 if INITIAL_VALUE was empty. */
9418 complete_array_type (tree
*ptype
, tree initial_value
, bool do_default
)
9420 tree maxindex
, type
, main_type
, elt
, unqual_elt
;
9421 int failure
= 0, quals
;
9422 hashval_t hashcode
= 0;
9423 bool overflow_p
= false;
9425 maxindex
= size_zero_node
;
9428 if (TREE_CODE (initial_value
) == STRING_CST
)
9431 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value
)));
9432 maxindex
= size_int (TREE_STRING_LENGTH (initial_value
)/eltsize
- 1);
9434 else if (TREE_CODE (initial_value
) == CONSTRUCTOR
)
9436 vec
<constructor_elt
, va_gc
> *v
= CONSTRUCTOR_ELTS (initial_value
);
9438 if (vec_safe_is_empty (v
))
9442 maxindex
= ssize_int (-1);
9447 unsigned HOST_WIDE_INT cnt
;
9448 constructor_elt
*ce
;
9449 bool fold_p
= false;
9452 maxindex
= (*v
)[0].index
, fold_p
= true;
9454 curindex
= maxindex
;
9456 for (cnt
= 1; vec_safe_iterate (v
, cnt
, &ce
); cnt
++)
9458 bool curfold_p
= false;
9460 curindex
= ce
->index
, curfold_p
= true;
9465 /* Since we treat size types now as ordinary
9466 unsigned types, we need an explicit overflow
9468 tree orig
= curindex
;
9469 curindex
= fold_convert (sizetype
, curindex
);
9470 overflow_p
|= tree_int_cst_lt (curindex
, orig
);
9472 curindex
= size_binop (PLUS_EXPR
, curindex
,
9475 if (tree_int_cst_lt (maxindex
, curindex
))
9476 maxindex
= curindex
, fold_p
= curfold_p
;
9480 tree orig
= maxindex
;
9481 maxindex
= fold_convert (sizetype
, maxindex
);
9482 overflow_p
|= tree_int_cst_lt (maxindex
, orig
);
9488 /* Make an error message unless that happened already. */
9489 if (initial_value
!= error_mark_node
)
9501 elt
= TREE_TYPE (type
);
9502 quals
= TYPE_QUALS (strip_array_types (elt
));
9506 unqual_elt
= c_build_qualified_type (elt
, KEEP_QUAL_ADDR_SPACE (quals
));
9508 /* Using build_distinct_type_copy and modifying things afterward instead
9509 of using build_array_type to create a new type preserves all of the
9510 TYPE_LANG_FLAG_? bits that the front end may have set. */
9511 main_type
= build_distinct_type_copy (TYPE_MAIN_VARIANT (type
));
9512 TREE_TYPE (main_type
) = unqual_elt
;
9513 TYPE_DOMAIN (main_type
)
9514 = build_range_type (TREE_TYPE (maxindex
),
9515 build_int_cst (TREE_TYPE (maxindex
), 0), maxindex
);
9516 layout_type (main_type
);
9518 /* Make sure we have the canonical MAIN_TYPE. */
9519 hashcode
= iterative_hash_object (TYPE_HASH (unqual_elt
), hashcode
);
9520 hashcode
= iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (main_type
)),
9522 main_type
= type_hash_canon (hashcode
, main_type
);
9524 /* Fix the canonical type. */
9525 if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type
))
9526 || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type
)))
9527 SET_TYPE_STRUCTURAL_EQUALITY (main_type
);
9528 else if (TYPE_CANONICAL (TREE_TYPE (main_type
)) != TREE_TYPE (main_type
)
9529 || (TYPE_CANONICAL (TYPE_DOMAIN (main_type
))
9530 != TYPE_DOMAIN (main_type
)))
9531 TYPE_CANONICAL (main_type
)
9532 = build_array_type (TYPE_CANONICAL (TREE_TYPE (main_type
)),
9533 TYPE_CANONICAL (TYPE_DOMAIN (main_type
)));
9535 TYPE_CANONICAL (main_type
) = main_type
;
9540 type
= c_build_qualified_type (main_type
, quals
);
9542 if (COMPLETE_TYPE_P (type
)
9543 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
9544 && (overflow_p
|| TREE_OVERFLOW (TYPE_SIZE_UNIT (type
))))
9546 error ("size of array is too large");
9547 /* If we proceed with the array type as it is, we'll eventually
9548 crash in tree_to_[su]hwi(). */
9549 type
= error_mark_node
;
9556 /* Like c_mark_addressable but don't check register qualifier. */
9558 c_common_mark_addressable_vec (tree t
)
9560 while (handled_component_p (t
))
9561 t
= TREE_OPERAND (t
, 0);
9563 && TREE_CODE (t
) != PARM_DECL
9564 && TREE_CODE (t
) != COMPOUND_LITERAL_EXPR
)
9566 TREE_ADDRESSABLE (t
) = 1;
9571 /* Used to help initialize the builtin-types.def table. When a type of
9572 the correct size doesn't exist, use error_mark_node instead of NULL.
9573 The later results in segfaults even when a decl using the type doesn't
9577 builtin_type_for_size (int size
, bool unsignedp
)
9579 tree type
= c_common_type_for_size (size
, unsignedp
);
9580 return type
? type
: error_mark_node
;
9583 /* A helper function for resolve_overloaded_builtin in resolving the
9584 overloaded __sync_ builtins. Returns a positive power of 2 if the
9585 first operand of PARAMS is a pointer to a supported data type.
9586 Returns 0 if an error is encountered.
9587 FETCH is true when FUNCTION is one of the _FETCH_OP_ or _OP_FETCH_
9591 sync_resolve_size (tree function
, vec
<tree
, va_gc
> *params
, bool fetch
)
9593 /* Type of the argument. */
9595 /* Type the argument points to. */
9599 if (vec_safe_is_empty (params
))
9601 error ("too few arguments to function %qE", function
);
9605 argtype
= type
= TREE_TYPE ((*params
)[0]);
9606 if (TREE_CODE (type
) == ARRAY_TYPE
)
9608 /* Force array-to-pointer decay for C++. */
9609 gcc_assert (c_dialect_cxx());
9610 (*params
)[0] = default_conversion ((*params
)[0]);
9611 type
= TREE_TYPE ((*params
)[0]);
9613 if (TREE_CODE (type
) != POINTER_TYPE
)
9616 type
= TREE_TYPE (type
);
9617 if (!INTEGRAL_TYPE_P (type
) && !POINTER_TYPE_P (type
))
9620 if (fetch
&& TREE_CODE (type
) == BOOLEAN_TYPE
)
9623 size
= tree_to_uhwi (TYPE_SIZE_UNIT (type
));
9624 if (size
== 1 || size
== 2 || size
== 4 || size
== 8 || size
== 16)
9628 /* Issue the diagnostic only if the argument is valid, otherwise
9629 it would be redundant at best and could be misleading. */
9630 if (argtype
!= error_mark_node
)
9631 error ("operand type %qT is incompatible with argument %d of %qE",
9632 argtype
, 1, function
);
9636 /* A helper function for resolve_overloaded_builtin. Adds casts to
9637 PARAMS to make arguments match up with those of FUNCTION. Drops
9638 the variadic arguments at the end. Returns false if some error
9639 was encountered; true on success. */
9642 sync_resolve_params (location_t loc
, tree orig_function
, tree function
,
9643 vec
<tree
, va_gc
> *params
, bool orig_format
)
9645 function_args_iterator iter
;
9647 unsigned int parmnum
;
9649 function_args_iter_init (&iter
, TREE_TYPE (function
));
9650 /* We've declared the implementation functions to use "volatile void *"
9651 as the pointer parameter, so we shouldn't get any complaints from the
9652 call to check_function_arguments what ever type the user used. */
9653 function_args_iter_next (&iter
);
9654 ptype
= TREE_TYPE (TREE_TYPE ((*params
)[0]));
9655 ptype
= TYPE_MAIN_VARIANT (ptype
);
9657 /* For the rest of the values, we need to cast these to FTYPE, so that we
9658 don't get warnings for passing pointer types, etc. */
9664 arg_type
= function_args_iter_cond (&iter
);
9665 /* XXX void_type_node belies the abstraction. */
9666 if (arg_type
== void_type_node
)
9670 if (params
->length () <= parmnum
)
9672 error_at (loc
, "too few arguments to function %qE", orig_function
);
9676 /* Only convert parameters if arg_type is unsigned integer type with
9677 new format sync routines, i.e. don't attempt to convert pointer
9678 arguments (e.g. EXPECTED argument of __atomic_compare_exchange_n),
9679 bool arguments (e.g. WEAK argument) or signed int arguments (memmodel
9681 if (TREE_CODE (arg_type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (arg_type
))
9683 /* Ideally for the first conversion we'd use convert_for_assignment
9684 so that we get warnings for anything that doesn't match the pointer
9685 type. This isn't portable across the C and C++ front ends atm. */
9686 val
= (*params
)[parmnum
];
9687 val
= convert (ptype
, val
);
9688 val
= convert (arg_type
, val
);
9689 (*params
)[parmnum
] = val
;
9692 function_args_iter_next (&iter
);
9695 /* __atomic routines are not variadic. */
9696 if (!orig_format
&& params
->length () != parmnum
+ 1)
9698 error_at (loc
, "too many arguments to function %qE", orig_function
);
9702 /* The definition of these primitives is variadic, with the remaining
9703 being "an optional list of variables protected by the memory barrier".
9704 No clue what that's supposed to mean, precisely, but we consider all
9705 call-clobbered variables to be protected so we're safe. */
9706 params
->truncate (parmnum
+ 1);
9711 /* A helper function for resolve_overloaded_builtin. Adds a cast to
9712 RESULT to make it match the type of the first pointer argument in
9716 sync_resolve_return (tree first_param
, tree result
, bool orig_format
)
9718 tree ptype
= TREE_TYPE (TREE_TYPE (first_param
));
9719 tree rtype
= TREE_TYPE (result
);
9720 ptype
= TYPE_MAIN_VARIANT (ptype
);
9722 /* New format doesn't require casting unless the types are the same size. */
9723 if (orig_format
|| tree_int_cst_equal (TYPE_SIZE (ptype
), TYPE_SIZE (rtype
)))
9724 return convert (ptype
, result
);
9729 /* This function verifies the PARAMS to generic atomic FUNCTION.
9730 It returns the size if all the parameters are the same size, otherwise
9731 0 is returned if the parameters are invalid. */
9734 get_atomic_generic_size (location_t loc
, tree function
,
9735 vec
<tree
, va_gc
> *params
)
9737 unsigned int n_param
;
9738 unsigned int n_model
;
9743 /* Determine the parameter makeup. */
9744 switch (DECL_FUNCTION_CODE (function
))
9746 case BUILT_IN_ATOMIC_EXCHANGE
:
9750 case BUILT_IN_ATOMIC_LOAD
:
9751 case BUILT_IN_ATOMIC_STORE
:
9755 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
9763 if (vec_safe_length (params
) != n_param
)
9765 error_at (loc
, "incorrect number of arguments to function %qE", function
);
9769 /* Get type of first parameter, and determine its size. */
9770 type_0
= TREE_TYPE ((*params
)[0]);
9771 if (TREE_CODE (type_0
) == ARRAY_TYPE
)
9773 /* Force array-to-pointer decay for C++. */
9774 gcc_assert (c_dialect_cxx());
9775 (*params
)[0] = default_conversion ((*params
)[0]);
9776 type_0
= TREE_TYPE ((*params
)[0]);
9778 if (TREE_CODE (type_0
) != POINTER_TYPE
|| VOID_TYPE_P (TREE_TYPE (type_0
)))
9780 error_at (loc
, "argument 1 of %qE must be a non-void pointer type",
9785 /* Types must be compile time constant sizes. */
9786 if (TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type_0
)))) != INTEGER_CST
)
9789 "argument 1 of %qE must be a pointer to a constant size type",
9794 size_0
= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type_0
)));
9796 /* Zero size objects are not allowed. */
9800 "argument 1 of %qE must be a pointer to a nonzero size object",
9805 /* Check each other parameter is a pointer and the same size. */
9806 for (x
= 0; x
< n_param
- n_model
; x
++)
9809 tree type
= TREE_TYPE ((*params
)[x
]);
9810 /* __atomic_compare_exchange has a bool in the 4th position, skip it. */
9811 if (n_param
== 6 && x
== 3)
9813 if (!POINTER_TYPE_P (type
))
9815 error_at (loc
, "argument %d of %qE must be a pointer type", x
+ 1,
9819 else if (TYPE_SIZE_UNIT (TREE_TYPE (type
))
9820 && TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type
))))
9823 error_at (loc
, "argument %d of %qE must be a pointer to a constant "
9824 "size type", x
+ 1, function
);
9827 else if (FUNCTION_POINTER_TYPE_P (type
))
9829 error_at (loc
, "argument %d of %qE must not be a pointer to a "
9830 "function", x
+ 1, function
);
9833 tree type_size
= TYPE_SIZE_UNIT (TREE_TYPE (type
));
9834 size
= type_size
? tree_to_uhwi (type_size
) : 0;
9837 error_at (loc
, "size mismatch in argument %d of %qE", x
+ 1,
9843 /* Check memory model parameters for validity. */
9844 for (x
= n_param
- n_model
; x
< n_param
; x
++)
9846 tree p
= (*params
)[x
];
9847 if (TREE_CODE (p
) == INTEGER_CST
)
9849 int i
= tree_to_uhwi (p
);
9850 if (i
< 0 || (memmodel_base (i
) >= MEMMODEL_LAST
))
9852 warning_at (loc
, OPT_Winvalid_memory_model
,
9853 "invalid memory model argument %d of %qE", x
+ 1,
9858 if (!INTEGRAL_TYPE_P (TREE_TYPE (p
)))
9860 error_at (loc
, "non-integer memory model argument %d of %qE", x
+ 1,
9870 /* This will take an __atomic_ generic FUNCTION call, and add a size parameter N
9871 at the beginning of the parameter list PARAMS representing the size of the
9872 objects. This is to match the library ABI requirement. LOC is the location
9873 of the function call.
9874 The new function is returned if it needed rebuilding, otherwise NULL_TREE is
9875 returned to allow the external call to be constructed. */
9878 add_atomic_size_parameter (unsigned n
, location_t loc
, tree function
,
9879 vec
<tree
, va_gc
> *params
)
9883 /* Insert a SIZE_T parameter as the first param. If there isn't
9884 enough space, allocate a new vector and recursively re-build with that. */
9885 if (!params
->space (1))
9887 unsigned int z
, len
;
9888 vec
<tree
, va_gc
> *v
;
9891 len
= params
->length ();
9892 vec_alloc (v
, len
+ 1);
9893 v
->quick_push (build_int_cst (size_type_node
, n
));
9894 for (z
= 0; z
< len
; z
++)
9895 v
->quick_push ((*params
)[z
]);
9896 f
= build_function_call_vec (loc
, vNULL
, function
, v
, NULL
);
9901 /* Add the size parameter and leave as a function call for processing. */
9902 size_node
= build_int_cst (size_type_node
, n
);
9903 params
->quick_insert (0, size_node
);
9908 /* Return whether atomic operations for naturally aligned N-byte
9909 arguments are supported, whether inline or through libatomic. */
9911 atomic_size_supported_p (int n
)
9922 return targetm
.scalar_mode_supported_p (TImode
);
9929 /* This will process an __atomic_exchange function call, determine whether it
9930 needs to be mapped to the _N variation, or turned into a library call.
9931 LOC is the location of the builtin call.
9932 FUNCTION is the DECL that has been invoked;
9933 PARAMS is the argument list for the call. The return value is non-null
9934 TRUE is returned if it is translated into the proper format for a call to the
9935 external library, and NEW_RETURN is set the tree for that function.
9936 FALSE is returned if processing for the _N variation is required, and
9937 NEW_RETURN is set to the return value the result is copied into. */
9939 resolve_overloaded_atomic_exchange (location_t loc
, tree function
,
9940 vec
<tree
, va_gc
> *params
, tree
*new_return
)
9942 tree p0
, p1
, p2
, p3
;
9943 tree I_type
, I_type_ptr
;
9944 int n
= get_atomic_generic_size (loc
, function
, params
);
9946 /* Size of 0 is an error condition. */
9949 *new_return
= error_mark_node
;
9953 /* If not a lock-free size, change to the library generic format. */
9954 if (!atomic_size_supported_p (n
))
9956 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
9960 /* Otherwise there is a lockfree match, transform the call from:
9961 void fn(T* mem, T* desired, T* return, model)
9963 *return = (T) (fn (In* mem, (In) *desired, model)) */
9970 /* Create pointer to appropriate size. */
9971 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
9972 I_type_ptr
= build_pointer_type (I_type
);
9974 /* Convert object pointer to required type. */
9975 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
9977 /* Convert new value to required type, and dereference it. */
9978 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
9979 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
9982 /* Move memory model to the 3rd position, and end param list. */
9984 params
->truncate (3);
9986 /* Convert return pointer and dereference it for later assignment. */
9987 *new_return
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
9993 /* This will process an __atomic_compare_exchange function call, determine
9994 whether it needs to be mapped to the _N variation, or turned into a lib call.
9995 LOC is the location of the builtin call.
9996 FUNCTION is the DECL that has been invoked;
9997 PARAMS is the argument list for the call. The return value is non-null
9998 TRUE is returned if it is translated into the proper format for a call to the
9999 external library, and NEW_RETURN is set the tree for that function.
10000 FALSE is returned if processing for the _N variation is required. */
10003 resolve_overloaded_atomic_compare_exchange (location_t loc
, tree function
,
10004 vec
<tree
, va_gc
> *params
,
10008 tree I_type
, I_type_ptr
;
10009 int n
= get_atomic_generic_size (loc
, function
, params
);
10011 /* Size of 0 is an error condition. */
10014 *new_return
= error_mark_node
;
10018 /* If not a lock-free size, change to the library generic format. */
10019 if (!atomic_size_supported_p (n
))
10021 /* The library generic format does not have the weak parameter, so
10022 remove it from the param list. Since a parameter has been removed,
10023 we can be sure that there is room for the SIZE_T parameter, meaning
10024 there will not be a recursive rebuilding of the parameter list, so
10025 there is no danger this will be done twice. */
10028 (*params
)[3] = (*params
)[4];
10029 (*params
)[4] = (*params
)[5];
10030 params
->truncate (5);
10032 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10036 /* Otherwise, there is a match, so the call needs to be transformed from:
10037 bool fn(T* mem, T* desired, T* return, weak, success, failure)
10039 bool fn ((In *)mem, (In *)expected, (In) *desired, weak, succ, fail) */
10045 /* Create pointer to appropriate size. */
10046 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10047 I_type_ptr
= build_pointer_type (I_type
);
10049 /* Convert object pointer to required type. */
10050 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10053 /* Convert expected pointer to required type. */
10054 p1
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p1
);
10057 /* Convert desired value to required type, and dereference it. */
10058 p2
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
10059 p2
= build1 (VIEW_CONVERT_EXPR
, I_type
, p2
);
10062 /* The rest of the parameters are fine. NULL means no special return value
10064 *new_return
= NULL
;
10069 /* This will process an __atomic_load function call, determine whether it
10070 needs to be mapped to the _N variation, or turned into a library call.
10071 LOC is the location of the builtin call.
10072 FUNCTION is the DECL that has been invoked;
10073 PARAMS is the argument list for the call. The return value is non-null
10074 TRUE is returned if it is translated into the proper format for a call to the
10075 external library, and NEW_RETURN is set the tree for that function.
10076 FALSE is returned if processing for the _N variation is required, and
10077 NEW_RETURN is set to the return value the result is copied into. */
10080 resolve_overloaded_atomic_load (location_t loc
, tree function
,
10081 vec
<tree
, va_gc
> *params
, tree
*new_return
)
10084 tree I_type
, I_type_ptr
;
10085 int n
= get_atomic_generic_size (loc
, function
, params
);
10087 /* Size of 0 is an error condition. */
10090 *new_return
= error_mark_node
;
10094 /* If not a lock-free size, change to the library generic format. */
10095 if (!atomic_size_supported_p (n
))
10097 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10101 /* Otherwise, there is a match, so the call needs to be transformed from:
10102 void fn(T* mem, T* return, model)
10104 *return = (T) (fn ((In *) mem, model)) */
10110 /* Create pointer to appropriate size. */
10111 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10112 I_type_ptr
= build_pointer_type (I_type
);
10114 /* Convert object pointer to required type. */
10115 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10118 /* Move memory model to the 2nd position, and end param list. */
10120 params
->truncate (2);
10122 /* Convert return pointer and dereference it for later assignment. */
10123 *new_return
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
10129 /* This will process an __atomic_store function call, determine whether it
10130 needs to be mapped to the _N variation, or turned into a library call.
10131 LOC is the location of the builtin call.
10132 FUNCTION is the DECL that has been invoked;
10133 PARAMS is the argument list for the call. The return value is non-null
10134 TRUE is returned if it is translated into the proper format for a call to the
10135 external library, and NEW_RETURN is set the tree for that function.
10136 FALSE is returned if processing for the _N variation is required, and
10137 NEW_RETURN is set to the return value the result is copied into. */
10140 resolve_overloaded_atomic_store (location_t loc
, tree function
,
10141 vec
<tree
, va_gc
> *params
, tree
*new_return
)
10144 tree I_type
, I_type_ptr
;
10145 int n
= get_atomic_generic_size (loc
, function
, params
);
10147 /* Size of 0 is an error condition. */
10150 *new_return
= error_mark_node
;
10154 /* If not a lock-free size, change to the library generic format. */
10155 if (!atomic_size_supported_p (n
))
10157 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10161 /* Otherwise, there is a match, so the call needs to be transformed from:
10162 void fn(T* mem, T* value, model)
10164 fn ((In *) mem, (In) *value, model) */
10169 /* Create pointer to appropriate size. */
10170 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10171 I_type_ptr
= build_pointer_type (I_type
);
10173 /* Convert object pointer to required type. */
10174 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10177 /* Convert new value to required type, and dereference it. */
10178 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
10179 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
10182 /* The memory model is in the right spot already. Return is void. */
10183 *new_return
= NULL_TREE
;
10189 /* Some builtin functions are placeholders for other expressions. This
10190 function should be called immediately after parsing the call expression
10191 before surrounding code has committed to the type of the expression.
10193 LOC is the location of the builtin call.
10195 FUNCTION is the DECL that has been invoked; it is known to be a builtin.
10196 PARAMS is the argument list for the call. The return value is non-null
10197 when expansion is complete, and null if normal processing should
10201 resolve_overloaded_builtin (location_t loc
, tree function
,
10202 vec
<tree
, va_gc
> *params
)
10204 enum built_in_function orig_code
= DECL_FUNCTION_CODE (function
);
10206 /* Is function one of the _FETCH_OP_ or _OP_FETCH_ built-ins?
10207 Those are not valid to call with a pointer to _Bool (or C++ bool)
10208 and so must be rejected. */
10209 bool fetch_op
= true;
10210 bool orig_format
= true;
10211 tree new_return
= NULL_TREE
;
10213 switch (DECL_BUILT_IN_CLASS (function
))
10215 case BUILT_IN_NORMAL
:
10218 if (targetm
.resolve_overloaded_builtin
)
10219 return targetm
.resolve_overloaded_builtin (loc
, function
, params
);
10226 /* Handle BUILT_IN_NORMAL here. */
10229 case BUILT_IN_ATOMIC_EXCHANGE
:
10230 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10231 case BUILT_IN_ATOMIC_LOAD
:
10232 case BUILT_IN_ATOMIC_STORE
:
10234 /* Handle these 4 together so that they can fall through to the next
10235 case if the call is transformed to an _N variant. */
10238 case BUILT_IN_ATOMIC_EXCHANGE
:
10240 if (resolve_overloaded_atomic_exchange (loc
, function
, params
,
10243 /* Change to the _N variant. */
10244 orig_code
= BUILT_IN_ATOMIC_EXCHANGE_N
;
10248 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10250 if (resolve_overloaded_atomic_compare_exchange (loc
, function
,
10254 /* Change to the _N variant. */
10255 orig_code
= BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
;
10258 case BUILT_IN_ATOMIC_LOAD
:
10260 if (resolve_overloaded_atomic_load (loc
, function
, params
,
10263 /* Change to the _N variant. */
10264 orig_code
= BUILT_IN_ATOMIC_LOAD_N
;
10267 case BUILT_IN_ATOMIC_STORE
:
10269 if (resolve_overloaded_atomic_store (loc
, function
, params
,
10272 /* Change to the _N variant. */
10273 orig_code
= BUILT_IN_ATOMIC_STORE_N
;
10277 gcc_unreachable ();
10281 case BUILT_IN_ATOMIC_EXCHANGE_N
:
10282 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
:
10283 case BUILT_IN_ATOMIC_LOAD_N
:
10284 case BUILT_IN_ATOMIC_STORE_N
:
10287 case BUILT_IN_ATOMIC_ADD_FETCH_N
:
10288 case BUILT_IN_ATOMIC_SUB_FETCH_N
:
10289 case BUILT_IN_ATOMIC_AND_FETCH_N
:
10290 case BUILT_IN_ATOMIC_NAND_FETCH_N
:
10291 case BUILT_IN_ATOMIC_XOR_FETCH_N
:
10292 case BUILT_IN_ATOMIC_OR_FETCH_N
:
10293 case BUILT_IN_ATOMIC_FETCH_ADD_N
:
10294 case BUILT_IN_ATOMIC_FETCH_SUB_N
:
10295 case BUILT_IN_ATOMIC_FETCH_AND_N
:
10296 case BUILT_IN_ATOMIC_FETCH_NAND_N
:
10297 case BUILT_IN_ATOMIC_FETCH_XOR_N
:
10298 case BUILT_IN_ATOMIC_FETCH_OR_N
:
10299 orig_format
= false;
10301 case BUILT_IN_SYNC_FETCH_AND_ADD_N
:
10302 case BUILT_IN_SYNC_FETCH_AND_SUB_N
:
10303 case BUILT_IN_SYNC_FETCH_AND_OR_N
:
10304 case BUILT_IN_SYNC_FETCH_AND_AND_N
:
10305 case BUILT_IN_SYNC_FETCH_AND_XOR_N
:
10306 case BUILT_IN_SYNC_FETCH_AND_NAND_N
:
10307 case BUILT_IN_SYNC_ADD_AND_FETCH_N
:
10308 case BUILT_IN_SYNC_SUB_AND_FETCH_N
:
10309 case BUILT_IN_SYNC_OR_AND_FETCH_N
:
10310 case BUILT_IN_SYNC_AND_AND_FETCH_N
:
10311 case BUILT_IN_SYNC_XOR_AND_FETCH_N
:
10312 case BUILT_IN_SYNC_NAND_AND_FETCH_N
:
10313 case BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
:
10314 case BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N
:
10315 case BUILT_IN_SYNC_LOCK_TEST_AND_SET_N
:
10316 case BUILT_IN_SYNC_LOCK_RELEASE_N
:
10318 /* The following are not _FETCH_OPs and must be accepted with
10319 pointers to _Bool (or C++ bool). */
10322 (orig_code
!= BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
10323 && orig_code
!= BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N
10324 && orig_code
!= BUILT_IN_SYNC_LOCK_TEST_AND_SET_N
10325 && orig_code
!= BUILT_IN_SYNC_LOCK_RELEASE_N
);
10327 int n
= sync_resolve_size (function
, params
, fetch_op
);
10328 tree new_function
, first_param
, result
;
10329 enum built_in_function fncode
;
10332 return error_mark_node
;
10334 fncode
= (enum built_in_function
)((int)orig_code
+ exact_log2 (n
) + 1);
10335 new_function
= builtin_decl_explicit (fncode
);
10336 if (!sync_resolve_params (loc
, function
, new_function
, params
,
10338 return error_mark_node
;
10340 first_param
= (*params
)[0];
10341 result
= build_function_call_vec (loc
, vNULL
, new_function
, params
,
10343 if (result
== error_mark_node
)
10345 if (orig_code
!= BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
10346 && orig_code
!= BUILT_IN_SYNC_LOCK_RELEASE_N
10347 && orig_code
!= BUILT_IN_ATOMIC_STORE_N
10348 && orig_code
!= BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
)
10349 result
= sync_resolve_return (first_param
, result
, orig_format
);
10352 /* Prevent -Wunused-value warning. */
10353 TREE_USED (result
) = true;
10355 /* If new_return is set, assign function to that expr and cast the
10356 result to void since the generic interface returned void. */
10359 /* Cast function result from I{1,2,4,8,16} to the required type. */
10360 result
= build1 (VIEW_CONVERT_EXPR
, TREE_TYPE (new_return
), result
);
10361 result
= build2 (MODIFY_EXPR
, TREE_TYPE (new_return
), new_return
,
10363 TREE_SIDE_EFFECTS (result
) = 1;
10364 protected_set_expr_location (result
, loc
);
10365 result
= convert (void_type_node
, result
);
10375 /* vector_types_compatible_elements_p is used in type checks of vectors
10376 values used as operands of binary operators. Where it returns true, and
10377 the other checks of the caller succeed (being vector types in he first
10378 place, and matching number of elements), we can just treat the types
10379 as essentially the same.
10380 Contrast with vector_targets_convertible_p, which is used for vector
10381 pointer types, and vector_types_convertible_p, which will allow
10382 language-specific matches under the control of flag_lax_vector_conversions,
10383 and might still require a conversion. */
10384 /* True if vector types T1 and T2 can be inputs to the same binary
10385 operator without conversion.
10386 We don't check the overall vector size here because some of our callers
10387 want to give different error messages when the vectors are compatible
10388 except for the element count. */
10391 vector_types_compatible_elements_p (tree t1
, tree t2
)
10393 bool opaque
= TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
);
10394 t1
= TREE_TYPE (t1
);
10395 t2
= TREE_TYPE (t2
);
10397 enum tree_code c1
= TREE_CODE (t1
), c2
= TREE_CODE (t2
);
10399 gcc_assert ((c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
|| c1
== FIXED_POINT_TYPE
)
10400 && (c2
== INTEGER_TYPE
|| c2
== REAL_TYPE
10401 || c2
== FIXED_POINT_TYPE
));
10403 t1
= c_common_signed_type (t1
);
10404 t2
= c_common_signed_type (t2
);
10405 /* Equality works here because c_common_signed_type uses
10406 TYPE_MAIN_VARIANT. */
10409 if (opaque
&& c1
== c2
10410 && (c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
)
10411 && TYPE_PRECISION (t1
) == TYPE_PRECISION (t2
))
10416 /* Check for missing format attributes on function pointers. LTYPE is
10417 the new type or left-hand side type. RTYPE is the old type or
10418 right-hand side type. Returns TRUE if LTYPE is missing the desired
10422 check_missing_format_attribute (tree ltype
, tree rtype
)
10424 tree
const ttr
= TREE_TYPE (rtype
), ttl
= TREE_TYPE (ltype
);
10427 for (ra
= TYPE_ATTRIBUTES (ttr
); ra
; ra
= TREE_CHAIN (ra
))
10428 if (is_attribute_p ("format", TREE_PURPOSE (ra
)))
10433 for (la
= TYPE_ATTRIBUTES (ttl
); la
; la
= TREE_CHAIN (la
))
10434 if (is_attribute_p ("format", TREE_PURPOSE (la
)))
10442 /* Setup a TYPE_DECL node as a typedef representation.
10444 X is a TYPE_DECL for a typedef statement. Create a brand new
10445 ..._TYPE node (which will be just a variant of the existing
10446 ..._TYPE node with identical properties) and then install X
10447 as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
10449 The whole point here is to end up with a situation where each
10450 and every ..._TYPE node the compiler creates will be uniquely
10451 associated with AT MOST one node representing a typedef name.
10452 This way, even though the compiler substitutes corresponding
10453 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
10454 early on, later parts of the compiler can always do the reverse
10455 translation and get back the corresponding typedef name. For
10458 typedef struct S MY_TYPE;
10461 Later parts of the compiler might only know that `object' was of
10462 type `struct S' if it were not for code just below. With this
10463 code however, later parts of the compiler see something like:
10465 struct S' == struct S
10466 typedef struct S' MY_TYPE;
10469 And they can then deduce (from the node for type struct S') that
10470 the original object declaration was:
10474 Being able to do this is important for proper support of protoize,
10475 and also for generating precise symbolic debugging information
10476 which takes full account of the programmer's (typedef) vocabulary.
10478 Obviously, we don't want to generate a duplicate ..._TYPE node if
10479 the TYPE_DECL node that we are now processing really represents a
10480 standard built-in type. */
10483 set_underlying_type (tree x
)
10485 if (x
== error_mark_node
)
10487 if (DECL_IS_BUILTIN (x
) && TREE_CODE (TREE_TYPE (x
)) != ARRAY_TYPE
)
10489 if (TYPE_NAME (TREE_TYPE (x
)) == 0)
10490 TYPE_NAME (TREE_TYPE (x
)) = x
;
10492 else if (TREE_TYPE (x
) != error_mark_node
10493 && DECL_ORIGINAL_TYPE (x
) == NULL_TREE
)
10495 tree tt
= TREE_TYPE (x
);
10496 DECL_ORIGINAL_TYPE (x
) = tt
;
10497 tt
= build_variant_type_copy (tt
);
10498 TYPE_STUB_DECL (tt
) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x
));
10499 TYPE_NAME (tt
) = x
;
10500 TREE_USED (tt
) = TREE_USED (x
);
10501 TREE_TYPE (x
) = tt
;
10505 /* Record the types used by the current global variable declaration
10506 being parsed, so that we can decide later to emit their debug info.
10507 Those types are in types_used_by_cur_var_decl, and we are going to
10508 store them in the types_used_by_vars_hash hash table.
10509 DECL is the declaration of the global variable that has been parsed. */
10512 record_types_used_by_current_var_decl (tree decl
)
10514 gcc_assert (decl
&& DECL_P (decl
) && TREE_STATIC (decl
));
10516 while (types_used_by_cur_var_decl
&& !types_used_by_cur_var_decl
->is_empty ())
10518 tree type
= types_used_by_cur_var_decl
->pop ();
10519 types_used_by_var_decl_insert (type
, decl
);
10523 /* The C and C++ parsers both use vectors to hold function arguments.
10524 For efficiency, we keep a cache of unused vectors. This is the
10527 typedef vec
<tree
, va_gc
> *tree_gc_vec
;
10528 static GTY((deletable
)) vec
<tree_gc_vec
, va_gc
> *tree_vector_cache
;
10530 /* Return a new vector from the cache. If the cache is empty,
10531 allocate a new vector. These vectors are GC'ed, so it is OK if the
10532 pointer is not released.. */
10535 make_tree_vector (void)
10537 if (tree_vector_cache
&& !tree_vector_cache
->is_empty ())
10538 return tree_vector_cache
->pop ();
10541 /* Passing 0 to vec::alloc returns NULL, and our callers require
10542 that we always return a non-NULL value. The vector code uses
10543 4 when growing a NULL vector, so we do too. */
10544 vec
<tree
, va_gc
> *v
;
10550 /* Release a vector of trees back to the cache. */
10553 release_tree_vector (vec
<tree
, va_gc
> *vec
)
10558 vec_safe_push (tree_vector_cache
, vec
);
10562 /* Get a new tree vector holding a single tree. */
10565 make_tree_vector_single (tree t
)
10567 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
10568 ret
->quick_push (t
);
10572 /* Get a new tree vector of the TREE_VALUEs of a TREE_LIST chain. */
10575 make_tree_vector_from_list (tree list
)
10577 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
10578 for (; list
; list
= TREE_CHAIN (list
))
10579 vec_safe_push (ret
, TREE_VALUE (list
));
10583 /* Get a new tree vector of the values of a CONSTRUCTOR. */
10586 make_tree_vector_from_ctor (tree ctor
)
10588 vec
<tree
,va_gc
> *ret
= make_tree_vector ();
10589 vec_safe_reserve (ret
, CONSTRUCTOR_NELTS (ctor
));
10590 for (unsigned i
= 0; i
< CONSTRUCTOR_NELTS (ctor
); ++i
)
10591 ret
->quick_push (CONSTRUCTOR_ELT (ctor
, i
)->value
);
10595 /* Get a new tree vector which is a copy of an existing one. */
10598 make_tree_vector_copy (const vec
<tree
, va_gc
> *orig
)
10600 vec
<tree
, va_gc
> *ret
;
10604 ret
= make_tree_vector ();
10605 vec_safe_reserve (ret
, vec_safe_length (orig
));
10606 FOR_EACH_VEC_SAFE_ELT (orig
, ix
, t
)
10607 ret
->quick_push (t
);
10611 /* Return true if KEYWORD starts a type specifier. */
10614 keyword_begins_type_specifier (enum rid keyword
)
10618 case RID_AUTO_TYPE
:
10628 CASE_RID_FLOATN_NX
:
10631 case RID_DFLOAT128
:
10647 if (keyword
>= RID_FIRST_INT_N
10648 && keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
10649 && int_n_enabled_p
[keyword
-RID_FIRST_INT_N
])
10655 /* Return true if KEYWORD names a type qualifier. */
10658 keyword_is_type_qualifier (enum rid keyword
)
10672 /* Return true if KEYWORD names a storage class specifier.
10674 RID_TYPEDEF is not included in this list despite `typedef' being
10675 listed in C99 6.7.1.1. 6.7.1.3 indicates that `typedef' is listed as
10676 such for syntactic convenience only. */
10679 keyword_is_storage_class_specifier (enum rid keyword
)
10695 /* Return true if KEYWORD names a function-specifier [dcl.fct.spec]. */
10698 keyword_is_function_specifier (enum rid keyword
)
10712 /* Return true if KEYWORD names a decl-specifier [dcl.spec] or a
10713 declaration-specifier (C99 6.7). */
10716 keyword_is_decl_specifier (enum rid keyword
)
10718 if (keyword_is_storage_class_specifier (keyword
)
10719 || keyword_is_type_qualifier (keyword
)
10720 || keyword_is_function_specifier (keyword
))
10727 case RID_CONSTEXPR
:
10734 /* Initialize language-specific-bits of tree_contains_struct. */
10737 c_common_init_ts (void)
10739 MARK_TS_TYPED (C_MAYBE_CONST_EXPR
);
10740 MARK_TS_TYPED (EXCESS_PRECISION_EXPR
);
10741 MARK_TS_TYPED (ARRAY_NOTATION_REF
);
10744 /* Build a user-defined numeric literal out of an integer constant type VALUE
10745 with identifier SUFFIX. */
10748 build_userdef_literal (tree suffix_id
, tree value
,
10749 enum overflow_type overflow
, tree num_string
)
10751 tree literal
= make_node (USERDEF_LITERAL
);
10752 USERDEF_LITERAL_SUFFIX_ID (literal
) = suffix_id
;
10753 USERDEF_LITERAL_VALUE (literal
) = value
;
10754 USERDEF_LITERAL_OVERFLOW (literal
) = overflow
;
10755 USERDEF_LITERAL_NUM_STRING (literal
) = num_string
;
10759 /* For vector[index], convert the vector to an array of the underlying type.
10760 Return true if the resulting ARRAY_REF should not be an lvalue. */
10763 convert_vector_to_array_for_subscript (location_t loc
,
10764 tree
*vecp
, tree index
)
10767 if (VECTOR_TYPE_P (TREE_TYPE (*vecp
)))
10769 tree type
= TREE_TYPE (*vecp
);
10771 ret
= !lvalue_p (*vecp
);
10773 if (TREE_CODE (index
) == INTEGER_CST
)
10774 if (!tree_fits_uhwi_p (index
)
10775 || tree_to_uhwi (index
) >= TYPE_VECTOR_SUBPARTS (type
))
10776 warning_at (loc
, OPT_Warray_bounds
, "index value is out of bound");
10778 /* We are building an ARRAY_REF so mark the vector as addressable
10779 to not run into the gimplifiers premature setting of DECL_GIMPLE_REG_P
10780 for function parameters. */
10781 c_common_mark_addressable_vec (*vecp
);
10783 *vecp
= build1 (VIEW_CONVERT_EXPR
,
10784 build_array_type_nelts (TREE_TYPE (type
),
10785 TYPE_VECTOR_SUBPARTS (type
)),
10791 /* Determine which of the operands, if any, is a scalar that needs to be
10792 converted to a vector, for the range of operations. */
10794 scalar_to_vector (location_t loc
, enum tree_code code
, tree op0
, tree op1
,
10797 tree type0
= TREE_TYPE (op0
);
10798 tree type1
= TREE_TYPE (op1
);
10799 bool integer_only_op
= false;
10800 enum stv_conv ret
= stv_firstarg
;
10802 gcc_assert (VECTOR_TYPE_P (type0
) || VECTOR_TYPE_P (type1
));
10805 /* Most GENERIC binary expressions require homogeneous arguments.
10806 LSHIFT_EXPR and RSHIFT_EXPR are exceptions and accept a first
10807 argument that is a vector and a second one that is a scalar, so
10808 we never return stv_secondarg for them. */
10811 if (TREE_CODE (type0
) == INTEGER_TYPE
10812 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
10814 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
10817 error_at (loc
, "conversion of scalar %qT to vector %qT "
10818 "involves truncation", type0
, type1
);
10822 return stv_firstarg
;
10829 integer_only_op
= true;
10832 case VEC_COND_EXPR
:
10837 case TRUNC_DIV_EXPR
:
10838 case CEIL_DIV_EXPR
:
10839 case FLOOR_DIV_EXPR
:
10840 case ROUND_DIV_EXPR
:
10841 case EXACT_DIV_EXPR
:
10842 case TRUNC_MOD_EXPR
:
10843 case FLOOR_MOD_EXPR
:
10851 /* What about UNLT_EXPR? */
10852 if (VECTOR_TYPE_P (type0
))
10854 ret
= stv_secondarg
;
10855 std::swap (type0
, type1
);
10856 std::swap (op0
, op1
);
10859 if (TREE_CODE (type0
) == INTEGER_TYPE
10860 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
10862 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
10865 error_at (loc
, "conversion of scalar %qT to vector %qT "
10866 "involves truncation", type0
, type1
);
10871 else if (!integer_only_op
10872 /* Allow integer --> real conversion if safe. */
10873 && (TREE_CODE (type0
) == REAL_TYPE
10874 || TREE_CODE (type0
) == INTEGER_TYPE
)
10875 && SCALAR_FLOAT_TYPE_P (TREE_TYPE (type1
)))
10877 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
10880 error_at (loc
, "conversion of scalar %qT to vector %qT "
10881 "involves truncation", type0
, type1
);
10890 return stv_nothing
;
10893 /* Return the alignment of std::max_align_t.
10895 [support.types.layout] The type max_align_t is a POD type whose alignment
10896 requirement is at least as great as that of every scalar type, and whose
10897 alignment requirement is supported in every context. */
10900 max_align_t_align ()
10902 unsigned int max_align
= MAX (TYPE_ALIGN (long_long_integer_type_node
),
10903 TYPE_ALIGN (long_double_type_node
));
10904 if (float128_type_node
!= NULL_TREE
)
10905 max_align
= MAX (max_align
, TYPE_ALIGN (float128_type_node
));
10909 /* Return true iff ALIGN is an integral constant that is a fundamental
10910 alignment, as defined by [basic.align] in the c++-11
10915 [A fundamental alignment is represented by an alignment less than or
10916 equal to the greatest alignment supported by the implementation
10917 in all contexts, which is equal to alignof(max_align_t)]. */
10920 cxx_fundamental_alignment_p (unsigned align
)
10922 return (align
<= max_align_t_align ());
10925 /* Return true if T is a pointer to a zero-sized aggregate. */
10928 pointer_to_zero_sized_aggr_p (tree t
)
10930 if (!POINTER_TYPE_P (t
))
10933 return (TYPE_SIZE (t
) && integer_zerop (TYPE_SIZE (t
)));
10936 /* For an EXPR of a FUNCTION_TYPE that references a GCC built-in function
10937 with no library fallback or for an ADDR_EXPR whose operand is such type
10938 issues an error pointing to the location LOC.
10939 Returns true when the expression has been diagnosed and false
10943 reject_gcc_builtin (const_tree expr
, location_t loc
/* = UNKNOWN_LOCATION */)
10945 if (TREE_CODE (expr
) == ADDR_EXPR
)
10946 expr
= TREE_OPERAND (expr
, 0);
10948 if (TREE_TYPE (expr
)
10949 && TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
10950 && TREE_CODE (expr
) == FUNCTION_DECL
10951 /* The intersection of DECL_BUILT_IN and DECL_IS_BUILTIN avoids
10952 false positives for user-declared built-ins such as abs or
10953 strlen, and for C++ operators new and delete.
10954 The c_decl_implicit() test avoids false positives for implicitly
10955 declared built-ins with library fallbacks (such as abs). */
10956 && DECL_BUILT_IN (expr
)
10957 && DECL_IS_BUILTIN (expr
)
10958 && !c_decl_implicit (expr
)
10959 && !DECL_ASSEMBLER_NAME_SET_P (expr
))
10961 if (loc
== UNKNOWN_LOCATION
)
10962 loc
= EXPR_LOC_OR_LOC (expr
, input_location
);
10964 /* Reject arguments that are built-in functions with
10965 no library fallback. */
10966 error_at (loc
, "built-in function %qE must be directly called", expr
);
10974 /* Check if array size calculations overflow or if the array covers more
10975 than half of the address space. Return true if the size of the array
10976 is valid, false otherwise. TYPE is the type of the array and NAME is
10977 the name of the array, or NULL_TREE for unnamed arrays. */
10980 valid_array_size_p (location_t loc
, tree type
, tree name
)
10982 if (type
!= error_mark_node
10983 && COMPLETE_TYPE_P (type
)
10984 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
10985 && !valid_constant_size_p (TYPE_SIZE_UNIT (type
)))
10988 error_at (loc
, "size of array %qE is too large", name
);
10990 error_at (loc
, "size of unnamed array is too large");
10996 /* Read SOURCE_DATE_EPOCH from environment to have a deterministic
10997 timestamp to replace embedded current dates to get reproducible
10998 results. Returns -1 if SOURCE_DATE_EPOCH is not defined. */
11001 cb_get_source_date_epoch (cpp_reader
*pfile ATTRIBUTE_UNUSED
)
11003 char *source_date_epoch
;
11007 source_date_epoch
= getenv ("SOURCE_DATE_EPOCH");
11008 if (!source_date_epoch
)
11009 return (time_t) -1;
11012 #if defined(INT64_T_IS_LONG)
11013 epoch
= strtol (source_date_epoch
, &endptr
, 10);
11015 epoch
= strtoll (source_date_epoch
, &endptr
, 10);
11017 if (errno
!= 0 || endptr
== source_date_epoch
|| *endptr
!= '\0'
11018 || epoch
< 0 || epoch
> MAX_SOURCE_DATE_EPOCH
)
11020 error_at (input_location
, "environment variable SOURCE_DATE_EPOCH must "
11021 "expand to a non-negative integer less than or equal to %wd",
11022 MAX_SOURCE_DATE_EPOCH
);
11023 return (time_t) -1;
11026 return (time_t) epoch
;
11029 /* Callback for libcpp for offering spelling suggestions for misspelled
11030 directives. GOAL is an unrecognized string; CANDIDATES is a
11031 NULL-terminated array of candidate strings. Return the closest
11032 match to GOAL within CANDIDATES, or NULL if none are good
11036 cb_get_suggestion (cpp_reader
*, const char *goal
,
11037 const char *const *candidates
)
11039 best_match
<const char *, const char *> bm (goal
);
11040 while (*candidates
)
11041 bm
.consider (*candidates
++);
11042 return bm
.get_best_meaningful_candidate ();
11045 #include "gt-c-family-c-common.h"