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_call_with_static_chain",
467 RID_BUILTIN_CALL_WITH_STATIC_CHAIN
, D_CONLY
},
468 { "__builtin_choose_expr", RID_CHOOSE_EXPR
, D_CONLY
},
469 { "__builtin_complex", RID_BUILTIN_COMPLEX
, D_CONLY
},
470 { "__builtin_shuffle", RID_BUILTIN_SHUFFLE
, 0 },
471 { "__builtin_offsetof", RID_OFFSETOF
, 0 },
472 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P
, D_CONLY
},
473 { "__builtin_va_arg", RID_VA_ARG
, 0 },
474 { "__complex", RID_COMPLEX
, 0 },
475 { "__complex__", RID_COMPLEX
, 0 },
476 { "__const", RID_CONST
, 0 },
477 { "__const__", RID_CONST
, 0 },
478 { "__decltype", RID_DECLTYPE
, D_CXXONLY
},
479 { "__direct_bases", RID_DIRECT_BASES
, D_CXXONLY
},
480 { "__extension__", RID_EXTENSION
, 0 },
481 { "__func__", RID_C99_FUNCTION_NAME
, 0 },
482 { "__has_nothrow_assign", RID_HAS_NOTHROW_ASSIGN
, D_CXXONLY
},
483 { "__has_nothrow_constructor", RID_HAS_NOTHROW_CONSTRUCTOR
, D_CXXONLY
},
484 { "__has_nothrow_copy", RID_HAS_NOTHROW_COPY
, D_CXXONLY
},
485 { "__has_trivial_assign", RID_HAS_TRIVIAL_ASSIGN
, D_CXXONLY
},
486 { "__has_trivial_constructor", RID_HAS_TRIVIAL_CONSTRUCTOR
, D_CXXONLY
},
487 { "__has_trivial_copy", RID_HAS_TRIVIAL_COPY
, D_CXXONLY
},
488 { "__has_trivial_destructor", RID_HAS_TRIVIAL_DESTRUCTOR
, D_CXXONLY
},
489 { "__has_unique_object_representations", RID_HAS_UNIQUE_OBJ_REPRESENTATIONS
,
491 { "__has_virtual_destructor", RID_HAS_VIRTUAL_DESTRUCTOR
, D_CXXONLY
},
492 { "__imag", RID_IMAGPART
, 0 },
493 { "__imag__", RID_IMAGPART
, 0 },
494 { "__inline", RID_INLINE
, 0 },
495 { "__inline__", RID_INLINE
, 0 },
496 { "__is_abstract", RID_IS_ABSTRACT
, D_CXXONLY
},
497 { "__is_base_of", RID_IS_BASE_OF
, D_CXXONLY
},
498 { "__is_class", RID_IS_CLASS
, D_CXXONLY
},
499 { "__is_empty", RID_IS_EMPTY
, D_CXXONLY
},
500 { "__is_enum", RID_IS_ENUM
, D_CXXONLY
},
501 { "__is_final", RID_IS_FINAL
, D_CXXONLY
},
502 { "__is_literal_type", RID_IS_LITERAL_TYPE
, D_CXXONLY
},
503 { "__is_pod", RID_IS_POD
, D_CXXONLY
},
504 { "__is_polymorphic", RID_IS_POLYMORPHIC
, D_CXXONLY
},
505 { "__is_same_as", RID_IS_SAME_AS
, D_CXXONLY
},
506 { "__is_standard_layout", RID_IS_STD_LAYOUT
, D_CXXONLY
},
507 { "__is_trivial", RID_IS_TRIVIAL
, D_CXXONLY
},
508 { "__is_trivially_assignable", RID_IS_TRIVIALLY_ASSIGNABLE
, D_CXXONLY
},
509 { "__is_trivially_constructible", RID_IS_TRIVIALLY_CONSTRUCTIBLE
, D_CXXONLY
},
510 { "__is_trivially_copyable", RID_IS_TRIVIALLY_COPYABLE
, D_CXXONLY
},
511 { "__is_union", RID_IS_UNION
, D_CXXONLY
},
512 { "__label__", RID_LABEL
, 0 },
513 { "__null", RID_NULL
, 0 },
514 { "__real", RID_REALPART
, 0 },
515 { "__real__", RID_REALPART
, 0 },
516 { "__restrict", RID_RESTRICT
, 0 },
517 { "__restrict__", RID_RESTRICT
, 0 },
518 { "__signed", RID_SIGNED
, 0 },
519 { "__signed__", RID_SIGNED
, 0 },
520 { "__thread", RID_THREAD
, 0 },
521 { "__transaction_atomic", RID_TRANSACTION_ATOMIC
, 0 },
522 { "__transaction_relaxed", RID_TRANSACTION_RELAXED
, 0 },
523 { "__transaction_cancel", RID_TRANSACTION_CANCEL
, 0 },
524 { "__typeof", RID_TYPEOF
, 0 },
525 { "__typeof__", RID_TYPEOF
, 0 },
526 { "__underlying_type", RID_UNDERLYING_TYPE
, D_CXXONLY
},
527 { "__volatile", RID_VOLATILE
, 0 },
528 { "__volatile__", RID_VOLATILE
, 0 },
529 { "alignas", RID_ALIGNAS
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
530 { "alignof", RID_ALIGNOF
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
531 { "asm", RID_ASM
, D_ASM
},
532 { "auto", RID_AUTO
, 0 },
533 { "bool", RID_BOOL
, D_CXXONLY
| D_CXXWARN
},
534 { "break", RID_BREAK
, 0 },
535 { "case", RID_CASE
, 0 },
536 { "catch", RID_CATCH
, D_CXX_OBJC
| D_CXXWARN
},
537 { "char", RID_CHAR
, 0 },
538 { "char16_t", RID_CHAR16
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
539 { "char32_t", RID_CHAR32
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
540 { "class", RID_CLASS
, D_CXX_OBJC
| D_CXXWARN
},
541 { "const", RID_CONST
, 0 },
542 { "constexpr", RID_CONSTEXPR
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
543 { "const_cast", RID_CONSTCAST
, D_CXXONLY
| D_CXXWARN
},
544 { "continue", RID_CONTINUE
, 0 },
545 { "decltype", RID_DECLTYPE
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
546 { "default", RID_DEFAULT
, 0 },
547 { "delete", RID_DELETE
, D_CXXONLY
| D_CXXWARN
},
549 { "double", RID_DOUBLE
, 0 },
550 { "dynamic_cast", RID_DYNCAST
, D_CXXONLY
| D_CXXWARN
},
551 { "else", RID_ELSE
, 0 },
552 { "enum", RID_ENUM
, 0 },
553 { "explicit", RID_EXPLICIT
, D_CXXONLY
| D_CXXWARN
},
554 { "export", RID_EXPORT
, D_CXXONLY
| D_CXXWARN
},
555 { "extern", RID_EXTERN
, 0 },
556 { "false", RID_FALSE
, D_CXXONLY
| D_CXXWARN
},
557 { "float", RID_FLOAT
, 0 },
558 { "for", RID_FOR
, 0 },
559 { "friend", RID_FRIEND
, D_CXXONLY
| D_CXXWARN
},
560 { "goto", RID_GOTO
, 0 },
562 { "inline", RID_INLINE
, D_EXT89
},
563 { "int", RID_INT
, 0 },
564 { "long", RID_LONG
, 0 },
565 { "mutable", RID_MUTABLE
, D_CXXONLY
| D_CXXWARN
},
566 { "namespace", RID_NAMESPACE
, D_CXXONLY
| D_CXXWARN
},
567 { "new", RID_NEW
, D_CXXONLY
| D_CXXWARN
},
568 { "noexcept", RID_NOEXCEPT
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
569 { "nullptr", RID_NULLPTR
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
570 { "operator", RID_OPERATOR
, D_CXXONLY
| D_CXXWARN
},
571 { "private", RID_PRIVATE
, D_CXX_OBJC
| D_CXXWARN
},
572 { "protected", RID_PROTECTED
, D_CXX_OBJC
| D_CXXWARN
},
573 { "public", RID_PUBLIC
, D_CXX_OBJC
| D_CXXWARN
},
574 { "register", RID_REGISTER
, 0 },
575 { "reinterpret_cast", RID_REINTCAST
, D_CXXONLY
| D_CXXWARN
},
576 { "restrict", RID_RESTRICT
, D_CONLY
| D_C99
},
577 { "return", RID_RETURN
, 0 },
578 { "short", RID_SHORT
, 0 },
579 { "signed", RID_SIGNED
, 0 },
580 { "sizeof", RID_SIZEOF
, 0 },
581 { "static", RID_STATIC
, 0 },
582 { "static_assert", RID_STATIC_ASSERT
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
583 { "static_cast", RID_STATCAST
, D_CXXONLY
| D_CXXWARN
},
584 { "struct", RID_STRUCT
, 0 },
585 { "switch", RID_SWITCH
, 0 },
586 { "template", RID_TEMPLATE
, D_CXXONLY
| D_CXXWARN
},
587 { "this", RID_THIS
, D_CXXONLY
| D_CXXWARN
},
588 { "thread_local", RID_THREAD
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
589 { "throw", RID_THROW
, D_CXX_OBJC
| D_CXXWARN
},
590 { "true", RID_TRUE
, D_CXXONLY
| D_CXXWARN
},
591 { "try", RID_TRY
, D_CXX_OBJC
| D_CXXWARN
},
592 { "typedef", RID_TYPEDEF
, 0 },
593 { "typename", RID_TYPENAME
, D_CXXONLY
| D_CXXWARN
},
594 { "typeid", RID_TYPEID
, D_CXXONLY
| D_CXXWARN
},
595 { "typeof", RID_TYPEOF
, D_ASM
| D_EXT
},
596 { "union", RID_UNION
, 0 },
597 { "unsigned", RID_UNSIGNED
, 0 },
598 { "using", RID_USING
, D_CXXONLY
| D_CXXWARN
},
599 { "virtual", RID_VIRTUAL
, D_CXXONLY
| D_CXXWARN
},
600 { "void", RID_VOID
, 0 },
601 { "volatile", RID_VOLATILE
, 0 },
602 { "wchar_t", RID_WCHAR
, D_CXXONLY
},
603 { "while", RID_WHILE
, 0 },
605 /* C++ transactional memory. */
606 { "synchronized", RID_SYNCHRONIZED
, D_CXX_OBJC
| D_TRANSMEM
},
607 { "atomic_noexcept", RID_ATOMIC_NOEXCEPT
, D_CXXONLY
| D_TRANSMEM
},
608 { "atomic_cancel", RID_ATOMIC_CANCEL
, D_CXXONLY
| D_TRANSMEM
},
609 { "atomic_commit", RID_TRANSACTION_ATOMIC
, D_CXXONLY
| D_TRANSMEM
},
611 /* Concepts-related keywords */
612 { "concept", RID_CONCEPT
, D_CXX_CONCEPTS_FLAGS
| D_CXXWARN
},
613 { "requires", RID_REQUIRES
, D_CXX_CONCEPTS_FLAGS
| D_CXXWARN
},
615 /* These Objective-C keywords are recognized only immediately after
617 { "compatibility_alias", RID_AT_ALIAS
, D_OBJC
},
618 { "defs", RID_AT_DEFS
, D_OBJC
},
619 { "encode", RID_AT_ENCODE
, D_OBJC
},
620 { "end", RID_AT_END
, D_OBJC
},
621 { "implementation", RID_AT_IMPLEMENTATION
, D_OBJC
},
622 { "interface", RID_AT_INTERFACE
, D_OBJC
},
623 { "protocol", RID_AT_PROTOCOL
, D_OBJC
},
624 { "selector", RID_AT_SELECTOR
, D_OBJC
},
625 { "finally", RID_AT_FINALLY
, D_OBJC
},
626 { "optional", RID_AT_OPTIONAL
, D_OBJC
},
627 { "required", RID_AT_REQUIRED
, D_OBJC
},
628 { "property", RID_AT_PROPERTY
, D_OBJC
},
629 { "package", RID_AT_PACKAGE
, D_OBJC
},
630 { "synthesize", RID_AT_SYNTHESIZE
, D_OBJC
},
631 { "dynamic", RID_AT_DYNAMIC
, D_OBJC
},
632 /* These are recognized only in protocol-qualifier context
634 { "bycopy", RID_BYCOPY
, D_OBJC
},
635 { "byref", RID_BYREF
, D_OBJC
},
636 { "in", RID_IN
, D_OBJC
},
637 { "inout", RID_INOUT
, D_OBJC
},
638 { "oneway", RID_ONEWAY
, D_OBJC
},
639 { "out", RID_OUT
, D_OBJC
},
640 /* These are recognized inside a property attribute list */
641 { "assign", RID_ASSIGN
, D_OBJC
},
642 { "copy", RID_COPY
, D_OBJC
},
643 { "getter", RID_GETTER
, D_OBJC
},
644 { "nonatomic", RID_NONATOMIC
, D_OBJC
},
645 { "readonly", RID_READONLY
, D_OBJC
},
646 { "readwrite", RID_READWRITE
, D_OBJC
},
647 { "retain", RID_RETAIN
, D_OBJC
},
648 { "setter", RID_SETTER
, D_OBJC
},
651 const unsigned int num_c_common_reswords
=
652 sizeof c_common_reswords
/ sizeof (struct c_common_resword
);
654 /* Table of machine-independent attributes common to all C-like languages.
656 All attributes referencing arguments should be additionally processed
657 in chkp_copy_function_type_adding_bounds for correct instrumentation
658 by Pointer Bounds Checker.
659 Current list of processed common attributes: nonnull. */
660 const struct attribute_spec c_common_attribute_table
[] =
662 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
663 affects_type_identity } */
664 { "packed", 0, 0, false, false, false,
665 handle_packed_attribute
, false},
666 { "nocommon", 0, 0, true, false, false,
667 handle_nocommon_attribute
, false},
668 { "common", 0, 0, true, false, false,
669 handle_common_attribute
, false },
670 /* FIXME: logically, noreturn attributes should be listed as
671 "false, true, true" and apply to function types. But implementing this
672 would require all the places in the compiler that use TREE_THIS_VOLATILE
673 on a decl to identify non-returning functions to be located and fixed
674 to check the function type instead. */
675 { "noreturn", 0, 0, true, false, false,
676 handle_noreturn_attribute
, false },
677 { "volatile", 0, 0, true, false, false,
678 handle_noreturn_attribute
, false },
679 { "stack_protect", 0, 0, true, false, false,
680 handle_stack_protect_attribute
, false },
681 { "noinline", 0, 0, true, false, false,
682 handle_noinline_attribute
, false },
683 { "noclone", 0, 0, true, false, false,
684 handle_noclone_attribute
, false },
685 { "no_icf", 0, 0, true, false, false,
686 handle_noicf_attribute
, false },
687 { "leaf", 0, 0, true, false, false,
688 handle_leaf_attribute
, false },
689 { "always_inline", 0, 0, true, false, false,
690 handle_always_inline_attribute
, false },
691 { "gnu_inline", 0, 0, true, false, false,
692 handle_gnu_inline_attribute
, false },
693 { "artificial", 0, 0, true, false, false,
694 handle_artificial_attribute
, false },
695 { "flatten", 0, 0, true, false, false,
696 handle_flatten_attribute
, false },
697 { "used", 0, 0, true, false, false,
698 handle_used_attribute
, false },
699 { "unused", 0, 0, false, false, false,
700 handle_unused_attribute
, false },
701 { "externally_visible", 0, 0, true, false, false,
702 handle_externally_visible_attribute
, false },
703 { "no_reorder", 0, 0, true, false, false,
704 handle_no_reorder_attribute
, false },
705 /* The same comments as for noreturn attributes apply to const ones. */
706 { "const", 0, 0, true, false, false,
707 handle_const_attribute
, false },
708 { "scalar_storage_order", 1, 1, false, false, false,
709 handle_scalar_storage_order_attribute
, false },
710 { "transparent_union", 0, 0, false, false, false,
711 handle_transparent_union_attribute
, false },
712 { "constructor", 0, 1, true, false, false,
713 handle_constructor_attribute
, false },
714 { "destructor", 0, 1, true, false, false,
715 handle_destructor_attribute
, false },
716 { "mode", 1, 1, false, true, false,
717 handle_mode_attribute
, false },
718 { "section", 1, 1, true, false, false,
719 handle_section_attribute
, false },
720 { "aligned", 0, 1, false, false, false,
721 handle_aligned_attribute
, false },
722 { "weak", 0, 0, true, false, false,
723 handle_weak_attribute
, false },
724 { "noplt", 0, 0, true, false, false,
725 handle_noplt_attribute
, false },
726 { "ifunc", 1, 1, true, false, false,
727 handle_ifunc_attribute
, false },
728 { "alias", 1, 1, true, false, false,
729 handle_alias_attribute
, false },
730 { "weakref", 0, 1, true, false, false,
731 handle_weakref_attribute
, false },
732 { "no_instrument_function", 0, 0, true, false, false,
733 handle_no_instrument_function_attribute
,
735 { "no_profile_instrument_function", 0, 0, true, false, false,
736 handle_no_profile_instrument_function_attribute
,
738 { "malloc", 0, 0, true, false, false,
739 handle_malloc_attribute
, false },
740 { "returns_twice", 0, 0, true, false, false,
741 handle_returns_twice_attribute
, false },
742 { "no_stack_limit", 0, 0, true, false, false,
743 handle_no_limit_stack_attribute
, false },
744 { "pure", 0, 0, true, false, false,
745 handle_pure_attribute
, false },
746 { "transaction_callable", 0, 0, false, true, false,
747 handle_tm_attribute
, false },
748 { "transaction_unsafe", 0, 0, false, true, false,
749 handle_tm_attribute
, true },
750 { "transaction_safe", 0, 0, false, true, false,
751 handle_tm_attribute
, true },
752 { "transaction_safe_dynamic", 0, 0, true, false, false,
753 handle_tm_attribute
, false },
754 { "transaction_may_cancel_outer", 0, 0, false, true, false,
755 handle_tm_attribute
, false },
756 /* ??? These two attributes didn't make the transition from the
757 Intel language document to the multi-vendor language document. */
758 { "transaction_pure", 0, 0, false, true, false,
759 handle_tm_attribute
, false },
760 { "transaction_wrap", 1, 1, true, false, false,
761 handle_tm_wrap_attribute
, false },
762 /* For internal use (marking of builtins) only. The name contains space
763 to prevent its usage in source code. */
764 { "no vops", 0, 0, true, false, false,
765 handle_novops_attribute
, false },
766 { "deprecated", 0, 1, false, false, false,
767 handle_deprecated_attribute
, false },
768 { "vector_size", 1, 1, false, true, false,
769 handle_vector_size_attribute
, true },
770 { "visibility", 1, 1, false, false, false,
771 handle_visibility_attribute
, false },
772 { "tls_model", 1, 1, true, false, false,
773 handle_tls_model_attribute
, false },
774 { "nonnull", 0, -1, false, true, true,
775 handle_nonnull_attribute
, false },
776 { "nothrow", 0, 0, true, false, false,
777 handle_nothrow_attribute
, false },
778 { "may_alias", 0, 0, false, true, false, NULL
, false },
779 { "cleanup", 1, 1, true, false, false,
780 handle_cleanup_attribute
, false },
781 { "warn_unused_result", 0, 0, false, true, true,
782 handle_warn_unused_result_attribute
, false },
783 { "sentinel", 0, 1, false, true, true,
784 handle_sentinel_attribute
, false },
785 /* For internal use (marking of builtins) only. The name contains space
786 to prevent its usage in source code. */
787 { "type generic", 0, 0, false, true, true,
788 handle_type_generic_attribute
, false },
789 { "alloc_size", 1, 2, false, true, true,
790 handle_alloc_size_attribute
, false },
791 { "cold", 0, 0, true, false, false,
792 handle_cold_attribute
, false },
793 { "hot", 0, 0, true, false, false,
794 handle_hot_attribute
, false },
795 { "no_address_safety_analysis",
796 0, 0, true, false, false,
797 handle_no_address_safety_analysis_attribute
,
799 { "no_sanitize_address", 0, 0, true, false, false,
800 handle_no_sanitize_address_attribute
,
802 { "no_sanitize_thread", 0, 0, true, false, false,
803 handle_no_sanitize_address_attribute
,
805 { "no_sanitize_undefined", 0, 0, true, false, false,
806 handle_no_sanitize_undefined_attribute
,
808 { "warning", 1, 1, true, false, false,
809 handle_error_attribute
, false },
810 { "error", 1, 1, true, false, false,
811 handle_error_attribute
, false },
812 { "target", 1, -1, true, false, false,
813 handle_target_attribute
, false },
814 { "target_clones", 1, -1, true, false, false,
815 handle_target_clones_attribute
, false },
816 { "optimize", 1, -1, true, false, false,
817 handle_optimize_attribute
, false },
818 /* For internal use only. The leading '*' both prevents its usage in
819 source code and signals that it may be overridden by machine tables. */
820 { "*tm regparm", 0, 0, false, true, true,
821 ignore_attribute
, false },
822 { "no_split_stack", 0, 0, true, false, false,
823 handle_no_split_stack_attribute
, false },
824 /* For internal use (marking of builtins and runtime functions) only.
825 The name contains space to prevent its usage in source code. */
826 { "fn spec", 1, 1, false, true, true,
827 handle_fnspec_attribute
, false },
828 { "warn_unused", 0, 0, false, false, false,
829 handle_warn_unused_attribute
, false },
830 { "returns_nonnull", 0, 0, false, true, true,
831 handle_returns_nonnull_attribute
, false },
832 { "omp declare simd", 0, -1, true, false, false,
833 handle_omp_declare_simd_attribute
, false },
834 { "cilk simd function", 0, -1, true, false, false,
835 handle_omp_declare_simd_attribute
, false },
836 { "simd", 0, 1, true, false, false,
837 handle_simd_attribute
, false },
838 { "omp declare target", 0, 0, true, false, false,
839 handle_omp_declare_target_attribute
, false },
840 { "omp declare target link", 0, 0, true, false, false,
841 handle_omp_declare_target_attribute
, false },
842 { "alloc_align", 1, 1, false, true, true,
843 handle_alloc_align_attribute
, false },
844 { "assume_aligned", 1, 2, false, true, true,
845 handle_assume_aligned_attribute
, false },
846 { "designated_init", 0, 0, false, true, false,
847 handle_designated_init_attribute
, false },
848 { "bnd_variable_size", 0, 0, true, false, false,
849 handle_bnd_variable_size_attribute
, false },
850 { "bnd_legacy", 0, 0, true, false, false,
851 handle_bnd_legacy
, false },
852 { "bnd_instrument", 0, 0, true, false, false,
853 handle_bnd_instrument
, false },
854 { "fallthrough", 0, 0, false, false, false,
855 handle_fallthrough_attribute
, false },
856 { NULL
, 0, 0, false, false, false, NULL
, false }
859 /* Give the specifications for the format attributes, used by C and all
862 All attributes referencing arguments should be additionally processed
863 in chkp_copy_function_type_adding_bounds for correct instrumentation
864 by Pointer Bounds Checker.
865 Current list of processed format attributes: format, format_arg. */
866 const struct attribute_spec c_common_format_attribute_table
[] =
868 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
869 affects_type_identity } */
870 { "format", 3, 3, false, true, true,
871 handle_format_attribute
, false },
872 { "format_arg", 1, 1, false, true, true,
873 handle_format_arg_attribute
, false },
874 { NULL
, 0, 0, false, false, false, NULL
, false }
877 /* Return identifier for address space AS. */
880 c_addr_space_name (addr_space_t as
)
882 int rid
= RID_FIRST_ADDR_SPACE
+ as
;
883 gcc_assert (ridpointers
[rid
]);
884 return IDENTIFIER_POINTER (ridpointers
[rid
]);
887 /* Push current bindings for the function name VAR_DECLS. */
890 start_fname_decls (void)
893 tree saved
= NULL_TREE
;
895 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
897 tree decl
= *fname_vars
[ix
].decl
;
901 saved
= tree_cons (decl
, build_int_cst (integer_type_node
, ix
),
903 *fname_vars
[ix
].decl
= NULL_TREE
;
906 if (saved
|| saved_function_name_decls
)
907 /* Normally they'll have been NULL, so only push if we've got a
908 stack, or they are non-NULL. */
909 saved_function_name_decls
= tree_cons (saved
, NULL_TREE
,
910 saved_function_name_decls
);
913 /* Finish up the current bindings, adding them into the current function's
914 statement tree. This must be done _before_ finish_stmt_tree is called.
915 If there is no current function, we must be at file scope and no statements
916 are involved. Pop the previous bindings. */
919 finish_fname_decls (void)
922 tree stmts
= NULL_TREE
;
923 tree stack
= saved_function_name_decls
;
925 for (; stack
&& TREE_VALUE (stack
); stack
= TREE_CHAIN (stack
))
926 append_to_statement_list (TREE_VALUE (stack
), &stmts
);
930 tree
*bodyp
= &DECL_SAVED_TREE (current_function_decl
);
932 if (TREE_CODE (*bodyp
) == BIND_EXPR
)
933 bodyp
= &BIND_EXPR_BODY (*bodyp
);
935 append_to_statement_list_force (*bodyp
, &stmts
);
939 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
940 *fname_vars
[ix
].decl
= NULL_TREE
;
944 /* We had saved values, restore them. */
947 for (saved
= TREE_PURPOSE (stack
); saved
; saved
= TREE_CHAIN (saved
))
949 tree decl
= TREE_PURPOSE (saved
);
950 unsigned ix
= TREE_INT_CST_LOW (TREE_VALUE (saved
));
952 *fname_vars
[ix
].decl
= decl
;
954 stack
= TREE_CHAIN (stack
);
956 saved_function_name_decls
= stack
;
959 /* Return the text name of the current function, suitably prettified
960 by PRETTY_P. Return string must be freed by caller. */
963 fname_as_string (int pretty_p
)
965 const char *name
= "top level";
968 cpp_string cstr
= { 0, 0 }, strname
;
976 if (current_function_decl
)
977 name
= lang_hooks
.decl_printable_name (current_function_decl
, vrb
);
979 len
= strlen (name
) + 3; /* Two for '"'s. One for NULL. */
981 namep
= XNEWVEC (char, len
);
982 snprintf (namep
, len
, "\"%s\"", name
);
983 strname
.text
= (unsigned char *) namep
;
984 strname
.len
= len
- 1;
986 if (cpp_interpret_string (parse_in
, &strname
, 1, &cstr
, CPP_STRING
))
989 return (const char *) cstr
.text
;
995 /* Return the VAR_DECL for a const char array naming the current
996 function. If the VAR_DECL has not yet been created, create it
997 now. RID indicates how it should be formatted and IDENTIFIER_NODE
998 ID is its name (unfortunately C and C++ hold the RID values of
999 keywords in different places, so we can't derive RID from ID in
1000 this language independent code. LOC is the location of the
1004 fname_decl (location_t loc
, unsigned int rid
, tree id
)
1007 tree decl
= NULL_TREE
;
1009 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
1010 if (fname_vars
[ix
].rid
== rid
)
1013 decl
= *fname_vars
[ix
].decl
;
1016 /* If a tree is built here, it would normally have the lineno of
1017 the current statement. Later this tree will be moved to the
1018 beginning of the function and this line number will be wrong.
1019 To avoid this problem set the lineno to 0 here; that prevents
1020 it from appearing in the RTL. */
1022 location_t saved_location
= input_location
;
1023 input_location
= UNKNOWN_LOCATION
;
1025 stmts
= push_stmt_list ();
1026 decl
= (*make_fname_decl
) (loc
, id
, fname_vars
[ix
].pretty
);
1027 stmts
= pop_stmt_list (stmts
);
1028 if (!IS_EMPTY_STMT (stmts
))
1029 saved_function_name_decls
1030 = tree_cons (decl
, stmts
, saved_function_name_decls
);
1031 *fname_vars
[ix
].decl
= decl
;
1032 input_location
= saved_location
;
1034 if (!ix
&& !current_function_decl
)
1035 pedwarn (loc
, 0, "%qD is not defined outside of function scope", decl
);
1040 /* Given a STRING_CST, give it a suitable array-of-chars data type. */
1043 fix_string_type (tree value
)
1045 int length
= TREE_STRING_LENGTH (value
);
1047 tree e_type
, i_type
, a_type
;
1049 /* Compute the number of elements, for the array type. */
1050 if (TREE_TYPE (value
) == char_array_type_node
|| !TREE_TYPE (value
))
1053 e_type
= char_type_node
;
1055 else if (TREE_TYPE (value
) == char16_array_type_node
)
1057 nchars
= length
/ (TYPE_PRECISION (char16_type_node
) / BITS_PER_UNIT
);
1058 e_type
= char16_type_node
;
1060 else if (TREE_TYPE (value
) == char32_array_type_node
)
1062 nchars
= length
/ (TYPE_PRECISION (char32_type_node
) / BITS_PER_UNIT
);
1063 e_type
= char32_type_node
;
1067 nchars
= length
/ (TYPE_PRECISION (wchar_type_node
) / BITS_PER_UNIT
);
1068 e_type
= wchar_type_node
;
1071 /* C89 2.2.4.1, C99 5.2.4.1 (Translation limits). The analogous
1072 limit in C++98 Annex B is very large (65536) and is not normative,
1073 so we do not diagnose it (warn_overlength_strings is forced off
1074 in c_common_post_options). */
1075 if (warn_overlength_strings
)
1077 const int nchars_max
= flag_isoc99
? 4095 : 509;
1078 const int relevant_std
= flag_isoc99
? 99 : 90;
1079 if (nchars
- 1 > nchars_max
)
1080 /* Translators: The %d after 'ISO C' will be 90 or 99. Do not
1081 separate the %d from the 'C'. 'ISO' should not be
1082 translated, but it may be moved after 'C%d' in languages
1083 where modifiers follow nouns. */
1084 pedwarn (input_location
, OPT_Woverlength_strings
,
1085 "string length %qd is greater than the length %qd "
1086 "ISO C%d compilers are required to support",
1087 nchars
- 1, nchars_max
, relevant_std
);
1090 /* Create the array type for the string constant. The ISO C++
1091 standard says that a string literal has type `const char[N]' or
1092 `const wchar_t[N]'. We use the same logic when invoked as a C
1093 front-end with -Wwrite-strings.
1094 ??? We should change the type of an expression depending on the
1095 state of a warning flag. We should just be warning -- see how
1096 this is handled in the C++ front-end for the deprecated implicit
1097 conversion from string literals to `char*' or `wchar_t*'.
1099 The C++ front end relies on TYPE_MAIN_VARIANT of a cv-qualified
1100 array type being the unqualified version of that type.
1101 Therefore, if we are constructing an array of const char, we must
1102 construct the matching unqualified array type first. The C front
1103 end does not require this, but it does no harm, so we do it
1105 i_type
= build_index_type (size_int (nchars
- 1));
1106 a_type
= build_array_type (e_type
, i_type
);
1107 if (c_dialect_cxx() || warn_write_strings
)
1108 a_type
= c_build_qualified_type (a_type
, TYPE_QUAL_CONST
);
1110 TREE_TYPE (value
) = a_type
;
1111 TREE_CONSTANT (value
) = 1;
1112 TREE_READONLY (value
) = 1;
1113 TREE_STATIC (value
) = 1;
1117 /* Given a string of type STRING_TYPE, determine what kind of string
1118 token would give an equivalent execution encoding: CPP_STRING,
1119 CPP_STRING16, or CPP_STRING32. Return CPP_OTHER in case of error.
1120 This may not be exactly the string token type that initially created
1121 the string, since CPP_WSTRING is indistinguishable from the 16/32 bit
1122 string type at this point.
1124 This effectively reverses part of the logic in lex_string and
1127 static enum cpp_ttype
1128 get_cpp_ttype_from_string_type (tree string_type
)
1130 gcc_assert (string_type
);
1131 if (TREE_CODE (string_type
) == POINTER_TYPE
)
1132 string_type
= TREE_TYPE (string_type
);
1134 if (TREE_CODE (string_type
) != ARRAY_TYPE
)
1137 tree element_type
= TREE_TYPE (string_type
);
1138 if (TREE_CODE (element_type
) != INTEGER_TYPE
)
1141 int bits_per_character
= TYPE_PRECISION (element_type
);
1142 switch (bits_per_character
)
1145 return CPP_STRING
; /* It could have also been CPP_UTF8STRING. */
1147 return CPP_STRING16
;
1149 return CPP_STRING32
;
1155 /* The global record of string concatentations, for use in
1156 extracting locations within string literals. */
1158 GTY(()) string_concat_db
*g_string_concat_db
;
1160 /* Implementation of LANG_HOOKS_GET_SUBSTRING_LOCATION. */
1163 c_get_substring_location (const substring_loc
&substr_loc
,
1164 location_t
*out_loc
)
1166 enum cpp_ttype tok_type
1167 = get_cpp_ttype_from_string_type (substr_loc
.get_string_type ());
1168 if (tok_type
== CPP_OTHER
)
1169 return "unrecognized string type";
1171 return get_source_location_for_substring (parse_in
, g_string_concat_db
,
1172 substr_loc
.get_fmt_string_loc (),
1174 substr_loc
.get_caret_idx (),
1175 substr_loc
.get_start_idx (),
1176 substr_loc
.get_end_idx (),
1181 /* Fold X for consideration by one of the warning functions when checking
1182 whether an expression has a constant value. */
1185 fold_for_warn (tree x
)
1187 if (c_dialect_cxx ())
1188 return c_fully_fold (x
, /*for_init*/false, /*maybe_constp*/NULL
);
1190 /* The C front-end has already folded X appropriately. */
1194 /* Print a warning if a constant expression had overflow in folding.
1195 Invoke this function on every expression that the language
1196 requires to be a constant expression.
1197 Note the ANSI C standard says it is erroneous for a
1198 constant expression to overflow. */
1201 constant_expression_warning (tree value
)
1203 if (warn_overflow
&& pedantic
1204 && (TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1205 || TREE_CODE (value
) == FIXED_CST
1206 || TREE_CODE (value
) == VECTOR_CST
1207 || TREE_CODE (value
) == COMPLEX_CST
)
1208 && TREE_OVERFLOW (value
))
1209 pedwarn (input_location
, OPT_Woverflow
, "overflow in constant expression");
1212 /* The same as above but print an unconditional error. */
1214 constant_expression_error (tree value
)
1216 if ((TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1217 || TREE_CODE (value
) == FIXED_CST
1218 || TREE_CODE (value
) == VECTOR_CST
1219 || TREE_CODE (value
) == COMPLEX_CST
)
1220 && TREE_OVERFLOW (value
))
1221 error ("overflow in constant expression");
1224 /* Print a warning if an expression had overflow in folding and its
1227 Invoke this function on every expression that
1228 (1) appears in the source code, and
1229 (2) is a constant expression that overflowed, and
1230 (3) is not already checked by convert_and_check;
1231 however, do not invoke this function on operands of explicit casts
1232 or when the expression is the result of an operator and any operand
1233 already overflowed. */
1236 overflow_warning (location_t loc
, tree value
)
1238 if (c_inhibit_evaluation_warnings
!= 0)
1241 switch (TREE_CODE (value
))
1244 warning_at (loc
, OPT_Woverflow
, "integer overflow in expression");
1248 warning_at (loc
, OPT_Woverflow
,
1249 "floating point overflow in expression");
1253 warning_at (loc
, OPT_Woverflow
, "fixed-point overflow in expression");
1257 warning_at (loc
, OPT_Woverflow
, "vector overflow in expression");
1261 if (TREE_CODE (TREE_REALPART (value
)) == INTEGER_CST
)
1262 warning_at (loc
, OPT_Woverflow
,
1263 "complex integer overflow in expression");
1264 else if (TREE_CODE (TREE_REALPART (value
)) == REAL_CST
)
1265 warning_at (loc
, OPT_Woverflow
,
1266 "complex floating point overflow in expression");
1274 /* Warn about uses of logical || / && operator in a context where it
1275 is likely that the bitwise equivalent was intended by the
1276 programmer. We have seen an expression in which CODE is a binary
1277 operator used to combine expressions OP_LEFT and OP_RIGHT, which before folding
1278 had CODE_LEFT and CODE_RIGHT, into an expression of type TYPE. */
1280 warn_logical_operator (location_t location
, enum tree_code code
, tree type
,
1281 enum tree_code code_left
, tree op_left
,
1282 enum tree_code
ARG_UNUSED (code_right
), tree op_right
)
1284 int or_op
= (code
== TRUTH_ORIF_EXPR
|| code
== TRUTH_OR_EXPR
);
1285 int in0_p
, in1_p
, in_p
;
1286 tree low0
, low1
, low
, high0
, high1
, high
, lhs
, rhs
, tem
;
1287 bool strict_overflow_p
= false;
1289 if (code
!= TRUTH_ANDIF_EXPR
1290 && code
!= TRUTH_AND_EXPR
1291 && code
!= TRUTH_ORIF_EXPR
1292 && code
!= TRUTH_OR_EXPR
)
1295 /* We don't want to warn if either operand comes from a macro
1296 expansion. ??? This doesn't work with e.g. NEGATE_EXPR yet;
1298 if (from_macro_expansion_at (EXPR_LOCATION (op_left
))
1299 || from_macro_expansion_at (EXPR_LOCATION (op_right
)))
1302 /* Warn if &&/|| are being used in a context where it is
1303 likely that the bitwise equivalent was intended by the
1304 programmer. That is, an expression such as op && MASK
1305 where op should not be any boolean expression, nor a
1306 constant, and mask seems to be a non-boolean integer constant. */
1307 if (TREE_CODE (op_right
) == CONST_DECL
)
1308 /* An enumerator counts as a constant. */
1309 op_right
= DECL_INITIAL (op_right
);
1310 if (!truth_value_p (code_left
)
1311 && INTEGRAL_TYPE_P (TREE_TYPE (op_left
))
1312 && !CONSTANT_CLASS_P (op_left
)
1313 && !TREE_NO_WARNING (op_left
)
1314 && TREE_CODE (op_right
) == INTEGER_CST
1315 && !integer_zerop (op_right
)
1316 && !integer_onep (op_right
))
1319 warning_at (location
, OPT_Wlogical_op
, "logical %<or%>"
1320 " applied to non-boolean constant");
1322 warning_at (location
, OPT_Wlogical_op
, "logical %<and%>"
1323 " applied to non-boolean constant");
1324 TREE_NO_WARNING (op_left
) = true;
1328 /* We do not warn for constants because they are typical of macro
1329 expansions that test for features. */
1330 if (CONSTANT_CLASS_P (fold_for_warn (op_left
))
1331 || CONSTANT_CLASS_P (fold_for_warn (op_right
)))
1334 /* This warning only makes sense with logical operands. */
1335 if (!(truth_value_p (TREE_CODE (op_left
))
1336 || INTEGRAL_TYPE_P (TREE_TYPE (op_left
)))
1337 || !(truth_value_p (TREE_CODE (op_right
))
1338 || INTEGRAL_TYPE_P (TREE_TYPE (op_right
))))
1341 /* The range computations only work with scalars. */
1342 if (VECTOR_TYPE_P (TREE_TYPE (op_left
))
1343 || VECTOR_TYPE_P (TREE_TYPE (op_right
)))
1346 /* We first test whether either side separately is trivially true
1347 (with OR) or trivially false (with AND). If so, do not warn.
1348 This is a common idiom for testing ranges of data types in
1350 lhs
= make_range (op_left
, &in0_p
, &low0
, &high0
, &strict_overflow_p
);
1353 if (TREE_CODE (lhs
) == C_MAYBE_CONST_EXPR
)
1354 lhs
= C_MAYBE_CONST_EXPR_EXPR (lhs
);
1356 /* If this is an OR operation, invert both sides; now, the result
1357 should be always false to get a warning. */
1361 tem
= build_range_check (UNKNOWN_LOCATION
, type
, lhs
, in0_p
, low0
, high0
);
1362 if (tem
&& integer_zerop (tem
))
1365 rhs
= make_range (op_right
, &in1_p
, &low1
, &high1
, &strict_overflow_p
);
1368 if (TREE_CODE (rhs
) == C_MAYBE_CONST_EXPR
)
1369 rhs
= C_MAYBE_CONST_EXPR_EXPR (rhs
);
1371 /* If this is an OR operation, invert both sides; now, the result
1372 should be always false to get a warning. */
1376 tem
= build_range_check (UNKNOWN_LOCATION
, type
, rhs
, in1_p
, low1
, high1
);
1377 if (tem
&& integer_zerop (tem
))
1380 /* If both expressions have the same operand, if we can merge the
1382 if (operand_equal_p (lhs
, rhs
, 0)
1383 && merge_ranges (&in_p
, &low
, &high
, in0_p
, low0
, high0
,
1384 in1_p
, low1
, high1
))
1386 tem
= build_range_check (UNKNOWN_LOCATION
, type
, lhs
, in_p
, low
, high
);
1387 /* ... and if the range test is always false, then warn. */
1388 if (tem
&& integer_zerop (tem
))
1391 warning_at (location
, OPT_Wlogical_op
,
1392 "logical %<or%> of collectively exhaustive tests is "
1395 warning_at (location
, OPT_Wlogical_op
,
1396 "logical %<and%> of mutually exclusive tests is "
1399 /* Or warn if the operands have exactly the same range, e.g.
1401 else if (tree_int_cst_equal (low0
, low1
)
1402 && tree_int_cst_equal (high0
, high1
))
1405 warning_at (location
, OPT_Wlogical_op
,
1406 "logical %<or%> of equal expressions");
1408 warning_at (location
, OPT_Wlogical_op
,
1409 "logical %<and%> of equal expressions");
1414 /* Helper function for warn_tautological_cmp. Look for ARRAY_REFs
1415 with constant indices. */
1418 find_array_ref_with_const_idx_r (tree
*expr_p
, int *walk_subtrees
, void *data
)
1420 tree expr
= *expr_p
;
1422 if ((TREE_CODE (expr
) == ARRAY_REF
1423 || TREE_CODE (expr
) == ARRAY_RANGE_REF
)
1424 && TREE_CODE (TREE_OPERAND (expr
, 1)) == INTEGER_CST
)
1426 *(bool *) data
= true;
1433 /* Warn if a self-comparison always evaluates to true or false. LOC
1434 is the location of the comparison with code CODE, LHS and RHS are
1435 operands of the comparison. */
1438 warn_tautological_cmp (location_t loc
, enum tree_code code
, tree lhs
, tree rhs
)
1440 if (TREE_CODE_CLASS (code
) != tcc_comparison
)
1443 /* Don't warn for various macro expansions. */
1444 if (from_macro_expansion_at (loc
)
1445 || from_macro_expansion_at (EXPR_LOCATION (lhs
))
1446 || from_macro_expansion_at (EXPR_LOCATION (rhs
)))
1449 /* We do not warn for constants because they are typical of macro
1450 expansions that test for features, sizeof, and similar. */
1451 if (CONSTANT_CLASS_P (fold_for_warn (lhs
))
1452 || CONSTANT_CLASS_P (fold_for_warn (rhs
)))
1455 /* Don't warn for e.g.
1458 if (n == (long) n) ...
1460 if ((CONVERT_EXPR_P (lhs
) || TREE_CODE (lhs
) == NON_LVALUE_EXPR
)
1461 || (CONVERT_EXPR_P (rhs
) || TREE_CODE (rhs
) == NON_LVALUE_EXPR
))
1464 /* Don't warn if either LHS or RHS has an IEEE floating-point type.
1465 It could be a NaN, and NaN never compares equal to anything, even
1467 if (FLOAT_TYPE_P (TREE_TYPE (lhs
)) || FLOAT_TYPE_P (TREE_TYPE (rhs
)))
1470 if (operand_equal_p (lhs
, rhs
, 0))
1472 /* Don't warn about array references with constant indices;
1473 these are likely to come from a macro. */
1475 walk_tree_without_duplicates (&lhs
, find_array_ref_with_const_idx_r
,
1479 const bool always_true
= (code
== EQ_EXPR
|| code
== LE_EXPR
1480 || code
== GE_EXPR
|| code
== UNLE_EXPR
1481 || code
== UNGE_EXPR
|| code
== UNEQ_EXPR
);
1483 warning_at (loc
, OPT_Wtautological_compare
,
1484 "self-comparison always evaluates to true");
1486 warning_at (loc
, OPT_Wtautological_compare
,
1487 "self-comparison always evaluates to false");
1491 /* Return true iff T is a boolean promoted to int. */
1494 bool_promoted_to_int_p (tree t
)
1496 return (CONVERT_EXPR_P (t
)
1497 && TREE_TYPE (t
) == integer_type_node
1498 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == BOOLEAN_TYPE
);
1501 /* Return true iff EXPR only contains boolean operands, or comparisons. */
1504 expr_has_boolean_operands_p (tree expr
)
1508 if (CONVERT_EXPR_P (expr
))
1509 return bool_promoted_to_int_p (expr
);
1510 else if (UNARY_CLASS_P (expr
))
1511 return expr_has_boolean_operands_p (TREE_OPERAND (expr
, 0));
1512 else if (BINARY_CLASS_P (expr
))
1513 return (expr_has_boolean_operands_p (TREE_OPERAND (expr
, 0))
1514 && expr_has_boolean_operands_p (TREE_OPERAND (expr
, 1)));
1515 else if (COMPARISON_CLASS_P (expr
))
1521 /* Warn about logical not used on the left hand side operand of a comparison.
1522 This function assumes that the LHS is inside of TRUTH_NOT_EXPR.
1523 Do not warn if RHS is of a boolean type, a logical operator, or
1527 warn_logical_not_parentheses (location_t location
, enum tree_code code
,
1530 if (TREE_CODE_CLASS (code
) != tcc_comparison
1531 || TREE_TYPE (rhs
) == NULL_TREE
1532 || TREE_CODE (TREE_TYPE (rhs
)) == BOOLEAN_TYPE
1533 || truth_value_p (TREE_CODE (rhs
)))
1536 /* Don't warn for expression like !x == ~(bool1 | bool2). */
1537 if (expr_has_boolean_operands_p (rhs
))
1540 /* Don't warn for !x == 0 or !y != 0, those are equivalent to
1541 !(x == 0) or !(y != 0). */
1542 if ((code
== EQ_EXPR
|| code
== NE_EXPR
)
1543 && integer_zerop (rhs
))
1546 if (warning_at (location
, OPT_Wlogical_not_parentheses
,
1547 "logical not is only applied to the left hand side of "
1549 && EXPR_HAS_LOCATION (lhs
))
1551 location_t lhs_loc
= EXPR_LOCATION (lhs
);
1552 rich_location
richloc (line_table
, lhs_loc
);
1553 richloc
.add_fixit_insert_before (lhs_loc
, "(");
1554 richloc
.add_fixit_insert_after (lhs_loc
, ")");
1555 inform_at_rich_loc (&richloc
, "add parentheses around left hand side "
1556 "expression to silence this warning");
1560 /* Warn if EXP contains any computations whose results are not used.
1561 Return true if a warning is printed; false otherwise. LOCUS is the
1562 (potential) location of the expression. */
1565 warn_if_unused_value (const_tree exp
, location_t locus
)
1568 if (TREE_USED (exp
) || TREE_NO_WARNING (exp
))
1571 /* Don't warn about void constructs. This includes casting to void,
1572 void function calls, and statement expressions with a final cast
1574 if (VOID_TYPE_P (TREE_TYPE (exp
)))
1577 if (EXPR_HAS_LOCATION (exp
))
1578 locus
= EXPR_LOCATION (exp
);
1580 switch (TREE_CODE (exp
))
1582 case PREINCREMENT_EXPR
:
1583 case POSTINCREMENT_EXPR
:
1584 case PREDECREMENT_EXPR
:
1585 case POSTDECREMENT_EXPR
:
1590 case TRY_CATCH_EXPR
:
1591 case WITH_CLEANUP_EXPR
:
1597 /* For a binding, warn if no side effect within it. */
1598 exp
= BIND_EXPR_BODY (exp
);
1602 case NON_LVALUE_EXPR
:
1604 exp
= TREE_OPERAND (exp
, 0);
1607 case TRUTH_ORIF_EXPR
:
1608 case TRUTH_ANDIF_EXPR
:
1609 /* In && or ||, warn if 2nd operand has no side effect. */
1610 exp
= TREE_OPERAND (exp
, 1);
1614 if (warn_if_unused_value (TREE_OPERAND (exp
, 0), locus
))
1616 /* Let people do `(foo (), 0)' without a warning. */
1617 if (TREE_CONSTANT (TREE_OPERAND (exp
, 1)))
1619 exp
= TREE_OPERAND (exp
, 1);
1623 /* If this is an expression with side effects, don't warn; this
1624 case commonly appears in macro expansions. */
1625 if (TREE_SIDE_EFFECTS (exp
))
1630 /* Don't warn about automatic dereferencing of references, since
1631 the user cannot control it. */
1632 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == REFERENCE_TYPE
)
1634 exp
= TREE_OPERAND (exp
, 0);
1640 /* Referencing a volatile value is a side effect, so don't warn. */
1641 if ((DECL_P (exp
) || REFERENCE_CLASS_P (exp
))
1642 && TREE_THIS_VOLATILE (exp
))
1645 /* If this is an expression which has no operands, there is no value
1646 to be unused. There are no such language-independent codes,
1647 but front ends may define such. */
1648 if (EXPRESSION_CLASS_P (exp
) && TREE_OPERAND_LENGTH (exp
) == 0)
1652 return warning_at (locus
, OPT_Wunused_value
, "value computed is not used");
1657 /* Print a warning about casts that might indicate violation
1658 of strict aliasing rules if -Wstrict-aliasing is used and
1659 strict aliasing mode is in effect. OTYPE is the original
1660 TREE_TYPE of EXPR, and TYPE the type we're casting to. */
1663 strict_aliasing_warning (tree otype
, tree type
, tree expr
)
1665 /* Strip pointer conversion chains and get to the correct original type. */
1667 otype
= TREE_TYPE (expr
);
1669 if (!(flag_strict_aliasing
1670 && POINTER_TYPE_P (type
)
1671 && POINTER_TYPE_P (otype
)
1672 && !VOID_TYPE_P (TREE_TYPE (type
)))
1673 /* If the type we are casting to is a ref-all pointer
1674 dereferencing it is always valid. */
1675 || TYPE_REF_CAN_ALIAS_ALL (type
))
1678 if ((warn_strict_aliasing
> 1) && TREE_CODE (expr
) == ADDR_EXPR
1679 && (DECL_P (TREE_OPERAND (expr
, 0))
1680 || handled_component_p (TREE_OPERAND (expr
, 0))))
1682 /* Casting the address of an object to non void pointer. Warn
1683 if the cast breaks type based aliasing. */
1684 if (!COMPLETE_TYPE_P (TREE_TYPE (type
)) && warn_strict_aliasing
== 2)
1686 warning (OPT_Wstrict_aliasing
, "type-punning to incomplete type "
1687 "might break strict-aliasing rules");
1692 /* warn_strict_aliasing >= 3. This includes the default (3).
1693 Only warn if the cast is dereferenced immediately. */
1694 alias_set_type set1
=
1695 get_alias_set (TREE_TYPE (TREE_OPERAND (expr
, 0)));
1696 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
1698 if (set1
!= set2
&& set2
!= 0
1700 || (!alias_set_subset_of (set2
, set1
)
1701 && !alias_sets_conflict_p (set1
, set2
))))
1703 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1704 "pointer will break strict-aliasing rules");
1707 else if (warn_strict_aliasing
== 2
1708 && !alias_sets_must_conflict_p (set1
, set2
))
1710 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1711 "pointer might break strict-aliasing rules");
1717 if ((warn_strict_aliasing
== 1) && !VOID_TYPE_P (TREE_TYPE (otype
)))
1719 /* At this level, warn for any conversions, even if an address is
1720 not taken in the same statement. This will likely produce many
1721 false positives, but could be useful to pinpoint problems that
1722 are not revealed at higher levels. */
1723 alias_set_type set1
= get_alias_set (TREE_TYPE (otype
));
1724 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
1725 if (!COMPLETE_TYPE_P (type
)
1726 || !alias_sets_must_conflict_p (set1
, set2
))
1728 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1729 "pointer might break strict-aliasing rules");
1737 /* Warn about memset (&a, 0, sizeof (&a)); and similar mistakes with
1738 sizeof as last operand of certain builtins. */
1741 sizeof_pointer_memaccess_warning (location_t
*sizeof_arg_loc
, tree callee
,
1742 vec
<tree
, va_gc
> *params
, tree
*sizeof_arg
,
1743 bool (*comp_types
) (tree
, tree
))
1745 tree type
, dest
= NULL_TREE
, src
= NULL_TREE
, tem
;
1746 bool strop
= false, cmp
= false;
1747 unsigned int idx
= ~0;
1750 if (TREE_CODE (callee
) != FUNCTION_DECL
1751 || DECL_BUILT_IN_CLASS (callee
) != BUILT_IN_NORMAL
1752 || vec_safe_length (params
) <= 1)
1755 switch (DECL_FUNCTION_CODE (callee
))
1757 case BUILT_IN_STRNCMP
:
1758 case BUILT_IN_STRNCASECMP
:
1761 case BUILT_IN_STRNCPY
:
1762 case BUILT_IN_STRNCPY_CHK
:
1763 case BUILT_IN_STRNCAT
:
1764 case BUILT_IN_STRNCAT_CHK
:
1765 case BUILT_IN_STPNCPY
:
1766 case BUILT_IN_STPNCPY_CHK
:
1769 case BUILT_IN_MEMCPY
:
1770 case BUILT_IN_MEMCPY_CHK
:
1771 case BUILT_IN_MEMMOVE
:
1772 case BUILT_IN_MEMMOVE_CHK
:
1773 if (params
->length () < 3)
1776 dest
= (*params
)[0];
1779 case BUILT_IN_BCOPY
:
1780 if (params
->length () < 3)
1783 dest
= (*params
)[1];
1786 case BUILT_IN_MEMCMP
:
1788 if (params
->length () < 3)
1791 dest
= (*params
)[0];
1795 case BUILT_IN_MEMSET
:
1796 case BUILT_IN_MEMSET_CHK
:
1797 if (params
->length () < 3)
1799 dest
= (*params
)[0];
1802 case BUILT_IN_BZERO
:
1803 dest
= (*params
)[0];
1806 case BUILT_IN_STRNDUP
:
1811 case BUILT_IN_MEMCHR
:
1812 if (params
->length () < 3)
1817 case BUILT_IN_SNPRINTF
:
1818 case BUILT_IN_SNPRINTF_CHK
:
1819 case BUILT_IN_VSNPRINTF
:
1820 case BUILT_IN_VSNPRINTF_CHK
:
1821 dest
= (*params
)[0];
1832 if (sizeof_arg
[idx
] == NULL
|| sizeof_arg
[idx
] == error_mark_node
)
1835 type
= TYPE_P (sizeof_arg
[idx
])
1836 ? sizeof_arg
[idx
] : TREE_TYPE (sizeof_arg
[idx
]);
1837 if (!POINTER_TYPE_P (type
))
1841 && (tem
= tree_strip_nop_conversions (dest
))
1842 && POINTER_TYPE_P (TREE_TYPE (tem
))
1843 && comp_types (TREE_TYPE (TREE_TYPE (tem
)), type
))
1847 && (tem
= tree_strip_nop_conversions (src
))
1848 && POINTER_TYPE_P (TREE_TYPE (tem
))
1849 && comp_types (TREE_TYPE (TREE_TYPE (tem
)), type
))
1852 loc
= sizeof_arg_loc
[idx
];
1856 if (!TYPE_P (sizeof_arg
[idx
])
1857 && operand_equal_p (dest
, sizeof_arg
[idx
], 0)
1858 && comp_types (TREE_TYPE (dest
), type
))
1860 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
1861 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1862 "argument to %<sizeof%> in %qD call is the same "
1863 "expression as the destination; did you mean to "
1864 "remove the addressof?", callee
);
1865 else if ((TYPE_PRECISION (TREE_TYPE (type
))
1866 == TYPE_PRECISION (char_type_node
))
1868 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1869 "argument to %<sizeof%> in %qD call is the same "
1870 "expression as the destination; did you mean to "
1871 "provide an explicit length?", callee
);
1873 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1874 "argument to %<sizeof%> in %qD call is the same "
1875 "expression as the destination; did you mean to "
1876 "dereference it?", callee
);
1880 if (POINTER_TYPE_P (TREE_TYPE (dest
))
1882 && comp_types (TREE_TYPE (dest
), type
)
1883 && !VOID_TYPE_P (TREE_TYPE (type
)))
1885 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1886 "argument to %<sizeof%> in %qD call is the same "
1887 "pointer type %qT as the destination; expected %qT "
1888 "or an explicit length", callee
, TREE_TYPE (dest
),
1889 TREE_TYPE (TREE_TYPE (dest
)));
1896 if (!TYPE_P (sizeof_arg
[idx
])
1897 && operand_equal_p (src
, sizeof_arg
[idx
], 0)
1898 && comp_types (TREE_TYPE (src
), type
))
1900 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
1901 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1902 "argument to %<sizeof%> in %qD call is the same "
1903 "expression as the source; did you mean to "
1904 "remove the addressof?", callee
);
1905 else if ((TYPE_PRECISION (TREE_TYPE (type
))
1906 == TYPE_PRECISION (char_type_node
))
1908 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1909 "argument to %<sizeof%> in %qD call is the same "
1910 "expression as the source; did you mean to "
1911 "provide an explicit length?", callee
);
1913 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1914 "argument to %<sizeof%> in %qD call is the same "
1915 "expression as the source; did you mean to "
1916 "dereference it?", callee
);
1920 if (POINTER_TYPE_P (TREE_TYPE (src
))
1922 && comp_types (TREE_TYPE (src
), type
)
1923 && !VOID_TYPE_P (TREE_TYPE (type
)))
1925 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1926 "argument to %<sizeof%> in %qD call is the same "
1927 "pointer type %qT as the source; expected %qT "
1928 "or an explicit length", callee
, TREE_TYPE (src
),
1929 TREE_TYPE (TREE_TYPE (src
)));
1936 if (!TYPE_P (sizeof_arg
[idx
])
1937 && operand_equal_p (dest
, sizeof_arg
[idx
], 0)
1938 && comp_types (TREE_TYPE (dest
), type
))
1940 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
1941 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1942 "argument to %<sizeof%> in %qD call is the same "
1943 "expression as the first source; did you mean to "
1944 "remove the addressof?", callee
);
1945 else if ((TYPE_PRECISION (TREE_TYPE (type
))
1946 == TYPE_PRECISION (char_type_node
))
1948 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1949 "argument to %<sizeof%> in %qD call is the same "
1950 "expression as the first source; did you mean to "
1951 "provide an explicit length?", callee
);
1953 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1954 "argument to %<sizeof%> in %qD call is the same "
1955 "expression as the first source; did you mean to "
1956 "dereference it?", callee
);
1960 if (POINTER_TYPE_P (TREE_TYPE (dest
))
1962 && comp_types (TREE_TYPE (dest
), type
)
1963 && !VOID_TYPE_P (TREE_TYPE (type
)))
1965 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1966 "argument to %<sizeof%> in %qD call is the same "
1967 "pointer type %qT as the first source; expected %qT "
1968 "or an explicit length", callee
, TREE_TYPE (dest
),
1969 TREE_TYPE (TREE_TYPE (dest
)));
1976 if (!TYPE_P (sizeof_arg
[idx
])
1977 && operand_equal_p (src
, sizeof_arg
[idx
], 0)
1978 && comp_types (TREE_TYPE (src
), type
))
1980 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
1981 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1982 "argument to %<sizeof%> in %qD call is the same "
1983 "expression as the second source; did you mean to "
1984 "remove the addressof?", callee
);
1985 else if ((TYPE_PRECISION (TREE_TYPE (type
))
1986 == TYPE_PRECISION (char_type_node
))
1988 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1989 "argument to %<sizeof%> in %qD call is the same "
1990 "expression as the second source; did you mean to "
1991 "provide an explicit length?", callee
);
1993 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1994 "argument to %<sizeof%> in %qD call is the same "
1995 "expression as the second source; did you mean to "
1996 "dereference it?", callee
);
2000 if (POINTER_TYPE_P (TREE_TYPE (src
))
2002 && comp_types (TREE_TYPE (src
), type
)
2003 && !VOID_TYPE_P (TREE_TYPE (type
)))
2005 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2006 "argument to %<sizeof%> in %qD call is the same "
2007 "pointer type %qT as the second source; expected %qT "
2008 "or an explicit length", callee
, TREE_TYPE (src
),
2009 TREE_TYPE (TREE_TYPE (src
)));
2016 /* Warn for unlikely, improbable, or stupid DECL declarations
2020 check_main_parameter_types (tree decl
)
2022 function_args_iterator iter
;
2026 FOREACH_FUNCTION_ARGS (TREE_TYPE (decl
), type
, iter
)
2028 /* XXX void_type_node belies the abstraction. */
2029 if (type
== void_type_node
|| type
== error_mark_node
)
2033 if (TYPE_ATOMIC (t
))
2034 pedwarn (input_location
, OPT_Wmain
,
2035 "%<_Atomic%>-qualified parameter type %qT of %q+D",
2037 while (POINTER_TYPE_P (t
))
2040 if (TYPE_ATOMIC (t
))
2041 pedwarn (input_location
, OPT_Wmain
,
2042 "%<_Atomic%>-qualified parameter type %qT of %q+D",
2050 if (TYPE_MAIN_VARIANT (type
) != integer_type_node
)
2051 pedwarn (input_location
, OPT_Wmain
,
2052 "first argument of %q+D should be %<int%>", decl
);
2056 if (TREE_CODE (type
) != POINTER_TYPE
2057 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
2058 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
2060 pedwarn (input_location
, OPT_Wmain
,
2061 "second argument of %q+D should be %<char **%>", decl
);
2065 if (TREE_CODE (type
) != POINTER_TYPE
2066 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
2067 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
2069 pedwarn (input_location
, OPT_Wmain
,
2070 "third argument of %q+D should probably be "
2071 "%<char **%>", decl
);
2076 /* It is intentional that this message does not mention the third
2077 argument because it's only mentioned in an appendix of the
2079 if (argct
> 0 && (argct
< 2 || argct
> 3))
2080 pedwarn (input_location
, OPT_Wmain
,
2081 "%q+D takes only zero or two arguments", decl
);
2083 if (stdarg_p (TREE_TYPE (decl
)))
2084 pedwarn (input_location
, OPT_Wmain
,
2085 "%q+D declared as variadic function", decl
);
2088 /* vector_targets_convertible_p is used for vector pointer types. The
2089 callers perform various checks that the qualifiers are satisfactory,
2090 while OTOH vector_targets_convertible_p ignores the number of elements
2091 in the vectors. That's fine with vector pointers as we can consider,
2092 say, a vector of 8 elements as two consecutive vectors of 4 elements,
2093 and that does not require and conversion of the pointer values.
2094 In contrast, vector_types_convertible_p and
2095 vector_types_compatible_elements_p are used for vector value types. */
2096 /* True if pointers to distinct types T1 and T2 can be converted to
2097 each other without an explicit cast. Only returns true for opaque
2100 vector_targets_convertible_p (const_tree t1
, const_tree t2
)
2102 if (VECTOR_TYPE_P (t1
) && VECTOR_TYPE_P (t2
)
2103 && (TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2104 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2110 /* vector_types_convertible_p is used for vector value types.
2111 It could in principle call vector_targets_convertible_p as a subroutine,
2112 but then the check for vector type would be duplicated with its callers,
2113 and also the purpose of vector_targets_convertible_p would become
2115 Where vector_types_convertible_p returns true, a conversion might still be
2116 needed to make the types match.
2117 In contrast, vector_targets_convertible_p is used for vector pointer
2118 values, and vector_types_compatible_elements_p is used specifically
2119 in the context for binary operators, as a check if use is possible without
2121 /* True if vector types T1 and T2 can be converted to each other
2122 without an explicit cast. If EMIT_LAX_NOTE is true, and T1 and T2
2123 can only be converted with -flax-vector-conversions yet that is not
2124 in effect, emit a note telling the user about that option if such
2125 a note has not previously been emitted. */
2127 vector_types_convertible_p (const_tree t1
, const_tree t2
, bool emit_lax_note
)
2129 static bool emitted_lax_note
= false;
2130 bool convertible_lax
;
2132 if ((TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2133 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2137 (tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
))
2138 && (TREE_CODE (TREE_TYPE (t1
)) != REAL_TYPE
||
2139 TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
))
2140 && (INTEGRAL_TYPE_P (TREE_TYPE (t1
))
2141 == INTEGRAL_TYPE_P (TREE_TYPE (t2
))));
2143 if (!convertible_lax
|| flag_lax_vector_conversions
)
2144 return convertible_lax
;
2146 if (TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
)
2147 && lang_hooks
.types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
2150 if (emit_lax_note
&& !emitted_lax_note
)
2152 emitted_lax_note
= true;
2153 inform (input_location
, "use -flax-vector-conversions to permit "
2154 "conversions between vectors with differing "
2155 "element types or numbers of subparts");
2161 /* Build a VEC_PERM_EXPR if V0, V1 and MASK are not error_mark_nodes
2162 and have vector types, V0 has the same type as V1, and the number of
2163 elements of V0, V1, MASK is the same.
2165 In case V1 is a NULL_TREE it is assumed that __builtin_shuffle was
2166 called with two arguments. In this case implementation passes the
2167 first argument twice in order to share the same tree code. This fact
2168 could enable the mask-values being twice the vector length. This is
2169 an implementation accident and this semantics is not guaranteed to
2172 c_build_vec_perm_expr (location_t loc
, tree v0
, tree v1
, tree mask
,
2177 bool maybe_const
= false;
2178 bool two_arguments
= false;
2180 if (v1
== NULL_TREE
)
2182 two_arguments
= true;
2186 if (v0
== error_mark_node
|| v1
== error_mark_node
2187 || mask
== error_mark_node
)
2188 return error_mark_node
;
2190 if (!VECTOR_INTEGER_TYPE_P (TREE_TYPE (mask
)))
2193 error_at (loc
, "__builtin_shuffle last argument must "
2194 "be an integer vector");
2195 return error_mark_node
;
2198 if (!VECTOR_TYPE_P (TREE_TYPE (v0
))
2199 || !VECTOR_TYPE_P (TREE_TYPE (v1
)))
2202 error_at (loc
, "__builtin_shuffle arguments must be vectors");
2203 return error_mark_node
;
2206 if (TYPE_MAIN_VARIANT (TREE_TYPE (v0
)) != TYPE_MAIN_VARIANT (TREE_TYPE (v1
)))
2209 error_at (loc
, "__builtin_shuffle argument vectors must be of "
2211 return error_mark_node
;
2214 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (v0
))
2215 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
))
2216 && TYPE_VECTOR_SUBPARTS (TREE_TYPE (v1
))
2217 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
)))
2220 error_at (loc
, "__builtin_shuffle number of elements of the "
2221 "argument vector(s) and the mask vector should "
2223 return error_mark_node
;
2226 if (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (v0
))))
2227 != GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (mask
)))))
2230 error_at (loc
, "__builtin_shuffle argument vector(s) inner type "
2231 "must have the same size as inner type of the mask");
2232 return error_mark_node
;
2235 if (!c_dialect_cxx ())
2237 /* Avoid C_MAYBE_CONST_EXPRs inside VEC_PERM_EXPR. */
2238 v0
= c_fully_fold (v0
, false, &maybe_const
);
2239 wrap
&= maybe_const
;
2242 v1
= v0
= save_expr (v0
);
2245 v1
= c_fully_fold (v1
, false, &maybe_const
);
2246 wrap
&= maybe_const
;
2249 mask
= c_fully_fold (mask
, false, &maybe_const
);
2250 wrap
&= maybe_const
;
2252 else if (two_arguments
)
2253 v1
= v0
= save_expr (v0
);
2255 ret
= build3_loc (loc
, VEC_PERM_EXPR
, TREE_TYPE (v0
), v0
, v1
, mask
);
2257 if (!c_dialect_cxx () && !wrap
)
2258 ret
= c_wrap_maybe_const (ret
, true);
2263 /* Like tree.c:get_narrower, but retain conversion from C++0x scoped enum
2264 to integral type. */
2267 c_common_get_narrower (tree op
, int *unsignedp_ptr
)
2269 op
= get_narrower (op
, unsignedp_ptr
);
2271 if (TREE_CODE (TREE_TYPE (op
)) == ENUMERAL_TYPE
2272 && ENUM_IS_SCOPED (TREE_TYPE (op
)))
2274 /* C++0x scoped enumerations don't implicitly convert to integral
2275 type; if we stripped an explicit conversion to a larger type we
2276 need to replace it so common_type will still work. */
2277 tree type
= c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op
)),
2278 TYPE_UNSIGNED (TREE_TYPE (op
)));
2279 op
= fold_convert (type
, op
);
2284 /* This is a helper function of build_binary_op.
2286 For certain operations if both args were extended from the same
2287 smaller type, do the arithmetic in that type and then extend.
2289 BITWISE indicates a bitwise operation.
2290 For them, this optimization is safe only if
2291 both args are zero-extended or both are sign-extended.
2292 Otherwise, we might change the result.
2293 Eg, (short)-1 | (unsigned short)-1 is (int)-1
2294 but calculated in (unsigned short) it would be (unsigned short)-1.
2297 shorten_binary_op (tree result_type
, tree op0
, tree op1
, bool bitwise
)
2299 int unsigned0
, unsigned1
;
2304 /* Cast OP0 and OP1 to RESULT_TYPE. Doing so prevents
2305 excessive narrowing when we call get_narrower below. For
2306 example, suppose that OP0 is of unsigned int extended
2307 from signed char and that RESULT_TYPE is long long int.
2308 If we explicitly cast OP0 to RESULT_TYPE, OP0 would look
2311 (long long int) (unsigned int) signed_char
2313 which get_narrower would narrow down to
2315 (unsigned int) signed char
2317 If we do not cast OP0 first, get_narrower would return
2318 signed_char, which is inconsistent with the case of the
2320 op0
= convert (result_type
, op0
);
2321 op1
= convert (result_type
, op1
);
2323 arg0
= c_common_get_narrower (op0
, &unsigned0
);
2324 arg1
= c_common_get_narrower (op1
, &unsigned1
);
2326 /* UNS is 1 if the operation to be done is an unsigned one. */
2327 uns
= TYPE_UNSIGNED (result_type
);
2329 /* Handle the case that OP0 (or OP1) does not *contain* a conversion
2330 but it *requires* conversion to FINAL_TYPE. */
2332 if ((TYPE_PRECISION (TREE_TYPE (op0
))
2333 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2334 && TREE_TYPE (op0
) != result_type
)
2335 unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2336 if ((TYPE_PRECISION (TREE_TYPE (op1
))
2337 == TYPE_PRECISION (TREE_TYPE (arg1
)))
2338 && TREE_TYPE (op1
) != result_type
)
2339 unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2341 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
2343 /* For bitwise operations, signedness of nominal type
2344 does not matter. Consider only how operands were extended. */
2348 /* Note that in all three cases below we refrain from optimizing
2349 an unsigned operation on sign-extended args.
2350 That would not be valid. */
2352 /* Both args variable: if both extended in same way
2353 from same width, do it in that width.
2354 Do it unsigned if args were zero-extended. */
2355 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
2356 < TYPE_PRECISION (result_type
))
2357 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2358 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2359 && unsigned0
== unsigned1
2360 && (unsigned0
|| !uns
))
2361 return c_common_signed_or_unsigned_type
2362 (unsigned0
, common_type (TREE_TYPE (arg0
), TREE_TYPE (arg1
)));
2364 else if (TREE_CODE (arg0
) == INTEGER_CST
2365 && (unsigned1
|| !uns
)
2366 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2367 < TYPE_PRECISION (result_type
))
2369 = c_common_signed_or_unsigned_type (unsigned1
,
2371 && !POINTER_TYPE_P (type
)
2372 && int_fits_type_p (arg0
, type
))
2375 else if (TREE_CODE (arg1
) == INTEGER_CST
2376 && (unsigned0
|| !uns
)
2377 && (TYPE_PRECISION (TREE_TYPE (arg0
))
2378 < TYPE_PRECISION (result_type
))
2380 = c_common_signed_or_unsigned_type (unsigned0
,
2382 && !POINTER_TYPE_P (type
)
2383 && int_fits_type_p (arg1
, type
))
2389 /* Returns true iff any integer value of type FROM_TYPE can be represented as
2390 real of type TO_TYPE. This is a helper function for unsafe_conversion_p. */
2393 int_safely_convertible_to_real_p (const_tree from_type
, const_tree to_type
)
2395 tree type_low_bound
= TYPE_MIN_VALUE (from_type
);
2396 tree type_high_bound
= TYPE_MAX_VALUE (from_type
);
2397 REAL_VALUE_TYPE real_low_bound
=
2398 real_value_from_int_cst (0, type_low_bound
);
2399 REAL_VALUE_TYPE real_high_bound
=
2400 real_value_from_int_cst (0, type_high_bound
);
2402 return exact_real_truncate (TYPE_MODE (to_type
), &real_low_bound
)
2403 && exact_real_truncate (TYPE_MODE (to_type
), &real_high_bound
);
2406 /* Checks if expression EXPR of complex/real/integer type cannot be converted
2407 to the complex/real/integer type TYPE. Function returns non-zero when:
2408 * EXPR is a constant which cannot be exactly converted to TYPE.
2409 * EXPR is not a constant and size of EXPR's type > than size of TYPE,
2410 for EXPR type and TYPE being both integers or both real, or both
2412 * EXPR is not a constant of complex type and TYPE is a real or
2414 * EXPR is not a constant of real type and TYPE is an integer.
2415 * EXPR is not a constant of integer type which cannot be
2416 exactly converted to real type.
2418 Function allows conversions between types of different signedness and
2419 can return SAFE_CONVERSION (zero) in that case. Function can produce
2420 signedness warnings if PRODUCE_WARNS is true.
2422 Function allows conversions from complex constants to non-complex types,
2423 provided that imaginary part is zero and real part can be safely converted
2426 enum conversion_safety
2427 unsafe_conversion_p (location_t loc
, tree type
, tree expr
, bool produce_warns
)
2429 enum conversion_safety give_warning
= SAFE_CONVERSION
; /* is 0 or false */
2430 tree expr_type
= TREE_TYPE (expr
);
2431 loc
= expansion_point_location_if_in_system_header (loc
);
2433 if (TREE_CODE (expr
) == REAL_CST
|| TREE_CODE (expr
) == INTEGER_CST
)
2435 /* If type is complex, we are interested in compatibility with
2437 if (TREE_CODE (type
) == COMPLEX_TYPE
)
2438 type
= TREE_TYPE (type
);
2440 /* Warn for real constant that is not an exact integer converted
2442 if (TREE_CODE (expr_type
) == REAL_TYPE
2443 && TREE_CODE (type
) == INTEGER_TYPE
)
2445 if (!real_isinteger (TREE_REAL_CST_PTR (expr
), TYPE_MODE (expr_type
)))
2446 give_warning
= UNSAFE_REAL
;
2448 /* Warn for an integer constant that does not fit into integer type. */
2449 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2450 && TREE_CODE (type
) == INTEGER_TYPE
2451 && !int_fits_type_p (expr
, type
))
2453 if (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)
2454 && tree_int_cst_sgn (expr
) < 0)
2457 warning_at (loc
, OPT_Wsign_conversion
, "negative integer"
2458 " implicitly converted to unsigned type");
2460 else if (!TYPE_UNSIGNED (type
) && TYPE_UNSIGNED (expr_type
))
2463 warning_at (loc
, OPT_Wsign_conversion
, "conversion of unsigned"
2464 " constant value to negative integer");
2467 give_warning
= UNSAFE_OTHER
;
2469 else if (TREE_CODE (type
) == REAL_TYPE
)
2471 /* Warn for an integer constant that does not fit into real type. */
2472 if (TREE_CODE (expr_type
) == INTEGER_TYPE
)
2474 REAL_VALUE_TYPE a
= real_value_from_int_cst (0, expr
);
2475 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2476 give_warning
= UNSAFE_REAL
;
2478 /* Warn for a real constant that does not fit into a smaller
2480 else if (TREE_CODE (expr_type
) == REAL_TYPE
2481 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2483 REAL_VALUE_TYPE a
= TREE_REAL_CST (expr
);
2484 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2485 give_warning
= UNSAFE_REAL
;
2490 else if (TREE_CODE (expr
) == COMPLEX_CST
)
2492 tree imag_part
= TREE_IMAGPART (expr
);
2493 /* Conversion from complex constant with zero imaginary part,
2494 perform check for conversion of real part. */
2495 if ((TREE_CODE (imag_part
) == REAL_CST
2496 && real_zerop (imag_part
))
2497 || (TREE_CODE (imag_part
) == INTEGER_CST
2498 && integer_zerop (imag_part
)))
2499 /* Note: in this branch we use recursive call to unsafe_conversion_p
2500 with different type of EXPR, but it is still safe, because when EXPR
2501 is a constant, it's type is not used in text of generated warnings
2502 (otherwise they could sound misleading). */
2503 return unsafe_conversion_p (loc
, type
, TREE_REALPART (expr
),
2505 /* Conversion from complex constant with non-zero imaginary part. */
2508 /* Conversion to complex type.
2509 Perform checks for both real and imaginary parts. */
2510 if (TREE_CODE (type
) == COMPLEX_TYPE
)
2512 /* Unfortunately, produce_warns must be false in two subsequent
2513 calls of unsafe_conversion_p, because otherwise we could
2514 produce strange "double" warnings, if both real and imaginary
2515 parts have conversion problems related to signedness.
2518 int32_t _Complex a = 0x80000000 + 0x80000000i;
2520 Possible solution: add a separate function for checking
2521 constants and combine result of two calls appropriately. */
2522 enum conversion_safety re_safety
=
2523 unsafe_conversion_p (loc
, type
, TREE_REALPART (expr
), false);
2524 enum conversion_safety im_safety
=
2525 unsafe_conversion_p (loc
, type
, imag_part
, false);
2527 /* Merge the results into appropriate single warning. */
2529 /* Note: this case includes SAFE_CONVERSION, i.e. success. */
2530 if (re_safety
== im_safety
)
2531 give_warning
= re_safety
;
2532 else if (!re_safety
&& im_safety
)
2533 give_warning
= im_safety
;
2534 else if (re_safety
&& !im_safety
)
2535 give_warning
= re_safety
;
2537 give_warning
= UNSAFE_OTHER
;
2539 /* Warn about conversion from complex to real or integer type. */
2541 give_warning
= UNSAFE_IMAGINARY
;
2545 /* Checks for remaining case: EXPR is not constant. */
2548 /* Warn for real types converted to integer types. */
2549 if (TREE_CODE (expr_type
) == REAL_TYPE
2550 && TREE_CODE (type
) == INTEGER_TYPE
)
2551 give_warning
= UNSAFE_REAL
;
2553 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2554 && TREE_CODE (type
) == INTEGER_TYPE
)
2556 /* Don't warn about unsigned char y = 0xff, x = (int) y; */
2557 expr
= get_unwidened (expr
, 0);
2558 expr_type
= TREE_TYPE (expr
);
2560 /* Don't warn for short y; short x = ((int)y & 0xff); */
2561 if (TREE_CODE (expr
) == BIT_AND_EXPR
2562 || TREE_CODE (expr
) == BIT_IOR_EXPR
2563 || TREE_CODE (expr
) == BIT_XOR_EXPR
)
2565 /* If both args were extended from a shortest type,
2566 use that type if that is safe. */
2567 expr_type
= shorten_binary_op (expr_type
,
2568 TREE_OPERAND (expr
, 0),
2569 TREE_OPERAND (expr
, 1),
2572 if (TREE_CODE (expr
) == BIT_AND_EXPR
)
2574 tree op0
= TREE_OPERAND (expr
, 0);
2575 tree op1
= TREE_OPERAND (expr
, 1);
2576 bool unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2577 bool unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2579 /* If one of the operands is a non-negative constant
2580 that fits in the target type, then the type of the
2581 other operand does not matter. */
2582 if ((TREE_CODE (op0
) == INTEGER_CST
2583 && int_fits_type_p (op0
, c_common_signed_type (type
))
2584 && int_fits_type_p (op0
, c_common_unsigned_type (type
)))
2585 || (TREE_CODE (op1
) == INTEGER_CST
2586 && int_fits_type_p (op1
, c_common_signed_type (type
))
2587 && int_fits_type_p (op1
,
2588 c_common_unsigned_type (type
))))
2589 return SAFE_CONVERSION
;
2590 /* If constant is unsigned and fits in the target
2591 type, then the result will also fit. */
2592 else if ((TREE_CODE (op0
) == INTEGER_CST
2594 && int_fits_type_p (op0
, type
))
2595 || (TREE_CODE (op1
) == INTEGER_CST
2597 && int_fits_type_p (op1
, type
)))
2598 return SAFE_CONVERSION
;
2601 /* Warn for integer types converted to smaller integer types. */
2602 if (TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2603 give_warning
= UNSAFE_OTHER
;
2605 /* When they are the same width but different signedness,
2606 then the value may change. */
2607 else if (((TYPE_PRECISION (type
) == TYPE_PRECISION (expr_type
)
2608 && TYPE_UNSIGNED (expr_type
) != TYPE_UNSIGNED (type
))
2609 /* Even when converted to a bigger type, if the type is
2610 unsigned but expr is signed, then negative values
2612 || (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)))
2614 warning_at (loc
, OPT_Wsign_conversion
, "conversion to %qT from %qT "
2615 "may change the sign of the result",
2619 /* Warn for integer types converted to real types if and only if
2620 all the range of values of the integer type cannot be
2621 represented by the real type. */
2622 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2623 && TREE_CODE (type
) == REAL_TYPE
)
2625 /* Don't warn about char y = 0xff; float x = (int) y; */
2626 expr
= get_unwidened (expr
, 0);
2627 expr_type
= TREE_TYPE (expr
);
2629 if (!int_safely_convertible_to_real_p (expr_type
, type
))
2630 give_warning
= UNSAFE_OTHER
;
2633 /* Warn for real types converted to smaller real types. */
2634 else if (TREE_CODE (expr_type
) == REAL_TYPE
2635 && TREE_CODE (type
) == REAL_TYPE
2636 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2637 give_warning
= UNSAFE_REAL
;
2639 /* Check conversion between two complex types. */
2640 else if (TREE_CODE (expr_type
) == COMPLEX_TYPE
2641 && TREE_CODE (type
) == COMPLEX_TYPE
)
2643 /* Extract underlying types (i.e., type of real and imaginary
2644 parts) of expr_type and type. */
2645 tree from_type
= TREE_TYPE (expr_type
);
2646 tree to_type
= TREE_TYPE (type
);
2648 /* Warn for real types converted to integer types. */
2649 if (TREE_CODE (from_type
) == REAL_TYPE
2650 && TREE_CODE (to_type
) == INTEGER_TYPE
)
2651 give_warning
= UNSAFE_REAL
;
2653 /* Warn for real types converted to smaller real types. */
2654 else if (TREE_CODE (from_type
) == REAL_TYPE
2655 && TREE_CODE (to_type
) == REAL_TYPE
2656 && TYPE_PRECISION (to_type
) < TYPE_PRECISION (from_type
))
2657 give_warning
= UNSAFE_REAL
;
2659 /* Check conversion for complex integer types. Here implementation
2660 is simpler than for real-domain integers because it does not
2661 involve sophisticated cases, such as bitmasks, casts, etc. */
2662 else if (TREE_CODE (from_type
) == INTEGER_TYPE
2663 && TREE_CODE (to_type
) == INTEGER_TYPE
)
2665 /* Warn for integer types converted to smaller integer types. */
2666 if (TYPE_PRECISION (to_type
) < TYPE_PRECISION (from_type
))
2667 give_warning
= UNSAFE_OTHER
;
2669 /* Check for different signedness, see case for real-domain
2670 integers (above) for a more detailed comment. */
2671 else if (((TYPE_PRECISION (to_type
) == TYPE_PRECISION (from_type
)
2672 && TYPE_UNSIGNED (to_type
) != TYPE_UNSIGNED (from_type
))
2673 || (TYPE_UNSIGNED (to_type
) && !TYPE_UNSIGNED (from_type
)))
2675 warning_at (loc
, OPT_Wsign_conversion
,
2676 "conversion to %qT from %qT "
2677 "may change the sign of the result",
2680 else if (TREE_CODE (from_type
) == INTEGER_TYPE
2681 && TREE_CODE (to_type
) == REAL_TYPE
2682 && !int_safely_convertible_to_real_p (from_type
, to_type
))
2683 give_warning
= UNSAFE_OTHER
;
2686 /* Warn for complex types converted to real or integer types. */
2687 else if (TREE_CODE (expr_type
) == COMPLEX_TYPE
2688 && TREE_CODE (type
) != COMPLEX_TYPE
)
2689 give_warning
= UNSAFE_IMAGINARY
;
2692 return give_warning
;
2695 /* Warns if the conversion of EXPR to TYPE may alter a value.
2696 This is a helper function for warnings_for_convert_and_check. */
2699 conversion_warning (location_t loc
, tree type
, tree expr
)
2701 tree expr_type
= TREE_TYPE (expr
);
2702 enum conversion_safety conversion_kind
;
2704 if (!warn_conversion
&& !warn_sign_conversion
&& !warn_float_conversion
)
2707 /* This may happen, because for LHS op= RHS we preevaluate
2708 RHS and create C_MAYBE_CONST_EXPR <SAVE_EXPR <RHS>>, which
2709 means we could no longer see the code of the EXPR. */
2710 if (TREE_CODE (expr
) == C_MAYBE_CONST_EXPR
)
2711 expr
= C_MAYBE_CONST_EXPR_EXPR (expr
);
2712 if (TREE_CODE (expr
) == SAVE_EXPR
)
2713 expr
= TREE_OPERAND (expr
, 0);
2715 switch (TREE_CODE (expr
))
2723 case TRUTH_ANDIF_EXPR
:
2724 case TRUTH_ORIF_EXPR
:
2725 case TRUTH_AND_EXPR
:
2727 case TRUTH_XOR_EXPR
:
2728 case TRUTH_NOT_EXPR
:
2729 /* Conversion from boolean to a signed:1 bit-field (which only
2730 can hold the values 0 and -1) doesn't lose information - but
2731 it does change the value. */
2732 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
2733 warning_at (loc
, OPT_Wconversion
,
2734 "conversion to %qT from boolean expression", type
);
2740 conversion_kind
= unsafe_conversion_p (loc
, type
, expr
, true);
2741 if (conversion_kind
== UNSAFE_REAL
)
2742 warning_at (loc
, OPT_Wfloat_conversion
,
2743 "conversion to %qT alters %qT constant value",
2745 else if (conversion_kind
)
2746 warning_at (loc
, OPT_Wconversion
,
2747 "conversion to %qT alters %qT constant value",
2753 /* In case of COND_EXPR, we do not care about the type of
2754 COND_EXPR, only about the conversion of each operand. */
2755 tree op1
= TREE_OPERAND (expr
, 1);
2756 tree op2
= TREE_OPERAND (expr
, 2);
2758 conversion_warning (loc
, type
, op1
);
2759 conversion_warning (loc
, type
, op2
);
2763 default: /* 'expr' is not a constant. */
2764 conversion_kind
= unsafe_conversion_p (loc
, type
, expr
, true);
2765 if (conversion_kind
== UNSAFE_REAL
)
2766 warning_at (loc
, OPT_Wfloat_conversion
,
2767 "conversion to %qT from %qT may alter its value",
2769 else if (conversion_kind
== UNSAFE_IMAGINARY
)
2770 warning_at (loc
, OPT_Wconversion
,
2771 "conversion to %qT from %qT discards imaginary component",
2773 else if (conversion_kind
)
2774 warning_at (loc
, OPT_Wconversion
,
2775 "conversion to %qT from %qT may alter its value",
2780 /* Produce warnings after a conversion. RESULT is the result of
2781 converting EXPR to TYPE. This is a helper function for
2782 convert_and_check and cp_convert_and_check. */
2785 warnings_for_convert_and_check (location_t loc
, tree type
, tree expr
,
2788 loc
= expansion_point_location_if_in_system_header (loc
);
2790 if (TREE_CODE (expr
) == INTEGER_CST
2791 && (TREE_CODE (type
) == INTEGER_TYPE
2792 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2793 && !int_fits_type_p (expr
, type
))
2795 /* Do not diagnose overflow in a constant expression merely
2796 because a conversion overflowed. */
2797 if (TREE_OVERFLOW (result
))
2798 TREE_OVERFLOW (result
) = TREE_OVERFLOW (expr
);
2800 if (TYPE_UNSIGNED (type
))
2802 /* This detects cases like converting -129 or 256 to
2804 if (!int_fits_type_p (expr
, c_common_signed_type (type
)))
2805 warning_at (loc
, OPT_Woverflow
,
2806 "large integer implicitly truncated to unsigned type");
2808 conversion_warning (loc
, type
, expr
);
2810 else if (!int_fits_type_p (expr
, c_common_unsigned_type (type
)))
2811 warning_at (loc
, OPT_Woverflow
,
2812 "overflow in implicit constant conversion");
2813 /* No warning for converting 0x80000000 to int. */
2815 && (TREE_CODE (TREE_TYPE (expr
)) != INTEGER_TYPE
2816 || TYPE_PRECISION (TREE_TYPE (expr
))
2817 != TYPE_PRECISION (type
)))
2818 warning_at (loc
, OPT_Woverflow
,
2819 "overflow in implicit constant conversion");
2822 conversion_warning (loc
, type
, expr
);
2824 else if ((TREE_CODE (result
) == INTEGER_CST
2825 || TREE_CODE (result
) == FIXED_CST
) && TREE_OVERFLOW (result
))
2826 warning_at (loc
, OPT_Woverflow
,
2827 "overflow in implicit constant conversion");
2829 conversion_warning (loc
, type
, expr
);
2833 /* Convert EXPR to TYPE, warning about conversion problems with constants.
2834 Invoke this function on every expression that is converted implicitly,
2835 i.e. because of language rules and not because of an explicit cast. */
2838 convert_and_check (location_t loc
, tree type
, tree expr
)
2841 tree expr_for_warning
;
2843 /* Convert from a value with possible excess precision rather than
2844 via the semantic type, but do not warn about values not fitting
2845 exactly in the semantic type. */
2846 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
2848 tree orig_type
= TREE_TYPE (expr
);
2849 expr
= TREE_OPERAND (expr
, 0);
2850 expr_for_warning
= convert (orig_type
, expr
);
2851 if (orig_type
== type
)
2852 return expr_for_warning
;
2855 expr_for_warning
= expr
;
2857 if (TREE_TYPE (expr
) == type
)
2860 result
= convert (type
, expr
);
2862 if (c_inhibit_evaluation_warnings
== 0
2863 && !TREE_OVERFLOW_P (expr
)
2864 && result
!= error_mark_node
)
2865 warnings_for_convert_and_check (loc
, type
, expr_for_warning
, result
);
2870 /* A node in a list that describes references to variables (EXPR), which are
2871 either read accesses if WRITER is zero, or write accesses, in which case
2872 WRITER is the parent of EXPR. */
2879 /* Used to implement a cache the results of a call to verify_tree. We only
2880 use this for SAVE_EXPRs. */
2883 struct tlist_cache
*next
;
2884 struct tlist
*cache_before_sp
;
2885 struct tlist
*cache_after_sp
;
2889 /* Obstack to use when allocating tlist structures, and corresponding
2891 static struct obstack tlist_obstack
;
2892 static char *tlist_firstobj
= 0;
2894 /* Keep track of the identifiers we've warned about, so we can avoid duplicate
2896 static struct tlist
*warned_ids
;
2897 /* SAVE_EXPRs need special treatment. We process them only once and then
2898 cache the results. */
2899 static struct tlist_cache
*save_expr_cache
;
2901 static void add_tlist (struct tlist
**, struct tlist
*, tree
, int);
2902 static void merge_tlist (struct tlist
**, struct tlist
*, int);
2903 static void verify_tree (tree
, struct tlist
**, struct tlist
**, tree
);
2904 static int warning_candidate_p (tree
);
2905 static bool candidate_equal_p (const_tree
, const_tree
);
2906 static void warn_for_collisions (struct tlist
*);
2907 static void warn_for_collisions_1 (tree
, tree
, struct tlist
*, int);
2908 static struct tlist
*new_tlist (struct tlist
*, tree
, tree
);
2910 /* Create a new struct tlist and fill in its fields. */
2911 static struct tlist
*
2912 new_tlist (struct tlist
*next
, tree t
, tree writer
)
2915 l
= XOBNEW (&tlist_obstack
, struct tlist
);
2922 /* Add duplicates of the nodes found in ADD to the list *TO. If EXCLUDE_WRITER
2923 is nonnull, we ignore any node we find which has a writer equal to it. */
2926 add_tlist (struct tlist
**to
, struct tlist
*add
, tree exclude_writer
, int copy
)
2930 struct tlist
*next
= add
->next
;
2933 if (!exclude_writer
|| !candidate_equal_p (add
->writer
, exclude_writer
))
2934 *to
= copy
? new_tlist (*to
, add
->expr
, add
->writer
) : add
;
2939 /* Merge the nodes of ADD into TO. This merging process is done so that for
2940 each variable that already exists in TO, no new node is added; however if
2941 there is a write access recorded in ADD, and an occurrence on TO is only
2942 a read access, then the occurrence in TO will be modified to record the
2946 merge_tlist (struct tlist
**to
, struct tlist
*add
, int copy
)
2948 struct tlist
**end
= to
;
2951 end
= &(*end
)->next
;
2957 struct tlist
*next
= add
->next
;
2959 for (tmp2
= *to
; tmp2
; tmp2
= tmp2
->next
)
2960 if (candidate_equal_p (tmp2
->expr
, add
->expr
))
2964 tmp2
->writer
= add
->writer
;
2968 *end
= copy
? new_tlist (NULL
, add
->expr
, add
->writer
) : add
;
2969 end
= &(*end
)->next
;
2976 /* WRITTEN is a variable, WRITER is its parent. Warn if any of the variable
2977 references in list LIST conflict with it, excluding reads if ONLY writers
2981 warn_for_collisions_1 (tree written
, tree writer
, struct tlist
*list
,
2986 /* Avoid duplicate warnings. */
2987 for (tmp
= warned_ids
; tmp
; tmp
= tmp
->next
)
2988 if (candidate_equal_p (tmp
->expr
, written
))
2993 if (candidate_equal_p (list
->expr
, written
)
2994 && !candidate_equal_p (list
->writer
, writer
)
2995 && (!only_writes
|| list
->writer
))
2997 warned_ids
= new_tlist (warned_ids
, written
, NULL_TREE
);
2998 warning_at (EXPR_LOC_OR_LOC (writer
, input_location
),
2999 OPT_Wsequence_point
, "operation on %qE may be undefined",
3006 /* Given a list LIST of references to variables, find whether any of these
3007 can cause conflicts due to missing sequence points. */
3010 warn_for_collisions (struct tlist
*list
)
3014 for (tmp
= list
; tmp
; tmp
= tmp
->next
)
3017 warn_for_collisions_1 (tmp
->expr
, tmp
->writer
, list
, 0);
3021 /* Return nonzero if X is a tree that can be verified by the sequence point
3024 warning_candidate_p (tree x
)
3026 if (DECL_P (x
) && DECL_ARTIFICIAL (x
))
3029 if (TREE_CODE (x
) == BLOCK
)
3032 /* VOID_TYPE_P (TREE_TYPE (x)) is workaround for cp/tree.c
3033 (lvalue_p) crash on TRY/CATCH. */
3034 if (TREE_TYPE (x
) == NULL_TREE
|| VOID_TYPE_P (TREE_TYPE (x
)))
3040 /* No point to track non-const calls, they will never satisfy
3042 if (TREE_CODE (x
) == CALL_EXPR
&& (call_expr_flags (x
) & ECF_CONST
) == 0)
3045 if (TREE_CODE (x
) == STRING_CST
)
3051 /* Return nonzero if X and Y appear to be the same candidate (or NULL) */
3053 candidate_equal_p (const_tree x
, const_tree y
)
3055 return (x
== y
) || (x
&& y
&& operand_equal_p (x
, y
, 0));
3058 /* Walk the tree X, and record accesses to variables. If X is written by the
3059 parent tree, WRITER is the parent.
3060 We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP. If this
3061 expression or its only operand forces a sequence point, then everything up
3062 to the sequence point is stored in PBEFORE_SP. Everything else gets stored
3064 Once we return, we will have emitted warnings if any subexpression before
3065 such a sequence point could be undefined. On a higher level, however, the
3066 sequence point may not be relevant, and we'll merge the two lists.
3068 Example: (b++, a) + b;
3069 The call that processes the COMPOUND_EXPR will store the increment of B
3070 in PBEFORE_SP, and the use of A in PNO_SP. The higher-level call that
3071 processes the PLUS_EXPR will need to merge the two lists so that
3072 eventually, all accesses end up on the same list (and we'll warn about the
3073 unordered subexpressions b++ and b.
3075 A note on merging. If we modify the former example so that our expression
3078 care must be taken not simply to add all three expressions into the final
3079 PNO_SP list. The function merge_tlist takes care of that by merging the
3080 before-SP list of the COMPOUND_EXPR into its after-SP list in a special
3081 way, so that no more than one access to B is recorded. */
3084 verify_tree (tree x
, struct tlist
**pbefore_sp
, struct tlist
**pno_sp
,
3087 struct tlist
*tmp_before
, *tmp_nosp
, *tmp_list2
, *tmp_list3
;
3088 enum tree_code code
;
3089 enum tree_code_class cl
;
3091 /* X may be NULL if it is the operand of an empty statement expression
3097 code
= TREE_CODE (x
);
3098 cl
= TREE_CODE_CLASS (code
);
3100 if (warning_candidate_p (x
))
3101 *pno_sp
= new_tlist (*pno_sp
, x
, writer
);
3110 case TRUTH_ANDIF_EXPR
:
3111 case TRUTH_ORIF_EXPR
:
3112 tmp_before
= tmp_nosp
= tmp_list2
= tmp_list3
= 0;
3113 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3114 warn_for_collisions (tmp_nosp
);
3115 merge_tlist (pbefore_sp
, tmp_before
, 0);
3116 merge_tlist (pbefore_sp
, tmp_nosp
, 0);
3117 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, &tmp_list2
, NULL_TREE
);
3118 warn_for_collisions (tmp_list2
);
3119 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3120 merge_tlist (pno_sp
, tmp_list2
, 0);
3124 tmp_before
= tmp_list2
= 0;
3125 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_list2
, NULL_TREE
);
3126 warn_for_collisions (tmp_list2
);
3127 merge_tlist (pbefore_sp
, tmp_before
, 0);
3128 merge_tlist (pbefore_sp
, tmp_list2
, 0);
3130 tmp_list3
= tmp_nosp
= 0;
3131 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, &tmp_nosp
, NULL_TREE
);
3132 warn_for_collisions (tmp_nosp
);
3133 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3135 tmp_list3
= tmp_list2
= 0;
3136 verify_tree (TREE_OPERAND (x
, 2), &tmp_list3
, &tmp_list2
, NULL_TREE
);
3137 warn_for_collisions (tmp_list2
);
3138 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3139 /* Rather than add both tmp_nosp and tmp_list2, we have to merge the
3140 two first, to avoid warning for (a ? b++ : b++). */
3141 merge_tlist (&tmp_nosp
, tmp_list2
, 0);
3142 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3145 case PREDECREMENT_EXPR
:
3146 case PREINCREMENT_EXPR
:
3147 case POSTDECREMENT_EXPR
:
3148 case POSTINCREMENT_EXPR
:
3149 verify_tree (TREE_OPERAND (x
, 0), pno_sp
, pno_sp
, x
);
3153 tmp_before
= tmp_nosp
= tmp_list3
= 0;
3154 verify_tree (TREE_OPERAND (x
, 1), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3155 verify_tree (TREE_OPERAND (x
, 0), &tmp_list3
, &tmp_list3
, x
);
3156 /* Expressions inside the LHS are not ordered wrt. the sequence points
3157 in the RHS. Example:
3159 Despite the fact that the modification of "a" is in the before_sp
3160 list (tmp_before), it conflicts with the use of "a" in the LHS.
3161 We can handle this by adding the contents of tmp_list3
3162 to those of tmp_before, and redoing the collision warnings for that
3164 add_tlist (&tmp_before
, tmp_list3
, x
, 1);
3165 warn_for_collisions (tmp_before
);
3166 /* Exclude the LHS itself here; we first have to merge it into the
3167 tmp_nosp list. This is done to avoid warning for "a = a"; if we
3168 didn't exclude the LHS, we'd get it twice, once as a read and once
3170 add_tlist (pno_sp
, tmp_list3
, x
, 0);
3171 warn_for_collisions_1 (TREE_OPERAND (x
, 0), x
, tmp_nosp
, 1);
3173 merge_tlist (pbefore_sp
, tmp_before
, 0);
3174 if (warning_candidate_p (TREE_OPERAND (x
, 0)))
3175 merge_tlist (&tmp_nosp
, new_tlist (NULL
, TREE_OPERAND (x
, 0), x
), 0);
3176 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 1);
3180 /* We need to warn about conflicts among arguments and conflicts between
3181 args and the function address. Side effects of the function address,
3182 however, are not ordered by the sequence point of the call. */
3184 call_expr_arg_iterator iter
;
3186 tmp_before
= tmp_nosp
= 0;
3187 verify_tree (CALL_EXPR_FN (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3188 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, x
)
3190 tmp_list2
= tmp_list3
= 0;
3191 verify_tree (arg
, &tmp_list2
, &tmp_list3
, NULL_TREE
);
3192 merge_tlist (&tmp_list3
, tmp_list2
, 0);
3193 add_tlist (&tmp_before
, tmp_list3
, NULL_TREE
, 0);
3195 add_tlist (&tmp_before
, tmp_nosp
, NULL_TREE
, 0);
3196 warn_for_collisions (tmp_before
);
3197 add_tlist (pbefore_sp
, tmp_before
, NULL_TREE
, 0);
3202 /* Scan all the list, e.g. indices of multi dimensional array. */
3205 tmp_before
= tmp_nosp
= 0;
3206 verify_tree (TREE_VALUE (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3207 merge_tlist (&tmp_nosp
, tmp_before
, 0);
3208 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3215 struct tlist_cache
*t
;
3216 for (t
= save_expr_cache
; t
; t
= t
->next
)
3217 if (candidate_equal_p (t
->expr
, x
))
3222 t
= XOBNEW (&tlist_obstack
, struct tlist_cache
);
3223 t
->next
= save_expr_cache
;
3225 save_expr_cache
= t
;
3227 tmp_before
= tmp_nosp
= 0;
3228 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3229 warn_for_collisions (tmp_nosp
);
3232 merge_tlist (&tmp_list3
, tmp_nosp
, 0);
3233 t
->cache_before_sp
= tmp_before
;
3234 t
->cache_after_sp
= tmp_list3
;
3236 merge_tlist (pbefore_sp
, t
->cache_before_sp
, 1);
3237 add_tlist (pno_sp
, t
->cache_after_sp
, NULL_TREE
, 1);
3242 x
= TREE_OPERAND (x
, 0);
3249 /* For other expressions, simply recurse on their operands.
3250 Manual tail recursion for unary expressions.
3251 Other non-expressions need not be processed. */
3252 if (cl
== tcc_unary
)
3254 x
= TREE_OPERAND (x
, 0);
3258 else if (IS_EXPR_CODE_CLASS (cl
))
3261 int max
= TREE_OPERAND_LENGTH (x
);
3262 for (lp
= 0; lp
< max
; lp
++)
3264 tmp_before
= tmp_nosp
= 0;
3265 verify_tree (TREE_OPERAND (x
, lp
), &tmp_before
, &tmp_nosp
, 0);
3266 merge_tlist (&tmp_nosp
, tmp_before
, 0);
3267 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3274 /* Try to warn for undefined behavior in EXPR due to missing sequence
3278 verify_sequence_points (tree expr
)
3280 struct tlist
*before_sp
= 0, *after_sp
= 0;
3283 save_expr_cache
= 0;
3284 if (tlist_firstobj
== 0)
3286 gcc_obstack_init (&tlist_obstack
);
3287 tlist_firstobj
= (char *) obstack_alloc (&tlist_obstack
, 0);
3290 verify_tree (expr
, &before_sp
, &after_sp
, 0);
3291 warn_for_collisions (after_sp
);
3292 obstack_free (&tlist_obstack
, tlist_firstobj
);
3295 /* Validate the expression after `case' and apply default promotions. */
3298 check_case_value (location_t loc
, tree value
)
3300 if (value
== NULL_TREE
)
3303 if (TREE_CODE (value
) == INTEGER_CST
)
3304 /* Promote char or short to int. */
3305 value
= perform_integral_promotions (value
);
3306 else if (value
!= error_mark_node
)
3308 error_at (loc
, "case label does not reduce to an integer constant");
3309 value
= error_mark_node
;
3312 constant_expression_warning (value
);
3317 /* See if the case values LOW and HIGH are in the range of the original
3318 type (i.e. before the default conversion to int) of the switch testing
3320 TYPE is the promoted type of the testing expression, and ORIG_TYPE is
3321 the type before promoting it. CASE_LOW_P is a pointer to the lower
3322 bound of the case label, and CASE_HIGH_P is the upper bound or NULL
3323 if the case is not a case range.
3324 The caller has to make sure that we are not called with NULL for
3325 CASE_LOW_P (i.e. the default case). OUTSIDE_RANGE_P says whether there
3326 was a case value that doesn't fit into the range of the ORIG_TYPE.
3327 Returns true if the case label is in range of ORIG_TYPE (saturated or
3328 untouched) or false if the label is out of range. */
3331 check_case_bounds (location_t loc
, tree type
, tree orig_type
,
3332 tree
*case_low_p
, tree
*case_high_p
,
3333 bool *outside_range_p
)
3335 tree min_value
, max_value
;
3336 tree case_low
= *case_low_p
;
3337 tree case_high
= case_high_p
? *case_high_p
: case_low
;
3339 /* If there was a problem with the original type, do nothing. */
3340 if (orig_type
== error_mark_node
)
3343 min_value
= TYPE_MIN_VALUE (orig_type
);
3344 max_value
= TYPE_MAX_VALUE (orig_type
);
3346 /* We'll really need integer constants here. */
3347 case_low
= fold (case_low
);
3348 case_high
= fold (case_high
);
3350 /* Case label is less than minimum for type. */
3351 if (tree_int_cst_compare (case_low
, min_value
) < 0
3352 && tree_int_cst_compare (case_high
, min_value
) < 0)
3354 warning_at (loc
, 0, "case label value is less than minimum value "
3356 *outside_range_p
= true;
3360 /* Case value is greater than maximum for type. */
3361 if (tree_int_cst_compare (case_low
, max_value
) > 0
3362 && tree_int_cst_compare (case_high
, max_value
) > 0)
3364 warning_at (loc
, 0, "case label value exceeds maximum value for type");
3365 *outside_range_p
= true;
3369 /* Saturate lower case label value to minimum. */
3370 if (tree_int_cst_compare (case_high
, min_value
) >= 0
3371 && tree_int_cst_compare (case_low
, min_value
) < 0)
3373 warning_at (loc
, 0, "lower value in case label range"
3374 " less than minimum value for type");
3375 *outside_range_p
= true;
3376 case_low
= min_value
;
3379 /* Saturate upper case label value to maximum. */
3380 if (tree_int_cst_compare (case_low
, max_value
) <= 0
3381 && tree_int_cst_compare (case_high
, max_value
) > 0)
3383 warning_at (loc
, 0, "upper value in case label range"
3384 " exceeds maximum value for type");
3385 *outside_range_p
= true;
3386 case_high
= max_value
;
3389 if (*case_low_p
!= case_low
)
3390 *case_low_p
= convert (type
, case_low
);
3391 if (case_high_p
&& *case_high_p
!= case_high
)
3392 *case_high_p
= convert (type
, case_high
);
3397 /* Return an integer type with BITS bits of precision,
3398 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
3401 c_common_type_for_size (unsigned int bits
, int unsignedp
)
3405 if (bits
== TYPE_PRECISION (integer_type_node
))
3406 return unsignedp
? unsigned_type_node
: integer_type_node
;
3408 if (bits
== TYPE_PRECISION (signed_char_type_node
))
3409 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3411 if (bits
== TYPE_PRECISION (short_integer_type_node
))
3412 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3414 if (bits
== TYPE_PRECISION (long_integer_type_node
))
3415 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3417 if (bits
== TYPE_PRECISION (long_long_integer_type_node
))
3418 return (unsignedp
? long_long_unsigned_type_node
3419 : long_long_integer_type_node
);
3421 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
3422 if (int_n_enabled_p
[i
]
3423 && bits
== int_n_data
[i
].bitsize
)
3424 return (unsignedp
? int_n_trees
[i
].unsigned_type
3425 : int_n_trees
[i
].signed_type
);
3427 if (bits
== TYPE_PRECISION (widest_integer_literal_type_node
))
3428 return (unsignedp
? widest_unsigned_literal_type_node
3429 : widest_integer_literal_type_node
);
3431 if (bits
<= TYPE_PRECISION (intQI_type_node
))
3432 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3434 if (bits
<= TYPE_PRECISION (intHI_type_node
))
3435 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3437 if (bits
<= TYPE_PRECISION (intSI_type_node
))
3438 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3440 if (bits
<= TYPE_PRECISION (intDI_type_node
))
3441 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3446 /* Return a fixed-point type that has at least IBIT ibits and FBIT fbits
3447 that is unsigned if UNSIGNEDP is nonzero, otherwise signed;
3448 and saturating if SATP is nonzero, otherwise not saturating. */
3451 c_common_fixed_point_type_for_size (unsigned int ibit
, unsigned int fbit
,
3452 int unsignedp
, int satp
)
3456 mode
= unsignedp
? UQQmode
: QQmode
;
3458 mode
= unsignedp
? UHAmode
: HAmode
;
3460 for (; mode
!= VOIDmode
; mode
= GET_MODE_WIDER_MODE (mode
))
3461 if (GET_MODE_IBIT (mode
) >= ibit
&& GET_MODE_FBIT (mode
) >= fbit
)
3464 if (mode
== VOIDmode
|| !targetm
.scalar_mode_supported_p (mode
))
3466 sorry ("GCC cannot support operators with integer types and "
3467 "fixed-point types that have too many integral and "
3468 "fractional bits together");
3472 return c_common_type_for_mode (mode
, satp
);
3475 /* Used for communication between c_common_type_for_mode and
3476 c_register_builtin_type. */
3477 tree registered_builtin_types
;
3479 /* Return a data type that has machine mode MODE.
3480 If the mode is an integer,
3481 then UNSIGNEDP selects between signed and unsigned types.
3482 If the mode is a fixed-point mode,
3483 then UNSIGNEDP selects between saturating and nonsaturating types. */
3486 c_common_type_for_mode (machine_mode mode
, int unsignedp
)
3491 if (mode
== TYPE_MODE (integer_type_node
))
3492 return unsignedp
? unsigned_type_node
: integer_type_node
;
3494 if (mode
== TYPE_MODE (signed_char_type_node
))
3495 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3497 if (mode
== TYPE_MODE (short_integer_type_node
))
3498 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3500 if (mode
== TYPE_MODE (long_integer_type_node
))
3501 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3503 if (mode
== TYPE_MODE (long_long_integer_type_node
))
3504 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3506 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
3507 if (int_n_enabled_p
[i
]
3508 && mode
== int_n_data
[i
].m
)
3509 return (unsignedp
? int_n_trees
[i
].unsigned_type
3510 : int_n_trees
[i
].signed_type
);
3512 if (mode
== TYPE_MODE (widest_integer_literal_type_node
))
3513 return unsignedp
? widest_unsigned_literal_type_node
3514 : widest_integer_literal_type_node
;
3517 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3520 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3523 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3526 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3528 #if HOST_BITS_PER_WIDE_INT >= 64
3529 if (mode
== TYPE_MODE (intTI_type_node
))
3530 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3533 if (mode
== TYPE_MODE (float_type_node
))
3534 return float_type_node
;
3536 if (mode
== TYPE_MODE (double_type_node
))
3537 return double_type_node
;
3539 if (mode
== TYPE_MODE (long_double_type_node
))
3540 return long_double_type_node
;
3542 for (i
= 0; i
< NUM_FLOATN_NX_TYPES
; i
++)
3543 if (FLOATN_NX_TYPE_NODE (i
) != NULL_TREE
3544 && mode
== TYPE_MODE (FLOATN_NX_TYPE_NODE (i
)))
3545 return FLOATN_NX_TYPE_NODE (i
);
3547 if (mode
== TYPE_MODE (void_type_node
))
3548 return void_type_node
;
3550 if (mode
== TYPE_MODE (build_pointer_type (char_type_node
)))
3552 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3553 : make_signed_type (GET_MODE_PRECISION (mode
)));
3555 if (mode
== TYPE_MODE (build_pointer_type (integer_type_node
)))
3557 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3558 : make_signed_type (GET_MODE_PRECISION (mode
)));
3560 if (COMPLEX_MODE_P (mode
))
3562 machine_mode inner_mode
;
3565 if (mode
== TYPE_MODE (complex_float_type_node
))
3566 return complex_float_type_node
;
3567 if (mode
== TYPE_MODE (complex_double_type_node
))
3568 return complex_double_type_node
;
3569 if (mode
== TYPE_MODE (complex_long_double_type_node
))
3570 return complex_long_double_type_node
;
3572 for (i
= 0; i
< NUM_FLOATN_NX_TYPES
; i
++)
3573 if (COMPLEX_FLOATN_NX_TYPE_NODE (i
) != NULL_TREE
3574 && mode
== TYPE_MODE (COMPLEX_FLOATN_NX_TYPE_NODE (i
)))
3575 return COMPLEX_FLOATN_NX_TYPE_NODE (i
);
3577 if (mode
== TYPE_MODE (complex_integer_type_node
) && !unsignedp
)
3578 return complex_integer_type_node
;
3580 inner_mode
= GET_MODE_INNER (mode
);
3581 inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3582 if (inner_type
!= NULL_TREE
)
3583 return build_complex_type (inner_type
);
3585 else if (VECTOR_MODE_P (mode
))
3587 machine_mode inner_mode
= GET_MODE_INNER (mode
);
3588 tree inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3589 if (inner_type
!= NULL_TREE
)
3590 return build_vector_type_for_mode (inner_type
, mode
);
3593 if (mode
== TYPE_MODE (dfloat32_type_node
))
3594 return dfloat32_type_node
;
3595 if (mode
== TYPE_MODE (dfloat64_type_node
))
3596 return dfloat64_type_node
;
3597 if (mode
== TYPE_MODE (dfloat128_type_node
))
3598 return dfloat128_type_node
;
3600 if (ALL_SCALAR_FIXED_POINT_MODE_P (mode
))
3602 if (mode
== TYPE_MODE (short_fract_type_node
))
3603 return unsignedp
? sat_short_fract_type_node
: short_fract_type_node
;
3604 if (mode
== TYPE_MODE (fract_type_node
))
3605 return unsignedp
? sat_fract_type_node
: fract_type_node
;
3606 if (mode
== TYPE_MODE (long_fract_type_node
))
3607 return unsignedp
? sat_long_fract_type_node
: long_fract_type_node
;
3608 if (mode
== TYPE_MODE (long_long_fract_type_node
))
3609 return unsignedp
? sat_long_long_fract_type_node
3610 : long_long_fract_type_node
;
3612 if (mode
== TYPE_MODE (unsigned_short_fract_type_node
))
3613 return unsignedp
? sat_unsigned_short_fract_type_node
3614 : unsigned_short_fract_type_node
;
3615 if (mode
== TYPE_MODE (unsigned_fract_type_node
))
3616 return unsignedp
? sat_unsigned_fract_type_node
3617 : unsigned_fract_type_node
;
3618 if (mode
== TYPE_MODE (unsigned_long_fract_type_node
))
3619 return unsignedp
? sat_unsigned_long_fract_type_node
3620 : unsigned_long_fract_type_node
;
3621 if (mode
== TYPE_MODE (unsigned_long_long_fract_type_node
))
3622 return unsignedp
? sat_unsigned_long_long_fract_type_node
3623 : unsigned_long_long_fract_type_node
;
3625 if (mode
== TYPE_MODE (short_accum_type_node
))
3626 return unsignedp
? sat_short_accum_type_node
: short_accum_type_node
;
3627 if (mode
== TYPE_MODE (accum_type_node
))
3628 return unsignedp
? sat_accum_type_node
: accum_type_node
;
3629 if (mode
== TYPE_MODE (long_accum_type_node
))
3630 return unsignedp
? sat_long_accum_type_node
: long_accum_type_node
;
3631 if (mode
== TYPE_MODE (long_long_accum_type_node
))
3632 return unsignedp
? sat_long_long_accum_type_node
3633 : long_long_accum_type_node
;
3635 if (mode
== TYPE_MODE (unsigned_short_accum_type_node
))
3636 return unsignedp
? sat_unsigned_short_accum_type_node
3637 : unsigned_short_accum_type_node
;
3638 if (mode
== TYPE_MODE (unsigned_accum_type_node
))
3639 return unsignedp
? sat_unsigned_accum_type_node
3640 : unsigned_accum_type_node
;
3641 if (mode
== TYPE_MODE (unsigned_long_accum_type_node
))
3642 return unsignedp
? sat_unsigned_long_accum_type_node
3643 : unsigned_long_accum_type_node
;
3644 if (mode
== TYPE_MODE (unsigned_long_long_accum_type_node
))
3645 return unsignedp
? sat_unsigned_long_long_accum_type_node
3646 : unsigned_long_long_accum_type_node
;
3649 return unsignedp
? sat_qq_type_node
: qq_type_node
;
3651 return unsignedp
? sat_hq_type_node
: hq_type_node
;
3653 return unsignedp
? sat_sq_type_node
: sq_type_node
;
3655 return unsignedp
? sat_dq_type_node
: dq_type_node
;
3657 return unsignedp
? sat_tq_type_node
: tq_type_node
;
3659 if (mode
== UQQmode
)
3660 return unsignedp
? sat_uqq_type_node
: uqq_type_node
;
3661 if (mode
== UHQmode
)
3662 return unsignedp
? sat_uhq_type_node
: uhq_type_node
;
3663 if (mode
== USQmode
)
3664 return unsignedp
? sat_usq_type_node
: usq_type_node
;
3665 if (mode
== UDQmode
)
3666 return unsignedp
? sat_udq_type_node
: udq_type_node
;
3667 if (mode
== UTQmode
)
3668 return unsignedp
? sat_utq_type_node
: utq_type_node
;
3671 return unsignedp
? sat_ha_type_node
: ha_type_node
;
3673 return unsignedp
? sat_sa_type_node
: sa_type_node
;
3675 return unsignedp
? sat_da_type_node
: da_type_node
;
3677 return unsignedp
? sat_ta_type_node
: ta_type_node
;
3679 if (mode
== UHAmode
)
3680 return unsignedp
? sat_uha_type_node
: uha_type_node
;
3681 if (mode
== USAmode
)
3682 return unsignedp
? sat_usa_type_node
: usa_type_node
;
3683 if (mode
== UDAmode
)
3684 return unsignedp
? sat_uda_type_node
: uda_type_node
;
3685 if (mode
== UTAmode
)
3686 return unsignedp
? sat_uta_type_node
: uta_type_node
;
3689 for (t
= registered_builtin_types
; t
; t
= TREE_CHAIN (t
))
3690 if (TYPE_MODE (TREE_VALUE (t
)) == mode
3691 && !!unsignedp
== !!TYPE_UNSIGNED (TREE_VALUE (t
)))
3692 return TREE_VALUE (t
);
3698 c_common_unsigned_type (tree type
)
3700 return c_common_signed_or_unsigned_type (1, type
);
3703 /* Return a signed type the same as TYPE in other respects. */
3706 c_common_signed_type (tree type
)
3708 return c_common_signed_or_unsigned_type (0, type
);
3711 /* Return a type the same as TYPE except unsigned or
3712 signed according to UNSIGNEDP. */
3715 c_common_signed_or_unsigned_type (int unsignedp
, tree type
)
3720 /* This block of code emulates the behavior of the old
3721 c_common_unsigned_type. In particular, it returns
3722 long_unsigned_type_node if passed a long, even when a int would
3723 have the same size. This is necessary for warnings to work
3724 correctly in archs where sizeof(int) == sizeof(long) */
3726 type1
= TYPE_MAIN_VARIANT (type
);
3727 if (type1
== signed_char_type_node
|| type1
== char_type_node
|| type1
== unsigned_char_type_node
)
3728 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3729 if (type1
== integer_type_node
|| type1
== unsigned_type_node
)
3730 return unsignedp
? unsigned_type_node
: integer_type_node
;
3731 if (type1
== short_integer_type_node
|| type1
== short_unsigned_type_node
)
3732 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3733 if (type1
== long_integer_type_node
|| type1
== long_unsigned_type_node
)
3734 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3735 if (type1
== long_long_integer_type_node
|| type1
== long_long_unsigned_type_node
)
3736 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3738 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
3739 if (int_n_enabled_p
[i
]
3740 && (type1
== int_n_trees
[i
].unsigned_type
3741 || type1
== int_n_trees
[i
].signed_type
))
3742 return (unsignedp
? int_n_trees
[i
].unsigned_type
3743 : int_n_trees
[i
].signed_type
);
3745 if (type1
== widest_integer_literal_type_node
|| type1
== widest_unsigned_literal_type_node
)
3746 return unsignedp
? widest_unsigned_literal_type_node
: widest_integer_literal_type_node
;
3747 #if HOST_BITS_PER_WIDE_INT >= 64
3748 if (type1
== intTI_type_node
|| type1
== unsigned_intTI_type_node
)
3749 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3751 if (type1
== intDI_type_node
|| type1
== unsigned_intDI_type_node
)
3752 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3753 if (type1
== intSI_type_node
|| type1
== unsigned_intSI_type_node
)
3754 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3755 if (type1
== intHI_type_node
|| type1
== unsigned_intHI_type_node
)
3756 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3757 if (type1
== intQI_type_node
|| type1
== unsigned_intQI_type_node
)
3758 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3760 #define C_COMMON_FIXED_TYPES(NAME) \
3761 if (type1 == short_ ## NAME ## _type_node \
3762 || type1 == unsigned_short_ ## NAME ## _type_node) \
3763 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
3764 : short_ ## NAME ## _type_node; \
3765 if (type1 == NAME ## _type_node \
3766 || type1 == unsigned_ ## NAME ## _type_node) \
3767 return unsignedp ? unsigned_ ## NAME ## _type_node \
3768 : NAME ## _type_node; \
3769 if (type1 == long_ ## NAME ## _type_node \
3770 || type1 == unsigned_long_ ## NAME ## _type_node) \
3771 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
3772 : long_ ## NAME ## _type_node; \
3773 if (type1 == long_long_ ## NAME ## _type_node \
3774 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
3775 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
3776 : long_long_ ## NAME ## _type_node;
3778 #define C_COMMON_FIXED_MODE_TYPES(NAME) \
3779 if (type1 == NAME ## _type_node \
3780 || type1 == u ## NAME ## _type_node) \
3781 return unsignedp ? u ## NAME ## _type_node \
3782 : NAME ## _type_node;
3784 #define C_COMMON_FIXED_TYPES_SAT(NAME) \
3785 if (type1 == sat_ ## short_ ## NAME ## _type_node \
3786 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
3787 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
3788 : sat_ ## short_ ## NAME ## _type_node; \
3789 if (type1 == sat_ ## NAME ## _type_node \
3790 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
3791 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
3792 : sat_ ## NAME ## _type_node; \
3793 if (type1 == sat_ ## long_ ## NAME ## _type_node \
3794 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
3795 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
3796 : sat_ ## long_ ## NAME ## _type_node; \
3797 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
3798 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
3799 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
3800 : sat_ ## long_long_ ## NAME ## _type_node;
3802 #define C_COMMON_FIXED_MODE_TYPES_SAT(NAME) \
3803 if (type1 == sat_ ## NAME ## _type_node \
3804 || type1 == sat_ ## u ## NAME ## _type_node) \
3805 return unsignedp ? sat_ ## u ## NAME ## _type_node \
3806 : sat_ ## NAME ## _type_node;
3808 C_COMMON_FIXED_TYPES (fract
);
3809 C_COMMON_FIXED_TYPES_SAT (fract
);
3810 C_COMMON_FIXED_TYPES (accum
);
3811 C_COMMON_FIXED_TYPES_SAT (accum
);
3813 C_COMMON_FIXED_MODE_TYPES (qq
);
3814 C_COMMON_FIXED_MODE_TYPES (hq
);
3815 C_COMMON_FIXED_MODE_TYPES (sq
);
3816 C_COMMON_FIXED_MODE_TYPES (dq
);
3817 C_COMMON_FIXED_MODE_TYPES (tq
);
3818 C_COMMON_FIXED_MODE_TYPES_SAT (qq
);
3819 C_COMMON_FIXED_MODE_TYPES_SAT (hq
);
3820 C_COMMON_FIXED_MODE_TYPES_SAT (sq
);
3821 C_COMMON_FIXED_MODE_TYPES_SAT (dq
);
3822 C_COMMON_FIXED_MODE_TYPES_SAT (tq
);
3823 C_COMMON_FIXED_MODE_TYPES (ha
);
3824 C_COMMON_FIXED_MODE_TYPES (sa
);
3825 C_COMMON_FIXED_MODE_TYPES (da
);
3826 C_COMMON_FIXED_MODE_TYPES (ta
);
3827 C_COMMON_FIXED_MODE_TYPES_SAT (ha
);
3828 C_COMMON_FIXED_MODE_TYPES_SAT (sa
);
3829 C_COMMON_FIXED_MODE_TYPES_SAT (da
);
3830 C_COMMON_FIXED_MODE_TYPES_SAT (ta
);
3832 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
3833 the precision; they have precision set to match their range, but
3834 may use a wider mode to match an ABI. If we change modes, we may
3835 wind up with bad conversions. For INTEGER_TYPEs in C, must check
3836 the precision as well, so as to yield correct results for
3837 bit-field types. C++ does not have these separate bit-field
3838 types, and producing a signed or unsigned variant of an
3839 ENUMERAL_TYPE may cause other problems as well. */
3841 if (!INTEGRAL_TYPE_P (type
)
3842 || TYPE_UNSIGNED (type
) == unsignedp
)
3845 #define TYPE_OK(node) \
3846 (TYPE_MODE (type) == TYPE_MODE (node) \
3847 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
3848 if (TYPE_OK (signed_char_type_node
))
3849 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3850 if (TYPE_OK (integer_type_node
))
3851 return unsignedp
? unsigned_type_node
: integer_type_node
;
3852 if (TYPE_OK (short_integer_type_node
))
3853 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3854 if (TYPE_OK (long_integer_type_node
))
3855 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3856 if (TYPE_OK (long_long_integer_type_node
))
3857 return (unsignedp
? long_long_unsigned_type_node
3858 : long_long_integer_type_node
);
3860 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
3861 if (int_n_enabled_p
[i
]
3862 && TYPE_MODE (type
) == int_n_data
[i
].m
3863 && TYPE_PRECISION (type
) == int_n_data
[i
].bitsize
)
3864 return (unsignedp
? int_n_trees
[i
].unsigned_type
3865 : int_n_trees
[i
].signed_type
);
3867 if (TYPE_OK (widest_integer_literal_type_node
))
3868 return (unsignedp
? widest_unsigned_literal_type_node
3869 : widest_integer_literal_type_node
);
3871 #if HOST_BITS_PER_WIDE_INT >= 64
3872 if (TYPE_OK (intTI_type_node
))
3873 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3875 if (TYPE_OK (intDI_type_node
))
3876 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3877 if (TYPE_OK (intSI_type_node
))
3878 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3879 if (TYPE_OK (intHI_type_node
))
3880 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3881 if (TYPE_OK (intQI_type_node
))
3882 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3885 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
3888 /* Build a bit-field integer type for the given WIDTH and UNSIGNEDP. */
3891 c_build_bitfield_integer_type (unsigned HOST_WIDE_INT width
, int unsignedp
)
3895 /* Extended integer types of the same width as a standard type have
3896 lesser rank, so those of the same width as int promote to int or
3897 unsigned int and are valid for printf formats expecting int or
3898 unsigned int. To avoid such special cases, avoid creating
3899 extended integer types for bit-fields if a standard integer type
3901 if (width
== TYPE_PRECISION (integer_type_node
))
3902 return unsignedp
? unsigned_type_node
: integer_type_node
;
3903 if (width
== TYPE_PRECISION (signed_char_type_node
))
3904 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3905 if (width
== TYPE_PRECISION (short_integer_type_node
))
3906 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3907 if (width
== TYPE_PRECISION (long_integer_type_node
))
3908 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3909 if (width
== TYPE_PRECISION (long_long_integer_type_node
))
3910 return (unsignedp
? long_long_unsigned_type_node
3911 : long_long_integer_type_node
);
3912 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
3913 if (int_n_enabled_p
[i
]
3914 && width
== int_n_data
[i
].bitsize
)
3915 return (unsignedp
? int_n_trees
[i
].unsigned_type
3916 : int_n_trees
[i
].signed_type
);
3917 return build_nonstandard_integer_type (width
, unsignedp
);
3920 /* The C version of the register_builtin_type langhook. */
3923 c_register_builtin_type (tree type
, const char* name
)
3927 decl
= build_decl (UNKNOWN_LOCATION
,
3928 TYPE_DECL
, get_identifier (name
), type
);
3929 DECL_ARTIFICIAL (decl
) = 1;
3930 if (!TYPE_NAME (type
))
3931 TYPE_NAME (type
) = decl
;
3934 registered_builtin_types
= tree_cons (0, type
, registered_builtin_types
);
3937 /* Print an error message for invalid operands to arith operation
3938 CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
3939 RICHLOC is a rich location for the message, containing either
3940 three separate locations for each of the operator and operands
3945 (C FE), or one location ranging over all over them
3953 binary_op_error (rich_location
*richloc
, enum tree_code code
,
3954 tree type0
, tree type1
)
3961 opname
= "+"; break;
3963 opname
= "-"; break;
3965 opname
= "*"; break;
3967 opname
= "max"; break;
3969 opname
= "min"; break;
3971 opname
= "=="; break;
3973 opname
= "!="; break;
3975 opname
= "<="; break;
3977 opname
= ">="; break;
3979 opname
= "<"; break;
3981 opname
= ">"; break;
3983 opname
= "<<"; break;
3985 opname
= ">>"; break;
3986 case TRUNC_MOD_EXPR
:
3987 case FLOOR_MOD_EXPR
:
3988 opname
= "%"; break;
3989 case TRUNC_DIV_EXPR
:
3990 case FLOOR_DIV_EXPR
:
3991 opname
= "/"; break;
3993 opname
= "&"; break;
3995 opname
= "|"; break;
3996 case TRUTH_ANDIF_EXPR
:
3997 opname
= "&&"; break;
3998 case TRUTH_ORIF_EXPR
:
3999 opname
= "||"; break;
4001 opname
= "^"; break;
4005 error_at_rich_loc (richloc
,
4006 "invalid operands to binary %s (have %qT and %qT)",
4007 opname
, type0
, type1
);
4010 /* Given an expression as a tree, return its original type. Do this
4011 by stripping any conversion that preserves the sign and precision. */
4013 expr_original_type (tree expr
)
4015 STRIP_SIGN_NOPS (expr
);
4016 return TREE_TYPE (expr
);
4019 /* Subroutine of build_binary_op, used for comparison operations.
4020 See if the operands have both been converted from subword integer types
4021 and, if so, perhaps change them both back to their original type.
4022 This function is also responsible for converting the two operands
4023 to the proper common type for comparison.
4025 The arguments of this function are all pointers to local variables
4026 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
4027 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
4029 LOC is the location of the comparison.
4031 If this function returns nonzero, it means that the comparison has
4032 a constant value. What this function returns is an expression for
4036 shorten_compare (location_t loc
, tree
*op0_ptr
, tree
*op1_ptr
,
4037 tree
*restype_ptr
, enum tree_code
*rescode_ptr
)
4040 tree op0
= *op0_ptr
;
4041 tree op1
= *op1_ptr
;
4042 int unsignedp0
, unsignedp1
;
4044 tree primop0
, primop1
;
4045 enum tree_code code
= *rescode_ptr
;
4047 /* Throw away any conversions to wider types
4048 already present in the operands. */
4050 primop0
= c_common_get_narrower (op0
, &unsignedp0
);
4051 primop1
= c_common_get_narrower (op1
, &unsignedp1
);
4053 /* If primopN is first sign-extended from primopN's precision to opN's
4054 precision, then zero-extended from opN's precision to
4055 *restype_ptr precision, shortenings might be invalid. */
4056 if (TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (TREE_TYPE (op0
))
4057 && TYPE_PRECISION (TREE_TYPE (op0
)) < TYPE_PRECISION (*restype_ptr
)
4059 && TYPE_UNSIGNED (TREE_TYPE (op0
)))
4061 if (TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (TREE_TYPE (op1
))
4062 && TYPE_PRECISION (TREE_TYPE (op1
)) < TYPE_PRECISION (*restype_ptr
)
4064 && TYPE_UNSIGNED (TREE_TYPE (op1
)))
4067 /* Handle the case that OP0 does not *contain* a conversion
4068 but it *requires* conversion to FINAL_TYPE. */
4070 if (op0
== primop0
&& TREE_TYPE (op0
) != *restype_ptr
)
4071 unsignedp0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
4072 if (op1
== primop1
&& TREE_TYPE (op1
) != *restype_ptr
)
4073 unsignedp1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
4075 /* If one of the operands must be floated, we cannot optimize. */
4076 real1
= TREE_CODE (TREE_TYPE (primop0
)) == REAL_TYPE
;
4077 real2
= TREE_CODE (TREE_TYPE (primop1
)) == REAL_TYPE
;
4079 /* If first arg is constant, swap the args (changing operation
4080 so value is preserved), for canonicalization. Don't do this if
4081 the second arg is 0. */
4083 if (TREE_CONSTANT (primop0
)
4084 && !integer_zerop (primop1
) && !real_zerop (primop1
)
4085 && !fixed_zerop (primop1
))
4087 std::swap (primop0
, primop1
);
4088 std::swap (op0
, op1
);
4091 std::swap (unsignedp0
, unsignedp1
);
4092 std::swap (real1
, real2
);
4111 *rescode_ptr
= code
;
4114 /* If comparing an integer against a constant more bits wide,
4115 maybe we can deduce a value of 1 or 0 independent of the data.
4116 Or else truncate the constant now
4117 rather than extend the variable at run time.
4119 This is only interesting if the constant is the wider arg.
4120 Also, it is not safe if the constant is unsigned and the
4121 variable arg is signed, since in this case the variable
4122 would be sign-extended and then regarded as unsigned.
4123 Our technique fails in this case because the lowest/highest
4124 possible unsigned results don't follow naturally from the
4125 lowest/highest possible values of the variable operand.
4126 For just EQ_EXPR and NE_EXPR there is another technique that
4127 could be used: see if the constant can be faithfully represented
4128 in the other operand's type, by truncating it and reextending it
4129 and see if that preserves the constant's value. */
4131 if (!real1
&& !real2
4132 && TREE_CODE (TREE_TYPE (primop0
)) != FIXED_POINT_TYPE
4133 && TREE_CODE (primop1
) == INTEGER_CST
4134 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
))
4136 int min_gt
, max_gt
, min_lt
, max_lt
;
4137 tree maxval
, minval
;
4138 /* 1 if comparison is nominally unsigned. */
4139 int unsignedp
= TYPE_UNSIGNED (*restype_ptr
);
4142 type
= c_common_signed_or_unsigned_type (unsignedp0
,
4143 TREE_TYPE (primop0
));
4145 maxval
= TYPE_MAX_VALUE (type
);
4146 minval
= TYPE_MIN_VALUE (type
);
4148 if (unsignedp
&& !unsignedp0
)
4149 *restype_ptr
= c_common_signed_type (*restype_ptr
);
4151 if (TREE_TYPE (primop1
) != *restype_ptr
)
4153 /* Convert primop1 to target type, but do not introduce
4154 additional overflow. We know primop1 is an int_cst. */
4155 primop1
= force_fit_type (*restype_ptr
,
4158 TYPE_PRECISION (*restype_ptr
)),
4159 0, TREE_OVERFLOW (primop1
));
4161 if (type
!= *restype_ptr
)
4163 minval
= convert (*restype_ptr
, minval
);
4164 maxval
= convert (*restype_ptr
, maxval
);
4167 min_gt
= tree_int_cst_lt (primop1
, minval
);
4168 max_gt
= tree_int_cst_lt (primop1
, maxval
);
4169 min_lt
= tree_int_cst_lt (minval
, primop1
);
4170 max_lt
= tree_int_cst_lt (maxval
, primop1
);
4173 /* This used to be a switch, but Genix compiler can't handle that. */
4174 if (code
== NE_EXPR
)
4176 if (max_lt
|| min_gt
)
4177 val
= truthvalue_true_node
;
4179 else if (code
== EQ_EXPR
)
4181 if (max_lt
|| min_gt
)
4182 val
= truthvalue_false_node
;
4184 else if (code
== LT_EXPR
)
4187 val
= truthvalue_true_node
;
4189 val
= truthvalue_false_node
;
4191 else if (code
== GT_EXPR
)
4194 val
= truthvalue_true_node
;
4196 val
= truthvalue_false_node
;
4198 else if (code
== LE_EXPR
)
4201 val
= truthvalue_true_node
;
4203 val
= truthvalue_false_node
;
4205 else if (code
== GE_EXPR
)
4208 val
= truthvalue_true_node
;
4210 val
= truthvalue_false_node
;
4213 /* If primop0 was sign-extended and unsigned comparison specd,
4214 we did a signed comparison above using the signed type bounds.
4215 But the comparison we output must be unsigned.
4217 Also, for inequalities, VAL is no good; but if the signed
4218 comparison had *any* fixed result, it follows that the
4219 unsigned comparison just tests the sign in reverse
4220 (positive values are LE, negative ones GE).
4221 So we can generate an unsigned comparison
4222 against an extreme value of the signed type. */
4224 if (unsignedp
&& !unsignedp0
)
4231 primop1
= TYPE_MIN_VALUE (type
);
4237 primop1
= TYPE_MAX_VALUE (type
);
4244 type
= c_common_unsigned_type (type
);
4247 if (TREE_CODE (primop0
) != INTEGER_CST
4248 /* Don't warn if it's from a (non-system) macro. */
4249 && !(from_macro_expansion_at
4250 (expansion_point_location_if_in_system_header
4251 (EXPR_LOCATION (primop0
)))))
4253 if (val
== truthvalue_false_node
)
4254 warning_at (loc
, OPT_Wtype_limits
,
4255 "comparison is always false due to limited range of data type");
4256 if (val
== truthvalue_true_node
)
4257 warning_at (loc
, OPT_Wtype_limits
,
4258 "comparison is always true due to limited range of data type");
4263 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4264 if (TREE_SIDE_EFFECTS (primop0
))
4265 return build2 (COMPOUND_EXPR
, TREE_TYPE (val
), primop0
, val
);
4269 /* Value is not predetermined, but do the comparison
4270 in the type of the operand that is not constant.
4271 TYPE is already properly set. */
4274 /* If either arg is decimal float and the other is float, find the
4275 proper common type to use for comparison. */
4276 else if (real1
&& real2
4277 && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0
)))
4278 && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1
))))
4279 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
4281 /* If either arg is decimal float and the other is float, fail. */
4282 else if (real1
&& real2
4283 && (DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0
)))
4284 || DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1
)))))
4287 else if (real1
&& real2
4288 && (TYPE_PRECISION (TREE_TYPE (primop0
))
4289 == TYPE_PRECISION (TREE_TYPE (primop1
))))
4290 type
= TREE_TYPE (primop0
);
4292 /* If args' natural types are both narrower than nominal type
4293 and both extend in the same manner, compare them
4294 in the type of the wider arg.
4295 Otherwise must actually extend both to the nominal
4296 common type lest different ways of extending
4298 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
4300 else if (unsignedp0
== unsignedp1
&& real1
== real2
4301 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
)
4302 && TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (*restype_ptr
))
4304 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
4305 type
= c_common_signed_or_unsigned_type (unsignedp0
4306 || TYPE_UNSIGNED (*restype_ptr
),
4308 /* Make sure shorter operand is extended the right way
4309 to match the longer operand. */
4311 = convert (c_common_signed_or_unsigned_type (unsignedp0
,
4312 TREE_TYPE (primop0
)),
4315 = convert (c_common_signed_or_unsigned_type (unsignedp1
,
4316 TREE_TYPE (primop1
)),
4321 /* Here we must do the comparison on the nominal type
4322 using the args exactly as we received them. */
4323 type
= *restype_ptr
;
4327 if (!real1
&& !real2
&& integer_zerop (primop1
)
4328 && TYPE_UNSIGNED (*restype_ptr
))
4331 /* All unsigned values are >= 0, so we warn. However,
4332 if OP0 is a constant that is >= 0, the signedness of
4333 the comparison isn't an issue, so suppress the
4336 warn_type_limits
&& !in_system_header_at (loc
)
4337 && !(TREE_CODE (primop0
) == INTEGER_CST
4338 && !TREE_OVERFLOW (convert (c_common_signed_type (type
),
4340 /* Do not warn for enumeration types. */
4341 && (TREE_CODE (expr_original_type (primop0
)) != ENUMERAL_TYPE
);
4347 warning_at (loc
, OPT_Wtype_limits
,
4348 "comparison of unsigned expression >= 0 is always true");
4349 value
= truthvalue_true_node
;
4354 warning_at (loc
, OPT_Wtype_limits
,
4355 "comparison of unsigned expression < 0 is always false");
4356 value
= truthvalue_false_node
;
4365 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4366 if (TREE_SIDE_EFFECTS (primop0
))
4367 return build2 (COMPOUND_EXPR
, TREE_TYPE (value
),
4374 *op0_ptr
= convert (type
, primop0
);
4375 *op1_ptr
= convert (type
, primop1
);
4377 *restype_ptr
= truthvalue_type_node
;
4382 /* Return a tree for the sum or difference (RESULTCODE says which)
4383 of pointer PTROP and integer INTOP. */
4386 pointer_int_sum (location_t loc
, enum tree_code resultcode
,
4387 tree ptrop
, tree intop
, bool complain
)
4391 /* The result is a pointer of the same type that is being added. */
4392 tree result_type
= TREE_TYPE (ptrop
);
4394 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
4396 if (complain
&& warn_pointer_arith
)
4397 pedwarn (loc
, OPT_Wpointer_arith
,
4398 "pointer of type %<void *%> used in arithmetic");
4400 return error_mark_node
;
4401 size_exp
= integer_one_node
;
4403 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
4405 if (complain
&& warn_pointer_arith
)
4406 pedwarn (loc
, OPT_Wpointer_arith
,
4407 "pointer to a function used in arithmetic");
4409 return error_mark_node
;
4410 size_exp
= integer_one_node
;
4413 size_exp
= size_in_bytes_loc (loc
, TREE_TYPE (result_type
));
4415 /* We are manipulating pointer values, so we don't need to warn
4416 about relying on undefined signed overflow. We disable the
4417 warning here because we use integer types so fold won't know that
4418 they are really pointers. */
4419 fold_defer_overflow_warnings ();
4421 /* If what we are about to multiply by the size of the elements
4422 contains a constant term, apply distributive law
4423 and multiply that constant term separately.
4424 This helps produce common subexpressions. */
4425 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
4426 && !TREE_CONSTANT (intop
)
4427 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
4428 && TREE_CONSTANT (size_exp
)
4429 /* If the constant comes from pointer subtraction,
4430 skip this optimization--it would cause an error. */
4431 && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop
, 0))) == INTEGER_TYPE
4432 /* If the constant is unsigned, and smaller than the pointer size,
4433 then we must skip this optimization. This is because it could cause
4434 an overflow error if the constant is negative but INTOP is not. */
4435 && (!TYPE_UNSIGNED (TREE_TYPE (intop
))
4436 || (TYPE_PRECISION (TREE_TYPE (intop
))
4437 == TYPE_PRECISION (TREE_TYPE (ptrop
)))))
4439 enum tree_code subcode
= resultcode
;
4440 tree int_type
= TREE_TYPE (intop
);
4441 if (TREE_CODE (intop
) == MINUS_EXPR
)
4442 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
4443 /* Convert both subexpression types to the type of intop,
4444 because weird cases involving pointer arithmetic
4445 can result in a sum or difference with different type args. */
4446 ptrop
= build_binary_op (EXPR_LOCATION (TREE_OPERAND (intop
, 1)),
4448 convert (int_type
, TREE_OPERAND (intop
, 1)), 1);
4449 intop
= convert (int_type
, TREE_OPERAND (intop
, 0));
4452 /* Convert the integer argument to a type the same size as sizetype
4453 so the multiply won't overflow spuriously. */
4454 if (TYPE_PRECISION (TREE_TYPE (intop
)) != TYPE_PRECISION (sizetype
)
4455 || TYPE_UNSIGNED (TREE_TYPE (intop
)) != TYPE_UNSIGNED (sizetype
))
4456 intop
= convert (c_common_type_for_size (TYPE_PRECISION (sizetype
),
4457 TYPE_UNSIGNED (sizetype
)), intop
);
4459 /* Replace the integer argument with a suitable product by the object size.
4460 Do this multiplication as signed, then convert to the appropriate type
4461 for the pointer operation and disregard an overflow that occurred only
4462 because of the sign-extension change in the latter conversion. */
4464 tree t
= fold_build2_loc (loc
, MULT_EXPR
, TREE_TYPE (intop
), intop
,
4465 convert (TREE_TYPE (intop
), size_exp
));
4466 intop
= convert (sizetype
, t
);
4467 if (TREE_OVERFLOW_P (intop
) && !TREE_OVERFLOW (t
))
4468 intop
= wide_int_to_tree (TREE_TYPE (intop
), intop
);
4471 /* Create the sum or difference. */
4472 if (resultcode
== MINUS_EXPR
)
4473 intop
= fold_build1_loc (loc
, NEGATE_EXPR
, sizetype
, intop
);
4475 ret
= fold_build_pointer_plus_loc (loc
, ptrop
, intop
);
4477 fold_undefer_and_ignore_overflow_warnings ();
4482 /* Wrap a C_MAYBE_CONST_EXPR around an expression that is fully folded
4483 and if NON_CONST is known not to be permitted in an evaluated part
4484 of a constant expression. */
4487 c_wrap_maybe_const (tree expr
, bool non_const
)
4489 bool nowarning
= TREE_NO_WARNING (expr
);
4490 location_t loc
= EXPR_LOCATION (expr
);
4492 /* This should never be called for C++. */
4493 if (c_dialect_cxx ())
4496 /* The result of folding may have a NOP_EXPR to set TREE_NO_WARNING. */
4497 STRIP_TYPE_NOPS (expr
);
4498 expr
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (expr
), NULL
, expr
);
4499 C_MAYBE_CONST_EXPR_NON_CONST (expr
) = non_const
;
4501 TREE_NO_WARNING (expr
) = 1;
4502 protected_set_expr_location (expr
, loc
);
4507 /* Wrap a SAVE_EXPR around EXPR, if appropriate. Like save_expr, but
4508 for C folds the inside expression and wraps a C_MAYBE_CONST_EXPR
4509 around the SAVE_EXPR if needed so that c_fully_fold does not need
4510 to look inside SAVE_EXPRs. */
4513 c_save_expr (tree expr
)
4515 bool maybe_const
= true;
4516 if (c_dialect_cxx ())
4517 return save_expr (expr
);
4518 expr
= c_fully_fold (expr
, false, &maybe_const
);
4519 expr
= save_expr (expr
);
4521 expr
= c_wrap_maybe_const (expr
, true);
4525 /* Return whether EXPR is a declaration whose address can never be
4529 decl_with_nonnull_addr_p (const_tree expr
)
4531 return (DECL_P (expr
)
4532 && (TREE_CODE (expr
) == PARM_DECL
4533 || TREE_CODE (expr
) == LABEL_DECL
4534 || !DECL_WEAK (expr
)));
4537 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
4538 or for an `if' or `while' statement or ?..: exp. It should already
4539 have been validated to be of suitable type; otherwise, a bad
4540 diagnostic may result.
4542 The EXPR is located at LOCATION.
4544 This preparation consists of taking the ordinary
4545 representation of an expression expr and producing a valid tree
4546 boolean expression describing whether expr is nonzero. We could
4547 simply always do build_binary_op (NE_EXPR, expr, truthvalue_false_node, 1),
4548 but we optimize comparisons, &&, ||, and !.
4550 The resulting type should always be `truthvalue_type_node'. */
4553 c_common_truthvalue_conversion (location_t location
, tree expr
)
4555 switch (TREE_CODE (expr
))
4557 case EQ_EXPR
: case NE_EXPR
: case UNEQ_EXPR
: case LTGT_EXPR
:
4558 case LE_EXPR
: case GE_EXPR
: case LT_EXPR
: case GT_EXPR
:
4559 case UNLE_EXPR
: case UNGE_EXPR
: case UNLT_EXPR
: case UNGT_EXPR
:
4560 case ORDERED_EXPR
: case UNORDERED_EXPR
:
4561 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4563 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4564 TREE_OPERAND (expr
, 0), TREE_OPERAND (expr
, 1));
4567 case TRUTH_ANDIF_EXPR
:
4568 case TRUTH_ORIF_EXPR
:
4569 case TRUTH_AND_EXPR
:
4571 case TRUTH_XOR_EXPR
:
4572 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4574 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4575 c_common_truthvalue_conversion (location
,
4576 TREE_OPERAND (expr
, 0)),
4577 c_common_truthvalue_conversion (location
,
4578 TREE_OPERAND (expr
, 1)));
4581 case TRUTH_NOT_EXPR
:
4582 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4584 expr
= build1 (TREE_CODE (expr
), truthvalue_type_node
,
4585 c_common_truthvalue_conversion (location
,
4586 TREE_OPERAND (expr
, 0)));
4593 return integer_zerop (expr
) ? truthvalue_false_node
4594 : truthvalue_true_node
;
4597 return real_compare (NE_EXPR
, &TREE_REAL_CST (expr
), &dconst0
)
4598 ? truthvalue_true_node
4599 : truthvalue_false_node
;
4602 return fixed_compare (NE_EXPR
, &TREE_FIXED_CST (expr
),
4603 &FCONST0 (TYPE_MODE (TREE_TYPE (expr
))))
4604 ? truthvalue_true_node
4605 : truthvalue_false_node
;
4608 expr
= build_unary_op (location
, ADDR_EXPR
, expr
, false);
4613 tree inner
= TREE_OPERAND (expr
, 0);
4614 if (decl_with_nonnull_addr_p (inner
))
4616 /* Common Ada/Pascal programmer's mistake. */
4617 warning_at (location
,
4619 "the address of %qD will always evaluate as %<true%>",
4621 return truthvalue_true_node
;
4627 expr
= build_binary_op (EXPR_LOCATION (expr
),
4628 (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1))
4629 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4630 c_common_truthvalue_conversion (location
,
4631 TREE_OPERAND (expr
, 0)),
4632 c_common_truthvalue_conversion (location
,
4633 TREE_OPERAND (expr
, 1)),
4640 case EXCESS_PRECISION_EXPR
:
4641 /* These don't change whether an object is nonzero or zero. */
4642 return c_common_truthvalue_conversion (location
, TREE_OPERAND (expr
, 0));
4646 /* These don't change whether an object is zero or nonzero, but
4647 we can't ignore them if their second arg has side-effects. */
4648 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1)))
4650 expr
= build2 (COMPOUND_EXPR
, truthvalue_type_node
,
4651 TREE_OPERAND (expr
, 1),
4652 c_common_truthvalue_conversion
4653 (location
, TREE_OPERAND (expr
, 0)));
4657 return c_common_truthvalue_conversion (location
,
4658 TREE_OPERAND (expr
, 0));
4661 warning_at (EXPR_LOCATION (expr
), OPT_Wint_in_bool_context
,
4662 "<< in boolean context, did you mean '<' ?");
4666 if (warn_int_in_bool_context
4667 && !from_macro_definition_at (EXPR_LOCATION (expr
)))
4669 tree val1
= fold_for_warn (TREE_OPERAND (expr
, 1));
4670 tree val2
= fold_for_warn (TREE_OPERAND (expr
, 2));
4671 if (TREE_CODE (val1
) == INTEGER_CST
4672 && TREE_CODE (val2
) == INTEGER_CST
4673 && !integer_zerop (val1
)
4674 && !integer_zerop (val2
)
4675 && (!integer_onep (val1
)
4676 || !integer_onep (val2
)))
4677 warning_at (EXPR_LOCATION (expr
), OPT_Wint_in_bool_context
,
4678 "?: using integer constants in boolean context, "
4679 "the expression will always evaluate to %<true%>");
4680 else if ((TREE_CODE (val1
) == INTEGER_CST
4681 && !integer_zerop (val1
)
4682 && !integer_onep (val1
))
4683 || (TREE_CODE (val2
) == INTEGER_CST
4684 && !integer_zerop (val2
)
4685 && !integer_onep (val2
)))
4686 warning_at (EXPR_LOCATION (expr
), OPT_Wint_in_bool_context
,
4687 "?: using integer constants in boolean context");
4689 /* Distribute the conversion into the arms of a COND_EXPR. */
4690 if (c_dialect_cxx ())
4692 tree op1
= TREE_OPERAND (expr
, 1);
4693 tree op2
= TREE_OPERAND (expr
, 2);
4694 int w
= warn_int_in_bool_context
;
4695 warn_int_in_bool_context
= 0;
4696 /* In C++ one of the arms might have void type if it is throw. */
4697 if (!VOID_TYPE_P (TREE_TYPE (op1
)))
4698 op1
= c_common_truthvalue_conversion (location
, op1
);
4699 if (!VOID_TYPE_P (TREE_TYPE (op2
)))
4700 op2
= c_common_truthvalue_conversion (location
, op2
);
4701 expr
= fold_build3_loc (location
, COND_EXPR
, truthvalue_type_node
,
4702 TREE_OPERAND (expr
, 0), op1
, op2
);
4703 warn_int_in_bool_context
= w
;
4708 int w
= warn_int_in_bool_context
;
4709 warn_int_in_bool_context
= 0;
4710 /* Folding will happen later for C. */
4711 expr
= build3 (COND_EXPR
, truthvalue_type_node
,
4712 TREE_OPERAND (expr
, 0),
4713 c_common_truthvalue_conversion (location
,
4714 TREE_OPERAND (expr
, 1)),
4715 c_common_truthvalue_conversion (location
,
4716 TREE_OPERAND (expr
, 2)));
4717 warn_int_in_bool_context
= w
;
4723 tree totype
= TREE_TYPE (expr
);
4724 tree fromtype
= TREE_TYPE (TREE_OPERAND (expr
, 0));
4726 if (POINTER_TYPE_P (totype
)
4727 && !c_inhibit_evaluation_warnings
4728 && TREE_CODE (fromtype
) == REFERENCE_TYPE
)
4734 warning_at (location
,
4736 "the compiler can assume that the address of "
4737 "%qD will always evaluate to %<true%>",
4741 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
4742 since that affects how `default_conversion' will behave. */
4743 if (TREE_CODE (totype
) == REFERENCE_TYPE
4744 || TREE_CODE (fromtype
) == REFERENCE_TYPE
)
4746 /* Don't strip a conversion from C++0x scoped enum, since they
4747 don't implicitly convert to other types. */
4748 if (TREE_CODE (fromtype
) == ENUMERAL_TYPE
4749 && ENUM_IS_SCOPED (fromtype
))
4751 /* If this isn't narrowing the argument, we can ignore it. */
4752 if (TYPE_PRECISION (totype
) >= TYPE_PRECISION (fromtype
))
4753 return c_common_truthvalue_conversion (location
,
4754 TREE_OPERAND (expr
, 0));
4759 if (!TREE_NO_WARNING (expr
)
4760 && warn_parentheses
)
4762 warning_at (location
, OPT_Wparentheses
,
4763 "suggest parentheses around assignment used as "
4765 TREE_NO_WARNING (expr
) = 1;
4773 if (TREE_CODE (TREE_TYPE (expr
)) == COMPLEX_TYPE
)
4775 tree t
= (in_late_binary_op
? save_expr (expr
) : c_save_expr (expr
));
4776 expr
= (build_binary_op
4777 (EXPR_LOCATION (expr
),
4778 (TREE_SIDE_EFFECTS (expr
)
4779 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4780 c_common_truthvalue_conversion
4782 build_unary_op (location
, REALPART_EXPR
, t
, false)),
4783 c_common_truthvalue_conversion
4785 build_unary_op (location
, IMAGPART_EXPR
, t
, false)),
4790 if (TREE_CODE (TREE_TYPE (expr
)) == FIXED_POINT_TYPE
)
4792 tree fixed_zero_node
= build_fixed (TREE_TYPE (expr
),
4794 (TREE_TYPE (expr
))));
4795 return build_binary_op (location
, NE_EXPR
, expr
, fixed_zero_node
, 1);
4798 return build_binary_op (location
, NE_EXPR
, expr
, integer_zero_node
, 1);
4801 protected_set_expr_location (expr
, location
);
4805 static void def_builtin_1 (enum built_in_function fncode
,
4807 enum built_in_class fnclass
,
4808 tree fntype
, tree libtype
,
4809 bool both_p
, bool fallback_p
, bool nonansi_p
,
4810 tree fnattrs
, bool implicit_p
);
4813 /* Apply the TYPE_QUALS to the new DECL. */
4816 c_apply_type_quals_to_decl (int type_quals
, tree decl
)
4818 tree type
= TREE_TYPE (decl
);
4820 if (type
== error_mark_node
)
4823 if ((type_quals
& TYPE_QUAL_CONST
)
4824 || (type
&& TREE_CODE (type
) == REFERENCE_TYPE
))
4825 /* We used to check TYPE_NEEDS_CONSTRUCTING here, but now a constexpr
4826 constructor can produce constant init, so rely on cp_finish_decl to
4827 clear TREE_READONLY if the variable has non-constant init. */
4828 TREE_READONLY (decl
) = 1;
4829 if (type_quals
& TYPE_QUAL_VOLATILE
)
4831 TREE_SIDE_EFFECTS (decl
) = 1;
4832 TREE_THIS_VOLATILE (decl
) = 1;
4834 if (type_quals
& TYPE_QUAL_RESTRICT
)
4836 while (type
&& TREE_CODE (type
) == ARRAY_TYPE
)
4837 /* Allow 'restrict' on arrays of pointers.
4838 FIXME currently we just ignore it. */
4839 type
= TREE_TYPE (type
);
4841 || !POINTER_TYPE_P (type
)
4842 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type
)))
4843 error ("invalid use of %<restrict%>");
4847 struct c_type_hasher
: ggc_ptr_hash
<tree_node
>
4849 static hashval_t
hash (tree
);
4850 static bool equal (tree
, tree
);
4853 /* Hash function for the problem of multiple type definitions in
4854 different files. This must hash all types that will compare
4855 equal via comptypes to the same value. In practice it hashes
4856 on some of the simple stuff and leaves the details to comptypes. */
4859 c_type_hasher::hash (tree t
)
4864 switch (TREE_CODE (t
))
4866 /* For pointers, hash on pointee type plus some swizzling. */
4868 return hash (TREE_TYPE (t
)) ^ 0x3003003;
4869 /* Hash on number of elements and total size. */
4872 t2
= TYPE_VALUES (t
);
4876 t2
= TYPE_FIELDS (t
);
4878 case QUAL_UNION_TYPE
:
4880 t2
= TYPE_FIELDS (t
);
4884 t2
= TYPE_FIELDS (t
);
4889 /* FIXME: We want to use a DECL_CHAIN iteration method here, but
4890 TYPE_VALUES of ENUMERAL_TYPEs is stored as a TREE_LIST. */
4891 n_elements
= list_length (t2
);
4892 /* We might have a VLA here. */
4893 if (TREE_CODE (TYPE_SIZE (t
)) != INTEGER_CST
)
4896 size
= TREE_INT_CST_LOW (TYPE_SIZE (t
));
4897 return ((size
<< 24) | (n_elements
<< shift
));
4901 c_type_hasher::equal (tree t1
, tree t2
)
4903 return lang_hooks
.types_compatible_p (t1
, t2
);
4906 static GTY(()) hash_table
<c_type_hasher
> *type_hash_table
;
4908 /* Return the typed-based alias set for T, which may be an expression
4909 or a type. Return -1 if we don't do anything special. */
4912 c_common_get_alias_set (tree t
)
4914 /* For VLAs, use the alias set of the element type rather than the
4915 default of alias set 0 for types compared structurally. */
4916 if (TYPE_P (t
) && TYPE_STRUCTURAL_EQUALITY_P (t
))
4918 if (TREE_CODE (t
) == ARRAY_TYPE
)
4919 return get_alias_set (TREE_TYPE (t
));
4923 /* That's all the expressions we handle specially. */
4927 /* The C standard guarantees that any object may be accessed via an
4928 lvalue that has character type. */
4929 if (t
== char_type_node
4930 || t
== signed_char_type_node
4931 || t
== unsigned_char_type_node
)
4934 /* The C standard specifically allows aliasing between signed and
4935 unsigned variants of the same type. We treat the signed
4936 variant as canonical. */
4937 if (TREE_CODE (t
) == INTEGER_TYPE
&& TYPE_UNSIGNED (t
))
4939 tree t1
= c_common_signed_type (t
);
4941 /* t1 == t can happen for boolean nodes which are always unsigned. */
4943 return get_alias_set (t1
);
4946 /* Handle the case of multiple type nodes referring to "the same" type,
4947 which occurs with IMA. These share an alias set. FIXME: Currently only
4948 C90 is handled. (In C99 type compatibility is not transitive, which
4949 complicates things mightily. The alias set splay trees can theoretically
4950 represent this, but insertion is tricky when you consider all the
4951 different orders things might arrive in.) */
4953 if (c_language
!= clk_c
|| flag_isoc99
)
4956 /* Save time if there's only one input file. */
4957 if (num_in_fnames
== 1)
4960 /* Pointers need special handling if they point to any type that
4961 needs special handling (below). */
4962 if (TREE_CODE (t
) == POINTER_TYPE
)
4965 /* Find bottom type under any nested POINTERs. */
4966 for (t2
= TREE_TYPE (t
);
4967 TREE_CODE (t2
) == POINTER_TYPE
;
4968 t2
= TREE_TYPE (t2
))
4970 if (!RECORD_OR_UNION_TYPE_P (t2
)
4971 && TREE_CODE (t2
) != ENUMERAL_TYPE
)
4973 if (TYPE_SIZE (t2
) == 0)
4976 /* These are the only cases that need special handling. */
4977 if (!RECORD_OR_UNION_TYPE_P (t
)
4978 && TREE_CODE (t
) != ENUMERAL_TYPE
4979 && TREE_CODE (t
) != POINTER_TYPE
)
4982 if (TYPE_SIZE (t
) == 0)
4985 /* Look up t in hash table. Only one of the compatible types within each
4986 alias set is recorded in the table. */
4987 if (!type_hash_table
)
4988 type_hash_table
= hash_table
<c_type_hasher
>::create_ggc (1021);
4989 tree
*slot
= type_hash_table
->find_slot (t
, INSERT
);
4992 TYPE_ALIAS_SET (t
) = TYPE_ALIAS_SET ((tree
)*slot
);
4993 return TYPE_ALIAS_SET ((tree
)*slot
);
4996 /* Our caller will assign and record (in t) a new alias set; all we need
4997 to do is remember t in the hash table. */
5003 /* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where
5004 the IS_SIZEOF parameter indicates which operator is being applied.
5005 The COMPLAIN flag controls whether we should diagnose possibly
5006 ill-formed constructs or not. LOC is the location of the SIZEOF or
5007 TYPEOF operator. If MIN_ALIGNOF, the least alignment required for
5008 a type in any context should be returned, rather than the normal
5009 alignment for that type. */
5012 c_sizeof_or_alignof_type (location_t loc
,
5013 tree type
, bool is_sizeof
, bool min_alignof
,
5016 const char *op_name
;
5018 enum tree_code type_code
= TREE_CODE (type
);
5020 op_name
= is_sizeof
? "sizeof" : "__alignof__";
5022 if (type_code
== FUNCTION_TYPE
)
5026 if (complain
&& warn_pointer_arith
)
5027 pedwarn (loc
, OPT_Wpointer_arith
,
5028 "invalid application of %<sizeof%> to a function type");
5030 return error_mark_node
;
5031 value
= size_one_node
;
5037 if (c_dialect_cxx ())
5038 pedwarn (loc
, OPT_Wpedantic
, "ISO C++ does not permit "
5039 "%<alignof%> applied to a function type");
5041 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not permit "
5042 "%<_Alignof%> applied to a function type");
5044 value
= size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
5047 else if (type_code
== VOID_TYPE
|| type_code
== ERROR_MARK
)
5049 if (type_code
== VOID_TYPE
5050 && complain
&& warn_pointer_arith
)
5051 pedwarn (loc
, OPT_Wpointer_arith
,
5052 "invalid application of %qs to a void type", op_name
);
5054 return error_mark_node
;
5055 value
= size_one_node
;
5057 else if (!COMPLETE_TYPE_P (type
)
5058 && (!c_dialect_cxx () || is_sizeof
|| type_code
!= ARRAY_TYPE
))
5061 error_at (loc
, "invalid application of %qs to incomplete type %qT",
5063 return error_mark_node
;
5065 else if (c_dialect_cxx () && type_code
== ARRAY_TYPE
5066 && !COMPLETE_TYPE_P (TREE_TYPE (type
)))
5069 error_at (loc
, "invalid application of %qs to array type %qT of "
5070 "incomplete element type", op_name
, type
);
5071 return error_mark_node
;
5076 /* Convert in case a char is more than one unit. */
5077 value
= size_binop_loc (loc
, CEIL_DIV_EXPR
, TYPE_SIZE_UNIT (type
),
5078 size_int (TYPE_PRECISION (char_type_node
)
5080 else if (min_alignof
)
5081 value
= size_int (min_align_of_type (type
));
5083 value
= size_int (TYPE_ALIGN_UNIT (type
));
5086 /* VALUE will have the middle-end integer type sizetype.
5087 However, we should really return a value of type `size_t',
5088 which is just a typedef for an ordinary integer type. */
5089 value
= fold_convert_loc (loc
, size_type_node
, value
);
5094 /* Implement the __alignof keyword: Return the minimum required
5095 alignment of EXPR, measured in bytes. For VAR_DECLs,
5096 FUNCTION_DECLs and FIELD_DECLs return DECL_ALIGN (which can be set
5097 from an "aligned" __attribute__ specification). LOC is the
5098 location of the ALIGNOF operator. */
5101 c_alignof_expr (location_t loc
, tree expr
)
5105 if (VAR_OR_FUNCTION_DECL_P (expr
))
5106 t
= size_int (DECL_ALIGN_UNIT (expr
));
5108 else if (TREE_CODE (expr
) == COMPONENT_REF
5109 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
, 1)))
5111 error_at (loc
, "%<__alignof%> applied to a bit-field");
5114 else if (TREE_CODE (expr
) == COMPONENT_REF
5115 && TREE_CODE (TREE_OPERAND (expr
, 1)) == FIELD_DECL
)
5116 t
= size_int (DECL_ALIGN_UNIT (TREE_OPERAND (expr
, 1)));
5118 else if (INDIRECT_REF_P (expr
))
5120 tree t
= TREE_OPERAND (expr
, 0);
5122 int bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
5124 while (CONVERT_EXPR_P (t
)
5125 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
5129 t
= TREE_OPERAND (t
, 0);
5130 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
5131 if (thisalign
> bestalign
)
5132 best
= t
, bestalign
= thisalign
;
5134 return c_alignof (loc
, TREE_TYPE (TREE_TYPE (best
)));
5137 return c_alignof (loc
, TREE_TYPE (expr
));
5139 return fold_convert_loc (loc
, size_type_node
, t
);
5142 /* Handle C and C++ default attributes. */
5144 enum built_in_attribute
5146 #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
5147 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
5148 #define DEF_ATTR_STRING(ENUM, VALUE) ENUM,
5149 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
5150 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
5151 #include "builtin-attrs.def"
5152 #undef DEF_ATTR_NULL_TREE
5154 #undef DEF_ATTR_STRING
5155 #undef DEF_ATTR_IDENT
5156 #undef DEF_ATTR_TREE_LIST
5160 static GTY(()) tree built_in_attributes
[(int) ATTR_LAST
];
5162 static void c_init_attributes (void);
5166 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
5167 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
5168 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
5169 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
5170 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
5171 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
5172 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
5173 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5175 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5177 #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5178 ARG6, ARG7, ARG8) NAME,
5179 #define DEF_FUNCTION_TYPE_9(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5180 ARG6, ARG7, ARG8, ARG9) NAME,
5181 #define DEF_FUNCTION_TYPE_10(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5182 ARG6, ARG7, ARG8, ARG9, ARG10) NAME,
5183 #define DEF_FUNCTION_TYPE_11(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5184 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) NAME,
5185 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
5186 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
5187 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
5188 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
5189 #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
5190 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5192 #define DEF_FUNCTION_TYPE_VAR_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5194 #define DEF_FUNCTION_TYPE_VAR_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5196 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
5197 #include "builtin-types.def"
5198 #undef DEF_PRIMITIVE_TYPE
5199 #undef DEF_FUNCTION_TYPE_0
5200 #undef DEF_FUNCTION_TYPE_1
5201 #undef DEF_FUNCTION_TYPE_2
5202 #undef DEF_FUNCTION_TYPE_3
5203 #undef DEF_FUNCTION_TYPE_4
5204 #undef DEF_FUNCTION_TYPE_5
5205 #undef DEF_FUNCTION_TYPE_6
5206 #undef DEF_FUNCTION_TYPE_7
5207 #undef DEF_FUNCTION_TYPE_8
5208 #undef DEF_FUNCTION_TYPE_9
5209 #undef DEF_FUNCTION_TYPE_10
5210 #undef DEF_FUNCTION_TYPE_11
5211 #undef DEF_FUNCTION_TYPE_VAR_0
5212 #undef DEF_FUNCTION_TYPE_VAR_1
5213 #undef DEF_FUNCTION_TYPE_VAR_2
5214 #undef DEF_FUNCTION_TYPE_VAR_3
5215 #undef DEF_FUNCTION_TYPE_VAR_4
5216 #undef DEF_FUNCTION_TYPE_VAR_5
5217 #undef DEF_FUNCTION_TYPE_VAR_6
5218 #undef DEF_FUNCTION_TYPE_VAR_7
5219 #undef DEF_POINTER_TYPE
5223 typedef enum c_builtin_type builtin_type
;
5225 /* A temporary array for c_common_nodes_and_builtins. Used in
5226 communication with def_fn_type. */
5227 static tree builtin_types
[(int) BT_LAST
+ 1];
5229 /* A helper function for c_common_nodes_and_builtins. Build function type
5230 for DEF with return type RET and N arguments. If VAR is true, then the
5231 function should be variadic after those N arguments.
5233 Takes special care not to ICE if any of the types involved are
5234 error_mark_node, which indicates that said type is not in fact available
5235 (see builtin_type_for_size). In which case the function type as a whole
5236 should be error_mark_node. */
5239 def_fn_type (builtin_type def
, builtin_type ret
, bool var
, int n
, ...)
5242 tree
*args
= XALLOCAVEC (tree
, n
);
5247 for (i
= 0; i
< n
; ++i
)
5249 builtin_type a
= (builtin_type
) va_arg (list
, int);
5250 t
= builtin_types
[a
];
5251 if (t
== error_mark_node
)
5256 t
= builtin_types
[ret
];
5257 if (t
== error_mark_node
)
5260 t
= build_varargs_function_type_array (t
, n
, args
);
5262 t
= build_function_type_array (t
, n
, args
);
5265 builtin_types
[def
] = t
;
5269 /* Build builtin functions common to both C and C++ language
5273 c_define_builtins (tree va_list_ref_type_node
, tree va_list_arg_type_node
)
5275 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
5276 builtin_types[ENUM] = VALUE;
5277 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
5278 def_fn_type (ENUM, RETURN, 0, 0);
5279 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
5280 def_fn_type (ENUM, RETURN, 0, 1, ARG1);
5281 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
5282 def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
5283 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
5284 def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
5285 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
5286 def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
5287 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5288 def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
5289 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5291 def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
5292 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5294 def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
5295 #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5297 def_fn_type (ENUM, RETURN, 0, 8, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
5299 #define DEF_FUNCTION_TYPE_9(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5300 ARG6, ARG7, ARG8, ARG9) \
5301 def_fn_type (ENUM, RETURN, 0, 9, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
5303 #define DEF_FUNCTION_TYPE_10(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5304 ARG6, ARG7, ARG8, ARG9, ARG10) \
5305 def_fn_type (ENUM, RETURN, 0, 10, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
5306 ARG7, ARG8, ARG9, ARG10);
5307 #define DEF_FUNCTION_TYPE_11(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5308 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) \
5309 def_fn_type (ENUM, RETURN, 0, 11, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
5310 ARG7, ARG8, ARG9, ARG10, ARG11);
5311 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
5312 def_fn_type (ENUM, RETURN, 1, 0);
5313 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
5314 def_fn_type (ENUM, RETURN, 1, 1, ARG1);
5315 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
5316 def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
5317 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
5318 def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
5319 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
5320 def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
5321 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5322 def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
5323 #define DEF_FUNCTION_TYPE_VAR_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5325 def_fn_type (ENUM, RETURN, 1, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
5326 #define DEF_FUNCTION_TYPE_VAR_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5328 def_fn_type (ENUM, RETURN, 1, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
5329 #define DEF_POINTER_TYPE(ENUM, TYPE) \
5330 builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
5332 #include "builtin-types.def"
5334 #undef DEF_PRIMITIVE_TYPE
5335 #undef DEF_FUNCTION_TYPE_0
5336 #undef DEF_FUNCTION_TYPE_1
5337 #undef DEF_FUNCTION_TYPE_2
5338 #undef DEF_FUNCTION_TYPE_3
5339 #undef DEF_FUNCTION_TYPE_4
5340 #undef DEF_FUNCTION_TYPE_5
5341 #undef DEF_FUNCTION_TYPE_6
5342 #undef DEF_FUNCTION_TYPE_7
5343 #undef DEF_FUNCTION_TYPE_8
5344 #undef DEF_FUNCTION_TYPE_9
5345 #undef DEF_FUNCTION_TYPE_10
5346 #undef DEF_FUNCTION_TYPE_11
5347 #undef DEF_FUNCTION_TYPE_VAR_0
5348 #undef DEF_FUNCTION_TYPE_VAR_1
5349 #undef DEF_FUNCTION_TYPE_VAR_2
5350 #undef DEF_FUNCTION_TYPE_VAR_3
5351 #undef DEF_FUNCTION_TYPE_VAR_4
5352 #undef DEF_FUNCTION_TYPE_VAR_5
5353 #undef DEF_FUNCTION_TYPE_VAR_6
5354 #undef DEF_FUNCTION_TYPE_VAR_7
5355 #undef DEF_POINTER_TYPE
5356 builtin_types
[(int) BT_LAST
] = NULL_TREE
;
5358 c_init_attributes ();
5360 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P, \
5361 NONANSI_P, ATTRS, IMPLICIT, COND) \
5363 def_builtin_1 (ENUM, NAME, CLASS, \
5364 builtin_types[(int) TYPE], \
5365 builtin_types[(int) LIBTYPE], \
5366 BOTH_P, FALLBACK_P, NONANSI_P, \
5367 built_in_attributes[(int) ATTRS], IMPLICIT);
5368 #include "builtins.def"
5370 targetm
.init_builtins ();
5372 build_common_builtin_nodes ();
5375 cilk_init_builtins ();
5378 /* Like get_identifier, but avoid warnings about null arguments when
5379 the argument may be NULL for targets where GCC lacks stdint.h type
5383 c_get_ident (const char *id
)
5385 return get_identifier (id
);
5388 /* Build tree nodes and builtin functions common to both C and C++ language
5392 c_common_nodes_and_builtins (void)
5394 int char16_type_size
;
5395 int char32_type_size
;
5396 int wchar_type_size
;
5397 tree array_domain_type
;
5398 tree va_list_ref_type_node
;
5399 tree va_list_arg_type_node
;
5402 build_common_tree_nodes (flag_signed_char
);
5404 /* Define `int' and `char' first so that dbx will output them first. */
5405 record_builtin_type (RID_INT
, NULL
, integer_type_node
);
5406 record_builtin_type (RID_CHAR
, "char", char_type_node
);
5408 /* `signed' is the same as `int'. FIXME: the declarations of "signed",
5409 "unsigned long", "long long unsigned" and "unsigned short" were in C++
5410 but not C. Are the conditionals here needed? */
5411 if (c_dialect_cxx ())
5412 record_builtin_type (RID_SIGNED
, NULL
, integer_type_node
);
5413 record_builtin_type (RID_LONG
, "long int", long_integer_type_node
);
5414 record_builtin_type (RID_UNSIGNED
, "unsigned int", unsigned_type_node
);
5415 record_builtin_type (RID_MAX
, "long unsigned int",
5416 long_unsigned_type_node
);
5418 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
5422 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
5423 record_builtin_type ((enum rid
)(RID_FIRST_INT_N
+ i
), name
,
5424 int_n_trees
[i
].signed_type
);
5425 sprintf (name
, "__int%d unsigned", int_n_data
[i
].bitsize
);
5426 record_builtin_type (RID_MAX
, name
, int_n_trees
[i
].unsigned_type
);
5429 if (c_dialect_cxx ())
5430 record_builtin_type (RID_MAX
, "unsigned long", long_unsigned_type_node
);
5431 record_builtin_type (RID_MAX
, "long long int",
5432 long_long_integer_type_node
);
5433 record_builtin_type (RID_MAX
, "long long unsigned int",
5434 long_long_unsigned_type_node
);
5435 if (c_dialect_cxx ())
5436 record_builtin_type (RID_MAX
, "long long unsigned",
5437 long_long_unsigned_type_node
);
5438 record_builtin_type (RID_SHORT
, "short int", short_integer_type_node
);
5439 record_builtin_type (RID_MAX
, "short unsigned int",
5440 short_unsigned_type_node
);
5441 if (c_dialect_cxx ())
5442 record_builtin_type (RID_MAX
, "unsigned short",
5443 short_unsigned_type_node
);
5445 /* Define both `signed char' and `unsigned char'. */
5446 record_builtin_type (RID_MAX
, "signed char", signed_char_type_node
);
5447 record_builtin_type (RID_MAX
, "unsigned char", unsigned_char_type_node
);
5449 /* These are types that c_common_type_for_size and
5450 c_common_type_for_mode use. */
5451 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5452 TYPE_DECL
, NULL_TREE
,
5454 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5455 TYPE_DECL
, NULL_TREE
,
5457 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5458 TYPE_DECL
, NULL_TREE
,
5460 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5461 TYPE_DECL
, NULL_TREE
,
5463 #if HOST_BITS_PER_WIDE_INT >= 64
5464 /* Note that this is different than the __int128 type that's part of
5465 the generic __intN support. */
5466 if (targetm
.scalar_mode_supported_p (TImode
))
5467 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5469 get_identifier ("__int128_t"),
5472 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5473 TYPE_DECL
, NULL_TREE
,
5474 unsigned_intQI_type_node
));
5475 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5476 TYPE_DECL
, NULL_TREE
,
5477 unsigned_intHI_type_node
));
5478 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5479 TYPE_DECL
, NULL_TREE
,
5480 unsigned_intSI_type_node
));
5481 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5482 TYPE_DECL
, NULL_TREE
,
5483 unsigned_intDI_type_node
));
5484 #if HOST_BITS_PER_WIDE_INT >= 64
5485 if (targetm
.scalar_mode_supported_p (TImode
))
5486 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5488 get_identifier ("__uint128_t"),
5489 unsigned_intTI_type_node
));
5492 /* Create the widest literal types. */
5493 widest_integer_literal_type_node
5494 = make_signed_type (HOST_BITS_PER_WIDE_INT
* 2);
5495 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5496 TYPE_DECL
, NULL_TREE
,
5497 widest_integer_literal_type_node
));
5499 widest_unsigned_literal_type_node
5500 = make_unsigned_type (HOST_BITS_PER_WIDE_INT
* 2);
5501 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5502 TYPE_DECL
, NULL_TREE
,
5503 widest_unsigned_literal_type_node
));
5505 signed_size_type_node
= c_common_signed_type (size_type_node
);
5508 TREE_TYPE (identifier_global_value (get_identifier (PID_TYPE
)));
5510 record_builtin_type (RID_FLOAT
, NULL
, float_type_node
);
5511 record_builtin_type (RID_DOUBLE
, NULL
, double_type_node
);
5512 record_builtin_type (RID_MAX
, "long double", long_double_type_node
);
5514 if (!c_dialect_cxx ())
5515 for (i
= 0; i
< NUM_FLOATN_NX_TYPES
; i
++)
5516 if (FLOATN_NX_TYPE_NODE (i
) != NULL_TREE
)
5517 record_builtin_type ((enum rid
) (RID_FLOATN_NX_FIRST
+ i
), NULL
,
5518 FLOATN_NX_TYPE_NODE (i
));
5520 /* Only supported decimal floating point extension if the target
5521 actually supports underlying modes. */
5522 if (targetm
.scalar_mode_supported_p (SDmode
)
5523 && targetm
.scalar_mode_supported_p (DDmode
)
5524 && targetm
.scalar_mode_supported_p (TDmode
))
5526 record_builtin_type (RID_DFLOAT32
, NULL
, dfloat32_type_node
);
5527 record_builtin_type (RID_DFLOAT64
, NULL
, dfloat64_type_node
);
5528 record_builtin_type (RID_DFLOAT128
, NULL
, dfloat128_type_node
);
5531 if (targetm
.fixed_point_supported_p ())
5533 record_builtin_type (RID_MAX
, "short _Fract", short_fract_type_node
);
5534 record_builtin_type (RID_FRACT
, NULL
, fract_type_node
);
5535 record_builtin_type (RID_MAX
, "long _Fract", long_fract_type_node
);
5536 record_builtin_type (RID_MAX
, "long long _Fract",
5537 long_long_fract_type_node
);
5538 record_builtin_type (RID_MAX
, "unsigned short _Fract",
5539 unsigned_short_fract_type_node
);
5540 record_builtin_type (RID_MAX
, "unsigned _Fract",
5541 unsigned_fract_type_node
);
5542 record_builtin_type (RID_MAX
, "unsigned long _Fract",
5543 unsigned_long_fract_type_node
);
5544 record_builtin_type (RID_MAX
, "unsigned long long _Fract",
5545 unsigned_long_long_fract_type_node
);
5546 record_builtin_type (RID_MAX
, "_Sat short _Fract",
5547 sat_short_fract_type_node
);
5548 record_builtin_type (RID_MAX
, "_Sat _Fract", sat_fract_type_node
);
5549 record_builtin_type (RID_MAX
, "_Sat long _Fract",
5550 sat_long_fract_type_node
);
5551 record_builtin_type (RID_MAX
, "_Sat long long _Fract",
5552 sat_long_long_fract_type_node
);
5553 record_builtin_type (RID_MAX
, "_Sat unsigned short _Fract",
5554 sat_unsigned_short_fract_type_node
);
5555 record_builtin_type (RID_MAX
, "_Sat unsigned _Fract",
5556 sat_unsigned_fract_type_node
);
5557 record_builtin_type (RID_MAX
, "_Sat unsigned long _Fract",
5558 sat_unsigned_long_fract_type_node
);
5559 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Fract",
5560 sat_unsigned_long_long_fract_type_node
);
5561 record_builtin_type (RID_MAX
, "short _Accum", short_accum_type_node
);
5562 record_builtin_type (RID_ACCUM
, NULL
, accum_type_node
);
5563 record_builtin_type (RID_MAX
, "long _Accum", long_accum_type_node
);
5564 record_builtin_type (RID_MAX
, "long long _Accum",
5565 long_long_accum_type_node
);
5566 record_builtin_type (RID_MAX
, "unsigned short _Accum",
5567 unsigned_short_accum_type_node
);
5568 record_builtin_type (RID_MAX
, "unsigned _Accum",
5569 unsigned_accum_type_node
);
5570 record_builtin_type (RID_MAX
, "unsigned long _Accum",
5571 unsigned_long_accum_type_node
);
5572 record_builtin_type (RID_MAX
, "unsigned long long _Accum",
5573 unsigned_long_long_accum_type_node
);
5574 record_builtin_type (RID_MAX
, "_Sat short _Accum",
5575 sat_short_accum_type_node
);
5576 record_builtin_type (RID_MAX
, "_Sat _Accum", sat_accum_type_node
);
5577 record_builtin_type (RID_MAX
, "_Sat long _Accum",
5578 sat_long_accum_type_node
);
5579 record_builtin_type (RID_MAX
, "_Sat long long _Accum",
5580 sat_long_long_accum_type_node
);
5581 record_builtin_type (RID_MAX
, "_Sat unsigned short _Accum",
5582 sat_unsigned_short_accum_type_node
);
5583 record_builtin_type (RID_MAX
, "_Sat unsigned _Accum",
5584 sat_unsigned_accum_type_node
);
5585 record_builtin_type (RID_MAX
, "_Sat unsigned long _Accum",
5586 sat_unsigned_long_accum_type_node
);
5587 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Accum",
5588 sat_unsigned_long_long_accum_type_node
);
5592 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5594 get_identifier ("complex int"),
5595 complex_integer_type_node
));
5596 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5598 get_identifier ("complex float"),
5599 complex_float_type_node
));
5600 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5602 get_identifier ("complex double"),
5603 complex_double_type_node
));
5604 lang_hooks
.decls
.pushdecl
5605 (build_decl (UNKNOWN_LOCATION
,
5606 TYPE_DECL
, get_identifier ("complex long double"),
5607 complex_long_double_type_node
));
5609 if (!c_dialect_cxx ())
5610 for (i
= 0; i
< NUM_FLOATN_NX_TYPES
; i
++)
5611 if (COMPLEX_FLOATN_NX_TYPE_NODE (i
) != NULL_TREE
)
5614 sprintf (buf
, "complex _Float%d%s", floatn_nx_types
[i
].n
,
5615 floatn_nx_types
[i
].extended
? "x" : "");
5616 lang_hooks
.decls
.pushdecl
5617 (build_decl (UNKNOWN_LOCATION
,
5619 get_identifier (buf
),
5620 COMPLEX_FLOATN_NX_TYPE_NODE (i
)));
5623 if (c_dialect_cxx ())
5624 /* For C++, make fileptr_type_node a distinct void * type until
5625 FILE type is defined. */
5626 fileptr_type_node
= build_variant_type_copy (ptr_type_node
);
5628 record_builtin_type (RID_VOID
, NULL
, void_type_node
);
5630 /* Set the TYPE_NAME for any variants that were built before
5631 record_builtin_type gave names to the built-in types. */
5633 tree void_name
= TYPE_NAME (void_type_node
);
5634 TYPE_NAME (void_type_node
) = NULL_TREE
;
5635 TYPE_NAME (build_qualified_type (void_type_node
, TYPE_QUAL_CONST
))
5637 TYPE_NAME (void_type_node
) = void_name
;
5640 void_list_node
= build_void_list_node ();
5642 /* Make a type to be the domain of a few array types
5643 whose domains don't really matter.
5644 200 is small enough that it always fits in size_t
5645 and large enough that it can hold most function names for the
5646 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
5647 array_domain_type
= build_index_type (size_int (200));
5649 /* Make a type for arrays of characters.
5650 With luck nothing will ever really depend on the length of this
5652 char_array_type_node
5653 = build_array_type (char_type_node
, array_domain_type
);
5655 string_type_node
= build_pointer_type (char_type_node
);
5656 const_string_type_node
5657 = build_pointer_type (build_qualified_type
5658 (char_type_node
, TYPE_QUAL_CONST
));
5660 /* This is special for C++ so functions can be overloaded. */
5661 wchar_type_node
= get_identifier (MODIFIED_WCHAR_TYPE
);
5662 wchar_type_node
= TREE_TYPE (identifier_global_value (wchar_type_node
));
5663 wchar_type_size
= TYPE_PRECISION (wchar_type_node
);
5664 underlying_wchar_type_node
= wchar_type_node
;
5665 if (c_dialect_cxx ())
5667 if (TYPE_UNSIGNED (wchar_type_node
))
5668 wchar_type_node
= make_unsigned_type (wchar_type_size
);
5670 wchar_type_node
= make_signed_type (wchar_type_size
);
5671 record_builtin_type (RID_WCHAR
, "wchar_t", wchar_type_node
);
5674 /* This is for wide string constants. */
5675 wchar_array_type_node
5676 = build_array_type (wchar_type_node
, array_domain_type
);
5678 /* Define 'char16_t'. */
5679 char16_type_node
= get_identifier (CHAR16_TYPE
);
5680 char16_type_node
= TREE_TYPE (identifier_global_value (char16_type_node
));
5681 char16_type_size
= TYPE_PRECISION (char16_type_node
);
5682 if (c_dialect_cxx ())
5684 char16_type_node
= make_unsigned_type (char16_type_size
);
5686 if (cxx_dialect
>= cxx11
)
5687 record_builtin_type (RID_CHAR16
, "char16_t", char16_type_node
);
5690 /* This is for UTF-16 string constants. */
5691 char16_array_type_node
5692 = build_array_type (char16_type_node
, array_domain_type
);
5694 /* Define 'char32_t'. */
5695 char32_type_node
= get_identifier (CHAR32_TYPE
);
5696 char32_type_node
= TREE_TYPE (identifier_global_value (char32_type_node
));
5697 char32_type_size
= TYPE_PRECISION (char32_type_node
);
5698 if (c_dialect_cxx ())
5700 char32_type_node
= make_unsigned_type (char32_type_size
);
5702 if (cxx_dialect
>= cxx11
)
5703 record_builtin_type (RID_CHAR32
, "char32_t", char32_type_node
);
5706 /* This is for UTF-32 string constants. */
5707 char32_array_type_node
5708 = build_array_type (char32_type_node
, array_domain_type
);
5711 TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE
)));
5714 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE
)));
5716 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE
)));
5718 if (SIG_ATOMIC_TYPE
)
5719 sig_atomic_type_node
=
5720 TREE_TYPE (identifier_global_value (c_get_ident (SIG_ATOMIC_TYPE
)));
5723 TREE_TYPE (identifier_global_value (c_get_ident (INT8_TYPE
)));
5726 TREE_TYPE (identifier_global_value (c_get_ident (INT16_TYPE
)));
5729 TREE_TYPE (identifier_global_value (c_get_ident (INT32_TYPE
)));
5732 TREE_TYPE (identifier_global_value (c_get_ident (INT64_TYPE
)));
5735 TREE_TYPE (identifier_global_value (c_get_ident (UINT8_TYPE
)));
5737 c_uint16_type_node
= uint16_type_node
=
5738 TREE_TYPE (identifier_global_value (c_get_ident (UINT16_TYPE
)));
5740 c_uint32_type_node
= uint32_type_node
=
5741 TREE_TYPE (identifier_global_value (c_get_ident (UINT32_TYPE
)));
5743 c_uint64_type_node
= uint64_type_node
=
5744 TREE_TYPE (identifier_global_value (c_get_ident (UINT64_TYPE
)));
5745 if (INT_LEAST8_TYPE
)
5746 int_least8_type_node
=
5747 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST8_TYPE
)));
5748 if (INT_LEAST16_TYPE
)
5749 int_least16_type_node
=
5750 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST16_TYPE
)));
5751 if (INT_LEAST32_TYPE
)
5752 int_least32_type_node
=
5753 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST32_TYPE
)));
5754 if (INT_LEAST64_TYPE
)
5755 int_least64_type_node
=
5756 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST64_TYPE
)));
5757 if (UINT_LEAST8_TYPE
)
5758 uint_least8_type_node
=
5759 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST8_TYPE
)));
5760 if (UINT_LEAST16_TYPE
)
5761 uint_least16_type_node
=
5762 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST16_TYPE
)));
5763 if (UINT_LEAST32_TYPE
)
5764 uint_least32_type_node
=
5765 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST32_TYPE
)));
5766 if (UINT_LEAST64_TYPE
)
5767 uint_least64_type_node
=
5768 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST64_TYPE
)));
5770 int_fast8_type_node
=
5771 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST8_TYPE
)));
5772 if (INT_FAST16_TYPE
)
5773 int_fast16_type_node
=
5774 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST16_TYPE
)));
5775 if (INT_FAST32_TYPE
)
5776 int_fast32_type_node
=
5777 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST32_TYPE
)));
5778 if (INT_FAST64_TYPE
)
5779 int_fast64_type_node
=
5780 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST64_TYPE
)));
5781 if (UINT_FAST8_TYPE
)
5782 uint_fast8_type_node
=
5783 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST8_TYPE
)));
5784 if (UINT_FAST16_TYPE
)
5785 uint_fast16_type_node
=
5786 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST16_TYPE
)));
5787 if (UINT_FAST32_TYPE
)
5788 uint_fast32_type_node
=
5789 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST32_TYPE
)));
5790 if (UINT_FAST64_TYPE
)
5791 uint_fast64_type_node
=
5792 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST64_TYPE
)));
5795 TREE_TYPE (identifier_global_value (c_get_ident (INTPTR_TYPE
)));
5798 TREE_TYPE (identifier_global_value (c_get_ident (UINTPTR_TYPE
)));
5800 default_function_type
5801 = build_varargs_function_type_list (integer_type_node
, NULL_TREE
);
5803 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE
)));
5804 unsigned_ptrdiff_type_node
= c_common_unsigned_type (ptrdiff_type_node
);
5806 lang_hooks
.decls
.pushdecl
5807 (build_decl (UNKNOWN_LOCATION
,
5808 TYPE_DECL
, get_identifier ("__builtin_va_list"),
5809 va_list_type_node
));
5810 if (targetm
.enum_va_list_p
)
5816 for (l
= 0; targetm
.enum_va_list_p (l
, &pname
, &ptype
); ++l
)
5818 lang_hooks
.decls
.pushdecl
5819 (build_decl (UNKNOWN_LOCATION
,
5820 TYPE_DECL
, get_identifier (pname
),
5826 if (TREE_CODE (va_list_type_node
) == ARRAY_TYPE
)
5828 va_list_arg_type_node
= va_list_ref_type_node
=
5829 build_pointer_type (TREE_TYPE (va_list_type_node
));
5833 va_list_arg_type_node
= va_list_type_node
;
5834 va_list_ref_type_node
= build_reference_type (va_list_type_node
);
5837 if (!flag_preprocess_only
)
5838 c_define_builtins (va_list_ref_type_node
, va_list_arg_type_node
);
5840 main_identifier_node
= get_identifier ("main");
5842 /* Create the built-in __null node. It is important that this is
5844 null_node
= make_int_cst (1, 1);
5845 TREE_TYPE (null_node
) = c_common_type_for_size (POINTER_SIZE
, 0);
5847 /* Since builtin_types isn't gc'ed, don't export these nodes. */
5848 memset (builtin_types
, 0, sizeof (builtin_types
));
5851 /* The number of named compound-literals generated thus far. */
5852 static GTY(()) int compound_literal_number
;
5854 /* Set DECL_NAME for DECL, a VAR_DECL for a compound-literal. */
5857 set_compound_literal_name (tree decl
)
5860 ASM_FORMAT_PRIVATE_NAME (name
, "__compound_literal",
5861 compound_literal_number
);
5862 compound_literal_number
++;
5863 DECL_NAME (decl
) = get_identifier (name
);
5866 /* build_va_arg helper function. Return a VA_ARG_EXPR with location LOC, type
5867 TYPE and operand OP. */
5870 build_va_arg_1 (location_t loc
, tree type
, tree op
)
5872 tree expr
= build1 (VA_ARG_EXPR
, type
, op
);
5873 SET_EXPR_LOCATION (expr
, loc
);
5877 /* Return a VA_ARG_EXPR corresponding to a source-level expression
5878 va_arg (EXPR, TYPE) at source location LOC. */
5881 build_va_arg (location_t loc
, tree expr
, tree type
)
5883 tree va_type
= TREE_TYPE (expr
);
5884 tree canon_va_type
= (va_type
== error_mark_node
5886 : targetm
.canonical_va_list_type (va_type
));
5888 if (va_type
== error_mark_node
5889 || canon_va_type
== NULL_TREE
)
5891 if (canon_va_type
== NULL_TREE
)
5892 error_at (loc
, "first argument to %<va_arg%> not of type %<va_list%>");
5894 /* Let's handle things neutrallly, if expr:
5895 - has undeclared type, or
5896 - is not an va_list type. */
5897 return build_va_arg_1 (loc
, type
, error_mark_node
);
5900 if (TREE_CODE (canon_va_type
) != ARRAY_TYPE
)
5902 /* Case 1: Not an array type. */
5904 /* Take the address, to get '&ap'. Note that &ap is not a va_list
5906 mark_addressable (expr
);
5907 expr
= build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (expr
)), expr
);
5909 return build_va_arg_1 (loc
, type
, expr
);
5912 /* Case 2: Array type.
5916 For contrast, let's start with the simple case (case 1). If
5917 canon_va_type is not an array type, but say a char *, then when
5918 passing-by-value a va_list, the type of the va_list param decl is
5919 the same as for another va_list decl (all ap's are char *):
5922 D.1815 = VA_ARG (&ap, 0B, 1);
5928 __builtin_va_start (&ap, 0);
5931 __builtin_va_end (&ap);
5935 However, if canon_va_type is ARRAY_TYPE, then when passing-by-value a
5936 va_list the type of the va_list param decl (case 2b, struct * ap) is not
5937 the same as for another va_list decl (case 2a, struct ap[1]).
5940 D.1844 = VA_ARG (ap, 0B, 0);
5945 __builtin_va_start (&ap, 0);
5947 __builtin_va_end (&ap);
5951 Case 2b is different because:
5952 - on the callee side, the parm decl has declared type va_list, but
5953 grokdeclarator changes the type of the parm decl to a pointer to the
5955 - on the caller side, the pass-by-value uses &ap.
5957 We unify these two cases (case 2a: va_list is array type,
5958 case 2b: va_list is pointer to array elem type), by adding '&' for the
5959 array type case, such that we have a pointer to array elem in both
5962 if (TREE_CODE (va_type
) == ARRAY_TYPE
)
5964 /* Case 2a: va_list is array type. */
5966 /* Take the address, to get '&ap'. Make sure it's a pointer to array
5968 mark_addressable (expr
);
5969 expr
= build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (canon_va_type
)),
5972 /* Verify that &ap is still recognized as having va_list type. */
5973 tree canon_expr_type
5974 = targetm
.canonical_va_list_type (TREE_TYPE (expr
));
5975 gcc_assert (canon_expr_type
!= NULL_TREE
);
5979 /* Case 2b: va_list is pointer to array elem type. */
5980 gcc_assert (POINTER_TYPE_P (va_type
));
5982 /* Comparison as in std_canonical_va_list_type. */
5983 gcc_assert (TYPE_MAIN_VARIANT (TREE_TYPE (va_type
))
5984 == TYPE_MAIN_VARIANT (TREE_TYPE (canon_va_type
)));
5986 /* Don't take the address. We've already got '&ap'. */
5990 return build_va_arg_1 (loc
, type
, expr
);
5994 /* Linked list of disabled built-in functions. */
5996 struct disabled_builtin
5999 struct disabled_builtin
*next
;
6001 static disabled_builtin
*disabled_builtins
= NULL
;
6003 static bool builtin_function_disabled_p (const char *);
6005 /* Disable a built-in function specified by -fno-builtin-NAME. If NAME
6006 begins with "__builtin_", give an error. */
6009 disable_builtin_function (const char *name
)
6011 if (strncmp (name
, "__builtin_", strlen ("__builtin_")) == 0)
6012 error ("cannot disable built-in function %qs", name
);
6015 disabled_builtin
*new_disabled_builtin
= XNEW (disabled_builtin
);
6016 new_disabled_builtin
->name
= name
;
6017 new_disabled_builtin
->next
= disabled_builtins
;
6018 disabled_builtins
= new_disabled_builtin
;
6023 /* Return true if the built-in function NAME has been disabled, false
6027 builtin_function_disabled_p (const char *name
)
6029 disabled_builtin
*p
;
6030 for (p
= disabled_builtins
; p
!= NULL
; p
= p
->next
)
6032 if (strcmp (name
, p
->name
) == 0)
6039 /* Worker for DEF_BUILTIN.
6040 Possibly define a builtin function with one or two names.
6041 Does not declare a non-__builtin_ function if flag_no_builtin, or if
6042 nonansi_p and flag_no_nonansi_builtin. */
6045 def_builtin_1 (enum built_in_function fncode
,
6047 enum built_in_class fnclass
,
6048 tree fntype
, tree libtype
,
6049 bool both_p
, bool fallback_p
, bool nonansi_p
,
6050 tree fnattrs
, bool implicit_p
)
6053 const char *libname
;
6055 if (fntype
== error_mark_node
)
6058 gcc_assert ((!both_p
&& !fallback_p
)
6059 || !strncmp (name
, "__builtin_",
6060 strlen ("__builtin_")));
6062 libname
= name
+ strlen ("__builtin_");
6063 decl
= add_builtin_function (name
, fntype
, fncode
, fnclass
,
6064 (fallback_p
? libname
: NULL
),
6067 set_builtin_decl (fncode
, decl
, implicit_p
);
6070 && !flag_no_builtin
&& !builtin_function_disabled_p (libname
)
6071 && !(nonansi_p
&& flag_no_nonansi_builtin
))
6072 add_builtin_function (libname
, libtype
, fncode
, fnclass
,
6076 /* Nonzero if the type T promotes to int. This is (nearly) the
6077 integral promotions defined in ISO C99 6.3.1.1/2. */
6080 c_promoting_integer_type_p (const_tree t
)
6082 switch (TREE_CODE (t
))
6085 return (TYPE_MAIN_VARIANT (t
) == char_type_node
6086 || TYPE_MAIN_VARIANT (t
) == signed_char_type_node
6087 || TYPE_MAIN_VARIANT (t
) == unsigned_char_type_node
6088 || TYPE_MAIN_VARIANT (t
) == short_integer_type_node
6089 || TYPE_MAIN_VARIANT (t
) == short_unsigned_type_node
6090 || TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
));
6093 /* ??? Technically all enumerations not larger than an int
6094 promote to an int. But this is used along code paths
6095 that only want to notice a size change. */
6096 return TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
);
6106 /* Return 1 if PARMS specifies a fixed number of parameters
6107 and none of their types is affected by default promotions. */
6110 self_promoting_args_p (const_tree parms
)
6113 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
6115 tree type
= TREE_VALUE (t
);
6117 if (type
== error_mark_node
)
6120 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
6126 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
6129 if (c_promoting_integer_type_p (type
))
6135 /* Recursively remove any '*' or '&' operator from TYPE. */
6137 strip_pointer_operator (tree t
)
6139 while (POINTER_TYPE_P (t
))
6144 /* Recursively remove pointer or array type from TYPE. */
6146 strip_pointer_or_array_types (tree t
)
6148 while (TREE_CODE (t
) == ARRAY_TYPE
|| POINTER_TYPE_P (t
))
6153 /* Used to compare case labels. K1 and K2 are actually tree nodes
6154 representing case labels, or NULL_TREE for a `default' label.
6155 Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after
6156 K2, and 0 if K1 and K2 are equal. */
6159 case_compare (splay_tree_key k1
, splay_tree_key k2
)
6161 /* Consider a NULL key (such as arises with a `default' label) to be
6162 smaller than anything else. */
6168 return tree_int_cst_compare ((tree
) k1
, (tree
) k2
);
6171 /* Process a case label, located at LOC, for the range LOW_VALUE
6172 ... HIGH_VALUE. If LOW_VALUE and HIGH_VALUE are both NULL_TREE
6173 then this case label is actually a `default' label. If only
6174 HIGH_VALUE is NULL_TREE, then case label was declared using the
6175 usual C/C++ syntax, rather than the GNU case range extension.
6176 CASES is a tree containing all the case ranges processed so far;
6177 COND is the condition for the switch-statement itself.
6178 OUTSIDE_RANGE_P says whether there was a case value that doesn't
6179 fit into the range of the ORIG_TYPE. Returns the CASE_LABEL_EXPR
6180 created, or ERROR_MARK_NODE if no CASE_LABEL_EXPR is created. */
6183 c_add_case_label (location_t loc
, splay_tree cases
, tree cond
, tree orig_type
,
6184 tree low_value
, tree high_value
, bool *outside_range_p
)
6189 splay_tree_node node
;
6191 /* Create the LABEL_DECL itself. */
6192 label
= create_artificial_label (loc
);
6194 /* If there was an error processing the switch condition, bail now
6195 before we get more confused. */
6196 if (!cond
|| cond
== error_mark_node
)
6199 if ((low_value
&& TREE_TYPE (low_value
)
6200 && POINTER_TYPE_P (TREE_TYPE (low_value
)))
6201 || (high_value
&& TREE_TYPE (high_value
)
6202 && POINTER_TYPE_P (TREE_TYPE (high_value
))))
6204 error_at (loc
, "pointers are not permitted as case values");
6208 /* Case ranges are a GNU extension. */
6210 pedwarn (loc
, OPT_Wpedantic
,
6211 "range expressions in switch statements are non-standard");
6213 type
= TREE_TYPE (cond
);
6216 low_value
= check_case_value (loc
, low_value
);
6217 low_value
= convert_and_check (loc
, type
, low_value
);
6218 if (low_value
== error_mark_node
)
6223 high_value
= check_case_value (loc
, high_value
);
6224 high_value
= convert_and_check (loc
, type
, high_value
);
6225 if (high_value
== error_mark_node
)
6229 if (low_value
&& high_value
)
6231 /* If the LOW_VALUE and HIGH_VALUE are the same, then this isn't
6232 really a case range, even though it was written that way.
6233 Remove the HIGH_VALUE to simplify later processing. */
6234 if (tree_int_cst_equal (low_value
, high_value
))
6235 high_value
= NULL_TREE
;
6236 else if (!tree_int_cst_lt (low_value
, high_value
))
6237 warning_at (loc
, 0, "empty range specified");
6240 /* See if the case is in range of the type of the original testing
6241 expression. If both low_value and high_value are out of range,
6242 don't insert the case label and return NULL_TREE. */
6244 && !check_case_bounds (loc
, type
, orig_type
,
6245 &low_value
, high_value
? &high_value
: NULL
,
6249 /* Look up the LOW_VALUE in the table of case labels we already
6251 node
= splay_tree_lookup (cases
, (splay_tree_key
) low_value
);
6252 /* If there was not an exact match, check for overlapping ranges.
6253 There's no need to do this if there's no LOW_VALUE or HIGH_VALUE;
6254 that's a `default' label and the only overlap is an exact match. */
6255 if (!node
&& (low_value
|| high_value
))
6257 splay_tree_node low_bound
;
6258 splay_tree_node high_bound
;
6260 /* Even though there wasn't an exact match, there might be an
6261 overlap between this case range and another case range.
6262 Since we've (inductively) not allowed any overlapping case
6263 ranges, we simply need to find the greatest low case label
6264 that is smaller that LOW_VALUE, and the smallest low case
6265 label that is greater than LOW_VALUE. If there is an overlap
6266 it will occur in one of these two ranges. */
6267 low_bound
= splay_tree_predecessor (cases
,
6268 (splay_tree_key
) low_value
);
6269 high_bound
= splay_tree_successor (cases
,
6270 (splay_tree_key
) low_value
);
6272 /* Check to see if the LOW_BOUND overlaps. It is smaller than
6273 the LOW_VALUE, so there is no need to check unless the
6274 LOW_BOUND is in fact itself a case range. */
6276 && CASE_HIGH ((tree
) low_bound
->value
)
6277 && tree_int_cst_compare (CASE_HIGH ((tree
) low_bound
->value
),
6280 /* Check to see if the HIGH_BOUND overlaps. The low end of that
6281 range is bigger than the low end of the current range, so we
6282 are only interested if the current range is a real range, and
6283 not an ordinary case label. */
6286 && (tree_int_cst_compare ((tree
) high_bound
->key
,
6291 /* If there was an overlap, issue an error. */
6294 tree duplicate
= CASE_LABEL ((tree
) node
->value
);
6298 error_at (loc
, "duplicate (or overlapping) case value");
6299 error_at (DECL_SOURCE_LOCATION (duplicate
),
6300 "this is the first entry overlapping that value");
6304 error_at (loc
, "duplicate case value") ;
6305 error_at (DECL_SOURCE_LOCATION (duplicate
), "previously used here");
6309 error_at (loc
, "multiple default labels in one switch");
6310 error_at (DECL_SOURCE_LOCATION (duplicate
),
6311 "this is the first default label");
6316 /* Add a CASE_LABEL to the statement-tree. */
6317 case_label
= add_stmt (build_case_label (low_value
, high_value
, label
));
6318 /* Register this case label in the splay tree. */
6319 splay_tree_insert (cases
,
6320 (splay_tree_key
) low_value
,
6321 (splay_tree_value
) case_label
);
6326 /* Add a label so that the back-end doesn't think that the beginning of
6327 the switch is unreachable. Note that we do not add a case label, as
6328 that just leads to duplicates and thence to failure later on. */
6331 tree t
= create_artificial_label (loc
);
6332 add_stmt (build_stmt (loc
, LABEL_EXPR
, t
));
6334 return error_mark_node
;
6337 /* Subroutines of c_do_switch_warnings, called via splay_tree_foreach.
6338 Used to verify that case values match up with enumerator values. */
6341 match_case_to_enum_1 (tree key
, tree type
, tree label
)
6343 char buf
[WIDE_INT_PRINT_BUFFER_SIZE
];
6345 if (tree_fits_uhwi_p (key
))
6346 print_dec (key
, buf
, UNSIGNED
);
6347 else if (tree_fits_shwi_p (key
))
6348 print_dec (key
, buf
, SIGNED
);
6350 print_hex (key
, buf
);
6352 if (TYPE_NAME (type
) == 0)
6353 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
6354 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
6355 "case value %qs not in enumerated type",
6358 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
6359 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
6360 "case value %qs not in enumerated type %qT",
6364 /* Subroutine of c_do_switch_warnings, called via splay_tree_foreach.
6365 Used to verify that case values match up with enumerator values. */
6368 match_case_to_enum (splay_tree_node node
, void *data
)
6370 tree label
= (tree
) node
->value
;
6371 tree type
= (tree
) data
;
6373 /* Skip default case. */
6374 if (!CASE_LOW (label
))
6377 /* If CASE_LOW_SEEN is not set, that means CASE_LOW did not appear
6378 when we did our enum->case scan. Reset our scratch bit after. */
6379 if (!CASE_LOW_SEEN (label
))
6380 match_case_to_enum_1 (CASE_LOW (label
), type
, label
);
6382 CASE_LOW_SEEN (label
) = 0;
6384 /* If CASE_HIGH is non-null, we have a range. If CASE_HIGH_SEEN is
6385 not set, that means that CASE_HIGH did not appear when we did our
6386 enum->case scan. Reset our scratch bit after. */
6387 if (CASE_HIGH (label
))
6389 if (!CASE_HIGH_SEEN (label
))
6390 match_case_to_enum_1 (CASE_HIGH (label
), type
, label
);
6392 CASE_HIGH_SEEN (label
) = 0;
6398 /* Handle -Wswitch*. Called from the front end after parsing the
6399 switch construct. */
6400 /* ??? Should probably be somewhere generic, since other languages
6401 besides C and C++ would want this. At the moment, however, C/C++
6402 are the only tree-ssa languages that support enumerations at all,
6403 so the point is moot. */
6406 c_do_switch_warnings (splay_tree cases
, location_t switch_location
,
6407 tree type
, tree cond
, bool bool_cond_p
,
6408 bool outside_range_p
)
6410 splay_tree_node default_node
;
6411 splay_tree_node node
;
6414 if (!warn_switch
&& !warn_switch_enum
&& !warn_switch_default
6415 && !warn_switch_bool
)
6418 default_node
= splay_tree_lookup (cases
, (splay_tree_key
) NULL
);
6420 warning_at (switch_location
, OPT_Wswitch_default
,
6421 "switch missing default case");
6423 /* There are certain cases where -Wswitch-bool warnings aren't
6430 so be careful here. */
6431 if (warn_switch_bool
&& bool_cond_p
)
6433 splay_tree_node min_node
;
6434 /* If there's a default node, it's also the value with the minimal
6435 key. So look at the penultimate key (if any). */
6437 min_node
= splay_tree_successor (cases
, (splay_tree_key
) NULL
);
6439 min_node
= splay_tree_min (cases
);
6440 tree min
= min_node
? (tree
) min_node
->key
: NULL_TREE
;
6442 splay_tree_node max_node
= splay_tree_max (cases
);
6443 /* This might be a case range, so look at the value with the
6444 maximal key and then check CASE_HIGH. */
6445 tree max
= max_node
? (tree
) max_node
->value
: NULL_TREE
;
6447 max
= CASE_HIGH (max
) ? CASE_HIGH (max
) : CASE_LOW (max
);
6449 /* If there's a case value > 1 or < 0, that is outside bool
6452 || (max
&& wi::gts_p (max
, 1))
6453 || (min
&& wi::lts_p (min
, 0))
6461 case, where we want to warn. */
6463 && max
&& wi::eq_p (max
, 1)
6464 && min
&& wi::eq_p (min
, 0)))
6465 warning_at (switch_location
, OPT_Wswitch_bool
,
6466 "switch condition has boolean value");
6469 /* From here on, we only care about enumerated types. */
6470 if (!type
|| TREE_CODE (type
) != ENUMERAL_TYPE
)
6473 /* From here on, we only care about -Wswitch and -Wswitch-enum. */
6474 if (!warn_switch_enum
&& !warn_switch
)
6477 /* Check the cases. Warn about case values which are not members of
6478 the enumerated type. For -Wswitch-enum, or for -Wswitch when
6479 there is no default case, check that exactly all enumeration
6480 literals are covered by the cases. */
6482 /* Clearing COND if it is not an integer constant simplifies
6483 the tests inside the loop below. */
6484 if (TREE_CODE (cond
) != INTEGER_CST
)
6487 /* The time complexity here is O(N*lg(N)) worst case, but for the
6488 common case of monotonically increasing enumerators, it is
6489 O(N), since the nature of the splay tree will keep the next
6490 element adjacent to the root at all times. */
6492 for (chain
= TYPE_VALUES (type
); chain
; chain
= TREE_CHAIN (chain
))
6494 tree value
= TREE_VALUE (chain
);
6495 if (TREE_CODE (value
) == CONST_DECL
)
6496 value
= DECL_INITIAL (value
);
6497 node
= splay_tree_lookup (cases
, (splay_tree_key
) value
);
6500 /* Mark the CASE_LOW part of the case entry as seen. */
6501 tree label
= (tree
) node
->value
;
6502 CASE_LOW_SEEN (label
) = 1;
6506 /* Even though there wasn't an exact match, there might be a
6507 case range which includes the enumerator's value. */
6508 node
= splay_tree_predecessor (cases
, (splay_tree_key
) value
);
6509 if (node
&& CASE_HIGH ((tree
) node
->value
))
6511 tree label
= (tree
) node
->value
;
6512 int cmp
= tree_int_cst_compare (CASE_HIGH (label
), value
);
6515 /* If we match the upper bound exactly, mark the CASE_HIGH
6516 part of the case entry as seen. */
6518 CASE_HIGH_SEEN (label
) = 1;
6523 /* We've now determined that this enumerated literal isn't
6524 handled by the case labels of the switch statement. */
6526 /* If the switch expression is a constant, we only really care
6527 about whether that constant is handled by the switch. */
6528 if (cond
&& tree_int_cst_compare (cond
, value
))
6531 /* If there is a default_node, the only relevant option is
6532 Wswitch-enum. Otherwise, if both are enabled then we prefer
6533 to warn using -Wswitch because -Wswitch is enabled by -Wall
6534 while -Wswitch-enum is explicit. */
6535 warning_at (switch_location
,
6536 (default_node
|| !warn_switch
6539 "enumeration value %qE not handled in switch",
6540 TREE_PURPOSE (chain
));
6543 /* Warn if there are case expressions that don't correspond to
6544 enumerators. This can occur since C and C++ don't enforce
6545 type-checking of assignments to enumeration variables.
6547 The time complexity here is now always O(N) worst case, since
6548 we should have marked both the lower bound and upper bound of
6549 every disjoint case label, with CASE_LOW_SEEN and CASE_HIGH_SEEN
6550 above. This scan also resets those fields. */
6552 splay_tree_foreach (cases
, match_case_to_enum
, type
);
6555 /* Finish an expression taking the address of LABEL (an
6556 IDENTIFIER_NODE). Returns an expression for the address.
6558 LOC is the location for the expression returned. */
6561 finish_label_address_expr (tree label
, location_t loc
)
6565 pedwarn (input_location
, OPT_Wpedantic
, "taking the address of a label is non-standard");
6567 if (label
== error_mark_node
)
6568 return error_mark_node
;
6570 label
= lookup_label (label
);
6571 if (label
== NULL_TREE
)
6572 result
= null_pointer_node
;
6575 TREE_USED (label
) = 1;
6576 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
6577 /* The current function is not necessarily uninlinable.
6578 Computed gotos are incompatible with inlining, but the value
6579 here could be used only in a diagnostic, for example. */
6580 protected_set_expr_location (result
, loc
);
6587 /* Given a boolean expression ARG, return a tree representing an increment
6588 or decrement (as indicated by CODE) of ARG. The front end must check for
6589 invalid cases (e.g., decrement in C++). */
6591 boolean_increment (enum tree_code code
, tree arg
)
6594 tree true_res
= build_int_cst (TREE_TYPE (arg
), 1);
6596 arg
= stabilize_reference (arg
);
6599 case PREINCREMENT_EXPR
:
6600 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
6602 case POSTINCREMENT_EXPR
:
6603 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
6604 arg
= save_expr (arg
);
6605 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
6606 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
6608 case PREDECREMENT_EXPR
:
6609 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
6610 invert_truthvalue_loc (input_location
, arg
));
6612 case POSTDECREMENT_EXPR
:
6613 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
6614 invert_truthvalue_loc (input_location
, arg
));
6615 arg
= save_expr (arg
);
6616 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
6617 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
6622 TREE_SIDE_EFFECTS (val
) = 1;
6626 /* Built-in macros for stddef.h and stdint.h, that require macros
6627 defined in this file. */
6629 c_stddef_cpp_builtins(void)
6631 builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE
, 0);
6632 builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE
, 0);
6633 builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE
, 0);
6634 builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE
, 0);
6635 builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE
, 0);
6636 builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE
, 0);
6637 builtin_define_with_value ("__CHAR16_TYPE__", CHAR16_TYPE
, 0);
6638 builtin_define_with_value ("__CHAR32_TYPE__", CHAR32_TYPE
, 0);
6639 if (SIG_ATOMIC_TYPE
)
6640 builtin_define_with_value ("__SIG_ATOMIC_TYPE__", SIG_ATOMIC_TYPE
, 0);
6642 builtin_define_with_value ("__INT8_TYPE__", INT8_TYPE
, 0);
6644 builtin_define_with_value ("__INT16_TYPE__", INT16_TYPE
, 0);
6646 builtin_define_with_value ("__INT32_TYPE__", INT32_TYPE
, 0);
6648 builtin_define_with_value ("__INT64_TYPE__", INT64_TYPE
, 0);
6650 builtin_define_with_value ("__UINT8_TYPE__", UINT8_TYPE
, 0);
6652 builtin_define_with_value ("__UINT16_TYPE__", UINT16_TYPE
, 0);
6654 builtin_define_with_value ("__UINT32_TYPE__", UINT32_TYPE
, 0);
6656 builtin_define_with_value ("__UINT64_TYPE__", UINT64_TYPE
, 0);
6657 if (INT_LEAST8_TYPE
)
6658 builtin_define_with_value ("__INT_LEAST8_TYPE__", INT_LEAST8_TYPE
, 0);
6659 if (INT_LEAST16_TYPE
)
6660 builtin_define_with_value ("__INT_LEAST16_TYPE__", INT_LEAST16_TYPE
, 0);
6661 if (INT_LEAST32_TYPE
)
6662 builtin_define_with_value ("__INT_LEAST32_TYPE__", INT_LEAST32_TYPE
, 0);
6663 if (INT_LEAST64_TYPE
)
6664 builtin_define_with_value ("__INT_LEAST64_TYPE__", INT_LEAST64_TYPE
, 0);
6665 if (UINT_LEAST8_TYPE
)
6666 builtin_define_with_value ("__UINT_LEAST8_TYPE__", UINT_LEAST8_TYPE
, 0);
6667 if (UINT_LEAST16_TYPE
)
6668 builtin_define_with_value ("__UINT_LEAST16_TYPE__", UINT_LEAST16_TYPE
, 0);
6669 if (UINT_LEAST32_TYPE
)
6670 builtin_define_with_value ("__UINT_LEAST32_TYPE__", UINT_LEAST32_TYPE
, 0);
6671 if (UINT_LEAST64_TYPE
)
6672 builtin_define_with_value ("__UINT_LEAST64_TYPE__", UINT_LEAST64_TYPE
, 0);
6674 builtin_define_with_value ("__INT_FAST8_TYPE__", INT_FAST8_TYPE
, 0);
6675 if (INT_FAST16_TYPE
)
6676 builtin_define_with_value ("__INT_FAST16_TYPE__", INT_FAST16_TYPE
, 0);
6677 if (INT_FAST32_TYPE
)
6678 builtin_define_with_value ("__INT_FAST32_TYPE__", INT_FAST32_TYPE
, 0);
6679 if (INT_FAST64_TYPE
)
6680 builtin_define_with_value ("__INT_FAST64_TYPE__", INT_FAST64_TYPE
, 0);
6681 if (UINT_FAST8_TYPE
)
6682 builtin_define_with_value ("__UINT_FAST8_TYPE__", UINT_FAST8_TYPE
, 0);
6683 if (UINT_FAST16_TYPE
)
6684 builtin_define_with_value ("__UINT_FAST16_TYPE__", UINT_FAST16_TYPE
, 0);
6685 if (UINT_FAST32_TYPE
)
6686 builtin_define_with_value ("__UINT_FAST32_TYPE__", UINT_FAST32_TYPE
, 0);
6687 if (UINT_FAST64_TYPE
)
6688 builtin_define_with_value ("__UINT_FAST64_TYPE__", UINT_FAST64_TYPE
, 0);
6690 builtin_define_with_value ("__INTPTR_TYPE__", INTPTR_TYPE
, 0);
6692 builtin_define_with_value ("__UINTPTR_TYPE__", UINTPTR_TYPE
, 0);
6696 c_init_attributes (void)
6698 /* Fill in the built_in_attributes array. */
6699 #define DEF_ATTR_NULL_TREE(ENUM) \
6700 built_in_attributes[(int) ENUM] = NULL_TREE;
6701 #define DEF_ATTR_INT(ENUM, VALUE) \
6702 built_in_attributes[(int) ENUM] = build_int_cst (integer_type_node, VALUE);
6703 #define DEF_ATTR_STRING(ENUM, VALUE) \
6704 built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
6705 #define DEF_ATTR_IDENT(ENUM, STRING) \
6706 built_in_attributes[(int) ENUM] = get_identifier (STRING);
6707 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
6708 built_in_attributes[(int) ENUM] \
6709 = tree_cons (built_in_attributes[(int) PURPOSE], \
6710 built_in_attributes[(int) VALUE], \
6711 built_in_attributes[(int) CHAIN]);
6712 #include "builtin-attrs.def"
6713 #undef DEF_ATTR_NULL_TREE
6715 #undef DEF_ATTR_IDENT
6716 #undef DEF_ATTR_TREE_LIST
6719 /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain
6720 identifier as an argument, so the front end shouldn't look it up. */
6723 attribute_takes_identifier_p (const_tree attr_id
)
6725 const struct attribute_spec
*spec
= lookup_attribute_spec (attr_id
);
6727 /* Unknown attribute that we'll end up ignoring, return true so we
6728 don't complain about an identifier argument. */
6730 else if (!strcmp ("mode", spec
->name
)
6731 || !strcmp ("format", spec
->name
)
6732 || !strcmp ("cleanup", spec
->name
))
6735 return targetm
.attribute_takes_identifier_p (attr_id
);
6738 /* Attribute handlers common to C front ends. */
6740 /* Handle a "packed" attribute; arguments as in
6741 struct attribute_spec.handler. */
6744 handle_packed_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6745 int flags
, bool *no_add_attrs
)
6749 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6750 *node
= build_variant_type_copy (*node
);
6751 TYPE_PACKED (*node
) = 1;
6753 else if (TREE_CODE (*node
) == FIELD_DECL
)
6755 if (TYPE_ALIGN (TREE_TYPE (*node
)) <= BITS_PER_UNIT
6756 /* Still pack bitfields. */
6757 && ! DECL_INITIAL (*node
))
6758 warning (OPT_Wattributes
,
6759 "%qE attribute ignored for field of type %qT",
6760 name
, TREE_TYPE (*node
));
6762 DECL_PACKED (*node
) = 1;
6764 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
6765 used for DECL_REGISTER. It wouldn't mean anything anyway.
6766 We can't set DECL_PACKED on the type of a TYPE_DECL, because
6767 that changes what the typedef is typing. */
6770 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6771 *no_add_attrs
= true;
6777 /* Handle a "nocommon" attribute; arguments as in
6778 struct attribute_spec.handler. */
6781 handle_nocommon_attribute (tree
*node
, tree name
,
6782 tree
ARG_UNUSED (args
),
6783 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6786 DECL_COMMON (*node
) = 0;
6789 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6790 *no_add_attrs
= true;
6796 /* Handle a "common" attribute; arguments as in
6797 struct attribute_spec.handler. */
6800 handle_common_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6801 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6804 DECL_COMMON (*node
) = 1;
6807 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6808 *no_add_attrs
= true;
6814 /* Handle a "noreturn" attribute; arguments as in
6815 struct attribute_spec.handler. */
6818 handle_noreturn_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6819 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6821 tree type
= TREE_TYPE (*node
);
6823 /* See FIXME comment in c_common_attribute_table. */
6824 if (TREE_CODE (*node
) == FUNCTION_DECL
6825 || objc_method_decl (TREE_CODE (*node
)))
6826 TREE_THIS_VOLATILE (*node
) = 1;
6827 else if (TREE_CODE (type
) == POINTER_TYPE
6828 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
6830 = (build_qualified_type
6832 (build_type_variant (TREE_TYPE (type
),
6833 TYPE_READONLY (TREE_TYPE (type
)), 1)),
6834 TYPE_QUALS (type
)));
6837 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6838 *no_add_attrs
= true;
6844 /* Handle a "hot" and attribute; arguments as in
6845 struct attribute_spec.handler. */
6848 handle_hot_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6849 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6851 if (TREE_CODE (*node
) == FUNCTION_DECL
6852 || TREE_CODE (*node
) == LABEL_DECL
)
6854 if (lookup_attribute ("cold", DECL_ATTRIBUTES (*node
)) != NULL
)
6856 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
6857 "with attribute %qs", name
, "cold");
6858 *no_add_attrs
= true;
6860 /* Most of the rest of the hot processing is done later with
6861 lookup_attribute. */
6865 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6866 *no_add_attrs
= true;
6872 /* Handle a "cold" and attribute; arguments as in
6873 struct attribute_spec.handler. */
6876 handle_cold_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6877 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6879 if (TREE_CODE (*node
) == FUNCTION_DECL
6880 || TREE_CODE (*node
) == LABEL_DECL
)
6882 if (lookup_attribute ("hot", DECL_ATTRIBUTES (*node
)) != NULL
)
6884 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
6885 "with attribute %qs", name
, "hot");
6886 *no_add_attrs
= true;
6888 /* Most of the rest of the cold processing is done later with
6889 lookup_attribute. */
6893 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6894 *no_add_attrs
= true;
6900 /* Handle a "no_sanitize_address" attribute; arguments as in
6901 struct attribute_spec.handler. */
6904 handle_no_sanitize_address_attribute (tree
*node
, tree name
, tree
, int,
6907 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6909 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6910 *no_add_attrs
= true;
6916 /* Handle a "no_address_safety_analysis" attribute; arguments as in
6917 struct attribute_spec.handler. */
6920 handle_no_address_safety_analysis_attribute (tree
*node
, tree name
, tree
, int,
6923 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6924 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6925 else if (!lookup_attribute ("no_sanitize_address", DECL_ATTRIBUTES (*node
)))
6926 DECL_ATTRIBUTES (*node
)
6927 = tree_cons (get_identifier ("no_sanitize_address"),
6928 NULL_TREE
, DECL_ATTRIBUTES (*node
));
6929 *no_add_attrs
= true;
6933 /* Handle a "no_sanitize_undefined" attribute; arguments as in
6934 struct attribute_spec.handler. */
6937 handle_no_sanitize_undefined_attribute (tree
*node
, tree name
, tree
, int,
6940 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6942 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6943 *no_add_attrs
= true;
6949 /* Handle a "stack_protect" attribute; arguments as in
6950 struct attribute_spec.handler. */
6952 handle_stack_protect_attribute (tree
*node
, tree name
, tree
, int,
6955 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6957 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6958 *no_add_attrs
= true;
6961 DECL_ATTRIBUTES (*node
)
6962 = tree_cons (get_identifier ("stack_protect"),
6963 NULL_TREE
, DECL_ATTRIBUTES (*node
));
6968 /* Handle a "noinline" attribute; arguments as in
6969 struct attribute_spec.handler. */
6972 handle_noinline_attribute (tree
*node
, tree name
,
6973 tree
ARG_UNUSED (args
),
6974 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6976 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6978 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node
)))
6980 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
6981 "with attribute %qs", name
, "always_inline");
6982 *no_add_attrs
= true;
6985 DECL_UNINLINABLE (*node
) = 1;
6989 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6990 *no_add_attrs
= true;
6996 /* Handle a "noclone" attribute; arguments as in
6997 struct attribute_spec.handler. */
7000 handle_noclone_attribute (tree
*node
, tree name
,
7001 tree
ARG_UNUSED (args
),
7002 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7004 if (TREE_CODE (*node
) != FUNCTION_DECL
)
7006 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7007 *no_add_attrs
= true;
7013 /* Handle a "no_icf" attribute; arguments as in
7014 struct attribute_spec.handler. */
7017 handle_noicf_attribute (tree
*node
, tree name
,
7018 tree
ARG_UNUSED (args
),
7019 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7021 if (TREE_CODE (*node
) != FUNCTION_DECL
)
7023 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7024 *no_add_attrs
= true;
7031 /* Handle a "always_inline" attribute; arguments as in
7032 struct attribute_spec.handler. */
7035 handle_always_inline_attribute (tree
*node
, tree name
,
7036 tree
ARG_UNUSED (args
),
7037 int ARG_UNUSED (flags
),
7040 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7042 if (lookup_attribute ("noinline", DECL_ATTRIBUTES (*node
)))
7044 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
7045 "with %qs attribute", name
, "noinline");
7046 *no_add_attrs
= true;
7048 else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node
)))
7050 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
7051 "with %qs attribute", name
, "target_clones");
7052 *no_add_attrs
= true;
7055 /* Set the attribute and mark it for disregarding inline
7057 DECL_DISREGARD_INLINE_LIMITS (*node
) = 1;
7061 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7062 *no_add_attrs
= true;
7068 /* Handle a "gnu_inline" attribute; arguments as in
7069 struct attribute_spec.handler. */
7072 handle_gnu_inline_attribute (tree
*node
, tree name
,
7073 tree
ARG_UNUSED (args
),
7074 int ARG_UNUSED (flags
),
7077 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
7079 /* Do nothing else, just set the attribute. We'll get at
7080 it later with lookup_attribute. */
7084 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7085 *no_add_attrs
= true;
7091 /* Handle a "leaf" attribute; arguments as in
7092 struct attribute_spec.handler. */
7095 handle_leaf_attribute (tree
*node
, tree name
,
7096 tree
ARG_UNUSED (args
),
7097 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7099 if (TREE_CODE (*node
) != FUNCTION_DECL
)
7101 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7102 *no_add_attrs
= true;
7104 if (!TREE_PUBLIC (*node
))
7106 warning (OPT_Wattributes
, "%qE attribute has no effect on unit local functions", name
);
7107 *no_add_attrs
= true;
7113 /* Handle an "artificial" attribute; arguments as in
7114 struct attribute_spec.handler. */
7117 handle_artificial_attribute (tree
*node
, tree name
,
7118 tree
ARG_UNUSED (args
),
7119 int ARG_UNUSED (flags
),
7122 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
7124 /* Do nothing else, just set the attribute. We'll get at
7125 it later with lookup_attribute. */
7129 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7130 *no_add_attrs
= true;
7136 /* Handle a "flatten" attribute; arguments as in
7137 struct attribute_spec.handler. */
7140 handle_flatten_attribute (tree
*node
, tree name
,
7141 tree args ATTRIBUTE_UNUSED
,
7142 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
7144 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7145 /* Do nothing else, just set the attribute. We'll get at
7146 it later with lookup_attribute. */
7150 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7151 *no_add_attrs
= true;
7157 /* Handle a "warning" or "error" attribute; arguments as in
7158 struct attribute_spec.handler. */
7161 handle_error_attribute (tree
*node
, tree name
, tree args
,
7162 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7164 if (TREE_CODE (*node
) == FUNCTION_DECL
7165 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
7166 /* Do nothing else, just set the attribute. We'll get at
7167 it later with lookup_attribute. */
7171 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7172 *no_add_attrs
= true;
7178 /* Handle a "used" attribute; arguments as in
7179 struct attribute_spec.handler. */
7182 handle_used_attribute (tree
*pnode
, tree name
, tree
ARG_UNUSED (args
),
7183 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7187 if (TREE_CODE (node
) == FUNCTION_DECL
7188 || (VAR_P (node
) && TREE_STATIC (node
))
7189 || (TREE_CODE (node
) == TYPE_DECL
))
7191 TREE_USED (node
) = 1;
7192 DECL_PRESERVE_P (node
) = 1;
7194 DECL_READ_P (node
) = 1;
7198 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7199 *no_add_attrs
= true;
7205 /* Handle a "unused" attribute; arguments as in
7206 struct attribute_spec.handler. */
7209 handle_unused_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7210 int flags
, bool *no_add_attrs
)
7216 if (TREE_CODE (decl
) == PARM_DECL
7217 || VAR_OR_FUNCTION_DECL_P (decl
)
7218 || TREE_CODE (decl
) == LABEL_DECL
7219 || TREE_CODE (decl
) == CONST_DECL
7220 || TREE_CODE (decl
) == TYPE_DECL
)
7222 TREE_USED (decl
) = 1;
7223 if (VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
)
7224 DECL_READ_P (decl
) = 1;
7228 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7229 *no_add_attrs
= true;
7234 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7235 *node
= build_variant_type_copy (*node
);
7236 TREE_USED (*node
) = 1;
7242 /* Handle a "externally_visible" attribute; arguments as in
7243 struct attribute_spec.handler. */
7246 handle_externally_visible_attribute (tree
*pnode
, tree name
,
7247 tree
ARG_UNUSED (args
),
7248 int ARG_UNUSED (flags
),
7253 if (VAR_OR_FUNCTION_DECL_P (node
))
7255 if ((!TREE_STATIC (node
) && TREE_CODE (node
) != FUNCTION_DECL
7256 && !DECL_EXTERNAL (node
)) || !TREE_PUBLIC (node
))
7258 warning (OPT_Wattributes
,
7259 "%qE attribute have effect only on public objects", name
);
7260 *no_add_attrs
= true;
7265 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7266 *no_add_attrs
= true;
7272 /* Handle the "no_reorder" attribute. Arguments as in
7273 struct attribute_spec.handler. */
7276 handle_no_reorder_attribute (tree
*pnode
,
7284 if (!VAR_OR_FUNCTION_DECL_P (node
)
7285 && !(TREE_STATIC (node
) || DECL_EXTERNAL (node
)))
7287 warning (OPT_Wattributes
,
7288 "%qE attribute only affects top level objects",
7290 *no_add_attrs
= true;
7296 /* Handle a "const" attribute; arguments as in
7297 struct attribute_spec.handler. */
7300 handle_const_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7301 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7303 tree type
= TREE_TYPE (*node
);
7305 /* See FIXME comment on noreturn in c_common_attribute_table. */
7306 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7307 TREE_READONLY (*node
) = 1;
7308 else if (TREE_CODE (type
) == POINTER_TYPE
7309 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
7311 = (build_qualified_type
7313 (build_type_variant (TREE_TYPE (type
), 1,
7314 TREE_THIS_VOLATILE (TREE_TYPE (type
)))),
7315 TYPE_QUALS (type
)));
7318 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7319 *no_add_attrs
= true;
7325 /* Handle a "scalar_storage_order" attribute; arguments as in
7326 struct attribute_spec.handler. */
7329 handle_scalar_storage_order_attribute (tree
*node
, tree name
, tree args
,
7330 int flags
, bool *no_add_attrs
)
7332 tree id
= TREE_VALUE (args
);
7335 if (TREE_CODE (*node
) == TYPE_DECL
7336 && ! (flags
& ATTR_FLAG_CXX11
))
7337 node
= &TREE_TYPE (*node
);
7340 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
)
7342 error ("scalar_storage_order is not supported because endianness "
7347 if (RECORD_OR_UNION_TYPE_P (type
) && !c_dialect_cxx ())
7349 bool reverse
= false;
7351 if (TREE_CODE (id
) == STRING_CST
7352 && strcmp (TREE_STRING_POINTER (id
), "big-endian") == 0)
7353 reverse
= !BYTES_BIG_ENDIAN
;
7354 else if (TREE_CODE (id
) == STRING_CST
7355 && strcmp (TREE_STRING_POINTER (id
), "little-endian") == 0)
7356 reverse
= BYTES_BIG_ENDIAN
;
7359 error ("scalar_storage_order argument must be one of \"big-endian\""
7360 " or \"little-endian\"");
7364 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7367 /* A type variant isn't good enough, since we don't want a cast
7368 to such a type to be removed as a no-op. */
7369 *node
= type
= build_duplicate_type (type
);
7372 TYPE_REVERSE_STORAGE_ORDER (type
) = reverse
;
7376 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7377 *no_add_attrs
= true;
7381 /* Handle a "transparent_union" attribute; arguments as in
7382 struct attribute_spec.handler. */
7385 handle_transparent_union_attribute (tree
*node
, tree name
,
7386 tree
ARG_UNUSED (args
), int flags
,
7391 *no_add_attrs
= true;
7393 if (TREE_CODE (*node
) == TYPE_DECL
7394 && ! (flags
& ATTR_FLAG_CXX11
))
7395 node
= &TREE_TYPE (*node
);
7398 if (TREE_CODE (type
) == UNION_TYPE
)
7400 /* Make sure that the first field will work for a transparent union.
7401 If the type isn't complete yet, leave the check to the code in
7403 if (TYPE_SIZE (type
))
7405 tree first
= first_field (type
);
7406 if (first
== NULL_TREE
7407 || DECL_ARTIFICIAL (first
)
7408 || TYPE_MODE (type
) != DECL_MODE (first
))
7412 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7414 /* If the type isn't complete yet, setting the flag
7415 on a variant wouldn't ever be checked. */
7416 if (!TYPE_SIZE (type
))
7419 /* build_duplicate_type doesn't work for C++. */
7420 if (c_dialect_cxx ())
7423 /* A type variant isn't good enough, since we don't want a cast
7424 to such a type to be removed as a no-op. */
7425 *node
= type
= build_duplicate_type (type
);
7428 for (tree t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
7429 TYPE_TRANSPARENT_AGGR (t
) = 1;
7434 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7438 /* Subroutine of handle_{con,de}structor_attribute. Evaluate ARGS to
7439 get the requested priority for a constructor or destructor,
7440 possibly issuing diagnostics for invalid or reserved
7443 static priority_type
7444 get_priority (tree args
, bool is_destructor
)
7450 return DEFAULT_INIT_PRIORITY
;
7452 if (!SUPPORTS_INIT_PRIORITY
)
7455 error ("destructor priorities are not supported");
7457 error ("constructor priorities are not supported");
7458 return DEFAULT_INIT_PRIORITY
;
7461 arg
= TREE_VALUE (args
);
7462 if (TREE_CODE (arg
) == IDENTIFIER_NODE
)
7464 if (arg
== error_mark_node
)
7465 return DEFAULT_INIT_PRIORITY
;
7466 arg
= default_conversion (arg
);
7467 if (!tree_fits_shwi_p (arg
)
7468 || !INTEGRAL_TYPE_P (TREE_TYPE (arg
)))
7471 pri
= tree_to_shwi (arg
);
7472 if (pri
< 0 || pri
> MAX_INIT_PRIORITY
)
7475 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
7479 "destructor priorities from 0 to %d are reserved "
7480 "for the implementation",
7481 MAX_RESERVED_INIT_PRIORITY
);
7484 "constructor priorities from 0 to %d are reserved "
7485 "for the implementation",
7486 MAX_RESERVED_INIT_PRIORITY
);
7492 error ("destructor priorities must be integers from 0 to %d inclusive",
7495 error ("constructor priorities must be integers from 0 to %d inclusive",
7497 return DEFAULT_INIT_PRIORITY
;
7500 /* Handle a "constructor" attribute; arguments as in
7501 struct attribute_spec.handler. */
7504 handle_constructor_attribute (tree
*node
, tree name
, tree args
,
7505 int ARG_UNUSED (flags
),
7509 tree type
= TREE_TYPE (decl
);
7511 if (TREE_CODE (decl
) == FUNCTION_DECL
7512 && TREE_CODE (type
) == FUNCTION_TYPE
7513 && decl_function_context (decl
) == 0)
7515 priority_type priority
;
7516 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
7517 priority
= get_priority (args
, /*is_destructor=*/false);
7518 SET_DECL_INIT_PRIORITY (decl
, priority
);
7519 TREE_USED (decl
) = 1;
7523 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7524 *no_add_attrs
= true;
7530 /* Handle a "destructor" attribute; arguments as in
7531 struct attribute_spec.handler. */
7534 handle_destructor_attribute (tree
*node
, tree name
, tree args
,
7535 int ARG_UNUSED (flags
),
7539 tree type
= TREE_TYPE (decl
);
7541 if (TREE_CODE (decl
) == FUNCTION_DECL
7542 && TREE_CODE (type
) == FUNCTION_TYPE
7543 && decl_function_context (decl
) == 0)
7545 priority_type priority
;
7546 DECL_STATIC_DESTRUCTOR (decl
) = 1;
7547 priority
= get_priority (args
, /*is_destructor=*/true);
7548 SET_DECL_FINI_PRIORITY (decl
, priority
);
7549 TREE_USED (decl
) = 1;
7553 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7554 *no_add_attrs
= true;
7560 /* Nonzero if the mode is a valid vector mode for this architecture.
7561 This returns nonzero even if there is no hardware support for the
7562 vector mode, but we can emulate with narrower modes. */
7565 vector_mode_valid_p (machine_mode mode
)
7567 enum mode_class mclass
= GET_MODE_CLASS (mode
);
7568 machine_mode innermode
;
7570 /* Doh! What's going on? */
7571 if (mclass
!= MODE_VECTOR_INT
7572 && mclass
!= MODE_VECTOR_FLOAT
7573 && mclass
!= MODE_VECTOR_FRACT
7574 && mclass
!= MODE_VECTOR_UFRACT
7575 && mclass
!= MODE_VECTOR_ACCUM
7576 && mclass
!= MODE_VECTOR_UACCUM
)
7579 /* Hardware support. Woo hoo! */
7580 if (targetm
.vector_mode_supported_p (mode
))
7583 innermode
= GET_MODE_INNER (mode
);
7585 /* We should probably return 1 if requesting V4DI and we have no DI,
7586 but we have V2DI, but this is probably very unlikely. */
7588 /* If we have support for the inner mode, we can safely emulate it.
7589 We may not have V2DI, but me can emulate with a pair of DIs. */
7590 return targetm
.scalar_mode_supported_p (innermode
);
7594 /* Handle a "mode" attribute; arguments as in
7595 struct attribute_spec.handler. */
7598 handle_mode_attribute (tree
*node
, tree name
, tree args
,
7599 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7602 tree ident
= TREE_VALUE (args
);
7604 *no_add_attrs
= true;
7606 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
7607 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7611 const char *p
= IDENTIFIER_POINTER (ident
);
7612 int len
= strlen (p
);
7613 machine_mode mode
= VOIDmode
;
7617 if (len
> 4 && p
[0] == '_' && p
[1] == '_'
7618 && p
[len
- 1] == '_' && p
[len
- 2] == '_')
7620 char *newp
= (char *) alloca (len
- 1);
7622 strcpy (newp
, &p
[2]);
7623 newp
[len
- 4] = '\0';
7627 /* Change this type to have a type with the specified mode.
7628 First check for the special modes. */
7629 if (!strcmp (p
, "byte"))
7631 else if (!strcmp (p
, "word"))
7633 else if (!strcmp (p
, "pointer"))
7635 else if (!strcmp (p
, "libgcc_cmp_return"))
7636 mode
= targetm
.libgcc_cmp_return_mode ();
7637 else if (!strcmp (p
, "libgcc_shift_count"))
7638 mode
= targetm
.libgcc_shift_count_mode ();
7639 else if (!strcmp (p
, "unwind_word"))
7640 mode
= targetm
.unwind_word_mode ();
7642 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
7643 if (!strcmp (p
, GET_MODE_NAME (j
)))
7645 mode
= (machine_mode
) j
;
7649 if (mode
== VOIDmode
)
7651 error ("unknown machine mode %qE", ident
);
7656 switch (GET_MODE_CLASS (mode
))
7659 case MODE_PARTIAL_INT
:
7661 case MODE_DECIMAL_FLOAT
:
7666 valid_mode
= targetm
.scalar_mode_supported_p (mode
);
7669 case MODE_COMPLEX_INT
:
7670 case MODE_COMPLEX_FLOAT
:
7671 valid_mode
= targetm
.scalar_mode_supported_p (GET_MODE_INNER (mode
));
7674 case MODE_VECTOR_INT
:
7675 case MODE_VECTOR_FLOAT
:
7676 case MODE_VECTOR_FRACT
:
7677 case MODE_VECTOR_UFRACT
:
7678 case MODE_VECTOR_ACCUM
:
7679 case MODE_VECTOR_UACCUM
:
7680 warning (OPT_Wattributes
, "specifying vector types with "
7681 "__attribute__ ((mode)) is deprecated");
7682 warning (OPT_Wattributes
,
7683 "use __attribute__ ((vector_size)) instead");
7684 valid_mode
= vector_mode_valid_p (mode
);
7692 error ("unable to emulate %qs", p
);
7696 if (POINTER_TYPE_P (type
))
7698 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
7699 tree (*fn
)(tree
, machine_mode
, bool);
7701 if (!targetm
.addr_space
.valid_pointer_mode (mode
, as
))
7703 error ("invalid pointer mode %qs", p
);
7707 if (TREE_CODE (type
) == POINTER_TYPE
)
7708 fn
= build_pointer_type_for_mode
;
7710 fn
= build_reference_type_for_mode
;
7711 typefm
= fn (TREE_TYPE (type
), mode
, false);
7715 /* For fixed-point modes, we need to test if the signness of type
7716 and the machine mode are consistent. */
7717 if (ALL_FIXED_POINT_MODE_P (mode
)
7718 && TYPE_UNSIGNED (type
) != UNSIGNED_FIXED_POINT_MODE_P (mode
))
7720 error ("signedness of type and machine mode %qs don%'t match", p
);
7723 /* For fixed-point modes, we need to pass saturating info. */
7724 typefm
= lang_hooks
.types
.type_for_mode (mode
,
7725 ALL_FIXED_POINT_MODE_P (mode
) ? TYPE_SATURATING (type
)
7726 : TYPE_UNSIGNED (type
));
7729 if (typefm
== NULL_TREE
)
7731 error ("no data type for mode %qs", p
);
7734 else if (TREE_CODE (type
) == ENUMERAL_TYPE
)
7736 /* For enumeral types, copy the precision from the integer
7737 type returned above. If not an INTEGER_TYPE, we can't use
7738 this mode for this type. */
7739 if (TREE_CODE (typefm
) != INTEGER_TYPE
)
7741 error ("cannot use mode %qs for enumeral types", p
);
7745 if (flags
& ATTR_FLAG_TYPE_IN_PLACE
)
7747 TYPE_PRECISION (type
) = TYPE_PRECISION (typefm
);
7752 /* We cannot build a type variant, as there's code that assumes
7753 that TYPE_MAIN_VARIANT has the same mode. This includes the
7754 debug generators. Instead, create a subrange type. This
7755 results in all of the enumeral values being emitted only once
7756 in the original, and the subtype gets them by reference. */
7757 if (TYPE_UNSIGNED (type
))
7758 typefm
= make_unsigned_type (TYPE_PRECISION (typefm
));
7760 typefm
= make_signed_type (TYPE_PRECISION (typefm
));
7761 TREE_TYPE (typefm
) = type
;
7764 else if (VECTOR_MODE_P (mode
)
7765 ? TREE_CODE (type
) != TREE_CODE (TREE_TYPE (typefm
))
7766 : TREE_CODE (type
) != TREE_CODE (typefm
))
7768 error ("mode %qs applied to inappropriate type", p
);
7778 /* Handle a "section" attribute; arguments as in
7779 struct attribute_spec.handler. */
7782 handle_section_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7783 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7787 if (!targetm_common
.have_named_sections
)
7789 error_at (DECL_SOURCE_LOCATION (*node
),
7790 "section attributes are not supported for this target");
7794 user_defined_section_attribute
= true;
7796 if (!VAR_OR_FUNCTION_DECL_P (decl
))
7798 error ("section attribute not allowed for %q+D", *node
);
7802 if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
7804 error ("section attribute argument not a string constant");
7809 && current_function_decl
!= NULL_TREE
7810 && !TREE_STATIC (decl
))
7812 error_at (DECL_SOURCE_LOCATION (decl
),
7813 "section attribute cannot be specified for local variables");
7817 /* The decl may have already been given a section attribute
7818 from a previous declaration. Ensure they match. */
7819 if (DECL_SECTION_NAME (decl
) != NULL
7820 && strcmp (DECL_SECTION_NAME (decl
),
7821 TREE_STRING_POINTER (TREE_VALUE (args
))) != 0)
7823 error ("section of %q+D conflicts with previous declaration", *node
);
7828 && !targetm
.have_tls
&& targetm
.emutls
.tmpl_section
7829 && DECL_THREAD_LOCAL_P (decl
))
7831 error ("section of %q+D cannot be overridden", *node
);
7835 set_decl_section_name (decl
, TREE_STRING_POINTER (TREE_VALUE (args
)));
7839 *no_add_attrs
= true;
7843 /* Check whether ALIGN is a valid user-specified alignment. If so,
7844 return its base-2 log; if not, output an error and return -1. If
7845 ALLOW_ZERO then 0 is valid and should result in a return of -1 with
7848 check_user_alignment (const_tree align
, bool allow_zero
)
7852 if (error_operand_p (align
))
7854 if (TREE_CODE (align
) != INTEGER_CST
7855 || !INTEGRAL_TYPE_P (TREE_TYPE (align
)))
7857 error ("requested alignment is not an integer constant");
7860 else if (allow_zero
&& integer_zerop (align
))
7862 else if (tree_int_cst_sgn (align
) == -1
7863 || (i
= tree_log2 (align
)) == -1)
7865 error ("requested alignment is not a positive power of 2");
7868 else if (i
>= HOST_BITS_PER_INT
- LOG2_BITS_PER_UNIT
)
7870 error ("requested alignment is too large");
7876 /* If in c++-11, check if the c++-11 alignment constraint with respect
7877 to fundamental alignment (in [dcl.align]) are satisfied. If not in
7878 c++-11 mode, does nothing.
7882 [* if the constant expression evaluates to a fundamental alignment,
7883 the alignment requirement of the declared entity shall be the
7884 specified fundamental alignment.
7886 * if the constant expression evaluates to an extended alignment
7887 and the implementation supports that alignment in the context
7888 of the declaration, the alignment of the declared entity shall
7891 * if the constant expression evaluates to an extended alignment
7892 and the implementation does not support that alignment in the
7893 context of the declaration, the program is ill-formed]. */
7896 check_cxx_fundamental_alignment_constraints (tree node
,
7900 bool alignment_too_large_p
= false;
7901 unsigned requested_alignment
= (1U << align_log
) * BITS_PER_UNIT
;
7902 unsigned max_align
= 0;
7904 if ((!(flags
& ATTR_FLAG_CXX11
) && !warn_cxx_compat
)
7905 || (node
== NULL_TREE
|| node
== error_mark_node
))
7908 if (cxx_fundamental_alignment_p (requested_alignment
))
7913 if (TREE_STATIC (node
) || DECL_EXTERNAL (node
))
7914 /* For file scope variables and static members, the target supports
7915 alignments that are at most MAX_OFILE_ALIGNMENT. */
7916 max_align
= MAX_OFILE_ALIGNMENT
;
7918 /* For stack variables, the target supports at most
7919 MAX_STACK_ALIGNMENT. */
7920 max_align
= MAX_STACK_ALIGNMENT
;
7921 if (requested_alignment
> max_align
)
7922 alignment_too_large_p
= true;
7924 /* Let's be liberal for types and fields; don't limit their alignment any
7925 more than check_user_alignment already did. */
7927 if (alignment_too_large_p
)
7928 pedwarn (input_location
, OPT_Wattributes
,
7929 "requested alignment %d is larger than %d",
7930 requested_alignment
/ BITS_PER_UNIT
, max_align
/ BITS_PER_UNIT
);
7932 return !alignment_too_large_p
;
7935 /* Handle a "aligned" attribute; arguments as in
7936 struct attribute_spec.handler. */
7939 handle_aligned_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7940 int flags
, bool *no_add_attrs
)
7942 tree decl
= NULL_TREE
;
7950 align_expr
= TREE_VALUE (args
);
7951 if (align_expr
&& TREE_CODE (align_expr
) != IDENTIFIER_NODE
7952 && TREE_CODE (align_expr
) != FUNCTION_DECL
)
7953 align_expr
= default_conversion (align_expr
);
7956 align_expr
= size_int (ATTRIBUTE_ALIGNED_VALUE
/ BITS_PER_UNIT
);
7961 type
= &TREE_TYPE (decl
);
7962 is_type
= TREE_CODE (*node
) == TYPE_DECL
;
7964 else if (TYPE_P (*node
))
7965 type
= node
, is_type
= 1;
7967 if ((i
= check_user_alignment (align_expr
, true)) == -1
7968 || !check_cxx_fundamental_alignment_constraints (*node
, i
, flags
))
7969 *no_add_attrs
= true;
7972 if ((flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7973 /* OK, modify the type in place. */;
7974 /* If we have a TYPE_DECL, then copy the type, so that we
7975 don't accidentally modify a builtin type. See pushdecl. */
7976 else if (decl
&& TREE_TYPE (decl
) != error_mark_node
7977 && DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
)
7979 tree tt
= TREE_TYPE (decl
);
7980 *type
= build_variant_type_copy (*type
);
7981 DECL_ORIGINAL_TYPE (decl
) = tt
;
7982 TYPE_NAME (*type
) = decl
;
7983 TREE_USED (*type
) = TREE_USED (decl
);
7984 TREE_TYPE (decl
) = *type
;
7987 *type
= build_variant_type_copy (*type
);
7989 SET_TYPE_ALIGN (*type
, (1U << i
) * BITS_PER_UNIT
);
7990 TYPE_USER_ALIGN (*type
) = 1;
7992 else if (! VAR_OR_FUNCTION_DECL_P (decl
)
7993 && TREE_CODE (decl
) != FIELD_DECL
)
7995 error ("alignment may not be specified for %q+D", decl
);
7996 *no_add_attrs
= true;
7998 else if (DECL_USER_ALIGN (decl
)
7999 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
8000 /* C++-11 [dcl.align/4]:
8002 When multiple alignment-specifiers are specified for an
8003 entity, the alignment requirement shall be set to the
8004 strictest specified alignment.
8006 This formally comes from the c++11 specification but we are
8007 doing it for the GNU attribute syntax as well. */
8008 *no_add_attrs
= true;
8009 else if (TREE_CODE (decl
) == FUNCTION_DECL
8010 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
8012 if (DECL_USER_ALIGN (decl
))
8013 error ("alignment for %q+D was previously specified as %d "
8014 "and may not be decreased", decl
,
8015 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
8017 error ("alignment for %q+D must be at least %d", decl
,
8018 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
8019 *no_add_attrs
= true;
8023 SET_DECL_ALIGN (decl
, (1U << i
) * BITS_PER_UNIT
);
8024 DECL_USER_ALIGN (decl
) = 1;
8030 /* Handle a "weak" attribute; arguments as in
8031 struct attribute_spec.handler. */
8034 handle_weak_attribute (tree
*node
, tree name
,
8035 tree
ARG_UNUSED (args
),
8036 int ARG_UNUSED (flags
),
8037 bool * ARG_UNUSED (no_add_attrs
))
8039 if (TREE_CODE (*node
) == FUNCTION_DECL
8040 && DECL_DECLARED_INLINE_P (*node
))
8042 warning (OPT_Wattributes
, "inline function %q+D declared weak", *node
);
8043 *no_add_attrs
= true;
8045 else if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
8047 error ("indirect function %q+D cannot be declared weak", *node
);
8048 *no_add_attrs
= true;
8051 else if (VAR_OR_FUNCTION_DECL_P (*node
))
8052 declare_weak (*node
);
8054 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8059 /* Handle a "noplt" attribute; arguments as in
8060 struct attribute_spec.handler. */
8063 handle_noplt_attribute (tree
*node
, tree name
,
8064 tree
ARG_UNUSED (args
),
8065 int ARG_UNUSED (flags
),
8066 bool * ARG_UNUSED (no_add_attrs
))
8068 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8070 warning (OPT_Wattributes
,
8071 "%qE attribute is only applicable on functions", name
);
8072 *no_add_attrs
= true;
8078 /* Handle an "alias" or "ifunc" attribute; arguments as in
8079 struct attribute_spec.handler, except that IS_ALIAS tells us
8080 whether this is an alias as opposed to ifunc attribute. */
8083 handle_alias_ifunc_attribute (bool is_alias
, tree
*node
, tree name
, tree args
,
8088 if (TREE_CODE (decl
) != FUNCTION_DECL
8089 && (!is_alias
|| !VAR_P (decl
)))
8091 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8092 *no_add_attrs
= true;
8094 else if ((TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INITIAL (decl
))
8095 || (TREE_CODE (decl
) != FUNCTION_DECL
8096 && TREE_PUBLIC (decl
) && !DECL_EXTERNAL (decl
))
8097 /* A static variable declaration is always a tentative definition,
8098 but the alias is a non-tentative definition which overrides. */
8099 || (TREE_CODE (decl
) != FUNCTION_DECL
8100 && ! TREE_PUBLIC (decl
) && DECL_INITIAL (decl
)))
8102 error ("%q+D defined both normally and as %qE attribute", decl
, name
);
8103 *no_add_attrs
= true;
8107 && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
8108 || lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
))))
8110 error ("weak %q+D cannot be defined %qE", decl
, name
);
8111 *no_add_attrs
= true;
8115 /* Note that the very first time we process a nested declaration,
8116 decl_function_context will not be set. Indeed, *would* never
8117 be set except for the DECL_INITIAL/DECL_EXTERNAL frobbery that
8118 we do below. After such frobbery, pushdecl would set the context.
8119 In any case, this is never what we want. */
8120 else if (decl_function_context (decl
) == 0 && current_function_decl
== NULL
)
8124 id
= TREE_VALUE (args
);
8125 if (TREE_CODE (id
) != STRING_CST
)
8127 error ("attribute %qE argument not a string", name
);
8128 *no_add_attrs
= true;
8131 id
= get_identifier (TREE_STRING_POINTER (id
));
8132 /* This counts as a use of the object pointed to. */
8135 if (TREE_CODE (decl
) == FUNCTION_DECL
)
8136 DECL_INITIAL (decl
) = error_mark_node
;
8138 TREE_STATIC (decl
) = 1;
8141 /* ifuncs are also aliases, so set that attribute too. */
8142 DECL_ATTRIBUTES (decl
)
8143 = tree_cons (get_identifier ("alias"), args
, DECL_ATTRIBUTES (decl
));
8147 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8148 *no_add_attrs
= true;
8151 if (decl_in_symtab_p (*node
))
8153 struct symtab_node
*n
= symtab_node::get (decl
);
8154 if (n
&& n
->refuse_visibility_changes
)
8157 error ("%+D declared alias after being used", decl
);
8159 error ("%+D declared ifunc after being used", decl
);
8167 /* Handle an "alias" or "ifunc" attribute; arguments as in
8168 struct attribute_spec.handler. */
8171 handle_ifunc_attribute (tree
*node
, tree name
, tree args
,
8172 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8174 return handle_alias_ifunc_attribute (false, node
, name
, args
, no_add_attrs
);
8177 /* Handle an "alias" or "ifunc" attribute; arguments as in
8178 struct attribute_spec.handler. */
8181 handle_alias_attribute (tree
*node
, tree name
, tree args
,
8182 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8184 return handle_alias_ifunc_attribute (true, node
, name
, args
, no_add_attrs
);
8187 /* Handle a "weakref" attribute; arguments as in struct
8188 attribute_spec.handler. */
8191 handle_weakref_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
8192 int flags
, bool *no_add_attrs
)
8194 tree attr
= NULL_TREE
;
8196 /* We must ignore the attribute when it is associated with
8197 local-scoped decls, since attribute alias is ignored and many
8198 such symbols do not even have a DECL_WEAK field. */
8199 if (decl_function_context (*node
)
8200 || current_function_decl
8201 || !VAR_OR_FUNCTION_DECL_P (*node
))
8203 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8204 *no_add_attrs
= true;
8208 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
8210 error ("indirect function %q+D cannot be declared weakref", *node
);
8211 *no_add_attrs
= true;
8215 /* The idea here is that `weakref("name")' mutates into `weakref,
8216 alias("name")', and weakref without arguments, in turn,
8217 implicitly adds weak. */
8221 attr
= tree_cons (get_identifier ("alias"), args
, attr
);
8222 attr
= tree_cons (get_identifier ("weakref"), NULL_TREE
, attr
);
8224 *no_add_attrs
= true;
8226 decl_attributes (node
, attr
, flags
);
8230 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node
)))
8231 error_at (DECL_SOURCE_LOCATION (*node
),
8232 "weakref attribute must appear before alias attribute");
8234 /* Can't call declare_weak because it wants this to be TREE_PUBLIC,
8235 and that isn't supported; and because it wants to add it to
8236 the list of weak decls, which isn't helpful. */
8237 DECL_WEAK (*node
) = 1;
8240 if (decl_in_symtab_p (*node
))
8242 struct symtab_node
*n
= symtab_node::get (*node
);
8243 if (n
&& n
->refuse_visibility_changes
)
8244 error ("%+D declared weakref after being used", *node
);
8250 /* Handle an "visibility" attribute; arguments as in
8251 struct attribute_spec.handler. */
8254 handle_visibility_attribute (tree
*node
, tree name
, tree args
,
8255 int ARG_UNUSED (flags
),
8256 bool *ARG_UNUSED (no_add_attrs
))
8259 tree id
= TREE_VALUE (args
);
8260 enum symbol_visibility vis
;
8264 if (TREE_CODE (*node
) == ENUMERAL_TYPE
)
8266 else if (!RECORD_OR_UNION_TYPE_P (*node
))
8268 warning (OPT_Wattributes
, "%qE attribute ignored on non-class types",
8272 else if (TYPE_FIELDS (*node
))
8274 error ("%qE attribute ignored because %qT is already defined",
8279 else if (decl_function_context (decl
) != 0 || !TREE_PUBLIC (decl
))
8281 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8285 if (TREE_CODE (id
) != STRING_CST
)
8287 error ("visibility argument not a string");
8291 /* If this is a type, set the visibility on the type decl. */
8294 decl
= TYPE_NAME (decl
);
8297 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
8299 warning (OPT_Wattributes
, "%qE attribute ignored on types",
8305 if (strcmp (TREE_STRING_POINTER (id
), "default") == 0)
8306 vis
= VISIBILITY_DEFAULT
;
8307 else if (strcmp (TREE_STRING_POINTER (id
), "internal") == 0)
8308 vis
= VISIBILITY_INTERNAL
;
8309 else if (strcmp (TREE_STRING_POINTER (id
), "hidden") == 0)
8310 vis
= VISIBILITY_HIDDEN
;
8311 else if (strcmp (TREE_STRING_POINTER (id
), "protected") == 0)
8312 vis
= VISIBILITY_PROTECTED
;
8315 error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
8316 vis
= VISIBILITY_DEFAULT
;
8319 if (DECL_VISIBILITY_SPECIFIED (decl
)
8320 && vis
!= DECL_VISIBILITY (decl
))
8322 tree attributes
= (TYPE_P (*node
)
8323 ? TYPE_ATTRIBUTES (*node
)
8324 : DECL_ATTRIBUTES (decl
));
8325 if (lookup_attribute ("visibility", attributes
))
8326 error ("%qD redeclared with different visibility", decl
);
8327 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
8328 && lookup_attribute ("dllimport", attributes
))
8329 error ("%qD was declared %qs which implies default visibility",
8331 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
8332 && lookup_attribute ("dllexport", attributes
))
8333 error ("%qD was declared %qs which implies default visibility",
8337 DECL_VISIBILITY (decl
) = vis
;
8338 DECL_VISIBILITY_SPECIFIED (decl
) = 1;
8340 /* Go ahead and attach the attribute to the node as well. This is needed
8341 so we can determine whether we have VISIBILITY_DEFAULT because the
8342 visibility was not specified, or because it was explicitly overridden
8343 from the containing scope. */
8348 /* Determine the ELF symbol visibility for DECL, which is either a
8349 variable or a function. It is an error to use this function if a
8350 definition of DECL is not available in this translation unit.
8351 Returns true if the final visibility has been determined by this
8352 function; false if the caller is free to make additional
8356 c_determine_visibility (tree decl
)
8358 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
8360 /* If the user explicitly specified the visibility with an
8361 attribute, honor that. DECL_VISIBILITY will have been set during
8362 the processing of the attribute. We check for an explicit
8363 attribute, rather than just checking DECL_VISIBILITY_SPECIFIED,
8364 to distinguish the use of an attribute from the use of a "#pragma
8365 GCC visibility push(...)"; in the latter case we still want other
8366 considerations to be able to overrule the #pragma. */
8367 if (lookup_attribute ("visibility", DECL_ATTRIBUTES (decl
))
8368 || (TARGET_DLLIMPORT_DECL_ATTRIBUTES
8369 && (lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl
))
8370 || lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl
)))))
8373 /* Set default visibility to whatever the user supplied with
8374 visibility_specified depending on #pragma GCC visibility. */
8375 if (!DECL_VISIBILITY_SPECIFIED (decl
))
8377 if (visibility_options
.inpragma
8378 || DECL_VISIBILITY (decl
) != default_visibility
)
8380 DECL_VISIBILITY (decl
) = default_visibility
;
8381 DECL_VISIBILITY_SPECIFIED (decl
) = visibility_options
.inpragma
;
8382 /* If visibility changed and DECL already has DECL_RTL, ensure
8383 symbol flags are updated. */
8384 if (((VAR_P (decl
) && TREE_STATIC (decl
))
8385 || TREE_CODE (decl
) == FUNCTION_DECL
)
8386 && DECL_RTL_SET_P (decl
))
8387 make_decl_rtl (decl
);
8393 /* Handle an "tls_model" attribute; arguments as in
8394 struct attribute_spec.handler. */
8397 handle_tls_model_attribute (tree
*node
, tree name
, tree args
,
8398 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8402 enum tls_model kind
;
8404 *no_add_attrs
= true;
8406 if (!VAR_P (decl
) || !DECL_THREAD_LOCAL_P (decl
))
8408 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8412 kind
= DECL_TLS_MODEL (decl
);
8413 id
= TREE_VALUE (args
);
8414 if (TREE_CODE (id
) != STRING_CST
)
8416 error ("tls_model argument not a string");
8420 if (!strcmp (TREE_STRING_POINTER (id
), "local-exec"))
8421 kind
= TLS_MODEL_LOCAL_EXEC
;
8422 else if (!strcmp (TREE_STRING_POINTER (id
), "initial-exec"))
8423 kind
= TLS_MODEL_INITIAL_EXEC
;
8424 else if (!strcmp (TREE_STRING_POINTER (id
), "local-dynamic"))
8425 kind
= optimize
? TLS_MODEL_LOCAL_DYNAMIC
: TLS_MODEL_GLOBAL_DYNAMIC
;
8426 else if (!strcmp (TREE_STRING_POINTER (id
), "global-dynamic"))
8427 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
8429 error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
8431 set_decl_tls_model (decl
, kind
);
8435 /* Handle a "no_instrument_function" attribute; arguments as in
8436 struct attribute_spec.handler. */
8439 handle_no_instrument_function_attribute (tree
*node
, tree name
,
8440 tree
ARG_UNUSED (args
),
8441 int ARG_UNUSED (flags
),
8446 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8448 error_at (DECL_SOURCE_LOCATION (decl
),
8449 "%qE attribute applies only to functions", name
);
8450 *no_add_attrs
= true;
8453 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
8458 /* Handle a "no_profile_instrument_function" attribute; arguments as in
8459 struct attribute_spec.handler. */
8462 handle_no_profile_instrument_function_attribute (tree
*node
, tree name
, tree
,
8463 int, bool *no_add_attrs
)
8465 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8467 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8468 *no_add_attrs
= true;
8474 /* Handle a "malloc" attribute; arguments as in
8475 struct attribute_spec.handler. */
8478 handle_malloc_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8479 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8481 if (TREE_CODE (*node
) == FUNCTION_DECL
8482 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node
))))
8483 DECL_IS_MALLOC (*node
) = 1;
8486 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8487 *no_add_attrs
= true;
8493 /* Handle a "alloc_size" attribute; arguments as in
8494 struct attribute_spec.handler. */
8497 handle_alloc_size_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
8498 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8500 unsigned arg_count
= type_num_arguments (*node
);
8501 for (; args
; args
= TREE_CHAIN (args
))
8503 tree position
= TREE_VALUE (args
);
8504 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
8505 && TREE_CODE (position
) != FUNCTION_DECL
)
8506 position
= default_conversion (position
);
8508 if (!tree_fits_uhwi_p (position
)
8510 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
8512 warning (OPT_Wattributes
,
8513 "alloc_size parameter outside range");
8514 *no_add_attrs
= true;
8521 /* Handle a "alloc_align" attribute; arguments as in
8522 struct attribute_spec.handler. */
8525 handle_alloc_align_attribute (tree
*node
, tree
, tree args
, int,
8528 unsigned arg_count
= type_num_arguments (*node
);
8529 tree position
= TREE_VALUE (args
);
8530 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
8531 && TREE_CODE (position
) != FUNCTION_DECL
)
8532 position
= default_conversion (position
);
8534 if (!tree_fits_uhwi_p (position
)
8536 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
8538 warning (OPT_Wattributes
,
8539 "alloc_align parameter outside range");
8540 *no_add_attrs
= true;
8546 /* Handle a "assume_aligned" attribute; arguments as in
8547 struct attribute_spec.handler. */
8550 handle_assume_aligned_attribute (tree
*, tree
, tree args
, int,
8553 for (; args
; args
= TREE_CHAIN (args
))
8555 tree position
= TREE_VALUE (args
);
8556 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
8557 && TREE_CODE (position
) != FUNCTION_DECL
)
8558 position
= default_conversion (position
);
8560 if (TREE_CODE (position
) != INTEGER_CST
)
8562 warning (OPT_Wattributes
,
8563 "assume_aligned parameter not integer constant");
8564 *no_add_attrs
= true;
8571 /* Handle a "fn spec" attribute; arguments as in
8572 struct attribute_spec.handler. */
8575 handle_fnspec_attribute (tree
*node ATTRIBUTE_UNUSED
, tree
ARG_UNUSED (name
),
8576 tree args
, int ARG_UNUSED (flags
),
8577 bool *no_add_attrs ATTRIBUTE_UNUSED
)
8580 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
8581 && !TREE_CHAIN (args
));
8585 /* Handle a "bnd_variable_size" attribute; arguments as in
8586 struct attribute_spec.handler. */
8589 handle_bnd_variable_size_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8590 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8592 if (TREE_CODE (*node
) != FIELD_DECL
)
8594 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8595 *no_add_attrs
= true;
8601 /* Handle a "bnd_legacy" attribute; arguments as in
8602 struct attribute_spec.handler. */
8605 handle_bnd_legacy (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8606 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8608 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8610 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8611 *no_add_attrs
= true;
8617 /* Handle a "bnd_instrument" attribute; arguments as in
8618 struct attribute_spec.handler. */
8621 handle_bnd_instrument (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8622 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8624 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8626 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8627 *no_add_attrs
= true;
8633 /* Handle a "warn_unused" attribute; arguments as in
8634 struct attribute_spec.handler. */
8637 handle_warn_unused_attribute (tree
*node
, tree name
,
8638 tree args ATTRIBUTE_UNUSED
,
8639 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
8642 /* Do nothing else, just set the attribute. We'll get at
8643 it later with lookup_attribute. */
8647 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8648 *no_add_attrs
= true;
8654 /* Handle an "omp declare simd" attribute; arguments as in
8655 struct attribute_spec.handler. */
8658 handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int, bool *)
8663 /* Handle a "simd" attribute. */
8666 handle_simd_attribute (tree
*node
, tree name
, tree args
, int, bool *no_add_attrs
)
8668 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8670 if (lookup_attribute ("cilk simd function",
8671 DECL_ATTRIBUTES (*node
)) != NULL
)
8673 error_at (DECL_SOURCE_LOCATION (*node
),
8674 "%<__simd__%> attribute cannot be used in the same "
8675 "function marked as a Cilk Plus SIMD-enabled function");
8676 *no_add_attrs
= true;
8680 tree t
= get_identifier ("omp declare simd");
8681 tree attr
= NULL_TREE
;
8684 tree id
= TREE_VALUE (args
);
8686 if (TREE_CODE (id
) != STRING_CST
)
8688 error ("attribute %qE argument not a string", name
);
8689 *no_add_attrs
= true;
8693 if (strcmp (TREE_STRING_POINTER (id
), "notinbranch") == 0)
8694 attr
= build_omp_clause (DECL_SOURCE_LOCATION (*node
),
8695 OMP_CLAUSE_NOTINBRANCH
);
8697 if (strcmp (TREE_STRING_POINTER (id
), "inbranch") == 0)
8698 attr
= build_omp_clause (DECL_SOURCE_LOCATION (*node
),
8699 OMP_CLAUSE_INBRANCH
);
8702 error ("only %<inbranch%> and %<notinbranch%> flags are "
8703 "allowed for %<__simd__%> attribute");
8704 *no_add_attrs
= true;
8709 DECL_ATTRIBUTES (*node
) = tree_cons (t
,
8710 build_tree_list (NULL_TREE
,
8712 DECL_ATTRIBUTES (*node
));
8717 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8718 *no_add_attrs
= true;
8724 /* Handle an "omp declare target" attribute; arguments as in
8725 struct attribute_spec.handler. */
8728 handle_omp_declare_target_attribute (tree
*, tree
, tree
, int, bool *)
8733 /* Handle a "returns_twice" attribute; arguments as in
8734 struct attribute_spec.handler. */
8737 handle_returns_twice_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8738 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8740 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8741 DECL_IS_RETURNS_TWICE (*node
) = 1;
8744 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8745 *no_add_attrs
= true;
8751 /* Handle a "no_limit_stack" attribute; arguments as in
8752 struct attribute_spec.handler. */
8755 handle_no_limit_stack_attribute (tree
*node
, tree name
,
8756 tree
ARG_UNUSED (args
),
8757 int ARG_UNUSED (flags
),
8762 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8764 error_at (DECL_SOURCE_LOCATION (decl
),
8765 "%qE attribute applies only to functions", name
);
8766 *no_add_attrs
= true;
8768 else if (DECL_INITIAL (decl
))
8770 error_at (DECL_SOURCE_LOCATION (decl
),
8771 "can%'t set %qE attribute after definition", name
);
8772 *no_add_attrs
= true;
8775 DECL_NO_LIMIT_STACK (decl
) = 1;
8780 /* Handle a "pure" attribute; arguments as in
8781 struct attribute_spec.handler. */
8784 handle_pure_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8785 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8787 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8788 DECL_PURE_P (*node
) = 1;
8789 /* ??? TODO: Support types. */
8792 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8793 *no_add_attrs
= true;
8799 /* Digest an attribute list destined for a transactional memory statement.
8800 ALLOWED is the set of attributes that are allowed for this statement;
8801 return the attribute we parsed. Multiple attributes are never allowed. */
8804 parse_tm_stmt_attr (tree attrs
, int allowed
)
8809 for ( ; attrs
; attrs
= TREE_CHAIN (attrs
))
8811 tree a
= TREE_PURPOSE (attrs
);
8814 if (is_attribute_p ("outer", a
))
8815 m
= TM_STMT_ATTR_OUTER
;
8817 if ((m
& allowed
) == 0)
8819 warning (OPT_Wattributes
, "%qE attribute directive ignored", a
);
8828 else if (m_seen
== m
)
8829 warning (OPT_Wattributes
, "%qE attribute duplicated", a
);
8831 warning (OPT_Wattributes
, "%qE attribute follows %qE", a
, a_seen
);
8837 /* Transform a TM attribute name into a maskable integer and back.
8838 Note that NULL (i.e. no attribute) is mapped to UNKNOWN, corresponding
8839 to how the lack of an attribute is treated. */
8842 tm_attr_to_mask (tree attr
)
8846 if (is_attribute_p ("transaction_safe", attr
))
8847 return TM_ATTR_SAFE
;
8848 if (is_attribute_p ("transaction_callable", attr
))
8849 return TM_ATTR_CALLABLE
;
8850 if (is_attribute_p ("transaction_pure", attr
))
8851 return TM_ATTR_PURE
;
8852 if (is_attribute_p ("transaction_unsafe", attr
))
8853 return TM_ATTR_IRREVOCABLE
;
8854 if (is_attribute_p ("transaction_may_cancel_outer", attr
))
8855 return TM_ATTR_MAY_CANCEL_OUTER
;
8860 tm_mask_to_attr (int mask
)
8866 str
= "transaction_safe";
8868 case TM_ATTR_CALLABLE
:
8869 str
= "transaction_callable";
8872 str
= "transaction_pure";
8874 case TM_ATTR_IRREVOCABLE
:
8875 str
= "transaction_unsafe";
8877 case TM_ATTR_MAY_CANCEL_OUTER
:
8878 str
= "transaction_may_cancel_outer";
8883 return get_identifier (str
);
8886 /* Return the first TM attribute seen in LIST. */
8889 find_tm_attribute (tree list
)
8891 for (; list
; list
= TREE_CHAIN (list
))
8893 tree name
= TREE_PURPOSE (list
);
8894 if (tm_attr_to_mask (name
) != 0)
8900 /* Handle the TM attributes; arguments as in struct attribute_spec.handler.
8901 Here we accept only function types, and verify that none of the other
8902 function TM attributes are also applied. */
8903 /* ??? We need to accept class types for C++, but not C. This greatly
8904 complicates this function, since we can no longer rely on the extra
8905 processing given by function_type_required. */
8908 handle_tm_attribute (tree
*node
, tree name
, tree args
,
8909 int flags
, bool *no_add_attrs
)
8911 /* Only one path adds the attribute; others don't. */
8912 *no_add_attrs
= true;
8914 switch (TREE_CODE (*node
))
8918 /* Only tm_callable and tm_safe apply to classes. */
8919 if (tm_attr_to_mask (name
) & ~(TM_ATTR_SAFE
| TM_ATTR_CALLABLE
))
8926 tree old_name
= find_tm_attribute (TYPE_ATTRIBUTES (*node
));
8927 if (old_name
== name
)
8929 else if (old_name
!= NULL_TREE
)
8930 error ("type was previously declared %qE", old_name
);
8932 *no_add_attrs
= false;
8938 /* transaction_safe_dynamic goes on the FUNCTION_DECL, but we also
8939 want to set transaction_safe on the type. */
8940 gcc_assert (is_attribute_p ("transaction_safe_dynamic", name
));
8941 if (!TYPE_P (DECL_CONTEXT (*node
)))
8942 error_at (DECL_SOURCE_LOCATION (*node
),
8943 "%<transaction_safe_dynamic%> may only be specified for "
8944 "a virtual function");
8945 *no_add_attrs
= false;
8946 decl_attributes (&TREE_TYPE (*node
),
8947 build_tree_list (get_identifier ("transaction_safe"),
8955 enum tree_code subcode
= TREE_CODE (TREE_TYPE (*node
));
8956 if (subcode
== FUNCTION_TYPE
|| subcode
== METHOD_TYPE
)
8958 tree fn_tmp
= TREE_TYPE (*node
);
8959 decl_attributes (&fn_tmp
, tree_cons (name
, args
, NULL
), 0);
8960 *node
= build_pointer_type (fn_tmp
);
8967 /* If a function is next, pass it on to be tried next. */
8968 if (flags
& (int) ATTR_FLAG_FUNCTION_NEXT
)
8969 return tree_cons (name
, args
, NULL
);
8972 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8979 /* Handle the TM_WRAP attribute; arguments as in
8980 struct attribute_spec.handler. */
8983 handle_tm_wrap_attribute (tree
*node
, tree name
, tree args
,
8984 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8988 /* We don't need the attribute even on success, since we
8989 record the entry in an external table. */
8990 *no_add_attrs
= true;
8992 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8993 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8996 tree wrap_decl
= TREE_VALUE (args
);
8997 if (error_operand_p (wrap_decl
))
8999 else if (TREE_CODE (wrap_decl
) != IDENTIFIER_NODE
9000 && !VAR_OR_FUNCTION_DECL_P (wrap_decl
))
9001 error ("%qE argument not an identifier", name
);
9004 if (TREE_CODE (wrap_decl
) == IDENTIFIER_NODE
)
9005 wrap_decl
= lookup_name (wrap_decl
);
9006 if (wrap_decl
&& TREE_CODE (wrap_decl
) == FUNCTION_DECL
)
9008 if (lang_hooks
.types_compatible_p (TREE_TYPE (decl
),
9009 TREE_TYPE (wrap_decl
)))
9010 record_tm_replacement (wrap_decl
, decl
);
9012 error ("%qD is not compatible with %qD", wrap_decl
, decl
);
9015 error ("%qE argument is not a function", name
);
9022 /* Ignore the given attribute. Used when this attribute may be usefully
9023 overridden by the target, but is not used generically. */
9026 ignore_attribute (tree
* ARG_UNUSED (node
), tree
ARG_UNUSED (name
),
9027 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
9030 *no_add_attrs
= true;
9034 /* Handle a "no vops" attribute; arguments as in
9035 struct attribute_spec.handler. */
9038 handle_novops_attribute (tree
*node
, tree
ARG_UNUSED (name
),
9039 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
9040 bool *ARG_UNUSED (no_add_attrs
))
9042 gcc_assert (TREE_CODE (*node
) == FUNCTION_DECL
);
9043 DECL_IS_NOVOPS (*node
) = 1;
9047 /* Handle a "deprecated" attribute; arguments as in
9048 struct attribute_spec.handler. */
9051 handle_deprecated_attribute (tree
*node
, tree name
,
9052 tree args
, int flags
,
9055 tree type
= NULL_TREE
;
9057 tree what
= NULL_TREE
;
9060 *no_add_attrs
= true;
9061 else if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
9063 error ("deprecated message is not a string");
9064 *no_add_attrs
= true;
9070 type
= TREE_TYPE (decl
);
9072 if (TREE_CODE (decl
) == TYPE_DECL
9073 || TREE_CODE (decl
) == PARM_DECL
9074 || VAR_OR_FUNCTION_DECL_P (decl
)
9075 || TREE_CODE (decl
) == FIELD_DECL
9076 || TREE_CODE (decl
) == CONST_DECL
9077 || objc_method_decl (TREE_CODE (decl
)))
9078 TREE_DEPRECATED (decl
) = 1;
9082 else if (TYPE_P (*node
))
9084 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
9085 *node
= build_variant_type_copy (*node
);
9086 TREE_DEPRECATED (*node
) = 1;
9094 *no_add_attrs
= true;
9095 if (type
&& TYPE_NAME (type
))
9097 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
9098 what
= TYPE_NAME (*node
);
9099 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
9100 && DECL_NAME (TYPE_NAME (type
)))
9101 what
= DECL_NAME (TYPE_NAME (type
));
9104 warning (OPT_Wattributes
, "%qE attribute ignored for %qE", name
, what
);
9106 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9112 /* Handle a "vector_size" attribute; arguments as in
9113 struct attribute_spec.handler. */
9116 handle_vector_size_attribute (tree
*node
, tree name
, tree args
,
9117 int ARG_UNUSED (flags
),
9120 unsigned HOST_WIDE_INT vecsize
, nunits
;
9121 machine_mode orig_mode
;
9122 tree type
= *node
, new_type
, size
;
9124 *no_add_attrs
= true;
9126 size
= TREE_VALUE (args
);
9127 if (size
&& TREE_CODE (size
) != IDENTIFIER_NODE
9128 && TREE_CODE (size
) != FUNCTION_DECL
)
9129 size
= default_conversion (size
);
9131 if (!tree_fits_uhwi_p (size
))
9133 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9137 /* Get the vector size (in bytes). */
9138 vecsize
= tree_to_uhwi (size
);
9140 /* We need to provide for vector pointers, vector arrays, and
9141 functions returning vectors. For example:
9143 __attribute__((vector_size(16))) short *foo;
9145 In this case, the mode is SI, but the type being modified is
9146 HI, so we need to look further. */
9148 while (POINTER_TYPE_P (type
)
9149 || TREE_CODE (type
) == FUNCTION_TYPE
9150 || TREE_CODE (type
) == METHOD_TYPE
9151 || TREE_CODE (type
) == ARRAY_TYPE
9152 || TREE_CODE (type
) == OFFSET_TYPE
)
9153 type
= TREE_TYPE (type
);
9155 /* Get the mode of the type being modified. */
9156 orig_mode
= TYPE_MODE (type
);
9158 if ((!INTEGRAL_TYPE_P (type
)
9159 && !SCALAR_FLOAT_TYPE_P (type
)
9160 && !FIXED_POINT_TYPE_P (type
))
9161 || (!SCALAR_FLOAT_MODE_P (orig_mode
)
9162 && GET_MODE_CLASS (orig_mode
) != MODE_INT
9163 && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode
))
9164 || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
9165 || TREE_CODE (type
) == BOOLEAN_TYPE
)
9167 error ("invalid vector type for attribute %qE", name
);
9171 if (vecsize
% tree_to_uhwi (TYPE_SIZE_UNIT (type
)))
9173 error ("vector size not an integral multiple of component size");
9179 error ("zero vector size");
9183 /* Calculate how many units fit in the vector. */
9184 nunits
= vecsize
/ tree_to_uhwi (TYPE_SIZE_UNIT (type
));
9185 if (nunits
& (nunits
- 1))
9187 error ("number of components of the vector not a power of two");
9191 new_type
= build_vector_type (type
, nunits
);
9193 /* Build back pointers if needed. */
9194 *node
= lang_hooks
.types
.reconstruct_complex_type (*node
, new_type
);
9199 /* Handle the "nonnull" attribute. */
9201 handle_nonnull_attribute (tree
*node
, tree
ARG_UNUSED (name
),
9202 tree args
, int ARG_UNUSED (flags
),
9206 unsigned HOST_WIDE_INT attr_arg_num
;
9208 /* If no arguments are specified, all pointer arguments should be
9209 non-null. Verify a full prototype is given so that the arguments
9210 will have the correct types when we actually check them later.
9211 Avoid diagnosing type-generic built-ins since those have no
9215 if (!prototype_p (type
)
9216 && (!TYPE_ATTRIBUTES (type
)
9217 || !lookup_attribute ("type generic", TYPE_ATTRIBUTES (type
))))
9219 error ("nonnull attribute without arguments on a non-prototype");
9220 *no_add_attrs
= true;
9225 /* Argument list specified. Verify that each argument number references
9226 a pointer argument. */
9227 for (attr_arg_num
= 1; args
; attr_arg_num
++, args
= TREE_CHAIN (args
))
9229 unsigned HOST_WIDE_INT arg_num
= 0, ck_num
;
9231 tree arg
= TREE_VALUE (args
);
9232 if (arg
&& TREE_CODE (arg
) != IDENTIFIER_NODE
9233 && TREE_CODE (arg
) != FUNCTION_DECL
)
9234 arg
= default_conversion (arg
);
9236 if (!get_nonnull_operand (arg
, &arg_num
))
9238 error ("nonnull argument has invalid operand number (argument %lu)",
9239 (unsigned long) attr_arg_num
);
9240 *no_add_attrs
= true;
9244 if (prototype_p (type
))
9246 function_args_iterator iter
;
9249 function_args_iter_init (&iter
, type
);
9250 for (ck_num
= 1; ; ck_num
++, function_args_iter_next (&iter
))
9252 argument
= function_args_iter_cond (&iter
);
9253 if (argument
== NULL_TREE
|| ck_num
== arg_num
)
9258 || TREE_CODE (argument
) == VOID_TYPE
)
9260 error ("nonnull argument with out-of-range operand number (argument %lu, operand %lu)",
9261 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
9262 *no_add_attrs
= true;
9266 if (TREE_CODE (argument
) != POINTER_TYPE
)
9268 error ("nonnull argument references non-pointer operand (argument %lu, operand %lu)",
9269 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
9270 *no_add_attrs
= true;
9279 /* Check the argument list of a function call for null in argument slots
9280 that are marked as requiring a non-null pointer argument. The NARGS
9281 arguments are passed in the array ARGARRAY. */
9284 check_function_nonnull (location_t loc
, tree attrs
, int nargs
, tree
*argarray
)
9289 attrs
= lookup_attribute ("nonnull", attrs
);
9290 if (attrs
== NULL_TREE
)
9294 /* See if any of the nonnull attributes has no arguments. If so,
9295 then every pointer argument is checked (in which case the check
9296 for pointer type is done in check_nonnull_arg). */
9297 if (TREE_VALUE (a
) != NULL_TREE
)
9299 a
= lookup_attribute ("nonnull", TREE_CHAIN (a
));
9300 while (a
!= NULL_TREE
&& TREE_VALUE (a
) != NULL_TREE
);
9303 for (i
= 0; i
< nargs
; i
++)
9304 check_function_arguments_recurse (check_nonnull_arg
, &loc
, argarray
[i
],
9308 /* Walk the argument list. If we encounter an argument number we
9309 should check for non-null, do it. */
9310 for (i
= 0; i
< nargs
; i
++)
9312 for (a
= attrs
; ; a
= TREE_CHAIN (a
))
9314 a
= lookup_attribute ("nonnull", a
);
9315 if (a
== NULL_TREE
|| nonnull_check_p (TREE_VALUE (a
), i
+ 1))
9320 check_function_arguments_recurse (check_nonnull_arg
, &loc
,
9321 argarray
[i
], i
+ 1);
9326 /* Check that the Nth argument of a function call (counting backwards
9327 from the end) is a (pointer)0. The NARGS arguments are passed in the
9331 check_function_sentinel (const_tree fntype
, int nargs
, tree
*argarray
)
9333 tree attr
= lookup_attribute ("sentinel", TYPE_ATTRIBUTES (fntype
));
9340 function_args_iterator iter
;
9343 /* Skip over the named arguments. */
9344 FOREACH_FUNCTION_ARGS (fntype
, t
, iter
)
9351 if (TREE_VALUE (attr
))
9353 tree p
= TREE_VALUE (TREE_VALUE (attr
));
9354 pos
= TREE_INT_CST_LOW (p
);
9357 /* The sentinel must be one of the varargs, i.e.
9358 in position >= the number of fixed arguments. */
9359 if ((nargs
- 1 - pos
) < len
)
9361 warning (OPT_Wformat_
,
9362 "not enough variable arguments to fit a sentinel");
9366 /* Validate the sentinel. */
9367 sentinel
= argarray
[nargs
- 1 - pos
];
9368 if ((!POINTER_TYPE_P (TREE_TYPE (sentinel
))
9369 || !integer_zerop (sentinel
))
9370 /* Although __null (in C++) is only an integer we allow it
9371 nevertheless, as we are guaranteed that it's exactly
9372 as wide as a pointer, and we don't want to force
9373 users to cast the NULL they have written there.
9374 We warn with -Wstrict-null-sentinel, though. */
9375 && (warn_strict_null_sentinel
|| null_node
!= sentinel
))
9376 warning (OPT_Wformat_
, "missing sentinel in function call");
9380 /* Helper for check_function_nonnull; given a list of operands which
9381 must be non-null in ARGS, determine if operand PARAM_NUM should be
9385 nonnull_check_p (tree args
, unsigned HOST_WIDE_INT param_num
)
9387 unsigned HOST_WIDE_INT arg_num
= 0;
9389 for (; args
; args
= TREE_CHAIN (args
))
9391 bool found
= get_nonnull_operand (TREE_VALUE (args
), &arg_num
);
9395 if (arg_num
== param_num
)
9401 /* Check that the function argument PARAM (which is operand number
9402 PARAM_NUM) is non-null. This is called by check_function_nonnull
9403 via check_function_arguments_recurse. */
9406 check_nonnull_arg (void *ctx
, tree param
, unsigned HOST_WIDE_INT param_num
)
9408 location_t
*ploc
= (location_t
*) ctx
;
9410 /* Just skip checking the argument if it's not a pointer. This can
9411 happen if the "nonnull" attribute was given without an operand
9412 list (which means to check every pointer argument). */
9414 if (TREE_CODE (TREE_TYPE (param
)) != POINTER_TYPE
)
9417 if (integer_zerop (param
))
9418 warning_at (*ploc
, OPT_Wnonnull
, "null argument where non-null required "
9419 "(argument %lu)", (unsigned long) param_num
);
9422 /* Helper for nonnull attribute handling; fetch the operand number
9423 from the attribute argument list. */
9426 get_nonnull_operand (tree arg_num_expr
, unsigned HOST_WIDE_INT
*valp
)
9428 /* Verify the arg number is a small constant. */
9429 if (tree_fits_uhwi_p (arg_num_expr
))
9431 *valp
= TREE_INT_CST_LOW (arg_num_expr
);
9438 /* Handle a "nothrow" attribute; arguments as in
9439 struct attribute_spec.handler. */
9442 handle_nothrow_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
9443 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9445 if (TREE_CODE (*node
) == FUNCTION_DECL
)
9446 TREE_NOTHROW (*node
) = 1;
9447 /* ??? TODO: Support types. */
9450 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9451 *no_add_attrs
= true;
9457 /* Handle a "cleanup" attribute; arguments as in
9458 struct attribute_spec.handler. */
9461 handle_cleanup_attribute (tree
*node
, tree name
, tree args
,
9462 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9465 tree cleanup_id
, cleanup_decl
;
9467 /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
9468 for global destructors in C++. This requires infrastructure that
9469 we don't have generically at the moment. It's also not a feature
9470 we'd be missing too much, since we do have attribute constructor. */
9471 if (!VAR_P (decl
) || TREE_STATIC (decl
))
9473 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9474 *no_add_attrs
= true;
9478 /* Verify that the argument is a function in scope. */
9479 /* ??? We could support pointers to functions here as well, if
9480 that was considered desirable. */
9481 cleanup_id
= TREE_VALUE (args
);
9482 if (TREE_CODE (cleanup_id
) != IDENTIFIER_NODE
)
9484 error ("cleanup argument not an identifier");
9485 *no_add_attrs
= true;
9488 cleanup_decl
= lookup_name (cleanup_id
);
9489 if (!cleanup_decl
|| TREE_CODE (cleanup_decl
) != FUNCTION_DECL
)
9491 error ("cleanup argument not a function");
9492 *no_add_attrs
= true;
9496 /* That the function has proper type is checked with the
9497 eventual call to build_function_call. */
9502 /* Handle a "warn_unused_result" attribute. No special handling. */
9505 handle_warn_unused_result_attribute (tree
*node
, tree name
,
9506 tree
ARG_UNUSED (args
),
9507 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9509 /* Ignore the attribute for functions not returning any value. */
9510 if (VOID_TYPE_P (TREE_TYPE (*node
)))
9512 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9513 *no_add_attrs
= true;
9519 /* Handle a "sentinel" attribute. */
9522 handle_sentinel_attribute (tree
*node
, tree name
, tree args
,
9523 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9525 if (!prototype_p (*node
))
9527 warning (OPT_Wattributes
,
9528 "%qE attribute requires prototypes with named arguments", name
);
9529 *no_add_attrs
= true;
9533 if (!stdarg_p (*node
))
9535 warning (OPT_Wattributes
,
9536 "%qE attribute only applies to variadic functions", name
);
9537 *no_add_attrs
= true;
9543 tree position
= TREE_VALUE (args
);
9544 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
9545 && TREE_CODE (position
) != FUNCTION_DECL
)
9546 position
= default_conversion (position
);
9548 if (TREE_CODE (position
) != INTEGER_CST
9549 || !INTEGRAL_TYPE_P (TREE_TYPE (position
)))
9551 warning (OPT_Wattributes
,
9552 "requested position is not an integer constant");
9553 *no_add_attrs
= true;
9557 if (tree_int_cst_lt (position
, integer_zero_node
))
9559 warning (OPT_Wattributes
,
9560 "requested position is less than zero");
9561 *no_add_attrs
= true;
9569 /* Handle a "type_generic" attribute. */
9572 handle_type_generic_attribute (tree
*node
, tree
ARG_UNUSED (name
),
9573 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
9574 bool * ARG_UNUSED (no_add_attrs
))
9576 /* Ensure we have a function type. */
9577 gcc_assert (TREE_CODE (*node
) == FUNCTION_TYPE
);
9579 /* Ensure we have a variadic function. */
9580 gcc_assert (!prototype_p (*node
) || stdarg_p (*node
));
9585 /* Handle a "target" attribute. */
9588 handle_target_attribute (tree
*node
, tree name
, tree args
, int flags
,
9591 /* Ensure we have a function type. */
9592 if (TREE_CODE (*node
) != FUNCTION_DECL
)
9594 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9595 *no_add_attrs
= true;
9597 else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node
)))
9599 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
9600 "with %qs attribute", name
, "target_clones");
9601 *no_add_attrs
= true;
9603 else if (! targetm
.target_option
.valid_attribute_p (*node
, name
, args
,
9605 *no_add_attrs
= true;
9610 /* Handle a "target_clones" attribute. */
9613 handle_target_clones_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
9614 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9616 /* Ensure we have a function type. */
9617 if (TREE_CODE (*node
) == FUNCTION_DECL
)
9619 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node
)))
9621 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
9622 "with %qs attribute", name
, "always_inline");
9623 *no_add_attrs
= true;
9625 else if (lookup_attribute ("target", DECL_ATTRIBUTES (*node
)))
9627 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
9628 "with %qs attribute", name
, "target");
9629 *no_add_attrs
= true;
9632 /* Do not inline functions with multiple clone targets. */
9633 DECL_UNINLINABLE (*node
) = 1;
9637 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9638 *no_add_attrs
= true;
9643 /* Arguments being collected for optimization. */
9644 typedef const char *const_char_p
; /* For DEF_VEC_P. */
9645 static GTY(()) vec
<const_char_p
, va_gc
> *optimize_args
;
9648 /* Inner function to convert a TREE_LIST to argv string to parse the optimize
9649 options in ARGS. ATTR_P is true if this is for attribute(optimize), and
9650 false for #pragma GCC optimize. */
9653 parse_optimize_options (tree args
, bool attr_p
)
9658 const char **opt_argv
;
9659 struct cl_decoded_option
*decoded_options
;
9660 unsigned int decoded_options_count
;
9663 /* Build up argv vector. Just in case the string is stored away, use garbage
9664 collected strings. */
9665 vec_safe_truncate (optimize_args
, 0);
9666 vec_safe_push (optimize_args
, (const char *) NULL
);
9668 for (ap
= args
; ap
!= NULL_TREE
; ap
= TREE_CHAIN (ap
))
9670 tree value
= TREE_VALUE (ap
);
9672 if (TREE_CODE (value
) == INTEGER_CST
)
9675 sprintf (buffer
, "-O%ld", (long) TREE_INT_CST_LOW (value
));
9676 vec_safe_push (optimize_args
, ggc_strdup (buffer
));
9679 else if (TREE_CODE (value
) == STRING_CST
)
9681 /* Split string into multiple substrings. */
9682 size_t len
= TREE_STRING_LENGTH (value
);
9683 char *p
= ASTRDUP (TREE_STRING_POINTER (value
));
9684 char *end
= p
+ len
;
9688 while (next_p
!= NULL
)
9694 comma
= strchr (p
, ',');
9707 r
= q
= (char *) ggc_alloc_atomic (len2
+ 3);
9709 /* If the user supplied -Oxxx or -fxxx, only allow -Oxxx or -fxxx
9711 if (*p
== '-' && p
[1] != 'O' && p
[1] != 'f')
9715 warning (OPT_Wattributes
,
9716 "bad option %qs to attribute %<optimize%>", p
);
9718 warning (OPT_Wpragmas
,
9719 "bad option %qs to pragma %<optimize%>", p
);
9727 /* Assume that Ox is -Ox, a numeric value is -Ox, a s by
9728 itself is -Os, and any other switch begins with a -f. */
9729 if ((*p
>= '0' && *p
<= '9')
9730 || (p
[0] == 's' && p
[1] == '\0'))
9736 memcpy (r
, p
, len2
);
9738 vec_safe_push (optimize_args
, (const char *) q
);
9744 opt_argc
= optimize_args
->length ();
9745 opt_argv
= (const char **) alloca (sizeof (char *) * (opt_argc
+ 1));
9747 for (i
= 1; i
< opt_argc
; i
++)
9748 opt_argv
[i
] = (*optimize_args
)[i
];
9750 /* Now parse the options. */
9751 decode_cmdline_options_to_array_default_mask (opt_argc
, opt_argv
,
9753 &decoded_options_count
);
9754 /* Drop non-Optimization options. */
9756 for (i
= 1; i
< decoded_options_count
; ++i
)
9758 if (! (cl_options
[decoded_options
[i
].opt_index
].flags
& CL_OPTIMIZATION
))
9762 warning (OPT_Wattributes
,
9763 "bad option %qs to attribute %<optimize%>",
9764 decoded_options
[i
].orig_option_with_args_text
);
9766 warning (OPT_Wpragmas
,
9767 "bad option %qs to pragma %<optimize%>",
9768 decoded_options
[i
].orig_option_with_args_text
);
9772 decoded_options
[j
] = decoded_options
[i
];
9775 decoded_options_count
= j
;
9776 /* And apply them. */
9777 decode_options (&global_options
, &global_options_set
,
9778 decoded_options
, decoded_options_count
,
9779 input_location
, global_dc
);
9781 targetm
.override_options_after_change();
9783 optimize_args
->truncate (0);
9787 /* For handling "optimize" attribute. arguments as in
9788 struct attribute_spec.handler. */
9791 handle_optimize_attribute (tree
*node
, tree name
, tree args
,
9792 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9794 /* Ensure we have a function type. */
9795 if (TREE_CODE (*node
) != FUNCTION_DECL
)
9797 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9798 *no_add_attrs
= true;
9802 struct cl_optimization cur_opts
;
9803 tree old_opts
= DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
);
9805 /* Save current options. */
9806 cl_optimization_save (&cur_opts
, &global_options
);
9808 /* If we previously had some optimization options, use them as the
9811 cl_optimization_restore (&global_options
,
9812 TREE_OPTIMIZATION (old_opts
));
9814 /* Parse options, and update the vector. */
9815 parse_optimize_options (args
, true);
9816 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
)
9817 = build_optimization_node (&global_options
);
9819 /* Restore current options. */
9820 cl_optimization_restore (&global_options
, &cur_opts
);
9826 /* Handle a "no_split_stack" attribute. */
9829 handle_no_split_stack_attribute (tree
*node
, tree name
,
9830 tree
ARG_UNUSED (args
),
9831 int ARG_UNUSED (flags
),
9836 if (TREE_CODE (decl
) != FUNCTION_DECL
)
9838 error_at (DECL_SOURCE_LOCATION (decl
),
9839 "%qE attribute applies only to functions", name
);
9840 *no_add_attrs
= true;
9842 else if (DECL_INITIAL (decl
))
9844 error_at (DECL_SOURCE_LOCATION (decl
),
9845 "can%'t set %qE attribute after definition", name
);
9846 *no_add_attrs
= true;
9852 /* Handle a "returns_nonnull" attribute; arguments as in
9853 struct attribute_spec.handler. */
9856 handle_returns_nonnull_attribute (tree
*node
, tree
, tree
, int,
9859 // Even without a prototype we still have a return type we can check.
9860 if (TREE_CODE (TREE_TYPE (*node
)) != POINTER_TYPE
)
9862 error ("returns_nonnull attribute on a function not returning a pointer");
9863 *no_add_attrs
= true;
9868 /* Handle a "designated_init" attribute; arguments as in
9869 struct attribute_spec.handler. */
9872 handle_designated_init_attribute (tree
*node
, tree name
, tree
, int,
9875 if (TREE_CODE (*node
) != RECORD_TYPE
)
9877 error ("%qE attribute is only valid on %<struct%> type", name
);
9878 *no_add_attrs
= true;
9884 /* Handle a "fallthrough" attribute; arguments as in struct
9885 attribute_spec.handler. */
9888 handle_fallthrough_attribute (tree
*, tree name
, tree
, int,
9891 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9892 *no_add_attrs
= true;
9896 /* Check whether ATTR is a valid attribute fallthrough. */
9899 attribute_fallthrough_p (tree attr
)
9901 tree t
= lookup_attribute ("fallthrough", attr
);
9904 /* This attribute shall appear at most once in each attribute-list. */
9905 if (lookup_attribute ("fallthrough", TREE_CHAIN (t
)))
9906 warning (OPT_Wattributes
, "%<fallthrough%> attribute specified multiple "
9908 /* No attribute-argument-clause shall be present. */
9909 else if (TREE_VALUE (t
) != NULL_TREE
)
9910 warning (OPT_Wattributes
, "%<fallthrough%> attribute specified with "
9912 /* Warn if other attributes are found. */
9913 for (t
= attr
; t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
9915 tree name
= get_attribute_name (t
);
9916 if (!is_attribute_p ("fallthrough", name
))
9917 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9923 /* Check for valid arguments being passed to a function with FNTYPE.
9924 There are NARGS arguments in the array ARGARRAY. LOC should be used for
9927 check_function_arguments (location_t loc
, const_tree fntype
, int nargs
,
9930 /* Check for null being passed in a pointer argument that must be
9931 non-null. We also need to do this if format checking is enabled. */
9934 check_function_nonnull (loc
, TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
9936 /* Check for errors in format strings. */
9938 if (warn_format
|| warn_suggest_attribute_format
)
9939 check_function_format (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
9942 check_function_sentinel (fntype
, nargs
, argarray
);
9945 /* Generic argument checking recursion routine. PARAM is the argument to
9946 be checked. PARAM_NUM is the number of the argument. CALLBACK is invoked
9947 once the argument is resolved. CTX is context for the callback. */
9949 check_function_arguments_recurse (void (*callback
)
9950 (void *, tree
, unsigned HOST_WIDE_INT
),
9951 void *ctx
, tree param
,
9952 unsigned HOST_WIDE_INT param_num
)
9954 if (CONVERT_EXPR_P (param
)
9955 && (TYPE_PRECISION (TREE_TYPE (param
))
9956 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (param
, 0)))))
9958 /* Strip coercion. */
9959 check_function_arguments_recurse (callback
, ctx
,
9960 TREE_OPERAND (param
, 0), param_num
);
9964 if (TREE_CODE (param
) == CALL_EXPR
)
9966 tree type
= TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (param
)));
9968 bool found_format_arg
= false;
9970 /* See if this is a call to a known internationalization function
9971 that modifies a format arg. Such a function may have multiple
9972 format_arg attributes (for example, ngettext). */
9974 for (attrs
= TYPE_ATTRIBUTES (type
);
9976 attrs
= TREE_CHAIN (attrs
))
9977 if (is_attribute_p ("format_arg", TREE_PURPOSE (attrs
)))
9980 tree format_num_expr
;
9983 call_expr_arg_iterator iter
;
9985 /* Extract the argument number, which was previously checked
9987 format_num_expr
= TREE_VALUE (TREE_VALUE (attrs
));
9989 format_num
= tree_to_uhwi (format_num_expr
);
9991 for (inner_arg
= first_call_expr_arg (param
, &iter
), i
= 1;
9993 inner_arg
= next_call_expr_arg (&iter
), i
++)
9994 if (i
== format_num
)
9996 check_function_arguments_recurse (callback
, ctx
,
9997 inner_arg
, param_num
);
9998 found_format_arg
= true;
10003 /* If we found a format_arg attribute and did a recursive check,
10004 we are done with checking this argument. Otherwise, we continue
10005 and this will be considered a non-literal. */
10006 if (found_format_arg
)
10010 if (TREE_CODE (param
) == COND_EXPR
)
10012 /* Simplify to avoid warning for an impossible case. */
10013 param
= fold_for_warn (param
);
10014 if (TREE_CODE (param
) == COND_EXPR
)
10016 /* Check both halves of the conditional expression. */
10017 check_function_arguments_recurse (callback
, ctx
,
10018 TREE_OPERAND (param
, 1),
10020 check_function_arguments_recurse (callback
, ctx
,
10021 TREE_OPERAND (param
, 2),
10027 (*callback
) (ctx
, param
, param_num
);
10030 /* Checks for a builtin function FNDECL that the number of arguments
10031 NARGS against the required number REQUIRED and issues an error if
10032 there is a mismatch. Returns true if the number of arguments is
10033 correct, otherwise false. LOC is the location of FNDECL. */
10036 builtin_function_validate_nargs (location_t loc
, tree fndecl
, int nargs
,
10039 if (nargs
< required
)
10041 error_at (loc
, "too few arguments to function %qE", fndecl
);
10044 else if (nargs
> required
)
10046 error_at (loc
, "too many arguments to function %qE", fndecl
);
10052 /* Helper macro for check_builtin_function_arguments. */
10053 #define ARG_LOCATION(N) \
10054 (arg_loc.is_empty () \
10055 ? EXPR_LOC_OR_LOC (args[(N)], input_location) \
10056 : expansion_point_location (arg_loc[(N)]))
10058 /* Verifies the NARGS arguments ARGS to the builtin function FNDECL.
10059 Returns false if there was an error, otherwise true. LOC is the
10060 location of the function; ARG_LOC is a vector of locations of the
10064 check_builtin_function_arguments (location_t loc
, vec
<location_t
> arg_loc
,
10065 tree fndecl
, int nargs
, tree
*args
)
10067 if (!DECL_BUILT_IN (fndecl
)
10068 || DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_NORMAL
)
10071 switch (DECL_FUNCTION_CODE (fndecl
))
10073 case BUILT_IN_ALLOCA_WITH_ALIGN
:
10075 /* Get the requested alignment (in bits) if it's a constant
10076 integer expression. */
10077 unsigned HOST_WIDE_INT align
10078 = tree_fits_uhwi_p (args
[1]) ? tree_to_uhwi (args
[1]) : 0;
10080 /* Determine if the requested alignment is a power of 2. */
10081 if ((align
& (align
- 1)))
10084 /* The maximum alignment in bits corresponding to the same
10085 maximum in bytes enforced in check_user_alignment(). */
10086 unsigned maxalign
= (UINT_MAX
>> 1) + 1;
10088 /* Reject invalid alignments. */
10089 if (align
< BITS_PER_UNIT
|| maxalign
< align
)
10091 error_at (ARG_LOCATION (1),
10092 "second argument to function %qE must be a constant "
10093 "integer power of 2 between %qi and %qu bits",
10094 fndecl
, BITS_PER_UNIT
, maxalign
);
10100 case BUILT_IN_CONSTANT_P
:
10101 return builtin_function_validate_nargs (loc
, fndecl
, nargs
, 1);
10103 case BUILT_IN_ISFINITE
:
10104 case BUILT_IN_ISINF
:
10105 case BUILT_IN_ISINF_SIGN
:
10106 case BUILT_IN_ISNAN
:
10107 case BUILT_IN_ISNORMAL
:
10108 case BUILT_IN_SIGNBIT
:
10109 if (builtin_function_validate_nargs (loc
, fndecl
, nargs
, 1))
10111 if (TREE_CODE (TREE_TYPE (args
[0])) != REAL_TYPE
)
10113 error_at (ARG_LOCATION (0), "non-floating-point argument in "
10114 "call to function %qE", fndecl
);
10121 case BUILT_IN_ISGREATER
:
10122 case BUILT_IN_ISGREATEREQUAL
:
10123 case BUILT_IN_ISLESS
:
10124 case BUILT_IN_ISLESSEQUAL
:
10125 case BUILT_IN_ISLESSGREATER
:
10126 case BUILT_IN_ISUNORDERED
:
10127 if (builtin_function_validate_nargs (loc
, fndecl
, nargs
, 2))
10129 enum tree_code code0
, code1
;
10130 code0
= TREE_CODE (TREE_TYPE (args
[0]));
10131 code1
= TREE_CODE (TREE_TYPE (args
[1]));
10132 if (!((code0
== REAL_TYPE
&& code1
== REAL_TYPE
)
10133 || (code0
== REAL_TYPE
&& code1
== INTEGER_TYPE
)
10134 || (code0
== INTEGER_TYPE
&& code1
== REAL_TYPE
)))
10136 error_at (loc
, "non-floating-point arguments in call to "
10137 "function %qE", fndecl
);
10144 case BUILT_IN_FPCLASSIFY
:
10145 if (builtin_function_validate_nargs (loc
, fndecl
, nargs
, 6))
10147 for (unsigned int i
= 0; i
< 5; i
++)
10148 if (TREE_CODE (args
[i
]) != INTEGER_CST
)
10150 error_at (ARG_LOCATION (i
), "non-const integer argument %u in "
10151 "call to function %qE", i
+ 1, fndecl
);
10155 if (TREE_CODE (TREE_TYPE (args
[5])) != REAL_TYPE
)
10157 error_at (ARG_LOCATION (5), "non-floating-point argument in "
10158 "call to function %qE", fndecl
);
10165 case BUILT_IN_ASSUME_ALIGNED
:
10166 if (builtin_function_validate_nargs (loc
, fndecl
, nargs
, 2 + (nargs
> 2)))
10168 if (nargs
>= 3 && TREE_CODE (TREE_TYPE (args
[2])) != INTEGER_TYPE
)
10170 error_at (ARG_LOCATION (2), "non-integer argument 3 in call to "
10171 "function %qE", fndecl
);
10178 case BUILT_IN_ADD_OVERFLOW
:
10179 case BUILT_IN_SUB_OVERFLOW
:
10180 case BUILT_IN_MUL_OVERFLOW
:
10181 if (builtin_function_validate_nargs (loc
, fndecl
, nargs
, 3))
10184 for (i
= 0; i
< 2; i
++)
10185 if (!INTEGRAL_TYPE_P (TREE_TYPE (args
[i
])))
10187 error_at (ARG_LOCATION (i
), "argument %u in call to function "
10188 "%qE does not have integral type", i
+ 1, fndecl
);
10191 if (TREE_CODE (TREE_TYPE (args
[2])) != POINTER_TYPE
10192 || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (args
[2]))))
10194 error_at (ARG_LOCATION (2), "argument 3 in call to function %qE "
10195 "does not have pointer to integral type", fndecl
);
10198 else if (TREE_CODE (TREE_TYPE (TREE_TYPE (args
[2]))) == ENUMERAL_TYPE
)
10200 error_at (ARG_LOCATION (2), "argument 3 in call to function %qE "
10201 "has pointer to enumerated type", fndecl
);
10204 else if (TREE_CODE (TREE_TYPE (TREE_TYPE (args
[2]))) == BOOLEAN_TYPE
)
10206 error_at (ARG_LOCATION (2), "argument 3 in call to function %qE "
10207 "has pointer to boolean type", fndecl
);
10214 case BUILT_IN_ADD_OVERFLOW_P
:
10215 case BUILT_IN_SUB_OVERFLOW_P
:
10216 case BUILT_IN_MUL_OVERFLOW_P
:
10217 if (builtin_function_validate_nargs (loc
, fndecl
, nargs
, 3))
10220 for (i
= 0; i
< 3; i
++)
10221 if (!INTEGRAL_TYPE_P (TREE_TYPE (args
[i
])))
10223 error_at (ARG_LOCATION (i
), "argument %u in call to function "
10224 "%qE does not have integral type", i
+ 1, fndecl
);
10227 if (TREE_CODE (TREE_TYPE (args
[2])) == ENUMERAL_TYPE
)
10229 error_at (ARG_LOCATION (2), "argument 3 in call to function "
10230 "%qE has enumerated type", fndecl
);
10233 else if (TREE_CODE (TREE_TYPE (args
[2])) == BOOLEAN_TYPE
)
10235 error_at (ARG_LOCATION (2), "argument 3 in call to function "
10236 "%qE has boolean type", fndecl
);
10248 /* Function to help qsort sort FIELD_DECLs by name order. */
10251 field_decl_cmp (const void *x_p
, const void *y_p
)
10253 const tree
*const x
= (const tree
*const) x_p
;
10254 const tree
*const y
= (const tree
*const) y_p
;
10256 if (DECL_NAME (*x
) == DECL_NAME (*y
))
10257 /* A nontype is "greater" than a type. */
10258 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
10259 if (DECL_NAME (*x
) == NULL_TREE
)
10261 if (DECL_NAME (*y
) == NULL_TREE
)
10263 if (DECL_NAME (*x
) < DECL_NAME (*y
))
10269 gt_pointer_operator new_value
;
10273 /* This routine compares two fields like field_decl_cmp but using the
10274 pointer operator in resort_data. */
10277 resort_field_decl_cmp (const void *x_p
, const void *y_p
)
10279 const tree
*const x
= (const tree
*const) x_p
;
10280 const tree
*const y
= (const tree
*const) y_p
;
10282 if (DECL_NAME (*x
) == DECL_NAME (*y
))
10283 /* A nontype is "greater" than a type. */
10284 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
10285 if (DECL_NAME (*x
) == NULL_TREE
)
10287 if (DECL_NAME (*y
) == NULL_TREE
)
10290 tree d1
= DECL_NAME (*x
);
10291 tree d2
= DECL_NAME (*y
);
10292 resort_data
.new_value (&d1
, resort_data
.cookie
);
10293 resort_data
.new_value (&d2
, resort_data
.cookie
);
10300 /* Resort DECL_SORTED_FIELDS because pointers have been reordered. */
10303 resort_sorted_fields (void *obj
,
10304 void * ARG_UNUSED (orig_obj
),
10305 gt_pointer_operator new_value
,
10308 struct sorted_fields_type
*sf
= (struct sorted_fields_type
*) obj
;
10309 resort_data
.new_value
= new_value
;
10310 resort_data
.cookie
= cookie
;
10311 qsort (&sf
->elts
[0], sf
->len
, sizeof (tree
),
10312 resort_field_decl_cmp
);
10315 /* Subroutine of c_parse_error.
10316 Return the result of concatenating LHS and RHS. RHS is really
10317 a string literal, its first character is indicated by RHS_START and
10318 RHS_SIZE is its length (including the terminating NUL character).
10320 The caller is responsible for deleting the returned pointer. */
10323 catenate_strings (const char *lhs
, const char *rhs_start
, int rhs_size
)
10325 const int lhs_size
= strlen (lhs
);
10326 char *result
= XNEWVEC (char, lhs_size
+ rhs_size
);
10327 strncpy (result
, lhs
, lhs_size
);
10328 strncpy (result
+ lhs_size
, rhs_start
, rhs_size
);
10332 /* Issue the error given by GMSGID, indicating that it occurred before
10333 TOKEN, which had the associated VALUE. */
10336 c_parse_error (const char *gmsgid
, enum cpp_ttype token_type
,
10337 tree value
, unsigned char token_flags
)
10339 #define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2))
10341 char *message
= NULL
;
10343 if (token_type
== CPP_EOF
)
10344 message
= catenate_messages (gmsgid
, " at end of input");
10345 else if (token_type
== CPP_CHAR
10346 || token_type
== CPP_WCHAR
10347 || token_type
== CPP_CHAR16
10348 || token_type
== CPP_CHAR32
10349 || token_type
== CPP_UTF8CHAR
)
10351 unsigned int val
= TREE_INT_CST_LOW (value
);
10352 const char *prefix
;
10354 switch (token_type
)
10373 if (val
<= UCHAR_MAX
&& ISGRAPH (val
))
10374 message
= catenate_messages (gmsgid
, " before %s'%c'");
10376 message
= catenate_messages (gmsgid
, " before %s'\\x%x'");
10378 error (message
, prefix
, val
);
10382 else if (token_type
== CPP_CHAR_USERDEF
10383 || token_type
== CPP_WCHAR_USERDEF
10384 || token_type
== CPP_CHAR16_USERDEF
10385 || token_type
== CPP_CHAR32_USERDEF
10386 || token_type
== CPP_UTF8CHAR_USERDEF
)
10387 message
= catenate_messages (gmsgid
,
10388 " before user-defined character literal");
10389 else if (token_type
== CPP_STRING_USERDEF
10390 || token_type
== CPP_WSTRING_USERDEF
10391 || token_type
== CPP_STRING16_USERDEF
10392 || token_type
== CPP_STRING32_USERDEF
10393 || token_type
== CPP_UTF8STRING_USERDEF
)
10394 message
= catenate_messages (gmsgid
, " before user-defined string literal");
10395 else if (token_type
== CPP_STRING
10396 || token_type
== CPP_WSTRING
10397 || token_type
== CPP_STRING16
10398 || token_type
== CPP_STRING32
10399 || token_type
== CPP_UTF8STRING
)
10400 message
= catenate_messages (gmsgid
, " before string constant");
10401 else if (token_type
== CPP_NUMBER
)
10402 message
= catenate_messages (gmsgid
, " before numeric constant");
10403 else if (token_type
== CPP_NAME
)
10405 message
= catenate_messages (gmsgid
, " before %qE");
10406 error (message
, value
);
10410 else if (token_type
== CPP_PRAGMA
)
10411 message
= catenate_messages (gmsgid
, " before %<#pragma%>");
10412 else if (token_type
== CPP_PRAGMA_EOL
)
10413 message
= catenate_messages (gmsgid
, " before end of line");
10414 else if (token_type
== CPP_DECLTYPE
)
10415 message
= catenate_messages (gmsgid
, " before %<decltype%>");
10416 else if (token_type
< N_TTYPES
)
10418 message
= catenate_messages (gmsgid
, " before %qs token");
10419 error (message
, cpp_type2name (token_type
, token_flags
));
10431 #undef catenate_messages
10434 /* Return the gcc option code associated with the reason for a cpp
10435 message, or 0 if none. */
10438 c_option_controlling_cpp_error (int reason
)
10440 const struct cpp_reason_option_codes_t
*entry
;
10442 for (entry
= cpp_reason_option_codes
; entry
->reason
!= CPP_W_NONE
; entry
++)
10444 if (entry
->reason
== reason
)
10445 return entry
->option_code
;
10450 /* Callback from cpp_error for PFILE to print diagnostics from the
10451 preprocessor. The diagnostic is of type LEVEL, with REASON set
10452 to the reason code if LEVEL is represents a warning, at location
10453 RICHLOC unless this is after lexing and the compiler's location
10454 should be used instead; MSG is the translated message and AP
10455 the arguments. Returns true if a diagnostic was emitted, false
10459 c_cpp_error (cpp_reader
*pfile ATTRIBUTE_UNUSED
, int level
, int reason
,
10460 rich_location
*richloc
,
10461 const char *msg
, va_list *ap
)
10463 diagnostic_info diagnostic
;
10464 diagnostic_t dlevel
;
10465 bool save_warn_system_headers
= global_dc
->dc_warn_system_headers
;
10470 case CPP_DL_WARNING_SYSHDR
:
10471 if (flag_no_output
)
10473 global_dc
->dc_warn_system_headers
= 1;
10474 /* Fall through. */
10475 case CPP_DL_WARNING
:
10476 if (flag_no_output
)
10478 dlevel
= DK_WARNING
;
10480 case CPP_DL_PEDWARN
:
10481 if (flag_no_output
&& !flag_pedantic_errors
)
10483 dlevel
= DK_PEDWARN
;
10498 gcc_unreachable ();
10501 richloc
->set_range (line_table
, 0, input_location
, true);
10502 diagnostic_set_info_translated (&diagnostic
, msg
, ap
,
10504 diagnostic_override_option_index (&diagnostic
,
10505 c_option_controlling_cpp_error (reason
));
10506 ret
= report_diagnostic (&diagnostic
);
10507 if (level
== CPP_DL_WARNING_SYSHDR
)
10508 global_dc
->dc_warn_system_headers
= save_warn_system_headers
;
10512 /* Convert a character from the host to the target execution character
10513 set. cpplib handles this, mostly. */
10516 c_common_to_target_charset (HOST_WIDE_INT c
)
10518 /* Character constants in GCC proper are sign-extended under -fsigned-char,
10519 zero-extended under -fno-signed-char. cpplib insists that characters
10520 and character constants are always unsigned. Hence we must convert
10522 cppchar_t uc
= ((cppchar_t
)c
) & ((((cppchar_t
)1) << CHAR_BIT
)-1);
10524 uc
= cpp_host_to_exec_charset (parse_in
, uc
);
10526 if (flag_signed_char
)
10527 return ((HOST_WIDE_INT
)uc
) << (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
)
10528 >> (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
);
10533 /* Fold an offsetof-like expression. EXPR is a nested sequence of component
10534 references with an INDIRECT_REF of a constant at the bottom; much like the
10535 traditional rendering of offsetof as a macro. Return the folded result. */
10538 fold_offsetof_1 (tree expr
, enum tree_code ctx
)
10541 tree_code code
= TREE_CODE (expr
);
10548 error ("cannot apply %<offsetof%> to static data member %qD", expr
);
10549 return error_mark_node
;
10553 error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded");
10554 return error_mark_node
;
10558 if (!TREE_CONSTANT (TREE_OPERAND (expr
, 0)))
10560 error ("cannot apply %<offsetof%> to a non constant address");
10561 return error_mark_node
;
10563 return TREE_OPERAND (expr
, 0);
10565 case COMPONENT_REF
:
10566 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0), code
);
10567 if (base
== error_mark_node
)
10570 t
= TREE_OPERAND (expr
, 1);
10571 if (DECL_C_BIT_FIELD (t
))
10573 error ("attempt to take address of bit-field structure "
10575 return error_mark_node
;
10577 off
= size_binop_loc (input_location
, PLUS_EXPR
, DECL_FIELD_OFFSET (t
),
10578 size_int (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (t
))
10583 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0), code
);
10584 if (base
== error_mark_node
)
10587 t
= TREE_OPERAND (expr
, 1);
10589 /* Check if the offset goes beyond the upper bound of the array. */
10590 if (TREE_CODE (t
) == INTEGER_CST
&& tree_int_cst_sgn (t
) >= 0)
10592 tree upbound
= array_ref_up_bound (expr
);
10593 if (upbound
!= NULL_TREE
10594 && TREE_CODE (upbound
) == INTEGER_CST
10595 && !tree_int_cst_equal (upbound
,
10596 TYPE_MAX_VALUE (TREE_TYPE (upbound
))))
10598 if (ctx
!= ARRAY_REF
&& ctx
!= COMPONENT_REF
)
10599 upbound
= size_binop (PLUS_EXPR
, upbound
,
10600 build_int_cst (TREE_TYPE (upbound
), 1));
10601 if (tree_int_cst_lt (upbound
, t
))
10605 for (v
= TREE_OPERAND (expr
, 0);
10606 TREE_CODE (v
) == COMPONENT_REF
;
10607 v
= TREE_OPERAND (v
, 0))
10608 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v
, 0)))
10611 tree fld_chain
= DECL_CHAIN (TREE_OPERAND (v
, 1));
10612 for (; fld_chain
; fld_chain
= DECL_CHAIN (fld_chain
))
10613 if (TREE_CODE (fld_chain
) == FIELD_DECL
)
10619 /* Don't warn if the array might be considered a poor
10620 man's flexible array member with a very permissive
10621 definition thereof. */
10622 if (TREE_CODE (v
) == ARRAY_REF
10623 || TREE_CODE (v
) == COMPONENT_REF
)
10624 warning (OPT_Warray_bounds
,
10625 "index %E denotes an offset "
10626 "greater than size of %qT",
10627 t
, TREE_TYPE (TREE_OPERAND (expr
, 0)));
10632 t
= convert (sizetype
, t
);
10633 off
= size_binop (MULT_EXPR
, TYPE_SIZE_UNIT (TREE_TYPE (expr
)), t
);
10636 case COMPOUND_EXPR
:
10637 /* Handle static members of volatile structs. */
10638 t
= TREE_OPERAND (expr
, 1);
10639 gcc_assert (VAR_P (t
));
10640 return fold_offsetof_1 (t
);
10643 gcc_unreachable ();
10646 return fold_build_pointer_plus (base
, off
);
10649 /* Likewise, but convert it to the return type of offsetof. */
10652 fold_offsetof (tree expr
)
10654 return convert (size_type_node
, fold_offsetof_1 (expr
));
10657 /* Warn for A ?: C expressions (with B omitted) where A is a boolean
10658 expression, because B will always be true. */
10661 warn_for_omitted_condop (location_t location
, tree cond
)
10663 /* In C++ template declarations it can happen that the type is dependent
10664 and not yet known, thus TREE_TYPE (cond) == NULL_TREE. */
10665 if (truth_value_p (TREE_CODE (cond
))
10666 || (TREE_TYPE (cond
) != NULL_TREE
10667 && TREE_CODE (TREE_TYPE (cond
)) == BOOLEAN_TYPE
))
10668 warning_at (location
, OPT_Wparentheses
,
10669 "the omitted middle operand in ?: will always be %<true%>, "
10670 "suggest explicit middle operand");
10673 /* Give an error for storing into ARG, which is 'const'. USE indicates
10674 how ARG was being used. */
10677 readonly_error (location_t loc
, tree arg
, enum lvalue_use use
)
10679 gcc_assert (use
== lv_assign
|| use
== lv_increment
|| use
== lv_decrement
10681 /* Using this macro rather than (for example) arrays of messages
10682 ensures that all the format strings are checked at compile
10684 #define READONLY_MSG(A, I, D, AS) (use == lv_assign ? (A) \
10685 : (use == lv_increment ? (I) \
10686 : (use == lv_decrement ? (D) : (AS))))
10687 if (TREE_CODE (arg
) == COMPONENT_REF
)
10689 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg
, 0))))
10690 error_at (loc
, READONLY_MSG (G_("assignment of member "
10691 "%qD in read-only object"),
10692 G_("increment of member "
10693 "%qD in read-only object"),
10694 G_("decrement of member "
10695 "%qD in read-only object"),
10696 G_("member %qD in read-only object "
10697 "used as %<asm%> output")),
10698 TREE_OPERAND (arg
, 1));
10700 error_at (loc
, READONLY_MSG (G_("assignment of read-only member %qD"),
10701 G_("increment of read-only member %qD"),
10702 G_("decrement of read-only member %qD"),
10703 G_("read-only member %qD used as %<asm%> output")),
10704 TREE_OPERAND (arg
, 1));
10706 else if (VAR_P (arg
))
10707 error_at (loc
, READONLY_MSG (G_("assignment of read-only variable %qD"),
10708 G_("increment of read-only variable %qD"),
10709 G_("decrement of read-only variable %qD"),
10710 G_("read-only variable %qD used as %<asm%> output")),
10712 else if (TREE_CODE (arg
) == PARM_DECL
)
10713 error_at (loc
, READONLY_MSG (G_("assignment of read-only parameter %qD"),
10714 G_("increment of read-only parameter %qD"),
10715 G_("decrement of read-only parameter %qD"),
10716 G_("read-only parameter %qD use as %<asm%> output")),
10718 else if (TREE_CODE (arg
) == RESULT_DECL
)
10720 gcc_assert (c_dialect_cxx ());
10721 error_at (loc
, READONLY_MSG (G_("assignment of "
10722 "read-only named return value %qD"),
10724 "read-only named return value %qD"),
10726 "read-only named return value %qD"),
10727 G_("read-only named return value %qD "
10728 "used as %<asm%>output")),
10731 else if (TREE_CODE (arg
) == FUNCTION_DECL
)
10732 error_at (loc
, READONLY_MSG (G_("assignment of function %qD"),
10733 G_("increment of function %qD"),
10734 G_("decrement of function %qD"),
10735 G_("function %qD used as %<asm%> output")),
10738 error_at (loc
, READONLY_MSG (G_("assignment of read-only location %qE"),
10739 G_("increment of read-only location %qE"),
10740 G_("decrement of read-only location %qE"),
10741 G_("read-only location %qE used as %<asm%> output")),
10745 /* Print an error message for an invalid lvalue. USE says
10746 how the lvalue is being used and so selects the error message. LOC
10747 is the location for the error. */
10750 lvalue_error (location_t loc
, enum lvalue_use use
)
10755 error_at (loc
, "lvalue required as left operand of assignment");
10758 error_at (loc
, "lvalue required as increment operand");
10761 error_at (loc
, "lvalue required as decrement operand");
10764 error_at (loc
, "lvalue required as unary %<&%> operand");
10767 error_at (loc
, "lvalue required in asm statement");
10770 gcc_unreachable ();
10774 /* Print an error message for an invalid indirection of type TYPE.
10775 ERRSTRING is the name of the operator for the indirection. */
10778 invalid_indirection_error (location_t loc
, tree type
, ref_operator errstring
)
10783 gcc_assert (c_dialect_cxx ());
10784 error_at (loc
, "invalid type argument (have %qT)", type
);
10786 case RO_ARRAY_INDEXING
:
10788 "invalid type argument of array indexing (have %qT)",
10791 case RO_UNARY_STAR
:
10793 "invalid type argument of unary %<*%> (have %qT)",
10798 "invalid type argument of %<->%> (have %qT)",
10801 case RO_ARROW_STAR
:
10803 "invalid type argument of %<->*%> (have %qT)",
10806 case RO_IMPLICIT_CONVERSION
:
10808 "invalid type argument of implicit conversion (have %qT)",
10812 gcc_unreachable ();
10816 /* *PTYPE is an incomplete array. Complete it with a domain based on
10817 INITIAL_VALUE. If INITIAL_VALUE is not present, use 1 if DO_DEFAULT
10818 is true. Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
10819 2 if INITIAL_VALUE was NULL, and 3 if INITIAL_VALUE was empty. */
10822 complete_array_type (tree
*ptype
, tree initial_value
, bool do_default
)
10824 tree maxindex
, type
, main_type
, elt
, unqual_elt
;
10825 int failure
= 0, quals
;
10826 hashval_t hashcode
= 0;
10827 bool overflow_p
= false;
10829 maxindex
= size_zero_node
;
10832 if (TREE_CODE (initial_value
) == STRING_CST
)
10835 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value
)));
10836 maxindex
= size_int (TREE_STRING_LENGTH (initial_value
)/eltsize
- 1);
10838 else if (TREE_CODE (initial_value
) == CONSTRUCTOR
)
10840 vec
<constructor_elt
, va_gc
> *v
= CONSTRUCTOR_ELTS (initial_value
);
10842 if (vec_safe_is_empty (v
))
10846 maxindex
= ssize_int (-1);
10851 unsigned HOST_WIDE_INT cnt
;
10852 constructor_elt
*ce
;
10853 bool fold_p
= false;
10856 maxindex
= (*v
)[0].index
, fold_p
= true;
10858 curindex
= maxindex
;
10860 for (cnt
= 1; vec_safe_iterate (v
, cnt
, &ce
); cnt
++)
10862 bool curfold_p
= false;
10864 curindex
= ce
->index
, curfold_p
= true;
10869 /* Since we treat size types now as ordinary
10870 unsigned types, we need an explicit overflow
10872 tree orig
= curindex
;
10873 curindex
= fold_convert (sizetype
, curindex
);
10874 overflow_p
|= tree_int_cst_lt (curindex
, orig
);
10876 curindex
= size_binop (PLUS_EXPR
, curindex
,
10879 if (tree_int_cst_lt (maxindex
, curindex
))
10880 maxindex
= curindex
, fold_p
= curfold_p
;
10884 tree orig
= maxindex
;
10885 maxindex
= fold_convert (sizetype
, maxindex
);
10886 overflow_p
|= tree_int_cst_lt (maxindex
, orig
);
10892 /* Make an error message unless that happened already. */
10893 if (initial_value
!= error_mark_node
)
10905 elt
= TREE_TYPE (type
);
10906 quals
= TYPE_QUALS (strip_array_types (elt
));
10910 unqual_elt
= c_build_qualified_type (elt
, KEEP_QUAL_ADDR_SPACE (quals
));
10912 /* Using build_distinct_type_copy and modifying things afterward instead
10913 of using build_array_type to create a new type preserves all of the
10914 TYPE_LANG_FLAG_? bits that the front end may have set. */
10915 main_type
= build_distinct_type_copy (TYPE_MAIN_VARIANT (type
));
10916 TREE_TYPE (main_type
) = unqual_elt
;
10917 TYPE_DOMAIN (main_type
)
10918 = build_range_type (TREE_TYPE (maxindex
),
10919 build_int_cst (TREE_TYPE (maxindex
), 0), maxindex
);
10920 layout_type (main_type
);
10922 /* Make sure we have the canonical MAIN_TYPE. */
10923 hashcode
= iterative_hash_object (TYPE_HASH (unqual_elt
), hashcode
);
10924 hashcode
= iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (main_type
)),
10926 main_type
= type_hash_canon (hashcode
, main_type
);
10928 /* Fix the canonical type. */
10929 if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type
))
10930 || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type
)))
10931 SET_TYPE_STRUCTURAL_EQUALITY (main_type
);
10932 else if (TYPE_CANONICAL (TREE_TYPE (main_type
)) != TREE_TYPE (main_type
)
10933 || (TYPE_CANONICAL (TYPE_DOMAIN (main_type
))
10934 != TYPE_DOMAIN (main_type
)))
10935 TYPE_CANONICAL (main_type
)
10936 = build_array_type (TYPE_CANONICAL (TREE_TYPE (main_type
)),
10937 TYPE_CANONICAL (TYPE_DOMAIN (main_type
)));
10939 TYPE_CANONICAL (main_type
) = main_type
;
10944 type
= c_build_qualified_type (main_type
, quals
);
10946 if (COMPLETE_TYPE_P (type
)
10947 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
10948 && (overflow_p
|| TREE_OVERFLOW (TYPE_SIZE_UNIT (type
))))
10950 error ("size of array is too large");
10951 /* If we proceed with the array type as it is, we'll eventually
10952 crash in tree_to_[su]hwi(). */
10953 type
= error_mark_node
;
10960 /* Like c_mark_addressable but don't check register qualifier. */
10962 c_common_mark_addressable_vec (tree t
)
10964 while (handled_component_p (t
))
10965 t
= TREE_OPERAND (t
, 0);
10967 && TREE_CODE (t
) != PARM_DECL
10968 && TREE_CODE (t
) != COMPOUND_LITERAL_EXPR
)
10970 TREE_ADDRESSABLE (t
) = 1;
10975 /* Used to help initialize the builtin-types.def table. When a type of
10976 the correct size doesn't exist, use error_mark_node instead of NULL.
10977 The later results in segfaults even when a decl using the type doesn't
10981 builtin_type_for_size (int size
, bool unsignedp
)
10983 tree type
= c_common_type_for_size (size
, unsignedp
);
10984 return type
? type
: error_mark_node
;
10987 /* A helper function for resolve_overloaded_builtin in resolving the
10988 overloaded __sync_ builtins. Returns a positive power of 2 if the
10989 first operand of PARAMS is a pointer to a supported data type.
10990 Returns 0 if an error is encountered.
10991 FETCH is true when FUNCTION is one of the _FETCH_OP_ or _OP_FETCH_
10995 sync_resolve_size (tree function
, vec
<tree
, va_gc
> *params
, bool fetch
)
10997 /* Type of the argument. */
10999 /* Type the argument points to. */
11003 if (vec_safe_is_empty (params
))
11005 error ("too few arguments to function %qE", function
);
11009 argtype
= type
= TREE_TYPE ((*params
)[0]);
11010 if (TREE_CODE (type
) == ARRAY_TYPE
)
11012 /* Force array-to-pointer decay for C++. */
11013 gcc_assert (c_dialect_cxx());
11014 (*params
)[0] = default_conversion ((*params
)[0]);
11015 type
= TREE_TYPE ((*params
)[0]);
11017 if (TREE_CODE (type
) != POINTER_TYPE
)
11020 type
= TREE_TYPE (type
);
11021 if (!INTEGRAL_TYPE_P (type
) && !POINTER_TYPE_P (type
))
11024 if (fetch
&& TREE_CODE (type
) == BOOLEAN_TYPE
)
11027 size
= tree_to_uhwi (TYPE_SIZE_UNIT (type
));
11028 if (size
== 1 || size
== 2 || size
== 4 || size
== 8 || size
== 16)
11032 /* Issue the diagnostic only if the argument is valid, otherwise
11033 it would be redundant at best and could be misleading. */
11034 if (argtype
!= error_mark_node
)
11035 error ("operand type %qT is incompatible with argument %d of %qE",
11036 argtype
, 1, function
);
11040 /* A helper function for resolve_overloaded_builtin. Adds casts to
11041 PARAMS to make arguments match up with those of FUNCTION. Drops
11042 the variadic arguments at the end. Returns false if some error
11043 was encountered; true on success. */
11046 sync_resolve_params (location_t loc
, tree orig_function
, tree function
,
11047 vec
<tree
, va_gc
> *params
, bool orig_format
)
11049 function_args_iterator iter
;
11051 unsigned int parmnum
;
11053 function_args_iter_init (&iter
, TREE_TYPE (function
));
11054 /* We've declared the implementation functions to use "volatile void *"
11055 as the pointer parameter, so we shouldn't get any complaints from the
11056 call to check_function_arguments what ever type the user used. */
11057 function_args_iter_next (&iter
);
11058 ptype
= TREE_TYPE (TREE_TYPE ((*params
)[0]));
11059 ptype
= TYPE_MAIN_VARIANT (ptype
);
11061 /* For the rest of the values, we need to cast these to FTYPE, so that we
11062 don't get warnings for passing pointer types, etc. */
11066 tree val
, arg_type
;
11068 arg_type
= function_args_iter_cond (&iter
);
11069 /* XXX void_type_node belies the abstraction. */
11070 if (arg_type
== void_type_node
)
11074 if (params
->length () <= parmnum
)
11076 error_at (loc
, "too few arguments to function %qE", orig_function
);
11080 /* Only convert parameters if arg_type is unsigned integer type with
11081 new format sync routines, i.e. don't attempt to convert pointer
11082 arguments (e.g. EXPECTED argument of __atomic_compare_exchange_n),
11083 bool arguments (e.g. WEAK argument) or signed int arguments (memmodel
11085 if (TREE_CODE (arg_type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (arg_type
))
11087 /* Ideally for the first conversion we'd use convert_for_assignment
11088 so that we get warnings for anything that doesn't match the pointer
11089 type. This isn't portable across the C and C++ front ends atm. */
11090 val
= (*params
)[parmnum
];
11091 val
= convert (ptype
, val
);
11092 val
= convert (arg_type
, val
);
11093 (*params
)[parmnum
] = val
;
11096 function_args_iter_next (&iter
);
11099 /* __atomic routines are not variadic. */
11100 if (!orig_format
&& params
->length () != parmnum
+ 1)
11102 error_at (loc
, "too many arguments to function %qE", orig_function
);
11106 /* The definition of these primitives is variadic, with the remaining
11107 being "an optional list of variables protected by the memory barrier".
11108 No clue what that's supposed to mean, precisely, but we consider all
11109 call-clobbered variables to be protected so we're safe. */
11110 params
->truncate (parmnum
+ 1);
11115 /* A helper function for resolve_overloaded_builtin. Adds a cast to
11116 RESULT to make it match the type of the first pointer argument in
11120 sync_resolve_return (tree first_param
, tree result
, bool orig_format
)
11122 tree ptype
= TREE_TYPE (TREE_TYPE (first_param
));
11123 tree rtype
= TREE_TYPE (result
);
11124 ptype
= TYPE_MAIN_VARIANT (ptype
);
11126 /* New format doesn't require casting unless the types are the same size. */
11127 if (orig_format
|| tree_int_cst_equal (TYPE_SIZE (ptype
), TYPE_SIZE (rtype
)))
11128 return convert (ptype
, result
);
11133 /* This function verifies the PARAMS to generic atomic FUNCTION.
11134 It returns the size if all the parameters are the same size, otherwise
11135 0 is returned if the parameters are invalid. */
11138 get_atomic_generic_size (location_t loc
, tree function
,
11139 vec
<tree
, va_gc
> *params
)
11141 unsigned int n_param
;
11142 unsigned int n_model
;
11147 /* Determine the parameter makeup. */
11148 switch (DECL_FUNCTION_CODE (function
))
11150 case BUILT_IN_ATOMIC_EXCHANGE
:
11154 case BUILT_IN_ATOMIC_LOAD
:
11155 case BUILT_IN_ATOMIC_STORE
:
11159 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
11164 gcc_unreachable ();
11167 if (vec_safe_length (params
) != n_param
)
11169 error_at (loc
, "incorrect number of arguments to function %qE", function
);
11173 /* Get type of first parameter, and determine its size. */
11174 type_0
= TREE_TYPE ((*params
)[0]);
11175 if (TREE_CODE (type_0
) == ARRAY_TYPE
)
11177 /* Force array-to-pointer decay for C++. */
11178 gcc_assert (c_dialect_cxx());
11179 (*params
)[0] = default_conversion ((*params
)[0]);
11180 type_0
= TREE_TYPE ((*params
)[0]);
11182 if (TREE_CODE (type_0
) != POINTER_TYPE
|| VOID_TYPE_P (TREE_TYPE (type_0
)))
11184 error_at (loc
, "argument 1 of %qE must be a non-void pointer type",
11189 /* Types must be compile time constant sizes. */
11190 if (TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type_0
)))) != INTEGER_CST
)
11193 "argument 1 of %qE must be a pointer to a constant size type",
11198 size_0
= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type_0
)));
11200 /* Zero size objects are not allowed. */
11204 "argument 1 of %qE must be a pointer to a nonzero size object",
11209 /* Check each other parameter is a pointer and the same size. */
11210 for (x
= 0; x
< n_param
- n_model
; x
++)
11213 tree type
= TREE_TYPE ((*params
)[x
]);
11214 /* __atomic_compare_exchange has a bool in the 4th position, skip it. */
11215 if (n_param
== 6 && x
== 3)
11217 if (!POINTER_TYPE_P (type
))
11219 error_at (loc
, "argument %d of %qE must be a pointer type", x
+ 1,
11223 else if (TYPE_SIZE_UNIT (TREE_TYPE (type
))
11224 && TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type
))))
11227 error_at (loc
, "argument %d of %qE must be a pointer to a constant "
11228 "size type", x
+ 1, function
);
11231 else if (FUNCTION_POINTER_TYPE_P (type
))
11233 error_at (loc
, "argument %d of %qE must not be a pointer to a "
11234 "function", x
+ 1, function
);
11237 tree type_size
= TYPE_SIZE_UNIT (TREE_TYPE (type
));
11238 size
= type_size
? tree_to_uhwi (type_size
) : 0;
11239 if (size
!= size_0
)
11241 error_at (loc
, "size mismatch in argument %d of %qE", x
+ 1,
11247 /* Check memory model parameters for validity. */
11248 for (x
= n_param
- n_model
; x
< n_param
; x
++)
11250 tree p
= (*params
)[x
];
11251 if (TREE_CODE (p
) == INTEGER_CST
)
11253 int i
= tree_to_uhwi (p
);
11254 if (i
< 0 || (memmodel_base (i
) >= MEMMODEL_LAST
))
11256 warning_at (loc
, OPT_Winvalid_memory_model
,
11257 "invalid memory model argument %d of %qE", x
+ 1,
11262 if (!INTEGRAL_TYPE_P (TREE_TYPE (p
)))
11264 error_at (loc
, "non-integer memory model argument %d of %qE", x
+ 1,
11274 /* This will take an __atomic_ generic FUNCTION call, and add a size parameter N
11275 at the beginning of the parameter list PARAMS representing the size of the
11276 objects. This is to match the library ABI requirement. LOC is the location
11277 of the function call.
11278 The new function is returned if it needed rebuilding, otherwise NULL_TREE is
11279 returned to allow the external call to be constructed. */
11282 add_atomic_size_parameter (unsigned n
, location_t loc
, tree function
,
11283 vec
<tree
, va_gc
> *params
)
11287 /* Insert a SIZE_T parameter as the first param. If there isn't
11288 enough space, allocate a new vector and recursively re-build with that. */
11289 if (!params
->space (1))
11291 unsigned int z
, len
;
11292 vec
<tree
, va_gc
> *v
;
11295 len
= params
->length ();
11296 vec_alloc (v
, len
+ 1);
11297 v
->quick_push (build_int_cst (size_type_node
, n
));
11298 for (z
= 0; z
< len
; z
++)
11299 v
->quick_push ((*params
)[z
]);
11300 f
= build_function_call_vec (loc
, vNULL
, function
, v
, NULL
);
11305 /* Add the size parameter and leave as a function call for processing. */
11306 size_node
= build_int_cst (size_type_node
, n
);
11307 params
->quick_insert (0, size_node
);
11312 /* Return whether atomic operations for naturally aligned N-byte
11313 arguments are supported, whether inline or through libatomic. */
11315 atomic_size_supported_p (int n
)
11326 return targetm
.scalar_mode_supported_p (TImode
);
11333 /* This will process an __atomic_exchange function call, determine whether it
11334 needs to be mapped to the _N variation, or turned into a library call.
11335 LOC is the location of the builtin call.
11336 FUNCTION is the DECL that has been invoked;
11337 PARAMS is the argument list for the call. The return value is non-null
11338 TRUE is returned if it is translated into the proper format for a call to the
11339 external library, and NEW_RETURN is set the tree for that function.
11340 FALSE is returned if processing for the _N variation is required, and
11341 NEW_RETURN is set to the return value the result is copied into. */
11343 resolve_overloaded_atomic_exchange (location_t loc
, tree function
,
11344 vec
<tree
, va_gc
> *params
, tree
*new_return
)
11346 tree p0
, p1
, p2
, p3
;
11347 tree I_type
, I_type_ptr
;
11348 int n
= get_atomic_generic_size (loc
, function
, params
);
11350 /* Size of 0 is an error condition. */
11353 *new_return
= error_mark_node
;
11357 /* If not a lock-free size, change to the library generic format. */
11358 if (!atomic_size_supported_p (n
))
11360 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
11364 /* Otherwise there is a lockfree match, transform the call from:
11365 void fn(T* mem, T* desired, T* return, model)
11367 *return = (T) (fn (In* mem, (In) *desired, model)) */
11374 /* Create pointer to appropriate size. */
11375 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
11376 I_type_ptr
= build_pointer_type (I_type
);
11378 /* Convert object pointer to required type. */
11379 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
11381 /* Convert new value to required type, and dereference it. */
11382 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
11383 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
11386 /* Move memory model to the 3rd position, and end param list. */
11388 params
->truncate (3);
11390 /* Convert return pointer and dereference it for later assignment. */
11391 *new_return
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
11397 /* This will process an __atomic_compare_exchange function call, determine
11398 whether it needs to be mapped to the _N variation, or turned into a lib call.
11399 LOC is the location of the builtin call.
11400 FUNCTION is the DECL that has been invoked;
11401 PARAMS is the argument list for the call. The return value is non-null
11402 TRUE is returned if it is translated into the proper format for a call to the
11403 external library, and NEW_RETURN is set the tree for that function.
11404 FALSE is returned if processing for the _N variation is required. */
11407 resolve_overloaded_atomic_compare_exchange (location_t loc
, tree function
,
11408 vec
<tree
, va_gc
> *params
,
11412 tree I_type
, I_type_ptr
;
11413 int n
= get_atomic_generic_size (loc
, function
, params
);
11415 /* Size of 0 is an error condition. */
11418 *new_return
= error_mark_node
;
11422 /* If not a lock-free size, change to the library generic format. */
11423 if (!atomic_size_supported_p (n
))
11425 /* The library generic format does not have the weak parameter, so
11426 remove it from the param list. Since a parameter has been removed,
11427 we can be sure that there is room for the SIZE_T parameter, meaning
11428 there will not be a recursive rebuilding of the parameter list, so
11429 there is no danger this will be done twice. */
11432 (*params
)[3] = (*params
)[4];
11433 (*params
)[4] = (*params
)[5];
11434 params
->truncate (5);
11436 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
11440 /* Otherwise, there is a match, so the call needs to be transformed from:
11441 bool fn(T* mem, T* desired, T* return, weak, success, failure)
11443 bool fn ((In *)mem, (In *)expected, (In) *desired, weak, succ, fail) */
11449 /* Create pointer to appropriate size. */
11450 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
11451 I_type_ptr
= build_pointer_type (I_type
);
11453 /* Convert object pointer to required type. */
11454 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
11457 /* Convert expected pointer to required type. */
11458 p1
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p1
);
11461 /* Convert desired value to required type, and dereference it. */
11462 p2
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
11463 p2
= build1 (VIEW_CONVERT_EXPR
, I_type
, p2
);
11466 /* The rest of the parameters are fine. NULL means no special return value
11468 *new_return
= NULL
;
11473 /* This will process an __atomic_load function call, determine whether it
11474 needs to be mapped to the _N variation, or turned into a library call.
11475 LOC is the location of the builtin call.
11476 FUNCTION is the DECL that has been invoked;
11477 PARAMS is the argument list for the call. The return value is non-null
11478 TRUE is returned if it is translated into the proper format for a call to the
11479 external library, and NEW_RETURN is set the tree for that function.
11480 FALSE is returned if processing for the _N variation is required, and
11481 NEW_RETURN is set to the return value the result is copied into. */
11484 resolve_overloaded_atomic_load (location_t loc
, tree function
,
11485 vec
<tree
, va_gc
> *params
, tree
*new_return
)
11488 tree I_type
, I_type_ptr
;
11489 int n
= get_atomic_generic_size (loc
, function
, params
);
11491 /* Size of 0 is an error condition. */
11494 *new_return
= error_mark_node
;
11498 /* If not a lock-free size, change to the library generic format. */
11499 if (!atomic_size_supported_p (n
))
11501 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
11505 /* Otherwise, there is a match, so the call needs to be transformed from:
11506 void fn(T* mem, T* return, model)
11508 *return = (T) (fn ((In *) mem, model)) */
11514 /* Create pointer to appropriate size. */
11515 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
11516 I_type_ptr
= build_pointer_type (I_type
);
11518 /* Convert object pointer to required type. */
11519 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
11522 /* Move memory model to the 2nd position, and end param list. */
11524 params
->truncate (2);
11526 /* Convert return pointer and dereference it for later assignment. */
11527 *new_return
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
11533 /* This will process an __atomic_store function call, determine whether it
11534 needs to be mapped to the _N variation, or turned into a library call.
11535 LOC is the location of the builtin call.
11536 FUNCTION is the DECL that has been invoked;
11537 PARAMS is the argument list for the call. The return value is non-null
11538 TRUE is returned if it is translated into the proper format for a call to the
11539 external library, and NEW_RETURN is set the tree for that function.
11540 FALSE is returned if processing for the _N variation is required, and
11541 NEW_RETURN is set to the return value the result is copied into. */
11544 resolve_overloaded_atomic_store (location_t loc
, tree function
,
11545 vec
<tree
, va_gc
> *params
, tree
*new_return
)
11548 tree I_type
, I_type_ptr
;
11549 int n
= get_atomic_generic_size (loc
, function
, params
);
11551 /* Size of 0 is an error condition. */
11554 *new_return
= error_mark_node
;
11558 /* If not a lock-free size, change to the library generic format. */
11559 if (!atomic_size_supported_p (n
))
11561 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
11565 /* Otherwise, there is a match, so the call needs to be transformed from:
11566 void fn(T* mem, T* value, model)
11568 fn ((In *) mem, (In) *value, model) */
11573 /* Create pointer to appropriate size. */
11574 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
11575 I_type_ptr
= build_pointer_type (I_type
);
11577 /* Convert object pointer to required type. */
11578 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
11581 /* Convert new value to required type, and dereference it. */
11582 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
11583 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
11586 /* The memory model is in the right spot already. Return is void. */
11587 *new_return
= NULL_TREE
;
11593 /* Some builtin functions are placeholders for other expressions. This
11594 function should be called immediately after parsing the call expression
11595 before surrounding code has committed to the type of the expression.
11597 LOC is the location of the builtin call.
11599 FUNCTION is the DECL that has been invoked; it is known to be a builtin.
11600 PARAMS is the argument list for the call. The return value is non-null
11601 when expansion is complete, and null if normal processing should
11605 resolve_overloaded_builtin (location_t loc
, tree function
,
11606 vec
<tree
, va_gc
> *params
)
11608 enum built_in_function orig_code
= DECL_FUNCTION_CODE (function
);
11610 /* Is function one of the _FETCH_OP_ or _OP_FETCH_ built-ins?
11611 Those are not valid to call with a pointer to _Bool (or C++ bool)
11612 and so must be rejected. */
11613 bool fetch_op
= true;
11614 bool orig_format
= true;
11615 tree new_return
= NULL_TREE
;
11617 switch (DECL_BUILT_IN_CLASS (function
))
11619 case BUILT_IN_NORMAL
:
11622 if (targetm
.resolve_overloaded_builtin
)
11623 return targetm
.resolve_overloaded_builtin (loc
, function
, params
);
11630 /* Handle BUILT_IN_NORMAL here. */
11633 case BUILT_IN_ATOMIC_EXCHANGE
:
11634 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
11635 case BUILT_IN_ATOMIC_LOAD
:
11636 case BUILT_IN_ATOMIC_STORE
:
11638 /* Handle these 4 together so that they can fall through to the next
11639 case if the call is transformed to an _N variant. */
11642 case BUILT_IN_ATOMIC_EXCHANGE
:
11644 if (resolve_overloaded_atomic_exchange (loc
, function
, params
,
11647 /* Change to the _N variant. */
11648 orig_code
= BUILT_IN_ATOMIC_EXCHANGE_N
;
11652 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
11654 if (resolve_overloaded_atomic_compare_exchange (loc
, function
,
11658 /* Change to the _N variant. */
11659 orig_code
= BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
;
11662 case BUILT_IN_ATOMIC_LOAD
:
11664 if (resolve_overloaded_atomic_load (loc
, function
, params
,
11667 /* Change to the _N variant. */
11668 orig_code
= BUILT_IN_ATOMIC_LOAD_N
;
11671 case BUILT_IN_ATOMIC_STORE
:
11673 if (resolve_overloaded_atomic_store (loc
, function
, params
,
11676 /* Change to the _N variant. */
11677 orig_code
= BUILT_IN_ATOMIC_STORE_N
;
11681 gcc_unreachable ();
11685 case BUILT_IN_ATOMIC_EXCHANGE_N
:
11686 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
:
11687 case BUILT_IN_ATOMIC_LOAD_N
:
11688 case BUILT_IN_ATOMIC_STORE_N
:
11691 case BUILT_IN_ATOMIC_ADD_FETCH_N
:
11692 case BUILT_IN_ATOMIC_SUB_FETCH_N
:
11693 case BUILT_IN_ATOMIC_AND_FETCH_N
:
11694 case BUILT_IN_ATOMIC_NAND_FETCH_N
:
11695 case BUILT_IN_ATOMIC_XOR_FETCH_N
:
11696 case BUILT_IN_ATOMIC_OR_FETCH_N
:
11697 case BUILT_IN_ATOMIC_FETCH_ADD_N
:
11698 case BUILT_IN_ATOMIC_FETCH_SUB_N
:
11699 case BUILT_IN_ATOMIC_FETCH_AND_N
:
11700 case BUILT_IN_ATOMIC_FETCH_NAND_N
:
11701 case BUILT_IN_ATOMIC_FETCH_XOR_N
:
11702 case BUILT_IN_ATOMIC_FETCH_OR_N
:
11703 orig_format
= false;
11705 case BUILT_IN_SYNC_FETCH_AND_ADD_N
:
11706 case BUILT_IN_SYNC_FETCH_AND_SUB_N
:
11707 case BUILT_IN_SYNC_FETCH_AND_OR_N
:
11708 case BUILT_IN_SYNC_FETCH_AND_AND_N
:
11709 case BUILT_IN_SYNC_FETCH_AND_XOR_N
:
11710 case BUILT_IN_SYNC_FETCH_AND_NAND_N
:
11711 case BUILT_IN_SYNC_ADD_AND_FETCH_N
:
11712 case BUILT_IN_SYNC_SUB_AND_FETCH_N
:
11713 case BUILT_IN_SYNC_OR_AND_FETCH_N
:
11714 case BUILT_IN_SYNC_AND_AND_FETCH_N
:
11715 case BUILT_IN_SYNC_XOR_AND_FETCH_N
:
11716 case BUILT_IN_SYNC_NAND_AND_FETCH_N
:
11717 case BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
:
11718 case BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N
:
11719 case BUILT_IN_SYNC_LOCK_TEST_AND_SET_N
:
11720 case BUILT_IN_SYNC_LOCK_RELEASE_N
:
11722 /* The following are not _FETCH_OPs and must be accepted with
11723 pointers to _Bool (or C++ bool). */
11726 (orig_code
!= BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
11727 && orig_code
!= BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N
11728 && orig_code
!= BUILT_IN_SYNC_LOCK_TEST_AND_SET_N
11729 && orig_code
!= BUILT_IN_SYNC_LOCK_RELEASE_N
);
11731 int n
= sync_resolve_size (function
, params
, fetch_op
);
11732 tree new_function
, first_param
, result
;
11733 enum built_in_function fncode
;
11736 return error_mark_node
;
11738 fncode
= (enum built_in_function
)((int)orig_code
+ exact_log2 (n
) + 1);
11739 new_function
= builtin_decl_explicit (fncode
);
11740 if (!sync_resolve_params (loc
, function
, new_function
, params
,
11742 return error_mark_node
;
11744 first_param
= (*params
)[0];
11745 result
= build_function_call_vec (loc
, vNULL
, new_function
, params
,
11747 if (result
== error_mark_node
)
11749 if (orig_code
!= BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
11750 && orig_code
!= BUILT_IN_SYNC_LOCK_RELEASE_N
11751 && orig_code
!= BUILT_IN_ATOMIC_STORE_N
11752 && orig_code
!= BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
)
11753 result
= sync_resolve_return (first_param
, result
, orig_format
);
11756 /* Prevent -Wunused-value warning. */
11757 TREE_USED (result
) = true;
11759 /* If new_return is set, assign function to that expr and cast the
11760 result to void since the generic interface returned void. */
11763 /* Cast function result from I{1,2,4,8,16} to the required type. */
11764 result
= build1 (VIEW_CONVERT_EXPR
, TREE_TYPE (new_return
), result
);
11765 result
= build2 (MODIFY_EXPR
, TREE_TYPE (new_return
), new_return
,
11767 TREE_SIDE_EFFECTS (result
) = 1;
11768 protected_set_expr_location (result
, loc
);
11769 result
= convert (void_type_node
, result
);
11779 /* vector_types_compatible_elements_p is used in type checks of vectors
11780 values used as operands of binary operators. Where it returns true, and
11781 the other checks of the caller succeed (being vector types in he first
11782 place, and matching number of elements), we can just treat the types
11783 as essentially the same.
11784 Contrast with vector_targets_convertible_p, which is used for vector
11785 pointer types, and vector_types_convertible_p, which will allow
11786 language-specific matches under the control of flag_lax_vector_conversions,
11787 and might still require a conversion. */
11788 /* True if vector types T1 and T2 can be inputs to the same binary
11789 operator without conversion.
11790 We don't check the overall vector size here because some of our callers
11791 want to give different error messages when the vectors are compatible
11792 except for the element count. */
11795 vector_types_compatible_elements_p (tree t1
, tree t2
)
11797 bool opaque
= TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
);
11798 t1
= TREE_TYPE (t1
);
11799 t2
= TREE_TYPE (t2
);
11801 enum tree_code c1
= TREE_CODE (t1
), c2
= TREE_CODE (t2
);
11803 gcc_assert ((c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
|| c1
== FIXED_POINT_TYPE
)
11804 && (c2
== INTEGER_TYPE
|| c2
== REAL_TYPE
11805 || c2
== FIXED_POINT_TYPE
));
11807 t1
= c_common_signed_type (t1
);
11808 t2
= c_common_signed_type (t2
);
11809 /* Equality works here because c_common_signed_type uses
11810 TYPE_MAIN_VARIANT. */
11813 if (opaque
&& c1
== c2
11814 && (c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
)
11815 && TYPE_PRECISION (t1
) == TYPE_PRECISION (t2
))
11820 /* Check for missing format attributes on function pointers. LTYPE is
11821 the new type or left-hand side type. RTYPE is the old type or
11822 right-hand side type. Returns TRUE if LTYPE is missing the desired
11826 check_missing_format_attribute (tree ltype
, tree rtype
)
11828 tree
const ttr
= TREE_TYPE (rtype
), ttl
= TREE_TYPE (ltype
);
11831 for (ra
= TYPE_ATTRIBUTES (ttr
); ra
; ra
= TREE_CHAIN (ra
))
11832 if (is_attribute_p ("format", TREE_PURPOSE (ra
)))
11837 for (la
= TYPE_ATTRIBUTES (ttl
); la
; la
= TREE_CHAIN (la
))
11838 if (is_attribute_p ("format", TREE_PURPOSE (la
)))
11846 /* Subscripting with type char is likely to lose on a machine where
11847 chars are signed. So warn on any machine, but optionally. Don't
11848 warn for unsigned char since that type is safe. Don't warn for
11849 signed char because anyone who uses that must have done so
11850 deliberately. Furthermore, we reduce the false positive load by
11851 warning only for non-constant value of type char. */
11854 warn_array_subscript_with_type_char (location_t loc
, tree index
)
11856 if (TYPE_MAIN_VARIANT (TREE_TYPE (index
)) == char_type_node
11857 && TREE_CODE (index
) != INTEGER_CST
)
11858 warning_at (loc
, OPT_Wchar_subscripts
,
11859 "array subscript has type %<char%>");
11862 /* Implement -Wparentheses for the unexpected C precedence rules, to
11863 cover cases like x + y << z which readers are likely to
11864 misinterpret. We have seen an expression in which CODE is a binary
11865 operator used to combine expressions ARG_LEFT and ARG_RIGHT, which
11866 before folding had CODE_LEFT and CODE_RIGHT. CODE_LEFT and
11867 CODE_RIGHT may be ERROR_MARK, which means that that side of the
11868 expression was not formed using a binary or unary operator, or it
11869 was enclosed in parentheses. */
11872 warn_about_parentheses (location_t loc
, enum tree_code code
,
11873 enum tree_code code_left
, tree arg_left
,
11874 enum tree_code code_right
, tree arg_right
)
11876 if (!warn_parentheses
)
11879 /* This macro tests that the expression ARG with original tree code
11880 CODE appears to be a boolean expression. or the result of folding a
11881 boolean expression. */
11882 #define APPEARS_TO_BE_BOOLEAN_EXPR_P(CODE, ARG) \
11883 (truth_value_p (TREE_CODE (ARG)) \
11884 || TREE_CODE (TREE_TYPE (ARG)) == BOOLEAN_TYPE \
11885 /* Folding may create 0 or 1 integers from other expressions. */ \
11886 || ((CODE) != INTEGER_CST \
11887 && (integer_onep (ARG) || integer_zerop (ARG))))
11892 if (code_left
== PLUS_EXPR
)
11893 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11894 "suggest parentheses around %<+%> inside %<<<%>");
11895 else if (code_right
== PLUS_EXPR
)
11896 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11897 "suggest parentheses around %<+%> inside %<<<%>");
11898 else if (code_left
== MINUS_EXPR
)
11899 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11900 "suggest parentheses around %<-%> inside %<<<%>");
11901 else if (code_right
== MINUS_EXPR
)
11902 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11903 "suggest parentheses around %<-%> inside %<<<%>");
11907 if (code_left
== PLUS_EXPR
)
11908 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11909 "suggest parentheses around %<+%> inside %<>>%>");
11910 else if (code_right
== PLUS_EXPR
)
11911 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11912 "suggest parentheses around %<+%> inside %<>>%>");
11913 else if (code_left
== MINUS_EXPR
)
11914 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11915 "suggest parentheses around %<-%> inside %<>>%>");
11916 else if (code_right
== MINUS_EXPR
)
11917 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11918 "suggest parentheses around %<-%> inside %<>>%>");
11921 case TRUTH_ORIF_EXPR
:
11922 if (code_left
== TRUTH_ANDIF_EXPR
)
11923 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11924 "suggest parentheses around %<&&%> within %<||%>");
11925 else if (code_right
== TRUTH_ANDIF_EXPR
)
11926 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11927 "suggest parentheses around %<&&%> within %<||%>");
11931 if (code_left
== BIT_AND_EXPR
|| code_left
== BIT_XOR_EXPR
11932 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
)
11933 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11934 "suggest parentheses around arithmetic in operand of %<|%>");
11935 else if (code_right
== BIT_AND_EXPR
|| code_right
== BIT_XOR_EXPR
11936 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
11937 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11938 "suggest parentheses around arithmetic in operand of %<|%>");
11939 /* Check cases like x|y==z */
11940 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11941 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11942 "suggest parentheses around comparison in operand of %<|%>");
11943 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11944 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11945 "suggest parentheses around comparison in operand of %<|%>");
11946 /* Check cases like !x | y */
11947 else if (code_left
== TRUTH_NOT_EXPR
11948 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
11949 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11950 "suggest parentheses around operand of "
11951 "%<!%> or change %<|%> to %<||%> or %<!%> to %<~%>");
11955 if (code_left
== BIT_AND_EXPR
11956 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
)
11957 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11958 "suggest parentheses around arithmetic in operand of %<^%>");
11959 else if (code_right
== BIT_AND_EXPR
11960 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
11961 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11962 "suggest parentheses around arithmetic in operand of %<^%>");
11963 /* Check cases like x^y==z */
11964 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11965 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11966 "suggest parentheses around comparison in operand of %<^%>");
11967 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11968 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11969 "suggest parentheses around comparison in operand of %<^%>");
11973 if (code_left
== PLUS_EXPR
)
11974 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11975 "suggest parentheses around %<+%> in operand of %<&%>");
11976 else if (code_right
== PLUS_EXPR
)
11977 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11978 "suggest parentheses around %<+%> in operand of %<&%>");
11979 else if (code_left
== MINUS_EXPR
)
11980 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11981 "suggest parentheses around %<-%> in operand of %<&%>");
11982 else if (code_right
== MINUS_EXPR
)
11983 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11984 "suggest parentheses around %<-%> in operand of %<&%>");
11985 /* Check cases like x&y==z */
11986 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11987 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11988 "suggest parentheses around comparison in operand of %<&%>");
11989 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11990 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11991 "suggest parentheses around comparison in operand of %<&%>");
11992 /* Check cases like !x & y */
11993 else if (code_left
== TRUTH_NOT_EXPR
11994 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
11995 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11996 "suggest parentheses around operand of "
11997 "%<!%> or change %<&%> to %<&&%> or %<!%> to %<~%>");
12001 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
12002 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
12003 "suggest parentheses around comparison in operand of %<==%>");
12004 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
12005 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
12006 "suggest parentheses around comparison in operand of %<==%>");
12009 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
12010 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
12011 "suggest parentheses around comparison in operand of %<!=%>");
12012 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
12013 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
12014 "suggest parentheses around comparison in operand of %<!=%>");
12018 if (TREE_CODE_CLASS (code
) == tcc_comparison
)
12020 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
12021 && code_left
!= NE_EXPR
&& code_left
!= EQ_EXPR
12022 && INTEGRAL_TYPE_P (TREE_TYPE (arg_left
)))
12023 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
12024 "comparisons like %<X<=Y<=Z%> do not "
12025 "have their mathematical meaning");
12026 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
12027 && code_right
!= NE_EXPR
&& code_right
!= EQ_EXPR
12028 && INTEGRAL_TYPE_P (TREE_TYPE (arg_right
)))
12029 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
12030 "comparisons like %<X<=Y<=Z%> do not "
12031 "have their mathematical meaning");
12035 #undef NOT_A_BOOLEAN_EXPR_P
12038 /* If LABEL (a LABEL_DECL) has not been used, issue a warning. */
12041 warn_for_unused_label (tree label
)
12043 if (!TREE_USED (label
))
12045 if (DECL_INITIAL (label
))
12046 warning (OPT_Wunused_label
, "label %q+D defined but not used", label
);
12048 warning (OPT_Wunused_label
, "label %q+D declared but not defined", label
);
12052 /* Warn for division by zero according to the value of DIVISOR. LOC
12053 is the location of the division operator. */
12056 warn_for_div_by_zero (location_t loc
, tree divisor
)
12058 /* If DIVISOR is zero, and has integral or fixed-point type, issue a warning
12059 about division by zero. Do not issue a warning if DIVISOR has a
12060 floating-point type, since we consider 0.0/0.0 a valid way of
12061 generating a NaN. */
12062 if (c_inhibit_evaluation_warnings
== 0
12063 && (integer_zerop (divisor
) || fixed_zerop (divisor
)))
12064 warning_at (loc
, OPT_Wdiv_by_zero
, "division by zero");
12067 /* Warn for patterns where memset appears to be used incorrectly. The
12068 warning location should be LOC. ARG0, and ARG2 are the first and
12069 last arguments to the call, while LITERAL_ZERO_MASK has a 1 bit for
12070 each argument that was a literal zero. */
12073 warn_for_memset (location_t loc
, tree arg0
, tree arg2
,
12074 int literal_zero_mask
)
12076 if (warn_memset_transposed_args
12077 && integer_zerop (arg2
)
12078 && (literal_zero_mask
& (1 << 2)) != 0
12079 && (literal_zero_mask
& (1 << 1)) == 0)
12080 warning_at (loc
, OPT_Wmemset_transposed_args
,
12081 "%<memset%> used with constant zero length "
12082 "parameter; this could be due to transposed "
12085 if (warn_memset_elt_size
&& TREE_CODE (arg2
) == INTEGER_CST
)
12088 if (TREE_CODE (arg0
) == ADDR_EXPR
)
12089 arg0
= TREE_OPERAND (arg0
, 0);
12090 tree type
= TREE_TYPE (arg0
);
12091 if (type
!= NULL_TREE
&& TREE_CODE (type
) == ARRAY_TYPE
)
12093 tree elt_type
= TREE_TYPE (type
);
12094 tree domain
= TYPE_DOMAIN (type
);
12095 if (!integer_onep (TYPE_SIZE_UNIT (elt_type
))
12096 && domain
!= NULL_TREE
12097 && TYPE_MAXVAL (domain
)
12098 && TYPE_MINVAL (domain
)
12099 && integer_zerop (TYPE_MINVAL (domain
))
12100 && integer_onep (fold_build2 (MINUS_EXPR
, domain
,
12102 TYPE_MAXVAL (domain
))))
12103 warning_at (loc
, OPT_Wmemset_elt_size
,
12104 "%<memset%> used with length equal to "
12105 "number of elements without multiplication "
12106 "by element size");
12111 /* Subroutine of build_binary_op. Give warnings for comparisons
12112 between signed and unsigned quantities that may fail. Do the
12113 checking based on the original operand trees ORIG_OP0 and ORIG_OP1,
12114 so that casts will be considered, but default promotions won't
12117 LOCATION is the location of the comparison operator.
12119 The arguments of this function map directly to local variables
12120 of build_binary_op. */
12123 warn_for_sign_compare (location_t location
,
12124 tree orig_op0
, tree orig_op1
,
12125 tree op0
, tree op1
,
12126 tree result_type
, enum tree_code resultcode
)
12128 int op0_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op0
));
12129 int op1_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op1
));
12130 int unsignedp0
, unsignedp1
;
12132 /* In C++, check for comparison of different enum types. */
12133 if (c_dialect_cxx()
12134 && TREE_CODE (TREE_TYPE (orig_op0
)) == ENUMERAL_TYPE
12135 && TREE_CODE (TREE_TYPE (orig_op1
)) == ENUMERAL_TYPE
12136 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0
))
12137 != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1
)))
12139 warning_at (location
,
12140 OPT_Wsign_compare
, "comparison between types %qT and %qT",
12141 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
));
12144 /* Do not warn if the comparison is being done in a signed type,
12145 since the signed type will only be chosen if it can represent
12146 all the values of the unsigned type. */
12147 if (!TYPE_UNSIGNED (result_type
))
12149 /* Do not warn if both operands are unsigned. */
12150 else if (op0_signed
== op1_signed
)
12154 tree sop
, uop
, base_type
;
12158 sop
= orig_op0
, uop
= orig_op1
;
12160 sop
= orig_op1
, uop
= orig_op0
;
12162 STRIP_TYPE_NOPS (sop
);
12163 STRIP_TYPE_NOPS (uop
);
12164 base_type
= (TREE_CODE (result_type
) == COMPLEX_TYPE
12165 ? TREE_TYPE (result_type
) : result_type
);
12167 /* Do not warn if the signed quantity is an unsuffixed integer
12168 literal (or some static constant expression involving such
12169 literals or a conditional expression involving such literals)
12170 and it is non-negative. */
12171 if (tree_expr_nonnegative_warnv_p (sop
, &ovf
))
12173 /* Do not warn if the comparison is an equality operation, the
12174 unsigned quantity is an integral constant, and it would fit
12175 in the result if the result were signed. */
12176 else if (TREE_CODE (uop
) == INTEGER_CST
12177 && (resultcode
== EQ_EXPR
|| resultcode
== NE_EXPR
)
12178 && int_fits_type_p (uop
, c_common_signed_type (base_type
)))
12180 /* In C, do not warn if the unsigned quantity is an enumeration
12181 constant and its maximum value would fit in the result if the
12182 result were signed. */
12183 else if (!c_dialect_cxx() && TREE_CODE (uop
) == INTEGER_CST
12184 && TREE_CODE (TREE_TYPE (uop
)) == ENUMERAL_TYPE
12185 && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (uop
)),
12186 c_common_signed_type (base_type
)))
12189 warning_at (location
,
12191 "comparison between signed and unsigned integer expressions");
12194 /* Warn if two unsigned values are being compared in a size larger
12195 than their original size, and one (and only one) is the result of
12196 a `~' operator. This comparison will always fail.
12198 Also warn if one operand is a constant, and the constant does not
12199 have all bits set that are set in the ~ operand when it is
12202 op0
= c_common_get_narrower (op0
, &unsignedp0
);
12203 op1
= c_common_get_narrower (op1
, &unsignedp1
);
12205 if ((TREE_CODE (op0
) == BIT_NOT_EXPR
)
12206 ^ (TREE_CODE (op1
) == BIT_NOT_EXPR
))
12208 if (TREE_CODE (op0
) == BIT_NOT_EXPR
)
12209 op0
= c_common_get_narrower (TREE_OPERAND (op0
, 0), &unsignedp0
);
12210 if (TREE_CODE (op1
) == BIT_NOT_EXPR
)
12211 op1
= c_common_get_narrower (TREE_OPERAND (op1
, 0), &unsignedp1
);
12213 if (tree_fits_shwi_p (op0
) || tree_fits_shwi_p (op1
))
12216 HOST_WIDE_INT constant
, mask
;
12220 if (tree_fits_shwi_p (op0
))
12223 unsignedp
= unsignedp1
;
12224 constant
= tree_to_shwi (op0
);
12229 unsignedp
= unsignedp0
;
12230 constant
= tree_to_shwi (op1
);
12233 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
12234 if (bits
< TYPE_PRECISION (result_type
)
12235 && bits
< HOST_BITS_PER_LONG
&& unsignedp
)
12237 mask
= HOST_WIDE_INT_M1U
<< bits
;
12238 if ((mask
& constant
) != mask
)
12241 warning_at (location
, OPT_Wsign_compare
,
12242 "promoted ~unsigned is always non-zero");
12244 warning_at (location
, OPT_Wsign_compare
,
12245 "comparison of promoted ~unsigned with constant");
12249 else if (unsignedp0
&& unsignedp1
12250 && (TYPE_PRECISION (TREE_TYPE (op0
))
12251 < TYPE_PRECISION (result_type
))
12252 && (TYPE_PRECISION (TREE_TYPE (op1
))
12253 < TYPE_PRECISION (result_type
)))
12254 warning_at (location
, OPT_Wsign_compare
,
12255 "comparison of promoted ~unsigned with unsigned");
12259 /* RESULT_TYPE is the result of converting TYPE1 and TYPE2 to a common
12260 type via c_common_type. If -Wdouble-promotion is in use, and the
12261 conditions for warning have been met, issue a warning. GMSGID is
12262 the warning message. It must have two %T specifiers for the type
12263 that was converted (generally "float") and the type to which it was
12264 converted (generally "double), respectively. LOC is the location
12265 to which the awrning should refer. */
12268 do_warn_double_promotion (tree result_type
, tree type1
, tree type2
,
12269 const char *gmsgid
, location_t loc
)
12273 if (!warn_double_promotion
)
12275 /* If the conversion will not occur at run-time, there is no need to
12277 if (c_inhibit_evaluation_warnings
)
12279 if (TYPE_MAIN_VARIANT (result_type
) != double_type_node
12280 && TYPE_MAIN_VARIANT (result_type
) != complex_double_type_node
)
12282 if (TYPE_MAIN_VARIANT (type1
) == float_type_node
12283 || TYPE_MAIN_VARIANT (type1
) == complex_float_type_node
)
12284 source_type
= type1
;
12285 else if (TYPE_MAIN_VARIANT (type2
) == float_type_node
12286 || TYPE_MAIN_VARIANT (type2
) == complex_float_type_node
)
12287 source_type
= type2
;
12290 warning_at (loc
, OPT_Wdouble_promotion
, gmsgid
, source_type
, result_type
);
12293 /* Possibly warn about unused parameters. */
12296 do_warn_unused_parameter (tree fn
)
12300 for (decl
= DECL_ARGUMENTS (fn
);
12301 decl
; decl
= DECL_CHAIN (decl
))
12302 if (!TREE_USED (decl
) && TREE_CODE (decl
) == PARM_DECL
12303 && DECL_NAME (decl
) && !DECL_ARTIFICIAL (decl
)
12304 && !TREE_NO_WARNING (decl
))
12305 warning_at (DECL_SOURCE_LOCATION (decl
), OPT_Wunused_parameter
,
12306 "unused parameter %qD", decl
);
12310 /* Setup a TYPE_DECL node as a typedef representation.
12312 X is a TYPE_DECL for a typedef statement. Create a brand new
12313 ..._TYPE node (which will be just a variant of the existing
12314 ..._TYPE node with identical properties) and then install X
12315 as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
12317 The whole point here is to end up with a situation where each
12318 and every ..._TYPE node the compiler creates will be uniquely
12319 associated with AT MOST one node representing a typedef name.
12320 This way, even though the compiler substitutes corresponding
12321 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
12322 early on, later parts of the compiler can always do the reverse
12323 translation and get back the corresponding typedef name. For
12326 typedef struct S MY_TYPE;
12329 Later parts of the compiler might only know that `object' was of
12330 type `struct S' if it were not for code just below. With this
12331 code however, later parts of the compiler see something like:
12333 struct S' == struct S
12334 typedef struct S' MY_TYPE;
12337 And they can then deduce (from the node for type struct S') that
12338 the original object declaration was:
12342 Being able to do this is important for proper support of protoize,
12343 and also for generating precise symbolic debugging information
12344 which takes full account of the programmer's (typedef) vocabulary.
12346 Obviously, we don't want to generate a duplicate ..._TYPE node if
12347 the TYPE_DECL node that we are now processing really represents a
12348 standard built-in type. */
12351 set_underlying_type (tree x
)
12353 if (x
== error_mark_node
)
12355 if (DECL_IS_BUILTIN (x
) && TREE_CODE (TREE_TYPE (x
)) != ARRAY_TYPE
)
12357 if (TYPE_NAME (TREE_TYPE (x
)) == 0)
12358 TYPE_NAME (TREE_TYPE (x
)) = x
;
12360 else if (TREE_TYPE (x
) != error_mark_node
12361 && DECL_ORIGINAL_TYPE (x
) == NULL_TREE
)
12363 tree tt
= TREE_TYPE (x
);
12364 DECL_ORIGINAL_TYPE (x
) = tt
;
12365 tt
= build_variant_type_copy (tt
);
12366 TYPE_STUB_DECL (tt
) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x
));
12367 TYPE_NAME (tt
) = x
;
12368 TREE_USED (tt
) = TREE_USED (x
);
12369 TREE_TYPE (x
) = tt
;
12373 /* Record the types used by the current global variable declaration
12374 being parsed, so that we can decide later to emit their debug info.
12375 Those types are in types_used_by_cur_var_decl, and we are going to
12376 store them in the types_used_by_vars_hash hash table.
12377 DECL is the declaration of the global variable that has been parsed. */
12380 record_types_used_by_current_var_decl (tree decl
)
12382 gcc_assert (decl
&& DECL_P (decl
) && TREE_STATIC (decl
));
12384 while (types_used_by_cur_var_decl
&& !types_used_by_cur_var_decl
->is_empty ())
12386 tree type
= types_used_by_cur_var_decl
->pop ();
12387 types_used_by_var_decl_insert (type
, decl
);
12391 /* If DECL is a typedef that is declared in the current function,
12392 record it for the purpose of -Wunused-local-typedefs. */
12395 record_locally_defined_typedef (tree decl
)
12397 struct c_language_function
*l
;
12399 if (!warn_unused_local_typedefs
12401 /* if this is not a locally defined typedef then we are not
12403 || !is_typedef_decl (decl
)
12404 || !decl_function_context (decl
))
12407 l
= (struct c_language_function
*) cfun
->language
;
12408 vec_safe_push (l
->local_typedefs
, decl
);
12411 /* If T is a TYPE_DECL declared locally, mark it as used. */
12414 maybe_record_typedef_use (tree t
)
12416 if (!is_typedef_decl (t
))
12419 TREE_USED (t
) = true;
12422 /* Warn if there are some unused locally defined typedefs in the
12423 current function. */
12426 maybe_warn_unused_local_typedefs (void)
12430 /* The number of times we have emitted -Wunused-local-typedefs
12431 warnings. If this is different from errorcount, that means some
12432 unrelated errors have been issued. In which case, we'll avoid
12433 emitting "unused-local-typedefs" warnings. */
12434 static int unused_local_typedefs_warn_count
;
12435 struct c_language_function
*l
;
12440 if ((l
= (struct c_language_function
*) cfun
->language
) == NULL
)
12443 if (warn_unused_local_typedefs
12444 && errorcount
== unused_local_typedefs_warn_count
)
12446 FOR_EACH_VEC_SAFE_ELT (l
->local_typedefs
, i
, decl
)
12447 if (!TREE_USED (decl
))
12448 warning_at (DECL_SOURCE_LOCATION (decl
),
12449 OPT_Wunused_local_typedefs
,
12450 "typedef %qD locally defined but not used", decl
);
12451 unused_local_typedefs_warn_count
= errorcount
;
12454 vec_free (l
->local_typedefs
);
12457 /* Warn about boolean expression compared with an integer value different
12458 from true/false. Warns also e.g. about "(i1 == i2) == 2".
12459 LOC is the location of the comparison, CODE is its code, OP0 and OP1
12460 are the operands of the comparison. The caller must ensure that
12461 either operand is a boolean expression. */
12464 maybe_warn_bool_compare (location_t loc
, enum tree_code code
, tree op0
,
12467 if (TREE_CODE_CLASS (code
) != tcc_comparison
)
12471 if (f
= fold_for_warn (op0
),
12472 TREE_CODE (f
) == INTEGER_CST
)
12474 else if (f
= fold_for_warn (op1
),
12475 TREE_CODE (f
) == INTEGER_CST
)
12480 if (!integer_zerop (cst
) && !integer_onep (cst
))
12482 int sign
= (TREE_CODE (op0
) == INTEGER_CST
12483 ? tree_int_cst_sgn (cst
) : -tree_int_cst_sgn (cst
));
12484 if (code
== EQ_EXPR
12485 || ((code
== GT_EXPR
|| code
== GE_EXPR
) && sign
< 0)
12486 || ((code
== LT_EXPR
|| code
== LE_EXPR
) && sign
> 0))
12487 warning_at (loc
, OPT_Wbool_compare
, "comparison of constant %qE "
12488 "with boolean expression is always false", cst
);
12490 warning_at (loc
, OPT_Wbool_compare
, "comparison of constant %qE "
12491 "with boolean expression is always true", cst
);
12493 else if (integer_zerop (cst
) || integer_onep (cst
))
12495 /* If the non-constant operand isn't of a boolean type, we
12496 don't want to warn here. */
12497 tree noncst
= TREE_CODE (op0
) == INTEGER_CST
? op1
: op0
;
12498 /* Handle booleans promoted to integers. */
12499 if (bool_promoted_to_int_p (noncst
))
12501 else if (TREE_CODE (TREE_TYPE (noncst
)) != BOOLEAN_TYPE
12502 && !truth_value_p (TREE_CODE (noncst
)))
12504 /* Do some magic to get the right diagnostics. */
12505 bool flag
= TREE_CODE (op0
) == INTEGER_CST
;
12506 flag
= integer_zerop (cst
) ? flag
: !flag
;
12507 if ((code
== GE_EXPR
&& !flag
) || (code
== LE_EXPR
&& flag
))
12508 warning_at (loc
, OPT_Wbool_compare
, "comparison of constant %qE "
12509 "with boolean expression is always true", cst
);
12510 else if ((code
== LT_EXPR
&& !flag
) || (code
== GT_EXPR
&& flag
))
12511 warning_at (loc
, OPT_Wbool_compare
, "comparison of constant %qE "
12512 "with boolean expression is always false", cst
);
12516 /* Warn if signed left shift overflows. We don't warn
12517 about left-shifting 1 into the sign bit in C++14; cf.
12518 <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3367.html#1457>
12519 LOC is a location of the shift; OP0 and OP1 are the operands.
12520 Return true if an overflow is detected, false otherwise. */
12523 maybe_warn_shift_overflow (location_t loc
, tree op0
, tree op1
)
12525 if (TREE_CODE (op0
) != INTEGER_CST
12526 || TREE_CODE (op1
) != INTEGER_CST
)
12529 tree type0
= TREE_TYPE (op0
);
12530 unsigned int prec0
= TYPE_PRECISION (type0
);
12532 /* Left-hand operand must be signed. */
12533 if (TYPE_UNSIGNED (type0
))
12536 unsigned int min_prec
= (wi::min_precision (op0
, SIGNED
)
12537 + TREE_INT_CST_LOW (op1
));
12538 /* Handle the case of left-shifting 1 into the sign bit.
12539 * However, shifting 1 _out_ of the sign bit, as in
12540 * INT_MIN << 1, is considered an overflow.
12542 if (!tree_int_cst_sign_bit(op0
) && min_prec
== prec0
+ 1)
12544 /* Never warn for C++14 onwards. */
12545 if (cxx_dialect
>= cxx14
)
12547 /* Otherwise only if -Wshift-overflow=2. But return
12548 true to signal an overflow for the sake of integer
12549 constant expressions. */
12550 if (warn_shift_overflow
< 2)
12554 bool overflowed
= min_prec
> prec0
;
12555 if (overflowed
&& c_inhibit_evaluation_warnings
== 0)
12556 warning_at (loc
, OPT_Wshift_overflow_
,
12557 "result of %qE requires %u bits to represent, "
12558 "but %qT only has %u bits",
12559 build2_loc (loc
, LSHIFT_EXPR
, type0
, op0
, op1
),
12560 min_prec
, type0
, prec0
);
12565 /* The C and C++ parsers both use vectors to hold function arguments.
12566 For efficiency, we keep a cache of unused vectors. This is the
12569 typedef vec
<tree
, va_gc
> *tree_gc_vec
;
12570 static GTY((deletable
)) vec
<tree_gc_vec
, va_gc
> *tree_vector_cache
;
12572 /* Return a new vector from the cache. If the cache is empty,
12573 allocate a new vector. These vectors are GC'ed, so it is OK if the
12574 pointer is not released.. */
12577 make_tree_vector (void)
12579 if (tree_vector_cache
&& !tree_vector_cache
->is_empty ())
12580 return tree_vector_cache
->pop ();
12583 /* Passing 0 to vec::alloc returns NULL, and our callers require
12584 that we always return a non-NULL value. The vector code uses
12585 4 when growing a NULL vector, so we do too. */
12586 vec
<tree
, va_gc
> *v
;
12592 /* Release a vector of trees back to the cache. */
12595 release_tree_vector (vec
<tree
, va_gc
> *vec
)
12600 vec_safe_push (tree_vector_cache
, vec
);
12604 /* Get a new tree vector holding a single tree. */
12607 make_tree_vector_single (tree t
)
12609 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
12610 ret
->quick_push (t
);
12614 /* Get a new tree vector of the TREE_VALUEs of a TREE_LIST chain. */
12617 make_tree_vector_from_list (tree list
)
12619 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
12620 for (; list
; list
= TREE_CHAIN (list
))
12621 vec_safe_push (ret
, TREE_VALUE (list
));
12625 /* Get a new tree vector of the values of a CONSTRUCTOR. */
12628 make_tree_vector_from_ctor (tree ctor
)
12630 vec
<tree
,va_gc
> *ret
= make_tree_vector ();
12631 vec_safe_reserve (ret
, CONSTRUCTOR_NELTS (ctor
));
12632 for (unsigned i
= 0; i
< CONSTRUCTOR_NELTS (ctor
); ++i
)
12633 ret
->quick_push (CONSTRUCTOR_ELT (ctor
, i
)->value
);
12637 /* Get a new tree vector which is a copy of an existing one. */
12640 make_tree_vector_copy (const vec
<tree
, va_gc
> *orig
)
12642 vec
<tree
, va_gc
> *ret
;
12646 ret
= make_tree_vector ();
12647 vec_safe_reserve (ret
, vec_safe_length (orig
));
12648 FOR_EACH_VEC_SAFE_ELT (orig
, ix
, t
)
12649 ret
->quick_push (t
);
12653 /* Return true if KEYWORD starts a type specifier. */
12656 keyword_begins_type_specifier (enum rid keyword
)
12660 case RID_AUTO_TYPE
:
12670 CASE_RID_FLOATN_NX
:
12673 case RID_DFLOAT128
:
12689 if (keyword
>= RID_FIRST_INT_N
12690 && keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
12691 && int_n_enabled_p
[keyword
-RID_FIRST_INT_N
])
12697 /* Return true if KEYWORD names a type qualifier. */
12700 keyword_is_type_qualifier (enum rid keyword
)
12714 /* Return true if KEYWORD names a storage class specifier.
12716 RID_TYPEDEF is not included in this list despite `typedef' being
12717 listed in C99 6.7.1.1. 6.7.1.3 indicates that `typedef' is listed as
12718 such for syntactic convenience only. */
12721 keyword_is_storage_class_specifier (enum rid keyword
)
12737 /* Return true if KEYWORD names a function-specifier [dcl.fct.spec]. */
12740 keyword_is_function_specifier (enum rid keyword
)
12754 /* Return true if KEYWORD names a decl-specifier [dcl.spec] or a
12755 declaration-specifier (C99 6.7). */
12758 keyword_is_decl_specifier (enum rid keyword
)
12760 if (keyword_is_storage_class_specifier (keyword
)
12761 || keyword_is_type_qualifier (keyword
)
12762 || keyword_is_function_specifier (keyword
))
12769 case RID_CONSTEXPR
:
12776 /* Initialize language-specific-bits of tree_contains_struct. */
12779 c_common_init_ts (void)
12781 MARK_TS_TYPED (C_MAYBE_CONST_EXPR
);
12782 MARK_TS_TYPED (EXCESS_PRECISION_EXPR
);
12783 MARK_TS_TYPED (ARRAY_NOTATION_REF
);
12786 /* Build a user-defined numeric literal out of an integer constant type VALUE
12787 with identifier SUFFIX. */
12790 build_userdef_literal (tree suffix_id
, tree value
,
12791 enum overflow_type overflow
, tree num_string
)
12793 tree literal
= make_node (USERDEF_LITERAL
);
12794 USERDEF_LITERAL_SUFFIX_ID (literal
) = suffix_id
;
12795 USERDEF_LITERAL_VALUE (literal
) = value
;
12796 USERDEF_LITERAL_OVERFLOW (literal
) = overflow
;
12797 USERDEF_LITERAL_NUM_STRING (literal
) = num_string
;
12801 /* For vector[index], convert the vector to an array of the underlying type.
12802 Return true if the resulting ARRAY_REF should not be an lvalue. */
12805 convert_vector_to_array_for_subscript (location_t loc
,
12806 tree
*vecp
, tree index
)
12809 if (VECTOR_TYPE_P (TREE_TYPE (*vecp
)))
12811 tree type
= TREE_TYPE (*vecp
);
12813 ret
= !lvalue_p (*vecp
);
12815 if (TREE_CODE (index
) == INTEGER_CST
)
12816 if (!tree_fits_uhwi_p (index
)
12817 || tree_to_uhwi (index
) >= TYPE_VECTOR_SUBPARTS (type
))
12818 warning_at (loc
, OPT_Warray_bounds
, "index value is out of bound");
12820 /* We are building an ARRAY_REF so mark the vector as addressable
12821 to not run into the gimplifiers premature setting of DECL_GIMPLE_REG_P
12822 for function parameters. */
12823 c_common_mark_addressable_vec (*vecp
);
12825 *vecp
= build1 (VIEW_CONVERT_EXPR
,
12826 build_array_type_nelts (TREE_TYPE (type
),
12827 TYPE_VECTOR_SUBPARTS (type
)),
12833 /* Determine which of the operands, if any, is a scalar that needs to be
12834 converted to a vector, for the range of operations. */
12836 scalar_to_vector (location_t loc
, enum tree_code code
, tree op0
, tree op1
,
12839 tree type0
= TREE_TYPE (op0
);
12840 tree type1
= TREE_TYPE (op1
);
12841 bool integer_only_op
= false;
12842 enum stv_conv ret
= stv_firstarg
;
12844 gcc_assert (VECTOR_TYPE_P (type0
) || VECTOR_TYPE_P (type1
));
12847 /* Most GENERIC binary expressions require homogeneous arguments.
12848 LSHIFT_EXPR and RSHIFT_EXPR are exceptions and accept a first
12849 argument that is a vector and a second one that is a scalar, so
12850 we never return stv_secondarg for them. */
12853 if (TREE_CODE (type0
) == INTEGER_TYPE
12854 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
12856 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
12859 error_at (loc
, "conversion of scalar %qT to vector %qT "
12860 "involves truncation", type0
, type1
);
12864 return stv_firstarg
;
12871 integer_only_op
= true;
12874 case VEC_COND_EXPR
:
12879 case TRUNC_DIV_EXPR
:
12880 case CEIL_DIV_EXPR
:
12881 case FLOOR_DIV_EXPR
:
12882 case ROUND_DIV_EXPR
:
12883 case EXACT_DIV_EXPR
:
12884 case TRUNC_MOD_EXPR
:
12885 case FLOOR_MOD_EXPR
:
12893 /* What about UNLT_EXPR? */
12894 if (VECTOR_TYPE_P (type0
))
12896 ret
= stv_secondarg
;
12897 std::swap (type0
, type1
);
12898 std::swap (op0
, op1
);
12901 if (TREE_CODE (type0
) == INTEGER_TYPE
12902 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
12904 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
12907 error_at (loc
, "conversion of scalar %qT to vector %qT "
12908 "involves truncation", type0
, type1
);
12913 else if (!integer_only_op
12914 /* Allow integer --> real conversion if safe. */
12915 && (TREE_CODE (type0
) == REAL_TYPE
12916 || TREE_CODE (type0
) == INTEGER_TYPE
)
12917 && SCALAR_FLOAT_TYPE_P (TREE_TYPE (type1
)))
12919 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
12922 error_at (loc
, "conversion of scalar %qT to vector %qT "
12923 "involves truncation", type0
, type1
);
12932 return stv_nothing
;
12935 /* Return the alignment of std::max_align_t.
12937 [support.types.layout] The type max_align_t is a POD type whose alignment
12938 requirement is at least as great as that of every scalar type, and whose
12939 alignment requirement is supported in every context. */
12942 max_align_t_align ()
12944 unsigned int max_align
= MAX (TYPE_ALIGN (long_long_integer_type_node
),
12945 TYPE_ALIGN (long_double_type_node
));
12946 if (float128_type_node
!= NULL_TREE
)
12947 max_align
= MAX (max_align
, TYPE_ALIGN (float128_type_node
));
12951 /* Return true iff ALIGN is an integral constant that is a fundamental
12952 alignment, as defined by [basic.align] in the c++-11
12957 [A fundamental alignment is represented by an alignment less than or
12958 equal to the greatest alignment supported by the implementation
12959 in all contexts, which is equal to alignof(max_align_t)]. */
12962 cxx_fundamental_alignment_p (unsigned align
)
12964 return (align
<= max_align_t_align ());
12967 /* Return true if T is a pointer to a zero-sized aggregate. */
12970 pointer_to_zero_sized_aggr_p (tree t
)
12972 if (!POINTER_TYPE_P (t
))
12975 return (TYPE_SIZE (t
) && integer_zerop (TYPE_SIZE (t
)));
12978 /* For an EXPR of a FUNCTION_TYPE that references a GCC built-in function
12979 with no library fallback or for an ADDR_EXPR whose operand is such type
12980 issues an error pointing to the location LOC.
12981 Returns true when the expression has been diagnosed and false
12984 reject_gcc_builtin (const_tree expr
, location_t loc
/* = UNKNOWN_LOCATION */)
12986 if (TREE_CODE (expr
) == ADDR_EXPR
)
12987 expr
= TREE_OPERAND (expr
, 0);
12989 if (TREE_TYPE (expr
)
12990 && TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
12991 && TREE_CODE (expr
) == FUNCTION_DECL
12992 /* The intersection of DECL_BUILT_IN and DECL_IS_BUILTIN avoids
12993 false positives for user-declared built-ins such as abs or
12994 strlen, and for C++ operators new and delete.
12995 The c_decl_implicit() test avoids false positives for implicitly
12996 declared built-ins with library fallbacks (such as abs). */
12997 && DECL_BUILT_IN (expr
)
12998 && DECL_IS_BUILTIN (expr
)
12999 && !c_decl_implicit (expr
)
13000 && !DECL_ASSEMBLER_NAME_SET_P (expr
))
13002 if (loc
== UNKNOWN_LOCATION
)
13003 loc
= EXPR_LOC_OR_LOC (expr
, input_location
);
13005 /* Reject arguments that are built-in functions with
13006 no library fallback. */
13007 error_at (loc
, "built-in function %qE must be directly called", expr
);
13015 /* If we're creating an if-else-if condition chain, first see if we
13016 already have this COND in the CHAIN. If so, warn and don't add COND
13017 into the vector, otherwise add the COND there. LOC is the location
13021 warn_duplicated_cond_add_or_warn (location_t loc
, tree cond
, vec
<tree
> **chain
)
13023 /* No chain has been created yet. Do nothing. */
13024 if (*chain
== NULL
)
13027 if (TREE_SIDE_EFFECTS (cond
))
13029 /* Uh-oh! This condition has a side-effect, thus invalidates
13030 the whole chain. */
13038 bool found
= false;
13039 FOR_EACH_VEC_ELT (**chain
, ix
, t
)
13040 if (operand_equal_p (cond
, t
, 0))
13042 if (warning_at (loc
, OPT_Wduplicated_cond
,
13043 "duplicated %<if%> condition"))
13044 inform (EXPR_LOCATION (t
), "previously used here");
13050 && !CONSTANT_CLASS_P (cond
)
13051 /* Don't infinitely grow the chain. */
13052 && (*chain
)->length () < 512)
13053 (*chain
)->safe_push (cond
);
13056 /* Check if array size calculations overflow or if the array covers more
13057 than half of the address space. Return true if the size of the array
13058 is valid, false otherwise. TYPE is the type of the array and NAME is
13059 the name of the array, or NULL_TREE for unnamed arrays. */
13062 valid_array_size_p (location_t loc
, tree type
, tree name
)
13064 if (type
!= error_mark_node
13065 && COMPLETE_TYPE_P (type
)
13066 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
13067 && !valid_constant_size_p (TYPE_SIZE_UNIT (type
)))
13070 error_at (loc
, "size of array %qE is too large", name
);
13072 error_at (loc
, "size of unnamed array is too large");
13078 /* Read SOURCE_DATE_EPOCH from environment to have a deterministic
13079 timestamp to replace embedded current dates to get reproducible
13080 results. Returns -1 if SOURCE_DATE_EPOCH is not defined. */
13083 cb_get_source_date_epoch (cpp_reader
*pfile ATTRIBUTE_UNUSED
)
13085 char *source_date_epoch
;
13089 source_date_epoch
= getenv ("SOURCE_DATE_EPOCH");
13090 if (!source_date_epoch
)
13091 return (time_t) -1;
13094 #if defined(INT64_T_IS_LONG)
13095 epoch
= strtol (source_date_epoch
, &endptr
, 10);
13097 epoch
= strtoll (source_date_epoch
, &endptr
, 10);
13099 if (errno
!= 0 || endptr
== source_date_epoch
|| *endptr
!= '\0'
13100 || epoch
< 0 || epoch
> MAX_SOURCE_DATE_EPOCH
)
13102 error_at (input_location
, "environment variable SOURCE_DATE_EPOCH must "
13103 "expand to a non-negative integer less than or equal to %wd",
13104 MAX_SOURCE_DATE_EPOCH
);
13105 return (time_t) -1;
13108 return (time_t) epoch
;
13111 /* Callback for libcpp for offering spelling suggestions for misspelled
13112 directives. GOAL is an unrecognized string; CANDIDATES is a
13113 NULL-terminated array of candidate strings. Return the closest
13114 match to GOAL within CANDIDATES, or NULL if none are good
13118 cb_get_suggestion (cpp_reader
*, const char *goal
,
13119 const char *const *candidates
)
13121 best_match
<const char *, const char *> bm (goal
);
13122 while (*candidates
)
13123 bm
.consider (*candidates
++);
13124 return bm
.get_best_meaningful_candidate ();
13127 /* Check and possibly warn if two declarations have contradictory
13128 attributes, such as always_inline vs. noinline. */
13131 diagnose_mismatched_attributes (tree olddecl
, tree newdecl
)
13133 bool warned
= false;
13135 tree a1
= lookup_attribute ("optimize", DECL_ATTRIBUTES (olddecl
));
13136 tree a2
= lookup_attribute ("optimize", DECL_ATTRIBUTES (newdecl
));
13137 /* An optimization attribute applied on a declaration after the
13138 definition is likely not what the user wanted. */
13139 if (a2
!= NULL_TREE
13140 && DECL_SAVED_TREE (olddecl
) != NULL_TREE
13141 && (a1
== NULL_TREE
|| !attribute_list_equal (a1
, a2
)))
13142 warned
|= warning (OPT_Wattributes
,
13143 "optimization attribute on %qD follows "
13144 "definition but the attribute doesn%'t match",
13147 /* Diagnose inline __attribute__ ((noinline)) which is silly. */
13148 if (DECL_DECLARED_INLINE_P (newdecl
)
13149 && DECL_UNINLINABLE (olddecl
)
13150 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl
)))
13151 warned
|= warning (OPT_Wattributes
, "inline declaration of %qD follows "
13152 "declaration with attribute noinline", newdecl
);
13153 else if (DECL_DECLARED_INLINE_P (olddecl
)
13154 && DECL_UNINLINABLE (newdecl
)
13155 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl
)))
13156 warned
|= warning (OPT_Wattributes
, "declaration of %q+D with attribute "
13157 "noinline follows inline declaration ", newdecl
);
13158 else if (lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl
))
13159 && lookup_attribute ("always_inline", DECL_ATTRIBUTES (olddecl
)))
13160 warned
|= warning (OPT_Wattributes
, "declaration of %q+D with attribute "
13161 "%qs follows declaration with attribute %qs",
13162 newdecl
, "noinline", "always_inline");
13163 else if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (newdecl
))
13164 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl
)))
13165 warned
|= warning (OPT_Wattributes
, "declaration of %q+D with attribute "
13166 "%qs follows declaration with attribute %qs",
13167 newdecl
, "always_inline", "noinline");
13168 else if (lookup_attribute ("cold", DECL_ATTRIBUTES (newdecl
))
13169 && lookup_attribute ("hot", DECL_ATTRIBUTES (olddecl
)))
13170 warned
|= warning (OPT_Wattributes
, "declaration of %q+D with attribute "
13171 "%qs follows declaration with attribute %qs",
13172 newdecl
, "cold", "hot");
13173 else if (lookup_attribute ("hot", DECL_ATTRIBUTES (newdecl
))
13174 && lookup_attribute ("cold", DECL_ATTRIBUTES (olddecl
)))
13175 warned
|= warning (OPT_Wattributes
, "declaration of %q+D with attribute "
13176 "%qs follows declaration with attribute %qs",
13177 newdecl
, "hot", "cold");
13181 #include "gt-c-family-c-common.h"