1 /* Subroutines shared by all languages that are variants of C.
2 Copyright (C) 1992-2016 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #define GCC_C_COMMON_C
24 #include "coretypes.h"
30 #include "gimple-expr.h"
32 #include "stringpool.h"
34 #include "diagnostic.h"
36 #include "stor-layout.h"
40 #include "trans-mem.h"
42 #include "common/common-target.h"
43 #include "langhooks.h"
44 #include "tree-inline.h"
46 #include "tree-iterator.h"
49 #include "substring-locations.h"
50 #include "spellcheck.h"
52 cpp_reader
*parse_in
; /* Declared in c-pragma.h. */
54 /* Mode used to build pointers (VOIDmode means ptr_mode). */
56 machine_mode c_default_pointer_mode
= VOIDmode
;
58 /* The following symbols are subsumed in the c_global_trees array, and
59 listed here individually for documentation purposes.
61 INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
63 tree short_integer_type_node;
64 tree long_integer_type_node;
65 tree long_long_integer_type_node;
67 tree short_unsigned_type_node;
68 tree long_unsigned_type_node;
69 tree long_long_unsigned_type_node;
71 tree truthvalue_type_node;
72 tree truthvalue_false_node;
73 tree truthvalue_true_node;
75 tree ptrdiff_type_node;
77 tree unsigned_char_type_node;
78 tree signed_char_type_node;
81 tree char16_type_node;
82 tree char32_type_node;
85 tree double_type_node;
86 tree long_double_type_node;
88 tree complex_integer_type_node;
89 tree complex_float_type_node;
90 tree complex_double_type_node;
91 tree complex_long_double_type_node;
93 tree dfloat32_type_node;
94 tree dfloat64_type_node;
95 tree_dfloat128_type_node;
100 tree intDI_type_node;
101 tree intTI_type_node;
103 tree unsigned_intQI_type_node;
104 tree unsigned_intHI_type_node;
105 tree unsigned_intSI_type_node;
106 tree unsigned_intDI_type_node;
107 tree unsigned_intTI_type_node;
109 tree widest_integer_literal_type_node;
110 tree widest_unsigned_literal_type_node;
112 Nodes for types `void *' and `const void *'.
114 tree ptr_type_node, const_ptr_type_node;
116 Nodes for types `char *' and `const char *'.
118 tree string_type_node, const_string_type_node;
120 Type `char[SOMENUMBER]'.
121 Used when an array of char is needed and the size is irrelevant.
123 tree char_array_type_node;
125 Type `wchar_t[SOMENUMBER]' or something like it.
126 Used when a wide string literal is created.
128 tree wchar_array_type_node;
130 Type `char16_t[SOMENUMBER]' or something like it.
131 Used when a UTF-16 string literal is created.
133 tree char16_array_type_node;
135 Type `char32_t[SOMENUMBER]' or something like it.
136 Used when a UTF-32 string literal is created.
138 tree char32_array_type_node;
140 Type `int ()' -- used for implicit declaration of functions.
142 tree default_function_type;
144 A VOID_TYPE node, packaged in a TREE_LIST.
148 The lazily created VAR_DECLs for __FUNCTION__, __PRETTY_FUNCTION__,
149 and __func__. (C doesn't generate __FUNCTION__ and__PRETTY_FUNCTION__
150 VAR_DECLS, but C++ does.)
152 tree function_name_decl_node;
153 tree pretty_function_name_decl_node;
154 tree c99_function_name_decl_node;
156 Stack of nested function name VAR_DECLs.
158 tree saved_function_name_decls;
162 tree c_global_trees
[CTI_MAX
];
164 /* Switches common to the C front ends. */
166 /* Nonzero means don't output line number information. */
168 char flag_no_line_commands
;
170 /* Nonzero causes -E output not to be done, but directives such as
171 #define that have side effects are still obeyed. */
175 /* Nonzero means dump macros in some fashion. */
177 char flag_dump_macros
;
179 /* Nonzero means pass #include lines through to the output. */
181 char flag_dump_includes
;
183 /* Nonzero means process PCH files while preprocessing. */
185 bool flag_pch_preprocess
;
187 /* The file name to which we should write a precompiled header, or
188 NULL if no header will be written in this compile. */
190 const char *pch_file
;
192 /* Nonzero if an ISO standard was selected. It rejects macros in the
196 /* C/ObjC language option variables. */
199 /* Nonzero means allow type mismatches in conditional expressions;
200 just make their values `void'. */
202 int flag_cond_mismatch
;
204 /* Nonzero means enable C89 Amendment 1 features. */
208 /* Nonzero means use the ISO C99 (or C11) dialect of C. */
212 /* Nonzero means use the ISO C11 dialect of C. */
216 /* Nonzero means that we have builtin functions, and main is an int. */
221 /* ObjC language option variables. */
224 /* Tells the compiler that this is a special run. Do not perform any
225 compiling, instead we are to test some platform dependent features
226 and output a C header file with appropriate definitions. */
228 int print_struct_values
;
230 /* Tells the compiler what is the constant string class for ObjC. */
232 const char *constant_string_class_name
;
235 /* C++ language option variables. */
237 /* The reference version of the ABI for -Wabi. */
239 int warn_abi_version
= -1;
241 /* Nonzero means generate separate instantiation control files and
242 juggle them at link time. */
244 int flag_use_repository
;
246 /* The C++ dialect being used. Default set in c_common_post_options. */
248 enum cxx_dialect cxx_dialect
= cxx_unset
;
250 /* Maximum template instantiation depth. This limit exists to limit the
251 time it takes to notice excessively recursive template instantiations.
253 The default is lower than the 1024 recommended by the C++0x standard
254 because G++ runs out of stack before 1024 with highly recursive template
255 argument deduction substitution (g++.dg/cpp0x/enum11.C). */
257 int max_tinst_depth
= 900;
259 /* The elements of `ridpointers' are identifier nodes for the reserved
260 type names and storage classes. It is indexed by a RID_... value. */
263 tree (*make_fname_decl
) (location_t
, tree
, int);
265 /* Nonzero means don't warn about problems that occur when the code is
267 int c_inhibit_evaluation_warnings
;
269 /* Whether we are building a boolean conversion inside
270 convert_for_assignment, or some other late binary operation. If
271 build_binary_op is called for C (from code shared by C and C++) in
272 this case, then the operands have already been folded and the
273 result will not be folded again, so C_MAYBE_CONST_EXPR should not
275 bool in_late_binary_op
;
277 /* Whether lexing has been completed, so subsequent preprocessor
278 errors should use the compiler's input_location. */
279 bool done_lexing
= false;
281 /* Information about how a function name is generated. */
284 tree
*const decl
; /* pointer to the VAR_DECL. */
285 const unsigned rid
; /* RID number for the identifier. */
286 const int pretty
; /* How pretty is it? */
289 /* The three ways of getting then name of the current function. */
291 const struct fname_var_t fname_vars
[] =
293 /* C99 compliant __func__, must be first. */
294 {&c99_function_name_decl_node
, RID_C99_FUNCTION_NAME
, 0},
295 /* GCC __FUNCTION__ compliant. */
296 {&function_name_decl_node
, RID_FUNCTION_NAME
, 0},
297 /* GCC __PRETTY_FUNCTION__ compliant. */
298 {&pretty_function_name_decl_node
, RID_PRETTY_FUNCTION_NAME
, 1},
302 /* Global visibility options. */
303 struct visibility_flags visibility_options
;
305 static tree
check_case_value (location_t
, tree
);
306 static bool check_case_bounds (location_t
, tree
, tree
, tree
*, tree
*,
309 static tree
handle_packed_attribute (tree
*, tree
, tree
, int, bool *);
310 static tree
handle_nocommon_attribute (tree
*, tree
, tree
, int, bool *);
311 static tree
handle_common_attribute (tree
*, tree
, tree
, int, bool *);
312 static tree
handle_noreturn_attribute (tree
*, tree
, tree
, int, bool *);
313 static tree
handle_hot_attribute (tree
*, tree
, tree
, int, bool *);
314 static tree
handle_cold_attribute (tree
*, tree
, tree
, int, bool *);
315 static tree
handle_no_sanitize_address_attribute (tree
*, tree
, tree
,
317 static tree
handle_no_address_safety_analysis_attribute (tree
*, tree
, tree
,
319 static tree
handle_no_sanitize_undefined_attribute (tree
*, tree
, tree
, int,
321 static tree
handle_stack_protect_attribute (tree
*, tree
, tree
, int, bool *);
322 static tree
handle_noinline_attribute (tree
*, tree
, tree
, int, bool *);
323 static tree
handle_noclone_attribute (tree
*, tree
, tree
, int, bool *);
324 static tree
handle_noicf_attribute (tree
*, tree
, tree
, int, bool *);
325 static tree
handle_leaf_attribute (tree
*, tree
, tree
, int, bool *);
326 static tree
handle_always_inline_attribute (tree
*, tree
, tree
, int,
328 static tree
handle_gnu_inline_attribute (tree
*, tree
, tree
, int, bool *);
329 static tree
handle_artificial_attribute (tree
*, tree
, tree
, int, bool *);
330 static tree
handle_flatten_attribute (tree
*, tree
, tree
, int, bool *);
331 static tree
handle_error_attribute (tree
*, tree
, tree
, int, bool *);
332 static tree
handle_used_attribute (tree
*, tree
, tree
, int, bool *);
333 static tree
handle_externally_visible_attribute (tree
*, tree
, tree
, int,
335 static tree
handle_no_reorder_attribute (tree
*, tree
, tree
, int,
337 static tree
handle_const_attribute (tree
*, tree
, tree
, int, bool *);
338 static tree
handle_transparent_union_attribute (tree
*, tree
, tree
,
340 static tree
handle_scalar_storage_order_attribute (tree
*, tree
, tree
,
342 static tree
handle_constructor_attribute (tree
*, tree
, tree
, int, bool *);
343 static tree
handle_destructor_attribute (tree
*, tree
, tree
, int, bool *);
344 static tree
handle_mode_attribute (tree
*, tree
, tree
, int, bool *);
345 static tree
handle_section_attribute (tree
*, tree
, tree
, int, bool *);
346 static tree
handle_aligned_attribute (tree
*, tree
, tree
, int, bool *);
347 static tree
handle_weak_attribute (tree
*, tree
, tree
, int, bool *) ;
348 static tree
handle_noplt_attribute (tree
*, tree
, tree
, int, bool *) ;
349 static tree
handle_alias_ifunc_attribute (bool, tree
*, tree
, tree
, bool *);
350 static tree
handle_ifunc_attribute (tree
*, tree
, tree
, int, bool *);
351 static tree
handle_alias_attribute (tree
*, tree
, tree
, int, bool *);
352 static tree
handle_weakref_attribute (tree
*, tree
, tree
, int, bool *) ;
353 static tree
handle_visibility_attribute (tree
*, tree
, tree
, int,
355 static tree
handle_tls_model_attribute (tree
*, tree
, tree
, int,
357 static tree
handle_no_instrument_function_attribute (tree
*, tree
,
359 static tree
handle_no_profile_instrument_function_attribute (tree
*, tree
,
361 static tree
handle_malloc_attribute (tree
*, tree
, tree
, int, bool *);
362 static tree
handle_returns_twice_attribute (tree
*, tree
, tree
, int, bool *);
363 static tree
handle_no_limit_stack_attribute (tree
*, tree
, tree
, int,
365 static tree
handle_pure_attribute (tree
*, tree
, tree
, int, bool *);
366 static tree
handle_tm_attribute (tree
*, tree
, tree
, int, bool *);
367 static tree
handle_tm_wrap_attribute (tree
*, tree
, tree
, int, bool *);
368 static tree
handle_novops_attribute (tree
*, tree
, tree
, int, bool *);
369 static tree
handle_deprecated_attribute (tree
*, tree
, tree
, int,
371 static tree
handle_vector_size_attribute (tree
*, tree
, tree
, int,
373 static tree
handle_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
374 static tree
handle_nothrow_attribute (tree
*, tree
, tree
, int, bool *);
375 static tree
handle_cleanup_attribute (tree
*, tree
, tree
, int, bool *);
376 static tree
handle_warn_unused_result_attribute (tree
*, tree
, tree
, int,
378 static tree
handle_sentinel_attribute (tree
*, tree
, tree
, int, bool *);
379 static tree
handle_type_generic_attribute (tree
*, tree
, tree
, int, bool *);
380 static tree
handle_alloc_size_attribute (tree
*, tree
, tree
, int, bool *);
381 static tree
handle_alloc_align_attribute (tree
*, tree
, tree
, int, bool *);
382 static tree
handle_assume_aligned_attribute (tree
*, tree
, tree
, int, bool *);
383 static tree
handle_target_attribute (tree
*, tree
, tree
, int, bool *);
384 static tree
handle_target_clones_attribute (tree
*, tree
, tree
, int, bool *);
385 static tree
handle_optimize_attribute (tree
*, tree
, tree
, int, bool *);
386 static tree
ignore_attribute (tree
*, tree
, tree
, int, bool *);
387 static tree
handle_no_split_stack_attribute (tree
*, tree
, tree
, int, bool *);
388 static tree
handle_fnspec_attribute (tree
*, tree
, tree
, int, bool *);
389 static tree
handle_warn_unused_attribute (tree
*, tree
, tree
, int, bool *);
390 static tree
handle_returns_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
391 static tree
handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int,
393 static tree
handle_simd_attribute (tree
*, tree
, tree
, int, bool *);
394 static tree
handle_omp_declare_target_attribute (tree
*, tree
, tree
, int,
396 static tree
handle_designated_init_attribute (tree
*, tree
, tree
, int, bool *);
397 static tree
handle_bnd_variable_size_attribute (tree
*, tree
, tree
, int, bool *);
398 static tree
handle_bnd_legacy (tree
*, tree
, tree
, int, bool *);
399 static tree
handle_bnd_instrument (tree
*, tree
, tree
, int, bool *);
400 static tree
handle_fallthrough_attribute (tree
*, tree
, tree
, int, bool *);
402 static void check_nonnull_arg (void *, tree
, unsigned HOST_WIDE_INT
);
403 static bool nonnull_check_p (tree
, unsigned HOST_WIDE_INT
);
404 static bool get_nonnull_operand (tree
, unsigned HOST_WIDE_INT
*);
405 static int resort_field_decl_cmp (const void *, const void *);
407 /* Reserved words. The third field is a mask: keywords are disabled
408 if they match the mask.
411 C --std=c89: D_C99 | D_CXXONLY | D_OBJC | D_CXX_OBJC
412 C --std=c99: D_CXXONLY | D_OBJC
413 ObjC is like C except that D_OBJC and D_CXX_OBJC are not set
414 C++ --std=c++98: D_CONLY | D_CXX11 | D_OBJC
415 C++ --std=c++11: D_CONLY | D_OBJC
416 ObjC++ is like C++ except that D_OBJC is not set
418 If -fno-asm is used, D_ASM is added to the mask. If
419 -fno-gnu-keywords is used, D_EXT is added. If -fno-asm and C in
420 C89 mode, D_EXT89 is added for both -fno-asm and -fno-gnu-keywords.
421 In C with -Wc++-compat, we warn if D_CXXWARN is set.
423 Note the complication of the D_CXX_OBJC keywords. These are
424 reserved words such as 'class'. In C++, 'class' is a reserved
425 word. In Objective-C++ it is too. In Objective-C, it is a
426 reserved word too, but only if it follows an '@' sign.
428 const struct c_common_resword c_common_reswords
[] =
430 { "_Alignas", RID_ALIGNAS
, D_CONLY
},
431 { "_Alignof", RID_ALIGNOF
, D_CONLY
},
432 { "_Atomic", RID_ATOMIC
, D_CONLY
},
433 { "_Bool", RID_BOOL
, D_CONLY
},
434 { "_Complex", RID_COMPLEX
, 0 },
435 { "_Cilk_spawn", RID_CILK_SPAWN
, 0 },
436 { "_Cilk_sync", RID_CILK_SYNC
, 0 },
437 { "_Cilk_for", RID_CILK_FOR
, 0 },
438 { "_Imaginary", RID_IMAGINARY
, D_CONLY
},
439 { "_Float16", RID_FLOAT16
, D_CONLY
},
440 { "_Float32", RID_FLOAT32
, D_CONLY
},
441 { "_Float64", RID_FLOAT64
, D_CONLY
},
442 { "_Float128", RID_FLOAT128
, D_CONLY
},
443 { "_Float32x", RID_FLOAT32X
, D_CONLY
},
444 { "_Float64x", RID_FLOAT64X
, D_CONLY
},
445 { "_Float128x", RID_FLOAT128X
, D_CONLY
},
446 { "_Decimal32", RID_DFLOAT32
, D_CONLY
| D_EXT
},
447 { "_Decimal64", RID_DFLOAT64
, D_CONLY
| D_EXT
},
448 { "_Decimal128", RID_DFLOAT128
, D_CONLY
| D_EXT
},
449 { "_Fract", RID_FRACT
, D_CONLY
| D_EXT
},
450 { "_Accum", RID_ACCUM
, D_CONLY
| D_EXT
},
451 { "_Sat", RID_SAT
, D_CONLY
| D_EXT
},
452 { "_Static_assert", RID_STATIC_ASSERT
, D_CONLY
},
453 { "_Noreturn", RID_NORETURN
, D_CONLY
},
454 { "_Generic", RID_GENERIC
, D_CONLY
},
455 { "_Thread_local", RID_THREAD
, D_CONLY
},
456 { "__FUNCTION__", RID_FUNCTION_NAME
, 0 },
457 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME
, 0 },
458 { "__alignof", RID_ALIGNOF
, 0 },
459 { "__alignof__", RID_ALIGNOF
, 0 },
460 { "__asm", RID_ASM
, 0 },
461 { "__asm__", RID_ASM
, 0 },
462 { "__attribute", RID_ATTRIBUTE
, 0 },
463 { "__attribute__", RID_ATTRIBUTE
, 0 },
464 { "__auto_type", RID_AUTO_TYPE
, D_CONLY
},
465 { "__bases", RID_BASES
, D_CXXONLY
},
466 { "__builtin_addressof", RID_ADDRESSOF
, D_CXXONLY
},
467 { "__builtin_call_with_static_chain",
468 RID_BUILTIN_CALL_WITH_STATIC_CHAIN
, D_CONLY
},
469 { "__builtin_choose_expr", RID_CHOOSE_EXPR
, D_CONLY
},
470 { "__builtin_complex", RID_BUILTIN_COMPLEX
, D_CONLY
},
471 { "__builtin_shuffle", RID_BUILTIN_SHUFFLE
, 0 },
472 { "__builtin_offsetof", RID_OFFSETOF
, 0 },
473 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P
, D_CONLY
},
474 { "__builtin_va_arg", RID_VA_ARG
, 0 },
475 { "__complex", RID_COMPLEX
, 0 },
476 { "__complex__", RID_COMPLEX
, 0 },
477 { "__const", RID_CONST
, 0 },
478 { "__const__", RID_CONST
, 0 },
479 { "__decltype", RID_DECLTYPE
, D_CXXONLY
},
480 { "__direct_bases", RID_DIRECT_BASES
, D_CXXONLY
},
481 { "__extension__", RID_EXTENSION
, 0 },
482 { "__func__", RID_C99_FUNCTION_NAME
, 0 },
483 { "__has_nothrow_assign", RID_HAS_NOTHROW_ASSIGN
, D_CXXONLY
},
484 { "__has_nothrow_constructor", RID_HAS_NOTHROW_CONSTRUCTOR
, D_CXXONLY
},
485 { "__has_nothrow_copy", RID_HAS_NOTHROW_COPY
, D_CXXONLY
},
486 { "__has_trivial_assign", RID_HAS_TRIVIAL_ASSIGN
, D_CXXONLY
},
487 { "__has_trivial_constructor", RID_HAS_TRIVIAL_CONSTRUCTOR
, D_CXXONLY
},
488 { "__has_trivial_copy", RID_HAS_TRIVIAL_COPY
, D_CXXONLY
},
489 { "__has_trivial_destructor", RID_HAS_TRIVIAL_DESTRUCTOR
, D_CXXONLY
},
490 { "__has_unique_object_representations", RID_HAS_UNIQUE_OBJ_REPRESENTATIONS
,
492 { "__has_virtual_destructor", RID_HAS_VIRTUAL_DESTRUCTOR
, D_CXXONLY
},
493 { "__imag", RID_IMAGPART
, 0 },
494 { "__imag__", RID_IMAGPART
, 0 },
495 { "__inline", RID_INLINE
, 0 },
496 { "__inline__", RID_INLINE
, 0 },
497 { "__is_abstract", RID_IS_ABSTRACT
, D_CXXONLY
},
498 { "__is_base_of", RID_IS_BASE_OF
, D_CXXONLY
},
499 { "__is_class", RID_IS_CLASS
, D_CXXONLY
},
500 { "__is_empty", RID_IS_EMPTY
, D_CXXONLY
},
501 { "__is_enum", RID_IS_ENUM
, D_CXXONLY
},
502 { "__is_final", RID_IS_FINAL
, D_CXXONLY
},
503 { "__is_literal_type", RID_IS_LITERAL_TYPE
, D_CXXONLY
},
504 { "__is_pod", RID_IS_POD
, D_CXXONLY
},
505 { "__is_polymorphic", RID_IS_POLYMORPHIC
, D_CXXONLY
},
506 { "__is_same_as", RID_IS_SAME_AS
, D_CXXONLY
},
507 { "__is_standard_layout", RID_IS_STD_LAYOUT
, D_CXXONLY
},
508 { "__is_trivial", RID_IS_TRIVIAL
, D_CXXONLY
},
509 { "__is_trivially_assignable", RID_IS_TRIVIALLY_ASSIGNABLE
, D_CXXONLY
},
510 { "__is_trivially_constructible", RID_IS_TRIVIALLY_CONSTRUCTIBLE
, D_CXXONLY
},
511 { "__is_trivially_copyable", RID_IS_TRIVIALLY_COPYABLE
, D_CXXONLY
},
512 { "__is_union", RID_IS_UNION
, D_CXXONLY
},
513 { "__label__", RID_LABEL
, 0 },
514 { "__null", RID_NULL
, 0 },
515 { "__real", RID_REALPART
, 0 },
516 { "__real__", RID_REALPART
, 0 },
517 { "__restrict", RID_RESTRICT
, 0 },
518 { "__restrict__", RID_RESTRICT
, 0 },
519 { "__signed", RID_SIGNED
, 0 },
520 { "__signed__", RID_SIGNED
, 0 },
521 { "__thread", RID_THREAD
, 0 },
522 { "__transaction_atomic", RID_TRANSACTION_ATOMIC
, 0 },
523 { "__transaction_relaxed", RID_TRANSACTION_RELAXED
, 0 },
524 { "__transaction_cancel", RID_TRANSACTION_CANCEL
, 0 },
525 { "__typeof", RID_TYPEOF
, 0 },
526 { "__typeof__", RID_TYPEOF
, 0 },
527 { "__underlying_type", RID_UNDERLYING_TYPE
, D_CXXONLY
},
528 { "__volatile", RID_VOLATILE
, 0 },
529 { "__volatile__", RID_VOLATILE
, 0 },
530 { "alignas", RID_ALIGNAS
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
531 { "alignof", RID_ALIGNOF
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
532 { "asm", RID_ASM
, D_ASM
},
533 { "auto", RID_AUTO
, 0 },
534 { "bool", RID_BOOL
, D_CXXONLY
| D_CXXWARN
},
535 { "break", RID_BREAK
, 0 },
536 { "case", RID_CASE
, 0 },
537 { "catch", RID_CATCH
, D_CXX_OBJC
| D_CXXWARN
},
538 { "char", RID_CHAR
, 0 },
539 { "char16_t", RID_CHAR16
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
540 { "char32_t", RID_CHAR32
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
541 { "class", RID_CLASS
, D_CXX_OBJC
| D_CXXWARN
},
542 { "const", RID_CONST
, 0 },
543 { "constexpr", RID_CONSTEXPR
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
544 { "const_cast", RID_CONSTCAST
, D_CXXONLY
| D_CXXWARN
},
545 { "continue", RID_CONTINUE
, 0 },
546 { "decltype", RID_DECLTYPE
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
547 { "default", RID_DEFAULT
, 0 },
548 { "delete", RID_DELETE
, D_CXXONLY
| D_CXXWARN
},
550 { "double", RID_DOUBLE
, 0 },
551 { "dynamic_cast", RID_DYNCAST
, D_CXXONLY
| D_CXXWARN
},
552 { "else", RID_ELSE
, 0 },
553 { "enum", RID_ENUM
, 0 },
554 { "explicit", RID_EXPLICIT
, D_CXXONLY
| D_CXXWARN
},
555 { "export", RID_EXPORT
, D_CXXONLY
| D_CXXWARN
},
556 { "extern", RID_EXTERN
, 0 },
557 { "false", RID_FALSE
, D_CXXONLY
| D_CXXWARN
},
558 { "float", RID_FLOAT
, 0 },
559 { "for", RID_FOR
, 0 },
560 { "friend", RID_FRIEND
, D_CXXONLY
| D_CXXWARN
},
561 { "goto", RID_GOTO
, 0 },
563 { "inline", RID_INLINE
, D_EXT89
},
564 { "int", RID_INT
, 0 },
565 { "long", RID_LONG
, 0 },
566 { "mutable", RID_MUTABLE
, D_CXXONLY
| D_CXXWARN
},
567 { "namespace", RID_NAMESPACE
, D_CXXONLY
| D_CXXWARN
},
568 { "new", RID_NEW
, D_CXXONLY
| D_CXXWARN
},
569 { "noexcept", RID_NOEXCEPT
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
570 { "nullptr", RID_NULLPTR
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
571 { "operator", RID_OPERATOR
, D_CXXONLY
| D_CXXWARN
},
572 { "private", RID_PRIVATE
, D_CXX_OBJC
| D_CXXWARN
},
573 { "protected", RID_PROTECTED
, D_CXX_OBJC
| D_CXXWARN
},
574 { "public", RID_PUBLIC
, D_CXX_OBJC
| D_CXXWARN
},
575 { "register", RID_REGISTER
, 0 },
576 { "reinterpret_cast", RID_REINTCAST
, D_CXXONLY
| D_CXXWARN
},
577 { "restrict", RID_RESTRICT
, D_CONLY
| D_C99
},
578 { "return", RID_RETURN
, 0 },
579 { "short", RID_SHORT
, 0 },
580 { "signed", RID_SIGNED
, 0 },
581 { "sizeof", RID_SIZEOF
, 0 },
582 { "static", RID_STATIC
, 0 },
583 { "static_assert", RID_STATIC_ASSERT
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
584 { "static_cast", RID_STATCAST
, D_CXXONLY
| D_CXXWARN
},
585 { "struct", RID_STRUCT
, 0 },
586 { "switch", RID_SWITCH
, 0 },
587 { "template", RID_TEMPLATE
, D_CXXONLY
| D_CXXWARN
},
588 { "this", RID_THIS
, D_CXXONLY
| D_CXXWARN
},
589 { "thread_local", RID_THREAD
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
590 { "throw", RID_THROW
, D_CXX_OBJC
| D_CXXWARN
},
591 { "true", RID_TRUE
, D_CXXONLY
| D_CXXWARN
},
592 { "try", RID_TRY
, D_CXX_OBJC
| D_CXXWARN
},
593 { "typedef", RID_TYPEDEF
, 0 },
594 { "typename", RID_TYPENAME
, D_CXXONLY
| D_CXXWARN
},
595 { "typeid", RID_TYPEID
, D_CXXONLY
| D_CXXWARN
},
596 { "typeof", RID_TYPEOF
, D_ASM
| D_EXT
},
597 { "union", RID_UNION
, 0 },
598 { "unsigned", RID_UNSIGNED
, 0 },
599 { "using", RID_USING
, D_CXXONLY
| D_CXXWARN
},
600 { "virtual", RID_VIRTUAL
, D_CXXONLY
| D_CXXWARN
},
601 { "void", RID_VOID
, 0 },
602 { "volatile", RID_VOLATILE
, 0 },
603 { "wchar_t", RID_WCHAR
, D_CXXONLY
},
604 { "while", RID_WHILE
, 0 },
606 /* C++ transactional memory. */
607 { "synchronized", RID_SYNCHRONIZED
, D_CXX_OBJC
| D_TRANSMEM
},
608 { "atomic_noexcept", RID_ATOMIC_NOEXCEPT
, D_CXXONLY
| D_TRANSMEM
},
609 { "atomic_cancel", RID_ATOMIC_CANCEL
, D_CXXONLY
| D_TRANSMEM
},
610 { "atomic_commit", RID_TRANSACTION_ATOMIC
, D_CXXONLY
| D_TRANSMEM
},
612 /* Concepts-related keywords */
613 { "concept", RID_CONCEPT
, D_CXX_CONCEPTS_FLAGS
| D_CXXWARN
},
614 { "requires", RID_REQUIRES
, D_CXX_CONCEPTS_FLAGS
| D_CXXWARN
},
616 /* These Objective-C keywords are recognized only immediately after
618 { "compatibility_alias", RID_AT_ALIAS
, D_OBJC
},
619 { "defs", RID_AT_DEFS
, D_OBJC
},
620 { "encode", RID_AT_ENCODE
, D_OBJC
},
621 { "end", RID_AT_END
, D_OBJC
},
622 { "implementation", RID_AT_IMPLEMENTATION
, D_OBJC
},
623 { "interface", RID_AT_INTERFACE
, D_OBJC
},
624 { "protocol", RID_AT_PROTOCOL
, D_OBJC
},
625 { "selector", RID_AT_SELECTOR
, D_OBJC
},
626 { "finally", RID_AT_FINALLY
, D_OBJC
},
627 { "optional", RID_AT_OPTIONAL
, D_OBJC
},
628 { "required", RID_AT_REQUIRED
, D_OBJC
},
629 { "property", RID_AT_PROPERTY
, D_OBJC
},
630 { "package", RID_AT_PACKAGE
, D_OBJC
},
631 { "synthesize", RID_AT_SYNTHESIZE
, D_OBJC
},
632 { "dynamic", RID_AT_DYNAMIC
, D_OBJC
},
633 /* These are recognized only in protocol-qualifier context
635 { "bycopy", RID_BYCOPY
, D_OBJC
},
636 { "byref", RID_BYREF
, D_OBJC
},
637 { "in", RID_IN
, D_OBJC
},
638 { "inout", RID_INOUT
, D_OBJC
},
639 { "oneway", RID_ONEWAY
, D_OBJC
},
640 { "out", RID_OUT
, D_OBJC
},
641 /* These are recognized inside a property attribute list */
642 { "assign", RID_ASSIGN
, D_OBJC
},
643 { "copy", RID_COPY
, D_OBJC
},
644 { "getter", RID_GETTER
, D_OBJC
},
645 { "nonatomic", RID_NONATOMIC
, D_OBJC
},
646 { "readonly", RID_READONLY
, D_OBJC
},
647 { "readwrite", RID_READWRITE
, D_OBJC
},
648 { "retain", RID_RETAIN
, D_OBJC
},
649 { "setter", RID_SETTER
, D_OBJC
},
652 const unsigned int num_c_common_reswords
=
653 sizeof c_common_reswords
/ sizeof (struct c_common_resword
);
655 /* Table of machine-independent attributes common to all C-like languages.
657 All attributes referencing arguments should be additionally processed
658 in chkp_copy_function_type_adding_bounds for correct instrumentation
659 by Pointer Bounds Checker.
660 Current list of processed common attributes: nonnull. */
661 const struct attribute_spec c_common_attribute_table
[] =
663 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
664 affects_type_identity } */
665 { "packed", 0, 0, false, false, false,
666 handle_packed_attribute
, false},
667 { "nocommon", 0, 0, true, false, false,
668 handle_nocommon_attribute
, false},
669 { "common", 0, 0, true, false, false,
670 handle_common_attribute
, false },
671 /* FIXME: logically, noreturn attributes should be listed as
672 "false, true, true" and apply to function types. But implementing this
673 would require all the places in the compiler that use TREE_THIS_VOLATILE
674 on a decl to identify non-returning functions to be located and fixed
675 to check the function type instead. */
676 { "noreturn", 0, 0, true, false, false,
677 handle_noreturn_attribute
, false },
678 { "volatile", 0, 0, true, false, false,
679 handle_noreturn_attribute
, false },
680 { "stack_protect", 0, 0, true, false, false,
681 handle_stack_protect_attribute
, false },
682 { "noinline", 0, 0, true, false, false,
683 handle_noinline_attribute
, false },
684 { "noclone", 0, 0, true, false, false,
685 handle_noclone_attribute
, false },
686 { "no_icf", 0, 0, true, false, false,
687 handle_noicf_attribute
, false },
688 { "leaf", 0, 0, true, false, false,
689 handle_leaf_attribute
, false },
690 { "always_inline", 0, 0, true, false, false,
691 handle_always_inline_attribute
, false },
692 { "gnu_inline", 0, 0, true, false, false,
693 handle_gnu_inline_attribute
, false },
694 { "artificial", 0, 0, true, false, false,
695 handle_artificial_attribute
, false },
696 { "flatten", 0, 0, true, false, false,
697 handle_flatten_attribute
, false },
698 { "used", 0, 0, true, false, false,
699 handle_used_attribute
, false },
700 { "unused", 0, 0, false, false, false,
701 handle_unused_attribute
, false },
702 { "externally_visible", 0, 0, true, false, false,
703 handle_externally_visible_attribute
, false },
704 { "no_reorder", 0, 0, true, false, false,
705 handle_no_reorder_attribute
, false },
706 /* The same comments as for noreturn attributes apply to const ones. */
707 { "const", 0, 0, true, false, false,
708 handle_const_attribute
, false },
709 { "scalar_storage_order", 1, 1, false, false, false,
710 handle_scalar_storage_order_attribute
, false },
711 { "transparent_union", 0, 0, false, false, false,
712 handle_transparent_union_attribute
, false },
713 { "constructor", 0, 1, true, false, false,
714 handle_constructor_attribute
, false },
715 { "destructor", 0, 1, true, false, false,
716 handle_destructor_attribute
, false },
717 { "mode", 1, 1, false, true, false,
718 handle_mode_attribute
, false },
719 { "section", 1, 1, true, false, false,
720 handle_section_attribute
, false },
721 { "aligned", 0, 1, false, false, false,
722 handle_aligned_attribute
, false },
723 { "weak", 0, 0, true, false, false,
724 handle_weak_attribute
, false },
725 { "noplt", 0, 0, true, false, false,
726 handle_noplt_attribute
, false },
727 { "ifunc", 1, 1, true, false, false,
728 handle_ifunc_attribute
, false },
729 { "alias", 1, 1, true, false, false,
730 handle_alias_attribute
, false },
731 { "weakref", 0, 1, true, false, false,
732 handle_weakref_attribute
, false },
733 { "no_instrument_function", 0, 0, true, false, false,
734 handle_no_instrument_function_attribute
,
736 { "no_profile_instrument_function", 0, 0, true, false, false,
737 handle_no_profile_instrument_function_attribute
,
739 { "malloc", 0, 0, true, false, false,
740 handle_malloc_attribute
, false },
741 { "returns_twice", 0, 0, true, false, false,
742 handle_returns_twice_attribute
, false },
743 { "no_stack_limit", 0, 0, true, false, false,
744 handle_no_limit_stack_attribute
, false },
745 { "pure", 0, 0, true, false, false,
746 handle_pure_attribute
, false },
747 { "transaction_callable", 0, 0, false, true, false,
748 handle_tm_attribute
, false },
749 { "transaction_unsafe", 0, 0, false, true, false,
750 handle_tm_attribute
, true },
751 { "transaction_safe", 0, 0, false, true, false,
752 handle_tm_attribute
, true },
753 { "transaction_safe_dynamic", 0, 0, true, false, false,
754 handle_tm_attribute
, false },
755 { "transaction_may_cancel_outer", 0, 0, false, true, false,
756 handle_tm_attribute
, false },
757 /* ??? These two attributes didn't make the transition from the
758 Intel language document to the multi-vendor language document. */
759 { "transaction_pure", 0, 0, false, true, false,
760 handle_tm_attribute
, false },
761 { "transaction_wrap", 1, 1, true, false, false,
762 handle_tm_wrap_attribute
, false },
763 /* For internal use (marking of builtins) only. The name contains space
764 to prevent its usage in source code. */
765 { "no vops", 0, 0, true, false, false,
766 handle_novops_attribute
, false },
767 { "deprecated", 0, 1, false, false, false,
768 handle_deprecated_attribute
, false },
769 { "vector_size", 1, 1, false, true, false,
770 handle_vector_size_attribute
, true },
771 { "visibility", 1, 1, false, false, false,
772 handle_visibility_attribute
, false },
773 { "tls_model", 1, 1, true, false, false,
774 handle_tls_model_attribute
, false },
775 { "nonnull", 0, -1, false, true, true,
776 handle_nonnull_attribute
, false },
777 { "nothrow", 0, 0, true, false, false,
778 handle_nothrow_attribute
, false },
779 { "may_alias", 0, 0, false, true, false, NULL
, false },
780 { "cleanup", 1, 1, true, false, false,
781 handle_cleanup_attribute
, false },
782 { "warn_unused_result", 0, 0, false, true, true,
783 handle_warn_unused_result_attribute
, false },
784 { "sentinel", 0, 1, false, true, true,
785 handle_sentinel_attribute
, false },
786 /* For internal use (marking of builtins) only. The name contains space
787 to prevent its usage in source code. */
788 { "type generic", 0, 0, false, true, true,
789 handle_type_generic_attribute
, false },
790 { "alloc_size", 1, 2, false, true, true,
791 handle_alloc_size_attribute
, false },
792 { "cold", 0, 0, true, false, false,
793 handle_cold_attribute
, false },
794 { "hot", 0, 0, true, false, false,
795 handle_hot_attribute
, false },
796 { "no_address_safety_analysis",
797 0, 0, true, false, false,
798 handle_no_address_safety_analysis_attribute
,
800 { "no_sanitize_address", 0, 0, true, false, false,
801 handle_no_sanitize_address_attribute
,
803 { "no_sanitize_thread", 0, 0, true, false, false,
804 handle_no_sanitize_address_attribute
,
806 { "no_sanitize_undefined", 0, 0, true, false, false,
807 handle_no_sanitize_undefined_attribute
,
809 { "warning", 1, 1, true, false, false,
810 handle_error_attribute
, false },
811 { "error", 1, 1, true, false, false,
812 handle_error_attribute
, false },
813 { "target", 1, -1, true, false, false,
814 handle_target_attribute
, false },
815 { "target_clones", 1, -1, true, false, false,
816 handle_target_clones_attribute
, false },
817 { "optimize", 1, -1, true, false, false,
818 handle_optimize_attribute
, false },
819 /* For internal use only. The leading '*' both prevents its usage in
820 source code and signals that it may be overridden by machine tables. */
821 { "*tm regparm", 0, 0, false, true, true,
822 ignore_attribute
, false },
823 { "no_split_stack", 0, 0, true, false, false,
824 handle_no_split_stack_attribute
, false },
825 /* For internal use (marking of builtins and runtime functions) only.
826 The name contains space to prevent its usage in source code. */
827 { "fn spec", 1, 1, false, true, true,
828 handle_fnspec_attribute
, false },
829 { "warn_unused", 0, 0, false, false, false,
830 handle_warn_unused_attribute
, false },
831 { "returns_nonnull", 0, 0, false, true, true,
832 handle_returns_nonnull_attribute
, false },
833 { "omp declare simd", 0, -1, true, false, false,
834 handle_omp_declare_simd_attribute
, false },
835 { "cilk simd function", 0, -1, true, false, false,
836 handle_omp_declare_simd_attribute
, false },
837 { "simd", 0, 1, true, false, false,
838 handle_simd_attribute
, false },
839 { "omp declare target", 0, 0, true, false, false,
840 handle_omp_declare_target_attribute
, false },
841 { "omp declare target link", 0, 0, true, false, false,
842 handle_omp_declare_target_attribute
, false },
843 { "alloc_align", 1, 1, false, true, true,
844 handle_alloc_align_attribute
, false },
845 { "assume_aligned", 1, 2, false, true, true,
846 handle_assume_aligned_attribute
, false },
847 { "designated_init", 0, 0, false, true, false,
848 handle_designated_init_attribute
, false },
849 { "bnd_variable_size", 0, 0, true, false, false,
850 handle_bnd_variable_size_attribute
, false },
851 { "bnd_legacy", 0, 0, true, false, false,
852 handle_bnd_legacy
, false },
853 { "bnd_instrument", 0, 0, true, false, false,
854 handle_bnd_instrument
, false },
855 { "fallthrough", 0, 0, false, false, false,
856 handle_fallthrough_attribute
, false },
857 { NULL
, 0, 0, false, false, false, NULL
, false }
860 /* Give the specifications for the format attributes, used by C and all
863 All attributes referencing arguments should be additionally processed
864 in chkp_copy_function_type_adding_bounds for correct instrumentation
865 by Pointer Bounds Checker.
866 Current list of processed format attributes: format, format_arg. */
867 const struct attribute_spec c_common_format_attribute_table
[] =
869 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
870 affects_type_identity } */
871 { "format", 3, 3, false, true, true,
872 handle_format_attribute
, false },
873 { "format_arg", 1, 1, false, true, true,
874 handle_format_arg_attribute
, false },
875 { NULL
, 0, 0, false, false, false, NULL
, false }
878 /* Return identifier for address space AS. */
881 c_addr_space_name (addr_space_t as
)
883 int rid
= RID_FIRST_ADDR_SPACE
+ as
;
884 gcc_assert (ridpointers
[rid
]);
885 return IDENTIFIER_POINTER (ridpointers
[rid
]);
888 /* Push current bindings for the function name VAR_DECLS. */
891 start_fname_decls (void)
894 tree saved
= NULL_TREE
;
896 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
898 tree decl
= *fname_vars
[ix
].decl
;
902 saved
= tree_cons (decl
, build_int_cst (integer_type_node
, ix
),
904 *fname_vars
[ix
].decl
= NULL_TREE
;
907 if (saved
|| saved_function_name_decls
)
908 /* Normally they'll have been NULL, so only push if we've got a
909 stack, or they are non-NULL. */
910 saved_function_name_decls
= tree_cons (saved
, NULL_TREE
,
911 saved_function_name_decls
);
914 /* Finish up the current bindings, adding them into the current function's
915 statement tree. This must be done _before_ finish_stmt_tree is called.
916 If there is no current function, we must be at file scope and no statements
917 are involved. Pop the previous bindings. */
920 finish_fname_decls (void)
923 tree stmts
= NULL_TREE
;
924 tree stack
= saved_function_name_decls
;
926 for (; stack
&& TREE_VALUE (stack
); stack
= TREE_CHAIN (stack
))
927 append_to_statement_list (TREE_VALUE (stack
), &stmts
);
931 tree
*bodyp
= &DECL_SAVED_TREE (current_function_decl
);
933 if (TREE_CODE (*bodyp
) == BIND_EXPR
)
934 bodyp
= &BIND_EXPR_BODY (*bodyp
);
936 append_to_statement_list_force (*bodyp
, &stmts
);
940 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
941 *fname_vars
[ix
].decl
= NULL_TREE
;
945 /* We had saved values, restore them. */
948 for (saved
= TREE_PURPOSE (stack
); saved
; saved
= TREE_CHAIN (saved
))
950 tree decl
= TREE_PURPOSE (saved
);
951 unsigned ix
= TREE_INT_CST_LOW (TREE_VALUE (saved
));
953 *fname_vars
[ix
].decl
= decl
;
955 stack
= TREE_CHAIN (stack
);
957 saved_function_name_decls
= stack
;
960 /* Return the text name of the current function, suitably prettified
961 by PRETTY_P. Return string must be freed by caller. */
964 fname_as_string (int pretty_p
)
966 const char *name
= "top level";
969 cpp_string cstr
= { 0, 0 }, strname
;
977 if (current_function_decl
)
978 name
= lang_hooks
.decl_printable_name (current_function_decl
, vrb
);
980 len
= strlen (name
) + 3; /* Two for '"'s. One for NULL. */
982 namep
= XNEWVEC (char, len
);
983 snprintf (namep
, len
, "\"%s\"", name
);
984 strname
.text
= (unsigned char *) namep
;
985 strname
.len
= len
- 1;
987 if (cpp_interpret_string (parse_in
, &strname
, 1, &cstr
, CPP_STRING
))
990 return (const char *) cstr
.text
;
996 /* Return the VAR_DECL for a const char array naming the current
997 function. If the VAR_DECL has not yet been created, create it
998 now. RID indicates how it should be formatted and IDENTIFIER_NODE
999 ID is its name (unfortunately C and C++ hold the RID values of
1000 keywords in different places, so we can't derive RID from ID in
1001 this language independent code. LOC is the location of the
1005 fname_decl (location_t loc
, unsigned int rid
, tree id
)
1008 tree decl
= NULL_TREE
;
1010 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
1011 if (fname_vars
[ix
].rid
== rid
)
1014 decl
= *fname_vars
[ix
].decl
;
1017 /* If a tree is built here, it would normally have the lineno of
1018 the current statement. Later this tree will be moved to the
1019 beginning of the function and this line number will be wrong.
1020 To avoid this problem set the lineno to 0 here; that prevents
1021 it from appearing in the RTL. */
1023 location_t saved_location
= input_location
;
1024 input_location
= UNKNOWN_LOCATION
;
1026 stmts
= push_stmt_list ();
1027 decl
= (*make_fname_decl
) (loc
, id
, fname_vars
[ix
].pretty
);
1028 stmts
= pop_stmt_list (stmts
);
1029 if (!IS_EMPTY_STMT (stmts
))
1030 saved_function_name_decls
1031 = tree_cons (decl
, stmts
, saved_function_name_decls
);
1032 *fname_vars
[ix
].decl
= decl
;
1033 input_location
= saved_location
;
1035 if (!ix
&& !current_function_decl
)
1036 pedwarn (loc
, 0, "%qD is not defined outside of function scope", decl
);
1041 /* Given a STRING_CST, give it a suitable array-of-chars data type. */
1044 fix_string_type (tree value
)
1046 int length
= TREE_STRING_LENGTH (value
);
1048 tree e_type
, i_type
, a_type
;
1050 /* Compute the number of elements, for the array type. */
1051 if (TREE_TYPE (value
) == char_array_type_node
|| !TREE_TYPE (value
))
1054 e_type
= char_type_node
;
1056 else if (TREE_TYPE (value
) == char16_array_type_node
)
1058 nchars
= length
/ (TYPE_PRECISION (char16_type_node
) / BITS_PER_UNIT
);
1059 e_type
= char16_type_node
;
1061 else if (TREE_TYPE (value
) == char32_array_type_node
)
1063 nchars
= length
/ (TYPE_PRECISION (char32_type_node
) / BITS_PER_UNIT
);
1064 e_type
= char32_type_node
;
1068 nchars
= length
/ (TYPE_PRECISION (wchar_type_node
) / BITS_PER_UNIT
);
1069 e_type
= wchar_type_node
;
1072 /* C89 2.2.4.1, C99 5.2.4.1 (Translation limits). The analogous
1073 limit in C++98 Annex B is very large (65536) and is not normative,
1074 so we do not diagnose it (warn_overlength_strings is forced off
1075 in c_common_post_options). */
1076 if (warn_overlength_strings
)
1078 const int nchars_max
= flag_isoc99
? 4095 : 509;
1079 const int relevant_std
= flag_isoc99
? 99 : 90;
1080 if (nchars
- 1 > nchars_max
)
1081 /* Translators: The %d after 'ISO C' will be 90 or 99. Do not
1082 separate the %d from the 'C'. 'ISO' should not be
1083 translated, but it may be moved after 'C%d' in languages
1084 where modifiers follow nouns. */
1085 pedwarn (input_location
, OPT_Woverlength_strings
,
1086 "string length %qd is greater than the length %qd "
1087 "ISO C%d compilers are required to support",
1088 nchars
- 1, nchars_max
, relevant_std
);
1091 /* Create the array type for the string constant. The ISO C++
1092 standard says that a string literal has type `const char[N]' or
1093 `const wchar_t[N]'. We use the same logic when invoked as a C
1094 front-end with -Wwrite-strings.
1095 ??? We should change the type of an expression depending on the
1096 state of a warning flag. We should just be warning -- see how
1097 this is handled in the C++ front-end for the deprecated implicit
1098 conversion from string literals to `char*' or `wchar_t*'.
1100 The C++ front end relies on TYPE_MAIN_VARIANT of a cv-qualified
1101 array type being the unqualified version of that type.
1102 Therefore, if we are constructing an array of const char, we must
1103 construct the matching unqualified array type first. The C front
1104 end does not require this, but it does no harm, so we do it
1106 i_type
= build_index_type (size_int (nchars
- 1));
1107 a_type
= build_array_type (e_type
, i_type
);
1108 if (c_dialect_cxx() || warn_write_strings
)
1109 a_type
= c_build_qualified_type (a_type
, TYPE_QUAL_CONST
);
1111 TREE_TYPE (value
) = a_type
;
1112 TREE_CONSTANT (value
) = 1;
1113 TREE_READONLY (value
) = 1;
1114 TREE_STATIC (value
) = 1;
1118 /* Given a string of type STRING_TYPE, determine what kind of string
1119 token would give an equivalent execution encoding: CPP_STRING,
1120 CPP_STRING16, or CPP_STRING32. Return CPP_OTHER in case of error.
1121 This may not be exactly the string token type that initially created
1122 the string, since CPP_WSTRING is indistinguishable from the 16/32 bit
1123 string type at this point.
1125 This effectively reverses part of the logic in lex_string and
1128 static enum cpp_ttype
1129 get_cpp_ttype_from_string_type (tree string_type
)
1131 gcc_assert (string_type
);
1132 if (TREE_CODE (string_type
) == POINTER_TYPE
)
1133 string_type
= TREE_TYPE (string_type
);
1135 if (TREE_CODE (string_type
) != ARRAY_TYPE
)
1138 tree element_type
= TREE_TYPE (string_type
);
1139 if (TREE_CODE (element_type
) != INTEGER_TYPE
)
1142 int bits_per_character
= TYPE_PRECISION (element_type
);
1143 switch (bits_per_character
)
1146 return CPP_STRING
; /* It could have also been CPP_UTF8STRING. */
1148 return CPP_STRING16
;
1150 return CPP_STRING32
;
1156 /* The global record of string concatentations, for use in
1157 extracting locations within string literals. */
1159 GTY(()) string_concat_db
*g_string_concat_db
;
1161 /* Implementation of LANG_HOOKS_GET_SUBSTRING_LOCATION. */
1164 c_get_substring_location (const substring_loc
&substr_loc
,
1165 location_t
*out_loc
)
1167 enum cpp_ttype tok_type
1168 = get_cpp_ttype_from_string_type (substr_loc
.get_string_type ());
1169 if (tok_type
== CPP_OTHER
)
1170 return "unrecognized string type";
1172 return get_source_location_for_substring (parse_in
, g_string_concat_db
,
1173 substr_loc
.get_fmt_string_loc (),
1175 substr_loc
.get_caret_idx (),
1176 substr_loc
.get_start_idx (),
1177 substr_loc
.get_end_idx (),
1182 /* Fold X for consideration by one of the warning functions when checking
1183 whether an expression has a constant value. */
1186 fold_for_warn (tree x
)
1188 if (c_dialect_cxx ())
1189 return c_fully_fold (x
, /*for_init*/false, /*maybe_constp*/NULL
);
1191 /* The C front-end has already folded X appropriately. */
1195 /* Print a warning if a constant expression had overflow in folding.
1196 Invoke this function on every expression that the language
1197 requires to be a constant expression.
1198 Note the ANSI C standard says it is erroneous for a
1199 constant expression to overflow. */
1202 constant_expression_warning (tree value
)
1204 if (warn_overflow
&& pedantic
1205 && (TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1206 || TREE_CODE (value
) == FIXED_CST
1207 || TREE_CODE (value
) == VECTOR_CST
1208 || TREE_CODE (value
) == COMPLEX_CST
)
1209 && TREE_OVERFLOW (value
))
1210 pedwarn (input_location
, OPT_Woverflow
, "overflow in constant expression");
1213 /* The same as above but print an unconditional error. */
1215 constant_expression_error (tree value
)
1217 if ((TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1218 || TREE_CODE (value
) == FIXED_CST
1219 || TREE_CODE (value
) == VECTOR_CST
1220 || TREE_CODE (value
) == COMPLEX_CST
)
1221 && TREE_OVERFLOW (value
))
1222 error ("overflow in constant expression");
1225 /* Print a warning if an expression had overflow in folding and its
1228 Invoke this function on every expression that
1229 (1) appears in the source code, and
1230 (2) is a constant expression that overflowed, and
1231 (3) is not already checked by convert_and_check;
1232 however, do not invoke this function on operands of explicit casts
1233 or when the expression is the result of an operator and any operand
1234 already overflowed. */
1237 overflow_warning (location_t loc
, tree value
)
1239 if (c_inhibit_evaluation_warnings
!= 0)
1242 switch (TREE_CODE (value
))
1245 warning_at (loc
, OPT_Woverflow
, "integer overflow in expression");
1249 warning_at (loc
, OPT_Woverflow
,
1250 "floating point overflow in expression");
1254 warning_at (loc
, OPT_Woverflow
, "fixed-point overflow in expression");
1258 warning_at (loc
, OPT_Woverflow
, "vector overflow in expression");
1262 if (TREE_CODE (TREE_REALPART (value
)) == INTEGER_CST
)
1263 warning_at (loc
, OPT_Woverflow
,
1264 "complex integer overflow in expression");
1265 else if (TREE_CODE (TREE_REALPART (value
)) == REAL_CST
)
1266 warning_at (loc
, OPT_Woverflow
,
1267 "complex floating point overflow in expression");
1275 /* Warn about uses of logical || / && operator in a context where it
1276 is likely that the bitwise equivalent was intended by the
1277 programmer. We have seen an expression in which CODE is a binary
1278 operator used to combine expressions OP_LEFT and OP_RIGHT, which before folding
1279 had CODE_LEFT and CODE_RIGHT, into an expression of type TYPE. */
1281 warn_logical_operator (location_t location
, enum tree_code code
, tree type
,
1282 enum tree_code code_left
, tree op_left
,
1283 enum tree_code
ARG_UNUSED (code_right
), tree op_right
)
1285 int or_op
= (code
== TRUTH_ORIF_EXPR
|| code
== TRUTH_OR_EXPR
);
1286 int in0_p
, in1_p
, in_p
;
1287 tree low0
, low1
, low
, high0
, high1
, high
, lhs
, rhs
, tem
;
1288 bool strict_overflow_p
= false;
1290 if (code
!= TRUTH_ANDIF_EXPR
1291 && code
!= TRUTH_AND_EXPR
1292 && code
!= TRUTH_ORIF_EXPR
1293 && code
!= TRUTH_OR_EXPR
)
1296 /* We don't want to warn if either operand comes from a macro
1297 expansion. ??? This doesn't work with e.g. NEGATE_EXPR yet;
1299 if (from_macro_expansion_at (EXPR_LOCATION (op_left
))
1300 || from_macro_expansion_at (EXPR_LOCATION (op_right
)))
1303 /* Warn if &&/|| are being used in a context where it is
1304 likely that the bitwise equivalent was intended by the
1305 programmer. That is, an expression such as op && MASK
1306 where op should not be any boolean expression, nor a
1307 constant, and mask seems to be a non-boolean integer constant. */
1308 if (TREE_CODE (op_right
) == CONST_DECL
)
1309 /* An enumerator counts as a constant. */
1310 op_right
= DECL_INITIAL (op_right
);
1311 if (!truth_value_p (code_left
)
1312 && INTEGRAL_TYPE_P (TREE_TYPE (op_left
))
1313 && !CONSTANT_CLASS_P (op_left
)
1314 && !TREE_NO_WARNING (op_left
)
1315 && TREE_CODE (op_right
) == INTEGER_CST
1316 && !integer_zerop (op_right
)
1317 && !integer_onep (op_right
))
1320 warning_at (location
, OPT_Wlogical_op
, "logical %<or%>"
1321 " applied to non-boolean constant");
1323 warning_at (location
, OPT_Wlogical_op
, "logical %<and%>"
1324 " applied to non-boolean constant");
1325 TREE_NO_WARNING (op_left
) = true;
1329 /* We do not warn for constants because they are typical of macro
1330 expansions that test for features. */
1331 if (CONSTANT_CLASS_P (fold_for_warn (op_left
))
1332 || CONSTANT_CLASS_P (fold_for_warn (op_right
)))
1335 /* This warning only makes sense with logical operands. */
1336 if (!(truth_value_p (TREE_CODE (op_left
))
1337 || INTEGRAL_TYPE_P (TREE_TYPE (op_left
)))
1338 || !(truth_value_p (TREE_CODE (op_right
))
1339 || INTEGRAL_TYPE_P (TREE_TYPE (op_right
))))
1342 /* The range computations only work with scalars. */
1343 if (VECTOR_TYPE_P (TREE_TYPE (op_left
))
1344 || VECTOR_TYPE_P (TREE_TYPE (op_right
)))
1347 /* We first test whether either side separately is trivially true
1348 (with OR) or trivially false (with AND). If so, do not warn.
1349 This is a common idiom for testing ranges of data types in
1351 lhs
= make_range (op_left
, &in0_p
, &low0
, &high0
, &strict_overflow_p
);
1354 if (TREE_CODE (lhs
) == C_MAYBE_CONST_EXPR
)
1355 lhs
= C_MAYBE_CONST_EXPR_EXPR (lhs
);
1357 /* If this is an OR operation, invert both sides; now, the result
1358 should be always false to get a warning. */
1362 tem
= build_range_check (UNKNOWN_LOCATION
, type
, lhs
, in0_p
, low0
, high0
);
1363 if (tem
&& integer_zerop (tem
))
1366 rhs
= make_range (op_right
, &in1_p
, &low1
, &high1
, &strict_overflow_p
);
1369 if (TREE_CODE (rhs
) == C_MAYBE_CONST_EXPR
)
1370 rhs
= C_MAYBE_CONST_EXPR_EXPR (rhs
);
1372 /* If this is an OR operation, invert both sides; now, the result
1373 should be always false to get a warning. */
1377 tem
= build_range_check (UNKNOWN_LOCATION
, type
, rhs
, in1_p
, low1
, high1
);
1378 if (tem
&& integer_zerop (tem
))
1381 /* If both expressions have the same operand, if we can merge the
1383 if (operand_equal_p (lhs
, rhs
, 0)
1384 && merge_ranges (&in_p
, &low
, &high
, in0_p
, low0
, high0
,
1385 in1_p
, low1
, high1
))
1387 tem
= build_range_check (UNKNOWN_LOCATION
, type
, lhs
, in_p
, low
, high
);
1388 /* ... and if the range test is always false, then warn. */
1389 if (tem
&& integer_zerop (tem
))
1392 warning_at (location
, OPT_Wlogical_op
,
1393 "logical %<or%> of collectively exhaustive tests is "
1396 warning_at (location
, OPT_Wlogical_op
,
1397 "logical %<and%> of mutually exclusive tests is "
1400 /* Or warn if the operands have exactly the same range, e.g.
1402 else if (tree_int_cst_equal (low0
, low1
)
1403 && tree_int_cst_equal (high0
, high1
))
1406 warning_at (location
, OPT_Wlogical_op
,
1407 "logical %<or%> of equal expressions");
1409 warning_at (location
, OPT_Wlogical_op
,
1410 "logical %<and%> of equal expressions");
1415 /* Helper function for warn_tautological_cmp. Look for ARRAY_REFs
1416 with constant indices. */
1419 find_array_ref_with_const_idx_r (tree
*expr_p
, int *walk_subtrees
, void *data
)
1421 tree expr
= *expr_p
;
1423 if ((TREE_CODE (expr
) == ARRAY_REF
1424 || TREE_CODE (expr
) == ARRAY_RANGE_REF
)
1425 && TREE_CODE (TREE_OPERAND (expr
, 1)) == INTEGER_CST
)
1427 *(bool *) data
= true;
1434 /* Warn if a self-comparison always evaluates to true or false. LOC
1435 is the location of the comparison with code CODE, LHS and RHS are
1436 operands of the comparison. */
1439 warn_tautological_cmp (location_t loc
, enum tree_code code
, tree lhs
, tree rhs
)
1441 if (TREE_CODE_CLASS (code
) != tcc_comparison
)
1444 /* Don't warn for various macro expansions. */
1445 if (from_macro_expansion_at (loc
)
1446 || from_macro_expansion_at (EXPR_LOCATION (lhs
))
1447 || from_macro_expansion_at (EXPR_LOCATION (rhs
)))
1450 /* We do not warn for constants because they are typical of macro
1451 expansions that test for features, sizeof, and similar. */
1452 if (CONSTANT_CLASS_P (fold_for_warn (lhs
))
1453 || CONSTANT_CLASS_P (fold_for_warn (rhs
)))
1456 /* Don't warn for e.g.
1459 if (n == (long) n) ...
1461 if ((CONVERT_EXPR_P (lhs
) || TREE_CODE (lhs
) == NON_LVALUE_EXPR
)
1462 || (CONVERT_EXPR_P (rhs
) || TREE_CODE (rhs
) == NON_LVALUE_EXPR
))
1465 /* Don't warn if either LHS or RHS has an IEEE floating-point type.
1466 It could be a NaN, and NaN never compares equal to anything, even
1468 if (FLOAT_TYPE_P (TREE_TYPE (lhs
)) || FLOAT_TYPE_P (TREE_TYPE (rhs
)))
1471 if (operand_equal_p (lhs
, rhs
, 0))
1473 /* Don't warn about array references with constant indices;
1474 these are likely to come from a macro. */
1476 walk_tree_without_duplicates (&lhs
, find_array_ref_with_const_idx_r
,
1480 const bool always_true
= (code
== EQ_EXPR
|| code
== LE_EXPR
1481 || code
== GE_EXPR
|| code
== UNLE_EXPR
1482 || code
== UNGE_EXPR
|| code
== UNEQ_EXPR
);
1484 warning_at (loc
, OPT_Wtautological_compare
,
1485 "self-comparison always evaluates to true");
1487 warning_at (loc
, OPT_Wtautological_compare
,
1488 "self-comparison always evaluates to false");
1492 /* Return true iff T is a boolean promoted to int. */
1495 bool_promoted_to_int_p (tree t
)
1497 return (CONVERT_EXPR_P (t
)
1498 && TREE_TYPE (t
) == integer_type_node
1499 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == BOOLEAN_TYPE
);
1502 /* Return true iff EXPR only contains boolean operands, or comparisons. */
1505 expr_has_boolean_operands_p (tree expr
)
1509 if (CONVERT_EXPR_P (expr
))
1510 return bool_promoted_to_int_p (expr
);
1511 else if (UNARY_CLASS_P (expr
))
1512 return expr_has_boolean_operands_p (TREE_OPERAND (expr
, 0));
1513 else if (BINARY_CLASS_P (expr
))
1514 return (expr_has_boolean_operands_p (TREE_OPERAND (expr
, 0))
1515 && expr_has_boolean_operands_p (TREE_OPERAND (expr
, 1)));
1516 else if (COMPARISON_CLASS_P (expr
))
1522 /* Warn about logical not used on the left hand side operand of a comparison.
1523 This function assumes that the LHS is inside of TRUTH_NOT_EXPR.
1524 Do not warn if RHS is of a boolean type, a logical operator, or
1528 warn_logical_not_parentheses (location_t location
, enum tree_code code
,
1531 if (TREE_CODE_CLASS (code
) != tcc_comparison
1532 || TREE_TYPE (rhs
) == NULL_TREE
1533 || TREE_CODE (TREE_TYPE (rhs
)) == BOOLEAN_TYPE
1534 || truth_value_p (TREE_CODE (rhs
)))
1537 /* Don't warn for expression like !x == ~(bool1 | bool2). */
1538 if (expr_has_boolean_operands_p (rhs
))
1541 /* Don't warn for !x == 0 or !y != 0, those are equivalent to
1542 !(x == 0) or !(y != 0). */
1543 if ((code
== EQ_EXPR
|| code
== NE_EXPR
)
1544 && integer_zerop (rhs
))
1547 if (warning_at (location
, OPT_Wlogical_not_parentheses
,
1548 "logical not is only applied to the left hand side of "
1550 && EXPR_HAS_LOCATION (lhs
))
1552 location_t lhs_loc
= EXPR_LOCATION (lhs
);
1553 rich_location
richloc (line_table
, lhs_loc
);
1554 richloc
.add_fixit_insert_before (lhs_loc
, "(");
1555 richloc
.add_fixit_insert_after (lhs_loc
, ")");
1556 inform_at_rich_loc (&richloc
, "add parentheses around left hand side "
1557 "expression to silence this warning");
1561 /* Warn if EXP contains any computations whose results are not used.
1562 Return true if a warning is printed; false otherwise. LOCUS is the
1563 (potential) location of the expression. */
1566 warn_if_unused_value (const_tree exp
, location_t locus
)
1569 if (TREE_USED (exp
) || TREE_NO_WARNING (exp
))
1572 /* Don't warn about void constructs. This includes casting to void,
1573 void function calls, and statement expressions with a final cast
1575 if (VOID_TYPE_P (TREE_TYPE (exp
)))
1578 if (EXPR_HAS_LOCATION (exp
))
1579 locus
= EXPR_LOCATION (exp
);
1581 switch (TREE_CODE (exp
))
1583 case PREINCREMENT_EXPR
:
1584 case POSTINCREMENT_EXPR
:
1585 case PREDECREMENT_EXPR
:
1586 case POSTDECREMENT_EXPR
:
1591 case TRY_CATCH_EXPR
:
1592 case WITH_CLEANUP_EXPR
:
1598 /* For a binding, warn if no side effect within it. */
1599 exp
= BIND_EXPR_BODY (exp
);
1603 case NON_LVALUE_EXPR
:
1605 exp
= TREE_OPERAND (exp
, 0);
1608 case TRUTH_ORIF_EXPR
:
1609 case TRUTH_ANDIF_EXPR
:
1610 /* In && or ||, warn if 2nd operand has no side effect. */
1611 exp
= TREE_OPERAND (exp
, 1);
1615 if (warn_if_unused_value (TREE_OPERAND (exp
, 0), locus
))
1617 /* Let people do `(foo (), 0)' without a warning. */
1618 if (TREE_CONSTANT (TREE_OPERAND (exp
, 1)))
1620 exp
= TREE_OPERAND (exp
, 1);
1624 /* If this is an expression with side effects, don't warn; this
1625 case commonly appears in macro expansions. */
1626 if (TREE_SIDE_EFFECTS (exp
))
1631 /* Don't warn about automatic dereferencing of references, since
1632 the user cannot control it. */
1633 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == REFERENCE_TYPE
)
1635 exp
= TREE_OPERAND (exp
, 0);
1641 /* Referencing a volatile value is a side effect, so don't warn. */
1642 if ((DECL_P (exp
) || REFERENCE_CLASS_P (exp
))
1643 && TREE_THIS_VOLATILE (exp
))
1646 /* If this is an expression which has no operands, there is no value
1647 to be unused. There are no such language-independent codes,
1648 but front ends may define such. */
1649 if (EXPRESSION_CLASS_P (exp
) && TREE_OPERAND_LENGTH (exp
) == 0)
1653 return warning_at (locus
, OPT_Wunused_value
, "value computed is not used");
1658 /* Print a warning about casts that might indicate violation
1659 of strict aliasing rules if -Wstrict-aliasing is used and
1660 strict aliasing mode is in effect. OTYPE is the original
1661 TREE_TYPE of EXPR, and TYPE the type we're casting to. */
1664 strict_aliasing_warning (tree otype
, tree type
, tree expr
)
1666 /* Strip pointer conversion chains and get to the correct original type. */
1668 otype
= TREE_TYPE (expr
);
1670 if (!(flag_strict_aliasing
1671 && POINTER_TYPE_P (type
)
1672 && POINTER_TYPE_P (otype
)
1673 && !VOID_TYPE_P (TREE_TYPE (type
)))
1674 /* If the type we are casting to is a ref-all pointer
1675 dereferencing it is always valid. */
1676 || TYPE_REF_CAN_ALIAS_ALL (type
))
1679 if ((warn_strict_aliasing
> 1) && TREE_CODE (expr
) == ADDR_EXPR
1680 && (DECL_P (TREE_OPERAND (expr
, 0))
1681 || handled_component_p (TREE_OPERAND (expr
, 0))))
1683 /* Casting the address of an object to non void pointer. Warn
1684 if the cast breaks type based aliasing. */
1685 if (!COMPLETE_TYPE_P (TREE_TYPE (type
)) && warn_strict_aliasing
== 2)
1687 warning (OPT_Wstrict_aliasing
, "type-punning to incomplete type "
1688 "might break strict-aliasing rules");
1693 /* warn_strict_aliasing >= 3. This includes the default (3).
1694 Only warn if the cast is dereferenced immediately. */
1695 alias_set_type set1
=
1696 get_alias_set (TREE_TYPE (TREE_OPERAND (expr
, 0)));
1697 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
1699 if (set1
!= set2
&& set2
!= 0
1701 || (!alias_set_subset_of (set2
, set1
)
1702 && !alias_sets_conflict_p (set1
, set2
))))
1704 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1705 "pointer will break strict-aliasing rules");
1708 else if (warn_strict_aliasing
== 2
1709 && !alias_sets_must_conflict_p (set1
, set2
))
1711 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1712 "pointer might break strict-aliasing rules");
1718 if ((warn_strict_aliasing
== 1) && !VOID_TYPE_P (TREE_TYPE (otype
)))
1720 /* At this level, warn for any conversions, even if an address is
1721 not taken in the same statement. This will likely produce many
1722 false positives, but could be useful to pinpoint problems that
1723 are not revealed at higher levels. */
1724 alias_set_type set1
= get_alias_set (TREE_TYPE (otype
));
1725 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
1726 if (!COMPLETE_TYPE_P (type
)
1727 || !alias_sets_must_conflict_p (set1
, set2
))
1729 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1730 "pointer might break strict-aliasing rules");
1738 /* Warn about memset (&a, 0, sizeof (&a)); and similar mistakes with
1739 sizeof as last operand of certain builtins. */
1742 sizeof_pointer_memaccess_warning (location_t
*sizeof_arg_loc
, tree callee
,
1743 vec
<tree
, va_gc
> *params
, tree
*sizeof_arg
,
1744 bool (*comp_types
) (tree
, tree
))
1746 tree type
, dest
= NULL_TREE
, src
= NULL_TREE
, tem
;
1747 bool strop
= false, cmp
= false;
1748 unsigned int idx
= ~0;
1751 if (TREE_CODE (callee
) != FUNCTION_DECL
1752 || DECL_BUILT_IN_CLASS (callee
) != BUILT_IN_NORMAL
1753 || vec_safe_length (params
) <= 1)
1756 switch (DECL_FUNCTION_CODE (callee
))
1758 case BUILT_IN_STRNCMP
:
1759 case BUILT_IN_STRNCASECMP
:
1762 case BUILT_IN_STRNCPY
:
1763 case BUILT_IN_STRNCPY_CHK
:
1764 case BUILT_IN_STRNCAT
:
1765 case BUILT_IN_STRNCAT_CHK
:
1766 case BUILT_IN_STPNCPY
:
1767 case BUILT_IN_STPNCPY_CHK
:
1770 case BUILT_IN_MEMCPY
:
1771 case BUILT_IN_MEMCPY_CHK
:
1772 case BUILT_IN_MEMMOVE
:
1773 case BUILT_IN_MEMMOVE_CHK
:
1774 if (params
->length () < 3)
1777 dest
= (*params
)[0];
1780 case BUILT_IN_BCOPY
:
1781 if (params
->length () < 3)
1784 dest
= (*params
)[1];
1787 case BUILT_IN_MEMCMP
:
1789 if (params
->length () < 3)
1792 dest
= (*params
)[0];
1796 case BUILT_IN_MEMSET
:
1797 case BUILT_IN_MEMSET_CHK
:
1798 if (params
->length () < 3)
1800 dest
= (*params
)[0];
1803 case BUILT_IN_BZERO
:
1804 dest
= (*params
)[0];
1807 case BUILT_IN_STRNDUP
:
1812 case BUILT_IN_MEMCHR
:
1813 if (params
->length () < 3)
1818 case BUILT_IN_SNPRINTF
:
1819 case BUILT_IN_SNPRINTF_CHK
:
1820 case BUILT_IN_VSNPRINTF
:
1821 case BUILT_IN_VSNPRINTF_CHK
:
1822 dest
= (*params
)[0];
1833 if (sizeof_arg
[idx
] == NULL
|| sizeof_arg
[idx
] == error_mark_node
)
1836 type
= TYPE_P (sizeof_arg
[idx
])
1837 ? sizeof_arg
[idx
] : TREE_TYPE (sizeof_arg
[idx
]);
1838 if (!POINTER_TYPE_P (type
))
1842 && (tem
= tree_strip_nop_conversions (dest
))
1843 && POINTER_TYPE_P (TREE_TYPE (tem
))
1844 && comp_types (TREE_TYPE (TREE_TYPE (tem
)), type
))
1848 && (tem
= tree_strip_nop_conversions (src
))
1849 && POINTER_TYPE_P (TREE_TYPE (tem
))
1850 && comp_types (TREE_TYPE (TREE_TYPE (tem
)), type
))
1853 loc
= sizeof_arg_loc
[idx
];
1857 if (!TYPE_P (sizeof_arg
[idx
])
1858 && operand_equal_p (dest
, sizeof_arg
[idx
], 0)
1859 && comp_types (TREE_TYPE (dest
), type
))
1861 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
1862 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1863 "argument to %<sizeof%> in %qD call is the same "
1864 "expression as the destination; did you mean to "
1865 "remove the addressof?", callee
);
1866 else if ((TYPE_PRECISION (TREE_TYPE (type
))
1867 == TYPE_PRECISION (char_type_node
))
1869 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1870 "argument to %<sizeof%> in %qD call is the same "
1871 "expression as the destination; did you mean to "
1872 "provide an explicit length?", callee
);
1874 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1875 "argument to %<sizeof%> in %qD call is the same "
1876 "expression as the destination; did you mean to "
1877 "dereference it?", callee
);
1881 if (POINTER_TYPE_P (TREE_TYPE (dest
))
1883 && comp_types (TREE_TYPE (dest
), type
)
1884 && !VOID_TYPE_P (TREE_TYPE (type
)))
1886 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1887 "argument to %<sizeof%> in %qD call is the same "
1888 "pointer type %qT as the destination; expected %qT "
1889 "or an explicit length", callee
, TREE_TYPE (dest
),
1890 TREE_TYPE (TREE_TYPE (dest
)));
1897 if (!TYPE_P (sizeof_arg
[idx
])
1898 && operand_equal_p (src
, sizeof_arg
[idx
], 0)
1899 && comp_types (TREE_TYPE (src
), type
))
1901 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
1902 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1903 "argument to %<sizeof%> in %qD call is the same "
1904 "expression as the source; did you mean to "
1905 "remove the addressof?", callee
);
1906 else if ((TYPE_PRECISION (TREE_TYPE (type
))
1907 == TYPE_PRECISION (char_type_node
))
1909 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1910 "argument to %<sizeof%> in %qD call is the same "
1911 "expression as the source; did you mean to "
1912 "provide an explicit length?", callee
);
1914 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1915 "argument to %<sizeof%> in %qD call is the same "
1916 "expression as the source; did you mean to "
1917 "dereference it?", callee
);
1921 if (POINTER_TYPE_P (TREE_TYPE (src
))
1923 && comp_types (TREE_TYPE (src
), type
)
1924 && !VOID_TYPE_P (TREE_TYPE (type
)))
1926 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1927 "argument to %<sizeof%> in %qD call is the same "
1928 "pointer type %qT as the source; expected %qT "
1929 "or an explicit length", callee
, TREE_TYPE (src
),
1930 TREE_TYPE (TREE_TYPE (src
)));
1937 if (!TYPE_P (sizeof_arg
[idx
])
1938 && operand_equal_p (dest
, sizeof_arg
[idx
], 0)
1939 && comp_types (TREE_TYPE (dest
), type
))
1941 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
1942 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1943 "argument to %<sizeof%> in %qD call is the same "
1944 "expression as the first source; did you mean to "
1945 "remove the addressof?", callee
);
1946 else if ((TYPE_PRECISION (TREE_TYPE (type
))
1947 == TYPE_PRECISION (char_type_node
))
1949 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1950 "argument to %<sizeof%> in %qD call is the same "
1951 "expression as the first source; did you mean to "
1952 "provide an explicit length?", callee
);
1954 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1955 "argument to %<sizeof%> in %qD call is the same "
1956 "expression as the first source; did you mean to "
1957 "dereference it?", callee
);
1961 if (POINTER_TYPE_P (TREE_TYPE (dest
))
1963 && comp_types (TREE_TYPE (dest
), type
)
1964 && !VOID_TYPE_P (TREE_TYPE (type
)))
1966 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1967 "argument to %<sizeof%> in %qD call is the same "
1968 "pointer type %qT as the first source; expected %qT "
1969 "or an explicit length", callee
, TREE_TYPE (dest
),
1970 TREE_TYPE (TREE_TYPE (dest
)));
1977 if (!TYPE_P (sizeof_arg
[idx
])
1978 && operand_equal_p (src
, sizeof_arg
[idx
], 0)
1979 && comp_types (TREE_TYPE (src
), type
))
1981 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
1982 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1983 "argument to %<sizeof%> in %qD call is the same "
1984 "expression as the second source; did you mean to "
1985 "remove the addressof?", callee
);
1986 else if ((TYPE_PRECISION (TREE_TYPE (type
))
1987 == TYPE_PRECISION (char_type_node
))
1989 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1990 "argument to %<sizeof%> in %qD call is the same "
1991 "expression as the second source; did you mean to "
1992 "provide an explicit length?", callee
);
1994 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1995 "argument to %<sizeof%> in %qD call is the same "
1996 "expression as the second source; did you mean to "
1997 "dereference it?", callee
);
2001 if (POINTER_TYPE_P (TREE_TYPE (src
))
2003 && comp_types (TREE_TYPE (src
), type
)
2004 && !VOID_TYPE_P (TREE_TYPE (type
)))
2006 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2007 "argument to %<sizeof%> in %qD call is the same "
2008 "pointer type %qT as the second source; expected %qT "
2009 "or an explicit length", callee
, TREE_TYPE (src
),
2010 TREE_TYPE (TREE_TYPE (src
)));
2017 /* Warn for unlikely, improbable, or stupid DECL declarations
2021 check_main_parameter_types (tree decl
)
2023 function_args_iterator iter
;
2027 FOREACH_FUNCTION_ARGS (TREE_TYPE (decl
), type
, iter
)
2029 /* XXX void_type_node belies the abstraction. */
2030 if (type
== void_type_node
|| type
== error_mark_node
)
2034 if (TYPE_ATOMIC (t
))
2035 pedwarn (input_location
, OPT_Wmain
,
2036 "%<_Atomic%>-qualified parameter type %qT of %q+D",
2038 while (POINTER_TYPE_P (t
))
2041 if (TYPE_ATOMIC (t
))
2042 pedwarn (input_location
, OPT_Wmain
,
2043 "%<_Atomic%>-qualified parameter type %qT of %q+D",
2051 if (TYPE_MAIN_VARIANT (type
) != integer_type_node
)
2052 pedwarn (input_location
, OPT_Wmain
,
2053 "first argument of %q+D should be %<int%>", decl
);
2057 if (TREE_CODE (type
) != POINTER_TYPE
2058 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
2059 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
2061 pedwarn (input_location
, OPT_Wmain
,
2062 "second argument of %q+D should be %<char **%>", decl
);
2066 if (TREE_CODE (type
) != POINTER_TYPE
2067 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
2068 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
2070 pedwarn (input_location
, OPT_Wmain
,
2071 "third argument of %q+D should probably be "
2072 "%<char **%>", decl
);
2077 /* It is intentional that this message does not mention the third
2078 argument because it's only mentioned in an appendix of the
2080 if (argct
> 0 && (argct
< 2 || argct
> 3))
2081 pedwarn (input_location
, OPT_Wmain
,
2082 "%q+D takes only zero or two arguments", decl
);
2084 if (stdarg_p (TREE_TYPE (decl
)))
2085 pedwarn (input_location
, OPT_Wmain
,
2086 "%q+D declared as variadic function", decl
);
2089 /* vector_targets_convertible_p is used for vector pointer types. The
2090 callers perform various checks that the qualifiers are satisfactory,
2091 while OTOH vector_targets_convertible_p ignores the number of elements
2092 in the vectors. That's fine with vector pointers as we can consider,
2093 say, a vector of 8 elements as two consecutive vectors of 4 elements,
2094 and that does not require and conversion of the pointer values.
2095 In contrast, vector_types_convertible_p and
2096 vector_types_compatible_elements_p are used for vector value types. */
2097 /* True if pointers to distinct types T1 and T2 can be converted to
2098 each other without an explicit cast. Only returns true for opaque
2101 vector_targets_convertible_p (const_tree t1
, const_tree t2
)
2103 if (VECTOR_TYPE_P (t1
) && VECTOR_TYPE_P (t2
)
2104 && (TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2105 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2111 /* vector_types_convertible_p is used for vector value types.
2112 It could in principle call vector_targets_convertible_p as a subroutine,
2113 but then the check for vector type would be duplicated with its callers,
2114 and also the purpose of vector_targets_convertible_p would become
2116 Where vector_types_convertible_p returns true, a conversion might still be
2117 needed to make the types match.
2118 In contrast, vector_targets_convertible_p is used for vector pointer
2119 values, and vector_types_compatible_elements_p is used specifically
2120 in the context for binary operators, as a check if use is possible without
2122 /* True if vector types T1 and T2 can be converted to each other
2123 without an explicit cast. If EMIT_LAX_NOTE is true, and T1 and T2
2124 can only be converted with -flax-vector-conversions yet that is not
2125 in effect, emit a note telling the user about that option if such
2126 a note has not previously been emitted. */
2128 vector_types_convertible_p (const_tree t1
, const_tree t2
, bool emit_lax_note
)
2130 static bool emitted_lax_note
= false;
2131 bool convertible_lax
;
2133 if ((TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2134 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2138 (tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
))
2139 && (TREE_CODE (TREE_TYPE (t1
)) != REAL_TYPE
||
2140 TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
))
2141 && (INTEGRAL_TYPE_P (TREE_TYPE (t1
))
2142 == INTEGRAL_TYPE_P (TREE_TYPE (t2
))));
2144 if (!convertible_lax
|| flag_lax_vector_conversions
)
2145 return convertible_lax
;
2147 if (TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
)
2148 && lang_hooks
.types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
2151 if (emit_lax_note
&& !emitted_lax_note
)
2153 emitted_lax_note
= true;
2154 inform (input_location
, "use -flax-vector-conversions to permit "
2155 "conversions between vectors with differing "
2156 "element types or numbers of subparts");
2162 /* Build a VEC_PERM_EXPR if V0, V1 and MASK are not error_mark_nodes
2163 and have vector types, V0 has the same type as V1, and the number of
2164 elements of V0, V1, MASK is the same.
2166 In case V1 is a NULL_TREE it is assumed that __builtin_shuffle was
2167 called with two arguments. In this case implementation passes the
2168 first argument twice in order to share the same tree code. This fact
2169 could enable the mask-values being twice the vector length. This is
2170 an implementation accident and this semantics is not guaranteed to
2173 c_build_vec_perm_expr (location_t loc
, tree v0
, tree v1
, tree mask
,
2178 bool maybe_const
= false;
2179 bool two_arguments
= false;
2181 if (v1
== NULL_TREE
)
2183 two_arguments
= true;
2187 if (v0
== error_mark_node
|| v1
== error_mark_node
2188 || mask
== error_mark_node
)
2189 return error_mark_node
;
2191 if (!VECTOR_INTEGER_TYPE_P (TREE_TYPE (mask
)))
2194 error_at (loc
, "__builtin_shuffle last argument must "
2195 "be an integer vector");
2196 return error_mark_node
;
2199 if (!VECTOR_TYPE_P (TREE_TYPE (v0
))
2200 || !VECTOR_TYPE_P (TREE_TYPE (v1
)))
2203 error_at (loc
, "__builtin_shuffle arguments must be vectors");
2204 return error_mark_node
;
2207 if (TYPE_MAIN_VARIANT (TREE_TYPE (v0
)) != TYPE_MAIN_VARIANT (TREE_TYPE (v1
)))
2210 error_at (loc
, "__builtin_shuffle argument vectors must be of "
2212 return error_mark_node
;
2215 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (v0
))
2216 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
))
2217 && TYPE_VECTOR_SUBPARTS (TREE_TYPE (v1
))
2218 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
)))
2221 error_at (loc
, "__builtin_shuffle number of elements of the "
2222 "argument vector(s) and the mask vector should "
2224 return error_mark_node
;
2227 if (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (v0
))))
2228 != GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (mask
)))))
2231 error_at (loc
, "__builtin_shuffle argument vector(s) inner type "
2232 "must have the same size as inner type of the mask");
2233 return error_mark_node
;
2236 if (!c_dialect_cxx ())
2238 /* Avoid C_MAYBE_CONST_EXPRs inside VEC_PERM_EXPR. */
2239 v0
= c_fully_fold (v0
, false, &maybe_const
);
2240 wrap
&= maybe_const
;
2243 v1
= v0
= save_expr (v0
);
2246 v1
= c_fully_fold (v1
, false, &maybe_const
);
2247 wrap
&= maybe_const
;
2250 mask
= c_fully_fold (mask
, false, &maybe_const
);
2251 wrap
&= maybe_const
;
2253 else if (two_arguments
)
2254 v1
= v0
= save_expr (v0
);
2256 ret
= build3_loc (loc
, VEC_PERM_EXPR
, TREE_TYPE (v0
), v0
, v1
, mask
);
2258 if (!c_dialect_cxx () && !wrap
)
2259 ret
= c_wrap_maybe_const (ret
, true);
2264 /* Like tree.c:get_narrower, but retain conversion from C++0x scoped enum
2265 to integral type. */
2268 c_common_get_narrower (tree op
, int *unsignedp_ptr
)
2270 op
= get_narrower (op
, unsignedp_ptr
);
2272 if (TREE_CODE (TREE_TYPE (op
)) == ENUMERAL_TYPE
2273 && ENUM_IS_SCOPED (TREE_TYPE (op
)))
2275 /* C++0x scoped enumerations don't implicitly convert to integral
2276 type; if we stripped an explicit conversion to a larger type we
2277 need to replace it so common_type will still work. */
2278 tree type
= c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op
)),
2279 TYPE_UNSIGNED (TREE_TYPE (op
)));
2280 op
= fold_convert (type
, op
);
2285 /* This is a helper function of build_binary_op.
2287 For certain operations if both args were extended from the same
2288 smaller type, do the arithmetic in that type and then extend.
2290 BITWISE indicates a bitwise operation.
2291 For them, this optimization is safe only if
2292 both args are zero-extended or both are sign-extended.
2293 Otherwise, we might change the result.
2294 Eg, (short)-1 | (unsigned short)-1 is (int)-1
2295 but calculated in (unsigned short) it would be (unsigned short)-1.
2298 shorten_binary_op (tree result_type
, tree op0
, tree op1
, bool bitwise
)
2300 int unsigned0
, unsigned1
;
2305 /* Cast OP0 and OP1 to RESULT_TYPE. Doing so prevents
2306 excessive narrowing when we call get_narrower below. For
2307 example, suppose that OP0 is of unsigned int extended
2308 from signed char and that RESULT_TYPE is long long int.
2309 If we explicitly cast OP0 to RESULT_TYPE, OP0 would look
2312 (long long int) (unsigned int) signed_char
2314 which get_narrower would narrow down to
2316 (unsigned int) signed char
2318 If we do not cast OP0 first, get_narrower would return
2319 signed_char, which is inconsistent with the case of the
2321 op0
= convert (result_type
, op0
);
2322 op1
= convert (result_type
, op1
);
2324 arg0
= c_common_get_narrower (op0
, &unsigned0
);
2325 arg1
= c_common_get_narrower (op1
, &unsigned1
);
2327 /* UNS is 1 if the operation to be done is an unsigned one. */
2328 uns
= TYPE_UNSIGNED (result_type
);
2330 /* Handle the case that OP0 (or OP1) does not *contain* a conversion
2331 but it *requires* conversion to FINAL_TYPE. */
2333 if ((TYPE_PRECISION (TREE_TYPE (op0
))
2334 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2335 && TREE_TYPE (op0
) != result_type
)
2336 unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2337 if ((TYPE_PRECISION (TREE_TYPE (op1
))
2338 == TYPE_PRECISION (TREE_TYPE (arg1
)))
2339 && TREE_TYPE (op1
) != result_type
)
2340 unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2342 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
2344 /* For bitwise operations, signedness of nominal type
2345 does not matter. Consider only how operands were extended. */
2349 /* Note that in all three cases below we refrain from optimizing
2350 an unsigned operation on sign-extended args.
2351 That would not be valid. */
2353 /* Both args variable: if both extended in same way
2354 from same width, do it in that width.
2355 Do it unsigned if args were zero-extended. */
2356 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
2357 < TYPE_PRECISION (result_type
))
2358 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2359 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2360 && unsigned0
== unsigned1
2361 && (unsigned0
|| !uns
))
2362 return c_common_signed_or_unsigned_type
2363 (unsigned0
, common_type (TREE_TYPE (arg0
), TREE_TYPE (arg1
)));
2365 else if (TREE_CODE (arg0
) == INTEGER_CST
2366 && (unsigned1
|| !uns
)
2367 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2368 < TYPE_PRECISION (result_type
))
2370 = c_common_signed_or_unsigned_type (unsigned1
,
2372 && !POINTER_TYPE_P (type
)
2373 && int_fits_type_p (arg0
, type
))
2376 else if (TREE_CODE (arg1
) == INTEGER_CST
2377 && (unsigned0
|| !uns
)
2378 && (TYPE_PRECISION (TREE_TYPE (arg0
))
2379 < TYPE_PRECISION (result_type
))
2381 = c_common_signed_or_unsigned_type (unsigned0
,
2383 && !POINTER_TYPE_P (type
)
2384 && int_fits_type_p (arg1
, type
))
2390 /* Returns true iff any integer value of type FROM_TYPE can be represented as
2391 real of type TO_TYPE. This is a helper function for unsafe_conversion_p. */
2394 int_safely_convertible_to_real_p (const_tree from_type
, const_tree to_type
)
2396 tree type_low_bound
= TYPE_MIN_VALUE (from_type
);
2397 tree type_high_bound
= TYPE_MAX_VALUE (from_type
);
2398 REAL_VALUE_TYPE real_low_bound
=
2399 real_value_from_int_cst (0, type_low_bound
);
2400 REAL_VALUE_TYPE real_high_bound
=
2401 real_value_from_int_cst (0, type_high_bound
);
2403 return exact_real_truncate (TYPE_MODE (to_type
), &real_low_bound
)
2404 && exact_real_truncate (TYPE_MODE (to_type
), &real_high_bound
);
2407 /* Checks if expression EXPR of complex/real/integer type cannot be converted
2408 to the complex/real/integer type TYPE. Function returns non-zero when:
2409 * EXPR is a constant which cannot be exactly converted to TYPE.
2410 * EXPR is not a constant and size of EXPR's type > than size of TYPE,
2411 for EXPR type and TYPE being both integers or both real, or both
2413 * EXPR is not a constant of complex type and TYPE is a real or
2415 * EXPR is not a constant of real type and TYPE is an integer.
2416 * EXPR is not a constant of integer type which cannot be
2417 exactly converted to real type.
2419 Function allows conversions between types of different signedness and
2420 can return SAFE_CONVERSION (zero) in that case. Function can produce
2421 signedness warnings if PRODUCE_WARNS is true.
2423 Function allows conversions from complex constants to non-complex types,
2424 provided that imaginary part is zero and real part can be safely converted
2427 enum conversion_safety
2428 unsafe_conversion_p (location_t loc
, tree type
, tree expr
, bool produce_warns
)
2430 enum conversion_safety give_warning
= SAFE_CONVERSION
; /* is 0 or false */
2431 tree expr_type
= TREE_TYPE (expr
);
2432 loc
= expansion_point_location_if_in_system_header (loc
);
2434 if (TREE_CODE (expr
) == REAL_CST
|| TREE_CODE (expr
) == INTEGER_CST
)
2436 /* If type is complex, we are interested in compatibility with
2438 if (TREE_CODE (type
) == COMPLEX_TYPE
)
2439 type
= TREE_TYPE (type
);
2441 /* Warn for real constant that is not an exact integer converted
2443 if (TREE_CODE (expr_type
) == REAL_TYPE
2444 && TREE_CODE (type
) == INTEGER_TYPE
)
2446 if (!real_isinteger (TREE_REAL_CST_PTR (expr
), TYPE_MODE (expr_type
)))
2447 give_warning
= UNSAFE_REAL
;
2449 /* Warn for an integer constant that does not fit into integer type. */
2450 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2451 && TREE_CODE (type
) == INTEGER_TYPE
2452 && !int_fits_type_p (expr
, type
))
2454 if (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)
2455 && tree_int_cst_sgn (expr
) < 0)
2458 warning_at (loc
, OPT_Wsign_conversion
, "negative integer"
2459 " implicitly converted to unsigned type");
2461 else if (!TYPE_UNSIGNED (type
) && TYPE_UNSIGNED (expr_type
))
2464 warning_at (loc
, OPT_Wsign_conversion
, "conversion of unsigned"
2465 " constant value to negative integer");
2468 give_warning
= UNSAFE_OTHER
;
2470 else if (TREE_CODE (type
) == REAL_TYPE
)
2472 /* Warn for an integer constant that does not fit into real type. */
2473 if (TREE_CODE (expr_type
) == INTEGER_TYPE
)
2475 REAL_VALUE_TYPE a
= real_value_from_int_cst (0, expr
);
2476 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2477 give_warning
= UNSAFE_REAL
;
2479 /* Warn for a real constant that does not fit into a smaller
2481 else if (TREE_CODE (expr_type
) == REAL_TYPE
2482 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2484 REAL_VALUE_TYPE a
= TREE_REAL_CST (expr
);
2485 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2486 give_warning
= UNSAFE_REAL
;
2491 else if (TREE_CODE (expr
) == COMPLEX_CST
)
2493 tree imag_part
= TREE_IMAGPART (expr
);
2494 /* Conversion from complex constant with zero imaginary part,
2495 perform check for conversion of real part. */
2496 if ((TREE_CODE (imag_part
) == REAL_CST
2497 && real_zerop (imag_part
))
2498 || (TREE_CODE (imag_part
) == INTEGER_CST
2499 && integer_zerop (imag_part
)))
2500 /* Note: in this branch we use recursive call to unsafe_conversion_p
2501 with different type of EXPR, but it is still safe, because when EXPR
2502 is a constant, it's type is not used in text of generated warnings
2503 (otherwise they could sound misleading). */
2504 return unsafe_conversion_p (loc
, type
, TREE_REALPART (expr
),
2506 /* Conversion from complex constant with non-zero imaginary part. */
2509 /* Conversion to complex type.
2510 Perform checks for both real and imaginary parts. */
2511 if (TREE_CODE (type
) == COMPLEX_TYPE
)
2513 /* Unfortunately, produce_warns must be false in two subsequent
2514 calls of unsafe_conversion_p, because otherwise we could
2515 produce strange "double" warnings, if both real and imaginary
2516 parts have conversion problems related to signedness.
2519 int32_t _Complex a = 0x80000000 + 0x80000000i;
2521 Possible solution: add a separate function for checking
2522 constants and combine result of two calls appropriately. */
2523 enum conversion_safety re_safety
=
2524 unsafe_conversion_p (loc
, type
, TREE_REALPART (expr
), false);
2525 enum conversion_safety im_safety
=
2526 unsafe_conversion_p (loc
, type
, imag_part
, false);
2528 /* Merge the results into appropriate single warning. */
2530 /* Note: this case includes SAFE_CONVERSION, i.e. success. */
2531 if (re_safety
== im_safety
)
2532 give_warning
= re_safety
;
2533 else if (!re_safety
&& im_safety
)
2534 give_warning
= im_safety
;
2535 else if (re_safety
&& !im_safety
)
2536 give_warning
= re_safety
;
2538 give_warning
= UNSAFE_OTHER
;
2540 /* Warn about conversion from complex to real or integer type. */
2542 give_warning
= UNSAFE_IMAGINARY
;
2546 /* Checks for remaining case: EXPR is not constant. */
2549 /* Warn for real types converted to integer types. */
2550 if (TREE_CODE (expr_type
) == REAL_TYPE
2551 && TREE_CODE (type
) == INTEGER_TYPE
)
2552 give_warning
= UNSAFE_REAL
;
2554 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2555 && TREE_CODE (type
) == INTEGER_TYPE
)
2557 /* Don't warn about unsigned char y = 0xff, x = (int) y; */
2558 expr
= get_unwidened (expr
, 0);
2559 expr_type
= TREE_TYPE (expr
);
2561 /* Don't warn for short y; short x = ((int)y & 0xff); */
2562 if (TREE_CODE (expr
) == BIT_AND_EXPR
2563 || TREE_CODE (expr
) == BIT_IOR_EXPR
2564 || TREE_CODE (expr
) == BIT_XOR_EXPR
)
2566 /* If both args were extended from a shortest type,
2567 use that type if that is safe. */
2568 expr_type
= shorten_binary_op (expr_type
,
2569 TREE_OPERAND (expr
, 0),
2570 TREE_OPERAND (expr
, 1),
2573 if (TREE_CODE (expr
) == BIT_AND_EXPR
)
2575 tree op0
= TREE_OPERAND (expr
, 0);
2576 tree op1
= TREE_OPERAND (expr
, 1);
2577 bool unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2578 bool unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2580 /* If one of the operands is a non-negative constant
2581 that fits in the target type, then the type of the
2582 other operand does not matter. */
2583 if ((TREE_CODE (op0
) == INTEGER_CST
2584 && int_fits_type_p (op0
, c_common_signed_type (type
))
2585 && int_fits_type_p (op0
, c_common_unsigned_type (type
)))
2586 || (TREE_CODE (op1
) == INTEGER_CST
2587 && int_fits_type_p (op1
, c_common_signed_type (type
))
2588 && int_fits_type_p (op1
,
2589 c_common_unsigned_type (type
))))
2590 return SAFE_CONVERSION
;
2591 /* If constant is unsigned and fits in the target
2592 type, then the result will also fit. */
2593 else if ((TREE_CODE (op0
) == INTEGER_CST
2595 && int_fits_type_p (op0
, type
))
2596 || (TREE_CODE (op1
) == INTEGER_CST
2598 && int_fits_type_p (op1
, type
)))
2599 return SAFE_CONVERSION
;
2602 /* Warn for integer types converted to smaller integer types. */
2603 if (TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2604 give_warning
= UNSAFE_OTHER
;
2606 /* When they are the same width but different signedness,
2607 then the value may change. */
2608 else if (((TYPE_PRECISION (type
) == TYPE_PRECISION (expr_type
)
2609 && TYPE_UNSIGNED (expr_type
) != TYPE_UNSIGNED (type
))
2610 /* Even when converted to a bigger type, if the type is
2611 unsigned but expr is signed, then negative values
2613 || (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)))
2615 warning_at (loc
, OPT_Wsign_conversion
, "conversion to %qT from %qT "
2616 "may change the sign of the result",
2620 /* Warn for integer types converted to real types if and only if
2621 all the range of values of the integer type cannot be
2622 represented by the real type. */
2623 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2624 && TREE_CODE (type
) == REAL_TYPE
)
2626 /* Don't warn about char y = 0xff; float x = (int) y; */
2627 expr
= get_unwidened (expr
, 0);
2628 expr_type
= TREE_TYPE (expr
);
2630 if (!int_safely_convertible_to_real_p (expr_type
, type
))
2631 give_warning
= UNSAFE_OTHER
;
2634 /* Warn for real types converted to smaller real types. */
2635 else if (TREE_CODE (expr_type
) == REAL_TYPE
2636 && TREE_CODE (type
) == REAL_TYPE
2637 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2638 give_warning
= UNSAFE_REAL
;
2640 /* Check conversion between two complex types. */
2641 else if (TREE_CODE (expr_type
) == COMPLEX_TYPE
2642 && TREE_CODE (type
) == COMPLEX_TYPE
)
2644 /* Extract underlying types (i.e., type of real and imaginary
2645 parts) of expr_type and type. */
2646 tree from_type
= TREE_TYPE (expr_type
);
2647 tree to_type
= TREE_TYPE (type
);
2649 /* Warn for real types converted to integer types. */
2650 if (TREE_CODE (from_type
) == REAL_TYPE
2651 && TREE_CODE (to_type
) == INTEGER_TYPE
)
2652 give_warning
= UNSAFE_REAL
;
2654 /* Warn for real types converted to smaller real types. */
2655 else if (TREE_CODE (from_type
) == REAL_TYPE
2656 && TREE_CODE (to_type
) == REAL_TYPE
2657 && TYPE_PRECISION (to_type
) < TYPE_PRECISION (from_type
))
2658 give_warning
= UNSAFE_REAL
;
2660 /* Check conversion for complex integer types. Here implementation
2661 is simpler than for real-domain integers because it does not
2662 involve sophisticated cases, such as bitmasks, casts, etc. */
2663 else if (TREE_CODE (from_type
) == INTEGER_TYPE
2664 && TREE_CODE (to_type
) == INTEGER_TYPE
)
2666 /* Warn for integer types converted to smaller integer types. */
2667 if (TYPE_PRECISION (to_type
) < TYPE_PRECISION (from_type
))
2668 give_warning
= UNSAFE_OTHER
;
2670 /* Check for different signedness, see case for real-domain
2671 integers (above) for a more detailed comment. */
2672 else if (((TYPE_PRECISION (to_type
) == TYPE_PRECISION (from_type
)
2673 && TYPE_UNSIGNED (to_type
) != TYPE_UNSIGNED (from_type
))
2674 || (TYPE_UNSIGNED (to_type
) && !TYPE_UNSIGNED (from_type
)))
2676 warning_at (loc
, OPT_Wsign_conversion
,
2677 "conversion to %qT from %qT "
2678 "may change the sign of the result",
2681 else if (TREE_CODE (from_type
) == INTEGER_TYPE
2682 && TREE_CODE (to_type
) == REAL_TYPE
2683 && !int_safely_convertible_to_real_p (from_type
, to_type
))
2684 give_warning
= UNSAFE_OTHER
;
2687 /* Warn for complex types converted to real or integer types. */
2688 else if (TREE_CODE (expr_type
) == COMPLEX_TYPE
2689 && TREE_CODE (type
) != COMPLEX_TYPE
)
2690 give_warning
= UNSAFE_IMAGINARY
;
2693 return give_warning
;
2696 /* Warns if the conversion of EXPR to TYPE may alter a value.
2697 This is a helper function for warnings_for_convert_and_check. */
2700 conversion_warning (location_t loc
, tree type
, tree expr
)
2702 tree expr_type
= TREE_TYPE (expr
);
2703 enum conversion_safety conversion_kind
;
2705 if (!warn_conversion
&& !warn_sign_conversion
&& !warn_float_conversion
)
2708 /* This may happen, because for LHS op= RHS we preevaluate
2709 RHS and create C_MAYBE_CONST_EXPR <SAVE_EXPR <RHS>>, which
2710 means we could no longer see the code of the EXPR. */
2711 if (TREE_CODE (expr
) == C_MAYBE_CONST_EXPR
)
2712 expr
= C_MAYBE_CONST_EXPR_EXPR (expr
);
2713 if (TREE_CODE (expr
) == SAVE_EXPR
)
2714 expr
= TREE_OPERAND (expr
, 0);
2716 switch (TREE_CODE (expr
))
2724 case TRUTH_ANDIF_EXPR
:
2725 case TRUTH_ORIF_EXPR
:
2726 case TRUTH_AND_EXPR
:
2728 case TRUTH_XOR_EXPR
:
2729 case TRUTH_NOT_EXPR
:
2730 /* Conversion from boolean to a signed:1 bit-field (which only
2731 can hold the values 0 and -1) doesn't lose information - but
2732 it does change the value. */
2733 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
2734 warning_at (loc
, OPT_Wconversion
,
2735 "conversion to %qT from boolean expression", type
);
2741 conversion_kind
= unsafe_conversion_p (loc
, type
, expr
, true);
2742 if (conversion_kind
== UNSAFE_REAL
)
2743 warning_at (loc
, OPT_Wfloat_conversion
,
2744 "conversion to %qT alters %qT constant value",
2746 else if (conversion_kind
)
2747 warning_at (loc
, OPT_Wconversion
,
2748 "conversion to %qT alters %qT constant value",
2754 /* In case of COND_EXPR, we do not care about the type of
2755 COND_EXPR, only about the conversion of each operand. */
2756 tree op1
= TREE_OPERAND (expr
, 1);
2757 tree op2
= TREE_OPERAND (expr
, 2);
2759 conversion_warning (loc
, type
, op1
);
2760 conversion_warning (loc
, type
, op2
);
2764 default: /* 'expr' is not a constant. */
2765 conversion_kind
= unsafe_conversion_p (loc
, type
, expr
, true);
2766 if (conversion_kind
== UNSAFE_REAL
)
2767 warning_at (loc
, OPT_Wfloat_conversion
,
2768 "conversion to %qT from %qT may alter its value",
2770 else if (conversion_kind
== UNSAFE_IMAGINARY
)
2771 warning_at (loc
, OPT_Wconversion
,
2772 "conversion to %qT from %qT discards imaginary component",
2774 else if (conversion_kind
)
2775 warning_at (loc
, OPT_Wconversion
,
2776 "conversion to %qT from %qT may alter its value",
2781 /* Produce warnings after a conversion. RESULT is the result of
2782 converting EXPR to TYPE. This is a helper function for
2783 convert_and_check and cp_convert_and_check. */
2786 warnings_for_convert_and_check (location_t loc
, tree type
, tree expr
,
2789 loc
= expansion_point_location_if_in_system_header (loc
);
2791 if (TREE_CODE (expr
) == INTEGER_CST
2792 && (TREE_CODE (type
) == INTEGER_TYPE
2793 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2794 && !int_fits_type_p (expr
, type
))
2796 /* Do not diagnose overflow in a constant expression merely
2797 because a conversion overflowed. */
2798 if (TREE_OVERFLOW (result
))
2799 TREE_OVERFLOW (result
) = TREE_OVERFLOW (expr
);
2801 if (TYPE_UNSIGNED (type
))
2803 /* This detects cases like converting -129 or 256 to
2805 if (!int_fits_type_p (expr
, c_common_signed_type (type
)))
2806 warning_at (loc
, OPT_Woverflow
,
2807 "large integer implicitly truncated to unsigned type");
2809 conversion_warning (loc
, type
, expr
);
2811 else if (!int_fits_type_p (expr
, c_common_unsigned_type (type
)))
2812 warning_at (loc
, OPT_Woverflow
,
2813 "overflow in implicit constant conversion");
2814 /* No warning for converting 0x80000000 to int. */
2816 && (TREE_CODE (TREE_TYPE (expr
)) != INTEGER_TYPE
2817 || TYPE_PRECISION (TREE_TYPE (expr
))
2818 != TYPE_PRECISION (type
)))
2819 warning_at (loc
, OPT_Woverflow
,
2820 "overflow in implicit constant conversion");
2823 conversion_warning (loc
, type
, expr
);
2825 else if ((TREE_CODE (result
) == INTEGER_CST
2826 || TREE_CODE (result
) == FIXED_CST
) && TREE_OVERFLOW (result
))
2827 warning_at (loc
, OPT_Woverflow
,
2828 "overflow in implicit constant conversion");
2830 conversion_warning (loc
, type
, expr
);
2834 /* Convert EXPR to TYPE, warning about conversion problems with constants.
2835 Invoke this function on every expression that is converted implicitly,
2836 i.e. because of language rules and not because of an explicit cast. */
2839 convert_and_check (location_t loc
, tree type
, tree expr
)
2842 tree expr_for_warning
;
2844 /* Convert from a value with possible excess precision rather than
2845 via the semantic type, but do not warn about values not fitting
2846 exactly in the semantic type. */
2847 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
2849 tree orig_type
= TREE_TYPE (expr
);
2850 expr
= TREE_OPERAND (expr
, 0);
2851 expr_for_warning
= convert (orig_type
, expr
);
2852 if (orig_type
== type
)
2853 return expr_for_warning
;
2856 expr_for_warning
= expr
;
2858 if (TREE_TYPE (expr
) == type
)
2861 result
= convert (type
, expr
);
2863 if (c_inhibit_evaluation_warnings
== 0
2864 && !TREE_OVERFLOW_P (expr
)
2865 && result
!= error_mark_node
)
2866 warnings_for_convert_and_check (loc
, type
, expr_for_warning
, result
);
2871 /* A node in a list that describes references to variables (EXPR), which are
2872 either read accesses if WRITER is zero, or write accesses, in which case
2873 WRITER is the parent of EXPR. */
2880 /* Used to implement a cache the results of a call to verify_tree. We only
2881 use this for SAVE_EXPRs. */
2884 struct tlist_cache
*next
;
2885 struct tlist
*cache_before_sp
;
2886 struct tlist
*cache_after_sp
;
2890 /* Obstack to use when allocating tlist structures, and corresponding
2892 static struct obstack tlist_obstack
;
2893 static char *tlist_firstobj
= 0;
2895 /* Keep track of the identifiers we've warned about, so we can avoid duplicate
2897 static struct tlist
*warned_ids
;
2898 /* SAVE_EXPRs need special treatment. We process them only once and then
2899 cache the results. */
2900 static struct tlist_cache
*save_expr_cache
;
2902 static void add_tlist (struct tlist
**, struct tlist
*, tree
, int);
2903 static void merge_tlist (struct tlist
**, struct tlist
*, int);
2904 static void verify_tree (tree
, struct tlist
**, struct tlist
**, tree
);
2905 static int warning_candidate_p (tree
);
2906 static bool candidate_equal_p (const_tree
, const_tree
);
2907 static void warn_for_collisions (struct tlist
*);
2908 static void warn_for_collisions_1 (tree
, tree
, struct tlist
*, int);
2909 static struct tlist
*new_tlist (struct tlist
*, tree
, tree
);
2911 /* Create a new struct tlist and fill in its fields. */
2912 static struct tlist
*
2913 new_tlist (struct tlist
*next
, tree t
, tree writer
)
2916 l
= XOBNEW (&tlist_obstack
, struct tlist
);
2923 /* Add duplicates of the nodes found in ADD to the list *TO. If EXCLUDE_WRITER
2924 is nonnull, we ignore any node we find which has a writer equal to it. */
2927 add_tlist (struct tlist
**to
, struct tlist
*add
, tree exclude_writer
, int copy
)
2931 struct tlist
*next
= add
->next
;
2934 if (!exclude_writer
|| !candidate_equal_p (add
->writer
, exclude_writer
))
2935 *to
= copy
? new_tlist (*to
, add
->expr
, add
->writer
) : add
;
2940 /* Merge the nodes of ADD into TO. This merging process is done so that for
2941 each variable that already exists in TO, no new node is added; however if
2942 there is a write access recorded in ADD, and an occurrence on TO is only
2943 a read access, then the occurrence in TO will be modified to record the
2947 merge_tlist (struct tlist
**to
, struct tlist
*add
, int copy
)
2949 struct tlist
**end
= to
;
2952 end
= &(*end
)->next
;
2958 struct tlist
*next
= add
->next
;
2960 for (tmp2
= *to
; tmp2
; tmp2
= tmp2
->next
)
2961 if (candidate_equal_p (tmp2
->expr
, add
->expr
))
2965 tmp2
->writer
= add
->writer
;
2969 *end
= copy
? new_tlist (NULL
, add
->expr
, add
->writer
) : add
;
2970 end
= &(*end
)->next
;
2977 /* WRITTEN is a variable, WRITER is its parent. Warn if any of the variable
2978 references in list LIST conflict with it, excluding reads if ONLY writers
2982 warn_for_collisions_1 (tree written
, tree writer
, struct tlist
*list
,
2987 /* Avoid duplicate warnings. */
2988 for (tmp
= warned_ids
; tmp
; tmp
= tmp
->next
)
2989 if (candidate_equal_p (tmp
->expr
, written
))
2994 if (candidate_equal_p (list
->expr
, written
)
2995 && !candidate_equal_p (list
->writer
, writer
)
2996 && (!only_writes
|| list
->writer
))
2998 warned_ids
= new_tlist (warned_ids
, written
, NULL_TREE
);
2999 warning_at (EXPR_LOC_OR_LOC (writer
, input_location
),
3000 OPT_Wsequence_point
, "operation on %qE may be undefined",
3007 /* Given a list LIST of references to variables, find whether any of these
3008 can cause conflicts due to missing sequence points. */
3011 warn_for_collisions (struct tlist
*list
)
3015 for (tmp
= list
; tmp
; tmp
= tmp
->next
)
3018 warn_for_collisions_1 (tmp
->expr
, tmp
->writer
, list
, 0);
3022 /* Return nonzero if X is a tree that can be verified by the sequence point
3025 warning_candidate_p (tree x
)
3027 if (DECL_P (x
) && DECL_ARTIFICIAL (x
))
3030 if (TREE_CODE (x
) == BLOCK
)
3033 /* VOID_TYPE_P (TREE_TYPE (x)) is workaround for cp/tree.c
3034 (lvalue_p) crash on TRY/CATCH. */
3035 if (TREE_TYPE (x
) == NULL_TREE
|| VOID_TYPE_P (TREE_TYPE (x
)))
3041 /* No point to track non-const calls, they will never satisfy
3043 if (TREE_CODE (x
) == CALL_EXPR
&& (call_expr_flags (x
) & ECF_CONST
) == 0)
3046 if (TREE_CODE (x
) == STRING_CST
)
3052 /* Return nonzero if X and Y appear to be the same candidate (or NULL) */
3054 candidate_equal_p (const_tree x
, const_tree y
)
3056 return (x
== y
) || (x
&& y
&& operand_equal_p (x
, y
, 0));
3059 /* Walk the tree X, and record accesses to variables. If X is written by the
3060 parent tree, WRITER is the parent.
3061 We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP. If this
3062 expression or its only operand forces a sequence point, then everything up
3063 to the sequence point is stored in PBEFORE_SP. Everything else gets stored
3065 Once we return, we will have emitted warnings if any subexpression before
3066 such a sequence point could be undefined. On a higher level, however, the
3067 sequence point may not be relevant, and we'll merge the two lists.
3069 Example: (b++, a) + b;
3070 The call that processes the COMPOUND_EXPR will store the increment of B
3071 in PBEFORE_SP, and the use of A in PNO_SP. The higher-level call that
3072 processes the PLUS_EXPR will need to merge the two lists so that
3073 eventually, all accesses end up on the same list (and we'll warn about the
3074 unordered subexpressions b++ and b.
3076 A note on merging. If we modify the former example so that our expression
3079 care must be taken not simply to add all three expressions into the final
3080 PNO_SP list. The function merge_tlist takes care of that by merging the
3081 before-SP list of the COMPOUND_EXPR into its after-SP list in a special
3082 way, so that no more than one access to B is recorded. */
3085 verify_tree (tree x
, struct tlist
**pbefore_sp
, struct tlist
**pno_sp
,
3088 struct tlist
*tmp_before
, *tmp_nosp
, *tmp_list2
, *tmp_list3
;
3089 enum tree_code code
;
3090 enum tree_code_class cl
;
3092 /* X may be NULL if it is the operand of an empty statement expression
3098 code
= TREE_CODE (x
);
3099 cl
= TREE_CODE_CLASS (code
);
3101 if (warning_candidate_p (x
))
3102 *pno_sp
= new_tlist (*pno_sp
, x
, writer
);
3111 case TRUTH_ANDIF_EXPR
:
3112 case TRUTH_ORIF_EXPR
:
3113 tmp_before
= tmp_nosp
= tmp_list2
= tmp_list3
= 0;
3114 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3115 warn_for_collisions (tmp_nosp
);
3116 merge_tlist (pbefore_sp
, tmp_before
, 0);
3117 merge_tlist (pbefore_sp
, tmp_nosp
, 0);
3118 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, &tmp_list2
, NULL_TREE
);
3119 warn_for_collisions (tmp_list2
);
3120 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3121 merge_tlist (pno_sp
, tmp_list2
, 0);
3125 tmp_before
= tmp_list2
= 0;
3126 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_list2
, NULL_TREE
);
3127 warn_for_collisions (tmp_list2
);
3128 merge_tlist (pbefore_sp
, tmp_before
, 0);
3129 merge_tlist (pbefore_sp
, tmp_list2
, 0);
3131 tmp_list3
= tmp_nosp
= 0;
3132 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, &tmp_nosp
, NULL_TREE
);
3133 warn_for_collisions (tmp_nosp
);
3134 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3136 tmp_list3
= tmp_list2
= 0;
3137 verify_tree (TREE_OPERAND (x
, 2), &tmp_list3
, &tmp_list2
, NULL_TREE
);
3138 warn_for_collisions (tmp_list2
);
3139 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3140 /* Rather than add both tmp_nosp and tmp_list2, we have to merge the
3141 two first, to avoid warning for (a ? b++ : b++). */
3142 merge_tlist (&tmp_nosp
, tmp_list2
, 0);
3143 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3146 case PREDECREMENT_EXPR
:
3147 case PREINCREMENT_EXPR
:
3148 case POSTDECREMENT_EXPR
:
3149 case POSTINCREMENT_EXPR
:
3150 verify_tree (TREE_OPERAND (x
, 0), pno_sp
, pno_sp
, x
);
3154 tmp_before
= tmp_nosp
= tmp_list3
= 0;
3155 verify_tree (TREE_OPERAND (x
, 1), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3156 verify_tree (TREE_OPERAND (x
, 0), &tmp_list3
, &tmp_list3
, x
);
3157 /* Expressions inside the LHS are not ordered wrt. the sequence points
3158 in the RHS. Example:
3160 Despite the fact that the modification of "a" is in the before_sp
3161 list (tmp_before), it conflicts with the use of "a" in the LHS.
3162 We can handle this by adding the contents of tmp_list3
3163 to those of tmp_before, and redoing the collision warnings for that
3165 add_tlist (&tmp_before
, tmp_list3
, x
, 1);
3166 warn_for_collisions (tmp_before
);
3167 /* Exclude the LHS itself here; we first have to merge it into the
3168 tmp_nosp list. This is done to avoid warning for "a = a"; if we
3169 didn't exclude the LHS, we'd get it twice, once as a read and once
3171 add_tlist (pno_sp
, tmp_list3
, x
, 0);
3172 warn_for_collisions_1 (TREE_OPERAND (x
, 0), x
, tmp_nosp
, 1);
3174 merge_tlist (pbefore_sp
, tmp_before
, 0);
3175 if (warning_candidate_p (TREE_OPERAND (x
, 0)))
3176 merge_tlist (&tmp_nosp
, new_tlist (NULL
, TREE_OPERAND (x
, 0), x
), 0);
3177 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 1);
3181 /* We need to warn about conflicts among arguments and conflicts between
3182 args and the function address. Side effects of the function address,
3183 however, are not ordered by the sequence point of the call. */
3185 call_expr_arg_iterator iter
;
3187 tmp_before
= tmp_nosp
= 0;
3188 verify_tree (CALL_EXPR_FN (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3189 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, x
)
3191 tmp_list2
= tmp_list3
= 0;
3192 verify_tree (arg
, &tmp_list2
, &tmp_list3
, NULL_TREE
);
3193 merge_tlist (&tmp_list3
, tmp_list2
, 0);
3194 add_tlist (&tmp_before
, tmp_list3
, NULL_TREE
, 0);
3196 add_tlist (&tmp_before
, tmp_nosp
, NULL_TREE
, 0);
3197 warn_for_collisions (tmp_before
);
3198 add_tlist (pbefore_sp
, tmp_before
, NULL_TREE
, 0);
3203 /* Scan all the list, e.g. indices of multi dimensional array. */
3206 tmp_before
= tmp_nosp
= 0;
3207 verify_tree (TREE_VALUE (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3208 merge_tlist (&tmp_nosp
, tmp_before
, 0);
3209 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3216 struct tlist_cache
*t
;
3217 for (t
= save_expr_cache
; t
; t
= t
->next
)
3218 if (candidate_equal_p (t
->expr
, x
))
3223 t
= XOBNEW (&tlist_obstack
, struct tlist_cache
);
3224 t
->next
= save_expr_cache
;
3226 save_expr_cache
= t
;
3228 tmp_before
= tmp_nosp
= 0;
3229 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3230 warn_for_collisions (tmp_nosp
);
3233 merge_tlist (&tmp_list3
, tmp_nosp
, 0);
3234 t
->cache_before_sp
= tmp_before
;
3235 t
->cache_after_sp
= tmp_list3
;
3237 merge_tlist (pbefore_sp
, t
->cache_before_sp
, 1);
3238 add_tlist (pno_sp
, t
->cache_after_sp
, NULL_TREE
, 1);
3243 x
= TREE_OPERAND (x
, 0);
3250 /* For other expressions, simply recurse on their operands.
3251 Manual tail recursion for unary expressions.
3252 Other non-expressions need not be processed. */
3253 if (cl
== tcc_unary
)
3255 x
= TREE_OPERAND (x
, 0);
3259 else if (IS_EXPR_CODE_CLASS (cl
))
3262 int max
= TREE_OPERAND_LENGTH (x
);
3263 for (lp
= 0; lp
< max
; lp
++)
3265 tmp_before
= tmp_nosp
= 0;
3266 verify_tree (TREE_OPERAND (x
, lp
), &tmp_before
, &tmp_nosp
, 0);
3267 merge_tlist (&tmp_nosp
, tmp_before
, 0);
3268 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3275 /* Try to warn for undefined behavior in EXPR due to missing sequence
3279 verify_sequence_points (tree expr
)
3281 struct tlist
*before_sp
= 0, *after_sp
= 0;
3284 save_expr_cache
= 0;
3285 if (tlist_firstobj
== 0)
3287 gcc_obstack_init (&tlist_obstack
);
3288 tlist_firstobj
= (char *) obstack_alloc (&tlist_obstack
, 0);
3291 verify_tree (expr
, &before_sp
, &after_sp
, 0);
3292 warn_for_collisions (after_sp
);
3293 obstack_free (&tlist_obstack
, tlist_firstobj
);
3296 /* Validate the expression after `case' and apply default promotions. */
3299 check_case_value (location_t loc
, tree value
)
3301 if (value
== NULL_TREE
)
3304 if (TREE_CODE (value
) == INTEGER_CST
)
3305 /* Promote char or short to int. */
3306 value
= perform_integral_promotions (value
);
3307 else if (value
!= error_mark_node
)
3309 error_at (loc
, "case label does not reduce to an integer constant");
3310 value
= error_mark_node
;
3313 constant_expression_warning (value
);
3318 /* See if the case values LOW and HIGH are in the range of the original
3319 type (i.e. before the default conversion to int) of the switch testing
3321 TYPE is the promoted type of the testing expression, and ORIG_TYPE is
3322 the type before promoting it. CASE_LOW_P is a pointer to the lower
3323 bound of the case label, and CASE_HIGH_P is the upper bound or NULL
3324 if the case is not a case range.
3325 The caller has to make sure that we are not called with NULL for
3326 CASE_LOW_P (i.e. the default case). OUTSIDE_RANGE_P says whether there
3327 was a case value that doesn't fit into the range of the ORIG_TYPE.
3328 Returns true if the case label is in range of ORIG_TYPE (saturated or
3329 untouched) or false if the label is out of range. */
3332 check_case_bounds (location_t loc
, tree type
, tree orig_type
,
3333 tree
*case_low_p
, tree
*case_high_p
,
3334 bool *outside_range_p
)
3336 tree min_value
, max_value
;
3337 tree case_low
= *case_low_p
;
3338 tree case_high
= case_high_p
? *case_high_p
: case_low
;
3340 /* If there was a problem with the original type, do nothing. */
3341 if (orig_type
== error_mark_node
)
3344 min_value
= TYPE_MIN_VALUE (orig_type
);
3345 max_value
= TYPE_MAX_VALUE (orig_type
);
3347 /* We'll really need integer constants here. */
3348 case_low
= fold (case_low
);
3349 case_high
= fold (case_high
);
3351 /* Case label is less than minimum for type. */
3352 if (tree_int_cst_compare (case_low
, min_value
) < 0
3353 && tree_int_cst_compare (case_high
, min_value
) < 0)
3355 warning_at (loc
, 0, "case label value is less than minimum value "
3357 *outside_range_p
= true;
3361 /* Case value is greater than maximum for type. */
3362 if (tree_int_cst_compare (case_low
, max_value
) > 0
3363 && tree_int_cst_compare (case_high
, max_value
) > 0)
3365 warning_at (loc
, 0, "case label value exceeds maximum value for type");
3366 *outside_range_p
= true;
3370 /* Saturate lower case label value to minimum. */
3371 if (tree_int_cst_compare (case_high
, min_value
) >= 0
3372 && tree_int_cst_compare (case_low
, min_value
) < 0)
3374 warning_at (loc
, 0, "lower value in case label range"
3375 " less than minimum value for type");
3376 *outside_range_p
= true;
3377 case_low
= min_value
;
3380 /* Saturate upper case label value to maximum. */
3381 if (tree_int_cst_compare (case_low
, max_value
) <= 0
3382 && tree_int_cst_compare (case_high
, max_value
) > 0)
3384 warning_at (loc
, 0, "upper value in case label range"
3385 " exceeds maximum value for type");
3386 *outside_range_p
= true;
3387 case_high
= max_value
;
3390 if (*case_low_p
!= case_low
)
3391 *case_low_p
= convert (type
, case_low
);
3392 if (case_high_p
&& *case_high_p
!= case_high
)
3393 *case_high_p
= convert (type
, case_high
);
3398 /* Return an integer type with BITS bits of precision,
3399 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
3402 c_common_type_for_size (unsigned int bits
, int unsignedp
)
3406 if (bits
== TYPE_PRECISION (integer_type_node
))
3407 return unsignedp
? unsigned_type_node
: integer_type_node
;
3409 if (bits
== TYPE_PRECISION (signed_char_type_node
))
3410 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3412 if (bits
== TYPE_PRECISION (short_integer_type_node
))
3413 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3415 if (bits
== TYPE_PRECISION (long_integer_type_node
))
3416 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3418 if (bits
== TYPE_PRECISION (long_long_integer_type_node
))
3419 return (unsignedp
? long_long_unsigned_type_node
3420 : long_long_integer_type_node
);
3422 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
3423 if (int_n_enabled_p
[i
]
3424 && bits
== int_n_data
[i
].bitsize
)
3425 return (unsignedp
? int_n_trees
[i
].unsigned_type
3426 : int_n_trees
[i
].signed_type
);
3428 if (bits
== TYPE_PRECISION (widest_integer_literal_type_node
))
3429 return (unsignedp
? widest_unsigned_literal_type_node
3430 : widest_integer_literal_type_node
);
3432 if (bits
<= TYPE_PRECISION (intQI_type_node
))
3433 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3435 if (bits
<= TYPE_PRECISION (intHI_type_node
))
3436 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3438 if (bits
<= TYPE_PRECISION (intSI_type_node
))
3439 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3441 if (bits
<= TYPE_PRECISION (intDI_type_node
))
3442 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3447 /* Return a fixed-point type that has at least IBIT ibits and FBIT fbits
3448 that is unsigned if UNSIGNEDP is nonzero, otherwise signed;
3449 and saturating if SATP is nonzero, otherwise not saturating. */
3452 c_common_fixed_point_type_for_size (unsigned int ibit
, unsigned int fbit
,
3453 int unsignedp
, int satp
)
3457 mode
= unsignedp
? UQQmode
: QQmode
;
3459 mode
= unsignedp
? UHAmode
: HAmode
;
3461 for (; mode
!= VOIDmode
; mode
= GET_MODE_WIDER_MODE (mode
))
3462 if (GET_MODE_IBIT (mode
) >= ibit
&& GET_MODE_FBIT (mode
) >= fbit
)
3465 if (mode
== VOIDmode
|| !targetm
.scalar_mode_supported_p (mode
))
3467 sorry ("GCC cannot support operators with integer types and "
3468 "fixed-point types that have too many integral and "
3469 "fractional bits together");
3473 return c_common_type_for_mode (mode
, satp
);
3476 /* Used for communication between c_common_type_for_mode and
3477 c_register_builtin_type. */
3478 tree registered_builtin_types
;
3480 /* Return a data type that has machine mode MODE.
3481 If the mode is an integer,
3482 then UNSIGNEDP selects between signed and unsigned types.
3483 If the mode is a fixed-point mode,
3484 then UNSIGNEDP selects between saturating and nonsaturating types. */
3487 c_common_type_for_mode (machine_mode mode
, int unsignedp
)
3492 if (mode
== TYPE_MODE (integer_type_node
))
3493 return unsignedp
? unsigned_type_node
: integer_type_node
;
3495 if (mode
== TYPE_MODE (signed_char_type_node
))
3496 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3498 if (mode
== TYPE_MODE (short_integer_type_node
))
3499 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3501 if (mode
== TYPE_MODE (long_integer_type_node
))
3502 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3504 if (mode
== TYPE_MODE (long_long_integer_type_node
))
3505 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3507 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
3508 if (int_n_enabled_p
[i
]
3509 && mode
== int_n_data
[i
].m
)
3510 return (unsignedp
? int_n_trees
[i
].unsigned_type
3511 : int_n_trees
[i
].signed_type
);
3513 if (mode
== TYPE_MODE (widest_integer_literal_type_node
))
3514 return unsignedp
? widest_unsigned_literal_type_node
3515 : widest_integer_literal_type_node
;
3518 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3521 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3524 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3527 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3529 #if HOST_BITS_PER_WIDE_INT >= 64
3530 if (mode
== TYPE_MODE (intTI_type_node
))
3531 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3534 if (mode
== TYPE_MODE (float_type_node
))
3535 return float_type_node
;
3537 if (mode
== TYPE_MODE (double_type_node
))
3538 return double_type_node
;
3540 if (mode
== TYPE_MODE (long_double_type_node
))
3541 return long_double_type_node
;
3543 for (i
= 0; i
< NUM_FLOATN_NX_TYPES
; i
++)
3544 if (FLOATN_NX_TYPE_NODE (i
) != NULL_TREE
3545 && mode
== TYPE_MODE (FLOATN_NX_TYPE_NODE (i
)))
3546 return FLOATN_NX_TYPE_NODE (i
);
3548 if (mode
== TYPE_MODE (void_type_node
))
3549 return void_type_node
;
3551 if (mode
== TYPE_MODE (build_pointer_type (char_type_node
)))
3553 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3554 : make_signed_type (GET_MODE_PRECISION (mode
)));
3556 if (mode
== TYPE_MODE (build_pointer_type (integer_type_node
)))
3558 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3559 : make_signed_type (GET_MODE_PRECISION (mode
)));
3561 if (COMPLEX_MODE_P (mode
))
3563 machine_mode inner_mode
;
3566 if (mode
== TYPE_MODE (complex_float_type_node
))
3567 return complex_float_type_node
;
3568 if (mode
== TYPE_MODE (complex_double_type_node
))
3569 return complex_double_type_node
;
3570 if (mode
== TYPE_MODE (complex_long_double_type_node
))
3571 return complex_long_double_type_node
;
3573 for (i
= 0; i
< NUM_FLOATN_NX_TYPES
; i
++)
3574 if (COMPLEX_FLOATN_NX_TYPE_NODE (i
) != NULL_TREE
3575 && mode
== TYPE_MODE (COMPLEX_FLOATN_NX_TYPE_NODE (i
)))
3576 return COMPLEX_FLOATN_NX_TYPE_NODE (i
);
3578 if (mode
== TYPE_MODE (complex_integer_type_node
) && !unsignedp
)
3579 return complex_integer_type_node
;
3581 inner_mode
= GET_MODE_INNER (mode
);
3582 inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3583 if (inner_type
!= NULL_TREE
)
3584 return build_complex_type (inner_type
);
3586 else if (VECTOR_MODE_P (mode
))
3588 machine_mode inner_mode
= GET_MODE_INNER (mode
);
3589 tree inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3590 if (inner_type
!= NULL_TREE
)
3591 return build_vector_type_for_mode (inner_type
, mode
);
3594 if (mode
== TYPE_MODE (dfloat32_type_node
))
3595 return dfloat32_type_node
;
3596 if (mode
== TYPE_MODE (dfloat64_type_node
))
3597 return dfloat64_type_node
;
3598 if (mode
== TYPE_MODE (dfloat128_type_node
))
3599 return dfloat128_type_node
;
3601 if (ALL_SCALAR_FIXED_POINT_MODE_P (mode
))
3603 if (mode
== TYPE_MODE (short_fract_type_node
))
3604 return unsignedp
? sat_short_fract_type_node
: short_fract_type_node
;
3605 if (mode
== TYPE_MODE (fract_type_node
))
3606 return unsignedp
? sat_fract_type_node
: fract_type_node
;
3607 if (mode
== TYPE_MODE (long_fract_type_node
))
3608 return unsignedp
? sat_long_fract_type_node
: long_fract_type_node
;
3609 if (mode
== TYPE_MODE (long_long_fract_type_node
))
3610 return unsignedp
? sat_long_long_fract_type_node
3611 : long_long_fract_type_node
;
3613 if (mode
== TYPE_MODE (unsigned_short_fract_type_node
))
3614 return unsignedp
? sat_unsigned_short_fract_type_node
3615 : unsigned_short_fract_type_node
;
3616 if (mode
== TYPE_MODE (unsigned_fract_type_node
))
3617 return unsignedp
? sat_unsigned_fract_type_node
3618 : unsigned_fract_type_node
;
3619 if (mode
== TYPE_MODE (unsigned_long_fract_type_node
))
3620 return unsignedp
? sat_unsigned_long_fract_type_node
3621 : unsigned_long_fract_type_node
;
3622 if (mode
== TYPE_MODE (unsigned_long_long_fract_type_node
))
3623 return unsignedp
? sat_unsigned_long_long_fract_type_node
3624 : unsigned_long_long_fract_type_node
;
3626 if (mode
== TYPE_MODE (short_accum_type_node
))
3627 return unsignedp
? sat_short_accum_type_node
: short_accum_type_node
;
3628 if (mode
== TYPE_MODE (accum_type_node
))
3629 return unsignedp
? sat_accum_type_node
: accum_type_node
;
3630 if (mode
== TYPE_MODE (long_accum_type_node
))
3631 return unsignedp
? sat_long_accum_type_node
: long_accum_type_node
;
3632 if (mode
== TYPE_MODE (long_long_accum_type_node
))
3633 return unsignedp
? sat_long_long_accum_type_node
3634 : long_long_accum_type_node
;
3636 if (mode
== TYPE_MODE (unsigned_short_accum_type_node
))
3637 return unsignedp
? sat_unsigned_short_accum_type_node
3638 : unsigned_short_accum_type_node
;
3639 if (mode
== TYPE_MODE (unsigned_accum_type_node
))
3640 return unsignedp
? sat_unsigned_accum_type_node
3641 : unsigned_accum_type_node
;
3642 if (mode
== TYPE_MODE (unsigned_long_accum_type_node
))
3643 return unsignedp
? sat_unsigned_long_accum_type_node
3644 : unsigned_long_accum_type_node
;
3645 if (mode
== TYPE_MODE (unsigned_long_long_accum_type_node
))
3646 return unsignedp
? sat_unsigned_long_long_accum_type_node
3647 : unsigned_long_long_accum_type_node
;
3650 return unsignedp
? sat_qq_type_node
: qq_type_node
;
3652 return unsignedp
? sat_hq_type_node
: hq_type_node
;
3654 return unsignedp
? sat_sq_type_node
: sq_type_node
;
3656 return unsignedp
? sat_dq_type_node
: dq_type_node
;
3658 return unsignedp
? sat_tq_type_node
: tq_type_node
;
3660 if (mode
== UQQmode
)
3661 return unsignedp
? sat_uqq_type_node
: uqq_type_node
;
3662 if (mode
== UHQmode
)
3663 return unsignedp
? sat_uhq_type_node
: uhq_type_node
;
3664 if (mode
== USQmode
)
3665 return unsignedp
? sat_usq_type_node
: usq_type_node
;
3666 if (mode
== UDQmode
)
3667 return unsignedp
? sat_udq_type_node
: udq_type_node
;
3668 if (mode
== UTQmode
)
3669 return unsignedp
? sat_utq_type_node
: utq_type_node
;
3672 return unsignedp
? sat_ha_type_node
: ha_type_node
;
3674 return unsignedp
? sat_sa_type_node
: sa_type_node
;
3676 return unsignedp
? sat_da_type_node
: da_type_node
;
3678 return unsignedp
? sat_ta_type_node
: ta_type_node
;
3680 if (mode
== UHAmode
)
3681 return unsignedp
? sat_uha_type_node
: uha_type_node
;
3682 if (mode
== USAmode
)
3683 return unsignedp
? sat_usa_type_node
: usa_type_node
;
3684 if (mode
== UDAmode
)
3685 return unsignedp
? sat_uda_type_node
: uda_type_node
;
3686 if (mode
== UTAmode
)
3687 return unsignedp
? sat_uta_type_node
: uta_type_node
;
3690 for (t
= registered_builtin_types
; t
; t
= TREE_CHAIN (t
))
3691 if (TYPE_MODE (TREE_VALUE (t
)) == mode
3692 && !!unsignedp
== !!TYPE_UNSIGNED (TREE_VALUE (t
)))
3693 return TREE_VALUE (t
);
3699 c_common_unsigned_type (tree type
)
3701 return c_common_signed_or_unsigned_type (1, type
);
3704 /* Return a signed type the same as TYPE in other respects. */
3707 c_common_signed_type (tree type
)
3709 return c_common_signed_or_unsigned_type (0, type
);
3712 /* Return a type the same as TYPE except unsigned or
3713 signed according to UNSIGNEDP. */
3716 c_common_signed_or_unsigned_type (int unsignedp
, tree type
)
3721 /* This block of code emulates the behavior of the old
3722 c_common_unsigned_type. In particular, it returns
3723 long_unsigned_type_node if passed a long, even when a int would
3724 have the same size. This is necessary for warnings to work
3725 correctly in archs where sizeof(int) == sizeof(long) */
3727 type1
= TYPE_MAIN_VARIANT (type
);
3728 if (type1
== signed_char_type_node
|| type1
== char_type_node
|| type1
== unsigned_char_type_node
)
3729 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3730 if (type1
== integer_type_node
|| type1
== unsigned_type_node
)
3731 return unsignedp
? unsigned_type_node
: integer_type_node
;
3732 if (type1
== short_integer_type_node
|| type1
== short_unsigned_type_node
)
3733 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3734 if (type1
== long_integer_type_node
|| type1
== long_unsigned_type_node
)
3735 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3736 if (type1
== long_long_integer_type_node
|| type1
== long_long_unsigned_type_node
)
3737 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3739 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
3740 if (int_n_enabled_p
[i
]
3741 && (type1
== int_n_trees
[i
].unsigned_type
3742 || type1
== int_n_trees
[i
].signed_type
))
3743 return (unsignedp
? int_n_trees
[i
].unsigned_type
3744 : int_n_trees
[i
].signed_type
);
3746 if (type1
== widest_integer_literal_type_node
|| type1
== widest_unsigned_literal_type_node
)
3747 return unsignedp
? widest_unsigned_literal_type_node
: widest_integer_literal_type_node
;
3748 #if HOST_BITS_PER_WIDE_INT >= 64
3749 if (type1
== intTI_type_node
|| type1
== unsigned_intTI_type_node
)
3750 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3752 if (type1
== intDI_type_node
|| type1
== unsigned_intDI_type_node
)
3753 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3754 if (type1
== intSI_type_node
|| type1
== unsigned_intSI_type_node
)
3755 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3756 if (type1
== intHI_type_node
|| type1
== unsigned_intHI_type_node
)
3757 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3758 if (type1
== intQI_type_node
|| type1
== unsigned_intQI_type_node
)
3759 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3761 #define C_COMMON_FIXED_TYPES(NAME) \
3762 if (type1 == short_ ## NAME ## _type_node \
3763 || type1 == unsigned_short_ ## NAME ## _type_node) \
3764 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
3765 : short_ ## NAME ## _type_node; \
3766 if (type1 == NAME ## _type_node \
3767 || type1 == unsigned_ ## NAME ## _type_node) \
3768 return unsignedp ? unsigned_ ## NAME ## _type_node \
3769 : NAME ## _type_node; \
3770 if (type1 == long_ ## NAME ## _type_node \
3771 || type1 == unsigned_long_ ## NAME ## _type_node) \
3772 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
3773 : long_ ## NAME ## _type_node; \
3774 if (type1 == long_long_ ## NAME ## _type_node \
3775 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
3776 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
3777 : long_long_ ## NAME ## _type_node;
3779 #define C_COMMON_FIXED_MODE_TYPES(NAME) \
3780 if (type1 == NAME ## _type_node \
3781 || type1 == u ## NAME ## _type_node) \
3782 return unsignedp ? u ## NAME ## _type_node \
3783 : NAME ## _type_node;
3785 #define C_COMMON_FIXED_TYPES_SAT(NAME) \
3786 if (type1 == sat_ ## short_ ## NAME ## _type_node \
3787 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
3788 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
3789 : sat_ ## short_ ## NAME ## _type_node; \
3790 if (type1 == sat_ ## NAME ## _type_node \
3791 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
3792 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
3793 : sat_ ## NAME ## _type_node; \
3794 if (type1 == sat_ ## long_ ## NAME ## _type_node \
3795 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
3796 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
3797 : sat_ ## long_ ## NAME ## _type_node; \
3798 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
3799 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
3800 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
3801 : sat_ ## long_long_ ## NAME ## _type_node;
3803 #define C_COMMON_FIXED_MODE_TYPES_SAT(NAME) \
3804 if (type1 == sat_ ## NAME ## _type_node \
3805 || type1 == sat_ ## u ## NAME ## _type_node) \
3806 return unsignedp ? sat_ ## u ## NAME ## _type_node \
3807 : sat_ ## NAME ## _type_node;
3809 C_COMMON_FIXED_TYPES (fract
);
3810 C_COMMON_FIXED_TYPES_SAT (fract
);
3811 C_COMMON_FIXED_TYPES (accum
);
3812 C_COMMON_FIXED_TYPES_SAT (accum
);
3814 C_COMMON_FIXED_MODE_TYPES (qq
);
3815 C_COMMON_FIXED_MODE_TYPES (hq
);
3816 C_COMMON_FIXED_MODE_TYPES (sq
);
3817 C_COMMON_FIXED_MODE_TYPES (dq
);
3818 C_COMMON_FIXED_MODE_TYPES (tq
);
3819 C_COMMON_FIXED_MODE_TYPES_SAT (qq
);
3820 C_COMMON_FIXED_MODE_TYPES_SAT (hq
);
3821 C_COMMON_FIXED_MODE_TYPES_SAT (sq
);
3822 C_COMMON_FIXED_MODE_TYPES_SAT (dq
);
3823 C_COMMON_FIXED_MODE_TYPES_SAT (tq
);
3824 C_COMMON_FIXED_MODE_TYPES (ha
);
3825 C_COMMON_FIXED_MODE_TYPES (sa
);
3826 C_COMMON_FIXED_MODE_TYPES (da
);
3827 C_COMMON_FIXED_MODE_TYPES (ta
);
3828 C_COMMON_FIXED_MODE_TYPES_SAT (ha
);
3829 C_COMMON_FIXED_MODE_TYPES_SAT (sa
);
3830 C_COMMON_FIXED_MODE_TYPES_SAT (da
);
3831 C_COMMON_FIXED_MODE_TYPES_SAT (ta
);
3833 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
3834 the precision; they have precision set to match their range, but
3835 may use a wider mode to match an ABI. If we change modes, we may
3836 wind up with bad conversions. For INTEGER_TYPEs in C, must check
3837 the precision as well, so as to yield correct results for
3838 bit-field types. C++ does not have these separate bit-field
3839 types, and producing a signed or unsigned variant of an
3840 ENUMERAL_TYPE may cause other problems as well. */
3842 if (!INTEGRAL_TYPE_P (type
)
3843 || TYPE_UNSIGNED (type
) == unsignedp
)
3846 #define TYPE_OK(node) \
3847 (TYPE_MODE (type) == TYPE_MODE (node) \
3848 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
3849 if (TYPE_OK (signed_char_type_node
))
3850 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3851 if (TYPE_OK (integer_type_node
))
3852 return unsignedp
? unsigned_type_node
: integer_type_node
;
3853 if (TYPE_OK (short_integer_type_node
))
3854 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3855 if (TYPE_OK (long_integer_type_node
))
3856 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3857 if (TYPE_OK (long_long_integer_type_node
))
3858 return (unsignedp
? long_long_unsigned_type_node
3859 : long_long_integer_type_node
);
3861 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
3862 if (int_n_enabled_p
[i
]
3863 && TYPE_MODE (type
) == int_n_data
[i
].m
3864 && TYPE_PRECISION (type
) == int_n_data
[i
].bitsize
)
3865 return (unsignedp
? int_n_trees
[i
].unsigned_type
3866 : int_n_trees
[i
].signed_type
);
3868 if (TYPE_OK (widest_integer_literal_type_node
))
3869 return (unsignedp
? widest_unsigned_literal_type_node
3870 : widest_integer_literal_type_node
);
3872 #if HOST_BITS_PER_WIDE_INT >= 64
3873 if (TYPE_OK (intTI_type_node
))
3874 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3876 if (TYPE_OK (intDI_type_node
))
3877 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3878 if (TYPE_OK (intSI_type_node
))
3879 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3880 if (TYPE_OK (intHI_type_node
))
3881 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3882 if (TYPE_OK (intQI_type_node
))
3883 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3886 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
3889 /* Build a bit-field integer type for the given WIDTH and UNSIGNEDP. */
3892 c_build_bitfield_integer_type (unsigned HOST_WIDE_INT width
, int unsignedp
)
3896 /* Extended integer types of the same width as a standard type have
3897 lesser rank, so those of the same width as int promote to int or
3898 unsigned int and are valid for printf formats expecting int or
3899 unsigned int. To avoid such special cases, avoid creating
3900 extended integer types for bit-fields if a standard integer type
3902 if (width
== TYPE_PRECISION (integer_type_node
))
3903 return unsignedp
? unsigned_type_node
: integer_type_node
;
3904 if (width
== TYPE_PRECISION (signed_char_type_node
))
3905 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3906 if (width
== TYPE_PRECISION (short_integer_type_node
))
3907 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3908 if (width
== TYPE_PRECISION (long_integer_type_node
))
3909 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3910 if (width
== TYPE_PRECISION (long_long_integer_type_node
))
3911 return (unsignedp
? long_long_unsigned_type_node
3912 : long_long_integer_type_node
);
3913 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
3914 if (int_n_enabled_p
[i
]
3915 && width
== int_n_data
[i
].bitsize
)
3916 return (unsignedp
? int_n_trees
[i
].unsigned_type
3917 : int_n_trees
[i
].signed_type
);
3918 return build_nonstandard_integer_type (width
, unsignedp
);
3921 /* The C version of the register_builtin_type langhook. */
3924 c_register_builtin_type (tree type
, const char* name
)
3928 decl
= build_decl (UNKNOWN_LOCATION
,
3929 TYPE_DECL
, get_identifier (name
), type
);
3930 DECL_ARTIFICIAL (decl
) = 1;
3931 if (!TYPE_NAME (type
))
3932 TYPE_NAME (type
) = decl
;
3935 registered_builtin_types
= tree_cons (0, type
, registered_builtin_types
);
3938 /* Print an error message for invalid operands to arith operation
3939 CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
3940 RICHLOC is a rich location for the message, containing either
3941 three separate locations for each of the operator and operands
3946 (C FE), or one location ranging over all over them
3954 binary_op_error (rich_location
*richloc
, enum tree_code code
,
3955 tree type0
, tree type1
)
3962 opname
= "+"; break;
3964 opname
= "-"; break;
3966 opname
= "*"; break;
3968 opname
= "max"; break;
3970 opname
= "min"; break;
3972 opname
= "=="; break;
3974 opname
= "!="; break;
3976 opname
= "<="; break;
3978 opname
= ">="; break;
3980 opname
= "<"; break;
3982 opname
= ">"; break;
3984 opname
= "<<"; break;
3986 opname
= ">>"; break;
3987 case TRUNC_MOD_EXPR
:
3988 case FLOOR_MOD_EXPR
:
3989 opname
= "%"; break;
3990 case TRUNC_DIV_EXPR
:
3991 case FLOOR_DIV_EXPR
:
3992 opname
= "/"; break;
3994 opname
= "&"; break;
3996 opname
= "|"; break;
3997 case TRUTH_ANDIF_EXPR
:
3998 opname
= "&&"; break;
3999 case TRUTH_ORIF_EXPR
:
4000 opname
= "||"; break;
4002 opname
= "^"; break;
4006 error_at_rich_loc (richloc
,
4007 "invalid operands to binary %s (have %qT and %qT)",
4008 opname
, type0
, type1
);
4011 /* Given an expression as a tree, return its original type. Do this
4012 by stripping any conversion that preserves the sign and precision. */
4014 expr_original_type (tree expr
)
4016 STRIP_SIGN_NOPS (expr
);
4017 return TREE_TYPE (expr
);
4020 /* Subroutine of build_binary_op, used for comparison operations.
4021 See if the operands have both been converted from subword integer types
4022 and, if so, perhaps change them both back to their original type.
4023 This function is also responsible for converting the two operands
4024 to the proper common type for comparison.
4026 The arguments of this function are all pointers to local variables
4027 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
4028 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
4030 LOC is the location of the comparison.
4032 If this function returns nonzero, it means that the comparison has
4033 a constant value. What this function returns is an expression for
4037 shorten_compare (location_t loc
, tree
*op0_ptr
, tree
*op1_ptr
,
4038 tree
*restype_ptr
, enum tree_code
*rescode_ptr
)
4041 tree op0
= *op0_ptr
;
4042 tree op1
= *op1_ptr
;
4043 int unsignedp0
, unsignedp1
;
4045 tree primop0
, primop1
;
4046 enum tree_code code
= *rescode_ptr
;
4048 /* Throw away any conversions to wider types
4049 already present in the operands. */
4051 primop0
= c_common_get_narrower (op0
, &unsignedp0
);
4052 primop1
= c_common_get_narrower (op1
, &unsignedp1
);
4054 /* If primopN is first sign-extended from primopN's precision to opN's
4055 precision, then zero-extended from opN's precision to
4056 *restype_ptr precision, shortenings might be invalid. */
4057 if (TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (TREE_TYPE (op0
))
4058 && TYPE_PRECISION (TREE_TYPE (op0
)) < TYPE_PRECISION (*restype_ptr
)
4060 && TYPE_UNSIGNED (TREE_TYPE (op0
)))
4062 if (TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (TREE_TYPE (op1
))
4063 && TYPE_PRECISION (TREE_TYPE (op1
)) < TYPE_PRECISION (*restype_ptr
)
4065 && TYPE_UNSIGNED (TREE_TYPE (op1
)))
4068 /* Handle the case that OP0 does not *contain* a conversion
4069 but it *requires* conversion to FINAL_TYPE. */
4071 if (op0
== primop0
&& TREE_TYPE (op0
) != *restype_ptr
)
4072 unsignedp0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
4073 if (op1
== primop1
&& TREE_TYPE (op1
) != *restype_ptr
)
4074 unsignedp1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
4076 /* If one of the operands must be floated, we cannot optimize. */
4077 real1
= TREE_CODE (TREE_TYPE (primop0
)) == REAL_TYPE
;
4078 real2
= TREE_CODE (TREE_TYPE (primop1
)) == REAL_TYPE
;
4080 /* If first arg is constant, swap the args (changing operation
4081 so value is preserved), for canonicalization. Don't do this if
4082 the second arg is 0. */
4084 if (TREE_CONSTANT (primop0
)
4085 && !integer_zerop (primop1
) && !real_zerop (primop1
)
4086 && !fixed_zerop (primop1
))
4088 std::swap (primop0
, primop1
);
4089 std::swap (op0
, op1
);
4092 std::swap (unsignedp0
, unsignedp1
);
4093 std::swap (real1
, real2
);
4112 *rescode_ptr
= code
;
4115 /* If comparing an integer against a constant more bits wide,
4116 maybe we can deduce a value of 1 or 0 independent of the data.
4117 Or else truncate the constant now
4118 rather than extend the variable at run time.
4120 This is only interesting if the constant is the wider arg.
4121 Also, it is not safe if the constant is unsigned and the
4122 variable arg is signed, since in this case the variable
4123 would be sign-extended and then regarded as unsigned.
4124 Our technique fails in this case because the lowest/highest
4125 possible unsigned results don't follow naturally from the
4126 lowest/highest possible values of the variable operand.
4127 For just EQ_EXPR and NE_EXPR there is another technique that
4128 could be used: see if the constant can be faithfully represented
4129 in the other operand's type, by truncating it and reextending it
4130 and see if that preserves the constant's value. */
4132 if (!real1
&& !real2
4133 && TREE_CODE (TREE_TYPE (primop0
)) != FIXED_POINT_TYPE
4134 && TREE_CODE (primop1
) == INTEGER_CST
4135 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
))
4137 int min_gt
, max_gt
, min_lt
, max_lt
;
4138 tree maxval
, minval
;
4139 /* 1 if comparison is nominally unsigned. */
4140 int unsignedp
= TYPE_UNSIGNED (*restype_ptr
);
4143 type
= c_common_signed_or_unsigned_type (unsignedp0
,
4144 TREE_TYPE (primop0
));
4146 maxval
= TYPE_MAX_VALUE (type
);
4147 minval
= TYPE_MIN_VALUE (type
);
4149 if (unsignedp
&& !unsignedp0
)
4150 *restype_ptr
= c_common_signed_type (*restype_ptr
);
4152 if (TREE_TYPE (primop1
) != *restype_ptr
)
4154 /* Convert primop1 to target type, but do not introduce
4155 additional overflow. We know primop1 is an int_cst. */
4156 primop1
= force_fit_type (*restype_ptr
,
4159 TYPE_PRECISION (*restype_ptr
)),
4160 0, TREE_OVERFLOW (primop1
));
4162 if (type
!= *restype_ptr
)
4164 minval
= convert (*restype_ptr
, minval
);
4165 maxval
= convert (*restype_ptr
, maxval
);
4168 min_gt
= tree_int_cst_lt (primop1
, minval
);
4169 max_gt
= tree_int_cst_lt (primop1
, maxval
);
4170 min_lt
= tree_int_cst_lt (minval
, primop1
);
4171 max_lt
= tree_int_cst_lt (maxval
, primop1
);
4174 /* This used to be a switch, but Genix compiler can't handle that. */
4175 if (code
== NE_EXPR
)
4177 if (max_lt
|| min_gt
)
4178 val
= truthvalue_true_node
;
4180 else if (code
== EQ_EXPR
)
4182 if (max_lt
|| min_gt
)
4183 val
= truthvalue_false_node
;
4185 else if (code
== LT_EXPR
)
4188 val
= truthvalue_true_node
;
4190 val
= truthvalue_false_node
;
4192 else if (code
== GT_EXPR
)
4195 val
= truthvalue_true_node
;
4197 val
= truthvalue_false_node
;
4199 else if (code
== LE_EXPR
)
4202 val
= truthvalue_true_node
;
4204 val
= truthvalue_false_node
;
4206 else if (code
== GE_EXPR
)
4209 val
= truthvalue_true_node
;
4211 val
= truthvalue_false_node
;
4214 /* If primop0 was sign-extended and unsigned comparison specd,
4215 we did a signed comparison above using the signed type bounds.
4216 But the comparison we output must be unsigned.
4218 Also, for inequalities, VAL is no good; but if the signed
4219 comparison had *any* fixed result, it follows that the
4220 unsigned comparison just tests the sign in reverse
4221 (positive values are LE, negative ones GE).
4222 So we can generate an unsigned comparison
4223 against an extreme value of the signed type. */
4225 if (unsignedp
&& !unsignedp0
)
4232 primop1
= TYPE_MIN_VALUE (type
);
4238 primop1
= TYPE_MAX_VALUE (type
);
4245 type
= c_common_unsigned_type (type
);
4248 if (TREE_CODE (primop0
) != INTEGER_CST
4249 /* Don't warn if it's from a (non-system) macro. */
4250 && !(from_macro_expansion_at
4251 (expansion_point_location_if_in_system_header
4252 (EXPR_LOCATION (primop0
)))))
4254 if (val
== truthvalue_false_node
)
4255 warning_at (loc
, OPT_Wtype_limits
,
4256 "comparison is always false due to limited range of data type");
4257 if (val
== truthvalue_true_node
)
4258 warning_at (loc
, OPT_Wtype_limits
,
4259 "comparison is always true due to limited range of data type");
4264 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4265 if (TREE_SIDE_EFFECTS (primop0
))
4266 return build2 (COMPOUND_EXPR
, TREE_TYPE (val
), primop0
, val
);
4270 /* Value is not predetermined, but do the comparison
4271 in the type of the operand that is not constant.
4272 TYPE is already properly set. */
4275 /* If either arg is decimal float and the other is float, find the
4276 proper common type to use for comparison. */
4277 else if (real1
&& real2
4278 && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0
)))
4279 && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1
))))
4280 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
4282 /* If either arg is decimal float and the other is float, fail. */
4283 else if (real1
&& real2
4284 && (DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0
)))
4285 || DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1
)))))
4288 else if (real1
&& real2
4289 && (TYPE_PRECISION (TREE_TYPE (primop0
))
4290 == TYPE_PRECISION (TREE_TYPE (primop1
))))
4291 type
= TREE_TYPE (primop0
);
4293 /* If args' natural types are both narrower than nominal type
4294 and both extend in the same manner, compare them
4295 in the type of the wider arg.
4296 Otherwise must actually extend both to the nominal
4297 common type lest different ways of extending
4299 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
4301 else if (unsignedp0
== unsignedp1
&& real1
== real2
4302 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
)
4303 && TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (*restype_ptr
))
4305 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
4306 type
= c_common_signed_or_unsigned_type (unsignedp0
4307 || TYPE_UNSIGNED (*restype_ptr
),
4309 /* Make sure shorter operand is extended the right way
4310 to match the longer operand. */
4312 = convert (c_common_signed_or_unsigned_type (unsignedp0
,
4313 TREE_TYPE (primop0
)),
4316 = convert (c_common_signed_or_unsigned_type (unsignedp1
,
4317 TREE_TYPE (primop1
)),
4322 /* Here we must do the comparison on the nominal type
4323 using the args exactly as we received them. */
4324 type
= *restype_ptr
;
4328 if (!real1
&& !real2
&& integer_zerop (primop1
)
4329 && TYPE_UNSIGNED (*restype_ptr
))
4332 /* All unsigned values are >= 0, so we warn. However,
4333 if OP0 is a constant that is >= 0, the signedness of
4334 the comparison isn't an issue, so suppress the
4337 warn_type_limits
&& !in_system_header_at (loc
)
4338 && !(TREE_CODE (primop0
) == INTEGER_CST
4339 && !TREE_OVERFLOW (convert (c_common_signed_type (type
),
4341 /* Do not warn for enumeration types. */
4342 && (TREE_CODE (expr_original_type (primop0
)) != ENUMERAL_TYPE
);
4348 warning_at (loc
, OPT_Wtype_limits
,
4349 "comparison of unsigned expression >= 0 is always true");
4350 value
= truthvalue_true_node
;
4355 warning_at (loc
, OPT_Wtype_limits
,
4356 "comparison of unsigned expression < 0 is always false");
4357 value
= truthvalue_false_node
;
4366 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4367 if (TREE_SIDE_EFFECTS (primop0
))
4368 return build2 (COMPOUND_EXPR
, TREE_TYPE (value
),
4375 *op0_ptr
= convert (type
, primop0
);
4376 *op1_ptr
= convert (type
, primop1
);
4378 *restype_ptr
= truthvalue_type_node
;
4383 /* Return a tree for the sum or difference (RESULTCODE says which)
4384 of pointer PTROP and integer INTOP. */
4387 pointer_int_sum (location_t loc
, enum tree_code resultcode
,
4388 tree ptrop
, tree intop
, bool complain
)
4392 /* The result is a pointer of the same type that is being added. */
4393 tree result_type
= TREE_TYPE (ptrop
);
4395 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
4397 if (complain
&& warn_pointer_arith
)
4398 pedwarn (loc
, OPT_Wpointer_arith
,
4399 "pointer of type %<void *%> used in arithmetic");
4401 return error_mark_node
;
4402 size_exp
= integer_one_node
;
4404 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
4406 if (complain
&& warn_pointer_arith
)
4407 pedwarn (loc
, OPT_Wpointer_arith
,
4408 "pointer to a function used in arithmetic");
4410 return error_mark_node
;
4411 size_exp
= integer_one_node
;
4414 size_exp
= size_in_bytes_loc (loc
, TREE_TYPE (result_type
));
4416 /* We are manipulating pointer values, so we don't need to warn
4417 about relying on undefined signed overflow. We disable the
4418 warning here because we use integer types so fold won't know that
4419 they are really pointers. */
4420 fold_defer_overflow_warnings ();
4422 /* If what we are about to multiply by the size of the elements
4423 contains a constant term, apply distributive law
4424 and multiply that constant term separately.
4425 This helps produce common subexpressions. */
4426 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
4427 && !TREE_CONSTANT (intop
)
4428 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
4429 && TREE_CONSTANT (size_exp
)
4430 /* If the constant comes from pointer subtraction,
4431 skip this optimization--it would cause an error. */
4432 && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop
, 0))) == INTEGER_TYPE
4433 /* If the constant is unsigned, and smaller than the pointer size,
4434 then we must skip this optimization. This is because it could cause
4435 an overflow error if the constant is negative but INTOP is not. */
4436 && (!TYPE_UNSIGNED (TREE_TYPE (intop
))
4437 || (TYPE_PRECISION (TREE_TYPE (intop
))
4438 == TYPE_PRECISION (TREE_TYPE (ptrop
)))))
4440 enum tree_code subcode
= resultcode
;
4441 tree int_type
= TREE_TYPE (intop
);
4442 if (TREE_CODE (intop
) == MINUS_EXPR
)
4443 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
4444 /* Convert both subexpression types to the type of intop,
4445 because weird cases involving pointer arithmetic
4446 can result in a sum or difference with different type args. */
4447 ptrop
= build_binary_op (EXPR_LOCATION (TREE_OPERAND (intop
, 1)),
4449 convert (int_type
, TREE_OPERAND (intop
, 1)), 1);
4450 intop
= convert (int_type
, TREE_OPERAND (intop
, 0));
4453 /* Convert the integer argument to a type the same size as sizetype
4454 so the multiply won't overflow spuriously. */
4455 if (TYPE_PRECISION (TREE_TYPE (intop
)) != TYPE_PRECISION (sizetype
)
4456 || TYPE_UNSIGNED (TREE_TYPE (intop
)) != TYPE_UNSIGNED (sizetype
))
4457 intop
= convert (c_common_type_for_size (TYPE_PRECISION (sizetype
),
4458 TYPE_UNSIGNED (sizetype
)), intop
);
4460 /* Replace the integer argument with a suitable product by the object size.
4461 Do this multiplication as signed, then convert to the appropriate type
4462 for the pointer operation and disregard an overflow that occurred only
4463 because of the sign-extension change in the latter conversion. */
4465 tree t
= fold_build2_loc (loc
, MULT_EXPR
, TREE_TYPE (intop
), intop
,
4466 convert (TREE_TYPE (intop
), size_exp
));
4467 intop
= convert (sizetype
, t
);
4468 if (TREE_OVERFLOW_P (intop
) && !TREE_OVERFLOW (t
))
4469 intop
= wide_int_to_tree (TREE_TYPE (intop
), intop
);
4472 /* Create the sum or difference. */
4473 if (resultcode
== MINUS_EXPR
)
4474 intop
= fold_build1_loc (loc
, NEGATE_EXPR
, sizetype
, intop
);
4476 ret
= fold_build_pointer_plus_loc (loc
, ptrop
, intop
);
4478 fold_undefer_and_ignore_overflow_warnings ();
4483 /* Wrap a C_MAYBE_CONST_EXPR around an expression that is fully folded
4484 and if NON_CONST is known not to be permitted in an evaluated part
4485 of a constant expression. */
4488 c_wrap_maybe_const (tree expr
, bool non_const
)
4490 bool nowarning
= TREE_NO_WARNING (expr
);
4491 location_t loc
= EXPR_LOCATION (expr
);
4493 /* This should never be called for C++. */
4494 if (c_dialect_cxx ())
4497 /* The result of folding may have a NOP_EXPR to set TREE_NO_WARNING. */
4498 STRIP_TYPE_NOPS (expr
);
4499 expr
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (expr
), NULL
, expr
);
4500 C_MAYBE_CONST_EXPR_NON_CONST (expr
) = non_const
;
4502 TREE_NO_WARNING (expr
) = 1;
4503 protected_set_expr_location (expr
, loc
);
4508 /* Wrap a SAVE_EXPR around EXPR, if appropriate. Like save_expr, but
4509 for C folds the inside expression and wraps a C_MAYBE_CONST_EXPR
4510 around the SAVE_EXPR if needed so that c_fully_fold does not need
4511 to look inside SAVE_EXPRs. */
4514 c_save_expr (tree expr
)
4516 bool maybe_const
= true;
4517 if (c_dialect_cxx ())
4518 return save_expr (expr
);
4519 expr
= c_fully_fold (expr
, false, &maybe_const
);
4520 expr
= save_expr (expr
);
4522 expr
= c_wrap_maybe_const (expr
, true);
4526 /* Return whether EXPR is a declaration whose address can never be
4530 decl_with_nonnull_addr_p (const_tree expr
)
4532 return (DECL_P (expr
)
4533 && (TREE_CODE (expr
) == PARM_DECL
4534 || TREE_CODE (expr
) == LABEL_DECL
4535 || !DECL_WEAK (expr
)));
4538 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
4539 or for an `if' or `while' statement or ?..: exp. It should already
4540 have been validated to be of suitable type; otherwise, a bad
4541 diagnostic may result.
4543 The EXPR is located at LOCATION.
4545 This preparation consists of taking the ordinary
4546 representation of an expression expr and producing a valid tree
4547 boolean expression describing whether expr is nonzero. We could
4548 simply always do build_binary_op (NE_EXPR, expr, truthvalue_false_node, 1),
4549 but we optimize comparisons, &&, ||, and !.
4551 The resulting type should always be `truthvalue_type_node'. */
4554 c_common_truthvalue_conversion (location_t location
, tree expr
)
4556 switch (TREE_CODE (expr
))
4558 case EQ_EXPR
: case NE_EXPR
: case UNEQ_EXPR
: case LTGT_EXPR
:
4559 case LE_EXPR
: case GE_EXPR
: case LT_EXPR
: case GT_EXPR
:
4560 case UNLE_EXPR
: case UNGE_EXPR
: case UNLT_EXPR
: case UNGT_EXPR
:
4561 case ORDERED_EXPR
: case UNORDERED_EXPR
:
4562 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4564 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4565 TREE_OPERAND (expr
, 0), TREE_OPERAND (expr
, 1));
4568 case TRUTH_ANDIF_EXPR
:
4569 case TRUTH_ORIF_EXPR
:
4570 case TRUTH_AND_EXPR
:
4572 case TRUTH_XOR_EXPR
:
4573 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4575 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4576 c_common_truthvalue_conversion (location
,
4577 TREE_OPERAND (expr
, 0)),
4578 c_common_truthvalue_conversion (location
,
4579 TREE_OPERAND (expr
, 1)));
4582 case TRUTH_NOT_EXPR
:
4583 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4585 expr
= build1 (TREE_CODE (expr
), truthvalue_type_node
,
4586 c_common_truthvalue_conversion (location
,
4587 TREE_OPERAND (expr
, 0)));
4594 if (TREE_CODE (TREE_TYPE (expr
)) == ENUMERAL_TYPE
4595 && !integer_zerop (expr
)
4596 && !integer_onep (expr
))
4597 warning_at (location
, OPT_Wint_in_bool_context
,
4598 "enum constant in boolean context");
4599 return integer_zerop (expr
) ? truthvalue_false_node
4600 : truthvalue_true_node
;
4603 return real_compare (NE_EXPR
, &TREE_REAL_CST (expr
), &dconst0
)
4604 ? truthvalue_true_node
4605 : truthvalue_false_node
;
4608 return fixed_compare (NE_EXPR
, &TREE_FIXED_CST (expr
),
4609 &FCONST0 (TYPE_MODE (TREE_TYPE (expr
))))
4610 ? truthvalue_true_node
4611 : truthvalue_false_node
;
4614 expr
= build_unary_op (location
, ADDR_EXPR
, expr
, false);
4619 tree inner
= TREE_OPERAND (expr
, 0);
4620 if (decl_with_nonnull_addr_p (inner
))
4622 /* Common Ada/Pascal programmer's mistake. */
4623 warning_at (location
,
4625 "the address of %qD will always evaluate as %<true%>",
4627 return truthvalue_true_node
;
4633 expr
= build_binary_op (EXPR_LOCATION (expr
),
4634 (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1))
4635 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4636 c_common_truthvalue_conversion (location
,
4637 TREE_OPERAND (expr
, 0)),
4638 c_common_truthvalue_conversion (location
,
4639 TREE_OPERAND (expr
, 1)),
4646 case EXCESS_PRECISION_EXPR
:
4647 /* These don't change whether an object is nonzero or zero. */
4648 return c_common_truthvalue_conversion (location
, TREE_OPERAND (expr
, 0));
4652 /* These don't change whether an object is zero or nonzero, but
4653 we can't ignore them if their second arg has side-effects. */
4654 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1)))
4656 expr
= build2 (COMPOUND_EXPR
, truthvalue_type_node
,
4657 TREE_OPERAND (expr
, 1),
4658 c_common_truthvalue_conversion
4659 (location
, TREE_OPERAND (expr
, 0)));
4663 return c_common_truthvalue_conversion (location
,
4664 TREE_OPERAND (expr
, 0));
4667 warning_at (EXPR_LOCATION (expr
), OPT_Wint_in_bool_context
,
4668 "<< in boolean context, did you mean '<' ?");
4672 if (warn_int_in_bool_context
4673 && !from_macro_definition_at (EXPR_LOCATION (expr
)))
4675 tree val1
= fold_for_warn (TREE_OPERAND (expr
, 1));
4676 tree val2
= fold_for_warn (TREE_OPERAND (expr
, 2));
4677 if (TREE_CODE (val1
) == INTEGER_CST
4678 && TREE_CODE (val2
) == INTEGER_CST
4679 && !integer_zerop (val1
)
4680 && !integer_zerop (val2
)
4681 && (!integer_onep (val1
)
4682 || !integer_onep (val2
)))
4683 warning_at (EXPR_LOCATION (expr
), OPT_Wint_in_bool_context
,
4684 "?: using integer constants in boolean context, "
4685 "the expression will always evaluate to %<true%>");
4686 else if ((TREE_CODE (val1
) == INTEGER_CST
4687 && !integer_zerop (val1
)
4688 && !integer_onep (val1
))
4689 || (TREE_CODE (val2
) == INTEGER_CST
4690 && !integer_zerop (val2
)
4691 && !integer_onep (val2
)))
4692 warning_at (EXPR_LOCATION (expr
), OPT_Wint_in_bool_context
,
4693 "?: using integer constants in boolean context");
4695 /* Distribute the conversion into the arms of a COND_EXPR. */
4696 if (c_dialect_cxx ())
4697 /* Avoid premature folding. */
4701 int w
= warn_int_in_bool_context
;
4702 warn_int_in_bool_context
= 0;
4703 /* Folding will happen later for C. */
4704 expr
= build3 (COND_EXPR
, truthvalue_type_node
,
4705 TREE_OPERAND (expr
, 0),
4706 c_common_truthvalue_conversion (location
,
4707 TREE_OPERAND (expr
, 1)),
4708 c_common_truthvalue_conversion (location
,
4709 TREE_OPERAND (expr
, 2)));
4710 warn_int_in_bool_context
= w
;
4716 tree totype
= TREE_TYPE (expr
);
4717 tree fromtype
= TREE_TYPE (TREE_OPERAND (expr
, 0));
4719 if (POINTER_TYPE_P (totype
)
4720 && !c_inhibit_evaluation_warnings
4721 && TREE_CODE (fromtype
) == REFERENCE_TYPE
)
4727 warning_at (location
,
4729 "the compiler can assume that the address of "
4730 "%qD will always evaluate to %<true%>",
4734 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
4735 since that affects how `default_conversion' will behave. */
4736 if (TREE_CODE (totype
) == REFERENCE_TYPE
4737 || TREE_CODE (fromtype
) == REFERENCE_TYPE
)
4739 /* Don't strip a conversion from C++0x scoped enum, since they
4740 don't implicitly convert to other types. */
4741 if (TREE_CODE (fromtype
) == ENUMERAL_TYPE
4742 && ENUM_IS_SCOPED (fromtype
))
4744 /* If this isn't narrowing the argument, we can ignore it. */
4745 if (TYPE_PRECISION (totype
) >= TYPE_PRECISION (fromtype
))
4746 return c_common_truthvalue_conversion (location
,
4747 TREE_OPERAND (expr
, 0));
4752 if (!TREE_NO_WARNING (expr
)
4753 && warn_parentheses
)
4755 warning_at (location
, OPT_Wparentheses
,
4756 "suggest parentheses around assignment used as "
4758 TREE_NO_WARNING (expr
) = 1;
4766 if (TREE_CODE (TREE_TYPE (expr
)) == COMPLEX_TYPE
)
4768 tree t
= (in_late_binary_op
? save_expr (expr
) : c_save_expr (expr
));
4769 expr
= (build_binary_op
4770 (EXPR_LOCATION (expr
),
4771 (TREE_SIDE_EFFECTS (expr
)
4772 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4773 c_common_truthvalue_conversion
4775 build_unary_op (location
, REALPART_EXPR
, t
, false)),
4776 c_common_truthvalue_conversion
4778 build_unary_op (location
, IMAGPART_EXPR
, t
, false)),
4783 if (TREE_CODE (TREE_TYPE (expr
)) == FIXED_POINT_TYPE
)
4785 tree fixed_zero_node
= build_fixed (TREE_TYPE (expr
),
4787 (TREE_TYPE (expr
))));
4788 return build_binary_op (location
, NE_EXPR
, expr
, fixed_zero_node
, 1);
4791 return build_binary_op (location
, NE_EXPR
, expr
, integer_zero_node
, 1);
4794 protected_set_expr_location (expr
, location
);
4798 static void def_builtin_1 (enum built_in_function fncode
,
4800 enum built_in_class fnclass
,
4801 tree fntype
, tree libtype
,
4802 bool both_p
, bool fallback_p
, bool nonansi_p
,
4803 tree fnattrs
, bool implicit_p
);
4806 /* Apply the TYPE_QUALS to the new DECL. */
4809 c_apply_type_quals_to_decl (int type_quals
, tree decl
)
4811 tree type
= TREE_TYPE (decl
);
4813 if (type
== error_mark_node
)
4816 if ((type_quals
& TYPE_QUAL_CONST
)
4817 || (type
&& TREE_CODE (type
) == REFERENCE_TYPE
))
4818 /* We used to check TYPE_NEEDS_CONSTRUCTING here, but now a constexpr
4819 constructor can produce constant init, so rely on cp_finish_decl to
4820 clear TREE_READONLY if the variable has non-constant init. */
4821 TREE_READONLY (decl
) = 1;
4822 if (type_quals
& TYPE_QUAL_VOLATILE
)
4824 TREE_SIDE_EFFECTS (decl
) = 1;
4825 TREE_THIS_VOLATILE (decl
) = 1;
4827 if (type_quals
& TYPE_QUAL_RESTRICT
)
4829 while (type
&& TREE_CODE (type
) == ARRAY_TYPE
)
4830 /* Allow 'restrict' on arrays of pointers.
4831 FIXME currently we just ignore it. */
4832 type
= TREE_TYPE (type
);
4834 || !POINTER_TYPE_P (type
)
4835 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type
)))
4836 error ("invalid use of %<restrict%>");
4840 struct c_type_hasher
: ggc_ptr_hash
<tree_node
>
4842 static hashval_t
hash (tree
);
4843 static bool equal (tree
, tree
);
4846 /* Hash function for the problem of multiple type definitions in
4847 different files. This must hash all types that will compare
4848 equal via comptypes to the same value. In practice it hashes
4849 on some of the simple stuff and leaves the details to comptypes. */
4852 c_type_hasher::hash (tree t
)
4857 switch (TREE_CODE (t
))
4859 /* For pointers, hash on pointee type plus some swizzling. */
4861 return hash (TREE_TYPE (t
)) ^ 0x3003003;
4862 /* Hash on number of elements and total size. */
4865 t2
= TYPE_VALUES (t
);
4869 t2
= TYPE_FIELDS (t
);
4871 case QUAL_UNION_TYPE
:
4873 t2
= TYPE_FIELDS (t
);
4877 t2
= TYPE_FIELDS (t
);
4882 /* FIXME: We want to use a DECL_CHAIN iteration method here, but
4883 TYPE_VALUES of ENUMERAL_TYPEs is stored as a TREE_LIST. */
4884 n_elements
= list_length (t2
);
4885 /* We might have a VLA here. */
4886 if (TREE_CODE (TYPE_SIZE (t
)) != INTEGER_CST
)
4889 size
= TREE_INT_CST_LOW (TYPE_SIZE (t
));
4890 return ((size
<< 24) | (n_elements
<< shift
));
4894 c_type_hasher::equal (tree t1
, tree t2
)
4896 return lang_hooks
.types_compatible_p (t1
, t2
);
4899 static GTY(()) hash_table
<c_type_hasher
> *type_hash_table
;
4901 /* Return the typed-based alias set for T, which may be an expression
4902 or a type. Return -1 if we don't do anything special. */
4905 c_common_get_alias_set (tree t
)
4907 /* For VLAs, use the alias set of the element type rather than the
4908 default of alias set 0 for types compared structurally. */
4909 if (TYPE_P (t
) && TYPE_STRUCTURAL_EQUALITY_P (t
))
4911 if (TREE_CODE (t
) == ARRAY_TYPE
)
4912 return get_alias_set (TREE_TYPE (t
));
4916 /* That's all the expressions we handle specially. */
4920 /* The C standard guarantees that any object may be accessed via an
4921 lvalue that has character type. */
4922 if (t
== char_type_node
4923 || t
== signed_char_type_node
4924 || t
== unsigned_char_type_node
)
4927 /* The C standard specifically allows aliasing between signed and
4928 unsigned variants of the same type. We treat the signed
4929 variant as canonical. */
4930 if (TREE_CODE (t
) == INTEGER_TYPE
&& TYPE_UNSIGNED (t
))
4932 tree t1
= c_common_signed_type (t
);
4934 /* t1 == t can happen for boolean nodes which are always unsigned. */
4936 return get_alias_set (t1
);
4939 /* Handle the case of multiple type nodes referring to "the same" type,
4940 which occurs with IMA. These share an alias set. FIXME: Currently only
4941 C90 is handled. (In C99 type compatibility is not transitive, which
4942 complicates things mightily. The alias set splay trees can theoretically
4943 represent this, but insertion is tricky when you consider all the
4944 different orders things might arrive in.) */
4946 if (c_language
!= clk_c
|| flag_isoc99
)
4949 /* Save time if there's only one input file. */
4950 if (num_in_fnames
== 1)
4953 /* Pointers need special handling if they point to any type that
4954 needs special handling (below). */
4955 if (TREE_CODE (t
) == POINTER_TYPE
)
4958 /* Find bottom type under any nested POINTERs. */
4959 for (t2
= TREE_TYPE (t
);
4960 TREE_CODE (t2
) == POINTER_TYPE
;
4961 t2
= TREE_TYPE (t2
))
4963 if (!RECORD_OR_UNION_TYPE_P (t2
)
4964 && TREE_CODE (t2
) != ENUMERAL_TYPE
)
4966 if (TYPE_SIZE (t2
) == 0)
4969 /* These are the only cases that need special handling. */
4970 if (!RECORD_OR_UNION_TYPE_P (t
)
4971 && TREE_CODE (t
) != ENUMERAL_TYPE
4972 && TREE_CODE (t
) != POINTER_TYPE
)
4975 if (TYPE_SIZE (t
) == 0)
4978 /* Look up t in hash table. Only one of the compatible types within each
4979 alias set is recorded in the table. */
4980 if (!type_hash_table
)
4981 type_hash_table
= hash_table
<c_type_hasher
>::create_ggc (1021);
4982 tree
*slot
= type_hash_table
->find_slot (t
, INSERT
);
4985 TYPE_ALIAS_SET (t
) = TYPE_ALIAS_SET ((tree
)*slot
);
4986 return TYPE_ALIAS_SET ((tree
)*slot
);
4989 /* Our caller will assign and record (in t) a new alias set; all we need
4990 to do is remember t in the hash table. */
4996 /* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where
4997 the IS_SIZEOF parameter indicates which operator is being applied.
4998 The COMPLAIN flag controls whether we should diagnose possibly
4999 ill-formed constructs or not. LOC is the location of the SIZEOF or
5000 TYPEOF operator. If MIN_ALIGNOF, the least alignment required for
5001 a type in any context should be returned, rather than the normal
5002 alignment for that type. */
5005 c_sizeof_or_alignof_type (location_t loc
,
5006 tree type
, bool is_sizeof
, bool min_alignof
,
5009 const char *op_name
;
5011 enum tree_code type_code
= TREE_CODE (type
);
5013 op_name
= is_sizeof
? "sizeof" : "__alignof__";
5015 if (type_code
== FUNCTION_TYPE
)
5019 if (complain
&& warn_pointer_arith
)
5020 pedwarn (loc
, OPT_Wpointer_arith
,
5021 "invalid application of %<sizeof%> to a function type");
5023 return error_mark_node
;
5024 value
= size_one_node
;
5030 if (c_dialect_cxx ())
5031 pedwarn (loc
, OPT_Wpedantic
, "ISO C++ does not permit "
5032 "%<alignof%> applied to a function type");
5034 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not permit "
5035 "%<_Alignof%> applied to a function type");
5037 value
= size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
5040 else if (type_code
== VOID_TYPE
|| type_code
== ERROR_MARK
)
5042 if (type_code
== VOID_TYPE
5043 && complain
&& warn_pointer_arith
)
5044 pedwarn (loc
, OPT_Wpointer_arith
,
5045 "invalid application of %qs to a void type", op_name
);
5047 return error_mark_node
;
5048 value
= size_one_node
;
5050 else if (!COMPLETE_TYPE_P (type
)
5051 && (!c_dialect_cxx () || is_sizeof
|| type_code
!= ARRAY_TYPE
))
5054 error_at (loc
, "invalid application of %qs to incomplete type %qT",
5056 return error_mark_node
;
5058 else if (c_dialect_cxx () && type_code
== ARRAY_TYPE
5059 && !COMPLETE_TYPE_P (TREE_TYPE (type
)))
5062 error_at (loc
, "invalid application of %qs to array type %qT of "
5063 "incomplete element type", op_name
, type
);
5064 return error_mark_node
;
5069 /* Convert in case a char is more than one unit. */
5070 value
= size_binop_loc (loc
, CEIL_DIV_EXPR
, TYPE_SIZE_UNIT (type
),
5071 size_int (TYPE_PRECISION (char_type_node
)
5073 else if (min_alignof
)
5074 value
= size_int (min_align_of_type (type
));
5076 value
= size_int (TYPE_ALIGN_UNIT (type
));
5079 /* VALUE will have the middle-end integer type sizetype.
5080 However, we should really return a value of type `size_t',
5081 which is just a typedef for an ordinary integer type. */
5082 value
= fold_convert_loc (loc
, size_type_node
, value
);
5087 /* Implement the __alignof keyword: Return the minimum required
5088 alignment of EXPR, measured in bytes. For VAR_DECLs,
5089 FUNCTION_DECLs and FIELD_DECLs return DECL_ALIGN (which can be set
5090 from an "aligned" __attribute__ specification). LOC is the
5091 location of the ALIGNOF operator. */
5094 c_alignof_expr (location_t loc
, tree expr
)
5098 if (VAR_OR_FUNCTION_DECL_P (expr
))
5099 t
= size_int (DECL_ALIGN_UNIT (expr
));
5101 else if (TREE_CODE (expr
) == COMPONENT_REF
5102 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
, 1)))
5104 error_at (loc
, "%<__alignof%> applied to a bit-field");
5107 else if (TREE_CODE (expr
) == COMPONENT_REF
5108 && TREE_CODE (TREE_OPERAND (expr
, 1)) == FIELD_DECL
)
5109 t
= size_int (DECL_ALIGN_UNIT (TREE_OPERAND (expr
, 1)));
5111 else if (INDIRECT_REF_P (expr
))
5113 tree t
= TREE_OPERAND (expr
, 0);
5115 int bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
5117 while (CONVERT_EXPR_P (t
)
5118 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
5122 t
= TREE_OPERAND (t
, 0);
5123 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
5124 if (thisalign
> bestalign
)
5125 best
= t
, bestalign
= thisalign
;
5127 return c_alignof (loc
, TREE_TYPE (TREE_TYPE (best
)));
5130 return c_alignof (loc
, TREE_TYPE (expr
));
5132 return fold_convert_loc (loc
, size_type_node
, t
);
5135 /* Handle C and C++ default attributes. */
5137 enum built_in_attribute
5139 #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
5140 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
5141 #define DEF_ATTR_STRING(ENUM, VALUE) ENUM,
5142 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
5143 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
5144 #include "builtin-attrs.def"
5145 #undef DEF_ATTR_NULL_TREE
5147 #undef DEF_ATTR_STRING
5148 #undef DEF_ATTR_IDENT
5149 #undef DEF_ATTR_TREE_LIST
5153 static GTY(()) tree built_in_attributes
[(int) ATTR_LAST
];
5155 static void c_init_attributes (void);
5159 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
5160 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
5161 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
5162 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
5163 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
5164 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
5165 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
5166 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5168 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5170 #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5171 ARG6, ARG7, ARG8) NAME,
5172 #define DEF_FUNCTION_TYPE_9(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5173 ARG6, ARG7, ARG8, ARG9) NAME,
5174 #define DEF_FUNCTION_TYPE_10(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5175 ARG6, ARG7, ARG8, ARG9, ARG10) NAME,
5176 #define DEF_FUNCTION_TYPE_11(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5177 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) NAME,
5178 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
5179 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
5180 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
5181 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
5182 #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
5183 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5185 #define DEF_FUNCTION_TYPE_VAR_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5187 #define DEF_FUNCTION_TYPE_VAR_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5189 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
5190 #include "builtin-types.def"
5191 #undef DEF_PRIMITIVE_TYPE
5192 #undef DEF_FUNCTION_TYPE_0
5193 #undef DEF_FUNCTION_TYPE_1
5194 #undef DEF_FUNCTION_TYPE_2
5195 #undef DEF_FUNCTION_TYPE_3
5196 #undef DEF_FUNCTION_TYPE_4
5197 #undef DEF_FUNCTION_TYPE_5
5198 #undef DEF_FUNCTION_TYPE_6
5199 #undef DEF_FUNCTION_TYPE_7
5200 #undef DEF_FUNCTION_TYPE_8
5201 #undef DEF_FUNCTION_TYPE_9
5202 #undef DEF_FUNCTION_TYPE_10
5203 #undef DEF_FUNCTION_TYPE_11
5204 #undef DEF_FUNCTION_TYPE_VAR_0
5205 #undef DEF_FUNCTION_TYPE_VAR_1
5206 #undef DEF_FUNCTION_TYPE_VAR_2
5207 #undef DEF_FUNCTION_TYPE_VAR_3
5208 #undef DEF_FUNCTION_TYPE_VAR_4
5209 #undef DEF_FUNCTION_TYPE_VAR_5
5210 #undef DEF_FUNCTION_TYPE_VAR_6
5211 #undef DEF_FUNCTION_TYPE_VAR_7
5212 #undef DEF_POINTER_TYPE
5216 typedef enum c_builtin_type builtin_type
;
5218 /* A temporary array for c_common_nodes_and_builtins. Used in
5219 communication with def_fn_type. */
5220 static tree builtin_types
[(int) BT_LAST
+ 1];
5222 /* A helper function for c_common_nodes_and_builtins. Build function type
5223 for DEF with return type RET and N arguments. If VAR is true, then the
5224 function should be variadic after those N arguments.
5226 Takes special care not to ICE if any of the types involved are
5227 error_mark_node, which indicates that said type is not in fact available
5228 (see builtin_type_for_size). In which case the function type as a whole
5229 should be error_mark_node. */
5232 def_fn_type (builtin_type def
, builtin_type ret
, bool var
, int n
, ...)
5235 tree
*args
= XALLOCAVEC (tree
, n
);
5240 for (i
= 0; i
< n
; ++i
)
5242 builtin_type a
= (builtin_type
) va_arg (list
, int);
5243 t
= builtin_types
[a
];
5244 if (t
== error_mark_node
)
5249 t
= builtin_types
[ret
];
5250 if (t
== error_mark_node
)
5253 t
= build_varargs_function_type_array (t
, n
, args
);
5255 t
= build_function_type_array (t
, n
, args
);
5258 builtin_types
[def
] = t
;
5262 /* Build builtin functions common to both C and C++ language
5266 c_define_builtins (tree va_list_ref_type_node
, tree va_list_arg_type_node
)
5268 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
5269 builtin_types[ENUM] = VALUE;
5270 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
5271 def_fn_type (ENUM, RETURN, 0, 0);
5272 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
5273 def_fn_type (ENUM, RETURN, 0, 1, ARG1);
5274 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
5275 def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
5276 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
5277 def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
5278 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
5279 def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
5280 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5281 def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
5282 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5284 def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
5285 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5287 def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
5288 #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5290 def_fn_type (ENUM, RETURN, 0, 8, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
5292 #define DEF_FUNCTION_TYPE_9(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5293 ARG6, ARG7, ARG8, ARG9) \
5294 def_fn_type (ENUM, RETURN, 0, 9, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
5296 #define DEF_FUNCTION_TYPE_10(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5297 ARG6, ARG7, ARG8, ARG9, ARG10) \
5298 def_fn_type (ENUM, RETURN, 0, 10, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
5299 ARG7, ARG8, ARG9, ARG10);
5300 #define DEF_FUNCTION_TYPE_11(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5301 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) \
5302 def_fn_type (ENUM, RETURN, 0, 11, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
5303 ARG7, ARG8, ARG9, ARG10, ARG11);
5304 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
5305 def_fn_type (ENUM, RETURN, 1, 0);
5306 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
5307 def_fn_type (ENUM, RETURN, 1, 1, ARG1);
5308 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
5309 def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
5310 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
5311 def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
5312 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
5313 def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
5314 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5315 def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
5316 #define DEF_FUNCTION_TYPE_VAR_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5318 def_fn_type (ENUM, RETURN, 1, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
5319 #define DEF_FUNCTION_TYPE_VAR_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5321 def_fn_type (ENUM, RETURN, 1, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
5322 #define DEF_POINTER_TYPE(ENUM, TYPE) \
5323 builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
5325 #include "builtin-types.def"
5327 #undef DEF_PRIMITIVE_TYPE
5328 #undef DEF_FUNCTION_TYPE_0
5329 #undef DEF_FUNCTION_TYPE_1
5330 #undef DEF_FUNCTION_TYPE_2
5331 #undef DEF_FUNCTION_TYPE_3
5332 #undef DEF_FUNCTION_TYPE_4
5333 #undef DEF_FUNCTION_TYPE_5
5334 #undef DEF_FUNCTION_TYPE_6
5335 #undef DEF_FUNCTION_TYPE_7
5336 #undef DEF_FUNCTION_TYPE_8
5337 #undef DEF_FUNCTION_TYPE_9
5338 #undef DEF_FUNCTION_TYPE_10
5339 #undef DEF_FUNCTION_TYPE_11
5340 #undef DEF_FUNCTION_TYPE_VAR_0
5341 #undef DEF_FUNCTION_TYPE_VAR_1
5342 #undef DEF_FUNCTION_TYPE_VAR_2
5343 #undef DEF_FUNCTION_TYPE_VAR_3
5344 #undef DEF_FUNCTION_TYPE_VAR_4
5345 #undef DEF_FUNCTION_TYPE_VAR_5
5346 #undef DEF_FUNCTION_TYPE_VAR_6
5347 #undef DEF_FUNCTION_TYPE_VAR_7
5348 #undef DEF_POINTER_TYPE
5349 builtin_types
[(int) BT_LAST
] = NULL_TREE
;
5351 c_init_attributes ();
5353 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P, \
5354 NONANSI_P, ATTRS, IMPLICIT, COND) \
5356 def_builtin_1 (ENUM, NAME, CLASS, \
5357 builtin_types[(int) TYPE], \
5358 builtin_types[(int) LIBTYPE], \
5359 BOTH_P, FALLBACK_P, NONANSI_P, \
5360 built_in_attributes[(int) ATTRS], IMPLICIT);
5361 #include "builtins.def"
5363 targetm
.init_builtins ();
5365 build_common_builtin_nodes ();
5368 cilk_init_builtins ();
5371 /* Like get_identifier, but avoid warnings about null arguments when
5372 the argument may be NULL for targets where GCC lacks stdint.h type
5376 c_get_ident (const char *id
)
5378 return get_identifier (id
);
5381 /* Build tree nodes and builtin functions common to both C and C++ language
5385 c_common_nodes_and_builtins (void)
5387 int char16_type_size
;
5388 int char32_type_size
;
5389 int wchar_type_size
;
5390 tree array_domain_type
;
5391 tree va_list_ref_type_node
;
5392 tree va_list_arg_type_node
;
5395 build_common_tree_nodes (flag_signed_char
);
5397 /* Define `int' and `char' first so that dbx will output them first. */
5398 record_builtin_type (RID_INT
, NULL
, integer_type_node
);
5399 record_builtin_type (RID_CHAR
, "char", char_type_node
);
5401 /* `signed' is the same as `int'. FIXME: the declarations of "signed",
5402 "unsigned long", "long long unsigned" and "unsigned short" were in C++
5403 but not C. Are the conditionals here needed? */
5404 if (c_dialect_cxx ())
5405 record_builtin_type (RID_SIGNED
, NULL
, integer_type_node
);
5406 record_builtin_type (RID_LONG
, "long int", long_integer_type_node
);
5407 record_builtin_type (RID_UNSIGNED
, "unsigned int", unsigned_type_node
);
5408 record_builtin_type (RID_MAX
, "long unsigned int",
5409 long_unsigned_type_node
);
5411 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
5415 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
5416 record_builtin_type ((enum rid
)(RID_FIRST_INT_N
+ i
), name
,
5417 int_n_trees
[i
].signed_type
);
5418 sprintf (name
, "__int%d unsigned", int_n_data
[i
].bitsize
);
5419 record_builtin_type (RID_MAX
, name
, int_n_trees
[i
].unsigned_type
);
5422 if (c_dialect_cxx ())
5423 record_builtin_type (RID_MAX
, "unsigned long", long_unsigned_type_node
);
5424 record_builtin_type (RID_MAX
, "long long int",
5425 long_long_integer_type_node
);
5426 record_builtin_type (RID_MAX
, "long long unsigned int",
5427 long_long_unsigned_type_node
);
5428 if (c_dialect_cxx ())
5429 record_builtin_type (RID_MAX
, "long long unsigned",
5430 long_long_unsigned_type_node
);
5431 record_builtin_type (RID_SHORT
, "short int", short_integer_type_node
);
5432 record_builtin_type (RID_MAX
, "short unsigned int",
5433 short_unsigned_type_node
);
5434 if (c_dialect_cxx ())
5435 record_builtin_type (RID_MAX
, "unsigned short",
5436 short_unsigned_type_node
);
5438 /* Define both `signed char' and `unsigned char'. */
5439 record_builtin_type (RID_MAX
, "signed char", signed_char_type_node
);
5440 record_builtin_type (RID_MAX
, "unsigned char", unsigned_char_type_node
);
5442 /* These are types that c_common_type_for_size and
5443 c_common_type_for_mode use. */
5444 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5445 TYPE_DECL
, NULL_TREE
,
5447 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5448 TYPE_DECL
, NULL_TREE
,
5450 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5451 TYPE_DECL
, NULL_TREE
,
5453 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5454 TYPE_DECL
, NULL_TREE
,
5456 #if HOST_BITS_PER_WIDE_INT >= 64
5457 /* Note that this is different than the __int128 type that's part of
5458 the generic __intN support. */
5459 if (targetm
.scalar_mode_supported_p (TImode
))
5460 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5462 get_identifier ("__int128_t"),
5465 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5466 TYPE_DECL
, NULL_TREE
,
5467 unsigned_intQI_type_node
));
5468 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5469 TYPE_DECL
, NULL_TREE
,
5470 unsigned_intHI_type_node
));
5471 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5472 TYPE_DECL
, NULL_TREE
,
5473 unsigned_intSI_type_node
));
5474 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5475 TYPE_DECL
, NULL_TREE
,
5476 unsigned_intDI_type_node
));
5477 #if HOST_BITS_PER_WIDE_INT >= 64
5478 if (targetm
.scalar_mode_supported_p (TImode
))
5479 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5481 get_identifier ("__uint128_t"),
5482 unsigned_intTI_type_node
));
5485 /* Create the widest literal types. */
5486 widest_integer_literal_type_node
5487 = make_signed_type (HOST_BITS_PER_WIDE_INT
* 2);
5488 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5489 TYPE_DECL
, NULL_TREE
,
5490 widest_integer_literal_type_node
));
5492 widest_unsigned_literal_type_node
5493 = make_unsigned_type (HOST_BITS_PER_WIDE_INT
* 2);
5494 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5495 TYPE_DECL
, NULL_TREE
,
5496 widest_unsigned_literal_type_node
));
5498 signed_size_type_node
= c_common_signed_type (size_type_node
);
5501 TREE_TYPE (identifier_global_value (get_identifier (PID_TYPE
)));
5503 record_builtin_type (RID_FLOAT
, NULL
, float_type_node
);
5504 record_builtin_type (RID_DOUBLE
, NULL
, double_type_node
);
5505 record_builtin_type (RID_MAX
, "long double", long_double_type_node
);
5507 if (!c_dialect_cxx ())
5508 for (i
= 0; i
< NUM_FLOATN_NX_TYPES
; i
++)
5509 if (FLOATN_NX_TYPE_NODE (i
) != NULL_TREE
)
5510 record_builtin_type ((enum rid
) (RID_FLOATN_NX_FIRST
+ i
), NULL
,
5511 FLOATN_NX_TYPE_NODE (i
));
5513 /* Only supported decimal floating point extension if the target
5514 actually supports underlying modes. */
5515 if (targetm
.scalar_mode_supported_p (SDmode
)
5516 && targetm
.scalar_mode_supported_p (DDmode
)
5517 && targetm
.scalar_mode_supported_p (TDmode
))
5519 record_builtin_type (RID_DFLOAT32
, NULL
, dfloat32_type_node
);
5520 record_builtin_type (RID_DFLOAT64
, NULL
, dfloat64_type_node
);
5521 record_builtin_type (RID_DFLOAT128
, NULL
, dfloat128_type_node
);
5524 if (targetm
.fixed_point_supported_p ())
5526 record_builtin_type (RID_MAX
, "short _Fract", short_fract_type_node
);
5527 record_builtin_type (RID_FRACT
, NULL
, fract_type_node
);
5528 record_builtin_type (RID_MAX
, "long _Fract", long_fract_type_node
);
5529 record_builtin_type (RID_MAX
, "long long _Fract",
5530 long_long_fract_type_node
);
5531 record_builtin_type (RID_MAX
, "unsigned short _Fract",
5532 unsigned_short_fract_type_node
);
5533 record_builtin_type (RID_MAX
, "unsigned _Fract",
5534 unsigned_fract_type_node
);
5535 record_builtin_type (RID_MAX
, "unsigned long _Fract",
5536 unsigned_long_fract_type_node
);
5537 record_builtin_type (RID_MAX
, "unsigned long long _Fract",
5538 unsigned_long_long_fract_type_node
);
5539 record_builtin_type (RID_MAX
, "_Sat short _Fract",
5540 sat_short_fract_type_node
);
5541 record_builtin_type (RID_MAX
, "_Sat _Fract", sat_fract_type_node
);
5542 record_builtin_type (RID_MAX
, "_Sat long _Fract",
5543 sat_long_fract_type_node
);
5544 record_builtin_type (RID_MAX
, "_Sat long long _Fract",
5545 sat_long_long_fract_type_node
);
5546 record_builtin_type (RID_MAX
, "_Sat unsigned short _Fract",
5547 sat_unsigned_short_fract_type_node
);
5548 record_builtin_type (RID_MAX
, "_Sat unsigned _Fract",
5549 sat_unsigned_fract_type_node
);
5550 record_builtin_type (RID_MAX
, "_Sat unsigned long _Fract",
5551 sat_unsigned_long_fract_type_node
);
5552 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Fract",
5553 sat_unsigned_long_long_fract_type_node
);
5554 record_builtin_type (RID_MAX
, "short _Accum", short_accum_type_node
);
5555 record_builtin_type (RID_ACCUM
, NULL
, accum_type_node
);
5556 record_builtin_type (RID_MAX
, "long _Accum", long_accum_type_node
);
5557 record_builtin_type (RID_MAX
, "long long _Accum",
5558 long_long_accum_type_node
);
5559 record_builtin_type (RID_MAX
, "unsigned short _Accum",
5560 unsigned_short_accum_type_node
);
5561 record_builtin_type (RID_MAX
, "unsigned _Accum",
5562 unsigned_accum_type_node
);
5563 record_builtin_type (RID_MAX
, "unsigned long _Accum",
5564 unsigned_long_accum_type_node
);
5565 record_builtin_type (RID_MAX
, "unsigned long long _Accum",
5566 unsigned_long_long_accum_type_node
);
5567 record_builtin_type (RID_MAX
, "_Sat short _Accum",
5568 sat_short_accum_type_node
);
5569 record_builtin_type (RID_MAX
, "_Sat _Accum", sat_accum_type_node
);
5570 record_builtin_type (RID_MAX
, "_Sat long _Accum",
5571 sat_long_accum_type_node
);
5572 record_builtin_type (RID_MAX
, "_Sat long long _Accum",
5573 sat_long_long_accum_type_node
);
5574 record_builtin_type (RID_MAX
, "_Sat unsigned short _Accum",
5575 sat_unsigned_short_accum_type_node
);
5576 record_builtin_type (RID_MAX
, "_Sat unsigned _Accum",
5577 sat_unsigned_accum_type_node
);
5578 record_builtin_type (RID_MAX
, "_Sat unsigned long _Accum",
5579 sat_unsigned_long_accum_type_node
);
5580 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Accum",
5581 sat_unsigned_long_long_accum_type_node
);
5585 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5587 get_identifier ("complex int"),
5588 complex_integer_type_node
));
5589 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5591 get_identifier ("complex float"),
5592 complex_float_type_node
));
5593 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5595 get_identifier ("complex double"),
5596 complex_double_type_node
));
5597 lang_hooks
.decls
.pushdecl
5598 (build_decl (UNKNOWN_LOCATION
,
5599 TYPE_DECL
, get_identifier ("complex long double"),
5600 complex_long_double_type_node
));
5602 if (!c_dialect_cxx ())
5603 for (i
= 0; i
< NUM_FLOATN_NX_TYPES
; i
++)
5604 if (COMPLEX_FLOATN_NX_TYPE_NODE (i
) != NULL_TREE
)
5607 sprintf (buf
, "complex _Float%d%s", floatn_nx_types
[i
].n
,
5608 floatn_nx_types
[i
].extended
? "x" : "");
5609 lang_hooks
.decls
.pushdecl
5610 (build_decl (UNKNOWN_LOCATION
,
5612 get_identifier (buf
),
5613 COMPLEX_FLOATN_NX_TYPE_NODE (i
)));
5616 if (c_dialect_cxx ())
5617 /* For C++, make fileptr_type_node a distinct void * type until
5618 FILE type is defined. */
5619 fileptr_type_node
= build_variant_type_copy (ptr_type_node
);
5621 record_builtin_type (RID_VOID
, NULL
, void_type_node
);
5623 /* Set the TYPE_NAME for any variants that were built before
5624 record_builtin_type gave names to the built-in types. */
5626 tree void_name
= TYPE_NAME (void_type_node
);
5627 TYPE_NAME (void_type_node
) = NULL_TREE
;
5628 TYPE_NAME (build_qualified_type (void_type_node
, TYPE_QUAL_CONST
))
5630 TYPE_NAME (void_type_node
) = void_name
;
5633 void_list_node
= build_void_list_node ();
5635 /* Make a type to be the domain of a few array types
5636 whose domains don't really matter.
5637 200 is small enough that it always fits in size_t
5638 and large enough that it can hold most function names for the
5639 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
5640 array_domain_type
= build_index_type (size_int (200));
5642 /* Make a type for arrays of characters.
5643 With luck nothing will ever really depend on the length of this
5645 char_array_type_node
5646 = build_array_type (char_type_node
, array_domain_type
);
5648 string_type_node
= build_pointer_type (char_type_node
);
5649 const_string_type_node
5650 = build_pointer_type (build_qualified_type
5651 (char_type_node
, TYPE_QUAL_CONST
));
5653 /* This is special for C++ so functions can be overloaded. */
5654 wchar_type_node
= get_identifier (MODIFIED_WCHAR_TYPE
);
5655 wchar_type_node
= TREE_TYPE (identifier_global_value (wchar_type_node
));
5656 wchar_type_size
= TYPE_PRECISION (wchar_type_node
);
5657 underlying_wchar_type_node
= wchar_type_node
;
5658 if (c_dialect_cxx ())
5660 if (TYPE_UNSIGNED (wchar_type_node
))
5661 wchar_type_node
= make_unsigned_type (wchar_type_size
);
5663 wchar_type_node
= make_signed_type (wchar_type_size
);
5664 record_builtin_type (RID_WCHAR
, "wchar_t", wchar_type_node
);
5667 /* This is for wide string constants. */
5668 wchar_array_type_node
5669 = build_array_type (wchar_type_node
, array_domain_type
);
5671 /* Define 'char16_t'. */
5672 char16_type_node
= get_identifier (CHAR16_TYPE
);
5673 char16_type_node
= TREE_TYPE (identifier_global_value (char16_type_node
));
5674 char16_type_size
= TYPE_PRECISION (char16_type_node
);
5675 if (c_dialect_cxx ())
5677 char16_type_node
= make_unsigned_type (char16_type_size
);
5679 if (cxx_dialect
>= cxx11
)
5680 record_builtin_type (RID_CHAR16
, "char16_t", char16_type_node
);
5683 /* This is for UTF-16 string constants. */
5684 char16_array_type_node
5685 = build_array_type (char16_type_node
, array_domain_type
);
5687 /* Define 'char32_t'. */
5688 char32_type_node
= get_identifier (CHAR32_TYPE
);
5689 char32_type_node
= TREE_TYPE (identifier_global_value (char32_type_node
));
5690 char32_type_size
= TYPE_PRECISION (char32_type_node
);
5691 if (c_dialect_cxx ())
5693 char32_type_node
= make_unsigned_type (char32_type_size
);
5695 if (cxx_dialect
>= cxx11
)
5696 record_builtin_type (RID_CHAR32
, "char32_t", char32_type_node
);
5699 /* This is for UTF-32 string constants. */
5700 char32_array_type_node
5701 = build_array_type (char32_type_node
, array_domain_type
);
5704 TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE
)));
5707 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE
)));
5709 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE
)));
5711 if (SIG_ATOMIC_TYPE
)
5712 sig_atomic_type_node
=
5713 TREE_TYPE (identifier_global_value (c_get_ident (SIG_ATOMIC_TYPE
)));
5716 TREE_TYPE (identifier_global_value (c_get_ident (INT8_TYPE
)));
5719 TREE_TYPE (identifier_global_value (c_get_ident (INT16_TYPE
)));
5722 TREE_TYPE (identifier_global_value (c_get_ident (INT32_TYPE
)));
5725 TREE_TYPE (identifier_global_value (c_get_ident (INT64_TYPE
)));
5728 TREE_TYPE (identifier_global_value (c_get_ident (UINT8_TYPE
)));
5730 c_uint16_type_node
= uint16_type_node
=
5731 TREE_TYPE (identifier_global_value (c_get_ident (UINT16_TYPE
)));
5733 c_uint32_type_node
= uint32_type_node
=
5734 TREE_TYPE (identifier_global_value (c_get_ident (UINT32_TYPE
)));
5736 c_uint64_type_node
= uint64_type_node
=
5737 TREE_TYPE (identifier_global_value (c_get_ident (UINT64_TYPE
)));
5738 if (INT_LEAST8_TYPE
)
5739 int_least8_type_node
=
5740 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST8_TYPE
)));
5741 if (INT_LEAST16_TYPE
)
5742 int_least16_type_node
=
5743 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST16_TYPE
)));
5744 if (INT_LEAST32_TYPE
)
5745 int_least32_type_node
=
5746 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST32_TYPE
)));
5747 if (INT_LEAST64_TYPE
)
5748 int_least64_type_node
=
5749 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST64_TYPE
)));
5750 if (UINT_LEAST8_TYPE
)
5751 uint_least8_type_node
=
5752 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST8_TYPE
)));
5753 if (UINT_LEAST16_TYPE
)
5754 uint_least16_type_node
=
5755 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST16_TYPE
)));
5756 if (UINT_LEAST32_TYPE
)
5757 uint_least32_type_node
=
5758 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST32_TYPE
)));
5759 if (UINT_LEAST64_TYPE
)
5760 uint_least64_type_node
=
5761 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST64_TYPE
)));
5763 int_fast8_type_node
=
5764 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST8_TYPE
)));
5765 if (INT_FAST16_TYPE
)
5766 int_fast16_type_node
=
5767 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST16_TYPE
)));
5768 if (INT_FAST32_TYPE
)
5769 int_fast32_type_node
=
5770 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST32_TYPE
)));
5771 if (INT_FAST64_TYPE
)
5772 int_fast64_type_node
=
5773 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST64_TYPE
)));
5774 if (UINT_FAST8_TYPE
)
5775 uint_fast8_type_node
=
5776 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST8_TYPE
)));
5777 if (UINT_FAST16_TYPE
)
5778 uint_fast16_type_node
=
5779 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST16_TYPE
)));
5780 if (UINT_FAST32_TYPE
)
5781 uint_fast32_type_node
=
5782 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST32_TYPE
)));
5783 if (UINT_FAST64_TYPE
)
5784 uint_fast64_type_node
=
5785 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST64_TYPE
)));
5788 TREE_TYPE (identifier_global_value (c_get_ident (INTPTR_TYPE
)));
5791 TREE_TYPE (identifier_global_value (c_get_ident (UINTPTR_TYPE
)));
5793 default_function_type
5794 = build_varargs_function_type_list (integer_type_node
, NULL_TREE
);
5796 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE
)));
5797 unsigned_ptrdiff_type_node
= c_common_unsigned_type (ptrdiff_type_node
);
5799 lang_hooks
.decls
.pushdecl
5800 (build_decl (UNKNOWN_LOCATION
,
5801 TYPE_DECL
, get_identifier ("__builtin_va_list"),
5802 va_list_type_node
));
5803 if (targetm
.enum_va_list_p
)
5809 for (l
= 0; targetm
.enum_va_list_p (l
, &pname
, &ptype
); ++l
)
5811 lang_hooks
.decls
.pushdecl
5812 (build_decl (UNKNOWN_LOCATION
,
5813 TYPE_DECL
, get_identifier (pname
),
5819 if (TREE_CODE (va_list_type_node
) == ARRAY_TYPE
)
5821 va_list_arg_type_node
= va_list_ref_type_node
=
5822 build_pointer_type (TREE_TYPE (va_list_type_node
));
5826 va_list_arg_type_node
= va_list_type_node
;
5827 va_list_ref_type_node
= build_reference_type (va_list_type_node
);
5830 if (!flag_preprocess_only
)
5831 c_define_builtins (va_list_ref_type_node
, va_list_arg_type_node
);
5833 main_identifier_node
= get_identifier ("main");
5835 /* Create the built-in __null node. It is important that this is
5837 null_node
= make_int_cst (1, 1);
5838 TREE_TYPE (null_node
) = c_common_type_for_size (POINTER_SIZE
, 0);
5840 /* Since builtin_types isn't gc'ed, don't export these nodes. */
5841 memset (builtin_types
, 0, sizeof (builtin_types
));
5844 /* The number of named compound-literals generated thus far. */
5845 static GTY(()) int compound_literal_number
;
5847 /* Set DECL_NAME for DECL, a VAR_DECL for a compound-literal. */
5850 set_compound_literal_name (tree decl
)
5853 ASM_FORMAT_PRIVATE_NAME (name
, "__compound_literal",
5854 compound_literal_number
);
5855 compound_literal_number
++;
5856 DECL_NAME (decl
) = get_identifier (name
);
5859 /* build_va_arg helper function. Return a VA_ARG_EXPR with location LOC, type
5860 TYPE and operand OP. */
5863 build_va_arg_1 (location_t loc
, tree type
, tree op
)
5865 tree expr
= build1 (VA_ARG_EXPR
, type
, op
);
5866 SET_EXPR_LOCATION (expr
, loc
);
5870 /* Return a VA_ARG_EXPR corresponding to a source-level expression
5871 va_arg (EXPR, TYPE) at source location LOC. */
5874 build_va_arg (location_t loc
, tree expr
, tree type
)
5876 tree va_type
= TREE_TYPE (expr
);
5877 tree canon_va_type
= (va_type
== error_mark_node
5879 : targetm
.canonical_va_list_type (va_type
));
5881 if (va_type
== error_mark_node
5882 || canon_va_type
== NULL_TREE
)
5884 if (canon_va_type
== NULL_TREE
)
5885 error_at (loc
, "first argument to %<va_arg%> not of type %<va_list%>");
5887 /* Let's handle things neutrallly, if expr:
5888 - has undeclared type, or
5889 - is not an va_list type. */
5890 return build_va_arg_1 (loc
, type
, error_mark_node
);
5893 if (TREE_CODE (canon_va_type
) != ARRAY_TYPE
)
5895 /* Case 1: Not an array type. */
5897 /* Take the address, to get '&ap'. Note that &ap is not a va_list
5899 mark_addressable (expr
);
5900 expr
= build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (expr
)), expr
);
5902 return build_va_arg_1 (loc
, type
, expr
);
5905 /* Case 2: Array type.
5909 For contrast, let's start with the simple case (case 1). If
5910 canon_va_type is not an array type, but say a char *, then when
5911 passing-by-value a va_list, the type of the va_list param decl is
5912 the same as for another va_list decl (all ap's are char *):
5915 D.1815 = VA_ARG (&ap, 0B, 1);
5921 __builtin_va_start (&ap, 0);
5924 __builtin_va_end (&ap);
5928 However, if canon_va_type is ARRAY_TYPE, then when passing-by-value a
5929 va_list the type of the va_list param decl (case 2b, struct * ap) is not
5930 the same as for another va_list decl (case 2a, struct ap[1]).
5933 D.1844 = VA_ARG (ap, 0B, 0);
5938 __builtin_va_start (&ap, 0);
5940 __builtin_va_end (&ap);
5944 Case 2b is different because:
5945 - on the callee side, the parm decl has declared type va_list, but
5946 grokdeclarator changes the type of the parm decl to a pointer to the
5948 - on the caller side, the pass-by-value uses &ap.
5950 We unify these two cases (case 2a: va_list is array type,
5951 case 2b: va_list is pointer to array elem type), by adding '&' for the
5952 array type case, such that we have a pointer to array elem in both
5955 if (TREE_CODE (va_type
) == ARRAY_TYPE
)
5957 /* Case 2a: va_list is array type. */
5959 /* Take the address, to get '&ap'. Make sure it's a pointer to array
5961 mark_addressable (expr
);
5962 expr
= build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (canon_va_type
)),
5965 /* Verify that &ap is still recognized as having va_list type. */
5966 tree canon_expr_type
5967 = targetm
.canonical_va_list_type (TREE_TYPE (expr
));
5968 gcc_assert (canon_expr_type
!= NULL_TREE
);
5972 /* Case 2b: va_list is pointer to array elem type. */
5973 gcc_assert (POINTER_TYPE_P (va_type
));
5975 /* Comparison as in std_canonical_va_list_type. */
5976 gcc_assert (TYPE_MAIN_VARIANT (TREE_TYPE (va_type
))
5977 == TYPE_MAIN_VARIANT (TREE_TYPE (canon_va_type
)));
5979 /* Don't take the address. We've already got '&ap'. */
5983 return build_va_arg_1 (loc
, type
, expr
);
5987 /* Linked list of disabled built-in functions. */
5989 struct disabled_builtin
5992 struct disabled_builtin
*next
;
5994 static disabled_builtin
*disabled_builtins
= NULL
;
5996 static bool builtin_function_disabled_p (const char *);
5998 /* Disable a built-in function specified by -fno-builtin-NAME. If NAME
5999 begins with "__builtin_", give an error. */
6002 disable_builtin_function (const char *name
)
6004 if (strncmp (name
, "__builtin_", strlen ("__builtin_")) == 0)
6005 error ("cannot disable built-in function %qs", name
);
6008 disabled_builtin
*new_disabled_builtin
= XNEW (disabled_builtin
);
6009 new_disabled_builtin
->name
= name
;
6010 new_disabled_builtin
->next
= disabled_builtins
;
6011 disabled_builtins
= new_disabled_builtin
;
6016 /* Return true if the built-in function NAME has been disabled, false
6020 builtin_function_disabled_p (const char *name
)
6022 disabled_builtin
*p
;
6023 for (p
= disabled_builtins
; p
!= NULL
; p
= p
->next
)
6025 if (strcmp (name
, p
->name
) == 0)
6032 /* Worker for DEF_BUILTIN.
6033 Possibly define a builtin function with one or two names.
6034 Does not declare a non-__builtin_ function if flag_no_builtin, or if
6035 nonansi_p and flag_no_nonansi_builtin. */
6038 def_builtin_1 (enum built_in_function fncode
,
6040 enum built_in_class fnclass
,
6041 tree fntype
, tree libtype
,
6042 bool both_p
, bool fallback_p
, bool nonansi_p
,
6043 tree fnattrs
, bool implicit_p
)
6046 const char *libname
;
6048 if (fntype
== error_mark_node
)
6051 gcc_assert ((!both_p
&& !fallback_p
)
6052 || !strncmp (name
, "__builtin_",
6053 strlen ("__builtin_")));
6055 libname
= name
+ strlen ("__builtin_");
6056 decl
= add_builtin_function (name
, fntype
, fncode
, fnclass
,
6057 (fallback_p
? libname
: NULL
),
6060 set_builtin_decl (fncode
, decl
, implicit_p
);
6063 && !flag_no_builtin
&& !builtin_function_disabled_p (libname
)
6064 && !(nonansi_p
&& flag_no_nonansi_builtin
))
6065 add_builtin_function (libname
, libtype
, fncode
, fnclass
,
6069 /* Nonzero if the type T promotes to int. This is (nearly) the
6070 integral promotions defined in ISO C99 6.3.1.1/2. */
6073 c_promoting_integer_type_p (const_tree t
)
6075 switch (TREE_CODE (t
))
6078 return (TYPE_MAIN_VARIANT (t
) == char_type_node
6079 || TYPE_MAIN_VARIANT (t
) == signed_char_type_node
6080 || TYPE_MAIN_VARIANT (t
) == unsigned_char_type_node
6081 || TYPE_MAIN_VARIANT (t
) == short_integer_type_node
6082 || TYPE_MAIN_VARIANT (t
) == short_unsigned_type_node
6083 || TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
));
6086 /* ??? Technically all enumerations not larger than an int
6087 promote to an int. But this is used along code paths
6088 that only want to notice a size change. */
6089 return TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
);
6099 /* Return 1 if PARMS specifies a fixed number of parameters
6100 and none of their types is affected by default promotions. */
6103 self_promoting_args_p (const_tree parms
)
6106 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
6108 tree type
= TREE_VALUE (t
);
6110 if (type
== error_mark_node
)
6113 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
6119 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
6122 if (c_promoting_integer_type_p (type
))
6128 /* Recursively remove any '*' or '&' operator from TYPE. */
6130 strip_pointer_operator (tree t
)
6132 while (POINTER_TYPE_P (t
))
6137 /* Recursively remove pointer or array type from TYPE. */
6139 strip_pointer_or_array_types (tree t
)
6141 while (TREE_CODE (t
) == ARRAY_TYPE
|| POINTER_TYPE_P (t
))
6146 /* Used to compare case labels. K1 and K2 are actually tree nodes
6147 representing case labels, or NULL_TREE for a `default' label.
6148 Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after
6149 K2, and 0 if K1 and K2 are equal. */
6152 case_compare (splay_tree_key k1
, splay_tree_key k2
)
6154 /* Consider a NULL key (such as arises with a `default' label) to be
6155 smaller than anything else. */
6161 return tree_int_cst_compare ((tree
) k1
, (tree
) k2
);
6164 /* Process a case label, located at LOC, for the range LOW_VALUE
6165 ... HIGH_VALUE. If LOW_VALUE and HIGH_VALUE are both NULL_TREE
6166 then this case label is actually a `default' label. If only
6167 HIGH_VALUE is NULL_TREE, then case label was declared using the
6168 usual C/C++ syntax, rather than the GNU case range extension.
6169 CASES is a tree containing all the case ranges processed so far;
6170 COND is the condition for the switch-statement itself.
6171 OUTSIDE_RANGE_P says whether there was a case value that doesn't
6172 fit into the range of the ORIG_TYPE. Returns the CASE_LABEL_EXPR
6173 created, or ERROR_MARK_NODE if no CASE_LABEL_EXPR is created. */
6176 c_add_case_label (location_t loc
, splay_tree cases
, tree cond
, tree orig_type
,
6177 tree low_value
, tree high_value
, bool *outside_range_p
)
6182 splay_tree_node node
;
6184 /* Create the LABEL_DECL itself. */
6185 label
= create_artificial_label (loc
);
6187 /* If there was an error processing the switch condition, bail now
6188 before we get more confused. */
6189 if (!cond
|| cond
== error_mark_node
)
6192 if ((low_value
&& TREE_TYPE (low_value
)
6193 && POINTER_TYPE_P (TREE_TYPE (low_value
)))
6194 || (high_value
&& TREE_TYPE (high_value
)
6195 && POINTER_TYPE_P (TREE_TYPE (high_value
))))
6197 error_at (loc
, "pointers are not permitted as case values");
6201 /* Case ranges are a GNU extension. */
6203 pedwarn (loc
, OPT_Wpedantic
,
6204 "range expressions in switch statements are non-standard");
6206 type
= TREE_TYPE (cond
);
6209 low_value
= check_case_value (loc
, low_value
);
6210 low_value
= convert_and_check (loc
, type
, low_value
);
6211 if (low_value
== error_mark_node
)
6216 high_value
= check_case_value (loc
, high_value
);
6217 high_value
= convert_and_check (loc
, type
, high_value
);
6218 if (high_value
== error_mark_node
)
6222 if (low_value
&& high_value
)
6224 /* If the LOW_VALUE and HIGH_VALUE are the same, then this isn't
6225 really a case range, even though it was written that way.
6226 Remove the HIGH_VALUE to simplify later processing. */
6227 if (tree_int_cst_equal (low_value
, high_value
))
6228 high_value
= NULL_TREE
;
6229 else if (!tree_int_cst_lt (low_value
, high_value
))
6230 warning_at (loc
, 0, "empty range specified");
6233 /* See if the case is in range of the type of the original testing
6234 expression. If both low_value and high_value are out of range,
6235 don't insert the case label and return NULL_TREE. */
6237 && !check_case_bounds (loc
, type
, orig_type
,
6238 &low_value
, high_value
? &high_value
: NULL
,
6242 /* Look up the LOW_VALUE in the table of case labels we already
6244 node
= splay_tree_lookup (cases
, (splay_tree_key
) low_value
);
6245 /* If there was not an exact match, check for overlapping ranges.
6246 There's no need to do this if there's no LOW_VALUE or HIGH_VALUE;
6247 that's a `default' label and the only overlap is an exact match. */
6248 if (!node
&& (low_value
|| high_value
))
6250 splay_tree_node low_bound
;
6251 splay_tree_node high_bound
;
6253 /* Even though there wasn't an exact match, there might be an
6254 overlap between this case range and another case range.
6255 Since we've (inductively) not allowed any overlapping case
6256 ranges, we simply need to find the greatest low case label
6257 that is smaller that LOW_VALUE, and the smallest low case
6258 label that is greater than LOW_VALUE. If there is an overlap
6259 it will occur in one of these two ranges. */
6260 low_bound
= splay_tree_predecessor (cases
,
6261 (splay_tree_key
) low_value
);
6262 high_bound
= splay_tree_successor (cases
,
6263 (splay_tree_key
) low_value
);
6265 /* Check to see if the LOW_BOUND overlaps. It is smaller than
6266 the LOW_VALUE, so there is no need to check unless the
6267 LOW_BOUND is in fact itself a case range. */
6269 && CASE_HIGH ((tree
) low_bound
->value
)
6270 && tree_int_cst_compare (CASE_HIGH ((tree
) low_bound
->value
),
6273 /* Check to see if the HIGH_BOUND overlaps. The low end of that
6274 range is bigger than the low end of the current range, so we
6275 are only interested if the current range is a real range, and
6276 not an ordinary case label. */
6279 && (tree_int_cst_compare ((tree
) high_bound
->key
,
6284 /* If there was an overlap, issue an error. */
6287 tree duplicate
= CASE_LABEL ((tree
) node
->value
);
6291 error_at (loc
, "duplicate (or overlapping) case value");
6292 error_at (DECL_SOURCE_LOCATION (duplicate
),
6293 "this is the first entry overlapping that value");
6297 error_at (loc
, "duplicate case value") ;
6298 error_at (DECL_SOURCE_LOCATION (duplicate
), "previously used here");
6302 error_at (loc
, "multiple default labels in one switch");
6303 error_at (DECL_SOURCE_LOCATION (duplicate
),
6304 "this is the first default label");
6309 /* Add a CASE_LABEL to the statement-tree. */
6310 case_label
= add_stmt (build_case_label (low_value
, high_value
, label
));
6311 /* Register this case label in the splay tree. */
6312 splay_tree_insert (cases
,
6313 (splay_tree_key
) low_value
,
6314 (splay_tree_value
) case_label
);
6319 /* Add a label so that the back-end doesn't think that the beginning of
6320 the switch is unreachable. Note that we do not add a case label, as
6321 that just leads to duplicates and thence to failure later on. */
6324 tree t
= create_artificial_label (loc
);
6325 add_stmt (build_stmt (loc
, LABEL_EXPR
, t
));
6327 return error_mark_node
;
6330 /* Subroutines of c_do_switch_warnings, called via splay_tree_foreach.
6331 Used to verify that case values match up with enumerator values. */
6334 match_case_to_enum_1 (tree key
, tree type
, tree label
)
6336 char buf
[WIDE_INT_PRINT_BUFFER_SIZE
];
6338 if (tree_fits_uhwi_p (key
))
6339 print_dec (key
, buf
, UNSIGNED
);
6340 else if (tree_fits_shwi_p (key
))
6341 print_dec (key
, buf
, SIGNED
);
6343 print_hex (key
, buf
);
6345 if (TYPE_NAME (type
) == 0)
6346 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
6347 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
6348 "case value %qs not in enumerated type",
6351 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
6352 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
6353 "case value %qs not in enumerated type %qT",
6357 /* Subroutine of c_do_switch_warnings, called via splay_tree_foreach.
6358 Used to verify that case values match up with enumerator values. */
6361 match_case_to_enum (splay_tree_node node
, void *data
)
6363 tree label
= (tree
) node
->value
;
6364 tree type
= (tree
) data
;
6366 /* Skip default case. */
6367 if (!CASE_LOW (label
))
6370 /* If CASE_LOW_SEEN is not set, that means CASE_LOW did not appear
6371 when we did our enum->case scan. Reset our scratch bit after. */
6372 if (!CASE_LOW_SEEN (label
))
6373 match_case_to_enum_1 (CASE_LOW (label
), type
, label
);
6375 CASE_LOW_SEEN (label
) = 0;
6377 /* If CASE_HIGH is non-null, we have a range. If CASE_HIGH_SEEN is
6378 not set, that means that CASE_HIGH did not appear when we did our
6379 enum->case scan. Reset our scratch bit after. */
6380 if (CASE_HIGH (label
))
6382 if (!CASE_HIGH_SEEN (label
))
6383 match_case_to_enum_1 (CASE_HIGH (label
), type
, label
);
6385 CASE_HIGH_SEEN (label
) = 0;
6391 /* Handle -Wswitch*. Called from the front end after parsing the
6392 switch construct. */
6393 /* ??? Should probably be somewhere generic, since other languages
6394 besides C and C++ would want this. At the moment, however, C/C++
6395 are the only tree-ssa languages that support enumerations at all,
6396 so the point is moot. */
6399 c_do_switch_warnings (splay_tree cases
, location_t switch_location
,
6400 tree type
, tree cond
, bool bool_cond_p
,
6401 bool outside_range_p
)
6403 splay_tree_node default_node
;
6404 splay_tree_node node
;
6407 if (!warn_switch
&& !warn_switch_enum
&& !warn_switch_default
6408 && !warn_switch_bool
)
6411 default_node
= splay_tree_lookup (cases
, (splay_tree_key
) NULL
);
6413 warning_at (switch_location
, OPT_Wswitch_default
,
6414 "switch missing default case");
6416 /* There are certain cases where -Wswitch-bool warnings aren't
6423 so be careful here. */
6424 if (warn_switch_bool
&& bool_cond_p
)
6426 splay_tree_node min_node
;
6427 /* If there's a default node, it's also the value with the minimal
6428 key. So look at the penultimate key (if any). */
6430 min_node
= splay_tree_successor (cases
, (splay_tree_key
) NULL
);
6432 min_node
= splay_tree_min (cases
);
6433 tree min
= min_node
? (tree
) min_node
->key
: NULL_TREE
;
6435 splay_tree_node max_node
= splay_tree_max (cases
);
6436 /* This might be a case range, so look at the value with the
6437 maximal key and then check CASE_HIGH. */
6438 tree max
= max_node
? (tree
) max_node
->value
: NULL_TREE
;
6440 max
= CASE_HIGH (max
) ? CASE_HIGH (max
) : CASE_LOW (max
);
6442 /* If there's a case value > 1 or < 0, that is outside bool
6445 || (max
&& wi::gts_p (max
, 1))
6446 || (min
&& wi::lts_p (min
, 0))
6454 case, where we want to warn. */
6456 && max
&& wi::eq_p (max
, 1)
6457 && min
&& wi::eq_p (min
, 0)))
6458 warning_at (switch_location
, OPT_Wswitch_bool
,
6459 "switch condition has boolean value");
6462 /* From here on, we only care about enumerated types. */
6463 if (!type
|| TREE_CODE (type
) != ENUMERAL_TYPE
)
6466 /* From here on, we only care about -Wswitch and -Wswitch-enum. */
6467 if (!warn_switch_enum
&& !warn_switch
)
6470 /* Check the cases. Warn about case values which are not members of
6471 the enumerated type. For -Wswitch-enum, or for -Wswitch when
6472 there is no default case, check that exactly all enumeration
6473 literals are covered by the cases. */
6475 /* Clearing COND if it is not an integer constant simplifies
6476 the tests inside the loop below. */
6477 if (TREE_CODE (cond
) != INTEGER_CST
)
6480 /* The time complexity here is O(N*lg(N)) worst case, but for the
6481 common case of monotonically increasing enumerators, it is
6482 O(N), since the nature of the splay tree will keep the next
6483 element adjacent to the root at all times. */
6485 for (chain
= TYPE_VALUES (type
); chain
; chain
= TREE_CHAIN (chain
))
6487 tree value
= TREE_VALUE (chain
);
6488 if (TREE_CODE (value
) == CONST_DECL
)
6489 value
= DECL_INITIAL (value
);
6490 node
= splay_tree_lookup (cases
, (splay_tree_key
) value
);
6493 /* Mark the CASE_LOW part of the case entry as seen. */
6494 tree label
= (tree
) node
->value
;
6495 CASE_LOW_SEEN (label
) = 1;
6499 /* Even though there wasn't an exact match, there might be a
6500 case range which includes the enumerator's value. */
6501 node
= splay_tree_predecessor (cases
, (splay_tree_key
) value
);
6502 if (node
&& CASE_HIGH ((tree
) node
->value
))
6504 tree label
= (tree
) node
->value
;
6505 int cmp
= tree_int_cst_compare (CASE_HIGH (label
), value
);
6508 /* If we match the upper bound exactly, mark the CASE_HIGH
6509 part of the case entry as seen. */
6511 CASE_HIGH_SEEN (label
) = 1;
6516 /* We've now determined that this enumerated literal isn't
6517 handled by the case labels of the switch statement. */
6519 /* If the switch expression is a constant, we only really care
6520 about whether that constant is handled by the switch. */
6521 if (cond
&& tree_int_cst_compare (cond
, value
))
6524 /* If there is a default_node, the only relevant option is
6525 Wswitch-enum. Otherwise, if both are enabled then we prefer
6526 to warn using -Wswitch because -Wswitch is enabled by -Wall
6527 while -Wswitch-enum is explicit. */
6528 warning_at (switch_location
,
6529 (default_node
|| !warn_switch
6532 "enumeration value %qE not handled in switch",
6533 TREE_PURPOSE (chain
));
6536 /* Warn if there are case expressions that don't correspond to
6537 enumerators. This can occur since C and C++ don't enforce
6538 type-checking of assignments to enumeration variables.
6540 The time complexity here is now always O(N) worst case, since
6541 we should have marked both the lower bound and upper bound of
6542 every disjoint case label, with CASE_LOW_SEEN and CASE_HIGH_SEEN
6543 above. This scan also resets those fields. */
6545 splay_tree_foreach (cases
, match_case_to_enum
, type
);
6548 /* Finish an expression taking the address of LABEL (an
6549 IDENTIFIER_NODE). Returns an expression for the address.
6551 LOC is the location for the expression returned. */
6554 finish_label_address_expr (tree label
, location_t loc
)
6558 pedwarn (input_location
, OPT_Wpedantic
, "taking the address of a label is non-standard");
6560 if (label
== error_mark_node
)
6561 return error_mark_node
;
6563 label
= lookup_label (label
);
6564 if (label
== NULL_TREE
)
6565 result
= null_pointer_node
;
6568 TREE_USED (label
) = 1;
6569 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
6570 /* The current function is not necessarily uninlinable.
6571 Computed gotos are incompatible with inlining, but the value
6572 here could be used only in a diagnostic, for example. */
6573 protected_set_expr_location (result
, loc
);
6580 /* Given a boolean expression ARG, return a tree representing an increment
6581 or decrement (as indicated by CODE) of ARG. The front end must check for
6582 invalid cases (e.g., decrement in C++). */
6584 boolean_increment (enum tree_code code
, tree arg
)
6587 tree true_res
= build_int_cst (TREE_TYPE (arg
), 1);
6589 arg
= stabilize_reference (arg
);
6592 case PREINCREMENT_EXPR
:
6593 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
6595 case POSTINCREMENT_EXPR
:
6596 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
6597 arg
= save_expr (arg
);
6598 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
6599 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
6601 case PREDECREMENT_EXPR
:
6602 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
6603 invert_truthvalue_loc (input_location
, arg
));
6605 case POSTDECREMENT_EXPR
:
6606 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
6607 invert_truthvalue_loc (input_location
, arg
));
6608 arg
= save_expr (arg
);
6609 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
6610 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
6615 TREE_SIDE_EFFECTS (val
) = 1;
6619 /* Built-in macros for stddef.h and stdint.h, that require macros
6620 defined in this file. */
6622 c_stddef_cpp_builtins(void)
6624 builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE
, 0);
6625 builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE
, 0);
6626 builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE
, 0);
6627 builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE
, 0);
6628 builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE
, 0);
6629 builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE
, 0);
6630 builtin_define_with_value ("__CHAR16_TYPE__", CHAR16_TYPE
, 0);
6631 builtin_define_with_value ("__CHAR32_TYPE__", CHAR32_TYPE
, 0);
6632 if (SIG_ATOMIC_TYPE
)
6633 builtin_define_with_value ("__SIG_ATOMIC_TYPE__", SIG_ATOMIC_TYPE
, 0);
6635 builtin_define_with_value ("__INT8_TYPE__", INT8_TYPE
, 0);
6637 builtin_define_with_value ("__INT16_TYPE__", INT16_TYPE
, 0);
6639 builtin_define_with_value ("__INT32_TYPE__", INT32_TYPE
, 0);
6641 builtin_define_with_value ("__INT64_TYPE__", INT64_TYPE
, 0);
6643 builtin_define_with_value ("__UINT8_TYPE__", UINT8_TYPE
, 0);
6645 builtin_define_with_value ("__UINT16_TYPE__", UINT16_TYPE
, 0);
6647 builtin_define_with_value ("__UINT32_TYPE__", UINT32_TYPE
, 0);
6649 builtin_define_with_value ("__UINT64_TYPE__", UINT64_TYPE
, 0);
6650 if (INT_LEAST8_TYPE
)
6651 builtin_define_with_value ("__INT_LEAST8_TYPE__", INT_LEAST8_TYPE
, 0);
6652 if (INT_LEAST16_TYPE
)
6653 builtin_define_with_value ("__INT_LEAST16_TYPE__", INT_LEAST16_TYPE
, 0);
6654 if (INT_LEAST32_TYPE
)
6655 builtin_define_with_value ("__INT_LEAST32_TYPE__", INT_LEAST32_TYPE
, 0);
6656 if (INT_LEAST64_TYPE
)
6657 builtin_define_with_value ("__INT_LEAST64_TYPE__", INT_LEAST64_TYPE
, 0);
6658 if (UINT_LEAST8_TYPE
)
6659 builtin_define_with_value ("__UINT_LEAST8_TYPE__", UINT_LEAST8_TYPE
, 0);
6660 if (UINT_LEAST16_TYPE
)
6661 builtin_define_with_value ("__UINT_LEAST16_TYPE__", UINT_LEAST16_TYPE
, 0);
6662 if (UINT_LEAST32_TYPE
)
6663 builtin_define_with_value ("__UINT_LEAST32_TYPE__", UINT_LEAST32_TYPE
, 0);
6664 if (UINT_LEAST64_TYPE
)
6665 builtin_define_with_value ("__UINT_LEAST64_TYPE__", UINT_LEAST64_TYPE
, 0);
6667 builtin_define_with_value ("__INT_FAST8_TYPE__", INT_FAST8_TYPE
, 0);
6668 if (INT_FAST16_TYPE
)
6669 builtin_define_with_value ("__INT_FAST16_TYPE__", INT_FAST16_TYPE
, 0);
6670 if (INT_FAST32_TYPE
)
6671 builtin_define_with_value ("__INT_FAST32_TYPE__", INT_FAST32_TYPE
, 0);
6672 if (INT_FAST64_TYPE
)
6673 builtin_define_with_value ("__INT_FAST64_TYPE__", INT_FAST64_TYPE
, 0);
6674 if (UINT_FAST8_TYPE
)
6675 builtin_define_with_value ("__UINT_FAST8_TYPE__", UINT_FAST8_TYPE
, 0);
6676 if (UINT_FAST16_TYPE
)
6677 builtin_define_with_value ("__UINT_FAST16_TYPE__", UINT_FAST16_TYPE
, 0);
6678 if (UINT_FAST32_TYPE
)
6679 builtin_define_with_value ("__UINT_FAST32_TYPE__", UINT_FAST32_TYPE
, 0);
6680 if (UINT_FAST64_TYPE
)
6681 builtin_define_with_value ("__UINT_FAST64_TYPE__", UINT_FAST64_TYPE
, 0);
6683 builtin_define_with_value ("__INTPTR_TYPE__", INTPTR_TYPE
, 0);
6685 builtin_define_with_value ("__UINTPTR_TYPE__", UINTPTR_TYPE
, 0);
6689 c_init_attributes (void)
6691 /* Fill in the built_in_attributes array. */
6692 #define DEF_ATTR_NULL_TREE(ENUM) \
6693 built_in_attributes[(int) ENUM] = NULL_TREE;
6694 #define DEF_ATTR_INT(ENUM, VALUE) \
6695 built_in_attributes[(int) ENUM] = build_int_cst (integer_type_node, VALUE);
6696 #define DEF_ATTR_STRING(ENUM, VALUE) \
6697 built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
6698 #define DEF_ATTR_IDENT(ENUM, STRING) \
6699 built_in_attributes[(int) ENUM] = get_identifier (STRING);
6700 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
6701 built_in_attributes[(int) ENUM] \
6702 = tree_cons (built_in_attributes[(int) PURPOSE], \
6703 built_in_attributes[(int) VALUE], \
6704 built_in_attributes[(int) CHAIN]);
6705 #include "builtin-attrs.def"
6706 #undef DEF_ATTR_NULL_TREE
6708 #undef DEF_ATTR_IDENT
6709 #undef DEF_ATTR_TREE_LIST
6712 /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain
6713 identifier as an argument, so the front end shouldn't look it up. */
6716 attribute_takes_identifier_p (const_tree attr_id
)
6718 const struct attribute_spec
*spec
= lookup_attribute_spec (attr_id
);
6720 /* Unknown attribute that we'll end up ignoring, return true so we
6721 don't complain about an identifier argument. */
6723 else if (!strcmp ("mode", spec
->name
)
6724 || !strcmp ("format", spec
->name
)
6725 || !strcmp ("cleanup", spec
->name
))
6728 return targetm
.attribute_takes_identifier_p (attr_id
);
6731 /* Attribute handlers common to C front ends. */
6733 /* Handle a "packed" attribute; arguments as in
6734 struct attribute_spec.handler. */
6737 handle_packed_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6738 int flags
, bool *no_add_attrs
)
6742 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6743 *node
= build_variant_type_copy (*node
);
6744 TYPE_PACKED (*node
) = 1;
6746 else if (TREE_CODE (*node
) == FIELD_DECL
)
6748 if (TYPE_ALIGN (TREE_TYPE (*node
)) <= BITS_PER_UNIT
6749 /* Still pack bitfields. */
6750 && ! DECL_INITIAL (*node
))
6751 warning (OPT_Wattributes
,
6752 "%qE attribute ignored for field of type %qT",
6753 name
, TREE_TYPE (*node
));
6755 DECL_PACKED (*node
) = 1;
6757 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
6758 used for DECL_REGISTER. It wouldn't mean anything anyway.
6759 We can't set DECL_PACKED on the type of a TYPE_DECL, because
6760 that changes what the typedef is typing. */
6763 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6764 *no_add_attrs
= true;
6770 /* Handle a "nocommon" attribute; arguments as in
6771 struct attribute_spec.handler. */
6774 handle_nocommon_attribute (tree
*node
, tree name
,
6775 tree
ARG_UNUSED (args
),
6776 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6779 DECL_COMMON (*node
) = 0;
6782 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6783 *no_add_attrs
= true;
6789 /* Handle a "common" attribute; arguments as in
6790 struct attribute_spec.handler. */
6793 handle_common_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6794 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6797 DECL_COMMON (*node
) = 1;
6800 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6801 *no_add_attrs
= true;
6807 /* Handle a "noreturn" attribute; arguments as in
6808 struct attribute_spec.handler. */
6811 handle_noreturn_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6812 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6814 tree type
= TREE_TYPE (*node
);
6816 /* See FIXME comment in c_common_attribute_table. */
6817 if (TREE_CODE (*node
) == FUNCTION_DECL
6818 || objc_method_decl (TREE_CODE (*node
)))
6819 TREE_THIS_VOLATILE (*node
) = 1;
6820 else if (TREE_CODE (type
) == POINTER_TYPE
6821 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
6823 = (build_qualified_type
6825 (build_type_variant (TREE_TYPE (type
),
6826 TYPE_READONLY (TREE_TYPE (type
)), 1)),
6827 TYPE_QUALS (type
)));
6830 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6831 *no_add_attrs
= true;
6837 /* Handle a "hot" and attribute; arguments as in
6838 struct attribute_spec.handler. */
6841 handle_hot_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6842 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6844 if (TREE_CODE (*node
) == FUNCTION_DECL
6845 || TREE_CODE (*node
) == LABEL_DECL
)
6847 if (lookup_attribute ("cold", DECL_ATTRIBUTES (*node
)) != NULL
)
6849 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
6850 "with attribute %qs", name
, "cold");
6851 *no_add_attrs
= true;
6853 /* Most of the rest of the hot processing is done later with
6854 lookup_attribute. */
6858 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6859 *no_add_attrs
= true;
6865 /* Handle a "cold" and attribute; arguments as in
6866 struct attribute_spec.handler. */
6869 handle_cold_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6870 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6872 if (TREE_CODE (*node
) == FUNCTION_DECL
6873 || TREE_CODE (*node
) == LABEL_DECL
)
6875 if (lookup_attribute ("hot", DECL_ATTRIBUTES (*node
)) != NULL
)
6877 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
6878 "with attribute %qs", name
, "hot");
6879 *no_add_attrs
= true;
6881 /* Most of the rest of the cold processing is done later with
6882 lookup_attribute. */
6886 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6887 *no_add_attrs
= true;
6893 /* Handle a "no_sanitize_address" attribute; arguments as in
6894 struct attribute_spec.handler. */
6897 handle_no_sanitize_address_attribute (tree
*node
, tree name
, tree
, int,
6900 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6902 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6903 *no_add_attrs
= true;
6909 /* Handle a "no_address_safety_analysis" attribute; arguments as in
6910 struct attribute_spec.handler. */
6913 handle_no_address_safety_analysis_attribute (tree
*node
, tree name
, tree
, int,
6916 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6917 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6918 else if (!lookup_attribute ("no_sanitize_address", DECL_ATTRIBUTES (*node
)))
6919 DECL_ATTRIBUTES (*node
)
6920 = tree_cons (get_identifier ("no_sanitize_address"),
6921 NULL_TREE
, DECL_ATTRIBUTES (*node
));
6922 *no_add_attrs
= true;
6926 /* Handle a "no_sanitize_undefined" attribute; arguments as in
6927 struct attribute_spec.handler. */
6930 handle_no_sanitize_undefined_attribute (tree
*node
, tree name
, tree
, int,
6933 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6935 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6936 *no_add_attrs
= true;
6942 /* Handle a "stack_protect" attribute; arguments as in
6943 struct attribute_spec.handler. */
6945 handle_stack_protect_attribute (tree
*node
, tree name
, tree
, int,
6948 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6950 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6951 *no_add_attrs
= true;
6954 DECL_ATTRIBUTES (*node
)
6955 = tree_cons (get_identifier ("stack_protect"),
6956 NULL_TREE
, DECL_ATTRIBUTES (*node
));
6961 /* Handle a "noinline" attribute; arguments as in
6962 struct attribute_spec.handler. */
6965 handle_noinline_attribute (tree
*node
, tree name
,
6966 tree
ARG_UNUSED (args
),
6967 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6969 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6971 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node
)))
6973 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
6974 "with attribute %qs", name
, "always_inline");
6975 *no_add_attrs
= true;
6978 DECL_UNINLINABLE (*node
) = 1;
6982 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6983 *no_add_attrs
= true;
6989 /* Handle a "noclone" attribute; arguments as in
6990 struct attribute_spec.handler. */
6993 handle_noclone_attribute (tree
*node
, tree name
,
6994 tree
ARG_UNUSED (args
),
6995 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6997 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6999 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7000 *no_add_attrs
= true;
7006 /* Handle a "no_icf" attribute; arguments as in
7007 struct attribute_spec.handler. */
7010 handle_noicf_attribute (tree
*node
, tree name
,
7011 tree
ARG_UNUSED (args
),
7012 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7014 if (TREE_CODE (*node
) != FUNCTION_DECL
)
7016 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7017 *no_add_attrs
= true;
7024 /* Handle a "always_inline" attribute; arguments as in
7025 struct attribute_spec.handler. */
7028 handle_always_inline_attribute (tree
*node
, tree name
,
7029 tree
ARG_UNUSED (args
),
7030 int ARG_UNUSED (flags
),
7033 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7035 if (lookup_attribute ("noinline", DECL_ATTRIBUTES (*node
)))
7037 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
7038 "with %qs attribute", name
, "noinline");
7039 *no_add_attrs
= true;
7041 else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node
)))
7043 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
7044 "with %qs attribute", name
, "target_clones");
7045 *no_add_attrs
= true;
7048 /* Set the attribute and mark it for disregarding inline
7050 DECL_DISREGARD_INLINE_LIMITS (*node
) = 1;
7054 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7055 *no_add_attrs
= true;
7061 /* Handle a "gnu_inline" attribute; arguments as in
7062 struct attribute_spec.handler. */
7065 handle_gnu_inline_attribute (tree
*node
, tree name
,
7066 tree
ARG_UNUSED (args
),
7067 int ARG_UNUSED (flags
),
7070 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
7072 /* Do nothing else, just set the attribute. We'll get at
7073 it later with lookup_attribute. */
7077 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7078 *no_add_attrs
= true;
7084 /* Handle a "leaf" attribute; arguments as in
7085 struct attribute_spec.handler. */
7088 handle_leaf_attribute (tree
*node
, tree name
,
7089 tree
ARG_UNUSED (args
),
7090 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7092 if (TREE_CODE (*node
) != FUNCTION_DECL
)
7094 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7095 *no_add_attrs
= true;
7097 if (!TREE_PUBLIC (*node
))
7099 warning (OPT_Wattributes
, "%qE attribute has no effect on unit local functions", name
);
7100 *no_add_attrs
= true;
7106 /* Handle an "artificial" attribute; arguments as in
7107 struct attribute_spec.handler. */
7110 handle_artificial_attribute (tree
*node
, tree name
,
7111 tree
ARG_UNUSED (args
),
7112 int ARG_UNUSED (flags
),
7115 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
7117 /* Do nothing else, just set the attribute. We'll get at
7118 it later with lookup_attribute. */
7122 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7123 *no_add_attrs
= true;
7129 /* Handle a "flatten" attribute; arguments as in
7130 struct attribute_spec.handler. */
7133 handle_flatten_attribute (tree
*node
, tree name
,
7134 tree args ATTRIBUTE_UNUSED
,
7135 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
7137 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7138 /* Do nothing else, just set the attribute. We'll get at
7139 it later with lookup_attribute. */
7143 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7144 *no_add_attrs
= true;
7150 /* Handle a "warning" or "error" attribute; arguments as in
7151 struct attribute_spec.handler. */
7154 handle_error_attribute (tree
*node
, tree name
, tree args
,
7155 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7157 if (TREE_CODE (*node
) == FUNCTION_DECL
7158 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
7159 /* Do nothing else, just set the attribute. We'll get at
7160 it later with lookup_attribute. */
7164 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7165 *no_add_attrs
= true;
7171 /* Handle a "used" attribute; arguments as in
7172 struct attribute_spec.handler. */
7175 handle_used_attribute (tree
*pnode
, tree name
, tree
ARG_UNUSED (args
),
7176 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7180 if (TREE_CODE (node
) == FUNCTION_DECL
7181 || (VAR_P (node
) && TREE_STATIC (node
))
7182 || (TREE_CODE (node
) == TYPE_DECL
))
7184 TREE_USED (node
) = 1;
7185 DECL_PRESERVE_P (node
) = 1;
7187 DECL_READ_P (node
) = 1;
7191 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7192 *no_add_attrs
= true;
7198 /* Handle a "unused" attribute; arguments as in
7199 struct attribute_spec.handler. */
7202 handle_unused_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7203 int flags
, bool *no_add_attrs
)
7209 if (TREE_CODE (decl
) == PARM_DECL
7210 || VAR_OR_FUNCTION_DECL_P (decl
)
7211 || TREE_CODE (decl
) == LABEL_DECL
7212 || TREE_CODE (decl
) == CONST_DECL
7213 || TREE_CODE (decl
) == TYPE_DECL
)
7215 TREE_USED (decl
) = 1;
7216 if (VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
)
7217 DECL_READ_P (decl
) = 1;
7221 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7222 *no_add_attrs
= true;
7227 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7228 *node
= build_variant_type_copy (*node
);
7229 TREE_USED (*node
) = 1;
7235 /* Handle a "externally_visible" attribute; arguments as in
7236 struct attribute_spec.handler. */
7239 handle_externally_visible_attribute (tree
*pnode
, tree name
,
7240 tree
ARG_UNUSED (args
),
7241 int ARG_UNUSED (flags
),
7246 if (VAR_OR_FUNCTION_DECL_P (node
))
7248 if ((!TREE_STATIC (node
) && TREE_CODE (node
) != FUNCTION_DECL
7249 && !DECL_EXTERNAL (node
)) || !TREE_PUBLIC (node
))
7251 warning (OPT_Wattributes
,
7252 "%qE attribute have effect only on public objects", name
);
7253 *no_add_attrs
= true;
7258 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7259 *no_add_attrs
= true;
7265 /* Handle the "no_reorder" attribute. Arguments as in
7266 struct attribute_spec.handler. */
7269 handle_no_reorder_attribute (tree
*pnode
,
7277 if (!VAR_OR_FUNCTION_DECL_P (node
)
7278 && !(TREE_STATIC (node
) || DECL_EXTERNAL (node
)))
7280 warning (OPT_Wattributes
,
7281 "%qE attribute only affects top level objects",
7283 *no_add_attrs
= true;
7289 /* Handle a "const" attribute; arguments as in
7290 struct attribute_spec.handler. */
7293 handle_const_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7294 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7296 tree type
= TREE_TYPE (*node
);
7298 /* See FIXME comment on noreturn in c_common_attribute_table. */
7299 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7300 TREE_READONLY (*node
) = 1;
7301 else if (TREE_CODE (type
) == POINTER_TYPE
7302 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
7304 = (build_qualified_type
7306 (build_type_variant (TREE_TYPE (type
), 1,
7307 TREE_THIS_VOLATILE (TREE_TYPE (type
)))),
7308 TYPE_QUALS (type
)));
7311 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7312 *no_add_attrs
= true;
7318 /* Handle a "scalar_storage_order" attribute; arguments as in
7319 struct attribute_spec.handler. */
7322 handle_scalar_storage_order_attribute (tree
*node
, tree name
, tree args
,
7323 int flags
, bool *no_add_attrs
)
7325 tree id
= TREE_VALUE (args
);
7328 if (TREE_CODE (*node
) == TYPE_DECL
7329 && ! (flags
& ATTR_FLAG_CXX11
))
7330 node
= &TREE_TYPE (*node
);
7333 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
)
7335 error ("scalar_storage_order is not supported because endianness "
7340 if (RECORD_OR_UNION_TYPE_P (type
) && !c_dialect_cxx ())
7342 bool reverse
= false;
7344 if (TREE_CODE (id
) == STRING_CST
7345 && strcmp (TREE_STRING_POINTER (id
), "big-endian") == 0)
7346 reverse
= !BYTES_BIG_ENDIAN
;
7347 else if (TREE_CODE (id
) == STRING_CST
7348 && strcmp (TREE_STRING_POINTER (id
), "little-endian") == 0)
7349 reverse
= BYTES_BIG_ENDIAN
;
7352 error ("scalar_storage_order argument must be one of \"big-endian\""
7353 " or \"little-endian\"");
7357 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7360 /* A type variant isn't good enough, since we don't want a cast
7361 to such a type to be removed as a no-op. */
7362 *node
= type
= build_duplicate_type (type
);
7365 TYPE_REVERSE_STORAGE_ORDER (type
) = reverse
;
7369 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7370 *no_add_attrs
= true;
7374 /* Handle a "transparent_union" attribute; arguments as in
7375 struct attribute_spec.handler. */
7378 handle_transparent_union_attribute (tree
*node
, tree name
,
7379 tree
ARG_UNUSED (args
), int flags
,
7384 *no_add_attrs
= true;
7386 if (TREE_CODE (*node
) == TYPE_DECL
7387 && ! (flags
& ATTR_FLAG_CXX11
))
7388 node
= &TREE_TYPE (*node
);
7391 if (TREE_CODE (type
) == UNION_TYPE
)
7393 /* Make sure that the first field will work for a transparent union.
7394 If the type isn't complete yet, leave the check to the code in
7396 if (TYPE_SIZE (type
))
7398 tree first
= first_field (type
);
7399 if (first
== NULL_TREE
7400 || DECL_ARTIFICIAL (first
)
7401 || TYPE_MODE (type
) != DECL_MODE (first
))
7405 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7407 /* If the type isn't complete yet, setting the flag
7408 on a variant wouldn't ever be checked. */
7409 if (!TYPE_SIZE (type
))
7412 /* build_duplicate_type doesn't work for C++. */
7413 if (c_dialect_cxx ())
7416 /* A type variant isn't good enough, since we don't want a cast
7417 to such a type to be removed as a no-op. */
7418 *node
= type
= build_duplicate_type (type
);
7421 for (tree t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
7422 TYPE_TRANSPARENT_AGGR (t
) = 1;
7427 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7431 /* Subroutine of handle_{con,de}structor_attribute. Evaluate ARGS to
7432 get the requested priority for a constructor or destructor,
7433 possibly issuing diagnostics for invalid or reserved
7436 static priority_type
7437 get_priority (tree args
, bool is_destructor
)
7443 return DEFAULT_INIT_PRIORITY
;
7445 if (!SUPPORTS_INIT_PRIORITY
)
7448 error ("destructor priorities are not supported");
7450 error ("constructor priorities are not supported");
7451 return DEFAULT_INIT_PRIORITY
;
7454 arg
= TREE_VALUE (args
);
7455 if (TREE_CODE (arg
) == IDENTIFIER_NODE
)
7457 if (arg
== error_mark_node
)
7458 return DEFAULT_INIT_PRIORITY
;
7459 arg
= default_conversion (arg
);
7460 if (!tree_fits_shwi_p (arg
)
7461 || !INTEGRAL_TYPE_P (TREE_TYPE (arg
)))
7464 pri
= tree_to_shwi (arg
);
7465 if (pri
< 0 || pri
> MAX_INIT_PRIORITY
)
7468 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
7472 "destructor priorities from 0 to %d are reserved "
7473 "for the implementation",
7474 MAX_RESERVED_INIT_PRIORITY
);
7477 "constructor priorities from 0 to %d are reserved "
7478 "for the implementation",
7479 MAX_RESERVED_INIT_PRIORITY
);
7485 error ("destructor priorities must be integers from 0 to %d inclusive",
7488 error ("constructor priorities must be integers from 0 to %d inclusive",
7490 return DEFAULT_INIT_PRIORITY
;
7493 /* Handle a "constructor" attribute; arguments as in
7494 struct attribute_spec.handler. */
7497 handle_constructor_attribute (tree
*node
, tree name
, tree args
,
7498 int ARG_UNUSED (flags
),
7502 tree type
= TREE_TYPE (decl
);
7504 if (TREE_CODE (decl
) == FUNCTION_DECL
7505 && TREE_CODE (type
) == FUNCTION_TYPE
7506 && decl_function_context (decl
) == 0)
7508 priority_type priority
;
7509 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
7510 priority
= get_priority (args
, /*is_destructor=*/false);
7511 SET_DECL_INIT_PRIORITY (decl
, priority
);
7512 TREE_USED (decl
) = 1;
7516 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7517 *no_add_attrs
= true;
7523 /* Handle a "destructor" attribute; arguments as in
7524 struct attribute_spec.handler. */
7527 handle_destructor_attribute (tree
*node
, tree name
, tree args
,
7528 int ARG_UNUSED (flags
),
7532 tree type
= TREE_TYPE (decl
);
7534 if (TREE_CODE (decl
) == FUNCTION_DECL
7535 && TREE_CODE (type
) == FUNCTION_TYPE
7536 && decl_function_context (decl
) == 0)
7538 priority_type priority
;
7539 DECL_STATIC_DESTRUCTOR (decl
) = 1;
7540 priority
= get_priority (args
, /*is_destructor=*/true);
7541 SET_DECL_FINI_PRIORITY (decl
, priority
);
7542 TREE_USED (decl
) = 1;
7546 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7547 *no_add_attrs
= true;
7553 /* Nonzero if the mode is a valid vector mode for this architecture.
7554 This returns nonzero even if there is no hardware support for the
7555 vector mode, but we can emulate with narrower modes. */
7558 vector_mode_valid_p (machine_mode mode
)
7560 enum mode_class mclass
= GET_MODE_CLASS (mode
);
7561 machine_mode innermode
;
7563 /* Doh! What's going on? */
7564 if (mclass
!= MODE_VECTOR_INT
7565 && mclass
!= MODE_VECTOR_FLOAT
7566 && mclass
!= MODE_VECTOR_FRACT
7567 && mclass
!= MODE_VECTOR_UFRACT
7568 && mclass
!= MODE_VECTOR_ACCUM
7569 && mclass
!= MODE_VECTOR_UACCUM
)
7572 /* Hardware support. Woo hoo! */
7573 if (targetm
.vector_mode_supported_p (mode
))
7576 innermode
= GET_MODE_INNER (mode
);
7578 /* We should probably return 1 if requesting V4DI and we have no DI,
7579 but we have V2DI, but this is probably very unlikely. */
7581 /* If we have support for the inner mode, we can safely emulate it.
7582 We may not have V2DI, but me can emulate with a pair of DIs. */
7583 return targetm
.scalar_mode_supported_p (innermode
);
7587 /* Handle a "mode" attribute; arguments as in
7588 struct attribute_spec.handler. */
7591 handle_mode_attribute (tree
*node
, tree name
, tree args
,
7592 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7595 tree ident
= TREE_VALUE (args
);
7597 *no_add_attrs
= true;
7599 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
7600 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7604 const char *p
= IDENTIFIER_POINTER (ident
);
7605 int len
= strlen (p
);
7606 machine_mode mode
= VOIDmode
;
7610 if (len
> 4 && p
[0] == '_' && p
[1] == '_'
7611 && p
[len
- 1] == '_' && p
[len
- 2] == '_')
7613 char *newp
= (char *) alloca (len
- 1);
7615 strcpy (newp
, &p
[2]);
7616 newp
[len
- 4] = '\0';
7620 /* Change this type to have a type with the specified mode.
7621 First check for the special modes. */
7622 if (!strcmp (p
, "byte"))
7624 else if (!strcmp (p
, "word"))
7626 else if (!strcmp (p
, "pointer"))
7628 else if (!strcmp (p
, "libgcc_cmp_return"))
7629 mode
= targetm
.libgcc_cmp_return_mode ();
7630 else if (!strcmp (p
, "libgcc_shift_count"))
7631 mode
= targetm
.libgcc_shift_count_mode ();
7632 else if (!strcmp (p
, "unwind_word"))
7633 mode
= targetm
.unwind_word_mode ();
7635 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
7636 if (!strcmp (p
, GET_MODE_NAME (j
)))
7638 mode
= (machine_mode
) j
;
7642 if (mode
== VOIDmode
)
7644 error ("unknown machine mode %qE", ident
);
7649 switch (GET_MODE_CLASS (mode
))
7652 case MODE_PARTIAL_INT
:
7654 case MODE_DECIMAL_FLOAT
:
7659 valid_mode
= targetm
.scalar_mode_supported_p (mode
);
7662 case MODE_COMPLEX_INT
:
7663 case MODE_COMPLEX_FLOAT
:
7664 valid_mode
= targetm
.scalar_mode_supported_p (GET_MODE_INNER (mode
));
7667 case MODE_VECTOR_INT
:
7668 case MODE_VECTOR_FLOAT
:
7669 case MODE_VECTOR_FRACT
:
7670 case MODE_VECTOR_UFRACT
:
7671 case MODE_VECTOR_ACCUM
:
7672 case MODE_VECTOR_UACCUM
:
7673 warning (OPT_Wattributes
, "specifying vector types with "
7674 "__attribute__ ((mode)) is deprecated");
7675 warning (OPT_Wattributes
,
7676 "use __attribute__ ((vector_size)) instead");
7677 valid_mode
= vector_mode_valid_p (mode
);
7685 error ("unable to emulate %qs", p
);
7689 if (POINTER_TYPE_P (type
))
7691 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
7692 tree (*fn
)(tree
, machine_mode
, bool);
7694 if (!targetm
.addr_space
.valid_pointer_mode (mode
, as
))
7696 error ("invalid pointer mode %qs", p
);
7700 if (TREE_CODE (type
) == POINTER_TYPE
)
7701 fn
= build_pointer_type_for_mode
;
7703 fn
= build_reference_type_for_mode
;
7704 typefm
= fn (TREE_TYPE (type
), mode
, false);
7708 /* For fixed-point modes, we need to test if the signness of type
7709 and the machine mode are consistent. */
7710 if (ALL_FIXED_POINT_MODE_P (mode
)
7711 && TYPE_UNSIGNED (type
) != UNSIGNED_FIXED_POINT_MODE_P (mode
))
7713 error ("signedness of type and machine mode %qs don%'t match", p
);
7716 /* For fixed-point modes, we need to pass saturating info. */
7717 typefm
= lang_hooks
.types
.type_for_mode (mode
,
7718 ALL_FIXED_POINT_MODE_P (mode
) ? TYPE_SATURATING (type
)
7719 : TYPE_UNSIGNED (type
));
7722 if (typefm
== NULL_TREE
)
7724 error ("no data type for mode %qs", p
);
7727 else if (TREE_CODE (type
) == ENUMERAL_TYPE
)
7729 /* For enumeral types, copy the precision from the integer
7730 type returned above. If not an INTEGER_TYPE, we can't use
7731 this mode for this type. */
7732 if (TREE_CODE (typefm
) != INTEGER_TYPE
)
7734 error ("cannot use mode %qs for enumeral types", p
);
7738 if (flags
& ATTR_FLAG_TYPE_IN_PLACE
)
7740 TYPE_PRECISION (type
) = TYPE_PRECISION (typefm
);
7745 /* We cannot build a type variant, as there's code that assumes
7746 that TYPE_MAIN_VARIANT has the same mode. This includes the
7747 debug generators. Instead, create a subrange type. This
7748 results in all of the enumeral values being emitted only once
7749 in the original, and the subtype gets them by reference. */
7750 if (TYPE_UNSIGNED (type
))
7751 typefm
= make_unsigned_type (TYPE_PRECISION (typefm
));
7753 typefm
= make_signed_type (TYPE_PRECISION (typefm
));
7754 TREE_TYPE (typefm
) = type
;
7757 else if (VECTOR_MODE_P (mode
)
7758 ? TREE_CODE (type
) != TREE_CODE (TREE_TYPE (typefm
))
7759 : TREE_CODE (type
) != TREE_CODE (typefm
))
7761 error ("mode %qs applied to inappropriate type", p
);
7771 /* Handle a "section" attribute; arguments as in
7772 struct attribute_spec.handler. */
7775 handle_section_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7776 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7780 if (!targetm_common
.have_named_sections
)
7782 error_at (DECL_SOURCE_LOCATION (*node
),
7783 "section attributes are not supported for this target");
7787 user_defined_section_attribute
= true;
7789 if (!VAR_OR_FUNCTION_DECL_P (decl
))
7791 error ("section attribute not allowed for %q+D", *node
);
7795 if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
7797 error ("section attribute argument not a string constant");
7802 && current_function_decl
!= NULL_TREE
7803 && !TREE_STATIC (decl
))
7805 error_at (DECL_SOURCE_LOCATION (decl
),
7806 "section attribute cannot be specified for local variables");
7810 /* The decl may have already been given a section attribute
7811 from a previous declaration. Ensure they match. */
7812 if (DECL_SECTION_NAME (decl
) != NULL
7813 && strcmp (DECL_SECTION_NAME (decl
),
7814 TREE_STRING_POINTER (TREE_VALUE (args
))) != 0)
7816 error ("section of %q+D conflicts with previous declaration", *node
);
7821 && !targetm
.have_tls
&& targetm
.emutls
.tmpl_section
7822 && DECL_THREAD_LOCAL_P (decl
))
7824 error ("section of %q+D cannot be overridden", *node
);
7828 set_decl_section_name (decl
, TREE_STRING_POINTER (TREE_VALUE (args
)));
7832 *no_add_attrs
= true;
7836 /* Check whether ALIGN is a valid user-specified alignment. If so,
7837 return its base-2 log; if not, output an error and return -1. If
7838 ALLOW_ZERO then 0 is valid and should result in a return of -1 with
7841 check_user_alignment (const_tree align
, bool allow_zero
)
7845 if (error_operand_p (align
))
7847 if (TREE_CODE (align
) != INTEGER_CST
7848 || !INTEGRAL_TYPE_P (TREE_TYPE (align
)))
7850 error ("requested alignment is not an integer constant");
7853 else if (allow_zero
&& integer_zerop (align
))
7855 else if (tree_int_cst_sgn (align
) == -1
7856 || (i
= tree_log2 (align
)) == -1)
7858 error ("requested alignment is not a positive power of 2");
7861 else if (i
>= HOST_BITS_PER_INT
- LOG2_BITS_PER_UNIT
)
7863 error ("requested alignment is too large");
7869 /* If in c++-11, check if the c++-11 alignment constraint with respect
7870 to fundamental alignment (in [dcl.align]) are satisfied. If not in
7871 c++-11 mode, does nothing.
7875 [* if the constant expression evaluates to a fundamental alignment,
7876 the alignment requirement of the declared entity shall be the
7877 specified fundamental alignment.
7879 * if the constant expression evaluates to an extended alignment
7880 and the implementation supports that alignment in the context
7881 of the declaration, the alignment of the declared entity shall
7884 * if the constant expression evaluates to an extended alignment
7885 and the implementation does not support that alignment in the
7886 context of the declaration, the program is ill-formed]. */
7889 check_cxx_fundamental_alignment_constraints (tree node
,
7893 bool alignment_too_large_p
= false;
7894 unsigned requested_alignment
= (1U << align_log
) * BITS_PER_UNIT
;
7895 unsigned max_align
= 0;
7897 if ((!(flags
& ATTR_FLAG_CXX11
) && !warn_cxx_compat
)
7898 || (node
== NULL_TREE
|| node
== error_mark_node
))
7901 if (cxx_fundamental_alignment_p (requested_alignment
))
7906 if (TREE_STATIC (node
) || DECL_EXTERNAL (node
))
7907 /* For file scope variables and static members, the target supports
7908 alignments that are at most MAX_OFILE_ALIGNMENT. */
7909 max_align
= MAX_OFILE_ALIGNMENT
;
7911 /* For stack variables, the target supports at most
7912 MAX_STACK_ALIGNMENT. */
7913 max_align
= MAX_STACK_ALIGNMENT
;
7914 if (requested_alignment
> max_align
)
7915 alignment_too_large_p
= true;
7917 /* Let's be liberal for types and fields; don't limit their alignment any
7918 more than check_user_alignment already did. */
7920 if (alignment_too_large_p
)
7921 pedwarn (input_location
, OPT_Wattributes
,
7922 "requested alignment %d is larger than %d",
7923 requested_alignment
/ BITS_PER_UNIT
, max_align
/ BITS_PER_UNIT
);
7925 return !alignment_too_large_p
;
7928 /* Handle a "aligned" attribute; arguments as in
7929 struct attribute_spec.handler. */
7932 handle_aligned_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7933 int flags
, bool *no_add_attrs
)
7935 tree decl
= NULL_TREE
;
7943 align_expr
= TREE_VALUE (args
);
7944 if (align_expr
&& TREE_CODE (align_expr
) != IDENTIFIER_NODE
7945 && TREE_CODE (align_expr
) != FUNCTION_DECL
)
7946 align_expr
= default_conversion (align_expr
);
7949 align_expr
= size_int (ATTRIBUTE_ALIGNED_VALUE
/ BITS_PER_UNIT
);
7954 type
= &TREE_TYPE (decl
);
7955 is_type
= TREE_CODE (*node
) == TYPE_DECL
;
7957 else if (TYPE_P (*node
))
7958 type
= node
, is_type
= 1;
7960 if ((i
= check_user_alignment (align_expr
, true)) == -1
7961 || !check_cxx_fundamental_alignment_constraints (*node
, i
, flags
))
7962 *no_add_attrs
= true;
7965 if ((flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7966 /* OK, modify the type in place. */;
7967 /* If we have a TYPE_DECL, then copy the type, so that we
7968 don't accidentally modify a builtin type. See pushdecl. */
7969 else if (decl
&& TREE_TYPE (decl
) != error_mark_node
7970 && DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
)
7972 tree tt
= TREE_TYPE (decl
);
7973 *type
= build_variant_type_copy (*type
);
7974 DECL_ORIGINAL_TYPE (decl
) = tt
;
7975 TYPE_NAME (*type
) = decl
;
7976 TREE_USED (*type
) = TREE_USED (decl
);
7977 TREE_TYPE (decl
) = *type
;
7980 *type
= build_variant_type_copy (*type
);
7982 SET_TYPE_ALIGN (*type
, (1U << i
) * BITS_PER_UNIT
);
7983 TYPE_USER_ALIGN (*type
) = 1;
7985 else if (! VAR_OR_FUNCTION_DECL_P (decl
)
7986 && TREE_CODE (decl
) != FIELD_DECL
)
7988 error ("alignment may not be specified for %q+D", decl
);
7989 *no_add_attrs
= true;
7991 else if (DECL_USER_ALIGN (decl
)
7992 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
7993 /* C++-11 [dcl.align/4]:
7995 When multiple alignment-specifiers are specified for an
7996 entity, the alignment requirement shall be set to the
7997 strictest specified alignment.
7999 This formally comes from the c++11 specification but we are
8000 doing it for the GNU attribute syntax as well. */
8001 *no_add_attrs
= true;
8002 else if (TREE_CODE (decl
) == FUNCTION_DECL
8003 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
8005 if (DECL_USER_ALIGN (decl
))
8006 error ("alignment for %q+D was previously specified as %d "
8007 "and may not be decreased", decl
,
8008 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
8010 error ("alignment for %q+D must be at least %d", decl
,
8011 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
8012 *no_add_attrs
= true;
8016 SET_DECL_ALIGN (decl
, (1U << i
) * BITS_PER_UNIT
);
8017 DECL_USER_ALIGN (decl
) = 1;
8023 /* Handle a "weak" attribute; arguments as in
8024 struct attribute_spec.handler. */
8027 handle_weak_attribute (tree
*node
, tree name
,
8028 tree
ARG_UNUSED (args
),
8029 int ARG_UNUSED (flags
),
8030 bool * ARG_UNUSED (no_add_attrs
))
8032 if (TREE_CODE (*node
) == FUNCTION_DECL
8033 && DECL_DECLARED_INLINE_P (*node
))
8035 warning (OPT_Wattributes
, "inline function %q+D declared weak", *node
);
8036 *no_add_attrs
= true;
8038 else if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
8040 error ("indirect function %q+D cannot be declared weak", *node
);
8041 *no_add_attrs
= true;
8044 else if (VAR_OR_FUNCTION_DECL_P (*node
))
8045 declare_weak (*node
);
8047 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8052 /* Handle a "noplt" attribute; arguments as in
8053 struct attribute_spec.handler. */
8056 handle_noplt_attribute (tree
*node
, tree name
,
8057 tree
ARG_UNUSED (args
),
8058 int ARG_UNUSED (flags
),
8059 bool * ARG_UNUSED (no_add_attrs
))
8061 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8063 warning (OPT_Wattributes
,
8064 "%qE attribute is only applicable on functions", name
);
8065 *no_add_attrs
= true;
8071 /* Handle an "alias" or "ifunc" attribute; arguments as in
8072 struct attribute_spec.handler, except that IS_ALIAS tells us
8073 whether this is an alias as opposed to ifunc attribute. */
8076 handle_alias_ifunc_attribute (bool is_alias
, tree
*node
, tree name
, tree args
,
8081 if (TREE_CODE (decl
) != FUNCTION_DECL
8082 && (!is_alias
|| !VAR_P (decl
)))
8084 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8085 *no_add_attrs
= true;
8087 else if ((TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INITIAL (decl
))
8088 || (TREE_CODE (decl
) != FUNCTION_DECL
8089 && TREE_PUBLIC (decl
) && !DECL_EXTERNAL (decl
))
8090 /* A static variable declaration is always a tentative definition,
8091 but the alias is a non-tentative definition which overrides. */
8092 || (TREE_CODE (decl
) != FUNCTION_DECL
8093 && ! TREE_PUBLIC (decl
) && DECL_INITIAL (decl
)))
8095 error ("%q+D defined both normally and as %qE attribute", decl
, name
);
8096 *no_add_attrs
= true;
8100 && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
8101 || lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
))))
8103 error ("weak %q+D cannot be defined %qE", decl
, name
);
8104 *no_add_attrs
= true;
8108 /* Note that the very first time we process a nested declaration,
8109 decl_function_context will not be set. Indeed, *would* never
8110 be set except for the DECL_INITIAL/DECL_EXTERNAL frobbery that
8111 we do below. After such frobbery, pushdecl would set the context.
8112 In any case, this is never what we want. */
8113 else if (decl_function_context (decl
) == 0 && current_function_decl
== NULL
)
8117 id
= TREE_VALUE (args
);
8118 if (TREE_CODE (id
) != STRING_CST
)
8120 error ("attribute %qE argument not a string", name
);
8121 *no_add_attrs
= true;
8124 id
= get_identifier (TREE_STRING_POINTER (id
));
8125 /* This counts as a use of the object pointed to. */
8128 if (TREE_CODE (decl
) == FUNCTION_DECL
)
8129 DECL_INITIAL (decl
) = error_mark_node
;
8131 TREE_STATIC (decl
) = 1;
8134 /* ifuncs are also aliases, so set that attribute too. */
8135 DECL_ATTRIBUTES (decl
)
8136 = tree_cons (get_identifier ("alias"), args
, DECL_ATTRIBUTES (decl
));
8140 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8141 *no_add_attrs
= true;
8144 if (decl_in_symtab_p (*node
))
8146 struct symtab_node
*n
= symtab_node::get (decl
);
8147 if (n
&& n
->refuse_visibility_changes
)
8150 error ("%+D declared alias after being used", decl
);
8152 error ("%+D declared ifunc after being used", decl
);
8160 /* Handle an "alias" or "ifunc" attribute; arguments as in
8161 struct attribute_spec.handler. */
8164 handle_ifunc_attribute (tree
*node
, tree name
, tree args
,
8165 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8167 return handle_alias_ifunc_attribute (false, node
, name
, args
, no_add_attrs
);
8170 /* Handle an "alias" or "ifunc" attribute; arguments as in
8171 struct attribute_spec.handler. */
8174 handle_alias_attribute (tree
*node
, tree name
, tree args
,
8175 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8177 return handle_alias_ifunc_attribute (true, node
, name
, args
, no_add_attrs
);
8180 /* Handle a "weakref" attribute; arguments as in struct
8181 attribute_spec.handler. */
8184 handle_weakref_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
8185 int flags
, bool *no_add_attrs
)
8187 tree attr
= NULL_TREE
;
8189 /* We must ignore the attribute when it is associated with
8190 local-scoped decls, since attribute alias is ignored and many
8191 such symbols do not even have a DECL_WEAK field. */
8192 if (decl_function_context (*node
)
8193 || current_function_decl
8194 || !VAR_OR_FUNCTION_DECL_P (*node
))
8196 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8197 *no_add_attrs
= true;
8201 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
8203 error ("indirect function %q+D cannot be declared weakref", *node
);
8204 *no_add_attrs
= true;
8208 /* The idea here is that `weakref("name")' mutates into `weakref,
8209 alias("name")', and weakref without arguments, in turn,
8210 implicitly adds weak. */
8214 attr
= tree_cons (get_identifier ("alias"), args
, attr
);
8215 attr
= tree_cons (get_identifier ("weakref"), NULL_TREE
, attr
);
8217 *no_add_attrs
= true;
8219 decl_attributes (node
, attr
, flags
);
8223 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node
)))
8224 error_at (DECL_SOURCE_LOCATION (*node
),
8225 "weakref attribute must appear before alias attribute");
8227 /* Can't call declare_weak because it wants this to be TREE_PUBLIC,
8228 and that isn't supported; and because it wants to add it to
8229 the list of weak decls, which isn't helpful. */
8230 DECL_WEAK (*node
) = 1;
8233 if (decl_in_symtab_p (*node
))
8235 struct symtab_node
*n
= symtab_node::get (*node
);
8236 if (n
&& n
->refuse_visibility_changes
)
8237 error ("%+D declared weakref after being used", *node
);
8243 /* Handle an "visibility" attribute; arguments as in
8244 struct attribute_spec.handler. */
8247 handle_visibility_attribute (tree
*node
, tree name
, tree args
,
8248 int ARG_UNUSED (flags
),
8249 bool *ARG_UNUSED (no_add_attrs
))
8252 tree id
= TREE_VALUE (args
);
8253 enum symbol_visibility vis
;
8257 if (TREE_CODE (*node
) == ENUMERAL_TYPE
)
8259 else if (!RECORD_OR_UNION_TYPE_P (*node
))
8261 warning (OPT_Wattributes
, "%qE attribute ignored on non-class types",
8265 else if (TYPE_FIELDS (*node
))
8267 error ("%qE attribute ignored because %qT is already defined",
8272 else if (decl_function_context (decl
) != 0 || !TREE_PUBLIC (decl
))
8274 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8278 if (TREE_CODE (id
) != STRING_CST
)
8280 error ("visibility argument not a string");
8284 /* If this is a type, set the visibility on the type decl. */
8287 decl
= TYPE_NAME (decl
);
8290 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
8292 warning (OPT_Wattributes
, "%qE attribute ignored on types",
8298 if (strcmp (TREE_STRING_POINTER (id
), "default") == 0)
8299 vis
= VISIBILITY_DEFAULT
;
8300 else if (strcmp (TREE_STRING_POINTER (id
), "internal") == 0)
8301 vis
= VISIBILITY_INTERNAL
;
8302 else if (strcmp (TREE_STRING_POINTER (id
), "hidden") == 0)
8303 vis
= VISIBILITY_HIDDEN
;
8304 else if (strcmp (TREE_STRING_POINTER (id
), "protected") == 0)
8305 vis
= VISIBILITY_PROTECTED
;
8308 error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
8309 vis
= VISIBILITY_DEFAULT
;
8312 if (DECL_VISIBILITY_SPECIFIED (decl
)
8313 && vis
!= DECL_VISIBILITY (decl
))
8315 tree attributes
= (TYPE_P (*node
)
8316 ? TYPE_ATTRIBUTES (*node
)
8317 : DECL_ATTRIBUTES (decl
));
8318 if (lookup_attribute ("visibility", attributes
))
8319 error ("%qD redeclared with different visibility", decl
);
8320 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
8321 && lookup_attribute ("dllimport", attributes
))
8322 error ("%qD was declared %qs which implies default visibility",
8324 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
8325 && lookup_attribute ("dllexport", attributes
))
8326 error ("%qD was declared %qs which implies default visibility",
8330 DECL_VISIBILITY (decl
) = vis
;
8331 DECL_VISIBILITY_SPECIFIED (decl
) = 1;
8333 /* Go ahead and attach the attribute to the node as well. This is needed
8334 so we can determine whether we have VISIBILITY_DEFAULT because the
8335 visibility was not specified, or because it was explicitly overridden
8336 from the containing scope. */
8341 /* Determine the ELF symbol visibility for DECL, which is either a
8342 variable or a function. It is an error to use this function if a
8343 definition of DECL is not available in this translation unit.
8344 Returns true if the final visibility has been determined by this
8345 function; false if the caller is free to make additional
8349 c_determine_visibility (tree decl
)
8351 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
8353 /* If the user explicitly specified the visibility with an
8354 attribute, honor that. DECL_VISIBILITY will have been set during
8355 the processing of the attribute. We check for an explicit
8356 attribute, rather than just checking DECL_VISIBILITY_SPECIFIED,
8357 to distinguish the use of an attribute from the use of a "#pragma
8358 GCC visibility push(...)"; in the latter case we still want other
8359 considerations to be able to overrule the #pragma. */
8360 if (lookup_attribute ("visibility", DECL_ATTRIBUTES (decl
))
8361 || (TARGET_DLLIMPORT_DECL_ATTRIBUTES
8362 && (lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl
))
8363 || lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl
)))))
8366 /* Set default visibility to whatever the user supplied with
8367 visibility_specified depending on #pragma GCC visibility. */
8368 if (!DECL_VISIBILITY_SPECIFIED (decl
))
8370 if (visibility_options
.inpragma
8371 || DECL_VISIBILITY (decl
) != default_visibility
)
8373 DECL_VISIBILITY (decl
) = default_visibility
;
8374 DECL_VISIBILITY_SPECIFIED (decl
) = visibility_options
.inpragma
;
8375 /* If visibility changed and DECL already has DECL_RTL, ensure
8376 symbol flags are updated. */
8377 if (((VAR_P (decl
) && TREE_STATIC (decl
))
8378 || TREE_CODE (decl
) == FUNCTION_DECL
)
8379 && DECL_RTL_SET_P (decl
))
8380 make_decl_rtl (decl
);
8386 /* Handle an "tls_model" attribute; arguments as in
8387 struct attribute_spec.handler. */
8390 handle_tls_model_attribute (tree
*node
, tree name
, tree args
,
8391 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8395 enum tls_model kind
;
8397 *no_add_attrs
= true;
8399 if (!VAR_P (decl
) || !DECL_THREAD_LOCAL_P (decl
))
8401 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8405 kind
= DECL_TLS_MODEL (decl
);
8406 id
= TREE_VALUE (args
);
8407 if (TREE_CODE (id
) != STRING_CST
)
8409 error ("tls_model argument not a string");
8413 if (!strcmp (TREE_STRING_POINTER (id
), "local-exec"))
8414 kind
= TLS_MODEL_LOCAL_EXEC
;
8415 else if (!strcmp (TREE_STRING_POINTER (id
), "initial-exec"))
8416 kind
= TLS_MODEL_INITIAL_EXEC
;
8417 else if (!strcmp (TREE_STRING_POINTER (id
), "local-dynamic"))
8418 kind
= optimize
? TLS_MODEL_LOCAL_DYNAMIC
: TLS_MODEL_GLOBAL_DYNAMIC
;
8419 else if (!strcmp (TREE_STRING_POINTER (id
), "global-dynamic"))
8420 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
8422 error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
8424 set_decl_tls_model (decl
, kind
);
8428 /* Handle a "no_instrument_function" attribute; arguments as in
8429 struct attribute_spec.handler. */
8432 handle_no_instrument_function_attribute (tree
*node
, tree name
,
8433 tree
ARG_UNUSED (args
),
8434 int ARG_UNUSED (flags
),
8439 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8441 error_at (DECL_SOURCE_LOCATION (decl
),
8442 "%qE attribute applies only to functions", name
);
8443 *no_add_attrs
= true;
8446 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
8451 /* Handle a "no_profile_instrument_function" attribute; arguments as in
8452 struct attribute_spec.handler. */
8455 handle_no_profile_instrument_function_attribute (tree
*node
, tree name
, tree
,
8456 int, bool *no_add_attrs
)
8458 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8460 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8461 *no_add_attrs
= true;
8467 /* Handle a "malloc" attribute; arguments as in
8468 struct attribute_spec.handler. */
8471 handle_malloc_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8472 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8474 if (TREE_CODE (*node
) == FUNCTION_DECL
8475 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node
))))
8476 DECL_IS_MALLOC (*node
) = 1;
8479 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8480 *no_add_attrs
= true;
8486 /* Handle a "alloc_size" attribute; arguments as in
8487 struct attribute_spec.handler. */
8490 handle_alloc_size_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
8491 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8493 unsigned arg_count
= type_num_arguments (*node
);
8494 for (; args
; args
= TREE_CHAIN (args
))
8496 tree position
= TREE_VALUE (args
);
8497 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
8498 && TREE_CODE (position
) != FUNCTION_DECL
)
8499 position
= default_conversion (position
);
8501 if (!tree_fits_uhwi_p (position
)
8503 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
8505 warning (OPT_Wattributes
,
8506 "alloc_size parameter outside range");
8507 *no_add_attrs
= true;
8514 /* Handle a "alloc_align" attribute; arguments as in
8515 struct attribute_spec.handler. */
8518 handle_alloc_align_attribute (tree
*node
, tree
, tree args
, int,
8521 unsigned arg_count
= type_num_arguments (*node
);
8522 tree position
= TREE_VALUE (args
);
8523 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
8524 && TREE_CODE (position
) != FUNCTION_DECL
)
8525 position
= default_conversion (position
);
8527 if (!tree_fits_uhwi_p (position
)
8529 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
8531 warning (OPT_Wattributes
,
8532 "alloc_align parameter outside range");
8533 *no_add_attrs
= true;
8539 /* Handle a "assume_aligned" attribute; arguments as in
8540 struct attribute_spec.handler. */
8543 handle_assume_aligned_attribute (tree
*, tree
, tree args
, int,
8546 for (; args
; args
= TREE_CHAIN (args
))
8548 tree position
= TREE_VALUE (args
);
8549 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
8550 && TREE_CODE (position
) != FUNCTION_DECL
)
8551 position
= default_conversion (position
);
8553 if (TREE_CODE (position
) != INTEGER_CST
)
8555 warning (OPT_Wattributes
,
8556 "assume_aligned parameter not integer constant");
8557 *no_add_attrs
= true;
8564 /* Handle a "fn spec" attribute; arguments as in
8565 struct attribute_spec.handler. */
8568 handle_fnspec_attribute (tree
*node ATTRIBUTE_UNUSED
, tree
ARG_UNUSED (name
),
8569 tree args
, int ARG_UNUSED (flags
),
8570 bool *no_add_attrs ATTRIBUTE_UNUSED
)
8573 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
8574 && !TREE_CHAIN (args
));
8578 /* Handle a "bnd_variable_size" attribute; arguments as in
8579 struct attribute_spec.handler. */
8582 handle_bnd_variable_size_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8583 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8585 if (TREE_CODE (*node
) != FIELD_DECL
)
8587 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8588 *no_add_attrs
= true;
8594 /* Handle a "bnd_legacy" attribute; arguments as in
8595 struct attribute_spec.handler. */
8598 handle_bnd_legacy (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8599 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8601 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8603 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8604 *no_add_attrs
= true;
8610 /* Handle a "bnd_instrument" attribute; arguments as in
8611 struct attribute_spec.handler. */
8614 handle_bnd_instrument (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8615 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8617 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8619 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8620 *no_add_attrs
= true;
8626 /* Handle a "warn_unused" attribute; arguments as in
8627 struct attribute_spec.handler. */
8630 handle_warn_unused_attribute (tree
*node
, tree name
,
8631 tree args ATTRIBUTE_UNUSED
,
8632 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
8635 /* Do nothing else, just set the attribute. We'll get at
8636 it later with lookup_attribute. */
8640 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8641 *no_add_attrs
= true;
8647 /* Handle an "omp declare simd" attribute; arguments as in
8648 struct attribute_spec.handler. */
8651 handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int, bool *)
8656 /* Handle a "simd" attribute. */
8659 handle_simd_attribute (tree
*node
, tree name
, tree args
, int, bool *no_add_attrs
)
8661 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8663 if (lookup_attribute ("cilk simd function",
8664 DECL_ATTRIBUTES (*node
)) != NULL
)
8666 error_at (DECL_SOURCE_LOCATION (*node
),
8667 "%<__simd__%> attribute cannot be used in the same "
8668 "function marked as a Cilk Plus SIMD-enabled function");
8669 *no_add_attrs
= true;
8673 tree t
= get_identifier ("omp declare simd");
8674 tree attr
= NULL_TREE
;
8677 tree id
= TREE_VALUE (args
);
8679 if (TREE_CODE (id
) != STRING_CST
)
8681 error ("attribute %qE argument not a string", name
);
8682 *no_add_attrs
= true;
8686 if (strcmp (TREE_STRING_POINTER (id
), "notinbranch") == 0)
8687 attr
= build_omp_clause (DECL_SOURCE_LOCATION (*node
),
8688 OMP_CLAUSE_NOTINBRANCH
);
8690 if (strcmp (TREE_STRING_POINTER (id
), "inbranch") == 0)
8691 attr
= build_omp_clause (DECL_SOURCE_LOCATION (*node
),
8692 OMP_CLAUSE_INBRANCH
);
8695 error ("only %<inbranch%> and %<notinbranch%> flags are "
8696 "allowed for %<__simd__%> attribute");
8697 *no_add_attrs
= true;
8702 DECL_ATTRIBUTES (*node
) = tree_cons (t
,
8703 build_tree_list (NULL_TREE
,
8705 DECL_ATTRIBUTES (*node
));
8710 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8711 *no_add_attrs
= true;
8717 /* Handle an "omp declare target" attribute; arguments as in
8718 struct attribute_spec.handler. */
8721 handle_omp_declare_target_attribute (tree
*, tree
, tree
, int, bool *)
8726 /* Handle a "returns_twice" attribute; arguments as in
8727 struct attribute_spec.handler. */
8730 handle_returns_twice_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8731 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8733 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8734 DECL_IS_RETURNS_TWICE (*node
) = 1;
8737 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8738 *no_add_attrs
= true;
8744 /* Handle a "no_limit_stack" attribute; arguments as in
8745 struct attribute_spec.handler. */
8748 handle_no_limit_stack_attribute (tree
*node
, tree name
,
8749 tree
ARG_UNUSED (args
),
8750 int ARG_UNUSED (flags
),
8755 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8757 error_at (DECL_SOURCE_LOCATION (decl
),
8758 "%qE attribute applies only to functions", name
);
8759 *no_add_attrs
= true;
8761 else if (DECL_INITIAL (decl
))
8763 error_at (DECL_SOURCE_LOCATION (decl
),
8764 "can%'t set %qE attribute after definition", name
);
8765 *no_add_attrs
= true;
8768 DECL_NO_LIMIT_STACK (decl
) = 1;
8773 /* Handle a "pure" attribute; arguments as in
8774 struct attribute_spec.handler. */
8777 handle_pure_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8778 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8780 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8781 DECL_PURE_P (*node
) = 1;
8782 /* ??? TODO: Support types. */
8785 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8786 *no_add_attrs
= true;
8792 /* Digest an attribute list destined for a transactional memory statement.
8793 ALLOWED is the set of attributes that are allowed for this statement;
8794 return the attribute we parsed. Multiple attributes are never allowed. */
8797 parse_tm_stmt_attr (tree attrs
, int allowed
)
8802 for ( ; attrs
; attrs
= TREE_CHAIN (attrs
))
8804 tree a
= TREE_PURPOSE (attrs
);
8807 if (is_attribute_p ("outer", a
))
8808 m
= TM_STMT_ATTR_OUTER
;
8810 if ((m
& allowed
) == 0)
8812 warning (OPT_Wattributes
, "%qE attribute directive ignored", a
);
8821 else if (m_seen
== m
)
8822 warning (OPT_Wattributes
, "%qE attribute duplicated", a
);
8824 warning (OPT_Wattributes
, "%qE attribute follows %qE", a
, a_seen
);
8830 /* Transform a TM attribute name into a maskable integer and back.
8831 Note that NULL (i.e. no attribute) is mapped to UNKNOWN, corresponding
8832 to how the lack of an attribute is treated. */
8835 tm_attr_to_mask (tree attr
)
8839 if (is_attribute_p ("transaction_safe", attr
))
8840 return TM_ATTR_SAFE
;
8841 if (is_attribute_p ("transaction_callable", attr
))
8842 return TM_ATTR_CALLABLE
;
8843 if (is_attribute_p ("transaction_pure", attr
))
8844 return TM_ATTR_PURE
;
8845 if (is_attribute_p ("transaction_unsafe", attr
))
8846 return TM_ATTR_IRREVOCABLE
;
8847 if (is_attribute_p ("transaction_may_cancel_outer", attr
))
8848 return TM_ATTR_MAY_CANCEL_OUTER
;
8853 tm_mask_to_attr (int mask
)
8859 str
= "transaction_safe";
8861 case TM_ATTR_CALLABLE
:
8862 str
= "transaction_callable";
8865 str
= "transaction_pure";
8867 case TM_ATTR_IRREVOCABLE
:
8868 str
= "transaction_unsafe";
8870 case TM_ATTR_MAY_CANCEL_OUTER
:
8871 str
= "transaction_may_cancel_outer";
8876 return get_identifier (str
);
8879 /* Return the first TM attribute seen in LIST. */
8882 find_tm_attribute (tree list
)
8884 for (; list
; list
= TREE_CHAIN (list
))
8886 tree name
= TREE_PURPOSE (list
);
8887 if (tm_attr_to_mask (name
) != 0)
8893 /* Handle the TM attributes; arguments as in struct attribute_spec.handler.
8894 Here we accept only function types, and verify that none of the other
8895 function TM attributes are also applied. */
8896 /* ??? We need to accept class types for C++, but not C. This greatly
8897 complicates this function, since we can no longer rely on the extra
8898 processing given by function_type_required. */
8901 handle_tm_attribute (tree
*node
, tree name
, tree args
,
8902 int flags
, bool *no_add_attrs
)
8904 /* Only one path adds the attribute; others don't. */
8905 *no_add_attrs
= true;
8907 switch (TREE_CODE (*node
))
8911 /* Only tm_callable and tm_safe apply to classes. */
8912 if (tm_attr_to_mask (name
) & ~(TM_ATTR_SAFE
| TM_ATTR_CALLABLE
))
8919 tree old_name
= find_tm_attribute (TYPE_ATTRIBUTES (*node
));
8920 if (old_name
== name
)
8922 else if (old_name
!= NULL_TREE
)
8923 error ("type was previously declared %qE", old_name
);
8925 *no_add_attrs
= false;
8931 /* transaction_safe_dynamic goes on the FUNCTION_DECL, but we also
8932 want to set transaction_safe on the type. */
8933 gcc_assert (is_attribute_p ("transaction_safe_dynamic", name
));
8934 if (!TYPE_P (DECL_CONTEXT (*node
)))
8935 error_at (DECL_SOURCE_LOCATION (*node
),
8936 "%<transaction_safe_dynamic%> may only be specified for "
8937 "a virtual function");
8938 *no_add_attrs
= false;
8939 decl_attributes (&TREE_TYPE (*node
),
8940 build_tree_list (get_identifier ("transaction_safe"),
8948 enum tree_code subcode
= TREE_CODE (TREE_TYPE (*node
));
8949 if (subcode
== FUNCTION_TYPE
|| subcode
== METHOD_TYPE
)
8951 tree fn_tmp
= TREE_TYPE (*node
);
8952 decl_attributes (&fn_tmp
, tree_cons (name
, args
, NULL
), 0);
8953 *node
= build_pointer_type (fn_tmp
);
8960 /* If a function is next, pass it on to be tried next. */
8961 if (flags
& (int) ATTR_FLAG_FUNCTION_NEXT
)
8962 return tree_cons (name
, args
, NULL
);
8965 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8972 /* Handle the TM_WRAP attribute; arguments as in
8973 struct attribute_spec.handler. */
8976 handle_tm_wrap_attribute (tree
*node
, tree name
, tree args
,
8977 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8981 /* We don't need the attribute even on success, since we
8982 record the entry in an external table. */
8983 *no_add_attrs
= true;
8985 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8986 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8989 tree wrap_decl
= TREE_VALUE (args
);
8990 if (error_operand_p (wrap_decl
))
8992 else if (TREE_CODE (wrap_decl
) != IDENTIFIER_NODE
8993 && !VAR_OR_FUNCTION_DECL_P (wrap_decl
))
8994 error ("%qE argument not an identifier", name
);
8997 if (TREE_CODE (wrap_decl
) == IDENTIFIER_NODE
)
8998 wrap_decl
= lookup_name (wrap_decl
);
8999 if (wrap_decl
&& TREE_CODE (wrap_decl
) == FUNCTION_DECL
)
9001 if (lang_hooks
.types_compatible_p (TREE_TYPE (decl
),
9002 TREE_TYPE (wrap_decl
)))
9003 record_tm_replacement (wrap_decl
, decl
);
9005 error ("%qD is not compatible with %qD", wrap_decl
, decl
);
9008 error ("%qE argument is not a function", name
);
9015 /* Ignore the given attribute. Used when this attribute may be usefully
9016 overridden by the target, but is not used generically. */
9019 ignore_attribute (tree
* ARG_UNUSED (node
), tree
ARG_UNUSED (name
),
9020 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
9023 *no_add_attrs
= true;
9027 /* Handle a "no vops" attribute; arguments as in
9028 struct attribute_spec.handler. */
9031 handle_novops_attribute (tree
*node
, tree
ARG_UNUSED (name
),
9032 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
9033 bool *ARG_UNUSED (no_add_attrs
))
9035 gcc_assert (TREE_CODE (*node
) == FUNCTION_DECL
);
9036 DECL_IS_NOVOPS (*node
) = 1;
9040 /* Handle a "deprecated" attribute; arguments as in
9041 struct attribute_spec.handler. */
9044 handle_deprecated_attribute (tree
*node
, tree name
,
9045 tree args
, int flags
,
9048 tree type
= NULL_TREE
;
9050 tree what
= NULL_TREE
;
9053 *no_add_attrs
= true;
9054 else if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
9056 error ("deprecated message is not a string");
9057 *no_add_attrs
= true;
9063 type
= TREE_TYPE (decl
);
9065 if (TREE_CODE (decl
) == TYPE_DECL
9066 || TREE_CODE (decl
) == PARM_DECL
9067 || VAR_OR_FUNCTION_DECL_P (decl
)
9068 || TREE_CODE (decl
) == FIELD_DECL
9069 || TREE_CODE (decl
) == CONST_DECL
9070 || objc_method_decl (TREE_CODE (decl
)))
9071 TREE_DEPRECATED (decl
) = 1;
9075 else if (TYPE_P (*node
))
9077 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
9078 *node
= build_variant_type_copy (*node
);
9079 TREE_DEPRECATED (*node
) = 1;
9087 *no_add_attrs
= true;
9088 if (type
&& TYPE_NAME (type
))
9090 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
9091 what
= TYPE_NAME (*node
);
9092 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
9093 && DECL_NAME (TYPE_NAME (type
)))
9094 what
= DECL_NAME (TYPE_NAME (type
));
9097 warning (OPT_Wattributes
, "%qE attribute ignored for %qE", name
, what
);
9099 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9105 /* Handle a "vector_size" attribute; arguments as in
9106 struct attribute_spec.handler. */
9109 handle_vector_size_attribute (tree
*node
, tree name
, tree args
,
9110 int ARG_UNUSED (flags
),
9113 unsigned HOST_WIDE_INT vecsize
, nunits
;
9114 machine_mode orig_mode
;
9115 tree type
= *node
, new_type
, size
;
9117 *no_add_attrs
= true;
9119 size
= TREE_VALUE (args
);
9120 if (size
&& TREE_CODE (size
) != IDENTIFIER_NODE
9121 && TREE_CODE (size
) != FUNCTION_DECL
)
9122 size
= default_conversion (size
);
9124 if (!tree_fits_uhwi_p (size
))
9126 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9130 /* Get the vector size (in bytes). */
9131 vecsize
= tree_to_uhwi (size
);
9133 /* We need to provide for vector pointers, vector arrays, and
9134 functions returning vectors. For example:
9136 __attribute__((vector_size(16))) short *foo;
9138 In this case, the mode is SI, but the type being modified is
9139 HI, so we need to look further. */
9141 while (POINTER_TYPE_P (type
)
9142 || TREE_CODE (type
) == FUNCTION_TYPE
9143 || TREE_CODE (type
) == METHOD_TYPE
9144 || TREE_CODE (type
) == ARRAY_TYPE
9145 || TREE_CODE (type
) == OFFSET_TYPE
)
9146 type
= TREE_TYPE (type
);
9148 /* Get the mode of the type being modified. */
9149 orig_mode
= TYPE_MODE (type
);
9151 if ((!INTEGRAL_TYPE_P (type
)
9152 && !SCALAR_FLOAT_TYPE_P (type
)
9153 && !FIXED_POINT_TYPE_P (type
))
9154 || (!SCALAR_FLOAT_MODE_P (orig_mode
)
9155 && GET_MODE_CLASS (orig_mode
) != MODE_INT
9156 && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode
))
9157 || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
9158 || TREE_CODE (type
) == BOOLEAN_TYPE
)
9160 error ("invalid vector type for attribute %qE", name
);
9164 if (vecsize
% tree_to_uhwi (TYPE_SIZE_UNIT (type
)))
9166 error ("vector size not an integral multiple of component size");
9172 error ("zero vector size");
9176 /* Calculate how many units fit in the vector. */
9177 nunits
= vecsize
/ tree_to_uhwi (TYPE_SIZE_UNIT (type
));
9178 if (nunits
& (nunits
- 1))
9180 error ("number of components of the vector not a power of two");
9184 new_type
= build_vector_type (type
, nunits
);
9186 /* Build back pointers if needed. */
9187 *node
= lang_hooks
.types
.reconstruct_complex_type (*node
, new_type
);
9192 /* Handle the "nonnull" attribute. */
9194 handle_nonnull_attribute (tree
*node
, tree
ARG_UNUSED (name
),
9195 tree args
, int ARG_UNUSED (flags
),
9199 unsigned HOST_WIDE_INT attr_arg_num
;
9201 /* If no arguments are specified, all pointer arguments should be
9202 non-null. Verify a full prototype is given so that the arguments
9203 will have the correct types when we actually check them later.
9204 Avoid diagnosing type-generic built-ins since those have no
9208 if (!prototype_p (type
)
9209 && (!TYPE_ATTRIBUTES (type
)
9210 || !lookup_attribute ("type generic", TYPE_ATTRIBUTES (type
))))
9212 error ("nonnull attribute without arguments on a non-prototype");
9213 *no_add_attrs
= true;
9218 /* Argument list specified. Verify that each argument number references
9219 a pointer argument. */
9220 for (attr_arg_num
= 1; args
; attr_arg_num
++, args
= TREE_CHAIN (args
))
9222 unsigned HOST_WIDE_INT arg_num
= 0, ck_num
;
9224 tree arg
= TREE_VALUE (args
);
9225 if (arg
&& TREE_CODE (arg
) != IDENTIFIER_NODE
9226 && TREE_CODE (arg
) != FUNCTION_DECL
)
9227 arg
= default_conversion (arg
);
9229 if (!get_nonnull_operand (arg
, &arg_num
))
9231 error ("nonnull argument has invalid operand number (argument %lu)",
9232 (unsigned long) attr_arg_num
);
9233 *no_add_attrs
= true;
9237 if (prototype_p (type
))
9239 function_args_iterator iter
;
9242 function_args_iter_init (&iter
, type
);
9243 for (ck_num
= 1; ; ck_num
++, function_args_iter_next (&iter
))
9245 argument
= function_args_iter_cond (&iter
);
9246 if (argument
== NULL_TREE
|| ck_num
== arg_num
)
9251 || TREE_CODE (argument
) == VOID_TYPE
)
9253 error ("nonnull argument with out-of-range operand number (argument %lu, operand %lu)",
9254 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
9255 *no_add_attrs
= true;
9259 if (TREE_CODE (argument
) != POINTER_TYPE
)
9261 error ("nonnull argument references non-pointer operand (argument %lu, operand %lu)",
9262 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
9263 *no_add_attrs
= true;
9272 /* Check the argument list of a function call for null in argument slots
9273 that are marked as requiring a non-null pointer argument. The NARGS
9274 arguments are passed in the array ARGARRAY. */
9277 check_function_nonnull (location_t loc
, tree attrs
, int nargs
, tree
*argarray
)
9282 attrs
= lookup_attribute ("nonnull", attrs
);
9283 if (attrs
== NULL_TREE
)
9287 /* See if any of the nonnull attributes has no arguments. If so,
9288 then every pointer argument is checked (in which case the check
9289 for pointer type is done in check_nonnull_arg). */
9290 if (TREE_VALUE (a
) != NULL_TREE
)
9292 a
= lookup_attribute ("nonnull", TREE_CHAIN (a
));
9293 while (a
!= NULL_TREE
&& TREE_VALUE (a
) != NULL_TREE
);
9296 for (i
= 0; i
< nargs
; i
++)
9297 check_function_arguments_recurse (check_nonnull_arg
, &loc
, argarray
[i
],
9301 /* Walk the argument list. If we encounter an argument number we
9302 should check for non-null, do it. */
9303 for (i
= 0; i
< nargs
; i
++)
9305 for (a
= attrs
; ; a
= TREE_CHAIN (a
))
9307 a
= lookup_attribute ("nonnull", a
);
9308 if (a
== NULL_TREE
|| nonnull_check_p (TREE_VALUE (a
), i
+ 1))
9313 check_function_arguments_recurse (check_nonnull_arg
, &loc
,
9314 argarray
[i
], i
+ 1);
9319 /* Check that the Nth argument of a function call (counting backwards
9320 from the end) is a (pointer)0. The NARGS arguments are passed in the
9324 check_function_sentinel (const_tree fntype
, int nargs
, tree
*argarray
)
9326 tree attr
= lookup_attribute ("sentinel", TYPE_ATTRIBUTES (fntype
));
9333 function_args_iterator iter
;
9336 /* Skip over the named arguments. */
9337 FOREACH_FUNCTION_ARGS (fntype
, t
, iter
)
9344 if (TREE_VALUE (attr
))
9346 tree p
= TREE_VALUE (TREE_VALUE (attr
));
9347 pos
= TREE_INT_CST_LOW (p
);
9350 /* The sentinel must be one of the varargs, i.e.
9351 in position >= the number of fixed arguments. */
9352 if ((nargs
- 1 - pos
) < len
)
9354 warning (OPT_Wformat_
,
9355 "not enough variable arguments to fit a sentinel");
9359 /* Validate the sentinel. */
9360 sentinel
= argarray
[nargs
- 1 - pos
];
9361 if ((!POINTER_TYPE_P (TREE_TYPE (sentinel
))
9362 || !integer_zerop (sentinel
))
9363 /* Although __null (in C++) is only an integer we allow it
9364 nevertheless, as we are guaranteed that it's exactly
9365 as wide as a pointer, and we don't want to force
9366 users to cast the NULL they have written there.
9367 We warn with -Wstrict-null-sentinel, though. */
9368 && (warn_strict_null_sentinel
|| null_node
!= sentinel
))
9369 warning (OPT_Wformat_
, "missing sentinel in function call");
9373 /* Helper for check_function_nonnull; given a list of operands which
9374 must be non-null in ARGS, determine if operand PARAM_NUM should be
9378 nonnull_check_p (tree args
, unsigned HOST_WIDE_INT param_num
)
9380 unsigned HOST_WIDE_INT arg_num
= 0;
9382 for (; args
; args
= TREE_CHAIN (args
))
9384 bool found
= get_nonnull_operand (TREE_VALUE (args
), &arg_num
);
9388 if (arg_num
== param_num
)
9394 /* Check that the function argument PARAM (which is operand number
9395 PARAM_NUM) is non-null. This is called by check_function_nonnull
9396 via check_function_arguments_recurse. */
9399 check_nonnull_arg (void *ctx
, tree param
, unsigned HOST_WIDE_INT param_num
)
9401 location_t
*ploc
= (location_t
*) ctx
;
9403 /* Just skip checking the argument if it's not a pointer. This can
9404 happen if the "nonnull" attribute was given without an operand
9405 list (which means to check every pointer argument). */
9407 if (TREE_CODE (TREE_TYPE (param
)) != POINTER_TYPE
)
9410 if (integer_zerop (param
))
9411 warning_at (*ploc
, OPT_Wnonnull
, "null argument where non-null required "
9412 "(argument %lu)", (unsigned long) param_num
);
9415 /* Helper for nonnull attribute handling; fetch the operand number
9416 from the attribute argument list. */
9419 get_nonnull_operand (tree arg_num_expr
, unsigned HOST_WIDE_INT
*valp
)
9421 /* Verify the arg number is a small constant. */
9422 if (tree_fits_uhwi_p (arg_num_expr
))
9424 *valp
= TREE_INT_CST_LOW (arg_num_expr
);
9431 /* Handle a "nothrow" attribute; arguments as in
9432 struct attribute_spec.handler. */
9435 handle_nothrow_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
9436 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9438 if (TREE_CODE (*node
) == FUNCTION_DECL
)
9439 TREE_NOTHROW (*node
) = 1;
9440 /* ??? TODO: Support types. */
9443 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9444 *no_add_attrs
= true;
9450 /* Handle a "cleanup" attribute; arguments as in
9451 struct attribute_spec.handler. */
9454 handle_cleanup_attribute (tree
*node
, tree name
, tree args
,
9455 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9458 tree cleanup_id
, cleanup_decl
;
9460 /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
9461 for global destructors in C++. This requires infrastructure that
9462 we don't have generically at the moment. It's also not a feature
9463 we'd be missing too much, since we do have attribute constructor. */
9464 if (!VAR_P (decl
) || TREE_STATIC (decl
))
9466 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9467 *no_add_attrs
= true;
9471 /* Verify that the argument is a function in scope. */
9472 /* ??? We could support pointers to functions here as well, if
9473 that was considered desirable. */
9474 cleanup_id
= TREE_VALUE (args
);
9475 if (TREE_CODE (cleanup_id
) != IDENTIFIER_NODE
)
9477 error ("cleanup argument not an identifier");
9478 *no_add_attrs
= true;
9481 cleanup_decl
= lookup_name (cleanup_id
);
9482 if (!cleanup_decl
|| TREE_CODE (cleanup_decl
) != FUNCTION_DECL
)
9484 error ("cleanup argument not a function");
9485 *no_add_attrs
= true;
9489 /* That the function has proper type is checked with the
9490 eventual call to build_function_call. */
9495 /* Handle a "warn_unused_result" attribute. No special handling. */
9498 handle_warn_unused_result_attribute (tree
*node
, tree name
,
9499 tree
ARG_UNUSED (args
),
9500 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9502 /* Ignore the attribute for functions not returning any value. */
9503 if (VOID_TYPE_P (TREE_TYPE (*node
)))
9505 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9506 *no_add_attrs
= true;
9512 /* Handle a "sentinel" attribute. */
9515 handle_sentinel_attribute (tree
*node
, tree name
, tree args
,
9516 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9518 if (!prototype_p (*node
))
9520 warning (OPT_Wattributes
,
9521 "%qE attribute requires prototypes with named arguments", name
);
9522 *no_add_attrs
= true;
9526 if (!stdarg_p (*node
))
9528 warning (OPT_Wattributes
,
9529 "%qE attribute only applies to variadic functions", name
);
9530 *no_add_attrs
= true;
9536 tree position
= TREE_VALUE (args
);
9537 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
9538 && TREE_CODE (position
) != FUNCTION_DECL
)
9539 position
= default_conversion (position
);
9541 if (TREE_CODE (position
) != INTEGER_CST
9542 || !INTEGRAL_TYPE_P (TREE_TYPE (position
)))
9544 warning (OPT_Wattributes
,
9545 "requested position is not an integer constant");
9546 *no_add_attrs
= true;
9550 if (tree_int_cst_lt (position
, integer_zero_node
))
9552 warning (OPT_Wattributes
,
9553 "requested position is less than zero");
9554 *no_add_attrs
= true;
9562 /* Handle a "type_generic" attribute. */
9565 handle_type_generic_attribute (tree
*node
, tree
ARG_UNUSED (name
),
9566 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
9567 bool * ARG_UNUSED (no_add_attrs
))
9569 /* Ensure we have a function type. */
9570 gcc_assert (TREE_CODE (*node
) == FUNCTION_TYPE
);
9572 /* Ensure we have a variadic function. */
9573 gcc_assert (!prototype_p (*node
) || stdarg_p (*node
));
9578 /* Handle a "target" attribute. */
9581 handle_target_attribute (tree
*node
, tree name
, tree args
, int flags
,
9584 /* Ensure we have a function type. */
9585 if (TREE_CODE (*node
) != FUNCTION_DECL
)
9587 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9588 *no_add_attrs
= true;
9590 else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node
)))
9592 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
9593 "with %qs attribute", name
, "target_clones");
9594 *no_add_attrs
= true;
9596 else if (! targetm
.target_option
.valid_attribute_p (*node
, name
, args
,
9598 *no_add_attrs
= true;
9603 /* Handle a "target_clones" attribute. */
9606 handle_target_clones_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
9607 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9609 /* Ensure we have a function type. */
9610 if (TREE_CODE (*node
) == FUNCTION_DECL
)
9612 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node
)))
9614 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
9615 "with %qs attribute", name
, "always_inline");
9616 *no_add_attrs
= true;
9618 else if (lookup_attribute ("target", DECL_ATTRIBUTES (*node
)))
9620 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
9621 "with %qs attribute", name
, "target");
9622 *no_add_attrs
= true;
9625 /* Do not inline functions with multiple clone targets. */
9626 DECL_UNINLINABLE (*node
) = 1;
9630 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9631 *no_add_attrs
= true;
9636 /* Arguments being collected for optimization. */
9637 typedef const char *const_char_p
; /* For DEF_VEC_P. */
9638 static GTY(()) vec
<const_char_p
, va_gc
> *optimize_args
;
9641 /* Inner function to convert a TREE_LIST to argv string to parse the optimize
9642 options in ARGS. ATTR_P is true if this is for attribute(optimize), and
9643 false for #pragma GCC optimize. */
9646 parse_optimize_options (tree args
, bool attr_p
)
9651 const char **opt_argv
;
9652 struct cl_decoded_option
*decoded_options
;
9653 unsigned int decoded_options_count
;
9656 /* Build up argv vector. Just in case the string is stored away, use garbage
9657 collected strings. */
9658 vec_safe_truncate (optimize_args
, 0);
9659 vec_safe_push (optimize_args
, (const char *) NULL
);
9661 for (ap
= args
; ap
!= NULL_TREE
; ap
= TREE_CHAIN (ap
))
9663 tree value
= TREE_VALUE (ap
);
9665 if (TREE_CODE (value
) == INTEGER_CST
)
9668 sprintf (buffer
, "-O%ld", (long) TREE_INT_CST_LOW (value
));
9669 vec_safe_push (optimize_args
, ggc_strdup (buffer
));
9672 else if (TREE_CODE (value
) == STRING_CST
)
9674 /* Split string into multiple substrings. */
9675 size_t len
= TREE_STRING_LENGTH (value
);
9676 char *p
= ASTRDUP (TREE_STRING_POINTER (value
));
9677 char *end
= p
+ len
;
9681 while (next_p
!= NULL
)
9687 comma
= strchr (p
, ',');
9700 r
= q
= (char *) ggc_alloc_atomic (len2
+ 3);
9702 /* If the user supplied -Oxxx or -fxxx, only allow -Oxxx or -fxxx
9704 if (*p
== '-' && p
[1] != 'O' && p
[1] != 'f')
9708 warning (OPT_Wattributes
,
9709 "bad option %qs to attribute %<optimize%>", p
);
9711 warning (OPT_Wpragmas
,
9712 "bad option %qs to pragma %<optimize%>", p
);
9720 /* Assume that Ox is -Ox, a numeric value is -Ox, a s by
9721 itself is -Os, and any other switch begins with a -f. */
9722 if ((*p
>= '0' && *p
<= '9')
9723 || (p
[0] == 's' && p
[1] == '\0'))
9729 memcpy (r
, p
, len2
);
9731 vec_safe_push (optimize_args
, (const char *) q
);
9737 opt_argc
= optimize_args
->length ();
9738 opt_argv
= (const char **) alloca (sizeof (char *) * (opt_argc
+ 1));
9740 for (i
= 1; i
< opt_argc
; i
++)
9741 opt_argv
[i
] = (*optimize_args
)[i
];
9743 /* Now parse the options. */
9744 decode_cmdline_options_to_array_default_mask (opt_argc
, opt_argv
,
9746 &decoded_options_count
);
9747 /* Drop non-Optimization options. */
9749 for (i
= 1; i
< decoded_options_count
; ++i
)
9751 if (! (cl_options
[decoded_options
[i
].opt_index
].flags
& CL_OPTIMIZATION
))
9755 warning (OPT_Wattributes
,
9756 "bad option %qs to attribute %<optimize%>",
9757 decoded_options
[i
].orig_option_with_args_text
);
9759 warning (OPT_Wpragmas
,
9760 "bad option %qs to pragma %<optimize%>",
9761 decoded_options
[i
].orig_option_with_args_text
);
9765 decoded_options
[j
] = decoded_options
[i
];
9768 decoded_options_count
= j
;
9769 /* And apply them. */
9770 decode_options (&global_options
, &global_options_set
,
9771 decoded_options
, decoded_options_count
,
9772 input_location
, global_dc
);
9774 targetm
.override_options_after_change();
9776 optimize_args
->truncate (0);
9780 /* For handling "optimize" attribute. arguments as in
9781 struct attribute_spec.handler. */
9784 handle_optimize_attribute (tree
*node
, tree name
, tree args
,
9785 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9787 /* Ensure we have a function type. */
9788 if (TREE_CODE (*node
) != FUNCTION_DECL
)
9790 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9791 *no_add_attrs
= true;
9795 struct cl_optimization cur_opts
;
9796 tree old_opts
= DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
);
9798 /* Save current options. */
9799 cl_optimization_save (&cur_opts
, &global_options
);
9801 /* If we previously had some optimization options, use them as the
9804 cl_optimization_restore (&global_options
,
9805 TREE_OPTIMIZATION (old_opts
));
9807 /* Parse options, and update the vector. */
9808 parse_optimize_options (args
, true);
9809 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
)
9810 = build_optimization_node (&global_options
);
9812 /* Restore current options. */
9813 cl_optimization_restore (&global_options
, &cur_opts
);
9819 /* Handle a "no_split_stack" attribute. */
9822 handle_no_split_stack_attribute (tree
*node
, tree name
,
9823 tree
ARG_UNUSED (args
),
9824 int ARG_UNUSED (flags
),
9829 if (TREE_CODE (decl
) != FUNCTION_DECL
)
9831 error_at (DECL_SOURCE_LOCATION (decl
),
9832 "%qE attribute applies only to functions", name
);
9833 *no_add_attrs
= true;
9835 else if (DECL_INITIAL (decl
))
9837 error_at (DECL_SOURCE_LOCATION (decl
),
9838 "can%'t set %qE attribute after definition", name
);
9839 *no_add_attrs
= true;
9845 /* Handle a "returns_nonnull" attribute; arguments as in
9846 struct attribute_spec.handler. */
9849 handle_returns_nonnull_attribute (tree
*node
, tree
, tree
, int,
9852 // Even without a prototype we still have a return type we can check.
9853 if (TREE_CODE (TREE_TYPE (*node
)) != POINTER_TYPE
)
9855 error ("returns_nonnull attribute on a function not returning a pointer");
9856 *no_add_attrs
= true;
9861 /* Handle a "designated_init" attribute; arguments as in
9862 struct attribute_spec.handler. */
9865 handle_designated_init_attribute (tree
*node
, tree name
, tree
, int,
9868 if (TREE_CODE (*node
) != RECORD_TYPE
)
9870 error ("%qE attribute is only valid on %<struct%> type", name
);
9871 *no_add_attrs
= true;
9877 /* Handle a "fallthrough" attribute; arguments as in struct
9878 attribute_spec.handler. */
9881 handle_fallthrough_attribute (tree
*, tree name
, tree
, int,
9884 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9885 *no_add_attrs
= true;
9889 /* Check whether ATTR is a valid attribute fallthrough. */
9892 attribute_fallthrough_p (tree attr
)
9894 tree t
= lookup_attribute ("fallthrough", attr
);
9897 /* This attribute shall appear at most once in each attribute-list. */
9898 if (lookup_attribute ("fallthrough", TREE_CHAIN (t
)))
9899 warning (OPT_Wattributes
, "%<fallthrough%> attribute specified multiple "
9901 /* No attribute-argument-clause shall be present. */
9902 else if (TREE_VALUE (t
) != NULL_TREE
)
9903 warning (OPT_Wattributes
, "%<fallthrough%> attribute specified with "
9905 /* Warn if other attributes are found. */
9906 for (t
= attr
; t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
9908 tree name
= get_attribute_name (t
);
9909 if (!is_attribute_p ("fallthrough", name
))
9910 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9916 /* Check for valid arguments being passed to a function with FNTYPE.
9917 There are NARGS arguments in the array ARGARRAY. LOC should be used for
9920 check_function_arguments (location_t loc
, const_tree fntype
, int nargs
,
9923 /* Check for null being passed in a pointer argument that must be
9924 non-null. We also need to do this if format checking is enabled. */
9927 check_function_nonnull (loc
, TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
9929 /* Check for errors in format strings. */
9931 if (warn_format
|| warn_suggest_attribute_format
)
9932 check_function_format (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
9935 check_function_sentinel (fntype
, nargs
, argarray
);
9938 /* Generic argument checking recursion routine. PARAM is the argument to
9939 be checked. PARAM_NUM is the number of the argument. CALLBACK is invoked
9940 once the argument is resolved. CTX is context for the callback. */
9942 check_function_arguments_recurse (void (*callback
)
9943 (void *, tree
, unsigned HOST_WIDE_INT
),
9944 void *ctx
, tree param
,
9945 unsigned HOST_WIDE_INT param_num
)
9947 if (CONVERT_EXPR_P (param
)
9948 && (TYPE_PRECISION (TREE_TYPE (param
))
9949 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (param
, 0)))))
9951 /* Strip coercion. */
9952 check_function_arguments_recurse (callback
, ctx
,
9953 TREE_OPERAND (param
, 0), param_num
);
9957 if (TREE_CODE (param
) == CALL_EXPR
)
9959 tree type
= TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (param
)));
9961 bool found_format_arg
= false;
9963 /* See if this is a call to a known internationalization function
9964 that modifies a format arg. Such a function may have multiple
9965 format_arg attributes (for example, ngettext). */
9967 for (attrs
= TYPE_ATTRIBUTES (type
);
9969 attrs
= TREE_CHAIN (attrs
))
9970 if (is_attribute_p ("format_arg", TREE_PURPOSE (attrs
)))
9973 tree format_num_expr
;
9976 call_expr_arg_iterator iter
;
9978 /* Extract the argument number, which was previously checked
9980 format_num_expr
= TREE_VALUE (TREE_VALUE (attrs
));
9982 format_num
= tree_to_uhwi (format_num_expr
);
9984 for (inner_arg
= first_call_expr_arg (param
, &iter
), i
= 1;
9986 inner_arg
= next_call_expr_arg (&iter
), i
++)
9987 if (i
== format_num
)
9989 check_function_arguments_recurse (callback
, ctx
,
9990 inner_arg
, param_num
);
9991 found_format_arg
= true;
9996 /* If we found a format_arg attribute and did a recursive check,
9997 we are done with checking this argument. Otherwise, we continue
9998 and this will be considered a non-literal. */
9999 if (found_format_arg
)
10003 if (TREE_CODE (param
) == COND_EXPR
)
10005 /* Simplify to avoid warning for an impossible case. */
10006 param
= fold_for_warn (param
);
10007 if (TREE_CODE (param
) == COND_EXPR
)
10009 /* Check both halves of the conditional expression. */
10010 check_function_arguments_recurse (callback
, ctx
,
10011 TREE_OPERAND (param
, 1),
10013 check_function_arguments_recurse (callback
, ctx
,
10014 TREE_OPERAND (param
, 2),
10020 (*callback
) (ctx
, param
, param_num
);
10023 /* Checks for a builtin function FNDECL that the number of arguments
10024 NARGS against the required number REQUIRED and issues an error if
10025 there is a mismatch. Returns true if the number of arguments is
10026 correct, otherwise false. LOC is the location of FNDECL. */
10029 builtin_function_validate_nargs (location_t loc
, tree fndecl
, int nargs
,
10032 if (nargs
< required
)
10034 error_at (loc
, "too few arguments to function %qE", fndecl
);
10037 else if (nargs
> required
)
10039 error_at (loc
, "too many arguments to function %qE", fndecl
);
10045 /* Helper macro for check_builtin_function_arguments. */
10046 #define ARG_LOCATION(N) \
10047 (arg_loc.is_empty () \
10048 ? EXPR_LOC_OR_LOC (args[(N)], input_location) \
10049 : expansion_point_location (arg_loc[(N)]))
10051 /* Verifies the NARGS arguments ARGS to the builtin function FNDECL.
10052 Returns false if there was an error, otherwise true. LOC is the
10053 location of the function; ARG_LOC is a vector of locations of the
10057 check_builtin_function_arguments (location_t loc
, vec
<location_t
> arg_loc
,
10058 tree fndecl
, int nargs
, tree
*args
)
10060 if (!DECL_BUILT_IN (fndecl
)
10061 || DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_NORMAL
)
10064 switch (DECL_FUNCTION_CODE (fndecl
))
10066 case BUILT_IN_ALLOCA_WITH_ALIGN
:
10068 /* Get the requested alignment (in bits) if it's a constant
10069 integer expression. */
10070 unsigned HOST_WIDE_INT align
10071 = tree_fits_uhwi_p (args
[1]) ? tree_to_uhwi (args
[1]) : 0;
10073 /* Determine if the requested alignment is a power of 2. */
10074 if ((align
& (align
- 1)))
10077 /* The maximum alignment in bits corresponding to the same
10078 maximum in bytes enforced in check_user_alignment(). */
10079 unsigned maxalign
= (UINT_MAX
>> 1) + 1;
10081 /* Reject invalid alignments. */
10082 if (align
< BITS_PER_UNIT
|| maxalign
< align
)
10084 error_at (ARG_LOCATION (1),
10085 "second argument to function %qE must be a constant "
10086 "integer power of 2 between %qi and %qu bits",
10087 fndecl
, BITS_PER_UNIT
, maxalign
);
10093 case BUILT_IN_CONSTANT_P
:
10094 return builtin_function_validate_nargs (loc
, fndecl
, nargs
, 1);
10096 case BUILT_IN_ISFINITE
:
10097 case BUILT_IN_ISINF
:
10098 case BUILT_IN_ISINF_SIGN
:
10099 case BUILT_IN_ISNAN
:
10100 case BUILT_IN_ISNORMAL
:
10101 case BUILT_IN_SIGNBIT
:
10102 if (builtin_function_validate_nargs (loc
, fndecl
, nargs
, 1))
10104 if (TREE_CODE (TREE_TYPE (args
[0])) != REAL_TYPE
)
10106 error_at (ARG_LOCATION (0), "non-floating-point argument in "
10107 "call to function %qE", fndecl
);
10114 case BUILT_IN_ISGREATER
:
10115 case BUILT_IN_ISGREATEREQUAL
:
10116 case BUILT_IN_ISLESS
:
10117 case BUILT_IN_ISLESSEQUAL
:
10118 case BUILT_IN_ISLESSGREATER
:
10119 case BUILT_IN_ISUNORDERED
:
10120 if (builtin_function_validate_nargs (loc
, fndecl
, nargs
, 2))
10122 enum tree_code code0
, code1
;
10123 code0
= TREE_CODE (TREE_TYPE (args
[0]));
10124 code1
= TREE_CODE (TREE_TYPE (args
[1]));
10125 if (!((code0
== REAL_TYPE
&& code1
== REAL_TYPE
)
10126 || (code0
== REAL_TYPE
&& code1
== INTEGER_TYPE
)
10127 || (code0
== INTEGER_TYPE
&& code1
== REAL_TYPE
)))
10129 error_at (loc
, "non-floating-point arguments in call to "
10130 "function %qE", fndecl
);
10137 case BUILT_IN_FPCLASSIFY
:
10138 if (builtin_function_validate_nargs (loc
, fndecl
, nargs
, 6))
10140 for (unsigned int i
= 0; i
< 5; i
++)
10141 if (TREE_CODE (args
[i
]) != INTEGER_CST
)
10143 error_at (ARG_LOCATION (i
), "non-const integer argument %u in "
10144 "call to function %qE", i
+ 1, fndecl
);
10148 if (TREE_CODE (TREE_TYPE (args
[5])) != REAL_TYPE
)
10150 error_at (ARG_LOCATION (5), "non-floating-point argument in "
10151 "call to function %qE", fndecl
);
10158 case BUILT_IN_ASSUME_ALIGNED
:
10159 if (builtin_function_validate_nargs (loc
, fndecl
, nargs
, 2 + (nargs
> 2)))
10161 if (nargs
>= 3 && TREE_CODE (TREE_TYPE (args
[2])) != INTEGER_TYPE
)
10163 error_at (ARG_LOCATION (2), "non-integer argument 3 in call to "
10164 "function %qE", fndecl
);
10171 case BUILT_IN_ADD_OVERFLOW
:
10172 case BUILT_IN_SUB_OVERFLOW
:
10173 case BUILT_IN_MUL_OVERFLOW
:
10174 if (builtin_function_validate_nargs (loc
, fndecl
, nargs
, 3))
10177 for (i
= 0; i
< 2; i
++)
10178 if (!INTEGRAL_TYPE_P (TREE_TYPE (args
[i
])))
10180 error_at (ARG_LOCATION (i
), "argument %u in call to function "
10181 "%qE does not have integral type", i
+ 1, fndecl
);
10184 if (TREE_CODE (TREE_TYPE (args
[2])) != POINTER_TYPE
10185 || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (args
[2]))))
10187 error_at (ARG_LOCATION (2), "argument 3 in call to function %qE "
10188 "does not have pointer to integral type", fndecl
);
10191 else if (TREE_CODE (TREE_TYPE (TREE_TYPE (args
[2]))) == ENUMERAL_TYPE
)
10193 error_at (ARG_LOCATION (2), "argument 3 in call to function %qE "
10194 "has pointer to enumerated type", fndecl
);
10197 else if (TREE_CODE (TREE_TYPE (TREE_TYPE (args
[2]))) == BOOLEAN_TYPE
)
10199 error_at (ARG_LOCATION (2), "argument 3 in call to function %qE "
10200 "has pointer to boolean type", fndecl
);
10207 case BUILT_IN_ADD_OVERFLOW_P
:
10208 case BUILT_IN_SUB_OVERFLOW_P
:
10209 case BUILT_IN_MUL_OVERFLOW_P
:
10210 if (builtin_function_validate_nargs (loc
, fndecl
, nargs
, 3))
10213 for (i
= 0; i
< 3; i
++)
10214 if (!INTEGRAL_TYPE_P (TREE_TYPE (args
[i
])))
10216 error_at (ARG_LOCATION (i
), "argument %u in call to function "
10217 "%qE does not have integral type", i
+ 1, fndecl
);
10220 if (TREE_CODE (TREE_TYPE (args
[2])) == ENUMERAL_TYPE
)
10222 error_at (ARG_LOCATION (2), "argument 3 in call to function "
10223 "%qE has enumerated type", fndecl
);
10226 else if (TREE_CODE (TREE_TYPE (args
[2])) == BOOLEAN_TYPE
)
10228 error_at (ARG_LOCATION (2), "argument 3 in call to function "
10229 "%qE has boolean type", fndecl
);
10241 /* Function to help qsort sort FIELD_DECLs by name order. */
10244 field_decl_cmp (const void *x_p
, const void *y_p
)
10246 const tree
*const x
= (const tree
*const) x_p
;
10247 const tree
*const y
= (const tree
*const) y_p
;
10249 if (DECL_NAME (*x
) == DECL_NAME (*y
))
10250 /* A nontype is "greater" than a type. */
10251 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
10252 if (DECL_NAME (*x
) == NULL_TREE
)
10254 if (DECL_NAME (*y
) == NULL_TREE
)
10256 if (DECL_NAME (*x
) < DECL_NAME (*y
))
10262 gt_pointer_operator new_value
;
10266 /* This routine compares two fields like field_decl_cmp but using the
10267 pointer operator in resort_data. */
10270 resort_field_decl_cmp (const void *x_p
, const void *y_p
)
10272 const tree
*const x
= (const tree
*const) x_p
;
10273 const tree
*const y
= (const tree
*const) y_p
;
10275 if (DECL_NAME (*x
) == DECL_NAME (*y
))
10276 /* A nontype is "greater" than a type. */
10277 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
10278 if (DECL_NAME (*x
) == NULL_TREE
)
10280 if (DECL_NAME (*y
) == NULL_TREE
)
10283 tree d1
= DECL_NAME (*x
);
10284 tree d2
= DECL_NAME (*y
);
10285 resort_data
.new_value (&d1
, resort_data
.cookie
);
10286 resort_data
.new_value (&d2
, resort_data
.cookie
);
10293 /* Resort DECL_SORTED_FIELDS because pointers have been reordered. */
10296 resort_sorted_fields (void *obj
,
10297 void * ARG_UNUSED (orig_obj
),
10298 gt_pointer_operator new_value
,
10301 struct sorted_fields_type
*sf
= (struct sorted_fields_type
*) obj
;
10302 resort_data
.new_value
= new_value
;
10303 resort_data
.cookie
= cookie
;
10304 qsort (&sf
->elts
[0], sf
->len
, sizeof (tree
),
10305 resort_field_decl_cmp
);
10308 /* Subroutine of c_parse_error.
10309 Return the result of concatenating LHS and RHS. RHS is really
10310 a string literal, its first character is indicated by RHS_START and
10311 RHS_SIZE is its length (including the terminating NUL character).
10313 The caller is responsible for deleting the returned pointer. */
10316 catenate_strings (const char *lhs
, const char *rhs_start
, int rhs_size
)
10318 const int lhs_size
= strlen (lhs
);
10319 char *result
= XNEWVEC (char, lhs_size
+ rhs_size
);
10320 strncpy (result
, lhs
, lhs_size
);
10321 strncpy (result
+ lhs_size
, rhs_start
, rhs_size
);
10325 /* Issue the error given by GMSGID, indicating that it occurred before
10326 TOKEN, which had the associated VALUE. */
10329 c_parse_error (const char *gmsgid
, enum cpp_ttype token_type
,
10330 tree value
, unsigned char token_flags
)
10332 #define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2))
10334 char *message
= NULL
;
10336 if (token_type
== CPP_EOF
)
10337 message
= catenate_messages (gmsgid
, " at end of input");
10338 else if (token_type
== CPP_CHAR
10339 || token_type
== CPP_WCHAR
10340 || token_type
== CPP_CHAR16
10341 || token_type
== CPP_CHAR32
10342 || token_type
== CPP_UTF8CHAR
)
10344 unsigned int val
= TREE_INT_CST_LOW (value
);
10345 const char *prefix
;
10347 switch (token_type
)
10366 if (val
<= UCHAR_MAX
&& ISGRAPH (val
))
10367 message
= catenate_messages (gmsgid
, " before %s'%c'");
10369 message
= catenate_messages (gmsgid
, " before %s'\\x%x'");
10371 error (message
, prefix
, val
);
10375 else if (token_type
== CPP_CHAR_USERDEF
10376 || token_type
== CPP_WCHAR_USERDEF
10377 || token_type
== CPP_CHAR16_USERDEF
10378 || token_type
== CPP_CHAR32_USERDEF
10379 || token_type
== CPP_UTF8CHAR_USERDEF
)
10380 message
= catenate_messages (gmsgid
,
10381 " before user-defined character literal");
10382 else if (token_type
== CPP_STRING_USERDEF
10383 || token_type
== CPP_WSTRING_USERDEF
10384 || token_type
== CPP_STRING16_USERDEF
10385 || token_type
== CPP_STRING32_USERDEF
10386 || token_type
== CPP_UTF8STRING_USERDEF
)
10387 message
= catenate_messages (gmsgid
, " before user-defined string literal");
10388 else if (token_type
== CPP_STRING
10389 || token_type
== CPP_WSTRING
10390 || token_type
== CPP_STRING16
10391 || token_type
== CPP_STRING32
10392 || token_type
== CPP_UTF8STRING
)
10393 message
= catenate_messages (gmsgid
, " before string constant");
10394 else if (token_type
== CPP_NUMBER
)
10395 message
= catenate_messages (gmsgid
, " before numeric constant");
10396 else if (token_type
== CPP_NAME
)
10398 message
= catenate_messages (gmsgid
, " before %qE");
10399 error (message
, value
);
10403 else if (token_type
== CPP_PRAGMA
)
10404 message
= catenate_messages (gmsgid
, " before %<#pragma%>");
10405 else if (token_type
== CPP_PRAGMA_EOL
)
10406 message
= catenate_messages (gmsgid
, " before end of line");
10407 else if (token_type
== CPP_DECLTYPE
)
10408 message
= catenate_messages (gmsgid
, " before %<decltype%>");
10409 else if (token_type
< N_TTYPES
)
10411 message
= catenate_messages (gmsgid
, " before %qs token");
10412 error (message
, cpp_type2name (token_type
, token_flags
));
10424 #undef catenate_messages
10427 /* Return the gcc option code associated with the reason for a cpp
10428 message, or 0 if none. */
10431 c_option_controlling_cpp_error (int reason
)
10433 const struct cpp_reason_option_codes_t
*entry
;
10435 for (entry
= cpp_reason_option_codes
; entry
->reason
!= CPP_W_NONE
; entry
++)
10437 if (entry
->reason
== reason
)
10438 return entry
->option_code
;
10443 /* Callback from cpp_error for PFILE to print diagnostics from the
10444 preprocessor. The diagnostic is of type LEVEL, with REASON set
10445 to the reason code if LEVEL is represents a warning, at location
10446 RICHLOC unless this is after lexing and the compiler's location
10447 should be used instead; MSG is the translated message and AP
10448 the arguments. Returns true if a diagnostic was emitted, false
10452 c_cpp_error (cpp_reader
*pfile ATTRIBUTE_UNUSED
, int level
, int reason
,
10453 rich_location
*richloc
,
10454 const char *msg
, va_list *ap
)
10456 diagnostic_info diagnostic
;
10457 diagnostic_t dlevel
;
10458 bool save_warn_system_headers
= global_dc
->dc_warn_system_headers
;
10463 case CPP_DL_WARNING_SYSHDR
:
10464 if (flag_no_output
)
10466 global_dc
->dc_warn_system_headers
= 1;
10467 /* Fall through. */
10468 case CPP_DL_WARNING
:
10469 if (flag_no_output
)
10471 dlevel
= DK_WARNING
;
10473 case CPP_DL_PEDWARN
:
10474 if (flag_no_output
&& !flag_pedantic_errors
)
10476 dlevel
= DK_PEDWARN
;
10491 gcc_unreachable ();
10494 richloc
->set_range (line_table
, 0, input_location
, true);
10495 diagnostic_set_info_translated (&diagnostic
, msg
, ap
,
10497 diagnostic_override_option_index (&diagnostic
,
10498 c_option_controlling_cpp_error (reason
));
10499 ret
= report_diagnostic (&diagnostic
);
10500 if (level
== CPP_DL_WARNING_SYSHDR
)
10501 global_dc
->dc_warn_system_headers
= save_warn_system_headers
;
10505 /* Convert a character from the host to the target execution character
10506 set. cpplib handles this, mostly. */
10509 c_common_to_target_charset (HOST_WIDE_INT c
)
10511 /* Character constants in GCC proper are sign-extended under -fsigned-char,
10512 zero-extended under -fno-signed-char. cpplib insists that characters
10513 and character constants are always unsigned. Hence we must convert
10515 cppchar_t uc
= ((cppchar_t
)c
) & ((((cppchar_t
)1) << CHAR_BIT
)-1);
10517 uc
= cpp_host_to_exec_charset (parse_in
, uc
);
10519 if (flag_signed_char
)
10520 return ((HOST_WIDE_INT
)uc
) << (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
)
10521 >> (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
);
10526 /* Fold an offsetof-like expression. EXPR is a nested sequence of component
10527 references with an INDIRECT_REF of a constant at the bottom; much like the
10528 traditional rendering of offsetof as a macro. Return the folded result. */
10531 fold_offsetof_1 (tree expr
, enum tree_code ctx
)
10534 tree_code code
= TREE_CODE (expr
);
10541 error ("cannot apply %<offsetof%> to static data member %qD", expr
);
10542 return error_mark_node
;
10546 error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded");
10547 return error_mark_node
;
10551 if (!TREE_CONSTANT (TREE_OPERAND (expr
, 0)))
10553 error ("cannot apply %<offsetof%> to a non constant address");
10554 return error_mark_node
;
10556 return TREE_OPERAND (expr
, 0);
10558 case COMPONENT_REF
:
10559 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0), code
);
10560 if (base
== error_mark_node
)
10563 t
= TREE_OPERAND (expr
, 1);
10564 if (DECL_C_BIT_FIELD (t
))
10566 error ("attempt to take address of bit-field structure "
10568 return error_mark_node
;
10570 off
= size_binop_loc (input_location
, PLUS_EXPR
, DECL_FIELD_OFFSET (t
),
10571 size_int (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (t
))
10576 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0), code
);
10577 if (base
== error_mark_node
)
10580 t
= TREE_OPERAND (expr
, 1);
10582 /* Check if the offset goes beyond the upper bound of the array. */
10583 if (TREE_CODE (t
) == INTEGER_CST
&& tree_int_cst_sgn (t
) >= 0)
10585 tree upbound
= array_ref_up_bound (expr
);
10586 if (upbound
!= NULL_TREE
10587 && TREE_CODE (upbound
) == INTEGER_CST
10588 && !tree_int_cst_equal (upbound
,
10589 TYPE_MAX_VALUE (TREE_TYPE (upbound
))))
10591 if (ctx
!= ARRAY_REF
&& ctx
!= COMPONENT_REF
)
10592 upbound
= size_binop (PLUS_EXPR
, upbound
,
10593 build_int_cst (TREE_TYPE (upbound
), 1));
10594 if (tree_int_cst_lt (upbound
, t
))
10598 for (v
= TREE_OPERAND (expr
, 0);
10599 TREE_CODE (v
) == COMPONENT_REF
;
10600 v
= TREE_OPERAND (v
, 0))
10601 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v
, 0)))
10604 tree fld_chain
= DECL_CHAIN (TREE_OPERAND (v
, 1));
10605 for (; fld_chain
; fld_chain
= DECL_CHAIN (fld_chain
))
10606 if (TREE_CODE (fld_chain
) == FIELD_DECL
)
10612 /* Don't warn if the array might be considered a poor
10613 man's flexible array member with a very permissive
10614 definition thereof. */
10615 if (TREE_CODE (v
) == ARRAY_REF
10616 || TREE_CODE (v
) == COMPONENT_REF
)
10617 warning (OPT_Warray_bounds
,
10618 "index %E denotes an offset "
10619 "greater than size of %qT",
10620 t
, TREE_TYPE (TREE_OPERAND (expr
, 0)));
10625 t
= convert (sizetype
, t
);
10626 off
= size_binop (MULT_EXPR
, TYPE_SIZE_UNIT (TREE_TYPE (expr
)), t
);
10629 case COMPOUND_EXPR
:
10630 /* Handle static members of volatile structs. */
10631 t
= TREE_OPERAND (expr
, 1);
10632 gcc_assert (VAR_P (t
));
10633 return fold_offsetof_1 (t
);
10636 gcc_unreachable ();
10639 return fold_build_pointer_plus (base
, off
);
10642 /* Likewise, but convert it to the return type of offsetof. */
10645 fold_offsetof (tree expr
)
10647 return convert (size_type_node
, fold_offsetof_1 (expr
));
10650 /* Warn for A ?: C expressions (with B omitted) where A is a boolean
10651 expression, because B will always be true. */
10654 warn_for_omitted_condop (location_t location
, tree cond
)
10656 /* In C++ template declarations it can happen that the type is dependent
10657 and not yet known, thus TREE_TYPE (cond) == NULL_TREE. */
10658 if (truth_value_p (TREE_CODE (cond
))
10659 || (TREE_TYPE (cond
) != NULL_TREE
10660 && TREE_CODE (TREE_TYPE (cond
)) == BOOLEAN_TYPE
))
10661 warning_at (location
, OPT_Wparentheses
,
10662 "the omitted middle operand in ?: will always be %<true%>, "
10663 "suggest explicit middle operand");
10666 /* Give an error for storing into ARG, which is 'const'. USE indicates
10667 how ARG was being used. */
10670 readonly_error (location_t loc
, tree arg
, enum lvalue_use use
)
10672 gcc_assert (use
== lv_assign
|| use
== lv_increment
|| use
== lv_decrement
10674 /* Using this macro rather than (for example) arrays of messages
10675 ensures that all the format strings are checked at compile
10677 #define READONLY_MSG(A, I, D, AS) (use == lv_assign ? (A) \
10678 : (use == lv_increment ? (I) \
10679 : (use == lv_decrement ? (D) : (AS))))
10680 if (TREE_CODE (arg
) == COMPONENT_REF
)
10682 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg
, 0))))
10683 error_at (loc
, READONLY_MSG (G_("assignment of member "
10684 "%qD in read-only object"),
10685 G_("increment of member "
10686 "%qD in read-only object"),
10687 G_("decrement of member "
10688 "%qD in read-only object"),
10689 G_("member %qD in read-only object "
10690 "used as %<asm%> output")),
10691 TREE_OPERAND (arg
, 1));
10693 error_at (loc
, READONLY_MSG (G_("assignment of read-only member %qD"),
10694 G_("increment of read-only member %qD"),
10695 G_("decrement of read-only member %qD"),
10696 G_("read-only member %qD used as %<asm%> output")),
10697 TREE_OPERAND (arg
, 1));
10699 else if (VAR_P (arg
))
10700 error_at (loc
, READONLY_MSG (G_("assignment of read-only variable %qD"),
10701 G_("increment of read-only variable %qD"),
10702 G_("decrement of read-only variable %qD"),
10703 G_("read-only variable %qD used as %<asm%> output")),
10705 else if (TREE_CODE (arg
) == PARM_DECL
)
10706 error_at (loc
, READONLY_MSG (G_("assignment of read-only parameter %qD"),
10707 G_("increment of read-only parameter %qD"),
10708 G_("decrement of read-only parameter %qD"),
10709 G_("read-only parameter %qD use as %<asm%> output")),
10711 else if (TREE_CODE (arg
) == RESULT_DECL
)
10713 gcc_assert (c_dialect_cxx ());
10714 error_at (loc
, READONLY_MSG (G_("assignment of "
10715 "read-only named return value %qD"),
10717 "read-only named return value %qD"),
10719 "read-only named return value %qD"),
10720 G_("read-only named return value %qD "
10721 "used as %<asm%>output")),
10724 else if (TREE_CODE (arg
) == FUNCTION_DECL
)
10725 error_at (loc
, READONLY_MSG (G_("assignment of function %qD"),
10726 G_("increment of function %qD"),
10727 G_("decrement of function %qD"),
10728 G_("function %qD used as %<asm%> output")),
10731 error_at (loc
, READONLY_MSG (G_("assignment of read-only location %qE"),
10732 G_("increment of read-only location %qE"),
10733 G_("decrement of read-only location %qE"),
10734 G_("read-only location %qE used as %<asm%> output")),
10738 /* Print an error message for an invalid lvalue. USE says
10739 how the lvalue is being used and so selects the error message. LOC
10740 is the location for the error. */
10743 lvalue_error (location_t loc
, enum lvalue_use use
)
10748 error_at (loc
, "lvalue required as left operand of assignment");
10751 error_at (loc
, "lvalue required as increment operand");
10754 error_at (loc
, "lvalue required as decrement operand");
10757 error_at (loc
, "lvalue required as unary %<&%> operand");
10760 error_at (loc
, "lvalue required in asm statement");
10763 gcc_unreachable ();
10767 /* Print an error message for an invalid indirection of type TYPE.
10768 ERRSTRING is the name of the operator for the indirection. */
10771 invalid_indirection_error (location_t loc
, tree type
, ref_operator errstring
)
10776 gcc_assert (c_dialect_cxx ());
10777 error_at (loc
, "invalid type argument (have %qT)", type
);
10779 case RO_ARRAY_INDEXING
:
10781 "invalid type argument of array indexing (have %qT)",
10784 case RO_UNARY_STAR
:
10786 "invalid type argument of unary %<*%> (have %qT)",
10791 "invalid type argument of %<->%> (have %qT)",
10794 case RO_ARROW_STAR
:
10796 "invalid type argument of %<->*%> (have %qT)",
10799 case RO_IMPLICIT_CONVERSION
:
10801 "invalid type argument of implicit conversion (have %qT)",
10805 gcc_unreachable ();
10809 /* *PTYPE is an incomplete array. Complete it with a domain based on
10810 INITIAL_VALUE. If INITIAL_VALUE is not present, use 1 if DO_DEFAULT
10811 is true. Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
10812 2 if INITIAL_VALUE was NULL, and 3 if INITIAL_VALUE was empty. */
10815 complete_array_type (tree
*ptype
, tree initial_value
, bool do_default
)
10817 tree maxindex
, type
, main_type
, elt
, unqual_elt
;
10818 int failure
= 0, quals
;
10819 hashval_t hashcode
= 0;
10820 bool overflow_p
= false;
10822 maxindex
= size_zero_node
;
10825 if (TREE_CODE (initial_value
) == STRING_CST
)
10828 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value
)));
10829 maxindex
= size_int (TREE_STRING_LENGTH (initial_value
)/eltsize
- 1);
10831 else if (TREE_CODE (initial_value
) == CONSTRUCTOR
)
10833 vec
<constructor_elt
, va_gc
> *v
= CONSTRUCTOR_ELTS (initial_value
);
10835 if (vec_safe_is_empty (v
))
10839 maxindex
= ssize_int (-1);
10844 unsigned HOST_WIDE_INT cnt
;
10845 constructor_elt
*ce
;
10846 bool fold_p
= false;
10849 maxindex
= (*v
)[0].index
, fold_p
= true;
10851 curindex
= maxindex
;
10853 for (cnt
= 1; vec_safe_iterate (v
, cnt
, &ce
); cnt
++)
10855 bool curfold_p
= false;
10857 curindex
= ce
->index
, curfold_p
= true;
10862 /* Since we treat size types now as ordinary
10863 unsigned types, we need an explicit overflow
10865 tree orig
= curindex
;
10866 curindex
= fold_convert (sizetype
, curindex
);
10867 overflow_p
|= tree_int_cst_lt (curindex
, orig
);
10869 curindex
= size_binop (PLUS_EXPR
, curindex
,
10872 if (tree_int_cst_lt (maxindex
, curindex
))
10873 maxindex
= curindex
, fold_p
= curfold_p
;
10877 tree orig
= maxindex
;
10878 maxindex
= fold_convert (sizetype
, maxindex
);
10879 overflow_p
|= tree_int_cst_lt (maxindex
, orig
);
10885 /* Make an error message unless that happened already. */
10886 if (initial_value
!= error_mark_node
)
10898 elt
= TREE_TYPE (type
);
10899 quals
= TYPE_QUALS (strip_array_types (elt
));
10903 unqual_elt
= c_build_qualified_type (elt
, KEEP_QUAL_ADDR_SPACE (quals
));
10905 /* Using build_distinct_type_copy and modifying things afterward instead
10906 of using build_array_type to create a new type preserves all of the
10907 TYPE_LANG_FLAG_? bits that the front end may have set. */
10908 main_type
= build_distinct_type_copy (TYPE_MAIN_VARIANT (type
));
10909 TREE_TYPE (main_type
) = unqual_elt
;
10910 TYPE_DOMAIN (main_type
)
10911 = build_range_type (TREE_TYPE (maxindex
),
10912 build_int_cst (TREE_TYPE (maxindex
), 0), maxindex
);
10913 layout_type (main_type
);
10915 /* Make sure we have the canonical MAIN_TYPE. */
10916 hashcode
= iterative_hash_object (TYPE_HASH (unqual_elt
), hashcode
);
10917 hashcode
= iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (main_type
)),
10919 main_type
= type_hash_canon (hashcode
, main_type
);
10921 /* Fix the canonical type. */
10922 if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type
))
10923 || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type
)))
10924 SET_TYPE_STRUCTURAL_EQUALITY (main_type
);
10925 else if (TYPE_CANONICAL (TREE_TYPE (main_type
)) != TREE_TYPE (main_type
)
10926 || (TYPE_CANONICAL (TYPE_DOMAIN (main_type
))
10927 != TYPE_DOMAIN (main_type
)))
10928 TYPE_CANONICAL (main_type
)
10929 = build_array_type (TYPE_CANONICAL (TREE_TYPE (main_type
)),
10930 TYPE_CANONICAL (TYPE_DOMAIN (main_type
)));
10932 TYPE_CANONICAL (main_type
) = main_type
;
10937 type
= c_build_qualified_type (main_type
, quals
);
10939 if (COMPLETE_TYPE_P (type
)
10940 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
10941 && (overflow_p
|| TREE_OVERFLOW (TYPE_SIZE_UNIT (type
))))
10943 error ("size of array is too large");
10944 /* If we proceed with the array type as it is, we'll eventually
10945 crash in tree_to_[su]hwi(). */
10946 type
= error_mark_node
;
10953 /* Like c_mark_addressable but don't check register qualifier. */
10955 c_common_mark_addressable_vec (tree t
)
10957 while (handled_component_p (t
))
10958 t
= TREE_OPERAND (t
, 0);
10960 && TREE_CODE (t
) != PARM_DECL
10961 && TREE_CODE (t
) != COMPOUND_LITERAL_EXPR
)
10963 TREE_ADDRESSABLE (t
) = 1;
10968 /* Used to help initialize the builtin-types.def table. When a type of
10969 the correct size doesn't exist, use error_mark_node instead of NULL.
10970 The later results in segfaults even when a decl using the type doesn't
10974 builtin_type_for_size (int size
, bool unsignedp
)
10976 tree type
= c_common_type_for_size (size
, unsignedp
);
10977 return type
? type
: error_mark_node
;
10980 /* A helper function for resolve_overloaded_builtin in resolving the
10981 overloaded __sync_ builtins. Returns a positive power of 2 if the
10982 first operand of PARAMS is a pointer to a supported data type.
10983 Returns 0 if an error is encountered.
10984 FETCH is true when FUNCTION is one of the _FETCH_OP_ or _OP_FETCH_
10988 sync_resolve_size (tree function
, vec
<tree
, va_gc
> *params
, bool fetch
)
10990 /* Type of the argument. */
10992 /* Type the argument points to. */
10996 if (vec_safe_is_empty (params
))
10998 error ("too few arguments to function %qE", function
);
11002 argtype
= type
= TREE_TYPE ((*params
)[0]);
11003 if (TREE_CODE (type
) == ARRAY_TYPE
)
11005 /* Force array-to-pointer decay for C++. */
11006 gcc_assert (c_dialect_cxx());
11007 (*params
)[0] = default_conversion ((*params
)[0]);
11008 type
= TREE_TYPE ((*params
)[0]);
11010 if (TREE_CODE (type
) != POINTER_TYPE
)
11013 type
= TREE_TYPE (type
);
11014 if (!INTEGRAL_TYPE_P (type
) && !POINTER_TYPE_P (type
))
11017 if (fetch
&& TREE_CODE (type
) == BOOLEAN_TYPE
)
11020 size
= tree_to_uhwi (TYPE_SIZE_UNIT (type
));
11021 if (size
== 1 || size
== 2 || size
== 4 || size
== 8 || size
== 16)
11025 /* Issue the diagnostic only if the argument is valid, otherwise
11026 it would be redundant at best and could be misleading. */
11027 if (argtype
!= error_mark_node
)
11028 error ("operand type %qT is incompatible with argument %d of %qE",
11029 argtype
, 1, function
);
11033 /* A helper function for resolve_overloaded_builtin. Adds casts to
11034 PARAMS to make arguments match up with those of FUNCTION. Drops
11035 the variadic arguments at the end. Returns false if some error
11036 was encountered; true on success. */
11039 sync_resolve_params (location_t loc
, tree orig_function
, tree function
,
11040 vec
<tree
, va_gc
> *params
, bool orig_format
)
11042 function_args_iterator iter
;
11044 unsigned int parmnum
;
11046 function_args_iter_init (&iter
, TREE_TYPE (function
));
11047 /* We've declared the implementation functions to use "volatile void *"
11048 as the pointer parameter, so we shouldn't get any complaints from the
11049 call to check_function_arguments what ever type the user used. */
11050 function_args_iter_next (&iter
);
11051 ptype
= TREE_TYPE (TREE_TYPE ((*params
)[0]));
11052 ptype
= TYPE_MAIN_VARIANT (ptype
);
11054 /* For the rest of the values, we need to cast these to FTYPE, so that we
11055 don't get warnings for passing pointer types, etc. */
11059 tree val
, arg_type
;
11061 arg_type
= function_args_iter_cond (&iter
);
11062 /* XXX void_type_node belies the abstraction. */
11063 if (arg_type
== void_type_node
)
11067 if (params
->length () <= parmnum
)
11069 error_at (loc
, "too few arguments to function %qE", orig_function
);
11073 /* Only convert parameters if arg_type is unsigned integer type with
11074 new format sync routines, i.e. don't attempt to convert pointer
11075 arguments (e.g. EXPECTED argument of __atomic_compare_exchange_n),
11076 bool arguments (e.g. WEAK argument) or signed int arguments (memmodel
11078 if (TREE_CODE (arg_type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (arg_type
))
11080 /* Ideally for the first conversion we'd use convert_for_assignment
11081 so that we get warnings for anything that doesn't match the pointer
11082 type. This isn't portable across the C and C++ front ends atm. */
11083 val
= (*params
)[parmnum
];
11084 val
= convert (ptype
, val
);
11085 val
= convert (arg_type
, val
);
11086 (*params
)[parmnum
] = val
;
11089 function_args_iter_next (&iter
);
11092 /* __atomic routines are not variadic. */
11093 if (!orig_format
&& params
->length () != parmnum
+ 1)
11095 error_at (loc
, "too many arguments to function %qE", orig_function
);
11099 /* The definition of these primitives is variadic, with the remaining
11100 being "an optional list of variables protected by the memory barrier".
11101 No clue what that's supposed to mean, precisely, but we consider all
11102 call-clobbered variables to be protected so we're safe. */
11103 params
->truncate (parmnum
+ 1);
11108 /* A helper function for resolve_overloaded_builtin. Adds a cast to
11109 RESULT to make it match the type of the first pointer argument in
11113 sync_resolve_return (tree first_param
, tree result
, bool orig_format
)
11115 tree ptype
= TREE_TYPE (TREE_TYPE (first_param
));
11116 tree rtype
= TREE_TYPE (result
);
11117 ptype
= TYPE_MAIN_VARIANT (ptype
);
11119 /* New format doesn't require casting unless the types are the same size. */
11120 if (orig_format
|| tree_int_cst_equal (TYPE_SIZE (ptype
), TYPE_SIZE (rtype
)))
11121 return convert (ptype
, result
);
11126 /* This function verifies the PARAMS to generic atomic FUNCTION.
11127 It returns the size if all the parameters are the same size, otherwise
11128 0 is returned if the parameters are invalid. */
11131 get_atomic_generic_size (location_t loc
, tree function
,
11132 vec
<tree
, va_gc
> *params
)
11134 unsigned int n_param
;
11135 unsigned int n_model
;
11140 /* Determine the parameter makeup. */
11141 switch (DECL_FUNCTION_CODE (function
))
11143 case BUILT_IN_ATOMIC_EXCHANGE
:
11147 case BUILT_IN_ATOMIC_LOAD
:
11148 case BUILT_IN_ATOMIC_STORE
:
11152 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
11157 gcc_unreachable ();
11160 if (vec_safe_length (params
) != n_param
)
11162 error_at (loc
, "incorrect number of arguments to function %qE", function
);
11166 /* Get type of first parameter, and determine its size. */
11167 type_0
= TREE_TYPE ((*params
)[0]);
11168 if (TREE_CODE (type_0
) == ARRAY_TYPE
)
11170 /* Force array-to-pointer decay for C++. */
11171 gcc_assert (c_dialect_cxx());
11172 (*params
)[0] = default_conversion ((*params
)[0]);
11173 type_0
= TREE_TYPE ((*params
)[0]);
11175 if (TREE_CODE (type_0
) != POINTER_TYPE
|| VOID_TYPE_P (TREE_TYPE (type_0
)))
11177 error_at (loc
, "argument 1 of %qE must be a non-void pointer type",
11182 /* Types must be compile time constant sizes. */
11183 if (TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type_0
)))) != INTEGER_CST
)
11186 "argument 1 of %qE must be a pointer to a constant size type",
11191 size_0
= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type_0
)));
11193 /* Zero size objects are not allowed. */
11197 "argument 1 of %qE must be a pointer to a nonzero size object",
11202 /* Check each other parameter is a pointer and the same size. */
11203 for (x
= 0; x
< n_param
- n_model
; x
++)
11206 tree type
= TREE_TYPE ((*params
)[x
]);
11207 /* __atomic_compare_exchange has a bool in the 4th position, skip it. */
11208 if (n_param
== 6 && x
== 3)
11210 if (!POINTER_TYPE_P (type
))
11212 error_at (loc
, "argument %d of %qE must be a pointer type", x
+ 1,
11216 else if (TYPE_SIZE_UNIT (TREE_TYPE (type
))
11217 && TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type
))))
11220 error_at (loc
, "argument %d of %qE must be a pointer to a constant "
11221 "size type", x
+ 1, function
);
11224 else if (FUNCTION_POINTER_TYPE_P (type
))
11226 error_at (loc
, "argument %d of %qE must not be a pointer to a "
11227 "function", x
+ 1, function
);
11230 tree type_size
= TYPE_SIZE_UNIT (TREE_TYPE (type
));
11231 size
= type_size
? tree_to_uhwi (type_size
) : 0;
11232 if (size
!= size_0
)
11234 error_at (loc
, "size mismatch in argument %d of %qE", x
+ 1,
11240 /* Check memory model parameters for validity. */
11241 for (x
= n_param
- n_model
; x
< n_param
; x
++)
11243 tree p
= (*params
)[x
];
11244 if (TREE_CODE (p
) == INTEGER_CST
)
11246 int i
= tree_to_uhwi (p
);
11247 if (i
< 0 || (memmodel_base (i
) >= MEMMODEL_LAST
))
11249 warning_at (loc
, OPT_Winvalid_memory_model
,
11250 "invalid memory model argument %d of %qE", x
+ 1,
11255 if (!INTEGRAL_TYPE_P (TREE_TYPE (p
)))
11257 error_at (loc
, "non-integer memory model argument %d of %qE", x
+ 1,
11267 /* This will take an __atomic_ generic FUNCTION call, and add a size parameter N
11268 at the beginning of the parameter list PARAMS representing the size of the
11269 objects. This is to match the library ABI requirement. LOC is the location
11270 of the function call.
11271 The new function is returned if it needed rebuilding, otherwise NULL_TREE is
11272 returned to allow the external call to be constructed. */
11275 add_atomic_size_parameter (unsigned n
, location_t loc
, tree function
,
11276 vec
<tree
, va_gc
> *params
)
11280 /* Insert a SIZE_T parameter as the first param. If there isn't
11281 enough space, allocate a new vector and recursively re-build with that. */
11282 if (!params
->space (1))
11284 unsigned int z
, len
;
11285 vec
<tree
, va_gc
> *v
;
11288 len
= params
->length ();
11289 vec_alloc (v
, len
+ 1);
11290 v
->quick_push (build_int_cst (size_type_node
, n
));
11291 for (z
= 0; z
< len
; z
++)
11292 v
->quick_push ((*params
)[z
]);
11293 f
= build_function_call_vec (loc
, vNULL
, function
, v
, NULL
);
11298 /* Add the size parameter and leave as a function call for processing. */
11299 size_node
= build_int_cst (size_type_node
, n
);
11300 params
->quick_insert (0, size_node
);
11305 /* Return whether atomic operations for naturally aligned N-byte
11306 arguments are supported, whether inline or through libatomic. */
11308 atomic_size_supported_p (int n
)
11319 return targetm
.scalar_mode_supported_p (TImode
);
11326 /* This will process an __atomic_exchange function call, determine whether it
11327 needs to be mapped to the _N variation, or turned into a library call.
11328 LOC is the location of the builtin call.
11329 FUNCTION is the DECL that has been invoked;
11330 PARAMS is the argument list for the call. The return value is non-null
11331 TRUE is returned if it is translated into the proper format for a call to the
11332 external library, and NEW_RETURN is set the tree for that function.
11333 FALSE is returned if processing for the _N variation is required, and
11334 NEW_RETURN is set to the return value the result is copied into. */
11336 resolve_overloaded_atomic_exchange (location_t loc
, tree function
,
11337 vec
<tree
, va_gc
> *params
, tree
*new_return
)
11339 tree p0
, p1
, p2
, p3
;
11340 tree I_type
, I_type_ptr
;
11341 int n
= get_atomic_generic_size (loc
, function
, params
);
11343 /* Size of 0 is an error condition. */
11346 *new_return
= error_mark_node
;
11350 /* If not a lock-free size, change to the library generic format. */
11351 if (!atomic_size_supported_p (n
))
11353 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
11357 /* Otherwise there is a lockfree match, transform the call from:
11358 void fn(T* mem, T* desired, T* return, model)
11360 *return = (T) (fn (In* mem, (In) *desired, model)) */
11367 /* Create pointer to appropriate size. */
11368 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
11369 I_type_ptr
= build_pointer_type (I_type
);
11371 /* Convert object pointer to required type. */
11372 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
11374 /* Convert new value to required type, and dereference it. */
11375 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
11376 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
11379 /* Move memory model to the 3rd position, and end param list. */
11381 params
->truncate (3);
11383 /* Convert return pointer and dereference it for later assignment. */
11384 *new_return
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
11390 /* This will process an __atomic_compare_exchange function call, determine
11391 whether it needs to be mapped to the _N variation, or turned into a lib call.
11392 LOC is the location of the builtin call.
11393 FUNCTION is the DECL that has been invoked;
11394 PARAMS is the argument list for the call. The return value is non-null
11395 TRUE is returned if it is translated into the proper format for a call to the
11396 external library, and NEW_RETURN is set the tree for that function.
11397 FALSE is returned if processing for the _N variation is required. */
11400 resolve_overloaded_atomic_compare_exchange (location_t loc
, tree function
,
11401 vec
<tree
, va_gc
> *params
,
11405 tree I_type
, I_type_ptr
;
11406 int n
= get_atomic_generic_size (loc
, function
, params
);
11408 /* Size of 0 is an error condition. */
11411 *new_return
= error_mark_node
;
11415 /* If not a lock-free size, change to the library generic format. */
11416 if (!atomic_size_supported_p (n
))
11418 /* The library generic format does not have the weak parameter, so
11419 remove it from the param list. Since a parameter has been removed,
11420 we can be sure that there is room for the SIZE_T parameter, meaning
11421 there will not be a recursive rebuilding of the parameter list, so
11422 there is no danger this will be done twice. */
11425 (*params
)[3] = (*params
)[4];
11426 (*params
)[4] = (*params
)[5];
11427 params
->truncate (5);
11429 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
11433 /* Otherwise, there is a match, so the call needs to be transformed from:
11434 bool fn(T* mem, T* desired, T* return, weak, success, failure)
11436 bool fn ((In *)mem, (In *)expected, (In) *desired, weak, succ, fail) */
11442 /* Create pointer to appropriate size. */
11443 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
11444 I_type_ptr
= build_pointer_type (I_type
);
11446 /* Convert object pointer to required type. */
11447 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
11450 /* Convert expected pointer to required type. */
11451 p1
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p1
);
11454 /* Convert desired value to required type, and dereference it. */
11455 p2
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
11456 p2
= build1 (VIEW_CONVERT_EXPR
, I_type
, p2
);
11459 /* The rest of the parameters are fine. NULL means no special return value
11461 *new_return
= NULL
;
11466 /* This will process an __atomic_load function call, determine whether it
11467 needs to be mapped to the _N variation, or turned into a library call.
11468 LOC is the location of the builtin call.
11469 FUNCTION is the DECL that has been invoked;
11470 PARAMS is the argument list for the call. The return value is non-null
11471 TRUE is returned if it is translated into the proper format for a call to the
11472 external library, and NEW_RETURN is set the tree for that function.
11473 FALSE is returned if processing for the _N variation is required, and
11474 NEW_RETURN is set to the return value the result is copied into. */
11477 resolve_overloaded_atomic_load (location_t loc
, tree function
,
11478 vec
<tree
, va_gc
> *params
, tree
*new_return
)
11481 tree I_type
, I_type_ptr
;
11482 int n
= get_atomic_generic_size (loc
, function
, params
);
11484 /* Size of 0 is an error condition. */
11487 *new_return
= error_mark_node
;
11491 /* If not a lock-free size, change to the library generic format. */
11492 if (!atomic_size_supported_p (n
))
11494 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
11498 /* Otherwise, there is a match, so the call needs to be transformed from:
11499 void fn(T* mem, T* return, model)
11501 *return = (T) (fn ((In *) mem, model)) */
11507 /* Create pointer to appropriate size. */
11508 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
11509 I_type_ptr
= build_pointer_type (I_type
);
11511 /* Convert object pointer to required type. */
11512 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
11515 /* Move memory model to the 2nd position, and end param list. */
11517 params
->truncate (2);
11519 /* Convert return pointer and dereference it for later assignment. */
11520 *new_return
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
11526 /* This will process an __atomic_store function call, determine whether it
11527 needs to be mapped to the _N variation, or turned into a library call.
11528 LOC is the location of the builtin call.
11529 FUNCTION is the DECL that has been invoked;
11530 PARAMS is the argument list for the call. The return value is non-null
11531 TRUE is returned if it is translated into the proper format for a call to the
11532 external library, and NEW_RETURN is set the tree for that function.
11533 FALSE is returned if processing for the _N variation is required, and
11534 NEW_RETURN is set to the return value the result is copied into. */
11537 resolve_overloaded_atomic_store (location_t loc
, tree function
,
11538 vec
<tree
, va_gc
> *params
, tree
*new_return
)
11541 tree I_type
, I_type_ptr
;
11542 int n
= get_atomic_generic_size (loc
, function
, params
);
11544 /* Size of 0 is an error condition. */
11547 *new_return
= error_mark_node
;
11551 /* If not a lock-free size, change to the library generic format. */
11552 if (!atomic_size_supported_p (n
))
11554 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
11558 /* Otherwise, there is a match, so the call needs to be transformed from:
11559 void fn(T* mem, T* value, model)
11561 fn ((In *) mem, (In) *value, model) */
11566 /* Create pointer to appropriate size. */
11567 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
11568 I_type_ptr
= build_pointer_type (I_type
);
11570 /* Convert object pointer to required type. */
11571 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
11574 /* Convert new value to required type, and dereference it. */
11575 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
11576 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
11579 /* The memory model is in the right spot already. Return is void. */
11580 *new_return
= NULL_TREE
;
11586 /* Some builtin functions are placeholders for other expressions. This
11587 function should be called immediately after parsing the call expression
11588 before surrounding code has committed to the type of the expression.
11590 LOC is the location of the builtin call.
11592 FUNCTION is the DECL that has been invoked; it is known to be a builtin.
11593 PARAMS is the argument list for the call. The return value is non-null
11594 when expansion is complete, and null if normal processing should
11598 resolve_overloaded_builtin (location_t loc
, tree function
,
11599 vec
<tree
, va_gc
> *params
)
11601 enum built_in_function orig_code
= DECL_FUNCTION_CODE (function
);
11603 /* Is function one of the _FETCH_OP_ or _OP_FETCH_ built-ins?
11604 Those are not valid to call with a pointer to _Bool (or C++ bool)
11605 and so must be rejected. */
11606 bool fetch_op
= true;
11607 bool orig_format
= true;
11608 tree new_return
= NULL_TREE
;
11610 switch (DECL_BUILT_IN_CLASS (function
))
11612 case BUILT_IN_NORMAL
:
11615 if (targetm
.resolve_overloaded_builtin
)
11616 return targetm
.resolve_overloaded_builtin (loc
, function
, params
);
11623 /* Handle BUILT_IN_NORMAL here. */
11626 case BUILT_IN_ATOMIC_EXCHANGE
:
11627 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
11628 case BUILT_IN_ATOMIC_LOAD
:
11629 case BUILT_IN_ATOMIC_STORE
:
11631 /* Handle these 4 together so that they can fall through to the next
11632 case if the call is transformed to an _N variant. */
11635 case BUILT_IN_ATOMIC_EXCHANGE
:
11637 if (resolve_overloaded_atomic_exchange (loc
, function
, params
,
11640 /* Change to the _N variant. */
11641 orig_code
= BUILT_IN_ATOMIC_EXCHANGE_N
;
11645 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
11647 if (resolve_overloaded_atomic_compare_exchange (loc
, function
,
11651 /* Change to the _N variant. */
11652 orig_code
= BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
;
11655 case BUILT_IN_ATOMIC_LOAD
:
11657 if (resolve_overloaded_atomic_load (loc
, function
, params
,
11660 /* Change to the _N variant. */
11661 orig_code
= BUILT_IN_ATOMIC_LOAD_N
;
11664 case BUILT_IN_ATOMIC_STORE
:
11666 if (resolve_overloaded_atomic_store (loc
, function
, params
,
11669 /* Change to the _N variant. */
11670 orig_code
= BUILT_IN_ATOMIC_STORE_N
;
11674 gcc_unreachable ();
11678 case BUILT_IN_ATOMIC_EXCHANGE_N
:
11679 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
:
11680 case BUILT_IN_ATOMIC_LOAD_N
:
11681 case BUILT_IN_ATOMIC_STORE_N
:
11684 case BUILT_IN_ATOMIC_ADD_FETCH_N
:
11685 case BUILT_IN_ATOMIC_SUB_FETCH_N
:
11686 case BUILT_IN_ATOMIC_AND_FETCH_N
:
11687 case BUILT_IN_ATOMIC_NAND_FETCH_N
:
11688 case BUILT_IN_ATOMIC_XOR_FETCH_N
:
11689 case BUILT_IN_ATOMIC_OR_FETCH_N
:
11690 case BUILT_IN_ATOMIC_FETCH_ADD_N
:
11691 case BUILT_IN_ATOMIC_FETCH_SUB_N
:
11692 case BUILT_IN_ATOMIC_FETCH_AND_N
:
11693 case BUILT_IN_ATOMIC_FETCH_NAND_N
:
11694 case BUILT_IN_ATOMIC_FETCH_XOR_N
:
11695 case BUILT_IN_ATOMIC_FETCH_OR_N
:
11696 orig_format
= false;
11698 case BUILT_IN_SYNC_FETCH_AND_ADD_N
:
11699 case BUILT_IN_SYNC_FETCH_AND_SUB_N
:
11700 case BUILT_IN_SYNC_FETCH_AND_OR_N
:
11701 case BUILT_IN_SYNC_FETCH_AND_AND_N
:
11702 case BUILT_IN_SYNC_FETCH_AND_XOR_N
:
11703 case BUILT_IN_SYNC_FETCH_AND_NAND_N
:
11704 case BUILT_IN_SYNC_ADD_AND_FETCH_N
:
11705 case BUILT_IN_SYNC_SUB_AND_FETCH_N
:
11706 case BUILT_IN_SYNC_OR_AND_FETCH_N
:
11707 case BUILT_IN_SYNC_AND_AND_FETCH_N
:
11708 case BUILT_IN_SYNC_XOR_AND_FETCH_N
:
11709 case BUILT_IN_SYNC_NAND_AND_FETCH_N
:
11710 case BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
:
11711 case BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N
:
11712 case BUILT_IN_SYNC_LOCK_TEST_AND_SET_N
:
11713 case BUILT_IN_SYNC_LOCK_RELEASE_N
:
11715 /* The following are not _FETCH_OPs and must be accepted with
11716 pointers to _Bool (or C++ bool). */
11719 (orig_code
!= BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
11720 && orig_code
!= BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N
11721 && orig_code
!= BUILT_IN_SYNC_LOCK_TEST_AND_SET_N
11722 && orig_code
!= BUILT_IN_SYNC_LOCK_RELEASE_N
);
11724 int n
= sync_resolve_size (function
, params
, fetch_op
);
11725 tree new_function
, first_param
, result
;
11726 enum built_in_function fncode
;
11729 return error_mark_node
;
11731 fncode
= (enum built_in_function
)((int)orig_code
+ exact_log2 (n
) + 1);
11732 new_function
= builtin_decl_explicit (fncode
);
11733 if (!sync_resolve_params (loc
, function
, new_function
, params
,
11735 return error_mark_node
;
11737 first_param
= (*params
)[0];
11738 result
= build_function_call_vec (loc
, vNULL
, new_function
, params
,
11740 if (result
== error_mark_node
)
11742 if (orig_code
!= BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
11743 && orig_code
!= BUILT_IN_SYNC_LOCK_RELEASE_N
11744 && orig_code
!= BUILT_IN_ATOMIC_STORE_N
11745 && orig_code
!= BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
)
11746 result
= sync_resolve_return (first_param
, result
, orig_format
);
11749 /* Prevent -Wunused-value warning. */
11750 TREE_USED (result
) = true;
11752 /* If new_return is set, assign function to that expr and cast the
11753 result to void since the generic interface returned void. */
11756 /* Cast function result from I{1,2,4,8,16} to the required type. */
11757 result
= build1 (VIEW_CONVERT_EXPR
, TREE_TYPE (new_return
), result
);
11758 result
= build2 (MODIFY_EXPR
, TREE_TYPE (new_return
), new_return
,
11760 TREE_SIDE_EFFECTS (result
) = 1;
11761 protected_set_expr_location (result
, loc
);
11762 result
= convert (void_type_node
, result
);
11772 /* vector_types_compatible_elements_p is used in type checks of vectors
11773 values used as operands of binary operators. Where it returns true, and
11774 the other checks of the caller succeed (being vector types in he first
11775 place, and matching number of elements), we can just treat the types
11776 as essentially the same.
11777 Contrast with vector_targets_convertible_p, which is used for vector
11778 pointer types, and vector_types_convertible_p, which will allow
11779 language-specific matches under the control of flag_lax_vector_conversions,
11780 and might still require a conversion. */
11781 /* True if vector types T1 and T2 can be inputs to the same binary
11782 operator without conversion.
11783 We don't check the overall vector size here because some of our callers
11784 want to give different error messages when the vectors are compatible
11785 except for the element count. */
11788 vector_types_compatible_elements_p (tree t1
, tree t2
)
11790 bool opaque
= TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
);
11791 t1
= TREE_TYPE (t1
);
11792 t2
= TREE_TYPE (t2
);
11794 enum tree_code c1
= TREE_CODE (t1
), c2
= TREE_CODE (t2
);
11796 gcc_assert ((c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
|| c1
== FIXED_POINT_TYPE
)
11797 && (c2
== INTEGER_TYPE
|| c2
== REAL_TYPE
11798 || c2
== FIXED_POINT_TYPE
));
11800 t1
= c_common_signed_type (t1
);
11801 t2
= c_common_signed_type (t2
);
11802 /* Equality works here because c_common_signed_type uses
11803 TYPE_MAIN_VARIANT. */
11806 if (opaque
&& c1
== c2
11807 && (c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
)
11808 && TYPE_PRECISION (t1
) == TYPE_PRECISION (t2
))
11813 /* Check for missing format attributes on function pointers. LTYPE is
11814 the new type or left-hand side type. RTYPE is the old type or
11815 right-hand side type. Returns TRUE if LTYPE is missing the desired
11819 check_missing_format_attribute (tree ltype
, tree rtype
)
11821 tree
const ttr
= TREE_TYPE (rtype
), ttl
= TREE_TYPE (ltype
);
11824 for (ra
= TYPE_ATTRIBUTES (ttr
); ra
; ra
= TREE_CHAIN (ra
))
11825 if (is_attribute_p ("format", TREE_PURPOSE (ra
)))
11830 for (la
= TYPE_ATTRIBUTES (ttl
); la
; la
= TREE_CHAIN (la
))
11831 if (is_attribute_p ("format", TREE_PURPOSE (la
)))
11839 /* Subscripting with type char is likely to lose on a machine where
11840 chars are signed. So warn on any machine, but optionally. Don't
11841 warn for unsigned char since that type is safe. Don't warn for
11842 signed char because anyone who uses that must have done so
11843 deliberately. Furthermore, we reduce the false positive load by
11844 warning only for non-constant value of type char. */
11847 warn_array_subscript_with_type_char (location_t loc
, tree index
)
11849 if (TYPE_MAIN_VARIANT (TREE_TYPE (index
)) == char_type_node
11850 && TREE_CODE (index
) != INTEGER_CST
)
11851 warning_at (loc
, OPT_Wchar_subscripts
,
11852 "array subscript has type %<char%>");
11855 /* Implement -Wparentheses for the unexpected C precedence rules, to
11856 cover cases like x + y << z which readers are likely to
11857 misinterpret. We have seen an expression in which CODE is a binary
11858 operator used to combine expressions ARG_LEFT and ARG_RIGHT, which
11859 before folding had CODE_LEFT and CODE_RIGHT. CODE_LEFT and
11860 CODE_RIGHT may be ERROR_MARK, which means that that side of the
11861 expression was not formed using a binary or unary operator, or it
11862 was enclosed in parentheses. */
11865 warn_about_parentheses (location_t loc
, enum tree_code code
,
11866 enum tree_code code_left
, tree arg_left
,
11867 enum tree_code code_right
, tree arg_right
)
11869 if (!warn_parentheses
)
11872 /* This macro tests that the expression ARG with original tree code
11873 CODE appears to be a boolean expression. or the result of folding a
11874 boolean expression. */
11875 #define APPEARS_TO_BE_BOOLEAN_EXPR_P(CODE, ARG) \
11876 (truth_value_p (TREE_CODE (ARG)) \
11877 || TREE_CODE (TREE_TYPE (ARG)) == BOOLEAN_TYPE \
11878 /* Folding may create 0 or 1 integers from other expressions. */ \
11879 || ((CODE) != INTEGER_CST \
11880 && (integer_onep (ARG) || integer_zerop (ARG))))
11885 if (code_left
== PLUS_EXPR
)
11886 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11887 "suggest parentheses around %<+%> inside %<<<%>");
11888 else if (code_right
== PLUS_EXPR
)
11889 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11890 "suggest parentheses around %<+%> inside %<<<%>");
11891 else if (code_left
== MINUS_EXPR
)
11892 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11893 "suggest parentheses around %<-%> inside %<<<%>");
11894 else if (code_right
== MINUS_EXPR
)
11895 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11896 "suggest parentheses around %<-%> inside %<<<%>");
11900 if (code_left
== PLUS_EXPR
)
11901 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11902 "suggest parentheses around %<+%> inside %<>>%>");
11903 else if (code_right
== PLUS_EXPR
)
11904 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11905 "suggest parentheses around %<+%> inside %<>>%>");
11906 else if (code_left
== MINUS_EXPR
)
11907 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11908 "suggest parentheses around %<-%> inside %<>>%>");
11909 else if (code_right
== MINUS_EXPR
)
11910 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11911 "suggest parentheses around %<-%> inside %<>>%>");
11914 case TRUTH_ORIF_EXPR
:
11915 if (code_left
== TRUTH_ANDIF_EXPR
)
11916 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11917 "suggest parentheses around %<&&%> within %<||%>");
11918 else if (code_right
== TRUTH_ANDIF_EXPR
)
11919 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11920 "suggest parentheses around %<&&%> within %<||%>");
11924 if (code_left
== BIT_AND_EXPR
|| code_left
== BIT_XOR_EXPR
11925 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
)
11926 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11927 "suggest parentheses around arithmetic in operand of %<|%>");
11928 else if (code_right
== BIT_AND_EXPR
|| code_right
== BIT_XOR_EXPR
11929 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
11930 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11931 "suggest parentheses around arithmetic in operand of %<|%>");
11932 /* Check cases like x|y==z */
11933 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11934 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11935 "suggest parentheses around comparison in operand of %<|%>");
11936 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11937 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11938 "suggest parentheses around comparison in operand of %<|%>");
11939 /* Check cases like !x | y */
11940 else if (code_left
== TRUTH_NOT_EXPR
11941 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
11942 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11943 "suggest parentheses around operand of "
11944 "%<!%> or change %<|%> to %<||%> or %<!%> to %<~%>");
11948 if (code_left
== BIT_AND_EXPR
11949 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
)
11950 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11951 "suggest parentheses around arithmetic in operand of %<^%>");
11952 else if (code_right
== BIT_AND_EXPR
11953 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
11954 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11955 "suggest parentheses around arithmetic in operand of %<^%>");
11956 /* Check cases like x^y==z */
11957 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11958 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11959 "suggest parentheses around comparison in operand of %<^%>");
11960 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11961 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11962 "suggest parentheses around comparison in operand of %<^%>");
11966 if (code_left
== PLUS_EXPR
)
11967 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11968 "suggest parentheses around %<+%> in operand of %<&%>");
11969 else if (code_right
== PLUS_EXPR
)
11970 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11971 "suggest parentheses around %<+%> in operand of %<&%>");
11972 else if (code_left
== MINUS_EXPR
)
11973 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11974 "suggest parentheses around %<-%> in operand of %<&%>");
11975 else if (code_right
== MINUS_EXPR
)
11976 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11977 "suggest parentheses around %<-%> in operand of %<&%>");
11978 /* Check cases like x&y==z */
11979 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11980 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11981 "suggest parentheses around comparison in operand of %<&%>");
11982 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11983 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11984 "suggest parentheses around comparison in operand of %<&%>");
11985 /* Check cases like !x & y */
11986 else if (code_left
== TRUTH_NOT_EXPR
11987 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
11988 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11989 "suggest parentheses around operand of "
11990 "%<!%> or change %<&%> to %<&&%> or %<!%> to %<~%>");
11994 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11995 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11996 "suggest parentheses around comparison in operand of %<==%>");
11997 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11998 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11999 "suggest parentheses around comparison in operand of %<==%>");
12002 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
12003 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
12004 "suggest parentheses around comparison in operand of %<!=%>");
12005 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
12006 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
12007 "suggest parentheses around comparison in operand of %<!=%>");
12011 if (TREE_CODE_CLASS (code
) == tcc_comparison
)
12013 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
12014 && code_left
!= NE_EXPR
&& code_left
!= EQ_EXPR
12015 && INTEGRAL_TYPE_P (TREE_TYPE (arg_left
)))
12016 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
12017 "comparisons like %<X<=Y<=Z%> do not "
12018 "have their mathematical meaning");
12019 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
12020 && code_right
!= NE_EXPR
&& code_right
!= EQ_EXPR
12021 && INTEGRAL_TYPE_P (TREE_TYPE (arg_right
)))
12022 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
12023 "comparisons like %<X<=Y<=Z%> do not "
12024 "have their mathematical meaning");
12028 #undef NOT_A_BOOLEAN_EXPR_P
12031 /* If LABEL (a LABEL_DECL) has not been used, issue a warning. */
12034 warn_for_unused_label (tree label
)
12036 if (!TREE_USED (label
))
12038 if (DECL_INITIAL (label
))
12039 warning (OPT_Wunused_label
, "label %q+D defined but not used", label
);
12041 warning (OPT_Wunused_label
, "label %q+D declared but not defined", label
);
12045 /* Warn for division by zero according to the value of DIVISOR. LOC
12046 is the location of the division operator. */
12049 warn_for_div_by_zero (location_t loc
, tree divisor
)
12051 /* If DIVISOR is zero, and has integral or fixed-point type, issue a warning
12052 about division by zero. Do not issue a warning if DIVISOR has a
12053 floating-point type, since we consider 0.0/0.0 a valid way of
12054 generating a NaN. */
12055 if (c_inhibit_evaluation_warnings
== 0
12056 && (integer_zerop (divisor
) || fixed_zerop (divisor
)))
12057 warning_at (loc
, OPT_Wdiv_by_zero
, "division by zero");
12060 /* Warn for patterns where memset appears to be used incorrectly. The
12061 warning location should be LOC. ARG0, and ARG2 are the first and
12062 last arguments to the call, while LITERAL_ZERO_MASK has a 1 bit for
12063 each argument that was a literal zero. */
12066 warn_for_memset (location_t loc
, tree arg0
, tree arg2
,
12067 int literal_zero_mask
)
12069 if (warn_memset_transposed_args
12070 && integer_zerop (arg2
)
12071 && (literal_zero_mask
& (1 << 2)) != 0
12072 && (literal_zero_mask
& (1 << 1)) == 0)
12073 warning_at (loc
, OPT_Wmemset_transposed_args
,
12074 "%<memset%> used with constant zero length "
12075 "parameter; this could be due to transposed "
12078 if (warn_memset_elt_size
&& TREE_CODE (arg2
) == INTEGER_CST
)
12081 if (TREE_CODE (arg0
) == ADDR_EXPR
)
12082 arg0
= TREE_OPERAND (arg0
, 0);
12083 tree type
= TREE_TYPE (arg0
);
12084 if (type
!= NULL_TREE
&& TREE_CODE (type
) == ARRAY_TYPE
)
12086 tree elt_type
= TREE_TYPE (type
);
12087 tree domain
= TYPE_DOMAIN (type
);
12088 if (!integer_onep (TYPE_SIZE_UNIT (elt_type
))
12089 && domain
!= NULL_TREE
12090 && TYPE_MAXVAL (domain
)
12091 && TYPE_MINVAL (domain
)
12092 && integer_zerop (TYPE_MINVAL (domain
))
12093 && integer_onep (fold_build2 (MINUS_EXPR
, domain
,
12095 TYPE_MAXVAL (domain
))))
12096 warning_at (loc
, OPT_Wmemset_elt_size
,
12097 "%<memset%> used with length equal to "
12098 "number of elements without multiplication "
12099 "by element size");
12104 /* Subroutine of build_binary_op. Give warnings for comparisons
12105 between signed and unsigned quantities that may fail. Do the
12106 checking based on the original operand trees ORIG_OP0 and ORIG_OP1,
12107 so that casts will be considered, but default promotions won't
12110 LOCATION is the location of the comparison operator.
12112 The arguments of this function map directly to local variables
12113 of build_binary_op. */
12116 warn_for_sign_compare (location_t location
,
12117 tree orig_op0
, tree orig_op1
,
12118 tree op0
, tree op1
,
12119 tree result_type
, enum tree_code resultcode
)
12121 int op0_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op0
));
12122 int op1_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op1
));
12123 int unsignedp0
, unsignedp1
;
12125 /* In C++, check for comparison of different enum types. */
12126 if (c_dialect_cxx()
12127 && TREE_CODE (TREE_TYPE (orig_op0
)) == ENUMERAL_TYPE
12128 && TREE_CODE (TREE_TYPE (orig_op1
)) == ENUMERAL_TYPE
12129 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0
))
12130 != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1
)))
12132 warning_at (location
,
12133 OPT_Wsign_compare
, "comparison between types %qT and %qT",
12134 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
));
12137 /* Do not warn if the comparison is being done in a signed type,
12138 since the signed type will only be chosen if it can represent
12139 all the values of the unsigned type. */
12140 if (!TYPE_UNSIGNED (result_type
))
12142 /* Do not warn if both operands are unsigned. */
12143 else if (op0_signed
== op1_signed
)
12147 tree sop
, uop
, base_type
;
12151 sop
= orig_op0
, uop
= orig_op1
;
12153 sop
= orig_op1
, uop
= orig_op0
;
12155 STRIP_TYPE_NOPS (sop
);
12156 STRIP_TYPE_NOPS (uop
);
12157 base_type
= (TREE_CODE (result_type
) == COMPLEX_TYPE
12158 ? TREE_TYPE (result_type
) : result_type
);
12160 /* Do not warn if the signed quantity is an unsuffixed integer
12161 literal (or some static constant expression involving such
12162 literals or a conditional expression involving such literals)
12163 and it is non-negative. */
12164 if (tree_expr_nonnegative_warnv_p (sop
, &ovf
))
12166 /* Do not warn if the comparison is an equality operation, the
12167 unsigned quantity is an integral constant, and it would fit
12168 in the result if the result were signed. */
12169 else if (TREE_CODE (uop
) == INTEGER_CST
12170 && (resultcode
== EQ_EXPR
|| resultcode
== NE_EXPR
)
12171 && int_fits_type_p (uop
, c_common_signed_type (base_type
)))
12173 /* In C, do not warn if the unsigned quantity is an enumeration
12174 constant and its maximum value would fit in the result if the
12175 result were signed. */
12176 else if (!c_dialect_cxx() && TREE_CODE (uop
) == INTEGER_CST
12177 && TREE_CODE (TREE_TYPE (uop
)) == ENUMERAL_TYPE
12178 && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (uop
)),
12179 c_common_signed_type (base_type
)))
12182 warning_at (location
,
12184 "comparison between signed and unsigned integer expressions");
12187 /* Warn if two unsigned values are being compared in a size larger
12188 than their original size, and one (and only one) is the result of
12189 a `~' operator. This comparison will always fail.
12191 Also warn if one operand is a constant, and the constant does not
12192 have all bits set that are set in the ~ operand when it is
12195 op0
= c_common_get_narrower (op0
, &unsignedp0
);
12196 op1
= c_common_get_narrower (op1
, &unsignedp1
);
12198 if ((TREE_CODE (op0
) == BIT_NOT_EXPR
)
12199 ^ (TREE_CODE (op1
) == BIT_NOT_EXPR
))
12201 if (TREE_CODE (op0
) == BIT_NOT_EXPR
)
12202 op0
= c_common_get_narrower (TREE_OPERAND (op0
, 0), &unsignedp0
);
12203 if (TREE_CODE (op1
) == BIT_NOT_EXPR
)
12204 op1
= c_common_get_narrower (TREE_OPERAND (op1
, 0), &unsignedp1
);
12206 if (tree_fits_shwi_p (op0
) || tree_fits_shwi_p (op1
))
12209 HOST_WIDE_INT constant
, mask
;
12213 if (tree_fits_shwi_p (op0
))
12216 unsignedp
= unsignedp1
;
12217 constant
= tree_to_shwi (op0
);
12222 unsignedp
= unsignedp0
;
12223 constant
= tree_to_shwi (op1
);
12226 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
12227 if (bits
< TYPE_PRECISION (result_type
)
12228 && bits
< HOST_BITS_PER_LONG
&& unsignedp
)
12230 mask
= HOST_WIDE_INT_M1U
<< bits
;
12231 if ((mask
& constant
) != mask
)
12234 warning_at (location
, OPT_Wsign_compare
,
12235 "promoted ~unsigned is always non-zero");
12237 warning_at (location
, OPT_Wsign_compare
,
12238 "comparison of promoted ~unsigned with constant");
12242 else if (unsignedp0
&& unsignedp1
12243 && (TYPE_PRECISION (TREE_TYPE (op0
))
12244 < TYPE_PRECISION (result_type
))
12245 && (TYPE_PRECISION (TREE_TYPE (op1
))
12246 < TYPE_PRECISION (result_type
)))
12247 warning_at (location
, OPT_Wsign_compare
,
12248 "comparison of promoted ~unsigned with unsigned");
12252 /* RESULT_TYPE is the result of converting TYPE1 and TYPE2 to a common
12253 type via c_common_type. If -Wdouble-promotion is in use, and the
12254 conditions for warning have been met, issue a warning. GMSGID is
12255 the warning message. It must have two %T specifiers for the type
12256 that was converted (generally "float") and the type to which it was
12257 converted (generally "double), respectively. LOC is the location
12258 to which the awrning should refer. */
12261 do_warn_double_promotion (tree result_type
, tree type1
, tree type2
,
12262 const char *gmsgid
, location_t loc
)
12266 if (!warn_double_promotion
)
12268 /* If the conversion will not occur at run-time, there is no need to
12270 if (c_inhibit_evaluation_warnings
)
12272 if (TYPE_MAIN_VARIANT (result_type
) != double_type_node
12273 && TYPE_MAIN_VARIANT (result_type
) != complex_double_type_node
)
12275 if (TYPE_MAIN_VARIANT (type1
) == float_type_node
12276 || TYPE_MAIN_VARIANT (type1
) == complex_float_type_node
)
12277 source_type
= type1
;
12278 else if (TYPE_MAIN_VARIANT (type2
) == float_type_node
12279 || TYPE_MAIN_VARIANT (type2
) == complex_float_type_node
)
12280 source_type
= type2
;
12283 warning_at (loc
, OPT_Wdouble_promotion
, gmsgid
, source_type
, result_type
);
12286 /* Possibly warn about unused parameters. */
12289 do_warn_unused_parameter (tree fn
)
12293 for (decl
= DECL_ARGUMENTS (fn
);
12294 decl
; decl
= DECL_CHAIN (decl
))
12295 if (!TREE_USED (decl
) && TREE_CODE (decl
) == PARM_DECL
12296 && DECL_NAME (decl
) && !DECL_ARTIFICIAL (decl
)
12297 && !TREE_NO_WARNING (decl
))
12298 warning_at (DECL_SOURCE_LOCATION (decl
), OPT_Wunused_parameter
,
12299 "unused parameter %qD", decl
);
12303 /* Setup a TYPE_DECL node as a typedef representation.
12305 X is a TYPE_DECL for a typedef statement. Create a brand new
12306 ..._TYPE node (which will be just a variant of the existing
12307 ..._TYPE node with identical properties) and then install X
12308 as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
12310 The whole point here is to end up with a situation where each
12311 and every ..._TYPE node the compiler creates will be uniquely
12312 associated with AT MOST one node representing a typedef name.
12313 This way, even though the compiler substitutes corresponding
12314 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
12315 early on, later parts of the compiler can always do the reverse
12316 translation and get back the corresponding typedef name. For
12319 typedef struct S MY_TYPE;
12322 Later parts of the compiler might only know that `object' was of
12323 type `struct S' if it were not for code just below. With this
12324 code however, later parts of the compiler see something like:
12326 struct S' == struct S
12327 typedef struct S' MY_TYPE;
12330 And they can then deduce (from the node for type struct S') that
12331 the original object declaration was:
12335 Being able to do this is important for proper support of protoize,
12336 and also for generating precise symbolic debugging information
12337 which takes full account of the programmer's (typedef) vocabulary.
12339 Obviously, we don't want to generate a duplicate ..._TYPE node if
12340 the TYPE_DECL node that we are now processing really represents a
12341 standard built-in type. */
12344 set_underlying_type (tree x
)
12346 if (x
== error_mark_node
)
12348 if (DECL_IS_BUILTIN (x
) && TREE_CODE (TREE_TYPE (x
)) != ARRAY_TYPE
)
12350 if (TYPE_NAME (TREE_TYPE (x
)) == 0)
12351 TYPE_NAME (TREE_TYPE (x
)) = x
;
12353 else if (TREE_TYPE (x
) != error_mark_node
12354 && DECL_ORIGINAL_TYPE (x
) == NULL_TREE
)
12356 tree tt
= TREE_TYPE (x
);
12357 DECL_ORIGINAL_TYPE (x
) = tt
;
12358 tt
= build_variant_type_copy (tt
);
12359 TYPE_STUB_DECL (tt
) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x
));
12360 TYPE_NAME (tt
) = x
;
12361 TREE_USED (tt
) = TREE_USED (x
);
12362 TREE_TYPE (x
) = tt
;
12366 /* Record the types used by the current global variable declaration
12367 being parsed, so that we can decide later to emit their debug info.
12368 Those types are in types_used_by_cur_var_decl, and we are going to
12369 store them in the types_used_by_vars_hash hash table.
12370 DECL is the declaration of the global variable that has been parsed. */
12373 record_types_used_by_current_var_decl (tree decl
)
12375 gcc_assert (decl
&& DECL_P (decl
) && TREE_STATIC (decl
));
12377 while (types_used_by_cur_var_decl
&& !types_used_by_cur_var_decl
->is_empty ())
12379 tree type
= types_used_by_cur_var_decl
->pop ();
12380 types_used_by_var_decl_insert (type
, decl
);
12384 /* If DECL is a typedef that is declared in the current function,
12385 record it for the purpose of -Wunused-local-typedefs. */
12388 record_locally_defined_typedef (tree decl
)
12390 struct c_language_function
*l
;
12392 if (!warn_unused_local_typedefs
12394 /* if this is not a locally defined typedef then we are not
12396 || !is_typedef_decl (decl
)
12397 || !decl_function_context (decl
))
12400 l
= (struct c_language_function
*) cfun
->language
;
12401 vec_safe_push (l
->local_typedefs
, decl
);
12404 /* If T is a TYPE_DECL declared locally, mark it as used. */
12407 maybe_record_typedef_use (tree t
)
12409 if (!is_typedef_decl (t
))
12412 TREE_USED (t
) = true;
12415 /* Warn if there are some unused locally defined typedefs in the
12416 current function. */
12419 maybe_warn_unused_local_typedefs (void)
12423 /* The number of times we have emitted -Wunused-local-typedefs
12424 warnings. If this is different from errorcount, that means some
12425 unrelated errors have been issued. In which case, we'll avoid
12426 emitting "unused-local-typedefs" warnings. */
12427 static int unused_local_typedefs_warn_count
;
12428 struct c_language_function
*l
;
12433 if ((l
= (struct c_language_function
*) cfun
->language
) == NULL
)
12436 if (warn_unused_local_typedefs
12437 && errorcount
== unused_local_typedefs_warn_count
)
12439 FOR_EACH_VEC_SAFE_ELT (l
->local_typedefs
, i
, decl
)
12440 if (!TREE_USED (decl
))
12441 warning_at (DECL_SOURCE_LOCATION (decl
),
12442 OPT_Wunused_local_typedefs
,
12443 "typedef %qD locally defined but not used", decl
);
12444 unused_local_typedefs_warn_count
= errorcount
;
12447 vec_free (l
->local_typedefs
);
12450 /* Warn about boolean expression compared with an integer value different
12451 from true/false. Warns also e.g. about "(i1 == i2) == 2".
12452 LOC is the location of the comparison, CODE is its code, OP0 and OP1
12453 are the operands of the comparison. The caller must ensure that
12454 either operand is a boolean expression. */
12457 maybe_warn_bool_compare (location_t loc
, enum tree_code code
, tree op0
,
12460 if (TREE_CODE_CLASS (code
) != tcc_comparison
)
12464 if (f
= fold_for_warn (op0
),
12465 TREE_CODE (f
) == INTEGER_CST
)
12467 else if (f
= fold_for_warn (op1
),
12468 TREE_CODE (f
) == INTEGER_CST
)
12473 if (!integer_zerop (cst
) && !integer_onep (cst
))
12475 int sign
= (TREE_CODE (op0
) == INTEGER_CST
12476 ? tree_int_cst_sgn (cst
) : -tree_int_cst_sgn (cst
));
12477 if (code
== EQ_EXPR
12478 || ((code
== GT_EXPR
|| code
== GE_EXPR
) && sign
< 0)
12479 || ((code
== LT_EXPR
|| code
== LE_EXPR
) && sign
> 0))
12480 warning_at (loc
, OPT_Wbool_compare
, "comparison of constant %qE "
12481 "with boolean expression is always false", cst
);
12483 warning_at (loc
, OPT_Wbool_compare
, "comparison of constant %qE "
12484 "with boolean expression is always true", cst
);
12486 else if (integer_zerop (cst
) || integer_onep (cst
))
12488 /* If the non-constant operand isn't of a boolean type, we
12489 don't want to warn here. */
12490 tree noncst
= TREE_CODE (op0
) == INTEGER_CST
? op1
: op0
;
12491 /* Handle booleans promoted to integers. */
12492 if (bool_promoted_to_int_p (noncst
))
12494 else if (TREE_CODE (TREE_TYPE (noncst
)) != BOOLEAN_TYPE
12495 && !truth_value_p (TREE_CODE (noncst
)))
12497 /* Do some magic to get the right diagnostics. */
12498 bool flag
= TREE_CODE (op0
) == INTEGER_CST
;
12499 flag
= integer_zerop (cst
) ? flag
: !flag
;
12500 if ((code
== GE_EXPR
&& !flag
) || (code
== LE_EXPR
&& flag
))
12501 warning_at (loc
, OPT_Wbool_compare
, "comparison of constant %qE "
12502 "with boolean expression is always true", cst
);
12503 else if ((code
== LT_EXPR
&& !flag
) || (code
== GT_EXPR
&& flag
))
12504 warning_at (loc
, OPT_Wbool_compare
, "comparison of constant %qE "
12505 "with boolean expression is always false", cst
);
12509 /* Warn if signed left shift overflows. We don't warn
12510 about left-shifting 1 into the sign bit in C++14; cf.
12511 <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3367.html#1457>
12512 LOC is a location of the shift; OP0 and OP1 are the operands.
12513 Return true if an overflow is detected, false otherwise. */
12516 maybe_warn_shift_overflow (location_t loc
, tree op0
, tree op1
)
12518 if (TREE_CODE (op0
) != INTEGER_CST
12519 || TREE_CODE (op1
) != INTEGER_CST
)
12522 tree type0
= TREE_TYPE (op0
);
12523 unsigned int prec0
= TYPE_PRECISION (type0
);
12525 /* Left-hand operand must be signed. */
12526 if (TYPE_UNSIGNED (type0
))
12529 unsigned int min_prec
= (wi::min_precision (op0
, SIGNED
)
12530 + TREE_INT_CST_LOW (op1
));
12531 /* Handle the case of left-shifting 1 into the sign bit.
12532 * However, shifting 1 _out_ of the sign bit, as in
12533 * INT_MIN << 1, is considered an overflow.
12535 if (!tree_int_cst_sign_bit(op0
) && min_prec
== prec0
+ 1)
12537 /* Never warn for C++14 onwards. */
12538 if (cxx_dialect
>= cxx14
)
12540 /* Otherwise only if -Wshift-overflow=2. But return
12541 true to signal an overflow for the sake of integer
12542 constant expressions. */
12543 if (warn_shift_overflow
< 2)
12547 bool overflowed
= min_prec
> prec0
;
12548 if (overflowed
&& c_inhibit_evaluation_warnings
== 0)
12549 warning_at (loc
, OPT_Wshift_overflow_
,
12550 "result of %qE requires %u bits to represent, "
12551 "but %qT only has %u bits",
12552 build2_loc (loc
, LSHIFT_EXPR
, type0
, op0
, op1
),
12553 min_prec
, type0
, prec0
);
12558 /* The C and C++ parsers both use vectors to hold function arguments.
12559 For efficiency, we keep a cache of unused vectors. This is the
12562 typedef vec
<tree
, va_gc
> *tree_gc_vec
;
12563 static GTY((deletable
)) vec
<tree_gc_vec
, va_gc
> *tree_vector_cache
;
12565 /* Return a new vector from the cache. If the cache is empty,
12566 allocate a new vector. These vectors are GC'ed, so it is OK if the
12567 pointer is not released.. */
12570 make_tree_vector (void)
12572 if (tree_vector_cache
&& !tree_vector_cache
->is_empty ())
12573 return tree_vector_cache
->pop ();
12576 /* Passing 0 to vec::alloc returns NULL, and our callers require
12577 that we always return a non-NULL value. The vector code uses
12578 4 when growing a NULL vector, so we do too. */
12579 vec
<tree
, va_gc
> *v
;
12585 /* Release a vector of trees back to the cache. */
12588 release_tree_vector (vec
<tree
, va_gc
> *vec
)
12593 vec_safe_push (tree_vector_cache
, vec
);
12597 /* Get a new tree vector holding a single tree. */
12600 make_tree_vector_single (tree t
)
12602 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
12603 ret
->quick_push (t
);
12607 /* Get a new tree vector of the TREE_VALUEs of a TREE_LIST chain. */
12610 make_tree_vector_from_list (tree list
)
12612 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
12613 for (; list
; list
= TREE_CHAIN (list
))
12614 vec_safe_push (ret
, TREE_VALUE (list
));
12618 /* Get a new tree vector of the values of a CONSTRUCTOR. */
12621 make_tree_vector_from_ctor (tree ctor
)
12623 vec
<tree
,va_gc
> *ret
= make_tree_vector ();
12624 vec_safe_reserve (ret
, CONSTRUCTOR_NELTS (ctor
));
12625 for (unsigned i
= 0; i
< CONSTRUCTOR_NELTS (ctor
); ++i
)
12626 ret
->quick_push (CONSTRUCTOR_ELT (ctor
, i
)->value
);
12630 /* Get a new tree vector which is a copy of an existing one. */
12633 make_tree_vector_copy (const vec
<tree
, va_gc
> *orig
)
12635 vec
<tree
, va_gc
> *ret
;
12639 ret
= make_tree_vector ();
12640 vec_safe_reserve (ret
, vec_safe_length (orig
));
12641 FOR_EACH_VEC_SAFE_ELT (orig
, ix
, t
)
12642 ret
->quick_push (t
);
12646 /* Return true if KEYWORD starts a type specifier. */
12649 keyword_begins_type_specifier (enum rid keyword
)
12653 case RID_AUTO_TYPE
:
12663 CASE_RID_FLOATN_NX
:
12666 case RID_DFLOAT128
:
12682 if (keyword
>= RID_FIRST_INT_N
12683 && keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
12684 && int_n_enabled_p
[keyword
-RID_FIRST_INT_N
])
12690 /* Return true if KEYWORD names a type qualifier. */
12693 keyword_is_type_qualifier (enum rid keyword
)
12707 /* Return true if KEYWORD names a storage class specifier.
12709 RID_TYPEDEF is not included in this list despite `typedef' being
12710 listed in C99 6.7.1.1. 6.7.1.3 indicates that `typedef' is listed as
12711 such for syntactic convenience only. */
12714 keyword_is_storage_class_specifier (enum rid keyword
)
12730 /* Return true if KEYWORD names a function-specifier [dcl.fct.spec]. */
12733 keyword_is_function_specifier (enum rid keyword
)
12747 /* Return true if KEYWORD names a decl-specifier [dcl.spec] or a
12748 declaration-specifier (C99 6.7). */
12751 keyword_is_decl_specifier (enum rid keyword
)
12753 if (keyword_is_storage_class_specifier (keyword
)
12754 || keyword_is_type_qualifier (keyword
)
12755 || keyword_is_function_specifier (keyword
))
12762 case RID_CONSTEXPR
:
12769 /* Initialize language-specific-bits of tree_contains_struct. */
12772 c_common_init_ts (void)
12774 MARK_TS_TYPED (C_MAYBE_CONST_EXPR
);
12775 MARK_TS_TYPED (EXCESS_PRECISION_EXPR
);
12776 MARK_TS_TYPED (ARRAY_NOTATION_REF
);
12779 /* Build a user-defined numeric literal out of an integer constant type VALUE
12780 with identifier SUFFIX. */
12783 build_userdef_literal (tree suffix_id
, tree value
,
12784 enum overflow_type overflow
, tree num_string
)
12786 tree literal
= make_node (USERDEF_LITERAL
);
12787 USERDEF_LITERAL_SUFFIX_ID (literal
) = suffix_id
;
12788 USERDEF_LITERAL_VALUE (literal
) = value
;
12789 USERDEF_LITERAL_OVERFLOW (literal
) = overflow
;
12790 USERDEF_LITERAL_NUM_STRING (literal
) = num_string
;
12794 /* For vector[index], convert the vector to an array of the underlying type.
12795 Return true if the resulting ARRAY_REF should not be an lvalue. */
12798 convert_vector_to_array_for_subscript (location_t loc
,
12799 tree
*vecp
, tree index
)
12802 if (VECTOR_TYPE_P (TREE_TYPE (*vecp
)))
12804 tree type
= TREE_TYPE (*vecp
);
12806 ret
= !lvalue_p (*vecp
);
12808 if (TREE_CODE (index
) == INTEGER_CST
)
12809 if (!tree_fits_uhwi_p (index
)
12810 || tree_to_uhwi (index
) >= TYPE_VECTOR_SUBPARTS (type
))
12811 warning_at (loc
, OPT_Warray_bounds
, "index value is out of bound");
12813 /* We are building an ARRAY_REF so mark the vector as addressable
12814 to not run into the gimplifiers premature setting of DECL_GIMPLE_REG_P
12815 for function parameters. */
12816 c_common_mark_addressable_vec (*vecp
);
12818 *vecp
= build1 (VIEW_CONVERT_EXPR
,
12819 build_array_type_nelts (TREE_TYPE (type
),
12820 TYPE_VECTOR_SUBPARTS (type
)),
12826 /* Determine which of the operands, if any, is a scalar that needs to be
12827 converted to a vector, for the range of operations. */
12829 scalar_to_vector (location_t loc
, enum tree_code code
, tree op0
, tree op1
,
12832 tree type0
= TREE_TYPE (op0
);
12833 tree type1
= TREE_TYPE (op1
);
12834 bool integer_only_op
= false;
12835 enum stv_conv ret
= stv_firstarg
;
12837 gcc_assert (VECTOR_TYPE_P (type0
) || VECTOR_TYPE_P (type1
));
12840 /* Most GENERIC binary expressions require homogeneous arguments.
12841 LSHIFT_EXPR and RSHIFT_EXPR are exceptions and accept a first
12842 argument that is a vector and a second one that is a scalar, so
12843 we never return stv_secondarg for them. */
12846 if (TREE_CODE (type0
) == INTEGER_TYPE
12847 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
12849 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
12852 error_at (loc
, "conversion of scalar %qT to vector %qT "
12853 "involves truncation", type0
, type1
);
12857 return stv_firstarg
;
12864 integer_only_op
= true;
12867 case VEC_COND_EXPR
:
12872 case TRUNC_DIV_EXPR
:
12873 case CEIL_DIV_EXPR
:
12874 case FLOOR_DIV_EXPR
:
12875 case ROUND_DIV_EXPR
:
12876 case EXACT_DIV_EXPR
:
12877 case TRUNC_MOD_EXPR
:
12878 case FLOOR_MOD_EXPR
:
12886 /* What about UNLT_EXPR? */
12887 if (VECTOR_TYPE_P (type0
))
12889 ret
= stv_secondarg
;
12890 std::swap (type0
, type1
);
12891 std::swap (op0
, op1
);
12894 if (TREE_CODE (type0
) == INTEGER_TYPE
12895 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
12897 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
12900 error_at (loc
, "conversion of scalar %qT to vector %qT "
12901 "involves truncation", type0
, type1
);
12906 else if (!integer_only_op
12907 /* Allow integer --> real conversion if safe. */
12908 && (TREE_CODE (type0
) == REAL_TYPE
12909 || TREE_CODE (type0
) == INTEGER_TYPE
)
12910 && SCALAR_FLOAT_TYPE_P (TREE_TYPE (type1
)))
12912 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
12915 error_at (loc
, "conversion of scalar %qT to vector %qT "
12916 "involves truncation", type0
, type1
);
12925 return stv_nothing
;
12928 /* Return the alignment of std::max_align_t.
12930 [support.types.layout] The type max_align_t is a POD type whose alignment
12931 requirement is at least as great as that of every scalar type, and whose
12932 alignment requirement is supported in every context. */
12935 max_align_t_align ()
12937 unsigned int max_align
= MAX (TYPE_ALIGN (long_long_integer_type_node
),
12938 TYPE_ALIGN (long_double_type_node
));
12939 if (float128_type_node
!= NULL_TREE
)
12940 max_align
= MAX (max_align
, TYPE_ALIGN (float128_type_node
));
12944 /* Return true iff ALIGN is an integral constant that is a fundamental
12945 alignment, as defined by [basic.align] in the c++-11
12950 [A fundamental alignment is represented by an alignment less than or
12951 equal to the greatest alignment supported by the implementation
12952 in all contexts, which is equal to alignof(max_align_t)]. */
12955 cxx_fundamental_alignment_p (unsigned align
)
12957 return (align
<= max_align_t_align ());
12960 /* Return true if T is a pointer to a zero-sized aggregate. */
12963 pointer_to_zero_sized_aggr_p (tree t
)
12965 if (!POINTER_TYPE_P (t
))
12968 return (TYPE_SIZE (t
) && integer_zerop (TYPE_SIZE (t
)));
12971 /* For an EXPR of a FUNCTION_TYPE that references a GCC built-in function
12972 with no library fallback or for an ADDR_EXPR whose operand is such type
12973 issues an error pointing to the location LOC.
12974 Returns true when the expression has been diagnosed and false
12977 reject_gcc_builtin (const_tree expr
, location_t loc
/* = UNKNOWN_LOCATION */)
12979 if (TREE_CODE (expr
) == ADDR_EXPR
)
12980 expr
= TREE_OPERAND (expr
, 0);
12982 if (TREE_TYPE (expr
)
12983 && TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
12984 && TREE_CODE (expr
) == FUNCTION_DECL
12985 /* The intersection of DECL_BUILT_IN and DECL_IS_BUILTIN avoids
12986 false positives for user-declared built-ins such as abs or
12987 strlen, and for C++ operators new and delete.
12988 The c_decl_implicit() test avoids false positives for implicitly
12989 declared built-ins with library fallbacks (such as abs). */
12990 && DECL_BUILT_IN (expr
)
12991 && DECL_IS_BUILTIN (expr
)
12992 && !c_decl_implicit (expr
)
12993 && !DECL_ASSEMBLER_NAME_SET_P (expr
))
12995 if (loc
== UNKNOWN_LOCATION
)
12996 loc
= EXPR_LOC_OR_LOC (expr
, input_location
);
12998 /* Reject arguments that are built-in functions with
12999 no library fallback. */
13000 error_at (loc
, "built-in function %qE must be directly called", expr
);
13008 /* If we're creating an if-else-if condition chain, first see if we
13009 already have this COND in the CHAIN. If so, warn and don't add COND
13010 into the vector, otherwise add the COND there. LOC is the location
13014 warn_duplicated_cond_add_or_warn (location_t loc
, tree cond
, vec
<tree
> **chain
)
13016 /* No chain has been created yet. Do nothing. */
13017 if (*chain
== NULL
)
13020 if (TREE_SIDE_EFFECTS (cond
))
13022 /* Uh-oh! This condition has a side-effect, thus invalidates
13023 the whole chain. */
13031 bool found
= false;
13032 FOR_EACH_VEC_ELT (**chain
, ix
, t
)
13033 if (operand_equal_p (cond
, t
, 0))
13035 if (warning_at (loc
, OPT_Wduplicated_cond
,
13036 "duplicated %<if%> condition"))
13037 inform (EXPR_LOCATION (t
), "previously used here");
13043 && !CONSTANT_CLASS_P (cond
)
13044 /* Don't infinitely grow the chain. */
13045 && (*chain
)->length () < 512)
13046 (*chain
)->safe_push (cond
);
13049 /* Check if array size calculations overflow or if the array covers more
13050 than half of the address space. Return true if the size of the array
13051 is valid, false otherwise. TYPE is the type of the array and NAME is
13052 the name of the array, or NULL_TREE for unnamed arrays. */
13055 valid_array_size_p (location_t loc
, tree type
, tree name
)
13057 if (type
!= error_mark_node
13058 && COMPLETE_TYPE_P (type
)
13059 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
13060 && !valid_constant_size_p (TYPE_SIZE_UNIT (type
)))
13063 error_at (loc
, "size of array %qE is too large", name
);
13065 error_at (loc
, "size of unnamed array is too large");
13071 /* Read SOURCE_DATE_EPOCH from environment to have a deterministic
13072 timestamp to replace embedded current dates to get reproducible
13073 results. Returns -1 if SOURCE_DATE_EPOCH is not defined. */
13076 cb_get_source_date_epoch (cpp_reader
*pfile ATTRIBUTE_UNUSED
)
13078 char *source_date_epoch
;
13082 source_date_epoch
= getenv ("SOURCE_DATE_EPOCH");
13083 if (!source_date_epoch
)
13084 return (time_t) -1;
13087 #if defined(INT64_T_IS_LONG)
13088 epoch
= strtol (source_date_epoch
, &endptr
, 10);
13090 epoch
= strtoll (source_date_epoch
, &endptr
, 10);
13092 if (errno
!= 0 || endptr
== source_date_epoch
|| *endptr
!= '\0'
13093 || epoch
< 0 || epoch
> MAX_SOURCE_DATE_EPOCH
)
13095 error_at (input_location
, "environment variable SOURCE_DATE_EPOCH must "
13096 "expand to a non-negative integer less than or equal to %wd",
13097 MAX_SOURCE_DATE_EPOCH
);
13098 return (time_t) -1;
13101 return (time_t) epoch
;
13104 /* Callback for libcpp for offering spelling suggestions for misspelled
13105 directives. GOAL is an unrecognized string; CANDIDATES is a
13106 NULL-terminated array of candidate strings. Return the closest
13107 match to GOAL within CANDIDATES, or NULL if none are good
13111 cb_get_suggestion (cpp_reader
*, const char *goal
,
13112 const char *const *candidates
)
13114 best_match
<const char *, const char *> bm (goal
);
13115 while (*candidates
)
13116 bm
.consider (*candidates
++);
13117 return bm
.get_best_meaningful_candidate ();
13120 /* Check and possibly warn if two declarations have contradictory
13121 attributes, such as always_inline vs. noinline. */
13124 diagnose_mismatched_attributes (tree olddecl
, tree newdecl
)
13126 bool warned
= false;
13128 tree a1
= lookup_attribute ("optimize", DECL_ATTRIBUTES (olddecl
));
13129 tree a2
= lookup_attribute ("optimize", DECL_ATTRIBUTES (newdecl
));
13130 /* An optimization attribute applied on a declaration after the
13131 definition is likely not what the user wanted. */
13132 if (a2
!= NULL_TREE
13133 && DECL_SAVED_TREE (olddecl
) != NULL_TREE
13134 && (a1
== NULL_TREE
|| !attribute_list_equal (a1
, a2
)))
13135 warned
|= warning (OPT_Wattributes
,
13136 "optimization attribute on %qD follows "
13137 "definition but the attribute doesn%'t match",
13140 /* Diagnose inline __attribute__ ((noinline)) which is silly. */
13141 if (DECL_DECLARED_INLINE_P (newdecl
)
13142 && DECL_UNINLINABLE (olddecl
)
13143 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl
)))
13144 warned
|= warning (OPT_Wattributes
, "inline declaration of %qD follows "
13145 "declaration with attribute noinline", newdecl
);
13146 else if (DECL_DECLARED_INLINE_P (olddecl
)
13147 && DECL_UNINLINABLE (newdecl
)
13148 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl
)))
13149 warned
|= warning (OPT_Wattributes
, "declaration of %q+D with attribute "
13150 "noinline follows inline declaration ", newdecl
);
13151 else if (lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl
))
13152 && lookup_attribute ("always_inline", DECL_ATTRIBUTES (olddecl
)))
13153 warned
|= warning (OPT_Wattributes
, "declaration of %q+D with attribute "
13154 "%qs follows declaration with attribute %qs",
13155 newdecl
, "noinline", "always_inline");
13156 else if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (newdecl
))
13157 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl
)))
13158 warned
|= warning (OPT_Wattributes
, "declaration of %q+D with attribute "
13159 "%qs follows declaration with attribute %qs",
13160 newdecl
, "always_inline", "noinline");
13161 else if (lookup_attribute ("cold", DECL_ATTRIBUTES (newdecl
))
13162 && lookup_attribute ("hot", DECL_ATTRIBUTES (olddecl
)))
13163 warned
|= warning (OPT_Wattributes
, "declaration of %q+D with attribute "
13164 "%qs follows declaration with attribute %qs",
13165 newdecl
, "cold", "hot");
13166 else if (lookup_attribute ("hot", DECL_ATTRIBUTES (newdecl
))
13167 && lookup_attribute ("cold", DECL_ATTRIBUTES (olddecl
)))
13168 warned
|= warning (OPT_Wattributes
, "declaration of %q+D with attribute "
13169 "%qs follows declaration with attribute %qs",
13170 newdecl
, "hot", "cold");
13174 #include "gt-c-family-c-common.h"