1 /* Subroutines shared by all languages that are variants of C.
2 Copyright (C) 1992-2013 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/>. */
22 #include "coretypes.h"
35 #include "common/common-target.h"
36 #include "langhooks.h"
37 #include "tree-inline.h"
39 #include "diagnostic.h"
40 #include "tree-iterator.h"
44 #include "target-def.h"
46 cpp_reader
*parse_in
; /* Declared in c-pragma.h. */
48 /* The following symbols are subsumed in the c_global_trees array, and
49 listed here individually for documentation purposes.
51 INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
53 tree short_integer_type_node;
54 tree long_integer_type_node;
55 tree long_long_integer_type_node;
56 tree int128_integer_type_node;
58 tree short_unsigned_type_node;
59 tree long_unsigned_type_node;
60 tree long_long_unsigned_type_node;
61 tree int128_unsigned_type_node;
63 tree truthvalue_type_node;
64 tree truthvalue_false_node;
65 tree truthvalue_true_node;
67 tree ptrdiff_type_node;
69 tree unsigned_char_type_node;
70 tree signed_char_type_node;
73 tree char16_type_node;
74 tree char32_type_node;
77 tree double_type_node;
78 tree long_double_type_node;
80 tree complex_integer_type_node;
81 tree complex_float_type_node;
82 tree complex_double_type_node;
83 tree complex_long_double_type_node;
85 tree dfloat32_type_node;
86 tree dfloat64_type_node;
87 tree_dfloat128_type_node;
95 tree unsigned_intQI_type_node;
96 tree unsigned_intHI_type_node;
97 tree unsigned_intSI_type_node;
98 tree unsigned_intDI_type_node;
99 tree unsigned_intTI_type_node;
101 tree widest_integer_literal_type_node;
102 tree widest_unsigned_literal_type_node;
104 Nodes for types `void *' and `const void *'.
106 tree ptr_type_node, const_ptr_type_node;
108 Nodes for types `char *' and `const char *'.
110 tree string_type_node, const_string_type_node;
112 Type `char[SOMENUMBER]'.
113 Used when an array of char is needed and the size is irrelevant.
115 tree char_array_type_node;
117 Type `int[SOMENUMBER]' or something like it.
118 Used when an array of int needed and the size is irrelevant.
120 tree int_array_type_node;
122 Type `wchar_t[SOMENUMBER]' or something like it.
123 Used when a wide string literal is created.
125 tree wchar_array_type_node;
127 Type `char16_t[SOMENUMBER]' or something like it.
128 Used when a UTF-16 string literal is created.
130 tree char16_array_type_node;
132 Type `char32_t[SOMENUMBER]' or something like it.
133 Used when a UTF-32 string literal is created.
135 tree char32_array_type_node;
137 Type `int ()' -- used for implicit declaration of functions.
139 tree default_function_type;
141 A VOID_TYPE node, packaged in a TREE_LIST.
145 The lazily created VAR_DECLs for __FUNCTION__, __PRETTY_FUNCTION__,
146 and __func__. (C doesn't generate __FUNCTION__ and__PRETTY_FUNCTION__
147 VAR_DECLS, but C++ does.)
149 tree function_name_decl_node;
150 tree pretty_function_name_decl_node;
151 tree c99_function_name_decl_node;
153 Stack of nested function name VAR_DECLs.
155 tree saved_function_name_decls;
159 tree c_global_trees
[CTI_MAX
];
161 /* Switches common to the C front ends. */
163 /* Nonzero means don't output line number information. */
165 char flag_no_line_commands
;
167 /* Nonzero causes -E output not to be done, but directives such as
168 #define that have side effects are still obeyed. */
172 /* Nonzero means dump macros in some fashion. */
174 char flag_dump_macros
;
176 /* Nonzero means pass #include lines through to the output. */
178 char flag_dump_includes
;
180 /* Nonzero means process PCH files while preprocessing. */
182 bool flag_pch_preprocess
;
184 /* The file name to which we should write a precompiled header, or
185 NULL if no header will be written in this compile. */
187 const char *pch_file
;
189 /* Nonzero if an ISO standard was selected. It rejects macros in the
193 /* C/ObjC language option variables. */
196 /* Nonzero means allow type mismatches in conditional expressions;
197 just make their values `void'. */
199 int flag_cond_mismatch
;
201 /* Nonzero means enable C89 Amendment 1 features. */
205 /* Nonzero means use the ISO C99 (or C11) dialect of C. */
209 /* Nonzero means use the ISO C11 dialect of C. */
213 /* Nonzero means that we have builtin functions, and main is an int. */
218 /* ObjC language option variables. */
221 /* Tells the compiler that this is a special run. Do not perform any
222 compiling, instead we are to test some platform dependent features
223 and output a C header file with appropriate definitions. */
225 int print_struct_values
;
227 /* Tells the compiler what is the constant string class for ObjC. */
229 const char *constant_string_class_name
;
232 /* C++ language option variables. */
235 /* Nonzero means generate separate instantiation control files and
236 juggle them at link time. */
238 int flag_use_repository
;
240 /* The C++ dialect being used. C++98 is the default. */
242 enum cxx_dialect cxx_dialect
= cxx98
;
244 /* Maximum template instantiation depth. This limit exists to limit the
245 time it takes to notice excessively recursive template instantiations.
247 The default is lower than the 1024 recommended by the C++0x standard
248 because G++ runs out of stack before 1024 with highly recursive template
249 argument deduction substitution (g++.dg/cpp0x/enum11.C). */
251 int max_tinst_depth
= 900;
253 /* The elements of `ridpointers' are identifier nodes for the reserved
254 type names and storage classes. It is indexed by a RID_... value. */
257 tree (*make_fname_decl
) (location_t
, tree
, int);
259 /* Nonzero means don't warn about problems that occur when the code is
261 int c_inhibit_evaluation_warnings
;
263 /* Whether we are building a boolean conversion inside
264 convert_for_assignment, or some other late binary operation. If
265 build_binary_op is called for C (from code shared by C and C++) in
266 this case, then the operands have already been folded and the
267 result will not be folded again, so C_MAYBE_CONST_EXPR should not
269 bool in_late_binary_op
;
271 /* Whether lexing has been completed, so subsequent preprocessor
272 errors should use the compiler's input_location. */
273 bool done_lexing
= false;
275 /* Information about how a function name is generated. */
278 tree
*const decl
; /* pointer to the VAR_DECL. */
279 const unsigned rid
; /* RID number for the identifier. */
280 const int pretty
; /* How pretty is it? */
283 /* The three ways of getting then name of the current function. */
285 const struct fname_var_t fname_vars
[] =
287 /* C99 compliant __func__, must be first. */
288 {&c99_function_name_decl_node
, RID_C99_FUNCTION_NAME
, 0},
289 /* GCC __FUNCTION__ compliant. */
290 {&function_name_decl_node
, RID_FUNCTION_NAME
, 0},
291 /* GCC __PRETTY_FUNCTION__ compliant. */
292 {&pretty_function_name_decl_node
, RID_PRETTY_FUNCTION_NAME
, 1},
296 /* Global visibility options. */
297 struct visibility_flags visibility_options
;
299 static tree
c_fully_fold_internal (tree expr
, bool, bool *, bool *);
300 static tree
check_case_value (tree
);
301 static bool check_case_bounds (tree
, tree
, tree
*, tree
*);
303 static tree
handle_packed_attribute (tree
*, tree
, tree
, int, bool *);
304 static tree
handle_nocommon_attribute (tree
*, tree
, tree
, int, bool *);
305 static tree
handle_common_attribute (tree
*, tree
, tree
, int, bool *);
306 static tree
handle_noreturn_attribute (tree
*, tree
, tree
, int, bool *);
307 static tree
handle_hot_attribute (tree
*, tree
, tree
, int, bool *);
308 static tree
handle_cold_attribute (tree
*, tree
, tree
, int, bool *);
309 static tree
handle_no_sanitize_address_attribute (tree
*, tree
, tree
,
311 static tree
handle_no_address_safety_analysis_attribute (tree
*, tree
, tree
,
313 static tree
handle_no_sanitize_undefined_attribute (tree
*, tree
, tree
, int,
315 static tree
handle_noinline_attribute (tree
*, tree
, tree
, int, bool *);
316 static tree
handle_noclone_attribute (tree
*, tree
, tree
, int, bool *);
317 static tree
handle_leaf_attribute (tree
*, tree
, tree
, int, bool *);
318 static tree
handle_always_inline_attribute (tree
*, tree
, tree
, int,
320 static tree
handle_gnu_inline_attribute (tree
*, tree
, tree
, int, bool *);
321 static tree
handle_artificial_attribute (tree
*, tree
, tree
, int, bool *);
322 static tree
handle_flatten_attribute (tree
*, tree
, tree
, int, bool *);
323 static tree
handle_error_attribute (tree
*, tree
, tree
, int, bool *);
324 static tree
handle_used_attribute (tree
*, tree
, tree
, int, bool *);
325 static tree
handle_unused_attribute (tree
*, tree
, tree
, int, bool *);
326 static tree
handle_externally_visible_attribute (tree
*, tree
, tree
, int,
328 static tree
handle_const_attribute (tree
*, tree
, tree
, int, bool *);
329 static tree
handle_transparent_union_attribute (tree
*, tree
, tree
,
331 static tree
handle_constructor_attribute (tree
*, tree
, tree
, int, bool *);
332 static tree
handle_destructor_attribute (tree
*, tree
, tree
, int, bool *);
333 static tree
handle_mode_attribute (tree
*, tree
, tree
, int, bool *);
334 static tree
handle_section_attribute (tree
*, tree
, tree
, int, bool *);
335 static tree
handle_aligned_attribute (tree
*, tree
, tree
, int, bool *);
336 static tree
handle_weak_attribute (tree
*, tree
, tree
, int, bool *) ;
337 static tree
handle_alias_ifunc_attribute (bool, tree
*, tree
, tree
, bool *);
338 static tree
handle_ifunc_attribute (tree
*, tree
, tree
, int, bool *);
339 static tree
handle_alias_attribute (tree
*, tree
, tree
, int, bool *);
340 static tree
handle_weakref_attribute (tree
*, tree
, tree
, int, bool *) ;
341 static tree
handle_visibility_attribute (tree
*, tree
, tree
, int,
343 static tree
handle_tls_model_attribute (tree
*, tree
, tree
, int,
345 static tree
handle_no_instrument_function_attribute (tree
*, tree
,
347 static tree
handle_malloc_attribute (tree
*, tree
, tree
, int, bool *);
348 static tree
handle_returns_twice_attribute (tree
*, tree
, tree
, int, bool *);
349 static tree
handle_no_limit_stack_attribute (tree
*, tree
, tree
, int,
351 static tree
handle_pure_attribute (tree
*, tree
, tree
, int, bool *);
352 static tree
handle_tm_attribute (tree
*, tree
, tree
, int, bool *);
353 static tree
handle_tm_wrap_attribute (tree
*, tree
, tree
, int, bool *);
354 static tree
handle_novops_attribute (tree
*, tree
, tree
, int, bool *);
355 static tree
handle_deprecated_attribute (tree
*, tree
, tree
, int,
357 static tree
handle_vector_size_attribute (tree
*, tree
, tree
, int,
359 static tree
handle_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
360 static tree
handle_nothrow_attribute (tree
*, tree
, tree
, int, bool *);
361 static tree
handle_cleanup_attribute (tree
*, tree
, tree
, int, bool *);
362 static tree
handle_warn_unused_result_attribute (tree
*, tree
, tree
, int,
364 static tree
handle_sentinel_attribute (tree
*, tree
, tree
, int, bool *);
365 static tree
handle_type_generic_attribute (tree
*, tree
, tree
, int, bool *);
366 static tree
handle_alloc_size_attribute (tree
*, tree
, tree
, int, bool *);
367 static tree
handle_target_attribute (tree
*, tree
, tree
, int, bool *);
368 static tree
handle_optimize_attribute (tree
*, tree
, tree
, int, bool *);
369 static tree
ignore_attribute (tree
*, tree
, tree
, int, bool *);
370 static tree
handle_no_split_stack_attribute (tree
*, tree
, tree
, int, bool *);
371 static tree
handle_fnspec_attribute (tree
*, tree
, tree
, int, bool *);
372 static tree
handle_warn_unused_attribute (tree
*, tree
, tree
, int, bool *);
373 static tree
handle_returns_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
374 static tree
handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int,
376 static tree
handle_omp_declare_target_attribute (tree
*, tree
, tree
, int,
378 static tree
handle_bnd_variable_size_attribute (tree
*, tree
, tree
, int, bool *);
379 static tree
handle_bnd_legacy (tree
*, tree
, tree
, int, bool *);
381 static void check_function_nonnull (tree
, int, tree
*);
382 static void check_nonnull_arg (void *, tree
, unsigned HOST_WIDE_INT
);
383 static bool nonnull_check_p (tree
, unsigned HOST_WIDE_INT
);
384 static bool get_nonnull_operand (tree
, unsigned HOST_WIDE_INT
*);
385 static int resort_field_decl_cmp (const void *, const void *);
387 /* Reserved words. The third field is a mask: keywords are disabled
388 if they match the mask.
391 C --std=c89: D_C99 | D_CXXONLY | D_OBJC | D_CXX_OBJC
392 C --std=c99: D_CXXONLY | D_OBJC
393 ObjC is like C except that D_OBJC and D_CXX_OBJC are not set
394 C++ --std=c98: D_CONLY | D_CXXOX | D_OBJC
395 C++ --std=c0x: D_CONLY | D_OBJC
396 ObjC++ is like C++ except that D_OBJC is not set
398 If -fno-asm is used, D_ASM is added to the mask. If
399 -fno-gnu-keywords is used, D_EXT is added. If -fno-asm and C in
400 C89 mode, D_EXT89 is added for both -fno-asm and -fno-gnu-keywords.
401 In C with -Wc++-compat, we warn if D_CXXWARN is set.
403 Note the complication of the D_CXX_OBJC keywords. These are
404 reserved words such as 'class'. In C++, 'class' is a reserved
405 word. In Objective-C++ it is too. In Objective-C, it is a
406 reserved word too, but only if it follows an '@' sign.
408 const struct c_common_resword c_common_reswords
[] =
410 { "_Alignas", RID_ALIGNAS
, D_CONLY
},
411 { "_Alignof", RID_ALIGNOF
, D_CONLY
},
412 { "_Bool", RID_BOOL
, D_CONLY
},
413 { "_Complex", RID_COMPLEX
, 0 },
414 { "_Cilk_spawn", RID_CILK_SPAWN
, 0 },
415 { "_Cilk_sync", RID_CILK_SYNC
, 0 },
416 { "_Imaginary", RID_IMAGINARY
, D_CONLY
},
417 { "_Decimal32", RID_DFLOAT32
, D_CONLY
| D_EXT
},
418 { "_Decimal64", RID_DFLOAT64
, D_CONLY
| D_EXT
},
419 { "_Decimal128", RID_DFLOAT128
, D_CONLY
| D_EXT
},
420 { "_Fract", RID_FRACT
, D_CONLY
| D_EXT
},
421 { "_Accum", RID_ACCUM
, D_CONLY
| D_EXT
},
422 { "_Sat", RID_SAT
, D_CONLY
| D_EXT
},
423 { "_Static_assert", RID_STATIC_ASSERT
, D_CONLY
},
424 { "_Noreturn", RID_NORETURN
, D_CONLY
},
425 { "_Generic", RID_GENERIC
, D_CONLY
},
426 { "__FUNCTION__", RID_FUNCTION_NAME
, 0 },
427 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME
, 0 },
428 { "__alignof", RID_ALIGNOF
, 0 },
429 { "__alignof__", RID_ALIGNOF
, 0 },
430 { "__asm", RID_ASM
, 0 },
431 { "__asm__", RID_ASM
, 0 },
432 { "__attribute", RID_ATTRIBUTE
, 0 },
433 { "__attribute__", RID_ATTRIBUTE
, 0 },
434 { "__bases", RID_BASES
, D_CXXONLY
},
435 { "__builtin_choose_expr", RID_CHOOSE_EXPR
, D_CONLY
},
436 { "__builtin_complex", RID_BUILTIN_COMPLEX
, D_CONLY
},
437 { "__builtin_shuffle", RID_BUILTIN_SHUFFLE
, 0 },
438 { "__builtin_offsetof", RID_OFFSETOF
, 0 },
439 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P
, D_CONLY
},
440 { "__builtin_va_arg", RID_VA_ARG
, 0 },
441 { "__complex", RID_COMPLEX
, 0 },
442 { "__complex__", RID_COMPLEX
, 0 },
443 { "__const", RID_CONST
, 0 },
444 { "__const__", RID_CONST
, 0 },
445 { "__decltype", RID_DECLTYPE
, D_CXXONLY
},
446 { "__direct_bases", RID_DIRECT_BASES
, D_CXXONLY
},
447 { "__extension__", RID_EXTENSION
, 0 },
448 { "__func__", RID_C99_FUNCTION_NAME
, 0 },
449 { "__has_nothrow_assign", RID_HAS_NOTHROW_ASSIGN
, D_CXXONLY
},
450 { "__has_nothrow_constructor", RID_HAS_NOTHROW_CONSTRUCTOR
, D_CXXONLY
},
451 { "__has_nothrow_copy", RID_HAS_NOTHROW_COPY
, D_CXXONLY
},
452 { "__has_trivial_assign", RID_HAS_TRIVIAL_ASSIGN
, D_CXXONLY
},
453 { "__has_trivial_constructor", RID_HAS_TRIVIAL_CONSTRUCTOR
, D_CXXONLY
},
454 { "__has_trivial_copy", RID_HAS_TRIVIAL_COPY
, D_CXXONLY
},
455 { "__has_trivial_destructor", RID_HAS_TRIVIAL_DESTRUCTOR
, D_CXXONLY
},
456 { "__has_virtual_destructor", RID_HAS_VIRTUAL_DESTRUCTOR
, D_CXXONLY
},
457 { "__imag", RID_IMAGPART
, 0 },
458 { "__imag__", RID_IMAGPART
, 0 },
459 { "__inline", RID_INLINE
, 0 },
460 { "__inline__", RID_INLINE
, 0 },
461 { "__int128", RID_INT128
, 0 },
462 { "__is_abstract", RID_IS_ABSTRACT
, D_CXXONLY
},
463 { "__is_base_of", RID_IS_BASE_OF
, D_CXXONLY
},
464 { "__is_class", RID_IS_CLASS
, D_CXXONLY
},
465 { "__is_convertible_to", RID_IS_CONVERTIBLE_TO
, D_CXXONLY
},
466 { "__is_empty", RID_IS_EMPTY
, D_CXXONLY
},
467 { "__is_enum", RID_IS_ENUM
, D_CXXONLY
},
468 { "__is_final", RID_IS_FINAL
, D_CXXONLY
},
469 { "__is_literal_type", RID_IS_LITERAL_TYPE
, D_CXXONLY
},
470 { "__is_pod", RID_IS_POD
, D_CXXONLY
},
471 { "__is_polymorphic", RID_IS_POLYMORPHIC
, D_CXXONLY
},
472 { "__is_standard_layout", RID_IS_STD_LAYOUT
, D_CXXONLY
},
473 { "__is_trivial", RID_IS_TRIVIAL
, D_CXXONLY
},
474 { "__is_union", RID_IS_UNION
, D_CXXONLY
},
475 { "__label__", RID_LABEL
, 0 },
476 { "__null", RID_NULL
, 0 },
477 { "__real", RID_REALPART
, 0 },
478 { "__real__", RID_REALPART
, 0 },
479 { "__restrict", RID_RESTRICT
, 0 },
480 { "__restrict__", RID_RESTRICT
, 0 },
481 { "__signed", RID_SIGNED
, 0 },
482 { "__signed__", RID_SIGNED
, 0 },
483 { "__thread", RID_THREAD
, 0 },
484 { "__transaction_atomic", RID_TRANSACTION_ATOMIC
, 0 },
485 { "__transaction_relaxed", RID_TRANSACTION_RELAXED
, 0 },
486 { "__transaction_cancel", RID_TRANSACTION_CANCEL
, 0 },
487 { "__typeof", RID_TYPEOF
, 0 },
488 { "__typeof__", RID_TYPEOF
, 0 },
489 { "__underlying_type", RID_UNDERLYING_TYPE
, D_CXXONLY
},
490 { "__volatile", RID_VOLATILE
, 0 },
491 { "__volatile__", RID_VOLATILE
, 0 },
492 { "alignas", RID_ALIGNAS
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
493 { "alignof", RID_ALIGNOF
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
494 { "asm", RID_ASM
, D_ASM
},
495 { "auto", RID_AUTO
, 0 },
496 { "bool", RID_BOOL
, D_CXXONLY
| D_CXXWARN
},
497 { "break", RID_BREAK
, 0 },
498 { "case", RID_CASE
, 0 },
499 { "catch", RID_CATCH
, D_CXX_OBJC
| D_CXXWARN
},
500 { "char", RID_CHAR
, 0 },
501 { "char16_t", RID_CHAR16
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
502 { "char32_t", RID_CHAR32
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
503 { "class", RID_CLASS
, D_CXX_OBJC
| D_CXXWARN
},
504 { "const", RID_CONST
, 0 },
505 { "constexpr", RID_CONSTEXPR
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
506 { "const_cast", RID_CONSTCAST
, D_CXXONLY
| D_CXXWARN
},
507 { "continue", RID_CONTINUE
, 0 },
508 { "decltype", RID_DECLTYPE
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
509 { "default", RID_DEFAULT
, 0 },
510 { "delete", RID_DELETE
, D_CXXONLY
| D_CXXWARN
},
512 { "double", RID_DOUBLE
, 0 },
513 { "dynamic_cast", RID_DYNCAST
, D_CXXONLY
| D_CXXWARN
},
514 { "else", RID_ELSE
, 0 },
515 { "enum", RID_ENUM
, 0 },
516 { "explicit", RID_EXPLICIT
, D_CXXONLY
| D_CXXWARN
},
517 { "export", RID_EXPORT
, D_CXXONLY
| D_CXXWARN
},
518 { "extern", RID_EXTERN
, 0 },
519 { "false", RID_FALSE
, D_CXXONLY
| D_CXXWARN
},
520 { "float", RID_FLOAT
, 0 },
521 { "for", RID_FOR
, 0 },
522 { "friend", RID_FRIEND
, D_CXXONLY
| D_CXXWARN
},
523 { "goto", RID_GOTO
, 0 },
525 { "inline", RID_INLINE
, D_EXT89
},
526 { "int", RID_INT
, 0 },
527 { "long", RID_LONG
, 0 },
528 { "mutable", RID_MUTABLE
, D_CXXONLY
| D_CXXWARN
},
529 { "namespace", RID_NAMESPACE
, D_CXXONLY
| D_CXXWARN
},
530 { "new", RID_NEW
, D_CXXONLY
| D_CXXWARN
},
531 { "noexcept", RID_NOEXCEPT
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
532 { "nullptr", RID_NULLPTR
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
533 { "operator", RID_OPERATOR
, D_CXXONLY
| D_CXXWARN
},
534 { "private", RID_PRIVATE
, D_CXX_OBJC
| D_CXXWARN
},
535 { "protected", RID_PROTECTED
, D_CXX_OBJC
| D_CXXWARN
},
536 { "public", RID_PUBLIC
, D_CXX_OBJC
| D_CXXWARN
},
537 { "register", RID_REGISTER
, 0 },
538 { "reinterpret_cast", RID_REINTCAST
, D_CXXONLY
| D_CXXWARN
},
539 { "restrict", RID_RESTRICT
, D_CONLY
| D_C99
},
540 { "return", RID_RETURN
, 0 },
541 { "short", RID_SHORT
, 0 },
542 { "signed", RID_SIGNED
, 0 },
543 { "sizeof", RID_SIZEOF
, 0 },
544 { "static", RID_STATIC
, 0 },
545 { "static_assert", RID_STATIC_ASSERT
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
546 { "static_cast", RID_STATCAST
, D_CXXONLY
| D_CXXWARN
},
547 { "struct", RID_STRUCT
, 0 },
548 { "switch", RID_SWITCH
, 0 },
549 { "template", RID_TEMPLATE
, D_CXXONLY
| D_CXXWARN
},
550 { "this", RID_THIS
, D_CXXONLY
| D_CXXWARN
},
551 { "thread_local", RID_THREAD
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
552 { "throw", RID_THROW
, D_CXX_OBJC
| D_CXXWARN
},
553 { "true", RID_TRUE
, D_CXXONLY
| D_CXXWARN
},
554 { "try", RID_TRY
, D_CXX_OBJC
| D_CXXWARN
},
555 { "typedef", RID_TYPEDEF
, 0 },
556 { "typename", RID_TYPENAME
, D_CXXONLY
| D_CXXWARN
},
557 { "typeid", RID_TYPEID
, D_CXXONLY
| D_CXXWARN
},
558 { "typeof", RID_TYPEOF
, D_ASM
| D_EXT
},
559 { "union", RID_UNION
, 0 },
560 { "unsigned", RID_UNSIGNED
, 0 },
561 { "using", RID_USING
, D_CXXONLY
| D_CXXWARN
},
562 { "virtual", RID_VIRTUAL
, D_CXXONLY
| D_CXXWARN
},
563 { "void", RID_VOID
, 0 },
564 { "volatile", RID_VOLATILE
, 0 },
565 { "wchar_t", RID_WCHAR
, D_CXXONLY
},
566 { "while", RID_WHILE
, 0 },
567 /* These Objective-C keywords are recognized only immediately after
569 { "compatibility_alias", RID_AT_ALIAS
, D_OBJC
},
570 { "defs", RID_AT_DEFS
, D_OBJC
},
571 { "encode", RID_AT_ENCODE
, D_OBJC
},
572 { "end", RID_AT_END
, D_OBJC
},
573 { "implementation", RID_AT_IMPLEMENTATION
, D_OBJC
},
574 { "interface", RID_AT_INTERFACE
, D_OBJC
},
575 { "protocol", RID_AT_PROTOCOL
, D_OBJC
},
576 { "selector", RID_AT_SELECTOR
, D_OBJC
},
577 { "finally", RID_AT_FINALLY
, D_OBJC
},
578 { "synchronized", RID_AT_SYNCHRONIZED
, D_OBJC
},
579 { "optional", RID_AT_OPTIONAL
, D_OBJC
},
580 { "required", RID_AT_REQUIRED
, D_OBJC
},
581 { "property", RID_AT_PROPERTY
, D_OBJC
},
582 { "package", RID_AT_PACKAGE
, D_OBJC
},
583 { "synthesize", RID_AT_SYNTHESIZE
, D_OBJC
},
584 { "dynamic", RID_AT_DYNAMIC
, D_OBJC
},
585 /* These are recognized only in protocol-qualifier context
587 { "bycopy", RID_BYCOPY
, D_OBJC
},
588 { "byref", RID_BYREF
, D_OBJC
},
589 { "in", RID_IN
, D_OBJC
},
590 { "inout", RID_INOUT
, D_OBJC
},
591 { "oneway", RID_ONEWAY
, D_OBJC
},
592 { "out", RID_OUT
, D_OBJC
},
593 /* These are recognized inside a property attribute list */
594 { "assign", RID_ASSIGN
, D_OBJC
},
595 { "copy", RID_COPY
, D_OBJC
},
596 { "getter", RID_GETTER
, D_OBJC
},
597 { "nonatomic", RID_NONATOMIC
, D_OBJC
},
598 { "readonly", RID_READONLY
, D_OBJC
},
599 { "readwrite", RID_READWRITE
, D_OBJC
},
600 { "retain", RID_RETAIN
, D_OBJC
},
601 { "setter", RID_SETTER
, D_OBJC
},
604 const unsigned int num_c_common_reswords
=
605 sizeof c_common_reswords
/ sizeof (struct c_common_resword
);
607 /* Table of machine-independent attributes common to all C-like languages. */
608 const struct attribute_spec c_common_attribute_table
[] =
610 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
611 affects_type_identity } */
612 { "packed", 0, 0, false, false, false,
613 handle_packed_attribute
, false},
614 { "nocommon", 0, 0, true, false, false,
615 handle_nocommon_attribute
, false},
616 { "common", 0, 0, true, false, false,
617 handle_common_attribute
, false },
618 /* FIXME: logically, noreturn attributes should be listed as
619 "false, true, true" and apply to function types. But implementing this
620 would require all the places in the compiler that use TREE_THIS_VOLATILE
621 on a decl to identify non-returning functions to be located and fixed
622 to check the function type instead. */
623 { "noreturn", 0, 0, true, false, false,
624 handle_noreturn_attribute
, false },
625 { "volatile", 0, 0, true, false, false,
626 handle_noreturn_attribute
, false },
627 { "noinline", 0, 0, true, false, false,
628 handle_noinline_attribute
, false },
629 { "noclone", 0, 0, true, false, false,
630 handle_noclone_attribute
, false },
631 { "leaf", 0, 0, true, false, false,
632 handle_leaf_attribute
, false },
633 { "always_inline", 0, 0, true, false, false,
634 handle_always_inline_attribute
, false },
635 { "gnu_inline", 0, 0, true, false, false,
636 handle_gnu_inline_attribute
, false },
637 { "artificial", 0, 0, true, false, false,
638 handle_artificial_attribute
, false },
639 { "flatten", 0, 0, true, false, false,
640 handle_flatten_attribute
, false },
641 { "used", 0, 0, true, false, false,
642 handle_used_attribute
, false },
643 { "unused", 0, 0, false, false, false,
644 handle_unused_attribute
, false },
645 { "externally_visible", 0, 0, true, false, false,
646 handle_externally_visible_attribute
, false },
647 /* The same comments as for noreturn attributes apply to const ones. */
648 { "const", 0, 0, true, false, false,
649 handle_const_attribute
, false },
650 { "transparent_union", 0, 0, false, false, false,
651 handle_transparent_union_attribute
, false },
652 { "constructor", 0, 1, true, false, false,
653 handle_constructor_attribute
, false },
654 { "destructor", 0, 1, true, false, false,
655 handle_destructor_attribute
, false },
656 { "mode", 1, 1, false, true, false,
657 handle_mode_attribute
, false },
658 { "section", 1, 1, true, false, false,
659 handle_section_attribute
, false },
660 { "aligned", 0, 1, false, false, false,
661 handle_aligned_attribute
, false },
662 { "weak", 0, 0, true, false, false,
663 handle_weak_attribute
, false },
664 { "ifunc", 1, 1, true, false, false,
665 handle_ifunc_attribute
, false },
666 { "alias", 1, 1, true, false, false,
667 handle_alias_attribute
, false },
668 { "weakref", 0, 1, true, false, false,
669 handle_weakref_attribute
, false },
670 { "no_instrument_function", 0, 0, true, false, false,
671 handle_no_instrument_function_attribute
,
673 { "malloc", 0, 0, true, false, false,
674 handle_malloc_attribute
, false },
675 { "returns_twice", 0, 0, true, false, false,
676 handle_returns_twice_attribute
, false },
677 { "no_stack_limit", 0, 0, true, false, false,
678 handle_no_limit_stack_attribute
, false },
679 { "pure", 0, 0, true, false, false,
680 handle_pure_attribute
, false },
681 { "transaction_callable", 0, 0, false, true, false,
682 handle_tm_attribute
, false },
683 { "transaction_unsafe", 0, 0, false, true, false,
684 handle_tm_attribute
, false },
685 { "transaction_safe", 0, 0, false, true, false,
686 handle_tm_attribute
, false },
687 { "transaction_may_cancel_outer", 0, 0, false, true, false,
688 handle_tm_attribute
, false },
689 /* ??? These two attributes didn't make the transition from the
690 Intel language document to the multi-vendor language document. */
691 { "transaction_pure", 0, 0, false, true, false,
692 handle_tm_attribute
, false },
693 { "transaction_wrap", 1, 1, true, false, false,
694 handle_tm_wrap_attribute
, false },
695 /* For internal use (marking of builtins) only. The name contains space
696 to prevent its usage in source code. */
697 { "no vops", 0, 0, true, false, false,
698 handle_novops_attribute
, false },
699 { "deprecated", 0, 1, false, false, false,
700 handle_deprecated_attribute
, false },
701 { "vector_size", 1, 1, false, true, false,
702 handle_vector_size_attribute
, false },
703 { "visibility", 1, 1, false, false, false,
704 handle_visibility_attribute
, false },
705 { "tls_model", 1, 1, true, false, false,
706 handle_tls_model_attribute
, false },
707 { "nonnull", 0, -1, false, true, true,
708 handle_nonnull_attribute
, false },
709 { "nothrow", 0, 0, true, false, false,
710 handle_nothrow_attribute
, false },
711 { "may_alias", 0, 0, false, true, false, NULL
, false },
712 { "cleanup", 1, 1, true, false, false,
713 handle_cleanup_attribute
, false },
714 { "warn_unused_result", 0, 0, false, true, true,
715 handle_warn_unused_result_attribute
, false },
716 { "sentinel", 0, 1, false, true, true,
717 handle_sentinel_attribute
, false },
718 /* For internal use (marking of builtins) only. The name contains space
719 to prevent its usage in source code. */
720 { "type generic", 0, 0, false, true, true,
721 handle_type_generic_attribute
, false },
722 { "alloc_size", 1, 2, false, true, true,
723 handle_alloc_size_attribute
, false },
724 { "cold", 0, 0, true, false, false,
725 handle_cold_attribute
, false },
726 { "hot", 0, 0, true, false, false,
727 handle_hot_attribute
, false },
728 { "no_address_safety_analysis",
729 0, 0, true, false, false,
730 handle_no_address_safety_analysis_attribute
,
732 { "no_sanitize_address", 0, 0, true, false, false,
733 handle_no_sanitize_address_attribute
,
735 { "no_sanitize_undefined", 0, 0, true, false, false,
736 handle_no_sanitize_undefined_attribute
,
738 { "warning", 1, 1, true, false, false,
739 handle_error_attribute
, false },
740 { "error", 1, 1, true, false, false,
741 handle_error_attribute
, false },
742 { "target", 1, -1, true, false, false,
743 handle_target_attribute
, false },
744 { "optimize", 1, -1, true, false, false,
745 handle_optimize_attribute
, false },
746 /* For internal use only. The leading '*' both prevents its usage in
747 source code and signals that it may be overridden by machine tables. */
748 { "*tm regparm", 0, 0, false, true, true,
749 ignore_attribute
, false },
750 { "no_split_stack", 0, 0, true, false, false,
751 handle_no_split_stack_attribute
, false },
752 /* For internal use (marking of builtins and runtime functions) only.
753 The name contains space to prevent its usage in source code. */
754 { "fn spec", 1, 1, false, true, true,
755 handle_fnspec_attribute
, false },
756 { "warn_unused", 0, 0, false, false, false,
757 handle_warn_unused_attribute
, false },
758 { "returns_nonnull", 0, 0, false, true, true,
759 handle_returns_nonnull_attribute
, false },
760 { "omp declare simd", 0, -1, true, false, false,
761 handle_omp_declare_simd_attribute
, false },
762 { "omp declare target", 0, 0, true, false, false,
763 handle_omp_declare_target_attribute
, false },
764 { "bnd_variable_size", 0, 0, true, false, false,
765 handle_bnd_variable_size_attribute
, false },
766 { "bnd_legacy", 0, 0, true, false, false,
767 handle_bnd_legacy
, false },
768 { NULL
, 0, 0, false, false, false, NULL
, false }
771 /* Give the specifications for the format attributes, used by C and all
774 const struct attribute_spec c_common_format_attribute_table
[] =
776 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
777 affects_type_identity } */
778 { "format", 3, 3, false, true, true,
779 handle_format_attribute
, false },
780 { "format_arg", 1, 1, false, true, true,
781 handle_format_arg_attribute
, false },
782 { NULL
, 0, 0, false, false, false, NULL
, false }
785 /* Return identifier for address space AS. */
788 c_addr_space_name (addr_space_t as
)
790 int rid
= RID_FIRST_ADDR_SPACE
+ as
;
791 gcc_assert (ridpointers
[rid
]);
792 return IDENTIFIER_POINTER (ridpointers
[rid
]);
795 /* Push current bindings for the function name VAR_DECLS. */
798 start_fname_decls (void)
801 tree saved
= NULL_TREE
;
803 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
805 tree decl
= *fname_vars
[ix
].decl
;
809 saved
= tree_cons (decl
, build_int_cst (integer_type_node
, ix
),
811 *fname_vars
[ix
].decl
= NULL_TREE
;
814 if (saved
|| saved_function_name_decls
)
815 /* Normally they'll have been NULL, so only push if we've got a
816 stack, or they are non-NULL. */
817 saved_function_name_decls
= tree_cons (saved
, NULL_TREE
,
818 saved_function_name_decls
);
821 /* Finish up the current bindings, adding them into the current function's
822 statement tree. This must be done _before_ finish_stmt_tree is called.
823 If there is no current function, we must be at file scope and no statements
824 are involved. Pop the previous bindings. */
827 finish_fname_decls (void)
830 tree stmts
= NULL_TREE
;
831 tree stack
= saved_function_name_decls
;
833 for (; stack
&& TREE_VALUE (stack
); stack
= TREE_CHAIN (stack
))
834 append_to_statement_list (TREE_VALUE (stack
), &stmts
);
838 tree
*bodyp
= &DECL_SAVED_TREE (current_function_decl
);
840 if (TREE_CODE (*bodyp
) == BIND_EXPR
)
841 bodyp
= &BIND_EXPR_BODY (*bodyp
);
843 append_to_statement_list_force (*bodyp
, &stmts
);
847 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
848 *fname_vars
[ix
].decl
= NULL_TREE
;
852 /* We had saved values, restore them. */
855 for (saved
= TREE_PURPOSE (stack
); saved
; saved
= TREE_CHAIN (saved
))
857 tree decl
= TREE_PURPOSE (saved
);
858 unsigned ix
= TREE_INT_CST_LOW (TREE_VALUE (saved
));
860 *fname_vars
[ix
].decl
= decl
;
862 stack
= TREE_CHAIN (stack
);
864 saved_function_name_decls
= stack
;
867 /* Return the text name of the current function, suitably prettified
868 by PRETTY_P. Return string must be freed by caller. */
871 fname_as_string (int pretty_p
)
873 const char *name
= "top level";
876 cpp_string cstr
= { 0, 0 }, strname
;
884 if (current_function_decl
)
885 name
= lang_hooks
.decl_printable_name (current_function_decl
, vrb
);
887 len
= strlen (name
) + 3; /* Two for '"'s. One for NULL. */
889 namep
= XNEWVEC (char, len
);
890 snprintf (namep
, len
, "\"%s\"", name
);
891 strname
.text
= (unsigned char *) namep
;
892 strname
.len
= len
- 1;
894 if (cpp_interpret_string (parse_in
, &strname
, 1, &cstr
, CPP_STRING
))
897 return (const char *) cstr
.text
;
903 /* Return the VAR_DECL for a const char array naming the current
904 function. If the VAR_DECL has not yet been created, create it
905 now. RID indicates how it should be formatted and IDENTIFIER_NODE
906 ID is its name (unfortunately C and C++ hold the RID values of
907 keywords in different places, so we can't derive RID from ID in
908 this language independent code. LOC is the location of the
912 fname_decl (location_t loc
, unsigned int rid
, tree id
)
915 tree decl
= NULL_TREE
;
917 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
918 if (fname_vars
[ix
].rid
== rid
)
921 decl
= *fname_vars
[ix
].decl
;
924 /* If a tree is built here, it would normally have the lineno of
925 the current statement. Later this tree will be moved to the
926 beginning of the function and this line number will be wrong.
927 To avoid this problem set the lineno to 0 here; that prevents
928 it from appearing in the RTL. */
930 location_t saved_location
= input_location
;
931 input_location
= UNKNOWN_LOCATION
;
933 stmts
= push_stmt_list ();
934 decl
= (*make_fname_decl
) (loc
, id
, fname_vars
[ix
].pretty
);
935 stmts
= pop_stmt_list (stmts
);
936 if (!IS_EMPTY_STMT (stmts
))
937 saved_function_name_decls
938 = tree_cons (decl
, stmts
, saved_function_name_decls
);
939 *fname_vars
[ix
].decl
= decl
;
940 input_location
= saved_location
;
942 if (!ix
&& !current_function_decl
)
943 pedwarn (loc
, 0, "%qD is not defined outside of function scope", decl
);
948 /* Given a STRING_CST, give it a suitable array-of-chars data type. */
951 fix_string_type (tree value
)
953 int length
= TREE_STRING_LENGTH (value
);
955 tree e_type
, i_type
, a_type
;
957 /* Compute the number of elements, for the array type. */
958 if (TREE_TYPE (value
) == char_array_type_node
|| !TREE_TYPE (value
))
961 e_type
= char_type_node
;
963 else if (TREE_TYPE (value
) == char16_array_type_node
)
965 nchars
= length
/ (TYPE_PRECISION (char16_type_node
) / BITS_PER_UNIT
);
966 e_type
= char16_type_node
;
968 else if (TREE_TYPE (value
) == char32_array_type_node
)
970 nchars
= length
/ (TYPE_PRECISION (char32_type_node
) / BITS_PER_UNIT
);
971 e_type
= char32_type_node
;
975 nchars
= length
/ (TYPE_PRECISION (wchar_type_node
) / BITS_PER_UNIT
);
976 e_type
= wchar_type_node
;
979 /* C89 2.2.4.1, C99 5.2.4.1 (Translation limits). The analogous
980 limit in C++98 Annex B is very large (65536) and is not normative,
981 so we do not diagnose it (warn_overlength_strings is forced off
982 in c_common_post_options). */
983 if (warn_overlength_strings
)
985 const int nchars_max
= flag_isoc99
? 4095 : 509;
986 const int relevant_std
= flag_isoc99
? 99 : 90;
987 if (nchars
- 1 > nchars_max
)
988 /* Translators: The %d after 'ISO C' will be 90 or 99. Do not
989 separate the %d from the 'C'. 'ISO' should not be
990 translated, but it may be moved after 'C%d' in languages
991 where modifiers follow nouns. */
992 pedwarn (input_location
, OPT_Woverlength_strings
,
993 "string length %qd is greater than the length %qd "
994 "ISO C%d compilers are required to support",
995 nchars
- 1, nchars_max
, relevant_std
);
998 /* Create the array type for the string constant. The ISO C++
999 standard says that a string literal has type `const char[N]' or
1000 `const wchar_t[N]'. We use the same logic when invoked as a C
1001 front-end with -Wwrite-strings.
1002 ??? We should change the type of an expression depending on the
1003 state of a warning flag. We should just be warning -- see how
1004 this is handled in the C++ front-end for the deprecated implicit
1005 conversion from string literals to `char*' or `wchar_t*'.
1007 The C++ front end relies on TYPE_MAIN_VARIANT of a cv-qualified
1008 array type being the unqualified version of that type.
1009 Therefore, if we are constructing an array of const char, we must
1010 construct the matching unqualified array type first. The C front
1011 end does not require this, but it does no harm, so we do it
1013 i_type
= build_index_type (size_int (nchars
- 1));
1014 a_type
= build_array_type (e_type
, i_type
);
1015 if (c_dialect_cxx() || warn_write_strings
)
1016 a_type
= c_build_qualified_type (a_type
, TYPE_QUAL_CONST
);
1018 TREE_TYPE (value
) = a_type
;
1019 TREE_CONSTANT (value
) = 1;
1020 TREE_READONLY (value
) = 1;
1021 TREE_STATIC (value
) = 1;
1025 /* If DISABLE is true, stop issuing warnings. This is used when
1026 parsing code that we know will not be executed. This function may
1027 be called multiple times, and works as a stack. */
1030 c_disable_warnings (bool disable
)
1034 ++c_inhibit_evaluation_warnings
;
1035 fold_defer_overflow_warnings ();
1039 /* If ENABLE is true, reenable issuing warnings. */
1042 c_enable_warnings (bool enable
)
1046 --c_inhibit_evaluation_warnings
;
1047 fold_undefer_and_ignore_overflow_warnings ();
1051 /* Fully fold EXPR, an expression that was not folded (beyond integer
1052 constant expressions and null pointer constants) when being built
1053 up. If IN_INIT, this is in a static initializer and certain
1054 changes are made to the folding done. Clear *MAYBE_CONST if
1055 MAYBE_CONST is not NULL and EXPR is definitely not a constant
1056 expression because it contains an evaluated operator (in C99) or an
1057 operator outside of sizeof returning an integer constant (in C90)
1058 not permitted in constant expressions, or because it contains an
1059 evaluated arithmetic overflow. (*MAYBE_CONST should typically be
1060 set to true by callers before calling this function.) Return the
1061 folded expression. Function arguments have already been folded
1062 before calling this function, as have the contents of SAVE_EXPR,
1063 TARGET_EXPR, BIND_EXPR, VA_ARG_EXPR, OBJ_TYPE_REF and
1064 C_MAYBE_CONST_EXPR. */
1067 c_fully_fold (tree expr
, bool in_init
, bool *maybe_const
)
1070 tree eptype
= NULL_TREE
;
1072 bool maybe_const_itself
= true;
1073 location_t loc
= EXPR_LOCATION (expr
);
1075 /* This function is not relevant to C++ because C++ folds while
1076 parsing, and may need changes to be correct for C++ when C++
1077 stops folding while parsing. */
1078 if (c_dialect_cxx ())
1082 maybe_const
= &dummy
;
1083 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
1085 eptype
= TREE_TYPE (expr
);
1086 expr
= TREE_OPERAND (expr
, 0);
1088 ret
= c_fully_fold_internal (expr
, in_init
, maybe_const
,
1089 &maybe_const_itself
);
1091 ret
= fold_convert_loc (loc
, eptype
, ret
);
1092 *maybe_const
&= maybe_const_itself
;
1096 /* Internal helper for c_fully_fold. EXPR and IN_INIT are as for
1097 c_fully_fold. *MAYBE_CONST_OPERANDS is cleared because of operands
1098 not permitted, while *MAYBE_CONST_ITSELF is cleared because of
1099 arithmetic overflow (for C90, *MAYBE_CONST_OPERANDS is carried from
1100 both evaluated and unevaluated subexpressions while
1101 *MAYBE_CONST_ITSELF is carried from only evaluated
1105 c_fully_fold_internal (tree expr
, bool in_init
, bool *maybe_const_operands
,
1106 bool *maybe_const_itself
)
1109 enum tree_code code
= TREE_CODE (expr
);
1110 enum tree_code_class kind
= TREE_CODE_CLASS (code
);
1111 location_t loc
= EXPR_LOCATION (expr
);
1112 tree op0
, op1
, op2
, op3
;
1113 tree orig_op0
, orig_op1
, orig_op2
;
1114 bool op0_const
= true, op1_const
= true, op2_const
= true;
1115 bool op0_const_self
= true, op1_const_self
= true, op2_const_self
= true;
1116 bool nowarning
= TREE_NO_WARNING (expr
);
1119 /* This function is not relevant to C++ because C++ folds while
1120 parsing, and may need changes to be correct for C++ when C++
1121 stops folding while parsing. */
1122 if (c_dialect_cxx ())
1125 /* Constants, declarations, statements, errors, SAVE_EXPRs and
1126 anything else not counted as an expression cannot usefully be
1127 folded further at this point. */
1128 if (!IS_EXPR_CODE_CLASS (kind
)
1129 || kind
== tcc_statement
1130 || code
== SAVE_EXPR
)
1133 /* Operands of variable-length expressions (function calls) have
1134 already been folded, as have __builtin_* function calls, and such
1135 expressions cannot occur in constant expressions. */
1136 if (kind
== tcc_vl_exp
)
1138 *maybe_const_operands
= false;
1143 if (code
== C_MAYBE_CONST_EXPR
)
1145 tree pre
= C_MAYBE_CONST_EXPR_PRE (expr
);
1146 tree inner
= C_MAYBE_CONST_EXPR_EXPR (expr
);
1147 if (C_MAYBE_CONST_EXPR_NON_CONST (expr
))
1148 *maybe_const_operands
= false;
1149 if (C_MAYBE_CONST_EXPR_INT_OPERANDS (expr
))
1150 *maybe_const_itself
= false;
1151 if (pre
&& !in_init
)
1152 ret
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr
), pre
, inner
);
1158 /* Assignment, increment, decrement, function call and comma
1159 operators, and statement expressions, cannot occur in constant
1160 expressions if evaluated / outside of sizeof. (Function calls
1161 were handled above, though VA_ARG_EXPR is treated like a function
1162 call here, and statement expressions are handled through
1163 C_MAYBE_CONST_EXPR to avoid folding inside them.) */
1167 case PREDECREMENT_EXPR
:
1168 case PREINCREMENT_EXPR
:
1169 case POSTDECREMENT_EXPR
:
1170 case POSTINCREMENT_EXPR
:
1172 *maybe_const_operands
= false;
1179 *maybe_const_operands
= false;
1187 /* Fold individual tree codes as appropriate. */
1190 case COMPOUND_LITERAL_EXPR
:
1191 /* Any non-constancy will have been marked in a containing
1192 C_MAYBE_CONST_EXPR; there is no more folding to do here. */
1196 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1197 op1
= TREE_OPERAND (expr
, 1);
1198 op2
= TREE_OPERAND (expr
, 2);
1199 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1200 maybe_const_itself
);
1201 STRIP_TYPE_NOPS (op0
);
1202 if (op0
!= orig_op0
)
1203 ret
= build3 (COMPONENT_REF
, TREE_TYPE (expr
), op0
, op1
, op2
);
1206 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1207 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1212 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1213 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1214 op2
= TREE_OPERAND (expr
, 2);
1215 op3
= TREE_OPERAND (expr
, 3);
1216 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1217 maybe_const_itself
);
1218 STRIP_TYPE_NOPS (op0
);
1219 op1
= c_fully_fold_internal (op1
, in_init
, maybe_const_operands
,
1220 maybe_const_itself
);
1221 STRIP_TYPE_NOPS (op1
);
1222 op1
= decl_constant_value_for_optimization (op1
);
1223 if (op0
!= orig_op0
|| op1
!= orig_op1
)
1224 ret
= build4 (ARRAY_REF
, TREE_TYPE (expr
), op0
, op1
, op2
, op3
);
1227 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1228 TREE_SIDE_EFFECTS (ret
) = TREE_SIDE_EFFECTS (expr
);
1229 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1236 case PREDECREMENT_EXPR
:
1237 case PREINCREMENT_EXPR
:
1238 case POSTDECREMENT_EXPR
:
1239 case POSTINCREMENT_EXPR
:
1243 case POINTER_PLUS_EXPR
:
1244 case TRUNC_DIV_EXPR
:
1246 case FLOOR_DIV_EXPR
:
1247 case TRUNC_MOD_EXPR
:
1249 case EXACT_DIV_EXPR
:
1262 case TRUTH_AND_EXPR
:
1264 case TRUTH_XOR_EXPR
:
1265 case UNORDERED_EXPR
:
1272 /* Binary operations evaluating both arguments (increment and
1273 decrement are binary internally in GCC). */
1274 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1275 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1276 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1277 maybe_const_itself
);
1278 STRIP_TYPE_NOPS (op0
);
1279 if (code
!= MODIFY_EXPR
1280 && code
!= PREDECREMENT_EXPR
1281 && code
!= PREINCREMENT_EXPR
1282 && code
!= POSTDECREMENT_EXPR
1283 && code
!= POSTINCREMENT_EXPR
)
1284 op0
= decl_constant_value_for_optimization (op0
);
1285 /* The RHS of a MODIFY_EXPR was fully folded when building that
1286 expression for the sake of conversion warnings. */
1287 if (code
!= MODIFY_EXPR
)
1288 op1
= c_fully_fold_internal (op1
, in_init
, maybe_const_operands
,
1289 maybe_const_itself
);
1290 STRIP_TYPE_NOPS (op1
);
1291 op1
= decl_constant_value_for_optimization (op1
);
1292 if (op0
!= orig_op0
|| op1
!= orig_op1
|| in_init
)
1294 ? fold_build2_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
)
1295 : fold_build2_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
);
1298 if (TREE_OVERFLOW_P (ret
)
1299 && !TREE_OVERFLOW_P (op0
)
1300 && !TREE_OVERFLOW_P (op1
))
1301 overflow_warning (EXPR_LOCATION (expr
), ret
);
1302 if ((code
== LSHIFT_EXPR
|| code
== RSHIFT_EXPR
)
1303 && TREE_CODE (orig_op1
) != INTEGER_CST
1304 && TREE_CODE (op1
) == INTEGER_CST
1305 && (TREE_CODE (TREE_TYPE (orig_op0
)) == INTEGER_TYPE
1306 || TREE_CODE (TREE_TYPE (orig_op0
)) == FIXED_POINT_TYPE
)
1307 && TREE_CODE (TREE_TYPE (orig_op1
)) == INTEGER_TYPE
1308 && c_inhibit_evaluation_warnings
== 0)
1310 if (tree_int_cst_sgn (op1
) < 0)
1311 warning_at (loc
, 0, (code
== LSHIFT_EXPR
1312 ? G_("left shift count is negative")
1313 : G_("right shift count is negative")));
1314 else if (compare_tree_int (op1
,
1315 TYPE_PRECISION (TREE_TYPE (orig_op0
)))
1317 warning_at (loc
, 0, (code
== LSHIFT_EXPR
1318 ? G_("left shift count >= width of type")
1319 : G_("right shift count >= width of type")));
1324 case FIX_TRUNC_EXPR
:
1327 case VIEW_CONVERT_EXPR
:
1328 case NON_LVALUE_EXPR
:
1331 case TRUTH_NOT_EXPR
:
1336 /* Unary operations. */
1337 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1338 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1339 maybe_const_itself
);
1340 STRIP_TYPE_NOPS (op0
);
1341 if (code
!= ADDR_EXPR
&& code
!= REALPART_EXPR
&& code
!= IMAGPART_EXPR
)
1342 op0
= decl_constant_value_for_optimization (op0
);
1343 /* ??? Cope with user tricks that amount to offsetof. The middle-end is
1344 not prepared to deal with them if they occur in initializers. */
1346 && code
== ADDR_EXPR
1347 && (op1
= get_base_address (op0
)) != NULL_TREE
1348 && TREE_CODE (op1
) == INDIRECT_REF
1349 && TREE_CONSTANT (TREE_OPERAND (op1
, 0)))
1350 ret
= fold_convert_loc (loc
, TREE_TYPE (expr
), fold_offsetof_1 (op0
));
1351 else if (op0
!= orig_op0
|| in_init
)
1353 ? fold_build1_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
)
1354 : fold_build1_loc (loc
, code
, TREE_TYPE (expr
), op0
);
1357 if (code
== INDIRECT_REF
1359 && TREE_CODE (ret
) == INDIRECT_REF
)
1361 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1362 TREE_SIDE_EFFECTS (ret
) = TREE_SIDE_EFFECTS (expr
);
1363 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1367 case FIX_TRUNC_EXPR
:
1370 /* Don't warn about explicit conversions. We will already
1371 have warned about suspect implicit conversions. */
1375 if (TREE_OVERFLOW_P (ret
) && !TREE_OVERFLOW_P (op0
))
1376 overflow_warning (EXPR_LOCATION (expr
), ret
);
1381 case TRUTH_ANDIF_EXPR
:
1382 case TRUTH_ORIF_EXPR
:
1383 /* Binary operations not necessarily evaluating both
1385 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1386 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1387 op0
= c_fully_fold_internal (op0
, in_init
, &op0_const
, &op0_const_self
);
1388 STRIP_TYPE_NOPS (op0
);
1390 unused_p
= (op0
== (code
== TRUTH_ANDIF_EXPR
1391 ? truthvalue_false_node
1392 : truthvalue_true_node
));
1393 c_disable_warnings (unused_p
);
1394 op1
= c_fully_fold_internal (op1
, in_init
, &op1_const
, &op1_const_self
);
1395 STRIP_TYPE_NOPS (op1
);
1396 c_enable_warnings (unused_p
);
1398 if (op0
!= orig_op0
|| op1
!= orig_op1
|| in_init
)
1400 ? fold_build2_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
)
1401 : fold_build2_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
);
1404 *maybe_const_operands
&= op0_const
;
1405 *maybe_const_itself
&= op0_const_self
;
1409 && (code
== TRUTH_ANDIF_EXPR
1410 ? op0
== truthvalue_false_node
1411 : op0
== truthvalue_true_node
)))
1412 *maybe_const_operands
&= op1_const
;
1415 && (code
== TRUTH_ANDIF_EXPR
1416 ? op0
== truthvalue_false_node
1417 : op0
== truthvalue_true_node
)))
1418 *maybe_const_itself
&= op1_const_self
;
1422 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1423 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1424 orig_op2
= op2
= TREE_OPERAND (expr
, 2);
1425 op0
= c_fully_fold_internal (op0
, in_init
, &op0_const
, &op0_const_self
);
1427 STRIP_TYPE_NOPS (op0
);
1428 c_disable_warnings (op0
== truthvalue_false_node
);
1429 op1
= c_fully_fold_internal (op1
, in_init
, &op1_const
, &op1_const_self
);
1430 STRIP_TYPE_NOPS (op1
);
1431 c_enable_warnings (op0
== truthvalue_false_node
);
1433 c_disable_warnings (op0
== truthvalue_true_node
);
1434 op2
= c_fully_fold_internal (op2
, in_init
, &op2_const
, &op2_const_self
);
1435 STRIP_TYPE_NOPS (op2
);
1436 c_enable_warnings (op0
== truthvalue_true_node
);
1438 if (op0
!= orig_op0
|| op1
!= orig_op1
|| op2
!= orig_op2
)
1439 ret
= fold_build3_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
, op2
);
1442 *maybe_const_operands
&= op0_const
;
1443 *maybe_const_itself
&= op0_const_self
;
1447 && op0
== truthvalue_false_node
))
1448 *maybe_const_operands
&= op1_const
;
1451 && op0
== truthvalue_false_node
))
1452 *maybe_const_itself
&= op1_const_self
;
1456 && op0
== truthvalue_true_node
))
1457 *maybe_const_operands
&= op2_const
;
1460 && op0
== truthvalue_true_node
))
1461 *maybe_const_itself
&= op2_const_self
;
1464 case EXCESS_PRECISION_EXPR
:
1465 /* Each case where an operand with excess precision may be
1466 encountered must remove the EXCESS_PRECISION_EXPR around
1467 inner operands and possibly put one around the whole
1468 expression or possibly convert to the semantic type (which
1469 c_fully_fold does); we cannot tell at this stage which is
1470 appropriate in any particular case. */
1474 /* Various codes may appear through folding built-in functions
1475 and their arguments. */
1480 /* Some folding may introduce NON_LVALUE_EXPRs; all lvalue checks
1481 have been done by this point, so remove them again. */
1482 nowarning
|= TREE_NO_WARNING (ret
);
1483 STRIP_TYPE_NOPS (ret
);
1484 if (nowarning
&& !TREE_NO_WARNING (ret
))
1486 if (!CAN_HAVE_LOCATION_P (ret
))
1487 ret
= build1 (NOP_EXPR
, TREE_TYPE (ret
), ret
);
1488 TREE_NO_WARNING (ret
) = 1;
1491 protected_set_expr_location (ret
, loc
);
1495 /* If not optimizing, EXP is not a VAR_DECL, or EXP has array type,
1496 return EXP. Otherwise, return either EXP or its known constant
1497 value (if it has one), but return EXP if EXP has mode BLKmode. ???
1498 Is the BLKmode test appropriate? */
1501 decl_constant_value_for_optimization (tree exp
)
1505 /* This function is only used by C, for c_fully_fold and other
1506 optimization, and may not be correct for C++. */
1507 if (c_dialect_cxx ())
1511 || TREE_CODE (exp
) != VAR_DECL
1512 || TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
1513 || DECL_MODE (exp
) == BLKmode
)
1516 ret
= decl_constant_value (exp
);
1517 /* Avoid unwanted tree sharing between the initializer and current
1518 function's body where the tree can be modified e.g. by the
1520 if (ret
!= exp
&& TREE_STATIC (exp
))
1521 ret
= unshare_expr (ret
);
1525 /* Print a warning if a constant expression had overflow in folding.
1526 Invoke this function on every expression that the language
1527 requires to be a constant expression.
1528 Note the ANSI C standard says it is erroneous for a
1529 constant expression to overflow. */
1532 constant_expression_warning (tree value
)
1534 if (warn_overflow
&& pedantic
1535 && (TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1536 || TREE_CODE (value
) == FIXED_CST
1537 || TREE_CODE (value
) == VECTOR_CST
1538 || TREE_CODE (value
) == COMPLEX_CST
)
1539 && TREE_OVERFLOW (value
))
1540 pedwarn (input_location
, OPT_Woverflow
, "overflow in constant expression");
1543 /* The same as above but print an unconditional error. */
1545 constant_expression_error (tree value
)
1547 if ((TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1548 || TREE_CODE (value
) == FIXED_CST
1549 || TREE_CODE (value
) == VECTOR_CST
1550 || TREE_CODE (value
) == COMPLEX_CST
)
1551 && TREE_OVERFLOW (value
))
1552 error ("overflow in constant expression");
1555 /* Print a warning if an expression had overflow in folding and its
1558 Invoke this function on every expression that
1559 (1) appears in the source code, and
1560 (2) is a constant expression that overflowed, and
1561 (3) is not already checked by convert_and_check;
1562 however, do not invoke this function on operands of explicit casts
1563 or when the expression is the result of an operator and any operand
1564 already overflowed. */
1567 overflow_warning (location_t loc
, tree value
)
1569 if (c_inhibit_evaluation_warnings
!= 0)
1572 switch (TREE_CODE (value
))
1575 warning_at (loc
, OPT_Woverflow
, "integer overflow in expression");
1579 warning_at (loc
, OPT_Woverflow
,
1580 "floating point overflow in expression");
1584 warning_at (loc
, OPT_Woverflow
, "fixed-point overflow in expression");
1588 warning_at (loc
, OPT_Woverflow
, "vector overflow in expression");
1592 if (TREE_CODE (TREE_REALPART (value
)) == INTEGER_CST
)
1593 warning_at (loc
, OPT_Woverflow
,
1594 "complex integer overflow in expression");
1595 else if (TREE_CODE (TREE_REALPART (value
)) == REAL_CST
)
1596 warning_at (loc
, OPT_Woverflow
,
1597 "complex floating point overflow in expression");
1605 /* Warn about uses of logical || / && operator in a context where it
1606 is likely that the bitwise equivalent was intended by the
1607 programmer. We have seen an expression in which CODE is a binary
1608 operator used to combine expressions OP_LEFT and OP_RIGHT, which before folding
1609 had CODE_LEFT and CODE_RIGHT, into an expression of type TYPE. */
1611 warn_logical_operator (location_t location
, enum tree_code code
, tree type
,
1612 enum tree_code code_left
, tree op_left
,
1613 enum tree_code
ARG_UNUSED (code_right
), tree op_right
)
1615 int or_op
= (code
== TRUTH_ORIF_EXPR
|| code
== TRUTH_OR_EXPR
);
1616 int in0_p
, in1_p
, in_p
;
1617 tree low0
, low1
, low
, high0
, high1
, high
, lhs
, rhs
, tem
;
1618 bool strict_overflow_p
= false;
1620 if (code
!= TRUTH_ANDIF_EXPR
1621 && code
!= TRUTH_AND_EXPR
1622 && code
!= TRUTH_ORIF_EXPR
1623 && code
!= TRUTH_OR_EXPR
)
1626 /* Warn if &&/|| are being used in a context where it is
1627 likely that the bitwise equivalent was intended by the
1628 programmer. That is, an expression such as op && MASK
1629 where op should not be any boolean expression, nor a
1630 constant, and mask seems to be a non-boolean integer constant. */
1631 if (!truth_value_p (code_left
)
1632 && INTEGRAL_TYPE_P (TREE_TYPE (op_left
))
1633 && !CONSTANT_CLASS_P (op_left
)
1634 && !TREE_NO_WARNING (op_left
)
1635 && TREE_CODE (op_right
) == INTEGER_CST
1636 && !integer_zerop (op_right
)
1637 && !integer_onep (op_right
))
1640 warning_at (location
, OPT_Wlogical_op
, "logical %<or%>"
1641 " applied to non-boolean constant");
1643 warning_at (location
, OPT_Wlogical_op
, "logical %<and%>"
1644 " applied to non-boolean constant");
1645 TREE_NO_WARNING (op_left
) = true;
1649 /* We do not warn for constants because they are typical of macro
1650 expansions that test for features. */
1651 if (CONSTANT_CLASS_P (op_left
) || CONSTANT_CLASS_P (op_right
))
1654 /* This warning only makes sense with logical operands. */
1655 if (!(truth_value_p (TREE_CODE (op_left
))
1656 || INTEGRAL_TYPE_P (TREE_TYPE (op_left
)))
1657 || !(truth_value_p (TREE_CODE (op_right
))
1658 || INTEGRAL_TYPE_P (TREE_TYPE (op_right
))))
1662 /* We first test whether either side separately is trivially true
1663 (with OR) or trivially false (with AND). If so, do not warn.
1664 This is a common idiom for testing ranges of data types in
1666 lhs
= make_range (op_left
, &in0_p
, &low0
, &high0
, &strict_overflow_p
);
1669 if (TREE_CODE (lhs
) == C_MAYBE_CONST_EXPR
)
1670 lhs
= C_MAYBE_CONST_EXPR_EXPR (lhs
);
1672 /* If this is an OR operation, invert both sides; now, the result
1673 should be always false to get a warning. */
1677 tem
= build_range_check (UNKNOWN_LOCATION
, type
, lhs
, in0_p
, low0
, high0
);
1678 if (tem
&& integer_zerop (tem
))
1681 rhs
= make_range (op_right
, &in1_p
, &low1
, &high1
, &strict_overflow_p
);
1684 if (TREE_CODE (rhs
) == C_MAYBE_CONST_EXPR
)
1685 rhs
= C_MAYBE_CONST_EXPR_EXPR (rhs
);
1687 /* If this is an OR operation, invert both sides; now, the result
1688 should be always false to get a warning. */
1692 tem
= build_range_check (UNKNOWN_LOCATION
, type
, rhs
, in1_p
, low1
, high1
);
1693 if (tem
&& integer_zerop (tem
))
1696 /* If both expressions have the same operand, if we can merge the
1697 ranges, and if the range test is always false, then warn. */
1698 if (operand_equal_p (lhs
, rhs
, 0)
1699 && merge_ranges (&in_p
, &low
, &high
, in0_p
, low0
, high0
,
1701 && 0 != (tem
= build_range_check (UNKNOWN_LOCATION
,
1702 type
, lhs
, in_p
, low
, high
))
1703 && integer_zerop (tem
))
1706 warning_at (location
, OPT_Wlogical_op
,
1708 "of collectively exhaustive tests is always true");
1710 warning_at (location
, OPT_Wlogical_op
,
1712 "of mutually exclusive tests is always false");
1717 /* Warn if EXP contains any computations whose results are not used.
1718 Return true if a warning is printed; false otherwise. LOCUS is the
1719 (potential) location of the expression. */
1722 warn_if_unused_value (const_tree exp
, location_t locus
)
1725 if (TREE_USED (exp
) || TREE_NO_WARNING (exp
))
1728 /* Don't warn about void constructs. This includes casting to void,
1729 void function calls, and statement expressions with a final cast
1731 if (VOID_TYPE_P (TREE_TYPE (exp
)))
1734 if (EXPR_HAS_LOCATION (exp
))
1735 locus
= EXPR_LOCATION (exp
);
1737 switch (TREE_CODE (exp
))
1739 case PREINCREMENT_EXPR
:
1740 case POSTINCREMENT_EXPR
:
1741 case PREDECREMENT_EXPR
:
1742 case POSTDECREMENT_EXPR
:
1747 case TRY_CATCH_EXPR
:
1748 case WITH_CLEANUP_EXPR
:
1754 /* For a binding, warn if no side effect within it. */
1755 exp
= BIND_EXPR_BODY (exp
);
1759 case NON_LVALUE_EXPR
:
1761 exp
= TREE_OPERAND (exp
, 0);
1764 case TRUTH_ORIF_EXPR
:
1765 case TRUTH_ANDIF_EXPR
:
1766 /* In && or ||, warn if 2nd operand has no side effect. */
1767 exp
= TREE_OPERAND (exp
, 1);
1771 if (warn_if_unused_value (TREE_OPERAND (exp
, 0), locus
))
1773 /* Let people do `(foo (), 0)' without a warning. */
1774 if (TREE_CONSTANT (TREE_OPERAND (exp
, 1)))
1776 exp
= TREE_OPERAND (exp
, 1);
1780 /* If this is an expression with side effects, don't warn; this
1781 case commonly appears in macro expansions. */
1782 if (TREE_SIDE_EFFECTS (exp
))
1787 /* Don't warn about automatic dereferencing of references, since
1788 the user cannot control it. */
1789 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == REFERENCE_TYPE
)
1791 exp
= TREE_OPERAND (exp
, 0);
1797 /* Referencing a volatile value is a side effect, so don't warn. */
1798 if ((DECL_P (exp
) || REFERENCE_CLASS_P (exp
))
1799 && TREE_THIS_VOLATILE (exp
))
1802 /* If this is an expression which has no operands, there is no value
1803 to be unused. There are no such language-independent codes,
1804 but front ends may define such. */
1805 if (EXPRESSION_CLASS_P (exp
) && TREE_OPERAND_LENGTH (exp
) == 0)
1809 return warning_at (locus
, OPT_Wunused_value
, "value computed is not used");
1814 /* Print a warning about casts that might indicate violation
1815 of strict aliasing rules if -Wstrict-aliasing is used and
1816 strict aliasing mode is in effect. OTYPE is the original
1817 TREE_TYPE of EXPR, and TYPE the type we're casting to. */
1820 strict_aliasing_warning (tree otype
, tree type
, tree expr
)
1822 /* Strip pointer conversion chains and get to the correct original type. */
1824 otype
= TREE_TYPE (expr
);
1826 if (!(flag_strict_aliasing
1827 && POINTER_TYPE_P (type
)
1828 && POINTER_TYPE_P (otype
)
1829 && !VOID_TYPE_P (TREE_TYPE (type
)))
1830 /* If the type we are casting to is a ref-all pointer
1831 dereferencing it is always valid. */
1832 || TYPE_REF_CAN_ALIAS_ALL (type
))
1835 if ((warn_strict_aliasing
> 1) && TREE_CODE (expr
) == ADDR_EXPR
1836 && (DECL_P (TREE_OPERAND (expr
, 0))
1837 || handled_component_p (TREE_OPERAND (expr
, 0))))
1839 /* Casting the address of an object to non void pointer. Warn
1840 if the cast breaks type based aliasing. */
1841 if (!COMPLETE_TYPE_P (TREE_TYPE (type
)) && warn_strict_aliasing
== 2)
1843 warning (OPT_Wstrict_aliasing
, "type-punning to incomplete type "
1844 "might break strict-aliasing rules");
1849 /* warn_strict_aliasing >= 3. This includes the default (3).
1850 Only warn if the cast is dereferenced immediately. */
1851 alias_set_type set1
=
1852 get_alias_set (TREE_TYPE (TREE_OPERAND (expr
, 0)));
1853 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
1855 if (set1
!= set2
&& set2
!= 0
1856 && (set1
== 0 || !alias_sets_conflict_p (set1
, set2
)))
1858 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1859 "pointer will break strict-aliasing rules");
1862 else if (warn_strict_aliasing
== 2
1863 && !alias_sets_must_conflict_p (set1
, set2
))
1865 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1866 "pointer might break strict-aliasing rules");
1872 if ((warn_strict_aliasing
== 1) && !VOID_TYPE_P (TREE_TYPE (otype
)))
1874 /* At this level, warn for any conversions, even if an address is
1875 not taken in the same statement. This will likely produce many
1876 false positives, but could be useful to pinpoint problems that
1877 are not revealed at higher levels. */
1878 alias_set_type set1
= get_alias_set (TREE_TYPE (otype
));
1879 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
1880 if (!COMPLETE_TYPE_P (type
)
1881 || !alias_sets_must_conflict_p (set1
, set2
))
1883 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1884 "pointer might break strict-aliasing rules");
1892 /* Warn about memset (&a, 0, sizeof (&a)); and similar mistakes with
1893 sizeof as last operand of certain builtins. */
1896 sizeof_pointer_memaccess_warning (location_t
*sizeof_arg_loc
, tree callee
,
1897 vec
<tree
, va_gc
> *params
, tree
*sizeof_arg
,
1898 bool (*comp_types
) (tree
, tree
))
1900 tree type
, dest
= NULL_TREE
, src
= NULL_TREE
, tem
;
1901 bool strop
= false, cmp
= false;
1902 unsigned int idx
= ~0;
1905 if (TREE_CODE (callee
) != FUNCTION_DECL
1906 || DECL_BUILT_IN_CLASS (callee
) != BUILT_IN_NORMAL
1907 || vec_safe_length (params
) <= 1)
1910 switch (DECL_FUNCTION_CODE (callee
))
1912 case BUILT_IN_STRNCMP
:
1913 case BUILT_IN_STRNCASECMP
:
1916 case BUILT_IN_STRNCPY
:
1917 case BUILT_IN_STRNCPY_CHK
:
1918 case BUILT_IN_STRNCAT
:
1919 case BUILT_IN_STRNCAT_CHK
:
1920 case BUILT_IN_STPNCPY
:
1921 case BUILT_IN_STPNCPY_CHK
:
1924 case BUILT_IN_MEMCPY
:
1925 case BUILT_IN_MEMCPY_CHK
:
1926 case BUILT_IN_MEMMOVE
:
1927 case BUILT_IN_MEMMOVE_CHK
:
1928 if (params
->length () < 3)
1931 dest
= (*params
)[0];
1934 case BUILT_IN_BCOPY
:
1935 if (params
->length () < 3)
1938 dest
= (*params
)[1];
1941 case BUILT_IN_MEMCMP
:
1943 if (params
->length () < 3)
1946 dest
= (*params
)[0];
1950 case BUILT_IN_MEMSET
:
1951 case BUILT_IN_MEMSET_CHK
:
1952 if (params
->length () < 3)
1954 dest
= (*params
)[0];
1957 case BUILT_IN_BZERO
:
1958 dest
= (*params
)[0];
1961 case BUILT_IN_STRNDUP
:
1966 case BUILT_IN_MEMCHR
:
1967 if (params
->length () < 3)
1972 case BUILT_IN_SNPRINTF
:
1973 case BUILT_IN_SNPRINTF_CHK
:
1974 case BUILT_IN_VSNPRINTF
:
1975 case BUILT_IN_VSNPRINTF_CHK
:
1976 dest
= (*params
)[0];
1987 if (sizeof_arg
[idx
] == NULL
|| sizeof_arg
[idx
] == error_mark_node
)
1990 type
= TYPE_P (sizeof_arg
[idx
])
1991 ? sizeof_arg
[idx
] : TREE_TYPE (sizeof_arg
[idx
]);
1992 if (!POINTER_TYPE_P (type
))
1996 && (tem
= tree_strip_nop_conversions (dest
))
1997 && POINTER_TYPE_P (TREE_TYPE (tem
))
1998 && comp_types (TREE_TYPE (TREE_TYPE (tem
)), type
))
2002 && (tem
= tree_strip_nop_conversions (src
))
2003 && POINTER_TYPE_P (TREE_TYPE (tem
))
2004 && comp_types (TREE_TYPE (TREE_TYPE (tem
)), type
))
2007 loc
= sizeof_arg_loc
[idx
];
2011 if (!TYPE_P (sizeof_arg
[idx
])
2012 && operand_equal_p (dest
, sizeof_arg
[idx
], 0)
2013 && comp_types (TREE_TYPE (dest
), type
))
2015 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2016 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2017 "argument to %<sizeof%> in %qD call is the same "
2018 "expression as the destination; did you mean to "
2019 "remove the addressof?", callee
);
2020 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2021 == TYPE_PRECISION (char_type_node
))
2023 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2024 "argument to %<sizeof%> in %qD call is the same "
2025 "expression as the destination; did you mean to "
2026 "provide an explicit length?", callee
);
2028 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2029 "argument to %<sizeof%> in %qD call is the same "
2030 "expression as the destination; did you mean to "
2031 "dereference it?", callee
);
2035 if (POINTER_TYPE_P (TREE_TYPE (dest
))
2037 && comp_types (TREE_TYPE (dest
), type
)
2038 && !VOID_TYPE_P (TREE_TYPE (type
)))
2040 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2041 "argument to %<sizeof%> in %qD call is the same "
2042 "pointer type %qT as the destination; expected %qT "
2043 "or an explicit length", callee
, TREE_TYPE (dest
),
2044 TREE_TYPE (TREE_TYPE (dest
)));
2051 if (!TYPE_P (sizeof_arg
[idx
])
2052 && operand_equal_p (src
, sizeof_arg
[idx
], 0)
2053 && comp_types (TREE_TYPE (src
), type
))
2055 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2056 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2057 "argument to %<sizeof%> in %qD call is the same "
2058 "expression as the source; did you mean to "
2059 "remove the addressof?", callee
);
2060 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2061 == TYPE_PRECISION (char_type_node
))
2063 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2064 "argument to %<sizeof%> in %qD call is the same "
2065 "expression as the source; did you mean to "
2066 "provide an explicit length?", callee
);
2068 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2069 "argument to %<sizeof%> in %qD call is the same "
2070 "expression as the source; did you mean to "
2071 "dereference it?", callee
);
2075 if (POINTER_TYPE_P (TREE_TYPE (src
))
2077 && comp_types (TREE_TYPE (src
), type
)
2078 && !VOID_TYPE_P (TREE_TYPE (type
)))
2080 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2081 "argument to %<sizeof%> in %qD call is the same "
2082 "pointer type %qT as the source; expected %qT "
2083 "or an explicit length", callee
, TREE_TYPE (src
),
2084 TREE_TYPE (TREE_TYPE (src
)));
2091 if (!TYPE_P (sizeof_arg
[idx
])
2092 && operand_equal_p (dest
, sizeof_arg
[idx
], 0)
2093 && comp_types (TREE_TYPE (dest
), type
))
2095 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2096 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2097 "argument to %<sizeof%> in %qD call is the same "
2098 "expression as the first source; did you mean to "
2099 "remove the addressof?", callee
);
2100 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2101 == TYPE_PRECISION (char_type_node
))
2103 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2104 "argument to %<sizeof%> in %qD call is the same "
2105 "expression as the first source; did you mean to "
2106 "provide an explicit length?", callee
);
2108 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2109 "argument to %<sizeof%> in %qD call is the same "
2110 "expression as the first source; did you mean to "
2111 "dereference it?", callee
);
2115 if (POINTER_TYPE_P (TREE_TYPE (dest
))
2117 && comp_types (TREE_TYPE (dest
), type
)
2118 && !VOID_TYPE_P (TREE_TYPE (type
)))
2120 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2121 "argument to %<sizeof%> in %qD call is the same "
2122 "pointer type %qT as the first source; expected %qT "
2123 "or an explicit length", callee
, TREE_TYPE (dest
),
2124 TREE_TYPE (TREE_TYPE (dest
)));
2131 if (!TYPE_P (sizeof_arg
[idx
])
2132 && operand_equal_p (src
, sizeof_arg
[idx
], 0)
2133 && comp_types (TREE_TYPE (src
), type
))
2135 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2136 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2137 "argument to %<sizeof%> in %qD call is the same "
2138 "expression as the second source; did you mean to "
2139 "remove the addressof?", callee
);
2140 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2141 == TYPE_PRECISION (char_type_node
))
2143 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2144 "argument to %<sizeof%> in %qD call is the same "
2145 "expression as the second source; did you mean to "
2146 "provide an explicit length?", callee
);
2148 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2149 "argument to %<sizeof%> in %qD call is the same "
2150 "expression as the second source; did you mean to "
2151 "dereference it?", callee
);
2155 if (POINTER_TYPE_P (TREE_TYPE (src
))
2157 && comp_types (TREE_TYPE (src
), type
)
2158 && !VOID_TYPE_P (TREE_TYPE (type
)))
2160 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2161 "argument to %<sizeof%> in %qD call is the same "
2162 "pointer type %qT as the second source; expected %qT "
2163 "or an explicit length", callee
, TREE_TYPE (src
),
2164 TREE_TYPE (TREE_TYPE (src
)));
2171 /* Warn for unlikely, improbable, or stupid DECL declarations
2175 check_main_parameter_types (tree decl
)
2177 function_args_iterator iter
;
2181 FOREACH_FUNCTION_ARGS (TREE_TYPE (decl
), type
, iter
)
2183 /* XXX void_type_node belies the abstraction. */
2184 if (type
== void_type_node
|| type
== error_mark_node
)
2191 if (TYPE_MAIN_VARIANT (type
) != integer_type_node
)
2192 pedwarn (input_location
, OPT_Wmain
,
2193 "first argument of %q+D should be %<int%>", decl
);
2197 if (TREE_CODE (type
) != POINTER_TYPE
2198 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
2199 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
2201 pedwarn (input_location
, OPT_Wmain
,
2202 "second argument of %q+D should be %<char **%>", decl
);
2206 if (TREE_CODE (type
) != POINTER_TYPE
2207 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
2208 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
2210 pedwarn (input_location
, OPT_Wmain
,
2211 "third argument of %q+D should probably be "
2212 "%<char **%>", decl
);
2217 /* It is intentional that this message does not mention the third
2218 argument because it's only mentioned in an appendix of the
2220 if (argct
> 0 && (argct
< 2 || argct
> 3))
2221 pedwarn (input_location
, OPT_Wmain
,
2222 "%q+D takes only zero or two arguments", decl
);
2225 /* vector_targets_convertible_p is used for vector pointer types. The
2226 callers perform various checks that the qualifiers are satisfactory,
2227 while OTOH vector_targets_convertible_p ignores the number of elements
2228 in the vectors. That's fine with vector pointers as we can consider,
2229 say, a vector of 8 elements as two consecutive vectors of 4 elements,
2230 and that does not require and conversion of the pointer values.
2231 In contrast, vector_types_convertible_p and
2232 vector_types_compatible_elements_p are used for vector value types. */
2233 /* True if pointers to distinct types T1 and T2 can be converted to
2234 each other without an explicit cast. Only returns true for opaque
2237 vector_targets_convertible_p (const_tree t1
, const_tree t2
)
2239 if (TREE_CODE (t1
) == VECTOR_TYPE
&& TREE_CODE (t2
) == VECTOR_TYPE
2240 && (TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2241 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2247 /* vector_types_convertible_p is used for vector value types.
2248 It could in principle call vector_targets_convertible_p as a subroutine,
2249 but then the check for vector type would be duplicated with its callers,
2250 and also the purpose of vector_targets_convertible_p would become
2252 Where vector_types_convertible_p returns true, a conversion might still be
2253 needed to make the types match.
2254 In contrast, vector_targets_convertible_p is used for vector pointer
2255 values, and vector_types_compatible_elements_p is used specifically
2256 in the context for binary operators, as a check if use is possible without
2258 /* True if vector types T1 and T2 can be converted to each other
2259 without an explicit cast. If EMIT_LAX_NOTE is true, and T1 and T2
2260 can only be converted with -flax-vector-conversions yet that is not
2261 in effect, emit a note telling the user about that option if such
2262 a note has not previously been emitted. */
2264 vector_types_convertible_p (const_tree t1
, const_tree t2
, bool emit_lax_note
)
2266 static bool emitted_lax_note
= false;
2267 bool convertible_lax
;
2269 if ((TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2270 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2274 (tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
))
2275 && (TREE_CODE (TREE_TYPE (t1
)) != REAL_TYPE
||
2276 TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
))
2277 && (INTEGRAL_TYPE_P (TREE_TYPE (t1
))
2278 == INTEGRAL_TYPE_P (TREE_TYPE (t2
))));
2280 if (!convertible_lax
|| flag_lax_vector_conversions
)
2281 return convertible_lax
;
2283 if (TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
)
2284 && lang_hooks
.types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
2287 if (emit_lax_note
&& !emitted_lax_note
)
2289 emitted_lax_note
= true;
2290 inform (input_location
, "use -flax-vector-conversions to permit "
2291 "conversions between vectors with differing "
2292 "element types or numbers of subparts");
2298 /* Build a VEC_PERM_EXPR if V0, V1 and MASK are not error_mark_nodes
2299 and have vector types, V0 has the same type as V1, and the number of
2300 elements of V0, V1, MASK is the same.
2302 In case V1 is a NULL_TREE it is assumed that __builtin_shuffle was
2303 called with two arguments. In this case implementation passes the
2304 first argument twice in order to share the same tree code. This fact
2305 could enable the mask-values being twice the vector length. This is
2306 an implementation accident and this semantics is not guaranteed to
2309 c_build_vec_perm_expr (location_t loc
, tree v0
, tree v1
, tree mask
,
2314 bool maybe_const
= false;
2315 bool two_arguments
= false;
2317 if (v1
== NULL_TREE
)
2319 two_arguments
= true;
2323 if (v0
== error_mark_node
|| v1
== error_mark_node
2324 || mask
== error_mark_node
)
2325 return error_mark_node
;
2327 if (TREE_CODE (TREE_TYPE (mask
)) != VECTOR_TYPE
2328 || TREE_CODE (TREE_TYPE (TREE_TYPE (mask
))) != INTEGER_TYPE
)
2331 error_at (loc
, "__builtin_shuffle last argument must "
2332 "be an integer vector");
2333 return error_mark_node
;
2336 if (TREE_CODE (TREE_TYPE (v0
)) != VECTOR_TYPE
2337 || TREE_CODE (TREE_TYPE (v1
)) != VECTOR_TYPE
)
2340 error_at (loc
, "__builtin_shuffle arguments must be vectors");
2341 return error_mark_node
;
2344 if (TYPE_MAIN_VARIANT (TREE_TYPE (v0
)) != TYPE_MAIN_VARIANT (TREE_TYPE (v1
)))
2347 error_at (loc
, "__builtin_shuffle argument vectors must be of "
2349 return error_mark_node
;
2352 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (v0
))
2353 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
))
2354 && TYPE_VECTOR_SUBPARTS (TREE_TYPE (v1
))
2355 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
)))
2358 error_at (loc
, "__builtin_shuffle number of elements of the "
2359 "argument vector(s) and the mask vector should "
2361 return error_mark_node
;
2364 if (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (v0
))))
2365 != GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (mask
)))))
2368 error_at (loc
, "__builtin_shuffle argument vector(s) inner type "
2369 "must have the same size as inner type of the mask");
2370 return error_mark_node
;
2373 if (!c_dialect_cxx ())
2375 /* Avoid C_MAYBE_CONST_EXPRs inside VEC_PERM_EXPR. */
2376 v0
= c_fully_fold (v0
, false, &maybe_const
);
2377 wrap
&= maybe_const
;
2380 v1
= v0
= save_expr (v0
);
2383 v1
= c_fully_fold (v1
, false, &maybe_const
);
2384 wrap
&= maybe_const
;
2387 mask
= c_fully_fold (mask
, false, &maybe_const
);
2388 wrap
&= maybe_const
;
2390 else if (two_arguments
)
2391 v1
= v0
= save_expr (v0
);
2393 ret
= build3_loc (loc
, VEC_PERM_EXPR
, TREE_TYPE (v0
), v0
, v1
, mask
);
2395 if (!c_dialect_cxx () && !wrap
)
2396 ret
= c_wrap_maybe_const (ret
, true);
2401 /* Like tree.c:get_narrower, but retain conversion from C++0x scoped enum
2402 to integral type. */
2405 c_common_get_narrower (tree op
, int *unsignedp_ptr
)
2407 op
= get_narrower (op
, unsignedp_ptr
);
2409 if (TREE_CODE (TREE_TYPE (op
)) == ENUMERAL_TYPE
2410 && ENUM_IS_SCOPED (TREE_TYPE (op
)))
2412 /* C++0x scoped enumerations don't implicitly convert to integral
2413 type; if we stripped an explicit conversion to a larger type we
2414 need to replace it so common_type will still work. */
2415 tree type
= c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op
)),
2416 TYPE_UNSIGNED (TREE_TYPE (op
)));
2417 op
= fold_convert (type
, op
);
2422 /* This is a helper function of build_binary_op.
2424 For certain operations if both args were extended from the same
2425 smaller type, do the arithmetic in that type and then extend.
2427 BITWISE indicates a bitwise operation.
2428 For them, this optimization is safe only if
2429 both args are zero-extended or both are sign-extended.
2430 Otherwise, we might change the result.
2431 Eg, (short)-1 | (unsigned short)-1 is (int)-1
2432 but calculated in (unsigned short) it would be (unsigned short)-1.
2435 shorten_binary_op (tree result_type
, tree op0
, tree op1
, bool bitwise
)
2437 int unsigned0
, unsigned1
;
2442 /* Cast OP0 and OP1 to RESULT_TYPE. Doing so prevents
2443 excessive narrowing when we call get_narrower below. For
2444 example, suppose that OP0 is of unsigned int extended
2445 from signed char and that RESULT_TYPE is long long int.
2446 If we explicitly cast OP0 to RESULT_TYPE, OP0 would look
2449 (long long int) (unsigned int) signed_char
2451 which get_narrower would narrow down to
2453 (unsigned int) signed char
2455 If we do not cast OP0 first, get_narrower would return
2456 signed_char, which is inconsistent with the case of the
2458 op0
= convert (result_type
, op0
);
2459 op1
= convert (result_type
, op1
);
2461 arg0
= c_common_get_narrower (op0
, &unsigned0
);
2462 arg1
= c_common_get_narrower (op1
, &unsigned1
);
2464 /* UNS is 1 if the operation to be done is an unsigned one. */
2465 uns
= TYPE_UNSIGNED (result_type
);
2467 /* Handle the case that OP0 (or OP1) does not *contain* a conversion
2468 but it *requires* conversion to FINAL_TYPE. */
2470 if ((TYPE_PRECISION (TREE_TYPE (op0
))
2471 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2472 && TREE_TYPE (op0
) != result_type
)
2473 unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2474 if ((TYPE_PRECISION (TREE_TYPE (op1
))
2475 == TYPE_PRECISION (TREE_TYPE (arg1
)))
2476 && TREE_TYPE (op1
) != result_type
)
2477 unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2479 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
2481 /* For bitwise operations, signedness of nominal type
2482 does not matter. Consider only how operands were extended. */
2486 /* Note that in all three cases below we refrain from optimizing
2487 an unsigned operation on sign-extended args.
2488 That would not be valid. */
2490 /* Both args variable: if both extended in same way
2491 from same width, do it in that width.
2492 Do it unsigned if args were zero-extended. */
2493 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
2494 < TYPE_PRECISION (result_type
))
2495 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2496 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2497 && unsigned0
== unsigned1
2498 && (unsigned0
|| !uns
))
2499 return c_common_signed_or_unsigned_type
2500 (unsigned0
, common_type (TREE_TYPE (arg0
), TREE_TYPE (arg1
)));
2502 else if (TREE_CODE (arg0
) == INTEGER_CST
2503 && (unsigned1
|| !uns
)
2504 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2505 < TYPE_PRECISION (result_type
))
2507 = c_common_signed_or_unsigned_type (unsigned1
,
2509 && !POINTER_TYPE_P (type
)
2510 && int_fits_type_p (arg0
, type
))
2513 else if (TREE_CODE (arg1
) == INTEGER_CST
2514 && (unsigned0
|| !uns
)
2515 && (TYPE_PRECISION (TREE_TYPE (arg0
))
2516 < TYPE_PRECISION (result_type
))
2518 = c_common_signed_or_unsigned_type (unsigned0
,
2520 && !POINTER_TYPE_P (type
)
2521 && int_fits_type_p (arg1
, type
))
2527 /* Checks if expression EXPR of real/integer type cannot be converted
2528 to the real/integer type TYPE. Function returns true when:
2529 * EXPR is a constant which cannot be exactly converted to TYPE
2530 * EXPR is not a constant and size of EXPR's type > than size of TYPE,
2531 for EXPR type and TYPE being both integers or both real.
2532 * EXPR is not a constant of real type and TYPE is an integer.
2533 * EXPR is not a constant of integer type which cannot be
2534 exactly converted to real type.
2535 Function allows conversions between types of different signedness and
2536 does not return true in that case. Function can produce signedness
2537 warnings if PRODUCE_WARNS is true. */
2539 unsafe_conversion_p (tree type
, tree expr
, bool produce_warns
)
2541 bool give_warning
= false;
2542 tree expr_type
= TREE_TYPE (expr
);
2543 location_t loc
= EXPR_LOC_OR_HERE (expr
);
2545 if (TREE_CODE (expr
) == REAL_CST
|| TREE_CODE (expr
) == INTEGER_CST
)
2547 /* Warn for real constant that is not an exact integer converted
2549 if (TREE_CODE (expr_type
) == REAL_TYPE
2550 && TREE_CODE (type
) == INTEGER_TYPE
)
2552 if (!real_isinteger (TREE_REAL_CST_PTR (expr
), TYPE_MODE (expr_type
)))
2553 give_warning
= true;
2555 /* Warn for an integer constant that does not fit into integer type. */
2556 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2557 && TREE_CODE (type
) == INTEGER_TYPE
2558 && !int_fits_type_p (expr
, type
))
2560 if (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)
2561 && tree_int_cst_sgn (expr
) < 0)
2564 warning_at (loc
, OPT_Wsign_conversion
, "negative integer"
2565 " implicitly converted to unsigned type");
2567 else if (!TYPE_UNSIGNED (type
) && TYPE_UNSIGNED (expr_type
))
2570 warning_at (loc
, OPT_Wsign_conversion
, "conversion of unsigned"
2571 " constant value to negative integer");
2574 give_warning
= true;
2576 else if (TREE_CODE (type
) == REAL_TYPE
)
2578 /* Warn for an integer constant that does not fit into real type. */
2579 if (TREE_CODE (expr_type
) == INTEGER_TYPE
)
2581 REAL_VALUE_TYPE a
= real_value_from_int_cst (0, expr
);
2582 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2583 give_warning
= true;
2585 /* Warn for a real constant that does not fit into a smaller
2587 else if (TREE_CODE (expr_type
) == REAL_TYPE
2588 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2590 REAL_VALUE_TYPE a
= TREE_REAL_CST (expr
);
2591 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2592 give_warning
= true;
2598 /* Warn for real types converted to integer types. */
2599 if (TREE_CODE (expr_type
) == REAL_TYPE
2600 && TREE_CODE (type
) == INTEGER_TYPE
)
2601 give_warning
= true;
2603 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2604 && TREE_CODE (type
) == INTEGER_TYPE
)
2606 /* Don't warn about unsigned char y = 0xff, x = (int) y; */
2607 expr
= get_unwidened (expr
, 0);
2608 expr_type
= TREE_TYPE (expr
);
2610 /* Don't warn for short y; short x = ((int)y & 0xff); */
2611 if (TREE_CODE (expr
) == BIT_AND_EXPR
2612 || TREE_CODE (expr
) == BIT_IOR_EXPR
2613 || TREE_CODE (expr
) == BIT_XOR_EXPR
)
2615 /* If both args were extended from a shortest type,
2616 use that type if that is safe. */
2617 expr_type
= shorten_binary_op (expr_type
,
2618 TREE_OPERAND (expr
, 0),
2619 TREE_OPERAND (expr
, 1),
2622 if (TREE_CODE (expr
) == BIT_AND_EXPR
)
2624 tree op0
= TREE_OPERAND (expr
, 0);
2625 tree op1
= TREE_OPERAND (expr
, 1);
2626 bool unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2627 bool unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2629 /* If one of the operands is a non-negative constant
2630 that fits in the target type, then the type of the
2631 other operand does not matter. */
2632 if ((TREE_CODE (op0
) == INTEGER_CST
2633 && int_fits_type_p (op0
, c_common_signed_type (type
))
2634 && int_fits_type_p (op0
, c_common_unsigned_type (type
)))
2635 || (TREE_CODE (op1
) == INTEGER_CST
2636 && int_fits_type_p (op1
, c_common_signed_type (type
))
2637 && int_fits_type_p (op1
,
2638 c_common_unsigned_type (type
))))
2640 /* If constant is unsigned and fits in the target
2641 type, then the result will also fit. */
2642 else if ((TREE_CODE (op0
) == INTEGER_CST
2644 && int_fits_type_p (op0
, type
))
2645 || (TREE_CODE (op1
) == INTEGER_CST
2647 && int_fits_type_p (op1
, type
)))
2651 /* Warn for integer types converted to smaller integer types. */
2652 if (TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2653 give_warning
= true;
2655 /* When they are the same width but different signedness,
2656 then the value may change. */
2657 else if (((TYPE_PRECISION (type
) == TYPE_PRECISION (expr_type
)
2658 && TYPE_UNSIGNED (expr_type
) != TYPE_UNSIGNED (type
))
2659 /* Even when converted to a bigger type, if the type is
2660 unsigned but expr is signed, then negative values
2662 || (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)))
2664 warning_at (loc
, OPT_Wsign_conversion
, "conversion to %qT from %qT "
2665 "may change the sign of the result",
2669 /* Warn for integer types converted to real types if and only if
2670 all the range of values of the integer type cannot be
2671 represented by the real type. */
2672 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2673 && TREE_CODE (type
) == REAL_TYPE
)
2675 tree type_low_bound
, type_high_bound
;
2676 REAL_VALUE_TYPE real_low_bound
, real_high_bound
;
2678 /* Don't warn about char y = 0xff; float x = (int) y; */
2679 expr
= get_unwidened (expr
, 0);
2680 expr_type
= TREE_TYPE (expr
);
2682 type_low_bound
= TYPE_MIN_VALUE (expr_type
);
2683 type_high_bound
= TYPE_MAX_VALUE (expr_type
);
2684 real_low_bound
= real_value_from_int_cst (0, type_low_bound
);
2685 real_high_bound
= real_value_from_int_cst (0, type_high_bound
);
2687 if (!exact_real_truncate (TYPE_MODE (type
), &real_low_bound
)
2688 || !exact_real_truncate (TYPE_MODE (type
), &real_high_bound
))
2689 give_warning
= true;
2692 /* Warn for real types converted to smaller real types. */
2693 else if (TREE_CODE (expr_type
) == REAL_TYPE
2694 && TREE_CODE (type
) == REAL_TYPE
2695 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2696 give_warning
= true;
2699 return give_warning
;
2702 /* Warns if the conversion of EXPR to TYPE may alter a value.
2703 This is a helper function for warnings_for_convert_and_check. */
2706 conversion_warning (tree type
, tree expr
)
2708 tree expr_type
= TREE_TYPE (expr
);
2709 location_t loc
= EXPR_LOC_OR_HERE (expr
);
2711 if (!warn_conversion
&& !warn_sign_conversion
)
2714 switch (TREE_CODE (expr
))
2722 case TRUTH_ANDIF_EXPR
:
2723 case TRUTH_ORIF_EXPR
:
2724 case TRUTH_AND_EXPR
:
2726 case TRUTH_XOR_EXPR
:
2727 case TRUTH_NOT_EXPR
:
2728 /* Conversion from boolean to a signed:1 bit-field (which only
2729 can hold the values 0 and -1) doesn't lose information - but
2730 it does change the value. */
2731 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
2732 warning_at (loc
, OPT_Wconversion
,
2733 "conversion to %qT from boolean expression", type
);
2738 if (unsafe_conversion_p (type
, expr
, true))
2739 warning_at (loc
, OPT_Wconversion
,
2740 "conversion to %qT alters %qT constant value",
2746 /* In case of COND_EXPR, we do not care about the type of
2747 COND_EXPR, only about the conversion of each operand. */
2748 tree op1
= TREE_OPERAND (expr
, 1);
2749 tree op2
= TREE_OPERAND (expr
, 2);
2751 conversion_warning (type
, op1
);
2752 conversion_warning (type
, op2
);
2756 default: /* 'expr' is not a constant. */
2757 if (unsafe_conversion_p (type
, expr
, true))
2758 warning_at (loc
, OPT_Wconversion
,
2759 "conversion to %qT from %qT may alter its value",
2764 /* Produce warnings after a conversion. RESULT is the result of
2765 converting EXPR to TYPE. This is a helper function for
2766 convert_and_check and cp_convert_and_check. */
2769 warnings_for_convert_and_check (tree type
, tree expr
, tree result
)
2771 location_t loc
= EXPR_LOC_OR_HERE (expr
);
2773 if (TREE_CODE (expr
) == INTEGER_CST
2774 && (TREE_CODE (type
) == INTEGER_TYPE
2775 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2776 && !int_fits_type_p (expr
, type
))
2778 /* Do not diagnose overflow in a constant expression merely
2779 because a conversion overflowed. */
2780 if (TREE_OVERFLOW (result
))
2781 TREE_OVERFLOW (result
) = TREE_OVERFLOW (expr
);
2783 if (TYPE_UNSIGNED (type
))
2785 /* This detects cases like converting -129 or 256 to
2787 if (!int_fits_type_p (expr
, c_common_signed_type (type
)))
2788 warning_at (loc
, OPT_Woverflow
,
2789 "large integer implicitly truncated to unsigned type");
2791 conversion_warning (type
, expr
);
2793 else if (!int_fits_type_p (expr
, c_common_unsigned_type (type
)))
2794 warning (OPT_Woverflow
,
2795 "overflow in implicit constant conversion");
2796 /* No warning for converting 0x80000000 to int. */
2798 && (TREE_CODE (TREE_TYPE (expr
)) != INTEGER_TYPE
2799 || TYPE_PRECISION (TREE_TYPE (expr
))
2800 != TYPE_PRECISION (type
)))
2801 warning_at (loc
, OPT_Woverflow
,
2802 "overflow in implicit constant conversion");
2805 conversion_warning (type
, expr
);
2807 else if ((TREE_CODE (result
) == INTEGER_CST
2808 || TREE_CODE (result
) == FIXED_CST
) && TREE_OVERFLOW (result
))
2809 warning_at (loc
, OPT_Woverflow
,
2810 "overflow in implicit constant conversion");
2812 conversion_warning (type
, expr
);
2816 /* Convert EXPR to TYPE, warning about conversion problems with constants.
2817 Invoke this function on every expression that is converted implicitly,
2818 i.e. because of language rules and not because of an explicit cast. */
2821 convert_and_check (tree type
, tree expr
)
2824 tree expr_for_warning
;
2826 /* Convert from a value with possible excess precision rather than
2827 via the semantic type, but do not warn about values not fitting
2828 exactly in the semantic type. */
2829 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
2831 tree orig_type
= TREE_TYPE (expr
);
2832 expr
= TREE_OPERAND (expr
, 0);
2833 expr_for_warning
= convert (orig_type
, expr
);
2834 if (orig_type
== type
)
2835 return expr_for_warning
;
2838 expr_for_warning
= expr
;
2840 if (TREE_TYPE (expr
) == type
)
2843 result
= convert (type
, expr
);
2845 if (c_inhibit_evaluation_warnings
== 0
2846 && !TREE_OVERFLOW_P (expr
)
2847 && result
!= error_mark_node
)
2848 warnings_for_convert_and_check (type
, expr_for_warning
, result
);
2853 /* A node in a list that describes references to variables (EXPR), which are
2854 either read accesses if WRITER is zero, or write accesses, in which case
2855 WRITER is the parent of EXPR. */
2862 /* Used to implement a cache the results of a call to verify_tree. We only
2863 use this for SAVE_EXPRs. */
2866 struct tlist_cache
*next
;
2867 struct tlist
*cache_before_sp
;
2868 struct tlist
*cache_after_sp
;
2872 /* Obstack to use when allocating tlist structures, and corresponding
2874 static struct obstack tlist_obstack
;
2875 static char *tlist_firstobj
= 0;
2877 /* Keep track of the identifiers we've warned about, so we can avoid duplicate
2879 static struct tlist
*warned_ids
;
2880 /* SAVE_EXPRs need special treatment. We process them only once and then
2881 cache the results. */
2882 static struct tlist_cache
*save_expr_cache
;
2884 static void add_tlist (struct tlist
**, struct tlist
*, tree
, int);
2885 static void merge_tlist (struct tlist
**, struct tlist
*, int);
2886 static void verify_tree (tree
, struct tlist
**, struct tlist
**, tree
);
2887 static int warning_candidate_p (tree
);
2888 static bool candidate_equal_p (const_tree
, const_tree
);
2889 static void warn_for_collisions (struct tlist
*);
2890 static void warn_for_collisions_1 (tree
, tree
, struct tlist
*, int);
2891 static struct tlist
*new_tlist (struct tlist
*, tree
, tree
);
2893 /* Create a new struct tlist and fill in its fields. */
2894 static struct tlist
*
2895 new_tlist (struct tlist
*next
, tree t
, tree writer
)
2898 l
= XOBNEW (&tlist_obstack
, struct tlist
);
2905 /* Add duplicates of the nodes found in ADD to the list *TO. If EXCLUDE_WRITER
2906 is nonnull, we ignore any node we find which has a writer equal to it. */
2909 add_tlist (struct tlist
**to
, struct tlist
*add
, tree exclude_writer
, int copy
)
2913 struct tlist
*next
= add
->next
;
2916 if (!exclude_writer
|| !candidate_equal_p (add
->writer
, exclude_writer
))
2917 *to
= copy
? new_tlist (*to
, add
->expr
, add
->writer
) : add
;
2922 /* Merge the nodes of ADD into TO. This merging process is done so that for
2923 each variable that already exists in TO, no new node is added; however if
2924 there is a write access recorded in ADD, and an occurrence on TO is only
2925 a read access, then the occurrence in TO will be modified to record the
2929 merge_tlist (struct tlist
**to
, struct tlist
*add
, int copy
)
2931 struct tlist
**end
= to
;
2934 end
= &(*end
)->next
;
2940 struct tlist
*next
= add
->next
;
2942 for (tmp2
= *to
; tmp2
; tmp2
= tmp2
->next
)
2943 if (candidate_equal_p (tmp2
->expr
, add
->expr
))
2947 tmp2
->writer
= add
->writer
;
2951 *end
= copy
? add
: new_tlist (NULL
, add
->expr
, add
->writer
);
2952 end
= &(*end
)->next
;
2959 /* WRITTEN is a variable, WRITER is its parent. Warn if any of the variable
2960 references in list LIST conflict with it, excluding reads if ONLY writers
2964 warn_for_collisions_1 (tree written
, tree writer
, struct tlist
*list
,
2969 /* Avoid duplicate warnings. */
2970 for (tmp
= warned_ids
; tmp
; tmp
= tmp
->next
)
2971 if (candidate_equal_p (tmp
->expr
, written
))
2976 if (candidate_equal_p (list
->expr
, written
)
2977 && !candidate_equal_p (list
->writer
, writer
)
2978 && (!only_writes
|| list
->writer
))
2980 warned_ids
= new_tlist (warned_ids
, written
, NULL_TREE
);
2981 warning_at (EXPR_LOC_OR_HERE (writer
),
2982 OPT_Wsequence_point
, "operation on %qE may be undefined",
2989 /* Given a list LIST of references to variables, find whether any of these
2990 can cause conflicts due to missing sequence points. */
2993 warn_for_collisions (struct tlist
*list
)
2997 for (tmp
= list
; tmp
; tmp
= tmp
->next
)
3000 warn_for_collisions_1 (tmp
->expr
, tmp
->writer
, list
, 0);
3004 /* Return nonzero if X is a tree that can be verified by the sequence point
3007 warning_candidate_p (tree x
)
3009 if (DECL_P (x
) && DECL_ARTIFICIAL (x
))
3012 if (TREE_CODE (x
) == BLOCK
)
3015 /* VOID_TYPE_P (TREE_TYPE (x)) is workaround for cp/tree.c
3016 (lvalue_p) crash on TRY/CATCH. */
3017 if (TREE_TYPE (x
) == NULL_TREE
|| VOID_TYPE_P (TREE_TYPE (x
)))
3023 /* No point to track non-const calls, they will never satisfy
3025 if (TREE_CODE (x
) == CALL_EXPR
&& (call_expr_flags (x
) & ECF_CONST
) == 0)
3028 if (TREE_CODE (x
) == STRING_CST
)
3034 /* Return nonzero if X and Y appear to be the same candidate (or NULL) */
3036 candidate_equal_p (const_tree x
, const_tree y
)
3038 return (x
== y
) || (x
&& y
&& operand_equal_p (x
, y
, 0));
3041 /* Walk the tree X, and record accesses to variables. If X is written by the
3042 parent tree, WRITER is the parent.
3043 We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP. If this
3044 expression or its only operand forces a sequence point, then everything up
3045 to the sequence point is stored in PBEFORE_SP. Everything else gets stored
3047 Once we return, we will have emitted warnings if any subexpression before
3048 such a sequence point could be undefined. On a higher level, however, the
3049 sequence point may not be relevant, and we'll merge the two lists.
3051 Example: (b++, a) + b;
3052 The call that processes the COMPOUND_EXPR will store the increment of B
3053 in PBEFORE_SP, and the use of A in PNO_SP. The higher-level call that
3054 processes the PLUS_EXPR will need to merge the two lists so that
3055 eventually, all accesses end up on the same list (and we'll warn about the
3056 unordered subexpressions b++ and b.
3058 A note on merging. If we modify the former example so that our expression
3061 care must be taken not simply to add all three expressions into the final
3062 PNO_SP list. The function merge_tlist takes care of that by merging the
3063 before-SP list of the COMPOUND_EXPR into its after-SP list in a special
3064 way, so that no more than one access to B is recorded. */
3067 verify_tree (tree x
, struct tlist
**pbefore_sp
, struct tlist
**pno_sp
,
3070 struct tlist
*tmp_before
, *tmp_nosp
, *tmp_list2
, *tmp_list3
;
3071 enum tree_code code
;
3072 enum tree_code_class cl
;
3074 /* X may be NULL if it is the operand of an empty statement expression
3080 code
= TREE_CODE (x
);
3081 cl
= TREE_CODE_CLASS (code
);
3083 if (warning_candidate_p (x
))
3084 *pno_sp
= new_tlist (*pno_sp
, x
, writer
);
3093 case TRUTH_ANDIF_EXPR
:
3094 case TRUTH_ORIF_EXPR
:
3095 tmp_before
= tmp_nosp
= tmp_list3
= 0;
3096 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3097 warn_for_collisions (tmp_nosp
);
3098 merge_tlist (pbefore_sp
, tmp_before
, 0);
3099 merge_tlist (pbefore_sp
, tmp_nosp
, 0);
3100 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, pno_sp
, NULL_TREE
);
3101 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3105 tmp_before
= tmp_list2
= 0;
3106 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_list2
, NULL_TREE
);
3107 warn_for_collisions (tmp_list2
);
3108 merge_tlist (pbefore_sp
, tmp_before
, 0);
3109 merge_tlist (pbefore_sp
, tmp_list2
, 1);
3111 tmp_list3
= tmp_nosp
= 0;
3112 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, &tmp_nosp
, NULL_TREE
);
3113 warn_for_collisions (tmp_nosp
);
3114 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3116 tmp_list3
= tmp_list2
= 0;
3117 verify_tree (TREE_OPERAND (x
, 2), &tmp_list3
, &tmp_list2
, NULL_TREE
);
3118 warn_for_collisions (tmp_list2
);
3119 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3120 /* Rather than add both tmp_nosp and tmp_list2, we have to merge the
3121 two first, to avoid warning for (a ? b++ : b++). */
3122 merge_tlist (&tmp_nosp
, tmp_list2
, 0);
3123 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3126 case PREDECREMENT_EXPR
:
3127 case PREINCREMENT_EXPR
:
3128 case POSTDECREMENT_EXPR
:
3129 case POSTINCREMENT_EXPR
:
3130 verify_tree (TREE_OPERAND (x
, 0), pno_sp
, pno_sp
, x
);
3134 tmp_before
= tmp_nosp
= tmp_list3
= 0;
3135 verify_tree (TREE_OPERAND (x
, 1), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3136 verify_tree (TREE_OPERAND (x
, 0), &tmp_list3
, &tmp_list3
, x
);
3137 /* Expressions inside the LHS are not ordered wrt. the sequence points
3138 in the RHS. Example:
3140 Despite the fact that the modification of "a" is in the before_sp
3141 list (tmp_before), it conflicts with the use of "a" in the LHS.
3142 We can handle this by adding the contents of tmp_list3
3143 to those of tmp_before, and redoing the collision warnings for that
3145 add_tlist (&tmp_before
, tmp_list3
, x
, 1);
3146 warn_for_collisions (tmp_before
);
3147 /* Exclude the LHS itself here; we first have to merge it into the
3148 tmp_nosp list. This is done to avoid warning for "a = a"; if we
3149 didn't exclude the LHS, we'd get it twice, once as a read and once
3151 add_tlist (pno_sp
, tmp_list3
, x
, 0);
3152 warn_for_collisions_1 (TREE_OPERAND (x
, 0), x
, tmp_nosp
, 1);
3154 merge_tlist (pbefore_sp
, tmp_before
, 0);
3155 if (warning_candidate_p (TREE_OPERAND (x
, 0)))
3156 merge_tlist (&tmp_nosp
, new_tlist (NULL
, TREE_OPERAND (x
, 0), x
), 0);
3157 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 1);
3161 /* We need to warn about conflicts among arguments and conflicts between
3162 args and the function address. Side effects of the function address,
3163 however, are not ordered by the sequence point of the call. */
3165 call_expr_arg_iterator iter
;
3167 tmp_before
= tmp_nosp
= 0;
3168 verify_tree (CALL_EXPR_FN (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3169 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, x
)
3171 tmp_list2
= tmp_list3
= 0;
3172 verify_tree (arg
, &tmp_list2
, &tmp_list3
, NULL_TREE
);
3173 merge_tlist (&tmp_list3
, tmp_list2
, 0);
3174 add_tlist (&tmp_before
, tmp_list3
, NULL_TREE
, 0);
3176 add_tlist (&tmp_before
, tmp_nosp
, NULL_TREE
, 0);
3177 warn_for_collisions (tmp_before
);
3178 add_tlist (pbefore_sp
, tmp_before
, NULL_TREE
, 0);
3183 /* Scan all the list, e.g. indices of multi dimensional array. */
3186 tmp_before
= tmp_nosp
= 0;
3187 verify_tree (TREE_VALUE (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3188 merge_tlist (&tmp_nosp
, tmp_before
, 0);
3189 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3196 struct tlist_cache
*t
;
3197 for (t
= save_expr_cache
; t
; t
= t
->next
)
3198 if (candidate_equal_p (t
->expr
, x
))
3203 t
= XOBNEW (&tlist_obstack
, struct tlist_cache
);
3204 t
->next
= save_expr_cache
;
3206 save_expr_cache
= t
;
3208 tmp_before
= tmp_nosp
= 0;
3209 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3210 warn_for_collisions (tmp_nosp
);
3215 struct tlist
*t
= tmp_nosp
;
3217 merge_tlist (&tmp_list3
, t
, 0);
3219 t
->cache_before_sp
= tmp_before
;
3220 t
->cache_after_sp
= tmp_list3
;
3222 merge_tlist (pbefore_sp
, t
->cache_before_sp
, 1);
3223 add_tlist (pno_sp
, t
->cache_after_sp
, NULL_TREE
, 1);
3228 x
= TREE_OPERAND (x
, 0);
3235 /* For other expressions, simply recurse on their operands.
3236 Manual tail recursion for unary expressions.
3237 Other non-expressions need not be processed. */
3238 if (cl
== tcc_unary
)
3240 x
= TREE_OPERAND (x
, 0);
3244 else if (IS_EXPR_CODE_CLASS (cl
))
3247 int max
= TREE_OPERAND_LENGTH (x
);
3248 for (lp
= 0; lp
< max
; lp
++)
3250 tmp_before
= tmp_nosp
= 0;
3251 verify_tree (TREE_OPERAND (x
, lp
), &tmp_before
, &tmp_nosp
, 0);
3252 merge_tlist (&tmp_nosp
, tmp_before
, 0);
3253 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3260 /* Try to warn for undefined behavior in EXPR due to missing sequence
3264 verify_sequence_points (tree expr
)
3266 struct tlist
*before_sp
= 0, *after_sp
= 0;
3269 save_expr_cache
= 0;
3270 if (tlist_firstobj
== 0)
3272 gcc_obstack_init (&tlist_obstack
);
3273 tlist_firstobj
= (char *) obstack_alloc (&tlist_obstack
, 0);
3276 verify_tree (expr
, &before_sp
, &after_sp
, 0);
3277 warn_for_collisions (after_sp
);
3278 obstack_free (&tlist_obstack
, tlist_firstobj
);
3281 /* Validate the expression after `case' and apply default promotions. */
3284 check_case_value (tree value
)
3286 if (value
== NULL_TREE
)
3289 if (TREE_CODE (value
) == INTEGER_CST
)
3290 /* Promote char or short to int. */
3291 value
= perform_integral_promotions (value
);
3292 else if (value
!= error_mark_node
)
3294 error ("case label does not reduce to an integer constant");
3295 value
= error_mark_node
;
3298 constant_expression_warning (value
);
3303 /* See if the case values LOW and HIGH are in the range of the original
3304 type (i.e. before the default conversion to int) of the switch testing
3306 TYPE is the promoted type of the testing expression, and ORIG_TYPE is
3307 the type before promoting it. CASE_LOW_P is a pointer to the lower
3308 bound of the case label, and CASE_HIGH_P is the upper bound or NULL
3309 if the case is not a case range.
3310 The caller has to make sure that we are not called with NULL for
3311 CASE_LOW_P (i.e. the default case).
3312 Returns true if the case label is in range of ORIG_TYPE (saturated or
3313 untouched) or false if the label is out of range. */
3316 check_case_bounds (tree type
, tree orig_type
,
3317 tree
*case_low_p
, tree
*case_high_p
)
3319 tree min_value
, max_value
;
3320 tree case_low
= *case_low_p
;
3321 tree case_high
= case_high_p
? *case_high_p
: case_low
;
3323 /* If there was a problem with the original type, do nothing. */
3324 if (orig_type
== error_mark_node
)
3327 min_value
= TYPE_MIN_VALUE (orig_type
);
3328 max_value
= TYPE_MAX_VALUE (orig_type
);
3330 /* Case label is less than minimum for type. */
3331 if (tree_int_cst_compare (case_low
, min_value
) < 0
3332 && tree_int_cst_compare (case_high
, min_value
) < 0)
3334 warning (0, "case label value is less than minimum value for type");
3338 /* Case value is greater than maximum for type. */
3339 if (tree_int_cst_compare (case_low
, max_value
) > 0
3340 && tree_int_cst_compare (case_high
, max_value
) > 0)
3342 warning (0, "case label value exceeds maximum value for type");
3346 /* Saturate lower case label value to minimum. */
3347 if (tree_int_cst_compare (case_high
, min_value
) >= 0
3348 && tree_int_cst_compare (case_low
, min_value
) < 0)
3350 warning (0, "lower value in case label range"
3351 " less than minimum value for type");
3352 case_low
= min_value
;
3355 /* Saturate upper case label value to maximum. */
3356 if (tree_int_cst_compare (case_low
, max_value
) <= 0
3357 && tree_int_cst_compare (case_high
, max_value
) > 0)
3359 warning (0, "upper value in case label range"
3360 " exceeds maximum value for type");
3361 case_high
= max_value
;
3364 if (*case_low_p
!= case_low
)
3365 *case_low_p
= convert (type
, case_low
);
3366 if (case_high_p
&& *case_high_p
!= case_high
)
3367 *case_high_p
= convert (type
, case_high
);
3372 /* Return an integer type with BITS bits of precision,
3373 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
3376 c_common_type_for_size (unsigned int bits
, int unsignedp
)
3378 if (bits
== TYPE_PRECISION (integer_type_node
))
3379 return unsignedp
? unsigned_type_node
: integer_type_node
;
3381 if (bits
== TYPE_PRECISION (signed_char_type_node
))
3382 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3384 if (bits
== TYPE_PRECISION (short_integer_type_node
))
3385 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3387 if (bits
== TYPE_PRECISION (long_integer_type_node
))
3388 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3390 if (bits
== TYPE_PRECISION (long_long_integer_type_node
))
3391 return (unsignedp
? long_long_unsigned_type_node
3392 : long_long_integer_type_node
);
3394 if (int128_integer_type_node
3395 && bits
== TYPE_PRECISION (int128_integer_type_node
))
3396 return (unsignedp
? int128_unsigned_type_node
3397 : int128_integer_type_node
);
3399 if (bits
== TYPE_PRECISION (widest_integer_literal_type_node
))
3400 return (unsignedp
? widest_unsigned_literal_type_node
3401 : widest_integer_literal_type_node
);
3403 if (bits
<= TYPE_PRECISION (intQI_type_node
))
3404 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3406 if (bits
<= TYPE_PRECISION (intHI_type_node
))
3407 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3409 if (bits
<= TYPE_PRECISION (intSI_type_node
))
3410 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3412 if (bits
<= TYPE_PRECISION (intDI_type_node
))
3413 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3418 /* Return a fixed-point type that has at least IBIT ibits and FBIT fbits
3419 that is unsigned if UNSIGNEDP is nonzero, otherwise signed;
3420 and saturating if SATP is nonzero, otherwise not saturating. */
3423 c_common_fixed_point_type_for_size (unsigned int ibit
, unsigned int fbit
,
3424 int unsignedp
, int satp
)
3426 enum machine_mode mode
;
3428 mode
= unsignedp
? UQQmode
: QQmode
;
3430 mode
= unsignedp
? UHAmode
: HAmode
;
3432 for (; mode
!= VOIDmode
; mode
= GET_MODE_WIDER_MODE (mode
))
3433 if (GET_MODE_IBIT (mode
) >= ibit
&& GET_MODE_FBIT (mode
) >= fbit
)
3436 if (mode
== VOIDmode
|| !targetm
.scalar_mode_supported_p (mode
))
3438 sorry ("GCC cannot support operators with integer types and "
3439 "fixed-point types that have too many integral and "
3440 "fractional bits together");
3444 return c_common_type_for_mode (mode
, satp
);
3447 /* Used for communication between c_common_type_for_mode and
3448 c_register_builtin_type. */
3449 static GTY(()) tree registered_builtin_types
;
3451 /* Return a data type that has machine mode MODE.
3452 If the mode is an integer,
3453 then UNSIGNEDP selects between signed and unsigned types.
3454 If the mode is a fixed-point mode,
3455 then UNSIGNEDP selects between saturating and nonsaturating types. */
3458 c_common_type_for_mode (enum machine_mode mode
, int unsignedp
)
3462 if (mode
== TYPE_MODE (integer_type_node
))
3463 return unsignedp
? unsigned_type_node
: integer_type_node
;
3465 if (mode
== TYPE_MODE (signed_char_type_node
))
3466 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3468 if (mode
== TYPE_MODE (short_integer_type_node
))
3469 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3471 if (mode
== TYPE_MODE (long_integer_type_node
))
3472 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3474 if (mode
== TYPE_MODE (long_long_integer_type_node
))
3475 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3477 if (int128_integer_type_node
3478 && mode
== TYPE_MODE (int128_integer_type_node
))
3479 return unsignedp
? int128_unsigned_type_node
: int128_integer_type_node
;
3481 if (mode
== TYPE_MODE (widest_integer_literal_type_node
))
3482 return unsignedp
? widest_unsigned_literal_type_node
3483 : widest_integer_literal_type_node
;
3486 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3489 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3492 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3495 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3497 #if HOST_BITS_PER_WIDE_INT >= 64
3498 if (mode
== TYPE_MODE (intTI_type_node
))
3499 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3502 if (mode
== TYPE_MODE (float_type_node
))
3503 return float_type_node
;
3505 if (mode
== TYPE_MODE (double_type_node
))
3506 return double_type_node
;
3508 if (mode
== TYPE_MODE (long_double_type_node
))
3509 return long_double_type_node
;
3511 if (mode
== TYPE_MODE (void_type_node
))
3512 return void_type_node
;
3514 if (mode
== TYPE_MODE (build_pointer_type (char_type_node
)))
3516 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3517 : make_signed_type (GET_MODE_PRECISION (mode
)));
3519 if (mode
== TYPE_MODE (build_pointer_type (integer_type_node
)))
3521 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3522 : make_signed_type (GET_MODE_PRECISION (mode
)));
3524 if (COMPLEX_MODE_P (mode
))
3526 enum machine_mode inner_mode
;
3529 if (mode
== TYPE_MODE (complex_float_type_node
))
3530 return complex_float_type_node
;
3531 if (mode
== TYPE_MODE (complex_double_type_node
))
3532 return complex_double_type_node
;
3533 if (mode
== TYPE_MODE (complex_long_double_type_node
))
3534 return complex_long_double_type_node
;
3536 if (mode
== TYPE_MODE (complex_integer_type_node
) && !unsignedp
)
3537 return complex_integer_type_node
;
3539 inner_mode
= GET_MODE_INNER (mode
);
3540 inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3541 if (inner_type
!= NULL_TREE
)
3542 return build_complex_type (inner_type
);
3544 else if (VECTOR_MODE_P (mode
))
3546 enum machine_mode inner_mode
= GET_MODE_INNER (mode
);
3547 tree inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3548 if (inner_type
!= NULL_TREE
)
3549 return build_vector_type_for_mode (inner_type
, mode
);
3552 if (mode
== TYPE_MODE (dfloat32_type_node
))
3553 return dfloat32_type_node
;
3554 if (mode
== TYPE_MODE (dfloat64_type_node
))
3555 return dfloat64_type_node
;
3556 if (mode
== TYPE_MODE (dfloat128_type_node
))
3557 return dfloat128_type_node
;
3559 if (ALL_SCALAR_FIXED_POINT_MODE_P (mode
))
3561 if (mode
== TYPE_MODE (short_fract_type_node
))
3562 return unsignedp
? sat_short_fract_type_node
: short_fract_type_node
;
3563 if (mode
== TYPE_MODE (fract_type_node
))
3564 return unsignedp
? sat_fract_type_node
: fract_type_node
;
3565 if (mode
== TYPE_MODE (long_fract_type_node
))
3566 return unsignedp
? sat_long_fract_type_node
: long_fract_type_node
;
3567 if (mode
== TYPE_MODE (long_long_fract_type_node
))
3568 return unsignedp
? sat_long_long_fract_type_node
3569 : long_long_fract_type_node
;
3571 if (mode
== TYPE_MODE (unsigned_short_fract_type_node
))
3572 return unsignedp
? sat_unsigned_short_fract_type_node
3573 : unsigned_short_fract_type_node
;
3574 if (mode
== TYPE_MODE (unsigned_fract_type_node
))
3575 return unsignedp
? sat_unsigned_fract_type_node
3576 : unsigned_fract_type_node
;
3577 if (mode
== TYPE_MODE (unsigned_long_fract_type_node
))
3578 return unsignedp
? sat_unsigned_long_fract_type_node
3579 : unsigned_long_fract_type_node
;
3580 if (mode
== TYPE_MODE (unsigned_long_long_fract_type_node
))
3581 return unsignedp
? sat_unsigned_long_long_fract_type_node
3582 : unsigned_long_long_fract_type_node
;
3584 if (mode
== TYPE_MODE (short_accum_type_node
))
3585 return unsignedp
? sat_short_accum_type_node
: short_accum_type_node
;
3586 if (mode
== TYPE_MODE (accum_type_node
))
3587 return unsignedp
? sat_accum_type_node
: accum_type_node
;
3588 if (mode
== TYPE_MODE (long_accum_type_node
))
3589 return unsignedp
? sat_long_accum_type_node
: long_accum_type_node
;
3590 if (mode
== TYPE_MODE (long_long_accum_type_node
))
3591 return unsignedp
? sat_long_long_accum_type_node
3592 : long_long_accum_type_node
;
3594 if (mode
== TYPE_MODE (unsigned_short_accum_type_node
))
3595 return unsignedp
? sat_unsigned_short_accum_type_node
3596 : unsigned_short_accum_type_node
;
3597 if (mode
== TYPE_MODE (unsigned_accum_type_node
))
3598 return unsignedp
? sat_unsigned_accum_type_node
3599 : unsigned_accum_type_node
;
3600 if (mode
== TYPE_MODE (unsigned_long_accum_type_node
))
3601 return unsignedp
? sat_unsigned_long_accum_type_node
3602 : unsigned_long_accum_type_node
;
3603 if (mode
== TYPE_MODE (unsigned_long_long_accum_type_node
))
3604 return unsignedp
? sat_unsigned_long_long_accum_type_node
3605 : unsigned_long_long_accum_type_node
;
3608 return unsignedp
? sat_qq_type_node
: qq_type_node
;
3610 return unsignedp
? sat_hq_type_node
: hq_type_node
;
3612 return unsignedp
? sat_sq_type_node
: sq_type_node
;
3614 return unsignedp
? sat_dq_type_node
: dq_type_node
;
3616 return unsignedp
? sat_tq_type_node
: tq_type_node
;
3618 if (mode
== UQQmode
)
3619 return unsignedp
? sat_uqq_type_node
: uqq_type_node
;
3620 if (mode
== UHQmode
)
3621 return unsignedp
? sat_uhq_type_node
: uhq_type_node
;
3622 if (mode
== USQmode
)
3623 return unsignedp
? sat_usq_type_node
: usq_type_node
;
3624 if (mode
== UDQmode
)
3625 return unsignedp
? sat_udq_type_node
: udq_type_node
;
3626 if (mode
== UTQmode
)
3627 return unsignedp
? sat_utq_type_node
: utq_type_node
;
3630 return unsignedp
? sat_ha_type_node
: ha_type_node
;
3632 return unsignedp
? sat_sa_type_node
: sa_type_node
;
3634 return unsignedp
? sat_da_type_node
: da_type_node
;
3636 return unsignedp
? sat_ta_type_node
: ta_type_node
;
3638 if (mode
== UHAmode
)
3639 return unsignedp
? sat_uha_type_node
: uha_type_node
;
3640 if (mode
== USAmode
)
3641 return unsignedp
? sat_usa_type_node
: usa_type_node
;
3642 if (mode
== UDAmode
)
3643 return unsignedp
? sat_uda_type_node
: uda_type_node
;
3644 if (mode
== UTAmode
)
3645 return unsignedp
? sat_uta_type_node
: uta_type_node
;
3648 for (t
= registered_builtin_types
; t
; t
= TREE_CHAIN (t
))
3649 if (TYPE_MODE (TREE_VALUE (t
)) == mode
3650 && !!unsignedp
== !!TYPE_UNSIGNED (TREE_VALUE (t
)))
3651 return TREE_VALUE (t
);
3657 c_common_unsigned_type (tree type
)
3659 return c_common_signed_or_unsigned_type (1, type
);
3662 /* Return a signed type the same as TYPE in other respects. */
3665 c_common_signed_type (tree type
)
3667 return c_common_signed_or_unsigned_type (0, type
);
3670 /* Return a type the same as TYPE except unsigned or
3671 signed according to UNSIGNEDP. */
3674 c_common_signed_or_unsigned_type (int unsignedp
, tree type
)
3678 /* This block of code emulates the behavior of the old
3679 c_common_unsigned_type. In particular, it returns
3680 long_unsigned_type_node if passed a long, even when a int would
3681 have the same size. This is necessary for warnings to work
3682 correctly in archs where sizeof(int) == sizeof(long) */
3684 type1
= TYPE_MAIN_VARIANT (type
);
3685 if (type1
== signed_char_type_node
|| type1
== char_type_node
|| type1
== unsigned_char_type_node
)
3686 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3687 if (type1
== integer_type_node
|| type1
== unsigned_type_node
)
3688 return unsignedp
? unsigned_type_node
: integer_type_node
;
3689 if (type1
== short_integer_type_node
|| type1
== short_unsigned_type_node
)
3690 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3691 if (type1
== long_integer_type_node
|| type1
== long_unsigned_type_node
)
3692 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3693 if (type1
== long_long_integer_type_node
|| type1
== long_long_unsigned_type_node
)
3694 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3695 if (int128_integer_type_node
3696 && (type1
== int128_integer_type_node
3697 || type1
== int128_unsigned_type_node
))
3698 return unsignedp
? int128_unsigned_type_node
: int128_integer_type_node
;
3699 if (type1
== widest_integer_literal_type_node
|| type1
== widest_unsigned_literal_type_node
)
3700 return unsignedp
? widest_unsigned_literal_type_node
: widest_integer_literal_type_node
;
3701 #if HOST_BITS_PER_WIDE_INT >= 64
3702 if (type1
== intTI_type_node
|| type1
== unsigned_intTI_type_node
)
3703 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3705 if (type1
== intDI_type_node
|| type1
== unsigned_intDI_type_node
)
3706 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3707 if (type1
== intSI_type_node
|| type1
== unsigned_intSI_type_node
)
3708 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3709 if (type1
== intHI_type_node
|| type1
== unsigned_intHI_type_node
)
3710 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3711 if (type1
== intQI_type_node
|| type1
== unsigned_intQI_type_node
)
3712 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3714 #define C_COMMON_FIXED_TYPES(NAME) \
3715 if (type1 == short_ ## NAME ## _type_node \
3716 || type1 == unsigned_short_ ## NAME ## _type_node) \
3717 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
3718 : short_ ## NAME ## _type_node; \
3719 if (type1 == NAME ## _type_node \
3720 || type1 == unsigned_ ## NAME ## _type_node) \
3721 return unsignedp ? unsigned_ ## NAME ## _type_node \
3722 : NAME ## _type_node; \
3723 if (type1 == long_ ## NAME ## _type_node \
3724 || type1 == unsigned_long_ ## NAME ## _type_node) \
3725 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
3726 : long_ ## NAME ## _type_node; \
3727 if (type1 == long_long_ ## NAME ## _type_node \
3728 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
3729 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
3730 : long_long_ ## NAME ## _type_node;
3732 #define C_COMMON_FIXED_MODE_TYPES(NAME) \
3733 if (type1 == NAME ## _type_node \
3734 || type1 == u ## NAME ## _type_node) \
3735 return unsignedp ? u ## NAME ## _type_node \
3736 : NAME ## _type_node;
3738 #define C_COMMON_FIXED_TYPES_SAT(NAME) \
3739 if (type1 == sat_ ## short_ ## NAME ## _type_node \
3740 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
3741 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
3742 : sat_ ## short_ ## NAME ## _type_node; \
3743 if (type1 == sat_ ## NAME ## _type_node \
3744 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
3745 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
3746 : sat_ ## NAME ## _type_node; \
3747 if (type1 == sat_ ## long_ ## NAME ## _type_node \
3748 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
3749 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
3750 : sat_ ## long_ ## NAME ## _type_node; \
3751 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
3752 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
3753 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
3754 : sat_ ## long_long_ ## NAME ## _type_node;
3756 #define C_COMMON_FIXED_MODE_TYPES_SAT(NAME) \
3757 if (type1 == sat_ ## NAME ## _type_node \
3758 || type1 == sat_ ## u ## NAME ## _type_node) \
3759 return unsignedp ? sat_ ## u ## NAME ## _type_node \
3760 : sat_ ## NAME ## _type_node;
3762 C_COMMON_FIXED_TYPES (fract
);
3763 C_COMMON_FIXED_TYPES_SAT (fract
);
3764 C_COMMON_FIXED_TYPES (accum
);
3765 C_COMMON_FIXED_TYPES_SAT (accum
);
3767 C_COMMON_FIXED_MODE_TYPES (qq
);
3768 C_COMMON_FIXED_MODE_TYPES (hq
);
3769 C_COMMON_FIXED_MODE_TYPES (sq
);
3770 C_COMMON_FIXED_MODE_TYPES (dq
);
3771 C_COMMON_FIXED_MODE_TYPES (tq
);
3772 C_COMMON_FIXED_MODE_TYPES_SAT (qq
);
3773 C_COMMON_FIXED_MODE_TYPES_SAT (hq
);
3774 C_COMMON_FIXED_MODE_TYPES_SAT (sq
);
3775 C_COMMON_FIXED_MODE_TYPES_SAT (dq
);
3776 C_COMMON_FIXED_MODE_TYPES_SAT (tq
);
3777 C_COMMON_FIXED_MODE_TYPES (ha
);
3778 C_COMMON_FIXED_MODE_TYPES (sa
);
3779 C_COMMON_FIXED_MODE_TYPES (da
);
3780 C_COMMON_FIXED_MODE_TYPES (ta
);
3781 C_COMMON_FIXED_MODE_TYPES_SAT (ha
);
3782 C_COMMON_FIXED_MODE_TYPES_SAT (sa
);
3783 C_COMMON_FIXED_MODE_TYPES_SAT (da
);
3784 C_COMMON_FIXED_MODE_TYPES_SAT (ta
);
3786 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
3787 the precision; they have precision set to match their range, but
3788 may use a wider mode to match an ABI. If we change modes, we may
3789 wind up with bad conversions. For INTEGER_TYPEs in C, must check
3790 the precision as well, so as to yield correct results for
3791 bit-field types. C++ does not have these separate bit-field
3792 types, and producing a signed or unsigned variant of an
3793 ENUMERAL_TYPE may cause other problems as well. */
3795 if (!INTEGRAL_TYPE_P (type
)
3796 || TYPE_UNSIGNED (type
) == unsignedp
)
3799 #define TYPE_OK(node) \
3800 (TYPE_MODE (type) == TYPE_MODE (node) \
3801 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
3802 if (TYPE_OK (signed_char_type_node
))
3803 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3804 if (TYPE_OK (integer_type_node
))
3805 return unsignedp
? unsigned_type_node
: integer_type_node
;
3806 if (TYPE_OK (short_integer_type_node
))
3807 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3808 if (TYPE_OK (long_integer_type_node
))
3809 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3810 if (TYPE_OK (long_long_integer_type_node
))
3811 return (unsignedp
? long_long_unsigned_type_node
3812 : long_long_integer_type_node
);
3813 if (int128_integer_type_node
&& TYPE_OK (int128_integer_type_node
))
3814 return (unsignedp
? int128_unsigned_type_node
3815 : int128_integer_type_node
);
3816 if (TYPE_OK (widest_integer_literal_type_node
))
3817 return (unsignedp
? widest_unsigned_literal_type_node
3818 : widest_integer_literal_type_node
);
3820 #if HOST_BITS_PER_WIDE_INT >= 64
3821 if (TYPE_OK (intTI_type_node
))
3822 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3824 if (TYPE_OK (intDI_type_node
))
3825 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3826 if (TYPE_OK (intSI_type_node
))
3827 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3828 if (TYPE_OK (intHI_type_node
))
3829 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3830 if (TYPE_OK (intQI_type_node
))
3831 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3834 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
3837 /* Build a bit-field integer type for the given WIDTH and UNSIGNEDP. */
3840 c_build_bitfield_integer_type (unsigned HOST_WIDE_INT width
, int unsignedp
)
3842 /* Extended integer types of the same width as a standard type have
3843 lesser rank, so those of the same width as int promote to int or
3844 unsigned int and are valid for printf formats expecting int or
3845 unsigned int. To avoid such special cases, avoid creating
3846 extended integer types for bit-fields if a standard integer type
3848 if (width
== TYPE_PRECISION (integer_type_node
))
3849 return unsignedp
? unsigned_type_node
: integer_type_node
;
3850 if (width
== TYPE_PRECISION (signed_char_type_node
))
3851 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3852 if (width
== TYPE_PRECISION (short_integer_type_node
))
3853 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3854 if (width
== TYPE_PRECISION (long_integer_type_node
))
3855 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3856 if (width
== TYPE_PRECISION (long_long_integer_type_node
))
3857 return (unsignedp
? long_long_unsigned_type_node
3858 : long_long_integer_type_node
);
3859 if (int128_integer_type_node
3860 && width
== TYPE_PRECISION (int128_integer_type_node
))
3861 return (unsignedp
? int128_unsigned_type_node
3862 : int128_integer_type_node
);
3863 return build_nonstandard_integer_type (width
, unsignedp
);
3866 /* The C version of the register_builtin_type langhook. */
3869 c_register_builtin_type (tree type
, const char* name
)
3873 decl
= build_decl (UNKNOWN_LOCATION
,
3874 TYPE_DECL
, get_identifier (name
), type
);
3875 DECL_ARTIFICIAL (decl
) = 1;
3876 if (!TYPE_NAME (type
))
3877 TYPE_NAME (type
) = decl
;
3880 registered_builtin_types
= tree_cons (0, type
, registered_builtin_types
);
3883 /* Print an error message for invalid operands to arith operation
3884 CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
3885 LOCATION is the location of the message. */
3888 binary_op_error (location_t location
, enum tree_code code
,
3889 tree type0
, tree type1
)
3896 opname
= "+"; break;
3898 opname
= "-"; break;
3900 opname
= "*"; break;
3902 opname
= "max"; break;
3904 opname
= "min"; break;
3906 opname
= "=="; break;
3908 opname
= "!="; break;
3910 opname
= "<="; break;
3912 opname
= ">="; break;
3914 opname
= "<"; break;
3916 opname
= ">"; break;
3918 opname
= "<<"; break;
3920 opname
= ">>"; break;
3921 case TRUNC_MOD_EXPR
:
3922 case FLOOR_MOD_EXPR
:
3923 opname
= "%"; break;
3924 case TRUNC_DIV_EXPR
:
3925 case FLOOR_DIV_EXPR
:
3926 opname
= "/"; break;
3928 opname
= "&"; break;
3930 opname
= "|"; break;
3931 case TRUTH_ANDIF_EXPR
:
3932 opname
= "&&"; break;
3933 case TRUTH_ORIF_EXPR
:
3934 opname
= "||"; break;
3936 opname
= "^"; break;
3941 "invalid operands to binary %s (have %qT and %qT)", opname
,
3945 /* Given an expression as a tree, return its original type. Do this
3946 by stripping any conversion that preserves the sign and precision. */
3948 expr_original_type (tree expr
)
3950 STRIP_SIGN_NOPS (expr
);
3951 return TREE_TYPE (expr
);
3954 /* Subroutine of build_binary_op, used for comparison operations.
3955 See if the operands have both been converted from subword integer types
3956 and, if so, perhaps change them both back to their original type.
3957 This function is also responsible for converting the two operands
3958 to the proper common type for comparison.
3960 The arguments of this function are all pointers to local variables
3961 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
3962 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
3964 If this function returns nonzero, it means that the comparison has
3965 a constant value. What this function returns is an expression for
3969 shorten_compare (tree
*op0_ptr
, tree
*op1_ptr
, tree
*restype_ptr
,
3970 enum tree_code
*rescode_ptr
)
3973 tree op0
= *op0_ptr
;
3974 tree op1
= *op1_ptr
;
3975 int unsignedp0
, unsignedp1
;
3977 tree primop0
, primop1
;
3978 enum tree_code code
= *rescode_ptr
;
3979 location_t loc
= EXPR_LOC_OR_HERE (op0
);
3981 /* Throw away any conversions to wider types
3982 already present in the operands. */
3984 primop0
= c_common_get_narrower (op0
, &unsignedp0
);
3985 primop1
= c_common_get_narrower (op1
, &unsignedp1
);
3987 /* If primopN is first sign-extended from primopN's precision to opN's
3988 precision, then zero-extended from opN's precision to
3989 *restype_ptr precision, shortenings might be invalid. */
3990 if (TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (TREE_TYPE (op0
))
3991 && TYPE_PRECISION (TREE_TYPE (op0
)) < TYPE_PRECISION (*restype_ptr
)
3993 && TYPE_UNSIGNED (TREE_TYPE (op0
)))
3995 if (TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (TREE_TYPE (op1
))
3996 && TYPE_PRECISION (TREE_TYPE (op1
)) < TYPE_PRECISION (*restype_ptr
)
3998 && TYPE_UNSIGNED (TREE_TYPE (op1
)))
4001 /* Handle the case that OP0 does not *contain* a conversion
4002 but it *requires* conversion to FINAL_TYPE. */
4004 if (op0
== primop0
&& TREE_TYPE (op0
) != *restype_ptr
)
4005 unsignedp0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
4006 if (op1
== primop1
&& TREE_TYPE (op1
) != *restype_ptr
)
4007 unsignedp1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
4009 /* If one of the operands must be floated, we cannot optimize. */
4010 real1
= TREE_CODE (TREE_TYPE (primop0
)) == REAL_TYPE
;
4011 real2
= TREE_CODE (TREE_TYPE (primop1
)) == REAL_TYPE
;
4013 /* If first arg is constant, swap the args (changing operation
4014 so value is preserved), for canonicalization. Don't do this if
4015 the second arg is 0. */
4017 if (TREE_CONSTANT (primop0
)
4018 && !integer_zerop (primop1
) && !real_zerop (primop1
)
4019 && !fixed_zerop (primop1
))
4022 int temi
= unsignedp0
;
4030 unsignedp0
= unsignedp1
;
4053 *rescode_ptr
= code
;
4056 /* If comparing an integer against a constant more bits wide,
4057 maybe we can deduce a value of 1 or 0 independent of the data.
4058 Or else truncate the constant now
4059 rather than extend the variable at run time.
4061 This is only interesting if the constant is the wider arg.
4062 Also, it is not safe if the constant is unsigned and the
4063 variable arg is signed, since in this case the variable
4064 would be sign-extended and then regarded as unsigned.
4065 Our technique fails in this case because the lowest/highest
4066 possible unsigned results don't follow naturally from the
4067 lowest/highest possible values of the variable operand.
4068 For just EQ_EXPR and NE_EXPR there is another technique that
4069 could be used: see if the constant can be faithfully represented
4070 in the other operand's type, by truncating it and reextending it
4071 and see if that preserves the constant's value. */
4073 if (!real1
&& !real2
4074 && TREE_CODE (TREE_TYPE (primop0
)) != FIXED_POINT_TYPE
4075 && TREE_CODE (primop1
) == INTEGER_CST
4076 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
))
4078 int min_gt
, max_gt
, min_lt
, max_lt
;
4079 tree maxval
, minval
;
4080 /* 1 if comparison is nominally unsigned. */
4081 int unsignedp
= TYPE_UNSIGNED (*restype_ptr
);
4084 type
= c_common_signed_or_unsigned_type (unsignedp0
,
4085 TREE_TYPE (primop0
));
4087 maxval
= TYPE_MAX_VALUE (type
);
4088 minval
= TYPE_MIN_VALUE (type
);
4090 if (unsignedp
&& !unsignedp0
)
4091 *restype_ptr
= c_common_signed_type (*restype_ptr
);
4093 if (TREE_TYPE (primop1
) != *restype_ptr
)
4095 /* Convert primop1 to target type, but do not introduce
4096 additional overflow. We know primop1 is an int_cst. */
4097 primop1
= force_fit_type_double (*restype_ptr
,
4098 tree_to_double_int (primop1
),
4099 0, TREE_OVERFLOW (primop1
));
4101 if (type
!= *restype_ptr
)
4103 minval
= convert (*restype_ptr
, minval
);
4104 maxval
= convert (*restype_ptr
, maxval
);
4107 if (unsignedp
&& unsignedp0
)
4109 min_gt
= INT_CST_LT_UNSIGNED (primop1
, minval
);
4110 max_gt
= INT_CST_LT_UNSIGNED (primop1
, maxval
);
4111 min_lt
= INT_CST_LT_UNSIGNED (minval
, primop1
);
4112 max_lt
= INT_CST_LT_UNSIGNED (maxval
, primop1
);
4116 min_gt
= INT_CST_LT (primop1
, minval
);
4117 max_gt
= INT_CST_LT (primop1
, maxval
);
4118 min_lt
= INT_CST_LT (minval
, primop1
);
4119 max_lt
= INT_CST_LT (maxval
, primop1
);
4123 /* This used to be a switch, but Genix compiler can't handle that. */
4124 if (code
== NE_EXPR
)
4126 if (max_lt
|| min_gt
)
4127 val
= truthvalue_true_node
;
4129 else if (code
== EQ_EXPR
)
4131 if (max_lt
|| min_gt
)
4132 val
= truthvalue_false_node
;
4134 else if (code
== LT_EXPR
)
4137 val
= truthvalue_true_node
;
4139 val
= truthvalue_false_node
;
4141 else if (code
== GT_EXPR
)
4144 val
= truthvalue_true_node
;
4146 val
= truthvalue_false_node
;
4148 else if (code
== LE_EXPR
)
4151 val
= truthvalue_true_node
;
4153 val
= truthvalue_false_node
;
4155 else if (code
== GE_EXPR
)
4158 val
= truthvalue_true_node
;
4160 val
= truthvalue_false_node
;
4163 /* If primop0 was sign-extended and unsigned comparison specd,
4164 we did a signed comparison above using the signed type bounds.
4165 But the comparison we output must be unsigned.
4167 Also, for inequalities, VAL is no good; but if the signed
4168 comparison had *any* fixed result, it follows that the
4169 unsigned comparison just tests the sign in reverse
4170 (positive values are LE, negative ones GE).
4171 So we can generate an unsigned comparison
4172 against an extreme value of the signed type. */
4174 if (unsignedp
&& !unsignedp0
)
4181 primop1
= TYPE_MIN_VALUE (type
);
4187 primop1
= TYPE_MAX_VALUE (type
);
4194 type
= c_common_unsigned_type (type
);
4197 if (TREE_CODE (primop0
) != INTEGER_CST
4198 && c_inhibit_evaluation_warnings
== 0)
4200 if (val
== truthvalue_false_node
)
4201 warning_at (loc
, OPT_Wtype_limits
,
4202 "comparison is always false due to limited range of data type");
4203 if (val
== truthvalue_true_node
)
4204 warning_at (loc
, OPT_Wtype_limits
,
4205 "comparison is always true due to limited range of data type");
4210 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4211 if (TREE_SIDE_EFFECTS (primop0
))
4212 return build2 (COMPOUND_EXPR
, TREE_TYPE (val
), primop0
, val
);
4216 /* Value is not predetermined, but do the comparison
4217 in the type of the operand that is not constant.
4218 TYPE is already properly set. */
4221 /* If either arg is decimal float and the other is float, find the
4222 proper common type to use for comparison. */
4223 else if (real1
&& real2
4224 && (DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0
)))
4225 || DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1
)))))
4226 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
4228 else if (real1
&& real2
4229 && (TYPE_PRECISION (TREE_TYPE (primop0
))
4230 == TYPE_PRECISION (TREE_TYPE (primop1
))))
4231 type
= TREE_TYPE (primop0
);
4233 /* If args' natural types are both narrower than nominal type
4234 and both extend in the same manner, compare them
4235 in the type of the wider arg.
4236 Otherwise must actually extend both to the nominal
4237 common type lest different ways of extending
4239 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
4241 else if (unsignedp0
== unsignedp1
&& real1
== real2
4242 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
)
4243 && TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (*restype_ptr
))
4245 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
4246 type
= c_common_signed_or_unsigned_type (unsignedp0
4247 || TYPE_UNSIGNED (*restype_ptr
),
4249 /* Make sure shorter operand is extended the right way
4250 to match the longer operand. */
4252 = convert (c_common_signed_or_unsigned_type (unsignedp0
,
4253 TREE_TYPE (primop0
)),
4256 = convert (c_common_signed_or_unsigned_type (unsignedp1
,
4257 TREE_TYPE (primop1
)),
4262 /* Here we must do the comparison on the nominal type
4263 using the args exactly as we received them. */
4264 type
= *restype_ptr
;
4268 if (!real1
&& !real2
&& integer_zerop (primop1
)
4269 && TYPE_UNSIGNED (*restype_ptr
))
4272 /* All unsigned values are >= 0, so we warn. However,
4273 if OP0 is a constant that is >= 0, the signedness of
4274 the comparison isn't an issue, so suppress the
4277 warn_type_limits
&& !in_system_header
4278 && c_inhibit_evaluation_warnings
== 0
4279 && !(TREE_CODE (primop0
) == INTEGER_CST
4280 && !TREE_OVERFLOW (convert (c_common_signed_type (type
),
4282 /* Do not warn for enumeration types. */
4283 && (TREE_CODE (expr_original_type (primop0
)) != ENUMERAL_TYPE
);
4289 warning_at (loc
, OPT_Wtype_limits
,
4290 "comparison of unsigned expression >= 0 is always true");
4291 value
= truthvalue_true_node
;
4296 warning_at (loc
, OPT_Wtype_limits
,
4297 "comparison of unsigned expression < 0 is always false");
4298 value
= truthvalue_false_node
;
4307 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4308 if (TREE_SIDE_EFFECTS (primop0
))
4309 return build2 (COMPOUND_EXPR
, TREE_TYPE (value
),
4316 *op0_ptr
= convert (type
, primop0
);
4317 *op1_ptr
= convert (type
, primop1
);
4319 *restype_ptr
= truthvalue_type_node
;
4324 /* Return a tree for the sum or difference (RESULTCODE says which)
4325 of pointer PTROP and integer INTOP. */
4328 pointer_int_sum (location_t loc
, enum tree_code resultcode
,
4329 tree ptrop
, tree intop
, bool complain
)
4333 /* The result is a pointer of the same type that is being added. */
4334 tree result_type
= TREE_TYPE (ptrop
);
4336 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
4338 if (complain
&& warn_pointer_arith
)
4339 pedwarn (loc
, OPT_Wpointer_arith
,
4340 "pointer of type %<void *%> used in arithmetic");
4342 return error_mark_node
;
4343 size_exp
= integer_one_node
;
4345 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
4347 if (complain
&& warn_pointer_arith
)
4348 pedwarn (loc
, OPT_Wpointer_arith
,
4349 "pointer to a function used in arithmetic");
4351 return error_mark_node
;
4352 size_exp
= integer_one_node
;
4355 size_exp
= size_in_bytes (TREE_TYPE (result_type
));
4357 /* We are manipulating pointer values, so we don't need to warn
4358 about relying on undefined signed overflow. We disable the
4359 warning here because we use integer types so fold won't know that
4360 they are really pointers. */
4361 fold_defer_overflow_warnings ();
4363 /* If what we are about to multiply by the size of the elements
4364 contains a constant term, apply distributive law
4365 and multiply that constant term separately.
4366 This helps produce common subexpressions. */
4367 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
4368 && !TREE_CONSTANT (intop
)
4369 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
4370 && TREE_CONSTANT (size_exp
)
4371 /* If the constant comes from pointer subtraction,
4372 skip this optimization--it would cause an error. */
4373 && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop
, 0))) == INTEGER_TYPE
4374 /* If the constant is unsigned, and smaller than the pointer size,
4375 then we must skip this optimization. This is because it could cause
4376 an overflow error if the constant is negative but INTOP is not. */
4377 && (!TYPE_UNSIGNED (TREE_TYPE (intop
))
4378 || (TYPE_PRECISION (TREE_TYPE (intop
))
4379 == TYPE_PRECISION (TREE_TYPE (ptrop
)))))
4381 enum tree_code subcode
= resultcode
;
4382 tree int_type
= TREE_TYPE (intop
);
4383 if (TREE_CODE (intop
) == MINUS_EXPR
)
4384 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
4385 /* Convert both subexpression types to the type of intop,
4386 because weird cases involving pointer arithmetic
4387 can result in a sum or difference with different type args. */
4388 ptrop
= build_binary_op (EXPR_LOCATION (TREE_OPERAND (intop
, 1)),
4390 convert (int_type
, TREE_OPERAND (intop
, 1)), 1);
4391 intop
= convert (int_type
, TREE_OPERAND (intop
, 0));
4394 /* Convert the integer argument to a type the same size as sizetype
4395 so the multiply won't overflow spuriously. */
4396 if (TYPE_PRECISION (TREE_TYPE (intop
)) != TYPE_PRECISION (sizetype
)
4397 || TYPE_UNSIGNED (TREE_TYPE (intop
)) != TYPE_UNSIGNED (sizetype
))
4398 intop
= convert (c_common_type_for_size (TYPE_PRECISION (sizetype
),
4399 TYPE_UNSIGNED (sizetype
)), intop
);
4401 /* Replace the integer argument with a suitable product by the object size.
4402 Do this multiplication as signed, then convert to the appropriate type
4403 for the pointer operation and disregard an overflow that occurred only
4404 because of the sign-extension change in the latter conversion. */
4406 tree t
= build_binary_op (loc
,
4408 convert (TREE_TYPE (intop
), size_exp
), 1);
4409 intop
= convert (sizetype
, t
);
4410 if (TREE_OVERFLOW_P (intop
) && !TREE_OVERFLOW (t
))
4411 intop
= build_int_cst_wide (TREE_TYPE (intop
), TREE_INT_CST_LOW (intop
),
4412 TREE_INT_CST_HIGH (intop
));
4415 /* Create the sum or difference. */
4416 if (resultcode
== MINUS_EXPR
)
4417 intop
= fold_build1_loc (loc
, NEGATE_EXPR
, sizetype
, intop
);
4419 ret
= fold_build_pointer_plus_loc (loc
, ptrop
, intop
);
4421 fold_undefer_and_ignore_overflow_warnings ();
4426 /* Wrap a C_MAYBE_CONST_EXPR around an expression that is fully folded
4427 and if NON_CONST is known not to be permitted in an evaluated part
4428 of a constant expression. */
4431 c_wrap_maybe_const (tree expr
, bool non_const
)
4433 bool nowarning
= TREE_NO_WARNING (expr
);
4434 location_t loc
= EXPR_LOCATION (expr
);
4436 /* This should never be called for C++. */
4437 if (c_dialect_cxx ())
4440 /* The result of folding may have a NOP_EXPR to set TREE_NO_WARNING. */
4441 STRIP_TYPE_NOPS (expr
);
4442 expr
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (expr
), NULL
, expr
);
4443 C_MAYBE_CONST_EXPR_NON_CONST (expr
) = non_const
;
4445 TREE_NO_WARNING (expr
) = 1;
4446 protected_set_expr_location (expr
, loc
);
4451 /* Wrap a SAVE_EXPR around EXPR, if appropriate. Like save_expr, but
4452 for C folds the inside expression and wraps a C_MAYBE_CONST_EXPR
4453 around the SAVE_EXPR if needed so that c_fully_fold does not need
4454 to look inside SAVE_EXPRs. */
4457 c_save_expr (tree expr
)
4459 bool maybe_const
= true;
4460 if (c_dialect_cxx ())
4461 return save_expr (expr
);
4462 expr
= c_fully_fold (expr
, false, &maybe_const
);
4463 expr
= save_expr (expr
);
4465 expr
= c_wrap_maybe_const (expr
, true);
4469 /* Return whether EXPR is a declaration whose address can never be
4473 decl_with_nonnull_addr_p (const_tree expr
)
4475 return (DECL_P (expr
)
4476 && (TREE_CODE (expr
) == PARM_DECL
4477 || TREE_CODE (expr
) == LABEL_DECL
4478 || !DECL_WEAK (expr
)));
4481 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
4482 or for an `if' or `while' statement or ?..: exp. It should already
4483 have been validated to be of suitable type; otherwise, a bad
4484 diagnostic may result.
4486 The EXPR is located at LOCATION.
4488 This preparation consists of taking the ordinary
4489 representation of an expression expr and producing a valid tree
4490 boolean expression describing whether expr is nonzero. We could
4491 simply always do build_binary_op (NE_EXPR, expr, truthvalue_false_node, 1),
4492 but we optimize comparisons, &&, ||, and !.
4494 The resulting type should always be `truthvalue_type_node'. */
4497 c_common_truthvalue_conversion (location_t location
, tree expr
)
4499 switch (TREE_CODE (expr
))
4501 case EQ_EXPR
: case NE_EXPR
: case UNEQ_EXPR
: case LTGT_EXPR
:
4502 case LE_EXPR
: case GE_EXPR
: case LT_EXPR
: case GT_EXPR
:
4503 case UNLE_EXPR
: case UNGE_EXPR
: case UNLT_EXPR
: case UNGT_EXPR
:
4504 case ORDERED_EXPR
: case UNORDERED_EXPR
:
4505 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4507 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4508 TREE_OPERAND (expr
, 0), TREE_OPERAND (expr
, 1));
4511 case TRUTH_ANDIF_EXPR
:
4512 case TRUTH_ORIF_EXPR
:
4513 case TRUTH_AND_EXPR
:
4515 case TRUTH_XOR_EXPR
:
4516 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4518 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4519 c_common_truthvalue_conversion (location
,
4520 TREE_OPERAND (expr
, 0)),
4521 c_common_truthvalue_conversion (location
,
4522 TREE_OPERAND (expr
, 1)));
4525 case TRUTH_NOT_EXPR
:
4526 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4528 expr
= build1 (TREE_CODE (expr
), truthvalue_type_node
,
4529 c_common_truthvalue_conversion (location
,
4530 TREE_OPERAND (expr
, 0)));
4537 return integer_zerop (expr
) ? truthvalue_false_node
4538 : truthvalue_true_node
;
4541 return real_compare (NE_EXPR
, &TREE_REAL_CST (expr
), &dconst0
)
4542 ? truthvalue_true_node
4543 : truthvalue_false_node
;
4546 return fixed_compare (NE_EXPR
, &TREE_FIXED_CST (expr
),
4547 &FCONST0 (TYPE_MODE (TREE_TYPE (expr
))))
4548 ? truthvalue_true_node
4549 : truthvalue_false_node
;
4552 expr
= build_unary_op (location
, ADDR_EXPR
, expr
, 0);
4557 tree inner
= TREE_OPERAND (expr
, 0);
4558 if (decl_with_nonnull_addr_p (inner
))
4560 /* Common Ada/Pascal programmer's mistake. */
4561 warning_at (location
,
4563 "the address of %qD will always evaluate as %<true%>",
4565 return truthvalue_true_node
;
4571 expr
= build_binary_op (EXPR_LOCATION (expr
),
4572 (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1))
4573 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4574 c_common_truthvalue_conversion (location
,
4575 TREE_OPERAND (expr
, 0)),
4576 c_common_truthvalue_conversion (location
,
4577 TREE_OPERAND (expr
, 1)),
4584 case EXCESS_PRECISION_EXPR
:
4585 /* These don't change whether an object is nonzero or zero. */
4586 return c_common_truthvalue_conversion (location
, TREE_OPERAND (expr
, 0));
4590 /* These don't change whether an object is zero or nonzero, but
4591 we can't ignore them if their second arg has side-effects. */
4592 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1)))
4594 expr
= build2 (COMPOUND_EXPR
, truthvalue_type_node
,
4595 TREE_OPERAND (expr
, 1),
4596 c_common_truthvalue_conversion
4597 (location
, TREE_OPERAND (expr
, 0)));
4601 return c_common_truthvalue_conversion (location
,
4602 TREE_OPERAND (expr
, 0));
4605 /* Distribute the conversion into the arms of a COND_EXPR. */
4606 if (c_dialect_cxx ())
4608 tree op1
= TREE_OPERAND (expr
, 1);
4609 tree op2
= TREE_OPERAND (expr
, 2);
4610 /* In C++ one of the arms might have void type if it is throw. */
4611 if (!VOID_TYPE_P (TREE_TYPE (op1
)))
4612 op1
= c_common_truthvalue_conversion (location
, op1
);
4613 if (!VOID_TYPE_P (TREE_TYPE (op2
)))
4614 op2
= c_common_truthvalue_conversion (location
, op2
);
4615 expr
= fold_build3_loc (location
, COND_EXPR
, truthvalue_type_node
,
4616 TREE_OPERAND (expr
, 0), op1
, op2
);
4621 /* Folding will happen later for C. */
4622 expr
= build3 (COND_EXPR
, truthvalue_type_node
,
4623 TREE_OPERAND (expr
, 0),
4624 c_common_truthvalue_conversion (location
,
4625 TREE_OPERAND (expr
, 1)),
4626 c_common_truthvalue_conversion (location
,
4627 TREE_OPERAND (expr
, 2)));
4633 tree totype
= TREE_TYPE (expr
);
4634 tree fromtype
= TREE_TYPE (TREE_OPERAND (expr
, 0));
4636 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
4637 since that affects how `default_conversion' will behave. */
4638 if (TREE_CODE (totype
) == REFERENCE_TYPE
4639 || TREE_CODE (fromtype
) == REFERENCE_TYPE
)
4641 /* Don't strip a conversion from C++0x scoped enum, since they
4642 don't implicitly convert to other types. */
4643 if (TREE_CODE (fromtype
) == ENUMERAL_TYPE
4644 && ENUM_IS_SCOPED (fromtype
))
4646 /* If this isn't narrowing the argument, we can ignore it. */
4647 if (TYPE_PRECISION (totype
) >= TYPE_PRECISION (fromtype
))
4648 return c_common_truthvalue_conversion (location
,
4649 TREE_OPERAND (expr
, 0));
4654 if (!TREE_NO_WARNING (expr
)
4655 && warn_parentheses
)
4657 warning (OPT_Wparentheses
,
4658 "suggest parentheses around assignment used as truth value");
4659 TREE_NO_WARNING (expr
) = 1;
4667 if (TREE_CODE (TREE_TYPE (expr
)) == COMPLEX_TYPE
)
4669 tree t
= (in_late_binary_op
? save_expr (expr
) : c_save_expr (expr
));
4670 expr
= (build_binary_op
4671 (EXPR_LOCATION (expr
),
4672 (TREE_SIDE_EFFECTS (expr
)
4673 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4674 c_common_truthvalue_conversion
4676 build_unary_op (location
, REALPART_EXPR
, t
, 0)),
4677 c_common_truthvalue_conversion
4679 build_unary_op (location
, IMAGPART_EXPR
, t
, 0)),
4684 if (TREE_CODE (TREE_TYPE (expr
)) == FIXED_POINT_TYPE
)
4686 tree fixed_zero_node
= build_fixed (TREE_TYPE (expr
),
4688 (TREE_TYPE (expr
))));
4689 return build_binary_op (location
, NE_EXPR
, expr
, fixed_zero_node
, 1);
4692 return build_binary_op (location
, NE_EXPR
, expr
, integer_zero_node
, 1);
4695 protected_set_expr_location (expr
, location
);
4699 static void def_builtin_1 (enum built_in_function fncode
,
4701 enum built_in_class fnclass
,
4702 tree fntype
, tree libtype
,
4703 bool both_p
, bool fallback_p
, bool nonansi_p
,
4704 tree fnattrs
, bool implicit_p
);
4707 /* Apply the TYPE_QUALS to the new DECL. */
4710 c_apply_type_quals_to_decl (int type_quals
, tree decl
)
4712 tree type
= TREE_TYPE (decl
);
4714 if (type
== error_mark_node
)
4717 if ((type_quals
& TYPE_QUAL_CONST
)
4718 || (type
&& TREE_CODE (type
) == REFERENCE_TYPE
))
4719 /* We used to check TYPE_NEEDS_CONSTRUCTING here, but now a constexpr
4720 constructor can produce constant init, so rely on cp_finish_decl to
4721 clear TREE_READONLY if the variable has non-constant init. */
4722 TREE_READONLY (decl
) = 1;
4723 if (type_quals
& TYPE_QUAL_VOLATILE
)
4725 TREE_SIDE_EFFECTS (decl
) = 1;
4726 TREE_THIS_VOLATILE (decl
) = 1;
4728 if (type_quals
& TYPE_QUAL_RESTRICT
)
4730 while (type
&& TREE_CODE (type
) == ARRAY_TYPE
)
4731 /* Allow 'restrict' on arrays of pointers.
4732 FIXME currently we just ignore it. */
4733 type
= TREE_TYPE (type
);
4735 || !POINTER_TYPE_P (type
)
4736 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type
)))
4737 error ("invalid use of %<restrict%>");
4741 /* Hash function for the problem of multiple type definitions in
4742 different files. This must hash all types that will compare
4743 equal via comptypes to the same value. In practice it hashes
4744 on some of the simple stuff and leaves the details to comptypes. */
4747 c_type_hash (const void *p
)
4751 const_tree
const t
= (const_tree
) p
;
4753 switch (TREE_CODE (t
))
4755 /* For pointers, hash on pointee type plus some swizzling. */
4757 return c_type_hash (TREE_TYPE (t
)) ^ 0x3003003;
4758 /* Hash on number of elements and total size. */
4761 t2
= TYPE_VALUES (t
);
4765 t2
= TYPE_FIELDS (t
);
4767 case QUAL_UNION_TYPE
:
4769 t2
= TYPE_FIELDS (t
);
4773 t2
= TYPE_FIELDS (t
);
4778 /* FIXME: We want to use a DECL_CHAIN iteration method here, but
4779 TYPE_VALUES of ENUMERAL_TYPEs is stored as a TREE_LIST. */
4780 n_elements
= list_length (t2
);
4781 /* We might have a VLA here. */
4782 if (TREE_CODE (TYPE_SIZE (t
)) != INTEGER_CST
)
4785 size
= TREE_INT_CST_LOW (TYPE_SIZE (t
));
4786 return ((size
<< 24) | (n_elements
<< shift
));
4789 static GTY((param_is (union tree_node
))) htab_t type_hash_table
;
4791 /* Return the typed-based alias set for T, which may be an expression
4792 or a type. Return -1 if we don't do anything special. */
4795 c_common_get_alias_set (tree t
)
4800 /* For VLAs, use the alias set of the element type rather than the
4801 default of alias set 0 for types compared structurally. */
4802 if (TYPE_P (t
) && TYPE_STRUCTURAL_EQUALITY_P (t
))
4804 if (TREE_CODE (t
) == ARRAY_TYPE
)
4805 return get_alias_set (TREE_TYPE (t
));
4809 /* Permit type-punning when accessing a union, provided the access
4810 is directly through the union. For example, this code does not
4811 permit taking the address of a union member and then storing
4812 through it. Even the type-punning allowed here is a GCC
4813 extension, albeit a common and useful one; the C standard says
4814 that such accesses have implementation-defined behavior. */
4816 TREE_CODE (u
) == COMPONENT_REF
|| TREE_CODE (u
) == ARRAY_REF
;
4817 u
= TREE_OPERAND (u
, 0))
4818 if (TREE_CODE (u
) == COMPONENT_REF
4819 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u
, 0))) == UNION_TYPE
)
4822 /* That's all the expressions we handle specially. */
4826 /* The C standard guarantees that any object may be accessed via an
4827 lvalue that has character type. */
4828 if (t
== char_type_node
4829 || t
== signed_char_type_node
4830 || t
== unsigned_char_type_node
)
4833 /* The C standard specifically allows aliasing between signed and
4834 unsigned variants of the same type. We treat the signed
4835 variant as canonical. */
4836 if (TREE_CODE (t
) == INTEGER_TYPE
&& TYPE_UNSIGNED (t
))
4838 tree t1
= c_common_signed_type (t
);
4840 /* t1 == t can happen for boolean nodes which are always unsigned. */
4842 return get_alias_set (t1
);
4845 /* Handle the case of multiple type nodes referring to "the same" type,
4846 which occurs with IMA. These share an alias set. FIXME: Currently only
4847 C90 is handled. (In C99 type compatibility is not transitive, which
4848 complicates things mightily. The alias set splay trees can theoretically
4849 represent this, but insertion is tricky when you consider all the
4850 different orders things might arrive in.) */
4852 if (c_language
!= clk_c
|| flag_isoc99
)
4855 /* Save time if there's only one input file. */
4856 if (num_in_fnames
== 1)
4859 /* Pointers need special handling if they point to any type that
4860 needs special handling (below). */
4861 if (TREE_CODE (t
) == POINTER_TYPE
)
4864 /* Find bottom type under any nested POINTERs. */
4865 for (t2
= TREE_TYPE (t
);
4866 TREE_CODE (t2
) == POINTER_TYPE
;
4867 t2
= TREE_TYPE (t2
))
4869 if (TREE_CODE (t2
) != RECORD_TYPE
4870 && TREE_CODE (t2
) != ENUMERAL_TYPE
4871 && TREE_CODE (t2
) != QUAL_UNION_TYPE
4872 && TREE_CODE (t2
) != UNION_TYPE
)
4874 if (TYPE_SIZE (t2
) == 0)
4877 /* These are the only cases that need special handling. */
4878 if (TREE_CODE (t
) != RECORD_TYPE
4879 && TREE_CODE (t
) != ENUMERAL_TYPE
4880 && TREE_CODE (t
) != QUAL_UNION_TYPE
4881 && TREE_CODE (t
) != UNION_TYPE
4882 && TREE_CODE (t
) != POINTER_TYPE
)
4885 if (TYPE_SIZE (t
) == 0)
4888 /* Look up t in hash table. Only one of the compatible types within each
4889 alias set is recorded in the table. */
4890 if (!type_hash_table
)
4891 type_hash_table
= htab_create_ggc (1021, c_type_hash
,
4892 (htab_eq
) lang_hooks
.types_compatible_p
,
4894 slot
= htab_find_slot (type_hash_table
, t
, INSERT
);
4897 TYPE_ALIAS_SET (t
) = TYPE_ALIAS_SET ((tree
)*slot
);
4898 return TYPE_ALIAS_SET ((tree
)*slot
);
4901 /* Our caller will assign and record (in t) a new alias set; all we need
4902 to do is remember t in the hash table. */
4908 /* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where
4909 the second parameter indicates which OPERATOR is being applied.
4910 The COMPLAIN flag controls whether we should diagnose possibly
4911 ill-formed constructs or not. LOC is the location of the SIZEOF or
4915 c_sizeof_or_alignof_type (location_t loc
,
4916 tree type
, bool is_sizeof
, int complain
)
4918 const char *op_name
;
4920 enum tree_code type_code
= TREE_CODE (type
);
4922 op_name
= is_sizeof
? "sizeof" : "__alignof__";
4924 if (type_code
== FUNCTION_TYPE
)
4928 if (complain
&& warn_pointer_arith
)
4929 pedwarn (loc
, OPT_Wpointer_arith
,
4930 "invalid application of %<sizeof%> to a function type");
4932 return error_mark_node
;
4933 value
= size_one_node
;
4939 if (c_dialect_cxx ())
4940 pedwarn (loc
, OPT_Wpedantic
, "ISO C++ does not permit "
4941 "%<alignof%> applied to a function type");
4943 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not permit "
4944 "%<_Alignof%> applied to a function type");
4946 value
= size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
4949 else if (type_code
== VOID_TYPE
|| type_code
== ERROR_MARK
)
4951 if (type_code
== VOID_TYPE
4952 && complain
&& warn_pointer_arith
)
4953 pedwarn (loc
, OPT_Wpointer_arith
,
4954 "invalid application of %qs to a void type", op_name
);
4956 return error_mark_node
;
4957 value
= size_one_node
;
4959 else if (!COMPLETE_TYPE_P (type
)
4960 && (!c_dialect_cxx () || is_sizeof
|| type_code
!= ARRAY_TYPE
))
4963 error_at (loc
, "invalid application of %qs to incomplete type %qT",
4965 return error_mark_node
;
4967 else if (c_dialect_cxx () && type_code
== ARRAY_TYPE
4968 && !COMPLETE_TYPE_P (TREE_TYPE (type
)))
4971 error_at (loc
, "invalid application of %qs to array type %qT of "
4972 "incomplete element type", op_name
, type
);
4973 return error_mark_node
;
4978 /* Convert in case a char is more than one unit. */
4979 value
= size_binop_loc (loc
, CEIL_DIV_EXPR
, TYPE_SIZE_UNIT (type
),
4980 size_int (TYPE_PRECISION (char_type_node
)
4983 value
= size_int (TYPE_ALIGN_UNIT (type
));
4986 /* VALUE will have the middle-end integer type sizetype.
4987 However, we should really return a value of type `size_t',
4988 which is just a typedef for an ordinary integer type. */
4989 value
= fold_convert_loc (loc
, size_type_node
, value
);
4994 /* Implement the __alignof keyword: Return the minimum required
4995 alignment of EXPR, measured in bytes. For VAR_DECLs,
4996 FUNCTION_DECLs and FIELD_DECLs return DECL_ALIGN (which can be set
4997 from an "aligned" __attribute__ specification). LOC is the
4998 location of the ALIGNOF operator. */
5001 c_alignof_expr (location_t loc
, tree expr
)
5005 if (VAR_OR_FUNCTION_DECL_P (expr
))
5006 t
= size_int (DECL_ALIGN_UNIT (expr
));
5008 else if (TREE_CODE (expr
) == COMPONENT_REF
5009 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
, 1)))
5011 error_at (loc
, "%<__alignof%> applied to a bit-field");
5014 else if (TREE_CODE (expr
) == COMPONENT_REF
5015 && TREE_CODE (TREE_OPERAND (expr
, 1)) == FIELD_DECL
)
5016 t
= size_int (DECL_ALIGN_UNIT (TREE_OPERAND (expr
, 1)));
5018 else if (TREE_CODE (expr
) == INDIRECT_REF
)
5020 tree t
= TREE_OPERAND (expr
, 0);
5022 int bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
5024 while (CONVERT_EXPR_P (t
)
5025 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
5029 t
= TREE_OPERAND (t
, 0);
5030 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
5031 if (thisalign
> bestalign
)
5032 best
= t
, bestalign
= thisalign
;
5034 return c_alignof (loc
, TREE_TYPE (TREE_TYPE (best
)));
5037 return c_alignof (loc
, TREE_TYPE (expr
));
5039 return fold_convert_loc (loc
, size_type_node
, t
);
5042 /* Handle C and C++ default attributes. */
5044 enum built_in_attribute
5046 #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
5047 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
5048 #define DEF_ATTR_STRING(ENUM, VALUE) ENUM,
5049 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
5050 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
5051 #include "builtin-attrs.def"
5052 #undef DEF_ATTR_NULL_TREE
5054 #undef DEF_ATTR_STRING
5055 #undef DEF_ATTR_IDENT
5056 #undef DEF_ATTR_TREE_LIST
5060 static GTY(()) tree built_in_attributes
[(int) ATTR_LAST
];
5062 static void c_init_attributes (void);
5066 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
5067 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
5068 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
5069 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
5070 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
5071 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
5072 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
5073 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) NAME,
5074 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) NAME,
5075 #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8) NAME,
5076 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
5077 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
5078 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
5079 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
5080 #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
5081 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG6) \
5083 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
5084 #include "builtin-types.def"
5085 #undef DEF_PRIMITIVE_TYPE
5086 #undef DEF_FUNCTION_TYPE_0
5087 #undef DEF_FUNCTION_TYPE_1
5088 #undef DEF_FUNCTION_TYPE_2
5089 #undef DEF_FUNCTION_TYPE_3
5090 #undef DEF_FUNCTION_TYPE_4
5091 #undef DEF_FUNCTION_TYPE_5
5092 #undef DEF_FUNCTION_TYPE_6
5093 #undef DEF_FUNCTION_TYPE_7
5094 #undef DEF_FUNCTION_TYPE_8
5095 #undef DEF_FUNCTION_TYPE_VAR_0
5096 #undef DEF_FUNCTION_TYPE_VAR_1
5097 #undef DEF_FUNCTION_TYPE_VAR_2
5098 #undef DEF_FUNCTION_TYPE_VAR_3
5099 #undef DEF_FUNCTION_TYPE_VAR_4
5100 #undef DEF_FUNCTION_TYPE_VAR_5
5101 #undef DEF_POINTER_TYPE
5105 typedef enum c_builtin_type builtin_type
;
5107 /* A temporary array for c_common_nodes_and_builtins. Used in
5108 communication with def_fn_type. */
5109 static tree builtin_types
[(int) BT_LAST
+ 1];
5111 /* A helper function for c_common_nodes_and_builtins. Build function type
5112 for DEF with return type RET and N arguments. If VAR is true, then the
5113 function should be variadic after those N arguments.
5115 Takes special care not to ICE if any of the types involved are
5116 error_mark_node, which indicates that said type is not in fact available
5117 (see builtin_type_for_size). In which case the function type as a whole
5118 should be error_mark_node. */
5121 def_fn_type (builtin_type def
, builtin_type ret
, bool var
, int n
, ...)
5124 tree
*args
= XALLOCAVEC (tree
, n
);
5129 for (i
= 0; i
< n
; ++i
)
5131 builtin_type a
= (builtin_type
) va_arg (list
, int);
5132 t
= builtin_types
[a
];
5133 if (t
== error_mark_node
)
5138 t
= builtin_types
[ret
];
5139 if (t
== error_mark_node
)
5142 t
= build_varargs_function_type_array (t
, n
, args
);
5144 t
= build_function_type_array (t
, n
, args
);
5147 builtin_types
[def
] = t
;
5151 /* Build builtin functions common to both C and C++ language
5155 c_define_builtins (tree va_list_ref_type_node
, tree va_list_arg_type_node
)
5157 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
5158 builtin_types[ENUM] = VALUE;
5159 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
5160 def_fn_type (ENUM, RETURN, 0, 0);
5161 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
5162 def_fn_type (ENUM, RETURN, 0, 1, ARG1);
5163 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
5164 def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
5165 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
5166 def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
5167 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
5168 def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
5169 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5170 def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
5171 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5173 def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
5174 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5176 def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
5177 #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5179 def_fn_type (ENUM, RETURN, 0, 8, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
5181 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
5182 def_fn_type (ENUM, RETURN, 1, 0);
5183 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
5184 def_fn_type (ENUM, RETURN, 1, 1, ARG1);
5185 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
5186 def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
5187 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
5188 def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
5189 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
5190 def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
5191 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5192 def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
5193 #define DEF_POINTER_TYPE(ENUM, TYPE) \
5194 builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
5196 #include "builtin-types.def"
5198 #undef DEF_PRIMITIVE_TYPE
5199 #undef DEF_FUNCTION_TYPE_1
5200 #undef DEF_FUNCTION_TYPE_2
5201 #undef DEF_FUNCTION_TYPE_3
5202 #undef DEF_FUNCTION_TYPE_4
5203 #undef DEF_FUNCTION_TYPE_5
5204 #undef DEF_FUNCTION_TYPE_6
5205 #undef DEF_FUNCTION_TYPE_VAR_0
5206 #undef DEF_FUNCTION_TYPE_VAR_1
5207 #undef DEF_FUNCTION_TYPE_VAR_2
5208 #undef DEF_FUNCTION_TYPE_VAR_3
5209 #undef DEF_FUNCTION_TYPE_VAR_4
5210 #undef DEF_FUNCTION_TYPE_VAR_5
5211 #undef DEF_POINTER_TYPE
5212 builtin_types
[(int) BT_LAST
] = NULL_TREE
;
5214 c_init_attributes ();
5216 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P, \
5217 NONANSI_P, ATTRS, IMPLICIT, COND) \
5219 def_builtin_1 (ENUM, NAME, CLASS, \
5220 builtin_types[(int) TYPE], \
5221 builtin_types[(int) LIBTYPE], \
5222 BOTH_P, FALLBACK_P, NONANSI_P, \
5223 built_in_attributes[(int) ATTRS], IMPLICIT);
5224 #include "builtins.def"
5227 targetm
.init_builtins ();
5229 build_common_builtin_nodes ();
5231 if (flag_enable_cilkplus
)
5232 cilk_init_builtins ();
5235 /* Like get_identifier, but avoid warnings about null arguments when
5236 the argument may be NULL for targets where GCC lacks stdint.h type
5240 c_get_ident (const char *id
)
5242 return get_identifier (id
);
5245 /* Build tree nodes and builtin functions common to both C and C++ language
5249 c_common_nodes_and_builtins (void)
5251 int char16_type_size
;
5252 int char32_type_size
;
5253 int wchar_type_size
;
5254 tree array_domain_type
;
5255 tree va_list_ref_type_node
;
5256 tree va_list_arg_type_node
;
5258 build_common_tree_nodes (flag_signed_char
, flag_short_double
);
5260 /* Define `int' and `char' first so that dbx will output them first. */
5261 record_builtin_type (RID_INT
, NULL
, integer_type_node
);
5262 record_builtin_type (RID_CHAR
, "char", char_type_node
);
5264 /* `signed' is the same as `int'. FIXME: the declarations of "signed",
5265 "unsigned long", "long long unsigned" and "unsigned short" were in C++
5266 but not C. Are the conditionals here needed? */
5267 if (c_dialect_cxx ())
5268 record_builtin_type (RID_SIGNED
, NULL
, integer_type_node
);
5269 record_builtin_type (RID_LONG
, "long int", long_integer_type_node
);
5270 record_builtin_type (RID_UNSIGNED
, "unsigned int", unsigned_type_node
);
5271 record_builtin_type (RID_MAX
, "long unsigned int",
5272 long_unsigned_type_node
);
5273 if (int128_integer_type_node
!= NULL_TREE
)
5275 record_builtin_type (RID_INT128
, "__int128",
5276 int128_integer_type_node
);
5277 record_builtin_type (RID_MAX
, "__int128 unsigned",
5278 int128_unsigned_type_node
);
5280 if (c_dialect_cxx ())
5281 record_builtin_type (RID_MAX
, "unsigned long", long_unsigned_type_node
);
5282 record_builtin_type (RID_MAX
, "long long int",
5283 long_long_integer_type_node
);
5284 record_builtin_type (RID_MAX
, "long long unsigned int",
5285 long_long_unsigned_type_node
);
5286 if (c_dialect_cxx ())
5287 record_builtin_type (RID_MAX
, "long long unsigned",
5288 long_long_unsigned_type_node
);
5289 record_builtin_type (RID_SHORT
, "short int", short_integer_type_node
);
5290 record_builtin_type (RID_MAX
, "short unsigned int",
5291 short_unsigned_type_node
);
5292 if (c_dialect_cxx ())
5293 record_builtin_type (RID_MAX
, "unsigned short",
5294 short_unsigned_type_node
);
5296 /* Define both `signed char' and `unsigned char'. */
5297 record_builtin_type (RID_MAX
, "signed char", signed_char_type_node
);
5298 record_builtin_type (RID_MAX
, "unsigned char", unsigned_char_type_node
);
5300 /* These are types that c_common_type_for_size and
5301 c_common_type_for_mode use. */
5302 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5303 TYPE_DECL
, NULL_TREE
,
5305 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5306 TYPE_DECL
, NULL_TREE
,
5308 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5309 TYPE_DECL
, NULL_TREE
,
5311 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5312 TYPE_DECL
, NULL_TREE
,
5314 #if HOST_BITS_PER_WIDE_INT >= 64
5315 if (targetm
.scalar_mode_supported_p (TImode
))
5316 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5318 get_identifier ("__int128_t"),
5321 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5322 TYPE_DECL
, NULL_TREE
,
5323 unsigned_intQI_type_node
));
5324 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5325 TYPE_DECL
, NULL_TREE
,
5326 unsigned_intHI_type_node
));
5327 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5328 TYPE_DECL
, NULL_TREE
,
5329 unsigned_intSI_type_node
));
5330 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5331 TYPE_DECL
, NULL_TREE
,
5332 unsigned_intDI_type_node
));
5333 #if HOST_BITS_PER_WIDE_INT >= 64
5334 if (targetm
.scalar_mode_supported_p (TImode
))
5335 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5337 get_identifier ("__uint128_t"),
5338 unsigned_intTI_type_node
));
5341 /* Create the widest literal types. */
5342 widest_integer_literal_type_node
5343 = make_signed_type (HOST_BITS_PER_WIDE_INT
* 2);
5344 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5345 TYPE_DECL
, NULL_TREE
,
5346 widest_integer_literal_type_node
));
5348 widest_unsigned_literal_type_node
5349 = make_unsigned_type (HOST_BITS_PER_WIDE_INT
* 2);
5350 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5351 TYPE_DECL
, NULL_TREE
,
5352 widest_unsigned_literal_type_node
));
5354 signed_size_type_node
= c_common_signed_type (size_type_node
);
5357 TREE_TYPE (identifier_global_value (get_identifier (PID_TYPE
)));
5359 record_builtin_type (RID_FLOAT
, NULL
, float_type_node
);
5360 record_builtin_type (RID_DOUBLE
, NULL
, double_type_node
);
5361 record_builtin_type (RID_MAX
, "long double", long_double_type_node
);
5363 /* Only supported decimal floating point extension if the target
5364 actually supports underlying modes. */
5365 if (targetm
.scalar_mode_supported_p (SDmode
)
5366 && targetm
.scalar_mode_supported_p (DDmode
)
5367 && targetm
.scalar_mode_supported_p (TDmode
))
5369 record_builtin_type (RID_DFLOAT32
, NULL
, dfloat32_type_node
);
5370 record_builtin_type (RID_DFLOAT64
, NULL
, dfloat64_type_node
);
5371 record_builtin_type (RID_DFLOAT128
, NULL
, dfloat128_type_node
);
5374 if (targetm
.fixed_point_supported_p ())
5376 record_builtin_type (RID_MAX
, "short _Fract", short_fract_type_node
);
5377 record_builtin_type (RID_FRACT
, NULL
, fract_type_node
);
5378 record_builtin_type (RID_MAX
, "long _Fract", long_fract_type_node
);
5379 record_builtin_type (RID_MAX
, "long long _Fract",
5380 long_long_fract_type_node
);
5381 record_builtin_type (RID_MAX
, "unsigned short _Fract",
5382 unsigned_short_fract_type_node
);
5383 record_builtin_type (RID_MAX
, "unsigned _Fract",
5384 unsigned_fract_type_node
);
5385 record_builtin_type (RID_MAX
, "unsigned long _Fract",
5386 unsigned_long_fract_type_node
);
5387 record_builtin_type (RID_MAX
, "unsigned long long _Fract",
5388 unsigned_long_long_fract_type_node
);
5389 record_builtin_type (RID_MAX
, "_Sat short _Fract",
5390 sat_short_fract_type_node
);
5391 record_builtin_type (RID_MAX
, "_Sat _Fract", sat_fract_type_node
);
5392 record_builtin_type (RID_MAX
, "_Sat long _Fract",
5393 sat_long_fract_type_node
);
5394 record_builtin_type (RID_MAX
, "_Sat long long _Fract",
5395 sat_long_long_fract_type_node
);
5396 record_builtin_type (RID_MAX
, "_Sat unsigned short _Fract",
5397 sat_unsigned_short_fract_type_node
);
5398 record_builtin_type (RID_MAX
, "_Sat unsigned _Fract",
5399 sat_unsigned_fract_type_node
);
5400 record_builtin_type (RID_MAX
, "_Sat unsigned long _Fract",
5401 sat_unsigned_long_fract_type_node
);
5402 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Fract",
5403 sat_unsigned_long_long_fract_type_node
);
5404 record_builtin_type (RID_MAX
, "short _Accum", short_accum_type_node
);
5405 record_builtin_type (RID_ACCUM
, NULL
, accum_type_node
);
5406 record_builtin_type (RID_MAX
, "long _Accum", long_accum_type_node
);
5407 record_builtin_type (RID_MAX
, "long long _Accum",
5408 long_long_accum_type_node
);
5409 record_builtin_type (RID_MAX
, "unsigned short _Accum",
5410 unsigned_short_accum_type_node
);
5411 record_builtin_type (RID_MAX
, "unsigned _Accum",
5412 unsigned_accum_type_node
);
5413 record_builtin_type (RID_MAX
, "unsigned long _Accum",
5414 unsigned_long_accum_type_node
);
5415 record_builtin_type (RID_MAX
, "unsigned long long _Accum",
5416 unsigned_long_long_accum_type_node
);
5417 record_builtin_type (RID_MAX
, "_Sat short _Accum",
5418 sat_short_accum_type_node
);
5419 record_builtin_type (RID_MAX
, "_Sat _Accum", sat_accum_type_node
);
5420 record_builtin_type (RID_MAX
, "_Sat long _Accum",
5421 sat_long_accum_type_node
);
5422 record_builtin_type (RID_MAX
, "_Sat long long _Accum",
5423 sat_long_long_accum_type_node
);
5424 record_builtin_type (RID_MAX
, "_Sat unsigned short _Accum",
5425 sat_unsigned_short_accum_type_node
);
5426 record_builtin_type (RID_MAX
, "_Sat unsigned _Accum",
5427 sat_unsigned_accum_type_node
);
5428 record_builtin_type (RID_MAX
, "_Sat unsigned long _Accum",
5429 sat_unsigned_long_accum_type_node
);
5430 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Accum",
5431 sat_unsigned_long_long_accum_type_node
);
5435 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5437 get_identifier ("complex int"),
5438 complex_integer_type_node
));
5439 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5441 get_identifier ("complex float"),
5442 complex_float_type_node
));
5443 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5445 get_identifier ("complex double"),
5446 complex_double_type_node
));
5447 lang_hooks
.decls
.pushdecl
5448 (build_decl (UNKNOWN_LOCATION
,
5449 TYPE_DECL
, get_identifier ("complex long double"),
5450 complex_long_double_type_node
));
5452 if (c_dialect_cxx ())
5453 /* For C++, make fileptr_type_node a distinct void * type until
5454 FILE type is defined. */
5455 fileptr_type_node
= build_variant_type_copy (ptr_type_node
);
5457 record_builtin_type (RID_VOID
, NULL
, void_type_node
);
5459 /* Set the TYPE_NAME for any variants that were built before
5460 record_builtin_type gave names to the built-in types. */
5462 tree void_name
= TYPE_NAME (void_type_node
);
5463 TYPE_NAME (void_type_node
) = NULL_TREE
;
5464 TYPE_NAME (build_qualified_type (void_type_node
, TYPE_QUAL_CONST
))
5466 TYPE_NAME (void_type_node
) = void_name
;
5469 /* This node must not be shared. */
5470 void_zero_node
= make_node (INTEGER_CST
);
5471 TREE_TYPE (void_zero_node
) = void_type_node
;
5473 void_list_node
= build_void_list_node ();
5475 /* Make a type to be the domain of a few array types
5476 whose domains don't really matter.
5477 200 is small enough that it always fits in size_t
5478 and large enough that it can hold most function names for the
5479 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
5480 array_domain_type
= build_index_type (size_int (200));
5482 /* Make a type for arrays of characters.
5483 With luck nothing will ever really depend on the length of this
5485 char_array_type_node
5486 = build_array_type (char_type_node
, array_domain_type
);
5488 /* Likewise for arrays of ints. */
5490 = build_array_type (integer_type_node
, array_domain_type
);
5492 string_type_node
= build_pointer_type (char_type_node
);
5493 const_string_type_node
5494 = build_pointer_type (build_qualified_type
5495 (char_type_node
, TYPE_QUAL_CONST
));
5497 /* This is special for C++ so functions can be overloaded. */
5498 wchar_type_node
= get_identifier (MODIFIED_WCHAR_TYPE
);
5499 wchar_type_node
= TREE_TYPE (identifier_global_value (wchar_type_node
));
5500 wchar_type_size
= TYPE_PRECISION (wchar_type_node
);
5501 underlying_wchar_type_node
= wchar_type_node
;
5502 if (c_dialect_cxx ())
5504 if (TYPE_UNSIGNED (wchar_type_node
))
5505 wchar_type_node
= make_unsigned_type (wchar_type_size
);
5507 wchar_type_node
= make_signed_type (wchar_type_size
);
5508 record_builtin_type (RID_WCHAR
, "wchar_t", wchar_type_node
);
5511 /* This is for wide string constants. */
5512 wchar_array_type_node
5513 = build_array_type (wchar_type_node
, array_domain_type
);
5515 /* Define 'char16_t'. */
5516 char16_type_node
= get_identifier (CHAR16_TYPE
);
5517 char16_type_node
= TREE_TYPE (identifier_global_value (char16_type_node
));
5518 char16_type_size
= TYPE_PRECISION (char16_type_node
);
5519 if (c_dialect_cxx ())
5521 char16_type_node
= make_unsigned_type (char16_type_size
);
5523 if (cxx_dialect
>= cxx11
)
5524 record_builtin_type (RID_CHAR16
, "char16_t", char16_type_node
);
5527 /* This is for UTF-16 string constants. */
5528 char16_array_type_node
5529 = build_array_type (char16_type_node
, array_domain_type
);
5531 /* Define 'char32_t'. */
5532 char32_type_node
= get_identifier (CHAR32_TYPE
);
5533 char32_type_node
= TREE_TYPE (identifier_global_value (char32_type_node
));
5534 char32_type_size
= TYPE_PRECISION (char32_type_node
);
5535 if (c_dialect_cxx ())
5537 char32_type_node
= make_unsigned_type (char32_type_size
);
5539 if (cxx_dialect
>= cxx11
)
5540 record_builtin_type (RID_CHAR32
, "char32_t", char32_type_node
);
5543 /* This is for UTF-32 string constants. */
5544 char32_array_type_node
5545 = build_array_type (char32_type_node
, array_domain_type
);
5548 TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE
)));
5551 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE
)));
5553 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE
)));
5555 if (SIG_ATOMIC_TYPE
)
5556 sig_atomic_type_node
=
5557 TREE_TYPE (identifier_global_value (c_get_ident (SIG_ATOMIC_TYPE
)));
5560 TREE_TYPE (identifier_global_value (c_get_ident (INT8_TYPE
)));
5563 TREE_TYPE (identifier_global_value (c_get_ident (INT16_TYPE
)));
5566 TREE_TYPE (identifier_global_value (c_get_ident (INT32_TYPE
)));
5569 TREE_TYPE (identifier_global_value (c_get_ident (INT64_TYPE
)));
5572 TREE_TYPE (identifier_global_value (c_get_ident (UINT8_TYPE
)));
5574 c_uint16_type_node
=
5575 TREE_TYPE (identifier_global_value (c_get_ident (UINT16_TYPE
)));
5577 c_uint32_type_node
=
5578 TREE_TYPE (identifier_global_value (c_get_ident (UINT32_TYPE
)));
5580 c_uint64_type_node
=
5581 TREE_TYPE (identifier_global_value (c_get_ident (UINT64_TYPE
)));
5582 if (INT_LEAST8_TYPE
)
5583 int_least8_type_node
=
5584 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST8_TYPE
)));
5585 if (INT_LEAST16_TYPE
)
5586 int_least16_type_node
=
5587 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST16_TYPE
)));
5588 if (INT_LEAST32_TYPE
)
5589 int_least32_type_node
=
5590 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST32_TYPE
)));
5591 if (INT_LEAST64_TYPE
)
5592 int_least64_type_node
=
5593 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST64_TYPE
)));
5594 if (UINT_LEAST8_TYPE
)
5595 uint_least8_type_node
=
5596 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST8_TYPE
)));
5597 if (UINT_LEAST16_TYPE
)
5598 uint_least16_type_node
=
5599 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST16_TYPE
)));
5600 if (UINT_LEAST32_TYPE
)
5601 uint_least32_type_node
=
5602 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST32_TYPE
)));
5603 if (UINT_LEAST64_TYPE
)
5604 uint_least64_type_node
=
5605 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST64_TYPE
)));
5607 int_fast8_type_node
=
5608 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST8_TYPE
)));
5609 if (INT_FAST16_TYPE
)
5610 int_fast16_type_node
=
5611 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST16_TYPE
)));
5612 if (INT_FAST32_TYPE
)
5613 int_fast32_type_node
=
5614 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST32_TYPE
)));
5615 if (INT_FAST64_TYPE
)
5616 int_fast64_type_node
=
5617 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST64_TYPE
)));
5618 if (UINT_FAST8_TYPE
)
5619 uint_fast8_type_node
=
5620 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST8_TYPE
)));
5621 if (UINT_FAST16_TYPE
)
5622 uint_fast16_type_node
=
5623 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST16_TYPE
)));
5624 if (UINT_FAST32_TYPE
)
5625 uint_fast32_type_node
=
5626 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST32_TYPE
)));
5627 if (UINT_FAST64_TYPE
)
5628 uint_fast64_type_node
=
5629 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST64_TYPE
)));
5632 TREE_TYPE (identifier_global_value (c_get_ident (INTPTR_TYPE
)));
5635 TREE_TYPE (identifier_global_value (c_get_ident (UINTPTR_TYPE
)));
5637 default_function_type
5638 = build_varargs_function_type_list (integer_type_node
, NULL_TREE
);
5640 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE
)));
5641 unsigned_ptrdiff_type_node
= c_common_unsigned_type (ptrdiff_type_node
);
5643 lang_hooks
.decls
.pushdecl
5644 (build_decl (UNKNOWN_LOCATION
,
5645 TYPE_DECL
, get_identifier ("__builtin_va_list"),
5646 va_list_type_node
));
5647 if (targetm
.enum_va_list_p
)
5653 for (l
= 0; targetm
.enum_va_list_p (l
, &pname
, &ptype
); ++l
)
5655 lang_hooks
.decls
.pushdecl
5656 (build_decl (UNKNOWN_LOCATION
,
5657 TYPE_DECL
, get_identifier (pname
),
5663 if (TREE_CODE (va_list_type_node
) == ARRAY_TYPE
)
5665 va_list_arg_type_node
= va_list_ref_type_node
=
5666 build_pointer_type (TREE_TYPE (va_list_type_node
));
5670 va_list_arg_type_node
= va_list_type_node
;
5671 va_list_ref_type_node
= build_reference_type (va_list_type_node
);
5674 if (!flag_preprocess_only
)
5675 c_define_builtins (va_list_ref_type_node
, va_list_arg_type_node
);
5677 main_identifier_node
= get_identifier ("main");
5679 /* Create the built-in __null node. It is important that this is
5681 null_node
= make_node (INTEGER_CST
);
5682 TREE_TYPE (null_node
) = c_common_type_for_size (POINTER_SIZE
, 0);
5684 /* Since builtin_types isn't gc'ed, don't export these nodes. */
5685 memset (builtin_types
, 0, sizeof (builtin_types
));
5688 /* The number of named compound-literals generated thus far. */
5689 static GTY(()) int compound_literal_number
;
5691 /* Set DECL_NAME for DECL, a VAR_DECL for a compound-literal. */
5694 set_compound_literal_name (tree decl
)
5697 ASM_FORMAT_PRIVATE_NAME (name
, "__compound_literal",
5698 compound_literal_number
);
5699 compound_literal_number
++;
5700 DECL_NAME (decl
) = get_identifier (name
);
5704 build_va_arg (location_t loc
, tree expr
, tree type
)
5706 expr
= build1 (VA_ARG_EXPR
, type
, expr
);
5707 SET_EXPR_LOCATION (expr
, loc
);
5712 /* Linked list of disabled built-in functions. */
5714 typedef struct disabled_builtin
5717 struct disabled_builtin
*next
;
5719 static disabled_builtin
*disabled_builtins
= NULL
;
5721 static bool builtin_function_disabled_p (const char *);
5723 /* Disable a built-in function specified by -fno-builtin-NAME. If NAME
5724 begins with "__builtin_", give an error. */
5727 disable_builtin_function (const char *name
)
5729 if (strncmp (name
, "__builtin_", strlen ("__builtin_")) == 0)
5730 error ("cannot disable built-in function %qs", name
);
5733 disabled_builtin
*new_disabled_builtin
= XNEW (disabled_builtin
);
5734 new_disabled_builtin
->name
= name
;
5735 new_disabled_builtin
->next
= disabled_builtins
;
5736 disabled_builtins
= new_disabled_builtin
;
5741 /* Return true if the built-in function NAME has been disabled, false
5745 builtin_function_disabled_p (const char *name
)
5747 disabled_builtin
*p
;
5748 for (p
= disabled_builtins
; p
!= NULL
; p
= p
->next
)
5750 if (strcmp (name
, p
->name
) == 0)
5757 /* Worker for DEF_BUILTIN.
5758 Possibly define a builtin function with one or two names.
5759 Does not declare a non-__builtin_ function if flag_no_builtin, or if
5760 nonansi_p and flag_no_nonansi_builtin. */
5763 def_builtin_1 (enum built_in_function fncode
,
5765 enum built_in_class fnclass
,
5766 tree fntype
, tree libtype
,
5767 bool both_p
, bool fallback_p
, bool nonansi_p
,
5768 tree fnattrs
, bool implicit_p
)
5771 const char *libname
;
5773 if (fntype
== error_mark_node
)
5776 gcc_assert ((!both_p
&& !fallback_p
)
5777 || !strncmp (name
, "__builtin_",
5778 strlen ("__builtin_")));
5780 libname
= name
+ strlen ("__builtin_");
5781 decl
= add_builtin_function (name
, fntype
, fncode
, fnclass
,
5782 (fallback_p
? libname
: NULL
),
5785 set_builtin_decl (fncode
, decl
, implicit_p
);
5788 && !flag_no_builtin
&& !builtin_function_disabled_p (libname
)
5789 && !(nonansi_p
&& flag_no_nonansi_builtin
))
5790 add_builtin_function (libname
, libtype
, fncode
, fnclass
,
5794 /* Nonzero if the type T promotes to int. This is (nearly) the
5795 integral promotions defined in ISO C99 6.3.1.1/2. */
5798 c_promoting_integer_type_p (const_tree t
)
5800 switch (TREE_CODE (t
))
5803 return (TYPE_MAIN_VARIANT (t
) == char_type_node
5804 || TYPE_MAIN_VARIANT (t
) == signed_char_type_node
5805 || TYPE_MAIN_VARIANT (t
) == unsigned_char_type_node
5806 || TYPE_MAIN_VARIANT (t
) == short_integer_type_node
5807 || TYPE_MAIN_VARIANT (t
) == short_unsigned_type_node
5808 || TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
));
5811 /* ??? Technically all enumerations not larger than an int
5812 promote to an int. But this is used along code paths
5813 that only want to notice a size change. */
5814 return TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
);
5824 /* Return 1 if PARMS specifies a fixed number of parameters
5825 and none of their types is affected by default promotions. */
5828 self_promoting_args_p (const_tree parms
)
5831 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
5833 tree type
= TREE_VALUE (t
);
5835 if (type
== error_mark_node
)
5838 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
5844 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
5847 if (c_promoting_integer_type_p (type
))
5853 /* Recursively remove any '*' or '&' operator from TYPE. */
5855 strip_pointer_operator (tree t
)
5857 while (POINTER_TYPE_P (t
))
5862 /* Recursively remove pointer or array type from TYPE. */
5864 strip_pointer_or_array_types (tree t
)
5866 while (TREE_CODE (t
) == ARRAY_TYPE
|| POINTER_TYPE_P (t
))
5871 /* Used to compare case labels. K1 and K2 are actually tree nodes
5872 representing case labels, or NULL_TREE for a `default' label.
5873 Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after
5874 K2, and 0 if K1 and K2 are equal. */
5877 case_compare (splay_tree_key k1
, splay_tree_key k2
)
5879 /* Consider a NULL key (such as arises with a `default' label) to be
5880 smaller than anything else. */
5886 return tree_int_cst_compare ((tree
) k1
, (tree
) k2
);
5889 /* Process a case label, located at LOC, for the range LOW_VALUE
5890 ... HIGH_VALUE. If LOW_VALUE and HIGH_VALUE are both NULL_TREE
5891 then this case label is actually a `default' label. If only
5892 HIGH_VALUE is NULL_TREE, then case label was declared using the
5893 usual C/C++ syntax, rather than the GNU case range extension.
5894 CASES is a tree containing all the case ranges processed so far;
5895 COND is the condition for the switch-statement itself. Returns the
5896 CASE_LABEL_EXPR created, or ERROR_MARK_NODE if no CASE_LABEL_EXPR
5900 c_add_case_label (location_t loc
, splay_tree cases
, tree cond
, tree orig_type
,
5901 tree low_value
, tree high_value
)
5906 splay_tree_node node
;
5908 /* Create the LABEL_DECL itself. */
5909 label
= create_artificial_label (loc
);
5911 /* If there was an error processing the switch condition, bail now
5912 before we get more confused. */
5913 if (!cond
|| cond
== error_mark_node
)
5916 if ((low_value
&& TREE_TYPE (low_value
)
5917 && POINTER_TYPE_P (TREE_TYPE (low_value
)))
5918 || (high_value
&& TREE_TYPE (high_value
)
5919 && POINTER_TYPE_P (TREE_TYPE (high_value
))))
5921 error_at (loc
, "pointers are not permitted as case values");
5925 /* Case ranges are a GNU extension. */
5927 pedwarn (loc
, OPT_Wpedantic
,
5928 "range expressions in switch statements are non-standard");
5930 type
= TREE_TYPE (cond
);
5933 low_value
= check_case_value (low_value
);
5934 low_value
= convert_and_check (type
, low_value
);
5935 if (low_value
== error_mark_node
)
5940 high_value
= check_case_value (high_value
);
5941 high_value
= convert_and_check (type
, high_value
);
5942 if (high_value
== error_mark_node
)
5946 if (low_value
&& high_value
)
5948 /* If the LOW_VALUE and HIGH_VALUE are the same, then this isn't
5949 really a case range, even though it was written that way.
5950 Remove the HIGH_VALUE to simplify later processing. */
5951 if (tree_int_cst_equal (low_value
, high_value
))
5952 high_value
= NULL_TREE
;
5953 else if (!tree_int_cst_lt (low_value
, high_value
))
5954 warning_at (loc
, 0, "empty range specified");
5957 /* See if the case is in range of the type of the original testing
5958 expression. If both low_value and high_value are out of range,
5959 don't insert the case label and return NULL_TREE. */
5961 && !check_case_bounds (type
, orig_type
,
5962 &low_value
, high_value
? &high_value
: NULL
))
5965 /* Look up the LOW_VALUE in the table of case labels we already
5967 node
= splay_tree_lookup (cases
, (splay_tree_key
) low_value
);
5968 /* If there was not an exact match, check for overlapping ranges.
5969 There's no need to do this if there's no LOW_VALUE or HIGH_VALUE;
5970 that's a `default' label and the only overlap is an exact match. */
5971 if (!node
&& (low_value
|| high_value
))
5973 splay_tree_node low_bound
;
5974 splay_tree_node high_bound
;
5976 /* Even though there wasn't an exact match, there might be an
5977 overlap between this case range and another case range.
5978 Since we've (inductively) not allowed any overlapping case
5979 ranges, we simply need to find the greatest low case label
5980 that is smaller that LOW_VALUE, and the smallest low case
5981 label that is greater than LOW_VALUE. If there is an overlap
5982 it will occur in one of these two ranges. */
5983 low_bound
= splay_tree_predecessor (cases
,
5984 (splay_tree_key
) low_value
);
5985 high_bound
= splay_tree_successor (cases
,
5986 (splay_tree_key
) low_value
);
5988 /* Check to see if the LOW_BOUND overlaps. It is smaller than
5989 the LOW_VALUE, so there is no need to check unless the
5990 LOW_BOUND is in fact itself a case range. */
5992 && CASE_HIGH ((tree
) low_bound
->value
)
5993 && tree_int_cst_compare (CASE_HIGH ((tree
) low_bound
->value
),
5996 /* Check to see if the HIGH_BOUND overlaps. The low end of that
5997 range is bigger than the low end of the current range, so we
5998 are only interested if the current range is a real range, and
5999 not an ordinary case label. */
6002 && (tree_int_cst_compare ((tree
) high_bound
->key
,
6007 /* If there was an overlap, issue an error. */
6010 tree duplicate
= CASE_LABEL ((tree
) node
->value
);
6014 error_at (loc
, "duplicate (or overlapping) case value");
6015 error_at (DECL_SOURCE_LOCATION (duplicate
),
6016 "this is the first entry overlapping that value");
6020 error_at (loc
, "duplicate case value") ;
6021 error_at (DECL_SOURCE_LOCATION (duplicate
), "previously used here");
6025 error_at (loc
, "multiple default labels in one switch");
6026 error_at (DECL_SOURCE_LOCATION (duplicate
),
6027 "this is the first default label");
6032 /* Add a CASE_LABEL to the statement-tree. */
6033 case_label
= add_stmt (build_case_label (low_value
, high_value
, label
));
6034 /* Register this case label in the splay tree. */
6035 splay_tree_insert (cases
,
6036 (splay_tree_key
) low_value
,
6037 (splay_tree_value
) case_label
);
6042 /* Add a label so that the back-end doesn't think that the beginning of
6043 the switch is unreachable. Note that we do not add a case label, as
6044 that just leads to duplicates and thence to failure later on. */
6047 tree t
= create_artificial_label (loc
);
6048 add_stmt (build_stmt (loc
, LABEL_EXPR
, t
));
6050 return error_mark_node
;
6053 /* Subroutines of c_do_switch_warnings, called via splay_tree_foreach.
6054 Used to verify that case values match up with enumerator values. */
6057 match_case_to_enum_1 (tree key
, tree type
, tree label
)
6059 char buf
[2 + 2*HOST_BITS_PER_WIDE_INT
/4 + 1];
6061 /* ??? Not working too hard to print the double-word value.
6062 Should perhaps be done with %lwd in the diagnostic routines? */
6063 if (TREE_INT_CST_HIGH (key
) == 0)
6064 snprintf (buf
, sizeof (buf
), HOST_WIDE_INT_PRINT_UNSIGNED
,
6065 TREE_INT_CST_LOW (key
));
6066 else if (!TYPE_UNSIGNED (type
)
6067 && TREE_INT_CST_HIGH (key
) == -1
6068 && TREE_INT_CST_LOW (key
) != 0)
6069 snprintf (buf
, sizeof (buf
), "-" HOST_WIDE_INT_PRINT_UNSIGNED
,
6070 -TREE_INT_CST_LOW (key
));
6072 snprintf (buf
, sizeof (buf
), HOST_WIDE_INT_PRINT_DOUBLE_HEX
,
6073 (unsigned HOST_WIDE_INT
) TREE_INT_CST_HIGH (key
),
6074 (unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (key
));
6076 if (TYPE_NAME (type
) == 0)
6077 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
6078 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
6079 "case value %qs not in enumerated type",
6082 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
6083 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
6084 "case value %qs not in enumerated type %qT",
6088 /* Subroutine of c_do_switch_warnings, called via splay_tree_foreach.
6089 Used to verify that case values match up with enumerator values. */
6092 match_case_to_enum (splay_tree_node node
, void *data
)
6094 tree label
= (tree
) node
->value
;
6095 tree type
= (tree
) data
;
6097 /* Skip default case. */
6098 if (!CASE_LOW (label
))
6101 /* If CASE_LOW_SEEN is not set, that means CASE_LOW did not appear
6102 when we did our enum->case scan. Reset our scratch bit after. */
6103 if (!CASE_LOW_SEEN (label
))
6104 match_case_to_enum_1 (CASE_LOW (label
), type
, label
);
6106 CASE_LOW_SEEN (label
) = 0;
6108 /* If CASE_HIGH is non-null, we have a range. If CASE_HIGH_SEEN is
6109 not set, that means that CASE_HIGH did not appear when we did our
6110 enum->case scan. Reset our scratch bit after. */
6111 if (CASE_HIGH (label
))
6113 if (!CASE_HIGH_SEEN (label
))
6114 match_case_to_enum_1 (CASE_HIGH (label
), type
, label
);
6116 CASE_HIGH_SEEN (label
) = 0;
6122 /* Handle -Wswitch*. Called from the front end after parsing the
6123 switch construct. */
6124 /* ??? Should probably be somewhere generic, since other languages
6125 besides C and C++ would want this. At the moment, however, C/C++
6126 are the only tree-ssa languages that support enumerations at all,
6127 so the point is moot. */
6130 c_do_switch_warnings (splay_tree cases
, location_t switch_location
,
6131 tree type
, tree cond
)
6133 splay_tree_node default_node
;
6134 splay_tree_node node
;
6137 if (!warn_switch
&& !warn_switch_enum
&& !warn_switch_default
)
6140 default_node
= splay_tree_lookup (cases
, (splay_tree_key
) NULL
);
6142 warning_at (switch_location
, OPT_Wswitch_default
,
6143 "switch missing default case");
6145 /* From here on, we only care about about enumerated types. */
6146 if (!type
|| TREE_CODE (type
) != ENUMERAL_TYPE
)
6149 /* From here on, we only care about -Wswitch and -Wswitch-enum. */
6150 if (!warn_switch_enum
&& !warn_switch
)
6153 /* Check the cases. Warn about case values which are not members of
6154 the enumerated type. For -Wswitch-enum, or for -Wswitch when
6155 there is no default case, check that exactly all enumeration
6156 literals are covered by the cases. */
6158 /* Clearing COND if it is not an integer constant simplifies
6159 the tests inside the loop below. */
6160 if (TREE_CODE (cond
) != INTEGER_CST
)
6163 /* The time complexity here is O(N*lg(N)) worst case, but for the
6164 common case of monotonically increasing enumerators, it is
6165 O(N), since the nature of the splay tree will keep the next
6166 element adjacent to the root at all times. */
6168 for (chain
= TYPE_VALUES (type
); chain
; chain
= TREE_CHAIN (chain
))
6170 tree value
= TREE_VALUE (chain
);
6171 if (TREE_CODE (value
) == CONST_DECL
)
6172 value
= DECL_INITIAL (value
);
6173 node
= splay_tree_lookup (cases
, (splay_tree_key
) value
);
6176 /* Mark the CASE_LOW part of the case entry as seen. */
6177 tree label
= (tree
) node
->value
;
6178 CASE_LOW_SEEN (label
) = 1;
6182 /* Even though there wasn't an exact match, there might be a
6183 case range which includes the enumerator's value. */
6184 node
= splay_tree_predecessor (cases
, (splay_tree_key
) value
);
6185 if (node
&& CASE_HIGH ((tree
) node
->value
))
6187 tree label
= (tree
) node
->value
;
6188 int cmp
= tree_int_cst_compare (CASE_HIGH (label
), value
);
6191 /* If we match the upper bound exactly, mark the CASE_HIGH
6192 part of the case entry as seen. */
6194 CASE_HIGH_SEEN (label
) = 1;
6199 /* We've now determined that this enumerated literal isn't
6200 handled by the case labels of the switch statement. */
6202 /* If the switch expression is a constant, we only really care
6203 about whether that constant is handled by the switch. */
6204 if (cond
&& tree_int_cst_compare (cond
, value
))
6207 /* If there is a default_node, the only relevant option is
6208 Wswitch-enum. Otherwise, if both are enabled then we prefer
6209 to warn using -Wswitch because -Wswitch is enabled by -Wall
6210 while -Wswitch-enum is explicit. */
6211 warning_at (switch_location
,
6212 (default_node
|| !warn_switch
6215 "enumeration value %qE not handled in switch",
6216 TREE_PURPOSE (chain
));
6219 /* Warn if there are case expressions that don't correspond to
6220 enumerators. This can occur since C and C++ don't enforce
6221 type-checking of assignments to enumeration variables.
6223 The time complexity here is now always O(N) worst case, since
6224 we should have marked both the lower bound and upper bound of
6225 every disjoint case label, with CASE_LOW_SEEN and CASE_HIGH_SEEN
6226 above. This scan also resets those fields. */
6228 splay_tree_foreach (cases
, match_case_to_enum
, type
);
6231 /* Finish an expression taking the address of LABEL (an
6232 IDENTIFIER_NODE). Returns an expression for the address.
6234 LOC is the location for the expression returned. */
6237 finish_label_address_expr (tree label
, location_t loc
)
6241 pedwarn (input_location
, OPT_Wpedantic
, "taking the address of a label is non-standard");
6243 if (label
== error_mark_node
)
6244 return error_mark_node
;
6246 label
= lookup_label (label
);
6247 if (label
== NULL_TREE
)
6248 result
= null_pointer_node
;
6251 TREE_USED (label
) = 1;
6252 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
6253 /* The current function is not necessarily uninlinable.
6254 Computed gotos are incompatible with inlining, but the value
6255 here could be used only in a diagnostic, for example. */
6256 protected_set_expr_location (result
, loc
);
6263 /* Given a boolean expression ARG, return a tree representing an increment
6264 or decrement (as indicated by CODE) of ARG. The front end must check for
6265 invalid cases (e.g., decrement in C++). */
6267 boolean_increment (enum tree_code code
, tree arg
)
6270 tree true_res
= build_int_cst (TREE_TYPE (arg
), 1);
6272 arg
= stabilize_reference (arg
);
6275 case PREINCREMENT_EXPR
:
6276 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
6278 case POSTINCREMENT_EXPR
:
6279 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
6280 arg
= save_expr (arg
);
6281 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
6282 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
6284 case PREDECREMENT_EXPR
:
6285 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
6286 invert_truthvalue_loc (input_location
, arg
));
6288 case POSTDECREMENT_EXPR
:
6289 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
6290 invert_truthvalue_loc (input_location
, arg
));
6291 arg
= save_expr (arg
);
6292 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
6293 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
6298 TREE_SIDE_EFFECTS (val
) = 1;
6302 /* Built-in macros for stddef.h and stdint.h, that require macros
6303 defined in this file. */
6305 c_stddef_cpp_builtins(void)
6307 builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE
, 0);
6308 builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE
, 0);
6309 builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE
, 0);
6310 builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE
, 0);
6311 builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE
, 0);
6312 builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE
, 0);
6313 builtin_define_with_value ("__CHAR16_TYPE__", CHAR16_TYPE
, 0);
6314 builtin_define_with_value ("__CHAR32_TYPE__", CHAR32_TYPE
, 0);
6315 if (SIG_ATOMIC_TYPE
)
6316 builtin_define_with_value ("__SIG_ATOMIC_TYPE__", SIG_ATOMIC_TYPE
, 0);
6318 builtin_define_with_value ("__INT8_TYPE__", INT8_TYPE
, 0);
6320 builtin_define_with_value ("__INT16_TYPE__", INT16_TYPE
, 0);
6322 builtin_define_with_value ("__INT32_TYPE__", INT32_TYPE
, 0);
6324 builtin_define_with_value ("__INT64_TYPE__", INT64_TYPE
, 0);
6326 builtin_define_with_value ("__UINT8_TYPE__", UINT8_TYPE
, 0);
6328 builtin_define_with_value ("__UINT16_TYPE__", UINT16_TYPE
, 0);
6330 builtin_define_with_value ("__UINT32_TYPE__", UINT32_TYPE
, 0);
6332 builtin_define_with_value ("__UINT64_TYPE__", UINT64_TYPE
, 0);
6333 if (INT_LEAST8_TYPE
)
6334 builtin_define_with_value ("__INT_LEAST8_TYPE__", INT_LEAST8_TYPE
, 0);
6335 if (INT_LEAST16_TYPE
)
6336 builtin_define_with_value ("__INT_LEAST16_TYPE__", INT_LEAST16_TYPE
, 0);
6337 if (INT_LEAST32_TYPE
)
6338 builtin_define_with_value ("__INT_LEAST32_TYPE__", INT_LEAST32_TYPE
, 0);
6339 if (INT_LEAST64_TYPE
)
6340 builtin_define_with_value ("__INT_LEAST64_TYPE__", INT_LEAST64_TYPE
, 0);
6341 if (UINT_LEAST8_TYPE
)
6342 builtin_define_with_value ("__UINT_LEAST8_TYPE__", UINT_LEAST8_TYPE
, 0);
6343 if (UINT_LEAST16_TYPE
)
6344 builtin_define_with_value ("__UINT_LEAST16_TYPE__", UINT_LEAST16_TYPE
, 0);
6345 if (UINT_LEAST32_TYPE
)
6346 builtin_define_with_value ("__UINT_LEAST32_TYPE__", UINT_LEAST32_TYPE
, 0);
6347 if (UINT_LEAST64_TYPE
)
6348 builtin_define_with_value ("__UINT_LEAST64_TYPE__", UINT_LEAST64_TYPE
, 0);
6350 builtin_define_with_value ("__INT_FAST8_TYPE__", INT_FAST8_TYPE
, 0);
6351 if (INT_FAST16_TYPE
)
6352 builtin_define_with_value ("__INT_FAST16_TYPE__", INT_FAST16_TYPE
, 0);
6353 if (INT_FAST32_TYPE
)
6354 builtin_define_with_value ("__INT_FAST32_TYPE__", INT_FAST32_TYPE
, 0);
6355 if (INT_FAST64_TYPE
)
6356 builtin_define_with_value ("__INT_FAST64_TYPE__", INT_FAST64_TYPE
, 0);
6357 if (UINT_FAST8_TYPE
)
6358 builtin_define_with_value ("__UINT_FAST8_TYPE__", UINT_FAST8_TYPE
, 0);
6359 if (UINT_FAST16_TYPE
)
6360 builtin_define_with_value ("__UINT_FAST16_TYPE__", UINT_FAST16_TYPE
, 0);
6361 if (UINT_FAST32_TYPE
)
6362 builtin_define_with_value ("__UINT_FAST32_TYPE__", UINT_FAST32_TYPE
, 0);
6363 if (UINT_FAST64_TYPE
)
6364 builtin_define_with_value ("__UINT_FAST64_TYPE__", UINT_FAST64_TYPE
, 0);
6366 builtin_define_with_value ("__INTPTR_TYPE__", INTPTR_TYPE
, 0);
6368 builtin_define_with_value ("__UINTPTR_TYPE__", UINTPTR_TYPE
, 0);
6372 c_init_attributes (void)
6374 /* Fill in the built_in_attributes array. */
6375 #define DEF_ATTR_NULL_TREE(ENUM) \
6376 built_in_attributes[(int) ENUM] = NULL_TREE;
6377 #define DEF_ATTR_INT(ENUM, VALUE) \
6378 built_in_attributes[(int) ENUM] = build_int_cst (integer_type_node, VALUE);
6379 #define DEF_ATTR_STRING(ENUM, VALUE) \
6380 built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
6381 #define DEF_ATTR_IDENT(ENUM, STRING) \
6382 built_in_attributes[(int) ENUM] = get_identifier (STRING);
6383 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
6384 built_in_attributes[(int) ENUM] \
6385 = tree_cons (built_in_attributes[(int) PURPOSE], \
6386 built_in_attributes[(int) VALUE], \
6387 built_in_attributes[(int) CHAIN]);
6388 #include "builtin-attrs.def"
6389 #undef DEF_ATTR_NULL_TREE
6391 #undef DEF_ATTR_IDENT
6392 #undef DEF_ATTR_TREE_LIST
6395 /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain
6396 identifier as an argument, so the front end shouldn't look it up. */
6399 attribute_takes_identifier_p (const_tree attr_id
)
6401 const struct attribute_spec
*spec
= lookup_attribute_spec (attr_id
);
6403 /* Unknown attribute that we'll end up ignoring, return true so we
6404 don't complain about an identifier argument. */
6406 else if (!strcmp ("mode", spec
->name
)
6407 || !strcmp ("format", spec
->name
)
6408 || !strcmp ("cleanup", spec
->name
))
6411 return targetm
.attribute_takes_identifier_p (attr_id
);
6414 /* Attribute handlers common to C front ends. */
6416 /* Handle a "packed" attribute; arguments as in
6417 struct attribute_spec.handler. */
6420 handle_packed_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6421 int flags
, bool *no_add_attrs
)
6425 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6426 *node
= build_variant_type_copy (*node
);
6427 TYPE_PACKED (*node
) = 1;
6429 else if (TREE_CODE (*node
) == FIELD_DECL
)
6431 if (TYPE_ALIGN (TREE_TYPE (*node
)) <= BITS_PER_UNIT
6432 /* Still pack bitfields. */
6433 && ! DECL_INITIAL (*node
))
6434 warning (OPT_Wattributes
,
6435 "%qE attribute ignored for field of type %qT",
6436 name
, TREE_TYPE (*node
));
6438 DECL_PACKED (*node
) = 1;
6440 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
6441 used for DECL_REGISTER. It wouldn't mean anything anyway.
6442 We can't set DECL_PACKED on the type of a TYPE_DECL, because
6443 that changes what the typedef is typing. */
6446 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6447 *no_add_attrs
= true;
6453 /* Handle a "nocommon" attribute; arguments as in
6454 struct attribute_spec.handler. */
6457 handle_nocommon_attribute (tree
*node
, tree name
,
6458 tree
ARG_UNUSED (args
),
6459 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6461 if (TREE_CODE (*node
) == VAR_DECL
)
6462 DECL_COMMON (*node
) = 0;
6465 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6466 *no_add_attrs
= true;
6472 /* Handle a "common" attribute; arguments as in
6473 struct attribute_spec.handler. */
6476 handle_common_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6477 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6479 if (TREE_CODE (*node
) == VAR_DECL
)
6480 DECL_COMMON (*node
) = 1;
6483 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6484 *no_add_attrs
= true;
6490 /* Handle a "noreturn" attribute; arguments as in
6491 struct attribute_spec.handler. */
6494 handle_noreturn_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6495 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6497 tree type
= TREE_TYPE (*node
);
6499 /* See FIXME comment in c_common_attribute_table. */
6500 if (TREE_CODE (*node
) == FUNCTION_DECL
6501 || objc_method_decl (TREE_CODE (*node
)))
6502 TREE_THIS_VOLATILE (*node
) = 1;
6503 else if (TREE_CODE (type
) == POINTER_TYPE
6504 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
6506 = build_pointer_type
6507 (build_type_variant (TREE_TYPE (type
),
6508 TYPE_READONLY (TREE_TYPE (type
)), 1));
6511 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6512 *no_add_attrs
= true;
6518 /* Handle a "hot" and attribute; arguments as in
6519 struct attribute_spec.handler. */
6522 handle_hot_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6523 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6525 if (TREE_CODE (*node
) == FUNCTION_DECL
6526 || TREE_CODE (*node
) == LABEL_DECL
)
6528 if (lookup_attribute ("cold", DECL_ATTRIBUTES (*node
)) != NULL
)
6530 warning (OPT_Wattributes
, "%qE attribute conflicts with attribute %s",
6532 *no_add_attrs
= true;
6534 /* Most of the rest of the hot processing is done later with
6535 lookup_attribute. */
6539 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6540 *no_add_attrs
= true;
6546 /* Handle a "cold" and attribute; arguments as in
6547 struct attribute_spec.handler. */
6550 handle_cold_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6551 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6553 if (TREE_CODE (*node
) == FUNCTION_DECL
6554 || TREE_CODE (*node
) == LABEL_DECL
)
6556 if (lookup_attribute ("hot", DECL_ATTRIBUTES (*node
)) != NULL
)
6558 warning (OPT_Wattributes
, "%qE attribute conflicts with attribute %s",
6560 *no_add_attrs
= true;
6562 /* Most of the rest of the cold processing is done later with
6563 lookup_attribute. */
6567 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6568 *no_add_attrs
= true;
6574 /* Handle a "no_sanitize_address" attribute; arguments as in
6575 struct attribute_spec.handler. */
6578 handle_no_sanitize_address_attribute (tree
*node
, tree name
, tree
, int,
6581 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6583 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6584 *no_add_attrs
= true;
6590 /* Handle a "no_address_safety_analysis" attribute; arguments as in
6591 struct attribute_spec.handler. */
6594 handle_no_address_safety_analysis_attribute (tree
*node
, tree name
, tree
, int,
6597 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6598 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6599 else if (!lookup_attribute ("no_sanitize_address", DECL_ATTRIBUTES (*node
)))
6600 DECL_ATTRIBUTES (*node
)
6601 = tree_cons (get_identifier ("no_sanitize_address"),
6602 NULL_TREE
, DECL_ATTRIBUTES (*node
));
6603 *no_add_attrs
= true;
6607 /* Handle a "no_sanitize_undefined" attribute; arguments as in
6608 struct attribute_spec.handler. */
6611 handle_no_sanitize_undefined_attribute (tree
*node
, tree name
, tree
, int,
6614 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6616 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6617 *no_add_attrs
= true;
6623 /* Handle a "noinline" attribute; arguments as in
6624 struct attribute_spec.handler. */
6627 handle_noinline_attribute (tree
*node
, tree name
,
6628 tree
ARG_UNUSED (args
),
6629 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6631 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6632 DECL_UNINLINABLE (*node
) = 1;
6635 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6636 *no_add_attrs
= true;
6642 /* Handle a "noclone" attribute; arguments as in
6643 struct attribute_spec.handler. */
6646 handle_noclone_attribute (tree
*node
, tree name
,
6647 tree
ARG_UNUSED (args
),
6648 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6650 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6652 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6653 *no_add_attrs
= true;
6659 /* Handle a "always_inline" attribute; arguments as in
6660 struct attribute_spec.handler. */
6663 handle_always_inline_attribute (tree
*node
, tree name
,
6664 tree
ARG_UNUSED (args
),
6665 int ARG_UNUSED (flags
),
6668 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6670 /* Set the attribute and mark it for disregarding inline
6672 DECL_DISREGARD_INLINE_LIMITS (*node
) = 1;
6676 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6677 *no_add_attrs
= true;
6683 /* Handle a "gnu_inline" attribute; arguments as in
6684 struct attribute_spec.handler. */
6687 handle_gnu_inline_attribute (tree
*node
, tree name
,
6688 tree
ARG_UNUSED (args
),
6689 int ARG_UNUSED (flags
),
6692 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
6694 /* Do nothing else, just set the attribute. We'll get at
6695 it later with lookup_attribute. */
6699 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6700 *no_add_attrs
= true;
6706 /* Handle a "leaf" attribute; arguments as in
6707 struct attribute_spec.handler. */
6710 handle_leaf_attribute (tree
*node
, tree name
,
6711 tree
ARG_UNUSED (args
),
6712 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6714 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6716 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6717 *no_add_attrs
= true;
6719 if (!TREE_PUBLIC (*node
))
6721 warning (OPT_Wattributes
, "%qE attribute has no effect on unit local functions", name
);
6722 *no_add_attrs
= true;
6728 /* Handle an "artificial" attribute; arguments as in
6729 struct attribute_spec.handler. */
6732 handle_artificial_attribute (tree
*node
, tree name
,
6733 tree
ARG_UNUSED (args
),
6734 int ARG_UNUSED (flags
),
6737 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
6739 /* Do nothing else, just set the attribute. We'll get at
6740 it later with lookup_attribute. */
6744 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6745 *no_add_attrs
= true;
6751 /* Handle a "flatten" attribute; arguments as in
6752 struct attribute_spec.handler. */
6755 handle_flatten_attribute (tree
*node
, tree name
,
6756 tree args ATTRIBUTE_UNUSED
,
6757 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
6759 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6760 /* Do nothing else, just set the attribute. We'll get at
6761 it later with lookup_attribute. */
6765 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6766 *no_add_attrs
= true;
6772 /* Handle a "warning" or "error" attribute; arguments as in
6773 struct attribute_spec.handler. */
6776 handle_error_attribute (tree
*node
, tree name
, tree args
,
6777 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6779 if (TREE_CODE (*node
) == FUNCTION_DECL
6780 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
6781 /* Do nothing else, just set the attribute. We'll get at
6782 it later with lookup_attribute. */
6786 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6787 *no_add_attrs
= true;
6793 /* Handle a "used" attribute; arguments as in
6794 struct attribute_spec.handler. */
6797 handle_used_attribute (tree
*pnode
, tree name
, tree
ARG_UNUSED (args
),
6798 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6802 if (TREE_CODE (node
) == FUNCTION_DECL
6803 || (TREE_CODE (node
) == VAR_DECL
&& TREE_STATIC (node
))
6804 || (TREE_CODE (node
) == TYPE_DECL
))
6806 TREE_USED (node
) = 1;
6807 DECL_PRESERVE_P (node
) = 1;
6808 if (TREE_CODE (node
) == VAR_DECL
)
6809 DECL_READ_P (node
) = 1;
6813 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6814 *no_add_attrs
= true;
6820 /* Handle a "unused" attribute; arguments as in
6821 struct attribute_spec.handler. */
6824 handle_unused_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6825 int flags
, bool *no_add_attrs
)
6831 if (TREE_CODE (decl
) == PARM_DECL
6832 || TREE_CODE (decl
) == VAR_DECL
6833 || TREE_CODE (decl
) == FUNCTION_DECL
6834 || TREE_CODE (decl
) == LABEL_DECL
6835 || TREE_CODE (decl
) == TYPE_DECL
)
6837 TREE_USED (decl
) = 1;
6838 if (TREE_CODE (decl
) == VAR_DECL
6839 || TREE_CODE (decl
) == PARM_DECL
)
6840 DECL_READ_P (decl
) = 1;
6844 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6845 *no_add_attrs
= true;
6850 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6851 *node
= build_variant_type_copy (*node
);
6852 TREE_USED (*node
) = 1;
6858 /* Handle a "externally_visible" attribute; arguments as in
6859 struct attribute_spec.handler. */
6862 handle_externally_visible_attribute (tree
*pnode
, tree name
,
6863 tree
ARG_UNUSED (args
),
6864 int ARG_UNUSED (flags
),
6869 if (TREE_CODE (node
) == FUNCTION_DECL
|| TREE_CODE (node
) == VAR_DECL
)
6871 if ((!TREE_STATIC (node
) && TREE_CODE (node
) != FUNCTION_DECL
6872 && !DECL_EXTERNAL (node
)) || !TREE_PUBLIC (node
))
6874 warning (OPT_Wattributes
,
6875 "%qE attribute have effect only on public objects", name
);
6876 *no_add_attrs
= true;
6881 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6882 *no_add_attrs
= true;
6888 /* Handle a "const" attribute; arguments as in
6889 struct attribute_spec.handler. */
6892 handle_const_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6893 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6895 tree type
= TREE_TYPE (*node
);
6897 /* See FIXME comment on noreturn in c_common_attribute_table. */
6898 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6899 TREE_READONLY (*node
) = 1;
6900 else if (TREE_CODE (type
) == POINTER_TYPE
6901 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
6903 = build_pointer_type
6904 (build_type_variant (TREE_TYPE (type
), 1,
6905 TREE_THIS_VOLATILE (TREE_TYPE (type
))));
6908 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6909 *no_add_attrs
= true;
6915 /* Handle a "transparent_union" attribute; arguments as in
6916 struct attribute_spec.handler. */
6919 handle_transparent_union_attribute (tree
*node
, tree name
,
6920 tree
ARG_UNUSED (args
), int flags
,
6925 *no_add_attrs
= true;
6928 if (TREE_CODE (*node
) == TYPE_DECL
6929 && ! (flags
& ATTR_FLAG_CXX11
))
6930 node
= &TREE_TYPE (*node
);
6933 if (TREE_CODE (type
) == UNION_TYPE
)
6935 /* Make sure that the first field will work for a transparent union.
6936 If the type isn't complete yet, leave the check to the code in
6938 if (TYPE_SIZE (type
))
6940 tree first
= first_field (type
);
6941 if (first
== NULL_TREE
6942 || DECL_ARTIFICIAL (first
)
6943 || TYPE_MODE (type
) != DECL_MODE (first
))
6947 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6949 /* If the type isn't complete yet, setting the flag
6950 on a variant wouldn't ever be checked. */
6951 if (!TYPE_SIZE (type
))
6954 /* build_duplicate_type doesn't work for C++. */
6955 if (c_dialect_cxx ())
6958 /* A type variant isn't good enough, since we don't a cast
6959 to such a type removed as a no-op. */
6960 *node
= type
= build_duplicate_type (type
);
6963 TYPE_TRANSPARENT_AGGR (type
) = 1;
6968 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6972 /* Subroutine of handle_{con,de}structor_attribute. Evaluate ARGS to
6973 get the requested priority for a constructor or destructor,
6974 possibly issuing diagnostics for invalid or reserved
6977 static priority_type
6978 get_priority (tree args
, bool is_destructor
)
6984 return DEFAULT_INIT_PRIORITY
;
6986 if (!SUPPORTS_INIT_PRIORITY
)
6989 error ("destructor priorities are not supported");
6991 error ("constructor priorities are not supported");
6992 return DEFAULT_INIT_PRIORITY
;
6995 arg
= TREE_VALUE (args
);
6996 arg
= default_conversion (arg
);
6997 if (!host_integerp (arg
, /*pos=*/0)
6998 || !INTEGRAL_TYPE_P (TREE_TYPE (arg
)))
7001 pri
= tree_low_cst (arg
, /*pos=*/0);
7002 if (pri
< 0 || pri
> MAX_INIT_PRIORITY
)
7005 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
7009 "destructor priorities from 0 to %d are reserved "
7010 "for the implementation",
7011 MAX_RESERVED_INIT_PRIORITY
);
7014 "constructor priorities from 0 to %d are reserved "
7015 "for the implementation",
7016 MAX_RESERVED_INIT_PRIORITY
);
7022 error ("destructor priorities must be integers from 0 to %d inclusive",
7025 error ("constructor priorities must be integers from 0 to %d inclusive",
7027 return DEFAULT_INIT_PRIORITY
;
7030 /* Handle a "constructor" attribute; arguments as in
7031 struct attribute_spec.handler. */
7034 handle_constructor_attribute (tree
*node
, tree name
, tree args
,
7035 int ARG_UNUSED (flags
),
7039 tree type
= TREE_TYPE (decl
);
7041 if (TREE_CODE (decl
) == FUNCTION_DECL
7042 && TREE_CODE (type
) == FUNCTION_TYPE
7043 && decl_function_context (decl
) == 0)
7045 priority_type priority
;
7046 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
7047 priority
= get_priority (args
, /*is_destructor=*/false);
7048 SET_DECL_INIT_PRIORITY (decl
, priority
);
7049 TREE_USED (decl
) = 1;
7053 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7054 *no_add_attrs
= true;
7060 /* Handle a "destructor" attribute; arguments as in
7061 struct attribute_spec.handler. */
7064 handle_destructor_attribute (tree
*node
, tree name
, tree args
,
7065 int ARG_UNUSED (flags
),
7069 tree type
= TREE_TYPE (decl
);
7071 if (TREE_CODE (decl
) == FUNCTION_DECL
7072 && TREE_CODE (type
) == FUNCTION_TYPE
7073 && decl_function_context (decl
) == 0)
7075 priority_type priority
;
7076 DECL_STATIC_DESTRUCTOR (decl
) = 1;
7077 priority
= get_priority (args
, /*is_destructor=*/true);
7078 SET_DECL_FINI_PRIORITY (decl
, priority
);
7079 TREE_USED (decl
) = 1;
7083 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7084 *no_add_attrs
= true;
7090 /* Nonzero if the mode is a valid vector mode for this architecture.
7091 This returns nonzero even if there is no hardware support for the
7092 vector mode, but we can emulate with narrower modes. */
7095 vector_mode_valid_p (enum machine_mode mode
)
7097 enum mode_class mclass
= GET_MODE_CLASS (mode
);
7098 enum machine_mode innermode
;
7100 /* Doh! What's going on? */
7101 if (mclass
!= MODE_VECTOR_INT
7102 && mclass
!= MODE_VECTOR_FLOAT
7103 && mclass
!= MODE_VECTOR_FRACT
7104 && mclass
!= MODE_VECTOR_UFRACT
7105 && mclass
!= MODE_VECTOR_ACCUM
7106 && mclass
!= MODE_VECTOR_UACCUM
)
7109 /* Hardware support. Woo hoo! */
7110 if (targetm
.vector_mode_supported_p (mode
))
7113 innermode
= GET_MODE_INNER (mode
);
7115 /* We should probably return 1 if requesting V4DI and we have no DI,
7116 but we have V2DI, but this is probably very unlikely. */
7118 /* If we have support for the inner mode, we can safely emulate it.
7119 We may not have V2DI, but me can emulate with a pair of DIs. */
7120 return targetm
.scalar_mode_supported_p (innermode
);
7124 /* Handle a "mode" attribute; arguments as in
7125 struct attribute_spec.handler. */
7128 handle_mode_attribute (tree
*node
, tree name
, tree args
,
7129 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7132 tree ident
= TREE_VALUE (args
);
7134 *no_add_attrs
= true;
7136 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
7137 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7141 const char *p
= IDENTIFIER_POINTER (ident
);
7142 int len
= strlen (p
);
7143 enum machine_mode mode
= VOIDmode
;
7147 if (len
> 4 && p
[0] == '_' && p
[1] == '_'
7148 && p
[len
- 1] == '_' && p
[len
- 2] == '_')
7150 char *newp
= (char *) alloca (len
- 1);
7152 strcpy (newp
, &p
[2]);
7153 newp
[len
- 4] = '\0';
7157 /* Change this type to have a type with the specified mode.
7158 First check for the special modes. */
7159 if (!strcmp (p
, "byte"))
7161 else if (!strcmp (p
, "word"))
7163 else if (!strcmp (p
, "pointer"))
7165 else if (!strcmp (p
, "libgcc_cmp_return"))
7166 mode
= targetm
.libgcc_cmp_return_mode ();
7167 else if (!strcmp (p
, "libgcc_shift_count"))
7168 mode
= targetm
.libgcc_shift_count_mode ();
7169 else if (!strcmp (p
, "unwind_word"))
7170 mode
= targetm
.unwind_word_mode ();
7172 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
7173 if (!strcmp (p
, GET_MODE_NAME (j
)))
7175 mode
= (enum machine_mode
) j
;
7179 if (mode
== VOIDmode
)
7181 error ("unknown machine mode %qE", ident
);
7186 switch (GET_MODE_CLASS (mode
))
7189 case MODE_PARTIAL_INT
:
7191 case MODE_DECIMAL_FLOAT
:
7196 valid_mode
= targetm
.scalar_mode_supported_p (mode
);
7199 case MODE_COMPLEX_INT
:
7200 case MODE_COMPLEX_FLOAT
:
7201 valid_mode
= targetm
.scalar_mode_supported_p (GET_MODE_INNER (mode
));
7204 case MODE_VECTOR_INT
:
7205 case MODE_VECTOR_FLOAT
:
7206 case MODE_VECTOR_FRACT
:
7207 case MODE_VECTOR_UFRACT
:
7208 case MODE_VECTOR_ACCUM
:
7209 case MODE_VECTOR_UACCUM
:
7210 warning (OPT_Wattributes
, "specifying vector types with "
7211 "__attribute__ ((mode)) is deprecated");
7212 warning (OPT_Wattributes
,
7213 "use __attribute__ ((vector_size)) instead");
7214 valid_mode
= vector_mode_valid_p (mode
);
7222 error ("unable to emulate %qs", p
);
7226 if (POINTER_TYPE_P (type
))
7228 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
7229 tree (*fn
)(tree
, enum machine_mode
, bool);
7231 if (!targetm
.addr_space
.valid_pointer_mode (mode
, as
))
7233 error ("invalid pointer mode %qs", p
);
7237 if (TREE_CODE (type
) == POINTER_TYPE
)
7238 fn
= build_pointer_type_for_mode
;
7240 fn
= build_reference_type_for_mode
;
7241 typefm
= fn (TREE_TYPE (type
), mode
, false);
7245 /* For fixed-point modes, we need to test if the signness of type
7246 and the machine mode are consistent. */
7247 if (ALL_FIXED_POINT_MODE_P (mode
)
7248 && TYPE_UNSIGNED (type
) != UNSIGNED_FIXED_POINT_MODE_P (mode
))
7250 error ("signedness of type and machine mode %qs don%'t match", p
);
7253 /* For fixed-point modes, we need to pass saturating info. */
7254 typefm
= lang_hooks
.types
.type_for_mode (mode
,
7255 ALL_FIXED_POINT_MODE_P (mode
) ? TYPE_SATURATING (type
)
7256 : TYPE_UNSIGNED (type
));
7259 if (typefm
== NULL_TREE
)
7261 error ("no data type for mode %qs", p
);
7264 else if (TREE_CODE (type
) == ENUMERAL_TYPE
)
7266 /* For enumeral types, copy the precision from the integer
7267 type returned above. If not an INTEGER_TYPE, we can't use
7268 this mode for this type. */
7269 if (TREE_CODE (typefm
) != INTEGER_TYPE
)
7271 error ("cannot use mode %qs for enumeral types", p
);
7275 if (flags
& ATTR_FLAG_TYPE_IN_PLACE
)
7277 TYPE_PRECISION (type
) = TYPE_PRECISION (typefm
);
7282 /* We cannot build a type variant, as there's code that assumes
7283 that TYPE_MAIN_VARIANT has the same mode. This includes the
7284 debug generators. Instead, create a subrange type. This
7285 results in all of the enumeral values being emitted only once
7286 in the original, and the subtype gets them by reference. */
7287 if (TYPE_UNSIGNED (type
))
7288 typefm
= make_unsigned_type (TYPE_PRECISION (typefm
));
7290 typefm
= make_signed_type (TYPE_PRECISION (typefm
));
7291 TREE_TYPE (typefm
) = type
;
7294 else if (VECTOR_MODE_P (mode
)
7295 ? TREE_CODE (type
) != TREE_CODE (TREE_TYPE (typefm
))
7296 : TREE_CODE (type
) != TREE_CODE (typefm
))
7298 error ("mode %qs applied to inappropriate type", p
);
7308 /* Handle a "section" attribute; arguments as in
7309 struct attribute_spec.handler. */
7312 handle_section_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7313 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7317 if (targetm_common
.have_named_sections
)
7319 user_defined_section_attribute
= true;
7321 if ((TREE_CODE (decl
) == FUNCTION_DECL
7322 || TREE_CODE (decl
) == VAR_DECL
)
7323 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
7325 if (TREE_CODE (decl
) == VAR_DECL
7326 && current_function_decl
!= NULL_TREE
7327 && !TREE_STATIC (decl
))
7329 error_at (DECL_SOURCE_LOCATION (decl
),
7330 "section attribute cannot be specified for "
7332 *no_add_attrs
= true;
7335 /* The decl may have already been given a section attribute
7336 from a previous declaration. Ensure they match. */
7337 else if (DECL_SECTION_NAME (decl
) != NULL_TREE
7338 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl
)),
7339 TREE_STRING_POINTER (TREE_VALUE (args
))) != 0)
7341 error ("section of %q+D conflicts with previous declaration",
7343 *no_add_attrs
= true;
7345 else if (TREE_CODE (decl
) == VAR_DECL
7346 && !targetm
.have_tls
&& targetm
.emutls
.tmpl_section
7347 && DECL_THREAD_LOCAL_P (decl
))
7349 error ("section of %q+D cannot be overridden", *node
);
7350 *no_add_attrs
= true;
7353 DECL_SECTION_NAME (decl
) = TREE_VALUE (args
);
7357 error ("section attribute not allowed for %q+D", *node
);
7358 *no_add_attrs
= true;
7363 error_at (DECL_SOURCE_LOCATION (*node
),
7364 "section attributes are not supported for this target");
7365 *no_add_attrs
= true;
7371 /* Check whether ALIGN is a valid user-specified alignment. If so,
7372 return its base-2 log; if not, output an error and return -1. If
7373 ALLOW_ZERO then 0 is valid and should result in a return of -1 with
7376 check_user_alignment (const_tree align
, bool allow_zero
)
7380 if (TREE_CODE (align
) != INTEGER_CST
7381 || !INTEGRAL_TYPE_P (TREE_TYPE (align
)))
7383 error ("requested alignment is not an integer constant");
7386 else if (allow_zero
&& integer_zerop (align
))
7388 else if (tree_int_cst_sgn (align
) == -1
7389 || (i
= tree_log2 (align
)) == -1)
7391 error ("requested alignment is not a positive power of 2");
7394 else if (i
>= HOST_BITS_PER_INT
- BITS_PER_UNIT_LOG
)
7396 error ("requested alignment is too large");
7403 If in c++-11, check if the c++-11 alignment constraint with respect
7404 to fundamental alignment (in [dcl.align]) are satisfied. If not in
7405 c++-11 mode, does nothing.
7409 [* if the constant expression evaluates to a fundamental alignment,
7410 the alignment requirement of the declared entity shall be the
7411 specified fundamental alignment.
7413 * if the constant expression evaluates to an extended alignment
7414 and the implementation supports that alignment in the context
7415 of the declaration, the alignment of the declared entity shall
7418 * if the constant expression evaluates to an extended alignment
7419 and the implementation does not support that alignment in the
7420 context of the declaration, the program is ill-formed]. */
7423 check_cxx_fundamental_alignment_constraints (tree node
,
7427 bool alignment_too_large_p
= false;
7428 unsigned requested_alignment
= 1U << align_log
;
7429 unsigned max_align
= 0;
7431 if ((!(flags
& ATTR_FLAG_CXX11
) && !warn_cxx_compat
)
7432 || (node
== NULL_TREE
|| node
== error_mark_node
))
7435 if (cxx_fundamental_alignment_p (requested_alignment
))
7440 if (TREE_STATIC (node
))
7442 /* For file scope variables and static members, the target
7443 supports alignments that are at most
7444 MAX_OFILE_ALIGNMENT. */
7445 if (requested_alignment
> (max_align
= MAX_OFILE_ALIGNMENT
))
7446 alignment_too_large_p
= true;
7450 #ifdef BIGGEST_FIELD_ALIGNMENT
7451 #define MAX_TARGET_FIELD_ALIGNMENT BIGGEST_FIELD_ALIGNMENT
7453 #define MAX_TARGET_FIELD_ALIGNMENT BIGGEST_ALIGNMENT
7455 /* For non-static members, the target supports either
7456 alignments that at most either BIGGEST_FIELD_ALIGNMENT
7457 if it is defined or BIGGEST_ALIGNMENT. */
7458 max_align
= MAX_TARGET_FIELD_ALIGNMENT
;
7459 if (TREE_CODE (node
) == FIELD_DECL
7460 && requested_alignment
> (max_align
= MAX_TARGET_FIELD_ALIGNMENT
))
7461 alignment_too_large_p
= true;
7462 #undef MAX_TARGET_FIELD_ALIGNMENT
7463 /* For stack variables, the target supports at most
7464 MAX_STACK_ALIGNMENT. */
7465 else if (decl_function_context (node
) != NULL
7466 && requested_alignment
> (max_align
= MAX_STACK_ALIGNMENT
))
7467 alignment_too_large_p
= true;
7470 else if (TYPE_P (node
))
7472 /* Let's be liberal for types. */
7473 if (requested_alignment
> (max_align
= BIGGEST_ALIGNMENT
))
7474 alignment_too_large_p
= true;
7477 if (alignment_too_large_p
)
7478 pedwarn (input_location
, OPT_Wattributes
,
7479 "requested alignment %d is larger than %d",
7480 requested_alignment
, max_align
);
7482 return !alignment_too_large_p
;
7485 /* Handle a "aligned" attribute; arguments as in
7486 struct attribute_spec.handler. */
7489 handle_aligned_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7490 int flags
, bool *no_add_attrs
)
7492 tree decl
= NULL_TREE
;
7495 tree align_expr
= (args
? TREE_VALUE (args
)
7496 : size_int (ATTRIBUTE_ALIGNED_VALUE
/ BITS_PER_UNIT
));
7502 type
= &TREE_TYPE (decl
);
7503 is_type
= TREE_CODE (*node
) == TYPE_DECL
;
7505 else if (TYPE_P (*node
))
7506 type
= node
, is_type
= 1;
7508 if ((i
= check_user_alignment (align_expr
, false)) == -1
7509 || !check_cxx_fundamental_alignment_constraints (*node
, i
, flags
))
7510 *no_add_attrs
= true;
7513 if ((flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7514 /* OK, modify the type in place. */;
7515 /* If we have a TYPE_DECL, then copy the type, so that we
7516 don't accidentally modify a builtin type. See pushdecl. */
7517 else if (decl
&& TREE_TYPE (decl
) != error_mark_node
7518 && DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
)
7520 tree tt
= TREE_TYPE (decl
);
7521 *type
= build_variant_type_copy (*type
);
7522 DECL_ORIGINAL_TYPE (decl
) = tt
;
7523 TYPE_NAME (*type
) = decl
;
7524 TREE_USED (*type
) = TREE_USED (decl
);
7525 TREE_TYPE (decl
) = *type
;
7528 *type
= build_variant_type_copy (*type
);
7530 TYPE_ALIGN (*type
) = (1U << i
) * BITS_PER_UNIT
;
7531 TYPE_USER_ALIGN (*type
) = 1;
7533 else if (! VAR_OR_FUNCTION_DECL_P (decl
)
7534 && TREE_CODE (decl
) != FIELD_DECL
)
7536 error ("alignment may not be specified for %q+D", decl
);
7537 *no_add_attrs
= true;
7539 else if (DECL_USER_ALIGN (decl
)
7540 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
7541 /* C++-11 [dcl.align/4]:
7543 When multiple alignment-specifiers are specified for an
7544 entity, the alignment requirement shall be set to the
7545 strictest specified alignment.
7547 This formally comes from the c++11 specification but we are
7548 doing it for the GNU attribute syntax as well. */
7549 *no_add_attrs
= true;
7550 else if (TREE_CODE (decl
) == FUNCTION_DECL
7551 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
7553 if (DECL_USER_ALIGN (decl
))
7554 error ("alignment for %q+D was previously specified as %d "
7555 "and may not be decreased", decl
,
7556 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
7558 error ("alignment for %q+D must be at least %d", decl
,
7559 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
7560 *no_add_attrs
= true;
7564 DECL_ALIGN (decl
) = (1U << i
) * BITS_PER_UNIT
;
7565 DECL_USER_ALIGN (decl
) = 1;
7571 /* Handle a "weak" attribute; arguments as in
7572 struct attribute_spec.handler. */
7575 handle_weak_attribute (tree
*node
, tree name
,
7576 tree
ARG_UNUSED (args
),
7577 int ARG_UNUSED (flags
),
7578 bool * ARG_UNUSED (no_add_attrs
))
7580 if (TREE_CODE (*node
) == FUNCTION_DECL
7581 && DECL_DECLARED_INLINE_P (*node
))
7583 warning (OPT_Wattributes
, "inline function %q+D declared weak", *node
);
7584 *no_add_attrs
= true;
7586 else if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
7588 error ("indirect function %q+D cannot be declared weak", *node
);
7589 *no_add_attrs
= true;
7592 else if (TREE_CODE (*node
) == FUNCTION_DECL
7593 || TREE_CODE (*node
) == VAR_DECL
)
7594 declare_weak (*node
);
7596 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7601 /* Handle an "alias" or "ifunc" attribute; arguments as in
7602 struct attribute_spec.handler, except that IS_ALIAS tells us
7603 whether this is an alias as opposed to ifunc attribute. */
7606 handle_alias_ifunc_attribute (bool is_alias
, tree
*node
, tree name
, tree args
,
7611 if (TREE_CODE (decl
) != FUNCTION_DECL
7612 && (!is_alias
|| TREE_CODE (decl
) != VAR_DECL
))
7614 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7615 *no_add_attrs
= true;
7617 else if ((TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INITIAL (decl
))
7618 || (TREE_CODE (decl
) != FUNCTION_DECL
7619 && TREE_PUBLIC (decl
) && !DECL_EXTERNAL (decl
))
7620 /* A static variable declaration is always a tentative definition,
7621 but the alias is a non-tentative definition which overrides. */
7622 || (TREE_CODE (decl
) != FUNCTION_DECL
7623 && ! TREE_PUBLIC (decl
) && DECL_INITIAL (decl
)))
7625 error ("%q+D defined both normally and as %qE attribute", decl
, name
);
7626 *no_add_attrs
= true;
7630 && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
7631 || lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
))))
7633 error ("weak %q+D cannot be defined %qE", decl
, name
);
7634 *no_add_attrs
= true;
7638 /* Note that the very first time we process a nested declaration,
7639 decl_function_context will not be set. Indeed, *would* never
7640 be set except for the DECL_INITIAL/DECL_EXTERNAL frobbery that
7641 we do below. After such frobbery, pushdecl would set the context.
7642 In any case, this is never what we want. */
7643 else if (decl_function_context (decl
) == 0 && current_function_decl
== NULL
)
7647 id
= TREE_VALUE (args
);
7648 if (TREE_CODE (id
) != STRING_CST
)
7650 error ("attribute %qE argument not a string", name
);
7651 *no_add_attrs
= true;
7654 id
= get_identifier (TREE_STRING_POINTER (id
));
7655 /* This counts as a use of the object pointed to. */
7658 if (TREE_CODE (decl
) == FUNCTION_DECL
)
7659 DECL_INITIAL (decl
) = error_mark_node
;
7661 TREE_STATIC (decl
) = 1;
7664 /* ifuncs are also aliases, so set that attribute too. */
7665 DECL_ATTRIBUTES (decl
)
7666 = tree_cons (get_identifier ("alias"), args
, DECL_ATTRIBUTES (decl
));
7670 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7671 *no_add_attrs
= true;
7677 /* Handle an "alias" or "ifunc" attribute; arguments as in
7678 struct attribute_spec.handler. */
7681 handle_ifunc_attribute (tree
*node
, tree name
, tree args
,
7682 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7684 return handle_alias_ifunc_attribute (false, node
, name
, args
, no_add_attrs
);
7687 /* Handle an "alias" or "ifunc" attribute; arguments as in
7688 struct attribute_spec.handler. */
7691 handle_alias_attribute (tree
*node
, tree name
, tree args
,
7692 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7694 return handle_alias_ifunc_attribute (true, node
, name
, args
, no_add_attrs
);
7697 /* Handle a "weakref" attribute; arguments as in struct
7698 attribute_spec.handler. */
7701 handle_weakref_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7702 int flags
, bool *no_add_attrs
)
7704 tree attr
= NULL_TREE
;
7706 /* We must ignore the attribute when it is associated with
7707 local-scoped decls, since attribute alias is ignored and many
7708 such symbols do not even have a DECL_WEAK field. */
7709 if (decl_function_context (*node
)
7710 || current_function_decl
7711 || (TREE_CODE (*node
) != VAR_DECL
&& TREE_CODE (*node
) != FUNCTION_DECL
))
7713 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7714 *no_add_attrs
= true;
7718 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
7720 error ("indirect function %q+D cannot be declared weakref", *node
);
7721 *no_add_attrs
= true;
7725 /* The idea here is that `weakref("name")' mutates into `weakref,
7726 alias("name")', and weakref without arguments, in turn,
7727 implicitly adds weak. */
7731 attr
= tree_cons (get_identifier ("alias"), args
, attr
);
7732 attr
= tree_cons (get_identifier ("weakref"), NULL_TREE
, attr
);
7734 *no_add_attrs
= true;
7736 decl_attributes (node
, attr
, flags
);
7740 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node
)))
7741 error_at (DECL_SOURCE_LOCATION (*node
),
7742 "weakref attribute must appear before alias attribute");
7744 /* Can't call declare_weak because it wants this to be TREE_PUBLIC,
7745 and that isn't supported; and because it wants to add it to
7746 the list of weak decls, which isn't helpful. */
7747 DECL_WEAK (*node
) = 1;
7753 /* Handle an "visibility" attribute; arguments as in
7754 struct attribute_spec.handler. */
7757 handle_visibility_attribute (tree
*node
, tree name
, tree args
,
7758 int ARG_UNUSED (flags
),
7759 bool *ARG_UNUSED (no_add_attrs
))
7762 tree id
= TREE_VALUE (args
);
7763 enum symbol_visibility vis
;
7767 if (TREE_CODE (*node
) == ENUMERAL_TYPE
)
7769 else if (TREE_CODE (*node
) != RECORD_TYPE
&& TREE_CODE (*node
) != UNION_TYPE
)
7771 warning (OPT_Wattributes
, "%qE attribute ignored on non-class types",
7775 else if (TYPE_FIELDS (*node
))
7777 error ("%qE attribute ignored because %qT is already defined",
7782 else if (decl_function_context (decl
) != 0 || !TREE_PUBLIC (decl
))
7784 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7788 if (TREE_CODE (id
) != STRING_CST
)
7790 error ("visibility argument not a string");
7794 /* If this is a type, set the visibility on the type decl. */
7797 decl
= TYPE_NAME (decl
);
7800 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
7802 warning (OPT_Wattributes
, "%qE attribute ignored on types",
7808 if (strcmp (TREE_STRING_POINTER (id
), "default") == 0)
7809 vis
= VISIBILITY_DEFAULT
;
7810 else if (strcmp (TREE_STRING_POINTER (id
), "internal") == 0)
7811 vis
= VISIBILITY_INTERNAL
;
7812 else if (strcmp (TREE_STRING_POINTER (id
), "hidden") == 0)
7813 vis
= VISIBILITY_HIDDEN
;
7814 else if (strcmp (TREE_STRING_POINTER (id
), "protected") == 0)
7815 vis
= VISIBILITY_PROTECTED
;
7818 error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
7819 vis
= VISIBILITY_DEFAULT
;
7822 if (DECL_VISIBILITY_SPECIFIED (decl
)
7823 && vis
!= DECL_VISIBILITY (decl
))
7825 tree attributes
= (TYPE_P (*node
)
7826 ? TYPE_ATTRIBUTES (*node
)
7827 : DECL_ATTRIBUTES (decl
));
7828 if (lookup_attribute ("visibility", attributes
))
7829 error ("%qD redeclared with different visibility", decl
);
7830 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
7831 && lookup_attribute ("dllimport", attributes
))
7832 error ("%qD was declared %qs which implies default visibility",
7834 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
7835 && lookup_attribute ("dllexport", attributes
))
7836 error ("%qD was declared %qs which implies default visibility",
7840 DECL_VISIBILITY (decl
) = vis
;
7841 DECL_VISIBILITY_SPECIFIED (decl
) = 1;
7843 /* Go ahead and attach the attribute to the node as well. This is needed
7844 so we can determine whether we have VISIBILITY_DEFAULT because the
7845 visibility was not specified, or because it was explicitly overridden
7846 from the containing scope. */
7851 /* Determine the ELF symbol visibility for DECL, which is either a
7852 variable or a function. It is an error to use this function if a
7853 definition of DECL is not available in this translation unit.
7854 Returns true if the final visibility has been determined by this
7855 function; false if the caller is free to make additional
7859 c_determine_visibility (tree decl
)
7861 gcc_assert (TREE_CODE (decl
) == VAR_DECL
7862 || TREE_CODE (decl
) == FUNCTION_DECL
);
7864 /* If the user explicitly specified the visibility with an
7865 attribute, honor that. DECL_VISIBILITY will have been set during
7866 the processing of the attribute. We check for an explicit
7867 attribute, rather than just checking DECL_VISIBILITY_SPECIFIED,
7868 to distinguish the use of an attribute from the use of a "#pragma
7869 GCC visibility push(...)"; in the latter case we still want other
7870 considerations to be able to overrule the #pragma. */
7871 if (lookup_attribute ("visibility", DECL_ATTRIBUTES (decl
))
7872 || (TARGET_DLLIMPORT_DECL_ATTRIBUTES
7873 && (lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl
))
7874 || lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl
)))))
7877 /* Set default visibility to whatever the user supplied with
7878 visibility_specified depending on #pragma GCC visibility. */
7879 if (!DECL_VISIBILITY_SPECIFIED (decl
))
7881 if (visibility_options
.inpragma
7882 || DECL_VISIBILITY (decl
) != default_visibility
)
7884 DECL_VISIBILITY (decl
) = default_visibility
;
7885 DECL_VISIBILITY_SPECIFIED (decl
) = visibility_options
.inpragma
;
7886 /* If visibility changed and DECL already has DECL_RTL, ensure
7887 symbol flags are updated. */
7888 if (((TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
))
7889 || TREE_CODE (decl
) == FUNCTION_DECL
)
7890 && DECL_RTL_SET_P (decl
))
7891 make_decl_rtl (decl
);
7897 /* Handle an "tls_model" attribute; arguments as in
7898 struct attribute_spec.handler. */
7901 handle_tls_model_attribute (tree
*node
, tree name
, tree args
,
7902 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7906 enum tls_model kind
;
7908 *no_add_attrs
= true;
7910 if (TREE_CODE (decl
) != VAR_DECL
|| !DECL_THREAD_LOCAL_P (decl
))
7912 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7916 kind
= DECL_TLS_MODEL (decl
);
7917 id
= TREE_VALUE (args
);
7918 if (TREE_CODE (id
) != STRING_CST
)
7920 error ("tls_model argument not a string");
7924 if (!strcmp (TREE_STRING_POINTER (id
), "local-exec"))
7925 kind
= TLS_MODEL_LOCAL_EXEC
;
7926 else if (!strcmp (TREE_STRING_POINTER (id
), "initial-exec"))
7927 kind
= TLS_MODEL_INITIAL_EXEC
;
7928 else if (!strcmp (TREE_STRING_POINTER (id
), "local-dynamic"))
7929 kind
= optimize
? TLS_MODEL_LOCAL_DYNAMIC
: TLS_MODEL_GLOBAL_DYNAMIC
;
7930 else if (!strcmp (TREE_STRING_POINTER (id
), "global-dynamic"))
7931 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
7933 error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
7935 DECL_TLS_MODEL (decl
) = kind
;
7939 /* Handle a "no_instrument_function" attribute; arguments as in
7940 struct attribute_spec.handler. */
7943 handle_no_instrument_function_attribute (tree
*node
, tree name
,
7944 tree
ARG_UNUSED (args
),
7945 int ARG_UNUSED (flags
),
7950 if (TREE_CODE (decl
) != FUNCTION_DECL
)
7952 error_at (DECL_SOURCE_LOCATION (decl
),
7953 "%qE attribute applies only to functions", name
);
7954 *no_add_attrs
= true;
7956 else if (DECL_INITIAL (decl
))
7958 error_at (DECL_SOURCE_LOCATION (decl
),
7959 "can%'t set %qE attribute after definition", name
);
7960 *no_add_attrs
= true;
7963 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
7968 /* Handle a "malloc" attribute; arguments as in
7969 struct attribute_spec.handler. */
7972 handle_malloc_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7973 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7975 if (TREE_CODE (*node
) == FUNCTION_DECL
7976 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node
))))
7977 DECL_IS_MALLOC (*node
) = 1;
7980 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7981 *no_add_attrs
= true;
7987 /* Handle a "alloc_size" attribute; arguments as in
7988 struct attribute_spec.handler. */
7991 handle_alloc_size_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7992 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7994 unsigned arg_count
= type_num_arguments (*node
);
7995 for (; args
; args
= TREE_CHAIN (args
))
7997 tree position
= TREE_VALUE (args
);
7999 if (TREE_CODE (position
) != INTEGER_CST
8000 || TREE_INT_CST_HIGH (position
)
8001 || TREE_INT_CST_LOW (position
) < 1
8002 || TREE_INT_CST_LOW (position
) > arg_count
)
8004 warning (OPT_Wattributes
,
8005 "alloc_size parameter outside range");
8006 *no_add_attrs
= true;
8013 /* Handle a "fn spec" attribute; arguments as in
8014 struct attribute_spec.handler. */
8017 handle_fnspec_attribute (tree
*node ATTRIBUTE_UNUSED
, tree
ARG_UNUSED (name
),
8018 tree args
, int ARG_UNUSED (flags
),
8019 bool *no_add_attrs ATTRIBUTE_UNUSED
)
8022 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
8023 && !TREE_CHAIN (args
));
8027 /* Handle a "bnd_variable_size" attribute; arguments as in
8028 struct attribute_spec.handler. */
8031 handle_bnd_variable_size_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8032 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8034 if (TREE_CODE (*node
) != FIELD_DECL
)
8036 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8037 *no_add_attrs
= true;
8043 /* Handle a "bnd_legacy" attribute; arguments as in
8044 struct attribute_spec.handler. */
8047 handle_bnd_legacy (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8048 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8050 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8052 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8053 *no_add_attrs
= true;
8059 /* Handle a "warn_unused" attribute; arguments as in
8060 struct attribute_spec.handler. */
8063 handle_warn_unused_attribute (tree
*node
, tree name
,
8064 tree args ATTRIBUTE_UNUSED
,
8065 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
8068 /* Do nothing else, just set the attribute. We'll get at
8069 it later with lookup_attribute. */
8073 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8074 *no_add_attrs
= true;
8080 /* Handle an "omp declare simd" attribute; arguments as in
8081 struct attribute_spec.handler. */
8084 handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int, bool *)
8089 /* Handle an "omp declare target" attribute; arguments as in
8090 struct attribute_spec.handler. */
8093 handle_omp_declare_target_attribute (tree
*, tree
, tree
, int, bool *)
8098 /* Handle a "returns_twice" attribute; arguments as in
8099 struct attribute_spec.handler. */
8102 handle_returns_twice_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8103 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8105 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8106 DECL_IS_RETURNS_TWICE (*node
) = 1;
8109 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8110 *no_add_attrs
= true;
8116 /* Handle a "no_limit_stack" attribute; arguments as in
8117 struct attribute_spec.handler. */
8120 handle_no_limit_stack_attribute (tree
*node
, tree name
,
8121 tree
ARG_UNUSED (args
),
8122 int ARG_UNUSED (flags
),
8127 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8129 error_at (DECL_SOURCE_LOCATION (decl
),
8130 "%qE attribute applies only to functions", name
);
8131 *no_add_attrs
= true;
8133 else if (DECL_INITIAL (decl
))
8135 error_at (DECL_SOURCE_LOCATION (decl
),
8136 "can%'t set %qE attribute after definition", name
);
8137 *no_add_attrs
= true;
8140 DECL_NO_LIMIT_STACK (decl
) = 1;
8145 /* Handle a "pure" attribute; arguments as in
8146 struct attribute_spec.handler. */
8149 handle_pure_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8150 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8152 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8153 DECL_PURE_P (*node
) = 1;
8154 /* ??? TODO: Support types. */
8157 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8158 *no_add_attrs
= true;
8164 /* Digest an attribute list destined for a transactional memory statement.
8165 ALLOWED is the set of attributes that are allowed for this statement;
8166 return the attribute we parsed. Multiple attributes are never allowed. */
8169 parse_tm_stmt_attr (tree attrs
, int allowed
)
8174 for ( ; attrs
; attrs
= TREE_CHAIN (attrs
))
8176 tree a
= TREE_PURPOSE (attrs
);
8179 if (is_attribute_p ("outer", a
))
8180 m
= TM_STMT_ATTR_OUTER
;
8182 if ((m
& allowed
) == 0)
8184 warning (OPT_Wattributes
, "%qE attribute directive ignored", a
);
8193 else if (m_seen
== m
)
8194 warning (OPT_Wattributes
, "%qE attribute duplicated", a
);
8196 warning (OPT_Wattributes
, "%qE attribute follows %qE", a
, a_seen
);
8202 /* Transform a TM attribute name into a maskable integer and back.
8203 Note that NULL (i.e. no attribute) is mapped to UNKNOWN, corresponding
8204 to how the lack of an attribute is treated. */
8207 tm_attr_to_mask (tree attr
)
8211 if (is_attribute_p ("transaction_safe", attr
))
8212 return TM_ATTR_SAFE
;
8213 if (is_attribute_p ("transaction_callable", attr
))
8214 return TM_ATTR_CALLABLE
;
8215 if (is_attribute_p ("transaction_pure", attr
))
8216 return TM_ATTR_PURE
;
8217 if (is_attribute_p ("transaction_unsafe", attr
))
8218 return TM_ATTR_IRREVOCABLE
;
8219 if (is_attribute_p ("transaction_may_cancel_outer", attr
))
8220 return TM_ATTR_MAY_CANCEL_OUTER
;
8225 tm_mask_to_attr (int mask
)
8231 str
= "transaction_safe";
8233 case TM_ATTR_CALLABLE
:
8234 str
= "transaction_callable";
8237 str
= "transaction_pure";
8239 case TM_ATTR_IRREVOCABLE
:
8240 str
= "transaction_unsafe";
8242 case TM_ATTR_MAY_CANCEL_OUTER
:
8243 str
= "transaction_may_cancel_outer";
8248 return get_identifier (str
);
8251 /* Return the first TM attribute seen in LIST. */
8254 find_tm_attribute (tree list
)
8256 for (; list
; list
= TREE_CHAIN (list
))
8258 tree name
= TREE_PURPOSE (list
);
8259 if (tm_attr_to_mask (name
) != 0)
8265 /* Handle the TM attributes; arguments as in struct attribute_spec.handler.
8266 Here we accept only function types, and verify that none of the other
8267 function TM attributes are also applied. */
8268 /* ??? We need to accept class types for C++, but not C. This greatly
8269 complicates this function, since we can no longer rely on the extra
8270 processing given by function_type_required. */
8273 handle_tm_attribute (tree
*node
, tree name
, tree args
,
8274 int flags
, bool *no_add_attrs
)
8276 /* Only one path adds the attribute; others don't. */
8277 *no_add_attrs
= true;
8279 switch (TREE_CODE (*node
))
8283 /* Only tm_callable and tm_safe apply to classes. */
8284 if (tm_attr_to_mask (name
) & ~(TM_ATTR_SAFE
| TM_ATTR_CALLABLE
))
8291 tree old_name
= find_tm_attribute (TYPE_ATTRIBUTES (*node
));
8292 if (old_name
== name
)
8294 else if (old_name
!= NULL_TREE
)
8295 error ("type was previously declared %qE", old_name
);
8297 *no_add_attrs
= false;
8303 enum tree_code subcode
= TREE_CODE (TREE_TYPE (*node
));
8304 if (subcode
== FUNCTION_TYPE
|| subcode
== METHOD_TYPE
)
8306 tree fn_tmp
= TREE_TYPE (*node
);
8307 decl_attributes (&fn_tmp
, tree_cons (name
, args
, NULL
), 0);
8308 *node
= build_pointer_type (fn_tmp
);
8315 /* If a function is next, pass it on to be tried next. */
8316 if (flags
& (int) ATTR_FLAG_FUNCTION_NEXT
)
8317 return tree_cons (name
, args
, NULL
);
8320 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8327 /* Handle the TM_WRAP attribute; arguments as in
8328 struct attribute_spec.handler. */
8331 handle_tm_wrap_attribute (tree
*node
, tree name
, tree args
,
8332 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8336 /* We don't need the attribute even on success, since we
8337 record the entry in an external table. */
8338 *no_add_attrs
= true;
8340 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8341 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8344 tree wrap_decl
= TREE_VALUE (args
);
8345 if (TREE_CODE (wrap_decl
) != IDENTIFIER_NODE
8346 && TREE_CODE (wrap_decl
) != VAR_DECL
8347 && TREE_CODE (wrap_decl
) != FUNCTION_DECL
)
8348 error ("%qE argument not an identifier", name
);
8351 if (TREE_CODE (wrap_decl
) == IDENTIFIER_NODE
)
8352 wrap_decl
= lookup_name (wrap_decl
);
8353 if (wrap_decl
&& TREE_CODE (wrap_decl
) == FUNCTION_DECL
)
8355 if (lang_hooks
.types_compatible_p (TREE_TYPE (decl
),
8356 TREE_TYPE (wrap_decl
)))
8357 record_tm_replacement (wrap_decl
, decl
);
8359 error ("%qD is not compatible with %qD", wrap_decl
, decl
);
8362 error ("transaction_wrap argument is not a function");
8369 /* Ignore the given attribute. Used when this attribute may be usefully
8370 overridden by the target, but is not used generically. */
8373 ignore_attribute (tree
* ARG_UNUSED (node
), tree
ARG_UNUSED (name
),
8374 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
8377 *no_add_attrs
= true;
8381 /* Handle a "no vops" attribute; arguments as in
8382 struct attribute_spec.handler. */
8385 handle_novops_attribute (tree
*node
, tree
ARG_UNUSED (name
),
8386 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
8387 bool *ARG_UNUSED (no_add_attrs
))
8389 gcc_assert (TREE_CODE (*node
) == FUNCTION_DECL
);
8390 DECL_IS_NOVOPS (*node
) = 1;
8394 /* Handle a "deprecated" attribute; arguments as in
8395 struct attribute_spec.handler. */
8398 handle_deprecated_attribute (tree
*node
, tree name
,
8399 tree args
, int flags
,
8402 tree type
= NULL_TREE
;
8404 tree what
= NULL_TREE
;
8407 *no_add_attrs
= true;
8408 else if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
8410 error ("deprecated message is not a string");
8411 *no_add_attrs
= true;
8417 type
= TREE_TYPE (decl
);
8419 if (TREE_CODE (decl
) == TYPE_DECL
8420 || TREE_CODE (decl
) == PARM_DECL
8421 || TREE_CODE (decl
) == VAR_DECL
8422 || TREE_CODE (decl
) == FUNCTION_DECL
8423 || TREE_CODE (decl
) == FIELD_DECL
8424 || objc_method_decl (TREE_CODE (decl
)))
8425 TREE_DEPRECATED (decl
) = 1;
8429 else if (TYPE_P (*node
))
8431 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
8432 *node
= build_variant_type_copy (*node
);
8433 TREE_DEPRECATED (*node
) = 1;
8441 *no_add_attrs
= true;
8442 if (type
&& TYPE_NAME (type
))
8444 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
8445 what
= TYPE_NAME (*node
);
8446 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
8447 && DECL_NAME (TYPE_NAME (type
)))
8448 what
= DECL_NAME (TYPE_NAME (type
));
8451 warning (OPT_Wattributes
, "%qE attribute ignored for %qE", name
, what
);
8453 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8459 /* Handle a "vector_size" attribute; arguments as in
8460 struct attribute_spec.handler. */
8463 handle_vector_size_attribute (tree
*node
, tree name
, tree args
,
8464 int ARG_UNUSED (flags
),
8467 unsigned HOST_WIDE_INT vecsize
, nunits
;
8468 enum machine_mode orig_mode
;
8469 tree type
= *node
, new_type
, size
;
8471 *no_add_attrs
= true;
8473 size
= TREE_VALUE (args
);
8475 if (!host_integerp (size
, 1))
8477 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8481 /* Get the vector size (in bytes). */
8482 vecsize
= tree_low_cst (size
, 1);
8484 /* We need to provide for vector pointers, vector arrays, and
8485 functions returning vectors. For example:
8487 __attribute__((vector_size(16))) short *foo;
8489 In this case, the mode is SI, but the type being modified is
8490 HI, so we need to look further. */
8492 while (POINTER_TYPE_P (type
)
8493 || TREE_CODE (type
) == FUNCTION_TYPE
8494 || TREE_CODE (type
) == METHOD_TYPE
8495 || TREE_CODE (type
) == ARRAY_TYPE
8496 || TREE_CODE (type
) == OFFSET_TYPE
)
8497 type
= TREE_TYPE (type
);
8499 /* Get the mode of the type being modified. */
8500 orig_mode
= TYPE_MODE (type
);
8502 if ((!INTEGRAL_TYPE_P (type
)
8503 && !SCALAR_FLOAT_TYPE_P (type
)
8504 && !FIXED_POINT_TYPE_P (type
))
8505 || (!SCALAR_FLOAT_MODE_P (orig_mode
)
8506 && GET_MODE_CLASS (orig_mode
) != MODE_INT
8507 && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode
))
8508 || !host_integerp (TYPE_SIZE_UNIT (type
), 1)
8509 || TREE_CODE (type
) == BOOLEAN_TYPE
)
8511 error ("invalid vector type for attribute %qE", name
);
8515 if (vecsize
% tree_low_cst (TYPE_SIZE_UNIT (type
), 1))
8517 error ("vector size not an integral multiple of component size");
8523 error ("zero vector size");
8527 /* Calculate how many units fit in the vector. */
8528 nunits
= vecsize
/ tree_low_cst (TYPE_SIZE_UNIT (type
), 1);
8529 if (nunits
& (nunits
- 1))
8531 error ("number of components of the vector not a power of two");
8535 new_type
= build_vector_type (type
, nunits
);
8537 /* Build back pointers if needed. */
8538 *node
= lang_hooks
.types
.reconstruct_complex_type (*node
, new_type
);
8543 /* Handle the "nonnull" attribute. */
8545 handle_nonnull_attribute (tree
*node
, tree
ARG_UNUSED (name
),
8546 tree args
, int ARG_UNUSED (flags
),
8550 unsigned HOST_WIDE_INT attr_arg_num
;
8552 /* If no arguments are specified, all pointer arguments should be
8553 non-null. Verify a full prototype is given so that the arguments
8554 will have the correct types when we actually check them later. */
8557 if (!prototype_p (type
))
8559 error ("nonnull attribute without arguments on a non-prototype");
8560 *no_add_attrs
= true;
8565 /* Argument list specified. Verify that each argument number references
8566 a pointer argument. */
8567 for (attr_arg_num
= 1; args
; args
= TREE_CHAIN (args
))
8569 unsigned HOST_WIDE_INT arg_num
= 0, ck_num
;
8571 if (!get_nonnull_operand (TREE_VALUE (args
), &arg_num
))
8573 error ("nonnull argument has invalid operand number (argument %lu)",
8574 (unsigned long) attr_arg_num
);
8575 *no_add_attrs
= true;
8579 if (prototype_p (type
))
8581 function_args_iterator iter
;
8584 function_args_iter_init (&iter
, type
);
8585 for (ck_num
= 1; ; ck_num
++, function_args_iter_next (&iter
))
8587 argument
= function_args_iter_cond (&iter
);
8588 if (argument
== NULL_TREE
|| ck_num
== arg_num
)
8593 || TREE_CODE (argument
) == VOID_TYPE
)
8595 error ("nonnull argument with out-of-range operand number (argument %lu, operand %lu)",
8596 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
8597 *no_add_attrs
= true;
8601 if (TREE_CODE (argument
) != POINTER_TYPE
)
8603 error ("nonnull argument references non-pointer operand (argument %lu, operand %lu)",
8604 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
8605 *no_add_attrs
= true;
8614 /* Check the argument list of a function call for null in argument slots
8615 that are marked as requiring a non-null pointer argument. The NARGS
8616 arguments are passed in the array ARGARRAY.
8620 check_function_nonnull (tree attrs
, int nargs
, tree
*argarray
)
8625 attrs
= lookup_attribute ("nonnull", attrs
);
8626 if (attrs
== NULL_TREE
)
8630 /* See if any of the nonnull attributes has no arguments. If so,
8631 then every pointer argument is checked (in which case the check
8632 for pointer type is done in check_nonnull_arg). */
8633 if (TREE_VALUE (a
) != NULL_TREE
)
8635 a
= lookup_attribute ("nonnull", TREE_CHAIN (a
));
8636 while (a
!= NULL_TREE
&& TREE_VALUE (a
) != NULL_TREE
);
8639 for (i
= 0; i
< nargs
; i
++)
8640 check_function_arguments_recurse (check_nonnull_arg
, NULL
, argarray
[i
],
8644 /* Walk the argument list. If we encounter an argument number we
8645 should check for non-null, do it. */
8646 for (i
= 0; i
< nargs
; i
++)
8648 for (a
= attrs
; ; a
= TREE_CHAIN (a
))
8650 a
= lookup_attribute ("nonnull", a
);
8651 if (a
== NULL_TREE
|| nonnull_check_p (TREE_VALUE (a
), i
+ 1))
8656 check_function_arguments_recurse (check_nonnull_arg
, NULL
,
8657 argarray
[i
], i
+ 1);
8662 /* Check that the Nth argument of a function call (counting backwards
8663 from the end) is a (pointer)0. The NARGS arguments are passed in the
8667 check_function_sentinel (const_tree fntype
, int nargs
, tree
*argarray
)
8669 tree attr
= lookup_attribute ("sentinel", TYPE_ATTRIBUTES (fntype
));
8676 function_args_iterator iter
;
8679 /* Skip over the named arguments. */
8680 FOREACH_FUNCTION_ARGS (fntype
, t
, iter
)
8687 if (TREE_VALUE (attr
))
8689 tree p
= TREE_VALUE (TREE_VALUE (attr
));
8690 pos
= TREE_INT_CST_LOW (p
);
8693 /* The sentinel must be one of the varargs, i.e.
8694 in position >= the number of fixed arguments. */
8695 if ((nargs
- 1 - pos
) < len
)
8697 warning (OPT_Wformat_
,
8698 "not enough variable arguments to fit a sentinel");
8702 /* Validate the sentinel. */
8703 sentinel
= argarray
[nargs
- 1 - pos
];
8704 if ((!POINTER_TYPE_P (TREE_TYPE (sentinel
))
8705 || !integer_zerop (sentinel
))
8706 /* Although __null (in C++) is only an integer we allow it
8707 nevertheless, as we are guaranteed that it's exactly
8708 as wide as a pointer, and we don't want to force
8709 users to cast the NULL they have written there.
8710 We warn with -Wstrict-null-sentinel, though. */
8711 && (warn_strict_null_sentinel
|| null_node
!= sentinel
))
8712 warning (OPT_Wformat_
, "missing sentinel in function call");
8716 /* Helper for check_function_nonnull; given a list of operands which
8717 must be non-null in ARGS, determine if operand PARAM_NUM should be
8721 nonnull_check_p (tree args
, unsigned HOST_WIDE_INT param_num
)
8723 unsigned HOST_WIDE_INT arg_num
= 0;
8725 for (; args
; args
= TREE_CHAIN (args
))
8727 bool found
= get_nonnull_operand (TREE_VALUE (args
), &arg_num
);
8731 if (arg_num
== param_num
)
8737 /* Check that the function argument PARAM (which is operand number
8738 PARAM_NUM) is non-null. This is called by check_function_nonnull
8739 via check_function_arguments_recurse. */
8742 check_nonnull_arg (void * ARG_UNUSED (ctx
), tree param
,
8743 unsigned HOST_WIDE_INT param_num
)
8745 /* Just skip checking the argument if it's not a pointer. This can
8746 happen if the "nonnull" attribute was given without an operand
8747 list (which means to check every pointer argument). */
8749 if (TREE_CODE (TREE_TYPE (param
)) != POINTER_TYPE
)
8752 if (integer_zerop (param
))
8753 warning (OPT_Wnonnull
, "null argument where non-null required "
8754 "(argument %lu)", (unsigned long) param_num
);
8757 /* Helper for nonnull attribute handling; fetch the operand number
8758 from the attribute argument list. */
8761 get_nonnull_operand (tree arg_num_expr
, unsigned HOST_WIDE_INT
*valp
)
8763 /* Verify the arg number is a constant. */
8764 if (TREE_CODE (arg_num_expr
) != INTEGER_CST
8765 || TREE_INT_CST_HIGH (arg_num_expr
) != 0)
8768 *valp
= TREE_INT_CST_LOW (arg_num_expr
);
8772 /* Handle a "nothrow" attribute; arguments as in
8773 struct attribute_spec.handler. */
8776 handle_nothrow_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8777 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8779 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8780 TREE_NOTHROW (*node
) = 1;
8781 /* ??? TODO: Support types. */
8784 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8785 *no_add_attrs
= true;
8791 /* Handle a "cleanup" attribute; arguments as in
8792 struct attribute_spec.handler. */
8795 handle_cleanup_attribute (tree
*node
, tree name
, tree args
,
8796 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8799 tree cleanup_id
, cleanup_decl
;
8801 /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
8802 for global destructors in C++. This requires infrastructure that
8803 we don't have generically at the moment. It's also not a feature
8804 we'd be missing too much, since we do have attribute constructor. */
8805 if (TREE_CODE (decl
) != VAR_DECL
|| TREE_STATIC (decl
))
8807 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8808 *no_add_attrs
= true;
8812 /* Verify that the argument is a function in scope. */
8813 /* ??? We could support pointers to functions here as well, if
8814 that was considered desirable. */
8815 cleanup_id
= TREE_VALUE (args
);
8816 if (TREE_CODE (cleanup_id
) != IDENTIFIER_NODE
)
8818 error ("cleanup argument not an identifier");
8819 *no_add_attrs
= true;
8822 cleanup_decl
= lookup_name (cleanup_id
);
8823 if (!cleanup_decl
|| TREE_CODE (cleanup_decl
) != FUNCTION_DECL
)
8825 error ("cleanup argument not a function");
8826 *no_add_attrs
= true;
8830 /* That the function has proper type is checked with the
8831 eventual call to build_function_call. */
8836 /* Handle a "warn_unused_result" attribute. No special handling. */
8839 handle_warn_unused_result_attribute (tree
*node
, tree name
,
8840 tree
ARG_UNUSED (args
),
8841 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8843 /* Ignore the attribute for functions not returning any value. */
8844 if (VOID_TYPE_P (TREE_TYPE (*node
)))
8846 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8847 *no_add_attrs
= true;
8853 /* Handle a "sentinel" attribute. */
8856 handle_sentinel_attribute (tree
*node
, tree name
, tree args
,
8857 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8859 if (!prototype_p (*node
))
8861 warning (OPT_Wattributes
,
8862 "%qE attribute requires prototypes with named arguments", name
);
8863 *no_add_attrs
= true;
8867 if (!stdarg_p (*node
))
8869 warning (OPT_Wattributes
,
8870 "%qE attribute only applies to variadic functions", name
);
8871 *no_add_attrs
= true;
8877 tree position
= TREE_VALUE (args
);
8879 if (TREE_CODE (position
) != INTEGER_CST
)
8881 warning (OPT_Wattributes
,
8882 "requested position is not an integer constant");
8883 *no_add_attrs
= true;
8887 if (tree_int_cst_lt (position
, integer_zero_node
))
8889 warning (OPT_Wattributes
,
8890 "requested position is less than zero");
8891 *no_add_attrs
= true;
8899 /* Handle a "type_generic" attribute. */
8902 handle_type_generic_attribute (tree
*node
, tree
ARG_UNUSED (name
),
8903 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
8904 bool * ARG_UNUSED (no_add_attrs
))
8906 /* Ensure we have a function type. */
8907 gcc_assert (TREE_CODE (*node
) == FUNCTION_TYPE
);
8909 /* Ensure we have a variadic function. */
8910 gcc_assert (!prototype_p (*node
) || stdarg_p (*node
));
8915 /* Handle a "target" attribute. */
8918 handle_target_attribute (tree
*node
, tree name
, tree args
, int flags
,
8921 /* Ensure we have a function type. */
8922 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8924 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8925 *no_add_attrs
= true;
8927 else if (! targetm
.target_option
.valid_attribute_p (*node
, name
, args
,
8929 *no_add_attrs
= true;
8934 /* Arguments being collected for optimization. */
8935 typedef const char *const_char_p
; /* For DEF_VEC_P. */
8936 static GTY(()) vec
<const_char_p
, va_gc
> *optimize_args
;
8939 /* Inner function to convert a TREE_LIST to argv string to parse the optimize
8940 options in ARGS. ATTR_P is true if this is for attribute(optimize), and
8941 false for #pragma GCC optimize. */
8944 parse_optimize_options (tree args
, bool attr_p
)
8949 int saved_flag_strict_aliasing
;
8950 const char **opt_argv
;
8951 struct cl_decoded_option
*decoded_options
;
8952 unsigned int decoded_options_count
;
8955 /* Build up argv vector. Just in case the string is stored away, use garbage
8956 collected strings. */
8957 vec_safe_truncate (optimize_args
, 0);
8958 vec_safe_push (optimize_args
, (const char *) NULL
);
8960 for (ap
= args
; ap
!= NULL_TREE
; ap
= TREE_CHAIN (ap
))
8962 tree value
= TREE_VALUE (ap
);
8964 if (TREE_CODE (value
) == INTEGER_CST
)
8967 sprintf (buffer
, "-O%ld", (long) TREE_INT_CST_LOW (value
));
8968 vec_safe_push (optimize_args
, ggc_strdup (buffer
));
8971 else if (TREE_CODE (value
) == STRING_CST
)
8973 /* Split string into multiple substrings. */
8974 size_t len
= TREE_STRING_LENGTH (value
);
8975 char *p
= ASTRDUP (TREE_STRING_POINTER (value
));
8976 char *end
= p
+ len
;
8980 while (next_p
!= NULL
)
8986 comma
= strchr (p
, ',');
8999 r
= q
= (char *) ggc_alloc_atomic (len2
+ 3);
9001 /* If the user supplied -Oxxx or -fxxx, only allow -Oxxx or -fxxx
9003 if (*p
== '-' && p
[1] != 'O' && p
[1] != 'f')
9007 warning (OPT_Wattributes
,
9008 "bad option %s to optimize attribute", p
);
9010 warning (OPT_Wpragmas
,
9011 "bad option %s to pragma attribute", p
);
9019 /* Assume that Ox is -Ox, a numeric value is -Ox, a s by
9020 itself is -Os, and any other switch begins with a -f. */
9021 if ((*p
>= '0' && *p
<= '9')
9022 || (p
[0] == 's' && p
[1] == '\0'))
9028 memcpy (r
, p
, len2
);
9030 vec_safe_push (optimize_args
, (const char *) q
);
9036 opt_argc
= optimize_args
->length ();
9037 opt_argv
= (const char **) alloca (sizeof (char *) * (opt_argc
+ 1));
9039 for (i
= 1; i
< opt_argc
; i
++)
9040 opt_argv
[i
] = (*optimize_args
)[i
];
9042 saved_flag_strict_aliasing
= flag_strict_aliasing
;
9044 /* Now parse the options. */
9045 decode_cmdline_options_to_array_default_mask (opt_argc
, opt_argv
,
9047 &decoded_options_count
);
9048 decode_options (&global_options
, &global_options_set
,
9049 decoded_options
, decoded_options_count
,
9050 input_location
, global_dc
);
9052 targetm
.override_options_after_change();
9054 /* Don't allow changing -fstrict-aliasing. */
9055 flag_strict_aliasing
= saved_flag_strict_aliasing
;
9057 optimize_args
->truncate (0);
9061 /* For handling "optimize" attribute. arguments as in
9062 struct attribute_spec.handler. */
9065 handle_optimize_attribute (tree
*node
, tree name
, tree args
,
9066 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9068 /* Ensure we have a function type. */
9069 if (TREE_CODE (*node
) != FUNCTION_DECL
)
9071 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9072 *no_add_attrs
= true;
9076 struct cl_optimization cur_opts
;
9077 tree old_opts
= DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
);
9079 /* Save current options. */
9080 cl_optimization_save (&cur_opts
, &global_options
);
9082 /* If we previously had some optimization options, use them as the
9085 cl_optimization_restore (&global_options
,
9086 TREE_OPTIMIZATION (old_opts
));
9088 /* Parse options, and update the vector. */
9089 parse_optimize_options (args
, true);
9090 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
)
9091 = build_optimization_node (&global_options
);
9093 /* Restore current options. */
9094 cl_optimization_restore (&global_options
, &cur_opts
);
9100 /* Handle a "no_split_stack" attribute. */
9103 handle_no_split_stack_attribute (tree
*node
, tree name
,
9104 tree
ARG_UNUSED (args
),
9105 int ARG_UNUSED (flags
),
9110 if (TREE_CODE (decl
) != FUNCTION_DECL
)
9112 error_at (DECL_SOURCE_LOCATION (decl
),
9113 "%qE attribute applies only to functions", name
);
9114 *no_add_attrs
= true;
9116 else if (DECL_INITIAL (decl
))
9118 error_at (DECL_SOURCE_LOCATION (decl
),
9119 "can%'t set %qE attribute after definition", name
);
9120 *no_add_attrs
= true;
9126 /* Handle a "returns_nonnull" attribute; arguments as in
9127 struct attribute_spec.handler. */
9130 handle_returns_nonnull_attribute (tree
*node
, tree
, tree
, int,
9133 // Even without a prototype we still have a return type we can check.
9134 if (TREE_CODE (TREE_TYPE (*node
)) != POINTER_TYPE
)
9136 error ("returns_nonnull attribute on a function not returning a pointer");
9137 *no_add_attrs
= true;
9143 /* Check for valid arguments being passed to a function with FNTYPE.
9144 There are NARGS arguments in the array ARGARRAY. */
9146 check_function_arguments (const_tree fntype
, int nargs
, tree
*argarray
)
9148 /* Check for null being passed in a pointer argument that must be
9149 non-null. We also need to do this if format checking is enabled. */
9152 check_function_nonnull (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
9154 /* Check for errors in format strings. */
9156 if (warn_format
|| warn_suggest_attribute_format
)
9157 check_function_format (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
9160 check_function_sentinel (fntype
, nargs
, argarray
);
9163 /* Generic argument checking recursion routine. PARAM is the argument to
9164 be checked. PARAM_NUM is the number of the argument. CALLBACK is invoked
9165 once the argument is resolved. CTX is context for the callback. */
9167 check_function_arguments_recurse (void (*callback
)
9168 (void *, tree
, unsigned HOST_WIDE_INT
),
9169 void *ctx
, tree param
,
9170 unsigned HOST_WIDE_INT param_num
)
9172 if (CONVERT_EXPR_P (param
)
9173 && (TYPE_PRECISION (TREE_TYPE (param
))
9174 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (param
, 0)))))
9176 /* Strip coercion. */
9177 check_function_arguments_recurse (callback
, ctx
,
9178 TREE_OPERAND (param
, 0), param_num
);
9182 if (TREE_CODE (param
) == CALL_EXPR
)
9184 tree type
= TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (param
)));
9186 bool found_format_arg
= false;
9188 /* See if this is a call to a known internationalization function
9189 that modifies a format arg. Such a function may have multiple
9190 format_arg attributes (for example, ngettext). */
9192 for (attrs
= TYPE_ATTRIBUTES (type
);
9194 attrs
= TREE_CHAIN (attrs
))
9195 if (is_attribute_p ("format_arg", TREE_PURPOSE (attrs
)))
9198 tree format_num_expr
;
9201 call_expr_arg_iterator iter
;
9203 /* Extract the argument number, which was previously checked
9205 format_num_expr
= TREE_VALUE (TREE_VALUE (attrs
));
9207 gcc_assert (TREE_CODE (format_num_expr
) == INTEGER_CST
9208 && !TREE_INT_CST_HIGH (format_num_expr
));
9210 format_num
= TREE_INT_CST_LOW (format_num_expr
);
9212 for (inner_arg
= first_call_expr_arg (param
, &iter
), i
= 1;
9214 inner_arg
= next_call_expr_arg (&iter
), i
++)
9215 if (i
== format_num
)
9217 check_function_arguments_recurse (callback
, ctx
,
9218 inner_arg
, param_num
);
9219 found_format_arg
= true;
9224 /* If we found a format_arg attribute and did a recursive check,
9225 we are done with checking this argument. Otherwise, we continue
9226 and this will be considered a non-literal. */
9227 if (found_format_arg
)
9231 if (TREE_CODE (param
) == COND_EXPR
)
9233 /* Check both halves of the conditional expression. */
9234 check_function_arguments_recurse (callback
, ctx
,
9235 TREE_OPERAND (param
, 1), param_num
);
9236 check_function_arguments_recurse (callback
, ctx
,
9237 TREE_OPERAND (param
, 2), param_num
);
9241 (*callback
) (ctx
, param
, param_num
);
9244 /* Checks for a builtin function FNDECL that the number of arguments
9245 NARGS against the required number REQUIRED and issues an error if
9246 there is a mismatch. Returns true if the number of arguments is
9247 correct, otherwise false. */
9250 builtin_function_validate_nargs (tree fndecl
, int nargs
, int required
)
9252 if (nargs
< required
)
9254 error_at (input_location
,
9255 "not enough arguments to function %qE", fndecl
);
9258 else if (nargs
> required
)
9260 error_at (input_location
,
9261 "too many arguments to function %qE", fndecl
);
9267 /* Verifies the NARGS arguments ARGS to the builtin function FNDECL.
9268 Returns false if there was an error, otherwise true. */
9271 check_builtin_function_arguments (tree fndecl
, int nargs
, tree
*args
)
9273 if (!DECL_BUILT_IN (fndecl
)
9274 || DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_NORMAL
)
9277 switch (DECL_FUNCTION_CODE (fndecl
))
9279 case BUILT_IN_CONSTANT_P
:
9280 return builtin_function_validate_nargs (fndecl
, nargs
, 1);
9282 case BUILT_IN_ISFINITE
:
9283 case BUILT_IN_ISINF
:
9284 case BUILT_IN_ISINF_SIGN
:
9285 case BUILT_IN_ISNAN
:
9286 case BUILT_IN_ISNORMAL
:
9287 if (builtin_function_validate_nargs (fndecl
, nargs
, 1))
9289 if (TREE_CODE (TREE_TYPE (args
[0])) != REAL_TYPE
)
9291 error ("non-floating-point argument in call to "
9292 "function %qE", fndecl
);
9299 case BUILT_IN_ISGREATER
:
9300 case BUILT_IN_ISGREATEREQUAL
:
9301 case BUILT_IN_ISLESS
:
9302 case BUILT_IN_ISLESSEQUAL
:
9303 case BUILT_IN_ISLESSGREATER
:
9304 case BUILT_IN_ISUNORDERED
:
9305 if (builtin_function_validate_nargs (fndecl
, nargs
, 2))
9307 enum tree_code code0
, code1
;
9308 code0
= TREE_CODE (TREE_TYPE (args
[0]));
9309 code1
= TREE_CODE (TREE_TYPE (args
[1]));
9310 if (!((code0
== REAL_TYPE
&& code1
== REAL_TYPE
)
9311 || (code0
== REAL_TYPE
&& code1
== INTEGER_TYPE
)
9312 || (code0
== INTEGER_TYPE
&& code1
== REAL_TYPE
)))
9314 error ("non-floating-point arguments in call to "
9315 "function %qE", fndecl
);
9322 case BUILT_IN_FPCLASSIFY
:
9323 if (builtin_function_validate_nargs (fndecl
, nargs
, 6))
9328 if (TREE_CODE (args
[i
]) != INTEGER_CST
)
9330 error ("non-const integer argument %u in call to function %qE",
9335 if (TREE_CODE (TREE_TYPE (args
[5])) != REAL_TYPE
)
9337 error ("non-floating-point argument in call to function %qE",
9345 case BUILT_IN_ASSUME_ALIGNED
:
9346 if (builtin_function_validate_nargs (fndecl
, nargs
, 2 + (nargs
> 2)))
9348 if (nargs
>= 3 && TREE_CODE (TREE_TYPE (args
[2])) != INTEGER_TYPE
)
9350 error ("non-integer argument 3 in call to function %qE", fndecl
);
9362 /* Function to help qsort sort FIELD_DECLs by name order. */
9365 field_decl_cmp (const void *x_p
, const void *y_p
)
9367 const tree
*const x
= (const tree
*const) x_p
;
9368 const tree
*const y
= (const tree
*const) y_p
;
9370 if (DECL_NAME (*x
) == DECL_NAME (*y
))
9371 /* A nontype is "greater" than a type. */
9372 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
9373 if (DECL_NAME (*x
) == NULL_TREE
)
9375 if (DECL_NAME (*y
) == NULL_TREE
)
9377 if (DECL_NAME (*x
) < DECL_NAME (*y
))
9383 gt_pointer_operator new_value
;
9387 /* This routine compares two fields like field_decl_cmp but using the
9388 pointer operator in resort_data. */
9391 resort_field_decl_cmp (const void *x_p
, const void *y_p
)
9393 const tree
*const x
= (const tree
*const) x_p
;
9394 const tree
*const y
= (const tree
*const) y_p
;
9396 if (DECL_NAME (*x
) == DECL_NAME (*y
))
9397 /* A nontype is "greater" than a type. */
9398 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
9399 if (DECL_NAME (*x
) == NULL_TREE
)
9401 if (DECL_NAME (*y
) == NULL_TREE
)
9404 tree d1
= DECL_NAME (*x
);
9405 tree d2
= DECL_NAME (*y
);
9406 resort_data
.new_value (&d1
, resort_data
.cookie
);
9407 resort_data
.new_value (&d2
, resort_data
.cookie
);
9414 /* Resort DECL_SORTED_FIELDS because pointers have been reordered. */
9417 resort_sorted_fields (void *obj
,
9418 void * ARG_UNUSED (orig_obj
),
9419 gt_pointer_operator new_value
,
9422 struct sorted_fields_type
*sf
= (struct sorted_fields_type
*) obj
;
9423 resort_data
.new_value
= new_value
;
9424 resort_data
.cookie
= cookie
;
9425 qsort (&sf
->elts
[0], sf
->len
, sizeof (tree
),
9426 resort_field_decl_cmp
);
9429 /* Subroutine of c_parse_error.
9430 Return the result of concatenating LHS and RHS. RHS is really
9431 a string literal, its first character is indicated by RHS_START and
9432 RHS_SIZE is its length (including the terminating NUL character).
9434 The caller is responsible for deleting the returned pointer. */
9437 catenate_strings (const char *lhs
, const char *rhs_start
, int rhs_size
)
9439 const int lhs_size
= strlen (lhs
);
9440 char *result
= XNEWVEC (char, lhs_size
+ rhs_size
);
9441 strncpy (result
, lhs
, lhs_size
);
9442 strncpy (result
+ lhs_size
, rhs_start
, rhs_size
);
9446 /* Issue the error given by GMSGID, indicating that it occurred before
9447 TOKEN, which had the associated VALUE. */
9450 c_parse_error (const char *gmsgid
, enum cpp_ttype token_type
,
9451 tree value
, unsigned char token_flags
)
9453 #define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2))
9455 char *message
= NULL
;
9457 if (token_type
== CPP_EOF
)
9458 message
= catenate_messages (gmsgid
, " at end of input");
9459 else if (token_type
== CPP_CHAR
9460 || token_type
== CPP_WCHAR
9461 || token_type
== CPP_CHAR16
9462 || token_type
== CPP_CHAR32
)
9464 unsigned int val
= TREE_INT_CST_LOW (value
);
9483 if (val
<= UCHAR_MAX
&& ISGRAPH (val
))
9484 message
= catenate_messages (gmsgid
, " before %s'%c'");
9486 message
= catenate_messages (gmsgid
, " before %s'\\x%x'");
9488 error (message
, prefix
, val
);
9492 else if (token_type
== CPP_CHAR_USERDEF
9493 || token_type
== CPP_WCHAR_USERDEF
9494 || token_type
== CPP_CHAR16_USERDEF
9495 || token_type
== CPP_CHAR32_USERDEF
)
9496 message
= catenate_messages (gmsgid
,
9497 " before user-defined character literal");
9498 else if (token_type
== CPP_STRING_USERDEF
9499 || token_type
== CPP_WSTRING_USERDEF
9500 || token_type
== CPP_STRING16_USERDEF
9501 || token_type
== CPP_STRING32_USERDEF
9502 || token_type
== CPP_UTF8STRING_USERDEF
)
9503 message
= catenate_messages (gmsgid
, " before user-defined string literal");
9504 else if (token_type
== CPP_STRING
9505 || token_type
== CPP_WSTRING
9506 || token_type
== CPP_STRING16
9507 || token_type
== CPP_STRING32
9508 || token_type
== CPP_UTF8STRING
)
9509 message
= catenate_messages (gmsgid
, " before string constant");
9510 else if (token_type
== CPP_NUMBER
)
9511 message
= catenate_messages (gmsgid
, " before numeric constant");
9512 else if (token_type
== CPP_NAME
)
9514 message
= catenate_messages (gmsgid
, " before %qE");
9515 error (message
, value
);
9519 else if (token_type
== CPP_PRAGMA
)
9520 message
= catenate_messages (gmsgid
, " before %<#pragma%>");
9521 else if (token_type
== CPP_PRAGMA_EOL
)
9522 message
= catenate_messages (gmsgid
, " before end of line");
9523 else if (token_type
== CPP_DECLTYPE
)
9524 message
= catenate_messages (gmsgid
, " before %<decltype%>");
9525 else if (token_type
< N_TTYPES
)
9527 message
= catenate_messages (gmsgid
, " before %qs token");
9528 error (message
, cpp_type2name (token_type
, token_flags
));
9540 #undef catenate_messages
9543 /* Mapping for cpp message reasons to the options that enable them. */
9545 struct reason_option_codes_t
9547 const int reason
; /* cpplib message reason. */
9548 const int option_code
; /* gcc option that controls this message. */
9551 static const struct reason_option_codes_t option_codes
[] = {
9552 {CPP_W_DEPRECATED
, OPT_Wdeprecated
},
9553 {CPP_W_COMMENTS
, OPT_Wcomment
},
9554 {CPP_W_TRIGRAPHS
, OPT_Wtrigraphs
},
9555 {CPP_W_MULTICHAR
, OPT_Wmultichar
},
9556 {CPP_W_TRADITIONAL
, OPT_Wtraditional
},
9557 {CPP_W_LONG_LONG
, OPT_Wlong_long
},
9558 {CPP_W_ENDIF_LABELS
, OPT_Wendif_labels
},
9559 {CPP_W_VARIADIC_MACROS
, OPT_Wvariadic_macros
},
9560 {CPP_W_BUILTIN_MACRO_REDEFINED
, OPT_Wbuiltin_macro_redefined
},
9561 {CPP_W_UNDEF
, OPT_Wundef
},
9562 {CPP_W_UNUSED_MACROS
, OPT_Wunused_macros
},
9563 {CPP_W_CXX_OPERATOR_NAMES
, OPT_Wc___compat
},
9564 {CPP_W_NORMALIZE
, OPT_Wnormalized_
},
9565 {CPP_W_INVALID_PCH
, OPT_Winvalid_pch
},
9566 {CPP_W_WARNING_DIRECTIVE
, OPT_Wcpp
},
9567 {CPP_W_LITERAL_SUFFIX
, OPT_Wliteral_suffix
},
9568 {CPP_W_DATE_TIME
, OPT_Wdate_time
},
9572 /* Return the gcc option code associated with the reason for a cpp
9573 message, or 0 if none. */
9576 c_option_controlling_cpp_error (int reason
)
9578 const struct reason_option_codes_t
*entry
;
9580 for (entry
= option_codes
; entry
->reason
!= CPP_W_NONE
; entry
++)
9582 if (entry
->reason
== reason
)
9583 return entry
->option_code
;
9588 /* Callback from cpp_error for PFILE to print diagnostics from the
9589 preprocessor. The diagnostic is of type LEVEL, with REASON set
9590 to the reason code if LEVEL is represents a warning, at location
9591 LOCATION unless this is after lexing and the compiler's location
9592 should be used instead, with column number possibly overridden by
9593 COLUMN_OVERRIDE if not zero; MSG is the translated message and AP
9594 the arguments. Returns true if a diagnostic was emitted, false
9598 c_cpp_error (cpp_reader
*pfile ATTRIBUTE_UNUSED
, int level
, int reason
,
9599 location_t location
, unsigned int column_override
,
9600 const char *msg
, va_list *ap
)
9602 diagnostic_info diagnostic
;
9603 diagnostic_t dlevel
;
9604 bool save_warn_system_headers
= global_dc
->dc_warn_system_headers
;
9609 case CPP_DL_WARNING_SYSHDR
:
9612 global_dc
->dc_warn_system_headers
= 1;
9614 case CPP_DL_WARNING
:
9617 dlevel
= DK_WARNING
;
9619 case CPP_DL_PEDWARN
:
9620 if (flag_no_output
&& !flag_pedantic_errors
)
9622 dlevel
= DK_PEDWARN
;
9640 location
= input_location
;
9641 diagnostic_set_info_translated (&diagnostic
, msg
, ap
,
9643 if (column_override
)
9644 diagnostic_override_column (&diagnostic
, column_override
);
9645 diagnostic_override_option_index (&diagnostic
,
9646 c_option_controlling_cpp_error (reason
));
9647 ret
= report_diagnostic (&diagnostic
);
9648 if (level
== CPP_DL_WARNING_SYSHDR
)
9649 global_dc
->dc_warn_system_headers
= save_warn_system_headers
;
9653 /* Convert a character from the host to the target execution character
9654 set. cpplib handles this, mostly. */
9657 c_common_to_target_charset (HOST_WIDE_INT c
)
9659 /* Character constants in GCC proper are sign-extended under -fsigned-char,
9660 zero-extended under -fno-signed-char. cpplib insists that characters
9661 and character constants are always unsigned. Hence we must convert
9663 cppchar_t uc
= ((cppchar_t
)c
) & ((((cppchar_t
)1) << CHAR_BIT
)-1);
9665 uc
= cpp_host_to_exec_charset (parse_in
, uc
);
9667 if (flag_signed_char
)
9668 return ((HOST_WIDE_INT
)uc
) << (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
)
9669 >> (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
);
9674 /* Fold an offsetof-like expression. EXPR is a nested sequence of component
9675 references with an INDIRECT_REF of a constant at the bottom; much like the
9676 traditional rendering of offsetof as a macro. Return the folded result. */
9679 fold_offsetof_1 (tree expr
)
9683 switch (TREE_CODE (expr
))
9689 error ("cannot apply %<offsetof%> to static data member %qD", expr
);
9690 return error_mark_node
;
9694 error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded");
9695 return error_mark_node
;
9699 if (!TREE_CONSTANT (TREE_OPERAND (expr
, 0)))
9701 error ("cannot apply %<offsetof%> to a non constant address");
9702 return error_mark_node
;
9704 return TREE_OPERAND (expr
, 0);
9707 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0));
9708 if (base
== error_mark_node
)
9711 t
= TREE_OPERAND (expr
, 1);
9712 if (DECL_C_BIT_FIELD (t
))
9714 error ("attempt to take address of bit-field structure "
9716 return error_mark_node
;
9718 off
= size_binop_loc (input_location
, PLUS_EXPR
, DECL_FIELD_OFFSET (t
),
9719 size_int (tree_low_cst (DECL_FIELD_BIT_OFFSET (t
),
9725 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0));
9726 if (base
== error_mark_node
)
9729 t
= TREE_OPERAND (expr
, 1);
9731 /* Check if the offset goes beyond the upper bound of the array. */
9732 if (TREE_CODE (t
) == INTEGER_CST
&& tree_int_cst_sgn (t
) >= 0)
9734 tree upbound
= array_ref_up_bound (expr
);
9735 if (upbound
!= NULL_TREE
9736 && TREE_CODE (upbound
) == INTEGER_CST
9737 && !tree_int_cst_equal (upbound
,
9738 TYPE_MAX_VALUE (TREE_TYPE (upbound
))))
9740 upbound
= size_binop (PLUS_EXPR
, upbound
,
9741 build_int_cst (TREE_TYPE (upbound
), 1));
9742 if (tree_int_cst_lt (upbound
, t
))
9746 for (v
= TREE_OPERAND (expr
, 0);
9747 TREE_CODE (v
) == COMPONENT_REF
;
9748 v
= TREE_OPERAND (v
, 0))
9749 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v
, 0)))
9752 tree fld_chain
= DECL_CHAIN (TREE_OPERAND (v
, 1));
9753 for (; fld_chain
; fld_chain
= DECL_CHAIN (fld_chain
))
9754 if (TREE_CODE (fld_chain
) == FIELD_DECL
)
9760 /* Don't warn if the array might be considered a poor
9761 man's flexible array member with a very permissive
9762 definition thereof. */
9763 if (TREE_CODE (v
) == ARRAY_REF
9764 || TREE_CODE (v
) == COMPONENT_REF
)
9765 warning (OPT_Warray_bounds
,
9766 "index %E denotes an offset "
9767 "greater than size of %qT",
9768 t
, TREE_TYPE (TREE_OPERAND (expr
, 0)));
9773 t
= convert (sizetype
, t
);
9774 off
= size_binop (MULT_EXPR
, TYPE_SIZE_UNIT (TREE_TYPE (expr
)), t
);
9778 /* Handle static members of volatile structs. */
9779 t
= TREE_OPERAND (expr
, 1);
9780 gcc_assert (TREE_CODE (t
) == VAR_DECL
);
9781 return fold_offsetof_1 (t
);
9787 return fold_build_pointer_plus (base
, off
);
9790 /* Likewise, but convert it to the return type of offsetof. */
9793 fold_offsetof (tree expr
)
9795 return convert (size_type_node
, fold_offsetof_1 (expr
));
9798 /* Warn for A ?: C expressions (with B omitted) where A is a boolean
9799 expression, because B will always be true. */
9802 warn_for_omitted_condop (location_t location
, tree cond
)
9804 if (truth_value_p (TREE_CODE (cond
)))
9805 warning_at (location
, OPT_Wparentheses
,
9806 "the omitted middle operand in ?: will always be %<true%>, "
9807 "suggest explicit middle operand");
9810 /* Give an error for storing into ARG, which is 'const'. USE indicates
9811 how ARG was being used. */
9814 readonly_error (tree arg
, enum lvalue_use use
)
9816 gcc_assert (use
== lv_assign
|| use
== lv_increment
|| use
== lv_decrement
9818 /* Using this macro rather than (for example) arrays of messages
9819 ensures that all the format strings are checked at compile
9821 #define READONLY_MSG(A, I, D, AS) (use == lv_assign ? (A) \
9822 : (use == lv_increment ? (I) \
9823 : (use == lv_decrement ? (D) : (AS))))
9824 if (TREE_CODE (arg
) == COMPONENT_REF
)
9826 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg
, 0))))
9827 error (READONLY_MSG (G_("assignment of member "
9828 "%qD in read-only object"),
9829 G_("increment of member "
9830 "%qD in read-only object"),
9831 G_("decrement of member "
9832 "%qD in read-only object"),
9833 G_("member %qD in read-only object "
9834 "used as %<asm%> output")),
9835 TREE_OPERAND (arg
, 1));
9837 error (READONLY_MSG (G_("assignment of read-only member %qD"),
9838 G_("increment of read-only member %qD"),
9839 G_("decrement of read-only member %qD"),
9840 G_("read-only member %qD used as %<asm%> output")),
9841 TREE_OPERAND (arg
, 1));
9843 else if (TREE_CODE (arg
) == VAR_DECL
)
9844 error (READONLY_MSG (G_("assignment of read-only variable %qD"),
9845 G_("increment of read-only variable %qD"),
9846 G_("decrement of read-only variable %qD"),
9847 G_("read-only variable %qD used as %<asm%> output")),
9849 else if (TREE_CODE (arg
) == PARM_DECL
)
9850 error (READONLY_MSG (G_("assignment of read-only parameter %qD"),
9851 G_("increment of read-only parameter %qD"),
9852 G_("decrement of read-only parameter %qD"),
9853 G_("read-only parameter %qD use as %<asm%> output")),
9855 else if (TREE_CODE (arg
) == RESULT_DECL
)
9857 gcc_assert (c_dialect_cxx ());
9858 error (READONLY_MSG (G_("assignment of "
9859 "read-only named return value %qD"),
9861 "read-only named return value %qD"),
9863 "read-only named return value %qD"),
9864 G_("read-only named return value %qD "
9865 "used as %<asm%>output")),
9868 else if (TREE_CODE (arg
) == FUNCTION_DECL
)
9869 error (READONLY_MSG (G_("assignment of function %qD"),
9870 G_("increment of function %qD"),
9871 G_("decrement of function %qD"),
9872 G_("function %qD used as %<asm%> output")),
9875 error (READONLY_MSG (G_("assignment of read-only location %qE"),
9876 G_("increment of read-only location %qE"),
9877 G_("decrement of read-only location %qE"),
9878 G_("read-only location %qE used as %<asm%> output")),
9882 /* Print an error message for an invalid lvalue. USE says
9883 how the lvalue is being used and so selects the error message. LOC
9884 is the location for the error. */
9887 lvalue_error (location_t loc
, enum lvalue_use use
)
9892 error_at (loc
, "lvalue required as left operand of assignment");
9895 error_at (loc
, "lvalue required as increment operand");
9898 error_at (loc
, "lvalue required as decrement operand");
9901 error_at (loc
, "lvalue required as unary %<&%> operand");
9904 error_at (loc
, "lvalue required in asm statement");
9911 /* Print an error message for an invalid indirection of type TYPE.
9912 ERRSTRING is the name of the operator for the indirection. */
9915 invalid_indirection_error (location_t loc
, tree type
, ref_operator errstring
)
9920 gcc_assert (c_dialect_cxx ());
9921 error_at (loc
, "invalid type argument (have %qT)", type
);
9923 case RO_ARRAY_INDEXING
:
9925 "invalid type argument of array indexing (have %qT)",
9930 "invalid type argument of unary %<*%> (have %qT)",
9935 "invalid type argument of %<->%> (have %qT)",
9940 "invalid type argument of %<->*%> (have %qT)",
9943 case RO_IMPLICIT_CONVERSION
:
9945 "invalid type argument of implicit conversion (have %qT)",
9953 /* *PTYPE is an incomplete array. Complete it with a domain based on
9954 INITIAL_VALUE. If INITIAL_VALUE is not present, use 1 if DO_DEFAULT
9955 is true. Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
9956 2 if INITIAL_VALUE was NULL, and 3 if INITIAL_VALUE was empty. */
9959 complete_array_type (tree
*ptype
, tree initial_value
, bool do_default
)
9961 tree maxindex
, type
, main_type
, elt
, unqual_elt
;
9962 int failure
= 0, quals
;
9963 hashval_t hashcode
= 0;
9964 bool overflow_p
= false;
9966 maxindex
= size_zero_node
;
9969 if (TREE_CODE (initial_value
) == STRING_CST
)
9972 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value
)));
9973 maxindex
= size_int (TREE_STRING_LENGTH (initial_value
)/eltsize
- 1);
9975 else if (TREE_CODE (initial_value
) == CONSTRUCTOR
)
9977 vec
<constructor_elt
, va_gc
> *v
= CONSTRUCTOR_ELTS (initial_value
);
9979 if (vec_safe_is_empty (v
))
9983 maxindex
= ssize_int (-1);
9988 unsigned HOST_WIDE_INT cnt
;
9989 constructor_elt
*ce
;
9990 bool fold_p
= false;
9993 maxindex
= (*v
)[0].index
, fold_p
= true;
9995 curindex
= maxindex
;
9997 for (cnt
= 1; vec_safe_iterate (v
, cnt
, &ce
); cnt
++)
9999 bool curfold_p
= false;
10001 curindex
= ce
->index
, curfold_p
= true;
10006 /* Since we treat size types now as ordinary
10007 unsigned types, we need an explicit overflow
10009 tree orig
= curindex
;
10010 curindex
= fold_convert (sizetype
, curindex
);
10011 overflow_p
|= tree_int_cst_lt (curindex
, orig
);
10013 curindex
= size_binop (PLUS_EXPR
, curindex
,
10016 if (tree_int_cst_lt (maxindex
, curindex
))
10017 maxindex
= curindex
, fold_p
= curfold_p
;
10021 tree orig
= maxindex
;
10022 maxindex
= fold_convert (sizetype
, maxindex
);
10023 overflow_p
|= tree_int_cst_lt (maxindex
, orig
);
10029 /* Make an error message unless that happened already. */
10030 if (initial_value
!= error_mark_node
)
10042 elt
= TREE_TYPE (type
);
10043 quals
= TYPE_QUALS (strip_array_types (elt
));
10047 unqual_elt
= c_build_qualified_type (elt
, KEEP_QUAL_ADDR_SPACE (quals
));
10049 /* Using build_distinct_type_copy and modifying things afterward instead
10050 of using build_array_type to create a new type preserves all of the
10051 TYPE_LANG_FLAG_? bits that the front end may have set. */
10052 main_type
= build_distinct_type_copy (TYPE_MAIN_VARIANT (type
));
10053 TREE_TYPE (main_type
) = unqual_elt
;
10054 TYPE_DOMAIN (main_type
)
10055 = build_range_type (TREE_TYPE (maxindex
),
10056 build_int_cst (TREE_TYPE (maxindex
), 0), maxindex
);
10057 layout_type (main_type
);
10059 /* Make sure we have the canonical MAIN_TYPE. */
10060 hashcode
= iterative_hash_object (TYPE_HASH (unqual_elt
), hashcode
);
10061 hashcode
= iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (main_type
)),
10063 main_type
= type_hash_canon (hashcode
, main_type
);
10065 /* Fix the canonical type. */
10066 if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type
))
10067 || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type
)))
10068 SET_TYPE_STRUCTURAL_EQUALITY (main_type
);
10069 else if (TYPE_CANONICAL (TREE_TYPE (main_type
)) != TREE_TYPE (main_type
)
10070 || (TYPE_CANONICAL (TYPE_DOMAIN (main_type
))
10071 != TYPE_DOMAIN (main_type
)))
10072 TYPE_CANONICAL (main_type
)
10073 = build_array_type (TYPE_CANONICAL (TREE_TYPE (main_type
)),
10074 TYPE_CANONICAL (TYPE_DOMAIN (main_type
)));
10076 TYPE_CANONICAL (main_type
) = main_type
;
10081 type
= c_build_qualified_type (main_type
, quals
);
10083 if (COMPLETE_TYPE_P (type
)
10084 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
10085 && (overflow_p
|| TREE_OVERFLOW (TYPE_SIZE_UNIT (type
))))
10087 error ("size of array is too large");
10088 /* If we proceed with the array type as it is, we'll eventually
10089 crash in tree_low_cst(). */
10090 type
= error_mark_node
;
10097 /* Like c_mark_addressable but don't check register qualifier. */
10099 c_common_mark_addressable_vec (tree t
)
10101 while (handled_component_p (t
))
10102 t
= TREE_OPERAND (t
, 0);
10103 if (TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != PARM_DECL
)
10105 TREE_ADDRESSABLE (t
) = 1;
10110 /* Used to help initialize the builtin-types.def table. When a type of
10111 the correct size doesn't exist, use error_mark_node instead of NULL.
10112 The later results in segfaults even when a decl using the type doesn't
10116 builtin_type_for_size (int size
, bool unsignedp
)
10118 tree type
= c_common_type_for_size (size
, unsignedp
);
10119 return type
? type
: error_mark_node
;
10122 /* A helper function for resolve_overloaded_builtin in resolving the
10123 overloaded __sync_ builtins. Returns a positive power of 2 if the
10124 first operand of PARAMS is a pointer to a supported data type.
10125 Returns 0 if an error is encountered. */
10128 sync_resolve_size (tree function
, vec
<tree
, va_gc
> *params
)
10135 error ("too few arguments to function %qE", function
);
10139 type
= TREE_TYPE ((*params
)[0]);
10140 if (TREE_CODE (type
) != POINTER_TYPE
)
10143 type
= TREE_TYPE (type
);
10144 if (!INTEGRAL_TYPE_P (type
) && !POINTER_TYPE_P (type
))
10147 size
= tree_low_cst (TYPE_SIZE_UNIT (type
), 1);
10148 if (size
== 1 || size
== 2 || size
== 4 || size
== 8 || size
== 16)
10152 error ("incompatible type for argument %d of %qE", 1, function
);
10156 /* A helper function for resolve_overloaded_builtin. Adds casts to
10157 PARAMS to make arguments match up with those of FUNCTION. Drops
10158 the variadic arguments at the end. Returns false if some error
10159 was encountered; true on success. */
10162 sync_resolve_params (location_t loc
, tree orig_function
, tree function
,
10163 vec
<tree
, va_gc
> *params
, bool orig_format
)
10165 function_args_iterator iter
;
10167 unsigned int parmnum
;
10169 function_args_iter_init (&iter
, TREE_TYPE (function
));
10170 /* We've declared the implementation functions to use "volatile void *"
10171 as the pointer parameter, so we shouldn't get any complaints from the
10172 call to check_function_arguments what ever type the user used. */
10173 function_args_iter_next (&iter
);
10174 ptype
= TREE_TYPE (TREE_TYPE ((*params
)[0]));
10176 /* For the rest of the values, we need to cast these to FTYPE, so that we
10177 don't get warnings for passing pointer types, etc. */
10181 tree val
, arg_type
;
10183 arg_type
= function_args_iter_cond (&iter
);
10184 /* XXX void_type_node belies the abstraction. */
10185 if (arg_type
== void_type_node
)
10189 if (params
->length () <= parmnum
)
10191 error_at (loc
, "too few arguments to function %qE", orig_function
);
10195 /* Only convert parameters if arg_type is unsigned integer type with
10196 new format sync routines, i.e. don't attempt to convert pointer
10197 arguments (e.g. EXPECTED argument of __atomic_compare_exchange_n),
10198 bool arguments (e.g. WEAK argument) or signed int arguments (memmodel
10200 if (TREE_CODE (arg_type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (arg_type
))
10202 /* Ideally for the first conversion we'd use convert_for_assignment
10203 so that we get warnings for anything that doesn't match the pointer
10204 type. This isn't portable across the C and C++ front ends atm. */
10205 val
= (*params
)[parmnum
];
10206 val
= convert (ptype
, val
);
10207 val
= convert (arg_type
, val
);
10208 (*params
)[parmnum
] = val
;
10211 function_args_iter_next (&iter
);
10214 /* __atomic routines are not variadic. */
10215 if (!orig_format
&& params
->length () != parmnum
+ 1)
10217 error_at (loc
, "too many arguments to function %qE", orig_function
);
10221 /* The definition of these primitives is variadic, with the remaining
10222 being "an optional list of variables protected by the memory barrier".
10223 No clue what that's supposed to mean, precisely, but we consider all
10224 call-clobbered variables to be protected so we're safe. */
10225 params
->truncate (parmnum
+ 1);
10230 /* A helper function for resolve_overloaded_builtin. Adds a cast to
10231 RESULT to make it match the type of the first pointer argument in
10235 sync_resolve_return (tree first_param
, tree result
, bool orig_format
)
10237 tree ptype
= TREE_TYPE (TREE_TYPE (first_param
));
10238 tree rtype
= TREE_TYPE (result
);
10239 ptype
= TYPE_MAIN_VARIANT (ptype
);
10241 /* New format doesn't require casting unless the types are the same size. */
10242 if (orig_format
|| tree_int_cst_equal (TYPE_SIZE (ptype
), TYPE_SIZE (rtype
)))
10243 return convert (ptype
, result
);
10248 /* This function verifies the PARAMS to generic atomic FUNCTION.
10249 It returns the size if all the parameters are the same size, otherwise
10250 0 is returned if the parameters are invalid. */
10253 get_atomic_generic_size (location_t loc
, tree function
,
10254 vec
<tree
, va_gc
> *params
)
10256 unsigned int n_param
;
10257 unsigned int n_model
;
10262 /* Determine the parameter makeup. */
10263 switch (DECL_FUNCTION_CODE (function
))
10265 case BUILT_IN_ATOMIC_EXCHANGE
:
10269 case BUILT_IN_ATOMIC_LOAD
:
10270 case BUILT_IN_ATOMIC_STORE
:
10274 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10279 gcc_unreachable ();
10282 if (vec_safe_length (params
) != n_param
)
10284 error_at (loc
, "incorrect number of arguments to function %qE", function
);
10288 /* Get type of first parameter, and determine its size. */
10289 type_0
= TREE_TYPE ((*params
)[0]);
10290 if (TREE_CODE (type_0
) != POINTER_TYPE
|| VOID_TYPE_P (TREE_TYPE (type_0
)))
10292 error_at (loc
, "argument 1 of %qE must be a non-void pointer type",
10297 /* Types must be compile time constant sizes. */
10298 if (TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type_0
)))) != INTEGER_CST
)
10301 "argument 1 of %qE must be a pointer to a constant size type",
10306 size_0
= tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (type_0
)), 1);
10308 /* Zero size objects are not allowed. */
10312 "argument 1 of %qE must be a pointer to a nonzero size object",
10317 /* Check each other parameter is a pointer and the same size. */
10318 for (x
= 0; x
< n_param
- n_model
; x
++)
10321 tree type
= TREE_TYPE ((*params
)[x
]);
10322 /* __atomic_compare_exchange has a bool in the 4th position, skip it. */
10323 if (n_param
== 6 && x
== 3)
10325 if (!POINTER_TYPE_P (type
))
10327 error_at (loc
, "argument %d of %qE must be a pointer type", x
+ 1,
10331 size
= tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (type
)), 1);
10332 if (size
!= size_0
)
10334 error_at (loc
, "size mismatch in argument %d of %qE", x
+ 1,
10340 /* Check memory model parameters for validity. */
10341 for (x
= n_param
- n_model
; x
< n_param
; x
++)
10343 tree p
= (*params
)[x
];
10344 if (TREE_CODE (p
) == INTEGER_CST
)
10346 int i
= tree_low_cst (p
, 1);
10347 if (i
< 0 || (i
& MEMMODEL_MASK
) >= MEMMODEL_LAST
)
10349 warning_at (loc
, OPT_Winvalid_memory_model
,
10350 "invalid memory model argument %d of %qE", x
+ 1,
10355 if (!INTEGRAL_TYPE_P (TREE_TYPE (p
)))
10357 error_at (loc
, "non-integer memory model argument %d of %qE", x
+ 1,
10367 /* This will take an __atomic_ generic FUNCTION call, and add a size parameter N
10368 at the beginning of the parameter list PARAMS representing the size of the
10369 objects. This is to match the library ABI requirement. LOC is the location
10370 of the function call.
10371 The new function is returned if it needed rebuilding, otherwise NULL_TREE is
10372 returned to allow the external call to be constructed. */
10375 add_atomic_size_parameter (unsigned n
, location_t loc
, tree function
,
10376 vec
<tree
, va_gc
> *params
)
10380 /* Insert a SIZE_T parameter as the first param. If there isn't
10381 enough space, allocate a new vector and recursively re-build with that. */
10382 if (!params
->space (1))
10384 unsigned int z
, len
;
10385 vec
<tree
, va_gc
> *v
;
10388 len
= params
->length ();
10389 vec_alloc (v
, len
+ 1);
10390 for (z
= 0; z
< len
; z
++)
10391 v
->quick_push ((*params
)[z
]);
10392 f
= build_function_call_vec (loc
, function
, v
, NULL
);
10397 /* Add the size parameter and leave as a function call for processing. */
10398 size_node
= build_int_cst (size_type_node
, n
);
10399 params
->quick_insert (0, size_node
);
10404 /* This will process an __atomic_exchange function call, determine whether it
10405 needs to be mapped to the _N variation, or turned into a library call.
10406 LOC is the location of the builtin call.
10407 FUNCTION is the DECL that has been invoked;
10408 PARAMS is the argument list for the call. The return value is non-null
10409 TRUE is returned if it is translated into the proper format for a call to the
10410 external library, and NEW_RETURN is set the tree for that function.
10411 FALSE is returned if processing for the _N variation is required, and
10412 NEW_RETURN is set to the the return value the result is copied into. */
10414 resolve_overloaded_atomic_exchange (location_t loc
, tree function
,
10415 vec
<tree
, va_gc
> *params
, tree
*new_return
)
10417 tree p0
, p1
, p2
, p3
;
10418 tree I_type
, I_type_ptr
;
10419 int n
= get_atomic_generic_size (loc
, function
, params
);
10421 /* Size of 0 is an error condition. */
10424 *new_return
= error_mark_node
;
10428 /* If not a lock-free size, change to the library generic format. */
10429 if (n
!= 1 && n
!= 2 && n
!= 4 && n
!= 8 && n
!= 16)
10431 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10435 /* Otherwise there is a lockfree match, transform the call from:
10436 void fn(T* mem, T* desired, T* return, model)
10438 *return = (T) (fn (In* mem, (In) *desired, model)) */
10445 /* Create pointer to appropriate size. */
10446 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10447 I_type_ptr
= build_pointer_type (I_type
);
10449 /* Convert object pointer to required type. */
10450 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10452 /* Convert new value to required type, and dereference it. */
10453 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
10454 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
10457 /* Move memory model to the 3rd position, and end param list. */
10459 params
->truncate (3);
10461 /* Convert return pointer and dereference it for later assignment. */
10462 *new_return
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
10468 /* This will process an __atomic_compare_exchange function call, determine
10469 whether it needs to be mapped to the _N variation, or turned into a lib call.
10470 LOC is the location of the builtin call.
10471 FUNCTION is the DECL that has been invoked;
10472 PARAMS is the argument list for the call. The return value is non-null
10473 TRUE is returned if it is translated into the proper format for a call to the
10474 external library, and NEW_RETURN is set the tree for that function.
10475 FALSE is returned if processing for the _N variation is required. */
10478 resolve_overloaded_atomic_compare_exchange (location_t loc
, tree function
,
10479 vec
<tree
, va_gc
> *params
,
10483 tree I_type
, I_type_ptr
;
10484 int n
= get_atomic_generic_size (loc
, function
, params
);
10486 /* Size of 0 is an error condition. */
10489 *new_return
= error_mark_node
;
10493 /* If not a lock-free size, change to the library generic format. */
10494 if (n
!= 1 && n
!= 2 && n
!= 4 && n
!= 8 && n
!= 16)
10496 /* The library generic format does not have the weak parameter, so
10497 remove it from the param list. Since a parameter has been removed,
10498 we can be sure that there is room for the SIZE_T parameter, meaning
10499 there will not be a recursive rebuilding of the parameter list, so
10500 there is no danger this will be done twice. */
10503 (*params
)[3] = (*params
)[4];
10504 (*params
)[4] = (*params
)[5];
10505 params
->truncate (5);
10507 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10511 /* Otherwise, there is a match, so the call needs to be transformed from:
10512 bool fn(T* mem, T* desired, T* return, weak, success, failure)
10514 bool fn ((In *)mem, (In *)expected, (In) *desired, weak, succ, fail) */
10520 /* Create pointer to appropriate size. */
10521 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10522 I_type_ptr
= build_pointer_type (I_type
);
10524 /* Convert object pointer to required type. */
10525 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10528 /* Convert expected pointer to required type. */
10529 p1
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p1
);
10532 /* Convert desired value to required type, and dereference it. */
10533 p2
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
10534 p2
= build1 (VIEW_CONVERT_EXPR
, I_type
, p2
);
10537 /* The rest of the parameters are fine. NULL means no special return value
10539 *new_return
= NULL
;
10544 /* This will process an __atomic_load function call, determine whether it
10545 needs to be mapped to the _N variation, or turned into a library call.
10546 LOC is the location of the builtin call.
10547 FUNCTION is the DECL that has been invoked;
10548 PARAMS is the argument list for the call. The return value is non-null
10549 TRUE is returned if it is translated into the proper format for a call to the
10550 external library, and NEW_RETURN is set the tree for that function.
10551 FALSE is returned if processing for the _N variation is required, and
10552 NEW_RETURN is set to the the return value the result is copied into. */
10555 resolve_overloaded_atomic_load (location_t loc
, tree function
,
10556 vec
<tree
, va_gc
> *params
, tree
*new_return
)
10559 tree I_type
, I_type_ptr
;
10560 int n
= get_atomic_generic_size (loc
, function
, params
);
10562 /* Size of 0 is an error condition. */
10565 *new_return
= error_mark_node
;
10569 /* If not a lock-free size, change to the library generic format. */
10570 if (n
!= 1 && n
!= 2 && n
!= 4 && n
!= 8 && n
!= 16)
10572 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10576 /* Otherwise, there is a match, so the call needs to be transformed from:
10577 void fn(T* mem, T* return, model)
10579 *return = (T) (fn ((In *) mem, model)) */
10585 /* Create pointer to appropriate size. */
10586 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10587 I_type_ptr
= build_pointer_type (I_type
);
10589 /* Convert object pointer to required type. */
10590 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10593 /* Move memory model to the 2nd position, and end param list. */
10595 params
->truncate (2);
10597 /* Convert return pointer and dereference it for later assignment. */
10598 *new_return
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
10604 /* This will process an __atomic_store function call, determine whether it
10605 needs to be mapped to the _N variation, or turned into a library call.
10606 LOC is the location of the builtin call.
10607 FUNCTION is the DECL that has been invoked;
10608 PARAMS is the argument list for the call. The return value is non-null
10609 TRUE is returned if it is translated into the proper format for a call to the
10610 external library, and NEW_RETURN is set the tree for that function.
10611 FALSE is returned if processing for the _N variation is required, and
10612 NEW_RETURN is set to the the return value the result is copied into. */
10615 resolve_overloaded_atomic_store (location_t loc
, tree function
,
10616 vec
<tree
, va_gc
> *params
, tree
*new_return
)
10619 tree I_type
, I_type_ptr
;
10620 int n
= get_atomic_generic_size (loc
, function
, params
);
10622 /* Size of 0 is an error condition. */
10625 *new_return
= error_mark_node
;
10629 /* If not a lock-free size, change to the library generic format. */
10630 if (n
!= 1 && n
!= 2 && n
!= 4 && n
!= 8 && n
!= 16)
10632 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10636 /* Otherwise, there is a match, so the call needs to be transformed from:
10637 void fn(T* mem, T* value, model)
10639 fn ((In *) mem, (In) *value, model) */
10644 /* Create pointer to appropriate size. */
10645 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10646 I_type_ptr
= build_pointer_type (I_type
);
10648 /* Convert object pointer to required type. */
10649 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10652 /* Convert new value to required type, and dereference it. */
10653 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
10654 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
10657 /* The memory model is in the right spot already. Return is void. */
10658 *new_return
= NULL_TREE
;
10664 /* Some builtin functions are placeholders for other expressions. This
10665 function should be called immediately after parsing the call expression
10666 before surrounding code has committed to the type of the expression.
10668 LOC is the location of the builtin call.
10670 FUNCTION is the DECL that has been invoked; it is known to be a builtin.
10671 PARAMS is the argument list for the call. The return value is non-null
10672 when expansion is complete, and null if normal processing should
10676 resolve_overloaded_builtin (location_t loc
, tree function
,
10677 vec
<tree
, va_gc
> *params
)
10679 enum built_in_function orig_code
= DECL_FUNCTION_CODE (function
);
10680 bool orig_format
= true;
10681 tree new_return
= NULL_TREE
;
10683 switch (DECL_BUILT_IN_CLASS (function
))
10685 case BUILT_IN_NORMAL
:
10688 if (targetm
.resolve_overloaded_builtin
)
10689 return targetm
.resolve_overloaded_builtin (loc
, function
, params
);
10696 /* Handle BUILT_IN_NORMAL here. */
10699 case BUILT_IN_ATOMIC_EXCHANGE
:
10700 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10701 case BUILT_IN_ATOMIC_LOAD
:
10702 case BUILT_IN_ATOMIC_STORE
:
10704 /* Handle these 4 together so that they can fall through to the next
10705 case if the call is transformed to an _N variant. */
10708 case BUILT_IN_ATOMIC_EXCHANGE
:
10710 if (resolve_overloaded_atomic_exchange (loc
, function
, params
,
10713 /* Change to the _N variant. */
10714 orig_code
= BUILT_IN_ATOMIC_EXCHANGE_N
;
10718 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10720 if (resolve_overloaded_atomic_compare_exchange (loc
, function
,
10724 /* Change to the _N variant. */
10725 orig_code
= BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
;
10728 case BUILT_IN_ATOMIC_LOAD
:
10730 if (resolve_overloaded_atomic_load (loc
, function
, params
,
10733 /* Change to the _N variant. */
10734 orig_code
= BUILT_IN_ATOMIC_LOAD_N
;
10737 case BUILT_IN_ATOMIC_STORE
:
10739 if (resolve_overloaded_atomic_store (loc
, function
, params
,
10742 /* Change to the _N variant. */
10743 orig_code
= BUILT_IN_ATOMIC_STORE_N
;
10747 gcc_unreachable ();
10749 /* Fallthrough to the normal processing. */
10751 case BUILT_IN_ATOMIC_EXCHANGE_N
:
10752 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
:
10753 case BUILT_IN_ATOMIC_LOAD_N
:
10754 case BUILT_IN_ATOMIC_STORE_N
:
10755 case BUILT_IN_ATOMIC_ADD_FETCH_N
:
10756 case BUILT_IN_ATOMIC_SUB_FETCH_N
:
10757 case BUILT_IN_ATOMIC_AND_FETCH_N
:
10758 case BUILT_IN_ATOMIC_NAND_FETCH_N
:
10759 case BUILT_IN_ATOMIC_XOR_FETCH_N
:
10760 case BUILT_IN_ATOMIC_OR_FETCH_N
:
10761 case BUILT_IN_ATOMIC_FETCH_ADD_N
:
10762 case BUILT_IN_ATOMIC_FETCH_SUB_N
:
10763 case BUILT_IN_ATOMIC_FETCH_AND_N
:
10764 case BUILT_IN_ATOMIC_FETCH_NAND_N
:
10765 case BUILT_IN_ATOMIC_FETCH_XOR_N
:
10766 case BUILT_IN_ATOMIC_FETCH_OR_N
:
10768 orig_format
= false;
10769 /* Fallthru for parameter processing. */
10771 case BUILT_IN_SYNC_FETCH_AND_ADD_N
:
10772 case BUILT_IN_SYNC_FETCH_AND_SUB_N
:
10773 case BUILT_IN_SYNC_FETCH_AND_OR_N
:
10774 case BUILT_IN_SYNC_FETCH_AND_AND_N
:
10775 case BUILT_IN_SYNC_FETCH_AND_XOR_N
:
10776 case BUILT_IN_SYNC_FETCH_AND_NAND_N
:
10777 case BUILT_IN_SYNC_ADD_AND_FETCH_N
:
10778 case BUILT_IN_SYNC_SUB_AND_FETCH_N
:
10779 case BUILT_IN_SYNC_OR_AND_FETCH_N
:
10780 case BUILT_IN_SYNC_AND_AND_FETCH_N
:
10781 case BUILT_IN_SYNC_XOR_AND_FETCH_N
:
10782 case BUILT_IN_SYNC_NAND_AND_FETCH_N
:
10783 case BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
:
10784 case BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N
:
10785 case BUILT_IN_SYNC_LOCK_TEST_AND_SET_N
:
10786 case BUILT_IN_SYNC_LOCK_RELEASE_N
:
10788 int n
= sync_resolve_size (function
, params
);
10789 tree new_function
, first_param
, result
;
10790 enum built_in_function fncode
;
10793 return error_mark_node
;
10795 fncode
= (enum built_in_function
)((int)orig_code
+ exact_log2 (n
) + 1);
10796 new_function
= builtin_decl_explicit (fncode
);
10797 if (!sync_resolve_params (loc
, function
, new_function
, params
,
10799 return error_mark_node
;
10801 first_param
= (*params
)[0];
10802 result
= build_function_call_vec (loc
, new_function
, params
, NULL
);
10803 if (result
== error_mark_node
)
10805 if (orig_code
!= BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
10806 && orig_code
!= BUILT_IN_SYNC_LOCK_RELEASE_N
10807 && orig_code
!= BUILT_IN_ATOMIC_STORE_N
)
10808 result
= sync_resolve_return (first_param
, result
, orig_format
);
10810 /* If new_return is set, assign function to that expr and cast the
10811 result to void since the generic interface returned void. */
10814 /* Cast function result from I{1,2,4,8,16} to the required type. */
10815 result
= build1 (VIEW_CONVERT_EXPR
, TREE_TYPE (new_return
), result
);
10816 result
= build2 (MODIFY_EXPR
, TREE_TYPE (new_return
), new_return
,
10818 TREE_SIDE_EFFECTS (result
) = 1;
10819 protected_set_expr_location (result
, loc
);
10820 result
= convert (void_type_node
, result
);
10830 /* vector_types_compatible_elements_p is used in type checks of vectors
10831 values used as operands of binary operators. Where it returns true, and
10832 the other checks of the caller succeed (being vector types in he first
10833 place, and matching number of elements), we can just treat the types
10834 as essentially the same.
10835 Contrast with vector_targets_convertible_p, which is used for vector
10836 pointer types, and vector_types_convertible_p, which will allow
10837 language-specific matches under the control of flag_lax_vector_conversions,
10838 and might still require a conversion. */
10839 /* True if vector types T1 and T2 can be inputs to the same binary
10840 operator without conversion.
10841 We don't check the overall vector size here because some of our callers
10842 want to give different error messages when the vectors are compatible
10843 except for the element count. */
10846 vector_types_compatible_elements_p (tree t1
, tree t2
)
10848 bool opaque
= TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
);
10849 t1
= TREE_TYPE (t1
);
10850 t2
= TREE_TYPE (t2
);
10852 enum tree_code c1
= TREE_CODE (t1
), c2
= TREE_CODE (t2
);
10854 gcc_assert ((c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
|| c1
== FIXED_POINT_TYPE
)
10855 && (c2
== INTEGER_TYPE
|| c2
== REAL_TYPE
10856 || c2
== FIXED_POINT_TYPE
));
10858 t1
= c_common_signed_type (t1
);
10859 t2
= c_common_signed_type (t2
);
10860 /* Equality works here because c_common_signed_type uses
10861 TYPE_MAIN_VARIANT. */
10864 if (opaque
&& c1
== c2
10865 && (c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
)
10866 && TYPE_PRECISION (t1
) == TYPE_PRECISION (t2
))
10871 /* Check for missing format attributes on function pointers. LTYPE is
10872 the new type or left-hand side type. RTYPE is the old type or
10873 right-hand side type. Returns TRUE if LTYPE is missing the desired
10877 check_missing_format_attribute (tree ltype
, tree rtype
)
10879 tree
const ttr
= TREE_TYPE (rtype
), ttl
= TREE_TYPE (ltype
);
10882 for (ra
= TYPE_ATTRIBUTES (ttr
); ra
; ra
= TREE_CHAIN (ra
))
10883 if (is_attribute_p ("format", TREE_PURPOSE (ra
)))
10888 for (la
= TYPE_ATTRIBUTES (ttl
); la
; la
= TREE_CHAIN (la
))
10889 if (is_attribute_p ("format", TREE_PURPOSE (la
)))
10897 /* Subscripting with type char is likely to lose on a machine where
10898 chars are signed. So warn on any machine, but optionally. Don't
10899 warn for unsigned char since that type is safe. Don't warn for
10900 signed char because anyone who uses that must have done so
10901 deliberately. Furthermore, we reduce the false positive load by
10902 warning only for non-constant value of type char. */
10905 warn_array_subscript_with_type_char (tree index
)
10907 if (TYPE_MAIN_VARIANT (TREE_TYPE (index
)) == char_type_node
10908 && TREE_CODE (index
) != INTEGER_CST
)
10909 warning (OPT_Wchar_subscripts
, "array subscript has type %<char%>");
10912 /* Implement -Wparentheses for the unexpected C precedence rules, to
10913 cover cases like x + y << z which readers are likely to
10914 misinterpret. We have seen an expression in which CODE is a binary
10915 operator used to combine expressions ARG_LEFT and ARG_RIGHT, which
10916 before folding had CODE_LEFT and CODE_RIGHT. CODE_LEFT and
10917 CODE_RIGHT may be ERROR_MARK, which means that that side of the
10918 expression was not formed using a binary or unary operator, or it
10919 was enclosed in parentheses. */
10922 warn_about_parentheses (location_t loc
, enum tree_code code
,
10923 enum tree_code code_left
, tree arg_left
,
10924 enum tree_code code_right
, tree arg_right
)
10926 if (!warn_parentheses
)
10929 /* This macro tests that the expression ARG with original tree code
10930 CODE appears to be a boolean expression. or the result of folding a
10931 boolean expression. */
10932 #define APPEARS_TO_BE_BOOLEAN_EXPR_P(CODE, ARG) \
10933 (truth_value_p (TREE_CODE (ARG)) \
10934 || TREE_CODE (TREE_TYPE (ARG)) == BOOLEAN_TYPE \
10935 /* Folding may create 0 or 1 integers from other expressions. */ \
10936 || ((CODE) != INTEGER_CST \
10937 && (integer_onep (ARG) || integer_zerop (ARG))))
10942 if (code_left
== PLUS_EXPR
)
10943 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10944 "suggest parentheses around %<+%> inside %<<<%>");
10945 else if (code_right
== PLUS_EXPR
)
10946 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10947 "suggest parentheses around %<+%> inside %<<<%>");
10948 else if (code_left
== MINUS_EXPR
)
10949 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10950 "suggest parentheses around %<-%> inside %<<<%>");
10951 else if (code_right
== MINUS_EXPR
)
10952 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10953 "suggest parentheses around %<-%> inside %<<<%>");
10957 if (code_left
== PLUS_EXPR
)
10958 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10959 "suggest parentheses around %<+%> inside %<>>%>");
10960 else if (code_right
== PLUS_EXPR
)
10961 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10962 "suggest parentheses around %<+%> inside %<>>%>");
10963 else if (code_left
== MINUS_EXPR
)
10964 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10965 "suggest parentheses around %<-%> inside %<>>%>");
10966 else if (code_right
== MINUS_EXPR
)
10967 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10968 "suggest parentheses around %<-%> inside %<>>%>");
10971 case TRUTH_ORIF_EXPR
:
10972 if (code_left
== TRUTH_ANDIF_EXPR
)
10973 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10974 "suggest parentheses around %<&&%> within %<||%>");
10975 else if (code_right
== TRUTH_ANDIF_EXPR
)
10976 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10977 "suggest parentheses around %<&&%> within %<||%>");
10981 if (code_left
== BIT_AND_EXPR
|| code_left
== BIT_XOR_EXPR
10982 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
)
10983 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10984 "suggest parentheses around arithmetic in operand of %<|%>");
10985 else if (code_right
== BIT_AND_EXPR
|| code_right
== BIT_XOR_EXPR
10986 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
10987 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10988 "suggest parentheses around arithmetic in operand of %<|%>");
10989 /* Check cases like x|y==z */
10990 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
10991 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10992 "suggest parentheses around comparison in operand of %<|%>");
10993 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
10994 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10995 "suggest parentheses around comparison in operand of %<|%>");
10996 /* Check cases like !x | y */
10997 else if (code_left
== TRUTH_NOT_EXPR
10998 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
10999 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11000 "suggest parentheses around operand of "
11001 "%<!%> or change %<|%> to %<||%> or %<!%> to %<~%>");
11005 if (code_left
== BIT_AND_EXPR
11006 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
)
11007 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11008 "suggest parentheses around arithmetic in operand of %<^%>");
11009 else if (code_right
== BIT_AND_EXPR
11010 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
11011 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11012 "suggest parentheses around arithmetic in operand of %<^%>");
11013 /* Check cases like x^y==z */
11014 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11015 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11016 "suggest parentheses around comparison in operand of %<^%>");
11017 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11018 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11019 "suggest parentheses around comparison in operand of %<^%>");
11023 if (code_left
== PLUS_EXPR
)
11024 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11025 "suggest parentheses around %<+%> in operand of %<&%>");
11026 else if (code_right
== PLUS_EXPR
)
11027 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11028 "suggest parentheses around %<+%> in operand of %<&%>");
11029 else if (code_left
== MINUS_EXPR
)
11030 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11031 "suggest parentheses around %<-%> in operand of %<&%>");
11032 else if (code_right
== MINUS_EXPR
)
11033 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11034 "suggest parentheses around %<-%> in operand of %<&%>");
11035 /* Check cases like x&y==z */
11036 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11037 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11038 "suggest parentheses around comparison in operand of %<&%>");
11039 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11040 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11041 "suggest parentheses around comparison in operand of %<&%>");
11042 /* Check cases like !x & y */
11043 else if (code_left
== TRUTH_NOT_EXPR
11044 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
11045 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11046 "suggest parentheses around operand of "
11047 "%<!%> or change %<&%> to %<&&%> or %<!%> to %<~%>");
11051 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11052 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11053 "suggest parentheses around comparison in operand of %<==%>");
11054 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11055 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11056 "suggest parentheses around comparison in operand of %<==%>");
11059 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11060 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11061 "suggest parentheses around comparison in operand of %<!=%>");
11062 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11063 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11064 "suggest parentheses around comparison in operand of %<!=%>");
11068 if (TREE_CODE_CLASS (code
) == tcc_comparison
)
11070 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
11071 && code_left
!= NE_EXPR
&& code_left
!= EQ_EXPR
11072 && INTEGRAL_TYPE_P (TREE_TYPE (arg_left
)))
11073 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11074 "comparisons like %<X<=Y<=Z%> do not "
11075 "have their mathematical meaning");
11076 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
11077 && code_right
!= NE_EXPR
&& code_right
!= EQ_EXPR
11078 && INTEGRAL_TYPE_P (TREE_TYPE (arg_right
)))
11079 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11080 "comparisons like %<X<=Y<=Z%> do not "
11081 "have their mathematical meaning");
11085 #undef NOT_A_BOOLEAN_EXPR_P
11088 /* If LABEL (a LABEL_DECL) has not been used, issue a warning. */
11091 warn_for_unused_label (tree label
)
11093 if (!TREE_USED (label
))
11095 if (DECL_INITIAL (label
))
11096 warning (OPT_Wunused_label
, "label %q+D defined but not used", label
);
11098 warning (OPT_Wunused_label
, "label %q+D declared but not defined", label
);
11102 /* Warn for division by zero according to the value of DIVISOR. LOC
11103 is the location of the division operator. */
11106 warn_for_div_by_zero (location_t loc
, tree divisor
)
11108 /* If DIVISOR is zero, and has integral or fixed-point type, issue a warning
11109 about division by zero. Do not issue a warning if DIVISOR has a
11110 floating-point type, since we consider 0.0/0.0 a valid way of
11111 generating a NaN. */
11112 if (c_inhibit_evaluation_warnings
== 0
11113 && (integer_zerop (divisor
) || fixed_zerop (divisor
)))
11114 warning_at (loc
, OPT_Wdiv_by_zero
, "division by zero");
11117 /* Subroutine of build_binary_op. Give warnings for comparisons
11118 between signed and unsigned quantities that may fail. Do the
11119 checking based on the original operand trees ORIG_OP0 and ORIG_OP1,
11120 so that casts will be considered, but default promotions won't
11123 LOCATION is the location of the comparison operator.
11125 The arguments of this function map directly to local variables
11126 of build_binary_op. */
11129 warn_for_sign_compare (location_t location
,
11130 tree orig_op0
, tree orig_op1
,
11131 tree op0
, tree op1
,
11132 tree result_type
, enum tree_code resultcode
)
11134 int op0_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op0
));
11135 int op1_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op1
));
11136 int unsignedp0
, unsignedp1
;
11138 /* In C++, check for comparison of different enum types. */
11139 if (c_dialect_cxx()
11140 && TREE_CODE (TREE_TYPE (orig_op0
)) == ENUMERAL_TYPE
11141 && TREE_CODE (TREE_TYPE (orig_op1
)) == ENUMERAL_TYPE
11142 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0
))
11143 != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1
)))
11145 warning_at (location
,
11146 OPT_Wsign_compare
, "comparison between types %qT and %qT",
11147 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
));
11150 /* Do not warn if the comparison is being done in a signed type,
11151 since the signed type will only be chosen if it can represent
11152 all the values of the unsigned type. */
11153 if (!TYPE_UNSIGNED (result_type
))
11155 /* Do not warn if both operands are unsigned. */
11156 else if (op0_signed
== op1_signed
)
11160 tree sop
, uop
, base_type
;
11164 sop
= orig_op0
, uop
= orig_op1
;
11166 sop
= orig_op1
, uop
= orig_op0
;
11168 STRIP_TYPE_NOPS (sop
);
11169 STRIP_TYPE_NOPS (uop
);
11170 base_type
= (TREE_CODE (result_type
) == COMPLEX_TYPE
11171 ? TREE_TYPE (result_type
) : result_type
);
11173 /* Do not warn if the signed quantity is an unsuffixed integer
11174 literal (or some static constant expression involving such
11175 literals or a conditional expression involving such literals)
11176 and it is non-negative. */
11177 if (tree_expr_nonnegative_warnv_p (sop
, &ovf
))
11179 /* Do not warn if the comparison is an equality operation, the
11180 unsigned quantity is an integral constant, and it would fit
11181 in the result if the result were signed. */
11182 else if (TREE_CODE (uop
) == INTEGER_CST
11183 && (resultcode
== EQ_EXPR
|| resultcode
== NE_EXPR
)
11184 && int_fits_type_p (uop
, c_common_signed_type (base_type
)))
11186 /* In C, do not warn if the unsigned quantity is an enumeration
11187 constant and its maximum value would fit in the result if the
11188 result were signed. */
11189 else if (!c_dialect_cxx() && TREE_CODE (uop
) == INTEGER_CST
11190 && TREE_CODE (TREE_TYPE (uop
)) == ENUMERAL_TYPE
11191 && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (uop
)),
11192 c_common_signed_type (base_type
)))
11195 warning_at (location
,
11197 "comparison between signed and unsigned integer expressions");
11200 /* Warn if two unsigned values are being compared in a size larger
11201 than their original size, and one (and only one) is the result of
11202 a `~' operator. This comparison will always fail.
11204 Also warn if one operand is a constant, and the constant does not
11205 have all bits set that are set in the ~ operand when it is
11208 op0
= c_common_get_narrower (op0
, &unsignedp0
);
11209 op1
= c_common_get_narrower (op1
, &unsignedp1
);
11211 if ((TREE_CODE (op0
) == BIT_NOT_EXPR
)
11212 ^ (TREE_CODE (op1
) == BIT_NOT_EXPR
))
11214 if (TREE_CODE (op0
) == BIT_NOT_EXPR
)
11215 op0
= c_common_get_narrower (TREE_OPERAND (op0
, 0), &unsignedp0
);
11216 if (TREE_CODE (op1
) == BIT_NOT_EXPR
)
11217 op1
= c_common_get_narrower (TREE_OPERAND (op1
, 0), &unsignedp1
);
11219 if (host_integerp (op0
, 0) || host_integerp (op1
, 0))
11222 HOST_WIDE_INT constant
, mask
;
11226 if (host_integerp (op0
, 0))
11229 unsignedp
= unsignedp1
;
11230 constant
= tree_low_cst (op0
, 0);
11235 unsignedp
= unsignedp0
;
11236 constant
= tree_low_cst (op1
, 0);
11239 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
11240 if (bits
< TYPE_PRECISION (result_type
)
11241 && bits
< HOST_BITS_PER_LONG
&& unsignedp
)
11243 mask
= (~ (HOST_WIDE_INT
) 0) << bits
;
11244 if ((mask
& constant
) != mask
)
11247 warning (OPT_Wsign_compare
,
11248 "promoted ~unsigned is always non-zero");
11250 warning_at (location
, OPT_Wsign_compare
,
11251 "comparison of promoted ~unsigned with constant");
11255 else if (unsignedp0
&& unsignedp1
11256 && (TYPE_PRECISION (TREE_TYPE (op0
))
11257 < TYPE_PRECISION (result_type
))
11258 && (TYPE_PRECISION (TREE_TYPE (op1
))
11259 < TYPE_PRECISION (result_type
)))
11260 warning_at (location
, OPT_Wsign_compare
,
11261 "comparison of promoted ~unsigned with unsigned");
11265 /* RESULT_TYPE is the result of converting TYPE1 and TYPE2 to a common
11266 type via c_common_type. If -Wdouble-promotion is in use, and the
11267 conditions for warning have been met, issue a warning. GMSGID is
11268 the warning message. It must have two %T specifiers for the type
11269 that was converted (generally "float") and the type to which it was
11270 converted (generally "double), respectively. LOC is the location
11271 to which the awrning should refer. */
11274 do_warn_double_promotion (tree result_type
, tree type1
, tree type2
,
11275 const char *gmsgid
, location_t loc
)
11279 if (!warn_double_promotion
)
11281 /* If the conversion will not occur at run-time, there is no need to
11283 if (c_inhibit_evaluation_warnings
)
11285 if (TYPE_MAIN_VARIANT (result_type
) != double_type_node
11286 && TYPE_MAIN_VARIANT (result_type
) != complex_double_type_node
)
11288 if (TYPE_MAIN_VARIANT (type1
) == float_type_node
11289 || TYPE_MAIN_VARIANT (type1
) == complex_float_type_node
)
11290 source_type
= type1
;
11291 else if (TYPE_MAIN_VARIANT (type2
) == float_type_node
11292 || TYPE_MAIN_VARIANT (type2
) == complex_float_type_node
)
11293 source_type
= type2
;
11296 warning_at (loc
, OPT_Wdouble_promotion
, gmsgid
, source_type
, result_type
);
11299 /* Setup a TYPE_DECL node as a typedef representation.
11301 X is a TYPE_DECL for a typedef statement. Create a brand new
11302 ..._TYPE node (which will be just a variant of the existing
11303 ..._TYPE node with identical properties) and then install X
11304 as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
11306 The whole point here is to end up with a situation where each
11307 and every ..._TYPE node the compiler creates will be uniquely
11308 associated with AT MOST one node representing a typedef name.
11309 This way, even though the compiler substitutes corresponding
11310 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
11311 early on, later parts of the compiler can always do the reverse
11312 translation and get back the corresponding typedef name. For
11315 typedef struct S MY_TYPE;
11318 Later parts of the compiler might only know that `object' was of
11319 type `struct S' if it were not for code just below. With this
11320 code however, later parts of the compiler see something like:
11322 struct S' == struct S
11323 typedef struct S' MY_TYPE;
11326 And they can then deduce (from the node for type struct S') that
11327 the original object declaration was:
11331 Being able to do this is important for proper support of protoize,
11332 and also for generating precise symbolic debugging information
11333 which takes full account of the programmer's (typedef) vocabulary.
11335 Obviously, we don't want to generate a duplicate ..._TYPE node if
11336 the TYPE_DECL node that we are now processing really represents a
11337 standard built-in type. */
11340 set_underlying_type (tree x
)
11342 if (x
== error_mark_node
)
11344 if (DECL_IS_BUILTIN (x
))
11346 if (TYPE_NAME (TREE_TYPE (x
)) == 0)
11347 TYPE_NAME (TREE_TYPE (x
)) = x
;
11349 else if (TREE_TYPE (x
) != error_mark_node
11350 && DECL_ORIGINAL_TYPE (x
) == NULL_TREE
)
11352 tree tt
= TREE_TYPE (x
);
11353 DECL_ORIGINAL_TYPE (x
) = tt
;
11354 tt
= build_variant_type_copy (tt
);
11355 TYPE_STUB_DECL (tt
) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x
));
11356 TYPE_NAME (tt
) = x
;
11357 TREE_USED (tt
) = TREE_USED (x
);
11358 TREE_TYPE (x
) = tt
;
11362 /* Record the types used by the current global variable declaration
11363 being parsed, so that we can decide later to emit their debug info.
11364 Those types are in types_used_by_cur_var_decl, and we are going to
11365 store them in the types_used_by_vars_hash hash table.
11366 DECL is the declaration of the global variable that has been parsed. */
11369 record_types_used_by_current_var_decl (tree decl
)
11371 gcc_assert (decl
&& DECL_P (decl
) && TREE_STATIC (decl
));
11373 while (types_used_by_cur_var_decl
&& !types_used_by_cur_var_decl
->is_empty ())
11375 tree type
= types_used_by_cur_var_decl
->pop ();
11376 types_used_by_var_decl_insert (type
, decl
);
11380 /* If DECL is a typedef that is declared in the current function,
11381 record it for the purpose of -Wunused-local-typedefs. */
11384 record_locally_defined_typedef (tree decl
)
11386 struct c_language_function
*l
;
11388 if (!warn_unused_local_typedefs
11390 /* if this is not a locally defined typedef then we are not
11392 || !is_typedef_decl (decl
)
11393 || !decl_function_context (decl
))
11396 l
= (struct c_language_function
*) cfun
->language
;
11397 vec_safe_push (l
->local_typedefs
, decl
);
11400 /* If T is a TYPE_DECL declared locally, mark it as used. */
11403 maybe_record_typedef_use (tree t
)
11405 if (!is_typedef_decl (t
))
11408 TREE_USED (t
) = true;
11411 /* Warn if there are some unused locally defined typedefs in the
11412 current function. */
11415 maybe_warn_unused_local_typedefs (void)
11419 /* The number of times we have emitted -Wunused-local-typedefs
11420 warnings. If this is different from errorcount, that means some
11421 unrelated errors have been issued. In which case, we'll avoid
11422 emitting "unused-local-typedefs" warnings. */
11423 static int unused_local_typedefs_warn_count
;
11424 struct c_language_function
*l
;
11429 if ((l
= (struct c_language_function
*) cfun
->language
) == NULL
)
11432 if (warn_unused_local_typedefs
11433 && errorcount
== unused_local_typedefs_warn_count
)
11435 FOR_EACH_VEC_SAFE_ELT (l
->local_typedefs
, i
, decl
)
11436 if (!TREE_USED (decl
))
11437 warning_at (DECL_SOURCE_LOCATION (decl
),
11438 OPT_Wunused_local_typedefs
,
11439 "typedef %qD locally defined but not used", decl
);
11440 unused_local_typedefs_warn_count
= errorcount
;
11443 vec_free (l
->local_typedefs
);
11446 /* The C and C++ parsers both use vectors to hold function arguments.
11447 For efficiency, we keep a cache of unused vectors. This is the
11450 typedef vec
<tree
, va_gc
> *tree_gc_vec
;
11451 static GTY((deletable
)) vec
<tree_gc_vec
, va_gc
> *tree_vector_cache
;
11453 /* Return a new vector from the cache. If the cache is empty,
11454 allocate a new vector. These vectors are GC'ed, so it is OK if the
11455 pointer is not released.. */
11458 make_tree_vector (void)
11460 if (tree_vector_cache
&& !tree_vector_cache
->is_empty ())
11461 return tree_vector_cache
->pop ();
11464 /* Passing 0 to vec::alloc returns NULL, and our callers require
11465 that we always return a non-NULL value. The vector code uses
11466 4 when growing a NULL vector, so we do too. */
11467 vec
<tree
, va_gc
> *v
;
11473 /* Release a vector of trees back to the cache. */
11476 release_tree_vector (vec
<tree
, va_gc
> *vec
)
11481 vec_safe_push (tree_vector_cache
, vec
);
11485 /* Get a new tree vector holding a single tree. */
11488 make_tree_vector_single (tree t
)
11490 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
11491 ret
->quick_push (t
);
11495 /* Get a new tree vector of the TREE_VALUEs of a TREE_LIST chain. */
11498 make_tree_vector_from_list (tree list
)
11500 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
11501 for (; list
; list
= TREE_CHAIN (list
))
11502 vec_safe_push (ret
, TREE_VALUE (list
));
11506 /* Get a new tree vector which is a copy of an existing one. */
11509 make_tree_vector_copy (const vec
<tree
, va_gc
> *orig
)
11511 vec
<tree
, va_gc
> *ret
;
11515 ret
= make_tree_vector ();
11516 vec_safe_reserve (ret
, vec_safe_length (orig
));
11517 FOR_EACH_VEC_SAFE_ELT (orig
, ix
, t
)
11518 ret
->quick_push (t
);
11522 /* Return true if KEYWORD starts a type specifier. */
11525 keyword_begins_type_specifier (enum rid keyword
)
11541 case RID_DFLOAT128
:
11561 /* Return true if KEYWORD names a type qualifier. */
11564 keyword_is_type_qualifier (enum rid keyword
)
11577 /* Return true if KEYWORD names a storage class specifier.
11579 RID_TYPEDEF is not included in this list despite `typedef' being
11580 listed in C99 6.7.1.1. 6.7.1.3 indicates that `typedef' is listed as
11581 such for syntactic convenience only. */
11584 keyword_is_storage_class_specifier (enum rid keyword
)
11600 /* Return true if KEYWORD names a function-specifier [dcl.fct.spec]. */
11603 keyword_is_function_specifier (enum rid keyword
)
11617 /* Return true if KEYWORD names a decl-specifier [dcl.spec] or a
11618 declaration-specifier (C99 6.7). */
11621 keyword_is_decl_specifier (enum rid keyword
)
11623 if (keyword_is_storage_class_specifier (keyword
)
11624 || keyword_is_type_qualifier (keyword
)
11625 || keyword_is_function_specifier (keyword
))
11632 case RID_CONSTEXPR
:
11639 /* Initialize language-specific-bits of tree_contains_struct. */
11642 c_common_init_ts (void)
11644 MARK_TS_TYPED (C_MAYBE_CONST_EXPR
);
11645 MARK_TS_TYPED (EXCESS_PRECISION_EXPR
);
11646 MARK_TS_TYPED (ARRAY_NOTATION_REF
);
11649 /* Build a user-defined numeric literal out of an integer constant type VALUE
11650 with identifier SUFFIX. */
11653 build_userdef_literal (tree suffix_id
, tree value
,
11654 enum overflow_type overflow
, tree num_string
)
11656 tree literal
= make_node (USERDEF_LITERAL
);
11657 USERDEF_LITERAL_SUFFIX_ID (literal
) = suffix_id
;
11658 USERDEF_LITERAL_VALUE (literal
) = value
;
11659 USERDEF_LITERAL_OVERFLOW (literal
) = overflow
;
11660 USERDEF_LITERAL_NUM_STRING (literal
) = num_string
;
11664 /* For vector[index], convert the vector to a
11665 pointer of the underlying type. */
11667 convert_vector_to_pointer_for_subscript (location_t loc
,
11668 tree
* vecp
, tree index
)
11670 if (TREE_CODE (TREE_TYPE (*vecp
)) == VECTOR_TYPE
)
11672 tree type
= TREE_TYPE (*vecp
);
11675 if (TREE_CODE (index
) == INTEGER_CST
)
11676 if (!host_integerp (index
, 1)
11677 || ((unsigned HOST_WIDE_INT
) tree_low_cst (index
, 1)
11678 >= TYPE_VECTOR_SUBPARTS (type
)))
11679 warning_at (loc
, OPT_Warray_bounds
, "index value is out of bound");
11681 c_common_mark_addressable_vec (*vecp
);
11682 type
= build_qualified_type (TREE_TYPE (type
), TYPE_QUALS (type
));
11683 type
= build_pointer_type (type
);
11684 type1
= build_pointer_type (TREE_TYPE (*vecp
));
11685 *vecp
= build1 (ADDR_EXPR
, type1
, *vecp
);
11686 *vecp
= convert (type
, *vecp
);
11690 /* Determine which of the operands, if any, is a scalar that needs to be
11691 converted to a vector, for the range of operations. */
11693 scalar_to_vector (location_t loc
, enum tree_code code
, tree op0
, tree op1
,
11696 tree type0
= TREE_TYPE (op0
);
11697 tree type1
= TREE_TYPE (op1
);
11698 bool integer_only_op
= false;
11699 enum stv_conv ret
= stv_firstarg
;
11701 gcc_assert (TREE_CODE (type0
) == VECTOR_TYPE
11702 || TREE_CODE (type1
) == VECTOR_TYPE
);
11705 /* Most GENERIC binary expressions require homogeneous arguments.
11706 LSHIFT_EXPR and RSHIFT_EXPR are exceptions and accept a first
11707 argument that is a vector and a second one that is a scalar, so
11708 we never return stv_secondarg for them. */
11711 if (TREE_CODE (type0
) == INTEGER_TYPE
11712 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
11714 if (unsafe_conversion_p (TREE_TYPE (type1
), op0
, false))
11717 error_at (loc
, "conversion of scalar %qT to vector %qT "
11718 "involves truncation", type0
, type1
);
11722 return stv_firstarg
;
11729 integer_only_op
= true;
11730 /* ... fall through ... */
11732 case VEC_COND_EXPR
:
11737 case TRUNC_DIV_EXPR
:
11738 case CEIL_DIV_EXPR
:
11739 case FLOOR_DIV_EXPR
:
11740 case ROUND_DIV_EXPR
:
11741 case EXACT_DIV_EXPR
:
11742 case TRUNC_MOD_EXPR
:
11743 case FLOOR_MOD_EXPR
:
11751 /* What about UNLT_EXPR? */
11752 if (TREE_CODE (type0
) == VECTOR_TYPE
)
11755 ret
= stv_secondarg
;
11756 /* Swap TYPE0 with TYPE1 and OP0 with OP1 */
11757 tmp
= type0
; type0
= type1
; type1
= tmp
;
11758 tmp
= op0
; op0
= op1
; op1
= tmp
;
11761 if (TREE_CODE (type0
) == INTEGER_TYPE
11762 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
11764 if (unsafe_conversion_p (TREE_TYPE (type1
), op0
, false))
11767 error_at (loc
, "conversion of scalar %qT to vector %qT "
11768 "involves truncation", type0
, type1
);
11773 else if (!integer_only_op
11774 /* Allow integer --> real conversion if safe. */
11775 && (TREE_CODE (type0
) == REAL_TYPE
11776 || TREE_CODE (type0
) == INTEGER_TYPE
)
11777 && SCALAR_FLOAT_TYPE_P (TREE_TYPE (type1
)))
11779 if (unsafe_conversion_p (TREE_TYPE (type1
), op0
, false))
11782 error_at (loc
, "conversion of scalar %qT to vector %qT "
11783 "involves truncation", type0
, type1
);
11792 return stv_nothing
;
11795 /* Return true iff ALIGN is an integral constant that is a fundamental
11796 alignment, as defined by [basic.align] in the c++-11
11801 [A fundamental alignment is represented by an alignment less than or
11802 equal to the greatest alignment supported by the implementation
11803 in all contexts, which is equal to
11804 alignof(max_align_t)]. */
11807 cxx_fundamental_alignment_p (unsigned align
)
11809 return (align
<= MAX (TYPE_ALIGN (long_long_integer_type_node
),
11810 TYPE_ALIGN (long_double_type_node
)));
11813 #include "gt-c-family-c-common.h"