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
|| code
== RSHIFT_EXPR
)
1365 && TREE_CODE (orig_op1
) != INTEGER_CST
1366 && TREE_CODE (op1
) == INTEGER_CST
1367 && (TREE_CODE (TREE_TYPE (orig_op0
)) == INTEGER_TYPE
1368 || TREE_CODE (TREE_TYPE (orig_op0
)) == FIXED_POINT_TYPE
)
1369 && TREE_CODE (TREE_TYPE (orig_op1
)) == INTEGER_TYPE
1370 && c_inhibit_evaluation_warnings
== 0)
1372 if (tree_int_cst_sgn (op1
) < 0)
1373 warning_at (loc
, 0, (code
== LSHIFT_EXPR
1374 ? G_("left shift count is negative")
1375 : G_("right shift count is negative")));
1376 else if (compare_tree_int (op1
,
1377 TYPE_PRECISION (TREE_TYPE (orig_op0
)))
1379 warning_at (loc
, 0, (code
== LSHIFT_EXPR
1380 ? G_("left shift count >= width of type")
1381 : G_("right shift count >= width of type")));
1383 if ((code
== TRUNC_DIV_EXPR
1384 || code
== CEIL_DIV_EXPR
1385 || code
== FLOOR_DIV_EXPR
1386 || code
== EXACT_DIV_EXPR
1387 || code
== TRUNC_MOD_EXPR
)
1388 && TREE_CODE (orig_op1
) != INTEGER_CST
1389 && TREE_CODE (op1
) == INTEGER_CST
1390 && (TREE_CODE (TREE_TYPE (orig_op0
)) == INTEGER_TYPE
1391 || TREE_CODE (TREE_TYPE (orig_op0
)) == FIXED_POINT_TYPE
)
1392 && TREE_CODE (TREE_TYPE (orig_op1
)) == INTEGER_TYPE
)
1393 warn_for_div_by_zero (loc
, op1
);
1397 case FIX_TRUNC_EXPR
:
1400 case ADDR_SPACE_CONVERT_EXPR
:
1401 case VIEW_CONVERT_EXPR
:
1402 case NON_LVALUE_EXPR
:
1405 case TRUTH_NOT_EXPR
:
1410 /* Unary operations. */
1411 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1412 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1413 maybe_const_itself
);
1414 STRIP_TYPE_NOPS (op0
);
1415 if (code
!= ADDR_EXPR
&& code
!= REALPART_EXPR
&& code
!= IMAGPART_EXPR
)
1416 op0
= decl_constant_value_for_optimization (op0
);
1417 /* ??? Cope with user tricks that amount to offsetof. The middle-end is
1418 not prepared to deal with them if they occur in initializers. */
1420 && code
== ADDR_EXPR
1421 && (op1
= get_base_address (op0
)) != NULL_TREE
1422 && TREE_CODE (op1
) == INDIRECT_REF
1423 && TREE_CONSTANT (TREE_OPERAND (op1
, 0)))
1424 ret
= fold_convert_loc (loc
, TREE_TYPE (expr
), fold_offsetof_1 (op0
));
1425 else if (op0
!= orig_op0
|| in_init
)
1427 ? fold_build1_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
)
1428 : fold_build1_loc (loc
, code
, TREE_TYPE (expr
), op0
);
1431 if (code
== INDIRECT_REF
1433 && TREE_CODE (ret
) == INDIRECT_REF
)
1435 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1436 TREE_SIDE_EFFECTS (ret
) = TREE_SIDE_EFFECTS (expr
);
1437 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1441 case FIX_TRUNC_EXPR
:
1444 /* Don't warn about explicit conversions. We will already
1445 have warned about suspect implicit conversions. */
1449 if (TREE_OVERFLOW_P (ret
) && !TREE_OVERFLOW_P (op0
))
1450 overflow_warning (EXPR_LOCATION (expr
), ret
);
1455 case TRUTH_ANDIF_EXPR
:
1456 case TRUTH_ORIF_EXPR
:
1457 /* Binary operations not necessarily evaluating both
1459 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1460 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1461 op0
= c_fully_fold_internal (op0
, in_init
, &op0_const
, &op0_const_self
);
1462 STRIP_TYPE_NOPS (op0
);
1464 unused_p
= (op0
== (code
== TRUTH_ANDIF_EXPR
1465 ? truthvalue_false_node
1466 : truthvalue_true_node
));
1467 c_disable_warnings (unused_p
);
1468 op1
= c_fully_fold_internal (op1
, in_init
, &op1_const
, &op1_const_self
);
1469 STRIP_TYPE_NOPS (op1
);
1470 c_enable_warnings (unused_p
);
1472 if (op0
!= orig_op0
|| op1
!= orig_op1
|| in_init
)
1474 ? fold_build2_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
)
1475 : fold_build2_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
);
1478 *maybe_const_operands
&= op0_const
;
1479 *maybe_const_itself
&= op0_const_self
;
1483 && (code
== TRUTH_ANDIF_EXPR
1484 ? op0
== truthvalue_false_node
1485 : op0
== truthvalue_true_node
)))
1486 *maybe_const_operands
&= op1_const
;
1489 && (code
== TRUTH_ANDIF_EXPR
1490 ? op0
== truthvalue_false_node
1491 : op0
== truthvalue_true_node
)))
1492 *maybe_const_itself
&= op1_const_self
;
1496 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1497 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1498 orig_op2
= op2
= TREE_OPERAND (expr
, 2);
1499 op0
= c_fully_fold_internal (op0
, in_init
, &op0_const
, &op0_const_self
);
1501 STRIP_TYPE_NOPS (op0
);
1502 c_disable_warnings (op0
== truthvalue_false_node
);
1503 op1
= c_fully_fold_internal (op1
, in_init
, &op1_const
, &op1_const_self
);
1504 STRIP_TYPE_NOPS (op1
);
1505 c_enable_warnings (op0
== truthvalue_false_node
);
1507 c_disable_warnings (op0
== truthvalue_true_node
);
1508 op2
= c_fully_fold_internal (op2
, in_init
, &op2_const
, &op2_const_self
);
1509 STRIP_TYPE_NOPS (op2
);
1510 c_enable_warnings (op0
== truthvalue_true_node
);
1512 if (op0
!= orig_op0
|| op1
!= orig_op1
|| op2
!= orig_op2
)
1513 ret
= fold_build3_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
, op2
);
1516 *maybe_const_operands
&= op0_const
;
1517 *maybe_const_itself
&= op0_const_self
;
1521 && op0
== truthvalue_false_node
))
1522 *maybe_const_operands
&= op1_const
;
1525 && op0
== truthvalue_false_node
))
1526 *maybe_const_itself
&= op1_const_self
;
1530 && op0
== truthvalue_true_node
))
1531 *maybe_const_operands
&= op2_const
;
1534 && op0
== truthvalue_true_node
))
1535 *maybe_const_itself
&= op2_const_self
;
1538 case EXCESS_PRECISION_EXPR
:
1539 /* Each case where an operand with excess precision may be
1540 encountered must remove the EXCESS_PRECISION_EXPR around
1541 inner operands and possibly put one around the whole
1542 expression or possibly convert to the semantic type (which
1543 c_fully_fold does); we cannot tell at this stage which is
1544 appropriate in any particular case. */
1548 /* Various codes may appear through folding built-in functions
1549 and their arguments. */
1554 /* Some folding may introduce NON_LVALUE_EXPRs; all lvalue checks
1555 have been done by this point, so remove them again. */
1556 nowarning
|= TREE_NO_WARNING (ret
);
1557 STRIP_TYPE_NOPS (ret
);
1558 if (nowarning
&& !TREE_NO_WARNING (ret
))
1560 if (!CAN_HAVE_LOCATION_P (ret
))
1561 ret
= build1 (NOP_EXPR
, TREE_TYPE (ret
), ret
);
1562 TREE_NO_WARNING (ret
) = 1;
1565 protected_set_expr_location (ret
, loc
);
1569 /* If not optimizing, EXP is not a VAR_DECL, or EXP has array type,
1570 return EXP. Otherwise, return either EXP or its known constant
1571 value (if it has one), but return EXP if EXP has mode BLKmode. ???
1572 Is the BLKmode test appropriate? */
1575 decl_constant_value_for_optimization (tree exp
)
1579 /* This function is only used by C, for c_fully_fold and other
1580 optimization, and may not be correct for C++. */
1581 if (c_dialect_cxx ())
1585 || TREE_CODE (exp
) != VAR_DECL
1586 || TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
1587 || DECL_MODE (exp
) == BLKmode
)
1590 ret
= decl_constant_value (exp
);
1591 /* Avoid unwanted tree sharing between the initializer and current
1592 function's body where the tree can be modified e.g. by the
1594 if (ret
!= exp
&& TREE_STATIC (exp
))
1595 ret
= unshare_expr (ret
);
1599 /* Print a warning if a constant expression had overflow in folding.
1600 Invoke this function on every expression that the language
1601 requires to be a constant expression.
1602 Note the ANSI C standard says it is erroneous for a
1603 constant expression to overflow. */
1606 constant_expression_warning (tree value
)
1608 if (warn_overflow
&& pedantic
1609 && (TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1610 || TREE_CODE (value
) == FIXED_CST
1611 || TREE_CODE (value
) == VECTOR_CST
1612 || TREE_CODE (value
) == COMPLEX_CST
)
1613 && TREE_OVERFLOW (value
))
1614 pedwarn (input_location
, OPT_Woverflow
, "overflow in constant expression");
1617 /* The same as above but print an unconditional error. */
1619 constant_expression_error (tree value
)
1621 if ((TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1622 || TREE_CODE (value
) == FIXED_CST
1623 || TREE_CODE (value
) == VECTOR_CST
1624 || TREE_CODE (value
) == COMPLEX_CST
)
1625 && TREE_OVERFLOW (value
))
1626 error ("overflow in constant expression");
1629 /* Print a warning if an expression had overflow in folding and its
1632 Invoke this function on every expression that
1633 (1) appears in the source code, and
1634 (2) is a constant expression that overflowed, and
1635 (3) is not already checked by convert_and_check;
1636 however, do not invoke this function on operands of explicit casts
1637 or when the expression is the result of an operator and any operand
1638 already overflowed. */
1641 overflow_warning (location_t loc
, tree value
)
1643 if (c_inhibit_evaluation_warnings
!= 0)
1646 switch (TREE_CODE (value
))
1649 warning_at (loc
, OPT_Woverflow
, "integer overflow in expression");
1653 warning_at (loc
, OPT_Woverflow
,
1654 "floating point overflow in expression");
1658 warning_at (loc
, OPT_Woverflow
, "fixed-point overflow in expression");
1662 warning_at (loc
, OPT_Woverflow
, "vector overflow in expression");
1666 if (TREE_CODE (TREE_REALPART (value
)) == INTEGER_CST
)
1667 warning_at (loc
, OPT_Woverflow
,
1668 "complex integer overflow in expression");
1669 else if (TREE_CODE (TREE_REALPART (value
)) == REAL_CST
)
1670 warning_at (loc
, OPT_Woverflow
,
1671 "complex floating point overflow in expression");
1679 /* Warn about uses of logical || / && operator in a context where it
1680 is likely that the bitwise equivalent was intended by the
1681 programmer. We have seen an expression in which CODE is a binary
1682 operator used to combine expressions OP_LEFT and OP_RIGHT, which before folding
1683 had CODE_LEFT and CODE_RIGHT, into an expression of type TYPE. */
1685 warn_logical_operator (location_t location
, enum tree_code code
, tree type
,
1686 enum tree_code code_left
, tree op_left
,
1687 enum tree_code
ARG_UNUSED (code_right
), tree op_right
)
1689 int or_op
= (code
== TRUTH_ORIF_EXPR
|| code
== TRUTH_OR_EXPR
);
1690 int in0_p
, in1_p
, in_p
;
1691 tree low0
, low1
, low
, high0
, high1
, high
, lhs
, rhs
, tem
;
1692 bool strict_overflow_p
= false;
1694 if (code
!= TRUTH_ANDIF_EXPR
1695 && code
!= TRUTH_AND_EXPR
1696 && code
!= TRUTH_ORIF_EXPR
1697 && code
!= TRUTH_OR_EXPR
)
1700 /* We don't want to warn if either operand comes from a macro
1701 expansion. ??? This doesn't work with e.g. NEGATE_EXPR yet;
1703 if (from_macro_expansion_at (EXPR_LOCATION (op_left
))
1704 || from_macro_expansion_at (EXPR_LOCATION (op_right
)))
1707 /* Warn if &&/|| are being used in a context where it is
1708 likely that the bitwise equivalent was intended by the
1709 programmer. That is, an expression such as op && MASK
1710 where op should not be any boolean expression, nor a
1711 constant, and mask seems to be a non-boolean integer constant. */
1712 if (!truth_value_p (code_left
)
1713 && INTEGRAL_TYPE_P (TREE_TYPE (op_left
))
1714 && !CONSTANT_CLASS_P (op_left
)
1715 && !TREE_NO_WARNING (op_left
)
1716 && TREE_CODE (op_right
) == INTEGER_CST
1717 && !integer_zerop (op_right
)
1718 && !integer_onep (op_right
))
1721 warning_at (location
, OPT_Wlogical_op
, "logical %<or%>"
1722 " applied to non-boolean constant");
1724 warning_at (location
, OPT_Wlogical_op
, "logical %<and%>"
1725 " applied to non-boolean constant");
1726 TREE_NO_WARNING (op_left
) = true;
1730 /* We do not warn for constants because they are typical of macro
1731 expansions that test for features. */
1732 if (CONSTANT_CLASS_P (op_left
) || CONSTANT_CLASS_P (op_right
))
1735 /* This warning only makes sense with logical operands. */
1736 if (!(truth_value_p (TREE_CODE (op_left
))
1737 || INTEGRAL_TYPE_P (TREE_TYPE (op_left
)))
1738 || !(truth_value_p (TREE_CODE (op_right
))
1739 || INTEGRAL_TYPE_P (TREE_TYPE (op_right
))))
1742 /* The range computations only work with scalars. */
1743 if (VECTOR_TYPE_P (TREE_TYPE (op_left
))
1744 || VECTOR_TYPE_P (TREE_TYPE (op_right
)))
1747 /* We first test whether either side separately is trivially true
1748 (with OR) or trivially false (with AND). If so, do not warn.
1749 This is a common idiom for testing ranges of data types in
1751 lhs
= make_range (op_left
, &in0_p
, &low0
, &high0
, &strict_overflow_p
);
1754 if (TREE_CODE (lhs
) == C_MAYBE_CONST_EXPR
)
1755 lhs
= C_MAYBE_CONST_EXPR_EXPR (lhs
);
1757 /* If this is an OR operation, invert both sides; now, the result
1758 should be always false to get a warning. */
1762 tem
= build_range_check (UNKNOWN_LOCATION
, type
, lhs
, in0_p
, low0
, high0
);
1763 if (tem
&& integer_zerop (tem
))
1766 rhs
= make_range (op_right
, &in1_p
, &low1
, &high1
, &strict_overflow_p
);
1769 if (TREE_CODE (rhs
) == C_MAYBE_CONST_EXPR
)
1770 rhs
= C_MAYBE_CONST_EXPR_EXPR (rhs
);
1772 /* If this is an OR operation, invert both sides; now, the result
1773 should be always false to get a warning. */
1777 tem
= build_range_check (UNKNOWN_LOCATION
, type
, rhs
, in1_p
, low1
, high1
);
1778 if (tem
&& integer_zerop (tem
))
1781 /* If both expressions have the same operand, if we can merge the
1782 ranges, and if the range test is always false, then warn. */
1783 if (operand_equal_p (lhs
, rhs
, 0)
1784 && merge_ranges (&in_p
, &low
, &high
, in0_p
, low0
, high0
,
1786 && 0 != (tem
= build_range_check (UNKNOWN_LOCATION
,
1787 type
, lhs
, in_p
, low
, high
))
1788 && integer_zerop (tem
))
1791 warning_at (location
, OPT_Wlogical_op
,
1793 "of collectively exhaustive tests is always true");
1795 warning_at (location
, OPT_Wlogical_op
,
1797 "of mutually exclusive tests is always false");
1801 /* Warn about logical not used on the left hand side operand of a comparison.
1802 This function assumes that the LHS is inside of TRUTH_NOT_EXPR.
1803 Do not warn if RHS is of a boolean type. */
1806 warn_logical_not_parentheses (location_t location
, enum tree_code code
,
1809 if (TREE_CODE_CLASS (code
) != tcc_comparison
1810 || TREE_TYPE (rhs
) == NULL_TREE
1811 || TREE_CODE (TREE_TYPE (rhs
)) == BOOLEAN_TYPE
)
1814 /* Don't warn for !x == 0 or !y != 0, those are equivalent to
1815 !(x == 0) or !(y != 0). */
1816 if ((code
== EQ_EXPR
|| code
== NE_EXPR
)
1817 && integer_zerop (rhs
))
1820 warning_at (location
, OPT_Wlogical_not_parentheses
,
1821 "logical not is only applied to the left hand side of "
1825 /* Warn if EXP contains any computations whose results are not used.
1826 Return true if a warning is printed; false otherwise. LOCUS is the
1827 (potential) location of the expression. */
1830 warn_if_unused_value (const_tree exp
, location_t locus
)
1833 if (TREE_USED (exp
) || TREE_NO_WARNING (exp
))
1836 /* Don't warn about void constructs. This includes casting to void,
1837 void function calls, and statement expressions with a final cast
1839 if (VOID_TYPE_P (TREE_TYPE (exp
)))
1842 if (EXPR_HAS_LOCATION (exp
))
1843 locus
= EXPR_LOCATION (exp
);
1845 switch (TREE_CODE (exp
))
1847 case PREINCREMENT_EXPR
:
1848 case POSTINCREMENT_EXPR
:
1849 case PREDECREMENT_EXPR
:
1850 case POSTDECREMENT_EXPR
:
1855 case TRY_CATCH_EXPR
:
1856 case WITH_CLEANUP_EXPR
:
1862 /* For a binding, warn if no side effect within it. */
1863 exp
= BIND_EXPR_BODY (exp
);
1867 case NON_LVALUE_EXPR
:
1869 exp
= TREE_OPERAND (exp
, 0);
1872 case TRUTH_ORIF_EXPR
:
1873 case TRUTH_ANDIF_EXPR
:
1874 /* In && or ||, warn if 2nd operand has no side effect. */
1875 exp
= TREE_OPERAND (exp
, 1);
1879 if (warn_if_unused_value (TREE_OPERAND (exp
, 0), locus
))
1881 /* Let people do `(foo (), 0)' without a warning. */
1882 if (TREE_CONSTANT (TREE_OPERAND (exp
, 1)))
1884 exp
= TREE_OPERAND (exp
, 1);
1888 /* If this is an expression with side effects, don't warn; this
1889 case commonly appears in macro expansions. */
1890 if (TREE_SIDE_EFFECTS (exp
))
1895 /* Don't warn about automatic dereferencing of references, since
1896 the user cannot control it. */
1897 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == REFERENCE_TYPE
)
1899 exp
= TREE_OPERAND (exp
, 0);
1905 /* Referencing a volatile value is a side effect, so don't warn. */
1906 if ((DECL_P (exp
) || REFERENCE_CLASS_P (exp
))
1907 && TREE_THIS_VOLATILE (exp
))
1910 /* If this is an expression which has no operands, there is no value
1911 to be unused. There are no such language-independent codes,
1912 but front ends may define such. */
1913 if (EXPRESSION_CLASS_P (exp
) && TREE_OPERAND_LENGTH (exp
) == 0)
1917 return warning_at (locus
, OPT_Wunused_value
, "value computed is not used");
1922 /* Print a warning about casts that might indicate violation
1923 of strict aliasing rules if -Wstrict-aliasing is used and
1924 strict aliasing mode is in effect. OTYPE is the original
1925 TREE_TYPE of EXPR, and TYPE the type we're casting to. */
1928 strict_aliasing_warning (tree otype
, tree type
, tree expr
)
1930 /* Strip pointer conversion chains and get to the correct original type. */
1932 otype
= TREE_TYPE (expr
);
1934 if (!(flag_strict_aliasing
1935 && POINTER_TYPE_P (type
)
1936 && POINTER_TYPE_P (otype
)
1937 && !VOID_TYPE_P (TREE_TYPE (type
)))
1938 /* If the type we are casting to is a ref-all pointer
1939 dereferencing it is always valid. */
1940 || TYPE_REF_CAN_ALIAS_ALL (type
))
1943 if ((warn_strict_aliasing
> 1) && TREE_CODE (expr
) == ADDR_EXPR
1944 && (DECL_P (TREE_OPERAND (expr
, 0))
1945 || handled_component_p (TREE_OPERAND (expr
, 0))))
1947 /* Casting the address of an object to non void pointer. Warn
1948 if the cast breaks type based aliasing. */
1949 if (!COMPLETE_TYPE_P (TREE_TYPE (type
)) && warn_strict_aliasing
== 2)
1951 warning (OPT_Wstrict_aliasing
, "type-punning to incomplete type "
1952 "might break strict-aliasing rules");
1957 /* warn_strict_aliasing >= 3. This includes the default (3).
1958 Only warn if the cast is dereferenced immediately. */
1959 alias_set_type set1
=
1960 get_alias_set (TREE_TYPE (TREE_OPERAND (expr
, 0)));
1961 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
1963 if (set1
!= set2
&& set2
!= 0
1964 && (set1
== 0 || !alias_sets_conflict_p (set1
, set2
)))
1966 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1967 "pointer will break strict-aliasing rules");
1970 else if (warn_strict_aliasing
== 2
1971 && !alias_sets_must_conflict_p (set1
, set2
))
1973 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1974 "pointer might break strict-aliasing rules");
1980 if ((warn_strict_aliasing
== 1) && !VOID_TYPE_P (TREE_TYPE (otype
)))
1982 /* At this level, warn for any conversions, even if an address is
1983 not taken in the same statement. This will likely produce many
1984 false positives, but could be useful to pinpoint problems that
1985 are not revealed at higher levels. */
1986 alias_set_type set1
= get_alias_set (TREE_TYPE (otype
));
1987 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
1988 if (!COMPLETE_TYPE_P (type
)
1989 || !alias_sets_must_conflict_p (set1
, set2
))
1991 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1992 "pointer might break strict-aliasing rules");
2000 /* Warn about memset (&a, 0, sizeof (&a)); and similar mistakes with
2001 sizeof as last operand of certain builtins. */
2004 sizeof_pointer_memaccess_warning (location_t
*sizeof_arg_loc
, tree callee
,
2005 vec
<tree
, va_gc
> *params
, tree
*sizeof_arg
,
2006 bool (*comp_types
) (tree
, tree
))
2008 tree type
, dest
= NULL_TREE
, src
= NULL_TREE
, tem
;
2009 bool strop
= false, cmp
= false;
2010 unsigned int idx
= ~0;
2013 if (TREE_CODE (callee
) != FUNCTION_DECL
2014 || DECL_BUILT_IN_CLASS (callee
) != BUILT_IN_NORMAL
2015 || vec_safe_length (params
) <= 1)
2018 switch (DECL_FUNCTION_CODE (callee
))
2020 case BUILT_IN_STRNCMP
:
2021 case BUILT_IN_STRNCASECMP
:
2024 case BUILT_IN_STRNCPY
:
2025 case BUILT_IN_STRNCPY_CHK
:
2026 case BUILT_IN_STRNCAT
:
2027 case BUILT_IN_STRNCAT_CHK
:
2028 case BUILT_IN_STPNCPY
:
2029 case BUILT_IN_STPNCPY_CHK
:
2032 case BUILT_IN_MEMCPY
:
2033 case BUILT_IN_MEMCPY_CHK
:
2034 case BUILT_IN_MEMMOVE
:
2035 case BUILT_IN_MEMMOVE_CHK
:
2036 if (params
->length () < 3)
2039 dest
= (*params
)[0];
2042 case BUILT_IN_BCOPY
:
2043 if (params
->length () < 3)
2046 dest
= (*params
)[1];
2049 case BUILT_IN_MEMCMP
:
2051 if (params
->length () < 3)
2054 dest
= (*params
)[0];
2058 case BUILT_IN_MEMSET
:
2059 case BUILT_IN_MEMSET_CHK
:
2060 if (params
->length () < 3)
2062 dest
= (*params
)[0];
2065 case BUILT_IN_BZERO
:
2066 dest
= (*params
)[0];
2069 case BUILT_IN_STRNDUP
:
2074 case BUILT_IN_MEMCHR
:
2075 if (params
->length () < 3)
2080 case BUILT_IN_SNPRINTF
:
2081 case BUILT_IN_SNPRINTF_CHK
:
2082 case BUILT_IN_VSNPRINTF
:
2083 case BUILT_IN_VSNPRINTF_CHK
:
2084 dest
= (*params
)[0];
2095 if (sizeof_arg
[idx
] == NULL
|| sizeof_arg
[idx
] == error_mark_node
)
2098 type
= TYPE_P (sizeof_arg
[idx
])
2099 ? sizeof_arg
[idx
] : TREE_TYPE (sizeof_arg
[idx
]);
2100 if (!POINTER_TYPE_P (type
))
2104 && (tem
= tree_strip_nop_conversions (dest
))
2105 && POINTER_TYPE_P (TREE_TYPE (tem
))
2106 && comp_types (TREE_TYPE (TREE_TYPE (tem
)), type
))
2110 && (tem
= tree_strip_nop_conversions (src
))
2111 && POINTER_TYPE_P (TREE_TYPE (tem
))
2112 && comp_types (TREE_TYPE (TREE_TYPE (tem
)), type
))
2115 loc
= sizeof_arg_loc
[idx
];
2119 if (!TYPE_P (sizeof_arg
[idx
])
2120 && operand_equal_p (dest
, sizeof_arg
[idx
], 0)
2121 && comp_types (TREE_TYPE (dest
), type
))
2123 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2124 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2125 "argument to %<sizeof%> in %qD call is the same "
2126 "expression as the destination; did you mean to "
2127 "remove the addressof?", callee
);
2128 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2129 == TYPE_PRECISION (char_type_node
))
2131 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2132 "argument to %<sizeof%> in %qD call is the same "
2133 "expression as the destination; did you mean to "
2134 "provide an explicit length?", callee
);
2136 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2137 "argument to %<sizeof%> in %qD call is the same "
2138 "expression as the destination; did you mean to "
2139 "dereference it?", callee
);
2143 if (POINTER_TYPE_P (TREE_TYPE (dest
))
2145 && comp_types (TREE_TYPE (dest
), type
)
2146 && !VOID_TYPE_P (TREE_TYPE (type
)))
2148 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2149 "argument to %<sizeof%> in %qD call is the same "
2150 "pointer type %qT as the destination; expected %qT "
2151 "or an explicit length", callee
, TREE_TYPE (dest
),
2152 TREE_TYPE (TREE_TYPE (dest
)));
2159 if (!TYPE_P (sizeof_arg
[idx
])
2160 && operand_equal_p (src
, sizeof_arg
[idx
], 0)
2161 && comp_types (TREE_TYPE (src
), type
))
2163 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2164 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2165 "argument to %<sizeof%> in %qD call is the same "
2166 "expression as the source; did you mean to "
2167 "remove the addressof?", callee
);
2168 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2169 == TYPE_PRECISION (char_type_node
))
2171 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2172 "argument to %<sizeof%> in %qD call is the same "
2173 "expression as the source; did you mean to "
2174 "provide an explicit length?", callee
);
2176 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2177 "argument to %<sizeof%> in %qD call is the same "
2178 "expression as the source; did you mean to "
2179 "dereference it?", callee
);
2183 if (POINTER_TYPE_P (TREE_TYPE (src
))
2185 && comp_types (TREE_TYPE (src
), type
)
2186 && !VOID_TYPE_P (TREE_TYPE (type
)))
2188 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2189 "argument to %<sizeof%> in %qD call is the same "
2190 "pointer type %qT as the source; expected %qT "
2191 "or an explicit length", callee
, TREE_TYPE (src
),
2192 TREE_TYPE (TREE_TYPE (src
)));
2199 if (!TYPE_P (sizeof_arg
[idx
])
2200 && operand_equal_p (dest
, sizeof_arg
[idx
], 0)
2201 && comp_types (TREE_TYPE (dest
), type
))
2203 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2204 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2205 "argument to %<sizeof%> in %qD call is the same "
2206 "expression as the first source; did you mean to "
2207 "remove the addressof?", callee
);
2208 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2209 == TYPE_PRECISION (char_type_node
))
2211 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2212 "argument to %<sizeof%> in %qD call is the same "
2213 "expression as the first source; did you mean to "
2214 "provide an explicit length?", callee
);
2216 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2217 "argument to %<sizeof%> in %qD call is the same "
2218 "expression as the first source; did you mean to "
2219 "dereference it?", callee
);
2223 if (POINTER_TYPE_P (TREE_TYPE (dest
))
2225 && comp_types (TREE_TYPE (dest
), type
)
2226 && !VOID_TYPE_P (TREE_TYPE (type
)))
2228 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2229 "argument to %<sizeof%> in %qD call is the same "
2230 "pointer type %qT as the first source; expected %qT "
2231 "or an explicit length", callee
, TREE_TYPE (dest
),
2232 TREE_TYPE (TREE_TYPE (dest
)));
2239 if (!TYPE_P (sizeof_arg
[idx
])
2240 && operand_equal_p (src
, sizeof_arg
[idx
], 0)
2241 && comp_types (TREE_TYPE (src
), type
))
2243 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2244 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2245 "argument to %<sizeof%> in %qD call is the same "
2246 "expression as the second source; did you mean to "
2247 "remove the addressof?", callee
);
2248 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2249 == TYPE_PRECISION (char_type_node
))
2251 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2252 "argument to %<sizeof%> in %qD call is the same "
2253 "expression as the second source; did you mean to "
2254 "provide an explicit length?", callee
);
2256 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2257 "argument to %<sizeof%> in %qD call is the same "
2258 "expression as the second source; did you mean to "
2259 "dereference it?", callee
);
2263 if (POINTER_TYPE_P (TREE_TYPE (src
))
2265 && comp_types (TREE_TYPE (src
), type
)
2266 && !VOID_TYPE_P (TREE_TYPE (type
)))
2268 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2269 "argument to %<sizeof%> in %qD call is the same "
2270 "pointer type %qT as the second source; expected %qT "
2271 "or an explicit length", callee
, TREE_TYPE (src
),
2272 TREE_TYPE (TREE_TYPE (src
)));
2279 /* Warn for unlikely, improbable, or stupid DECL declarations
2283 check_main_parameter_types (tree decl
)
2285 function_args_iterator iter
;
2289 FOREACH_FUNCTION_ARGS (TREE_TYPE (decl
), type
, iter
)
2291 /* XXX void_type_node belies the abstraction. */
2292 if (type
== void_type_node
|| type
== error_mark_node
)
2296 if (TYPE_ATOMIC (t
))
2297 pedwarn (input_location
, OPT_Wmain
,
2298 "%<_Atomic%>-qualified parameter type %qT of %q+D",
2300 while (POINTER_TYPE_P (t
))
2303 if (TYPE_ATOMIC (t
))
2304 pedwarn (input_location
, OPT_Wmain
,
2305 "%<_Atomic%>-qualified parameter type %qT of %q+D",
2313 if (TYPE_MAIN_VARIANT (type
) != integer_type_node
)
2314 pedwarn (input_location
, OPT_Wmain
,
2315 "first argument of %q+D should be %<int%>", decl
);
2319 if (TREE_CODE (type
) != POINTER_TYPE
2320 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
2321 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
2323 pedwarn (input_location
, OPT_Wmain
,
2324 "second argument of %q+D should be %<char **%>", decl
);
2328 if (TREE_CODE (type
) != POINTER_TYPE
2329 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
2330 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
2332 pedwarn (input_location
, OPT_Wmain
,
2333 "third argument of %q+D should probably be "
2334 "%<char **%>", decl
);
2339 /* It is intentional that this message does not mention the third
2340 argument because it's only mentioned in an appendix of the
2342 if (argct
> 0 && (argct
< 2 || argct
> 3))
2343 pedwarn (input_location
, OPT_Wmain
,
2344 "%q+D takes only zero or two arguments", decl
);
2346 if (stdarg_p (TREE_TYPE (decl
)))
2347 pedwarn (input_location
, OPT_Wmain
,
2348 "%q+D declared as variadic function", decl
);
2351 /* vector_targets_convertible_p is used for vector pointer types. The
2352 callers perform various checks that the qualifiers are satisfactory,
2353 while OTOH vector_targets_convertible_p ignores the number of elements
2354 in the vectors. That's fine with vector pointers as we can consider,
2355 say, a vector of 8 elements as two consecutive vectors of 4 elements,
2356 and that does not require and conversion of the pointer values.
2357 In contrast, vector_types_convertible_p and
2358 vector_types_compatible_elements_p are used for vector value types. */
2359 /* True if pointers to distinct types T1 and T2 can be converted to
2360 each other without an explicit cast. Only returns true for opaque
2363 vector_targets_convertible_p (const_tree t1
, const_tree t2
)
2365 if (TREE_CODE (t1
) == VECTOR_TYPE
&& TREE_CODE (t2
) == VECTOR_TYPE
2366 && (TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2367 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2373 /* vector_types_convertible_p is used for vector value types.
2374 It could in principle call vector_targets_convertible_p as a subroutine,
2375 but then the check for vector type would be duplicated with its callers,
2376 and also the purpose of vector_targets_convertible_p would become
2378 Where vector_types_convertible_p returns true, a conversion might still be
2379 needed to make the types match.
2380 In contrast, vector_targets_convertible_p is used for vector pointer
2381 values, and vector_types_compatible_elements_p is used specifically
2382 in the context for binary operators, as a check if use is possible without
2384 /* True if vector types T1 and T2 can be converted to each other
2385 without an explicit cast. If EMIT_LAX_NOTE is true, and T1 and T2
2386 can only be converted with -flax-vector-conversions yet that is not
2387 in effect, emit a note telling the user about that option if such
2388 a note has not previously been emitted. */
2390 vector_types_convertible_p (const_tree t1
, const_tree t2
, bool emit_lax_note
)
2392 static bool emitted_lax_note
= false;
2393 bool convertible_lax
;
2395 if ((TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2396 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2400 (tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
))
2401 && (TREE_CODE (TREE_TYPE (t1
)) != REAL_TYPE
||
2402 TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
))
2403 && (INTEGRAL_TYPE_P (TREE_TYPE (t1
))
2404 == INTEGRAL_TYPE_P (TREE_TYPE (t2
))));
2406 if (!convertible_lax
|| flag_lax_vector_conversions
)
2407 return convertible_lax
;
2409 if (TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
)
2410 && lang_hooks
.types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
2413 if (emit_lax_note
&& !emitted_lax_note
)
2415 emitted_lax_note
= true;
2416 inform (input_location
, "use -flax-vector-conversions to permit "
2417 "conversions between vectors with differing "
2418 "element types or numbers of subparts");
2424 /* Build a VEC_PERM_EXPR if V0, V1 and MASK are not error_mark_nodes
2425 and have vector types, V0 has the same type as V1, and the number of
2426 elements of V0, V1, MASK is the same.
2428 In case V1 is a NULL_TREE it is assumed that __builtin_shuffle was
2429 called with two arguments. In this case implementation passes the
2430 first argument twice in order to share the same tree code. This fact
2431 could enable the mask-values being twice the vector length. This is
2432 an implementation accident and this semantics is not guaranteed to
2435 c_build_vec_perm_expr (location_t loc
, tree v0
, tree v1
, tree mask
,
2440 bool maybe_const
= false;
2441 bool two_arguments
= false;
2443 if (v1
== NULL_TREE
)
2445 two_arguments
= true;
2449 if (v0
== error_mark_node
|| v1
== error_mark_node
2450 || mask
== error_mark_node
)
2451 return error_mark_node
;
2453 if (TREE_CODE (TREE_TYPE (mask
)) != VECTOR_TYPE
2454 || TREE_CODE (TREE_TYPE (TREE_TYPE (mask
))) != INTEGER_TYPE
)
2457 error_at (loc
, "__builtin_shuffle last argument must "
2458 "be an integer vector");
2459 return error_mark_node
;
2462 if (TREE_CODE (TREE_TYPE (v0
)) != VECTOR_TYPE
2463 || TREE_CODE (TREE_TYPE (v1
)) != VECTOR_TYPE
)
2466 error_at (loc
, "__builtin_shuffle arguments must be vectors");
2467 return error_mark_node
;
2470 if (TYPE_MAIN_VARIANT (TREE_TYPE (v0
)) != TYPE_MAIN_VARIANT (TREE_TYPE (v1
)))
2473 error_at (loc
, "__builtin_shuffle argument vectors must be of "
2475 return error_mark_node
;
2478 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (v0
))
2479 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
))
2480 && TYPE_VECTOR_SUBPARTS (TREE_TYPE (v1
))
2481 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
)))
2484 error_at (loc
, "__builtin_shuffle number of elements of the "
2485 "argument vector(s) and the mask vector should "
2487 return error_mark_node
;
2490 if (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (v0
))))
2491 != GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (mask
)))))
2494 error_at (loc
, "__builtin_shuffle argument vector(s) inner type "
2495 "must have the same size as inner type of the mask");
2496 return error_mark_node
;
2499 if (!c_dialect_cxx ())
2501 /* Avoid C_MAYBE_CONST_EXPRs inside VEC_PERM_EXPR. */
2502 v0
= c_fully_fold (v0
, false, &maybe_const
);
2503 wrap
&= maybe_const
;
2506 v1
= v0
= save_expr (v0
);
2509 v1
= c_fully_fold (v1
, false, &maybe_const
);
2510 wrap
&= maybe_const
;
2513 mask
= c_fully_fold (mask
, false, &maybe_const
);
2514 wrap
&= maybe_const
;
2516 else if (two_arguments
)
2517 v1
= v0
= save_expr (v0
);
2519 ret
= build3_loc (loc
, VEC_PERM_EXPR
, TREE_TYPE (v0
), v0
, v1
, mask
);
2521 if (!c_dialect_cxx () && !wrap
)
2522 ret
= c_wrap_maybe_const (ret
, true);
2527 /* Like tree.c:get_narrower, but retain conversion from C++0x scoped enum
2528 to integral type. */
2531 c_common_get_narrower (tree op
, int *unsignedp_ptr
)
2533 op
= get_narrower (op
, unsignedp_ptr
);
2535 if (TREE_CODE (TREE_TYPE (op
)) == ENUMERAL_TYPE
2536 && ENUM_IS_SCOPED (TREE_TYPE (op
)))
2538 /* C++0x scoped enumerations don't implicitly convert to integral
2539 type; if we stripped an explicit conversion to a larger type we
2540 need to replace it so common_type will still work. */
2541 tree type
= c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op
)),
2542 TYPE_UNSIGNED (TREE_TYPE (op
)));
2543 op
= fold_convert (type
, op
);
2548 /* This is a helper function of build_binary_op.
2550 For certain operations if both args were extended from the same
2551 smaller type, do the arithmetic in that type and then extend.
2553 BITWISE indicates a bitwise operation.
2554 For them, this optimization is safe only if
2555 both args are zero-extended or both are sign-extended.
2556 Otherwise, we might change the result.
2557 Eg, (short)-1 | (unsigned short)-1 is (int)-1
2558 but calculated in (unsigned short) it would be (unsigned short)-1.
2561 shorten_binary_op (tree result_type
, tree op0
, tree op1
, bool bitwise
)
2563 int unsigned0
, unsigned1
;
2568 /* Cast OP0 and OP1 to RESULT_TYPE. Doing so prevents
2569 excessive narrowing when we call get_narrower below. For
2570 example, suppose that OP0 is of unsigned int extended
2571 from signed char and that RESULT_TYPE is long long int.
2572 If we explicitly cast OP0 to RESULT_TYPE, OP0 would look
2575 (long long int) (unsigned int) signed_char
2577 which get_narrower would narrow down to
2579 (unsigned int) signed char
2581 If we do not cast OP0 first, get_narrower would return
2582 signed_char, which is inconsistent with the case of the
2584 op0
= convert (result_type
, op0
);
2585 op1
= convert (result_type
, op1
);
2587 arg0
= c_common_get_narrower (op0
, &unsigned0
);
2588 arg1
= c_common_get_narrower (op1
, &unsigned1
);
2590 /* UNS is 1 if the operation to be done is an unsigned one. */
2591 uns
= TYPE_UNSIGNED (result_type
);
2593 /* Handle the case that OP0 (or OP1) does not *contain* a conversion
2594 but it *requires* conversion to FINAL_TYPE. */
2596 if ((TYPE_PRECISION (TREE_TYPE (op0
))
2597 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2598 && TREE_TYPE (op0
) != result_type
)
2599 unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2600 if ((TYPE_PRECISION (TREE_TYPE (op1
))
2601 == TYPE_PRECISION (TREE_TYPE (arg1
)))
2602 && TREE_TYPE (op1
) != result_type
)
2603 unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2605 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
2607 /* For bitwise operations, signedness of nominal type
2608 does not matter. Consider only how operands were extended. */
2612 /* Note that in all three cases below we refrain from optimizing
2613 an unsigned operation on sign-extended args.
2614 That would not be valid. */
2616 /* Both args variable: if both extended in same way
2617 from same width, do it in that width.
2618 Do it unsigned if args were zero-extended. */
2619 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
2620 < TYPE_PRECISION (result_type
))
2621 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2622 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2623 && unsigned0
== unsigned1
2624 && (unsigned0
|| !uns
))
2625 return c_common_signed_or_unsigned_type
2626 (unsigned0
, common_type (TREE_TYPE (arg0
), TREE_TYPE (arg1
)));
2628 else if (TREE_CODE (arg0
) == INTEGER_CST
2629 && (unsigned1
|| !uns
)
2630 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2631 < TYPE_PRECISION (result_type
))
2633 = c_common_signed_or_unsigned_type (unsigned1
,
2635 && !POINTER_TYPE_P (type
)
2636 && int_fits_type_p (arg0
, type
))
2639 else if (TREE_CODE (arg1
) == INTEGER_CST
2640 && (unsigned0
|| !uns
)
2641 && (TYPE_PRECISION (TREE_TYPE (arg0
))
2642 < TYPE_PRECISION (result_type
))
2644 = c_common_signed_or_unsigned_type (unsigned0
,
2646 && !POINTER_TYPE_P (type
)
2647 && int_fits_type_p (arg1
, type
))
2653 /* Checks if expression EXPR of real/integer type cannot be converted
2654 to the real/integer type TYPE. Function returns non-zero when:
2655 * EXPR is a constant which cannot be exactly converted to TYPE.
2656 * EXPR is not a constant and size of EXPR's type > than size of TYPE,
2657 for EXPR type and TYPE being both integers or both real.
2658 * EXPR is not a constant of real type and TYPE is an integer.
2659 * EXPR is not a constant of integer type which cannot be
2660 exactly converted to real type.
2661 Function allows conversions between types of different signedness and
2662 can return SAFE_CONVERSION (zero) in that case. Function can produce
2663 signedness warnings if PRODUCE_WARNS is true. */
2665 enum conversion_safety
2666 unsafe_conversion_p (location_t loc
, tree type
, tree expr
, bool produce_warns
)
2668 enum conversion_safety give_warning
= SAFE_CONVERSION
; /* is 0 or false */
2669 tree expr_type
= TREE_TYPE (expr
);
2670 loc
= expansion_point_location_if_in_system_header (loc
);
2672 if (TREE_CODE (expr
) == REAL_CST
|| TREE_CODE (expr
) == INTEGER_CST
)
2674 /* Warn for real constant that is not an exact integer converted
2676 if (TREE_CODE (expr_type
) == REAL_TYPE
2677 && TREE_CODE (type
) == INTEGER_TYPE
)
2679 if (!real_isinteger (TREE_REAL_CST_PTR (expr
), TYPE_MODE (expr_type
)))
2680 give_warning
= UNSAFE_REAL
;
2682 /* Warn for an integer constant that does not fit into integer type. */
2683 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2684 && TREE_CODE (type
) == INTEGER_TYPE
2685 && !int_fits_type_p (expr
, type
))
2687 if (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)
2688 && tree_int_cst_sgn (expr
) < 0)
2691 warning_at (loc
, OPT_Wsign_conversion
, "negative integer"
2692 " implicitly converted to unsigned type");
2694 else if (!TYPE_UNSIGNED (type
) && TYPE_UNSIGNED (expr_type
))
2697 warning_at (loc
, OPT_Wsign_conversion
, "conversion of unsigned"
2698 " constant value to negative integer");
2701 give_warning
= UNSAFE_OTHER
;
2703 else if (TREE_CODE (type
) == REAL_TYPE
)
2705 /* Warn for an integer constant that does not fit into real type. */
2706 if (TREE_CODE (expr_type
) == INTEGER_TYPE
)
2708 REAL_VALUE_TYPE a
= real_value_from_int_cst (0, expr
);
2709 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2710 give_warning
= UNSAFE_REAL
;
2712 /* Warn for a real constant that does not fit into a smaller
2714 else if (TREE_CODE (expr_type
) == REAL_TYPE
2715 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2717 REAL_VALUE_TYPE a
= TREE_REAL_CST (expr
);
2718 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2719 give_warning
= UNSAFE_REAL
;
2725 /* Warn for real types converted to integer types. */
2726 if (TREE_CODE (expr_type
) == REAL_TYPE
2727 && TREE_CODE (type
) == INTEGER_TYPE
)
2728 give_warning
= UNSAFE_REAL
;
2730 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2731 && TREE_CODE (type
) == INTEGER_TYPE
)
2733 /* Don't warn about unsigned char y = 0xff, x = (int) y; */
2734 expr
= get_unwidened (expr
, 0);
2735 expr_type
= TREE_TYPE (expr
);
2737 /* Don't warn for short y; short x = ((int)y & 0xff); */
2738 if (TREE_CODE (expr
) == BIT_AND_EXPR
2739 || TREE_CODE (expr
) == BIT_IOR_EXPR
2740 || TREE_CODE (expr
) == BIT_XOR_EXPR
)
2742 /* If both args were extended from a shortest type,
2743 use that type if that is safe. */
2744 expr_type
= shorten_binary_op (expr_type
,
2745 TREE_OPERAND (expr
, 0),
2746 TREE_OPERAND (expr
, 1),
2749 if (TREE_CODE (expr
) == BIT_AND_EXPR
)
2751 tree op0
= TREE_OPERAND (expr
, 0);
2752 tree op1
= TREE_OPERAND (expr
, 1);
2753 bool unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2754 bool unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2756 /* If one of the operands is a non-negative constant
2757 that fits in the target type, then the type of the
2758 other operand does not matter. */
2759 if ((TREE_CODE (op0
) == INTEGER_CST
2760 && int_fits_type_p (op0
, c_common_signed_type (type
))
2761 && int_fits_type_p (op0
, c_common_unsigned_type (type
)))
2762 || (TREE_CODE (op1
) == INTEGER_CST
2763 && int_fits_type_p (op1
, c_common_signed_type (type
))
2764 && int_fits_type_p (op1
,
2765 c_common_unsigned_type (type
))))
2766 return SAFE_CONVERSION
;
2767 /* If constant is unsigned and fits in the target
2768 type, then the result will also fit. */
2769 else if ((TREE_CODE (op0
) == INTEGER_CST
2771 && int_fits_type_p (op0
, type
))
2772 || (TREE_CODE (op1
) == INTEGER_CST
2774 && int_fits_type_p (op1
, type
)))
2775 return SAFE_CONVERSION
;
2778 /* Warn for integer types converted to smaller integer types. */
2779 if (TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2780 give_warning
= UNSAFE_OTHER
;
2782 /* When they are the same width but different signedness,
2783 then the value may change. */
2784 else if (((TYPE_PRECISION (type
) == TYPE_PRECISION (expr_type
)
2785 && TYPE_UNSIGNED (expr_type
) != TYPE_UNSIGNED (type
))
2786 /* Even when converted to a bigger type, if the type is
2787 unsigned but expr is signed, then negative values
2789 || (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)))
2791 warning_at (loc
, OPT_Wsign_conversion
, "conversion to %qT from %qT "
2792 "may change the sign of the result",
2796 /* Warn for integer types converted to real types if and only if
2797 all the range of values of the integer type cannot be
2798 represented by the real type. */
2799 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2800 && TREE_CODE (type
) == REAL_TYPE
)
2802 tree type_low_bound
, type_high_bound
;
2803 REAL_VALUE_TYPE real_low_bound
, real_high_bound
;
2805 /* Don't warn about char y = 0xff; float x = (int) y; */
2806 expr
= get_unwidened (expr
, 0);
2807 expr_type
= TREE_TYPE (expr
);
2809 type_low_bound
= TYPE_MIN_VALUE (expr_type
);
2810 type_high_bound
= TYPE_MAX_VALUE (expr_type
);
2811 real_low_bound
= real_value_from_int_cst (0, type_low_bound
);
2812 real_high_bound
= real_value_from_int_cst (0, type_high_bound
);
2814 if (!exact_real_truncate (TYPE_MODE (type
), &real_low_bound
)
2815 || !exact_real_truncate (TYPE_MODE (type
), &real_high_bound
))
2816 give_warning
= UNSAFE_OTHER
;
2819 /* Warn for real types converted to smaller real types. */
2820 else if (TREE_CODE (expr_type
) == REAL_TYPE
2821 && TREE_CODE (type
) == REAL_TYPE
2822 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2823 give_warning
= UNSAFE_REAL
;
2826 return give_warning
;
2829 /* Warns if the conversion of EXPR to TYPE may alter a value.
2830 This is a helper function for warnings_for_convert_and_check. */
2833 conversion_warning (location_t loc
, tree type
, tree expr
)
2835 tree expr_type
= TREE_TYPE (expr
);
2836 enum conversion_safety conversion_kind
;
2838 if (!warn_conversion
&& !warn_sign_conversion
&& !warn_float_conversion
)
2841 /* This may happen, because for LHS op= RHS we preevaluate
2842 RHS and create C_MAYBE_CONST_EXPR <SAVE_EXPR <RHS>>, which
2843 means we could no longer see the code of the EXPR. */
2844 if (TREE_CODE (expr
) == C_MAYBE_CONST_EXPR
)
2845 expr
= C_MAYBE_CONST_EXPR_EXPR (expr
);
2846 if (TREE_CODE (expr
) == SAVE_EXPR
)
2847 expr
= TREE_OPERAND (expr
, 0);
2849 switch (TREE_CODE (expr
))
2857 case TRUTH_ANDIF_EXPR
:
2858 case TRUTH_ORIF_EXPR
:
2859 case TRUTH_AND_EXPR
:
2861 case TRUTH_XOR_EXPR
:
2862 case TRUTH_NOT_EXPR
:
2863 /* Conversion from boolean to a signed:1 bit-field (which only
2864 can hold the values 0 and -1) doesn't lose information - but
2865 it does change the value. */
2866 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
2867 warning_at (loc
, OPT_Wconversion
,
2868 "conversion to %qT from boolean expression", type
);
2873 conversion_kind
= unsafe_conversion_p (loc
, type
, expr
, true);
2874 if (conversion_kind
== UNSAFE_REAL
)
2875 warning_at (loc
, OPT_Wfloat_conversion
,
2876 "conversion to %qT alters %qT constant value",
2878 else if (conversion_kind
)
2879 warning_at (loc
, OPT_Wconversion
,
2880 "conversion to %qT alters %qT constant value",
2886 /* In case of COND_EXPR, we do not care about the type of
2887 COND_EXPR, only about the conversion of each operand. */
2888 tree op1
= TREE_OPERAND (expr
, 1);
2889 tree op2
= TREE_OPERAND (expr
, 2);
2891 conversion_warning (loc
, type
, op1
);
2892 conversion_warning (loc
, type
, op2
);
2896 default: /* 'expr' is not a constant. */
2897 conversion_kind
= unsafe_conversion_p (loc
, type
, expr
, true);
2898 if (conversion_kind
== UNSAFE_REAL
)
2899 warning_at (loc
, OPT_Wfloat_conversion
,
2900 "conversion to %qT from %qT may alter its value",
2902 else if (conversion_kind
)
2903 warning_at (loc
, OPT_Wconversion
,
2904 "conversion to %qT from %qT may alter its value",
2909 /* Produce warnings after a conversion. RESULT is the result of
2910 converting EXPR to TYPE. This is a helper function for
2911 convert_and_check and cp_convert_and_check. */
2914 warnings_for_convert_and_check (location_t loc
, tree type
, tree expr
,
2917 loc
= expansion_point_location_if_in_system_header (loc
);
2919 if (TREE_CODE (expr
) == INTEGER_CST
2920 && (TREE_CODE (type
) == INTEGER_TYPE
2921 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2922 && !int_fits_type_p (expr
, type
))
2924 /* Do not diagnose overflow in a constant expression merely
2925 because a conversion overflowed. */
2926 if (TREE_OVERFLOW (result
))
2927 TREE_OVERFLOW (result
) = TREE_OVERFLOW (expr
);
2929 if (TYPE_UNSIGNED (type
))
2931 /* This detects cases like converting -129 or 256 to
2933 if (!int_fits_type_p (expr
, c_common_signed_type (type
)))
2934 warning_at (loc
, OPT_Woverflow
,
2935 "large integer implicitly truncated to unsigned type");
2937 conversion_warning (loc
, type
, expr
);
2939 else if (!int_fits_type_p (expr
, c_common_unsigned_type (type
)))
2940 warning_at (loc
, OPT_Woverflow
,
2941 "overflow in implicit constant conversion");
2942 /* No warning for converting 0x80000000 to int. */
2944 && (TREE_CODE (TREE_TYPE (expr
)) != INTEGER_TYPE
2945 || TYPE_PRECISION (TREE_TYPE (expr
))
2946 != TYPE_PRECISION (type
)))
2947 warning_at (loc
, OPT_Woverflow
,
2948 "overflow in implicit constant conversion");
2951 conversion_warning (loc
, type
, expr
);
2953 else if ((TREE_CODE (result
) == INTEGER_CST
2954 || TREE_CODE (result
) == FIXED_CST
) && TREE_OVERFLOW (result
))
2955 warning_at (loc
, OPT_Woverflow
,
2956 "overflow in implicit constant conversion");
2958 conversion_warning (loc
, type
, expr
);
2962 /* Convert EXPR to TYPE, warning about conversion problems with constants.
2963 Invoke this function on every expression that is converted implicitly,
2964 i.e. because of language rules and not because of an explicit cast. */
2967 convert_and_check (location_t loc
, tree type
, tree expr
)
2970 tree expr_for_warning
;
2972 /* Convert from a value with possible excess precision rather than
2973 via the semantic type, but do not warn about values not fitting
2974 exactly in the semantic type. */
2975 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
2977 tree orig_type
= TREE_TYPE (expr
);
2978 expr
= TREE_OPERAND (expr
, 0);
2979 expr_for_warning
= convert (orig_type
, expr
);
2980 if (orig_type
== type
)
2981 return expr_for_warning
;
2984 expr_for_warning
= expr
;
2986 if (TREE_TYPE (expr
) == type
)
2989 result
= convert (type
, expr
);
2991 if (c_inhibit_evaluation_warnings
== 0
2992 && !TREE_OVERFLOW_P (expr
)
2993 && result
!= error_mark_node
)
2994 warnings_for_convert_and_check (loc
, type
, expr_for_warning
, result
);
2999 /* A node in a list that describes references to variables (EXPR), which are
3000 either read accesses if WRITER is zero, or write accesses, in which case
3001 WRITER is the parent of EXPR. */
3008 /* Used to implement a cache the results of a call to verify_tree. We only
3009 use this for SAVE_EXPRs. */
3012 struct tlist_cache
*next
;
3013 struct tlist
*cache_before_sp
;
3014 struct tlist
*cache_after_sp
;
3018 /* Obstack to use when allocating tlist structures, and corresponding
3020 static struct obstack tlist_obstack
;
3021 static char *tlist_firstobj
= 0;
3023 /* Keep track of the identifiers we've warned about, so we can avoid duplicate
3025 static struct tlist
*warned_ids
;
3026 /* SAVE_EXPRs need special treatment. We process them only once and then
3027 cache the results. */
3028 static struct tlist_cache
*save_expr_cache
;
3030 static void add_tlist (struct tlist
**, struct tlist
*, tree
, int);
3031 static void merge_tlist (struct tlist
**, struct tlist
*, int);
3032 static void verify_tree (tree
, struct tlist
**, struct tlist
**, tree
);
3033 static int warning_candidate_p (tree
);
3034 static bool candidate_equal_p (const_tree
, const_tree
);
3035 static void warn_for_collisions (struct tlist
*);
3036 static void warn_for_collisions_1 (tree
, tree
, struct tlist
*, int);
3037 static struct tlist
*new_tlist (struct tlist
*, tree
, tree
);
3039 /* Create a new struct tlist and fill in its fields. */
3040 static struct tlist
*
3041 new_tlist (struct tlist
*next
, tree t
, tree writer
)
3044 l
= XOBNEW (&tlist_obstack
, struct tlist
);
3051 /* Add duplicates of the nodes found in ADD to the list *TO. If EXCLUDE_WRITER
3052 is nonnull, we ignore any node we find which has a writer equal to it. */
3055 add_tlist (struct tlist
**to
, struct tlist
*add
, tree exclude_writer
, int copy
)
3059 struct tlist
*next
= add
->next
;
3062 if (!exclude_writer
|| !candidate_equal_p (add
->writer
, exclude_writer
))
3063 *to
= copy
? new_tlist (*to
, add
->expr
, add
->writer
) : add
;
3068 /* Merge the nodes of ADD into TO. This merging process is done so that for
3069 each variable that already exists in TO, no new node is added; however if
3070 there is a write access recorded in ADD, and an occurrence on TO is only
3071 a read access, then the occurrence in TO will be modified to record the
3075 merge_tlist (struct tlist
**to
, struct tlist
*add
, int copy
)
3077 struct tlist
**end
= to
;
3080 end
= &(*end
)->next
;
3086 struct tlist
*next
= add
->next
;
3088 for (tmp2
= *to
; tmp2
; tmp2
= tmp2
->next
)
3089 if (candidate_equal_p (tmp2
->expr
, add
->expr
))
3093 tmp2
->writer
= add
->writer
;
3097 *end
= copy
? new_tlist (NULL
, add
->expr
, add
->writer
) : add
;
3098 end
= &(*end
)->next
;
3105 /* WRITTEN is a variable, WRITER is its parent. Warn if any of the variable
3106 references in list LIST conflict with it, excluding reads if ONLY writers
3110 warn_for_collisions_1 (tree written
, tree writer
, struct tlist
*list
,
3115 /* Avoid duplicate warnings. */
3116 for (tmp
= warned_ids
; tmp
; tmp
= tmp
->next
)
3117 if (candidate_equal_p (tmp
->expr
, written
))
3122 if (candidate_equal_p (list
->expr
, written
)
3123 && !candidate_equal_p (list
->writer
, writer
)
3124 && (!only_writes
|| list
->writer
))
3126 warned_ids
= new_tlist (warned_ids
, written
, NULL_TREE
);
3127 warning_at (EXPR_LOC_OR_LOC (writer
, input_location
),
3128 OPT_Wsequence_point
, "operation on %qE may be undefined",
3135 /* Given a list LIST of references to variables, find whether any of these
3136 can cause conflicts due to missing sequence points. */
3139 warn_for_collisions (struct tlist
*list
)
3143 for (tmp
= list
; tmp
; tmp
= tmp
->next
)
3146 warn_for_collisions_1 (tmp
->expr
, tmp
->writer
, list
, 0);
3150 /* Return nonzero if X is a tree that can be verified by the sequence point
3153 warning_candidate_p (tree x
)
3155 if (DECL_P (x
) && DECL_ARTIFICIAL (x
))
3158 if (TREE_CODE (x
) == BLOCK
)
3161 /* VOID_TYPE_P (TREE_TYPE (x)) is workaround for cp/tree.c
3162 (lvalue_p) crash on TRY/CATCH. */
3163 if (TREE_TYPE (x
) == NULL_TREE
|| VOID_TYPE_P (TREE_TYPE (x
)))
3169 /* No point to track non-const calls, they will never satisfy
3171 if (TREE_CODE (x
) == CALL_EXPR
&& (call_expr_flags (x
) & ECF_CONST
) == 0)
3174 if (TREE_CODE (x
) == STRING_CST
)
3180 /* Return nonzero if X and Y appear to be the same candidate (or NULL) */
3182 candidate_equal_p (const_tree x
, const_tree y
)
3184 return (x
== y
) || (x
&& y
&& operand_equal_p (x
, y
, 0));
3187 /* Walk the tree X, and record accesses to variables. If X is written by the
3188 parent tree, WRITER is the parent.
3189 We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP. If this
3190 expression or its only operand forces a sequence point, then everything up
3191 to the sequence point is stored in PBEFORE_SP. Everything else gets stored
3193 Once we return, we will have emitted warnings if any subexpression before
3194 such a sequence point could be undefined. On a higher level, however, the
3195 sequence point may not be relevant, and we'll merge the two lists.
3197 Example: (b++, a) + b;
3198 The call that processes the COMPOUND_EXPR will store the increment of B
3199 in PBEFORE_SP, and the use of A in PNO_SP. The higher-level call that
3200 processes the PLUS_EXPR will need to merge the two lists so that
3201 eventually, all accesses end up on the same list (and we'll warn about the
3202 unordered subexpressions b++ and b.
3204 A note on merging. If we modify the former example so that our expression
3207 care must be taken not simply to add all three expressions into the final
3208 PNO_SP list. The function merge_tlist takes care of that by merging the
3209 before-SP list of the COMPOUND_EXPR into its after-SP list in a special
3210 way, so that no more than one access to B is recorded. */
3213 verify_tree (tree x
, struct tlist
**pbefore_sp
, struct tlist
**pno_sp
,
3216 struct tlist
*tmp_before
, *tmp_nosp
, *tmp_list2
, *tmp_list3
;
3217 enum tree_code code
;
3218 enum tree_code_class cl
;
3220 /* X may be NULL if it is the operand of an empty statement expression
3226 code
= TREE_CODE (x
);
3227 cl
= TREE_CODE_CLASS (code
);
3229 if (warning_candidate_p (x
))
3230 *pno_sp
= new_tlist (*pno_sp
, x
, writer
);
3239 case TRUTH_ANDIF_EXPR
:
3240 case TRUTH_ORIF_EXPR
:
3241 tmp_before
= tmp_nosp
= tmp_list3
= 0;
3242 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3243 warn_for_collisions (tmp_nosp
);
3244 merge_tlist (pbefore_sp
, tmp_before
, 0);
3245 merge_tlist (pbefore_sp
, tmp_nosp
, 0);
3246 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, pno_sp
, NULL_TREE
);
3247 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3251 tmp_before
= tmp_list2
= 0;
3252 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_list2
, NULL_TREE
);
3253 warn_for_collisions (tmp_list2
);
3254 merge_tlist (pbefore_sp
, tmp_before
, 0);
3255 merge_tlist (pbefore_sp
, tmp_list2
, 0);
3257 tmp_list3
= tmp_nosp
= 0;
3258 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, &tmp_nosp
, NULL_TREE
);
3259 warn_for_collisions (tmp_nosp
);
3260 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3262 tmp_list3
= tmp_list2
= 0;
3263 verify_tree (TREE_OPERAND (x
, 2), &tmp_list3
, &tmp_list2
, NULL_TREE
);
3264 warn_for_collisions (tmp_list2
);
3265 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3266 /* Rather than add both tmp_nosp and tmp_list2, we have to merge the
3267 two first, to avoid warning for (a ? b++ : b++). */
3268 merge_tlist (&tmp_nosp
, tmp_list2
, 0);
3269 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3272 case PREDECREMENT_EXPR
:
3273 case PREINCREMENT_EXPR
:
3274 case POSTDECREMENT_EXPR
:
3275 case POSTINCREMENT_EXPR
:
3276 verify_tree (TREE_OPERAND (x
, 0), pno_sp
, pno_sp
, x
);
3280 tmp_before
= tmp_nosp
= tmp_list3
= 0;
3281 verify_tree (TREE_OPERAND (x
, 1), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3282 verify_tree (TREE_OPERAND (x
, 0), &tmp_list3
, &tmp_list3
, x
);
3283 /* Expressions inside the LHS are not ordered wrt. the sequence points
3284 in the RHS. Example:
3286 Despite the fact that the modification of "a" is in the before_sp
3287 list (tmp_before), it conflicts with the use of "a" in the LHS.
3288 We can handle this by adding the contents of tmp_list3
3289 to those of tmp_before, and redoing the collision warnings for that
3291 add_tlist (&tmp_before
, tmp_list3
, x
, 1);
3292 warn_for_collisions (tmp_before
);
3293 /* Exclude the LHS itself here; we first have to merge it into the
3294 tmp_nosp list. This is done to avoid warning for "a = a"; if we
3295 didn't exclude the LHS, we'd get it twice, once as a read and once
3297 add_tlist (pno_sp
, tmp_list3
, x
, 0);
3298 warn_for_collisions_1 (TREE_OPERAND (x
, 0), x
, tmp_nosp
, 1);
3300 merge_tlist (pbefore_sp
, tmp_before
, 0);
3301 if (warning_candidate_p (TREE_OPERAND (x
, 0)))
3302 merge_tlist (&tmp_nosp
, new_tlist (NULL
, TREE_OPERAND (x
, 0), x
), 0);
3303 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 1);
3307 /* We need to warn about conflicts among arguments and conflicts between
3308 args and the function address. Side effects of the function address,
3309 however, are not ordered by the sequence point of the call. */
3311 call_expr_arg_iterator iter
;
3313 tmp_before
= tmp_nosp
= 0;
3314 verify_tree (CALL_EXPR_FN (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3315 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, x
)
3317 tmp_list2
= tmp_list3
= 0;
3318 verify_tree (arg
, &tmp_list2
, &tmp_list3
, NULL_TREE
);
3319 merge_tlist (&tmp_list3
, tmp_list2
, 0);
3320 add_tlist (&tmp_before
, tmp_list3
, NULL_TREE
, 0);
3322 add_tlist (&tmp_before
, tmp_nosp
, NULL_TREE
, 0);
3323 warn_for_collisions (tmp_before
);
3324 add_tlist (pbefore_sp
, tmp_before
, NULL_TREE
, 0);
3329 /* Scan all the list, e.g. indices of multi dimensional array. */
3332 tmp_before
= tmp_nosp
= 0;
3333 verify_tree (TREE_VALUE (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3334 merge_tlist (&tmp_nosp
, tmp_before
, 0);
3335 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3342 struct tlist_cache
*t
;
3343 for (t
= save_expr_cache
; t
; t
= t
->next
)
3344 if (candidate_equal_p (t
->expr
, x
))
3349 t
= XOBNEW (&tlist_obstack
, struct tlist_cache
);
3350 t
->next
= save_expr_cache
;
3352 save_expr_cache
= t
;
3354 tmp_before
= tmp_nosp
= 0;
3355 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3356 warn_for_collisions (tmp_nosp
);
3359 merge_tlist (&tmp_list3
, tmp_nosp
, 0);
3360 t
->cache_before_sp
= tmp_before
;
3361 t
->cache_after_sp
= tmp_list3
;
3363 merge_tlist (pbefore_sp
, t
->cache_before_sp
, 1);
3364 add_tlist (pno_sp
, t
->cache_after_sp
, NULL_TREE
, 1);
3369 x
= TREE_OPERAND (x
, 0);
3376 /* For other expressions, simply recurse on their operands.
3377 Manual tail recursion for unary expressions.
3378 Other non-expressions need not be processed. */
3379 if (cl
== tcc_unary
)
3381 x
= TREE_OPERAND (x
, 0);
3385 else if (IS_EXPR_CODE_CLASS (cl
))
3388 int max
= TREE_OPERAND_LENGTH (x
);
3389 for (lp
= 0; lp
< max
; lp
++)
3391 tmp_before
= tmp_nosp
= 0;
3392 verify_tree (TREE_OPERAND (x
, lp
), &tmp_before
, &tmp_nosp
, 0);
3393 merge_tlist (&tmp_nosp
, tmp_before
, 0);
3394 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3401 /* Try to warn for undefined behavior in EXPR due to missing sequence
3405 verify_sequence_points (tree expr
)
3407 struct tlist
*before_sp
= 0, *after_sp
= 0;
3410 save_expr_cache
= 0;
3411 if (tlist_firstobj
== 0)
3413 gcc_obstack_init (&tlist_obstack
);
3414 tlist_firstobj
= (char *) obstack_alloc (&tlist_obstack
, 0);
3417 verify_tree (expr
, &before_sp
, &after_sp
, 0);
3418 warn_for_collisions (after_sp
);
3419 obstack_free (&tlist_obstack
, tlist_firstobj
);
3422 /* Validate the expression after `case' and apply default promotions. */
3425 check_case_value (location_t loc
, tree value
)
3427 if (value
== NULL_TREE
)
3430 if (TREE_CODE (value
) == INTEGER_CST
)
3431 /* Promote char or short to int. */
3432 value
= perform_integral_promotions (value
);
3433 else if (value
!= error_mark_node
)
3435 error_at (loc
, "case label does not reduce to an integer constant");
3436 value
= error_mark_node
;
3439 constant_expression_warning (value
);
3444 /* See if the case values LOW and HIGH are in the range of the original
3445 type (i.e. before the default conversion to int) of the switch testing
3447 TYPE is the promoted type of the testing expression, and ORIG_TYPE is
3448 the type before promoting it. CASE_LOW_P is a pointer to the lower
3449 bound of the case label, and CASE_HIGH_P is the upper bound or NULL
3450 if the case is not a case range.
3451 The caller has to make sure that we are not called with NULL for
3452 CASE_LOW_P (i.e. the default case).
3453 Returns true if the case label is in range of ORIG_TYPE (saturated or
3454 untouched) or false if the label is out of range. */
3457 check_case_bounds (location_t loc
, tree type
, tree orig_type
,
3458 tree
*case_low_p
, tree
*case_high_p
)
3460 tree min_value
, max_value
;
3461 tree case_low
= *case_low_p
;
3462 tree case_high
= case_high_p
? *case_high_p
: case_low
;
3464 /* If there was a problem with the original type, do nothing. */
3465 if (orig_type
== error_mark_node
)
3468 min_value
= TYPE_MIN_VALUE (orig_type
);
3469 max_value
= TYPE_MAX_VALUE (orig_type
);
3471 /* Case label is less than minimum for type. */
3472 if (tree_int_cst_compare (case_low
, min_value
) < 0
3473 && tree_int_cst_compare (case_high
, min_value
) < 0)
3475 warning_at (loc
, 0, "case label value is less than minimum value "
3480 /* Case value is greater than maximum for type. */
3481 if (tree_int_cst_compare (case_low
, max_value
) > 0
3482 && tree_int_cst_compare (case_high
, max_value
) > 0)
3484 warning_at (loc
, 0, "case label value exceeds maximum value for type");
3488 /* Saturate lower case label value to minimum. */
3489 if (tree_int_cst_compare (case_high
, min_value
) >= 0
3490 && tree_int_cst_compare (case_low
, min_value
) < 0)
3492 warning_at (loc
, 0, "lower value in case label range"
3493 " less than minimum value for type");
3494 case_low
= min_value
;
3497 /* Saturate upper case label value to maximum. */
3498 if (tree_int_cst_compare (case_low
, max_value
) <= 0
3499 && tree_int_cst_compare (case_high
, max_value
) > 0)
3501 warning_at (loc
, 0, "upper value in case label range"
3502 " exceeds maximum value for type");
3503 case_high
= max_value
;
3506 if (*case_low_p
!= case_low
)
3507 *case_low_p
= convert (type
, case_low
);
3508 if (case_high_p
&& *case_high_p
!= case_high
)
3509 *case_high_p
= convert (type
, case_high
);
3514 /* Return an integer type with BITS bits of precision,
3515 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
3518 c_common_type_for_size (unsigned int bits
, int unsignedp
)
3522 if (bits
== TYPE_PRECISION (integer_type_node
))
3523 return unsignedp
? unsigned_type_node
: integer_type_node
;
3525 if (bits
== TYPE_PRECISION (signed_char_type_node
))
3526 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3528 if (bits
== TYPE_PRECISION (short_integer_type_node
))
3529 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3531 if (bits
== TYPE_PRECISION (long_integer_type_node
))
3532 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3534 if (bits
== TYPE_PRECISION (long_long_integer_type_node
))
3535 return (unsignedp
? long_long_unsigned_type_node
3536 : long_long_integer_type_node
);
3538 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
3539 if (int_n_enabled_p
[i
]
3540 && bits
== int_n_data
[i
].bitsize
)
3541 return (unsignedp
? int_n_trees
[i
].unsigned_type
3542 : int_n_trees
[i
].signed_type
);
3544 if (bits
== TYPE_PRECISION (widest_integer_literal_type_node
))
3545 return (unsignedp
? widest_unsigned_literal_type_node
3546 : widest_integer_literal_type_node
);
3548 if (bits
<= TYPE_PRECISION (intQI_type_node
))
3549 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3551 if (bits
<= TYPE_PRECISION (intHI_type_node
))
3552 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3554 if (bits
<= TYPE_PRECISION (intSI_type_node
))
3555 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3557 if (bits
<= TYPE_PRECISION (intDI_type_node
))
3558 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3563 /* Return a fixed-point type that has at least IBIT ibits and FBIT fbits
3564 that is unsigned if UNSIGNEDP is nonzero, otherwise signed;
3565 and saturating if SATP is nonzero, otherwise not saturating. */
3568 c_common_fixed_point_type_for_size (unsigned int ibit
, unsigned int fbit
,
3569 int unsignedp
, int satp
)
3573 mode
= unsignedp
? UQQmode
: QQmode
;
3575 mode
= unsignedp
? UHAmode
: HAmode
;
3577 for (; mode
!= VOIDmode
; mode
= GET_MODE_WIDER_MODE (mode
))
3578 if (GET_MODE_IBIT (mode
) >= ibit
&& GET_MODE_FBIT (mode
) >= fbit
)
3581 if (mode
== VOIDmode
|| !targetm
.scalar_mode_supported_p (mode
))
3583 sorry ("GCC cannot support operators with integer types and "
3584 "fixed-point types that have too many integral and "
3585 "fractional bits together");
3589 return c_common_type_for_mode (mode
, satp
);
3592 /* Used for communication between c_common_type_for_mode and
3593 c_register_builtin_type. */
3594 tree registered_builtin_types
;
3596 /* Return a data type that has machine mode MODE.
3597 If the mode is an integer,
3598 then UNSIGNEDP selects between signed and unsigned types.
3599 If the mode is a fixed-point mode,
3600 then UNSIGNEDP selects between saturating and nonsaturating types. */
3603 c_common_type_for_mode (machine_mode mode
, int unsignedp
)
3608 if (mode
== TYPE_MODE (integer_type_node
))
3609 return unsignedp
? unsigned_type_node
: integer_type_node
;
3611 if (mode
== TYPE_MODE (signed_char_type_node
))
3612 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3614 if (mode
== TYPE_MODE (short_integer_type_node
))
3615 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3617 if (mode
== TYPE_MODE (long_integer_type_node
))
3618 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3620 if (mode
== TYPE_MODE (long_long_integer_type_node
))
3621 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3623 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
3624 if (int_n_enabled_p
[i
]
3625 && mode
== int_n_data
[i
].m
)
3626 return (unsignedp
? int_n_trees
[i
].unsigned_type
3627 : int_n_trees
[i
].signed_type
);
3629 if (mode
== TYPE_MODE (widest_integer_literal_type_node
))
3630 return unsignedp
? widest_unsigned_literal_type_node
3631 : widest_integer_literal_type_node
;
3634 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3637 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3640 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3643 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3645 #if HOST_BITS_PER_WIDE_INT >= 64
3646 if (mode
== TYPE_MODE (intTI_type_node
))
3647 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3650 if (mode
== TYPE_MODE (float_type_node
))
3651 return float_type_node
;
3653 if (mode
== TYPE_MODE (double_type_node
))
3654 return double_type_node
;
3656 if (mode
== TYPE_MODE (long_double_type_node
))
3657 return long_double_type_node
;
3659 if (mode
== TYPE_MODE (void_type_node
))
3660 return void_type_node
;
3662 if (mode
== TYPE_MODE (build_pointer_type (char_type_node
)))
3664 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3665 : make_signed_type (GET_MODE_PRECISION (mode
)));
3667 if (mode
== TYPE_MODE (build_pointer_type (integer_type_node
)))
3669 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3670 : make_signed_type (GET_MODE_PRECISION (mode
)));
3672 if (COMPLEX_MODE_P (mode
))
3674 machine_mode inner_mode
;
3677 if (mode
== TYPE_MODE (complex_float_type_node
))
3678 return complex_float_type_node
;
3679 if (mode
== TYPE_MODE (complex_double_type_node
))
3680 return complex_double_type_node
;
3681 if (mode
== TYPE_MODE (complex_long_double_type_node
))
3682 return complex_long_double_type_node
;
3684 if (mode
== TYPE_MODE (complex_integer_type_node
) && !unsignedp
)
3685 return complex_integer_type_node
;
3687 inner_mode
= GET_MODE_INNER (mode
);
3688 inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3689 if (inner_type
!= NULL_TREE
)
3690 return build_complex_type (inner_type
);
3692 else if (VECTOR_MODE_P (mode
))
3694 machine_mode inner_mode
= GET_MODE_INNER (mode
);
3695 tree inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3696 if (inner_type
!= NULL_TREE
)
3697 return build_vector_type_for_mode (inner_type
, mode
);
3700 if (mode
== TYPE_MODE (dfloat32_type_node
))
3701 return dfloat32_type_node
;
3702 if (mode
== TYPE_MODE (dfloat64_type_node
))
3703 return dfloat64_type_node
;
3704 if (mode
== TYPE_MODE (dfloat128_type_node
))
3705 return dfloat128_type_node
;
3707 if (ALL_SCALAR_FIXED_POINT_MODE_P (mode
))
3709 if (mode
== TYPE_MODE (short_fract_type_node
))
3710 return unsignedp
? sat_short_fract_type_node
: short_fract_type_node
;
3711 if (mode
== TYPE_MODE (fract_type_node
))
3712 return unsignedp
? sat_fract_type_node
: fract_type_node
;
3713 if (mode
== TYPE_MODE (long_fract_type_node
))
3714 return unsignedp
? sat_long_fract_type_node
: long_fract_type_node
;
3715 if (mode
== TYPE_MODE (long_long_fract_type_node
))
3716 return unsignedp
? sat_long_long_fract_type_node
3717 : long_long_fract_type_node
;
3719 if (mode
== TYPE_MODE (unsigned_short_fract_type_node
))
3720 return unsignedp
? sat_unsigned_short_fract_type_node
3721 : unsigned_short_fract_type_node
;
3722 if (mode
== TYPE_MODE (unsigned_fract_type_node
))
3723 return unsignedp
? sat_unsigned_fract_type_node
3724 : unsigned_fract_type_node
;
3725 if (mode
== TYPE_MODE (unsigned_long_fract_type_node
))
3726 return unsignedp
? sat_unsigned_long_fract_type_node
3727 : unsigned_long_fract_type_node
;
3728 if (mode
== TYPE_MODE (unsigned_long_long_fract_type_node
))
3729 return unsignedp
? sat_unsigned_long_long_fract_type_node
3730 : unsigned_long_long_fract_type_node
;
3732 if (mode
== TYPE_MODE (short_accum_type_node
))
3733 return unsignedp
? sat_short_accum_type_node
: short_accum_type_node
;
3734 if (mode
== TYPE_MODE (accum_type_node
))
3735 return unsignedp
? sat_accum_type_node
: accum_type_node
;
3736 if (mode
== TYPE_MODE (long_accum_type_node
))
3737 return unsignedp
? sat_long_accum_type_node
: long_accum_type_node
;
3738 if (mode
== TYPE_MODE (long_long_accum_type_node
))
3739 return unsignedp
? sat_long_long_accum_type_node
3740 : long_long_accum_type_node
;
3742 if (mode
== TYPE_MODE (unsigned_short_accum_type_node
))
3743 return unsignedp
? sat_unsigned_short_accum_type_node
3744 : unsigned_short_accum_type_node
;
3745 if (mode
== TYPE_MODE (unsigned_accum_type_node
))
3746 return unsignedp
? sat_unsigned_accum_type_node
3747 : unsigned_accum_type_node
;
3748 if (mode
== TYPE_MODE (unsigned_long_accum_type_node
))
3749 return unsignedp
? sat_unsigned_long_accum_type_node
3750 : unsigned_long_accum_type_node
;
3751 if (mode
== TYPE_MODE (unsigned_long_long_accum_type_node
))
3752 return unsignedp
? sat_unsigned_long_long_accum_type_node
3753 : unsigned_long_long_accum_type_node
;
3756 return unsignedp
? sat_qq_type_node
: qq_type_node
;
3758 return unsignedp
? sat_hq_type_node
: hq_type_node
;
3760 return unsignedp
? sat_sq_type_node
: sq_type_node
;
3762 return unsignedp
? sat_dq_type_node
: dq_type_node
;
3764 return unsignedp
? sat_tq_type_node
: tq_type_node
;
3766 if (mode
== UQQmode
)
3767 return unsignedp
? sat_uqq_type_node
: uqq_type_node
;
3768 if (mode
== UHQmode
)
3769 return unsignedp
? sat_uhq_type_node
: uhq_type_node
;
3770 if (mode
== USQmode
)
3771 return unsignedp
? sat_usq_type_node
: usq_type_node
;
3772 if (mode
== UDQmode
)
3773 return unsignedp
? sat_udq_type_node
: udq_type_node
;
3774 if (mode
== UTQmode
)
3775 return unsignedp
? sat_utq_type_node
: utq_type_node
;
3778 return unsignedp
? sat_ha_type_node
: ha_type_node
;
3780 return unsignedp
? sat_sa_type_node
: sa_type_node
;
3782 return unsignedp
? sat_da_type_node
: da_type_node
;
3784 return unsignedp
? sat_ta_type_node
: ta_type_node
;
3786 if (mode
== UHAmode
)
3787 return unsignedp
? sat_uha_type_node
: uha_type_node
;
3788 if (mode
== USAmode
)
3789 return unsignedp
? sat_usa_type_node
: usa_type_node
;
3790 if (mode
== UDAmode
)
3791 return unsignedp
? sat_uda_type_node
: uda_type_node
;
3792 if (mode
== UTAmode
)
3793 return unsignedp
? sat_uta_type_node
: uta_type_node
;
3796 for (t
= registered_builtin_types
; t
; t
= TREE_CHAIN (t
))
3797 if (TYPE_MODE (TREE_VALUE (t
)) == mode
3798 && !!unsignedp
== !!TYPE_UNSIGNED (TREE_VALUE (t
)))
3799 return TREE_VALUE (t
);
3805 c_common_unsigned_type (tree type
)
3807 return c_common_signed_or_unsigned_type (1, type
);
3810 /* Return a signed type the same as TYPE in other respects. */
3813 c_common_signed_type (tree type
)
3815 return c_common_signed_or_unsigned_type (0, type
);
3818 /* Return a type the same as TYPE except unsigned or
3819 signed according to UNSIGNEDP. */
3822 c_common_signed_or_unsigned_type (int unsignedp
, tree type
)
3827 /* This block of code emulates the behavior of the old
3828 c_common_unsigned_type. In particular, it returns
3829 long_unsigned_type_node if passed a long, even when a int would
3830 have the same size. This is necessary for warnings to work
3831 correctly in archs where sizeof(int) == sizeof(long) */
3833 type1
= TYPE_MAIN_VARIANT (type
);
3834 if (type1
== signed_char_type_node
|| type1
== char_type_node
|| type1
== unsigned_char_type_node
)
3835 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3836 if (type1
== integer_type_node
|| type1
== unsigned_type_node
)
3837 return unsignedp
? unsigned_type_node
: integer_type_node
;
3838 if (type1
== short_integer_type_node
|| type1
== short_unsigned_type_node
)
3839 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3840 if (type1
== long_integer_type_node
|| type1
== long_unsigned_type_node
)
3841 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3842 if (type1
== long_long_integer_type_node
|| type1
== long_long_unsigned_type_node
)
3843 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3845 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
3846 if (int_n_enabled_p
[i
]
3847 && (type1
== int_n_trees
[i
].unsigned_type
3848 || type1
== int_n_trees
[i
].signed_type
))
3849 return (unsignedp
? int_n_trees
[i
].unsigned_type
3850 : int_n_trees
[i
].signed_type
);
3852 if (type1
== widest_integer_literal_type_node
|| type1
== widest_unsigned_literal_type_node
)
3853 return unsignedp
? widest_unsigned_literal_type_node
: widest_integer_literal_type_node
;
3854 #if HOST_BITS_PER_WIDE_INT >= 64
3855 if (type1
== intTI_type_node
|| type1
== unsigned_intTI_type_node
)
3856 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3858 if (type1
== intDI_type_node
|| type1
== unsigned_intDI_type_node
)
3859 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3860 if (type1
== intSI_type_node
|| type1
== unsigned_intSI_type_node
)
3861 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3862 if (type1
== intHI_type_node
|| type1
== unsigned_intHI_type_node
)
3863 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3864 if (type1
== intQI_type_node
|| type1
== unsigned_intQI_type_node
)
3865 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3867 #define C_COMMON_FIXED_TYPES(NAME) \
3868 if (type1 == short_ ## NAME ## _type_node \
3869 || type1 == unsigned_short_ ## NAME ## _type_node) \
3870 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
3871 : short_ ## NAME ## _type_node; \
3872 if (type1 == NAME ## _type_node \
3873 || type1 == unsigned_ ## NAME ## _type_node) \
3874 return unsignedp ? unsigned_ ## NAME ## _type_node \
3875 : NAME ## _type_node; \
3876 if (type1 == long_ ## NAME ## _type_node \
3877 || type1 == unsigned_long_ ## NAME ## _type_node) \
3878 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
3879 : long_ ## NAME ## _type_node; \
3880 if (type1 == long_long_ ## NAME ## _type_node \
3881 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
3882 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
3883 : long_long_ ## NAME ## _type_node;
3885 #define C_COMMON_FIXED_MODE_TYPES(NAME) \
3886 if (type1 == NAME ## _type_node \
3887 || type1 == u ## NAME ## _type_node) \
3888 return unsignedp ? u ## NAME ## _type_node \
3889 : NAME ## _type_node;
3891 #define C_COMMON_FIXED_TYPES_SAT(NAME) \
3892 if (type1 == sat_ ## short_ ## NAME ## _type_node \
3893 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
3894 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
3895 : sat_ ## short_ ## NAME ## _type_node; \
3896 if (type1 == sat_ ## NAME ## _type_node \
3897 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
3898 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
3899 : sat_ ## NAME ## _type_node; \
3900 if (type1 == sat_ ## long_ ## NAME ## _type_node \
3901 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
3902 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
3903 : sat_ ## long_ ## NAME ## _type_node; \
3904 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
3905 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
3906 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
3907 : sat_ ## long_long_ ## NAME ## _type_node;
3909 #define C_COMMON_FIXED_MODE_TYPES_SAT(NAME) \
3910 if (type1 == sat_ ## NAME ## _type_node \
3911 || type1 == sat_ ## u ## NAME ## _type_node) \
3912 return unsignedp ? sat_ ## u ## NAME ## _type_node \
3913 : sat_ ## NAME ## _type_node;
3915 C_COMMON_FIXED_TYPES (fract
);
3916 C_COMMON_FIXED_TYPES_SAT (fract
);
3917 C_COMMON_FIXED_TYPES (accum
);
3918 C_COMMON_FIXED_TYPES_SAT (accum
);
3920 C_COMMON_FIXED_MODE_TYPES (qq
);
3921 C_COMMON_FIXED_MODE_TYPES (hq
);
3922 C_COMMON_FIXED_MODE_TYPES (sq
);
3923 C_COMMON_FIXED_MODE_TYPES (dq
);
3924 C_COMMON_FIXED_MODE_TYPES (tq
);
3925 C_COMMON_FIXED_MODE_TYPES_SAT (qq
);
3926 C_COMMON_FIXED_MODE_TYPES_SAT (hq
);
3927 C_COMMON_FIXED_MODE_TYPES_SAT (sq
);
3928 C_COMMON_FIXED_MODE_TYPES_SAT (dq
);
3929 C_COMMON_FIXED_MODE_TYPES_SAT (tq
);
3930 C_COMMON_FIXED_MODE_TYPES (ha
);
3931 C_COMMON_FIXED_MODE_TYPES (sa
);
3932 C_COMMON_FIXED_MODE_TYPES (da
);
3933 C_COMMON_FIXED_MODE_TYPES (ta
);
3934 C_COMMON_FIXED_MODE_TYPES_SAT (ha
);
3935 C_COMMON_FIXED_MODE_TYPES_SAT (sa
);
3936 C_COMMON_FIXED_MODE_TYPES_SAT (da
);
3937 C_COMMON_FIXED_MODE_TYPES_SAT (ta
);
3939 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
3940 the precision; they have precision set to match their range, but
3941 may use a wider mode to match an ABI. If we change modes, we may
3942 wind up with bad conversions. For INTEGER_TYPEs in C, must check
3943 the precision as well, so as to yield correct results for
3944 bit-field types. C++ does not have these separate bit-field
3945 types, and producing a signed or unsigned variant of an
3946 ENUMERAL_TYPE may cause other problems as well. */
3948 if (!INTEGRAL_TYPE_P (type
)
3949 || TYPE_UNSIGNED (type
) == unsignedp
)
3952 #define TYPE_OK(node) \
3953 (TYPE_MODE (type) == TYPE_MODE (node) \
3954 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
3955 if (TYPE_OK (signed_char_type_node
))
3956 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3957 if (TYPE_OK (integer_type_node
))
3958 return unsignedp
? unsigned_type_node
: integer_type_node
;
3959 if (TYPE_OK (short_integer_type_node
))
3960 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3961 if (TYPE_OK (long_integer_type_node
))
3962 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3963 if (TYPE_OK (long_long_integer_type_node
))
3964 return (unsignedp
? long_long_unsigned_type_node
3965 : long_long_integer_type_node
);
3967 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
3968 if (int_n_enabled_p
[i
]
3969 && TYPE_MODE (type
) == int_n_data
[i
].m
3970 && TYPE_PRECISION (type
) == int_n_data
[i
].bitsize
)
3971 return (unsignedp
? int_n_trees
[i
].unsigned_type
3972 : int_n_trees
[i
].signed_type
);
3974 if (TYPE_OK (widest_integer_literal_type_node
))
3975 return (unsignedp
? widest_unsigned_literal_type_node
3976 : widest_integer_literal_type_node
);
3978 #if HOST_BITS_PER_WIDE_INT >= 64
3979 if (TYPE_OK (intTI_type_node
))
3980 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3982 if (TYPE_OK (intDI_type_node
))
3983 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3984 if (TYPE_OK (intSI_type_node
))
3985 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3986 if (TYPE_OK (intHI_type_node
))
3987 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3988 if (TYPE_OK (intQI_type_node
))
3989 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3992 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
3995 /* Build a bit-field integer type for the given WIDTH and UNSIGNEDP. */
3998 c_build_bitfield_integer_type (unsigned HOST_WIDE_INT width
, int unsignedp
)
4002 /* Extended integer types of the same width as a standard type have
4003 lesser rank, so those of the same width as int promote to int or
4004 unsigned int and are valid for printf formats expecting int or
4005 unsigned int. To avoid such special cases, avoid creating
4006 extended integer types for bit-fields if a standard integer type
4008 if (width
== TYPE_PRECISION (integer_type_node
))
4009 return unsignedp
? unsigned_type_node
: integer_type_node
;
4010 if (width
== TYPE_PRECISION (signed_char_type_node
))
4011 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
4012 if (width
== TYPE_PRECISION (short_integer_type_node
))
4013 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
4014 if (width
== TYPE_PRECISION (long_integer_type_node
))
4015 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
4016 if (width
== TYPE_PRECISION (long_long_integer_type_node
))
4017 return (unsignedp
? long_long_unsigned_type_node
4018 : long_long_integer_type_node
);
4019 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
4020 if (int_n_enabled_p
[i
]
4021 && width
== int_n_data
[i
].bitsize
)
4022 return (unsignedp
? int_n_trees
[i
].unsigned_type
4023 : int_n_trees
[i
].signed_type
);
4024 return build_nonstandard_integer_type (width
, unsignedp
);
4027 /* The C version of the register_builtin_type langhook. */
4030 c_register_builtin_type (tree type
, const char* name
)
4034 decl
= build_decl (UNKNOWN_LOCATION
,
4035 TYPE_DECL
, get_identifier (name
), type
);
4036 DECL_ARTIFICIAL (decl
) = 1;
4037 if (!TYPE_NAME (type
))
4038 TYPE_NAME (type
) = decl
;
4041 registered_builtin_types
= tree_cons (0, type
, registered_builtin_types
);
4044 /* Print an error message for invalid operands to arith operation
4045 CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
4046 LOCATION is the location of the message. */
4049 binary_op_error (location_t location
, enum tree_code code
,
4050 tree type0
, tree type1
)
4057 opname
= "+"; break;
4059 opname
= "-"; break;
4061 opname
= "*"; break;
4063 opname
= "max"; break;
4065 opname
= "min"; break;
4067 opname
= "=="; break;
4069 opname
= "!="; break;
4071 opname
= "<="; break;
4073 opname
= ">="; break;
4075 opname
= "<"; break;
4077 opname
= ">"; break;
4079 opname
= "<<"; break;
4081 opname
= ">>"; break;
4082 case TRUNC_MOD_EXPR
:
4083 case FLOOR_MOD_EXPR
:
4084 opname
= "%"; break;
4085 case TRUNC_DIV_EXPR
:
4086 case FLOOR_DIV_EXPR
:
4087 opname
= "/"; break;
4089 opname
= "&"; break;
4091 opname
= "|"; break;
4092 case TRUTH_ANDIF_EXPR
:
4093 opname
= "&&"; break;
4094 case TRUTH_ORIF_EXPR
:
4095 opname
= "||"; break;
4097 opname
= "^"; break;
4102 "invalid operands to binary %s (have %qT and %qT)", opname
,
4106 /* Given an expression as a tree, return its original type. Do this
4107 by stripping any conversion that preserves the sign and precision. */
4109 expr_original_type (tree expr
)
4111 STRIP_SIGN_NOPS (expr
);
4112 return TREE_TYPE (expr
);
4115 /* Subroutine of build_binary_op, used for comparison operations.
4116 See if the operands have both been converted from subword integer types
4117 and, if so, perhaps change them both back to their original type.
4118 This function is also responsible for converting the two operands
4119 to the proper common type for comparison.
4121 The arguments of this function are all pointers to local variables
4122 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
4123 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
4125 LOC is the location of the comparison.
4127 If this function returns nonzero, it means that the comparison has
4128 a constant value. What this function returns is an expression for
4132 shorten_compare (location_t loc
, tree
*op0_ptr
, tree
*op1_ptr
,
4133 tree
*restype_ptr
, enum tree_code
*rescode_ptr
)
4136 tree op0
= *op0_ptr
;
4137 tree op1
= *op1_ptr
;
4138 int unsignedp0
, unsignedp1
;
4140 tree primop0
, primop1
;
4141 enum tree_code code
= *rescode_ptr
;
4143 /* Throw away any conversions to wider types
4144 already present in the operands. */
4146 primop0
= c_common_get_narrower (op0
, &unsignedp0
);
4147 primop1
= c_common_get_narrower (op1
, &unsignedp1
);
4149 /* If primopN is first sign-extended from primopN's precision to opN's
4150 precision, then zero-extended from opN's precision to
4151 *restype_ptr precision, shortenings might be invalid. */
4152 if (TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (TREE_TYPE (op0
))
4153 && TYPE_PRECISION (TREE_TYPE (op0
)) < TYPE_PRECISION (*restype_ptr
)
4155 && TYPE_UNSIGNED (TREE_TYPE (op0
)))
4157 if (TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (TREE_TYPE (op1
))
4158 && TYPE_PRECISION (TREE_TYPE (op1
)) < TYPE_PRECISION (*restype_ptr
)
4160 && TYPE_UNSIGNED (TREE_TYPE (op1
)))
4163 /* Handle the case that OP0 does not *contain* a conversion
4164 but it *requires* conversion to FINAL_TYPE. */
4166 if (op0
== primop0
&& TREE_TYPE (op0
) != *restype_ptr
)
4167 unsignedp0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
4168 if (op1
== primop1
&& TREE_TYPE (op1
) != *restype_ptr
)
4169 unsignedp1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
4171 /* If one of the operands must be floated, we cannot optimize. */
4172 real1
= TREE_CODE (TREE_TYPE (primop0
)) == REAL_TYPE
;
4173 real2
= TREE_CODE (TREE_TYPE (primop1
)) == REAL_TYPE
;
4175 /* If first arg is constant, swap the args (changing operation
4176 so value is preserved), for canonicalization. Don't do this if
4177 the second arg is 0. */
4179 if (TREE_CONSTANT (primop0
)
4180 && !integer_zerop (primop1
) && !real_zerop (primop1
)
4181 && !fixed_zerop (primop1
))
4184 int temi
= unsignedp0
;
4192 unsignedp0
= unsignedp1
;
4215 *rescode_ptr
= code
;
4218 /* If comparing an integer against a constant more bits wide,
4219 maybe we can deduce a value of 1 or 0 independent of the data.
4220 Or else truncate the constant now
4221 rather than extend the variable at run time.
4223 This is only interesting if the constant is the wider arg.
4224 Also, it is not safe if the constant is unsigned and the
4225 variable arg is signed, since in this case the variable
4226 would be sign-extended and then regarded as unsigned.
4227 Our technique fails in this case because the lowest/highest
4228 possible unsigned results don't follow naturally from the
4229 lowest/highest possible values of the variable operand.
4230 For just EQ_EXPR and NE_EXPR there is another technique that
4231 could be used: see if the constant can be faithfully represented
4232 in the other operand's type, by truncating it and reextending it
4233 and see if that preserves the constant's value. */
4235 if (!real1
&& !real2
4236 && TREE_CODE (TREE_TYPE (primop0
)) != FIXED_POINT_TYPE
4237 && TREE_CODE (primop1
) == INTEGER_CST
4238 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
))
4240 int min_gt
, max_gt
, min_lt
, max_lt
;
4241 tree maxval
, minval
;
4242 /* 1 if comparison is nominally unsigned. */
4243 int unsignedp
= TYPE_UNSIGNED (*restype_ptr
);
4246 type
= c_common_signed_or_unsigned_type (unsignedp0
,
4247 TREE_TYPE (primop0
));
4249 maxval
= TYPE_MAX_VALUE (type
);
4250 minval
= TYPE_MIN_VALUE (type
);
4252 if (unsignedp
&& !unsignedp0
)
4253 *restype_ptr
= c_common_signed_type (*restype_ptr
);
4255 if (TREE_TYPE (primop1
) != *restype_ptr
)
4257 /* Convert primop1 to target type, but do not introduce
4258 additional overflow. We know primop1 is an int_cst. */
4259 primop1
= force_fit_type (*restype_ptr
,
4262 TYPE_PRECISION (*restype_ptr
),
4263 TYPE_SIGN (TREE_TYPE (primop1
))),
4264 0, TREE_OVERFLOW (primop1
));
4266 if (type
!= *restype_ptr
)
4268 minval
= convert (*restype_ptr
, minval
);
4269 maxval
= convert (*restype_ptr
, maxval
);
4272 min_gt
= tree_int_cst_lt (primop1
, minval
);
4273 max_gt
= tree_int_cst_lt (primop1
, maxval
);
4274 min_lt
= tree_int_cst_lt (minval
, primop1
);
4275 max_lt
= tree_int_cst_lt (maxval
, primop1
);
4278 /* This used to be a switch, but Genix compiler can't handle that. */
4279 if (code
== NE_EXPR
)
4281 if (max_lt
|| min_gt
)
4282 val
= truthvalue_true_node
;
4284 else if (code
== EQ_EXPR
)
4286 if (max_lt
|| min_gt
)
4287 val
= truthvalue_false_node
;
4289 else if (code
== LT_EXPR
)
4292 val
= truthvalue_true_node
;
4294 val
= truthvalue_false_node
;
4296 else if (code
== GT_EXPR
)
4299 val
= truthvalue_true_node
;
4301 val
= truthvalue_false_node
;
4303 else if (code
== LE_EXPR
)
4306 val
= truthvalue_true_node
;
4308 val
= truthvalue_false_node
;
4310 else if (code
== GE_EXPR
)
4313 val
= truthvalue_true_node
;
4315 val
= truthvalue_false_node
;
4318 /* If primop0 was sign-extended and unsigned comparison specd,
4319 we did a signed comparison above using the signed type bounds.
4320 But the comparison we output must be unsigned.
4322 Also, for inequalities, VAL is no good; but if the signed
4323 comparison had *any* fixed result, it follows that the
4324 unsigned comparison just tests the sign in reverse
4325 (positive values are LE, negative ones GE).
4326 So we can generate an unsigned comparison
4327 against an extreme value of the signed type. */
4329 if (unsignedp
&& !unsignedp0
)
4336 primop1
= TYPE_MIN_VALUE (type
);
4342 primop1
= TYPE_MAX_VALUE (type
);
4349 type
= c_common_unsigned_type (type
);
4352 if (TREE_CODE (primop0
) != INTEGER_CST
)
4354 if (val
== truthvalue_false_node
)
4355 warning_at (loc
, OPT_Wtype_limits
,
4356 "comparison is always false due to limited range of data type");
4357 if (val
== truthvalue_true_node
)
4358 warning_at (loc
, OPT_Wtype_limits
,
4359 "comparison is always true due to limited range of data type");
4364 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4365 if (TREE_SIDE_EFFECTS (primop0
))
4366 return build2 (COMPOUND_EXPR
, TREE_TYPE (val
), primop0
, val
);
4370 /* Value is not predetermined, but do the comparison
4371 in the type of the operand that is not constant.
4372 TYPE is already properly set. */
4375 /* If either arg is decimal float and the other is float, find the
4376 proper common type to use for comparison. */
4377 else if (real1
&& real2
4378 && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0
)))
4379 && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1
))))
4380 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
4382 /* If either arg is decimal float and the other is float, fail. */
4383 else if (real1
&& real2
4384 && (DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0
)))
4385 || DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1
)))))
4388 else if (real1
&& real2
4389 && (TYPE_PRECISION (TREE_TYPE (primop0
))
4390 == TYPE_PRECISION (TREE_TYPE (primop1
))))
4391 type
= TREE_TYPE (primop0
);
4393 /* If args' natural types are both narrower than nominal type
4394 and both extend in the same manner, compare them
4395 in the type of the wider arg.
4396 Otherwise must actually extend both to the nominal
4397 common type lest different ways of extending
4399 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
4401 else if (unsignedp0
== unsignedp1
&& real1
== real2
4402 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
)
4403 && TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (*restype_ptr
))
4405 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
4406 type
= c_common_signed_or_unsigned_type (unsignedp0
4407 || TYPE_UNSIGNED (*restype_ptr
),
4409 /* Make sure shorter operand is extended the right way
4410 to match the longer operand. */
4412 = convert (c_common_signed_or_unsigned_type (unsignedp0
,
4413 TREE_TYPE (primop0
)),
4416 = convert (c_common_signed_or_unsigned_type (unsignedp1
,
4417 TREE_TYPE (primop1
)),
4422 /* Here we must do the comparison on the nominal type
4423 using the args exactly as we received them. */
4424 type
= *restype_ptr
;
4428 if (!real1
&& !real2
&& integer_zerop (primop1
)
4429 && TYPE_UNSIGNED (*restype_ptr
))
4432 /* All unsigned values are >= 0, so we warn. However,
4433 if OP0 is a constant that is >= 0, the signedness of
4434 the comparison isn't an issue, so suppress the
4437 warn_type_limits
&& !in_system_header_at (loc
)
4438 && !(TREE_CODE (primop0
) == INTEGER_CST
4439 && !TREE_OVERFLOW (convert (c_common_signed_type (type
),
4441 /* Do not warn for enumeration types. */
4442 && (TREE_CODE (expr_original_type (primop0
)) != ENUMERAL_TYPE
);
4448 warning_at (loc
, OPT_Wtype_limits
,
4449 "comparison of unsigned expression >= 0 is always true");
4450 value
= truthvalue_true_node
;
4455 warning_at (loc
, OPT_Wtype_limits
,
4456 "comparison of unsigned expression < 0 is always false");
4457 value
= truthvalue_false_node
;
4466 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4467 if (TREE_SIDE_EFFECTS (primop0
))
4468 return build2 (COMPOUND_EXPR
, TREE_TYPE (value
),
4475 *op0_ptr
= convert (type
, primop0
);
4476 *op1_ptr
= convert (type
, primop1
);
4478 *restype_ptr
= truthvalue_type_node
;
4483 /* Return a tree for the sum or difference (RESULTCODE says which)
4484 of pointer PTROP and integer INTOP. */
4487 pointer_int_sum (location_t loc
, enum tree_code resultcode
,
4488 tree ptrop
, tree intop
, bool complain
)
4492 /* The result is a pointer of the same type that is being added. */
4493 tree result_type
= TREE_TYPE (ptrop
);
4495 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
4497 if (complain
&& warn_pointer_arith
)
4498 pedwarn (loc
, OPT_Wpointer_arith
,
4499 "pointer of type %<void *%> used in arithmetic");
4501 return error_mark_node
;
4502 size_exp
= integer_one_node
;
4504 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
4506 if (complain
&& warn_pointer_arith
)
4507 pedwarn (loc
, OPT_Wpointer_arith
,
4508 "pointer to a function used in arithmetic");
4510 return error_mark_node
;
4511 size_exp
= integer_one_node
;
4514 size_exp
= size_in_bytes (TREE_TYPE (result_type
));
4516 /* We are manipulating pointer values, so we don't need to warn
4517 about relying on undefined signed overflow. We disable the
4518 warning here because we use integer types so fold won't know that
4519 they are really pointers. */
4520 fold_defer_overflow_warnings ();
4522 /* If what we are about to multiply by the size of the elements
4523 contains a constant term, apply distributive law
4524 and multiply that constant term separately.
4525 This helps produce common subexpressions. */
4526 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
4527 && !TREE_CONSTANT (intop
)
4528 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
4529 && TREE_CONSTANT (size_exp
)
4530 /* If the constant comes from pointer subtraction,
4531 skip this optimization--it would cause an error. */
4532 && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop
, 0))) == INTEGER_TYPE
4533 /* If the constant is unsigned, and smaller than the pointer size,
4534 then we must skip this optimization. This is because it could cause
4535 an overflow error if the constant is negative but INTOP is not. */
4536 && (!TYPE_UNSIGNED (TREE_TYPE (intop
))
4537 || (TYPE_PRECISION (TREE_TYPE (intop
))
4538 == TYPE_PRECISION (TREE_TYPE (ptrop
)))))
4540 enum tree_code subcode
= resultcode
;
4541 tree int_type
= TREE_TYPE (intop
);
4542 if (TREE_CODE (intop
) == MINUS_EXPR
)
4543 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
4544 /* Convert both subexpression types to the type of intop,
4545 because weird cases involving pointer arithmetic
4546 can result in a sum or difference with different type args. */
4547 ptrop
= build_binary_op (EXPR_LOCATION (TREE_OPERAND (intop
, 1)),
4549 convert (int_type
, TREE_OPERAND (intop
, 1)), 1);
4550 intop
= convert (int_type
, TREE_OPERAND (intop
, 0));
4553 /* Convert the integer argument to a type the same size as sizetype
4554 so the multiply won't overflow spuriously. */
4555 if (TYPE_PRECISION (TREE_TYPE (intop
)) != TYPE_PRECISION (sizetype
)
4556 || TYPE_UNSIGNED (TREE_TYPE (intop
)) != TYPE_UNSIGNED (sizetype
))
4557 intop
= convert (c_common_type_for_size (TYPE_PRECISION (sizetype
),
4558 TYPE_UNSIGNED (sizetype
)), intop
);
4560 /* Replace the integer argument with a suitable product by the object size.
4561 Do this multiplication as signed, then convert to the appropriate type
4562 for the pointer operation and disregard an overflow that occurred only
4563 because of the sign-extension change in the latter conversion. */
4565 tree t
= build_binary_op (loc
,
4567 convert (TREE_TYPE (intop
), size_exp
), 1);
4568 intop
= convert (sizetype
, t
);
4569 if (TREE_OVERFLOW_P (intop
) && !TREE_OVERFLOW (t
))
4570 intop
= wide_int_to_tree (TREE_TYPE (intop
), intop
);
4573 /* Create the sum or difference. */
4574 if (resultcode
== MINUS_EXPR
)
4575 intop
= fold_build1_loc (loc
, NEGATE_EXPR
, sizetype
, intop
);
4577 ret
= fold_build_pointer_plus_loc (loc
, ptrop
, intop
);
4579 fold_undefer_and_ignore_overflow_warnings ();
4584 /* Wrap a C_MAYBE_CONST_EXPR around an expression that is fully folded
4585 and if NON_CONST is known not to be permitted in an evaluated part
4586 of a constant expression. */
4589 c_wrap_maybe_const (tree expr
, bool non_const
)
4591 bool nowarning
= TREE_NO_WARNING (expr
);
4592 location_t loc
= EXPR_LOCATION (expr
);
4594 /* This should never be called for C++. */
4595 if (c_dialect_cxx ())
4598 /* The result of folding may have a NOP_EXPR to set TREE_NO_WARNING. */
4599 STRIP_TYPE_NOPS (expr
);
4600 expr
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (expr
), NULL
, expr
);
4601 C_MAYBE_CONST_EXPR_NON_CONST (expr
) = non_const
;
4603 TREE_NO_WARNING (expr
) = 1;
4604 protected_set_expr_location (expr
, loc
);
4609 /* Wrap a SAVE_EXPR around EXPR, if appropriate. Like save_expr, but
4610 for C folds the inside expression and wraps a C_MAYBE_CONST_EXPR
4611 around the SAVE_EXPR if needed so that c_fully_fold does not need
4612 to look inside SAVE_EXPRs. */
4615 c_save_expr (tree expr
)
4617 bool maybe_const
= true;
4618 if (c_dialect_cxx ())
4619 return save_expr (expr
);
4620 expr
= c_fully_fold (expr
, false, &maybe_const
);
4621 expr
= save_expr (expr
);
4623 expr
= c_wrap_maybe_const (expr
, true);
4627 /* Return whether EXPR is a declaration whose address can never be
4631 decl_with_nonnull_addr_p (const_tree expr
)
4633 return (DECL_P (expr
)
4634 && (TREE_CODE (expr
) == PARM_DECL
4635 || TREE_CODE (expr
) == LABEL_DECL
4636 || !DECL_WEAK (expr
)));
4639 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
4640 or for an `if' or `while' statement or ?..: exp. It should already
4641 have been validated to be of suitable type; otherwise, a bad
4642 diagnostic may result.
4644 The EXPR is located at LOCATION.
4646 This preparation consists of taking the ordinary
4647 representation of an expression expr and producing a valid tree
4648 boolean expression describing whether expr is nonzero. We could
4649 simply always do build_binary_op (NE_EXPR, expr, truthvalue_false_node, 1),
4650 but we optimize comparisons, &&, ||, and !.
4652 The resulting type should always be `truthvalue_type_node'. */
4655 c_common_truthvalue_conversion (location_t location
, tree expr
)
4657 switch (TREE_CODE (expr
))
4659 case EQ_EXPR
: case NE_EXPR
: case UNEQ_EXPR
: case LTGT_EXPR
:
4660 case LE_EXPR
: case GE_EXPR
: case LT_EXPR
: case GT_EXPR
:
4661 case UNLE_EXPR
: case UNGE_EXPR
: case UNLT_EXPR
: case UNGT_EXPR
:
4662 case ORDERED_EXPR
: case UNORDERED_EXPR
:
4663 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4665 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4666 TREE_OPERAND (expr
, 0), TREE_OPERAND (expr
, 1));
4669 case TRUTH_ANDIF_EXPR
:
4670 case TRUTH_ORIF_EXPR
:
4671 case TRUTH_AND_EXPR
:
4673 case TRUTH_XOR_EXPR
:
4674 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4676 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4677 c_common_truthvalue_conversion (location
,
4678 TREE_OPERAND (expr
, 0)),
4679 c_common_truthvalue_conversion (location
,
4680 TREE_OPERAND (expr
, 1)));
4683 case TRUTH_NOT_EXPR
:
4684 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4686 expr
= build1 (TREE_CODE (expr
), truthvalue_type_node
,
4687 c_common_truthvalue_conversion (location
,
4688 TREE_OPERAND (expr
, 0)));
4695 return integer_zerop (expr
) ? truthvalue_false_node
4696 : truthvalue_true_node
;
4699 return real_compare (NE_EXPR
, &TREE_REAL_CST (expr
), &dconst0
)
4700 ? truthvalue_true_node
4701 : truthvalue_false_node
;
4704 return fixed_compare (NE_EXPR
, &TREE_FIXED_CST (expr
),
4705 &FCONST0 (TYPE_MODE (TREE_TYPE (expr
))))
4706 ? truthvalue_true_node
4707 : truthvalue_false_node
;
4710 expr
= build_unary_op (location
, ADDR_EXPR
, expr
, 0);
4715 tree inner
= TREE_OPERAND (expr
, 0);
4716 if (decl_with_nonnull_addr_p (inner
))
4718 /* Common Ada/Pascal programmer's mistake. */
4719 warning_at (location
,
4721 "the address of %qD will always evaluate as %<true%>",
4723 return truthvalue_true_node
;
4729 expr
= build_binary_op (EXPR_LOCATION (expr
),
4730 (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1))
4731 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4732 c_common_truthvalue_conversion (location
,
4733 TREE_OPERAND (expr
, 0)),
4734 c_common_truthvalue_conversion (location
,
4735 TREE_OPERAND (expr
, 1)),
4742 case EXCESS_PRECISION_EXPR
:
4743 /* These don't change whether an object is nonzero or zero. */
4744 return c_common_truthvalue_conversion (location
, TREE_OPERAND (expr
, 0));
4748 /* These don't change whether an object is zero or nonzero, but
4749 we can't ignore them if their second arg has side-effects. */
4750 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1)))
4752 expr
= build2 (COMPOUND_EXPR
, truthvalue_type_node
,
4753 TREE_OPERAND (expr
, 1),
4754 c_common_truthvalue_conversion
4755 (location
, TREE_OPERAND (expr
, 0)));
4759 return c_common_truthvalue_conversion (location
,
4760 TREE_OPERAND (expr
, 0));
4763 /* Distribute the conversion into the arms of a COND_EXPR. */
4764 if (c_dialect_cxx ())
4766 tree op1
= TREE_OPERAND (expr
, 1);
4767 tree op2
= TREE_OPERAND (expr
, 2);
4768 /* In C++ one of the arms might have void type if it is throw. */
4769 if (!VOID_TYPE_P (TREE_TYPE (op1
)))
4770 op1
= c_common_truthvalue_conversion (location
, op1
);
4771 if (!VOID_TYPE_P (TREE_TYPE (op2
)))
4772 op2
= c_common_truthvalue_conversion (location
, op2
);
4773 expr
= fold_build3_loc (location
, COND_EXPR
, truthvalue_type_node
,
4774 TREE_OPERAND (expr
, 0), op1
, op2
);
4779 /* Folding will happen later for C. */
4780 expr
= build3 (COND_EXPR
, truthvalue_type_node
,
4781 TREE_OPERAND (expr
, 0),
4782 c_common_truthvalue_conversion (location
,
4783 TREE_OPERAND (expr
, 1)),
4784 c_common_truthvalue_conversion (location
,
4785 TREE_OPERAND (expr
, 2)));
4791 tree totype
= TREE_TYPE (expr
);
4792 tree fromtype
= TREE_TYPE (TREE_OPERAND (expr
, 0));
4794 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
4795 since that affects how `default_conversion' will behave. */
4796 if (TREE_CODE (totype
) == REFERENCE_TYPE
4797 || TREE_CODE (fromtype
) == REFERENCE_TYPE
)
4799 /* Don't strip a conversion from C++0x scoped enum, since they
4800 don't implicitly convert to other types. */
4801 if (TREE_CODE (fromtype
) == ENUMERAL_TYPE
4802 && ENUM_IS_SCOPED (fromtype
))
4804 /* If this isn't narrowing the argument, we can ignore it. */
4805 if (TYPE_PRECISION (totype
) >= TYPE_PRECISION (fromtype
))
4806 return c_common_truthvalue_conversion (location
,
4807 TREE_OPERAND (expr
, 0));
4812 if (!TREE_NO_WARNING (expr
)
4813 && warn_parentheses
)
4815 warning (OPT_Wparentheses
,
4816 "suggest parentheses around assignment used as truth value");
4817 TREE_NO_WARNING (expr
) = 1;
4825 if (TREE_CODE (TREE_TYPE (expr
)) == COMPLEX_TYPE
)
4827 tree t
= (in_late_binary_op
? save_expr (expr
) : c_save_expr (expr
));
4828 expr
= (build_binary_op
4829 (EXPR_LOCATION (expr
),
4830 (TREE_SIDE_EFFECTS (expr
)
4831 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4832 c_common_truthvalue_conversion
4834 build_unary_op (location
, REALPART_EXPR
, t
, 0)),
4835 c_common_truthvalue_conversion
4837 build_unary_op (location
, IMAGPART_EXPR
, t
, 0)),
4842 if (TREE_CODE (TREE_TYPE (expr
)) == FIXED_POINT_TYPE
)
4844 tree fixed_zero_node
= build_fixed (TREE_TYPE (expr
),
4846 (TREE_TYPE (expr
))));
4847 return build_binary_op (location
, NE_EXPR
, expr
, fixed_zero_node
, 1);
4850 return build_binary_op (location
, NE_EXPR
, expr
, integer_zero_node
, 1);
4853 protected_set_expr_location (expr
, location
);
4857 static void def_builtin_1 (enum built_in_function fncode
,
4859 enum built_in_class fnclass
,
4860 tree fntype
, tree libtype
,
4861 bool both_p
, bool fallback_p
, bool nonansi_p
,
4862 tree fnattrs
, bool implicit_p
);
4865 /* Apply the TYPE_QUALS to the new DECL. */
4868 c_apply_type_quals_to_decl (int type_quals
, tree decl
)
4870 tree type
= TREE_TYPE (decl
);
4872 if (type
== error_mark_node
)
4875 if ((type_quals
& TYPE_QUAL_CONST
)
4876 || (type
&& TREE_CODE (type
) == REFERENCE_TYPE
))
4877 /* We used to check TYPE_NEEDS_CONSTRUCTING here, but now a constexpr
4878 constructor can produce constant init, so rely on cp_finish_decl to
4879 clear TREE_READONLY if the variable has non-constant init. */
4880 TREE_READONLY (decl
) = 1;
4881 if (type_quals
& TYPE_QUAL_VOLATILE
)
4883 TREE_SIDE_EFFECTS (decl
) = 1;
4884 TREE_THIS_VOLATILE (decl
) = 1;
4886 if (type_quals
& TYPE_QUAL_RESTRICT
)
4888 while (type
&& TREE_CODE (type
) == ARRAY_TYPE
)
4889 /* Allow 'restrict' on arrays of pointers.
4890 FIXME currently we just ignore it. */
4891 type
= TREE_TYPE (type
);
4893 || !POINTER_TYPE_P (type
)
4894 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type
)))
4895 error ("invalid use of %<restrict%>");
4899 struct c_type_hasher
: ggc_hasher
<tree
>
4901 static hashval_t
hash (tree
);
4902 static bool equal (tree
, tree
);
4905 /* Hash function for the problem of multiple type definitions in
4906 different files. This must hash all types that will compare
4907 equal via comptypes to the same value. In practice it hashes
4908 on some of the simple stuff and leaves the details to comptypes. */
4911 c_type_hasher::hash (tree t
)
4916 switch (TREE_CODE (t
))
4918 /* For pointers, hash on pointee type plus some swizzling. */
4920 return hash (TREE_TYPE (t
)) ^ 0x3003003;
4921 /* Hash on number of elements and total size. */
4924 t2
= TYPE_VALUES (t
);
4928 t2
= TYPE_FIELDS (t
);
4930 case QUAL_UNION_TYPE
:
4932 t2
= TYPE_FIELDS (t
);
4936 t2
= TYPE_FIELDS (t
);
4941 /* FIXME: We want to use a DECL_CHAIN iteration method here, but
4942 TYPE_VALUES of ENUMERAL_TYPEs is stored as a TREE_LIST. */
4943 n_elements
= list_length (t2
);
4944 /* We might have a VLA here. */
4945 if (TREE_CODE (TYPE_SIZE (t
)) != INTEGER_CST
)
4948 size
= TREE_INT_CST_LOW (TYPE_SIZE (t
));
4949 return ((size
<< 24) | (n_elements
<< shift
));
4953 c_type_hasher::equal (tree t1
, tree t2
)
4955 return lang_hooks
.types_compatible_p (t1
, t2
);
4958 static GTY(()) hash_table
<c_type_hasher
> *type_hash_table
;
4960 /* Return the typed-based alias set for T, which may be an expression
4961 or a type. Return -1 if we don't do anything special. */
4964 c_common_get_alias_set (tree t
)
4968 /* For VLAs, use the alias set of the element type rather than the
4969 default of alias set 0 for types compared structurally. */
4970 if (TYPE_P (t
) && TYPE_STRUCTURAL_EQUALITY_P (t
))
4972 if (TREE_CODE (t
) == ARRAY_TYPE
)
4973 return get_alias_set (TREE_TYPE (t
));
4977 /* Permit type-punning when accessing a union, provided the access
4978 is directly through the union. For example, this code does not
4979 permit taking the address of a union member and then storing
4980 through it. Even the type-punning allowed here is a GCC
4981 extension, albeit a common and useful one; the C standard says
4982 that such accesses have implementation-defined behavior. */
4984 TREE_CODE (u
) == COMPONENT_REF
|| TREE_CODE (u
) == ARRAY_REF
;
4985 u
= TREE_OPERAND (u
, 0))
4986 if (TREE_CODE (u
) == COMPONENT_REF
4987 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u
, 0))) == UNION_TYPE
)
4990 /* That's all the expressions we handle specially. */
4994 /* The C standard guarantees that any object may be accessed via an
4995 lvalue that has character type. */
4996 if (t
== char_type_node
4997 || t
== signed_char_type_node
4998 || t
== unsigned_char_type_node
)
5001 /* The C standard specifically allows aliasing between signed and
5002 unsigned variants of the same type. We treat the signed
5003 variant as canonical. */
5004 if (TREE_CODE (t
) == INTEGER_TYPE
&& TYPE_UNSIGNED (t
))
5006 tree t1
= c_common_signed_type (t
);
5008 /* t1 == t can happen for boolean nodes which are always unsigned. */
5010 return get_alias_set (t1
);
5013 /* Handle the case of multiple type nodes referring to "the same" type,
5014 which occurs with IMA. These share an alias set. FIXME: Currently only
5015 C90 is handled. (In C99 type compatibility is not transitive, which
5016 complicates things mightily. The alias set splay trees can theoretically
5017 represent this, but insertion is tricky when you consider all the
5018 different orders things might arrive in.) */
5020 if (c_language
!= clk_c
|| flag_isoc99
)
5023 /* Save time if there's only one input file. */
5024 if (num_in_fnames
== 1)
5027 /* Pointers need special handling if they point to any type that
5028 needs special handling (below). */
5029 if (TREE_CODE (t
) == POINTER_TYPE
)
5032 /* Find bottom type under any nested POINTERs. */
5033 for (t2
= TREE_TYPE (t
);
5034 TREE_CODE (t2
) == POINTER_TYPE
;
5035 t2
= TREE_TYPE (t2
))
5037 if (TREE_CODE (t2
) != RECORD_TYPE
5038 && TREE_CODE (t2
) != ENUMERAL_TYPE
5039 && TREE_CODE (t2
) != QUAL_UNION_TYPE
5040 && TREE_CODE (t2
) != UNION_TYPE
)
5042 if (TYPE_SIZE (t2
) == 0)
5045 /* These are the only cases that need special handling. */
5046 if (TREE_CODE (t
) != RECORD_TYPE
5047 && TREE_CODE (t
) != ENUMERAL_TYPE
5048 && TREE_CODE (t
) != QUAL_UNION_TYPE
5049 && TREE_CODE (t
) != UNION_TYPE
5050 && TREE_CODE (t
) != POINTER_TYPE
)
5053 if (TYPE_SIZE (t
) == 0)
5056 /* Look up t in hash table. Only one of the compatible types within each
5057 alias set is recorded in the table. */
5058 if (!type_hash_table
)
5059 type_hash_table
= hash_table
<c_type_hasher
>::create_ggc (1021);
5060 tree
*slot
= type_hash_table
->find_slot (t
, INSERT
);
5063 TYPE_ALIAS_SET (t
) = TYPE_ALIAS_SET ((tree
)*slot
);
5064 return TYPE_ALIAS_SET ((tree
)*slot
);
5067 /* Our caller will assign and record (in t) a new alias set; all we need
5068 to do is remember t in the hash table. */
5074 /* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where
5075 the IS_SIZEOF parameter indicates which operator is being applied.
5076 The COMPLAIN flag controls whether we should diagnose possibly
5077 ill-formed constructs or not. LOC is the location of the SIZEOF or
5078 TYPEOF operator. If MIN_ALIGNOF, the least alignment required for
5079 a type in any context should be returned, rather than the normal
5080 alignment for that type. */
5083 c_sizeof_or_alignof_type (location_t loc
,
5084 tree type
, bool is_sizeof
, bool min_alignof
,
5087 const char *op_name
;
5089 enum tree_code type_code
= TREE_CODE (type
);
5091 op_name
= is_sizeof
? "sizeof" : "__alignof__";
5093 if (type_code
== FUNCTION_TYPE
)
5097 if (complain
&& warn_pointer_arith
)
5098 pedwarn (loc
, OPT_Wpointer_arith
,
5099 "invalid application of %<sizeof%> to a function type");
5101 return error_mark_node
;
5102 value
= size_one_node
;
5108 if (c_dialect_cxx ())
5109 pedwarn (loc
, OPT_Wpedantic
, "ISO C++ does not permit "
5110 "%<alignof%> applied to a function type");
5112 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not permit "
5113 "%<_Alignof%> applied to a function type");
5115 value
= size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
5118 else if (type_code
== VOID_TYPE
|| type_code
== ERROR_MARK
)
5120 if (type_code
== VOID_TYPE
5121 && complain
&& warn_pointer_arith
)
5122 pedwarn (loc
, OPT_Wpointer_arith
,
5123 "invalid application of %qs to a void type", op_name
);
5125 return error_mark_node
;
5126 value
= size_one_node
;
5128 else if (!COMPLETE_TYPE_P (type
)
5129 && (!c_dialect_cxx () || is_sizeof
|| type_code
!= ARRAY_TYPE
))
5132 error_at (loc
, "invalid application of %qs to incomplete type %qT",
5134 return error_mark_node
;
5136 else if (c_dialect_cxx () && type_code
== ARRAY_TYPE
5137 && !COMPLETE_TYPE_P (TREE_TYPE (type
)))
5140 error_at (loc
, "invalid application of %qs to array type %qT of "
5141 "incomplete element type", op_name
, type
);
5142 return error_mark_node
;
5147 /* Convert in case a char is more than one unit. */
5148 value
= size_binop_loc (loc
, CEIL_DIV_EXPR
, TYPE_SIZE_UNIT (type
),
5149 size_int (TYPE_PRECISION (char_type_node
)
5151 else if (min_alignof
)
5152 value
= size_int (min_align_of_type (type
));
5154 value
= size_int (TYPE_ALIGN_UNIT (type
));
5157 /* VALUE will have the middle-end integer type sizetype.
5158 However, we should really return a value of type `size_t',
5159 which is just a typedef for an ordinary integer type. */
5160 value
= fold_convert_loc (loc
, size_type_node
, value
);
5165 /* Implement the __alignof keyword: Return the minimum required
5166 alignment of EXPR, measured in bytes. For VAR_DECLs,
5167 FUNCTION_DECLs and FIELD_DECLs return DECL_ALIGN (which can be set
5168 from an "aligned" __attribute__ specification). LOC is the
5169 location of the ALIGNOF operator. */
5172 c_alignof_expr (location_t loc
, tree expr
)
5176 if (VAR_OR_FUNCTION_DECL_P (expr
))
5177 t
= size_int (DECL_ALIGN_UNIT (expr
));
5179 else if (TREE_CODE (expr
) == COMPONENT_REF
5180 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
, 1)))
5182 error_at (loc
, "%<__alignof%> applied to a bit-field");
5185 else if (TREE_CODE (expr
) == COMPONENT_REF
5186 && TREE_CODE (TREE_OPERAND (expr
, 1)) == FIELD_DECL
)
5187 t
= size_int (DECL_ALIGN_UNIT (TREE_OPERAND (expr
, 1)));
5189 else if (TREE_CODE (expr
) == INDIRECT_REF
)
5191 tree t
= TREE_OPERAND (expr
, 0);
5193 int bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
5195 while (CONVERT_EXPR_P (t
)
5196 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
5200 t
= TREE_OPERAND (t
, 0);
5201 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
5202 if (thisalign
> bestalign
)
5203 best
= t
, bestalign
= thisalign
;
5205 return c_alignof (loc
, TREE_TYPE (TREE_TYPE (best
)));
5208 return c_alignof (loc
, TREE_TYPE (expr
));
5210 return fold_convert_loc (loc
, size_type_node
, t
);
5213 /* Handle C and C++ default attributes. */
5215 enum built_in_attribute
5217 #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
5218 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
5219 #define DEF_ATTR_STRING(ENUM, VALUE) ENUM,
5220 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
5221 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
5222 #include "builtin-attrs.def"
5223 #undef DEF_ATTR_NULL_TREE
5225 #undef DEF_ATTR_STRING
5226 #undef DEF_ATTR_IDENT
5227 #undef DEF_ATTR_TREE_LIST
5231 static GTY(()) tree built_in_attributes
[(int) ATTR_LAST
];
5233 static void c_init_attributes (void);
5237 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
5238 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
5239 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
5240 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
5241 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
5242 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
5243 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
5244 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5246 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5248 #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5249 ARG6, ARG7, ARG8) NAME,
5250 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
5251 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
5252 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
5253 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
5254 #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
5255 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5257 #define DEF_FUNCTION_TYPE_VAR_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5259 #define DEF_FUNCTION_TYPE_VAR_11(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5260 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) NAME,
5261 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
5262 #include "builtin-types.def"
5263 #undef DEF_PRIMITIVE_TYPE
5264 #undef DEF_FUNCTION_TYPE_0
5265 #undef DEF_FUNCTION_TYPE_1
5266 #undef DEF_FUNCTION_TYPE_2
5267 #undef DEF_FUNCTION_TYPE_3
5268 #undef DEF_FUNCTION_TYPE_4
5269 #undef DEF_FUNCTION_TYPE_5
5270 #undef DEF_FUNCTION_TYPE_6
5271 #undef DEF_FUNCTION_TYPE_7
5272 #undef DEF_FUNCTION_TYPE_8
5273 #undef DEF_FUNCTION_TYPE_VAR_0
5274 #undef DEF_FUNCTION_TYPE_VAR_1
5275 #undef DEF_FUNCTION_TYPE_VAR_2
5276 #undef DEF_FUNCTION_TYPE_VAR_3
5277 #undef DEF_FUNCTION_TYPE_VAR_4
5278 #undef DEF_FUNCTION_TYPE_VAR_5
5279 #undef DEF_FUNCTION_TYPE_VAR_7
5280 #undef DEF_FUNCTION_TYPE_VAR_11
5281 #undef DEF_POINTER_TYPE
5285 typedef enum c_builtin_type builtin_type
;
5287 /* A temporary array for c_common_nodes_and_builtins. Used in
5288 communication with def_fn_type. */
5289 static tree builtin_types
[(int) BT_LAST
+ 1];
5291 /* A helper function for c_common_nodes_and_builtins. Build function type
5292 for DEF with return type RET and N arguments. If VAR is true, then the
5293 function should be variadic after those N arguments.
5295 Takes special care not to ICE if any of the types involved are
5296 error_mark_node, which indicates that said type is not in fact available
5297 (see builtin_type_for_size). In which case the function type as a whole
5298 should be error_mark_node. */
5301 def_fn_type (builtin_type def
, builtin_type ret
, bool var
, int n
, ...)
5304 tree
*args
= XALLOCAVEC (tree
, n
);
5309 for (i
= 0; i
< n
; ++i
)
5311 builtin_type a
= (builtin_type
) va_arg (list
, int);
5312 t
= builtin_types
[a
];
5313 if (t
== error_mark_node
)
5318 t
= builtin_types
[ret
];
5319 if (t
== error_mark_node
)
5322 t
= build_varargs_function_type_array (t
, n
, args
);
5324 t
= build_function_type_array (t
, n
, args
);
5327 builtin_types
[def
] = t
;
5331 /* Build builtin functions common to both C and C++ language
5335 c_define_builtins (tree va_list_ref_type_node
, tree va_list_arg_type_node
)
5337 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
5338 builtin_types[ENUM] = VALUE;
5339 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
5340 def_fn_type (ENUM, RETURN, 0, 0);
5341 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
5342 def_fn_type (ENUM, RETURN, 0, 1, ARG1);
5343 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
5344 def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
5345 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
5346 def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
5347 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
5348 def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
5349 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5350 def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
5351 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5353 def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
5354 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5356 def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
5357 #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5359 def_fn_type (ENUM, RETURN, 0, 8, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
5361 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
5362 def_fn_type (ENUM, RETURN, 1, 0);
5363 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
5364 def_fn_type (ENUM, RETURN, 1, 1, ARG1);
5365 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
5366 def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
5367 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
5368 def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
5369 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
5370 def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
5371 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5372 def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
5373 #define DEF_FUNCTION_TYPE_VAR_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5375 def_fn_type (ENUM, RETURN, 1, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
5376 #define DEF_FUNCTION_TYPE_VAR_11(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5377 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) \
5378 def_fn_type (ENUM, RETURN, 1, 11, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
5379 ARG7, ARG8, ARG9, ARG10, ARG11);
5380 #define DEF_POINTER_TYPE(ENUM, TYPE) \
5381 builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
5383 #include "builtin-types.def"
5385 #undef DEF_PRIMITIVE_TYPE
5386 #undef DEF_FUNCTION_TYPE_0
5387 #undef DEF_FUNCTION_TYPE_1
5388 #undef DEF_FUNCTION_TYPE_2
5389 #undef DEF_FUNCTION_TYPE_3
5390 #undef DEF_FUNCTION_TYPE_4
5391 #undef DEF_FUNCTION_TYPE_5
5392 #undef DEF_FUNCTION_TYPE_6
5393 #undef DEF_FUNCTION_TYPE_7
5394 #undef DEF_FUNCTION_TYPE_8
5395 #undef DEF_FUNCTION_TYPE_VAR_0
5396 #undef DEF_FUNCTION_TYPE_VAR_1
5397 #undef DEF_FUNCTION_TYPE_VAR_2
5398 #undef DEF_FUNCTION_TYPE_VAR_3
5399 #undef DEF_FUNCTION_TYPE_VAR_4
5400 #undef DEF_FUNCTION_TYPE_VAR_5
5401 #undef DEF_FUNCTION_TYPE_VAR_7
5402 #undef DEF_FUNCTION_TYPE_VAR_11
5403 #undef DEF_POINTER_TYPE
5404 builtin_types
[(int) BT_LAST
] = NULL_TREE
;
5406 c_init_attributes ();
5408 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P, \
5409 NONANSI_P, ATTRS, IMPLICIT, COND) \
5411 def_builtin_1 (ENUM, NAME, CLASS, \
5412 builtin_types[(int) TYPE], \
5413 builtin_types[(int) LIBTYPE], \
5414 BOTH_P, FALLBACK_P, NONANSI_P, \
5415 built_in_attributes[(int) ATTRS], IMPLICIT);
5416 #include "builtins.def"
5419 targetm
.init_builtins ();
5421 build_common_builtin_nodes ();
5424 cilk_init_builtins ();
5427 /* Like get_identifier, but avoid warnings about null arguments when
5428 the argument may be NULL for targets where GCC lacks stdint.h type
5432 c_get_ident (const char *id
)
5434 return get_identifier (id
);
5437 /* Build tree nodes and builtin functions common to both C and C++ language
5441 c_common_nodes_and_builtins (void)
5443 int char16_type_size
;
5444 int char32_type_size
;
5445 int wchar_type_size
;
5446 tree array_domain_type
;
5447 tree va_list_ref_type_node
;
5448 tree va_list_arg_type_node
;
5451 build_common_tree_nodes (flag_signed_char
, flag_short_double
);
5453 /* Define `int' and `char' first so that dbx will output them first. */
5454 record_builtin_type (RID_INT
, NULL
, integer_type_node
);
5455 record_builtin_type (RID_CHAR
, "char", char_type_node
);
5457 /* `signed' is the same as `int'. FIXME: the declarations of "signed",
5458 "unsigned long", "long long unsigned" and "unsigned short" were in C++
5459 but not C. Are the conditionals here needed? */
5460 if (c_dialect_cxx ())
5461 record_builtin_type (RID_SIGNED
, NULL
, integer_type_node
);
5462 record_builtin_type (RID_LONG
, "long int", long_integer_type_node
);
5463 record_builtin_type (RID_UNSIGNED
, "unsigned int", unsigned_type_node
);
5464 record_builtin_type (RID_MAX
, "long unsigned int",
5465 long_unsigned_type_node
);
5467 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
5471 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
5472 record_builtin_type ((enum rid
)(RID_FIRST_INT_N
+ i
), name
,
5473 int_n_trees
[i
].signed_type
);
5474 sprintf (name
, "__int%d unsigned", int_n_data
[i
].bitsize
);
5475 record_builtin_type (RID_MAX
, name
, int_n_trees
[i
].unsigned_type
);
5478 if (c_dialect_cxx ())
5479 record_builtin_type (RID_MAX
, "unsigned long", long_unsigned_type_node
);
5480 record_builtin_type (RID_MAX
, "long long int",
5481 long_long_integer_type_node
);
5482 record_builtin_type (RID_MAX
, "long long unsigned int",
5483 long_long_unsigned_type_node
);
5484 if (c_dialect_cxx ())
5485 record_builtin_type (RID_MAX
, "long long unsigned",
5486 long_long_unsigned_type_node
);
5487 record_builtin_type (RID_SHORT
, "short int", short_integer_type_node
);
5488 record_builtin_type (RID_MAX
, "short unsigned int",
5489 short_unsigned_type_node
);
5490 if (c_dialect_cxx ())
5491 record_builtin_type (RID_MAX
, "unsigned short",
5492 short_unsigned_type_node
);
5494 /* Define both `signed char' and `unsigned char'. */
5495 record_builtin_type (RID_MAX
, "signed char", signed_char_type_node
);
5496 record_builtin_type (RID_MAX
, "unsigned char", unsigned_char_type_node
);
5498 /* These are types that c_common_type_for_size and
5499 c_common_type_for_mode use. */
5500 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5501 TYPE_DECL
, NULL_TREE
,
5503 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5504 TYPE_DECL
, NULL_TREE
,
5506 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5507 TYPE_DECL
, NULL_TREE
,
5509 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5510 TYPE_DECL
, NULL_TREE
,
5512 #if HOST_BITS_PER_WIDE_INT >= 64
5513 /* Note that this is different than the __int128 type that's part of
5514 the generic __intN support. */
5515 if (targetm
.scalar_mode_supported_p (TImode
))
5516 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5518 get_identifier ("__int128_t"),
5521 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5522 TYPE_DECL
, NULL_TREE
,
5523 unsigned_intQI_type_node
));
5524 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5525 TYPE_DECL
, NULL_TREE
,
5526 unsigned_intHI_type_node
));
5527 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5528 TYPE_DECL
, NULL_TREE
,
5529 unsigned_intSI_type_node
));
5530 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5531 TYPE_DECL
, NULL_TREE
,
5532 unsigned_intDI_type_node
));
5533 #if HOST_BITS_PER_WIDE_INT >= 64
5534 if (targetm
.scalar_mode_supported_p (TImode
))
5535 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5537 get_identifier ("__uint128_t"),
5538 unsigned_intTI_type_node
));
5541 /* Create the widest literal types. */
5542 widest_integer_literal_type_node
5543 = make_signed_type (HOST_BITS_PER_WIDE_INT
* 2);
5544 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5545 TYPE_DECL
, NULL_TREE
,
5546 widest_integer_literal_type_node
));
5548 widest_unsigned_literal_type_node
5549 = make_unsigned_type (HOST_BITS_PER_WIDE_INT
* 2);
5550 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5551 TYPE_DECL
, NULL_TREE
,
5552 widest_unsigned_literal_type_node
));
5554 signed_size_type_node
= c_common_signed_type (size_type_node
);
5557 TREE_TYPE (identifier_global_value (get_identifier (PID_TYPE
)));
5559 record_builtin_type (RID_FLOAT
, NULL
, float_type_node
);
5560 record_builtin_type (RID_DOUBLE
, NULL
, double_type_node
);
5561 record_builtin_type (RID_MAX
, "long double", long_double_type_node
);
5563 /* Only supported decimal floating point extension if the target
5564 actually supports underlying modes. */
5565 if (targetm
.scalar_mode_supported_p (SDmode
)
5566 && targetm
.scalar_mode_supported_p (DDmode
)
5567 && targetm
.scalar_mode_supported_p (TDmode
))
5569 record_builtin_type (RID_DFLOAT32
, NULL
, dfloat32_type_node
);
5570 record_builtin_type (RID_DFLOAT64
, NULL
, dfloat64_type_node
);
5571 record_builtin_type (RID_DFLOAT128
, NULL
, dfloat128_type_node
);
5574 if (targetm
.fixed_point_supported_p ())
5576 record_builtin_type (RID_MAX
, "short _Fract", short_fract_type_node
);
5577 record_builtin_type (RID_FRACT
, NULL
, fract_type_node
);
5578 record_builtin_type (RID_MAX
, "long _Fract", long_fract_type_node
);
5579 record_builtin_type (RID_MAX
, "long long _Fract",
5580 long_long_fract_type_node
);
5581 record_builtin_type (RID_MAX
, "unsigned short _Fract",
5582 unsigned_short_fract_type_node
);
5583 record_builtin_type (RID_MAX
, "unsigned _Fract",
5584 unsigned_fract_type_node
);
5585 record_builtin_type (RID_MAX
, "unsigned long _Fract",
5586 unsigned_long_fract_type_node
);
5587 record_builtin_type (RID_MAX
, "unsigned long long _Fract",
5588 unsigned_long_long_fract_type_node
);
5589 record_builtin_type (RID_MAX
, "_Sat short _Fract",
5590 sat_short_fract_type_node
);
5591 record_builtin_type (RID_MAX
, "_Sat _Fract", sat_fract_type_node
);
5592 record_builtin_type (RID_MAX
, "_Sat long _Fract",
5593 sat_long_fract_type_node
);
5594 record_builtin_type (RID_MAX
, "_Sat long long _Fract",
5595 sat_long_long_fract_type_node
);
5596 record_builtin_type (RID_MAX
, "_Sat unsigned short _Fract",
5597 sat_unsigned_short_fract_type_node
);
5598 record_builtin_type (RID_MAX
, "_Sat unsigned _Fract",
5599 sat_unsigned_fract_type_node
);
5600 record_builtin_type (RID_MAX
, "_Sat unsigned long _Fract",
5601 sat_unsigned_long_fract_type_node
);
5602 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Fract",
5603 sat_unsigned_long_long_fract_type_node
);
5604 record_builtin_type (RID_MAX
, "short _Accum", short_accum_type_node
);
5605 record_builtin_type (RID_ACCUM
, NULL
, accum_type_node
);
5606 record_builtin_type (RID_MAX
, "long _Accum", long_accum_type_node
);
5607 record_builtin_type (RID_MAX
, "long long _Accum",
5608 long_long_accum_type_node
);
5609 record_builtin_type (RID_MAX
, "unsigned short _Accum",
5610 unsigned_short_accum_type_node
);
5611 record_builtin_type (RID_MAX
, "unsigned _Accum",
5612 unsigned_accum_type_node
);
5613 record_builtin_type (RID_MAX
, "unsigned long _Accum",
5614 unsigned_long_accum_type_node
);
5615 record_builtin_type (RID_MAX
, "unsigned long long _Accum",
5616 unsigned_long_long_accum_type_node
);
5617 record_builtin_type (RID_MAX
, "_Sat short _Accum",
5618 sat_short_accum_type_node
);
5619 record_builtin_type (RID_MAX
, "_Sat _Accum", sat_accum_type_node
);
5620 record_builtin_type (RID_MAX
, "_Sat long _Accum",
5621 sat_long_accum_type_node
);
5622 record_builtin_type (RID_MAX
, "_Sat long long _Accum",
5623 sat_long_long_accum_type_node
);
5624 record_builtin_type (RID_MAX
, "_Sat unsigned short _Accum",
5625 sat_unsigned_short_accum_type_node
);
5626 record_builtin_type (RID_MAX
, "_Sat unsigned _Accum",
5627 sat_unsigned_accum_type_node
);
5628 record_builtin_type (RID_MAX
, "_Sat unsigned long _Accum",
5629 sat_unsigned_long_accum_type_node
);
5630 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Accum",
5631 sat_unsigned_long_long_accum_type_node
);
5635 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5637 get_identifier ("complex int"),
5638 complex_integer_type_node
));
5639 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5641 get_identifier ("complex float"),
5642 complex_float_type_node
));
5643 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5645 get_identifier ("complex double"),
5646 complex_double_type_node
));
5647 lang_hooks
.decls
.pushdecl
5648 (build_decl (UNKNOWN_LOCATION
,
5649 TYPE_DECL
, get_identifier ("complex long double"),
5650 complex_long_double_type_node
));
5652 if (c_dialect_cxx ())
5653 /* For C++, make fileptr_type_node a distinct void * type until
5654 FILE type is defined. */
5655 fileptr_type_node
= build_variant_type_copy (ptr_type_node
);
5657 record_builtin_type (RID_VOID
, NULL
, void_type_node
);
5659 /* Set the TYPE_NAME for any variants that were built before
5660 record_builtin_type gave names to the built-in types. */
5662 tree void_name
= TYPE_NAME (void_type_node
);
5663 TYPE_NAME (void_type_node
) = NULL_TREE
;
5664 TYPE_NAME (build_qualified_type (void_type_node
, TYPE_QUAL_CONST
))
5666 TYPE_NAME (void_type_node
) = void_name
;
5669 void_list_node
= build_void_list_node ();
5671 /* Make a type to be the domain of a few array types
5672 whose domains don't really matter.
5673 200 is small enough that it always fits in size_t
5674 and large enough that it can hold most function names for the
5675 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
5676 array_domain_type
= build_index_type (size_int (200));
5678 /* Make a type for arrays of characters.
5679 With luck nothing will ever really depend on the length of this
5681 char_array_type_node
5682 = build_array_type (char_type_node
, array_domain_type
);
5684 string_type_node
= build_pointer_type (char_type_node
);
5685 const_string_type_node
5686 = build_pointer_type (build_qualified_type
5687 (char_type_node
, TYPE_QUAL_CONST
));
5689 /* This is special for C++ so functions can be overloaded. */
5690 wchar_type_node
= get_identifier (MODIFIED_WCHAR_TYPE
);
5691 wchar_type_node
= TREE_TYPE (identifier_global_value (wchar_type_node
));
5692 wchar_type_size
= TYPE_PRECISION (wchar_type_node
);
5693 underlying_wchar_type_node
= wchar_type_node
;
5694 if (c_dialect_cxx ())
5696 if (TYPE_UNSIGNED (wchar_type_node
))
5697 wchar_type_node
= make_unsigned_type (wchar_type_size
);
5699 wchar_type_node
= make_signed_type (wchar_type_size
);
5700 record_builtin_type (RID_WCHAR
, "wchar_t", wchar_type_node
);
5703 /* This is for wide string constants. */
5704 wchar_array_type_node
5705 = build_array_type (wchar_type_node
, array_domain_type
);
5707 /* Define 'char16_t'. */
5708 char16_type_node
= get_identifier (CHAR16_TYPE
);
5709 char16_type_node
= TREE_TYPE (identifier_global_value (char16_type_node
));
5710 char16_type_size
= TYPE_PRECISION (char16_type_node
);
5711 if (c_dialect_cxx ())
5713 char16_type_node
= make_unsigned_type (char16_type_size
);
5715 if (cxx_dialect
>= cxx11
)
5716 record_builtin_type (RID_CHAR16
, "char16_t", char16_type_node
);
5719 /* This is for UTF-16 string constants. */
5720 char16_array_type_node
5721 = build_array_type (char16_type_node
, array_domain_type
);
5723 /* Define 'char32_t'. */
5724 char32_type_node
= get_identifier (CHAR32_TYPE
);
5725 char32_type_node
= TREE_TYPE (identifier_global_value (char32_type_node
));
5726 char32_type_size
= TYPE_PRECISION (char32_type_node
);
5727 if (c_dialect_cxx ())
5729 char32_type_node
= make_unsigned_type (char32_type_size
);
5731 if (cxx_dialect
>= cxx11
)
5732 record_builtin_type (RID_CHAR32
, "char32_t", char32_type_node
);
5735 /* This is for UTF-32 string constants. */
5736 char32_array_type_node
5737 = build_array_type (char32_type_node
, array_domain_type
);
5740 TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE
)));
5743 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE
)));
5745 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE
)));
5747 if (SIG_ATOMIC_TYPE
)
5748 sig_atomic_type_node
=
5749 TREE_TYPE (identifier_global_value (c_get_ident (SIG_ATOMIC_TYPE
)));
5752 TREE_TYPE (identifier_global_value (c_get_ident (INT8_TYPE
)));
5755 TREE_TYPE (identifier_global_value (c_get_ident (INT16_TYPE
)));
5758 TREE_TYPE (identifier_global_value (c_get_ident (INT32_TYPE
)));
5761 TREE_TYPE (identifier_global_value (c_get_ident (INT64_TYPE
)));
5764 TREE_TYPE (identifier_global_value (c_get_ident (UINT8_TYPE
)));
5766 c_uint16_type_node
= uint16_type_node
=
5767 TREE_TYPE (identifier_global_value (c_get_ident (UINT16_TYPE
)));
5769 c_uint32_type_node
= uint32_type_node
=
5770 TREE_TYPE (identifier_global_value (c_get_ident (UINT32_TYPE
)));
5772 c_uint64_type_node
= uint64_type_node
=
5773 TREE_TYPE (identifier_global_value (c_get_ident (UINT64_TYPE
)));
5774 if (INT_LEAST8_TYPE
)
5775 int_least8_type_node
=
5776 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST8_TYPE
)));
5777 if (INT_LEAST16_TYPE
)
5778 int_least16_type_node
=
5779 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST16_TYPE
)));
5780 if (INT_LEAST32_TYPE
)
5781 int_least32_type_node
=
5782 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST32_TYPE
)));
5783 if (INT_LEAST64_TYPE
)
5784 int_least64_type_node
=
5785 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST64_TYPE
)));
5786 if (UINT_LEAST8_TYPE
)
5787 uint_least8_type_node
=
5788 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST8_TYPE
)));
5789 if (UINT_LEAST16_TYPE
)
5790 uint_least16_type_node
=
5791 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST16_TYPE
)));
5792 if (UINT_LEAST32_TYPE
)
5793 uint_least32_type_node
=
5794 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST32_TYPE
)));
5795 if (UINT_LEAST64_TYPE
)
5796 uint_least64_type_node
=
5797 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST64_TYPE
)));
5799 int_fast8_type_node
=
5800 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST8_TYPE
)));
5801 if (INT_FAST16_TYPE
)
5802 int_fast16_type_node
=
5803 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST16_TYPE
)));
5804 if (INT_FAST32_TYPE
)
5805 int_fast32_type_node
=
5806 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST32_TYPE
)));
5807 if (INT_FAST64_TYPE
)
5808 int_fast64_type_node
=
5809 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST64_TYPE
)));
5810 if (UINT_FAST8_TYPE
)
5811 uint_fast8_type_node
=
5812 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST8_TYPE
)));
5813 if (UINT_FAST16_TYPE
)
5814 uint_fast16_type_node
=
5815 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST16_TYPE
)));
5816 if (UINT_FAST32_TYPE
)
5817 uint_fast32_type_node
=
5818 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST32_TYPE
)));
5819 if (UINT_FAST64_TYPE
)
5820 uint_fast64_type_node
=
5821 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST64_TYPE
)));
5824 TREE_TYPE (identifier_global_value (c_get_ident (INTPTR_TYPE
)));
5827 TREE_TYPE (identifier_global_value (c_get_ident (UINTPTR_TYPE
)));
5829 default_function_type
5830 = build_varargs_function_type_list (integer_type_node
, NULL_TREE
);
5832 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE
)));
5833 unsigned_ptrdiff_type_node
= c_common_unsigned_type (ptrdiff_type_node
);
5835 lang_hooks
.decls
.pushdecl
5836 (build_decl (UNKNOWN_LOCATION
,
5837 TYPE_DECL
, get_identifier ("__builtin_va_list"),
5838 va_list_type_node
));
5839 if (targetm
.enum_va_list_p
)
5845 for (l
= 0; targetm
.enum_va_list_p (l
, &pname
, &ptype
); ++l
)
5847 lang_hooks
.decls
.pushdecl
5848 (build_decl (UNKNOWN_LOCATION
,
5849 TYPE_DECL
, get_identifier (pname
),
5855 if (TREE_CODE (va_list_type_node
) == ARRAY_TYPE
)
5857 va_list_arg_type_node
= va_list_ref_type_node
=
5858 build_pointer_type (TREE_TYPE (va_list_type_node
));
5862 va_list_arg_type_node
= va_list_type_node
;
5863 va_list_ref_type_node
= build_reference_type (va_list_type_node
);
5866 if (!flag_preprocess_only
)
5867 c_define_builtins (va_list_ref_type_node
, va_list_arg_type_node
);
5869 main_identifier_node
= get_identifier ("main");
5871 /* Create the built-in __null node. It is important that this is
5873 null_node
= make_int_cst (1, 1);
5874 TREE_TYPE (null_node
) = c_common_type_for_size (POINTER_SIZE
, 0);
5876 /* Since builtin_types isn't gc'ed, don't export these nodes. */
5877 memset (builtin_types
, 0, sizeof (builtin_types
));
5880 /* The number of named compound-literals generated thus far. */
5881 static GTY(()) int compound_literal_number
;
5883 /* Set DECL_NAME for DECL, a VAR_DECL for a compound-literal. */
5886 set_compound_literal_name (tree decl
)
5889 ASM_FORMAT_PRIVATE_NAME (name
, "__compound_literal",
5890 compound_literal_number
);
5891 compound_literal_number
++;
5892 DECL_NAME (decl
) = get_identifier (name
);
5896 build_va_arg (location_t loc
, tree expr
, tree type
)
5898 expr
= build1 (VA_ARG_EXPR
, type
, expr
);
5899 SET_EXPR_LOCATION (expr
, loc
);
5904 /* Linked list of disabled built-in functions. */
5906 typedef struct disabled_builtin
5909 struct disabled_builtin
*next
;
5911 static disabled_builtin
*disabled_builtins
= NULL
;
5913 static bool builtin_function_disabled_p (const char *);
5915 /* Disable a built-in function specified by -fno-builtin-NAME. If NAME
5916 begins with "__builtin_", give an error. */
5919 disable_builtin_function (const char *name
)
5921 if (strncmp (name
, "__builtin_", strlen ("__builtin_")) == 0)
5922 error ("cannot disable built-in function %qs", name
);
5925 disabled_builtin
*new_disabled_builtin
= XNEW (disabled_builtin
);
5926 new_disabled_builtin
->name
= name
;
5927 new_disabled_builtin
->next
= disabled_builtins
;
5928 disabled_builtins
= new_disabled_builtin
;
5933 /* Return true if the built-in function NAME has been disabled, false
5937 builtin_function_disabled_p (const char *name
)
5939 disabled_builtin
*p
;
5940 for (p
= disabled_builtins
; p
!= NULL
; p
= p
->next
)
5942 if (strcmp (name
, p
->name
) == 0)
5949 /* Worker for DEF_BUILTIN.
5950 Possibly define a builtin function with one or two names.
5951 Does not declare a non-__builtin_ function if flag_no_builtin, or if
5952 nonansi_p and flag_no_nonansi_builtin. */
5955 def_builtin_1 (enum built_in_function fncode
,
5957 enum built_in_class fnclass
,
5958 tree fntype
, tree libtype
,
5959 bool both_p
, bool fallback_p
, bool nonansi_p
,
5960 tree fnattrs
, bool implicit_p
)
5963 const char *libname
;
5965 if (fntype
== error_mark_node
)
5968 gcc_assert ((!both_p
&& !fallback_p
)
5969 || !strncmp (name
, "__builtin_",
5970 strlen ("__builtin_")));
5972 libname
= name
+ strlen ("__builtin_");
5973 decl
= add_builtin_function (name
, fntype
, fncode
, fnclass
,
5974 (fallback_p
? libname
: NULL
),
5977 set_builtin_decl (fncode
, decl
, implicit_p
);
5980 && !flag_no_builtin
&& !builtin_function_disabled_p (libname
)
5981 && !(nonansi_p
&& flag_no_nonansi_builtin
))
5982 add_builtin_function (libname
, libtype
, fncode
, fnclass
,
5986 /* Nonzero if the type T promotes to int. This is (nearly) the
5987 integral promotions defined in ISO C99 6.3.1.1/2. */
5990 c_promoting_integer_type_p (const_tree t
)
5992 switch (TREE_CODE (t
))
5995 return (TYPE_MAIN_VARIANT (t
) == char_type_node
5996 || TYPE_MAIN_VARIANT (t
) == signed_char_type_node
5997 || TYPE_MAIN_VARIANT (t
) == unsigned_char_type_node
5998 || TYPE_MAIN_VARIANT (t
) == short_integer_type_node
5999 || TYPE_MAIN_VARIANT (t
) == short_unsigned_type_node
6000 || TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
));
6003 /* ??? Technically all enumerations not larger than an int
6004 promote to an int. But this is used along code paths
6005 that only want to notice a size change. */
6006 return TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
);
6016 /* Return 1 if PARMS specifies a fixed number of parameters
6017 and none of their types is affected by default promotions. */
6020 self_promoting_args_p (const_tree parms
)
6023 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
6025 tree type
= TREE_VALUE (t
);
6027 if (type
== error_mark_node
)
6030 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
6036 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
6039 if (c_promoting_integer_type_p (type
))
6045 /* Recursively remove any '*' or '&' operator from TYPE. */
6047 strip_pointer_operator (tree t
)
6049 while (POINTER_TYPE_P (t
))
6054 /* Recursively remove pointer or array type from TYPE. */
6056 strip_pointer_or_array_types (tree t
)
6058 while (TREE_CODE (t
) == ARRAY_TYPE
|| POINTER_TYPE_P (t
))
6063 /* Used to compare case labels. K1 and K2 are actually tree nodes
6064 representing case labels, or NULL_TREE for a `default' label.
6065 Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after
6066 K2, and 0 if K1 and K2 are equal. */
6069 case_compare (splay_tree_key k1
, splay_tree_key k2
)
6071 /* Consider a NULL key (such as arises with a `default' label) to be
6072 smaller than anything else. */
6078 return tree_int_cst_compare ((tree
) k1
, (tree
) k2
);
6081 /* Process a case label, located at LOC, for the range LOW_VALUE
6082 ... HIGH_VALUE. If LOW_VALUE and HIGH_VALUE are both NULL_TREE
6083 then this case label is actually a `default' label. If only
6084 HIGH_VALUE is NULL_TREE, then case label was declared using the
6085 usual C/C++ syntax, rather than the GNU case range extension.
6086 CASES is a tree containing all the case ranges processed so far;
6087 COND is the condition for the switch-statement itself. Returns the
6088 CASE_LABEL_EXPR created, or ERROR_MARK_NODE if no CASE_LABEL_EXPR
6092 c_add_case_label (location_t loc
, splay_tree cases
, tree cond
, tree orig_type
,
6093 tree low_value
, tree high_value
)
6098 splay_tree_node node
;
6100 /* Create the LABEL_DECL itself. */
6101 label
= create_artificial_label (loc
);
6103 /* If there was an error processing the switch condition, bail now
6104 before we get more confused. */
6105 if (!cond
|| cond
== error_mark_node
)
6108 if ((low_value
&& TREE_TYPE (low_value
)
6109 && POINTER_TYPE_P (TREE_TYPE (low_value
)))
6110 || (high_value
&& TREE_TYPE (high_value
)
6111 && POINTER_TYPE_P (TREE_TYPE (high_value
))))
6113 error_at (loc
, "pointers are not permitted as case values");
6117 /* Case ranges are a GNU extension. */
6119 pedwarn (loc
, OPT_Wpedantic
,
6120 "range expressions in switch statements are non-standard");
6122 type
= TREE_TYPE (cond
);
6125 low_value
= check_case_value (loc
, low_value
);
6126 low_value
= convert_and_check (loc
, type
, low_value
);
6127 if (low_value
== error_mark_node
)
6132 high_value
= check_case_value (loc
, high_value
);
6133 high_value
= convert_and_check (loc
, type
, high_value
);
6134 if (high_value
== error_mark_node
)
6138 if (low_value
&& high_value
)
6140 /* If the LOW_VALUE and HIGH_VALUE are the same, then this isn't
6141 really a case range, even though it was written that way.
6142 Remove the HIGH_VALUE to simplify later processing. */
6143 if (tree_int_cst_equal (low_value
, high_value
))
6144 high_value
= NULL_TREE
;
6145 else if (!tree_int_cst_lt (low_value
, high_value
))
6146 warning_at (loc
, 0, "empty range specified");
6149 /* See if the case is in range of the type of the original testing
6150 expression. If both low_value and high_value are out of range,
6151 don't insert the case label and return NULL_TREE. */
6153 && !check_case_bounds (loc
, type
, orig_type
,
6154 &low_value
, high_value
? &high_value
: NULL
))
6157 /* Look up the LOW_VALUE in the table of case labels we already
6159 node
= splay_tree_lookup (cases
, (splay_tree_key
) low_value
);
6160 /* If there was not an exact match, check for overlapping ranges.
6161 There's no need to do this if there's no LOW_VALUE or HIGH_VALUE;
6162 that's a `default' label and the only overlap is an exact match. */
6163 if (!node
&& (low_value
|| high_value
))
6165 splay_tree_node low_bound
;
6166 splay_tree_node high_bound
;
6168 /* Even though there wasn't an exact match, there might be an
6169 overlap between this case range and another case range.
6170 Since we've (inductively) not allowed any overlapping case
6171 ranges, we simply need to find the greatest low case label
6172 that is smaller that LOW_VALUE, and the smallest low case
6173 label that is greater than LOW_VALUE. If there is an overlap
6174 it will occur in one of these two ranges. */
6175 low_bound
= splay_tree_predecessor (cases
,
6176 (splay_tree_key
) low_value
);
6177 high_bound
= splay_tree_successor (cases
,
6178 (splay_tree_key
) low_value
);
6180 /* Check to see if the LOW_BOUND overlaps. It is smaller than
6181 the LOW_VALUE, so there is no need to check unless the
6182 LOW_BOUND is in fact itself a case range. */
6184 && CASE_HIGH ((tree
) low_bound
->value
)
6185 && tree_int_cst_compare (CASE_HIGH ((tree
) low_bound
->value
),
6188 /* Check to see if the HIGH_BOUND overlaps. The low end of that
6189 range is bigger than the low end of the current range, so we
6190 are only interested if the current range is a real range, and
6191 not an ordinary case label. */
6194 && (tree_int_cst_compare ((tree
) high_bound
->key
,
6199 /* If there was an overlap, issue an error. */
6202 tree duplicate
= CASE_LABEL ((tree
) node
->value
);
6206 error_at (loc
, "duplicate (or overlapping) case value");
6207 error_at (DECL_SOURCE_LOCATION (duplicate
),
6208 "this is the first entry overlapping that value");
6212 error_at (loc
, "duplicate case value") ;
6213 error_at (DECL_SOURCE_LOCATION (duplicate
), "previously used here");
6217 error_at (loc
, "multiple default labels in one switch");
6218 error_at (DECL_SOURCE_LOCATION (duplicate
),
6219 "this is the first default label");
6224 /* Add a CASE_LABEL to the statement-tree. */
6225 case_label
= add_stmt (build_case_label (low_value
, high_value
, label
));
6226 /* Register this case label in the splay tree. */
6227 splay_tree_insert (cases
,
6228 (splay_tree_key
) low_value
,
6229 (splay_tree_value
) case_label
);
6234 /* Add a label so that the back-end doesn't think that the beginning of
6235 the switch is unreachable. Note that we do not add a case label, as
6236 that just leads to duplicates and thence to failure later on. */
6239 tree t
= create_artificial_label (loc
);
6240 add_stmt (build_stmt (loc
, LABEL_EXPR
, t
));
6242 return error_mark_node
;
6245 /* Subroutines of c_do_switch_warnings, called via splay_tree_foreach.
6246 Used to verify that case values match up with enumerator values. */
6249 match_case_to_enum_1 (tree key
, tree type
, tree label
)
6251 char buf
[WIDE_INT_PRINT_BUFFER_SIZE
];
6253 if (tree_fits_uhwi_p (key
))
6254 print_dec (key
, buf
, UNSIGNED
);
6255 else if (tree_fits_shwi_p (key
))
6256 print_dec (key
, buf
, SIGNED
);
6258 print_hex (key
, buf
);
6260 if (TYPE_NAME (type
) == 0)
6261 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
6262 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
6263 "case value %qs not in enumerated type",
6266 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
6267 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
6268 "case value %qs not in enumerated type %qT",
6272 /* Subroutine 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 (splay_tree_node node
, void *data
)
6278 tree label
= (tree
) node
->value
;
6279 tree type
= (tree
) data
;
6281 /* Skip default case. */
6282 if (!CASE_LOW (label
))
6285 /* If CASE_LOW_SEEN is not set, that means CASE_LOW did not appear
6286 when we did our enum->case scan. Reset our scratch bit after. */
6287 if (!CASE_LOW_SEEN (label
))
6288 match_case_to_enum_1 (CASE_LOW (label
), type
, label
);
6290 CASE_LOW_SEEN (label
) = 0;
6292 /* If CASE_HIGH is non-null, we have a range. If CASE_HIGH_SEEN is
6293 not set, that means that CASE_HIGH did not appear when we did our
6294 enum->case scan. Reset our scratch bit after. */
6295 if (CASE_HIGH (label
))
6297 if (!CASE_HIGH_SEEN (label
))
6298 match_case_to_enum_1 (CASE_HIGH (label
), type
, label
);
6300 CASE_HIGH_SEEN (label
) = 0;
6306 /* Handle -Wswitch*. Called from the front end after parsing the
6307 switch construct. */
6308 /* ??? Should probably be somewhere generic, since other languages
6309 besides C and C++ would want this. At the moment, however, C/C++
6310 are the only tree-ssa languages that support enumerations at all,
6311 so the point is moot. */
6314 c_do_switch_warnings (splay_tree cases
, location_t switch_location
,
6315 tree type
, tree cond
)
6317 splay_tree_node default_node
;
6318 splay_tree_node node
;
6321 if (!warn_switch
&& !warn_switch_enum
&& !warn_switch_default
)
6324 default_node
= splay_tree_lookup (cases
, (splay_tree_key
) NULL
);
6326 warning_at (switch_location
, OPT_Wswitch_default
,
6327 "switch missing default case");
6329 /* From here on, we only care about about enumerated types. */
6330 if (!type
|| TREE_CODE (type
) != ENUMERAL_TYPE
)
6333 /* From here on, we only care about -Wswitch and -Wswitch-enum. */
6334 if (!warn_switch_enum
&& !warn_switch
)
6337 /* Check the cases. Warn about case values which are not members of
6338 the enumerated type. For -Wswitch-enum, or for -Wswitch when
6339 there is no default case, check that exactly all enumeration
6340 literals are covered by the cases. */
6342 /* Clearing COND if it is not an integer constant simplifies
6343 the tests inside the loop below. */
6344 if (TREE_CODE (cond
) != INTEGER_CST
)
6347 /* The time complexity here is O(N*lg(N)) worst case, but for the
6348 common case of monotonically increasing enumerators, it is
6349 O(N), since the nature of the splay tree will keep the next
6350 element adjacent to the root at all times. */
6352 for (chain
= TYPE_VALUES (type
); chain
; chain
= TREE_CHAIN (chain
))
6354 tree value
= TREE_VALUE (chain
);
6355 if (TREE_CODE (value
) == CONST_DECL
)
6356 value
= DECL_INITIAL (value
);
6357 node
= splay_tree_lookup (cases
, (splay_tree_key
) value
);
6360 /* Mark the CASE_LOW part of the case entry as seen. */
6361 tree label
= (tree
) node
->value
;
6362 CASE_LOW_SEEN (label
) = 1;
6366 /* Even though there wasn't an exact match, there might be a
6367 case range which includes the enumerator's value. */
6368 node
= splay_tree_predecessor (cases
, (splay_tree_key
) value
);
6369 if (node
&& CASE_HIGH ((tree
) node
->value
))
6371 tree label
= (tree
) node
->value
;
6372 int cmp
= tree_int_cst_compare (CASE_HIGH (label
), value
);
6375 /* If we match the upper bound exactly, mark the CASE_HIGH
6376 part of the case entry as seen. */
6378 CASE_HIGH_SEEN (label
) = 1;
6383 /* We've now determined that this enumerated literal isn't
6384 handled by the case labels of the switch statement. */
6386 /* If the switch expression is a constant, we only really care
6387 about whether that constant is handled by the switch. */
6388 if (cond
&& tree_int_cst_compare (cond
, value
))
6391 /* If there is a default_node, the only relevant option is
6392 Wswitch-enum. Otherwise, if both are enabled then we prefer
6393 to warn using -Wswitch because -Wswitch is enabled by -Wall
6394 while -Wswitch-enum is explicit. */
6395 warning_at (switch_location
,
6396 (default_node
|| !warn_switch
6399 "enumeration value %qE not handled in switch",
6400 TREE_PURPOSE (chain
));
6403 /* Warn if there are case expressions that don't correspond to
6404 enumerators. This can occur since C and C++ don't enforce
6405 type-checking of assignments to enumeration variables.
6407 The time complexity here is now always O(N) worst case, since
6408 we should have marked both the lower bound and upper bound of
6409 every disjoint case label, with CASE_LOW_SEEN and CASE_HIGH_SEEN
6410 above. This scan also resets those fields. */
6412 splay_tree_foreach (cases
, match_case_to_enum
, type
);
6415 /* Finish an expression taking the address of LABEL (an
6416 IDENTIFIER_NODE). Returns an expression for the address.
6418 LOC is the location for the expression returned. */
6421 finish_label_address_expr (tree label
, location_t loc
)
6425 pedwarn (input_location
, OPT_Wpedantic
, "taking the address of a label is non-standard");
6427 if (label
== error_mark_node
)
6428 return error_mark_node
;
6430 label
= lookup_label (label
);
6431 if (label
== NULL_TREE
)
6432 result
= null_pointer_node
;
6435 TREE_USED (label
) = 1;
6436 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
6437 /* The current function is not necessarily uninlinable.
6438 Computed gotos are incompatible with inlining, but the value
6439 here could be used only in a diagnostic, for example. */
6440 protected_set_expr_location (result
, loc
);
6447 /* Given a boolean expression ARG, return a tree representing an increment
6448 or decrement (as indicated by CODE) of ARG. The front end must check for
6449 invalid cases (e.g., decrement in C++). */
6451 boolean_increment (enum tree_code code
, tree arg
)
6454 tree true_res
= build_int_cst (TREE_TYPE (arg
), 1);
6456 arg
= stabilize_reference (arg
);
6459 case PREINCREMENT_EXPR
:
6460 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
6462 case POSTINCREMENT_EXPR
:
6463 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
6464 arg
= save_expr (arg
);
6465 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
6466 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
6468 case PREDECREMENT_EXPR
:
6469 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
6470 invert_truthvalue_loc (input_location
, arg
));
6472 case POSTDECREMENT_EXPR
:
6473 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
6474 invert_truthvalue_loc (input_location
, arg
));
6475 arg
= save_expr (arg
);
6476 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
6477 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
6482 TREE_SIDE_EFFECTS (val
) = 1;
6486 /* Built-in macros for stddef.h and stdint.h, that require macros
6487 defined in this file. */
6489 c_stddef_cpp_builtins(void)
6491 builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE
, 0);
6492 builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE
, 0);
6493 builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE
, 0);
6494 builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE
, 0);
6495 builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE
, 0);
6496 builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE
, 0);
6497 builtin_define_with_value ("__CHAR16_TYPE__", CHAR16_TYPE
, 0);
6498 builtin_define_with_value ("__CHAR32_TYPE__", CHAR32_TYPE
, 0);
6499 if (SIG_ATOMIC_TYPE
)
6500 builtin_define_with_value ("__SIG_ATOMIC_TYPE__", SIG_ATOMIC_TYPE
, 0);
6502 builtin_define_with_value ("__INT8_TYPE__", INT8_TYPE
, 0);
6504 builtin_define_with_value ("__INT16_TYPE__", INT16_TYPE
, 0);
6506 builtin_define_with_value ("__INT32_TYPE__", INT32_TYPE
, 0);
6508 builtin_define_with_value ("__INT64_TYPE__", INT64_TYPE
, 0);
6510 builtin_define_with_value ("__UINT8_TYPE__", UINT8_TYPE
, 0);
6512 builtin_define_with_value ("__UINT16_TYPE__", UINT16_TYPE
, 0);
6514 builtin_define_with_value ("__UINT32_TYPE__", UINT32_TYPE
, 0);
6516 builtin_define_with_value ("__UINT64_TYPE__", UINT64_TYPE
, 0);
6517 if (INT_LEAST8_TYPE
)
6518 builtin_define_with_value ("__INT_LEAST8_TYPE__", INT_LEAST8_TYPE
, 0);
6519 if (INT_LEAST16_TYPE
)
6520 builtin_define_with_value ("__INT_LEAST16_TYPE__", INT_LEAST16_TYPE
, 0);
6521 if (INT_LEAST32_TYPE
)
6522 builtin_define_with_value ("__INT_LEAST32_TYPE__", INT_LEAST32_TYPE
, 0);
6523 if (INT_LEAST64_TYPE
)
6524 builtin_define_with_value ("__INT_LEAST64_TYPE__", INT_LEAST64_TYPE
, 0);
6525 if (UINT_LEAST8_TYPE
)
6526 builtin_define_with_value ("__UINT_LEAST8_TYPE__", UINT_LEAST8_TYPE
, 0);
6527 if (UINT_LEAST16_TYPE
)
6528 builtin_define_with_value ("__UINT_LEAST16_TYPE__", UINT_LEAST16_TYPE
, 0);
6529 if (UINT_LEAST32_TYPE
)
6530 builtin_define_with_value ("__UINT_LEAST32_TYPE__", UINT_LEAST32_TYPE
, 0);
6531 if (UINT_LEAST64_TYPE
)
6532 builtin_define_with_value ("__UINT_LEAST64_TYPE__", UINT_LEAST64_TYPE
, 0);
6534 builtin_define_with_value ("__INT_FAST8_TYPE__", INT_FAST8_TYPE
, 0);
6535 if (INT_FAST16_TYPE
)
6536 builtin_define_with_value ("__INT_FAST16_TYPE__", INT_FAST16_TYPE
, 0);
6537 if (INT_FAST32_TYPE
)
6538 builtin_define_with_value ("__INT_FAST32_TYPE__", INT_FAST32_TYPE
, 0);
6539 if (INT_FAST64_TYPE
)
6540 builtin_define_with_value ("__INT_FAST64_TYPE__", INT_FAST64_TYPE
, 0);
6541 if (UINT_FAST8_TYPE
)
6542 builtin_define_with_value ("__UINT_FAST8_TYPE__", UINT_FAST8_TYPE
, 0);
6543 if (UINT_FAST16_TYPE
)
6544 builtin_define_with_value ("__UINT_FAST16_TYPE__", UINT_FAST16_TYPE
, 0);
6545 if (UINT_FAST32_TYPE
)
6546 builtin_define_with_value ("__UINT_FAST32_TYPE__", UINT_FAST32_TYPE
, 0);
6547 if (UINT_FAST64_TYPE
)
6548 builtin_define_with_value ("__UINT_FAST64_TYPE__", UINT_FAST64_TYPE
, 0);
6550 builtin_define_with_value ("__INTPTR_TYPE__", INTPTR_TYPE
, 0);
6552 builtin_define_with_value ("__UINTPTR_TYPE__", UINTPTR_TYPE
, 0);
6556 c_init_attributes (void)
6558 /* Fill in the built_in_attributes array. */
6559 #define DEF_ATTR_NULL_TREE(ENUM) \
6560 built_in_attributes[(int) ENUM] = NULL_TREE;
6561 #define DEF_ATTR_INT(ENUM, VALUE) \
6562 built_in_attributes[(int) ENUM] = build_int_cst (integer_type_node, VALUE);
6563 #define DEF_ATTR_STRING(ENUM, VALUE) \
6564 built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
6565 #define DEF_ATTR_IDENT(ENUM, STRING) \
6566 built_in_attributes[(int) ENUM] = get_identifier (STRING);
6567 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
6568 built_in_attributes[(int) ENUM] \
6569 = tree_cons (built_in_attributes[(int) PURPOSE], \
6570 built_in_attributes[(int) VALUE], \
6571 built_in_attributes[(int) CHAIN]);
6572 #include "builtin-attrs.def"
6573 #undef DEF_ATTR_NULL_TREE
6575 #undef DEF_ATTR_IDENT
6576 #undef DEF_ATTR_TREE_LIST
6579 /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain
6580 identifier as an argument, so the front end shouldn't look it up. */
6583 attribute_takes_identifier_p (const_tree attr_id
)
6585 const struct attribute_spec
*spec
= lookup_attribute_spec (attr_id
);
6587 /* Unknown attribute that we'll end up ignoring, return true so we
6588 don't complain about an identifier argument. */
6590 else if (!strcmp ("mode", spec
->name
)
6591 || !strcmp ("format", spec
->name
)
6592 || !strcmp ("cleanup", spec
->name
))
6595 return targetm
.attribute_takes_identifier_p (attr_id
);
6598 /* Attribute handlers common to C front ends. */
6600 /* Handle a "packed" attribute; arguments as in
6601 struct attribute_spec.handler. */
6604 handle_packed_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6605 int flags
, bool *no_add_attrs
)
6609 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6610 *node
= build_variant_type_copy (*node
);
6611 TYPE_PACKED (*node
) = 1;
6613 else if (TREE_CODE (*node
) == FIELD_DECL
)
6615 if (TYPE_ALIGN (TREE_TYPE (*node
)) <= BITS_PER_UNIT
6616 /* Still pack bitfields. */
6617 && ! DECL_INITIAL (*node
))
6618 warning (OPT_Wattributes
,
6619 "%qE attribute ignored for field of type %qT",
6620 name
, TREE_TYPE (*node
));
6622 DECL_PACKED (*node
) = 1;
6624 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
6625 used for DECL_REGISTER. It wouldn't mean anything anyway.
6626 We can't set DECL_PACKED on the type of a TYPE_DECL, because
6627 that changes what the typedef is typing. */
6630 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6631 *no_add_attrs
= true;
6637 /* Handle a "nocommon" attribute; arguments as in
6638 struct attribute_spec.handler. */
6641 handle_nocommon_attribute (tree
*node
, tree name
,
6642 tree
ARG_UNUSED (args
),
6643 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6645 if (TREE_CODE (*node
) == VAR_DECL
)
6646 DECL_COMMON (*node
) = 0;
6649 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6650 *no_add_attrs
= true;
6656 /* Handle a "common" attribute; arguments as in
6657 struct attribute_spec.handler. */
6660 handle_common_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6661 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6663 if (TREE_CODE (*node
) == VAR_DECL
)
6664 DECL_COMMON (*node
) = 1;
6667 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6668 *no_add_attrs
= true;
6674 /* Handle a "noreturn" attribute; arguments as in
6675 struct attribute_spec.handler. */
6678 handle_noreturn_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6679 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6681 tree type
= TREE_TYPE (*node
);
6683 /* See FIXME comment in c_common_attribute_table. */
6684 if (TREE_CODE (*node
) == FUNCTION_DECL
6685 || objc_method_decl (TREE_CODE (*node
)))
6686 TREE_THIS_VOLATILE (*node
) = 1;
6687 else if (TREE_CODE (type
) == POINTER_TYPE
6688 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
6690 = (build_qualified_type
6692 (build_type_variant (TREE_TYPE (type
),
6693 TYPE_READONLY (TREE_TYPE (type
)), 1)),
6694 TYPE_QUALS (type
)));
6697 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6698 *no_add_attrs
= true;
6704 /* Handle a "hot" and attribute; arguments as in
6705 struct attribute_spec.handler. */
6708 handle_hot_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6709 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6711 if (TREE_CODE (*node
) == FUNCTION_DECL
6712 || TREE_CODE (*node
) == LABEL_DECL
)
6714 if (lookup_attribute ("cold", DECL_ATTRIBUTES (*node
)) != NULL
)
6716 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
6717 "with attribute %qs", name
, "cold");
6718 *no_add_attrs
= true;
6720 /* Most of the rest of the hot processing is done later with
6721 lookup_attribute. */
6725 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6726 *no_add_attrs
= true;
6732 /* Handle a "cold" and attribute; arguments as in
6733 struct attribute_spec.handler. */
6736 handle_cold_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6737 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6739 if (TREE_CODE (*node
) == FUNCTION_DECL
6740 || TREE_CODE (*node
) == LABEL_DECL
)
6742 if (lookup_attribute ("hot", DECL_ATTRIBUTES (*node
)) != NULL
)
6744 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
6745 "with attribute %qs", name
, "hot");
6746 *no_add_attrs
= true;
6748 /* Most of the rest of the cold processing is done later with
6749 lookup_attribute. */
6753 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6754 *no_add_attrs
= true;
6760 /* Handle a "no_sanitize_address" attribute; arguments as in
6761 struct attribute_spec.handler. */
6764 handle_no_sanitize_address_attribute (tree
*node
, tree name
, tree
, int,
6767 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6769 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6770 *no_add_attrs
= true;
6776 /* Handle a "no_address_safety_analysis" attribute; arguments as in
6777 struct attribute_spec.handler. */
6780 handle_no_address_safety_analysis_attribute (tree
*node
, tree name
, tree
, int,
6783 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6784 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6785 else if (!lookup_attribute ("no_sanitize_address", DECL_ATTRIBUTES (*node
)))
6786 DECL_ATTRIBUTES (*node
)
6787 = tree_cons (get_identifier ("no_sanitize_address"),
6788 NULL_TREE
, DECL_ATTRIBUTES (*node
));
6789 *no_add_attrs
= true;
6793 /* Handle a "no_sanitize_undefined" attribute; arguments as in
6794 struct attribute_spec.handler. */
6797 handle_no_sanitize_undefined_attribute (tree
*node
, tree name
, tree
, int,
6800 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6802 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6803 *no_add_attrs
= true;
6809 /* Handle a "stack_protect" attribute; arguments as in
6810 struct attribute_spec.handler. */
6812 handle_stack_protect_attribute (tree
*node
, tree name
, tree
, int,
6815 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6817 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6818 *no_add_attrs
= true;
6821 DECL_ATTRIBUTES (*node
)
6822 = tree_cons (get_identifier ("stack_protect"),
6823 NULL_TREE
, DECL_ATTRIBUTES (*node
));
6828 /* Handle a "noinline" attribute; arguments as in
6829 struct attribute_spec.handler. */
6832 handle_noinline_attribute (tree
*node
, tree name
,
6833 tree
ARG_UNUSED (args
),
6834 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6836 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6838 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node
)))
6840 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
6841 "with attribute %qs", name
, "always_inline");
6842 *no_add_attrs
= true;
6845 DECL_UNINLINABLE (*node
) = 1;
6849 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6850 *no_add_attrs
= true;
6856 /* Handle a "noclone" attribute; arguments as in
6857 struct attribute_spec.handler. */
6860 handle_noclone_attribute (tree
*node
, tree name
,
6861 tree
ARG_UNUSED (args
),
6862 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6864 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6866 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6867 *no_add_attrs
= true;
6873 /* Handle a "no_icf" attribute; arguments as in
6874 struct attribute_spec.handler. */
6877 handle_noicf_attribute (tree
*node
, tree name
,
6878 tree
ARG_UNUSED (args
),
6879 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6881 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6883 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6884 *no_add_attrs
= true;
6891 /* Handle a "always_inline" attribute; arguments as in
6892 struct attribute_spec.handler. */
6895 handle_always_inline_attribute (tree
*node
, tree name
,
6896 tree
ARG_UNUSED (args
),
6897 int ARG_UNUSED (flags
),
6900 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6902 if (lookup_attribute ("noinline", DECL_ATTRIBUTES (*node
)))
6904 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
6905 "with %qs attribute", name
, "noinline");
6906 *no_add_attrs
= true;
6909 /* Set the attribute and mark it for disregarding inline
6911 DECL_DISREGARD_INLINE_LIMITS (*node
) = 1;
6915 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6916 *no_add_attrs
= true;
6922 /* Handle a "gnu_inline" attribute; arguments as in
6923 struct attribute_spec.handler. */
6926 handle_gnu_inline_attribute (tree
*node
, tree name
,
6927 tree
ARG_UNUSED (args
),
6928 int ARG_UNUSED (flags
),
6931 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
6933 /* Do nothing else, just set the attribute. We'll get at
6934 it later with lookup_attribute. */
6938 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6939 *no_add_attrs
= true;
6945 /* Handle a "leaf" attribute; arguments as in
6946 struct attribute_spec.handler. */
6949 handle_leaf_attribute (tree
*node
, tree name
,
6950 tree
ARG_UNUSED (args
),
6951 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6953 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6955 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6956 *no_add_attrs
= true;
6958 if (!TREE_PUBLIC (*node
))
6960 warning (OPT_Wattributes
, "%qE attribute has no effect on unit local functions", name
);
6961 *no_add_attrs
= true;
6967 /* Handle an "artificial" attribute; arguments as in
6968 struct attribute_spec.handler. */
6971 handle_artificial_attribute (tree
*node
, tree name
,
6972 tree
ARG_UNUSED (args
),
6973 int ARG_UNUSED (flags
),
6976 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
6978 /* Do nothing else, just set the attribute. We'll get at
6979 it later with lookup_attribute. */
6983 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6984 *no_add_attrs
= true;
6990 /* Handle a "flatten" attribute; arguments as in
6991 struct attribute_spec.handler. */
6994 handle_flatten_attribute (tree
*node
, tree name
,
6995 tree args ATTRIBUTE_UNUSED
,
6996 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
6998 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6999 /* Do nothing else, just set the attribute. We'll get at
7000 it later with lookup_attribute. */
7004 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7005 *no_add_attrs
= true;
7011 /* Handle a "warning" or "error" attribute; arguments as in
7012 struct attribute_spec.handler. */
7015 handle_error_attribute (tree
*node
, tree name
, tree args
,
7016 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7018 if (TREE_CODE (*node
) == FUNCTION_DECL
7019 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
7020 /* Do nothing else, just set the attribute. We'll get at
7021 it later with lookup_attribute. */
7025 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7026 *no_add_attrs
= true;
7032 /* Handle a "used" attribute; arguments as in
7033 struct attribute_spec.handler. */
7036 handle_used_attribute (tree
*pnode
, tree name
, tree
ARG_UNUSED (args
),
7037 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7041 if (TREE_CODE (node
) == FUNCTION_DECL
7042 || (TREE_CODE (node
) == VAR_DECL
&& TREE_STATIC (node
))
7043 || (TREE_CODE (node
) == TYPE_DECL
))
7045 TREE_USED (node
) = 1;
7046 DECL_PRESERVE_P (node
) = 1;
7047 if (TREE_CODE (node
) == VAR_DECL
)
7048 DECL_READ_P (node
) = 1;
7052 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7053 *no_add_attrs
= true;
7059 /* Handle a "unused" attribute; arguments as in
7060 struct attribute_spec.handler. */
7063 handle_unused_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7064 int flags
, bool *no_add_attrs
)
7070 if (TREE_CODE (decl
) == PARM_DECL
7071 || TREE_CODE (decl
) == VAR_DECL
7072 || TREE_CODE (decl
) == FUNCTION_DECL
7073 || TREE_CODE (decl
) == LABEL_DECL
7074 || TREE_CODE (decl
) == TYPE_DECL
)
7076 TREE_USED (decl
) = 1;
7077 if (TREE_CODE (decl
) == VAR_DECL
7078 || TREE_CODE (decl
) == PARM_DECL
)
7079 DECL_READ_P (decl
) = 1;
7083 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7084 *no_add_attrs
= true;
7089 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7090 *node
= build_variant_type_copy (*node
);
7091 TREE_USED (*node
) = 1;
7097 /* Handle a "externally_visible" attribute; arguments as in
7098 struct attribute_spec.handler. */
7101 handle_externally_visible_attribute (tree
*pnode
, tree name
,
7102 tree
ARG_UNUSED (args
),
7103 int ARG_UNUSED (flags
),
7108 if (TREE_CODE (node
) == FUNCTION_DECL
|| TREE_CODE (node
) == VAR_DECL
)
7110 if ((!TREE_STATIC (node
) && TREE_CODE (node
) != FUNCTION_DECL
7111 && !DECL_EXTERNAL (node
)) || !TREE_PUBLIC (node
))
7113 warning (OPT_Wattributes
,
7114 "%qE attribute have effect only on public objects", name
);
7115 *no_add_attrs
= true;
7120 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7121 *no_add_attrs
= true;
7127 /* Handle the "no_reorder" attribute. Arguments as in
7128 struct attribute_spec.handler. */
7131 handle_no_reorder_attribute (tree
*pnode
,
7139 if ((TREE_CODE (node
) != FUNCTION_DECL
&& TREE_CODE (node
) != VAR_DECL
)
7140 && !(TREE_STATIC (node
) || DECL_EXTERNAL (node
)))
7142 warning (OPT_Wattributes
,
7143 "%qE attribute only affects top level objects",
7145 *no_add_attrs
= true;
7151 /* Handle a "const" attribute; arguments as in
7152 struct attribute_spec.handler. */
7155 handle_const_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7156 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7158 tree type
= TREE_TYPE (*node
);
7160 /* See FIXME comment on noreturn in c_common_attribute_table. */
7161 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7162 TREE_READONLY (*node
) = 1;
7163 else if (TREE_CODE (type
) == POINTER_TYPE
7164 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
7166 = (build_qualified_type
7168 (build_type_variant (TREE_TYPE (type
), 1,
7169 TREE_THIS_VOLATILE (TREE_TYPE (type
)))),
7170 TYPE_QUALS (type
)));
7173 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7174 *no_add_attrs
= true;
7180 /* Handle a "transparent_union" attribute; arguments as in
7181 struct attribute_spec.handler. */
7184 handle_transparent_union_attribute (tree
*node
, tree name
,
7185 tree
ARG_UNUSED (args
), int flags
,
7190 *no_add_attrs
= true;
7193 if (TREE_CODE (*node
) == TYPE_DECL
7194 && ! (flags
& ATTR_FLAG_CXX11
))
7195 node
= &TREE_TYPE (*node
);
7198 if (TREE_CODE (type
) == UNION_TYPE
)
7200 /* Make sure that the first field will work for a transparent union.
7201 If the type isn't complete yet, leave the check to the code in
7203 if (TYPE_SIZE (type
))
7205 tree first
= first_field (type
);
7206 if (first
== NULL_TREE
7207 || DECL_ARTIFICIAL (first
)
7208 || TYPE_MODE (type
) != DECL_MODE (first
))
7212 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7214 /* If the type isn't complete yet, setting the flag
7215 on a variant wouldn't ever be checked. */
7216 if (!TYPE_SIZE (type
))
7219 /* build_duplicate_type doesn't work for C++. */
7220 if (c_dialect_cxx ())
7223 /* A type variant isn't good enough, since we don't a cast
7224 to such a type removed as a no-op. */
7225 *node
= type
= build_duplicate_type (type
);
7228 TYPE_TRANSPARENT_AGGR (type
) = 1;
7233 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7237 /* Subroutine of handle_{con,de}structor_attribute. Evaluate ARGS to
7238 get the requested priority for a constructor or destructor,
7239 possibly issuing diagnostics for invalid or reserved
7242 static priority_type
7243 get_priority (tree args
, bool is_destructor
)
7249 return DEFAULT_INIT_PRIORITY
;
7251 if (!SUPPORTS_INIT_PRIORITY
)
7254 error ("destructor priorities are not supported");
7256 error ("constructor priorities are not supported");
7257 return DEFAULT_INIT_PRIORITY
;
7260 arg
= TREE_VALUE (args
);
7261 if (TREE_CODE (arg
) == IDENTIFIER_NODE
)
7263 if (arg
== error_mark_node
)
7264 return DEFAULT_INIT_PRIORITY
;
7265 arg
= default_conversion (arg
);
7266 if (!tree_fits_shwi_p (arg
)
7267 || !INTEGRAL_TYPE_P (TREE_TYPE (arg
)))
7270 pri
= tree_to_shwi (arg
);
7271 if (pri
< 0 || pri
> MAX_INIT_PRIORITY
)
7274 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
7278 "destructor priorities from 0 to %d are reserved "
7279 "for the implementation",
7280 MAX_RESERVED_INIT_PRIORITY
);
7283 "constructor priorities from 0 to %d are reserved "
7284 "for the implementation",
7285 MAX_RESERVED_INIT_PRIORITY
);
7291 error ("destructor priorities must be integers from 0 to %d inclusive",
7294 error ("constructor priorities must be integers from 0 to %d inclusive",
7296 return DEFAULT_INIT_PRIORITY
;
7299 /* Handle a "constructor" attribute; arguments as in
7300 struct attribute_spec.handler. */
7303 handle_constructor_attribute (tree
*node
, tree name
, tree args
,
7304 int ARG_UNUSED (flags
),
7308 tree type
= TREE_TYPE (decl
);
7310 if (TREE_CODE (decl
) == FUNCTION_DECL
7311 && TREE_CODE (type
) == FUNCTION_TYPE
7312 && decl_function_context (decl
) == 0)
7314 priority_type priority
;
7315 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
7316 priority
= get_priority (args
, /*is_destructor=*/false);
7317 SET_DECL_INIT_PRIORITY (decl
, priority
);
7318 TREE_USED (decl
) = 1;
7322 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7323 *no_add_attrs
= true;
7329 /* Handle a "destructor" attribute; arguments as in
7330 struct attribute_spec.handler. */
7333 handle_destructor_attribute (tree
*node
, tree name
, tree args
,
7334 int ARG_UNUSED (flags
),
7338 tree type
= TREE_TYPE (decl
);
7340 if (TREE_CODE (decl
) == FUNCTION_DECL
7341 && TREE_CODE (type
) == FUNCTION_TYPE
7342 && decl_function_context (decl
) == 0)
7344 priority_type priority
;
7345 DECL_STATIC_DESTRUCTOR (decl
) = 1;
7346 priority
= get_priority (args
, /*is_destructor=*/true);
7347 SET_DECL_FINI_PRIORITY (decl
, priority
);
7348 TREE_USED (decl
) = 1;
7352 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7353 *no_add_attrs
= true;
7359 /* Nonzero if the mode is a valid vector mode for this architecture.
7360 This returns nonzero even if there is no hardware support for the
7361 vector mode, but we can emulate with narrower modes. */
7364 vector_mode_valid_p (machine_mode mode
)
7366 enum mode_class mclass
= GET_MODE_CLASS (mode
);
7367 machine_mode innermode
;
7369 /* Doh! What's going on? */
7370 if (mclass
!= MODE_VECTOR_INT
7371 && mclass
!= MODE_VECTOR_FLOAT
7372 && mclass
!= MODE_VECTOR_FRACT
7373 && mclass
!= MODE_VECTOR_UFRACT
7374 && mclass
!= MODE_VECTOR_ACCUM
7375 && mclass
!= MODE_VECTOR_UACCUM
)
7378 /* Hardware support. Woo hoo! */
7379 if (targetm
.vector_mode_supported_p (mode
))
7382 innermode
= GET_MODE_INNER (mode
);
7384 /* We should probably return 1 if requesting V4DI and we have no DI,
7385 but we have V2DI, but this is probably very unlikely. */
7387 /* If we have support for the inner mode, we can safely emulate it.
7388 We may not have V2DI, but me can emulate with a pair of DIs. */
7389 return targetm
.scalar_mode_supported_p (innermode
);
7393 /* Handle a "mode" attribute; arguments as in
7394 struct attribute_spec.handler. */
7397 handle_mode_attribute (tree
*node
, tree name
, tree args
,
7398 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7401 tree ident
= TREE_VALUE (args
);
7403 *no_add_attrs
= true;
7405 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
7406 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7410 const char *p
= IDENTIFIER_POINTER (ident
);
7411 int len
= strlen (p
);
7412 machine_mode mode
= VOIDmode
;
7416 if (len
> 4 && p
[0] == '_' && p
[1] == '_'
7417 && p
[len
- 1] == '_' && p
[len
- 2] == '_')
7419 char *newp
= (char *) alloca (len
- 1);
7421 strcpy (newp
, &p
[2]);
7422 newp
[len
- 4] = '\0';
7426 /* Change this type to have a type with the specified mode.
7427 First check for the special modes. */
7428 if (!strcmp (p
, "byte"))
7430 else if (!strcmp (p
, "word"))
7432 else if (!strcmp (p
, "pointer"))
7434 else if (!strcmp (p
, "libgcc_cmp_return"))
7435 mode
= targetm
.libgcc_cmp_return_mode ();
7436 else if (!strcmp (p
, "libgcc_shift_count"))
7437 mode
= targetm
.libgcc_shift_count_mode ();
7438 else if (!strcmp (p
, "unwind_word"))
7439 mode
= targetm
.unwind_word_mode ();
7441 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
7442 if (!strcmp (p
, GET_MODE_NAME (j
)))
7444 mode
= (machine_mode
) j
;
7448 if (mode
== VOIDmode
)
7450 error ("unknown machine mode %qE", ident
);
7455 switch (GET_MODE_CLASS (mode
))
7458 case MODE_PARTIAL_INT
:
7460 case MODE_DECIMAL_FLOAT
:
7465 valid_mode
= targetm
.scalar_mode_supported_p (mode
);
7468 case MODE_COMPLEX_INT
:
7469 case MODE_COMPLEX_FLOAT
:
7470 valid_mode
= targetm
.scalar_mode_supported_p (GET_MODE_INNER (mode
));
7473 case MODE_VECTOR_INT
:
7474 case MODE_VECTOR_FLOAT
:
7475 case MODE_VECTOR_FRACT
:
7476 case MODE_VECTOR_UFRACT
:
7477 case MODE_VECTOR_ACCUM
:
7478 case MODE_VECTOR_UACCUM
:
7479 warning (OPT_Wattributes
, "specifying vector types with "
7480 "__attribute__ ((mode)) is deprecated");
7481 warning (OPT_Wattributes
,
7482 "use __attribute__ ((vector_size)) instead");
7483 valid_mode
= vector_mode_valid_p (mode
);
7491 error ("unable to emulate %qs", p
);
7495 if (POINTER_TYPE_P (type
))
7497 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
7498 tree (*fn
)(tree
, machine_mode
, bool);
7500 if (!targetm
.addr_space
.valid_pointer_mode (mode
, as
))
7502 error ("invalid pointer mode %qs", p
);
7506 if (TREE_CODE (type
) == POINTER_TYPE
)
7507 fn
= build_pointer_type_for_mode
;
7509 fn
= build_reference_type_for_mode
;
7510 typefm
= fn (TREE_TYPE (type
), mode
, false);
7514 /* For fixed-point modes, we need to test if the signness of type
7515 and the machine mode are consistent. */
7516 if (ALL_FIXED_POINT_MODE_P (mode
)
7517 && TYPE_UNSIGNED (type
) != UNSIGNED_FIXED_POINT_MODE_P (mode
))
7519 error ("signedness of type and machine mode %qs don%'t match", p
);
7522 /* For fixed-point modes, we need to pass saturating info. */
7523 typefm
= lang_hooks
.types
.type_for_mode (mode
,
7524 ALL_FIXED_POINT_MODE_P (mode
) ? TYPE_SATURATING (type
)
7525 : TYPE_UNSIGNED (type
));
7528 if (typefm
== NULL_TREE
)
7530 error ("no data type for mode %qs", p
);
7533 else if (TREE_CODE (type
) == ENUMERAL_TYPE
)
7535 /* For enumeral types, copy the precision from the integer
7536 type returned above. If not an INTEGER_TYPE, we can't use
7537 this mode for this type. */
7538 if (TREE_CODE (typefm
) != INTEGER_TYPE
)
7540 error ("cannot use mode %qs for enumeral types", p
);
7544 if (flags
& ATTR_FLAG_TYPE_IN_PLACE
)
7546 TYPE_PRECISION (type
) = TYPE_PRECISION (typefm
);
7551 /* We cannot build a type variant, as there's code that assumes
7552 that TYPE_MAIN_VARIANT has the same mode. This includes the
7553 debug generators. Instead, create a subrange type. This
7554 results in all of the enumeral values being emitted only once
7555 in the original, and the subtype gets them by reference. */
7556 if (TYPE_UNSIGNED (type
))
7557 typefm
= make_unsigned_type (TYPE_PRECISION (typefm
));
7559 typefm
= make_signed_type (TYPE_PRECISION (typefm
));
7560 TREE_TYPE (typefm
) = type
;
7563 else if (VECTOR_MODE_P (mode
)
7564 ? TREE_CODE (type
) != TREE_CODE (TREE_TYPE (typefm
))
7565 : TREE_CODE (type
) != TREE_CODE (typefm
))
7567 error ("mode %qs applied to inappropriate type", p
);
7577 /* Handle a "section" attribute; arguments as in
7578 struct attribute_spec.handler. */
7581 handle_section_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7582 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7586 if (targetm_common
.have_named_sections
)
7588 user_defined_section_attribute
= true;
7590 if ((TREE_CODE (decl
) == FUNCTION_DECL
7591 || TREE_CODE (decl
) == VAR_DECL
)
7592 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
7594 if (TREE_CODE (decl
) == VAR_DECL
7595 && current_function_decl
!= NULL_TREE
7596 && !TREE_STATIC (decl
))
7598 error_at (DECL_SOURCE_LOCATION (decl
),
7599 "section attribute cannot be specified for "
7601 *no_add_attrs
= true;
7604 /* The decl may have already been given a section attribute
7605 from a previous declaration. Ensure they match. */
7606 else if (DECL_SECTION_NAME (decl
) != NULL
7607 && strcmp (DECL_SECTION_NAME (decl
),
7608 TREE_STRING_POINTER (TREE_VALUE (args
))) != 0)
7610 error ("section of %q+D conflicts with previous declaration",
7612 *no_add_attrs
= true;
7614 else if (TREE_CODE (decl
) == VAR_DECL
7615 && !targetm
.have_tls
&& targetm
.emutls
.tmpl_section
7616 && DECL_THREAD_LOCAL_P (decl
))
7618 error ("section of %q+D cannot be overridden", *node
);
7619 *no_add_attrs
= true;
7622 set_decl_section_name (decl
,
7623 TREE_STRING_POINTER (TREE_VALUE (args
)));
7627 error ("section attribute not allowed for %q+D", *node
);
7628 *no_add_attrs
= true;
7633 error_at (DECL_SOURCE_LOCATION (*node
),
7634 "section attributes are not supported for this target");
7635 *no_add_attrs
= true;
7641 /* Check whether ALIGN is a valid user-specified alignment. If so,
7642 return its base-2 log; if not, output an error and return -1. If
7643 ALLOW_ZERO then 0 is valid and should result in a return of -1 with
7646 check_user_alignment (const_tree align
, bool allow_zero
)
7650 if (error_operand_p (align
))
7652 if (TREE_CODE (align
) != INTEGER_CST
7653 || !INTEGRAL_TYPE_P (TREE_TYPE (align
)))
7655 error ("requested alignment is not an integer constant");
7658 else if (allow_zero
&& integer_zerop (align
))
7660 else if (tree_int_cst_sgn (align
) == -1
7661 || (i
= tree_log2 (align
)) == -1)
7663 error ("requested alignment is not a positive power of 2");
7666 else if (i
>= HOST_BITS_PER_INT
- BITS_PER_UNIT_LOG
)
7668 error ("requested alignment is too large");
7675 If in c++-11, check if the c++-11 alignment constraint with respect
7676 to fundamental alignment (in [dcl.align]) are satisfied. If not in
7677 c++-11 mode, does nothing.
7681 [* if the constant expression evaluates to a fundamental alignment,
7682 the alignment requirement of the declared entity shall be the
7683 specified fundamental alignment.
7685 * if the constant expression evaluates to an extended alignment
7686 and the implementation supports that alignment in the context
7687 of the declaration, the alignment of the declared entity shall
7690 * if the constant expression evaluates to an extended alignment
7691 and the implementation does not support that alignment in the
7692 context of the declaration, the program is ill-formed]. */
7695 check_cxx_fundamental_alignment_constraints (tree node
,
7699 bool alignment_too_large_p
= false;
7700 unsigned requested_alignment
= 1U << align_log
;
7701 unsigned max_align
= 0;
7703 if ((!(flags
& ATTR_FLAG_CXX11
) && !warn_cxx_compat
)
7704 || (node
== NULL_TREE
|| node
== error_mark_node
))
7707 if (cxx_fundamental_alignment_p (requested_alignment
))
7712 if (TREE_STATIC (node
))
7714 /* For file scope variables and static members, the target
7715 supports alignments that are at most
7716 MAX_OFILE_ALIGNMENT. */
7717 if (requested_alignment
> (max_align
= MAX_OFILE_ALIGNMENT
))
7718 alignment_too_large_p
= true;
7722 #ifdef BIGGEST_FIELD_ALIGNMENT
7723 #define MAX_TARGET_FIELD_ALIGNMENT BIGGEST_FIELD_ALIGNMENT
7725 #define MAX_TARGET_FIELD_ALIGNMENT BIGGEST_ALIGNMENT
7727 /* For non-static members, the target supports either
7728 alignments that at most either BIGGEST_FIELD_ALIGNMENT
7729 if it is defined or BIGGEST_ALIGNMENT. */
7730 max_align
= MAX_TARGET_FIELD_ALIGNMENT
;
7731 if (TREE_CODE (node
) == FIELD_DECL
7732 && requested_alignment
> (max_align
= MAX_TARGET_FIELD_ALIGNMENT
))
7733 alignment_too_large_p
= true;
7734 #undef MAX_TARGET_FIELD_ALIGNMENT
7735 /* For stack variables, the target supports at most
7736 MAX_STACK_ALIGNMENT. */
7737 else if (decl_function_context (node
) != NULL
7738 && requested_alignment
> (max_align
= MAX_STACK_ALIGNMENT
))
7739 alignment_too_large_p
= true;
7742 else if (TYPE_P (node
))
7744 /* Let's be liberal for types. */
7745 if (requested_alignment
> (max_align
= BIGGEST_ALIGNMENT
))
7746 alignment_too_large_p
= true;
7749 if (alignment_too_large_p
)
7750 pedwarn (input_location
, OPT_Wattributes
,
7751 "requested alignment %d is larger than %d",
7752 requested_alignment
, max_align
);
7754 return !alignment_too_large_p
;
7757 /* Handle a "aligned" attribute; arguments as in
7758 struct attribute_spec.handler. */
7761 handle_aligned_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7762 int flags
, bool *no_add_attrs
)
7764 tree decl
= NULL_TREE
;
7772 align_expr
= TREE_VALUE (args
);
7773 if (align_expr
&& TREE_CODE (align_expr
) != IDENTIFIER_NODE
7774 && TREE_CODE (align_expr
) != FUNCTION_DECL
)
7775 align_expr
= default_conversion (align_expr
);
7778 align_expr
= size_int (ATTRIBUTE_ALIGNED_VALUE
/ BITS_PER_UNIT
);
7783 type
= &TREE_TYPE (decl
);
7784 is_type
= TREE_CODE (*node
) == TYPE_DECL
;
7786 else if (TYPE_P (*node
))
7787 type
= node
, is_type
= 1;
7789 if ((i
= check_user_alignment (align_expr
, false)) == -1
7790 || !check_cxx_fundamental_alignment_constraints (*node
, i
, flags
))
7791 *no_add_attrs
= true;
7794 if ((flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7795 /* OK, modify the type in place. */;
7796 /* If we have a TYPE_DECL, then copy the type, so that we
7797 don't accidentally modify a builtin type. See pushdecl. */
7798 else if (decl
&& TREE_TYPE (decl
) != error_mark_node
7799 && DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
)
7801 tree tt
= TREE_TYPE (decl
);
7802 *type
= build_variant_type_copy (*type
);
7803 DECL_ORIGINAL_TYPE (decl
) = tt
;
7804 TYPE_NAME (*type
) = decl
;
7805 TREE_USED (*type
) = TREE_USED (decl
);
7806 TREE_TYPE (decl
) = *type
;
7809 *type
= build_variant_type_copy (*type
);
7811 TYPE_ALIGN (*type
) = (1U << i
) * BITS_PER_UNIT
;
7812 TYPE_USER_ALIGN (*type
) = 1;
7814 else if (! VAR_OR_FUNCTION_DECL_P (decl
)
7815 && TREE_CODE (decl
) != FIELD_DECL
)
7817 error ("alignment may not be specified for %q+D", decl
);
7818 *no_add_attrs
= true;
7820 else if (DECL_USER_ALIGN (decl
)
7821 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
7822 /* C++-11 [dcl.align/4]:
7824 When multiple alignment-specifiers are specified for an
7825 entity, the alignment requirement shall be set to the
7826 strictest specified alignment.
7828 This formally comes from the c++11 specification but we are
7829 doing it for the GNU attribute syntax as well. */
7830 *no_add_attrs
= true;
7831 else if (TREE_CODE (decl
) == FUNCTION_DECL
7832 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
7834 if (DECL_USER_ALIGN (decl
))
7835 error ("alignment for %q+D was previously specified as %d "
7836 "and may not be decreased", decl
,
7837 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
7839 error ("alignment for %q+D must be at least %d", decl
,
7840 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
7841 *no_add_attrs
= true;
7845 DECL_ALIGN (decl
) = (1U << i
) * BITS_PER_UNIT
;
7846 DECL_USER_ALIGN (decl
) = 1;
7852 /* Handle a "weak" attribute; arguments as in
7853 struct attribute_spec.handler. */
7856 handle_weak_attribute (tree
*node
, tree name
,
7857 tree
ARG_UNUSED (args
),
7858 int ARG_UNUSED (flags
),
7859 bool * ARG_UNUSED (no_add_attrs
))
7861 if (TREE_CODE (*node
) == FUNCTION_DECL
7862 && DECL_DECLARED_INLINE_P (*node
))
7864 warning (OPT_Wattributes
, "inline function %q+D declared weak", *node
);
7865 *no_add_attrs
= true;
7867 else if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
7869 error ("indirect function %q+D cannot be declared weak", *node
);
7870 *no_add_attrs
= true;
7873 else if (TREE_CODE (*node
) == FUNCTION_DECL
7874 || TREE_CODE (*node
) == VAR_DECL
)
7876 struct symtab_node
*n
= symtab_node::get (*node
);
7877 if (n
&& n
->refuse_visibility_changes
)
7878 error ("%+D declared weak after being used", *node
);
7879 declare_weak (*node
);
7882 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7887 /* Handle an "alias" or "ifunc" attribute; arguments as in
7888 struct attribute_spec.handler, except that IS_ALIAS tells us
7889 whether this is an alias as opposed to ifunc attribute. */
7892 handle_alias_ifunc_attribute (bool is_alias
, tree
*node
, tree name
, tree args
,
7897 if (TREE_CODE (decl
) != FUNCTION_DECL
7898 && (!is_alias
|| TREE_CODE (decl
) != VAR_DECL
))
7900 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7901 *no_add_attrs
= true;
7903 else if ((TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INITIAL (decl
))
7904 || (TREE_CODE (decl
) != FUNCTION_DECL
7905 && TREE_PUBLIC (decl
) && !DECL_EXTERNAL (decl
))
7906 /* A static variable declaration is always a tentative definition,
7907 but the alias is a non-tentative definition which overrides. */
7908 || (TREE_CODE (decl
) != FUNCTION_DECL
7909 && ! TREE_PUBLIC (decl
) && DECL_INITIAL (decl
)))
7911 error ("%q+D defined both normally and as %qE attribute", decl
, name
);
7912 *no_add_attrs
= true;
7916 && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
7917 || lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
))))
7919 error ("weak %q+D cannot be defined %qE", decl
, name
);
7920 *no_add_attrs
= true;
7924 /* Note that the very first time we process a nested declaration,
7925 decl_function_context will not be set. Indeed, *would* never
7926 be set except for the DECL_INITIAL/DECL_EXTERNAL frobbery that
7927 we do below. After such frobbery, pushdecl would set the context.
7928 In any case, this is never what we want. */
7929 else if (decl_function_context (decl
) == 0 && current_function_decl
== NULL
)
7933 id
= TREE_VALUE (args
);
7934 if (TREE_CODE (id
) != STRING_CST
)
7936 error ("attribute %qE argument not a string", name
);
7937 *no_add_attrs
= true;
7940 id
= get_identifier (TREE_STRING_POINTER (id
));
7941 /* This counts as a use of the object pointed to. */
7944 if (TREE_CODE (decl
) == FUNCTION_DECL
)
7945 DECL_INITIAL (decl
) = error_mark_node
;
7947 TREE_STATIC (decl
) = 1;
7950 /* ifuncs are also aliases, so set that attribute too. */
7951 DECL_ATTRIBUTES (decl
)
7952 = tree_cons (get_identifier ("alias"), args
, DECL_ATTRIBUTES (decl
));
7956 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7957 *no_add_attrs
= true;
7960 if (decl_in_symtab_p (*node
))
7962 struct symtab_node
*n
= symtab_node::get (decl
);
7963 if (n
&& n
->refuse_visibility_changes
)
7966 error ("%+D declared alias after being used", decl
);
7968 error ("%+D declared ifunc after being used", decl
);
7976 /* Handle an "alias" or "ifunc" attribute; arguments as in
7977 struct attribute_spec.handler. */
7980 handle_ifunc_attribute (tree
*node
, tree name
, tree args
,
7981 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7983 return handle_alias_ifunc_attribute (false, node
, name
, args
, no_add_attrs
);
7986 /* Handle an "alias" or "ifunc" attribute; arguments as in
7987 struct attribute_spec.handler. */
7990 handle_alias_attribute (tree
*node
, tree name
, tree args
,
7991 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7993 return handle_alias_ifunc_attribute (true, node
, name
, args
, no_add_attrs
);
7996 /* Handle a "weakref" attribute; arguments as in struct
7997 attribute_spec.handler. */
8000 handle_weakref_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
8001 int flags
, bool *no_add_attrs
)
8003 tree attr
= NULL_TREE
;
8005 /* We must ignore the attribute when it is associated with
8006 local-scoped decls, since attribute alias is ignored and many
8007 such symbols do not even have a DECL_WEAK field. */
8008 if (decl_function_context (*node
)
8009 || current_function_decl
8010 || (TREE_CODE (*node
) != VAR_DECL
&& TREE_CODE (*node
) != FUNCTION_DECL
))
8012 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8013 *no_add_attrs
= true;
8017 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
8019 error ("indirect function %q+D cannot be declared weakref", *node
);
8020 *no_add_attrs
= true;
8024 /* The idea here is that `weakref("name")' mutates into `weakref,
8025 alias("name")', and weakref without arguments, in turn,
8026 implicitly adds weak. */
8030 attr
= tree_cons (get_identifier ("alias"), args
, attr
);
8031 attr
= tree_cons (get_identifier ("weakref"), NULL_TREE
, attr
);
8033 *no_add_attrs
= true;
8035 decl_attributes (node
, attr
, flags
);
8039 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node
)))
8040 error_at (DECL_SOURCE_LOCATION (*node
),
8041 "weakref attribute must appear before alias attribute");
8043 /* Can't call declare_weak because it wants this to be TREE_PUBLIC,
8044 and that isn't supported; and because it wants to add it to
8045 the list of weak decls, which isn't helpful. */
8046 DECL_WEAK (*node
) = 1;
8049 if (decl_in_symtab_p (*node
))
8051 struct symtab_node
*n
= symtab_node::get (*node
);
8052 if (n
&& n
->refuse_visibility_changes
)
8053 error ("%+D declared weakref after being used", *node
);
8059 /* Handle an "visibility" attribute; arguments as in
8060 struct attribute_spec.handler. */
8063 handle_visibility_attribute (tree
*node
, tree name
, tree args
,
8064 int ARG_UNUSED (flags
),
8065 bool *ARG_UNUSED (no_add_attrs
))
8068 tree id
= TREE_VALUE (args
);
8069 enum symbol_visibility vis
;
8073 if (TREE_CODE (*node
) == ENUMERAL_TYPE
)
8075 else if (TREE_CODE (*node
) != RECORD_TYPE
&& TREE_CODE (*node
) != UNION_TYPE
)
8077 warning (OPT_Wattributes
, "%qE attribute ignored on non-class types",
8081 else if (TYPE_FIELDS (*node
))
8083 error ("%qE attribute ignored because %qT is already defined",
8088 else if (decl_function_context (decl
) != 0 || !TREE_PUBLIC (decl
))
8090 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8094 if (TREE_CODE (id
) != STRING_CST
)
8096 error ("visibility argument not a string");
8100 /* If this is a type, set the visibility on the type decl. */
8103 decl
= TYPE_NAME (decl
);
8106 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
8108 warning (OPT_Wattributes
, "%qE attribute ignored on types",
8114 if (strcmp (TREE_STRING_POINTER (id
), "default") == 0)
8115 vis
= VISIBILITY_DEFAULT
;
8116 else if (strcmp (TREE_STRING_POINTER (id
), "internal") == 0)
8117 vis
= VISIBILITY_INTERNAL
;
8118 else if (strcmp (TREE_STRING_POINTER (id
), "hidden") == 0)
8119 vis
= VISIBILITY_HIDDEN
;
8120 else if (strcmp (TREE_STRING_POINTER (id
), "protected") == 0)
8121 vis
= VISIBILITY_PROTECTED
;
8124 error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
8125 vis
= VISIBILITY_DEFAULT
;
8128 if (DECL_VISIBILITY_SPECIFIED (decl
)
8129 && vis
!= DECL_VISIBILITY (decl
))
8131 tree attributes
= (TYPE_P (*node
)
8132 ? TYPE_ATTRIBUTES (*node
)
8133 : DECL_ATTRIBUTES (decl
));
8134 if (lookup_attribute ("visibility", attributes
))
8135 error ("%qD redeclared with different visibility", decl
);
8136 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
8137 && lookup_attribute ("dllimport", attributes
))
8138 error ("%qD was declared %qs which implies default visibility",
8140 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
8141 && lookup_attribute ("dllexport", attributes
))
8142 error ("%qD was declared %qs which implies default visibility",
8146 DECL_VISIBILITY (decl
) = vis
;
8147 DECL_VISIBILITY_SPECIFIED (decl
) = 1;
8149 /* Go ahead and attach the attribute to the node as well. This is needed
8150 so we can determine whether we have VISIBILITY_DEFAULT because the
8151 visibility was not specified, or because it was explicitly overridden
8152 from the containing scope. */
8157 /* Determine the ELF symbol visibility for DECL, which is either a
8158 variable or a function. It is an error to use this function if a
8159 definition of DECL is not available in this translation unit.
8160 Returns true if the final visibility has been determined by this
8161 function; false if the caller is free to make additional
8165 c_determine_visibility (tree decl
)
8167 gcc_assert (TREE_CODE (decl
) == VAR_DECL
8168 || TREE_CODE (decl
) == FUNCTION_DECL
);
8170 /* If the user explicitly specified the visibility with an
8171 attribute, honor that. DECL_VISIBILITY will have been set during
8172 the processing of the attribute. We check for an explicit
8173 attribute, rather than just checking DECL_VISIBILITY_SPECIFIED,
8174 to distinguish the use of an attribute from the use of a "#pragma
8175 GCC visibility push(...)"; in the latter case we still want other
8176 considerations to be able to overrule the #pragma. */
8177 if (lookup_attribute ("visibility", DECL_ATTRIBUTES (decl
))
8178 || (TARGET_DLLIMPORT_DECL_ATTRIBUTES
8179 && (lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl
))
8180 || lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl
)))))
8183 /* Set default visibility to whatever the user supplied with
8184 visibility_specified depending on #pragma GCC visibility. */
8185 if (!DECL_VISIBILITY_SPECIFIED (decl
))
8187 if (visibility_options
.inpragma
8188 || DECL_VISIBILITY (decl
) != default_visibility
)
8190 DECL_VISIBILITY (decl
) = default_visibility
;
8191 DECL_VISIBILITY_SPECIFIED (decl
) = visibility_options
.inpragma
;
8192 /* If visibility changed and DECL already has DECL_RTL, ensure
8193 symbol flags are updated. */
8194 if (((TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
))
8195 || TREE_CODE (decl
) == FUNCTION_DECL
)
8196 && DECL_RTL_SET_P (decl
))
8197 make_decl_rtl (decl
);
8203 /* Handle an "tls_model" attribute; arguments as in
8204 struct attribute_spec.handler. */
8207 handle_tls_model_attribute (tree
*node
, tree name
, tree args
,
8208 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8212 enum tls_model kind
;
8214 *no_add_attrs
= true;
8216 if (TREE_CODE (decl
) != VAR_DECL
|| !DECL_THREAD_LOCAL_P (decl
))
8218 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8222 kind
= DECL_TLS_MODEL (decl
);
8223 id
= TREE_VALUE (args
);
8224 if (TREE_CODE (id
) != STRING_CST
)
8226 error ("tls_model argument not a string");
8230 if (!strcmp (TREE_STRING_POINTER (id
), "local-exec"))
8231 kind
= TLS_MODEL_LOCAL_EXEC
;
8232 else if (!strcmp (TREE_STRING_POINTER (id
), "initial-exec"))
8233 kind
= TLS_MODEL_INITIAL_EXEC
;
8234 else if (!strcmp (TREE_STRING_POINTER (id
), "local-dynamic"))
8235 kind
= optimize
? TLS_MODEL_LOCAL_DYNAMIC
: TLS_MODEL_GLOBAL_DYNAMIC
;
8236 else if (!strcmp (TREE_STRING_POINTER (id
), "global-dynamic"))
8237 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
8239 error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
8241 set_decl_tls_model (decl
, kind
);
8245 /* Handle a "no_instrument_function" attribute; arguments as in
8246 struct attribute_spec.handler. */
8249 handle_no_instrument_function_attribute (tree
*node
, tree name
,
8250 tree
ARG_UNUSED (args
),
8251 int ARG_UNUSED (flags
),
8256 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8258 error_at (DECL_SOURCE_LOCATION (decl
),
8259 "%qE attribute applies only to functions", name
);
8260 *no_add_attrs
= true;
8263 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
8268 /* Handle a "malloc" attribute; arguments as in
8269 struct attribute_spec.handler. */
8272 handle_malloc_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8273 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8275 if (TREE_CODE (*node
) == FUNCTION_DECL
8276 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node
))))
8277 DECL_IS_MALLOC (*node
) = 1;
8280 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8281 *no_add_attrs
= true;
8287 /* Handle a "alloc_size" attribute; arguments as in
8288 struct attribute_spec.handler. */
8291 handle_alloc_size_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
8292 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8294 unsigned arg_count
= type_num_arguments (*node
);
8295 for (; args
; args
= TREE_CHAIN (args
))
8297 tree position
= TREE_VALUE (args
);
8298 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
8299 && TREE_CODE (position
) != FUNCTION_DECL
)
8300 position
= default_conversion (position
);
8302 if (!tree_fits_uhwi_p (position
)
8304 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
8306 warning (OPT_Wattributes
,
8307 "alloc_size parameter outside range");
8308 *no_add_attrs
= true;
8315 /* Handle a "alloc_align" attribute; arguments as in
8316 struct attribute_spec.handler. */
8319 handle_alloc_align_attribute (tree
*node
, tree
, tree args
, int,
8322 unsigned arg_count
= type_num_arguments (*node
);
8323 tree position
= TREE_VALUE (args
);
8324 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
)
8325 position
= default_conversion (position
);
8327 if (!tree_fits_uhwi_p (position
)
8329 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
8331 warning (OPT_Wattributes
,
8332 "alloc_align parameter outside range");
8333 *no_add_attrs
= true;
8339 /* Handle a "assume_aligned" attribute; arguments as in
8340 struct attribute_spec.handler. */
8343 handle_assume_aligned_attribute (tree
*, tree
, tree args
, int,
8346 for (; args
; args
= TREE_CHAIN (args
))
8348 tree position
= TREE_VALUE (args
);
8349 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
8350 && TREE_CODE (position
) != FUNCTION_DECL
)
8351 position
= default_conversion (position
);
8353 if (TREE_CODE (position
) != INTEGER_CST
)
8355 warning (OPT_Wattributes
,
8356 "assume_aligned parameter not integer constant");
8357 *no_add_attrs
= true;
8364 /* Handle a "fn spec" attribute; arguments as in
8365 struct attribute_spec.handler. */
8368 handle_fnspec_attribute (tree
*node ATTRIBUTE_UNUSED
, tree
ARG_UNUSED (name
),
8369 tree args
, int ARG_UNUSED (flags
),
8370 bool *no_add_attrs ATTRIBUTE_UNUSED
)
8373 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
8374 && !TREE_CHAIN (args
));
8378 /* Handle a "bnd_variable_size" attribute; arguments as in
8379 struct attribute_spec.handler. */
8382 handle_bnd_variable_size_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8383 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8385 if (TREE_CODE (*node
) != FIELD_DECL
)
8387 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8388 *no_add_attrs
= true;
8394 /* Handle a "bnd_legacy" attribute; arguments as in
8395 struct attribute_spec.handler. */
8398 handle_bnd_legacy (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8399 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8401 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8403 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8404 *no_add_attrs
= true;
8410 /* Handle a "bnd_instrument" attribute; arguments as in
8411 struct attribute_spec.handler. */
8414 handle_bnd_instrument (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8415 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8417 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8419 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8420 *no_add_attrs
= true;
8426 /* Handle a "warn_unused" attribute; arguments as in
8427 struct attribute_spec.handler. */
8430 handle_warn_unused_attribute (tree
*node
, tree name
,
8431 tree args ATTRIBUTE_UNUSED
,
8432 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
8435 /* Do nothing else, just set the attribute. We'll get at
8436 it later with lookup_attribute. */
8440 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8441 *no_add_attrs
= true;
8447 /* Handle an "omp declare simd" attribute; arguments as in
8448 struct attribute_spec.handler. */
8451 handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int, bool *)
8456 /* Handle an "omp declare target" attribute; arguments as in
8457 struct attribute_spec.handler. */
8460 handle_omp_declare_target_attribute (tree
*, tree
, tree
, int, bool *)
8465 /* Handle a "returns_twice" attribute; arguments as in
8466 struct attribute_spec.handler. */
8469 handle_returns_twice_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8470 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8472 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8473 DECL_IS_RETURNS_TWICE (*node
) = 1;
8476 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8477 *no_add_attrs
= true;
8483 /* Handle a "no_limit_stack" attribute; arguments as in
8484 struct attribute_spec.handler. */
8487 handle_no_limit_stack_attribute (tree
*node
, tree name
,
8488 tree
ARG_UNUSED (args
),
8489 int ARG_UNUSED (flags
),
8494 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8496 error_at (DECL_SOURCE_LOCATION (decl
),
8497 "%qE attribute applies only to functions", name
);
8498 *no_add_attrs
= true;
8500 else if (DECL_INITIAL (decl
))
8502 error_at (DECL_SOURCE_LOCATION (decl
),
8503 "can%'t set %qE attribute after definition", name
);
8504 *no_add_attrs
= true;
8507 DECL_NO_LIMIT_STACK (decl
) = 1;
8512 /* Handle a "pure" attribute; arguments as in
8513 struct attribute_spec.handler. */
8516 handle_pure_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8517 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8519 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8520 DECL_PURE_P (*node
) = 1;
8521 /* ??? TODO: Support types. */
8524 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8525 *no_add_attrs
= true;
8531 /* Digest an attribute list destined for a transactional memory statement.
8532 ALLOWED is the set of attributes that are allowed for this statement;
8533 return the attribute we parsed. Multiple attributes are never allowed. */
8536 parse_tm_stmt_attr (tree attrs
, int allowed
)
8541 for ( ; attrs
; attrs
= TREE_CHAIN (attrs
))
8543 tree a
= TREE_PURPOSE (attrs
);
8546 if (is_attribute_p ("outer", a
))
8547 m
= TM_STMT_ATTR_OUTER
;
8549 if ((m
& allowed
) == 0)
8551 warning (OPT_Wattributes
, "%qE attribute directive ignored", a
);
8560 else if (m_seen
== m
)
8561 warning (OPT_Wattributes
, "%qE attribute duplicated", a
);
8563 warning (OPT_Wattributes
, "%qE attribute follows %qE", a
, a_seen
);
8569 /* Transform a TM attribute name into a maskable integer and back.
8570 Note that NULL (i.e. no attribute) is mapped to UNKNOWN, corresponding
8571 to how the lack of an attribute is treated. */
8574 tm_attr_to_mask (tree attr
)
8578 if (is_attribute_p ("transaction_safe", attr
))
8579 return TM_ATTR_SAFE
;
8580 if (is_attribute_p ("transaction_callable", attr
))
8581 return TM_ATTR_CALLABLE
;
8582 if (is_attribute_p ("transaction_pure", attr
))
8583 return TM_ATTR_PURE
;
8584 if (is_attribute_p ("transaction_unsafe", attr
))
8585 return TM_ATTR_IRREVOCABLE
;
8586 if (is_attribute_p ("transaction_may_cancel_outer", attr
))
8587 return TM_ATTR_MAY_CANCEL_OUTER
;
8592 tm_mask_to_attr (int mask
)
8598 str
= "transaction_safe";
8600 case TM_ATTR_CALLABLE
:
8601 str
= "transaction_callable";
8604 str
= "transaction_pure";
8606 case TM_ATTR_IRREVOCABLE
:
8607 str
= "transaction_unsafe";
8609 case TM_ATTR_MAY_CANCEL_OUTER
:
8610 str
= "transaction_may_cancel_outer";
8615 return get_identifier (str
);
8618 /* Return the first TM attribute seen in LIST. */
8621 find_tm_attribute (tree list
)
8623 for (; list
; list
= TREE_CHAIN (list
))
8625 tree name
= TREE_PURPOSE (list
);
8626 if (tm_attr_to_mask (name
) != 0)
8632 /* Handle the TM attributes; arguments as in struct attribute_spec.handler.
8633 Here we accept only function types, and verify that none of the other
8634 function TM attributes are also applied. */
8635 /* ??? We need to accept class types for C++, but not C. This greatly
8636 complicates this function, since we can no longer rely on the extra
8637 processing given by function_type_required. */
8640 handle_tm_attribute (tree
*node
, tree name
, tree args
,
8641 int flags
, bool *no_add_attrs
)
8643 /* Only one path adds the attribute; others don't. */
8644 *no_add_attrs
= true;
8646 switch (TREE_CODE (*node
))
8650 /* Only tm_callable and tm_safe apply to classes. */
8651 if (tm_attr_to_mask (name
) & ~(TM_ATTR_SAFE
| TM_ATTR_CALLABLE
))
8658 tree old_name
= find_tm_attribute (TYPE_ATTRIBUTES (*node
));
8659 if (old_name
== name
)
8661 else if (old_name
!= NULL_TREE
)
8662 error ("type was previously declared %qE", old_name
);
8664 *no_add_attrs
= false;
8670 enum tree_code subcode
= TREE_CODE (TREE_TYPE (*node
));
8671 if (subcode
== FUNCTION_TYPE
|| subcode
== METHOD_TYPE
)
8673 tree fn_tmp
= TREE_TYPE (*node
);
8674 decl_attributes (&fn_tmp
, tree_cons (name
, args
, NULL
), 0);
8675 *node
= build_pointer_type (fn_tmp
);
8682 /* If a function is next, pass it on to be tried next. */
8683 if (flags
& (int) ATTR_FLAG_FUNCTION_NEXT
)
8684 return tree_cons (name
, args
, NULL
);
8687 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8694 /* Handle the TM_WRAP attribute; arguments as in
8695 struct attribute_spec.handler. */
8698 handle_tm_wrap_attribute (tree
*node
, tree name
, tree args
,
8699 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8703 /* We don't need the attribute even on success, since we
8704 record the entry in an external table. */
8705 *no_add_attrs
= true;
8707 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8708 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8711 tree wrap_decl
= TREE_VALUE (args
);
8712 if (error_operand_p (wrap_decl
))
8714 else if (TREE_CODE (wrap_decl
) != IDENTIFIER_NODE
8715 && TREE_CODE (wrap_decl
) != VAR_DECL
8716 && TREE_CODE (wrap_decl
) != FUNCTION_DECL
)
8717 error ("%qE argument not an identifier", name
);
8720 if (TREE_CODE (wrap_decl
) == IDENTIFIER_NODE
)
8721 wrap_decl
= lookup_name (wrap_decl
);
8722 if (wrap_decl
&& TREE_CODE (wrap_decl
) == FUNCTION_DECL
)
8724 if (lang_hooks
.types_compatible_p (TREE_TYPE (decl
),
8725 TREE_TYPE (wrap_decl
)))
8726 record_tm_replacement (wrap_decl
, decl
);
8728 error ("%qD is not compatible with %qD", wrap_decl
, decl
);
8731 error ("%qE argument is not a function", name
);
8738 /* Ignore the given attribute. Used when this attribute may be usefully
8739 overridden by the target, but is not used generically. */
8742 ignore_attribute (tree
* ARG_UNUSED (node
), tree
ARG_UNUSED (name
),
8743 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
8746 *no_add_attrs
= true;
8750 /* Handle a "no vops" attribute; arguments as in
8751 struct attribute_spec.handler. */
8754 handle_novops_attribute (tree
*node
, tree
ARG_UNUSED (name
),
8755 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
8756 bool *ARG_UNUSED (no_add_attrs
))
8758 gcc_assert (TREE_CODE (*node
) == FUNCTION_DECL
);
8759 DECL_IS_NOVOPS (*node
) = 1;
8763 /* Handle a "deprecated" attribute; arguments as in
8764 struct attribute_spec.handler. */
8767 handle_deprecated_attribute (tree
*node
, tree name
,
8768 tree args
, int flags
,
8771 tree type
= NULL_TREE
;
8773 tree what
= NULL_TREE
;
8776 *no_add_attrs
= true;
8777 else if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
8779 error ("deprecated message is not a string");
8780 *no_add_attrs
= true;
8786 type
= TREE_TYPE (decl
);
8788 if (TREE_CODE (decl
) == TYPE_DECL
8789 || TREE_CODE (decl
) == PARM_DECL
8790 || TREE_CODE (decl
) == VAR_DECL
8791 || TREE_CODE (decl
) == FUNCTION_DECL
8792 || TREE_CODE (decl
) == FIELD_DECL
8793 || objc_method_decl (TREE_CODE (decl
)))
8794 TREE_DEPRECATED (decl
) = 1;
8798 else if (TYPE_P (*node
))
8800 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
8801 *node
= build_variant_type_copy (*node
);
8802 TREE_DEPRECATED (*node
) = 1;
8810 *no_add_attrs
= true;
8811 if (type
&& TYPE_NAME (type
))
8813 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
8814 what
= TYPE_NAME (*node
);
8815 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
8816 && DECL_NAME (TYPE_NAME (type
)))
8817 what
= DECL_NAME (TYPE_NAME (type
));
8820 warning (OPT_Wattributes
, "%qE attribute ignored for %qE", name
, what
);
8822 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8828 /* Handle a "vector_size" attribute; arguments as in
8829 struct attribute_spec.handler. */
8832 handle_vector_size_attribute (tree
*node
, tree name
, tree args
,
8833 int ARG_UNUSED (flags
),
8836 unsigned HOST_WIDE_INT vecsize
, nunits
;
8837 machine_mode orig_mode
;
8838 tree type
= *node
, new_type
, size
;
8840 *no_add_attrs
= true;
8842 size
= TREE_VALUE (args
);
8843 if (size
&& TREE_CODE (size
) != IDENTIFIER_NODE
8844 && TREE_CODE (size
) != FUNCTION_DECL
)
8845 size
= default_conversion (size
);
8847 if (!tree_fits_uhwi_p (size
))
8849 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8853 /* Get the vector size (in bytes). */
8854 vecsize
= tree_to_uhwi (size
);
8856 /* We need to provide for vector pointers, vector arrays, and
8857 functions returning vectors. For example:
8859 __attribute__((vector_size(16))) short *foo;
8861 In this case, the mode is SI, but the type being modified is
8862 HI, so we need to look further. */
8864 while (POINTER_TYPE_P (type
)
8865 || TREE_CODE (type
) == FUNCTION_TYPE
8866 || TREE_CODE (type
) == METHOD_TYPE
8867 || TREE_CODE (type
) == ARRAY_TYPE
8868 || TREE_CODE (type
) == OFFSET_TYPE
)
8869 type
= TREE_TYPE (type
);
8871 /* Get the mode of the type being modified. */
8872 orig_mode
= TYPE_MODE (type
);
8874 if ((!INTEGRAL_TYPE_P (type
)
8875 && !SCALAR_FLOAT_TYPE_P (type
)
8876 && !FIXED_POINT_TYPE_P (type
))
8877 || (!SCALAR_FLOAT_MODE_P (orig_mode
)
8878 && GET_MODE_CLASS (orig_mode
) != MODE_INT
8879 && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode
))
8880 || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
8881 || TREE_CODE (type
) == BOOLEAN_TYPE
)
8883 error ("invalid vector type for attribute %qE", name
);
8887 if (vecsize
% tree_to_uhwi (TYPE_SIZE_UNIT (type
)))
8889 error ("vector size not an integral multiple of component size");
8895 error ("zero vector size");
8899 /* Calculate how many units fit in the vector. */
8900 nunits
= vecsize
/ tree_to_uhwi (TYPE_SIZE_UNIT (type
));
8901 if (nunits
& (nunits
- 1))
8903 error ("number of components of the vector not a power of two");
8907 new_type
= build_vector_type (type
, nunits
);
8909 /* Build back pointers if needed. */
8910 *node
= lang_hooks
.types
.reconstruct_complex_type (*node
, new_type
);
8915 /* Handle the "nonnull" attribute. */
8917 handle_nonnull_attribute (tree
*node
, tree
ARG_UNUSED (name
),
8918 tree args
, int ARG_UNUSED (flags
),
8922 unsigned HOST_WIDE_INT attr_arg_num
;
8924 /* If no arguments are specified, all pointer arguments should be
8925 non-null. Verify a full prototype is given so that the arguments
8926 will have the correct types when we actually check them later. */
8929 if (!prototype_p (type
))
8931 error ("nonnull attribute without arguments on a non-prototype");
8932 *no_add_attrs
= true;
8937 /* Argument list specified. Verify that each argument number references
8938 a pointer argument. */
8939 for (attr_arg_num
= 1; args
; attr_arg_num
++, args
= TREE_CHAIN (args
))
8941 unsigned HOST_WIDE_INT arg_num
= 0, ck_num
;
8943 tree arg
= TREE_VALUE (args
);
8944 if (arg
&& TREE_CODE (arg
) != IDENTIFIER_NODE
8945 && TREE_CODE (arg
) != FUNCTION_DECL
)
8946 arg
= default_conversion (arg
);
8948 if (!get_nonnull_operand (arg
, &arg_num
))
8950 error ("nonnull argument has invalid operand number (argument %lu)",
8951 (unsigned long) attr_arg_num
);
8952 *no_add_attrs
= true;
8956 if (prototype_p (type
))
8958 function_args_iterator iter
;
8961 function_args_iter_init (&iter
, type
);
8962 for (ck_num
= 1; ; ck_num
++, function_args_iter_next (&iter
))
8964 argument
= function_args_iter_cond (&iter
);
8965 if (argument
== NULL_TREE
|| ck_num
== arg_num
)
8970 || TREE_CODE (argument
) == VOID_TYPE
)
8972 error ("nonnull argument with out-of-range operand number (argument %lu, operand %lu)",
8973 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
8974 *no_add_attrs
= true;
8978 if (TREE_CODE (argument
) != POINTER_TYPE
)
8980 error ("nonnull argument references non-pointer operand (argument %lu, operand %lu)",
8981 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
8982 *no_add_attrs
= true;
8991 /* Check the argument list of a function call for null in argument slots
8992 that are marked as requiring a non-null pointer argument. The NARGS
8993 arguments are passed in the array ARGARRAY.
8997 check_function_nonnull (tree attrs
, int nargs
, tree
*argarray
)
9002 attrs
= lookup_attribute ("nonnull", attrs
);
9003 if (attrs
== NULL_TREE
)
9007 /* See if any of the nonnull attributes has no arguments. If so,
9008 then every pointer argument is checked (in which case the check
9009 for pointer type is done in check_nonnull_arg). */
9010 if (TREE_VALUE (a
) != NULL_TREE
)
9012 a
= lookup_attribute ("nonnull", TREE_CHAIN (a
));
9013 while (a
!= NULL_TREE
&& TREE_VALUE (a
) != NULL_TREE
);
9016 for (i
= 0; i
< nargs
; i
++)
9017 check_function_arguments_recurse (check_nonnull_arg
, NULL
, argarray
[i
],
9021 /* Walk the argument list. If we encounter an argument number we
9022 should check for non-null, do it. */
9023 for (i
= 0; i
< nargs
; i
++)
9025 for (a
= attrs
; ; a
= TREE_CHAIN (a
))
9027 a
= lookup_attribute ("nonnull", a
);
9028 if (a
== NULL_TREE
|| nonnull_check_p (TREE_VALUE (a
), i
+ 1))
9033 check_function_arguments_recurse (check_nonnull_arg
, NULL
,
9034 argarray
[i
], i
+ 1);
9039 /* Check that the Nth argument of a function call (counting backwards
9040 from the end) is a (pointer)0. The NARGS arguments are passed in the
9044 check_function_sentinel (const_tree fntype
, int nargs
, tree
*argarray
)
9046 tree attr
= lookup_attribute ("sentinel", TYPE_ATTRIBUTES (fntype
));
9053 function_args_iterator iter
;
9056 /* Skip over the named arguments. */
9057 FOREACH_FUNCTION_ARGS (fntype
, t
, iter
)
9064 if (TREE_VALUE (attr
))
9066 tree p
= TREE_VALUE (TREE_VALUE (attr
));
9067 pos
= TREE_INT_CST_LOW (p
);
9070 /* The sentinel must be one of the varargs, i.e.
9071 in position >= the number of fixed arguments. */
9072 if ((nargs
- 1 - pos
) < len
)
9074 warning (OPT_Wformat_
,
9075 "not enough variable arguments to fit a sentinel");
9079 /* Validate the sentinel. */
9080 sentinel
= argarray
[nargs
- 1 - pos
];
9081 if ((!POINTER_TYPE_P (TREE_TYPE (sentinel
))
9082 || !integer_zerop (sentinel
))
9083 /* Although __null (in C++) is only an integer we allow it
9084 nevertheless, as we are guaranteed that it's exactly
9085 as wide as a pointer, and we don't want to force
9086 users to cast the NULL they have written there.
9087 We warn with -Wstrict-null-sentinel, though. */
9088 && (warn_strict_null_sentinel
|| null_node
!= sentinel
))
9089 warning (OPT_Wformat_
, "missing sentinel in function call");
9093 /* Helper for check_function_nonnull; given a list of operands which
9094 must be non-null in ARGS, determine if operand PARAM_NUM should be
9098 nonnull_check_p (tree args
, unsigned HOST_WIDE_INT param_num
)
9100 unsigned HOST_WIDE_INT arg_num
= 0;
9102 for (; args
; args
= TREE_CHAIN (args
))
9104 bool found
= get_nonnull_operand (TREE_VALUE (args
), &arg_num
);
9108 if (arg_num
== param_num
)
9114 /* Check that the function argument PARAM (which is operand number
9115 PARAM_NUM) is non-null. This is called by check_function_nonnull
9116 via check_function_arguments_recurse. */
9119 check_nonnull_arg (void * ARG_UNUSED (ctx
), tree param
,
9120 unsigned HOST_WIDE_INT param_num
)
9122 /* Just skip checking the argument if it's not a pointer. This can
9123 happen if the "nonnull" attribute was given without an operand
9124 list (which means to check every pointer argument). */
9126 if (TREE_CODE (TREE_TYPE (param
)) != POINTER_TYPE
)
9129 if (integer_zerop (param
))
9130 warning (OPT_Wnonnull
, "null argument where non-null required "
9131 "(argument %lu)", (unsigned long) param_num
);
9134 /* Helper for nonnull attribute handling; fetch the operand number
9135 from the attribute argument list. */
9138 get_nonnull_operand (tree arg_num_expr
, unsigned HOST_WIDE_INT
*valp
)
9140 /* Verify the arg number is a small constant. */
9141 if (tree_fits_uhwi_p (arg_num_expr
))
9143 *valp
= TREE_INT_CST_LOW (arg_num_expr
);
9150 /* Handle a "nothrow" attribute; arguments as in
9151 struct attribute_spec.handler. */
9154 handle_nothrow_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
9155 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9157 if (TREE_CODE (*node
) == FUNCTION_DECL
)
9158 TREE_NOTHROW (*node
) = 1;
9159 /* ??? TODO: Support types. */
9162 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9163 *no_add_attrs
= true;
9169 /* Handle a "cleanup" attribute; arguments as in
9170 struct attribute_spec.handler. */
9173 handle_cleanup_attribute (tree
*node
, tree name
, tree args
,
9174 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9177 tree cleanup_id
, cleanup_decl
;
9179 /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
9180 for global destructors in C++. This requires infrastructure that
9181 we don't have generically at the moment. It's also not a feature
9182 we'd be missing too much, since we do have attribute constructor. */
9183 if (TREE_CODE (decl
) != VAR_DECL
|| TREE_STATIC (decl
))
9185 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9186 *no_add_attrs
= true;
9190 /* Verify that the argument is a function in scope. */
9191 /* ??? We could support pointers to functions here as well, if
9192 that was considered desirable. */
9193 cleanup_id
= TREE_VALUE (args
);
9194 if (TREE_CODE (cleanup_id
) != IDENTIFIER_NODE
)
9196 error ("cleanup argument not an identifier");
9197 *no_add_attrs
= true;
9200 cleanup_decl
= lookup_name (cleanup_id
);
9201 if (!cleanup_decl
|| TREE_CODE (cleanup_decl
) != FUNCTION_DECL
)
9203 error ("cleanup argument not a function");
9204 *no_add_attrs
= true;
9208 /* That the function has proper type is checked with the
9209 eventual call to build_function_call. */
9214 /* Handle a "warn_unused_result" attribute. No special handling. */
9217 handle_warn_unused_result_attribute (tree
*node
, tree name
,
9218 tree
ARG_UNUSED (args
),
9219 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9221 /* Ignore the attribute for functions not returning any value. */
9222 if (VOID_TYPE_P (TREE_TYPE (*node
)))
9224 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9225 *no_add_attrs
= true;
9231 /* Handle a "sentinel" attribute. */
9234 handle_sentinel_attribute (tree
*node
, tree name
, tree args
,
9235 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9237 if (!prototype_p (*node
))
9239 warning (OPT_Wattributes
,
9240 "%qE attribute requires prototypes with named arguments", name
);
9241 *no_add_attrs
= true;
9245 if (!stdarg_p (*node
))
9247 warning (OPT_Wattributes
,
9248 "%qE attribute only applies to variadic functions", name
);
9249 *no_add_attrs
= true;
9255 tree position
= TREE_VALUE (args
);
9256 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
9257 && TREE_CODE (position
) != FUNCTION_DECL
)
9258 position
= default_conversion (position
);
9260 if (TREE_CODE (position
) != INTEGER_CST
9261 || !INTEGRAL_TYPE_P (TREE_TYPE (position
)))
9263 warning (OPT_Wattributes
,
9264 "requested position is not an integer constant");
9265 *no_add_attrs
= true;
9269 if (tree_int_cst_lt (position
, integer_zero_node
))
9271 warning (OPT_Wattributes
,
9272 "requested position is less than zero");
9273 *no_add_attrs
= true;
9281 /* Handle a "type_generic" attribute. */
9284 handle_type_generic_attribute (tree
*node
, tree
ARG_UNUSED (name
),
9285 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
9286 bool * ARG_UNUSED (no_add_attrs
))
9288 /* Ensure we have a function type. */
9289 gcc_assert (TREE_CODE (*node
) == FUNCTION_TYPE
);
9291 /* Ensure we have a variadic function. */
9292 gcc_assert (!prototype_p (*node
) || stdarg_p (*node
));
9297 /* Handle a "target" attribute. */
9300 handle_target_attribute (tree
*node
, tree name
, tree args
, int flags
,
9303 /* Ensure we have a function type. */
9304 if (TREE_CODE (*node
) != FUNCTION_DECL
)
9306 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9307 *no_add_attrs
= true;
9309 else if (! targetm
.target_option
.valid_attribute_p (*node
, name
, args
,
9311 *no_add_attrs
= true;
9316 /* Arguments being collected for optimization. */
9317 typedef const char *const_char_p
; /* For DEF_VEC_P. */
9318 static GTY(()) vec
<const_char_p
, va_gc
> *optimize_args
;
9321 /* Inner function to convert a TREE_LIST to argv string to parse the optimize
9322 options in ARGS. ATTR_P is true if this is for attribute(optimize), and
9323 false for #pragma GCC optimize. */
9326 parse_optimize_options (tree args
, bool attr_p
)
9331 int saved_flag_strict_aliasing
;
9332 const char **opt_argv
;
9333 struct cl_decoded_option
*decoded_options
;
9334 unsigned int decoded_options_count
;
9337 /* Build up argv vector. Just in case the string is stored away, use garbage
9338 collected strings. */
9339 vec_safe_truncate (optimize_args
, 0);
9340 vec_safe_push (optimize_args
, (const char *) NULL
);
9342 for (ap
= args
; ap
!= NULL_TREE
; ap
= TREE_CHAIN (ap
))
9344 tree value
= TREE_VALUE (ap
);
9346 if (TREE_CODE (value
) == INTEGER_CST
)
9349 sprintf (buffer
, "-O%ld", (long) TREE_INT_CST_LOW (value
));
9350 vec_safe_push (optimize_args
, ggc_strdup (buffer
));
9353 else if (TREE_CODE (value
) == STRING_CST
)
9355 /* Split string into multiple substrings. */
9356 size_t len
= TREE_STRING_LENGTH (value
);
9357 char *p
= ASTRDUP (TREE_STRING_POINTER (value
));
9358 char *end
= p
+ len
;
9362 while (next_p
!= NULL
)
9368 comma
= strchr (p
, ',');
9381 r
= q
= (char *) ggc_alloc_atomic (len2
+ 3);
9383 /* If the user supplied -Oxxx or -fxxx, only allow -Oxxx or -fxxx
9385 if (*p
== '-' && p
[1] != 'O' && p
[1] != 'f')
9389 warning (OPT_Wattributes
,
9390 "bad option %s to optimize attribute", p
);
9392 warning (OPT_Wpragmas
,
9393 "bad option %s to pragma attribute", p
);
9401 /* Assume that Ox is -Ox, a numeric value is -Ox, a s by
9402 itself is -Os, and any other switch begins with a -f. */
9403 if ((*p
>= '0' && *p
<= '9')
9404 || (p
[0] == 's' && p
[1] == '\0'))
9410 memcpy (r
, p
, len2
);
9412 vec_safe_push (optimize_args
, (const char *) q
);
9418 opt_argc
= optimize_args
->length ();
9419 opt_argv
= (const char **) alloca (sizeof (char *) * (opt_argc
+ 1));
9421 for (i
= 1; i
< opt_argc
; i
++)
9422 opt_argv
[i
] = (*optimize_args
)[i
];
9424 saved_flag_strict_aliasing
= flag_strict_aliasing
;
9426 /* Now parse the options. */
9427 decode_cmdline_options_to_array_default_mask (opt_argc
, opt_argv
,
9429 &decoded_options_count
);
9430 decode_options (&global_options
, &global_options_set
,
9431 decoded_options
, decoded_options_count
,
9432 input_location
, global_dc
);
9434 targetm
.override_options_after_change();
9436 /* Don't allow changing -fstrict-aliasing. */
9437 flag_strict_aliasing
= saved_flag_strict_aliasing
;
9439 optimize_args
->truncate (0);
9443 /* For handling "optimize" attribute. arguments as in
9444 struct attribute_spec.handler. */
9447 handle_optimize_attribute (tree
*node
, tree name
, tree args
,
9448 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9450 /* Ensure we have a function type. */
9451 if (TREE_CODE (*node
) != FUNCTION_DECL
)
9453 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9454 *no_add_attrs
= true;
9458 struct cl_optimization cur_opts
;
9459 tree old_opts
= DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
);
9461 /* Save current options. */
9462 cl_optimization_save (&cur_opts
, &global_options
);
9464 /* If we previously had some optimization options, use them as the
9467 cl_optimization_restore (&global_options
,
9468 TREE_OPTIMIZATION (old_opts
));
9470 /* Parse options, and update the vector. */
9471 parse_optimize_options (args
, true);
9472 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
)
9473 = build_optimization_node (&global_options
);
9475 /* Restore current options. */
9476 cl_optimization_restore (&global_options
, &cur_opts
);
9482 /* Handle a "no_split_stack" attribute. */
9485 handle_no_split_stack_attribute (tree
*node
, tree name
,
9486 tree
ARG_UNUSED (args
),
9487 int ARG_UNUSED (flags
),
9492 if (TREE_CODE (decl
) != FUNCTION_DECL
)
9494 error_at (DECL_SOURCE_LOCATION (decl
),
9495 "%qE attribute applies only to functions", name
);
9496 *no_add_attrs
= true;
9498 else if (DECL_INITIAL (decl
))
9500 error_at (DECL_SOURCE_LOCATION (decl
),
9501 "can%'t set %qE attribute after definition", name
);
9502 *no_add_attrs
= true;
9508 /* Handle a "returns_nonnull" attribute; arguments as in
9509 struct attribute_spec.handler. */
9512 handle_returns_nonnull_attribute (tree
*node
, tree
, tree
, int,
9515 // Even without a prototype we still have a return type we can check.
9516 if (TREE_CODE (TREE_TYPE (*node
)) != POINTER_TYPE
)
9518 error ("returns_nonnull attribute on a function not returning a pointer");
9519 *no_add_attrs
= true;
9524 /* Handle a "designated_init" attribute; arguments as in
9525 struct attribute_spec.handler. */
9528 handle_designated_init_attribute (tree
*node
, tree name
, tree
, int,
9531 if (TREE_CODE (*node
) != RECORD_TYPE
)
9533 error ("%qE attribute is only valid on %<struct%> type", name
);
9534 *no_add_attrs
= true;
9540 /* Check for valid arguments being passed to a function with FNTYPE.
9541 There are NARGS arguments in the array ARGARRAY. */
9543 check_function_arguments (const_tree fntype
, int nargs
, tree
*argarray
)
9545 /* Check for null being passed in a pointer argument that must be
9546 non-null. We also need to do this if format checking is enabled. */
9549 check_function_nonnull (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
9551 /* Check for errors in format strings. */
9553 if (warn_format
|| warn_suggest_attribute_format
)
9554 check_function_format (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
9557 check_function_sentinel (fntype
, nargs
, argarray
);
9560 /* Generic argument checking recursion routine. PARAM is the argument to
9561 be checked. PARAM_NUM is the number of the argument. CALLBACK is invoked
9562 once the argument is resolved. CTX is context for the callback. */
9564 check_function_arguments_recurse (void (*callback
)
9565 (void *, tree
, unsigned HOST_WIDE_INT
),
9566 void *ctx
, tree param
,
9567 unsigned HOST_WIDE_INT param_num
)
9569 if (CONVERT_EXPR_P (param
)
9570 && (TYPE_PRECISION (TREE_TYPE (param
))
9571 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (param
, 0)))))
9573 /* Strip coercion. */
9574 check_function_arguments_recurse (callback
, ctx
,
9575 TREE_OPERAND (param
, 0), param_num
);
9579 if (TREE_CODE (param
) == CALL_EXPR
)
9581 tree type
= TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (param
)));
9583 bool found_format_arg
= false;
9585 /* See if this is a call to a known internationalization function
9586 that modifies a format arg. Such a function may have multiple
9587 format_arg attributes (for example, ngettext). */
9589 for (attrs
= TYPE_ATTRIBUTES (type
);
9591 attrs
= TREE_CHAIN (attrs
))
9592 if (is_attribute_p ("format_arg", TREE_PURPOSE (attrs
)))
9595 tree format_num_expr
;
9598 call_expr_arg_iterator iter
;
9600 /* Extract the argument number, which was previously checked
9602 format_num_expr
= TREE_VALUE (TREE_VALUE (attrs
));
9604 format_num
= tree_to_uhwi (format_num_expr
);
9606 for (inner_arg
= first_call_expr_arg (param
, &iter
), i
= 1;
9608 inner_arg
= next_call_expr_arg (&iter
), i
++)
9609 if (i
== format_num
)
9611 check_function_arguments_recurse (callback
, ctx
,
9612 inner_arg
, param_num
);
9613 found_format_arg
= true;
9618 /* If we found a format_arg attribute and did a recursive check,
9619 we are done with checking this argument. Otherwise, we continue
9620 and this will be considered a non-literal. */
9621 if (found_format_arg
)
9625 if (TREE_CODE (param
) == COND_EXPR
)
9627 /* Check both halves of the conditional expression. */
9628 check_function_arguments_recurse (callback
, ctx
,
9629 TREE_OPERAND (param
, 1), param_num
);
9630 check_function_arguments_recurse (callback
, ctx
,
9631 TREE_OPERAND (param
, 2), param_num
);
9635 (*callback
) (ctx
, param
, param_num
);
9638 /* Checks for a builtin function FNDECL that the number of arguments
9639 NARGS against the required number REQUIRED and issues an error if
9640 there is a mismatch. Returns true if the number of arguments is
9641 correct, otherwise false. */
9644 builtin_function_validate_nargs (tree fndecl
, int nargs
, int required
)
9646 if (nargs
< required
)
9648 error_at (input_location
,
9649 "not enough arguments to function %qE", fndecl
);
9652 else if (nargs
> required
)
9654 error_at (input_location
,
9655 "too many arguments to function %qE", fndecl
);
9661 /* Verifies the NARGS arguments ARGS to the builtin function FNDECL.
9662 Returns false if there was an error, otherwise true. */
9665 check_builtin_function_arguments (tree fndecl
, int nargs
, tree
*args
)
9667 if (!DECL_BUILT_IN (fndecl
)
9668 || DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_NORMAL
)
9671 switch (DECL_FUNCTION_CODE (fndecl
))
9673 case BUILT_IN_CONSTANT_P
:
9674 return builtin_function_validate_nargs (fndecl
, nargs
, 1);
9676 case BUILT_IN_ISFINITE
:
9677 case BUILT_IN_ISINF
:
9678 case BUILT_IN_ISINF_SIGN
:
9679 case BUILT_IN_ISNAN
:
9680 case BUILT_IN_ISNORMAL
:
9681 if (builtin_function_validate_nargs (fndecl
, nargs
, 1))
9683 if (TREE_CODE (TREE_TYPE (args
[0])) != REAL_TYPE
)
9685 error ("non-floating-point argument in call to "
9686 "function %qE", fndecl
);
9693 case BUILT_IN_ISGREATER
:
9694 case BUILT_IN_ISGREATEREQUAL
:
9695 case BUILT_IN_ISLESS
:
9696 case BUILT_IN_ISLESSEQUAL
:
9697 case BUILT_IN_ISLESSGREATER
:
9698 case BUILT_IN_ISUNORDERED
:
9699 if (builtin_function_validate_nargs (fndecl
, nargs
, 2))
9701 enum tree_code code0
, code1
;
9702 code0
= TREE_CODE (TREE_TYPE (args
[0]));
9703 code1
= TREE_CODE (TREE_TYPE (args
[1]));
9704 if (!((code0
== REAL_TYPE
&& code1
== REAL_TYPE
)
9705 || (code0
== REAL_TYPE
&& code1
== INTEGER_TYPE
)
9706 || (code0
== INTEGER_TYPE
&& code1
== REAL_TYPE
)))
9708 error ("non-floating-point arguments in call to "
9709 "function %qE", fndecl
);
9716 case BUILT_IN_FPCLASSIFY
:
9717 if (builtin_function_validate_nargs (fndecl
, nargs
, 6))
9722 if (TREE_CODE (args
[i
]) != INTEGER_CST
)
9724 error ("non-const integer argument %u in call to function %qE",
9729 if (TREE_CODE (TREE_TYPE (args
[5])) != REAL_TYPE
)
9731 error ("non-floating-point argument in call to function %qE",
9739 case BUILT_IN_ASSUME_ALIGNED
:
9740 if (builtin_function_validate_nargs (fndecl
, nargs
, 2 + (nargs
> 2)))
9742 if (nargs
>= 3 && TREE_CODE (TREE_TYPE (args
[2])) != INTEGER_TYPE
)
9744 error ("non-integer argument 3 in call to function %qE", fndecl
);
9751 case BUILT_IN_ADD_OVERFLOW
:
9752 case BUILT_IN_SUB_OVERFLOW
:
9753 case BUILT_IN_MUL_OVERFLOW
:
9754 if (builtin_function_validate_nargs (fndecl
, nargs
, 3))
9757 for (i
= 0; i
< 2; i
++)
9758 if (!INTEGRAL_TYPE_P (TREE_TYPE (args
[i
])))
9760 error ("argument %u in call to function %qE does not have "
9761 "integral type", i
+ 1, fndecl
);
9764 if (TREE_CODE (TREE_TYPE (args
[2])) != POINTER_TYPE
9765 || TREE_CODE (TREE_TYPE (TREE_TYPE (args
[2]))) != INTEGER_TYPE
)
9767 error ("argument 3 in call to function %qE does not have "
9768 "pointer to integer type", fndecl
);
9780 /* Function to help qsort sort FIELD_DECLs by name order. */
9783 field_decl_cmp (const void *x_p
, const void *y_p
)
9785 const tree
*const x
= (const tree
*const) x_p
;
9786 const tree
*const y
= (const tree
*const) y_p
;
9788 if (DECL_NAME (*x
) == DECL_NAME (*y
))
9789 /* A nontype is "greater" than a type. */
9790 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
9791 if (DECL_NAME (*x
) == NULL_TREE
)
9793 if (DECL_NAME (*y
) == NULL_TREE
)
9795 if (DECL_NAME (*x
) < DECL_NAME (*y
))
9801 gt_pointer_operator new_value
;
9805 /* This routine compares two fields like field_decl_cmp but using the
9806 pointer operator in resort_data. */
9809 resort_field_decl_cmp (const void *x_p
, const void *y_p
)
9811 const tree
*const x
= (const tree
*const) x_p
;
9812 const tree
*const y
= (const tree
*const) y_p
;
9814 if (DECL_NAME (*x
) == DECL_NAME (*y
))
9815 /* A nontype is "greater" than a type. */
9816 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
9817 if (DECL_NAME (*x
) == NULL_TREE
)
9819 if (DECL_NAME (*y
) == NULL_TREE
)
9822 tree d1
= DECL_NAME (*x
);
9823 tree d2
= DECL_NAME (*y
);
9824 resort_data
.new_value (&d1
, resort_data
.cookie
);
9825 resort_data
.new_value (&d2
, resort_data
.cookie
);
9832 /* Resort DECL_SORTED_FIELDS because pointers have been reordered. */
9835 resort_sorted_fields (void *obj
,
9836 void * ARG_UNUSED (orig_obj
),
9837 gt_pointer_operator new_value
,
9840 struct sorted_fields_type
*sf
= (struct sorted_fields_type
*) obj
;
9841 resort_data
.new_value
= new_value
;
9842 resort_data
.cookie
= cookie
;
9843 qsort (&sf
->elts
[0], sf
->len
, sizeof (tree
),
9844 resort_field_decl_cmp
);
9847 /* Subroutine of c_parse_error.
9848 Return the result of concatenating LHS and RHS. RHS is really
9849 a string literal, its first character is indicated by RHS_START and
9850 RHS_SIZE is its length (including the terminating NUL character).
9852 The caller is responsible for deleting the returned pointer. */
9855 catenate_strings (const char *lhs
, const char *rhs_start
, int rhs_size
)
9857 const int lhs_size
= strlen (lhs
);
9858 char *result
= XNEWVEC (char, lhs_size
+ rhs_size
);
9859 strncpy (result
, lhs
, lhs_size
);
9860 strncpy (result
+ lhs_size
, rhs_start
, rhs_size
);
9864 /* Issue the error given by GMSGID, indicating that it occurred before
9865 TOKEN, which had the associated VALUE. */
9868 c_parse_error (const char *gmsgid
, enum cpp_ttype token_type
,
9869 tree value
, unsigned char token_flags
)
9871 #define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2))
9873 char *message
= NULL
;
9875 if (token_type
== CPP_EOF
)
9876 message
= catenate_messages (gmsgid
, " at end of input");
9877 else if (token_type
== CPP_CHAR
9878 || token_type
== CPP_WCHAR
9879 || token_type
== CPP_CHAR16
9880 || token_type
== CPP_CHAR32
)
9882 unsigned int val
= TREE_INT_CST_LOW (value
);
9901 if (val
<= UCHAR_MAX
&& ISGRAPH (val
))
9902 message
= catenate_messages (gmsgid
, " before %s'%c'");
9904 message
= catenate_messages (gmsgid
, " before %s'\\x%x'");
9906 error (message
, prefix
, val
);
9910 else if (token_type
== CPP_CHAR_USERDEF
9911 || token_type
== CPP_WCHAR_USERDEF
9912 || token_type
== CPP_CHAR16_USERDEF
9913 || token_type
== CPP_CHAR32_USERDEF
)
9914 message
= catenate_messages (gmsgid
,
9915 " before user-defined character literal");
9916 else if (token_type
== CPP_STRING_USERDEF
9917 || token_type
== CPP_WSTRING_USERDEF
9918 || token_type
== CPP_STRING16_USERDEF
9919 || token_type
== CPP_STRING32_USERDEF
9920 || token_type
== CPP_UTF8STRING_USERDEF
)
9921 message
= catenate_messages (gmsgid
, " before user-defined string literal");
9922 else if (token_type
== CPP_STRING
9923 || token_type
== CPP_WSTRING
9924 || token_type
== CPP_STRING16
9925 || token_type
== CPP_STRING32
9926 || token_type
== CPP_UTF8STRING
)
9927 message
= catenate_messages (gmsgid
, " before string constant");
9928 else if (token_type
== CPP_NUMBER
)
9929 message
= catenate_messages (gmsgid
, " before numeric constant");
9930 else if (token_type
== CPP_NAME
)
9932 message
= catenate_messages (gmsgid
, " before %qE");
9933 error (message
, value
);
9937 else if (token_type
== CPP_PRAGMA
)
9938 message
= catenate_messages (gmsgid
, " before %<#pragma%>");
9939 else if (token_type
== CPP_PRAGMA_EOL
)
9940 message
= catenate_messages (gmsgid
, " before end of line");
9941 else if (token_type
== CPP_DECLTYPE
)
9942 message
= catenate_messages (gmsgid
, " before %<decltype%>");
9943 else if (token_type
< N_TTYPES
)
9945 message
= catenate_messages (gmsgid
, " before %qs token");
9946 error (message
, cpp_type2name (token_type
, token_flags
));
9958 #undef catenate_messages
9961 /* Return the gcc option code associated with the reason for a cpp
9962 message, or 0 if none. */
9965 c_option_controlling_cpp_error (int reason
)
9967 const struct cpp_reason_option_codes_t
*entry
;
9969 for (entry
= cpp_reason_option_codes
; entry
->reason
!= CPP_W_NONE
; entry
++)
9971 if (entry
->reason
== reason
)
9972 return entry
->option_code
;
9977 /* Callback from cpp_error for PFILE to print diagnostics from the
9978 preprocessor. The diagnostic is of type LEVEL, with REASON set
9979 to the reason code if LEVEL is represents a warning, at location
9980 LOCATION unless this is after lexing and the compiler's location
9981 should be used instead, with column number possibly overridden by
9982 COLUMN_OVERRIDE if not zero; MSG is the translated message and AP
9983 the arguments. Returns true if a diagnostic was emitted, false
9987 c_cpp_error (cpp_reader
*pfile ATTRIBUTE_UNUSED
, int level
, int reason
,
9988 location_t location
, unsigned int column_override
,
9989 const char *msg
, va_list *ap
)
9991 diagnostic_info diagnostic
;
9992 diagnostic_t dlevel
;
9993 bool save_warn_system_headers
= global_dc
->dc_warn_system_headers
;
9998 case CPP_DL_WARNING_SYSHDR
:
10001 global_dc
->dc_warn_system_headers
= 1;
10002 /* Fall through. */
10003 case CPP_DL_WARNING
:
10004 if (flag_no_output
)
10006 dlevel
= DK_WARNING
;
10008 case CPP_DL_PEDWARN
:
10009 if (flag_no_output
&& !flag_pedantic_errors
)
10011 dlevel
= DK_PEDWARN
;
10026 gcc_unreachable ();
10029 location
= input_location
;
10030 diagnostic_set_info_translated (&diagnostic
, msg
, ap
,
10032 if (column_override
)
10033 diagnostic_override_column (&diagnostic
, column_override
);
10034 diagnostic_override_option_index (&diagnostic
,
10035 c_option_controlling_cpp_error (reason
));
10036 ret
= report_diagnostic (&diagnostic
);
10037 if (level
== CPP_DL_WARNING_SYSHDR
)
10038 global_dc
->dc_warn_system_headers
= save_warn_system_headers
;
10042 /* Convert a character from the host to the target execution character
10043 set. cpplib handles this, mostly. */
10046 c_common_to_target_charset (HOST_WIDE_INT c
)
10048 /* Character constants in GCC proper are sign-extended under -fsigned-char,
10049 zero-extended under -fno-signed-char. cpplib insists that characters
10050 and character constants are always unsigned. Hence we must convert
10052 cppchar_t uc
= ((cppchar_t
)c
) & ((((cppchar_t
)1) << CHAR_BIT
)-1);
10054 uc
= cpp_host_to_exec_charset (parse_in
, uc
);
10056 if (flag_signed_char
)
10057 return ((HOST_WIDE_INT
)uc
) << (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
)
10058 >> (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
);
10063 /* Fold an offsetof-like expression. EXPR is a nested sequence of component
10064 references with an INDIRECT_REF of a constant at the bottom; much like the
10065 traditional rendering of offsetof as a macro. Return the folded result. */
10068 fold_offsetof_1 (tree expr
)
10072 switch (TREE_CODE (expr
))
10078 error ("cannot apply %<offsetof%> to static data member %qD", expr
);
10079 return error_mark_node
;
10083 error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded");
10084 return error_mark_node
;
10088 if (!TREE_CONSTANT (TREE_OPERAND (expr
, 0)))
10090 error ("cannot apply %<offsetof%> to a non constant address");
10091 return error_mark_node
;
10093 return TREE_OPERAND (expr
, 0);
10095 case COMPONENT_REF
:
10096 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0));
10097 if (base
== error_mark_node
)
10100 t
= TREE_OPERAND (expr
, 1);
10101 if (DECL_C_BIT_FIELD (t
))
10103 error ("attempt to take address of bit-field structure "
10105 return error_mark_node
;
10107 off
= size_binop_loc (input_location
, PLUS_EXPR
, DECL_FIELD_OFFSET (t
),
10108 size_int (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (t
))
10113 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0));
10114 if (base
== error_mark_node
)
10117 t
= TREE_OPERAND (expr
, 1);
10119 /* Check if the offset goes beyond the upper bound of the array. */
10120 if (TREE_CODE (t
) == INTEGER_CST
&& tree_int_cst_sgn (t
) >= 0)
10122 tree upbound
= array_ref_up_bound (expr
);
10123 if (upbound
!= NULL_TREE
10124 && TREE_CODE (upbound
) == INTEGER_CST
10125 && !tree_int_cst_equal (upbound
,
10126 TYPE_MAX_VALUE (TREE_TYPE (upbound
))))
10128 upbound
= size_binop (PLUS_EXPR
, upbound
,
10129 build_int_cst (TREE_TYPE (upbound
), 1));
10130 if (tree_int_cst_lt (upbound
, t
))
10134 for (v
= TREE_OPERAND (expr
, 0);
10135 TREE_CODE (v
) == COMPONENT_REF
;
10136 v
= TREE_OPERAND (v
, 0))
10137 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v
, 0)))
10140 tree fld_chain
= DECL_CHAIN (TREE_OPERAND (v
, 1));
10141 for (; fld_chain
; fld_chain
= DECL_CHAIN (fld_chain
))
10142 if (TREE_CODE (fld_chain
) == FIELD_DECL
)
10148 /* Don't warn if the array might be considered a poor
10149 man's flexible array member with a very permissive
10150 definition thereof. */
10151 if (TREE_CODE (v
) == ARRAY_REF
10152 || TREE_CODE (v
) == COMPONENT_REF
)
10153 warning (OPT_Warray_bounds
,
10154 "index %E denotes an offset "
10155 "greater than size of %qT",
10156 t
, TREE_TYPE (TREE_OPERAND (expr
, 0)));
10161 t
= convert (sizetype
, t
);
10162 off
= size_binop (MULT_EXPR
, TYPE_SIZE_UNIT (TREE_TYPE (expr
)), t
);
10165 case COMPOUND_EXPR
:
10166 /* Handle static members of volatile structs. */
10167 t
= TREE_OPERAND (expr
, 1);
10168 gcc_assert (TREE_CODE (t
) == VAR_DECL
);
10169 return fold_offsetof_1 (t
);
10172 gcc_unreachable ();
10175 return fold_build_pointer_plus (base
, off
);
10178 /* Likewise, but convert it to the return type of offsetof. */
10181 fold_offsetof (tree expr
)
10183 return convert (size_type_node
, fold_offsetof_1 (expr
));
10186 /* Warn for A ?: C expressions (with B omitted) where A is a boolean
10187 expression, because B will always be true. */
10190 warn_for_omitted_condop (location_t location
, tree cond
)
10192 if (truth_value_p (TREE_CODE (cond
)))
10193 warning_at (location
, OPT_Wparentheses
,
10194 "the omitted middle operand in ?: will always be %<true%>, "
10195 "suggest explicit middle operand");
10198 /* Give an error for storing into ARG, which is 'const'. USE indicates
10199 how ARG was being used. */
10202 readonly_error (location_t loc
, tree arg
, enum lvalue_use use
)
10204 gcc_assert (use
== lv_assign
|| use
== lv_increment
|| use
== lv_decrement
10206 /* Using this macro rather than (for example) arrays of messages
10207 ensures that all the format strings are checked at compile
10209 #define READONLY_MSG(A, I, D, AS) (use == lv_assign ? (A) \
10210 : (use == lv_increment ? (I) \
10211 : (use == lv_decrement ? (D) : (AS))))
10212 if (TREE_CODE (arg
) == COMPONENT_REF
)
10214 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg
, 0))))
10215 error_at (loc
, READONLY_MSG (G_("assignment of member "
10216 "%qD in read-only object"),
10217 G_("increment of member "
10218 "%qD in read-only object"),
10219 G_("decrement of member "
10220 "%qD in read-only object"),
10221 G_("member %qD in read-only object "
10222 "used as %<asm%> output")),
10223 TREE_OPERAND (arg
, 1));
10225 error_at (loc
, READONLY_MSG (G_("assignment of read-only member %qD"),
10226 G_("increment of read-only member %qD"),
10227 G_("decrement of read-only member %qD"),
10228 G_("read-only member %qD used as %<asm%> output")),
10229 TREE_OPERAND (arg
, 1));
10231 else if (TREE_CODE (arg
) == VAR_DECL
)
10232 error_at (loc
, READONLY_MSG (G_("assignment of read-only variable %qD"),
10233 G_("increment of read-only variable %qD"),
10234 G_("decrement of read-only variable %qD"),
10235 G_("read-only variable %qD used as %<asm%> output")),
10237 else if (TREE_CODE (arg
) == PARM_DECL
)
10238 error_at (loc
, READONLY_MSG (G_("assignment of read-only parameter %qD"),
10239 G_("increment of read-only parameter %qD"),
10240 G_("decrement of read-only parameter %qD"),
10241 G_("read-only parameter %qD use as %<asm%> output")),
10243 else if (TREE_CODE (arg
) == RESULT_DECL
)
10245 gcc_assert (c_dialect_cxx ());
10246 error_at (loc
, READONLY_MSG (G_("assignment of "
10247 "read-only named return value %qD"),
10249 "read-only named return value %qD"),
10251 "read-only named return value %qD"),
10252 G_("read-only named return value %qD "
10253 "used as %<asm%>output")),
10256 else if (TREE_CODE (arg
) == FUNCTION_DECL
)
10257 error_at (loc
, READONLY_MSG (G_("assignment of function %qD"),
10258 G_("increment of function %qD"),
10259 G_("decrement of function %qD"),
10260 G_("function %qD used as %<asm%> output")),
10263 error_at (loc
, READONLY_MSG (G_("assignment of read-only location %qE"),
10264 G_("increment of read-only location %qE"),
10265 G_("decrement of read-only location %qE"),
10266 G_("read-only location %qE used as %<asm%> output")),
10270 /* Print an error message for an invalid lvalue. USE says
10271 how the lvalue is being used and so selects the error message. LOC
10272 is the location for the error. */
10275 lvalue_error (location_t loc
, enum lvalue_use use
)
10280 error_at (loc
, "lvalue required as left operand of assignment");
10283 error_at (loc
, "lvalue required as increment operand");
10286 error_at (loc
, "lvalue required as decrement operand");
10289 error_at (loc
, "lvalue required as unary %<&%> operand");
10292 error_at (loc
, "lvalue required in asm statement");
10295 gcc_unreachable ();
10299 /* Print an error message for an invalid indirection of type TYPE.
10300 ERRSTRING is the name of the operator for the indirection. */
10303 invalid_indirection_error (location_t loc
, tree type
, ref_operator errstring
)
10308 gcc_assert (c_dialect_cxx ());
10309 error_at (loc
, "invalid type argument (have %qT)", type
);
10311 case RO_ARRAY_INDEXING
:
10313 "invalid type argument of array indexing (have %qT)",
10316 case RO_UNARY_STAR
:
10318 "invalid type argument of unary %<*%> (have %qT)",
10323 "invalid type argument of %<->%> (have %qT)",
10326 case RO_ARROW_STAR
:
10328 "invalid type argument of %<->*%> (have %qT)",
10331 case RO_IMPLICIT_CONVERSION
:
10333 "invalid type argument of implicit conversion (have %qT)",
10337 gcc_unreachable ();
10341 /* *PTYPE is an incomplete array. Complete it with a domain based on
10342 INITIAL_VALUE. If INITIAL_VALUE is not present, use 1 if DO_DEFAULT
10343 is true. Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
10344 2 if INITIAL_VALUE was NULL, and 3 if INITIAL_VALUE was empty. */
10347 complete_array_type (tree
*ptype
, tree initial_value
, bool do_default
)
10349 tree maxindex
, type
, main_type
, elt
, unqual_elt
;
10350 int failure
= 0, quals
;
10351 hashval_t hashcode
= 0;
10352 bool overflow_p
= false;
10354 maxindex
= size_zero_node
;
10357 if (TREE_CODE (initial_value
) == STRING_CST
)
10360 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value
)));
10361 maxindex
= size_int (TREE_STRING_LENGTH (initial_value
)/eltsize
- 1);
10363 else if (TREE_CODE (initial_value
) == CONSTRUCTOR
)
10365 vec
<constructor_elt
, va_gc
> *v
= CONSTRUCTOR_ELTS (initial_value
);
10367 if (vec_safe_is_empty (v
))
10371 maxindex
= ssize_int (-1);
10376 unsigned HOST_WIDE_INT cnt
;
10377 constructor_elt
*ce
;
10378 bool fold_p
= false;
10381 maxindex
= (*v
)[0].index
, fold_p
= true;
10383 curindex
= maxindex
;
10385 for (cnt
= 1; vec_safe_iterate (v
, cnt
, &ce
); cnt
++)
10387 bool curfold_p
= false;
10389 curindex
= ce
->index
, curfold_p
= true;
10394 /* Since we treat size types now as ordinary
10395 unsigned types, we need an explicit overflow
10397 tree orig
= curindex
;
10398 curindex
= fold_convert (sizetype
, curindex
);
10399 overflow_p
|= tree_int_cst_lt (curindex
, orig
);
10401 curindex
= size_binop (PLUS_EXPR
, curindex
,
10404 if (tree_int_cst_lt (maxindex
, curindex
))
10405 maxindex
= curindex
, fold_p
= curfold_p
;
10409 tree orig
= maxindex
;
10410 maxindex
= fold_convert (sizetype
, maxindex
);
10411 overflow_p
|= tree_int_cst_lt (maxindex
, orig
);
10417 /* Make an error message unless that happened already. */
10418 if (initial_value
!= error_mark_node
)
10430 elt
= TREE_TYPE (type
);
10431 quals
= TYPE_QUALS (strip_array_types (elt
));
10435 unqual_elt
= c_build_qualified_type (elt
, KEEP_QUAL_ADDR_SPACE (quals
));
10437 /* Using build_distinct_type_copy and modifying things afterward instead
10438 of using build_array_type to create a new type preserves all of the
10439 TYPE_LANG_FLAG_? bits that the front end may have set. */
10440 main_type
= build_distinct_type_copy (TYPE_MAIN_VARIANT (type
));
10441 TREE_TYPE (main_type
) = unqual_elt
;
10442 TYPE_DOMAIN (main_type
)
10443 = build_range_type (TREE_TYPE (maxindex
),
10444 build_int_cst (TREE_TYPE (maxindex
), 0), maxindex
);
10445 layout_type (main_type
);
10447 /* Make sure we have the canonical MAIN_TYPE. */
10448 hashcode
= iterative_hash_object (TYPE_HASH (unqual_elt
), hashcode
);
10449 hashcode
= iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (main_type
)),
10451 main_type
= type_hash_canon (hashcode
, main_type
);
10453 /* Fix the canonical type. */
10454 if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type
))
10455 || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type
)))
10456 SET_TYPE_STRUCTURAL_EQUALITY (main_type
);
10457 else if (TYPE_CANONICAL (TREE_TYPE (main_type
)) != TREE_TYPE (main_type
)
10458 || (TYPE_CANONICAL (TYPE_DOMAIN (main_type
))
10459 != TYPE_DOMAIN (main_type
)))
10460 TYPE_CANONICAL (main_type
)
10461 = build_array_type (TYPE_CANONICAL (TREE_TYPE (main_type
)),
10462 TYPE_CANONICAL (TYPE_DOMAIN (main_type
)));
10464 TYPE_CANONICAL (main_type
) = main_type
;
10469 type
= c_build_qualified_type (main_type
, quals
);
10471 if (COMPLETE_TYPE_P (type
)
10472 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
10473 && (overflow_p
|| TREE_OVERFLOW (TYPE_SIZE_UNIT (type
))))
10475 error ("size of array is too large");
10476 /* If we proceed with the array type as it is, we'll eventually
10477 crash in tree_to_[su]hwi(). */
10478 type
= error_mark_node
;
10485 /* Like c_mark_addressable but don't check register qualifier. */
10487 c_common_mark_addressable_vec (tree t
)
10489 while (handled_component_p (t
))
10490 t
= TREE_OPERAND (t
, 0);
10491 if (TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != PARM_DECL
)
10493 TREE_ADDRESSABLE (t
) = 1;
10498 /* Used to help initialize the builtin-types.def table. When a type of
10499 the correct size doesn't exist, use error_mark_node instead of NULL.
10500 The later results in segfaults even when a decl using the type doesn't
10504 builtin_type_for_size (int size
, bool unsignedp
)
10506 tree type
= c_common_type_for_size (size
, unsignedp
);
10507 return type
? type
: error_mark_node
;
10510 /* A helper function for resolve_overloaded_builtin in resolving the
10511 overloaded __sync_ builtins. Returns a positive power of 2 if the
10512 first operand of PARAMS is a pointer to a supported data type.
10513 Returns 0 if an error is encountered. */
10516 sync_resolve_size (tree function
, vec
<tree
, va_gc
> *params
)
10523 error ("too few arguments to function %qE", function
);
10527 type
= TREE_TYPE ((*params
)[0]);
10528 if (TREE_CODE (type
) == ARRAY_TYPE
)
10530 /* Force array-to-pointer decay for C++. */
10531 gcc_assert (c_dialect_cxx());
10532 (*params
)[0] = default_conversion ((*params
)[0]);
10533 type
= TREE_TYPE ((*params
)[0]);
10535 if (TREE_CODE (type
) != POINTER_TYPE
)
10538 type
= TREE_TYPE (type
);
10539 if (!INTEGRAL_TYPE_P (type
) && !POINTER_TYPE_P (type
))
10542 size
= tree_to_uhwi (TYPE_SIZE_UNIT (type
));
10543 if (size
== 1 || size
== 2 || size
== 4 || size
== 8 || size
== 16)
10547 error ("incompatible type for argument %d of %qE", 1, function
);
10551 /* A helper function for resolve_overloaded_builtin. Adds casts to
10552 PARAMS to make arguments match up with those of FUNCTION. Drops
10553 the variadic arguments at the end. Returns false if some error
10554 was encountered; true on success. */
10557 sync_resolve_params (location_t loc
, tree orig_function
, tree function
,
10558 vec
<tree
, va_gc
> *params
, bool orig_format
)
10560 function_args_iterator iter
;
10562 unsigned int parmnum
;
10564 function_args_iter_init (&iter
, TREE_TYPE (function
));
10565 /* We've declared the implementation functions to use "volatile void *"
10566 as the pointer parameter, so we shouldn't get any complaints from the
10567 call to check_function_arguments what ever type the user used. */
10568 function_args_iter_next (&iter
);
10569 ptype
= TREE_TYPE (TREE_TYPE ((*params
)[0]));
10570 ptype
= TYPE_MAIN_VARIANT (ptype
);
10572 /* For the rest of the values, we need to cast these to FTYPE, so that we
10573 don't get warnings for passing pointer types, etc. */
10577 tree val
, arg_type
;
10579 arg_type
= function_args_iter_cond (&iter
);
10580 /* XXX void_type_node belies the abstraction. */
10581 if (arg_type
== void_type_node
)
10585 if (params
->length () <= parmnum
)
10587 error_at (loc
, "too few arguments to function %qE", orig_function
);
10591 /* Only convert parameters if arg_type is unsigned integer type with
10592 new format sync routines, i.e. don't attempt to convert pointer
10593 arguments (e.g. EXPECTED argument of __atomic_compare_exchange_n),
10594 bool arguments (e.g. WEAK argument) or signed int arguments (memmodel
10596 if (TREE_CODE (arg_type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (arg_type
))
10598 /* Ideally for the first conversion we'd use convert_for_assignment
10599 so that we get warnings for anything that doesn't match the pointer
10600 type. This isn't portable across the C and C++ front ends atm. */
10601 val
= (*params
)[parmnum
];
10602 val
= convert (ptype
, val
);
10603 val
= convert (arg_type
, val
);
10604 (*params
)[parmnum
] = val
;
10607 function_args_iter_next (&iter
);
10610 /* __atomic routines are not variadic. */
10611 if (!orig_format
&& params
->length () != parmnum
+ 1)
10613 error_at (loc
, "too many arguments to function %qE", orig_function
);
10617 /* The definition of these primitives is variadic, with the remaining
10618 being "an optional list of variables protected by the memory barrier".
10619 No clue what that's supposed to mean, precisely, but we consider all
10620 call-clobbered variables to be protected so we're safe. */
10621 params
->truncate (parmnum
+ 1);
10626 /* A helper function for resolve_overloaded_builtin. Adds a cast to
10627 RESULT to make it match the type of the first pointer argument in
10631 sync_resolve_return (tree first_param
, tree result
, bool orig_format
)
10633 tree ptype
= TREE_TYPE (TREE_TYPE (first_param
));
10634 tree rtype
= TREE_TYPE (result
);
10635 ptype
= TYPE_MAIN_VARIANT (ptype
);
10637 /* New format doesn't require casting unless the types are the same size. */
10638 if (orig_format
|| tree_int_cst_equal (TYPE_SIZE (ptype
), TYPE_SIZE (rtype
)))
10639 return convert (ptype
, result
);
10644 /* This function verifies the PARAMS to generic atomic FUNCTION.
10645 It returns the size if all the parameters are the same size, otherwise
10646 0 is returned if the parameters are invalid. */
10649 get_atomic_generic_size (location_t loc
, tree function
,
10650 vec
<tree
, va_gc
> *params
)
10652 unsigned int n_param
;
10653 unsigned int n_model
;
10658 /* Determine the parameter makeup. */
10659 switch (DECL_FUNCTION_CODE (function
))
10661 case BUILT_IN_ATOMIC_EXCHANGE
:
10665 case BUILT_IN_ATOMIC_LOAD
:
10666 case BUILT_IN_ATOMIC_STORE
:
10670 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10675 gcc_unreachable ();
10678 if (vec_safe_length (params
) != n_param
)
10680 error_at (loc
, "incorrect number of arguments to function %qE", function
);
10684 /* Get type of first parameter, and determine its size. */
10685 type_0
= TREE_TYPE ((*params
)[0]);
10686 if (TREE_CODE (type_0
) == ARRAY_TYPE
)
10688 /* Force array-to-pointer decay for C++. */
10689 gcc_assert (c_dialect_cxx());
10690 (*params
)[0] = default_conversion ((*params
)[0]);
10691 type_0
= TREE_TYPE ((*params
)[0]);
10693 if (TREE_CODE (type_0
) != POINTER_TYPE
|| VOID_TYPE_P (TREE_TYPE (type_0
)))
10695 error_at (loc
, "argument 1 of %qE must be a non-void pointer type",
10700 /* Types must be compile time constant sizes. */
10701 if (TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type_0
)))) != INTEGER_CST
)
10704 "argument 1 of %qE must be a pointer to a constant size type",
10709 size_0
= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type_0
)));
10711 /* Zero size objects are not allowed. */
10715 "argument 1 of %qE must be a pointer to a nonzero size object",
10720 /* Check each other parameter is a pointer and the same size. */
10721 for (x
= 0; x
< n_param
- n_model
; x
++)
10724 tree type
= TREE_TYPE ((*params
)[x
]);
10725 /* __atomic_compare_exchange has a bool in the 4th position, skip it. */
10726 if (n_param
== 6 && x
== 3)
10728 if (!POINTER_TYPE_P (type
))
10730 error_at (loc
, "argument %d of %qE must be a pointer type", x
+ 1,
10734 tree type_size
= TYPE_SIZE_UNIT (TREE_TYPE (type
));
10735 size
= type_size
? tree_to_uhwi (type_size
) : 0;
10736 if (size
!= size_0
)
10738 error_at (loc
, "size mismatch in argument %d of %qE", x
+ 1,
10744 /* Check memory model parameters for validity. */
10745 for (x
= n_param
- n_model
; x
< n_param
; x
++)
10747 tree p
= (*params
)[x
];
10748 if (TREE_CODE (p
) == INTEGER_CST
)
10750 int i
= tree_to_uhwi (p
);
10751 if (i
< 0 || (i
& MEMMODEL_MASK
) >= MEMMODEL_LAST
)
10753 warning_at (loc
, OPT_Winvalid_memory_model
,
10754 "invalid memory model argument %d of %qE", x
+ 1,
10759 if (!INTEGRAL_TYPE_P (TREE_TYPE (p
)))
10761 error_at (loc
, "non-integer memory model argument %d of %qE", x
+ 1,
10771 /* This will take an __atomic_ generic FUNCTION call, and add a size parameter N
10772 at the beginning of the parameter list PARAMS representing the size of the
10773 objects. This is to match the library ABI requirement. LOC is the location
10774 of the function call.
10775 The new function is returned if it needed rebuilding, otherwise NULL_TREE is
10776 returned to allow the external call to be constructed. */
10779 add_atomic_size_parameter (unsigned n
, location_t loc
, tree function
,
10780 vec
<tree
, va_gc
> *params
)
10784 /* Insert a SIZE_T parameter as the first param. If there isn't
10785 enough space, allocate a new vector and recursively re-build with that. */
10786 if (!params
->space (1))
10788 unsigned int z
, len
;
10789 vec
<tree
, va_gc
> *v
;
10792 len
= params
->length ();
10793 vec_alloc (v
, len
+ 1);
10794 v
->quick_push (build_int_cst (size_type_node
, n
));
10795 for (z
= 0; z
< len
; z
++)
10796 v
->quick_push ((*params
)[z
]);
10797 f
= build_function_call_vec (loc
, vNULL
, function
, v
, NULL
);
10802 /* Add the size parameter and leave as a function call for processing. */
10803 size_node
= build_int_cst (size_type_node
, n
);
10804 params
->quick_insert (0, size_node
);
10809 /* Return whether atomic operations for naturally aligned N-byte
10810 arguments are supported, whether inline or through libatomic. */
10812 atomic_size_supported_p (int n
)
10823 return targetm
.scalar_mode_supported_p (TImode
);
10830 /* This will process an __atomic_exchange function call, determine whether it
10831 needs to be mapped to the _N variation, or turned into a library call.
10832 LOC is the location of the builtin call.
10833 FUNCTION is the DECL that has been invoked;
10834 PARAMS is the argument list for the call. The return value is non-null
10835 TRUE is returned if it is translated into the proper format for a call to the
10836 external library, and NEW_RETURN is set the tree for that function.
10837 FALSE is returned if processing for the _N variation is required, and
10838 NEW_RETURN is set to the the return value the result is copied into. */
10840 resolve_overloaded_atomic_exchange (location_t loc
, tree function
,
10841 vec
<tree
, va_gc
> *params
, tree
*new_return
)
10843 tree p0
, p1
, p2
, p3
;
10844 tree I_type
, I_type_ptr
;
10845 int n
= get_atomic_generic_size (loc
, function
, params
);
10847 /* Size of 0 is an error condition. */
10850 *new_return
= error_mark_node
;
10854 /* If not a lock-free size, change to the library generic format. */
10855 if (!atomic_size_supported_p (n
))
10857 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10861 /* Otherwise there is a lockfree match, transform the call from:
10862 void fn(T* mem, T* desired, T* return, model)
10864 *return = (T) (fn (In* mem, (In) *desired, model)) */
10871 /* Create pointer to appropriate size. */
10872 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10873 I_type_ptr
= build_pointer_type (I_type
);
10875 /* Convert object pointer to required type. */
10876 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10878 /* Convert new value to required type, and dereference it. */
10879 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
10880 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
10883 /* Move memory model to the 3rd position, and end param list. */
10885 params
->truncate (3);
10887 /* Convert return pointer and dereference it for later assignment. */
10888 *new_return
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
10894 /* This will process an __atomic_compare_exchange function call, determine
10895 whether it needs to be mapped to the _N variation, or turned into a lib call.
10896 LOC is the location of the builtin call.
10897 FUNCTION is the DECL that has been invoked;
10898 PARAMS is the argument list for the call. The return value is non-null
10899 TRUE is returned if it is translated into the proper format for a call to the
10900 external library, and NEW_RETURN is set the tree for that function.
10901 FALSE is returned if processing for the _N variation is required. */
10904 resolve_overloaded_atomic_compare_exchange (location_t loc
, tree function
,
10905 vec
<tree
, va_gc
> *params
,
10909 tree I_type
, I_type_ptr
;
10910 int n
= get_atomic_generic_size (loc
, function
, params
);
10912 /* Size of 0 is an error condition. */
10915 *new_return
= error_mark_node
;
10919 /* If not a lock-free size, change to the library generic format. */
10920 if (!atomic_size_supported_p (n
))
10922 /* The library generic format does not have the weak parameter, so
10923 remove it from the param list. Since a parameter has been removed,
10924 we can be sure that there is room for the SIZE_T parameter, meaning
10925 there will not be a recursive rebuilding of the parameter list, so
10926 there is no danger this will be done twice. */
10929 (*params
)[3] = (*params
)[4];
10930 (*params
)[4] = (*params
)[5];
10931 params
->truncate (5);
10933 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10937 /* Otherwise, there is a match, so the call needs to be transformed from:
10938 bool fn(T* mem, T* desired, T* return, weak, success, failure)
10940 bool fn ((In *)mem, (In *)expected, (In) *desired, weak, succ, fail) */
10946 /* Create pointer to appropriate size. */
10947 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10948 I_type_ptr
= build_pointer_type (I_type
);
10950 /* Convert object pointer to required type. */
10951 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10954 /* Convert expected pointer to required type. */
10955 p1
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p1
);
10958 /* Convert desired value to required type, and dereference it. */
10959 p2
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
10960 p2
= build1 (VIEW_CONVERT_EXPR
, I_type
, p2
);
10963 /* The rest of the parameters are fine. NULL means no special return value
10965 *new_return
= NULL
;
10970 /* This will process an __atomic_load function call, determine whether it
10971 needs to be mapped to the _N variation, or turned into a library call.
10972 LOC is the location of the builtin call.
10973 FUNCTION is the DECL that has been invoked;
10974 PARAMS is the argument list for the call. The return value is non-null
10975 TRUE is returned if it is translated into the proper format for a call to the
10976 external library, and NEW_RETURN is set the tree for that function.
10977 FALSE is returned if processing for the _N variation is required, and
10978 NEW_RETURN is set to the the return value the result is copied into. */
10981 resolve_overloaded_atomic_load (location_t loc
, tree function
,
10982 vec
<tree
, va_gc
> *params
, tree
*new_return
)
10985 tree I_type
, I_type_ptr
;
10986 int n
= get_atomic_generic_size (loc
, function
, params
);
10988 /* Size of 0 is an error condition. */
10991 *new_return
= error_mark_node
;
10995 /* If not a lock-free size, change to the library generic format. */
10996 if (!atomic_size_supported_p (n
))
10998 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
11002 /* Otherwise, there is a match, so the call needs to be transformed from:
11003 void fn(T* mem, T* return, model)
11005 *return = (T) (fn ((In *) mem, model)) */
11011 /* Create pointer to appropriate size. */
11012 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
11013 I_type_ptr
= build_pointer_type (I_type
);
11015 /* Convert object pointer to required type. */
11016 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
11019 /* Move memory model to the 2nd position, and end param list. */
11021 params
->truncate (2);
11023 /* Convert return pointer and dereference it for later assignment. */
11024 *new_return
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
11030 /* This will process an __atomic_store function call, determine whether it
11031 needs to be mapped to the _N variation, or turned into a library call.
11032 LOC is the location of the builtin call.
11033 FUNCTION is the DECL that has been invoked;
11034 PARAMS is the argument list for the call. The return value is non-null
11035 TRUE is returned if it is translated into the proper format for a call to the
11036 external library, and NEW_RETURN is set the tree for that function.
11037 FALSE is returned if processing for the _N variation is required, and
11038 NEW_RETURN is set to the the return value the result is copied into. */
11041 resolve_overloaded_atomic_store (location_t loc
, tree function
,
11042 vec
<tree
, va_gc
> *params
, tree
*new_return
)
11045 tree I_type
, I_type_ptr
;
11046 int n
= get_atomic_generic_size (loc
, function
, params
);
11048 /* Size of 0 is an error condition. */
11051 *new_return
= error_mark_node
;
11055 /* If not a lock-free size, change to the library generic format. */
11056 if (!atomic_size_supported_p (n
))
11058 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
11062 /* Otherwise, there is a match, so the call needs to be transformed from:
11063 void fn(T* mem, T* value, model)
11065 fn ((In *) mem, (In) *value, model) */
11070 /* Create pointer to appropriate size. */
11071 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
11072 I_type_ptr
= build_pointer_type (I_type
);
11074 /* Convert object pointer to required type. */
11075 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
11078 /* Convert new value to required type, and dereference it. */
11079 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
11080 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
11083 /* The memory model is in the right spot already. Return is void. */
11084 *new_return
= NULL_TREE
;
11090 /* Some builtin functions are placeholders for other expressions. This
11091 function should be called immediately after parsing the call expression
11092 before surrounding code has committed to the type of the expression.
11094 LOC is the location of the builtin call.
11096 FUNCTION is the DECL that has been invoked; it is known to be a builtin.
11097 PARAMS is the argument list for the call. The return value is non-null
11098 when expansion is complete, and null if normal processing should
11102 resolve_overloaded_builtin (location_t loc
, tree function
,
11103 vec
<tree
, va_gc
> *params
)
11105 enum built_in_function orig_code
= DECL_FUNCTION_CODE (function
);
11106 bool orig_format
= true;
11107 tree new_return
= NULL_TREE
;
11109 switch (DECL_BUILT_IN_CLASS (function
))
11111 case BUILT_IN_NORMAL
:
11114 if (targetm
.resolve_overloaded_builtin
)
11115 return targetm
.resolve_overloaded_builtin (loc
, function
, params
);
11122 /* Handle BUILT_IN_NORMAL here. */
11125 case BUILT_IN_ATOMIC_EXCHANGE
:
11126 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
11127 case BUILT_IN_ATOMIC_LOAD
:
11128 case BUILT_IN_ATOMIC_STORE
:
11130 /* Handle these 4 together so that they can fall through to the next
11131 case if the call is transformed to an _N variant. */
11134 case BUILT_IN_ATOMIC_EXCHANGE
:
11136 if (resolve_overloaded_atomic_exchange (loc
, function
, params
,
11139 /* Change to the _N variant. */
11140 orig_code
= BUILT_IN_ATOMIC_EXCHANGE_N
;
11144 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
11146 if (resolve_overloaded_atomic_compare_exchange (loc
, function
,
11150 /* Change to the _N variant. */
11151 orig_code
= BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
;
11154 case BUILT_IN_ATOMIC_LOAD
:
11156 if (resolve_overloaded_atomic_load (loc
, function
, params
,
11159 /* Change to the _N variant. */
11160 orig_code
= BUILT_IN_ATOMIC_LOAD_N
;
11163 case BUILT_IN_ATOMIC_STORE
:
11165 if (resolve_overloaded_atomic_store (loc
, function
, params
,
11168 /* Change to the _N variant. */
11169 orig_code
= BUILT_IN_ATOMIC_STORE_N
;
11173 gcc_unreachable ();
11175 /* Fallthrough to the normal processing. */
11177 case BUILT_IN_ATOMIC_EXCHANGE_N
:
11178 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
:
11179 case BUILT_IN_ATOMIC_LOAD_N
:
11180 case BUILT_IN_ATOMIC_STORE_N
:
11181 case BUILT_IN_ATOMIC_ADD_FETCH_N
:
11182 case BUILT_IN_ATOMIC_SUB_FETCH_N
:
11183 case BUILT_IN_ATOMIC_AND_FETCH_N
:
11184 case BUILT_IN_ATOMIC_NAND_FETCH_N
:
11185 case BUILT_IN_ATOMIC_XOR_FETCH_N
:
11186 case BUILT_IN_ATOMIC_OR_FETCH_N
:
11187 case BUILT_IN_ATOMIC_FETCH_ADD_N
:
11188 case BUILT_IN_ATOMIC_FETCH_SUB_N
:
11189 case BUILT_IN_ATOMIC_FETCH_AND_N
:
11190 case BUILT_IN_ATOMIC_FETCH_NAND_N
:
11191 case BUILT_IN_ATOMIC_FETCH_XOR_N
:
11192 case BUILT_IN_ATOMIC_FETCH_OR_N
:
11194 orig_format
= false;
11195 /* Fallthru for parameter processing. */
11197 case BUILT_IN_SYNC_FETCH_AND_ADD_N
:
11198 case BUILT_IN_SYNC_FETCH_AND_SUB_N
:
11199 case BUILT_IN_SYNC_FETCH_AND_OR_N
:
11200 case BUILT_IN_SYNC_FETCH_AND_AND_N
:
11201 case BUILT_IN_SYNC_FETCH_AND_XOR_N
:
11202 case BUILT_IN_SYNC_FETCH_AND_NAND_N
:
11203 case BUILT_IN_SYNC_ADD_AND_FETCH_N
:
11204 case BUILT_IN_SYNC_SUB_AND_FETCH_N
:
11205 case BUILT_IN_SYNC_OR_AND_FETCH_N
:
11206 case BUILT_IN_SYNC_AND_AND_FETCH_N
:
11207 case BUILT_IN_SYNC_XOR_AND_FETCH_N
:
11208 case BUILT_IN_SYNC_NAND_AND_FETCH_N
:
11209 case BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
:
11210 case BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N
:
11211 case BUILT_IN_SYNC_LOCK_TEST_AND_SET_N
:
11212 case BUILT_IN_SYNC_LOCK_RELEASE_N
:
11214 int n
= sync_resolve_size (function
, params
);
11215 tree new_function
, first_param
, result
;
11216 enum built_in_function fncode
;
11219 return error_mark_node
;
11221 fncode
= (enum built_in_function
)((int)orig_code
+ exact_log2 (n
) + 1);
11222 new_function
= builtin_decl_explicit (fncode
);
11223 if (!sync_resolve_params (loc
, function
, new_function
, params
,
11225 return error_mark_node
;
11227 first_param
= (*params
)[0];
11228 result
= build_function_call_vec (loc
, vNULL
, new_function
, params
,
11230 if (result
== error_mark_node
)
11232 if (orig_code
!= BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
11233 && orig_code
!= BUILT_IN_SYNC_LOCK_RELEASE_N
11234 && orig_code
!= BUILT_IN_ATOMIC_STORE_N
)
11235 result
= sync_resolve_return (first_param
, result
, orig_format
);
11237 /* If new_return is set, assign function to that expr and cast the
11238 result to void since the generic interface returned void. */
11241 /* Cast function result from I{1,2,4,8,16} to the required type. */
11242 result
= build1 (VIEW_CONVERT_EXPR
, TREE_TYPE (new_return
), result
);
11243 result
= build2 (MODIFY_EXPR
, TREE_TYPE (new_return
), new_return
,
11245 TREE_SIDE_EFFECTS (result
) = 1;
11246 protected_set_expr_location (result
, loc
);
11247 result
= convert (void_type_node
, result
);
11257 /* vector_types_compatible_elements_p is used in type checks of vectors
11258 values used as operands of binary operators. Where it returns true, and
11259 the other checks of the caller succeed (being vector types in he first
11260 place, and matching number of elements), we can just treat the types
11261 as essentially the same.
11262 Contrast with vector_targets_convertible_p, which is used for vector
11263 pointer types, and vector_types_convertible_p, which will allow
11264 language-specific matches under the control of flag_lax_vector_conversions,
11265 and might still require a conversion. */
11266 /* True if vector types T1 and T2 can be inputs to the same binary
11267 operator without conversion.
11268 We don't check the overall vector size here because some of our callers
11269 want to give different error messages when the vectors are compatible
11270 except for the element count. */
11273 vector_types_compatible_elements_p (tree t1
, tree t2
)
11275 bool opaque
= TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
);
11276 t1
= TREE_TYPE (t1
);
11277 t2
= TREE_TYPE (t2
);
11279 enum tree_code c1
= TREE_CODE (t1
), c2
= TREE_CODE (t2
);
11281 gcc_assert ((c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
|| c1
== FIXED_POINT_TYPE
)
11282 && (c2
== INTEGER_TYPE
|| c2
== REAL_TYPE
11283 || c2
== FIXED_POINT_TYPE
));
11285 t1
= c_common_signed_type (t1
);
11286 t2
= c_common_signed_type (t2
);
11287 /* Equality works here because c_common_signed_type uses
11288 TYPE_MAIN_VARIANT. */
11291 if (opaque
&& c1
== c2
11292 && (c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
)
11293 && TYPE_PRECISION (t1
) == TYPE_PRECISION (t2
))
11298 /* Check for missing format attributes on function pointers. LTYPE is
11299 the new type or left-hand side type. RTYPE is the old type or
11300 right-hand side type. Returns TRUE if LTYPE is missing the desired
11304 check_missing_format_attribute (tree ltype
, tree rtype
)
11306 tree
const ttr
= TREE_TYPE (rtype
), ttl
= TREE_TYPE (ltype
);
11309 for (ra
= TYPE_ATTRIBUTES (ttr
); ra
; ra
= TREE_CHAIN (ra
))
11310 if (is_attribute_p ("format", TREE_PURPOSE (ra
)))
11315 for (la
= TYPE_ATTRIBUTES (ttl
); la
; la
= TREE_CHAIN (la
))
11316 if (is_attribute_p ("format", TREE_PURPOSE (la
)))
11324 /* Subscripting with type char is likely to lose on a machine where
11325 chars are signed. So warn on any machine, but optionally. Don't
11326 warn for unsigned char since that type is safe. Don't warn for
11327 signed char because anyone who uses that must have done so
11328 deliberately. Furthermore, we reduce the false positive load by
11329 warning only for non-constant value of type char. */
11332 warn_array_subscript_with_type_char (location_t loc
, tree index
)
11334 if (TYPE_MAIN_VARIANT (TREE_TYPE (index
)) == char_type_node
11335 && TREE_CODE (index
) != INTEGER_CST
)
11336 warning_at (loc
, OPT_Wchar_subscripts
,
11337 "array subscript has type %<char%>");
11340 /* Implement -Wparentheses for the unexpected C precedence rules, to
11341 cover cases like x + y << z which readers are likely to
11342 misinterpret. We have seen an expression in which CODE is a binary
11343 operator used to combine expressions ARG_LEFT and ARG_RIGHT, which
11344 before folding had CODE_LEFT and CODE_RIGHT. CODE_LEFT and
11345 CODE_RIGHT may be ERROR_MARK, which means that that side of the
11346 expression was not formed using a binary or unary operator, or it
11347 was enclosed in parentheses. */
11350 warn_about_parentheses (location_t loc
, enum tree_code code
,
11351 enum tree_code code_left
, tree arg_left
,
11352 enum tree_code code_right
, tree arg_right
)
11354 if (!warn_parentheses
)
11357 /* This macro tests that the expression ARG with original tree code
11358 CODE appears to be a boolean expression. or the result of folding a
11359 boolean expression. */
11360 #define APPEARS_TO_BE_BOOLEAN_EXPR_P(CODE, ARG) \
11361 (truth_value_p (TREE_CODE (ARG)) \
11362 || TREE_CODE (TREE_TYPE (ARG)) == BOOLEAN_TYPE \
11363 /* Folding may create 0 or 1 integers from other expressions. */ \
11364 || ((CODE) != INTEGER_CST \
11365 && (integer_onep (ARG) || integer_zerop (ARG))))
11370 if (code_left
== PLUS_EXPR
)
11371 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11372 "suggest parentheses around %<+%> inside %<<<%>");
11373 else if (code_right
== PLUS_EXPR
)
11374 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11375 "suggest parentheses around %<+%> inside %<<<%>");
11376 else if (code_left
== MINUS_EXPR
)
11377 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11378 "suggest parentheses around %<-%> inside %<<<%>");
11379 else if (code_right
== MINUS_EXPR
)
11380 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11381 "suggest parentheses around %<-%> inside %<<<%>");
11385 if (code_left
== PLUS_EXPR
)
11386 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11387 "suggest parentheses around %<+%> inside %<>>%>");
11388 else if (code_right
== PLUS_EXPR
)
11389 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11390 "suggest parentheses around %<+%> inside %<>>%>");
11391 else if (code_left
== MINUS_EXPR
)
11392 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11393 "suggest parentheses around %<-%> inside %<>>%>");
11394 else if (code_right
== MINUS_EXPR
)
11395 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11396 "suggest parentheses around %<-%> inside %<>>%>");
11399 case TRUTH_ORIF_EXPR
:
11400 if (code_left
== TRUTH_ANDIF_EXPR
)
11401 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11402 "suggest parentheses around %<&&%> within %<||%>");
11403 else if (code_right
== TRUTH_ANDIF_EXPR
)
11404 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11405 "suggest parentheses around %<&&%> within %<||%>");
11409 if (code_left
== BIT_AND_EXPR
|| code_left
== BIT_XOR_EXPR
11410 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
)
11411 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11412 "suggest parentheses around arithmetic in operand of %<|%>");
11413 else if (code_right
== BIT_AND_EXPR
|| code_right
== BIT_XOR_EXPR
11414 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
11415 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11416 "suggest parentheses around arithmetic in operand of %<|%>");
11417 /* Check cases like x|y==z */
11418 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11419 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11420 "suggest parentheses around comparison in operand of %<|%>");
11421 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11422 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11423 "suggest parentheses around comparison in operand of %<|%>");
11424 /* Check cases like !x | y */
11425 else if (code_left
== TRUTH_NOT_EXPR
11426 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
11427 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11428 "suggest parentheses around operand of "
11429 "%<!%> or change %<|%> to %<||%> or %<!%> to %<~%>");
11433 if (code_left
== BIT_AND_EXPR
11434 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
)
11435 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11436 "suggest parentheses around arithmetic in operand of %<^%>");
11437 else if (code_right
== BIT_AND_EXPR
11438 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
11439 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11440 "suggest parentheses around arithmetic in operand of %<^%>");
11441 /* Check cases like x^y==z */
11442 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11443 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11444 "suggest parentheses around comparison in operand of %<^%>");
11445 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11446 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11447 "suggest parentheses around comparison in operand of %<^%>");
11451 if (code_left
== PLUS_EXPR
)
11452 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11453 "suggest parentheses around %<+%> in operand of %<&%>");
11454 else if (code_right
== PLUS_EXPR
)
11455 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11456 "suggest parentheses around %<+%> in operand of %<&%>");
11457 else if (code_left
== MINUS_EXPR
)
11458 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11459 "suggest parentheses around %<-%> in operand of %<&%>");
11460 else if (code_right
== MINUS_EXPR
)
11461 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11462 "suggest parentheses around %<-%> in operand of %<&%>");
11463 /* Check cases like x&y==z */
11464 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11465 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11466 "suggest parentheses around comparison in operand of %<&%>");
11467 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11468 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11469 "suggest parentheses around comparison in operand of %<&%>");
11470 /* Check cases like !x & y */
11471 else if (code_left
== TRUTH_NOT_EXPR
11472 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
11473 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11474 "suggest parentheses around operand of "
11475 "%<!%> or change %<&%> to %<&&%> or %<!%> to %<~%>");
11479 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11480 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11481 "suggest parentheses around comparison in operand of %<==%>");
11482 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11483 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11484 "suggest parentheses around comparison in operand of %<==%>");
11487 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11488 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11489 "suggest parentheses around comparison in operand of %<!=%>");
11490 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11491 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11492 "suggest parentheses around comparison in operand of %<!=%>");
11496 if (TREE_CODE_CLASS (code
) == tcc_comparison
)
11498 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
11499 && code_left
!= NE_EXPR
&& code_left
!= EQ_EXPR
11500 && INTEGRAL_TYPE_P (TREE_TYPE (arg_left
)))
11501 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11502 "comparisons like %<X<=Y<=Z%> do not "
11503 "have their mathematical meaning");
11504 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
11505 && code_right
!= NE_EXPR
&& code_right
!= EQ_EXPR
11506 && INTEGRAL_TYPE_P (TREE_TYPE (arg_right
)))
11507 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11508 "comparisons like %<X<=Y<=Z%> do not "
11509 "have their mathematical meaning");
11513 #undef NOT_A_BOOLEAN_EXPR_P
11516 /* If LABEL (a LABEL_DECL) has not been used, issue a warning. */
11519 warn_for_unused_label (tree label
)
11521 if (!TREE_USED (label
))
11523 if (DECL_INITIAL (label
))
11524 warning (OPT_Wunused_label
, "label %q+D defined but not used", label
);
11526 warning (OPT_Wunused_label
, "label %q+D declared but not defined", label
);
11530 /* Warn for division by zero according to the value of DIVISOR. LOC
11531 is the location of the division operator. */
11534 warn_for_div_by_zero (location_t loc
, tree divisor
)
11536 /* If DIVISOR is zero, and has integral or fixed-point type, issue a warning
11537 about division by zero. Do not issue a warning if DIVISOR has a
11538 floating-point type, since we consider 0.0/0.0 a valid way of
11539 generating a NaN. */
11540 if (c_inhibit_evaluation_warnings
== 0
11541 && (integer_zerop (divisor
) || fixed_zerop (divisor
)))
11542 warning_at (loc
, OPT_Wdiv_by_zero
, "division by zero");
11545 /* Subroutine of build_binary_op. Give warnings for comparisons
11546 between signed and unsigned quantities that may fail. Do the
11547 checking based on the original operand trees ORIG_OP0 and ORIG_OP1,
11548 so that casts will be considered, but default promotions won't
11551 LOCATION is the location of the comparison operator.
11553 The arguments of this function map directly to local variables
11554 of build_binary_op. */
11557 warn_for_sign_compare (location_t location
,
11558 tree orig_op0
, tree orig_op1
,
11559 tree op0
, tree op1
,
11560 tree result_type
, enum tree_code resultcode
)
11562 int op0_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op0
));
11563 int op1_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op1
));
11564 int unsignedp0
, unsignedp1
;
11566 /* In C++, check for comparison of different enum types. */
11567 if (c_dialect_cxx()
11568 && TREE_CODE (TREE_TYPE (orig_op0
)) == ENUMERAL_TYPE
11569 && TREE_CODE (TREE_TYPE (orig_op1
)) == ENUMERAL_TYPE
11570 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0
))
11571 != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1
)))
11573 warning_at (location
,
11574 OPT_Wsign_compare
, "comparison between types %qT and %qT",
11575 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
));
11578 /* Do not warn if the comparison is being done in a signed type,
11579 since the signed type will only be chosen if it can represent
11580 all the values of the unsigned type. */
11581 if (!TYPE_UNSIGNED (result_type
))
11583 /* Do not warn if both operands are unsigned. */
11584 else if (op0_signed
== op1_signed
)
11588 tree sop
, uop
, base_type
;
11592 sop
= orig_op0
, uop
= orig_op1
;
11594 sop
= orig_op1
, uop
= orig_op0
;
11596 STRIP_TYPE_NOPS (sop
);
11597 STRIP_TYPE_NOPS (uop
);
11598 base_type
= (TREE_CODE (result_type
) == COMPLEX_TYPE
11599 ? TREE_TYPE (result_type
) : result_type
);
11601 /* Do not warn if the signed quantity is an unsuffixed integer
11602 literal (or some static constant expression involving such
11603 literals or a conditional expression involving such literals)
11604 and it is non-negative. */
11605 if (tree_expr_nonnegative_warnv_p (sop
, &ovf
))
11607 /* Do not warn if the comparison is an equality operation, the
11608 unsigned quantity is an integral constant, and it would fit
11609 in the result if the result were signed. */
11610 else if (TREE_CODE (uop
) == INTEGER_CST
11611 && (resultcode
== EQ_EXPR
|| resultcode
== NE_EXPR
)
11612 && int_fits_type_p (uop
, c_common_signed_type (base_type
)))
11614 /* In C, do not warn if the unsigned quantity is an enumeration
11615 constant and its maximum value would fit in the result if the
11616 result were signed. */
11617 else if (!c_dialect_cxx() && TREE_CODE (uop
) == INTEGER_CST
11618 && TREE_CODE (TREE_TYPE (uop
)) == ENUMERAL_TYPE
11619 && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (uop
)),
11620 c_common_signed_type (base_type
)))
11623 warning_at (location
,
11625 "comparison between signed and unsigned integer expressions");
11628 /* Warn if two unsigned values are being compared in a size larger
11629 than their original size, and one (and only one) is the result of
11630 a `~' operator. This comparison will always fail.
11632 Also warn if one operand is a constant, and the constant does not
11633 have all bits set that are set in the ~ operand when it is
11636 op0
= c_common_get_narrower (op0
, &unsignedp0
);
11637 op1
= c_common_get_narrower (op1
, &unsignedp1
);
11639 if ((TREE_CODE (op0
) == BIT_NOT_EXPR
)
11640 ^ (TREE_CODE (op1
) == BIT_NOT_EXPR
))
11642 if (TREE_CODE (op0
) == BIT_NOT_EXPR
)
11643 op0
= c_common_get_narrower (TREE_OPERAND (op0
, 0), &unsignedp0
);
11644 if (TREE_CODE (op1
) == BIT_NOT_EXPR
)
11645 op1
= c_common_get_narrower (TREE_OPERAND (op1
, 0), &unsignedp1
);
11647 if (tree_fits_shwi_p (op0
) || tree_fits_shwi_p (op1
))
11650 HOST_WIDE_INT constant
, mask
;
11654 if (tree_fits_shwi_p (op0
))
11657 unsignedp
= unsignedp1
;
11658 constant
= tree_to_shwi (op0
);
11663 unsignedp
= unsignedp0
;
11664 constant
= tree_to_shwi (op1
);
11667 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
11668 if (bits
< TYPE_PRECISION (result_type
)
11669 && bits
< HOST_BITS_PER_LONG
&& unsignedp
)
11671 mask
= (~ (HOST_WIDE_INT
) 0) << bits
;
11672 if ((mask
& constant
) != mask
)
11675 warning_at (location
, OPT_Wsign_compare
,
11676 "promoted ~unsigned is always non-zero");
11678 warning_at (location
, OPT_Wsign_compare
,
11679 "comparison of promoted ~unsigned with constant");
11683 else if (unsignedp0
&& unsignedp1
11684 && (TYPE_PRECISION (TREE_TYPE (op0
))
11685 < TYPE_PRECISION (result_type
))
11686 && (TYPE_PRECISION (TREE_TYPE (op1
))
11687 < TYPE_PRECISION (result_type
)))
11688 warning_at (location
, OPT_Wsign_compare
,
11689 "comparison of promoted ~unsigned with unsigned");
11693 /* RESULT_TYPE is the result of converting TYPE1 and TYPE2 to a common
11694 type via c_common_type. If -Wdouble-promotion is in use, and the
11695 conditions for warning have been met, issue a warning. GMSGID is
11696 the warning message. It must have two %T specifiers for the type
11697 that was converted (generally "float") and the type to which it was
11698 converted (generally "double), respectively. LOC is the location
11699 to which the awrning should refer. */
11702 do_warn_double_promotion (tree result_type
, tree type1
, tree type2
,
11703 const char *gmsgid
, location_t loc
)
11707 if (!warn_double_promotion
)
11709 /* If the conversion will not occur at run-time, there is no need to
11711 if (c_inhibit_evaluation_warnings
)
11713 if (TYPE_MAIN_VARIANT (result_type
) != double_type_node
11714 && TYPE_MAIN_VARIANT (result_type
) != complex_double_type_node
)
11716 if (TYPE_MAIN_VARIANT (type1
) == float_type_node
11717 || TYPE_MAIN_VARIANT (type1
) == complex_float_type_node
)
11718 source_type
= type1
;
11719 else if (TYPE_MAIN_VARIANT (type2
) == float_type_node
11720 || TYPE_MAIN_VARIANT (type2
) == complex_float_type_node
)
11721 source_type
= type2
;
11724 warning_at (loc
, OPT_Wdouble_promotion
, gmsgid
, source_type
, result_type
);
11727 /* Setup a TYPE_DECL node as a typedef representation.
11729 X is a TYPE_DECL for a typedef statement. Create a brand new
11730 ..._TYPE node (which will be just a variant of the existing
11731 ..._TYPE node with identical properties) and then install X
11732 as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
11734 The whole point here is to end up with a situation where each
11735 and every ..._TYPE node the compiler creates will be uniquely
11736 associated with AT MOST one node representing a typedef name.
11737 This way, even though the compiler substitutes corresponding
11738 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
11739 early on, later parts of the compiler can always do the reverse
11740 translation and get back the corresponding typedef name. For
11743 typedef struct S MY_TYPE;
11746 Later parts of the compiler might only know that `object' was of
11747 type `struct S' if it were not for code just below. With this
11748 code however, later parts of the compiler see something like:
11750 struct S' == struct S
11751 typedef struct S' MY_TYPE;
11754 And they can then deduce (from the node for type struct S') that
11755 the original object declaration was:
11759 Being able to do this is important for proper support of protoize,
11760 and also for generating precise symbolic debugging information
11761 which takes full account of the programmer's (typedef) vocabulary.
11763 Obviously, we don't want to generate a duplicate ..._TYPE node if
11764 the TYPE_DECL node that we are now processing really represents a
11765 standard built-in type. */
11768 set_underlying_type (tree x
)
11770 if (x
== error_mark_node
)
11772 if (DECL_IS_BUILTIN (x
))
11774 if (TYPE_NAME (TREE_TYPE (x
)) == 0)
11775 TYPE_NAME (TREE_TYPE (x
)) = x
;
11777 else if (TREE_TYPE (x
) != error_mark_node
11778 && DECL_ORIGINAL_TYPE (x
) == NULL_TREE
)
11780 tree tt
= TREE_TYPE (x
);
11781 DECL_ORIGINAL_TYPE (x
) = tt
;
11782 tt
= build_variant_type_copy (tt
);
11783 TYPE_STUB_DECL (tt
) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x
));
11784 TYPE_NAME (tt
) = x
;
11785 TREE_USED (tt
) = TREE_USED (x
);
11786 TREE_TYPE (x
) = tt
;
11790 /* Record the types used by the current global variable declaration
11791 being parsed, so that we can decide later to emit their debug info.
11792 Those types are in types_used_by_cur_var_decl, and we are going to
11793 store them in the types_used_by_vars_hash hash table.
11794 DECL is the declaration of the global variable that has been parsed. */
11797 record_types_used_by_current_var_decl (tree decl
)
11799 gcc_assert (decl
&& DECL_P (decl
) && TREE_STATIC (decl
));
11801 while (types_used_by_cur_var_decl
&& !types_used_by_cur_var_decl
->is_empty ())
11803 tree type
= types_used_by_cur_var_decl
->pop ();
11804 types_used_by_var_decl_insert (type
, decl
);
11808 /* If DECL is a typedef that is declared in the current function,
11809 record it for the purpose of -Wunused-local-typedefs. */
11812 record_locally_defined_typedef (tree decl
)
11814 struct c_language_function
*l
;
11816 if (!warn_unused_local_typedefs
11818 /* if this is not a locally defined typedef then we are not
11820 || !is_typedef_decl (decl
)
11821 || !decl_function_context (decl
))
11824 l
= (struct c_language_function
*) cfun
->language
;
11825 vec_safe_push (l
->local_typedefs
, decl
);
11828 /* If T is a TYPE_DECL declared locally, mark it as used. */
11831 maybe_record_typedef_use (tree t
)
11833 if (!is_typedef_decl (t
))
11836 TREE_USED (t
) = true;
11839 /* Warn if there are some unused locally defined typedefs in the
11840 current function. */
11843 maybe_warn_unused_local_typedefs (void)
11847 /* The number of times we have emitted -Wunused-local-typedefs
11848 warnings. If this is different from errorcount, that means some
11849 unrelated errors have been issued. In which case, we'll avoid
11850 emitting "unused-local-typedefs" warnings. */
11851 static int unused_local_typedefs_warn_count
;
11852 struct c_language_function
*l
;
11857 if ((l
= (struct c_language_function
*) cfun
->language
) == NULL
)
11860 if (warn_unused_local_typedefs
11861 && errorcount
== unused_local_typedefs_warn_count
)
11863 FOR_EACH_VEC_SAFE_ELT (l
->local_typedefs
, i
, decl
)
11864 if (!TREE_USED (decl
))
11865 warning_at (DECL_SOURCE_LOCATION (decl
),
11866 OPT_Wunused_local_typedefs
,
11867 "typedef %qD locally defined but not used", decl
);
11868 unused_local_typedefs_warn_count
= errorcount
;
11871 vec_free (l
->local_typedefs
);
11874 /* Warn about boolean expression compared with an integer value different
11875 from true/false. Warns also e.g. about "(i1 == i2) == 2".
11876 LOC is the location of the comparison, CODE is its code, OP0 and OP1
11877 are the operands of the comparison. The caller must ensure that
11878 either operand is a boolean expression. */
11881 maybe_warn_bool_compare (location_t loc
, enum tree_code code
, tree op0
,
11884 if (TREE_CODE_CLASS (code
) != tcc_comparison
)
11887 tree cst
= (TREE_CODE (op0
) == INTEGER_CST
)
11888 ? op0
: (TREE_CODE (op1
) == INTEGER_CST
) ? op1
: NULL_TREE
;
11892 if (!integer_zerop (cst
) && !integer_onep (cst
))
11894 int sign
= (TREE_CODE (op0
) == INTEGER_CST
)
11895 ? tree_int_cst_sgn (cst
) : -tree_int_cst_sgn (cst
);
11896 if (code
== EQ_EXPR
11897 || ((code
== GT_EXPR
|| code
== GE_EXPR
) && sign
< 0)
11898 || ((code
== LT_EXPR
|| code
== LE_EXPR
) && sign
> 0))
11899 warning_at (loc
, OPT_Wbool_compare
, "comparison of constant %qE "
11900 "with boolean expression is always false", cst
);
11902 warning_at (loc
, OPT_Wbool_compare
, "comparison of constant %qE "
11903 "with boolean expression is always true", cst
);
11907 /* The C and C++ parsers both use vectors to hold function arguments.
11908 For efficiency, we keep a cache of unused vectors. This is the
11911 typedef vec
<tree
, va_gc
> *tree_gc_vec
;
11912 static GTY((deletable
)) vec
<tree_gc_vec
, va_gc
> *tree_vector_cache
;
11914 /* Return a new vector from the cache. If the cache is empty,
11915 allocate a new vector. These vectors are GC'ed, so it is OK if the
11916 pointer is not released.. */
11919 make_tree_vector (void)
11921 if (tree_vector_cache
&& !tree_vector_cache
->is_empty ())
11922 return tree_vector_cache
->pop ();
11925 /* Passing 0 to vec::alloc returns NULL, and our callers require
11926 that we always return a non-NULL value. The vector code uses
11927 4 when growing a NULL vector, so we do too. */
11928 vec
<tree
, va_gc
> *v
;
11934 /* Release a vector of trees back to the cache. */
11937 release_tree_vector (vec
<tree
, va_gc
> *vec
)
11942 vec_safe_push (tree_vector_cache
, vec
);
11946 /* Get a new tree vector holding a single tree. */
11949 make_tree_vector_single (tree t
)
11951 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
11952 ret
->quick_push (t
);
11956 /* Get a new tree vector of the TREE_VALUEs of a TREE_LIST chain. */
11959 make_tree_vector_from_list (tree list
)
11961 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
11962 for (; list
; list
= TREE_CHAIN (list
))
11963 vec_safe_push (ret
, TREE_VALUE (list
));
11967 /* Get a new tree vector which is a copy of an existing one. */
11970 make_tree_vector_copy (const vec
<tree
, va_gc
> *orig
)
11972 vec
<tree
, va_gc
> *ret
;
11976 ret
= make_tree_vector ();
11977 vec_safe_reserve (ret
, vec_safe_length (orig
));
11978 FOR_EACH_VEC_SAFE_ELT (orig
, ix
, t
)
11979 ret
->quick_push (t
);
11983 /* Return true if KEYWORD starts a type specifier. */
11986 keyword_begins_type_specifier (enum rid keyword
)
11990 case RID_AUTO_TYPE
:
12002 case RID_DFLOAT128
:
12018 if (keyword
>= RID_FIRST_INT_N
12019 && keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
12020 && int_n_enabled_p
[keyword
-RID_FIRST_INT_N
])
12026 /* Return true if KEYWORD names a type qualifier. */
12029 keyword_is_type_qualifier (enum rid keyword
)
12043 /* Return true if KEYWORD names a storage class specifier.
12045 RID_TYPEDEF is not included in this list despite `typedef' being
12046 listed in C99 6.7.1.1. 6.7.1.3 indicates that `typedef' is listed as
12047 such for syntactic convenience only. */
12050 keyword_is_storage_class_specifier (enum rid keyword
)
12066 /* Return true if KEYWORD names a function-specifier [dcl.fct.spec]. */
12069 keyword_is_function_specifier (enum rid keyword
)
12083 /* Return true if KEYWORD names a decl-specifier [dcl.spec] or a
12084 declaration-specifier (C99 6.7). */
12087 keyword_is_decl_specifier (enum rid keyword
)
12089 if (keyword_is_storage_class_specifier (keyword
)
12090 || keyword_is_type_qualifier (keyword
)
12091 || keyword_is_function_specifier (keyword
))
12098 case RID_CONSTEXPR
:
12105 /* Initialize language-specific-bits of tree_contains_struct. */
12108 c_common_init_ts (void)
12110 MARK_TS_TYPED (C_MAYBE_CONST_EXPR
);
12111 MARK_TS_TYPED (EXCESS_PRECISION_EXPR
);
12112 MARK_TS_TYPED (ARRAY_NOTATION_REF
);
12115 /* Build a user-defined numeric literal out of an integer constant type VALUE
12116 with identifier SUFFIX. */
12119 build_userdef_literal (tree suffix_id
, tree value
,
12120 enum overflow_type overflow
, tree num_string
)
12122 tree literal
= make_node (USERDEF_LITERAL
);
12123 USERDEF_LITERAL_SUFFIX_ID (literal
) = suffix_id
;
12124 USERDEF_LITERAL_VALUE (literal
) = value
;
12125 USERDEF_LITERAL_OVERFLOW (literal
) = overflow
;
12126 USERDEF_LITERAL_NUM_STRING (literal
) = num_string
;
12130 /* For vector[index], convert the vector to a
12131 pointer of the underlying type. Return true if the resulting
12132 ARRAY_REF should not be an lvalue. */
12135 convert_vector_to_pointer_for_subscript (location_t loc
,
12136 tree
*vecp
, tree index
)
12139 if (TREE_CODE (TREE_TYPE (*vecp
)) == VECTOR_TYPE
)
12141 tree type
= TREE_TYPE (*vecp
);
12144 ret
= !lvalue_p (*vecp
);
12145 if (TREE_CODE (index
) == INTEGER_CST
)
12146 if (!tree_fits_uhwi_p (index
)
12147 || tree_to_uhwi (index
) >= TYPE_VECTOR_SUBPARTS (type
))
12148 warning_at (loc
, OPT_Warray_bounds
, "index value is out of bound");
12152 tree tmp
= create_tmp_var_raw (type
);
12153 DECL_SOURCE_LOCATION (tmp
) = loc
;
12154 *vecp
= c_save_expr (*vecp
);
12155 if (TREE_CODE (*vecp
) == C_MAYBE_CONST_EXPR
)
12157 bool non_const
= C_MAYBE_CONST_EXPR_NON_CONST (*vecp
);
12158 *vecp
= C_MAYBE_CONST_EXPR_EXPR (*vecp
);
12160 = c_wrap_maybe_const (build4 (TARGET_EXPR
, type
, tmp
,
12161 *vecp
, NULL_TREE
, NULL_TREE
),
12165 *vecp
= build4 (TARGET_EXPR
, type
, tmp
, *vecp
,
12166 NULL_TREE
, NULL_TREE
);
12167 SET_EXPR_LOCATION (*vecp
, loc
);
12168 c_common_mark_addressable_vec (tmp
);
12171 c_common_mark_addressable_vec (*vecp
);
12172 type
= build_qualified_type (TREE_TYPE (type
), TYPE_QUALS (type
));
12173 type1
= build_pointer_type (TREE_TYPE (*vecp
));
12174 bool ref_all
= TYPE_REF_CAN_ALIAS_ALL (type1
);
12176 && !DECL_P (*vecp
))
12178 /* If the original vector isn't declared may_alias and it
12179 isn't a bare vector look if the subscripting would
12180 alias the vector we subscript, and if not, force ref-all. */
12181 alias_set_type vecset
= get_alias_set (*vecp
);
12182 alias_set_type sset
= get_alias_set (type
);
12183 if (!alias_sets_must_conflict_p (sset
, vecset
)
12184 && !alias_set_subset_of (sset
, vecset
))
12187 type
= build_pointer_type_for_mode (type
, ptr_mode
, ref_all
);
12188 *vecp
= build1 (ADDR_EXPR
, type1
, *vecp
);
12189 *vecp
= convert (type
, *vecp
);
12194 /* Determine which of the operands, if any, is a scalar that needs to be
12195 converted to a vector, for the range of operations. */
12197 scalar_to_vector (location_t loc
, enum tree_code code
, tree op0
, tree op1
,
12200 tree type0
= TREE_TYPE (op0
);
12201 tree type1
= TREE_TYPE (op1
);
12202 bool integer_only_op
= false;
12203 enum stv_conv ret
= stv_firstarg
;
12205 gcc_assert (TREE_CODE (type0
) == VECTOR_TYPE
12206 || TREE_CODE (type1
) == VECTOR_TYPE
);
12209 /* Most GENERIC binary expressions require homogeneous arguments.
12210 LSHIFT_EXPR and RSHIFT_EXPR are exceptions and accept a first
12211 argument that is a vector and a second one that is a scalar, so
12212 we never return stv_secondarg for them. */
12215 if (TREE_CODE (type0
) == INTEGER_TYPE
12216 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
12218 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
12221 error_at (loc
, "conversion of scalar %qT to vector %qT "
12222 "involves truncation", type0
, type1
);
12226 return stv_firstarg
;
12233 integer_only_op
= true;
12234 /* ... fall through ... */
12236 case VEC_COND_EXPR
:
12241 case TRUNC_DIV_EXPR
:
12242 case CEIL_DIV_EXPR
:
12243 case FLOOR_DIV_EXPR
:
12244 case ROUND_DIV_EXPR
:
12245 case EXACT_DIV_EXPR
:
12246 case TRUNC_MOD_EXPR
:
12247 case FLOOR_MOD_EXPR
:
12255 /* What about UNLT_EXPR? */
12256 if (TREE_CODE (type0
) == VECTOR_TYPE
)
12259 ret
= stv_secondarg
;
12260 /* Swap TYPE0 with TYPE1 and OP0 with OP1 */
12261 tmp
= type0
; type0
= type1
; type1
= tmp
;
12262 tmp
= op0
; op0
= op1
; op1
= tmp
;
12265 if (TREE_CODE (type0
) == INTEGER_TYPE
12266 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
12268 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
12271 error_at (loc
, "conversion of scalar %qT to vector %qT "
12272 "involves truncation", type0
, type1
);
12277 else if (!integer_only_op
12278 /* Allow integer --> real conversion if safe. */
12279 && (TREE_CODE (type0
) == REAL_TYPE
12280 || TREE_CODE (type0
) == INTEGER_TYPE
)
12281 && SCALAR_FLOAT_TYPE_P (TREE_TYPE (type1
)))
12283 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
12286 error_at (loc
, "conversion of scalar %qT to vector %qT "
12287 "involves truncation", type0
, type1
);
12296 return stv_nothing
;
12299 /* Return true iff ALIGN is an integral constant that is a fundamental
12300 alignment, as defined by [basic.align] in the c++-11
12305 [A fundamental alignment is represented by an alignment less than or
12306 equal to the greatest alignment supported by the implementation
12307 in all contexts, which is equal to
12308 alignof(max_align_t)]. */
12311 cxx_fundamental_alignment_p (unsigned align
)
12313 return (align
<= MAX (TYPE_ALIGN (long_long_integer_type_node
),
12314 TYPE_ALIGN (long_double_type_node
)));
12317 /* Return true if T is a pointer to a zero-sized aggregate. */
12320 pointer_to_zero_sized_aggr_p (tree t
)
12322 if (!POINTER_TYPE_P (t
))
12325 return (TYPE_SIZE (t
) && integer_zerop (TYPE_SIZE (t
)));
12328 #include "gt-c-family-c-common.h"