1 /* Subroutines shared by all languages that are variants of C.
2 Copyright (C) 1992-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #define GCC_C_COMMON_C
24 #include "coretypes.h"
29 #include "fold-const.h"
30 #include "stor-layout.h"
32 #include "stringpool.h"
35 #include "trans-mem.h"
43 #include "common/common-target.h"
44 #include "langhooks.h"
45 #include "tree-inline.h"
47 #include "diagnostic.h"
48 #include "tree-iterator.h"
50 #include "hard-reg-set.h"
54 #include "wide-int-print.h"
55 #include "gimple-expr.h"
57 cpp_reader
*parse_in
; /* Declared in c-pragma.h. */
59 /* Mode used to build pointers (VOIDmode means ptr_mode). */
61 machine_mode c_default_pointer_mode
= VOIDmode
;
63 /* The following symbols are subsumed in the c_global_trees array, and
64 listed here individually for documentation purposes.
66 INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
68 tree short_integer_type_node;
69 tree long_integer_type_node;
70 tree long_long_integer_type_node;
72 tree short_unsigned_type_node;
73 tree long_unsigned_type_node;
74 tree long_long_unsigned_type_node;
76 tree truthvalue_type_node;
77 tree truthvalue_false_node;
78 tree truthvalue_true_node;
80 tree ptrdiff_type_node;
82 tree unsigned_char_type_node;
83 tree signed_char_type_node;
86 tree char16_type_node;
87 tree char32_type_node;
90 tree double_type_node;
91 tree long_double_type_node;
93 tree complex_integer_type_node;
94 tree complex_float_type_node;
95 tree complex_double_type_node;
96 tree complex_long_double_type_node;
98 tree dfloat32_type_node;
99 tree dfloat64_type_node;
100 tree_dfloat128_type_node;
102 tree intQI_type_node;
103 tree intHI_type_node;
104 tree intSI_type_node;
105 tree intDI_type_node;
106 tree intTI_type_node;
108 tree unsigned_intQI_type_node;
109 tree unsigned_intHI_type_node;
110 tree unsigned_intSI_type_node;
111 tree unsigned_intDI_type_node;
112 tree unsigned_intTI_type_node;
114 tree widest_integer_literal_type_node;
115 tree widest_unsigned_literal_type_node;
117 Nodes for types `void *' and `const void *'.
119 tree ptr_type_node, const_ptr_type_node;
121 Nodes for types `char *' and `const char *'.
123 tree string_type_node, const_string_type_node;
125 Type `char[SOMENUMBER]'.
126 Used when an array of char is needed and the size is irrelevant.
128 tree char_array_type_node;
130 Type `wchar_t[SOMENUMBER]' or something like it.
131 Used when a wide string literal is created.
133 tree wchar_array_type_node;
135 Type `char16_t[SOMENUMBER]' or something like it.
136 Used when a UTF-16 string literal is created.
138 tree char16_array_type_node;
140 Type `char32_t[SOMENUMBER]' or something like it.
141 Used when a UTF-32 string literal is created.
143 tree char32_array_type_node;
145 Type `int ()' -- used for implicit declaration of functions.
147 tree default_function_type;
149 A VOID_TYPE node, packaged in a TREE_LIST.
153 The lazily created VAR_DECLs for __FUNCTION__, __PRETTY_FUNCTION__,
154 and __func__. (C doesn't generate __FUNCTION__ and__PRETTY_FUNCTION__
155 VAR_DECLS, but C++ does.)
157 tree function_name_decl_node;
158 tree pretty_function_name_decl_node;
159 tree c99_function_name_decl_node;
161 Stack of nested function name VAR_DECLs.
163 tree saved_function_name_decls;
167 tree c_global_trees
[CTI_MAX
];
169 /* Switches common to the C front ends. */
171 /* Nonzero means don't output line number information. */
173 char flag_no_line_commands
;
175 /* Nonzero causes -E output not to be done, but directives such as
176 #define that have side effects are still obeyed. */
180 /* Nonzero means dump macros in some fashion. */
182 char flag_dump_macros
;
184 /* Nonzero means pass #include lines through to the output. */
186 char flag_dump_includes
;
188 /* Nonzero means process PCH files while preprocessing. */
190 bool flag_pch_preprocess
;
192 /* The file name to which we should write a precompiled header, or
193 NULL if no header will be written in this compile. */
195 const char *pch_file
;
197 /* Nonzero if an ISO standard was selected. It rejects macros in the
201 /* C/ObjC language option variables. */
204 /* Nonzero means allow type mismatches in conditional expressions;
205 just make their values `void'. */
207 int flag_cond_mismatch
;
209 /* Nonzero means enable C89 Amendment 1 features. */
213 /* Nonzero means use the ISO C99 (or C11) dialect of C. */
217 /* Nonzero means use the ISO C11 dialect of C. */
221 /* Nonzero means that we have builtin functions, and main is an int. */
226 /* ObjC language option variables. */
229 /* Tells the compiler that this is a special run. Do not perform any
230 compiling, instead we are to test some platform dependent features
231 and output a C header file with appropriate definitions. */
233 int print_struct_values
;
235 /* Tells the compiler what is the constant string class for ObjC. */
237 const char *constant_string_class_name
;
240 /* C++ language option variables. */
243 /* Nonzero means generate separate instantiation control files and
244 juggle them at link time. */
246 int flag_use_repository
;
248 /* The C++ dialect being used. Default set in c_common_post_options. */
250 enum cxx_dialect cxx_dialect
= cxx_unset
;
252 /* Maximum template instantiation depth. This limit exists to limit the
253 time it takes to notice excessively recursive template instantiations.
255 The default is lower than the 1024 recommended by the C++0x standard
256 because G++ runs out of stack before 1024 with highly recursive template
257 argument deduction substitution (g++.dg/cpp0x/enum11.C). */
259 int max_tinst_depth
= 900;
261 /* The elements of `ridpointers' are identifier nodes for the reserved
262 type names and storage classes. It is indexed by a RID_... value. */
265 tree (*make_fname_decl
) (location_t
, tree
, int);
267 /* Nonzero means don't warn about problems that occur when the code is
269 int c_inhibit_evaluation_warnings
;
271 /* Whether we are building a boolean conversion inside
272 convert_for_assignment, or some other late binary operation. If
273 build_binary_op is called for C (from code shared by C and C++) in
274 this case, then the operands have already been folded and the
275 result will not be folded again, so C_MAYBE_CONST_EXPR should not
277 bool in_late_binary_op
;
279 /* Whether lexing has been completed, so subsequent preprocessor
280 errors should use the compiler's input_location. */
281 bool done_lexing
= false;
283 /* Information about how a function name is generated. */
286 tree
*const decl
; /* pointer to the VAR_DECL. */
287 const unsigned rid
; /* RID number for the identifier. */
288 const int pretty
; /* How pretty is it? */
291 /* The three ways of getting then name of the current function. */
293 const struct fname_var_t fname_vars
[] =
295 /* C99 compliant __func__, must be first. */
296 {&c99_function_name_decl_node
, RID_C99_FUNCTION_NAME
, 0},
297 /* GCC __FUNCTION__ compliant. */
298 {&function_name_decl_node
, RID_FUNCTION_NAME
, 0},
299 /* GCC __PRETTY_FUNCTION__ compliant. */
300 {&pretty_function_name_decl_node
, RID_PRETTY_FUNCTION_NAME
, 1},
304 /* Global visibility options. */
305 struct visibility_flags visibility_options
;
307 static tree
c_fully_fold_internal (tree expr
, bool, bool *, bool *, bool);
308 static tree
check_case_value (location_t
, tree
);
309 static bool check_case_bounds (location_t
, tree
, tree
, tree
*, tree
*,
312 static tree
handle_packed_attribute (tree
*, tree
, tree
, int, bool *);
313 static tree
handle_nocommon_attribute (tree
*, tree
, tree
, int, bool *);
314 static tree
handle_common_attribute (tree
*, tree
, tree
, int, bool *);
315 static tree
handle_noreturn_attribute (tree
*, tree
, tree
, int, bool *);
316 static tree
handle_hot_attribute (tree
*, tree
, tree
, int, bool *);
317 static tree
handle_cold_attribute (tree
*, tree
, tree
, int, bool *);
318 static tree
handle_no_sanitize_address_attribute (tree
*, tree
, tree
,
320 static tree
handle_no_address_safety_analysis_attribute (tree
*, tree
, tree
,
322 static tree
handle_no_sanitize_undefined_attribute (tree
*, tree
, tree
, int,
324 static tree
handle_stack_protect_attribute (tree
*, tree
, tree
, int, bool *);
325 static tree
handle_noinline_attribute (tree
*, tree
, tree
, int, bool *);
326 static tree
handle_noclone_attribute (tree
*, tree
, tree
, int, bool *);
327 static tree
handle_noicf_attribute (tree
*, tree
, tree
, int, bool *);
328 static tree
handle_leaf_attribute (tree
*, tree
, tree
, int, bool *);
329 static tree
handle_always_inline_attribute (tree
*, tree
, tree
, int,
331 static tree
handle_gnu_inline_attribute (tree
*, tree
, tree
, int, bool *);
332 static tree
handle_artificial_attribute (tree
*, tree
, tree
, int, bool *);
333 static tree
handle_flatten_attribute (tree
*, tree
, tree
, int, bool *);
334 static tree
handle_error_attribute (tree
*, tree
, tree
, int, bool *);
335 static tree
handle_used_attribute (tree
*, tree
, tree
, int, bool *);
336 static tree
handle_unused_attribute (tree
*, tree
, tree
, int, bool *);
337 static tree
handle_externally_visible_attribute (tree
*, tree
, tree
, int,
339 static tree
handle_no_reorder_attribute (tree
*, tree
, tree
, int,
341 static tree
handle_const_attribute (tree
*, tree
, tree
, int, bool *);
342 static tree
handle_transparent_union_attribute (tree
*, tree
, tree
,
344 static tree
handle_constructor_attribute (tree
*, tree
, tree
, int, bool *);
345 static tree
handle_destructor_attribute (tree
*, tree
, tree
, int, bool *);
346 static tree
handle_mode_attribute (tree
*, tree
, tree
, int, bool *);
347 static tree
handle_section_attribute (tree
*, tree
, tree
, int, bool *);
348 static tree
handle_aligned_attribute (tree
*, tree
, tree
, int, bool *);
349 static tree
handle_weak_attribute (tree
*, tree
, tree
, int, bool *) ;
350 static tree
handle_noplt_attribute (tree
*, tree
, tree
, int, bool *) ;
351 static tree
handle_alias_ifunc_attribute (bool, tree
*, tree
, tree
, bool *);
352 static tree
handle_ifunc_attribute (tree
*, tree
, tree
, int, bool *);
353 static tree
handle_alias_attribute (tree
*, tree
, tree
, int, bool *);
354 static tree
handle_weakref_attribute (tree
*, tree
, tree
, int, bool *) ;
355 static tree
handle_visibility_attribute (tree
*, tree
, tree
, int,
357 static tree
handle_tls_model_attribute (tree
*, tree
, tree
, int,
359 static tree
handle_no_instrument_function_attribute (tree
*, tree
,
361 static tree
handle_malloc_attribute (tree
*, tree
, tree
, int, bool *);
362 static tree
handle_returns_twice_attribute (tree
*, tree
, tree
, int, bool *);
363 static tree
handle_no_limit_stack_attribute (tree
*, tree
, tree
, int,
365 static tree
handle_pure_attribute (tree
*, tree
, tree
, int, bool *);
366 static tree
handle_tm_attribute (tree
*, tree
, tree
, int, bool *);
367 static tree
handle_tm_wrap_attribute (tree
*, tree
, tree
, int, bool *);
368 static tree
handle_novops_attribute (tree
*, tree
, tree
, int, bool *);
369 static tree
handle_deprecated_attribute (tree
*, tree
, tree
, int,
371 static tree
handle_vector_size_attribute (tree
*, tree
, tree
, int,
373 static tree
handle_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
374 static tree
handle_nothrow_attribute (tree
*, tree
, tree
, int, bool *);
375 static tree
handle_cleanup_attribute (tree
*, tree
, tree
, int, bool *);
376 static tree
handle_warn_unused_result_attribute (tree
*, tree
, tree
, int,
378 static tree
handle_sentinel_attribute (tree
*, tree
, tree
, int, bool *);
379 static tree
handle_type_generic_attribute (tree
*, tree
, tree
, int, bool *);
380 static tree
handle_alloc_size_attribute (tree
*, tree
, tree
, int, bool *);
381 static tree
handle_alloc_align_attribute (tree
*, tree
, tree
, int, bool *);
382 static tree
handle_assume_aligned_attribute (tree
*, tree
, tree
, int, bool *);
383 static tree
handle_target_attribute (tree
*, tree
, tree
, int, bool *);
384 static tree
handle_optimize_attribute (tree
*, tree
, tree
, int, bool *);
385 static tree
ignore_attribute (tree
*, tree
, tree
, int, bool *);
386 static tree
handle_no_split_stack_attribute (tree
*, tree
, tree
, int, bool *);
387 static tree
handle_fnspec_attribute (tree
*, tree
, tree
, int, bool *);
388 static tree
handle_warn_unused_attribute (tree
*, tree
, tree
, int, bool *);
389 static tree
handle_returns_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
390 static tree
handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int,
392 static tree
handle_omp_declare_target_attribute (tree
*, tree
, tree
, int,
394 static tree
handle_designated_init_attribute (tree
*, tree
, tree
, int, bool *);
395 static tree
handle_bnd_variable_size_attribute (tree
*, tree
, tree
, int, bool *);
396 static tree
handle_bnd_legacy (tree
*, tree
, tree
, int, bool *);
397 static tree
handle_bnd_instrument (tree
*, tree
, tree
, int, bool *);
399 static void check_function_nonnull (tree
, int, tree
*);
400 static void check_nonnull_arg (void *, tree
, unsigned HOST_WIDE_INT
);
401 static bool nonnull_check_p (tree
, unsigned HOST_WIDE_INT
);
402 static bool get_nonnull_operand (tree
, unsigned HOST_WIDE_INT
*);
403 static int resort_field_decl_cmp (const void *, const void *);
405 /* Reserved words. The third field is a mask: keywords are disabled
406 if they match the mask.
409 C --std=c89: D_C99 | D_CXXONLY | D_OBJC | D_CXX_OBJC
410 C --std=c99: D_CXXONLY | D_OBJC
411 ObjC is like C except that D_OBJC and D_CXX_OBJC are not set
412 C++ --std=c98: D_CONLY | D_CXXOX | D_OBJC
413 C++ --std=c0x: D_CONLY | D_OBJC
414 ObjC++ is like C++ except that D_OBJC is not set
416 If -fno-asm is used, D_ASM is added to the mask. If
417 -fno-gnu-keywords is used, D_EXT is added. If -fno-asm and C in
418 C89 mode, D_EXT89 is added for both -fno-asm and -fno-gnu-keywords.
419 In C with -Wc++-compat, we warn if D_CXXWARN is set.
421 Note the complication of the D_CXX_OBJC keywords. These are
422 reserved words such as 'class'. In C++, 'class' is a reserved
423 word. In Objective-C++ it is too. In Objective-C, it is a
424 reserved word too, but only if it follows an '@' sign.
426 const struct c_common_resword c_common_reswords
[] =
428 { "_Alignas", RID_ALIGNAS
, D_CONLY
},
429 { "_Alignof", RID_ALIGNOF
, D_CONLY
},
430 { "_Atomic", RID_ATOMIC
, D_CONLY
},
431 { "_Bool", RID_BOOL
, D_CONLY
},
432 { "_Complex", RID_COMPLEX
, 0 },
433 { "_Cilk_spawn", RID_CILK_SPAWN
, 0 },
434 { "_Cilk_sync", RID_CILK_SYNC
, 0 },
435 { "_Cilk_for", RID_CILK_FOR
, 0 },
436 { "_Imaginary", RID_IMAGINARY
, D_CONLY
},
437 { "_Decimal32", RID_DFLOAT32
, D_CONLY
| D_EXT
},
438 { "_Decimal64", RID_DFLOAT64
, D_CONLY
| D_EXT
},
439 { "_Decimal128", RID_DFLOAT128
, D_CONLY
| D_EXT
},
440 { "_Fract", RID_FRACT
, D_CONLY
| D_EXT
},
441 { "_Accum", RID_ACCUM
, D_CONLY
| D_EXT
},
442 { "_Sat", RID_SAT
, D_CONLY
| D_EXT
},
443 { "_Static_assert", RID_STATIC_ASSERT
, D_CONLY
},
444 { "_Noreturn", RID_NORETURN
, D_CONLY
},
445 { "_Generic", RID_GENERIC
, D_CONLY
},
446 { "_Thread_local", RID_THREAD
, D_CONLY
},
447 { "__FUNCTION__", RID_FUNCTION_NAME
, 0 },
448 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME
, 0 },
449 { "__alignof", RID_ALIGNOF
, 0 },
450 { "__alignof__", RID_ALIGNOF
, 0 },
451 { "__asm", RID_ASM
, 0 },
452 { "__asm__", RID_ASM
, 0 },
453 { "__attribute", RID_ATTRIBUTE
, 0 },
454 { "__attribute__", RID_ATTRIBUTE
, 0 },
455 { "__auto_type", RID_AUTO_TYPE
, D_CONLY
},
456 { "__bases", RID_BASES
, D_CXXONLY
},
457 { "__builtin_call_with_static_chain",
458 RID_BUILTIN_CALL_WITH_STATIC_CHAIN
, D_CONLY
},
459 { "__builtin_choose_expr", RID_CHOOSE_EXPR
, D_CONLY
},
460 { "__builtin_complex", RID_BUILTIN_COMPLEX
, D_CONLY
},
461 { "__builtin_shuffle", RID_BUILTIN_SHUFFLE
, 0 },
462 { "__builtin_offsetof", RID_OFFSETOF
, 0 },
463 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P
, D_CONLY
},
464 { "__builtin_va_arg", RID_VA_ARG
, 0 },
465 { "__complex", RID_COMPLEX
, 0 },
466 { "__complex__", RID_COMPLEX
, 0 },
467 { "__const", RID_CONST
, 0 },
468 { "__const__", RID_CONST
, 0 },
469 { "__decltype", RID_DECLTYPE
, D_CXXONLY
},
470 { "__direct_bases", RID_DIRECT_BASES
, D_CXXONLY
},
471 { "__extension__", RID_EXTENSION
, 0 },
472 { "__func__", RID_C99_FUNCTION_NAME
, 0 },
473 { "__has_nothrow_assign", RID_HAS_NOTHROW_ASSIGN
, D_CXXONLY
},
474 { "__has_nothrow_constructor", RID_HAS_NOTHROW_CONSTRUCTOR
, D_CXXONLY
},
475 { "__has_nothrow_copy", RID_HAS_NOTHROW_COPY
, D_CXXONLY
},
476 { "__has_trivial_assign", RID_HAS_TRIVIAL_ASSIGN
, D_CXXONLY
},
477 { "__has_trivial_constructor", RID_HAS_TRIVIAL_CONSTRUCTOR
, D_CXXONLY
},
478 { "__has_trivial_copy", RID_HAS_TRIVIAL_COPY
, D_CXXONLY
},
479 { "__has_trivial_destructor", RID_HAS_TRIVIAL_DESTRUCTOR
, D_CXXONLY
},
480 { "__has_virtual_destructor", RID_HAS_VIRTUAL_DESTRUCTOR
, D_CXXONLY
},
481 { "__imag", RID_IMAGPART
, 0 },
482 { "__imag__", RID_IMAGPART
, 0 },
483 { "__inline", RID_INLINE
, 0 },
484 { "__inline__", RID_INLINE
, 0 },
485 { "__is_abstract", RID_IS_ABSTRACT
, D_CXXONLY
},
486 { "__is_base_of", RID_IS_BASE_OF
, D_CXXONLY
},
487 { "__is_class", RID_IS_CLASS
, D_CXXONLY
},
488 { "__is_empty", RID_IS_EMPTY
, D_CXXONLY
},
489 { "__is_enum", RID_IS_ENUM
, D_CXXONLY
},
490 { "__is_final", RID_IS_FINAL
, D_CXXONLY
},
491 { "__is_literal_type", RID_IS_LITERAL_TYPE
, D_CXXONLY
},
492 { "__is_pod", RID_IS_POD
, D_CXXONLY
},
493 { "__is_polymorphic", RID_IS_POLYMORPHIC
, D_CXXONLY
},
494 { "__is_standard_layout", RID_IS_STD_LAYOUT
, D_CXXONLY
},
495 { "__is_trivial", RID_IS_TRIVIAL
, D_CXXONLY
},
496 { "__is_trivially_assignable", RID_IS_TRIVIALLY_ASSIGNABLE
, D_CXXONLY
},
497 { "__is_trivially_constructible", RID_IS_TRIVIALLY_CONSTRUCTIBLE
, D_CXXONLY
},
498 { "__is_trivially_copyable", RID_IS_TRIVIALLY_COPYABLE
, D_CXXONLY
},
499 { "__is_union", RID_IS_UNION
, D_CXXONLY
},
500 { "__label__", RID_LABEL
, 0 },
501 { "__null", RID_NULL
, 0 },
502 { "__real", RID_REALPART
, 0 },
503 { "__real__", RID_REALPART
, 0 },
504 { "__restrict", RID_RESTRICT
, 0 },
505 { "__restrict__", RID_RESTRICT
, 0 },
506 { "__signed", RID_SIGNED
, 0 },
507 { "__signed__", RID_SIGNED
, 0 },
508 { "__thread", RID_THREAD
, 0 },
509 { "__transaction_atomic", RID_TRANSACTION_ATOMIC
, 0 },
510 { "__transaction_relaxed", RID_TRANSACTION_RELAXED
, 0 },
511 { "__transaction_cancel", RID_TRANSACTION_CANCEL
, 0 },
512 { "__typeof", RID_TYPEOF
, 0 },
513 { "__typeof__", RID_TYPEOF
, 0 },
514 { "__underlying_type", RID_UNDERLYING_TYPE
, D_CXXONLY
},
515 { "__volatile", RID_VOLATILE
, 0 },
516 { "__volatile__", RID_VOLATILE
, 0 },
517 { "alignas", RID_ALIGNAS
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
518 { "alignof", RID_ALIGNOF
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
519 { "asm", RID_ASM
, D_ASM
},
520 { "auto", RID_AUTO
, 0 },
521 { "bool", RID_BOOL
, D_CXXONLY
| D_CXXWARN
},
522 { "break", RID_BREAK
, 0 },
523 { "case", RID_CASE
, 0 },
524 { "catch", RID_CATCH
, D_CXX_OBJC
| D_CXXWARN
},
525 { "char", RID_CHAR
, 0 },
526 { "char16_t", RID_CHAR16
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
527 { "char32_t", RID_CHAR32
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
528 { "class", RID_CLASS
, D_CXX_OBJC
| D_CXXWARN
},
529 { "const", RID_CONST
, 0 },
530 { "constexpr", RID_CONSTEXPR
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
531 { "const_cast", RID_CONSTCAST
, D_CXXONLY
| D_CXXWARN
},
532 { "continue", RID_CONTINUE
, 0 },
533 { "decltype", RID_DECLTYPE
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
534 { "default", RID_DEFAULT
, 0 },
535 { "delete", RID_DELETE
, D_CXXONLY
| D_CXXWARN
},
537 { "double", RID_DOUBLE
, 0 },
538 { "dynamic_cast", RID_DYNCAST
, D_CXXONLY
| D_CXXWARN
},
539 { "else", RID_ELSE
, 0 },
540 { "enum", RID_ENUM
, 0 },
541 { "explicit", RID_EXPLICIT
, D_CXXONLY
| D_CXXWARN
},
542 { "export", RID_EXPORT
, D_CXXONLY
| D_CXXWARN
},
543 { "extern", RID_EXTERN
, 0 },
544 { "false", RID_FALSE
, D_CXXONLY
| D_CXXWARN
},
545 { "float", RID_FLOAT
, 0 },
546 { "for", RID_FOR
, 0 },
547 { "friend", RID_FRIEND
, D_CXXONLY
| D_CXXWARN
},
548 { "goto", RID_GOTO
, 0 },
550 { "inline", RID_INLINE
, D_EXT89
},
551 { "int", RID_INT
, 0 },
552 { "long", RID_LONG
, 0 },
553 { "mutable", RID_MUTABLE
, D_CXXONLY
| D_CXXWARN
},
554 { "namespace", RID_NAMESPACE
, D_CXXONLY
| D_CXXWARN
},
555 { "new", RID_NEW
, D_CXXONLY
| D_CXXWARN
},
556 { "noexcept", RID_NOEXCEPT
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
557 { "nullptr", RID_NULLPTR
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
558 { "operator", RID_OPERATOR
, D_CXXONLY
| D_CXXWARN
},
559 { "private", RID_PRIVATE
, D_CXX_OBJC
| D_CXXWARN
},
560 { "protected", RID_PROTECTED
, D_CXX_OBJC
| D_CXXWARN
},
561 { "public", RID_PUBLIC
, D_CXX_OBJC
| D_CXXWARN
},
562 { "register", RID_REGISTER
, 0 },
563 { "reinterpret_cast", RID_REINTCAST
, D_CXXONLY
| D_CXXWARN
},
564 { "restrict", RID_RESTRICT
, D_CONLY
| D_C99
},
565 { "return", RID_RETURN
, 0 },
566 { "short", RID_SHORT
, 0 },
567 { "signed", RID_SIGNED
, 0 },
568 { "sizeof", RID_SIZEOF
, 0 },
569 { "static", RID_STATIC
, 0 },
570 { "static_assert", RID_STATIC_ASSERT
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
571 { "static_cast", RID_STATCAST
, D_CXXONLY
| D_CXXWARN
},
572 { "struct", RID_STRUCT
, 0 },
573 { "switch", RID_SWITCH
, 0 },
574 { "template", RID_TEMPLATE
, D_CXXONLY
| D_CXXWARN
},
575 { "this", RID_THIS
, D_CXXONLY
| D_CXXWARN
},
576 { "thread_local", RID_THREAD
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
577 { "throw", RID_THROW
, D_CXX_OBJC
| D_CXXWARN
},
578 { "true", RID_TRUE
, D_CXXONLY
| D_CXXWARN
},
579 { "try", RID_TRY
, D_CXX_OBJC
| D_CXXWARN
},
580 { "typedef", RID_TYPEDEF
, 0 },
581 { "typename", RID_TYPENAME
, D_CXXONLY
| D_CXXWARN
},
582 { "typeid", RID_TYPEID
, D_CXXONLY
| D_CXXWARN
},
583 { "typeof", RID_TYPEOF
, D_ASM
| D_EXT
},
584 { "union", RID_UNION
, 0 },
585 { "unsigned", RID_UNSIGNED
, 0 },
586 { "using", RID_USING
, D_CXXONLY
| D_CXXWARN
},
587 { "virtual", RID_VIRTUAL
, D_CXXONLY
| D_CXXWARN
},
588 { "void", RID_VOID
, 0 },
589 { "volatile", RID_VOLATILE
, 0 },
590 { "wchar_t", RID_WCHAR
, D_CXXONLY
},
591 { "while", RID_WHILE
, 0 },
592 /* These Objective-C keywords are recognized only immediately after
594 { "compatibility_alias", RID_AT_ALIAS
, D_OBJC
},
595 { "defs", RID_AT_DEFS
, D_OBJC
},
596 { "encode", RID_AT_ENCODE
, D_OBJC
},
597 { "end", RID_AT_END
, D_OBJC
},
598 { "implementation", RID_AT_IMPLEMENTATION
, D_OBJC
},
599 { "interface", RID_AT_INTERFACE
, D_OBJC
},
600 { "protocol", RID_AT_PROTOCOL
, D_OBJC
},
601 { "selector", RID_AT_SELECTOR
, D_OBJC
},
602 { "finally", RID_AT_FINALLY
, D_OBJC
},
603 { "synchronized", RID_AT_SYNCHRONIZED
, D_OBJC
},
604 { "optional", RID_AT_OPTIONAL
, D_OBJC
},
605 { "required", RID_AT_REQUIRED
, D_OBJC
},
606 { "property", RID_AT_PROPERTY
, D_OBJC
},
607 { "package", RID_AT_PACKAGE
, D_OBJC
},
608 { "synthesize", RID_AT_SYNTHESIZE
, D_OBJC
},
609 { "dynamic", RID_AT_DYNAMIC
, D_OBJC
},
610 /* These are recognized only in protocol-qualifier context
612 { "bycopy", RID_BYCOPY
, D_OBJC
},
613 { "byref", RID_BYREF
, D_OBJC
},
614 { "in", RID_IN
, D_OBJC
},
615 { "inout", RID_INOUT
, D_OBJC
},
616 { "oneway", RID_ONEWAY
, D_OBJC
},
617 { "out", RID_OUT
, D_OBJC
},
618 /* These are recognized inside a property attribute list */
619 { "assign", RID_ASSIGN
, D_OBJC
},
620 { "copy", RID_COPY
, D_OBJC
},
621 { "getter", RID_GETTER
, D_OBJC
},
622 { "nonatomic", RID_NONATOMIC
, D_OBJC
},
623 { "readonly", RID_READONLY
, D_OBJC
},
624 { "readwrite", RID_READWRITE
, D_OBJC
},
625 { "retain", RID_RETAIN
, D_OBJC
},
626 { "setter", RID_SETTER
, D_OBJC
},
629 const unsigned int num_c_common_reswords
=
630 sizeof c_common_reswords
/ sizeof (struct c_common_resword
);
632 /* Table of machine-independent attributes common to all C-like languages.
634 All attributes referencing arguments should be additionally processed
635 in chkp_copy_function_type_adding_bounds for correct instrumentation
636 by Pointer Bounds Checker.
637 Current list of processed common attributes: nonnull. */
638 const struct attribute_spec c_common_attribute_table
[] =
640 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
641 affects_type_identity } */
642 { "packed", 0, 0, false, false, false,
643 handle_packed_attribute
, false},
644 { "nocommon", 0, 0, true, false, false,
645 handle_nocommon_attribute
, false},
646 { "common", 0, 0, true, false, false,
647 handle_common_attribute
, false },
648 /* FIXME: logically, noreturn attributes should be listed as
649 "false, true, true" and apply to function types. But implementing this
650 would require all the places in the compiler that use TREE_THIS_VOLATILE
651 on a decl to identify non-returning functions to be located and fixed
652 to check the function type instead. */
653 { "noreturn", 0, 0, true, false, false,
654 handle_noreturn_attribute
, false },
655 { "volatile", 0, 0, true, false, false,
656 handle_noreturn_attribute
, false },
657 { "stack_protect", 0, 0, true, false, false,
658 handle_stack_protect_attribute
, false },
659 { "noinline", 0, 0, true, false, false,
660 handle_noinline_attribute
, false },
661 { "noclone", 0, 0, true, false, false,
662 handle_noclone_attribute
, false },
663 { "no_icf", 0, 0, true, false, false,
664 handle_noicf_attribute
, false },
665 { "leaf", 0, 0, true, false, false,
666 handle_leaf_attribute
, false },
667 { "always_inline", 0, 0, true, false, false,
668 handle_always_inline_attribute
, false },
669 { "gnu_inline", 0, 0, true, false, false,
670 handle_gnu_inline_attribute
, false },
671 { "artificial", 0, 0, true, false, false,
672 handle_artificial_attribute
, false },
673 { "flatten", 0, 0, true, false, false,
674 handle_flatten_attribute
, false },
675 { "used", 0, 0, true, false, false,
676 handle_used_attribute
, false },
677 { "unused", 0, 0, false, false, false,
678 handle_unused_attribute
, false },
679 { "externally_visible", 0, 0, true, false, false,
680 handle_externally_visible_attribute
, false },
681 { "no_reorder", 0, 0, true, false, false,
682 handle_no_reorder_attribute
, false },
683 /* The same comments as for noreturn attributes apply to const ones. */
684 { "const", 0, 0, true, false, false,
685 handle_const_attribute
, false },
686 { "transparent_union", 0, 0, false, false, false,
687 handle_transparent_union_attribute
, false },
688 { "constructor", 0, 1, true, false, false,
689 handle_constructor_attribute
, false },
690 { "destructor", 0, 1, true, false, false,
691 handle_destructor_attribute
, false },
692 { "mode", 1, 1, false, true, false,
693 handle_mode_attribute
, false },
694 { "section", 1, 1, true, false, false,
695 handle_section_attribute
, false },
696 { "aligned", 0, 1, false, false, false,
697 handle_aligned_attribute
, false },
698 { "weak", 0, 0, true, false, false,
699 handle_weak_attribute
, false },
700 { "noplt", 0, 0, true, false, false,
701 handle_noplt_attribute
, false },
702 { "ifunc", 1, 1, true, false, false,
703 handle_ifunc_attribute
, false },
704 { "alias", 1, 1, true, false, false,
705 handle_alias_attribute
, false },
706 { "weakref", 0, 1, true, false, false,
707 handle_weakref_attribute
, false },
708 { "no_instrument_function", 0, 0, true, false, false,
709 handle_no_instrument_function_attribute
,
711 { "malloc", 0, 0, true, false, false,
712 handle_malloc_attribute
, false },
713 { "returns_twice", 0, 0, true, false, false,
714 handle_returns_twice_attribute
, false },
715 { "no_stack_limit", 0, 0, true, false, false,
716 handle_no_limit_stack_attribute
, false },
717 { "pure", 0, 0, true, false, false,
718 handle_pure_attribute
, false },
719 { "transaction_callable", 0, 0, false, true, false,
720 handle_tm_attribute
, false },
721 { "transaction_unsafe", 0, 0, false, true, false,
722 handle_tm_attribute
, false },
723 { "transaction_safe", 0, 0, false, true, false,
724 handle_tm_attribute
, false },
725 { "transaction_may_cancel_outer", 0, 0, false, true, false,
726 handle_tm_attribute
, false },
727 /* ??? These two attributes didn't make the transition from the
728 Intel language document to the multi-vendor language document. */
729 { "transaction_pure", 0, 0, false, true, false,
730 handle_tm_attribute
, false },
731 { "transaction_wrap", 1, 1, true, false, false,
732 handle_tm_wrap_attribute
, false },
733 /* For internal use (marking of builtins) only. The name contains space
734 to prevent its usage in source code. */
735 { "no vops", 0, 0, true, false, false,
736 handle_novops_attribute
, false },
737 { "deprecated", 0, 1, false, false, false,
738 handle_deprecated_attribute
, false },
739 { "vector_size", 1, 1, false, true, false,
740 handle_vector_size_attribute
, false },
741 { "visibility", 1, 1, false, false, false,
742 handle_visibility_attribute
, false },
743 { "tls_model", 1, 1, true, false, false,
744 handle_tls_model_attribute
, false },
745 { "nonnull", 0, -1, false, true, true,
746 handle_nonnull_attribute
, false },
747 { "nothrow", 0, 0, true, false, false,
748 handle_nothrow_attribute
, false },
749 { "may_alias", 0, 0, false, true, false, NULL
, false },
750 { "cleanup", 1, 1, true, false, false,
751 handle_cleanup_attribute
, false },
752 { "warn_unused_result", 0, 0, false, true, true,
753 handle_warn_unused_result_attribute
, false },
754 { "sentinel", 0, 1, false, true, true,
755 handle_sentinel_attribute
, false },
756 /* For internal use (marking of builtins) only. The name contains space
757 to prevent its usage in source code. */
758 { "type generic", 0, 0, false, true, true,
759 handle_type_generic_attribute
, false },
760 { "alloc_size", 1, 2, false, true, true,
761 handle_alloc_size_attribute
, false },
762 { "cold", 0, 0, true, false, false,
763 handle_cold_attribute
, false },
764 { "hot", 0, 0, true, false, false,
765 handle_hot_attribute
, false },
766 { "no_address_safety_analysis",
767 0, 0, true, false, false,
768 handle_no_address_safety_analysis_attribute
,
770 { "no_sanitize_address", 0, 0, true, false, false,
771 handle_no_sanitize_address_attribute
,
773 { "no_sanitize_thread", 0, 0, true, false, false,
774 handle_no_sanitize_address_attribute
,
776 { "no_sanitize_undefined", 0, 0, true, false, false,
777 handle_no_sanitize_undefined_attribute
,
779 { "warning", 1, 1, true, false, false,
780 handle_error_attribute
, false },
781 { "error", 1, 1, true, false, false,
782 handle_error_attribute
, false },
783 { "target", 1, -1, true, false, false,
784 handle_target_attribute
, false },
785 { "optimize", 1, -1, true, false, false,
786 handle_optimize_attribute
, false },
787 /* For internal use only. The leading '*' both prevents its usage in
788 source code and signals that it may be overridden by machine tables. */
789 { "*tm regparm", 0, 0, false, true, true,
790 ignore_attribute
, false },
791 { "no_split_stack", 0, 0, true, false, false,
792 handle_no_split_stack_attribute
, false },
793 /* For internal use (marking of builtins and runtime functions) only.
794 The name contains space to prevent its usage in source code. */
795 { "fn spec", 1, 1, false, true, true,
796 handle_fnspec_attribute
, false },
797 { "warn_unused", 0, 0, false, false, false,
798 handle_warn_unused_attribute
, false },
799 { "returns_nonnull", 0, 0, false, true, true,
800 handle_returns_nonnull_attribute
, false },
801 { "omp declare simd", 0, -1, true, false, false,
802 handle_omp_declare_simd_attribute
, false },
803 { "cilk simd function", 0, -1, true, false, false,
804 handle_omp_declare_simd_attribute
, false },
805 { "omp declare target", 0, 0, true, false, false,
806 handle_omp_declare_target_attribute
, false },
807 { "alloc_align", 1, 1, false, true, true,
808 handle_alloc_align_attribute
, false },
809 { "assume_aligned", 1, 2, false, true, true,
810 handle_assume_aligned_attribute
, false },
811 { "designated_init", 0, 0, false, true, false,
812 handle_designated_init_attribute
, false },
813 { "bnd_variable_size", 0, 0, true, false, false,
814 handle_bnd_variable_size_attribute
, false },
815 { "bnd_legacy", 0, 0, true, false, false,
816 handle_bnd_legacy
, false },
817 { "bnd_instrument", 0, 0, true, false, false,
818 handle_bnd_instrument
, false },
819 { NULL
, 0, 0, false, false, false, NULL
, false }
822 /* Give the specifications for the format attributes, used by C and all
825 All attributes referencing arguments should be additionally processed
826 in chkp_copy_function_type_adding_bounds for correct instrumentation
827 by Pointer Bounds Checker.
828 Current list of processed format attributes: format, format_arg. */
829 const struct attribute_spec c_common_format_attribute_table
[] =
831 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
832 affects_type_identity } */
833 { "format", 3, 3, false, true, true,
834 handle_format_attribute
, false },
835 { "format_arg", 1, 1, false, true, true,
836 handle_format_arg_attribute
, false },
837 { NULL
, 0, 0, false, false, false, NULL
, false }
840 /* Return identifier for address space AS. */
843 c_addr_space_name (addr_space_t as
)
845 int rid
= RID_FIRST_ADDR_SPACE
+ as
;
846 gcc_assert (ridpointers
[rid
]);
847 return IDENTIFIER_POINTER (ridpointers
[rid
]);
850 /* Push current bindings for the function name VAR_DECLS. */
853 start_fname_decls (void)
856 tree saved
= NULL_TREE
;
858 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
860 tree decl
= *fname_vars
[ix
].decl
;
864 saved
= tree_cons (decl
, build_int_cst (integer_type_node
, ix
),
866 *fname_vars
[ix
].decl
= NULL_TREE
;
869 if (saved
|| saved_function_name_decls
)
870 /* Normally they'll have been NULL, so only push if we've got a
871 stack, or they are non-NULL. */
872 saved_function_name_decls
= tree_cons (saved
, NULL_TREE
,
873 saved_function_name_decls
);
876 /* Finish up the current bindings, adding them into the current function's
877 statement tree. This must be done _before_ finish_stmt_tree is called.
878 If there is no current function, we must be at file scope and no statements
879 are involved. Pop the previous bindings. */
882 finish_fname_decls (void)
885 tree stmts
= NULL_TREE
;
886 tree stack
= saved_function_name_decls
;
888 for (; stack
&& TREE_VALUE (stack
); stack
= TREE_CHAIN (stack
))
889 append_to_statement_list (TREE_VALUE (stack
), &stmts
);
893 tree
*bodyp
= &DECL_SAVED_TREE (current_function_decl
);
895 if (TREE_CODE (*bodyp
) == BIND_EXPR
)
896 bodyp
= &BIND_EXPR_BODY (*bodyp
);
898 append_to_statement_list_force (*bodyp
, &stmts
);
902 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
903 *fname_vars
[ix
].decl
= NULL_TREE
;
907 /* We had saved values, restore them. */
910 for (saved
= TREE_PURPOSE (stack
); saved
; saved
= TREE_CHAIN (saved
))
912 tree decl
= TREE_PURPOSE (saved
);
913 unsigned ix
= TREE_INT_CST_LOW (TREE_VALUE (saved
));
915 *fname_vars
[ix
].decl
= decl
;
917 stack
= TREE_CHAIN (stack
);
919 saved_function_name_decls
= stack
;
922 /* Return the text name of the current function, suitably prettified
923 by PRETTY_P. Return string must be freed by caller. */
926 fname_as_string (int pretty_p
)
928 const char *name
= "top level";
931 cpp_string cstr
= { 0, 0 }, strname
;
939 if (current_function_decl
)
940 name
= lang_hooks
.decl_printable_name (current_function_decl
, vrb
);
942 len
= strlen (name
) + 3; /* Two for '"'s. One for NULL. */
944 namep
= XNEWVEC (char, len
);
945 snprintf (namep
, len
, "\"%s\"", name
);
946 strname
.text
= (unsigned char *) namep
;
947 strname
.len
= len
- 1;
949 if (cpp_interpret_string (parse_in
, &strname
, 1, &cstr
, CPP_STRING
))
952 return (const char *) cstr
.text
;
958 /* Return the VAR_DECL for a const char array naming the current
959 function. If the VAR_DECL has not yet been created, create it
960 now. RID indicates how it should be formatted and IDENTIFIER_NODE
961 ID is its name (unfortunately C and C++ hold the RID values of
962 keywords in different places, so we can't derive RID from ID in
963 this language independent code. LOC is the location of the
967 fname_decl (location_t loc
, unsigned int rid
, tree id
)
970 tree decl
= NULL_TREE
;
972 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
973 if (fname_vars
[ix
].rid
== rid
)
976 decl
= *fname_vars
[ix
].decl
;
979 /* If a tree is built here, it would normally have the lineno of
980 the current statement. Later this tree will be moved to the
981 beginning of the function and this line number will be wrong.
982 To avoid this problem set the lineno to 0 here; that prevents
983 it from appearing in the RTL. */
985 location_t saved_location
= input_location
;
986 input_location
= UNKNOWN_LOCATION
;
988 stmts
= push_stmt_list ();
989 decl
= (*make_fname_decl
) (loc
, id
, fname_vars
[ix
].pretty
);
990 stmts
= pop_stmt_list (stmts
);
991 if (!IS_EMPTY_STMT (stmts
))
992 saved_function_name_decls
993 = tree_cons (decl
, stmts
, saved_function_name_decls
);
994 *fname_vars
[ix
].decl
= decl
;
995 input_location
= saved_location
;
997 if (!ix
&& !current_function_decl
)
998 pedwarn (loc
, 0, "%qD is not defined outside of function scope", decl
);
1003 /* Given a STRING_CST, give it a suitable array-of-chars data type. */
1006 fix_string_type (tree value
)
1008 int length
= TREE_STRING_LENGTH (value
);
1010 tree e_type
, i_type
, a_type
;
1012 /* Compute the number of elements, for the array type. */
1013 if (TREE_TYPE (value
) == char_array_type_node
|| !TREE_TYPE (value
))
1016 e_type
= char_type_node
;
1018 else if (TREE_TYPE (value
) == char16_array_type_node
)
1020 nchars
= length
/ (TYPE_PRECISION (char16_type_node
) / BITS_PER_UNIT
);
1021 e_type
= char16_type_node
;
1023 else if (TREE_TYPE (value
) == char32_array_type_node
)
1025 nchars
= length
/ (TYPE_PRECISION (char32_type_node
) / BITS_PER_UNIT
);
1026 e_type
= char32_type_node
;
1030 nchars
= length
/ (TYPE_PRECISION (wchar_type_node
) / BITS_PER_UNIT
);
1031 e_type
= wchar_type_node
;
1034 /* C89 2.2.4.1, C99 5.2.4.1 (Translation limits). The analogous
1035 limit in C++98 Annex B is very large (65536) and is not normative,
1036 so we do not diagnose it (warn_overlength_strings is forced off
1037 in c_common_post_options). */
1038 if (warn_overlength_strings
)
1040 const int nchars_max
= flag_isoc99
? 4095 : 509;
1041 const int relevant_std
= flag_isoc99
? 99 : 90;
1042 if (nchars
- 1 > nchars_max
)
1043 /* Translators: The %d after 'ISO C' will be 90 or 99. Do not
1044 separate the %d from the 'C'. 'ISO' should not be
1045 translated, but it may be moved after 'C%d' in languages
1046 where modifiers follow nouns. */
1047 pedwarn (input_location
, OPT_Woverlength_strings
,
1048 "string length %qd is greater than the length %qd "
1049 "ISO C%d compilers are required to support",
1050 nchars
- 1, nchars_max
, relevant_std
);
1053 /* Create the array type for the string constant. The ISO C++
1054 standard says that a string literal has type `const char[N]' or
1055 `const wchar_t[N]'. We use the same logic when invoked as a C
1056 front-end with -Wwrite-strings.
1057 ??? We should change the type of an expression depending on the
1058 state of a warning flag. We should just be warning -- see how
1059 this is handled in the C++ front-end for the deprecated implicit
1060 conversion from string literals to `char*' or `wchar_t*'.
1062 The C++ front end relies on TYPE_MAIN_VARIANT of a cv-qualified
1063 array type being the unqualified version of that type.
1064 Therefore, if we are constructing an array of const char, we must
1065 construct the matching unqualified array type first. The C front
1066 end does not require this, but it does no harm, so we do it
1068 i_type
= build_index_type (size_int (nchars
- 1));
1069 a_type
= build_array_type (e_type
, i_type
);
1070 if (c_dialect_cxx() || warn_write_strings
)
1071 a_type
= c_build_qualified_type (a_type
, TYPE_QUAL_CONST
);
1073 TREE_TYPE (value
) = a_type
;
1074 TREE_CONSTANT (value
) = 1;
1075 TREE_READONLY (value
) = 1;
1076 TREE_STATIC (value
) = 1;
1080 /* If DISABLE is true, stop issuing warnings. This is used when
1081 parsing code that we know will not be executed. This function may
1082 be called multiple times, and works as a stack. */
1085 c_disable_warnings (bool disable
)
1089 ++c_inhibit_evaluation_warnings
;
1090 fold_defer_overflow_warnings ();
1094 /* If ENABLE is true, reenable issuing warnings. */
1097 c_enable_warnings (bool enable
)
1101 --c_inhibit_evaluation_warnings
;
1102 fold_undefer_and_ignore_overflow_warnings ();
1106 /* Fully fold EXPR, an expression that was not folded (beyond integer
1107 constant expressions and null pointer constants) when being built
1108 up. If IN_INIT, this is in a static initializer and certain
1109 changes are made to the folding done. Clear *MAYBE_CONST if
1110 MAYBE_CONST is not NULL and EXPR is definitely not a constant
1111 expression because it contains an evaluated operator (in C99) or an
1112 operator outside of sizeof returning an integer constant (in C90)
1113 not permitted in constant expressions, or because it contains an
1114 evaluated arithmetic overflow. (*MAYBE_CONST should typically be
1115 set to true by callers before calling this function.) Return the
1116 folded expression. Function arguments have already been folded
1117 before calling this function, as have the contents of SAVE_EXPR,
1118 TARGET_EXPR, BIND_EXPR, VA_ARG_EXPR, OBJ_TYPE_REF and
1119 C_MAYBE_CONST_EXPR. */
1122 c_fully_fold (tree expr
, bool in_init
, bool *maybe_const
)
1125 tree eptype
= NULL_TREE
;
1127 bool maybe_const_itself
= true;
1128 location_t loc
= EXPR_LOCATION (expr
);
1130 /* This function is not relevant to C++ because C++ folds while
1131 parsing, and may need changes to be correct for C++ when C++
1132 stops folding while parsing. */
1133 if (c_dialect_cxx ())
1137 maybe_const
= &dummy
;
1138 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
1140 eptype
= TREE_TYPE (expr
);
1141 expr
= TREE_OPERAND (expr
, 0);
1143 ret
= c_fully_fold_internal (expr
, in_init
, maybe_const
,
1144 &maybe_const_itself
, false);
1146 ret
= fold_convert_loc (loc
, eptype
, ret
);
1147 *maybe_const
&= maybe_const_itself
;
1151 /* Internal helper for c_fully_fold. EXPR and IN_INIT are as for
1152 c_fully_fold. *MAYBE_CONST_OPERANDS is cleared because of operands
1153 not permitted, while *MAYBE_CONST_ITSELF is cleared because of
1154 arithmetic overflow (for C90, *MAYBE_CONST_OPERANDS is carried from
1155 both evaluated and unevaluated subexpressions while
1156 *MAYBE_CONST_ITSELF is carried from only evaluated
1157 subexpressions). FOR_INT_CONST indicates if EXPR is an expression
1158 with integer constant operands, and if any of the operands doesn't
1159 get folded to an integer constant, don't fold the expression itself. */
1162 c_fully_fold_internal (tree expr
, bool in_init
, bool *maybe_const_operands
,
1163 bool *maybe_const_itself
, bool for_int_const
)
1166 enum tree_code code
= TREE_CODE (expr
);
1167 enum tree_code_class kind
= TREE_CODE_CLASS (code
);
1168 location_t loc
= EXPR_LOCATION (expr
);
1169 tree op0
, op1
, op2
, op3
;
1170 tree orig_op0
, orig_op1
, orig_op2
;
1171 bool op0_const
= true, op1_const
= true, op2_const
= true;
1172 bool op0_const_self
= true, op1_const_self
= true, op2_const_self
= true;
1173 bool nowarning
= TREE_NO_WARNING (expr
);
1176 /* This function is not relevant to C++ because C++ folds while
1177 parsing, and may need changes to be correct for C++ when C++
1178 stops folding while parsing. */
1179 if (c_dialect_cxx ())
1182 /* Constants, declarations, statements, errors, SAVE_EXPRs and
1183 anything else not counted as an expression cannot usefully be
1184 folded further at this point. */
1185 if (!IS_EXPR_CODE_CLASS (kind
)
1186 || kind
== tcc_statement
1187 || code
== SAVE_EXPR
)
1190 /* Operands of variable-length expressions (function calls) have
1191 already been folded, as have __builtin_* function calls, and such
1192 expressions cannot occur in constant expressions. */
1193 if (kind
== tcc_vl_exp
)
1195 *maybe_const_operands
= false;
1200 if (code
== C_MAYBE_CONST_EXPR
)
1202 tree pre
= C_MAYBE_CONST_EXPR_PRE (expr
);
1203 tree inner
= C_MAYBE_CONST_EXPR_EXPR (expr
);
1204 if (C_MAYBE_CONST_EXPR_NON_CONST (expr
))
1205 *maybe_const_operands
= false;
1206 if (C_MAYBE_CONST_EXPR_INT_OPERANDS (expr
))
1208 *maybe_const_itself
= false;
1209 inner
= c_fully_fold_internal (inner
, in_init
, maybe_const_operands
,
1210 maybe_const_itself
, true);
1212 if (pre
&& !in_init
)
1213 ret
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr
), pre
, inner
);
1219 /* Assignment, increment, decrement, function call and comma
1220 operators, and statement expressions, cannot occur in constant
1221 expressions if evaluated / outside of sizeof. (Function calls
1222 were handled above, though VA_ARG_EXPR is treated like a function
1223 call here, and statement expressions are handled through
1224 C_MAYBE_CONST_EXPR to avoid folding inside them.) */
1228 case PREDECREMENT_EXPR
:
1229 case PREINCREMENT_EXPR
:
1230 case POSTDECREMENT_EXPR
:
1231 case POSTINCREMENT_EXPR
:
1233 *maybe_const_operands
= false;
1240 *maybe_const_operands
= false;
1248 /* Fold individual tree codes as appropriate. */
1251 case COMPOUND_LITERAL_EXPR
:
1252 /* Any non-constancy will have been marked in a containing
1253 C_MAYBE_CONST_EXPR; there is no more folding to do here. */
1257 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1258 op1
= TREE_OPERAND (expr
, 1);
1259 op2
= TREE_OPERAND (expr
, 2);
1260 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1261 maybe_const_itself
, for_int_const
);
1262 STRIP_TYPE_NOPS (op0
);
1263 if (op0
!= orig_op0
)
1264 ret
= build3 (COMPONENT_REF
, TREE_TYPE (expr
), op0
, op1
, op2
);
1267 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1268 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1273 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1274 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1275 op2
= TREE_OPERAND (expr
, 2);
1276 op3
= TREE_OPERAND (expr
, 3);
1277 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1278 maybe_const_itself
, for_int_const
);
1279 STRIP_TYPE_NOPS (op0
);
1280 op1
= c_fully_fold_internal (op1
, in_init
, maybe_const_operands
,
1281 maybe_const_itself
, for_int_const
);
1282 STRIP_TYPE_NOPS (op1
);
1283 op1
= decl_constant_value_for_optimization (op1
);
1284 if (op0
!= orig_op0
|| op1
!= orig_op1
)
1285 ret
= build4 (ARRAY_REF
, TREE_TYPE (expr
), op0
, op1
, op2
, op3
);
1288 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1289 TREE_SIDE_EFFECTS (ret
) = TREE_SIDE_EFFECTS (expr
);
1290 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1297 case PREDECREMENT_EXPR
:
1298 case PREINCREMENT_EXPR
:
1299 case POSTDECREMENT_EXPR
:
1300 case POSTINCREMENT_EXPR
:
1304 case POINTER_PLUS_EXPR
:
1305 case TRUNC_DIV_EXPR
:
1307 case FLOOR_DIV_EXPR
:
1308 case TRUNC_MOD_EXPR
:
1310 case EXACT_DIV_EXPR
:
1323 case TRUTH_AND_EXPR
:
1325 case TRUTH_XOR_EXPR
:
1326 case UNORDERED_EXPR
:
1333 /* Binary operations evaluating both arguments (increment and
1334 decrement are binary internally in GCC). */
1335 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1336 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1337 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1338 maybe_const_itself
, for_int_const
);
1339 STRIP_TYPE_NOPS (op0
);
1340 if (code
!= MODIFY_EXPR
1341 && code
!= PREDECREMENT_EXPR
1342 && code
!= PREINCREMENT_EXPR
1343 && code
!= POSTDECREMENT_EXPR
1344 && code
!= POSTINCREMENT_EXPR
)
1345 op0
= decl_constant_value_for_optimization (op0
);
1346 /* The RHS of a MODIFY_EXPR was fully folded when building that
1347 expression for the sake of conversion warnings. */
1348 if (code
!= MODIFY_EXPR
)
1349 op1
= c_fully_fold_internal (op1
, in_init
, maybe_const_operands
,
1350 maybe_const_itself
, for_int_const
);
1351 STRIP_TYPE_NOPS (op1
);
1352 op1
= decl_constant_value_for_optimization (op1
);
1354 if (for_int_const
&& (TREE_CODE (op0
) != INTEGER_CST
1355 || TREE_CODE (op1
) != INTEGER_CST
))
1358 if (op0
!= orig_op0
|| op1
!= orig_op1
|| in_init
)
1360 ? fold_build2_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
)
1361 : fold_build2_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
);
1364 if (TREE_OVERFLOW_P (ret
)
1365 && !TREE_OVERFLOW_P (op0
)
1366 && !TREE_OVERFLOW_P (op1
))
1367 overflow_warning (EXPR_LOC_OR_LOC (expr
, input_location
), ret
);
1368 if (code
== LSHIFT_EXPR
1369 && TREE_CODE (orig_op0
) != INTEGER_CST
1370 && TREE_CODE (TREE_TYPE (orig_op0
)) == INTEGER_TYPE
1371 && TREE_CODE (op0
) == INTEGER_CST
1372 && c_inhibit_evaluation_warnings
== 0
1373 && tree_int_cst_sgn (op0
) < 0)
1374 warning_at (loc
, OPT_Wshift_negative_value
,
1375 "left shift of negative value");
1376 if ((code
== LSHIFT_EXPR
|| code
== RSHIFT_EXPR
)
1377 && TREE_CODE (orig_op1
) != INTEGER_CST
1378 && TREE_CODE (op1
) == INTEGER_CST
1379 && (TREE_CODE (TREE_TYPE (orig_op0
)) == INTEGER_TYPE
1380 || TREE_CODE (TREE_TYPE (orig_op0
)) == FIXED_POINT_TYPE
)
1381 && TREE_CODE (TREE_TYPE (orig_op1
)) == INTEGER_TYPE
1382 && c_inhibit_evaluation_warnings
== 0)
1384 if (tree_int_cst_sgn (op1
) < 0)
1385 warning_at (loc
, OPT_Wshift_count_negative
,
1386 (code
== LSHIFT_EXPR
1387 ? G_("left shift count is negative")
1388 : G_("right shift count is negative")));
1389 else if (compare_tree_int (op1
,
1390 TYPE_PRECISION (TREE_TYPE (orig_op0
)))
1392 warning_at (loc
, OPT_Wshift_count_overflow
,
1393 (code
== LSHIFT_EXPR
1394 ? G_("left shift count >= width of type")
1395 : G_("right shift count >= width of type")));
1397 if (code
== LSHIFT_EXPR
1398 /* If either OP0 has been folded to INTEGER_CST... */
1399 && ((TREE_CODE (orig_op0
) != INTEGER_CST
1400 && TREE_CODE (TREE_TYPE (orig_op0
)) == INTEGER_TYPE
1401 && TREE_CODE (op0
) == INTEGER_CST
)
1402 /* ...or if OP1 has been folded to INTEGER_CST... */
1403 || (TREE_CODE (orig_op1
) != INTEGER_CST
1404 && TREE_CODE (TREE_TYPE (orig_op1
)) == INTEGER_TYPE
1405 && TREE_CODE (op1
) == INTEGER_CST
))
1406 && c_inhibit_evaluation_warnings
== 0)
1407 /* ...then maybe we can detect an overflow. */
1408 maybe_warn_shift_overflow (loc
, op0
, op1
);
1409 if ((code
== TRUNC_DIV_EXPR
1410 || code
== CEIL_DIV_EXPR
1411 || code
== FLOOR_DIV_EXPR
1412 || code
== EXACT_DIV_EXPR
1413 || code
== TRUNC_MOD_EXPR
)
1414 && TREE_CODE (orig_op1
) != INTEGER_CST
1415 && TREE_CODE (op1
) == INTEGER_CST
1416 && (TREE_CODE (TREE_TYPE (orig_op0
)) == INTEGER_TYPE
1417 || TREE_CODE (TREE_TYPE (orig_op0
)) == FIXED_POINT_TYPE
)
1418 && TREE_CODE (TREE_TYPE (orig_op1
)) == INTEGER_TYPE
)
1419 warn_for_div_by_zero (loc
, op1
);
1423 case FIX_TRUNC_EXPR
:
1426 case ADDR_SPACE_CONVERT_EXPR
:
1427 case VIEW_CONVERT_EXPR
:
1428 case NON_LVALUE_EXPR
:
1431 case TRUTH_NOT_EXPR
:
1436 /* Unary operations. */
1437 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1438 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1439 maybe_const_itself
, for_int_const
);
1440 STRIP_TYPE_NOPS (op0
);
1441 if (code
!= ADDR_EXPR
&& code
!= REALPART_EXPR
&& code
!= IMAGPART_EXPR
)
1442 op0
= decl_constant_value_for_optimization (op0
);
1444 if (for_int_const
&& TREE_CODE (op0
) != INTEGER_CST
)
1447 /* ??? Cope with user tricks that amount to offsetof. The middle-end is
1448 not prepared to deal with them if they occur in initializers. */
1450 && code
== ADDR_EXPR
1451 && (op1
= get_base_address (op0
)) != NULL_TREE
1452 && INDIRECT_REF_P (op1
)
1453 && TREE_CONSTANT (TREE_OPERAND (op1
, 0)))
1454 ret
= fold_convert_loc (loc
, TREE_TYPE (expr
), fold_offsetof_1 (op0
));
1455 else if (op0
!= orig_op0
|| in_init
)
1457 ? fold_build1_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
)
1458 : fold_build1_loc (loc
, code
, TREE_TYPE (expr
), op0
);
1461 if (code
== INDIRECT_REF
1463 && INDIRECT_REF_P (ret
))
1465 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1466 TREE_SIDE_EFFECTS (ret
) = TREE_SIDE_EFFECTS (expr
);
1467 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1471 case FIX_TRUNC_EXPR
:
1474 /* Don't warn about explicit conversions. We will already
1475 have warned about suspect implicit conversions. */
1479 if (TREE_OVERFLOW_P (ret
) && !TREE_OVERFLOW_P (op0
))
1480 overflow_warning (EXPR_LOCATION (expr
), ret
);
1485 case TRUTH_ANDIF_EXPR
:
1486 case TRUTH_ORIF_EXPR
:
1487 /* Binary operations not necessarily evaluating both
1489 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1490 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1491 op0
= c_fully_fold_internal (op0
, in_init
, &op0_const
, &op0_const_self
,
1493 STRIP_TYPE_NOPS (op0
);
1495 unused_p
= (op0
== (code
== TRUTH_ANDIF_EXPR
1496 ? truthvalue_false_node
1497 : truthvalue_true_node
));
1498 c_disable_warnings (unused_p
);
1499 op1
= c_fully_fold_internal (op1
, in_init
, &op1_const
, &op1_const_self
,
1501 STRIP_TYPE_NOPS (op1
);
1502 c_enable_warnings (unused_p
);
1505 && (TREE_CODE (op0
) != INTEGER_CST
1506 /* Require OP1 be an INTEGER_CST only if it's evaluated. */
1507 || (!unused_p
&& TREE_CODE (op1
) != INTEGER_CST
)))
1510 if (op0
!= orig_op0
|| op1
!= orig_op1
|| in_init
)
1512 ? fold_build2_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
)
1513 : fold_build2_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
);
1516 *maybe_const_operands
&= op0_const
;
1517 *maybe_const_itself
&= op0_const_self
;
1521 && (code
== TRUTH_ANDIF_EXPR
1522 ? op0
== truthvalue_false_node
1523 : op0
== truthvalue_true_node
)))
1524 *maybe_const_operands
&= op1_const
;
1527 && (code
== TRUTH_ANDIF_EXPR
1528 ? op0
== truthvalue_false_node
1529 : op0
== truthvalue_true_node
)))
1530 *maybe_const_itself
&= op1_const_self
;
1534 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1535 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1536 orig_op2
= op2
= TREE_OPERAND (expr
, 2);
1537 op0
= c_fully_fold_internal (op0
, in_init
, &op0_const
, &op0_const_self
,
1540 STRIP_TYPE_NOPS (op0
);
1541 c_disable_warnings (op0
== truthvalue_false_node
);
1542 op1
= c_fully_fold_internal (op1
, in_init
, &op1_const
, &op1_const_self
,
1544 STRIP_TYPE_NOPS (op1
);
1545 c_enable_warnings (op0
== truthvalue_false_node
);
1547 c_disable_warnings (op0
== truthvalue_true_node
);
1548 op2
= c_fully_fold_internal (op2
, in_init
, &op2_const
, &op2_const_self
,
1550 STRIP_TYPE_NOPS (op2
);
1551 c_enable_warnings (op0
== truthvalue_true_node
);
1554 && (TREE_CODE (op0
) != INTEGER_CST
1555 /* Only the evaluated operand must be an INTEGER_CST. */
1556 || (op0
== truthvalue_true_node
1557 ? TREE_CODE (op1
) != INTEGER_CST
1558 : TREE_CODE (op2
) != INTEGER_CST
)))
1561 if (op0
!= orig_op0
|| op1
!= orig_op1
|| op2
!= orig_op2
)
1562 ret
= fold_build3_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
, op2
);
1565 *maybe_const_operands
&= op0_const
;
1566 *maybe_const_itself
&= op0_const_self
;
1570 && op0
== truthvalue_false_node
))
1571 *maybe_const_operands
&= op1_const
;
1574 && op0
== truthvalue_false_node
))
1575 *maybe_const_itself
&= op1_const_self
;
1579 && op0
== truthvalue_true_node
))
1580 *maybe_const_operands
&= op2_const
;
1583 && op0
== truthvalue_true_node
))
1584 *maybe_const_itself
&= op2_const_self
;
1587 case EXCESS_PRECISION_EXPR
:
1588 /* Each case where an operand with excess precision may be
1589 encountered must remove the EXCESS_PRECISION_EXPR around
1590 inner operands and possibly put one around the whole
1591 expression or possibly convert to the semantic type (which
1592 c_fully_fold does); we cannot tell at this stage which is
1593 appropriate in any particular case. */
1597 /* Various codes may appear through folding built-in functions
1598 and their arguments. */
1603 /* Some folding may introduce NON_LVALUE_EXPRs; all lvalue checks
1604 have been done by this point, so remove them again. */
1605 nowarning
|= TREE_NO_WARNING (ret
);
1606 STRIP_TYPE_NOPS (ret
);
1607 if (nowarning
&& !TREE_NO_WARNING (ret
))
1609 if (!CAN_HAVE_LOCATION_P (ret
))
1610 ret
= build1 (NOP_EXPR
, TREE_TYPE (ret
), ret
);
1611 TREE_NO_WARNING (ret
) = 1;
1614 protected_set_expr_location (ret
, loc
);
1618 /* If not optimizing, EXP is not a VAR_DECL, or EXP has array type,
1619 return EXP. Otherwise, return either EXP or its known constant
1620 value (if it has one), but return EXP if EXP has mode BLKmode. ???
1621 Is the BLKmode test appropriate? */
1624 decl_constant_value_for_optimization (tree exp
)
1628 /* This function is only used by C, for c_fully_fold and other
1629 optimization, and may not be correct for C++. */
1630 if (c_dialect_cxx ())
1635 || TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
1636 || DECL_MODE (exp
) == BLKmode
)
1639 ret
= decl_constant_value (exp
);
1640 /* Avoid unwanted tree sharing between the initializer and current
1641 function's body where the tree can be modified e.g. by the
1643 if (ret
!= exp
&& TREE_STATIC (exp
))
1644 ret
= unshare_expr (ret
);
1648 /* Print a warning if a constant expression had overflow in folding.
1649 Invoke this function on every expression that the language
1650 requires to be a constant expression.
1651 Note the ANSI C standard says it is erroneous for a
1652 constant expression to overflow. */
1655 constant_expression_warning (tree value
)
1657 if (warn_overflow
&& pedantic
1658 && (TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1659 || TREE_CODE (value
) == FIXED_CST
1660 || TREE_CODE (value
) == VECTOR_CST
1661 || TREE_CODE (value
) == COMPLEX_CST
)
1662 && TREE_OVERFLOW (value
))
1663 pedwarn (input_location
, OPT_Woverflow
, "overflow in constant expression");
1666 /* The same as above but print an unconditional error. */
1668 constant_expression_error (tree value
)
1670 if ((TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1671 || TREE_CODE (value
) == FIXED_CST
1672 || TREE_CODE (value
) == VECTOR_CST
1673 || TREE_CODE (value
) == COMPLEX_CST
)
1674 && TREE_OVERFLOW (value
))
1675 error ("overflow in constant expression");
1678 /* Print a warning if an expression had overflow in folding and its
1681 Invoke this function on every expression that
1682 (1) appears in the source code, and
1683 (2) is a constant expression that overflowed, and
1684 (3) is not already checked by convert_and_check;
1685 however, do not invoke this function on operands of explicit casts
1686 or when the expression is the result of an operator and any operand
1687 already overflowed. */
1690 overflow_warning (location_t loc
, tree value
)
1692 if (c_inhibit_evaluation_warnings
!= 0)
1695 switch (TREE_CODE (value
))
1698 warning_at (loc
, OPT_Woverflow
, "integer overflow in expression");
1702 warning_at (loc
, OPT_Woverflow
,
1703 "floating point overflow in expression");
1707 warning_at (loc
, OPT_Woverflow
, "fixed-point overflow in expression");
1711 warning_at (loc
, OPT_Woverflow
, "vector overflow in expression");
1715 if (TREE_CODE (TREE_REALPART (value
)) == INTEGER_CST
)
1716 warning_at (loc
, OPT_Woverflow
,
1717 "complex integer overflow in expression");
1718 else if (TREE_CODE (TREE_REALPART (value
)) == REAL_CST
)
1719 warning_at (loc
, OPT_Woverflow
,
1720 "complex floating point overflow in expression");
1728 /* Warn about uses of logical || / && operator in a context where it
1729 is likely that the bitwise equivalent was intended by the
1730 programmer. We have seen an expression in which CODE is a binary
1731 operator used to combine expressions OP_LEFT and OP_RIGHT, which before folding
1732 had CODE_LEFT and CODE_RIGHT, into an expression of type TYPE. */
1734 warn_logical_operator (location_t location
, enum tree_code code
, tree type
,
1735 enum tree_code code_left
, tree op_left
,
1736 enum tree_code
ARG_UNUSED (code_right
), tree op_right
)
1738 int or_op
= (code
== TRUTH_ORIF_EXPR
|| code
== TRUTH_OR_EXPR
);
1739 int in0_p
, in1_p
, in_p
;
1740 tree low0
, low1
, low
, high0
, high1
, high
, lhs
, rhs
, tem
;
1741 bool strict_overflow_p
= false;
1743 if (code
!= TRUTH_ANDIF_EXPR
1744 && code
!= TRUTH_AND_EXPR
1745 && code
!= TRUTH_ORIF_EXPR
1746 && code
!= TRUTH_OR_EXPR
)
1749 /* We don't want to warn if either operand comes from a macro
1750 expansion. ??? This doesn't work with e.g. NEGATE_EXPR yet;
1752 if (from_macro_expansion_at (EXPR_LOCATION (op_left
))
1753 || from_macro_expansion_at (EXPR_LOCATION (op_right
)))
1756 /* Warn if &&/|| are being used in a context where it is
1757 likely that the bitwise equivalent was intended by the
1758 programmer. That is, an expression such as op && MASK
1759 where op should not be any boolean expression, nor a
1760 constant, and mask seems to be a non-boolean integer constant. */
1761 if (!truth_value_p (code_left
)
1762 && INTEGRAL_TYPE_P (TREE_TYPE (op_left
))
1763 && !CONSTANT_CLASS_P (op_left
)
1764 && !TREE_NO_WARNING (op_left
)
1765 && TREE_CODE (op_right
) == INTEGER_CST
1766 && !integer_zerop (op_right
)
1767 && !integer_onep (op_right
))
1770 warning_at (location
, OPT_Wlogical_op
, "logical %<or%>"
1771 " applied to non-boolean constant");
1773 warning_at (location
, OPT_Wlogical_op
, "logical %<and%>"
1774 " applied to non-boolean constant");
1775 TREE_NO_WARNING (op_left
) = true;
1779 /* We do not warn for constants because they are typical of macro
1780 expansions that test for features. */
1781 if (CONSTANT_CLASS_P (op_left
) || CONSTANT_CLASS_P (op_right
))
1784 /* This warning only makes sense with logical operands. */
1785 if (!(truth_value_p (TREE_CODE (op_left
))
1786 || INTEGRAL_TYPE_P (TREE_TYPE (op_left
)))
1787 || !(truth_value_p (TREE_CODE (op_right
))
1788 || INTEGRAL_TYPE_P (TREE_TYPE (op_right
))))
1791 /* The range computations only work with scalars. */
1792 if (VECTOR_TYPE_P (TREE_TYPE (op_left
))
1793 || VECTOR_TYPE_P (TREE_TYPE (op_right
)))
1796 /* We first test whether either side separately is trivially true
1797 (with OR) or trivially false (with AND). If so, do not warn.
1798 This is a common idiom for testing ranges of data types in
1800 lhs
= make_range (op_left
, &in0_p
, &low0
, &high0
, &strict_overflow_p
);
1803 if (TREE_CODE (lhs
) == C_MAYBE_CONST_EXPR
)
1804 lhs
= C_MAYBE_CONST_EXPR_EXPR (lhs
);
1806 /* If this is an OR operation, invert both sides; now, the result
1807 should be always false to get a warning. */
1811 tem
= build_range_check (UNKNOWN_LOCATION
, type
, lhs
, in0_p
, low0
, high0
);
1812 if (tem
&& integer_zerop (tem
))
1815 rhs
= make_range (op_right
, &in1_p
, &low1
, &high1
, &strict_overflow_p
);
1818 if (TREE_CODE (rhs
) == C_MAYBE_CONST_EXPR
)
1819 rhs
= C_MAYBE_CONST_EXPR_EXPR (rhs
);
1821 /* If this is an OR operation, invert both sides; now, the result
1822 should be always false to get a warning. */
1826 tem
= build_range_check (UNKNOWN_LOCATION
, type
, rhs
, in1_p
, low1
, high1
);
1827 if (tem
&& integer_zerop (tem
))
1830 /* If both expressions have the same operand, if we can merge the
1832 if (operand_equal_p (lhs
, rhs
, 0)
1833 && merge_ranges (&in_p
, &low
, &high
, in0_p
, low0
, high0
,
1834 in1_p
, low1
, high1
))
1836 tem
= build_range_check (UNKNOWN_LOCATION
, type
, lhs
, in_p
, low
, high
);
1837 /* ... and if the range test is always false, then warn. */
1838 if (tem
&& integer_zerop (tem
))
1841 warning_at (location
, OPT_Wlogical_op
,
1842 "logical %<or%> of collectively exhaustive tests is "
1845 warning_at (location
, OPT_Wlogical_op
,
1846 "logical %<and%> of mutually exclusive tests is "
1849 /* Or warn if the operands have exactly the same range, e.g.
1851 else if (tree_int_cst_equal (low0
, low1
)
1852 && tree_int_cst_equal (high0
, high1
))
1855 warning_at (location
, OPT_Wlogical_op
,
1856 "logical %<or%> of equal expressions");
1858 warning_at (location
, OPT_Wlogical_op
,
1859 "logical %<and%> of equal expressions");
1864 /* Helper function for warn_tautological_cmp. Look for ARRAY_REFs
1865 with constant indices. */
1868 find_array_ref_with_const_idx_r (tree
*expr_p
, int *walk_subtrees
, void *data
)
1870 tree expr
= *expr_p
;
1872 if ((TREE_CODE (expr
) == ARRAY_REF
1873 || TREE_CODE (expr
) == ARRAY_RANGE_REF
)
1874 && TREE_CODE (TREE_OPERAND (expr
, 1)) == INTEGER_CST
)
1876 *(bool *) data
= true;
1883 /* Warn if a self-comparison always evaluates to true or false. LOC
1884 is the location of the comparison with code CODE, LHS and RHS are
1885 operands of the comparison. */
1888 warn_tautological_cmp (location_t loc
, enum tree_code code
, tree lhs
, tree rhs
)
1890 if (TREE_CODE_CLASS (code
) != tcc_comparison
)
1893 /* We do not warn for constants because they are typical of macro
1894 expansions that test for features, sizeof, and similar. */
1895 if (CONSTANT_CLASS_P (lhs
) || CONSTANT_CLASS_P (rhs
))
1898 /* Don't warn for e.g.
1901 if (n == (long) n) ...
1903 if ((CONVERT_EXPR_P (lhs
) || TREE_CODE (lhs
) == NON_LVALUE_EXPR
)
1904 || (CONVERT_EXPR_P (rhs
) || TREE_CODE (rhs
) == NON_LVALUE_EXPR
))
1907 if (operand_equal_p (lhs
, rhs
, 0))
1909 /* Don't warn about array references with constant indices;
1910 these are likely to come from a macro. */
1912 walk_tree_without_duplicates (&lhs
, find_array_ref_with_const_idx_r
,
1916 const bool always_true
= (code
== EQ_EXPR
|| code
== LE_EXPR
1917 || code
== GE_EXPR
|| code
== UNLE_EXPR
1918 || code
== UNGE_EXPR
|| code
== UNEQ_EXPR
);
1920 warning_at (loc
, OPT_Wtautological_compare
,
1921 "self-comparison always evaluates to true");
1923 warning_at (loc
, OPT_Wtautological_compare
,
1924 "self-comparison always evaluates to false");
1928 /* Warn about logical not used on the left hand side operand of a comparison.
1929 This function assumes that the LHS is inside of TRUTH_NOT_EXPR.
1930 Do not warn if RHS is of a boolean type. */
1933 warn_logical_not_parentheses (location_t location
, enum tree_code code
,
1936 if (TREE_CODE_CLASS (code
) != tcc_comparison
1937 || TREE_TYPE (rhs
) == NULL_TREE
1938 || TREE_CODE (TREE_TYPE (rhs
)) == BOOLEAN_TYPE
)
1941 /* Don't warn for !x == 0 or !y != 0, those are equivalent to
1942 !(x == 0) or !(y != 0). */
1943 if ((code
== EQ_EXPR
|| code
== NE_EXPR
)
1944 && integer_zerop (rhs
))
1947 warning_at (location
, OPT_Wlogical_not_parentheses
,
1948 "logical not is only applied to the left hand side of "
1952 /* Warn if EXP contains any computations whose results are not used.
1953 Return true if a warning is printed; false otherwise. LOCUS is the
1954 (potential) location of the expression. */
1957 warn_if_unused_value (const_tree exp
, location_t locus
)
1960 if (TREE_USED (exp
) || TREE_NO_WARNING (exp
))
1963 /* Don't warn about void constructs. This includes casting to void,
1964 void function calls, and statement expressions with a final cast
1966 if (VOID_TYPE_P (TREE_TYPE (exp
)))
1969 if (EXPR_HAS_LOCATION (exp
))
1970 locus
= EXPR_LOCATION (exp
);
1972 switch (TREE_CODE (exp
))
1974 case PREINCREMENT_EXPR
:
1975 case POSTINCREMENT_EXPR
:
1976 case PREDECREMENT_EXPR
:
1977 case POSTDECREMENT_EXPR
:
1982 case TRY_CATCH_EXPR
:
1983 case WITH_CLEANUP_EXPR
:
1989 /* For a binding, warn if no side effect within it. */
1990 exp
= BIND_EXPR_BODY (exp
);
1994 case NON_LVALUE_EXPR
:
1996 exp
= TREE_OPERAND (exp
, 0);
1999 case TRUTH_ORIF_EXPR
:
2000 case TRUTH_ANDIF_EXPR
:
2001 /* In && or ||, warn if 2nd operand has no side effect. */
2002 exp
= TREE_OPERAND (exp
, 1);
2006 if (warn_if_unused_value (TREE_OPERAND (exp
, 0), locus
))
2008 /* Let people do `(foo (), 0)' without a warning. */
2009 if (TREE_CONSTANT (TREE_OPERAND (exp
, 1)))
2011 exp
= TREE_OPERAND (exp
, 1);
2015 /* If this is an expression with side effects, don't warn; this
2016 case commonly appears in macro expansions. */
2017 if (TREE_SIDE_EFFECTS (exp
))
2022 /* Don't warn about automatic dereferencing of references, since
2023 the user cannot control it. */
2024 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == REFERENCE_TYPE
)
2026 exp
= TREE_OPERAND (exp
, 0);
2032 /* Referencing a volatile value is a side effect, so don't warn. */
2033 if ((DECL_P (exp
) || REFERENCE_CLASS_P (exp
))
2034 && TREE_THIS_VOLATILE (exp
))
2037 /* If this is an expression which has no operands, there is no value
2038 to be unused. There are no such language-independent codes,
2039 but front ends may define such. */
2040 if (EXPRESSION_CLASS_P (exp
) && TREE_OPERAND_LENGTH (exp
) == 0)
2044 return warning_at (locus
, OPT_Wunused_value
, "value computed is not used");
2049 /* Print a warning about casts that might indicate violation
2050 of strict aliasing rules if -Wstrict-aliasing is used and
2051 strict aliasing mode is in effect. OTYPE is the original
2052 TREE_TYPE of EXPR, and TYPE the type we're casting to. */
2055 strict_aliasing_warning (tree otype
, tree type
, tree expr
)
2057 /* Strip pointer conversion chains and get to the correct original type. */
2059 otype
= TREE_TYPE (expr
);
2061 if (!(flag_strict_aliasing
2062 && POINTER_TYPE_P (type
)
2063 && POINTER_TYPE_P (otype
)
2064 && !VOID_TYPE_P (TREE_TYPE (type
)))
2065 /* If the type we are casting to is a ref-all pointer
2066 dereferencing it is always valid. */
2067 || TYPE_REF_CAN_ALIAS_ALL (type
))
2070 if ((warn_strict_aliasing
> 1) && TREE_CODE (expr
) == ADDR_EXPR
2071 && (DECL_P (TREE_OPERAND (expr
, 0))
2072 || handled_component_p (TREE_OPERAND (expr
, 0))))
2074 /* Casting the address of an object to non void pointer. Warn
2075 if the cast breaks type based aliasing. */
2076 if (!COMPLETE_TYPE_P (TREE_TYPE (type
)) && warn_strict_aliasing
== 2)
2078 warning (OPT_Wstrict_aliasing
, "type-punning to incomplete type "
2079 "might break strict-aliasing rules");
2084 /* warn_strict_aliasing >= 3. This includes the default (3).
2085 Only warn if the cast is dereferenced immediately. */
2086 alias_set_type set1
=
2087 get_alias_set (TREE_TYPE (TREE_OPERAND (expr
, 0)));
2088 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
2090 if (set1
!= set2
&& set2
!= 0
2091 && (set1
== 0 || !alias_sets_conflict_p (set1
, set2
)))
2093 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
2094 "pointer will break strict-aliasing rules");
2097 else if (warn_strict_aliasing
== 2
2098 && !alias_sets_must_conflict_p (set1
, set2
))
2100 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
2101 "pointer might break strict-aliasing rules");
2107 if ((warn_strict_aliasing
== 1) && !VOID_TYPE_P (TREE_TYPE (otype
)))
2109 /* At this level, warn for any conversions, even if an address is
2110 not taken in the same statement. This will likely produce many
2111 false positives, but could be useful to pinpoint problems that
2112 are not revealed at higher levels. */
2113 alias_set_type set1
= get_alias_set (TREE_TYPE (otype
));
2114 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
2115 if (!COMPLETE_TYPE_P (type
)
2116 || !alias_sets_must_conflict_p (set1
, set2
))
2118 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
2119 "pointer might break strict-aliasing rules");
2127 /* Warn about memset (&a, 0, sizeof (&a)); and similar mistakes with
2128 sizeof as last operand of certain builtins. */
2131 sizeof_pointer_memaccess_warning (location_t
*sizeof_arg_loc
, tree callee
,
2132 vec
<tree
, va_gc
> *params
, tree
*sizeof_arg
,
2133 bool (*comp_types
) (tree
, tree
))
2135 tree type
, dest
= NULL_TREE
, src
= NULL_TREE
, tem
;
2136 bool strop
= false, cmp
= false;
2137 unsigned int idx
= ~0;
2140 if (TREE_CODE (callee
) != FUNCTION_DECL
2141 || DECL_BUILT_IN_CLASS (callee
) != BUILT_IN_NORMAL
2142 || vec_safe_length (params
) <= 1)
2145 switch (DECL_FUNCTION_CODE (callee
))
2147 case BUILT_IN_STRNCMP
:
2148 case BUILT_IN_STRNCASECMP
:
2151 case BUILT_IN_STRNCPY
:
2152 case BUILT_IN_STRNCPY_CHK
:
2153 case BUILT_IN_STRNCAT
:
2154 case BUILT_IN_STRNCAT_CHK
:
2155 case BUILT_IN_STPNCPY
:
2156 case BUILT_IN_STPNCPY_CHK
:
2159 case BUILT_IN_MEMCPY
:
2160 case BUILT_IN_MEMCPY_CHK
:
2161 case BUILT_IN_MEMMOVE
:
2162 case BUILT_IN_MEMMOVE_CHK
:
2163 if (params
->length () < 3)
2166 dest
= (*params
)[0];
2169 case BUILT_IN_BCOPY
:
2170 if (params
->length () < 3)
2173 dest
= (*params
)[1];
2176 case BUILT_IN_MEMCMP
:
2178 if (params
->length () < 3)
2181 dest
= (*params
)[0];
2185 case BUILT_IN_MEMSET
:
2186 case BUILT_IN_MEMSET_CHK
:
2187 if (params
->length () < 3)
2189 dest
= (*params
)[0];
2192 case BUILT_IN_BZERO
:
2193 dest
= (*params
)[0];
2196 case BUILT_IN_STRNDUP
:
2201 case BUILT_IN_MEMCHR
:
2202 if (params
->length () < 3)
2207 case BUILT_IN_SNPRINTF
:
2208 case BUILT_IN_SNPRINTF_CHK
:
2209 case BUILT_IN_VSNPRINTF
:
2210 case BUILT_IN_VSNPRINTF_CHK
:
2211 dest
= (*params
)[0];
2222 if (sizeof_arg
[idx
] == NULL
|| sizeof_arg
[idx
] == error_mark_node
)
2225 type
= TYPE_P (sizeof_arg
[idx
])
2226 ? sizeof_arg
[idx
] : TREE_TYPE (sizeof_arg
[idx
]);
2227 if (!POINTER_TYPE_P (type
))
2231 && (tem
= tree_strip_nop_conversions (dest
))
2232 && POINTER_TYPE_P (TREE_TYPE (tem
))
2233 && comp_types (TREE_TYPE (TREE_TYPE (tem
)), type
))
2237 && (tem
= tree_strip_nop_conversions (src
))
2238 && POINTER_TYPE_P (TREE_TYPE (tem
))
2239 && comp_types (TREE_TYPE (TREE_TYPE (tem
)), type
))
2242 loc
= sizeof_arg_loc
[idx
];
2246 if (!TYPE_P (sizeof_arg
[idx
])
2247 && operand_equal_p (dest
, sizeof_arg
[idx
], 0)
2248 && comp_types (TREE_TYPE (dest
), type
))
2250 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2251 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2252 "argument to %<sizeof%> in %qD call is the same "
2253 "expression as the destination; did you mean to "
2254 "remove the addressof?", callee
);
2255 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2256 == TYPE_PRECISION (char_type_node
))
2258 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2259 "argument to %<sizeof%> in %qD call is the same "
2260 "expression as the destination; did you mean to "
2261 "provide an explicit length?", callee
);
2263 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2264 "argument to %<sizeof%> in %qD call is the same "
2265 "expression as the destination; did you mean to "
2266 "dereference it?", callee
);
2270 if (POINTER_TYPE_P (TREE_TYPE (dest
))
2272 && comp_types (TREE_TYPE (dest
), type
)
2273 && !VOID_TYPE_P (TREE_TYPE (type
)))
2275 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2276 "argument to %<sizeof%> in %qD call is the same "
2277 "pointer type %qT as the destination; expected %qT "
2278 "or an explicit length", callee
, TREE_TYPE (dest
),
2279 TREE_TYPE (TREE_TYPE (dest
)));
2286 if (!TYPE_P (sizeof_arg
[idx
])
2287 && operand_equal_p (src
, sizeof_arg
[idx
], 0)
2288 && comp_types (TREE_TYPE (src
), type
))
2290 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2291 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2292 "argument to %<sizeof%> in %qD call is the same "
2293 "expression as the source; did you mean to "
2294 "remove the addressof?", callee
);
2295 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2296 == TYPE_PRECISION (char_type_node
))
2298 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2299 "argument to %<sizeof%> in %qD call is the same "
2300 "expression as the source; did you mean to "
2301 "provide an explicit length?", callee
);
2303 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2304 "argument to %<sizeof%> in %qD call is the same "
2305 "expression as the source; did you mean to "
2306 "dereference it?", callee
);
2310 if (POINTER_TYPE_P (TREE_TYPE (src
))
2312 && comp_types (TREE_TYPE (src
), type
)
2313 && !VOID_TYPE_P (TREE_TYPE (type
)))
2315 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2316 "argument to %<sizeof%> in %qD call is the same "
2317 "pointer type %qT as the source; expected %qT "
2318 "or an explicit length", callee
, TREE_TYPE (src
),
2319 TREE_TYPE (TREE_TYPE (src
)));
2326 if (!TYPE_P (sizeof_arg
[idx
])
2327 && operand_equal_p (dest
, sizeof_arg
[idx
], 0)
2328 && comp_types (TREE_TYPE (dest
), type
))
2330 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2331 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2332 "argument to %<sizeof%> in %qD call is the same "
2333 "expression as the first source; did you mean to "
2334 "remove the addressof?", callee
);
2335 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2336 == TYPE_PRECISION (char_type_node
))
2338 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2339 "argument to %<sizeof%> in %qD call is the same "
2340 "expression as the first source; did you mean to "
2341 "provide an explicit length?", callee
);
2343 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2344 "argument to %<sizeof%> in %qD call is the same "
2345 "expression as the first source; did you mean to "
2346 "dereference it?", callee
);
2350 if (POINTER_TYPE_P (TREE_TYPE (dest
))
2352 && comp_types (TREE_TYPE (dest
), type
)
2353 && !VOID_TYPE_P (TREE_TYPE (type
)))
2355 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2356 "argument to %<sizeof%> in %qD call is the same "
2357 "pointer type %qT as the first source; expected %qT "
2358 "or an explicit length", callee
, TREE_TYPE (dest
),
2359 TREE_TYPE (TREE_TYPE (dest
)));
2366 if (!TYPE_P (sizeof_arg
[idx
])
2367 && operand_equal_p (src
, sizeof_arg
[idx
], 0)
2368 && comp_types (TREE_TYPE (src
), type
))
2370 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2371 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2372 "argument to %<sizeof%> in %qD call is the same "
2373 "expression as the second source; did you mean to "
2374 "remove the addressof?", callee
);
2375 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2376 == TYPE_PRECISION (char_type_node
))
2378 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2379 "argument to %<sizeof%> in %qD call is the same "
2380 "expression as the second source; did you mean to "
2381 "provide an explicit length?", callee
);
2383 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2384 "argument to %<sizeof%> in %qD call is the same "
2385 "expression as the second source; did you mean to "
2386 "dereference it?", callee
);
2390 if (POINTER_TYPE_P (TREE_TYPE (src
))
2392 && comp_types (TREE_TYPE (src
), type
)
2393 && !VOID_TYPE_P (TREE_TYPE (type
)))
2395 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2396 "argument to %<sizeof%> in %qD call is the same "
2397 "pointer type %qT as the second source; expected %qT "
2398 "or an explicit length", callee
, TREE_TYPE (src
),
2399 TREE_TYPE (TREE_TYPE (src
)));
2406 /* Warn for unlikely, improbable, or stupid DECL declarations
2410 check_main_parameter_types (tree decl
)
2412 function_args_iterator iter
;
2416 FOREACH_FUNCTION_ARGS (TREE_TYPE (decl
), type
, iter
)
2418 /* XXX void_type_node belies the abstraction. */
2419 if (type
== void_type_node
|| type
== error_mark_node
)
2423 if (TYPE_ATOMIC (t
))
2424 pedwarn (input_location
, OPT_Wmain
,
2425 "%<_Atomic%>-qualified parameter type %qT of %q+D",
2427 while (POINTER_TYPE_P (t
))
2430 if (TYPE_ATOMIC (t
))
2431 pedwarn (input_location
, OPT_Wmain
,
2432 "%<_Atomic%>-qualified parameter type %qT of %q+D",
2440 if (TYPE_MAIN_VARIANT (type
) != integer_type_node
)
2441 pedwarn (input_location
, OPT_Wmain
,
2442 "first argument of %q+D should be %<int%>", decl
);
2446 if (TREE_CODE (type
) != POINTER_TYPE
2447 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
2448 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
2450 pedwarn (input_location
, OPT_Wmain
,
2451 "second argument of %q+D should be %<char **%>", decl
);
2455 if (TREE_CODE (type
) != POINTER_TYPE
2456 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
2457 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
2459 pedwarn (input_location
, OPT_Wmain
,
2460 "third argument of %q+D should probably be "
2461 "%<char **%>", decl
);
2466 /* It is intentional that this message does not mention the third
2467 argument because it's only mentioned in an appendix of the
2469 if (argct
> 0 && (argct
< 2 || argct
> 3))
2470 pedwarn (input_location
, OPT_Wmain
,
2471 "%q+D takes only zero or two arguments", decl
);
2473 if (stdarg_p (TREE_TYPE (decl
)))
2474 pedwarn (input_location
, OPT_Wmain
,
2475 "%q+D declared as variadic function", decl
);
2478 /* vector_targets_convertible_p is used for vector pointer types. The
2479 callers perform various checks that the qualifiers are satisfactory,
2480 while OTOH vector_targets_convertible_p ignores the number of elements
2481 in the vectors. That's fine with vector pointers as we can consider,
2482 say, a vector of 8 elements as two consecutive vectors of 4 elements,
2483 and that does not require and conversion of the pointer values.
2484 In contrast, vector_types_convertible_p and
2485 vector_types_compatible_elements_p are used for vector value types. */
2486 /* True if pointers to distinct types T1 and T2 can be converted to
2487 each other without an explicit cast. Only returns true for opaque
2490 vector_targets_convertible_p (const_tree t1
, const_tree t2
)
2492 if (VECTOR_TYPE_P (t1
) && VECTOR_TYPE_P (t2
)
2493 && (TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2494 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2500 /* vector_types_convertible_p is used for vector value types.
2501 It could in principle call vector_targets_convertible_p as a subroutine,
2502 but then the check for vector type would be duplicated with its callers,
2503 and also the purpose of vector_targets_convertible_p would become
2505 Where vector_types_convertible_p returns true, a conversion might still be
2506 needed to make the types match.
2507 In contrast, vector_targets_convertible_p is used for vector pointer
2508 values, and vector_types_compatible_elements_p is used specifically
2509 in the context for binary operators, as a check if use is possible without
2511 /* True if vector types T1 and T2 can be converted to each other
2512 without an explicit cast. If EMIT_LAX_NOTE is true, and T1 and T2
2513 can only be converted with -flax-vector-conversions yet that is not
2514 in effect, emit a note telling the user about that option if such
2515 a note has not previously been emitted. */
2517 vector_types_convertible_p (const_tree t1
, const_tree t2
, bool emit_lax_note
)
2519 static bool emitted_lax_note
= false;
2520 bool convertible_lax
;
2522 if ((TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2523 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2527 (tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
))
2528 && (TREE_CODE (TREE_TYPE (t1
)) != REAL_TYPE
||
2529 TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
))
2530 && (INTEGRAL_TYPE_P (TREE_TYPE (t1
))
2531 == INTEGRAL_TYPE_P (TREE_TYPE (t2
))));
2533 if (!convertible_lax
|| flag_lax_vector_conversions
)
2534 return convertible_lax
;
2536 if (TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
)
2537 && lang_hooks
.types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
2540 if (emit_lax_note
&& !emitted_lax_note
)
2542 emitted_lax_note
= true;
2543 inform (input_location
, "use -flax-vector-conversions to permit "
2544 "conversions between vectors with differing "
2545 "element types or numbers of subparts");
2551 /* Build a VEC_PERM_EXPR if V0, V1 and MASK are not error_mark_nodes
2552 and have vector types, V0 has the same type as V1, and the number of
2553 elements of V0, V1, MASK is the same.
2555 In case V1 is a NULL_TREE it is assumed that __builtin_shuffle was
2556 called with two arguments. In this case implementation passes the
2557 first argument twice in order to share the same tree code. This fact
2558 could enable the mask-values being twice the vector length. This is
2559 an implementation accident and this semantics is not guaranteed to
2562 c_build_vec_perm_expr (location_t loc
, tree v0
, tree v1
, tree mask
,
2567 bool maybe_const
= false;
2568 bool two_arguments
= false;
2570 if (v1
== NULL_TREE
)
2572 two_arguments
= true;
2576 if (v0
== error_mark_node
|| v1
== error_mark_node
2577 || mask
== error_mark_node
)
2578 return error_mark_node
;
2580 if (!VECTOR_INTEGER_TYPE_P (TREE_TYPE (mask
)))
2583 error_at (loc
, "__builtin_shuffle last argument must "
2584 "be an integer vector");
2585 return error_mark_node
;
2588 if (!VECTOR_TYPE_P (TREE_TYPE (v0
))
2589 || !VECTOR_TYPE_P (TREE_TYPE (v1
)))
2592 error_at (loc
, "__builtin_shuffle arguments must be vectors");
2593 return error_mark_node
;
2596 if (TYPE_MAIN_VARIANT (TREE_TYPE (v0
)) != TYPE_MAIN_VARIANT (TREE_TYPE (v1
)))
2599 error_at (loc
, "__builtin_shuffle argument vectors must be of "
2601 return error_mark_node
;
2604 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (v0
))
2605 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
))
2606 && TYPE_VECTOR_SUBPARTS (TREE_TYPE (v1
))
2607 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
)))
2610 error_at (loc
, "__builtin_shuffle number of elements of the "
2611 "argument vector(s) and the mask vector should "
2613 return error_mark_node
;
2616 if (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (v0
))))
2617 != GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (mask
)))))
2620 error_at (loc
, "__builtin_shuffle argument vector(s) inner type "
2621 "must have the same size as inner type of the mask");
2622 return error_mark_node
;
2625 if (!c_dialect_cxx ())
2627 /* Avoid C_MAYBE_CONST_EXPRs inside VEC_PERM_EXPR. */
2628 v0
= c_fully_fold (v0
, false, &maybe_const
);
2629 wrap
&= maybe_const
;
2632 v1
= v0
= save_expr (v0
);
2635 v1
= c_fully_fold (v1
, false, &maybe_const
);
2636 wrap
&= maybe_const
;
2639 mask
= c_fully_fold (mask
, false, &maybe_const
);
2640 wrap
&= maybe_const
;
2642 else if (two_arguments
)
2643 v1
= v0
= save_expr (v0
);
2645 ret
= build3_loc (loc
, VEC_PERM_EXPR
, TREE_TYPE (v0
), v0
, v1
, mask
);
2647 if (!c_dialect_cxx () && !wrap
)
2648 ret
= c_wrap_maybe_const (ret
, true);
2653 /* Like tree.c:get_narrower, but retain conversion from C++0x scoped enum
2654 to integral type. */
2657 c_common_get_narrower (tree op
, int *unsignedp_ptr
)
2659 op
= get_narrower (op
, unsignedp_ptr
);
2661 if (TREE_CODE (TREE_TYPE (op
)) == ENUMERAL_TYPE
2662 && ENUM_IS_SCOPED (TREE_TYPE (op
)))
2664 /* C++0x scoped enumerations don't implicitly convert to integral
2665 type; if we stripped an explicit conversion to a larger type we
2666 need to replace it so common_type will still work. */
2667 tree type
= c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op
)),
2668 TYPE_UNSIGNED (TREE_TYPE (op
)));
2669 op
= fold_convert (type
, op
);
2674 /* This is a helper function of build_binary_op.
2676 For certain operations if both args were extended from the same
2677 smaller type, do the arithmetic in that type and then extend.
2679 BITWISE indicates a bitwise operation.
2680 For them, this optimization is safe only if
2681 both args are zero-extended or both are sign-extended.
2682 Otherwise, we might change the result.
2683 Eg, (short)-1 | (unsigned short)-1 is (int)-1
2684 but calculated in (unsigned short) it would be (unsigned short)-1.
2687 shorten_binary_op (tree result_type
, tree op0
, tree op1
, bool bitwise
)
2689 int unsigned0
, unsigned1
;
2694 /* Cast OP0 and OP1 to RESULT_TYPE. Doing so prevents
2695 excessive narrowing when we call get_narrower below. For
2696 example, suppose that OP0 is of unsigned int extended
2697 from signed char and that RESULT_TYPE is long long int.
2698 If we explicitly cast OP0 to RESULT_TYPE, OP0 would look
2701 (long long int) (unsigned int) signed_char
2703 which get_narrower would narrow down to
2705 (unsigned int) signed char
2707 If we do not cast OP0 first, get_narrower would return
2708 signed_char, which is inconsistent with the case of the
2710 op0
= convert (result_type
, op0
);
2711 op1
= convert (result_type
, op1
);
2713 arg0
= c_common_get_narrower (op0
, &unsigned0
);
2714 arg1
= c_common_get_narrower (op1
, &unsigned1
);
2716 /* UNS is 1 if the operation to be done is an unsigned one. */
2717 uns
= TYPE_UNSIGNED (result_type
);
2719 /* Handle the case that OP0 (or OP1) does not *contain* a conversion
2720 but it *requires* conversion to FINAL_TYPE. */
2722 if ((TYPE_PRECISION (TREE_TYPE (op0
))
2723 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2724 && TREE_TYPE (op0
) != result_type
)
2725 unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2726 if ((TYPE_PRECISION (TREE_TYPE (op1
))
2727 == TYPE_PRECISION (TREE_TYPE (arg1
)))
2728 && TREE_TYPE (op1
) != result_type
)
2729 unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2731 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
2733 /* For bitwise operations, signedness of nominal type
2734 does not matter. Consider only how operands were extended. */
2738 /* Note that in all three cases below we refrain from optimizing
2739 an unsigned operation on sign-extended args.
2740 That would not be valid. */
2742 /* Both args variable: if both extended in same way
2743 from same width, do it in that width.
2744 Do it unsigned if args were zero-extended. */
2745 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
2746 < TYPE_PRECISION (result_type
))
2747 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2748 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2749 && unsigned0
== unsigned1
2750 && (unsigned0
|| !uns
))
2751 return c_common_signed_or_unsigned_type
2752 (unsigned0
, common_type (TREE_TYPE (arg0
), TREE_TYPE (arg1
)));
2754 else if (TREE_CODE (arg0
) == INTEGER_CST
2755 && (unsigned1
|| !uns
)
2756 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2757 < TYPE_PRECISION (result_type
))
2759 = c_common_signed_or_unsigned_type (unsigned1
,
2761 && !POINTER_TYPE_P (type
)
2762 && int_fits_type_p (arg0
, type
))
2765 else if (TREE_CODE (arg1
) == INTEGER_CST
2766 && (unsigned0
|| !uns
)
2767 && (TYPE_PRECISION (TREE_TYPE (arg0
))
2768 < TYPE_PRECISION (result_type
))
2770 = c_common_signed_or_unsigned_type (unsigned0
,
2772 && !POINTER_TYPE_P (type
)
2773 && int_fits_type_p (arg1
, type
))
2779 /* Returns true iff any integer value of type FROM_TYPE can be represented as
2780 real of type TO_TYPE. This is a helper function for unsafe_conversion_p. */
2783 int_safely_convertible_to_real_p (const_tree from_type
, const_tree to_type
)
2785 tree type_low_bound
= TYPE_MIN_VALUE (from_type
);
2786 tree type_high_bound
= TYPE_MAX_VALUE (from_type
);
2787 REAL_VALUE_TYPE real_low_bound
=
2788 real_value_from_int_cst (0, type_low_bound
);
2789 REAL_VALUE_TYPE real_high_bound
=
2790 real_value_from_int_cst (0, type_high_bound
);
2792 return exact_real_truncate (TYPE_MODE (to_type
), &real_low_bound
)
2793 && exact_real_truncate (TYPE_MODE (to_type
), &real_high_bound
);
2796 /* Checks if expression EXPR of complex/real/integer type cannot be converted
2797 to the complex/real/integer type TYPE. Function returns non-zero when:
2798 * EXPR is a constant which cannot be exactly converted to TYPE.
2799 * EXPR is not a constant and size of EXPR's type > than size of TYPE,
2800 for EXPR type and TYPE being both integers or both real, or both
2802 * EXPR is not a constant of complex type and TYPE is a real or
2804 * EXPR is not a constant of real type and TYPE is an integer.
2805 * EXPR is not a constant of integer type which cannot be
2806 exactly converted to real type.
2808 Function allows conversions between types of different signedness and
2809 can return SAFE_CONVERSION (zero) in that case. Function can produce
2810 signedness warnings if PRODUCE_WARNS is true.
2812 Function allows conversions from complex constants to non-complex types,
2813 provided that imaginary part is zero and real part can be safely converted
2816 enum conversion_safety
2817 unsafe_conversion_p (location_t loc
, tree type
, tree expr
, bool produce_warns
)
2819 enum conversion_safety give_warning
= SAFE_CONVERSION
; /* is 0 or false */
2820 tree expr_type
= TREE_TYPE (expr
);
2821 loc
= expansion_point_location_if_in_system_header (loc
);
2823 if (TREE_CODE (expr
) == REAL_CST
|| TREE_CODE (expr
) == INTEGER_CST
)
2825 /* If type is complex, we are interested in compatibility with
2827 if (TREE_CODE (type
) == COMPLEX_TYPE
)
2828 type
= TREE_TYPE (type
);
2830 /* Warn for real constant that is not an exact integer converted
2832 if (TREE_CODE (expr_type
) == REAL_TYPE
2833 && TREE_CODE (type
) == INTEGER_TYPE
)
2835 if (!real_isinteger (TREE_REAL_CST_PTR (expr
), TYPE_MODE (expr_type
)))
2836 give_warning
= UNSAFE_REAL
;
2838 /* Warn for an integer constant that does not fit into integer type. */
2839 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2840 && TREE_CODE (type
) == INTEGER_TYPE
2841 && !int_fits_type_p (expr
, type
))
2843 if (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)
2844 && tree_int_cst_sgn (expr
) < 0)
2847 warning_at (loc
, OPT_Wsign_conversion
, "negative integer"
2848 " implicitly converted to unsigned type");
2850 else if (!TYPE_UNSIGNED (type
) && TYPE_UNSIGNED (expr_type
))
2853 warning_at (loc
, OPT_Wsign_conversion
, "conversion of unsigned"
2854 " constant value to negative integer");
2857 give_warning
= UNSAFE_OTHER
;
2859 else if (TREE_CODE (type
) == REAL_TYPE
)
2861 /* Warn for an integer constant that does not fit into real type. */
2862 if (TREE_CODE (expr_type
) == INTEGER_TYPE
)
2864 REAL_VALUE_TYPE a
= real_value_from_int_cst (0, expr
);
2865 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2866 give_warning
= UNSAFE_REAL
;
2868 /* Warn for a real constant that does not fit into a smaller
2870 else if (TREE_CODE (expr_type
) == REAL_TYPE
2871 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2873 REAL_VALUE_TYPE a
= TREE_REAL_CST (expr
);
2874 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2875 give_warning
= UNSAFE_REAL
;
2880 else if (TREE_CODE (expr
) == COMPLEX_CST
)
2882 tree imag_part
= TREE_IMAGPART (expr
);
2883 /* Conversion from complex constant with zero imaginary part,
2884 perform check for conversion of real part. */
2885 if ((TREE_CODE (imag_part
) == REAL_CST
2886 && real_zerop (imag_part
))
2887 || (TREE_CODE (imag_part
) == INTEGER_CST
2888 && integer_zerop (imag_part
)))
2889 /* Note: in this branch we use recursive call to unsafe_conversion_p
2890 with different type of EXPR, but it is still safe, because when EXPR
2891 is a constant, it's type is not used in text of generated warnings
2892 (otherwise they could sound misleading). */
2893 return unsafe_conversion_p (loc
, type
, TREE_REALPART (expr
),
2895 /* Conversion from complex constant with non-zero imaginary part. */
2898 /* Conversion to complex type.
2899 Perform checks for both real and imaginary parts. */
2900 if (TREE_CODE (type
) == COMPLEX_TYPE
)
2902 /* Unfortunately, produce_warns must be false in two subsequent
2903 calls of unsafe_conversion_p, because otherwise we could
2904 produce strange "double" warnings, if both real and imaginary
2905 parts have conversion problems related to signedness.
2908 int32_t _Complex a = 0x80000000 + 0x80000000i;
2910 Possible solution: add a separate function for checking
2911 constants and combine result of two calls appropriately. */
2912 enum conversion_safety re_safety
=
2913 unsafe_conversion_p (loc
, type
, TREE_REALPART (expr
), false);
2914 enum conversion_safety im_safety
=
2915 unsafe_conversion_p (loc
, type
, imag_part
, false);
2917 /* Merge the results into appropriate single warning. */
2919 /* Note: this case includes SAFE_CONVERSION, i.e. success. */
2920 if (re_safety
== im_safety
)
2921 give_warning
= re_safety
;
2922 else if (!re_safety
&& im_safety
)
2923 give_warning
= im_safety
;
2924 else if (re_safety
&& !im_safety
)
2925 give_warning
= re_safety
;
2927 give_warning
= UNSAFE_OTHER
;
2929 /* Warn about conversion from complex to real or integer type. */
2931 give_warning
= UNSAFE_IMAGINARY
;
2935 /* Checks for remaining case: EXPR is not constant. */
2938 /* Warn for real types converted to integer types. */
2939 if (TREE_CODE (expr_type
) == REAL_TYPE
2940 && TREE_CODE (type
) == INTEGER_TYPE
)
2941 give_warning
= UNSAFE_REAL
;
2943 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2944 && TREE_CODE (type
) == INTEGER_TYPE
)
2946 /* Don't warn about unsigned char y = 0xff, x = (int) y; */
2947 expr
= get_unwidened (expr
, 0);
2948 expr_type
= TREE_TYPE (expr
);
2950 /* Don't warn for short y; short x = ((int)y & 0xff); */
2951 if (TREE_CODE (expr
) == BIT_AND_EXPR
2952 || TREE_CODE (expr
) == BIT_IOR_EXPR
2953 || TREE_CODE (expr
) == BIT_XOR_EXPR
)
2955 /* If both args were extended from a shortest type,
2956 use that type if that is safe. */
2957 expr_type
= shorten_binary_op (expr_type
,
2958 TREE_OPERAND (expr
, 0),
2959 TREE_OPERAND (expr
, 1),
2962 if (TREE_CODE (expr
) == BIT_AND_EXPR
)
2964 tree op0
= TREE_OPERAND (expr
, 0);
2965 tree op1
= TREE_OPERAND (expr
, 1);
2966 bool unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2967 bool unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2969 /* If one of the operands is a non-negative constant
2970 that fits in the target type, then the type of the
2971 other operand does not matter. */
2972 if ((TREE_CODE (op0
) == INTEGER_CST
2973 && int_fits_type_p (op0
, c_common_signed_type (type
))
2974 && int_fits_type_p (op0
, c_common_unsigned_type (type
)))
2975 || (TREE_CODE (op1
) == INTEGER_CST
2976 && int_fits_type_p (op1
, c_common_signed_type (type
))
2977 && int_fits_type_p (op1
,
2978 c_common_unsigned_type (type
))))
2979 return SAFE_CONVERSION
;
2980 /* If constant is unsigned and fits in the target
2981 type, then the result will also fit. */
2982 else if ((TREE_CODE (op0
) == INTEGER_CST
2984 && int_fits_type_p (op0
, type
))
2985 || (TREE_CODE (op1
) == INTEGER_CST
2987 && int_fits_type_p (op1
, type
)))
2988 return SAFE_CONVERSION
;
2991 /* Warn for integer types converted to smaller integer types. */
2992 if (TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2993 give_warning
= UNSAFE_OTHER
;
2995 /* When they are the same width but different signedness,
2996 then the value may change. */
2997 else if (((TYPE_PRECISION (type
) == TYPE_PRECISION (expr_type
)
2998 && TYPE_UNSIGNED (expr_type
) != TYPE_UNSIGNED (type
))
2999 /* Even when converted to a bigger type, if the type is
3000 unsigned but expr is signed, then negative values
3002 || (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)))
3004 warning_at (loc
, OPT_Wsign_conversion
, "conversion to %qT from %qT "
3005 "may change the sign of the result",
3009 /* Warn for integer types converted to real types if and only if
3010 all the range of values of the integer type cannot be
3011 represented by the real type. */
3012 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
3013 && TREE_CODE (type
) == REAL_TYPE
)
3015 /* Don't warn about char y = 0xff; float x = (int) y; */
3016 expr
= get_unwidened (expr
, 0);
3017 expr_type
= TREE_TYPE (expr
);
3019 if (!int_safely_convertible_to_real_p (expr_type
, type
))
3020 give_warning
= UNSAFE_OTHER
;
3023 /* Warn for real types converted to smaller real types. */
3024 else if (TREE_CODE (expr_type
) == REAL_TYPE
3025 && TREE_CODE (type
) == REAL_TYPE
3026 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
3027 give_warning
= UNSAFE_REAL
;
3029 /* Check conversion between two complex types. */
3030 else if (TREE_CODE (expr_type
) == COMPLEX_TYPE
3031 && TREE_CODE (type
) == COMPLEX_TYPE
)
3033 /* Extract underlying types (i.e., type of real and imaginary
3034 parts) of expr_type and type. */
3035 tree from_type
= TREE_TYPE (expr_type
);
3036 tree to_type
= TREE_TYPE (type
);
3038 /* Warn for real types converted to integer types. */
3039 if (TREE_CODE (from_type
) == REAL_TYPE
3040 && TREE_CODE (to_type
) == INTEGER_TYPE
)
3041 give_warning
= UNSAFE_REAL
;
3043 /* Warn for real types converted to smaller real types. */
3044 else if (TREE_CODE (from_type
) == REAL_TYPE
3045 && TREE_CODE (to_type
) == REAL_TYPE
3046 && TYPE_PRECISION (to_type
) < TYPE_PRECISION (from_type
))
3047 give_warning
= UNSAFE_REAL
;
3049 /* Check conversion for complex integer types. Here implementation
3050 is simpler than for real-domain integers because it does not
3051 involve sophisticated cases, such as bitmasks, casts, etc. */
3052 else if (TREE_CODE (from_type
) == INTEGER_TYPE
3053 && TREE_CODE (to_type
) == INTEGER_TYPE
)
3055 /* Warn for integer types converted to smaller integer types. */
3056 if (TYPE_PRECISION (to_type
) < TYPE_PRECISION (from_type
))
3057 give_warning
= UNSAFE_OTHER
;
3059 /* Check for different signedness, see case for real-domain
3060 integers (above) for a more detailed comment. */
3061 else if (((TYPE_PRECISION (to_type
) == TYPE_PRECISION (from_type
)
3062 && TYPE_UNSIGNED (to_type
) != TYPE_UNSIGNED (from_type
))
3063 || (TYPE_UNSIGNED (to_type
) && !TYPE_UNSIGNED (from_type
)))
3065 warning_at (loc
, OPT_Wsign_conversion
,
3066 "conversion to %qT from %qT "
3067 "may change the sign of the result",
3070 else if (TREE_CODE (from_type
) == INTEGER_TYPE
3071 && TREE_CODE (to_type
) == REAL_TYPE
3072 && !int_safely_convertible_to_real_p (from_type
, to_type
))
3073 give_warning
= UNSAFE_OTHER
;
3076 /* Warn for complex types converted to real or integer types. */
3077 else if (TREE_CODE (expr_type
) == COMPLEX_TYPE
3078 && TREE_CODE (type
) != COMPLEX_TYPE
)
3079 give_warning
= UNSAFE_IMAGINARY
;
3082 return give_warning
;
3085 /* Warns if the conversion of EXPR to TYPE may alter a value.
3086 This is a helper function for warnings_for_convert_and_check. */
3089 conversion_warning (location_t loc
, tree type
, tree expr
)
3091 tree expr_type
= TREE_TYPE (expr
);
3092 enum conversion_safety conversion_kind
;
3094 if (!warn_conversion
&& !warn_sign_conversion
&& !warn_float_conversion
)
3097 /* This may happen, because for LHS op= RHS we preevaluate
3098 RHS and create C_MAYBE_CONST_EXPR <SAVE_EXPR <RHS>>, which
3099 means we could no longer see the code of the EXPR. */
3100 if (TREE_CODE (expr
) == C_MAYBE_CONST_EXPR
)
3101 expr
= C_MAYBE_CONST_EXPR_EXPR (expr
);
3102 if (TREE_CODE (expr
) == SAVE_EXPR
)
3103 expr
= TREE_OPERAND (expr
, 0);
3105 switch (TREE_CODE (expr
))
3113 case TRUTH_ANDIF_EXPR
:
3114 case TRUTH_ORIF_EXPR
:
3115 case TRUTH_AND_EXPR
:
3117 case TRUTH_XOR_EXPR
:
3118 case TRUTH_NOT_EXPR
:
3119 /* Conversion from boolean to a signed:1 bit-field (which only
3120 can hold the values 0 and -1) doesn't lose information - but
3121 it does change the value. */
3122 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
3123 warning_at (loc
, OPT_Wconversion
,
3124 "conversion to %qT from boolean expression", type
);
3130 conversion_kind
= unsafe_conversion_p (loc
, type
, expr
, true);
3131 if (conversion_kind
== UNSAFE_REAL
)
3132 warning_at (loc
, OPT_Wfloat_conversion
,
3133 "conversion to %qT alters %qT constant value",
3135 else if (conversion_kind
)
3136 warning_at (loc
, OPT_Wconversion
,
3137 "conversion to %qT alters %qT constant value",
3143 /* In case of COND_EXPR, we do not care about the type of
3144 COND_EXPR, only about the conversion of each operand. */
3145 tree op1
= TREE_OPERAND (expr
, 1);
3146 tree op2
= TREE_OPERAND (expr
, 2);
3148 conversion_warning (loc
, type
, op1
);
3149 conversion_warning (loc
, type
, op2
);
3153 default: /* 'expr' is not a constant. */
3154 conversion_kind
= unsafe_conversion_p (loc
, type
, expr
, true);
3155 if (conversion_kind
== UNSAFE_REAL
)
3156 warning_at (loc
, OPT_Wfloat_conversion
,
3157 "conversion to %qT from %qT may alter its value",
3159 else if (conversion_kind
== UNSAFE_IMAGINARY
)
3160 warning_at (loc
, OPT_Wconversion
,
3161 "conversion to %qT from %qT discards imaginary component",
3163 else if (conversion_kind
)
3164 warning_at (loc
, OPT_Wconversion
,
3165 "conversion to %qT from %qT may alter its value",
3170 /* Produce warnings after a conversion. RESULT is the result of
3171 converting EXPR to TYPE. This is a helper function for
3172 convert_and_check and cp_convert_and_check. */
3175 warnings_for_convert_and_check (location_t loc
, tree type
, tree expr
,
3178 loc
= expansion_point_location_if_in_system_header (loc
);
3180 if (TREE_CODE (expr
) == INTEGER_CST
3181 && (TREE_CODE (type
) == INTEGER_TYPE
3182 || TREE_CODE (type
) == ENUMERAL_TYPE
)
3183 && !int_fits_type_p (expr
, type
))
3185 /* Do not diagnose overflow in a constant expression merely
3186 because a conversion overflowed. */
3187 if (TREE_OVERFLOW (result
))
3188 TREE_OVERFLOW (result
) = TREE_OVERFLOW (expr
);
3190 if (TYPE_UNSIGNED (type
))
3192 /* This detects cases like converting -129 or 256 to
3194 if (!int_fits_type_p (expr
, c_common_signed_type (type
)))
3195 warning_at (loc
, OPT_Woverflow
,
3196 "large integer implicitly truncated to unsigned type");
3198 conversion_warning (loc
, type
, expr
);
3200 else if (!int_fits_type_p (expr
, c_common_unsigned_type (type
)))
3201 warning_at (loc
, OPT_Woverflow
,
3202 "overflow in implicit constant conversion");
3203 /* No warning for converting 0x80000000 to int. */
3205 && (TREE_CODE (TREE_TYPE (expr
)) != INTEGER_TYPE
3206 || TYPE_PRECISION (TREE_TYPE (expr
))
3207 != TYPE_PRECISION (type
)))
3208 warning_at (loc
, OPT_Woverflow
,
3209 "overflow in implicit constant conversion");
3212 conversion_warning (loc
, type
, expr
);
3214 else if ((TREE_CODE (result
) == INTEGER_CST
3215 || TREE_CODE (result
) == FIXED_CST
) && TREE_OVERFLOW (result
))
3216 warning_at (loc
, OPT_Woverflow
,
3217 "overflow in implicit constant conversion");
3219 conversion_warning (loc
, type
, expr
);
3223 /* Convert EXPR to TYPE, warning about conversion problems with constants.
3224 Invoke this function on every expression that is converted implicitly,
3225 i.e. because of language rules and not because of an explicit cast. */
3228 convert_and_check (location_t loc
, tree type
, tree expr
)
3231 tree expr_for_warning
;
3233 /* Convert from a value with possible excess precision rather than
3234 via the semantic type, but do not warn about values not fitting
3235 exactly in the semantic type. */
3236 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
3238 tree orig_type
= TREE_TYPE (expr
);
3239 expr
= TREE_OPERAND (expr
, 0);
3240 expr_for_warning
= convert (orig_type
, expr
);
3241 if (orig_type
== type
)
3242 return expr_for_warning
;
3245 expr_for_warning
= expr
;
3247 if (TREE_TYPE (expr
) == type
)
3250 result
= convert (type
, expr
);
3252 if (c_inhibit_evaluation_warnings
== 0
3253 && !TREE_OVERFLOW_P (expr
)
3254 && result
!= error_mark_node
)
3255 warnings_for_convert_and_check (loc
, type
, expr_for_warning
, result
);
3260 /* A node in a list that describes references to variables (EXPR), which are
3261 either read accesses if WRITER is zero, or write accesses, in which case
3262 WRITER is the parent of EXPR. */
3269 /* Used to implement a cache the results of a call to verify_tree. We only
3270 use this for SAVE_EXPRs. */
3273 struct tlist_cache
*next
;
3274 struct tlist
*cache_before_sp
;
3275 struct tlist
*cache_after_sp
;
3279 /* Obstack to use when allocating tlist structures, and corresponding
3281 static struct obstack tlist_obstack
;
3282 static char *tlist_firstobj
= 0;
3284 /* Keep track of the identifiers we've warned about, so we can avoid duplicate
3286 static struct tlist
*warned_ids
;
3287 /* SAVE_EXPRs need special treatment. We process them only once and then
3288 cache the results. */
3289 static struct tlist_cache
*save_expr_cache
;
3291 static void add_tlist (struct tlist
**, struct tlist
*, tree
, int);
3292 static void merge_tlist (struct tlist
**, struct tlist
*, int);
3293 static void verify_tree (tree
, struct tlist
**, struct tlist
**, tree
);
3294 static int warning_candidate_p (tree
);
3295 static bool candidate_equal_p (const_tree
, const_tree
);
3296 static void warn_for_collisions (struct tlist
*);
3297 static void warn_for_collisions_1 (tree
, tree
, struct tlist
*, int);
3298 static struct tlist
*new_tlist (struct tlist
*, tree
, tree
);
3300 /* Create a new struct tlist and fill in its fields. */
3301 static struct tlist
*
3302 new_tlist (struct tlist
*next
, tree t
, tree writer
)
3305 l
= XOBNEW (&tlist_obstack
, struct tlist
);
3312 /* Add duplicates of the nodes found in ADD to the list *TO. If EXCLUDE_WRITER
3313 is nonnull, we ignore any node we find which has a writer equal to it. */
3316 add_tlist (struct tlist
**to
, struct tlist
*add
, tree exclude_writer
, int copy
)
3320 struct tlist
*next
= add
->next
;
3323 if (!exclude_writer
|| !candidate_equal_p (add
->writer
, exclude_writer
))
3324 *to
= copy
? new_tlist (*to
, add
->expr
, add
->writer
) : add
;
3329 /* Merge the nodes of ADD into TO. This merging process is done so that for
3330 each variable that already exists in TO, no new node is added; however if
3331 there is a write access recorded in ADD, and an occurrence on TO is only
3332 a read access, then the occurrence in TO will be modified to record the
3336 merge_tlist (struct tlist
**to
, struct tlist
*add
, int copy
)
3338 struct tlist
**end
= to
;
3341 end
= &(*end
)->next
;
3347 struct tlist
*next
= add
->next
;
3349 for (tmp2
= *to
; tmp2
; tmp2
= tmp2
->next
)
3350 if (candidate_equal_p (tmp2
->expr
, add
->expr
))
3354 tmp2
->writer
= add
->writer
;
3358 *end
= copy
? new_tlist (NULL
, add
->expr
, add
->writer
) : add
;
3359 end
= &(*end
)->next
;
3366 /* WRITTEN is a variable, WRITER is its parent. Warn if any of the variable
3367 references in list LIST conflict with it, excluding reads if ONLY writers
3371 warn_for_collisions_1 (tree written
, tree writer
, struct tlist
*list
,
3376 /* Avoid duplicate warnings. */
3377 for (tmp
= warned_ids
; tmp
; tmp
= tmp
->next
)
3378 if (candidate_equal_p (tmp
->expr
, written
))
3383 if (candidate_equal_p (list
->expr
, written
)
3384 && !candidate_equal_p (list
->writer
, writer
)
3385 && (!only_writes
|| list
->writer
))
3387 warned_ids
= new_tlist (warned_ids
, written
, NULL_TREE
);
3388 warning_at (EXPR_LOC_OR_LOC (writer
, input_location
),
3389 OPT_Wsequence_point
, "operation on %qE may be undefined",
3396 /* Given a list LIST of references to variables, find whether any of these
3397 can cause conflicts due to missing sequence points. */
3400 warn_for_collisions (struct tlist
*list
)
3404 for (tmp
= list
; tmp
; tmp
= tmp
->next
)
3407 warn_for_collisions_1 (tmp
->expr
, tmp
->writer
, list
, 0);
3411 /* Return nonzero if X is a tree that can be verified by the sequence point
3414 warning_candidate_p (tree x
)
3416 if (DECL_P (x
) && DECL_ARTIFICIAL (x
))
3419 if (TREE_CODE (x
) == BLOCK
)
3422 /* VOID_TYPE_P (TREE_TYPE (x)) is workaround for cp/tree.c
3423 (lvalue_p) crash on TRY/CATCH. */
3424 if (TREE_TYPE (x
) == NULL_TREE
|| VOID_TYPE_P (TREE_TYPE (x
)))
3430 /* No point to track non-const calls, they will never satisfy
3432 if (TREE_CODE (x
) == CALL_EXPR
&& (call_expr_flags (x
) & ECF_CONST
) == 0)
3435 if (TREE_CODE (x
) == STRING_CST
)
3441 /* Return nonzero if X and Y appear to be the same candidate (or NULL) */
3443 candidate_equal_p (const_tree x
, const_tree y
)
3445 return (x
== y
) || (x
&& y
&& operand_equal_p (x
, y
, 0));
3448 /* Walk the tree X, and record accesses to variables. If X is written by the
3449 parent tree, WRITER is the parent.
3450 We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP. If this
3451 expression or its only operand forces a sequence point, then everything up
3452 to the sequence point is stored in PBEFORE_SP. Everything else gets stored
3454 Once we return, we will have emitted warnings if any subexpression before
3455 such a sequence point could be undefined. On a higher level, however, the
3456 sequence point may not be relevant, and we'll merge the two lists.
3458 Example: (b++, a) + b;
3459 The call that processes the COMPOUND_EXPR will store the increment of B
3460 in PBEFORE_SP, and the use of A in PNO_SP. The higher-level call that
3461 processes the PLUS_EXPR will need to merge the two lists so that
3462 eventually, all accesses end up on the same list (and we'll warn about the
3463 unordered subexpressions b++ and b.
3465 A note on merging. If we modify the former example so that our expression
3468 care must be taken not simply to add all three expressions into the final
3469 PNO_SP list. The function merge_tlist takes care of that by merging the
3470 before-SP list of the COMPOUND_EXPR into its after-SP list in a special
3471 way, so that no more than one access to B is recorded. */
3474 verify_tree (tree x
, struct tlist
**pbefore_sp
, struct tlist
**pno_sp
,
3477 struct tlist
*tmp_before
, *tmp_nosp
, *tmp_list2
, *tmp_list3
;
3478 enum tree_code code
;
3479 enum tree_code_class cl
;
3481 /* X may be NULL if it is the operand of an empty statement expression
3487 code
= TREE_CODE (x
);
3488 cl
= TREE_CODE_CLASS (code
);
3490 if (warning_candidate_p (x
))
3491 *pno_sp
= new_tlist (*pno_sp
, x
, writer
);
3500 case TRUTH_ANDIF_EXPR
:
3501 case TRUTH_ORIF_EXPR
:
3502 tmp_before
= tmp_nosp
= tmp_list3
= 0;
3503 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3504 warn_for_collisions (tmp_nosp
);
3505 merge_tlist (pbefore_sp
, tmp_before
, 0);
3506 merge_tlist (pbefore_sp
, tmp_nosp
, 0);
3507 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, pno_sp
, NULL_TREE
);
3508 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3512 tmp_before
= tmp_list2
= 0;
3513 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_list2
, NULL_TREE
);
3514 warn_for_collisions (tmp_list2
);
3515 merge_tlist (pbefore_sp
, tmp_before
, 0);
3516 merge_tlist (pbefore_sp
, tmp_list2
, 0);
3518 tmp_list3
= tmp_nosp
= 0;
3519 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, &tmp_nosp
, NULL_TREE
);
3520 warn_for_collisions (tmp_nosp
);
3521 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3523 tmp_list3
= tmp_list2
= 0;
3524 verify_tree (TREE_OPERAND (x
, 2), &tmp_list3
, &tmp_list2
, NULL_TREE
);
3525 warn_for_collisions (tmp_list2
);
3526 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3527 /* Rather than add both tmp_nosp and tmp_list2, we have to merge the
3528 two first, to avoid warning for (a ? b++ : b++). */
3529 merge_tlist (&tmp_nosp
, tmp_list2
, 0);
3530 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3533 case PREDECREMENT_EXPR
:
3534 case PREINCREMENT_EXPR
:
3535 case POSTDECREMENT_EXPR
:
3536 case POSTINCREMENT_EXPR
:
3537 verify_tree (TREE_OPERAND (x
, 0), pno_sp
, pno_sp
, x
);
3541 tmp_before
= tmp_nosp
= tmp_list3
= 0;
3542 verify_tree (TREE_OPERAND (x
, 1), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3543 verify_tree (TREE_OPERAND (x
, 0), &tmp_list3
, &tmp_list3
, x
);
3544 /* Expressions inside the LHS are not ordered wrt. the sequence points
3545 in the RHS. Example:
3547 Despite the fact that the modification of "a" is in the before_sp
3548 list (tmp_before), it conflicts with the use of "a" in the LHS.
3549 We can handle this by adding the contents of tmp_list3
3550 to those of tmp_before, and redoing the collision warnings for that
3552 add_tlist (&tmp_before
, tmp_list3
, x
, 1);
3553 warn_for_collisions (tmp_before
);
3554 /* Exclude the LHS itself here; we first have to merge it into the
3555 tmp_nosp list. This is done to avoid warning for "a = a"; if we
3556 didn't exclude the LHS, we'd get it twice, once as a read and once
3558 add_tlist (pno_sp
, tmp_list3
, x
, 0);
3559 warn_for_collisions_1 (TREE_OPERAND (x
, 0), x
, tmp_nosp
, 1);
3561 merge_tlist (pbefore_sp
, tmp_before
, 0);
3562 if (warning_candidate_p (TREE_OPERAND (x
, 0)))
3563 merge_tlist (&tmp_nosp
, new_tlist (NULL
, TREE_OPERAND (x
, 0), x
), 0);
3564 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 1);
3568 /* We need to warn about conflicts among arguments and conflicts between
3569 args and the function address. Side effects of the function address,
3570 however, are not ordered by the sequence point of the call. */
3572 call_expr_arg_iterator iter
;
3574 tmp_before
= tmp_nosp
= 0;
3575 verify_tree (CALL_EXPR_FN (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3576 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, x
)
3578 tmp_list2
= tmp_list3
= 0;
3579 verify_tree (arg
, &tmp_list2
, &tmp_list3
, NULL_TREE
);
3580 merge_tlist (&tmp_list3
, tmp_list2
, 0);
3581 add_tlist (&tmp_before
, tmp_list3
, NULL_TREE
, 0);
3583 add_tlist (&tmp_before
, tmp_nosp
, NULL_TREE
, 0);
3584 warn_for_collisions (tmp_before
);
3585 add_tlist (pbefore_sp
, tmp_before
, NULL_TREE
, 0);
3590 /* Scan all the list, e.g. indices of multi dimensional array. */
3593 tmp_before
= tmp_nosp
= 0;
3594 verify_tree (TREE_VALUE (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3595 merge_tlist (&tmp_nosp
, tmp_before
, 0);
3596 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3603 struct tlist_cache
*t
;
3604 for (t
= save_expr_cache
; t
; t
= t
->next
)
3605 if (candidate_equal_p (t
->expr
, x
))
3610 t
= XOBNEW (&tlist_obstack
, struct tlist_cache
);
3611 t
->next
= save_expr_cache
;
3613 save_expr_cache
= t
;
3615 tmp_before
= tmp_nosp
= 0;
3616 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3617 warn_for_collisions (tmp_nosp
);
3620 merge_tlist (&tmp_list3
, tmp_nosp
, 0);
3621 t
->cache_before_sp
= tmp_before
;
3622 t
->cache_after_sp
= tmp_list3
;
3624 merge_tlist (pbefore_sp
, t
->cache_before_sp
, 1);
3625 add_tlist (pno_sp
, t
->cache_after_sp
, NULL_TREE
, 1);
3630 x
= TREE_OPERAND (x
, 0);
3637 /* For other expressions, simply recurse on their operands.
3638 Manual tail recursion for unary expressions.
3639 Other non-expressions need not be processed. */
3640 if (cl
== tcc_unary
)
3642 x
= TREE_OPERAND (x
, 0);
3646 else if (IS_EXPR_CODE_CLASS (cl
))
3649 int max
= TREE_OPERAND_LENGTH (x
);
3650 for (lp
= 0; lp
< max
; lp
++)
3652 tmp_before
= tmp_nosp
= 0;
3653 verify_tree (TREE_OPERAND (x
, lp
), &tmp_before
, &tmp_nosp
, 0);
3654 merge_tlist (&tmp_nosp
, tmp_before
, 0);
3655 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3662 /* Try to warn for undefined behavior in EXPR due to missing sequence
3666 verify_sequence_points (tree expr
)
3668 struct tlist
*before_sp
= 0, *after_sp
= 0;
3671 save_expr_cache
= 0;
3672 if (tlist_firstobj
== 0)
3674 gcc_obstack_init (&tlist_obstack
);
3675 tlist_firstobj
= (char *) obstack_alloc (&tlist_obstack
, 0);
3678 verify_tree (expr
, &before_sp
, &after_sp
, 0);
3679 warn_for_collisions (after_sp
);
3680 obstack_free (&tlist_obstack
, tlist_firstobj
);
3683 /* Validate the expression after `case' and apply default promotions. */
3686 check_case_value (location_t loc
, tree value
)
3688 if (value
== NULL_TREE
)
3691 if (TREE_CODE (value
) == INTEGER_CST
)
3692 /* Promote char or short to int. */
3693 value
= perform_integral_promotions (value
);
3694 else if (value
!= error_mark_node
)
3696 error_at (loc
, "case label does not reduce to an integer constant");
3697 value
= error_mark_node
;
3700 constant_expression_warning (value
);
3705 /* See if the case values LOW and HIGH are in the range of the original
3706 type (i.e. before the default conversion to int) of the switch testing
3708 TYPE is the promoted type of the testing expression, and ORIG_TYPE is
3709 the type before promoting it. CASE_LOW_P is a pointer to the lower
3710 bound of the case label, and CASE_HIGH_P is the upper bound or NULL
3711 if the case is not a case range.
3712 The caller has to make sure that we are not called with NULL for
3713 CASE_LOW_P (i.e. the default case). OUTSIDE_RANGE_P says whether there
3714 was a case value that doesn't fit into the range of the ORIG_TYPE.
3715 Returns true if the case label is in range of ORIG_TYPE (saturated or
3716 untouched) or false if the label is out of range. */
3719 check_case_bounds (location_t loc
, tree type
, tree orig_type
,
3720 tree
*case_low_p
, tree
*case_high_p
,
3721 bool *outside_range_p
)
3723 tree min_value
, max_value
;
3724 tree case_low
= *case_low_p
;
3725 tree case_high
= case_high_p
? *case_high_p
: case_low
;
3727 /* If there was a problem with the original type, do nothing. */
3728 if (orig_type
== error_mark_node
)
3731 min_value
= TYPE_MIN_VALUE (orig_type
);
3732 max_value
= TYPE_MAX_VALUE (orig_type
);
3734 /* Case label is less than minimum for type. */
3735 if (tree_int_cst_compare (case_low
, min_value
) < 0
3736 && tree_int_cst_compare (case_high
, min_value
) < 0)
3738 warning_at (loc
, 0, "case label value is less than minimum value "
3740 *outside_range_p
= true;
3744 /* Case value is greater than maximum for type. */
3745 if (tree_int_cst_compare (case_low
, max_value
) > 0
3746 && tree_int_cst_compare (case_high
, max_value
) > 0)
3748 warning_at (loc
, 0, "case label value exceeds maximum value for type");
3749 *outside_range_p
= true;
3753 /* Saturate lower case label value to minimum. */
3754 if (tree_int_cst_compare (case_high
, min_value
) >= 0
3755 && tree_int_cst_compare (case_low
, min_value
) < 0)
3757 warning_at (loc
, 0, "lower value in case label range"
3758 " less than minimum value for type");
3759 *outside_range_p
= true;
3760 case_low
= min_value
;
3763 /* Saturate upper case label value to maximum. */
3764 if (tree_int_cst_compare (case_low
, max_value
) <= 0
3765 && tree_int_cst_compare (case_high
, max_value
) > 0)
3767 warning_at (loc
, 0, "upper value in case label range"
3768 " exceeds maximum value for type");
3769 *outside_range_p
= true;
3770 case_high
= max_value
;
3773 if (*case_low_p
!= case_low
)
3774 *case_low_p
= convert (type
, case_low
);
3775 if (case_high_p
&& *case_high_p
!= case_high
)
3776 *case_high_p
= convert (type
, case_high
);
3781 /* Return an integer type with BITS bits of precision,
3782 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
3785 c_common_type_for_size (unsigned int bits
, int unsignedp
)
3789 if (bits
== TYPE_PRECISION (integer_type_node
))
3790 return unsignedp
? unsigned_type_node
: integer_type_node
;
3792 if (bits
== TYPE_PRECISION (signed_char_type_node
))
3793 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3795 if (bits
== TYPE_PRECISION (short_integer_type_node
))
3796 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3798 if (bits
== TYPE_PRECISION (long_integer_type_node
))
3799 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3801 if (bits
== TYPE_PRECISION (long_long_integer_type_node
))
3802 return (unsignedp
? long_long_unsigned_type_node
3803 : long_long_integer_type_node
);
3805 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
3806 if (int_n_enabled_p
[i
]
3807 && bits
== int_n_data
[i
].bitsize
)
3808 return (unsignedp
? int_n_trees
[i
].unsigned_type
3809 : int_n_trees
[i
].signed_type
);
3811 if (bits
== TYPE_PRECISION (widest_integer_literal_type_node
))
3812 return (unsignedp
? widest_unsigned_literal_type_node
3813 : widest_integer_literal_type_node
);
3815 if (bits
<= TYPE_PRECISION (intQI_type_node
))
3816 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3818 if (bits
<= TYPE_PRECISION (intHI_type_node
))
3819 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3821 if (bits
<= TYPE_PRECISION (intSI_type_node
))
3822 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3824 if (bits
<= TYPE_PRECISION (intDI_type_node
))
3825 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3830 /* Return a fixed-point type that has at least IBIT ibits and FBIT fbits
3831 that is unsigned if UNSIGNEDP is nonzero, otherwise signed;
3832 and saturating if SATP is nonzero, otherwise not saturating. */
3835 c_common_fixed_point_type_for_size (unsigned int ibit
, unsigned int fbit
,
3836 int unsignedp
, int satp
)
3840 mode
= unsignedp
? UQQmode
: QQmode
;
3842 mode
= unsignedp
? UHAmode
: HAmode
;
3844 for (; mode
!= VOIDmode
; mode
= GET_MODE_WIDER_MODE (mode
))
3845 if (GET_MODE_IBIT (mode
) >= ibit
&& GET_MODE_FBIT (mode
) >= fbit
)
3848 if (mode
== VOIDmode
|| !targetm
.scalar_mode_supported_p (mode
))
3850 sorry ("GCC cannot support operators with integer types and "
3851 "fixed-point types that have too many integral and "
3852 "fractional bits together");
3856 return c_common_type_for_mode (mode
, satp
);
3859 /* Used for communication between c_common_type_for_mode and
3860 c_register_builtin_type. */
3861 tree registered_builtin_types
;
3863 /* Return a data type that has machine mode MODE.
3864 If the mode is an integer,
3865 then UNSIGNEDP selects between signed and unsigned types.
3866 If the mode is a fixed-point mode,
3867 then UNSIGNEDP selects between saturating and nonsaturating types. */
3870 c_common_type_for_mode (machine_mode mode
, int unsignedp
)
3875 if (mode
== TYPE_MODE (integer_type_node
))
3876 return unsignedp
? unsigned_type_node
: integer_type_node
;
3878 if (mode
== TYPE_MODE (signed_char_type_node
))
3879 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3881 if (mode
== TYPE_MODE (short_integer_type_node
))
3882 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3884 if (mode
== TYPE_MODE (long_integer_type_node
))
3885 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3887 if (mode
== TYPE_MODE (long_long_integer_type_node
))
3888 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3890 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
3891 if (int_n_enabled_p
[i
]
3892 && mode
== int_n_data
[i
].m
)
3893 return (unsignedp
? int_n_trees
[i
].unsigned_type
3894 : int_n_trees
[i
].signed_type
);
3896 if (mode
== TYPE_MODE (widest_integer_literal_type_node
))
3897 return unsignedp
? widest_unsigned_literal_type_node
3898 : widest_integer_literal_type_node
;
3901 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3904 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3907 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3910 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3912 #if HOST_BITS_PER_WIDE_INT >= 64
3913 if (mode
== TYPE_MODE (intTI_type_node
))
3914 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3917 if (mode
== TYPE_MODE (float_type_node
))
3918 return float_type_node
;
3920 if (mode
== TYPE_MODE (double_type_node
))
3921 return double_type_node
;
3923 if (mode
== TYPE_MODE (long_double_type_node
))
3924 return long_double_type_node
;
3926 if (mode
== TYPE_MODE (void_type_node
))
3927 return void_type_node
;
3929 if (mode
== TYPE_MODE (build_pointer_type (char_type_node
)))
3931 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3932 : make_signed_type (GET_MODE_PRECISION (mode
)));
3934 if (mode
== TYPE_MODE (build_pointer_type (integer_type_node
)))
3936 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3937 : make_signed_type (GET_MODE_PRECISION (mode
)));
3939 if (COMPLEX_MODE_P (mode
))
3941 machine_mode inner_mode
;
3944 if (mode
== TYPE_MODE (complex_float_type_node
))
3945 return complex_float_type_node
;
3946 if (mode
== TYPE_MODE (complex_double_type_node
))
3947 return complex_double_type_node
;
3948 if (mode
== TYPE_MODE (complex_long_double_type_node
))
3949 return complex_long_double_type_node
;
3951 if (mode
== TYPE_MODE (complex_integer_type_node
) && !unsignedp
)
3952 return complex_integer_type_node
;
3954 inner_mode
= GET_MODE_INNER (mode
);
3955 inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3956 if (inner_type
!= NULL_TREE
)
3957 return build_complex_type (inner_type
);
3959 else if (VECTOR_MODE_P (mode
))
3961 machine_mode inner_mode
= GET_MODE_INNER (mode
);
3962 tree inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3963 if (inner_type
!= NULL_TREE
)
3964 return build_vector_type_for_mode (inner_type
, mode
);
3967 if (mode
== TYPE_MODE (dfloat32_type_node
))
3968 return dfloat32_type_node
;
3969 if (mode
== TYPE_MODE (dfloat64_type_node
))
3970 return dfloat64_type_node
;
3971 if (mode
== TYPE_MODE (dfloat128_type_node
))
3972 return dfloat128_type_node
;
3974 if (ALL_SCALAR_FIXED_POINT_MODE_P (mode
))
3976 if (mode
== TYPE_MODE (short_fract_type_node
))
3977 return unsignedp
? sat_short_fract_type_node
: short_fract_type_node
;
3978 if (mode
== TYPE_MODE (fract_type_node
))
3979 return unsignedp
? sat_fract_type_node
: fract_type_node
;
3980 if (mode
== TYPE_MODE (long_fract_type_node
))
3981 return unsignedp
? sat_long_fract_type_node
: long_fract_type_node
;
3982 if (mode
== TYPE_MODE (long_long_fract_type_node
))
3983 return unsignedp
? sat_long_long_fract_type_node
3984 : long_long_fract_type_node
;
3986 if (mode
== TYPE_MODE (unsigned_short_fract_type_node
))
3987 return unsignedp
? sat_unsigned_short_fract_type_node
3988 : unsigned_short_fract_type_node
;
3989 if (mode
== TYPE_MODE (unsigned_fract_type_node
))
3990 return unsignedp
? sat_unsigned_fract_type_node
3991 : unsigned_fract_type_node
;
3992 if (mode
== TYPE_MODE (unsigned_long_fract_type_node
))
3993 return unsignedp
? sat_unsigned_long_fract_type_node
3994 : unsigned_long_fract_type_node
;
3995 if (mode
== TYPE_MODE (unsigned_long_long_fract_type_node
))
3996 return unsignedp
? sat_unsigned_long_long_fract_type_node
3997 : unsigned_long_long_fract_type_node
;
3999 if (mode
== TYPE_MODE (short_accum_type_node
))
4000 return unsignedp
? sat_short_accum_type_node
: short_accum_type_node
;
4001 if (mode
== TYPE_MODE (accum_type_node
))
4002 return unsignedp
? sat_accum_type_node
: accum_type_node
;
4003 if (mode
== TYPE_MODE (long_accum_type_node
))
4004 return unsignedp
? sat_long_accum_type_node
: long_accum_type_node
;
4005 if (mode
== TYPE_MODE (long_long_accum_type_node
))
4006 return unsignedp
? sat_long_long_accum_type_node
4007 : long_long_accum_type_node
;
4009 if (mode
== TYPE_MODE (unsigned_short_accum_type_node
))
4010 return unsignedp
? sat_unsigned_short_accum_type_node
4011 : unsigned_short_accum_type_node
;
4012 if (mode
== TYPE_MODE (unsigned_accum_type_node
))
4013 return unsignedp
? sat_unsigned_accum_type_node
4014 : unsigned_accum_type_node
;
4015 if (mode
== TYPE_MODE (unsigned_long_accum_type_node
))
4016 return unsignedp
? sat_unsigned_long_accum_type_node
4017 : unsigned_long_accum_type_node
;
4018 if (mode
== TYPE_MODE (unsigned_long_long_accum_type_node
))
4019 return unsignedp
? sat_unsigned_long_long_accum_type_node
4020 : unsigned_long_long_accum_type_node
;
4023 return unsignedp
? sat_qq_type_node
: qq_type_node
;
4025 return unsignedp
? sat_hq_type_node
: hq_type_node
;
4027 return unsignedp
? sat_sq_type_node
: sq_type_node
;
4029 return unsignedp
? sat_dq_type_node
: dq_type_node
;
4031 return unsignedp
? sat_tq_type_node
: tq_type_node
;
4033 if (mode
== UQQmode
)
4034 return unsignedp
? sat_uqq_type_node
: uqq_type_node
;
4035 if (mode
== UHQmode
)
4036 return unsignedp
? sat_uhq_type_node
: uhq_type_node
;
4037 if (mode
== USQmode
)
4038 return unsignedp
? sat_usq_type_node
: usq_type_node
;
4039 if (mode
== UDQmode
)
4040 return unsignedp
? sat_udq_type_node
: udq_type_node
;
4041 if (mode
== UTQmode
)
4042 return unsignedp
? sat_utq_type_node
: utq_type_node
;
4045 return unsignedp
? sat_ha_type_node
: ha_type_node
;
4047 return unsignedp
? sat_sa_type_node
: sa_type_node
;
4049 return unsignedp
? sat_da_type_node
: da_type_node
;
4051 return unsignedp
? sat_ta_type_node
: ta_type_node
;
4053 if (mode
== UHAmode
)
4054 return unsignedp
? sat_uha_type_node
: uha_type_node
;
4055 if (mode
== USAmode
)
4056 return unsignedp
? sat_usa_type_node
: usa_type_node
;
4057 if (mode
== UDAmode
)
4058 return unsignedp
? sat_uda_type_node
: uda_type_node
;
4059 if (mode
== UTAmode
)
4060 return unsignedp
? sat_uta_type_node
: uta_type_node
;
4063 for (t
= registered_builtin_types
; t
; t
= TREE_CHAIN (t
))
4064 if (TYPE_MODE (TREE_VALUE (t
)) == mode
4065 && !!unsignedp
== !!TYPE_UNSIGNED (TREE_VALUE (t
)))
4066 return TREE_VALUE (t
);
4072 c_common_unsigned_type (tree type
)
4074 return c_common_signed_or_unsigned_type (1, type
);
4077 /* Return a signed type the same as TYPE in other respects. */
4080 c_common_signed_type (tree type
)
4082 return c_common_signed_or_unsigned_type (0, type
);
4085 /* Return a type the same as TYPE except unsigned or
4086 signed according to UNSIGNEDP. */
4089 c_common_signed_or_unsigned_type (int unsignedp
, tree type
)
4094 /* This block of code emulates the behavior of the old
4095 c_common_unsigned_type. In particular, it returns
4096 long_unsigned_type_node if passed a long, even when a int would
4097 have the same size. This is necessary for warnings to work
4098 correctly in archs where sizeof(int) == sizeof(long) */
4100 type1
= TYPE_MAIN_VARIANT (type
);
4101 if (type1
== signed_char_type_node
|| type1
== char_type_node
|| type1
== unsigned_char_type_node
)
4102 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
4103 if (type1
== integer_type_node
|| type1
== unsigned_type_node
)
4104 return unsignedp
? unsigned_type_node
: integer_type_node
;
4105 if (type1
== short_integer_type_node
|| type1
== short_unsigned_type_node
)
4106 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
4107 if (type1
== long_integer_type_node
|| type1
== long_unsigned_type_node
)
4108 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
4109 if (type1
== long_long_integer_type_node
|| type1
== long_long_unsigned_type_node
)
4110 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
4112 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
4113 if (int_n_enabled_p
[i
]
4114 && (type1
== int_n_trees
[i
].unsigned_type
4115 || type1
== int_n_trees
[i
].signed_type
))
4116 return (unsignedp
? int_n_trees
[i
].unsigned_type
4117 : int_n_trees
[i
].signed_type
);
4119 if (type1
== widest_integer_literal_type_node
|| type1
== widest_unsigned_literal_type_node
)
4120 return unsignedp
? widest_unsigned_literal_type_node
: widest_integer_literal_type_node
;
4121 #if HOST_BITS_PER_WIDE_INT >= 64
4122 if (type1
== intTI_type_node
|| type1
== unsigned_intTI_type_node
)
4123 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
4125 if (type1
== intDI_type_node
|| type1
== unsigned_intDI_type_node
)
4126 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
4127 if (type1
== intSI_type_node
|| type1
== unsigned_intSI_type_node
)
4128 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
4129 if (type1
== intHI_type_node
|| type1
== unsigned_intHI_type_node
)
4130 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
4131 if (type1
== intQI_type_node
|| type1
== unsigned_intQI_type_node
)
4132 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
4134 #define C_COMMON_FIXED_TYPES(NAME) \
4135 if (type1 == short_ ## NAME ## _type_node \
4136 || type1 == unsigned_short_ ## NAME ## _type_node) \
4137 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
4138 : short_ ## NAME ## _type_node; \
4139 if (type1 == NAME ## _type_node \
4140 || type1 == unsigned_ ## NAME ## _type_node) \
4141 return unsignedp ? unsigned_ ## NAME ## _type_node \
4142 : NAME ## _type_node; \
4143 if (type1 == long_ ## NAME ## _type_node \
4144 || type1 == unsigned_long_ ## NAME ## _type_node) \
4145 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
4146 : long_ ## NAME ## _type_node; \
4147 if (type1 == long_long_ ## NAME ## _type_node \
4148 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
4149 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
4150 : long_long_ ## NAME ## _type_node;
4152 #define C_COMMON_FIXED_MODE_TYPES(NAME) \
4153 if (type1 == NAME ## _type_node \
4154 || type1 == u ## NAME ## _type_node) \
4155 return unsignedp ? u ## NAME ## _type_node \
4156 : NAME ## _type_node;
4158 #define C_COMMON_FIXED_TYPES_SAT(NAME) \
4159 if (type1 == sat_ ## short_ ## NAME ## _type_node \
4160 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
4161 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
4162 : sat_ ## short_ ## NAME ## _type_node; \
4163 if (type1 == sat_ ## NAME ## _type_node \
4164 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
4165 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
4166 : sat_ ## NAME ## _type_node; \
4167 if (type1 == sat_ ## long_ ## NAME ## _type_node \
4168 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
4169 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
4170 : sat_ ## long_ ## NAME ## _type_node; \
4171 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
4172 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
4173 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
4174 : sat_ ## long_long_ ## NAME ## _type_node;
4176 #define C_COMMON_FIXED_MODE_TYPES_SAT(NAME) \
4177 if (type1 == sat_ ## NAME ## _type_node \
4178 || type1 == sat_ ## u ## NAME ## _type_node) \
4179 return unsignedp ? sat_ ## u ## NAME ## _type_node \
4180 : sat_ ## NAME ## _type_node;
4182 C_COMMON_FIXED_TYPES (fract
);
4183 C_COMMON_FIXED_TYPES_SAT (fract
);
4184 C_COMMON_FIXED_TYPES (accum
);
4185 C_COMMON_FIXED_TYPES_SAT (accum
);
4187 C_COMMON_FIXED_MODE_TYPES (qq
);
4188 C_COMMON_FIXED_MODE_TYPES (hq
);
4189 C_COMMON_FIXED_MODE_TYPES (sq
);
4190 C_COMMON_FIXED_MODE_TYPES (dq
);
4191 C_COMMON_FIXED_MODE_TYPES (tq
);
4192 C_COMMON_FIXED_MODE_TYPES_SAT (qq
);
4193 C_COMMON_FIXED_MODE_TYPES_SAT (hq
);
4194 C_COMMON_FIXED_MODE_TYPES_SAT (sq
);
4195 C_COMMON_FIXED_MODE_TYPES_SAT (dq
);
4196 C_COMMON_FIXED_MODE_TYPES_SAT (tq
);
4197 C_COMMON_FIXED_MODE_TYPES (ha
);
4198 C_COMMON_FIXED_MODE_TYPES (sa
);
4199 C_COMMON_FIXED_MODE_TYPES (da
);
4200 C_COMMON_FIXED_MODE_TYPES (ta
);
4201 C_COMMON_FIXED_MODE_TYPES_SAT (ha
);
4202 C_COMMON_FIXED_MODE_TYPES_SAT (sa
);
4203 C_COMMON_FIXED_MODE_TYPES_SAT (da
);
4204 C_COMMON_FIXED_MODE_TYPES_SAT (ta
);
4206 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
4207 the precision; they have precision set to match their range, but
4208 may use a wider mode to match an ABI. If we change modes, we may
4209 wind up with bad conversions. For INTEGER_TYPEs in C, must check
4210 the precision as well, so as to yield correct results for
4211 bit-field types. C++ does not have these separate bit-field
4212 types, and producing a signed or unsigned variant of an
4213 ENUMERAL_TYPE may cause other problems as well. */
4215 if (!INTEGRAL_TYPE_P (type
)
4216 || TYPE_UNSIGNED (type
) == unsignedp
)
4219 #define TYPE_OK(node) \
4220 (TYPE_MODE (type) == TYPE_MODE (node) \
4221 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
4222 if (TYPE_OK (signed_char_type_node
))
4223 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
4224 if (TYPE_OK (integer_type_node
))
4225 return unsignedp
? unsigned_type_node
: integer_type_node
;
4226 if (TYPE_OK (short_integer_type_node
))
4227 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
4228 if (TYPE_OK (long_integer_type_node
))
4229 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
4230 if (TYPE_OK (long_long_integer_type_node
))
4231 return (unsignedp
? long_long_unsigned_type_node
4232 : long_long_integer_type_node
);
4234 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
4235 if (int_n_enabled_p
[i
]
4236 && TYPE_MODE (type
) == int_n_data
[i
].m
4237 && TYPE_PRECISION (type
) == int_n_data
[i
].bitsize
)
4238 return (unsignedp
? int_n_trees
[i
].unsigned_type
4239 : int_n_trees
[i
].signed_type
);
4241 if (TYPE_OK (widest_integer_literal_type_node
))
4242 return (unsignedp
? widest_unsigned_literal_type_node
4243 : widest_integer_literal_type_node
);
4245 #if HOST_BITS_PER_WIDE_INT >= 64
4246 if (TYPE_OK (intTI_type_node
))
4247 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
4249 if (TYPE_OK (intDI_type_node
))
4250 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
4251 if (TYPE_OK (intSI_type_node
))
4252 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
4253 if (TYPE_OK (intHI_type_node
))
4254 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
4255 if (TYPE_OK (intQI_type_node
))
4256 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
4259 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
4262 /* Build a bit-field integer type for the given WIDTH and UNSIGNEDP. */
4265 c_build_bitfield_integer_type (unsigned HOST_WIDE_INT width
, int unsignedp
)
4269 /* Extended integer types of the same width as a standard type have
4270 lesser rank, so those of the same width as int promote to int or
4271 unsigned int and are valid for printf formats expecting int or
4272 unsigned int. To avoid such special cases, avoid creating
4273 extended integer types for bit-fields if a standard integer type
4275 if (width
== TYPE_PRECISION (integer_type_node
))
4276 return unsignedp
? unsigned_type_node
: integer_type_node
;
4277 if (width
== TYPE_PRECISION (signed_char_type_node
))
4278 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
4279 if (width
== TYPE_PRECISION (short_integer_type_node
))
4280 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
4281 if (width
== TYPE_PRECISION (long_integer_type_node
))
4282 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
4283 if (width
== TYPE_PRECISION (long_long_integer_type_node
))
4284 return (unsignedp
? long_long_unsigned_type_node
4285 : long_long_integer_type_node
);
4286 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
4287 if (int_n_enabled_p
[i
]
4288 && width
== int_n_data
[i
].bitsize
)
4289 return (unsignedp
? int_n_trees
[i
].unsigned_type
4290 : int_n_trees
[i
].signed_type
);
4291 return build_nonstandard_integer_type (width
, unsignedp
);
4294 /* The C version of the register_builtin_type langhook. */
4297 c_register_builtin_type (tree type
, const char* name
)
4301 decl
= build_decl (UNKNOWN_LOCATION
,
4302 TYPE_DECL
, get_identifier (name
), type
);
4303 DECL_ARTIFICIAL (decl
) = 1;
4304 if (!TYPE_NAME (type
))
4305 TYPE_NAME (type
) = decl
;
4308 registered_builtin_types
= tree_cons (0, type
, registered_builtin_types
);
4311 /* Print an error message for invalid operands to arith operation
4312 CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
4313 LOCATION is the location of the message. */
4316 binary_op_error (location_t location
, enum tree_code code
,
4317 tree type0
, tree type1
)
4324 opname
= "+"; break;
4326 opname
= "-"; break;
4328 opname
= "*"; break;
4330 opname
= "max"; break;
4332 opname
= "min"; break;
4334 opname
= "=="; break;
4336 opname
= "!="; break;
4338 opname
= "<="; break;
4340 opname
= ">="; break;
4342 opname
= "<"; break;
4344 opname
= ">"; break;
4346 opname
= "<<"; break;
4348 opname
= ">>"; break;
4349 case TRUNC_MOD_EXPR
:
4350 case FLOOR_MOD_EXPR
:
4351 opname
= "%"; break;
4352 case TRUNC_DIV_EXPR
:
4353 case FLOOR_DIV_EXPR
:
4354 opname
= "/"; break;
4356 opname
= "&"; break;
4358 opname
= "|"; break;
4359 case TRUTH_ANDIF_EXPR
:
4360 opname
= "&&"; break;
4361 case TRUTH_ORIF_EXPR
:
4362 opname
= "||"; break;
4364 opname
= "^"; break;
4369 "invalid operands to binary %s (have %qT and %qT)", opname
,
4373 /* Given an expression as a tree, return its original type. Do this
4374 by stripping any conversion that preserves the sign and precision. */
4376 expr_original_type (tree expr
)
4378 STRIP_SIGN_NOPS (expr
);
4379 return TREE_TYPE (expr
);
4382 /* Subroutine of build_binary_op, used for comparison operations.
4383 See if the operands have both been converted from subword integer types
4384 and, if so, perhaps change them both back to their original type.
4385 This function is also responsible for converting the two operands
4386 to the proper common type for comparison.
4388 The arguments of this function are all pointers to local variables
4389 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
4390 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
4392 LOC is the location of the comparison.
4394 If this function returns nonzero, it means that the comparison has
4395 a constant value. What this function returns is an expression for
4399 shorten_compare (location_t loc
, tree
*op0_ptr
, tree
*op1_ptr
,
4400 tree
*restype_ptr
, enum tree_code
*rescode_ptr
)
4403 tree op0
= *op0_ptr
;
4404 tree op1
= *op1_ptr
;
4405 int unsignedp0
, unsignedp1
;
4407 tree primop0
, primop1
;
4408 enum tree_code code
= *rescode_ptr
;
4410 /* Throw away any conversions to wider types
4411 already present in the operands. */
4413 primop0
= c_common_get_narrower (op0
, &unsignedp0
);
4414 primop1
= c_common_get_narrower (op1
, &unsignedp1
);
4416 /* If primopN is first sign-extended from primopN's precision to opN's
4417 precision, then zero-extended from opN's precision to
4418 *restype_ptr precision, shortenings might be invalid. */
4419 if (TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (TREE_TYPE (op0
))
4420 && TYPE_PRECISION (TREE_TYPE (op0
)) < TYPE_PRECISION (*restype_ptr
)
4422 && TYPE_UNSIGNED (TREE_TYPE (op0
)))
4424 if (TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (TREE_TYPE (op1
))
4425 && TYPE_PRECISION (TREE_TYPE (op1
)) < TYPE_PRECISION (*restype_ptr
)
4427 && TYPE_UNSIGNED (TREE_TYPE (op1
)))
4430 /* Handle the case that OP0 does not *contain* a conversion
4431 but it *requires* conversion to FINAL_TYPE. */
4433 if (op0
== primop0
&& TREE_TYPE (op0
) != *restype_ptr
)
4434 unsignedp0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
4435 if (op1
== primop1
&& TREE_TYPE (op1
) != *restype_ptr
)
4436 unsignedp1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
4438 /* If one of the operands must be floated, we cannot optimize. */
4439 real1
= TREE_CODE (TREE_TYPE (primop0
)) == REAL_TYPE
;
4440 real2
= TREE_CODE (TREE_TYPE (primop1
)) == REAL_TYPE
;
4442 /* If first arg is constant, swap the args (changing operation
4443 so value is preserved), for canonicalization. Don't do this if
4444 the second arg is 0. */
4446 if (TREE_CONSTANT (primop0
)
4447 && !integer_zerop (primop1
) && !real_zerop (primop1
)
4448 && !fixed_zerop (primop1
))
4450 std::swap (primop0
, primop1
);
4451 std::swap (op0
, op1
);
4454 std::swap (unsignedp0
, unsignedp1
);
4455 std::swap (real1
, real2
);
4474 *rescode_ptr
= code
;
4477 /* If comparing an integer against a constant more bits wide,
4478 maybe we can deduce a value of 1 or 0 independent of the data.
4479 Or else truncate the constant now
4480 rather than extend the variable at run time.
4482 This is only interesting if the constant is the wider arg.
4483 Also, it is not safe if the constant is unsigned and the
4484 variable arg is signed, since in this case the variable
4485 would be sign-extended and then regarded as unsigned.
4486 Our technique fails in this case because the lowest/highest
4487 possible unsigned results don't follow naturally from the
4488 lowest/highest possible values of the variable operand.
4489 For just EQ_EXPR and NE_EXPR there is another technique that
4490 could be used: see if the constant can be faithfully represented
4491 in the other operand's type, by truncating it and reextending it
4492 and see if that preserves the constant's value. */
4494 if (!real1
&& !real2
4495 && TREE_CODE (TREE_TYPE (primop0
)) != FIXED_POINT_TYPE
4496 && TREE_CODE (primop1
) == INTEGER_CST
4497 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
))
4499 int min_gt
, max_gt
, min_lt
, max_lt
;
4500 tree maxval
, minval
;
4501 /* 1 if comparison is nominally unsigned. */
4502 int unsignedp
= TYPE_UNSIGNED (*restype_ptr
);
4505 type
= c_common_signed_or_unsigned_type (unsignedp0
,
4506 TREE_TYPE (primop0
));
4508 maxval
= TYPE_MAX_VALUE (type
);
4509 minval
= TYPE_MIN_VALUE (type
);
4511 if (unsignedp
&& !unsignedp0
)
4512 *restype_ptr
= c_common_signed_type (*restype_ptr
);
4514 if (TREE_TYPE (primop1
) != *restype_ptr
)
4516 /* Convert primop1 to target type, but do not introduce
4517 additional overflow. We know primop1 is an int_cst. */
4518 primop1
= force_fit_type (*restype_ptr
,
4521 TYPE_PRECISION (*restype_ptr
),
4522 TYPE_SIGN (TREE_TYPE (primop1
))),
4523 0, TREE_OVERFLOW (primop1
));
4525 if (type
!= *restype_ptr
)
4527 minval
= convert (*restype_ptr
, minval
);
4528 maxval
= convert (*restype_ptr
, maxval
);
4531 min_gt
= tree_int_cst_lt (primop1
, minval
);
4532 max_gt
= tree_int_cst_lt (primop1
, maxval
);
4533 min_lt
= tree_int_cst_lt (minval
, primop1
);
4534 max_lt
= tree_int_cst_lt (maxval
, primop1
);
4537 /* This used to be a switch, but Genix compiler can't handle that. */
4538 if (code
== NE_EXPR
)
4540 if (max_lt
|| min_gt
)
4541 val
= truthvalue_true_node
;
4543 else if (code
== EQ_EXPR
)
4545 if (max_lt
|| min_gt
)
4546 val
= truthvalue_false_node
;
4548 else if (code
== LT_EXPR
)
4551 val
= truthvalue_true_node
;
4553 val
= truthvalue_false_node
;
4555 else if (code
== GT_EXPR
)
4558 val
= truthvalue_true_node
;
4560 val
= truthvalue_false_node
;
4562 else if (code
== LE_EXPR
)
4565 val
= truthvalue_true_node
;
4567 val
= truthvalue_false_node
;
4569 else if (code
== GE_EXPR
)
4572 val
= truthvalue_true_node
;
4574 val
= truthvalue_false_node
;
4577 /* If primop0 was sign-extended and unsigned comparison specd,
4578 we did a signed comparison above using the signed type bounds.
4579 But the comparison we output must be unsigned.
4581 Also, for inequalities, VAL is no good; but if the signed
4582 comparison had *any* fixed result, it follows that the
4583 unsigned comparison just tests the sign in reverse
4584 (positive values are LE, negative ones GE).
4585 So we can generate an unsigned comparison
4586 against an extreme value of the signed type. */
4588 if (unsignedp
&& !unsignedp0
)
4595 primop1
= TYPE_MIN_VALUE (type
);
4601 primop1
= TYPE_MAX_VALUE (type
);
4608 type
= c_common_unsigned_type (type
);
4611 if (TREE_CODE (primop0
) != INTEGER_CST
)
4613 if (val
== truthvalue_false_node
)
4614 warning_at (loc
, OPT_Wtype_limits
,
4615 "comparison is always false due to limited range of data type");
4616 if (val
== truthvalue_true_node
)
4617 warning_at (loc
, OPT_Wtype_limits
,
4618 "comparison is always true due to limited range of data type");
4623 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4624 if (TREE_SIDE_EFFECTS (primop0
))
4625 return build2 (COMPOUND_EXPR
, TREE_TYPE (val
), primop0
, val
);
4629 /* Value is not predetermined, but do the comparison
4630 in the type of the operand that is not constant.
4631 TYPE is already properly set. */
4634 /* If either arg is decimal float and the other is float, find the
4635 proper common type to use for comparison. */
4636 else if (real1
&& real2
4637 && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0
)))
4638 && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1
))))
4639 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
4641 /* If either arg is decimal float and the other is float, fail. */
4642 else if (real1
&& real2
4643 && (DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0
)))
4644 || DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1
)))))
4647 else if (real1
&& real2
4648 && (TYPE_PRECISION (TREE_TYPE (primop0
))
4649 == TYPE_PRECISION (TREE_TYPE (primop1
))))
4650 type
= TREE_TYPE (primop0
);
4652 /* If args' natural types are both narrower than nominal type
4653 and both extend in the same manner, compare them
4654 in the type of the wider arg.
4655 Otherwise must actually extend both to the nominal
4656 common type lest different ways of extending
4658 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
4660 else if (unsignedp0
== unsignedp1
&& real1
== real2
4661 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
)
4662 && TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (*restype_ptr
))
4664 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
4665 type
= c_common_signed_or_unsigned_type (unsignedp0
4666 || TYPE_UNSIGNED (*restype_ptr
),
4668 /* Make sure shorter operand is extended the right way
4669 to match the longer operand. */
4671 = convert (c_common_signed_or_unsigned_type (unsignedp0
,
4672 TREE_TYPE (primop0
)),
4675 = convert (c_common_signed_or_unsigned_type (unsignedp1
,
4676 TREE_TYPE (primop1
)),
4681 /* Here we must do the comparison on the nominal type
4682 using the args exactly as we received them. */
4683 type
= *restype_ptr
;
4687 if (!real1
&& !real2
&& integer_zerop (primop1
)
4688 && TYPE_UNSIGNED (*restype_ptr
))
4691 /* All unsigned values are >= 0, so we warn. However,
4692 if OP0 is a constant that is >= 0, the signedness of
4693 the comparison isn't an issue, so suppress the
4696 warn_type_limits
&& !in_system_header_at (loc
)
4697 && !(TREE_CODE (primop0
) == INTEGER_CST
4698 && !TREE_OVERFLOW (convert (c_common_signed_type (type
),
4700 /* Do not warn for enumeration types. */
4701 && (TREE_CODE (expr_original_type (primop0
)) != ENUMERAL_TYPE
);
4707 warning_at (loc
, OPT_Wtype_limits
,
4708 "comparison of unsigned expression >= 0 is always true");
4709 value
= truthvalue_true_node
;
4714 warning_at (loc
, OPT_Wtype_limits
,
4715 "comparison of unsigned expression < 0 is always false");
4716 value
= truthvalue_false_node
;
4725 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4726 if (TREE_SIDE_EFFECTS (primop0
))
4727 return build2 (COMPOUND_EXPR
, TREE_TYPE (value
),
4734 *op0_ptr
= convert (type
, primop0
);
4735 *op1_ptr
= convert (type
, primop1
);
4737 *restype_ptr
= truthvalue_type_node
;
4742 /* Return a tree for the sum or difference (RESULTCODE says which)
4743 of pointer PTROP and integer INTOP. */
4746 pointer_int_sum (location_t loc
, enum tree_code resultcode
,
4747 tree ptrop
, tree intop
, bool complain
)
4751 /* The result is a pointer of the same type that is being added. */
4752 tree result_type
= TREE_TYPE (ptrop
);
4754 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
4756 if (complain
&& warn_pointer_arith
)
4757 pedwarn (loc
, OPT_Wpointer_arith
,
4758 "pointer of type %<void *%> used in arithmetic");
4760 return error_mark_node
;
4761 size_exp
= integer_one_node
;
4763 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
4765 if (complain
&& warn_pointer_arith
)
4766 pedwarn (loc
, OPT_Wpointer_arith
,
4767 "pointer to a function used in arithmetic");
4769 return error_mark_node
;
4770 size_exp
= integer_one_node
;
4773 size_exp
= size_in_bytes (TREE_TYPE (result_type
));
4775 /* We are manipulating pointer values, so we don't need to warn
4776 about relying on undefined signed overflow. We disable the
4777 warning here because we use integer types so fold won't know that
4778 they are really pointers. */
4779 fold_defer_overflow_warnings ();
4781 /* If what we are about to multiply by the size of the elements
4782 contains a constant term, apply distributive law
4783 and multiply that constant term separately.
4784 This helps produce common subexpressions. */
4785 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
4786 && !TREE_CONSTANT (intop
)
4787 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
4788 && TREE_CONSTANT (size_exp
)
4789 /* If the constant comes from pointer subtraction,
4790 skip this optimization--it would cause an error. */
4791 && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop
, 0))) == INTEGER_TYPE
4792 /* If the constant is unsigned, and smaller than the pointer size,
4793 then we must skip this optimization. This is because it could cause
4794 an overflow error if the constant is negative but INTOP is not. */
4795 && (!TYPE_UNSIGNED (TREE_TYPE (intop
))
4796 || (TYPE_PRECISION (TREE_TYPE (intop
))
4797 == TYPE_PRECISION (TREE_TYPE (ptrop
)))))
4799 enum tree_code subcode
= resultcode
;
4800 tree int_type
= TREE_TYPE (intop
);
4801 if (TREE_CODE (intop
) == MINUS_EXPR
)
4802 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
4803 /* Convert both subexpression types to the type of intop,
4804 because weird cases involving pointer arithmetic
4805 can result in a sum or difference with different type args. */
4806 ptrop
= build_binary_op (EXPR_LOCATION (TREE_OPERAND (intop
, 1)),
4808 convert (int_type
, TREE_OPERAND (intop
, 1)), 1);
4809 intop
= convert (int_type
, TREE_OPERAND (intop
, 0));
4812 /* Convert the integer argument to a type the same size as sizetype
4813 so the multiply won't overflow spuriously. */
4814 if (TYPE_PRECISION (TREE_TYPE (intop
)) != TYPE_PRECISION (sizetype
)
4815 || TYPE_UNSIGNED (TREE_TYPE (intop
)) != TYPE_UNSIGNED (sizetype
))
4816 intop
= convert (c_common_type_for_size (TYPE_PRECISION (sizetype
),
4817 TYPE_UNSIGNED (sizetype
)), intop
);
4819 /* Replace the integer argument with a suitable product by the object size.
4820 Do this multiplication as signed, then convert to the appropriate type
4821 for the pointer operation and disregard an overflow that occurred only
4822 because of the sign-extension change in the latter conversion. */
4824 tree t
= build_binary_op (loc
,
4826 convert (TREE_TYPE (intop
), size_exp
), 1);
4827 intop
= convert (sizetype
, t
);
4828 if (TREE_OVERFLOW_P (intop
) && !TREE_OVERFLOW (t
))
4829 intop
= wide_int_to_tree (TREE_TYPE (intop
), intop
);
4832 /* Create the sum or difference. */
4833 if (resultcode
== MINUS_EXPR
)
4834 intop
= fold_build1_loc (loc
, NEGATE_EXPR
, sizetype
, intop
);
4836 ret
= fold_build_pointer_plus_loc (loc
, ptrop
, intop
);
4838 fold_undefer_and_ignore_overflow_warnings ();
4843 /* Wrap a C_MAYBE_CONST_EXPR around an expression that is fully folded
4844 and if NON_CONST is known not to be permitted in an evaluated part
4845 of a constant expression. */
4848 c_wrap_maybe_const (tree expr
, bool non_const
)
4850 bool nowarning
= TREE_NO_WARNING (expr
);
4851 location_t loc
= EXPR_LOCATION (expr
);
4853 /* This should never be called for C++. */
4854 if (c_dialect_cxx ())
4857 /* The result of folding may have a NOP_EXPR to set TREE_NO_WARNING. */
4858 STRIP_TYPE_NOPS (expr
);
4859 expr
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (expr
), NULL
, expr
);
4860 C_MAYBE_CONST_EXPR_NON_CONST (expr
) = non_const
;
4862 TREE_NO_WARNING (expr
) = 1;
4863 protected_set_expr_location (expr
, loc
);
4868 /* Wrap a SAVE_EXPR around EXPR, if appropriate. Like save_expr, but
4869 for C folds the inside expression and wraps a C_MAYBE_CONST_EXPR
4870 around the SAVE_EXPR if needed so that c_fully_fold does not need
4871 to look inside SAVE_EXPRs. */
4874 c_save_expr (tree expr
)
4876 bool maybe_const
= true;
4877 if (c_dialect_cxx ())
4878 return save_expr (expr
);
4879 expr
= c_fully_fold (expr
, false, &maybe_const
);
4880 expr
= save_expr (expr
);
4882 expr
= c_wrap_maybe_const (expr
, true);
4886 /* Return whether EXPR is a declaration whose address can never be
4890 decl_with_nonnull_addr_p (const_tree expr
)
4892 return (DECL_P (expr
)
4893 && (TREE_CODE (expr
) == PARM_DECL
4894 || TREE_CODE (expr
) == LABEL_DECL
4895 || !DECL_WEAK (expr
)));
4898 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
4899 or for an `if' or `while' statement or ?..: exp. It should already
4900 have been validated to be of suitable type; otherwise, a bad
4901 diagnostic may result.
4903 The EXPR is located at LOCATION.
4905 This preparation consists of taking the ordinary
4906 representation of an expression expr and producing a valid tree
4907 boolean expression describing whether expr is nonzero. We could
4908 simply always do build_binary_op (NE_EXPR, expr, truthvalue_false_node, 1),
4909 but we optimize comparisons, &&, ||, and !.
4911 The resulting type should always be `truthvalue_type_node'. */
4914 c_common_truthvalue_conversion (location_t location
, tree expr
)
4916 switch (TREE_CODE (expr
))
4918 case EQ_EXPR
: case NE_EXPR
: case UNEQ_EXPR
: case LTGT_EXPR
:
4919 case LE_EXPR
: case GE_EXPR
: case LT_EXPR
: case GT_EXPR
:
4920 case UNLE_EXPR
: case UNGE_EXPR
: case UNLT_EXPR
: case UNGT_EXPR
:
4921 case ORDERED_EXPR
: case UNORDERED_EXPR
:
4922 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4924 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4925 TREE_OPERAND (expr
, 0), TREE_OPERAND (expr
, 1));
4928 case TRUTH_ANDIF_EXPR
:
4929 case TRUTH_ORIF_EXPR
:
4930 case TRUTH_AND_EXPR
:
4932 case TRUTH_XOR_EXPR
:
4933 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4935 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4936 c_common_truthvalue_conversion (location
,
4937 TREE_OPERAND (expr
, 0)),
4938 c_common_truthvalue_conversion (location
,
4939 TREE_OPERAND (expr
, 1)));
4942 case TRUTH_NOT_EXPR
:
4943 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4945 expr
= build1 (TREE_CODE (expr
), truthvalue_type_node
,
4946 c_common_truthvalue_conversion (location
,
4947 TREE_OPERAND (expr
, 0)));
4954 return integer_zerop (expr
) ? truthvalue_false_node
4955 : truthvalue_true_node
;
4958 return real_compare (NE_EXPR
, &TREE_REAL_CST (expr
), &dconst0
)
4959 ? truthvalue_true_node
4960 : truthvalue_false_node
;
4963 return fixed_compare (NE_EXPR
, &TREE_FIXED_CST (expr
),
4964 &FCONST0 (TYPE_MODE (TREE_TYPE (expr
))))
4965 ? truthvalue_true_node
4966 : truthvalue_false_node
;
4969 expr
= build_unary_op (location
, ADDR_EXPR
, expr
, 0);
4974 tree inner
= TREE_OPERAND (expr
, 0);
4975 if (decl_with_nonnull_addr_p (inner
))
4977 /* Common Ada/Pascal programmer's mistake. */
4978 warning_at (location
,
4980 "the address of %qD will always evaluate as %<true%>",
4982 return truthvalue_true_node
;
4988 expr
= build_binary_op (EXPR_LOCATION (expr
),
4989 (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1))
4990 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4991 c_common_truthvalue_conversion (location
,
4992 TREE_OPERAND (expr
, 0)),
4993 c_common_truthvalue_conversion (location
,
4994 TREE_OPERAND (expr
, 1)),
5001 case EXCESS_PRECISION_EXPR
:
5002 /* These don't change whether an object is nonzero or zero. */
5003 return c_common_truthvalue_conversion (location
, TREE_OPERAND (expr
, 0));
5007 /* These don't change whether an object is zero or nonzero, but
5008 we can't ignore them if their second arg has side-effects. */
5009 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1)))
5011 expr
= build2 (COMPOUND_EXPR
, truthvalue_type_node
,
5012 TREE_OPERAND (expr
, 1),
5013 c_common_truthvalue_conversion
5014 (location
, TREE_OPERAND (expr
, 0)));
5018 return c_common_truthvalue_conversion (location
,
5019 TREE_OPERAND (expr
, 0));
5022 /* Distribute the conversion into the arms of a COND_EXPR. */
5023 if (c_dialect_cxx ())
5025 tree op1
= TREE_OPERAND (expr
, 1);
5026 tree op2
= TREE_OPERAND (expr
, 2);
5027 /* In C++ one of the arms might have void type if it is throw. */
5028 if (!VOID_TYPE_P (TREE_TYPE (op1
)))
5029 op1
= c_common_truthvalue_conversion (location
, op1
);
5030 if (!VOID_TYPE_P (TREE_TYPE (op2
)))
5031 op2
= c_common_truthvalue_conversion (location
, op2
);
5032 expr
= fold_build3_loc (location
, COND_EXPR
, truthvalue_type_node
,
5033 TREE_OPERAND (expr
, 0), op1
, op2
);
5038 /* Folding will happen later for C. */
5039 expr
= build3 (COND_EXPR
, truthvalue_type_node
,
5040 TREE_OPERAND (expr
, 0),
5041 c_common_truthvalue_conversion (location
,
5042 TREE_OPERAND (expr
, 1)),
5043 c_common_truthvalue_conversion (location
,
5044 TREE_OPERAND (expr
, 2)));
5050 tree totype
= TREE_TYPE (expr
);
5051 tree fromtype
= TREE_TYPE (TREE_OPERAND (expr
, 0));
5053 if (POINTER_TYPE_P (totype
)
5054 && TREE_CODE (fromtype
) == REFERENCE_TYPE
)
5060 warning_at (location
,
5062 "the compiler can assume that the address of "
5063 "%qD will always evaluate to %<true%>",
5067 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
5068 since that affects how `default_conversion' will behave. */
5069 if (TREE_CODE (totype
) == REFERENCE_TYPE
5070 || TREE_CODE (fromtype
) == REFERENCE_TYPE
)
5072 /* Don't strip a conversion from C++0x scoped enum, since they
5073 don't implicitly convert to other types. */
5074 if (TREE_CODE (fromtype
) == ENUMERAL_TYPE
5075 && ENUM_IS_SCOPED (fromtype
))
5077 /* If this isn't narrowing the argument, we can ignore it. */
5078 if (TYPE_PRECISION (totype
) >= TYPE_PRECISION (fromtype
))
5079 return c_common_truthvalue_conversion (location
,
5080 TREE_OPERAND (expr
, 0));
5085 if (!TREE_NO_WARNING (expr
)
5086 && warn_parentheses
)
5088 warning (OPT_Wparentheses
,
5089 "suggest parentheses around assignment used as truth value");
5090 TREE_NO_WARNING (expr
) = 1;
5098 if (TREE_CODE (TREE_TYPE (expr
)) == COMPLEX_TYPE
)
5100 tree t
= (in_late_binary_op
? save_expr (expr
) : c_save_expr (expr
));
5101 expr
= (build_binary_op
5102 (EXPR_LOCATION (expr
),
5103 (TREE_SIDE_EFFECTS (expr
)
5104 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
5105 c_common_truthvalue_conversion
5107 build_unary_op (location
, REALPART_EXPR
, t
, 0)),
5108 c_common_truthvalue_conversion
5110 build_unary_op (location
, IMAGPART_EXPR
, t
, 0)),
5115 if (TREE_CODE (TREE_TYPE (expr
)) == FIXED_POINT_TYPE
)
5117 tree fixed_zero_node
= build_fixed (TREE_TYPE (expr
),
5119 (TREE_TYPE (expr
))));
5120 return build_binary_op (location
, NE_EXPR
, expr
, fixed_zero_node
, 1);
5123 return build_binary_op (location
, NE_EXPR
, expr
, integer_zero_node
, 1);
5126 protected_set_expr_location (expr
, location
);
5130 static void def_builtin_1 (enum built_in_function fncode
,
5132 enum built_in_class fnclass
,
5133 tree fntype
, tree libtype
,
5134 bool both_p
, bool fallback_p
, bool nonansi_p
,
5135 tree fnattrs
, bool implicit_p
);
5138 /* Apply the TYPE_QUALS to the new DECL. */
5141 c_apply_type_quals_to_decl (int type_quals
, tree decl
)
5143 tree type
= TREE_TYPE (decl
);
5145 if (type
== error_mark_node
)
5148 if ((type_quals
& TYPE_QUAL_CONST
)
5149 || (type
&& TREE_CODE (type
) == REFERENCE_TYPE
))
5150 /* We used to check TYPE_NEEDS_CONSTRUCTING here, but now a constexpr
5151 constructor can produce constant init, so rely on cp_finish_decl to
5152 clear TREE_READONLY if the variable has non-constant init. */
5153 TREE_READONLY (decl
) = 1;
5154 if (type_quals
& TYPE_QUAL_VOLATILE
)
5156 TREE_SIDE_EFFECTS (decl
) = 1;
5157 TREE_THIS_VOLATILE (decl
) = 1;
5159 if (type_quals
& TYPE_QUAL_RESTRICT
)
5161 while (type
&& TREE_CODE (type
) == ARRAY_TYPE
)
5162 /* Allow 'restrict' on arrays of pointers.
5163 FIXME currently we just ignore it. */
5164 type
= TREE_TYPE (type
);
5166 || !POINTER_TYPE_P (type
)
5167 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type
)))
5168 error ("invalid use of %<restrict%>");
5172 struct c_type_hasher
: ggc_ptr_hash
<tree_node
>
5174 static hashval_t
hash (tree
);
5175 static bool equal (tree
, tree
);
5178 /* Hash function for the problem of multiple type definitions in
5179 different files. This must hash all types that will compare
5180 equal via comptypes to the same value. In practice it hashes
5181 on some of the simple stuff and leaves the details to comptypes. */
5184 c_type_hasher::hash (tree t
)
5189 switch (TREE_CODE (t
))
5191 /* For pointers, hash on pointee type plus some swizzling. */
5193 return hash (TREE_TYPE (t
)) ^ 0x3003003;
5194 /* Hash on number of elements and total size. */
5197 t2
= TYPE_VALUES (t
);
5201 t2
= TYPE_FIELDS (t
);
5203 case QUAL_UNION_TYPE
:
5205 t2
= TYPE_FIELDS (t
);
5209 t2
= TYPE_FIELDS (t
);
5214 /* FIXME: We want to use a DECL_CHAIN iteration method here, but
5215 TYPE_VALUES of ENUMERAL_TYPEs is stored as a TREE_LIST. */
5216 n_elements
= list_length (t2
);
5217 /* We might have a VLA here. */
5218 if (TREE_CODE (TYPE_SIZE (t
)) != INTEGER_CST
)
5221 size
= TREE_INT_CST_LOW (TYPE_SIZE (t
));
5222 return ((size
<< 24) | (n_elements
<< shift
));
5226 c_type_hasher::equal (tree t1
, tree t2
)
5228 return lang_hooks
.types_compatible_p (t1
, t2
);
5231 static GTY(()) hash_table
<c_type_hasher
> *type_hash_table
;
5233 /* Return the typed-based alias set for T, which may be an expression
5234 or a type. Return -1 if we don't do anything special. */
5237 c_common_get_alias_set (tree t
)
5241 /* For VLAs, use the alias set of the element type rather than the
5242 default of alias set 0 for types compared structurally. */
5243 if (TYPE_P (t
) && TYPE_STRUCTURAL_EQUALITY_P (t
))
5245 if (TREE_CODE (t
) == ARRAY_TYPE
)
5246 return get_alias_set (TREE_TYPE (t
));
5250 /* Permit type-punning when accessing a union, provided the access
5251 is directly through the union. For example, this code does not
5252 permit taking the address of a union member and then storing
5253 through it. Even the type-punning allowed here is a GCC
5254 extension, albeit a common and useful one; the C standard says
5255 that such accesses have implementation-defined behavior. */
5257 TREE_CODE (u
) == COMPONENT_REF
|| TREE_CODE (u
) == ARRAY_REF
;
5258 u
= TREE_OPERAND (u
, 0))
5259 if (TREE_CODE (u
) == COMPONENT_REF
5260 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u
, 0))) == UNION_TYPE
)
5263 /* That's all the expressions we handle specially. */
5267 /* The C standard guarantees that any object may be accessed via an
5268 lvalue that has character type. */
5269 if (t
== char_type_node
5270 || t
== signed_char_type_node
5271 || t
== unsigned_char_type_node
)
5274 /* The C standard specifically allows aliasing between signed and
5275 unsigned variants of the same type. We treat the signed
5276 variant as canonical. */
5277 if (TREE_CODE (t
) == INTEGER_TYPE
&& TYPE_UNSIGNED (t
))
5279 tree t1
= c_common_signed_type (t
);
5281 /* t1 == t can happen for boolean nodes which are always unsigned. */
5283 return get_alias_set (t1
);
5286 /* Handle the case of multiple type nodes referring to "the same" type,
5287 which occurs with IMA. These share an alias set. FIXME: Currently only
5288 C90 is handled. (In C99 type compatibility is not transitive, which
5289 complicates things mightily. The alias set splay trees can theoretically
5290 represent this, but insertion is tricky when you consider all the
5291 different orders things might arrive in.) */
5293 if (c_language
!= clk_c
|| flag_isoc99
)
5296 /* Save time if there's only one input file. */
5297 if (num_in_fnames
== 1)
5300 /* Pointers need special handling if they point to any type that
5301 needs special handling (below). */
5302 if (TREE_CODE (t
) == POINTER_TYPE
)
5305 /* Find bottom type under any nested POINTERs. */
5306 for (t2
= TREE_TYPE (t
);
5307 TREE_CODE (t2
) == POINTER_TYPE
;
5308 t2
= TREE_TYPE (t2
))
5310 if (TREE_CODE (t2
) != RECORD_TYPE
5311 && TREE_CODE (t2
) != ENUMERAL_TYPE
5312 && TREE_CODE (t2
) != QUAL_UNION_TYPE
5313 && TREE_CODE (t2
) != UNION_TYPE
)
5315 if (TYPE_SIZE (t2
) == 0)
5318 /* These are the only cases that need special handling. */
5319 if (TREE_CODE (t
) != RECORD_TYPE
5320 && TREE_CODE (t
) != ENUMERAL_TYPE
5321 && TREE_CODE (t
) != QUAL_UNION_TYPE
5322 && TREE_CODE (t
) != UNION_TYPE
5323 && TREE_CODE (t
) != POINTER_TYPE
)
5326 if (TYPE_SIZE (t
) == 0)
5329 /* Look up t in hash table. Only one of the compatible types within each
5330 alias set is recorded in the table. */
5331 if (!type_hash_table
)
5332 type_hash_table
= hash_table
<c_type_hasher
>::create_ggc (1021);
5333 tree
*slot
= type_hash_table
->find_slot (t
, INSERT
);
5336 TYPE_ALIAS_SET (t
) = TYPE_ALIAS_SET ((tree
)*slot
);
5337 return TYPE_ALIAS_SET ((tree
)*slot
);
5340 /* Our caller will assign and record (in t) a new alias set; all we need
5341 to do is remember t in the hash table. */
5347 /* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where
5348 the IS_SIZEOF parameter indicates which operator is being applied.
5349 The COMPLAIN flag controls whether we should diagnose possibly
5350 ill-formed constructs or not. LOC is the location of the SIZEOF or
5351 TYPEOF operator. If MIN_ALIGNOF, the least alignment required for
5352 a type in any context should be returned, rather than the normal
5353 alignment for that type. */
5356 c_sizeof_or_alignof_type (location_t loc
,
5357 tree type
, bool is_sizeof
, bool min_alignof
,
5360 const char *op_name
;
5362 enum tree_code type_code
= TREE_CODE (type
);
5364 op_name
= is_sizeof
? "sizeof" : "__alignof__";
5366 if (type_code
== FUNCTION_TYPE
)
5370 if (complain
&& warn_pointer_arith
)
5371 pedwarn (loc
, OPT_Wpointer_arith
,
5372 "invalid application of %<sizeof%> to a function type");
5374 return error_mark_node
;
5375 value
= size_one_node
;
5381 if (c_dialect_cxx ())
5382 pedwarn (loc
, OPT_Wpedantic
, "ISO C++ does not permit "
5383 "%<alignof%> applied to a function type");
5385 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not permit "
5386 "%<_Alignof%> applied to a function type");
5388 value
= size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
5391 else if (type_code
== VOID_TYPE
|| type_code
== ERROR_MARK
)
5393 if (type_code
== VOID_TYPE
5394 && complain
&& warn_pointer_arith
)
5395 pedwarn (loc
, OPT_Wpointer_arith
,
5396 "invalid application of %qs to a void type", op_name
);
5398 return error_mark_node
;
5399 value
= size_one_node
;
5401 else if (!COMPLETE_TYPE_P (type
)
5402 && (!c_dialect_cxx () || is_sizeof
|| type_code
!= ARRAY_TYPE
))
5405 error_at (loc
, "invalid application of %qs to incomplete type %qT",
5407 return error_mark_node
;
5409 else if (c_dialect_cxx () && type_code
== ARRAY_TYPE
5410 && !COMPLETE_TYPE_P (TREE_TYPE (type
)))
5413 error_at (loc
, "invalid application of %qs to array type %qT of "
5414 "incomplete element type", op_name
, type
);
5415 return error_mark_node
;
5420 /* Convert in case a char is more than one unit. */
5421 value
= size_binop_loc (loc
, CEIL_DIV_EXPR
, TYPE_SIZE_UNIT (type
),
5422 size_int (TYPE_PRECISION (char_type_node
)
5424 else if (min_alignof
)
5425 value
= size_int (min_align_of_type (type
));
5427 value
= size_int (TYPE_ALIGN_UNIT (type
));
5430 /* VALUE will have the middle-end integer type sizetype.
5431 However, we should really return a value of type `size_t',
5432 which is just a typedef for an ordinary integer type. */
5433 value
= fold_convert_loc (loc
, size_type_node
, value
);
5438 /* Implement the __alignof keyword: Return the minimum required
5439 alignment of EXPR, measured in bytes. For VAR_DECLs,
5440 FUNCTION_DECLs and FIELD_DECLs return DECL_ALIGN (which can be set
5441 from an "aligned" __attribute__ specification). LOC is the
5442 location of the ALIGNOF operator. */
5445 c_alignof_expr (location_t loc
, tree expr
)
5449 if (VAR_OR_FUNCTION_DECL_P (expr
))
5450 t
= size_int (DECL_ALIGN_UNIT (expr
));
5452 else if (TREE_CODE (expr
) == COMPONENT_REF
5453 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
, 1)))
5455 error_at (loc
, "%<__alignof%> applied to a bit-field");
5458 else if (TREE_CODE (expr
) == COMPONENT_REF
5459 && TREE_CODE (TREE_OPERAND (expr
, 1)) == FIELD_DECL
)
5460 t
= size_int (DECL_ALIGN_UNIT (TREE_OPERAND (expr
, 1)));
5462 else if (INDIRECT_REF_P (expr
))
5464 tree t
= TREE_OPERAND (expr
, 0);
5466 int bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
5468 while (CONVERT_EXPR_P (t
)
5469 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
5473 t
= TREE_OPERAND (t
, 0);
5474 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
5475 if (thisalign
> bestalign
)
5476 best
= t
, bestalign
= thisalign
;
5478 return c_alignof (loc
, TREE_TYPE (TREE_TYPE (best
)));
5481 return c_alignof (loc
, TREE_TYPE (expr
));
5483 return fold_convert_loc (loc
, size_type_node
, t
);
5486 /* Handle C and C++ default attributes. */
5488 enum built_in_attribute
5490 #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
5491 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
5492 #define DEF_ATTR_STRING(ENUM, VALUE) ENUM,
5493 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
5494 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
5495 #include "builtin-attrs.def"
5496 #undef DEF_ATTR_NULL_TREE
5498 #undef DEF_ATTR_STRING
5499 #undef DEF_ATTR_IDENT
5500 #undef DEF_ATTR_TREE_LIST
5504 static GTY(()) tree built_in_attributes
[(int) ATTR_LAST
];
5506 static void c_init_attributes (void);
5510 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
5511 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
5512 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
5513 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
5514 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
5515 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
5516 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
5517 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5519 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5521 #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5522 ARG6, ARG7, ARG8) NAME,
5523 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
5524 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
5525 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
5526 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
5527 #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
5528 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5530 #define DEF_FUNCTION_TYPE_VAR_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5532 #define DEF_FUNCTION_TYPE_VAR_11(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5533 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) NAME,
5534 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
5535 #include "builtin-types.def"
5536 #undef DEF_PRIMITIVE_TYPE
5537 #undef DEF_FUNCTION_TYPE_0
5538 #undef DEF_FUNCTION_TYPE_1
5539 #undef DEF_FUNCTION_TYPE_2
5540 #undef DEF_FUNCTION_TYPE_3
5541 #undef DEF_FUNCTION_TYPE_4
5542 #undef DEF_FUNCTION_TYPE_5
5543 #undef DEF_FUNCTION_TYPE_6
5544 #undef DEF_FUNCTION_TYPE_7
5545 #undef DEF_FUNCTION_TYPE_8
5546 #undef DEF_FUNCTION_TYPE_VAR_0
5547 #undef DEF_FUNCTION_TYPE_VAR_1
5548 #undef DEF_FUNCTION_TYPE_VAR_2
5549 #undef DEF_FUNCTION_TYPE_VAR_3
5550 #undef DEF_FUNCTION_TYPE_VAR_4
5551 #undef DEF_FUNCTION_TYPE_VAR_5
5552 #undef DEF_FUNCTION_TYPE_VAR_7
5553 #undef DEF_FUNCTION_TYPE_VAR_11
5554 #undef DEF_POINTER_TYPE
5558 typedef enum c_builtin_type builtin_type
;
5560 /* A temporary array for c_common_nodes_and_builtins. Used in
5561 communication with def_fn_type. */
5562 static tree builtin_types
[(int) BT_LAST
+ 1];
5564 /* A helper function for c_common_nodes_and_builtins. Build function type
5565 for DEF with return type RET and N arguments. If VAR is true, then the
5566 function should be variadic after those N arguments.
5568 Takes special care not to ICE if any of the types involved are
5569 error_mark_node, which indicates that said type is not in fact available
5570 (see builtin_type_for_size). In which case the function type as a whole
5571 should be error_mark_node. */
5574 def_fn_type (builtin_type def
, builtin_type ret
, bool var
, int n
, ...)
5577 tree
*args
= XALLOCAVEC (tree
, n
);
5582 for (i
= 0; i
< n
; ++i
)
5584 builtin_type a
= (builtin_type
) va_arg (list
, int);
5585 t
= builtin_types
[a
];
5586 if (t
== error_mark_node
)
5591 t
= builtin_types
[ret
];
5592 if (t
== error_mark_node
)
5595 t
= build_varargs_function_type_array (t
, n
, args
);
5597 t
= build_function_type_array (t
, n
, args
);
5600 builtin_types
[def
] = t
;
5604 /* Build builtin functions common to both C and C++ language
5608 c_define_builtins (tree va_list_ref_type_node
, tree va_list_arg_type_node
)
5610 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
5611 builtin_types[ENUM] = VALUE;
5612 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
5613 def_fn_type (ENUM, RETURN, 0, 0);
5614 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
5615 def_fn_type (ENUM, RETURN, 0, 1, ARG1);
5616 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
5617 def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
5618 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
5619 def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
5620 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
5621 def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
5622 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5623 def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
5624 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5626 def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
5627 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5629 def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
5630 #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5632 def_fn_type (ENUM, RETURN, 0, 8, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
5634 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
5635 def_fn_type (ENUM, RETURN, 1, 0);
5636 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
5637 def_fn_type (ENUM, RETURN, 1, 1, ARG1);
5638 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
5639 def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
5640 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
5641 def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
5642 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
5643 def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
5644 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5645 def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
5646 #define DEF_FUNCTION_TYPE_VAR_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5648 def_fn_type (ENUM, RETURN, 1, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
5649 #define DEF_FUNCTION_TYPE_VAR_11(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5650 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) \
5651 def_fn_type (ENUM, RETURN, 1, 11, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
5652 ARG7, ARG8, ARG9, ARG10, ARG11);
5653 #define DEF_POINTER_TYPE(ENUM, TYPE) \
5654 builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
5656 #include "builtin-types.def"
5658 #undef DEF_PRIMITIVE_TYPE
5659 #undef DEF_FUNCTION_TYPE_0
5660 #undef DEF_FUNCTION_TYPE_1
5661 #undef DEF_FUNCTION_TYPE_2
5662 #undef DEF_FUNCTION_TYPE_3
5663 #undef DEF_FUNCTION_TYPE_4
5664 #undef DEF_FUNCTION_TYPE_5
5665 #undef DEF_FUNCTION_TYPE_6
5666 #undef DEF_FUNCTION_TYPE_7
5667 #undef DEF_FUNCTION_TYPE_8
5668 #undef DEF_FUNCTION_TYPE_VAR_0
5669 #undef DEF_FUNCTION_TYPE_VAR_1
5670 #undef DEF_FUNCTION_TYPE_VAR_2
5671 #undef DEF_FUNCTION_TYPE_VAR_3
5672 #undef DEF_FUNCTION_TYPE_VAR_4
5673 #undef DEF_FUNCTION_TYPE_VAR_5
5674 #undef DEF_FUNCTION_TYPE_VAR_7
5675 #undef DEF_FUNCTION_TYPE_VAR_11
5676 #undef DEF_POINTER_TYPE
5677 builtin_types
[(int) BT_LAST
] = NULL_TREE
;
5679 c_init_attributes ();
5681 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P, \
5682 NONANSI_P, ATTRS, IMPLICIT, COND) \
5684 def_builtin_1 (ENUM, NAME, CLASS, \
5685 builtin_types[(int) TYPE], \
5686 builtin_types[(int) LIBTYPE], \
5687 BOTH_P, FALLBACK_P, NONANSI_P, \
5688 built_in_attributes[(int) ATTRS], IMPLICIT);
5689 #include "builtins.def"
5692 targetm
.init_builtins ();
5694 build_common_builtin_nodes ();
5697 cilk_init_builtins ();
5700 /* Like get_identifier, but avoid warnings about null arguments when
5701 the argument may be NULL for targets where GCC lacks stdint.h type
5705 c_get_ident (const char *id
)
5707 return get_identifier (id
);
5710 /* Build tree nodes and builtin functions common to both C and C++ language
5714 c_common_nodes_and_builtins (void)
5716 int char16_type_size
;
5717 int char32_type_size
;
5718 int wchar_type_size
;
5719 tree array_domain_type
;
5720 tree va_list_ref_type_node
;
5721 tree va_list_arg_type_node
;
5724 build_common_tree_nodes (flag_signed_char
, flag_short_double
);
5726 /* Define `int' and `char' first so that dbx will output them first. */
5727 record_builtin_type (RID_INT
, NULL
, integer_type_node
);
5728 record_builtin_type (RID_CHAR
, "char", char_type_node
);
5730 /* `signed' is the same as `int'. FIXME: the declarations of "signed",
5731 "unsigned long", "long long unsigned" and "unsigned short" were in C++
5732 but not C. Are the conditionals here needed? */
5733 if (c_dialect_cxx ())
5734 record_builtin_type (RID_SIGNED
, NULL
, integer_type_node
);
5735 record_builtin_type (RID_LONG
, "long int", long_integer_type_node
);
5736 record_builtin_type (RID_UNSIGNED
, "unsigned int", unsigned_type_node
);
5737 record_builtin_type (RID_MAX
, "long unsigned int",
5738 long_unsigned_type_node
);
5740 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
5744 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
5745 record_builtin_type ((enum rid
)(RID_FIRST_INT_N
+ i
), name
,
5746 int_n_trees
[i
].signed_type
);
5747 sprintf (name
, "__int%d unsigned", int_n_data
[i
].bitsize
);
5748 record_builtin_type (RID_MAX
, name
, int_n_trees
[i
].unsigned_type
);
5751 if (c_dialect_cxx ())
5752 record_builtin_type (RID_MAX
, "unsigned long", long_unsigned_type_node
);
5753 record_builtin_type (RID_MAX
, "long long int",
5754 long_long_integer_type_node
);
5755 record_builtin_type (RID_MAX
, "long long unsigned int",
5756 long_long_unsigned_type_node
);
5757 if (c_dialect_cxx ())
5758 record_builtin_type (RID_MAX
, "long long unsigned",
5759 long_long_unsigned_type_node
);
5760 record_builtin_type (RID_SHORT
, "short int", short_integer_type_node
);
5761 record_builtin_type (RID_MAX
, "short unsigned int",
5762 short_unsigned_type_node
);
5763 if (c_dialect_cxx ())
5764 record_builtin_type (RID_MAX
, "unsigned short",
5765 short_unsigned_type_node
);
5767 /* Define both `signed char' and `unsigned char'. */
5768 record_builtin_type (RID_MAX
, "signed char", signed_char_type_node
);
5769 record_builtin_type (RID_MAX
, "unsigned char", unsigned_char_type_node
);
5771 /* These are types that c_common_type_for_size and
5772 c_common_type_for_mode use. */
5773 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5774 TYPE_DECL
, NULL_TREE
,
5776 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5777 TYPE_DECL
, NULL_TREE
,
5779 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5780 TYPE_DECL
, NULL_TREE
,
5782 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5783 TYPE_DECL
, NULL_TREE
,
5785 #if HOST_BITS_PER_WIDE_INT >= 64
5786 /* Note that this is different than the __int128 type that's part of
5787 the generic __intN support. */
5788 if (targetm
.scalar_mode_supported_p (TImode
))
5789 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5791 get_identifier ("__int128_t"),
5794 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5795 TYPE_DECL
, NULL_TREE
,
5796 unsigned_intQI_type_node
));
5797 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5798 TYPE_DECL
, NULL_TREE
,
5799 unsigned_intHI_type_node
));
5800 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5801 TYPE_DECL
, NULL_TREE
,
5802 unsigned_intSI_type_node
));
5803 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5804 TYPE_DECL
, NULL_TREE
,
5805 unsigned_intDI_type_node
));
5806 #if HOST_BITS_PER_WIDE_INT >= 64
5807 if (targetm
.scalar_mode_supported_p (TImode
))
5808 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5810 get_identifier ("__uint128_t"),
5811 unsigned_intTI_type_node
));
5814 /* Create the widest literal types. */
5815 widest_integer_literal_type_node
5816 = make_signed_type (HOST_BITS_PER_WIDE_INT
* 2);
5817 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5818 TYPE_DECL
, NULL_TREE
,
5819 widest_integer_literal_type_node
));
5821 widest_unsigned_literal_type_node
5822 = make_unsigned_type (HOST_BITS_PER_WIDE_INT
* 2);
5823 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5824 TYPE_DECL
, NULL_TREE
,
5825 widest_unsigned_literal_type_node
));
5827 signed_size_type_node
= c_common_signed_type (size_type_node
);
5830 TREE_TYPE (identifier_global_value (get_identifier (PID_TYPE
)));
5832 record_builtin_type (RID_FLOAT
, NULL
, float_type_node
);
5833 record_builtin_type (RID_DOUBLE
, NULL
, double_type_node
);
5834 record_builtin_type (RID_MAX
, "long double", long_double_type_node
);
5836 /* Only supported decimal floating point extension if the target
5837 actually supports underlying modes. */
5838 if (targetm
.scalar_mode_supported_p (SDmode
)
5839 && targetm
.scalar_mode_supported_p (DDmode
)
5840 && targetm
.scalar_mode_supported_p (TDmode
))
5842 record_builtin_type (RID_DFLOAT32
, NULL
, dfloat32_type_node
);
5843 record_builtin_type (RID_DFLOAT64
, NULL
, dfloat64_type_node
);
5844 record_builtin_type (RID_DFLOAT128
, NULL
, dfloat128_type_node
);
5847 if (targetm
.fixed_point_supported_p ())
5849 record_builtin_type (RID_MAX
, "short _Fract", short_fract_type_node
);
5850 record_builtin_type (RID_FRACT
, NULL
, fract_type_node
);
5851 record_builtin_type (RID_MAX
, "long _Fract", long_fract_type_node
);
5852 record_builtin_type (RID_MAX
, "long long _Fract",
5853 long_long_fract_type_node
);
5854 record_builtin_type (RID_MAX
, "unsigned short _Fract",
5855 unsigned_short_fract_type_node
);
5856 record_builtin_type (RID_MAX
, "unsigned _Fract",
5857 unsigned_fract_type_node
);
5858 record_builtin_type (RID_MAX
, "unsigned long _Fract",
5859 unsigned_long_fract_type_node
);
5860 record_builtin_type (RID_MAX
, "unsigned long long _Fract",
5861 unsigned_long_long_fract_type_node
);
5862 record_builtin_type (RID_MAX
, "_Sat short _Fract",
5863 sat_short_fract_type_node
);
5864 record_builtin_type (RID_MAX
, "_Sat _Fract", sat_fract_type_node
);
5865 record_builtin_type (RID_MAX
, "_Sat long _Fract",
5866 sat_long_fract_type_node
);
5867 record_builtin_type (RID_MAX
, "_Sat long long _Fract",
5868 sat_long_long_fract_type_node
);
5869 record_builtin_type (RID_MAX
, "_Sat unsigned short _Fract",
5870 sat_unsigned_short_fract_type_node
);
5871 record_builtin_type (RID_MAX
, "_Sat unsigned _Fract",
5872 sat_unsigned_fract_type_node
);
5873 record_builtin_type (RID_MAX
, "_Sat unsigned long _Fract",
5874 sat_unsigned_long_fract_type_node
);
5875 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Fract",
5876 sat_unsigned_long_long_fract_type_node
);
5877 record_builtin_type (RID_MAX
, "short _Accum", short_accum_type_node
);
5878 record_builtin_type (RID_ACCUM
, NULL
, accum_type_node
);
5879 record_builtin_type (RID_MAX
, "long _Accum", long_accum_type_node
);
5880 record_builtin_type (RID_MAX
, "long long _Accum",
5881 long_long_accum_type_node
);
5882 record_builtin_type (RID_MAX
, "unsigned short _Accum",
5883 unsigned_short_accum_type_node
);
5884 record_builtin_type (RID_MAX
, "unsigned _Accum",
5885 unsigned_accum_type_node
);
5886 record_builtin_type (RID_MAX
, "unsigned long _Accum",
5887 unsigned_long_accum_type_node
);
5888 record_builtin_type (RID_MAX
, "unsigned long long _Accum",
5889 unsigned_long_long_accum_type_node
);
5890 record_builtin_type (RID_MAX
, "_Sat short _Accum",
5891 sat_short_accum_type_node
);
5892 record_builtin_type (RID_MAX
, "_Sat _Accum", sat_accum_type_node
);
5893 record_builtin_type (RID_MAX
, "_Sat long _Accum",
5894 sat_long_accum_type_node
);
5895 record_builtin_type (RID_MAX
, "_Sat long long _Accum",
5896 sat_long_long_accum_type_node
);
5897 record_builtin_type (RID_MAX
, "_Sat unsigned short _Accum",
5898 sat_unsigned_short_accum_type_node
);
5899 record_builtin_type (RID_MAX
, "_Sat unsigned _Accum",
5900 sat_unsigned_accum_type_node
);
5901 record_builtin_type (RID_MAX
, "_Sat unsigned long _Accum",
5902 sat_unsigned_long_accum_type_node
);
5903 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Accum",
5904 sat_unsigned_long_long_accum_type_node
);
5908 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5910 get_identifier ("complex int"),
5911 complex_integer_type_node
));
5912 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5914 get_identifier ("complex float"),
5915 complex_float_type_node
));
5916 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5918 get_identifier ("complex double"),
5919 complex_double_type_node
));
5920 lang_hooks
.decls
.pushdecl
5921 (build_decl (UNKNOWN_LOCATION
,
5922 TYPE_DECL
, get_identifier ("complex long double"),
5923 complex_long_double_type_node
));
5925 if (c_dialect_cxx ())
5926 /* For C++, make fileptr_type_node a distinct void * type until
5927 FILE type is defined. */
5928 fileptr_type_node
= build_variant_type_copy (ptr_type_node
);
5930 record_builtin_type (RID_VOID
, NULL
, void_type_node
);
5932 /* Set the TYPE_NAME for any variants that were built before
5933 record_builtin_type gave names to the built-in types. */
5935 tree void_name
= TYPE_NAME (void_type_node
);
5936 TYPE_NAME (void_type_node
) = NULL_TREE
;
5937 TYPE_NAME (build_qualified_type (void_type_node
, TYPE_QUAL_CONST
))
5939 TYPE_NAME (void_type_node
) = void_name
;
5942 void_list_node
= build_void_list_node ();
5944 /* Make a type to be the domain of a few array types
5945 whose domains don't really matter.
5946 200 is small enough that it always fits in size_t
5947 and large enough that it can hold most function names for the
5948 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
5949 array_domain_type
= build_index_type (size_int (200));
5951 /* Make a type for arrays of characters.
5952 With luck nothing will ever really depend on the length of this
5954 char_array_type_node
5955 = build_array_type (char_type_node
, array_domain_type
);
5957 string_type_node
= build_pointer_type (char_type_node
);
5958 const_string_type_node
5959 = build_pointer_type (build_qualified_type
5960 (char_type_node
, TYPE_QUAL_CONST
));
5962 /* This is special for C++ so functions can be overloaded. */
5963 wchar_type_node
= get_identifier (MODIFIED_WCHAR_TYPE
);
5964 wchar_type_node
= TREE_TYPE (identifier_global_value (wchar_type_node
));
5965 wchar_type_size
= TYPE_PRECISION (wchar_type_node
);
5966 underlying_wchar_type_node
= wchar_type_node
;
5967 if (c_dialect_cxx ())
5969 if (TYPE_UNSIGNED (wchar_type_node
))
5970 wchar_type_node
= make_unsigned_type (wchar_type_size
);
5972 wchar_type_node
= make_signed_type (wchar_type_size
);
5973 record_builtin_type (RID_WCHAR
, "wchar_t", wchar_type_node
);
5976 /* This is for wide string constants. */
5977 wchar_array_type_node
5978 = build_array_type (wchar_type_node
, array_domain_type
);
5980 /* Define 'char16_t'. */
5981 char16_type_node
= get_identifier (CHAR16_TYPE
);
5982 char16_type_node
= TREE_TYPE (identifier_global_value (char16_type_node
));
5983 char16_type_size
= TYPE_PRECISION (char16_type_node
);
5984 if (c_dialect_cxx ())
5986 char16_type_node
= make_unsigned_type (char16_type_size
);
5988 if (cxx_dialect
>= cxx11
)
5989 record_builtin_type (RID_CHAR16
, "char16_t", char16_type_node
);
5992 /* This is for UTF-16 string constants. */
5993 char16_array_type_node
5994 = build_array_type (char16_type_node
, array_domain_type
);
5996 /* Define 'char32_t'. */
5997 char32_type_node
= get_identifier (CHAR32_TYPE
);
5998 char32_type_node
= TREE_TYPE (identifier_global_value (char32_type_node
));
5999 char32_type_size
= TYPE_PRECISION (char32_type_node
);
6000 if (c_dialect_cxx ())
6002 char32_type_node
= make_unsigned_type (char32_type_size
);
6004 if (cxx_dialect
>= cxx11
)
6005 record_builtin_type (RID_CHAR32
, "char32_t", char32_type_node
);
6008 /* This is for UTF-32 string constants. */
6009 char32_array_type_node
6010 = build_array_type (char32_type_node
, array_domain_type
);
6013 TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE
)));
6016 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE
)));
6018 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE
)));
6020 if (SIG_ATOMIC_TYPE
)
6021 sig_atomic_type_node
=
6022 TREE_TYPE (identifier_global_value (c_get_ident (SIG_ATOMIC_TYPE
)));
6025 TREE_TYPE (identifier_global_value (c_get_ident (INT8_TYPE
)));
6028 TREE_TYPE (identifier_global_value (c_get_ident (INT16_TYPE
)));
6031 TREE_TYPE (identifier_global_value (c_get_ident (INT32_TYPE
)));
6034 TREE_TYPE (identifier_global_value (c_get_ident (INT64_TYPE
)));
6037 TREE_TYPE (identifier_global_value (c_get_ident (UINT8_TYPE
)));
6039 c_uint16_type_node
= uint16_type_node
=
6040 TREE_TYPE (identifier_global_value (c_get_ident (UINT16_TYPE
)));
6042 c_uint32_type_node
= uint32_type_node
=
6043 TREE_TYPE (identifier_global_value (c_get_ident (UINT32_TYPE
)));
6045 c_uint64_type_node
= uint64_type_node
=
6046 TREE_TYPE (identifier_global_value (c_get_ident (UINT64_TYPE
)));
6047 if (INT_LEAST8_TYPE
)
6048 int_least8_type_node
=
6049 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST8_TYPE
)));
6050 if (INT_LEAST16_TYPE
)
6051 int_least16_type_node
=
6052 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST16_TYPE
)));
6053 if (INT_LEAST32_TYPE
)
6054 int_least32_type_node
=
6055 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST32_TYPE
)));
6056 if (INT_LEAST64_TYPE
)
6057 int_least64_type_node
=
6058 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST64_TYPE
)));
6059 if (UINT_LEAST8_TYPE
)
6060 uint_least8_type_node
=
6061 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST8_TYPE
)));
6062 if (UINT_LEAST16_TYPE
)
6063 uint_least16_type_node
=
6064 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST16_TYPE
)));
6065 if (UINT_LEAST32_TYPE
)
6066 uint_least32_type_node
=
6067 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST32_TYPE
)));
6068 if (UINT_LEAST64_TYPE
)
6069 uint_least64_type_node
=
6070 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST64_TYPE
)));
6072 int_fast8_type_node
=
6073 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST8_TYPE
)));
6074 if (INT_FAST16_TYPE
)
6075 int_fast16_type_node
=
6076 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST16_TYPE
)));
6077 if (INT_FAST32_TYPE
)
6078 int_fast32_type_node
=
6079 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST32_TYPE
)));
6080 if (INT_FAST64_TYPE
)
6081 int_fast64_type_node
=
6082 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST64_TYPE
)));
6083 if (UINT_FAST8_TYPE
)
6084 uint_fast8_type_node
=
6085 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST8_TYPE
)));
6086 if (UINT_FAST16_TYPE
)
6087 uint_fast16_type_node
=
6088 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST16_TYPE
)));
6089 if (UINT_FAST32_TYPE
)
6090 uint_fast32_type_node
=
6091 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST32_TYPE
)));
6092 if (UINT_FAST64_TYPE
)
6093 uint_fast64_type_node
=
6094 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST64_TYPE
)));
6097 TREE_TYPE (identifier_global_value (c_get_ident (INTPTR_TYPE
)));
6100 TREE_TYPE (identifier_global_value (c_get_ident (UINTPTR_TYPE
)));
6102 default_function_type
6103 = build_varargs_function_type_list (integer_type_node
, NULL_TREE
);
6105 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE
)));
6106 unsigned_ptrdiff_type_node
= c_common_unsigned_type (ptrdiff_type_node
);
6108 lang_hooks
.decls
.pushdecl
6109 (build_decl (UNKNOWN_LOCATION
,
6110 TYPE_DECL
, get_identifier ("__builtin_va_list"),
6111 va_list_type_node
));
6112 if (targetm
.enum_va_list_p
)
6118 for (l
= 0; targetm
.enum_va_list_p (l
, &pname
, &ptype
); ++l
)
6120 lang_hooks
.decls
.pushdecl
6121 (build_decl (UNKNOWN_LOCATION
,
6122 TYPE_DECL
, get_identifier (pname
),
6128 if (TREE_CODE (va_list_type_node
) == ARRAY_TYPE
)
6130 va_list_arg_type_node
= va_list_ref_type_node
=
6131 build_pointer_type (TREE_TYPE (va_list_type_node
));
6135 va_list_arg_type_node
= va_list_type_node
;
6136 va_list_ref_type_node
= build_reference_type (va_list_type_node
);
6139 if (!flag_preprocess_only
)
6140 c_define_builtins (va_list_ref_type_node
, va_list_arg_type_node
);
6142 main_identifier_node
= get_identifier ("main");
6144 /* Create the built-in __null node. It is important that this is
6146 null_node
= make_int_cst (1, 1);
6147 TREE_TYPE (null_node
) = c_common_type_for_size (POINTER_SIZE
, 0);
6149 /* Since builtin_types isn't gc'ed, don't export these nodes. */
6150 memset (builtin_types
, 0, sizeof (builtin_types
));
6153 /* The number of named compound-literals generated thus far. */
6154 static GTY(()) int compound_literal_number
;
6156 /* Set DECL_NAME for DECL, a VAR_DECL for a compound-literal. */
6159 set_compound_literal_name (tree decl
)
6162 ASM_FORMAT_PRIVATE_NAME (name
, "__compound_literal",
6163 compound_literal_number
);
6164 compound_literal_number
++;
6165 DECL_NAME (decl
) = get_identifier (name
);
6168 /* build_va_arg helper function. Return a VA_ARG_EXPR with location LOC, type
6169 TYPE and operand OP. */
6172 build_va_arg_1 (location_t loc
, tree type
, tree op
)
6174 tree expr
= build1 (VA_ARG_EXPR
, type
, op
);
6175 SET_EXPR_LOCATION (expr
, loc
);
6179 /* Return a VA_ARG_EXPR corresponding to a source-level expression
6180 va_arg (EXPR, TYPE) at source location LOC. */
6183 build_va_arg (location_t loc
, tree expr
, tree type
)
6185 tree va_type
= TREE_TYPE (expr
);
6186 tree canon_va_type
= (va_type
== error_mark_node
6188 : targetm
.canonical_va_list_type (va_type
));
6190 if (va_type
== error_mark_node
6191 || canon_va_type
== NULL_TREE
)
6193 /* Let's handle things neutrallly, if expr:
6194 - has undeclared type, or
6195 - is not an va_list type. */
6196 return build_va_arg_1 (loc
, type
, expr
);
6199 if (TREE_CODE (canon_va_type
) != ARRAY_TYPE
)
6201 /* Case 1: Not an array type. */
6203 /* Take the address, to get '&ap'. */
6204 mark_addressable (expr
);
6205 expr
= build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (expr
)), expr
);
6207 /* Verify that &ap is still recognized as having va_list type. */
6208 tree canon_expr_type
6209 = targetm
.canonical_va_list_type (TREE_TYPE (expr
));
6210 gcc_assert (canon_expr_type
!= NULL_TREE
);
6212 return build_va_arg_1 (loc
, type
, expr
);
6215 /* Case 2: Array type.
6219 For contrast, let's start with the simple case (case 1). If
6220 canon_va_type is not an array type, but say a char *, then when
6221 passing-by-value a va_list, the type of the va_list param decl is
6222 the same as for another va_list decl (all ap's are char *):
6225 D.1815 = VA_ARG (&ap, 0B, 1);
6231 __builtin_va_start (&ap, 0);
6234 __builtin_va_end (&ap);
6238 However, if canon_va_type is ARRAY_TYPE, then when passing-by-value a
6239 va_list the type of the va_list param decl (case 2b, struct * ap) is not
6240 the same as for another va_list decl (case 2a, struct ap[1]).
6243 D.1844 = VA_ARG (ap, 0B, 0);
6248 __builtin_va_start (&ap, 0);
6250 __builtin_va_end (&ap);
6254 Case 2b is different because:
6255 - on the callee side, the parm decl has declared type va_list, but
6256 grokdeclarator changes the type of the parm decl to a pointer to the
6258 - on the caller side, the pass-by-value uses &ap.
6260 We unify these two cases (case 2a: va_list is array type,
6261 case 2b: va_list is pointer to array elem type), by adding '&' for the
6262 array type case, such that we have a pointer to array elem in both
6265 if (TREE_CODE (va_type
) == ARRAY_TYPE
)
6267 /* Case 2a: va_list is array type. */
6269 /* Take the address, to get '&ap'. Make sure it's a pointer to array
6271 mark_addressable (expr
);
6272 expr
= build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (canon_va_type
)),
6275 /* Verify that &ap is still recognized as having va_list type. */
6276 tree canon_expr_type
6277 = targetm
.canonical_va_list_type (TREE_TYPE (expr
));
6278 gcc_assert (canon_expr_type
!= NULL_TREE
);
6282 /* Case 2b: va_list is pointer to array elem type. */
6283 gcc_assert (POINTER_TYPE_P (va_type
));
6284 gcc_assert (TREE_TYPE (va_type
) == TREE_TYPE (canon_va_type
));
6286 /* Don't take the address. We've already got '&ap'. */
6290 return build_va_arg_1 (loc
, type
, expr
);
6294 /* Linked list of disabled built-in functions. */
6296 typedef struct disabled_builtin
6299 struct disabled_builtin
*next
;
6301 static disabled_builtin
*disabled_builtins
= NULL
;
6303 static bool builtin_function_disabled_p (const char *);
6305 /* Disable a built-in function specified by -fno-builtin-NAME. If NAME
6306 begins with "__builtin_", give an error. */
6309 disable_builtin_function (const char *name
)
6311 if (strncmp (name
, "__builtin_", strlen ("__builtin_")) == 0)
6312 error ("cannot disable built-in function %qs", name
);
6315 disabled_builtin
*new_disabled_builtin
= XNEW (disabled_builtin
);
6316 new_disabled_builtin
->name
= name
;
6317 new_disabled_builtin
->next
= disabled_builtins
;
6318 disabled_builtins
= new_disabled_builtin
;
6323 /* Return true if the built-in function NAME has been disabled, false
6327 builtin_function_disabled_p (const char *name
)
6329 disabled_builtin
*p
;
6330 for (p
= disabled_builtins
; p
!= NULL
; p
= p
->next
)
6332 if (strcmp (name
, p
->name
) == 0)
6339 /* Worker for DEF_BUILTIN.
6340 Possibly define a builtin function with one or two names.
6341 Does not declare a non-__builtin_ function if flag_no_builtin, or if
6342 nonansi_p and flag_no_nonansi_builtin. */
6345 def_builtin_1 (enum built_in_function fncode
,
6347 enum built_in_class fnclass
,
6348 tree fntype
, tree libtype
,
6349 bool both_p
, bool fallback_p
, bool nonansi_p
,
6350 tree fnattrs
, bool implicit_p
)
6353 const char *libname
;
6355 if (fntype
== error_mark_node
)
6358 gcc_assert ((!both_p
&& !fallback_p
)
6359 || !strncmp (name
, "__builtin_",
6360 strlen ("__builtin_")));
6362 libname
= name
+ strlen ("__builtin_");
6363 decl
= add_builtin_function (name
, fntype
, fncode
, fnclass
,
6364 (fallback_p
? libname
: NULL
),
6367 set_builtin_decl (fncode
, decl
, implicit_p
);
6370 && !flag_no_builtin
&& !builtin_function_disabled_p (libname
)
6371 && !(nonansi_p
&& flag_no_nonansi_builtin
))
6372 add_builtin_function (libname
, libtype
, fncode
, fnclass
,
6376 /* Nonzero if the type T promotes to int. This is (nearly) the
6377 integral promotions defined in ISO C99 6.3.1.1/2. */
6380 c_promoting_integer_type_p (const_tree t
)
6382 switch (TREE_CODE (t
))
6385 return (TYPE_MAIN_VARIANT (t
) == char_type_node
6386 || TYPE_MAIN_VARIANT (t
) == signed_char_type_node
6387 || TYPE_MAIN_VARIANT (t
) == unsigned_char_type_node
6388 || TYPE_MAIN_VARIANT (t
) == short_integer_type_node
6389 || TYPE_MAIN_VARIANT (t
) == short_unsigned_type_node
6390 || TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
));
6393 /* ??? Technically all enumerations not larger than an int
6394 promote to an int. But this is used along code paths
6395 that only want to notice a size change. */
6396 return TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
);
6406 /* Return 1 if PARMS specifies a fixed number of parameters
6407 and none of their types is affected by default promotions. */
6410 self_promoting_args_p (const_tree parms
)
6413 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
6415 tree type
= TREE_VALUE (t
);
6417 if (type
== error_mark_node
)
6420 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
6426 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
6429 if (c_promoting_integer_type_p (type
))
6435 /* Recursively remove any '*' or '&' operator from TYPE. */
6437 strip_pointer_operator (tree t
)
6439 while (POINTER_TYPE_P (t
))
6444 /* Recursively remove pointer or array type from TYPE. */
6446 strip_pointer_or_array_types (tree t
)
6448 while (TREE_CODE (t
) == ARRAY_TYPE
|| POINTER_TYPE_P (t
))
6453 /* Used to compare case labels. K1 and K2 are actually tree nodes
6454 representing case labels, or NULL_TREE for a `default' label.
6455 Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after
6456 K2, and 0 if K1 and K2 are equal. */
6459 case_compare (splay_tree_key k1
, splay_tree_key k2
)
6461 /* Consider a NULL key (such as arises with a `default' label) to be
6462 smaller than anything else. */
6468 return tree_int_cst_compare ((tree
) k1
, (tree
) k2
);
6471 /* Process a case label, located at LOC, for the range LOW_VALUE
6472 ... HIGH_VALUE. If LOW_VALUE and HIGH_VALUE are both NULL_TREE
6473 then this case label is actually a `default' label. If only
6474 HIGH_VALUE is NULL_TREE, then case label was declared using the
6475 usual C/C++ syntax, rather than the GNU case range extension.
6476 CASES is a tree containing all the case ranges processed so far;
6477 COND is the condition for the switch-statement itself.
6478 OUTSIDE_RANGE_P says whether there was a case value that doesn't
6479 fit into the range of the ORIG_TYPE. Returns the CASE_LABEL_EXPR
6480 created, or ERROR_MARK_NODE if no CASE_LABEL_EXPR is created. */
6483 c_add_case_label (location_t loc
, splay_tree cases
, tree cond
, tree orig_type
,
6484 tree low_value
, tree high_value
, bool *outside_range_p
)
6489 splay_tree_node node
;
6491 /* Create the LABEL_DECL itself. */
6492 label
= create_artificial_label (loc
);
6494 /* If there was an error processing the switch condition, bail now
6495 before we get more confused. */
6496 if (!cond
|| cond
== error_mark_node
)
6499 if ((low_value
&& TREE_TYPE (low_value
)
6500 && POINTER_TYPE_P (TREE_TYPE (low_value
)))
6501 || (high_value
&& TREE_TYPE (high_value
)
6502 && POINTER_TYPE_P (TREE_TYPE (high_value
))))
6504 error_at (loc
, "pointers are not permitted as case values");
6508 /* Case ranges are a GNU extension. */
6510 pedwarn (loc
, OPT_Wpedantic
,
6511 "range expressions in switch statements are non-standard");
6513 type
= TREE_TYPE (cond
);
6516 low_value
= check_case_value (loc
, low_value
);
6517 low_value
= convert_and_check (loc
, type
, low_value
);
6518 if (low_value
== error_mark_node
)
6523 high_value
= check_case_value (loc
, high_value
);
6524 high_value
= convert_and_check (loc
, type
, high_value
);
6525 if (high_value
== error_mark_node
)
6529 if (low_value
&& high_value
)
6531 /* If the LOW_VALUE and HIGH_VALUE are the same, then this isn't
6532 really a case range, even though it was written that way.
6533 Remove the HIGH_VALUE to simplify later processing. */
6534 if (tree_int_cst_equal (low_value
, high_value
))
6535 high_value
= NULL_TREE
;
6536 else if (!tree_int_cst_lt (low_value
, high_value
))
6537 warning_at (loc
, 0, "empty range specified");
6540 /* See if the case is in range of the type of the original testing
6541 expression. If both low_value and high_value are out of range,
6542 don't insert the case label and return NULL_TREE. */
6544 && !check_case_bounds (loc
, type
, orig_type
,
6545 &low_value
, high_value
? &high_value
: NULL
,
6549 /* Look up the LOW_VALUE in the table of case labels we already
6551 node
= splay_tree_lookup (cases
, (splay_tree_key
) low_value
);
6552 /* If there was not an exact match, check for overlapping ranges.
6553 There's no need to do this if there's no LOW_VALUE or HIGH_VALUE;
6554 that's a `default' label and the only overlap is an exact match. */
6555 if (!node
&& (low_value
|| high_value
))
6557 splay_tree_node low_bound
;
6558 splay_tree_node high_bound
;
6560 /* Even though there wasn't an exact match, there might be an
6561 overlap between this case range and another case range.
6562 Since we've (inductively) not allowed any overlapping case
6563 ranges, we simply need to find the greatest low case label
6564 that is smaller that LOW_VALUE, and the smallest low case
6565 label that is greater than LOW_VALUE. If there is an overlap
6566 it will occur in one of these two ranges. */
6567 low_bound
= splay_tree_predecessor (cases
,
6568 (splay_tree_key
) low_value
);
6569 high_bound
= splay_tree_successor (cases
,
6570 (splay_tree_key
) low_value
);
6572 /* Check to see if the LOW_BOUND overlaps. It is smaller than
6573 the LOW_VALUE, so there is no need to check unless the
6574 LOW_BOUND is in fact itself a case range. */
6576 && CASE_HIGH ((tree
) low_bound
->value
)
6577 && tree_int_cst_compare (CASE_HIGH ((tree
) low_bound
->value
),
6580 /* Check to see if the HIGH_BOUND overlaps. The low end of that
6581 range is bigger than the low end of the current range, so we
6582 are only interested if the current range is a real range, and
6583 not an ordinary case label. */
6586 && (tree_int_cst_compare ((tree
) high_bound
->key
,
6591 /* If there was an overlap, issue an error. */
6594 tree duplicate
= CASE_LABEL ((tree
) node
->value
);
6598 error_at (loc
, "duplicate (or overlapping) case value");
6599 error_at (DECL_SOURCE_LOCATION (duplicate
),
6600 "this is the first entry overlapping that value");
6604 error_at (loc
, "duplicate case value") ;
6605 error_at (DECL_SOURCE_LOCATION (duplicate
), "previously used here");
6609 error_at (loc
, "multiple default labels in one switch");
6610 error_at (DECL_SOURCE_LOCATION (duplicate
),
6611 "this is the first default label");
6616 /* Add a CASE_LABEL to the statement-tree. */
6617 case_label
= add_stmt (build_case_label (low_value
, high_value
, label
));
6618 /* Register this case label in the splay tree. */
6619 splay_tree_insert (cases
,
6620 (splay_tree_key
) low_value
,
6621 (splay_tree_value
) case_label
);
6626 /* Add a label so that the back-end doesn't think that the beginning of
6627 the switch is unreachable. Note that we do not add a case label, as
6628 that just leads to duplicates and thence to failure later on. */
6631 tree t
= create_artificial_label (loc
);
6632 add_stmt (build_stmt (loc
, LABEL_EXPR
, t
));
6634 return error_mark_node
;
6637 /* Subroutines of c_do_switch_warnings, called via splay_tree_foreach.
6638 Used to verify that case values match up with enumerator values. */
6641 match_case_to_enum_1 (tree key
, tree type
, tree label
)
6643 char buf
[WIDE_INT_PRINT_BUFFER_SIZE
];
6645 if (tree_fits_uhwi_p (key
))
6646 print_dec (key
, buf
, UNSIGNED
);
6647 else if (tree_fits_shwi_p (key
))
6648 print_dec (key
, buf
, SIGNED
);
6650 print_hex (key
, buf
);
6652 if (TYPE_NAME (type
) == 0)
6653 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
6654 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
6655 "case value %qs not in enumerated type",
6658 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
6659 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
6660 "case value %qs not in enumerated type %qT",
6664 /* Subroutine of c_do_switch_warnings, called via splay_tree_foreach.
6665 Used to verify that case values match up with enumerator values. */
6668 match_case_to_enum (splay_tree_node node
, void *data
)
6670 tree label
= (tree
) node
->value
;
6671 tree type
= (tree
) data
;
6673 /* Skip default case. */
6674 if (!CASE_LOW (label
))
6677 /* If CASE_LOW_SEEN is not set, that means CASE_LOW did not appear
6678 when we did our enum->case scan. Reset our scratch bit after. */
6679 if (!CASE_LOW_SEEN (label
))
6680 match_case_to_enum_1 (CASE_LOW (label
), type
, label
);
6682 CASE_LOW_SEEN (label
) = 0;
6684 /* If CASE_HIGH is non-null, we have a range. If CASE_HIGH_SEEN is
6685 not set, that means that CASE_HIGH did not appear when we did our
6686 enum->case scan. Reset our scratch bit after. */
6687 if (CASE_HIGH (label
))
6689 if (!CASE_HIGH_SEEN (label
))
6690 match_case_to_enum_1 (CASE_HIGH (label
), type
, label
);
6692 CASE_HIGH_SEEN (label
) = 0;
6698 /* Handle -Wswitch*. Called from the front end after parsing the
6699 switch construct. */
6700 /* ??? Should probably be somewhere generic, since other languages
6701 besides C and C++ would want this. At the moment, however, C/C++
6702 are the only tree-ssa languages that support enumerations at all,
6703 so the point is moot. */
6706 c_do_switch_warnings (splay_tree cases
, location_t switch_location
,
6707 tree type
, tree cond
, bool bool_cond_p
,
6708 bool outside_range_p
)
6710 splay_tree_node default_node
;
6711 splay_tree_node node
;
6714 if (!warn_switch
&& !warn_switch_enum
&& !warn_switch_default
6715 && !warn_switch_bool
)
6718 default_node
= splay_tree_lookup (cases
, (splay_tree_key
) NULL
);
6720 warning_at (switch_location
, OPT_Wswitch_default
,
6721 "switch missing default case");
6723 /* There are certain cases where -Wswitch-bool warnings aren't
6730 so be careful here. */
6731 if (warn_switch_bool
&& bool_cond_p
)
6733 splay_tree_node min_node
;
6734 /* If there's a default node, it's also the value with the minimal
6735 key. So look at the penultimate key (if any). */
6737 min_node
= splay_tree_successor (cases
, (splay_tree_key
) NULL
);
6739 min_node
= splay_tree_min (cases
);
6740 tree min
= min_node
? (tree
) min_node
->key
: NULL_TREE
;
6742 splay_tree_node max_node
= splay_tree_max (cases
);
6743 /* This might be a case range, so look at the value with the
6744 maximal key and then check CASE_HIGH. */
6745 tree max
= max_node
? (tree
) max_node
->value
: NULL_TREE
;
6747 max
= CASE_HIGH (max
) ? CASE_HIGH (max
) : CASE_LOW (max
);
6749 /* If there's a case value > 1 or < 0, that is outside bool
6752 || (max
&& wi::gts_p (max
, 1))
6753 || (min
&& wi::lts_p (min
, 0))
6761 case, where we want to warn. */
6763 && max
&& wi::eq_p (max
, 1)
6764 && min
&& wi::eq_p (min
, 0)))
6765 warning_at (switch_location
, OPT_Wswitch_bool
,
6766 "switch condition has boolean value");
6769 /* From here on, we only care about enumerated types. */
6770 if (!type
|| TREE_CODE (type
) != ENUMERAL_TYPE
)
6773 /* From here on, we only care about -Wswitch and -Wswitch-enum. */
6774 if (!warn_switch_enum
&& !warn_switch
)
6777 /* Check the cases. Warn about case values which are not members of
6778 the enumerated type. For -Wswitch-enum, or for -Wswitch when
6779 there is no default case, check that exactly all enumeration
6780 literals are covered by the cases. */
6782 /* Clearing COND if it is not an integer constant simplifies
6783 the tests inside the loop below. */
6784 if (TREE_CODE (cond
) != INTEGER_CST
)
6787 /* The time complexity here is O(N*lg(N)) worst case, but for the
6788 common case of monotonically increasing enumerators, it is
6789 O(N), since the nature of the splay tree will keep the next
6790 element adjacent to the root at all times. */
6792 for (chain
= TYPE_VALUES (type
); chain
; chain
= TREE_CHAIN (chain
))
6794 tree value
= TREE_VALUE (chain
);
6795 if (TREE_CODE (value
) == CONST_DECL
)
6796 value
= DECL_INITIAL (value
);
6797 node
= splay_tree_lookup (cases
, (splay_tree_key
) value
);
6800 /* Mark the CASE_LOW part of the case entry as seen. */
6801 tree label
= (tree
) node
->value
;
6802 CASE_LOW_SEEN (label
) = 1;
6806 /* Even though there wasn't an exact match, there might be a
6807 case range which includes the enumerator's value. */
6808 node
= splay_tree_predecessor (cases
, (splay_tree_key
) value
);
6809 if (node
&& CASE_HIGH ((tree
) node
->value
))
6811 tree label
= (tree
) node
->value
;
6812 int cmp
= tree_int_cst_compare (CASE_HIGH (label
), value
);
6815 /* If we match the upper bound exactly, mark the CASE_HIGH
6816 part of the case entry as seen. */
6818 CASE_HIGH_SEEN (label
) = 1;
6823 /* We've now determined that this enumerated literal isn't
6824 handled by the case labels of the switch statement. */
6826 /* If the switch expression is a constant, we only really care
6827 about whether that constant is handled by the switch. */
6828 if (cond
&& tree_int_cst_compare (cond
, value
))
6831 /* If there is a default_node, the only relevant option is
6832 Wswitch-enum. Otherwise, if both are enabled then we prefer
6833 to warn using -Wswitch because -Wswitch is enabled by -Wall
6834 while -Wswitch-enum is explicit. */
6835 warning_at (switch_location
,
6836 (default_node
|| !warn_switch
6839 "enumeration value %qE not handled in switch",
6840 TREE_PURPOSE (chain
));
6843 /* Warn if there are case expressions that don't correspond to
6844 enumerators. This can occur since C and C++ don't enforce
6845 type-checking of assignments to enumeration variables.
6847 The time complexity here is now always O(N) worst case, since
6848 we should have marked both the lower bound and upper bound of
6849 every disjoint case label, with CASE_LOW_SEEN and CASE_HIGH_SEEN
6850 above. This scan also resets those fields. */
6852 splay_tree_foreach (cases
, match_case_to_enum
, type
);
6855 /* Finish an expression taking the address of LABEL (an
6856 IDENTIFIER_NODE). Returns an expression for the address.
6858 LOC is the location for the expression returned. */
6861 finish_label_address_expr (tree label
, location_t loc
)
6865 pedwarn (input_location
, OPT_Wpedantic
, "taking the address of a label is non-standard");
6867 if (label
== error_mark_node
)
6868 return error_mark_node
;
6870 label
= lookup_label (label
);
6871 if (label
== NULL_TREE
)
6872 result
= null_pointer_node
;
6875 TREE_USED (label
) = 1;
6876 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
6877 /* The current function is not necessarily uninlinable.
6878 Computed gotos are incompatible with inlining, but the value
6879 here could be used only in a diagnostic, for example. */
6880 protected_set_expr_location (result
, loc
);
6887 /* Given a boolean expression ARG, return a tree representing an increment
6888 or decrement (as indicated by CODE) of ARG. The front end must check for
6889 invalid cases (e.g., decrement in C++). */
6891 boolean_increment (enum tree_code code
, tree arg
)
6894 tree true_res
= build_int_cst (TREE_TYPE (arg
), 1);
6896 arg
= stabilize_reference (arg
);
6899 case PREINCREMENT_EXPR
:
6900 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
6902 case POSTINCREMENT_EXPR
:
6903 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
6904 arg
= save_expr (arg
);
6905 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
6906 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
6908 case PREDECREMENT_EXPR
:
6909 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
6910 invert_truthvalue_loc (input_location
, arg
));
6912 case POSTDECREMENT_EXPR
:
6913 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
6914 invert_truthvalue_loc (input_location
, arg
));
6915 arg
= save_expr (arg
);
6916 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
6917 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
6922 TREE_SIDE_EFFECTS (val
) = 1;
6926 /* Built-in macros for stddef.h and stdint.h, that require macros
6927 defined in this file. */
6929 c_stddef_cpp_builtins(void)
6931 builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE
, 0);
6932 builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE
, 0);
6933 builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE
, 0);
6934 builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE
, 0);
6935 builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE
, 0);
6936 builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE
, 0);
6937 builtin_define_with_value ("__CHAR16_TYPE__", CHAR16_TYPE
, 0);
6938 builtin_define_with_value ("__CHAR32_TYPE__", CHAR32_TYPE
, 0);
6939 if (SIG_ATOMIC_TYPE
)
6940 builtin_define_with_value ("__SIG_ATOMIC_TYPE__", SIG_ATOMIC_TYPE
, 0);
6942 builtin_define_with_value ("__INT8_TYPE__", INT8_TYPE
, 0);
6944 builtin_define_with_value ("__INT16_TYPE__", INT16_TYPE
, 0);
6946 builtin_define_with_value ("__INT32_TYPE__", INT32_TYPE
, 0);
6948 builtin_define_with_value ("__INT64_TYPE__", INT64_TYPE
, 0);
6950 builtin_define_with_value ("__UINT8_TYPE__", UINT8_TYPE
, 0);
6952 builtin_define_with_value ("__UINT16_TYPE__", UINT16_TYPE
, 0);
6954 builtin_define_with_value ("__UINT32_TYPE__", UINT32_TYPE
, 0);
6956 builtin_define_with_value ("__UINT64_TYPE__", UINT64_TYPE
, 0);
6957 if (INT_LEAST8_TYPE
)
6958 builtin_define_with_value ("__INT_LEAST8_TYPE__", INT_LEAST8_TYPE
, 0);
6959 if (INT_LEAST16_TYPE
)
6960 builtin_define_with_value ("__INT_LEAST16_TYPE__", INT_LEAST16_TYPE
, 0);
6961 if (INT_LEAST32_TYPE
)
6962 builtin_define_with_value ("__INT_LEAST32_TYPE__", INT_LEAST32_TYPE
, 0);
6963 if (INT_LEAST64_TYPE
)
6964 builtin_define_with_value ("__INT_LEAST64_TYPE__", INT_LEAST64_TYPE
, 0);
6965 if (UINT_LEAST8_TYPE
)
6966 builtin_define_with_value ("__UINT_LEAST8_TYPE__", UINT_LEAST8_TYPE
, 0);
6967 if (UINT_LEAST16_TYPE
)
6968 builtin_define_with_value ("__UINT_LEAST16_TYPE__", UINT_LEAST16_TYPE
, 0);
6969 if (UINT_LEAST32_TYPE
)
6970 builtin_define_with_value ("__UINT_LEAST32_TYPE__", UINT_LEAST32_TYPE
, 0);
6971 if (UINT_LEAST64_TYPE
)
6972 builtin_define_with_value ("__UINT_LEAST64_TYPE__", UINT_LEAST64_TYPE
, 0);
6974 builtin_define_with_value ("__INT_FAST8_TYPE__", INT_FAST8_TYPE
, 0);
6975 if (INT_FAST16_TYPE
)
6976 builtin_define_with_value ("__INT_FAST16_TYPE__", INT_FAST16_TYPE
, 0);
6977 if (INT_FAST32_TYPE
)
6978 builtin_define_with_value ("__INT_FAST32_TYPE__", INT_FAST32_TYPE
, 0);
6979 if (INT_FAST64_TYPE
)
6980 builtin_define_with_value ("__INT_FAST64_TYPE__", INT_FAST64_TYPE
, 0);
6981 if (UINT_FAST8_TYPE
)
6982 builtin_define_with_value ("__UINT_FAST8_TYPE__", UINT_FAST8_TYPE
, 0);
6983 if (UINT_FAST16_TYPE
)
6984 builtin_define_with_value ("__UINT_FAST16_TYPE__", UINT_FAST16_TYPE
, 0);
6985 if (UINT_FAST32_TYPE
)
6986 builtin_define_with_value ("__UINT_FAST32_TYPE__", UINT_FAST32_TYPE
, 0);
6987 if (UINT_FAST64_TYPE
)
6988 builtin_define_with_value ("__UINT_FAST64_TYPE__", UINT_FAST64_TYPE
, 0);
6990 builtin_define_with_value ("__INTPTR_TYPE__", INTPTR_TYPE
, 0);
6992 builtin_define_with_value ("__UINTPTR_TYPE__", UINTPTR_TYPE
, 0);
6996 c_init_attributes (void)
6998 /* Fill in the built_in_attributes array. */
6999 #define DEF_ATTR_NULL_TREE(ENUM) \
7000 built_in_attributes[(int) ENUM] = NULL_TREE;
7001 #define DEF_ATTR_INT(ENUM, VALUE) \
7002 built_in_attributes[(int) ENUM] = build_int_cst (integer_type_node, VALUE);
7003 #define DEF_ATTR_STRING(ENUM, VALUE) \
7004 built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
7005 #define DEF_ATTR_IDENT(ENUM, STRING) \
7006 built_in_attributes[(int) ENUM] = get_identifier (STRING);
7007 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
7008 built_in_attributes[(int) ENUM] \
7009 = tree_cons (built_in_attributes[(int) PURPOSE], \
7010 built_in_attributes[(int) VALUE], \
7011 built_in_attributes[(int) CHAIN]);
7012 #include "builtin-attrs.def"
7013 #undef DEF_ATTR_NULL_TREE
7015 #undef DEF_ATTR_IDENT
7016 #undef DEF_ATTR_TREE_LIST
7019 /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain
7020 identifier as an argument, so the front end shouldn't look it up. */
7023 attribute_takes_identifier_p (const_tree attr_id
)
7025 const struct attribute_spec
*spec
= lookup_attribute_spec (attr_id
);
7027 /* Unknown attribute that we'll end up ignoring, return true so we
7028 don't complain about an identifier argument. */
7030 else if (!strcmp ("mode", spec
->name
)
7031 || !strcmp ("format", spec
->name
)
7032 || !strcmp ("cleanup", spec
->name
))
7035 return targetm
.attribute_takes_identifier_p (attr_id
);
7038 /* Attribute handlers common to C front ends. */
7040 /* Handle a "packed" attribute; arguments as in
7041 struct attribute_spec.handler. */
7044 handle_packed_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7045 int flags
, bool *no_add_attrs
)
7049 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7050 *node
= build_variant_type_copy (*node
);
7051 TYPE_PACKED (*node
) = 1;
7053 else if (TREE_CODE (*node
) == FIELD_DECL
)
7055 if (TYPE_ALIGN (TREE_TYPE (*node
)) <= BITS_PER_UNIT
7056 /* Still pack bitfields. */
7057 && ! DECL_INITIAL (*node
))
7058 warning (OPT_Wattributes
,
7059 "%qE attribute ignored for field of type %qT",
7060 name
, TREE_TYPE (*node
));
7062 DECL_PACKED (*node
) = 1;
7064 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
7065 used for DECL_REGISTER. It wouldn't mean anything anyway.
7066 We can't set DECL_PACKED on the type of a TYPE_DECL, because
7067 that changes what the typedef is typing. */
7070 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7071 *no_add_attrs
= true;
7077 /* Handle a "nocommon" attribute; arguments as in
7078 struct attribute_spec.handler. */
7081 handle_nocommon_attribute (tree
*node
, tree name
,
7082 tree
ARG_UNUSED (args
),
7083 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7086 DECL_COMMON (*node
) = 0;
7089 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7090 *no_add_attrs
= true;
7096 /* Handle a "common" attribute; arguments as in
7097 struct attribute_spec.handler. */
7100 handle_common_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7101 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7104 DECL_COMMON (*node
) = 1;
7107 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7108 *no_add_attrs
= true;
7114 /* Handle a "noreturn" attribute; arguments as in
7115 struct attribute_spec.handler. */
7118 handle_noreturn_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7119 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7121 tree type
= TREE_TYPE (*node
);
7123 /* See FIXME comment in c_common_attribute_table. */
7124 if (TREE_CODE (*node
) == FUNCTION_DECL
7125 || objc_method_decl (TREE_CODE (*node
)))
7126 TREE_THIS_VOLATILE (*node
) = 1;
7127 else if (TREE_CODE (type
) == POINTER_TYPE
7128 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
7130 = (build_qualified_type
7132 (build_type_variant (TREE_TYPE (type
),
7133 TYPE_READONLY (TREE_TYPE (type
)), 1)),
7134 TYPE_QUALS (type
)));
7137 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7138 *no_add_attrs
= true;
7144 /* Handle a "hot" and attribute; arguments as in
7145 struct attribute_spec.handler. */
7148 handle_hot_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7149 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7151 if (TREE_CODE (*node
) == FUNCTION_DECL
7152 || TREE_CODE (*node
) == LABEL_DECL
)
7154 if (lookup_attribute ("cold", DECL_ATTRIBUTES (*node
)) != NULL
)
7156 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
7157 "with attribute %qs", name
, "cold");
7158 *no_add_attrs
= true;
7160 /* Most of the rest of the hot processing is done later with
7161 lookup_attribute. */
7165 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7166 *no_add_attrs
= true;
7172 /* Handle a "cold" and attribute; arguments as in
7173 struct attribute_spec.handler. */
7176 handle_cold_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7177 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7179 if (TREE_CODE (*node
) == FUNCTION_DECL
7180 || TREE_CODE (*node
) == LABEL_DECL
)
7182 if (lookup_attribute ("hot", DECL_ATTRIBUTES (*node
)) != NULL
)
7184 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
7185 "with attribute %qs", name
, "hot");
7186 *no_add_attrs
= true;
7188 /* Most of the rest of the cold processing is done later with
7189 lookup_attribute. */
7193 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7194 *no_add_attrs
= true;
7200 /* Handle a "no_sanitize_address" attribute; arguments as in
7201 struct attribute_spec.handler. */
7204 handle_no_sanitize_address_attribute (tree
*node
, tree name
, tree
, int,
7207 if (TREE_CODE (*node
) != FUNCTION_DECL
)
7209 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7210 *no_add_attrs
= true;
7216 /* Handle a "no_address_safety_analysis" attribute; arguments as in
7217 struct attribute_spec.handler. */
7220 handle_no_address_safety_analysis_attribute (tree
*node
, tree name
, tree
, int,
7223 if (TREE_CODE (*node
) != FUNCTION_DECL
)
7224 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7225 else if (!lookup_attribute ("no_sanitize_address", DECL_ATTRIBUTES (*node
)))
7226 DECL_ATTRIBUTES (*node
)
7227 = tree_cons (get_identifier ("no_sanitize_address"),
7228 NULL_TREE
, DECL_ATTRIBUTES (*node
));
7229 *no_add_attrs
= true;
7233 /* Handle a "no_sanitize_undefined" attribute; arguments as in
7234 struct attribute_spec.handler. */
7237 handle_no_sanitize_undefined_attribute (tree
*node
, tree name
, tree
, int,
7240 if (TREE_CODE (*node
) != FUNCTION_DECL
)
7242 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7243 *no_add_attrs
= true;
7249 /* Handle a "stack_protect" attribute; arguments as in
7250 struct attribute_spec.handler. */
7252 handle_stack_protect_attribute (tree
*node
, tree name
, tree
, int,
7255 if (TREE_CODE (*node
) != FUNCTION_DECL
)
7257 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7258 *no_add_attrs
= true;
7261 DECL_ATTRIBUTES (*node
)
7262 = tree_cons (get_identifier ("stack_protect"),
7263 NULL_TREE
, DECL_ATTRIBUTES (*node
));
7268 /* Handle a "noinline" attribute; arguments as in
7269 struct attribute_spec.handler. */
7272 handle_noinline_attribute (tree
*node
, tree name
,
7273 tree
ARG_UNUSED (args
),
7274 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7276 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7278 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node
)))
7280 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
7281 "with attribute %qs", name
, "always_inline");
7282 *no_add_attrs
= true;
7285 DECL_UNINLINABLE (*node
) = 1;
7289 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7290 *no_add_attrs
= true;
7296 /* Handle a "noclone" attribute; arguments as in
7297 struct attribute_spec.handler. */
7300 handle_noclone_attribute (tree
*node
, tree name
,
7301 tree
ARG_UNUSED (args
),
7302 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7304 if (TREE_CODE (*node
) != FUNCTION_DECL
)
7306 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7307 *no_add_attrs
= true;
7313 /* Handle a "no_icf" attribute; arguments as in
7314 struct attribute_spec.handler. */
7317 handle_noicf_attribute (tree
*node
, tree name
,
7318 tree
ARG_UNUSED (args
),
7319 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7321 if (TREE_CODE (*node
) != FUNCTION_DECL
)
7323 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7324 *no_add_attrs
= true;
7331 /* Handle a "always_inline" attribute; arguments as in
7332 struct attribute_spec.handler. */
7335 handle_always_inline_attribute (tree
*node
, tree name
,
7336 tree
ARG_UNUSED (args
),
7337 int ARG_UNUSED (flags
),
7340 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7342 if (lookup_attribute ("noinline", DECL_ATTRIBUTES (*node
)))
7344 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
7345 "with %qs attribute", name
, "noinline");
7346 *no_add_attrs
= true;
7349 /* Set the attribute and mark it for disregarding inline
7351 DECL_DISREGARD_INLINE_LIMITS (*node
) = 1;
7355 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7356 *no_add_attrs
= true;
7362 /* Handle a "gnu_inline" attribute; arguments as in
7363 struct attribute_spec.handler. */
7366 handle_gnu_inline_attribute (tree
*node
, tree name
,
7367 tree
ARG_UNUSED (args
),
7368 int ARG_UNUSED (flags
),
7371 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
7373 /* Do nothing else, just set the attribute. We'll get at
7374 it later with lookup_attribute. */
7378 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7379 *no_add_attrs
= true;
7385 /* Handle a "leaf" attribute; arguments as in
7386 struct attribute_spec.handler. */
7389 handle_leaf_attribute (tree
*node
, tree name
,
7390 tree
ARG_UNUSED (args
),
7391 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7393 if (TREE_CODE (*node
) != FUNCTION_DECL
)
7395 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7396 *no_add_attrs
= true;
7398 if (!TREE_PUBLIC (*node
))
7400 warning (OPT_Wattributes
, "%qE attribute has no effect on unit local functions", name
);
7401 *no_add_attrs
= true;
7407 /* Handle an "artificial" attribute; arguments as in
7408 struct attribute_spec.handler. */
7411 handle_artificial_attribute (tree
*node
, tree name
,
7412 tree
ARG_UNUSED (args
),
7413 int ARG_UNUSED (flags
),
7416 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
7418 /* Do nothing else, just set the attribute. We'll get at
7419 it later with lookup_attribute. */
7423 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7424 *no_add_attrs
= true;
7430 /* Handle a "flatten" attribute; arguments as in
7431 struct attribute_spec.handler. */
7434 handle_flatten_attribute (tree
*node
, tree name
,
7435 tree args ATTRIBUTE_UNUSED
,
7436 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
7438 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7439 /* Do nothing else, just set the attribute. We'll get at
7440 it later with lookup_attribute. */
7444 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7445 *no_add_attrs
= true;
7451 /* Handle a "warning" or "error" attribute; arguments as in
7452 struct attribute_spec.handler. */
7455 handle_error_attribute (tree
*node
, tree name
, tree args
,
7456 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7458 if (TREE_CODE (*node
) == FUNCTION_DECL
7459 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
7460 /* Do nothing else, just set the attribute. We'll get at
7461 it later with lookup_attribute. */
7465 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7466 *no_add_attrs
= true;
7472 /* Handle a "used" attribute; arguments as in
7473 struct attribute_spec.handler. */
7476 handle_used_attribute (tree
*pnode
, tree name
, tree
ARG_UNUSED (args
),
7477 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7481 if (TREE_CODE (node
) == FUNCTION_DECL
7482 || (VAR_P (node
) && TREE_STATIC (node
))
7483 || (TREE_CODE (node
) == TYPE_DECL
))
7485 TREE_USED (node
) = 1;
7486 DECL_PRESERVE_P (node
) = 1;
7488 DECL_READ_P (node
) = 1;
7492 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7493 *no_add_attrs
= true;
7499 /* Handle a "unused" attribute; arguments as in
7500 struct attribute_spec.handler. */
7503 handle_unused_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7504 int flags
, bool *no_add_attrs
)
7510 if (TREE_CODE (decl
) == PARM_DECL
7511 || VAR_OR_FUNCTION_DECL_P (decl
)
7512 || TREE_CODE (decl
) == LABEL_DECL
7513 || TREE_CODE (decl
) == TYPE_DECL
)
7515 TREE_USED (decl
) = 1;
7516 if (VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
)
7517 DECL_READ_P (decl
) = 1;
7521 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7522 *no_add_attrs
= true;
7527 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7528 *node
= build_variant_type_copy (*node
);
7529 TREE_USED (*node
) = 1;
7535 /* Handle a "externally_visible" attribute; arguments as in
7536 struct attribute_spec.handler. */
7539 handle_externally_visible_attribute (tree
*pnode
, tree name
,
7540 tree
ARG_UNUSED (args
),
7541 int ARG_UNUSED (flags
),
7546 if (VAR_OR_FUNCTION_DECL_P (node
))
7548 if ((!TREE_STATIC (node
) && TREE_CODE (node
) != FUNCTION_DECL
7549 && !DECL_EXTERNAL (node
)) || !TREE_PUBLIC (node
))
7551 warning (OPT_Wattributes
,
7552 "%qE attribute have effect only on public objects", name
);
7553 *no_add_attrs
= true;
7558 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7559 *no_add_attrs
= true;
7565 /* Handle the "no_reorder" attribute. Arguments as in
7566 struct attribute_spec.handler. */
7569 handle_no_reorder_attribute (tree
*pnode
,
7577 if (!VAR_OR_FUNCTION_DECL_P (node
)
7578 && !(TREE_STATIC (node
) || DECL_EXTERNAL (node
)))
7580 warning (OPT_Wattributes
,
7581 "%qE attribute only affects top level objects",
7583 *no_add_attrs
= true;
7589 /* Handle a "const" attribute; arguments as in
7590 struct attribute_spec.handler. */
7593 handle_const_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7594 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7596 tree type
= TREE_TYPE (*node
);
7598 /* See FIXME comment on noreturn in c_common_attribute_table. */
7599 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7600 TREE_READONLY (*node
) = 1;
7601 else if (TREE_CODE (type
) == POINTER_TYPE
7602 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
7604 = (build_qualified_type
7606 (build_type_variant (TREE_TYPE (type
), 1,
7607 TREE_THIS_VOLATILE (TREE_TYPE (type
)))),
7608 TYPE_QUALS (type
)));
7611 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7612 *no_add_attrs
= true;
7618 /* Handle a "transparent_union" attribute; arguments as in
7619 struct attribute_spec.handler. */
7622 handle_transparent_union_attribute (tree
*node
, tree name
,
7623 tree
ARG_UNUSED (args
), int flags
,
7628 *no_add_attrs
= true;
7631 if (TREE_CODE (*node
) == TYPE_DECL
7632 && ! (flags
& ATTR_FLAG_CXX11
))
7633 node
= &TREE_TYPE (*node
);
7636 if (TREE_CODE (type
) == UNION_TYPE
)
7638 /* Make sure that the first field will work for a transparent union.
7639 If the type isn't complete yet, leave the check to the code in
7641 if (TYPE_SIZE (type
))
7643 tree first
= first_field (type
);
7644 if (first
== NULL_TREE
7645 || DECL_ARTIFICIAL (first
)
7646 || TYPE_MODE (type
) != DECL_MODE (first
))
7650 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7652 /* If the type isn't complete yet, setting the flag
7653 on a variant wouldn't ever be checked. */
7654 if (!TYPE_SIZE (type
))
7657 /* build_duplicate_type doesn't work for C++. */
7658 if (c_dialect_cxx ())
7661 /* A type variant isn't good enough, since we don't a cast
7662 to such a type removed as a no-op. */
7663 *node
= type
= build_duplicate_type (type
);
7666 TYPE_TRANSPARENT_AGGR (type
) = 1;
7671 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7675 /* Subroutine of handle_{con,de}structor_attribute. Evaluate ARGS to
7676 get the requested priority for a constructor or destructor,
7677 possibly issuing diagnostics for invalid or reserved
7680 static priority_type
7681 get_priority (tree args
, bool is_destructor
)
7687 return DEFAULT_INIT_PRIORITY
;
7689 if (!SUPPORTS_INIT_PRIORITY
)
7692 error ("destructor priorities are not supported");
7694 error ("constructor priorities are not supported");
7695 return DEFAULT_INIT_PRIORITY
;
7698 arg
= TREE_VALUE (args
);
7699 if (TREE_CODE (arg
) == IDENTIFIER_NODE
)
7701 if (arg
== error_mark_node
)
7702 return DEFAULT_INIT_PRIORITY
;
7703 arg
= default_conversion (arg
);
7704 if (!tree_fits_shwi_p (arg
)
7705 || !INTEGRAL_TYPE_P (TREE_TYPE (arg
)))
7708 pri
= tree_to_shwi (arg
);
7709 if (pri
< 0 || pri
> MAX_INIT_PRIORITY
)
7712 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
7716 "destructor priorities from 0 to %d are reserved "
7717 "for the implementation",
7718 MAX_RESERVED_INIT_PRIORITY
);
7721 "constructor priorities from 0 to %d are reserved "
7722 "for the implementation",
7723 MAX_RESERVED_INIT_PRIORITY
);
7729 error ("destructor priorities must be integers from 0 to %d inclusive",
7732 error ("constructor priorities must be integers from 0 to %d inclusive",
7734 return DEFAULT_INIT_PRIORITY
;
7737 /* Handle a "constructor" attribute; arguments as in
7738 struct attribute_spec.handler. */
7741 handle_constructor_attribute (tree
*node
, tree name
, tree args
,
7742 int ARG_UNUSED (flags
),
7746 tree type
= TREE_TYPE (decl
);
7748 if (TREE_CODE (decl
) == FUNCTION_DECL
7749 && TREE_CODE (type
) == FUNCTION_TYPE
7750 && decl_function_context (decl
) == 0)
7752 priority_type priority
;
7753 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
7754 priority
= get_priority (args
, /*is_destructor=*/false);
7755 SET_DECL_INIT_PRIORITY (decl
, priority
);
7756 TREE_USED (decl
) = 1;
7760 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7761 *no_add_attrs
= true;
7767 /* Handle a "destructor" attribute; arguments as in
7768 struct attribute_spec.handler. */
7771 handle_destructor_attribute (tree
*node
, tree name
, tree args
,
7772 int ARG_UNUSED (flags
),
7776 tree type
= TREE_TYPE (decl
);
7778 if (TREE_CODE (decl
) == FUNCTION_DECL
7779 && TREE_CODE (type
) == FUNCTION_TYPE
7780 && decl_function_context (decl
) == 0)
7782 priority_type priority
;
7783 DECL_STATIC_DESTRUCTOR (decl
) = 1;
7784 priority
= get_priority (args
, /*is_destructor=*/true);
7785 SET_DECL_FINI_PRIORITY (decl
, priority
);
7786 TREE_USED (decl
) = 1;
7790 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7791 *no_add_attrs
= true;
7797 /* Nonzero if the mode is a valid vector mode for this architecture.
7798 This returns nonzero even if there is no hardware support for the
7799 vector mode, but we can emulate with narrower modes. */
7802 vector_mode_valid_p (machine_mode mode
)
7804 enum mode_class mclass
= GET_MODE_CLASS (mode
);
7805 machine_mode innermode
;
7807 /* Doh! What's going on? */
7808 if (mclass
!= MODE_VECTOR_INT
7809 && mclass
!= MODE_VECTOR_FLOAT
7810 && mclass
!= MODE_VECTOR_FRACT
7811 && mclass
!= MODE_VECTOR_UFRACT
7812 && mclass
!= MODE_VECTOR_ACCUM
7813 && mclass
!= MODE_VECTOR_UACCUM
)
7816 /* Hardware support. Woo hoo! */
7817 if (targetm
.vector_mode_supported_p (mode
))
7820 innermode
= GET_MODE_INNER (mode
);
7822 /* We should probably return 1 if requesting V4DI and we have no DI,
7823 but we have V2DI, but this is probably very unlikely. */
7825 /* If we have support for the inner mode, we can safely emulate it.
7826 We may not have V2DI, but me can emulate with a pair of DIs. */
7827 return targetm
.scalar_mode_supported_p (innermode
);
7831 /* Handle a "mode" attribute; arguments as in
7832 struct attribute_spec.handler. */
7835 handle_mode_attribute (tree
*node
, tree name
, tree args
,
7836 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7839 tree ident
= TREE_VALUE (args
);
7841 *no_add_attrs
= true;
7843 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
7844 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7848 const char *p
= IDENTIFIER_POINTER (ident
);
7849 int len
= strlen (p
);
7850 machine_mode mode
= VOIDmode
;
7854 if (len
> 4 && p
[0] == '_' && p
[1] == '_'
7855 && p
[len
- 1] == '_' && p
[len
- 2] == '_')
7857 char *newp
= (char *) alloca (len
- 1);
7859 strcpy (newp
, &p
[2]);
7860 newp
[len
- 4] = '\0';
7864 /* Change this type to have a type with the specified mode.
7865 First check for the special modes. */
7866 if (!strcmp (p
, "byte"))
7868 else if (!strcmp (p
, "word"))
7870 else if (!strcmp (p
, "pointer"))
7872 else if (!strcmp (p
, "libgcc_cmp_return"))
7873 mode
= targetm
.libgcc_cmp_return_mode ();
7874 else if (!strcmp (p
, "libgcc_shift_count"))
7875 mode
= targetm
.libgcc_shift_count_mode ();
7876 else if (!strcmp (p
, "unwind_word"))
7877 mode
= targetm
.unwind_word_mode ();
7879 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
7880 if (!strcmp (p
, GET_MODE_NAME (j
)))
7882 mode
= (machine_mode
) j
;
7886 if (mode
== VOIDmode
)
7888 error ("unknown machine mode %qE", ident
);
7893 switch (GET_MODE_CLASS (mode
))
7896 case MODE_PARTIAL_INT
:
7898 case MODE_DECIMAL_FLOAT
:
7903 valid_mode
= targetm
.scalar_mode_supported_p (mode
);
7906 case MODE_COMPLEX_INT
:
7907 case MODE_COMPLEX_FLOAT
:
7908 valid_mode
= targetm
.scalar_mode_supported_p (GET_MODE_INNER (mode
));
7911 case MODE_VECTOR_INT
:
7912 case MODE_VECTOR_FLOAT
:
7913 case MODE_VECTOR_FRACT
:
7914 case MODE_VECTOR_UFRACT
:
7915 case MODE_VECTOR_ACCUM
:
7916 case MODE_VECTOR_UACCUM
:
7917 warning (OPT_Wattributes
, "specifying vector types with "
7918 "__attribute__ ((mode)) is deprecated");
7919 warning (OPT_Wattributes
,
7920 "use __attribute__ ((vector_size)) instead");
7921 valid_mode
= vector_mode_valid_p (mode
);
7929 error ("unable to emulate %qs", p
);
7933 if (POINTER_TYPE_P (type
))
7935 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
7936 tree (*fn
)(tree
, machine_mode
, bool);
7938 if (!targetm
.addr_space
.valid_pointer_mode (mode
, as
))
7940 error ("invalid pointer mode %qs", p
);
7944 if (TREE_CODE (type
) == POINTER_TYPE
)
7945 fn
= build_pointer_type_for_mode
;
7947 fn
= build_reference_type_for_mode
;
7948 typefm
= fn (TREE_TYPE (type
), mode
, false);
7952 /* For fixed-point modes, we need to test if the signness of type
7953 and the machine mode are consistent. */
7954 if (ALL_FIXED_POINT_MODE_P (mode
)
7955 && TYPE_UNSIGNED (type
) != UNSIGNED_FIXED_POINT_MODE_P (mode
))
7957 error ("signedness of type and machine mode %qs don%'t match", p
);
7960 /* For fixed-point modes, we need to pass saturating info. */
7961 typefm
= lang_hooks
.types
.type_for_mode (mode
,
7962 ALL_FIXED_POINT_MODE_P (mode
) ? TYPE_SATURATING (type
)
7963 : TYPE_UNSIGNED (type
));
7966 if (typefm
== NULL_TREE
)
7968 error ("no data type for mode %qs", p
);
7971 else if (TREE_CODE (type
) == ENUMERAL_TYPE
)
7973 /* For enumeral types, copy the precision from the integer
7974 type returned above. If not an INTEGER_TYPE, we can't use
7975 this mode for this type. */
7976 if (TREE_CODE (typefm
) != INTEGER_TYPE
)
7978 error ("cannot use mode %qs for enumeral types", p
);
7982 if (flags
& ATTR_FLAG_TYPE_IN_PLACE
)
7984 TYPE_PRECISION (type
) = TYPE_PRECISION (typefm
);
7989 /* We cannot build a type variant, as there's code that assumes
7990 that TYPE_MAIN_VARIANT has the same mode. This includes the
7991 debug generators. Instead, create a subrange type. This
7992 results in all of the enumeral values being emitted only once
7993 in the original, and the subtype gets them by reference. */
7994 if (TYPE_UNSIGNED (type
))
7995 typefm
= make_unsigned_type (TYPE_PRECISION (typefm
));
7997 typefm
= make_signed_type (TYPE_PRECISION (typefm
));
7998 TREE_TYPE (typefm
) = type
;
8001 else if (VECTOR_MODE_P (mode
)
8002 ? TREE_CODE (type
) != TREE_CODE (TREE_TYPE (typefm
))
8003 : TREE_CODE (type
) != TREE_CODE (typefm
))
8005 error ("mode %qs applied to inappropriate type", p
);
8015 /* Handle a "section" attribute; arguments as in
8016 struct attribute_spec.handler. */
8019 handle_section_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
8020 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8024 if (!targetm_common
.have_named_sections
)
8026 error_at (DECL_SOURCE_LOCATION (*node
),
8027 "section attributes are not supported for this target");
8031 user_defined_section_attribute
= true;
8033 if (!VAR_OR_FUNCTION_DECL_P (decl
))
8035 error ("section attribute not allowed for %q+D", *node
);
8039 if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
8041 error ("section attribute argument not a string constant");
8046 && current_function_decl
!= NULL_TREE
8047 && !TREE_STATIC (decl
))
8049 error_at (DECL_SOURCE_LOCATION (decl
),
8050 "section attribute cannot be specified for local variables");
8054 /* The decl may have already been given a section attribute
8055 from a previous declaration. Ensure they match. */
8056 if (DECL_SECTION_NAME (decl
) != NULL
8057 && strcmp (DECL_SECTION_NAME (decl
),
8058 TREE_STRING_POINTER (TREE_VALUE (args
))) != 0)
8060 error ("section of %q+D conflicts with previous declaration", *node
);
8065 && !targetm
.have_tls
&& targetm
.emutls
.tmpl_section
8066 && DECL_THREAD_LOCAL_P (decl
))
8068 error ("section of %q+D cannot be overridden", *node
);
8072 set_decl_section_name (decl
, TREE_STRING_POINTER (TREE_VALUE (args
)));
8076 *no_add_attrs
= true;
8080 /* Check whether ALIGN is a valid user-specified alignment. If so,
8081 return its base-2 log; if not, output an error and return -1. If
8082 ALLOW_ZERO then 0 is valid and should result in a return of -1 with
8085 check_user_alignment (const_tree align
, bool allow_zero
)
8089 if (error_operand_p (align
))
8091 if (TREE_CODE (align
) != INTEGER_CST
8092 || !INTEGRAL_TYPE_P (TREE_TYPE (align
)))
8094 error ("requested alignment is not an integer constant");
8097 else if (allow_zero
&& integer_zerop (align
))
8099 else if (tree_int_cst_sgn (align
) == -1
8100 || (i
= tree_log2 (align
)) == -1)
8102 error ("requested alignment is not a positive power of 2");
8105 else if (i
>= HOST_BITS_PER_INT
- BITS_PER_UNIT_LOG
)
8107 error ("requested alignment is too large");
8114 If in c++-11, check if the c++-11 alignment constraint with respect
8115 to fundamental alignment (in [dcl.align]) are satisfied. If not in
8116 c++-11 mode, does nothing.
8120 [* if the constant expression evaluates to a fundamental alignment,
8121 the alignment requirement of the declared entity shall be the
8122 specified fundamental alignment.
8124 * if the constant expression evaluates to an extended alignment
8125 and the implementation supports that alignment in the context
8126 of the declaration, the alignment of the declared entity shall
8129 * if the constant expression evaluates to an extended alignment
8130 and the implementation does not support that alignment in the
8131 context of the declaration, the program is ill-formed]. */
8134 check_cxx_fundamental_alignment_constraints (tree node
,
8138 bool alignment_too_large_p
= false;
8139 unsigned requested_alignment
= 1U << align_log
;
8140 unsigned max_align
= 0;
8142 if ((!(flags
& ATTR_FLAG_CXX11
) && !warn_cxx_compat
)
8143 || (node
== NULL_TREE
|| node
== error_mark_node
))
8146 if (cxx_fundamental_alignment_p (requested_alignment
))
8151 if (TREE_STATIC (node
))
8153 /* For file scope variables and static members, the target
8154 supports alignments that are at most
8155 MAX_OFILE_ALIGNMENT. */
8156 if (requested_alignment
> (max_align
= MAX_OFILE_ALIGNMENT
))
8157 alignment_too_large_p
= true;
8161 #ifdef BIGGEST_FIELD_ALIGNMENT
8162 #define MAX_TARGET_FIELD_ALIGNMENT BIGGEST_FIELD_ALIGNMENT
8164 #define MAX_TARGET_FIELD_ALIGNMENT BIGGEST_ALIGNMENT
8166 /* For non-static members, the target supports either
8167 alignments that at most either BIGGEST_FIELD_ALIGNMENT
8168 if it is defined or BIGGEST_ALIGNMENT. */
8169 max_align
= MAX_TARGET_FIELD_ALIGNMENT
;
8170 if (TREE_CODE (node
) == FIELD_DECL
8171 && requested_alignment
> (max_align
= MAX_TARGET_FIELD_ALIGNMENT
))
8172 alignment_too_large_p
= true;
8173 #undef MAX_TARGET_FIELD_ALIGNMENT
8174 /* For stack variables, the target supports at most
8175 MAX_STACK_ALIGNMENT. */
8176 else if (decl_function_context (node
) != NULL
8177 && requested_alignment
> (max_align
= MAX_STACK_ALIGNMENT
))
8178 alignment_too_large_p
= true;
8181 else if (TYPE_P (node
))
8183 /* Let's be liberal for types. */
8184 if (requested_alignment
> (max_align
= BIGGEST_ALIGNMENT
))
8185 alignment_too_large_p
= true;
8188 if (alignment_too_large_p
)
8189 pedwarn (input_location
, OPT_Wattributes
,
8190 "requested alignment %d is larger than %d",
8191 requested_alignment
, max_align
);
8193 return !alignment_too_large_p
;
8196 /* Handle a "aligned" attribute; arguments as in
8197 struct attribute_spec.handler. */
8200 handle_aligned_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
8201 int flags
, bool *no_add_attrs
)
8203 tree decl
= NULL_TREE
;
8211 align_expr
= TREE_VALUE (args
);
8212 if (align_expr
&& TREE_CODE (align_expr
) != IDENTIFIER_NODE
8213 && TREE_CODE (align_expr
) != FUNCTION_DECL
)
8214 align_expr
= default_conversion (align_expr
);
8217 align_expr
= size_int (ATTRIBUTE_ALIGNED_VALUE
/ BITS_PER_UNIT
);
8222 type
= &TREE_TYPE (decl
);
8223 is_type
= TREE_CODE (*node
) == TYPE_DECL
;
8225 else if (TYPE_P (*node
))
8226 type
= node
, is_type
= 1;
8228 if ((i
= check_user_alignment (align_expr
, false)) == -1
8229 || !check_cxx_fundamental_alignment_constraints (*node
, i
, flags
))
8230 *no_add_attrs
= true;
8233 if ((flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
8234 /* OK, modify the type in place. */;
8235 /* If we have a TYPE_DECL, then copy the type, so that we
8236 don't accidentally modify a builtin type. See pushdecl. */
8237 else if (decl
&& TREE_TYPE (decl
) != error_mark_node
8238 && DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
)
8240 tree tt
= TREE_TYPE (decl
);
8241 *type
= build_variant_type_copy (*type
);
8242 DECL_ORIGINAL_TYPE (decl
) = tt
;
8243 TYPE_NAME (*type
) = decl
;
8244 TREE_USED (*type
) = TREE_USED (decl
);
8245 TREE_TYPE (decl
) = *type
;
8248 *type
= build_variant_type_copy (*type
);
8250 TYPE_ALIGN (*type
) = (1U << i
) * BITS_PER_UNIT
;
8251 TYPE_USER_ALIGN (*type
) = 1;
8253 else if (! VAR_OR_FUNCTION_DECL_P (decl
)
8254 && TREE_CODE (decl
) != FIELD_DECL
)
8256 error ("alignment may not be specified for %q+D", decl
);
8257 *no_add_attrs
= true;
8259 else if (DECL_USER_ALIGN (decl
)
8260 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
8261 /* C++-11 [dcl.align/4]:
8263 When multiple alignment-specifiers are specified for an
8264 entity, the alignment requirement shall be set to the
8265 strictest specified alignment.
8267 This formally comes from the c++11 specification but we are
8268 doing it for the GNU attribute syntax as well. */
8269 *no_add_attrs
= true;
8270 else if (TREE_CODE (decl
) == FUNCTION_DECL
8271 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
8273 if (DECL_USER_ALIGN (decl
))
8274 error ("alignment for %q+D was previously specified as %d "
8275 "and may not be decreased", decl
,
8276 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
8278 error ("alignment for %q+D must be at least %d", decl
,
8279 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
8280 *no_add_attrs
= true;
8284 DECL_ALIGN (decl
) = (1U << i
) * BITS_PER_UNIT
;
8285 DECL_USER_ALIGN (decl
) = 1;
8291 /* Handle a "weak" attribute; arguments as in
8292 struct attribute_spec.handler. */
8295 handle_weak_attribute (tree
*node
, tree name
,
8296 tree
ARG_UNUSED (args
),
8297 int ARG_UNUSED (flags
),
8298 bool * ARG_UNUSED (no_add_attrs
))
8300 if (TREE_CODE (*node
) == FUNCTION_DECL
8301 && DECL_DECLARED_INLINE_P (*node
))
8303 warning (OPT_Wattributes
, "inline function %q+D declared weak", *node
);
8304 *no_add_attrs
= true;
8306 else if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
8308 error ("indirect function %q+D cannot be declared weak", *node
);
8309 *no_add_attrs
= true;
8312 else if (VAR_OR_FUNCTION_DECL_P (*node
))
8314 struct symtab_node
*n
= symtab_node::get (*node
);
8315 if (n
&& n
->refuse_visibility_changes
)
8316 error ("%+D declared weak after being used", *node
);
8317 declare_weak (*node
);
8320 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8325 /* Handle a "noplt" attribute; arguments as in
8326 struct attribute_spec.handler. */
8329 handle_noplt_attribute (tree
*node
, tree name
,
8330 tree
ARG_UNUSED (args
),
8331 int ARG_UNUSED (flags
),
8332 bool * ARG_UNUSED (no_add_attrs
))
8334 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8336 warning (OPT_Wattributes
,
8337 "%qE attribute is only applicable on functions", name
);
8338 *no_add_attrs
= true;
8344 /* Handle an "alias" or "ifunc" attribute; arguments as in
8345 struct attribute_spec.handler, except that IS_ALIAS tells us
8346 whether this is an alias as opposed to ifunc attribute. */
8349 handle_alias_ifunc_attribute (bool is_alias
, tree
*node
, tree name
, tree args
,
8354 if (TREE_CODE (decl
) != FUNCTION_DECL
8355 && (!is_alias
|| !VAR_P (decl
)))
8357 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8358 *no_add_attrs
= true;
8360 else if ((TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INITIAL (decl
))
8361 || (TREE_CODE (decl
) != FUNCTION_DECL
8362 && TREE_PUBLIC (decl
) && !DECL_EXTERNAL (decl
))
8363 /* A static variable declaration is always a tentative definition,
8364 but the alias is a non-tentative definition which overrides. */
8365 || (TREE_CODE (decl
) != FUNCTION_DECL
8366 && ! TREE_PUBLIC (decl
) && DECL_INITIAL (decl
)))
8368 error ("%q+D defined both normally and as %qE attribute", decl
, name
);
8369 *no_add_attrs
= true;
8373 && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
8374 || lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
))))
8376 error ("weak %q+D cannot be defined %qE", decl
, name
);
8377 *no_add_attrs
= true;
8381 /* Note that the very first time we process a nested declaration,
8382 decl_function_context will not be set. Indeed, *would* never
8383 be set except for the DECL_INITIAL/DECL_EXTERNAL frobbery that
8384 we do below. After such frobbery, pushdecl would set the context.
8385 In any case, this is never what we want. */
8386 else if (decl_function_context (decl
) == 0 && current_function_decl
== NULL
)
8390 id
= TREE_VALUE (args
);
8391 if (TREE_CODE (id
) != STRING_CST
)
8393 error ("attribute %qE argument not a string", name
);
8394 *no_add_attrs
= true;
8397 id
= get_identifier (TREE_STRING_POINTER (id
));
8398 /* This counts as a use of the object pointed to. */
8401 if (TREE_CODE (decl
) == FUNCTION_DECL
)
8402 DECL_INITIAL (decl
) = error_mark_node
;
8404 TREE_STATIC (decl
) = 1;
8407 /* ifuncs are also aliases, so set that attribute too. */
8408 DECL_ATTRIBUTES (decl
)
8409 = tree_cons (get_identifier ("alias"), args
, DECL_ATTRIBUTES (decl
));
8413 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8414 *no_add_attrs
= true;
8417 if (decl_in_symtab_p (*node
))
8419 struct symtab_node
*n
= symtab_node::get (decl
);
8420 if (n
&& n
->refuse_visibility_changes
)
8423 error ("%+D declared alias after being used", decl
);
8425 error ("%+D declared ifunc after being used", decl
);
8433 /* Handle an "alias" or "ifunc" attribute; arguments as in
8434 struct attribute_spec.handler. */
8437 handle_ifunc_attribute (tree
*node
, tree name
, tree args
,
8438 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8440 return handle_alias_ifunc_attribute (false, node
, name
, args
, no_add_attrs
);
8443 /* Handle an "alias" or "ifunc" attribute; arguments as in
8444 struct attribute_spec.handler. */
8447 handle_alias_attribute (tree
*node
, tree name
, tree args
,
8448 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8450 return handle_alias_ifunc_attribute (true, node
, name
, args
, no_add_attrs
);
8453 /* Handle a "weakref" attribute; arguments as in struct
8454 attribute_spec.handler. */
8457 handle_weakref_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
8458 int flags
, bool *no_add_attrs
)
8460 tree attr
= NULL_TREE
;
8462 /* We must ignore the attribute when it is associated with
8463 local-scoped decls, since attribute alias is ignored and many
8464 such symbols do not even have a DECL_WEAK field. */
8465 if (decl_function_context (*node
)
8466 || current_function_decl
8467 || !VAR_OR_FUNCTION_DECL_P (*node
))
8469 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8470 *no_add_attrs
= true;
8474 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
8476 error ("indirect function %q+D cannot be declared weakref", *node
);
8477 *no_add_attrs
= true;
8481 /* The idea here is that `weakref("name")' mutates into `weakref,
8482 alias("name")', and weakref without arguments, in turn,
8483 implicitly adds weak. */
8487 attr
= tree_cons (get_identifier ("alias"), args
, attr
);
8488 attr
= tree_cons (get_identifier ("weakref"), NULL_TREE
, attr
);
8490 *no_add_attrs
= true;
8492 decl_attributes (node
, attr
, flags
);
8496 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node
)))
8497 error_at (DECL_SOURCE_LOCATION (*node
),
8498 "weakref attribute must appear before alias attribute");
8500 /* Can't call declare_weak because it wants this to be TREE_PUBLIC,
8501 and that isn't supported; and because it wants to add it to
8502 the list of weak decls, which isn't helpful. */
8503 DECL_WEAK (*node
) = 1;
8506 if (decl_in_symtab_p (*node
))
8508 struct symtab_node
*n
= symtab_node::get (*node
);
8509 if (n
&& n
->refuse_visibility_changes
)
8510 error ("%+D declared weakref after being used", *node
);
8516 /* Handle an "visibility" attribute; arguments as in
8517 struct attribute_spec.handler. */
8520 handle_visibility_attribute (tree
*node
, tree name
, tree args
,
8521 int ARG_UNUSED (flags
),
8522 bool *ARG_UNUSED (no_add_attrs
))
8525 tree id
= TREE_VALUE (args
);
8526 enum symbol_visibility vis
;
8530 if (TREE_CODE (*node
) == ENUMERAL_TYPE
)
8532 else if (TREE_CODE (*node
) != RECORD_TYPE
&& TREE_CODE (*node
) != UNION_TYPE
)
8534 warning (OPT_Wattributes
, "%qE attribute ignored on non-class types",
8538 else if (TYPE_FIELDS (*node
))
8540 error ("%qE attribute ignored because %qT is already defined",
8545 else if (decl_function_context (decl
) != 0 || !TREE_PUBLIC (decl
))
8547 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8551 if (TREE_CODE (id
) != STRING_CST
)
8553 error ("visibility argument not a string");
8557 /* If this is a type, set the visibility on the type decl. */
8560 decl
= TYPE_NAME (decl
);
8563 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
8565 warning (OPT_Wattributes
, "%qE attribute ignored on types",
8571 if (strcmp (TREE_STRING_POINTER (id
), "default") == 0)
8572 vis
= VISIBILITY_DEFAULT
;
8573 else if (strcmp (TREE_STRING_POINTER (id
), "internal") == 0)
8574 vis
= VISIBILITY_INTERNAL
;
8575 else if (strcmp (TREE_STRING_POINTER (id
), "hidden") == 0)
8576 vis
= VISIBILITY_HIDDEN
;
8577 else if (strcmp (TREE_STRING_POINTER (id
), "protected") == 0)
8578 vis
= VISIBILITY_PROTECTED
;
8581 error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
8582 vis
= VISIBILITY_DEFAULT
;
8585 if (DECL_VISIBILITY_SPECIFIED (decl
)
8586 && vis
!= DECL_VISIBILITY (decl
))
8588 tree attributes
= (TYPE_P (*node
)
8589 ? TYPE_ATTRIBUTES (*node
)
8590 : DECL_ATTRIBUTES (decl
));
8591 if (lookup_attribute ("visibility", attributes
))
8592 error ("%qD redeclared with different visibility", decl
);
8593 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
8594 && lookup_attribute ("dllimport", attributes
))
8595 error ("%qD was declared %qs which implies default visibility",
8597 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
8598 && lookup_attribute ("dllexport", attributes
))
8599 error ("%qD was declared %qs which implies default visibility",
8603 DECL_VISIBILITY (decl
) = vis
;
8604 DECL_VISIBILITY_SPECIFIED (decl
) = 1;
8606 /* Go ahead and attach the attribute to the node as well. This is needed
8607 so we can determine whether we have VISIBILITY_DEFAULT because the
8608 visibility was not specified, or because it was explicitly overridden
8609 from the containing scope. */
8614 /* Determine the ELF symbol visibility for DECL, which is either a
8615 variable or a function. It is an error to use this function if a
8616 definition of DECL is not available in this translation unit.
8617 Returns true if the final visibility has been determined by this
8618 function; false if the caller is free to make additional
8622 c_determine_visibility (tree decl
)
8624 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
8626 /* If the user explicitly specified the visibility with an
8627 attribute, honor that. DECL_VISIBILITY will have been set during
8628 the processing of the attribute. We check for an explicit
8629 attribute, rather than just checking DECL_VISIBILITY_SPECIFIED,
8630 to distinguish the use of an attribute from the use of a "#pragma
8631 GCC visibility push(...)"; in the latter case we still want other
8632 considerations to be able to overrule the #pragma. */
8633 if (lookup_attribute ("visibility", DECL_ATTRIBUTES (decl
))
8634 || (TARGET_DLLIMPORT_DECL_ATTRIBUTES
8635 && (lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl
))
8636 || lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl
)))))
8639 /* Set default visibility to whatever the user supplied with
8640 visibility_specified depending on #pragma GCC visibility. */
8641 if (!DECL_VISIBILITY_SPECIFIED (decl
))
8643 if (visibility_options
.inpragma
8644 || DECL_VISIBILITY (decl
) != default_visibility
)
8646 DECL_VISIBILITY (decl
) = default_visibility
;
8647 DECL_VISIBILITY_SPECIFIED (decl
) = visibility_options
.inpragma
;
8648 /* If visibility changed and DECL already has DECL_RTL, ensure
8649 symbol flags are updated. */
8650 if (((VAR_P (decl
) && TREE_STATIC (decl
))
8651 || TREE_CODE (decl
) == FUNCTION_DECL
)
8652 && DECL_RTL_SET_P (decl
))
8653 make_decl_rtl (decl
);
8659 /* Handle an "tls_model" attribute; arguments as in
8660 struct attribute_spec.handler. */
8663 handle_tls_model_attribute (tree
*node
, tree name
, tree args
,
8664 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8668 enum tls_model kind
;
8670 *no_add_attrs
= true;
8672 if (!VAR_P (decl
) || !DECL_THREAD_LOCAL_P (decl
))
8674 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8678 kind
= DECL_TLS_MODEL (decl
);
8679 id
= TREE_VALUE (args
);
8680 if (TREE_CODE (id
) != STRING_CST
)
8682 error ("tls_model argument not a string");
8686 if (!strcmp (TREE_STRING_POINTER (id
), "local-exec"))
8687 kind
= TLS_MODEL_LOCAL_EXEC
;
8688 else if (!strcmp (TREE_STRING_POINTER (id
), "initial-exec"))
8689 kind
= TLS_MODEL_INITIAL_EXEC
;
8690 else if (!strcmp (TREE_STRING_POINTER (id
), "local-dynamic"))
8691 kind
= optimize
? TLS_MODEL_LOCAL_DYNAMIC
: TLS_MODEL_GLOBAL_DYNAMIC
;
8692 else if (!strcmp (TREE_STRING_POINTER (id
), "global-dynamic"))
8693 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
8695 error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
8697 set_decl_tls_model (decl
, kind
);
8701 /* Handle a "no_instrument_function" attribute; arguments as in
8702 struct attribute_spec.handler. */
8705 handle_no_instrument_function_attribute (tree
*node
, tree name
,
8706 tree
ARG_UNUSED (args
),
8707 int ARG_UNUSED (flags
),
8712 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8714 error_at (DECL_SOURCE_LOCATION (decl
),
8715 "%qE attribute applies only to functions", name
);
8716 *no_add_attrs
= true;
8719 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
8724 /* Handle a "malloc" attribute; arguments as in
8725 struct attribute_spec.handler. */
8728 handle_malloc_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8729 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8731 if (TREE_CODE (*node
) == FUNCTION_DECL
8732 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node
))))
8733 DECL_IS_MALLOC (*node
) = 1;
8736 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8737 *no_add_attrs
= true;
8743 /* Handle a "alloc_size" attribute; arguments as in
8744 struct attribute_spec.handler. */
8747 handle_alloc_size_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
8748 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8750 unsigned arg_count
= type_num_arguments (*node
);
8751 for (; args
; args
= TREE_CHAIN (args
))
8753 tree position
= TREE_VALUE (args
);
8754 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
8755 && TREE_CODE (position
) != FUNCTION_DECL
)
8756 position
= default_conversion (position
);
8758 if (!tree_fits_uhwi_p (position
)
8760 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
8762 warning (OPT_Wattributes
,
8763 "alloc_size parameter outside range");
8764 *no_add_attrs
= true;
8771 /* Handle a "alloc_align" attribute; arguments as in
8772 struct attribute_spec.handler. */
8775 handle_alloc_align_attribute (tree
*node
, tree
, tree args
, int,
8778 unsigned arg_count
= type_num_arguments (*node
);
8779 tree position
= TREE_VALUE (args
);
8780 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
)
8781 position
= default_conversion (position
);
8783 if (!tree_fits_uhwi_p (position
)
8785 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
8787 warning (OPT_Wattributes
,
8788 "alloc_align parameter outside range");
8789 *no_add_attrs
= true;
8795 /* Handle a "assume_aligned" attribute; arguments as in
8796 struct attribute_spec.handler. */
8799 handle_assume_aligned_attribute (tree
*, tree
, tree args
, int,
8802 for (; args
; args
= TREE_CHAIN (args
))
8804 tree position
= TREE_VALUE (args
);
8805 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
8806 && TREE_CODE (position
) != FUNCTION_DECL
)
8807 position
= default_conversion (position
);
8809 if (TREE_CODE (position
) != INTEGER_CST
)
8811 warning (OPT_Wattributes
,
8812 "assume_aligned parameter not integer constant");
8813 *no_add_attrs
= true;
8820 /* Handle a "fn spec" attribute; arguments as in
8821 struct attribute_spec.handler. */
8824 handle_fnspec_attribute (tree
*node ATTRIBUTE_UNUSED
, tree
ARG_UNUSED (name
),
8825 tree args
, int ARG_UNUSED (flags
),
8826 bool *no_add_attrs ATTRIBUTE_UNUSED
)
8829 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
8830 && !TREE_CHAIN (args
));
8834 /* Handle a "bnd_variable_size" attribute; arguments as in
8835 struct attribute_spec.handler. */
8838 handle_bnd_variable_size_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8839 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8841 if (TREE_CODE (*node
) != FIELD_DECL
)
8843 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8844 *no_add_attrs
= true;
8850 /* Handle a "bnd_legacy" attribute; arguments as in
8851 struct attribute_spec.handler. */
8854 handle_bnd_legacy (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8855 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8857 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8859 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8860 *no_add_attrs
= true;
8866 /* Handle a "bnd_instrument" attribute; arguments as in
8867 struct attribute_spec.handler. */
8870 handle_bnd_instrument (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8871 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8873 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8875 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8876 *no_add_attrs
= true;
8882 /* Handle a "warn_unused" attribute; arguments as in
8883 struct attribute_spec.handler. */
8886 handle_warn_unused_attribute (tree
*node
, tree name
,
8887 tree args ATTRIBUTE_UNUSED
,
8888 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
8891 /* Do nothing else, just set the attribute. We'll get at
8892 it later with lookup_attribute. */
8896 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8897 *no_add_attrs
= true;
8903 /* Handle an "omp declare simd" attribute; arguments as in
8904 struct attribute_spec.handler. */
8907 handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int, bool *)
8912 /* Handle an "omp declare target" attribute; arguments as in
8913 struct attribute_spec.handler. */
8916 handle_omp_declare_target_attribute (tree
*, tree
, tree
, int, bool *)
8921 /* Handle a "returns_twice" attribute; arguments as in
8922 struct attribute_spec.handler. */
8925 handle_returns_twice_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8926 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8928 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8929 DECL_IS_RETURNS_TWICE (*node
) = 1;
8932 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8933 *no_add_attrs
= true;
8939 /* Handle a "no_limit_stack" attribute; arguments as in
8940 struct attribute_spec.handler. */
8943 handle_no_limit_stack_attribute (tree
*node
, tree name
,
8944 tree
ARG_UNUSED (args
),
8945 int ARG_UNUSED (flags
),
8950 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8952 error_at (DECL_SOURCE_LOCATION (decl
),
8953 "%qE attribute applies only to functions", name
);
8954 *no_add_attrs
= true;
8956 else if (DECL_INITIAL (decl
))
8958 error_at (DECL_SOURCE_LOCATION (decl
),
8959 "can%'t set %qE attribute after definition", name
);
8960 *no_add_attrs
= true;
8963 DECL_NO_LIMIT_STACK (decl
) = 1;
8968 /* Handle a "pure" attribute; arguments as in
8969 struct attribute_spec.handler. */
8972 handle_pure_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8973 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8975 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8976 DECL_PURE_P (*node
) = 1;
8977 /* ??? TODO: Support types. */
8980 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8981 *no_add_attrs
= true;
8987 /* Digest an attribute list destined for a transactional memory statement.
8988 ALLOWED is the set of attributes that are allowed for this statement;
8989 return the attribute we parsed. Multiple attributes are never allowed. */
8992 parse_tm_stmt_attr (tree attrs
, int allowed
)
8997 for ( ; attrs
; attrs
= TREE_CHAIN (attrs
))
8999 tree a
= TREE_PURPOSE (attrs
);
9002 if (is_attribute_p ("outer", a
))
9003 m
= TM_STMT_ATTR_OUTER
;
9005 if ((m
& allowed
) == 0)
9007 warning (OPT_Wattributes
, "%qE attribute directive ignored", a
);
9016 else if (m_seen
== m
)
9017 warning (OPT_Wattributes
, "%qE attribute duplicated", a
);
9019 warning (OPT_Wattributes
, "%qE attribute follows %qE", a
, a_seen
);
9025 /* Transform a TM attribute name into a maskable integer and back.
9026 Note that NULL (i.e. no attribute) is mapped to UNKNOWN, corresponding
9027 to how the lack of an attribute is treated. */
9030 tm_attr_to_mask (tree attr
)
9034 if (is_attribute_p ("transaction_safe", attr
))
9035 return TM_ATTR_SAFE
;
9036 if (is_attribute_p ("transaction_callable", attr
))
9037 return TM_ATTR_CALLABLE
;
9038 if (is_attribute_p ("transaction_pure", attr
))
9039 return TM_ATTR_PURE
;
9040 if (is_attribute_p ("transaction_unsafe", attr
))
9041 return TM_ATTR_IRREVOCABLE
;
9042 if (is_attribute_p ("transaction_may_cancel_outer", attr
))
9043 return TM_ATTR_MAY_CANCEL_OUTER
;
9048 tm_mask_to_attr (int mask
)
9054 str
= "transaction_safe";
9056 case TM_ATTR_CALLABLE
:
9057 str
= "transaction_callable";
9060 str
= "transaction_pure";
9062 case TM_ATTR_IRREVOCABLE
:
9063 str
= "transaction_unsafe";
9065 case TM_ATTR_MAY_CANCEL_OUTER
:
9066 str
= "transaction_may_cancel_outer";
9071 return get_identifier (str
);
9074 /* Return the first TM attribute seen in LIST. */
9077 find_tm_attribute (tree list
)
9079 for (; list
; list
= TREE_CHAIN (list
))
9081 tree name
= TREE_PURPOSE (list
);
9082 if (tm_attr_to_mask (name
) != 0)
9088 /* Handle the TM attributes; arguments as in struct attribute_spec.handler.
9089 Here we accept only function types, and verify that none of the other
9090 function TM attributes are also applied. */
9091 /* ??? We need to accept class types for C++, but not C. This greatly
9092 complicates this function, since we can no longer rely on the extra
9093 processing given by function_type_required. */
9096 handle_tm_attribute (tree
*node
, tree name
, tree args
,
9097 int flags
, bool *no_add_attrs
)
9099 /* Only one path adds the attribute; others don't. */
9100 *no_add_attrs
= true;
9102 switch (TREE_CODE (*node
))
9106 /* Only tm_callable and tm_safe apply to classes. */
9107 if (tm_attr_to_mask (name
) & ~(TM_ATTR_SAFE
| TM_ATTR_CALLABLE
))
9114 tree old_name
= find_tm_attribute (TYPE_ATTRIBUTES (*node
));
9115 if (old_name
== name
)
9117 else if (old_name
!= NULL_TREE
)
9118 error ("type was previously declared %qE", old_name
);
9120 *no_add_attrs
= false;
9126 enum tree_code subcode
= TREE_CODE (TREE_TYPE (*node
));
9127 if (subcode
== FUNCTION_TYPE
|| subcode
== METHOD_TYPE
)
9129 tree fn_tmp
= TREE_TYPE (*node
);
9130 decl_attributes (&fn_tmp
, tree_cons (name
, args
, NULL
), 0);
9131 *node
= build_pointer_type (fn_tmp
);
9138 /* If a function is next, pass it on to be tried next. */
9139 if (flags
& (int) ATTR_FLAG_FUNCTION_NEXT
)
9140 return tree_cons (name
, args
, NULL
);
9143 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9150 /* Handle the TM_WRAP attribute; arguments as in
9151 struct attribute_spec.handler. */
9154 handle_tm_wrap_attribute (tree
*node
, tree name
, tree args
,
9155 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9159 /* We don't need the attribute even on success, since we
9160 record the entry in an external table. */
9161 *no_add_attrs
= true;
9163 if (TREE_CODE (decl
) != FUNCTION_DECL
)
9164 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9167 tree wrap_decl
= TREE_VALUE (args
);
9168 if (error_operand_p (wrap_decl
))
9170 else if (TREE_CODE (wrap_decl
) != IDENTIFIER_NODE
9171 && !VAR_OR_FUNCTION_DECL_P (wrap_decl
))
9172 error ("%qE argument not an identifier", name
);
9175 if (TREE_CODE (wrap_decl
) == IDENTIFIER_NODE
)
9176 wrap_decl
= lookup_name (wrap_decl
);
9177 if (wrap_decl
&& TREE_CODE (wrap_decl
) == FUNCTION_DECL
)
9179 if (lang_hooks
.types_compatible_p (TREE_TYPE (decl
),
9180 TREE_TYPE (wrap_decl
)))
9181 record_tm_replacement (wrap_decl
, decl
);
9183 error ("%qD is not compatible with %qD", wrap_decl
, decl
);
9186 error ("%qE argument is not a function", name
);
9193 /* Ignore the given attribute. Used when this attribute may be usefully
9194 overridden by the target, but is not used generically. */
9197 ignore_attribute (tree
* ARG_UNUSED (node
), tree
ARG_UNUSED (name
),
9198 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
9201 *no_add_attrs
= true;
9205 /* Handle a "no vops" attribute; arguments as in
9206 struct attribute_spec.handler. */
9209 handle_novops_attribute (tree
*node
, tree
ARG_UNUSED (name
),
9210 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
9211 bool *ARG_UNUSED (no_add_attrs
))
9213 gcc_assert (TREE_CODE (*node
) == FUNCTION_DECL
);
9214 DECL_IS_NOVOPS (*node
) = 1;
9218 /* Handle a "deprecated" attribute; arguments as in
9219 struct attribute_spec.handler. */
9222 handle_deprecated_attribute (tree
*node
, tree name
,
9223 tree args
, int flags
,
9226 tree type
= NULL_TREE
;
9228 tree what
= NULL_TREE
;
9231 *no_add_attrs
= true;
9232 else if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
9234 error ("deprecated message is not a string");
9235 *no_add_attrs
= true;
9241 type
= TREE_TYPE (decl
);
9243 if (TREE_CODE (decl
) == TYPE_DECL
9244 || TREE_CODE (decl
) == PARM_DECL
9245 || VAR_OR_FUNCTION_DECL_P (decl
)
9246 || TREE_CODE (decl
) == FIELD_DECL
9247 || TREE_CODE (decl
) == CONST_DECL
9248 || objc_method_decl (TREE_CODE (decl
)))
9249 TREE_DEPRECATED (decl
) = 1;
9253 else if (TYPE_P (*node
))
9255 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
9256 *node
= build_variant_type_copy (*node
);
9257 TREE_DEPRECATED (*node
) = 1;
9265 *no_add_attrs
= true;
9266 if (type
&& TYPE_NAME (type
))
9268 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
9269 what
= TYPE_NAME (*node
);
9270 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
9271 && DECL_NAME (TYPE_NAME (type
)))
9272 what
= DECL_NAME (TYPE_NAME (type
));
9275 warning (OPT_Wattributes
, "%qE attribute ignored for %qE", name
, what
);
9277 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9283 /* Handle a "vector_size" attribute; arguments as in
9284 struct attribute_spec.handler. */
9287 handle_vector_size_attribute (tree
*node
, tree name
, tree args
,
9288 int ARG_UNUSED (flags
),
9291 unsigned HOST_WIDE_INT vecsize
, nunits
;
9292 machine_mode orig_mode
;
9293 tree type
= *node
, new_type
, size
;
9295 *no_add_attrs
= true;
9297 size
= TREE_VALUE (args
);
9298 if (size
&& TREE_CODE (size
) != IDENTIFIER_NODE
9299 && TREE_CODE (size
) != FUNCTION_DECL
)
9300 size
= default_conversion (size
);
9302 if (!tree_fits_uhwi_p (size
))
9304 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9308 /* Get the vector size (in bytes). */
9309 vecsize
= tree_to_uhwi (size
);
9311 /* We need to provide for vector pointers, vector arrays, and
9312 functions returning vectors. For example:
9314 __attribute__((vector_size(16))) short *foo;
9316 In this case, the mode is SI, but the type being modified is
9317 HI, so we need to look further. */
9319 while (POINTER_TYPE_P (type
)
9320 || TREE_CODE (type
) == FUNCTION_TYPE
9321 || TREE_CODE (type
) == METHOD_TYPE
9322 || TREE_CODE (type
) == ARRAY_TYPE
9323 || TREE_CODE (type
) == OFFSET_TYPE
)
9324 type
= TREE_TYPE (type
);
9326 /* Get the mode of the type being modified. */
9327 orig_mode
= TYPE_MODE (type
);
9329 if ((!INTEGRAL_TYPE_P (type
)
9330 && !SCALAR_FLOAT_TYPE_P (type
)
9331 && !FIXED_POINT_TYPE_P (type
))
9332 || (!SCALAR_FLOAT_MODE_P (orig_mode
)
9333 && GET_MODE_CLASS (orig_mode
) != MODE_INT
9334 && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode
))
9335 || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
9336 || TREE_CODE (type
) == BOOLEAN_TYPE
)
9338 error ("invalid vector type for attribute %qE", name
);
9342 if (vecsize
% tree_to_uhwi (TYPE_SIZE_UNIT (type
)))
9344 error ("vector size not an integral multiple of component size");
9350 error ("zero vector size");
9354 /* Calculate how many units fit in the vector. */
9355 nunits
= vecsize
/ tree_to_uhwi (TYPE_SIZE_UNIT (type
));
9356 if (nunits
& (nunits
- 1))
9358 error ("number of components of the vector not a power of two");
9362 new_type
= build_vector_type (type
, nunits
);
9364 /* Build back pointers if needed. */
9365 *node
= lang_hooks
.types
.reconstruct_complex_type (*node
, new_type
);
9370 /* Handle the "nonnull" attribute. */
9372 handle_nonnull_attribute (tree
*node
, tree
ARG_UNUSED (name
),
9373 tree args
, int ARG_UNUSED (flags
),
9377 unsigned HOST_WIDE_INT attr_arg_num
;
9379 /* If no arguments are specified, all pointer arguments should be
9380 non-null. Verify a full prototype is given so that the arguments
9381 will have the correct types when we actually check them later. */
9384 if (!prototype_p (type
))
9386 error ("nonnull attribute without arguments on a non-prototype");
9387 *no_add_attrs
= true;
9392 /* Argument list specified. Verify that each argument number references
9393 a pointer argument. */
9394 for (attr_arg_num
= 1; args
; attr_arg_num
++, args
= TREE_CHAIN (args
))
9396 unsigned HOST_WIDE_INT arg_num
= 0, ck_num
;
9398 tree arg
= TREE_VALUE (args
);
9399 if (arg
&& TREE_CODE (arg
) != IDENTIFIER_NODE
9400 && TREE_CODE (arg
) != FUNCTION_DECL
)
9401 arg
= default_conversion (arg
);
9403 if (!get_nonnull_operand (arg
, &arg_num
))
9405 error ("nonnull argument has invalid operand number (argument %lu)",
9406 (unsigned long) attr_arg_num
);
9407 *no_add_attrs
= true;
9411 if (prototype_p (type
))
9413 function_args_iterator iter
;
9416 function_args_iter_init (&iter
, type
);
9417 for (ck_num
= 1; ; ck_num
++, function_args_iter_next (&iter
))
9419 argument
= function_args_iter_cond (&iter
);
9420 if (argument
== NULL_TREE
|| ck_num
== arg_num
)
9425 || TREE_CODE (argument
) == VOID_TYPE
)
9427 error ("nonnull argument with out-of-range operand number (argument %lu, operand %lu)",
9428 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
9429 *no_add_attrs
= true;
9433 if (TREE_CODE (argument
) != POINTER_TYPE
)
9435 error ("nonnull argument references non-pointer operand (argument %lu, operand %lu)",
9436 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
9437 *no_add_attrs
= true;
9446 /* Check the argument list of a function call for null in argument slots
9447 that are marked as requiring a non-null pointer argument. The NARGS
9448 arguments are passed in the array ARGARRAY.
9452 check_function_nonnull (tree attrs
, int nargs
, tree
*argarray
)
9457 attrs
= lookup_attribute ("nonnull", attrs
);
9458 if (attrs
== NULL_TREE
)
9462 /* See if any of the nonnull attributes has no arguments. If so,
9463 then every pointer argument is checked (in which case the check
9464 for pointer type is done in check_nonnull_arg). */
9465 if (TREE_VALUE (a
) != NULL_TREE
)
9467 a
= lookup_attribute ("nonnull", TREE_CHAIN (a
));
9468 while (a
!= NULL_TREE
&& TREE_VALUE (a
) != NULL_TREE
);
9471 for (i
= 0; i
< nargs
; i
++)
9472 check_function_arguments_recurse (check_nonnull_arg
, NULL
, argarray
[i
],
9476 /* Walk the argument list. If we encounter an argument number we
9477 should check for non-null, do it. */
9478 for (i
= 0; i
< nargs
; i
++)
9480 for (a
= attrs
; ; a
= TREE_CHAIN (a
))
9482 a
= lookup_attribute ("nonnull", a
);
9483 if (a
== NULL_TREE
|| nonnull_check_p (TREE_VALUE (a
), i
+ 1))
9488 check_function_arguments_recurse (check_nonnull_arg
, NULL
,
9489 argarray
[i
], i
+ 1);
9494 /* Check that the Nth argument of a function call (counting backwards
9495 from the end) is a (pointer)0. The NARGS arguments are passed in the
9499 check_function_sentinel (const_tree fntype
, int nargs
, tree
*argarray
)
9501 tree attr
= lookup_attribute ("sentinel", TYPE_ATTRIBUTES (fntype
));
9508 function_args_iterator iter
;
9511 /* Skip over the named arguments. */
9512 FOREACH_FUNCTION_ARGS (fntype
, t
, iter
)
9519 if (TREE_VALUE (attr
))
9521 tree p
= TREE_VALUE (TREE_VALUE (attr
));
9522 pos
= TREE_INT_CST_LOW (p
);
9525 /* The sentinel must be one of the varargs, i.e.
9526 in position >= the number of fixed arguments. */
9527 if ((nargs
- 1 - pos
) < len
)
9529 warning (OPT_Wformat_
,
9530 "not enough variable arguments to fit a sentinel");
9534 /* Validate the sentinel. */
9535 sentinel
= argarray
[nargs
- 1 - pos
];
9536 if ((!POINTER_TYPE_P (TREE_TYPE (sentinel
))
9537 || !integer_zerop (sentinel
))
9538 /* Although __null (in C++) is only an integer we allow it
9539 nevertheless, as we are guaranteed that it's exactly
9540 as wide as a pointer, and we don't want to force
9541 users to cast the NULL they have written there.
9542 We warn with -Wstrict-null-sentinel, though. */
9543 && (warn_strict_null_sentinel
|| null_node
!= sentinel
))
9544 warning (OPT_Wformat_
, "missing sentinel in function call");
9548 /* Helper for check_function_nonnull; given a list of operands which
9549 must be non-null in ARGS, determine if operand PARAM_NUM should be
9553 nonnull_check_p (tree args
, unsigned HOST_WIDE_INT param_num
)
9555 unsigned HOST_WIDE_INT arg_num
= 0;
9557 for (; args
; args
= TREE_CHAIN (args
))
9559 bool found
= get_nonnull_operand (TREE_VALUE (args
), &arg_num
);
9563 if (arg_num
== param_num
)
9569 /* Check that the function argument PARAM (which is operand number
9570 PARAM_NUM) is non-null. This is called by check_function_nonnull
9571 via check_function_arguments_recurse. */
9574 check_nonnull_arg (void * ARG_UNUSED (ctx
), tree param
,
9575 unsigned HOST_WIDE_INT param_num
)
9577 /* Just skip checking the argument if it's not a pointer. This can
9578 happen if the "nonnull" attribute was given without an operand
9579 list (which means to check every pointer argument). */
9581 if (TREE_CODE (TREE_TYPE (param
)) != POINTER_TYPE
)
9584 if (integer_zerop (param
))
9585 warning (OPT_Wnonnull
, "null argument where non-null required "
9586 "(argument %lu)", (unsigned long) param_num
);
9589 /* Helper for nonnull attribute handling; fetch the operand number
9590 from the attribute argument list. */
9593 get_nonnull_operand (tree arg_num_expr
, unsigned HOST_WIDE_INT
*valp
)
9595 /* Verify the arg number is a small constant. */
9596 if (tree_fits_uhwi_p (arg_num_expr
))
9598 *valp
= TREE_INT_CST_LOW (arg_num_expr
);
9605 /* Handle a "nothrow" attribute; arguments as in
9606 struct attribute_spec.handler. */
9609 handle_nothrow_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
9610 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9612 if (TREE_CODE (*node
) == FUNCTION_DECL
)
9613 TREE_NOTHROW (*node
) = 1;
9614 /* ??? TODO: Support types. */
9617 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9618 *no_add_attrs
= true;
9624 /* Handle a "cleanup" attribute; arguments as in
9625 struct attribute_spec.handler. */
9628 handle_cleanup_attribute (tree
*node
, tree name
, tree args
,
9629 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9632 tree cleanup_id
, cleanup_decl
;
9634 /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
9635 for global destructors in C++. This requires infrastructure that
9636 we don't have generically at the moment. It's also not a feature
9637 we'd be missing too much, since we do have attribute constructor. */
9638 if (!VAR_P (decl
) || TREE_STATIC (decl
))
9640 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9641 *no_add_attrs
= true;
9645 /* Verify that the argument is a function in scope. */
9646 /* ??? We could support pointers to functions here as well, if
9647 that was considered desirable. */
9648 cleanup_id
= TREE_VALUE (args
);
9649 if (TREE_CODE (cleanup_id
) != IDENTIFIER_NODE
)
9651 error ("cleanup argument not an identifier");
9652 *no_add_attrs
= true;
9655 cleanup_decl
= lookup_name (cleanup_id
);
9656 if (!cleanup_decl
|| TREE_CODE (cleanup_decl
) != FUNCTION_DECL
)
9658 error ("cleanup argument not a function");
9659 *no_add_attrs
= true;
9663 /* That the function has proper type is checked with the
9664 eventual call to build_function_call. */
9669 /* Handle a "warn_unused_result" attribute. No special handling. */
9672 handle_warn_unused_result_attribute (tree
*node
, tree name
,
9673 tree
ARG_UNUSED (args
),
9674 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9676 /* Ignore the attribute for functions not returning any value. */
9677 if (VOID_TYPE_P (TREE_TYPE (*node
)))
9679 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9680 *no_add_attrs
= true;
9686 /* Handle a "sentinel" attribute. */
9689 handle_sentinel_attribute (tree
*node
, tree name
, tree args
,
9690 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9692 if (!prototype_p (*node
))
9694 warning (OPT_Wattributes
,
9695 "%qE attribute requires prototypes with named arguments", name
);
9696 *no_add_attrs
= true;
9700 if (!stdarg_p (*node
))
9702 warning (OPT_Wattributes
,
9703 "%qE attribute only applies to variadic functions", name
);
9704 *no_add_attrs
= true;
9710 tree position
= TREE_VALUE (args
);
9711 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
9712 && TREE_CODE (position
) != FUNCTION_DECL
)
9713 position
= default_conversion (position
);
9715 if (TREE_CODE (position
) != INTEGER_CST
9716 || !INTEGRAL_TYPE_P (TREE_TYPE (position
)))
9718 warning (OPT_Wattributes
,
9719 "requested position is not an integer constant");
9720 *no_add_attrs
= true;
9724 if (tree_int_cst_lt (position
, integer_zero_node
))
9726 warning (OPT_Wattributes
,
9727 "requested position is less than zero");
9728 *no_add_attrs
= true;
9736 /* Handle a "type_generic" attribute. */
9739 handle_type_generic_attribute (tree
*node
, tree
ARG_UNUSED (name
),
9740 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
9741 bool * ARG_UNUSED (no_add_attrs
))
9743 /* Ensure we have a function type. */
9744 gcc_assert (TREE_CODE (*node
) == FUNCTION_TYPE
);
9746 /* Ensure we have a variadic function. */
9747 gcc_assert (!prototype_p (*node
) || stdarg_p (*node
));
9752 /* Handle a "target" attribute. */
9755 handle_target_attribute (tree
*node
, tree name
, tree args
, int flags
,
9758 /* Ensure we have a function type. */
9759 if (TREE_CODE (*node
) != FUNCTION_DECL
)
9761 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9762 *no_add_attrs
= true;
9764 else if (! targetm
.target_option
.valid_attribute_p (*node
, name
, args
,
9766 *no_add_attrs
= true;
9771 /* Arguments being collected for optimization. */
9772 typedef const char *const_char_p
; /* For DEF_VEC_P. */
9773 static GTY(()) vec
<const_char_p
, va_gc
> *optimize_args
;
9776 /* Inner function to convert a TREE_LIST to argv string to parse the optimize
9777 options in ARGS. ATTR_P is true if this is for attribute(optimize), and
9778 false for #pragma GCC optimize. */
9781 parse_optimize_options (tree args
, bool attr_p
)
9786 int saved_flag_strict_aliasing
;
9787 const char **opt_argv
;
9788 struct cl_decoded_option
*decoded_options
;
9789 unsigned int decoded_options_count
;
9792 /* Build up argv vector. Just in case the string is stored away, use garbage
9793 collected strings. */
9794 vec_safe_truncate (optimize_args
, 0);
9795 vec_safe_push (optimize_args
, (const char *) NULL
);
9797 for (ap
= args
; ap
!= NULL_TREE
; ap
= TREE_CHAIN (ap
))
9799 tree value
= TREE_VALUE (ap
);
9801 if (TREE_CODE (value
) == INTEGER_CST
)
9804 sprintf (buffer
, "-O%ld", (long) TREE_INT_CST_LOW (value
));
9805 vec_safe_push (optimize_args
, ggc_strdup (buffer
));
9808 else if (TREE_CODE (value
) == STRING_CST
)
9810 /* Split string into multiple substrings. */
9811 size_t len
= TREE_STRING_LENGTH (value
);
9812 char *p
= ASTRDUP (TREE_STRING_POINTER (value
));
9813 char *end
= p
+ len
;
9817 while (next_p
!= NULL
)
9823 comma
= strchr (p
, ',');
9836 r
= q
= (char *) ggc_alloc_atomic (len2
+ 3);
9838 /* If the user supplied -Oxxx or -fxxx, only allow -Oxxx or -fxxx
9840 if (*p
== '-' && p
[1] != 'O' && p
[1] != 'f')
9844 warning (OPT_Wattributes
,
9845 "bad option %s to optimize attribute", p
);
9847 warning (OPT_Wpragmas
,
9848 "bad option %s to pragma attribute", p
);
9856 /* Assume that Ox is -Ox, a numeric value is -Ox, a s by
9857 itself is -Os, and any other switch begins with a -f. */
9858 if ((*p
>= '0' && *p
<= '9')
9859 || (p
[0] == 's' && p
[1] == '\0'))
9865 memcpy (r
, p
, len2
);
9867 vec_safe_push (optimize_args
, (const char *) q
);
9873 opt_argc
= optimize_args
->length ();
9874 opt_argv
= (const char **) alloca (sizeof (char *) * (opt_argc
+ 1));
9876 for (i
= 1; i
< opt_argc
; i
++)
9877 opt_argv
[i
] = (*optimize_args
)[i
];
9879 saved_flag_strict_aliasing
= flag_strict_aliasing
;
9881 /* Now parse the options. */
9882 decode_cmdline_options_to_array_default_mask (opt_argc
, opt_argv
,
9884 &decoded_options_count
);
9885 decode_options (&global_options
, &global_options_set
,
9886 decoded_options
, decoded_options_count
,
9887 input_location
, global_dc
);
9889 targetm
.override_options_after_change();
9891 /* Don't allow changing -fstrict-aliasing. */
9892 flag_strict_aliasing
= saved_flag_strict_aliasing
;
9894 optimize_args
->truncate (0);
9898 /* For handling "optimize" attribute. arguments as in
9899 struct attribute_spec.handler. */
9902 handle_optimize_attribute (tree
*node
, tree name
, tree args
,
9903 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9905 /* Ensure we have a function type. */
9906 if (TREE_CODE (*node
) != FUNCTION_DECL
)
9908 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9909 *no_add_attrs
= true;
9913 struct cl_optimization cur_opts
;
9914 tree old_opts
= DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
);
9916 /* Save current options. */
9917 cl_optimization_save (&cur_opts
, &global_options
);
9919 /* If we previously had some optimization options, use them as the
9922 cl_optimization_restore (&global_options
,
9923 TREE_OPTIMIZATION (old_opts
));
9925 /* Parse options, and update the vector. */
9926 parse_optimize_options (args
, true);
9927 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
)
9928 = build_optimization_node (&global_options
);
9930 /* Restore current options. */
9931 cl_optimization_restore (&global_options
, &cur_opts
);
9937 /* Handle a "no_split_stack" attribute. */
9940 handle_no_split_stack_attribute (tree
*node
, tree name
,
9941 tree
ARG_UNUSED (args
),
9942 int ARG_UNUSED (flags
),
9947 if (TREE_CODE (decl
) != FUNCTION_DECL
)
9949 error_at (DECL_SOURCE_LOCATION (decl
),
9950 "%qE attribute applies only to functions", name
);
9951 *no_add_attrs
= true;
9953 else if (DECL_INITIAL (decl
))
9955 error_at (DECL_SOURCE_LOCATION (decl
),
9956 "can%'t set %qE attribute after definition", name
);
9957 *no_add_attrs
= true;
9963 /* Handle a "returns_nonnull" attribute; arguments as in
9964 struct attribute_spec.handler. */
9967 handle_returns_nonnull_attribute (tree
*node
, tree
, tree
, int,
9970 // Even without a prototype we still have a return type we can check.
9971 if (TREE_CODE (TREE_TYPE (*node
)) != POINTER_TYPE
)
9973 error ("returns_nonnull attribute on a function not returning a pointer");
9974 *no_add_attrs
= true;
9979 /* Handle a "designated_init" attribute; arguments as in
9980 struct attribute_spec.handler. */
9983 handle_designated_init_attribute (tree
*node
, tree name
, tree
, int,
9986 if (TREE_CODE (*node
) != RECORD_TYPE
)
9988 error ("%qE attribute is only valid on %<struct%> type", name
);
9989 *no_add_attrs
= true;
9995 /* Check for valid arguments being passed to a function with FNTYPE.
9996 There are NARGS arguments in the array ARGARRAY. */
9998 check_function_arguments (const_tree fntype
, int nargs
, tree
*argarray
)
10000 /* Check for null being passed in a pointer argument that must be
10001 non-null. We also need to do this if format checking is enabled. */
10004 check_function_nonnull (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
10006 /* Check for errors in format strings. */
10008 if (warn_format
|| warn_suggest_attribute_format
)
10009 check_function_format (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
10012 check_function_sentinel (fntype
, nargs
, argarray
);
10015 /* Generic argument checking recursion routine. PARAM is the argument to
10016 be checked. PARAM_NUM is the number of the argument. CALLBACK is invoked
10017 once the argument is resolved. CTX is context for the callback. */
10019 check_function_arguments_recurse (void (*callback
)
10020 (void *, tree
, unsigned HOST_WIDE_INT
),
10021 void *ctx
, tree param
,
10022 unsigned HOST_WIDE_INT param_num
)
10024 if (CONVERT_EXPR_P (param
)
10025 && (TYPE_PRECISION (TREE_TYPE (param
))
10026 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (param
, 0)))))
10028 /* Strip coercion. */
10029 check_function_arguments_recurse (callback
, ctx
,
10030 TREE_OPERAND (param
, 0), param_num
);
10034 if (TREE_CODE (param
) == CALL_EXPR
)
10036 tree type
= TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (param
)));
10038 bool found_format_arg
= false;
10040 /* See if this is a call to a known internationalization function
10041 that modifies a format arg. Such a function may have multiple
10042 format_arg attributes (for example, ngettext). */
10044 for (attrs
= TYPE_ATTRIBUTES (type
);
10046 attrs
= TREE_CHAIN (attrs
))
10047 if (is_attribute_p ("format_arg", TREE_PURPOSE (attrs
)))
10050 tree format_num_expr
;
10053 call_expr_arg_iterator iter
;
10055 /* Extract the argument number, which was previously checked
10057 format_num_expr
= TREE_VALUE (TREE_VALUE (attrs
));
10059 format_num
= tree_to_uhwi (format_num_expr
);
10061 for (inner_arg
= first_call_expr_arg (param
, &iter
), i
= 1;
10063 inner_arg
= next_call_expr_arg (&iter
), i
++)
10064 if (i
== format_num
)
10066 check_function_arguments_recurse (callback
, ctx
,
10067 inner_arg
, param_num
);
10068 found_format_arg
= true;
10073 /* If we found a format_arg attribute and did a recursive check,
10074 we are done with checking this argument. Otherwise, we continue
10075 and this will be considered a non-literal. */
10076 if (found_format_arg
)
10080 if (TREE_CODE (param
) == COND_EXPR
)
10082 /* Check both halves of the conditional expression. */
10083 check_function_arguments_recurse (callback
, ctx
,
10084 TREE_OPERAND (param
, 1), param_num
);
10085 check_function_arguments_recurse (callback
, ctx
,
10086 TREE_OPERAND (param
, 2), param_num
);
10090 (*callback
) (ctx
, param
, param_num
);
10093 /* Checks for a builtin function FNDECL that the number of arguments
10094 NARGS against the required number REQUIRED and issues an error if
10095 there is a mismatch. Returns true if the number of arguments is
10096 correct, otherwise false. */
10099 builtin_function_validate_nargs (tree fndecl
, int nargs
, int required
)
10101 if (nargs
< required
)
10103 error_at (input_location
,
10104 "not enough arguments to function %qE", fndecl
);
10107 else if (nargs
> required
)
10109 error_at (input_location
,
10110 "too many arguments to function %qE", fndecl
);
10116 /* Verifies the NARGS arguments ARGS to the builtin function FNDECL.
10117 Returns false if there was an error, otherwise true. */
10120 check_builtin_function_arguments (tree fndecl
, int nargs
, tree
*args
)
10122 if (!DECL_BUILT_IN (fndecl
)
10123 || DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_NORMAL
)
10126 switch (DECL_FUNCTION_CODE (fndecl
))
10128 case BUILT_IN_CONSTANT_P
:
10129 return builtin_function_validate_nargs (fndecl
, nargs
, 1);
10131 case BUILT_IN_ISFINITE
:
10132 case BUILT_IN_ISINF
:
10133 case BUILT_IN_ISINF_SIGN
:
10134 case BUILT_IN_ISNAN
:
10135 case BUILT_IN_ISNORMAL
:
10136 if (builtin_function_validate_nargs (fndecl
, nargs
, 1))
10138 if (TREE_CODE (TREE_TYPE (args
[0])) != REAL_TYPE
)
10140 error ("non-floating-point argument in call to "
10141 "function %qE", fndecl
);
10148 case BUILT_IN_ISGREATER
:
10149 case BUILT_IN_ISGREATEREQUAL
:
10150 case BUILT_IN_ISLESS
:
10151 case BUILT_IN_ISLESSEQUAL
:
10152 case BUILT_IN_ISLESSGREATER
:
10153 case BUILT_IN_ISUNORDERED
:
10154 if (builtin_function_validate_nargs (fndecl
, nargs
, 2))
10156 enum tree_code code0
, code1
;
10157 code0
= TREE_CODE (TREE_TYPE (args
[0]));
10158 code1
= TREE_CODE (TREE_TYPE (args
[1]));
10159 if (!((code0
== REAL_TYPE
&& code1
== REAL_TYPE
)
10160 || (code0
== REAL_TYPE
&& code1
== INTEGER_TYPE
)
10161 || (code0
== INTEGER_TYPE
&& code1
== REAL_TYPE
)))
10163 error ("non-floating-point arguments in call to "
10164 "function %qE", fndecl
);
10171 case BUILT_IN_FPCLASSIFY
:
10172 if (builtin_function_validate_nargs (fndecl
, nargs
, 6))
10176 for (i
=0; i
<5; i
++)
10177 if (TREE_CODE (args
[i
]) != INTEGER_CST
)
10179 error ("non-const integer argument %u in call to function %qE",
10184 if (TREE_CODE (TREE_TYPE (args
[5])) != REAL_TYPE
)
10186 error ("non-floating-point argument in call to function %qE",
10194 case BUILT_IN_ASSUME_ALIGNED
:
10195 if (builtin_function_validate_nargs (fndecl
, nargs
, 2 + (nargs
> 2)))
10197 if (nargs
>= 3 && TREE_CODE (TREE_TYPE (args
[2])) != INTEGER_TYPE
)
10199 error ("non-integer argument 3 in call to function %qE", fndecl
);
10206 case BUILT_IN_ADD_OVERFLOW
:
10207 case BUILT_IN_SUB_OVERFLOW
:
10208 case BUILT_IN_MUL_OVERFLOW
:
10209 if (builtin_function_validate_nargs (fndecl
, nargs
, 3))
10212 for (i
= 0; i
< 2; i
++)
10213 if (!INTEGRAL_TYPE_P (TREE_TYPE (args
[i
])))
10215 error ("argument %u in call to function %qE does not have "
10216 "integral type", i
+ 1, fndecl
);
10219 if (TREE_CODE (TREE_TYPE (args
[2])) != POINTER_TYPE
10220 || TREE_CODE (TREE_TYPE (TREE_TYPE (args
[2]))) != INTEGER_TYPE
)
10222 error ("argument 3 in call to function %qE does not have "
10223 "pointer to integer type", fndecl
);
10235 /* Function to help qsort sort FIELD_DECLs by name order. */
10238 field_decl_cmp (const void *x_p
, const void *y_p
)
10240 const tree
*const x
= (const tree
*const) x_p
;
10241 const tree
*const y
= (const tree
*const) y_p
;
10243 if (DECL_NAME (*x
) == DECL_NAME (*y
))
10244 /* A nontype is "greater" than a type. */
10245 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
10246 if (DECL_NAME (*x
) == NULL_TREE
)
10248 if (DECL_NAME (*y
) == NULL_TREE
)
10250 if (DECL_NAME (*x
) < DECL_NAME (*y
))
10256 gt_pointer_operator new_value
;
10260 /* This routine compares two fields like field_decl_cmp but using the
10261 pointer operator in resort_data. */
10264 resort_field_decl_cmp (const void *x_p
, const void *y_p
)
10266 const tree
*const x
= (const tree
*const) x_p
;
10267 const tree
*const y
= (const tree
*const) y_p
;
10269 if (DECL_NAME (*x
) == DECL_NAME (*y
))
10270 /* A nontype is "greater" than a type. */
10271 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
10272 if (DECL_NAME (*x
) == NULL_TREE
)
10274 if (DECL_NAME (*y
) == NULL_TREE
)
10277 tree d1
= DECL_NAME (*x
);
10278 tree d2
= DECL_NAME (*y
);
10279 resort_data
.new_value (&d1
, resort_data
.cookie
);
10280 resort_data
.new_value (&d2
, resort_data
.cookie
);
10287 /* Resort DECL_SORTED_FIELDS because pointers have been reordered. */
10290 resort_sorted_fields (void *obj
,
10291 void * ARG_UNUSED (orig_obj
),
10292 gt_pointer_operator new_value
,
10295 struct sorted_fields_type
*sf
= (struct sorted_fields_type
*) obj
;
10296 resort_data
.new_value
= new_value
;
10297 resort_data
.cookie
= cookie
;
10298 qsort (&sf
->elts
[0], sf
->len
, sizeof (tree
),
10299 resort_field_decl_cmp
);
10302 /* Subroutine of c_parse_error.
10303 Return the result of concatenating LHS and RHS. RHS is really
10304 a string literal, its first character is indicated by RHS_START and
10305 RHS_SIZE is its length (including the terminating NUL character).
10307 The caller is responsible for deleting the returned pointer. */
10310 catenate_strings (const char *lhs
, const char *rhs_start
, int rhs_size
)
10312 const int lhs_size
= strlen (lhs
);
10313 char *result
= XNEWVEC (char, lhs_size
+ rhs_size
);
10314 strncpy (result
, lhs
, lhs_size
);
10315 strncpy (result
+ lhs_size
, rhs_start
, rhs_size
);
10319 /* Issue the error given by GMSGID, indicating that it occurred before
10320 TOKEN, which had the associated VALUE. */
10323 c_parse_error (const char *gmsgid
, enum cpp_ttype token_type
,
10324 tree value
, unsigned char token_flags
)
10326 #define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2))
10328 char *message
= NULL
;
10330 if (token_type
== CPP_EOF
)
10331 message
= catenate_messages (gmsgid
, " at end of input");
10332 else if (token_type
== CPP_CHAR
10333 || token_type
== CPP_WCHAR
10334 || token_type
== CPP_CHAR16
10335 || token_type
== CPP_CHAR32
10336 || token_type
== CPP_UTF8CHAR
)
10338 unsigned int val
= TREE_INT_CST_LOW (value
);
10339 const char *prefix
;
10341 switch (token_type
)
10360 if (val
<= UCHAR_MAX
&& ISGRAPH (val
))
10361 message
= catenate_messages (gmsgid
, " before %s'%c'");
10363 message
= catenate_messages (gmsgid
, " before %s'\\x%x'");
10365 error (message
, prefix
, val
);
10369 else if (token_type
== CPP_CHAR_USERDEF
10370 || token_type
== CPP_WCHAR_USERDEF
10371 || token_type
== CPP_CHAR16_USERDEF
10372 || token_type
== CPP_CHAR32_USERDEF
10373 || token_type
== CPP_UTF8CHAR_USERDEF
)
10374 message
= catenate_messages (gmsgid
,
10375 " before user-defined character literal");
10376 else if (token_type
== CPP_STRING_USERDEF
10377 || token_type
== CPP_WSTRING_USERDEF
10378 || token_type
== CPP_STRING16_USERDEF
10379 || token_type
== CPP_STRING32_USERDEF
10380 || token_type
== CPP_UTF8STRING_USERDEF
)
10381 message
= catenate_messages (gmsgid
, " before user-defined string literal");
10382 else if (token_type
== CPP_STRING
10383 || token_type
== CPP_WSTRING
10384 || token_type
== CPP_STRING16
10385 || token_type
== CPP_STRING32
10386 || token_type
== CPP_UTF8STRING
)
10387 message
= catenate_messages (gmsgid
, " before string constant");
10388 else if (token_type
== CPP_NUMBER
)
10389 message
= catenate_messages (gmsgid
, " before numeric constant");
10390 else if (token_type
== CPP_NAME
)
10392 message
= catenate_messages (gmsgid
, " before %qE");
10393 error (message
, value
);
10397 else if (token_type
== CPP_PRAGMA
)
10398 message
= catenate_messages (gmsgid
, " before %<#pragma%>");
10399 else if (token_type
== CPP_PRAGMA_EOL
)
10400 message
= catenate_messages (gmsgid
, " before end of line");
10401 else if (token_type
== CPP_DECLTYPE
)
10402 message
= catenate_messages (gmsgid
, " before %<decltype%>");
10403 else if (token_type
< N_TTYPES
)
10405 message
= catenate_messages (gmsgid
, " before %qs token");
10406 error (message
, cpp_type2name (token_type
, token_flags
));
10418 #undef catenate_messages
10421 /* Return the gcc option code associated with the reason for a cpp
10422 message, or 0 if none. */
10425 c_option_controlling_cpp_error (int reason
)
10427 const struct cpp_reason_option_codes_t
*entry
;
10429 for (entry
= cpp_reason_option_codes
; entry
->reason
!= CPP_W_NONE
; entry
++)
10431 if (entry
->reason
== reason
)
10432 return entry
->option_code
;
10437 /* Callback from cpp_error for PFILE to print diagnostics from the
10438 preprocessor. The diagnostic is of type LEVEL, with REASON set
10439 to the reason code if LEVEL is represents a warning, at location
10440 LOCATION unless this is after lexing and the compiler's location
10441 should be used instead, with column number possibly overridden by
10442 COLUMN_OVERRIDE if not zero; MSG is the translated message and AP
10443 the arguments. Returns true if a diagnostic was emitted, false
10447 c_cpp_error (cpp_reader
*pfile ATTRIBUTE_UNUSED
, int level
, int reason
,
10448 location_t location
, unsigned int column_override
,
10449 const char *msg
, va_list *ap
)
10451 diagnostic_info diagnostic
;
10452 diagnostic_t dlevel
;
10453 bool save_warn_system_headers
= global_dc
->dc_warn_system_headers
;
10458 case CPP_DL_WARNING_SYSHDR
:
10459 if (flag_no_output
)
10461 global_dc
->dc_warn_system_headers
= 1;
10462 /* Fall through. */
10463 case CPP_DL_WARNING
:
10464 if (flag_no_output
)
10466 dlevel
= DK_WARNING
;
10468 case CPP_DL_PEDWARN
:
10469 if (flag_no_output
&& !flag_pedantic_errors
)
10471 dlevel
= DK_PEDWARN
;
10486 gcc_unreachable ();
10489 location
= input_location
;
10490 diagnostic_set_info_translated (&diagnostic
, msg
, ap
,
10492 if (column_override
)
10493 diagnostic_override_column (&diagnostic
, column_override
);
10494 diagnostic_override_option_index (&diagnostic
,
10495 c_option_controlling_cpp_error (reason
));
10496 ret
= report_diagnostic (&diagnostic
);
10497 if (level
== CPP_DL_WARNING_SYSHDR
)
10498 global_dc
->dc_warn_system_headers
= save_warn_system_headers
;
10502 /* Convert a character from the host to the target execution character
10503 set. cpplib handles this, mostly. */
10506 c_common_to_target_charset (HOST_WIDE_INT c
)
10508 /* Character constants in GCC proper are sign-extended under -fsigned-char,
10509 zero-extended under -fno-signed-char. cpplib insists that characters
10510 and character constants are always unsigned. Hence we must convert
10512 cppchar_t uc
= ((cppchar_t
)c
) & ((((cppchar_t
)1) << CHAR_BIT
)-1);
10514 uc
= cpp_host_to_exec_charset (parse_in
, uc
);
10516 if (flag_signed_char
)
10517 return ((HOST_WIDE_INT
)uc
) << (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
)
10518 >> (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
);
10523 /* Fold an offsetof-like expression. EXPR is a nested sequence of component
10524 references with an INDIRECT_REF of a constant at the bottom; much like the
10525 traditional rendering of offsetof as a macro. Return the folded result. */
10528 fold_offsetof_1 (tree expr
)
10532 switch (TREE_CODE (expr
))
10538 error ("cannot apply %<offsetof%> to static data member %qD", expr
);
10539 return error_mark_node
;
10543 error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded");
10544 return error_mark_node
;
10548 if (!TREE_CONSTANT (TREE_OPERAND (expr
, 0)))
10550 error ("cannot apply %<offsetof%> to a non constant address");
10551 return error_mark_node
;
10553 return TREE_OPERAND (expr
, 0);
10555 case COMPONENT_REF
:
10556 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0));
10557 if (base
== error_mark_node
)
10560 t
= TREE_OPERAND (expr
, 1);
10561 if (DECL_C_BIT_FIELD (t
))
10563 error ("attempt to take address of bit-field structure "
10565 return error_mark_node
;
10567 off
= size_binop_loc (input_location
, PLUS_EXPR
, DECL_FIELD_OFFSET (t
),
10568 size_int (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (t
))
10573 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0));
10574 if (base
== error_mark_node
)
10577 t
= TREE_OPERAND (expr
, 1);
10579 /* Check if the offset goes beyond the upper bound of the array. */
10580 if (TREE_CODE (t
) == INTEGER_CST
&& tree_int_cst_sgn (t
) >= 0)
10582 tree upbound
= array_ref_up_bound (expr
);
10583 if (upbound
!= NULL_TREE
10584 && TREE_CODE (upbound
) == INTEGER_CST
10585 && !tree_int_cst_equal (upbound
,
10586 TYPE_MAX_VALUE (TREE_TYPE (upbound
))))
10588 upbound
= size_binop (PLUS_EXPR
, upbound
,
10589 build_int_cst (TREE_TYPE (upbound
), 1));
10590 if (tree_int_cst_lt (upbound
, t
))
10594 for (v
= TREE_OPERAND (expr
, 0);
10595 TREE_CODE (v
) == COMPONENT_REF
;
10596 v
= TREE_OPERAND (v
, 0))
10597 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v
, 0)))
10600 tree fld_chain
= DECL_CHAIN (TREE_OPERAND (v
, 1));
10601 for (; fld_chain
; fld_chain
= DECL_CHAIN (fld_chain
))
10602 if (TREE_CODE (fld_chain
) == FIELD_DECL
)
10608 /* Don't warn if the array might be considered a poor
10609 man's flexible array member with a very permissive
10610 definition thereof. */
10611 if (TREE_CODE (v
) == ARRAY_REF
10612 || TREE_CODE (v
) == COMPONENT_REF
)
10613 warning (OPT_Warray_bounds
,
10614 "index %E denotes an offset "
10615 "greater than size of %qT",
10616 t
, TREE_TYPE (TREE_OPERAND (expr
, 0)));
10621 t
= convert (sizetype
, t
);
10622 off
= size_binop (MULT_EXPR
, TYPE_SIZE_UNIT (TREE_TYPE (expr
)), t
);
10625 case COMPOUND_EXPR
:
10626 /* Handle static members of volatile structs. */
10627 t
= TREE_OPERAND (expr
, 1);
10628 gcc_assert (VAR_P (t
));
10629 return fold_offsetof_1 (t
);
10632 gcc_unreachable ();
10635 return fold_build_pointer_plus (base
, off
);
10638 /* Likewise, but convert it to the return type of offsetof. */
10641 fold_offsetof (tree expr
)
10643 return convert (size_type_node
, fold_offsetof_1 (expr
));
10646 /* Warn for A ?: C expressions (with B omitted) where A is a boolean
10647 expression, because B will always be true. */
10650 warn_for_omitted_condop (location_t location
, tree cond
)
10652 if (truth_value_p (TREE_CODE (cond
)))
10653 warning_at (location
, OPT_Wparentheses
,
10654 "the omitted middle operand in ?: will always be %<true%>, "
10655 "suggest explicit middle operand");
10658 /* Give an error for storing into ARG, which is 'const'. USE indicates
10659 how ARG was being used. */
10662 readonly_error (location_t loc
, tree arg
, enum lvalue_use use
)
10664 gcc_assert (use
== lv_assign
|| use
== lv_increment
|| use
== lv_decrement
10666 /* Using this macro rather than (for example) arrays of messages
10667 ensures that all the format strings are checked at compile
10669 #define READONLY_MSG(A, I, D, AS) (use == lv_assign ? (A) \
10670 : (use == lv_increment ? (I) \
10671 : (use == lv_decrement ? (D) : (AS))))
10672 if (TREE_CODE (arg
) == COMPONENT_REF
)
10674 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg
, 0))))
10675 error_at (loc
, READONLY_MSG (G_("assignment of member "
10676 "%qD in read-only object"),
10677 G_("increment of member "
10678 "%qD in read-only object"),
10679 G_("decrement of member "
10680 "%qD in read-only object"),
10681 G_("member %qD in read-only object "
10682 "used as %<asm%> output")),
10683 TREE_OPERAND (arg
, 1));
10685 error_at (loc
, READONLY_MSG (G_("assignment of read-only member %qD"),
10686 G_("increment of read-only member %qD"),
10687 G_("decrement of read-only member %qD"),
10688 G_("read-only member %qD used as %<asm%> output")),
10689 TREE_OPERAND (arg
, 1));
10691 else if (VAR_P (arg
))
10692 error_at (loc
, READONLY_MSG (G_("assignment of read-only variable %qD"),
10693 G_("increment of read-only variable %qD"),
10694 G_("decrement of read-only variable %qD"),
10695 G_("read-only variable %qD used as %<asm%> output")),
10697 else if (TREE_CODE (arg
) == PARM_DECL
)
10698 error_at (loc
, READONLY_MSG (G_("assignment of read-only parameter %qD"),
10699 G_("increment of read-only parameter %qD"),
10700 G_("decrement of read-only parameter %qD"),
10701 G_("read-only parameter %qD use as %<asm%> output")),
10703 else if (TREE_CODE (arg
) == RESULT_DECL
)
10705 gcc_assert (c_dialect_cxx ());
10706 error_at (loc
, READONLY_MSG (G_("assignment of "
10707 "read-only named return value %qD"),
10709 "read-only named return value %qD"),
10711 "read-only named return value %qD"),
10712 G_("read-only named return value %qD "
10713 "used as %<asm%>output")),
10716 else if (TREE_CODE (arg
) == FUNCTION_DECL
)
10717 error_at (loc
, READONLY_MSG (G_("assignment of function %qD"),
10718 G_("increment of function %qD"),
10719 G_("decrement of function %qD"),
10720 G_("function %qD used as %<asm%> output")),
10723 error_at (loc
, READONLY_MSG (G_("assignment of read-only location %qE"),
10724 G_("increment of read-only location %qE"),
10725 G_("decrement of read-only location %qE"),
10726 G_("read-only location %qE used as %<asm%> output")),
10730 /* Print an error message for an invalid lvalue. USE says
10731 how the lvalue is being used and so selects the error message. LOC
10732 is the location for the error. */
10735 lvalue_error (location_t loc
, enum lvalue_use use
)
10740 error_at (loc
, "lvalue required as left operand of assignment");
10743 error_at (loc
, "lvalue required as increment operand");
10746 error_at (loc
, "lvalue required as decrement operand");
10749 error_at (loc
, "lvalue required as unary %<&%> operand");
10752 error_at (loc
, "lvalue required in asm statement");
10755 gcc_unreachable ();
10759 /* Print an error message for an invalid indirection of type TYPE.
10760 ERRSTRING is the name of the operator for the indirection. */
10763 invalid_indirection_error (location_t loc
, tree type
, ref_operator errstring
)
10768 gcc_assert (c_dialect_cxx ());
10769 error_at (loc
, "invalid type argument (have %qT)", type
);
10771 case RO_ARRAY_INDEXING
:
10773 "invalid type argument of array indexing (have %qT)",
10776 case RO_UNARY_STAR
:
10778 "invalid type argument of unary %<*%> (have %qT)",
10783 "invalid type argument of %<->%> (have %qT)",
10786 case RO_ARROW_STAR
:
10788 "invalid type argument of %<->*%> (have %qT)",
10791 case RO_IMPLICIT_CONVERSION
:
10793 "invalid type argument of implicit conversion (have %qT)",
10797 gcc_unreachable ();
10801 /* *PTYPE is an incomplete array. Complete it with a domain based on
10802 INITIAL_VALUE. If INITIAL_VALUE is not present, use 1 if DO_DEFAULT
10803 is true. Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
10804 2 if INITIAL_VALUE was NULL, and 3 if INITIAL_VALUE was empty. */
10807 complete_array_type (tree
*ptype
, tree initial_value
, bool do_default
)
10809 tree maxindex
, type
, main_type
, elt
, unqual_elt
;
10810 int failure
= 0, quals
;
10811 hashval_t hashcode
= 0;
10812 bool overflow_p
= false;
10814 maxindex
= size_zero_node
;
10817 if (TREE_CODE (initial_value
) == STRING_CST
)
10820 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value
)));
10821 maxindex
= size_int (TREE_STRING_LENGTH (initial_value
)/eltsize
- 1);
10823 else if (TREE_CODE (initial_value
) == CONSTRUCTOR
)
10825 vec
<constructor_elt
, va_gc
> *v
= CONSTRUCTOR_ELTS (initial_value
);
10827 if (vec_safe_is_empty (v
))
10831 maxindex
= ssize_int (-1);
10836 unsigned HOST_WIDE_INT cnt
;
10837 constructor_elt
*ce
;
10838 bool fold_p
= false;
10841 maxindex
= (*v
)[0].index
, fold_p
= true;
10843 curindex
= maxindex
;
10845 for (cnt
= 1; vec_safe_iterate (v
, cnt
, &ce
); cnt
++)
10847 bool curfold_p
= false;
10849 curindex
= ce
->index
, curfold_p
= true;
10854 /* Since we treat size types now as ordinary
10855 unsigned types, we need an explicit overflow
10857 tree orig
= curindex
;
10858 curindex
= fold_convert (sizetype
, curindex
);
10859 overflow_p
|= tree_int_cst_lt (curindex
, orig
);
10861 curindex
= size_binop (PLUS_EXPR
, curindex
,
10864 if (tree_int_cst_lt (maxindex
, curindex
))
10865 maxindex
= curindex
, fold_p
= curfold_p
;
10869 tree orig
= maxindex
;
10870 maxindex
= fold_convert (sizetype
, maxindex
);
10871 overflow_p
|= tree_int_cst_lt (maxindex
, orig
);
10877 /* Make an error message unless that happened already. */
10878 if (initial_value
!= error_mark_node
)
10890 elt
= TREE_TYPE (type
);
10891 quals
= TYPE_QUALS (strip_array_types (elt
));
10895 unqual_elt
= c_build_qualified_type (elt
, KEEP_QUAL_ADDR_SPACE (quals
));
10897 /* Using build_distinct_type_copy and modifying things afterward instead
10898 of using build_array_type to create a new type preserves all of the
10899 TYPE_LANG_FLAG_? bits that the front end may have set. */
10900 main_type
= build_distinct_type_copy (TYPE_MAIN_VARIANT (type
));
10901 TREE_TYPE (main_type
) = unqual_elt
;
10902 TYPE_DOMAIN (main_type
)
10903 = build_range_type (TREE_TYPE (maxindex
),
10904 build_int_cst (TREE_TYPE (maxindex
), 0), maxindex
);
10905 layout_type (main_type
);
10907 /* Make sure we have the canonical MAIN_TYPE. */
10908 hashcode
= iterative_hash_object (TYPE_HASH (unqual_elt
), hashcode
);
10909 hashcode
= iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (main_type
)),
10911 main_type
= type_hash_canon (hashcode
, main_type
);
10913 /* Fix the canonical type. */
10914 if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type
))
10915 || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type
)))
10916 SET_TYPE_STRUCTURAL_EQUALITY (main_type
);
10917 else if (TYPE_CANONICAL (TREE_TYPE (main_type
)) != TREE_TYPE (main_type
)
10918 || (TYPE_CANONICAL (TYPE_DOMAIN (main_type
))
10919 != TYPE_DOMAIN (main_type
)))
10920 TYPE_CANONICAL (main_type
)
10921 = build_array_type (TYPE_CANONICAL (TREE_TYPE (main_type
)),
10922 TYPE_CANONICAL (TYPE_DOMAIN (main_type
)));
10924 TYPE_CANONICAL (main_type
) = main_type
;
10929 type
= c_build_qualified_type (main_type
, quals
);
10931 if (COMPLETE_TYPE_P (type
)
10932 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
10933 && (overflow_p
|| TREE_OVERFLOW (TYPE_SIZE_UNIT (type
))))
10935 error ("size of array is too large");
10936 /* If we proceed with the array type as it is, we'll eventually
10937 crash in tree_to_[su]hwi(). */
10938 type
= error_mark_node
;
10945 /* Like c_mark_addressable but don't check register qualifier. */
10947 c_common_mark_addressable_vec (tree t
)
10949 while (handled_component_p (t
))
10950 t
= TREE_OPERAND (t
, 0);
10951 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
10953 TREE_ADDRESSABLE (t
) = 1;
10958 /* Used to help initialize the builtin-types.def table. When a type of
10959 the correct size doesn't exist, use error_mark_node instead of NULL.
10960 The later results in segfaults even when a decl using the type doesn't
10964 builtin_type_for_size (int size
, bool unsignedp
)
10966 tree type
= c_common_type_for_size (size
, unsignedp
);
10967 return type
? type
: error_mark_node
;
10970 /* A helper function for resolve_overloaded_builtin in resolving the
10971 overloaded __sync_ builtins. Returns a positive power of 2 if the
10972 first operand of PARAMS is a pointer to a supported data type.
10973 Returns 0 if an error is encountered. */
10976 sync_resolve_size (tree function
, vec
<tree
, va_gc
> *params
)
10983 error ("too few arguments to function %qE", function
);
10987 type
= TREE_TYPE ((*params
)[0]);
10988 if (TREE_CODE (type
) == ARRAY_TYPE
)
10990 /* Force array-to-pointer decay for C++. */
10991 gcc_assert (c_dialect_cxx());
10992 (*params
)[0] = default_conversion ((*params
)[0]);
10993 type
= TREE_TYPE ((*params
)[0]);
10995 if (TREE_CODE (type
) != POINTER_TYPE
)
10998 type
= TREE_TYPE (type
);
10999 if (!INTEGRAL_TYPE_P (type
) && !POINTER_TYPE_P (type
))
11002 size
= tree_to_uhwi (TYPE_SIZE_UNIT (type
));
11003 if (size
== 1 || size
== 2 || size
== 4 || size
== 8 || size
== 16)
11007 error ("incompatible type for argument %d of %qE", 1, function
);
11011 /* A helper function for resolve_overloaded_builtin. Adds casts to
11012 PARAMS to make arguments match up with those of FUNCTION. Drops
11013 the variadic arguments at the end. Returns false if some error
11014 was encountered; true on success. */
11017 sync_resolve_params (location_t loc
, tree orig_function
, tree function
,
11018 vec
<tree
, va_gc
> *params
, bool orig_format
)
11020 function_args_iterator iter
;
11022 unsigned int parmnum
;
11024 function_args_iter_init (&iter
, TREE_TYPE (function
));
11025 /* We've declared the implementation functions to use "volatile void *"
11026 as the pointer parameter, so we shouldn't get any complaints from the
11027 call to check_function_arguments what ever type the user used. */
11028 function_args_iter_next (&iter
);
11029 ptype
= TREE_TYPE (TREE_TYPE ((*params
)[0]));
11030 ptype
= TYPE_MAIN_VARIANT (ptype
);
11032 /* For the rest of the values, we need to cast these to FTYPE, so that we
11033 don't get warnings for passing pointer types, etc. */
11037 tree val
, arg_type
;
11039 arg_type
= function_args_iter_cond (&iter
);
11040 /* XXX void_type_node belies the abstraction. */
11041 if (arg_type
== void_type_node
)
11045 if (params
->length () <= parmnum
)
11047 error_at (loc
, "too few arguments to function %qE", orig_function
);
11051 /* Only convert parameters if arg_type is unsigned integer type with
11052 new format sync routines, i.e. don't attempt to convert pointer
11053 arguments (e.g. EXPECTED argument of __atomic_compare_exchange_n),
11054 bool arguments (e.g. WEAK argument) or signed int arguments (memmodel
11056 if (TREE_CODE (arg_type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (arg_type
))
11058 /* Ideally for the first conversion we'd use convert_for_assignment
11059 so that we get warnings for anything that doesn't match the pointer
11060 type. This isn't portable across the C and C++ front ends atm. */
11061 val
= (*params
)[parmnum
];
11062 val
= convert (ptype
, val
);
11063 val
= convert (arg_type
, val
);
11064 (*params
)[parmnum
] = val
;
11067 function_args_iter_next (&iter
);
11070 /* __atomic routines are not variadic. */
11071 if (!orig_format
&& params
->length () != parmnum
+ 1)
11073 error_at (loc
, "too many arguments to function %qE", orig_function
);
11077 /* The definition of these primitives is variadic, with the remaining
11078 being "an optional list of variables protected by the memory barrier".
11079 No clue what that's supposed to mean, precisely, but we consider all
11080 call-clobbered variables to be protected so we're safe. */
11081 params
->truncate (parmnum
+ 1);
11086 /* A helper function for resolve_overloaded_builtin. Adds a cast to
11087 RESULT to make it match the type of the first pointer argument in
11091 sync_resolve_return (tree first_param
, tree result
, bool orig_format
)
11093 tree ptype
= TREE_TYPE (TREE_TYPE (first_param
));
11094 tree rtype
= TREE_TYPE (result
);
11095 ptype
= TYPE_MAIN_VARIANT (ptype
);
11097 /* New format doesn't require casting unless the types are the same size. */
11098 if (orig_format
|| tree_int_cst_equal (TYPE_SIZE (ptype
), TYPE_SIZE (rtype
)))
11099 return convert (ptype
, result
);
11104 /* This function verifies the PARAMS to generic atomic FUNCTION.
11105 It returns the size if all the parameters are the same size, otherwise
11106 0 is returned if the parameters are invalid. */
11109 get_atomic_generic_size (location_t loc
, tree function
,
11110 vec
<tree
, va_gc
> *params
)
11112 unsigned int n_param
;
11113 unsigned int n_model
;
11118 /* Determine the parameter makeup. */
11119 switch (DECL_FUNCTION_CODE (function
))
11121 case BUILT_IN_ATOMIC_EXCHANGE
:
11125 case BUILT_IN_ATOMIC_LOAD
:
11126 case BUILT_IN_ATOMIC_STORE
:
11130 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
11135 gcc_unreachable ();
11138 if (vec_safe_length (params
) != n_param
)
11140 error_at (loc
, "incorrect number of arguments to function %qE", function
);
11144 /* Get type of first parameter, and determine its size. */
11145 type_0
= TREE_TYPE ((*params
)[0]);
11146 if (TREE_CODE (type_0
) == ARRAY_TYPE
)
11148 /* Force array-to-pointer decay for C++. */
11149 gcc_assert (c_dialect_cxx());
11150 (*params
)[0] = default_conversion ((*params
)[0]);
11151 type_0
= TREE_TYPE ((*params
)[0]);
11153 if (TREE_CODE (type_0
) != POINTER_TYPE
|| VOID_TYPE_P (TREE_TYPE (type_0
)))
11155 error_at (loc
, "argument 1 of %qE must be a non-void pointer type",
11160 /* Types must be compile time constant sizes. */
11161 if (TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type_0
)))) != INTEGER_CST
)
11164 "argument 1 of %qE must be a pointer to a constant size type",
11169 size_0
= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type_0
)));
11171 /* Zero size objects are not allowed. */
11175 "argument 1 of %qE must be a pointer to a nonzero size object",
11180 /* Check each other parameter is a pointer and the same size. */
11181 for (x
= 0; x
< n_param
- n_model
; x
++)
11184 tree type
= TREE_TYPE ((*params
)[x
]);
11185 /* __atomic_compare_exchange has a bool in the 4th position, skip it. */
11186 if (n_param
== 6 && x
== 3)
11188 if (!POINTER_TYPE_P (type
))
11190 error_at (loc
, "argument %d of %qE must be a pointer type", x
+ 1,
11194 tree type_size
= TYPE_SIZE_UNIT (TREE_TYPE (type
));
11195 size
= type_size
? tree_to_uhwi (type_size
) : 0;
11196 if (size
!= size_0
)
11198 error_at (loc
, "size mismatch in argument %d of %qE", x
+ 1,
11204 /* Check memory model parameters for validity. */
11205 for (x
= n_param
- n_model
; x
< n_param
; x
++)
11207 tree p
= (*params
)[x
];
11208 if (TREE_CODE (p
) == INTEGER_CST
)
11210 int i
= tree_to_uhwi (p
);
11211 if (i
< 0 || (memmodel_base (i
) >= MEMMODEL_LAST
))
11213 warning_at (loc
, OPT_Winvalid_memory_model
,
11214 "invalid memory model argument %d of %qE", x
+ 1,
11219 if (!INTEGRAL_TYPE_P (TREE_TYPE (p
)))
11221 error_at (loc
, "non-integer memory model argument %d of %qE", x
+ 1,
11231 /* This will take an __atomic_ generic FUNCTION call, and add a size parameter N
11232 at the beginning of the parameter list PARAMS representing the size of the
11233 objects. This is to match the library ABI requirement. LOC is the location
11234 of the function call.
11235 The new function is returned if it needed rebuilding, otherwise NULL_TREE is
11236 returned to allow the external call to be constructed. */
11239 add_atomic_size_parameter (unsigned n
, location_t loc
, tree function
,
11240 vec
<tree
, va_gc
> *params
)
11244 /* Insert a SIZE_T parameter as the first param. If there isn't
11245 enough space, allocate a new vector and recursively re-build with that. */
11246 if (!params
->space (1))
11248 unsigned int z
, len
;
11249 vec
<tree
, va_gc
> *v
;
11252 len
= params
->length ();
11253 vec_alloc (v
, len
+ 1);
11254 v
->quick_push (build_int_cst (size_type_node
, n
));
11255 for (z
= 0; z
< len
; z
++)
11256 v
->quick_push ((*params
)[z
]);
11257 f
= build_function_call_vec (loc
, vNULL
, function
, v
, NULL
);
11262 /* Add the size parameter and leave as a function call for processing. */
11263 size_node
= build_int_cst (size_type_node
, n
);
11264 params
->quick_insert (0, size_node
);
11269 /* Return whether atomic operations for naturally aligned N-byte
11270 arguments are supported, whether inline or through libatomic. */
11272 atomic_size_supported_p (int n
)
11283 return targetm
.scalar_mode_supported_p (TImode
);
11290 /* This will process an __atomic_exchange function call, determine whether it
11291 needs to be mapped to the _N variation, or turned into a library call.
11292 LOC is the location of the builtin call.
11293 FUNCTION is the DECL that has been invoked;
11294 PARAMS is the argument list for the call. The return value is non-null
11295 TRUE is returned if it is translated into the proper format for a call to the
11296 external library, and NEW_RETURN is set the tree for that function.
11297 FALSE is returned if processing for the _N variation is required, and
11298 NEW_RETURN is set to the return value the result is copied into. */
11300 resolve_overloaded_atomic_exchange (location_t loc
, tree function
,
11301 vec
<tree
, va_gc
> *params
, tree
*new_return
)
11303 tree p0
, p1
, p2
, p3
;
11304 tree I_type
, I_type_ptr
;
11305 int n
= get_atomic_generic_size (loc
, function
, params
);
11307 /* Size of 0 is an error condition. */
11310 *new_return
= error_mark_node
;
11314 /* If not a lock-free size, change to the library generic format. */
11315 if (!atomic_size_supported_p (n
))
11317 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
11321 /* Otherwise there is a lockfree match, transform the call from:
11322 void fn(T* mem, T* desired, T* return, model)
11324 *return = (T) (fn (In* mem, (In) *desired, model)) */
11331 /* Create pointer to appropriate size. */
11332 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
11333 I_type_ptr
= build_pointer_type (I_type
);
11335 /* Convert object pointer to required type. */
11336 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
11338 /* Convert new value to required type, and dereference it. */
11339 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
11340 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
11343 /* Move memory model to the 3rd position, and end param list. */
11345 params
->truncate (3);
11347 /* Convert return pointer and dereference it for later assignment. */
11348 *new_return
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
11354 /* This will process an __atomic_compare_exchange function call, determine
11355 whether it needs to be mapped to the _N variation, or turned into a lib call.
11356 LOC is the location of the builtin call.
11357 FUNCTION is the DECL that has been invoked;
11358 PARAMS is the argument list for the call. The return value is non-null
11359 TRUE is returned if it is translated into the proper format for a call to the
11360 external library, and NEW_RETURN is set the tree for that function.
11361 FALSE is returned if processing for the _N variation is required. */
11364 resolve_overloaded_atomic_compare_exchange (location_t loc
, tree function
,
11365 vec
<tree
, va_gc
> *params
,
11369 tree I_type
, I_type_ptr
;
11370 int n
= get_atomic_generic_size (loc
, function
, params
);
11372 /* Size of 0 is an error condition. */
11375 *new_return
= error_mark_node
;
11379 /* If not a lock-free size, change to the library generic format. */
11380 if (!atomic_size_supported_p (n
))
11382 /* The library generic format does not have the weak parameter, so
11383 remove it from the param list. Since a parameter has been removed,
11384 we can be sure that there is room for the SIZE_T parameter, meaning
11385 there will not be a recursive rebuilding of the parameter list, so
11386 there is no danger this will be done twice. */
11389 (*params
)[3] = (*params
)[4];
11390 (*params
)[4] = (*params
)[5];
11391 params
->truncate (5);
11393 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
11397 /* Otherwise, there is a match, so the call needs to be transformed from:
11398 bool fn(T* mem, T* desired, T* return, weak, success, failure)
11400 bool fn ((In *)mem, (In *)expected, (In) *desired, weak, succ, fail) */
11406 /* Create pointer to appropriate size. */
11407 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
11408 I_type_ptr
= build_pointer_type (I_type
);
11410 /* Convert object pointer to required type. */
11411 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
11414 /* Convert expected pointer to required type. */
11415 p1
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p1
);
11418 /* Convert desired value to required type, and dereference it. */
11419 p2
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
11420 p2
= build1 (VIEW_CONVERT_EXPR
, I_type
, p2
);
11423 /* The rest of the parameters are fine. NULL means no special return value
11425 *new_return
= NULL
;
11430 /* This will process an __atomic_load function call, determine whether it
11431 needs to be mapped to the _N variation, or turned into a library call.
11432 LOC is the location of the builtin call.
11433 FUNCTION is the DECL that has been invoked;
11434 PARAMS is the argument list for the call. The return value is non-null
11435 TRUE is returned if it is translated into the proper format for a call to the
11436 external library, and NEW_RETURN is set the tree for that function.
11437 FALSE is returned if processing for the _N variation is required, and
11438 NEW_RETURN is set to the return value the result is copied into. */
11441 resolve_overloaded_atomic_load (location_t loc
, tree function
,
11442 vec
<tree
, va_gc
> *params
, tree
*new_return
)
11445 tree I_type
, I_type_ptr
;
11446 int n
= get_atomic_generic_size (loc
, function
, params
);
11448 /* Size of 0 is an error condition. */
11451 *new_return
= error_mark_node
;
11455 /* If not a lock-free size, change to the library generic format. */
11456 if (!atomic_size_supported_p (n
))
11458 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
11462 /* Otherwise, there is a match, so the call needs to be transformed from:
11463 void fn(T* mem, T* return, model)
11465 *return = (T) (fn ((In *) mem, model)) */
11471 /* Create pointer to appropriate size. */
11472 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
11473 I_type_ptr
= build_pointer_type (I_type
);
11475 /* Convert object pointer to required type. */
11476 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
11479 /* Move memory model to the 2nd position, and end param list. */
11481 params
->truncate (2);
11483 /* Convert return pointer and dereference it for later assignment. */
11484 *new_return
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
11490 /* This will process an __atomic_store function call, determine whether it
11491 needs to be mapped to the _N variation, or turned into a library call.
11492 LOC is the location of the builtin call.
11493 FUNCTION is the DECL that has been invoked;
11494 PARAMS is the argument list for the call. The return value is non-null
11495 TRUE is returned if it is translated into the proper format for a call to the
11496 external library, and NEW_RETURN is set the tree for that function.
11497 FALSE is returned if processing for the _N variation is required, and
11498 NEW_RETURN is set to the return value the result is copied into. */
11501 resolve_overloaded_atomic_store (location_t loc
, tree function
,
11502 vec
<tree
, va_gc
> *params
, tree
*new_return
)
11505 tree I_type
, I_type_ptr
;
11506 int n
= get_atomic_generic_size (loc
, function
, params
);
11508 /* Size of 0 is an error condition. */
11511 *new_return
= error_mark_node
;
11515 /* If not a lock-free size, change to the library generic format. */
11516 if (!atomic_size_supported_p (n
))
11518 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
11522 /* Otherwise, there is a match, so the call needs to be transformed from:
11523 void fn(T* mem, T* value, model)
11525 fn ((In *) mem, (In) *value, model) */
11530 /* Create pointer to appropriate size. */
11531 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
11532 I_type_ptr
= build_pointer_type (I_type
);
11534 /* Convert object pointer to required type. */
11535 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
11538 /* Convert new value to required type, and dereference it. */
11539 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
11540 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
11543 /* The memory model is in the right spot already. Return is void. */
11544 *new_return
= NULL_TREE
;
11550 /* Some builtin functions are placeholders for other expressions. This
11551 function should be called immediately after parsing the call expression
11552 before surrounding code has committed to the type of the expression.
11554 LOC is the location of the builtin call.
11556 FUNCTION is the DECL that has been invoked; it is known to be a builtin.
11557 PARAMS is the argument list for the call. The return value is non-null
11558 when expansion is complete, and null if normal processing should
11562 resolve_overloaded_builtin (location_t loc
, tree function
,
11563 vec
<tree
, va_gc
> *params
)
11565 enum built_in_function orig_code
= DECL_FUNCTION_CODE (function
);
11566 bool orig_format
= true;
11567 tree new_return
= NULL_TREE
;
11569 switch (DECL_BUILT_IN_CLASS (function
))
11571 case BUILT_IN_NORMAL
:
11574 if (targetm
.resolve_overloaded_builtin
)
11575 return targetm
.resolve_overloaded_builtin (loc
, function
, params
);
11582 /* Handle BUILT_IN_NORMAL here. */
11585 case BUILT_IN_ATOMIC_EXCHANGE
:
11586 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
11587 case BUILT_IN_ATOMIC_LOAD
:
11588 case BUILT_IN_ATOMIC_STORE
:
11590 /* Handle these 4 together so that they can fall through to the next
11591 case if the call is transformed to an _N variant. */
11594 case BUILT_IN_ATOMIC_EXCHANGE
:
11596 if (resolve_overloaded_atomic_exchange (loc
, function
, params
,
11599 /* Change to the _N variant. */
11600 orig_code
= BUILT_IN_ATOMIC_EXCHANGE_N
;
11604 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
11606 if (resolve_overloaded_atomic_compare_exchange (loc
, function
,
11610 /* Change to the _N variant. */
11611 orig_code
= BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
;
11614 case BUILT_IN_ATOMIC_LOAD
:
11616 if (resolve_overloaded_atomic_load (loc
, function
, params
,
11619 /* Change to the _N variant. */
11620 orig_code
= BUILT_IN_ATOMIC_LOAD_N
;
11623 case BUILT_IN_ATOMIC_STORE
:
11625 if (resolve_overloaded_atomic_store (loc
, function
, params
,
11628 /* Change to the _N variant. */
11629 orig_code
= BUILT_IN_ATOMIC_STORE_N
;
11633 gcc_unreachable ();
11635 /* Fallthrough to the normal processing. */
11637 case BUILT_IN_ATOMIC_EXCHANGE_N
:
11638 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
:
11639 case BUILT_IN_ATOMIC_LOAD_N
:
11640 case BUILT_IN_ATOMIC_STORE_N
:
11641 case BUILT_IN_ATOMIC_ADD_FETCH_N
:
11642 case BUILT_IN_ATOMIC_SUB_FETCH_N
:
11643 case BUILT_IN_ATOMIC_AND_FETCH_N
:
11644 case BUILT_IN_ATOMIC_NAND_FETCH_N
:
11645 case BUILT_IN_ATOMIC_XOR_FETCH_N
:
11646 case BUILT_IN_ATOMIC_OR_FETCH_N
:
11647 case BUILT_IN_ATOMIC_FETCH_ADD_N
:
11648 case BUILT_IN_ATOMIC_FETCH_SUB_N
:
11649 case BUILT_IN_ATOMIC_FETCH_AND_N
:
11650 case BUILT_IN_ATOMIC_FETCH_NAND_N
:
11651 case BUILT_IN_ATOMIC_FETCH_XOR_N
:
11652 case BUILT_IN_ATOMIC_FETCH_OR_N
:
11654 orig_format
= false;
11655 /* Fallthru for parameter processing. */
11657 case BUILT_IN_SYNC_FETCH_AND_ADD_N
:
11658 case BUILT_IN_SYNC_FETCH_AND_SUB_N
:
11659 case BUILT_IN_SYNC_FETCH_AND_OR_N
:
11660 case BUILT_IN_SYNC_FETCH_AND_AND_N
:
11661 case BUILT_IN_SYNC_FETCH_AND_XOR_N
:
11662 case BUILT_IN_SYNC_FETCH_AND_NAND_N
:
11663 case BUILT_IN_SYNC_ADD_AND_FETCH_N
:
11664 case BUILT_IN_SYNC_SUB_AND_FETCH_N
:
11665 case BUILT_IN_SYNC_OR_AND_FETCH_N
:
11666 case BUILT_IN_SYNC_AND_AND_FETCH_N
:
11667 case BUILT_IN_SYNC_XOR_AND_FETCH_N
:
11668 case BUILT_IN_SYNC_NAND_AND_FETCH_N
:
11669 case BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
:
11670 case BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N
:
11671 case BUILT_IN_SYNC_LOCK_TEST_AND_SET_N
:
11672 case BUILT_IN_SYNC_LOCK_RELEASE_N
:
11674 int n
= sync_resolve_size (function
, params
);
11675 tree new_function
, first_param
, result
;
11676 enum built_in_function fncode
;
11679 return error_mark_node
;
11681 fncode
= (enum built_in_function
)((int)orig_code
+ exact_log2 (n
) + 1);
11682 new_function
= builtin_decl_explicit (fncode
);
11683 if (!sync_resolve_params (loc
, function
, new_function
, params
,
11685 return error_mark_node
;
11687 first_param
= (*params
)[0];
11688 result
= build_function_call_vec (loc
, vNULL
, new_function
, params
,
11690 if (result
== error_mark_node
)
11692 if (orig_code
!= BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
11693 && orig_code
!= BUILT_IN_SYNC_LOCK_RELEASE_N
11694 && orig_code
!= BUILT_IN_ATOMIC_STORE_N
)
11695 result
= sync_resolve_return (first_param
, result
, orig_format
);
11697 /* If new_return is set, assign function to that expr and cast the
11698 result to void since the generic interface returned void. */
11701 /* Cast function result from I{1,2,4,8,16} to the required type. */
11702 result
= build1 (VIEW_CONVERT_EXPR
, TREE_TYPE (new_return
), result
);
11703 result
= build2 (MODIFY_EXPR
, TREE_TYPE (new_return
), new_return
,
11705 TREE_SIDE_EFFECTS (result
) = 1;
11706 protected_set_expr_location (result
, loc
);
11707 result
= convert (void_type_node
, result
);
11717 /* vector_types_compatible_elements_p is used in type checks of vectors
11718 values used as operands of binary operators. Where it returns true, and
11719 the other checks of the caller succeed (being vector types in he first
11720 place, and matching number of elements), we can just treat the types
11721 as essentially the same.
11722 Contrast with vector_targets_convertible_p, which is used for vector
11723 pointer types, and vector_types_convertible_p, which will allow
11724 language-specific matches under the control of flag_lax_vector_conversions,
11725 and might still require a conversion. */
11726 /* True if vector types T1 and T2 can be inputs to the same binary
11727 operator without conversion.
11728 We don't check the overall vector size here because some of our callers
11729 want to give different error messages when the vectors are compatible
11730 except for the element count. */
11733 vector_types_compatible_elements_p (tree t1
, tree t2
)
11735 bool opaque
= TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
);
11736 t1
= TREE_TYPE (t1
);
11737 t2
= TREE_TYPE (t2
);
11739 enum tree_code c1
= TREE_CODE (t1
), c2
= TREE_CODE (t2
);
11741 gcc_assert ((c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
|| c1
== FIXED_POINT_TYPE
)
11742 && (c2
== INTEGER_TYPE
|| c2
== REAL_TYPE
11743 || c2
== FIXED_POINT_TYPE
));
11745 t1
= c_common_signed_type (t1
);
11746 t2
= c_common_signed_type (t2
);
11747 /* Equality works here because c_common_signed_type uses
11748 TYPE_MAIN_VARIANT. */
11751 if (opaque
&& c1
== c2
11752 && (c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
)
11753 && TYPE_PRECISION (t1
) == TYPE_PRECISION (t2
))
11758 /* Check for missing format attributes on function pointers. LTYPE is
11759 the new type or left-hand side type. RTYPE is the old type or
11760 right-hand side type. Returns TRUE if LTYPE is missing the desired
11764 check_missing_format_attribute (tree ltype
, tree rtype
)
11766 tree
const ttr
= TREE_TYPE (rtype
), ttl
= TREE_TYPE (ltype
);
11769 for (ra
= TYPE_ATTRIBUTES (ttr
); ra
; ra
= TREE_CHAIN (ra
))
11770 if (is_attribute_p ("format", TREE_PURPOSE (ra
)))
11775 for (la
= TYPE_ATTRIBUTES (ttl
); la
; la
= TREE_CHAIN (la
))
11776 if (is_attribute_p ("format", TREE_PURPOSE (la
)))
11784 /* Subscripting with type char is likely to lose on a machine where
11785 chars are signed. So warn on any machine, but optionally. Don't
11786 warn for unsigned char since that type is safe. Don't warn for
11787 signed char because anyone who uses that must have done so
11788 deliberately. Furthermore, we reduce the false positive load by
11789 warning only for non-constant value of type char. */
11792 warn_array_subscript_with_type_char (location_t loc
, tree index
)
11794 if (TYPE_MAIN_VARIANT (TREE_TYPE (index
)) == char_type_node
11795 && TREE_CODE (index
) != INTEGER_CST
)
11796 warning_at (loc
, OPT_Wchar_subscripts
,
11797 "array subscript has type %<char%>");
11800 /* Implement -Wparentheses for the unexpected C precedence rules, to
11801 cover cases like x + y << z which readers are likely to
11802 misinterpret. We have seen an expression in which CODE is a binary
11803 operator used to combine expressions ARG_LEFT and ARG_RIGHT, which
11804 before folding had CODE_LEFT and CODE_RIGHT. CODE_LEFT and
11805 CODE_RIGHT may be ERROR_MARK, which means that that side of the
11806 expression was not formed using a binary or unary operator, or it
11807 was enclosed in parentheses. */
11810 warn_about_parentheses (location_t loc
, enum tree_code code
,
11811 enum tree_code code_left
, tree arg_left
,
11812 enum tree_code code_right
, tree arg_right
)
11814 if (!warn_parentheses
)
11817 /* This macro tests that the expression ARG with original tree code
11818 CODE appears to be a boolean expression. or the result of folding a
11819 boolean expression. */
11820 #define APPEARS_TO_BE_BOOLEAN_EXPR_P(CODE, ARG) \
11821 (truth_value_p (TREE_CODE (ARG)) \
11822 || TREE_CODE (TREE_TYPE (ARG)) == BOOLEAN_TYPE \
11823 /* Folding may create 0 or 1 integers from other expressions. */ \
11824 || ((CODE) != INTEGER_CST \
11825 && (integer_onep (ARG) || integer_zerop (ARG))))
11830 if (code_left
== PLUS_EXPR
)
11831 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11832 "suggest parentheses around %<+%> inside %<<<%>");
11833 else if (code_right
== PLUS_EXPR
)
11834 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11835 "suggest parentheses around %<+%> inside %<<<%>");
11836 else if (code_left
== MINUS_EXPR
)
11837 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11838 "suggest parentheses around %<-%> inside %<<<%>");
11839 else if (code_right
== MINUS_EXPR
)
11840 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11841 "suggest parentheses around %<-%> inside %<<<%>");
11845 if (code_left
== PLUS_EXPR
)
11846 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11847 "suggest parentheses around %<+%> inside %<>>%>");
11848 else if (code_right
== PLUS_EXPR
)
11849 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11850 "suggest parentheses around %<+%> inside %<>>%>");
11851 else if (code_left
== MINUS_EXPR
)
11852 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11853 "suggest parentheses around %<-%> inside %<>>%>");
11854 else if (code_right
== MINUS_EXPR
)
11855 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11856 "suggest parentheses around %<-%> inside %<>>%>");
11859 case TRUTH_ORIF_EXPR
:
11860 if (code_left
== TRUTH_ANDIF_EXPR
)
11861 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11862 "suggest parentheses around %<&&%> within %<||%>");
11863 else if (code_right
== TRUTH_ANDIF_EXPR
)
11864 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11865 "suggest parentheses around %<&&%> within %<||%>");
11869 if (code_left
== BIT_AND_EXPR
|| code_left
== BIT_XOR_EXPR
11870 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
)
11871 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11872 "suggest parentheses around arithmetic in operand of %<|%>");
11873 else if (code_right
== BIT_AND_EXPR
|| code_right
== BIT_XOR_EXPR
11874 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
11875 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11876 "suggest parentheses around arithmetic in operand of %<|%>");
11877 /* Check cases like x|y==z */
11878 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11879 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11880 "suggest parentheses around comparison in operand of %<|%>");
11881 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11882 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11883 "suggest parentheses around comparison in operand of %<|%>");
11884 /* Check cases like !x | y */
11885 else if (code_left
== TRUTH_NOT_EXPR
11886 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
11887 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11888 "suggest parentheses around operand of "
11889 "%<!%> or change %<|%> to %<||%> or %<!%> to %<~%>");
11893 if (code_left
== BIT_AND_EXPR
11894 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
)
11895 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11896 "suggest parentheses around arithmetic in operand of %<^%>");
11897 else if (code_right
== BIT_AND_EXPR
11898 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
11899 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11900 "suggest parentheses around arithmetic in operand of %<^%>");
11901 /* Check cases like x^y==z */
11902 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11903 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11904 "suggest parentheses around comparison in operand of %<^%>");
11905 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11906 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11907 "suggest parentheses around comparison in operand of %<^%>");
11911 if (code_left
== PLUS_EXPR
)
11912 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11913 "suggest parentheses around %<+%> in operand of %<&%>");
11914 else if (code_right
== PLUS_EXPR
)
11915 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11916 "suggest parentheses around %<+%> in operand of %<&%>");
11917 else if (code_left
== MINUS_EXPR
)
11918 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11919 "suggest parentheses around %<-%> in operand of %<&%>");
11920 else if (code_right
== MINUS_EXPR
)
11921 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11922 "suggest parentheses around %<-%> in operand of %<&%>");
11923 /* Check cases like x&y==z */
11924 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11925 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11926 "suggest parentheses around comparison in operand of %<&%>");
11927 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11928 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11929 "suggest parentheses around comparison in operand of %<&%>");
11930 /* Check cases like !x & y */
11931 else if (code_left
== TRUTH_NOT_EXPR
11932 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
11933 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11934 "suggest parentheses around operand of "
11935 "%<!%> or change %<&%> to %<&&%> or %<!%> to %<~%>");
11939 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11940 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11941 "suggest parentheses around comparison in operand of %<==%>");
11942 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11943 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11944 "suggest parentheses around comparison in operand of %<==%>");
11947 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11948 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11949 "suggest parentheses around comparison in operand of %<!=%>");
11950 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11951 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11952 "suggest parentheses around comparison in operand of %<!=%>");
11956 if (TREE_CODE_CLASS (code
) == tcc_comparison
)
11958 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
11959 && code_left
!= NE_EXPR
&& code_left
!= EQ_EXPR
11960 && INTEGRAL_TYPE_P (TREE_TYPE (arg_left
)))
11961 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11962 "comparisons like %<X<=Y<=Z%> do not "
11963 "have their mathematical meaning");
11964 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
11965 && code_right
!= NE_EXPR
&& code_right
!= EQ_EXPR
11966 && INTEGRAL_TYPE_P (TREE_TYPE (arg_right
)))
11967 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11968 "comparisons like %<X<=Y<=Z%> do not "
11969 "have their mathematical meaning");
11973 #undef NOT_A_BOOLEAN_EXPR_P
11976 /* If LABEL (a LABEL_DECL) has not been used, issue a warning. */
11979 warn_for_unused_label (tree label
)
11981 if (!TREE_USED (label
))
11983 if (DECL_INITIAL (label
))
11984 warning (OPT_Wunused_label
, "label %q+D defined but not used", label
);
11986 warning (OPT_Wunused_label
, "label %q+D declared but not defined", label
);
11990 /* Warn for division by zero according to the value of DIVISOR. LOC
11991 is the location of the division operator. */
11994 warn_for_div_by_zero (location_t loc
, tree divisor
)
11996 /* If DIVISOR is zero, and has integral or fixed-point type, issue a warning
11997 about division by zero. Do not issue a warning if DIVISOR has a
11998 floating-point type, since we consider 0.0/0.0 a valid way of
11999 generating a NaN. */
12000 if (c_inhibit_evaluation_warnings
== 0
12001 && (integer_zerop (divisor
) || fixed_zerop (divisor
)))
12002 warning_at (loc
, OPT_Wdiv_by_zero
, "division by zero");
12005 /* Subroutine of build_binary_op. Give warnings for comparisons
12006 between signed and unsigned quantities that may fail. Do the
12007 checking based on the original operand trees ORIG_OP0 and ORIG_OP1,
12008 so that casts will be considered, but default promotions won't
12011 LOCATION is the location of the comparison operator.
12013 The arguments of this function map directly to local variables
12014 of build_binary_op. */
12017 warn_for_sign_compare (location_t location
,
12018 tree orig_op0
, tree orig_op1
,
12019 tree op0
, tree op1
,
12020 tree result_type
, enum tree_code resultcode
)
12022 int op0_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op0
));
12023 int op1_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op1
));
12024 int unsignedp0
, unsignedp1
;
12026 /* In C++, check for comparison of different enum types. */
12027 if (c_dialect_cxx()
12028 && TREE_CODE (TREE_TYPE (orig_op0
)) == ENUMERAL_TYPE
12029 && TREE_CODE (TREE_TYPE (orig_op1
)) == ENUMERAL_TYPE
12030 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0
))
12031 != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1
)))
12033 warning_at (location
,
12034 OPT_Wsign_compare
, "comparison between types %qT and %qT",
12035 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
));
12038 /* Do not warn if the comparison is being done in a signed type,
12039 since the signed type will only be chosen if it can represent
12040 all the values of the unsigned type. */
12041 if (!TYPE_UNSIGNED (result_type
))
12043 /* Do not warn if both operands are unsigned. */
12044 else if (op0_signed
== op1_signed
)
12048 tree sop
, uop
, base_type
;
12052 sop
= orig_op0
, uop
= orig_op1
;
12054 sop
= orig_op1
, uop
= orig_op0
;
12056 STRIP_TYPE_NOPS (sop
);
12057 STRIP_TYPE_NOPS (uop
);
12058 base_type
= (TREE_CODE (result_type
) == COMPLEX_TYPE
12059 ? TREE_TYPE (result_type
) : result_type
);
12061 /* Do not warn if the signed quantity is an unsuffixed integer
12062 literal (or some static constant expression involving such
12063 literals or a conditional expression involving such literals)
12064 and it is non-negative. */
12065 if (tree_expr_nonnegative_warnv_p (sop
, &ovf
))
12067 /* Do not warn if the comparison is an equality operation, the
12068 unsigned quantity is an integral constant, and it would fit
12069 in the result if the result were signed. */
12070 else if (TREE_CODE (uop
) == INTEGER_CST
12071 && (resultcode
== EQ_EXPR
|| resultcode
== NE_EXPR
)
12072 && int_fits_type_p (uop
, c_common_signed_type (base_type
)))
12074 /* In C, do not warn if the unsigned quantity is an enumeration
12075 constant and its maximum value would fit in the result if the
12076 result were signed. */
12077 else if (!c_dialect_cxx() && TREE_CODE (uop
) == INTEGER_CST
12078 && TREE_CODE (TREE_TYPE (uop
)) == ENUMERAL_TYPE
12079 && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (uop
)),
12080 c_common_signed_type (base_type
)))
12083 warning_at (location
,
12085 "comparison between signed and unsigned integer expressions");
12088 /* Warn if two unsigned values are being compared in a size larger
12089 than their original size, and one (and only one) is the result of
12090 a `~' operator. This comparison will always fail.
12092 Also warn if one operand is a constant, and the constant does not
12093 have all bits set that are set in the ~ operand when it is
12096 op0
= c_common_get_narrower (op0
, &unsignedp0
);
12097 op1
= c_common_get_narrower (op1
, &unsignedp1
);
12099 if ((TREE_CODE (op0
) == BIT_NOT_EXPR
)
12100 ^ (TREE_CODE (op1
) == BIT_NOT_EXPR
))
12102 if (TREE_CODE (op0
) == BIT_NOT_EXPR
)
12103 op0
= c_common_get_narrower (TREE_OPERAND (op0
, 0), &unsignedp0
);
12104 if (TREE_CODE (op1
) == BIT_NOT_EXPR
)
12105 op1
= c_common_get_narrower (TREE_OPERAND (op1
, 0), &unsignedp1
);
12107 if (tree_fits_shwi_p (op0
) || tree_fits_shwi_p (op1
))
12110 HOST_WIDE_INT constant
, mask
;
12114 if (tree_fits_shwi_p (op0
))
12117 unsignedp
= unsignedp1
;
12118 constant
= tree_to_shwi (op0
);
12123 unsignedp
= unsignedp0
;
12124 constant
= tree_to_shwi (op1
);
12127 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
12128 if (bits
< TYPE_PRECISION (result_type
)
12129 && bits
< HOST_BITS_PER_LONG
&& unsignedp
)
12131 mask
= (~ (HOST_WIDE_INT
) 0) << bits
;
12132 if ((mask
& constant
) != mask
)
12135 warning_at (location
, OPT_Wsign_compare
,
12136 "promoted ~unsigned is always non-zero");
12138 warning_at (location
, OPT_Wsign_compare
,
12139 "comparison of promoted ~unsigned with constant");
12143 else if (unsignedp0
&& unsignedp1
12144 && (TYPE_PRECISION (TREE_TYPE (op0
))
12145 < TYPE_PRECISION (result_type
))
12146 && (TYPE_PRECISION (TREE_TYPE (op1
))
12147 < TYPE_PRECISION (result_type
)))
12148 warning_at (location
, OPT_Wsign_compare
,
12149 "comparison of promoted ~unsigned with unsigned");
12153 /* RESULT_TYPE is the result of converting TYPE1 and TYPE2 to a common
12154 type via c_common_type. If -Wdouble-promotion is in use, and the
12155 conditions for warning have been met, issue a warning. GMSGID is
12156 the warning message. It must have two %T specifiers for the type
12157 that was converted (generally "float") and the type to which it was
12158 converted (generally "double), respectively. LOC is the location
12159 to which the awrning should refer. */
12162 do_warn_double_promotion (tree result_type
, tree type1
, tree type2
,
12163 const char *gmsgid
, location_t loc
)
12167 if (!warn_double_promotion
)
12169 /* If the conversion will not occur at run-time, there is no need to
12171 if (c_inhibit_evaluation_warnings
)
12173 if (TYPE_MAIN_VARIANT (result_type
) != double_type_node
12174 && TYPE_MAIN_VARIANT (result_type
) != complex_double_type_node
)
12176 if (TYPE_MAIN_VARIANT (type1
) == float_type_node
12177 || TYPE_MAIN_VARIANT (type1
) == complex_float_type_node
)
12178 source_type
= type1
;
12179 else if (TYPE_MAIN_VARIANT (type2
) == float_type_node
12180 || TYPE_MAIN_VARIANT (type2
) == complex_float_type_node
)
12181 source_type
= type2
;
12184 warning_at (loc
, OPT_Wdouble_promotion
, gmsgid
, source_type
, result_type
);
12187 /* Possibly warn about unused parameters. */
12190 do_warn_unused_parameter (tree fn
)
12194 for (decl
= DECL_ARGUMENTS (fn
);
12195 decl
; decl
= DECL_CHAIN (decl
))
12196 if (!TREE_USED (decl
) && TREE_CODE (decl
) == PARM_DECL
12197 && DECL_NAME (decl
) && !DECL_ARTIFICIAL (decl
)
12198 && !TREE_NO_WARNING (decl
))
12199 warning_at (DECL_SOURCE_LOCATION (decl
), OPT_Wunused_parameter
,
12200 "unused parameter %qD", decl
);
12204 /* Setup a TYPE_DECL node as a typedef representation.
12206 X is a TYPE_DECL for a typedef statement. Create a brand new
12207 ..._TYPE node (which will be just a variant of the existing
12208 ..._TYPE node with identical properties) and then install X
12209 as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
12211 The whole point here is to end up with a situation where each
12212 and every ..._TYPE node the compiler creates will be uniquely
12213 associated with AT MOST one node representing a typedef name.
12214 This way, even though the compiler substitutes corresponding
12215 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
12216 early on, later parts of the compiler can always do the reverse
12217 translation and get back the corresponding typedef name. For
12220 typedef struct S MY_TYPE;
12223 Later parts of the compiler might only know that `object' was of
12224 type `struct S' if it were not for code just below. With this
12225 code however, later parts of the compiler see something like:
12227 struct S' == struct S
12228 typedef struct S' MY_TYPE;
12231 And they can then deduce (from the node for type struct S') that
12232 the original object declaration was:
12236 Being able to do this is important for proper support of protoize,
12237 and also for generating precise symbolic debugging information
12238 which takes full account of the programmer's (typedef) vocabulary.
12240 Obviously, we don't want to generate a duplicate ..._TYPE node if
12241 the TYPE_DECL node that we are now processing really represents a
12242 standard built-in type. */
12245 set_underlying_type (tree x
)
12247 if (x
== error_mark_node
)
12249 if (DECL_IS_BUILTIN (x
))
12251 if (TYPE_NAME (TREE_TYPE (x
)) == 0)
12252 TYPE_NAME (TREE_TYPE (x
)) = x
;
12254 else if (TREE_TYPE (x
) != error_mark_node
12255 && DECL_ORIGINAL_TYPE (x
) == NULL_TREE
)
12257 tree tt
= TREE_TYPE (x
);
12258 DECL_ORIGINAL_TYPE (x
) = tt
;
12259 tt
= build_variant_type_copy (tt
);
12260 TYPE_STUB_DECL (tt
) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x
));
12261 TYPE_NAME (tt
) = x
;
12262 TREE_USED (tt
) = TREE_USED (x
);
12263 TREE_TYPE (x
) = tt
;
12267 /* Record the types used by the current global variable declaration
12268 being parsed, so that we can decide later to emit their debug info.
12269 Those types are in types_used_by_cur_var_decl, and we are going to
12270 store them in the types_used_by_vars_hash hash table.
12271 DECL is the declaration of the global variable that has been parsed. */
12274 record_types_used_by_current_var_decl (tree decl
)
12276 gcc_assert (decl
&& DECL_P (decl
) && TREE_STATIC (decl
));
12278 while (types_used_by_cur_var_decl
&& !types_used_by_cur_var_decl
->is_empty ())
12280 tree type
= types_used_by_cur_var_decl
->pop ();
12281 types_used_by_var_decl_insert (type
, decl
);
12285 /* If DECL is a typedef that is declared in the current function,
12286 record it for the purpose of -Wunused-local-typedefs. */
12289 record_locally_defined_typedef (tree decl
)
12291 struct c_language_function
*l
;
12293 if (!warn_unused_local_typedefs
12295 /* if this is not a locally defined typedef then we are not
12297 || !is_typedef_decl (decl
)
12298 || !decl_function_context (decl
))
12301 l
= (struct c_language_function
*) cfun
->language
;
12302 vec_safe_push (l
->local_typedefs
, decl
);
12305 /* If T is a TYPE_DECL declared locally, mark it as used. */
12308 maybe_record_typedef_use (tree t
)
12310 if (!is_typedef_decl (t
))
12313 TREE_USED (t
) = true;
12316 /* Warn if there are some unused locally defined typedefs in the
12317 current function. */
12320 maybe_warn_unused_local_typedefs (void)
12324 /* The number of times we have emitted -Wunused-local-typedefs
12325 warnings. If this is different from errorcount, that means some
12326 unrelated errors have been issued. In which case, we'll avoid
12327 emitting "unused-local-typedefs" warnings. */
12328 static int unused_local_typedefs_warn_count
;
12329 struct c_language_function
*l
;
12334 if ((l
= (struct c_language_function
*) cfun
->language
) == NULL
)
12337 if (warn_unused_local_typedefs
12338 && errorcount
== unused_local_typedefs_warn_count
)
12340 FOR_EACH_VEC_SAFE_ELT (l
->local_typedefs
, i
, decl
)
12341 if (!TREE_USED (decl
))
12342 warning_at (DECL_SOURCE_LOCATION (decl
),
12343 OPT_Wunused_local_typedefs
,
12344 "typedef %qD locally defined but not used", decl
);
12345 unused_local_typedefs_warn_count
= errorcount
;
12348 vec_free (l
->local_typedefs
);
12351 /* Warn about boolean expression compared with an integer value different
12352 from true/false. Warns also e.g. about "(i1 == i2) == 2".
12353 LOC is the location of the comparison, CODE is its code, OP0 and OP1
12354 are the operands of the comparison. The caller must ensure that
12355 either operand is a boolean expression. */
12358 maybe_warn_bool_compare (location_t loc
, enum tree_code code
, tree op0
,
12361 if (TREE_CODE_CLASS (code
) != tcc_comparison
)
12364 tree cst
= (TREE_CODE (op0
) == INTEGER_CST
)
12365 ? op0
: (TREE_CODE (op1
) == INTEGER_CST
) ? op1
: NULL_TREE
;
12369 if (!integer_zerop (cst
) && !integer_onep (cst
))
12371 int sign
= (TREE_CODE (op0
) == INTEGER_CST
12372 ? tree_int_cst_sgn (cst
) : -tree_int_cst_sgn (cst
));
12373 if (code
== EQ_EXPR
12374 || ((code
== GT_EXPR
|| code
== GE_EXPR
) && sign
< 0)
12375 || ((code
== LT_EXPR
|| code
== LE_EXPR
) && sign
> 0))
12376 warning_at (loc
, OPT_Wbool_compare
, "comparison of constant %qE "
12377 "with boolean expression is always false", cst
);
12379 warning_at (loc
, OPT_Wbool_compare
, "comparison of constant %qE "
12380 "with boolean expression is always true", cst
);
12382 else if (integer_zerop (cst
) || integer_onep (cst
))
12384 /* If the non-constant operand isn't of a boolean type, we
12385 don't want to warn here. */
12386 tree noncst
= TREE_CODE (op0
) == INTEGER_CST
? op1
: op0
;
12387 /* Handle booleans promoted to integers. */
12388 if (CONVERT_EXPR_P (noncst
)
12389 && TREE_TYPE (noncst
) == integer_type_node
12390 && TREE_CODE (TREE_TYPE (TREE_OPERAND (noncst
, 0))) == BOOLEAN_TYPE
)
12392 else if (TREE_CODE (TREE_TYPE (noncst
)) != BOOLEAN_TYPE
12393 && !truth_value_p (TREE_CODE (noncst
)))
12395 /* Do some magic to get the right diagnostics. */
12396 bool flag
= TREE_CODE (op0
) == INTEGER_CST
;
12397 flag
= integer_zerop (cst
) ? flag
: !flag
;
12398 if ((code
== GE_EXPR
&& !flag
) || (code
== LE_EXPR
&& flag
))
12399 warning_at (loc
, OPT_Wbool_compare
, "comparison of constant %qE "
12400 "with boolean expression is always true", cst
);
12401 else if ((code
== LT_EXPR
&& !flag
) || (code
== GT_EXPR
&& flag
))
12402 warning_at (loc
, OPT_Wbool_compare
, "comparison of constant %qE "
12403 "with boolean expression is always false", cst
);
12407 /* Warn if signed left shift overflows. We don't warn
12408 about left-shifting 1 into the sign bit in C++14; cf.
12409 <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3367.html#1457>
12410 LOC is a location of the shift; OP0 and OP1 are the operands.
12411 Return true if an overflow is detected, false otherwise. */
12414 maybe_warn_shift_overflow (location_t loc
, tree op0
, tree op1
)
12416 if (TREE_CODE (op0
) != INTEGER_CST
12417 || TREE_CODE (op1
) != INTEGER_CST
)
12420 tree type0
= TREE_TYPE (op0
);
12421 unsigned int prec0
= TYPE_PRECISION (type0
);
12423 /* Left-hand operand must be signed. */
12424 if (TYPE_UNSIGNED (type0
))
12427 /* Handle the left-shifting 1 into the sign bit case. */
12428 if (integer_onep (op0
)
12429 && compare_tree_int (op1
, prec0
- 1) == 0)
12431 /* Never warn for C++14 onwards. */
12432 if (cxx_dialect
>= cxx14
)
12434 /* Otherwise only if -Wshift-overflow=2. But return
12435 true to signal an overflow for the sake of integer
12436 constant expressions. */
12437 if (warn_shift_overflow
< 2)
12441 unsigned int min_prec
= (wi::min_precision (op0
, SIGNED
)
12442 + TREE_INT_CST_LOW (op1
));
12443 bool overflowed
= min_prec
> prec0
;
12444 if (overflowed
&& c_inhibit_evaluation_warnings
== 0)
12445 warning_at (loc
, OPT_Wshift_overflow_
,
12446 "result of %qE requires %u bits to represent, "
12447 "but %qT only has %u bits",
12448 build2_loc (loc
, LSHIFT_EXPR
, type0
, op0
, op1
),
12449 min_prec
, type0
, prec0
);
12454 /* The C and C++ parsers both use vectors to hold function arguments.
12455 For efficiency, we keep a cache of unused vectors. This is the
12458 typedef vec
<tree
, va_gc
> *tree_gc_vec
;
12459 static GTY((deletable
)) vec
<tree_gc_vec
, va_gc
> *tree_vector_cache
;
12461 /* Return a new vector from the cache. If the cache is empty,
12462 allocate a new vector. These vectors are GC'ed, so it is OK if the
12463 pointer is not released.. */
12466 make_tree_vector (void)
12468 if (tree_vector_cache
&& !tree_vector_cache
->is_empty ())
12469 return tree_vector_cache
->pop ();
12472 /* Passing 0 to vec::alloc returns NULL, and our callers require
12473 that we always return a non-NULL value. The vector code uses
12474 4 when growing a NULL vector, so we do too. */
12475 vec
<tree
, va_gc
> *v
;
12481 /* Release a vector of trees back to the cache. */
12484 release_tree_vector (vec
<tree
, va_gc
> *vec
)
12489 vec_safe_push (tree_vector_cache
, vec
);
12493 /* Get a new tree vector holding a single tree. */
12496 make_tree_vector_single (tree t
)
12498 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
12499 ret
->quick_push (t
);
12503 /* Get a new tree vector of the TREE_VALUEs of a TREE_LIST chain. */
12506 make_tree_vector_from_list (tree list
)
12508 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
12509 for (; list
; list
= TREE_CHAIN (list
))
12510 vec_safe_push (ret
, TREE_VALUE (list
));
12514 /* Get a new tree vector which is a copy of an existing one. */
12517 make_tree_vector_copy (const vec
<tree
, va_gc
> *orig
)
12519 vec
<tree
, va_gc
> *ret
;
12523 ret
= make_tree_vector ();
12524 vec_safe_reserve (ret
, vec_safe_length (orig
));
12525 FOR_EACH_VEC_SAFE_ELT (orig
, ix
, t
)
12526 ret
->quick_push (t
);
12530 /* Return true if KEYWORD starts a type specifier. */
12533 keyword_begins_type_specifier (enum rid keyword
)
12537 case RID_AUTO_TYPE
:
12549 case RID_DFLOAT128
:
12565 if (keyword
>= RID_FIRST_INT_N
12566 && keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
12567 && int_n_enabled_p
[keyword
-RID_FIRST_INT_N
])
12573 /* Return true if KEYWORD names a type qualifier. */
12576 keyword_is_type_qualifier (enum rid keyword
)
12590 /* Return true if KEYWORD names a storage class specifier.
12592 RID_TYPEDEF is not included in this list despite `typedef' being
12593 listed in C99 6.7.1.1. 6.7.1.3 indicates that `typedef' is listed as
12594 such for syntactic convenience only. */
12597 keyword_is_storage_class_specifier (enum rid keyword
)
12613 /* Return true if KEYWORD names a function-specifier [dcl.fct.spec]. */
12616 keyword_is_function_specifier (enum rid keyword
)
12630 /* Return true if KEYWORD names a decl-specifier [dcl.spec] or a
12631 declaration-specifier (C99 6.7). */
12634 keyword_is_decl_specifier (enum rid keyword
)
12636 if (keyword_is_storage_class_specifier (keyword
)
12637 || keyword_is_type_qualifier (keyword
)
12638 || keyword_is_function_specifier (keyword
))
12645 case RID_CONSTEXPR
:
12652 /* Initialize language-specific-bits of tree_contains_struct. */
12655 c_common_init_ts (void)
12657 MARK_TS_TYPED (C_MAYBE_CONST_EXPR
);
12658 MARK_TS_TYPED (EXCESS_PRECISION_EXPR
);
12659 MARK_TS_TYPED (ARRAY_NOTATION_REF
);
12662 /* Build a user-defined numeric literal out of an integer constant type VALUE
12663 with identifier SUFFIX. */
12666 build_userdef_literal (tree suffix_id
, tree value
,
12667 enum overflow_type overflow
, tree num_string
)
12669 tree literal
= make_node (USERDEF_LITERAL
);
12670 USERDEF_LITERAL_SUFFIX_ID (literal
) = suffix_id
;
12671 USERDEF_LITERAL_VALUE (literal
) = value
;
12672 USERDEF_LITERAL_OVERFLOW (literal
) = overflow
;
12673 USERDEF_LITERAL_NUM_STRING (literal
) = num_string
;
12677 /* For vector[index], convert the vector to a
12678 pointer of the underlying type. Return true if the resulting
12679 ARRAY_REF should not be an lvalue. */
12682 convert_vector_to_pointer_for_subscript (location_t loc
,
12683 tree
*vecp
, tree index
)
12686 if (VECTOR_TYPE_P (TREE_TYPE (*vecp
)))
12688 tree type
= TREE_TYPE (*vecp
);
12691 ret
= !lvalue_p (*vecp
);
12692 if (TREE_CODE (index
) == INTEGER_CST
)
12693 if (!tree_fits_uhwi_p (index
)
12694 || tree_to_uhwi (index
) >= TYPE_VECTOR_SUBPARTS (type
))
12695 warning_at (loc
, OPT_Warray_bounds
, "index value is out of bound");
12699 tree tmp
= create_tmp_var_raw (type
);
12700 DECL_SOURCE_LOCATION (tmp
) = loc
;
12701 *vecp
= c_save_expr (*vecp
);
12702 if (TREE_CODE (*vecp
) == C_MAYBE_CONST_EXPR
)
12704 bool non_const
= C_MAYBE_CONST_EXPR_NON_CONST (*vecp
);
12705 *vecp
= C_MAYBE_CONST_EXPR_EXPR (*vecp
);
12707 = c_wrap_maybe_const (build4 (TARGET_EXPR
, type
, tmp
,
12708 *vecp
, NULL_TREE
, NULL_TREE
),
12712 *vecp
= build4 (TARGET_EXPR
, type
, tmp
, *vecp
,
12713 NULL_TREE
, NULL_TREE
);
12714 SET_EXPR_LOCATION (*vecp
, loc
);
12715 c_common_mark_addressable_vec (tmp
);
12718 c_common_mark_addressable_vec (*vecp
);
12719 type
= build_qualified_type (TREE_TYPE (type
), TYPE_QUALS (type
));
12720 type1
= build_pointer_type (TREE_TYPE (*vecp
));
12721 bool ref_all
= TYPE_REF_CAN_ALIAS_ALL (type1
);
12723 && !DECL_P (*vecp
))
12725 /* If the original vector isn't declared may_alias and it
12726 isn't a bare vector look if the subscripting would
12727 alias the vector we subscript, and if not, force ref-all. */
12728 alias_set_type vecset
= get_alias_set (*vecp
);
12729 alias_set_type sset
= get_alias_set (type
);
12730 if (!alias_sets_must_conflict_p (sset
, vecset
)
12731 && !alias_set_subset_of (sset
, vecset
))
12734 type
= build_pointer_type_for_mode (type
, ptr_mode
, ref_all
);
12735 *vecp
= build1 (ADDR_EXPR
, type1
, *vecp
);
12736 *vecp
= convert (type
, *vecp
);
12741 /* Determine which of the operands, if any, is a scalar that needs to be
12742 converted to a vector, for the range of operations. */
12744 scalar_to_vector (location_t loc
, enum tree_code code
, tree op0
, tree op1
,
12747 tree type0
= TREE_TYPE (op0
);
12748 tree type1
= TREE_TYPE (op1
);
12749 bool integer_only_op
= false;
12750 enum stv_conv ret
= stv_firstarg
;
12752 gcc_assert (VECTOR_TYPE_P (type0
) || VECTOR_TYPE_P (type1
));
12755 /* Most GENERIC binary expressions require homogeneous arguments.
12756 LSHIFT_EXPR and RSHIFT_EXPR are exceptions and accept a first
12757 argument that is a vector and a second one that is a scalar, so
12758 we never return stv_secondarg for them. */
12761 if (TREE_CODE (type0
) == INTEGER_TYPE
12762 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
12764 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
12767 error_at (loc
, "conversion of scalar %qT to vector %qT "
12768 "involves truncation", type0
, type1
);
12772 return stv_firstarg
;
12779 integer_only_op
= true;
12780 /* ... fall through ... */
12782 case VEC_COND_EXPR
:
12787 case TRUNC_DIV_EXPR
:
12788 case CEIL_DIV_EXPR
:
12789 case FLOOR_DIV_EXPR
:
12790 case ROUND_DIV_EXPR
:
12791 case EXACT_DIV_EXPR
:
12792 case TRUNC_MOD_EXPR
:
12793 case FLOOR_MOD_EXPR
:
12801 /* What about UNLT_EXPR? */
12802 if (VECTOR_TYPE_P (type0
))
12804 ret
= stv_secondarg
;
12805 std::swap (type0
, type1
);
12806 std::swap (op0
, op1
);
12809 if (TREE_CODE (type0
) == INTEGER_TYPE
12810 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
12812 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
12815 error_at (loc
, "conversion of scalar %qT to vector %qT "
12816 "involves truncation", type0
, type1
);
12821 else if (!integer_only_op
12822 /* Allow integer --> real conversion if safe. */
12823 && (TREE_CODE (type0
) == REAL_TYPE
12824 || TREE_CODE (type0
) == INTEGER_TYPE
)
12825 && SCALAR_FLOAT_TYPE_P (TREE_TYPE (type1
)))
12827 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
12830 error_at (loc
, "conversion of scalar %qT to vector %qT "
12831 "involves truncation", type0
, type1
);
12840 return stv_nothing
;
12843 /* Return true iff ALIGN is an integral constant that is a fundamental
12844 alignment, as defined by [basic.align] in the c++-11
12849 [A fundamental alignment is represented by an alignment less than or
12850 equal to the greatest alignment supported by the implementation
12851 in all contexts, which is equal to
12852 alignof(max_align_t)]. */
12855 cxx_fundamental_alignment_p (unsigned align
)
12857 return (align
<= MAX (TYPE_ALIGN (long_long_integer_type_node
),
12858 TYPE_ALIGN (long_double_type_node
)));
12861 /* Return true if T is a pointer to a zero-sized aggregate. */
12864 pointer_to_zero_sized_aggr_p (tree t
)
12866 if (!POINTER_TYPE_P (t
))
12869 return (TYPE_SIZE (t
) && integer_zerop (TYPE_SIZE (t
)));
12872 #include "gt-c-family-c-common.h"