1 /* Subroutines shared by all languages that are variants of C.
2 Copyright (C) 1992-2015 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 "fold-const.h"
31 #include "stor-layout.h"
33 #include "stringpool.h"
36 #include "trans-mem.h"
44 #include "common/common-target.h"
45 #include "langhooks.h"
46 #include "tree-inline.h"
48 #include "diagnostic.h"
49 #include "tree-iterator.h"
54 #include "plugin-api.h"
58 #include "hard-reg-set.h"
63 #include "target-def.h"
65 #include "wide-int-print.h"
66 #include "gimple-expr.h"
68 cpp_reader
*parse_in
; /* Declared in c-pragma.h. */
70 /* Mode used to build pointers (VOIDmode means ptr_mode). */
72 machine_mode c_default_pointer_mode
= VOIDmode
;
74 /* The following symbols are subsumed in the c_global_trees array, and
75 listed here individually for documentation purposes.
77 INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
79 tree short_integer_type_node;
80 tree long_integer_type_node;
81 tree long_long_integer_type_node;
83 tree short_unsigned_type_node;
84 tree long_unsigned_type_node;
85 tree long_long_unsigned_type_node;
87 tree truthvalue_type_node;
88 tree truthvalue_false_node;
89 tree truthvalue_true_node;
91 tree ptrdiff_type_node;
93 tree unsigned_char_type_node;
94 tree signed_char_type_node;
97 tree char16_type_node;
98 tree char32_type_node;
100 tree float_type_node;
101 tree double_type_node;
102 tree long_double_type_node;
104 tree complex_integer_type_node;
105 tree complex_float_type_node;
106 tree complex_double_type_node;
107 tree complex_long_double_type_node;
109 tree dfloat32_type_node;
110 tree dfloat64_type_node;
111 tree_dfloat128_type_node;
113 tree intQI_type_node;
114 tree intHI_type_node;
115 tree intSI_type_node;
116 tree intDI_type_node;
117 tree intTI_type_node;
119 tree unsigned_intQI_type_node;
120 tree unsigned_intHI_type_node;
121 tree unsigned_intSI_type_node;
122 tree unsigned_intDI_type_node;
123 tree unsigned_intTI_type_node;
125 tree widest_integer_literal_type_node;
126 tree widest_unsigned_literal_type_node;
128 Nodes for types `void *' and `const void *'.
130 tree ptr_type_node, const_ptr_type_node;
132 Nodes for types `char *' and `const char *'.
134 tree string_type_node, const_string_type_node;
136 Type `char[SOMENUMBER]'.
137 Used when an array of char is needed and the size is irrelevant.
139 tree char_array_type_node;
141 Type `wchar_t[SOMENUMBER]' or something like it.
142 Used when a wide string literal is created.
144 tree wchar_array_type_node;
146 Type `char16_t[SOMENUMBER]' or something like it.
147 Used when a UTF-16 string literal is created.
149 tree char16_array_type_node;
151 Type `char32_t[SOMENUMBER]' or something like it.
152 Used when a UTF-32 string literal is created.
154 tree char32_array_type_node;
156 Type `int ()' -- used for implicit declaration of functions.
158 tree default_function_type;
160 A VOID_TYPE node, packaged in a TREE_LIST.
164 The lazily created VAR_DECLs for __FUNCTION__, __PRETTY_FUNCTION__,
165 and __func__. (C doesn't generate __FUNCTION__ and__PRETTY_FUNCTION__
166 VAR_DECLS, but C++ does.)
168 tree function_name_decl_node;
169 tree pretty_function_name_decl_node;
170 tree c99_function_name_decl_node;
172 Stack of nested function name VAR_DECLs.
174 tree saved_function_name_decls;
178 tree c_global_trees
[CTI_MAX
];
180 /* Switches common to the C front ends. */
182 /* Nonzero means don't output line number information. */
184 char flag_no_line_commands
;
186 /* Nonzero causes -E output not to be done, but directives such as
187 #define that have side effects are still obeyed. */
191 /* Nonzero means dump macros in some fashion. */
193 char flag_dump_macros
;
195 /* Nonzero means pass #include lines through to the output. */
197 char flag_dump_includes
;
199 /* Nonzero means process PCH files while preprocessing. */
201 bool flag_pch_preprocess
;
203 /* The file name to which we should write a precompiled header, or
204 NULL if no header will be written in this compile. */
206 const char *pch_file
;
208 /* Nonzero if an ISO standard was selected. It rejects macros in the
212 /* C/ObjC language option variables. */
215 /* Nonzero means allow type mismatches in conditional expressions;
216 just make their values `void'. */
218 int flag_cond_mismatch
;
220 /* Nonzero means enable C89 Amendment 1 features. */
224 /* Nonzero means use the ISO C99 (or C11) dialect of C. */
228 /* Nonzero means use the ISO C11 dialect of C. */
232 /* Nonzero means that we have builtin functions, and main is an int. */
237 /* ObjC language option variables. */
240 /* Tells the compiler that this is a special run. Do not perform any
241 compiling, instead we are to test some platform dependent features
242 and output a C header file with appropriate definitions. */
244 int print_struct_values
;
246 /* Tells the compiler what is the constant string class for ObjC. */
248 const char *constant_string_class_name
;
251 /* C++ language option variables. */
254 /* Nonzero means generate separate instantiation control files and
255 juggle them at link time. */
257 int flag_use_repository
;
259 /* The C++ dialect being used. Default set in c_common_post_options. */
261 enum cxx_dialect cxx_dialect
= cxx_unset
;
263 /* Maximum template instantiation depth. This limit exists to limit the
264 time it takes to notice excessively recursive template instantiations.
266 The default is lower than the 1024 recommended by the C++0x standard
267 because G++ runs out of stack before 1024 with highly recursive template
268 argument deduction substitution (g++.dg/cpp0x/enum11.C). */
270 int max_tinst_depth
= 900;
272 /* The elements of `ridpointers' are identifier nodes for the reserved
273 type names and storage classes. It is indexed by a RID_... value. */
276 tree (*make_fname_decl
) (location_t
, tree
, int);
278 /* Nonzero means don't warn about problems that occur when the code is
280 int c_inhibit_evaluation_warnings
;
282 /* Whether we are building a boolean conversion inside
283 convert_for_assignment, or some other late binary operation. If
284 build_binary_op is called for C (from code shared by C and C++) in
285 this case, then the operands have already been folded and the
286 result will not be folded again, so C_MAYBE_CONST_EXPR should not
288 bool in_late_binary_op
;
290 /* Whether lexing has been completed, so subsequent preprocessor
291 errors should use the compiler's input_location. */
292 bool done_lexing
= false;
294 /* Information about how a function name is generated. */
297 tree
*const decl
; /* pointer to the VAR_DECL. */
298 const unsigned rid
; /* RID number for the identifier. */
299 const int pretty
; /* How pretty is it? */
302 /* The three ways of getting then name of the current function. */
304 const struct fname_var_t fname_vars
[] =
306 /* C99 compliant __func__, must be first. */
307 {&c99_function_name_decl_node
, RID_C99_FUNCTION_NAME
, 0},
308 /* GCC __FUNCTION__ compliant. */
309 {&function_name_decl_node
, RID_FUNCTION_NAME
, 0},
310 /* GCC __PRETTY_FUNCTION__ compliant. */
311 {&pretty_function_name_decl_node
, RID_PRETTY_FUNCTION_NAME
, 1},
315 /* Global visibility options. */
316 struct visibility_flags visibility_options
;
318 static tree
c_fully_fold_internal (tree expr
, bool, bool *, bool *, bool);
319 static tree
check_case_value (location_t
, tree
);
320 static bool check_case_bounds (location_t
, tree
, tree
, tree
*, tree
*);
322 static tree
handle_packed_attribute (tree
*, tree
, tree
, int, bool *);
323 static tree
handle_nocommon_attribute (tree
*, tree
, tree
, int, bool *);
324 static tree
handle_common_attribute (tree
*, tree
, tree
, int, bool *);
325 static tree
handle_noreturn_attribute (tree
*, tree
, tree
, int, bool *);
326 static tree
handle_hot_attribute (tree
*, tree
, tree
, int, bool *);
327 static tree
handle_cold_attribute (tree
*, tree
, tree
, int, bool *);
328 static tree
handle_no_sanitize_address_attribute (tree
*, tree
, tree
,
330 static tree
handle_no_address_safety_analysis_attribute (tree
*, tree
, tree
,
332 static tree
handle_no_sanitize_undefined_attribute (tree
*, tree
, tree
, int,
334 static tree
handle_stack_protect_attribute (tree
*, tree
, tree
, int, bool *);
335 static tree
handle_noinline_attribute (tree
*, tree
, tree
, int, bool *);
336 static tree
handle_noclone_attribute (tree
*, tree
, tree
, int, bool *);
337 static tree
handle_noicf_attribute (tree
*, tree
, tree
, int, bool *);
338 static tree
handle_leaf_attribute (tree
*, tree
, tree
, int, bool *);
339 static tree
handle_always_inline_attribute (tree
*, tree
, tree
, int,
341 static tree
handle_gnu_inline_attribute (tree
*, tree
, tree
, int, bool *);
342 static tree
handle_artificial_attribute (tree
*, tree
, tree
, int, bool *);
343 static tree
handle_flatten_attribute (tree
*, tree
, tree
, int, bool *);
344 static tree
handle_error_attribute (tree
*, tree
, tree
, int, bool *);
345 static tree
handle_used_attribute (tree
*, tree
, tree
, int, bool *);
346 static tree
handle_unused_attribute (tree
*, tree
, tree
, int, bool *);
347 static tree
handle_externally_visible_attribute (tree
*, tree
, tree
, int,
349 static tree
handle_no_reorder_attribute (tree
*, tree
, tree
, int,
351 static tree
handle_const_attribute (tree
*, tree
, tree
, int, bool *);
352 static tree
handle_transparent_union_attribute (tree
*, tree
, tree
,
354 static tree
handle_constructor_attribute (tree
*, tree
, tree
, int, bool *);
355 static tree
handle_destructor_attribute (tree
*, tree
, tree
, int, bool *);
356 static tree
handle_mode_attribute (tree
*, tree
, tree
, int, bool *);
357 static tree
handle_section_attribute (tree
*, tree
, tree
, int, bool *);
358 static tree
handle_aligned_attribute (tree
*, tree
, tree
, int, bool *);
359 static tree
handle_weak_attribute (tree
*, tree
, tree
, int, bool *) ;
360 static tree
handle_alias_ifunc_attribute (bool, tree
*, tree
, tree
, bool *);
361 static tree
handle_ifunc_attribute (tree
*, tree
, tree
, int, bool *);
362 static tree
handle_alias_attribute (tree
*, tree
, tree
, int, bool *);
363 static tree
handle_weakref_attribute (tree
*, tree
, tree
, int, bool *) ;
364 static tree
handle_visibility_attribute (tree
*, tree
, tree
, int,
366 static tree
handle_tls_model_attribute (tree
*, tree
, tree
, int,
368 static tree
handle_no_instrument_function_attribute (tree
*, tree
,
370 static tree
handle_malloc_attribute (tree
*, tree
, tree
, int, bool *);
371 static tree
handle_returns_twice_attribute (tree
*, tree
, tree
, int, bool *);
372 static tree
handle_no_limit_stack_attribute (tree
*, tree
, tree
, int,
374 static tree
handle_pure_attribute (tree
*, tree
, tree
, int, bool *);
375 static tree
handle_tm_attribute (tree
*, tree
, tree
, int, bool *);
376 static tree
handle_tm_wrap_attribute (tree
*, tree
, tree
, int, bool *);
377 static tree
handle_novops_attribute (tree
*, tree
, tree
, int, bool *);
378 static tree
handle_deprecated_attribute (tree
*, tree
, tree
, int,
380 static tree
handle_vector_size_attribute (tree
*, tree
, tree
, int,
382 static tree
handle_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
383 static tree
handle_nothrow_attribute (tree
*, tree
, tree
, int, bool *);
384 static tree
handle_cleanup_attribute (tree
*, tree
, tree
, int, bool *);
385 static tree
handle_warn_unused_result_attribute (tree
*, tree
, tree
, int,
387 static tree
handle_sentinel_attribute (tree
*, tree
, tree
, int, bool *);
388 static tree
handle_type_generic_attribute (tree
*, tree
, tree
, int, bool *);
389 static tree
handle_alloc_size_attribute (tree
*, tree
, tree
, int, bool *);
390 static tree
handle_alloc_align_attribute (tree
*, tree
, tree
, int, bool *);
391 static tree
handle_assume_aligned_attribute (tree
*, tree
, tree
, int, bool *);
392 static tree
handle_target_attribute (tree
*, tree
, tree
, int, bool *);
393 static tree
handle_optimize_attribute (tree
*, tree
, tree
, int, bool *);
394 static tree
ignore_attribute (tree
*, tree
, tree
, int, bool *);
395 static tree
handle_no_split_stack_attribute (tree
*, tree
, tree
, int, bool *);
396 static tree
handle_fnspec_attribute (tree
*, tree
, tree
, int, bool *);
397 static tree
handle_warn_unused_attribute (tree
*, tree
, tree
, int, bool *);
398 static tree
handle_returns_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
399 static tree
handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int,
401 static tree
handle_omp_declare_target_attribute (tree
*, tree
, tree
, int,
403 static tree
handle_designated_init_attribute (tree
*, tree
, tree
, int, bool *);
404 static tree
handle_bnd_variable_size_attribute (tree
*, tree
, tree
, int, bool *);
405 static tree
handle_bnd_legacy (tree
*, tree
, tree
, int, bool *);
406 static tree
handle_bnd_instrument (tree
*, tree
, tree
, int, bool *);
408 static void check_function_nonnull (tree
, int, tree
*);
409 static void check_nonnull_arg (void *, tree
, unsigned HOST_WIDE_INT
);
410 static bool nonnull_check_p (tree
, unsigned HOST_WIDE_INT
);
411 static bool get_nonnull_operand (tree
, unsigned HOST_WIDE_INT
*);
412 static int resort_field_decl_cmp (const void *, const void *);
414 /* Reserved words. The third field is a mask: keywords are disabled
415 if they match the mask.
418 C --std=c89: D_C99 | D_CXXONLY | D_OBJC | D_CXX_OBJC
419 C --std=c99: D_CXXONLY | D_OBJC
420 ObjC is like C except that D_OBJC and D_CXX_OBJC are not set
421 C++ --std=c98: D_CONLY | D_CXXOX | D_OBJC
422 C++ --std=c0x: D_CONLY | D_OBJC
423 ObjC++ is like C++ except that D_OBJC is not set
425 If -fno-asm is used, D_ASM is added to the mask. If
426 -fno-gnu-keywords is used, D_EXT is added. If -fno-asm and C in
427 C89 mode, D_EXT89 is added for both -fno-asm and -fno-gnu-keywords.
428 In C with -Wc++-compat, we warn if D_CXXWARN is set.
430 Note the complication of the D_CXX_OBJC keywords. These are
431 reserved words such as 'class'. In C++, 'class' is a reserved
432 word. In Objective-C++ it is too. In Objective-C, it is a
433 reserved word too, but only if it follows an '@' sign.
435 const struct c_common_resword c_common_reswords
[] =
437 { "_Alignas", RID_ALIGNAS
, D_CONLY
},
438 { "_Alignof", RID_ALIGNOF
, D_CONLY
},
439 { "_Atomic", RID_ATOMIC
, D_CONLY
},
440 { "_Bool", RID_BOOL
, D_CONLY
},
441 { "_Complex", RID_COMPLEX
, 0 },
442 { "_Cilk_spawn", RID_CILK_SPAWN
, 0 },
443 { "_Cilk_sync", RID_CILK_SYNC
, 0 },
444 { "_Cilk_for", RID_CILK_FOR
, 0 },
445 { "_Imaginary", RID_IMAGINARY
, D_CONLY
},
446 { "_Decimal32", RID_DFLOAT32
, D_CONLY
| D_EXT
},
447 { "_Decimal64", RID_DFLOAT64
, D_CONLY
| D_EXT
},
448 { "_Decimal128", RID_DFLOAT128
, D_CONLY
| D_EXT
},
449 { "_Fract", RID_FRACT
, D_CONLY
| D_EXT
},
450 { "_Accum", RID_ACCUM
, D_CONLY
| D_EXT
},
451 { "_Sat", RID_SAT
, D_CONLY
| D_EXT
},
452 { "_Static_assert", RID_STATIC_ASSERT
, D_CONLY
},
453 { "_Noreturn", RID_NORETURN
, D_CONLY
},
454 { "_Generic", RID_GENERIC
, D_CONLY
},
455 { "_Thread_local", RID_THREAD
, D_CONLY
},
456 { "__FUNCTION__", RID_FUNCTION_NAME
, 0 },
457 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME
, 0 },
458 { "__alignof", RID_ALIGNOF
, 0 },
459 { "__alignof__", RID_ALIGNOF
, 0 },
460 { "__asm", RID_ASM
, 0 },
461 { "__asm__", RID_ASM
, 0 },
462 { "__attribute", RID_ATTRIBUTE
, 0 },
463 { "__attribute__", RID_ATTRIBUTE
, 0 },
464 { "__auto_type", RID_AUTO_TYPE
, D_CONLY
},
465 { "__bases", RID_BASES
, D_CXXONLY
},
466 { "__builtin_call_with_static_chain",
467 RID_BUILTIN_CALL_WITH_STATIC_CHAIN
, D_CONLY
},
468 { "__builtin_choose_expr", RID_CHOOSE_EXPR
, D_CONLY
},
469 { "__builtin_complex", RID_BUILTIN_COMPLEX
, D_CONLY
},
470 { "__builtin_shuffle", RID_BUILTIN_SHUFFLE
, 0 },
471 { "__builtin_offsetof", RID_OFFSETOF
, 0 },
472 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P
, D_CONLY
},
473 { "__builtin_va_arg", RID_VA_ARG
, 0 },
474 { "__complex", RID_COMPLEX
, 0 },
475 { "__complex__", RID_COMPLEX
, 0 },
476 { "__const", RID_CONST
, 0 },
477 { "__const__", RID_CONST
, 0 },
478 { "__decltype", RID_DECLTYPE
, D_CXXONLY
},
479 { "__direct_bases", RID_DIRECT_BASES
, D_CXXONLY
},
480 { "__extension__", RID_EXTENSION
, 0 },
481 { "__func__", RID_C99_FUNCTION_NAME
, 0 },
482 { "__has_nothrow_assign", RID_HAS_NOTHROW_ASSIGN
, D_CXXONLY
},
483 { "__has_nothrow_constructor", RID_HAS_NOTHROW_CONSTRUCTOR
, D_CXXONLY
},
484 { "__has_nothrow_copy", RID_HAS_NOTHROW_COPY
, D_CXXONLY
},
485 { "__has_trivial_assign", RID_HAS_TRIVIAL_ASSIGN
, D_CXXONLY
},
486 { "__has_trivial_constructor", RID_HAS_TRIVIAL_CONSTRUCTOR
, D_CXXONLY
},
487 { "__has_trivial_copy", RID_HAS_TRIVIAL_COPY
, D_CXXONLY
},
488 { "__has_trivial_destructor", RID_HAS_TRIVIAL_DESTRUCTOR
, D_CXXONLY
},
489 { "__has_virtual_destructor", RID_HAS_VIRTUAL_DESTRUCTOR
, D_CXXONLY
},
490 { "__imag", RID_IMAGPART
, 0 },
491 { "__imag__", RID_IMAGPART
, 0 },
492 { "__inline", RID_INLINE
, 0 },
493 { "__inline__", RID_INLINE
, 0 },
494 { "__is_abstract", RID_IS_ABSTRACT
, D_CXXONLY
},
495 { "__is_base_of", RID_IS_BASE_OF
, D_CXXONLY
},
496 { "__is_class", RID_IS_CLASS
, D_CXXONLY
},
497 { "__is_empty", RID_IS_EMPTY
, D_CXXONLY
},
498 { "__is_enum", RID_IS_ENUM
, D_CXXONLY
},
499 { "__is_final", RID_IS_FINAL
, D_CXXONLY
},
500 { "__is_literal_type", RID_IS_LITERAL_TYPE
, D_CXXONLY
},
501 { "__is_pod", RID_IS_POD
, D_CXXONLY
},
502 { "__is_polymorphic", RID_IS_POLYMORPHIC
, D_CXXONLY
},
503 { "__is_standard_layout", RID_IS_STD_LAYOUT
, D_CXXONLY
},
504 { "__is_trivial", RID_IS_TRIVIAL
, D_CXXONLY
},
505 { "__is_trivially_assignable", RID_IS_TRIVIALLY_ASSIGNABLE
, D_CXXONLY
},
506 { "__is_trivially_constructible", RID_IS_TRIVIALLY_CONSTRUCTIBLE
, D_CXXONLY
},
507 { "__is_trivially_copyable", RID_IS_TRIVIALLY_COPYABLE
, D_CXXONLY
},
508 { "__is_union", RID_IS_UNION
, D_CXXONLY
},
509 { "__label__", RID_LABEL
, 0 },
510 { "__null", RID_NULL
, 0 },
511 { "__real", RID_REALPART
, 0 },
512 { "__real__", RID_REALPART
, 0 },
513 { "__restrict", RID_RESTRICT
, 0 },
514 { "__restrict__", RID_RESTRICT
, 0 },
515 { "__signed", RID_SIGNED
, 0 },
516 { "__signed__", RID_SIGNED
, 0 },
517 { "__thread", RID_THREAD
, 0 },
518 { "__transaction_atomic", RID_TRANSACTION_ATOMIC
, 0 },
519 { "__transaction_relaxed", RID_TRANSACTION_RELAXED
, 0 },
520 { "__transaction_cancel", RID_TRANSACTION_CANCEL
, 0 },
521 { "__typeof", RID_TYPEOF
, 0 },
522 { "__typeof__", RID_TYPEOF
, 0 },
523 { "__underlying_type", RID_UNDERLYING_TYPE
, D_CXXONLY
},
524 { "__volatile", RID_VOLATILE
, 0 },
525 { "__volatile__", RID_VOLATILE
, 0 },
526 { "alignas", RID_ALIGNAS
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
527 { "alignof", RID_ALIGNOF
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
528 { "asm", RID_ASM
, D_ASM
},
529 { "auto", RID_AUTO
, 0 },
530 { "bool", RID_BOOL
, D_CXXONLY
| D_CXXWARN
},
531 { "break", RID_BREAK
, 0 },
532 { "case", RID_CASE
, 0 },
533 { "catch", RID_CATCH
, D_CXX_OBJC
| D_CXXWARN
},
534 { "char", RID_CHAR
, 0 },
535 { "char16_t", RID_CHAR16
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
536 { "char32_t", RID_CHAR32
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
537 { "class", RID_CLASS
, D_CXX_OBJC
| D_CXXWARN
},
538 { "const", RID_CONST
, 0 },
539 { "constexpr", RID_CONSTEXPR
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
540 { "const_cast", RID_CONSTCAST
, D_CXXONLY
| D_CXXWARN
},
541 { "continue", RID_CONTINUE
, 0 },
542 { "decltype", RID_DECLTYPE
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
543 { "default", RID_DEFAULT
, 0 },
544 { "delete", RID_DELETE
, D_CXXONLY
| D_CXXWARN
},
546 { "double", RID_DOUBLE
, 0 },
547 { "dynamic_cast", RID_DYNCAST
, D_CXXONLY
| D_CXXWARN
},
548 { "else", RID_ELSE
, 0 },
549 { "enum", RID_ENUM
, 0 },
550 { "explicit", RID_EXPLICIT
, D_CXXONLY
| D_CXXWARN
},
551 { "export", RID_EXPORT
, D_CXXONLY
| D_CXXWARN
},
552 { "extern", RID_EXTERN
, 0 },
553 { "false", RID_FALSE
, D_CXXONLY
| D_CXXWARN
},
554 { "float", RID_FLOAT
, 0 },
555 { "for", RID_FOR
, 0 },
556 { "friend", RID_FRIEND
, D_CXXONLY
| D_CXXWARN
},
557 { "goto", RID_GOTO
, 0 },
559 { "inline", RID_INLINE
, D_EXT89
},
560 { "int", RID_INT
, 0 },
561 { "long", RID_LONG
, 0 },
562 { "mutable", RID_MUTABLE
, D_CXXONLY
| D_CXXWARN
},
563 { "namespace", RID_NAMESPACE
, D_CXXONLY
| D_CXXWARN
},
564 { "new", RID_NEW
, D_CXXONLY
| D_CXXWARN
},
565 { "noexcept", RID_NOEXCEPT
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
566 { "nullptr", RID_NULLPTR
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
567 { "operator", RID_OPERATOR
, D_CXXONLY
| D_CXXWARN
},
568 { "private", RID_PRIVATE
, D_CXX_OBJC
| D_CXXWARN
},
569 { "protected", RID_PROTECTED
, D_CXX_OBJC
| D_CXXWARN
},
570 { "public", RID_PUBLIC
, D_CXX_OBJC
| D_CXXWARN
},
571 { "register", RID_REGISTER
, 0 },
572 { "reinterpret_cast", RID_REINTCAST
, D_CXXONLY
| D_CXXWARN
},
573 { "restrict", RID_RESTRICT
, D_CONLY
| D_C99
},
574 { "return", RID_RETURN
, 0 },
575 { "short", RID_SHORT
, 0 },
576 { "signed", RID_SIGNED
, 0 },
577 { "sizeof", RID_SIZEOF
, 0 },
578 { "static", RID_STATIC
, 0 },
579 { "static_assert", RID_STATIC_ASSERT
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
580 { "static_cast", RID_STATCAST
, D_CXXONLY
| D_CXXWARN
},
581 { "struct", RID_STRUCT
, 0 },
582 { "switch", RID_SWITCH
, 0 },
583 { "template", RID_TEMPLATE
, D_CXXONLY
| D_CXXWARN
},
584 { "this", RID_THIS
, D_CXXONLY
| D_CXXWARN
},
585 { "thread_local", RID_THREAD
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
586 { "throw", RID_THROW
, D_CXX_OBJC
| D_CXXWARN
},
587 { "true", RID_TRUE
, D_CXXONLY
| D_CXXWARN
},
588 { "try", RID_TRY
, D_CXX_OBJC
| D_CXXWARN
},
589 { "typedef", RID_TYPEDEF
, 0 },
590 { "typename", RID_TYPENAME
, D_CXXONLY
| D_CXXWARN
},
591 { "typeid", RID_TYPEID
, D_CXXONLY
| D_CXXWARN
},
592 { "typeof", RID_TYPEOF
, D_ASM
| D_EXT
},
593 { "union", RID_UNION
, 0 },
594 { "unsigned", RID_UNSIGNED
, 0 },
595 { "using", RID_USING
, D_CXXONLY
| D_CXXWARN
},
596 { "virtual", RID_VIRTUAL
, D_CXXONLY
| D_CXXWARN
},
597 { "void", RID_VOID
, 0 },
598 { "volatile", RID_VOLATILE
, 0 },
599 { "wchar_t", RID_WCHAR
, D_CXXONLY
},
600 { "while", RID_WHILE
, 0 },
601 /* These Objective-C keywords are recognized only immediately after
603 { "compatibility_alias", RID_AT_ALIAS
, D_OBJC
},
604 { "defs", RID_AT_DEFS
, D_OBJC
},
605 { "encode", RID_AT_ENCODE
, D_OBJC
},
606 { "end", RID_AT_END
, D_OBJC
},
607 { "implementation", RID_AT_IMPLEMENTATION
, D_OBJC
},
608 { "interface", RID_AT_INTERFACE
, D_OBJC
},
609 { "protocol", RID_AT_PROTOCOL
, D_OBJC
},
610 { "selector", RID_AT_SELECTOR
, D_OBJC
},
611 { "finally", RID_AT_FINALLY
, D_OBJC
},
612 { "synchronized", RID_AT_SYNCHRONIZED
, D_OBJC
},
613 { "optional", RID_AT_OPTIONAL
, D_OBJC
},
614 { "required", RID_AT_REQUIRED
, D_OBJC
},
615 { "property", RID_AT_PROPERTY
, D_OBJC
},
616 { "package", RID_AT_PACKAGE
, D_OBJC
},
617 { "synthesize", RID_AT_SYNTHESIZE
, D_OBJC
},
618 { "dynamic", RID_AT_DYNAMIC
, D_OBJC
},
619 /* These are recognized only in protocol-qualifier context
621 { "bycopy", RID_BYCOPY
, D_OBJC
},
622 { "byref", RID_BYREF
, D_OBJC
},
623 { "in", RID_IN
, D_OBJC
},
624 { "inout", RID_INOUT
, D_OBJC
},
625 { "oneway", RID_ONEWAY
, D_OBJC
},
626 { "out", RID_OUT
, D_OBJC
},
627 /* These are recognized inside a property attribute list */
628 { "assign", RID_ASSIGN
, D_OBJC
},
629 { "copy", RID_COPY
, D_OBJC
},
630 { "getter", RID_GETTER
, D_OBJC
},
631 { "nonatomic", RID_NONATOMIC
, D_OBJC
},
632 { "readonly", RID_READONLY
, D_OBJC
},
633 { "readwrite", RID_READWRITE
, D_OBJC
},
634 { "retain", RID_RETAIN
, D_OBJC
},
635 { "setter", RID_SETTER
, D_OBJC
},
638 const unsigned int num_c_common_reswords
=
639 sizeof c_common_reswords
/ sizeof (struct c_common_resword
);
641 /* Table of machine-independent attributes common to all C-like languages.
643 All attributes referencing arguments should be additionally processed
644 in chkp_copy_function_type_adding_bounds for correct instrumentation
645 by Pointer Bounds Checker.
646 Current list of processed common attributes: nonnull. */
647 const struct attribute_spec c_common_attribute_table
[] =
649 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
650 affects_type_identity } */
651 { "packed", 0, 0, false, false, false,
652 handle_packed_attribute
, false},
653 { "nocommon", 0, 0, true, false, false,
654 handle_nocommon_attribute
, false},
655 { "common", 0, 0, true, false, false,
656 handle_common_attribute
, false },
657 /* FIXME: logically, noreturn attributes should be listed as
658 "false, true, true" and apply to function types. But implementing this
659 would require all the places in the compiler that use TREE_THIS_VOLATILE
660 on a decl to identify non-returning functions to be located and fixed
661 to check the function type instead. */
662 { "noreturn", 0, 0, true, false, false,
663 handle_noreturn_attribute
, false },
664 { "volatile", 0, 0, true, false, false,
665 handle_noreturn_attribute
, false },
666 { "stack_protect", 0, 0, true, false, false,
667 handle_stack_protect_attribute
, false },
668 { "noinline", 0, 0, true, false, false,
669 handle_noinline_attribute
, false },
670 { "noclone", 0, 0, true, false, false,
671 handle_noclone_attribute
, false },
672 { "no_icf", 0, 0, true, false, false,
673 handle_noicf_attribute
, false },
674 { "leaf", 0, 0, true, false, false,
675 handle_leaf_attribute
, false },
676 { "always_inline", 0, 0, true, false, false,
677 handle_always_inline_attribute
, false },
678 { "gnu_inline", 0, 0, true, false, false,
679 handle_gnu_inline_attribute
, false },
680 { "artificial", 0, 0, true, false, false,
681 handle_artificial_attribute
, false },
682 { "flatten", 0, 0, true, false, false,
683 handle_flatten_attribute
, false },
684 { "used", 0, 0, true, false, false,
685 handle_used_attribute
, false },
686 { "unused", 0, 0, false, false, false,
687 handle_unused_attribute
, false },
688 { "externally_visible", 0, 0, true, false, false,
689 handle_externally_visible_attribute
, false },
690 { "no_reorder", 0, 0, true, false, false,
691 handle_no_reorder_attribute
, false },
692 /* The same comments as for noreturn attributes apply to const ones. */
693 { "const", 0, 0, true, false, false,
694 handle_const_attribute
, false },
695 { "transparent_union", 0, 0, false, false, false,
696 handle_transparent_union_attribute
, false },
697 { "constructor", 0, 1, true, false, false,
698 handle_constructor_attribute
, false },
699 { "destructor", 0, 1, true, false, false,
700 handle_destructor_attribute
, false },
701 { "mode", 1, 1, false, true, false,
702 handle_mode_attribute
, false },
703 { "section", 1, 1, true, false, false,
704 handle_section_attribute
, false },
705 { "aligned", 0, 1, false, false, false,
706 handle_aligned_attribute
, false },
707 { "weak", 0, 0, true, false, false,
708 handle_weak_attribute
, false },
709 { "ifunc", 1, 1, true, false, false,
710 handle_ifunc_attribute
, false },
711 { "alias", 1, 1, true, false, false,
712 handle_alias_attribute
, false },
713 { "weakref", 0, 1, true, false, false,
714 handle_weakref_attribute
, false },
715 { "no_instrument_function", 0, 0, true, false, false,
716 handle_no_instrument_function_attribute
,
718 { "malloc", 0, 0, true, false, false,
719 handle_malloc_attribute
, false },
720 { "returns_twice", 0, 0, true, false, false,
721 handle_returns_twice_attribute
, false },
722 { "no_stack_limit", 0, 0, true, false, false,
723 handle_no_limit_stack_attribute
, false },
724 { "pure", 0, 0, true, false, false,
725 handle_pure_attribute
, false },
726 { "transaction_callable", 0, 0, false, true, false,
727 handle_tm_attribute
, false },
728 { "transaction_unsafe", 0, 0, false, true, false,
729 handle_tm_attribute
, false },
730 { "transaction_safe", 0, 0, false, true, false,
731 handle_tm_attribute
, false },
732 { "transaction_may_cancel_outer", 0, 0, false, true, false,
733 handle_tm_attribute
, false },
734 /* ??? These two attributes didn't make the transition from the
735 Intel language document to the multi-vendor language document. */
736 { "transaction_pure", 0, 0, false, true, false,
737 handle_tm_attribute
, false },
738 { "transaction_wrap", 1, 1, true, false, false,
739 handle_tm_wrap_attribute
, false },
740 /* For internal use (marking of builtins) only. The name contains space
741 to prevent its usage in source code. */
742 { "no vops", 0, 0, true, false, false,
743 handle_novops_attribute
, false },
744 { "deprecated", 0, 1, false, false, false,
745 handle_deprecated_attribute
, false },
746 { "vector_size", 1, 1, false, true, false,
747 handle_vector_size_attribute
, false },
748 { "visibility", 1, 1, false, false, false,
749 handle_visibility_attribute
, false },
750 { "tls_model", 1, 1, true, false, false,
751 handle_tls_model_attribute
, false },
752 { "nonnull", 0, -1, false, true, true,
753 handle_nonnull_attribute
, false },
754 { "nothrow", 0, 0, true, false, false,
755 handle_nothrow_attribute
, false },
756 { "may_alias", 0, 0, false, true, false, NULL
, false },
757 { "cleanup", 1, 1, true, false, false,
758 handle_cleanup_attribute
, false },
759 { "warn_unused_result", 0, 0, false, true, true,
760 handle_warn_unused_result_attribute
, false },
761 { "sentinel", 0, 1, false, true, true,
762 handle_sentinel_attribute
, false },
763 /* For internal use (marking of builtins) only. The name contains space
764 to prevent its usage in source code. */
765 { "type generic", 0, 0, false, true, true,
766 handle_type_generic_attribute
, false },
767 { "alloc_size", 1, 2, false, true, true,
768 handle_alloc_size_attribute
, false },
769 { "cold", 0, 0, true, false, false,
770 handle_cold_attribute
, false },
771 { "hot", 0, 0, true, false, false,
772 handle_hot_attribute
, false },
773 { "no_address_safety_analysis",
774 0, 0, true, false, false,
775 handle_no_address_safety_analysis_attribute
,
777 { "no_sanitize_address", 0, 0, true, false, false,
778 handle_no_sanitize_address_attribute
,
780 { "no_sanitize_thread", 0, 0, true, false, false,
781 handle_no_sanitize_address_attribute
,
783 { "no_sanitize_undefined", 0, 0, true, false, false,
784 handle_no_sanitize_undefined_attribute
,
786 { "warning", 1, 1, true, false, false,
787 handle_error_attribute
, false },
788 { "error", 1, 1, true, false, false,
789 handle_error_attribute
, false },
790 { "target", 1, -1, true, false, false,
791 handle_target_attribute
, false },
792 { "optimize", 1, -1, true, false, false,
793 handle_optimize_attribute
, false },
794 /* For internal use only. The leading '*' both prevents its usage in
795 source code and signals that it may be overridden by machine tables. */
796 { "*tm regparm", 0, 0, false, true, true,
797 ignore_attribute
, false },
798 { "no_split_stack", 0, 0, true, false, false,
799 handle_no_split_stack_attribute
, false },
800 /* For internal use (marking of builtins and runtime functions) only.
801 The name contains space to prevent its usage in source code. */
802 { "fn spec", 1, 1, false, true, true,
803 handle_fnspec_attribute
, false },
804 { "warn_unused", 0, 0, false, false, false,
805 handle_warn_unused_attribute
, false },
806 { "returns_nonnull", 0, 0, false, true, true,
807 handle_returns_nonnull_attribute
, false },
808 { "omp declare simd", 0, -1, true, false, false,
809 handle_omp_declare_simd_attribute
, false },
810 { "cilk simd function", 0, -1, true, false, false,
811 handle_omp_declare_simd_attribute
, false },
812 { "omp declare target", 0, 0, true, false, false,
813 handle_omp_declare_target_attribute
, false },
814 { "alloc_align", 1, 1, false, true, true,
815 handle_alloc_align_attribute
, false },
816 { "assume_aligned", 1, 2, false, true, true,
817 handle_assume_aligned_attribute
, false },
818 { "designated_init", 0, 0, false, true, false,
819 handle_designated_init_attribute
, false },
820 { "bnd_variable_size", 0, 0, true, false, false,
821 handle_bnd_variable_size_attribute
, false },
822 { "bnd_legacy", 0, 0, true, false, false,
823 handle_bnd_legacy
, false },
824 { "bnd_instrument", 0, 0, true, false, false,
825 handle_bnd_instrument
, false },
826 { NULL
, 0, 0, false, false, false, NULL
, false }
829 /* Give the specifications for the format attributes, used by C and all
832 All attributes referencing arguments should be additionally processed
833 in chkp_copy_function_type_adding_bounds for correct instrumentation
834 by Pointer Bounds Checker.
835 Current list of processed format attributes: format, format_arg. */
836 const struct attribute_spec c_common_format_attribute_table
[] =
838 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
839 affects_type_identity } */
840 { "format", 3, 3, false, true, true,
841 handle_format_attribute
, false },
842 { "format_arg", 1, 1, false, true, true,
843 handle_format_arg_attribute
, false },
844 { NULL
, 0, 0, false, false, false, NULL
, false }
847 /* Return identifier for address space AS. */
850 c_addr_space_name (addr_space_t as
)
852 int rid
= RID_FIRST_ADDR_SPACE
+ as
;
853 gcc_assert (ridpointers
[rid
]);
854 return IDENTIFIER_POINTER (ridpointers
[rid
]);
857 /* Push current bindings for the function name VAR_DECLS. */
860 start_fname_decls (void)
863 tree saved
= NULL_TREE
;
865 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
867 tree decl
= *fname_vars
[ix
].decl
;
871 saved
= tree_cons (decl
, build_int_cst (integer_type_node
, ix
),
873 *fname_vars
[ix
].decl
= NULL_TREE
;
876 if (saved
|| saved_function_name_decls
)
877 /* Normally they'll have been NULL, so only push if we've got a
878 stack, or they are non-NULL. */
879 saved_function_name_decls
= tree_cons (saved
, NULL_TREE
,
880 saved_function_name_decls
);
883 /* Finish up the current bindings, adding them into the current function's
884 statement tree. This must be done _before_ finish_stmt_tree is called.
885 If there is no current function, we must be at file scope and no statements
886 are involved. Pop the previous bindings. */
889 finish_fname_decls (void)
892 tree stmts
= NULL_TREE
;
893 tree stack
= saved_function_name_decls
;
895 for (; stack
&& TREE_VALUE (stack
); stack
= TREE_CHAIN (stack
))
896 append_to_statement_list (TREE_VALUE (stack
), &stmts
);
900 tree
*bodyp
= &DECL_SAVED_TREE (current_function_decl
);
902 if (TREE_CODE (*bodyp
) == BIND_EXPR
)
903 bodyp
= &BIND_EXPR_BODY (*bodyp
);
905 append_to_statement_list_force (*bodyp
, &stmts
);
909 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
910 *fname_vars
[ix
].decl
= NULL_TREE
;
914 /* We had saved values, restore them. */
917 for (saved
= TREE_PURPOSE (stack
); saved
; saved
= TREE_CHAIN (saved
))
919 tree decl
= TREE_PURPOSE (saved
);
920 unsigned ix
= TREE_INT_CST_LOW (TREE_VALUE (saved
));
922 *fname_vars
[ix
].decl
= decl
;
924 stack
= TREE_CHAIN (stack
);
926 saved_function_name_decls
= stack
;
929 /* Return the text name of the current function, suitably prettified
930 by PRETTY_P. Return string must be freed by caller. */
933 fname_as_string (int pretty_p
)
935 const char *name
= "top level";
938 cpp_string cstr
= { 0, 0 }, strname
;
946 if (current_function_decl
)
947 name
= lang_hooks
.decl_printable_name (current_function_decl
, vrb
);
949 len
= strlen (name
) + 3; /* Two for '"'s. One for NULL. */
951 namep
= XNEWVEC (char, len
);
952 snprintf (namep
, len
, "\"%s\"", name
);
953 strname
.text
= (unsigned char *) namep
;
954 strname
.len
= len
- 1;
956 if (cpp_interpret_string (parse_in
, &strname
, 1, &cstr
, CPP_STRING
))
959 return (const char *) cstr
.text
;
965 /* Return the VAR_DECL for a const char array naming the current
966 function. If the VAR_DECL has not yet been created, create it
967 now. RID indicates how it should be formatted and IDENTIFIER_NODE
968 ID is its name (unfortunately C and C++ hold the RID values of
969 keywords in different places, so we can't derive RID from ID in
970 this language independent code. LOC is the location of the
974 fname_decl (location_t loc
, unsigned int rid
, tree id
)
977 tree decl
= NULL_TREE
;
979 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
980 if (fname_vars
[ix
].rid
== rid
)
983 decl
= *fname_vars
[ix
].decl
;
986 /* If a tree is built here, it would normally have the lineno of
987 the current statement. Later this tree will be moved to the
988 beginning of the function and this line number will be wrong.
989 To avoid this problem set the lineno to 0 here; that prevents
990 it from appearing in the RTL. */
992 location_t saved_location
= input_location
;
993 input_location
= UNKNOWN_LOCATION
;
995 stmts
= push_stmt_list ();
996 decl
= (*make_fname_decl
) (loc
, id
, fname_vars
[ix
].pretty
);
997 stmts
= pop_stmt_list (stmts
);
998 if (!IS_EMPTY_STMT (stmts
))
999 saved_function_name_decls
1000 = tree_cons (decl
, stmts
, saved_function_name_decls
);
1001 *fname_vars
[ix
].decl
= decl
;
1002 input_location
= saved_location
;
1004 if (!ix
&& !current_function_decl
)
1005 pedwarn (loc
, 0, "%qD is not defined outside of function scope", decl
);
1010 /* Given a STRING_CST, give it a suitable array-of-chars data type. */
1013 fix_string_type (tree value
)
1015 int length
= TREE_STRING_LENGTH (value
);
1017 tree e_type
, i_type
, a_type
;
1019 /* Compute the number of elements, for the array type. */
1020 if (TREE_TYPE (value
) == char_array_type_node
|| !TREE_TYPE (value
))
1023 e_type
= char_type_node
;
1025 else if (TREE_TYPE (value
) == char16_array_type_node
)
1027 nchars
= length
/ (TYPE_PRECISION (char16_type_node
) / BITS_PER_UNIT
);
1028 e_type
= char16_type_node
;
1030 else if (TREE_TYPE (value
) == char32_array_type_node
)
1032 nchars
= length
/ (TYPE_PRECISION (char32_type_node
) / BITS_PER_UNIT
);
1033 e_type
= char32_type_node
;
1037 nchars
= length
/ (TYPE_PRECISION (wchar_type_node
) / BITS_PER_UNIT
);
1038 e_type
= wchar_type_node
;
1041 /* C89 2.2.4.1, C99 5.2.4.1 (Translation limits). The analogous
1042 limit in C++98 Annex B is very large (65536) and is not normative,
1043 so we do not diagnose it (warn_overlength_strings is forced off
1044 in c_common_post_options). */
1045 if (warn_overlength_strings
)
1047 const int nchars_max
= flag_isoc99
? 4095 : 509;
1048 const int relevant_std
= flag_isoc99
? 99 : 90;
1049 if (nchars
- 1 > nchars_max
)
1050 /* Translators: The %d after 'ISO C' will be 90 or 99. Do not
1051 separate the %d from the 'C'. 'ISO' should not be
1052 translated, but it may be moved after 'C%d' in languages
1053 where modifiers follow nouns. */
1054 pedwarn (input_location
, OPT_Woverlength_strings
,
1055 "string length %qd is greater than the length %qd "
1056 "ISO C%d compilers are required to support",
1057 nchars
- 1, nchars_max
, relevant_std
);
1060 /* Create the array type for the string constant. The ISO C++
1061 standard says that a string literal has type `const char[N]' or
1062 `const wchar_t[N]'. We use the same logic when invoked as a C
1063 front-end with -Wwrite-strings.
1064 ??? We should change the type of an expression depending on the
1065 state of a warning flag. We should just be warning -- see how
1066 this is handled in the C++ front-end for the deprecated implicit
1067 conversion from string literals to `char*' or `wchar_t*'.
1069 The C++ front end relies on TYPE_MAIN_VARIANT of a cv-qualified
1070 array type being the unqualified version of that type.
1071 Therefore, if we are constructing an array of const char, we must
1072 construct the matching unqualified array type first. The C front
1073 end does not require this, but it does no harm, so we do it
1075 i_type
= build_index_type (size_int (nchars
- 1));
1076 a_type
= build_array_type (e_type
, i_type
);
1077 if (c_dialect_cxx() || warn_write_strings
)
1078 a_type
= c_build_qualified_type (a_type
, TYPE_QUAL_CONST
);
1080 TREE_TYPE (value
) = a_type
;
1081 TREE_CONSTANT (value
) = 1;
1082 TREE_READONLY (value
) = 1;
1083 TREE_STATIC (value
) = 1;
1087 /* If DISABLE is true, stop issuing warnings. This is used when
1088 parsing code that we know will not be executed. This function may
1089 be called multiple times, and works as a stack. */
1092 c_disable_warnings (bool disable
)
1096 ++c_inhibit_evaluation_warnings
;
1097 fold_defer_overflow_warnings ();
1101 /* If ENABLE is true, reenable issuing warnings. */
1104 c_enable_warnings (bool enable
)
1108 --c_inhibit_evaluation_warnings
;
1109 fold_undefer_and_ignore_overflow_warnings ();
1113 /* Fully fold EXPR, an expression that was not folded (beyond integer
1114 constant expressions and null pointer constants) when being built
1115 up. If IN_INIT, this is in a static initializer and certain
1116 changes are made to the folding done. Clear *MAYBE_CONST if
1117 MAYBE_CONST is not NULL and EXPR is definitely not a constant
1118 expression because it contains an evaluated operator (in C99) or an
1119 operator outside of sizeof returning an integer constant (in C90)
1120 not permitted in constant expressions, or because it contains an
1121 evaluated arithmetic overflow. (*MAYBE_CONST should typically be
1122 set to true by callers before calling this function.) Return the
1123 folded expression. Function arguments have already been folded
1124 before calling this function, as have the contents of SAVE_EXPR,
1125 TARGET_EXPR, BIND_EXPR, VA_ARG_EXPR, OBJ_TYPE_REF and
1126 C_MAYBE_CONST_EXPR. */
1129 c_fully_fold (tree expr
, bool in_init
, bool *maybe_const
)
1132 tree eptype
= NULL_TREE
;
1134 bool maybe_const_itself
= true;
1135 location_t loc
= EXPR_LOCATION (expr
);
1137 /* This function is not relevant to C++ because C++ folds while
1138 parsing, and may need changes to be correct for C++ when C++
1139 stops folding while parsing. */
1140 if (c_dialect_cxx ())
1144 maybe_const
= &dummy
;
1145 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
1147 eptype
= TREE_TYPE (expr
);
1148 expr
= TREE_OPERAND (expr
, 0);
1150 ret
= c_fully_fold_internal (expr
, in_init
, maybe_const
,
1151 &maybe_const_itself
, false);
1153 ret
= fold_convert_loc (loc
, eptype
, ret
);
1154 *maybe_const
&= maybe_const_itself
;
1158 /* Internal helper for c_fully_fold. EXPR and IN_INIT are as for
1159 c_fully_fold. *MAYBE_CONST_OPERANDS is cleared because of operands
1160 not permitted, while *MAYBE_CONST_ITSELF is cleared because of
1161 arithmetic overflow (for C90, *MAYBE_CONST_OPERANDS is carried from
1162 both evaluated and unevaluated subexpressions while
1163 *MAYBE_CONST_ITSELF is carried from only evaluated
1164 subexpressions). FOR_INT_CONST indicates if EXPR is an expression
1165 with integer constant operands, and if any of the operands doesn't
1166 get folded to an integer constant, don't fold the expression itself. */
1169 c_fully_fold_internal (tree expr
, bool in_init
, bool *maybe_const_operands
,
1170 bool *maybe_const_itself
, bool for_int_const
)
1173 enum tree_code code
= TREE_CODE (expr
);
1174 enum tree_code_class kind
= TREE_CODE_CLASS (code
);
1175 location_t loc
= EXPR_LOCATION (expr
);
1176 tree op0
, op1
, op2
, op3
;
1177 tree orig_op0
, orig_op1
, orig_op2
;
1178 bool op0_const
= true, op1_const
= true, op2_const
= true;
1179 bool op0_const_self
= true, op1_const_self
= true, op2_const_self
= true;
1180 bool nowarning
= TREE_NO_WARNING (expr
);
1183 /* This function is not relevant to C++ because C++ folds while
1184 parsing, and may need changes to be correct for C++ when C++
1185 stops folding while parsing. */
1186 if (c_dialect_cxx ())
1189 /* Constants, declarations, statements, errors, SAVE_EXPRs and
1190 anything else not counted as an expression cannot usefully be
1191 folded further at this point. */
1192 if (!IS_EXPR_CODE_CLASS (kind
)
1193 || kind
== tcc_statement
1194 || code
== SAVE_EXPR
)
1197 /* Operands of variable-length expressions (function calls) have
1198 already been folded, as have __builtin_* function calls, and such
1199 expressions cannot occur in constant expressions. */
1200 if (kind
== tcc_vl_exp
)
1202 *maybe_const_operands
= false;
1207 if (code
== C_MAYBE_CONST_EXPR
)
1209 tree pre
= C_MAYBE_CONST_EXPR_PRE (expr
);
1210 tree inner
= C_MAYBE_CONST_EXPR_EXPR (expr
);
1211 if (C_MAYBE_CONST_EXPR_NON_CONST (expr
))
1212 *maybe_const_operands
= false;
1213 if (C_MAYBE_CONST_EXPR_INT_OPERANDS (expr
))
1215 *maybe_const_itself
= false;
1216 inner
= c_fully_fold_internal (inner
, in_init
, maybe_const_operands
,
1217 maybe_const_itself
, true);
1219 if (pre
&& !in_init
)
1220 ret
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr
), pre
, inner
);
1226 /* Assignment, increment, decrement, function call and comma
1227 operators, and statement expressions, cannot occur in constant
1228 expressions if evaluated / outside of sizeof. (Function calls
1229 were handled above, though VA_ARG_EXPR is treated like a function
1230 call here, and statement expressions are handled through
1231 C_MAYBE_CONST_EXPR to avoid folding inside them.) */
1235 case PREDECREMENT_EXPR
:
1236 case PREINCREMENT_EXPR
:
1237 case POSTDECREMENT_EXPR
:
1238 case POSTINCREMENT_EXPR
:
1240 *maybe_const_operands
= false;
1247 *maybe_const_operands
= false;
1255 /* Fold individual tree codes as appropriate. */
1258 case COMPOUND_LITERAL_EXPR
:
1259 /* Any non-constancy will have been marked in a containing
1260 C_MAYBE_CONST_EXPR; there is no more folding to do here. */
1264 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1265 op1
= TREE_OPERAND (expr
, 1);
1266 op2
= TREE_OPERAND (expr
, 2);
1267 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1268 maybe_const_itself
, for_int_const
);
1269 STRIP_TYPE_NOPS (op0
);
1270 if (op0
!= orig_op0
)
1271 ret
= build3 (COMPONENT_REF
, TREE_TYPE (expr
), op0
, op1
, op2
);
1274 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1275 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1280 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1281 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1282 op2
= TREE_OPERAND (expr
, 2);
1283 op3
= TREE_OPERAND (expr
, 3);
1284 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1285 maybe_const_itself
, for_int_const
);
1286 STRIP_TYPE_NOPS (op0
);
1287 op1
= c_fully_fold_internal (op1
, in_init
, maybe_const_operands
,
1288 maybe_const_itself
, for_int_const
);
1289 STRIP_TYPE_NOPS (op1
);
1290 op1
= decl_constant_value_for_optimization (op1
);
1291 if (op0
!= orig_op0
|| op1
!= orig_op1
)
1292 ret
= build4 (ARRAY_REF
, TREE_TYPE (expr
), op0
, op1
, op2
, op3
);
1295 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1296 TREE_SIDE_EFFECTS (ret
) = TREE_SIDE_EFFECTS (expr
);
1297 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1304 case PREDECREMENT_EXPR
:
1305 case PREINCREMENT_EXPR
:
1306 case POSTDECREMENT_EXPR
:
1307 case POSTINCREMENT_EXPR
:
1311 case POINTER_PLUS_EXPR
:
1312 case TRUNC_DIV_EXPR
:
1314 case FLOOR_DIV_EXPR
:
1315 case TRUNC_MOD_EXPR
:
1317 case EXACT_DIV_EXPR
:
1330 case TRUTH_AND_EXPR
:
1332 case TRUTH_XOR_EXPR
:
1333 case UNORDERED_EXPR
:
1340 /* Binary operations evaluating both arguments (increment and
1341 decrement are binary internally in GCC). */
1342 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1343 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1344 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1345 maybe_const_itself
, for_int_const
);
1346 STRIP_TYPE_NOPS (op0
);
1347 if (code
!= MODIFY_EXPR
1348 && code
!= PREDECREMENT_EXPR
1349 && code
!= PREINCREMENT_EXPR
1350 && code
!= POSTDECREMENT_EXPR
1351 && code
!= POSTINCREMENT_EXPR
)
1352 op0
= decl_constant_value_for_optimization (op0
);
1353 /* The RHS of a MODIFY_EXPR was fully folded when building that
1354 expression for the sake of conversion warnings. */
1355 if (code
!= MODIFY_EXPR
)
1356 op1
= c_fully_fold_internal (op1
, in_init
, maybe_const_operands
,
1357 maybe_const_itself
, for_int_const
);
1358 STRIP_TYPE_NOPS (op1
);
1359 op1
= decl_constant_value_for_optimization (op1
);
1361 if (for_int_const
&& (TREE_CODE (op0
) != INTEGER_CST
1362 || TREE_CODE (op1
) != INTEGER_CST
))
1365 if (op0
!= orig_op0
|| op1
!= orig_op1
|| in_init
)
1367 ? fold_build2_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
)
1368 : fold_build2_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
);
1371 if (TREE_OVERFLOW_P (ret
)
1372 && !TREE_OVERFLOW_P (op0
)
1373 && !TREE_OVERFLOW_P (op1
))
1374 overflow_warning (EXPR_LOCATION (expr
), ret
);
1375 if (code
== LSHIFT_EXPR
1376 && TREE_CODE (orig_op0
) != INTEGER_CST
1377 && TREE_CODE (TREE_TYPE (orig_op0
)) == INTEGER_TYPE
1378 && TREE_CODE (op0
) == INTEGER_CST
1379 && c_inhibit_evaluation_warnings
== 0
1380 && tree_int_cst_sgn (op0
) < 0)
1381 warning_at (loc
, OPT_Wshift_negative_value
,
1382 "left shift of negative value");
1383 if ((code
== LSHIFT_EXPR
|| code
== RSHIFT_EXPR
)
1384 && TREE_CODE (orig_op1
) != INTEGER_CST
1385 && TREE_CODE (op1
) == INTEGER_CST
1386 && (TREE_CODE (TREE_TYPE (orig_op0
)) == INTEGER_TYPE
1387 || TREE_CODE (TREE_TYPE (orig_op0
)) == FIXED_POINT_TYPE
)
1388 && TREE_CODE (TREE_TYPE (orig_op1
)) == INTEGER_TYPE
1389 && c_inhibit_evaluation_warnings
== 0)
1391 if (tree_int_cst_sgn (op1
) < 0)
1392 warning_at (loc
, OPT_Wshift_count_negative
,
1393 (code
== LSHIFT_EXPR
1394 ? G_("left shift count is negative")
1395 : G_("right shift count is negative")));
1396 else if (compare_tree_int (op1
,
1397 TYPE_PRECISION (TREE_TYPE (orig_op0
)))
1399 warning_at (loc
, OPT_Wshift_count_overflow
,
1400 (code
== LSHIFT_EXPR
1401 ? G_("left shift count >= width of type")
1402 : G_("right shift count >= width of type")));
1404 if ((code
== TRUNC_DIV_EXPR
1405 || code
== CEIL_DIV_EXPR
1406 || code
== FLOOR_DIV_EXPR
1407 || code
== EXACT_DIV_EXPR
1408 || code
== TRUNC_MOD_EXPR
)
1409 && TREE_CODE (orig_op1
) != INTEGER_CST
1410 && TREE_CODE (op1
) == INTEGER_CST
1411 && (TREE_CODE (TREE_TYPE (orig_op0
)) == INTEGER_TYPE
1412 || TREE_CODE (TREE_TYPE (orig_op0
)) == FIXED_POINT_TYPE
)
1413 && TREE_CODE (TREE_TYPE (orig_op1
)) == INTEGER_TYPE
)
1414 warn_for_div_by_zero (loc
, op1
);
1418 case FIX_TRUNC_EXPR
:
1421 case ADDR_SPACE_CONVERT_EXPR
:
1422 case VIEW_CONVERT_EXPR
:
1423 case NON_LVALUE_EXPR
:
1426 case TRUTH_NOT_EXPR
:
1431 /* Unary operations. */
1432 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1433 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1434 maybe_const_itself
, for_int_const
);
1435 STRIP_TYPE_NOPS (op0
);
1436 if (code
!= ADDR_EXPR
&& code
!= REALPART_EXPR
&& code
!= IMAGPART_EXPR
)
1437 op0
= decl_constant_value_for_optimization (op0
);
1439 if (for_int_const
&& TREE_CODE (op0
) != INTEGER_CST
)
1442 /* ??? Cope with user tricks that amount to offsetof. The middle-end is
1443 not prepared to deal with them if they occur in initializers. */
1445 && code
== ADDR_EXPR
1446 && (op1
= get_base_address (op0
)) != NULL_TREE
1447 && TREE_CODE (op1
) == INDIRECT_REF
1448 && TREE_CONSTANT (TREE_OPERAND (op1
, 0)))
1449 ret
= fold_convert_loc (loc
, TREE_TYPE (expr
), fold_offsetof_1 (op0
));
1450 else if (op0
!= orig_op0
|| in_init
)
1452 ? fold_build1_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
)
1453 : fold_build1_loc (loc
, code
, TREE_TYPE (expr
), op0
);
1456 if (code
== INDIRECT_REF
1458 && TREE_CODE (ret
) == INDIRECT_REF
)
1460 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1461 TREE_SIDE_EFFECTS (ret
) = TREE_SIDE_EFFECTS (expr
);
1462 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1466 case FIX_TRUNC_EXPR
:
1469 /* Don't warn about explicit conversions. We will already
1470 have warned about suspect implicit conversions. */
1474 if (TREE_OVERFLOW_P (ret
) && !TREE_OVERFLOW_P (op0
))
1475 overflow_warning (EXPR_LOCATION (expr
), ret
);
1480 case TRUTH_ANDIF_EXPR
:
1481 case TRUTH_ORIF_EXPR
:
1482 /* Binary operations not necessarily evaluating both
1484 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1485 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1486 op0
= c_fully_fold_internal (op0
, in_init
, &op0_const
, &op0_const_self
,
1488 STRIP_TYPE_NOPS (op0
);
1490 unused_p
= (op0
== (code
== TRUTH_ANDIF_EXPR
1491 ? truthvalue_false_node
1492 : truthvalue_true_node
));
1493 c_disable_warnings (unused_p
);
1494 op1
= c_fully_fold_internal (op1
, in_init
, &op1_const
, &op1_const_self
,
1496 STRIP_TYPE_NOPS (op1
);
1497 c_enable_warnings (unused_p
);
1500 && (TREE_CODE (op0
) != INTEGER_CST
1501 /* Require OP1 be an INTEGER_CST only if it's evaluated. */
1502 || (!unused_p
&& TREE_CODE (op1
) != INTEGER_CST
)))
1505 if (op0
!= orig_op0
|| op1
!= orig_op1
|| in_init
)
1507 ? fold_build2_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
)
1508 : fold_build2_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
);
1511 *maybe_const_operands
&= op0_const
;
1512 *maybe_const_itself
&= op0_const_self
;
1516 && (code
== TRUTH_ANDIF_EXPR
1517 ? op0
== truthvalue_false_node
1518 : op0
== truthvalue_true_node
)))
1519 *maybe_const_operands
&= op1_const
;
1522 && (code
== TRUTH_ANDIF_EXPR
1523 ? op0
== truthvalue_false_node
1524 : op0
== truthvalue_true_node
)))
1525 *maybe_const_itself
&= op1_const_self
;
1529 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1530 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1531 orig_op2
= op2
= TREE_OPERAND (expr
, 2);
1532 op0
= c_fully_fold_internal (op0
, in_init
, &op0_const
, &op0_const_self
,
1535 STRIP_TYPE_NOPS (op0
);
1536 c_disable_warnings (op0
== truthvalue_false_node
);
1537 op1
= c_fully_fold_internal (op1
, in_init
, &op1_const
, &op1_const_self
,
1539 STRIP_TYPE_NOPS (op1
);
1540 c_enable_warnings (op0
== truthvalue_false_node
);
1542 c_disable_warnings (op0
== truthvalue_true_node
);
1543 op2
= c_fully_fold_internal (op2
, in_init
, &op2_const
, &op2_const_self
,
1545 STRIP_TYPE_NOPS (op2
);
1546 c_enable_warnings (op0
== truthvalue_true_node
);
1549 && (TREE_CODE (op0
) != INTEGER_CST
1550 /* Only the evaluated operand must be an INTEGER_CST. */
1551 || (op0
== truthvalue_true_node
1552 ? TREE_CODE (op1
) != INTEGER_CST
1553 : TREE_CODE (op2
) != INTEGER_CST
)))
1556 if (op0
!= orig_op0
|| op1
!= orig_op1
|| op2
!= orig_op2
)
1557 ret
= fold_build3_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
, op2
);
1560 *maybe_const_operands
&= op0_const
;
1561 *maybe_const_itself
&= op0_const_self
;
1565 && op0
== truthvalue_false_node
))
1566 *maybe_const_operands
&= op1_const
;
1569 && op0
== truthvalue_false_node
))
1570 *maybe_const_itself
&= op1_const_self
;
1574 && op0
== truthvalue_true_node
))
1575 *maybe_const_operands
&= op2_const
;
1578 && op0
== truthvalue_true_node
))
1579 *maybe_const_itself
&= op2_const_self
;
1582 case EXCESS_PRECISION_EXPR
:
1583 /* Each case where an operand with excess precision may be
1584 encountered must remove the EXCESS_PRECISION_EXPR around
1585 inner operands and possibly put one around the whole
1586 expression or possibly convert to the semantic type (which
1587 c_fully_fold does); we cannot tell at this stage which is
1588 appropriate in any particular case. */
1592 /* Various codes may appear through folding built-in functions
1593 and their arguments. */
1598 /* Some folding may introduce NON_LVALUE_EXPRs; all lvalue checks
1599 have been done by this point, so remove them again. */
1600 nowarning
|= TREE_NO_WARNING (ret
);
1601 STRIP_TYPE_NOPS (ret
);
1602 if (nowarning
&& !TREE_NO_WARNING (ret
))
1604 if (!CAN_HAVE_LOCATION_P (ret
))
1605 ret
= build1 (NOP_EXPR
, TREE_TYPE (ret
), ret
);
1606 TREE_NO_WARNING (ret
) = 1;
1609 protected_set_expr_location (ret
, loc
);
1613 /* If not optimizing, EXP is not a VAR_DECL, or EXP has array type,
1614 return EXP. Otherwise, return either EXP or its known constant
1615 value (if it has one), but return EXP if EXP has mode BLKmode. ???
1616 Is the BLKmode test appropriate? */
1619 decl_constant_value_for_optimization (tree exp
)
1623 /* This function is only used by C, for c_fully_fold and other
1624 optimization, and may not be correct for C++. */
1625 if (c_dialect_cxx ())
1629 || TREE_CODE (exp
) != VAR_DECL
1630 || TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
1631 || DECL_MODE (exp
) == BLKmode
)
1634 ret
= decl_constant_value (exp
);
1635 /* Avoid unwanted tree sharing between the initializer and current
1636 function's body where the tree can be modified e.g. by the
1638 if (ret
!= exp
&& TREE_STATIC (exp
))
1639 ret
= unshare_expr (ret
);
1643 /* Print a warning if a constant expression had overflow in folding.
1644 Invoke this function on every expression that the language
1645 requires to be a constant expression.
1646 Note the ANSI C standard says it is erroneous for a
1647 constant expression to overflow. */
1650 constant_expression_warning (tree value
)
1652 if (warn_overflow
&& pedantic
1653 && (TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1654 || TREE_CODE (value
) == FIXED_CST
1655 || TREE_CODE (value
) == VECTOR_CST
1656 || TREE_CODE (value
) == COMPLEX_CST
)
1657 && TREE_OVERFLOW (value
))
1658 pedwarn (input_location
, OPT_Woverflow
, "overflow in constant expression");
1661 /* The same as above but print an unconditional error. */
1663 constant_expression_error (tree value
)
1665 if ((TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1666 || TREE_CODE (value
) == FIXED_CST
1667 || TREE_CODE (value
) == VECTOR_CST
1668 || TREE_CODE (value
) == COMPLEX_CST
)
1669 && TREE_OVERFLOW (value
))
1670 error ("overflow in constant expression");
1673 /* Print a warning if an expression had overflow in folding and its
1676 Invoke this function on every expression that
1677 (1) appears in the source code, and
1678 (2) is a constant expression that overflowed, and
1679 (3) is not already checked by convert_and_check;
1680 however, do not invoke this function on operands of explicit casts
1681 or when the expression is the result of an operator and any operand
1682 already overflowed. */
1685 overflow_warning (location_t loc
, tree value
)
1687 if (c_inhibit_evaluation_warnings
!= 0)
1690 switch (TREE_CODE (value
))
1693 warning_at (loc
, OPT_Woverflow
, "integer overflow in expression");
1697 warning_at (loc
, OPT_Woverflow
,
1698 "floating point overflow in expression");
1702 warning_at (loc
, OPT_Woverflow
, "fixed-point overflow in expression");
1706 warning_at (loc
, OPT_Woverflow
, "vector overflow in expression");
1710 if (TREE_CODE (TREE_REALPART (value
)) == INTEGER_CST
)
1711 warning_at (loc
, OPT_Woverflow
,
1712 "complex integer overflow in expression");
1713 else if (TREE_CODE (TREE_REALPART (value
)) == REAL_CST
)
1714 warning_at (loc
, OPT_Woverflow
,
1715 "complex floating point overflow in expression");
1723 /* Warn about uses of logical || / && operator in a context where it
1724 is likely that the bitwise equivalent was intended by the
1725 programmer. We have seen an expression in which CODE is a binary
1726 operator used to combine expressions OP_LEFT and OP_RIGHT, which before folding
1727 had CODE_LEFT and CODE_RIGHT, into an expression of type TYPE. */
1729 warn_logical_operator (location_t location
, enum tree_code code
, tree type
,
1730 enum tree_code code_left
, tree op_left
,
1731 enum tree_code
ARG_UNUSED (code_right
), tree op_right
)
1733 int or_op
= (code
== TRUTH_ORIF_EXPR
|| code
== TRUTH_OR_EXPR
);
1734 int in0_p
, in1_p
, in_p
;
1735 tree low0
, low1
, low
, high0
, high1
, high
, lhs
, rhs
, tem
;
1736 bool strict_overflow_p
= false;
1738 if (code
!= TRUTH_ANDIF_EXPR
1739 && code
!= TRUTH_AND_EXPR
1740 && code
!= TRUTH_ORIF_EXPR
1741 && code
!= TRUTH_OR_EXPR
)
1744 /* We don't want to warn if either operand comes from a macro
1745 expansion. ??? This doesn't work with e.g. NEGATE_EXPR yet;
1747 if (from_macro_expansion_at (EXPR_LOCATION (op_left
))
1748 || from_macro_expansion_at (EXPR_LOCATION (op_right
)))
1751 /* Warn if &&/|| are being used in a context where it is
1752 likely that the bitwise equivalent was intended by the
1753 programmer. That is, an expression such as op && MASK
1754 where op should not be any boolean expression, nor a
1755 constant, and mask seems to be a non-boolean integer constant. */
1756 if (!truth_value_p (code_left
)
1757 && INTEGRAL_TYPE_P (TREE_TYPE (op_left
))
1758 && !CONSTANT_CLASS_P (op_left
)
1759 && !TREE_NO_WARNING (op_left
)
1760 && TREE_CODE (op_right
) == INTEGER_CST
1761 && !integer_zerop (op_right
)
1762 && !integer_onep (op_right
))
1765 warning_at (location
, OPT_Wlogical_op
, "logical %<or%>"
1766 " applied to non-boolean constant");
1768 warning_at (location
, OPT_Wlogical_op
, "logical %<and%>"
1769 " applied to non-boolean constant");
1770 TREE_NO_WARNING (op_left
) = true;
1774 /* We do not warn for constants because they are typical of macro
1775 expansions that test for features. */
1776 if (CONSTANT_CLASS_P (op_left
) || CONSTANT_CLASS_P (op_right
))
1779 /* This warning only makes sense with logical operands. */
1780 if (!(truth_value_p (TREE_CODE (op_left
))
1781 || INTEGRAL_TYPE_P (TREE_TYPE (op_left
)))
1782 || !(truth_value_p (TREE_CODE (op_right
))
1783 || INTEGRAL_TYPE_P (TREE_TYPE (op_right
))))
1786 /* The range computations only work with scalars. */
1787 if (VECTOR_TYPE_P (TREE_TYPE (op_left
))
1788 || VECTOR_TYPE_P (TREE_TYPE (op_right
)))
1791 /* We first test whether either side separately is trivially true
1792 (with OR) or trivially false (with AND). If so, do not warn.
1793 This is a common idiom for testing ranges of data types in
1795 lhs
= make_range (op_left
, &in0_p
, &low0
, &high0
, &strict_overflow_p
);
1798 if (TREE_CODE (lhs
) == C_MAYBE_CONST_EXPR
)
1799 lhs
= C_MAYBE_CONST_EXPR_EXPR (lhs
);
1801 /* If this is an OR operation, invert both sides; now, the result
1802 should be always false to get a warning. */
1806 tem
= build_range_check (UNKNOWN_LOCATION
, type
, lhs
, in0_p
, low0
, high0
);
1807 if (tem
&& integer_zerop (tem
))
1810 rhs
= make_range (op_right
, &in1_p
, &low1
, &high1
, &strict_overflow_p
);
1813 if (TREE_CODE (rhs
) == C_MAYBE_CONST_EXPR
)
1814 rhs
= C_MAYBE_CONST_EXPR_EXPR (rhs
);
1816 /* If this is an OR operation, invert both sides; now, the result
1817 should be always false to get a warning. */
1821 tem
= build_range_check (UNKNOWN_LOCATION
, type
, rhs
, in1_p
, low1
, high1
);
1822 if (tem
&& integer_zerop (tem
))
1825 /* If both expressions have the same operand, if we can merge the
1827 if (operand_equal_p (lhs
, rhs
, 0)
1828 && merge_ranges (&in_p
, &low
, &high
, in0_p
, low0
, high0
,
1829 in1_p
, low1
, high1
))
1831 tem
= build_range_check (UNKNOWN_LOCATION
, type
, lhs
, in_p
, low
, high
);
1832 /* ... and if the range test is always false, then warn. */
1833 if (tem
&& integer_zerop (tem
))
1836 warning_at (location
, OPT_Wlogical_op
,
1837 "logical %<or%> of collectively exhaustive tests is "
1840 warning_at (location
, OPT_Wlogical_op
,
1841 "logical %<and%> of mutually exclusive tests is "
1844 /* Or warn if the operands have exactly the same range, e.g.
1846 else if (low0
== low1
&& high0
== high1
)
1849 warning_at (location
, OPT_Wlogical_op
,
1850 "logical %<or%> of equal expressions");
1852 warning_at (location
, OPT_Wlogical_op
,
1853 "logical %<and%> of equal expressions");
1858 /* Warn about logical not used on the left hand side operand of a comparison.
1859 This function assumes that the LHS is inside of TRUTH_NOT_EXPR.
1860 Do not warn if RHS is of a boolean type. */
1863 warn_logical_not_parentheses (location_t location
, enum tree_code code
,
1866 if (TREE_CODE_CLASS (code
) != tcc_comparison
1867 || TREE_TYPE (rhs
) == NULL_TREE
1868 || TREE_CODE (TREE_TYPE (rhs
)) == BOOLEAN_TYPE
)
1871 /* Don't warn for !x == 0 or !y != 0, those are equivalent to
1872 !(x == 0) or !(y != 0). */
1873 if ((code
== EQ_EXPR
|| code
== NE_EXPR
)
1874 && integer_zerop (rhs
))
1877 warning_at (location
, OPT_Wlogical_not_parentheses
,
1878 "logical not is only applied to the left hand side of "
1882 /* Warn if EXP contains any computations whose results are not used.
1883 Return true if a warning is printed; false otherwise. LOCUS is the
1884 (potential) location of the expression. */
1887 warn_if_unused_value (const_tree exp
, location_t locus
)
1890 if (TREE_USED (exp
) || TREE_NO_WARNING (exp
))
1893 /* Don't warn about void constructs. This includes casting to void,
1894 void function calls, and statement expressions with a final cast
1896 if (VOID_TYPE_P (TREE_TYPE (exp
)))
1899 if (EXPR_HAS_LOCATION (exp
))
1900 locus
= EXPR_LOCATION (exp
);
1902 switch (TREE_CODE (exp
))
1904 case PREINCREMENT_EXPR
:
1905 case POSTINCREMENT_EXPR
:
1906 case PREDECREMENT_EXPR
:
1907 case POSTDECREMENT_EXPR
:
1912 case TRY_CATCH_EXPR
:
1913 case WITH_CLEANUP_EXPR
:
1919 /* For a binding, warn if no side effect within it. */
1920 exp
= BIND_EXPR_BODY (exp
);
1924 case NON_LVALUE_EXPR
:
1926 exp
= TREE_OPERAND (exp
, 0);
1929 case TRUTH_ORIF_EXPR
:
1930 case TRUTH_ANDIF_EXPR
:
1931 /* In && or ||, warn if 2nd operand has no side effect. */
1932 exp
= TREE_OPERAND (exp
, 1);
1936 if (warn_if_unused_value (TREE_OPERAND (exp
, 0), locus
))
1938 /* Let people do `(foo (), 0)' without a warning. */
1939 if (TREE_CONSTANT (TREE_OPERAND (exp
, 1)))
1941 exp
= TREE_OPERAND (exp
, 1);
1945 /* If this is an expression with side effects, don't warn; this
1946 case commonly appears in macro expansions. */
1947 if (TREE_SIDE_EFFECTS (exp
))
1952 /* Don't warn about automatic dereferencing of references, since
1953 the user cannot control it. */
1954 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == REFERENCE_TYPE
)
1956 exp
= TREE_OPERAND (exp
, 0);
1962 /* Referencing a volatile value is a side effect, so don't warn. */
1963 if ((DECL_P (exp
) || REFERENCE_CLASS_P (exp
))
1964 && TREE_THIS_VOLATILE (exp
))
1967 /* If this is an expression which has no operands, there is no value
1968 to be unused. There are no such language-independent codes,
1969 but front ends may define such. */
1970 if (EXPRESSION_CLASS_P (exp
) && TREE_OPERAND_LENGTH (exp
) == 0)
1974 return warning_at (locus
, OPT_Wunused_value
, "value computed is not used");
1979 /* Print a warning about casts that might indicate violation
1980 of strict aliasing rules if -Wstrict-aliasing is used and
1981 strict aliasing mode is in effect. OTYPE is the original
1982 TREE_TYPE of EXPR, and TYPE the type we're casting to. */
1985 strict_aliasing_warning (tree otype
, tree type
, tree expr
)
1987 /* Strip pointer conversion chains and get to the correct original type. */
1989 otype
= TREE_TYPE (expr
);
1991 if (!(flag_strict_aliasing
1992 && POINTER_TYPE_P (type
)
1993 && POINTER_TYPE_P (otype
)
1994 && !VOID_TYPE_P (TREE_TYPE (type
)))
1995 /* If the type we are casting to is a ref-all pointer
1996 dereferencing it is always valid. */
1997 || TYPE_REF_CAN_ALIAS_ALL (type
))
2000 if ((warn_strict_aliasing
> 1) && TREE_CODE (expr
) == ADDR_EXPR
2001 && (DECL_P (TREE_OPERAND (expr
, 0))
2002 || handled_component_p (TREE_OPERAND (expr
, 0))))
2004 /* Casting the address of an object to non void pointer. Warn
2005 if the cast breaks type based aliasing. */
2006 if (!COMPLETE_TYPE_P (TREE_TYPE (type
)) && warn_strict_aliasing
== 2)
2008 warning (OPT_Wstrict_aliasing
, "type-punning to incomplete type "
2009 "might break strict-aliasing rules");
2014 /* warn_strict_aliasing >= 3. This includes the default (3).
2015 Only warn if the cast is dereferenced immediately. */
2016 alias_set_type set1
=
2017 get_alias_set (TREE_TYPE (TREE_OPERAND (expr
, 0)));
2018 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
2020 if (set1
!= set2
&& set2
!= 0
2021 && (set1
== 0 || !alias_sets_conflict_p (set1
, set2
)))
2023 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
2024 "pointer will break strict-aliasing rules");
2027 else if (warn_strict_aliasing
== 2
2028 && !alias_sets_must_conflict_p (set1
, set2
))
2030 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
2031 "pointer might break strict-aliasing rules");
2037 if ((warn_strict_aliasing
== 1) && !VOID_TYPE_P (TREE_TYPE (otype
)))
2039 /* At this level, warn for any conversions, even if an address is
2040 not taken in the same statement. This will likely produce many
2041 false positives, but could be useful to pinpoint problems that
2042 are not revealed at higher levels. */
2043 alias_set_type set1
= get_alias_set (TREE_TYPE (otype
));
2044 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
2045 if (!COMPLETE_TYPE_P (type
)
2046 || !alias_sets_must_conflict_p (set1
, set2
))
2048 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
2049 "pointer might break strict-aliasing rules");
2057 /* Warn about memset (&a, 0, sizeof (&a)); and similar mistakes with
2058 sizeof as last operand of certain builtins. */
2061 sizeof_pointer_memaccess_warning (location_t
*sizeof_arg_loc
, tree callee
,
2062 vec
<tree
, va_gc
> *params
, tree
*sizeof_arg
,
2063 bool (*comp_types
) (tree
, tree
))
2065 tree type
, dest
= NULL_TREE
, src
= NULL_TREE
, tem
;
2066 bool strop
= false, cmp
= false;
2067 unsigned int idx
= ~0;
2070 if (TREE_CODE (callee
) != FUNCTION_DECL
2071 || DECL_BUILT_IN_CLASS (callee
) != BUILT_IN_NORMAL
2072 || vec_safe_length (params
) <= 1)
2075 switch (DECL_FUNCTION_CODE (callee
))
2077 case BUILT_IN_STRNCMP
:
2078 case BUILT_IN_STRNCASECMP
:
2081 case BUILT_IN_STRNCPY
:
2082 case BUILT_IN_STRNCPY_CHK
:
2083 case BUILT_IN_STRNCAT
:
2084 case BUILT_IN_STRNCAT_CHK
:
2085 case BUILT_IN_STPNCPY
:
2086 case BUILT_IN_STPNCPY_CHK
:
2089 case BUILT_IN_MEMCPY
:
2090 case BUILT_IN_MEMCPY_CHK
:
2091 case BUILT_IN_MEMMOVE
:
2092 case BUILT_IN_MEMMOVE_CHK
:
2093 if (params
->length () < 3)
2096 dest
= (*params
)[0];
2099 case BUILT_IN_BCOPY
:
2100 if (params
->length () < 3)
2103 dest
= (*params
)[1];
2106 case BUILT_IN_MEMCMP
:
2108 if (params
->length () < 3)
2111 dest
= (*params
)[0];
2115 case BUILT_IN_MEMSET
:
2116 case BUILT_IN_MEMSET_CHK
:
2117 if (params
->length () < 3)
2119 dest
= (*params
)[0];
2122 case BUILT_IN_BZERO
:
2123 dest
= (*params
)[0];
2126 case BUILT_IN_STRNDUP
:
2131 case BUILT_IN_MEMCHR
:
2132 if (params
->length () < 3)
2137 case BUILT_IN_SNPRINTF
:
2138 case BUILT_IN_SNPRINTF_CHK
:
2139 case BUILT_IN_VSNPRINTF
:
2140 case BUILT_IN_VSNPRINTF_CHK
:
2141 dest
= (*params
)[0];
2152 if (sizeof_arg
[idx
] == NULL
|| sizeof_arg
[idx
] == error_mark_node
)
2155 type
= TYPE_P (sizeof_arg
[idx
])
2156 ? sizeof_arg
[idx
] : TREE_TYPE (sizeof_arg
[idx
]);
2157 if (!POINTER_TYPE_P (type
))
2161 && (tem
= tree_strip_nop_conversions (dest
))
2162 && POINTER_TYPE_P (TREE_TYPE (tem
))
2163 && comp_types (TREE_TYPE (TREE_TYPE (tem
)), type
))
2167 && (tem
= tree_strip_nop_conversions (src
))
2168 && POINTER_TYPE_P (TREE_TYPE (tem
))
2169 && comp_types (TREE_TYPE (TREE_TYPE (tem
)), type
))
2172 loc
= sizeof_arg_loc
[idx
];
2176 if (!TYPE_P (sizeof_arg
[idx
])
2177 && operand_equal_p (dest
, sizeof_arg
[idx
], 0)
2178 && comp_types (TREE_TYPE (dest
), type
))
2180 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2181 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2182 "argument to %<sizeof%> in %qD call is the same "
2183 "expression as the destination; did you mean to "
2184 "remove the addressof?", callee
);
2185 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2186 == TYPE_PRECISION (char_type_node
))
2188 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2189 "argument to %<sizeof%> in %qD call is the same "
2190 "expression as the destination; did you mean to "
2191 "provide an explicit length?", callee
);
2193 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2194 "argument to %<sizeof%> in %qD call is the same "
2195 "expression as the destination; did you mean to "
2196 "dereference it?", callee
);
2200 if (POINTER_TYPE_P (TREE_TYPE (dest
))
2202 && comp_types (TREE_TYPE (dest
), type
)
2203 && !VOID_TYPE_P (TREE_TYPE (type
)))
2205 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2206 "argument to %<sizeof%> in %qD call is the same "
2207 "pointer type %qT as the destination; expected %qT "
2208 "or an explicit length", callee
, TREE_TYPE (dest
),
2209 TREE_TYPE (TREE_TYPE (dest
)));
2216 if (!TYPE_P (sizeof_arg
[idx
])
2217 && operand_equal_p (src
, sizeof_arg
[idx
], 0)
2218 && comp_types (TREE_TYPE (src
), type
))
2220 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2221 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2222 "argument to %<sizeof%> in %qD call is the same "
2223 "expression as the source; did you mean to "
2224 "remove the addressof?", callee
);
2225 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2226 == TYPE_PRECISION (char_type_node
))
2228 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2229 "argument to %<sizeof%> in %qD call is the same "
2230 "expression as the source; did you mean to "
2231 "provide an explicit length?", callee
);
2233 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2234 "argument to %<sizeof%> in %qD call is the same "
2235 "expression as the source; did you mean to "
2236 "dereference it?", callee
);
2240 if (POINTER_TYPE_P (TREE_TYPE (src
))
2242 && comp_types (TREE_TYPE (src
), type
)
2243 && !VOID_TYPE_P (TREE_TYPE (type
)))
2245 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2246 "argument to %<sizeof%> in %qD call is the same "
2247 "pointer type %qT as the source; expected %qT "
2248 "or an explicit length", callee
, TREE_TYPE (src
),
2249 TREE_TYPE (TREE_TYPE (src
)));
2256 if (!TYPE_P (sizeof_arg
[idx
])
2257 && operand_equal_p (dest
, sizeof_arg
[idx
], 0)
2258 && comp_types (TREE_TYPE (dest
), type
))
2260 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2261 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2262 "argument to %<sizeof%> in %qD call is the same "
2263 "expression as the first source; did you mean to "
2264 "remove the addressof?", callee
);
2265 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2266 == TYPE_PRECISION (char_type_node
))
2268 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2269 "argument to %<sizeof%> in %qD call is the same "
2270 "expression as the first source; did you mean to "
2271 "provide an explicit length?", callee
);
2273 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2274 "argument to %<sizeof%> in %qD call is the same "
2275 "expression as the first source; did you mean to "
2276 "dereference it?", callee
);
2280 if (POINTER_TYPE_P (TREE_TYPE (dest
))
2282 && comp_types (TREE_TYPE (dest
), type
)
2283 && !VOID_TYPE_P (TREE_TYPE (type
)))
2285 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2286 "argument to %<sizeof%> in %qD call is the same "
2287 "pointer type %qT as the first source; expected %qT "
2288 "or an explicit length", callee
, TREE_TYPE (dest
),
2289 TREE_TYPE (TREE_TYPE (dest
)));
2296 if (!TYPE_P (sizeof_arg
[idx
])
2297 && operand_equal_p (src
, sizeof_arg
[idx
], 0)
2298 && comp_types (TREE_TYPE (src
), type
))
2300 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2301 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2302 "argument to %<sizeof%> in %qD call is the same "
2303 "expression as the second source; did you mean to "
2304 "remove the addressof?", callee
);
2305 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2306 == TYPE_PRECISION (char_type_node
))
2308 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2309 "argument to %<sizeof%> in %qD call is the same "
2310 "expression as the second source; did you mean to "
2311 "provide an explicit length?", callee
);
2313 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2314 "argument to %<sizeof%> in %qD call is the same "
2315 "expression as the second source; did you mean to "
2316 "dereference it?", callee
);
2320 if (POINTER_TYPE_P (TREE_TYPE (src
))
2322 && comp_types (TREE_TYPE (src
), type
)
2323 && !VOID_TYPE_P (TREE_TYPE (type
)))
2325 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2326 "argument to %<sizeof%> in %qD call is the same "
2327 "pointer type %qT as the second source; expected %qT "
2328 "or an explicit length", callee
, TREE_TYPE (src
),
2329 TREE_TYPE (TREE_TYPE (src
)));
2336 /* Warn for unlikely, improbable, or stupid DECL declarations
2340 check_main_parameter_types (tree decl
)
2342 function_args_iterator iter
;
2346 FOREACH_FUNCTION_ARGS (TREE_TYPE (decl
), type
, iter
)
2348 /* XXX void_type_node belies the abstraction. */
2349 if (type
== void_type_node
|| type
== error_mark_node
)
2353 if (TYPE_ATOMIC (t
))
2354 pedwarn (input_location
, OPT_Wmain
,
2355 "%<_Atomic%>-qualified parameter type %qT of %q+D",
2357 while (POINTER_TYPE_P (t
))
2360 if (TYPE_ATOMIC (t
))
2361 pedwarn (input_location
, OPT_Wmain
,
2362 "%<_Atomic%>-qualified parameter type %qT of %q+D",
2370 if (TYPE_MAIN_VARIANT (type
) != integer_type_node
)
2371 pedwarn (input_location
, OPT_Wmain
,
2372 "first argument of %q+D should be %<int%>", decl
);
2376 if (TREE_CODE (type
) != POINTER_TYPE
2377 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
2378 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
2380 pedwarn (input_location
, OPT_Wmain
,
2381 "second argument of %q+D should be %<char **%>", decl
);
2385 if (TREE_CODE (type
) != POINTER_TYPE
2386 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
2387 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
2389 pedwarn (input_location
, OPT_Wmain
,
2390 "third argument of %q+D should probably be "
2391 "%<char **%>", decl
);
2396 /* It is intentional that this message does not mention the third
2397 argument because it's only mentioned in an appendix of the
2399 if (argct
> 0 && (argct
< 2 || argct
> 3))
2400 pedwarn (input_location
, OPT_Wmain
,
2401 "%q+D takes only zero or two arguments", decl
);
2403 if (stdarg_p (TREE_TYPE (decl
)))
2404 pedwarn (input_location
, OPT_Wmain
,
2405 "%q+D declared as variadic function", decl
);
2408 /* vector_targets_convertible_p is used for vector pointer types. The
2409 callers perform various checks that the qualifiers are satisfactory,
2410 while OTOH vector_targets_convertible_p ignores the number of elements
2411 in the vectors. That's fine with vector pointers as we can consider,
2412 say, a vector of 8 elements as two consecutive vectors of 4 elements,
2413 and that does not require and conversion of the pointer values.
2414 In contrast, vector_types_convertible_p and
2415 vector_types_compatible_elements_p are used for vector value types. */
2416 /* True if pointers to distinct types T1 and T2 can be converted to
2417 each other without an explicit cast. Only returns true for opaque
2420 vector_targets_convertible_p (const_tree t1
, const_tree t2
)
2422 if (TREE_CODE (t1
) == VECTOR_TYPE
&& TREE_CODE (t2
) == VECTOR_TYPE
2423 && (TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2424 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2430 /* vector_types_convertible_p is used for vector value types.
2431 It could in principle call vector_targets_convertible_p as a subroutine,
2432 but then the check for vector type would be duplicated with its callers,
2433 and also the purpose of vector_targets_convertible_p would become
2435 Where vector_types_convertible_p returns true, a conversion might still be
2436 needed to make the types match.
2437 In contrast, vector_targets_convertible_p is used for vector pointer
2438 values, and vector_types_compatible_elements_p is used specifically
2439 in the context for binary operators, as a check if use is possible without
2441 /* True if vector types T1 and T2 can be converted to each other
2442 without an explicit cast. If EMIT_LAX_NOTE is true, and T1 and T2
2443 can only be converted with -flax-vector-conversions yet that is not
2444 in effect, emit a note telling the user about that option if such
2445 a note has not previously been emitted. */
2447 vector_types_convertible_p (const_tree t1
, const_tree t2
, bool emit_lax_note
)
2449 static bool emitted_lax_note
= false;
2450 bool convertible_lax
;
2452 if ((TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2453 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2457 (tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
))
2458 && (TREE_CODE (TREE_TYPE (t1
)) != REAL_TYPE
||
2459 TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
))
2460 && (INTEGRAL_TYPE_P (TREE_TYPE (t1
))
2461 == INTEGRAL_TYPE_P (TREE_TYPE (t2
))));
2463 if (!convertible_lax
|| flag_lax_vector_conversions
)
2464 return convertible_lax
;
2466 if (TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
)
2467 && lang_hooks
.types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
2470 if (emit_lax_note
&& !emitted_lax_note
)
2472 emitted_lax_note
= true;
2473 inform (input_location
, "use -flax-vector-conversions to permit "
2474 "conversions between vectors with differing "
2475 "element types or numbers of subparts");
2481 /* Build a VEC_PERM_EXPR if V0, V1 and MASK are not error_mark_nodes
2482 and have vector types, V0 has the same type as V1, and the number of
2483 elements of V0, V1, MASK is the same.
2485 In case V1 is a NULL_TREE it is assumed that __builtin_shuffle was
2486 called with two arguments. In this case implementation passes the
2487 first argument twice in order to share the same tree code. This fact
2488 could enable the mask-values being twice the vector length. This is
2489 an implementation accident and this semantics is not guaranteed to
2492 c_build_vec_perm_expr (location_t loc
, tree v0
, tree v1
, tree mask
,
2497 bool maybe_const
= false;
2498 bool two_arguments
= false;
2500 if (v1
== NULL_TREE
)
2502 two_arguments
= true;
2506 if (v0
== error_mark_node
|| v1
== error_mark_node
2507 || mask
== error_mark_node
)
2508 return error_mark_node
;
2510 if (TREE_CODE (TREE_TYPE (mask
)) != VECTOR_TYPE
2511 || TREE_CODE (TREE_TYPE (TREE_TYPE (mask
))) != INTEGER_TYPE
)
2514 error_at (loc
, "__builtin_shuffle last argument must "
2515 "be an integer vector");
2516 return error_mark_node
;
2519 if (TREE_CODE (TREE_TYPE (v0
)) != VECTOR_TYPE
2520 || TREE_CODE (TREE_TYPE (v1
)) != VECTOR_TYPE
)
2523 error_at (loc
, "__builtin_shuffle arguments must be vectors");
2524 return error_mark_node
;
2527 if (TYPE_MAIN_VARIANT (TREE_TYPE (v0
)) != TYPE_MAIN_VARIANT (TREE_TYPE (v1
)))
2530 error_at (loc
, "__builtin_shuffle argument vectors must be of "
2532 return error_mark_node
;
2535 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (v0
))
2536 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
))
2537 && TYPE_VECTOR_SUBPARTS (TREE_TYPE (v1
))
2538 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
)))
2541 error_at (loc
, "__builtin_shuffle number of elements of the "
2542 "argument vector(s) and the mask vector should "
2544 return error_mark_node
;
2547 if (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (v0
))))
2548 != GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (mask
)))))
2551 error_at (loc
, "__builtin_shuffle argument vector(s) inner type "
2552 "must have the same size as inner type of the mask");
2553 return error_mark_node
;
2556 if (!c_dialect_cxx ())
2558 /* Avoid C_MAYBE_CONST_EXPRs inside VEC_PERM_EXPR. */
2559 v0
= c_fully_fold (v0
, false, &maybe_const
);
2560 wrap
&= maybe_const
;
2563 v1
= v0
= save_expr (v0
);
2566 v1
= c_fully_fold (v1
, false, &maybe_const
);
2567 wrap
&= maybe_const
;
2570 mask
= c_fully_fold (mask
, false, &maybe_const
);
2571 wrap
&= maybe_const
;
2573 else if (two_arguments
)
2574 v1
= v0
= save_expr (v0
);
2576 ret
= build3_loc (loc
, VEC_PERM_EXPR
, TREE_TYPE (v0
), v0
, v1
, mask
);
2578 if (!c_dialect_cxx () && !wrap
)
2579 ret
= c_wrap_maybe_const (ret
, true);
2584 /* Like tree.c:get_narrower, but retain conversion from C++0x scoped enum
2585 to integral type. */
2588 c_common_get_narrower (tree op
, int *unsignedp_ptr
)
2590 op
= get_narrower (op
, unsignedp_ptr
);
2592 if (TREE_CODE (TREE_TYPE (op
)) == ENUMERAL_TYPE
2593 && ENUM_IS_SCOPED (TREE_TYPE (op
)))
2595 /* C++0x scoped enumerations don't implicitly convert to integral
2596 type; if we stripped an explicit conversion to a larger type we
2597 need to replace it so common_type will still work. */
2598 tree type
= c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op
)),
2599 TYPE_UNSIGNED (TREE_TYPE (op
)));
2600 op
= fold_convert (type
, op
);
2605 /* This is a helper function of build_binary_op.
2607 For certain operations if both args were extended from the same
2608 smaller type, do the arithmetic in that type and then extend.
2610 BITWISE indicates a bitwise operation.
2611 For them, this optimization is safe only if
2612 both args are zero-extended or both are sign-extended.
2613 Otherwise, we might change the result.
2614 Eg, (short)-1 | (unsigned short)-1 is (int)-1
2615 but calculated in (unsigned short) it would be (unsigned short)-1.
2618 shorten_binary_op (tree result_type
, tree op0
, tree op1
, bool bitwise
)
2620 int unsigned0
, unsigned1
;
2625 /* Cast OP0 and OP1 to RESULT_TYPE. Doing so prevents
2626 excessive narrowing when we call get_narrower below. For
2627 example, suppose that OP0 is of unsigned int extended
2628 from signed char and that RESULT_TYPE is long long int.
2629 If we explicitly cast OP0 to RESULT_TYPE, OP0 would look
2632 (long long int) (unsigned int) signed_char
2634 which get_narrower would narrow down to
2636 (unsigned int) signed char
2638 If we do not cast OP0 first, get_narrower would return
2639 signed_char, which is inconsistent with the case of the
2641 op0
= convert (result_type
, op0
);
2642 op1
= convert (result_type
, op1
);
2644 arg0
= c_common_get_narrower (op0
, &unsigned0
);
2645 arg1
= c_common_get_narrower (op1
, &unsigned1
);
2647 /* UNS is 1 if the operation to be done is an unsigned one. */
2648 uns
= TYPE_UNSIGNED (result_type
);
2650 /* Handle the case that OP0 (or OP1) does not *contain* a conversion
2651 but it *requires* conversion to FINAL_TYPE. */
2653 if ((TYPE_PRECISION (TREE_TYPE (op0
))
2654 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2655 && TREE_TYPE (op0
) != result_type
)
2656 unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2657 if ((TYPE_PRECISION (TREE_TYPE (op1
))
2658 == TYPE_PRECISION (TREE_TYPE (arg1
)))
2659 && TREE_TYPE (op1
) != result_type
)
2660 unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2662 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
2664 /* For bitwise operations, signedness of nominal type
2665 does not matter. Consider only how operands were extended. */
2669 /* Note that in all three cases below we refrain from optimizing
2670 an unsigned operation on sign-extended args.
2671 That would not be valid. */
2673 /* Both args variable: if both extended in same way
2674 from same width, do it in that width.
2675 Do it unsigned if args were zero-extended. */
2676 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
2677 < TYPE_PRECISION (result_type
))
2678 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2679 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2680 && unsigned0
== unsigned1
2681 && (unsigned0
|| !uns
))
2682 return c_common_signed_or_unsigned_type
2683 (unsigned0
, common_type (TREE_TYPE (arg0
), TREE_TYPE (arg1
)));
2685 else if (TREE_CODE (arg0
) == INTEGER_CST
2686 && (unsigned1
|| !uns
)
2687 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2688 < TYPE_PRECISION (result_type
))
2690 = c_common_signed_or_unsigned_type (unsigned1
,
2692 && !POINTER_TYPE_P (type
)
2693 && int_fits_type_p (arg0
, type
))
2696 else if (TREE_CODE (arg1
) == INTEGER_CST
2697 && (unsigned0
|| !uns
)
2698 && (TYPE_PRECISION (TREE_TYPE (arg0
))
2699 < TYPE_PRECISION (result_type
))
2701 = c_common_signed_or_unsigned_type (unsigned0
,
2703 && !POINTER_TYPE_P (type
)
2704 && int_fits_type_p (arg1
, type
))
2710 /* Returns true iff any integer value of type FROM_TYPE can be represented as
2711 real of type TO_TYPE. This is a helper function for unsafe_conversion_p. */
2714 int_safely_convertible_to_real_p (const_tree from_type
, const_tree to_type
)
2716 tree type_low_bound
= TYPE_MIN_VALUE (from_type
);
2717 tree type_high_bound
= TYPE_MAX_VALUE (from_type
);
2718 REAL_VALUE_TYPE real_low_bound
=
2719 real_value_from_int_cst (0, type_low_bound
);
2720 REAL_VALUE_TYPE real_high_bound
=
2721 real_value_from_int_cst (0, type_high_bound
);
2723 return exact_real_truncate (TYPE_MODE (to_type
), &real_low_bound
)
2724 && exact_real_truncate (TYPE_MODE (to_type
), &real_high_bound
);
2727 /* Checks if expression EXPR of complex/real/integer type cannot be converted
2728 to the complex/real/integer type TYPE. Function returns non-zero when:
2729 * EXPR is a constant which cannot be exactly converted to TYPE.
2730 * EXPR is not a constant and size of EXPR's type > than size of TYPE,
2731 for EXPR type and TYPE being both integers or both real, or both
2733 * EXPR is not a constant of complex type and TYPE is a real or
2735 * EXPR is not a constant of real type and TYPE is an integer.
2736 * EXPR is not a constant of integer type which cannot be
2737 exactly converted to real type.
2739 Function allows conversions between types of different signedness and
2740 can return SAFE_CONVERSION (zero) in that case. Function can produce
2741 signedness warnings if PRODUCE_WARNS is true.
2743 Function allows conversions from complex constants to non-complex types,
2744 provided that imaginary part is zero and real part can be safely converted
2747 enum conversion_safety
2748 unsafe_conversion_p (location_t loc
, tree type
, tree expr
, bool produce_warns
)
2750 enum conversion_safety give_warning
= SAFE_CONVERSION
; /* is 0 or false */
2751 tree expr_type
= TREE_TYPE (expr
);
2752 loc
= expansion_point_location_if_in_system_header (loc
);
2754 if (TREE_CODE (expr
) == REAL_CST
|| TREE_CODE (expr
) == INTEGER_CST
)
2756 /* If type is complex, we are interested in compatibility with
2758 if (TREE_CODE (type
) == COMPLEX_TYPE
)
2759 type
= TREE_TYPE (type
);
2761 /* Warn for real constant that is not an exact integer converted
2763 if (TREE_CODE (expr_type
) == REAL_TYPE
2764 && TREE_CODE (type
) == INTEGER_TYPE
)
2766 if (!real_isinteger (TREE_REAL_CST_PTR (expr
), TYPE_MODE (expr_type
)))
2767 give_warning
= UNSAFE_REAL
;
2769 /* Warn for an integer constant that does not fit into integer type. */
2770 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2771 && TREE_CODE (type
) == INTEGER_TYPE
2772 && !int_fits_type_p (expr
, type
))
2774 if (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)
2775 && tree_int_cst_sgn (expr
) < 0)
2778 warning_at (loc
, OPT_Wsign_conversion
, "negative integer"
2779 " implicitly converted to unsigned type");
2781 else if (!TYPE_UNSIGNED (type
) && TYPE_UNSIGNED (expr_type
))
2784 warning_at (loc
, OPT_Wsign_conversion
, "conversion of unsigned"
2785 " constant value to negative integer");
2788 give_warning
= UNSAFE_OTHER
;
2790 else if (TREE_CODE (type
) == REAL_TYPE
)
2792 /* Warn for an integer constant that does not fit into real type. */
2793 if (TREE_CODE (expr_type
) == INTEGER_TYPE
)
2795 REAL_VALUE_TYPE a
= real_value_from_int_cst (0, expr
);
2796 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2797 give_warning
= UNSAFE_REAL
;
2799 /* Warn for a real constant that does not fit into a smaller
2801 else if (TREE_CODE (expr_type
) == REAL_TYPE
2802 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2804 REAL_VALUE_TYPE a
= TREE_REAL_CST (expr
);
2805 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2806 give_warning
= UNSAFE_REAL
;
2811 else if (TREE_CODE (expr
) == COMPLEX_CST
)
2813 tree imag_part
= TREE_IMAGPART (expr
);
2814 /* Conversion from complex constant with zero imaginary part,
2815 perform check for conversion of real part. */
2816 if ((TREE_CODE (imag_part
) == REAL_CST
2817 && real_zerop (imag_part
))
2818 || (TREE_CODE (imag_part
) == INTEGER_CST
2819 && integer_zerop (imag_part
)))
2820 /* Note: in this branch we use recursive call to unsafe_conversion_p
2821 with different type of EXPR, but it is still safe, because when EXPR
2822 is a constant, it's type is not used in text of generated warnings
2823 (otherwise they could sound misleading). */
2824 return unsafe_conversion_p (loc
, type
, TREE_REALPART (expr
),
2826 /* Conversion from complex constant with non-zero imaginary part. */
2829 /* Conversion to complex type.
2830 Perform checks for both real and imaginary parts. */
2831 if (TREE_CODE (type
) == COMPLEX_TYPE
)
2833 /* Unfortunately, produce_warns must be false in two subsequent
2834 calls of unsafe_conversion_p, because otherwise we could
2835 produce strange "double" warnings, if both real and imaginary
2836 parts have conversion problems related to signedness.
2839 int32_t _Complex a = 0x80000000 + 0x80000000i;
2841 Possible solution: add a separate function for checking
2842 constants and combine result of two calls appropriately. */
2843 enum conversion_safety re_safety
=
2844 unsafe_conversion_p (loc
, type
, TREE_REALPART (expr
), false);
2845 enum conversion_safety im_safety
=
2846 unsafe_conversion_p (loc
, type
, imag_part
, false);
2848 /* Merge the results into appropriate single warning. */
2850 /* Note: this case includes SAFE_CONVERSION, i.e. success. */
2851 if (re_safety
== im_safety
)
2852 give_warning
= re_safety
;
2853 else if (!re_safety
&& im_safety
)
2854 give_warning
= im_safety
;
2855 else if (re_safety
&& !im_safety
)
2856 give_warning
= re_safety
;
2858 give_warning
= UNSAFE_OTHER
;
2860 /* Warn about conversion from complex to real or integer type. */
2862 give_warning
= UNSAFE_IMAGINARY
;
2866 /* Checks for remaining case: EXPR is not constant. */
2869 /* Warn for real types converted to integer types. */
2870 if (TREE_CODE (expr_type
) == REAL_TYPE
2871 && TREE_CODE (type
) == INTEGER_TYPE
)
2872 give_warning
= UNSAFE_REAL
;
2874 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2875 && TREE_CODE (type
) == INTEGER_TYPE
)
2877 /* Don't warn about unsigned char y = 0xff, x = (int) y; */
2878 expr
= get_unwidened (expr
, 0);
2879 expr_type
= TREE_TYPE (expr
);
2881 /* Don't warn for short y; short x = ((int)y & 0xff); */
2882 if (TREE_CODE (expr
) == BIT_AND_EXPR
2883 || TREE_CODE (expr
) == BIT_IOR_EXPR
2884 || TREE_CODE (expr
) == BIT_XOR_EXPR
)
2886 /* If both args were extended from a shortest type,
2887 use that type if that is safe. */
2888 expr_type
= shorten_binary_op (expr_type
,
2889 TREE_OPERAND (expr
, 0),
2890 TREE_OPERAND (expr
, 1),
2893 if (TREE_CODE (expr
) == BIT_AND_EXPR
)
2895 tree op0
= TREE_OPERAND (expr
, 0);
2896 tree op1
= TREE_OPERAND (expr
, 1);
2897 bool unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2898 bool unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2900 /* If one of the operands is a non-negative constant
2901 that fits in the target type, then the type of the
2902 other operand does not matter. */
2903 if ((TREE_CODE (op0
) == INTEGER_CST
2904 && int_fits_type_p (op0
, c_common_signed_type (type
))
2905 && int_fits_type_p (op0
, c_common_unsigned_type (type
)))
2906 || (TREE_CODE (op1
) == INTEGER_CST
2907 && int_fits_type_p (op1
, c_common_signed_type (type
))
2908 && int_fits_type_p (op1
,
2909 c_common_unsigned_type (type
))))
2910 return SAFE_CONVERSION
;
2911 /* If constant is unsigned and fits in the target
2912 type, then the result will also fit. */
2913 else if ((TREE_CODE (op0
) == INTEGER_CST
2915 && int_fits_type_p (op0
, type
))
2916 || (TREE_CODE (op1
) == INTEGER_CST
2918 && int_fits_type_p (op1
, type
)))
2919 return SAFE_CONVERSION
;
2922 /* Warn for integer types converted to smaller integer types. */
2923 if (TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2924 give_warning
= UNSAFE_OTHER
;
2926 /* When they are the same width but different signedness,
2927 then the value may change. */
2928 else if (((TYPE_PRECISION (type
) == TYPE_PRECISION (expr_type
)
2929 && TYPE_UNSIGNED (expr_type
) != TYPE_UNSIGNED (type
))
2930 /* Even when converted to a bigger type, if the type is
2931 unsigned but expr is signed, then negative values
2933 || (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)))
2935 warning_at (loc
, OPT_Wsign_conversion
, "conversion to %qT from %qT "
2936 "may change the sign of the result",
2940 /* Warn for integer types converted to real types if and only if
2941 all the range of values of the integer type cannot be
2942 represented by the real type. */
2943 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2944 && TREE_CODE (type
) == REAL_TYPE
)
2946 /* Don't warn about char y = 0xff; float x = (int) y; */
2947 expr
= get_unwidened (expr
, 0);
2948 expr_type
= TREE_TYPE (expr
);
2950 if (!int_safely_convertible_to_real_p (expr_type
, type
))
2951 give_warning
= UNSAFE_OTHER
;
2954 /* Warn for real types converted to smaller real types. */
2955 else if (TREE_CODE (expr_type
) == REAL_TYPE
2956 && TREE_CODE (type
) == REAL_TYPE
2957 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2958 give_warning
= UNSAFE_REAL
;
2960 /* Check conversion between two complex types. */
2961 else if (TREE_CODE (expr_type
) == COMPLEX_TYPE
2962 && TREE_CODE (type
) == COMPLEX_TYPE
)
2964 /* Extract underlying types (i.e., type of real and imaginary
2965 parts) of expr_type and type. */
2966 tree from_type
= TREE_TYPE (expr_type
);
2967 tree to_type
= TREE_TYPE (type
);
2969 /* Warn for real types converted to integer types. */
2970 if (TREE_CODE (from_type
) == REAL_TYPE
2971 && TREE_CODE (to_type
) == INTEGER_TYPE
)
2972 give_warning
= UNSAFE_REAL
;
2974 /* Warn for real types converted to smaller real types. */
2975 else if (TREE_CODE (from_type
) == REAL_TYPE
2976 && TREE_CODE (to_type
) == REAL_TYPE
2977 && TYPE_PRECISION (to_type
) < TYPE_PRECISION (from_type
))
2978 give_warning
= UNSAFE_REAL
;
2980 /* Check conversion for complex integer types. Here implementation
2981 is simpler than for real-domain integers because it does not
2982 involve sophisticated cases, such as bitmasks, casts, etc. */
2983 else if (TREE_CODE (from_type
) == INTEGER_TYPE
2984 && TREE_CODE (to_type
) == INTEGER_TYPE
)
2986 /* Warn for integer types converted to smaller integer types. */
2987 if (TYPE_PRECISION (to_type
) < TYPE_PRECISION (from_type
))
2988 give_warning
= UNSAFE_OTHER
;
2990 /* Check for different signedness, see case for real-domain
2991 integers (above) for a more detailed comment. */
2992 else if (((TYPE_PRECISION (to_type
) == TYPE_PRECISION (from_type
)
2993 && TYPE_UNSIGNED (to_type
) != TYPE_UNSIGNED (from_type
))
2994 || (TYPE_UNSIGNED (to_type
) && !TYPE_UNSIGNED (from_type
)))
2996 warning_at (loc
, OPT_Wsign_conversion
,
2997 "conversion to %qT from %qT "
2998 "may change the sign of the result",
3001 else if (TREE_CODE (from_type
) == INTEGER_TYPE
3002 && TREE_CODE (to_type
) == REAL_TYPE
3003 && !int_safely_convertible_to_real_p (from_type
, to_type
))
3004 give_warning
= UNSAFE_OTHER
;
3007 /* Warn for complex types converted to real or integer types. */
3008 else if (TREE_CODE (expr_type
) == COMPLEX_TYPE
3009 && TREE_CODE (type
) != COMPLEX_TYPE
)
3010 give_warning
= UNSAFE_IMAGINARY
;
3013 return give_warning
;
3016 /* Warns if the conversion of EXPR to TYPE may alter a value.
3017 This is a helper function for warnings_for_convert_and_check. */
3020 conversion_warning (location_t loc
, tree type
, tree expr
)
3022 tree expr_type
= TREE_TYPE (expr
);
3023 enum conversion_safety conversion_kind
;
3025 if (!warn_conversion
&& !warn_sign_conversion
&& !warn_float_conversion
)
3028 /* This may happen, because for LHS op= RHS we preevaluate
3029 RHS and create C_MAYBE_CONST_EXPR <SAVE_EXPR <RHS>>, which
3030 means we could no longer see the code of the EXPR. */
3031 if (TREE_CODE (expr
) == C_MAYBE_CONST_EXPR
)
3032 expr
= C_MAYBE_CONST_EXPR_EXPR (expr
);
3033 if (TREE_CODE (expr
) == SAVE_EXPR
)
3034 expr
= TREE_OPERAND (expr
, 0);
3036 switch (TREE_CODE (expr
))
3044 case TRUTH_ANDIF_EXPR
:
3045 case TRUTH_ORIF_EXPR
:
3046 case TRUTH_AND_EXPR
:
3048 case TRUTH_XOR_EXPR
:
3049 case TRUTH_NOT_EXPR
:
3050 /* Conversion from boolean to a signed:1 bit-field (which only
3051 can hold the values 0 and -1) doesn't lose information - but
3052 it does change the value. */
3053 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
3054 warning_at (loc
, OPT_Wconversion
,
3055 "conversion to %qT from boolean expression", type
);
3061 conversion_kind
= unsafe_conversion_p (loc
, type
, expr
, true);
3062 if (conversion_kind
== UNSAFE_REAL
)
3063 warning_at (loc
, OPT_Wfloat_conversion
,
3064 "conversion to %qT alters %qT constant value",
3066 else if (conversion_kind
)
3067 warning_at (loc
, OPT_Wconversion
,
3068 "conversion to %qT alters %qT constant value",
3074 /* In case of COND_EXPR, we do not care about the type of
3075 COND_EXPR, only about the conversion of each operand. */
3076 tree op1
= TREE_OPERAND (expr
, 1);
3077 tree op2
= TREE_OPERAND (expr
, 2);
3079 conversion_warning (loc
, type
, op1
);
3080 conversion_warning (loc
, type
, op2
);
3084 default: /* 'expr' is not a constant. */
3085 conversion_kind
= unsafe_conversion_p (loc
, type
, expr
, true);
3086 if (conversion_kind
== UNSAFE_REAL
)
3087 warning_at (loc
, OPT_Wfloat_conversion
,
3088 "conversion to %qT from %qT may alter its value",
3090 else if (conversion_kind
== UNSAFE_IMAGINARY
)
3091 warning_at (loc
, OPT_Wconversion
,
3092 "conversion to %qT from %qT discards imaginary component",
3094 else if (conversion_kind
)
3095 warning_at (loc
, OPT_Wconversion
,
3096 "conversion to %qT from %qT may alter its value",
3101 /* Produce warnings after a conversion. RESULT is the result of
3102 converting EXPR to TYPE. This is a helper function for
3103 convert_and_check and cp_convert_and_check. */
3106 warnings_for_convert_and_check (location_t loc
, tree type
, tree expr
,
3109 loc
= expansion_point_location_if_in_system_header (loc
);
3111 if (TREE_CODE (expr
) == INTEGER_CST
3112 && (TREE_CODE (type
) == INTEGER_TYPE
3113 || TREE_CODE (type
) == ENUMERAL_TYPE
)
3114 && !int_fits_type_p (expr
, type
))
3116 /* Do not diagnose overflow in a constant expression merely
3117 because a conversion overflowed. */
3118 if (TREE_OVERFLOW (result
))
3119 TREE_OVERFLOW (result
) = TREE_OVERFLOW (expr
);
3121 if (TYPE_UNSIGNED (type
))
3123 /* This detects cases like converting -129 or 256 to
3125 if (!int_fits_type_p (expr
, c_common_signed_type (type
)))
3126 warning_at (loc
, OPT_Woverflow
,
3127 "large integer implicitly truncated to unsigned type");
3129 conversion_warning (loc
, type
, expr
);
3131 else if (!int_fits_type_p (expr
, c_common_unsigned_type (type
)))
3132 warning_at (loc
, OPT_Woverflow
,
3133 "overflow in implicit constant conversion");
3134 /* No warning for converting 0x80000000 to int. */
3136 && (TREE_CODE (TREE_TYPE (expr
)) != INTEGER_TYPE
3137 || TYPE_PRECISION (TREE_TYPE (expr
))
3138 != TYPE_PRECISION (type
)))
3139 warning_at (loc
, OPT_Woverflow
,
3140 "overflow in implicit constant conversion");
3143 conversion_warning (loc
, type
, expr
);
3145 else if ((TREE_CODE (result
) == INTEGER_CST
3146 || TREE_CODE (result
) == FIXED_CST
) && TREE_OVERFLOW (result
))
3147 warning_at (loc
, OPT_Woverflow
,
3148 "overflow in implicit constant conversion");
3150 conversion_warning (loc
, type
, expr
);
3154 /* Convert EXPR to TYPE, warning about conversion problems with constants.
3155 Invoke this function on every expression that is converted implicitly,
3156 i.e. because of language rules and not because of an explicit cast. */
3159 convert_and_check (location_t loc
, tree type
, tree expr
)
3162 tree expr_for_warning
;
3164 /* Convert from a value with possible excess precision rather than
3165 via the semantic type, but do not warn about values not fitting
3166 exactly in the semantic type. */
3167 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
3169 tree orig_type
= TREE_TYPE (expr
);
3170 expr
= TREE_OPERAND (expr
, 0);
3171 expr_for_warning
= convert (orig_type
, expr
);
3172 if (orig_type
== type
)
3173 return expr_for_warning
;
3176 expr_for_warning
= expr
;
3178 if (TREE_TYPE (expr
) == type
)
3181 result
= convert (type
, expr
);
3183 if (c_inhibit_evaluation_warnings
== 0
3184 && !TREE_OVERFLOW_P (expr
)
3185 && result
!= error_mark_node
)
3186 warnings_for_convert_and_check (loc
, type
, expr_for_warning
, result
);
3191 /* A node in a list that describes references to variables (EXPR), which are
3192 either read accesses if WRITER is zero, or write accesses, in which case
3193 WRITER is the parent of EXPR. */
3200 /* Used to implement a cache the results of a call to verify_tree. We only
3201 use this for SAVE_EXPRs. */
3204 struct tlist_cache
*next
;
3205 struct tlist
*cache_before_sp
;
3206 struct tlist
*cache_after_sp
;
3210 /* Obstack to use when allocating tlist structures, and corresponding
3212 static struct obstack tlist_obstack
;
3213 static char *tlist_firstobj
= 0;
3215 /* Keep track of the identifiers we've warned about, so we can avoid duplicate
3217 static struct tlist
*warned_ids
;
3218 /* SAVE_EXPRs need special treatment. We process them only once and then
3219 cache the results. */
3220 static struct tlist_cache
*save_expr_cache
;
3222 static void add_tlist (struct tlist
**, struct tlist
*, tree
, int);
3223 static void merge_tlist (struct tlist
**, struct tlist
*, int);
3224 static void verify_tree (tree
, struct tlist
**, struct tlist
**, tree
);
3225 static int warning_candidate_p (tree
);
3226 static bool candidate_equal_p (const_tree
, const_tree
);
3227 static void warn_for_collisions (struct tlist
*);
3228 static void warn_for_collisions_1 (tree
, tree
, struct tlist
*, int);
3229 static struct tlist
*new_tlist (struct tlist
*, tree
, tree
);
3231 /* Create a new struct tlist and fill in its fields. */
3232 static struct tlist
*
3233 new_tlist (struct tlist
*next
, tree t
, tree writer
)
3236 l
= XOBNEW (&tlist_obstack
, struct tlist
);
3243 /* Add duplicates of the nodes found in ADD to the list *TO. If EXCLUDE_WRITER
3244 is nonnull, we ignore any node we find which has a writer equal to it. */
3247 add_tlist (struct tlist
**to
, struct tlist
*add
, tree exclude_writer
, int copy
)
3251 struct tlist
*next
= add
->next
;
3254 if (!exclude_writer
|| !candidate_equal_p (add
->writer
, exclude_writer
))
3255 *to
= copy
? new_tlist (*to
, add
->expr
, add
->writer
) : add
;
3260 /* Merge the nodes of ADD into TO. This merging process is done so that for
3261 each variable that already exists in TO, no new node is added; however if
3262 there is a write access recorded in ADD, and an occurrence on TO is only
3263 a read access, then the occurrence in TO will be modified to record the
3267 merge_tlist (struct tlist
**to
, struct tlist
*add
, int copy
)
3269 struct tlist
**end
= to
;
3272 end
= &(*end
)->next
;
3278 struct tlist
*next
= add
->next
;
3280 for (tmp2
= *to
; tmp2
; tmp2
= tmp2
->next
)
3281 if (candidate_equal_p (tmp2
->expr
, add
->expr
))
3285 tmp2
->writer
= add
->writer
;
3289 *end
= copy
? new_tlist (NULL
, add
->expr
, add
->writer
) : add
;
3290 end
= &(*end
)->next
;
3297 /* WRITTEN is a variable, WRITER is its parent. Warn if any of the variable
3298 references in list LIST conflict with it, excluding reads if ONLY writers
3302 warn_for_collisions_1 (tree written
, tree writer
, struct tlist
*list
,
3307 /* Avoid duplicate warnings. */
3308 for (tmp
= warned_ids
; tmp
; tmp
= tmp
->next
)
3309 if (candidate_equal_p (tmp
->expr
, written
))
3314 if (candidate_equal_p (list
->expr
, written
)
3315 && !candidate_equal_p (list
->writer
, writer
)
3316 && (!only_writes
|| list
->writer
))
3318 warned_ids
= new_tlist (warned_ids
, written
, NULL_TREE
);
3319 warning_at (EXPR_LOC_OR_LOC (writer
, input_location
),
3320 OPT_Wsequence_point
, "operation on %qE may be undefined",
3327 /* Given a list LIST of references to variables, find whether any of these
3328 can cause conflicts due to missing sequence points. */
3331 warn_for_collisions (struct tlist
*list
)
3335 for (tmp
= list
; tmp
; tmp
= tmp
->next
)
3338 warn_for_collisions_1 (tmp
->expr
, tmp
->writer
, list
, 0);
3342 /* Return nonzero if X is a tree that can be verified by the sequence point
3345 warning_candidate_p (tree x
)
3347 if (DECL_P (x
) && DECL_ARTIFICIAL (x
))
3350 if (TREE_CODE (x
) == BLOCK
)
3353 /* VOID_TYPE_P (TREE_TYPE (x)) is workaround for cp/tree.c
3354 (lvalue_p) crash on TRY/CATCH. */
3355 if (TREE_TYPE (x
) == NULL_TREE
|| VOID_TYPE_P (TREE_TYPE (x
)))
3361 /* No point to track non-const calls, they will never satisfy
3363 if (TREE_CODE (x
) == CALL_EXPR
&& (call_expr_flags (x
) & ECF_CONST
) == 0)
3366 if (TREE_CODE (x
) == STRING_CST
)
3372 /* Return nonzero if X and Y appear to be the same candidate (or NULL) */
3374 candidate_equal_p (const_tree x
, const_tree y
)
3376 return (x
== y
) || (x
&& y
&& operand_equal_p (x
, y
, 0));
3379 /* Walk the tree X, and record accesses to variables. If X is written by the
3380 parent tree, WRITER is the parent.
3381 We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP. If this
3382 expression or its only operand forces a sequence point, then everything up
3383 to the sequence point is stored in PBEFORE_SP. Everything else gets stored
3385 Once we return, we will have emitted warnings if any subexpression before
3386 such a sequence point could be undefined. On a higher level, however, the
3387 sequence point may not be relevant, and we'll merge the two lists.
3389 Example: (b++, a) + b;
3390 The call that processes the COMPOUND_EXPR will store the increment of B
3391 in PBEFORE_SP, and the use of A in PNO_SP. The higher-level call that
3392 processes the PLUS_EXPR will need to merge the two lists so that
3393 eventually, all accesses end up on the same list (and we'll warn about the
3394 unordered subexpressions b++ and b.
3396 A note on merging. If we modify the former example so that our expression
3399 care must be taken not simply to add all three expressions into the final
3400 PNO_SP list. The function merge_tlist takes care of that by merging the
3401 before-SP list of the COMPOUND_EXPR into its after-SP list in a special
3402 way, so that no more than one access to B is recorded. */
3405 verify_tree (tree x
, struct tlist
**pbefore_sp
, struct tlist
**pno_sp
,
3408 struct tlist
*tmp_before
, *tmp_nosp
, *tmp_list2
, *tmp_list3
;
3409 enum tree_code code
;
3410 enum tree_code_class cl
;
3412 /* X may be NULL if it is the operand of an empty statement expression
3418 code
= TREE_CODE (x
);
3419 cl
= TREE_CODE_CLASS (code
);
3421 if (warning_candidate_p (x
))
3422 *pno_sp
= new_tlist (*pno_sp
, x
, writer
);
3431 case TRUTH_ANDIF_EXPR
:
3432 case TRUTH_ORIF_EXPR
:
3433 tmp_before
= tmp_nosp
= tmp_list3
= 0;
3434 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3435 warn_for_collisions (tmp_nosp
);
3436 merge_tlist (pbefore_sp
, tmp_before
, 0);
3437 merge_tlist (pbefore_sp
, tmp_nosp
, 0);
3438 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, pno_sp
, NULL_TREE
);
3439 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3443 tmp_before
= tmp_list2
= 0;
3444 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_list2
, NULL_TREE
);
3445 warn_for_collisions (tmp_list2
);
3446 merge_tlist (pbefore_sp
, tmp_before
, 0);
3447 merge_tlist (pbefore_sp
, tmp_list2
, 0);
3449 tmp_list3
= tmp_nosp
= 0;
3450 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, &tmp_nosp
, NULL_TREE
);
3451 warn_for_collisions (tmp_nosp
);
3452 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3454 tmp_list3
= tmp_list2
= 0;
3455 verify_tree (TREE_OPERAND (x
, 2), &tmp_list3
, &tmp_list2
, NULL_TREE
);
3456 warn_for_collisions (tmp_list2
);
3457 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3458 /* Rather than add both tmp_nosp and tmp_list2, we have to merge the
3459 two first, to avoid warning for (a ? b++ : b++). */
3460 merge_tlist (&tmp_nosp
, tmp_list2
, 0);
3461 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3464 case PREDECREMENT_EXPR
:
3465 case PREINCREMENT_EXPR
:
3466 case POSTDECREMENT_EXPR
:
3467 case POSTINCREMENT_EXPR
:
3468 verify_tree (TREE_OPERAND (x
, 0), pno_sp
, pno_sp
, x
);
3472 tmp_before
= tmp_nosp
= tmp_list3
= 0;
3473 verify_tree (TREE_OPERAND (x
, 1), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3474 verify_tree (TREE_OPERAND (x
, 0), &tmp_list3
, &tmp_list3
, x
);
3475 /* Expressions inside the LHS are not ordered wrt. the sequence points
3476 in the RHS. Example:
3478 Despite the fact that the modification of "a" is in the before_sp
3479 list (tmp_before), it conflicts with the use of "a" in the LHS.
3480 We can handle this by adding the contents of tmp_list3
3481 to those of tmp_before, and redoing the collision warnings for that
3483 add_tlist (&tmp_before
, tmp_list3
, x
, 1);
3484 warn_for_collisions (tmp_before
);
3485 /* Exclude the LHS itself here; we first have to merge it into the
3486 tmp_nosp list. This is done to avoid warning for "a = a"; if we
3487 didn't exclude the LHS, we'd get it twice, once as a read and once
3489 add_tlist (pno_sp
, tmp_list3
, x
, 0);
3490 warn_for_collisions_1 (TREE_OPERAND (x
, 0), x
, tmp_nosp
, 1);
3492 merge_tlist (pbefore_sp
, tmp_before
, 0);
3493 if (warning_candidate_p (TREE_OPERAND (x
, 0)))
3494 merge_tlist (&tmp_nosp
, new_tlist (NULL
, TREE_OPERAND (x
, 0), x
), 0);
3495 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 1);
3499 /* We need to warn about conflicts among arguments and conflicts between
3500 args and the function address. Side effects of the function address,
3501 however, are not ordered by the sequence point of the call. */
3503 call_expr_arg_iterator iter
;
3505 tmp_before
= tmp_nosp
= 0;
3506 verify_tree (CALL_EXPR_FN (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3507 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, x
)
3509 tmp_list2
= tmp_list3
= 0;
3510 verify_tree (arg
, &tmp_list2
, &tmp_list3
, NULL_TREE
);
3511 merge_tlist (&tmp_list3
, tmp_list2
, 0);
3512 add_tlist (&tmp_before
, tmp_list3
, NULL_TREE
, 0);
3514 add_tlist (&tmp_before
, tmp_nosp
, NULL_TREE
, 0);
3515 warn_for_collisions (tmp_before
);
3516 add_tlist (pbefore_sp
, tmp_before
, NULL_TREE
, 0);
3521 /* Scan all the list, e.g. indices of multi dimensional array. */
3524 tmp_before
= tmp_nosp
= 0;
3525 verify_tree (TREE_VALUE (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3526 merge_tlist (&tmp_nosp
, tmp_before
, 0);
3527 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3534 struct tlist_cache
*t
;
3535 for (t
= save_expr_cache
; t
; t
= t
->next
)
3536 if (candidate_equal_p (t
->expr
, x
))
3541 t
= XOBNEW (&tlist_obstack
, struct tlist_cache
);
3542 t
->next
= save_expr_cache
;
3544 save_expr_cache
= t
;
3546 tmp_before
= tmp_nosp
= 0;
3547 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3548 warn_for_collisions (tmp_nosp
);
3551 merge_tlist (&tmp_list3
, tmp_nosp
, 0);
3552 t
->cache_before_sp
= tmp_before
;
3553 t
->cache_after_sp
= tmp_list3
;
3555 merge_tlist (pbefore_sp
, t
->cache_before_sp
, 1);
3556 add_tlist (pno_sp
, t
->cache_after_sp
, NULL_TREE
, 1);
3561 x
= TREE_OPERAND (x
, 0);
3568 /* For other expressions, simply recurse on their operands.
3569 Manual tail recursion for unary expressions.
3570 Other non-expressions need not be processed. */
3571 if (cl
== tcc_unary
)
3573 x
= TREE_OPERAND (x
, 0);
3577 else if (IS_EXPR_CODE_CLASS (cl
))
3580 int max
= TREE_OPERAND_LENGTH (x
);
3581 for (lp
= 0; lp
< max
; lp
++)
3583 tmp_before
= tmp_nosp
= 0;
3584 verify_tree (TREE_OPERAND (x
, lp
), &tmp_before
, &tmp_nosp
, 0);
3585 merge_tlist (&tmp_nosp
, tmp_before
, 0);
3586 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3593 /* Try to warn for undefined behavior in EXPR due to missing sequence
3597 verify_sequence_points (tree expr
)
3599 struct tlist
*before_sp
= 0, *after_sp
= 0;
3602 save_expr_cache
= 0;
3603 if (tlist_firstobj
== 0)
3605 gcc_obstack_init (&tlist_obstack
);
3606 tlist_firstobj
= (char *) obstack_alloc (&tlist_obstack
, 0);
3609 verify_tree (expr
, &before_sp
, &after_sp
, 0);
3610 warn_for_collisions (after_sp
);
3611 obstack_free (&tlist_obstack
, tlist_firstobj
);
3614 /* Validate the expression after `case' and apply default promotions. */
3617 check_case_value (location_t loc
, tree value
)
3619 if (value
== NULL_TREE
)
3622 if (TREE_CODE (value
) == INTEGER_CST
)
3623 /* Promote char or short to int. */
3624 value
= perform_integral_promotions (value
);
3625 else if (value
!= error_mark_node
)
3627 error_at (loc
, "case label does not reduce to an integer constant");
3628 value
= error_mark_node
;
3631 constant_expression_warning (value
);
3636 /* See if the case values LOW and HIGH are in the range of the original
3637 type (i.e. before the default conversion to int) of the switch testing
3639 TYPE is the promoted type of the testing expression, and ORIG_TYPE is
3640 the type before promoting it. CASE_LOW_P is a pointer to the lower
3641 bound of the case label, and CASE_HIGH_P is the upper bound or NULL
3642 if the case is not a case range.
3643 The caller has to make sure that we are not called with NULL for
3644 CASE_LOW_P (i.e. the default case).
3645 Returns true if the case label is in range of ORIG_TYPE (saturated or
3646 untouched) or false if the label is out of range. */
3649 check_case_bounds (location_t loc
, tree type
, tree orig_type
,
3650 tree
*case_low_p
, tree
*case_high_p
)
3652 tree min_value
, max_value
;
3653 tree case_low
= *case_low_p
;
3654 tree case_high
= case_high_p
? *case_high_p
: case_low
;
3656 /* If there was a problem with the original type, do nothing. */
3657 if (orig_type
== error_mark_node
)
3660 min_value
= TYPE_MIN_VALUE (orig_type
);
3661 max_value
= TYPE_MAX_VALUE (orig_type
);
3663 /* Case label is less than minimum for type. */
3664 if (tree_int_cst_compare (case_low
, min_value
) < 0
3665 && tree_int_cst_compare (case_high
, min_value
) < 0)
3667 warning_at (loc
, 0, "case label value is less than minimum value "
3672 /* Case value is greater than maximum for type. */
3673 if (tree_int_cst_compare (case_low
, max_value
) > 0
3674 && tree_int_cst_compare (case_high
, max_value
) > 0)
3676 warning_at (loc
, 0, "case label value exceeds maximum value for type");
3680 /* Saturate lower case label value to minimum. */
3681 if (tree_int_cst_compare (case_high
, min_value
) >= 0
3682 && tree_int_cst_compare (case_low
, min_value
) < 0)
3684 warning_at (loc
, 0, "lower value in case label range"
3685 " less than minimum value for type");
3686 case_low
= min_value
;
3689 /* Saturate upper case label value to maximum. */
3690 if (tree_int_cst_compare (case_low
, max_value
) <= 0
3691 && tree_int_cst_compare (case_high
, max_value
) > 0)
3693 warning_at (loc
, 0, "upper value in case label range"
3694 " exceeds maximum value for type");
3695 case_high
= max_value
;
3698 if (*case_low_p
!= case_low
)
3699 *case_low_p
= convert (type
, case_low
);
3700 if (case_high_p
&& *case_high_p
!= case_high
)
3701 *case_high_p
= convert (type
, case_high
);
3706 /* Return an integer type with BITS bits of precision,
3707 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
3710 c_common_type_for_size (unsigned int bits
, int unsignedp
)
3714 if (bits
== TYPE_PRECISION (integer_type_node
))
3715 return unsignedp
? unsigned_type_node
: integer_type_node
;
3717 if (bits
== TYPE_PRECISION (signed_char_type_node
))
3718 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3720 if (bits
== TYPE_PRECISION (short_integer_type_node
))
3721 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3723 if (bits
== TYPE_PRECISION (long_integer_type_node
))
3724 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3726 if (bits
== TYPE_PRECISION (long_long_integer_type_node
))
3727 return (unsignedp
? long_long_unsigned_type_node
3728 : long_long_integer_type_node
);
3730 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
3731 if (int_n_enabled_p
[i
]
3732 && bits
== int_n_data
[i
].bitsize
)
3733 return (unsignedp
? int_n_trees
[i
].unsigned_type
3734 : int_n_trees
[i
].signed_type
);
3736 if (bits
== TYPE_PRECISION (widest_integer_literal_type_node
))
3737 return (unsignedp
? widest_unsigned_literal_type_node
3738 : widest_integer_literal_type_node
);
3740 if (bits
<= TYPE_PRECISION (intQI_type_node
))
3741 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3743 if (bits
<= TYPE_PRECISION (intHI_type_node
))
3744 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3746 if (bits
<= TYPE_PRECISION (intSI_type_node
))
3747 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3749 if (bits
<= TYPE_PRECISION (intDI_type_node
))
3750 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3755 /* Return a fixed-point type that has at least IBIT ibits and FBIT fbits
3756 that is unsigned if UNSIGNEDP is nonzero, otherwise signed;
3757 and saturating if SATP is nonzero, otherwise not saturating. */
3760 c_common_fixed_point_type_for_size (unsigned int ibit
, unsigned int fbit
,
3761 int unsignedp
, int satp
)
3765 mode
= unsignedp
? UQQmode
: QQmode
;
3767 mode
= unsignedp
? UHAmode
: HAmode
;
3769 for (; mode
!= VOIDmode
; mode
= GET_MODE_WIDER_MODE (mode
))
3770 if (GET_MODE_IBIT (mode
) >= ibit
&& GET_MODE_FBIT (mode
) >= fbit
)
3773 if (mode
== VOIDmode
|| !targetm
.scalar_mode_supported_p (mode
))
3775 sorry ("GCC cannot support operators with integer types and "
3776 "fixed-point types that have too many integral and "
3777 "fractional bits together");
3781 return c_common_type_for_mode (mode
, satp
);
3784 /* Used for communication between c_common_type_for_mode and
3785 c_register_builtin_type. */
3786 tree registered_builtin_types
;
3788 /* Return a data type that has machine mode MODE.
3789 If the mode is an integer,
3790 then UNSIGNEDP selects between signed and unsigned types.
3791 If the mode is a fixed-point mode,
3792 then UNSIGNEDP selects between saturating and nonsaturating types. */
3795 c_common_type_for_mode (machine_mode mode
, int unsignedp
)
3800 if (mode
== TYPE_MODE (integer_type_node
))
3801 return unsignedp
? unsigned_type_node
: integer_type_node
;
3803 if (mode
== TYPE_MODE (signed_char_type_node
))
3804 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3806 if (mode
== TYPE_MODE (short_integer_type_node
))
3807 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3809 if (mode
== TYPE_MODE (long_integer_type_node
))
3810 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3812 if (mode
== TYPE_MODE (long_long_integer_type_node
))
3813 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3815 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
3816 if (int_n_enabled_p
[i
]
3817 && mode
== int_n_data
[i
].m
)
3818 return (unsignedp
? int_n_trees
[i
].unsigned_type
3819 : int_n_trees
[i
].signed_type
);
3821 if (mode
== TYPE_MODE (widest_integer_literal_type_node
))
3822 return unsignedp
? widest_unsigned_literal_type_node
3823 : widest_integer_literal_type_node
;
3826 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3829 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3832 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3835 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3837 #if HOST_BITS_PER_WIDE_INT >= 64
3838 if (mode
== TYPE_MODE (intTI_type_node
))
3839 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3842 if (mode
== TYPE_MODE (float_type_node
))
3843 return float_type_node
;
3845 if (mode
== TYPE_MODE (double_type_node
))
3846 return double_type_node
;
3848 if (mode
== TYPE_MODE (long_double_type_node
))
3849 return long_double_type_node
;
3851 if (mode
== TYPE_MODE (void_type_node
))
3852 return void_type_node
;
3854 if (mode
== TYPE_MODE (build_pointer_type (char_type_node
)))
3856 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3857 : make_signed_type (GET_MODE_PRECISION (mode
)));
3859 if (mode
== TYPE_MODE (build_pointer_type (integer_type_node
)))
3861 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3862 : make_signed_type (GET_MODE_PRECISION (mode
)));
3864 if (COMPLEX_MODE_P (mode
))
3866 machine_mode inner_mode
;
3869 if (mode
== TYPE_MODE (complex_float_type_node
))
3870 return complex_float_type_node
;
3871 if (mode
== TYPE_MODE (complex_double_type_node
))
3872 return complex_double_type_node
;
3873 if (mode
== TYPE_MODE (complex_long_double_type_node
))
3874 return complex_long_double_type_node
;
3876 if (mode
== TYPE_MODE (complex_integer_type_node
) && !unsignedp
)
3877 return complex_integer_type_node
;
3879 inner_mode
= GET_MODE_INNER (mode
);
3880 inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3881 if (inner_type
!= NULL_TREE
)
3882 return build_complex_type (inner_type
);
3884 else if (VECTOR_MODE_P (mode
))
3886 machine_mode inner_mode
= GET_MODE_INNER (mode
);
3887 tree inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3888 if (inner_type
!= NULL_TREE
)
3889 return build_vector_type_for_mode (inner_type
, mode
);
3892 if (mode
== TYPE_MODE (dfloat32_type_node
))
3893 return dfloat32_type_node
;
3894 if (mode
== TYPE_MODE (dfloat64_type_node
))
3895 return dfloat64_type_node
;
3896 if (mode
== TYPE_MODE (dfloat128_type_node
))
3897 return dfloat128_type_node
;
3899 if (ALL_SCALAR_FIXED_POINT_MODE_P (mode
))
3901 if (mode
== TYPE_MODE (short_fract_type_node
))
3902 return unsignedp
? sat_short_fract_type_node
: short_fract_type_node
;
3903 if (mode
== TYPE_MODE (fract_type_node
))
3904 return unsignedp
? sat_fract_type_node
: fract_type_node
;
3905 if (mode
== TYPE_MODE (long_fract_type_node
))
3906 return unsignedp
? sat_long_fract_type_node
: long_fract_type_node
;
3907 if (mode
== TYPE_MODE (long_long_fract_type_node
))
3908 return unsignedp
? sat_long_long_fract_type_node
3909 : long_long_fract_type_node
;
3911 if (mode
== TYPE_MODE (unsigned_short_fract_type_node
))
3912 return unsignedp
? sat_unsigned_short_fract_type_node
3913 : unsigned_short_fract_type_node
;
3914 if (mode
== TYPE_MODE (unsigned_fract_type_node
))
3915 return unsignedp
? sat_unsigned_fract_type_node
3916 : unsigned_fract_type_node
;
3917 if (mode
== TYPE_MODE (unsigned_long_fract_type_node
))
3918 return unsignedp
? sat_unsigned_long_fract_type_node
3919 : unsigned_long_fract_type_node
;
3920 if (mode
== TYPE_MODE (unsigned_long_long_fract_type_node
))
3921 return unsignedp
? sat_unsigned_long_long_fract_type_node
3922 : unsigned_long_long_fract_type_node
;
3924 if (mode
== TYPE_MODE (short_accum_type_node
))
3925 return unsignedp
? sat_short_accum_type_node
: short_accum_type_node
;
3926 if (mode
== TYPE_MODE (accum_type_node
))
3927 return unsignedp
? sat_accum_type_node
: accum_type_node
;
3928 if (mode
== TYPE_MODE (long_accum_type_node
))
3929 return unsignedp
? sat_long_accum_type_node
: long_accum_type_node
;
3930 if (mode
== TYPE_MODE (long_long_accum_type_node
))
3931 return unsignedp
? sat_long_long_accum_type_node
3932 : long_long_accum_type_node
;
3934 if (mode
== TYPE_MODE (unsigned_short_accum_type_node
))
3935 return unsignedp
? sat_unsigned_short_accum_type_node
3936 : unsigned_short_accum_type_node
;
3937 if (mode
== TYPE_MODE (unsigned_accum_type_node
))
3938 return unsignedp
? sat_unsigned_accum_type_node
3939 : unsigned_accum_type_node
;
3940 if (mode
== TYPE_MODE (unsigned_long_accum_type_node
))
3941 return unsignedp
? sat_unsigned_long_accum_type_node
3942 : unsigned_long_accum_type_node
;
3943 if (mode
== TYPE_MODE (unsigned_long_long_accum_type_node
))
3944 return unsignedp
? sat_unsigned_long_long_accum_type_node
3945 : unsigned_long_long_accum_type_node
;
3948 return unsignedp
? sat_qq_type_node
: qq_type_node
;
3950 return unsignedp
? sat_hq_type_node
: hq_type_node
;
3952 return unsignedp
? sat_sq_type_node
: sq_type_node
;
3954 return unsignedp
? sat_dq_type_node
: dq_type_node
;
3956 return unsignedp
? sat_tq_type_node
: tq_type_node
;
3958 if (mode
== UQQmode
)
3959 return unsignedp
? sat_uqq_type_node
: uqq_type_node
;
3960 if (mode
== UHQmode
)
3961 return unsignedp
? sat_uhq_type_node
: uhq_type_node
;
3962 if (mode
== USQmode
)
3963 return unsignedp
? sat_usq_type_node
: usq_type_node
;
3964 if (mode
== UDQmode
)
3965 return unsignedp
? sat_udq_type_node
: udq_type_node
;
3966 if (mode
== UTQmode
)
3967 return unsignedp
? sat_utq_type_node
: utq_type_node
;
3970 return unsignedp
? sat_ha_type_node
: ha_type_node
;
3972 return unsignedp
? sat_sa_type_node
: sa_type_node
;
3974 return unsignedp
? sat_da_type_node
: da_type_node
;
3976 return unsignedp
? sat_ta_type_node
: ta_type_node
;
3978 if (mode
== UHAmode
)
3979 return unsignedp
? sat_uha_type_node
: uha_type_node
;
3980 if (mode
== USAmode
)
3981 return unsignedp
? sat_usa_type_node
: usa_type_node
;
3982 if (mode
== UDAmode
)
3983 return unsignedp
? sat_uda_type_node
: uda_type_node
;
3984 if (mode
== UTAmode
)
3985 return unsignedp
? sat_uta_type_node
: uta_type_node
;
3988 for (t
= registered_builtin_types
; t
; t
= TREE_CHAIN (t
))
3989 if (TYPE_MODE (TREE_VALUE (t
)) == mode
3990 && !!unsignedp
== !!TYPE_UNSIGNED (TREE_VALUE (t
)))
3991 return TREE_VALUE (t
);
3997 c_common_unsigned_type (tree type
)
3999 return c_common_signed_or_unsigned_type (1, type
);
4002 /* Return a signed type the same as TYPE in other respects. */
4005 c_common_signed_type (tree type
)
4007 return c_common_signed_or_unsigned_type (0, type
);
4010 /* Return a type the same as TYPE except unsigned or
4011 signed according to UNSIGNEDP. */
4014 c_common_signed_or_unsigned_type (int unsignedp
, tree type
)
4019 /* This block of code emulates the behavior of the old
4020 c_common_unsigned_type. In particular, it returns
4021 long_unsigned_type_node if passed a long, even when a int would
4022 have the same size. This is necessary for warnings to work
4023 correctly in archs where sizeof(int) == sizeof(long) */
4025 type1
= TYPE_MAIN_VARIANT (type
);
4026 if (type1
== signed_char_type_node
|| type1
== char_type_node
|| type1
== unsigned_char_type_node
)
4027 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
4028 if (type1
== integer_type_node
|| type1
== unsigned_type_node
)
4029 return unsignedp
? unsigned_type_node
: integer_type_node
;
4030 if (type1
== short_integer_type_node
|| type1
== short_unsigned_type_node
)
4031 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
4032 if (type1
== long_integer_type_node
|| type1
== long_unsigned_type_node
)
4033 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
4034 if (type1
== long_long_integer_type_node
|| type1
== long_long_unsigned_type_node
)
4035 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
4037 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
4038 if (int_n_enabled_p
[i
]
4039 && (type1
== int_n_trees
[i
].unsigned_type
4040 || type1
== int_n_trees
[i
].signed_type
))
4041 return (unsignedp
? int_n_trees
[i
].unsigned_type
4042 : int_n_trees
[i
].signed_type
);
4044 if (type1
== widest_integer_literal_type_node
|| type1
== widest_unsigned_literal_type_node
)
4045 return unsignedp
? widest_unsigned_literal_type_node
: widest_integer_literal_type_node
;
4046 #if HOST_BITS_PER_WIDE_INT >= 64
4047 if (type1
== intTI_type_node
|| type1
== unsigned_intTI_type_node
)
4048 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
4050 if (type1
== intDI_type_node
|| type1
== unsigned_intDI_type_node
)
4051 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
4052 if (type1
== intSI_type_node
|| type1
== unsigned_intSI_type_node
)
4053 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
4054 if (type1
== intHI_type_node
|| type1
== unsigned_intHI_type_node
)
4055 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
4056 if (type1
== intQI_type_node
|| type1
== unsigned_intQI_type_node
)
4057 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
4059 #define C_COMMON_FIXED_TYPES(NAME) \
4060 if (type1 == short_ ## NAME ## _type_node \
4061 || type1 == unsigned_short_ ## NAME ## _type_node) \
4062 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
4063 : short_ ## NAME ## _type_node; \
4064 if (type1 == NAME ## _type_node \
4065 || type1 == unsigned_ ## NAME ## _type_node) \
4066 return unsignedp ? unsigned_ ## NAME ## _type_node \
4067 : NAME ## _type_node; \
4068 if (type1 == long_ ## NAME ## _type_node \
4069 || type1 == unsigned_long_ ## NAME ## _type_node) \
4070 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
4071 : long_ ## NAME ## _type_node; \
4072 if (type1 == long_long_ ## NAME ## _type_node \
4073 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
4074 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
4075 : long_long_ ## NAME ## _type_node;
4077 #define C_COMMON_FIXED_MODE_TYPES(NAME) \
4078 if (type1 == NAME ## _type_node \
4079 || type1 == u ## NAME ## _type_node) \
4080 return unsignedp ? u ## NAME ## _type_node \
4081 : NAME ## _type_node;
4083 #define C_COMMON_FIXED_TYPES_SAT(NAME) \
4084 if (type1 == sat_ ## short_ ## NAME ## _type_node \
4085 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
4086 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
4087 : sat_ ## short_ ## NAME ## _type_node; \
4088 if (type1 == sat_ ## NAME ## _type_node \
4089 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
4090 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
4091 : sat_ ## NAME ## _type_node; \
4092 if (type1 == sat_ ## long_ ## NAME ## _type_node \
4093 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
4094 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
4095 : sat_ ## long_ ## NAME ## _type_node; \
4096 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
4097 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
4098 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
4099 : sat_ ## long_long_ ## NAME ## _type_node;
4101 #define C_COMMON_FIXED_MODE_TYPES_SAT(NAME) \
4102 if (type1 == sat_ ## NAME ## _type_node \
4103 || type1 == sat_ ## u ## NAME ## _type_node) \
4104 return unsignedp ? sat_ ## u ## NAME ## _type_node \
4105 : sat_ ## NAME ## _type_node;
4107 C_COMMON_FIXED_TYPES (fract
);
4108 C_COMMON_FIXED_TYPES_SAT (fract
);
4109 C_COMMON_FIXED_TYPES (accum
);
4110 C_COMMON_FIXED_TYPES_SAT (accum
);
4112 C_COMMON_FIXED_MODE_TYPES (qq
);
4113 C_COMMON_FIXED_MODE_TYPES (hq
);
4114 C_COMMON_FIXED_MODE_TYPES (sq
);
4115 C_COMMON_FIXED_MODE_TYPES (dq
);
4116 C_COMMON_FIXED_MODE_TYPES (tq
);
4117 C_COMMON_FIXED_MODE_TYPES_SAT (qq
);
4118 C_COMMON_FIXED_MODE_TYPES_SAT (hq
);
4119 C_COMMON_FIXED_MODE_TYPES_SAT (sq
);
4120 C_COMMON_FIXED_MODE_TYPES_SAT (dq
);
4121 C_COMMON_FIXED_MODE_TYPES_SAT (tq
);
4122 C_COMMON_FIXED_MODE_TYPES (ha
);
4123 C_COMMON_FIXED_MODE_TYPES (sa
);
4124 C_COMMON_FIXED_MODE_TYPES (da
);
4125 C_COMMON_FIXED_MODE_TYPES (ta
);
4126 C_COMMON_FIXED_MODE_TYPES_SAT (ha
);
4127 C_COMMON_FIXED_MODE_TYPES_SAT (sa
);
4128 C_COMMON_FIXED_MODE_TYPES_SAT (da
);
4129 C_COMMON_FIXED_MODE_TYPES_SAT (ta
);
4131 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
4132 the precision; they have precision set to match their range, but
4133 may use a wider mode to match an ABI. If we change modes, we may
4134 wind up with bad conversions. For INTEGER_TYPEs in C, must check
4135 the precision as well, so as to yield correct results for
4136 bit-field types. C++ does not have these separate bit-field
4137 types, and producing a signed or unsigned variant of an
4138 ENUMERAL_TYPE may cause other problems as well. */
4140 if (!INTEGRAL_TYPE_P (type
)
4141 || TYPE_UNSIGNED (type
) == unsignedp
)
4144 #define TYPE_OK(node) \
4145 (TYPE_MODE (type) == TYPE_MODE (node) \
4146 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
4147 if (TYPE_OK (signed_char_type_node
))
4148 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
4149 if (TYPE_OK (integer_type_node
))
4150 return unsignedp
? unsigned_type_node
: integer_type_node
;
4151 if (TYPE_OK (short_integer_type_node
))
4152 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
4153 if (TYPE_OK (long_integer_type_node
))
4154 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
4155 if (TYPE_OK (long_long_integer_type_node
))
4156 return (unsignedp
? long_long_unsigned_type_node
4157 : long_long_integer_type_node
);
4159 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
4160 if (int_n_enabled_p
[i
]
4161 && TYPE_MODE (type
) == int_n_data
[i
].m
4162 && TYPE_PRECISION (type
) == int_n_data
[i
].bitsize
)
4163 return (unsignedp
? int_n_trees
[i
].unsigned_type
4164 : int_n_trees
[i
].signed_type
);
4166 if (TYPE_OK (widest_integer_literal_type_node
))
4167 return (unsignedp
? widest_unsigned_literal_type_node
4168 : widest_integer_literal_type_node
);
4170 #if HOST_BITS_PER_WIDE_INT >= 64
4171 if (TYPE_OK (intTI_type_node
))
4172 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
4174 if (TYPE_OK (intDI_type_node
))
4175 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
4176 if (TYPE_OK (intSI_type_node
))
4177 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
4178 if (TYPE_OK (intHI_type_node
))
4179 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
4180 if (TYPE_OK (intQI_type_node
))
4181 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
4184 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
4187 /* Build a bit-field integer type for the given WIDTH and UNSIGNEDP. */
4190 c_build_bitfield_integer_type (unsigned HOST_WIDE_INT width
, int unsignedp
)
4194 /* Extended integer types of the same width as a standard type have
4195 lesser rank, so those of the same width as int promote to int or
4196 unsigned int and are valid for printf formats expecting int or
4197 unsigned int. To avoid such special cases, avoid creating
4198 extended integer types for bit-fields if a standard integer type
4200 if (width
== TYPE_PRECISION (integer_type_node
))
4201 return unsignedp
? unsigned_type_node
: integer_type_node
;
4202 if (width
== TYPE_PRECISION (signed_char_type_node
))
4203 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
4204 if (width
== TYPE_PRECISION (short_integer_type_node
))
4205 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
4206 if (width
== TYPE_PRECISION (long_integer_type_node
))
4207 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
4208 if (width
== TYPE_PRECISION (long_long_integer_type_node
))
4209 return (unsignedp
? long_long_unsigned_type_node
4210 : long_long_integer_type_node
);
4211 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
4212 if (int_n_enabled_p
[i
]
4213 && width
== int_n_data
[i
].bitsize
)
4214 return (unsignedp
? int_n_trees
[i
].unsigned_type
4215 : int_n_trees
[i
].signed_type
);
4216 return build_nonstandard_integer_type (width
, unsignedp
);
4219 /* The C version of the register_builtin_type langhook. */
4222 c_register_builtin_type (tree type
, const char* name
)
4226 decl
= build_decl (UNKNOWN_LOCATION
,
4227 TYPE_DECL
, get_identifier (name
), type
);
4228 DECL_ARTIFICIAL (decl
) = 1;
4229 if (!TYPE_NAME (type
))
4230 TYPE_NAME (type
) = decl
;
4233 registered_builtin_types
= tree_cons (0, type
, registered_builtin_types
);
4236 /* Print an error message for invalid operands to arith operation
4237 CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
4238 LOCATION is the location of the message. */
4241 binary_op_error (location_t location
, enum tree_code code
,
4242 tree type0
, tree type1
)
4249 opname
= "+"; break;
4251 opname
= "-"; break;
4253 opname
= "*"; break;
4255 opname
= "max"; break;
4257 opname
= "min"; break;
4259 opname
= "=="; break;
4261 opname
= "!="; break;
4263 opname
= "<="; break;
4265 opname
= ">="; break;
4267 opname
= "<"; break;
4269 opname
= ">"; break;
4271 opname
= "<<"; break;
4273 opname
= ">>"; break;
4274 case TRUNC_MOD_EXPR
:
4275 case FLOOR_MOD_EXPR
:
4276 opname
= "%"; break;
4277 case TRUNC_DIV_EXPR
:
4278 case FLOOR_DIV_EXPR
:
4279 opname
= "/"; break;
4281 opname
= "&"; break;
4283 opname
= "|"; break;
4284 case TRUTH_ANDIF_EXPR
:
4285 opname
= "&&"; break;
4286 case TRUTH_ORIF_EXPR
:
4287 opname
= "||"; break;
4289 opname
= "^"; break;
4294 "invalid operands to binary %s (have %qT and %qT)", opname
,
4298 /* Given an expression as a tree, return its original type. Do this
4299 by stripping any conversion that preserves the sign and precision. */
4301 expr_original_type (tree expr
)
4303 STRIP_SIGN_NOPS (expr
);
4304 return TREE_TYPE (expr
);
4307 /* Subroutine of build_binary_op, used for comparison operations.
4308 See if the operands have both been converted from subword integer types
4309 and, if so, perhaps change them both back to their original type.
4310 This function is also responsible for converting the two operands
4311 to the proper common type for comparison.
4313 The arguments of this function are all pointers to local variables
4314 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
4315 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
4317 LOC is the location of the comparison.
4319 If this function returns nonzero, it means that the comparison has
4320 a constant value. What this function returns is an expression for
4324 shorten_compare (location_t loc
, tree
*op0_ptr
, tree
*op1_ptr
,
4325 tree
*restype_ptr
, enum tree_code
*rescode_ptr
)
4328 tree op0
= *op0_ptr
;
4329 tree op1
= *op1_ptr
;
4330 int unsignedp0
, unsignedp1
;
4332 tree primop0
, primop1
;
4333 enum tree_code code
= *rescode_ptr
;
4335 /* Throw away any conversions to wider types
4336 already present in the operands. */
4338 primop0
= c_common_get_narrower (op0
, &unsignedp0
);
4339 primop1
= c_common_get_narrower (op1
, &unsignedp1
);
4341 /* If primopN is first sign-extended from primopN's precision to opN's
4342 precision, then zero-extended from opN's precision to
4343 *restype_ptr precision, shortenings might be invalid. */
4344 if (TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (TREE_TYPE (op0
))
4345 && TYPE_PRECISION (TREE_TYPE (op0
)) < TYPE_PRECISION (*restype_ptr
)
4347 && TYPE_UNSIGNED (TREE_TYPE (op0
)))
4349 if (TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (TREE_TYPE (op1
))
4350 && TYPE_PRECISION (TREE_TYPE (op1
)) < TYPE_PRECISION (*restype_ptr
)
4352 && TYPE_UNSIGNED (TREE_TYPE (op1
)))
4355 /* Handle the case that OP0 does not *contain* a conversion
4356 but it *requires* conversion to FINAL_TYPE. */
4358 if (op0
== primop0
&& TREE_TYPE (op0
) != *restype_ptr
)
4359 unsignedp0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
4360 if (op1
== primop1
&& TREE_TYPE (op1
) != *restype_ptr
)
4361 unsignedp1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
4363 /* If one of the operands must be floated, we cannot optimize. */
4364 real1
= TREE_CODE (TREE_TYPE (primop0
)) == REAL_TYPE
;
4365 real2
= TREE_CODE (TREE_TYPE (primop1
)) == REAL_TYPE
;
4367 /* If first arg is constant, swap the args (changing operation
4368 so value is preserved), for canonicalization. Don't do this if
4369 the second arg is 0. */
4371 if (TREE_CONSTANT (primop0
)
4372 && !integer_zerop (primop1
) && !real_zerop (primop1
)
4373 && !fixed_zerop (primop1
))
4375 std::swap (primop0
, primop1
);
4376 std::swap (op0
, op1
);
4379 std::swap (unsignedp0
, unsignedp1
);
4380 std::swap (real1
, real2
);
4399 *rescode_ptr
= code
;
4402 /* If comparing an integer against a constant more bits wide,
4403 maybe we can deduce a value of 1 or 0 independent of the data.
4404 Or else truncate the constant now
4405 rather than extend the variable at run time.
4407 This is only interesting if the constant is the wider arg.
4408 Also, it is not safe if the constant is unsigned and the
4409 variable arg is signed, since in this case the variable
4410 would be sign-extended and then regarded as unsigned.
4411 Our technique fails in this case because the lowest/highest
4412 possible unsigned results don't follow naturally from the
4413 lowest/highest possible values of the variable operand.
4414 For just EQ_EXPR and NE_EXPR there is another technique that
4415 could be used: see if the constant can be faithfully represented
4416 in the other operand's type, by truncating it and reextending it
4417 and see if that preserves the constant's value. */
4419 if (!real1
&& !real2
4420 && TREE_CODE (TREE_TYPE (primop0
)) != FIXED_POINT_TYPE
4421 && TREE_CODE (primop1
) == INTEGER_CST
4422 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
))
4424 int min_gt
, max_gt
, min_lt
, max_lt
;
4425 tree maxval
, minval
;
4426 /* 1 if comparison is nominally unsigned. */
4427 int unsignedp
= TYPE_UNSIGNED (*restype_ptr
);
4430 type
= c_common_signed_or_unsigned_type (unsignedp0
,
4431 TREE_TYPE (primop0
));
4433 maxval
= TYPE_MAX_VALUE (type
);
4434 minval
= TYPE_MIN_VALUE (type
);
4436 if (unsignedp
&& !unsignedp0
)
4437 *restype_ptr
= c_common_signed_type (*restype_ptr
);
4439 if (TREE_TYPE (primop1
) != *restype_ptr
)
4441 /* Convert primop1 to target type, but do not introduce
4442 additional overflow. We know primop1 is an int_cst. */
4443 primop1
= force_fit_type (*restype_ptr
,
4446 TYPE_PRECISION (*restype_ptr
),
4447 TYPE_SIGN (TREE_TYPE (primop1
))),
4448 0, TREE_OVERFLOW (primop1
));
4450 if (type
!= *restype_ptr
)
4452 minval
= convert (*restype_ptr
, minval
);
4453 maxval
= convert (*restype_ptr
, maxval
);
4456 min_gt
= tree_int_cst_lt (primop1
, minval
);
4457 max_gt
= tree_int_cst_lt (primop1
, maxval
);
4458 min_lt
= tree_int_cst_lt (minval
, primop1
);
4459 max_lt
= tree_int_cst_lt (maxval
, primop1
);
4462 /* This used to be a switch, but Genix compiler can't handle that. */
4463 if (code
== NE_EXPR
)
4465 if (max_lt
|| min_gt
)
4466 val
= truthvalue_true_node
;
4468 else if (code
== EQ_EXPR
)
4470 if (max_lt
|| min_gt
)
4471 val
= truthvalue_false_node
;
4473 else if (code
== LT_EXPR
)
4476 val
= truthvalue_true_node
;
4478 val
= truthvalue_false_node
;
4480 else if (code
== GT_EXPR
)
4483 val
= truthvalue_true_node
;
4485 val
= truthvalue_false_node
;
4487 else if (code
== LE_EXPR
)
4490 val
= truthvalue_true_node
;
4492 val
= truthvalue_false_node
;
4494 else if (code
== GE_EXPR
)
4497 val
= truthvalue_true_node
;
4499 val
= truthvalue_false_node
;
4502 /* If primop0 was sign-extended and unsigned comparison specd,
4503 we did a signed comparison above using the signed type bounds.
4504 But the comparison we output must be unsigned.
4506 Also, for inequalities, VAL is no good; but if the signed
4507 comparison had *any* fixed result, it follows that the
4508 unsigned comparison just tests the sign in reverse
4509 (positive values are LE, negative ones GE).
4510 So we can generate an unsigned comparison
4511 against an extreme value of the signed type. */
4513 if (unsignedp
&& !unsignedp0
)
4520 primop1
= TYPE_MIN_VALUE (type
);
4526 primop1
= TYPE_MAX_VALUE (type
);
4533 type
= c_common_unsigned_type (type
);
4536 if (TREE_CODE (primop0
) != INTEGER_CST
)
4538 if (val
== truthvalue_false_node
)
4539 warning_at (loc
, OPT_Wtype_limits
,
4540 "comparison is always false due to limited range of data type");
4541 if (val
== truthvalue_true_node
)
4542 warning_at (loc
, OPT_Wtype_limits
,
4543 "comparison is always true due to limited range of data type");
4548 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4549 if (TREE_SIDE_EFFECTS (primop0
))
4550 return build2 (COMPOUND_EXPR
, TREE_TYPE (val
), primop0
, val
);
4554 /* Value is not predetermined, but do the comparison
4555 in the type of the operand that is not constant.
4556 TYPE is already properly set. */
4559 /* If either arg is decimal float and the other is float, find the
4560 proper common type to use for comparison. */
4561 else if (real1
&& real2
4562 && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0
)))
4563 && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1
))))
4564 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
4566 /* If either arg is decimal float and the other is float, fail. */
4567 else if (real1
&& real2
4568 && (DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0
)))
4569 || DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1
)))))
4572 else if (real1
&& real2
4573 && (TYPE_PRECISION (TREE_TYPE (primop0
))
4574 == TYPE_PRECISION (TREE_TYPE (primop1
))))
4575 type
= TREE_TYPE (primop0
);
4577 /* If args' natural types are both narrower than nominal type
4578 and both extend in the same manner, compare them
4579 in the type of the wider arg.
4580 Otherwise must actually extend both to the nominal
4581 common type lest different ways of extending
4583 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
4585 else if (unsignedp0
== unsignedp1
&& real1
== real2
4586 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
)
4587 && TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (*restype_ptr
))
4589 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
4590 type
= c_common_signed_or_unsigned_type (unsignedp0
4591 || TYPE_UNSIGNED (*restype_ptr
),
4593 /* Make sure shorter operand is extended the right way
4594 to match the longer operand. */
4596 = convert (c_common_signed_or_unsigned_type (unsignedp0
,
4597 TREE_TYPE (primop0
)),
4600 = convert (c_common_signed_or_unsigned_type (unsignedp1
,
4601 TREE_TYPE (primop1
)),
4606 /* Here we must do the comparison on the nominal type
4607 using the args exactly as we received them. */
4608 type
= *restype_ptr
;
4612 if (!real1
&& !real2
&& integer_zerop (primop1
)
4613 && TYPE_UNSIGNED (*restype_ptr
))
4616 /* All unsigned values are >= 0, so we warn. However,
4617 if OP0 is a constant that is >= 0, the signedness of
4618 the comparison isn't an issue, so suppress the
4621 warn_type_limits
&& !in_system_header_at (loc
)
4622 && !(TREE_CODE (primop0
) == INTEGER_CST
4623 && !TREE_OVERFLOW (convert (c_common_signed_type (type
),
4625 /* Do not warn for enumeration types. */
4626 && (TREE_CODE (expr_original_type (primop0
)) != ENUMERAL_TYPE
);
4632 warning_at (loc
, OPT_Wtype_limits
,
4633 "comparison of unsigned expression >= 0 is always true");
4634 value
= truthvalue_true_node
;
4639 warning_at (loc
, OPT_Wtype_limits
,
4640 "comparison of unsigned expression < 0 is always false");
4641 value
= truthvalue_false_node
;
4650 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4651 if (TREE_SIDE_EFFECTS (primop0
))
4652 return build2 (COMPOUND_EXPR
, TREE_TYPE (value
),
4659 *op0_ptr
= convert (type
, primop0
);
4660 *op1_ptr
= convert (type
, primop1
);
4662 *restype_ptr
= truthvalue_type_node
;
4667 /* Return a tree for the sum or difference (RESULTCODE says which)
4668 of pointer PTROP and integer INTOP. */
4671 pointer_int_sum (location_t loc
, enum tree_code resultcode
,
4672 tree ptrop
, tree intop
, bool complain
)
4676 /* The result is a pointer of the same type that is being added. */
4677 tree result_type
= TREE_TYPE (ptrop
);
4679 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
4681 if (complain
&& warn_pointer_arith
)
4682 pedwarn (loc
, OPT_Wpointer_arith
,
4683 "pointer of type %<void *%> used in arithmetic");
4685 return error_mark_node
;
4686 size_exp
= integer_one_node
;
4688 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
4690 if (complain
&& warn_pointer_arith
)
4691 pedwarn (loc
, OPT_Wpointer_arith
,
4692 "pointer to a function used in arithmetic");
4694 return error_mark_node
;
4695 size_exp
= integer_one_node
;
4698 size_exp
= size_in_bytes (TREE_TYPE (result_type
));
4700 /* We are manipulating pointer values, so we don't need to warn
4701 about relying on undefined signed overflow. We disable the
4702 warning here because we use integer types so fold won't know that
4703 they are really pointers. */
4704 fold_defer_overflow_warnings ();
4706 /* If what we are about to multiply by the size of the elements
4707 contains a constant term, apply distributive law
4708 and multiply that constant term separately.
4709 This helps produce common subexpressions. */
4710 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
4711 && !TREE_CONSTANT (intop
)
4712 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
4713 && TREE_CONSTANT (size_exp
)
4714 /* If the constant comes from pointer subtraction,
4715 skip this optimization--it would cause an error. */
4716 && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop
, 0))) == INTEGER_TYPE
4717 /* If the constant is unsigned, and smaller than the pointer size,
4718 then we must skip this optimization. This is because it could cause
4719 an overflow error if the constant is negative but INTOP is not. */
4720 && (!TYPE_UNSIGNED (TREE_TYPE (intop
))
4721 || (TYPE_PRECISION (TREE_TYPE (intop
))
4722 == TYPE_PRECISION (TREE_TYPE (ptrop
)))))
4724 enum tree_code subcode
= resultcode
;
4725 tree int_type
= TREE_TYPE (intop
);
4726 if (TREE_CODE (intop
) == MINUS_EXPR
)
4727 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
4728 /* Convert both subexpression types to the type of intop,
4729 because weird cases involving pointer arithmetic
4730 can result in a sum or difference with different type args. */
4731 ptrop
= build_binary_op (EXPR_LOCATION (TREE_OPERAND (intop
, 1)),
4733 convert (int_type
, TREE_OPERAND (intop
, 1)), 1);
4734 intop
= convert (int_type
, TREE_OPERAND (intop
, 0));
4737 /* Convert the integer argument to a type the same size as sizetype
4738 so the multiply won't overflow spuriously. */
4739 if (TYPE_PRECISION (TREE_TYPE (intop
)) != TYPE_PRECISION (sizetype
)
4740 || TYPE_UNSIGNED (TREE_TYPE (intop
)) != TYPE_UNSIGNED (sizetype
))
4741 intop
= convert (c_common_type_for_size (TYPE_PRECISION (sizetype
),
4742 TYPE_UNSIGNED (sizetype
)), intop
);
4744 /* Replace the integer argument with a suitable product by the object size.
4745 Do this multiplication as signed, then convert to the appropriate type
4746 for the pointer operation and disregard an overflow that occurred only
4747 because of the sign-extension change in the latter conversion. */
4749 tree t
= build_binary_op (loc
,
4751 convert (TREE_TYPE (intop
), size_exp
), 1);
4752 intop
= convert (sizetype
, t
);
4753 if (TREE_OVERFLOW_P (intop
) && !TREE_OVERFLOW (t
))
4754 intop
= wide_int_to_tree (TREE_TYPE (intop
), intop
);
4757 /* Create the sum or difference. */
4758 if (resultcode
== MINUS_EXPR
)
4759 intop
= fold_build1_loc (loc
, NEGATE_EXPR
, sizetype
, intop
);
4761 ret
= fold_build_pointer_plus_loc (loc
, ptrop
, intop
);
4763 fold_undefer_and_ignore_overflow_warnings ();
4768 /* Wrap a C_MAYBE_CONST_EXPR around an expression that is fully folded
4769 and if NON_CONST is known not to be permitted in an evaluated part
4770 of a constant expression. */
4773 c_wrap_maybe_const (tree expr
, bool non_const
)
4775 bool nowarning
= TREE_NO_WARNING (expr
);
4776 location_t loc
= EXPR_LOCATION (expr
);
4778 /* This should never be called for C++. */
4779 if (c_dialect_cxx ())
4782 /* The result of folding may have a NOP_EXPR to set TREE_NO_WARNING. */
4783 STRIP_TYPE_NOPS (expr
);
4784 expr
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (expr
), NULL
, expr
);
4785 C_MAYBE_CONST_EXPR_NON_CONST (expr
) = non_const
;
4787 TREE_NO_WARNING (expr
) = 1;
4788 protected_set_expr_location (expr
, loc
);
4793 /* Wrap a SAVE_EXPR around EXPR, if appropriate. Like save_expr, but
4794 for C folds the inside expression and wraps a C_MAYBE_CONST_EXPR
4795 around the SAVE_EXPR if needed so that c_fully_fold does not need
4796 to look inside SAVE_EXPRs. */
4799 c_save_expr (tree expr
)
4801 bool maybe_const
= true;
4802 if (c_dialect_cxx ())
4803 return save_expr (expr
);
4804 expr
= c_fully_fold (expr
, false, &maybe_const
);
4805 expr
= save_expr (expr
);
4807 expr
= c_wrap_maybe_const (expr
, true);
4811 /* Return whether EXPR is a declaration whose address can never be
4815 decl_with_nonnull_addr_p (const_tree expr
)
4817 return (DECL_P (expr
)
4818 && (TREE_CODE (expr
) == PARM_DECL
4819 || TREE_CODE (expr
) == LABEL_DECL
4820 || !DECL_WEAK (expr
)));
4823 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
4824 or for an `if' or `while' statement or ?..: exp. It should already
4825 have been validated to be of suitable type; otherwise, a bad
4826 diagnostic may result.
4828 The EXPR is located at LOCATION.
4830 This preparation consists of taking the ordinary
4831 representation of an expression expr and producing a valid tree
4832 boolean expression describing whether expr is nonzero. We could
4833 simply always do build_binary_op (NE_EXPR, expr, truthvalue_false_node, 1),
4834 but we optimize comparisons, &&, ||, and !.
4836 The resulting type should always be `truthvalue_type_node'. */
4839 c_common_truthvalue_conversion (location_t location
, tree expr
)
4841 switch (TREE_CODE (expr
))
4843 case EQ_EXPR
: case NE_EXPR
: case UNEQ_EXPR
: case LTGT_EXPR
:
4844 case LE_EXPR
: case GE_EXPR
: case LT_EXPR
: case GT_EXPR
:
4845 case UNLE_EXPR
: case UNGE_EXPR
: case UNLT_EXPR
: case UNGT_EXPR
:
4846 case ORDERED_EXPR
: case UNORDERED_EXPR
:
4847 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4849 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4850 TREE_OPERAND (expr
, 0), TREE_OPERAND (expr
, 1));
4853 case TRUTH_ANDIF_EXPR
:
4854 case TRUTH_ORIF_EXPR
:
4855 case TRUTH_AND_EXPR
:
4857 case TRUTH_XOR_EXPR
:
4858 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4860 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4861 c_common_truthvalue_conversion (location
,
4862 TREE_OPERAND (expr
, 0)),
4863 c_common_truthvalue_conversion (location
,
4864 TREE_OPERAND (expr
, 1)));
4867 case TRUTH_NOT_EXPR
:
4868 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4870 expr
= build1 (TREE_CODE (expr
), truthvalue_type_node
,
4871 c_common_truthvalue_conversion (location
,
4872 TREE_OPERAND (expr
, 0)));
4879 return integer_zerop (expr
) ? truthvalue_false_node
4880 : truthvalue_true_node
;
4883 return real_compare (NE_EXPR
, &TREE_REAL_CST (expr
), &dconst0
)
4884 ? truthvalue_true_node
4885 : truthvalue_false_node
;
4888 return fixed_compare (NE_EXPR
, &TREE_FIXED_CST (expr
),
4889 &FCONST0 (TYPE_MODE (TREE_TYPE (expr
))))
4890 ? truthvalue_true_node
4891 : truthvalue_false_node
;
4894 expr
= build_unary_op (location
, ADDR_EXPR
, expr
, 0);
4899 tree inner
= TREE_OPERAND (expr
, 0);
4900 if (decl_with_nonnull_addr_p (inner
))
4902 /* Common Ada/Pascal programmer's mistake. */
4903 warning_at (location
,
4905 "the address of %qD will always evaluate as %<true%>",
4907 return truthvalue_true_node
;
4913 expr
= build_binary_op (EXPR_LOCATION (expr
),
4914 (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1))
4915 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4916 c_common_truthvalue_conversion (location
,
4917 TREE_OPERAND (expr
, 0)),
4918 c_common_truthvalue_conversion (location
,
4919 TREE_OPERAND (expr
, 1)),
4926 case EXCESS_PRECISION_EXPR
:
4927 /* These don't change whether an object is nonzero or zero. */
4928 return c_common_truthvalue_conversion (location
, TREE_OPERAND (expr
, 0));
4932 /* These don't change whether an object is zero or nonzero, but
4933 we can't ignore them if their second arg has side-effects. */
4934 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1)))
4936 expr
= build2 (COMPOUND_EXPR
, truthvalue_type_node
,
4937 TREE_OPERAND (expr
, 1),
4938 c_common_truthvalue_conversion
4939 (location
, TREE_OPERAND (expr
, 0)));
4943 return c_common_truthvalue_conversion (location
,
4944 TREE_OPERAND (expr
, 0));
4947 /* Distribute the conversion into the arms of a COND_EXPR. */
4948 if (c_dialect_cxx ())
4950 tree op1
= TREE_OPERAND (expr
, 1);
4951 tree op2
= TREE_OPERAND (expr
, 2);
4952 /* In C++ one of the arms might have void type if it is throw. */
4953 if (!VOID_TYPE_P (TREE_TYPE (op1
)))
4954 op1
= c_common_truthvalue_conversion (location
, op1
);
4955 if (!VOID_TYPE_P (TREE_TYPE (op2
)))
4956 op2
= c_common_truthvalue_conversion (location
, op2
);
4957 expr
= fold_build3_loc (location
, COND_EXPR
, truthvalue_type_node
,
4958 TREE_OPERAND (expr
, 0), op1
, op2
);
4963 /* Folding will happen later for C. */
4964 expr
= build3 (COND_EXPR
, truthvalue_type_node
,
4965 TREE_OPERAND (expr
, 0),
4966 c_common_truthvalue_conversion (location
,
4967 TREE_OPERAND (expr
, 1)),
4968 c_common_truthvalue_conversion (location
,
4969 TREE_OPERAND (expr
, 2)));
4975 tree totype
= TREE_TYPE (expr
);
4976 tree fromtype
= TREE_TYPE (TREE_OPERAND (expr
, 0));
4978 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
4979 since that affects how `default_conversion' will behave. */
4980 if (TREE_CODE (totype
) == REFERENCE_TYPE
4981 || TREE_CODE (fromtype
) == REFERENCE_TYPE
)
4983 /* Don't strip a conversion from C++0x scoped enum, since they
4984 don't implicitly convert to other types. */
4985 if (TREE_CODE (fromtype
) == ENUMERAL_TYPE
4986 && ENUM_IS_SCOPED (fromtype
))
4988 /* If this isn't narrowing the argument, we can ignore it. */
4989 if (TYPE_PRECISION (totype
) >= TYPE_PRECISION (fromtype
))
4990 return c_common_truthvalue_conversion (location
,
4991 TREE_OPERAND (expr
, 0));
4996 if (!TREE_NO_WARNING (expr
)
4997 && warn_parentheses
)
4999 warning (OPT_Wparentheses
,
5000 "suggest parentheses around assignment used as truth value");
5001 TREE_NO_WARNING (expr
) = 1;
5009 if (TREE_CODE (TREE_TYPE (expr
)) == COMPLEX_TYPE
)
5011 tree t
= (in_late_binary_op
? save_expr (expr
) : c_save_expr (expr
));
5012 expr
= (build_binary_op
5013 (EXPR_LOCATION (expr
),
5014 (TREE_SIDE_EFFECTS (expr
)
5015 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
5016 c_common_truthvalue_conversion
5018 build_unary_op (location
, REALPART_EXPR
, t
, 0)),
5019 c_common_truthvalue_conversion
5021 build_unary_op (location
, IMAGPART_EXPR
, t
, 0)),
5026 if (TREE_CODE (TREE_TYPE (expr
)) == FIXED_POINT_TYPE
)
5028 tree fixed_zero_node
= build_fixed (TREE_TYPE (expr
),
5030 (TREE_TYPE (expr
))));
5031 return build_binary_op (location
, NE_EXPR
, expr
, fixed_zero_node
, 1);
5034 return build_binary_op (location
, NE_EXPR
, expr
, integer_zero_node
, 1);
5037 protected_set_expr_location (expr
, location
);
5041 static void def_builtin_1 (enum built_in_function fncode
,
5043 enum built_in_class fnclass
,
5044 tree fntype
, tree libtype
,
5045 bool both_p
, bool fallback_p
, bool nonansi_p
,
5046 tree fnattrs
, bool implicit_p
);
5049 /* Apply the TYPE_QUALS to the new DECL. */
5052 c_apply_type_quals_to_decl (int type_quals
, tree decl
)
5054 tree type
= TREE_TYPE (decl
);
5056 if (type
== error_mark_node
)
5059 if ((type_quals
& TYPE_QUAL_CONST
)
5060 || (type
&& TREE_CODE (type
) == REFERENCE_TYPE
))
5061 /* We used to check TYPE_NEEDS_CONSTRUCTING here, but now a constexpr
5062 constructor can produce constant init, so rely on cp_finish_decl to
5063 clear TREE_READONLY if the variable has non-constant init. */
5064 TREE_READONLY (decl
) = 1;
5065 if (type_quals
& TYPE_QUAL_VOLATILE
)
5067 TREE_SIDE_EFFECTS (decl
) = 1;
5068 TREE_THIS_VOLATILE (decl
) = 1;
5070 if (type_quals
& TYPE_QUAL_RESTRICT
)
5072 while (type
&& TREE_CODE (type
) == ARRAY_TYPE
)
5073 /* Allow 'restrict' on arrays of pointers.
5074 FIXME currently we just ignore it. */
5075 type
= TREE_TYPE (type
);
5077 || !POINTER_TYPE_P (type
)
5078 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type
)))
5079 error ("invalid use of %<restrict%>");
5083 struct c_type_hasher
: ggc_hasher
<tree
>
5085 static hashval_t
hash (tree
);
5086 static bool equal (tree
, tree
);
5089 /* Hash function for the problem of multiple type definitions in
5090 different files. This must hash all types that will compare
5091 equal via comptypes to the same value. In practice it hashes
5092 on some of the simple stuff and leaves the details to comptypes. */
5095 c_type_hasher::hash (tree t
)
5100 switch (TREE_CODE (t
))
5102 /* For pointers, hash on pointee type plus some swizzling. */
5104 return hash (TREE_TYPE (t
)) ^ 0x3003003;
5105 /* Hash on number of elements and total size. */
5108 t2
= TYPE_VALUES (t
);
5112 t2
= TYPE_FIELDS (t
);
5114 case QUAL_UNION_TYPE
:
5116 t2
= TYPE_FIELDS (t
);
5120 t2
= TYPE_FIELDS (t
);
5125 /* FIXME: We want to use a DECL_CHAIN iteration method here, but
5126 TYPE_VALUES of ENUMERAL_TYPEs is stored as a TREE_LIST. */
5127 n_elements
= list_length (t2
);
5128 /* We might have a VLA here. */
5129 if (TREE_CODE (TYPE_SIZE (t
)) != INTEGER_CST
)
5132 size
= TREE_INT_CST_LOW (TYPE_SIZE (t
));
5133 return ((size
<< 24) | (n_elements
<< shift
));
5137 c_type_hasher::equal (tree t1
, tree t2
)
5139 return lang_hooks
.types_compatible_p (t1
, t2
);
5142 static GTY(()) hash_table
<c_type_hasher
> *type_hash_table
;
5144 /* Return the typed-based alias set for T, which may be an expression
5145 or a type. Return -1 if we don't do anything special. */
5148 c_common_get_alias_set (tree t
)
5152 /* For VLAs, use the alias set of the element type rather than the
5153 default of alias set 0 for types compared structurally. */
5154 if (TYPE_P (t
) && TYPE_STRUCTURAL_EQUALITY_P (t
))
5156 if (TREE_CODE (t
) == ARRAY_TYPE
)
5157 return get_alias_set (TREE_TYPE (t
));
5161 /* Permit type-punning when accessing a union, provided the access
5162 is directly through the union. For example, this code does not
5163 permit taking the address of a union member and then storing
5164 through it. Even the type-punning allowed here is a GCC
5165 extension, albeit a common and useful one; the C standard says
5166 that such accesses have implementation-defined behavior. */
5168 TREE_CODE (u
) == COMPONENT_REF
|| TREE_CODE (u
) == ARRAY_REF
;
5169 u
= TREE_OPERAND (u
, 0))
5170 if (TREE_CODE (u
) == COMPONENT_REF
5171 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u
, 0))) == UNION_TYPE
)
5174 /* That's all the expressions we handle specially. */
5178 /* The C standard guarantees that any object may be accessed via an
5179 lvalue that has character type. */
5180 if (t
== char_type_node
5181 || t
== signed_char_type_node
5182 || t
== unsigned_char_type_node
)
5185 /* The C standard specifically allows aliasing between signed and
5186 unsigned variants of the same type. We treat the signed
5187 variant as canonical. */
5188 if (TREE_CODE (t
) == INTEGER_TYPE
&& TYPE_UNSIGNED (t
))
5190 tree t1
= c_common_signed_type (t
);
5192 /* t1 == t can happen for boolean nodes which are always unsigned. */
5194 return get_alias_set (t1
);
5197 /* Handle the case of multiple type nodes referring to "the same" type,
5198 which occurs with IMA. These share an alias set. FIXME: Currently only
5199 C90 is handled. (In C99 type compatibility is not transitive, which
5200 complicates things mightily. The alias set splay trees can theoretically
5201 represent this, but insertion is tricky when you consider all the
5202 different orders things might arrive in.) */
5204 if (c_language
!= clk_c
|| flag_isoc99
)
5207 /* Save time if there's only one input file. */
5208 if (num_in_fnames
== 1)
5211 /* Pointers need special handling if they point to any type that
5212 needs special handling (below). */
5213 if (TREE_CODE (t
) == POINTER_TYPE
)
5216 /* Find bottom type under any nested POINTERs. */
5217 for (t2
= TREE_TYPE (t
);
5218 TREE_CODE (t2
) == POINTER_TYPE
;
5219 t2
= TREE_TYPE (t2
))
5221 if (TREE_CODE (t2
) != RECORD_TYPE
5222 && TREE_CODE (t2
) != ENUMERAL_TYPE
5223 && TREE_CODE (t2
) != QUAL_UNION_TYPE
5224 && TREE_CODE (t2
) != UNION_TYPE
)
5226 if (TYPE_SIZE (t2
) == 0)
5229 /* These are the only cases that need special handling. */
5230 if (TREE_CODE (t
) != RECORD_TYPE
5231 && TREE_CODE (t
) != ENUMERAL_TYPE
5232 && TREE_CODE (t
) != QUAL_UNION_TYPE
5233 && TREE_CODE (t
) != UNION_TYPE
5234 && TREE_CODE (t
) != POINTER_TYPE
)
5237 if (TYPE_SIZE (t
) == 0)
5240 /* Look up t in hash table. Only one of the compatible types within each
5241 alias set is recorded in the table. */
5242 if (!type_hash_table
)
5243 type_hash_table
= hash_table
<c_type_hasher
>::create_ggc (1021);
5244 tree
*slot
= type_hash_table
->find_slot (t
, INSERT
);
5247 TYPE_ALIAS_SET (t
) = TYPE_ALIAS_SET ((tree
)*slot
);
5248 return TYPE_ALIAS_SET ((tree
)*slot
);
5251 /* Our caller will assign and record (in t) a new alias set; all we need
5252 to do is remember t in the hash table. */
5258 /* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where
5259 the IS_SIZEOF parameter indicates which operator is being applied.
5260 The COMPLAIN flag controls whether we should diagnose possibly
5261 ill-formed constructs or not. LOC is the location of the SIZEOF or
5262 TYPEOF operator. If MIN_ALIGNOF, the least alignment required for
5263 a type in any context should be returned, rather than the normal
5264 alignment for that type. */
5267 c_sizeof_or_alignof_type (location_t loc
,
5268 tree type
, bool is_sizeof
, bool min_alignof
,
5271 const char *op_name
;
5273 enum tree_code type_code
= TREE_CODE (type
);
5275 op_name
= is_sizeof
? "sizeof" : "__alignof__";
5277 if (type_code
== FUNCTION_TYPE
)
5281 if (complain
&& warn_pointer_arith
)
5282 pedwarn (loc
, OPT_Wpointer_arith
,
5283 "invalid application of %<sizeof%> to a function type");
5285 return error_mark_node
;
5286 value
= size_one_node
;
5292 if (c_dialect_cxx ())
5293 pedwarn (loc
, OPT_Wpedantic
, "ISO C++ does not permit "
5294 "%<alignof%> applied to a function type");
5296 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not permit "
5297 "%<_Alignof%> applied to a function type");
5299 value
= size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
5302 else if (type_code
== VOID_TYPE
|| type_code
== ERROR_MARK
)
5304 if (type_code
== VOID_TYPE
5305 && complain
&& warn_pointer_arith
)
5306 pedwarn (loc
, OPT_Wpointer_arith
,
5307 "invalid application of %qs to a void type", op_name
);
5309 return error_mark_node
;
5310 value
= size_one_node
;
5312 else if (!COMPLETE_TYPE_P (type
)
5313 && (!c_dialect_cxx () || is_sizeof
|| type_code
!= ARRAY_TYPE
))
5316 error_at (loc
, "invalid application of %qs to incomplete type %qT",
5318 return error_mark_node
;
5320 else if (c_dialect_cxx () && type_code
== ARRAY_TYPE
5321 && !COMPLETE_TYPE_P (TREE_TYPE (type
)))
5324 error_at (loc
, "invalid application of %qs to array type %qT of "
5325 "incomplete element type", op_name
, type
);
5326 return error_mark_node
;
5331 /* Convert in case a char is more than one unit. */
5332 value
= size_binop_loc (loc
, CEIL_DIV_EXPR
, TYPE_SIZE_UNIT (type
),
5333 size_int (TYPE_PRECISION (char_type_node
)
5335 else if (min_alignof
)
5336 value
= size_int (min_align_of_type (type
));
5338 value
= size_int (TYPE_ALIGN_UNIT (type
));
5341 /* VALUE will have the middle-end integer type sizetype.
5342 However, we should really return a value of type `size_t',
5343 which is just a typedef for an ordinary integer type. */
5344 value
= fold_convert_loc (loc
, size_type_node
, value
);
5349 /* Implement the __alignof keyword: Return the minimum required
5350 alignment of EXPR, measured in bytes. For VAR_DECLs,
5351 FUNCTION_DECLs and FIELD_DECLs return DECL_ALIGN (which can be set
5352 from an "aligned" __attribute__ specification). LOC is the
5353 location of the ALIGNOF operator. */
5356 c_alignof_expr (location_t loc
, tree expr
)
5360 if (VAR_OR_FUNCTION_DECL_P (expr
))
5361 t
= size_int (DECL_ALIGN_UNIT (expr
));
5363 else if (TREE_CODE (expr
) == COMPONENT_REF
5364 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
, 1)))
5366 error_at (loc
, "%<__alignof%> applied to a bit-field");
5369 else if (TREE_CODE (expr
) == COMPONENT_REF
5370 && TREE_CODE (TREE_OPERAND (expr
, 1)) == FIELD_DECL
)
5371 t
= size_int (DECL_ALIGN_UNIT (TREE_OPERAND (expr
, 1)));
5373 else if (TREE_CODE (expr
) == INDIRECT_REF
)
5375 tree t
= TREE_OPERAND (expr
, 0);
5377 int bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
5379 while (CONVERT_EXPR_P (t
)
5380 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
5384 t
= TREE_OPERAND (t
, 0);
5385 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
5386 if (thisalign
> bestalign
)
5387 best
= t
, bestalign
= thisalign
;
5389 return c_alignof (loc
, TREE_TYPE (TREE_TYPE (best
)));
5392 return c_alignof (loc
, TREE_TYPE (expr
));
5394 return fold_convert_loc (loc
, size_type_node
, t
);
5397 /* Handle C and C++ default attributes. */
5399 enum built_in_attribute
5401 #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
5402 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
5403 #define DEF_ATTR_STRING(ENUM, VALUE) ENUM,
5404 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
5405 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
5406 #include "builtin-attrs.def"
5407 #undef DEF_ATTR_NULL_TREE
5409 #undef DEF_ATTR_STRING
5410 #undef DEF_ATTR_IDENT
5411 #undef DEF_ATTR_TREE_LIST
5415 static GTY(()) tree built_in_attributes
[(int) ATTR_LAST
];
5417 static void c_init_attributes (void);
5421 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
5422 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
5423 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
5424 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
5425 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
5426 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
5427 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
5428 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5430 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5432 #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5433 ARG6, ARG7, ARG8) NAME,
5434 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
5435 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
5436 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
5437 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
5438 #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
5439 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5441 #define DEF_FUNCTION_TYPE_VAR_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5443 #define DEF_FUNCTION_TYPE_VAR_11(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5444 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) NAME,
5445 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
5446 #include "builtin-types.def"
5447 #undef DEF_PRIMITIVE_TYPE
5448 #undef DEF_FUNCTION_TYPE_0
5449 #undef DEF_FUNCTION_TYPE_1
5450 #undef DEF_FUNCTION_TYPE_2
5451 #undef DEF_FUNCTION_TYPE_3
5452 #undef DEF_FUNCTION_TYPE_4
5453 #undef DEF_FUNCTION_TYPE_5
5454 #undef DEF_FUNCTION_TYPE_6
5455 #undef DEF_FUNCTION_TYPE_7
5456 #undef DEF_FUNCTION_TYPE_8
5457 #undef DEF_FUNCTION_TYPE_VAR_0
5458 #undef DEF_FUNCTION_TYPE_VAR_1
5459 #undef DEF_FUNCTION_TYPE_VAR_2
5460 #undef DEF_FUNCTION_TYPE_VAR_3
5461 #undef DEF_FUNCTION_TYPE_VAR_4
5462 #undef DEF_FUNCTION_TYPE_VAR_5
5463 #undef DEF_FUNCTION_TYPE_VAR_7
5464 #undef DEF_FUNCTION_TYPE_VAR_11
5465 #undef DEF_POINTER_TYPE
5469 typedef enum c_builtin_type builtin_type
;
5471 /* A temporary array for c_common_nodes_and_builtins. Used in
5472 communication with def_fn_type. */
5473 static tree builtin_types
[(int) BT_LAST
+ 1];
5475 /* A helper function for c_common_nodes_and_builtins. Build function type
5476 for DEF with return type RET and N arguments. If VAR is true, then the
5477 function should be variadic after those N arguments.
5479 Takes special care not to ICE if any of the types involved are
5480 error_mark_node, which indicates that said type is not in fact available
5481 (see builtin_type_for_size). In which case the function type as a whole
5482 should be error_mark_node. */
5485 def_fn_type (builtin_type def
, builtin_type ret
, bool var
, int n
, ...)
5488 tree
*args
= XALLOCAVEC (tree
, n
);
5493 for (i
= 0; i
< n
; ++i
)
5495 builtin_type a
= (builtin_type
) va_arg (list
, int);
5496 t
= builtin_types
[a
];
5497 if (t
== error_mark_node
)
5502 t
= builtin_types
[ret
];
5503 if (t
== error_mark_node
)
5506 t
= build_varargs_function_type_array (t
, n
, args
);
5508 t
= build_function_type_array (t
, n
, args
);
5511 builtin_types
[def
] = t
;
5515 /* Build builtin functions common to both C and C++ language
5519 c_define_builtins (tree va_list_ref_type_node
, tree va_list_arg_type_node
)
5521 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
5522 builtin_types[ENUM] = VALUE;
5523 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
5524 def_fn_type (ENUM, RETURN, 0, 0);
5525 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
5526 def_fn_type (ENUM, RETURN, 0, 1, ARG1);
5527 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
5528 def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
5529 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
5530 def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
5531 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
5532 def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
5533 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5534 def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
5535 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5537 def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
5538 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5540 def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
5541 #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5543 def_fn_type (ENUM, RETURN, 0, 8, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
5545 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
5546 def_fn_type (ENUM, RETURN, 1, 0);
5547 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
5548 def_fn_type (ENUM, RETURN, 1, 1, ARG1);
5549 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
5550 def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
5551 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
5552 def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
5553 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
5554 def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
5555 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5556 def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
5557 #define DEF_FUNCTION_TYPE_VAR_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5559 def_fn_type (ENUM, RETURN, 1, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
5560 #define DEF_FUNCTION_TYPE_VAR_11(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5561 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) \
5562 def_fn_type (ENUM, RETURN, 1, 11, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
5563 ARG7, ARG8, ARG9, ARG10, ARG11);
5564 #define DEF_POINTER_TYPE(ENUM, TYPE) \
5565 builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
5567 #include "builtin-types.def"
5569 #undef DEF_PRIMITIVE_TYPE
5570 #undef DEF_FUNCTION_TYPE_0
5571 #undef DEF_FUNCTION_TYPE_1
5572 #undef DEF_FUNCTION_TYPE_2
5573 #undef DEF_FUNCTION_TYPE_3
5574 #undef DEF_FUNCTION_TYPE_4
5575 #undef DEF_FUNCTION_TYPE_5
5576 #undef DEF_FUNCTION_TYPE_6
5577 #undef DEF_FUNCTION_TYPE_7
5578 #undef DEF_FUNCTION_TYPE_8
5579 #undef DEF_FUNCTION_TYPE_VAR_0
5580 #undef DEF_FUNCTION_TYPE_VAR_1
5581 #undef DEF_FUNCTION_TYPE_VAR_2
5582 #undef DEF_FUNCTION_TYPE_VAR_3
5583 #undef DEF_FUNCTION_TYPE_VAR_4
5584 #undef DEF_FUNCTION_TYPE_VAR_5
5585 #undef DEF_FUNCTION_TYPE_VAR_7
5586 #undef DEF_FUNCTION_TYPE_VAR_11
5587 #undef DEF_POINTER_TYPE
5588 builtin_types
[(int) BT_LAST
] = NULL_TREE
;
5590 c_init_attributes ();
5592 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P, \
5593 NONANSI_P, ATTRS, IMPLICIT, COND) \
5595 def_builtin_1 (ENUM, NAME, CLASS, \
5596 builtin_types[(int) TYPE], \
5597 builtin_types[(int) LIBTYPE], \
5598 BOTH_P, FALLBACK_P, NONANSI_P, \
5599 built_in_attributes[(int) ATTRS], IMPLICIT);
5600 #include "builtins.def"
5603 targetm
.init_builtins ();
5605 build_common_builtin_nodes ();
5608 cilk_init_builtins ();
5611 /* Like get_identifier, but avoid warnings about null arguments when
5612 the argument may be NULL for targets where GCC lacks stdint.h type
5616 c_get_ident (const char *id
)
5618 return get_identifier (id
);
5621 /* Build tree nodes and builtin functions common to both C and C++ language
5625 c_common_nodes_and_builtins (void)
5627 int char16_type_size
;
5628 int char32_type_size
;
5629 int wchar_type_size
;
5630 tree array_domain_type
;
5631 tree va_list_ref_type_node
;
5632 tree va_list_arg_type_node
;
5635 build_common_tree_nodes (flag_signed_char
, flag_short_double
);
5637 /* Define `int' and `char' first so that dbx will output them first. */
5638 record_builtin_type (RID_INT
, NULL
, integer_type_node
);
5639 record_builtin_type (RID_CHAR
, "char", char_type_node
);
5641 /* `signed' is the same as `int'. FIXME: the declarations of "signed",
5642 "unsigned long", "long long unsigned" and "unsigned short" were in C++
5643 but not C. Are the conditionals here needed? */
5644 if (c_dialect_cxx ())
5645 record_builtin_type (RID_SIGNED
, NULL
, integer_type_node
);
5646 record_builtin_type (RID_LONG
, "long int", long_integer_type_node
);
5647 record_builtin_type (RID_UNSIGNED
, "unsigned int", unsigned_type_node
);
5648 record_builtin_type (RID_MAX
, "long unsigned int",
5649 long_unsigned_type_node
);
5651 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
5655 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
5656 record_builtin_type ((enum rid
)(RID_FIRST_INT_N
+ i
), name
,
5657 int_n_trees
[i
].signed_type
);
5658 sprintf (name
, "__int%d unsigned", int_n_data
[i
].bitsize
);
5659 record_builtin_type (RID_MAX
, name
, int_n_trees
[i
].unsigned_type
);
5662 if (c_dialect_cxx ())
5663 record_builtin_type (RID_MAX
, "unsigned long", long_unsigned_type_node
);
5664 record_builtin_type (RID_MAX
, "long long int",
5665 long_long_integer_type_node
);
5666 record_builtin_type (RID_MAX
, "long long unsigned int",
5667 long_long_unsigned_type_node
);
5668 if (c_dialect_cxx ())
5669 record_builtin_type (RID_MAX
, "long long unsigned",
5670 long_long_unsigned_type_node
);
5671 record_builtin_type (RID_SHORT
, "short int", short_integer_type_node
);
5672 record_builtin_type (RID_MAX
, "short unsigned int",
5673 short_unsigned_type_node
);
5674 if (c_dialect_cxx ())
5675 record_builtin_type (RID_MAX
, "unsigned short",
5676 short_unsigned_type_node
);
5678 /* Define both `signed char' and `unsigned char'. */
5679 record_builtin_type (RID_MAX
, "signed char", signed_char_type_node
);
5680 record_builtin_type (RID_MAX
, "unsigned char", unsigned_char_type_node
);
5682 /* These are types that c_common_type_for_size and
5683 c_common_type_for_mode use. */
5684 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5685 TYPE_DECL
, NULL_TREE
,
5687 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5688 TYPE_DECL
, NULL_TREE
,
5690 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5691 TYPE_DECL
, NULL_TREE
,
5693 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5694 TYPE_DECL
, NULL_TREE
,
5696 #if HOST_BITS_PER_WIDE_INT >= 64
5697 /* Note that this is different than the __int128 type that's part of
5698 the generic __intN support. */
5699 if (targetm
.scalar_mode_supported_p (TImode
))
5700 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5702 get_identifier ("__int128_t"),
5705 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5706 TYPE_DECL
, NULL_TREE
,
5707 unsigned_intQI_type_node
));
5708 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5709 TYPE_DECL
, NULL_TREE
,
5710 unsigned_intHI_type_node
));
5711 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5712 TYPE_DECL
, NULL_TREE
,
5713 unsigned_intSI_type_node
));
5714 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5715 TYPE_DECL
, NULL_TREE
,
5716 unsigned_intDI_type_node
));
5717 #if HOST_BITS_PER_WIDE_INT >= 64
5718 if (targetm
.scalar_mode_supported_p (TImode
))
5719 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5721 get_identifier ("__uint128_t"),
5722 unsigned_intTI_type_node
));
5725 /* Create the widest literal types. */
5726 widest_integer_literal_type_node
5727 = make_signed_type (HOST_BITS_PER_WIDE_INT
* 2);
5728 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5729 TYPE_DECL
, NULL_TREE
,
5730 widest_integer_literal_type_node
));
5732 widest_unsigned_literal_type_node
5733 = make_unsigned_type (HOST_BITS_PER_WIDE_INT
* 2);
5734 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5735 TYPE_DECL
, NULL_TREE
,
5736 widest_unsigned_literal_type_node
));
5738 signed_size_type_node
= c_common_signed_type (size_type_node
);
5741 TREE_TYPE (identifier_global_value (get_identifier (PID_TYPE
)));
5743 record_builtin_type (RID_FLOAT
, NULL
, float_type_node
);
5744 record_builtin_type (RID_DOUBLE
, NULL
, double_type_node
);
5745 record_builtin_type (RID_MAX
, "long double", long_double_type_node
);
5747 /* Only supported decimal floating point extension if the target
5748 actually supports underlying modes. */
5749 if (targetm
.scalar_mode_supported_p (SDmode
)
5750 && targetm
.scalar_mode_supported_p (DDmode
)
5751 && targetm
.scalar_mode_supported_p (TDmode
))
5753 record_builtin_type (RID_DFLOAT32
, NULL
, dfloat32_type_node
);
5754 record_builtin_type (RID_DFLOAT64
, NULL
, dfloat64_type_node
);
5755 record_builtin_type (RID_DFLOAT128
, NULL
, dfloat128_type_node
);
5758 if (targetm
.fixed_point_supported_p ())
5760 record_builtin_type (RID_MAX
, "short _Fract", short_fract_type_node
);
5761 record_builtin_type (RID_FRACT
, NULL
, fract_type_node
);
5762 record_builtin_type (RID_MAX
, "long _Fract", long_fract_type_node
);
5763 record_builtin_type (RID_MAX
, "long long _Fract",
5764 long_long_fract_type_node
);
5765 record_builtin_type (RID_MAX
, "unsigned short _Fract",
5766 unsigned_short_fract_type_node
);
5767 record_builtin_type (RID_MAX
, "unsigned _Fract",
5768 unsigned_fract_type_node
);
5769 record_builtin_type (RID_MAX
, "unsigned long _Fract",
5770 unsigned_long_fract_type_node
);
5771 record_builtin_type (RID_MAX
, "unsigned long long _Fract",
5772 unsigned_long_long_fract_type_node
);
5773 record_builtin_type (RID_MAX
, "_Sat short _Fract",
5774 sat_short_fract_type_node
);
5775 record_builtin_type (RID_MAX
, "_Sat _Fract", sat_fract_type_node
);
5776 record_builtin_type (RID_MAX
, "_Sat long _Fract",
5777 sat_long_fract_type_node
);
5778 record_builtin_type (RID_MAX
, "_Sat long long _Fract",
5779 sat_long_long_fract_type_node
);
5780 record_builtin_type (RID_MAX
, "_Sat unsigned short _Fract",
5781 sat_unsigned_short_fract_type_node
);
5782 record_builtin_type (RID_MAX
, "_Sat unsigned _Fract",
5783 sat_unsigned_fract_type_node
);
5784 record_builtin_type (RID_MAX
, "_Sat unsigned long _Fract",
5785 sat_unsigned_long_fract_type_node
);
5786 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Fract",
5787 sat_unsigned_long_long_fract_type_node
);
5788 record_builtin_type (RID_MAX
, "short _Accum", short_accum_type_node
);
5789 record_builtin_type (RID_ACCUM
, NULL
, accum_type_node
);
5790 record_builtin_type (RID_MAX
, "long _Accum", long_accum_type_node
);
5791 record_builtin_type (RID_MAX
, "long long _Accum",
5792 long_long_accum_type_node
);
5793 record_builtin_type (RID_MAX
, "unsigned short _Accum",
5794 unsigned_short_accum_type_node
);
5795 record_builtin_type (RID_MAX
, "unsigned _Accum",
5796 unsigned_accum_type_node
);
5797 record_builtin_type (RID_MAX
, "unsigned long _Accum",
5798 unsigned_long_accum_type_node
);
5799 record_builtin_type (RID_MAX
, "unsigned long long _Accum",
5800 unsigned_long_long_accum_type_node
);
5801 record_builtin_type (RID_MAX
, "_Sat short _Accum",
5802 sat_short_accum_type_node
);
5803 record_builtin_type (RID_MAX
, "_Sat _Accum", sat_accum_type_node
);
5804 record_builtin_type (RID_MAX
, "_Sat long _Accum",
5805 sat_long_accum_type_node
);
5806 record_builtin_type (RID_MAX
, "_Sat long long _Accum",
5807 sat_long_long_accum_type_node
);
5808 record_builtin_type (RID_MAX
, "_Sat unsigned short _Accum",
5809 sat_unsigned_short_accum_type_node
);
5810 record_builtin_type (RID_MAX
, "_Sat unsigned _Accum",
5811 sat_unsigned_accum_type_node
);
5812 record_builtin_type (RID_MAX
, "_Sat unsigned long _Accum",
5813 sat_unsigned_long_accum_type_node
);
5814 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Accum",
5815 sat_unsigned_long_long_accum_type_node
);
5819 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5821 get_identifier ("complex int"),
5822 complex_integer_type_node
));
5823 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5825 get_identifier ("complex float"),
5826 complex_float_type_node
));
5827 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5829 get_identifier ("complex double"),
5830 complex_double_type_node
));
5831 lang_hooks
.decls
.pushdecl
5832 (build_decl (UNKNOWN_LOCATION
,
5833 TYPE_DECL
, get_identifier ("complex long double"),
5834 complex_long_double_type_node
));
5836 if (c_dialect_cxx ())
5837 /* For C++, make fileptr_type_node a distinct void * type until
5838 FILE type is defined. */
5839 fileptr_type_node
= build_variant_type_copy (ptr_type_node
);
5841 record_builtin_type (RID_VOID
, NULL
, void_type_node
);
5843 /* Set the TYPE_NAME for any variants that were built before
5844 record_builtin_type gave names to the built-in types. */
5846 tree void_name
= TYPE_NAME (void_type_node
);
5847 TYPE_NAME (void_type_node
) = NULL_TREE
;
5848 TYPE_NAME (build_qualified_type (void_type_node
, TYPE_QUAL_CONST
))
5850 TYPE_NAME (void_type_node
) = void_name
;
5853 void_list_node
= build_void_list_node ();
5855 /* Make a type to be the domain of a few array types
5856 whose domains don't really matter.
5857 200 is small enough that it always fits in size_t
5858 and large enough that it can hold most function names for the
5859 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
5860 array_domain_type
= build_index_type (size_int (200));
5862 /* Make a type for arrays of characters.
5863 With luck nothing will ever really depend on the length of this
5865 char_array_type_node
5866 = build_array_type (char_type_node
, array_domain_type
);
5868 string_type_node
= build_pointer_type (char_type_node
);
5869 const_string_type_node
5870 = build_pointer_type (build_qualified_type
5871 (char_type_node
, TYPE_QUAL_CONST
));
5873 /* This is special for C++ so functions can be overloaded. */
5874 wchar_type_node
= get_identifier (MODIFIED_WCHAR_TYPE
);
5875 wchar_type_node
= TREE_TYPE (identifier_global_value (wchar_type_node
));
5876 wchar_type_size
= TYPE_PRECISION (wchar_type_node
);
5877 underlying_wchar_type_node
= wchar_type_node
;
5878 if (c_dialect_cxx ())
5880 if (TYPE_UNSIGNED (wchar_type_node
))
5881 wchar_type_node
= make_unsigned_type (wchar_type_size
);
5883 wchar_type_node
= make_signed_type (wchar_type_size
);
5884 record_builtin_type (RID_WCHAR
, "wchar_t", wchar_type_node
);
5887 /* This is for wide string constants. */
5888 wchar_array_type_node
5889 = build_array_type (wchar_type_node
, array_domain_type
);
5891 /* Define 'char16_t'. */
5892 char16_type_node
= get_identifier (CHAR16_TYPE
);
5893 char16_type_node
= TREE_TYPE (identifier_global_value (char16_type_node
));
5894 char16_type_size
= TYPE_PRECISION (char16_type_node
);
5895 if (c_dialect_cxx ())
5897 char16_type_node
= make_unsigned_type (char16_type_size
);
5899 if (cxx_dialect
>= cxx11
)
5900 record_builtin_type (RID_CHAR16
, "char16_t", char16_type_node
);
5903 /* This is for UTF-16 string constants. */
5904 char16_array_type_node
5905 = build_array_type (char16_type_node
, array_domain_type
);
5907 /* Define 'char32_t'. */
5908 char32_type_node
= get_identifier (CHAR32_TYPE
);
5909 char32_type_node
= TREE_TYPE (identifier_global_value (char32_type_node
));
5910 char32_type_size
= TYPE_PRECISION (char32_type_node
);
5911 if (c_dialect_cxx ())
5913 char32_type_node
= make_unsigned_type (char32_type_size
);
5915 if (cxx_dialect
>= cxx11
)
5916 record_builtin_type (RID_CHAR32
, "char32_t", char32_type_node
);
5919 /* This is for UTF-32 string constants. */
5920 char32_array_type_node
5921 = build_array_type (char32_type_node
, array_domain_type
);
5924 TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE
)));
5927 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE
)));
5929 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE
)));
5931 if (SIG_ATOMIC_TYPE
)
5932 sig_atomic_type_node
=
5933 TREE_TYPE (identifier_global_value (c_get_ident (SIG_ATOMIC_TYPE
)));
5936 TREE_TYPE (identifier_global_value (c_get_ident (INT8_TYPE
)));
5939 TREE_TYPE (identifier_global_value (c_get_ident (INT16_TYPE
)));
5942 TREE_TYPE (identifier_global_value (c_get_ident (INT32_TYPE
)));
5945 TREE_TYPE (identifier_global_value (c_get_ident (INT64_TYPE
)));
5948 TREE_TYPE (identifier_global_value (c_get_ident (UINT8_TYPE
)));
5950 c_uint16_type_node
= uint16_type_node
=
5951 TREE_TYPE (identifier_global_value (c_get_ident (UINT16_TYPE
)));
5953 c_uint32_type_node
= uint32_type_node
=
5954 TREE_TYPE (identifier_global_value (c_get_ident (UINT32_TYPE
)));
5956 c_uint64_type_node
= uint64_type_node
=
5957 TREE_TYPE (identifier_global_value (c_get_ident (UINT64_TYPE
)));
5958 if (INT_LEAST8_TYPE
)
5959 int_least8_type_node
=
5960 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST8_TYPE
)));
5961 if (INT_LEAST16_TYPE
)
5962 int_least16_type_node
=
5963 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST16_TYPE
)));
5964 if (INT_LEAST32_TYPE
)
5965 int_least32_type_node
=
5966 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST32_TYPE
)));
5967 if (INT_LEAST64_TYPE
)
5968 int_least64_type_node
=
5969 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST64_TYPE
)));
5970 if (UINT_LEAST8_TYPE
)
5971 uint_least8_type_node
=
5972 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST8_TYPE
)));
5973 if (UINT_LEAST16_TYPE
)
5974 uint_least16_type_node
=
5975 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST16_TYPE
)));
5976 if (UINT_LEAST32_TYPE
)
5977 uint_least32_type_node
=
5978 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST32_TYPE
)));
5979 if (UINT_LEAST64_TYPE
)
5980 uint_least64_type_node
=
5981 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST64_TYPE
)));
5983 int_fast8_type_node
=
5984 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST8_TYPE
)));
5985 if (INT_FAST16_TYPE
)
5986 int_fast16_type_node
=
5987 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST16_TYPE
)));
5988 if (INT_FAST32_TYPE
)
5989 int_fast32_type_node
=
5990 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST32_TYPE
)));
5991 if (INT_FAST64_TYPE
)
5992 int_fast64_type_node
=
5993 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST64_TYPE
)));
5994 if (UINT_FAST8_TYPE
)
5995 uint_fast8_type_node
=
5996 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST8_TYPE
)));
5997 if (UINT_FAST16_TYPE
)
5998 uint_fast16_type_node
=
5999 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST16_TYPE
)));
6000 if (UINT_FAST32_TYPE
)
6001 uint_fast32_type_node
=
6002 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST32_TYPE
)));
6003 if (UINT_FAST64_TYPE
)
6004 uint_fast64_type_node
=
6005 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST64_TYPE
)));
6008 TREE_TYPE (identifier_global_value (c_get_ident (INTPTR_TYPE
)));
6011 TREE_TYPE (identifier_global_value (c_get_ident (UINTPTR_TYPE
)));
6013 default_function_type
6014 = build_varargs_function_type_list (integer_type_node
, NULL_TREE
);
6016 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE
)));
6017 unsigned_ptrdiff_type_node
= c_common_unsigned_type (ptrdiff_type_node
);
6019 lang_hooks
.decls
.pushdecl
6020 (build_decl (UNKNOWN_LOCATION
,
6021 TYPE_DECL
, get_identifier ("__builtin_va_list"),
6022 va_list_type_node
));
6023 if (targetm
.enum_va_list_p
)
6029 for (l
= 0; targetm
.enum_va_list_p (l
, &pname
, &ptype
); ++l
)
6031 lang_hooks
.decls
.pushdecl
6032 (build_decl (UNKNOWN_LOCATION
,
6033 TYPE_DECL
, get_identifier (pname
),
6039 if (TREE_CODE (va_list_type_node
) == ARRAY_TYPE
)
6041 va_list_arg_type_node
= va_list_ref_type_node
=
6042 build_pointer_type (TREE_TYPE (va_list_type_node
));
6046 va_list_arg_type_node
= va_list_type_node
;
6047 va_list_ref_type_node
= build_reference_type (va_list_type_node
);
6050 if (!flag_preprocess_only
)
6051 c_define_builtins (va_list_ref_type_node
, va_list_arg_type_node
);
6053 main_identifier_node
= get_identifier ("main");
6055 /* Create the built-in __null node. It is important that this is
6057 null_node
= make_int_cst (1, 1);
6058 TREE_TYPE (null_node
) = c_common_type_for_size (POINTER_SIZE
, 0);
6060 /* Since builtin_types isn't gc'ed, don't export these nodes. */
6061 memset (builtin_types
, 0, sizeof (builtin_types
));
6064 /* The number of named compound-literals generated thus far. */
6065 static GTY(()) int compound_literal_number
;
6067 /* Set DECL_NAME for DECL, a VAR_DECL for a compound-literal. */
6070 set_compound_literal_name (tree decl
)
6073 ASM_FORMAT_PRIVATE_NAME (name
, "__compound_literal",
6074 compound_literal_number
);
6075 compound_literal_number
++;
6076 DECL_NAME (decl
) = get_identifier (name
);
6079 /* build_va_arg helper function. Return a VA_ARG_EXPR with location LOC, type
6080 TYPE and operand OP. */
6083 build_va_arg_1 (location_t loc
, tree type
, tree op
)
6085 tree expr
= build1 (VA_ARG_EXPR
, type
, op
);
6086 SET_EXPR_LOCATION (expr
, loc
);
6090 /* Return a VA_ARG_EXPR corresponding to a source-level expression
6091 va_arg (EXPR, TYPE) at source location LOC. */
6094 build_va_arg (location_t loc
, tree expr
, tree type
)
6096 tree va_type
= TREE_TYPE (expr
);
6097 tree canon_va_type
= (va_type
== error_mark_node
6099 : targetm
.canonical_va_list_type (va_type
));
6101 if (va_type
== error_mark_node
6102 || canon_va_type
== NULL_TREE
)
6104 /* Let's handle things neutrallly, if expr:
6105 - has undeclared type, or
6106 - is not an va_list type. */
6107 return build_va_arg_1 (loc
, type
, expr
);
6110 if (TREE_CODE (canon_va_type
) != ARRAY_TYPE
)
6112 /* Case 1: Not an array type. */
6114 /* Take the address, to get '&ap'. */
6115 mark_addressable (expr
);
6116 expr
= build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (expr
)), expr
);
6118 /* Verify that &ap is still recognized as having va_list type. */
6119 tree canon_expr_type
6120 = targetm
.canonical_va_list_type (TREE_TYPE (expr
));
6121 gcc_assert (canon_expr_type
!= NULL_TREE
);
6123 return build_va_arg_1 (loc
, type
, expr
);
6126 /* Case 2: Array type.
6130 For contrast, let's start with the simple case (case 1). If
6131 canon_va_type is not an array type, but say a char *, then when
6132 passing-by-value a va_list, the type of the va_list param decl is
6133 the same as for another va_list decl (all ap's are char *):
6136 D.1815 = VA_ARG (&ap, 0B, 1);
6142 __builtin_va_start (&ap, 0);
6145 __builtin_va_end (&ap);
6149 However, if canon_va_type is ARRAY_TYPE, then when passing-by-value a
6150 va_list the type of the va_list param decl (case 2b, struct * ap) is not
6151 the same as for another va_list decl (case 2a, struct ap[1]).
6154 D.1844 = VA_ARG (ap, 0B, 0);
6159 __builtin_va_start (&ap, 0);
6161 __builtin_va_end (&ap);
6165 Case 2b is different because:
6166 - on the callee side, the parm decl has declared type va_list, but
6167 grokdeclarator changes the type of the parm decl to a pointer to the
6169 - on the caller side, the pass-by-value uses &ap.
6171 We unify these two cases (case 2a: va_list is array type,
6172 case 2b: va_list is pointer to array elem type), by adding '&' for the
6173 array type case, such that we have a pointer to array elem in both
6176 if (TREE_CODE (va_type
) == ARRAY_TYPE
)
6178 /* Case 2a: va_list is array type. */
6180 /* Take the address, to get '&ap'. Make sure it's a pointer to array
6182 mark_addressable (expr
);
6183 expr
= build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (canon_va_type
)),
6186 /* Verify that &ap is still recognized as having va_list type. */
6187 tree canon_expr_type
6188 = targetm
.canonical_va_list_type (TREE_TYPE (expr
));
6189 gcc_assert (canon_expr_type
!= NULL_TREE
);
6193 /* Case 2b: va_list is pointer to array elem type. */
6194 gcc_assert (POINTER_TYPE_P (va_type
));
6195 gcc_assert (TREE_TYPE (va_type
) == TREE_TYPE (canon_va_type
));
6197 /* Don't take the address. We've already got '&ap'. */
6201 return build_va_arg_1 (loc
, type
, expr
);
6205 /* Linked list of disabled built-in functions. */
6207 typedef struct disabled_builtin
6210 struct disabled_builtin
*next
;
6212 static disabled_builtin
*disabled_builtins
= NULL
;
6214 static bool builtin_function_disabled_p (const char *);
6216 /* Disable a built-in function specified by -fno-builtin-NAME. If NAME
6217 begins with "__builtin_", give an error. */
6220 disable_builtin_function (const char *name
)
6222 if (strncmp (name
, "__builtin_", strlen ("__builtin_")) == 0)
6223 error ("cannot disable built-in function %qs", name
);
6226 disabled_builtin
*new_disabled_builtin
= XNEW (disabled_builtin
);
6227 new_disabled_builtin
->name
= name
;
6228 new_disabled_builtin
->next
= disabled_builtins
;
6229 disabled_builtins
= new_disabled_builtin
;
6234 /* Return true if the built-in function NAME has been disabled, false
6238 builtin_function_disabled_p (const char *name
)
6240 disabled_builtin
*p
;
6241 for (p
= disabled_builtins
; p
!= NULL
; p
= p
->next
)
6243 if (strcmp (name
, p
->name
) == 0)
6250 /* Worker for DEF_BUILTIN.
6251 Possibly define a builtin function with one or two names.
6252 Does not declare a non-__builtin_ function if flag_no_builtin, or if
6253 nonansi_p and flag_no_nonansi_builtin. */
6256 def_builtin_1 (enum built_in_function fncode
,
6258 enum built_in_class fnclass
,
6259 tree fntype
, tree libtype
,
6260 bool both_p
, bool fallback_p
, bool nonansi_p
,
6261 tree fnattrs
, bool implicit_p
)
6264 const char *libname
;
6266 if (fntype
== error_mark_node
)
6269 gcc_assert ((!both_p
&& !fallback_p
)
6270 || !strncmp (name
, "__builtin_",
6271 strlen ("__builtin_")));
6273 libname
= name
+ strlen ("__builtin_");
6274 decl
= add_builtin_function (name
, fntype
, fncode
, fnclass
,
6275 (fallback_p
? libname
: NULL
),
6278 set_builtin_decl (fncode
, decl
, implicit_p
);
6281 && !flag_no_builtin
&& !builtin_function_disabled_p (libname
)
6282 && !(nonansi_p
&& flag_no_nonansi_builtin
))
6283 add_builtin_function (libname
, libtype
, fncode
, fnclass
,
6287 /* Nonzero if the type T promotes to int. This is (nearly) the
6288 integral promotions defined in ISO C99 6.3.1.1/2. */
6291 c_promoting_integer_type_p (const_tree t
)
6293 switch (TREE_CODE (t
))
6296 return (TYPE_MAIN_VARIANT (t
) == char_type_node
6297 || TYPE_MAIN_VARIANT (t
) == signed_char_type_node
6298 || TYPE_MAIN_VARIANT (t
) == unsigned_char_type_node
6299 || TYPE_MAIN_VARIANT (t
) == short_integer_type_node
6300 || TYPE_MAIN_VARIANT (t
) == short_unsigned_type_node
6301 || TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
));
6304 /* ??? Technically all enumerations not larger than an int
6305 promote to an int. But this is used along code paths
6306 that only want to notice a size change. */
6307 return TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
);
6317 /* Return 1 if PARMS specifies a fixed number of parameters
6318 and none of their types is affected by default promotions. */
6321 self_promoting_args_p (const_tree parms
)
6324 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
6326 tree type
= TREE_VALUE (t
);
6328 if (type
== error_mark_node
)
6331 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
6337 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
6340 if (c_promoting_integer_type_p (type
))
6346 /* Recursively remove any '*' or '&' operator from TYPE. */
6348 strip_pointer_operator (tree t
)
6350 while (POINTER_TYPE_P (t
))
6355 /* Recursively remove pointer or array type from TYPE. */
6357 strip_pointer_or_array_types (tree t
)
6359 while (TREE_CODE (t
) == ARRAY_TYPE
|| POINTER_TYPE_P (t
))
6364 /* Used to compare case labels. K1 and K2 are actually tree nodes
6365 representing case labels, or NULL_TREE for a `default' label.
6366 Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after
6367 K2, and 0 if K1 and K2 are equal. */
6370 case_compare (splay_tree_key k1
, splay_tree_key k2
)
6372 /* Consider a NULL key (such as arises with a `default' label) to be
6373 smaller than anything else. */
6379 return tree_int_cst_compare ((tree
) k1
, (tree
) k2
);
6382 /* Process a case label, located at LOC, for the range LOW_VALUE
6383 ... HIGH_VALUE. If LOW_VALUE and HIGH_VALUE are both NULL_TREE
6384 then this case label is actually a `default' label. If only
6385 HIGH_VALUE is NULL_TREE, then case label was declared using the
6386 usual C/C++ syntax, rather than the GNU case range extension.
6387 CASES is a tree containing all the case ranges processed so far;
6388 COND is the condition for the switch-statement itself. Returns the
6389 CASE_LABEL_EXPR created, or ERROR_MARK_NODE if no CASE_LABEL_EXPR
6393 c_add_case_label (location_t loc
, splay_tree cases
, tree cond
, tree orig_type
,
6394 tree low_value
, tree high_value
)
6399 splay_tree_node node
;
6401 /* Create the LABEL_DECL itself. */
6402 label
= create_artificial_label (loc
);
6404 /* If there was an error processing the switch condition, bail now
6405 before we get more confused. */
6406 if (!cond
|| cond
== error_mark_node
)
6409 if ((low_value
&& TREE_TYPE (low_value
)
6410 && POINTER_TYPE_P (TREE_TYPE (low_value
)))
6411 || (high_value
&& TREE_TYPE (high_value
)
6412 && POINTER_TYPE_P (TREE_TYPE (high_value
))))
6414 error_at (loc
, "pointers are not permitted as case values");
6418 /* Case ranges are a GNU extension. */
6420 pedwarn (loc
, OPT_Wpedantic
,
6421 "range expressions in switch statements are non-standard");
6423 type
= TREE_TYPE (cond
);
6426 low_value
= check_case_value (loc
, low_value
);
6427 low_value
= convert_and_check (loc
, type
, low_value
);
6428 if (low_value
== error_mark_node
)
6433 high_value
= check_case_value (loc
, high_value
);
6434 high_value
= convert_and_check (loc
, type
, high_value
);
6435 if (high_value
== error_mark_node
)
6439 if (low_value
&& high_value
)
6441 /* If the LOW_VALUE and HIGH_VALUE are the same, then this isn't
6442 really a case range, even though it was written that way.
6443 Remove the HIGH_VALUE to simplify later processing. */
6444 if (tree_int_cst_equal (low_value
, high_value
))
6445 high_value
= NULL_TREE
;
6446 else if (!tree_int_cst_lt (low_value
, high_value
))
6447 warning_at (loc
, 0, "empty range specified");
6450 /* See if the case is in range of the type of the original testing
6451 expression. If both low_value and high_value are out of range,
6452 don't insert the case label and return NULL_TREE. */
6454 && !check_case_bounds (loc
, type
, orig_type
,
6455 &low_value
, high_value
? &high_value
: NULL
))
6458 /* Look up the LOW_VALUE in the table of case labels we already
6460 node
= splay_tree_lookup (cases
, (splay_tree_key
) low_value
);
6461 /* If there was not an exact match, check for overlapping ranges.
6462 There's no need to do this if there's no LOW_VALUE or HIGH_VALUE;
6463 that's a `default' label and the only overlap is an exact match. */
6464 if (!node
&& (low_value
|| high_value
))
6466 splay_tree_node low_bound
;
6467 splay_tree_node high_bound
;
6469 /* Even though there wasn't an exact match, there might be an
6470 overlap between this case range and another case range.
6471 Since we've (inductively) not allowed any overlapping case
6472 ranges, we simply need to find the greatest low case label
6473 that is smaller that LOW_VALUE, and the smallest low case
6474 label that is greater than LOW_VALUE. If there is an overlap
6475 it will occur in one of these two ranges. */
6476 low_bound
= splay_tree_predecessor (cases
,
6477 (splay_tree_key
) low_value
);
6478 high_bound
= splay_tree_successor (cases
,
6479 (splay_tree_key
) low_value
);
6481 /* Check to see if the LOW_BOUND overlaps. It is smaller than
6482 the LOW_VALUE, so there is no need to check unless the
6483 LOW_BOUND is in fact itself a case range. */
6485 && CASE_HIGH ((tree
) low_bound
->value
)
6486 && tree_int_cst_compare (CASE_HIGH ((tree
) low_bound
->value
),
6489 /* Check to see if the HIGH_BOUND overlaps. The low end of that
6490 range is bigger than the low end of the current range, so we
6491 are only interested if the current range is a real range, and
6492 not an ordinary case label. */
6495 && (tree_int_cst_compare ((tree
) high_bound
->key
,
6500 /* If there was an overlap, issue an error. */
6503 tree duplicate
= CASE_LABEL ((tree
) node
->value
);
6507 error_at (loc
, "duplicate (or overlapping) case value");
6508 error_at (DECL_SOURCE_LOCATION (duplicate
),
6509 "this is the first entry overlapping that value");
6513 error_at (loc
, "duplicate case value") ;
6514 error_at (DECL_SOURCE_LOCATION (duplicate
), "previously used here");
6518 error_at (loc
, "multiple default labels in one switch");
6519 error_at (DECL_SOURCE_LOCATION (duplicate
),
6520 "this is the first default label");
6525 /* Add a CASE_LABEL to the statement-tree. */
6526 case_label
= add_stmt (build_case_label (low_value
, high_value
, label
));
6527 /* Register this case label in the splay tree. */
6528 splay_tree_insert (cases
,
6529 (splay_tree_key
) low_value
,
6530 (splay_tree_value
) case_label
);
6535 /* Add a label so that the back-end doesn't think that the beginning of
6536 the switch is unreachable. Note that we do not add a case label, as
6537 that just leads to duplicates and thence to failure later on. */
6540 tree t
= create_artificial_label (loc
);
6541 add_stmt (build_stmt (loc
, LABEL_EXPR
, t
));
6543 return error_mark_node
;
6546 /* Subroutines of c_do_switch_warnings, called via splay_tree_foreach.
6547 Used to verify that case values match up with enumerator values. */
6550 match_case_to_enum_1 (tree key
, tree type
, tree label
)
6552 char buf
[WIDE_INT_PRINT_BUFFER_SIZE
];
6554 if (tree_fits_uhwi_p (key
))
6555 print_dec (key
, buf
, UNSIGNED
);
6556 else if (tree_fits_shwi_p (key
))
6557 print_dec (key
, buf
, SIGNED
);
6559 print_hex (key
, buf
);
6561 if (TYPE_NAME (type
) == 0)
6562 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
6563 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
6564 "case value %qs not in enumerated type",
6567 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
6568 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
6569 "case value %qs not in enumerated type %qT",
6573 /* Subroutine of c_do_switch_warnings, called via splay_tree_foreach.
6574 Used to verify that case values match up with enumerator values. */
6577 match_case_to_enum (splay_tree_node node
, void *data
)
6579 tree label
= (tree
) node
->value
;
6580 tree type
= (tree
) data
;
6582 /* Skip default case. */
6583 if (!CASE_LOW (label
))
6586 /* If CASE_LOW_SEEN is not set, that means CASE_LOW did not appear
6587 when we did our enum->case scan. Reset our scratch bit after. */
6588 if (!CASE_LOW_SEEN (label
))
6589 match_case_to_enum_1 (CASE_LOW (label
), type
, label
);
6591 CASE_LOW_SEEN (label
) = 0;
6593 /* If CASE_HIGH is non-null, we have a range. If CASE_HIGH_SEEN is
6594 not set, that means that CASE_HIGH did not appear when we did our
6595 enum->case scan. Reset our scratch bit after. */
6596 if (CASE_HIGH (label
))
6598 if (!CASE_HIGH_SEEN (label
))
6599 match_case_to_enum_1 (CASE_HIGH (label
), type
, label
);
6601 CASE_HIGH_SEEN (label
) = 0;
6607 /* Handle -Wswitch*. Called from the front end after parsing the
6608 switch construct. */
6609 /* ??? Should probably be somewhere generic, since other languages
6610 besides C and C++ would want this. At the moment, however, C/C++
6611 are the only tree-ssa languages that support enumerations at all,
6612 so the point is moot. */
6615 c_do_switch_warnings (splay_tree cases
, location_t switch_location
,
6616 tree type
, tree cond
)
6618 splay_tree_node default_node
;
6619 splay_tree_node node
;
6622 if (!warn_switch
&& !warn_switch_enum
&& !warn_switch_default
)
6625 default_node
= splay_tree_lookup (cases
, (splay_tree_key
) NULL
);
6627 warning_at (switch_location
, OPT_Wswitch_default
,
6628 "switch missing default case");
6630 /* From here on, we only care about about enumerated types. */
6631 if (!type
|| TREE_CODE (type
) != ENUMERAL_TYPE
)
6634 /* From here on, we only care about -Wswitch and -Wswitch-enum. */
6635 if (!warn_switch_enum
&& !warn_switch
)
6638 /* Check the cases. Warn about case values which are not members of
6639 the enumerated type. For -Wswitch-enum, or for -Wswitch when
6640 there is no default case, check that exactly all enumeration
6641 literals are covered by the cases. */
6643 /* Clearing COND if it is not an integer constant simplifies
6644 the tests inside the loop below. */
6645 if (TREE_CODE (cond
) != INTEGER_CST
)
6648 /* The time complexity here is O(N*lg(N)) worst case, but for the
6649 common case of monotonically increasing enumerators, it is
6650 O(N), since the nature of the splay tree will keep the next
6651 element adjacent to the root at all times. */
6653 for (chain
= TYPE_VALUES (type
); chain
; chain
= TREE_CHAIN (chain
))
6655 tree value
= TREE_VALUE (chain
);
6656 if (TREE_CODE (value
) == CONST_DECL
)
6657 value
= DECL_INITIAL (value
);
6658 node
= splay_tree_lookup (cases
, (splay_tree_key
) value
);
6661 /* Mark the CASE_LOW part of the case entry as seen. */
6662 tree label
= (tree
) node
->value
;
6663 CASE_LOW_SEEN (label
) = 1;
6667 /* Even though there wasn't an exact match, there might be a
6668 case range which includes the enumerator's value. */
6669 node
= splay_tree_predecessor (cases
, (splay_tree_key
) value
);
6670 if (node
&& CASE_HIGH ((tree
) node
->value
))
6672 tree label
= (tree
) node
->value
;
6673 int cmp
= tree_int_cst_compare (CASE_HIGH (label
), value
);
6676 /* If we match the upper bound exactly, mark the CASE_HIGH
6677 part of the case entry as seen. */
6679 CASE_HIGH_SEEN (label
) = 1;
6684 /* We've now determined that this enumerated literal isn't
6685 handled by the case labels of the switch statement. */
6687 /* If the switch expression is a constant, we only really care
6688 about whether that constant is handled by the switch. */
6689 if (cond
&& tree_int_cst_compare (cond
, value
))
6692 /* If there is a default_node, the only relevant option is
6693 Wswitch-enum. Otherwise, if both are enabled then we prefer
6694 to warn using -Wswitch because -Wswitch is enabled by -Wall
6695 while -Wswitch-enum is explicit. */
6696 warning_at (switch_location
,
6697 (default_node
|| !warn_switch
6700 "enumeration value %qE not handled in switch",
6701 TREE_PURPOSE (chain
));
6704 /* Warn if there are case expressions that don't correspond to
6705 enumerators. This can occur since C and C++ don't enforce
6706 type-checking of assignments to enumeration variables.
6708 The time complexity here is now always O(N) worst case, since
6709 we should have marked both the lower bound and upper bound of
6710 every disjoint case label, with CASE_LOW_SEEN and CASE_HIGH_SEEN
6711 above. This scan also resets those fields. */
6713 splay_tree_foreach (cases
, match_case_to_enum
, type
);
6716 /* Finish an expression taking the address of LABEL (an
6717 IDENTIFIER_NODE). Returns an expression for the address.
6719 LOC is the location for the expression returned. */
6722 finish_label_address_expr (tree label
, location_t loc
)
6726 pedwarn (input_location
, OPT_Wpedantic
, "taking the address of a label is non-standard");
6728 if (label
== error_mark_node
)
6729 return error_mark_node
;
6731 label
= lookup_label (label
);
6732 if (label
== NULL_TREE
)
6733 result
= null_pointer_node
;
6736 TREE_USED (label
) = 1;
6737 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
6738 /* The current function is not necessarily uninlinable.
6739 Computed gotos are incompatible with inlining, but the value
6740 here could be used only in a diagnostic, for example. */
6741 protected_set_expr_location (result
, loc
);
6748 /* Given a boolean expression ARG, return a tree representing an increment
6749 or decrement (as indicated by CODE) of ARG. The front end must check for
6750 invalid cases (e.g., decrement in C++). */
6752 boolean_increment (enum tree_code code
, tree arg
)
6755 tree true_res
= build_int_cst (TREE_TYPE (arg
), 1);
6757 arg
= stabilize_reference (arg
);
6760 case PREINCREMENT_EXPR
:
6761 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
6763 case POSTINCREMENT_EXPR
:
6764 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
6765 arg
= save_expr (arg
);
6766 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
6767 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
6769 case PREDECREMENT_EXPR
:
6770 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
6771 invert_truthvalue_loc (input_location
, arg
));
6773 case POSTDECREMENT_EXPR
:
6774 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
6775 invert_truthvalue_loc (input_location
, arg
));
6776 arg
= save_expr (arg
);
6777 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
6778 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
6783 TREE_SIDE_EFFECTS (val
) = 1;
6787 /* Built-in macros for stddef.h and stdint.h, that require macros
6788 defined in this file. */
6790 c_stddef_cpp_builtins(void)
6792 builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE
, 0);
6793 builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE
, 0);
6794 builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE
, 0);
6795 builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE
, 0);
6796 builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE
, 0);
6797 builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE
, 0);
6798 builtin_define_with_value ("__CHAR16_TYPE__", CHAR16_TYPE
, 0);
6799 builtin_define_with_value ("__CHAR32_TYPE__", CHAR32_TYPE
, 0);
6800 if (SIG_ATOMIC_TYPE
)
6801 builtin_define_with_value ("__SIG_ATOMIC_TYPE__", SIG_ATOMIC_TYPE
, 0);
6803 builtin_define_with_value ("__INT8_TYPE__", INT8_TYPE
, 0);
6805 builtin_define_with_value ("__INT16_TYPE__", INT16_TYPE
, 0);
6807 builtin_define_with_value ("__INT32_TYPE__", INT32_TYPE
, 0);
6809 builtin_define_with_value ("__INT64_TYPE__", INT64_TYPE
, 0);
6811 builtin_define_with_value ("__UINT8_TYPE__", UINT8_TYPE
, 0);
6813 builtin_define_with_value ("__UINT16_TYPE__", UINT16_TYPE
, 0);
6815 builtin_define_with_value ("__UINT32_TYPE__", UINT32_TYPE
, 0);
6817 builtin_define_with_value ("__UINT64_TYPE__", UINT64_TYPE
, 0);
6818 if (INT_LEAST8_TYPE
)
6819 builtin_define_with_value ("__INT_LEAST8_TYPE__", INT_LEAST8_TYPE
, 0);
6820 if (INT_LEAST16_TYPE
)
6821 builtin_define_with_value ("__INT_LEAST16_TYPE__", INT_LEAST16_TYPE
, 0);
6822 if (INT_LEAST32_TYPE
)
6823 builtin_define_with_value ("__INT_LEAST32_TYPE__", INT_LEAST32_TYPE
, 0);
6824 if (INT_LEAST64_TYPE
)
6825 builtin_define_with_value ("__INT_LEAST64_TYPE__", INT_LEAST64_TYPE
, 0);
6826 if (UINT_LEAST8_TYPE
)
6827 builtin_define_with_value ("__UINT_LEAST8_TYPE__", UINT_LEAST8_TYPE
, 0);
6828 if (UINT_LEAST16_TYPE
)
6829 builtin_define_with_value ("__UINT_LEAST16_TYPE__", UINT_LEAST16_TYPE
, 0);
6830 if (UINT_LEAST32_TYPE
)
6831 builtin_define_with_value ("__UINT_LEAST32_TYPE__", UINT_LEAST32_TYPE
, 0);
6832 if (UINT_LEAST64_TYPE
)
6833 builtin_define_with_value ("__UINT_LEAST64_TYPE__", UINT_LEAST64_TYPE
, 0);
6835 builtin_define_with_value ("__INT_FAST8_TYPE__", INT_FAST8_TYPE
, 0);
6836 if (INT_FAST16_TYPE
)
6837 builtin_define_with_value ("__INT_FAST16_TYPE__", INT_FAST16_TYPE
, 0);
6838 if (INT_FAST32_TYPE
)
6839 builtin_define_with_value ("__INT_FAST32_TYPE__", INT_FAST32_TYPE
, 0);
6840 if (INT_FAST64_TYPE
)
6841 builtin_define_with_value ("__INT_FAST64_TYPE__", INT_FAST64_TYPE
, 0);
6842 if (UINT_FAST8_TYPE
)
6843 builtin_define_with_value ("__UINT_FAST8_TYPE__", UINT_FAST8_TYPE
, 0);
6844 if (UINT_FAST16_TYPE
)
6845 builtin_define_with_value ("__UINT_FAST16_TYPE__", UINT_FAST16_TYPE
, 0);
6846 if (UINT_FAST32_TYPE
)
6847 builtin_define_with_value ("__UINT_FAST32_TYPE__", UINT_FAST32_TYPE
, 0);
6848 if (UINT_FAST64_TYPE
)
6849 builtin_define_with_value ("__UINT_FAST64_TYPE__", UINT_FAST64_TYPE
, 0);
6851 builtin_define_with_value ("__INTPTR_TYPE__", INTPTR_TYPE
, 0);
6853 builtin_define_with_value ("__UINTPTR_TYPE__", UINTPTR_TYPE
, 0);
6857 c_init_attributes (void)
6859 /* Fill in the built_in_attributes array. */
6860 #define DEF_ATTR_NULL_TREE(ENUM) \
6861 built_in_attributes[(int) ENUM] = NULL_TREE;
6862 #define DEF_ATTR_INT(ENUM, VALUE) \
6863 built_in_attributes[(int) ENUM] = build_int_cst (integer_type_node, VALUE);
6864 #define DEF_ATTR_STRING(ENUM, VALUE) \
6865 built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
6866 #define DEF_ATTR_IDENT(ENUM, STRING) \
6867 built_in_attributes[(int) ENUM] = get_identifier (STRING);
6868 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
6869 built_in_attributes[(int) ENUM] \
6870 = tree_cons (built_in_attributes[(int) PURPOSE], \
6871 built_in_attributes[(int) VALUE], \
6872 built_in_attributes[(int) CHAIN]);
6873 #include "builtin-attrs.def"
6874 #undef DEF_ATTR_NULL_TREE
6876 #undef DEF_ATTR_IDENT
6877 #undef DEF_ATTR_TREE_LIST
6880 /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain
6881 identifier as an argument, so the front end shouldn't look it up. */
6884 attribute_takes_identifier_p (const_tree attr_id
)
6886 const struct attribute_spec
*spec
= lookup_attribute_spec (attr_id
);
6888 /* Unknown attribute that we'll end up ignoring, return true so we
6889 don't complain about an identifier argument. */
6891 else if (!strcmp ("mode", spec
->name
)
6892 || !strcmp ("format", spec
->name
)
6893 || !strcmp ("cleanup", spec
->name
))
6896 return targetm
.attribute_takes_identifier_p (attr_id
);
6899 /* Attribute handlers common to C front ends. */
6901 /* Handle a "packed" attribute; arguments as in
6902 struct attribute_spec.handler. */
6905 handle_packed_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6906 int flags
, bool *no_add_attrs
)
6910 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6911 *node
= build_variant_type_copy (*node
);
6912 TYPE_PACKED (*node
) = 1;
6914 else if (TREE_CODE (*node
) == FIELD_DECL
)
6916 if (TYPE_ALIGN (TREE_TYPE (*node
)) <= BITS_PER_UNIT
6917 /* Still pack bitfields. */
6918 && ! DECL_INITIAL (*node
))
6919 warning (OPT_Wattributes
,
6920 "%qE attribute ignored for field of type %qT",
6921 name
, TREE_TYPE (*node
));
6923 DECL_PACKED (*node
) = 1;
6925 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
6926 used for DECL_REGISTER. It wouldn't mean anything anyway.
6927 We can't set DECL_PACKED on the type of a TYPE_DECL, because
6928 that changes what the typedef is typing. */
6931 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6932 *no_add_attrs
= true;
6938 /* Handle a "nocommon" attribute; arguments as in
6939 struct attribute_spec.handler. */
6942 handle_nocommon_attribute (tree
*node
, tree name
,
6943 tree
ARG_UNUSED (args
),
6944 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6946 if (TREE_CODE (*node
) == VAR_DECL
)
6947 DECL_COMMON (*node
) = 0;
6950 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6951 *no_add_attrs
= true;
6957 /* Handle a "common" attribute; arguments as in
6958 struct attribute_spec.handler. */
6961 handle_common_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6962 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6964 if (TREE_CODE (*node
) == VAR_DECL
)
6965 DECL_COMMON (*node
) = 1;
6968 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6969 *no_add_attrs
= true;
6975 /* Handle a "noreturn" attribute; arguments as in
6976 struct attribute_spec.handler. */
6979 handle_noreturn_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6980 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6982 tree type
= TREE_TYPE (*node
);
6984 /* See FIXME comment in c_common_attribute_table. */
6985 if (TREE_CODE (*node
) == FUNCTION_DECL
6986 || objc_method_decl (TREE_CODE (*node
)))
6987 TREE_THIS_VOLATILE (*node
) = 1;
6988 else if (TREE_CODE (type
) == POINTER_TYPE
6989 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
6991 = (build_qualified_type
6993 (build_type_variant (TREE_TYPE (type
),
6994 TYPE_READONLY (TREE_TYPE (type
)), 1)),
6995 TYPE_QUALS (type
)));
6998 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6999 *no_add_attrs
= true;
7005 /* Handle a "hot" and attribute; arguments as in
7006 struct attribute_spec.handler. */
7009 handle_hot_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7010 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7012 if (TREE_CODE (*node
) == FUNCTION_DECL
7013 || TREE_CODE (*node
) == LABEL_DECL
)
7015 if (lookup_attribute ("cold", DECL_ATTRIBUTES (*node
)) != NULL
)
7017 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
7018 "with attribute %qs", name
, "cold");
7019 *no_add_attrs
= true;
7021 /* Most of the rest of the hot processing is done later with
7022 lookup_attribute. */
7026 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7027 *no_add_attrs
= true;
7033 /* Handle a "cold" and attribute; arguments as in
7034 struct attribute_spec.handler. */
7037 handle_cold_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7038 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7040 if (TREE_CODE (*node
) == FUNCTION_DECL
7041 || TREE_CODE (*node
) == LABEL_DECL
)
7043 if (lookup_attribute ("hot", DECL_ATTRIBUTES (*node
)) != NULL
)
7045 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
7046 "with attribute %qs", name
, "hot");
7047 *no_add_attrs
= true;
7049 /* Most of the rest of the cold processing is done later with
7050 lookup_attribute. */
7054 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7055 *no_add_attrs
= true;
7061 /* Handle a "no_sanitize_address" attribute; arguments as in
7062 struct attribute_spec.handler. */
7065 handle_no_sanitize_address_attribute (tree
*node
, tree name
, tree
, int,
7068 if (TREE_CODE (*node
) != FUNCTION_DECL
)
7070 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7071 *no_add_attrs
= true;
7077 /* Handle a "no_address_safety_analysis" attribute; arguments as in
7078 struct attribute_spec.handler. */
7081 handle_no_address_safety_analysis_attribute (tree
*node
, tree name
, tree
, int,
7084 if (TREE_CODE (*node
) != FUNCTION_DECL
)
7085 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7086 else if (!lookup_attribute ("no_sanitize_address", DECL_ATTRIBUTES (*node
)))
7087 DECL_ATTRIBUTES (*node
)
7088 = tree_cons (get_identifier ("no_sanitize_address"),
7089 NULL_TREE
, DECL_ATTRIBUTES (*node
));
7090 *no_add_attrs
= true;
7094 /* Handle a "no_sanitize_undefined" attribute; arguments as in
7095 struct attribute_spec.handler. */
7098 handle_no_sanitize_undefined_attribute (tree
*node
, tree name
, tree
, int,
7101 if (TREE_CODE (*node
) != FUNCTION_DECL
)
7103 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7104 *no_add_attrs
= true;
7110 /* Handle a "stack_protect" attribute; arguments as in
7111 struct attribute_spec.handler. */
7113 handle_stack_protect_attribute (tree
*node
, tree name
, tree
, int,
7116 if (TREE_CODE (*node
) != FUNCTION_DECL
)
7118 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7119 *no_add_attrs
= true;
7122 DECL_ATTRIBUTES (*node
)
7123 = tree_cons (get_identifier ("stack_protect"),
7124 NULL_TREE
, DECL_ATTRIBUTES (*node
));
7129 /* Handle a "noinline" attribute; arguments as in
7130 struct attribute_spec.handler. */
7133 handle_noinline_attribute (tree
*node
, tree name
,
7134 tree
ARG_UNUSED (args
),
7135 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7137 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7139 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node
)))
7141 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
7142 "with attribute %qs", name
, "always_inline");
7143 *no_add_attrs
= true;
7146 DECL_UNINLINABLE (*node
) = 1;
7150 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7151 *no_add_attrs
= true;
7157 /* Handle a "noclone" attribute; arguments as in
7158 struct attribute_spec.handler. */
7161 handle_noclone_attribute (tree
*node
, tree name
,
7162 tree
ARG_UNUSED (args
),
7163 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7165 if (TREE_CODE (*node
) != FUNCTION_DECL
)
7167 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7168 *no_add_attrs
= true;
7174 /* Handle a "no_icf" attribute; arguments as in
7175 struct attribute_spec.handler. */
7178 handle_noicf_attribute (tree
*node
, tree name
,
7179 tree
ARG_UNUSED (args
),
7180 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7182 if (TREE_CODE (*node
) != FUNCTION_DECL
)
7184 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7185 *no_add_attrs
= true;
7192 /* Handle a "always_inline" attribute; arguments as in
7193 struct attribute_spec.handler. */
7196 handle_always_inline_attribute (tree
*node
, tree name
,
7197 tree
ARG_UNUSED (args
),
7198 int ARG_UNUSED (flags
),
7201 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7203 if (lookup_attribute ("noinline", DECL_ATTRIBUTES (*node
)))
7205 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
7206 "with %qs attribute", name
, "noinline");
7207 *no_add_attrs
= true;
7210 /* Set the attribute and mark it for disregarding inline
7212 DECL_DISREGARD_INLINE_LIMITS (*node
) = 1;
7216 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7217 *no_add_attrs
= true;
7223 /* Handle a "gnu_inline" attribute; arguments as in
7224 struct attribute_spec.handler. */
7227 handle_gnu_inline_attribute (tree
*node
, tree name
,
7228 tree
ARG_UNUSED (args
),
7229 int ARG_UNUSED (flags
),
7232 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
7234 /* Do nothing else, just set the attribute. We'll get at
7235 it later with lookup_attribute. */
7239 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7240 *no_add_attrs
= true;
7246 /* Handle a "leaf" attribute; arguments as in
7247 struct attribute_spec.handler. */
7250 handle_leaf_attribute (tree
*node
, tree name
,
7251 tree
ARG_UNUSED (args
),
7252 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7254 if (TREE_CODE (*node
) != FUNCTION_DECL
)
7256 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7257 *no_add_attrs
= true;
7259 if (!TREE_PUBLIC (*node
))
7261 warning (OPT_Wattributes
, "%qE attribute has no effect on unit local functions", name
);
7262 *no_add_attrs
= true;
7268 /* Handle an "artificial" attribute; arguments as in
7269 struct attribute_spec.handler. */
7272 handle_artificial_attribute (tree
*node
, tree name
,
7273 tree
ARG_UNUSED (args
),
7274 int ARG_UNUSED (flags
),
7277 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
7279 /* Do nothing else, just set the attribute. We'll get at
7280 it later with lookup_attribute. */
7284 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7285 *no_add_attrs
= true;
7291 /* Handle a "flatten" attribute; arguments as in
7292 struct attribute_spec.handler. */
7295 handle_flatten_attribute (tree
*node
, tree name
,
7296 tree args ATTRIBUTE_UNUSED
,
7297 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
7299 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7300 /* Do nothing else, just set the attribute. We'll get at
7301 it later with lookup_attribute. */
7305 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7306 *no_add_attrs
= true;
7312 /* Handle a "warning" or "error" attribute; arguments as in
7313 struct attribute_spec.handler. */
7316 handle_error_attribute (tree
*node
, tree name
, tree args
,
7317 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7319 if (TREE_CODE (*node
) == FUNCTION_DECL
7320 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
7321 /* Do nothing else, just set the attribute. We'll get at
7322 it later with lookup_attribute. */
7326 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7327 *no_add_attrs
= true;
7333 /* Handle a "used" attribute; arguments as in
7334 struct attribute_spec.handler. */
7337 handle_used_attribute (tree
*pnode
, tree name
, tree
ARG_UNUSED (args
),
7338 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7342 if (TREE_CODE (node
) == FUNCTION_DECL
7343 || (TREE_CODE (node
) == VAR_DECL
&& TREE_STATIC (node
))
7344 || (TREE_CODE (node
) == TYPE_DECL
))
7346 TREE_USED (node
) = 1;
7347 DECL_PRESERVE_P (node
) = 1;
7348 if (TREE_CODE (node
) == VAR_DECL
)
7349 DECL_READ_P (node
) = 1;
7353 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7354 *no_add_attrs
= true;
7360 /* Handle a "unused" attribute; arguments as in
7361 struct attribute_spec.handler. */
7364 handle_unused_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7365 int flags
, bool *no_add_attrs
)
7371 if (TREE_CODE (decl
) == PARM_DECL
7372 || TREE_CODE (decl
) == VAR_DECL
7373 || TREE_CODE (decl
) == FUNCTION_DECL
7374 || TREE_CODE (decl
) == LABEL_DECL
7375 || TREE_CODE (decl
) == TYPE_DECL
)
7377 TREE_USED (decl
) = 1;
7378 if (TREE_CODE (decl
) == VAR_DECL
7379 || TREE_CODE (decl
) == PARM_DECL
)
7380 DECL_READ_P (decl
) = 1;
7384 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7385 *no_add_attrs
= true;
7390 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7391 *node
= build_variant_type_copy (*node
);
7392 TREE_USED (*node
) = 1;
7398 /* Handle a "externally_visible" attribute; arguments as in
7399 struct attribute_spec.handler. */
7402 handle_externally_visible_attribute (tree
*pnode
, tree name
,
7403 tree
ARG_UNUSED (args
),
7404 int ARG_UNUSED (flags
),
7409 if (VAR_OR_FUNCTION_DECL_P (node
))
7411 if ((!TREE_STATIC (node
) && TREE_CODE (node
) != FUNCTION_DECL
7412 && !DECL_EXTERNAL (node
)) || !TREE_PUBLIC (node
))
7414 warning (OPT_Wattributes
,
7415 "%qE attribute have effect only on public objects", name
);
7416 *no_add_attrs
= true;
7421 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7422 *no_add_attrs
= true;
7428 /* Handle the "no_reorder" attribute. Arguments as in
7429 struct attribute_spec.handler. */
7432 handle_no_reorder_attribute (tree
*pnode
,
7440 if (!VAR_OR_FUNCTION_DECL_P (node
)
7441 && !(TREE_STATIC (node
) || DECL_EXTERNAL (node
)))
7443 warning (OPT_Wattributes
,
7444 "%qE attribute only affects top level objects",
7446 *no_add_attrs
= true;
7452 /* Handle a "const" attribute; arguments as in
7453 struct attribute_spec.handler. */
7456 handle_const_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7457 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7459 tree type
= TREE_TYPE (*node
);
7461 /* See FIXME comment on noreturn in c_common_attribute_table. */
7462 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7463 TREE_READONLY (*node
) = 1;
7464 else if (TREE_CODE (type
) == POINTER_TYPE
7465 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
7467 = (build_qualified_type
7469 (build_type_variant (TREE_TYPE (type
), 1,
7470 TREE_THIS_VOLATILE (TREE_TYPE (type
)))),
7471 TYPE_QUALS (type
)));
7474 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7475 *no_add_attrs
= true;
7481 /* Handle a "transparent_union" attribute; arguments as in
7482 struct attribute_spec.handler. */
7485 handle_transparent_union_attribute (tree
*node
, tree name
,
7486 tree
ARG_UNUSED (args
), int flags
,
7491 *no_add_attrs
= true;
7494 if (TREE_CODE (*node
) == TYPE_DECL
7495 && ! (flags
& ATTR_FLAG_CXX11
))
7496 node
= &TREE_TYPE (*node
);
7499 if (TREE_CODE (type
) == UNION_TYPE
)
7501 /* Make sure that the first field will work for a transparent union.
7502 If the type isn't complete yet, leave the check to the code in
7504 if (TYPE_SIZE (type
))
7506 tree first
= first_field (type
);
7507 if (first
== NULL_TREE
7508 || DECL_ARTIFICIAL (first
)
7509 || TYPE_MODE (type
) != DECL_MODE (first
))
7513 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7515 /* If the type isn't complete yet, setting the flag
7516 on a variant wouldn't ever be checked. */
7517 if (!TYPE_SIZE (type
))
7520 /* build_duplicate_type doesn't work for C++. */
7521 if (c_dialect_cxx ())
7524 /* A type variant isn't good enough, since we don't a cast
7525 to such a type removed as a no-op. */
7526 *node
= type
= build_duplicate_type (type
);
7529 TYPE_TRANSPARENT_AGGR (type
) = 1;
7534 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7538 /* Subroutine of handle_{con,de}structor_attribute. Evaluate ARGS to
7539 get the requested priority for a constructor or destructor,
7540 possibly issuing diagnostics for invalid or reserved
7543 static priority_type
7544 get_priority (tree args
, bool is_destructor
)
7550 return DEFAULT_INIT_PRIORITY
;
7552 if (!SUPPORTS_INIT_PRIORITY
)
7555 error ("destructor priorities are not supported");
7557 error ("constructor priorities are not supported");
7558 return DEFAULT_INIT_PRIORITY
;
7561 arg
= TREE_VALUE (args
);
7562 if (TREE_CODE (arg
) == IDENTIFIER_NODE
)
7564 if (arg
== error_mark_node
)
7565 return DEFAULT_INIT_PRIORITY
;
7566 arg
= default_conversion (arg
);
7567 if (!tree_fits_shwi_p (arg
)
7568 || !INTEGRAL_TYPE_P (TREE_TYPE (arg
)))
7571 pri
= tree_to_shwi (arg
);
7572 if (pri
< 0 || pri
> MAX_INIT_PRIORITY
)
7575 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
7579 "destructor priorities from 0 to %d are reserved "
7580 "for the implementation",
7581 MAX_RESERVED_INIT_PRIORITY
);
7584 "constructor priorities from 0 to %d are reserved "
7585 "for the implementation",
7586 MAX_RESERVED_INIT_PRIORITY
);
7592 error ("destructor priorities must be integers from 0 to %d inclusive",
7595 error ("constructor priorities must be integers from 0 to %d inclusive",
7597 return DEFAULT_INIT_PRIORITY
;
7600 /* Handle a "constructor" attribute; arguments as in
7601 struct attribute_spec.handler. */
7604 handle_constructor_attribute (tree
*node
, tree name
, tree args
,
7605 int ARG_UNUSED (flags
),
7609 tree type
= TREE_TYPE (decl
);
7611 if (TREE_CODE (decl
) == FUNCTION_DECL
7612 && TREE_CODE (type
) == FUNCTION_TYPE
7613 && decl_function_context (decl
) == 0)
7615 priority_type priority
;
7616 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
7617 priority
= get_priority (args
, /*is_destructor=*/false);
7618 SET_DECL_INIT_PRIORITY (decl
, priority
);
7619 TREE_USED (decl
) = 1;
7623 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7624 *no_add_attrs
= true;
7630 /* Handle a "destructor" attribute; arguments as in
7631 struct attribute_spec.handler. */
7634 handle_destructor_attribute (tree
*node
, tree name
, tree args
,
7635 int ARG_UNUSED (flags
),
7639 tree type
= TREE_TYPE (decl
);
7641 if (TREE_CODE (decl
) == FUNCTION_DECL
7642 && TREE_CODE (type
) == FUNCTION_TYPE
7643 && decl_function_context (decl
) == 0)
7645 priority_type priority
;
7646 DECL_STATIC_DESTRUCTOR (decl
) = 1;
7647 priority
= get_priority (args
, /*is_destructor=*/true);
7648 SET_DECL_FINI_PRIORITY (decl
, priority
);
7649 TREE_USED (decl
) = 1;
7653 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7654 *no_add_attrs
= true;
7660 /* Nonzero if the mode is a valid vector mode for this architecture.
7661 This returns nonzero even if there is no hardware support for the
7662 vector mode, but we can emulate with narrower modes. */
7665 vector_mode_valid_p (machine_mode mode
)
7667 enum mode_class mclass
= GET_MODE_CLASS (mode
);
7668 machine_mode innermode
;
7670 /* Doh! What's going on? */
7671 if (mclass
!= MODE_VECTOR_INT
7672 && mclass
!= MODE_VECTOR_FLOAT
7673 && mclass
!= MODE_VECTOR_FRACT
7674 && mclass
!= MODE_VECTOR_UFRACT
7675 && mclass
!= MODE_VECTOR_ACCUM
7676 && mclass
!= MODE_VECTOR_UACCUM
)
7679 /* Hardware support. Woo hoo! */
7680 if (targetm
.vector_mode_supported_p (mode
))
7683 innermode
= GET_MODE_INNER (mode
);
7685 /* We should probably return 1 if requesting V4DI and we have no DI,
7686 but we have V2DI, but this is probably very unlikely. */
7688 /* If we have support for the inner mode, we can safely emulate it.
7689 We may not have V2DI, but me can emulate with a pair of DIs. */
7690 return targetm
.scalar_mode_supported_p (innermode
);
7694 /* Handle a "mode" attribute; arguments as in
7695 struct attribute_spec.handler. */
7698 handle_mode_attribute (tree
*node
, tree name
, tree args
,
7699 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7702 tree ident
= TREE_VALUE (args
);
7704 *no_add_attrs
= true;
7706 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
7707 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7711 const char *p
= IDENTIFIER_POINTER (ident
);
7712 int len
= strlen (p
);
7713 machine_mode mode
= VOIDmode
;
7717 if (len
> 4 && p
[0] == '_' && p
[1] == '_'
7718 && p
[len
- 1] == '_' && p
[len
- 2] == '_')
7720 char *newp
= (char *) alloca (len
- 1);
7722 strcpy (newp
, &p
[2]);
7723 newp
[len
- 4] = '\0';
7727 /* Change this type to have a type with the specified mode.
7728 First check for the special modes. */
7729 if (!strcmp (p
, "byte"))
7731 else if (!strcmp (p
, "word"))
7733 else if (!strcmp (p
, "pointer"))
7735 else if (!strcmp (p
, "libgcc_cmp_return"))
7736 mode
= targetm
.libgcc_cmp_return_mode ();
7737 else if (!strcmp (p
, "libgcc_shift_count"))
7738 mode
= targetm
.libgcc_shift_count_mode ();
7739 else if (!strcmp (p
, "unwind_word"))
7740 mode
= targetm
.unwind_word_mode ();
7742 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
7743 if (!strcmp (p
, GET_MODE_NAME (j
)))
7745 mode
= (machine_mode
) j
;
7749 if (mode
== VOIDmode
)
7751 error ("unknown machine mode %qE", ident
);
7756 switch (GET_MODE_CLASS (mode
))
7759 case MODE_PARTIAL_INT
:
7761 case MODE_DECIMAL_FLOAT
:
7766 valid_mode
= targetm
.scalar_mode_supported_p (mode
);
7769 case MODE_COMPLEX_INT
:
7770 case MODE_COMPLEX_FLOAT
:
7771 valid_mode
= targetm
.scalar_mode_supported_p (GET_MODE_INNER (mode
));
7774 case MODE_VECTOR_INT
:
7775 case MODE_VECTOR_FLOAT
:
7776 case MODE_VECTOR_FRACT
:
7777 case MODE_VECTOR_UFRACT
:
7778 case MODE_VECTOR_ACCUM
:
7779 case MODE_VECTOR_UACCUM
:
7780 warning (OPT_Wattributes
, "specifying vector types with "
7781 "__attribute__ ((mode)) is deprecated");
7782 warning (OPT_Wattributes
,
7783 "use __attribute__ ((vector_size)) instead");
7784 valid_mode
= vector_mode_valid_p (mode
);
7792 error ("unable to emulate %qs", p
);
7796 if (POINTER_TYPE_P (type
))
7798 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
7799 tree (*fn
)(tree
, machine_mode
, bool);
7801 if (!targetm
.addr_space
.valid_pointer_mode (mode
, as
))
7803 error ("invalid pointer mode %qs", p
);
7807 if (TREE_CODE (type
) == POINTER_TYPE
)
7808 fn
= build_pointer_type_for_mode
;
7810 fn
= build_reference_type_for_mode
;
7811 typefm
= fn (TREE_TYPE (type
), mode
, false);
7815 /* For fixed-point modes, we need to test if the signness of type
7816 and the machine mode are consistent. */
7817 if (ALL_FIXED_POINT_MODE_P (mode
)
7818 && TYPE_UNSIGNED (type
) != UNSIGNED_FIXED_POINT_MODE_P (mode
))
7820 error ("signedness of type and machine mode %qs don%'t match", p
);
7823 /* For fixed-point modes, we need to pass saturating info. */
7824 typefm
= lang_hooks
.types
.type_for_mode (mode
,
7825 ALL_FIXED_POINT_MODE_P (mode
) ? TYPE_SATURATING (type
)
7826 : TYPE_UNSIGNED (type
));
7829 if (typefm
== NULL_TREE
)
7831 error ("no data type for mode %qs", p
);
7834 else if (TREE_CODE (type
) == ENUMERAL_TYPE
)
7836 /* For enumeral types, copy the precision from the integer
7837 type returned above. If not an INTEGER_TYPE, we can't use
7838 this mode for this type. */
7839 if (TREE_CODE (typefm
) != INTEGER_TYPE
)
7841 error ("cannot use mode %qs for enumeral types", p
);
7845 if (flags
& ATTR_FLAG_TYPE_IN_PLACE
)
7847 TYPE_PRECISION (type
) = TYPE_PRECISION (typefm
);
7852 /* We cannot build a type variant, as there's code that assumes
7853 that TYPE_MAIN_VARIANT has the same mode. This includes the
7854 debug generators. Instead, create a subrange type. This
7855 results in all of the enumeral values being emitted only once
7856 in the original, and the subtype gets them by reference. */
7857 if (TYPE_UNSIGNED (type
))
7858 typefm
= make_unsigned_type (TYPE_PRECISION (typefm
));
7860 typefm
= make_signed_type (TYPE_PRECISION (typefm
));
7861 TREE_TYPE (typefm
) = type
;
7864 else if (VECTOR_MODE_P (mode
)
7865 ? TREE_CODE (type
) != TREE_CODE (TREE_TYPE (typefm
))
7866 : TREE_CODE (type
) != TREE_CODE (typefm
))
7868 error ("mode %qs applied to inappropriate type", p
);
7878 /* Handle a "section" attribute; arguments as in
7879 struct attribute_spec.handler. */
7882 handle_section_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7883 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7887 if (!targetm_common
.have_named_sections
)
7889 error_at (DECL_SOURCE_LOCATION (*node
),
7890 "section attributes are not supported for this target");
7894 user_defined_section_attribute
= true;
7896 if (!VAR_OR_FUNCTION_DECL_P (decl
))
7898 error ("section attribute not allowed for %q+D", *node
);
7902 if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
7904 error ("section attribute argument not a string constant");
7908 if (TREE_CODE (decl
) == VAR_DECL
7909 && current_function_decl
!= NULL_TREE
7910 && !TREE_STATIC (decl
))
7912 error_at (DECL_SOURCE_LOCATION (decl
),
7913 "section attribute cannot be specified for local variables");
7917 /* The decl may have already been given a section attribute
7918 from a previous declaration. Ensure they match. */
7919 if (DECL_SECTION_NAME (decl
) != NULL
7920 && strcmp (DECL_SECTION_NAME (decl
),
7921 TREE_STRING_POINTER (TREE_VALUE (args
))) != 0)
7923 error ("section of %q+D conflicts with previous declaration", *node
);
7927 if (TREE_CODE (decl
) == VAR_DECL
7928 && !targetm
.have_tls
&& targetm
.emutls
.tmpl_section
7929 && DECL_THREAD_LOCAL_P (decl
))
7931 error ("section of %q+D cannot be overridden", *node
);
7935 set_decl_section_name (decl
, TREE_STRING_POINTER (TREE_VALUE (args
)));
7939 *no_add_attrs
= true;
7943 /* Check whether ALIGN is a valid user-specified alignment. If so,
7944 return its base-2 log; if not, output an error and return -1. If
7945 ALLOW_ZERO then 0 is valid and should result in a return of -1 with
7948 check_user_alignment (const_tree align
, bool allow_zero
)
7952 if (error_operand_p (align
))
7954 if (TREE_CODE (align
) != INTEGER_CST
7955 || !INTEGRAL_TYPE_P (TREE_TYPE (align
)))
7957 error ("requested alignment is not an integer constant");
7960 else if (allow_zero
&& integer_zerop (align
))
7962 else if (tree_int_cst_sgn (align
) == -1
7963 || (i
= tree_log2 (align
)) == -1)
7965 error ("requested alignment is not a positive power of 2");
7968 else if (i
>= HOST_BITS_PER_INT
- BITS_PER_UNIT_LOG
)
7970 error ("requested alignment is too large");
7977 If in c++-11, check if the c++-11 alignment constraint with respect
7978 to fundamental alignment (in [dcl.align]) are satisfied. If not in
7979 c++-11 mode, does nothing.
7983 [* if the constant expression evaluates to a fundamental alignment,
7984 the alignment requirement of the declared entity shall be the
7985 specified fundamental alignment.
7987 * if the constant expression evaluates to an extended alignment
7988 and the implementation supports that alignment in the context
7989 of the declaration, the alignment of the declared entity shall
7992 * if the constant expression evaluates to an extended alignment
7993 and the implementation does not support that alignment in the
7994 context of the declaration, the program is ill-formed]. */
7997 check_cxx_fundamental_alignment_constraints (tree node
,
8001 bool alignment_too_large_p
= false;
8002 unsigned requested_alignment
= 1U << align_log
;
8003 unsigned max_align
= 0;
8005 if ((!(flags
& ATTR_FLAG_CXX11
) && !warn_cxx_compat
)
8006 || (node
== NULL_TREE
|| node
== error_mark_node
))
8009 if (cxx_fundamental_alignment_p (requested_alignment
))
8014 if (TREE_STATIC (node
))
8016 /* For file scope variables and static members, the target
8017 supports alignments that are at most
8018 MAX_OFILE_ALIGNMENT. */
8019 if (requested_alignment
> (max_align
= MAX_OFILE_ALIGNMENT
))
8020 alignment_too_large_p
= true;
8024 #ifdef BIGGEST_FIELD_ALIGNMENT
8025 #define MAX_TARGET_FIELD_ALIGNMENT BIGGEST_FIELD_ALIGNMENT
8027 #define MAX_TARGET_FIELD_ALIGNMENT BIGGEST_ALIGNMENT
8029 /* For non-static members, the target supports either
8030 alignments that at most either BIGGEST_FIELD_ALIGNMENT
8031 if it is defined or BIGGEST_ALIGNMENT. */
8032 max_align
= MAX_TARGET_FIELD_ALIGNMENT
;
8033 if (TREE_CODE (node
) == FIELD_DECL
8034 && requested_alignment
> (max_align
= MAX_TARGET_FIELD_ALIGNMENT
))
8035 alignment_too_large_p
= true;
8036 #undef MAX_TARGET_FIELD_ALIGNMENT
8037 /* For stack variables, the target supports at most
8038 MAX_STACK_ALIGNMENT. */
8039 else if (decl_function_context (node
) != NULL
8040 && requested_alignment
> (max_align
= MAX_STACK_ALIGNMENT
))
8041 alignment_too_large_p
= true;
8044 else if (TYPE_P (node
))
8046 /* Let's be liberal for types. */
8047 if (requested_alignment
> (max_align
= BIGGEST_ALIGNMENT
))
8048 alignment_too_large_p
= true;
8051 if (alignment_too_large_p
)
8052 pedwarn (input_location
, OPT_Wattributes
,
8053 "requested alignment %d is larger than %d",
8054 requested_alignment
, max_align
);
8056 return !alignment_too_large_p
;
8059 /* Handle a "aligned" attribute; arguments as in
8060 struct attribute_spec.handler. */
8063 handle_aligned_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
8064 int flags
, bool *no_add_attrs
)
8066 tree decl
= NULL_TREE
;
8074 align_expr
= TREE_VALUE (args
);
8075 if (align_expr
&& TREE_CODE (align_expr
) != IDENTIFIER_NODE
8076 && TREE_CODE (align_expr
) != FUNCTION_DECL
)
8077 align_expr
= default_conversion (align_expr
);
8080 align_expr
= size_int (ATTRIBUTE_ALIGNED_VALUE
/ BITS_PER_UNIT
);
8085 type
= &TREE_TYPE (decl
);
8086 is_type
= TREE_CODE (*node
) == TYPE_DECL
;
8088 else if (TYPE_P (*node
))
8089 type
= node
, is_type
= 1;
8091 if ((i
= check_user_alignment (align_expr
, false)) == -1
8092 || !check_cxx_fundamental_alignment_constraints (*node
, i
, flags
))
8093 *no_add_attrs
= true;
8096 if ((flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
8097 /* OK, modify the type in place. */;
8098 /* If we have a TYPE_DECL, then copy the type, so that we
8099 don't accidentally modify a builtin type. See pushdecl. */
8100 else if (decl
&& TREE_TYPE (decl
) != error_mark_node
8101 && DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
)
8103 tree tt
= TREE_TYPE (decl
);
8104 *type
= build_variant_type_copy (*type
);
8105 DECL_ORIGINAL_TYPE (decl
) = tt
;
8106 TYPE_NAME (*type
) = decl
;
8107 TREE_USED (*type
) = TREE_USED (decl
);
8108 TREE_TYPE (decl
) = *type
;
8111 *type
= build_variant_type_copy (*type
);
8113 TYPE_ALIGN (*type
) = (1U << i
) * BITS_PER_UNIT
;
8114 TYPE_USER_ALIGN (*type
) = 1;
8116 else if (! VAR_OR_FUNCTION_DECL_P (decl
)
8117 && TREE_CODE (decl
) != FIELD_DECL
)
8119 error ("alignment may not be specified for %q+D", decl
);
8120 *no_add_attrs
= true;
8122 else if (DECL_USER_ALIGN (decl
)
8123 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
8124 /* C++-11 [dcl.align/4]:
8126 When multiple alignment-specifiers are specified for an
8127 entity, the alignment requirement shall be set to the
8128 strictest specified alignment.
8130 This formally comes from the c++11 specification but we are
8131 doing it for the GNU attribute syntax as well. */
8132 *no_add_attrs
= true;
8133 else if (TREE_CODE (decl
) == FUNCTION_DECL
8134 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
8136 if (DECL_USER_ALIGN (decl
))
8137 error ("alignment for %q+D was previously specified as %d "
8138 "and may not be decreased", decl
,
8139 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
8141 error ("alignment for %q+D must be at least %d", decl
,
8142 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
8143 *no_add_attrs
= true;
8147 DECL_ALIGN (decl
) = (1U << i
) * BITS_PER_UNIT
;
8148 DECL_USER_ALIGN (decl
) = 1;
8154 /* Handle a "weak" attribute; arguments as in
8155 struct attribute_spec.handler. */
8158 handle_weak_attribute (tree
*node
, tree name
,
8159 tree
ARG_UNUSED (args
),
8160 int ARG_UNUSED (flags
),
8161 bool * ARG_UNUSED (no_add_attrs
))
8163 if (TREE_CODE (*node
) == FUNCTION_DECL
8164 && DECL_DECLARED_INLINE_P (*node
))
8166 warning (OPT_Wattributes
, "inline function %q+D declared weak", *node
);
8167 *no_add_attrs
= true;
8169 else if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
8171 error ("indirect function %q+D cannot be declared weak", *node
);
8172 *no_add_attrs
= true;
8175 else if (VAR_OR_FUNCTION_DECL_P (*node
))
8177 struct symtab_node
*n
= symtab_node::get (*node
);
8178 if (n
&& n
->refuse_visibility_changes
)
8179 error ("%+D declared weak after being used", *node
);
8180 declare_weak (*node
);
8183 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8188 /* Handle an "alias" or "ifunc" attribute; arguments as in
8189 struct attribute_spec.handler, except that IS_ALIAS tells us
8190 whether this is an alias as opposed to ifunc attribute. */
8193 handle_alias_ifunc_attribute (bool is_alias
, tree
*node
, tree name
, tree args
,
8198 if (TREE_CODE (decl
) != FUNCTION_DECL
8199 && (!is_alias
|| TREE_CODE (decl
) != VAR_DECL
))
8201 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8202 *no_add_attrs
= true;
8204 else if ((TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INITIAL (decl
))
8205 || (TREE_CODE (decl
) != FUNCTION_DECL
8206 && TREE_PUBLIC (decl
) && !DECL_EXTERNAL (decl
))
8207 /* A static variable declaration is always a tentative definition,
8208 but the alias is a non-tentative definition which overrides. */
8209 || (TREE_CODE (decl
) != FUNCTION_DECL
8210 && ! TREE_PUBLIC (decl
) && DECL_INITIAL (decl
)))
8212 error ("%q+D defined both normally and as %qE attribute", decl
, name
);
8213 *no_add_attrs
= true;
8217 && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
8218 || lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
))))
8220 error ("weak %q+D cannot be defined %qE", decl
, name
);
8221 *no_add_attrs
= true;
8225 /* Note that the very first time we process a nested declaration,
8226 decl_function_context will not be set. Indeed, *would* never
8227 be set except for the DECL_INITIAL/DECL_EXTERNAL frobbery that
8228 we do below. After such frobbery, pushdecl would set the context.
8229 In any case, this is never what we want. */
8230 else if (decl_function_context (decl
) == 0 && current_function_decl
== NULL
)
8234 id
= TREE_VALUE (args
);
8235 if (TREE_CODE (id
) != STRING_CST
)
8237 error ("attribute %qE argument not a string", name
);
8238 *no_add_attrs
= true;
8241 id
= get_identifier (TREE_STRING_POINTER (id
));
8242 /* This counts as a use of the object pointed to. */
8245 if (TREE_CODE (decl
) == FUNCTION_DECL
)
8246 DECL_INITIAL (decl
) = error_mark_node
;
8248 TREE_STATIC (decl
) = 1;
8251 /* ifuncs are also aliases, so set that attribute too. */
8252 DECL_ATTRIBUTES (decl
)
8253 = tree_cons (get_identifier ("alias"), args
, DECL_ATTRIBUTES (decl
));
8257 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8258 *no_add_attrs
= true;
8261 if (decl_in_symtab_p (*node
))
8263 struct symtab_node
*n
= symtab_node::get (decl
);
8264 if (n
&& n
->refuse_visibility_changes
)
8267 error ("%+D declared alias after being used", decl
);
8269 error ("%+D declared ifunc after being used", decl
);
8277 /* Handle an "alias" or "ifunc" attribute; arguments as in
8278 struct attribute_spec.handler. */
8281 handle_ifunc_attribute (tree
*node
, tree name
, tree args
,
8282 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8284 return handle_alias_ifunc_attribute (false, node
, name
, args
, no_add_attrs
);
8287 /* Handle an "alias" or "ifunc" attribute; arguments as in
8288 struct attribute_spec.handler. */
8291 handle_alias_attribute (tree
*node
, tree name
, tree args
,
8292 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8294 return handle_alias_ifunc_attribute (true, node
, name
, args
, no_add_attrs
);
8297 /* Handle a "weakref" attribute; arguments as in struct
8298 attribute_spec.handler. */
8301 handle_weakref_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
8302 int flags
, bool *no_add_attrs
)
8304 tree attr
= NULL_TREE
;
8306 /* We must ignore the attribute when it is associated with
8307 local-scoped decls, since attribute alias is ignored and many
8308 such symbols do not even have a DECL_WEAK field. */
8309 if (decl_function_context (*node
)
8310 || current_function_decl
8311 || !VAR_OR_FUNCTION_DECL_P (*node
))
8313 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8314 *no_add_attrs
= true;
8318 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
8320 error ("indirect function %q+D cannot be declared weakref", *node
);
8321 *no_add_attrs
= true;
8325 /* The idea here is that `weakref("name")' mutates into `weakref,
8326 alias("name")', and weakref without arguments, in turn,
8327 implicitly adds weak. */
8331 attr
= tree_cons (get_identifier ("alias"), args
, attr
);
8332 attr
= tree_cons (get_identifier ("weakref"), NULL_TREE
, attr
);
8334 *no_add_attrs
= true;
8336 decl_attributes (node
, attr
, flags
);
8340 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node
)))
8341 error_at (DECL_SOURCE_LOCATION (*node
),
8342 "weakref attribute must appear before alias attribute");
8344 /* Can't call declare_weak because it wants this to be TREE_PUBLIC,
8345 and that isn't supported; and because it wants to add it to
8346 the list of weak decls, which isn't helpful. */
8347 DECL_WEAK (*node
) = 1;
8350 if (decl_in_symtab_p (*node
))
8352 struct symtab_node
*n
= symtab_node::get (*node
);
8353 if (n
&& n
->refuse_visibility_changes
)
8354 error ("%+D declared weakref after being used", *node
);
8360 /* Handle an "visibility" attribute; arguments as in
8361 struct attribute_spec.handler. */
8364 handle_visibility_attribute (tree
*node
, tree name
, tree args
,
8365 int ARG_UNUSED (flags
),
8366 bool *ARG_UNUSED (no_add_attrs
))
8369 tree id
= TREE_VALUE (args
);
8370 enum symbol_visibility vis
;
8374 if (TREE_CODE (*node
) == ENUMERAL_TYPE
)
8376 else if (TREE_CODE (*node
) != RECORD_TYPE
&& TREE_CODE (*node
) != UNION_TYPE
)
8378 warning (OPT_Wattributes
, "%qE attribute ignored on non-class types",
8382 else if (TYPE_FIELDS (*node
))
8384 error ("%qE attribute ignored because %qT is already defined",
8389 else if (decl_function_context (decl
) != 0 || !TREE_PUBLIC (decl
))
8391 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8395 if (TREE_CODE (id
) != STRING_CST
)
8397 error ("visibility argument not a string");
8401 /* If this is a type, set the visibility on the type decl. */
8404 decl
= TYPE_NAME (decl
);
8407 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
8409 warning (OPT_Wattributes
, "%qE attribute ignored on types",
8415 if (strcmp (TREE_STRING_POINTER (id
), "default") == 0)
8416 vis
= VISIBILITY_DEFAULT
;
8417 else if (strcmp (TREE_STRING_POINTER (id
), "internal") == 0)
8418 vis
= VISIBILITY_INTERNAL
;
8419 else if (strcmp (TREE_STRING_POINTER (id
), "hidden") == 0)
8420 vis
= VISIBILITY_HIDDEN
;
8421 else if (strcmp (TREE_STRING_POINTER (id
), "protected") == 0)
8422 vis
= VISIBILITY_PROTECTED
;
8425 error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
8426 vis
= VISIBILITY_DEFAULT
;
8429 if (DECL_VISIBILITY_SPECIFIED (decl
)
8430 && vis
!= DECL_VISIBILITY (decl
))
8432 tree attributes
= (TYPE_P (*node
)
8433 ? TYPE_ATTRIBUTES (*node
)
8434 : DECL_ATTRIBUTES (decl
));
8435 if (lookup_attribute ("visibility", attributes
))
8436 error ("%qD redeclared with different visibility", decl
);
8437 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
8438 && lookup_attribute ("dllimport", attributes
))
8439 error ("%qD was declared %qs which implies default visibility",
8441 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
8442 && lookup_attribute ("dllexport", attributes
))
8443 error ("%qD was declared %qs which implies default visibility",
8447 DECL_VISIBILITY (decl
) = vis
;
8448 DECL_VISIBILITY_SPECIFIED (decl
) = 1;
8450 /* Go ahead and attach the attribute to the node as well. This is needed
8451 so we can determine whether we have VISIBILITY_DEFAULT because the
8452 visibility was not specified, or because it was explicitly overridden
8453 from the containing scope. */
8458 /* Determine the ELF symbol visibility for DECL, which is either a
8459 variable or a function. It is an error to use this function if a
8460 definition of DECL is not available in this translation unit.
8461 Returns true if the final visibility has been determined by this
8462 function; false if the caller is free to make additional
8466 c_determine_visibility (tree decl
)
8468 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
8470 /* If the user explicitly specified the visibility with an
8471 attribute, honor that. DECL_VISIBILITY will have been set during
8472 the processing of the attribute. We check for an explicit
8473 attribute, rather than just checking DECL_VISIBILITY_SPECIFIED,
8474 to distinguish the use of an attribute from the use of a "#pragma
8475 GCC visibility push(...)"; in the latter case we still want other
8476 considerations to be able to overrule the #pragma. */
8477 if (lookup_attribute ("visibility", DECL_ATTRIBUTES (decl
))
8478 || (TARGET_DLLIMPORT_DECL_ATTRIBUTES
8479 && (lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl
))
8480 || lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl
)))))
8483 /* Set default visibility to whatever the user supplied with
8484 visibility_specified depending on #pragma GCC visibility. */
8485 if (!DECL_VISIBILITY_SPECIFIED (decl
))
8487 if (visibility_options
.inpragma
8488 || DECL_VISIBILITY (decl
) != default_visibility
)
8490 DECL_VISIBILITY (decl
) = default_visibility
;
8491 DECL_VISIBILITY_SPECIFIED (decl
) = visibility_options
.inpragma
;
8492 /* If visibility changed and DECL already has DECL_RTL, ensure
8493 symbol flags are updated. */
8494 if (((TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
))
8495 || TREE_CODE (decl
) == FUNCTION_DECL
)
8496 && DECL_RTL_SET_P (decl
))
8497 make_decl_rtl (decl
);
8503 /* Handle an "tls_model" attribute; arguments as in
8504 struct attribute_spec.handler. */
8507 handle_tls_model_attribute (tree
*node
, tree name
, tree args
,
8508 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8512 enum tls_model kind
;
8514 *no_add_attrs
= true;
8516 if (TREE_CODE (decl
) != VAR_DECL
|| !DECL_THREAD_LOCAL_P (decl
))
8518 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8522 kind
= DECL_TLS_MODEL (decl
);
8523 id
= TREE_VALUE (args
);
8524 if (TREE_CODE (id
) != STRING_CST
)
8526 error ("tls_model argument not a string");
8530 if (!strcmp (TREE_STRING_POINTER (id
), "local-exec"))
8531 kind
= TLS_MODEL_LOCAL_EXEC
;
8532 else if (!strcmp (TREE_STRING_POINTER (id
), "initial-exec"))
8533 kind
= TLS_MODEL_INITIAL_EXEC
;
8534 else if (!strcmp (TREE_STRING_POINTER (id
), "local-dynamic"))
8535 kind
= optimize
? TLS_MODEL_LOCAL_DYNAMIC
: TLS_MODEL_GLOBAL_DYNAMIC
;
8536 else if (!strcmp (TREE_STRING_POINTER (id
), "global-dynamic"))
8537 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
8539 error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
8541 set_decl_tls_model (decl
, kind
);
8545 /* Handle a "no_instrument_function" attribute; arguments as in
8546 struct attribute_spec.handler. */
8549 handle_no_instrument_function_attribute (tree
*node
, tree name
,
8550 tree
ARG_UNUSED (args
),
8551 int ARG_UNUSED (flags
),
8556 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8558 error_at (DECL_SOURCE_LOCATION (decl
),
8559 "%qE attribute applies only to functions", name
);
8560 *no_add_attrs
= true;
8563 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
8568 /* Handle a "malloc" attribute; arguments as in
8569 struct attribute_spec.handler. */
8572 handle_malloc_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8573 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8575 if (TREE_CODE (*node
) == FUNCTION_DECL
8576 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node
))))
8577 DECL_IS_MALLOC (*node
) = 1;
8580 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8581 *no_add_attrs
= true;
8587 /* Handle a "alloc_size" attribute; arguments as in
8588 struct attribute_spec.handler. */
8591 handle_alloc_size_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
8592 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8594 unsigned arg_count
= type_num_arguments (*node
);
8595 for (; args
; args
= TREE_CHAIN (args
))
8597 tree position
= TREE_VALUE (args
);
8598 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
8599 && TREE_CODE (position
) != FUNCTION_DECL
)
8600 position
= default_conversion (position
);
8602 if (!tree_fits_uhwi_p (position
)
8604 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
8606 warning (OPT_Wattributes
,
8607 "alloc_size parameter outside range");
8608 *no_add_attrs
= true;
8615 /* Handle a "alloc_align" attribute; arguments as in
8616 struct attribute_spec.handler. */
8619 handle_alloc_align_attribute (tree
*node
, tree
, tree args
, int,
8622 unsigned arg_count
= type_num_arguments (*node
);
8623 tree position
= TREE_VALUE (args
);
8624 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
)
8625 position
= default_conversion (position
);
8627 if (!tree_fits_uhwi_p (position
)
8629 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
8631 warning (OPT_Wattributes
,
8632 "alloc_align parameter outside range");
8633 *no_add_attrs
= true;
8639 /* Handle a "assume_aligned" attribute; arguments as in
8640 struct attribute_spec.handler. */
8643 handle_assume_aligned_attribute (tree
*, tree
, tree args
, int,
8646 for (; args
; args
= TREE_CHAIN (args
))
8648 tree position
= TREE_VALUE (args
);
8649 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
8650 && TREE_CODE (position
) != FUNCTION_DECL
)
8651 position
= default_conversion (position
);
8653 if (TREE_CODE (position
) != INTEGER_CST
)
8655 warning (OPT_Wattributes
,
8656 "assume_aligned parameter not integer constant");
8657 *no_add_attrs
= true;
8664 /* Handle a "fn spec" attribute; arguments as in
8665 struct attribute_spec.handler. */
8668 handle_fnspec_attribute (tree
*node ATTRIBUTE_UNUSED
, tree
ARG_UNUSED (name
),
8669 tree args
, int ARG_UNUSED (flags
),
8670 bool *no_add_attrs ATTRIBUTE_UNUSED
)
8673 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
8674 && !TREE_CHAIN (args
));
8678 /* Handle a "bnd_variable_size" attribute; arguments as in
8679 struct attribute_spec.handler. */
8682 handle_bnd_variable_size_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8683 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8685 if (TREE_CODE (*node
) != FIELD_DECL
)
8687 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8688 *no_add_attrs
= true;
8694 /* Handle a "bnd_legacy" attribute; arguments as in
8695 struct attribute_spec.handler. */
8698 handle_bnd_legacy (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8699 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8701 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8703 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8704 *no_add_attrs
= true;
8710 /* Handle a "bnd_instrument" attribute; arguments as in
8711 struct attribute_spec.handler. */
8714 handle_bnd_instrument (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8715 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8717 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8719 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8720 *no_add_attrs
= true;
8726 /* Handle a "warn_unused" attribute; arguments as in
8727 struct attribute_spec.handler. */
8730 handle_warn_unused_attribute (tree
*node
, tree name
,
8731 tree args ATTRIBUTE_UNUSED
,
8732 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
8735 /* Do nothing else, just set the attribute. We'll get at
8736 it later with lookup_attribute. */
8740 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8741 *no_add_attrs
= true;
8747 /* Handle an "omp declare simd" attribute; arguments as in
8748 struct attribute_spec.handler. */
8751 handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int, bool *)
8756 /* Handle an "omp declare target" attribute; arguments as in
8757 struct attribute_spec.handler. */
8760 handle_omp_declare_target_attribute (tree
*, tree
, tree
, int, bool *)
8765 /* Handle a "returns_twice" attribute; arguments as in
8766 struct attribute_spec.handler. */
8769 handle_returns_twice_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8770 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8772 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8773 DECL_IS_RETURNS_TWICE (*node
) = 1;
8776 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8777 *no_add_attrs
= true;
8783 /* Handle a "no_limit_stack" attribute; arguments as in
8784 struct attribute_spec.handler. */
8787 handle_no_limit_stack_attribute (tree
*node
, tree name
,
8788 tree
ARG_UNUSED (args
),
8789 int ARG_UNUSED (flags
),
8794 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8796 error_at (DECL_SOURCE_LOCATION (decl
),
8797 "%qE attribute applies only to functions", name
);
8798 *no_add_attrs
= true;
8800 else if (DECL_INITIAL (decl
))
8802 error_at (DECL_SOURCE_LOCATION (decl
),
8803 "can%'t set %qE attribute after definition", name
);
8804 *no_add_attrs
= true;
8807 DECL_NO_LIMIT_STACK (decl
) = 1;
8812 /* Handle a "pure" attribute; arguments as in
8813 struct attribute_spec.handler. */
8816 handle_pure_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8817 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8819 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8820 DECL_PURE_P (*node
) = 1;
8821 /* ??? TODO: Support types. */
8824 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8825 *no_add_attrs
= true;
8831 /* Digest an attribute list destined for a transactional memory statement.
8832 ALLOWED is the set of attributes that are allowed for this statement;
8833 return the attribute we parsed. Multiple attributes are never allowed. */
8836 parse_tm_stmt_attr (tree attrs
, int allowed
)
8841 for ( ; attrs
; attrs
= TREE_CHAIN (attrs
))
8843 tree a
= TREE_PURPOSE (attrs
);
8846 if (is_attribute_p ("outer", a
))
8847 m
= TM_STMT_ATTR_OUTER
;
8849 if ((m
& allowed
) == 0)
8851 warning (OPT_Wattributes
, "%qE attribute directive ignored", a
);
8860 else if (m_seen
== m
)
8861 warning (OPT_Wattributes
, "%qE attribute duplicated", a
);
8863 warning (OPT_Wattributes
, "%qE attribute follows %qE", a
, a_seen
);
8869 /* Transform a TM attribute name into a maskable integer and back.
8870 Note that NULL (i.e. no attribute) is mapped to UNKNOWN, corresponding
8871 to how the lack of an attribute is treated. */
8874 tm_attr_to_mask (tree attr
)
8878 if (is_attribute_p ("transaction_safe", attr
))
8879 return TM_ATTR_SAFE
;
8880 if (is_attribute_p ("transaction_callable", attr
))
8881 return TM_ATTR_CALLABLE
;
8882 if (is_attribute_p ("transaction_pure", attr
))
8883 return TM_ATTR_PURE
;
8884 if (is_attribute_p ("transaction_unsafe", attr
))
8885 return TM_ATTR_IRREVOCABLE
;
8886 if (is_attribute_p ("transaction_may_cancel_outer", attr
))
8887 return TM_ATTR_MAY_CANCEL_OUTER
;
8892 tm_mask_to_attr (int mask
)
8898 str
= "transaction_safe";
8900 case TM_ATTR_CALLABLE
:
8901 str
= "transaction_callable";
8904 str
= "transaction_pure";
8906 case TM_ATTR_IRREVOCABLE
:
8907 str
= "transaction_unsafe";
8909 case TM_ATTR_MAY_CANCEL_OUTER
:
8910 str
= "transaction_may_cancel_outer";
8915 return get_identifier (str
);
8918 /* Return the first TM attribute seen in LIST. */
8921 find_tm_attribute (tree list
)
8923 for (; list
; list
= TREE_CHAIN (list
))
8925 tree name
= TREE_PURPOSE (list
);
8926 if (tm_attr_to_mask (name
) != 0)
8932 /* Handle the TM attributes; arguments as in struct attribute_spec.handler.
8933 Here we accept only function types, and verify that none of the other
8934 function TM attributes are also applied. */
8935 /* ??? We need to accept class types for C++, but not C. This greatly
8936 complicates this function, since we can no longer rely on the extra
8937 processing given by function_type_required. */
8940 handle_tm_attribute (tree
*node
, tree name
, tree args
,
8941 int flags
, bool *no_add_attrs
)
8943 /* Only one path adds the attribute; others don't. */
8944 *no_add_attrs
= true;
8946 switch (TREE_CODE (*node
))
8950 /* Only tm_callable and tm_safe apply to classes. */
8951 if (tm_attr_to_mask (name
) & ~(TM_ATTR_SAFE
| TM_ATTR_CALLABLE
))
8958 tree old_name
= find_tm_attribute (TYPE_ATTRIBUTES (*node
));
8959 if (old_name
== name
)
8961 else if (old_name
!= NULL_TREE
)
8962 error ("type was previously declared %qE", old_name
);
8964 *no_add_attrs
= false;
8970 enum tree_code subcode
= TREE_CODE (TREE_TYPE (*node
));
8971 if (subcode
== FUNCTION_TYPE
|| subcode
== METHOD_TYPE
)
8973 tree fn_tmp
= TREE_TYPE (*node
);
8974 decl_attributes (&fn_tmp
, tree_cons (name
, args
, NULL
), 0);
8975 *node
= build_pointer_type (fn_tmp
);
8982 /* If a function is next, pass it on to be tried next. */
8983 if (flags
& (int) ATTR_FLAG_FUNCTION_NEXT
)
8984 return tree_cons (name
, args
, NULL
);
8987 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8994 /* Handle the TM_WRAP attribute; arguments as in
8995 struct attribute_spec.handler. */
8998 handle_tm_wrap_attribute (tree
*node
, tree name
, tree args
,
8999 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9003 /* We don't need the attribute even on success, since we
9004 record the entry in an external table. */
9005 *no_add_attrs
= true;
9007 if (TREE_CODE (decl
) != FUNCTION_DECL
)
9008 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9011 tree wrap_decl
= TREE_VALUE (args
);
9012 if (error_operand_p (wrap_decl
))
9014 else if (TREE_CODE (wrap_decl
) != IDENTIFIER_NODE
9015 && !VAR_OR_FUNCTION_DECL_P (wrap_decl
))
9016 error ("%qE argument not an identifier", name
);
9019 if (TREE_CODE (wrap_decl
) == IDENTIFIER_NODE
)
9020 wrap_decl
= lookup_name (wrap_decl
);
9021 if (wrap_decl
&& TREE_CODE (wrap_decl
) == FUNCTION_DECL
)
9023 if (lang_hooks
.types_compatible_p (TREE_TYPE (decl
),
9024 TREE_TYPE (wrap_decl
)))
9025 record_tm_replacement (wrap_decl
, decl
);
9027 error ("%qD is not compatible with %qD", wrap_decl
, decl
);
9030 error ("%qE argument is not a function", name
);
9037 /* Ignore the given attribute. Used when this attribute may be usefully
9038 overridden by the target, but is not used generically. */
9041 ignore_attribute (tree
* ARG_UNUSED (node
), tree
ARG_UNUSED (name
),
9042 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
9045 *no_add_attrs
= true;
9049 /* Handle a "no vops" attribute; arguments as in
9050 struct attribute_spec.handler. */
9053 handle_novops_attribute (tree
*node
, tree
ARG_UNUSED (name
),
9054 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
9055 bool *ARG_UNUSED (no_add_attrs
))
9057 gcc_assert (TREE_CODE (*node
) == FUNCTION_DECL
);
9058 DECL_IS_NOVOPS (*node
) = 1;
9062 /* Handle a "deprecated" attribute; arguments as in
9063 struct attribute_spec.handler. */
9066 handle_deprecated_attribute (tree
*node
, tree name
,
9067 tree args
, int flags
,
9070 tree type
= NULL_TREE
;
9072 tree what
= NULL_TREE
;
9075 *no_add_attrs
= true;
9076 else if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
9078 error ("deprecated message is not a string");
9079 *no_add_attrs
= true;
9085 type
= TREE_TYPE (decl
);
9087 if (TREE_CODE (decl
) == TYPE_DECL
9088 || TREE_CODE (decl
) == PARM_DECL
9089 || VAR_OR_FUNCTION_DECL_P (decl
)
9090 || TREE_CODE (decl
) == FIELD_DECL
9091 || TREE_CODE (decl
) == CONST_DECL
9092 || objc_method_decl (TREE_CODE (decl
)))
9093 TREE_DEPRECATED (decl
) = 1;
9097 else if (TYPE_P (*node
))
9099 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
9100 *node
= build_variant_type_copy (*node
);
9101 TREE_DEPRECATED (*node
) = 1;
9109 *no_add_attrs
= true;
9110 if (type
&& TYPE_NAME (type
))
9112 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
9113 what
= TYPE_NAME (*node
);
9114 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
9115 && DECL_NAME (TYPE_NAME (type
)))
9116 what
= DECL_NAME (TYPE_NAME (type
));
9119 warning (OPT_Wattributes
, "%qE attribute ignored for %qE", name
, what
);
9121 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9127 /* Handle a "vector_size" attribute; arguments as in
9128 struct attribute_spec.handler. */
9131 handle_vector_size_attribute (tree
*node
, tree name
, tree args
,
9132 int ARG_UNUSED (flags
),
9135 unsigned HOST_WIDE_INT vecsize
, nunits
;
9136 machine_mode orig_mode
;
9137 tree type
= *node
, new_type
, size
;
9139 *no_add_attrs
= true;
9141 size
= TREE_VALUE (args
);
9142 if (size
&& TREE_CODE (size
) != IDENTIFIER_NODE
9143 && TREE_CODE (size
) != FUNCTION_DECL
)
9144 size
= default_conversion (size
);
9146 if (!tree_fits_uhwi_p (size
))
9148 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9152 /* Get the vector size (in bytes). */
9153 vecsize
= tree_to_uhwi (size
);
9155 /* We need to provide for vector pointers, vector arrays, and
9156 functions returning vectors. For example:
9158 __attribute__((vector_size(16))) short *foo;
9160 In this case, the mode is SI, but the type being modified is
9161 HI, so we need to look further. */
9163 while (POINTER_TYPE_P (type
)
9164 || TREE_CODE (type
) == FUNCTION_TYPE
9165 || TREE_CODE (type
) == METHOD_TYPE
9166 || TREE_CODE (type
) == ARRAY_TYPE
9167 || TREE_CODE (type
) == OFFSET_TYPE
)
9168 type
= TREE_TYPE (type
);
9170 /* Get the mode of the type being modified. */
9171 orig_mode
= TYPE_MODE (type
);
9173 if ((!INTEGRAL_TYPE_P (type
)
9174 && !SCALAR_FLOAT_TYPE_P (type
)
9175 && !FIXED_POINT_TYPE_P (type
))
9176 || (!SCALAR_FLOAT_MODE_P (orig_mode
)
9177 && GET_MODE_CLASS (orig_mode
) != MODE_INT
9178 && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode
))
9179 || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
9180 || TREE_CODE (type
) == BOOLEAN_TYPE
)
9182 error ("invalid vector type for attribute %qE", name
);
9186 if (vecsize
% tree_to_uhwi (TYPE_SIZE_UNIT (type
)))
9188 error ("vector size not an integral multiple of component size");
9194 error ("zero vector size");
9198 /* Calculate how many units fit in the vector. */
9199 nunits
= vecsize
/ tree_to_uhwi (TYPE_SIZE_UNIT (type
));
9200 if (nunits
& (nunits
- 1))
9202 error ("number of components of the vector not a power of two");
9206 new_type
= build_vector_type (type
, nunits
);
9208 /* Build back pointers if needed. */
9209 *node
= lang_hooks
.types
.reconstruct_complex_type (*node
, new_type
);
9214 /* Handle the "nonnull" attribute. */
9216 handle_nonnull_attribute (tree
*node
, tree
ARG_UNUSED (name
),
9217 tree args
, int ARG_UNUSED (flags
),
9221 unsigned HOST_WIDE_INT attr_arg_num
;
9223 /* If no arguments are specified, all pointer arguments should be
9224 non-null. Verify a full prototype is given so that the arguments
9225 will have the correct types when we actually check them later. */
9228 if (!prototype_p (type
))
9230 error ("nonnull attribute without arguments on a non-prototype");
9231 *no_add_attrs
= true;
9236 /* Argument list specified. Verify that each argument number references
9237 a pointer argument. */
9238 for (attr_arg_num
= 1; args
; attr_arg_num
++, args
= TREE_CHAIN (args
))
9240 unsigned HOST_WIDE_INT arg_num
= 0, ck_num
;
9242 tree arg
= TREE_VALUE (args
);
9243 if (arg
&& TREE_CODE (arg
) != IDENTIFIER_NODE
9244 && TREE_CODE (arg
) != FUNCTION_DECL
)
9245 arg
= default_conversion (arg
);
9247 if (!get_nonnull_operand (arg
, &arg_num
))
9249 error ("nonnull argument has invalid operand number (argument %lu)",
9250 (unsigned long) attr_arg_num
);
9251 *no_add_attrs
= true;
9255 if (prototype_p (type
))
9257 function_args_iterator iter
;
9260 function_args_iter_init (&iter
, type
);
9261 for (ck_num
= 1; ; ck_num
++, function_args_iter_next (&iter
))
9263 argument
= function_args_iter_cond (&iter
);
9264 if (argument
== NULL_TREE
|| ck_num
== arg_num
)
9269 || TREE_CODE (argument
) == VOID_TYPE
)
9271 error ("nonnull argument with out-of-range operand number (argument %lu, operand %lu)",
9272 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
9273 *no_add_attrs
= true;
9277 if (TREE_CODE (argument
) != POINTER_TYPE
)
9279 error ("nonnull argument references non-pointer operand (argument %lu, operand %lu)",
9280 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
9281 *no_add_attrs
= true;
9290 /* Check the argument list of a function call for null in argument slots
9291 that are marked as requiring a non-null pointer argument. The NARGS
9292 arguments are passed in the array ARGARRAY.
9296 check_function_nonnull (tree attrs
, int nargs
, tree
*argarray
)
9301 attrs
= lookup_attribute ("nonnull", attrs
);
9302 if (attrs
== NULL_TREE
)
9306 /* See if any of the nonnull attributes has no arguments. If so,
9307 then every pointer argument is checked (in which case the check
9308 for pointer type is done in check_nonnull_arg). */
9309 if (TREE_VALUE (a
) != NULL_TREE
)
9311 a
= lookup_attribute ("nonnull", TREE_CHAIN (a
));
9312 while (a
!= NULL_TREE
&& TREE_VALUE (a
) != NULL_TREE
);
9315 for (i
= 0; i
< nargs
; i
++)
9316 check_function_arguments_recurse (check_nonnull_arg
, NULL
, argarray
[i
],
9320 /* Walk the argument list. If we encounter an argument number we
9321 should check for non-null, do it. */
9322 for (i
= 0; i
< nargs
; i
++)
9324 for (a
= attrs
; ; a
= TREE_CHAIN (a
))
9326 a
= lookup_attribute ("nonnull", a
);
9327 if (a
== NULL_TREE
|| nonnull_check_p (TREE_VALUE (a
), i
+ 1))
9332 check_function_arguments_recurse (check_nonnull_arg
, NULL
,
9333 argarray
[i
], i
+ 1);
9338 /* Check that the Nth argument of a function call (counting backwards
9339 from the end) is a (pointer)0. The NARGS arguments are passed in the
9343 check_function_sentinel (const_tree fntype
, int nargs
, tree
*argarray
)
9345 tree attr
= lookup_attribute ("sentinel", TYPE_ATTRIBUTES (fntype
));
9352 function_args_iterator iter
;
9355 /* Skip over the named arguments. */
9356 FOREACH_FUNCTION_ARGS (fntype
, t
, iter
)
9363 if (TREE_VALUE (attr
))
9365 tree p
= TREE_VALUE (TREE_VALUE (attr
));
9366 pos
= TREE_INT_CST_LOW (p
);
9369 /* The sentinel must be one of the varargs, i.e.
9370 in position >= the number of fixed arguments. */
9371 if ((nargs
- 1 - pos
) < len
)
9373 warning (OPT_Wformat_
,
9374 "not enough variable arguments to fit a sentinel");
9378 /* Validate the sentinel. */
9379 sentinel
= argarray
[nargs
- 1 - pos
];
9380 if ((!POINTER_TYPE_P (TREE_TYPE (sentinel
))
9381 || !integer_zerop (sentinel
))
9382 /* Although __null (in C++) is only an integer we allow it
9383 nevertheless, as we are guaranteed that it's exactly
9384 as wide as a pointer, and we don't want to force
9385 users to cast the NULL they have written there.
9386 We warn with -Wstrict-null-sentinel, though. */
9387 && (warn_strict_null_sentinel
|| null_node
!= sentinel
))
9388 warning (OPT_Wformat_
, "missing sentinel in function call");
9392 /* Helper for check_function_nonnull; given a list of operands which
9393 must be non-null in ARGS, determine if operand PARAM_NUM should be
9397 nonnull_check_p (tree args
, unsigned HOST_WIDE_INT param_num
)
9399 unsigned HOST_WIDE_INT arg_num
= 0;
9401 for (; args
; args
= TREE_CHAIN (args
))
9403 bool found
= get_nonnull_operand (TREE_VALUE (args
), &arg_num
);
9407 if (arg_num
== param_num
)
9413 /* Check that the function argument PARAM (which is operand number
9414 PARAM_NUM) is non-null. This is called by check_function_nonnull
9415 via check_function_arguments_recurse. */
9418 check_nonnull_arg (void * ARG_UNUSED (ctx
), tree param
,
9419 unsigned HOST_WIDE_INT param_num
)
9421 /* Just skip checking the argument if it's not a pointer. This can
9422 happen if the "nonnull" attribute was given without an operand
9423 list (which means to check every pointer argument). */
9425 if (TREE_CODE (TREE_TYPE (param
)) != POINTER_TYPE
)
9428 if (integer_zerop (param
))
9429 warning (OPT_Wnonnull
, "null argument where non-null required "
9430 "(argument %lu)", (unsigned long) param_num
);
9433 /* Helper for nonnull attribute handling; fetch the operand number
9434 from the attribute argument list. */
9437 get_nonnull_operand (tree arg_num_expr
, unsigned HOST_WIDE_INT
*valp
)
9439 /* Verify the arg number is a small constant. */
9440 if (tree_fits_uhwi_p (arg_num_expr
))
9442 *valp
= TREE_INT_CST_LOW (arg_num_expr
);
9449 /* Handle a "nothrow" attribute; arguments as in
9450 struct attribute_spec.handler. */
9453 handle_nothrow_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
9454 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9456 if (TREE_CODE (*node
) == FUNCTION_DECL
)
9457 TREE_NOTHROW (*node
) = 1;
9458 /* ??? TODO: Support types. */
9461 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9462 *no_add_attrs
= true;
9468 /* Handle a "cleanup" attribute; arguments as in
9469 struct attribute_spec.handler. */
9472 handle_cleanup_attribute (tree
*node
, tree name
, tree args
,
9473 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9476 tree cleanup_id
, cleanup_decl
;
9478 /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
9479 for global destructors in C++. This requires infrastructure that
9480 we don't have generically at the moment. It's also not a feature
9481 we'd be missing too much, since we do have attribute constructor. */
9482 if (TREE_CODE (decl
) != VAR_DECL
|| TREE_STATIC (decl
))
9484 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9485 *no_add_attrs
= true;
9489 /* Verify that the argument is a function in scope. */
9490 /* ??? We could support pointers to functions here as well, if
9491 that was considered desirable. */
9492 cleanup_id
= TREE_VALUE (args
);
9493 if (TREE_CODE (cleanup_id
) != IDENTIFIER_NODE
)
9495 error ("cleanup argument not an identifier");
9496 *no_add_attrs
= true;
9499 cleanup_decl
= lookup_name (cleanup_id
);
9500 if (!cleanup_decl
|| TREE_CODE (cleanup_decl
) != FUNCTION_DECL
)
9502 error ("cleanup argument not a function");
9503 *no_add_attrs
= true;
9507 /* That the function has proper type is checked with the
9508 eventual call to build_function_call. */
9513 /* Handle a "warn_unused_result" attribute. No special handling. */
9516 handle_warn_unused_result_attribute (tree
*node
, tree name
,
9517 tree
ARG_UNUSED (args
),
9518 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9520 /* Ignore the attribute for functions not returning any value. */
9521 if (VOID_TYPE_P (TREE_TYPE (*node
)))
9523 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9524 *no_add_attrs
= true;
9530 /* Handle a "sentinel" attribute. */
9533 handle_sentinel_attribute (tree
*node
, tree name
, tree args
,
9534 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9536 if (!prototype_p (*node
))
9538 warning (OPT_Wattributes
,
9539 "%qE attribute requires prototypes with named arguments", name
);
9540 *no_add_attrs
= true;
9544 if (!stdarg_p (*node
))
9546 warning (OPT_Wattributes
,
9547 "%qE attribute only applies to variadic functions", name
);
9548 *no_add_attrs
= true;
9554 tree position
= TREE_VALUE (args
);
9555 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
9556 && TREE_CODE (position
) != FUNCTION_DECL
)
9557 position
= default_conversion (position
);
9559 if (TREE_CODE (position
) != INTEGER_CST
9560 || !INTEGRAL_TYPE_P (TREE_TYPE (position
)))
9562 warning (OPT_Wattributes
,
9563 "requested position is not an integer constant");
9564 *no_add_attrs
= true;
9568 if (tree_int_cst_lt (position
, integer_zero_node
))
9570 warning (OPT_Wattributes
,
9571 "requested position is less than zero");
9572 *no_add_attrs
= true;
9580 /* Handle a "type_generic" attribute. */
9583 handle_type_generic_attribute (tree
*node
, tree
ARG_UNUSED (name
),
9584 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
9585 bool * ARG_UNUSED (no_add_attrs
))
9587 /* Ensure we have a function type. */
9588 gcc_assert (TREE_CODE (*node
) == FUNCTION_TYPE
);
9590 /* Ensure we have a variadic function. */
9591 gcc_assert (!prototype_p (*node
) || stdarg_p (*node
));
9596 /* Handle a "target" attribute. */
9599 handle_target_attribute (tree
*node
, tree name
, tree args
, int flags
,
9602 /* Ensure we have a function type. */
9603 if (TREE_CODE (*node
) != FUNCTION_DECL
)
9605 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9606 *no_add_attrs
= true;
9608 else if (! targetm
.target_option
.valid_attribute_p (*node
, name
, args
,
9610 *no_add_attrs
= true;
9615 /* Arguments being collected for optimization. */
9616 typedef const char *const_char_p
; /* For DEF_VEC_P. */
9617 static GTY(()) vec
<const_char_p
, va_gc
> *optimize_args
;
9620 /* Inner function to convert a TREE_LIST to argv string to parse the optimize
9621 options in ARGS. ATTR_P is true if this is for attribute(optimize), and
9622 false for #pragma GCC optimize. */
9625 parse_optimize_options (tree args
, bool attr_p
)
9630 int saved_flag_strict_aliasing
;
9631 const char **opt_argv
;
9632 struct cl_decoded_option
*decoded_options
;
9633 unsigned int decoded_options_count
;
9636 /* Build up argv vector. Just in case the string is stored away, use garbage
9637 collected strings. */
9638 vec_safe_truncate (optimize_args
, 0);
9639 vec_safe_push (optimize_args
, (const char *) NULL
);
9641 for (ap
= args
; ap
!= NULL_TREE
; ap
= TREE_CHAIN (ap
))
9643 tree value
= TREE_VALUE (ap
);
9645 if (TREE_CODE (value
) == INTEGER_CST
)
9648 sprintf (buffer
, "-O%ld", (long) TREE_INT_CST_LOW (value
));
9649 vec_safe_push (optimize_args
, ggc_strdup (buffer
));
9652 else if (TREE_CODE (value
) == STRING_CST
)
9654 /* Split string into multiple substrings. */
9655 size_t len
= TREE_STRING_LENGTH (value
);
9656 char *p
= ASTRDUP (TREE_STRING_POINTER (value
));
9657 char *end
= p
+ len
;
9661 while (next_p
!= NULL
)
9667 comma
= strchr (p
, ',');
9680 r
= q
= (char *) ggc_alloc_atomic (len2
+ 3);
9682 /* If the user supplied -Oxxx or -fxxx, only allow -Oxxx or -fxxx
9684 if (*p
== '-' && p
[1] != 'O' && p
[1] != 'f')
9688 warning (OPT_Wattributes
,
9689 "bad option %s to optimize attribute", p
);
9691 warning (OPT_Wpragmas
,
9692 "bad option %s to pragma attribute", p
);
9700 /* Assume that Ox is -Ox, a numeric value is -Ox, a s by
9701 itself is -Os, and any other switch begins with a -f. */
9702 if ((*p
>= '0' && *p
<= '9')
9703 || (p
[0] == 's' && p
[1] == '\0'))
9709 memcpy (r
, p
, len2
);
9711 vec_safe_push (optimize_args
, (const char *) q
);
9717 opt_argc
= optimize_args
->length ();
9718 opt_argv
= (const char **) alloca (sizeof (char *) * (opt_argc
+ 1));
9720 for (i
= 1; i
< opt_argc
; i
++)
9721 opt_argv
[i
] = (*optimize_args
)[i
];
9723 saved_flag_strict_aliasing
= flag_strict_aliasing
;
9725 /* Now parse the options. */
9726 decode_cmdline_options_to_array_default_mask (opt_argc
, opt_argv
,
9728 &decoded_options_count
);
9729 decode_options (&global_options
, &global_options_set
,
9730 decoded_options
, decoded_options_count
,
9731 input_location
, global_dc
);
9733 targetm
.override_options_after_change();
9735 /* Don't allow changing -fstrict-aliasing. */
9736 flag_strict_aliasing
= saved_flag_strict_aliasing
;
9738 optimize_args
->truncate (0);
9742 /* For handling "optimize" attribute. arguments as in
9743 struct attribute_spec.handler. */
9746 handle_optimize_attribute (tree
*node
, tree name
, tree args
,
9747 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9749 /* Ensure we have a function type. */
9750 if (TREE_CODE (*node
) != FUNCTION_DECL
)
9752 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9753 *no_add_attrs
= true;
9757 struct cl_optimization cur_opts
;
9758 tree old_opts
= DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
);
9760 /* Save current options. */
9761 cl_optimization_save (&cur_opts
, &global_options
);
9763 /* If we previously had some optimization options, use them as the
9766 cl_optimization_restore (&global_options
,
9767 TREE_OPTIMIZATION (old_opts
));
9769 /* Parse options, and update the vector. */
9770 parse_optimize_options (args
, true);
9771 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
)
9772 = build_optimization_node (&global_options
);
9774 /* Restore current options. */
9775 cl_optimization_restore (&global_options
, &cur_opts
);
9781 /* Handle a "no_split_stack" attribute. */
9784 handle_no_split_stack_attribute (tree
*node
, tree name
,
9785 tree
ARG_UNUSED (args
),
9786 int ARG_UNUSED (flags
),
9791 if (TREE_CODE (decl
) != FUNCTION_DECL
)
9793 error_at (DECL_SOURCE_LOCATION (decl
),
9794 "%qE attribute applies only to functions", name
);
9795 *no_add_attrs
= true;
9797 else if (DECL_INITIAL (decl
))
9799 error_at (DECL_SOURCE_LOCATION (decl
),
9800 "can%'t set %qE attribute after definition", name
);
9801 *no_add_attrs
= true;
9807 /* Handle a "returns_nonnull" attribute; arguments as in
9808 struct attribute_spec.handler. */
9811 handle_returns_nonnull_attribute (tree
*node
, tree
, tree
, int,
9814 // Even without a prototype we still have a return type we can check.
9815 if (TREE_CODE (TREE_TYPE (*node
)) != POINTER_TYPE
)
9817 error ("returns_nonnull attribute on a function not returning a pointer");
9818 *no_add_attrs
= true;
9823 /* Handle a "designated_init" attribute; arguments as in
9824 struct attribute_spec.handler. */
9827 handle_designated_init_attribute (tree
*node
, tree name
, tree
, int,
9830 if (TREE_CODE (*node
) != RECORD_TYPE
)
9832 error ("%qE attribute is only valid on %<struct%> type", name
);
9833 *no_add_attrs
= true;
9839 /* Check for valid arguments being passed to a function with FNTYPE.
9840 There are NARGS arguments in the array ARGARRAY. */
9842 check_function_arguments (const_tree fntype
, int nargs
, tree
*argarray
)
9844 /* Check for null being passed in a pointer argument that must be
9845 non-null. We also need to do this if format checking is enabled. */
9848 check_function_nonnull (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
9850 /* Check for errors in format strings. */
9852 if (warn_format
|| warn_suggest_attribute_format
)
9853 check_function_format (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
9856 check_function_sentinel (fntype
, nargs
, argarray
);
9859 /* Generic argument checking recursion routine. PARAM is the argument to
9860 be checked. PARAM_NUM is the number of the argument. CALLBACK is invoked
9861 once the argument is resolved. CTX is context for the callback. */
9863 check_function_arguments_recurse (void (*callback
)
9864 (void *, tree
, unsigned HOST_WIDE_INT
),
9865 void *ctx
, tree param
,
9866 unsigned HOST_WIDE_INT param_num
)
9868 if (CONVERT_EXPR_P (param
)
9869 && (TYPE_PRECISION (TREE_TYPE (param
))
9870 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (param
, 0)))))
9872 /* Strip coercion. */
9873 check_function_arguments_recurse (callback
, ctx
,
9874 TREE_OPERAND (param
, 0), param_num
);
9878 if (TREE_CODE (param
) == CALL_EXPR
)
9880 tree type
= TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (param
)));
9882 bool found_format_arg
= false;
9884 /* See if this is a call to a known internationalization function
9885 that modifies a format arg. Such a function may have multiple
9886 format_arg attributes (for example, ngettext). */
9888 for (attrs
= TYPE_ATTRIBUTES (type
);
9890 attrs
= TREE_CHAIN (attrs
))
9891 if (is_attribute_p ("format_arg", TREE_PURPOSE (attrs
)))
9894 tree format_num_expr
;
9897 call_expr_arg_iterator iter
;
9899 /* Extract the argument number, which was previously checked
9901 format_num_expr
= TREE_VALUE (TREE_VALUE (attrs
));
9903 format_num
= tree_to_uhwi (format_num_expr
);
9905 for (inner_arg
= first_call_expr_arg (param
, &iter
), i
= 1;
9907 inner_arg
= next_call_expr_arg (&iter
), i
++)
9908 if (i
== format_num
)
9910 check_function_arguments_recurse (callback
, ctx
,
9911 inner_arg
, param_num
);
9912 found_format_arg
= true;
9917 /* If we found a format_arg attribute and did a recursive check,
9918 we are done with checking this argument. Otherwise, we continue
9919 and this will be considered a non-literal. */
9920 if (found_format_arg
)
9924 if (TREE_CODE (param
) == COND_EXPR
)
9926 /* Check both halves of the conditional expression. */
9927 check_function_arguments_recurse (callback
, ctx
,
9928 TREE_OPERAND (param
, 1), param_num
);
9929 check_function_arguments_recurse (callback
, ctx
,
9930 TREE_OPERAND (param
, 2), param_num
);
9934 (*callback
) (ctx
, param
, param_num
);
9937 /* Checks for a builtin function FNDECL that the number of arguments
9938 NARGS against the required number REQUIRED and issues an error if
9939 there is a mismatch. Returns true if the number of arguments is
9940 correct, otherwise false. */
9943 builtin_function_validate_nargs (tree fndecl
, int nargs
, int required
)
9945 if (nargs
< required
)
9947 error_at (input_location
,
9948 "not enough arguments to function %qE", fndecl
);
9951 else if (nargs
> required
)
9953 error_at (input_location
,
9954 "too many arguments to function %qE", fndecl
);
9960 /* Verifies the NARGS arguments ARGS to the builtin function FNDECL.
9961 Returns false if there was an error, otherwise true. */
9964 check_builtin_function_arguments (tree fndecl
, int nargs
, tree
*args
)
9966 if (!DECL_BUILT_IN (fndecl
)
9967 || DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_NORMAL
)
9970 switch (DECL_FUNCTION_CODE (fndecl
))
9972 case BUILT_IN_CONSTANT_P
:
9973 return builtin_function_validate_nargs (fndecl
, nargs
, 1);
9975 case BUILT_IN_ISFINITE
:
9976 case BUILT_IN_ISINF
:
9977 case BUILT_IN_ISINF_SIGN
:
9978 case BUILT_IN_ISNAN
:
9979 case BUILT_IN_ISNORMAL
:
9980 if (builtin_function_validate_nargs (fndecl
, nargs
, 1))
9982 if (TREE_CODE (TREE_TYPE (args
[0])) != REAL_TYPE
)
9984 error ("non-floating-point argument in call to "
9985 "function %qE", fndecl
);
9992 case BUILT_IN_ISGREATER
:
9993 case BUILT_IN_ISGREATEREQUAL
:
9994 case BUILT_IN_ISLESS
:
9995 case BUILT_IN_ISLESSEQUAL
:
9996 case BUILT_IN_ISLESSGREATER
:
9997 case BUILT_IN_ISUNORDERED
:
9998 if (builtin_function_validate_nargs (fndecl
, nargs
, 2))
10000 enum tree_code code0
, code1
;
10001 code0
= TREE_CODE (TREE_TYPE (args
[0]));
10002 code1
= TREE_CODE (TREE_TYPE (args
[1]));
10003 if (!((code0
== REAL_TYPE
&& code1
== REAL_TYPE
)
10004 || (code0
== REAL_TYPE
&& code1
== INTEGER_TYPE
)
10005 || (code0
== INTEGER_TYPE
&& code1
== REAL_TYPE
)))
10007 error ("non-floating-point arguments in call to "
10008 "function %qE", fndecl
);
10015 case BUILT_IN_FPCLASSIFY
:
10016 if (builtin_function_validate_nargs (fndecl
, nargs
, 6))
10020 for (i
=0; i
<5; i
++)
10021 if (TREE_CODE (args
[i
]) != INTEGER_CST
)
10023 error ("non-const integer argument %u in call to function %qE",
10028 if (TREE_CODE (TREE_TYPE (args
[5])) != REAL_TYPE
)
10030 error ("non-floating-point argument in call to function %qE",
10038 case BUILT_IN_ASSUME_ALIGNED
:
10039 if (builtin_function_validate_nargs (fndecl
, nargs
, 2 + (nargs
> 2)))
10041 if (nargs
>= 3 && TREE_CODE (TREE_TYPE (args
[2])) != INTEGER_TYPE
)
10043 error ("non-integer argument 3 in call to function %qE", fndecl
);
10050 case BUILT_IN_ADD_OVERFLOW
:
10051 case BUILT_IN_SUB_OVERFLOW
:
10052 case BUILT_IN_MUL_OVERFLOW
:
10053 if (builtin_function_validate_nargs (fndecl
, nargs
, 3))
10056 for (i
= 0; i
< 2; i
++)
10057 if (!INTEGRAL_TYPE_P (TREE_TYPE (args
[i
])))
10059 error ("argument %u in call to function %qE does not have "
10060 "integral type", i
+ 1, fndecl
);
10063 if (TREE_CODE (TREE_TYPE (args
[2])) != POINTER_TYPE
10064 || TREE_CODE (TREE_TYPE (TREE_TYPE (args
[2]))) != INTEGER_TYPE
)
10066 error ("argument 3 in call to function %qE does not have "
10067 "pointer to integer type", fndecl
);
10079 /* Function to help qsort sort FIELD_DECLs by name order. */
10082 field_decl_cmp (const void *x_p
, const void *y_p
)
10084 const tree
*const x
= (const tree
*const) x_p
;
10085 const tree
*const y
= (const tree
*const) y_p
;
10087 if (DECL_NAME (*x
) == DECL_NAME (*y
))
10088 /* A nontype is "greater" than a type. */
10089 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
10090 if (DECL_NAME (*x
) == NULL_TREE
)
10092 if (DECL_NAME (*y
) == NULL_TREE
)
10094 if (DECL_NAME (*x
) < DECL_NAME (*y
))
10100 gt_pointer_operator new_value
;
10104 /* This routine compares two fields like field_decl_cmp but using the
10105 pointer operator in resort_data. */
10108 resort_field_decl_cmp (const void *x_p
, const void *y_p
)
10110 const tree
*const x
= (const tree
*const) x_p
;
10111 const tree
*const y
= (const tree
*const) y_p
;
10113 if (DECL_NAME (*x
) == DECL_NAME (*y
))
10114 /* A nontype is "greater" than a type. */
10115 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
10116 if (DECL_NAME (*x
) == NULL_TREE
)
10118 if (DECL_NAME (*y
) == NULL_TREE
)
10121 tree d1
= DECL_NAME (*x
);
10122 tree d2
= DECL_NAME (*y
);
10123 resort_data
.new_value (&d1
, resort_data
.cookie
);
10124 resort_data
.new_value (&d2
, resort_data
.cookie
);
10131 /* Resort DECL_SORTED_FIELDS because pointers have been reordered. */
10134 resort_sorted_fields (void *obj
,
10135 void * ARG_UNUSED (orig_obj
),
10136 gt_pointer_operator new_value
,
10139 struct sorted_fields_type
*sf
= (struct sorted_fields_type
*) obj
;
10140 resort_data
.new_value
= new_value
;
10141 resort_data
.cookie
= cookie
;
10142 qsort (&sf
->elts
[0], sf
->len
, sizeof (tree
),
10143 resort_field_decl_cmp
);
10146 /* Subroutine of c_parse_error.
10147 Return the result of concatenating LHS and RHS. RHS is really
10148 a string literal, its first character is indicated by RHS_START and
10149 RHS_SIZE is its length (including the terminating NUL character).
10151 The caller is responsible for deleting the returned pointer. */
10154 catenate_strings (const char *lhs
, const char *rhs_start
, int rhs_size
)
10156 const int lhs_size
= strlen (lhs
);
10157 char *result
= XNEWVEC (char, lhs_size
+ rhs_size
);
10158 strncpy (result
, lhs
, lhs_size
);
10159 strncpy (result
+ lhs_size
, rhs_start
, rhs_size
);
10163 /* Issue the error given by GMSGID, indicating that it occurred before
10164 TOKEN, which had the associated VALUE. */
10167 c_parse_error (const char *gmsgid
, enum cpp_ttype token_type
,
10168 tree value
, unsigned char token_flags
)
10170 #define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2))
10172 char *message
= NULL
;
10174 if (token_type
== CPP_EOF
)
10175 message
= catenate_messages (gmsgid
, " at end of input");
10176 else if (token_type
== CPP_CHAR
10177 || token_type
== CPP_WCHAR
10178 || token_type
== CPP_CHAR16
10179 || token_type
== CPP_CHAR32
)
10181 unsigned int val
= TREE_INT_CST_LOW (value
);
10182 const char *prefix
;
10184 switch (token_type
)
10200 if (val
<= UCHAR_MAX
&& ISGRAPH (val
))
10201 message
= catenate_messages (gmsgid
, " before %s'%c'");
10203 message
= catenate_messages (gmsgid
, " before %s'\\x%x'");
10205 error (message
, prefix
, val
);
10209 else if (token_type
== CPP_CHAR_USERDEF
10210 || token_type
== CPP_WCHAR_USERDEF
10211 || token_type
== CPP_CHAR16_USERDEF
10212 || token_type
== CPP_CHAR32_USERDEF
)
10213 message
= catenate_messages (gmsgid
,
10214 " before user-defined character literal");
10215 else if (token_type
== CPP_STRING_USERDEF
10216 || token_type
== CPP_WSTRING_USERDEF
10217 || token_type
== CPP_STRING16_USERDEF
10218 || token_type
== CPP_STRING32_USERDEF
10219 || token_type
== CPP_UTF8STRING_USERDEF
)
10220 message
= catenate_messages (gmsgid
, " before user-defined string literal");
10221 else if (token_type
== CPP_STRING
10222 || token_type
== CPP_WSTRING
10223 || token_type
== CPP_STRING16
10224 || token_type
== CPP_STRING32
10225 || token_type
== CPP_UTF8STRING
)
10226 message
= catenate_messages (gmsgid
, " before string constant");
10227 else if (token_type
== CPP_NUMBER
)
10228 message
= catenate_messages (gmsgid
, " before numeric constant");
10229 else if (token_type
== CPP_NAME
)
10231 message
= catenate_messages (gmsgid
, " before %qE");
10232 error (message
, value
);
10236 else if (token_type
== CPP_PRAGMA
)
10237 message
= catenate_messages (gmsgid
, " before %<#pragma%>");
10238 else if (token_type
== CPP_PRAGMA_EOL
)
10239 message
= catenate_messages (gmsgid
, " before end of line");
10240 else if (token_type
== CPP_DECLTYPE
)
10241 message
= catenate_messages (gmsgid
, " before %<decltype%>");
10242 else if (token_type
< N_TTYPES
)
10244 message
= catenate_messages (gmsgid
, " before %qs token");
10245 error (message
, cpp_type2name (token_type
, token_flags
));
10257 #undef catenate_messages
10260 /* Return the gcc option code associated with the reason for a cpp
10261 message, or 0 if none. */
10264 c_option_controlling_cpp_error (int reason
)
10266 const struct cpp_reason_option_codes_t
*entry
;
10268 for (entry
= cpp_reason_option_codes
; entry
->reason
!= CPP_W_NONE
; entry
++)
10270 if (entry
->reason
== reason
)
10271 return entry
->option_code
;
10276 /* Callback from cpp_error for PFILE to print diagnostics from the
10277 preprocessor. The diagnostic is of type LEVEL, with REASON set
10278 to the reason code if LEVEL is represents a warning, at location
10279 LOCATION unless this is after lexing and the compiler's location
10280 should be used instead, with column number possibly overridden by
10281 COLUMN_OVERRIDE if not zero; MSG is the translated message and AP
10282 the arguments. Returns true if a diagnostic was emitted, false
10286 c_cpp_error (cpp_reader
*pfile ATTRIBUTE_UNUSED
, int level
, int reason
,
10287 location_t location
, unsigned int column_override
,
10288 const char *msg
, va_list *ap
)
10290 diagnostic_info diagnostic
;
10291 diagnostic_t dlevel
;
10292 bool save_warn_system_headers
= global_dc
->dc_warn_system_headers
;
10297 case CPP_DL_WARNING_SYSHDR
:
10298 if (flag_no_output
)
10300 global_dc
->dc_warn_system_headers
= 1;
10301 /* Fall through. */
10302 case CPP_DL_WARNING
:
10303 if (flag_no_output
)
10305 dlevel
= DK_WARNING
;
10307 case CPP_DL_PEDWARN
:
10308 if (flag_no_output
&& !flag_pedantic_errors
)
10310 dlevel
= DK_PEDWARN
;
10325 gcc_unreachable ();
10328 location
= input_location
;
10329 diagnostic_set_info_translated (&diagnostic
, msg
, ap
,
10331 if (column_override
)
10332 diagnostic_override_column (&diagnostic
, column_override
);
10333 diagnostic_override_option_index (&diagnostic
,
10334 c_option_controlling_cpp_error (reason
));
10335 ret
= report_diagnostic (&diagnostic
);
10336 if (level
== CPP_DL_WARNING_SYSHDR
)
10337 global_dc
->dc_warn_system_headers
= save_warn_system_headers
;
10341 /* Convert a character from the host to the target execution character
10342 set. cpplib handles this, mostly. */
10345 c_common_to_target_charset (HOST_WIDE_INT c
)
10347 /* Character constants in GCC proper are sign-extended under -fsigned-char,
10348 zero-extended under -fno-signed-char. cpplib insists that characters
10349 and character constants are always unsigned. Hence we must convert
10351 cppchar_t uc
= ((cppchar_t
)c
) & ((((cppchar_t
)1) << CHAR_BIT
)-1);
10353 uc
= cpp_host_to_exec_charset (parse_in
, uc
);
10355 if (flag_signed_char
)
10356 return ((HOST_WIDE_INT
)uc
) << (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
)
10357 >> (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
);
10362 /* Fold an offsetof-like expression. EXPR is a nested sequence of component
10363 references with an INDIRECT_REF of a constant at the bottom; much like the
10364 traditional rendering of offsetof as a macro. Return the folded result. */
10367 fold_offsetof_1 (tree expr
)
10371 switch (TREE_CODE (expr
))
10377 error ("cannot apply %<offsetof%> to static data member %qD", expr
);
10378 return error_mark_node
;
10382 error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded");
10383 return error_mark_node
;
10387 if (!TREE_CONSTANT (TREE_OPERAND (expr
, 0)))
10389 error ("cannot apply %<offsetof%> to a non constant address");
10390 return error_mark_node
;
10392 return TREE_OPERAND (expr
, 0);
10394 case COMPONENT_REF
:
10395 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0));
10396 if (base
== error_mark_node
)
10399 t
= TREE_OPERAND (expr
, 1);
10400 if (DECL_C_BIT_FIELD (t
))
10402 error ("attempt to take address of bit-field structure "
10404 return error_mark_node
;
10406 off
= size_binop_loc (input_location
, PLUS_EXPR
, DECL_FIELD_OFFSET (t
),
10407 size_int (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (t
))
10412 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0));
10413 if (base
== error_mark_node
)
10416 t
= TREE_OPERAND (expr
, 1);
10418 /* Check if the offset goes beyond the upper bound of the array. */
10419 if (TREE_CODE (t
) == INTEGER_CST
&& tree_int_cst_sgn (t
) >= 0)
10421 tree upbound
= array_ref_up_bound (expr
);
10422 if (upbound
!= NULL_TREE
10423 && TREE_CODE (upbound
) == INTEGER_CST
10424 && !tree_int_cst_equal (upbound
,
10425 TYPE_MAX_VALUE (TREE_TYPE (upbound
))))
10427 upbound
= size_binop (PLUS_EXPR
, upbound
,
10428 build_int_cst (TREE_TYPE (upbound
), 1));
10429 if (tree_int_cst_lt (upbound
, t
))
10433 for (v
= TREE_OPERAND (expr
, 0);
10434 TREE_CODE (v
) == COMPONENT_REF
;
10435 v
= TREE_OPERAND (v
, 0))
10436 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v
, 0)))
10439 tree fld_chain
= DECL_CHAIN (TREE_OPERAND (v
, 1));
10440 for (; fld_chain
; fld_chain
= DECL_CHAIN (fld_chain
))
10441 if (TREE_CODE (fld_chain
) == FIELD_DECL
)
10447 /* Don't warn if the array might be considered a poor
10448 man's flexible array member with a very permissive
10449 definition thereof. */
10450 if (TREE_CODE (v
) == ARRAY_REF
10451 || TREE_CODE (v
) == COMPONENT_REF
)
10452 warning (OPT_Warray_bounds
,
10453 "index %E denotes an offset "
10454 "greater than size of %qT",
10455 t
, TREE_TYPE (TREE_OPERAND (expr
, 0)));
10460 t
= convert (sizetype
, t
);
10461 off
= size_binop (MULT_EXPR
, TYPE_SIZE_UNIT (TREE_TYPE (expr
)), t
);
10464 case COMPOUND_EXPR
:
10465 /* Handle static members of volatile structs. */
10466 t
= TREE_OPERAND (expr
, 1);
10467 gcc_assert (TREE_CODE (t
) == VAR_DECL
);
10468 return fold_offsetof_1 (t
);
10471 gcc_unreachable ();
10474 return fold_build_pointer_plus (base
, off
);
10477 /* Likewise, but convert it to the return type of offsetof. */
10480 fold_offsetof (tree expr
)
10482 return convert (size_type_node
, fold_offsetof_1 (expr
));
10485 /* Warn for A ?: C expressions (with B omitted) where A is a boolean
10486 expression, because B will always be true. */
10489 warn_for_omitted_condop (location_t location
, tree cond
)
10491 if (truth_value_p (TREE_CODE (cond
)))
10492 warning_at (location
, OPT_Wparentheses
,
10493 "the omitted middle operand in ?: will always be %<true%>, "
10494 "suggest explicit middle operand");
10497 /* Give an error for storing into ARG, which is 'const'. USE indicates
10498 how ARG was being used. */
10501 readonly_error (location_t loc
, tree arg
, enum lvalue_use use
)
10503 gcc_assert (use
== lv_assign
|| use
== lv_increment
|| use
== lv_decrement
10505 /* Using this macro rather than (for example) arrays of messages
10506 ensures that all the format strings are checked at compile
10508 #define READONLY_MSG(A, I, D, AS) (use == lv_assign ? (A) \
10509 : (use == lv_increment ? (I) \
10510 : (use == lv_decrement ? (D) : (AS))))
10511 if (TREE_CODE (arg
) == COMPONENT_REF
)
10513 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg
, 0))))
10514 error_at (loc
, READONLY_MSG (G_("assignment of member "
10515 "%qD in read-only object"),
10516 G_("increment of member "
10517 "%qD in read-only object"),
10518 G_("decrement of member "
10519 "%qD in read-only object"),
10520 G_("member %qD in read-only object "
10521 "used as %<asm%> output")),
10522 TREE_OPERAND (arg
, 1));
10524 error_at (loc
, READONLY_MSG (G_("assignment of read-only member %qD"),
10525 G_("increment of read-only member %qD"),
10526 G_("decrement of read-only member %qD"),
10527 G_("read-only member %qD used as %<asm%> output")),
10528 TREE_OPERAND (arg
, 1));
10530 else if (TREE_CODE (arg
) == VAR_DECL
)
10531 error_at (loc
, READONLY_MSG (G_("assignment of read-only variable %qD"),
10532 G_("increment of read-only variable %qD"),
10533 G_("decrement of read-only variable %qD"),
10534 G_("read-only variable %qD used as %<asm%> output")),
10536 else if (TREE_CODE (arg
) == PARM_DECL
)
10537 error_at (loc
, READONLY_MSG (G_("assignment of read-only parameter %qD"),
10538 G_("increment of read-only parameter %qD"),
10539 G_("decrement of read-only parameter %qD"),
10540 G_("read-only parameter %qD use as %<asm%> output")),
10542 else if (TREE_CODE (arg
) == RESULT_DECL
)
10544 gcc_assert (c_dialect_cxx ());
10545 error_at (loc
, READONLY_MSG (G_("assignment of "
10546 "read-only named return value %qD"),
10548 "read-only named return value %qD"),
10550 "read-only named return value %qD"),
10551 G_("read-only named return value %qD "
10552 "used as %<asm%>output")),
10555 else if (TREE_CODE (arg
) == FUNCTION_DECL
)
10556 error_at (loc
, READONLY_MSG (G_("assignment of function %qD"),
10557 G_("increment of function %qD"),
10558 G_("decrement of function %qD"),
10559 G_("function %qD used as %<asm%> output")),
10562 error_at (loc
, READONLY_MSG (G_("assignment of read-only location %qE"),
10563 G_("increment of read-only location %qE"),
10564 G_("decrement of read-only location %qE"),
10565 G_("read-only location %qE used as %<asm%> output")),
10569 /* Print an error message for an invalid lvalue. USE says
10570 how the lvalue is being used and so selects the error message. LOC
10571 is the location for the error. */
10574 lvalue_error (location_t loc
, enum lvalue_use use
)
10579 error_at (loc
, "lvalue required as left operand of assignment");
10582 error_at (loc
, "lvalue required as increment operand");
10585 error_at (loc
, "lvalue required as decrement operand");
10588 error_at (loc
, "lvalue required as unary %<&%> operand");
10591 error_at (loc
, "lvalue required in asm statement");
10594 gcc_unreachable ();
10598 /* Print an error message for an invalid indirection of type TYPE.
10599 ERRSTRING is the name of the operator for the indirection. */
10602 invalid_indirection_error (location_t loc
, tree type
, ref_operator errstring
)
10607 gcc_assert (c_dialect_cxx ());
10608 error_at (loc
, "invalid type argument (have %qT)", type
);
10610 case RO_ARRAY_INDEXING
:
10612 "invalid type argument of array indexing (have %qT)",
10615 case RO_UNARY_STAR
:
10617 "invalid type argument of unary %<*%> (have %qT)",
10622 "invalid type argument of %<->%> (have %qT)",
10625 case RO_ARROW_STAR
:
10627 "invalid type argument of %<->*%> (have %qT)",
10630 case RO_IMPLICIT_CONVERSION
:
10632 "invalid type argument of implicit conversion (have %qT)",
10636 gcc_unreachable ();
10640 /* *PTYPE is an incomplete array. Complete it with a domain based on
10641 INITIAL_VALUE. If INITIAL_VALUE is not present, use 1 if DO_DEFAULT
10642 is true. Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
10643 2 if INITIAL_VALUE was NULL, and 3 if INITIAL_VALUE was empty. */
10646 complete_array_type (tree
*ptype
, tree initial_value
, bool do_default
)
10648 tree maxindex
, type
, main_type
, elt
, unqual_elt
;
10649 int failure
= 0, quals
;
10650 hashval_t hashcode
= 0;
10651 bool overflow_p
= false;
10653 maxindex
= size_zero_node
;
10656 if (TREE_CODE (initial_value
) == STRING_CST
)
10659 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value
)));
10660 maxindex
= size_int (TREE_STRING_LENGTH (initial_value
)/eltsize
- 1);
10662 else if (TREE_CODE (initial_value
) == CONSTRUCTOR
)
10664 vec
<constructor_elt
, va_gc
> *v
= CONSTRUCTOR_ELTS (initial_value
);
10666 if (vec_safe_is_empty (v
))
10670 maxindex
= ssize_int (-1);
10675 unsigned HOST_WIDE_INT cnt
;
10676 constructor_elt
*ce
;
10677 bool fold_p
= false;
10680 maxindex
= (*v
)[0].index
, fold_p
= true;
10682 curindex
= maxindex
;
10684 for (cnt
= 1; vec_safe_iterate (v
, cnt
, &ce
); cnt
++)
10686 bool curfold_p
= false;
10688 curindex
= ce
->index
, curfold_p
= true;
10693 /* Since we treat size types now as ordinary
10694 unsigned types, we need an explicit overflow
10696 tree orig
= curindex
;
10697 curindex
= fold_convert (sizetype
, curindex
);
10698 overflow_p
|= tree_int_cst_lt (curindex
, orig
);
10700 curindex
= size_binop (PLUS_EXPR
, curindex
,
10703 if (tree_int_cst_lt (maxindex
, curindex
))
10704 maxindex
= curindex
, fold_p
= curfold_p
;
10708 tree orig
= maxindex
;
10709 maxindex
= fold_convert (sizetype
, maxindex
);
10710 overflow_p
|= tree_int_cst_lt (maxindex
, orig
);
10716 /* Make an error message unless that happened already. */
10717 if (initial_value
!= error_mark_node
)
10729 elt
= TREE_TYPE (type
);
10730 quals
= TYPE_QUALS (strip_array_types (elt
));
10734 unqual_elt
= c_build_qualified_type (elt
, KEEP_QUAL_ADDR_SPACE (quals
));
10736 /* Using build_distinct_type_copy and modifying things afterward instead
10737 of using build_array_type to create a new type preserves all of the
10738 TYPE_LANG_FLAG_? bits that the front end may have set. */
10739 main_type
= build_distinct_type_copy (TYPE_MAIN_VARIANT (type
));
10740 TREE_TYPE (main_type
) = unqual_elt
;
10741 TYPE_DOMAIN (main_type
)
10742 = build_range_type (TREE_TYPE (maxindex
),
10743 build_int_cst (TREE_TYPE (maxindex
), 0), maxindex
);
10744 layout_type (main_type
);
10746 /* Make sure we have the canonical MAIN_TYPE. */
10747 hashcode
= iterative_hash_object (TYPE_HASH (unqual_elt
), hashcode
);
10748 hashcode
= iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (main_type
)),
10750 main_type
= type_hash_canon (hashcode
, main_type
);
10752 /* Fix the canonical type. */
10753 if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type
))
10754 || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type
)))
10755 SET_TYPE_STRUCTURAL_EQUALITY (main_type
);
10756 else if (TYPE_CANONICAL (TREE_TYPE (main_type
)) != TREE_TYPE (main_type
)
10757 || (TYPE_CANONICAL (TYPE_DOMAIN (main_type
))
10758 != TYPE_DOMAIN (main_type
)))
10759 TYPE_CANONICAL (main_type
)
10760 = build_array_type (TYPE_CANONICAL (TREE_TYPE (main_type
)),
10761 TYPE_CANONICAL (TYPE_DOMAIN (main_type
)));
10763 TYPE_CANONICAL (main_type
) = main_type
;
10768 type
= c_build_qualified_type (main_type
, quals
);
10770 if (COMPLETE_TYPE_P (type
)
10771 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
10772 && (overflow_p
|| TREE_OVERFLOW (TYPE_SIZE_UNIT (type
))))
10774 error ("size of array is too large");
10775 /* If we proceed with the array type as it is, we'll eventually
10776 crash in tree_to_[su]hwi(). */
10777 type
= error_mark_node
;
10784 /* Like c_mark_addressable but don't check register qualifier. */
10786 c_common_mark_addressable_vec (tree t
)
10788 while (handled_component_p (t
))
10789 t
= TREE_OPERAND (t
, 0);
10790 if (TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != PARM_DECL
)
10792 TREE_ADDRESSABLE (t
) = 1;
10797 /* Used to help initialize the builtin-types.def table. When a type of
10798 the correct size doesn't exist, use error_mark_node instead of NULL.
10799 The later results in segfaults even when a decl using the type doesn't
10803 builtin_type_for_size (int size
, bool unsignedp
)
10805 tree type
= c_common_type_for_size (size
, unsignedp
);
10806 return type
? type
: error_mark_node
;
10809 /* A helper function for resolve_overloaded_builtin in resolving the
10810 overloaded __sync_ builtins. Returns a positive power of 2 if the
10811 first operand of PARAMS is a pointer to a supported data type.
10812 Returns 0 if an error is encountered. */
10815 sync_resolve_size (tree function
, vec
<tree
, va_gc
> *params
)
10822 error ("too few arguments to function %qE", function
);
10826 type
= TREE_TYPE ((*params
)[0]);
10827 if (TREE_CODE (type
) == ARRAY_TYPE
)
10829 /* Force array-to-pointer decay for C++. */
10830 gcc_assert (c_dialect_cxx());
10831 (*params
)[0] = default_conversion ((*params
)[0]);
10832 type
= TREE_TYPE ((*params
)[0]);
10834 if (TREE_CODE (type
) != POINTER_TYPE
)
10837 type
= TREE_TYPE (type
);
10838 if (!INTEGRAL_TYPE_P (type
) && !POINTER_TYPE_P (type
))
10841 size
= tree_to_uhwi (TYPE_SIZE_UNIT (type
));
10842 if (size
== 1 || size
== 2 || size
== 4 || size
== 8 || size
== 16)
10846 error ("incompatible type for argument %d of %qE", 1, function
);
10850 /* A helper function for resolve_overloaded_builtin. Adds casts to
10851 PARAMS to make arguments match up with those of FUNCTION. Drops
10852 the variadic arguments at the end. Returns false if some error
10853 was encountered; true on success. */
10856 sync_resolve_params (location_t loc
, tree orig_function
, tree function
,
10857 vec
<tree
, va_gc
> *params
, bool orig_format
)
10859 function_args_iterator iter
;
10861 unsigned int parmnum
;
10863 function_args_iter_init (&iter
, TREE_TYPE (function
));
10864 /* We've declared the implementation functions to use "volatile void *"
10865 as the pointer parameter, so we shouldn't get any complaints from the
10866 call to check_function_arguments what ever type the user used. */
10867 function_args_iter_next (&iter
);
10868 ptype
= TREE_TYPE (TREE_TYPE ((*params
)[0]));
10869 ptype
= TYPE_MAIN_VARIANT (ptype
);
10871 /* For the rest of the values, we need to cast these to FTYPE, so that we
10872 don't get warnings for passing pointer types, etc. */
10876 tree val
, arg_type
;
10878 arg_type
= function_args_iter_cond (&iter
);
10879 /* XXX void_type_node belies the abstraction. */
10880 if (arg_type
== void_type_node
)
10884 if (params
->length () <= parmnum
)
10886 error_at (loc
, "too few arguments to function %qE", orig_function
);
10890 /* Only convert parameters if arg_type is unsigned integer type with
10891 new format sync routines, i.e. don't attempt to convert pointer
10892 arguments (e.g. EXPECTED argument of __atomic_compare_exchange_n),
10893 bool arguments (e.g. WEAK argument) or signed int arguments (memmodel
10895 if (TREE_CODE (arg_type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (arg_type
))
10897 /* Ideally for the first conversion we'd use convert_for_assignment
10898 so that we get warnings for anything that doesn't match the pointer
10899 type. This isn't portable across the C and C++ front ends atm. */
10900 val
= (*params
)[parmnum
];
10901 val
= convert (ptype
, val
);
10902 val
= convert (arg_type
, val
);
10903 (*params
)[parmnum
] = val
;
10906 function_args_iter_next (&iter
);
10909 /* __atomic routines are not variadic. */
10910 if (!orig_format
&& params
->length () != parmnum
+ 1)
10912 error_at (loc
, "too many arguments to function %qE", orig_function
);
10916 /* The definition of these primitives is variadic, with the remaining
10917 being "an optional list of variables protected by the memory barrier".
10918 No clue what that's supposed to mean, precisely, but we consider all
10919 call-clobbered variables to be protected so we're safe. */
10920 params
->truncate (parmnum
+ 1);
10925 /* A helper function for resolve_overloaded_builtin. Adds a cast to
10926 RESULT to make it match the type of the first pointer argument in
10930 sync_resolve_return (tree first_param
, tree result
, bool orig_format
)
10932 tree ptype
= TREE_TYPE (TREE_TYPE (first_param
));
10933 tree rtype
= TREE_TYPE (result
);
10934 ptype
= TYPE_MAIN_VARIANT (ptype
);
10936 /* New format doesn't require casting unless the types are the same size. */
10937 if (orig_format
|| tree_int_cst_equal (TYPE_SIZE (ptype
), TYPE_SIZE (rtype
)))
10938 return convert (ptype
, result
);
10943 /* This function verifies the PARAMS to generic atomic FUNCTION.
10944 It returns the size if all the parameters are the same size, otherwise
10945 0 is returned if the parameters are invalid. */
10948 get_atomic_generic_size (location_t loc
, tree function
,
10949 vec
<tree
, va_gc
> *params
)
10951 unsigned int n_param
;
10952 unsigned int n_model
;
10957 /* Determine the parameter makeup. */
10958 switch (DECL_FUNCTION_CODE (function
))
10960 case BUILT_IN_ATOMIC_EXCHANGE
:
10964 case BUILT_IN_ATOMIC_LOAD
:
10965 case BUILT_IN_ATOMIC_STORE
:
10969 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10974 gcc_unreachable ();
10977 if (vec_safe_length (params
) != n_param
)
10979 error_at (loc
, "incorrect number of arguments to function %qE", function
);
10983 /* Get type of first parameter, and determine its size. */
10984 type_0
= TREE_TYPE ((*params
)[0]);
10985 if (TREE_CODE (type_0
) == ARRAY_TYPE
)
10987 /* Force array-to-pointer decay for C++. */
10988 gcc_assert (c_dialect_cxx());
10989 (*params
)[0] = default_conversion ((*params
)[0]);
10990 type_0
= TREE_TYPE ((*params
)[0]);
10992 if (TREE_CODE (type_0
) != POINTER_TYPE
|| VOID_TYPE_P (TREE_TYPE (type_0
)))
10994 error_at (loc
, "argument 1 of %qE must be a non-void pointer type",
10999 /* Types must be compile time constant sizes. */
11000 if (TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type_0
)))) != INTEGER_CST
)
11003 "argument 1 of %qE must be a pointer to a constant size type",
11008 size_0
= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type_0
)));
11010 /* Zero size objects are not allowed. */
11014 "argument 1 of %qE must be a pointer to a nonzero size object",
11019 /* Check each other parameter is a pointer and the same size. */
11020 for (x
= 0; x
< n_param
- n_model
; x
++)
11023 tree type
= TREE_TYPE ((*params
)[x
]);
11024 /* __atomic_compare_exchange has a bool in the 4th position, skip it. */
11025 if (n_param
== 6 && x
== 3)
11027 if (!POINTER_TYPE_P (type
))
11029 error_at (loc
, "argument %d of %qE must be a pointer type", x
+ 1,
11033 tree type_size
= TYPE_SIZE_UNIT (TREE_TYPE (type
));
11034 size
= type_size
? tree_to_uhwi (type_size
) : 0;
11035 if (size
!= size_0
)
11037 error_at (loc
, "size mismatch in argument %d of %qE", x
+ 1,
11043 /* Check memory model parameters for validity. */
11044 for (x
= n_param
- n_model
; x
< n_param
; x
++)
11046 tree p
= (*params
)[x
];
11047 if (TREE_CODE (p
) == INTEGER_CST
)
11049 int i
= tree_to_uhwi (p
);
11050 if (i
< 0 || (memmodel_base (i
) >= MEMMODEL_LAST
))
11052 warning_at (loc
, OPT_Winvalid_memory_model
,
11053 "invalid memory model argument %d of %qE", x
+ 1,
11058 if (!INTEGRAL_TYPE_P (TREE_TYPE (p
)))
11060 error_at (loc
, "non-integer memory model argument %d of %qE", x
+ 1,
11070 /* This will take an __atomic_ generic FUNCTION call, and add a size parameter N
11071 at the beginning of the parameter list PARAMS representing the size of the
11072 objects. This is to match the library ABI requirement. LOC is the location
11073 of the function call.
11074 The new function is returned if it needed rebuilding, otherwise NULL_TREE is
11075 returned to allow the external call to be constructed. */
11078 add_atomic_size_parameter (unsigned n
, location_t loc
, tree function
,
11079 vec
<tree
, va_gc
> *params
)
11083 /* Insert a SIZE_T parameter as the first param. If there isn't
11084 enough space, allocate a new vector and recursively re-build with that. */
11085 if (!params
->space (1))
11087 unsigned int z
, len
;
11088 vec
<tree
, va_gc
> *v
;
11091 len
= params
->length ();
11092 vec_alloc (v
, len
+ 1);
11093 v
->quick_push (build_int_cst (size_type_node
, n
));
11094 for (z
= 0; z
< len
; z
++)
11095 v
->quick_push ((*params
)[z
]);
11096 f
= build_function_call_vec (loc
, vNULL
, function
, v
, NULL
);
11101 /* Add the size parameter and leave as a function call for processing. */
11102 size_node
= build_int_cst (size_type_node
, n
);
11103 params
->quick_insert (0, size_node
);
11108 /* Return whether atomic operations for naturally aligned N-byte
11109 arguments are supported, whether inline or through libatomic. */
11111 atomic_size_supported_p (int n
)
11122 return targetm
.scalar_mode_supported_p (TImode
);
11129 /* This will process an __atomic_exchange function call, determine whether it
11130 needs to be mapped to the _N variation, or turned into a library call.
11131 LOC is the location of the builtin call.
11132 FUNCTION is the DECL that has been invoked;
11133 PARAMS is the argument list for the call. The return value is non-null
11134 TRUE is returned if it is translated into the proper format for a call to the
11135 external library, and NEW_RETURN is set the tree for that function.
11136 FALSE is returned if processing for the _N variation is required, and
11137 NEW_RETURN is set to the the return value the result is copied into. */
11139 resolve_overloaded_atomic_exchange (location_t loc
, tree function
,
11140 vec
<tree
, va_gc
> *params
, tree
*new_return
)
11142 tree p0
, p1
, p2
, p3
;
11143 tree I_type
, I_type_ptr
;
11144 int n
= get_atomic_generic_size (loc
, function
, params
);
11146 /* Size of 0 is an error condition. */
11149 *new_return
= error_mark_node
;
11153 /* If not a lock-free size, change to the library generic format. */
11154 if (!atomic_size_supported_p (n
))
11156 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
11160 /* Otherwise there is a lockfree match, transform the call from:
11161 void fn(T* mem, T* desired, T* return, model)
11163 *return = (T) (fn (In* mem, (In) *desired, model)) */
11170 /* Create pointer to appropriate size. */
11171 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
11172 I_type_ptr
= build_pointer_type (I_type
);
11174 /* Convert object pointer to required type. */
11175 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
11177 /* Convert new value to required type, and dereference it. */
11178 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
11179 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
11182 /* Move memory model to the 3rd position, and end param list. */
11184 params
->truncate (3);
11186 /* Convert return pointer and dereference it for later assignment. */
11187 *new_return
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
11193 /* This will process an __atomic_compare_exchange function call, determine
11194 whether it needs to be mapped to the _N variation, or turned into a lib call.
11195 LOC is the location of the builtin call.
11196 FUNCTION is the DECL that has been invoked;
11197 PARAMS is the argument list for the call. The return value is non-null
11198 TRUE is returned if it is translated into the proper format for a call to the
11199 external library, and NEW_RETURN is set the tree for that function.
11200 FALSE is returned if processing for the _N variation is required. */
11203 resolve_overloaded_atomic_compare_exchange (location_t loc
, tree function
,
11204 vec
<tree
, va_gc
> *params
,
11208 tree I_type
, I_type_ptr
;
11209 int n
= get_atomic_generic_size (loc
, function
, params
);
11211 /* Size of 0 is an error condition. */
11214 *new_return
= error_mark_node
;
11218 /* If not a lock-free size, change to the library generic format. */
11219 if (!atomic_size_supported_p (n
))
11221 /* The library generic format does not have the weak parameter, so
11222 remove it from the param list. Since a parameter has been removed,
11223 we can be sure that there is room for the SIZE_T parameter, meaning
11224 there will not be a recursive rebuilding of the parameter list, so
11225 there is no danger this will be done twice. */
11228 (*params
)[3] = (*params
)[4];
11229 (*params
)[4] = (*params
)[5];
11230 params
->truncate (5);
11232 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
11236 /* Otherwise, there is a match, so the call needs to be transformed from:
11237 bool fn(T* mem, T* desired, T* return, weak, success, failure)
11239 bool fn ((In *)mem, (In *)expected, (In) *desired, weak, succ, fail) */
11245 /* Create pointer to appropriate size. */
11246 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
11247 I_type_ptr
= build_pointer_type (I_type
);
11249 /* Convert object pointer to required type. */
11250 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
11253 /* Convert expected pointer to required type. */
11254 p1
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p1
);
11257 /* Convert desired value to required type, and dereference it. */
11258 p2
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
11259 p2
= build1 (VIEW_CONVERT_EXPR
, I_type
, p2
);
11262 /* The rest of the parameters are fine. NULL means no special return value
11264 *new_return
= NULL
;
11269 /* This will process an __atomic_load function call, determine whether it
11270 needs to be mapped to the _N variation, or turned into a library call.
11271 LOC is the location of the builtin call.
11272 FUNCTION is the DECL that has been invoked;
11273 PARAMS is the argument list for the call. The return value is non-null
11274 TRUE is returned if it is translated into the proper format for a call to the
11275 external library, and NEW_RETURN is set the tree for that function.
11276 FALSE is returned if processing for the _N variation is required, and
11277 NEW_RETURN is set to the the return value the result is copied into. */
11280 resolve_overloaded_atomic_load (location_t loc
, tree function
,
11281 vec
<tree
, va_gc
> *params
, tree
*new_return
)
11284 tree I_type
, I_type_ptr
;
11285 int n
= get_atomic_generic_size (loc
, function
, params
);
11287 /* Size of 0 is an error condition. */
11290 *new_return
= error_mark_node
;
11294 /* If not a lock-free size, change to the library generic format. */
11295 if (!atomic_size_supported_p (n
))
11297 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
11301 /* Otherwise, there is a match, so the call needs to be transformed from:
11302 void fn(T* mem, T* return, model)
11304 *return = (T) (fn ((In *) mem, model)) */
11310 /* Create pointer to appropriate size. */
11311 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
11312 I_type_ptr
= build_pointer_type (I_type
);
11314 /* Convert object pointer to required type. */
11315 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
11318 /* Move memory model to the 2nd position, and end param list. */
11320 params
->truncate (2);
11322 /* Convert return pointer and dereference it for later assignment. */
11323 *new_return
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
11329 /* This will process an __atomic_store function call, determine whether it
11330 needs to be mapped to the _N variation, or turned into a library call.
11331 LOC is the location of the builtin call.
11332 FUNCTION is the DECL that has been invoked;
11333 PARAMS is the argument list for the call. The return value is non-null
11334 TRUE is returned if it is translated into the proper format for a call to the
11335 external library, and NEW_RETURN is set the tree for that function.
11336 FALSE is returned if processing for the _N variation is required, and
11337 NEW_RETURN is set to the the return value the result is copied into. */
11340 resolve_overloaded_atomic_store (location_t loc
, tree function
,
11341 vec
<tree
, va_gc
> *params
, tree
*new_return
)
11344 tree I_type
, I_type_ptr
;
11345 int n
= get_atomic_generic_size (loc
, function
, params
);
11347 /* Size of 0 is an error condition. */
11350 *new_return
= error_mark_node
;
11354 /* If not a lock-free size, change to the library generic format. */
11355 if (!atomic_size_supported_p (n
))
11357 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
11361 /* Otherwise, there is a match, so the call needs to be transformed from:
11362 void fn(T* mem, T* value, model)
11364 fn ((In *) mem, (In) *value, model) */
11369 /* Create pointer to appropriate size. */
11370 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
11371 I_type_ptr
= build_pointer_type (I_type
);
11373 /* Convert object pointer to required type. */
11374 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
11377 /* Convert new value to required type, and dereference it. */
11378 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
11379 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
11382 /* The memory model is in the right spot already. Return is void. */
11383 *new_return
= NULL_TREE
;
11389 /* Some builtin functions are placeholders for other expressions. This
11390 function should be called immediately after parsing the call expression
11391 before surrounding code has committed to the type of the expression.
11393 LOC is the location of the builtin call.
11395 FUNCTION is the DECL that has been invoked; it is known to be a builtin.
11396 PARAMS is the argument list for the call. The return value is non-null
11397 when expansion is complete, and null if normal processing should
11401 resolve_overloaded_builtin (location_t loc
, tree function
,
11402 vec
<tree
, va_gc
> *params
)
11404 enum built_in_function orig_code
= DECL_FUNCTION_CODE (function
);
11405 bool orig_format
= true;
11406 tree new_return
= NULL_TREE
;
11408 switch (DECL_BUILT_IN_CLASS (function
))
11410 case BUILT_IN_NORMAL
:
11413 if (targetm
.resolve_overloaded_builtin
)
11414 return targetm
.resolve_overloaded_builtin (loc
, function
, params
);
11421 /* Handle BUILT_IN_NORMAL here. */
11424 case BUILT_IN_ATOMIC_EXCHANGE
:
11425 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
11426 case BUILT_IN_ATOMIC_LOAD
:
11427 case BUILT_IN_ATOMIC_STORE
:
11429 /* Handle these 4 together so that they can fall through to the next
11430 case if the call is transformed to an _N variant. */
11433 case BUILT_IN_ATOMIC_EXCHANGE
:
11435 if (resolve_overloaded_atomic_exchange (loc
, function
, params
,
11438 /* Change to the _N variant. */
11439 orig_code
= BUILT_IN_ATOMIC_EXCHANGE_N
;
11443 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
11445 if (resolve_overloaded_atomic_compare_exchange (loc
, function
,
11449 /* Change to the _N variant. */
11450 orig_code
= BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
;
11453 case BUILT_IN_ATOMIC_LOAD
:
11455 if (resolve_overloaded_atomic_load (loc
, function
, params
,
11458 /* Change to the _N variant. */
11459 orig_code
= BUILT_IN_ATOMIC_LOAD_N
;
11462 case BUILT_IN_ATOMIC_STORE
:
11464 if (resolve_overloaded_atomic_store (loc
, function
, params
,
11467 /* Change to the _N variant. */
11468 orig_code
= BUILT_IN_ATOMIC_STORE_N
;
11472 gcc_unreachable ();
11474 /* Fallthrough to the normal processing. */
11476 case BUILT_IN_ATOMIC_EXCHANGE_N
:
11477 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
:
11478 case BUILT_IN_ATOMIC_LOAD_N
:
11479 case BUILT_IN_ATOMIC_STORE_N
:
11480 case BUILT_IN_ATOMIC_ADD_FETCH_N
:
11481 case BUILT_IN_ATOMIC_SUB_FETCH_N
:
11482 case BUILT_IN_ATOMIC_AND_FETCH_N
:
11483 case BUILT_IN_ATOMIC_NAND_FETCH_N
:
11484 case BUILT_IN_ATOMIC_XOR_FETCH_N
:
11485 case BUILT_IN_ATOMIC_OR_FETCH_N
:
11486 case BUILT_IN_ATOMIC_FETCH_ADD_N
:
11487 case BUILT_IN_ATOMIC_FETCH_SUB_N
:
11488 case BUILT_IN_ATOMIC_FETCH_AND_N
:
11489 case BUILT_IN_ATOMIC_FETCH_NAND_N
:
11490 case BUILT_IN_ATOMIC_FETCH_XOR_N
:
11491 case BUILT_IN_ATOMIC_FETCH_OR_N
:
11493 orig_format
= false;
11494 /* Fallthru for parameter processing. */
11496 case BUILT_IN_SYNC_FETCH_AND_ADD_N
:
11497 case BUILT_IN_SYNC_FETCH_AND_SUB_N
:
11498 case BUILT_IN_SYNC_FETCH_AND_OR_N
:
11499 case BUILT_IN_SYNC_FETCH_AND_AND_N
:
11500 case BUILT_IN_SYNC_FETCH_AND_XOR_N
:
11501 case BUILT_IN_SYNC_FETCH_AND_NAND_N
:
11502 case BUILT_IN_SYNC_ADD_AND_FETCH_N
:
11503 case BUILT_IN_SYNC_SUB_AND_FETCH_N
:
11504 case BUILT_IN_SYNC_OR_AND_FETCH_N
:
11505 case BUILT_IN_SYNC_AND_AND_FETCH_N
:
11506 case BUILT_IN_SYNC_XOR_AND_FETCH_N
:
11507 case BUILT_IN_SYNC_NAND_AND_FETCH_N
:
11508 case BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
:
11509 case BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N
:
11510 case BUILT_IN_SYNC_LOCK_TEST_AND_SET_N
:
11511 case BUILT_IN_SYNC_LOCK_RELEASE_N
:
11513 int n
= sync_resolve_size (function
, params
);
11514 tree new_function
, first_param
, result
;
11515 enum built_in_function fncode
;
11518 return error_mark_node
;
11520 fncode
= (enum built_in_function
)((int)orig_code
+ exact_log2 (n
) + 1);
11521 new_function
= builtin_decl_explicit (fncode
);
11522 if (!sync_resolve_params (loc
, function
, new_function
, params
,
11524 return error_mark_node
;
11526 first_param
= (*params
)[0];
11527 result
= build_function_call_vec (loc
, vNULL
, new_function
, params
,
11529 if (result
== error_mark_node
)
11531 if (orig_code
!= BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
11532 && orig_code
!= BUILT_IN_SYNC_LOCK_RELEASE_N
11533 && orig_code
!= BUILT_IN_ATOMIC_STORE_N
)
11534 result
= sync_resolve_return (first_param
, result
, orig_format
);
11536 /* If new_return is set, assign function to that expr and cast the
11537 result to void since the generic interface returned void. */
11540 /* Cast function result from I{1,2,4,8,16} to the required type. */
11541 result
= build1 (VIEW_CONVERT_EXPR
, TREE_TYPE (new_return
), result
);
11542 result
= build2 (MODIFY_EXPR
, TREE_TYPE (new_return
), new_return
,
11544 TREE_SIDE_EFFECTS (result
) = 1;
11545 protected_set_expr_location (result
, loc
);
11546 result
= convert (void_type_node
, result
);
11556 /* vector_types_compatible_elements_p is used in type checks of vectors
11557 values used as operands of binary operators. Where it returns true, and
11558 the other checks of the caller succeed (being vector types in he first
11559 place, and matching number of elements), we can just treat the types
11560 as essentially the same.
11561 Contrast with vector_targets_convertible_p, which is used for vector
11562 pointer types, and vector_types_convertible_p, which will allow
11563 language-specific matches under the control of flag_lax_vector_conversions,
11564 and might still require a conversion. */
11565 /* True if vector types T1 and T2 can be inputs to the same binary
11566 operator without conversion.
11567 We don't check the overall vector size here because some of our callers
11568 want to give different error messages when the vectors are compatible
11569 except for the element count. */
11572 vector_types_compatible_elements_p (tree t1
, tree t2
)
11574 bool opaque
= TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
);
11575 t1
= TREE_TYPE (t1
);
11576 t2
= TREE_TYPE (t2
);
11578 enum tree_code c1
= TREE_CODE (t1
), c2
= TREE_CODE (t2
);
11580 gcc_assert ((c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
|| c1
== FIXED_POINT_TYPE
)
11581 && (c2
== INTEGER_TYPE
|| c2
== REAL_TYPE
11582 || c2
== FIXED_POINT_TYPE
));
11584 t1
= c_common_signed_type (t1
);
11585 t2
= c_common_signed_type (t2
);
11586 /* Equality works here because c_common_signed_type uses
11587 TYPE_MAIN_VARIANT. */
11590 if (opaque
&& c1
== c2
11591 && (c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
)
11592 && TYPE_PRECISION (t1
) == TYPE_PRECISION (t2
))
11597 /* Check for missing format attributes on function pointers. LTYPE is
11598 the new type or left-hand side type. RTYPE is the old type or
11599 right-hand side type. Returns TRUE if LTYPE is missing the desired
11603 check_missing_format_attribute (tree ltype
, tree rtype
)
11605 tree
const ttr
= TREE_TYPE (rtype
), ttl
= TREE_TYPE (ltype
);
11608 for (ra
= TYPE_ATTRIBUTES (ttr
); ra
; ra
= TREE_CHAIN (ra
))
11609 if (is_attribute_p ("format", TREE_PURPOSE (ra
)))
11614 for (la
= TYPE_ATTRIBUTES (ttl
); la
; la
= TREE_CHAIN (la
))
11615 if (is_attribute_p ("format", TREE_PURPOSE (la
)))
11623 /* Subscripting with type char is likely to lose on a machine where
11624 chars are signed. So warn on any machine, but optionally. Don't
11625 warn for unsigned char since that type is safe. Don't warn for
11626 signed char because anyone who uses that must have done so
11627 deliberately. Furthermore, we reduce the false positive load by
11628 warning only for non-constant value of type char. */
11631 warn_array_subscript_with_type_char (location_t loc
, tree index
)
11633 if (TYPE_MAIN_VARIANT (TREE_TYPE (index
)) == char_type_node
11634 && TREE_CODE (index
) != INTEGER_CST
)
11635 warning_at (loc
, OPT_Wchar_subscripts
,
11636 "array subscript has type %<char%>");
11639 /* Implement -Wparentheses for the unexpected C precedence rules, to
11640 cover cases like x + y << z which readers are likely to
11641 misinterpret. We have seen an expression in which CODE is a binary
11642 operator used to combine expressions ARG_LEFT and ARG_RIGHT, which
11643 before folding had CODE_LEFT and CODE_RIGHT. CODE_LEFT and
11644 CODE_RIGHT may be ERROR_MARK, which means that that side of the
11645 expression was not formed using a binary or unary operator, or it
11646 was enclosed in parentheses. */
11649 warn_about_parentheses (location_t loc
, enum tree_code code
,
11650 enum tree_code code_left
, tree arg_left
,
11651 enum tree_code code_right
, tree arg_right
)
11653 if (!warn_parentheses
)
11656 /* This macro tests that the expression ARG with original tree code
11657 CODE appears to be a boolean expression. or the result of folding a
11658 boolean expression. */
11659 #define APPEARS_TO_BE_BOOLEAN_EXPR_P(CODE, ARG) \
11660 (truth_value_p (TREE_CODE (ARG)) \
11661 || TREE_CODE (TREE_TYPE (ARG)) == BOOLEAN_TYPE \
11662 /* Folding may create 0 or 1 integers from other expressions. */ \
11663 || ((CODE) != INTEGER_CST \
11664 && (integer_onep (ARG) || integer_zerop (ARG))))
11669 if (code_left
== PLUS_EXPR
)
11670 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11671 "suggest parentheses around %<+%> inside %<<<%>");
11672 else if (code_right
== PLUS_EXPR
)
11673 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11674 "suggest parentheses around %<+%> inside %<<<%>");
11675 else if (code_left
== MINUS_EXPR
)
11676 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11677 "suggest parentheses around %<-%> inside %<<<%>");
11678 else if (code_right
== MINUS_EXPR
)
11679 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11680 "suggest parentheses around %<-%> inside %<<<%>");
11684 if (code_left
== PLUS_EXPR
)
11685 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11686 "suggest parentheses around %<+%> inside %<>>%>");
11687 else if (code_right
== PLUS_EXPR
)
11688 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11689 "suggest parentheses around %<+%> inside %<>>%>");
11690 else if (code_left
== MINUS_EXPR
)
11691 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11692 "suggest parentheses around %<-%> inside %<>>%>");
11693 else if (code_right
== MINUS_EXPR
)
11694 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11695 "suggest parentheses around %<-%> inside %<>>%>");
11698 case TRUTH_ORIF_EXPR
:
11699 if (code_left
== TRUTH_ANDIF_EXPR
)
11700 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11701 "suggest parentheses around %<&&%> within %<||%>");
11702 else if (code_right
== TRUTH_ANDIF_EXPR
)
11703 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11704 "suggest parentheses around %<&&%> within %<||%>");
11708 if (code_left
== BIT_AND_EXPR
|| code_left
== BIT_XOR_EXPR
11709 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
)
11710 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11711 "suggest parentheses around arithmetic in operand of %<|%>");
11712 else if (code_right
== BIT_AND_EXPR
|| code_right
== BIT_XOR_EXPR
11713 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
11714 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11715 "suggest parentheses around arithmetic in operand of %<|%>");
11716 /* Check cases like x|y==z */
11717 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11718 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11719 "suggest parentheses around comparison in operand of %<|%>");
11720 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11721 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11722 "suggest parentheses around comparison in operand of %<|%>");
11723 /* Check cases like !x | y */
11724 else if (code_left
== TRUTH_NOT_EXPR
11725 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
11726 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11727 "suggest parentheses around operand of "
11728 "%<!%> or change %<|%> to %<||%> or %<!%> to %<~%>");
11732 if (code_left
== BIT_AND_EXPR
11733 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
)
11734 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11735 "suggest parentheses around arithmetic in operand of %<^%>");
11736 else if (code_right
== BIT_AND_EXPR
11737 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
11738 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11739 "suggest parentheses around arithmetic in operand of %<^%>");
11740 /* Check cases like x^y==z */
11741 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11742 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11743 "suggest parentheses around comparison in operand of %<^%>");
11744 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11745 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11746 "suggest parentheses around comparison in operand of %<^%>");
11750 if (code_left
== PLUS_EXPR
)
11751 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11752 "suggest parentheses around %<+%> in operand of %<&%>");
11753 else if (code_right
== PLUS_EXPR
)
11754 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11755 "suggest parentheses around %<+%> in operand of %<&%>");
11756 else if (code_left
== MINUS_EXPR
)
11757 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11758 "suggest parentheses around %<-%> in operand of %<&%>");
11759 else if (code_right
== MINUS_EXPR
)
11760 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11761 "suggest parentheses around %<-%> in operand of %<&%>");
11762 /* Check cases like x&y==z */
11763 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11764 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11765 "suggest parentheses around comparison in operand of %<&%>");
11766 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11767 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11768 "suggest parentheses around comparison in operand of %<&%>");
11769 /* Check cases like !x & y */
11770 else if (code_left
== TRUTH_NOT_EXPR
11771 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
11772 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11773 "suggest parentheses around operand of "
11774 "%<!%> or change %<&%> to %<&&%> or %<!%> to %<~%>");
11778 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11779 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11780 "suggest parentheses around comparison in operand of %<==%>");
11781 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11782 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11783 "suggest parentheses around comparison in operand of %<==%>");
11786 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11787 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11788 "suggest parentheses around comparison in operand of %<!=%>");
11789 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11790 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11791 "suggest parentheses around comparison in operand of %<!=%>");
11795 if (TREE_CODE_CLASS (code
) == tcc_comparison
)
11797 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
11798 && code_left
!= NE_EXPR
&& code_left
!= EQ_EXPR
11799 && INTEGRAL_TYPE_P (TREE_TYPE (arg_left
)))
11800 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11801 "comparisons like %<X<=Y<=Z%> do not "
11802 "have their mathematical meaning");
11803 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
11804 && code_right
!= NE_EXPR
&& code_right
!= EQ_EXPR
11805 && INTEGRAL_TYPE_P (TREE_TYPE (arg_right
)))
11806 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11807 "comparisons like %<X<=Y<=Z%> do not "
11808 "have their mathematical meaning");
11812 #undef NOT_A_BOOLEAN_EXPR_P
11815 /* If LABEL (a LABEL_DECL) has not been used, issue a warning. */
11818 warn_for_unused_label (tree label
)
11820 if (!TREE_USED (label
))
11822 if (DECL_INITIAL (label
))
11823 warning (OPT_Wunused_label
, "label %q+D defined but not used", label
);
11825 warning (OPT_Wunused_label
, "label %q+D declared but not defined", label
);
11829 /* Warn for division by zero according to the value of DIVISOR. LOC
11830 is the location of the division operator. */
11833 warn_for_div_by_zero (location_t loc
, tree divisor
)
11835 /* If DIVISOR is zero, and has integral or fixed-point type, issue a warning
11836 about division by zero. Do not issue a warning if DIVISOR has a
11837 floating-point type, since we consider 0.0/0.0 a valid way of
11838 generating a NaN. */
11839 if (c_inhibit_evaluation_warnings
== 0
11840 && (integer_zerop (divisor
) || fixed_zerop (divisor
)))
11841 warning_at (loc
, OPT_Wdiv_by_zero
, "division by zero");
11844 /* Subroutine of build_binary_op. Give warnings for comparisons
11845 between signed and unsigned quantities that may fail. Do the
11846 checking based on the original operand trees ORIG_OP0 and ORIG_OP1,
11847 so that casts will be considered, but default promotions won't
11850 LOCATION is the location of the comparison operator.
11852 The arguments of this function map directly to local variables
11853 of build_binary_op. */
11856 warn_for_sign_compare (location_t location
,
11857 tree orig_op0
, tree orig_op1
,
11858 tree op0
, tree op1
,
11859 tree result_type
, enum tree_code resultcode
)
11861 int op0_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op0
));
11862 int op1_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op1
));
11863 int unsignedp0
, unsignedp1
;
11865 /* In C++, check for comparison of different enum types. */
11866 if (c_dialect_cxx()
11867 && TREE_CODE (TREE_TYPE (orig_op0
)) == ENUMERAL_TYPE
11868 && TREE_CODE (TREE_TYPE (orig_op1
)) == ENUMERAL_TYPE
11869 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0
))
11870 != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1
)))
11872 warning_at (location
,
11873 OPT_Wsign_compare
, "comparison between types %qT and %qT",
11874 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
));
11877 /* Do not warn if the comparison is being done in a signed type,
11878 since the signed type will only be chosen if it can represent
11879 all the values of the unsigned type. */
11880 if (!TYPE_UNSIGNED (result_type
))
11882 /* Do not warn if both operands are unsigned. */
11883 else if (op0_signed
== op1_signed
)
11887 tree sop
, uop
, base_type
;
11891 sop
= orig_op0
, uop
= orig_op1
;
11893 sop
= orig_op1
, uop
= orig_op0
;
11895 STRIP_TYPE_NOPS (sop
);
11896 STRIP_TYPE_NOPS (uop
);
11897 base_type
= (TREE_CODE (result_type
) == COMPLEX_TYPE
11898 ? TREE_TYPE (result_type
) : result_type
);
11900 /* Do not warn if the signed quantity is an unsuffixed integer
11901 literal (or some static constant expression involving such
11902 literals or a conditional expression involving such literals)
11903 and it is non-negative. */
11904 if (tree_expr_nonnegative_warnv_p (sop
, &ovf
))
11906 /* Do not warn if the comparison is an equality operation, the
11907 unsigned quantity is an integral constant, and it would fit
11908 in the result if the result were signed. */
11909 else if (TREE_CODE (uop
) == INTEGER_CST
11910 && (resultcode
== EQ_EXPR
|| resultcode
== NE_EXPR
)
11911 && int_fits_type_p (uop
, c_common_signed_type (base_type
)))
11913 /* In C, do not warn if the unsigned quantity is an enumeration
11914 constant and its maximum value would fit in the result if the
11915 result were signed. */
11916 else if (!c_dialect_cxx() && TREE_CODE (uop
) == INTEGER_CST
11917 && TREE_CODE (TREE_TYPE (uop
)) == ENUMERAL_TYPE
11918 && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (uop
)),
11919 c_common_signed_type (base_type
)))
11922 warning_at (location
,
11924 "comparison between signed and unsigned integer expressions");
11927 /* Warn if two unsigned values are being compared in a size larger
11928 than their original size, and one (and only one) is the result of
11929 a `~' operator. This comparison will always fail.
11931 Also warn if one operand is a constant, and the constant does not
11932 have all bits set that are set in the ~ operand when it is
11935 op0
= c_common_get_narrower (op0
, &unsignedp0
);
11936 op1
= c_common_get_narrower (op1
, &unsignedp1
);
11938 if ((TREE_CODE (op0
) == BIT_NOT_EXPR
)
11939 ^ (TREE_CODE (op1
) == BIT_NOT_EXPR
))
11941 if (TREE_CODE (op0
) == BIT_NOT_EXPR
)
11942 op0
= c_common_get_narrower (TREE_OPERAND (op0
, 0), &unsignedp0
);
11943 if (TREE_CODE (op1
) == BIT_NOT_EXPR
)
11944 op1
= c_common_get_narrower (TREE_OPERAND (op1
, 0), &unsignedp1
);
11946 if (tree_fits_shwi_p (op0
) || tree_fits_shwi_p (op1
))
11949 HOST_WIDE_INT constant
, mask
;
11953 if (tree_fits_shwi_p (op0
))
11956 unsignedp
= unsignedp1
;
11957 constant
= tree_to_shwi (op0
);
11962 unsignedp
= unsignedp0
;
11963 constant
= tree_to_shwi (op1
);
11966 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
11967 if (bits
< TYPE_PRECISION (result_type
)
11968 && bits
< HOST_BITS_PER_LONG
&& unsignedp
)
11970 mask
= (~ (HOST_WIDE_INT
) 0) << bits
;
11971 if ((mask
& constant
) != mask
)
11974 warning_at (location
, OPT_Wsign_compare
,
11975 "promoted ~unsigned is always non-zero");
11977 warning_at (location
, OPT_Wsign_compare
,
11978 "comparison of promoted ~unsigned with constant");
11982 else if (unsignedp0
&& unsignedp1
11983 && (TYPE_PRECISION (TREE_TYPE (op0
))
11984 < TYPE_PRECISION (result_type
))
11985 && (TYPE_PRECISION (TREE_TYPE (op1
))
11986 < TYPE_PRECISION (result_type
)))
11987 warning_at (location
, OPT_Wsign_compare
,
11988 "comparison of promoted ~unsigned with unsigned");
11992 /* RESULT_TYPE is the result of converting TYPE1 and TYPE2 to a common
11993 type via c_common_type. If -Wdouble-promotion is in use, and the
11994 conditions for warning have been met, issue a warning. GMSGID is
11995 the warning message. It must have two %T specifiers for the type
11996 that was converted (generally "float") and the type to which it was
11997 converted (generally "double), respectively. LOC is the location
11998 to which the awrning should refer. */
12001 do_warn_double_promotion (tree result_type
, tree type1
, tree type2
,
12002 const char *gmsgid
, location_t loc
)
12006 if (!warn_double_promotion
)
12008 /* If the conversion will not occur at run-time, there is no need to
12010 if (c_inhibit_evaluation_warnings
)
12012 if (TYPE_MAIN_VARIANT (result_type
) != double_type_node
12013 && TYPE_MAIN_VARIANT (result_type
) != complex_double_type_node
)
12015 if (TYPE_MAIN_VARIANT (type1
) == float_type_node
12016 || TYPE_MAIN_VARIANT (type1
) == complex_float_type_node
)
12017 source_type
= type1
;
12018 else if (TYPE_MAIN_VARIANT (type2
) == float_type_node
12019 || TYPE_MAIN_VARIANT (type2
) == complex_float_type_node
)
12020 source_type
= type2
;
12023 warning_at (loc
, OPT_Wdouble_promotion
, gmsgid
, source_type
, result_type
);
12026 /* Setup a TYPE_DECL node as a typedef representation.
12028 X is a TYPE_DECL for a typedef statement. Create a brand new
12029 ..._TYPE node (which will be just a variant of the existing
12030 ..._TYPE node with identical properties) and then install X
12031 as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
12033 The whole point here is to end up with a situation where each
12034 and every ..._TYPE node the compiler creates will be uniquely
12035 associated with AT MOST one node representing a typedef name.
12036 This way, even though the compiler substitutes corresponding
12037 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
12038 early on, later parts of the compiler can always do the reverse
12039 translation and get back the corresponding typedef name. For
12042 typedef struct S MY_TYPE;
12045 Later parts of the compiler might only know that `object' was of
12046 type `struct S' if it were not for code just below. With this
12047 code however, later parts of the compiler see something like:
12049 struct S' == struct S
12050 typedef struct S' MY_TYPE;
12053 And they can then deduce (from the node for type struct S') that
12054 the original object declaration was:
12058 Being able to do this is important for proper support of protoize,
12059 and also for generating precise symbolic debugging information
12060 which takes full account of the programmer's (typedef) vocabulary.
12062 Obviously, we don't want to generate a duplicate ..._TYPE node if
12063 the TYPE_DECL node that we are now processing really represents a
12064 standard built-in type. */
12067 set_underlying_type (tree x
)
12069 if (x
== error_mark_node
)
12071 if (DECL_IS_BUILTIN (x
))
12073 if (TYPE_NAME (TREE_TYPE (x
)) == 0)
12074 TYPE_NAME (TREE_TYPE (x
)) = x
;
12076 else if (TREE_TYPE (x
) != error_mark_node
12077 && DECL_ORIGINAL_TYPE (x
) == NULL_TREE
)
12079 tree tt
= TREE_TYPE (x
);
12080 DECL_ORIGINAL_TYPE (x
) = tt
;
12081 tt
= build_variant_type_copy (tt
);
12082 TYPE_STUB_DECL (tt
) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x
));
12083 TYPE_NAME (tt
) = x
;
12084 TREE_USED (tt
) = TREE_USED (x
);
12085 TREE_TYPE (x
) = tt
;
12089 /* Record the types used by the current global variable declaration
12090 being parsed, so that we can decide later to emit their debug info.
12091 Those types are in types_used_by_cur_var_decl, and we are going to
12092 store them in the types_used_by_vars_hash hash table.
12093 DECL is the declaration of the global variable that has been parsed. */
12096 record_types_used_by_current_var_decl (tree decl
)
12098 gcc_assert (decl
&& DECL_P (decl
) && TREE_STATIC (decl
));
12100 while (types_used_by_cur_var_decl
&& !types_used_by_cur_var_decl
->is_empty ())
12102 tree type
= types_used_by_cur_var_decl
->pop ();
12103 types_used_by_var_decl_insert (type
, decl
);
12107 /* If DECL is a typedef that is declared in the current function,
12108 record it for the purpose of -Wunused-local-typedefs. */
12111 record_locally_defined_typedef (tree decl
)
12113 struct c_language_function
*l
;
12115 if (!warn_unused_local_typedefs
12117 /* if this is not a locally defined typedef then we are not
12119 || !is_typedef_decl (decl
)
12120 || !decl_function_context (decl
))
12123 l
= (struct c_language_function
*) cfun
->language
;
12124 vec_safe_push (l
->local_typedefs
, decl
);
12127 /* If T is a TYPE_DECL declared locally, mark it as used. */
12130 maybe_record_typedef_use (tree t
)
12132 if (!is_typedef_decl (t
))
12135 TREE_USED (t
) = true;
12138 /* Warn if there are some unused locally defined typedefs in the
12139 current function. */
12142 maybe_warn_unused_local_typedefs (void)
12146 /* The number of times we have emitted -Wunused-local-typedefs
12147 warnings. If this is different from errorcount, that means some
12148 unrelated errors have been issued. In which case, we'll avoid
12149 emitting "unused-local-typedefs" warnings. */
12150 static int unused_local_typedefs_warn_count
;
12151 struct c_language_function
*l
;
12156 if ((l
= (struct c_language_function
*) cfun
->language
) == NULL
)
12159 if (warn_unused_local_typedefs
12160 && errorcount
== unused_local_typedefs_warn_count
)
12162 FOR_EACH_VEC_SAFE_ELT (l
->local_typedefs
, i
, decl
)
12163 if (!TREE_USED (decl
))
12164 warning_at (DECL_SOURCE_LOCATION (decl
),
12165 OPT_Wunused_local_typedefs
,
12166 "typedef %qD locally defined but not used", decl
);
12167 unused_local_typedefs_warn_count
= errorcount
;
12170 vec_free (l
->local_typedefs
);
12173 /* Warn about boolean expression compared with an integer value different
12174 from true/false. Warns also e.g. about "(i1 == i2) == 2".
12175 LOC is the location of the comparison, CODE is its code, OP0 and OP1
12176 are the operands of the comparison. The caller must ensure that
12177 either operand is a boolean expression. */
12180 maybe_warn_bool_compare (location_t loc
, enum tree_code code
, tree op0
,
12183 if (TREE_CODE_CLASS (code
) != tcc_comparison
)
12186 tree cst
= (TREE_CODE (op0
) == INTEGER_CST
)
12187 ? op0
: (TREE_CODE (op1
) == INTEGER_CST
) ? op1
: NULL_TREE
;
12191 if (!integer_zerop (cst
) && !integer_onep (cst
))
12193 int sign
= (TREE_CODE (op0
) == INTEGER_CST
12194 ? tree_int_cst_sgn (cst
) : -tree_int_cst_sgn (cst
));
12195 if (code
== EQ_EXPR
12196 || ((code
== GT_EXPR
|| code
== GE_EXPR
) && sign
< 0)
12197 || ((code
== LT_EXPR
|| code
== LE_EXPR
) && sign
> 0))
12198 warning_at (loc
, OPT_Wbool_compare
, "comparison of constant %qE "
12199 "with boolean expression is always false", cst
);
12201 warning_at (loc
, OPT_Wbool_compare
, "comparison of constant %qE "
12202 "with boolean expression is always true", cst
);
12204 else if (integer_zerop (cst
) || integer_onep (cst
))
12206 /* If the non-constant operand isn't of a boolean type, we
12207 don't want to warn here. */
12208 tree noncst
= TREE_CODE (op0
) == INTEGER_CST
? op1
: op0
;
12209 /* Handle booleans promoted to integers. */
12210 if (CONVERT_EXPR_P (noncst
)
12211 && TREE_TYPE (noncst
) == integer_type_node
12212 && TREE_CODE (TREE_TYPE (TREE_OPERAND (noncst
, 0))) == BOOLEAN_TYPE
)
12214 else if (TREE_CODE (TREE_TYPE (noncst
)) != BOOLEAN_TYPE
12215 && !truth_value_p (TREE_CODE (noncst
)))
12217 /* Do some magic to get the right diagnostics. */
12218 bool flag
= TREE_CODE (op0
) == INTEGER_CST
;
12219 flag
= integer_zerop (cst
) ? flag
: !flag
;
12220 if ((code
== GE_EXPR
&& !flag
) || (code
== LE_EXPR
&& flag
))
12221 warning_at (loc
, OPT_Wbool_compare
, "comparison of constant %qE "
12222 "with boolean expression is always true", cst
);
12223 else if ((code
== LT_EXPR
&& !flag
) || (code
== GT_EXPR
&& flag
))
12224 warning_at (loc
, OPT_Wbool_compare
, "comparison of constant %qE "
12225 "with boolean expression is always false", cst
);
12229 /* The C and C++ parsers both use vectors to hold function arguments.
12230 For efficiency, we keep a cache of unused vectors. This is the
12233 typedef vec
<tree
, va_gc
> *tree_gc_vec
;
12234 static GTY((deletable
)) vec
<tree_gc_vec
, va_gc
> *tree_vector_cache
;
12236 /* Return a new vector from the cache. If the cache is empty,
12237 allocate a new vector. These vectors are GC'ed, so it is OK if the
12238 pointer is not released.. */
12241 make_tree_vector (void)
12243 if (tree_vector_cache
&& !tree_vector_cache
->is_empty ())
12244 return tree_vector_cache
->pop ();
12247 /* Passing 0 to vec::alloc returns NULL, and our callers require
12248 that we always return a non-NULL value. The vector code uses
12249 4 when growing a NULL vector, so we do too. */
12250 vec
<tree
, va_gc
> *v
;
12256 /* Release a vector of trees back to the cache. */
12259 release_tree_vector (vec
<tree
, va_gc
> *vec
)
12264 vec_safe_push (tree_vector_cache
, vec
);
12268 /* Get a new tree vector holding a single tree. */
12271 make_tree_vector_single (tree t
)
12273 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
12274 ret
->quick_push (t
);
12278 /* Get a new tree vector of the TREE_VALUEs of a TREE_LIST chain. */
12281 make_tree_vector_from_list (tree list
)
12283 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
12284 for (; list
; list
= TREE_CHAIN (list
))
12285 vec_safe_push (ret
, TREE_VALUE (list
));
12289 /* Get a new tree vector which is a copy of an existing one. */
12292 make_tree_vector_copy (const vec
<tree
, va_gc
> *orig
)
12294 vec
<tree
, va_gc
> *ret
;
12298 ret
= make_tree_vector ();
12299 vec_safe_reserve (ret
, vec_safe_length (orig
));
12300 FOR_EACH_VEC_SAFE_ELT (orig
, ix
, t
)
12301 ret
->quick_push (t
);
12305 /* Return true if KEYWORD starts a type specifier. */
12308 keyword_begins_type_specifier (enum rid keyword
)
12312 case RID_AUTO_TYPE
:
12324 case RID_DFLOAT128
:
12340 if (keyword
>= RID_FIRST_INT_N
12341 && keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
12342 && int_n_enabled_p
[keyword
-RID_FIRST_INT_N
])
12348 /* Return true if KEYWORD names a type qualifier. */
12351 keyword_is_type_qualifier (enum rid keyword
)
12365 /* Return true if KEYWORD names a storage class specifier.
12367 RID_TYPEDEF is not included in this list despite `typedef' being
12368 listed in C99 6.7.1.1. 6.7.1.3 indicates that `typedef' is listed as
12369 such for syntactic convenience only. */
12372 keyword_is_storage_class_specifier (enum rid keyword
)
12388 /* Return true if KEYWORD names a function-specifier [dcl.fct.spec]. */
12391 keyword_is_function_specifier (enum rid keyword
)
12405 /* Return true if KEYWORD names a decl-specifier [dcl.spec] or a
12406 declaration-specifier (C99 6.7). */
12409 keyword_is_decl_specifier (enum rid keyword
)
12411 if (keyword_is_storage_class_specifier (keyword
)
12412 || keyword_is_type_qualifier (keyword
)
12413 || keyword_is_function_specifier (keyword
))
12420 case RID_CONSTEXPR
:
12427 /* Initialize language-specific-bits of tree_contains_struct. */
12430 c_common_init_ts (void)
12432 MARK_TS_TYPED (C_MAYBE_CONST_EXPR
);
12433 MARK_TS_TYPED (EXCESS_PRECISION_EXPR
);
12434 MARK_TS_TYPED (ARRAY_NOTATION_REF
);
12437 /* Build a user-defined numeric literal out of an integer constant type VALUE
12438 with identifier SUFFIX. */
12441 build_userdef_literal (tree suffix_id
, tree value
,
12442 enum overflow_type overflow
, tree num_string
)
12444 tree literal
= make_node (USERDEF_LITERAL
);
12445 USERDEF_LITERAL_SUFFIX_ID (literal
) = suffix_id
;
12446 USERDEF_LITERAL_VALUE (literal
) = value
;
12447 USERDEF_LITERAL_OVERFLOW (literal
) = overflow
;
12448 USERDEF_LITERAL_NUM_STRING (literal
) = num_string
;
12452 /* For vector[index], convert the vector to a
12453 pointer of the underlying type. Return true if the resulting
12454 ARRAY_REF should not be an lvalue. */
12457 convert_vector_to_pointer_for_subscript (location_t loc
,
12458 tree
*vecp
, tree index
)
12461 if (TREE_CODE (TREE_TYPE (*vecp
)) == VECTOR_TYPE
)
12463 tree type
= TREE_TYPE (*vecp
);
12466 ret
= !lvalue_p (*vecp
);
12467 if (TREE_CODE (index
) == INTEGER_CST
)
12468 if (!tree_fits_uhwi_p (index
)
12469 || tree_to_uhwi (index
) >= TYPE_VECTOR_SUBPARTS (type
))
12470 warning_at (loc
, OPT_Warray_bounds
, "index value is out of bound");
12474 tree tmp
= create_tmp_var_raw (type
);
12475 DECL_SOURCE_LOCATION (tmp
) = loc
;
12476 *vecp
= c_save_expr (*vecp
);
12477 if (TREE_CODE (*vecp
) == C_MAYBE_CONST_EXPR
)
12479 bool non_const
= C_MAYBE_CONST_EXPR_NON_CONST (*vecp
);
12480 *vecp
= C_MAYBE_CONST_EXPR_EXPR (*vecp
);
12482 = c_wrap_maybe_const (build4 (TARGET_EXPR
, type
, tmp
,
12483 *vecp
, NULL_TREE
, NULL_TREE
),
12487 *vecp
= build4 (TARGET_EXPR
, type
, tmp
, *vecp
,
12488 NULL_TREE
, NULL_TREE
);
12489 SET_EXPR_LOCATION (*vecp
, loc
);
12490 c_common_mark_addressable_vec (tmp
);
12493 c_common_mark_addressable_vec (*vecp
);
12494 type
= build_qualified_type (TREE_TYPE (type
), TYPE_QUALS (type
));
12495 type1
= build_pointer_type (TREE_TYPE (*vecp
));
12496 bool ref_all
= TYPE_REF_CAN_ALIAS_ALL (type1
);
12498 && !DECL_P (*vecp
))
12500 /* If the original vector isn't declared may_alias and it
12501 isn't a bare vector look if the subscripting would
12502 alias the vector we subscript, and if not, force ref-all. */
12503 alias_set_type vecset
= get_alias_set (*vecp
);
12504 alias_set_type sset
= get_alias_set (type
);
12505 if (!alias_sets_must_conflict_p (sset
, vecset
)
12506 && !alias_set_subset_of (sset
, vecset
))
12509 type
= build_pointer_type_for_mode (type
, ptr_mode
, ref_all
);
12510 *vecp
= build1 (ADDR_EXPR
, type1
, *vecp
);
12511 *vecp
= convert (type
, *vecp
);
12516 /* Determine which of the operands, if any, is a scalar that needs to be
12517 converted to a vector, for the range of operations. */
12519 scalar_to_vector (location_t loc
, enum tree_code code
, tree op0
, tree op1
,
12522 tree type0
= TREE_TYPE (op0
);
12523 tree type1
= TREE_TYPE (op1
);
12524 bool integer_only_op
= false;
12525 enum stv_conv ret
= stv_firstarg
;
12527 gcc_assert (TREE_CODE (type0
) == VECTOR_TYPE
12528 || TREE_CODE (type1
) == VECTOR_TYPE
);
12531 /* Most GENERIC binary expressions require homogeneous arguments.
12532 LSHIFT_EXPR and RSHIFT_EXPR are exceptions and accept a first
12533 argument that is a vector and a second one that is a scalar, so
12534 we never return stv_secondarg for them. */
12537 if (TREE_CODE (type0
) == INTEGER_TYPE
12538 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
12540 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
12543 error_at (loc
, "conversion of scalar %qT to vector %qT "
12544 "involves truncation", type0
, type1
);
12548 return stv_firstarg
;
12555 integer_only_op
= true;
12556 /* ... fall through ... */
12558 case VEC_COND_EXPR
:
12563 case TRUNC_DIV_EXPR
:
12564 case CEIL_DIV_EXPR
:
12565 case FLOOR_DIV_EXPR
:
12566 case ROUND_DIV_EXPR
:
12567 case EXACT_DIV_EXPR
:
12568 case TRUNC_MOD_EXPR
:
12569 case FLOOR_MOD_EXPR
:
12577 /* What about UNLT_EXPR? */
12578 if (TREE_CODE (type0
) == VECTOR_TYPE
)
12581 ret
= stv_secondarg
;
12582 /* Swap TYPE0 with TYPE1 and OP0 with OP1 */
12583 tmp
= type0
; type0
= type1
; type1
= tmp
;
12584 tmp
= op0
; op0
= op1
; op1
= tmp
;
12587 if (TREE_CODE (type0
) == INTEGER_TYPE
12588 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
12590 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
12593 error_at (loc
, "conversion of scalar %qT to vector %qT "
12594 "involves truncation", type0
, type1
);
12599 else if (!integer_only_op
12600 /* Allow integer --> real conversion if safe. */
12601 && (TREE_CODE (type0
) == REAL_TYPE
12602 || TREE_CODE (type0
) == INTEGER_TYPE
)
12603 && SCALAR_FLOAT_TYPE_P (TREE_TYPE (type1
)))
12605 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
12608 error_at (loc
, "conversion of scalar %qT to vector %qT "
12609 "involves truncation", type0
, type1
);
12618 return stv_nothing
;
12621 /* Return true iff ALIGN is an integral constant that is a fundamental
12622 alignment, as defined by [basic.align] in the c++-11
12627 [A fundamental alignment is represented by an alignment less than or
12628 equal to the greatest alignment supported by the implementation
12629 in all contexts, which is equal to
12630 alignof(max_align_t)]. */
12633 cxx_fundamental_alignment_p (unsigned align
)
12635 return (align
<= MAX (TYPE_ALIGN (long_long_integer_type_node
),
12636 TYPE_ALIGN (long_double_type_node
)));
12639 /* Return true if T is a pointer to a zero-sized aggregate. */
12642 pointer_to_zero_sized_aggr_p (tree t
)
12644 if (!POINTER_TYPE_P (t
))
12647 return (TYPE_SIZE (t
) && integer_zerop (TYPE_SIZE (t
)));
12650 #include "gt-c-family-c-common.h"