1 /* Subroutines shared by all languages that are variants of C.
2 Copyright (C) 1992-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #define GCC_C_COMMON_C
24 #include "coretypes.h"
30 #include "fold-const.h"
31 #include "stor-layout.h"
33 #include "stringpool.h"
36 #include "trans-mem.h"
44 #include "common/common-target.h"
45 #include "langhooks.h"
46 #include "tree-inline.h"
48 #include "diagnostic.h"
49 #include "tree-iterator.h"
54 #include "plugin-api.h"
58 #include "hard-reg-set.h"
63 #include "target-def.h"
65 #include "wide-int-print.h"
66 #include "gimple-expr.h"
68 cpp_reader
*parse_in
; /* Declared in c-pragma.h. */
70 /* Mode used to build pointers (VOIDmode means ptr_mode). */
72 machine_mode c_default_pointer_mode
= VOIDmode
;
74 /* The following symbols are subsumed in the c_global_trees array, and
75 listed here individually for documentation purposes.
77 INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
79 tree short_integer_type_node;
80 tree long_integer_type_node;
81 tree long_long_integer_type_node;
83 tree short_unsigned_type_node;
84 tree long_unsigned_type_node;
85 tree long_long_unsigned_type_node;
87 tree truthvalue_type_node;
88 tree truthvalue_false_node;
89 tree truthvalue_true_node;
91 tree ptrdiff_type_node;
93 tree unsigned_char_type_node;
94 tree signed_char_type_node;
97 tree char16_type_node;
98 tree char32_type_node;
100 tree float_type_node;
101 tree double_type_node;
102 tree long_double_type_node;
104 tree complex_integer_type_node;
105 tree complex_float_type_node;
106 tree complex_double_type_node;
107 tree complex_long_double_type_node;
109 tree dfloat32_type_node;
110 tree dfloat64_type_node;
111 tree_dfloat128_type_node;
113 tree intQI_type_node;
114 tree intHI_type_node;
115 tree intSI_type_node;
116 tree intDI_type_node;
117 tree intTI_type_node;
119 tree unsigned_intQI_type_node;
120 tree unsigned_intHI_type_node;
121 tree unsigned_intSI_type_node;
122 tree unsigned_intDI_type_node;
123 tree unsigned_intTI_type_node;
125 tree widest_integer_literal_type_node;
126 tree widest_unsigned_literal_type_node;
128 Nodes for types `void *' and `const void *'.
130 tree ptr_type_node, const_ptr_type_node;
132 Nodes for types `char *' and `const char *'.
134 tree string_type_node, const_string_type_node;
136 Type `char[SOMENUMBER]'.
137 Used when an array of char is needed and the size is irrelevant.
139 tree char_array_type_node;
141 Type `wchar_t[SOMENUMBER]' or something like it.
142 Used when a wide string literal is created.
144 tree wchar_array_type_node;
146 Type `char16_t[SOMENUMBER]' or something like it.
147 Used when a UTF-16 string literal is created.
149 tree char16_array_type_node;
151 Type `char32_t[SOMENUMBER]' or something like it.
152 Used when a UTF-32 string literal is created.
154 tree char32_array_type_node;
156 Type `int ()' -- used for implicit declaration of functions.
158 tree default_function_type;
160 A VOID_TYPE node, packaged in a TREE_LIST.
164 The lazily created VAR_DECLs for __FUNCTION__, __PRETTY_FUNCTION__,
165 and __func__. (C doesn't generate __FUNCTION__ and__PRETTY_FUNCTION__
166 VAR_DECLS, but C++ does.)
168 tree function_name_decl_node;
169 tree pretty_function_name_decl_node;
170 tree c99_function_name_decl_node;
172 Stack of nested function name VAR_DECLs.
174 tree saved_function_name_decls;
178 tree c_global_trees
[CTI_MAX
];
180 /* Switches common to the C front ends. */
182 /* Nonzero means don't output line number information. */
184 char flag_no_line_commands
;
186 /* Nonzero causes -E output not to be done, but directives such as
187 #define that have side effects are still obeyed. */
191 /* Nonzero means dump macros in some fashion. */
193 char flag_dump_macros
;
195 /* Nonzero means pass #include lines through to the output. */
197 char flag_dump_includes
;
199 /* Nonzero means process PCH files while preprocessing. */
201 bool flag_pch_preprocess
;
203 /* The file name to which we should write a precompiled header, or
204 NULL if no header will be written in this compile. */
206 const char *pch_file
;
208 /* Nonzero if an ISO standard was selected. It rejects macros in the
212 /* C/ObjC language option variables. */
215 /* Nonzero means allow type mismatches in conditional expressions;
216 just make their values `void'. */
218 int flag_cond_mismatch
;
220 /* Nonzero means enable C89 Amendment 1 features. */
224 /* Nonzero means use the ISO C99 (or C11) dialect of C. */
228 /* Nonzero means use the ISO C11 dialect of C. */
232 /* Nonzero means that we have builtin functions, and main is an int. */
237 /* ObjC language option variables. */
240 /* Tells the compiler that this is a special run. Do not perform any
241 compiling, instead we are to test some platform dependent features
242 and output a C header file with appropriate definitions. */
244 int print_struct_values
;
246 /* Tells the compiler what is the constant string class for ObjC. */
248 const char *constant_string_class_name
;
251 /* C++ language option variables. */
254 /* Nonzero means generate separate instantiation control files and
255 juggle them at link time. */
257 int flag_use_repository
;
259 /* The C++ dialect being used. C++98 is the default. */
261 enum cxx_dialect cxx_dialect
= cxx98
;
263 /* Maximum template instantiation depth. This limit exists to limit the
264 time it takes to notice excessively recursive template instantiations.
266 The default is lower than the 1024 recommended by the C++0x standard
267 because G++ runs out of stack before 1024 with highly recursive template
268 argument deduction substitution (g++.dg/cpp0x/enum11.C). */
270 int max_tinst_depth
= 900;
272 /* The elements of `ridpointers' are identifier nodes for the reserved
273 type names and storage classes. It is indexed by a RID_... value. */
276 tree (*make_fname_decl
) (location_t
, tree
, int);
278 /* Nonzero means don't warn about problems that occur when the code is
280 int c_inhibit_evaluation_warnings
;
282 /* Whether we are building a boolean conversion inside
283 convert_for_assignment, or some other late binary operation. If
284 build_binary_op is called for C (from code shared by C and C++) in
285 this case, then the operands have already been folded and the
286 result will not be folded again, so C_MAYBE_CONST_EXPR should not
288 bool in_late_binary_op
;
290 /* Whether lexing has been completed, so subsequent preprocessor
291 errors should use the compiler's input_location. */
292 bool done_lexing
= false;
294 /* Information about how a function name is generated. */
297 tree
*const decl
; /* pointer to the VAR_DECL. */
298 const unsigned rid
; /* RID number for the identifier. */
299 const int pretty
; /* How pretty is it? */
302 /* The three ways of getting then name of the current function. */
304 const struct fname_var_t fname_vars
[] =
306 /* C99 compliant __func__, must be first. */
307 {&c99_function_name_decl_node
, RID_C99_FUNCTION_NAME
, 0},
308 /* GCC __FUNCTION__ compliant. */
309 {&function_name_decl_node
, RID_FUNCTION_NAME
, 0},
310 /* GCC __PRETTY_FUNCTION__ compliant. */
311 {&pretty_function_name_decl_node
, RID_PRETTY_FUNCTION_NAME
, 1},
315 /* Global visibility options. */
316 struct visibility_flags visibility_options
;
318 static tree
c_fully_fold_internal (tree expr
, bool, bool *, bool *);
319 static tree
check_case_value (location_t
, tree
);
320 static bool check_case_bounds (location_t
, tree
, tree
, tree
*, tree
*);
322 static tree
handle_packed_attribute (tree
*, tree
, tree
, int, bool *);
323 static tree
handle_nocommon_attribute (tree
*, tree
, tree
, int, bool *);
324 static tree
handle_common_attribute (tree
*, tree
, tree
, int, bool *);
325 static tree
handle_noreturn_attribute (tree
*, tree
, tree
, int, bool *);
326 static tree
handle_hot_attribute (tree
*, tree
, tree
, int, bool *);
327 static tree
handle_cold_attribute (tree
*, tree
, tree
, int, bool *);
328 static tree
handle_no_sanitize_address_attribute (tree
*, tree
, tree
,
330 static tree
handle_no_address_safety_analysis_attribute (tree
*, tree
, tree
,
332 static tree
handle_no_sanitize_undefined_attribute (tree
*, tree
, tree
, int,
334 static tree
handle_stack_protect_attribute (tree
*, tree
, tree
, int, bool *);
335 static tree
handle_noinline_attribute (tree
*, tree
, tree
, int, bool *);
336 static tree
handle_noclone_attribute (tree
*, tree
, tree
, int, bool *);
337 static tree
handle_noicf_attribute (tree
*, tree
, tree
, int, bool *);
338 static tree
handle_leaf_attribute (tree
*, tree
, tree
, int, bool *);
339 static tree
handle_always_inline_attribute (tree
*, tree
, tree
, int,
341 static tree
handle_gnu_inline_attribute (tree
*, tree
, tree
, int, bool *);
342 static tree
handle_artificial_attribute (tree
*, tree
, tree
, int, bool *);
343 static tree
handle_flatten_attribute (tree
*, tree
, tree
, int, bool *);
344 static tree
handle_error_attribute (tree
*, tree
, tree
, int, bool *);
345 static tree
handle_used_attribute (tree
*, tree
, tree
, int, bool *);
346 static tree
handle_unused_attribute (tree
*, tree
, tree
, int, bool *);
347 static tree
handle_externally_visible_attribute (tree
*, tree
, tree
, int,
349 static tree
handle_no_reorder_attribute (tree
*, tree
, tree
, int,
351 static tree
handle_const_attribute (tree
*, tree
, tree
, int, bool *);
352 static tree
handle_transparent_union_attribute (tree
*, tree
, tree
,
354 static tree
handle_constructor_attribute (tree
*, tree
, tree
, int, bool *);
355 static tree
handle_destructor_attribute (tree
*, tree
, tree
, int, bool *);
356 static tree
handle_mode_attribute (tree
*, tree
, tree
, int, bool *);
357 static tree
handle_section_attribute (tree
*, tree
, tree
, int, bool *);
358 static tree
handle_aligned_attribute (tree
*, tree
, tree
, int, bool *);
359 static tree
handle_weak_attribute (tree
*, tree
, tree
, int, bool *) ;
360 static tree
handle_alias_ifunc_attribute (bool, tree
*, tree
, tree
, bool *);
361 static tree
handle_ifunc_attribute (tree
*, tree
, tree
, int, bool *);
362 static tree
handle_alias_attribute (tree
*, tree
, tree
, int, bool *);
363 static tree
handle_weakref_attribute (tree
*, tree
, tree
, int, bool *) ;
364 static tree
handle_visibility_attribute (tree
*, tree
, tree
, int,
366 static tree
handle_tls_model_attribute (tree
*, tree
, tree
, int,
368 static tree
handle_no_instrument_function_attribute (tree
*, tree
,
370 static tree
handle_malloc_attribute (tree
*, tree
, tree
, int, bool *);
371 static tree
handle_returns_twice_attribute (tree
*, tree
, tree
, int, bool *);
372 static tree
handle_no_limit_stack_attribute (tree
*, tree
, tree
, int,
374 static tree
handle_pure_attribute (tree
*, tree
, tree
, int, bool *);
375 static tree
handle_tm_attribute (tree
*, tree
, tree
, int, bool *);
376 static tree
handle_tm_wrap_attribute (tree
*, tree
, tree
, int, bool *);
377 static tree
handle_novops_attribute (tree
*, tree
, tree
, int, bool *);
378 static tree
handle_deprecated_attribute (tree
*, tree
, tree
, int,
380 static tree
handle_vector_size_attribute (tree
*, tree
, tree
, int,
382 static tree
handle_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
383 static tree
handle_nothrow_attribute (tree
*, tree
, tree
, int, bool *);
384 static tree
handle_cleanup_attribute (tree
*, tree
, tree
, int, bool *);
385 static tree
handle_warn_unused_result_attribute (tree
*, tree
, tree
, int,
387 static tree
handle_sentinel_attribute (tree
*, tree
, tree
, int, bool *);
388 static tree
handle_type_generic_attribute (tree
*, tree
, tree
, int, bool *);
389 static tree
handle_alloc_size_attribute (tree
*, tree
, tree
, int, bool *);
390 static tree
handle_alloc_align_attribute (tree
*, tree
, tree
, int, bool *);
391 static tree
handle_assume_aligned_attribute (tree
*, tree
, tree
, int, bool *);
392 static tree
handle_target_attribute (tree
*, tree
, tree
, int, bool *);
393 static tree
handle_optimize_attribute (tree
*, tree
, tree
, int, bool *);
394 static tree
ignore_attribute (tree
*, tree
, tree
, int, bool *);
395 static tree
handle_no_split_stack_attribute (tree
*, tree
, tree
, int, bool *);
396 static tree
handle_fnspec_attribute (tree
*, tree
, tree
, int, bool *);
397 static tree
handle_warn_unused_attribute (tree
*, tree
, tree
, int, bool *);
398 static tree
handle_returns_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
399 static tree
handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int,
401 static tree
handle_omp_declare_target_attribute (tree
*, tree
, tree
, int,
403 static tree
handle_designated_init_attribute (tree
*, tree
, tree
, int, bool *);
404 static tree
handle_bnd_variable_size_attribute (tree
*, tree
, tree
, int, bool *);
405 static tree
handle_bnd_legacy (tree
*, tree
, tree
, int, bool *);
406 static tree
handle_bnd_instrument (tree
*, tree
, tree
, int, bool *);
408 static void check_function_nonnull (tree
, int, tree
*);
409 static void check_nonnull_arg (void *, tree
, unsigned HOST_WIDE_INT
);
410 static bool nonnull_check_p (tree
, unsigned HOST_WIDE_INT
);
411 static bool get_nonnull_operand (tree
, unsigned HOST_WIDE_INT
*);
412 static int resort_field_decl_cmp (const void *, const void *);
414 /* Reserved words. The third field is a mask: keywords are disabled
415 if they match the mask.
418 C --std=c89: D_C99 | D_CXXONLY | D_OBJC | D_CXX_OBJC
419 C --std=c99: D_CXXONLY | D_OBJC
420 ObjC is like C except that D_OBJC and D_CXX_OBJC are not set
421 C++ --std=c98: D_CONLY | D_CXXOX | D_OBJC
422 C++ --std=c0x: D_CONLY | D_OBJC
423 ObjC++ is like C++ except that D_OBJC is not set
425 If -fno-asm is used, D_ASM is added to the mask. If
426 -fno-gnu-keywords is used, D_EXT is added. If -fno-asm and C in
427 C89 mode, D_EXT89 is added for both -fno-asm and -fno-gnu-keywords.
428 In C with -Wc++-compat, we warn if D_CXXWARN is set.
430 Note the complication of the D_CXX_OBJC keywords. These are
431 reserved words such as 'class'. In C++, 'class' is a reserved
432 word. In Objective-C++ it is too. In Objective-C, it is a
433 reserved word too, but only if it follows an '@' sign.
435 const struct c_common_resword c_common_reswords
[] =
437 { "_Alignas", RID_ALIGNAS
, D_CONLY
},
438 { "_Alignof", RID_ALIGNOF
, D_CONLY
},
439 { "_Atomic", RID_ATOMIC
, D_CONLY
},
440 { "_Bool", RID_BOOL
, D_CONLY
},
441 { "_Complex", RID_COMPLEX
, 0 },
442 { "_Cilk_spawn", RID_CILK_SPAWN
, 0 },
443 { "_Cilk_sync", RID_CILK_SYNC
, 0 },
444 { "_Cilk_for", RID_CILK_FOR
, 0 },
445 { "_Imaginary", RID_IMAGINARY
, D_CONLY
},
446 { "_Decimal32", RID_DFLOAT32
, D_CONLY
| D_EXT
},
447 { "_Decimal64", RID_DFLOAT64
, D_CONLY
| D_EXT
},
448 { "_Decimal128", RID_DFLOAT128
, D_CONLY
| D_EXT
},
449 { "_Fract", RID_FRACT
, D_CONLY
| D_EXT
},
450 { "_Accum", RID_ACCUM
, D_CONLY
| D_EXT
},
451 { "_Sat", RID_SAT
, D_CONLY
| D_EXT
},
452 { "_Static_assert", RID_STATIC_ASSERT
, D_CONLY
},
453 { "_Noreturn", RID_NORETURN
, D_CONLY
},
454 { "_Generic", RID_GENERIC
, D_CONLY
},
455 { "_Thread_local", RID_THREAD
, D_CONLY
},
456 { "__FUNCTION__", RID_FUNCTION_NAME
, 0 },
457 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME
, 0 },
458 { "__alignof", RID_ALIGNOF
, 0 },
459 { "__alignof__", RID_ALIGNOF
, 0 },
460 { "__asm", RID_ASM
, 0 },
461 { "__asm__", RID_ASM
, 0 },
462 { "__attribute", RID_ATTRIBUTE
, 0 },
463 { "__attribute__", RID_ATTRIBUTE
, 0 },
464 { "__auto_type", RID_AUTO_TYPE
, D_CONLY
},
465 { "__bases", RID_BASES
, D_CXXONLY
},
466 { "__builtin_call_with_static_chain",
467 RID_BUILTIN_CALL_WITH_STATIC_CHAIN
, D_CONLY
},
468 { "__builtin_choose_expr", RID_CHOOSE_EXPR
, D_CONLY
},
469 { "__builtin_complex", RID_BUILTIN_COMPLEX
, D_CONLY
},
470 { "__builtin_shuffle", RID_BUILTIN_SHUFFLE
, 0 },
471 { "__builtin_offsetof", RID_OFFSETOF
, 0 },
472 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P
, D_CONLY
},
473 { "__builtin_va_arg", RID_VA_ARG
, 0 },
474 { "__complex", RID_COMPLEX
, 0 },
475 { "__complex__", RID_COMPLEX
, 0 },
476 { "__const", RID_CONST
, 0 },
477 { "__const__", RID_CONST
, 0 },
478 { "__decltype", RID_DECLTYPE
, D_CXXONLY
},
479 { "__direct_bases", RID_DIRECT_BASES
, D_CXXONLY
},
480 { "__extension__", RID_EXTENSION
, 0 },
481 { "__func__", RID_C99_FUNCTION_NAME
, 0 },
482 { "__has_nothrow_assign", RID_HAS_NOTHROW_ASSIGN
, D_CXXONLY
},
483 { "__has_nothrow_constructor", RID_HAS_NOTHROW_CONSTRUCTOR
, D_CXXONLY
},
484 { "__has_nothrow_copy", RID_HAS_NOTHROW_COPY
, D_CXXONLY
},
485 { "__has_trivial_assign", RID_HAS_TRIVIAL_ASSIGN
, D_CXXONLY
},
486 { "__has_trivial_constructor", RID_HAS_TRIVIAL_CONSTRUCTOR
, D_CXXONLY
},
487 { "__has_trivial_copy", RID_HAS_TRIVIAL_COPY
, D_CXXONLY
},
488 { "__has_trivial_destructor", RID_HAS_TRIVIAL_DESTRUCTOR
, D_CXXONLY
},
489 { "__has_virtual_destructor", RID_HAS_VIRTUAL_DESTRUCTOR
, D_CXXONLY
},
490 { "__imag", RID_IMAGPART
, 0 },
491 { "__imag__", RID_IMAGPART
, 0 },
492 { "__inline", RID_INLINE
, 0 },
493 { "__inline__", RID_INLINE
, 0 },
494 { "__is_abstract", RID_IS_ABSTRACT
, D_CXXONLY
},
495 { "__is_base_of", RID_IS_BASE_OF
, D_CXXONLY
},
496 { "__is_class", RID_IS_CLASS
, D_CXXONLY
},
497 { "__is_empty", RID_IS_EMPTY
, D_CXXONLY
},
498 { "__is_enum", RID_IS_ENUM
, D_CXXONLY
},
499 { "__is_final", RID_IS_FINAL
, D_CXXONLY
},
500 { "__is_literal_type", RID_IS_LITERAL_TYPE
, D_CXXONLY
},
501 { "__is_pod", RID_IS_POD
, D_CXXONLY
},
502 { "__is_polymorphic", RID_IS_POLYMORPHIC
, D_CXXONLY
},
503 { "__is_standard_layout", RID_IS_STD_LAYOUT
, D_CXXONLY
},
504 { "__is_trivial", RID_IS_TRIVIAL
, D_CXXONLY
},
505 { "__is_trivially_assignable", RID_IS_TRIVIALLY_ASSIGNABLE
, D_CXXONLY
},
506 { "__is_trivially_constructible", RID_IS_TRIVIALLY_CONSTRUCTIBLE
, D_CXXONLY
},
507 { "__is_trivially_copyable", RID_IS_TRIVIALLY_COPYABLE
, D_CXXONLY
},
508 { "__is_union", RID_IS_UNION
, D_CXXONLY
},
509 { "__label__", RID_LABEL
, 0 },
510 { "__null", RID_NULL
, 0 },
511 { "__real", RID_REALPART
, 0 },
512 { "__real__", RID_REALPART
, 0 },
513 { "__restrict", RID_RESTRICT
, 0 },
514 { "__restrict__", RID_RESTRICT
, 0 },
515 { "__signed", RID_SIGNED
, 0 },
516 { "__signed__", RID_SIGNED
, 0 },
517 { "__thread", RID_THREAD
, 0 },
518 { "__transaction_atomic", RID_TRANSACTION_ATOMIC
, 0 },
519 { "__transaction_relaxed", RID_TRANSACTION_RELAXED
, 0 },
520 { "__transaction_cancel", RID_TRANSACTION_CANCEL
, 0 },
521 { "__typeof", RID_TYPEOF
, 0 },
522 { "__typeof__", RID_TYPEOF
, 0 },
523 { "__underlying_type", RID_UNDERLYING_TYPE
, D_CXXONLY
},
524 { "__volatile", RID_VOLATILE
, 0 },
525 { "__volatile__", RID_VOLATILE
, 0 },
526 { "alignas", RID_ALIGNAS
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
527 { "alignof", RID_ALIGNOF
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
528 { "asm", RID_ASM
, D_ASM
},
529 { "auto", RID_AUTO
, 0 },
530 { "bool", RID_BOOL
, D_CXXONLY
| D_CXXWARN
},
531 { "break", RID_BREAK
, 0 },
532 { "case", RID_CASE
, 0 },
533 { "catch", RID_CATCH
, D_CXX_OBJC
| D_CXXWARN
},
534 { "char", RID_CHAR
, 0 },
535 { "char16_t", RID_CHAR16
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
536 { "char32_t", RID_CHAR32
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
537 { "class", RID_CLASS
, D_CXX_OBJC
| D_CXXWARN
},
538 { "const", RID_CONST
, 0 },
539 { "constexpr", RID_CONSTEXPR
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
540 { "const_cast", RID_CONSTCAST
, D_CXXONLY
| D_CXXWARN
},
541 { "continue", RID_CONTINUE
, 0 },
542 { "decltype", RID_DECLTYPE
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
543 { "default", RID_DEFAULT
, 0 },
544 { "delete", RID_DELETE
, D_CXXONLY
| D_CXXWARN
},
546 { "double", RID_DOUBLE
, 0 },
547 { "dynamic_cast", RID_DYNCAST
, D_CXXONLY
| D_CXXWARN
},
548 { "else", RID_ELSE
, 0 },
549 { "enum", RID_ENUM
, 0 },
550 { "explicit", RID_EXPLICIT
, D_CXXONLY
| D_CXXWARN
},
551 { "export", RID_EXPORT
, D_CXXONLY
| D_CXXWARN
},
552 { "extern", RID_EXTERN
, 0 },
553 { "false", RID_FALSE
, D_CXXONLY
| D_CXXWARN
},
554 { "float", RID_FLOAT
, 0 },
555 { "for", RID_FOR
, 0 },
556 { "friend", RID_FRIEND
, D_CXXONLY
| D_CXXWARN
},
557 { "goto", RID_GOTO
, 0 },
559 { "inline", RID_INLINE
, D_EXT89
},
560 { "int", RID_INT
, 0 },
561 { "long", RID_LONG
, 0 },
562 { "mutable", RID_MUTABLE
, D_CXXONLY
| D_CXXWARN
},
563 { "namespace", RID_NAMESPACE
, D_CXXONLY
| D_CXXWARN
},
564 { "new", RID_NEW
, D_CXXONLY
| D_CXXWARN
},
565 { "noexcept", RID_NOEXCEPT
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
566 { "nullptr", RID_NULLPTR
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
567 { "operator", RID_OPERATOR
, D_CXXONLY
| D_CXXWARN
},
568 { "private", RID_PRIVATE
, D_CXX_OBJC
| D_CXXWARN
},
569 { "protected", RID_PROTECTED
, D_CXX_OBJC
| D_CXXWARN
},
570 { "public", RID_PUBLIC
, D_CXX_OBJC
| D_CXXWARN
},
571 { "register", RID_REGISTER
, 0 },
572 { "reinterpret_cast", RID_REINTCAST
, D_CXXONLY
| D_CXXWARN
},
573 { "restrict", RID_RESTRICT
, D_CONLY
| D_C99
},
574 { "return", RID_RETURN
, 0 },
575 { "short", RID_SHORT
, 0 },
576 { "signed", RID_SIGNED
, 0 },
577 { "sizeof", RID_SIZEOF
, 0 },
578 { "static", RID_STATIC
, 0 },
579 { "static_assert", RID_STATIC_ASSERT
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
580 { "static_cast", RID_STATCAST
, D_CXXONLY
| D_CXXWARN
},
581 { "struct", RID_STRUCT
, 0 },
582 { "switch", RID_SWITCH
, 0 },
583 { "template", RID_TEMPLATE
, D_CXXONLY
| D_CXXWARN
},
584 { "this", RID_THIS
, D_CXXONLY
| D_CXXWARN
},
585 { "thread_local", RID_THREAD
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
586 { "throw", RID_THROW
, D_CXX_OBJC
| D_CXXWARN
},
587 { "true", RID_TRUE
, D_CXXONLY
| D_CXXWARN
},
588 { "try", RID_TRY
, D_CXX_OBJC
| D_CXXWARN
},
589 { "typedef", RID_TYPEDEF
, 0 },
590 { "typename", RID_TYPENAME
, D_CXXONLY
| D_CXXWARN
},
591 { "typeid", RID_TYPEID
, D_CXXONLY
| D_CXXWARN
},
592 { "typeof", RID_TYPEOF
, D_ASM
| D_EXT
},
593 { "union", RID_UNION
, 0 },
594 { "unsigned", RID_UNSIGNED
, 0 },
595 { "using", RID_USING
, D_CXXONLY
| D_CXXWARN
},
596 { "virtual", RID_VIRTUAL
, D_CXXONLY
| D_CXXWARN
},
597 { "void", RID_VOID
, 0 },
598 { "volatile", RID_VOLATILE
, 0 },
599 { "wchar_t", RID_WCHAR
, D_CXXONLY
},
600 { "while", RID_WHILE
, 0 },
601 /* These Objective-C keywords are recognized only immediately after
603 { "compatibility_alias", RID_AT_ALIAS
, D_OBJC
},
604 { "defs", RID_AT_DEFS
, D_OBJC
},
605 { "encode", RID_AT_ENCODE
, D_OBJC
},
606 { "end", RID_AT_END
, D_OBJC
},
607 { "implementation", RID_AT_IMPLEMENTATION
, D_OBJC
},
608 { "interface", RID_AT_INTERFACE
, D_OBJC
},
609 { "protocol", RID_AT_PROTOCOL
, D_OBJC
},
610 { "selector", RID_AT_SELECTOR
, D_OBJC
},
611 { "finally", RID_AT_FINALLY
, D_OBJC
},
612 { "synchronized", RID_AT_SYNCHRONIZED
, D_OBJC
},
613 { "optional", RID_AT_OPTIONAL
, D_OBJC
},
614 { "required", RID_AT_REQUIRED
, D_OBJC
},
615 { "property", RID_AT_PROPERTY
, D_OBJC
},
616 { "package", RID_AT_PACKAGE
, D_OBJC
},
617 { "synthesize", RID_AT_SYNTHESIZE
, D_OBJC
},
618 { "dynamic", RID_AT_DYNAMIC
, D_OBJC
},
619 /* These are recognized only in protocol-qualifier context
621 { "bycopy", RID_BYCOPY
, D_OBJC
},
622 { "byref", RID_BYREF
, D_OBJC
},
623 { "in", RID_IN
, D_OBJC
},
624 { "inout", RID_INOUT
, D_OBJC
},
625 { "oneway", RID_ONEWAY
, D_OBJC
},
626 { "out", RID_OUT
, D_OBJC
},
627 /* These are recognized inside a property attribute list */
628 { "assign", RID_ASSIGN
, D_OBJC
},
629 { "copy", RID_COPY
, D_OBJC
},
630 { "getter", RID_GETTER
, D_OBJC
},
631 { "nonatomic", RID_NONATOMIC
, D_OBJC
},
632 { "readonly", RID_READONLY
, D_OBJC
},
633 { "readwrite", RID_READWRITE
, D_OBJC
},
634 { "retain", RID_RETAIN
, D_OBJC
},
635 { "setter", RID_SETTER
, D_OBJC
},
638 const unsigned int num_c_common_reswords
=
639 sizeof c_common_reswords
/ sizeof (struct c_common_resword
);
641 /* Table of machine-independent attributes common to all C-like languages.
643 All attributes referencing arguments should be additionally processed
644 in chkp_copy_function_type_adding_bounds for correct instrumentation
645 by Pointer Bounds Checker.
646 Current list of processed common attributes: nonnull. */
647 const struct attribute_spec c_common_attribute_table
[] =
649 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
650 affects_type_identity } */
651 { "packed", 0, 0, false, false, false,
652 handle_packed_attribute
, false},
653 { "nocommon", 0, 0, true, false, false,
654 handle_nocommon_attribute
, false},
655 { "common", 0, 0, true, false, false,
656 handle_common_attribute
, false },
657 /* FIXME: logically, noreturn attributes should be listed as
658 "false, true, true" and apply to function types. But implementing this
659 would require all the places in the compiler that use TREE_THIS_VOLATILE
660 on a decl to identify non-returning functions to be located and fixed
661 to check the function type instead. */
662 { "noreturn", 0, 0, true, false, false,
663 handle_noreturn_attribute
, false },
664 { "volatile", 0, 0, true, false, false,
665 handle_noreturn_attribute
, false },
666 { "stack_protect", 0, 0, true, false, false,
667 handle_stack_protect_attribute
, false },
668 { "noinline", 0, 0, true, false, false,
669 handle_noinline_attribute
, false },
670 { "noclone", 0, 0, true, false, false,
671 handle_noclone_attribute
, false },
672 { "no_icf", 0, 0, true, false, false,
673 handle_noicf_attribute
, false },
674 { "leaf", 0, 0, true, false, false,
675 handle_leaf_attribute
, false },
676 { "always_inline", 0, 0, true, false, false,
677 handle_always_inline_attribute
, false },
678 { "gnu_inline", 0, 0, true, false, false,
679 handle_gnu_inline_attribute
, false },
680 { "artificial", 0, 0, true, false, false,
681 handle_artificial_attribute
, false },
682 { "flatten", 0, 0, true, false, false,
683 handle_flatten_attribute
, false },
684 { "used", 0, 0, true, false, false,
685 handle_used_attribute
, false },
686 { "unused", 0, 0, false, false, false,
687 handle_unused_attribute
, false },
688 { "externally_visible", 0, 0, true, false, false,
689 handle_externally_visible_attribute
, false },
690 { "no_reorder", 0, 0, true, false, false,
691 handle_no_reorder_attribute
, false },
692 /* The same comments as for noreturn attributes apply to const ones. */
693 { "const", 0, 0, true, false, false,
694 handle_const_attribute
, false },
695 { "transparent_union", 0, 0, false, false, false,
696 handle_transparent_union_attribute
, false },
697 { "constructor", 0, 1, true, false, false,
698 handle_constructor_attribute
, false },
699 { "destructor", 0, 1, true, false, false,
700 handle_destructor_attribute
, false },
701 { "mode", 1, 1, false, true, false,
702 handle_mode_attribute
, false },
703 { "section", 1, 1, true, false, false,
704 handle_section_attribute
, false },
705 { "aligned", 0, 1, false, false, false,
706 handle_aligned_attribute
, false },
707 { "weak", 0, 0, true, false, false,
708 handle_weak_attribute
, false },
709 { "ifunc", 1, 1, true, false, false,
710 handle_ifunc_attribute
, false },
711 { "alias", 1, 1, true, false, false,
712 handle_alias_attribute
, false },
713 { "weakref", 0, 1, true, false, false,
714 handle_weakref_attribute
, false },
715 { "no_instrument_function", 0, 0, true, false, false,
716 handle_no_instrument_function_attribute
,
718 { "malloc", 0, 0, true, false, false,
719 handle_malloc_attribute
, false },
720 { "returns_twice", 0, 0, true, false, false,
721 handle_returns_twice_attribute
, false },
722 { "no_stack_limit", 0, 0, true, false, false,
723 handle_no_limit_stack_attribute
, false },
724 { "pure", 0, 0, true, false, false,
725 handle_pure_attribute
, false },
726 { "transaction_callable", 0, 0, false, true, false,
727 handle_tm_attribute
, false },
728 { "transaction_unsafe", 0, 0, false, true, false,
729 handle_tm_attribute
, false },
730 { "transaction_safe", 0, 0, false, true, false,
731 handle_tm_attribute
, false },
732 { "transaction_may_cancel_outer", 0, 0, false, true, false,
733 handle_tm_attribute
, false },
734 /* ??? These two attributes didn't make the transition from the
735 Intel language document to the multi-vendor language document. */
736 { "transaction_pure", 0, 0, false, true, false,
737 handle_tm_attribute
, false },
738 { "transaction_wrap", 1, 1, true, false, false,
739 handle_tm_wrap_attribute
, false },
740 /* For internal use (marking of builtins) only. The name contains space
741 to prevent its usage in source code. */
742 { "no vops", 0, 0, true, false, false,
743 handle_novops_attribute
, false },
744 { "deprecated", 0, 1, false, false, false,
745 handle_deprecated_attribute
, false },
746 { "vector_size", 1, 1, false, true, false,
747 handle_vector_size_attribute
, false },
748 { "visibility", 1, 1, false, false, false,
749 handle_visibility_attribute
, false },
750 { "tls_model", 1, 1, true, false, false,
751 handle_tls_model_attribute
, false },
752 { "nonnull", 0, -1, false, true, true,
753 handle_nonnull_attribute
, false },
754 { "nothrow", 0, 0, true, false, false,
755 handle_nothrow_attribute
, false },
756 { "may_alias", 0, 0, false, true, false, NULL
, false },
757 { "cleanup", 1, 1, true, false, false,
758 handle_cleanup_attribute
, false },
759 { "warn_unused_result", 0, 0, false, true, true,
760 handle_warn_unused_result_attribute
, false },
761 { "sentinel", 0, 1, false, true, true,
762 handle_sentinel_attribute
, false },
763 /* For internal use (marking of builtins) only. The name contains space
764 to prevent its usage in source code. */
765 { "type generic", 0, 0, false, true, true,
766 handle_type_generic_attribute
, false },
767 { "alloc_size", 1, 2, false, true, true,
768 handle_alloc_size_attribute
, false },
769 { "cold", 0, 0, true, false, false,
770 handle_cold_attribute
, false },
771 { "hot", 0, 0, true, false, false,
772 handle_hot_attribute
, false },
773 { "no_address_safety_analysis",
774 0, 0, true, false, false,
775 handle_no_address_safety_analysis_attribute
,
777 { "no_sanitize_address", 0, 0, true, false, false,
778 handle_no_sanitize_address_attribute
,
780 { "no_sanitize_thread", 0, 0, true, false, false,
781 handle_no_sanitize_address_attribute
,
783 { "no_sanitize_undefined", 0, 0, true, false, false,
784 handle_no_sanitize_undefined_attribute
,
786 { "warning", 1, 1, true, false, false,
787 handle_error_attribute
, false },
788 { "error", 1, 1, true, false, false,
789 handle_error_attribute
, false },
790 { "target", 1, -1, true, false, false,
791 handle_target_attribute
, false },
792 { "optimize", 1, -1, true, false, false,
793 handle_optimize_attribute
, false },
794 /* For internal use only. The leading '*' both prevents its usage in
795 source code and signals that it may be overridden by machine tables. */
796 { "*tm regparm", 0, 0, false, true, true,
797 ignore_attribute
, false },
798 { "no_split_stack", 0, 0, true, false, false,
799 handle_no_split_stack_attribute
, false },
800 /* For internal use (marking of builtins and runtime functions) only.
801 The name contains space to prevent its usage in source code. */
802 { "fn spec", 1, 1, false, true, true,
803 handle_fnspec_attribute
, false },
804 { "warn_unused", 0, 0, false, false, false,
805 handle_warn_unused_attribute
, false },
806 { "returns_nonnull", 0, 0, false, true, true,
807 handle_returns_nonnull_attribute
, false },
808 { "omp declare simd", 0, -1, true, false, false,
809 handle_omp_declare_simd_attribute
, false },
810 { "cilk simd function", 0, -1, true, false, false,
811 handle_omp_declare_simd_attribute
, false },
812 { "omp declare target", 0, 0, true, false, false,
813 handle_omp_declare_target_attribute
, false },
814 { "alloc_align", 1, 1, false, true, true,
815 handle_alloc_align_attribute
, false },
816 { "assume_aligned", 1, 2, false, true, true,
817 handle_assume_aligned_attribute
, false },
818 { "designated_init", 0, 0, false, true, false,
819 handle_designated_init_attribute
, false },
820 { "bnd_variable_size", 0, 0, true, false, false,
821 handle_bnd_variable_size_attribute
, false },
822 { "bnd_legacy", 0, 0, true, false, false,
823 handle_bnd_legacy
, false },
824 { "bnd_instrument", 0, 0, true, false, false,
825 handle_bnd_instrument
, false },
826 { NULL
, 0, 0, false, false, false, NULL
, false }
829 /* Give the specifications for the format attributes, used by C and all
832 All attributes referencing arguments should be additionally processed
833 in chkp_copy_function_type_adding_bounds for correct instrumentation
834 by Pointer Bounds Checker.
835 Current list of processed format attributes: format, format_arg. */
836 const struct attribute_spec c_common_format_attribute_table
[] =
838 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
839 affects_type_identity } */
840 { "format", 3, 3, false, true, true,
841 handle_format_attribute
, false },
842 { "format_arg", 1, 1, false, true, true,
843 handle_format_arg_attribute
, false },
844 { NULL
, 0, 0, false, false, false, NULL
, false }
847 /* Return identifier for address space AS. */
850 c_addr_space_name (addr_space_t as
)
852 int rid
= RID_FIRST_ADDR_SPACE
+ as
;
853 gcc_assert (ridpointers
[rid
]);
854 return IDENTIFIER_POINTER (ridpointers
[rid
]);
857 /* Push current bindings for the function name VAR_DECLS. */
860 start_fname_decls (void)
863 tree saved
= NULL_TREE
;
865 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
867 tree decl
= *fname_vars
[ix
].decl
;
871 saved
= tree_cons (decl
, build_int_cst (integer_type_node
, ix
),
873 *fname_vars
[ix
].decl
= NULL_TREE
;
876 if (saved
|| saved_function_name_decls
)
877 /* Normally they'll have been NULL, so only push if we've got a
878 stack, or they are non-NULL. */
879 saved_function_name_decls
= tree_cons (saved
, NULL_TREE
,
880 saved_function_name_decls
);
883 /* Finish up the current bindings, adding them into the current function's
884 statement tree. This must be done _before_ finish_stmt_tree is called.
885 If there is no current function, we must be at file scope and no statements
886 are involved. Pop the previous bindings. */
889 finish_fname_decls (void)
892 tree stmts
= NULL_TREE
;
893 tree stack
= saved_function_name_decls
;
895 for (; stack
&& TREE_VALUE (stack
); stack
= TREE_CHAIN (stack
))
896 append_to_statement_list (TREE_VALUE (stack
), &stmts
);
900 tree
*bodyp
= &DECL_SAVED_TREE (current_function_decl
);
902 if (TREE_CODE (*bodyp
) == BIND_EXPR
)
903 bodyp
= &BIND_EXPR_BODY (*bodyp
);
905 append_to_statement_list_force (*bodyp
, &stmts
);
909 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
910 *fname_vars
[ix
].decl
= NULL_TREE
;
914 /* We had saved values, restore them. */
917 for (saved
= TREE_PURPOSE (stack
); saved
; saved
= TREE_CHAIN (saved
))
919 tree decl
= TREE_PURPOSE (saved
);
920 unsigned ix
= TREE_INT_CST_LOW (TREE_VALUE (saved
));
922 *fname_vars
[ix
].decl
= decl
;
924 stack
= TREE_CHAIN (stack
);
926 saved_function_name_decls
= stack
;
929 /* Return the text name of the current function, suitably prettified
930 by PRETTY_P. Return string must be freed by caller. */
933 fname_as_string (int pretty_p
)
935 const char *name
= "top level";
938 cpp_string cstr
= { 0, 0 }, strname
;
946 if (current_function_decl
)
947 name
= lang_hooks
.decl_printable_name (current_function_decl
, vrb
);
949 len
= strlen (name
) + 3; /* Two for '"'s. One for NULL. */
951 namep
= XNEWVEC (char, len
);
952 snprintf (namep
, len
, "\"%s\"", name
);
953 strname
.text
= (unsigned char *) namep
;
954 strname
.len
= len
- 1;
956 if (cpp_interpret_string (parse_in
, &strname
, 1, &cstr
, CPP_STRING
))
959 return (const char *) cstr
.text
;
965 /* Return the VAR_DECL for a const char array naming the current
966 function. If the VAR_DECL has not yet been created, create it
967 now. RID indicates how it should be formatted and IDENTIFIER_NODE
968 ID is its name (unfortunately C and C++ hold the RID values of
969 keywords in different places, so we can't derive RID from ID in
970 this language independent code. LOC is the location of the
974 fname_decl (location_t loc
, unsigned int rid
, tree id
)
977 tree decl
= NULL_TREE
;
979 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
980 if (fname_vars
[ix
].rid
== rid
)
983 decl
= *fname_vars
[ix
].decl
;
986 /* If a tree is built here, it would normally have the lineno of
987 the current statement. Later this tree will be moved to the
988 beginning of the function and this line number will be wrong.
989 To avoid this problem set the lineno to 0 here; that prevents
990 it from appearing in the RTL. */
992 location_t saved_location
= input_location
;
993 input_location
= UNKNOWN_LOCATION
;
995 stmts
= push_stmt_list ();
996 decl
= (*make_fname_decl
) (loc
, id
, fname_vars
[ix
].pretty
);
997 stmts
= pop_stmt_list (stmts
);
998 if (!IS_EMPTY_STMT (stmts
))
999 saved_function_name_decls
1000 = tree_cons (decl
, stmts
, saved_function_name_decls
);
1001 *fname_vars
[ix
].decl
= decl
;
1002 input_location
= saved_location
;
1004 if (!ix
&& !current_function_decl
)
1005 pedwarn (loc
, 0, "%qD is not defined outside of function scope", decl
);
1010 /* Given a STRING_CST, give it a suitable array-of-chars data type. */
1013 fix_string_type (tree value
)
1015 int length
= TREE_STRING_LENGTH (value
);
1017 tree e_type
, i_type
, a_type
;
1019 /* Compute the number of elements, for the array type. */
1020 if (TREE_TYPE (value
) == char_array_type_node
|| !TREE_TYPE (value
))
1023 e_type
= char_type_node
;
1025 else if (TREE_TYPE (value
) == char16_array_type_node
)
1027 nchars
= length
/ (TYPE_PRECISION (char16_type_node
) / BITS_PER_UNIT
);
1028 e_type
= char16_type_node
;
1030 else if (TREE_TYPE (value
) == char32_array_type_node
)
1032 nchars
= length
/ (TYPE_PRECISION (char32_type_node
) / BITS_PER_UNIT
);
1033 e_type
= char32_type_node
;
1037 nchars
= length
/ (TYPE_PRECISION (wchar_type_node
) / BITS_PER_UNIT
);
1038 e_type
= wchar_type_node
;
1041 /* C89 2.2.4.1, C99 5.2.4.1 (Translation limits). The analogous
1042 limit in C++98 Annex B is very large (65536) and is not normative,
1043 so we do not diagnose it (warn_overlength_strings is forced off
1044 in c_common_post_options). */
1045 if (warn_overlength_strings
)
1047 const int nchars_max
= flag_isoc99
? 4095 : 509;
1048 const int relevant_std
= flag_isoc99
? 99 : 90;
1049 if (nchars
- 1 > nchars_max
)
1050 /* Translators: The %d after 'ISO C' will be 90 or 99. Do not
1051 separate the %d from the 'C'. 'ISO' should not be
1052 translated, but it may be moved after 'C%d' in languages
1053 where modifiers follow nouns. */
1054 pedwarn (input_location
, OPT_Woverlength_strings
,
1055 "string length %qd is greater than the length %qd "
1056 "ISO C%d compilers are required to support",
1057 nchars
- 1, nchars_max
, relevant_std
);
1060 /* Create the array type for the string constant. The ISO C++
1061 standard says that a string literal has type `const char[N]' or
1062 `const wchar_t[N]'. We use the same logic when invoked as a C
1063 front-end with -Wwrite-strings.
1064 ??? We should change the type of an expression depending on the
1065 state of a warning flag. We should just be warning -- see how
1066 this is handled in the C++ front-end for the deprecated implicit
1067 conversion from string literals to `char*' or `wchar_t*'.
1069 The C++ front end relies on TYPE_MAIN_VARIANT of a cv-qualified
1070 array type being the unqualified version of that type.
1071 Therefore, if we are constructing an array of const char, we must
1072 construct the matching unqualified array type first. The C front
1073 end does not require this, but it does no harm, so we do it
1075 i_type
= build_index_type (size_int (nchars
- 1));
1076 a_type
= build_array_type (e_type
, i_type
);
1077 if (c_dialect_cxx() || warn_write_strings
)
1078 a_type
= c_build_qualified_type (a_type
, TYPE_QUAL_CONST
);
1080 TREE_TYPE (value
) = a_type
;
1081 TREE_CONSTANT (value
) = 1;
1082 TREE_READONLY (value
) = 1;
1083 TREE_STATIC (value
) = 1;
1087 /* If DISABLE is true, stop issuing warnings. This is used when
1088 parsing code that we know will not be executed. This function may
1089 be called multiple times, and works as a stack. */
1092 c_disable_warnings (bool disable
)
1096 ++c_inhibit_evaluation_warnings
;
1097 fold_defer_overflow_warnings ();
1101 /* If ENABLE is true, reenable issuing warnings. */
1104 c_enable_warnings (bool enable
)
1108 --c_inhibit_evaluation_warnings
;
1109 fold_undefer_and_ignore_overflow_warnings ();
1113 /* Fully fold EXPR, an expression that was not folded (beyond integer
1114 constant expressions and null pointer constants) when being built
1115 up. If IN_INIT, this is in a static initializer and certain
1116 changes are made to the folding done. Clear *MAYBE_CONST if
1117 MAYBE_CONST is not NULL and EXPR is definitely not a constant
1118 expression because it contains an evaluated operator (in C99) or an
1119 operator outside of sizeof returning an integer constant (in C90)
1120 not permitted in constant expressions, or because it contains an
1121 evaluated arithmetic overflow. (*MAYBE_CONST should typically be
1122 set to true by callers before calling this function.) Return the
1123 folded expression. Function arguments have already been folded
1124 before calling this function, as have the contents of SAVE_EXPR,
1125 TARGET_EXPR, BIND_EXPR, VA_ARG_EXPR, OBJ_TYPE_REF and
1126 C_MAYBE_CONST_EXPR. */
1129 c_fully_fold (tree expr
, bool in_init
, bool *maybe_const
)
1132 tree eptype
= NULL_TREE
;
1134 bool maybe_const_itself
= true;
1135 location_t loc
= EXPR_LOCATION (expr
);
1137 /* This function is not relevant to C++ because C++ folds while
1138 parsing, and may need changes to be correct for C++ when C++
1139 stops folding while parsing. */
1140 if (c_dialect_cxx ())
1144 maybe_const
= &dummy
;
1145 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
1147 eptype
= TREE_TYPE (expr
);
1148 expr
= TREE_OPERAND (expr
, 0);
1150 ret
= c_fully_fold_internal (expr
, in_init
, maybe_const
,
1151 &maybe_const_itself
);
1153 ret
= fold_convert_loc (loc
, eptype
, ret
);
1154 *maybe_const
&= maybe_const_itself
;
1158 /* Internal helper for c_fully_fold. EXPR and IN_INIT are as for
1159 c_fully_fold. *MAYBE_CONST_OPERANDS is cleared because of operands
1160 not permitted, while *MAYBE_CONST_ITSELF is cleared because of
1161 arithmetic overflow (for C90, *MAYBE_CONST_OPERANDS is carried from
1162 both evaluated and unevaluated subexpressions while
1163 *MAYBE_CONST_ITSELF is carried from only evaluated
1167 c_fully_fold_internal (tree expr
, bool in_init
, bool *maybe_const_operands
,
1168 bool *maybe_const_itself
)
1171 enum tree_code code
= TREE_CODE (expr
);
1172 enum tree_code_class kind
= TREE_CODE_CLASS (code
);
1173 location_t loc
= EXPR_LOCATION (expr
);
1174 tree op0
, op1
, op2
, op3
;
1175 tree orig_op0
, orig_op1
, orig_op2
;
1176 bool op0_const
= true, op1_const
= true, op2_const
= true;
1177 bool op0_const_self
= true, op1_const_self
= true, op2_const_self
= true;
1178 bool nowarning
= TREE_NO_WARNING (expr
);
1181 /* This function is not relevant to C++ because C++ folds while
1182 parsing, and may need changes to be correct for C++ when C++
1183 stops folding while parsing. */
1184 if (c_dialect_cxx ())
1187 /* Constants, declarations, statements, errors, SAVE_EXPRs and
1188 anything else not counted as an expression cannot usefully be
1189 folded further at this point. */
1190 if (!IS_EXPR_CODE_CLASS (kind
)
1191 || kind
== tcc_statement
1192 || code
== SAVE_EXPR
)
1195 /* Operands of variable-length expressions (function calls) have
1196 already been folded, as have __builtin_* function calls, and such
1197 expressions cannot occur in constant expressions. */
1198 if (kind
== tcc_vl_exp
)
1200 *maybe_const_operands
= false;
1205 if (code
== C_MAYBE_CONST_EXPR
)
1207 tree pre
= C_MAYBE_CONST_EXPR_PRE (expr
);
1208 tree inner
= C_MAYBE_CONST_EXPR_EXPR (expr
);
1209 if (C_MAYBE_CONST_EXPR_NON_CONST (expr
))
1210 *maybe_const_operands
= false;
1211 if (C_MAYBE_CONST_EXPR_INT_OPERANDS (expr
))
1212 *maybe_const_itself
= false;
1213 if (pre
&& !in_init
)
1214 ret
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr
), pre
, inner
);
1220 /* Assignment, increment, decrement, function call and comma
1221 operators, and statement expressions, cannot occur in constant
1222 expressions if evaluated / outside of sizeof. (Function calls
1223 were handled above, though VA_ARG_EXPR is treated like a function
1224 call here, and statement expressions are handled through
1225 C_MAYBE_CONST_EXPR to avoid folding inside them.) */
1229 case PREDECREMENT_EXPR
:
1230 case PREINCREMENT_EXPR
:
1231 case POSTDECREMENT_EXPR
:
1232 case POSTINCREMENT_EXPR
:
1234 *maybe_const_operands
= false;
1241 *maybe_const_operands
= false;
1249 /* Fold individual tree codes as appropriate. */
1252 case COMPOUND_LITERAL_EXPR
:
1253 /* Any non-constancy will have been marked in a containing
1254 C_MAYBE_CONST_EXPR; there is no more folding to do here. */
1258 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1259 op1
= TREE_OPERAND (expr
, 1);
1260 op2
= TREE_OPERAND (expr
, 2);
1261 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1262 maybe_const_itself
);
1263 STRIP_TYPE_NOPS (op0
);
1264 if (op0
!= orig_op0
)
1265 ret
= build3 (COMPONENT_REF
, TREE_TYPE (expr
), op0
, op1
, op2
);
1268 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1269 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1274 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1275 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1276 op2
= TREE_OPERAND (expr
, 2);
1277 op3
= TREE_OPERAND (expr
, 3);
1278 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1279 maybe_const_itself
);
1280 STRIP_TYPE_NOPS (op0
);
1281 op1
= c_fully_fold_internal (op1
, in_init
, maybe_const_operands
,
1282 maybe_const_itself
);
1283 STRIP_TYPE_NOPS (op1
);
1284 op1
= decl_constant_value_for_optimization (op1
);
1285 if (op0
!= orig_op0
|| op1
!= orig_op1
)
1286 ret
= build4 (ARRAY_REF
, TREE_TYPE (expr
), op0
, op1
, op2
, op3
);
1289 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1290 TREE_SIDE_EFFECTS (ret
) = TREE_SIDE_EFFECTS (expr
);
1291 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1298 case PREDECREMENT_EXPR
:
1299 case PREINCREMENT_EXPR
:
1300 case POSTDECREMENT_EXPR
:
1301 case POSTINCREMENT_EXPR
:
1305 case POINTER_PLUS_EXPR
:
1306 case TRUNC_DIV_EXPR
:
1308 case FLOOR_DIV_EXPR
:
1309 case TRUNC_MOD_EXPR
:
1311 case EXACT_DIV_EXPR
:
1324 case TRUTH_AND_EXPR
:
1326 case TRUTH_XOR_EXPR
:
1327 case UNORDERED_EXPR
:
1334 /* Binary operations evaluating both arguments (increment and
1335 decrement are binary internally in GCC). */
1336 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1337 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1338 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1339 maybe_const_itself
);
1340 STRIP_TYPE_NOPS (op0
);
1341 if (code
!= MODIFY_EXPR
1342 && code
!= PREDECREMENT_EXPR
1343 && code
!= PREINCREMENT_EXPR
1344 && code
!= POSTDECREMENT_EXPR
1345 && code
!= POSTINCREMENT_EXPR
)
1346 op0
= decl_constant_value_for_optimization (op0
);
1347 /* The RHS of a MODIFY_EXPR was fully folded when building that
1348 expression for the sake of conversion warnings. */
1349 if (code
!= MODIFY_EXPR
)
1350 op1
= c_fully_fold_internal (op1
, in_init
, maybe_const_operands
,
1351 maybe_const_itself
);
1352 STRIP_TYPE_NOPS (op1
);
1353 op1
= decl_constant_value_for_optimization (op1
);
1354 if (op0
!= orig_op0
|| op1
!= orig_op1
|| in_init
)
1356 ? fold_build2_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
)
1357 : fold_build2_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
);
1360 if (TREE_OVERFLOW_P (ret
)
1361 && !TREE_OVERFLOW_P (op0
)
1362 && !TREE_OVERFLOW_P (op1
))
1363 overflow_warning (EXPR_LOCATION (expr
), ret
);
1364 if (code
== LSHIFT_EXPR
1365 && TREE_CODE (orig_op0
) != INTEGER_CST
1366 && TREE_CODE (TREE_TYPE (orig_op0
)) == INTEGER_TYPE
1367 && TREE_CODE (op0
) == INTEGER_CST
1368 && c_inhibit_evaluation_warnings
== 0
1369 && tree_int_cst_sgn (op0
) < 0)
1370 warning_at (loc
, OPT_Wshift_negative_value
,
1371 "left shift of negative value");
1372 if ((code
== LSHIFT_EXPR
|| code
== RSHIFT_EXPR
)
1373 && TREE_CODE (orig_op1
) != INTEGER_CST
1374 && TREE_CODE (op1
) == INTEGER_CST
1375 && (TREE_CODE (TREE_TYPE (orig_op0
)) == INTEGER_TYPE
1376 || TREE_CODE (TREE_TYPE (orig_op0
)) == FIXED_POINT_TYPE
)
1377 && TREE_CODE (TREE_TYPE (orig_op1
)) == INTEGER_TYPE
1378 && c_inhibit_evaluation_warnings
== 0)
1380 if (tree_int_cst_sgn (op1
) < 0)
1381 warning_at (loc
, OPT_Wshift_count_negative
,
1382 (code
== LSHIFT_EXPR
1383 ? G_("left shift count is negative")
1384 : G_("right shift count is negative")));
1385 else if (compare_tree_int (op1
,
1386 TYPE_PRECISION (TREE_TYPE (orig_op0
)))
1388 warning_at (loc
, OPT_Wshift_count_overflow
,
1389 (code
== LSHIFT_EXPR
1390 ? G_("left shift count >= width of type")
1391 : G_("right shift count >= width of type")));
1393 if ((code
== TRUNC_DIV_EXPR
1394 || code
== CEIL_DIV_EXPR
1395 || code
== FLOOR_DIV_EXPR
1396 || code
== EXACT_DIV_EXPR
1397 || code
== TRUNC_MOD_EXPR
)
1398 && TREE_CODE (orig_op1
) != INTEGER_CST
1399 && TREE_CODE (op1
) == INTEGER_CST
1400 && (TREE_CODE (TREE_TYPE (orig_op0
)) == INTEGER_TYPE
1401 || TREE_CODE (TREE_TYPE (orig_op0
)) == FIXED_POINT_TYPE
)
1402 && TREE_CODE (TREE_TYPE (orig_op1
)) == INTEGER_TYPE
)
1403 warn_for_div_by_zero (loc
, op1
);
1407 case FIX_TRUNC_EXPR
:
1410 case ADDR_SPACE_CONVERT_EXPR
:
1411 case VIEW_CONVERT_EXPR
:
1412 case NON_LVALUE_EXPR
:
1415 case TRUTH_NOT_EXPR
:
1420 /* Unary operations. */
1421 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1422 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1423 maybe_const_itself
);
1424 STRIP_TYPE_NOPS (op0
);
1425 if (code
!= ADDR_EXPR
&& code
!= REALPART_EXPR
&& code
!= IMAGPART_EXPR
)
1426 op0
= decl_constant_value_for_optimization (op0
);
1427 /* ??? Cope with user tricks that amount to offsetof. The middle-end is
1428 not prepared to deal with them if they occur in initializers. */
1430 && code
== ADDR_EXPR
1431 && (op1
= get_base_address (op0
)) != NULL_TREE
1432 && TREE_CODE (op1
) == INDIRECT_REF
1433 && TREE_CONSTANT (TREE_OPERAND (op1
, 0)))
1434 ret
= fold_convert_loc (loc
, TREE_TYPE (expr
), fold_offsetof_1 (op0
));
1435 else if (op0
!= orig_op0
|| in_init
)
1437 ? fold_build1_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
)
1438 : fold_build1_loc (loc
, code
, TREE_TYPE (expr
), op0
);
1441 if (code
== INDIRECT_REF
1443 && TREE_CODE (ret
) == INDIRECT_REF
)
1445 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1446 TREE_SIDE_EFFECTS (ret
) = TREE_SIDE_EFFECTS (expr
);
1447 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1451 case FIX_TRUNC_EXPR
:
1454 /* Don't warn about explicit conversions. We will already
1455 have warned about suspect implicit conversions. */
1459 if (TREE_OVERFLOW_P (ret
) && !TREE_OVERFLOW_P (op0
))
1460 overflow_warning (EXPR_LOCATION (expr
), ret
);
1465 case TRUTH_ANDIF_EXPR
:
1466 case TRUTH_ORIF_EXPR
:
1467 /* Binary operations not necessarily evaluating both
1469 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1470 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1471 op0
= c_fully_fold_internal (op0
, in_init
, &op0_const
, &op0_const_self
);
1472 STRIP_TYPE_NOPS (op0
);
1474 unused_p
= (op0
== (code
== TRUTH_ANDIF_EXPR
1475 ? truthvalue_false_node
1476 : truthvalue_true_node
));
1477 c_disable_warnings (unused_p
);
1478 op1
= c_fully_fold_internal (op1
, in_init
, &op1_const
, &op1_const_self
);
1479 STRIP_TYPE_NOPS (op1
);
1480 c_enable_warnings (unused_p
);
1482 if (op0
!= orig_op0
|| op1
!= orig_op1
|| in_init
)
1484 ? fold_build2_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
)
1485 : fold_build2_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
);
1488 *maybe_const_operands
&= op0_const
;
1489 *maybe_const_itself
&= op0_const_self
;
1493 && (code
== TRUTH_ANDIF_EXPR
1494 ? op0
== truthvalue_false_node
1495 : op0
== truthvalue_true_node
)))
1496 *maybe_const_operands
&= op1_const
;
1499 && (code
== TRUTH_ANDIF_EXPR
1500 ? op0
== truthvalue_false_node
1501 : op0
== truthvalue_true_node
)))
1502 *maybe_const_itself
&= op1_const_self
;
1506 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1507 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1508 orig_op2
= op2
= TREE_OPERAND (expr
, 2);
1509 op0
= c_fully_fold_internal (op0
, in_init
, &op0_const
, &op0_const_self
);
1511 STRIP_TYPE_NOPS (op0
);
1512 c_disable_warnings (op0
== truthvalue_false_node
);
1513 op1
= c_fully_fold_internal (op1
, in_init
, &op1_const
, &op1_const_self
);
1514 STRIP_TYPE_NOPS (op1
);
1515 c_enable_warnings (op0
== truthvalue_false_node
);
1517 c_disable_warnings (op0
== truthvalue_true_node
);
1518 op2
= c_fully_fold_internal (op2
, in_init
, &op2_const
, &op2_const_self
);
1519 STRIP_TYPE_NOPS (op2
);
1520 c_enable_warnings (op0
== truthvalue_true_node
);
1522 if (op0
!= orig_op0
|| op1
!= orig_op1
|| op2
!= orig_op2
)
1523 ret
= fold_build3_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
, op2
);
1526 *maybe_const_operands
&= op0_const
;
1527 *maybe_const_itself
&= op0_const_self
;
1531 && op0
== truthvalue_false_node
))
1532 *maybe_const_operands
&= op1_const
;
1535 && op0
== truthvalue_false_node
))
1536 *maybe_const_itself
&= op1_const_self
;
1540 && op0
== truthvalue_true_node
))
1541 *maybe_const_operands
&= op2_const
;
1544 && op0
== truthvalue_true_node
))
1545 *maybe_const_itself
&= op2_const_self
;
1548 case EXCESS_PRECISION_EXPR
:
1549 /* Each case where an operand with excess precision may be
1550 encountered must remove the EXCESS_PRECISION_EXPR around
1551 inner operands and possibly put one around the whole
1552 expression or possibly convert to the semantic type (which
1553 c_fully_fold does); we cannot tell at this stage which is
1554 appropriate in any particular case. */
1558 /* Various codes may appear through folding built-in functions
1559 and their arguments. */
1564 /* Some folding may introduce NON_LVALUE_EXPRs; all lvalue checks
1565 have been done by this point, so remove them again. */
1566 nowarning
|= TREE_NO_WARNING (ret
);
1567 STRIP_TYPE_NOPS (ret
);
1568 if (nowarning
&& !TREE_NO_WARNING (ret
))
1570 if (!CAN_HAVE_LOCATION_P (ret
))
1571 ret
= build1 (NOP_EXPR
, TREE_TYPE (ret
), ret
);
1572 TREE_NO_WARNING (ret
) = 1;
1575 protected_set_expr_location (ret
, loc
);
1579 /* If not optimizing, EXP is not a VAR_DECL, or EXP has array type,
1580 return EXP. Otherwise, return either EXP or its known constant
1581 value (if it has one), but return EXP if EXP has mode BLKmode. ???
1582 Is the BLKmode test appropriate? */
1585 decl_constant_value_for_optimization (tree exp
)
1589 /* This function is only used by C, for c_fully_fold and other
1590 optimization, and may not be correct for C++. */
1591 if (c_dialect_cxx ())
1595 || TREE_CODE (exp
) != VAR_DECL
1596 || TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
1597 || DECL_MODE (exp
) == BLKmode
)
1600 ret
= decl_constant_value (exp
);
1601 /* Avoid unwanted tree sharing between the initializer and current
1602 function's body where the tree can be modified e.g. by the
1604 if (ret
!= exp
&& TREE_STATIC (exp
))
1605 ret
= unshare_expr (ret
);
1609 /* Print a warning if a constant expression had overflow in folding.
1610 Invoke this function on every expression that the language
1611 requires to be a constant expression.
1612 Note the ANSI C standard says it is erroneous for a
1613 constant expression to overflow. */
1616 constant_expression_warning (tree value
)
1618 if (warn_overflow
&& pedantic
1619 && (TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1620 || TREE_CODE (value
) == FIXED_CST
1621 || TREE_CODE (value
) == VECTOR_CST
1622 || TREE_CODE (value
) == COMPLEX_CST
)
1623 && TREE_OVERFLOW (value
))
1624 pedwarn (input_location
, OPT_Woverflow
, "overflow in constant expression");
1627 /* The same as above but print an unconditional error. */
1629 constant_expression_error (tree value
)
1631 if ((TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1632 || TREE_CODE (value
) == FIXED_CST
1633 || TREE_CODE (value
) == VECTOR_CST
1634 || TREE_CODE (value
) == COMPLEX_CST
)
1635 && TREE_OVERFLOW (value
))
1636 error ("overflow in constant expression");
1639 /* Print a warning if an expression had overflow in folding and its
1642 Invoke this function on every expression that
1643 (1) appears in the source code, and
1644 (2) is a constant expression that overflowed, and
1645 (3) is not already checked by convert_and_check;
1646 however, do not invoke this function on operands of explicit casts
1647 or when the expression is the result of an operator and any operand
1648 already overflowed. */
1651 overflow_warning (location_t loc
, tree value
)
1653 if (c_inhibit_evaluation_warnings
!= 0)
1656 switch (TREE_CODE (value
))
1659 warning_at (loc
, OPT_Woverflow
, "integer overflow in expression");
1663 warning_at (loc
, OPT_Woverflow
,
1664 "floating point overflow in expression");
1668 warning_at (loc
, OPT_Woverflow
, "fixed-point overflow in expression");
1672 warning_at (loc
, OPT_Woverflow
, "vector overflow in expression");
1676 if (TREE_CODE (TREE_REALPART (value
)) == INTEGER_CST
)
1677 warning_at (loc
, OPT_Woverflow
,
1678 "complex integer overflow in expression");
1679 else if (TREE_CODE (TREE_REALPART (value
)) == REAL_CST
)
1680 warning_at (loc
, OPT_Woverflow
,
1681 "complex floating point overflow in expression");
1689 /* Warn about uses of logical || / && operator in a context where it
1690 is likely that the bitwise equivalent was intended by the
1691 programmer. We have seen an expression in which CODE is a binary
1692 operator used to combine expressions OP_LEFT and OP_RIGHT, which before folding
1693 had CODE_LEFT and CODE_RIGHT, into an expression of type TYPE. */
1695 warn_logical_operator (location_t location
, enum tree_code code
, tree type
,
1696 enum tree_code code_left
, tree op_left
,
1697 enum tree_code
ARG_UNUSED (code_right
), tree op_right
)
1699 int or_op
= (code
== TRUTH_ORIF_EXPR
|| code
== TRUTH_OR_EXPR
);
1700 int in0_p
, in1_p
, in_p
;
1701 tree low0
, low1
, low
, high0
, high1
, high
, lhs
, rhs
, tem
;
1702 bool strict_overflow_p
= false;
1704 if (code
!= TRUTH_ANDIF_EXPR
1705 && code
!= TRUTH_AND_EXPR
1706 && code
!= TRUTH_ORIF_EXPR
1707 && code
!= TRUTH_OR_EXPR
)
1710 /* We don't want to warn if either operand comes from a macro
1711 expansion. ??? This doesn't work with e.g. NEGATE_EXPR yet;
1713 if (from_macro_expansion_at (EXPR_LOCATION (op_left
))
1714 || from_macro_expansion_at (EXPR_LOCATION (op_right
)))
1717 /* Warn if &&/|| are being used in a context where it is
1718 likely that the bitwise equivalent was intended by the
1719 programmer. That is, an expression such as op && MASK
1720 where op should not be any boolean expression, nor a
1721 constant, and mask seems to be a non-boolean integer constant. */
1722 if (!truth_value_p (code_left
)
1723 && INTEGRAL_TYPE_P (TREE_TYPE (op_left
))
1724 && !CONSTANT_CLASS_P (op_left
)
1725 && !TREE_NO_WARNING (op_left
)
1726 && TREE_CODE (op_right
) == INTEGER_CST
1727 && !integer_zerop (op_right
)
1728 && !integer_onep (op_right
))
1731 warning_at (location
, OPT_Wlogical_op
, "logical %<or%>"
1732 " applied to non-boolean constant");
1734 warning_at (location
, OPT_Wlogical_op
, "logical %<and%>"
1735 " applied to non-boolean constant");
1736 TREE_NO_WARNING (op_left
) = true;
1740 /* We do not warn for constants because they are typical of macro
1741 expansions that test for features. */
1742 if (CONSTANT_CLASS_P (op_left
) || CONSTANT_CLASS_P (op_right
))
1745 /* This warning only makes sense with logical operands. */
1746 if (!(truth_value_p (TREE_CODE (op_left
))
1747 || INTEGRAL_TYPE_P (TREE_TYPE (op_left
)))
1748 || !(truth_value_p (TREE_CODE (op_right
))
1749 || INTEGRAL_TYPE_P (TREE_TYPE (op_right
))))
1752 /* The range computations only work with scalars. */
1753 if (VECTOR_TYPE_P (TREE_TYPE (op_left
))
1754 || VECTOR_TYPE_P (TREE_TYPE (op_right
)))
1757 /* We first test whether either side separately is trivially true
1758 (with OR) or trivially false (with AND). If so, do not warn.
1759 This is a common idiom for testing ranges of data types in
1761 lhs
= make_range (op_left
, &in0_p
, &low0
, &high0
, &strict_overflow_p
);
1764 if (TREE_CODE (lhs
) == C_MAYBE_CONST_EXPR
)
1765 lhs
= C_MAYBE_CONST_EXPR_EXPR (lhs
);
1767 /* If this is an OR operation, invert both sides; now, the result
1768 should be always false to get a warning. */
1772 tem
= build_range_check (UNKNOWN_LOCATION
, type
, lhs
, in0_p
, low0
, high0
);
1773 if (tem
&& integer_zerop (tem
))
1776 rhs
= make_range (op_right
, &in1_p
, &low1
, &high1
, &strict_overflow_p
);
1779 if (TREE_CODE (rhs
) == C_MAYBE_CONST_EXPR
)
1780 rhs
= C_MAYBE_CONST_EXPR_EXPR (rhs
);
1782 /* If this is an OR operation, invert both sides; now, the result
1783 should be always false to get a warning. */
1787 tem
= build_range_check (UNKNOWN_LOCATION
, type
, rhs
, in1_p
, low1
, high1
);
1788 if (tem
&& integer_zerop (tem
))
1791 /* If both expressions have the same operand, if we can merge the
1793 if (operand_equal_p (lhs
, rhs
, 0)
1794 && merge_ranges (&in_p
, &low
, &high
, in0_p
, low0
, high0
,
1795 in1_p
, low1
, high1
))
1797 tem
= build_range_check (UNKNOWN_LOCATION
, type
, lhs
, in_p
, low
, high
);
1798 /* ... and if the range test is always false, then warn. */
1799 if (tem
&& integer_zerop (tem
))
1802 warning_at (location
, OPT_Wlogical_op
,
1803 "logical %<or%> of collectively exhaustive tests is "
1806 warning_at (location
, OPT_Wlogical_op
,
1807 "logical %<and%> of mutually exclusive tests is "
1810 /* Or warn if the operands have exactly the same range, e.g.
1812 else if (low0
== low1
&& high0
== high1
)
1815 warning_at (location
, OPT_Wlogical_op
,
1816 "logical %<or%> of equal expressions");
1818 warning_at (location
, OPT_Wlogical_op
,
1819 "logical %<and%> of equal expressions");
1824 /* Warn about logical not used on the left hand side operand of a comparison.
1825 This function assumes that the LHS is inside of TRUTH_NOT_EXPR.
1826 Do not warn if RHS is of a boolean type. */
1829 warn_logical_not_parentheses (location_t location
, enum tree_code code
,
1832 if (TREE_CODE_CLASS (code
) != tcc_comparison
1833 || TREE_TYPE (rhs
) == NULL_TREE
1834 || TREE_CODE (TREE_TYPE (rhs
)) == BOOLEAN_TYPE
)
1837 /* Don't warn for !x == 0 or !y != 0, those are equivalent to
1838 !(x == 0) or !(y != 0). */
1839 if ((code
== EQ_EXPR
|| code
== NE_EXPR
)
1840 && integer_zerop (rhs
))
1843 warning_at (location
, OPT_Wlogical_not_parentheses
,
1844 "logical not is only applied to the left hand side of "
1848 /* Warn if EXP contains any computations whose results are not used.
1849 Return true if a warning is printed; false otherwise. LOCUS is the
1850 (potential) location of the expression. */
1853 warn_if_unused_value (const_tree exp
, location_t locus
)
1856 if (TREE_USED (exp
) || TREE_NO_WARNING (exp
))
1859 /* Don't warn about void constructs. This includes casting to void,
1860 void function calls, and statement expressions with a final cast
1862 if (VOID_TYPE_P (TREE_TYPE (exp
)))
1865 if (EXPR_HAS_LOCATION (exp
))
1866 locus
= EXPR_LOCATION (exp
);
1868 switch (TREE_CODE (exp
))
1870 case PREINCREMENT_EXPR
:
1871 case POSTINCREMENT_EXPR
:
1872 case PREDECREMENT_EXPR
:
1873 case POSTDECREMENT_EXPR
:
1878 case TRY_CATCH_EXPR
:
1879 case WITH_CLEANUP_EXPR
:
1885 /* For a binding, warn if no side effect within it. */
1886 exp
= BIND_EXPR_BODY (exp
);
1890 case NON_LVALUE_EXPR
:
1892 exp
= TREE_OPERAND (exp
, 0);
1895 case TRUTH_ORIF_EXPR
:
1896 case TRUTH_ANDIF_EXPR
:
1897 /* In && or ||, warn if 2nd operand has no side effect. */
1898 exp
= TREE_OPERAND (exp
, 1);
1902 if (warn_if_unused_value (TREE_OPERAND (exp
, 0), locus
))
1904 /* Let people do `(foo (), 0)' without a warning. */
1905 if (TREE_CONSTANT (TREE_OPERAND (exp
, 1)))
1907 exp
= TREE_OPERAND (exp
, 1);
1911 /* If this is an expression with side effects, don't warn; this
1912 case commonly appears in macro expansions. */
1913 if (TREE_SIDE_EFFECTS (exp
))
1918 /* Don't warn about automatic dereferencing of references, since
1919 the user cannot control it. */
1920 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == REFERENCE_TYPE
)
1922 exp
= TREE_OPERAND (exp
, 0);
1928 /* Referencing a volatile value is a side effect, so don't warn. */
1929 if ((DECL_P (exp
) || REFERENCE_CLASS_P (exp
))
1930 && TREE_THIS_VOLATILE (exp
))
1933 /* If this is an expression which has no operands, there is no value
1934 to be unused. There are no such language-independent codes,
1935 but front ends may define such. */
1936 if (EXPRESSION_CLASS_P (exp
) && TREE_OPERAND_LENGTH (exp
) == 0)
1940 return warning_at (locus
, OPT_Wunused_value
, "value computed is not used");
1945 /* Print a warning about casts that might indicate violation
1946 of strict aliasing rules if -Wstrict-aliasing is used and
1947 strict aliasing mode is in effect. OTYPE is the original
1948 TREE_TYPE of EXPR, and TYPE the type we're casting to. */
1951 strict_aliasing_warning (tree otype
, tree type
, tree expr
)
1953 /* Strip pointer conversion chains and get to the correct original type. */
1955 otype
= TREE_TYPE (expr
);
1957 if (!(flag_strict_aliasing
1958 && POINTER_TYPE_P (type
)
1959 && POINTER_TYPE_P (otype
)
1960 && !VOID_TYPE_P (TREE_TYPE (type
)))
1961 /* If the type we are casting to is a ref-all pointer
1962 dereferencing it is always valid. */
1963 || TYPE_REF_CAN_ALIAS_ALL (type
))
1966 if ((warn_strict_aliasing
> 1) && TREE_CODE (expr
) == ADDR_EXPR
1967 && (DECL_P (TREE_OPERAND (expr
, 0))
1968 || handled_component_p (TREE_OPERAND (expr
, 0))))
1970 /* Casting the address of an object to non void pointer. Warn
1971 if the cast breaks type based aliasing. */
1972 if (!COMPLETE_TYPE_P (TREE_TYPE (type
)) && warn_strict_aliasing
== 2)
1974 warning (OPT_Wstrict_aliasing
, "type-punning to incomplete type "
1975 "might break strict-aliasing rules");
1980 /* warn_strict_aliasing >= 3. This includes the default (3).
1981 Only warn if the cast is dereferenced immediately. */
1982 alias_set_type set1
=
1983 get_alias_set (TREE_TYPE (TREE_OPERAND (expr
, 0)));
1984 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
1986 if (set1
!= set2
&& set2
!= 0
1987 && (set1
== 0 || !alias_sets_conflict_p (set1
, set2
)))
1989 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1990 "pointer will break strict-aliasing rules");
1993 else if (warn_strict_aliasing
== 2
1994 && !alias_sets_must_conflict_p (set1
, set2
))
1996 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1997 "pointer might break strict-aliasing rules");
2003 if ((warn_strict_aliasing
== 1) && !VOID_TYPE_P (TREE_TYPE (otype
)))
2005 /* At this level, warn for any conversions, even if an address is
2006 not taken in the same statement. This will likely produce many
2007 false positives, but could be useful to pinpoint problems that
2008 are not revealed at higher levels. */
2009 alias_set_type set1
= get_alias_set (TREE_TYPE (otype
));
2010 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
2011 if (!COMPLETE_TYPE_P (type
)
2012 || !alias_sets_must_conflict_p (set1
, set2
))
2014 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
2015 "pointer might break strict-aliasing rules");
2023 /* Warn about memset (&a, 0, sizeof (&a)); and similar mistakes with
2024 sizeof as last operand of certain builtins. */
2027 sizeof_pointer_memaccess_warning (location_t
*sizeof_arg_loc
, tree callee
,
2028 vec
<tree
, va_gc
> *params
, tree
*sizeof_arg
,
2029 bool (*comp_types
) (tree
, tree
))
2031 tree type
, dest
= NULL_TREE
, src
= NULL_TREE
, tem
;
2032 bool strop
= false, cmp
= false;
2033 unsigned int idx
= ~0;
2036 if (TREE_CODE (callee
) != FUNCTION_DECL
2037 || DECL_BUILT_IN_CLASS (callee
) != BUILT_IN_NORMAL
2038 || vec_safe_length (params
) <= 1)
2041 switch (DECL_FUNCTION_CODE (callee
))
2043 case BUILT_IN_STRNCMP
:
2044 case BUILT_IN_STRNCASECMP
:
2047 case BUILT_IN_STRNCPY
:
2048 case BUILT_IN_STRNCPY_CHK
:
2049 case BUILT_IN_STRNCAT
:
2050 case BUILT_IN_STRNCAT_CHK
:
2051 case BUILT_IN_STPNCPY
:
2052 case BUILT_IN_STPNCPY_CHK
:
2055 case BUILT_IN_MEMCPY
:
2056 case BUILT_IN_MEMCPY_CHK
:
2057 case BUILT_IN_MEMMOVE
:
2058 case BUILT_IN_MEMMOVE_CHK
:
2059 if (params
->length () < 3)
2062 dest
= (*params
)[0];
2065 case BUILT_IN_BCOPY
:
2066 if (params
->length () < 3)
2069 dest
= (*params
)[1];
2072 case BUILT_IN_MEMCMP
:
2074 if (params
->length () < 3)
2077 dest
= (*params
)[0];
2081 case BUILT_IN_MEMSET
:
2082 case BUILT_IN_MEMSET_CHK
:
2083 if (params
->length () < 3)
2085 dest
= (*params
)[0];
2088 case BUILT_IN_BZERO
:
2089 dest
= (*params
)[0];
2092 case BUILT_IN_STRNDUP
:
2097 case BUILT_IN_MEMCHR
:
2098 if (params
->length () < 3)
2103 case BUILT_IN_SNPRINTF
:
2104 case BUILT_IN_SNPRINTF_CHK
:
2105 case BUILT_IN_VSNPRINTF
:
2106 case BUILT_IN_VSNPRINTF_CHK
:
2107 dest
= (*params
)[0];
2118 if (sizeof_arg
[idx
] == NULL
|| sizeof_arg
[idx
] == error_mark_node
)
2121 type
= TYPE_P (sizeof_arg
[idx
])
2122 ? sizeof_arg
[idx
] : TREE_TYPE (sizeof_arg
[idx
]);
2123 if (!POINTER_TYPE_P (type
))
2127 && (tem
= tree_strip_nop_conversions (dest
))
2128 && POINTER_TYPE_P (TREE_TYPE (tem
))
2129 && comp_types (TREE_TYPE (TREE_TYPE (tem
)), type
))
2133 && (tem
= tree_strip_nop_conversions (src
))
2134 && POINTER_TYPE_P (TREE_TYPE (tem
))
2135 && comp_types (TREE_TYPE (TREE_TYPE (tem
)), type
))
2138 loc
= sizeof_arg_loc
[idx
];
2142 if (!TYPE_P (sizeof_arg
[idx
])
2143 && operand_equal_p (dest
, sizeof_arg
[idx
], 0)
2144 && comp_types (TREE_TYPE (dest
), type
))
2146 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2147 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2148 "argument to %<sizeof%> in %qD call is the same "
2149 "expression as the destination; did you mean to "
2150 "remove the addressof?", callee
);
2151 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2152 == TYPE_PRECISION (char_type_node
))
2154 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2155 "argument to %<sizeof%> in %qD call is the same "
2156 "expression as the destination; did you mean to "
2157 "provide an explicit length?", callee
);
2159 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2160 "argument to %<sizeof%> in %qD call is the same "
2161 "expression as the destination; did you mean to "
2162 "dereference it?", callee
);
2166 if (POINTER_TYPE_P (TREE_TYPE (dest
))
2168 && comp_types (TREE_TYPE (dest
), type
)
2169 && !VOID_TYPE_P (TREE_TYPE (type
)))
2171 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2172 "argument to %<sizeof%> in %qD call is the same "
2173 "pointer type %qT as the destination; expected %qT "
2174 "or an explicit length", callee
, TREE_TYPE (dest
),
2175 TREE_TYPE (TREE_TYPE (dest
)));
2182 if (!TYPE_P (sizeof_arg
[idx
])
2183 && operand_equal_p (src
, sizeof_arg
[idx
], 0)
2184 && comp_types (TREE_TYPE (src
), type
))
2186 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2187 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2188 "argument to %<sizeof%> in %qD call is the same "
2189 "expression as the source; did you mean to "
2190 "remove the addressof?", callee
);
2191 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2192 == TYPE_PRECISION (char_type_node
))
2194 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2195 "argument to %<sizeof%> in %qD call is the same "
2196 "expression as the source; did you mean to "
2197 "provide an explicit length?", callee
);
2199 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2200 "argument to %<sizeof%> in %qD call is the same "
2201 "expression as the source; did you mean to "
2202 "dereference it?", callee
);
2206 if (POINTER_TYPE_P (TREE_TYPE (src
))
2208 && comp_types (TREE_TYPE (src
), type
)
2209 && !VOID_TYPE_P (TREE_TYPE (type
)))
2211 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2212 "argument to %<sizeof%> in %qD call is the same "
2213 "pointer type %qT as the source; expected %qT "
2214 "or an explicit length", callee
, TREE_TYPE (src
),
2215 TREE_TYPE (TREE_TYPE (src
)));
2222 if (!TYPE_P (sizeof_arg
[idx
])
2223 && operand_equal_p (dest
, sizeof_arg
[idx
], 0)
2224 && comp_types (TREE_TYPE (dest
), type
))
2226 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2227 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2228 "argument to %<sizeof%> in %qD call is the same "
2229 "expression as the first source; did you mean to "
2230 "remove the addressof?", callee
);
2231 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2232 == TYPE_PRECISION (char_type_node
))
2234 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2235 "argument to %<sizeof%> in %qD call is the same "
2236 "expression as the first source; did you mean to "
2237 "provide an explicit length?", callee
);
2239 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2240 "argument to %<sizeof%> in %qD call is the same "
2241 "expression as the first source; did you mean to "
2242 "dereference it?", callee
);
2246 if (POINTER_TYPE_P (TREE_TYPE (dest
))
2248 && comp_types (TREE_TYPE (dest
), type
)
2249 && !VOID_TYPE_P (TREE_TYPE (type
)))
2251 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2252 "argument to %<sizeof%> in %qD call is the same "
2253 "pointer type %qT as the first source; expected %qT "
2254 "or an explicit length", callee
, TREE_TYPE (dest
),
2255 TREE_TYPE (TREE_TYPE (dest
)));
2262 if (!TYPE_P (sizeof_arg
[idx
])
2263 && operand_equal_p (src
, sizeof_arg
[idx
], 0)
2264 && comp_types (TREE_TYPE (src
), type
))
2266 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2267 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2268 "argument to %<sizeof%> in %qD call is the same "
2269 "expression as the second source; did you mean to "
2270 "remove the addressof?", callee
);
2271 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2272 == TYPE_PRECISION (char_type_node
))
2274 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2275 "argument to %<sizeof%> in %qD call is the same "
2276 "expression as the second source; did you mean to "
2277 "provide an explicit length?", callee
);
2279 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2280 "argument to %<sizeof%> in %qD call is the same "
2281 "expression as the second source; did you mean to "
2282 "dereference it?", callee
);
2286 if (POINTER_TYPE_P (TREE_TYPE (src
))
2288 && comp_types (TREE_TYPE (src
), type
)
2289 && !VOID_TYPE_P (TREE_TYPE (type
)))
2291 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2292 "argument to %<sizeof%> in %qD call is the same "
2293 "pointer type %qT as the second source; expected %qT "
2294 "or an explicit length", callee
, TREE_TYPE (src
),
2295 TREE_TYPE (TREE_TYPE (src
)));
2302 /* Warn for unlikely, improbable, or stupid DECL declarations
2306 check_main_parameter_types (tree decl
)
2308 function_args_iterator iter
;
2312 FOREACH_FUNCTION_ARGS (TREE_TYPE (decl
), type
, iter
)
2314 /* XXX void_type_node belies the abstraction. */
2315 if (type
== void_type_node
|| type
== error_mark_node
)
2319 if (TYPE_ATOMIC (t
))
2320 pedwarn (input_location
, OPT_Wmain
,
2321 "%<_Atomic%>-qualified parameter type %qT of %q+D",
2323 while (POINTER_TYPE_P (t
))
2326 if (TYPE_ATOMIC (t
))
2327 pedwarn (input_location
, OPT_Wmain
,
2328 "%<_Atomic%>-qualified parameter type %qT of %q+D",
2336 if (TYPE_MAIN_VARIANT (type
) != integer_type_node
)
2337 pedwarn (input_location
, OPT_Wmain
,
2338 "first argument of %q+D should be %<int%>", decl
);
2342 if (TREE_CODE (type
) != POINTER_TYPE
2343 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
2344 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
2346 pedwarn (input_location
, OPT_Wmain
,
2347 "second argument of %q+D should be %<char **%>", decl
);
2351 if (TREE_CODE (type
) != POINTER_TYPE
2352 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
2353 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
2355 pedwarn (input_location
, OPT_Wmain
,
2356 "third argument of %q+D should probably be "
2357 "%<char **%>", decl
);
2362 /* It is intentional that this message does not mention the third
2363 argument because it's only mentioned in an appendix of the
2365 if (argct
> 0 && (argct
< 2 || argct
> 3))
2366 pedwarn (input_location
, OPT_Wmain
,
2367 "%q+D takes only zero or two arguments", decl
);
2369 if (stdarg_p (TREE_TYPE (decl
)))
2370 pedwarn (input_location
, OPT_Wmain
,
2371 "%q+D declared as variadic function", decl
);
2374 /* vector_targets_convertible_p is used for vector pointer types. The
2375 callers perform various checks that the qualifiers are satisfactory,
2376 while OTOH vector_targets_convertible_p ignores the number of elements
2377 in the vectors. That's fine with vector pointers as we can consider,
2378 say, a vector of 8 elements as two consecutive vectors of 4 elements,
2379 and that does not require and conversion of the pointer values.
2380 In contrast, vector_types_convertible_p and
2381 vector_types_compatible_elements_p are used for vector value types. */
2382 /* True if pointers to distinct types T1 and T2 can be converted to
2383 each other without an explicit cast. Only returns true for opaque
2386 vector_targets_convertible_p (const_tree t1
, const_tree t2
)
2388 if (TREE_CODE (t1
) == VECTOR_TYPE
&& TREE_CODE (t2
) == VECTOR_TYPE
2389 && (TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2390 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2396 /* vector_types_convertible_p is used for vector value types.
2397 It could in principle call vector_targets_convertible_p as a subroutine,
2398 but then the check for vector type would be duplicated with its callers,
2399 and also the purpose of vector_targets_convertible_p would become
2401 Where vector_types_convertible_p returns true, a conversion might still be
2402 needed to make the types match.
2403 In contrast, vector_targets_convertible_p is used for vector pointer
2404 values, and vector_types_compatible_elements_p is used specifically
2405 in the context for binary operators, as a check if use is possible without
2407 /* True if vector types T1 and T2 can be converted to each other
2408 without an explicit cast. If EMIT_LAX_NOTE is true, and T1 and T2
2409 can only be converted with -flax-vector-conversions yet that is not
2410 in effect, emit a note telling the user about that option if such
2411 a note has not previously been emitted. */
2413 vector_types_convertible_p (const_tree t1
, const_tree t2
, bool emit_lax_note
)
2415 static bool emitted_lax_note
= false;
2416 bool convertible_lax
;
2418 if ((TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2419 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2423 (tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
))
2424 && (TREE_CODE (TREE_TYPE (t1
)) != REAL_TYPE
||
2425 TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
))
2426 && (INTEGRAL_TYPE_P (TREE_TYPE (t1
))
2427 == INTEGRAL_TYPE_P (TREE_TYPE (t2
))));
2429 if (!convertible_lax
|| flag_lax_vector_conversions
)
2430 return convertible_lax
;
2432 if (TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
)
2433 && lang_hooks
.types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
2436 if (emit_lax_note
&& !emitted_lax_note
)
2438 emitted_lax_note
= true;
2439 inform (input_location
, "use -flax-vector-conversions to permit "
2440 "conversions between vectors with differing "
2441 "element types or numbers of subparts");
2447 /* Build a VEC_PERM_EXPR if V0, V1 and MASK are not error_mark_nodes
2448 and have vector types, V0 has the same type as V1, and the number of
2449 elements of V0, V1, MASK is the same.
2451 In case V1 is a NULL_TREE it is assumed that __builtin_shuffle was
2452 called with two arguments. In this case implementation passes the
2453 first argument twice in order to share the same tree code. This fact
2454 could enable the mask-values being twice the vector length. This is
2455 an implementation accident and this semantics is not guaranteed to
2458 c_build_vec_perm_expr (location_t loc
, tree v0
, tree v1
, tree mask
,
2463 bool maybe_const
= false;
2464 bool two_arguments
= false;
2466 if (v1
== NULL_TREE
)
2468 two_arguments
= true;
2472 if (v0
== error_mark_node
|| v1
== error_mark_node
2473 || mask
== error_mark_node
)
2474 return error_mark_node
;
2476 if (TREE_CODE (TREE_TYPE (mask
)) != VECTOR_TYPE
2477 || TREE_CODE (TREE_TYPE (TREE_TYPE (mask
))) != INTEGER_TYPE
)
2480 error_at (loc
, "__builtin_shuffle last argument must "
2481 "be an integer vector");
2482 return error_mark_node
;
2485 if (TREE_CODE (TREE_TYPE (v0
)) != VECTOR_TYPE
2486 || TREE_CODE (TREE_TYPE (v1
)) != VECTOR_TYPE
)
2489 error_at (loc
, "__builtin_shuffle arguments must be vectors");
2490 return error_mark_node
;
2493 if (TYPE_MAIN_VARIANT (TREE_TYPE (v0
)) != TYPE_MAIN_VARIANT (TREE_TYPE (v1
)))
2496 error_at (loc
, "__builtin_shuffle argument vectors must be of "
2498 return error_mark_node
;
2501 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (v0
))
2502 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
))
2503 && TYPE_VECTOR_SUBPARTS (TREE_TYPE (v1
))
2504 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
)))
2507 error_at (loc
, "__builtin_shuffle number of elements of the "
2508 "argument vector(s) and the mask vector should "
2510 return error_mark_node
;
2513 if (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (v0
))))
2514 != GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (mask
)))))
2517 error_at (loc
, "__builtin_shuffle argument vector(s) inner type "
2518 "must have the same size as inner type of the mask");
2519 return error_mark_node
;
2522 if (!c_dialect_cxx ())
2524 /* Avoid C_MAYBE_CONST_EXPRs inside VEC_PERM_EXPR. */
2525 v0
= c_fully_fold (v0
, false, &maybe_const
);
2526 wrap
&= maybe_const
;
2529 v1
= v0
= save_expr (v0
);
2532 v1
= c_fully_fold (v1
, false, &maybe_const
);
2533 wrap
&= maybe_const
;
2536 mask
= c_fully_fold (mask
, false, &maybe_const
);
2537 wrap
&= maybe_const
;
2539 else if (two_arguments
)
2540 v1
= v0
= save_expr (v0
);
2542 ret
= build3_loc (loc
, VEC_PERM_EXPR
, TREE_TYPE (v0
), v0
, v1
, mask
);
2544 if (!c_dialect_cxx () && !wrap
)
2545 ret
= c_wrap_maybe_const (ret
, true);
2550 /* Like tree.c:get_narrower, but retain conversion from C++0x scoped enum
2551 to integral type. */
2554 c_common_get_narrower (tree op
, int *unsignedp_ptr
)
2556 op
= get_narrower (op
, unsignedp_ptr
);
2558 if (TREE_CODE (TREE_TYPE (op
)) == ENUMERAL_TYPE
2559 && ENUM_IS_SCOPED (TREE_TYPE (op
)))
2561 /* C++0x scoped enumerations don't implicitly convert to integral
2562 type; if we stripped an explicit conversion to a larger type we
2563 need to replace it so common_type will still work. */
2564 tree type
= c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op
)),
2565 TYPE_UNSIGNED (TREE_TYPE (op
)));
2566 op
= fold_convert (type
, op
);
2571 /* This is a helper function of build_binary_op.
2573 For certain operations if both args were extended from the same
2574 smaller type, do the arithmetic in that type and then extend.
2576 BITWISE indicates a bitwise operation.
2577 For them, this optimization is safe only if
2578 both args are zero-extended or both are sign-extended.
2579 Otherwise, we might change the result.
2580 Eg, (short)-1 | (unsigned short)-1 is (int)-1
2581 but calculated in (unsigned short) it would be (unsigned short)-1.
2584 shorten_binary_op (tree result_type
, tree op0
, tree op1
, bool bitwise
)
2586 int unsigned0
, unsigned1
;
2591 /* Cast OP0 and OP1 to RESULT_TYPE. Doing so prevents
2592 excessive narrowing when we call get_narrower below. For
2593 example, suppose that OP0 is of unsigned int extended
2594 from signed char and that RESULT_TYPE is long long int.
2595 If we explicitly cast OP0 to RESULT_TYPE, OP0 would look
2598 (long long int) (unsigned int) signed_char
2600 which get_narrower would narrow down to
2602 (unsigned int) signed char
2604 If we do not cast OP0 first, get_narrower would return
2605 signed_char, which is inconsistent with the case of the
2607 op0
= convert (result_type
, op0
);
2608 op1
= convert (result_type
, op1
);
2610 arg0
= c_common_get_narrower (op0
, &unsigned0
);
2611 arg1
= c_common_get_narrower (op1
, &unsigned1
);
2613 /* UNS is 1 if the operation to be done is an unsigned one. */
2614 uns
= TYPE_UNSIGNED (result_type
);
2616 /* Handle the case that OP0 (or OP1) does not *contain* a conversion
2617 but it *requires* conversion to FINAL_TYPE. */
2619 if ((TYPE_PRECISION (TREE_TYPE (op0
))
2620 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2621 && TREE_TYPE (op0
) != result_type
)
2622 unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2623 if ((TYPE_PRECISION (TREE_TYPE (op1
))
2624 == TYPE_PRECISION (TREE_TYPE (arg1
)))
2625 && TREE_TYPE (op1
) != result_type
)
2626 unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2628 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
2630 /* For bitwise operations, signedness of nominal type
2631 does not matter. Consider only how operands were extended. */
2635 /* Note that in all three cases below we refrain from optimizing
2636 an unsigned operation on sign-extended args.
2637 That would not be valid. */
2639 /* Both args variable: if both extended in same way
2640 from same width, do it in that width.
2641 Do it unsigned if args were zero-extended. */
2642 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
2643 < TYPE_PRECISION (result_type
))
2644 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2645 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2646 && unsigned0
== unsigned1
2647 && (unsigned0
|| !uns
))
2648 return c_common_signed_or_unsigned_type
2649 (unsigned0
, common_type (TREE_TYPE (arg0
), TREE_TYPE (arg1
)));
2651 else if (TREE_CODE (arg0
) == INTEGER_CST
2652 && (unsigned1
|| !uns
)
2653 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2654 < TYPE_PRECISION (result_type
))
2656 = c_common_signed_or_unsigned_type (unsigned1
,
2658 && !POINTER_TYPE_P (type
)
2659 && int_fits_type_p (arg0
, type
))
2662 else if (TREE_CODE (arg1
) == INTEGER_CST
2663 && (unsigned0
|| !uns
)
2664 && (TYPE_PRECISION (TREE_TYPE (arg0
))
2665 < TYPE_PRECISION (result_type
))
2667 = c_common_signed_or_unsigned_type (unsigned0
,
2669 && !POINTER_TYPE_P (type
)
2670 && int_fits_type_p (arg1
, type
))
2676 /* Checks if expression EXPR of real/integer type cannot be converted
2677 to the real/integer type TYPE. Function returns non-zero when:
2678 * EXPR is a constant which cannot be exactly converted to TYPE.
2679 * EXPR is not a constant and size of EXPR's type > than size of TYPE,
2680 for EXPR type and TYPE being both integers or both real.
2681 * EXPR is not a constant of real type and TYPE is an integer.
2682 * EXPR is not a constant of integer type which cannot be
2683 exactly converted to real type.
2684 Function allows conversions between types of different signedness and
2685 can return SAFE_CONVERSION (zero) in that case. Function can produce
2686 signedness warnings if PRODUCE_WARNS is true. */
2688 enum conversion_safety
2689 unsafe_conversion_p (location_t loc
, tree type
, tree expr
, bool produce_warns
)
2691 enum conversion_safety give_warning
= SAFE_CONVERSION
; /* is 0 or false */
2692 tree expr_type
= TREE_TYPE (expr
);
2693 loc
= expansion_point_location_if_in_system_header (loc
);
2695 if (TREE_CODE (expr
) == REAL_CST
|| TREE_CODE (expr
) == INTEGER_CST
)
2697 /* Warn for real constant that is not an exact integer converted
2699 if (TREE_CODE (expr_type
) == REAL_TYPE
2700 && TREE_CODE (type
) == INTEGER_TYPE
)
2702 if (!real_isinteger (TREE_REAL_CST_PTR (expr
), TYPE_MODE (expr_type
)))
2703 give_warning
= UNSAFE_REAL
;
2705 /* Warn for an integer constant that does not fit into integer type. */
2706 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2707 && TREE_CODE (type
) == INTEGER_TYPE
2708 && !int_fits_type_p (expr
, type
))
2710 if (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)
2711 && tree_int_cst_sgn (expr
) < 0)
2714 warning_at (loc
, OPT_Wsign_conversion
, "negative integer"
2715 " implicitly converted to unsigned type");
2717 else if (!TYPE_UNSIGNED (type
) && TYPE_UNSIGNED (expr_type
))
2720 warning_at (loc
, OPT_Wsign_conversion
, "conversion of unsigned"
2721 " constant value to negative integer");
2724 give_warning
= UNSAFE_OTHER
;
2726 else if (TREE_CODE (type
) == REAL_TYPE
)
2728 /* Warn for an integer constant that does not fit into real type. */
2729 if (TREE_CODE (expr_type
) == INTEGER_TYPE
)
2731 REAL_VALUE_TYPE a
= real_value_from_int_cst (0, expr
);
2732 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2733 give_warning
= UNSAFE_REAL
;
2735 /* Warn for a real constant that does not fit into a smaller
2737 else if (TREE_CODE (expr_type
) == REAL_TYPE
2738 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2740 REAL_VALUE_TYPE a
= TREE_REAL_CST (expr
);
2741 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2742 give_warning
= UNSAFE_REAL
;
2748 /* Warn for real types converted to integer types. */
2749 if (TREE_CODE (expr_type
) == REAL_TYPE
2750 && TREE_CODE (type
) == INTEGER_TYPE
)
2751 give_warning
= UNSAFE_REAL
;
2753 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2754 && TREE_CODE (type
) == INTEGER_TYPE
)
2756 /* Don't warn about unsigned char y = 0xff, x = (int) y; */
2757 expr
= get_unwidened (expr
, 0);
2758 expr_type
= TREE_TYPE (expr
);
2760 /* Don't warn for short y; short x = ((int)y & 0xff); */
2761 if (TREE_CODE (expr
) == BIT_AND_EXPR
2762 || TREE_CODE (expr
) == BIT_IOR_EXPR
2763 || TREE_CODE (expr
) == BIT_XOR_EXPR
)
2765 /* If both args were extended from a shortest type,
2766 use that type if that is safe. */
2767 expr_type
= shorten_binary_op (expr_type
,
2768 TREE_OPERAND (expr
, 0),
2769 TREE_OPERAND (expr
, 1),
2772 if (TREE_CODE (expr
) == BIT_AND_EXPR
)
2774 tree op0
= TREE_OPERAND (expr
, 0);
2775 tree op1
= TREE_OPERAND (expr
, 1);
2776 bool unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2777 bool unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2779 /* If one of the operands is a non-negative constant
2780 that fits in the target type, then the type of the
2781 other operand does not matter. */
2782 if ((TREE_CODE (op0
) == INTEGER_CST
2783 && int_fits_type_p (op0
, c_common_signed_type (type
))
2784 && int_fits_type_p (op0
, c_common_unsigned_type (type
)))
2785 || (TREE_CODE (op1
) == INTEGER_CST
2786 && int_fits_type_p (op1
, c_common_signed_type (type
))
2787 && int_fits_type_p (op1
,
2788 c_common_unsigned_type (type
))))
2789 return SAFE_CONVERSION
;
2790 /* If constant is unsigned and fits in the target
2791 type, then the result will also fit. */
2792 else if ((TREE_CODE (op0
) == INTEGER_CST
2794 && int_fits_type_p (op0
, type
))
2795 || (TREE_CODE (op1
) == INTEGER_CST
2797 && int_fits_type_p (op1
, type
)))
2798 return SAFE_CONVERSION
;
2801 /* Warn for integer types converted to smaller integer types. */
2802 if (TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2803 give_warning
= UNSAFE_OTHER
;
2805 /* When they are the same width but different signedness,
2806 then the value may change. */
2807 else if (((TYPE_PRECISION (type
) == TYPE_PRECISION (expr_type
)
2808 && TYPE_UNSIGNED (expr_type
) != TYPE_UNSIGNED (type
))
2809 /* Even when converted to a bigger type, if the type is
2810 unsigned but expr is signed, then negative values
2812 || (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)))
2814 warning_at (loc
, OPT_Wsign_conversion
, "conversion to %qT from %qT "
2815 "may change the sign of the result",
2819 /* Warn for integer types converted to real types if and only if
2820 all the range of values of the integer type cannot be
2821 represented by the real type. */
2822 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2823 && TREE_CODE (type
) == REAL_TYPE
)
2825 tree type_low_bound
, type_high_bound
;
2826 REAL_VALUE_TYPE real_low_bound
, real_high_bound
;
2828 /* Don't warn about char y = 0xff; float x = (int) y; */
2829 expr
= get_unwidened (expr
, 0);
2830 expr_type
= TREE_TYPE (expr
);
2832 type_low_bound
= TYPE_MIN_VALUE (expr_type
);
2833 type_high_bound
= TYPE_MAX_VALUE (expr_type
);
2834 real_low_bound
= real_value_from_int_cst (0, type_low_bound
);
2835 real_high_bound
= real_value_from_int_cst (0, type_high_bound
);
2837 if (!exact_real_truncate (TYPE_MODE (type
), &real_low_bound
)
2838 || !exact_real_truncate (TYPE_MODE (type
), &real_high_bound
))
2839 give_warning
= UNSAFE_OTHER
;
2842 /* Warn for real types converted to smaller real types. */
2843 else if (TREE_CODE (expr_type
) == REAL_TYPE
2844 && TREE_CODE (type
) == REAL_TYPE
2845 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2846 give_warning
= UNSAFE_REAL
;
2849 return give_warning
;
2852 /* Warns if the conversion of EXPR to TYPE may alter a value.
2853 This is a helper function for warnings_for_convert_and_check. */
2856 conversion_warning (location_t loc
, tree type
, tree expr
)
2858 tree expr_type
= TREE_TYPE (expr
);
2859 enum conversion_safety conversion_kind
;
2861 if (!warn_conversion
&& !warn_sign_conversion
&& !warn_float_conversion
)
2864 /* This may happen, because for LHS op= RHS we preevaluate
2865 RHS and create C_MAYBE_CONST_EXPR <SAVE_EXPR <RHS>>, which
2866 means we could no longer see the code of the EXPR. */
2867 if (TREE_CODE (expr
) == C_MAYBE_CONST_EXPR
)
2868 expr
= C_MAYBE_CONST_EXPR_EXPR (expr
);
2869 if (TREE_CODE (expr
) == SAVE_EXPR
)
2870 expr
= TREE_OPERAND (expr
, 0);
2872 switch (TREE_CODE (expr
))
2880 case TRUTH_ANDIF_EXPR
:
2881 case TRUTH_ORIF_EXPR
:
2882 case TRUTH_AND_EXPR
:
2884 case TRUTH_XOR_EXPR
:
2885 case TRUTH_NOT_EXPR
:
2886 /* Conversion from boolean to a signed:1 bit-field (which only
2887 can hold the values 0 and -1) doesn't lose information - but
2888 it does change the value. */
2889 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
2890 warning_at (loc
, OPT_Wconversion
,
2891 "conversion to %qT from boolean expression", type
);
2896 conversion_kind
= unsafe_conversion_p (loc
, type
, expr
, true);
2897 if (conversion_kind
== UNSAFE_REAL
)
2898 warning_at (loc
, OPT_Wfloat_conversion
,
2899 "conversion to %qT alters %qT constant value",
2901 else if (conversion_kind
)
2902 warning_at (loc
, OPT_Wconversion
,
2903 "conversion to %qT alters %qT constant value",
2909 /* In case of COND_EXPR, we do not care about the type of
2910 COND_EXPR, only about the conversion of each operand. */
2911 tree op1
= TREE_OPERAND (expr
, 1);
2912 tree op2
= TREE_OPERAND (expr
, 2);
2914 conversion_warning (loc
, type
, op1
);
2915 conversion_warning (loc
, type
, op2
);
2919 default: /* 'expr' is not a constant. */
2920 conversion_kind
= unsafe_conversion_p (loc
, type
, expr
, true);
2921 if (conversion_kind
== UNSAFE_REAL
)
2922 warning_at (loc
, OPT_Wfloat_conversion
,
2923 "conversion to %qT from %qT may alter its value",
2925 else if (conversion_kind
)
2926 warning_at (loc
, OPT_Wconversion
,
2927 "conversion to %qT from %qT may alter its value",
2932 /* Produce warnings after a conversion. RESULT is the result of
2933 converting EXPR to TYPE. This is a helper function for
2934 convert_and_check and cp_convert_and_check. */
2937 warnings_for_convert_and_check (location_t loc
, tree type
, tree expr
,
2940 loc
= expansion_point_location_if_in_system_header (loc
);
2942 if (TREE_CODE (expr
) == INTEGER_CST
2943 && (TREE_CODE (type
) == INTEGER_TYPE
2944 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2945 && !int_fits_type_p (expr
, type
))
2947 /* Do not diagnose overflow in a constant expression merely
2948 because a conversion overflowed. */
2949 if (TREE_OVERFLOW (result
))
2950 TREE_OVERFLOW (result
) = TREE_OVERFLOW (expr
);
2952 if (TYPE_UNSIGNED (type
))
2954 /* This detects cases like converting -129 or 256 to
2956 if (!int_fits_type_p (expr
, c_common_signed_type (type
)))
2957 warning_at (loc
, OPT_Woverflow
,
2958 "large integer implicitly truncated to unsigned type");
2960 conversion_warning (loc
, type
, expr
);
2962 else if (!int_fits_type_p (expr
, c_common_unsigned_type (type
)))
2963 warning_at (loc
, OPT_Woverflow
,
2964 "overflow in implicit constant conversion");
2965 /* No warning for converting 0x80000000 to int. */
2967 && (TREE_CODE (TREE_TYPE (expr
)) != INTEGER_TYPE
2968 || TYPE_PRECISION (TREE_TYPE (expr
))
2969 != TYPE_PRECISION (type
)))
2970 warning_at (loc
, OPT_Woverflow
,
2971 "overflow in implicit constant conversion");
2974 conversion_warning (loc
, type
, expr
);
2976 else if ((TREE_CODE (result
) == INTEGER_CST
2977 || TREE_CODE (result
) == FIXED_CST
) && TREE_OVERFLOW (result
))
2978 warning_at (loc
, OPT_Woverflow
,
2979 "overflow in implicit constant conversion");
2981 conversion_warning (loc
, type
, expr
);
2985 /* Convert EXPR to TYPE, warning about conversion problems with constants.
2986 Invoke this function on every expression that is converted implicitly,
2987 i.e. because of language rules and not because of an explicit cast. */
2990 convert_and_check (location_t loc
, tree type
, tree expr
)
2993 tree expr_for_warning
;
2995 /* Convert from a value with possible excess precision rather than
2996 via the semantic type, but do not warn about values not fitting
2997 exactly in the semantic type. */
2998 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
3000 tree orig_type
= TREE_TYPE (expr
);
3001 expr
= TREE_OPERAND (expr
, 0);
3002 expr_for_warning
= convert (orig_type
, expr
);
3003 if (orig_type
== type
)
3004 return expr_for_warning
;
3007 expr_for_warning
= expr
;
3009 if (TREE_TYPE (expr
) == type
)
3012 result
= convert (type
, expr
);
3014 if (c_inhibit_evaluation_warnings
== 0
3015 && !TREE_OVERFLOW_P (expr
)
3016 && result
!= error_mark_node
)
3017 warnings_for_convert_and_check (loc
, type
, expr_for_warning
, result
);
3022 /* A node in a list that describes references to variables (EXPR), which are
3023 either read accesses if WRITER is zero, or write accesses, in which case
3024 WRITER is the parent of EXPR. */
3031 /* Used to implement a cache the results of a call to verify_tree. We only
3032 use this for SAVE_EXPRs. */
3035 struct tlist_cache
*next
;
3036 struct tlist
*cache_before_sp
;
3037 struct tlist
*cache_after_sp
;
3041 /* Obstack to use when allocating tlist structures, and corresponding
3043 static struct obstack tlist_obstack
;
3044 static char *tlist_firstobj
= 0;
3046 /* Keep track of the identifiers we've warned about, so we can avoid duplicate
3048 static struct tlist
*warned_ids
;
3049 /* SAVE_EXPRs need special treatment. We process them only once and then
3050 cache the results. */
3051 static struct tlist_cache
*save_expr_cache
;
3053 static void add_tlist (struct tlist
**, struct tlist
*, tree
, int);
3054 static void merge_tlist (struct tlist
**, struct tlist
*, int);
3055 static void verify_tree (tree
, struct tlist
**, struct tlist
**, tree
);
3056 static int warning_candidate_p (tree
);
3057 static bool candidate_equal_p (const_tree
, const_tree
);
3058 static void warn_for_collisions (struct tlist
*);
3059 static void warn_for_collisions_1 (tree
, tree
, struct tlist
*, int);
3060 static struct tlist
*new_tlist (struct tlist
*, tree
, tree
);
3062 /* Create a new struct tlist and fill in its fields. */
3063 static struct tlist
*
3064 new_tlist (struct tlist
*next
, tree t
, tree writer
)
3067 l
= XOBNEW (&tlist_obstack
, struct tlist
);
3074 /* Add duplicates of the nodes found in ADD to the list *TO. If EXCLUDE_WRITER
3075 is nonnull, we ignore any node we find which has a writer equal to it. */
3078 add_tlist (struct tlist
**to
, struct tlist
*add
, tree exclude_writer
, int copy
)
3082 struct tlist
*next
= add
->next
;
3085 if (!exclude_writer
|| !candidate_equal_p (add
->writer
, exclude_writer
))
3086 *to
= copy
? new_tlist (*to
, add
->expr
, add
->writer
) : add
;
3091 /* Merge the nodes of ADD into TO. This merging process is done so that for
3092 each variable that already exists in TO, no new node is added; however if
3093 there is a write access recorded in ADD, and an occurrence on TO is only
3094 a read access, then the occurrence in TO will be modified to record the
3098 merge_tlist (struct tlist
**to
, struct tlist
*add
, int copy
)
3100 struct tlist
**end
= to
;
3103 end
= &(*end
)->next
;
3109 struct tlist
*next
= add
->next
;
3111 for (tmp2
= *to
; tmp2
; tmp2
= tmp2
->next
)
3112 if (candidate_equal_p (tmp2
->expr
, add
->expr
))
3116 tmp2
->writer
= add
->writer
;
3120 *end
= copy
? new_tlist (NULL
, add
->expr
, add
->writer
) : add
;
3121 end
= &(*end
)->next
;
3128 /* WRITTEN is a variable, WRITER is its parent. Warn if any of the variable
3129 references in list LIST conflict with it, excluding reads if ONLY writers
3133 warn_for_collisions_1 (tree written
, tree writer
, struct tlist
*list
,
3138 /* Avoid duplicate warnings. */
3139 for (tmp
= warned_ids
; tmp
; tmp
= tmp
->next
)
3140 if (candidate_equal_p (tmp
->expr
, written
))
3145 if (candidate_equal_p (list
->expr
, written
)
3146 && !candidate_equal_p (list
->writer
, writer
)
3147 && (!only_writes
|| list
->writer
))
3149 warned_ids
= new_tlist (warned_ids
, written
, NULL_TREE
);
3150 warning_at (EXPR_LOC_OR_LOC (writer
, input_location
),
3151 OPT_Wsequence_point
, "operation on %qE may be undefined",
3158 /* Given a list LIST of references to variables, find whether any of these
3159 can cause conflicts due to missing sequence points. */
3162 warn_for_collisions (struct tlist
*list
)
3166 for (tmp
= list
; tmp
; tmp
= tmp
->next
)
3169 warn_for_collisions_1 (tmp
->expr
, tmp
->writer
, list
, 0);
3173 /* Return nonzero if X is a tree that can be verified by the sequence point
3176 warning_candidate_p (tree x
)
3178 if (DECL_P (x
) && DECL_ARTIFICIAL (x
))
3181 if (TREE_CODE (x
) == BLOCK
)
3184 /* VOID_TYPE_P (TREE_TYPE (x)) is workaround for cp/tree.c
3185 (lvalue_p) crash on TRY/CATCH. */
3186 if (TREE_TYPE (x
) == NULL_TREE
|| VOID_TYPE_P (TREE_TYPE (x
)))
3192 /* No point to track non-const calls, they will never satisfy
3194 if (TREE_CODE (x
) == CALL_EXPR
&& (call_expr_flags (x
) & ECF_CONST
) == 0)
3197 if (TREE_CODE (x
) == STRING_CST
)
3203 /* Return nonzero if X and Y appear to be the same candidate (or NULL) */
3205 candidate_equal_p (const_tree x
, const_tree y
)
3207 return (x
== y
) || (x
&& y
&& operand_equal_p (x
, y
, 0));
3210 /* Walk the tree X, and record accesses to variables. If X is written by the
3211 parent tree, WRITER is the parent.
3212 We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP. If this
3213 expression or its only operand forces a sequence point, then everything up
3214 to the sequence point is stored in PBEFORE_SP. Everything else gets stored
3216 Once we return, we will have emitted warnings if any subexpression before
3217 such a sequence point could be undefined. On a higher level, however, the
3218 sequence point may not be relevant, and we'll merge the two lists.
3220 Example: (b++, a) + b;
3221 The call that processes the COMPOUND_EXPR will store the increment of B
3222 in PBEFORE_SP, and the use of A in PNO_SP. The higher-level call that
3223 processes the PLUS_EXPR will need to merge the two lists so that
3224 eventually, all accesses end up on the same list (and we'll warn about the
3225 unordered subexpressions b++ and b.
3227 A note on merging. If we modify the former example so that our expression
3230 care must be taken not simply to add all three expressions into the final
3231 PNO_SP list. The function merge_tlist takes care of that by merging the
3232 before-SP list of the COMPOUND_EXPR into its after-SP list in a special
3233 way, so that no more than one access to B is recorded. */
3236 verify_tree (tree x
, struct tlist
**pbefore_sp
, struct tlist
**pno_sp
,
3239 struct tlist
*tmp_before
, *tmp_nosp
, *tmp_list2
, *tmp_list3
;
3240 enum tree_code code
;
3241 enum tree_code_class cl
;
3243 /* X may be NULL if it is the operand of an empty statement expression
3249 code
= TREE_CODE (x
);
3250 cl
= TREE_CODE_CLASS (code
);
3252 if (warning_candidate_p (x
))
3253 *pno_sp
= new_tlist (*pno_sp
, x
, writer
);
3262 case TRUTH_ANDIF_EXPR
:
3263 case TRUTH_ORIF_EXPR
:
3264 tmp_before
= tmp_nosp
= tmp_list3
= 0;
3265 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3266 warn_for_collisions (tmp_nosp
);
3267 merge_tlist (pbefore_sp
, tmp_before
, 0);
3268 merge_tlist (pbefore_sp
, tmp_nosp
, 0);
3269 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, pno_sp
, NULL_TREE
);
3270 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3274 tmp_before
= tmp_list2
= 0;
3275 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_list2
, NULL_TREE
);
3276 warn_for_collisions (tmp_list2
);
3277 merge_tlist (pbefore_sp
, tmp_before
, 0);
3278 merge_tlist (pbefore_sp
, tmp_list2
, 0);
3280 tmp_list3
= tmp_nosp
= 0;
3281 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, &tmp_nosp
, NULL_TREE
);
3282 warn_for_collisions (tmp_nosp
);
3283 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3285 tmp_list3
= tmp_list2
= 0;
3286 verify_tree (TREE_OPERAND (x
, 2), &tmp_list3
, &tmp_list2
, NULL_TREE
);
3287 warn_for_collisions (tmp_list2
);
3288 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3289 /* Rather than add both tmp_nosp and tmp_list2, we have to merge the
3290 two first, to avoid warning for (a ? b++ : b++). */
3291 merge_tlist (&tmp_nosp
, tmp_list2
, 0);
3292 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3295 case PREDECREMENT_EXPR
:
3296 case PREINCREMENT_EXPR
:
3297 case POSTDECREMENT_EXPR
:
3298 case POSTINCREMENT_EXPR
:
3299 verify_tree (TREE_OPERAND (x
, 0), pno_sp
, pno_sp
, x
);
3303 tmp_before
= tmp_nosp
= tmp_list3
= 0;
3304 verify_tree (TREE_OPERAND (x
, 1), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3305 verify_tree (TREE_OPERAND (x
, 0), &tmp_list3
, &tmp_list3
, x
);
3306 /* Expressions inside the LHS are not ordered wrt. the sequence points
3307 in the RHS. Example:
3309 Despite the fact that the modification of "a" is in the before_sp
3310 list (tmp_before), it conflicts with the use of "a" in the LHS.
3311 We can handle this by adding the contents of tmp_list3
3312 to those of tmp_before, and redoing the collision warnings for that
3314 add_tlist (&tmp_before
, tmp_list3
, x
, 1);
3315 warn_for_collisions (tmp_before
);
3316 /* Exclude the LHS itself here; we first have to merge it into the
3317 tmp_nosp list. This is done to avoid warning for "a = a"; if we
3318 didn't exclude the LHS, we'd get it twice, once as a read and once
3320 add_tlist (pno_sp
, tmp_list3
, x
, 0);
3321 warn_for_collisions_1 (TREE_OPERAND (x
, 0), x
, tmp_nosp
, 1);
3323 merge_tlist (pbefore_sp
, tmp_before
, 0);
3324 if (warning_candidate_p (TREE_OPERAND (x
, 0)))
3325 merge_tlist (&tmp_nosp
, new_tlist (NULL
, TREE_OPERAND (x
, 0), x
), 0);
3326 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 1);
3330 /* We need to warn about conflicts among arguments and conflicts between
3331 args and the function address. Side effects of the function address,
3332 however, are not ordered by the sequence point of the call. */
3334 call_expr_arg_iterator iter
;
3336 tmp_before
= tmp_nosp
= 0;
3337 verify_tree (CALL_EXPR_FN (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3338 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, x
)
3340 tmp_list2
= tmp_list3
= 0;
3341 verify_tree (arg
, &tmp_list2
, &tmp_list3
, NULL_TREE
);
3342 merge_tlist (&tmp_list3
, tmp_list2
, 0);
3343 add_tlist (&tmp_before
, tmp_list3
, NULL_TREE
, 0);
3345 add_tlist (&tmp_before
, tmp_nosp
, NULL_TREE
, 0);
3346 warn_for_collisions (tmp_before
);
3347 add_tlist (pbefore_sp
, tmp_before
, NULL_TREE
, 0);
3352 /* Scan all the list, e.g. indices of multi dimensional array. */
3355 tmp_before
= tmp_nosp
= 0;
3356 verify_tree (TREE_VALUE (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3357 merge_tlist (&tmp_nosp
, tmp_before
, 0);
3358 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3365 struct tlist_cache
*t
;
3366 for (t
= save_expr_cache
; t
; t
= t
->next
)
3367 if (candidate_equal_p (t
->expr
, x
))
3372 t
= XOBNEW (&tlist_obstack
, struct tlist_cache
);
3373 t
->next
= save_expr_cache
;
3375 save_expr_cache
= t
;
3377 tmp_before
= tmp_nosp
= 0;
3378 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3379 warn_for_collisions (tmp_nosp
);
3382 merge_tlist (&tmp_list3
, tmp_nosp
, 0);
3383 t
->cache_before_sp
= tmp_before
;
3384 t
->cache_after_sp
= tmp_list3
;
3386 merge_tlist (pbefore_sp
, t
->cache_before_sp
, 1);
3387 add_tlist (pno_sp
, t
->cache_after_sp
, NULL_TREE
, 1);
3392 x
= TREE_OPERAND (x
, 0);
3399 /* For other expressions, simply recurse on their operands.
3400 Manual tail recursion for unary expressions.
3401 Other non-expressions need not be processed. */
3402 if (cl
== tcc_unary
)
3404 x
= TREE_OPERAND (x
, 0);
3408 else if (IS_EXPR_CODE_CLASS (cl
))
3411 int max
= TREE_OPERAND_LENGTH (x
);
3412 for (lp
= 0; lp
< max
; lp
++)
3414 tmp_before
= tmp_nosp
= 0;
3415 verify_tree (TREE_OPERAND (x
, lp
), &tmp_before
, &tmp_nosp
, 0);
3416 merge_tlist (&tmp_nosp
, tmp_before
, 0);
3417 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3424 /* Try to warn for undefined behavior in EXPR due to missing sequence
3428 verify_sequence_points (tree expr
)
3430 struct tlist
*before_sp
= 0, *after_sp
= 0;
3433 save_expr_cache
= 0;
3434 if (tlist_firstobj
== 0)
3436 gcc_obstack_init (&tlist_obstack
);
3437 tlist_firstobj
= (char *) obstack_alloc (&tlist_obstack
, 0);
3440 verify_tree (expr
, &before_sp
, &after_sp
, 0);
3441 warn_for_collisions (after_sp
);
3442 obstack_free (&tlist_obstack
, tlist_firstobj
);
3445 /* Validate the expression after `case' and apply default promotions. */
3448 check_case_value (location_t loc
, tree value
)
3450 if (value
== NULL_TREE
)
3453 if (TREE_CODE (value
) == INTEGER_CST
)
3454 /* Promote char or short to int. */
3455 value
= perform_integral_promotions (value
);
3456 else if (value
!= error_mark_node
)
3458 error_at (loc
, "case label does not reduce to an integer constant");
3459 value
= error_mark_node
;
3462 constant_expression_warning (value
);
3467 /* See if the case values LOW and HIGH are in the range of the original
3468 type (i.e. before the default conversion to int) of the switch testing
3470 TYPE is the promoted type of the testing expression, and ORIG_TYPE is
3471 the type before promoting it. CASE_LOW_P is a pointer to the lower
3472 bound of the case label, and CASE_HIGH_P is the upper bound or NULL
3473 if the case is not a case range.
3474 The caller has to make sure that we are not called with NULL for
3475 CASE_LOW_P (i.e. the default case).
3476 Returns true if the case label is in range of ORIG_TYPE (saturated or
3477 untouched) or false if the label is out of range. */
3480 check_case_bounds (location_t loc
, tree type
, tree orig_type
,
3481 tree
*case_low_p
, tree
*case_high_p
)
3483 tree min_value
, max_value
;
3484 tree case_low
= *case_low_p
;
3485 tree case_high
= case_high_p
? *case_high_p
: case_low
;
3487 /* If there was a problem with the original type, do nothing. */
3488 if (orig_type
== error_mark_node
)
3491 min_value
= TYPE_MIN_VALUE (orig_type
);
3492 max_value
= TYPE_MAX_VALUE (orig_type
);
3494 /* Case label is less than minimum for type. */
3495 if (tree_int_cst_compare (case_low
, min_value
) < 0
3496 && tree_int_cst_compare (case_high
, min_value
) < 0)
3498 warning_at (loc
, 0, "case label value is less than minimum value "
3503 /* Case value is greater than maximum for type. */
3504 if (tree_int_cst_compare (case_low
, max_value
) > 0
3505 && tree_int_cst_compare (case_high
, max_value
) > 0)
3507 warning_at (loc
, 0, "case label value exceeds maximum value for type");
3511 /* Saturate lower case label value to minimum. */
3512 if (tree_int_cst_compare (case_high
, min_value
) >= 0
3513 && tree_int_cst_compare (case_low
, min_value
) < 0)
3515 warning_at (loc
, 0, "lower value in case label range"
3516 " less than minimum value for type");
3517 case_low
= min_value
;
3520 /* Saturate upper case label value to maximum. */
3521 if (tree_int_cst_compare (case_low
, max_value
) <= 0
3522 && tree_int_cst_compare (case_high
, max_value
) > 0)
3524 warning_at (loc
, 0, "upper value in case label range"
3525 " exceeds maximum value for type");
3526 case_high
= max_value
;
3529 if (*case_low_p
!= case_low
)
3530 *case_low_p
= convert (type
, case_low
);
3531 if (case_high_p
&& *case_high_p
!= case_high
)
3532 *case_high_p
= convert (type
, case_high
);
3537 /* Return an integer type with BITS bits of precision,
3538 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
3541 c_common_type_for_size (unsigned int bits
, int unsignedp
)
3545 if (bits
== TYPE_PRECISION (integer_type_node
))
3546 return unsignedp
? unsigned_type_node
: integer_type_node
;
3548 if (bits
== TYPE_PRECISION (signed_char_type_node
))
3549 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3551 if (bits
== TYPE_PRECISION (short_integer_type_node
))
3552 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3554 if (bits
== TYPE_PRECISION (long_integer_type_node
))
3555 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3557 if (bits
== TYPE_PRECISION (long_long_integer_type_node
))
3558 return (unsignedp
? long_long_unsigned_type_node
3559 : long_long_integer_type_node
);
3561 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
3562 if (int_n_enabled_p
[i
]
3563 && bits
== int_n_data
[i
].bitsize
)
3564 return (unsignedp
? int_n_trees
[i
].unsigned_type
3565 : int_n_trees
[i
].signed_type
);
3567 if (bits
== TYPE_PRECISION (widest_integer_literal_type_node
))
3568 return (unsignedp
? widest_unsigned_literal_type_node
3569 : widest_integer_literal_type_node
);
3571 if (bits
<= TYPE_PRECISION (intQI_type_node
))
3572 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3574 if (bits
<= TYPE_PRECISION (intHI_type_node
))
3575 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3577 if (bits
<= TYPE_PRECISION (intSI_type_node
))
3578 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3580 if (bits
<= TYPE_PRECISION (intDI_type_node
))
3581 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3586 /* Return a fixed-point type that has at least IBIT ibits and FBIT fbits
3587 that is unsigned if UNSIGNEDP is nonzero, otherwise signed;
3588 and saturating if SATP is nonzero, otherwise not saturating. */
3591 c_common_fixed_point_type_for_size (unsigned int ibit
, unsigned int fbit
,
3592 int unsignedp
, int satp
)
3596 mode
= unsignedp
? UQQmode
: QQmode
;
3598 mode
= unsignedp
? UHAmode
: HAmode
;
3600 for (; mode
!= VOIDmode
; mode
= GET_MODE_WIDER_MODE (mode
))
3601 if (GET_MODE_IBIT (mode
) >= ibit
&& GET_MODE_FBIT (mode
) >= fbit
)
3604 if (mode
== VOIDmode
|| !targetm
.scalar_mode_supported_p (mode
))
3606 sorry ("GCC cannot support operators with integer types and "
3607 "fixed-point types that have too many integral and "
3608 "fractional bits together");
3612 return c_common_type_for_mode (mode
, satp
);
3615 /* Used for communication between c_common_type_for_mode and
3616 c_register_builtin_type. */
3617 tree registered_builtin_types
;
3619 /* Return a data type that has machine mode MODE.
3620 If the mode is an integer,
3621 then UNSIGNEDP selects between signed and unsigned types.
3622 If the mode is a fixed-point mode,
3623 then UNSIGNEDP selects between saturating and nonsaturating types. */
3626 c_common_type_for_mode (machine_mode mode
, int unsignedp
)
3631 if (mode
== TYPE_MODE (integer_type_node
))
3632 return unsignedp
? unsigned_type_node
: integer_type_node
;
3634 if (mode
== TYPE_MODE (signed_char_type_node
))
3635 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3637 if (mode
== TYPE_MODE (short_integer_type_node
))
3638 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3640 if (mode
== TYPE_MODE (long_integer_type_node
))
3641 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3643 if (mode
== TYPE_MODE (long_long_integer_type_node
))
3644 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3646 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
3647 if (int_n_enabled_p
[i
]
3648 && mode
== int_n_data
[i
].m
)
3649 return (unsignedp
? int_n_trees
[i
].unsigned_type
3650 : int_n_trees
[i
].signed_type
);
3652 if (mode
== TYPE_MODE (widest_integer_literal_type_node
))
3653 return unsignedp
? widest_unsigned_literal_type_node
3654 : widest_integer_literal_type_node
;
3657 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3660 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3663 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3666 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3668 #if HOST_BITS_PER_WIDE_INT >= 64
3669 if (mode
== TYPE_MODE (intTI_type_node
))
3670 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3673 if (mode
== TYPE_MODE (float_type_node
))
3674 return float_type_node
;
3676 if (mode
== TYPE_MODE (double_type_node
))
3677 return double_type_node
;
3679 if (mode
== TYPE_MODE (long_double_type_node
))
3680 return long_double_type_node
;
3682 if (mode
== TYPE_MODE (void_type_node
))
3683 return void_type_node
;
3685 if (mode
== TYPE_MODE (build_pointer_type (char_type_node
)))
3687 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3688 : make_signed_type (GET_MODE_PRECISION (mode
)));
3690 if (mode
== TYPE_MODE (build_pointer_type (integer_type_node
)))
3692 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3693 : make_signed_type (GET_MODE_PRECISION (mode
)));
3695 if (COMPLEX_MODE_P (mode
))
3697 machine_mode inner_mode
;
3700 if (mode
== TYPE_MODE (complex_float_type_node
))
3701 return complex_float_type_node
;
3702 if (mode
== TYPE_MODE (complex_double_type_node
))
3703 return complex_double_type_node
;
3704 if (mode
== TYPE_MODE (complex_long_double_type_node
))
3705 return complex_long_double_type_node
;
3707 if (mode
== TYPE_MODE (complex_integer_type_node
) && !unsignedp
)
3708 return complex_integer_type_node
;
3710 inner_mode
= GET_MODE_INNER (mode
);
3711 inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3712 if (inner_type
!= NULL_TREE
)
3713 return build_complex_type (inner_type
);
3715 else if (VECTOR_MODE_P (mode
))
3717 machine_mode inner_mode
= GET_MODE_INNER (mode
);
3718 tree inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3719 if (inner_type
!= NULL_TREE
)
3720 return build_vector_type_for_mode (inner_type
, mode
);
3723 if (mode
== TYPE_MODE (dfloat32_type_node
))
3724 return dfloat32_type_node
;
3725 if (mode
== TYPE_MODE (dfloat64_type_node
))
3726 return dfloat64_type_node
;
3727 if (mode
== TYPE_MODE (dfloat128_type_node
))
3728 return dfloat128_type_node
;
3730 if (ALL_SCALAR_FIXED_POINT_MODE_P (mode
))
3732 if (mode
== TYPE_MODE (short_fract_type_node
))
3733 return unsignedp
? sat_short_fract_type_node
: short_fract_type_node
;
3734 if (mode
== TYPE_MODE (fract_type_node
))
3735 return unsignedp
? sat_fract_type_node
: fract_type_node
;
3736 if (mode
== TYPE_MODE (long_fract_type_node
))
3737 return unsignedp
? sat_long_fract_type_node
: long_fract_type_node
;
3738 if (mode
== TYPE_MODE (long_long_fract_type_node
))
3739 return unsignedp
? sat_long_long_fract_type_node
3740 : long_long_fract_type_node
;
3742 if (mode
== TYPE_MODE (unsigned_short_fract_type_node
))
3743 return unsignedp
? sat_unsigned_short_fract_type_node
3744 : unsigned_short_fract_type_node
;
3745 if (mode
== TYPE_MODE (unsigned_fract_type_node
))
3746 return unsignedp
? sat_unsigned_fract_type_node
3747 : unsigned_fract_type_node
;
3748 if (mode
== TYPE_MODE (unsigned_long_fract_type_node
))
3749 return unsignedp
? sat_unsigned_long_fract_type_node
3750 : unsigned_long_fract_type_node
;
3751 if (mode
== TYPE_MODE (unsigned_long_long_fract_type_node
))
3752 return unsignedp
? sat_unsigned_long_long_fract_type_node
3753 : unsigned_long_long_fract_type_node
;
3755 if (mode
== TYPE_MODE (short_accum_type_node
))
3756 return unsignedp
? sat_short_accum_type_node
: short_accum_type_node
;
3757 if (mode
== TYPE_MODE (accum_type_node
))
3758 return unsignedp
? sat_accum_type_node
: accum_type_node
;
3759 if (mode
== TYPE_MODE (long_accum_type_node
))
3760 return unsignedp
? sat_long_accum_type_node
: long_accum_type_node
;
3761 if (mode
== TYPE_MODE (long_long_accum_type_node
))
3762 return unsignedp
? sat_long_long_accum_type_node
3763 : long_long_accum_type_node
;
3765 if (mode
== TYPE_MODE (unsigned_short_accum_type_node
))
3766 return unsignedp
? sat_unsigned_short_accum_type_node
3767 : unsigned_short_accum_type_node
;
3768 if (mode
== TYPE_MODE (unsigned_accum_type_node
))
3769 return unsignedp
? sat_unsigned_accum_type_node
3770 : unsigned_accum_type_node
;
3771 if (mode
== TYPE_MODE (unsigned_long_accum_type_node
))
3772 return unsignedp
? sat_unsigned_long_accum_type_node
3773 : unsigned_long_accum_type_node
;
3774 if (mode
== TYPE_MODE (unsigned_long_long_accum_type_node
))
3775 return unsignedp
? sat_unsigned_long_long_accum_type_node
3776 : unsigned_long_long_accum_type_node
;
3779 return unsignedp
? sat_qq_type_node
: qq_type_node
;
3781 return unsignedp
? sat_hq_type_node
: hq_type_node
;
3783 return unsignedp
? sat_sq_type_node
: sq_type_node
;
3785 return unsignedp
? sat_dq_type_node
: dq_type_node
;
3787 return unsignedp
? sat_tq_type_node
: tq_type_node
;
3789 if (mode
== UQQmode
)
3790 return unsignedp
? sat_uqq_type_node
: uqq_type_node
;
3791 if (mode
== UHQmode
)
3792 return unsignedp
? sat_uhq_type_node
: uhq_type_node
;
3793 if (mode
== USQmode
)
3794 return unsignedp
? sat_usq_type_node
: usq_type_node
;
3795 if (mode
== UDQmode
)
3796 return unsignedp
? sat_udq_type_node
: udq_type_node
;
3797 if (mode
== UTQmode
)
3798 return unsignedp
? sat_utq_type_node
: utq_type_node
;
3801 return unsignedp
? sat_ha_type_node
: ha_type_node
;
3803 return unsignedp
? sat_sa_type_node
: sa_type_node
;
3805 return unsignedp
? sat_da_type_node
: da_type_node
;
3807 return unsignedp
? sat_ta_type_node
: ta_type_node
;
3809 if (mode
== UHAmode
)
3810 return unsignedp
? sat_uha_type_node
: uha_type_node
;
3811 if (mode
== USAmode
)
3812 return unsignedp
? sat_usa_type_node
: usa_type_node
;
3813 if (mode
== UDAmode
)
3814 return unsignedp
? sat_uda_type_node
: uda_type_node
;
3815 if (mode
== UTAmode
)
3816 return unsignedp
? sat_uta_type_node
: uta_type_node
;
3819 for (t
= registered_builtin_types
; t
; t
= TREE_CHAIN (t
))
3820 if (TYPE_MODE (TREE_VALUE (t
)) == mode
3821 && !!unsignedp
== !!TYPE_UNSIGNED (TREE_VALUE (t
)))
3822 return TREE_VALUE (t
);
3828 c_common_unsigned_type (tree type
)
3830 return c_common_signed_or_unsigned_type (1, type
);
3833 /* Return a signed type the same as TYPE in other respects. */
3836 c_common_signed_type (tree type
)
3838 return c_common_signed_or_unsigned_type (0, type
);
3841 /* Return a type the same as TYPE except unsigned or
3842 signed according to UNSIGNEDP. */
3845 c_common_signed_or_unsigned_type (int unsignedp
, tree type
)
3850 /* This block of code emulates the behavior of the old
3851 c_common_unsigned_type. In particular, it returns
3852 long_unsigned_type_node if passed a long, even when a int would
3853 have the same size. This is necessary for warnings to work
3854 correctly in archs where sizeof(int) == sizeof(long) */
3856 type1
= TYPE_MAIN_VARIANT (type
);
3857 if (type1
== signed_char_type_node
|| type1
== char_type_node
|| type1
== unsigned_char_type_node
)
3858 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3859 if (type1
== integer_type_node
|| type1
== unsigned_type_node
)
3860 return unsignedp
? unsigned_type_node
: integer_type_node
;
3861 if (type1
== short_integer_type_node
|| type1
== short_unsigned_type_node
)
3862 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3863 if (type1
== long_integer_type_node
|| type1
== long_unsigned_type_node
)
3864 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3865 if (type1
== long_long_integer_type_node
|| type1
== long_long_unsigned_type_node
)
3866 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3868 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
3869 if (int_n_enabled_p
[i
]
3870 && (type1
== int_n_trees
[i
].unsigned_type
3871 || type1
== int_n_trees
[i
].signed_type
))
3872 return (unsignedp
? int_n_trees
[i
].unsigned_type
3873 : int_n_trees
[i
].signed_type
);
3875 if (type1
== widest_integer_literal_type_node
|| type1
== widest_unsigned_literal_type_node
)
3876 return unsignedp
? widest_unsigned_literal_type_node
: widest_integer_literal_type_node
;
3877 #if HOST_BITS_PER_WIDE_INT >= 64
3878 if (type1
== intTI_type_node
|| type1
== unsigned_intTI_type_node
)
3879 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3881 if (type1
== intDI_type_node
|| type1
== unsigned_intDI_type_node
)
3882 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3883 if (type1
== intSI_type_node
|| type1
== unsigned_intSI_type_node
)
3884 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3885 if (type1
== intHI_type_node
|| type1
== unsigned_intHI_type_node
)
3886 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3887 if (type1
== intQI_type_node
|| type1
== unsigned_intQI_type_node
)
3888 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3890 #define C_COMMON_FIXED_TYPES(NAME) \
3891 if (type1 == short_ ## NAME ## _type_node \
3892 || type1 == unsigned_short_ ## NAME ## _type_node) \
3893 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
3894 : short_ ## NAME ## _type_node; \
3895 if (type1 == NAME ## _type_node \
3896 || type1 == unsigned_ ## NAME ## _type_node) \
3897 return unsignedp ? unsigned_ ## NAME ## _type_node \
3898 : NAME ## _type_node; \
3899 if (type1 == long_ ## NAME ## _type_node \
3900 || type1 == unsigned_long_ ## NAME ## _type_node) \
3901 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
3902 : long_ ## NAME ## _type_node; \
3903 if (type1 == long_long_ ## NAME ## _type_node \
3904 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
3905 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
3906 : long_long_ ## NAME ## _type_node;
3908 #define C_COMMON_FIXED_MODE_TYPES(NAME) \
3909 if (type1 == NAME ## _type_node \
3910 || type1 == u ## NAME ## _type_node) \
3911 return unsignedp ? u ## NAME ## _type_node \
3912 : NAME ## _type_node;
3914 #define C_COMMON_FIXED_TYPES_SAT(NAME) \
3915 if (type1 == sat_ ## short_ ## NAME ## _type_node \
3916 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
3917 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
3918 : sat_ ## short_ ## NAME ## _type_node; \
3919 if (type1 == sat_ ## NAME ## _type_node \
3920 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
3921 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
3922 : sat_ ## NAME ## _type_node; \
3923 if (type1 == sat_ ## long_ ## NAME ## _type_node \
3924 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
3925 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
3926 : sat_ ## long_ ## NAME ## _type_node; \
3927 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
3928 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
3929 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
3930 : sat_ ## long_long_ ## NAME ## _type_node;
3932 #define C_COMMON_FIXED_MODE_TYPES_SAT(NAME) \
3933 if (type1 == sat_ ## NAME ## _type_node \
3934 || type1 == sat_ ## u ## NAME ## _type_node) \
3935 return unsignedp ? sat_ ## u ## NAME ## _type_node \
3936 : sat_ ## NAME ## _type_node;
3938 C_COMMON_FIXED_TYPES (fract
);
3939 C_COMMON_FIXED_TYPES_SAT (fract
);
3940 C_COMMON_FIXED_TYPES (accum
);
3941 C_COMMON_FIXED_TYPES_SAT (accum
);
3943 C_COMMON_FIXED_MODE_TYPES (qq
);
3944 C_COMMON_FIXED_MODE_TYPES (hq
);
3945 C_COMMON_FIXED_MODE_TYPES (sq
);
3946 C_COMMON_FIXED_MODE_TYPES (dq
);
3947 C_COMMON_FIXED_MODE_TYPES (tq
);
3948 C_COMMON_FIXED_MODE_TYPES_SAT (qq
);
3949 C_COMMON_FIXED_MODE_TYPES_SAT (hq
);
3950 C_COMMON_FIXED_MODE_TYPES_SAT (sq
);
3951 C_COMMON_FIXED_MODE_TYPES_SAT (dq
);
3952 C_COMMON_FIXED_MODE_TYPES_SAT (tq
);
3953 C_COMMON_FIXED_MODE_TYPES (ha
);
3954 C_COMMON_FIXED_MODE_TYPES (sa
);
3955 C_COMMON_FIXED_MODE_TYPES (da
);
3956 C_COMMON_FIXED_MODE_TYPES (ta
);
3957 C_COMMON_FIXED_MODE_TYPES_SAT (ha
);
3958 C_COMMON_FIXED_MODE_TYPES_SAT (sa
);
3959 C_COMMON_FIXED_MODE_TYPES_SAT (da
);
3960 C_COMMON_FIXED_MODE_TYPES_SAT (ta
);
3962 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
3963 the precision; they have precision set to match their range, but
3964 may use a wider mode to match an ABI. If we change modes, we may
3965 wind up with bad conversions. For INTEGER_TYPEs in C, must check
3966 the precision as well, so as to yield correct results for
3967 bit-field types. C++ does not have these separate bit-field
3968 types, and producing a signed or unsigned variant of an
3969 ENUMERAL_TYPE may cause other problems as well. */
3971 if (!INTEGRAL_TYPE_P (type
)
3972 || TYPE_UNSIGNED (type
) == unsignedp
)
3975 #define TYPE_OK(node) \
3976 (TYPE_MODE (type) == TYPE_MODE (node) \
3977 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
3978 if (TYPE_OK (signed_char_type_node
))
3979 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3980 if (TYPE_OK (integer_type_node
))
3981 return unsignedp
? unsigned_type_node
: integer_type_node
;
3982 if (TYPE_OK (short_integer_type_node
))
3983 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3984 if (TYPE_OK (long_integer_type_node
))
3985 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3986 if (TYPE_OK (long_long_integer_type_node
))
3987 return (unsignedp
? long_long_unsigned_type_node
3988 : long_long_integer_type_node
);
3990 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
3991 if (int_n_enabled_p
[i
]
3992 && TYPE_MODE (type
) == int_n_data
[i
].m
3993 && TYPE_PRECISION (type
) == int_n_data
[i
].bitsize
)
3994 return (unsignedp
? int_n_trees
[i
].unsigned_type
3995 : int_n_trees
[i
].signed_type
);
3997 if (TYPE_OK (widest_integer_literal_type_node
))
3998 return (unsignedp
? widest_unsigned_literal_type_node
3999 : widest_integer_literal_type_node
);
4001 #if HOST_BITS_PER_WIDE_INT >= 64
4002 if (TYPE_OK (intTI_type_node
))
4003 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
4005 if (TYPE_OK (intDI_type_node
))
4006 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
4007 if (TYPE_OK (intSI_type_node
))
4008 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
4009 if (TYPE_OK (intHI_type_node
))
4010 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
4011 if (TYPE_OK (intQI_type_node
))
4012 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
4015 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
4018 /* Build a bit-field integer type for the given WIDTH and UNSIGNEDP. */
4021 c_build_bitfield_integer_type (unsigned HOST_WIDE_INT width
, int unsignedp
)
4025 /* Extended integer types of the same width as a standard type have
4026 lesser rank, so those of the same width as int promote to int or
4027 unsigned int and are valid for printf formats expecting int or
4028 unsigned int. To avoid such special cases, avoid creating
4029 extended integer types for bit-fields if a standard integer type
4031 if (width
== TYPE_PRECISION (integer_type_node
))
4032 return unsignedp
? unsigned_type_node
: integer_type_node
;
4033 if (width
== TYPE_PRECISION (signed_char_type_node
))
4034 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
4035 if (width
== TYPE_PRECISION (short_integer_type_node
))
4036 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
4037 if (width
== TYPE_PRECISION (long_integer_type_node
))
4038 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
4039 if (width
== TYPE_PRECISION (long_long_integer_type_node
))
4040 return (unsignedp
? long_long_unsigned_type_node
4041 : long_long_integer_type_node
);
4042 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
4043 if (int_n_enabled_p
[i
]
4044 && width
== int_n_data
[i
].bitsize
)
4045 return (unsignedp
? int_n_trees
[i
].unsigned_type
4046 : int_n_trees
[i
].signed_type
);
4047 return build_nonstandard_integer_type (width
, unsignedp
);
4050 /* The C version of the register_builtin_type langhook. */
4053 c_register_builtin_type (tree type
, const char* name
)
4057 decl
= build_decl (UNKNOWN_LOCATION
,
4058 TYPE_DECL
, get_identifier (name
), type
);
4059 DECL_ARTIFICIAL (decl
) = 1;
4060 if (!TYPE_NAME (type
))
4061 TYPE_NAME (type
) = decl
;
4064 registered_builtin_types
= tree_cons (0, type
, registered_builtin_types
);
4067 /* Print an error message for invalid operands to arith operation
4068 CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
4069 LOCATION is the location of the message. */
4072 binary_op_error (location_t location
, enum tree_code code
,
4073 tree type0
, tree type1
)
4080 opname
= "+"; break;
4082 opname
= "-"; break;
4084 opname
= "*"; break;
4086 opname
= "max"; break;
4088 opname
= "min"; break;
4090 opname
= "=="; break;
4092 opname
= "!="; break;
4094 opname
= "<="; break;
4096 opname
= ">="; break;
4098 opname
= "<"; break;
4100 opname
= ">"; break;
4102 opname
= "<<"; break;
4104 opname
= ">>"; break;
4105 case TRUNC_MOD_EXPR
:
4106 case FLOOR_MOD_EXPR
:
4107 opname
= "%"; break;
4108 case TRUNC_DIV_EXPR
:
4109 case FLOOR_DIV_EXPR
:
4110 opname
= "/"; break;
4112 opname
= "&"; break;
4114 opname
= "|"; break;
4115 case TRUTH_ANDIF_EXPR
:
4116 opname
= "&&"; break;
4117 case TRUTH_ORIF_EXPR
:
4118 opname
= "||"; break;
4120 opname
= "^"; break;
4125 "invalid operands to binary %s (have %qT and %qT)", opname
,
4129 /* Given an expression as a tree, return its original type. Do this
4130 by stripping any conversion that preserves the sign and precision. */
4132 expr_original_type (tree expr
)
4134 STRIP_SIGN_NOPS (expr
);
4135 return TREE_TYPE (expr
);
4138 /* Subroutine of build_binary_op, used for comparison operations.
4139 See if the operands have both been converted from subword integer types
4140 and, if so, perhaps change them both back to their original type.
4141 This function is also responsible for converting the two operands
4142 to the proper common type for comparison.
4144 The arguments of this function are all pointers to local variables
4145 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
4146 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
4148 LOC is the location of the comparison.
4150 If this function returns nonzero, it means that the comparison has
4151 a constant value. What this function returns is an expression for
4155 shorten_compare (location_t loc
, tree
*op0_ptr
, tree
*op1_ptr
,
4156 tree
*restype_ptr
, enum tree_code
*rescode_ptr
)
4159 tree op0
= *op0_ptr
;
4160 tree op1
= *op1_ptr
;
4161 int unsignedp0
, unsignedp1
;
4163 tree primop0
, primop1
;
4164 enum tree_code code
= *rescode_ptr
;
4166 /* Throw away any conversions to wider types
4167 already present in the operands. */
4169 primop0
= c_common_get_narrower (op0
, &unsignedp0
);
4170 primop1
= c_common_get_narrower (op1
, &unsignedp1
);
4172 /* If primopN is first sign-extended from primopN's precision to opN's
4173 precision, then zero-extended from opN's precision to
4174 *restype_ptr precision, shortenings might be invalid. */
4175 if (TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (TREE_TYPE (op0
))
4176 && TYPE_PRECISION (TREE_TYPE (op0
)) < TYPE_PRECISION (*restype_ptr
)
4178 && TYPE_UNSIGNED (TREE_TYPE (op0
)))
4180 if (TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (TREE_TYPE (op1
))
4181 && TYPE_PRECISION (TREE_TYPE (op1
)) < TYPE_PRECISION (*restype_ptr
)
4183 && TYPE_UNSIGNED (TREE_TYPE (op1
)))
4186 /* Handle the case that OP0 does not *contain* a conversion
4187 but it *requires* conversion to FINAL_TYPE. */
4189 if (op0
== primop0
&& TREE_TYPE (op0
) != *restype_ptr
)
4190 unsignedp0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
4191 if (op1
== primop1
&& TREE_TYPE (op1
) != *restype_ptr
)
4192 unsignedp1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
4194 /* If one of the operands must be floated, we cannot optimize. */
4195 real1
= TREE_CODE (TREE_TYPE (primop0
)) == REAL_TYPE
;
4196 real2
= TREE_CODE (TREE_TYPE (primop1
)) == REAL_TYPE
;
4198 /* If first arg is constant, swap the args (changing operation
4199 so value is preserved), for canonicalization. Don't do this if
4200 the second arg is 0. */
4202 if (TREE_CONSTANT (primop0
)
4203 && !integer_zerop (primop1
) && !real_zerop (primop1
)
4204 && !fixed_zerop (primop1
))
4207 int temi
= unsignedp0
;
4215 unsignedp0
= unsignedp1
;
4238 *rescode_ptr
= code
;
4241 /* If comparing an integer against a constant more bits wide,
4242 maybe we can deduce a value of 1 or 0 independent of the data.
4243 Or else truncate the constant now
4244 rather than extend the variable at run time.
4246 This is only interesting if the constant is the wider arg.
4247 Also, it is not safe if the constant is unsigned and the
4248 variable arg is signed, since in this case the variable
4249 would be sign-extended and then regarded as unsigned.
4250 Our technique fails in this case because the lowest/highest
4251 possible unsigned results don't follow naturally from the
4252 lowest/highest possible values of the variable operand.
4253 For just EQ_EXPR and NE_EXPR there is another technique that
4254 could be used: see if the constant can be faithfully represented
4255 in the other operand's type, by truncating it and reextending it
4256 and see if that preserves the constant's value. */
4258 if (!real1
&& !real2
4259 && TREE_CODE (TREE_TYPE (primop0
)) != FIXED_POINT_TYPE
4260 && TREE_CODE (primop1
) == INTEGER_CST
4261 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
))
4263 int min_gt
, max_gt
, min_lt
, max_lt
;
4264 tree maxval
, minval
;
4265 /* 1 if comparison is nominally unsigned. */
4266 int unsignedp
= TYPE_UNSIGNED (*restype_ptr
);
4269 type
= c_common_signed_or_unsigned_type (unsignedp0
,
4270 TREE_TYPE (primop0
));
4272 maxval
= TYPE_MAX_VALUE (type
);
4273 minval
= TYPE_MIN_VALUE (type
);
4275 if (unsignedp
&& !unsignedp0
)
4276 *restype_ptr
= c_common_signed_type (*restype_ptr
);
4278 if (TREE_TYPE (primop1
) != *restype_ptr
)
4280 /* Convert primop1 to target type, but do not introduce
4281 additional overflow. We know primop1 is an int_cst. */
4282 primop1
= force_fit_type (*restype_ptr
,
4285 TYPE_PRECISION (*restype_ptr
),
4286 TYPE_SIGN (TREE_TYPE (primop1
))),
4287 0, TREE_OVERFLOW (primop1
));
4289 if (type
!= *restype_ptr
)
4291 minval
= convert (*restype_ptr
, minval
);
4292 maxval
= convert (*restype_ptr
, maxval
);
4295 min_gt
= tree_int_cst_lt (primop1
, minval
);
4296 max_gt
= tree_int_cst_lt (primop1
, maxval
);
4297 min_lt
= tree_int_cst_lt (minval
, primop1
);
4298 max_lt
= tree_int_cst_lt (maxval
, primop1
);
4301 /* This used to be a switch, but Genix compiler can't handle that. */
4302 if (code
== NE_EXPR
)
4304 if (max_lt
|| min_gt
)
4305 val
= truthvalue_true_node
;
4307 else if (code
== EQ_EXPR
)
4309 if (max_lt
|| min_gt
)
4310 val
= truthvalue_false_node
;
4312 else if (code
== LT_EXPR
)
4315 val
= truthvalue_true_node
;
4317 val
= truthvalue_false_node
;
4319 else if (code
== GT_EXPR
)
4322 val
= truthvalue_true_node
;
4324 val
= truthvalue_false_node
;
4326 else if (code
== LE_EXPR
)
4329 val
= truthvalue_true_node
;
4331 val
= truthvalue_false_node
;
4333 else if (code
== GE_EXPR
)
4336 val
= truthvalue_true_node
;
4338 val
= truthvalue_false_node
;
4341 /* If primop0 was sign-extended and unsigned comparison specd,
4342 we did a signed comparison above using the signed type bounds.
4343 But the comparison we output must be unsigned.
4345 Also, for inequalities, VAL is no good; but if the signed
4346 comparison had *any* fixed result, it follows that the
4347 unsigned comparison just tests the sign in reverse
4348 (positive values are LE, negative ones GE).
4349 So we can generate an unsigned comparison
4350 against an extreme value of the signed type. */
4352 if (unsignedp
&& !unsignedp0
)
4359 primop1
= TYPE_MIN_VALUE (type
);
4365 primop1
= TYPE_MAX_VALUE (type
);
4372 type
= c_common_unsigned_type (type
);
4375 if (TREE_CODE (primop0
) != INTEGER_CST
)
4377 if (val
== truthvalue_false_node
)
4378 warning_at (loc
, OPT_Wtype_limits
,
4379 "comparison is always false due to limited range of data type");
4380 if (val
== truthvalue_true_node
)
4381 warning_at (loc
, OPT_Wtype_limits
,
4382 "comparison is always true due to limited range of data type");
4387 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4388 if (TREE_SIDE_EFFECTS (primop0
))
4389 return build2 (COMPOUND_EXPR
, TREE_TYPE (val
), primop0
, val
);
4393 /* Value is not predetermined, but do the comparison
4394 in the type of the operand that is not constant.
4395 TYPE is already properly set. */
4398 /* If either arg is decimal float and the other is float, find the
4399 proper common type to use for comparison. */
4400 else if (real1
&& real2
4401 && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0
)))
4402 && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1
))))
4403 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
4405 /* If either arg is decimal float and the other is float, fail. */
4406 else if (real1
&& real2
4407 && (DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0
)))
4408 || DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1
)))))
4411 else if (real1
&& real2
4412 && (TYPE_PRECISION (TREE_TYPE (primop0
))
4413 == TYPE_PRECISION (TREE_TYPE (primop1
))))
4414 type
= TREE_TYPE (primop0
);
4416 /* If args' natural types are both narrower than nominal type
4417 and both extend in the same manner, compare them
4418 in the type of the wider arg.
4419 Otherwise must actually extend both to the nominal
4420 common type lest different ways of extending
4422 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
4424 else if (unsignedp0
== unsignedp1
&& real1
== real2
4425 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
)
4426 && TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (*restype_ptr
))
4428 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
4429 type
= c_common_signed_or_unsigned_type (unsignedp0
4430 || TYPE_UNSIGNED (*restype_ptr
),
4432 /* Make sure shorter operand is extended the right way
4433 to match the longer operand. */
4435 = convert (c_common_signed_or_unsigned_type (unsignedp0
,
4436 TREE_TYPE (primop0
)),
4439 = convert (c_common_signed_or_unsigned_type (unsignedp1
,
4440 TREE_TYPE (primop1
)),
4445 /* Here we must do the comparison on the nominal type
4446 using the args exactly as we received them. */
4447 type
= *restype_ptr
;
4451 if (!real1
&& !real2
&& integer_zerop (primop1
)
4452 && TYPE_UNSIGNED (*restype_ptr
))
4455 /* All unsigned values are >= 0, so we warn. However,
4456 if OP0 is a constant that is >= 0, the signedness of
4457 the comparison isn't an issue, so suppress the
4460 warn_type_limits
&& !in_system_header_at (loc
)
4461 && !(TREE_CODE (primop0
) == INTEGER_CST
4462 && !TREE_OVERFLOW (convert (c_common_signed_type (type
),
4464 /* Do not warn for enumeration types. */
4465 && (TREE_CODE (expr_original_type (primop0
)) != ENUMERAL_TYPE
);
4471 warning_at (loc
, OPT_Wtype_limits
,
4472 "comparison of unsigned expression >= 0 is always true");
4473 value
= truthvalue_true_node
;
4478 warning_at (loc
, OPT_Wtype_limits
,
4479 "comparison of unsigned expression < 0 is always false");
4480 value
= truthvalue_false_node
;
4489 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4490 if (TREE_SIDE_EFFECTS (primop0
))
4491 return build2 (COMPOUND_EXPR
, TREE_TYPE (value
),
4498 *op0_ptr
= convert (type
, primop0
);
4499 *op1_ptr
= convert (type
, primop1
);
4501 *restype_ptr
= truthvalue_type_node
;
4506 /* Return a tree for the sum or difference (RESULTCODE says which)
4507 of pointer PTROP and integer INTOP. */
4510 pointer_int_sum (location_t loc
, enum tree_code resultcode
,
4511 tree ptrop
, tree intop
, bool complain
)
4515 /* The result is a pointer of the same type that is being added. */
4516 tree result_type
= TREE_TYPE (ptrop
);
4518 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
4520 if (complain
&& warn_pointer_arith
)
4521 pedwarn (loc
, OPT_Wpointer_arith
,
4522 "pointer of type %<void *%> used in arithmetic");
4524 return error_mark_node
;
4525 size_exp
= integer_one_node
;
4527 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
4529 if (complain
&& warn_pointer_arith
)
4530 pedwarn (loc
, OPT_Wpointer_arith
,
4531 "pointer to a function used in arithmetic");
4533 return error_mark_node
;
4534 size_exp
= integer_one_node
;
4537 size_exp
= size_in_bytes (TREE_TYPE (result_type
));
4539 /* We are manipulating pointer values, so we don't need to warn
4540 about relying on undefined signed overflow. We disable the
4541 warning here because we use integer types so fold won't know that
4542 they are really pointers. */
4543 fold_defer_overflow_warnings ();
4545 /* If what we are about to multiply by the size of the elements
4546 contains a constant term, apply distributive law
4547 and multiply that constant term separately.
4548 This helps produce common subexpressions. */
4549 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
4550 && !TREE_CONSTANT (intop
)
4551 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
4552 && TREE_CONSTANT (size_exp
)
4553 /* If the constant comes from pointer subtraction,
4554 skip this optimization--it would cause an error. */
4555 && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop
, 0))) == INTEGER_TYPE
4556 /* If the constant is unsigned, and smaller than the pointer size,
4557 then we must skip this optimization. This is because it could cause
4558 an overflow error if the constant is negative but INTOP is not. */
4559 && (!TYPE_UNSIGNED (TREE_TYPE (intop
))
4560 || (TYPE_PRECISION (TREE_TYPE (intop
))
4561 == TYPE_PRECISION (TREE_TYPE (ptrop
)))))
4563 enum tree_code subcode
= resultcode
;
4564 tree int_type
= TREE_TYPE (intop
);
4565 if (TREE_CODE (intop
) == MINUS_EXPR
)
4566 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
4567 /* Convert both subexpression types to the type of intop,
4568 because weird cases involving pointer arithmetic
4569 can result in a sum or difference with different type args. */
4570 ptrop
= build_binary_op (EXPR_LOCATION (TREE_OPERAND (intop
, 1)),
4572 convert (int_type
, TREE_OPERAND (intop
, 1)), 1);
4573 intop
= convert (int_type
, TREE_OPERAND (intop
, 0));
4576 /* Convert the integer argument to a type the same size as sizetype
4577 so the multiply won't overflow spuriously. */
4578 if (TYPE_PRECISION (TREE_TYPE (intop
)) != TYPE_PRECISION (sizetype
)
4579 || TYPE_UNSIGNED (TREE_TYPE (intop
)) != TYPE_UNSIGNED (sizetype
))
4580 intop
= convert (c_common_type_for_size (TYPE_PRECISION (sizetype
),
4581 TYPE_UNSIGNED (sizetype
)), intop
);
4583 /* Replace the integer argument with a suitable product by the object size.
4584 Do this multiplication as signed, then convert to the appropriate type
4585 for the pointer operation and disregard an overflow that occurred only
4586 because of the sign-extension change in the latter conversion. */
4588 tree t
= build_binary_op (loc
,
4590 convert (TREE_TYPE (intop
), size_exp
), 1);
4591 intop
= convert (sizetype
, t
);
4592 if (TREE_OVERFLOW_P (intop
) && !TREE_OVERFLOW (t
))
4593 intop
= wide_int_to_tree (TREE_TYPE (intop
), intop
);
4596 /* Create the sum or difference. */
4597 if (resultcode
== MINUS_EXPR
)
4598 intop
= fold_build1_loc (loc
, NEGATE_EXPR
, sizetype
, intop
);
4600 ret
= fold_build_pointer_plus_loc (loc
, ptrop
, intop
);
4602 fold_undefer_and_ignore_overflow_warnings ();
4607 /* Wrap a C_MAYBE_CONST_EXPR around an expression that is fully folded
4608 and if NON_CONST is known not to be permitted in an evaluated part
4609 of a constant expression. */
4612 c_wrap_maybe_const (tree expr
, bool non_const
)
4614 bool nowarning
= TREE_NO_WARNING (expr
);
4615 location_t loc
= EXPR_LOCATION (expr
);
4617 /* This should never be called for C++. */
4618 if (c_dialect_cxx ())
4621 /* The result of folding may have a NOP_EXPR to set TREE_NO_WARNING. */
4622 STRIP_TYPE_NOPS (expr
);
4623 expr
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (expr
), NULL
, expr
);
4624 C_MAYBE_CONST_EXPR_NON_CONST (expr
) = non_const
;
4626 TREE_NO_WARNING (expr
) = 1;
4627 protected_set_expr_location (expr
, loc
);
4632 /* Wrap a SAVE_EXPR around EXPR, if appropriate. Like save_expr, but
4633 for C folds the inside expression and wraps a C_MAYBE_CONST_EXPR
4634 around the SAVE_EXPR if needed so that c_fully_fold does not need
4635 to look inside SAVE_EXPRs. */
4638 c_save_expr (tree expr
)
4640 bool maybe_const
= true;
4641 if (c_dialect_cxx ())
4642 return save_expr (expr
);
4643 expr
= c_fully_fold (expr
, false, &maybe_const
);
4644 expr
= save_expr (expr
);
4646 expr
= c_wrap_maybe_const (expr
, true);
4650 /* Return whether EXPR is a declaration whose address can never be
4654 decl_with_nonnull_addr_p (const_tree expr
)
4656 return (DECL_P (expr
)
4657 && (TREE_CODE (expr
) == PARM_DECL
4658 || TREE_CODE (expr
) == LABEL_DECL
4659 || !DECL_WEAK (expr
)));
4662 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
4663 or for an `if' or `while' statement or ?..: exp. It should already
4664 have been validated to be of suitable type; otherwise, a bad
4665 diagnostic may result.
4667 The EXPR is located at LOCATION.
4669 This preparation consists of taking the ordinary
4670 representation of an expression expr and producing a valid tree
4671 boolean expression describing whether expr is nonzero. We could
4672 simply always do build_binary_op (NE_EXPR, expr, truthvalue_false_node, 1),
4673 but we optimize comparisons, &&, ||, and !.
4675 The resulting type should always be `truthvalue_type_node'. */
4678 c_common_truthvalue_conversion (location_t location
, tree expr
)
4680 switch (TREE_CODE (expr
))
4682 case EQ_EXPR
: case NE_EXPR
: case UNEQ_EXPR
: case LTGT_EXPR
:
4683 case LE_EXPR
: case GE_EXPR
: case LT_EXPR
: case GT_EXPR
:
4684 case UNLE_EXPR
: case UNGE_EXPR
: case UNLT_EXPR
: case UNGT_EXPR
:
4685 case ORDERED_EXPR
: case UNORDERED_EXPR
:
4686 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4688 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4689 TREE_OPERAND (expr
, 0), TREE_OPERAND (expr
, 1));
4692 case TRUTH_ANDIF_EXPR
:
4693 case TRUTH_ORIF_EXPR
:
4694 case TRUTH_AND_EXPR
:
4696 case TRUTH_XOR_EXPR
:
4697 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4699 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4700 c_common_truthvalue_conversion (location
,
4701 TREE_OPERAND (expr
, 0)),
4702 c_common_truthvalue_conversion (location
,
4703 TREE_OPERAND (expr
, 1)));
4706 case TRUTH_NOT_EXPR
:
4707 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4709 expr
= build1 (TREE_CODE (expr
), truthvalue_type_node
,
4710 c_common_truthvalue_conversion (location
,
4711 TREE_OPERAND (expr
, 0)));
4718 return integer_zerop (expr
) ? truthvalue_false_node
4719 : truthvalue_true_node
;
4722 return real_compare (NE_EXPR
, &TREE_REAL_CST (expr
), &dconst0
)
4723 ? truthvalue_true_node
4724 : truthvalue_false_node
;
4727 return fixed_compare (NE_EXPR
, &TREE_FIXED_CST (expr
),
4728 &FCONST0 (TYPE_MODE (TREE_TYPE (expr
))))
4729 ? truthvalue_true_node
4730 : truthvalue_false_node
;
4733 expr
= build_unary_op (location
, ADDR_EXPR
, expr
, 0);
4738 tree inner
= TREE_OPERAND (expr
, 0);
4739 if (decl_with_nonnull_addr_p (inner
))
4741 /* Common Ada/Pascal programmer's mistake. */
4742 warning_at (location
,
4744 "the address of %qD will always evaluate as %<true%>",
4746 return truthvalue_true_node
;
4752 expr
= build_binary_op (EXPR_LOCATION (expr
),
4753 (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1))
4754 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4755 c_common_truthvalue_conversion (location
,
4756 TREE_OPERAND (expr
, 0)),
4757 c_common_truthvalue_conversion (location
,
4758 TREE_OPERAND (expr
, 1)),
4765 case EXCESS_PRECISION_EXPR
:
4766 /* These don't change whether an object is nonzero or zero. */
4767 return c_common_truthvalue_conversion (location
, TREE_OPERAND (expr
, 0));
4771 /* These don't change whether an object is zero or nonzero, but
4772 we can't ignore them if their second arg has side-effects. */
4773 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1)))
4775 expr
= build2 (COMPOUND_EXPR
, truthvalue_type_node
,
4776 TREE_OPERAND (expr
, 1),
4777 c_common_truthvalue_conversion
4778 (location
, TREE_OPERAND (expr
, 0)));
4782 return c_common_truthvalue_conversion (location
,
4783 TREE_OPERAND (expr
, 0));
4786 /* Distribute the conversion into the arms of a COND_EXPR. */
4787 if (c_dialect_cxx ())
4789 tree op1
= TREE_OPERAND (expr
, 1);
4790 tree op2
= TREE_OPERAND (expr
, 2);
4791 /* In C++ one of the arms might have void type if it is throw. */
4792 if (!VOID_TYPE_P (TREE_TYPE (op1
)))
4793 op1
= c_common_truthvalue_conversion (location
, op1
);
4794 if (!VOID_TYPE_P (TREE_TYPE (op2
)))
4795 op2
= c_common_truthvalue_conversion (location
, op2
);
4796 expr
= fold_build3_loc (location
, COND_EXPR
, truthvalue_type_node
,
4797 TREE_OPERAND (expr
, 0), op1
, op2
);
4802 /* Folding will happen later for C. */
4803 expr
= build3 (COND_EXPR
, truthvalue_type_node
,
4804 TREE_OPERAND (expr
, 0),
4805 c_common_truthvalue_conversion (location
,
4806 TREE_OPERAND (expr
, 1)),
4807 c_common_truthvalue_conversion (location
,
4808 TREE_OPERAND (expr
, 2)));
4814 tree totype
= TREE_TYPE (expr
);
4815 tree fromtype
= TREE_TYPE (TREE_OPERAND (expr
, 0));
4817 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
4818 since that affects how `default_conversion' will behave. */
4819 if (TREE_CODE (totype
) == REFERENCE_TYPE
4820 || TREE_CODE (fromtype
) == REFERENCE_TYPE
)
4822 /* Don't strip a conversion from C++0x scoped enum, since they
4823 don't implicitly convert to other types. */
4824 if (TREE_CODE (fromtype
) == ENUMERAL_TYPE
4825 && ENUM_IS_SCOPED (fromtype
))
4827 /* If this isn't narrowing the argument, we can ignore it. */
4828 if (TYPE_PRECISION (totype
) >= TYPE_PRECISION (fromtype
))
4829 return c_common_truthvalue_conversion (location
,
4830 TREE_OPERAND (expr
, 0));
4835 if (!TREE_NO_WARNING (expr
)
4836 && warn_parentheses
)
4838 warning (OPT_Wparentheses
,
4839 "suggest parentheses around assignment used as truth value");
4840 TREE_NO_WARNING (expr
) = 1;
4848 if (TREE_CODE (TREE_TYPE (expr
)) == COMPLEX_TYPE
)
4850 tree t
= (in_late_binary_op
? save_expr (expr
) : c_save_expr (expr
));
4851 expr
= (build_binary_op
4852 (EXPR_LOCATION (expr
),
4853 (TREE_SIDE_EFFECTS (expr
)
4854 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4855 c_common_truthvalue_conversion
4857 build_unary_op (location
, REALPART_EXPR
, t
, 0)),
4858 c_common_truthvalue_conversion
4860 build_unary_op (location
, IMAGPART_EXPR
, t
, 0)),
4865 if (TREE_CODE (TREE_TYPE (expr
)) == FIXED_POINT_TYPE
)
4867 tree fixed_zero_node
= build_fixed (TREE_TYPE (expr
),
4869 (TREE_TYPE (expr
))));
4870 return build_binary_op (location
, NE_EXPR
, expr
, fixed_zero_node
, 1);
4873 return build_binary_op (location
, NE_EXPR
, expr
, integer_zero_node
, 1);
4876 protected_set_expr_location (expr
, location
);
4880 static void def_builtin_1 (enum built_in_function fncode
,
4882 enum built_in_class fnclass
,
4883 tree fntype
, tree libtype
,
4884 bool both_p
, bool fallback_p
, bool nonansi_p
,
4885 tree fnattrs
, bool implicit_p
);
4888 /* Apply the TYPE_QUALS to the new DECL. */
4891 c_apply_type_quals_to_decl (int type_quals
, tree decl
)
4893 tree type
= TREE_TYPE (decl
);
4895 if (type
== error_mark_node
)
4898 if ((type_quals
& TYPE_QUAL_CONST
)
4899 || (type
&& TREE_CODE (type
) == REFERENCE_TYPE
))
4900 /* We used to check TYPE_NEEDS_CONSTRUCTING here, but now a constexpr
4901 constructor can produce constant init, so rely on cp_finish_decl to
4902 clear TREE_READONLY if the variable has non-constant init. */
4903 TREE_READONLY (decl
) = 1;
4904 if (type_quals
& TYPE_QUAL_VOLATILE
)
4906 TREE_SIDE_EFFECTS (decl
) = 1;
4907 TREE_THIS_VOLATILE (decl
) = 1;
4909 if (type_quals
& TYPE_QUAL_RESTRICT
)
4911 while (type
&& TREE_CODE (type
) == ARRAY_TYPE
)
4912 /* Allow 'restrict' on arrays of pointers.
4913 FIXME currently we just ignore it. */
4914 type
= TREE_TYPE (type
);
4916 || !POINTER_TYPE_P (type
)
4917 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type
)))
4918 error ("invalid use of %<restrict%>");
4922 struct c_type_hasher
: ggc_hasher
<tree
>
4924 static hashval_t
hash (tree
);
4925 static bool equal (tree
, tree
);
4928 /* Hash function for the problem of multiple type definitions in
4929 different files. This must hash all types that will compare
4930 equal via comptypes to the same value. In practice it hashes
4931 on some of the simple stuff and leaves the details to comptypes. */
4934 c_type_hasher::hash (tree t
)
4939 switch (TREE_CODE (t
))
4941 /* For pointers, hash on pointee type plus some swizzling. */
4943 return hash (TREE_TYPE (t
)) ^ 0x3003003;
4944 /* Hash on number of elements and total size. */
4947 t2
= TYPE_VALUES (t
);
4951 t2
= TYPE_FIELDS (t
);
4953 case QUAL_UNION_TYPE
:
4955 t2
= TYPE_FIELDS (t
);
4959 t2
= TYPE_FIELDS (t
);
4964 /* FIXME: We want to use a DECL_CHAIN iteration method here, but
4965 TYPE_VALUES of ENUMERAL_TYPEs is stored as a TREE_LIST. */
4966 n_elements
= list_length (t2
);
4967 /* We might have a VLA here. */
4968 if (TREE_CODE (TYPE_SIZE (t
)) != INTEGER_CST
)
4971 size
= TREE_INT_CST_LOW (TYPE_SIZE (t
));
4972 return ((size
<< 24) | (n_elements
<< shift
));
4976 c_type_hasher::equal (tree t1
, tree t2
)
4978 return lang_hooks
.types_compatible_p (t1
, t2
);
4981 static GTY(()) hash_table
<c_type_hasher
> *type_hash_table
;
4983 /* Return the typed-based alias set for T, which may be an expression
4984 or a type. Return -1 if we don't do anything special. */
4987 c_common_get_alias_set (tree t
)
4991 /* For VLAs, use the alias set of the element type rather than the
4992 default of alias set 0 for types compared structurally. */
4993 if (TYPE_P (t
) && TYPE_STRUCTURAL_EQUALITY_P (t
))
4995 if (TREE_CODE (t
) == ARRAY_TYPE
)
4996 return get_alias_set (TREE_TYPE (t
));
5000 /* Permit type-punning when accessing a union, provided the access
5001 is directly through the union. For example, this code does not
5002 permit taking the address of a union member and then storing
5003 through it. Even the type-punning allowed here is a GCC
5004 extension, albeit a common and useful one; the C standard says
5005 that such accesses have implementation-defined behavior. */
5007 TREE_CODE (u
) == COMPONENT_REF
|| TREE_CODE (u
) == ARRAY_REF
;
5008 u
= TREE_OPERAND (u
, 0))
5009 if (TREE_CODE (u
) == COMPONENT_REF
5010 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u
, 0))) == UNION_TYPE
)
5013 /* That's all the expressions we handle specially. */
5017 /* The C standard guarantees that any object may be accessed via an
5018 lvalue that has character type. */
5019 if (t
== char_type_node
5020 || t
== signed_char_type_node
5021 || t
== unsigned_char_type_node
)
5024 /* The C standard specifically allows aliasing between signed and
5025 unsigned variants of the same type. We treat the signed
5026 variant as canonical. */
5027 if (TREE_CODE (t
) == INTEGER_TYPE
&& TYPE_UNSIGNED (t
))
5029 tree t1
= c_common_signed_type (t
);
5031 /* t1 == t can happen for boolean nodes which are always unsigned. */
5033 return get_alias_set (t1
);
5036 /* Handle the case of multiple type nodes referring to "the same" type,
5037 which occurs with IMA. These share an alias set. FIXME: Currently only
5038 C90 is handled. (In C99 type compatibility is not transitive, which
5039 complicates things mightily. The alias set splay trees can theoretically
5040 represent this, but insertion is tricky when you consider all the
5041 different orders things might arrive in.) */
5043 if (c_language
!= clk_c
|| flag_isoc99
)
5046 /* Save time if there's only one input file. */
5047 if (num_in_fnames
== 1)
5050 /* Pointers need special handling if they point to any type that
5051 needs special handling (below). */
5052 if (TREE_CODE (t
) == POINTER_TYPE
)
5055 /* Find bottom type under any nested POINTERs. */
5056 for (t2
= TREE_TYPE (t
);
5057 TREE_CODE (t2
) == POINTER_TYPE
;
5058 t2
= TREE_TYPE (t2
))
5060 if (TREE_CODE (t2
) != RECORD_TYPE
5061 && TREE_CODE (t2
) != ENUMERAL_TYPE
5062 && TREE_CODE (t2
) != QUAL_UNION_TYPE
5063 && TREE_CODE (t2
) != UNION_TYPE
)
5065 if (TYPE_SIZE (t2
) == 0)
5068 /* These are the only cases that need special handling. */
5069 if (TREE_CODE (t
) != RECORD_TYPE
5070 && TREE_CODE (t
) != ENUMERAL_TYPE
5071 && TREE_CODE (t
) != QUAL_UNION_TYPE
5072 && TREE_CODE (t
) != UNION_TYPE
5073 && TREE_CODE (t
) != POINTER_TYPE
)
5076 if (TYPE_SIZE (t
) == 0)
5079 /* Look up t in hash table. Only one of the compatible types within each
5080 alias set is recorded in the table. */
5081 if (!type_hash_table
)
5082 type_hash_table
= hash_table
<c_type_hasher
>::create_ggc (1021);
5083 tree
*slot
= type_hash_table
->find_slot (t
, INSERT
);
5086 TYPE_ALIAS_SET (t
) = TYPE_ALIAS_SET ((tree
)*slot
);
5087 return TYPE_ALIAS_SET ((tree
)*slot
);
5090 /* Our caller will assign and record (in t) a new alias set; all we need
5091 to do is remember t in the hash table. */
5097 /* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where
5098 the IS_SIZEOF parameter indicates which operator is being applied.
5099 The COMPLAIN flag controls whether we should diagnose possibly
5100 ill-formed constructs or not. LOC is the location of the SIZEOF or
5101 TYPEOF operator. If MIN_ALIGNOF, the least alignment required for
5102 a type in any context should be returned, rather than the normal
5103 alignment for that type. */
5106 c_sizeof_or_alignof_type (location_t loc
,
5107 tree type
, bool is_sizeof
, bool min_alignof
,
5110 const char *op_name
;
5112 enum tree_code type_code
= TREE_CODE (type
);
5114 op_name
= is_sizeof
? "sizeof" : "__alignof__";
5116 if (type_code
== FUNCTION_TYPE
)
5120 if (complain
&& warn_pointer_arith
)
5121 pedwarn (loc
, OPT_Wpointer_arith
,
5122 "invalid application of %<sizeof%> to a function type");
5124 return error_mark_node
;
5125 value
= size_one_node
;
5131 if (c_dialect_cxx ())
5132 pedwarn (loc
, OPT_Wpedantic
, "ISO C++ does not permit "
5133 "%<alignof%> applied to a function type");
5135 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not permit "
5136 "%<_Alignof%> applied to a function type");
5138 value
= size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
5141 else if (type_code
== VOID_TYPE
|| type_code
== ERROR_MARK
)
5143 if (type_code
== VOID_TYPE
5144 && complain
&& warn_pointer_arith
)
5145 pedwarn (loc
, OPT_Wpointer_arith
,
5146 "invalid application of %qs to a void type", op_name
);
5148 return error_mark_node
;
5149 value
= size_one_node
;
5151 else if (!COMPLETE_TYPE_P (type
)
5152 && (!c_dialect_cxx () || is_sizeof
|| type_code
!= ARRAY_TYPE
))
5155 error_at (loc
, "invalid application of %qs to incomplete type %qT",
5157 return error_mark_node
;
5159 else if (c_dialect_cxx () && type_code
== ARRAY_TYPE
5160 && !COMPLETE_TYPE_P (TREE_TYPE (type
)))
5163 error_at (loc
, "invalid application of %qs to array type %qT of "
5164 "incomplete element type", op_name
, type
);
5165 return error_mark_node
;
5170 /* Convert in case a char is more than one unit. */
5171 value
= size_binop_loc (loc
, CEIL_DIV_EXPR
, TYPE_SIZE_UNIT (type
),
5172 size_int (TYPE_PRECISION (char_type_node
)
5174 else if (min_alignof
)
5175 value
= size_int (min_align_of_type (type
));
5177 value
= size_int (TYPE_ALIGN_UNIT (type
));
5180 /* VALUE will have the middle-end integer type sizetype.
5181 However, we should really return a value of type `size_t',
5182 which is just a typedef for an ordinary integer type. */
5183 value
= fold_convert_loc (loc
, size_type_node
, value
);
5188 /* Implement the __alignof keyword: Return the minimum required
5189 alignment of EXPR, measured in bytes. For VAR_DECLs,
5190 FUNCTION_DECLs and FIELD_DECLs return DECL_ALIGN (which can be set
5191 from an "aligned" __attribute__ specification). LOC is the
5192 location of the ALIGNOF operator. */
5195 c_alignof_expr (location_t loc
, tree expr
)
5199 if (VAR_OR_FUNCTION_DECL_P (expr
))
5200 t
= size_int (DECL_ALIGN_UNIT (expr
));
5202 else if (TREE_CODE (expr
) == COMPONENT_REF
5203 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
, 1)))
5205 error_at (loc
, "%<__alignof%> applied to a bit-field");
5208 else if (TREE_CODE (expr
) == COMPONENT_REF
5209 && TREE_CODE (TREE_OPERAND (expr
, 1)) == FIELD_DECL
)
5210 t
= size_int (DECL_ALIGN_UNIT (TREE_OPERAND (expr
, 1)));
5212 else if (TREE_CODE (expr
) == INDIRECT_REF
)
5214 tree t
= TREE_OPERAND (expr
, 0);
5216 int bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
5218 while (CONVERT_EXPR_P (t
)
5219 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
5223 t
= TREE_OPERAND (t
, 0);
5224 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
5225 if (thisalign
> bestalign
)
5226 best
= t
, bestalign
= thisalign
;
5228 return c_alignof (loc
, TREE_TYPE (TREE_TYPE (best
)));
5231 return c_alignof (loc
, TREE_TYPE (expr
));
5233 return fold_convert_loc (loc
, size_type_node
, t
);
5236 /* Handle C and C++ default attributes. */
5238 enum built_in_attribute
5240 #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
5241 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
5242 #define DEF_ATTR_STRING(ENUM, VALUE) ENUM,
5243 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
5244 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
5245 #include "builtin-attrs.def"
5246 #undef DEF_ATTR_NULL_TREE
5248 #undef DEF_ATTR_STRING
5249 #undef DEF_ATTR_IDENT
5250 #undef DEF_ATTR_TREE_LIST
5254 static GTY(()) tree built_in_attributes
[(int) ATTR_LAST
];
5256 static void c_init_attributes (void);
5260 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
5261 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
5262 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
5263 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
5264 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
5265 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
5266 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
5267 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5269 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5271 #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5272 ARG6, ARG7, ARG8) NAME,
5273 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
5274 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
5275 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
5276 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
5277 #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
5278 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5280 #define DEF_FUNCTION_TYPE_VAR_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5282 #define DEF_FUNCTION_TYPE_VAR_11(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5283 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) NAME,
5284 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
5285 #include "builtin-types.def"
5286 #undef DEF_PRIMITIVE_TYPE
5287 #undef DEF_FUNCTION_TYPE_0
5288 #undef DEF_FUNCTION_TYPE_1
5289 #undef DEF_FUNCTION_TYPE_2
5290 #undef DEF_FUNCTION_TYPE_3
5291 #undef DEF_FUNCTION_TYPE_4
5292 #undef DEF_FUNCTION_TYPE_5
5293 #undef DEF_FUNCTION_TYPE_6
5294 #undef DEF_FUNCTION_TYPE_7
5295 #undef DEF_FUNCTION_TYPE_8
5296 #undef DEF_FUNCTION_TYPE_VAR_0
5297 #undef DEF_FUNCTION_TYPE_VAR_1
5298 #undef DEF_FUNCTION_TYPE_VAR_2
5299 #undef DEF_FUNCTION_TYPE_VAR_3
5300 #undef DEF_FUNCTION_TYPE_VAR_4
5301 #undef DEF_FUNCTION_TYPE_VAR_5
5302 #undef DEF_FUNCTION_TYPE_VAR_7
5303 #undef DEF_FUNCTION_TYPE_VAR_11
5304 #undef DEF_POINTER_TYPE
5308 typedef enum c_builtin_type builtin_type
;
5310 /* A temporary array for c_common_nodes_and_builtins. Used in
5311 communication with def_fn_type. */
5312 static tree builtin_types
[(int) BT_LAST
+ 1];
5314 /* A helper function for c_common_nodes_and_builtins. Build function type
5315 for DEF with return type RET and N arguments. If VAR is true, then the
5316 function should be variadic after those N arguments.
5318 Takes special care not to ICE if any of the types involved are
5319 error_mark_node, which indicates that said type is not in fact available
5320 (see builtin_type_for_size). In which case the function type as a whole
5321 should be error_mark_node. */
5324 def_fn_type (builtin_type def
, builtin_type ret
, bool var
, int n
, ...)
5327 tree
*args
= XALLOCAVEC (tree
, n
);
5332 for (i
= 0; i
< n
; ++i
)
5334 builtin_type a
= (builtin_type
) va_arg (list
, int);
5335 t
= builtin_types
[a
];
5336 if (t
== error_mark_node
)
5341 t
= builtin_types
[ret
];
5342 if (t
== error_mark_node
)
5345 t
= build_varargs_function_type_array (t
, n
, args
);
5347 t
= build_function_type_array (t
, n
, args
);
5350 builtin_types
[def
] = t
;
5354 /* Build builtin functions common to both C and C++ language
5358 c_define_builtins (tree va_list_ref_type_node
, tree va_list_arg_type_node
)
5360 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
5361 builtin_types[ENUM] = VALUE;
5362 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
5363 def_fn_type (ENUM, RETURN, 0, 0);
5364 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
5365 def_fn_type (ENUM, RETURN, 0, 1, ARG1);
5366 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
5367 def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
5368 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
5369 def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
5370 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
5371 def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
5372 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5373 def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
5374 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5376 def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
5377 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5379 def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
5380 #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5382 def_fn_type (ENUM, RETURN, 0, 8, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
5384 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
5385 def_fn_type (ENUM, RETURN, 1, 0);
5386 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
5387 def_fn_type (ENUM, RETURN, 1, 1, ARG1);
5388 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
5389 def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
5390 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
5391 def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
5392 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
5393 def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
5394 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5395 def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
5396 #define DEF_FUNCTION_TYPE_VAR_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5398 def_fn_type (ENUM, RETURN, 1, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
5399 #define DEF_FUNCTION_TYPE_VAR_11(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5400 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) \
5401 def_fn_type (ENUM, RETURN, 1, 11, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
5402 ARG7, ARG8, ARG9, ARG10, ARG11);
5403 #define DEF_POINTER_TYPE(ENUM, TYPE) \
5404 builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
5406 #include "builtin-types.def"
5408 #undef DEF_PRIMITIVE_TYPE
5409 #undef DEF_FUNCTION_TYPE_0
5410 #undef DEF_FUNCTION_TYPE_1
5411 #undef DEF_FUNCTION_TYPE_2
5412 #undef DEF_FUNCTION_TYPE_3
5413 #undef DEF_FUNCTION_TYPE_4
5414 #undef DEF_FUNCTION_TYPE_5
5415 #undef DEF_FUNCTION_TYPE_6
5416 #undef DEF_FUNCTION_TYPE_7
5417 #undef DEF_FUNCTION_TYPE_8
5418 #undef DEF_FUNCTION_TYPE_VAR_0
5419 #undef DEF_FUNCTION_TYPE_VAR_1
5420 #undef DEF_FUNCTION_TYPE_VAR_2
5421 #undef DEF_FUNCTION_TYPE_VAR_3
5422 #undef DEF_FUNCTION_TYPE_VAR_4
5423 #undef DEF_FUNCTION_TYPE_VAR_5
5424 #undef DEF_FUNCTION_TYPE_VAR_7
5425 #undef DEF_FUNCTION_TYPE_VAR_11
5426 #undef DEF_POINTER_TYPE
5427 builtin_types
[(int) BT_LAST
] = NULL_TREE
;
5429 c_init_attributes ();
5431 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P, \
5432 NONANSI_P, ATTRS, IMPLICIT, COND) \
5434 def_builtin_1 (ENUM, NAME, CLASS, \
5435 builtin_types[(int) TYPE], \
5436 builtin_types[(int) LIBTYPE], \
5437 BOTH_P, FALLBACK_P, NONANSI_P, \
5438 built_in_attributes[(int) ATTRS], IMPLICIT);
5439 #include "builtins.def"
5442 targetm
.init_builtins ();
5444 build_common_builtin_nodes ();
5447 cilk_init_builtins ();
5450 /* Like get_identifier, but avoid warnings about null arguments when
5451 the argument may be NULL for targets where GCC lacks stdint.h type
5455 c_get_ident (const char *id
)
5457 return get_identifier (id
);
5460 /* Build tree nodes and builtin functions common to both C and C++ language
5464 c_common_nodes_and_builtins (void)
5466 int char16_type_size
;
5467 int char32_type_size
;
5468 int wchar_type_size
;
5469 tree array_domain_type
;
5470 tree va_list_ref_type_node
;
5471 tree va_list_arg_type_node
;
5474 build_common_tree_nodes (flag_signed_char
, flag_short_double
);
5476 /* Define `int' and `char' first so that dbx will output them first. */
5477 record_builtin_type (RID_INT
, NULL
, integer_type_node
);
5478 record_builtin_type (RID_CHAR
, "char", char_type_node
);
5480 /* `signed' is the same as `int'. FIXME: the declarations of "signed",
5481 "unsigned long", "long long unsigned" and "unsigned short" were in C++
5482 but not C. Are the conditionals here needed? */
5483 if (c_dialect_cxx ())
5484 record_builtin_type (RID_SIGNED
, NULL
, integer_type_node
);
5485 record_builtin_type (RID_LONG
, "long int", long_integer_type_node
);
5486 record_builtin_type (RID_UNSIGNED
, "unsigned int", unsigned_type_node
);
5487 record_builtin_type (RID_MAX
, "long unsigned int",
5488 long_unsigned_type_node
);
5490 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
5494 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
5495 record_builtin_type ((enum rid
)(RID_FIRST_INT_N
+ i
), name
,
5496 int_n_trees
[i
].signed_type
);
5497 sprintf (name
, "__int%d unsigned", int_n_data
[i
].bitsize
);
5498 record_builtin_type (RID_MAX
, name
, int_n_trees
[i
].unsigned_type
);
5501 if (c_dialect_cxx ())
5502 record_builtin_type (RID_MAX
, "unsigned long", long_unsigned_type_node
);
5503 record_builtin_type (RID_MAX
, "long long int",
5504 long_long_integer_type_node
);
5505 record_builtin_type (RID_MAX
, "long long unsigned int",
5506 long_long_unsigned_type_node
);
5507 if (c_dialect_cxx ())
5508 record_builtin_type (RID_MAX
, "long long unsigned",
5509 long_long_unsigned_type_node
);
5510 record_builtin_type (RID_SHORT
, "short int", short_integer_type_node
);
5511 record_builtin_type (RID_MAX
, "short unsigned int",
5512 short_unsigned_type_node
);
5513 if (c_dialect_cxx ())
5514 record_builtin_type (RID_MAX
, "unsigned short",
5515 short_unsigned_type_node
);
5517 /* Define both `signed char' and `unsigned char'. */
5518 record_builtin_type (RID_MAX
, "signed char", signed_char_type_node
);
5519 record_builtin_type (RID_MAX
, "unsigned char", unsigned_char_type_node
);
5521 /* These are types that c_common_type_for_size and
5522 c_common_type_for_mode use. */
5523 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5524 TYPE_DECL
, NULL_TREE
,
5526 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5527 TYPE_DECL
, NULL_TREE
,
5529 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5530 TYPE_DECL
, NULL_TREE
,
5532 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5533 TYPE_DECL
, NULL_TREE
,
5535 #if HOST_BITS_PER_WIDE_INT >= 64
5536 /* Note that this is different than the __int128 type that's part of
5537 the generic __intN support. */
5538 if (targetm
.scalar_mode_supported_p (TImode
))
5539 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5541 get_identifier ("__int128_t"),
5544 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5545 TYPE_DECL
, NULL_TREE
,
5546 unsigned_intQI_type_node
));
5547 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5548 TYPE_DECL
, NULL_TREE
,
5549 unsigned_intHI_type_node
));
5550 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5551 TYPE_DECL
, NULL_TREE
,
5552 unsigned_intSI_type_node
));
5553 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5554 TYPE_DECL
, NULL_TREE
,
5555 unsigned_intDI_type_node
));
5556 #if HOST_BITS_PER_WIDE_INT >= 64
5557 if (targetm
.scalar_mode_supported_p (TImode
))
5558 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5560 get_identifier ("__uint128_t"),
5561 unsigned_intTI_type_node
));
5564 /* Create the widest literal types. */
5565 widest_integer_literal_type_node
5566 = make_signed_type (HOST_BITS_PER_WIDE_INT
* 2);
5567 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5568 TYPE_DECL
, NULL_TREE
,
5569 widest_integer_literal_type_node
));
5571 widest_unsigned_literal_type_node
5572 = make_unsigned_type (HOST_BITS_PER_WIDE_INT
* 2);
5573 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5574 TYPE_DECL
, NULL_TREE
,
5575 widest_unsigned_literal_type_node
));
5577 signed_size_type_node
= c_common_signed_type (size_type_node
);
5580 TREE_TYPE (identifier_global_value (get_identifier (PID_TYPE
)));
5582 record_builtin_type (RID_FLOAT
, NULL
, float_type_node
);
5583 record_builtin_type (RID_DOUBLE
, NULL
, double_type_node
);
5584 record_builtin_type (RID_MAX
, "long double", long_double_type_node
);
5586 /* Only supported decimal floating point extension if the target
5587 actually supports underlying modes. */
5588 if (targetm
.scalar_mode_supported_p (SDmode
)
5589 && targetm
.scalar_mode_supported_p (DDmode
)
5590 && targetm
.scalar_mode_supported_p (TDmode
))
5592 record_builtin_type (RID_DFLOAT32
, NULL
, dfloat32_type_node
);
5593 record_builtin_type (RID_DFLOAT64
, NULL
, dfloat64_type_node
);
5594 record_builtin_type (RID_DFLOAT128
, NULL
, dfloat128_type_node
);
5597 if (targetm
.fixed_point_supported_p ())
5599 record_builtin_type (RID_MAX
, "short _Fract", short_fract_type_node
);
5600 record_builtin_type (RID_FRACT
, NULL
, fract_type_node
);
5601 record_builtin_type (RID_MAX
, "long _Fract", long_fract_type_node
);
5602 record_builtin_type (RID_MAX
, "long long _Fract",
5603 long_long_fract_type_node
);
5604 record_builtin_type (RID_MAX
, "unsigned short _Fract",
5605 unsigned_short_fract_type_node
);
5606 record_builtin_type (RID_MAX
, "unsigned _Fract",
5607 unsigned_fract_type_node
);
5608 record_builtin_type (RID_MAX
, "unsigned long _Fract",
5609 unsigned_long_fract_type_node
);
5610 record_builtin_type (RID_MAX
, "unsigned long long _Fract",
5611 unsigned_long_long_fract_type_node
);
5612 record_builtin_type (RID_MAX
, "_Sat short _Fract",
5613 sat_short_fract_type_node
);
5614 record_builtin_type (RID_MAX
, "_Sat _Fract", sat_fract_type_node
);
5615 record_builtin_type (RID_MAX
, "_Sat long _Fract",
5616 sat_long_fract_type_node
);
5617 record_builtin_type (RID_MAX
, "_Sat long long _Fract",
5618 sat_long_long_fract_type_node
);
5619 record_builtin_type (RID_MAX
, "_Sat unsigned short _Fract",
5620 sat_unsigned_short_fract_type_node
);
5621 record_builtin_type (RID_MAX
, "_Sat unsigned _Fract",
5622 sat_unsigned_fract_type_node
);
5623 record_builtin_type (RID_MAX
, "_Sat unsigned long _Fract",
5624 sat_unsigned_long_fract_type_node
);
5625 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Fract",
5626 sat_unsigned_long_long_fract_type_node
);
5627 record_builtin_type (RID_MAX
, "short _Accum", short_accum_type_node
);
5628 record_builtin_type (RID_ACCUM
, NULL
, accum_type_node
);
5629 record_builtin_type (RID_MAX
, "long _Accum", long_accum_type_node
);
5630 record_builtin_type (RID_MAX
, "long long _Accum",
5631 long_long_accum_type_node
);
5632 record_builtin_type (RID_MAX
, "unsigned short _Accum",
5633 unsigned_short_accum_type_node
);
5634 record_builtin_type (RID_MAX
, "unsigned _Accum",
5635 unsigned_accum_type_node
);
5636 record_builtin_type (RID_MAX
, "unsigned long _Accum",
5637 unsigned_long_accum_type_node
);
5638 record_builtin_type (RID_MAX
, "unsigned long long _Accum",
5639 unsigned_long_long_accum_type_node
);
5640 record_builtin_type (RID_MAX
, "_Sat short _Accum",
5641 sat_short_accum_type_node
);
5642 record_builtin_type (RID_MAX
, "_Sat _Accum", sat_accum_type_node
);
5643 record_builtin_type (RID_MAX
, "_Sat long _Accum",
5644 sat_long_accum_type_node
);
5645 record_builtin_type (RID_MAX
, "_Sat long long _Accum",
5646 sat_long_long_accum_type_node
);
5647 record_builtin_type (RID_MAX
, "_Sat unsigned short _Accum",
5648 sat_unsigned_short_accum_type_node
);
5649 record_builtin_type (RID_MAX
, "_Sat unsigned _Accum",
5650 sat_unsigned_accum_type_node
);
5651 record_builtin_type (RID_MAX
, "_Sat unsigned long _Accum",
5652 sat_unsigned_long_accum_type_node
);
5653 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Accum",
5654 sat_unsigned_long_long_accum_type_node
);
5658 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5660 get_identifier ("complex int"),
5661 complex_integer_type_node
));
5662 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5664 get_identifier ("complex float"),
5665 complex_float_type_node
));
5666 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5668 get_identifier ("complex double"),
5669 complex_double_type_node
));
5670 lang_hooks
.decls
.pushdecl
5671 (build_decl (UNKNOWN_LOCATION
,
5672 TYPE_DECL
, get_identifier ("complex long double"),
5673 complex_long_double_type_node
));
5675 if (c_dialect_cxx ())
5676 /* For C++, make fileptr_type_node a distinct void * type until
5677 FILE type is defined. */
5678 fileptr_type_node
= build_variant_type_copy (ptr_type_node
);
5680 record_builtin_type (RID_VOID
, NULL
, void_type_node
);
5682 /* Set the TYPE_NAME for any variants that were built before
5683 record_builtin_type gave names to the built-in types. */
5685 tree void_name
= TYPE_NAME (void_type_node
);
5686 TYPE_NAME (void_type_node
) = NULL_TREE
;
5687 TYPE_NAME (build_qualified_type (void_type_node
, TYPE_QUAL_CONST
))
5689 TYPE_NAME (void_type_node
) = void_name
;
5692 void_list_node
= build_void_list_node ();
5694 /* Make a type to be the domain of a few array types
5695 whose domains don't really matter.
5696 200 is small enough that it always fits in size_t
5697 and large enough that it can hold most function names for the
5698 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
5699 array_domain_type
= build_index_type (size_int (200));
5701 /* Make a type for arrays of characters.
5702 With luck nothing will ever really depend on the length of this
5704 char_array_type_node
5705 = build_array_type (char_type_node
, array_domain_type
);
5707 string_type_node
= build_pointer_type (char_type_node
);
5708 const_string_type_node
5709 = build_pointer_type (build_qualified_type
5710 (char_type_node
, TYPE_QUAL_CONST
));
5712 /* This is special for C++ so functions can be overloaded. */
5713 wchar_type_node
= get_identifier (MODIFIED_WCHAR_TYPE
);
5714 wchar_type_node
= TREE_TYPE (identifier_global_value (wchar_type_node
));
5715 wchar_type_size
= TYPE_PRECISION (wchar_type_node
);
5716 underlying_wchar_type_node
= wchar_type_node
;
5717 if (c_dialect_cxx ())
5719 if (TYPE_UNSIGNED (wchar_type_node
))
5720 wchar_type_node
= make_unsigned_type (wchar_type_size
);
5722 wchar_type_node
= make_signed_type (wchar_type_size
);
5723 record_builtin_type (RID_WCHAR
, "wchar_t", wchar_type_node
);
5726 /* This is for wide string constants. */
5727 wchar_array_type_node
5728 = build_array_type (wchar_type_node
, array_domain_type
);
5730 /* Define 'char16_t'. */
5731 char16_type_node
= get_identifier (CHAR16_TYPE
);
5732 char16_type_node
= TREE_TYPE (identifier_global_value (char16_type_node
));
5733 char16_type_size
= TYPE_PRECISION (char16_type_node
);
5734 if (c_dialect_cxx ())
5736 char16_type_node
= make_unsigned_type (char16_type_size
);
5738 if (cxx_dialect
>= cxx11
)
5739 record_builtin_type (RID_CHAR16
, "char16_t", char16_type_node
);
5742 /* This is for UTF-16 string constants. */
5743 char16_array_type_node
5744 = build_array_type (char16_type_node
, array_domain_type
);
5746 /* Define 'char32_t'. */
5747 char32_type_node
= get_identifier (CHAR32_TYPE
);
5748 char32_type_node
= TREE_TYPE (identifier_global_value (char32_type_node
));
5749 char32_type_size
= TYPE_PRECISION (char32_type_node
);
5750 if (c_dialect_cxx ())
5752 char32_type_node
= make_unsigned_type (char32_type_size
);
5754 if (cxx_dialect
>= cxx11
)
5755 record_builtin_type (RID_CHAR32
, "char32_t", char32_type_node
);
5758 /* This is for UTF-32 string constants. */
5759 char32_array_type_node
5760 = build_array_type (char32_type_node
, array_domain_type
);
5763 TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE
)));
5766 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE
)));
5768 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE
)));
5770 if (SIG_ATOMIC_TYPE
)
5771 sig_atomic_type_node
=
5772 TREE_TYPE (identifier_global_value (c_get_ident (SIG_ATOMIC_TYPE
)));
5775 TREE_TYPE (identifier_global_value (c_get_ident (INT8_TYPE
)));
5778 TREE_TYPE (identifier_global_value (c_get_ident (INT16_TYPE
)));
5781 TREE_TYPE (identifier_global_value (c_get_ident (INT32_TYPE
)));
5784 TREE_TYPE (identifier_global_value (c_get_ident (INT64_TYPE
)));
5787 TREE_TYPE (identifier_global_value (c_get_ident (UINT8_TYPE
)));
5789 c_uint16_type_node
= uint16_type_node
=
5790 TREE_TYPE (identifier_global_value (c_get_ident (UINT16_TYPE
)));
5792 c_uint32_type_node
= uint32_type_node
=
5793 TREE_TYPE (identifier_global_value (c_get_ident (UINT32_TYPE
)));
5795 c_uint64_type_node
= uint64_type_node
=
5796 TREE_TYPE (identifier_global_value (c_get_ident (UINT64_TYPE
)));
5797 if (INT_LEAST8_TYPE
)
5798 int_least8_type_node
=
5799 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST8_TYPE
)));
5800 if (INT_LEAST16_TYPE
)
5801 int_least16_type_node
=
5802 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST16_TYPE
)));
5803 if (INT_LEAST32_TYPE
)
5804 int_least32_type_node
=
5805 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST32_TYPE
)));
5806 if (INT_LEAST64_TYPE
)
5807 int_least64_type_node
=
5808 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST64_TYPE
)));
5809 if (UINT_LEAST8_TYPE
)
5810 uint_least8_type_node
=
5811 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST8_TYPE
)));
5812 if (UINT_LEAST16_TYPE
)
5813 uint_least16_type_node
=
5814 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST16_TYPE
)));
5815 if (UINT_LEAST32_TYPE
)
5816 uint_least32_type_node
=
5817 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST32_TYPE
)));
5818 if (UINT_LEAST64_TYPE
)
5819 uint_least64_type_node
=
5820 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST64_TYPE
)));
5822 int_fast8_type_node
=
5823 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST8_TYPE
)));
5824 if (INT_FAST16_TYPE
)
5825 int_fast16_type_node
=
5826 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST16_TYPE
)));
5827 if (INT_FAST32_TYPE
)
5828 int_fast32_type_node
=
5829 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST32_TYPE
)));
5830 if (INT_FAST64_TYPE
)
5831 int_fast64_type_node
=
5832 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST64_TYPE
)));
5833 if (UINT_FAST8_TYPE
)
5834 uint_fast8_type_node
=
5835 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST8_TYPE
)));
5836 if (UINT_FAST16_TYPE
)
5837 uint_fast16_type_node
=
5838 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST16_TYPE
)));
5839 if (UINT_FAST32_TYPE
)
5840 uint_fast32_type_node
=
5841 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST32_TYPE
)));
5842 if (UINT_FAST64_TYPE
)
5843 uint_fast64_type_node
=
5844 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST64_TYPE
)));
5847 TREE_TYPE (identifier_global_value (c_get_ident (INTPTR_TYPE
)));
5850 TREE_TYPE (identifier_global_value (c_get_ident (UINTPTR_TYPE
)));
5852 default_function_type
5853 = build_varargs_function_type_list (integer_type_node
, NULL_TREE
);
5855 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE
)));
5856 unsigned_ptrdiff_type_node
= c_common_unsigned_type (ptrdiff_type_node
);
5858 lang_hooks
.decls
.pushdecl
5859 (build_decl (UNKNOWN_LOCATION
,
5860 TYPE_DECL
, get_identifier ("__builtin_va_list"),
5861 va_list_type_node
));
5862 if (targetm
.enum_va_list_p
)
5868 for (l
= 0; targetm
.enum_va_list_p (l
, &pname
, &ptype
); ++l
)
5870 lang_hooks
.decls
.pushdecl
5871 (build_decl (UNKNOWN_LOCATION
,
5872 TYPE_DECL
, get_identifier (pname
),
5878 if (TREE_CODE (va_list_type_node
) == ARRAY_TYPE
)
5880 va_list_arg_type_node
= va_list_ref_type_node
=
5881 build_pointer_type (TREE_TYPE (va_list_type_node
));
5885 va_list_arg_type_node
= va_list_type_node
;
5886 va_list_ref_type_node
= build_reference_type (va_list_type_node
);
5889 if (!flag_preprocess_only
)
5890 c_define_builtins (va_list_ref_type_node
, va_list_arg_type_node
);
5892 main_identifier_node
= get_identifier ("main");
5894 /* Create the built-in __null node. It is important that this is
5896 null_node
= make_int_cst (1, 1);
5897 TREE_TYPE (null_node
) = c_common_type_for_size (POINTER_SIZE
, 0);
5899 /* Since builtin_types isn't gc'ed, don't export these nodes. */
5900 memset (builtin_types
, 0, sizeof (builtin_types
));
5903 /* The number of named compound-literals generated thus far. */
5904 static GTY(()) int compound_literal_number
;
5906 /* Set DECL_NAME for DECL, a VAR_DECL for a compound-literal. */
5909 set_compound_literal_name (tree decl
)
5912 ASM_FORMAT_PRIVATE_NAME (name
, "__compound_literal",
5913 compound_literal_number
);
5914 compound_literal_number
++;
5915 DECL_NAME (decl
) = get_identifier (name
);
5919 build_va_arg (location_t loc
, tree expr
, tree type
)
5921 /* In gimplify_va_arg_expr we take the address of the ap argument, mark it
5923 mark_addressable (expr
);
5925 expr
= build1 (VA_ARG_EXPR
, type
, expr
);
5926 SET_EXPR_LOCATION (expr
, loc
);
5931 /* Linked list of disabled built-in functions. */
5933 typedef struct disabled_builtin
5936 struct disabled_builtin
*next
;
5938 static disabled_builtin
*disabled_builtins
= NULL
;
5940 static bool builtin_function_disabled_p (const char *);
5942 /* Disable a built-in function specified by -fno-builtin-NAME. If NAME
5943 begins with "__builtin_", give an error. */
5946 disable_builtin_function (const char *name
)
5948 if (strncmp (name
, "__builtin_", strlen ("__builtin_")) == 0)
5949 error ("cannot disable built-in function %qs", name
);
5952 disabled_builtin
*new_disabled_builtin
= XNEW (disabled_builtin
);
5953 new_disabled_builtin
->name
= name
;
5954 new_disabled_builtin
->next
= disabled_builtins
;
5955 disabled_builtins
= new_disabled_builtin
;
5960 /* Return true if the built-in function NAME has been disabled, false
5964 builtin_function_disabled_p (const char *name
)
5966 disabled_builtin
*p
;
5967 for (p
= disabled_builtins
; p
!= NULL
; p
= p
->next
)
5969 if (strcmp (name
, p
->name
) == 0)
5976 /* Worker for DEF_BUILTIN.
5977 Possibly define a builtin function with one or two names.
5978 Does not declare a non-__builtin_ function if flag_no_builtin, or if
5979 nonansi_p and flag_no_nonansi_builtin. */
5982 def_builtin_1 (enum built_in_function fncode
,
5984 enum built_in_class fnclass
,
5985 tree fntype
, tree libtype
,
5986 bool both_p
, bool fallback_p
, bool nonansi_p
,
5987 tree fnattrs
, bool implicit_p
)
5990 const char *libname
;
5992 if (fntype
== error_mark_node
)
5995 gcc_assert ((!both_p
&& !fallback_p
)
5996 || !strncmp (name
, "__builtin_",
5997 strlen ("__builtin_")));
5999 libname
= name
+ strlen ("__builtin_");
6000 decl
= add_builtin_function (name
, fntype
, fncode
, fnclass
,
6001 (fallback_p
? libname
: NULL
),
6004 set_builtin_decl (fncode
, decl
, implicit_p
);
6007 && !flag_no_builtin
&& !builtin_function_disabled_p (libname
)
6008 && !(nonansi_p
&& flag_no_nonansi_builtin
))
6009 add_builtin_function (libname
, libtype
, fncode
, fnclass
,
6013 /* Nonzero if the type T promotes to int. This is (nearly) the
6014 integral promotions defined in ISO C99 6.3.1.1/2. */
6017 c_promoting_integer_type_p (const_tree t
)
6019 switch (TREE_CODE (t
))
6022 return (TYPE_MAIN_VARIANT (t
) == char_type_node
6023 || TYPE_MAIN_VARIANT (t
) == signed_char_type_node
6024 || TYPE_MAIN_VARIANT (t
) == unsigned_char_type_node
6025 || TYPE_MAIN_VARIANT (t
) == short_integer_type_node
6026 || TYPE_MAIN_VARIANT (t
) == short_unsigned_type_node
6027 || TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
));
6030 /* ??? Technically all enumerations not larger than an int
6031 promote to an int. But this is used along code paths
6032 that only want to notice a size change. */
6033 return TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
);
6043 /* Return 1 if PARMS specifies a fixed number of parameters
6044 and none of their types is affected by default promotions. */
6047 self_promoting_args_p (const_tree parms
)
6050 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
6052 tree type
= TREE_VALUE (t
);
6054 if (type
== error_mark_node
)
6057 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
6063 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
6066 if (c_promoting_integer_type_p (type
))
6072 /* Recursively remove any '*' or '&' operator from TYPE. */
6074 strip_pointer_operator (tree t
)
6076 while (POINTER_TYPE_P (t
))
6081 /* Recursively remove pointer or array type from TYPE. */
6083 strip_pointer_or_array_types (tree t
)
6085 while (TREE_CODE (t
) == ARRAY_TYPE
|| POINTER_TYPE_P (t
))
6090 /* Used to compare case labels. K1 and K2 are actually tree nodes
6091 representing case labels, or NULL_TREE for a `default' label.
6092 Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after
6093 K2, and 0 if K1 and K2 are equal. */
6096 case_compare (splay_tree_key k1
, splay_tree_key k2
)
6098 /* Consider a NULL key (such as arises with a `default' label) to be
6099 smaller than anything else. */
6105 return tree_int_cst_compare ((tree
) k1
, (tree
) k2
);
6108 /* Process a case label, located at LOC, for the range LOW_VALUE
6109 ... HIGH_VALUE. If LOW_VALUE and HIGH_VALUE are both NULL_TREE
6110 then this case label is actually a `default' label. If only
6111 HIGH_VALUE is NULL_TREE, then case label was declared using the
6112 usual C/C++ syntax, rather than the GNU case range extension.
6113 CASES is a tree containing all the case ranges processed so far;
6114 COND is the condition for the switch-statement itself. Returns the
6115 CASE_LABEL_EXPR created, or ERROR_MARK_NODE if no CASE_LABEL_EXPR
6119 c_add_case_label (location_t loc
, splay_tree cases
, tree cond
, tree orig_type
,
6120 tree low_value
, tree high_value
)
6125 splay_tree_node node
;
6127 /* Create the LABEL_DECL itself. */
6128 label
= create_artificial_label (loc
);
6130 /* If there was an error processing the switch condition, bail now
6131 before we get more confused. */
6132 if (!cond
|| cond
== error_mark_node
)
6135 if ((low_value
&& TREE_TYPE (low_value
)
6136 && POINTER_TYPE_P (TREE_TYPE (low_value
)))
6137 || (high_value
&& TREE_TYPE (high_value
)
6138 && POINTER_TYPE_P (TREE_TYPE (high_value
))))
6140 error_at (loc
, "pointers are not permitted as case values");
6144 /* Case ranges are a GNU extension. */
6146 pedwarn (loc
, OPT_Wpedantic
,
6147 "range expressions in switch statements are non-standard");
6149 type
= TREE_TYPE (cond
);
6152 low_value
= check_case_value (loc
, low_value
);
6153 low_value
= convert_and_check (loc
, type
, low_value
);
6154 if (low_value
== error_mark_node
)
6159 high_value
= check_case_value (loc
, high_value
);
6160 high_value
= convert_and_check (loc
, type
, high_value
);
6161 if (high_value
== error_mark_node
)
6165 if (low_value
&& high_value
)
6167 /* If the LOW_VALUE and HIGH_VALUE are the same, then this isn't
6168 really a case range, even though it was written that way.
6169 Remove the HIGH_VALUE to simplify later processing. */
6170 if (tree_int_cst_equal (low_value
, high_value
))
6171 high_value
= NULL_TREE
;
6172 else if (!tree_int_cst_lt (low_value
, high_value
))
6173 warning_at (loc
, 0, "empty range specified");
6176 /* See if the case is in range of the type of the original testing
6177 expression. If both low_value and high_value are out of range,
6178 don't insert the case label and return NULL_TREE. */
6180 && !check_case_bounds (loc
, type
, orig_type
,
6181 &low_value
, high_value
? &high_value
: NULL
))
6184 /* Look up the LOW_VALUE in the table of case labels we already
6186 node
= splay_tree_lookup (cases
, (splay_tree_key
) low_value
);
6187 /* If there was not an exact match, check for overlapping ranges.
6188 There's no need to do this if there's no LOW_VALUE or HIGH_VALUE;
6189 that's a `default' label and the only overlap is an exact match. */
6190 if (!node
&& (low_value
|| high_value
))
6192 splay_tree_node low_bound
;
6193 splay_tree_node high_bound
;
6195 /* Even though there wasn't an exact match, there might be an
6196 overlap between this case range and another case range.
6197 Since we've (inductively) not allowed any overlapping case
6198 ranges, we simply need to find the greatest low case label
6199 that is smaller that LOW_VALUE, and the smallest low case
6200 label that is greater than LOW_VALUE. If there is an overlap
6201 it will occur in one of these two ranges. */
6202 low_bound
= splay_tree_predecessor (cases
,
6203 (splay_tree_key
) low_value
);
6204 high_bound
= splay_tree_successor (cases
,
6205 (splay_tree_key
) low_value
);
6207 /* Check to see if the LOW_BOUND overlaps. It is smaller than
6208 the LOW_VALUE, so there is no need to check unless the
6209 LOW_BOUND is in fact itself a case range. */
6211 && CASE_HIGH ((tree
) low_bound
->value
)
6212 && tree_int_cst_compare (CASE_HIGH ((tree
) low_bound
->value
),
6215 /* Check to see if the HIGH_BOUND overlaps. The low end of that
6216 range is bigger than the low end of the current range, so we
6217 are only interested if the current range is a real range, and
6218 not an ordinary case label. */
6221 && (tree_int_cst_compare ((tree
) high_bound
->key
,
6226 /* If there was an overlap, issue an error. */
6229 tree duplicate
= CASE_LABEL ((tree
) node
->value
);
6233 error_at (loc
, "duplicate (or overlapping) case value");
6234 error_at (DECL_SOURCE_LOCATION (duplicate
),
6235 "this is the first entry overlapping that value");
6239 error_at (loc
, "duplicate case value") ;
6240 error_at (DECL_SOURCE_LOCATION (duplicate
), "previously used here");
6244 error_at (loc
, "multiple default labels in one switch");
6245 error_at (DECL_SOURCE_LOCATION (duplicate
),
6246 "this is the first default label");
6251 /* Add a CASE_LABEL to the statement-tree. */
6252 case_label
= add_stmt (build_case_label (low_value
, high_value
, label
));
6253 /* Register this case label in the splay tree. */
6254 splay_tree_insert (cases
,
6255 (splay_tree_key
) low_value
,
6256 (splay_tree_value
) case_label
);
6261 /* Add a label so that the back-end doesn't think that the beginning of
6262 the switch is unreachable. Note that we do not add a case label, as
6263 that just leads to duplicates and thence to failure later on. */
6266 tree t
= create_artificial_label (loc
);
6267 add_stmt (build_stmt (loc
, LABEL_EXPR
, t
));
6269 return error_mark_node
;
6272 /* Subroutines of c_do_switch_warnings, called via splay_tree_foreach.
6273 Used to verify that case values match up with enumerator values. */
6276 match_case_to_enum_1 (tree key
, tree type
, tree label
)
6278 char buf
[WIDE_INT_PRINT_BUFFER_SIZE
];
6280 if (tree_fits_uhwi_p (key
))
6281 print_dec (key
, buf
, UNSIGNED
);
6282 else if (tree_fits_shwi_p (key
))
6283 print_dec (key
, buf
, SIGNED
);
6285 print_hex (key
, buf
);
6287 if (TYPE_NAME (type
) == 0)
6288 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
6289 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
6290 "case value %qs not in enumerated type",
6293 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
6294 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
6295 "case value %qs not in enumerated type %qT",
6299 /* Subroutine of c_do_switch_warnings, called via splay_tree_foreach.
6300 Used to verify that case values match up with enumerator values. */
6303 match_case_to_enum (splay_tree_node node
, void *data
)
6305 tree label
= (tree
) node
->value
;
6306 tree type
= (tree
) data
;
6308 /* Skip default case. */
6309 if (!CASE_LOW (label
))
6312 /* If CASE_LOW_SEEN is not set, that means CASE_LOW did not appear
6313 when we did our enum->case scan. Reset our scratch bit after. */
6314 if (!CASE_LOW_SEEN (label
))
6315 match_case_to_enum_1 (CASE_LOW (label
), type
, label
);
6317 CASE_LOW_SEEN (label
) = 0;
6319 /* If CASE_HIGH is non-null, we have a range. If CASE_HIGH_SEEN is
6320 not set, that means that CASE_HIGH did not appear when we did our
6321 enum->case scan. Reset our scratch bit after. */
6322 if (CASE_HIGH (label
))
6324 if (!CASE_HIGH_SEEN (label
))
6325 match_case_to_enum_1 (CASE_HIGH (label
), type
, label
);
6327 CASE_HIGH_SEEN (label
) = 0;
6333 /* Handle -Wswitch*. Called from the front end after parsing the
6334 switch construct. */
6335 /* ??? Should probably be somewhere generic, since other languages
6336 besides C and C++ would want this. At the moment, however, C/C++
6337 are the only tree-ssa languages that support enumerations at all,
6338 so the point is moot. */
6341 c_do_switch_warnings (splay_tree cases
, location_t switch_location
,
6342 tree type
, tree cond
)
6344 splay_tree_node default_node
;
6345 splay_tree_node node
;
6348 if (!warn_switch
&& !warn_switch_enum
&& !warn_switch_default
)
6351 default_node
= splay_tree_lookup (cases
, (splay_tree_key
) NULL
);
6353 warning_at (switch_location
, OPT_Wswitch_default
,
6354 "switch missing default case");
6356 /* From here on, we only care about about enumerated types. */
6357 if (!type
|| TREE_CODE (type
) != ENUMERAL_TYPE
)
6360 /* From here on, we only care about -Wswitch and -Wswitch-enum. */
6361 if (!warn_switch_enum
&& !warn_switch
)
6364 /* Check the cases. Warn about case values which are not members of
6365 the enumerated type. For -Wswitch-enum, or for -Wswitch when
6366 there is no default case, check that exactly all enumeration
6367 literals are covered by the cases. */
6369 /* Clearing COND if it is not an integer constant simplifies
6370 the tests inside the loop below. */
6371 if (TREE_CODE (cond
) != INTEGER_CST
)
6374 /* The time complexity here is O(N*lg(N)) worst case, but for the
6375 common case of monotonically increasing enumerators, it is
6376 O(N), since the nature of the splay tree will keep the next
6377 element adjacent to the root at all times. */
6379 for (chain
= TYPE_VALUES (type
); chain
; chain
= TREE_CHAIN (chain
))
6381 tree value
= TREE_VALUE (chain
);
6382 if (TREE_CODE (value
) == CONST_DECL
)
6383 value
= DECL_INITIAL (value
);
6384 node
= splay_tree_lookup (cases
, (splay_tree_key
) value
);
6387 /* Mark the CASE_LOW part of the case entry as seen. */
6388 tree label
= (tree
) node
->value
;
6389 CASE_LOW_SEEN (label
) = 1;
6393 /* Even though there wasn't an exact match, there might be a
6394 case range which includes the enumerator's value. */
6395 node
= splay_tree_predecessor (cases
, (splay_tree_key
) value
);
6396 if (node
&& CASE_HIGH ((tree
) node
->value
))
6398 tree label
= (tree
) node
->value
;
6399 int cmp
= tree_int_cst_compare (CASE_HIGH (label
), value
);
6402 /* If we match the upper bound exactly, mark the CASE_HIGH
6403 part of the case entry as seen. */
6405 CASE_HIGH_SEEN (label
) = 1;
6410 /* We've now determined that this enumerated literal isn't
6411 handled by the case labels of the switch statement. */
6413 /* If the switch expression is a constant, we only really care
6414 about whether that constant is handled by the switch. */
6415 if (cond
&& tree_int_cst_compare (cond
, value
))
6418 /* If there is a default_node, the only relevant option is
6419 Wswitch-enum. Otherwise, if both are enabled then we prefer
6420 to warn using -Wswitch because -Wswitch is enabled by -Wall
6421 while -Wswitch-enum is explicit. */
6422 warning_at (switch_location
,
6423 (default_node
|| !warn_switch
6426 "enumeration value %qE not handled in switch",
6427 TREE_PURPOSE (chain
));
6430 /* Warn if there are case expressions that don't correspond to
6431 enumerators. This can occur since C and C++ don't enforce
6432 type-checking of assignments to enumeration variables.
6434 The time complexity here is now always O(N) worst case, since
6435 we should have marked both the lower bound and upper bound of
6436 every disjoint case label, with CASE_LOW_SEEN and CASE_HIGH_SEEN
6437 above. This scan also resets those fields. */
6439 splay_tree_foreach (cases
, match_case_to_enum
, type
);
6442 /* Finish an expression taking the address of LABEL (an
6443 IDENTIFIER_NODE). Returns an expression for the address.
6445 LOC is the location for the expression returned. */
6448 finish_label_address_expr (tree label
, location_t loc
)
6452 pedwarn (input_location
, OPT_Wpedantic
, "taking the address of a label is non-standard");
6454 if (label
== error_mark_node
)
6455 return error_mark_node
;
6457 label
= lookup_label (label
);
6458 if (label
== NULL_TREE
)
6459 result
= null_pointer_node
;
6462 TREE_USED (label
) = 1;
6463 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
6464 /* The current function is not necessarily uninlinable.
6465 Computed gotos are incompatible with inlining, but the value
6466 here could be used only in a diagnostic, for example. */
6467 protected_set_expr_location (result
, loc
);
6474 /* Given a boolean expression ARG, return a tree representing an increment
6475 or decrement (as indicated by CODE) of ARG. The front end must check for
6476 invalid cases (e.g., decrement in C++). */
6478 boolean_increment (enum tree_code code
, tree arg
)
6481 tree true_res
= build_int_cst (TREE_TYPE (arg
), 1);
6483 arg
= stabilize_reference (arg
);
6486 case PREINCREMENT_EXPR
:
6487 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
6489 case POSTINCREMENT_EXPR
:
6490 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
6491 arg
= save_expr (arg
);
6492 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
6493 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
6495 case PREDECREMENT_EXPR
:
6496 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
6497 invert_truthvalue_loc (input_location
, arg
));
6499 case POSTDECREMENT_EXPR
:
6500 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
6501 invert_truthvalue_loc (input_location
, arg
));
6502 arg
= save_expr (arg
);
6503 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
6504 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
6509 TREE_SIDE_EFFECTS (val
) = 1;
6513 /* Built-in macros for stddef.h and stdint.h, that require macros
6514 defined in this file. */
6516 c_stddef_cpp_builtins(void)
6518 builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE
, 0);
6519 builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE
, 0);
6520 builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE
, 0);
6521 builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE
, 0);
6522 builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE
, 0);
6523 builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE
, 0);
6524 builtin_define_with_value ("__CHAR16_TYPE__", CHAR16_TYPE
, 0);
6525 builtin_define_with_value ("__CHAR32_TYPE__", CHAR32_TYPE
, 0);
6526 if (SIG_ATOMIC_TYPE
)
6527 builtin_define_with_value ("__SIG_ATOMIC_TYPE__", SIG_ATOMIC_TYPE
, 0);
6529 builtin_define_with_value ("__INT8_TYPE__", INT8_TYPE
, 0);
6531 builtin_define_with_value ("__INT16_TYPE__", INT16_TYPE
, 0);
6533 builtin_define_with_value ("__INT32_TYPE__", INT32_TYPE
, 0);
6535 builtin_define_with_value ("__INT64_TYPE__", INT64_TYPE
, 0);
6537 builtin_define_with_value ("__UINT8_TYPE__", UINT8_TYPE
, 0);
6539 builtin_define_with_value ("__UINT16_TYPE__", UINT16_TYPE
, 0);
6541 builtin_define_with_value ("__UINT32_TYPE__", UINT32_TYPE
, 0);
6543 builtin_define_with_value ("__UINT64_TYPE__", UINT64_TYPE
, 0);
6544 if (INT_LEAST8_TYPE
)
6545 builtin_define_with_value ("__INT_LEAST8_TYPE__", INT_LEAST8_TYPE
, 0);
6546 if (INT_LEAST16_TYPE
)
6547 builtin_define_with_value ("__INT_LEAST16_TYPE__", INT_LEAST16_TYPE
, 0);
6548 if (INT_LEAST32_TYPE
)
6549 builtin_define_with_value ("__INT_LEAST32_TYPE__", INT_LEAST32_TYPE
, 0);
6550 if (INT_LEAST64_TYPE
)
6551 builtin_define_with_value ("__INT_LEAST64_TYPE__", INT_LEAST64_TYPE
, 0);
6552 if (UINT_LEAST8_TYPE
)
6553 builtin_define_with_value ("__UINT_LEAST8_TYPE__", UINT_LEAST8_TYPE
, 0);
6554 if (UINT_LEAST16_TYPE
)
6555 builtin_define_with_value ("__UINT_LEAST16_TYPE__", UINT_LEAST16_TYPE
, 0);
6556 if (UINT_LEAST32_TYPE
)
6557 builtin_define_with_value ("__UINT_LEAST32_TYPE__", UINT_LEAST32_TYPE
, 0);
6558 if (UINT_LEAST64_TYPE
)
6559 builtin_define_with_value ("__UINT_LEAST64_TYPE__", UINT_LEAST64_TYPE
, 0);
6561 builtin_define_with_value ("__INT_FAST8_TYPE__", INT_FAST8_TYPE
, 0);
6562 if (INT_FAST16_TYPE
)
6563 builtin_define_with_value ("__INT_FAST16_TYPE__", INT_FAST16_TYPE
, 0);
6564 if (INT_FAST32_TYPE
)
6565 builtin_define_with_value ("__INT_FAST32_TYPE__", INT_FAST32_TYPE
, 0);
6566 if (INT_FAST64_TYPE
)
6567 builtin_define_with_value ("__INT_FAST64_TYPE__", INT_FAST64_TYPE
, 0);
6568 if (UINT_FAST8_TYPE
)
6569 builtin_define_with_value ("__UINT_FAST8_TYPE__", UINT_FAST8_TYPE
, 0);
6570 if (UINT_FAST16_TYPE
)
6571 builtin_define_with_value ("__UINT_FAST16_TYPE__", UINT_FAST16_TYPE
, 0);
6572 if (UINT_FAST32_TYPE
)
6573 builtin_define_with_value ("__UINT_FAST32_TYPE__", UINT_FAST32_TYPE
, 0);
6574 if (UINT_FAST64_TYPE
)
6575 builtin_define_with_value ("__UINT_FAST64_TYPE__", UINT_FAST64_TYPE
, 0);
6577 builtin_define_with_value ("__INTPTR_TYPE__", INTPTR_TYPE
, 0);
6579 builtin_define_with_value ("__UINTPTR_TYPE__", UINTPTR_TYPE
, 0);
6583 c_init_attributes (void)
6585 /* Fill in the built_in_attributes array. */
6586 #define DEF_ATTR_NULL_TREE(ENUM) \
6587 built_in_attributes[(int) ENUM] = NULL_TREE;
6588 #define DEF_ATTR_INT(ENUM, VALUE) \
6589 built_in_attributes[(int) ENUM] = build_int_cst (integer_type_node, VALUE);
6590 #define DEF_ATTR_STRING(ENUM, VALUE) \
6591 built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
6592 #define DEF_ATTR_IDENT(ENUM, STRING) \
6593 built_in_attributes[(int) ENUM] = get_identifier (STRING);
6594 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
6595 built_in_attributes[(int) ENUM] \
6596 = tree_cons (built_in_attributes[(int) PURPOSE], \
6597 built_in_attributes[(int) VALUE], \
6598 built_in_attributes[(int) CHAIN]);
6599 #include "builtin-attrs.def"
6600 #undef DEF_ATTR_NULL_TREE
6602 #undef DEF_ATTR_IDENT
6603 #undef DEF_ATTR_TREE_LIST
6606 /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain
6607 identifier as an argument, so the front end shouldn't look it up. */
6610 attribute_takes_identifier_p (const_tree attr_id
)
6612 const struct attribute_spec
*spec
= lookup_attribute_spec (attr_id
);
6614 /* Unknown attribute that we'll end up ignoring, return true so we
6615 don't complain about an identifier argument. */
6617 else if (!strcmp ("mode", spec
->name
)
6618 || !strcmp ("format", spec
->name
)
6619 || !strcmp ("cleanup", spec
->name
))
6622 return targetm
.attribute_takes_identifier_p (attr_id
);
6625 /* Attribute handlers common to C front ends. */
6627 /* Handle a "packed" attribute; arguments as in
6628 struct attribute_spec.handler. */
6631 handle_packed_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6632 int flags
, bool *no_add_attrs
)
6636 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6637 *node
= build_variant_type_copy (*node
);
6638 TYPE_PACKED (*node
) = 1;
6640 else if (TREE_CODE (*node
) == FIELD_DECL
)
6642 if (TYPE_ALIGN (TREE_TYPE (*node
)) <= BITS_PER_UNIT
6643 /* Still pack bitfields. */
6644 && ! DECL_INITIAL (*node
))
6645 warning (OPT_Wattributes
,
6646 "%qE attribute ignored for field of type %qT",
6647 name
, TREE_TYPE (*node
));
6649 DECL_PACKED (*node
) = 1;
6651 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
6652 used for DECL_REGISTER. It wouldn't mean anything anyway.
6653 We can't set DECL_PACKED on the type of a TYPE_DECL, because
6654 that changes what the typedef is typing. */
6657 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6658 *no_add_attrs
= true;
6664 /* Handle a "nocommon" attribute; arguments as in
6665 struct attribute_spec.handler. */
6668 handle_nocommon_attribute (tree
*node
, tree name
,
6669 tree
ARG_UNUSED (args
),
6670 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6672 if (TREE_CODE (*node
) == VAR_DECL
)
6673 DECL_COMMON (*node
) = 0;
6676 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6677 *no_add_attrs
= true;
6683 /* Handle a "common" attribute; arguments as in
6684 struct attribute_spec.handler. */
6687 handle_common_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6688 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6690 if (TREE_CODE (*node
) == VAR_DECL
)
6691 DECL_COMMON (*node
) = 1;
6694 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6695 *no_add_attrs
= true;
6701 /* Handle a "noreturn" attribute; arguments as in
6702 struct attribute_spec.handler. */
6705 handle_noreturn_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6706 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6708 tree type
= TREE_TYPE (*node
);
6710 /* See FIXME comment in c_common_attribute_table. */
6711 if (TREE_CODE (*node
) == FUNCTION_DECL
6712 || objc_method_decl (TREE_CODE (*node
)))
6713 TREE_THIS_VOLATILE (*node
) = 1;
6714 else if (TREE_CODE (type
) == POINTER_TYPE
6715 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
6717 = (build_qualified_type
6719 (build_type_variant (TREE_TYPE (type
),
6720 TYPE_READONLY (TREE_TYPE (type
)), 1)),
6721 TYPE_QUALS (type
)));
6724 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6725 *no_add_attrs
= true;
6731 /* Handle a "hot" and attribute; arguments as in
6732 struct attribute_spec.handler. */
6735 handle_hot_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6736 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6738 if (TREE_CODE (*node
) == FUNCTION_DECL
6739 || TREE_CODE (*node
) == LABEL_DECL
)
6741 if (lookup_attribute ("cold", DECL_ATTRIBUTES (*node
)) != NULL
)
6743 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
6744 "with attribute %qs", name
, "cold");
6745 *no_add_attrs
= true;
6747 /* Most of the rest of the hot processing is done later with
6748 lookup_attribute. */
6752 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6753 *no_add_attrs
= true;
6759 /* Handle a "cold" and attribute; arguments as in
6760 struct attribute_spec.handler. */
6763 handle_cold_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6764 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6766 if (TREE_CODE (*node
) == FUNCTION_DECL
6767 || TREE_CODE (*node
) == LABEL_DECL
)
6769 if (lookup_attribute ("hot", DECL_ATTRIBUTES (*node
)) != NULL
)
6771 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
6772 "with attribute %qs", name
, "hot");
6773 *no_add_attrs
= true;
6775 /* Most of the rest of the cold processing is done later with
6776 lookup_attribute. */
6780 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6781 *no_add_attrs
= true;
6787 /* Handle a "no_sanitize_address" attribute; arguments as in
6788 struct attribute_spec.handler. */
6791 handle_no_sanitize_address_attribute (tree
*node
, tree name
, tree
, int,
6794 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6796 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6797 *no_add_attrs
= true;
6803 /* Handle a "no_address_safety_analysis" attribute; arguments as in
6804 struct attribute_spec.handler. */
6807 handle_no_address_safety_analysis_attribute (tree
*node
, tree name
, tree
, int,
6810 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6811 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6812 else if (!lookup_attribute ("no_sanitize_address", DECL_ATTRIBUTES (*node
)))
6813 DECL_ATTRIBUTES (*node
)
6814 = tree_cons (get_identifier ("no_sanitize_address"),
6815 NULL_TREE
, DECL_ATTRIBUTES (*node
));
6816 *no_add_attrs
= true;
6820 /* Handle a "no_sanitize_undefined" attribute; arguments as in
6821 struct attribute_spec.handler. */
6824 handle_no_sanitize_undefined_attribute (tree
*node
, tree name
, tree
, int,
6827 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6829 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6830 *no_add_attrs
= true;
6836 /* Handle a "stack_protect" attribute; arguments as in
6837 struct attribute_spec.handler. */
6839 handle_stack_protect_attribute (tree
*node
, tree name
, tree
, int,
6842 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6844 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6845 *no_add_attrs
= true;
6848 DECL_ATTRIBUTES (*node
)
6849 = tree_cons (get_identifier ("stack_protect"),
6850 NULL_TREE
, DECL_ATTRIBUTES (*node
));
6855 /* Handle a "noinline" attribute; arguments as in
6856 struct attribute_spec.handler. */
6859 handle_noinline_attribute (tree
*node
, tree name
,
6860 tree
ARG_UNUSED (args
),
6861 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6863 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6865 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node
)))
6867 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
6868 "with attribute %qs", name
, "always_inline");
6869 *no_add_attrs
= true;
6872 DECL_UNINLINABLE (*node
) = 1;
6876 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6877 *no_add_attrs
= true;
6883 /* Handle a "noclone" attribute; arguments as in
6884 struct attribute_spec.handler. */
6887 handle_noclone_attribute (tree
*node
, tree name
,
6888 tree
ARG_UNUSED (args
),
6889 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6891 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6893 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6894 *no_add_attrs
= true;
6900 /* Handle a "no_icf" attribute; arguments as in
6901 struct attribute_spec.handler. */
6904 handle_noicf_attribute (tree
*node
, tree name
,
6905 tree
ARG_UNUSED (args
),
6906 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6908 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6910 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6911 *no_add_attrs
= true;
6918 /* Handle a "always_inline" attribute; arguments as in
6919 struct attribute_spec.handler. */
6922 handle_always_inline_attribute (tree
*node
, tree name
,
6923 tree
ARG_UNUSED (args
),
6924 int ARG_UNUSED (flags
),
6927 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6929 if (lookup_attribute ("noinline", DECL_ATTRIBUTES (*node
)))
6931 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
6932 "with %qs attribute", name
, "noinline");
6933 *no_add_attrs
= true;
6936 /* Set the attribute and mark it for disregarding inline
6938 DECL_DISREGARD_INLINE_LIMITS (*node
) = 1;
6942 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6943 *no_add_attrs
= true;
6949 /* Handle a "gnu_inline" attribute; arguments as in
6950 struct attribute_spec.handler. */
6953 handle_gnu_inline_attribute (tree
*node
, tree name
,
6954 tree
ARG_UNUSED (args
),
6955 int ARG_UNUSED (flags
),
6958 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
6960 /* Do nothing else, just set the attribute. We'll get at
6961 it later with lookup_attribute. */
6965 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6966 *no_add_attrs
= true;
6972 /* Handle a "leaf" attribute; arguments as in
6973 struct attribute_spec.handler. */
6976 handle_leaf_attribute (tree
*node
, tree name
,
6977 tree
ARG_UNUSED (args
),
6978 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6980 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6982 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6983 *no_add_attrs
= true;
6985 if (!TREE_PUBLIC (*node
))
6987 warning (OPT_Wattributes
, "%qE attribute has no effect on unit local functions", name
);
6988 *no_add_attrs
= true;
6994 /* Handle an "artificial" attribute; arguments as in
6995 struct attribute_spec.handler. */
6998 handle_artificial_attribute (tree
*node
, tree name
,
6999 tree
ARG_UNUSED (args
),
7000 int ARG_UNUSED (flags
),
7003 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
7005 /* Do nothing else, just set the attribute. We'll get at
7006 it later with lookup_attribute. */
7010 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7011 *no_add_attrs
= true;
7017 /* Handle a "flatten" attribute; arguments as in
7018 struct attribute_spec.handler. */
7021 handle_flatten_attribute (tree
*node
, tree name
,
7022 tree args ATTRIBUTE_UNUSED
,
7023 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
7025 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7026 /* Do nothing else, just set the attribute. We'll get at
7027 it later with lookup_attribute. */
7031 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7032 *no_add_attrs
= true;
7038 /* Handle a "warning" or "error" attribute; arguments as in
7039 struct attribute_spec.handler. */
7042 handle_error_attribute (tree
*node
, tree name
, tree args
,
7043 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7045 if (TREE_CODE (*node
) == FUNCTION_DECL
7046 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
7047 /* Do nothing else, just set the attribute. We'll get at
7048 it later with lookup_attribute. */
7052 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7053 *no_add_attrs
= true;
7059 /* Handle a "used" attribute; arguments as in
7060 struct attribute_spec.handler. */
7063 handle_used_attribute (tree
*pnode
, tree name
, tree
ARG_UNUSED (args
),
7064 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7068 if (TREE_CODE (node
) == FUNCTION_DECL
7069 || (TREE_CODE (node
) == VAR_DECL
&& TREE_STATIC (node
))
7070 || (TREE_CODE (node
) == TYPE_DECL
))
7072 TREE_USED (node
) = 1;
7073 DECL_PRESERVE_P (node
) = 1;
7074 if (TREE_CODE (node
) == VAR_DECL
)
7075 DECL_READ_P (node
) = 1;
7079 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7080 *no_add_attrs
= true;
7086 /* Handle a "unused" attribute; arguments as in
7087 struct attribute_spec.handler. */
7090 handle_unused_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7091 int flags
, bool *no_add_attrs
)
7097 if (TREE_CODE (decl
) == PARM_DECL
7098 || TREE_CODE (decl
) == VAR_DECL
7099 || TREE_CODE (decl
) == FUNCTION_DECL
7100 || TREE_CODE (decl
) == LABEL_DECL
7101 || TREE_CODE (decl
) == TYPE_DECL
)
7103 TREE_USED (decl
) = 1;
7104 if (TREE_CODE (decl
) == VAR_DECL
7105 || TREE_CODE (decl
) == PARM_DECL
)
7106 DECL_READ_P (decl
) = 1;
7110 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7111 *no_add_attrs
= true;
7116 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7117 *node
= build_variant_type_copy (*node
);
7118 TREE_USED (*node
) = 1;
7124 /* Handle a "externally_visible" attribute; arguments as in
7125 struct attribute_spec.handler. */
7128 handle_externally_visible_attribute (tree
*pnode
, tree name
,
7129 tree
ARG_UNUSED (args
),
7130 int ARG_UNUSED (flags
),
7135 if (TREE_CODE (node
) == FUNCTION_DECL
|| TREE_CODE (node
) == VAR_DECL
)
7137 if ((!TREE_STATIC (node
) && TREE_CODE (node
) != FUNCTION_DECL
7138 && !DECL_EXTERNAL (node
)) || !TREE_PUBLIC (node
))
7140 warning (OPT_Wattributes
,
7141 "%qE attribute have effect only on public objects", name
);
7142 *no_add_attrs
= true;
7147 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7148 *no_add_attrs
= true;
7154 /* Handle the "no_reorder" attribute. Arguments as in
7155 struct attribute_spec.handler. */
7158 handle_no_reorder_attribute (tree
*pnode
,
7166 if ((TREE_CODE (node
) != FUNCTION_DECL
&& TREE_CODE (node
) != VAR_DECL
)
7167 && !(TREE_STATIC (node
) || DECL_EXTERNAL (node
)))
7169 warning (OPT_Wattributes
,
7170 "%qE attribute only affects top level objects",
7172 *no_add_attrs
= true;
7178 /* Handle a "const" attribute; arguments as in
7179 struct attribute_spec.handler. */
7182 handle_const_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7183 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7185 tree type
= TREE_TYPE (*node
);
7187 /* See FIXME comment on noreturn in c_common_attribute_table. */
7188 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7189 TREE_READONLY (*node
) = 1;
7190 else if (TREE_CODE (type
) == POINTER_TYPE
7191 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
7193 = (build_qualified_type
7195 (build_type_variant (TREE_TYPE (type
), 1,
7196 TREE_THIS_VOLATILE (TREE_TYPE (type
)))),
7197 TYPE_QUALS (type
)));
7200 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7201 *no_add_attrs
= true;
7207 /* Handle a "transparent_union" attribute; arguments as in
7208 struct attribute_spec.handler. */
7211 handle_transparent_union_attribute (tree
*node
, tree name
,
7212 tree
ARG_UNUSED (args
), int flags
,
7217 *no_add_attrs
= true;
7220 if (TREE_CODE (*node
) == TYPE_DECL
7221 && ! (flags
& ATTR_FLAG_CXX11
))
7222 node
= &TREE_TYPE (*node
);
7225 if (TREE_CODE (type
) == UNION_TYPE
)
7227 /* Make sure that the first field will work for a transparent union.
7228 If the type isn't complete yet, leave the check to the code in
7230 if (TYPE_SIZE (type
))
7232 tree first
= first_field (type
);
7233 if (first
== NULL_TREE
7234 || DECL_ARTIFICIAL (first
)
7235 || TYPE_MODE (type
) != DECL_MODE (first
))
7239 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7241 /* If the type isn't complete yet, setting the flag
7242 on a variant wouldn't ever be checked. */
7243 if (!TYPE_SIZE (type
))
7246 /* build_duplicate_type doesn't work for C++. */
7247 if (c_dialect_cxx ())
7250 /* A type variant isn't good enough, since we don't a cast
7251 to such a type removed as a no-op. */
7252 *node
= type
= build_duplicate_type (type
);
7255 TYPE_TRANSPARENT_AGGR (type
) = 1;
7260 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7264 /* Subroutine of handle_{con,de}structor_attribute. Evaluate ARGS to
7265 get the requested priority for a constructor or destructor,
7266 possibly issuing diagnostics for invalid or reserved
7269 static priority_type
7270 get_priority (tree args
, bool is_destructor
)
7276 return DEFAULT_INIT_PRIORITY
;
7278 if (!SUPPORTS_INIT_PRIORITY
)
7281 error ("destructor priorities are not supported");
7283 error ("constructor priorities are not supported");
7284 return DEFAULT_INIT_PRIORITY
;
7287 arg
= TREE_VALUE (args
);
7288 if (TREE_CODE (arg
) == IDENTIFIER_NODE
)
7290 if (arg
== error_mark_node
)
7291 return DEFAULT_INIT_PRIORITY
;
7292 arg
= default_conversion (arg
);
7293 if (!tree_fits_shwi_p (arg
)
7294 || !INTEGRAL_TYPE_P (TREE_TYPE (arg
)))
7297 pri
= tree_to_shwi (arg
);
7298 if (pri
< 0 || pri
> MAX_INIT_PRIORITY
)
7301 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
7305 "destructor priorities from 0 to %d are reserved "
7306 "for the implementation",
7307 MAX_RESERVED_INIT_PRIORITY
);
7310 "constructor priorities from 0 to %d are reserved "
7311 "for the implementation",
7312 MAX_RESERVED_INIT_PRIORITY
);
7318 error ("destructor priorities must be integers from 0 to %d inclusive",
7321 error ("constructor priorities must be integers from 0 to %d inclusive",
7323 return DEFAULT_INIT_PRIORITY
;
7326 /* Handle a "constructor" attribute; arguments as in
7327 struct attribute_spec.handler. */
7330 handle_constructor_attribute (tree
*node
, tree name
, tree args
,
7331 int ARG_UNUSED (flags
),
7335 tree type
= TREE_TYPE (decl
);
7337 if (TREE_CODE (decl
) == FUNCTION_DECL
7338 && TREE_CODE (type
) == FUNCTION_TYPE
7339 && decl_function_context (decl
) == 0)
7341 priority_type priority
;
7342 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
7343 priority
= get_priority (args
, /*is_destructor=*/false);
7344 SET_DECL_INIT_PRIORITY (decl
, priority
);
7345 TREE_USED (decl
) = 1;
7349 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7350 *no_add_attrs
= true;
7356 /* Handle a "destructor" attribute; arguments as in
7357 struct attribute_spec.handler. */
7360 handle_destructor_attribute (tree
*node
, tree name
, tree args
,
7361 int ARG_UNUSED (flags
),
7365 tree type
= TREE_TYPE (decl
);
7367 if (TREE_CODE (decl
) == FUNCTION_DECL
7368 && TREE_CODE (type
) == FUNCTION_TYPE
7369 && decl_function_context (decl
) == 0)
7371 priority_type priority
;
7372 DECL_STATIC_DESTRUCTOR (decl
) = 1;
7373 priority
= get_priority (args
, /*is_destructor=*/true);
7374 SET_DECL_FINI_PRIORITY (decl
, priority
);
7375 TREE_USED (decl
) = 1;
7379 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7380 *no_add_attrs
= true;
7386 /* Nonzero if the mode is a valid vector mode for this architecture.
7387 This returns nonzero even if there is no hardware support for the
7388 vector mode, but we can emulate with narrower modes. */
7391 vector_mode_valid_p (machine_mode mode
)
7393 enum mode_class mclass
= GET_MODE_CLASS (mode
);
7394 machine_mode innermode
;
7396 /* Doh! What's going on? */
7397 if (mclass
!= MODE_VECTOR_INT
7398 && mclass
!= MODE_VECTOR_FLOAT
7399 && mclass
!= MODE_VECTOR_FRACT
7400 && mclass
!= MODE_VECTOR_UFRACT
7401 && mclass
!= MODE_VECTOR_ACCUM
7402 && mclass
!= MODE_VECTOR_UACCUM
)
7405 /* Hardware support. Woo hoo! */
7406 if (targetm
.vector_mode_supported_p (mode
))
7409 innermode
= GET_MODE_INNER (mode
);
7411 /* We should probably return 1 if requesting V4DI and we have no DI,
7412 but we have V2DI, but this is probably very unlikely. */
7414 /* If we have support for the inner mode, we can safely emulate it.
7415 We may not have V2DI, but me can emulate with a pair of DIs. */
7416 return targetm
.scalar_mode_supported_p (innermode
);
7420 /* Handle a "mode" attribute; arguments as in
7421 struct attribute_spec.handler. */
7424 handle_mode_attribute (tree
*node
, tree name
, tree args
,
7425 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7428 tree ident
= TREE_VALUE (args
);
7430 *no_add_attrs
= true;
7432 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
7433 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7437 const char *p
= IDENTIFIER_POINTER (ident
);
7438 int len
= strlen (p
);
7439 machine_mode mode
= VOIDmode
;
7443 if (len
> 4 && p
[0] == '_' && p
[1] == '_'
7444 && p
[len
- 1] == '_' && p
[len
- 2] == '_')
7446 char *newp
= (char *) alloca (len
- 1);
7448 strcpy (newp
, &p
[2]);
7449 newp
[len
- 4] = '\0';
7453 /* Change this type to have a type with the specified mode.
7454 First check for the special modes. */
7455 if (!strcmp (p
, "byte"))
7457 else if (!strcmp (p
, "word"))
7459 else if (!strcmp (p
, "pointer"))
7461 else if (!strcmp (p
, "libgcc_cmp_return"))
7462 mode
= targetm
.libgcc_cmp_return_mode ();
7463 else if (!strcmp (p
, "libgcc_shift_count"))
7464 mode
= targetm
.libgcc_shift_count_mode ();
7465 else if (!strcmp (p
, "unwind_word"))
7466 mode
= targetm
.unwind_word_mode ();
7468 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
7469 if (!strcmp (p
, GET_MODE_NAME (j
)))
7471 mode
= (machine_mode
) j
;
7475 if (mode
== VOIDmode
)
7477 error ("unknown machine mode %qE", ident
);
7482 switch (GET_MODE_CLASS (mode
))
7485 case MODE_PARTIAL_INT
:
7487 case MODE_DECIMAL_FLOAT
:
7492 valid_mode
= targetm
.scalar_mode_supported_p (mode
);
7495 case MODE_COMPLEX_INT
:
7496 case MODE_COMPLEX_FLOAT
:
7497 valid_mode
= targetm
.scalar_mode_supported_p (GET_MODE_INNER (mode
));
7500 case MODE_VECTOR_INT
:
7501 case MODE_VECTOR_FLOAT
:
7502 case MODE_VECTOR_FRACT
:
7503 case MODE_VECTOR_UFRACT
:
7504 case MODE_VECTOR_ACCUM
:
7505 case MODE_VECTOR_UACCUM
:
7506 warning (OPT_Wattributes
, "specifying vector types with "
7507 "__attribute__ ((mode)) is deprecated");
7508 warning (OPT_Wattributes
,
7509 "use __attribute__ ((vector_size)) instead");
7510 valid_mode
= vector_mode_valid_p (mode
);
7518 error ("unable to emulate %qs", p
);
7522 if (POINTER_TYPE_P (type
))
7524 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
7525 tree (*fn
)(tree
, machine_mode
, bool);
7527 if (!targetm
.addr_space
.valid_pointer_mode (mode
, as
))
7529 error ("invalid pointer mode %qs", p
);
7533 if (TREE_CODE (type
) == POINTER_TYPE
)
7534 fn
= build_pointer_type_for_mode
;
7536 fn
= build_reference_type_for_mode
;
7537 typefm
= fn (TREE_TYPE (type
), mode
, false);
7541 /* For fixed-point modes, we need to test if the signness of type
7542 and the machine mode are consistent. */
7543 if (ALL_FIXED_POINT_MODE_P (mode
)
7544 && TYPE_UNSIGNED (type
) != UNSIGNED_FIXED_POINT_MODE_P (mode
))
7546 error ("signedness of type and machine mode %qs don%'t match", p
);
7549 /* For fixed-point modes, we need to pass saturating info. */
7550 typefm
= lang_hooks
.types
.type_for_mode (mode
,
7551 ALL_FIXED_POINT_MODE_P (mode
) ? TYPE_SATURATING (type
)
7552 : TYPE_UNSIGNED (type
));
7555 if (typefm
== NULL_TREE
)
7557 error ("no data type for mode %qs", p
);
7560 else if (TREE_CODE (type
) == ENUMERAL_TYPE
)
7562 /* For enumeral types, copy the precision from the integer
7563 type returned above. If not an INTEGER_TYPE, we can't use
7564 this mode for this type. */
7565 if (TREE_CODE (typefm
) != INTEGER_TYPE
)
7567 error ("cannot use mode %qs for enumeral types", p
);
7571 if (flags
& ATTR_FLAG_TYPE_IN_PLACE
)
7573 TYPE_PRECISION (type
) = TYPE_PRECISION (typefm
);
7578 /* We cannot build a type variant, as there's code that assumes
7579 that TYPE_MAIN_VARIANT has the same mode. This includes the
7580 debug generators. Instead, create a subrange type. This
7581 results in all of the enumeral values being emitted only once
7582 in the original, and the subtype gets them by reference. */
7583 if (TYPE_UNSIGNED (type
))
7584 typefm
= make_unsigned_type (TYPE_PRECISION (typefm
));
7586 typefm
= make_signed_type (TYPE_PRECISION (typefm
));
7587 TREE_TYPE (typefm
) = type
;
7590 else if (VECTOR_MODE_P (mode
)
7591 ? TREE_CODE (type
) != TREE_CODE (TREE_TYPE (typefm
))
7592 : TREE_CODE (type
) != TREE_CODE (typefm
))
7594 error ("mode %qs applied to inappropriate type", p
);
7604 /* Handle a "section" attribute; arguments as in
7605 struct attribute_spec.handler. */
7608 handle_section_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7609 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7613 if (!targetm_common
.have_named_sections
)
7615 error_at (DECL_SOURCE_LOCATION (*node
),
7616 "section attributes are not supported for this target");
7620 user_defined_section_attribute
= true;
7622 if (TREE_CODE (decl
) != FUNCTION_DECL
&& TREE_CODE (decl
) != VAR_DECL
)
7624 error ("section attribute not allowed for %q+D", *node
);
7628 if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
7630 error ("section attribute argument not a string constant");
7634 if (TREE_CODE (decl
) == VAR_DECL
7635 && current_function_decl
!= NULL_TREE
7636 && !TREE_STATIC (decl
))
7638 error_at (DECL_SOURCE_LOCATION (decl
),
7639 "section attribute cannot be specified for local variables");
7643 /* The decl may have already been given a section attribute
7644 from a previous declaration. Ensure they match. */
7645 if (DECL_SECTION_NAME (decl
) != NULL
7646 && strcmp (DECL_SECTION_NAME (decl
),
7647 TREE_STRING_POINTER (TREE_VALUE (args
))) != 0)
7649 error ("section of %q+D conflicts with previous declaration", *node
);
7653 if (TREE_CODE (decl
) == VAR_DECL
7654 && !targetm
.have_tls
&& targetm
.emutls
.tmpl_section
7655 && DECL_THREAD_LOCAL_P (decl
))
7657 error ("section of %q+D cannot be overridden", *node
);
7661 set_decl_section_name (decl
, TREE_STRING_POINTER (TREE_VALUE (args
)));
7665 *no_add_attrs
= true;
7669 /* Check whether ALIGN is a valid user-specified alignment. If so,
7670 return its base-2 log; if not, output an error and return -1. If
7671 ALLOW_ZERO then 0 is valid and should result in a return of -1 with
7674 check_user_alignment (const_tree align
, bool allow_zero
)
7678 if (error_operand_p (align
))
7680 if (TREE_CODE (align
) != INTEGER_CST
7681 || !INTEGRAL_TYPE_P (TREE_TYPE (align
)))
7683 error ("requested alignment is not an integer constant");
7686 else if (allow_zero
&& integer_zerop (align
))
7688 else if (tree_int_cst_sgn (align
) == -1
7689 || (i
= tree_log2 (align
)) == -1)
7691 error ("requested alignment is not a positive power of 2");
7694 else if (i
>= HOST_BITS_PER_INT
- BITS_PER_UNIT_LOG
)
7696 error ("requested alignment is too large");
7703 If in c++-11, check if the c++-11 alignment constraint with respect
7704 to fundamental alignment (in [dcl.align]) are satisfied. If not in
7705 c++-11 mode, does nothing.
7709 [* if the constant expression evaluates to a fundamental alignment,
7710 the alignment requirement of the declared entity shall be the
7711 specified fundamental alignment.
7713 * if the constant expression evaluates to an extended alignment
7714 and the implementation supports that alignment in the context
7715 of the declaration, the alignment of the declared entity shall
7718 * if the constant expression evaluates to an extended alignment
7719 and the implementation does not support that alignment in the
7720 context of the declaration, the program is ill-formed]. */
7723 check_cxx_fundamental_alignment_constraints (tree node
,
7727 bool alignment_too_large_p
= false;
7728 unsigned requested_alignment
= 1U << align_log
;
7729 unsigned max_align
= 0;
7731 if ((!(flags
& ATTR_FLAG_CXX11
) && !warn_cxx_compat
)
7732 || (node
== NULL_TREE
|| node
== error_mark_node
))
7735 if (cxx_fundamental_alignment_p (requested_alignment
))
7740 if (TREE_STATIC (node
))
7742 /* For file scope variables and static members, the target
7743 supports alignments that are at most
7744 MAX_OFILE_ALIGNMENT. */
7745 if (requested_alignment
> (max_align
= MAX_OFILE_ALIGNMENT
))
7746 alignment_too_large_p
= true;
7750 #ifdef BIGGEST_FIELD_ALIGNMENT
7751 #define MAX_TARGET_FIELD_ALIGNMENT BIGGEST_FIELD_ALIGNMENT
7753 #define MAX_TARGET_FIELD_ALIGNMENT BIGGEST_ALIGNMENT
7755 /* For non-static members, the target supports either
7756 alignments that at most either BIGGEST_FIELD_ALIGNMENT
7757 if it is defined or BIGGEST_ALIGNMENT. */
7758 max_align
= MAX_TARGET_FIELD_ALIGNMENT
;
7759 if (TREE_CODE (node
) == FIELD_DECL
7760 && requested_alignment
> (max_align
= MAX_TARGET_FIELD_ALIGNMENT
))
7761 alignment_too_large_p
= true;
7762 #undef MAX_TARGET_FIELD_ALIGNMENT
7763 /* For stack variables, the target supports at most
7764 MAX_STACK_ALIGNMENT. */
7765 else if (decl_function_context (node
) != NULL
7766 && requested_alignment
> (max_align
= MAX_STACK_ALIGNMENT
))
7767 alignment_too_large_p
= true;
7770 else if (TYPE_P (node
))
7772 /* Let's be liberal for types. */
7773 if (requested_alignment
> (max_align
= BIGGEST_ALIGNMENT
))
7774 alignment_too_large_p
= true;
7777 if (alignment_too_large_p
)
7778 pedwarn (input_location
, OPT_Wattributes
,
7779 "requested alignment %d is larger than %d",
7780 requested_alignment
, max_align
);
7782 return !alignment_too_large_p
;
7785 /* Handle a "aligned" attribute; arguments as in
7786 struct attribute_spec.handler. */
7789 handle_aligned_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7790 int flags
, bool *no_add_attrs
)
7792 tree decl
= NULL_TREE
;
7800 align_expr
= TREE_VALUE (args
);
7801 if (align_expr
&& TREE_CODE (align_expr
) != IDENTIFIER_NODE
7802 && TREE_CODE (align_expr
) != FUNCTION_DECL
)
7803 align_expr
= default_conversion (align_expr
);
7806 align_expr
= size_int (ATTRIBUTE_ALIGNED_VALUE
/ BITS_PER_UNIT
);
7811 type
= &TREE_TYPE (decl
);
7812 is_type
= TREE_CODE (*node
) == TYPE_DECL
;
7814 else if (TYPE_P (*node
))
7815 type
= node
, is_type
= 1;
7817 if ((i
= check_user_alignment (align_expr
, false)) == -1
7818 || !check_cxx_fundamental_alignment_constraints (*node
, i
, flags
))
7819 *no_add_attrs
= true;
7822 if ((flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7823 /* OK, modify the type in place. */;
7824 /* If we have a TYPE_DECL, then copy the type, so that we
7825 don't accidentally modify a builtin type. See pushdecl. */
7826 else if (decl
&& TREE_TYPE (decl
) != error_mark_node
7827 && DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
)
7829 tree tt
= TREE_TYPE (decl
);
7830 *type
= build_variant_type_copy (*type
);
7831 DECL_ORIGINAL_TYPE (decl
) = tt
;
7832 TYPE_NAME (*type
) = decl
;
7833 TREE_USED (*type
) = TREE_USED (decl
);
7834 TREE_TYPE (decl
) = *type
;
7837 *type
= build_variant_type_copy (*type
);
7839 TYPE_ALIGN (*type
) = (1U << i
) * BITS_PER_UNIT
;
7840 TYPE_USER_ALIGN (*type
) = 1;
7842 else if (! VAR_OR_FUNCTION_DECL_P (decl
)
7843 && TREE_CODE (decl
) != FIELD_DECL
)
7845 error ("alignment may not be specified for %q+D", decl
);
7846 *no_add_attrs
= true;
7848 else if (DECL_USER_ALIGN (decl
)
7849 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
7850 /* C++-11 [dcl.align/4]:
7852 When multiple alignment-specifiers are specified for an
7853 entity, the alignment requirement shall be set to the
7854 strictest specified alignment.
7856 This formally comes from the c++11 specification but we are
7857 doing it for the GNU attribute syntax as well. */
7858 *no_add_attrs
= true;
7859 else if (TREE_CODE (decl
) == FUNCTION_DECL
7860 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
7862 if (DECL_USER_ALIGN (decl
))
7863 error ("alignment for %q+D was previously specified as %d "
7864 "and may not be decreased", decl
,
7865 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
7867 error ("alignment for %q+D must be at least %d", decl
,
7868 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
7869 *no_add_attrs
= true;
7873 DECL_ALIGN (decl
) = (1U << i
) * BITS_PER_UNIT
;
7874 DECL_USER_ALIGN (decl
) = 1;
7880 /* Handle a "weak" attribute; arguments as in
7881 struct attribute_spec.handler. */
7884 handle_weak_attribute (tree
*node
, tree name
,
7885 tree
ARG_UNUSED (args
),
7886 int ARG_UNUSED (flags
),
7887 bool * ARG_UNUSED (no_add_attrs
))
7889 if (TREE_CODE (*node
) == FUNCTION_DECL
7890 && DECL_DECLARED_INLINE_P (*node
))
7892 warning (OPT_Wattributes
, "inline function %q+D declared weak", *node
);
7893 *no_add_attrs
= true;
7895 else if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
7897 error ("indirect function %q+D cannot be declared weak", *node
);
7898 *no_add_attrs
= true;
7901 else if (TREE_CODE (*node
) == FUNCTION_DECL
7902 || TREE_CODE (*node
) == VAR_DECL
)
7904 struct symtab_node
*n
= symtab_node::get (*node
);
7905 if (n
&& n
->refuse_visibility_changes
)
7906 error ("%+D declared weak after being used", *node
);
7907 declare_weak (*node
);
7910 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7915 /* Handle an "alias" or "ifunc" attribute; arguments as in
7916 struct attribute_spec.handler, except that IS_ALIAS tells us
7917 whether this is an alias as opposed to ifunc attribute. */
7920 handle_alias_ifunc_attribute (bool is_alias
, tree
*node
, tree name
, tree args
,
7925 if (TREE_CODE (decl
) != FUNCTION_DECL
7926 && (!is_alias
|| TREE_CODE (decl
) != VAR_DECL
))
7928 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7929 *no_add_attrs
= true;
7931 else if ((TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INITIAL (decl
))
7932 || (TREE_CODE (decl
) != FUNCTION_DECL
7933 && TREE_PUBLIC (decl
) && !DECL_EXTERNAL (decl
))
7934 /* A static variable declaration is always a tentative definition,
7935 but the alias is a non-tentative definition which overrides. */
7936 || (TREE_CODE (decl
) != FUNCTION_DECL
7937 && ! TREE_PUBLIC (decl
) && DECL_INITIAL (decl
)))
7939 error ("%q+D defined both normally and as %qE attribute", decl
, name
);
7940 *no_add_attrs
= true;
7944 && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
7945 || lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
))))
7947 error ("weak %q+D cannot be defined %qE", decl
, name
);
7948 *no_add_attrs
= true;
7952 /* Note that the very first time we process a nested declaration,
7953 decl_function_context will not be set. Indeed, *would* never
7954 be set except for the DECL_INITIAL/DECL_EXTERNAL frobbery that
7955 we do below. After such frobbery, pushdecl would set the context.
7956 In any case, this is never what we want. */
7957 else if (decl_function_context (decl
) == 0 && current_function_decl
== NULL
)
7961 id
= TREE_VALUE (args
);
7962 if (TREE_CODE (id
) != STRING_CST
)
7964 error ("attribute %qE argument not a string", name
);
7965 *no_add_attrs
= true;
7968 id
= get_identifier (TREE_STRING_POINTER (id
));
7969 /* This counts as a use of the object pointed to. */
7972 if (TREE_CODE (decl
) == FUNCTION_DECL
)
7973 DECL_INITIAL (decl
) = error_mark_node
;
7975 TREE_STATIC (decl
) = 1;
7978 /* ifuncs are also aliases, so set that attribute too. */
7979 DECL_ATTRIBUTES (decl
)
7980 = tree_cons (get_identifier ("alias"), args
, DECL_ATTRIBUTES (decl
));
7984 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7985 *no_add_attrs
= true;
7988 if (decl_in_symtab_p (*node
))
7990 struct symtab_node
*n
= symtab_node::get (decl
);
7991 if (n
&& n
->refuse_visibility_changes
)
7994 error ("%+D declared alias after being used", decl
);
7996 error ("%+D declared ifunc after being used", decl
);
8004 /* Handle an "alias" or "ifunc" attribute; arguments as in
8005 struct attribute_spec.handler. */
8008 handle_ifunc_attribute (tree
*node
, tree name
, tree args
,
8009 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8011 return handle_alias_ifunc_attribute (false, node
, name
, args
, no_add_attrs
);
8014 /* Handle an "alias" or "ifunc" attribute; arguments as in
8015 struct attribute_spec.handler. */
8018 handle_alias_attribute (tree
*node
, tree name
, tree args
,
8019 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8021 return handle_alias_ifunc_attribute (true, node
, name
, args
, no_add_attrs
);
8024 /* Handle a "weakref" attribute; arguments as in struct
8025 attribute_spec.handler. */
8028 handle_weakref_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
8029 int flags
, bool *no_add_attrs
)
8031 tree attr
= NULL_TREE
;
8033 /* We must ignore the attribute when it is associated with
8034 local-scoped decls, since attribute alias is ignored and many
8035 such symbols do not even have a DECL_WEAK field. */
8036 if (decl_function_context (*node
)
8037 || current_function_decl
8038 || (TREE_CODE (*node
) != VAR_DECL
&& TREE_CODE (*node
) != FUNCTION_DECL
))
8040 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8041 *no_add_attrs
= true;
8045 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
8047 error ("indirect function %q+D cannot be declared weakref", *node
);
8048 *no_add_attrs
= true;
8052 /* The idea here is that `weakref("name")' mutates into `weakref,
8053 alias("name")', and weakref without arguments, in turn,
8054 implicitly adds weak. */
8058 attr
= tree_cons (get_identifier ("alias"), args
, attr
);
8059 attr
= tree_cons (get_identifier ("weakref"), NULL_TREE
, attr
);
8061 *no_add_attrs
= true;
8063 decl_attributes (node
, attr
, flags
);
8067 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node
)))
8068 error_at (DECL_SOURCE_LOCATION (*node
),
8069 "weakref attribute must appear before alias attribute");
8071 /* Can't call declare_weak because it wants this to be TREE_PUBLIC,
8072 and that isn't supported; and because it wants to add it to
8073 the list of weak decls, which isn't helpful. */
8074 DECL_WEAK (*node
) = 1;
8077 if (decl_in_symtab_p (*node
))
8079 struct symtab_node
*n
= symtab_node::get (*node
);
8080 if (n
&& n
->refuse_visibility_changes
)
8081 error ("%+D declared weakref after being used", *node
);
8087 /* Handle an "visibility" attribute; arguments as in
8088 struct attribute_spec.handler. */
8091 handle_visibility_attribute (tree
*node
, tree name
, tree args
,
8092 int ARG_UNUSED (flags
),
8093 bool *ARG_UNUSED (no_add_attrs
))
8096 tree id
= TREE_VALUE (args
);
8097 enum symbol_visibility vis
;
8101 if (TREE_CODE (*node
) == ENUMERAL_TYPE
)
8103 else if (TREE_CODE (*node
) != RECORD_TYPE
&& TREE_CODE (*node
) != UNION_TYPE
)
8105 warning (OPT_Wattributes
, "%qE attribute ignored on non-class types",
8109 else if (TYPE_FIELDS (*node
))
8111 error ("%qE attribute ignored because %qT is already defined",
8116 else if (decl_function_context (decl
) != 0 || !TREE_PUBLIC (decl
))
8118 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8122 if (TREE_CODE (id
) != STRING_CST
)
8124 error ("visibility argument not a string");
8128 /* If this is a type, set the visibility on the type decl. */
8131 decl
= TYPE_NAME (decl
);
8134 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
8136 warning (OPT_Wattributes
, "%qE attribute ignored on types",
8142 if (strcmp (TREE_STRING_POINTER (id
), "default") == 0)
8143 vis
= VISIBILITY_DEFAULT
;
8144 else if (strcmp (TREE_STRING_POINTER (id
), "internal") == 0)
8145 vis
= VISIBILITY_INTERNAL
;
8146 else if (strcmp (TREE_STRING_POINTER (id
), "hidden") == 0)
8147 vis
= VISIBILITY_HIDDEN
;
8148 else if (strcmp (TREE_STRING_POINTER (id
), "protected") == 0)
8149 vis
= VISIBILITY_PROTECTED
;
8152 error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
8153 vis
= VISIBILITY_DEFAULT
;
8156 if (DECL_VISIBILITY_SPECIFIED (decl
)
8157 && vis
!= DECL_VISIBILITY (decl
))
8159 tree attributes
= (TYPE_P (*node
)
8160 ? TYPE_ATTRIBUTES (*node
)
8161 : DECL_ATTRIBUTES (decl
));
8162 if (lookup_attribute ("visibility", attributes
))
8163 error ("%qD redeclared with different visibility", decl
);
8164 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
8165 && lookup_attribute ("dllimport", attributes
))
8166 error ("%qD was declared %qs which implies default visibility",
8168 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
8169 && lookup_attribute ("dllexport", attributes
))
8170 error ("%qD was declared %qs which implies default visibility",
8174 DECL_VISIBILITY (decl
) = vis
;
8175 DECL_VISIBILITY_SPECIFIED (decl
) = 1;
8177 /* Go ahead and attach the attribute to the node as well. This is needed
8178 so we can determine whether we have VISIBILITY_DEFAULT because the
8179 visibility was not specified, or because it was explicitly overridden
8180 from the containing scope. */
8185 /* Determine the ELF symbol visibility for DECL, which is either a
8186 variable or a function. It is an error to use this function if a
8187 definition of DECL is not available in this translation unit.
8188 Returns true if the final visibility has been determined by this
8189 function; false if the caller is free to make additional
8193 c_determine_visibility (tree decl
)
8195 gcc_assert (TREE_CODE (decl
) == VAR_DECL
8196 || TREE_CODE (decl
) == FUNCTION_DECL
);
8198 /* If the user explicitly specified the visibility with an
8199 attribute, honor that. DECL_VISIBILITY will have been set during
8200 the processing of the attribute. We check for an explicit
8201 attribute, rather than just checking DECL_VISIBILITY_SPECIFIED,
8202 to distinguish the use of an attribute from the use of a "#pragma
8203 GCC visibility push(...)"; in the latter case we still want other
8204 considerations to be able to overrule the #pragma. */
8205 if (lookup_attribute ("visibility", DECL_ATTRIBUTES (decl
))
8206 || (TARGET_DLLIMPORT_DECL_ATTRIBUTES
8207 && (lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl
))
8208 || lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl
)))))
8211 /* Set default visibility to whatever the user supplied with
8212 visibility_specified depending on #pragma GCC visibility. */
8213 if (!DECL_VISIBILITY_SPECIFIED (decl
))
8215 if (visibility_options
.inpragma
8216 || DECL_VISIBILITY (decl
) != default_visibility
)
8218 DECL_VISIBILITY (decl
) = default_visibility
;
8219 DECL_VISIBILITY_SPECIFIED (decl
) = visibility_options
.inpragma
;
8220 /* If visibility changed and DECL already has DECL_RTL, ensure
8221 symbol flags are updated. */
8222 if (((TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
))
8223 || TREE_CODE (decl
) == FUNCTION_DECL
)
8224 && DECL_RTL_SET_P (decl
))
8225 make_decl_rtl (decl
);
8231 /* Handle an "tls_model" attribute; arguments as in
8232 struct attribute_spec.handler. */
8235 handle_tls_model_attribute (tree
*node
, tree name
, tree args
,
8236 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8240 enum tls_model kind
;
8242 *no_add_attrs
= true;
8244 if (TREE_CODE (decl
) != VAR_DECL
|| !DECL_THREAD_LOCAL_P (decl
))
8246 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8250 kind
= DECL_TLS_MODEL (decl
);
8251 id
= TREE_VALUE (args
);
8252 if (TREE_CODE (id
) != STRING_CST
)
8254 error ("tls_model argument not a string");
8258 if (!strcmp (TREE_STRING_POINTER (id
), "local-exec"))
8259 kind
= TLS_MODEL_LOCAL_EXEC
;
8260 else if (!strcmp (TREE_STRING_POINTER (id
), "initial-exec"))
8261 kind
= TLS_MODEL_INITIAL_EXEC
;
8262 else if (!strcmp (TREE_STRING_POINTER (id
), "local-dynamic"))
8263 kind
= optimize
? TLS_MODEL_LOCAL_DYNAMIC
: TLS_MODEL_GLOBAL_DYNAMIC
;
8264 else if (!strcmp (TREE_STRING_POINTER (id
), "global-dynamic"))
8265 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
8267 error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
8269 set_decl_tls_model (decl
, kind
);
8273 /* Handle a "no_instrument_function" attribute; arguments as in
8274 struct attribute_spec.handler. */
8277 handle_no_instrument_function_attribute (tree
*node
, tree name
,
8278 tree
ARG_UNUSED (args
),
8279 int ARG_UNUSED (flags
),
8284 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8286 error_at (DECL_SOURCE_LOCATION (decl
),
8287 "%qE attribute applies only to functions", name
);
8288 *no_add_attrs
= true;
8291 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
8296 /* Handle a "malloc" attribute; arguments as in
8297 struct attribute_spec.handler. */
8300 handle_malloc_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8301 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8303 if (TREE_CODE (*node
) == FUNCTION_DECL
8304 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node
))))
8305 DECL_IS_MALLOC (*node
) = 1;
8308 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8309 *no_add_attrs
= true;
8315 /* Handle a "alloc_size" attribute; arguments as in
8316 struct attribute_spec.handler. */
8319 handle_alloc_size_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
8320 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8322 unsigned arg_count
= type_num_arguments (*node
);
8323 for (; args
; args
= TREE_CHAIN (args
))
8325 tree position
= TREE_VALUE (args
);
8326 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
8327 && TREE_CODE (position
) != FUNCTION_DECL
)
8328 position
= default_conversion (position
);
8330 if (!tree_fits_uhwi_p (position
)
8332 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
8334 warning (OPT_Wattributes
,
8335 "alloc_size parameter outside range");
8336 *no_add_attrs
= true;
8343 /* Handle a "alloc_align" attribute; arguments as in
8344 struct attribute_spec.handler. */
8347 handle_alloc_align_attribute (tree
*node
, tree
, tree args
, int,
8350 unsigned arg_count
= type_num_arguments (*node
);
8351 tree position
= TREE_VALUE (args
);
8352 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
)
8353 position
= default_conversion (position
);
8355 if (!tree_fits_uhwi_p (position
)
8357 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
8359 warning (OPT_Wattributes
,
8360 "alloc_align parameter outside range");
8361 *no_add_attrs
= true;
8367 /* Handle a "assume_aligned" attribute; arguments as in
8368 struct attribute_spec.handler. */
8371 handle_assume_aligned_attribute (tree
*, tree
, tree args
, int,
8374 for (; args
; args
= TREE_CHAIN (args
))
8376 tree position
= TREE_VALUE (args
);
8377 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
8378 && TREE_CODE (position
) != FUNCTION_DECL
)
8379 position
= default_conversion (position
);
8381 if (TREE_CODE (position
) != INTEGER_CST
)
8383 warning (OPT_Wattributes
,
8384 "assume_aligned parameter not integer constant");
8385 *no_add_attrs
= true;
8392 /* Handle a "fn spec" attribute; arguments as in
8393 struct attribute_spec.handler. */
8396 handle_fnspec_attribute (tree
*node ATTRIBUTE_UNUSED
, tree
ARG_UNUSED (name
),
8397 tree args
, int ARG_UNUSED (flags
),
8398 bool *no_add_attrs ATTRIBUTE_UNUSED
)
8401 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
8402 && !TREE_CHAIN (args
));
8406 /* Handle a "bnd_variable_size" attribute; arguments as in
8407 struct attribute_spec.handler. */
8410 handle_bnd_variable_size_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8411 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8413 if (TREE_CODE (*node
) != FIELD_DECL
)
8415 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8416 *no_add_attrs
= true;
8422 /* Handle a "bnd_legacy" attribute; arguments as in
8423 struct attribute_spec.handler. */
8426 handle_bnd_legacy (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8427 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8429 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8431 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8432 *no_add_attrs
= true;
8438 /* Handle a "bnd_instrument" attribute; arguments as in
8439 struct attribute_spec.handler. */
8442 handle_bnd_instrument (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8443 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8445 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8447 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8448 *no_add_attrs
= true;
8454 /* Handle a "warn_unused" attribute; arguments as in
8455 struct attribute_spec.handler. */
8458 handle_warn_unused_attribute (tree
*node
, tree name
,
8459 tree args ATTRIBUTE_UNUSED
,
8460 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
8463 /* Do nothing else, just set the attribute. We'll get at
8464 it later with lookup_attribute. */
8468 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8469 *no_add_attrs
= true;
8475 /* Handle an "omp declare simd" attribute; arguments as in
8476 struct attribute_spec.handler. */
8479 handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int, bool *)
8484 /* Handle an "omp declare target" attribute; arguments as in
8485 struct attribute_spec.handler. */
8488 handle_omp_declare_target_attribute (tree
*, tree
, tree
, int, bool *)
8493 /* Handle a "returns_twice" attribute; arguments as in
8494 struct attribute_spec.handler. */
8497 handle_returns_twice_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8498 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8500 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8501 DECL_IS_RETURNS_TWICE (*node
) = 1;
8504 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8505 *no_add_attrs
= true;
8511 /* Handle a "no_limit_stack" attribute; arguments as in
8512 struct attribute_spec.handler. */
8515 handle_no_limit_stack_attribute (tree
*node
, tree name
,
8516 tree
ARG_UNUSED (args
),
8517 int ARG_UNUSED (flags
),
8522 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8524 error_at (DECL_SOURCE_LOCATION (decl
),
8525 "%qE attribute applies only to functions", name
);
8526 *no_add_attrs
= true;
8528 else if (DECL_INITIAL (decl
))
8530 error_at (DECL_SOURCE_LOCATION (decl
),
8531 "can%'t set %qE attribute after definition", name
);
8532 *no_add_attrs
= true;
8535 DECL_NO_LIMIT_STACK (decl
) = 1;
8540 /* Handle a "pure" attribute; arguments as in
8541 struct attribute_spec.handler. */
8544 handle_pure_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8545 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8547 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8548 DECL_PURE_P (*node
) = 1;
8549 /* ??? TODO: Support types. */
8552 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8553 *no_add_attrs
= true;
8559 /* Digest an attribute list destined for a transactional memory statement.
8560 ALLOWED is the set of attributes that are allowed for this statement;
8561 return the attribute we parsed. Multiple attributes are never allowed. */
8564 parse_tm_stmt_attr (tree attrs
, int allowed
)
8569 for ( ; attrs
; attrs
= TREE_CHAIN (attrs
))
8571 tree a
= TREE_PURPOSE (attrs
);
8574 if (is_attribute_p ("outer", a
))
8575 m
= TM_STMT_ATTR_OUTER
;
8577 if ((m
& allowed
) == 0)
8579 warning (OPT_Wattributes
, "%qE attribute directive ignored", a
);
8588 else if (m_seen
== m
)
8589 warning (OPT_Wattributes
, "%qE attribute duplicated", a
);
8591 warning (OPT_Wattributes
, "%qE attribute follows %qE", a
, a_seen
);
8597 /* Transform a TM attribute name into a maskable integer and back.
8598 Note that NULL (i.e. no attribute) is mapped to UNKNOWN, corresponding
8599 to how the lack of an attribute is treated. */
8602 tm_attr_to_mask (tree attr
)
8606 if (is_attribute_p ("transaction_safe", attr
))
8607 return TM_ATTR_SAFE
;
8608 if (is_attribute_p ("transaction_callable", attr
))
8609 return TM_ATTR_CALLABLE
;
8610 if (is_attribute_p ("transaction_pure", attr
))
8611 return TM_ATTR_PURE
;
8612 if (is_attribute_p ("transaction_unsafe", attr
))
8613 return TM_ATTR_IRREVOCABLE
;
8614 if (is_attribute_p ("transaction_may_cancel_outer", attr
))
8615 return TM_ATTR_MAY_CANCEL_OUTER
;
8620 tm_mask_to_attr (int mask
)
8626 str
= "transaction_safe";
8628 case TM_ATTR_CALLABLE
:
8629 str
= "transaction_callable";
8632 str
= "transaction_pure";
8634 case TM_ATTR_IRREVOCABLE
:
8635 str
= "transaction_unsafe";
8637 case TM_ATTR_MAY_CANCEL_OUTER
:
8638 str
= "transaction_may_cancel_outer";
8643 return get_identifier (str
);
8646 /* Return the first TM attribute seen in LIST. */
8649 find_tm_attribute (tree list
)
8651 for (; list
; list
= TREE_CHAIN (list
))
8653 tree name
= TREE_PURPOSE (list
);
8654 if (tm_attr_to_mask (name
) != 0)
8660 /* Handle the TM attributes; arguments as in struct attribute_spec.handler.
8661 Here we accept only function types, and verify that none of the other
8662 function TM attributes are also applied. */
8663 /* ??? We need to accept class types for C++, but not C. This greatly
8664 complicates this function, since we can no longer rely on the extra
8665 processing given by function_type_required. */
8668 handle_tm_attribute (tree
*node
, tree name
, tree args
,
8669 int flags
, bool *no_add_attrs
)
8671 /* Only one path adds the attribute; others don't. */
8672 *no_add_attrs
= true;
8674 switch (TREE_CODE (*node
))
8678 /* Only tm_callable and tm_safe apply to classes. */
8679 if (tm_attr_to_mask (name
) & ~(TM_ATTR_SAFE
| TM_ATTR_CALLABLE
))
8686 tree old_name
= find_tm_attribute (TYPE_ATTRIBUTES (*node
));
8687 if (old_name
== name
)
8689 else if (old_name
!= NULL_TREE
)
8690 error ("type was previously declared %qE", old_name
);
8692 *no_add_attrs
= false;
8698 enum tree_code subcode
= TREE_CODE (TREE_TYPE (*node
));
8699 if (subcode
== FUNCTION_TYPE
|| subcode
== METHOD_TYPE
)
8701 tree fn_tmp
= TREE_TYPE (*node
);
8702 decl_attributes (&fn_tmp
, tree_cons (name
, args
, NULL
), 0);
8703 *node
= build_pointer_type (fn_tmp
);
8710 /* If a function is next, pass it on to be tried next. */
8711 if (flags
& (int) ATTR_FLAG_FUNCTION_NEXT
)
8712 return tree_cons (name
, args
, NULL
);
8715 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8722 /* Handle the TM_WRAP attribute; arguments as in
8723 struct attribute_spec.handler. */
8726 handle_tm_wrap_attribute (tree
*node
, tree name
, tree args
,
8727 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8731 /* We don't need the attribute even on success, since we
8732 record the entry in an external table. */
8733 *no_add_attrs
= true;
8735 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8736 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8739 tree wrap_decl
= TREE_VALUE (args
);
8740 if (error_operand_p (wrap_decl
))
8742 else if (TREE_CODE (wrap_decl
) != IDENTIFIER_NODE
8743 && TREE_CODE (wrap_decl
) != VAR_DECL
8744 && TREE_CODE (wrap_decl
) != FUNCTION_DECL
)
8745 error ("%qE argument not an identifier", name
);
8748 if (TREE_CODE (wrap_decl
) == IDENTIFIER_NODE
)
8749 wrap_decl
= lookup_name (wrap_decl
);
8750 if (wrap_decl
&& TREE_CODE (wrap_decl
) == FUNCTION_DECL
)
8752 if (lang_hooks
.types_compatible_p (TREE_TYPE (decl
),
8753 TREE_TYPE (wrap_decl
)))
8754 record_tm_replacement (wrap_decl
, decl
);
8756 error ("%qD is not compatible with %qD", wrap_decl
, decl
);
8759 error ("%qE argument is not a function", name
);
8766 /* Ignore the given attribute. Used when this attribute may be usefully
8767 overridden by the target, but is not used generically. */
8770 ignore_attribute (tree
* ARG_UNUSED (node
), tree
ARG_UNUSED (name
),
8771 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
8774 *no_add_attrs
= true;
8778 /* Handle a "no vops" attribute; arguments as in
8779 struct attribute_spec.handler. */
8782 handle_novops_attribute (tree
*node
, tree
ARG_UNUSED (name
),
8783 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
8784 bool *ARG_UNUSED (no_add_attrs
))
8786 gcc_assert (TREE_CODE (*node
) == FUNCTION_DECL
);
8787 DECL_IS_NOVOPS (*node
) = 1;
8791 /* Handle a "deprecated" attribute; arguments as in
8792 struct attribute_spec.handler. */
8795 handle_deprecated_attribute (tree
*node
, tree name
,
8796 tree args
, int flags
,
8799 tree type
= NULL_TREE
;
8801 tree what
= NULL_TREE
;
8804 *no_add_attrs
= true;
8805 else if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
8807 error ("deprecated message is not a string");
8808 *no_add_attrs
= true;
8814 type
= TREE_TYPE (decl
);
8816 if (TREE_CODE (decl
) == TYPE_DECL
8817 || TREE_CODE (decl
) == PARM_DECL
8818 || TREE_CODE (decl
) == VAR_DECL
8819 || TREE_CODE (decl
) == FUNCTION_DECL
8820 || TREE_CODE (decl
) == FIELD_DECL
8821 || objc_method_decl (TREE_CODE (decl
)))
8822 TREE_DEPRECATED (decl
) = 1;
8826 else if (TYPE_P (*node
))
8828 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
8829 *node
= build_variant_type_copy (*node
);
8830 TREE_DEPRECATED (*node
) = 1;
8838 *no_add_attrs
= true;
8839 if (type
&& TYPE_NAME (type
))
8841 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
8842 what
= TYPE_NAME (*node
);
8843 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
8844 && DECL_NAME (TYPE_NAME (type
)))
8845 what
= DECL_NAME (TYPE_NAME (type
));
8848 warning (OPT_Wattributes
, "%qE attribute ignored for %qE", name
, what
);
8850 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8856 /* Handle a "vector_size" attribute; arguments as in
8857 struct attribute_spec.handler. */
8860 handle_vector_size_attribute (tree
*node
, tree name
, tree args
,
8861 int ARG_UNUSED (flags
),
8864 unsigned HOST_WIDE_INT vecsize
, nunits
;
8865 machine_mode orig_mode
;
8866 tree type
= *node
, new_type
, size
;
8868 *no_add_attrs
= true;
8870 size
= TREE_VALUE (args
);
8871 if (size
&& TREE_CODE (size
) != IDENTIFIER_NODE
8872 && TREE_CODE (size
) != FUNCTION_DECL
)
8873 size
= default_conversion (size
);
8875 if (!tree_fits_uhwi_p (size
))
8877 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8881 /* Get the vector size (in bytes). */
8882 vecsize
= tree_to_uhwi (size
);
8884 /* We need to provide for vector pointers, vector arrays, and
8885 functions returning vectors. For example:
8887 __attribute__((vector_size(16))) short *foo;
8889 In this case, the mode is SI, but the type being modified is
8890 HI, so we need to look further. */
8892 while (POINTER_TYPE_P (type
)
8893 || TREE_CODE (type
) == FUNCTION_TYPE
8894 || TREE_CODE (type
) == METHOD_TYPE
8895 || TREE_CODE (type
) == ARRAY_TYPE
8896 || TREE_CODE (type
) == OFFSET_TYPE
)
8897 type
= TREE_TYPE (type
);
8899 /* Get the mode of the type being modified. */
8900 orig_mode
= TYPE_MODE (type
);
8902 if ((!INTEGRAL_TYPE_P (type
)
8903 && !SCALAR_FLOAT_TYPE_P (type
)
8904 && !FIXED_POINT_TYPE_P (type
))
8905 || (!SCALAR_FLOAT_MODE_P (orig_mode
)
8906 && GET_MODE_CLASS (orig_mode
) != MODE_INT
8907 && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode
))
8908 || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
8909 || TREE_CODE (type
) == BOOLEAN_TYPE
)
8911 error ("invalid vector type for attribute %qE", name
);
8915 if (vecsize
% tree_to_uhwi (TYPE_SIZE_UNIT (type
)))
8917 error ("vector size not an integral multiple of component size");
8923 error ("zero vector size");
8927 /* Calculate how many units fit in the vector. */
8928 nunits
= vecsize
/ tree_to_uhwi (TYPE_SIZE_UNIT (type
));
8929 if (nunits
& (nunits
- 1))
8931 error ("number of components of the vector not a power of two");
8935 new_type
= build_vector_type (type
, nunits
);
8937 /* Build back pointers if needed. */
8938 *node
= lang_hooks
.types
.reconstruct_complex_type (*node
, new_type
);
8943 /* Handle the "nonnull" attribute. */
8945 handle_nonnull_attribute (tree
*node
, tree
ARG_UNUSED (name
),
8946 tree args
, int ARG_UNUSED (flags
),
8950 unsigned HOST_WIDE_INT attr_arg_num
;
8952 /* If no arguments are specified, all pointer arguments should be
8953 non-null. Verify a full prototype is given so that the arguments
8954 will have the correct types when we actually check them later. */
8957 if (!prototype_p (type
))
8959 error ("nonnull attribute without arguments on a non-prototype");
8960 *no_add_attrs
= true;
8965 /* Argument list specified. Verify that each argument number references
8966 a pointer argument. */
8967 for (attr_arg_num
= 1; args
; attr_arg_num
++, args
= TREE_CHAIN (args
))
8969 unsigned HOST_WIDE_INT arg_num
= 0, ck_num
;
8971 tree arg
= TREE_VALUE (args
);
8972 if (arg
&& TREE_CODE (arg
) != IDENTIFIER_NODE
8973 && TREE_CODE (arg
) != FUNCTION_DECL
)
8974 arg
= default_conversion (arg
);
8976 if (!get_nonnull_operand (arg
, &arg_num
))
8978 error ("nonnull argument has invalid operand number (argument %lu)",
8979 (unsigned long) attr_arg_num
);
8980 *no_add_attrs
= true;
8984 if (prototype_p (type
))
8986 function_args_iterator iter
;
8989 function_args_iter_init (&iter
, type
);
8990 for (ck_num
= 1; ; ck_num
++, function_args_iter_next (&iter
))
8992 argument
= function_args_iter_cond (&iter
);
8993 if (argument
== NULL_TREE
|| ck_num
== arg_num
)
8998 || TREE_CODE (argument
) == VOID_TYPE
)
9000 error ("nonnull argument with out-of-range operand number (argument %lu, operand %lu)",
9001 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
9002 *no_add_attrs
= true;
9006 if (TREE_CODE (argument
) != POINTER_TYPE
)
9008 error ("nonnull argument references non-pointer operand (argument %lu, operand %lu)",
9009 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
9010 *no_add_attrs
= true;
9019 /* Check the argument list of a function call for null in argument slots
9020 that are marked as requiring a non-null pointer argument. The NARGS
9021 arguments are passed in the array ARGARRAY.
9025 check_function_nonnull (tree attrs
, int nargs
, tree
*argarray
)
9030 attrs
= lookup_attribute ("nonnull", attrs
);
9031 if (attrs
== NULL_TREE
)
9035 /* See if any of the nonnull attributes has no arguments. If so,
9036 then every pointer argument is checked (in which case the check
9037 for pointer type is done in check_nonnull_arg). */
9038 if (TREE_VALUE (a
) != NULL_TREE
)
9040 a
= lookup_attribute ("nonnull", TREE_CHAIN (a
));
9041 while (a
!= NULL_TREE
&& TREE_VALUE (a
) != NULL_TREE
);
9044 for (i
= 0; i
< nargs
; i
++)
9045 check_function_arguments_recurse (check_nonnull_arg
, NULL
, argarray
[i
],
9049 /* Walk the argument list. If we encounter an argument number we
9050 should check for non-null, do it. */
9051 for (i
= 0; i
< nargs
; i
++)
9053 for (a
= attrs
; ; a
= TREE_CHAIN (a
))
9055 a
= lookup_attribute ("nonnull", a
);
9056 if (a
== NULL_TREE
|| nonnull_check_p (TREE_VALUE (a
), i
+ 1))
9061 check_function_arguments_recurse (check_nonnull_arg
, NULL
,
9062 argarray
[i
], i
+ 1);
9067 /* Check that the Nth argument of a function call (counting backwards
9068 from the end) is a (pointer)0. The NARGS arguments are passed in the
9072 check_function_sentinel (const_tree fntype
, int nargs
, tree
*argarray
)
9074 tree attr
= lookup_attribute ("sentinel", TYPE_ATTRIBUTES (fntype
));
9081 function_args_iterator iter
;
9084 /* Skip over the named arguments. */
9085 FOREACH_FUNCTION_ARGS (fntype
, t
, iter
)
9092 if (TREE_VALUE (attr
))
9094 tree p
= TREE_VALUE (TREE_VALUE (attr
));
9095 pos
= TREE_INT_CST_LOW (p
);
9098 /* The sentinel must be one of the varargs, i.e.
9099 in position >= the number of fixed arguments. */
9100 if ((nargs
- 1 - pos
) < len
)
9102 warning (OPT_Wformat_
,
9103 "not enough variable arguments to fit a sentinel");
9107 /* Validate the sentinel. */
9108 sentinel
= argarray
[nargs
- 1 - pos
];
9109 if ((!POINTER_TYPE_P (TREE_TYPE (sentinel
))
9110 || !integer_zerop (sentinel
))
9111 /* Although __null (in C++) is only an integer we allow it
9112 nevertheless, as we are guaranteed that it's exactly
9113 as wide as a pointer, and we don't want to force
9114 users to cast the NULL they have written there.
9115 We warn with -Wstrict-null-sentinel, though. */
9116 && (warn_strict_null_sentinel
|| null_node
!= sentinel
))
9117 warning (OPT_Wformat_
, "missing sentinel in function call");
9121 /* Helper for check_function_nonnull; given a list of operands which
9122 must be non-null in ARGS, determine if operand PARAM_NUM should be
9126 nonnull_check_p (tree args
, unsigned HOST_WIDE_INT param_num
)
9128 unsigned HOST_WIDE_INT arg_num
= 0;
9130 for (; args
; args
= TREE_CHAIN (args
))
9132 bool found
= get_nonnull_operand (TREE_VALUE (args
), &arg_num
);
9136 if (arg_num
== param_num
)
9142 /* Check that the function argument PARAM (which is operand number
9143 PARAM_NUM) is non-null. This is called by check_function_nonnull
9144 via check_function_arguments_recurse. */
9147 check_nonnull_arg (void * ARG_UNUSED (ctx
), tree param
,
9148 unsigned HOST_WIDE_INT param_num
)
9150 /* Just skip checking the argument if it's not a pointer. This can
9151 happen if the "nonnull" attribute was given without an operand
9152 list (which means to check every pointer argument). */
9154 if (TREE_CODE (TREE_TYPE (param
)) != POINTER_TYPE
)
9157 if (integer_zerop (param
))
9158 warning (OPT_Wnonnull
, "null argument where non-null required "
9159 "(argument %lu)", (unsigned long) param_num
);
9162 /* Helper for nonnull attribute handling; fetch the operand number
9163 from the attribute argument list. */
9166 get_nonnull_operand (tree arg_num_expr
, unsigned HOST_WIDE_INT
*valp
)
9168 /* Verify the arg number is a small constant. */
9169 if (tree_fits_uhwi_p (arg_num_expr
))
9171 *valp
= TREE_INT_CST_LOW (arg_num_expr
);
9178 /* Handle a "nothrow" attribute; arguments as in
9179 struct attribute_spec.handler. */
9182 handle_nothrow_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
9183 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9185 if (TREE_CODE (*node
) == FUNCTION_DECL
)
9186 TREE_NOTHROW (*node
) = 1;
9187 /* ??? TODO: Support types. */
9190 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9191 *no_add_attrs
= true;
9197 /* Handle a "cleanup" attribute; arguments as in
9198 struct attribute_spec.handler. */
9201 handle_cleanup_attribute (tree
*node
, tree name
, tree args
,
9202 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9205 tree cleanup_id
, cleanup_decl
;
9207 /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
9208 for global destructors in C++. This requires infrastructure that
9209 we don't have generically at the moment. It's also not a feature
9210 we'd be missing too much, since we do have attribute constructor. */
9211 if (TREE_CODE (decl
) != VAR_DECL
|| TREE_STATIC (decl
))
9213 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9214 *no_add_attrs
= true;
9218 /* Verify that the argument is a function in scope. */
9219 /* ??? We could support pointers to functions here as well, if
9220 that was considered desirable. */
9221 cleanup_id
= TREE_VALUE (args
);
9222 if (TREE_CODE (cleanup_id
) != IDENTIFIER_NODE
)
9224 error ("cleanup argument not an identifier");
9225 *no_add_attrs
= true;
9228 cleanup_decl
= lookup_name (cleanup_id
);
9229 if (!cleanup_decl
|| TREE_CODE (cleanup_decl
) != FUNCTION_DECL
)
9231 error ("cleanup argument not a function");
9232 *no_add_attrs
= true;
9236 /* That the function has proper type is checked with the
9237 eventual call to build_function_call. */
9242 /* Handle a "warn_unused_result" attribute. No special handling. */
9245 handle_warn_unused_result_attribute (tree
*node
, tree name
,
9246 tree
ARG_UNUSED (args
),
9247 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9249 /* Ignore the attribute for functions not returning any value. */
9250 if (VOID_TYPE_P (TREE_TYPE (*node
)))
9252 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9253 *no_add_attrs
= true;
9259 /* Handle a "sentinel" attribute. */
9262 handle_sentinel_attribute (tree
*node
, tree name
, tree args
,
9263 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9265 if (!prototype_p (*node
))
9267 warning (OPT_Wattributes
,
9268 "%qE attribute requires prototypes with named arguments", name
);
9269 *no_add_attrs
= true;
9273 if (!stdarg_p (*node
))
9275 warning (OPT_Wattributes
,
9276 "%qE attribute only applies to variadic functions", name
);
9277 *no_add_attrs
= true;
9283 tree position
= TREE_VALUE (args
);
9284 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
9285 && TREE_CODE (position
) != FUNCTION_DECL
)
9286 position
= default_conversion (position
);
9288 if (TREE_CODE (position
) != INTEGER_CST
9289 || !INTEGRAL_TYPE_P (TREE_TYPE (position
)))
9291 warning (OPT_Wattributes
,
9292 "requested position is not an integer constant");
9293 *no_add_attrs
= true;
9297 if (tree_int_cst_lt (position
, integer_zero_node
))
9299 warning (OPT_Wattributes
,
9300 "requested position is less than zero");
9301 *no_add_attrs
= true;
9309 /* Handle a "type_generic" attribute. */
9312 handle_type_generic_attribute (tree
*node
, tree
ARG_UNUSED (name
),
9313 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
9314 bool * ARG_UNUSED (no_add_attrs
))
9316 /* Ensure we have a function type. */
9317 gcc_assert (TREE_CODE (*node
) == FUNCTION_TYPE
);
9319 /* Ensure we have a variadic function. */
9320 gcc_assert (!prototype_p (*node
) || stdarg_p (*node
));
9325 /* Handle a "target" attribute. */
9328 handle_target_attribute (tree
*node
, tree name
, tree args
, int flags
,
9331 /* Ensure we have a function type. */
9332 if (TREE_CODE (*node
) != FUNCTION_DECL
)
9334 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9335 *no_add_attrs
= true;
9337 else if (! targetm
.target_option
.valid_attribute_p (*node
, name
, args
,
9339 *no_add_attrs
= true;
9344 /* Arguments being collected for optimization. */
9345 typedef const char *const_char_p
; /* For DEF_VEC_P. */
9346 static GTY(()) vec
<const_char_p
, va_gc
> *optimize_args
;
9349 /* Inner function to convert a TREE_LIST to argv string to parse the optimize
9350 options in ARGS. ATTR_P is true if this is for attribute(optimize), and
9351 false for #pragma GCC optimize. */
9354 parse_optimize_options (tree args
, bool attr_p
)
9359 int saved_flag_strict_aliasing
;
9360 const char **opt_argv
;
9361 struct cl_decoded_option
*decoded_options
;
9362 unsigned int decoded_options_count
;
9365 /* Build up argv vector. Just in case the string is stored away, use garbage
9366 collected strings. */
9367 vec_safe_truncate (optimize_args
, 0);
9368 vec_safe_push (optimize_args
, (const char *) NULL
);
9370 for (ap
= args
; ap
!= NULL_TREE
; ap
= TREE_CHAIN (ap
))
9372 tree value
= TREE_VALUE (ap
);
9374 if (TREE_CODE (value
) == INTEGER_CST
)
9377 sprintf (buffer
, "-O%ld", (long) TREE_INT_CST_LOW (value
));
9378 vec_safe_push (optimize_args
, ggc_strdup (buffer
));
9381 else if (TREE_CODE (value
) == STRING_CST
)
9383 /* Split string into multiple substrings. */
9384 size_t len
= TREE_STRING_LENGTH (value
);
9385 char *p
= ASTRDUP (TREE_STRING_POINTER (value
));
9386 char *end
= p
+ len
;
9390 while (next_p
!= NULL
)
9396 comma
= strchr (p
, ',');
9409 r
= q
= (char *) ggc_alloc_atomic (len2
+ 3);
9411 /* If the user supplied -Oxxx or -fxxx, only allow -Oxxx or -fxxx
9413 if (*p
== '-' && p
[1] != 'O' && p
[1] != 'f')
9417 warning (OPT_Wattributes
,
9418 "bad option %s to optimize attribute", p
);
9420 warning (OPT_Wpragmas
,
9421 "bad option %s to pragma attribute", p
);
9429 /* Assume that Ox is -Ox, a numeric value is -Ox, a s by
9430 itself is -Os, and any other switch begins with a -f. */
9431 if ((*p
>= '0' && *p
<= '9')
9432 || (p
[0] == 's' && p
[1] == '\0'))
9438 memcpy (r
, p
, len2
);
9440 vec_safe_push (optimize_args
, (const char *) q
);
9446 opt_argc
= optimize_args
->length ();
9447 opt_argv
= (const char **) alloca (sizeof (char *) * (opt_argc
+ 1));
9449 for (i
= 1; i
< opt_argc
; i
++)
9450 opt_argv
[i
] = (*optimize_args
)[i
];
9452 saved_flag_strict_aliasing
= flag_strict_aliasing
;
9454 /* Now parse the options. */
9455 decode_cmdline_options_to_array_default_mask (opt_argc
, opt_argv
,
9457 &decoded_options_count
);
9458 decode_options (&global_options
, &global_options_set
,
9459 decoded_options
, decoded_options_count
,
9460 input_location
, global_dc
);
9462 targetm
.override_options_after_change();
9464 /* Don't allow changing -fstrict-aliasing. */
9465 flag_strict_aliasing
= saved_flag_strict_aliasing
;
9467 optimize_args
->truncate (0);
9471 /* For handling "optimize" attribute. arguments as in
9472 struct attribute_spec.handler. */
9475 handle_optimize_attribute (tree
*node
, tree name
, tree args
,
9476 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9478 /* Ensure we have a function type. */
9479 if (TREE_CODE (*node
) != FUNCTION_DECL
)
9481 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9482 *no_add_attrs
= true;
9486 struct cl_optimization cur_opts
;
9487 tree old_opts
= DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
);
9489 /* Save current options. */
9490 cl_optimization_save (&cur_opts
, &global_options
);
9492 /* If we previously had some optimization options, use them as the
9495 cl_optimization_restore (&global_options
,
9496 TREE_OPTIMIZATION (old_opts
));
9498 /* Parse options, and update the vector. */
9499 parse_optimize_options (args
, true);
9500 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
)
9501 = build_optimization_node (&global_options
);
9503 /* Restore current options. */
9504 cl_optimization_restore (&global_options
, &cur_opts
);
9510 /* Handle a "no_split_stack" attribute. */
9513 handle_no_split_stack_attribute (tree
*node
, tree name
,
9514 tree
ARG_UNUSED (args
),
9515 int ARG_UNUSED (flags
),
9520 if (TREE_CODE (decl
) != FUNCTION_DECL
)
9522 error_at (DECL_SOURCE_LOCATION (decl
),
9523 "%qE attribute applies only to functions", name
);
9524 *no_add_attrs
= true;
9526 else if (DECL_INITIAL (decl
))
9528 error_at (DECL_SOURCE_LOCATION (decl
),
9529 "can%'t set %qE attribute after definition", name
);
9530 *no_add_attrs
= true;
9536 /* Handle a "returns_nonnull" attribute; arguments as in
9537 struct attribute_spec.handler. */
9540 handle_returns_nonnull_attribute (tree
*node
, tree
, tree
, int,
9543 // Even without a prototype we still have a return type we can check.
9544 if (TREE_CODE (TREE_TYPE (*node
)) != POINTER_TYPE
)
9546 error ("returns_nonnull attribute on a function not returning a pointer");
9547 *no_add_attrs
= true;
9552 /* Handle a "designated_init" attribute; arguments as in
9553 struct attribute_spec.handler. */
9556 handle_designated_init_attribute (tree
*node
, tree name
, tree
, int,
9559 if (TREE_CODE (*node
) != RECORD_TYPE
)
9561 error ("%qE attribute is only valid on %<struct%> type", name
);
9562 *no_add_attrs
= true;
9568 /* Check for valid arguments being passed to a function with FNTYPE.
9569 There are NARGS arguments in the array ARGARRAY. */
9571 check_function_arguments (const_tree fntype
, int nargs
, tree
*argarray
)
9573 /* Check for null being passed in a pointer argument that must be
9574 non-null. We also need to do this if format checking is enabled. */
9577 check_function_nonnull (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
9579 /* Check for errors in format strings. */
9581 if (warn_format
|| warn_suggest_attribute_format
)
9582 check_function_format (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
9585 check_function_sentinel (fntype
, nargs
, argarray
);
9588 /* Generic argument checking recursion routine. PARAM is the argument to
9589 be checked. PARAM_NUM is the number of the argument. CALLBACK is invoked
9590 once the argument is resolved. CTX is context for the callback. */
9592 check_function_arguments_recurse (void (*callback
)
9593 (void *, tree
, unsigned HOST_WIDE_INT
),
9594 void *ctx
, tree param
,
9595 unsigned HOST_WIDE_INT param_num
)
9597 if (CONVERT_EXPR_P (param
)
9598 && (TYPE_PRECISION (TREE_TYPE (param
))
9599 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (param
, 0)))))
9601 /* Strip coercion. */
9602 check_function_arguments_recurse (callback
, ctx
,
9603 TREE_OPERAND (param
, 0), param_num
);
9607 if (TREE_CODE (param
) == CALL_EXPR
)
9609 tree type
= TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (param
)));
9611 bool found_format_arg
= false;
9613 /* See if this is a call to a known internationalization function
9614 that modifies a format arg. Such a function may have multiple
9615 format_arg attributes (for example, ngettext). */
9617 for (attrs
= TYPE_ATTRIBUTES (type
);
9619 attrs
= TREE_CHAIN (attrs
))
9620 if (is_attribute_p ("format_arg", TREE_PURPOSE (attrs
)))
9623 tree format_num_expr
;
9626 call_expr_arg_iterator iter
;
9628 /* Extract the argument number, which was previously checked
9630 format_num_expr
= TREE_VALUE (TREE_VALUE (attrs
));
9632 format_num
= tree_to_uhwi (format_num_expr
);
9634 for (inner_arg
= first_call_expr_arg (param
, &iter
), i
= 1;
9636 inner_arg
= next_call_expr_arg (&iter
), i
++)
9637 if (i
== format_num
)
9639 check_function_arguments_recurse (callback
, ctx
,
9640 inner_arg
, param_num
);
9641 found_format_arg
= true;
9646 /* If we found a format_arg attribute and did a recursive check,
9647 we are done with checking this argument. Otherwise, we continue
9648 and this will be considered a non-literal. */
9649 if (found_format_arg
)
9653 if (TREE_CODE (param
) == COND_EXPR
)
9655 /* Check both halves of the conditional expression. */
9656 check_function_arguments_recurse (callback
, ctx
,
9657 TREE_OPERAND (param
, 1), param_num
);
9658 check_function_arguments_recurse (callback
, ctx
,
9659 TREE_OPERAND (param
, 2), param_num
);
9663 (*callback
) (ctx
, param
, param_num
);
9666 /* Checks for a builtin function FNDECL that the number of arguments
9667 NARGS against the required number REQUIRED and issues an error if
9668 there is a mismatch. Returns true if the number of arguments is
9669 correct, otherwise false. */
9672 builtin_function_validate_nargs (tree fndecl
, int nargs
, int required
)
9674 if (nargs
< required
)
9676 error_at (input_location
,
9677 "not enough arguments to function %qE", fndecl
);
9680 else if (nargs
> required
)
9682 error_at (input_location
,
9683 "too many arguments to function %qE", fndecl
);
9689 /* Verifies the NARGS arguments ARGS to the builtin function FNDECL.
9690 Returns false if there was an error, otherwise true. */
9693 check_builtin_function_arguments (tree fndecl
, int nargs
, tree
*args
)
9695 if (!DECL_BUILT_IN (fndecl
)
9696 || DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_NORMAL
)
9699 switch (DECL_FUNCTION_CODE (fndecl
))
9701 case BUILT_IN_CONSTANT_P
:
9702 return builtin_function_validate_nargs (fndecl
, nargs
, 1);
9704 case BUILT_IN_ISFINITE
:
9705 case BUILT_IN_ISINF
:
9706 case BUILT_IN_ISINF_SIGN
:
9707 case BUILT_IN_ISNAN
:
9708 case BUILT_IN_ISNORMAL
:
9709 if (builtin_function_validate_nargs (fndecl
, nargs
, 1))
9711 if (TREE_CODE (TREE_TYPE (args
[0])) != REAL_TYPE
)
9713 error ("non-floating-point argument in call to "
9714 "function %qE", fndecl
);
9721 case BUILT_IN_ISGREATER
:
9722 case BUILT_IN_ISGREATEREQUAL
:
9723 case BUILT_IN_ISLESS
:
9724 case BUILT_IN_ISLESSEQUAL
:
9725 case BUILT_IN_ISLESSGREATER
:
9726 case BUILT_IN_ISUNORDERED
:
9727 if (builtin_function_validate_nargs (fndecl
, nargs
, 2))
9729 enum tree_code code0
, code1
;
9730 code0
= TREE_CODE (TREE_TYPE (args
[0]));
9731 code1
= TREE_CODE (TREE_TYPE (args
[1]));
9732 if (!((code0
== REAL_TYPE
&& code1
== REAL_TYPE
)
9733 || (code0
== REAL_TYPE
&& code1
== INTEGER_TYPE
)
9734 || (code0
== INTEGER_TYPE
&& code1
== REAL_TYPE
)))
9736 error ("non-floating-point arguments in call to "
9737 "function %qE", fndecl
);
9744 case BUILT_IN_FPCLASSIFY
:
9745 if (builtin_function_validate_nargs (fndecl
, nargs
, 6))
9750 if (TREE_CODE (args
[i
]) != INTEGER_CST
)
9752 error ("non-const integer argument %u in call to function %qE",
9757 if (TREE_CODE (TREE_TYPE (args
[5])) != REAL_TYPE
)
9759 error ("non-floating-point argument in call to function %qE",
9767 case BUILT_IN_ASSUME_ALIGNED
:
9768 if (builtin_function_validate_nargs (fndecl
, nargs
, 2 + (nargs
> 2)))
9770 if (nargs
>= 3 && TREE_CODE (TREE_TYPE (args
[2])) != INTEGER_TYPE
)
9772 error ("non-integer argument 3 in call to function %qE", fndecl
);
9779 case BUILT_IN_ADD_OVERFLOW
:
9780 case BUILT_IN_SUB_OVERFLOW
:
9781 case BUILT_IN_MUL_OVERFLOW
:
9782 if (builtin_function_validate_nargs (fndecl
, nargs
, 3))
9785 for (i
= 0; i
< 2; i
++)
9786 if (!INTEGRAL_TYPE_P (TREE_TYPE (args
[i
])))
9788 error ("argument %u in call to function %qE does not have "
9789 "integral type", i
+ 1, fndecl
);
9792 if (TREE_CODE (TREE_TYPE (args
[2])) != POINTER_TYPE
9793 || TREE_CODE (TREE_TYPE (TREE_TYPE (args
[2]))) != INTEGER_TYPE
)
9795 error ("argument 3 in call to function %qE does not have "
9796 "pointer to integer type", fndecl
);
9808 /* Function to help qsort sort FIELD_DECLs by name order. */
9811 field_decl_cmp (const void *x_p
, const void *y_p
)
9813 const tree
*const x
= (const tree
*const) x_p
;
9814 const tree
*const y
= (const tree
*const) y_p
;
9816 if (DECL_NAME (*x
) == DECL_NAME (*y
))
9817 /* A nontype is "greater" than a type. */
9818 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
9819 if (DECL_NAME (*x
) == NULL_TREE
)
9821 if (DECL_NAME (*y
) == NULL_TREE
)
9823 if (DECL_NAME (*x
) < DECL_NAME (*y
))
9829 gt_pointer_operator new_value
;
9833 /* This routine compares two fields like field_decl_cmp but using the
9834 pointer operator in resort_data. */
9837 resort_field_decl_cmp (const void *x_p
, const void *y_p
)
9839 const tree
*const x
= (const tree
*const) x_p
;
9840 const tree
*const y
= (const tree
*const) y_p
;
9842 if (DECL_NAME (*x
) == DECL_NAME (*y
))
9843 /* A nontype is "greater" than a type. */
9844 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
9845 if (DECL_NAME (*x
) == NULL_TREE
)
9847 if (DECL_NAME (*y
) == NULL_TREE
)
9850 tree d1
= DECL_NAME (*x
);
9851 tree d2
= DECL_NAME (*y
);
9852 resort_data
.new_value (&d1
, resort_data
.cookie
);
9853 resort_data
.new_value (&d2
, resort_data
.cookie
);
9860 /* Resort DECL_SORTED_FIELDS because pointers have been reordered. */
9863 resort_sorted_fields (void *obj
,
9864 void * ARG_UNUSED (orig_obj
),
9865 gt_pointer_operator new_value
,
9868 struct sorted_fields_type
*sf
= (struct sorted_fields_type
*) obj
;
9869 resort_data
.new_value
= new_value
;
9870 resort_data
.cookie
= cookie
;
9871 qsort (&sf
->elts
[0], sf
->len
, sizeof (tree
),
9872 resort_field_decl_cmp
);
9875 /* Subroutine of c_parse_error.
9876 Return the result of concatenating LHS and RHS. RHS is really
9877 a string literal, its first character is indicated by RHS_START and
9878 RHS_SIZE is its length (including the terminating NUL character).
9880 The caller is responsible for deleting the returned pointer. */
9883 catenate_strings (const char *lhs
, const char *rhs_start
, int rhs_size
)
9885 const int lhs_size
= strlen (lhs
);
9886 char *result
= XNEWVEC (char, lhs_size
+ rhs_size
);
9887 strncpy (result
, lhs
, lhs_size
);
9888 strncpy (result
+ lhs_size
, rhs_start
, rhs_size
);
9892 /* Issue the error given by GMSGID, indicating that it occurred before
9893 TOKEN, which had the associated VALUE. */
9896 c_parse_error (const char *gmsgid
, enum cpp_ttype token_type
,
9897 tree value
, unsigned char token_flags
)
9899 #define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2))
9901 char *message
= NULL
;
9903 if (token_type
== CPP_EOF
)
9904 message
= catenate_messages (gmsgid
, " at end of input");
9905 else if (token_type
== CPP_CHAR
9906 || token_type
== CPP_WCHAR
9907 || token_type
== CPP_CHAR16
9908 || token_type
== CPP_CHAR32
)
9910 unsigned int val
= TREE_INT_CST_LOW (value
);
9929 if (val
<= UCHAR_MAX
&& ISGRAPH (val
))
9930 message
= catenate_messages (gmsgid
, " before %s'%c'");
9932 message
= catenate_messages (gmsgid
, " before %s'\\x%x'");
9934 error (message
, prefix
, val
);
9938 else if (token_type
== CPP_CHAR_USERDEF
9939 || token_type
== CPP_WCHAR_USERDEF
9940 || token_type
== CPP_CHAR16_USERDEF
9941 || token_type
== CPP_CHAR32_USERDEF
)
9942 message
= catenate_messages (gmsgid
,
9943 " before user-defined character literal");
9944 else if (token_type
== CPP_STRING_USERDEF
9945 || token_type
== CPP_WSTRING_USERDEF
9946 || token_type
== CPP_STRING16_USERDEF
9947 || token_type
== CPP_STRING32_USERDEF
9948 || token_type
== CPP_UTF8STRING_USERDEF
)
9949 message
= catenate_messages (gmsgid
, " before user-defined string literal");
9950 else if (token_type
== CPP_STRING
9951 || token_type
== CPP_WSTRING
9952 || token_type
== CPP_STRING16
9953 || token_type
== CPP_STRING32
9954 || token_type
== CPP_UTF8STRING
)
9955 message
= catenate_messages (gmsgid
, " before string constant");
9956 else if (token_type
== CPP_NUMBER
)
9957 message
= catenate_messages (gmsgid
, " before numeric constant");
9958 else if (token_type
== CPP_NAME
)
9960 message
= catenate_messages (gmsgid
, " before %qE");
9961 error (message
, value
);
9965 else if (token_type
== CPP_PRAGMA
)
9966 message
= catenate_messages (gmsgid
, " before %<#pragma%>");
9967 else if (token_type
== CPP_PRAGMA_EOL
)
9968 message
= catenate_messages (gmsgid
, " before end of line");
9969 else if (token_type
== CPP_DECLTYPE
)
9970 message
= catenate_messages (gmsgid
, " before %<decltype%>");
9971 else if (token_type
< N_TTYPES
)
9973 message
= catenate_messages (gmsgid
, " before %qs token");
9974 error (message
, cpp_type2name (token_type
, token_flags
));
9986 #undef catenate_messages
9989 /* Return the gcc option code associated with the reason for a cpp
9990 message, or 0 if none. */
9993 c_option_controlling_cpp_error (int reason
)
9995 const struct cpp_reason_option_codes_t
*entry
;
9997 for (entry
= cpp_reason_option_codes
; entry
->reason
!= CPP_W_NONE
; entry
++)
9999 if (entry
->reason
== reason
)
10000 return entry
->option_code
;
10005 /* Callback from cpp_error for PFILE to print diagnostics from the
10006 preprocessor. The diagnostic is of type LEVEL, with REASON set
10007 to the reason code if LEVEL is represents a warning, at location
10008 LOCATION unless this is after lexing and the compiler's location
10009 should be used instead, with column number possibly overridden by
10010 COLUMN_OVERRIDE if not zero; MSG is the translated message and AP
10011 the arguments. Returns true if a diagnostic was emitted, false
10015 c_cpp_error (cpp_reader
*pfile ATTRIBUTE_UNUSED
, int level
, int reason
,
10016 location_t location
, unsigned int column_override
,
10017 const char *msg
, va_list *ap
)
10019 diagnostic_info diagnostic
;
10020 diagnostic_t dlevel
;
10021 bool save_warn_system_headers
= global_dc
->dc_warn_system_headers
;
10026 case CPP_DL_WARNING_SYSHDR
:
10027 if (flag_no_output
)
10029 global_dc
->dc_warn_system_headers
= 1;
10030 /* Fall through. */
10031 case CPP_DL_WARNING
:
10032 if (flag_no_output
)
10034 dlevel
= DK_WARNING
;
10036 case CPP_DL_PEDWARN
:
10037 if (flag_no_output
&& !flag_pedantic_errors
)
10039 dlevel
= DK_PEDWARN
;
10054 gcc_unreachable ();
10057 location
= input_location
;
10058 diagnostic_set_info_translated (&diagnostic
, msg
, ap
,
10060 if (column_override
)
10061 diagnostic_override_column (&diagnostic
, column_override
);
10062 diagnostic_override_option_index (&diagnostic
,
10063 c_option_controlling_cpp_error (reason
));
10064 ret
= report_diagnostic (&diagnostic
);
10065 if (level
== CPP_DL_WARNING_SYSHDR
)
10066 global_dc
->dc_warn_system_headers
= save_warn_system_headers
;
10070 /* Convert a character from the host to the target execution character
10071 set. cpplib handles this, mostly. */
10074 c_common_to_target_charset (HOST_WIDE_INT c
)
10076 /* Character constants in GCC proper are sign-extended under -fsigned-char,
10077 zero-extended under -fno-signed-char. cpplib insists that characters
10078 and character constants are always unsigned. Hence we must convert
10080 cppchar_t uc
= ((cppchar_t
)c
) & ((((cppchar_t
)1) << CHAR_BIT
)-1);
10082 uc
= cpp_host_to_exec_charset (parse_in
, uc
);
10084 if (flag_signed_char
)
10085 return ((HOST_WIDE_INT
)uc
) << (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
)
10086 >> (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
);
10091 /* Fold an offsetof-like expression. EXPR is a nested sequence of component
10092 references with an INDIRECT_REF of a constant at the bottom; much like the
10093 traditional rendering of offsetof as a macro. Return the folded result. */
10096 fold_offsetof_1 (tree expr
)
10100 switch (TREE_CODE (expr
))
10106 error ("cannot apply %<offsetof%> to static data member %qD", expr
);
10107 return error_mark_node
;
10111 error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded");
10112 return error_mark_node
;
10116 if (!TREE_CONSTANT (TREE_OPERAND (expr
, 0)))
10118 error ("cannot apply %<offsetof%> to a non constant address");
10119 return error_mark_node
;
10121 return TREE_OPERAND (expr
, 0);
10123 case COMPONENT_REF
:
10124 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0));
10125 if (base
== error_mark_node
)
10128 t
= TREE_OPERAND (expr
, 1);
10129 if (DECL_C_BIT_FIELD (t
))
10131 error ("attempt to take address of bit-field structure "
10133 return error_mark_node
;
10135 off
= size_binop_loc (input_location
, PLUS_EXPR
, DECL_FIELD_OFFSET (t
),
10136 size_int (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (t
))
10141 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0));
10142 if (base
== error_mark_node
)
10145 t
= TREE_OPERAND (expr
, 1);
10147 /* Check if the offset goes beyond the upper bound of the array. */
10148 if (TREE_CODE (t
) == INTEGER_CST
&& tree_int_cst_sgn (t
) >= 0)
10150 tree upbound
= array_ref_up_bound (expr
);
10151 if (upbound
!= NULL_TREE
10152 && TREE_CODE (upbound
) == INTEGER_CST
10153 && !tree_int_cst_equal (upbound
,
10154 TYPE_MAX_VALUE (TREE_TYPE (upbound
))))
10156 upbound
= size_binop (PLUS_EXPR
, upbound
,
10157 build_int_cst (TREE_TYPE (upbound
), 1));
10158 if (tree_int_cst_lt (upbound
, t
))
10162 for (v
= TREE_OPERAND (expr
, 0);
10163 TREE_CODE (v
) == COMPONENT_REF
;
10164 v
= TREE_OPERAND (v
, 0))
10165 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v
, 0)))
10168 tree fld_chain
= DECL_CHAIN (TREE_OPERAND (v
, 1));
10169 for (; fld_chain
; fld_chain
= DECL_CHAIN (fld_chain
))
10170 if (TREE_CODE (fld_chain
) == FIELD_DECL
)
10176 /* Don't warn if the array might be considered a poor
10177 man's flexible array member with a very permissive
10178 definition thereof. */
10179 if (TREE_CODE (v
) == ARRAY_REF
10180 || TREE_CODE (v
) == COMPONENT_REF
)
10181 warning (OPT_Warray_bounds
,
10182 "index %E denotes an offset "
10183 "greater than size of %qT",
10184 t
, TREE_TYPE (TREE_OPERAND (expr
, 0)));
10189 t
= convert (sizetype
, t
);
10190 off
= size_binop (MULT_EXPR
, TYPE_SIZE_UNIT (TREE_TYPE (expr
)), t
);
10193 case COMPOUND_EXPR
:
10194 /* Handle static members of volatile structs. */
10195 t
= TREE_OPERAND (expr
, 1);
10196 gcc_assert (TREE_CODE (t
) == VAR_DECL
);
10197 return fold_offsetof_1 (t
);
10200 gcc_unreachable ();
10203 return fold_build_pointer_plus (base
, off
);
10206 /* Likewise, but convert it to the return type of offsetof. */
10209 fold_offsetof (tree expr
)
10211 return convert (size_type_node
, fold_offsetof_1 (expr
));
10214 /* Warn for A ?: C expressions (with B omitted) where A is a boolean
10215 expression, because B will always be true. */
10218 warn_for_omitted_condop (location_t location
, tree cond
)
10220 if (truth_value_p (TREE_CODE (cond
)))
10221 warning_at (location
, OPT_Wparentheses
,
10222 "the omitted middle operand in ?: will always be %<true%>, "
10223 "suggest explicit middle operand");
10226 /* Give an error for storing into ARG, which is 'const'. USE indicates
10227 how ARG was being used. */
10230 readonly_error (location_t loc
, tree arg
, enum lvalue_use use
)
10232 gcc_assert (use
== lv_assign
|| use
== lv_increment
|| use
== lv_decrement
10234 /* Using this macro rather than (for example) arrays of messages
10235 ensures that all the format strings are checked at compile
10237 #define READONLY_MSG(A, I, D, AS) (use == lv_assign ? (A) \
10238 : (use == lv_increment ? (I) \
10239 : (use == lv_decrement ? (D) : (AS))))
10240 if (TREE_CODE (arg
) == COMPONENT_REF
)
10242 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg
, 0))))
10243 error_at (loc
, READONLY_MSG (G_("assignment of member "
10244 "%qD in read-only object"),
10245 G_("increment of member "
10246 "%qD in read-only object"),
10247 G_("decrement of member "
10248 "%qD in read-only object"),
10249 G_("member %qD in read-only object "
10250 "used as %<asm%> output")),
10251 TREE_OPERAND (arg
, 1));
10253 error_at (loc
, READONLY_MSG (G_("assignment of read-only member %qD"),
10254 G_("increment of read-only member %qD"),
10255 G_("decrement of read-only member %qD"),
10256 G_("read-only member %qD used as %<asm%> output")),
10257 TREE_OPERAND (arg
, 1));
10259 else if (TREE_CODE (arg
) == VAR_DECL
)
10260 error_at (loc
, READONLY_MSG (G_("assignment of read-only variable %qD"),
10261 G_("increment of read-only variable %qD"),
10262 G_("decrement of read-only variable %qD"),
10263 G_("read-only variable %qD used as %<asm%> output")),
10265 else if (TREE_CODE (arg
) == PARM_DECL
)
10266 error_at (loc
, READONLY_MSG (G_("assignment of read-only parameter %qD"),
10267 G_("increment of read-only parameter %qD"),
10268 G_("decrement of read-only parameter %qD"),
10269 G_("read-only parameter %qD use as %<asm%> output")),
10271 else if (TREE_CODE (arg
) == RESULT_DECL
)
10273 gcc_assert (c_dialect_cxx ());
10274 error_at (loc
, READONLY_MSG (G_("assignment of "
10275 "read-only named return value %qD"),
10277 "read-only named return value %qD"),
10279 "read-only named return value %qD"),
10280 G_("read-only named return value %qD "
10281 "used as %<asm%>output")),
10284 else if (TREE_CODE (arg
) == FUNCTION_DECL
)
10285 error_at (loc
, READONLY_MSG (G_("assignment of function %qD"),
10286 G_("increment of function %qD"),
10287 G_("decrement of function %qD"),
10288 G_("function %qD used as %<asm%> output")),
10291 error_at (loc
, READONLY_MSG (G_("assignment of read-only location %qE"),
10292 G_("increment of read-only location %qE"),
10293 G_("decrement of read-only location %qE"),
10294 G_("read-only location %qE used as %<asm%> output")),
10298 /* Print an error message for an invalid lvalue. USE says
10299 how the lvalue is being used and so selects the error message. LOC
10300 is the location for the error. */
10303 lvalue_error (location_t loc
, enum lvalue_use use
)
10308 error_at (loc
, "lvalue required as left operand of assignment");
10311 error_at (loc
, "lvalue required as increment operand");
10314 error_at (loc
, "lvalue required as decrement operand");
10317 error_at (loc
, "lvalue required as unary %<&%> operand");
10320 error_at (loc
, "lvalue required in asm statement");
10323 gcc_unreachable ();
10327 /* Print an error message for an invalid indirection of type TYPE.
10328 ERRSTRING is the name of the operator for the indirection. */
10331 invalid_indirection_error (location_t loc
, tree type
, ref_operator errstring
)
10336 gcc_assert (c_dialect_cxx ());
10337 error_at (loc
, "invalid type argument (have %qT)", type
);
10339 case RO_ARRAY_INDEXING
:
10341 "invalid type argument of array indexing (have %qT)",
10344 case RO_UNARY_STAR
:
10346 "invalid type argument of unary %<*%> (have %qT)",
10351 "invalid type argument of %<->%> (have %qT)",
10354 case RO_ARROW_STAR
:
10356 "invalid type argument of %<->*%> (have %qT)",
10359 case RO_IMPLICIT_CONVERSION
:
10361 "invalid type argument of implicit conversion (have %qT)",
10365 gcc_unreachable ();
10369 /* *PTYPE is an incomplete array. Complete it with a domain based on
10370 INITIAL_VALUE. If INITIAL_VALUE is not present, use 1 if DO_DEFAULT
10371 is true. Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
10372 2 if INITIAL_VALUE was NULL, and 3 if INITIAL_VALUE was empty. */
10375 complete_array_type (tree
*ptype
, tree initial_value
, bool do_default
)
10377 tree maxindex
, type
, main_type
, elt
, unqual_elt
;
10378 int failure
= 0, quals
;
10379 hashval_t hashcode
= 0;
10380 bool overflow_p
= false;
10382 maxindex
= size_zero_node
;
10385 if (TREE_CODE (initial_value
) == STRING_CST
)
10388 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value
)));
10389 maxindex
= size_int (TREE_STRING_LENGTH (initial_value
)/eltsize
- 1);
10391 else if (TREE_CODE (initial_value
) == CONSTRUCTOR
)
10393 vec
<constructor_elt
, va_gc
> *v
= CONSTRUCTOR_ELTS (initial_value
);
10395 if (vec_safe_is_empty (v
))
10399 maxindex
= ssize_int (-1);
10404 unsigned HOST_WIDE_INT cnt
;
10405 constructor_elt
*ce
;
10406 bool fold_p
= false;
10409 maxindex
= (*v
)[0].index
, fold_p
= true;
10411 curindex
= maxindex
;
10413 for (cnt
= 1; vec_safe_iterate (v
, cnt
, &ce
); cnt
++)
10415 bool curfold_p
= false;
10417 curindex
= ce
->index
, curfold_p
= true;
10422 /* Since we treat size types now as ordinary
10423 unsigned types, we need an explicit overflow
10425 tree orig
= curindex
;
10426 curindex
= fold_convert (sizetype
, curindex
);
10427 overflow_p
|= tree_int_cst_lt (curindex
, orig
);
10429 curindex
= size_binop (PLUS_EXPR
, curindex
,
10432 if (tree_int_cst_lt (maxindex
, curindex
))
10433 maxindex
= curindex
, fold_p
= curfold_p
;
10437 tree orig
= maxindex
;
10438 maxindex
= fold_convert (sizetype
, maxindex
);
10439 overflow_p
|= tree_int_cst_lt (maxindex
, orig
);
10445 /* Make an error message unless that happened already. */
10446 if (initial_value
!= error_mark_node
)
10458 elt
= TREE_TYPE (type
);
10459 quals
= TYPE_QUALS (strip_array_types (elt
));
10463 unqual_elt
= c_build_qualified_type (elt
, KEEP_QUAL_ADDR_SPACE (quals
));
10465 /* Using build_distinct_type_copy and modifying things afterward instead
10466 of using build_array_type to create a new type preserves all of the
10467 TYPE_LANG_FLAG_? bits that the front end may have set. */
10468 main_type
= build_distinct_type_copy (TYPE_MAIN_VARIANT (type
));
10469 TREE_TYPE (main_type
) = unqual_elt
;
10470 TYPE_DOMAIN (main_type
)
10471 = build_range_type (TREE_TYPE (maxindex
),
10472 build_int_cst (TREE_TYPE (maxindex
), 0), maxindex
);
10473 layout_type (main_type
);
10475 /* Make sure we have the canonical MAIN_TYPE. */
10476 hashcode
= iterative_hash_object (TYPE_HASH (unqual_elt
), hashcode
);
10477 hashcode
= iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (main_type
)),
10479 main_type
= type_hash_canon (hashcode
, main_type
);
10481 /* Fix the canonical type. */
10482 if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type
))
10483 || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type
)))
10484 SET_TYPE_STRUCTURAL_EQUALITY (main_type
);
10485 else if (TYPE_CANONICAL (TREE_TYPE (main_type
)) != TREE_TYPE (main_type
)
10486 || (TYPE_CANONICAL (TYPE_DOMAIN (main_type
))
10487 != TYPE_DOMAIN (main_type
)))
10488 TYPE_CANONICAL (main_type
)
10489 = build_array_type (TYPE_CANONICAL (TREE_TYPE (main_type
)),
10490 TYPE_CANONICAL (TYPE_DOMAIN (main_type
)));
10492 TYPE_CANONICAL (main_type
) = main_type
;
10497 type
= c_build_qualified_type (main_type
, quals
);
10499 if (COMPLETE_TYPE_P (type
)
10500 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
10501 && (overflow_p
|| TREE_OVERFLOW (TYPE_SIZE_UNIT (type
))))
10503 error ("size of array is too large");
10504 /* If we proceed with the array type as it is, we'll eventually
10505 crash in tree_to_[su]hwi(). */
10506 type
= error_mark_node
;
10513 /* Like c_mark_addressable but don't check register qualifier. */
10515 c_common_mark_addressable_vec (tree t
)
10517 while (handled_component_p (t
))
10518 t
= TREE_OPERAND (t
, 0);
10519 if (TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != PARM_DECL
)
10521 TREE_ADDRESSABLE (t
) = 1;
10526 /* Used to help initialize the builtin-types.def table. When a type of
10527 the correct size doesn't exist, use error_mark_node instead of NULL.
10528 The later results in segfaults even when a decl using the type doesn't
10532 builtin_type_for_size (int size
, bool unsignedp
)
10534 tree type
= c_common_type_for_size (size
, unsignedp
);
10535 return type
? type
: error_mark_node
;
10538 /* A helper function for resolve_overloaded_builtin in resolving the
10539 overloaded __sync_ builtins. Returns a positive power of 2 if the
10540 first operand of PARAMS is a pointer to a supported data type.
10541 Returns 0 if an error is encountered. */
10544 sync_resolve_size (tree function
, vec
<tree
, va_gc
> *params
)
10551 error ("too few arguments to function %qE", function
);
10555 type
= TREE_TYPE ((*params
)[0]);
10556 if (TREE_CODE (type
) == ARRAY_TYPE
)
10558 /* Force array-to-pointer decay for C++. */
10559 gcc_assert (c_dialect_cxx());
10560 (*params
)[0] = default_conversion ((*params
)[0]);
10561 type
= TREE_TYPE ((*params
)[0]);
10563 if (TREE_CODE (type
) != POINTER_TYPE
)
10566 type
= TREE_TYPE (type
);
10567 if (!INTEGRAL_TYPE_P (type
) && !POINTER_TYPE_P (type
))
10570 size
= tree_to_uhwi (TYPE_SIZE_UNIT (type
));
10571 if (size
== 1 || size
== 2 || size
== 4 || size
== 8 || size
== 16)
10575 error ("incompatible type for argument %d of %qE", 1, function
);
10579 /* A helper function for resolve_overloaded_builtin. Adds casts to
10580 PARAMS to make arguments match up with those of FUNCTION. Drops
10581 the variadic arguments at the end. Returns false if some error
10582 was encountered; true on success. */
10585 sync_resolve_params (location_t loc
, tree orig_function
, tree function
,
10586 vec
<tree
, va_gc
> *params
, bool orig_format
)
10588 function_args_iterator iter
;
10590 unsigned int parmnum
;
10592 function_args_iter_init (&iter
, TREE_TYPE (function
));
10593 /* We've declared the implementation functions to use "volatile void *"
10594 as the pointer parameter, so we shouldn't get any complaints from the
10595 call to check_function_arguments what ever type the user used. */
10596 function_args_iter_next (&iter
);
10597 ptype
= TREE_TYPE (TREE_TYPE ((*params
)[0]));
10598 ptype
= TYPE_MAIN_VARIANT (ptype
);
10600 /* For the rest of the values, we need to cast these to FTYPE, so that we
10601 don't get warnings for passing pointer types, etc. */
10605 tree val
, arg_type
;
10607 arg_type
= function_args_iter_cond (&iter
);
10608 /* XXX void_type_node belies the abstraction. */
10609 if (arg_type
== void_type_node
)
10613 if (params
->length () <= parmnum
)
10615 error_at (loc
, "too few arguments to function %qE", orig_function
);
10619 /* Only convert parameters if arg_type is unsigned integer type with
10620 new format sync routines, i.e. don't attempt to convert pointer
10621 arguments (e.g. EXPECTED argument of __atomic_compare_exchange_n),
10622 bool arguments (e.g. WEAK argument) or signed int arguments (memmodel
10624 if (TREE_CODE (arg_type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (arg_type
))
10626 /* Ideally for the first conversion we'd use convert_for_assignment
10627 so that we get warnings for anything that doesn't match the pointer
10628 type. This isn't portable across the C and C++ front ends atm. */
10629 val
= (*params
)[parmnum
];
10630 val
= convert (ptype
, val
);
10631 val
= convert (arg_type
, val
);
10632 (*params
)[parmnum
] = val
;
10635 function_args_iter_next (&iter
);
10638 /* __atomic routines are not variadic. */
10639 if (!orig_format
&& params
->length () != parmnum
+ 1)
10641 error_at (loc
, "too many arguments to function %qE", orig_function
);
10645 /* The definition of these primitives is variadic, with the remaining
10646 being "an optional list of variables protected by the memory barrier".
10647 No clue what that's supposed to mean, precisely, but we consider all
10648 call-clobbered variables to be protected so we're safe. */
10649 params
->truncate (parmnum
+ 1);
10654 /* A helper function for resolve_overloaded_builtin. Adds a cast to
10655 RESULT to make it match the type of the first pointer argument in
10659 sync_resolve_return (tree first_param
, tree result
, bool orig_format
)
10661 tree ptype
= TREE_TYPE (TREE_TYPE (first_param
));
10662 tree rtype
= TREE_TYPE (result
);
10663 ptype
= TYPE_MAIN_VARIANT (ptype
);
10665 /* New format doesn't require casting unless the types are the same size. */
10666 if (orig_format
|| tree_int_cst_equal (TYPE_SIZE (ptype
), TYPE_SIZE (rtype
)))
10667 return convert (ptype
, result
);
10672 /* This function verifies the PARAMS to generic atomic FUNCTION.
10673 It returns the size if all the parameters are the same size, otherwise
10674 0 is returned if the parameters are invalid. */
10677 get_atomic_generic_size (location_t loc
, tree function
,
10678 vec
<tree
, va_gc
> *params
)
10680 unsigned int n_param
;
10681 unsigned int n_model
;
10686 /* Determine the parameter makeup. */
10687 switch (DECL_FUNCTION_CODE (function
))
10689 case BUILT_IN_ATOMIC_EXCHANGE
:
10693 case BUILT_IN_ATOMIC_LOAD
:
10694 case BUILT_IN_ATOMIC_STORE
:
10698 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10703 gcc_unreachable ();
10706 if (vec_safe_length (params
) != n_param
)
10708 error_at (loc
, "incorrect number of arguments to function %qE", function
);
10712 /* Get type of first parameter, and determine its size. */
10713 type_0
= TREE_TYPE ((*params
)[0]);
10714 if (TREE_CODE (type_0
) == ARRAY_TYPE
)
10716 /* Force array-to-pointer decay for C++. */
10717 gcc_assert (c_dialect_cxx());
10718 (*params
)[0] = default_conversion ((*params
)[0]);
10719 type_0
= TREE_TYPE ((*params
)[0]);
10721 if (TREE_CODE (type_0
) != POINTER_TYPE
|| VOID_TYPE_P (TREE_TYPE (type_0
)))
10723 error_at (loc
, "argument 1 of %qE must be a non-void pointer type",
10728 /* Types must be compile time constant sizes. */
10729 if (TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type_0
)))) != INTEGER_CST
)
10732 "argument 1 of %qE must be a pointer to a constant size type",
10737 size_0
= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type_0
)));
10739 /* Zero size objects are not allowed. */
10743 "argument 1 of %qE must be a pointer to a nonzero size object",
10748 /* Check each other parameter is a pointer and the same size. */
10749 for (x
= 0; x
< n_param
- n_model
; x
++)
10752 tree type
= TREE_TYPE ((*params
)[x
]);
10753 /* __atomic_compare_exchange has a bool in the 4th position, skip it. */
10754 if (n_param
== 6 && x
== 3)
10756 if (!POINTER_TYPE_P (type
))
10758 error_at (loc
, "argument %d of %qE must be a pointer type", x
+ 1,
10762 tree type_size
= TYPE_SIZE_UNIT (TREE_TYPE (type
));
10763 size
= type_size
? tree_to_uhwi (type_size
) : 0;
10764 if (size
!= size_0
)
10766 error_at (loc
, "size mismatch in argument %d of %qE", x
+ 1,
10772 /* Check memory model parameters for validity. */
10773 for (x
= n_param
- n_model
; x
< n_param
; x
++)
10775 tree p
= (*params
)[x
];
10776 if (TREE_CODE (p
) == INTEGER_CST
)
10778 int i
= tree_to_uhwi (p
);
10779 if (i
< 0 || (i
& MEMMODEL_MASK
) >= MEMMODEL_LAST
)
10781 warning_at (loc
, OPT_Winvalid_memory_model
,
10782 "invalid memory model argument %d of %qE", x
+ 1,
10787 if (!INTEGRAL_TYPE_P (TREE_TYPE (p
)))
10789 error_at (loc
, "non-integer memory model argument %d of %qE", x
+ 1,
10799 /* This will take an __atomic_ generic FUNCTION call, and add a size parameter N
10800 at the beginning of the parameter list PARAMS representing the size of the
10801 objects. This is to match the library ABI requirement. LOC is the location
10802 of the function call.
10803 The new function is returned if it needed rebuilding, otherwise NULL_TREE is
10804 returned to allow the external call to be constructed. */
10807 add_atomic_size_parameter (unsigned n
, location_t loc
, tree function
,
10808 vec
<tree
, va_gc
> *params
)
10812 /* Insert a SIZE_T parameter as the first param. If there isn't
10813 enough space, allocate a new vector and recursively re-build with that. */
10814 if (!params
->space (1))
10816 unsigned int z
, len
;
10817 vec
<tree
, va_gc
> *v
;
10820 len
= params
->length ();
10821 vec_alloc (v
, len
+ 1);
10822 v
->quick_push (build_int_cst (size_type_node
, n
));
10823 for (z
= 0; z
< len
; z
++)
10824 v
->quick_push ((*params
)[z
]);
10825 f
= build_function_call_vec (loc
, vNULL
, function
, v
, NULL
);
10830 /* Add the size parameter and leave as a function call for processing. */
10831 size_node
= build_int_cst (size_type_node
, n
);
10832 params
->quick_insert (0, size_node
);
10837 /* Return whether atomic operations for naturally aligned N-byte
10838 arguments are supported, whether inline or through libatomic. */
10840 atomic_size_supported_p (int n
)
10851 return targetm
.scalar_mode_supported_p (TImode
);
10858 /* This will process an __atomic_exchange function call, determine whether it
10859 needs to be mapped to the _N variation, or turned into a library call.
10860 LOC is the location of the builtin call.
10861 FUNCTION is the DECL that has been invoked;
10862 PARAMS is the argument list for the call. The return value is non-null
10863 TRUE is returned if it is translated into the proper format for a call to the
10864 external library, and NEW_RETURN is set the tree for that function.
10865 FALSE is returned if processing for the _N variation is required, and
10866 NEW_RETURN is set to the the return value the result is copied into. */
10868 resolve_overloaded_atomic_exchange (location_t loc
, tree function
,
10869 vec
<tree
, va_gc
> *params
, tree
*new_return
)
10871 tree p0
, p1
, p2
, p3
;
10872 tree I_type
, I_type_ptr
;
10873 int n
= get_atomic_generic_size (loc
, function
, params
);
10875 /* Size of 0 is an error condition. */
10878 *new_return
= error_mark_node
;
10882 /* If not a lock-free size, change to the library generic format. */
10883 if (!atomic_size_supported_p (n
))
10885 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10889 /* Otherwise there is a lockfree match, transform the call from:
10890 void fn(T* mem, T* desired, T* return, model)
10892 *return = (T) (fn (In* mem, (In) *desired, model)) */
10899 /* Create pointer to appropriate size. */
10900 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10901 I_type_ptr
= build_pointer_type (I_type
);
10903 /* Convert object pointer to required type. */
10904 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10906 /* Convert new value to required type, and dereference it. */
10907 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
10908 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
10911 /* Move memory model to the 3rd position, and end param list. */
10913 params
->truncate (3);
10915 /* Convert return pointer and dereference it for later assignment. */
10916 *new_return
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
10922 /* This will process an __atomic_compare_exchange function call, determine
10923 whether it needs to be mapped to the _N variation, or turned into a lib call.
10924 LOC is the location of the builtin call.
10925 FUNCTION is the DECL that has been invoked;
10926 PARAMS is the argument list for the call. The return value is non-null
10927 TRUE is returned if it is translated into the proper format for a call to the
10928 external library, and NEW_RETURN is set the tree for that function.
10929 FALSE is returned if processing for the _N variation is required. */
10932 resolve_overloaded_atomic_compare_exchange (location_t loc
, tree function
,
10933 vec
<tree
, va_gc
> *params
,
10937 tree I_type
, I_type_ptr
;
10938 int n
= get_atomic_generic_size (loc
, function
, params
);
10940 /* Size of 0 is an error condition. */
10943 *new_return
= error_mark_node
;
10947 /* If not a lock-free size, change to the library generic format. */
10948 if (!atomic_size_supported_p (n
))
10950 /* The library generic format does not have the weak parameter, so
10951 remove it from the param list. Since a parameter has been removed,
10952 we can be sure that there is room for the SIZE_T parameter, meaning
10953 there will not be a recursive rebuilding of the parameter list, so
10954 there is no danger this will be done twice. */
10957 (*params
)[3] = (*params
)[4];
10958 (*params
)[4] = (*params
)[5];
10959 params
->truncate (5);
10961 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10965 /* Otherwise, there is a match, so the call needs to be transformed from:
10966 bool fn(T* mem, T* desired, T* return, weak, success, failure)
10968 bool fn ((In *)mem, (In *)expected, (In) *desired, weak, succ, fail) */
10974 /* Create pointer to appropriate size. */
10975 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10976 I_type_ptr
= build_pointer_type (I_type
);
10978 /* Convert object pointer to required type. */
10979 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10982 /* Convert expected pointer to required type. */
10983 p1
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p1
);
10986 /* Convert desired value to required type, and dereference it. */
10987 p2
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
10988 p2
= build1 (VIEW_CONVERT_EXPR
, I_type
, p2
);
10991 /* The rest of the parameters are fine. NULL means no special return value
10993 *new_return
= NULL
;
10998 /* This will process an __atomic_load function call, determine whether it
10999 needs to be mapped to the _N variation, or turned into a library call.
11000 LOC is the location of the builtin call.
11001 FUNCTION is the DECL that has been invoked;
11002 PARAMS is the argument list for the call. The return value is non-null
11003 TRUE is returned if it is translated into the proper format for a call to the
11004 external library, and NEW_RETURN is set the tree for that function.
11005 FALSE is returned if processing for the _N variation is required, and
11006 NEW_RETURN is set to the the return value the result is copied into. */
11009 resolve_overloaded_atomic_load (location_t loc
, tree function
,
11010 vec
<tree
, va_gc
> *params
, tree
*new_return
)
11013 tree I_type
, I_type_ptr
;
11014 int n
= get_atomic_generic_size (loc
, function
, params
);
11016 /* Size of 0 is an error condition. */
11019 *new_return
= error_mark_node
;
11023 /* If not a lock-free size, change to the library generic format. */
11024 if (!atomic_size_supported_p (n
))
11026 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
11030 /* Otherwise, there is a match, so the call needs to be transformed from:
11031 void fn(T* mem, T* return, model)
11033 *return = (T) (fn ((In *) mem, model)) */
11039 /* Create pointer to appropriate size. */
11040 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
11041 I_type_ptr
= build_pointer_type (I_type
);
11043 /* Convert object pointer to required type. */
11044 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
11047 /* Move memory model to the 2nd position, and end param list. */
11049 params
->truncate (2);
11051 /* Convert return pointer and dereference it for later assignment. */
11052 *new_return
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
11058 /* This will process an __atomic_store function call, determine whether it
11059 needs to be mapped to the _N variation, or turned into a library call.
11060 LOC is the location of the builtin call.
11061 FUNCTION is the DECL that has been invoked;
11062 PARAMS is the argument list for the call. The return value is non-null
11063 TRUE is returned if it is translated into the proper format for a call to the
11064 external library, and NEW_RETURN is set the tree for that function.
11065 FALSE is returned if processing for the _N variation is required, and
11066 NEW_RETURN is set to the the return value the result is copied into. */
11069 resolve_overloaded_atomic_store (location_t loc
, tree function
,
11070 vec
<tree
, va_gc
> *params
, tree
*new_return
)
11073 tree I_type
, I_type_ptr
;
11074 int n
= get_atomic_generic_size (loc
, function
, params
);
11076 /* Size of 0 is an error condition. */
11079 *new_return
= error_mark_node
;
11083 /* If not a lock-free size, change to the library generic format. */
11084 if (!atomic_size_supported_p (n
))
11086 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
11090 /* Otherwise, there is a match, so the call needs to be transformed from:
11091 void fn(T* mem, T* value, model)
11093 fn ((In *) mem, (In) *value, model) */
11098 /* Create pointer to appropriate size. */
11099 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
11100 I_type_ptr
= build_pointer_type (I_type
);
11102 /* Convert object pointer to required type. */
11103 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
11106 /* Convert new value to required type, and dereference it. */
11107 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
11108 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
11111 /* The memory model is in the right spot already. Return is void. */
11112 *new_return
= NULL_TREE
;
11118 /* Some builtin functions are placeholders for other expressions. This
11119 function should be called immediately after parsing the call expression
11120 before surrounding code has committed to the type of the expression.
11122 LOC is the location of the builtin call.
11124 FUNCTION is the DECL that has been invoked; it is known to be a builtin.
11125 PARAMS is the argument list for the call. The return value is non-null
11126 when expansion is complete, and null if normal processing should
11130 resolve_overloaded_builtin (location_t loc
, tree function
,
11131 vec
<tree
, va_gc
> *params
)
11133 enum built_in_function orig_code
= DECL_FUNCTION_CODE (function
);
11134 bool orig_format
= true;
11135 tree new_return
= NULL_TREE
;
11137 switch (DECL_BUILT_IN_CLASS (function
))
11139 case BUILT_IN_NORMAL
:
11142 if (targetm
.resolve_overloaded_builtin
)
11143 return targetm
.resolve_overloaded_builtin (loc
, function
, params
);
11150 /* Handle BUILT_IN_NORMAL here. */
11153 case BUILT_IN_ATOMIC_EXCHANGE
:
11154 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
11155 case BUILT_IN_ATOMIC_LOAD
:
11156 case BUILT_IN_ATOMIC_STORE
:
11158 /* Handle these 4 together so that they can fall through to the next
11159 case if the call is transformed to an _N variant. */
11162 case BUILT_IN_ATOMIC_EXCHANGE
:
11164 if (resolve_overloaded_atomic_exchange (loc
, function
, params
,
11167 /* Change to the _N variant. */
11168 orig_code
= BUILT_IN_ATOMIC_EXCHANGE_N
;
11172 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
11174 if (resolve_overloaded_atomic_compare_exchange (loc
, function
,
11178 /* Change to the _N variant. */
11179 orig_code
= BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
;
11182 case BUILT_IN_ATOMIC_LOAD
:
11184 if (resolve_overloaded_atomic_load (loc
, function
, params
,
11187 /* Change to the _N variant. */
11188 orig_code
= BUILT_IN_ATOMIC_LOAD_N
;
11191 case BUILT_IN_ATOMIC_STORE
:
11193 if (resolve_overloaded_atomic_store (loc
, function
, params
,
11196 /* Change to the _N variant. */
11197 orig_code
= BUILT_IN_ATOMIC_STORE_N
;
11201 gcc_unreachable ();
11203 /* Fallthrough to the normal processing. */
11205 case BUILT_IN_ATOMIC_EXCHANGE_N
:
11206 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
:
11207 case BUILT_IN_ATOMIC_LOAD_N
:
11208 case BUILT_IN_ATOMIC_STORE_N
:
11209 case BUILT_IN_ATOMIC_ADD_FETCH_N
:
11210 case BUILT_IN_ATOMIC_SUB_FETCH_N
:
11211 case BUILT_IN_ATOMIC_AND_FETCH_N
:
11212 case BUILT_IN_ATOMIC_NAND_FETCH_N
:
11213 case BUILT_IN_ATOMIC_XOR_FETCH_N
:
11214 case BUILT_IN_ATOMIC_OR_FETCH_N
:
11215 case BUILT_IN_ATOMIC_FETCH_ADD_N
:
11216 case BUILT_IN_ATOMIC_FETCH_SUB_N
:
11217 case BUILT_IN_ATOMIC_FETCH_AND_N
:
11218 case BUILT_IN_ATOMIC_FETCH_NAND_N
:
11219 case BUILT_IN_ATOMIC_FETCH_XOR_N
:
11220 case BUILT_IN_ATOMIC_FETCH_OR_N
:
11222 orig_format
= false;
11223 /* Fallthru for parameter processing. */
11225 case BUILT_IN_SYNC_FETCH_AND_ADD_N
:
11226 case BUILT_IN_SYNC_FETCH_AND_SUB_N
:
11227 case BUILT_IN_SYNC_FETCH_AND_OR_N
:
11228 case BUILT_IN_SYNC_FETCH_AND_AND_N
:
11229 case BUILT_IN_SYNC_FETCH_AND_XOR_N
:
11230 case BUILT_IN_SYNC_FETCH_AND_NAND_N
:
11231 case BUILT_IN_SYNC_ADD_AND_FETCH_N
:
11232 case BUILT_IN_SYNC_SUB_AND_FETCH_N
:
11233 case BUILT_IN_SYNC_OR_AND_FETCH_N
:
11234 case BUILT_IN_SYNC_AND_AND_FETCH_N
:
11235 case BUILT_IN_SYNC_XOR_AND_FETCH_N
:
11236 case BUILT_IN_SYNC_NAND_AND_FETCH_N
:
11237 case BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
:
11238 case BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N
:
11239 case BUILT_IN_SYNC_LOCK_TEST_AND_SET_N
:
11240 case BUILT_IN_SYNC_LOCK_RELEASE_N
:
11242 int n
= sync_resolve_size (function
, params
);
11243 tree new_function
, first_param
, result
;
11244 enum built_in_function fncode
;
11247 return error_mark_node
;
11249 fncode
= (enum built_in_function
)((int)orig_code
+ exact_log2 (n
) + 1);
11250 new_function
= builtin_decl_explicit (fncode
);
11251 if (!sync_resolve_params (loc
, function
, new_function
, params
,
11253 return error_mark_node
;
11255 first_param
= (*params
)[0];
11256 result
= build_function_call_vec (loc
, vNULL
, new_function
, params
,
11258 if (result
== error_mark_node
)
11260 if (orig_code
!= BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
11261 && orig_code
!= BUILT_IN_SYNC_LOCK_RELEASE_N
11262 && orig_code
!= BUILT_IN_ATOMIC_STORE_N
)
11263 result
= sync_resolve_return (first_param
, result
, orig_format
);
11265 /* If new_return is set, assign function to that expr and cast the
11266 result to void since the generic interface returned void. */
11269 /* Cast function result from I{1,2,4,8,16} to the required type. */
11270 result
= build1 (VIEW_CONVERT_EXPR
, TREE_TYPE (new_return
), result
);
11271 result
= build2 (MODIFY_EXPR
, TREE_TYPE (new_return
), new_return
,
11273 TREE_SIDE_EFFECTS (result
) = 1;
11274 protected_set_expr_location (result
, loc
);
11275 result
= convert (void_type_node
, result
);
11285 /* vector_types_compatible_elements_p is used in type checks of vectors
11286 values used as operands of binary operators. Where it returns true, and
11287 the other checks of the caller succeed (being vector types in he first
11288 place, and matching number of elements), we can just treat the types
11289 as essentially the same.
11290 Contrast with vector_targets_convertible_p, which is used for vector
11291 pointer types, and vector_types_convertible_p, which will allow
11292 language-specific matches under the control of flag_lax_vector_conversions,
11293 and might still require a conversion. */
11294 /* True if vector types T1 and T2 can be inputs to the same binary
11295 operator without conversion.
11296 We don't check the overall vector size here because some of our callers
11297 want to give different error messages when the vectors are compatible
11298 except for the element count. */
11301 vector_types_compatible_elements_p (tree t1
, tree t2
)
11303 bool opaque
= TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
);
11304 t1
= TREE_TYPE (t1
);
11305 t2
= TREE_TYPE (t2
);
11307 enum tree_code c1
= TREE_CODE (t1
), c2
= TREE_CODE (t2
);
11309 gcc_assert ((c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
|| c1
== FIXED_POINT_TYPE
)
11310 && (c2
== INTEGER_TYPE
|| c2
== REAL_TYPE
11311 || c2
== FIXED_POINT_TYPE
));
11313 t1
= c_common_signed_type (t1
);
11314 t2
= c_common_signed_type (t2
);
11315 /* Equality works here because c_common_signed_type uses
11316 TYPE_MAIN_VARIANT. */
11319 if (opaque
&& c1
== c2
11320 && (c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
)
11321 && TYPE_PRECISION (t1
) == TYPE_PRECISION (t2
))
11326 /* Check for missing format attributes on function pointers. LTYPE is
11327 the new type or left-hand side type. RTYPE is the old type or
11328 right-hand side type. Returns TRUE if LTYPE is missing the desired
11332 check_missing_format_attribute (tree ltype
, tree rtype
)
11334 tree
const ttr
= TREE_TYPE (rtype
), ttl
= TREE_TYPE (ltype
);
11337 for (ra
= TYPE_ATTRIBUTES (ttr
); ra
; ra
= TREE_CHAIN (ra
))
11338 if (is_attribute_p ("format", TREE_PURPOSE (ra
)))
11343 for (la
= TYPE_ATTRIBUTES (ttl
); la
; la
= TREE_CHAIN (la
))
11344 if (is_attribute_p ("format", TREE_PURPOSE (la
)))
11352 /* Subscripting with type char is likely to lose on a machine where
11353 chars are signed. So warn on any machine, but optionally. Don't
11354 warn for unsigned char since that type is safe. Don't warn for
11355 signed char because anyone who uses that must have done so
11356 deliberately. Furthermore, we reduce the false positive load by
11357 warning only for non-constant value of type char. */
11360 warn_array_subscript_with_type_char (location_t loc
, tree index
)
11362 if (TYPE_MAIN_VARIANT (TREE_TYPE (index
)) == char_type_node
11363 && TREE_CODE (index
) != INTEGER_CST
)
11364 warning_at (loc
, OPT_Wchar_subscripts
,
11365 "array subscript has type %<char%>");
11368 /* Implement -Wparentheses for the unexpected C precedence rules, to
11369 cover cases like x + y << z which readers are likely to
11370 misinterpret. We have seen an expression in which CODE is a binary
11371 operator used to combine expressions ARG_LEFT and ARG_RIGHT, which
11372 before folding had CODE_LEFT and CODE_RIGHT. CODE_LEFT and
11373 CODE_RIGHT may be ERROR_MARK, which means that that side of the
11374 expression was not formed using a binary or unary operator, or it
11375 was enclosed in parentheses. */
11378 warn_about_parentheses (location_t loc
, enum tree_code code
,
11379 enum tree_code code_left
, tree arg_left
,
11380 enum tree_code code_right
, tree arg_right
)
11382 if (!warn_parentheses
)
11385 /* This macro tests that the expression ARG with original tree code
11386 CODE appears to be a boolean expression. or the result of folding a
11387 boolean expression. */
11388 #define APPEARS_TO_BE_BOOLEAN_EXPR_P(CODE, ARG) \
11389 (truth_value_p (TREE_CODE (ARG)) \
11390 || TREE_CODE (TREE_TYPE (ARG)) == BOOLEAN_TYPE \
11391 /* Folding may create 0 or 1 integers from other expressions. */ \
11392 || ((CODE) != INTEGER_CST \
11393 && (integer_onep (ARG) || integer_zerop (ARG))))
11398 if (code_left
== PLUS_EXPR
)
11399 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11400 "suggest parentheses around %<+%> inside %<<<%>");
11401 else if (code_right
== PLUS_EXPR
)
11402 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11403 "suggest parentheses around %<+%> inside %<<<%>");
11404 else if (code_left
== MINUS_EXPR
)
11405 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11406 "suggest parentheses around %<-%> inside %<<<%>");
11407 else if (code_right
== MINUS_EXPR
)
11408 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11409 "suggest parentheses around %<-%> inside %<<<%>");
11413 if (code_left
== PLUS_EXPR
)
11414 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11415 "suggest parentheses around %<+%> inside %<>>%>");
11416 else if (code_right
== PLUS_EXPR
)
11417 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11418 "suggest parentheses around %<+%> inside %<>>%>");
11419 else if (code_left
== MINUS_EXPR
)
11420 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11421 "suggest parentheses around %<-%> inside %<>>%>");
11422 else if (code_right
== MINUS_EXPR
)
11423 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11424 "suggest parentheses around %<-%> inside %<>>%>");
11427 case TRUTH_ORIF_EXPR
:
11428 if (code_left
== TRUTH_ANDIF_EXPR
)
11429 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11430 "suggest parentheses around %<&&%> within %<||%>");
11431 else if (code_right
== TRUTH_ANDIF_EXPR
)
11432 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11433 "suggest parentheses around %<&&%> within %<||%>");
11437 if (code_left
== BIT_AND_EXPR
|| code_left
== BIT_XOR_EXPR
11438 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
)
11439 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11440 "suggest parentheses around arithmetic in operand of %<|%>");
11441 else if (code_right
== BIT_AND_EXPR
|| code_right
== BIT_XOR_EXPR
11442 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
11443 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11444 "suggest parentheses around arithmetic in operand of %<|%>");
11445 /* Check cases like x|y==z */
11446 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11447 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11448 "suggest parentheses around comparison in operand of %<|%>");
11449 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11450 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11451 "suggest parentheses around comparison in operand of %<|%>");
11452 /* Check cases like !x | y */
11453 else if (code_left
== TRUTH_NOT_EXPR
11454 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
11455 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11456 "suggest parentheses around operand of "
11457 "%<!%> or change %<|%> to %<||%> or %<!%> to %<~%>");
11461 if (code_left
== BIT_AND_EXPR
11462 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
)
11463 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11464 "suggest parentheses around arithmetic in operand of %<^%>");
11465 else if (code_right
== BIT_AND_EXPR
11466 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
11467 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11468 "suggest parentheses around arithmetic in operand of %<^%>");
11469 /* Check cases like x^y==z */
11470 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11471 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11472 "suggest parentheses around comparison in operand of %<^%>");
11473 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11474 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11475 "suggest parentheses around comparison in operand of %<^%>");
11479 if (code_left
== PLUS_EXPR
)
11480 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11481 "suggest parentheses around %<+%> in operand of %<&%>");
11482 else if (code_right
== PLUS_EXPR
)
11483 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11484 "suggest parentheses around %<+%> in operand of %<&%>");
11485 else if (code_left
== MINUS_EXPR
)
11486 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11487 "suggest parentheses around %<-%> in operand of %<&%>");
11488 else if (code_right
== MINUS_EXPR
)
11489 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11490 "suggest parentheses around %<-%> in operand of %<&%>");
11491 /* Check cases like x&y==z */
11492 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11493 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11494 "suggest parentheses around comparison in operand of %<&%>");
11495 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11496 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11497 "suggest parentheses around comparison in operand of %<&%>");
11498 /* Check cases like !x & y */
11499 else if (code_left
== TRUTH_NOT_EXPR
11500 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
11501 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11502 "suggest parentheses around operand of "
11503 "%<!%> or change %<&%> to %<&&%> or %<!%> to %<~%>");
11507 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11508 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11509 "suggest parentheses around comparison in operand of %<==%>");
11510 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11511 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11512 "suggest parentheses around comparison in operand of %<==%>");
11515 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11516 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11517 "suggest parentheses around comparison in operand of %<!=%>");
11518 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11519 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11520 "suggest parentheses around comparison in operand of %<!=%>");
11524 if (TREE_CODE_CLASS (code
) == tcc_comparison
)
11526 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
11527 && code_left
!= NE_EXPR
&& code_left
!= EQ_EXPR
11528 && INTEGRAL_TYPE_P (TREE_TYPE (arg_left
)))
11529 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11530 "comparisons like %<X<=Y<=Z%> do not "
11531 "have their mathematical meaning");
11532 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
11533 && code_right
!= NE_EXPR
&& code_right
!= EQ_EXPR
11534 && INTEGRAL_TYPE_P (TREE_TYPE (arg_right
)))
11535 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11536 "comparisons like %<X<=Y<=Z%> do not "
11537 "have their mathematical meaning");
11541 #undef NOT_A_BOOLEAN_EXPR_P
11544 /* If LABEL (a LABEL_DECL) has not been used, issue a warning. */
11547 warn_for_unused_label (tree label
)
11549 if (!TREE_USED (label
))
11551 if (DECL_INITIAL (label
))
11552 warning (OPT_Wunused_label
, "label %q+D defined but not used", label
);
11554 warning (OPT_Wunused_label
, "label %q+D declared but not defined", label
);
11558 /* Warn for division by zero according to the value of DIVISOR. LOC
11559 is the location of the division operator. */
11562 warn_for_div_by_zero (location_t loc
, tree divisor
)
11564 /* If DIVISOR is zero, and has integral or fixed-point type, issue a warning
11565 about division by zero. Do not issue a warning if DIVISOR has a
11566 floating-point type, since we consider 0.0/0.0 a valid way of
11567 generating a NaN. */
11568 if (c_inhibit_evaluation_warnings
== 0
11569 && (integer_zerop (divisor
) || fixed_zerop (divisor
)))
11570 warning_at (loc
, OPT_Wdiv_by_zero
, "division by zero");
11573 /* Subroutine of build_binary_op. Give warnings for comparisons
11574 between signed and unsigned quantities that may fail. Do the
11575 checking based on the original operand trees ORIG_OP0 and ORIG_OP1,
11576 so that casts will be considered, but default promotions won't
11579 LOCATION is the location of the comparison operator.
11581 The arguments of this function map directly to local variables
11582 of build_binary_op. */
11585 warn_for_sign_compare (location_t location
,
11586 tree orig_op0
, tree orig_op1
,
11587 tree op0
, tree op1
,
11588 tree result_type
, enum tree_code resultcode
)
11590 int op0_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op0
));
11591 int op1_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op1
));
11592 int unsignedp0
, unsignedp1
;
11594 /* In C++, check for comparison of different enum types. */
11595 if (c_dialect_cxx()
11596 && TREE_CODE (TREE_TYPE (orig_op0
)) == ENUMERAL_TYPE
11597 && TREE_CODE (TREE_TYPE (orig_op1
)) == ENUMERAL_TYPE
11598 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0
))
11599 != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1
)))
11601 warning_at (location
,
11602 OPT_Wsign_compare
, "comparison between types %qT and %qT",
11603 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
));
11606 /* Do not warn if the comparison is being done in a signed type,
11607 since the signed type will only be chosen if it can represent
11608 all the values of the unsigned type. */
11609 if (!TYPE_UNSIGNED (result_type
))
11611 /* Do not warn if both operands are unsigned. */
11612 else if (op0_signed
== op1_signed
)
11616 tree sop
, uop
, base_type
;
11620 sop
= orig_op0
, uop
= orig_op1
;
11622 sop
= orig_op1
, uop
= orig_op0
;
11624 STRIP_TYPE_NOPS (sop
);
11625 STRIP_TYPE_NOPS (uop
);
11626 base_type
= (TREE_CODE (result_type
) == COMPLEX_TYPE
11627 ? TREE_TYPE (result_type
) : result_type
);
11629 /* Do not warn if the signed quantity is an unsuffixed integer
11630 literal (or some static constant expression involving such
11631 literals or a conditional expression involving such literals)
11632 and it is non-negative. */
11633 if (tree_expr_nonnegative_warnv_p (sop
, &ovf
))
11635 /* Do not warn if the comparison is an equality operation, the
11636 unsigned quantity is an integral constant, and it would fit
11637 in the result if the result were signed. */
11638 else if (TREE_CODE (uop
) == INTEGER_CST
11639 && (resultcode
== EQ_EXPR
|| resultcode
== NE_EXPR
)
11640 && int_fits_type_p (uop
, c_common_signed_type (base_type
)))
11642 /* In C, do not warn if the unsigned quantity is an enumeration
11643 constant and its maximum value would fit in the result if the
11644 result were signed. */
11645 else if (!c_dialect_cxx() && TREE_CODE (uop
) == INTEGER_CST
11646 && TREE_CODE (TREE_TYPE (uop
)) == ENUMERAL_TYPE
11647 && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (uop
)),
11648 c_common_signed_type (base_type
)))
11651 warning_at (location
,
11653 "comparison between signed and unsigned integer expressions");
11656 /* Warn if two unsigned values are being compared in a size larger
11657 than their original size, and one (and only one) is the result of
11658 a `~' operator. This comparison will always fail.
11660 Also warn if one operand is a constant, and the constant does not
11661 have all bits set that are set in the ~ operand when it is
11664 op0
= c_common_get_narrower (op0
, &unsignedp0
);
11665 op1
= c_common_get_narrower (op1
, &unsignedp1
);
11667 if ((TREE_CODE (op0
) == BIT_NOT_EXPR
)
11668 ^ (TREE_CODE (op1
) == BIT_NOT_EXPR
))
11670 if (TREE_CODE (op0
) == BIT_NOT_EXPR
)
11671 op0
= c_common_get_narrower (TREE_OPERAND (op0
, 0), &unsignedp0
);
11672 if (TREE_CODE (op1
) == BIT_NOT_EXPR
)
11673 op1
= c_common_get_narrower (TREE_OPERAND (op1
, 0), &unsignedp1
);
11675 if (tree_fits_shwi_p (op0
) || tree_fits_shwi_p (op1
))
11678 HOST_WIDE_INT constant
, mask
;
11682 if (tree_fits_shwi_p (op0
))
11685 unsignedp
= unsignedp1
;
11686 constant
= tree_to_shwi (op0
);
11691 unsignedp
= unsignedp0
;
11692 constant
= tree_to_shwi (op1
);
11695 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
11696 if (bits
< TYPE_PRECISION (result_type
)
11697 && bits
< HOST_BITS_PER_LONG
&& unsignedp
)
11699 mask
= (~ (HOST_WIDE_INT
) 0) << bits
;
11700 if ((mask
& constant
) != mask
)
11703 warning_at (location
, OPT_Wsign_compare
,
11704 "promoted ~unsigned is always non-zero");
11706 warning_at (location
, OPT_Wsign_compare
,
11707 "comparison of promoted ~unsigned with constant");
11711 else if (unsignedp0
&& unsignedp1
11712 && (TYPE_PRECISION (TREE_TYPE (op0
))
11713 < TYPE_PRECISION (result_type
))
11714 && (TYPE_PRECISION (TREE_TYPE (op1
))
11715 < TYPE_PRECISION (result_type
)))
11716 warning_at (location
, OPT_Wsign_compare
,
11717 "comparison of promoted ~unsigned with unsigned");
11721 /* RESULT_TYPE is the result of converting TYPE1 and TYPE2 to a common
11722 type via c_common_type. If -Wdouble-promotion is in use, and the
11723 conditions for warning have been met, issue a warning. GMSGID is
11724 the warning message. It must have two %T specifiers for the type
11725 that was converted (generally "float") and the type to which it was
11726 converted (generally "double), respectively. LOC is the location
11727 to which the awrning should refer. */
11730 do_warn_double_promotion (tree result_type
, tree type1
, tree type2
,
11731 const char *gmsgid
, location_t loc
)
11735 if (!warn_double_promotion
)
11737 /* If the conversion will not occur at run-time, there is no need to
11739 if (c_inhibit_evaluation_warnings
)
11741 if (TYPE_MAIN_VARIANT (result_type
) != double_type_node
11742 && TYPE_MAIN_VARIANT (result_type
) != complex_double_type_node
)
11744 if (TYPE_MAIN_VARIANT (type1
) == float_type_node
11745 || TYPE_MAIN_VARIANT (type1
) == complex_float_type_node
)
11746 source_type
= type1
;
11747 else if (TYPE_MAIN_VARIANT (type2
) == float_type_node
11748 || TYPE_MAIN_VARIANT (type2
) == complex_float_type_node
)
11749 source_type
= type2
;
11752 warning_at (loc
, OPT_Wdouble_promotion
, gmsgid
, source_type
, result_type
);
11755 /* Setup a TYPE_DECL node as a typedef representation.
11757 X is a TYPE_DECL for a typedef statement. Create a brand new
11758 ..._TYPE node (which will be just a variant of the existing
11759 ..._TYPE node with identical properties) and then install X
11760 as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
11762 The whole point here is to end up with a situation where each
11763 and every ..._TYPE node the compiler creates will be uniquely
11764 associated with AT MOST one node representing a typedef name.
11765 This way, even though the compiler substitutes corresponding
11766 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
11767 early on, later parts of the compiler can always do the reverse
11768 translation and get back the corresponding typedef name. For
11771 typedef struct S MY_TYPE;
11774 Later parts of the compiler might only know that `object' was of
11775 type `struct S' if it were not for code just below. With this
11776 code however, later parts of the compiler see something like:
11778 struct S' == struct S
11779 typedef struct S' MY_TYPE;
11782 And they can then deduce (from the node for type struct S') that
11783 the original object declaration was:
11787 Being able to do this is important for proper support of protoize,
11788 and also for generating precise symbolic debugging information
11789 which takes full account of the programmer's (typedef) vocabulary.
11791 Obviously, we don't want to generate a duplicate ..._TYPE node if
11792 the TYPE_DECL node that we are now processing really represents a
11793 standard built-in type. */
11796 set_underlying_type (tree x
)
11798 if (x
== error_mark_node
)
11800 if (DECL_IS_BUILTIN (x
))
11802 if (TYPE_NAME (TREE_TYPE (x
)) == 0)
11803 TYPE_NAME (TREE_TYPE (x
)) = x
;
11805 else if (TREE_TYPE (x
) != error_mark_node
11806 && DECL_ORIGINAL_TYPE (x
) == NULL_TREE
)
11808 tree tt
= TREE_TYPE (x
);
11809 DECL_ORIGINAL_TYPE (x
) = tt
;
11810 tt
= build_variant_type_copy (tt
);
11811 TYPE_STUB_DECL (tt
) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x
));
11812 TYPE_NAME (tt
) = x
;
11813 TREE_USED (tt
) = TREE_USED (x
);
11814 TREE_TYPE (x
) = tt
;
11818 /* Record the types used by the current global variable declaration
11819 being parsed, so that we can decide later to emit their debug info.
11820 Those types are in types_used_by_cur_var_decl, and we are going to
11821 store them in the types_used_by_vars_hash hash table.
11822 DECL is the declaration of the global variable that has been parsed. */
11825 record_types_used_by_current_var_decl (tree decl
)
11827 gcc_assert (decl
&& DECL_P (decl
) && TREE_STATIC (decl
));
11829 while (types_used_by_cur_var_decl
&& !types_used_by_cur_var_decl
->is_empty ())
11831 tree type
= types_used_by_cur_var_decl
->pop ();
11832 types_used_by_var_decl_insert (type
, decl
);
11836 /* If DECL is a typedef that is declared in the current function,
11837 record it for the purpose of -Wunused-local-typedefs. */
11840 record_locally_defined_typedef (tree decl
)
11842 struct c_language_function
*l
;
11844 if (!warn_unused_local_typedefs
11846 /* if this is not a locally defined typedef then we are not
11848 || !is_typedef_decl (decl
)
11849 || !decl_function_context (decl
))
11852 l
= (struct c_language_function
*) cfun
->language
;
11853 vec_safe_push (l
->local_typedefs
, decl
);
11856 /* If T is a TYPE_DECL declared locally, mark it as used. */
11859 maybe_record_typedef_use (tree t
)
11861 if (!is_typedef_decl (t
))
11864 TREE_USED (t
) = true;
11867 /* Warn if there are some unused locally defined typedefs in the
11868 current function. */
11871 maybe_warn_unused_local_typedefs (void)
11875 /* The number of times we have emitted -Wunused-local-typedefs
11876 warnings. If this is different from errorcount, that means some
11877 unrelated errors have been issued. In which case, we'll avoid
11878 emitting "unused-local-typedefs" warnings. */
11879 static int unused_local_typedefs_warn_count
;
11880 struct c_language_function
*l
;
11885 if ((l
= (struct c_language_function
*) cfun
->language
) == NULL
)
11888 if (warn_unused_local_typedefs
11889 && errorcount
== unused_local_typedefs_warn_count
)
11891 FOR_EACH_VEC_SAFE_ELT (l
->local_typedefs
, i
, decl
)
11892 if (!TREE_USED (decl
))
11893 warning_at (DECL_SOURCE_LOCATION (decl
),
11894 OPT_Wunused_local_typedefs
,
11895 "typedef %qD locally defined but not used", decl
);
11896 unused_local_typedefs_warn_count
= errorcount
;
11899 vec_free (l
->local_typedefs
);
11902 /* Warn about boolean expression compared with an integer value different
11903 from true/false. Warns also e.g. about "(i1 == i2) == 2".
11904 LOC is the location of the comparison, CODE is its code, OP0 and OP1
11905 are the operands of the comparison. The caller must ensure that
11906 either operand is a boolean expression. */
11909 maybe_warn_bool_compare (location_t loc
, enum tree_code code
, tree op0
,
11912 if (TREE_CODE_CLASS (code
) != tcc_comparison
)
11915 tree cst
= (TREE_CODE (op0
) == INTEGER_CST
)
11916 ? op0
: (TREE_CODE (op1
) == INTEGER_CST
) ? op1
: NULL_TREE
;
11920 if (!integer_zerop (cst
) && !integer_onep (cst
))
11922 int sign
= (TREE_CODE (op0
) == INTEGER_CST
11923 ? tree_int_cst_sgn (cst
) : -tree_int_cst_sgn (cst
));
11924 if (code
== EQ_EXPR
11925 || ((code
== GT_EXPR
|| code
== GE_EXPR
) && sign
< 0)
11926 || ((code
== LT_EXPR
|| code
== LE_EXPR
) && sign
> 0))
11927 warning_at (loc
, OPT_Wbool_compare
, "comparison of constant %qE "
11928 "with boolean expression is always false", cst
);
11930 warning_at (loc
, OPT_Wbool_compare
, "comparison of constant %qE "
11931 "with boolean expression is always true", cst
);
11933 else if (integer_zerop (cst
) || integer_onep (cst
))
11935 /* If the non-constant operand isn't of a boolean type, we
11936 don't want to warn here. */
11937 tree noncst
= TREE_CODE (op0
) == INTEGER_CST
? op1
: op0
;
11938 /* Handle booleans promoted to integers. */
11939 if (CONVERT_EXPR_P (noncst
)
11940 && TREE_TYPE (noncst
) == integer_type_node
11941 && TREE_CODE (TREE_TYPE (TREE_OPERAND (noncst
, 0))) == BOOLEAN_TYPE
)
11943 else if (TREE_CODE (TREE_TYPE (noncst
)) != BOOLEAN_TYPE
11944 && !truth_value_p (TREE_CODE (noncst
)))
11946 /* Do some magic to get the right diagnostics. */
11947 bool flag
= TREE_CODE (op0
) == INTEGER_CST
;
11948 flag
= integer_zerop (cst
) ? flag
: !flag
;
11949 if ((code
== GE_EXPR
&& !flag
) || (code
== LE_EXPR
&& flag
))
11950 warning_at (loc
, OPT_Wbool_compare
, "comparison of constant %qE "
11951 "with boolean expression is always true", cst
);
11952 else if ((code
== LT_EXPR
&& !flag
) || (code
== GT_EXPR
&& flag
))
11953 warning_at (loc
, OPT_Wbool_compare
, "comparison of constant %qE "
11954 "with boolean expression is always false", cst
);
11958 /* The C and C++ parsers both use vectors to hold function arguments.
11959 For efficiency, we keep a cache of unused vectors. This is the
11962 typedef vec
<tree
, va_gc
> *tree_gc_vec
;
11963 static GTY((deletable
)) vec
<tree_gc_vec
, va_gc
> *tree_vector_cache
;
11965 /* Return a new vector from the cache. If the cache is empty,
11966 allocate a new vector. These vectors are GC'ed, so it is OK if the
11967 pointer is not released.. */
11970 make_tree_vector (void)
11972 if (tree_vector_cache
&& !tree_vector_cache
->is_empty ())
11973 return tree_vector_cache
->pop ();
11976 /* Passing 0 to vec::alloc returns NULL, and our callers require
11977 that we always return a non-NULL value. The vector code uses
11978 4 when growing a NULL vector, so we do too. */
11979 vec
<tree
, va_gc
> *v
;
11985 /* Release a vector of trees back to the cache. */
11988 release_tree_vector (vec
<tree
, va_gc
> *vec
)
11993 vec_safe_push (tree_vector_cache
, vec
);
11997 /* Get a new tree vector holding a single tree. */
12000 make_tree_vector_single (tree t
)
12002 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
12003 ret
->quick_push (t
);
12007 /* Get a new tree vector of the TREE_VALUEs of a TREE_LIST chain. */
12010 make_tree_vector_from_list (tree list
)
12012 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
12013 for (; list
; list
= TREE_CHAIN (list
))
12014 vec_safe_push (ret
, TREE_VALUE (list
));
12018 /* Get a new tree vector which is a copy of an existing one. */
12021 make_tree_vector_copy (const vec
<tree
, va_gc
> *orig
)
12023 vec
<tree
, va_gc
> *ret
;
12027 ret
= make_tree_vector ();
12028 vec_safe_reserve (ret
, vec_safe_length (orig
));
12029 FOR_EACH_VEC_SAFE_ELT (orig
, ix
, t
)
12030 ret
->quick_push (t
);
12034 /* Return true if KEYWORD starts a type specifier. */
12037 keyword_begins_type_specifier (enum rid keyword
)
12041 case RID_AUTO_TYPE
:
12053 case RID_DFLOAT128
:
12069 if (keyword
>= RID_FIRST_INT_N
12070 && keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
12071 && int_n_enabled_p
[keyword
-RID_FIRST_INT_N
])
12077 /* Return true if KEYWORD names a type qualifier. */
12080 keyword_is_type_qualifier (enum rid keyword
)
12094 /* Return true if KEYWORD names a storage class specifier.
12096 RID_TYPEDEF is not included in this list despite `typedef' being
12097 listed in C99 6.7.1.1. 6.7.1.3 indicates that `typedef' is listed as
12098 such for syntactic convenience only. */
12101 keyword_is_storage_class_specifier (enum rid keyword
)
12117 /* Return true if KEYWORD names a function-specifier [dcl.fct.spec]. */
12120 keyword_is_function_specifier (enum rid keyword
)
12134 /* Return true if KEYWORD names a decl-specifier [dcl.spec] or a
12135 declaration-specifier (C99 6.7). */
12138 keyword_is_decl_specifier (enum rid keyword
)
12140 if (keyword_is_storage_class_specifier (keyword
)
12141 || keyword_is_type_qualifier (keyword
)
12142 || keyword_is_function_specifier (keyword
))
12149 case RID_CONSTEXPR
:
12156 /* Initialize language-specific-bits of tree_contains_struct. */
12159 c_common_init_ts (void)
12161 MARK_TS_TYPED (C_MAYBE_CONST_EXPR
);
12162 MARK_TS_TYPED (EXCESS_PRECISION_EXPR
);
12163 MARK_TS_TYPED (ARRAY_NOTATION_REF
);
12166 /* Build a user-defined numeric literal out of an integer constant type VALUE
12167 with identifier SUFFIX. */
12170 build_userdef_literal (tree suffix_id
, tree value
,
12171 enum overflow_type overflow
, tree num_string
)
12173 tree literal
= make_node (USERDEF_LITERAL
);
12174 USERDEF_LITERAL_SUFFIX_ID (literal
) = suffix_id
;
12175 USERDEF_LITERAL_VALUE (literal
) = value
;
12176 USERDEF_LITERAL_OVERFLOW (literal
) = overflow
;
12177 USERDEF_LITERAL_NUM_STRING (literal
) = num_string
;
12181 /* For vector[index], convert the vector to a
12182 pointer of the underlying type. Return true if the resulting
12183 ARRAY_REF should not be an lvalue. */
12186 convert_vector_to_pointer_for_subscript (location_t loc
,
12187 tree
*vecp
, tree index
)
12190 if (TREE_CODE (TREE_TYPE (*vecp
)) == VECTOR_TYPE
)
12192 tree type
= TREE_TYPE (*vecp
);
12195 ret
= !lvalue_p (*vecp
);
12196 if (TREE_CODE (index
) == INTEGER_CST
)
12197 if (!tree_fits_uhwi_p (index
)
12198 || tree_to_uhwi (index
) >= TYPE_VECTOR_SUBPARTS (type
))
12199 warning_at (loc
, OPT_Warray_bounds
, "index value is out of bound");
12203 tree tmp
= create_tmp_var_raw (type
);
12204 DECL_SOURCE_LOCATION (tmp
) = loc
;
12205 *vecp
= c_save_expr (*vecp
);
12206 if (TREE_CODE (*vecp
) == C_MAYBE_CONST_EXPR
)
12208 bool non_const
= C_MAYBE_CONST_EXPR_NON_CONST (*vecp
);
12209 *vecp
= C_MAYBE_CONST_EXPR_EXPR (*vecp
);
12211 = c_wrap_maybe_const (build4 (TARGET_EXPR
, type
, tmp
,
12212 *vecp
, NULL_TREE
, NULL_TREE
),
12216 *vecp
= build4 (TARGET_EXPR
, type
, tmp
, *vecp
,
12217 NULL_TREE
, NULL_TREE
);
12218 SET_EXPR_LOCATION (*vecp
, loc
);
12219 c_common_mark_addressable_vec (tmp
);
12222 c_common_mark_addressable_vec (*vecp
);
12223 type
= build_qualified_type (TREE_TYPE (type
), TYPE_QUALS (type
));
12224 type1
= build_pointer_type (TREE_TYPE (*vecp
));
12225 bool ref_all
= TYPE_REF_CAN_ALIAS_ALL (type1
);
12227 && !DECL_P (*vecp
))
12229 /* If the original vector isn't declared may_alias and it
12230 isn't a bare vector look if the subscripting would
12231 alias the vector we subscript, and if not, force ref-all. */
12232 alias_set_type vecset
= get_alias_set (*vecp
);
12233 alias_set_type sset
= get_alias_set (type
);
12234 if (!alias_sets_must_conflict_p (sset
, vecset
)
12235 && !alias_set_subset_of (sset
, vecset
))
12238 type
= build_pointer_type_for_mode (type
, ptr_mode
, ref_all
);
12239 *vecp
= build1 (ADDR_EXPR
, type1
, *vecp
);
12240 *vecp
= convert (type
, *vecp
);
12245 /* Determine which of the operands, if any, is a scalar that needs to be
12246 converted to a vector, for the range of operations. */
12248 scalar_to_vector (location_t loc
, enum tree_code code
, tree op0
, tree op1
,
12251 tree type0
= TREE_TYPE (op0
);
12252 tree type1
= TREE_TYPE (op1
);
12253 bool integer_only_op
= false;
12254 enum stv_conv ret
= stv_firstarg
;
12256 gcc_assert (TREE_CODE (type0
) == VECTOR_TYPE
12257 || TREE_CODE (type1
) == VECTOR_TYPE
);
12260 /* Most GENERIC binary expressions require homogeneous arguments.
12261 LSHIFT_EXPR and RSHIFT_EXPR are exceptions and accept a first
12262 argument that is a vector and a second one that is a scalar, so
12263 we never return stv_secondarg for them. */
12266 if (TREE_CODE (type0
) == INTEGER_TYPE
12267 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
12269 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
12272 error_at (loc
, "conversion of scalar %qT to vector %qT "
12273 "involves truncation", type0
, type1
);
12277 return stv_firstarg
;
12284 integer_only_op
= true;
12285 /* ... fall through ... */
12287 case VEC_COND_EXPR
:
12292 case TRUNC_DIV_EXPR
:
12293 case CEIL_DIV_EXPR
:
12294 case FLOOR_DIV_EXPR
:
12295 case ROUND_DIV_EXPR
:
12296 case EXACT_DIV_EXPR
:
12297 case TRUNC_MOD_EXPR
:
12298 case FLOOR_MOD_EXPR
:
12306 /* What about UNLT_EXPR? */
12307 if (TREE_CODE (type0
) == VECTOR_TYPE
)
12310 ret
= stv_secondarg
;
12311 /* Swap TYPE0 with TYPE1 and OP0 with OP1 */
12312 tmp
= type0
; type0
= type1
; type1
= tmp
;
12313 tmp
= op0
; op0
= op1
; op1
= tmp
;
12316 if (TREE_CODE (type0
) == INTEGER_TYPE
12317 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
12319 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
12322 error_at (loc
, "conversion of scalar %qT to vector %qT "
12323 "involves truncation", type0
, type1
);
12328 else if (!integer_only_op
12329 /* Allow integer --> real conversion if safe. */
12330 && (TREE_CODE (type0
) == REAL_TYPE
12331 || TREE_CODE (type0
) == INTEGER_TYPE
)
12332 && SCALAR_FLOAT_TYPE_P (TREE_TYPE (type1
)))
12334 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
12337 error_at (loc
, "conversion of scalar %qT to vector %qT "
12338 "involves truncation", type0
, type1
);
12347 return stv_nothing
;
12350 /* Return true iff ALIGN is an integral constant that is a fundamental
12351 alignment, as defined by [basic.align] in the c++-11
12356 [A fundamental alignment is represented by an alignment less than or
12357 equal to the greatest alignment supported by the implementation
12358 in all contexts, which is equal to
12359 alignof(max_align_t)]. */
12362 cxx_fundamental_alignment_p (unsigned align
)
12364 return (align
<= MAX (TYPE_ALIGN (long_long_integer_type_node
),
12365 TYPE_ALIGN (long_double_type_node
)));
12368 /* Return true if T is a pointer to a zero-sized aggregate. */
12371 pointer_to_zero_sized_aggr_p (tree t
)
12373 if (!POINTER_TYPE_P (t
))
12376 return (TYPE_SIZE (t
) && integer_zerop (TYPE_SIZE (t
)));
12379 #include "gt-c-family-c-common.h"