1 /* Subroutines shared by all languages that are variants of C.
2 Copyright (C) 1992-2014 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
27 #include "fold-const.h"
28 #include "stor-layout.h"
30 #include "stringpool.h"
33 #include "trans-mem.h"
41 #include "common/common-target.h"
42 #include "langhooks.h"
43 #include "tree-inline.h"
45 #include "diagnostic.h"
46 #include "tree-iterator.h"
50 #include "target-def.h"
52 #include "wide-int-print.h"
54 cpp_reader
*parse_in
; /* Declared in c-pragma.h. */
56 /* The following symbols are subsumed in the c_global_trees array, and
57 listed here individually for documentation purposes.
59 INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
61 tree short_integer_type_node;
62 tree long_integer_type_node;
63 tree long_long_integer_type_node;
64 tree int128_integer_type_node;
66 tree short_unsigned_type_node;
67 tree long_unsigned_type_node;
68 tree long_long_unsigned_type_node;
69 tree int128_unsigned_type_node;
71 tree truthvalue_type_node;
72 tree truthvalue_false_node;
73 tree truthvalue_true_node;
75 tree ptrdiff_type_node;
77 tree unsigned_char_type_node;
78 tree signed_char_type_node;
81 tree char16_type_node;
82 tree char32_type_node;
85 tree double_type_node;
86 tree long_double_type_node;
88 tree complex_integer_type_node;
89 tree complex_float_type_node;
90 tree complex_double_type_node;
91 tree complex_long_double_type_node;
93 tree dfloat32_type_node;
94 tree dfloat64_type_node;
95 tree_dfloat128_type_node;
100 tree intDI_type_node;
101 tree intTI_type_node;
103 tree unsigned_intQI_type_node;
104 tree unsigned_intHI_type_node;
105 tree unsigned_intSI_type_node;
106 tree unsigned_intDI_type_node;
107 tree unsigned_intTI_type_node;
109 tree widest_integer_literal_type_node;
110 tree widest_unsigned_literal_type_node;
112 Nodes for types `void *' and `const void *'.
114 tree ptr_type_node, const_ptr_type_node;
116 Nodes for types `char *' and `const char *'.
118 tree string_type_node, const_string_type_node;
120 Type `char[SOMENUMBER]'.
121 Used when an array of char is needed and the size is irrelevant.
123 tree char_array_type_node;
125 Type `wchar_t[SOMENUMBER]' or something like it.
126 Used when a wide string literal is created.
128 tree wchar_array_type_node;
130 Type `char16_t[SOMENUMBER]' or something like it.
131 Used when a UTF-16 string literal is created.
133 tree char16_array_type_node;
135 Type `char32_t[SOMENUMBER]' or something like it.
136 Used when a UTF-32 string literal is created.
138 tree char32_array_type_node;
140 Type `int ()' -- used for implicit declaration of functions.
142 tree default_function_type;
144 A VOID_TYPE node, packaged in a TREE_LIST.
148 The lazily created VAR_DECLs for __FUNCTION__, __PRETTY_FUNCTION__,
149 and __func__. (C doesn't generate __FUNCTION__ and__PRETTY_FUNCTION__
150 VAR_DECLS, but C++ does.)
152 tree function_name_decl_node;
153 tree pretty_function_name_decl_node;
154 tree c99_function_name_decl_node;
156 Stack of nested function name VAR_DECLs.
158 tree saved_function_name_decls;
162 tree c_global_trees
[CTI_MAX
];
164 /* Switches common to the C front ends. */
166 /* Nonzero means don't output line number information. */
168 char flag_no_line_commands
;
170 /* Nonzero causes -E output not to be done, but directives such as
171 #define that have side effects are still obeyed. */
175 /* Nonzero means dump macros in some fashion. */
177 char flag_dump_macros
;
179 /* Nonzero means pass #include lines through to the output. */
181 char flag_dump_includes
;
183 /* Nonzero means process PCH files while preprocessing. */
185 bool flag_pch_preprocess
;
187 /* The file name to which we should write a precompiled header, or
188 NULL if no header will be written in this compile. */
190 const char *pch_file
;
192 /* Nonzero if an ISO standard was selected. It rejects macros in the
196 /* C/ObjC language option variables. */
199 /* Nonzero means allow type mismatches in conditional expressions;
200 just make their values `void'. */
202 int flag_cond_mismatch
;
204 /* Nonzero means enable C89 Amendment 1 features. */
208 /* Nonzero means use the ISO C99 (or C11) dialect of C. */
212 /* Nonzero means use the ISO C11 dialect of C. */
216 /* Nonzero means that we have builtin functions, and main is an int. */
221 /* ObjC language option variables. */
224 /* Tells the compiler that this is a special run. Do not perform any
225 compiling, instead we are to test some platform dependent features
226 and output a C header file with appropriate definitions. */
228 int print_struct_values
;
230 /* Tells the compiler what is the constant string class for ObjC. */
232 const char *constant_string_class_name
;
235 /* C++ language option variables. */
238 /* Nonzero means generate separate instantiation control files and
239 juggle them at link time. */
241 int flag_use_repository
;
243 /* The C++ dialect being used. C++98 is the default. */
245 enum cxx_dialect cxx_dialect
= cxx98
;
247 /* Maximum template instantiation depth. This limit exists to limit the
248 time it takes to notice excessively recursive template instantiations.
250 The default is lower than the 1024 recommended by the C++0x standard
251 because G++ runs out of stack before 1024 with highly recursive template
252 argument deduction substitution (g++.dg/cpp0x/enum11.C). */
254 int max_tinst_depth
= 900;
256 /* The elements of `ridpointers' are identifier nodes for the reserved
257 type names and storage classes. It is indexed by a RID_... value. */
260 tree (*make_fname_decl
) (location_t
, tree
, int);
262 /* Nonzero means don't warn about problems that occur when the code is
264 int c_inhibit_evaluation_warnings
;
266 /* Whether we are building a boolean conversion inside
267 convert_for_assignment, or some other late binary operation. If
268 build_binary_op is called for C (from code shared by C and C++) in
269 this case, then the operands have already been folded and the
270 result will not be folded again, so C_MAYBE_CONST_EXPR should not
272 bool in_late_binary_op
;
274 /* Whether lexing has been completed, so subsequent preprocessor
275 errors should use the compiler's input_location. */
276 bool done_lexing
= false;
278 /* Information about how a function name is generated. */
281 tree
*const decl
; /* pointer to the VAR_DECL. */
282 const unsigned rid
; /* RID number for the identifier. */
283 const int pretty
; /* How pretty is it? */
286 /* The three ways of getting then name of the current function. */
288 const struct fname_var_t fname_vars
[] =
290 /* C99 compliant __func__, must be first. */
291 {&c99_function_name_decl_node
, RID_C99_FUNCTION_NAME
, 0},
292 /* GCC __FUNCTION__ compliant. */
293 {&function_name_decl_node
, RID_FUNCTION_NAME
, 0},
294 /* GCC __PRETTY_FUNCTION__ compliant. */
295 {&pretty_function_name_decl_node
, RID_PRETTY_FUNCTION_NAME
, 1},
299 /* Global visibility options. */
300 struct visibility_flags visibility_options
;
302 static tree
c_fully_fold_internal (tree expr
, bool, bool *, bool *);
303 static tree
check_case_value (location_t
, tree
);
304 static bool check_case_bounds (location_t
, tree
, tree
, tree
*, tree
*);
306 static tree
handle_packed_attribute (tree
*, tree
, tree
, int, bool *);
307 static tree
handle_nocommon_attribute (tree
*, tree
, tree
, int, bool *);
308 static tree
handle_common_attribute (tree
*, tree
, tree
, int, bool *);
309 static tree
handle_noreturn_attribute (tree
*, tree
, tree
, int, bool *);
310 static tree
handle_hot_attribute (tree
*, tree
, tree
, int, bool *);
311 static tree
handle_cold_attribute (tree
*, tree
, tree
, int, bool *);
312 static tree
handle_no_sanitize_address_attribute (tree
*, tree
, tree
,
314 static tree
handle_no_address_safety_analysis_attribute (tree
*, tree
, tree
,
316 static tree
handle_no_sanitize_undefined_attribute (tree
*, tree
, tree
, int,
318 static tree
handle_noinline_attribute (tree
*, tree
, tree
, int, bool *);
319 static tree
handle_noclone_attribute (tree
*, tree
, tree
, int, bool *);
320 static tree
handle_leaf_attribute (tree
*, tree
, tree
, int, bool *);
321 static tree
handle_always_inline_attribute (tree
*, tree
, tree
, int,
323 static tree
handle_gnu_inline_attribute (tree
*, tree
, tree
, int, bool *);
324 static tree
handle_artificial_attribute (tree
*, tree
, tree
, int, bool *);
325 static tree
handle_flatten_attribute (tree
*, tree
, tree
, int, bool *);
326 static tree
handle_error_attribute (tree
*, tree
, tree
, int, bool *);
327 static tree
handle_used_attribute (tree
*, tree
, tree
, int, bool *);
328 static tree
handle_unused_attribute (tree
*, tree
, tree
, int, bool *);
329 static tree
handle_externally_visible_attribute (tree
*, tree
, tree
, int,
331 static tree
handle_no_reorder_attribute (tree
*, tree
, tree
, int,
333 static tree
handle_const_attribute (tree
*, tree
, tree
, int, bool *);
334 static tree
handle_transparent_union_attribute (tree
*, tree
, tree
,
336 static tree
handle_constructor_attribute (tree
*, tree
, tree
, int, bool *);
337 static tree
handle_destructor_attribute (tree
*, tree
, tree
, int, bool *);
338 static tree
handle_mode_attribute (tree
*, tree
, tree
, int, bool *);
339 static tree
handle_section_attribute (tree
*, tree
, tree
, int, bool *);
340 static tree
handle_aligned_attribute (tree
*, tree
, tree
, int, bool *);
341 static tree
handle_weak_attribute (tree
*, tree
, tree
, int, bool *) ;
342 static tree
handle_alias_ifunc_attribute (bool, tree
*, tree
, tree
, bool *);
343 static tree
handle_ifunc_attribute (tree
*, tree
, tree
, int, bool *);
344 static tree
handle_alias_attribute (tree
*, tree
, tree
, int, bool *);
345 static tree
handle_weakref_attribute (tree
*, tree
, tree
, int, bool *) ;
346 static tree
handle_visibility_attribute (tree
*, tree
, tree
, int,
348 static tree
handle_tls_model_attribute (tree
*, tree
, tree
, int,
350 static tree
handle_no_instrument_function_attribute (tree
*, tree
,
352 static tree
handle_malloc_attribute (tree
*, tree
, tree
, int, bool *);
353 static tree
handle_returns_twice_attribute (tree
*, tree
, tree
, int, bool *);
354 static tree
handle_no_limit_stack_attribute (tree
*, tree
, tree
, int,
356 static tree
handle_pure_attribute (tree
*, tree
, tree
, int, bool *);
357 static tree
handle_tm_attribute (tree
*, tree
, tree
, int, bool *);
358 static tree
handle_tm_wrap_attribute (tree
*, tree
, tree
, int, bool *);
359 static tree
handle_novops_attribute (tree
*, tree
, tree
, int, bool *);
360 static tree
handle_deprecated_attribute (tree
*, tree
, tree
, int,
362 static tree
handle_vector_size_attribute (tree
*, tree
, tree
, int,
364 static tree
handle_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
365 static tree
handle_nothrow_attribute (tree
*, tree
, tree
, int, bool *);
366 static tree
handle_cleanup_attribute (tree
*, tree
, tree
, int, bool *);
367 static tree
handle_warn_unused_result_attribute (tree
*, tree
, tree
, int,
369 static tree
handle_sentinel_attribute (tree
*, tree
, tree
, int, bool *);
370 static tree
handle_type_generic_attribute (tree
*, tree
, tree
, int, bool *);
371 static tree
handle_alloc_size_attribute (tree
*, tree
, tree
, int, bool *);
372 static tree
handle_alloc_align_attribute (tree
*, tree
, tree
, int, bool *);
373 static tree
handle_assume_aligned_attribute (tree
*, tree
, tree
, int, bool *);
374 static tree
handle_target_attribute (tree
*, tree
, tree
, int, bool *);
375 static tree
handle_optimize_attribute (tree
*, tree
, tree
, int, bool *);
376 static tree
ignore_attribute (tree
*, tree
, tree
, int, bool *);
377 static tree
handle_no_split_stack_attribute (tree
*, tree
, tree
, int, bool *);
378 static tree
handle_fnspec_attribute (tree
*, tree
, tree
, int, bool *);
379 static tree
handle_warn_unused_attribute (tree
*, tree
, tree
, int, bool *);
380 static tree
handle_returns_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
381 static tree
handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int,
383 static tree
handle_omp_declare_target_attribute (tree
*, tree
, tree
, int,
385 static tree
handle_designated_init_attribute (tree
*, tree
, tree
, int, bool *);
387 static void check_function_nonnull (tree
, int, tree
*);
388 static void check_nonnull_arg (void *, tree
, unsigned HOST_WIDE_INT
);
389 static bool nonnull_check_p (tree
, unsigned HOST_WIDE_INT
);
390 static bool get_nonnull_operand (tree
, unsigned HOST_WIDE_INT
*);
391 static int resort_field_decl_cmp (const void *, const void *);
393 /* Reserved words. The third field is a mask: keywords are disabled
394 if they match the mask.
397 C --std=c89: D_C99 | D_CXXONLY | D_OBJC | D_CXX_OBJC
398 C --std=c99: D_CXXONLY | D_OBJC
399 ObjC is like C except that D_OBJC and D_CXX_OBJC are not set
400 C++ --std=c98: D_CONLY | D_CXXOX | D_OBJC
401 C++ --std=c0x: D_CONLY | D_OBJC
402 ObjC++ is like C++ except that D_OBJC is not set
404 If -fno-asm is used, D_ASM is added to the mask. If
405 -fno-gnu-keywords is used, D_EXT is added. If -fno-asm and C in
406 C89 mode, D_EXT89 is added for both -fno-asm and -fno-gnu-keywords.
407 In C with -Wc++-compat, we warn if D_CXXWARN is set.
409 Note the complication of the D_CXX_OBJC keywords. These are
410 reserved words such as 'class'. In C++, 'class' is a reserved
411 word. In Objective-C++ it is too. In Objective-C, it is a
412 reserved word too, but only if it follows an '@' sign.
414 const struct c_common_resword c_common_reswords
[] =
416 { "_Alignas", RID_ALIGNAS
, D_CONLY
},
417 { "_Alignof", RID_ALIGNOF
, D_CONLY
},
418 { "_Atomic", RID_ATOMIC
, D_CONLY
},
419 { "_Bool", RID_BOOL
, D_CONLY
},
420 { "_Complex", RID_COMPLEX
, 0 },
421 { "_Cilk_spawn", RID_CILK_SPAWN
, 0 },
422 { "_Cilk_sync", RID_CILK_SYNC
, 0 },
423 { "_Cilk_for", RID_CILK_FOR
, 0 },
424 { "_Imaginary", RID_IMAGINARY
, D_CONLY
},
425 { "_Decimal32", RID_DFLOAT32
, D_CONLY
| D_EXT
},
426 { "_Decimal64", RID_DFLOAT64
, D_CONLY
| D_EXT
},
427 { "_Decimal128", RID_DFLOAT128
, D_CONLY
| D_EXT
},
428 { "_Fract", RID_FRACT
, D_CONLY
| D_EXT
},
429 { "_Accum", RID_ACCUM
, D_CONLY
| D_EXT
},
430 { "_Sat", RID_SAT
, D_CONLY
| D_EXT
},
431 { "_Static_assert", RID_STATIC_ASSERT
, D_CONLY
},
432 { "_Noreturn", RID_NORETURN
, D_CONLY
},
433 { "_Generic", RID_GENERIC
, D_CONLY
},
434 { "_Thread_local", RID_THREAD
, D_CONLY
},
435 { "__FUNCTION__", RID_FUNCTION_NAME
, 0 },
436 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME
, 0 },
437 { "__alignof", RID_ALIGNOF
, 0 },
438 { "__alignof__", RID_ALIGNOF
, 0 },
439 { "__asm", RID_ASM
, 0 },
440 { "__asm__", RID_ASM
, 0 },
441 { "__attribute", RID_ATTRIBUTE
, 0 },
442 { "__attribute__", RID_ATTRIBUTE
, 0 },
443 { "__auto_type", RID_AUTO_TYPE
, D_CONLY
},
444 { "__bases", RID_BASES
, D_CXXONLY
},
445 { "__builtin_choose_expr", RID_CHOOSE_EXPR
, D_CONLY
},
446 { "__builtin_complex", RID_BUILTIN_COMPLEX
, D_CONLY
},
447 { "__builtin_shuffle", RID_BUILTIN_SHUFFLE
, 0 },
448 { "__builtin_offsetof", RID_OFFSETOF
, 0 },
449 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P
, D_CONLY
},
450 { "__builtin_va_arg", RID_VA_ARG
, 0 },
451 { "__complex", RID_COMPLEX
, 0 },
452 { "__complex__", RID_COMPLEX
, 0 },
453 { "__const", RID_CONST
, 0 },
454 { "__const__", RID_CONST
, 0 },
455 { "__decltype", RID_DECLTYPE
, D_CXXONLY
},
456 { "__direct_bases", RID_DIRECT_BASES
, D_CXXONLY
},
457 { "__extension__", RID_EXTENSION
, 0 },
458 { "__func__", RID_C99_FUNCTION_NAME
, 0 },
459 { "__has_nothrow_assign", RID_HAS_NOTHROW_ASSIGN
, D_CXXONLY
},
460 { "__has_nothrow_constructor", RID_HAS_NOTHROW_CONSTRUCTOR
, D_CXXONLY
},
461 { "__has_nothrow_copy", RID_HAS_NOTHROW_COPY
, D_CXXONLY
},
462 { "__has_trivial_assign", RID_HAS_TRIVIAL_ASSIGN
, D_CXXONLY
},
463 { "__has_trivial_constructor", RID_HAS_TRIVIAL_CONSTRUCTOR
, D_CXXONLY
},
464 { "__has_trivial_copy", RID_HAS_TRIVIAL_COPY
, D_CXXONLY
},
465 { "__has_trivial_destructor", RID_HAS_TRIVIAL_DESTRUCTOR
, D_CXXONLY
},
466 { "__has_virtual_destructor", RID_HAS_VIRTUAL_DESTRUCTOR
, D_CXXONLY
},
467 { "__imag", RID_IMAGPART
, 0 },
468 { "__imag__", RID_IMAGPART
, 0 },
469 { "__inline", RID_INLINE
, 0 },
470 { "__inline__", RID_INLINE
, 0 },
471 { "__int128", RID_INT128
, 0 },
472 { "__is_abstract", RID_IS_ABSTRACT
, D_CXXONLY
},
473 { "__is_base_of", RID_IS_BASE_OF
, D_CXXONLY
},
474 { "__is_class", RID_IS_CLASS
, D_CXXONLY
},
475 { "__is_empty", RID_IS_EMPTY
, D_CXXONLY
},
476 { "__is_enum", RID_IS_ENUM
, D_CXXONLY
},
477 { "__is_final", RID_IS_FINAL
, D_CXXONLY
},
478 { "__is_literal_type", RID_IS_LITERAL_TYPE
, D_CXXONLY
},
479 { "__is_pod", RID_IS_POD
, D_CXXONLY
},
480 { "__is_polymorphic", RID_IS_POLYMORPHIC
, D_CXXONLY
},
481 { "__is_standard_layout", RID_IS_STD_LAYOUT
, D_CXXONLY
},
482 { "__is_trivial", RID_IS_TRIVIAL
, D_CXXONLY
},
483 { "__is_trivially_assignable", RID_IS_TRIVIALLY_ASSIGNABLE
, D_CXXONLY
},
484 { "__is_trivially_constructible", RID_IS_TRIVIALLY_CONSTRUCTIBLE
, D_CXXONLY
},
485 { "__is_trivially_copyable", RID_IS_TRIVIALLY_COPYABLE
, D_CXXONLY
},
486 { "__is_union", RID_IS_UNION
, D_CXXONLY
},
487 { "__label__", RID_LABEL
, 0 },
488 { "__null", RID_NULL
, 0 },
489 { "__real", RID_REALPART
, 0 },
490 { "__real__", RID_REALPART
, 0 },
491 { "__restrict", RID_RESTRICT
, 0 },
492 { "__restrict__", RID_RESTRICT
, 0 },
493 { "__signed", RID_SIGNED
, 0 },
494 { "__signed__", RID_SIGNED
, 0 },
495 { "__thread", RID_THREAD
, 0 },
496 { "__transaction_atomic", RID_TRANSACTION_ATOMIC
, 0 },
497 { "__transaction_relaxed", RID_TRANSACTION_RELAXED
, 0 },
498 { "__transaction_cancel", RID_TRANSACTION_CANCEL
, 0 },
499 { "__typeof", RID_TYPEOF
, 0 },
500 { "__typeof__", RID_TYPEOF
, 0 },
501 { "__underlying_type", RID_UNDERLYING_TYPE
, D_CXXONLY
},
502 { "__volatile", RID_VOLATILE
, 0 },
503 { "__volatile__", RID_VOLATILE
, 0 },
504 { "alignas", RID_ALIGNAS
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
505 { "alignof", RID_ALIGNOF
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
506 { "asm", RID_ASM
, D_ASM
},
507 { "auto", RID_AUTO
, 0 },
508 { "bool", RID_BOOL
, D_CXXONLY
| D_CXXWARN
},
509 { "break", RID_BREAK
, 0 },
510 { "case", RID_CASE
, 0 },
511 { "catch", RID_CATCH
, D_CXX_OBJC
| D_CXXWARN
},
512 { "char", RID_CHAR
, 0 },
513 { "char16_t", RID_CHAR16
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
514 { "char32_t", RID_CHAR32
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
515 { "class", RID_CLASS
, D_CXX_OBJC
| D_CXXWARN
},
516 { "const", RID_CONST
, 0 },
517 { "constexpr", RID_CONSTEXPR
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
518 { "const_cast", RID_CONSTCAST
, D_CXXONLY
| D_CXXWARN
},
519 { "continue", RID_CONTINUE
, 0 },
520 { "decltype", RID_DECLTYPE
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
521 { "default", RID_DEFAULT
, 0 },
522 { "delete", RID_DELETE
, D_CXXONLY
| D_CXXWARN
},
524 { "double", RID_DOUBLE
, 0 },
525 { "dynamic_cast", RID_DYNCAST
, D_CXXONLY
| D_CXXWARN
},
526 { "else", RID_ELSE
, 0 },
527 { "enum", RID_ENUM
, 0 },
528 { "explicit", RID_EXPLICIT
, D_CXXONLY
| D_CXXWARN
},
529 { "export", RID_EXPORT
, D_CXXONLY
| D_CXXWARN
},
530 { "extern", RID_EXTERN
, 0 },
531 { "false", RID_FALSE
, D_CXXONLY
| D_CXXWARN
},
532 { "float", RID_FLOAT
, 0 },
533 { "for", RID_FOR
, 0 },
534 { "friend", RID_FRIEND
, D_CXXONLY
| D_CXXWARN
},
535 { "goto", RID_GOTO
, 0 },
537 { "inline", RID_INLINE
, D_EXT89
},
538 { "int", RID_INT
, 0 },
539 { "long", RID_LONG
, 0 },
540 { "mutable", RID_MUTABLE
, D_CXXONLY
| D_CXXWARN
},
541 { "namespace", RID_NAMESPACE
, D_CXXONLY
| D_CXXWARN
},
542 { "new", RID_NEW
, D_CXXONLY
| D_CXXWARN
},
543 { "noexcept", RID_NOEXCEPT
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
544 { "nullptr", RID_NULLPTR
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
545 { "operator", RID_OPERATOR
, D_CXXONLY
| D_CXXWARN
},
546 { "private", RID_PRIVATE
, D_CXX_OBJC
| D_CXXWARN
},
547 { "protected", RID_PROTECTED
, D_CXX_OBJC
| D_CXXWARN
},
548 { "public", RID_PUBLIC
, D_CXX_OBJC
| D_CXXWARN
},
549 { "register", RID_REGISTER
, 0 },
550 { "reinterpret_cast", RID_REINTCAST
, D_CXXONLY
| D_CXXWARN
},
551 { "restrict", RID_RESTRICT
, D_CONLY
| D_C99
},
552 { "return", RID_RETURN
, 0 },
553 { "short", RID_SHORT
, 0 },
554 { "signed", RID_SIGNED
, 0 },
555 { "sizeof", RID_SIZEOF
, 0 },
556 { "static", RID_STATIC
, 0 },
557 { "static_assert", RID_STATIC_ASSERT
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
558 { "static_cast", RID_STATCAST
, D_CXXONLY
| D_CXXWARN
},
559 { "struct", RID_STRUCT
, 0 },
560 { "switch", RID_SWITCH
, 0 },
561 { "template", RID_TEMPLATE
, D_CXXONLY
| D_CXXWARN
},
562 { "this", RID_THIS
, D_CXXONLY
| D_CXXWARN
},
563 { "thread_local", RID_THREAD
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
564 { "throw", RID_THROW
, D_CXX_OBJC
| D_CXXWARN
},
565 { "true", RID_TRUE
, D_CXXONLY
| D_CXXWARN
},
566 { "try", RID_TRY
, D_CXX_OBJC
| D_CXXWARN
},
567 { "typedef", RID_TYPEDEF
, 0 },
568 { "typename", RID_TYPENAME
, D_CXXONLY
| D_CXXWARN
},
569 { "typeid", RID_TYPEID
, D_CXXONLY
| D_CXXWARN
},
570 { "typeof", RID_TYPEOF
, D_ASM
| D_EXT
},
571 { "union", RID_UNION
, 0 },
572 { "unsigned", RID_UNSIGNED
, 0 },
573 { "using", RID_USING
, D_CXXONLY
| D_CXXWARN
},
574 { "virtual", RID_VIRTUAL
, D_CXXONLY
| D_CXXWARN
},
575 { "void", RID_VOID
, 0 },
576 { "volatile", RID_VOLATILE
, 0 },
577 { "wchar_t", RID_WCHAR
, D_CXXONLY
},
578 { "while", RID_WHILE
, 0 },
579 /* These Objective-C keywords are recognized only immediately after
581 { "compatibility_alias", RID_AT_ALIAS
, D_OBJC
},
582 { "defs", RID_AT_DEFS
, D_OBJC
},
583 { "encode", RID_AT_ENCODE
, D_OBJC
},
584 { "end", RID_AT_END
, D_OBJC
},
585 { "implementation", RID_AT_IMPLEMENTATION
, D_OBJC
},
586 { "interface", RID_AT_INTERFACE
, D_OBJC
},
587 { "protocol", RID_AT_PROTOCOL
, D_OBJC
},
588 { "selector", RID_AT_SELECTOR
, D_OBJC
},
589 { "finally", RID_AT_FINALLY
, D_OBJC
},
590 { "synchronized", RID_AT_SYNCHRONIZED
, D_OBJC
},
591 { "optional", RID_AT_OPTIONAL
, D_OBJC
},
592 { "required", RID_AT_REQUIRED
, D_OBJC
},
593 { "property", RID_AT_PROPERTY
, D_OBJC
},
594 { "package", RID_AT_PACKAGE
, D_OBJC
},
595 { "synthesize", RID_AT_SYNTHESIZE
, D_OBJC
},
596 { "dynamic", RID_AT_DYNAMIC
, D_OBJC
},
597 /* These are recognized only in protocol-qualifier context
599 { "bycopy", RID_BYCOPY
, D_OBJC
},
600 { "byref", RID_BYREF
, D_OBJC
},
601 { "in", RID_IN
, D_OBJC
},
602 { "inout", RID_INOUT
, D_OBJC
},
603 { "oneway", RID_ONEWAY
, D_OBJC
},
604 { "out", RID_OUT
, D_OBJC
},
605 /* These are recognized inside a property attribute list */
606 { "assign", RID_ASSIGN
, D_OBJC
},
607 { "copy", RID_COPY
, D_OBJC
},
608 { "getter", RID_GETTER
, D_OBJC
},
609 { "nonatomic", RID_NONATOMIC
, D_OBJC
},
610 { "readonly", RID_READONLY
, D_OBJC
},
611 { "readwrite", RID_READWRITE
, D_OBJC
},
612 { "retain", RID_RETAIN
, D_OBJC
},
613 { "setter", RID_SETTER
, D_OBJC
},
616 const unsigned int num_c_common_reswords
=
617 sizeof c_common_reswords
/ sizeof (struct c_common_resword
);
619 /* Table of machine-independent attributes common to all C-like languages. */
620 const struct attribute_spec c_common_attribute_table
[] =
622 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
623 affects_type_identity } */
624 { "packed", 0, 0, false, false, false,
625 handle_packed_attribute
, false},
626 { "nocommon", 0, 0, true, false, false,
627 handle_nocommon_attribute
, false},
628 { "common", 0, 0, true, false, false,
629 handle_common_attribute
, false },
630 /* FIXME: logically, noreturn attributes should be listed as
631 "false, true, true" and apply to function types. But implementing this
632 would require all the places in the compiler that use TREE_THIS_VOLATILE
633 on a decl to identify non-returning functions to be located and fixed
634 to check the function type instead. */
635 { "noreturn", 0, 0, true, false, false,
636 handle_noreturn_attribute
, false },
637 { "volatile", 0, 0, true, false, false,
638 handle_noreturn_attribute
, false },
639 { "noinline", 0, 0, true, false, false,
640 handle_noinline_attribute
, false },
641 { "noclone", 0, 0, true, false, false,
642 handle_noclone_attribute
, false },
643 { "leaf", 0, 0, true, false, false,
644 handle_leaf_attribute
, false },
645 { "always_inline", 0, 0, true, false, false,
646 handle_always_inline_attribute
, false },
647 { "gnu_inline", 0, 0, true, false, false,
648 handle_gnu_inline_attribute
, false },
649 { "artificial", 0, 0, true, false, false,
650 handle_artificial_attribute
, false },
651 { "flatten", 0, 0, true, false, false,
652 handle_flatten_attribute
, false },
653 { "used", 0, 0, true, false, false,
654 handle_used_attribute
, false },
655 { "unused", 0, 0, false, false, false,
656 handle_unused_attribute
, false },
657 { "externally_visible", 0, 0, true, false, false,
658 handle_externally_visible_attribute
, false },
659 { "no_reorder", 0, 0, true, false, false,
660 handle_no_reorder_attribute
, false },
661 /* The same comments as for noreturn attributes apply to const ones. */
662 { "const", 0, 0, true, false, false,
663 handle_const_attribute
, false },
664 { "transparent_union", 0, 0, false, false, false,
665 handle_transparent_union_attribute
, false },
666 { "constructor", 0, 1, true, false, false,
667 handle_constructor_attribute
, false },
668 { "destructor", 0, 1, true, false, false,
669 handle_destructor_attribute
, false },
670 { "mode", 1, 1, false, true, false,
671 handle_mode_attribute
, false },
672 { "section", 1, 1, true, false, false,
673 handle_section_attribute
, false },
674 { "aligned", 0, 1, false, false, false,
675 handle_aligned_attribute
, false },
676 { "weak", 0, 0, true, false, false,
677 handle_weak_attribute
, false },
678 { "ifunc", 1, 1, true, false, false,
679 handle_ifunc_attribute
, false },
680 { "alias", 1, 1, true, false, false,
681 handle_alias_attribute
, false },
682 { "weakref", 0, 1, true, false, false,
683 handle_weakref_attribute
, false },
684 { "no_instrument_function", 0, 0, true, false, false,
685 handle_no_instrument_function_attribute
,
687 { "malloc", 0, 0, true, false, false,
688 handle_malloc_attribute
, false },
689 { "returns_twice", 0, 0, true, false, false,
690 handle_returns_twice_attribute
, false },
691 { "no_stack_limit", 0, 0, true, false, false,
692 handle_no_limit_stack_attribute
, false },
693 { "pure", 0, 0, true, false, false,
694 handle_pure_attribute
, false },
695 { "transaction_callable", 0, 0, false, true, false,
696 handle_tm_attribute
, false },
697 { "transaction_unsafe", 0, 0, false, true, false,
698 handle_tm_attribute
, false },
699 { "transaction_safe", 0, 0, false, true, false,
700 handle_tm_attribute
, false },
701 { "transaction_may_cancel_outer", 0, 0, false, true, false,
702 handle_tm_attribute
, false },
703 /* ??? These two attributes didn't make the transition from the
704 Intel language document to the multi-vendor language document. */
705 { "transaction_pure", 0, 0, false, true, false,
706 handle_tm_attribute
, false },
707 { "transaction_wrap", 1, 1, true, false, false,
708 handle_tm_wrap_attribute
, false },
709 /* For internal use (marking of builtins) only. The name contains space
710 to prevent its usage in source code. */
711 { "no vops", 0, 0, true, false, false,
712 handle_novops_attribute
, false },
713 { "deprecated", 0, 1, false, false, false,
714 handle_deprecated_attribute
, false },
715 { "vector_size", 1, 1, false, true, false,
716 handle_vector_size_attribute
, false },
717 { "visibility", 1, 1, false, false, false,
718 handle_visibility_attribute
, false },
719 { "tls_model", 1, 1, true, false, false,
720 handle_tls_model_attribute
, false },
721 { "nonnull", 0, -1, false, true, true,
722 handle_nonnull_attribute
, false },
723 { "nothrow", 0, 0, true, false, false,
724 handle_nothrow_attribute
, false },
725 { "may_alias", 0, 0, false, true, false, NULL
, false },
726 { "cleanup", 1, 1, true, false, false,
727 handle_cleanup_attribute
, false },
728 { "warn_unused_result", 0, 0, false, true, true,
729 handle_warn_unused_result_attribute
, false },
730 { "sentinel", 0, 1, false, true, true,
731 handle_sentinel_attribute
, false },
732 /* For internal use (marking of builtins) only. The name contains space
733 to prevent its usage in source code. */
734 { "type generic", 0, 0, false, true, true,
735 handle_type_generic_attribute
, false },
736 { "alloc_size", 1, 2, false, true, true,
737 handle_alloc_size_attribute
, false },
738 { "cold", 0, 0, true, false, false,
739 handle_cold_attribute
, false },
740 { "hot", 0, 0, true, false, false,
741 handle_hot_attribute
, false },
742 { "no_address_safety_analysis",
743 0, 0, true, false, false,
744 handle_no_address_safety_analysis_attribute
,
746 { "no_sanitize_address", 0, 0, true, false, false,
747 handle_no_sanitize_address_attribute
,
749 { "no_sanitize_undefined", 0, 0, true, false, false,
750 handle_no_sanitize_undefined_attribute
,
752 { "warning", 1, 1, true, false, false,
753 handle_error_attribute
, false },
754 { "error", 1, 1, true, false, false,
755 handle_error_attribute
, false },
756 { "target", 1, -1, true, false, false,
757 handle_target_attribute
, false },
758 { "optimize", 1, -1, true, false, false,
759 handle_optimize_attribute
, false },
760 /* For internal use only. The leading '*' both prevents its usage in
761 source code and signals that it may be overridden by machine tables. */
762 { "*tm regparm", 0, 0, false, true, true,
763 ignore_attribute
, false },
764 { "no_split_stack", 0, 0, true, false, false,
765 handle_no_split_stack_attribute
, false },
766 /* For internal use (marking of builtins and runtime functions) only.
767 The name contains space to prevent its usage in source code. */
768 { "fn spec", 1, 1, false, true, true,
769 handle_fnspec_attribute
, false },
770 { "warn_unused", 0, 0, false, false, false,
771 handle_warn_unused_attribute
, false },
772 { "returns_nonnull", 0, 0, false, true, true,
773 handle_returns_nonnull_attribute
, false },
774 { "omp declare simd", 0, -1, true, false, false,
775 handle_omp_declare_simd_attribute
, false },
776 { "cilk simd function", 0, -1, true, false, false,
777 handle_omp_declare_simd_attribute
, false },
778 { "omp declare target", 0, 0, true, false, false,
779 handle_omp_declare_target_attribute
, false },
780 { "alloc_align", 1, 1, false, true, true,
781 handle_alloc_align_attribute
, false },
782 { "assume_aligned", 1, 2, false, true, true,
783 handle_assume_aligned_attribute
, false },
784 { "designated_init", 0, 0, false, true, false,
785 handle_designated_init_attribute
, false },
786 { NULL
, 0, 0, false, false, false, NULL
, false }
789 /* Give the specifications for the format attributes, used by C and all
792 const struct attribute_spec c_common_format_attribute_table
[] =
794 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
795 affects_type_identity } */
796 { "format", 3, 3, false, true, true,
797 handle_format_attribute
, false },
798 { "format_arg", 1, 1, false, true, true,
799 handle_format_arg_attribute
, false },
800 { NULL
, 0, 0, false, false, false, NULL
, false }
803 /* Return identifier for address space AS. */
806 c_addr_space_name (addr_space_t as
)
808 int rid
= RID_FIRST_ADDR_SPACE
+ as
;
809 gcc_assert (ridpointers
[rid
]);
810 return IDENTIFIER_POINTER (ridpointers
[rid
]);
813 /* Push current bindings for the function name VAR_DECLS. */
816 start_fname_decls (void)
819 tree saved
= NULL_TREE
;
821 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
823 tree decl
= *fname_vars
[ix
].decl
;
827 saved
= tree_cons (decl
, build_int_cst (integer_type_node
, ix
),
829 *fname_vars
[ix
].decl
= NULL_TREE
;
832 if (saved
|| saved_function_name_decls
)
833 /* Normally they'll have been NULL, so only push if we've got a
834 stack, or they are non-NULL. */
835 saved_function_name_decls
= tree_cons (saved
, NULL_TREE
,
836 saved_function_name_decls
);
839 /* Finish up the current bindings, adding them into the current function's
840 statement tree. This must be done _before_ finish_stmt_tree is called.
841 If there is no current function, we must be at file scope and no statements
842 are involved. Pop the previous bindings. */
845 finish_fname_decls (void)
848 tree stmts
= NULL_TREE
;
849 tree stack
= saved_function_name_decls
;
851 for (; stack
&& TREE_VALUE (stack
); stack
= TREE_CHAIN (stack
))
852 append_to_statement_list (TREE_VALUE (stack
), &stmts
);
856 tree
*bodyp
= &DECL_SAVED_TREE (current_function_decl
);
858 if (TREE_CODE (*bodyp
) == BIND_EXPR
)
859 bodyp
= &BIND_EXPR_BODY (*bodyp
);
861 append_to_statement_list_force (*bodyp
, &stmts
);
865 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
866 *fname_vars
[ix
].decl
= NULL_TREE
;
870 /* We had saved values, restore them. */
873 for (saved
= TREE_PURPOSE (stack
); saved
; saved
= TREE_CHAIN (saved
))
875 tree decl
= TREE_PURPOSE (saved
);
876 unsigned ix
= TREE_INT_CST_LOW (TREE_VALUE (saved
));
878 *fname_vars
[ix
].decl
= decl
;
880 stack
= TREE_CHAIN (stack
);
882 saved_function_name_decls
= stack
;
885 /* Return the text name of the current function, suitably prettified
886 by PRETTY_P. Return string must be freed by caller. */
889 fname_as_string (int pretty_p
)
891 const char *name
= "top level";
894 cpp_string cstr
= { 0, 0 }, strname
;
902 if (current_function_decl
)
903 name
= lang_hooks
.decl_printable_name (current_function_decl
, vrb
);
905 len
= strlen (name
) + 3; /* Two for '"'s. One for NULL. */
907 namep
= XNEWVEC (char, len
);
908 snprintf (namep
, len
, "\"%s\"", name
);
909 strname
.text
= (unsigned char *) namep
;
910 strname
.len
= len
- 1;
912 if (cpp_interpret_string (parse_in
, &strname
, 1, &cstr
, CPP_STRING
))
915 return (const char *) cstr
.text
;
921 /* Return the VAR_DECL for a const char array naming the current
922 function. If the VAR_DECL has not yet been created, create it
923 now. RID indicates how it should be formatted and IDENTIFIER_NODE
924 ID is its name (unfortunately C and C++ hold the RID values of
925 keywords in different places, so we can't derive RID from ID in
926 this language independent code. LOC is the location of the
930 fname_decl (location_t loc
, unsigned int rid
, tree id
)
933 tree decl
= NULL_TREE
;
935 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
936 if (fname_vars
[ix
].rid
== rid
)
939 decl
= *fname_vars
[ix
].decl
;
942 /* If a tree is built here, it would normally have the lineno of
943 the current statement. Later this tree will be moved to the
944 beginning of the function and this line number will be wrong.
945 To avoid this problem set the lineno to 0 here; that prevents
946 it from appearing in the RTL. */
948 location_t saved_location
= input_location
;
949 input_location
= UNKNOWN_LOCATION
;
951 stmts
= push_stmt_list ();
952 decl
= (*make_fname_decl
) (loc
, id
, fname_vars
[ix
].pretty
);
953 stmts
= pop_stmt_list (stmts
);
954 if (!IS_EMPTY_STMT (stmts
))
955 saved_function_name_decls
956 = tree_cons (decl
, stmts
, saved_function_name_decls
);
957 *fname_vars
[ix
].decl
= decl
;
958 input_location
= saved_location
;
960 if (!ix
&& !current_function_decl
)
961 pedwarn (loc
, 0, "%qD is not defined outside of function scope", decl
);
966 /* Given a STRING_CST, give it a suitable array-of-chars data type. */
969 fix_string_type (tree value
)
971 int length
= TREE_STRING_LENGTH (value
);
973 tree e_type
, i_type
, a_type
;
975 /* Compute the number of elements, for the array type. */
976 if (TREE_TYPE (value
) == char_array_type_node
|| !TREE_TYPE (value
))
979 e_type
= char_type_node
;
981 else if (TREE_TYPE (value
) == char16_array_type_node
)
983 nchars
= length
/ (TYPE_PRECISION (char16_type_node
) / BITS_PER_UNIT
);
984 e_type
= char16_type_node
;
986 else if (TREE_TYPE (value
) == char32_array_type_node
)
988 nchars
= length
/ (TYPE_PRECISION (char32_type_node
) / BITS_PER_UNIT
);
989 e_type
= char32_type_node
;
993 nchars
= length
/ (TYPE_PRECISION (wchar_type_node
) / BITS_PER_UNIT
);
994 e_type
= wchar_type_node
;
997 /* C89 2.2.4.1, C99 5.2.4.1 (Translation limits). The analogous
998 limit in C++98 Annex B is very large (65536) and is not normative,
999 so we do not diagnose it (warn_overlength_strings is forced off
1000 in c_common_post_options). */
1001 if (warn_overlength_strings
)
1003 const int nchars_max
= flag_isoc99
? 4095 : 509;
1004 const int relevant_std
= flag_isoc99
? 99 : 90;
1005 if (nchars
- 1 > nchars_max
)
1006 /* Translators: The %d after 'ISO C' will be 90 or 99. Do not
1007 separate the %d from the 'C'. 'ISO' should not be
1008 translated, but it may be moved after 'C%d' in languages
1009 where modifiers follow nouns. */
1010 pedwarn (input_location
, OPT_Woverlength_strings
,
1011 "string length %qd is greater than the length %qd "
1012 "ISO C%d compilers are required to support",
1013 nchars
- 1, nchars_max
, relevant_std
);
1016 /* Create the array type for the string constant. The ISO C++
1017 standard says that a string literal has type `const char[N]' or
1018 `const wchar_t[N]'. We use the same logic when invoked as a C
1019 front-end with -Wwrite-strings.
1020 ??? We should change the type of an expression depending on the
1021 state of a warning flag. We should just be warning -- see how
1022 this is handled in the C++ front-end for the deprecated implicit
1023 conversion from string literals to `char*' or `wchar_t*'.
1025 The C++ front end relies on TYPE_MAIN_VARIANT of a cv-qualified
1026 array type being the unqualified version of that type.
1027 Therefore, if we are constructing an array of const char, we must
1028 construct the matching unqualified array type first. The C front
1029 end does not require this, but it does no harm, so we do it
1031 i_type
= build_index_type (size_int (nchars
- 1));
1032 a_type
= build_array_type (e_type
, i_type
);
1033 if (c_dialect_cxx() || warn_write_strings
)
1034 a_type
= c_build_qualified_type (a_type
, TYPE_QUAL_CONST
);
1036 TREE_TYPE (value
) = a_type
;
1037 TREE_CONSTANT (value
) = 1;
1038 TREE_READONLY (value
) = 1;
1039 TREE_STATIC (value
) = 1;
1043 /* If DISABLE is true, stop issuing warnings. This is used when
1044 parsing code that we know will not be executed. This function may
1045 be called multiple times, and works as a stack. */
1048 c_disable_warnings (bool disable
)
1052 ++c_inhibit_evaluation_warnings
;
1053 fold_defer_overflow_warnings ();
1057 /* If ENABLE is true, reenable issuing warnings. */
1060 c_enable_warnings (bool enable
)
1064 --c_inhibit_evaluation_warnings
;
1065 fold_undefer_and_ignore_overflow_warnings ();
1069 /* Fully fold EXPR, an expression that was not folded (beyond integer
1070 constant expressions and null pointer constants) when being built
1071 up. If IN_INIT, this is in a static initializer and certain
1072 changes are made to the folding done. Clear *MAYBE_CONST if
1073 MAYBE_CONST is not NULL and EXPR is definitely not a constant
1074 expression because it contains an evaluated operator (in C99) or an
1075 operator outside of sizeof returning an integer constant (in C90)
1076 not permitted in constant expressions, or because it contains an
1077 evaluated arithmetic overflow. (*MAYBE_CONST should typically be
1078 set to true by callers before calling this function.) Return the
1079 folded expression. Function arguments have already been folded
1080 before calling this function, as have the contents of SAVE_EXPR,
1081 TARGET_EXPR, BIND_EXPR, VA_ARG_EXPR, OBJ_TYPE_REF and
1082 C_MAYBE_CONST_EXPR. */
1085 c_fully_fold (tree expr
, bool in_init
, bool *maybe_const
)
1088 tree eptype
= NULL_TREE
;
1090 bool maybe_const_itself
= true;
1091 location_t loc
= EXPR_LOCATION (expr
);
1093 /* This function is not relevant to C++ because C++ folds while
1094 parsing, and may need changes to be correct for C++ when C++
1095 stops folding while parsing. */
1096 if (c_dialect_cxx ())
1100 maybe_const
= &dummy
;
1101 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
1103 eptype
= TREE_TYPE (expr
);
1104 expr
= TREE_OPERAND (expr
, 0);
1106 ret
= c_fully_fold_internal (expr
, in_init
, maybe_const
,
1107 &maybe_const_itself
);
1109 ret
= fold_convert_loc (loc
, eptype
, ret
);
1110 *maybe_const
&= maybe_const_itself
;
1114 /* Internal helper for c_fully_fold. EXPR and IN_INIT are as for
1115 c_fully_fold. *MAYBE_CONST_OPERANDS is cleared because of operands
1116 not permitted, while *MAYBE_CONST_ITSELF is cleared because of
1117 arithmetic overflow (for C90, *MAYBE_CONST_OPERANDS is carried from
1118 both evaluated and unevaluated subexpressions while
1119 *MAYBE_CONST_ITSELF is carried from only evaluated
1123 c_fully_fold_internal (tree expr
, bool in_init
, bool *maybe_const_operands
,
1124 bool *maybe_const_itself
)
1127 enum tree_code code
= TREE_CODE (expr
);
1128 enum tree_code_class kind
= TREE_CODE_CLASS (code
);
1129 location_t loc
= EXPR_LOCATION (expr
);
1130 tree op0
, op1
, op2
, op3
;
1131 tree orig_op0
, orig_op1
, orig_op2
;
1132 bool op0_const
= true, op1_const
= true, op2_const
= true;
1133 bool op0_const_self
= true, op1_const_self
= true, op2_const_self
= true;
1134 bool nowarning
= TREE_NO_WARNING (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 ())
1143 /* Constants, declarations, statements, errors, SAVE_EXPRs and
1144 anything else not counted as an expression cannot usefully be
1145 folded further at this point. */
1146 if (!IS_EXPR_CODE_CLASS (kind
)
1147 || kind
== tcc_statement
1148 || code
== SAVE_EXPR
)
1151 /* Operands of variable-length expressions (function calls) have
1152 already been folded, as have __builtin_* function calls, and such
1153 expressions cannot occur in constant expressions. */
1154 if (kind
== tcc_vl_exp
)
1156 *maybe_const_operands
= false;
1161 if (code
== C_MAYBE_CONST_EXPR
)
1163 tree pre
= C_MAYBE_CONST_EXPR_PRE (expr
);
1164 tree inner
= C_MAYBE_CONST_EXPR_EXPR (expr
);
1165 if (C_MAYBE_CONST_EXPR_NON_CONST (expr
))
1166 *maybe_const_operands
= false;
1167 if (C_MAYBE_CONST_EXPR_INT_OPERANDS (expr
))
1168 *maybe_const_itself
= false;
1169 if (pre
&& !in_init
)
1170 ret
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr
), pre
, inner
);
1176 /* Assignment, increment, decrement, function call and comma
1177 operators, and statement expressions, cannot occur in constant
1178 expressions if evaluated / outside of sizeof. (Function calls
1179 were handled above, though VA_ARG_EXPR is treated like a function
1180 call here, and statement expressions are handled through
1181 C_MAYBE_CONST_EXPR to avoid folding inside them.) */
1185 case PREDECREMENT_EXPR
:
1186 case PREINCREMENT_EXPR
:
1187 case POSTDECREMENT_EXPR
:
1188 case POSTINCREMENT_EXPR
:
1190 *maybe_const_operands
= false;
1197 *maybe_const_operands
= false;
1205 /* Fold individual tree codes as appropriate. */
1208 case COMPOUND_LITERAL_EXPR
:
1209 /* Any non-constancy will have been marked in a containing
1210 C_MAYBE_CONST_EXPR; there is no more folding to do here. */
1214 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1215 op1
= TREE_OPERAND (expr
, 1);
1216 op2
= TREE_OPERAND (expr
, 2);
1217 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1218 maybe_const_itself
);
1219 STRIP_TYPE_NOPS (op0
);
1220 if (op0
!= orig_op0
)
1221 ret
= build3 (COMPONENT_REF
, TREE_TYPE (expr
), op0
, op1
, op2
);
1224 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1225 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1230 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1231 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1232 op2
= TREE_OPERAND (expr
, 2);
1233 op3
= TREE_OPERAND (expr
, 3);
1234 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1235 maybe_const_itself
);
1236 STRIP_TYPE_NOPS (op0
);
1237 op1
= c_fully_fold_internal (op1
, in_init
, maybe_const_operands
,
1238 maybe_const_itself
);
1239 STRIP_TYPE_NOPS (op1
);
1240 op1
= decl_constant_value_for_optimization (op1
);
1241 if (op0
!= orig_op0
|| op1
!= orig_op1
)
1242 ret
= build4 (ARRAY_REF
, TREE_TYPE (expr
), op0
, op1
, op2
, op3
);
1245 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1246 TREE_SIDE_EFFECTS (ret
) = TREE_SIDE_EFFECTS (expr
);
1247 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1254 case PREDECREMENT_EXPR
:
1255 case PREINCREMENT_EXPR
:
1256 case POSTDECREMENT_EXPR
:
1257 case POSTINCREMENT_EXPR
:
1261 case POINTER_PLUS_EXPR
:
1262 case TRUNC_DIV_EXPR
:
1264 case FLOOR_DIV_EXPR
:
1265 case TRUNC_MOD_EXPR
:
1267 case EXACT_DIV_EXPR
:
1280 case TRUTH_AND_EXPR
:
1282 case TRUTH_XOR_EXPR
:
1283 case UNORDERED_EXPR
:
1290 /* Binary operations evaluating both arguments (increment and
1291 decrement are binary internally in GCC). */
1292 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1293 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1294 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1295 maybe_const_itself
);
1296 STRIP_TYPE_NOPS (op0
);
1297 if (code
!= MODIFY_EXPR
1298 && code
!= PREDECREMENT_EXPR
1299 && code
!= PREINCREMENT_EXPR
1300 && code
!= POSTDECREMENT_EXPR
1301 && code
!= POSTINCREMENT_EXPR
)
1302 op0
= decl_constant_value_for_optimization (op0
);
1303 /* The RHS of a MODIFY_EXPR was fully folded when building that
1304 expression for the sake of conversion warnings. */
1305 if (code
!= MODIFY_EXPR
)
1306 op1
= c_fully_fold_internal (op1
, in_init
, maybe_const_operands
,
1307 maybe_const_itself
);
1308 STRIP_TYPE_NOPS (op1
);
1309 op1
= decl_constant_value_for_optimization (op1
);
1310 if (op0
!= orig_op0
|| op1
!= orig_op1
|| in_init
)
1312 ? fold_build2_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
)
1313 : fold_build2_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
);
1316 if (TREE_OVERFLOW_P (ret
)
1317 && !TREE_OVERFLOW_P (op0
)
1318 && !TREE_OVERFLOW_P (op1
))
1319 overflow_warning (EXPR_LOCATION (expr
), ret
);
1320 if ((code
== LSHIFT_EXPR
|| code
== RSHIFT_EXPR
)
1321 && TREE_CODE (orig_op1
) != INTEGER_CST
1322 && TREE_CODE (op1
) == INTEGER_CST
1323 && (TREE_CODE (TREE_TYPE (orig_op0
)) == INTEGER_TYPE
1324 || TREE_CODE (TREE_TYPE (orig_op0
)) == FIXED_POINT_TYPE
)
1325 && TREE_CODE (TREE_TYPE (orig_op1
)) == INTEGER_TYPE
1326 && c_inhibit_evaluation_warnings
== 0)
1328 if (tree_int_cst_sgn (op1
) < 0)
1329 warning_at (loc
, 0, (code
== LSHIFT_EXPR
1330 ? G_("left shift count is negative")
1331 : G_("right shift count is negative")));
1332 else if (compare_tree_int (op1
,
1333 TYPE_PRECISION (TREE_TYPE (orig_op0
)))
1335 warning_at (loc
, 0, (code
== LSHIFT_EXPR
1336 ? G_("left shift count >= width of type")
1337 : G_("right shift count >= width of type")));
1342 case FIX_TRUNC_EXPR
:
1345 case ADDR_SPACE_CONVERT_EXPR
:
1346 case VIEW_CONVERT_EXPR
:
1347 case NON_LVALUE_EXPR
:
1350 case TRUTH_NOT_EXPR
:
1355 /* Unary operations. */
1356 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1357 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1358 maybe_const_itself
);
1359 STRIP_TYPE_NOPS (op0
);
1360 if (code
!= ADDR_EXPR
&& code
!= REALPART_EXPR
&& code
!= IMAGPART_EXPR
)
1361 op0
= decl_constant_value_for_optimization (op0
);
1362 /* ??? Cope with user tricks that amount to offsetof. The middle-end is
1363 not prepared to deal with them if they occur in initializers. */
1365 && code
== ADDR_EXPR
1366 && (op1
= get_base_address (op0
)) != NULL_TREE
1367 && TREE_CODE (op1
) == INDIRECT_REF
1368 && TREE_CONSTANT (TREE_OPERAND (op1
, 0)))
1369 ret
= fold_convert_loc (loc
, TREE_TYPE (expr
), fold_offsetof_1 (op0
));
1370 else if (op0
!= orig_op0
|| in_init
)
1372 ? fold_build1_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
)
1373 : fold_build1_loc (loc
, code
, TREE_TYPE (expr
), op0
);
1376 if (code
== INDIRECT_REF
1378 && TREE_CODE (ret
) == INDIRECT_REF
)
1380 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1381 TREE_SIDE_EFFECTS (ret
) = TREE_SIDE_EFFECTS (expr
);
1382 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1386 case FIX_TRUNC_EXPR
:
1389 /* Don't warn about explicit conversions. We will already
1390 have warned about suspect implicit conversions. */
1394 if (TREE_OVERFLOW_P (ret
) && !TREE_OVERFLOW_P (op0
))
1395 overflow_warning (EXPR_LOCATION (expr
), ret
);
1400 case TRUTH_ANDIF_EXPR
:
1401 case TRUTH_ORIF_EXPR
:
1402 /* Binary operations not necessarily evaluating both
1404 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1405 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1406 op0
= c_fully_fold_internal (op0
, in_init
, &op0_const
, &op0_const_self
);
1407 STRIP_TYPE_NOPS (op0
);
1409 unused_p
= (op0
== (code
== TRUTH_ANDIF_EXPR
1410 ? truthvalue_false_node
1411 : truthvalue_true_node
));
1412 c_disable_warnings (unused_p
);
1413 op1
= c_fully_fold_internal (op1
, in_init
, &op1_const
, &op1_const_self
);
1414 STRIP_TYPE_NOPS (op1
);
1415 c_enable_warnings (unused_p
);
1417 if (op0
!= orig_op0
|| op1
!= orig_op1
|| in_init
)
1419 ? fold_build2_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
)
1420 : fold_build2_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
);
1423 *maybe_const_operands
&= op0_const
;
1424 *maybe_const_itself
&= op0_const_self
;
1428 && (code
== TRUTH_ANDIF_EXPR
1429 ? op0
== truthvalue_false_node
1430 : op0
== truthvalue_true_node
)))
1431 *maybe_const_operands
&= op1_const
;
1434 && (code
== TRUTH_ANDIF_EXPR
1435 ? op0
== truthvalue_false_node
1436 : op0
== truthvalue_true_node
)))
1437 *maybe_const_itself
&= op1_const_self
;
1441 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1442 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1443 orig_op2
= op2
= TREE_OPERAND (expr
, 2);
1444 op0
= c_fully_fold_internal (op0
, in_init
, &op0_const
, &op0_const_self
);
1446 STRIP_TYPE_NOPS (op0
);
1447 c_disable_warnings (op0
== truthvalue_false_node
);
1448 op1
= c_fully_fold_internal (op1
, in_init
, &op1_const
, &op1_const_self
);
1449 STRIP_TYPE_NOPS (op1
);
1450 c_enable_warnings (op0
== truthvalue_false_node
);
1452 c_disable_warnings (op0
== truthvalue_true_node
);
1453 op2
= c_fully_fold_internal (op2
, in_init
, &op2_const
, &op2_const_self
);
1454 STRIP_TYPE_NOPS (op2
);
1455 c_enable_warnings (op0
== truthvalue_true_node
);
1457 if (op0
!= orig_op0
|| op1
!= orig_op1
|| op2
!= orig_op2
)
1458 ret
= fold_build3_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
, op2
);
1461 *maybe_const_operands
&= op0_const
;
1462 *maybe_const_itself
&= op0_const_self
;
1466 && op0
== truthvalue_false_node
))
1467 *maybe_const_operands
&= op1_const
;
1470 && op0
== truthvalue_false_node
))
1471 *maybe_const_itself
&= op1_const_self
;
1475 && op0
== truthvalue_true_node
))
1476 *maybe_const_operands
&= op2_const
;
1479 && op0
== truthvalue_true_node
))
1480 *maybe_const_itself
&= op2_const_self
;
1483 case EXCESS_PRECISION_EXPR
:
1484 /* Each case where an operand with excess precision may be
1485 encountered must remove the EXCESS_PRECISION_EXPR around
1486 inner operands and possibly put one around the whole
1487 expression or possibly convert to the semantic type (which
1488 c_fully_fold does); we cannot tell at this stage which is
1489 appropriate in any particular case. */
1493 /* Various codes may appear through folding built-in functions
1494 and their arguments. */
1499 /* Some folding may introduce NON_LVALUE_EXPRs; all lvalue checks
1500 have been done by this point, so remove them again. */
1501 nowarning
|= TREE_NO_WARNING (ret
);
1502 STRIP_TYPE_NOPS (ret
);
1503 if (nowarning
&& !TREE_NO_WARNING (ret
))
1505 if (!CAN_HAVE_LOCATION_P (ret
))
1506 ret
= build1 (NOP_EXPR
, TREE_TYPE (ret
), ret
);
1507 TREE_NO_WARNING (ret
) = 1;
1510 protected_set_expr_location (ret
, loc
);
1514 /* If not optimizing, EXP is not a VAR_DECL, or EXP has array type,
1515 return EXP. Otherwise, return either EXP or its known constant
1516 value (if it has one), but return EXP if EXP has mode BLKmode. ???
1517 Is the BLKmode test appropriate? */
1520 decl_constant_value_for_optimization (tree exp
)
1524 /* This function is only used by C, for c_fully_fold and other
1525 optimization, and may not be correct for C++. */
1526 if (c_dialect_cxx ())
1530 || TREE_CODE (exp
) != VAR_DECL
1531 || TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
1532 || DECL_MODE (exp
) == BLKmode
)
1535 ret
= decl_constant_value (exp
);
1536 /* Avoid unwanted tree sharing between the initializer and current
1537 function's body where the tree can be modified e.g. by the
1539 if (ret
!= exp
&& TREE_STATIC (exp
))
1540 ret
= unshare_expr (ret
);
1544 /* Print a warning if a constant expression had overflow in folding.
1545 Invoke this function on every expression that the language
1546 requires to be a constant expression.
1547 Note the ANSI C standard says it is erroneous for a
1548 constant expression to overflow. */
1551 constant_expression_warning (tree value
)
1553 if (warn_overflow
&& pedantic
1554 && (TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1555 || TREE_CODE (value
) == FIXED_CST
1556 || TREE_CODE (value
) == VECTOR_CST
1557 || TREE_CODE (value
) == COMPLEX_CST
)
1558 && TREE_OVERFLOW (value
))
1559 pedwarn (input_location
, OPT_Woverflow
, "overflow in constant expression");
1562 /* The same as above but print an unconditional error. */
1564 constant_expression_error (tree value
)
1566 if ((TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1567 || TREE_CODE (value
) == FIXED_CST
1568 || TREE_CODE (value
) == VECTOR_CST
1569 || TREE_CODE (value
) == COMPLEX_CST
)
1570 && TREE_OVERFLOW (value
))
1571 error ("overflow in constant expression");
1574 /* Print a warning if an expression had overflow in folding and its
1577 Invoke this function on every expression that
1578 (1) appears in the source code, and
1579 (2) is a constant expression that overflowed, and
1580 (3) is not already checked by convert_and_check;
1581 however, do not invoke this function on operands of explicit casts
1582 or when the expression is the result of an operator and any operand
1583 already overflowed. */
1586 overflow_warning (location_t loc
, tree value
)
1588 if (c_inhibit_evaluation_warnings
!= 0)
1591 switch (TREE_CODE (value
))
1594 warning_at (loc
, OPT_Woverflow
, "integer overflow in expression");
1598 warning_at (loc
, OPT_Woverflow
,
1599 "floating point overflow in expression");
1603 warning_at (loc
, OPT_Woverflow
, "fixed-point overflow in expression");
1607 warning_at (loc
, OPT_Woverflow
, "vector overflow in expression");
1611 if (TREE_CODE (TREE_REALPART (value
)) == INTEGER_CST
)
1612 warning_at (loc
, OPT_Woverflow
,
1613 "complex integer overflow in expression");
1614 else if (TREE_CODE (TREE_REALPART (value
)) == REAL_CST
)
1615 warning_at (loc
, OPT_Woverflow
,
1616 "complex floating point overflow in expression");
1624 /* Warn about uses of logical || / && operator in a context where it
1625 is likely that the bitwise equivalent was intended by the
1626 programmer. We have seen an expression in which CODE is a binary
1627 operator used to combine expressions OP_LEFT and OP_RIGHT, which before folding
1628 had CODE_LEFT and CODE_RIGHT, into an expression of type TYPE. */
1630 warn_logical_operator (location_t location
, enum tree_code code
, tree type
,
1631 enum tree_code code_left
, tree op_left
,
1632 enum tree_code
ARG_UNUSED (code_right
), tree op_right
)
1634 int or_op
= (code
== TRUTH_ORIF_EXPR
|| code
== TRUTH_OR_EXPR
);
1635 int in0_p
, in1_p
, in_p
;
1636 tree low0
, low1
, low
, high0
, high1
, high
, lhs
, rhs
, tem
;
1637 bool strict_overflow_p
= false;
1639 if (code
!= TRUTH_ANDIF_EXPR
1640 && code
!= TRUTH_AND_EXPR
1641 && code
!= TRUTH_ORIF_EXPR
1642 && code
!= TRUTH_OR_EXPR
)
1645 /* Warn if &&/|| are being used in a context where it is
1646 likely that the bitwise equivalent was intended by the
1647 programmer. That is, an expression such as op && MASK
1648 where op should not be any boolean expression, nor a
1649 constant, and mask seems to be a non-boolean integer constant. */
1650 if (!truth_value_p (code_left
)
1651 && INTEGRAL_TYPE_P (TREE_TYPE (op_left
))
1652 && !CONSTANT_CLASS_P (op_left
)
1653 && !TREE_NO_WARNING (op_left
)
1654 && TREE_CODE (op_right
) == INTEGER_CST
1655 && !integer_zerop (op_right
)
1656 && !integer_onep (op_right
))
1659 warning_at (location
, OPT_Wlogical_op
, "logical %<or%>"
1660 " applied to non-boolean constant");
1662 warning_at (location
, OPT_Wlogical_op
, "logical %<and%>"
1663 " applied to non-boolean constant");
1664 TREE_NO_WARNING (op_left
) = true;
1668 /* We do not warn for constants because they are typical of macro
1669 expansions that test for features. */
1670 if (CONSTANT_CLASS_P (op_left
) || CONSTANT_CLASS_P (op_right
))
1673 /* This warning only makes sense with logical operands. */
1674 if (!(truth_value_p (TREE_CODE (op_left
))
1675 || INTEGRAL_TYPE_P (TREE_TYPE (op_left
)))
1676 || !(truth_value_p (TREE_CODE (op_right
))
1677 || INTEGRAL_TYPE_P (TREE_TYPE (op_right
))))
1680 /* The range computations only work with scalars. */
1681 if (VECTOR_TYPE_P (TREE_TYPE (op_left
))
1682 || VECTOR_TYPE_P (TREE_TYPE (op_right
)))
1685 /* We first test whether either side separately is trivially true
1686 (with OR) or trivially false (with AND). If so, do not warn.
1687 This is a common idiom for testing ranges of data types in
1689 lhs
= make_range (op_left
, &in0_p
, &low0
, &high0
, &strict_overflow_p
);
1692 if (TREE_CODE (lhs
) == C_MAYBE_CONST_EXPR
)
1693 lhs
= C_MAYBE_CONST_EXPR_EXPR (lhs
);
1695 /* If this is an OR operation, invert both sides; now, the result
1696 should be always false to get a warning. */
1700 tem
= build_range_check (UNKNOWN_LOCATION
, type
, lhs
, in0_p
, low0
, high0
);
1701 if (tem
&& integer_zerop (tem
))
1704 rhs
= make_range (op_right
, &in1_p
, &low1
, &high1
, &strict_overflow_p
);
1707 if (TREE_CODE (rhs
) == C_MAYBE_CONST_EXPR
)
1708 rhs
= C_MAYBE_CONST_EXPR_EXPR (rhs
);
1710 /* If this is an OR operation, invert both sides; now, the result
1711 should be always false to get a warning. */
1715 tem
= build_range_check (UNKNOWN_LOCATION
, type
, rhs
, in1_p
, low1
, high1
);
1716 if (tem
&& integer_zerop (tem
))
1719 /* If both expressions have the same operand, if we can merge the
1720 ranges, and if the range test is always false, then warn. */
1721 if (operand_equal_p (lhs
, rhs
, 0)
1722 && merge_ranges (&in_p
, &low
, &high
, in0_p
, low0
, high0
,
1724 && 0 != (tem
= build_range_check (UNKNOWN_LOCATION
,
1725 type
, lhs
, in_p
, low
, high
))
1726 && integer_zerop (tem
))
1729 warning_at (location
, OPT_Wlogical_op
,
1731 "of collectively exhaustive tests is always true");
1733 warning_at (location
, OPT_Wlogical_op
,
1735 "of mutually exclusive tests is always false");
1739 /* Warn about logical not used on the left hand side operand of a comparison.
1740 This function assumes that the LHS is inside of TRUTH_NOT_EXPR.
1741 Do not warn if RHS is of a boolean type. */
1744 warn_logical_not_parentheses (location_t location
, enum tree_code code
,
1747 if (TREE_CODE_CLASS (code
) != tcc_comparison
1748 || TREE_TYPE (rhs
) == NULL_TREE
1749 || TREE_CODE (TREE_TYPE (rhs
)) == BOOLEAN_TYPE
)
1752 warning_at (location
, OPT_Wlogical_not_parentheses
,
1753 "logical not is only applied to the left hand side of "
1757 /* Warn if EXP contains any computations whose results are not used.
1758 Return true if a warning is printed; false otherwise. LOCUS is the
1759 (potential) location of the expression. */
1762 warn_if_unused_value (const_tree exp
, location_t locus
)
1765 if (TREE_USED (exp
) || TREE_NO_WARNING (exp
))
1768 /* Don't warn about void constructs. This includes casting to void,
1769 void function calls, and statement expressions with a final cast
1771 if (VOID_TYPE_P (TREE_TYPE (exp
)))
1774 if (EXPR_HAS_LOCATION (exp
))
1775 locus
= EXPR_LOCATION (exp
);
1777 switch (TREE_CODE (exp
))
1779 case PREINCREMENT_EXPR
:
1780 case POSTINCREMENT_EXPR
:
1781 case PREDECREMENT_EXPR
:
1782 case POSTDECREMENT_EXPR
:
1787 case TRY_CATCH_EXPR
:
1788 case WITH_CLEANUP_EXPR
:
1794 /* For a binding, warn if no side effect within it. */
1795 exp
= BIND_EXPR_BODY (exp
);
1799 case NON_LVALUE_EXPR
:
1801 exp
= TREE_OPERAND (exp
, 0);
1804 case TRUTH_ORIF_EXPR
:
1805 case TRUTH_ANDIF_EXPR
:
1806 /* In && or ||, warn if 2nd operand has no side effect. */
1807 exp
= TREE_OPERAND (exp
, 1);
1811 if (warn_if_unused_value (TREE_OPERAND (exp
, 0), locus
))
1813 /* Let people do `(foo (), 0)' without a warning. */
1814 if (TREE_CONSTANT (TREE_OPERAND (exp
, 1)))
1816 exp
= TREE_OPERAND (exp
, 1);
1820 /* If this is an expression with side effects, don't warn; this
1821 case commonly appears in macro expansions. */
1822 if (TREE_SIDE_EFFECTS (exp
))
1827 /* Don't warn about automatic dereferencing of references, since
1828 the user cannot control it. */
1829 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == REFERENCE_TYPE
)
1831 exp
= TREE_OPERAND (exp
, 0);
1837 /* Referencing a volatile value is a side effect, so don't warn. */
1838 if ((DECL_P (exp
) || REFERENCE_CLASS_P (exp
))
1839 && TREE_THIS_VOLATILE (exp
))
1842 /* If this is an expression which has no operands, there is no value
1843 to be unused. There are no such language-independent codes,
1844 but front ends may define such. */
1845 if (EXPRESSION_CLASS_P (exp
) && TREE_OPERAND_LENGTH (exp
) == 0)
1849 return warning_at (locus
, OPT_Wunused_value
, "value computed is not used");
1854 /* Print a warning about casts that might indicate violation
1855 of strict aliasing rules if -Wstrict-aliasing is used and
1856 strict aliasing mode is in effect. OTYPE is the original
1857 TREE_TYPE of EXPR, and TYPE the type we're casting to. */
1860 strict_aliasing_warning (tree otype
, tree type
, tree expr
)
1862 /* Strip pointer conversion chains and get to the correct original type. */
1864 otype
= TREE_TYPE (expr
);
1866 if (!(flag_strict_aliasing
1867 && POINTER_TYPE_P (type
)
1868 && POINTER_TYPE_P (otype
)
1869 && !VOID_TYPE_P (TREE_TYPE (type
)))
1870 /* If the type we are casting to is a ref-all pointer
1871 dereferencing it is always valid. */
1872 || TYPE_REF_CAN_ALIAS_ALL (type
))
1875 if ((warn_strict_aliasing
> 1) && TREE_CODE (expr
) == ADDR_EXPR
1876 && (DECL_P (TREE_OPERAND (expr
, 0))
1877 || handled_component_p (TREE_OPERAND (expr
, 0))))
1879 /* Casting the address of an object to non void pointer. Warn
1880 if the cast breaks type based aliasing. */
1881 if (!COMPLETE_TYPE_P (TREE_TYPE (type
)) && warn_strict_aliasing
== 2)
1883 warning (OPT_Wstrict_aliasing
, "type-punning to incomplete type "
1884 "might break strict-aliasing rules");
1889 /* warn_strict_aliasing >= 3. This includes the default (3).
1890 Only warn if the cast is dereferenced immediately. */
1891 alias_set_type set1
=
1892 get_alias_set (TREE_TYPE (TREE_OPERAND (expr
, 0)));
1893 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
1895 if (set1
!= set2
&& set2
!= 0
1896 && (set1
== 0 || !alias_sets_conflict_p (set1
, set2
)))
1898 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1899 "pointer will break strict-aliasing rules");
1902 else if (warn_strict_aliasing
== 2
1903 && !alias_sets_must_conflict_p (set1
, set2
))
1905 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1906 "pointer might break strict-aliasing rules");
1912 if ((warn_strict_aliasing
== 1) && !VOID_TYPE_P (TREE_TYPE (otype
)))
1914 /* At this level, warn for any conversions, even if an address is
1915 not taken in the same statement. This will likely produce many
1916 false positives, but could be useful to pinpoint problems that
1917 are not revealed at higher levels. */
1918 alias_set_type set1
= get_alias_set (TREE_TYPE (otype
));
1919 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
1920 if (!COMPLETE_TYPE_P (type
)
1921 || !alias_sets_must_conflict_p (set1
, set2
))
1923 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1924 "pointer might break strict-aliasing rules");
1932 /* Warn about memset (&a, 0, sizeof (&a)); and similar mistakes with
1933 sizeof as last operand of certain builtins. */
1936 sizeof_pointer_memaccess_warning (location_t
*sizeof_arg_loc
, tree callee
,
1937 vec
<tree
, va_gc
> *params
, tree
*sizeof_arg
,
1938 bool (*comp_types
) (tree
, tree
))
1940 tree type
, dest
= NULL_TREE
, src
= NULL_TREE
, tem
;
1941 bool strop
= false, cmp
= false;
1942 unsigned int idx
= ~0;
1945 if (TREE_CODE (callee
) != FUNCTION_DECL
1946 || DECL_BUILT_IN_CLASS (callee
) != BUILT_IN_NORMAL
1947 || vec_safe_length (params
) <= 1)
1950 switch (DECL_FUNCTION_CODE (callee
))
1952 case BUILT_IN_STRNCMP
:
1953 case BUILT_IN_STRNCASECMP
:
1956 case BUILT_IN_STRNCPY
:
1957 case BUILT_IN_STRNCPY_CHK
:
1958 case BUILT_IN_STRNCAT
:
1959 case BUILT_IN_STRNCAT_CHK
:
1960 case BUILT_IN_STPNCPY
:
1961 case BUILT_IN_STPNCPY_CHK
:
1964 case BUILT_IN_MEMCPY
:
1965 case BUILT_IN_MEMCPY_CHK
:
1966 case BUILT_IN_MEMMOVE
:
1967 case BUILT_IN_MEMMOVE_CHK
:
1968 if (params
->length () < 3)
1971 dest
= (*params
)[0];
1974 case BUILT_IN_BCOPY
:
1975 if (params
->length () < 3)
1978 dest
= (*params
)[1];
1981 case BUILT_IN_MEMCMP
:
1983 if (params
->length () < 3)
1986 dest
= (*params
)[0];
1990 case BUILT_IN_MEMSET
:
1991 case BUILT_IN_MEMSET_CHK
:
1992 if (params
->length () < 3)
1994 dest
= (*params
)[0];
1997 case BUILT_IN_BZERO
:
1998 dest
= (*params
)[0];
2001 case BUILT_IN_STRNDUP
:
2006 case BUILT_IN_MEMCHR
:
2007 if (params
->length () < 3)
2012 case BUILT_IN_SNPRINTF
:
2013 case BUILT_IN_SNPRINTF_CHK
:
2014 case BUILT_IN_VSNPRINTF
:
2015 case BUILT_IN_VSNPRINTF_CHK
:
2016 dest
= (*params
)[0];
2027 if (sizeof_arg
[idx
] == NULL
|| sizeof_arg
[idx
] == error_mark_node
)
2030 type
= TYPE_P (sizeof_arg
[idx
])
2031 ? sizeof_arg
[idx
] : TREE_TYPE (sizeof_arg
[idx
]);
2032 if (!POINTER_TYPE_P (type
))
2036 && (tem
= tree_strip_nop_conversions (dest
))
2037 && POINTER_TYPE_P (TREE_TYPE (tem
))
2038 && comp_types (TREE_TYPE (TREE_TYPE (tem
)), type
))
2042 && (tem
= tree_strip_nop_conversions (src
))
2043 && POINTER_TYPE_P (TREE_TYPE (tem
))
2044 && comp_types (TREE_TYPE (TREE_TYPE (tem
)), type
))
2047 loc
= sizeof_arg_loc
[idx
];
2051 if (!TYPE_P (sizeof_arg
[idx
])
2052 && operand_equal_p (dest
, sizeof_arg
[idx
], 0)
2053 && comp_types (TREE_TYPE (dest
), type
))
2055 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2056 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2057 "argument to %<sizeof%> in %qD call is the same "
2058 "expression as the destination; did you mean to "
2059 "remove the addressof?", callee
);
2060 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2061 == TYPE_PRECISION (char_type_node
))
2063 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2064 "argument to %<sizeof%> in %qD call is the same "
2065 "expression as the destination; did you mean to "
2066 "provide an explicit length?", callee
);
2068 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2069 "argument to %<sizeof%> in %qD call is the same "
2070 "expression as the destination; did you mean to "
2071 "dereference it?", callee
);
2075 if (POINTER_TYPE_P (TREE_TYPE (dest
))
2077 && comp_types (TREE_TYPE (dest
), type
)
2078 && !VOID_TYPE_P (TREE_TYPE (type
)))
2080 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2081 "argument to %<sizeof%> in %qD call is the same "
2082 "pointer type %qT as the destination; expected %qT "
2083 "or an explicit length", callee
, TREE_TYPE (dest
),
2084 TREE_TYPE (TREE_TYPE (dest
)));
2091 if (!TYPE_P (sizeof_arg
[idx
])
2092 && operand_equal_p (src
, sizeof_arg
[idx
], 0)
2093 && comp_types (TREE_TYPE (src
), type
))
2095 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2096 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2097 "argument to %<sizeof%> in %qD call is the same "
2098 "expression as the source; did you mean to "
2099 "remove the addressof?", callee
);
2100 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2101 == TYPE_PRECISION (char_type_node
))
2103 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2104 "argument to %<sizeof%> in %qD call is the same "
2105 "expression as the source; did you mean to "
2106 "provide an explicit length?", callee
);
2108 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2109 "argument to %<sizeof%> in %qD call is the same "
2110 "expression as the source; did you mean to "
2111 "dereference it?", callee
);
2115 if (POINTER_TYPE_P (TREE_TYPE (src
))
2117 && comp_types (TREE_TYPE (src
), type
)
2118 && !VOID_TYPE_P (TREE_TYPE (type
)))
2120 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2121 "argument to %<sizeof%> in %qD call is the same "
2122 "pointer type %qT as the source; expected %qT "
2123 "or an explicit length", callee
, TREE_TYPE (src
),
2124 TREE_TYPE (TREE_TYPE (src
)));
2131 if (!TYPE_P (sizeof_arg
[idx
])
2132 && operand_equal_p (dest
, sizeof_arg
[idx
], 0)
2133 && comp_types (TREE_TYPE (dest
), type
))
2135 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2136 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2137 "argument to %<sizeof%> in %qD call is the same "
2138 "expression as the first source; did you mean to "
2139 "remove the addressof?", callee
);
2140 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2141 == TYPE_PRECISION (char_type_node
))
2143 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2144 "argument to %<sizeof%> in %qD call is the same "
2145 "expression as the first source; did you mean to "
2146 "provide an explicit length?", callee
);
2148 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2149 "argument to %<sizeof%> in %qD call is the same "
2150 "expression as the first source; did you mean to "
2151 "dereference it?", callee
);
2155 if (POINTER_TYPE_P (TREE_TYPE (dest
))
2157 && comp_types (TREE_TYPE (dest
), type
)
2158 && !VOID_TYPE_P (TREE_TYPE (type
)))
2160 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2161 "argument to %<sizeof%> in %qD call is the same "
2162 "pointer type %qT as the first source; expected %qT "
2163 "or an explicit length", callee
, TREE_TYPE (dest
),
2164 TREE_TYPE (TREE_TYPE (dest
)));
2171 if (!TYPE_P (sizeof_arg
[idx
])
2172 && operand_equal_p (src
, sizeof_arg
[idx
], 0)
2173 && comp_types (TREE_TYPE (src
), type
))
2175 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2176 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2177 "argument to %<sizeof%> in %qD call is the same "
2178 "expression as the second source; did you mean to "
2179 "remove the addressof?", callee
);
2180 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2181 == TYPE_PRECISION (char_type_node
))
2183 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2184 "argument to %<sizeof%> in %qD call is the same "
2185 "expression as the second source; did you mean to "
2186 "provide an explicit length?", callee
);
2188 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2189 "argument to %<sizeof%> in %qD call is the same "
2190 "expression as the second source; did you mean to "
2191 "dereference it?", callee
);
2195 if (POINTER_TYPE_P (TREE_TYPE (src
))
2197 && comp_types (TREE_TYPE (src
), type
)
2198 && !VOID_TYPE_P (TREE_TYPE (type
)))
2200 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2201 "argument to %<sizeof%> in %qD call is the same "
2202 "pointer type %qT as the second source; expected %qT "
2203 "or an explicit length", callee
, TREE_TYPE (src
),
2204 TREE_TYPE (TREE_TYPE (src
)));
2211 /* Warn for unlikely, improbable, or stupid DECL declarations
2215 check_main_parameter_types (tree decl
)
2217 function_args_iterator iter
;
2221 FOREACH_FUNCTION_ARGS (TREE_TYPE (decl
), type
, iter
)
2223 /* XXX void_type_node belies the abstraction. */
2224 if (type
== void_type_node
|| type
== error_mark_node
)
2228 if (TYPE_ATOMIC (t
))
2229 pedwarn (input_location
, OPT_Wmain
,
2230 "%<_Atomic%>-qualified parameter type %qT of %q+D",
2232 while (POINTER_TYPE_P (t
))
2235 if (TYPE_ATOMIC (t
))
2236 pedwarn (input_location
, OPT_Wmain
,
2237 "%<_Atomic%>-qualified parameter type %qT of %q+D",
2245 if (TYPE_MAIN_VARIANT (type
) != integer_type_node
)
2246 pedwarn (input_location
, OPT_Wmain
,
2247 "first argument of %q+D should be %<int%>", decl
);
2251 if (TREE_CODE (type
) != POINTER_TYPE
2252 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
2253 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
2255 pedwarn (input_location
, OPT_Wmain
,
2256 "second argument of %q+D should be %<char **%>", decl
);
2260 if (TREE_CODE (type
) != POINTER_TYPE
2261 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
2262 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
2264 pedwarn (input_location
, OPT_Wmain
,
2265 "third argument of %q+D should probably be "
2266 "%<char **%>", decl
);
2271 /* It is intentional that this message does not mention the third
2272 argument because it's only mentioned in an appendix of the
2274 if (argct
> 0 && (argct
< 2 || argct
> 3))
2275 pedwarn (input_location
, OPT_Wmain
,
2276 "%q+D takes only zero or two arguments", decl
);
2278 if (stdarg_p (TREE_TYPE (decl
)))
2279 pedwarn (input_location
, OPT_Wmain
,
2280 "%q+D declared as variadic function", decl
);
2283 /* vector_targets_convertible_p is used for vector pointer types. The
2284 callers perform various checks that the qualifiers are satisfactory,
2285 while OTOH vector_targets_convertible_p ignores the number of elements
2286 in the vectors. That's fine with vector pointers as we can consider,
2287 say, a vector of 8 elements as two consecutive vectors of 4 elements,
2288 and that does not require and conversion of the pointer values.
2289 In contrast, vector_types_convertible_p and
2290 vector_types_compatible_elements_p are used for vector value types. */
2291 /* True if pointers to distinct types T1 and T2 can be converted to
2292 each other without an explicit cast. Only returns true for opaque
2295 vector_targets_convertible_p (const_tree t1
, const_tree t2
)
2297 if (TREE_CODE (t1
) == VECTOR_TYPE
&& TREE_CODE (t2
) == VECTOR_TYPE
2298 && (TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2299 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2305 /* vector_types_convertible_p is used for vector value types.
2306 It could in principle call vector_targets_convertible_p as a subroutine,
2307 but then the check for vector type would be duplicated with its callers,
2308 and also the purpose of vector_targets_convertible_p would become
2310 Where vector_types_convertible_p returns true, a conversion might still be
2311 needed to make the types match.
2312 In contrast, vector_targets_convertible_p is used for vector pointer
2313 values, and vector_types_compatible_elements_p is used specifically
2314 in the context for binary operators, as a check if use is possible without
2316 /* True if vector types T1 and T2 can be converted to each other
2317 without an explicit cast. If EMIT_LAX_NOTE is true, and T1 and T2
2318 can only be converted with -flax-vector-conversions yet that is not
2319 in effect, emit a note telling the user about that option if such
2320 a note has not previously been emitted. */
2322 vector_types_convertible_p (const_tree t1
, const_tree t2
, bool emit_lax_note
)
2324 static bool emitted_lax_note
= false;
2325 bool convertible_lax
;
2327 if ((TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2328 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2332 (tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
))
2333 && (TREE_CODE (TREE_TYPE (t1
)) != REAL_TYPE
||
2334 TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
))
2335 && (INTEGRAL_TYPE_P (TREE_TYPE (t1
))
2336 == INTEGRAL_TYPE_P (TREE_TYPE (t2
))));
2338 if (!convertible_lax
|| flag_lax_vector_conversions
)
2339 return convertible_lax
;
2341 if (TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
)
2342 && lang_hooks
.types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
2345 if (emit_lax_note
&& !emitted_lax_note
)
2347 emitted_lax_note
= true;
2348 inform (input_location
, "use -flax-vector-conversions to permit "
2349 "conversions between vectors with differing "
2350 "element types or numbers of subparts");
2356 /* Build a VEC_PERM_EXPR if V0, V1 and MASK are not error_mark_nodes
2357 and have vector types, V0 has the same type as V1, and the number of
2358 elements of V0, V1, MASK is the same.
2360 In case V1 is a NULL_TREE it is assumed that __builtin_shuffle was
2361 called with two arguments. In this case implementation passes the
2362 first argument twice in order to share the same tree code. This fact
2363 could enable the mask-values being twice the vector length. This is
2364 an implementation accident and this semantics is not guaranteed to
2367 c_build_vec_perm_expr (location_t loc
, tree v0
, tree v1
, tree mask
,
2372 bool maybe_const
= false;
2373 bool two_arguments
= false;
2375 if (v1
== NULL_TREE
)
2377 two_arguments
= true;
2381 if (v0
== error_mark_node
|| v1
== error_mark_node
2382 || mask
== error_mark_node
)
2383 return error_mark_node
;
2385 if (TREE_CODE (TREE_TYPE (mask
)) != VECTOR_TYPE
2386 || TREE_CODE (TREE_TYPE (TREE_TYPE (mask
))) != INTEGER_TYPE
)
2389 error_at (loc
, "__builtin_shuffle last argument must "
2390 "be an integer vector");
2391 return error_mark_node
;
2394 if (TREE_CODE (TREE_TYPE (v0
)) != VECTOR_TYPE
2395 || TREE_CODE (TREE_TYPE (v1
)) != VECTOR_TYPE
)
2398 error_at (loc
, "__builtin_shuffle arguments must be vectors");
2399 return error_mark_node
;
2402 if (TYPE_MAIN_VARIANT (TREE_TYPE (v0
)) != TYPE_MAIN_VARIANT (TREE_TYPE (v1
)))
2405 error_at (loc
, "__builtin_shuffle argument vectors must be of "
2407 return error_mark_node
;
2410 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (v0
))
2411 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
))
2412 && TYPE_VECTOR_SUBPARTS (TREE_TYPE (v1
))
2413 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
)))
2416 error_at (loc
, "__builtin_shuffle number of elements of the "
2417 "argument vector(s) and the mask vector should "
2419 return error_mark_node
;
2422 if (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (v0
))))
2423 != GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (mask
)))))
2426 error_at (loc
, "__builtin_shuffle argument vector(s) inner type "
2427 "must have the same size as inner type of the mask");
2428 return error_mark_node
;
2431 if (!c_dialect_cxx ())
2433 /* Avoid C_MAYBE_CONST_EXPRs inside VEC_PERM_EXPR. */
2434 v0
= c_fully_fold (v0
, false, &maybe_const
);
2435 wrap
&= maybe_const
;
2438 v1
= v0
= save_expr (v0
);
2441 v1
= c_fully_fold (v1
, false, &maybe_const
);
2442 wrap
&= maybe_const
;
2445 mask
= c_fully_fold (mask
, false, &maybe_const
);
2446 wrap
&= maybe_const
;
2448 else if (two_arguments
)
2449 v1
= v0
= save_expr (v0
);
2451 ret
= build3_loc (loc
, VEC_PERM_EXPR
, TREE_TYPE (v0
), v0
, v1
, mask
);
2453 if (!c_dialect_cxx () && !wrap
)
2454 ret
= c_wrap_maybe_const (ret
, true);
2459 /* Like tree.c:get_narrower, but retain conversion from C++0x scoped enum
2460 to integral type. */
2463 c_common_get_narrower (tree op
, int *unsignedp_ptr
)
2465 op
= get_narrower (op
, unsignedp_ptr
);
2467 if (TREE_CODE (TREE_TYPE (op
)) == ENUMERAL_TYPE
2468 && ENUM_IS_SCOPED (TREE_TYPE (op
)))
2470 /* C++0x scoped enumerations don't implicitly convert to integral
2471 type; if we stripped an explicit conversion to a larger type we
2472 need to replace it so common_type will still work. */
2473 tree type
= c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op
)),
2474 TYPE_UNSIGNED (TREE_TYPE (op
)));
2475 op
= fold_convert (type
, op
);
2480 /* This is a helper function of build_binary_op.
2482 For certain operations if both args were extended from the same
2483 smaller type, do the arithmetic in that type and then extend.
2485 BITWISE indicates a bitwise operation.
2486 For them, this optimization is safe only if
2487 both args are zero-extended or both are sign-extended.
2488 Otherwise, we might change the result.
2489 Eg, (short)-1 | (unsigned short)-1 is (int)-1
2490 but calculated in (unsigned short) it would be (unsigned short)-1.
2493 shorten_binary_op (tree result_type
, tree op0
, tree op1
, bool bitwise
)
2495 int unsigned0
, unsigned1
;
2500 /* Cast OP0 and OP1 to RESULT_TYPE. Doing so prevents
2501 excessive narrowing when we call get_narrower below. For
2502 example, suppose that OP0 is of unsigned int extended
2503 from signed char and that RESULT_TYPE is long long int.
2504 If we explicitly cast OP0 to RESULT_TYPE, OP0 would look
2507 (long long int) (unsigned int) signed_char
2509 which get_narrower would narrow down to
2511 (unsigned int) signed char
2513 If we do not cast OP0 first, get_narrower would return
2514 signed_char, which is inconsistent with the case of the
2516 op0
= convert (result_type
, op0
);
2517 op1
= convert (result_type
, op1
);
2519 arg0
= c_common_get_narrower (op0
, &unsigned0
);
2520 arg1
= c_common_get_narrower (op1
, &unsigned1
);
2522 /* UNS is 1 if the operation to be done is an unsigned one. */
2523 uns
= TYPE_UNSIGNED (result_type
);
2525 /* Handle the case that OP0 (or OP1) does not *contain* a conversion
2526 but it *requires* conversion to FINAL_TYPE. */
2528 if ((TYPE_PRECISION (TREE_TYPE (op0
))
2529 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2530 && TREE_TYPE (op0
) != result_type
)
2531 unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2532 if ((TYPE_PRECISION (TREE_TYPE (op1
))
2533 == TYPE_PRECISION (TREE_TYPE (arg1
)))
2534 && TREE_TYPE (op1
) != result_type
)
2535 unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2537 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
2539 /* For bitwise operations, signedness of nominal type
2540 does not matter. Consider only how operands were extended. */
2544 /* Note that in all three cases below we refrain from optimizing
2545 an unsigned operation on sign-extended args.
2546 That would not be valid. */
2548 /* Both args variable: if both extended in same way
2549 from same width, do it in that width.
2550 Do it unsigned if args were zero-extended. */
2551 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
2552 < TYPE_PRECISION (result_type
))
2553 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2554 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2555 && unsigned0
== unsigned1
2556 && (unsigned0
|| !uns
))
2557 return c_common_signed_or_unsigned_type
2558 (unsigned0
, common_type (TREE_TYPE (arg0
), TREE_TYPE (arg1
)));
2560 else if (TREE_CODE (arg0
) == INTEGER_CST
2561 && (unsigned1
|| !uns
)
2562 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2563 < TYPE_PRECISION (result_type
))
2565 = c_common_signed_or_unsigned_type (unsigned1
,
2567 && !POINTER_TYPE_P (type
)
2568 && int_fits_type_p (arg0
, type
))
2571 else if (TREE_CODE (arg1
) == INTEGER_CST
2572 && (unsigned0
|| !uns
)
2573 && (TYPE_PRECISION (TREE_TYPE (arg0
))
2574 < TYPE_PRECISION (result_type
))
2576 = c_common_signed_or_unsigned_type (unsigned0
,
2578 && !POINTER_TYPE_P (type
)
2579 && int_fits_type_p (arg1
, type
))
2585 /* Checks if expression EXPR of real/integer type cannot be converted
2586 to the real/integer type TYPE. Function returns non-zero when:
2587 * EXPR is a constant which cannot be exactly converted to TYPE.
2588 * EXPR is not a constant and size of EXPR's type > than size of TYPE,
2589 for EXPR type and TYPE being both integers or both real.
2590 * EXPR is not a constant of real type and TYPE is an integer.
2591 * EXPR is not a constant of integer type which cannot be
2592 exactly converted to real type.
2593 Function allows conversions between types of different signedness and
2594 can return SAFE_CONVERSION (zero) in that case. Function can produce
2595 signedness warnings if PRODUCE_WARNS is true. */
2597 enum conversion_safety
2598 unsafe_conversion_p (location_t loc
, tree type
, tree expr
, bool produce_warns
)
2600 enum conversion_safety give_warning
= SAFE_CONVERSION
; /* is 0 or false */
2601 tree expr_type
= TREE_TYPE (expr
);
2602 loc
= expansion_point_location_if_in_system_header (loc
);
2604 if (TREE_CODE (expr
) == REAL_CST
|| TREE_CODE (expr
) == INTEGER_CST
)
2606 /* Warn for real constant that is not an exact integer converted
2608 if (TREE_CODE (expr_type
) == REAL_TYPE
2609 && TREE_CODE (type
) == INTEGER_TYPE
)
2611 if (!real_isinteger (TREE_REAL_CST_PTR (expr
), TYPE_MODE (expr_type
)))
2612 give_warning
= UNSAFE_REAL
;
2614 /* Warn for an integer constant that does not fit into integer type. */
2615 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2616 && TREE_CODE (type
) == INTEGER_TYPE
2617 && !int_fits_type_p (expr
, type
))
2619 if (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)
2620 && tree_int_cst_sgn (expr
) < 0)
2623 warning_at (loc
, OPT_Wsign_conversion
, "negative integer"
2624 " implicitly converted to unsigned type");
2626 else if (!TYPE_UNSIGNED (type
) && TYPE_UNSIGNED (expr_type
))
2629 warning_at (loc
, OPT_Wsign_conversion
, "conversion of unsigned"
2630 " constant value to negative integer");
2633 give_warning
= UNSAFE_OTHER
;
2635 else if (TREE_CODE (type
) == REAL_TYPE
)
2637 /* Warn for an integer constant that does not fit into real type. */
2638 if (TREE_CODE (expr_type
) == INTEGER_TYPE
)
2640 REAL_VALUE_TYPE a
= real_value_from_int_cst (0, expr
);
2641 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2642 give_warning
= UNSAFE_REAL
;
2644 /* Warn for a real constant that does not fit into a smaller
2646 else if (TREE_CODE (expr_type
) == REAL_TYPE
2647 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2649 REAL_VALUE_TYPE a
= TREE_REAL_CST (expr
);
2650 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2651 give_warning
= UNSAFE_REAL
;
2657 /* Warn for real types converted to integer types. */
2658 if (TREE_CODE (expr_type
) == REAL_TYPE
2659 && TREE_CODE (type
) == INTEGER_TYPE
)
2660 give_warning
= UNSAFE_REAL
;
2662 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2663 && TREE_CODE (type
) == INTEGER_TYPE
)
2665 /* Don't warn about unsigned char y = 0xff, x = (int) y; */
2666 expr
= get_unwidened (expr
, 0);
2667 expr_type
= TREE_TYPE (expr
);
2669 /* Don't warn for short y; short x = ((int)y & 0xff); */
2670 if (TREE_CODE (expr
) == BIT_AND_EXPR
2671 || TREE_CODE (expr
) == BIT_IOR_EXPR
2672 || TREE_CODE (expr
) == BIT_XOR_EXPR
)
2674 /* If both args were extended from a shortest type,
2675 use that type if that is safe. */
2676 expr_type
= shorten_binary_op (expr_type
,
2677 TREE_OPERAND (expr
, 0),
2678 TREE_OPERAND (expr
, 1),
2681 if (TREE_CODE (expr
) == BIT_AND_EXPR
)
2683 tree op0
= TREE_OPERAND (expr
, 0);
2684 tree op1
= TREE_OPERAND (expr
, 1);
2685 bool unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2686 bool unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2688 /* If one of the operands is a non-negative constant
2689 that fits in the target type, then the type of the
2690 other operand does not matter. */
2691 if ((TREE_CODE (op0
) == INTEGER_CST
2692 && int_fits_type_p (op0
, c_common_signed_type (type
))
2693 && int_fits_type_p (op0
, c_common_unsigned_type (type
)))
2694 || (TREE_CODE (op1
) == INTEGER_CST
2695 && int_fits_type_p (op1
, c_common_signed_type (type
))
2696 && int_fits_type_p (op1
,
2697 c_common_unsigned_type (type
))))
2698 return SAFE_CONVERSION
;
2699 /* If constant is unsigned and fits in the target
2700 type, then the result will also fit. */
2701 else if ((TREE_CODE (op0
) == INTEGER_CST
2703 && int_fits_type_p (op0
, type
))
2704 || (TREE_CODE (op1
) == INTEGER_CST
2706 && int_fits_type_p (op1
, type
)))
2707 return SAFE_CONVERSION
;
2710 /* Warn for integer types converted to smaller integer types. */
2711 if (TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2712 give_warning
= UNSAFE_OTHER
;
2714 /* When they are the same width but different signedness,
2715 then the value may change. */
2716 else if (((TYPE_PRECISION (type
) == TYPE_PRECISION (expr_type
)
2717 && TYPE_UNSIGNED (expr_type
) != TYPE_UNSIGNED (type
))
2718 /* Even when converted to a bigger type, if the type is
2719 unsigned but expr is signed, then negative values
2721 || (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)))
2723 warning_at (loc
, OPT_Wsign_conversion
, "conversion to %qT from %qT "
2724 "may change the sign of the result",
2728 /* Warn for integer types converted to real types if and only if
2729 all the range of values of the integer type cannot be
2730 represented by the real type. */
2731 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2732 && TREE_CODE (type
) == REAL_TYPE
)
2734 tree type_low_bound
, type_high_bound
;
2735 REAL_VALUE_TYPE real_low_bound
, real_high_bound
;
2737 /* Don't warn about char y = 0xff; float x = (int) y; */
2738 expr
= get_unwidened (expr
, 0);
2739 expr_type
= TREE_TYPE (expr
);
2741 type_low_bound
= TYPE_MIN_VALUE (expr_type
);
2742 type_high_bound
= TYPE_MAX_VALUE (expr_type
);
2743 real_low_bound
= real_value_from_int_cst (0, type_low_bound
);
2744 real_high_bound
= real_value_from_int_cst (0, type_high_bound
);
2746 if (!exact_real_truncate (TYPE_MODE (type
), &real_low_bound
)
2747 || !exact_real_truncate (TYPE_MODE (type
), &real_high_bound
))
2748 give_warning
= UNSAFE_OTHER
;
2751 /* Warn for real types converted to smaller real types. */
2752 else if (TREE_CODE (expr_type
) == REAL_TYPE
2753 && TREE_CODE (type
) == REAL_TYPE
2754 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2755 give_warning
= UNSAFE_REAL
;
2758 return give_warning
;
2761 /* Warns if the conversion of EXPR to TYPE may alter a value.
2762 This is a helper function for warnings_for_convert_and_check. */
2765 conversion_warning (location_t loc
, tree type
, tree expr
)
2767 tree expr_type
= TREE_TYPE (expr
);
2768 enum conversion_safety conversion_kind
;
2770 if (!warn_conversion
&& !warn_sign_conversion
&& !warn_float_conversion
)
2773 /* This may happen, because for LHS op= RHS we preevaluate
2774 RHS and create C_MAYBE_CONST_EXPR <SAVE_EXPR <RHS>>, which
2775 means we could no longer see the code of the EXPR. */
2776 if (TREE_CODE (expr
) == C_MAYBE_CONST_EXPR
)
2777 expr
= C_MAYBE_CONST_EXPR_EXPR (expr
);
2778 if (TREE_CODE (expr
) == SAVE_EXPR
)
2779 expr
= TREE_OPERAND (expr
, 0);
2781 switch (TREE_CODE (expr
))
2789 case TRUTH_ANDIF_EXPR
:
2790 case TRUTH_ORIF_EXPR
:
2791 case TRUTH_AND_EXPR
:
2793 case TRUTH_XOR_EXPR
:
2794 case TRUTH_NOT_EXPR
:
2795 /* Conversion from boolean to a signed:1 bit-field (which only
2796 can hold the values 0 and -1) doesn't lose information - but
2797 it does change the value. */
2798 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
2799 warning_at (loc
, OPT_Wconversion
,
2800 "conversion to %qT from boolean expression", type
);
2805 conversion_kind
= unsafe_conversion_p (loc
, type
, expr
, true);
2806 if (conversion_kind
== UNSAFE_REAL
)
2807 warning_at (loc
, OPT_Wfloat_conversion
,
2808 "conversion to %qT alters %qT constant value",
2810 else if (conversion_kind
)
2811 warning_at (loc
, OPT_Wconversion
,
2812 "conversion to %qT alters %qT constant value",
2818 /* In case of COND_EXPR, we do not care about the type of
2819 COND_EXPR, only about the conversion of each operand. */
2820 tree op1
= TREE_OPERAND (expr
, 1);
2821 tree op2
= TREE_OPERAND (expr
, 2);
2823 conversion_warning (loc
, type
, op1
);
2824 conversion_warning (loc
, type
, op2
);
2828 default: /* 'expr' is not a constant. */
2829 conversion_kind
= unsafe_conversion_p (loc
, type
, expr
, true);
2830 if (conversion_kind
== UNSAFE_REAL
)
2831 warning_at (loc
, OPT_Wfloat_conversion
,
2832 "conversion to %qT from %qT may alter its value",
2834 else if (conversion_kind
)
2835 warning_at (loc
, OPT_Wconversion
,
2836 "conversion to %qT from %qT may alter its value",
2841 /* Produce warnings after a conversion. RESULT is the result of
2842 converting EXPR to TYPE. This is a helper function for
2843 convert_and_check and cp_convert_and_check. */
2846 warnings_for_convert_and_check (location_t loc
, tree type
, tree expr
,
2849 loc
= expansion_point_location_if_in_system_header (loc
);
2851 if (TREE_CODE (expr
) == INTEGER_CST
2852 && (TREE_CODE (type
) == INTEGER_TYPE
2853 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2854 && !int_fits_type_p (expr
, type
))
2856 /* Do not diagnose overflow in a constant expression merely
2857 because a conversion overflowed. */
2858 if (TREE_OVERFLOW (result
))
2859 TREE_OVERFLOW (result
) = TREE_OVERFLOW (expr
);
2861 if (TYPE_UNSIGNED (type
))
2863 /* This detects cases like converting -129 or 256 to
2865 if (!int_fits_type_p (expr
, c_common_signed_type (type
)))
2866 warning_at (loc
, OPT_Woverflow
,
2867 "large integer implicitly truncated to unsigned type");
2869 conversion_warning (loc
, type
, expr
);
2871 else if (!int_fits_type_p (expr
, c_common_unsigned_type (type
)))
2872 warning_at (loc
, OPT_Woverflow
,
2873 "overflow in implicit constant conversion");
2874 /* No warning for converting 0x80000000 to int. */
2876 && (TREE_CODE (TREE_TYPE (expr
)) != INTEGER_TYPE
2877 || TYPE_PRECISION (TREE_TYPE (expr
))
2878 != TYPE_PRECISION (type
)))
2879 warning_at (loc
, OPT_Woverflow
,
2880 "overflow in implicit constant conversion");
2883 conversion_warning (loc
, type
, expr
);
2885 else if ((TREE_CODE (result
) == INTEGER_CST
2886 || TREE_CODE (result
) == FIXED_CST
) && TREE_OVERFLOW (result
))
2887 warning_at (loc
, OPT_Woverflow
,
2888 "overflow in implicit constant conversion");
2890 conversion_warning (loc
, type
, expr
);
2894 /* Convert EXPR to TYPE, warning about conversion problems with constants.
2895 Invoke this function on every expression that is converted implicitly,
2896 i.e. because of language rules and not because of an explicit cast. */
2899 convert_and_check (location_t loc
, tree type
, tree expr
)
2902 tree expr_for_warning
;
2904 /* Convert from a value with possible excess precision rather than
2905 via the semantic type, but do not warn about values not fitting
2906 exactly in the semantic type. */
2907 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
2909 tree orig_type
= TREE_TYPE (expr
);
2910 expr
= TREE_OPERAND (expr
, 0);
2911 expr_for_warning
= convert (orig_type
, expr
);
2912 if (orig_type
== type
)
2913 return expr_for_warning
;
2916 expr_for_warning
= expr
;
2918 if (TREE_TYPE (expr
) == type
)
2921 result
= convert (type
, expr
);
2923 if (c_inhibit_evaluation_warnings
== 0
2924 && !TREE_OVERFLOW_P (expr
)
2925 && result
!= error_mark_node
)
2926 warnings_for_convert_and_check (loc
, type
, expr_for_warning
, result
);
2931 /* A node in a list that describes references to variables (EXPR), which are
2932 either read accesses if WRITER is zero, or write accesses, in which case
2933 WRITER is the parent of EXPR. */
2940 /* Used to implement a cache the results of a call to verify_tree. We only
2941 use this for SAVE_EXPRs. */
2944 struct tlist_cache
*next
;
2945 struct tlist
*cache_before_sp
;
2946 struct tlist
*cache_after_sp
;
2950 /* Obstack to use when allocating tlist structures, and corresponding
2952 static struct obstack tlist_obstack
;
2953 static char *tlist_firstobj
= 0;
2955 /* Keep track of the identifiers we've warned about, so we can avoid duplicate
2957 static struct tlist
*warned_ids
;
2958 /* SAVE_EXPRs need special treatment. We process them only once and then
2959 cache the results. */
2960 static struct tlist_cache
*save_expr_cache
;
2962 static void add_tlist (struct tlist
**, struct tlist
*, tree
, int);
2963 static void merge_tlist (struct tlist
**, struct tlist
*, int);
2964 static void verify_tree (tree
, struct tlist
**, struct tlist
**, tree
);
2965 static int warning_candidate_p (tree
);
2966 static bool candidate_equal_p (const_tree
, const_tree
);
2967 static void warn_for_collisions (struct tlist
*);
2968 static void warn_for_collisions_1 (tree
, tree
, struct tlist
*, int);
2969 static struct tlist
*new_tlist (struct tlist
*, tree
, tree
);
2971 /* Create a new struct tlist and fill in its fields. */
2972 static struct tlist
*
2973 new_tlist (struct tlist
*next
, tree t
, tree writer
)
2976 l
= XOBNEW (&tlist_obstack
, struct tlist
);
2983 /* Add duplicates of the nodes found in ADD to the list *TO. If EXCLUDE_WRITER
2984 is nonnull, we ignore any node we find which has a writer equal to it. */
2987 add_tlist (struct tlist
**to
, struct tlist
*add
, tree exclude_writer
, int copy
)
2991 struct tlist
*next
= add
->next
;
2994 if (!exclude_writer
|| !candidate_equal_p (add
->writer
, exclude_writer
))
2995 *to
= copy
? new_tlist (*to
, add
->expr
, add
->writer
) : add
;
3000 /* Merge the nodes of ADD into TO. This merging process is done so that for
3001 each variable that already exists in TO, no new node is added; however if
3002 there is a write access recorded in ADD, and an occurrence on TO is only
3003 a read access, then the occurrence in TO will be modified to record the
3007 merge_tlist (struct tlist
**to
, struct tlist
*add
, int copy
)
3009 struct tlist
**end
= to
;
3012 end
= &(*end
)->next
;
3018 struct tlist
*next
= add
->next
;
3020 for (tmp2
= *to
; tmp2
; tmp2
= tmp2
->next
)
3021 if (candidate_equal_p (tmp2
->expr
, add
->expr
))
3025 tmp2
->writer
= add
->writer
;
3029 *end
= copy
? new_tlist (NULL
, add
->expr
, add
->writer
) : add
;
3030 end
= &(*end
)->next
;
3037 /* WRITTEN is a variable, WRITER is its parent. Warn if any of the variable
3038 references in list LIST conflict with it, excluding reads if ONLY writers
3042 warn_for_collisions_1 (tree written
, tree writer
, struct tlist
*list
,
3047 /* Avoid duplicate warnings. */
3048 for (tmp
= warned_ids
; tmp
; tmp
= tmp
->next
)
3049 if (candidate_equal_p (tmp
->expr
, written
))
3054 if (candidate_equal_p (list
->expr
, written
)
3055 && !candidate_equal_p (list
->writer
, writer
)
3056 && (!only_writes
|| list
->writer
))
3058 warned_ids
= new_tlist (warned_ids
, written
, NULL_TREE
);
3059 warning_at (EXPR_LOC_OR_LOC (writer
, input_location
),
3060 OPT_Wsequence_point
, "operation on %qE may be undefined",
3067 /* Given a list LIST of references to variables, find whether any of these
3068 can cause conflicts due to missing sequence points. */
3071 warn_for_collisions (struct tlist
*list
)
3075 for (tmp
= list
; tmp
; tmp
= tmp
->next
)
3078 warn_for_collisions_1 (tmp
->expr
, tmp
->writer
, list
, 0);
3082 /* Return nonzero if X is a tree that can be verified by the sequence point
3085 warning_candidate_p (tree x
)
3087 if (DECL_P (x
) && DECL_ARTIFICIAL (x
))
3090 if (TREE_CODE (x
) == BLOCK
)
3093 /* VOID_TYPE_P (TREE_TYPE (x)) is workaround for cp/tree.c
3094 (lvalue_p) crash on TRY/CATCH. */
3095 if (TREE_TYPE (x
) == NULL_TREE
|| VOID_TYPE_P (TREE_TYPE (x
)))
3101 /* No point to track non-const calls, they will never satisfy
3103 if (TREE_CODE (x
) == CALL_EXPR
&& (call_expr_flags (x
) & ECF_CONST
) == 0)
3106 if (TREE_CODE (x
) == STRING_CST
)
3112 /* Return nonzero if X and Y appear to be the same candidate (or NULL) */
3114 candidate_equal_p (const_tree x
, const_tree y
)
3116 return (x
== y
) || (x
&& y
&& operand_equal_p (x
, y
, 0));
3119 /* Walk the tree X, and record accesses to variables. If X is written by the
3120 parent tree, WRITER is the parent.
3121 We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP. If this
3122 expression or its only operand forces a sequence point, then everything up
3123 to the sequence point is stored in PBEFORE_SP. Everything else gets stored
3125 Once we return, we will have emitted warnings if any subexpression before
3126 such a sequence point could be undefined. On a higher level, however, the
3127 sequence point may not be relevant, and we'll merge the two lists.
3129 Example: (b++, a) + b;
3130 The call that processes the COMPOUND_EXPR will store the increment of B
3131 in PBEFORE_SP, and the use of A in PNO_SP. The higher-level call that
3132 processes the PLUS_EXPR will need to merge the two lists so that
3133 eventually, all accesses end up on the same list (and we'll warn about the
3134 unordered subexpressions b++ and b.
3136 A note on merging. If we modify the former example so that our expression
3139 care must be taken not simply to add all three expressions into the final
3140 PNO_SP list. The function merge_tlist takes care of that by merging the
3141 before-SP list of the COMPOUND_EXPR into its after-SP list in a special
3142 way, so that no more than one access to B is recorded. */
3145 verify_tree (tree x
, struct tlist
**pbefore_sp
, struct tlist
**pno_sp
,
3148 struct tlist
*tmp_before
, *tmp_nosp
, *tmp_list2
, *tmp_list3
;
3149 enum tree_code code
;
3150 enum tree_code_class cl
;
3152 /* X may be NULL if it is the operand of an empty statement expression
3158 code
= TREE_CODE (x
);
3159 cl
= TREE_CODE_CLASS (code
);
3161 if (warning_candidate_p (x
))
3162 *pno_sp
= new_tlist (*pno_sp
, x
, writer
);
3171 case TRUTH_ANDIF_EXPR
:
3172 case TRUTH_ORIF_EXPR
:
3173 tmp_before
= tmp_nosp
= tmp_list3
= 0;
3174 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3175 warn_for_collisions (tmp_nosp
);
3176 merge_tlist (pbefore_sp
, tmp_before
, 0);
3177 merge_tlist (pbefore_sp
, tmp_nosp
, 0);
3178 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, pno_sp
, NULL_TREE
);
3179 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3183 tmp_before
= tmp_list2
= 0;
3184 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_list2
, NULL_TREE
);
3185 warn_for_collisions (tmp_list2
);
3186 merge_tlist (pbefore_sp
, tmp_before
, 0);
3187 merge_tlist (pbefore_sp
, tmp_list2
, 0);
3189 tmp_list3
= tmp_nosp
= 0;
3190 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, &tmp_nosp
, NULL_TREE
);
3191 warn_for_collisions (tmp_nosp
);
3192 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3194 tmp_list3
= tmp_list2
= 0;
3195 verify_tree (TREE_OPERAND (x
, 2), &tmp_list3
, &tmp_list2
, NULL_TREE
);
3196 warn_for_collisions (tmp_list2
);
3197 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3198 /* Rather than add both tmp_nosp and tmp_list2, we have to merge the
3199 two first, to avoid warning for (a ? b++ : b++). */
3200 merge_tlist (&tmp_nosp
, tmp_list2
, 0);
3201 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3204 case PREDECREMENT_EXPR
:
3205 case PREINCREMENT_EXPR
:
3206 case POSTDECREMENT_EXPR
:
3207 case POSTINCREMENT_EXPR
:
3208 verify_tree (TREE_OPERAND (x
, 0), pno_sp
, pno_sp
, x
);
3212 tmp_before
= tmp_nosp
= tmp_list3
= 0;
3213 verify_tree (TREE_OPERAND (x
, 1), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3214 verify_tree (TREE_OPERAND (x
, 0), &tmp_list3
, &tmp_list3
, x
);
3215 /* Expressions inside the LHS are not ordered wrt. the sequence points
3216 in the RHS. Example:
3218 Despite the fact that the modification of "a" is in the before_sp
3219 list (tmp_before), it conflicts with the use of "a" in the LHS.
3220 We can handle this by adding the contents of tmp_list3
3221 to those of tmp_before, and redoing the collision warnings for that
3223 add_tlist (&tmp_before
, tmp_list3
, x
, 1);
3224 warn_for_collisions (tmp_before
);
3225 /* Exclude the LHS itself here; we first have to merge it into the
3226 tmp_nosp list. This is done to avoid warning for "a = a"; if we
3227 didn't exclude the LHS, we'd get it twice, once as a read and once
3229 add_tlist (pno_sp
, tmp_list3
, x
, 0);
3230 warn_for_collisions_1 (TREE_OPERAND (x
, 0), x
, tmp_nosp
, 1);
3232 merge_tlist (pbefore_sp
, tmp_before
, 0);
3233 if (warning_candidate_p (TREE_OPERAND (x
, 0)))
3234 merge_tlist (&tmp_nosp
, new_tlist (NULL
, TREE_OPERAND (x
, 0), x
), 0);
3235 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 1);
3239 /* We need to warn about conflicts among arguments and conflicts between
3240 args and the function address. Side effects of the function address,
3241 however, are not ordered by the sequence point of the call. */
3243 call_expr_arg_iterator iter
;
3245 tmp_before
= tmp_nosp
= 0;
3246 verify_tree (CALL_EXPR_FN (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3247 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, x
)
3249 tmp_list2
= tmp_list3
= 0;
3250 verify_tree (arg
, &tmp_list2
, &tmp_list3
, NULL_TREE
);
3251 merge_tlist (&tmp_list3
, tmp_list2
, 0);
3252 add_tlist (&tmp_before
, tmp_list3
, NULL_TREE
, 0);
3254 add_tlist (&tmp_before
, tmp_nosp
, NULL_TREE
, 0);
3255 warn_for_collisions (tmp_before
);
3256 add_tlist (pbefore_sp
, tmp_before
, NULL_TREE
, 0);
3261 /* Scan all the list, e.g. indices of multi dimensional array. */
3264 tmp_before
= tmp_nosp
= 0;
3265 verify_tree (TREE_VALUE (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3266 merge_tlist (&tmp_nosp
, tmp_before
, 0);
3267 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3274 struct tlist_cache
*t
;
3275 for (t
= save_expr_cache
; t
; t
= t
->next
)
3276 if (candidate_equal_p (t
->expr
, x
))
3281 t
= XOBNEW (&tlist_obstack
, struct tlist_cache
);
3282 t
->next
= save_expr_cache
;
3284 save_expr_cache
= t
;
3286 tmp_before
= tmp_nosp
= 0;
3287 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3288 warn_for_collisions (tmp_nosp
);
3291 merge_tlist (&tmp_list3
, tmp_nosp
, 0);
3292 t
->cache_before_sp
= tmp_before
;
3293 t
->cache_after_sp
= tmp_list3
;
3295 merge_tlist (pbefore_sp
, t
->cache_before_sp
, 1);
3296 add_tlist (pno_sp
, t
->cache_after_sp
, NULL_TREE
, 1);
3301 x
= TREE_OPERAND (x
, 0);
3308 /* For other expressions, simply recurse on their operands.
3309 Manual tail recursion for unary expressions.
3310 Other non-expressions need not be processed. */
3311 if (cl
== tcc_unary
)
3313 x
= TREE_OPERAND (x
, 0);
3317 else if (IS_EXPR_CODE_CLASS (cl
))
3320 int max
= TREE_OPERAND_LENGTH (x
);
3321 for (lp
= 0; lp
< max
; lp
++)
3323 tmp_before
= tmp_nosp
= 0;
3324 verify_tree (TREE_OPERAND (x
, lp
), &tmp_before
, &tmp_nosp
, 0);
3325 merge_tlist (&tmp_nosp
, tmp_before
, 0);
3326 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3333 /* Try to warn for undefined behavior in EXPR due to missing sequence
3337 verify_sequence_points (tree expr
)
3339 struct tlist
*before_sp
= 0, *after_sp
= 0;
3342 save_expr_cache
= 0;
3343 if (tlist_firstobj
== 0)
3345 gcc_obstack_init (&tlist_obstack
);
3346 tlist_firstobj
= (char *) obstack_alloc (&tlist_obstack
, 0);
3349 verify_tree (expr
, &before_sp
, &after_sp
, 0);
3350 warn_for_collisions (after_sp
);
3351 obstack_free (&tlist_obstack
, tlist_firstobj
);
3354 /* Validate the expression after `case' and apply default promotions. */
3357 check_case_value (location_t loc
, tree value
)
3359 if (value
== NULL_TREE
)
3362 if (TREE_CODE (value
) == INTEGER_CST
)
3363 /* Promote char or short to int. */
3364 value
= perform_integral_promotions (value
);
3365 else if (value
!= error_mark_node
)
3367 error_at (loc
, "case label does not reduce to an integer constant");
3368 value
= error_mark_node
;
3371 constant_expression_warning (value
);
3376 /* See if the case values LOW and HIGH are in the range of the original
3377 type (i.e. before the default conversion to int) of the switch testing
3379 TYPE is the promoted type of the testing expression, and ORIG_TYPE is
3380 the type before promoting it. CASE_LOW_P is a pointer to the lower
3381 bound of the case label, and CASE_HIGH_P is the upper bound or NULL
3382 if the case is not a case range.
3383 The caller has to make sure that we are not called with NULL for
3384 CASE_LOW_P (i.e. the default case).
3385 Returns true if the case label is in range of ORIG_TYPE (saturated or
3386 untouched) or false if the label is out of range. */
3389 check_case_bounds (location_t loc
, tree type
, tree orig_type
,
3390 tree
*case_low_p
, tree
*case_high_p
)
3392 tree min_value
, max_value
;
3393 tree case_low
= *case_low_p
;
3394 tree case_high
= case_high_p
? *case_high_p
: case_low
;
3396 /* If there was a problem with the original type, do nothing. */
3397 if (orig_type
== error_mark_node
)
3400 min_value
= TYPE_MIN_VALUE (orig_type
);
3401 max_value
= TYPE_MAX_VALUE (orig_type
);
3403 /* Case label is less than minimum for type. */
3404 if (tree_int_cst_compare (case_low
, min_value
) < 0
3405 && tree_int_cst_compare (case_high
, min_value
) < 0)
3407 warning_at (loc
, 0, "case label value is less than minimum value "
3412 /* Case value is greater than maximum for type. */
3413 if (tree_int_cst_compare (case_low
, max_value
) > 0
3414 && tree_int_cst_compare (case_high
, max_value
) > 0)
3416 warning_at (loc
, 0, "case label value exceeds maximum value for type");
3420 /* Saturate lower case label value to minimum. */
3421 if (tree_int_cst_compare (case_high
, min_value
) >= 0
3422 && tree_int_cst_compare (case_low
, min_value
) < 0)
3424 warning_at (loc
, 0, "lower value in case label range"
3425 " less than minimum value for type");
3426 case_low
= min_value
;
3429 /* Saturate upper case label value to maximum. */
3430 if (tree_int_cst_compare (case_low
, max_value
) <= 0
3431 && tree_int_cst_compare (case_high
, max_value
) > 0)
3433 warning_at (loc
, 0, "upper value in case label range"
3434 " exceeds maximum value for type");
3435 case_high
= max_value
;
3438 if (*case_low_p
!= case_low
)
3439 *case_low_p
= convert (type
, case_low
);
3440 if (case_high_p
&& *case_high_p
!= case_high
)
3441 *case_high_p
= convert (type
, case_high
);
3446 /* Return an integer type with BITS bits of precision,
3447 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
3450 c_common_type_for_size (unsigned int bits
, int unsignedp
)
3452 if (bits
== TYPE_PRECISION (integer_type_node
))
3453 return unsignedp
? unsigned_type_node
: integer_type_node
;
3455 if (bits
== TYPE_PRECISION (signed_char_type_node
))
3456 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3458 if (bits
== TYPE_PRECISION (short_integer_type_node
))
3459 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3461 if (bits
== TYPE_PRECISION (long_integer_type_node
))
3462 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3464 if (bits
== TYPE_PRECISION (long_long_integer_type_node
))
3465 return (unsignedp
? long_long_unsigned_type_node
3466 : long_long_integer_type_node
);
3468 if (int128_integer_type_node
3469 && bits
== TYPE_PRECISION (int128_integer_type_node
))
3470 return (unsignedp
? int128_unsigned_type_node
3471 : int128_integer_type_node
);
3473 if (bits
== TYPE_PRECISION (widest_integer_literal_type_node
))
3474 return (unsignedp
? widest_unsigned_literal_type_node
3475 : widest_integer_literal_type_node
);
3477 if (bits
<= TYPE_PRECISION (intQI_type_node
))
3478 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3480 if (bits
<= TYPE_PRECISION (intHI_type_node
))
3481 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3483 if (bits
<= TYPE_PRECISION (intSI_type_node
))
3484 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3486 if (bits
<= TYPE_PRECISION (intDI_type_node
))
3487 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3492 /* Return a fixed-point type that has at least IBIT ibits and FBIT fbits
3493 that is unsigned if UNSIGNEDP is nonzero, otherwise signed;
3494 and saturating if SATP is nonzero, otherwise not saturating. */
3497 c_common_fixed_point_type_for_size (unsigned int ibit
, unsigned int fbit
,
3498 int unsignedp
, int satp
)
3500 enum machine_mode mode
;
3502 mode
= unsignedp
? UQQmode
: QQmode
;
3504 mode
= unsignedp
? UHAmode
: HAmode
;
3506 for (; mode
!= VOIDmode
; mode
= GET_MODE_WIDER_MODE (mode
))
3507 if (GET_MODE_IBIT (mode
) >= ibit
&& GET_MODE_FBIT (mode
) >= fbit
)
3510 if (mode
== VOIDmode
|| !targetm
.scalar_mode_supported_p (mode
))
3512 sorry ("GCC cannot support operators with integer types and "
3513 "fixed-point types that have too many integral and "
3514 "fractional bits together");
3518 return c_common_type_for_mode (mode
, satp
);
3521 /* Used for communication between c_common_type_for_mode and
3522 c_register_builtin_type. */
3523 tree registered_builtin_types
;
3525 /* Return a data type that has machine mode MODE.
3526 If the mode is an integer,
3527 then UNSIGNEDP selects between signed and unsigned types.
3528 If the mode is a fixed-point mode,
3529 then UNSIGNEDP selects between saturating and nonsaturating types. */
3532 c_common_type_for_mode (enum machine_mode mode
, int unsignedp
)
3536 if (mode
== TYPE_MODE (integer_type_node
))
3537 return unsignedp
? unsigned_type_node
: integer_type_node
;
3539 if (mode
== TYPE_MODE (signed_char_type_node
))
3540 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3542 if (mode
== TYPE_MODE (short_integer_type_node
))
3543 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3545 if (mode
== TYPE_MODE (long_integer_type_node
))
3546 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3548 if (mode
== TYPE_MODE (long_long_integer_type_node
))
3549 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3551 if (int128_integer_type_node
3552 && mode
== TYPE_MODE (int128_integer_type_node
))
3553 return unsignedp
? int128_unsigned_type_node
: int128_integer_type_node
;
3555 if (mode
== TYPE_MODE (widest_integer_literal_type_node
))
3556 return unsignedp
? widest_unsigned_literal_type_node
3557 : widest_integer_literal_type_node
;
3560 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3563 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3566 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3569 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3571 #if HOST_BITS_PER_WIDE_INT >= 64
3572 if (mode
== TYPE_MODE (intTI_type_node
))
3573 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3576 if (mode
== TYPE_MODE (float_type_node
))
3577 return float_type_node
;
3579 if (mode
== TYPE_MODE (double_type_node
))
3580 return double_type_node
;
3582 if (mode
== TYPE_MODE (long_double_type_node
))
3583 return long_double_type_node
;
3585 if (mode
== TYPE_MODE (void_type_node
))
3586 return void_type_node
;
3588 if (mode
== TYPE_MODE (build_pointer_type (char_type_node
)))
3590 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3591 : make_signed_type (GET_MODE_PRECISION (mode
)));
3593 if (mode
== TYPE_MODE (build_pointer_type (integer_type_node
)))
3595 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3596 : make_signed_type (GET_MODE_PRECISION (mode
)));
3598 if (COMPLEX_MODE_P (mode
))
3600 enum machine_mode inner_mode
;
3603 if (mode
== TYPE_MODE (complex_float_type_node
))
3604 return complex_float_type_node
;
3605 if (mode
== TYPE_MODE (complex_double_type_node
))
3606 return complex_double_type_node
;
3607 if (mode
== TYPE_MODE (complex_long_double_type_node
))
3608 return complex_long_double_type_node
;
3610 if (mode
== TYPE_MODE (complex_integer_type_node
) && !unsignedp
)
3611 return complex_integer_type_node
;
3613 inner_mode
= GET_MODE_INNER (mode
);
3614 inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3615 if (inner_type
!= NULL_TREE
)
3616 return build_complex_type (inner_type
);
3618 else if (VECTOR_MODE_P (mode
))
3620 enum machine_mode inner_mode
= GET_MODE_INNER (mode
);
3621 tree inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3622 if (inner_type
!= NULL_TREE
)
3623 return build_vector_type_for_mode (inner_type
, mode
);
3626 if (mode
== TYPE_MODE (dfloat32_type_node
))
3627 return dfloat32_type_node
;
3628 if (mode
== TYPE_MODE (dfloat64_type_node
))
3629 return dfloat64_type_node
;
3630 if (mode
== TYPE_MODE (dfloat128_type_node
))
3631 return dfloat128_type_node
;
3633 if (ALL_SCALAR_FIXED_POINT_MODE_P (mode
))
3635 if (mode
== TYPE_MODE (short_fract_type_node
))
3636 return unsignedp
? sat_short_fract_type_node
: short_fract_type_node
;
3637 if (mode
== TYPE_MODE (fract_type_node
))
3638 return unsignedp
? sat_fract_type_node
: fract_type_node
;
3639 if (mode
== TYPE_MODE (long_fract_type_node
))
3640 return unsignedp
? sat_long_fract_type_node
: long_fract_type_node
;
3641 if (mode
== TYPE_MODE (long_long_fract_type_node
))
3642 return unsignedp
? sat_long_long_fract_type_node
3643 : long_long_fract_type_node
;
3645 if (mode
== TYPE_MODE (unsigned_short_fract_type_node
))
3646 return unsignedp
? sat_unsigned_short_fract_type_node
3647 : unsigned_short_fract_type_node
;
3648 if (mode
== TYPE_MODE (unsigned_fract_type_node
))
3649 return unsignedp
? sat_unsigned_fract_type_node
3650 : unsigned_fract_type_node
;
3651 if (mode
== TYPE_MODE (unsigned_long_fract_type_node
))
3652 return unsignedp
? sat_unsigned_long_fract_type_node
3653 : unsigned_long_fract_type_node
;
3654 if (mode
== TYPE_MODE (unsigned_long_long_fract_type_node
))
3655 return unsignedp
? sat_unsigned_long_long_fract_type_node
3656 : unsigned_long_long_fract_type_node
;
3658 if (mode
== TYPE_MODE (short_accum_type_node
))
3659 return unsignedp
? sat_short_accum_type_node
: short_accum_type_node
;
3660 if (mode
== TYPE_MODE (accum_type_node
))
3661 return unsignedp
? sat_accum_type_node
: accum_type_node
;
3662 if (mode
== TYPE_MODE (long_accum_type_node
))
3663 return unsignedp
? sat_long_accum_type_node
: long_accum_type_node
;
3664 if (mode
== TYPE_MODE (long_long_accum_type_node
))
3665 return unsignedp
? sat_long_long_accum_type_node
3666 : long_long_accum_type_node
;
3668 if (mode
== TYPE_MODE (unsigned_short_accum_type_node
))
3669 return unsignedp
? sat_unsigned_short_accum_type_node
3670 : unsigned_short_accum_type_node
;
3671 if (mode
== TYPE_MODE (unsigned_accum_type_node
))
3672 return unsignedp
? sat_unsigned_accum_type_node
3673 : unsigned_accum_type_node
;
3674 if (mode
== TYPE_MODE (unsigned_long_accum_type_node
))
3675 return unsignedp
? sat_unsigned_long_accum_type_node
3676 : unsigned_long_accum_type_node
;
3677 if (mode
== TYPE_MODE (unsigned_long_long_accum_type_node
))
3678 return unsignedp
? sat_unsigned_long_long_accum_type_node
3679 : unsigned_long_long_accum_type_node
;
3682 return unsignedp
? sat_qq_type_node
: qq_type_node
;
3684 return unsignedp
? sat_hq_type_node
: hq_type_node
;
3686 return unsignedp
? sat_sq_type_node
: sq_type_node
;
3688 return unsignedp
? sat_dq_type_node
: dq_type_node
;
3690 return unsignedp
? sat_tq_type_node
: tq_type_node
;
3692 if (mode
== UQQmode
)
3693 return unsignedp
? sat_uqq_type_node
: uqq_type_node
;
3694 if (mode
== UHQmode
)
3695 return unsignedp
? sat_uhq_type_node
: uhq_type_node
;
3696 if (mode
== USQmode
)
3697 return unsignedp
? sat_usq_type_node
: usq_type_node
;
3698 if (mode
== UDQmode
)
3699 return unsignedp
? sat_udq_type_node
: udq_type_node
;
3700 if (mode
== UTQmode
)
3701 return unsignedp
? sat_utq_type_node
: utq_type_node
;
3704 return unsignedp
? sat_ha_type_node
: ha_type_node
;
3706 return unsignedp
? sat_sa_type_node
: sa_type_node
;
3708 return unsignedp
? sat_da_type_node
: da_type_node
;
3710 return unsignedp
? sat_ta_type_node
: ta_type_node
;
3712 if (mode
== UHAmode
)
3713 return unsignedp
? sat_uha_type_node
: uha_type_node
;
3714 if (mode
== USAmode
)
3715 return unsignedp
? sat_usa_type_node
: usa_type_node
;
3716 if (mode
== UDAmode
)
3717 return unsignedp
? sat_uda_type_node
: uda_type_node
;
3718 if (mode
== UTAmode
)
3719 return unsignedp
? sat_uta_type_node
: uta_type_node
;
3722 for (t
= registered_builtin_types
; t
; t
= TREE_CHAIN (t
))
3723 if (TYPE_MODE (TREE_VALUE (t
)) == mode
3724 && !!unsignedp
== !!TYPE_UNSIGNED (TREE_VALUE (t
)))
3725 return TREE_VALUE (t
);
3731 c_common_unsigned_type (tree type
)
3733 return c_common_signed_or_unsigned_type (1, type
);
3736 /* Return a signed type the same as TYPE in other respects. */
3739 c_common_signed_type (tree type
)
3741 return c_common_signed_or_unsigned_type (0, type
);
3744 /* Return a type the same as TYPE except unsigned or
3745 signed according to UNSIGNEDP. */
3748 c_common_signed_or_unsigned_type (int unsignedp
, tree type
)
3752 /* This block of code emulates the behavior of the old
3753 c_common_unsigned_type. In particular, it returns
3754 long_unsigned_type_node if passed a long, even when a int would
3755 have the same size. This is necessary for warnings to work
3756 correctly in archs where sizeof(int) == sizeof(long) */
3758 type1
= TYPE_MAIN_VARIANT (type
);
3759 if (type1
== signed_char_type_node
|| type1
== char_type_node
|| type1
== unsigned_char_type_node
)
3760 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3761 if (type1
== integer_type_node
|| type1
== unsigned_type_node
)
3762 return unsignedp
? unsigned_type_node
: integer_type_node
;
3763 if (type1
== short_integer_type_node
|| type1
== short_unsigned_type_node
)
3764 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3765 if (type1
== long_integer_type_node
|| type1
== long_unsigned_type_node
)
3766 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3767 if (type1
== long_long_integer_type_node
|| type1
== long_long_unsigned_type_node
)
3768 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3769 if (int128_integer_type_node
3770 && (type1
== int128_integer_type_node
3771 || type1
== int128_unsigned_type_node
))
3772 return unsignedp
? int128_unsigned_type_node
: int128_integer_type_node
;
3773 if (type1
== widest_integer_literal_type_node
|| type1
== widest_unsigned_literal_type_node
)
3774 return unsignedp
? widest_unsigned_literal_type_node
: widest_integer_literal_type_node
;
3775 #if HOST_BITS_PER_WIDE_INT >= 64
3776 if (type1
== intTI_type_node
|| type1
== unsigned_intTI_type_node
)
3777 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3779 if (type1
== intDI_type_node
|| type1
== unsigned_intDI_type_node
)
3780 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3781 if (type1
== intSI_type_node
|| type1
== unsigned_intSI_type_node
)
3782 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3783 if (type1
== intHI_type_node
|| type1
== unsigned_intHI_type_node
)
3784 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3785 if (type1
== intQI_type_node
|| type1
== unsigned_intQI_type_node
)
3786 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3788 #define C_COMMON_FIXED_TYPES(NAME) \
3789 if (type1 == short_ ## NAME ## _type_node \
3790 || type1 == unsigned_short_ ## NAME ## _type_node) \
3791 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
3792 : short_ ## NAME ## _type_node; \
3793 if (type1 == NAME ## _type_node \
3794 || type1 == unsigned_ ## NAME ## _type_node) \
3795 return unsignedp ? unsigned_ ## NAME ## _type_node \
3796 : NAME ## _type_node; \
3797 if (type1 == long_ ## NAME ## _type_node \
3798 || type1 == unsigned_long_ ## NAME ## _type_node) \
3799 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
3800 : long_ ## NAME ## _type_node; \
3801 if (type1 == long_long_ ## NAME ## _type_node \
3802 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
3803 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
3804 : long_long_ ## NAME ## _type_node;
3806 #define C_COMMON_FIXED_MODE_TYPES(NAME) \
3807 if (type1 == NAME ## _type_node \
3808 || type1 == u ## NAME ## _type_node) \
3809 return unsignedp ? u ## NAME ## _type_node \
3810 : NAME ## _type_node;
3812 #define C_COMMON_FIXED_TYPES_SAT(NAME) \
3813 if (type1 == sat_ ## short_ ## NAME ## _type_node \
3814 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
3815 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
3816 : sat_ ## short_ ## NAME ## _type_node; \
3817 if (type1 == sat_ ## NAME ## _type_node \
3818 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
3819 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
3820 : sat_ ## NAME ## _type_node; \
3821 if (type1 == sat_ ## long_ ## NAME ## _type_node \
3822 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
3823 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
3824 : sat_ ## long_ ## NAME ## _type_node; \
3825 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
3826 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
3827 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
3828 : sat_ ## long_long_ ## NAME ## _type_node;
3830 #define C_COMMON_FIXED_MODE_TYPES_SAT(NAME) \
3831 if (type1 == sat_ ## NAME ## _type_node \
3832 || type1 == sat_ ## u ## NAME ## _type_node) \
3833 return unsignedp ? sat_ ## u ## NAME ## _type_node \
3834 : sat_ ## NAME ## _type_node;
3836 C_COMMON_FIXED_TYPES (fract
);
3837 C_COMMON_FIXED_TYPES_SAT (fract
);
3838 C_COMMON_FIXED_TYPES (accum
);
3839 C_COMMON_FIXED_TYPES_SAT (accum
);
3841 C_COMMON_FIXED_MODE_TYPES (qq
);
3842 C_COMMON_FIXED_MODE_TYPES (hq
);
3843 C_COMMON_FIXED_MODE_TYPES (sq
);
3844 C_COMMON_FIXED_MODE_TYPES (dq
);
3845 C_COMMON_FIXED_MODE_TYPES (tq
);
3846 C_COMMON_FIXED_MODE_TYPES_SAT (qq
);
3847 C_COMMON_FIXED_MODE_TYPES_SAT (hq
);
3848 C_COMMON_FIXED_MODE_TYPES_SAT (sq
);
3849 C_COMMON_FIXED_MODE_TYPES_SAT (dq
);
3850 C_COMMON_FIXED_MODE_TYPES_SAT (tq
);
3851 C_COMMON_FIXED_MODE_TYPES (ha
);
3852 C_COMMON_FIXED_MODE_TYPES (sa
);
3853 C_COMMON_FIXED_MODE_TYPES (da
);
3854 C_COMMON_FIXED_MODE_TYPES (ta
);
3855 C_COMMON_FIXED_MODE_TYPES_SAT (ha
);
3856 C_COMMON_FIXED_MODE_TYPES_SAT (sa
);
3857 C_COMMON_FIXED_MODE_TYPES_SAT (da
);
3858 C_COMMON_FIXED_MODE_TYPES_SAT (ta
);
3860 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
3861 the precision; they have precision set to match their range, but
3862 may use a wider mode to match an ABI. If we change modes, we may
3863 wind up with bad conversions. For INTEGER_TYPEs in C, must check
3864 the precision as well, so as to yield correct results for
3865 bit-field types. C++ does not have these separate bit-field
3866 types, and producing a signed or unsigned variant of an
3867 ENUMERAL_TYPE may cause other problems as well. */
3869 if (!INTEGRAL_TYPE_P (type
)
3870 || TYPE_UNSIGNED (type
) == unsignedp
)
3873 #define TYPE_OK(node) \
3874 (TYPE_MODE (type) == TYPE_MODE (node) \
3875 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
3876 if (TYPE_OK (signed_char_type_node
))
3877 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3878 if (TYPE_OK (integer_type_node
))
3879 return unsignedp
? unsigned_type_node
: integer_type_node
;
3880 if (TYPE_OK (short_integer_type_node
))
3881 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3882 if (TYPE_OK (long_integer_type_node
))
3883 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3884 if (TYPE_OK (long_long_integer_type_node
))
3885 return (unsignedp
? long_long_unsigned_type_node
3886 : long_long_integer_type_node
);
3887 if (int128_integer_type_node
&& TYPE_OK (int128_integer_type_node
))
3888 return (unsignedp
? int128_unsigned_type_node
3889 : int128_integer_type_node
);
3890 if (TYPE_OK (widest_integer_literal_type_node
))
3891 return (unsignedp
? widest_unsigned_literal_type_node
3892 : widest_integer_literal_type_node
);
3894 #if HOST_BITS_PER_WIDE_INT >= 64
3895 if (TYPE_OK (intTI_type_node
))
3896 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3898 if (TYPE_OK (intDI_type_node
))
3899 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3900 if (TYPE_OK (intSI_type_node
))
3901 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3902 if (TYPE_OK (intHI_type_node
))
3903 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3904 if (TYPE_OK (intQI_type_node
))
3905 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3908 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
3911 /* Build a bit-field integer type for the given WIDTH and UNSIGNEDP. */
3914 c_build_bitfield_integer_type (unsigned HOST_WIDE_INT width
, int unsignedp
)
3916 /* Extended integer types of the same width as a standard type have
3917 lesser rank, so those of the same width as int promote to int or
3918 unsigned int and are valid for printf formats expecting int or
3919 unsigned int. To avoid such special cases, avoid creating
3920 extended integer types for bit-fields if a standard integer type
3922 if (width
== TYPE_PRECISION (integer_type_node
))
3923 return unsignedp
? unsigned_type_node
: integer_type_node
;
3924 if (width
== TYPE_PRECISION (signed_char_type_node
))
3925 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3926 if (width
== TYPE_PRECISION (short_integer_type_node
))
3927 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3928 if (width
== TYPE_PRECISION (long_integer_type_node
))
3929 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3930 if (width
== TYPE_PRECISION (long_long_integer_type_node
))
3931 return (unsignedp
? long_long_unsigned_type_node
3932 : long_long_integer_type_node
);
3933 if (int128_integer_type_node
3934 && width
== TYPE_PRECISION (int128_integer_type_node
))
3935 return (unsignedp
? int128_unsigned_type_node
3936 : int128_integer_type_node
);
3937 return build_nonstandard_integer_type (width
, unsignedp
);
3940 /* The C version of the register_builtin_type langhook. */
3943 c_register_builtin_type (tree type
, const char* name
)
3947 decl
= build_decl (UNKNOWN_LOCATION
,
3948 TYPE_DECL
, get_identifier (name
), type
);
3949 DECL_ARTIFICIAL (decl
) = 1;
3950 if (!TYPE_NAME (type
))
3951 TYPE_NAME (type
) = decl
;
3954 registered_builtin_types
= tree_cons (0, type
, registered_builtin_types
);
3957 /* Print an error message for invalid operands to arith operation
3958 CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
3959 LOCATION is the location of the message. */
3962 binary_op_error (location_t location
, enum tree_code code
,
3963 tree type0
, tree type1
)
3970 opname
= "+"; break;
3972 opname
= "-"; break;
3974 opname
= "*"; break;
3976 opname
= "max"; break;
3978 opname
= "min"; break;
3980 opname
= "=="; break;
3982 opname
= "!="; break;
3984 opname
= "<="; break;
3986 opname
= ">="; break;
3988 opname
= "<"; break;
3990 opname
= ">"; break;
3992 opname
= "<<"; break;
3994 opname
= ">>"; break;
3995 case TRUNC_MOD_EXPR
:
3996 case FLOOR_MOD_EXPR
:
3997 opname
= "%"; break;
3998 case TRUNC_DIV_EXPR
:
3999 case FLOOR_DIV_EXPR
:
4000 opname
= "/"; break;
4002 opname
= "&"; break;
4004 opname
= "|"; break;
4005 case TRUTH_ANDIF_EXPR
:
4006 opname
= "&&"; break;
4007 case TRUTH_ORIF_EXPR
:
4008 opname
= "||"; break;
4010 opname
= "^"; break;
4015 "invalid operands to binary %s (have %qT and %qT)", opname
,
4019 /* Given an expression as a tree, return its original type. Do this
4020 by stripping any conversion that preserves the sign and precision. */
4022 expr_original_type (tree expr
)
4024 STRIP_SIGN_NOPS (expr
);
4025 return TREE_TYPE (expr
);
4028 /* Subroutine of build_binary_op, used for comparison operations.
4029 See if the operands have both been converted from subword integer types
4030 and, if so, perhaps change them both back to their original type.
4031 This function is also responsible for converting the two operands
4032 to the proper common type for comparison.
4034 The arguments of this function are all pointers to local variables
4035 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
4036 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
4038 LOC is the location of the comparison.
4040 If this function returns nonzero, it means that the comparison has
4041 a constant value. What this function returns is an expression for
4045 shorten_compare (location_t loc
, tree
*op0_ptr
, tree
*op1_ptr
,
4046 tree
*restype_ptr
, enum tree_code
*rescode_ptr
)
4049 tree op0
= *op0_ptr
;
4050 tree op1
= *op1_ptr
;
4051 int unsignedp0
, unsignedp1
;
4053 tree primop0
, primop1
;
4054 enum tree_code code
= *rescode_ptr
;
4056 /* Throw away any conversions to wider types
4057 already present in the operands. */
4059 primop0
= c_common_get_narrower (op0
, &unsignedp0
);
4060 primop1
= c_common_get_narrower (op1
, &unsignedp1
);
4062 /* If primopN is first sign-extended from primopN's precision to opN's
4063 precision, then zero-extended from opN's precision to
4064 *restype_ptr precision, shortenings might be invalid. */
4065 if (TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (TREE_TYPE (op0
))
4066 && TYPE_PRECISION (TREE_TYPE (op0
)) < TYPE_PRECISION (*restype_ptr
)
4068 && TYPE_UNSIGNED (TREE_TYPE (op0
)))
4070 if (TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (TREE_TYPE (op1
))
4071 && TYPE_PRECISION (TREE_TYPE (op1
)) < TYPE_PRECISION (*restype_ptr
)
4073 && TYPE_UNSIGNED (TREE_TYPE (op1
)))
4076 /* Handle the case that OP0 does not *contain* a conversion
4077 but it *requires* conversion to FINAL_TYPE. */
4079 if (op0
== primop0
&& TREE_TYPE (op0
) != *restype_ptr
)
4080 unsignedp0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
4081 if (op1
== primop1
&& TREE_TYPE (op1
) != *restype_ptr
)
4082 unsignedp1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
4084 /* If one of the operands must be floated, we cannot optimize. */
4085 real1
= TREE_CODE (TREE_TYPE (primop0
)) == REAL_TYPE
;
4086 real2
= TREE_CODE (TREE_TYPE (primop1
)) == REAL_TYPE
;
4088 /* If first arg is constant, swap the args (changing operation
4089 so value is preserved), for canonicalization. Don't do this if
4090 the second arg is 0. */
4092 if (TREE_CONSTANT (primop0
)
4093 && !integer_zerop (primop1
) && !real_zerop (primop1
)
4094 && !fixed_zerop (primop1
))
4097 int temi
= unsignedp0
;
4105 unsignedp0
= unsignedp1
;
4128 *rescode_ptr
= code
;
4131 /* If comparing an integer against a constant more bits wide,
4132 maybe we can deduce a value of 1 or 0 independent of the data.
4133 Or else truncate the constant now
4134 rather than extend the variable at run time.
4136 This is only interesting if the constant is the wider arg.
4137 Also, it is not safe if the constant is unsigned and the
4138 variable arg is signed, since in this case the variable
4139 would be sign-extended and then regarded as unsigned.
4140 Our technique fails in this case because the lowest/highest
4141 possible unsigned results don't follow naturally from the
4142 lowest/highest possible values of the variable operand.
4143 For just EQ_EXPR and NE_EXPR there is another technique that
4144 could be used: see if the constant can be faithfully represented
4145 in the other operand's type, by truncating it and reextending it
4146 and see if that preserves the constant's value. */
4148 if (!real1
&& !real2
4149 && TREE_CODE (TREE_TYPE (primop0
)) != FIXED_POINT_TYPE
4150 && TREE_CODE (primop1
) == INTEGER_CST
4151 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
))
4153 int min_gt
, max_gt
, min_lt
, max_lt
;
4154 tree maxval
, minval
;
4155 /* 1 if comparison is nominally unsigned. */
4156 int unsignedp
= TYPE_UNSIGNED (*restype_ptr
);
4159 type
= c_common_signed_or_unsigned_type (unsignedp0
,
4160 TREE_TYPE (primop0
));
4162 maxval
= TYPE_MAX_VALUE (type
);
4163 minval
= TYPE_MIN_VALUE (type
);
4165 if (unsignedp
&& !unsignedp0
)
4166 *restype_ptr
= c_common_signed_type (*restype_ptr
);
4168 if (TREE_TYPE (primop1
) != *restype_ptr
)
4170 /* Convert primop1 to target type, but do not introduce
4171 additional overflow. We know primop1 is an int_cst. */
4172 primop1
= force_fit_type (*restype_ptr
,
4175 TYPE_PRECISION (*restype_ptr
),
4176 TYPE_SIGN (TREE_TYPE (primop1
))),
4177 0, TREE_OVERFLOW (primop1
));
4179 if (type
!= *restype_ptr
)
4181 minval
= convert (*restype_ptr
, minval
);
4182 maxval
= convert (*restype_ptr
, maxval
);
4185 min_gt
= tree_int_cst_lt (primop1
, minval
);
4186 max_gt
= tree_int_cst_lt (primop1
, maxval
);
4187 min_lt
= tree_int_cst_lt (minval
, primop1
);
4188 max_lt
= tree_int_cst_lt (maxval
, primop1
);
4191 /* This used to be a switch, but Genix compiler can't handle that. */
4192 if (code
== NE_EXPR
)
4194 if (max_lt
|| min_gt
)
4195 val
= truthvalue_true_node
;
4197 else if (code
== EQ_EXPR
)
4199 if (max_lt
|| min_gt
)
4200 val
= truthvalue_false_node
;
4202 else if (code
== LT_EXPR
)
4205 val
= truthvalue_true_node
;
4207 val
= truthvalue_false_node
;
4209 else if (code
== GT_EXPR
)
4212 val
= truthvalue_true_node
;
4214 val
= truthvalue_false_node
;
4216 else if (code
== LE_EXPR
)
4219 val
= truthvalue_true_node
;
4221 val
= truthvalue_false_node
;
4223 else if (code
== GE_EXPR
)
4226 val
= truthvalue_true_node
;
4228 val
= truthvalue_false_node
;
4231 /* If primop0 was sign-extended and unsigned comparison specd,
4232 we did a signed comparison above using the signed type bounds.
4233 But the comparison we output must be unsigned.
4235 Also, for inequalities, VAL is no good; but if the signed
4236 comparison had *any* fixed result, it follows that the
4237 unsigned comparison just tests the sign in reverse
4238 (positive values are LE, negative ones GE).
4239 So we can generate an unsigned comparison
4240 against an extreme value of the signed type. */
4242 if (unsignedp
&& !unsignedp0
)
4249 primop1
= TYPE_MIN_VALUE (type
);
4255 primop1
= TYPE_MAX_VALUE (type
);
4262 type
= c_common_unsigned_type (type
);
4265 if (TREE_CODE (primop0
) != INTEGER_CST
)
4267 if (val
== truthvalue_false_node
)
4268 warning_at (loc
, OPT_Wtype_limits
,
4269 "comparison is always false due to limited range of data type");
4270 if (val
== truthvalue_true_node
)
4271 warning_at (loc
, OPT_Wtype_limits
,
4272 "comparison is always true due to limited range of data type");
4277 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4278 if (TREE_SIDE_EFFECTS (primop0
))
4279 return build2 (COMPOUND_EXPR
, TREE_TYPE (val
), primop0
, val
);
4283 /* Value is not predetermined, but do the comparison
4284 in the type of the operand that is not constant.
4285 TYPE is already properly set. */
4288 /* If either arg is decimal float and the other is float, find the
4289 proper common type to use for comparison. */
4290 else if (real1
&& real2
4291 && (DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0
)))
4292 || DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1
)))))
4293 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
4295 else if (real1
&& real2
4296 && (TYPE_PRECISION (TREE_TYPE (primop0
))
4297 == TYPE_PRECISION (TREE_TYPE (primop1
))))
4298 type
= TREE_TYPE (primop0
);
4300 /* If args' natural types are both narrower than nominal type
4301 and both extend in the same manner, compare them
4302 in the type of the wider arg.
4303 Otherwise must actually extend both to the nominal
4304 common type lest different ways of extending
4306 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
4308 else if (unsignedp0
== unsignedp1
&& real1
== real2
4309 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
)
4310 && TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (*restype_ptr
))
4312 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
4313 type
= c_common_signed_or_unsigned_type (unsignedp0
4314 || TYPE_UNSIGNED (*restype_ptr
),
4316 /* Make sure shorter operand is extended the right way
4317 to match the longer operand. */
4319 = convert (c_common_signed_or_unsigned_type (unsignedp0
,
4320 TREE_TYPE (primop0
)),
4323 = convert (c_common_signed_or_unsigned_type (unsignedp1
,
4324 TREE_TYPE (primop1
)),
4329 /* Here we must do the comparison on the nominal type
4330 using the args exactly as we received them. */
4331 type
= *restype_ptr
;
4335 if (!real1
&& !real2
&& integer_zerop (primop1
)
4336 && TYPE_UNSIGNED (*restype_ptr
))
4339 /* All unsigned values are >= 0, so we warn. However,
4340 if OP0 is a constant that is >= 0, the signedness of
4341 the comparison isn't an issue, so suppress the
4344 warn_type_limits
&& !in_system_header_at (loc
)
4345 && !(TREE_CODE (primop0
) == INTEGER_CST
4346 && !TREE_OVERFLOW (convert (c_common_signed_type (type
),
4348 /* Do not warn for enumeration types. */
4349 && (TREE_CODE (expr_original_type (primop0
)) != ENUMERAL_TYPE
);
4355 warning_at (loc
, OPT_Wtype_limits
,
4356 "comparison of unsigned expression >= 0 is always true");
4357 value
= truthvalue_true_node
;
4362 warning_at (loc
, OPT_Wtype_limits
,
4363 "comparison of unsigned expression < 0 is always false");
4364 value
= truthvalue_false_node
;
4373 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4374 if (TREE_SIDE_EFFECTS (primop0
))
4375 return build2 (COMPOUND_EXPR
, TREE_TYPE (value
),
4382 *op0_ptr
= convert (type
, primop0
);
4383 *op1_ptr
= convert (type
, primop1
);
4385 *restype_ptr
= truthvalue_type_node
;
4390 /* Return a tree for the sum or difference (RESULTCODE says which)
4391 of pointer PTROP and integer INTOP. */
4394 pointer_int_sum (location_t loc
, enum tree_code resultcode
,
4395 tree ptrop
, tree intop
, bool complain
)
4399 /* The result is a pointer of the same type that is being added. */
4400 tree result_type
= TREE_TYPE (ptrop
);
4402 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
4404 if (complain
&& warn_pointer_arith
)
4405 pedwarn (loc
, OPT_Wpointer_arith
,
4406 "pointer of type %<void *%> used in arithmetic");
4408 return error_mark_node
;
4409 size_exp
= integer_one_node
;
4411 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
4413 if (complain
&& warn_pointer_arith
)
4414 pedwarn (loc
, OPT_Wpointer_arith
,
4415 "pointer to a function used in arithmetic");
4417 return error_mark_node
;
4418 size_exp
= integer_one_node
;
4421 size_exp
= size_in_bytes (TREE_TYPE (result_type
));
4423 /* We are manipulating pointer values, so we don't need to warn
4424 about relying on undefined signed overflow. We disable the
4425 warning here because we use integer types so fold won't know that
4426 they are really pointers. */
4427 fold_defer_overflow_warnings ();
4429 /* If what we are about to multiply by the size of the elements
4430 contains a constant term, apply distributive law
4431 and multiply that constant term separately.
4432 This helps produce common subexpressions. */
4433 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
4434 && !TREE_CONSTANT (intop
)
4435 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
4436 && TREE_CONSTANT (size_exp
)
4437 /* If the constant comes from pointer subtraction,
4438 skip this optimization--it would cause an error. */
4439 && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop
, 0))) == INTEGER_TYPE
4440 /* If the constant is unsigned, and smaller than the pointer size,
4441 then we must skip this optimization. This is because it could cause
4442 an overflow error if the constant is negative but INTOP is not. */
4443 && (!TYPE_UNSIGNED (TREE_TYPE (intop
))
4444 || (TYPE_PRECISION (TREE_TYPE (intop
))
4445 == TYPE_PRECISION (TREE_TYPE (ptrop
)))))
4447 enum tree_code subcode
= resultcode
;
4448 tree int_type
= TREE_TYPE (intop
);
4449 if (TREE_CODE (intop
) == MINUS_EXPR
)
4450 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
4451 /* Convert both subexpression types to the type of intop,
4452 because weird cases involving pointer arithmetic
4453 can result in a sum or difference with different type args. */
4454 ptrop
= build_binary_op (EXPR_LOCATION (TREE_OPERAND (intop
, 1)),
4456 convert (int_type
, TREE_OPERAND (intop
, 1)), 1);
4457 intop
= convert (int_type
, TREE_OPERAND (intop
, 0));
4460 /* Convert the integer argument to a type the same size as sizetype
4461 so the multiply won't overflow spuriously. */
4462 if (TYPE_PRECISION (TREE_TYPE (intop
)) != TYPE_PRECISION (sizetype
)
4463 || TYPE_UNSIGNED (TREE_TYPE (intop
)) != TYPE_UNSIGNED (sizetype
))
4464 intop
= convert (c_common_type_for_size (TYPE_PRECISION (sizetype
),
4465 TYPE_UNSIGNED (sizetype
)), intop
);
4467 /* Replace the integer argument with a suitable product by the object size.
4468 Do this multiplication as signed, then convert to the appropriate type
4469 for the pointer operation and disregard an overflow that occurred only
4470 because of the sign-extension change in the latter conversion. */
4472 tree t
= build_binary_op (loc
,
4474 convert (TREE_TYPE (intop
), size_exp
), 1);
4475 intop
= convert (sizetype
, t
);
4476 if (TREE_OVERFLOW_P (intop
) && !TREE_OVERFLOW (t
))
4477 intop
= wide_int_to_tree (TREE_TYPE (intop
), intop
);
4480 /* Create the sum or difference. */
4481 if (resultcode
== MINUS_EXPR
)
4482 intop
= fold_build1_loc (loc
, NEGATE_EXPR
, sizetype
, intop
);
4484 ret
= fold_build_pointer_plus_loc (loc
, ptrop
, intop
);
4486 fold_undefer_and_ignore_overflow_warnings ();
4491 /* Wrap a C_MAYBE_CONST_EXPR around an expression that is fully folded
4492 and if NON_CONST is known not to be permitted in an evaluated part
4493 of a constant expression. */
4496 c_wrap_maybe_const (tree expr
, bool non_const
)
4498 bool nowarning
= TREE_NO_WARNING (expr
);
4499 location_t loc
= EXPR_LOCATION (expr
);
4501 /* This should never be called for C++. */
4502 if (c_dialect_cxx ())
4505 /* The result of folding may have a NOP_EXPR to set TREE_NO_WARNING. */
4506 STRIP_TYPE_NOPS (expr
);
4507 expr
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (expr
), NULL
, expr
);
4508 C_MAYBE_CONST_EXPR_NON_CONST (expr
) = non_const
;
4510 TREE_NO_WARNING (expr
) = 1;
4511 protected_set_expr_location (expr
, loc
);
4516 /* Wrap a SAVE_EXPR around EXPR, if appropriate. Like save_expr, but
4517 for C folds the inside expression and wraps a C_MAYBE_CONST_EXPR
4518 around the SAVE_EXPR if needed so that c_fully_fold does not need
4519 to look inside SAVE_EXPRs. */
4522 c_save_expr (tree expr
)
4524 bool maybe_const
= true;
4525 if (c_dialect_cxx ())
4526 return save_expr (expr
);
4527 expr
= c_fully_fold (expr
, false, &maybe_const
);
4528 expr
= save_expr (expr
);
4530 expr
= c_wrap_maybe_const (expr
, true);
4534 /* Return whether EXPR is a declaration whose address can never be
4538 decl_with_nonnull_addr_p (const_tree expr
)
4540 return (DECL_P (expr
)
4541 && (TREE_CODE (expr
) == PARM_DECL
4542 || TREE_CODE (expr
) == LABEL_DECL
4543 || !DECL_WEAK (expr
)));
4546 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
4547 or for an `if' or `while' statement or ?..: exp. It should already
4548 have been validated to be of suitable type; otherwise, a bad
4549 diagnostic may result.
4551 The EXPR is located at LOCATION.
4553 This preparation consists of taking the ordinary
4554 representation of an expression expr and producing a valid tree
4555 boolean expression describing whether expr is nonzero. We could
4556 simply always do build_binary_op (NE_EXPR, expr, truthvalue_false_node, 1),
4557 but we optimize comparisons, &&, ||, and !.
4559 The resulting type should always be `truthvalue_type_node'. */
4562 c_common_truthvalue_conversion (location_t location
, tree expr
)
4564 switch (TREE_CODE (expr
))
4566 case EQ_EXPR
: case NE_EXPR
: case UNEQ_EXPR
: case LTGT_EXPR
:
4567 case LE_EXPR
: case GE_EXPR
: case LT_EXPR
: case GT_EXPR
:
4568 case UNLE_EXPR
: case UNGE_EXPR
: case UNLT_EXPR
: case UNGT_EXPR
:
4569 case ORDERED_EXPR
: case UNORDERED_EXPR
:
4570 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4572 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4573 TREE_OPERAND (expr
, 0), TREE_OPERAND (expr
, 1));
4576 case TRUTH_ANDIF_EXPR
:
4577 case TRUTH_ORIF_EXPR
:
4578 case TRUTH_AND_EXPR
:
4580 case TRUTH_XOR_EXPR
:
4581 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4583 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4584 c_common_truthvalue_conversion (location
,
4585 TREE_OPERAND (expr
, 0)),
4586 c_common_truthvalue_conversion (location
,
4587 TREE_OPERAND (expr
, 1)));
4590 case TRUTH_NOT_EXPR
:
4591 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4593 expr
= build1 (TREE_CODE (expr
), truthvalue_type_node
,
4594 c_common_truthvalue_conversion (location
,
4595 TREE_OPERAND (expr
, 0)));
4602 return integer_zerop (expr
) ? truthvalue_false_node
4603 : truthvalue_true_node
;
4606 return real_compare (NE_EXPR
, &TREE_REAL_CST (expr
), &dconst0
)
4607 ? truthvalue_true_node
4608 : truthvalue_false_node
;
4611 return fixed_compare (NE_EXPR
, &TREE_FIXED_CST (expr
),
4612 &FCONST0 (TYPE_MODE (TREE_TYPE (expr
))))
4613 ? truthvalue_true_node
4614 : truthvalue_false_node
;
4617 expr
= build_unary_op (location
, ADDR_EXPR
, expr
, 0);
4622 tree inner
= TREE_OPERAND (expr
, 0);
4623 if (decl_with_nonnull_addr_p (inner
))
4625 /* Common Ada/Pascal programmer's mistake. */
4626 warning_at (location
,
4628 "the address of %qD will always evaluate as %<true%>",
4630 return truthvalue_true_node
;
4636 expr
= build_binary_op (EXPR_LOCATION (expr
),
4637 (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1))
4638 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4639 c_common_truthvalue_conversion (location
,
4640 TREE_OPERAND (expr
, 0)),
4641 c_common_truthvalue_conversion (location
,
4642 TREE_OPERAND (expr
, 1)),
4649 case EXCESS_PRECISION_EXPR
:
4650 /* These don't change whether an object is nonzero or zero. */
4651 return c_common_truthvalue_conversion (location
, TREE_OPERAND (expr
, 0));
4655 /* These don't change whether an object is zero or nonzero, but
4656 we can't ignore them if their second arg has side-effects. */
4657 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1)))
4659 expr
= build2 (COMPOUND_EXPR
, truthvalue_type_node
,
4660 TREE_OPERAND (expr
, 1),
4661 c_common_truthvalue_conversion
4662 (location
, TREE_OPERAND (expr
, 0)));
4666 return c_common_truthvalue_conversion (location
,
4667 TREE_OPERAND (expr
, 0));
4670 /* Distribute the conversion into the arms of a COND_EXPR. */
4671 if (c_dialect_cxx ())
4673 tree op1
= TREE_OPERAND (expr
, 1);
4674 tree op2
= TREE_OPERAND (expr
, 2);
4675 /* In C++ one of the arms might have void type if it is throw. */
4676 if (!VOID_TYPE_P (TREE_TYPE (op1
)))
4677 op1
= c_common_truthvalue_conversion (location
, op1
);
4678 if (!VOID_TYPE_P (TREE_TYPE (op2
)))
4679 op2
= c_common_truthvalue_conversion (location
, op2
);
4680 expr
= fold_build3_loc (location
, COND_EXPR
, truthvalue_type_node
,
4681 TREE_OPERAND (expr
, 0), op1
, op2
);
4686 /* Folding will happen later for C. */
4687 expr
= build3 (COND_EXPR
, truthvalue_type_node
,
4688 TREE_OPERAND (expr
, 0),
4689 c_common_truthvalue_conversion (location
,
4690 TREE_OPERAND (expr
, 1)),
4691 c_common_truthvalue_conversion (location
,
4692 TREE_OPERAND (expr
, 2)));
4698 tree totype
= TREE_TYPE (expr
);
4699 tree fromtype
= TREE_TYPE (TREE_OPERAND (expr
, 0));
4701 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
4702 since that affects how `default_conversion' will behave. */
4703 if (TREE_CODE (totype
) == REFERENCE_TYPE
4704 || TREE_CODE (fromtype
) == REFERENCE_TYPE
)
4706 /* Don't strip a conversion from C++0x scoped enum, since they
4707 don't implicitly convert to other types. */
4708 if (TREE_CODE (fromtype
) == ENUMERAL_TYPE
4709 && ENUM_IS_SCOPED (fromtype
))
4711 /* If this isn't narrowing the argument, we can ignore it. */
4712 if (TYPE_PRECISION (totype
) >= TYPE_PRECISION (fromtype
))
4713 return c_common_truthvalue_conversion (location
,
4714 TREE_OPERAND (expr
, 0));
4719 if (!TREE_NO_WARNING (expr
)
4720 && warn_parentheses
)
4722 warning (OPT_Wparentheses
,
4723 "suggest parentheses around assignment used as truth value");
4724 TREE_NO_WARNING (expr
) = 1;
4732 if (TREE_CODE (TREE_TYPE (expr
)) == COMPLEX_TYPE
)
4734 tree t
= (in_late_binary_op
? save_expr (expr
) : c_save_expr (expr
));
4735 expr
= (build_binary_op
4736 (EXPR_LOCATION (expr
),
4737 (TREE_SIDE_EFFECTS (expr
)
4738 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4739 c_common_truthvalue_conversion
4741 build_unary_op (location
, REALPART_EXPR
, t
, 0)),
4742 c_common_truthvalue_conversion
4744 build_unary_op (location
, IMAGPART_EXPR
, t
, 0)),
4749 if (TREE_CODE (TREE_TYPE (expr
)) == FIXED_POINT_TYPE
)
4751 tree fixed_zero_node
= build_fixed (TREE_TYPE (expr
),
4753 (TREE_TYPE (expr
))));
4754 return build_binary_op (location
, NE_EXPR
, expr
, fixed_zero_node
, 1);
4757 return build_binary_op (location
, NE_EXPR
, expr
, integer_zero_node
, 1);
4760 protected_set_expr_location (expr
, location
);
4764 static void def_builtin_1 (enum built_in_function fncode
,
4766 enum built_in_class fnclass
,
4767 tree fntype
, tree libtype
,
4768 bool both_p
, bool fallback_p
, bool nonansi_p
,
4769 tree fnattrs
, bool implicit_p
);
4772 /* Apply the TYPE_QUALS to the new DECL. */
4775 c_apply_type_quals_to_decl (int type_quals
, tree decl
)
4777 tree type
= TREE_TYPE (decl
);
4779 if (type
== error_mark_node
)
4782 if ((type_quals
& TYPE_QUAL_CONST
)
4783 || (type
&& TREE_CODE (type
) == REFERENCE_TYPE
))
4784 /* We used to check TYPE_NEEDS_CONSTRUCTING here, but now a constexpr
4785 constructor can produce constant init, so rely on cp_finish_decl to
4786 clear TREE_READONLY if the variable has non-constant init. */
4787 TREE_READONLY (decl
) = 1;
4788 if (type_quals
& TYPE_QUAL_VOLATILE
)
4790 TREE_SIDE_EFFECTS (decl
) = 1;
4791 TREE_THIS_VOLATILE (decl
) = 1;
4793 if (type_quals
& TYPE_QUAL_RESTRICT
)
4795 while (type
&& TREE_CODE (type
) == ARRAY_TYPE
)
4796 /* Allow 'restrict' on arrays of pointers.
4797 FIXME currently we just ignore it. */
4798 type
= TREE_TYPE (type
);
4800 || !POINTER_TYPE_P (type
)
4801 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type
)))
4802 error ("invalid use of %<restrict%>");
4806 struct c_type_hasher
: ggc_hasher
<tree
>
4808 static hashval_t
hash (tree
);
4809 static bool equal (tree
, tree
);
4812 /* Hash function for the problem of multiple type definitions in
4813 different files. This must hash all types that will compare
4814 equal via comptypes to the same value. In practice it hashes
4815 on some of the simple stuff and leaves the details to comptypes. */
4818 c_type_hasher::hash (tree t
)
4823 switch (TREE_CODE (t
))
4825 /* For pointers, hash on pointee type plus some swizzling. */
4827 return hash (TREE_TYPE (t
)) ^ 0x3003003;
4828 /* Hash on number of elements and total size. */
4831 t2
= TYPE_VALUES (t
);
4835 t2
= TYPE_FIELDS (t
);
4837 case QUAL_UNION_TYPE
:
4839 t2
= TYPE_FIELDS (t
);
4843 t2
= TYPE_FIELDS (t
);
4848 /* FIXME: We want to use a DECL_CHAIN iteration method here, but
4849 TYPE_VALUES of ENUMERAL_TYPEs is stored as a TREE_LIST. */
4850 n_elements
= list_length (t2
);
4851 /* We might have a VLA here. */
4852 if (TREE_CODE (TYPE_SIZE (t
)) != INTEGER_CST
)
4855 size
= TREE_INT_CST_LOW (TYPE_SIZE (t
));
4856 return ((size
<< 24) | (n_elements
<< shift
));
4860 c_type_hasher::equal (tree t1
, tree t2
)
4862 return lang_hooks
.types_compatible_p (t1
, t2
);
4865 static GTY(()) hash_table
<c_type_hasher
> *type_hash_table
;
4867 /* Return the typed-based alias set for T, which may be an expression
4868 or a type. Return -1 if we don't do anything special. */
4871 c_common_get_alias_set (tree t
)
4875 /* For VLAs, use the alias set of the element type rather than the
4876 default of alias set 0 for types compared structurally. */
4877 if (TYPE_P (t
) && TYPE_STRUCTURAL_EQUALITY_P (t
))
4879 if (TREE_CODE (t
) == ARRAY_TYPE
)
4880 return get_alias_set (TREE_TYPE (t
));
4884 /* Permit type-punning when accessing a union, provided the access
4885 is directly through the union. For example, this code does not
4886 permit taking the address of a union member and then storing
4887 through it. Even the type-punning allowed here is a GCC
4888 extension, albeit a common and useful one; the C standard says
4889 that such accesses have implementation-defined behavior. */
4891 TREE_CODE (u
) == COMPONENT_REF
|| TREE_CODE (u
) == ARRAY_REF
;
4892 u
= TREE_OPERAND (u
, 0))
4893 if (TREE_CODE (u
) == COMPONENT_REF
4894 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u
, 0))) == UNION_TYPE
)
4897 /* That's all the expressions we handle specially. */
4901 /* The C standard guarantees that any object may be accessed via an
4902 lvalue that has character type. */
4903 if (t
== char_type_node
4904 || t
== signed_char_type_node
4905 || t
== unsigned_char_type_node
)
4908 /* The C standard specifically allows aliasing between signed and
4909 unsigned variants of the same type. We treat the signed
4910 variant as canonical. */
4911 if (TREE_CODE (t
) == INTEGER_TYPE
&& TYPE_UNSIGNED (t
))
4913 tree t1
= c_common_signed_type (t
);
4915 /* t1 == t can happen for boolean nodes which are always unsigned. */
4917 return get_alias_set (t1
);
4920 /* Handle the case of multiple type nodes referring to "the same" type,
4921 which occurs with IMA. These share an alias set. FIXME: Currently only
4922 C90 is handled. (In C99 type compatibility is not transitive, which
4923 complicates things mightily. The alias set splay trees can theoretically
4924 represent this, but insertion is tricky when you consider all the
4925 different orders things might arrive in.) */
4927 if (c_language
!= clk_c
|| flag_isoc99
)
4930 /* Save time if there's only one input file. */
4931 if (num_in_fnames
== 1)
4934 /* Pointers need special handling if they point to any type that
4935 needs special handling (below). */
4936 if (TREE_CODE (t
) == POINTER_TYPE
)
4939 /* Find bottom type under any nested POINTERs. */
4940 for (t2
= TREE_TYPE (t
);
4941 TREE_CODE (t2
) == POINTER_TYPE
;
4942 t2
= TREE_TYPE (t2
))
4944 if (TREE_CODE (t2
) != RECORD_TYPE
4945 && TREE_CODE (t2
) != ENUMERAL_TYPE
4946 && TREE_CODE (t2
) != QUAL_UNION_TYPE
4947 && TREE_CODE (t2
) != UNION_TYPE
)
4949 if (TYPE_SIZE (t2
) == 0)
4952 /* These are the only cases that need special handling. */
4953 if (TREE_CODE (t
) != RECORD_TYPE
4954 && TREE_CODE (t
) != ENUMERAL_TYPE
4955 && TREE_CODE (t
) != QUAL_UNION_TYPE
4956 && TREE_CODE (t
) != UNION_TYPE
4957 && TREE_CODE (t
) != POINTER_TYPE
)
4960 if (TYPE_SIZE (t
) == 0)
4963 /* Look up t in hash table. Only one of the compatible types within each
4964 alias set is recorded in the table. */
4965 if (!type_hash_table
)
4966 type_hash_table
= hash_table
<c_type_hasher
>::create_ggc (1021);
4967 tree
*slot
= type_hash_table
->find_slot (t
, INSERT
);
4970 TYPE_ALIAS_SET (t
) = TYPE_ALIAS_SET ((tree
)*slot
);
4971 return TYPE_ALIAS_SET ((tree
)*slot
);
4974 /* Our caller will assign and record (in t) a new alias set; all we need
4975 to do is remember t in the hash table. */
4981 /* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where
4982 the IS_SIZEOF parameter indicates which operator is being applied.
4983 The COMPLAIN flag controls whether we should diagnose possibly
4984 ill-formed constructs or not. LOC is the location of the SIZEOF or
4985 TYPEOF operator. If MIN_ALIGNOF, the least alignment required for
4986 a type in any context should be returned, rather than the normal
4987 alignment for that type. */
4990 c_sizeof_or_alignof_type (location_t loc
,
4991 tree type
, bool is_sizeof
, bool min_alignof
,
4994 const char *op_name
;
4996 enum tree_code type_code
= TREE_CODE (type
);
4998 op_name
= is_sizeof
? "sizeof" : "__alignof__";
5000 if (type_code
== FUNCTION_TYPE
)
5004 if (complain
&& warn_pointer_arith
)
5005 pedwarn (loc
, OPT_Wpointer_arith
,
5006 "invalid application of %<sizeof%> to a function type");
5008 return error_mark_node
;
5009 value
= size_one_node
;
5015 if (c_dialect_cxx ())
5016 pedwarn (loc
, OPT_Wpedantic
, "ISO C++ does not permit "
5017 "%<alignof%> applied to a function type");
5019 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not permit "
5020 "%<_Alignof%> applied to a function type");
5022 value
= size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
5025 else if (type_code
== VOID_TYPE
|| type_code
== ERROR_MARK
)
5027 if (type_code
== VOID_TYPE
5028 && complain
&& warn_pointer_arith
)
5029 pedwarn (loc
, OPT_Wpointer_arith
,
5030 "invalid application of %qs to a void type", op_name
);
5032 return error_mark_node
;
5033 value
= size_one_node
;
5035 else if (!COMPLETE_TYPE_P (type
)
5036 && (!c_dialect_cxx () || is_sizeof
|| type_code
!= ARRAY_TYPE
))
5039 error_at (loc
, "invalid application of %qs to incomplete type %qT",
5041 return error_mark_node
;
5043 else if (c_dialect_cxx () && type_code
== ARRAY_TYPE
5044 && !COMPLETE_TYPE_P (TREE_TYPE (type
)))
5047 error_at (loc
, "invalid application of %qs to array type %qT of "
5048 "incomplete element type", op_name
, type
);
5049 return error_mark_node
;
5054 /* Convert in case a char is more than one unit. */
5055 value
= size_binop_loc (loc
, CEIL_DIV_EXPR
, TYPE_SIZE_UNIT (type
),
5056 size_int (TYPE_PRECISION (char_type_node
)
5058 else if (min_alignof
)
5059 value
= size_int (min_align_of_type (type
));
5061 value
= size_int (TYPE_ALIGN_UNIT (type
));
5064 /* VALUE will have the middle-end integer type sizetype.
5065 However, we should really return a value of type `size_t',
5066 which is just a typedef for an ordinary integer type. */
5067 value
= fold_convert_loc (loc
, size_type_node
, value
);
5072 /* Implement the __alignof keyword: Return the minimum required
5073 alignment of EXPR, measured in bytes. For VAR_DECLs,
5074 FUNCTION_DECLs and FIELD_DECLs return DECL_ALIGN (which can be set
5075 from an "aligned" __attribute__ specification). LOC is the
5076 location of the ALIGNOF operator. */
5079 c_alignof_expr (location_t loc
, tree expr
)
5083 if (VAR_OR_FUNCTION_DECL_P (expr
))
5084 t
= size_int (DECL_ALIGN_UNIT (expr
));
5086 else if (TREE_CODE (expr
) == COMPONENT_REF
5087 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
, 1)))
5089 error_at (loc
, "%<__alignof%> applied to a bit-field");
5092 else if (TREE_CODE (expr
) == COMPONENT_REF
5093 && TREE_CODE (TREE_OPERAND (expr
, 1)) == FIELD_DECL
)
5094 t
= size_int (DECL_ALIGN_UNIT (TREE_OPERAND (expr
, 1)));
5096 else if (TREE_CODE (expr
) == INDIRECT_REF
)
5098 tree t
= TREE_OPERAND (expr
, 0);
5100 int bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
5102 while (CONVERT_EXPR_P (t
)
5103 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
5107 t
= TREE_OPERAND (t
, 0);
5108 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
5109 if (thisalign
> bestalign
)
5110 best
= t
, bestalign
= thisalign
;
5112 return c_alignof (loc
, TREE_TYPE (TREE_TYPE (best
)));
5115 return c_alignof (loc
, TREE_TYPE (expr
));
5117 return fold_convert_loc (loc
, size_type_node
, t
);
5120 /* Handle C and C++ default attributes. */
5122 enum built_in_attribute
5124 #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
5125 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
5126 #define DEF_ATTR_STRING(ENUM, VALUE) ENUM,
5127 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
5128 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
5129 #include "builtin-attrs.def"
5130 #undef DEF_ATTR_NULL_TREE
5132 #undef DEF_ATTR_STRING
5133 #undef DEF_ATTR_IDENT
5134 #undef DEF_ATTR_TREE_LIST
5138 static GTY(()) tree built_in_attributes
[(int) ATTR_LAST
];
5140 static void c_init_attributes (void);
5144 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
5145 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
5146 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
5147 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
5148 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
5149 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
5150 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
5151 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5153 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5155 #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5156 ARG6, ARG7, ARG8) NAME,
5157 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
5158 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
5159 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
5160 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
5161 #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
5162 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5164 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
5165 #include "builtin-types.def"
5166 #undef DEF_PRIMITIVE_TYPE
5167 #undef DEF_FUNCTION_TYPE_0
5168 #undef DEF_FUNCTION_TYPE_1
5169 #undef DEF_FUNCTION_TYPE_2
5170 #undef DEF_FUNCTION_TYPE_3
5171 #undef DEF_FUNCTION_TYPE_4
5172 #undef DEF_FUNCTION_TYPE_5
5173 #undef DEF_FUNCTION_TYPE_6
5174 #undef DEF_FUNCTION_TYPE_7
5175 #undef DEF_FUNCTION_TYPE_8
5176 #undef DEF_FUNCTION_TYPE_VAR_0
5177 #undef DEF_FUNCTION_TYPE_VAR_1
5178 #undef DEF_FUNCTION_TYPE_VAR_2
5179 #undef DEF_FUNCTION_TYPE_VAR_3
5180 #undef DEF_FUNCTION_TYPE_VAR_4
5181 #undef DEF_FUNCTION_TYPE_VAR_5
5182 #undef DEF_POINTER_TYPE
5186 typedef enum c_builtin_type builtin_type
;
5188 /* A temporary array for c_common_nodes_and_builtins. Used in
5189 communication with def_fn_type. */
5190 static tree builtin_types
[(int) BT_LAST
+ 1];
5192 /* A helper function for c_common_nodes_and_builtins. Build function type
5193 for DEF with return type RET and N arguments. If VAR is true, then the
5194 function should be variadic after those N arguments.
5196 Takes special care not to ICE if any of the types involved are
5197 error_mark_node, which indicates that said type is not in fact available
5198 (see builtin_type_for_size). In which case the function type as a whole
5199 should be error_mark_node. */
5202 def_fn_type (builtin_type def
, builtin_type ret
, bool var
, int n
, ...)
5205 tree
*args
= XALLOCAVEC (tree
, n
);
5210 for (i
= 0; i
< n
; ++i
)
5212 builtin_type a
= (builtin_type
) va_arg (list
, int);
5213 t
= builtin_types
[a
];
5214 if (t
== error_mark_node
)
5219 t
= builtin_types
[ret
];
5220 if (t
== error_mark_node
)
5223 t
= build_varargs_function_type_array (t
, n
, args
);
5225 t
= build_function_type_array (t
, n
, args
);
5228 builtin_types
[def
] = t
;
5232 /* Build builtin functions common to both C and C++ language
5236 c_define_builtins (tree va_list_ref_type_node
, tree va_list_arg_type_node
)
5238 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
5239 builtin_types[ENUM] = VALUE;
5240 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
5241 def_fn_type (ENUM, RETURN, 0, 0);
5242 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
5243 def_fn_type (ENUM, RETURN, 0, 1, ARG1);
5244 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
5245 def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
5246 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
5247 def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
5248 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
5249 def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
5250 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5251 def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
5252 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5254 def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
5255 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5257 def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
5258 #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5260 def_fn_type (ENUM, RETURN, 0, 8, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
5262 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
5263 def_fn_type (ENUM, RETURN, 1, 0);
5264 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
5265 def_fn_type (ENUM, RETURN, 1, 1, ARG1);
5266 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
5267 def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
5268 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
5269 def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
5270 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
5271 def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
5272 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5273 def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
5274 #define DEF_POINTER_TYPE(ENUM, TYPE) \
5275 builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
5277 #include "builtin-types.def"
5279 #undef DEF_PRIMITIVE_TYPE
5280 #undef DEF_FUNCTION_TYPE_0
5281 #undef DEF_FUNCTION_TYPE_1
5282 #undef DEF_FUNCTION_TYPE_2
5283 #undef DEF_FUNCTION_TYPE_3
5284 #undef DEF_FUNCTION_TYPE_4
5285 #undef DEF_FUNCTION_TYPE_5
5286 #undef DEF_FUNCTION_TYPE_6
5287 #undef DEF_FUNCTION_TYPE_7
5288 #undef DEF_FUNCTION_TYPE_8
5289 #undef DEF_FUNCTION_TYPE_VAR_0
5290 #undef DEF_FUNCTION_TYPE_VAR_1
5291 #undef DEF_FUNCTION_TYPE_VAR_2
5292 #undef DEF_FUNCTION_TYPE_VAR_3
5293 #undef DEF_FUNCTION_TYPE_VAR_4
5294 #undef DEF_FUNCTION_TYPE_VAR_5
5295 #undef DEF_POINTER_TYPE
5296 builtin_types
[(int) BT_LAST
] = NULL_TREE
;
5298 c_init_attributes ();
5300 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P, \
5301 NONANSI_P, ATTRS, IMPLICIT, COND) \
5303 def_builtin_1 (ENUM, NAME, CLASS, \
5304 builtin_types[(int) TYPE], \
5305 builtin_types[(int) LIBTYPE], \
5306 BOTH_P, FALLBACK_P, NONANSI_P, \
5307 built_in_attributes[(int) ATTRS], IMPLICIT);
5308 #include "builtins.def"
5311 targetm
.init_builtins ();
5313 build_common_builtin_nodes ();
5316 cilk_init_builtins ();
5319 /* Like get_identifier, but avoid warnings about null arguments when
5320 the argument may be NULL for targets where GCC lacks stdint.h type
5324 c_get_ident (const char *id
)
5326 return get_identifier (id
);
5329 /* Build tree nodes and builtin functions common to both C and C++ language
5333 c_common_nodes_and_builtins (void)
5335 int char16_type_size
;
5336 int char32_type_size
;
5337 int wchar_type_size
;
5338 tree array_domain_type
;
5339 tree va_list_ref_type_node
;
5340 tree va_list_arg_type_node
;
5342 build_common_tree_nodes (flag_signed_char
, flag_short_double
);
5344 /* Define `int' and `char' first so that dbx will output them first. */
5345 record_builtin_type (RID_INT
, NULL
, integer_type_node
);
5346 record_builtin_type (RID_CHAR
, "char", char_type_node
);
5348 /* `signed' is the same as `int'. FIXME: the declarations of "signed",
5349 "unsigned long", "long long unsigned" and "unsigned short" were in C++
5350 but not C. Are the conditionals here needed? */
5351 if (c_dialect_cxx ())
5352 record_builtin_type (RID_SIGNED
, NULL
, integer_type_node
);
5353 record_builtin_type (RID_LONG
, "long int", long_integer_type_node
);
5354 record_builtin_type (RID_UNSIGNED
, "unsigned int", unsigned_type_node
);
5355 record_builtin_type (RID_MAX
, "long unsigned int",
5356 long_unsigned_type_node
);
5357 if (int128_integer_type_node
!= NULL_TREE
)
5359 record_builtin_type (RID_INT128
, "__int128",
5360 int128_integer_type_node
);
5361 record_builtin_type (RID_MAX
, "__int128 unsigned",
5362 int128_unsigned_type_node
);
5364 if (c_dialect_cxx ())
5365 record_builtin_type (RID_MAX
, "unsigned long", long_unsigned_type_node
);
5366 record_builtin_type (RID_MAX
, "long long int",
5367 long_long_integer_type_node
);
5368 record_builtin_type (RID_MAX
, "long long unsigned int",
5369 long_long_unsigned_type_node
);
5370 if (c_dialect_cxx ())
5371 record_builtin_type (RID_MAX
, "long long unsigned",
5372 long_long_unsigned_type_node
);
5373 record_builtin_type (RID_SHORT
, "short int", short_integer_type_node
);
5374 record_builtin_type (RID_MAX
, "short unsigned int",
5375 short_unsigned_type_node
);
5376 if (c_dialect_cxx ())
5377 record_builtin_type (RID_MAX
, "unsigned short",
5378 short_unsigned_type_node
);
5380 /* Define both `signed char' and `unsigned char'. */
5381 record_builtin_type (RID_MAX
, "signed char", signed_char_type_node
);
5382 record_builtin_type (RID_MAX
, "unsigned char", unsigned_char_type_node
);
5384 /* These are types that c_common_type_for_size and
5385 c_common_type_for_mode use. */
5386 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5387 TYPE_DECL
, NULL_TREE
,
5389 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5390 TYPE_DECL
, NULL_TREE
,
5392 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5393 TYPE_DECL
, NULL_TREE
,
5395 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5396 TYPE_DECL
, NULL_TREE
,
5398 #if HOST_BITS_PER_WIDE_INT >= 64
5399 if (targetm
.scalar_mode_supported_p (TImode
))
5400 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5402 get_identifier ("__int128_t"),
5405 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5406 TYPE_DECL
, NULL_TREE
,
5407 unsigned_intQI_type_node
));
5408 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5409 TYPE_DECL
, NULL_TREE
,
5410 unsigned_intHI_type_node
));
5411 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5412 TYPE_DECL
, NULL_TREE
,
5413 unsigned_intSI_type_node
));
5414 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5415 TYPE_DECL
, NULL_TREE
,
5416 unsigned_intDI_type_node
));
5417 #if HOST_BITS_PER_WIDE_INT >= 64
5418 if (targetm
.scalar_mode_supported_p (TImode
))
5419 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5421 get_identifier ("__uint128_t"),
5422 unsigned_intTI_type_node
));
5425 /* Create the widest literal types. */
5426 widest_integer_literal_type_node
5427 = make_signed_type (HOST_BITS_PER_WIDE_INT
* 2);
5428 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5429 TYPE_DECL
, NULL_TREE
,
5430 widest_integer_literal_type_node
));
5432 widest_unsigned_literal_type_node
5433 = make_unsigned_type (HOST_BITS_PER_WIDE_INT
* 2);
5434 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5435 TYPE_DECL
, NULL_TREE
,
5436 widest_unsigned_literal_type_node
));
5438 signed_size_type_node
= c_common_signed_type (size_type_node
);
5441 TREE_TYPE (identifier_global_value (get_identifier (PID_TYPE
)));
5443 record_builtin_type (RID_FLOAT
, NULL
, float_type_node
);
5444 record_builtin_type (RID_DOUBLE
, NULL
, double_type_node
);
5445 record_builtin_type (RID_MAX
, "long double", long_double_type_node
);
5447 /* Only supported decimal floating point extension if the target
5448 actually supports underlying modes. */
5449 if (targetm
.scalar_mode_supported_p (SDmode
)
5450 && targetm
.scalar_mode_supported_p (DDmode
)
5451 && targetm
.scalar_mode_supported_p (TDmode
))
5453 record_builtin_type (RID_DFLOAT32
, NULL
, dfloat32_type_node
);
5454 record_builtin_type (RID_DFLOAT64
, NULL
, dfloat64_type_node
);
5455 record_builtin_type (RID_DFLOAT128
, NULL
, dfloat128_type_node
);
5458 if (targetm
.fixed_point_supported_p ())
5460 record_builtin_type (RID_MAX
, "short _Fract", short_fract_type_node
);
5461 record_builtin_type (RID_FRACT
, NULL
, fract_type_node
);
5462 record_builtin_type (RID_MAX
, "long _Fract", long_fract_type_node
);
5463 record_builtin_type (RID_MAX
, "long long _Fract",
5464 long_long_fract_type_node
);
5465 record_builtin_type (RID_MAX
, "unsigned short _Fract",
5466 unsigned_short_fract_type_node
);
5467 record_builtin_type (RID_MAX
, "unsigned _Fract",
5468 unsigned_fract_type_node
);
5469 record_builtin_type (RID_MAX
, "unsigned long _Fract",
5470 unsigned_long_fract_type_node
);
5471 record_builtin_type (RID_MAX
, "unsigned long long _Fract",
5472 unsigned_long_long_fract_type_node
);
5473 record_builtin_type (RID_MAX
, "_Sat short _Fract",
5474 sat_short_fract_type_node
);
5475 record_builtin_type (RID_MAX
, "_Sat _Fract", sat_fract_type_node
);
5476 record_builtin_type (RID_MAX
, "_Sat long _Fract",
5477 sat_long_fract_type_node
);
5478 record_builtin_type (RID_MAX
, "_Sat long long _Fract",
5479 sat_long_long_fract_type_node
);
5480 record_builtin_type (RID_MAX
, "_Sat unsigned short _Fract",
5481 sat_unsigned_short_fract_type_node
);
5482 record_builtin_type (RID_MAX
, "_Sat unsigned _Fract",
5483 sat_unsigned_fract_type_node
);
5484 record_builtin_type (RID_MAX
, "_Sat unsigned long _Fract",
5485 sat_unsigned_long_fract_type_node
);
5486 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Fract",
5487 sat_unsigned_long_long_fract_type_node
);
5488 record_builtin_type (RID_MAX
, "short _Accum", short_accum_type_node
);
5489 record_builtin_type (RID_ACCUM
, NULL
, accum_type_node
);
5490 record_builtin_type (RID_MAX
, "long _Accum", long_accum_type_node
);
5491 record_builtin_type (RID_MAX
, "long long _Accum",
5492 long_long_accum_type_node
);
5493 record_builtin_type (RID_MAX
, "unsigned short _Accum",
5494 unsigned_short_accum_type_node
);
5495 record_builtin_type (RID_MAX
, "unsigned _Accum",
5496 unsigned_accum_type_node
);
5497 record_builtin_type (RID_MAX
, "unsigned long _Accum",
5498 unsigned_long_accum_type_node
);
5499 record_builtin_type (RID_MAX
, "unsigned long long _Accum",
5500 unsigned_long_long_accum_type_node
);
5501 record_builtin_type (RID_MAX
, "_Sat short _Accum",
5502 sat_short_accum_type_node
);
5503 record_builtin_type (RID_MAX
, "_Sat _Accum", sat_accum_type_node
);
5504 record_builtin_type (RID_MAX
, "_Sat long _Accum",
5505 sat_long_accum_type_node
);
5506 record_builtin_type (RID_MAX
, "_Sat long long _Accum",
5507 sat_long_long_accum_type_node
);
5508 record_builtin_type (RID_MAX
, "_Sat unsigned short _Accum",
5509 sat_unsigned_short_accum_type_node
);
5510 record_builtin_type (RID_MAX
, "_Sat unsigned _Accum",
5511 sat_unsigned_accum_type_node
);
5512 record_builtin_type (RID_MAX
, "_Sat unsigned long _Accum",
5513 sat_unsigned_long_accum_type_node
);
5514 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Accum",
5515 sat_unsigned_long_long_accum_type_node
);
5519 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5521 get_identifier ("complex int"),
5522 complex_integer_type_node
));
5523 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5525 get_identifier ("complex float"),
5526 complex_float_type_node
));
5527 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5529 get_identifier ("complex double"),
5530 complex_double_type_node
));
5531 lang_hooks
.decls
.pushdecl
5532 (build_decl (UNKNOWN_LOCATION
,
5533 TYPE_DECL
, get_identifier ("complex long double"),
5534 complex_long_double_type_node
));
5536 if (c_dialect_cxx ())
5537 /* For C++, make fileptr_type_node a distinct void * type until
5538 FILE type is defined. */
5539 fileptr_type_node
= build_variant_type_copy (ptr_type_node
);
5541 record_builtin_type (RID_VOID
, NULL
, void_type_node
);
5543 /* Set the TYPE_NAME for any variants that were built before
5544 record_builtin_type gave names to the built-in types. */
5546 tree void_name
= TYPE_NAME (void_type_node
);
5547 TYPE_NAME (void_type_node
) = NULL_TREE
;
5548 TYPE_NAME (build_qualified_type (void_type_node
, TYPE_QUAL_CONST
))
5550 TYPE_NAME (void_type_node
) = void_name
;
5553 void_list_node
= build_void_list_node ();
5555 /* Make a type to be the domain of a few array types
5556 whose domains don't really matter.
5557 200 is small enough that it always fits in size_t
5558 and large enough that it can hold most function names for the
5559 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
5560 array_domain_type
= build_index_type (size_int (200));
5562 /* Make a type for arrays of characters.
5563 With luck nothing will ever really depend on the length of this
5565 char_array_type_node
5566 = build_array_type (char_type_node
, array_domain_type
);
5568 string_type_node
= build_pointer_type (char_type_node
);
5569 const_string_type_node
5570 = build_pointer_type (build_qualified_type
5571 (char_type_node
, TYPE_QUAL_CONST
));
5573 /* This is special for C++ so functions can be overloaded. */
5574 wchar_type_node
= get_identifier (MODIFIED_WCHAR_TYPE
);
5575 wchar_type_node
= TREE_TYPE (identifier_global_value (wchar_type_node
));
5576 wchar_type_size
= TYPE_PRECISION (wchar_type_node
);
5577 underlying_wchar_type_node
= wchar_type_node
;
5578 if (c_dialect_cxx ())
5580 if (TYPE_UNSIGNED (wchar_type_node
))
5581 wchar_type_node
= make_unsigned_type (wchar_type_size
);
5583 wchar_type_node
= make_signed_type (wchar_type_size
);
5584 record_builtin_type (RID_WCHAR
, "wchar_t", wchar_type_node
);
5587 /* This is for wide string constants. */
5588 wchar_array_type_node
5589 = build_array_type (wchar_type_node
, array_domain_type
);
5591 /* Define 'char16_t'. */
5592 char16_type_node
= get_identifier (CHAR16_TYPE
);
5593 char16_type_node
= TREE_TYPE (identifier_global_value (char16_type_node
));
5594 char16_type_size
= TYPE_PRECISION (char16_type_node
);
5595 if (c_dialect_cxx ())
5597 char16_type_node
= make_unsigned_type (char16_type_size
);
5599 if (cxx_dialect
>= cxx11
)
5600 record_builtin_type (RID_CHAR16
, "char16_t", char16_type_node
);
5603 /* This is for UTF-16 string constants. */
5604 char16_array_type_node
5605 = build_array_type (char16_type_node
, array_domain_type
);
5607 /* Define 'char32_t'. */
5608 char32_type_node
= get_identifier (CHAR32_TYPE
);
5609 char32_type_node
= TREE_TYPE (identifier_global_value (char32_type_node
));
5610 char32_type_size
= TYPE_PRECISION (char32_type_node
);
5611 if (c_dialect_cxx ())
5613 char32_type_node
= make_unsigned_type (char32_type_size
);
5615 if (cxx_dialect
>= cxx11
)
5616 record_builtin_type (RID_CHAR32
, "char32_t", char32_type_node
);
5619 /* This is for UTF-32 string constants. */
5620 char32_array_type_node
5621 = build_array_type (char32_type_node
, array_domain_type
);
5624 TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE
)));
5627 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE
)));
5629 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE
)));
5631 if (SIG_ATOMIC_TYPE
)
5632 sig_atomic_type_node
=
5633 TREE_TYPE (identifier_global_value (c_get_ident (SIG_ATOMIC_TYPE
)));
5636 TREE_TYPE (identifier_global_value (c_get_ident (INT8_TYPE
)));
5639 TREE_TYPE (identifier_global_value (c_get_ident (INT16_TYPE
)));
5642 TREE_TYPE (identifier_global_value (c_get_ident (INT32_TYPE
)));
5645 TREE_TYPE (identifier_global_value (c_get_ident (INT64_TYPE
)));
5648 TREE_TYPE (identifier_global_value (c_get_ident (UINT8_TYPE
)));
5650 c_uint16_type_node
= uint16_type_node
=
5651 TREE_TYPE (identifier_global_value (c_get_ident (UINT16_TYPE
)));
5653 c_uint32_type_node
= uint32_type_node
=
5654 TREE_TYPE (identifier_global_value (c_get_ident (UINT32_TYPE
)));
5656 c_uint64_type_node
= uint64_type_node
=
5657 TREE_TYPE (identifier_global_value (c_get_ident (UINT64_TYPE
)));
5658 if (INT_LEAST8_TYPE
)
5659 int_least8_type_node
=
5660 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST8_TYPE
)));
5661 if (INT_LEAST16_TYPE
)
5662 int_least16_type_node
=
5663 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST16_TYPE
)));
5664 if (INT_LEAST32_TYPE
)
5665 int_least32_type_node
=
5666 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST32_TYPE
)));
5667 if (INT_LEAST64_TYPE
)
5668 int_least64_type_node
=
5669 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST64_TYPE
)));
5670 if (UINT_LEAST8_TYPE
)
5671 uint_least8_type_node
=
5672 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST8_TYPE
)));
5673 if (UINT_LEAST16_TYPE
)
5674 uint_least16_type_node
=
5675 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST16_TYPE
)));
5676 if (UINT_LEAST32_TYPE
)
5677 uint_least32_type_node
=
5678 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST32_TYPE
)));
5679 if (UINT_LEAST64_TYPE
)
5680 uint_least64_type_node
=
5681 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST64_TYPE
)));
5683 int_fast8_type_node
=
5684 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST8_TYPE
)));
5685 if (INT_FAST16_TYPE
)
5686 int_fast16_type_node
=
5687 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST16_TYPE
)));
5688 if (INT_FAST32_TYPE
)
5689 int_fast32_type_node
=
5690 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST32_TYPE
)));
5691 if (INT_FAST64_TYPE
)
5692 int_fast64_type_node
=
5693 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST64_TYPE
)));
5694 if (UINT_FAST8_TYPE
)
5695 uint_fast8_type_node
=
5696 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST8_TYPE
)));
5697 if (UINT_FAST16_TYPE
)
5698 uint_fast16_type_node
=
5699 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST16_TYPE
)));
5700 if (UINT_FAST32_TYPE
)
5701 uint_fast32_type_node
=
5702 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST32_TYPE
)));
5703 if (UINT_FAST64_TYPE
)
5704 uint_fast64_type_node
=
5705 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST64_TYPE
)));
5708 TREE_TYPE (identifier_global_value (c_get_ident (INTPTR_TYPE
)));
5711 TREE_TYPE (identifier_global_value (c_get_ident (UINTPTR_TYPE
)));
5713 default_function_type
5714 = build_varargs_function_type_list (integer_type_node
, NULL_TREE
);
5716 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE
)));
5717 unsigned_ptrdiff_type_node
= c_common_unsigned_type (ptrdiff_type_node
);
5719 lang_hooks
.decls
.pushdecl
5720 (build_decl (UNKNOWN_LOCATION
,
5721 TYPE_DECL
, get_identifier ("__builtin_va_list"),
5722 va_list_type_node
));
5723 if (targetm
.enum_va_list_p
)
5729 for (l
= 0; targetm
.enum_va_list_p (l
, &pname
, &ptype
); ++l
)
5731 lang_hooks
.decls
.pushdecl
5732 (build_decl (UNKNOWN_LOCATION
,
5733 TYPE_DECL
, get_identifier (pname
),
5739 if (TREE_CODE (va_list_type_node
) == ARRAY_TYPE
)
5741 va_list_arg_type_node
= va_list_ref_type_node
=
5742 build_pointer_type (TREE_TYPE (va_list_type_node
));
5746 va_list_arg_type_node
= va_list_type_node
;
5747 va_list_ref_type_node
= build_reference_type (va_list_type_node
);
5750 if (!flag_preprocess_only
)
5751 c_define_builtins (va_list_ref_type_node
, va_list_arg_type_node
);
5753 main_identifier_node
= get_identifier ("main");
5755 /* Create the built-in __null node. It is important that this is
5757 null_node
= make_int_cst (1, 1);
5758 TREE_TYPE (null_node
) = c_common_type_for_size (POINTER_SIZE
, 0);
5760 /* Since builtin_types isn't gc'ed, don't export these nodes. */
5761 memset (builtin_types
, 0, sizeof (builtin_types
));
5764 /* The number of named compound-literals generated thus far. */
5765 static GTY(()) int compound_literal_number
;
5767 /* Set DECL_NAME for DECL, a VAR_DECL for a compound-literal. */
5770 set_compound_literal_name (tree decl
)
5773 ASM_FORMAT_PRIVATE_NAME (name
, "__compound_literal",
5774 compound_literal_number
);
5775 compound_literal_number
++;
5776 DECL_NAME (decl
) = get_identifier (name
);
5780 build_va_arg (location_t loc
, tree expr
, tree type
)
5782 expr
= build1 (VA_ARG_EXPR
, type
, expr
);
5783 SET_EXPR_LOCATION (expr
, loc
);
5788 /* Linked list of disabled built-in functions. */
5790 typedef struct disabled_builtin
5793 struct disabled_builtin
*next
;
5795 static disabled_builtin
*disabled_builtins
= NULL
;
5797 static bool builtin_function_disabled_p (const char *);
5799 /* Disable a built-in function specified by -fno-builtin-NAME. If NAME
5800 begins with "__builtin_", give an error. */
5803 disable_builtin_function (const char *name
)
5805 if (strncmp (name
, "__builtin_", strlen ("__builtin_")) == 0)
5806 error ("cannot disable built-in function %qs", name
);
5809 disabled_builtin
*new_disabled_builtin
= XNEW (disabled_builtin
);
5810 new_disabled_builtin
->name
= name
;
5811 new_disabled_builtin
->next
= disabled_builtins
;
5812 disabled_builtins
= new_disabled_builtin
;
5817 /* Return true if the built-in function NAME has been disabled, false
5821 builtin_function_disabled_p (const char *name
)
5823 disabled_builtin
*p
;
5824 for (p
= disabled_builtins
; p
!= NULL
; p
= p
->next
)
5826 if (strcmp (name
, p
->name
) == 0)
5833 /* Worker for DEF_BUILTIN.
5834 Possibly define a builtin function with one or two names.
5835 Does not declare a non-__builtin_ function if flag_no_builtin, or if
5836 nonansi_p and flag_no_nonansi_builtin. */
5839 def_builtin_1 (enum built_in_function fncode
,
5841 enum built_in_class fnclass
,
5842 tree fntype
, tree libtype
,
5843 bool both_p
, bool fallback_p
, bool nonansi_p
,
5844 tree fnattrs
, bool implicit_p
)
5847 const char *libname
;
5849 if (fntype
== error_mark_node
)
5852 gcc_assert ((!both_p
&& !fallback_p
)
5853 || !strncmp (name
, "__builtin_",
5854 strlen ("__builtin_")));
5856 libname
= name
+ strlen ("__builtin_");
5857 decl
= add_builtin_function (name
, fntype
, fncode
, fnclass
,
5858 (fallback_p
? libname
: NULL
),
5861 set_builtin_decl (fncode
, decl
, implicit_p
);
5864 && !flag_no_builtin
&& !builtin_function_disabled_p (libname
)
5865 && !(nonansi_p
&& flag_no_nonansi_builtin
))
5866 add_builtin_function (libname
, libtype
, fncode
, fnclass
,
5870 /* Nonzero if the type T promotes to int. This is (nearly) the
5871 integral promotions defined in ISO C99 6.3.1.1/2. */
5874 c_promoting_integer_type_p (const_tree t
)
5876 switch (TREE_CODE (t
))
5879 return (TYPE_MAIN_VARIANT (t
) == char_type_node
5880 || TYPE_MAIN_VARIANT (t
) == signed_char_type_node
5881 || TYPE_MAIN_VARIANT (t
) == unsigned_char_type_node
5882 || TYPE_MAIN_VARIANT (t
) == short_integer_type_node
5883 || TYPE_MAIN_VARIANT (t
) == short_unsigned_type_node
5884 || TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
));
5887 /* ??? Technically all enumerations not larger than an int
5888 promote to an int. But this is used along code paths
5889 that only want to notice a size change. */
5890 return TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
);
5900 /* Return 1 if PARMS specifies a fixed number of parameters
5901 and none of their types is affected by default promotions. */
5904 self_promoting_args_p (const_tree parms
)
5907 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
5909 tree type
= TREE_VALUE (t
);
5911 if (type
== error_mark_node
)
5914 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
5920 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
5923 if (c_promoting_integer_type_p (type
))
5929 /* Recursively remove any '*' or '&' operator from TYPE. */
5931 strip_pointer_operator (tree t
)
5933 while (POINTER_TYPE_P (t
))
5938 /* Recursively remove pointer or array type from TYPE. */
5940 strip_pointer_or_array_types (tree t
)
5942 while (TREE_CODE (t
) == ARRAY_TYPE
|| POINTER_TYPE_P (t
))
5947 /* Used to compare case labels. K1 and K2 are actually tree nodes
5948 representing case labels, or NULL_TREE for a `default' label.
5949 Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after
5950 K2, and 0 if K1 and K2 are equal. */
5953 case_compare (splay_tree_key k1
, splay_tree_key k2
)
5955 /* Consider a NULL key (such as arises with a `default' label) to be
5956 smaller than anything else. */
5962 return tree_int_cst_compare ((tree
) k1
, (tree
) k2
);
5965 /* Process a case label, located at LOC, for the range LOW_VALUE
5966 ... HIGH_VALUE. If LOW_VALUE and HIGH_VALUE are both NULL_TREE
5967 then this case label is actually a `default' label. If only
5968 HIGH_VALUE is NULL_TREE, then case label was declared using the
5969 usual C/C++ syntax, rather than the GNU case range extension.
5970 CASES is a tree containing all the case ranges processed so far;
5971 COND is the condition for the switch-statement itself. Returns the
5972 CASE_LABEL_EXPR created, or ERROR_MARK_NODE if no CASE_LABEL_EXPR
5976 c_add_case_label (location_t loc
, splay_tree cases
, tree cond
, tree orig_type
,
5977 tree low_value
, tree high_value
)
5982 splay_tree_node node
;
5984 /* Create the LABEL_DECL itself. */
5985 label
= create_artificial_label (loc
);
5987 /* If there was an error processing the switch condition, bail now
5988 before we get more confused. */
5989 if (!cond
|| cond
== error_mark_node
)
5992 if ((low_value
&& TREE_TYPE (low_value
)
5993 && POINTER_TYPE_P (TREE_TYPE (low_value
)))
5994 || (high_value
&& TREE_TYPE (high_value
)
5995 && POINTER_TYPE_P (TREE_TYPE (high_value
))))
5997 error_at (loc
, "pointers are not permitted as case values");
6001 /* Case ranges are a GNU extension. */
6003 pedwarn (loc
, OPT_Wpedantic
,
6004 "range expressions in switch statements are non-standard");
6006 type
= TREE_TYPE (cond
);
6009 low_value
= check_case_value (loc
, low_value
);
6010 low_value
= convert_and_check (loc
, type
, low_value
);
6011 if (low_value
== error_mark_node
)
6016 high_value
= check_case_value (loc
, high_value
);
6017 high_value
= convert_and_check (loc
, type
, high_value
);
6018 if (high_value
== error_mark_node
)
6022 if (low_value
&& high_value
)
6024 /* If the LOW_VALUE and HIGH_VALUE are the same, then this isn't
6025 really a case range, even though it was written that way.
6026 Remove the HIGH_VALUE to simplify later processing. */
6027 if (tree_int_cst_equal (low_value
, high_value
))
6028 high_value
= NULL_TREE
;
6029 else if (!tree_int_cst_lt (low_value
, high_value
))
6030 warning_at (loc
, 0, "empty range specified");
6033 /* See if the case is in range of the type of the original testing
6034 expression. If both low_value and high_value are out of range,
6035 don't insert the case label and return NULL_TREE. */
6037 && !check_case_bounds (loc
, type
, orig_type
,
6038 &low_value
, high_value
? &high_value
: NULL
))
6041 /* Look up the LOW_VALUE in the table of case labels we already
6043 node
= splay_tree_lookup (cases
, (splay_tree_key
) low_value
);
6044 /* If there was not an exact match, check for overlapping ranges.
6045 There's no need to do this if there's no LOW_VALUE or HIGH_VALUE;
6046 that's a `default' label and the only overlap is an exact match. */
6047 if (!node
&& (low_value
|| high_value
))
6049 splay_tree_node low_bound
;
6050 splay_tree_node high_bound
;
6052 /* Even though there wasn't an exact match, there might be an
6053 overlap between this case range and another case range.
6054 Since we've (inductively) not allowed any overlapping case
6055 ranges, we simply need to find the greatest low case label
6056 that is smaller that LOW_VALUE, and the smallest low case
6057 label that is greater than LOW_VALUE. If there is an overlap
6058 it will occur in one of these two ranges. */
6059 low_bound
= splay_tree_predecessor (cases
,
6060 (splay_tree_key
) low_value
);
6061 high_bound
= splay_tree_successor (cases
,
6062 (splay_tree_key
) low_value
);
6064 /* Check to see if the LOW_BOUND overlaps. It is smaller than
6065 the LOW_VALUE, so there is no need to check unless the
6066 LOW_BOUND is in fact itself a case range. */
6068 && CASE_HIGH ((tree
) low_bound
->value
)
6069 && tree_int_cst_compare (CASE_HIGH ((tree
) low_bound
->value
),
6072 /* Check to see if the HIGH_BOUND overlaps. The low end of that
6073 range is bigger than the low end of the current range, so we
6074 are only interested if the current range is a real range, and
6075 not an ordinary case label. */
6078 && (tree_int_cst_compare ((tree
) high_bound
->key
,
6083 /* If there was an overlap, issue an error. */
6086 tree duplicate
= CASE_LABEL ((tree
) node
->value
);
6090 error_at (loc
, "duplicate (or overlapping) case value");
6091 error_at (DECL_SOURCE_LOCATION (duplicate
),
6092 "this is the first entry overlapping that value");
6096 error_at (loc
, "duplicate case value") ;
6097 error_at (DECL_SOURCE_LOCATION (duplicate
), "previously used here");
6101 error_at (loc
, "multiple default labels in one switch");
6102 error_at (DECL_SOURCE_LOCATION (duplicate
),
6103 "this is the first default label");
6108 /* Add a CASE_LABEL to the statement-tree. */
6109 case_label
= add_stmt (build_case_label (low_value
, high_value
, label
));
6110 /* Register this case label in the splay tree. */
6111 splay_tree_insert (cases
,
6112 (splay_tree_key
) low_value
,
6113 (splay_tree_value
) case_label
);
6118 /* Add a label so that the back-end doesn't think that the beginning of
6119 the switch is unreachable. Note that we do not add a case label, as
6120 that just leads to duplicates and thence to failure later on. */
6123 tree t
= create_artificial_label (loc
);
6124 add_stmt (build_stmt (loc
, LABEL_EXPR
, t
));
6126 return error_mark_node
;
6129 /* Subroutines of c_do_switch_warnings, called via splay_tree_foreach.
6130 Used to verify that case values match up with enumerator values. */
6133 match_case_to_enum_1 (tree key
, tree type
, tree label
)
6135 char buf
[WIDE_INT_PRINT_BUFFER_SIZE
];
6137 if (tree_fits_uhwi_p (key
))
6138 print_dec (key
, buf
, UNSIGNED
);
6139 else if (tree_fits_shwi_p (key
))
6140 print_dec (key
, buf
, SIGNED
);
6142 print_hex (key
, buf
);
6144 if (TYPE_NAME (type
) == 0)
6145 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
6146 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
6147 "case value %qs not in enumerated type",
6150 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
6151 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
6152 "case value %qs not in enumerated type %qT",
6156 /* Subroutine of c_do_switch_warnings, called via splay_tree_foreach.
6157 Used to verify that case values match up with enumerator values. */
6160 match_case_to_enum (splay_tree_node node
, void *data
)
6162 tree label
= (tree
) node
->value
;
6163 tree type
= (tree
) data
;
6165 /* Skip default case. */
6166 if (!CASE_LOW (label
))
6169 /* If CASE_LOW_SEEN is not set, that means CASE_LOW did not appear
6170 when we did our enum->case scan. Reset our scratch bit after. */
6171 if (!CASE_LOW_SEEN (label
))
6172 match_case_to_enum_1 (CASE_LOW (label
), type
, label
);
6174 CASE_LOW_SEEN (label
) = 0;
6176 /* If CASE_HIGH is non-null, we have a range. If CASE_HIGH_SEEN is
6177 not set, that means that CASE_HIGH did not appear when we did our
6178 enum->case scan. Reset our scratch bit after. */
6179 if (CASE_HIGH (label
))
6181 if (!CASE_HIGH_SEEN (label
))
6182 match_case_to_enum_1 (CASE_HIGH (label
), type
, label
);
6184 CASE_HIGH_SEEN (label
) = 0;
6190 /* Handle -Wswitch*. Called from the front end after parsing the
6191 switch construct. */
6192 /* ??? Should probably be somewhere generic, since other languages
6193 besides C and C++ would want this. At the moment, however, C/C++
6194 are the only tree-ssa languages that support enumerations at all,
6195 so the point is moot. */
6198 c_do_switch_warnings (splay_tree cases
, location_t switch_location
,
6199 tree type
, tree cond
)
6201 splay_tree_node default_node
;
6202 splay_tree_node node
;
6205 if (!warn_switch
&& !warn_switch_enum
&& !warn_switch_default
)
6208 default_node
= splay_tree_lookup (cases
, (splay_tree_key
) NULL
);
6210 warning_at (switch_location
, OPT_Wswitch_default
,
6211 "switch missing default case");
6213 /* From here on, we only care about about enumerated types. */
6214 if (!type
|| TREE_CODE (type
) != ENUMERAL_TYPE
)
6217 /* From here on, we only care about -Wswitch and -Wswitch-enum. */
6218 if (!warn_switch_enum
&& !warn_switch
)
6221 /* Check the cases. Warn about case values which are not members of
6222 the enumerated type. For -Wswitch-enum, or for -Wswitch when
6223 there is no default case, check that exactly all enumeration
6224 literals are covered by the cases. */
6226 /* Clearing COND if it is not an integer constant simplifies
6227 the tests inside the loop below. */
6228 if (TREE_CODE (cond
) != INTEGER_CST
)
6231 /* The time complexity here is O(N*lg(N)) worst case, but for the
6232 common case of monotonically increasing enumerators, it is
6233 O(N), since the nature of the splay tree will keep the next
6234 element adjacent to the root at all times. */
6236 for (chain
= TYPE_VALUES (type
); chain
; chain
= TREE_CHAIN (chain
))
6238 tree value
= TREE_VALUE (chain
);
6239 if (TREE_CODE (value
) == CONST_DECL
)
6240 value
= DECL_INITIAL (value
);
6241 node
= splay_tree_lookup (cases
, (splay_tree_key
) value
);
6244 /* Mark the CASE_LOW part of the case entry as seen. */
6245 tree label
= (tree
) node
->value
;
6246 CASE_LOW_SEEN (label
) = 1;
6250 /* Even though there wasn't an exact match, there might be a
6251 case range which includes the enumerator's value. */
6252 node
= splay_tree_predecessor (cases
, (splay_tree_key
) value
);
6253 if (node
&& CASE_HIGH ((tree
) node
->value
))
6255 tree label
= (tree
) node
->value
;
6256 int cmp
= tree_int_cst_compare (CASE_HIGH (label
), value
);
6259 /* If we match the upper bound exactly, mark the CASE_HIGH
6260 part of the case entry as seen. */
6262 CASE_HIGH_SEEN (label
) = 1;
6267 /* We've now determined that this enumerated literal isn't
6268 handled by the case labels of the switch statement. */
6270 /* If the switch expression is a constant, we only really care
6271 about whether that constant is handled by the switch. */
6272 if (cond
&& tree_int_cst_compare (cond
, value
))
6275 /* If there is a default_node, the only relevant option is
6276 Wswitch-enum. Otherwise, if both are enabled then we prefer
6277 to warn using -Wswitch because -Wswitch is enabled by -Wall
6278 while -Wswitch-enum is explicit. */
6279 warning_at (switch_location
,
6280 (default_node
|| !warn_switch
6283 "enumeration value %qE not handled in switch",
6284 TREE_PURPOSE (chain
));
6287 /* Warn if there are case expressions that don't correspond to
6288 enumerators. This can occur since C and C++ don't enforce
6289 type-checking of assignments to enumeration variables.
6291 The time complexity here is now always O(N) worst case, since
6292 we should have marked both the lower bound and upper bound of
6293 every disjoint case label, with CASE_LOW_SEEN and CASE_HIGH_SEEN
6294 above. This scan also resets those fields. */
6296 splay_tree_foreach (cases
, match_case_to_enum
, type
);
6299 /* Finish an expression taking the address of LABEL (an
6300 IDENTIFIER_NODE). Returns an expression for the address.
6302 LOC is the location for the expression returned. */
6305 finish_label_address_expr (tree label
, location_t loc
)
6309 pedwarn (input_location
, OPT_Wpedantic
, "taking the address of a label is non-standard");
6311 if (label
== error_mark_node
)
6312 return error_mark_node
;
6314 label
= lookup_label (label
);
6315 if (label
== NULL_TREE
)
6316 result
= null_pointer_node
;
6319 TREE_USED (label
) = 1;
6320 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
6321 /* The current function is not necessarily uninlinable.
6322 Computed gotos are incompatible with inlining, but the value
6323 here could be used only in a diagnostic, for example. */
6324 protected_set_expr_location (result
, loc
);
6331 /* Given a boolean expression ARG, return a tree representing an increment
6332 or decrement (as indicated by CODE) of ARG. The front end must check for
6333 invalid cases (e.g., decrement in C++). */
6335 boolean_increment (enum tree_code code
, tree arg
)
6338 tree true_res
= build_int_cst (TREE_TYPE (arg
), 1);
6340 arg
= stabilize_reference (arg
);
6343 case PREINCREMENT_EXPR
:
6344 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
6346 case POSTINCREMENT_EXPR
:
6347 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
6348 arg
= save_expr (arg
);
6349 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
6350 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
6352 case PREDECREMENT_EXPR
:
6353 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
6354 invert_truthvalue_loc (input_location
, arg
));
6356 case POSTDECREMENT_EXPR
:
6357 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
6358 invert_truthvalue_loc (input_location
, arg
));
6359 arg
= save_expr (arg
);
6360 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
6361 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
6366 TREE_SIDE_EFFECTS (val
) = 1;
6370 /* Built-in macros for stddef.h and stdint.h, that require macros
6371 defined in this file. */
6373 c_stddef_cpp_builtins(void)
6375 builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE
, 0);
6376 builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE
, 0);
6377 builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE
, 0);
6378 builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE
, 0);
6379 builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE
, 0);
6380 builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE
, 0);
6381 builtin_define_with_value ("__CHAR16_TYPE__", CHAR16_TYPE
, 0);
6382 builtin_define_with_value ("__CHAR32_TYPE__", CHAR32_TYPE
, 0);
6383 if (SIG_ATOMIC_TYPE
)
6384 builtin_define_with_value ("__SIG_ATOMIC_TYPE__", SIG_ATOMIC_TYPE
, 0);
6386 builtin_define_with_value ("__INT8_TYPE__", INT8_TYPE
, 0);
6388 builtin_define_with_value ("__INT16_TYPE__", INT16_TYPE
, 0);
6390 builtin_define_with_value ("__INT32_TYPE__", INT32_TYPE
, 0);
6392 builtin_define_with_value ("__INT64_TYPE__", INT64_TYPE
, 0);
6394 builtin_define_with_value ("__UINT8_TYPE__", UINT8_TYPE
, 0);
6396 builtin_define_with_value ("__UINT16_TYPE__", UINT16_TYPE
, 0);
6398 builtin_define_with_value ("__UINT32_TYPE__", UINT32_TYPE
, 0);
6400 builtin_define_with_value ("__UINT64_TYPE__", UINT64_TYPE
, 0);
6401 if (INT_LEAST8_TYPE
)
6402 builtin_define_with_value ("__INT_LEAST8_TYPE__", INT_LEAST8_TYPE
, 0);
6403 if (INT_LEAST16_TYPE
)
6404 builtin_define_with_value ("__INT_LEAST16_TYPE__", INT_LEAST16_TYPE
, 0);
6405 if (INT_LEAST32_TYPE
)
6406 builtin_define_with_value ("__INT_LEAST32_TYPE__", INT_LEAST32_TYPE
, 0);
6407 if (INT_LEAST64_TYPE
)
6408 builtin_define_with_value ("__INT_LEAST64_TYPE__", INT_LEAST64_TYPE
, 0);
6409 if (UINT_LEAST8_TYPE
)
6410 builtin_define_with_value ("__UINT_LEAST8_TYPE__", UINT_LEAST8_TYPE
, 0);
6411 if (UINT_LEAST16_TYPE
)
6412 builtin_define_with_value ("__UINT_LEAST16_TYPE__", UINT_LEAST16_TYPE
, 0);
6413 if (UINT_LEAST32_TYPE
)
6414 builtin_define_with_value ("__UINT_LEAST32_TYPE__", UINT_LEAST32_TYPE
, 0);
6415 if (UINT_LEAST64_TYPE
)
6416 builtin_define_with_value ("__UINT_LEAST64_TYPE__", UINT_LEAST64_TYPE
, 0);
6418 builtin_define_with_value ("__INT_FAST8_TYPE__", INT_FAST8_TYPE
, 0);
6419 if (INT_FAST16_TYPE
)
6420 builtin_define_with_value ("__INT_FAST16_TYPE__", INT_FAST16_TYPE
, 0);
6421 if (INT_FAST32_TYPE
)
6422 builtin_define_with_value ("__INT_FAST32_TYPE__", INT_FAST32_TYPE
, 0);
6423 if (INT_FAST64_TYPE
)
6424 builtin_define_with_value ("__INT_FAST64_TYPE__", INT_FAST64_TYPE
, 0);
6425 if (UINT_FAST8_TYPE
)
6426 builtin_define_with_value ("__UINT_FAST8_TYPE__", UINT_FAST8_TYPE
, 0);
6427 if (UINT_FAST16_TYPE
)
6428 builtin_define_with_value ("__UINT_FAST16_TYPE__", UINT_FAST16_TYPE
, 0);
6429 if (UINT_FAST32_TYPE
)
6430 builtin_define_with_value ("__UINT_FAST32_TYPE__", UINT_FAST32_TYPE
, 0);
6431 if (UINT_FAST64_TYPE
)
6432 builtin_define_with_value ("__UINT_FAST64_TYPE__", UINT_FAST64_TYPE
, 0);
6434 builtin_define_with_value ("__INTPTR_TYPE__", INTPTR_TYPE
, 0);
6436 builtin_define_with_value ("__UINTPTR_TYPE__", UINTPTR_TYPE
, 0);
6440 c_init_attributes (void)
6442 /* Fill in the built_in_attributes array. */
6443 #define DEF_ATTR_NULL_TREE(ENUM) \
6444 built_in_attributes[(int) ENUM] = NULL_TREE;
6445 #define DEF_ATTR_INT(ENUM, VALUE) \
6446 built_in_attributes[(int) ENUM] = build_int_cst (integer_type_node, VALUE);
6447 #define DEF_ATTR_STRING(ENUM, VALUE) \
6448 built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
6449 #define DEF_ATTR_IDENT(ENUM, STRING) \
6450 built_in_attributes[(int) ENUM] = get_identifier (STRING);
6451 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
6452 built_in_attributes[(int) ENUM] \
6453 = tree_cons (built_in_attributes[(int) PURPOSE], \
6454 built_in_attributes[(int) VALUE], \
6455 built_in_attributes[(int) CHAIN]);
6456 #include "builtin-attrs.def"
6457 #undef DEF_ATTR_NULL_TREE
6459 #undef DEF_ATTR_IDENT
6460 #undef DEF_ATTR_TREE_LIST
6463 /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain
6464 identifier as an argument, so the front end shouldn't look it up. */
6467 attribute_takes_identifier_p (const_tree attr_id
)
6469 const struct attribute_spec
*spec
= lookup_attribute_spec (attr_id
);
6471 /* Unknown attribute that we'll end up ignoring, return true so we
6472 don't complain about an identifier argument. */
6474 else if (!strcmp ("mode", spec
->name
)
6475 || !strcmp ("format", spec
->name
)
6476 || !strcmp ("cleanup", spec
->name
))
6479 return targetm
.attribute_takes_identifier_p (attr_id
);
6482 /* Attribute handlers common to C front ends. */
6484 /* Handle a "packed" attribute; arguments as in
6485 struct attribute_spec.handler. */
6488 handle_packed_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6489 int flags
, bool *no_add_attrs
)
6493 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6494 *node
= build_variant_type_copy (*node
);
6495 TYPE_PACKED (*node
) = 1;
6497 else if (TREE_CODE (*node
) == FIELD_DECL
)
6499 if (TYPE_ALIGN (TREE_TYPE (*node
)) <= BITS_PER_UNIT
6500 /* Still pack bitfields. */
6501 && ! DECL_INITIAL (*node
))
6502 warning (OPT_Wattributes
,
6503 "%qE attribute ignored for field of type %qT",
6504 name
, TREE_TYPE (*node
));
6506 DECL_PACKED (*node
) = 1;
6508 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
6509 used for DECL_REGISTER. It wouldn't mean anything anyway.
6510 We can't set DECL_PACKED on the type of a TYPE_DECL, because
6511 that changes what the typedef is typing. */
6514 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6515 *no_add_attrs
= true;
6521 /* Handle a "nocommon" attribute; arguments as in
6522 struct attribute_spec.handler. */
6525 handle_nocommon_attribute (tree
*node
, tree name
,
6526 tree
ARG_UNUSED (args
),
6527 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6529 if (TREE_CODE (*node
) == VAR_DECL
)
6530 DECL_COMMON (*node
) = 0;
6533 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6534 *no_add_attrs
= true;
6540 /* Handle a "common" attribute; arguments as in
6541 struct attribute_spec.handler. */
6544 handle_common_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6545 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6547 if (TREE_CODE (*node
) == VAR_DECL
)
6548 DECL_COMMON (*node
) = 1;
6551 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6552 *no_add_attrs
= true;
6558 /* Handle a "noreturn" attribute; arguments as in
6559 struct attribute_spec.handler. */
6562 handle_noreturn_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6563 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6565 tree type
= TREE_TYPE (*node
);
6567 /* See FIXME comment in c_common_attribute_table. */
6568 if (TREE_CODE (*node
) == FUNCTION_DECL
6569 || objc_method_decl (TREE_CODE (*node
)))
6570 TREE_THIS_VOLATILE (*node
) = 1;
6571 else if (TREE_CODE (type
) == POINTER_TYPE
6572 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
6574 = (build_qualified_type
6576 (build_type_variant (TREE_TYPE (type
),
6577 TYPE_READONLY (TREE_TYPE (type
)), 1)),
6578 TYPE_QUALS (type
)));
6581 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6582 *no_add_attrs
= true;
6588 /* Handle a "hot" and attribute; arguments as in
6589 struct attribute_spec.handler. */
6592 handle_hot_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6593 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6595 if (TREE_CODE (*node
) == FUNCTION_DECL
6596 || TREE_CODE (*node
) == LABEL_DECL
)
6598 if (lookup_attribute ("cold", DECL_ATTRIBUTES (*node
)) != NULL
)
6600 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
6601 "with attribute %qs", name
, "cold");
6602 *no_add_attrs
= true;
6604 /* Most of the rest of the hot processing is done later with
6605 lookup_attribute. */
6609 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6610 *no_add_attrs
= true;
6616 /* Handle a "cold" and attribute; arguments as in
6617 struct attribute_spec.handler. */
6620 handle_cold_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6621 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6623 if (TREE_CODE (*node
) == FUNCTION_DECL
6624 || TREE_CODE (*node
) == LABEL_DECL
)
6626 if (lookup_attribute ("hot", DECL_ATTRIBUTES (*node
)) != NULL
)
6628 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
6629 "with attribute %qs", name
, "hot");
6630 *no_add_attrs
= true;
6632 /* Most of the rest of the cold processing is done later with
6633 lookup_attribute. */
6637 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6638 *no_add_attrs
= true;
6644 /* Handle a "no_sanitize_address" attribute; arguments as in
6645 struct attribute_spec.handler. */
6648 handle_no_sanitize_address_attribute (tree
*node
, tree name
, tree
, int,
6651 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6653 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6654 *no_add_attrs
= true;
6660 /* Handle a "no_address_safety_analysis" attribute; arguments as in
6661 struct attribute_spec.handler. */
6664 handle_no_address_safety_analysis_attribute (tree
*node
, tree name
, tree
, int,
6667 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6668 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6669 else if (!lookup_attribute ("no_sanitize_address", DECL_ATTRIBUTES (*node
)))
6670 DECL_ATTRIBUTES (*node
)
6671 = tree_cons (get_identifier ("no_sanitize_address"),
6672 NULL_TREE
, DECL_ATTRIBUTES (*node
));
6673 *no_add_attrs
= true;
6677 /* Handle a "no_sanitize_undefined" attribute; arguments as in
6678 struct attribute_spec.handler. */
6681 handle_no_sanitize_undefined_attribute (tree
*node
, tree name
, tree
, int,
6684 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6686 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6687 *no_add_attrs
= true;
6693 /* Handle a "noinline" attribute; arguments as in
6694 struct attribute_spec.handler. */
6697 handle_noinline_attribute (tree
*node
, tree name
,
6698 tree
ARG_UNUSED (args
),
6699 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6701 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6703 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node
)))
6705 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
6706 "with attribute %qs", name
, "always_inline");
6707 *no_add_attrs
= true;
6710 DECL_UNINLINABLE (*node
) = 1;
6714 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6715 *no_add_attrs
= true;
6721 /* Handle a "noclone" attribute; arguments as in
6722 struct attribute_spec.handler. */
6725 handle_noclone_attribute (tree
*node
, tree name
,
6726 tree
ARG_UNUSED (args
),
6727 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6729 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6731 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6732 *no_add_attrs
= true;
6738 /* Handle a "always_inline" attribute; arguments as in
6739 struct attribute_spec.handler. */
6742 handle_always_inline_attribute (tree
*node
, tree name
,
6743 tree
ARG_UNUSED (args
),
6744 int ARG_UNUSED (flags
),
6747 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6749 if (lookup_attribute ("noinline", DECL_ATTRIBUTES (*node
)))
6751 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
6752 "with %qs attribute", name
, "noinline");
6753 *no_add_attrs
= true;
6756 /* Set the attribute and mark it for disregarding inline
6758 DECL_DISREGARD_INLINE_LIMITS (*node
) = 1;
6762 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6763 *no_add_attrs
= true;
6769 /* Handle a "gnu_inline" attribute; arguments as in
6770 struct attribute_spec.handler. */
6773 handle_gnu_inline_attribute (tree
*node
, tree name
,
6774 tree
ARG_UNUSED (args
),
6775 int ARG_UNUSED (flags
),
6778 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
6780 /* Do nothing else, just set the attribute. We'll get at
6781 it later with lookup_attribute. */
6785 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6786 *no_add_attrs
= true;
6792 /* Handle a "leaf" attribute; arguments as in
6793 struct attribute_spec.handler. */
6796 handle_leaf_attribute (tree
*node
, tree name
,
6797 tree
ARG_UNUSED (args
),
6798 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6800 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6802 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6803 *no_add_attrs
= true;
6805 if (!TREE_PUBLIC (*node
))
6807 warning (OPT_Wattributes
, "%qE attribute has no effect on unit local functions", name
);
6808 *no_add_attrs
= true;
6814 /* Handle an "artificial" attribute; arguments as in
6815 struct attribute_spec.handler. */
6818 handle_artificial_attribute (tree
*node
, tree name
,
6819 tree
ARG_UNUSED (args
),
6820 int ARG_UNUSED (flags
),
6823 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
6825 /* Do nothing else, just set the attribute. We'll get at
6826 it later with lookup_attribute. */
6830 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6831 *no_add_attrs
= true;
6837 /* Handle a "flatten" attribute; arguments as in
6838 struct attribute_spec.handler. */
6841 handle_flatten_attribute (tree
*node
, tree name
,
6842 tree args ATTRIBUTE_UNUSED
,
6843 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
6845 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6846 /* Do nothing else, just set the attribute. We'll get at
6847 it later with lookup_attribute. */
6851 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6852 *no_add_attrs
= true;
6858 /* Handle a "warning" or "error" attribute; arguments as in
6859 struct attribute_spec.handler. */
6862 handle_error_attribute (tree
*node
, tree name
, tree args
,
6863 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6865 if (TREE_CODE (*node
) == FUNCTION_DECL
6866 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
6867 /* Do nothing else, just set the attribute. We'll get at
6868 it later with lookup_attribute. */
6872 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6873 *no_add_attrs
= true;
6879 /* Handle a "used" attribute; arguments as in
6880 struct attribute_spec.handler. */
6883 handle_used_attribute (tree
*pnode
, tree name
, tree
ARG_UNUSED (args
),
6884 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6888 if (TREE_CODE (node
) == FUNCTION_DECL
6889 || (TREE_CODE (node
) == VAR_DECL
&& TREE_STATIC (node
))
6890 || (TREE_CODE (node
) == TYPE_DECL
))
6892 TREE_USED (node
) = 1;
6893 DECL_PRESERVE_P (node
) = 1;
6894 if (TREE_CODE (node
) == VAR_DECL
)
6895 DECL_READ_P (node
) = 1;
6899 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6900 *no_add_attrs
= true;
6906 /* Handle a "unused" attribute; arguments as in
6907 struct attribute_spec.handler. */
6910 handle_unused_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6911 int flags
, bool *no_add_attrs
)
6917 if (TREE_CODE (decl
) == PARM_DECL
6918 || TREE_CODE (decl
) == VAR_DECL
6919 || TREE_CODE (decl
) == FUNCTION_DECL
6920 || TREE_CODE (decl
) == LABEL_DECL
6921 || TREE_CODE (decl
) == TYPE_DECL
)
6923 TREE_USED (decl
) = 1;
6924 if (TREE_CODE (decl
) == VAR_DECL
6925 || TREE_CODE (decl
) == PARM_DECL
)
6926 DECL_READ_P (decl
) = 1;
6930 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6931 *no_add_attrs
= true;
6936 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6937 *node
= build_variant_type_copy (*node
);
6938 TREE_USED (*node
) = 1;
6944 /* Handle a "externally_visible" attribute; arguments as in
6945 struct attribute_spec.handler. */
6948 handle_externally_visible_attribute (tree
*pnode
, tree name
,
6949 tree
ARG_UNUSED (args
),
6950 int ARG_UNUSED (flags
),
6955 if (TREE_CODE (node
) == FUNCTION_DECL
|| TREE_CODE (node
) == VAR_DECL
)
6957 if ((!TREE_STATIC (node
) && TREE_CODE (node
) != FUNCTION_DECL
6958 && !DECL_EXTERNAL (node
)) || !TREE_PUBLIC (node
))
6960 warning (OPT_Wattributes
,
6961 "%qE attribute have effect only on public objects", name
);
6962 *no_add_attrs
= true;
6967 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6968 *no_add_attrs
= true;
6974 /* Handle the "no_reorder" attribute. Arguments as in
6975 struct attribute_spec.handler. */
6978 handle_no_reorder_attribute (tree
*pnode
,
6986 if ((TREE_CODE (node
) != FUNCTION_DECL
&& TREE_CODE (node
) != VAR_DECL
)
6987 && !(TREE_STATIC (node
) || DECL_EXTERNAL (node
)))
6989 warning (OPT_Wattributes
,
6990 "%qE attribute only affects top level objects",
6992 *no_add_attrs
= true;
6998 /* Handle a "const" attribute; arguments as in
6999 struct attribute_spec.handler. */
7002 handle_const_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7003 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7005 tree type
= TREE_TYPE (*node
);
7007 /* See FIXME comment on noreturn in c_common_attribute_table. */
7008 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7009 TREE_READONLY (*node
) = 1;
7010 else if (TREE_CODE (type
) == POINTER_TYPE
7011 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
7013 = (build_qualified_type
7015 (build_type_variant (TREE_TYPE (type
), 1,
7016 TREE_THIS_VOLATILE (TREE_TYPE (type
)))),
7017 TYPE_QUALS (type
)));
7020 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7021 *no_add_attrs
= true;
7027 /* Handle a "transparent_union" attribute; arguments as in
7028 struct attribute_spec.handler. */
7031 handle_transparent_union_attribute (tree
*node
, tree name
,
7032 tree
ARG_UNUSED (args
), int flags
,
7037 *no_add_attrs
= true;
7040 if (TREE_CODE (*node
) == TYPE_DECL
7041 && ! (flags
& ATTR_FLAG_CXX11
))
7042 node
= &TREE_TYPE (*node
);
7045 if (TREE_CODE (type
) == UNION_TYPE
)
7047 /* Make sure that the first field will work for a transparent union.
7048 If the type isn't complete yet, leave the check to the code in
7050 if (TYPE_SIZE (type
))
7052 tree first
= first_field (type
);
7053 if (first
== NULL_TREE
7054 || DECL_ARTIFICIAL (first
)
7055 || TYPE_MODE (type
) != DECL_MODE (first
))
7059 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7061 /* If the type isn't complete yet, setting the flag
7062 on a variant wouldn't ever be checked. */
7063 if (!TYPE_SIZE (type
))
7066 /* build_duplicate_type doesn't work for C++. */
7067 if (c_dialect_cxx ())
7070 /* A type variant isn't good enough, since we don't a cast
7071 to such a type removed as a no-op. */
7072 *node
= type
= build_duplicate_type (type
);
7075 TYPE_TRANSPARENT_AGGR (type
) = 1;
7080 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7084 /* Subroutine of handle_{con,de}structor_attribute. Evaluate ARGS to
7085 get the requested priority for a constructor or destructor,
7086 possibly issuing diagnostics for invalid or reserved
7089 static priority_type
7090 get_priority (tree args
, bool is_destructor
)
7096 return DEFAULT_INIT_PRIORITY
;
7098 if (!SUPPORTS_INIT_PRIORITY
)
7101 error ("destructor priorities are not supported");
7103 error ("constructor priorities are not supported");
7104 return DEFAULT_INIT_PRIORITY
;
7107 arg
= TREE_VALUE (args
);
7108 if (TREE_CODE (arg
) == IDENTIFIER_NODE
)
7110 if (arg
== error_mark_node
)
7111 return DEFAULT_INIT_PRIORITY
;
7112 arg
= default_conversion (arg
);
7113 if (!tree_fits_shwi_p (arg
)
7114 || !INTEGRAL_TYPE_P (TREE_TYPE (arg
)))
7117 pri
= tree_to_shwi (arg
);
7118 if (pri
< 0 || pri
> MAX_INIT_PRIORITY
)
7121 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
7125 "destructor priorities from 0 to %d are reserved "
7126 "for the implementation",
7127 MAX_RESERVED_INIT_PRIORITY
);
7130 "constructor priorities from 0 to %d are reserved "
7131 "for the implementation",
7132 MAX_RESERVED_INIT_PRIORITY
);
7138 error ("destructor priorities must be integers from 0 to %d inclusive",
7141 error ("constructor priorities must be integers from 0 to %d inclusive",
7143 return DEFAULT_INIT_PRIORITY
;
7146 /* Handle a "constructor" attribute; arguments as in
7147 struct attribute_spec.handler. */
7150 handle_constructor_attribute (tree
*node
, tree name
, tree args
,
7151 int ARG_UNUSED (flags
),
7155 tree type
= TREE_TYPE (decl
);
7157 if (TREE_CODE (decl
) == FUNCTION_DECL
7158 && TREE_CODE (type
) == FUNCTION_TYPE
7159 && decl_function_context (decl
) == 0)
7161 priority_type priority
;
7162 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
7163 priority
= get_priority (args
, /*is_destructor=*/false);
7164 SET_DECL_INIT_PRIORITY (decl
, priority
);
7165 TREE_USED (decl
) = 1;
7169 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7170 *no_add_attrs
= true;
7176 /* Handle a "destructor" attribute; arguments as in
7177 struct attribute_spec.handler. */
7180 handle_destructor_attribute (tree
*node
, tree name
, tree args
,
7181 int ARG_UNUSED (flags
),
7185 tree type
= TREE_TYPE (decl
);
7187 if (TREE_CODE (decl
) == FUNCTION_DECL
7188 && TREE_CODE (type
) == FUNCTION_TYPE
7189 && decl_function_context (decl
) == 0)
7191 priority_type priority
;
7192 DECL_STATIC_DESTRUCTOR (decl
) = 1;
7193 priority
= get_priority (args
, /*is_destructor=*/true);
7194 SET_DECL_FINI_PRIORITY (decl
, priority
);
7195 TREE_USED (decl
) = 1;
7199 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7200 *no_add_attrs
= true;
7206 /* Nonzero if the mode is a valid vector mode for this architecture.
7207 This returns nonzero even if there is no hardware support for the
7208 vector mode, but we can emulate with narrower modes. */
7211 vector_mode_valid_p (enum machine_mode mode
)
7213 enum mode_class mclass
= GET_MODE_CLASS (mode
);
7214 enum machine_mode innermode
;
7216 /* Doh! What's going on? */
7217 if (mclass
!= MODE_VECTOR_INT
7218 && mclass
!= MODE_VECTOR_FLOAT
7219 && mclass
!= MODE_VECTOR_FRACT
7220 && mclass
!= MODE_VECTOR_UFRACT
7221 && mclass
!= MODE_VECTOR_ACCUM
7222 && mclass
!= MODE_VECTOR_UACCUM
)
7225 /* Hardware support. Woo hoo! */
7226 if (targetm
.vector_mode_supported_p (mode
))
7229 innermode
= GET_MODE_INNER (mode
);
7231 /* We should probably return 1 if requesting V4DI and we have no DI,
7232 but we have V2DI, but this is probably very unlikely. */
7234 /* If we have support for the inner mode, we can safely emulate it.
7235 We may not have V2DI, but me can emulate with a pair of DIs. */
7236 return targetm
.scalar_mode_supported_p (innermode
);
7240 /* Handle a "mode" attribute; arguments as in
7241 struct attribute_spec.handler. */
7244 handle_mode_attribute (tree
*node
, tree name
, tree args
,
7245 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7248 tree ident
= TREE_VALUE (args
);
7250 *no_add_attrs
= true;
7252 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
7253 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7257 const char *p
= IDENTIFIER_POINTER (ident
);
7258 int len
= strlen (p
);
7259 enum machine_mode mode
= VOIDmode
;
7263 if (len
> 4 && p
[0] == '_' && p
[1] == '_'
7264 && p
[len
- 1] == '_' && p
[len
- 2] == '_')
7266 char *newp
= (char *) alloca (len
- 1);
7268 strcpy (newp
, &p
[2]);
7269 newp
[len
- 4] = '\0';
7273 /* Change this type to have a type with the specified mode.
7274 First check for the special modes. */
7275 if (!strcmp (p
, "byte"))
7277 else if (!strcmp (p
, "word"))
7279 else if (!strcmp (p
, "pointer"))
7281 else if (!strcmp (p
, "libgcc_cmp_return"))
7282 mode
= targetm
.libgcc_cmp_return_mode ();
7283 else if (!strcmp (p
, "libgcc_shift_count"))
7284 mode
= targetm
.libgcc_shift_count_mode ();
7285 else if (!strcmp (p
, "unwind_word"))
7286 mode
= targetm
.unwind_word_mode ();
7288 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
7289 if (!strcmp (p
, GET_MODE_NAME (j
)))
7291 mode
= (enum machine_mode
) j
;
7295 if (mode
== VOIDmode
)
7297 error ("unknown machine mode %qE", ident
);
7302 switch (GET_MODE_CLASS (mode
))
7305 case MODE_PARTIAL_INT
:
7307 case MODE_DECIMAL_FLOAT
:
7312 valid_mode
= targetm
.scalar_mode_supported_p (mode
);
7315 case MODE_COMPLEX_INT
:
7316 case MODE_COMPLEX_FLOAT
:
7317 valid_mode
= targetm
.scalar_mode_supported_p (GET_MODE_INNER (mode
));
7320 case MODE_VECTOR_INT
:
7321 case MODE_VECTOR_FLOAT
:
7322 case MODE_VECTOR_FRACT
:
7323 case MODE_VECTOR_UFRACT
:
7324 case MODE_VECTOR_ACCUM
:
7325 case MODE_VECTOR_UACCUM
:
7326 warning (OPT_Wattributes
, "specifying vector types with "
7327 "__attribute__ ((mode)) is deprecated");
7328 warning (OPT_Wattributes
,
7329 "use __attribute__ ((vector_size)) instead");
7330 valid_mode
= vector_mode_valid_p (mode
);
7338 error ("unable to emulate %qs", p
);
7342 if (POINTER_TYPE_P (type
))
7344 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
7345 tree (*fn
)(tree
, enum machine_mode
, bool);
7347 if (!targetm
.addr_space
.valid_pointer_mode (mode
, as
))
7349 error ("invalid pointer mode %qs", p
);
7353 if (TREE_CODE (type
) == POINTER_TYPE
)
7354 fn
= build_pointer_type_for_mode
;
7356 fn
= build_reference_type_for_mode
;
7357 typefm
= fn (TREE_TYPE (type
), mode
, false);
7361 /* For fixed-point modes, we need to test if the signness of type
7362 and the machine mode are consistent. */
7363 if (ALL_FIXED_POINT_MODE_P (mode
)
7364 && TYPE_UNSIGNED (type
) != UNSIGNED_FIXED_POINT_MODE_P (mode
))
7366 error ("signedness of type and machine mode %qs don%'t match", p
);
7369 /* For fixed-point modes, we need to pass saturating info. */
7370 typefm
= lang_hooks
.types
.type_for_mode (mode
,
7371 ALL_FIXED_POINT_MODE_P (mode
) ? TYPE_SATURATING (type
)
7372 : TYPE_UNSIGNED (type
));
7375 if (typefm
== NULL_TREE
)
7377 error ("no data type for mode %qs", p
);
7380 else if (TREE_CODE (type
) == ENUMERAL_TYPE
)
7382 /* For enumeral types, copy the precision from the integer
7383 type returned above. If not an INTEGER_TYPE, we can't use
7384 this mode for this type. */
7385 if (TREE_CODE (typefm
) != INTEGER_TYPE
)
7387 error ("cannot use mode %qs for enumeral types", p
);
7391 if (flags
& ATTR_FLAG_TYPE_IN_PLACE
)
7393 TYPE_PRECISION (type
) = TYPE_PRECISION (typefm
);
7398 /* We cannot build a type variant, as there's code that assumes
7399 that TYPE_MAIN_VARIANT has the same mode. This includes the
7400 debug generators. Instead, create a subrange type. This
7401 results in all of the enumeral values being emitted only once
7402 in the original, and the subtype gets them by reference. */
7403 if (TYPE_UNSIGNED (type
))
7404 typefm
= make_unsigned_type (TYPE_PRECISION (typefm
));
7406 typefm
= make_signed_type (TYPE_PRECISION (typefm
));
7407 TREE_TYPE (typefm
) = type
;
7410 else if (VECTOR_MODE_P (mode
)
7411 ? TREE_CODE (type
) != TREE_CODE (TREE_TYPE (typefm
))
7412 : TREE_CODE (type
) != TREE_CODE (typefm
))
7414 error ("mode %qs applied to inappropriate type", p
);
7424 /* Handle a "section" attribute; arguments as in
7425 struct attribute_spec.handler. */
7428 handle_section_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7429 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7433 if (targetm_common
.have_named_sections
)
7435 user_defined_section_attribute
= true;
7437 if ((TREE_CODE (decl
) == FUNCTION_DECL
7438 || TREE_CODE (decl
) == VAR_DECL
)
7439 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
7441 if (TREE_CODE (decl
) == VAR_DECL
7442 && current_function_decl
!= NULL_TREE
7443 && !TREE_STATIC (decl
))
7445 error_at (DECL_SOURCE_LOCATION (decl
),
7446 "section attribute cannot be specified for "
7448 *no_add_attrs
= true;
7451 /* The decl may have already been given a section attribute
7452 from a previous declaration. Ensure they match. */
7453 else if (DECL_SECTION_NAME (decl
) != NULL
7454 && strcmp (DECL_SECTION_NAME (decl
),
7455 TREE_STRING_POINTER (TREE_VALUE (args
))) != 0)
7457 error ("section of %q+D conflicts with previous declaration",
7459 *no_add_attrs
= true;
7461 else if (TREE_CODE (decl
) == VAR_DECL
7462 && !targetm
.have_tls
&& targetm
.emutls
.tmpl_section
7463 && DECL_THREAD_LOCAL_P (decl
))
7465 error ("section of %q+D cannot be overridden", *node
);
7466 *no_add_attrs
= true;
7469 set_decl_section_name (decl
,
7470 TREE_STRING_POINTER (TREE_VALUE (args
)));
7474 error ("section attribute not allowed for %q+D", *node
);
7475 *no_add_attrs
= true;
7480 error_at (DECL_SOURCE_LOCATION (*node
),
7481 "section attributes are not supported for this target");
7482 *no_add_attrs
= true;
7488 /* Check whether ALIGN is a valid user-specified alignment. If so,
7489 return its base-2 log; if not, output an error and return -1. If
7490 ALLOW_ZERO then 0 is valid and should result in a return of -1 with
7493 check_user_alignment (const_tree align
, bool allow_zero
)
7497 if (error_operand_p (align
))
7499 if (TREE_CODE (align
) != INTEGER_CST
7500 || !INTEGRAL_TYPE_P (TREE_TYPE (align
)))
7502 error ("requested alignment is not an integer constant");
7505 else if (allow_zero
&& integer_zerop (align
))
7507 else if (tree_int_cst_sgn (align
) == -1
7508 || (i
= tree_log2 (align
)) == -1)
7510 error ("requested alignment is not a positive power of 2");
7513 else if (i
>= HOST_BITS_PER_INT
- BITS_PER_UNIT_LOG
)
7515 error ("requested alignment is too large");
7522 If in c++-11, check if the c++-11 alignment constraint with respect
7523 to fundamental alignment (in [dcl.align]) are satisfied. If not in
7524 c++-11 mode, does nothing.
7528 [* if the constant expression evaluates to a fundamental alignment,
7529 the alignment requirement of the declared entity shall be the
7530 specified fundamental alignment.
7532 * if the constant expression evaluates to an extended alignment
7533 and the implementation supports that alignment in the context
7534 of the declaration, the alignment of the declared entity shall
7537 * if the constant expression evaluates to an extended alignment
7538 and the implementation does not support that alignment in the
7539 context of the declaration, the program is ill-formed]. */
7542 check_cxx_fundamental_alignment_constraints (tree node
,
7546 bool alignment_too_large_p
= false;
7547 unsigned requested_alignment
= 1U << align_log
;
7548 unsigned max_align
= 0;
7550 if ((!(flags
& ATTR_FLAG_CXX11
) && !warn_cxx_compat
)
7551 || (node
== NULL_TREE
|| node
== error_mark_node
))
7554 if (cxx_fundamental_alignment_p (requested_alignment
))
7559 if (TREE_STATIC (node
))
7561 /* For file scope variables and static members, the target
7562 supports alignments that are at most
7563 MAX_OFILE_ALIGNMENT. */
7564 if (requested_alignment
> (max_align
= MAX_OFILE_ALIGNMENT
))
7565 alignment_too_large_p
= true;
7569 #ifdef BIGGEST_FIELD_ALIGNMENT
7570 #define MAX_TARGET_FIELD_ALIGNMENT BIGGEST_FIELD_ALIGNMENT
7572 #define MAX_TARGET_FIELD_ALIGNMENT BIGGEST_ALIGNMENT
7574 /* For non-static members, the target supports either
7575 alignments that at most either BIGGEST_FIELD_ALIGNMENT
7576 if it is defined or BIGGEST_ALIGNMENT. */
7577 max_align
= MAX_TARGET_FIELD_ALIGNMENT
;
7578 if (TREE_CODE (node
) == FIELD_DECL
7579 && requested_alignment
> (max_align
= MAX_TARGET_FIELD_ALIGNMENT
))
7580 alignment_too_large_p
= true;
7581 #undef MAX_TARGET_FIELD_ALIGNMENT
7582 /* For stack variables, the target supports at most
7583 MAX_STACK_ALIGNMENT. */
7584 else if (decl_function_context (node
) != NULL
7585 && requested_alignment
> (max_align
= MAX_STACK_ALIGNMENT
))
7586 alignment_too_large_p
= true;
7589 else if (TYPE_P (node
))
7591 /* Let's be liberal for types. */
7592 if (requested_alignment
> (max_align
= BIGGEST_ALIGNMENT
))
7593 alignment_too_large_p
= true;
7596 if (alignment_too_large_p
)
7597 pedwarn (input_location
, OPT_Wattributes
,
7598 "requested alignment %d is larger than %d",
7599 requested_alignment
, max_align
);
7601 return !alignment_too_large_p
;
7604 /* Handle a "aligned" attribute; arguments as in
7605 struct attribute_spec.handler. */
7608 handle_aligned_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7609 int flags
, bool *no_add_attrs
)
7611 tree decl
= NULL_TREE
;
7619 align_expr
= TREE_VALUE (args
);
7620 if (align_expr
&& TREE_CODE (align_expr
) != IDENTIFIER_NODE
7621 && TREE_CODE (align_expr
) != FUNCTION_DECL
)
7622 align_expr
= default_conversion (align_expr
);
7625 align_expr
= size_int (ATTRIBUTE_ALIGNED_VALUE
/ BITS_PER_UNIT
);
7630 type
= &TREE_TYPE (decl
);
7631 is_type
= TREE_CODE (*node
) == TYPE_DECL
;
7633 else if (TYPE_P (*node
))
7634 type
= node
, is_type
= 1;
7636 if ((i
= check_user_alignment (align_expr
, false)) == -1
7637 || !check_cxx_fundamental_alignment_constraints (*node
, i
, flags
))
7638 *no_add_attrs
= true;
7641 if ((flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7642 /* OK, modify the type in place. */;
7643 /* If we have a TYPE_DECL, then copy the type, so that we
7644 don't accidentally modify a builtin type. See pushdecl. */
7645 else if (decl
&& TREE_TYPE (decl
) != error_mark_node
7646 && DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
)
7648 tree tt
= TREE_TYPE (decl
);
7649 *type
= build_variant_type_copy (*type
);
7650 DECL_ORIGINAL_TYPE (decl
) = tt
;
7651 TYPE_NAME (*type
) = decl
;
7652 TREE_USED (*type
) = TREE_USED (decl
);
7653 TREE_TYPE (decl
) = *type
;
7656 *type
= build_variant_type_copy (*type
);
7658 TYPE_ALIGN (*type
) = (1U << i
) * BITS_PER_UNIT
;
7659 TYPE_USER_ALIGN (*type
) = 1;
7661 else if (! VAR_OR_FUNCTION_DECL_P (decl
)
7662 && TREE_CODE (decl
) != FIELD_DECL
)
7664 error ("alignment may not be specified for %q+D", decl
);
7665 *no_add_attrs
= true;
7667 else if (DECL_USER_ALIGN (decl
)
7668 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
7669 /* C++-11 [dcl.align/4]:
7671 When multiple alignment-specifiers are specified for an
7672 entity, the alignment requirement shall be set to the
7673 strictest specified alignment.
7675 This formally comes from the c++11 specification but we are
7676 doing it for the GNU attribute syntax as well. */
7677 *no_add_attrs
= true;
7678 else if (TREE_CODE (decl
) == FUNCTION_DECL
7679 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
7681 if (DECL_USER_ALIGN (decl
))
7682 error ("alignment for %q+D was previously specified as %d "
7683 "and may not be decreased", decl
,
7684 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
7686 error ("alignment for %q+D must be at least %d", decl
,
7687 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
7688 *no_add_attrs
= true;
7692 DECL_ALIGN (decl
) = (1U << i
) * BITS_PER_UNIT
;
7693 DECL_USER_ALIGN (decl
) = 1;
7699 /* Handle a "weak" attribute; arguments as in
7700 struct attribute_spec.handler. */
7703 handle_weak_attribute (tree
*node
, tree name
,
7704 tree
ARG_UNUSED (args
),
7705 int ARG_UNUSED (flags
),
7706 bool * ARG_UNUSED (no_add_attrs
))
7708 if (TREE_CODE (*node
) == FUNCTION_DECL
7709 && DECL_DECLARED_INLINE_P (*node
))
7711 warning (OPT_Wattributes
, "inline function %q+D declared weak", *node
);
7712 *no_add_attrs
= true;
7714 else if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
7716 error ("indirect function %q+D cannot be declared weak", *node
);
7717 *no_add_attrs
= true;
7720 else if (TREE_CODE (*node
) == FUNCTION_DECL
7721 || TREE_CODE (*node
) == VAR_DECL
)
7722 declare_weak (*node
);
7724 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7729 /* Handle an "alias" or "ifunc" attribute; arguments as in
7730 struct attribute_spec.handler, except that IS_ALIAS tells us
7731 whether this is an alias as opposed to ifunc attribute. */
7734 handle_alias_ifunc_attribute (bool is_alias
, tree
*node
, tree name
, tree args
,
7739 if (TREE_CODE (decl
) != FUNCTION_DECL
7740 && (!is_alias
|| TREE_CODE (decl
) != VAR_DECL
))
7742 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7743 *no_add_attrs
= true;
7745 else if ((TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INITIAL (decl
))
7746 || (TREE_CODE (decl
) != FUNCTION_DECL
7747 && TREE_PUBLIC (decl
) && !DECL_EXTERNAL (decl
))
7748 /* A static variable declaration is always a tentative definition,
7749 but the alias is a non-tentative definition which overrides. */
7750 || (TREE_CODE (decl
) != FUNCTION_DECL
7751 && ! TREE_PUBLIC (decl
) && DECL_INITIAL (decl
)))
7753 error ("%q+D defined both normally and as %qE attribute", decl
, name
);
7754 *no_add_attrs
= true;
7758 && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
7759 || lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
))))
7761 error ("weak %q+D cannot be defined %qE", decl
, name
);
7762 *no_add_attrs
= true;
7766 /* Note that the very first time we process a nested declaration,
7767 decl_function_context will not be set. Indeed, *would* never
7768 be set except for the DECL_INITIAL/DECL_EXTERNAL frobbery that
7769 we do below. After such frobbery, pushdecl would set the context.
7770 In any case, this is never what we want. */
7771 else if (decl_function_context (decl
) == 0 && current_function_decl
== NULL
)
7775 id
= TREE_VALUE (args
);
7776 if (TREE_CODE (id
) != STRING_CST
)
7778 error ("attribute %qE argument not a string", name
);
7779 *no_add_attrs
= true;
7782 id
= get_identifier (TREE_STRING_POINTER (id
));
7783 /* This counts as a use of the object pointed to. */
7786 if (TREE_CODE (decl
) == FUNCTION_DECL
)
7787 DECL_INITIAL (decl
) = error_mark_node
;
7789 TREE_STATIC (decl
) = 1;
7792 /* ifuncs are also aliases, so set that attribute too. */
7793 DECL_ATTRIBUTES (decl
)
7794 = tree_cons (get_identifier ("alias"), args
, DECL_ATTRIBUTES (decl
));
7798 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7799 *no_add_attrs
= true;
7802 if (decl_in_symtab_p (*node
))
7804 struct symtab_node
*n
= symtab_node::get (decl
);
7805 if (n
&& n
->refuse_visibility_changes
)
7808 error ("%+D declared alias after being used", decl
);
7810 error ("%+D declared ifunc after being used", decl
);
7818 /* Handle an "alias" or "ifunc" attribute; arguments as in
7819 struct attribute_spec.handler. */
7822 handle_ifunc_attribute (tree
*node
, tree name
, tree args
,
7823 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7825 return handle_alias_ifunc_attribute (false, node
, name
, args
, no_add_attrs
);
7828 /* Handle an "alias" or "ifunc" attribute; arguments as in
7829 struct attribute_spec.handler. */
7832 handle_alias_attribute (tree
*node
, tree name
, tree args
,
7833 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7835 return handle_alias_ifunc_attribute (true, node
, name
, args
, no_add_attrs
);
7838 /* Handle a "weakref" attribute; arguments as in struct
7839 attribute_spec.handler. */
7842 handle_weakref_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7843 int flags
, bool *no_add_attrs
)
7845 tree attr
= NULL_TREE
;
7847 /* We must ignore the attribute when it is associated with
7848 local-scoped decls, since attribute alias is ignored and many
7849 such symbols do not even have a DECL_WEAK field. */
7850 if (decl_function_context (*node
)
7851 || current_function_decl
7852 || (TREE_CODE (*node
) != VAR_DECL
&& TREE_CODE (*node
) != FUNCTION_DECL
))
7854 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7855 *no_add_attrs
= true;
7859 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
7861 error ("indirect function %q+D cannot be declared weakref", *node
);
7862 *no_add_attrs
= true;
7866 /* The idea here is that `weakref("name")' mutates into `weakref,
7867 alias("name")', and weakref without arguments, in turn,
7868 implicitly adds weak. */
7872 attr
= tree_cons (get_identifier ("alias"), args
, attr
);
7873 attr
= tree_cons (get_identifier ("weakref"), NULL_TREE
, attr
);
7875 *no_add_attrs
= true;
7877 decl_attributes (node
, attr
, flags
);
7881 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node
)))
7882 error_at (DECL_SOURCE_LOCATION (*node
),
7883 "weakref attribute must appear before alias attribute");
7885 /* Can't call declare_weak because it wants this to be TREE_PUBLIC,
7886 and that isn't supported; and because it wants to add it to
7887 the list of weak decls, which isn't helpful. */
7888 DECL_WEAK (*node
) = 1;
7891 if (decl_in_symtab_p (*node
))
7893 struct symtab_node
*n
= symtab_node::get (*node
);
7894 if (n
&& n
->refuse_visibility_changes
)
7895 error ("%+D declared weakref after being used", *node
);
7901 /* Handle an "visibility" attribute; arguments as in
7902 struct attribute_spec.handler. */
7905 handle_visibility_attribute (tree
*node
, tree name
, tree args
,
7906 int ARG_UNUSED (flags
),
7907 bool *ARG_UNUSED (no_add_attrs
))
7910 tree id
= TREE_VALUE (args
);
7911 enum symbol_visibility vis
;
7915 if (TREE_CODE (*node
) == ENUMERAL_TYPE
)
7917 else if (TREE_CODE (*node
) != RECORD_TYPE
&& TREE_CODE (*node
) != UNION_TYPE
)
7919 warning (OPT_Wattributes
, "%qE attribute ignored on non-class types",
7923 else if (TYPE_FIELDS (*node
))
7925 error ("%qE attribute ignored because %qT is already defined",
7930 else if (decl_function_context (decl
) != 0 || !TREE_PUBLIC (decl
))
7932 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7936 if (TREE_CODE (id
) != STRING_CST
)
7938 error ("visibility argument not a string");
7942 /* If this is a type, set the visibility on the type decl. */
7945 decl
= TYPE_NAME (decl
);
7948 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
7950 warning (OPT_Wattributes
, "%qE attribute ignored on types",
7956 if (strcmp (TREE_STRING_POINTER (id
), "default") == 0)
7957 vis
= VISIBILITY_DEFAULT
;
7958 else if (strcmp (TREE_STRING_POINTER (id
), "internal") == 0)
7959 vis
= VISIBILITY_INTERNAL
;
7960 else if (strcmp (TREE_STRING_POINTER (id
), "hidden") == 0)
7961 vis
= VISIBILITY_HIDDEN
;
7962 else if (strcmp (TREE_STRING_POINTER (id
), "protected") == 0)
7963 vis
= VISIBILITY_PROTECTED
;
7966 error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
7967 vis
= VISIBILITY_DEFAULT
;
7970 if (DECL_VISIBILITY_SPECIFIED (decl
)
7971 && vis
!= DECL_VISIBILITY (decl
))
7973 tree attributes
= (TYPE_P (*node
)
7974 ? TYPE_ATTRIBUTES (*node
)
7975 : DECL_ATTRIBUTES (decl
));
7976 if (lookup_attribute ("visibility", attributes
))
7977 error ("%qD redeclared with different visibility", decl
);
7978 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
7979 && lookup_attribute ("dllimport", attributes
))
7980 error ("%qD was declared %qs which implies default visibility",
7982 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
7983 && lookup_attribute ("dllexport", attributes
))
7984 error ("%qD was declared %qs which implies default visibility",
7988 DECL_VISIBILITY (decl
) = vis
;
7989 DECL_VISIBILITY_SPECIFIED (decl
) = 1;
7991 /* Go ahead and attach the attribute to the node as well. This is needed
7992 so we can determine whether we have VISIBILITY_DEFAULT because the
7993 visibility was not specified, or because it was explicitly overridden
7994 from the containing scope. */
7999 /* Determine the ELF symbol visibility for DECL, which is either a
8000 variable or a function. It is an error to use this function if a
8001 definition of DECL is not available in this translation unit.
8002 Returns true if the final visibility has been determined by this
8003 function; false if the caller is free to make additional
8007 c_determine_visibility (tree decl
)
8009 gcc_assert (TREE_CODE (decl
) == VAR_DECL
8010 || TREE_CODE (decl
) == FUNCTION_DECL
);
8012 /* If the user explicitly specified the visibility with an
8013 attribute, honor that. DECL_VISIBILITY will have been set during
8014 the processing of the attribute. We check for an explicit
8015 attribute, rather than just checking DECL_VISIBILITY_SPECIFIED,
8016 to distinguish the use of an attribute from the use of a "#pragma
8017 GCC visibility push(...)"; in the latter case we still want other
8018 considerations to be able to overrule the #pragma. */
8019 if (lookup_attribute ("visibility", DECL_ATTRIBUTES (decl
))
8020 || (TARGET_DLLIMPORT_DECL_ATTRIBUTES
8021 && (lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl
))
8022 || lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl
)))))
8025 /* Set default visibility to whatever the user supplied with
8026 visibility_specified depending on #pragma GCC visibility. */
8027 if (!DECL_VISIBILITY_SPECIFIED (decl
))
8029 if (visibility_options
.inpragma
8030 || DECL_VISIBILITY (decl
) != default_visibility
)
8032 DECL_VISIBILITY (decl
) = default_visibility
;
8033 DECL_VISIBILITY_SPECIFIED (decl
) = visibility_options
.inpragma
;
8034 /* If visibility changed and DECL already has DECL_RTL, ensure
8035 symbol flags are updated. */
8036 if (((TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
))
8037 || TREE_CODE (decl
) == FUNCTION_DECL
)
8038 && DECL_RTL_SET_P (decl
))
8039 make_decl_rtl (decl
);
8045 /* Handle an "tls_model" attribute; arguments as in
8046 struct attribute_spec.handler. */
8049 handle_tls_model_attribute (tree
*node
, tree name
, tree args
,
8050 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8054 enum tls_model kind
;
8056 *no_add_attrs
= true;
8058 if (TREE_CODE (decl
) != VAR_DECL
|| !DECL_THREAD_LOCAL_P (decl
))
8060 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8064 kind
= DECL_TLS_MODEL (decl
);
8065 id
= TREE_VALUE (args
);
8066 if (TREE_CODE (id
) != STRING_CST
)
8068 error ("tls_model argument not a string");
8072 if (!strcmp (TREE_STRING_POINTER (id
), "local-exec"))
8073 kind
= TLS_MODEL_LOCAL_EXEC
;
8074 else if (!strcmp (TREE_STRING_POINTER (id
), "initial-exec"))
8075 kind
= TLS_MODEL_INITIAL_EXEC
;
8076 else if (!strcmp (TREE_STRING_POINTER (id
), "local-dynamic"))
8077 kind
= optimize
? TLS_MODEL_LOCAL_DYNAMIC
: TLS_MODEL_GLOBAL_DYNAMIC
;
8078 else if (!strcmp (TREE_STRING_POINTER (id
), "global-dynamic"))
8079 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
8081 error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
8083 set_decl_tls_model (decl
, kind
);
8087 /* Handle a "no_instrument_function" attribute; arguments as in
8088 struct attribute_spec.handler. */
8091 handle_no_instrument_function_attribute (tree
*node
, tree name
,
8092 tree
ARG_UNUSED (args
),
8093 int ARG_UNUSED (flags
),
8098 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8100 error_at (DECL_SOURCE_LOCATION (decl
),
8101 "%qE attribute applies only to functions", name
);
8102 *no_add_attrs
= true;
8105 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
8110 /* Handle a "malloc" attribute; arguments as in
8111 struct attribute_spec.handler. */
8114 handle_malloc_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8115 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8117 if (TREE_CODE (*node
) == FUNCTION_DECL
8118 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node
))))
8119 DECL_IS_MALLOC (*node
) = 1;
8122 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8123 *no_add_attrs
= true;
8129 /* Handle a "alloc_size" attribute; arguments as in
8130 struct attribute_spec.handler. */
8133 handle_alloc_size_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
8134 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8136 unsigned arg_count
= type_num_arguments (*node
);
8137 for (; args
; args
= TREE_CHAIN (args
))
8139 tree position
= TREE_VALUE (args
);
8140 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
8141 && TREE_CODE (position
) != FUNCTION_DECL
)
8142 position
= default_conversion (position
);
8144 if (!tree_fits_uhwi_p (position
)
8146 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
8148 warning (OPT_Wattributes
,
8149 "alloc_size parameter outside range");
8150 *no_add_attrs
= true;
8157 /* Handle a "alloc_align" attribute; arguments as in
8158 struct attribute_spec.handler. */
8161 handle_alloc_align_attribute (tree
*node
, tree
, tree args
, int,
8164 unsigned arg_count
= type_num_arguments (*node
);
8165 tree position
= TREE_VALUE (args
);
8166 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
)
8167 position
= default_conversion (position
);
8169 if (!tree_fits_uhwi_p (position
)
8171 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
8173 warning (OPT_Wattributes
,
8174 "alloc_align parameter outside range");
8175 *no_add_attrs
= true;
8181 /* Handle a "assume_aligned" attribute; arguments as in
8182 struct attribute_spec.handler. */
8185 handle_assume_aligned_attribute (tree
*, tree
, tree args
, int,
8188 for (; args
; args
= TREE_CHAIN (args
))
8190 tree position
= TREE_VALUE (args
);
8191 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
8192 && TREE_CODE (position
) != FUNCTION_DECL
)
8193 position
= default_conversion (position
);
8195 if (TREE_CODE (position
) != INTEGER_CST
)
8197 warning (OPT_Wattributes
,
8198 "assume_aligned parameter not integer constant");
8199 *no_add_attrs
= true;
8206 /* Handle a "fn spec" attribute; arguments as in
8207 struct attribute_spec.handler. */
8210 handle_fnspec_attribute (tree
*node ATTRIBUTE_UNUSED
, tree
ARG_UNUSED (name
),
8211 tree args
, int ARG_UNUSED (flags
),
8212 bool *no_add_attrs ATTRIBUTE_UNUSED
)
8215 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
8216 && !TREE_CHAIN (args
));
8220 /* Handle a "warn_unused" attribute; arguments as in
8221 struct attribute_spec.handler. */
8224 handle_warn_unused_attribute (tree
*node
, tree name
,
8225 tree args ATTRIBUTE_UNUSED
,
8226 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
8229 /* Do nothing else, just set the attribute. We'll get at
8230 it later with lookup_attribute. */
8234 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8235 *no_add_attrs
= true;
8241 /* Handle an "omp declare simd" attribute; arguments as in
8242 struct attribute_spec.handler. */
8245 handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int, bool *)
8250 /* Handle an "omp declare target" attribute; arguments as in
8251 struct attribute_spec.handler. */
8254 handle_omp_declare_target_attribute (tree
*, tree
, tree
, int, bool *)
8259 /* Handle a "returns_twice" attribute; arguments as in
8260 struct attribute_spec.handler. */
8263 handle_returns_twice_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8264 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8266 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8267 DECL_IS_RETURNS_TWICE (*node
) = 1;
8270 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8271 *no_add_attrs
= true;
8277 /* Handle a "no_limit_stack" attribute; arguments as in
8278 struct attribute_spec.handler. */
8281 handle_no_limit_stack_attribute (tree
*node
, tree name
,
8282 tree
ARG_UNUSED (args
),
8283 int ARG_UNUSED (flags
),
8288 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8290 error_at (DECL_SOURCE_LOCATION (decl
),
8291 "%qE attribute applies only to functions", name
);
8292 *no_add_attrs
= true;
8294 else if (DECL_INITIAL (decl
))
8296 error_at (DECL_SOURCE_LOCATION (decl
),
8297 "can%'t set %qE attribute after definition", name
);
8298 *no_add_attrs
= true;
8301 DECL_NO_LIMIT_STACK (decl
) = 1;
8306 /* Handle a "pure" attribute; arguments as in
8307 struct attribute_spec.handler. */
8310 handle_pure_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8311 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8313 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8314 DECL_PURE_P (*node
) = 1;
8315 /* ??? TODO: Support types. */
8318 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8319 *no_add_attrs
= true;
8325 /* Digest an attribute list destined for a transactional memory statement.
8326 ALLOWED is the set of attributes that are allowed for this statement;
8327 return the attribute we parsed. Multiple attributes are never allowed. */
8330 parse_tm_stmt_attr (tree attrs
, int allowed
)
8335 for ( ; attrs
; attrs
= TREE_CHAIN (attrs
))
8337 tree a
= TREE_PURPOSE (attrs
);
8340 if (is_attribute_p ("outer", a
))
8341 m
= TM_STMT_ATTR_OUTER
;
8343 if ((m
& allowed
) == 0)
8345 warning (OPT_Wattributes
, "%qE attribute directive ignored", a
);
8354 else if (m_seen
== m
)
8355 warning (OPT_Wattributes
, "%qE attribute duplicated", a
);
8357 warning (OPT_Wattributes
, "%qE attribute follows %qE", a
, a_seen
);
8363 /* Transform a TM attribute name into a maskable integer and back.
8364 Note that NULL (i.e. no attribute) is mapped to UNKNOWN, corresponding
8365 to how the lack of an attribute is treated. */
8368 tm_attr_to_mask (tree attr
)
8372 if (is_attribute_p ("transaction_safe", attr
))
8373 return TM_ATTR_SAFE
;
8374 if (is_attribute_p ("transaction_callable", attr
))
8375 return TM_ATTR_CALLABLE
;
8376 if (is_attribute_p ("transaction_pure", attr
))
8377 return TM_ATTR_PURE
;
8378 if (is_attribute_p ("transaction_unsafe", attr
))
8379 return TM_ATTR_IRREVOCABLE
;
8380 if (is_attribute_p ("transaction_may_cancel_outer", attr
))
8381 return TM_ATTR_MAY_CANCEL_OUTER
;
8386 tm_mask_to_attr (int mask
)
8392 str
= "transaction_safe";
8394 case TM_ATTR_CALLABLE
:
8395 str
= "transaction_callable";
8398 str
= "transaction_pure";
8400 case TM_ATTR_IRREVOCABLE
:
8401 str
= "transaction_unsafe";
8403 case TM_ATTR_MAY_CANCEL_OUTER
:
8404 str
= "transaction_may_cancel_outer";
8409 return get_identifier (str
);
8412 /* Return the first TM attribute seen in LIST. */
8415 find_tm_attribute (tree list
)
8417 for (; list
; list
= TREE_CHAIN (list
))
8419 tree name
= TREE_PURPOSE (list
);
8420 if (tm_attr_to_mask (name
) != 0)
8426 /* Handle the TM attributes; arguments as in struct attribute_spec.handler.
8427 Here we accept only function types, and verify that none of the other
8428 function TM attributes are also applied. */
8429 /* ??? We need to accept class types for C++, but not C. This greatly
8430 complicates this function, since we can no longer rely on the extra
8431 processing given by function_type_required. */
8434 handle_tm_attribute (tree
*node
, tree name
, tree args
,
8435 int flags
, bool *no_add_attrs
)
8437 /* Only one path adds the attribute; others don't. */
8438 *no_add_attrs
= true;
8440 switch (TREE_CODE (*node
))
8444 /* Only tm_callable and tm_safe apply to classes. */
8445 if (tm_attr_to_mask (name
) & ~(TM_ATTR_SAFE
| TM_ATTR_CALLABLE
))
8452 tree old_name
= find_tm_attribute (TYPE_ATTRIBUTES (*node
));
8453 if (old_name
== name
)
8455 else if (old_name
!= NULL_TREE
)
8456 error ("type was previously declared %qE", old_name
);
8458 *no_add_attrs
= false;
8464 enum tree_code subcode
= TREE_CODE (TREE_TYPE (*node
));
8465 if (subcode
== FUNCTION_TYPE
|| subcode
== METHOD_TYPE
)
8467 tree fn_tmp
= TREE_TYPE (*node
);
8468 decl_attributes (&fn_tmp
, tree_cons (name
, args
, NULL
), 0);
8469 *node
= build_pointer_type (fn_tmp
);
8476 /* If a function is next, pass it on to be tried next. */
8477 if (flags
& (int) ATTR_FLAG_FUNCTION_NEXT
)
8478 return tree_cons (name
, args
, NULL
);
8481 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8488 /* Handle the TM_WRAP attribute; arguments as in
8489 struct attribute_spec.handler. */
8492 handle_tm_wrap_attribute (tree
*node
, tree name
, tree args
,
8493 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8497 /* We don't need the attribute even on success, since we
8498 record the entry in an external table. */
8499 *no_add_attrs
= true;
8501 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8502 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8505 tree wrap_decl
= TREE_VALUE (args
);
8506 if (error_operand_p (wrap_decl
))
8508 else if (TREE_CODE (wrap_decl
) != IDENTIFIER_NODE
8509 && TREE_CODE (wrap_decl
) != VAR_DECL
8510 && TREE_CODE (wrap_decl
) != FUNCTION_DECL
)
8511 error ("%qE argument not an identifier", name
);
8514 if (TREE_CODE (wrap_decl
) == IDENTIFIER_NODE
)
8515 wrap_decl
= lookup_name (wrap_decl
);
8516 if (wrap_decl
&& TREE_CODE (wrap_decl
) == FUNCTION_DECL
)
8518 if (lang_hooks
.types_compatible_p (TREE_TYPE (decl
),
8519 TREE_TYPE (wrap_decl
)))
8520 record_tm_replacement (wrap_decl
, decl
);
8522 error ("%qD is not compatible with %qD", wrap_decl
, decl
);
8525 error ("%qE argument is not a function", name
);
8532 /* Ignore the given attribute. Used when this attribute may be usefully
8533 overridden by the target, but is not used generically. */
8536 ignore_attribute (tree
* ARG_UNUSED (node
), tree
ARG_UNUSED (name
),
8537 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
8540 *no_add_attrs
= true;
8544 /* Handle a "no vops" attribute; arguments as in
8545 struct attribute_spec.handler. */
8548 handle_novops_attribute (tree
*node
, tree
ARG_UNUSED (name
),
8549 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
8550 bool *ARG_UNUSED (no_add_attrs
))
8552 gcc_assert (TREE_CODE (*node
) == FUNCTION_DECL
);
8553 DECL_IS_NOVOPS (*node
) = 1;
8557 /* Handle a "deprecated" attribute; arguments as in
8558 struct attribute_spec.handler. */
8561 handle_deprecated_attribute (tree
*node
, tree name
,
8562 tree args
, int flags
,
8565 tree type
= NULL_TREE
;
8567 tree what
= NULL_TREE
;
8570 *no_add_attrs
= true;
8571 else if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
8573 error ("deprecated message is not a string");
8574 *no_add_attrs
= true;
8580 type
= TREE_TYPE (decl
);
8582 if (TREE_CODE (decl
) == TYPE_DECL
8583 || TREE_CODE (decl
) == PARM_DECL
8584 || TREE_CODE (decl
) == VAR_DECL
8585 || TREE_CODE (decl
) == FUNCTION_DECL
8586 || TREE_CODE (decl
) == FIELD_DECL
8587 || objc_method_decl (TREE_CODE (decl
)))
8588 TREE_DEPRECATED (decl
) = 1;
8592 else if (TYPE_P (*node
))
8594 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
8595 *node
= build_variant_type_copy (*node
);
8596 TREE_DEPRECATED (*node
) = 1;
8604 *no_add_attrs
= true;
8605 if (type
&& TYPE_NAME (type
))
8607 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
8608 what
= TYPE_NAME (*node
);
8609 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
8610 && DECL_NAME (TYPE_NAME (type
)))
8611 what
= DECL_NAME (TYPE_NAME (type
));
8614 warning (OPT_Wattributes
, "%qE attribute ignored for %qE", name
, what
);
8616 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8622 /* Handle a "vector_size" attribute; arguments as in
8623 struct attribute_spec.handler. */
8626 handle_vector_size_attribute (tree
*node
, tree name
, tree args
,
8627 int ARG_UNUSED (flags
),
8630 unsigned HOST_WIDE_INT vecsize
, nunits
;
8631 enum machine_mode orig_mode
;
8632 tree type
= *node
, new_type
, size
;
8634 *no_add_attrs
= true;
8636 size
= TREE_VALUE (args
);
8637 if (size
&& TREE_CODE (size
) != IDENTIFIER_NODE
8638 && TREE_CODE (size
) != FUNCTION_DECL
)
8639 size
= default_conversion (size
);
8641 if (!tree_fits_uhwi_p (size
))
8643 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8647 /* Get the vector size (in bytes). */
8648 vecsize
= tree_to_uhwi (size
);
8650 /* We need to provide for vector pointers, vector arrays, and
8651 functions returning vectors. For example:
8653 __attribute__((vector_size(16))) short *foo;
8655 In this case, the mode is SI, but the type being modified is
8656 HI, so we need to look further. */
8658 while (POINTER_TYPE_P (type
)
8659 || TREE_CODE (type
) == FUNCTION_TYPE
8660 || TREE_CODE (type
) == METHOD_TYPE
8661 || TREE_CODE (type
) == ARRAY_TYPE
8662 || TREE_CODE (type
) == OFFSET_TYPE
)
8663 type
= TREE_TYPE (type
);
8665 /* Get the mode of the type being modified. */
8666 orig_mode
= TYPE_MODE (type
);
8668 if ((!INTEGRAL_TYPE_P (type
)
8669 && !SCALAR_FLOAT_TYPE_P (type
)
8670 && !FIXED_POINT_TYPE_P (type
))
8671 || (!SCALAR_FLOAT_MODE_P (orig_mode
)
8672 && GET_MODE_CLASS (orig_mode
) != MODE_INT
8673 && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode
))
8674 || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
8675 || TREE_CODE (type
) == BOOLEAN_TYPE
)
8677 error ("invalid vector type for attribute %qE", name
);
8681 if (vecsize
% tree_to_uhwi (TYPE_SIZE_UNIT (type
)))
8683 error ("vector size not an integral multiple of component size");
8689 error ("zero vector size");
8693 /* Calculate how many units fit in the vector. */
8694 nunits
= vecsize
/ tree_to_uhwi (TYPE_SIZE_UNIT (type
));
8695 if (nunits
& (nunits
- 1))
8697 error ("number of components of the vector not a power of two");
8701 new_type
= build_vector_type (type
, nunits
);
8703 /* Build back pointers if needed. */
8704 *node
= lang_hooks
.types
.reconstruct_complex_type (*node
, new_type
);
8709 /* Handle the "nonnull" attribute. */
8711 handle_nonnull_attribute (tree
*node
, tree
ARG_UNUSED (name
),
8712 tree args
, int ARG_UNUSED (flags
),
8716 unsigned HOST_WIDE_INT attr_arg_num
;
8718 /* If no arguments are specified, all pointer arguments should be
8719 non-null. Verify a full prototype is given so that the arguments
8720 will have the correct types when we actually check them later. */
8723 if (!prototype_p (type
))
8725 error ("nonnull attribute without arguments on a non-prototype");
8726 *no_add_attrs
= true;
8731 /* Argument list specified. Verify that each argument number references
8732 a pointer argument. */
8733 for (attr_arg_num
= 1; args
; attr_arg_num
++, args
= TREE_CHAIN (args
))
8735 unsigned HOST_WIDE_INT arg_num
= 0, ck_num
;
8737 tree arg
= TREE_VALUE (args
);
8738 if (arg
&& TREE_CODE (arg
) != IDENTIFIER_NODE
8739 && TREE_CODE (arg
) != FUNCTION_DECL
)
8740 arg
= default_conversion (arg
);
8742 if (!get_nonnull_operand (arg
, &arg_num
))
8744 error ("nonnull argument has invalid operand number (argument %lu)",
8745 (unsigned long) attr_arg_num
);
8746 *no_add_attrs
= true;
8750 if (prototype_p (type
))
8752 function_args_iterator iter
;
8755 function_args_iter_init (&iter
, type
);
8756 for (ck_num
= 1; ; ck_num
++, function_args_iter_next (&iter
))
8758 argument
= function_args_iter_cond (&iter
);
8759 if (argument
== NULL_TREE
|| ck_num
== arg_num
)
8764 || TREE_CODE (argument
) == VOID_TYPE
)
8766 error ("nonnull argument with out-of-range operand number (argument %lu, operand %lu)",
8767 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
8768 *no_add_attrs
= true;
8772 if (TREE_CODE (argument
) != POINTER_TYPE
)
8774 error ("nonnull argument references non-pointer operand (argument %lu, operand %lu)",
8775 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
8776 *no_add_attrs
= true;
8785 /* Check the argument list of a function call for null in argument slots
8786 that are marked as requiring a non-null pointer argument. The NARGS
8787 arguments are passed in the array ARGARRAY.
8791 check_function_nonnull (tree attrs
, int nargs
, tree
*argarray
)
8796 attrs
= lookup_attribute ("nonnull", attrs
);
8797 if (attrs
== NULL_TREE
)
8801 /* See if any of the nonnull attributes has no arguments. If so,
8802 then every pointer argument is checked (in which case the check
8803 for pointer type is done in check_nonnull_arg). */
8804 if (TREE_VALUE (a
) != NULL_TREE
)
8806 a
= lookup_attribute ("nonnull", TREE_CHAIN (a
));
8807 while (a
!= NULL_TREE
&& TREE_VALUE (a
) != NULL_TREE
);
8810 for (i
= 0; i
< nargs
; i
++)
8811 check_function_arguments_recurse (check_nonnull_arg
, NULL
, argarray
[i
],
8815 /* Walk the argument list. If we encounter an argument number we
8816 should check for non-null, do it. */
8817 for (i
= 0; i
< nargs
; i
++)
8819 for (a
= attrs
; ; a
= TREE_CHAIN (a
))
8821 a
= lookup_attribute ("nonnull", a
);
8822 if (a
== NULL_TREE
|| nonnull_check_p (TREE_VALUE (a
), i
+ 1))
8827 check_function_arguments_recurse (check_nonnull_arg
, NULL
,
8828 argarray
[i
], i
+ 1);
8833 /* Check that the Nth argument of a function call (counting backwards
8834 from the end) is a (pointer)0. The NARGS arguments are passed in the
8838 check_function_sentinel (const_tree fntype
, int nargs
, tree
*argarray
)
8840 tree attr
= lookup_attribute ("sentinel", TYPE_ATTRIBUTES (fntype
));
8847 function_args_iterator iter
;
8850 /* Skip over the named arguments. */
8851 FOREACH_FUNCTION_ARGS (fntype
, t
, iter
)
8858 if (TREE_VALUE (attr
))
8860 tree p
= TREE_VALUE (TREE_VALUE (attr
));
8861 pos
= TREE_INT_CST_LOW (p
);
8864 /* The sentinel must be one of the varargs, i.e.
8865 in position >= the number of fixed arguments. */
8866 if ((nargs
- 1 - pos
) < len
)
8868 warning (OPT_Wformat_
,
8869 "not enough variable arguments to fit a sentinel");
8873 /* Validate the sentinel. */
8874 sentinel
= argarray
[nargs
- 1 - pos
];
8875 if ((!POINTER_TYPE_P (TREE_TYPE (sentinel
))
8876 || !integer_zerop (sentinel
))
8877 /* Although __null (in C++) is only an integer we allow it
8878 nevertheless, as we are guaranteed that it's exactly
8879 as wide as a pointer, and we don't want to force
8880 users to cast the NULL they have written there.
8881 We warn with -Wstrict-null-sentinel, though. */
8882 && (warn_strict_null_sentinel
|| null_node
!= sentinel
))
8883 warning (OPT_Wformat_
, "missing sentinel in function call");
8887 /* Helper for check_function_nonnull; given a list of operands which
8888 must be non-null in ARGS, determine if operand PARAM_NUM should be
8892 nonnull_check_p (tree args
, unsigned HOST_WIDE_INT param_num
)
8894 unsigned HOST_WIDE_INT arg_num
= 0;
8896 for (; args
; args
= TREE_CHAIN (args
))
8898 bool found
= get_nonnull_operand (TREE_VALUE (args
), &arg_num
);
8902 if (arg_num
== param_num
)
8908 /* Check that the function argument PARAM (which is operand number
8909 PARAM_NUM) is non-null. This is called by check_function_nonnull
8910 via check_function_arguments_recurse. */
8913 check_nonnull_arg (void * ARG_UNUSED (ctx
), tree param
,
8914 unsigned HOST_WIDE_INT param_num
)
8916 /* Just skip checking the argument if it's not a pointer. This can
8917 happen if the "nonnull" attribute was given without an operand
8918 list (which means to check every pointer argument). */
8920 if (TREE_CODE (TREE_TYPE (param
)) != POINTER_TYPE
)
8923 if (integer_zerop (param
))
8924 warning (OPT_Wnonnull
, "null argument where non-null required "
8925 "(argument %lu)", (unsigned long) param_num
);
8928 /* Helper for nonnull attribute handling; fetch the operand number
8929 from the attribute argument list. */
8932 get_nonnull_operand (tree arg_num_expr
, unsigned HOST_WIDE_INT
*valp
)
8934 /* Verify the arg number is a small constant. */
8935 if (tree_fits_uhwi_p (arg_num_expr
))
8937 *valp
= TREE_INT_CST_LOW (arg_num_expr
);
8944 /* Handle a "nothrow" attribute; arguments as in
8945 struct attribute_spec.handler. */
8948 handle_nothrow_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8949 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8951 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8952 TREE_NOTHROW (*node
) = 1;
8953 /* ??? TODO: Support types. */
8956 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8957 *no_add_attrs
= true;
8963 /* Handle a "cleanup" attribute; arguments as in
8964 struct attribute_spec.handler. */
8967 handle_cleanup_attribute (tree
*node
, tree name
, tree args
,
8968 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8971 tree cleanup_id
, cleanup_decl
;
8973 /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
8974 for global destructors in C++. This requires infrastructure that
8975 we don't have generically at the moment. It's also not a feature
8976 we'd be missing too much, since we do have attribute constructor. */
8977 if (TREE_CODE (decl
) != VAR_DECL
|| TREE_STATIC (decl
))
8979 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8980 *no_add_attrs
= true;
8984 /* Verify that the argument is a function in scope. */
8985 /* ??? We could support pointers to functions here as well, if
8986 that was considered desirable. */
8987 cleanup_id
= TREE_VALUE (args
);
8988 if (TREE_CODE (cleanup_id
) != IDENTIFIER_NODE
)
8990 error ("cleanup argument not an identifier");
8991 *no_add_attrs
= true;
8994 cleanup_decl
= lookup_name (cleanup_id
);
8995 if (!cleanup_decl
|| TREE_CODE (cleanup_decl
) != FUNCTION_DECL
)
8997 error ("cleanup argument not a function");
8998 *no_add_attrs
= true;
9002 /* That the function has proper type is checked with the
9003 eventual call to build_function_call. */
9008 /* Handle a "warn_unused_result" attribute. No special handling. */
9011 handle_warn_unused_result_attribute (tree
*node
, tree name
,
9012 tree
ARG_UNUSED (args
),
9013 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9015 /* Ignore the attribute for functions not returning any value. */
9016 if (VOID_TYPE_P (TREE_TYPE (*node
)))
9018 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9019 *no_add_attrs
= true;
9025 /* Handle a "sentinel" attribute. */
9028 handle_sentinel_attribute (tree
*node
, tree name
, tree args
,
9029 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9031 if (!prototype_p (*node
))
9033 warning (OPT_Wattributes
,
9034 "%qE attribute requires prototypes with named arguments", name
);
9035 *no_add_attrs
= true;
9039 if (!stdarg_p (*node
))
9041 warning (OPT_Wattributes
,
9042 "%qE attribute only applies to variadic functions", name
);
9043 *no_add_attrs
= true;
9049 tree position
= TREE_VALUE (args
);
9050 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
9051 && TREE_CODE (position
) != FUNCTION_DECL
)
9052 position
= default_conversion (position
);
9054 if (TREE_CODE (position
) != INTEGER_CST
9055 || !INTEGRAL_TYPE_P (TREE_TYPE (position
)))
9057 warning (OPT_Wattributes
,
9058 "requested position is not an integer constant");
9059 *no_add_attrs
= true;
9063 if (tree_int_cst_lt (position
, integer_zero_node
))
9065 warning (OPT_Wattributes
,
9066 "requested position is less than zero");
9067 *no_add_attrs
= true;
9075 /* Handle a "type_generic" attribute. */
9078 handle_type_generic_attribute (tree
*node
, tree
ARG_UNUSED (name
),
9079 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
9080 bool * ARG_UNUSED (no_add_attrs
))
9082 /* Ensure we have a function type. */
9083 gcc_assert (TREE_CODE (*node
) == FUNCTION_TYPE
);
9085 /* Ensure we have a variadic function. */
9086 gcc_assert (!prototype_p (*node
) || stdarg_p (*node
));
9091 /* Handle a "target" attribute. */
9094 handle_target_attribute (tree
*node
, tree name
, tree args
, int flags
,
9097 /* Ensure we have a function type. */
9098 if (TREE_CODE (*node
) != FUNCTION_DECL
)
9100 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9101 *no_add_attrs
= true;
9103 else if (! targetm
.target_option
.valid_attribute_p (*node
, name
, args
,
9105 *no_add_attrs
= true;
9110 /* Arguments being collected for optimization. */
9111 typedef const char *const_char_p
; /* For DEF_VEC_P. */
9112 static GTY(()) vec
<const_char_p
, va_gc
> *optimize_args
;
9115 /* Inner function to convert a TREE_LIST to argv string to parse the optimize
9116 options in ARGS. ATTR_P is true if this is for attribute(optimize), and
9117 false for #pragma GCC optimize. */
9120 parse_optimize_options (tree args
, bool attr_p
)
9125 int saved_flag_strict_aliasing
;
9126 const char **opt_argv
;
9127 struct cl_decoded_option
*decoded_options
;
9128 unsigned int decoded_options_count
;
9131 /* Build up argv vector. Just in case the string is stored away, use garbage
9132 collected strings. */
9133 vec_safe_truncate (optimize_args
, 0);
9134 vec_safe_push (optimize_args
, (const char *) NULL
);
9136 for (ap
= args
; ap
!= NULL_TREE
; ap
= TREE_CHAIN (ap
))
9138 tree value
= TREE_VALUE (ap
);
9140 if (TREE_CODE (value
) == INTEGER_CST
)
9143 sprintf (buffer
, "-O%ld", (long) TREE_INT_CST_LOW (value
));
9144 vec_safe_push (optimize_args
, ggc_strdup (buffer
));
9147 else if (TREE_CODE (value
) == STRING_CST
)
9149 /* Split string into multiple substrings. */
9150 size_t len
= TREE_STRING_LENGTH (value
);
9151 char *p
= ASTRDUP (TREE_STRING_POINTER (value
));
9152 char *end
= p
+ len
;
9156 while (next_p
!= NULL
)
9162 comma
= strchr (p
, ',');
9175 r
= q
= (char *) ggc_alloc_atomic (len2
+ 3);
9177 /* If the user supplied -Oxxx or -fxxx, only allow -Oxxx or -fxxx
9179 if (*p
== '-' && p
[1] != 'O' && p
[1] != 'f')
9183 warning (OPT_Wattributes
,
9184 "bad option %s to optimize attribute", p
);
9186 warning (OPT_Wpragmas
,
9187 "bad option %s to pragma attribute", p
);
9195 /* Assume that Ox is -Ox, a numeric value is -Ox, a s by
9196 itself is -Os, and any other switch begins with a -f. */
9197 if ((*p
>= '0' && *p
<= '9')
9198 || (p
[0] == 's' && p
[1] == '\0'))
9204 memcpy (r
, p
, len2
);
9206 vec_safe_push (optimize_args
, (const char *) q
);
9212 opt_argc
= optimize_args
->length ();
9213 opt_argv
= (const char **) alloca (sizeof (char *) * (opt_argc
+ 1));
9215 for (i
= 1; i
< opt_argc
; i
++)
9216 opt_argv
[i
] = (*optimize_args
)[i
];
9218 saved_flag_strict_aliasing
= flag_strict_aliasing
;
9220 /* Now parse the options. */
9221 decode_cmdline_options_to_array_default_mask (opt_argc
, opt_argv
,
9223 &decoded_options_count
);
9224 decode_options (&global_options
, &global_options_set
,
9225 decoded_options
, decoded_options_count
,
9226 input_location
, global_dc
);
9228 targetm
.override_options_after_change();
9230 /* Don't allow changing -fstrict-aliasing. */
9231 flag_strict_aliasing
= saved_flag_strict_aliasing
;
9233 optimize_args
->truncate (0);
9237 /* For handling "optimize" attribute. arguments as in
9238 struct attribute_spec.handler. */
9241 handle_optimize_attribute (tree
*node
, tree name
, tree args
,
9242 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9244 /* Ensure we have a function type. */
9245 if (TREE_CODE (*node
) != FUNCTION_DECL
)
9247 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9248 *no_add_attrs
= true;
9252 struct cl_optimization cur_opts
;
9253 tree old_opts
= DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
);
9255 /* Save current options. */
9256 cl_optimization_save (&cur_opts
, &global_options
);
9258 /* If we previously had some optimization options, use them as the
9261 cl_optimization_restore (&global_options
,
9262 TREE_OPTIMIZATION (old_opts
));
9264 /* Parse options, and update the vector. */
9265 parse_optimize_options (args
, true);
9266 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
)
9267 = build_optimization_node (&global_options
);
9269 /* Restore current options. */
9270 cl_optimization_restore (&global_options
, &cur_opts
);
9276 /* Handle a "no_split_stack" attribute. */
9279 handle_no_split_stack_attribute (tree
*node
, tree name
,
9280 tree
ARG_UNUSED (args
),
9281 int ARG_UNUSED (flags
),
9286 if (TREE_CODE (decl
) != FUNCTION_DECL
)
9288 error_at (DECL_SOURCE_LOCATION (decl
),
9289 "%qE attribute applies only to functions", name
);
9290 *no_add_attrs
= true;
9292 else if (DECL_INITIAL (decl
))
9294 error_at (DECL_SOURCE_LOCATION (decl
),
9295 "can%'t set %qE attribute after definition", name
);
9296 *no_add_attrs
= true;
9302 /* Handle a "returns_nonnull" attribute; arguments as in
9303 struct attribute_spec.handler. */
9306 handle_returns_nonnull_attribute (tree
*node
, tree
, tree
, int,
9309 // Even without a prototype we still have a return type we can check.
9310 if (TREE_CODE (TREE_TYPE (*node
)) != POINTER_TYPE
)
9312 error ("returns_nonnull attribute on a function not returning a pointer");
9313 *no_add_attrs
= true;
9318 /* Handle a "designated_init" attribute; arguments as in
9319 struct attribute_spec.handler. */
9322 handle_designated_init_attribute (tree
*node
, tree name
, tree
, int,
9325 if (TREE_CODE (*node
) != RECORD_TYPE
)
9327 error ("%qE attribute is only valid on %<struct%> type", name
);
9328 *no_add_attrs
= true;
9334 /* Check for valid arguments being passed to a function with FNTYPE.
9335 There are NARGS arguments in the array ARGARRAY. */
9337 check_function_arguments (const_tree fntype
, int nargs
, tree
*argarray
)
9339 /* Check for null being passed in a pointer argument that must be
9340 non-null. We also need to do this if format checking is enabled. */
9343 check_function_nonnull (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
9345 /* Check for errors in format strings. */
9347 if (warn_format
|| warn_suggest_attribute_format
)
9348 check_function_format (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
9351 check_function_sentinel (fntype
, nargs
, argarray
);
9354 /* Generic argument checking recursion routine. PARAM is the argument to
9355 be checked. PARAM_NUM is the number of the argument. CALLBACK is invoked
9356 once the argument is resolved. CTX is context for the callback. */
9358 check_function_arguments_recurse (void (*callback
)
9359 (void *, tree
, unsigned HOST_WIDE_INT
),
9360 void *ctx
, tree param
,
9361 unsigned HOST_WIDE_INT param_num
)
9363 if (CONVERT_EXPR_P (param
)
9364 && (TYPE_PRECISION (TREE_TYPE (param
))
9365 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (param
, 0)))))
9367 /* Strip coercion. */
9368 check_function_arguments_recurse (callback
, ctx
,
9369 TREE_OPERAND (param
, 0), param_num
);
9373 if (TREE_CODE (param
) == CALL_EXPR
)
9375 tree type
= TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (param
)));
9377 bool found_format_arg
= false;
9379 /* See if this is a call to a known internationalization function
9380 that modifies a format arg. Such a function may have multiple
9381 format_arg attributes (for example, ngettext). */
9383 for (attrs
= TYPE_ATTRIBUTES (type
);
9385 attrs
= TREE_CHAIN (attrs
))
9386 if (is_attribute_p ("format_arg", TREE_PURPOSE (attrs
)))
9389 tree format_num_expr
;
9392 call_expr_arg_iterator iter
;
9394 /* Extract the argument number, which was previously checked
9396 format_num_expr
= TREE_VALUE (TREE_VALUE (attrs
));
9398 format_num
= tree_to_uhwi (format_num_expr
);
9400 for (inner_arg
= first_call_expr_arg (param
, &iter
), i
= 1;
9402 inner_arg
= next_call_expr_arg (&iter
), i
++)
9403 if (i
== format_num
)
9405 check_function_arguments_recurse (callback
, ctx
,
9406 inner_arg
, param_num
);
9407 found_format_arg
= true;
9412 /* If we found a format_arg attribute and did a recursive check,
9413 we are done with checking this argument. Otherwise, we continue
9414 and this will be considered a non-literal. */
9415 if (found_format_arg
)
9419 if (TREE_CODE (param
) == COND_EXPR
)
9421 /* Check both halves of the conditional expression. */
9422 check_function_arguments_recurse (callback
, ctx
,
9423 TREE_OPERAND (param
, 1), param_num
);
9424 check_function_arguments_recurse (callback
, ctx
,
9425 TREE_OPERAND (param
, 2), param_num
);
9429 (*callback
) (ctx
, param
, param_num
);
9432 /* Checks for a builtin function FNDECL that the number of arguments
9433 NARGS against the required number REQUIRED and issues an error if
9434 there is a mismatch. Returns true if the number of arguments is
9435 correct, otherwise false. */
9438 builtin_function_validate_nargs (tree fndecl
, int nargs
, int required
)
9440 if (nargs
< required
)
9442 error_at (input_location
,
9443 "not enough arguments to function %qE", fndecl
);
9446 else if (nargs
> required
)
9448 error_at (input_location
,
9449 "too many arguments to function %qE", fndecl
);
9455 /* Verifies the NARGS arguments ARGS to the builtin function FNDECL.
9456 Returns false if there was an error, otherwise true. */
9459 check_builtin_function_arguments (tree fndecl
, int nargs
, tree
*args
)
9461 if (!DECL_BUILT_IN (fndecl
)
9462 || DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_NORMAL
)
9465 switch (DECL_FUNCTION_CODE (fndecl
))
9467 case BUILT_IN_CONSTANT_P
:
9468 return builtin_function_validate_nargs (fndecl
, nargs
, 1);
9470 case BUILT_IN_ISFINITE
:
9471 case BUILT_IN_ISINF
:
9472 case BUILT_IN_ISINF_SIGN
:
9473 case BUILT_IN_ISNAN
:
9474 case BUILT_IN_ISNORMAL
:
9475 if (builtin_function_validate_nargs (fndecl
, nargs
, 1))
9477 if (TREE_CODE (TREE_TYPE (args
[0])) != REAL_TYPE
)
9479 error ("non-floating-point argument in call to "
9480 "function %qE", fndecl
);
9487 case BUILT_IN_ISGREATER
:
9488 case BUILT_IN_ISGREATEREQUAL
:
9489 case BUILT_IN_ISLESS
:
9490 case BUILT_IN_ISLESSEQUAL
:
9491 case BUILT_IN_ISLESSGREATER
:
9492 case BUILT_IN_ISUNORDERED
:
9493 if (builtin_function_validate_nargs (fndecl
, nargs
, 2))
9495 enum tree_code code0
, code1
;
9496 code0
= TREE_CODE (TREE_TYPE (args
[0]));
9497 code1
= TREE_CODE (TREE_TYPE (args
[1]));
9498 if (!((code0
== REAL_TYPE
&& code1
== REAL_TYPE
)
9499 || (code0
== REAL_TYPE
&& code1
== INTEGER_TYPE
)
9500 || (code0
== INTEGER_TYPE
&& code1
== REAL_TYPE
)))
9502 error ("non-floating-point arguments in call to "
9503 "function %qE", fndecl
);
9510 case BUILT_IN_FPCLASSIFY
:
9511 if (builtin_function_validate_nargs (fndecl
, nargs
, 6))
9516 if (TREE_CODE (args
[i
]) != INTEGER_CST
)
9518 error ("non-const integer argument %u in call to function %qE",
9523 if (TREE_CODE (TREE_TYPE (args
[5])) != REAL_TYPE
)
9525 error ("non-floating-point argument in call to function %qE",
9533 case BUILT_IN_ASSUME_ALIGNED
:
9534 if (builtin_function_validate_nargs (fndecl
, nargs
, 2 + (nargs
> 2)))
9536 if (nargs
>= 3 && TREE_CODE (TREE_TYPE (args
[2])) != INTEGER_TYPE
)
9538 error ("non-integer argument 3 in call to function %qE", fndecl
);
9550 /* Function to help qsort sort FIELD_DECLs by name order. */
9553 field_decl_cmp (const void *x_p
, const void *y_p
)
9555 const tree
*const x
= (const tree
*const) x_p
;
9556 const tree
*const y
= (const tree
*const) y_p
;
9558 if (DECL_NAME (*x
) == DECL_NAME (*y
))
9559 /* A nontype is "greater" than a type. */
9560 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
9561 if (DECL_NAME (*x
) == NULL_TREE
)
9563 if (DECL_NAME (*y
) == NULL_TREE
)
9565 if (DECL_NAME (*x
) < DECL_NAME (*y
))
9571 gt_pointer_operator new_value
;
9575 /* This routine compares two fields like field_decl_cmp but using the
9576 pointer operator in resort_data. */
9579 resort_field_decl_cmp (const void *x_p
, const void *y_p
)
9581 const tree
*const x
= (const tree
*const) x_p
;
9582 const tree
*const y
= (const tree
*const) y_p
;
9584 if (DECL_NAME (*x
) == DECL_NAME (*y
))
9585 /* A nontype is "greater" than a type. */
9586 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
9587 if (DECL_NAME (*x
) == NULL_TREE
)
9589 if (DECL_NAME (*y
) == NULL_TREE
)
9592 tree d1
= DECL_NAME (*x
);
9593 tree d2
= DECL_NAME (*y
);
9594 resort_data
.new_value (&d1
, resort_data
.cookie
);
9595 resort_data
.new_value (&d2
, resort_data
.cookie
);
9602 /* Resort DECL_SORTED_FIELDS because pointers have been reordered. */
9605 resort_sorted_fields (void *obj
,
9606 void * ARG_UNUSED (orig_obj
),
9607 gt_pointer_operator new_value
,
9610 struct sorted_fields_type
*sf
= (struct sorted_fields_type
*) obj
;
9611 resort_data
.new_value
= new_value
;
9612 resort_data
.cookie
= cookie
;
9613 qsort (&sf
->elts
[0], sf
->len
, sizeof (tree
),
9614 resort_field_decl_cmp
);
9617 /* Subroutine of c_parse_error.
9618 Return the result of concatenating LHS and RHS. RHS is really
9619 a string literal, its first character is indicated by RHS_START and
9620 RHS_SIZE is its length (including the terminating NUL character).
9622 The caller is responsible for deleting the returned pointer. */
9625 catenate_strings (const char *lhs
, const char *rhs_start
, int rhs_size
)
9627 const int lhs_size
= strlen (lhs
);
9628 char *result
= XNEWVEC (char, lhs_size
+ rhs_size
);
9629 strncpy (result
, lhs
, lhs_size
);
9630 strncpy (result
+ lhs_size
, rhs_start
, rhs_size
);
9634 /* Issue the error given by GMSGID, indicating that it occurred before
9635 TOKEN, which had the associated VALUE. */
9638 c_parse_error (const char *gmsgid
, enum cpp_ttype token_type
,
9639 tree value
, unsigned char token_flags
)
9641 #define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2))
9643 char *message
= NULL
;
9645 if (token_type
== CPP_EOF
)
9646 message
= catenate_messages (gmsgid
, " at end of input");
9647 else if (token_type
== CPP_CHAR
9648 || token_type
== CPP_WCHAR
9649 || token_type
== CPP_CHAR16
9650 || token_type
== CPP_CHAR32
)
9652 unsigned int val
= TREE_INT_CST_LOW (value
);
9671 if (val
<= UCHAR_MAX
&& ISGRAPH (val
))
9672 message
= catenate_messages (gmsgid
, " before %s'%c'");
9674 message
= catenate_messages (gmsgid
, " before %s'\\x%x'");
9676 error (message
, prefix
, val
);
9680 else if (token_type
== CPP_CHAR_USERDEF
9681 || token_type
== CPP_WCHAR_USERDEF
9682 || token_type
== CPP_CHAR16_USERDEF
9683 || token_type
== CPP_CHAR32_USERDEF
)
9684 message
= catenate_messages (gmsgid
,
9685 " before user-defined character literal");
9686 else if (token_type
== CPP_STRING_USERDEF
9687 || token_type
== CPP_WSTRING_USERDEF
9688 || token_type
== CPP_STRING16_USERDEF
9689 || token_type
== CPP_STRING32_USERDEF
9690 || token_type
== CPP_UTF8STRING_USERDEF
)
9691 message
= catenate_messages (gmsgid
, " before user-defined string literal");
9692 else if (token_type
== CPP_STRING
9693 || token_type
== CPP_WSTRING
9694 || token_type
== CPP_STRING16
9695 || token_type
== CPP_STRING32
9696 || token_type
== CPP_UTF8STRING
)
9697 message
= catenate_messages (gmsgid
, " before string constant");
9698 else if (token_type
== CPP_NUMBER
)
9699 message
= catenate_messages (gmsgid
, " before numeric constant");
9700 else if (token_type
== CPP_NAME
)
9702 message
= catenate_messages (gmsgid
, " before %qE");
9703 error (message
, value
);
9707 else if (token_type
== CPP_PRAGMA
)
9708 message
= catenate_messages (gmsgid
, " before %<#pragma%>");
9709 else if (token_type
== CPP_PRAGMA_EOL
)
9710 message
= catenate_messages (gmsgid
, " before end of line");
9711 else if (token_type
== CPP_DECLTYPE
)
9712 message
= catenate_messages (gmsgid
, " before %<decltype%>");
9713 else if (token_type
< N_TTYPES
)
9715 message
= catenate_messages (gmsgid
, " before %qs token");
9716 error (message
, cpp_type2name (token_type
, token_flags
));
9728 #undef catenate_messages
9731 /* Return the gcc option code associated with the reason for a cpp
9732 message, or 0 if none. */
9735 c_option_controlling_cpp_error (int reason
)
9737 const struct cpp_reason_option_codes_t
*entry
;
9739 for (entry
= cpp_reason_option_codes
; entry
->reason
!= CPP_W_NONE
; entry
++)
9741 if (entry
->reason
== reason
)
9742 return entry
->option_code
;
9747 /* Callback from cpp_error for PFILE to print diagnostics from the
9748 preprocessor. The diagnostic is of type LEVEL, with REASON set
9749 to the reason code if LEVEL is represents a warning, at location
9750 LOCATION unless this is after lexing and the compiler's location
9751 should be used instead, with column number possibly overridden by
9752 COLUMN_OVERRIDE if not zero; MSG is the translated message and AP
9753 the arguments. Returns true if a diagnostic was emitted, false
9757 c_cpp_error (cpp_reader
*pfile ATTRIBUTE_UNUSED
, int level
, int reason
,
9758 location_t location
, unsigned int column_override
,
9759 const char *msg
, va_list *ap
)
9761 diagnostic_info diagnostic
;
9762 diagnostic_t dlevel
;
9763 bool save_warn_system_headers
= global_dc
->dc_warn_system_headers
;
9768 case CPP_DL_WARNING_SYSHDR
:
9771 global_dc
->dc_warn_system_headers
= 1;
9773 case CPP_DL_WARNING
:
9776 dlevel
= DK_WARNING
;
9778 case CPP_DL_PEDWARN
:
9779 if (flag_no_output
&& !flag_pedantic_errors
)
9781 dlevel
= DK_PEDWARN
;
9799 location
= input_location
;
9800 diagnostic_set_info_translated (&diagnostic
, msg
, ap
,
9802 if (column_override
)
9803 diagnostic_override_column (&diagnostic
, column_override
);
9804 diagnostic_override_option_index (&diagnostic
,
9805 c_option_controlling_cpp_error (reason
));
9806 ret
= report_diagnostic (&diagnostic
);
9807 if (level
== CPP_DL_WARNING_SYSHDR
)
9808 global_dc
->dc_warn_system_headers
= save_warn_system_headers
;
9812 /* Convert a character from the host to the target execution character
9813 set. cpplib handles this, mostly. */
9816 c_common_to_target_charset (HOST_WIDE_INT c
)
9818 /* Character constants in GCC proper are sign-extended under -fsigned-char,
9819 zero-extended under -fno-signed-char. cpplib insists that characters
9820 and character constants are always unsigned. Hence we must convert
9822 cppchar_t uc
= ((cppchar_t
)c
) & ((((cppchar_t
)1) << CHAR_BIT
)-1);
9824 uc
= cpp_host_to_exec_charset (parse_in
, uc
);
9826 if (flag_signed_char
)
9827 return ((HOST_WIDE_INT
)uc
) << (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
)
9828 >> (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
);
9833 /* Fold an offsetof-like expression. EXPR is a nested sequence of component
9834 references with an INDIRECT_REF of a constant at the bottom; much like the
9835 traditional rendering of offsetof as a macro. Return the folded result. */
9838 fold_offsetof_1 (tree expr
)
9842 switch (TREE_CODE (expr
))
9848 error ("cannot apply %<offsetof%> to static data member %qD", expr
);
9849 return error_mark_node
;
9853 error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded");
9854 return error_mark_node
;
9858 if (!TREE_CONSTANT (TREE_OPERAND (expr
, 0)))
9860 error ("cannot apply %<offsetof%> to a non constant address");
9861 return error_mark_node
;
9863 return TREE_OPERAND (expr
, 0);
9866 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0));
9867 if (base
== error_mark_node
)
9870 t
= TREE_OPERAND (expr
, 1);
9871 if (DECL_C_BIT_FIELD (t
))
9873 error ("attempt to take address of bit-field structure "
9875 return error_mark_node
;
9877 off
= size_binop_loc (input_location
, PLUS_EXPR
, DECL_FIELD_OFFSET (t
),
9878 size_int (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (t
))
9883 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0));
9884 if (base
== error_mark_node
)
9887 t
= TREE_OPERAND (expr
, 1);
9889 /* Check if the offset goes beyond the upper bound of the array. */
9890 if (TREE_CODE (t
) == INTEGER_CST
&& tree_int_cst_sgn (t
) >= 0)
9892 tree upbound
= array_ref_up_bound (expr
);
9893 if (upbound
!= NULL_TREE
9894 && TREE_CODE (upbound
) == INTEGER_CST
9895 && !tree_int_cst_equal (upbound
,
9896 TYPE_MAX_VALUE (TREE_TYPE (upbound
))))
9898 upbound
= size_binop (PLUS_EXPR
, upbound
,
9899 build_int_cst (TREE_TYPE (upbound
), 1));
9900 if (tree_int_cst_lt (upbound
, t
))
9904 for (v
= TREE_OPERAND (expr
, 0);
9905 TREE_CODE (v
) == COMPONENT_REF
;
9906 v
= TREE_OPERAND (v
, 0))
9907 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v
, 0)))
9910 tree fld_chain
= DECL_CHAIN (TREE_OPERAND (v
, 1));
9911 for (; fld_chain
; fld_chain
= DECL_CHAIN (fld_chain
))
9912 if (TREE_CODE (fld_chain
) == FIELD_DECL
)
9918 /* Don't warn if the array might be considered a poor
9919 man's flexible array member with a very permissive
9920 definition thereof. */
9921 if (TREE_CODE (v
) == ARRAY_REF
9922 || TREE_CODE (v
) == COMPONENT_REF
)
9923 warning (OPT_Warray_bounds
,
9924 "index %E denotes an offset "
9925 "greater than size of %qT",
9926 t
, TREE_TYPE (TREE_OPERAND (expr
, 0)));
9931 t
= convert (sizetype
, t
);
9932 off
= size_binop (MULT_EXPR
, TYPE_SIZE_UNIT (TREE_TYPE (expr
)), t
);
9936 /* Handle static members of volatile structs. */
9937 t
= TREE_OPERAND (expr
, 1);
9938 gcc_assert (TREE_CODE (t
) == VAR_DECL
);
9939 return fold_offsetof_1 (t
);
9945 return fold_build_pointer_plus (base
, off
);
9948 /* Likewise, but convert it to the return type of offsetof. */
9951 fold_offsetof (tree expr
)
9953 return convert (size_type_node
, fold_offsetof_1 (expr
));
9956 /* Warn for A ?: C expressions (with B omitted) where A is a boolean
9957 expression, because B will always be true. */
9960 warn_for_omitted_condop (location_t location
, tree cond
)
9962 if (truth_value_p (TREE_CODE (cond
)))
9963 warning_at (location
, OPT_Wparentheses
,
9964 "the omitted middle operand in ?: will always be %<true%>, "
9965 "suggest explicit middle operand");
9968 /* Give an error for storing into ARG, which is 'const'. USE indicates
9969 how ARG was being used. */
9972 readonly_error (location_t loc
, tree arg
, enum lvalue_use use
)
9974 gcc_assert (use
== lv_assign
|| use
== lv_increment
|| use
== lv_decrement
9976 /* Using this macro rather than (for example) arrays of messages
9977 ensures that all the format strings are checked at compile
9979 #define READONLY_MSG(A, I, D, AS) (use == lv_assign ? (A) \
9980 : (use == lv_increment ? (I) \
9981 : (use == lv_decrement ? (D) : (AS))))
9982 if (TREE_CODE (arg
) == COMPONENT_REF
)
9984 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg
, 0))))
9985 error_at (loc
, READONLY_MSG (G_("assignment of member "
9986 "%qD in read-only object"),
9987 G_("increment of member "
9988 "%qD in read-only object"),
9989 G_("decrement of member "
9990 "%qD in read-only object"),
9991 G_("member %qD in read-only object "
9992 "used as %<asm%> output")),
9993 TREE_OPERAND (arg
, 1));
9995 error_at (loc
, READONLY_MSG (G_("assignment of read-only member %qD"),
9996 G_("increment of read-only member %qD"),
9997 G_("decrement of read-only member %qD"),
9998 G_("read-only member %qD used as %<asm%> output")),
9999 TREE_OPERAND (arg
, 1));
10001 else if (TREE_CODE (arg
) == VAR_DECL
)
10002 error_at (loc
, READONLY_MSG (G_("assignment of read-only variable %qD"),
10003 G_("increment of read-only variable %qD"),
10004 G_("decrement of read-only variable %qD"),
10005 G_("read-only variable %qD used as %<asm%> output")),
10007 else if (TREE_CODE (arg
) == PARM_DECL
)
10008 error_at (loc
, READONLY_MSG (G_("assignment of read-only parameter %qD"),
10009 G_("increment of read-only parameter %qD"),
10010 G_("decrement of read-only parameter %qD"),
10011 G_("read-only parameter %qD use as %<asm%> output")),
10013 else if (TREE_CODE (arg
) == RESULT_DECL
)
10015 gcc_assert (c_dialect_cxx ());
10016 error_at (loc
, READONLY_MSG (G_("assignment of "
10017 "read-only named return value %qD"),
10019 "read-only named return value %qD"),
10021 "read-only named return value %qD"),
10022 G_("read-only named return value %qD "
10023 "used as %<asm%>output")),
10026 else if (TREE_CODE (arg
) == FUNCTION_DECL
)
10027 error_at (loc
, READONLY_MSG (G_("assignment of function %qD"),
10028 G_("increment of function %qD"),
10029 G_("decrement of function %qD"),
10030 G_("function %qD used as %<asm%> output")),
10033 error_at (loc
, READONLY_MSG (G_("assignment of read-only location %qE"),
10034 G_("increment of read-only location %qE"),
10035 G_("decrement of read-only location %qE"),
10036 G_("read-only location %qE used as %<asm%> output")),
10040 /* Print an error message for an invalid lvalue. USE says
10041 how the lvalue is being used and so selects the error message. LOC
10042 is the location for the error. */
10045 lvalue_error (location_t loc
, enum lvalue_use use
)
10050 error_at (loc
, "lvalue required as left operand of assignment");
10053 error_at (loc
, "lvalue required as increment operand");
10056 error_at (loc
, "lvalue required as decrement operand");
10059 error_at (loc
, "lvalue required as unary %<&%> operand");
10062 error_at (loc
, "lvalue required in asm statement");
10065 gcc_unreachable ();
10069 /* Print an error message for an invalid indirection of type TYPE.
10070 ERRSTRING is the name of the operator for the indirection. */
10073 invalid_indirection_error (location_t loc
, tree type
, ref_operator errstring
)
10078 gcc_assert (c_dialect_cxx ());
10079 error_at (loc
, "invalid type argument (have %qT)", type
);
10081 case RO_ARRAY_INDEXING
:
10083 "invalid type argument of array indexing (have %qT)",
10086 case RO_UNARY_STAR
:
10088 "invalid type argument of unary %<*%> (have %qT)",
10093 "invalid type argument of %<->%> (have %qT)",
10096 case RO_ARROW_STAR
:
10098 "invalid type argument of %<->*%> (have %qT)",
10101 case RO_IMPLICIT_CONVERSION
:
10103 "invalid type argument of implicit conversion (have %qT)",
10107 gcc_unreachable ();
10111 /* *PTYPE is an incomplete array. Complete it with a domain based on
10112 INITIAL_VALUE. If INITIAL_VALUE is not present, use 1 if DO_DEFAULT
10113 is true. Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
10114 2 if INITIAL_VALUE was NULL, and 3 if INITIAL_VALUE was empty. */
10117 complete_array_type (tree
*ptype
, tree initial_value
, bool do_default
)
10119 tree maxindex
, type
, main_type
, elt
, unqual_elt
;
10120 int failure
= 0, quals
;
10121 hashval_t hashcode
= 0;
10122 bool overflow_p
= false;
10124 maxindex
= size_zero_node
;
10127 if (TREE_CODE (initial_value
) == STRING_CST
)
10130 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value
)));
10131 maxindex
= size_int (TREE_STRING_LENGTH (initial_value
)/eltsize
- 1);
10133 else if (TREE_CODE (initial_value
) == CONSTRUCTOR
)
10135 vec
<constructor_elt
, va_gc
> *v
= CONSTRUCTOR_ELTS (initial_value
);
10137 if (vec_safe_is_empty (v
))
10141 maxindex
= ssize_int (-1);
10146 unsigned HOST_WIDE_INT cnt
;
10147 constructor_elt
*ce
;
10148 bool fold_p
= false;
10151 maxindex
= (*v
)[0].index
, fold_p
= true;
10153 curindex
= maxindex
;
10155 for (cnt
= 1; vec_safe_iterate (v
, cnt
, &ce
); cnt
++)
10157 bool curfold_p
= false;
10159 curindex
= ce
->index
, curfold_p
= true;
10164 /* Since we treat size types now as ordinary
10165 unsigned types, we need an explicit overflow
10167 tree orig
= curindex
;
10168 curindex
= fold_convert (sizetype
, curindex
);
10169 overflow_p
|= tree_int_cst_lt (curindex
, orig
);
10171 curindex
= size_binop (PLUS_EXPR
, curindex
,
10174 if (tree_int_cst_lt (maxindex
, curindex
))
10175 maxindex
= curindex
, fold_p
= curfold_p
;
10179 tree orig
= maxindex
;
10180 maxindex
= fold_convert (sizetype
, maxindex
);
10181 overflow_p
|= tree_int_cst_lt (maxindex
, orig
);
10187 /* Make an error message unless that happened already. */
10188 if (initial_value
!= error_mark_node
)
10200 elt
= TREE_TYPE (type
);
10201 quals
= TYPE_QUALS (strip_array_types (elt
));
10205 unqual_elt
= c_build_qualified_type (elt
, KEEP_QUAL_ADDR_SPACE (quals
));
10207 /* Using build_distinct_type_copy and modifying things afterward instead
10208 of using build_array_type to create a new type preserves all of the
10209 TYPE_LANG_FLAG_? bits that the front end may have set. */
10210 main_type
= build_distinct_type_copy (TYPE_MAIN_VARIANT (type
));
10211 TREE_TYPE (main_type
) = unqual_elt
;
10212 TYPE_DOMAIN (main_type
)
10213 = build_range_type (TREE_TYPE (maxindex
),
10214 build_int_cst (TREE_TYPE (maxindex
), 0), maxindex
);
10215 layout_type (main_type
);
10217 /* Make sure we have the canonical MAIN_TYPE. */
10218 hashcode
= iterative_hash_object (TYPE_HASH (unqual_elt
), hashcode
);
10219 hashcode
= iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (main_type
)),
10221 main_type
= type_hash_canon (hashcode
, main_type
);
10223 /* Fix the canonical type. */
10224 if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type
))
10225 || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type
)))
10226 SET_TYPE_STRUCTURAL_EQUALITY (main_type
);
10227 else if (TYPE_CANONICAL (TREE_TYPE (main_type
)) != TREE_TYPE (main_type
)
10228 || (TYPE_CANONICAL (TYPE_DOMAIN (main_type
))
10229 != TYPE_DOMAIN (main_type
)))
10230 TYPE_CANONICAL (main_type
)
10231 = build_array_type (TYPE_CANONICAL (TREE_TYPE (main_type
)),
10232 TYPE_CANONICAL (TYPE_DOMAIN (main_type
)));
10234 TYPE_CANONICAL (main_type
) = main_type
;
10239 type
= c_build_qualified_type (main_type
, quals
);
10241 if (COMPLETE_TYPE_P (type
)
10242 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
10243 && (overflow_p
|| TREE_OVERFLOW (TYPE_SIZE_UNIT (type
))))
10245 error ("size of array is too large");
10246 /* If we proceed with the array type as it is, we'll eventually
10247 crash in tree_to_[su]hwi(). */
10248 type
= error_mark_node
;
10255 /* Like c_mark_addressable but don't check register qualifier. */
10257 c_common_mark_addressable_vec (tree t
)
10259 while (handled_component_p (t
))
10260 t
= TREE_OPERAND (t
, 0);
10261 if (TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != PARM_DECL
)
10263 TREE_ADDRESSABLE (t
) = 1;
10268 /* Used to help initialize the builtin-types.def table. When a type of
10269 the correct size doesn't exist, use error_mark_node instead of NULL.
10270 The later results in segfaults even when a decl using the type doesn't
10274 builtin_type_for_size (int size
, bool unsignedp
)
10276 tree type
= c_common_type_for_size (size
, unsignedp
);
10277 return type
? type
: error_mark_node
;
10280 /* A helper function for resolve_overloaded_builtin in resolving the
10281 overloaded __sync_ builtins. Returns a positive power of 2 if the
10282 first operand of PARAMS is a pointer to a supported data type.
10283 Returns 0 if an error is encountered. */
10286 sync_resolve_size (tree function
, vec
<tree
, va_gc
> *params
)
10293 error ("too few arguments to function %qE", function
);
10297 type
= TREE_TYPE ((*params
)[0]);
10298 if (TREE_CODE (type
) == ARRAY_TYPE
)
10300 /* Force array-to-pointer decay for C++. */
10301 gcc_assert (c_dialect_cxx());
10302 (*params
)[0] = default_conversion ((*params
)[0]);
10303 type
= TREE_TYPE ((*params
)[0]);
10305 if (TREE_CODE (type
) != POINTER_TYPE
)
10308 type
= TREE_TYPE (type
);
10309 if (!INTEGRAL_TYPE_P (type
) && !POINTER_TYPE_P (type
))
10312 size
= tree_to_uhwi (TYPE_SIZE_UNIT (type
));
10313 if (size
== 1 || size
== 2 || size
== 4 || size
== 8 || size
== 16)
10317 error ("incompatible type for argument %d of %qE", 1, function
);
10321 /* A helper function for resolve_overloaded_builtin. Adds casts to
10322 PARAMS to make arguments match up with those of FUNCTION. Drops
10323 the variadic arguments at the end. Returns false if some error
10324 was encountered; true on success. */
10327 sync_resolve_params (location_t loc
, tree orig_function
, tree function
,
10328 vec
<tree
, va_gc
> *params
, bool orig_format
)
10330 function_args_iterator iter
;
10332 unsigned int parmnum
;
10334 function_args_iter_init (&iter
, TREE_TYPE (function
));
10335 /* We've declared the implementation functions to use "volatile void *"
10336 as the pointer parameter, so we shouldn't get any complaints from the
10337 call to check_function_arguments what ever type the user used. */
10338 function_args_iter_next (&iter
);
10339 ptype
= TREE_TYPE (TREE_TYPE ((*params
)[0]));
10340 ptype
= TYPE_MAIN_VARIANT (ptype
);
10342 /* For the rest of the values, we need to cast these to FTYPE, so that we
10343 don't get warnings for passing pointer types, etc. */
10347 tree val
, arg_type
;
10349 arg_type
= function_args_iter_cond (&iter
);
10350 /* XXX void_type_node belies the abstraction. */
10351 if (arg_type
== void_type_node
)
10355 if (params
->length () <= parmnum
)
10357 error_at (loc
, "too few arguments to function %qE", orig_function
);
10361 /* Only convert parameters if arg_type is unsigned integer type with
10362 new format sync routines, i.e. don't attempt to convert pointer
10363 arguments (e.g. EXPECTED argument of __atomic_compare_exchange_n),
10364 bool arguments (e.g. WEAK argument) or signed int arguments (memmodel
10366 if (TREE_CODE (arg_type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (arg_type
))
10368 /* Ideally for the first conversion we'd use convert_for_assignment
10369 so that we get warnings for anything that doesn't match the pointer
10370 type. This isn't portable across the C and C++ front ends atm. */
10371 val
= (*params
)[parmnum
];
10372 val
= convert (ptype
, val
);
10373 val
= convert (arg_type
, val
);
10374 (*params
)[parmnum
] = val
;
10377 function_args_iter_next (&iter
);
10380 /* __atomic routines are not variadic. */
10381 if (!orig_format
&& params
->length () != parmnum
+ 1)
10383 error_at (loc
, "too many arguments to function %qE", orig_function
);
10387 /* The definition of these primitives is variadic, with the remaining
10388 being "an optional list of variables protected by the memory barrier".
10389 No clue what that's supposed to mean, precisely, but we consider all
10390 call-clobbered variables to be protected so we're safe. */
10391 params
->truncate (parmnum
+ 1);
10396 /* A helper function for resolve_overloaded_builtin. Adds a cast to
10397 RESULT to make it match the type of the first pointer argument in
10401 sync_resolve_return (tree first_param
, tree result
, bool orig_format
)
10403 tree ptype
= TREE_TYPE (TREE_TYPE (first_param
));
10404 tree rtype
= TREE_TYPE (result
);
10405 ptype
= TYPE_MAIN_VARIANT (ptype
);
10407 /* New format doesn't require casting unless the types are the same size. */
10408 if (orig_format
|| tree_int_cst_equal (TYPE_SIZE (ptype
), TYPE_SIZE (rtype
)))
10409 return convert (ptype
, result
);
10414 /* This function verifies the PARAMS to generic atomic FUNCTION.
10415 It returns the size if all the parameters are the same size, otherwise
10416 0 is returned if the parameters are invalid. */
10419 get_atomic_generic_size (location_t loc
, tree function
,
10420 vec
<tree
, va_gc
> *params
)
10422 unsigned int n_param
;
10423 unsigned int n_model
;
10428 /* Determine the parameter makeup. */
10429 switch (DECL_FUNCTION_CODE (function
))
10431 case BUILT_IN_ATOMIC_EXCHANGE
:
10435 case BUILT_IN_ATOMIC_LOAD
:
10436 case BUILT_IN_ATOMIC_STORE
:
10440 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10445 gcc_unreachable ();
10448 if (vec_safe_length (params
) != n_param
)
10450 error_at (loc
, "incorrect number of arguments to function %qE", function
);
10454 /* Get type of first parameter, and determine its size. */
10455 type_0
= TREE_TYPE ((*params
)[0]);
10456 if (TREE_CODE (type_0
) == ARRAY_TYPE
)
10458 /* Force array-to-pointer decay for C++. */
10459 gcc_assert (c_dialect_cxx());
10460 (*params
)[0] = default_conversion ((*params
)[0]);
10461 type_0
= TREE_TYPE ((*params
)[0]);
10463 if (TREE_CODE (type_0
) != POINTER_TYPE
|| VOID_TYPE_P (TREE_TYPE (type_0
)))
10465 error_at (loc
, "argument 1 of %qE must be a non-void pointer type",
10470 /* Types must be compile time constant sizes. */
10471 if (TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type_0
)))) != INTEGER_CST
)
10474 "argument 1 of %qE must be a pointer to a constant size type",
10479 size_0
= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type_0
)));
10481 /* Zero size objects are not allowed. */
10485 "argument 1 of %qE must be a pointer to a nonzero size object",
10490 /* Check each other parameter is a pointer and the same size. */
10491 for (x
= 0; x
< n_param
- n_model
; x
++)
10494 tree type
= TREE_TYPE ((*params
)[x
]);
10495 /* __atomic_compare_exchange has a bool in the 4th position, skip it. */
10496 if (n_param
== 6 && x
== 3)
10498 if (!POINTER_TYPE_P (type
))
10500 error_at (loc
, "argument %d of %qE must be a pointer type", x
+ 1,
10504 tree type_size
= TYPE_SIZE_UNIT (TREE_TYPE (type
));
10505 size
= type_size
? tree_to_uhwi (type_size
) : 0;
10506 if (size
!= size_0
)
10508 error_at (loc
, "size mismatch in argument %d of %qE", x
+ 1,
10514 /* Check memory model parameters for validity. */
10515 for (x
= n_param
- n_model
; x
< n_param
; x
++)
10517 tree p
= (*params
)[x
];
10518 if (TREE_CODE (p
) == INTEGER_CST
)
10520 int i
= tree_to_uhwi (p
);
10521 if (i
< 0 || (i
& MEMMODEL_MASK
) >= MEMMODEL_LAST
)
10523 warning_at (loc
, OPT_Winvalid_memory_model
,
10524 "invalid memory model argument %d of %qE", x
+ 1,
10529 if (!INTEGRAL_TYPE_P (TREE_TYPE (p
)))
10531 error_at (loc
, "non-integer memory model argument %d of %qE", x
+ 1,
10541 /* This will take an __atomic_ generic FUNCTION call, and add a size parameter N
10542 at the beginning of the parameter list PARAMS representing the size of the
10543 objects. This is to match the library ABI requirement. LOC is the location
10544 of the function call.
10545 The new function is returned if it needed rebuilding, otherwise NULL_TREE is
10546 returned to allow the external call to be constructed. */
10549 add_atomic_size_parameter (unsigned n
, location_t loc
, tree function
,
10550 vec
<tree
, va_gc
> *params
)
10554 /* Insert a SIZE_T parameter as the first param. If there isn't
10555 enough space, allocate a new vector and recursively re-build with that. */
10556 if (!params
->space (1))
10558 unsigned int z
, len
;
10559 vec
<tree
, va_gc
> *v
;
10562 len
= params
->length ();
10563 vec_alloc (v
, len
+ 1);
10564 v
->quick_push (build_int_cst (size_type_node
, n
));
10565 for (z
= 0; z
< len
; z
++)
10566 v
->quick_push ((*params
)[z
]);
10567 f
= build_function_call_vec (loc
, vNULL
, function
, v
, NULL
);
10572 /* Add the size parameter and leave as a function call for processing. */
10573 size_node
= build_int_cst (size_type_node
, n
);
10574 params
->quick_insert (0, size_node
);
10579 /* Return whether atomic operations for naturally aligned N-byte
10580 arguments are supported, whether inline or through libatomic. */
10582 atomic_size_supported_p (int n
)
10593 return targetm
.scalar_mode_supported_p (TImode
);
10600 /* This will process an __atomic_exchange function call, determine whether it
10601 needs to be mapped to the _N variation, or turned into a library call.
10602 LOC is the location of the builtin call.
10603 FUNCTION is the DECL that has been invoked;
10604 PARAMS is the argument list for the call. The return value is non-null
10605 TRUE is returned if it is translated into the proper format for a call to the
10606 external library, and NEW_RETURN is set the tree for that function.
10607 FALSE is returned if processing for the _N variation is required, and
10608 NEW_RETURN is set to the the return value the result is copied into. */
10610 resolve_overloaded_atomic_exchange (location_t loc
, tree function
,
10611 vec
<tree
, va_gc
> *params
, tree
*new_return
)
10613 tree p0
, p1
, p2
, p3
;
10614 tree I_type
, I_type_ptr
;
10615 int n
= get_atomic_generic_size (loc
, function
, params
);
10617 /* Size of 0 is an error condition. */
10620 *new_return
= error_mark_node
;
10624 /* If not a lock-free size, change to the library generic format. */
10625 if (!atomic_size_supported_p (n
))
10627 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10631 /* Otherwise there is a lockfree match, transform the call from:
10632 void fn(T* mem, T* desired, T* return, model)
10634 *return = (T) (fn (In* mem, (In) *desired, model)) */
10641 /* Create pointer to appropriate size. */
10642 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10643 I_type_ptr
= build_pointer_type (I_type
);
10645 /* Convert object pointer to required type. */
10646 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10648 /* Convert new value to required type, and dereference it. */
10649 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
10650 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
10653 /* Move memory model to the 3rd position, and end param list. */
10655 params
->truncate (3);
10657 /* Convert return pointer and dereference it for later assignment. */
10658 *new_return
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
10664 /* This will process an __atomic_compare_exchange function call, determine
10665 whether it needs to be mapped to the _N variation, or turned into a lib call.
10666 LOC is the location of the builtin call.
10667 FUNCTION is the DECL that has been invoked;
10668 PARAMS is the argument list for the call. The return value is non-null
10669 TRUE is returned if it is translated into the proper format for a call to the
10670 external library, and NEW_RETURN is set the tree for that function.
10671 FALSE is returned if processing for the _N variation is required. */
10674 resolve_overloaded_atomic_compare_exchange (location_t loc
, tree function
,
10675 vec
<tree
, va_gc
> *params
,
10679 tree I_type
, I_type_ptr
;
10680 int n
= get_atomic_generic_size (loc
, function
, params
);
10682 /* Size of 0 is an error condition. */
10685 *new_return
= error_mark_node
;
10689 /* If not a lock-free size, change to the library generic format. */
10690 if (!atomic_size_supported_p (n
))
10692 /* The library generic format does not have the weak parameter, so
10693 remove it from the param list. Since a parameter has been removed,
10694 we can be sure that there is room for the SIZE_T parameter, meaning
10695 there will not be a recursive rebuilding of the parameter list, so
10696 there is no danger this will be done twice. */
10699 (*params
)[3] = (*params
)[4];
10700 (*params
)[4] = (*params
)[5];
10701 params
->truncate (5);
10703 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10707 /* Otherwise, there is a match, so the call needs to be transformed from:
10708 bool fn(T* mem, T* desired, T* return, weak, success, failure)
10710 bool fn ((In *)mem, (In *)expected, (In) *desired, weak, succ, fail) */
10716 /* Create pointer to appropriate size. */
10717 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10718 I_type_ptr
= build_pointer_type (I_type
);
10720 /* Convert object pointer to required type. */
10721 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10724 /* Convert expected pointer to required type. */
10725 p1
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p1
);
10728 /* Convert desired value to required type, and dereference it. */
10729 p2
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
10730 p2
= build1 (VIEW_CONVERT_EXPR
, I_type
, p2
);
10733 /* The rest of the parameters are fine. NULL means no special return value
10735 *new_return
= NULL
;
10740 /* This will process an __atomic_load function call, determine whether it
10741 needs to be mapped to the _N variation, or turned into a library call.
10742 LOC is the location of the builtin call.
10743 FUNCTION is the DECL that has been invoked;
10744 PARAMS is the argument list for the call. The return value is non-null
10745 TRUE is returned if it is translated into the proper format for a call to the
10746 external library, and NEW_RETURN is set the tree for that function.
10747 FALSE is returned if processing for the _N variation is required, and
10748 NEW_RETURN is set to the the return value the result is copied into. */
10751 resolve_overloaded_atomic_load (location_t loc
, tree function
,
10752 vec
<tree
, va_gc
> *params
, tree
*new_return
)
10755 tree I_type
, I_type_ptr
;
10756 int n
= get_atomic_generic_size (loc
, function
, params
);
10758 /* Size of 0 is an error condition. */
10761 *new_return
= error_mark_node
;
10765 /* If not a lock-free size, change to the library generic format. */
10766 if (!atomic_size_supported_p (n
))
10768 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10772 /* Otherwise, there is a match, so the call needs to be transformed from:
10773 void fn(T* mem, T* return, model)
10775 *return = (T) (fn ((In *) mem, model)) */
10781 /* Create pointer to appropriate size. */
10782 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10783 I_type_ptr
= build_pointer_type (I_type
);
10785 /* Convert object pointer to required type. */
10786 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10789 /* Move memory model to the 2nd position, and end param list. */
10791 params
->truncate (2);
10793 /* Convert return pointer and dereference it for later assignment. */
10794 *new_return
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
10800 /* This will process an __atomic_store function call, determine whether it
10801 needs to be mapped to the _N variation, or turned into a library call.
10802 LOC is the location of the builtin call.
10803 FUNCTION is the DECL that has been invoked;
10804 PARAMS is the argument list for the call. The return value is non-null
10805 TRUE is returned if it is translated into the proper format for a call to the
10806 external library, and NEW_RETURN is set the tree for that function.
10807 FALSE is returned if processing for the _N variation is required, and
10808 NEW_RETURN is set to the the return value the result is copied into. */
10811 resolve_overloaded_atomic_store (location_t loc
, tree function
,
10812 vec
<tree
, va_gc
> *params
, tree
*new_return
)
10815 tree I_type
, I_type_ptr
;
10816 int n
= get_atomic_generic_size (loc
, function
, params
);
10818 /* Size of 0 is an error condition. */
10821 *new_return
= error_mark_node
;
10825 /* If not a lock-free size, change to the library generic format. */
10826 if (!atomic_size_supported_p (n
))
10828 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10832 /* Otherwise, there is a match, so the call needs to be transformed from:
10833 void fn(T* mem, T* value, model)
10835 fn ((In *) mem, (In) *value, model) */
10840 /* Create pointer to appropriate size. */
10841 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10842 I_type_ptr
= build_pointer_type (I_type
);
10844 /* Convert object pointer to required type. */
10845 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10848 /* Convert new value to required type, and dereference it. */
10849 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
10850 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
10853 /* The memory model is in the right spot already. Return is void. */
10854 *new_return
= NULL_TREE
;
10860 /* Some builtin functions are placeholders for other expressions. This
10861 function should be called immediately after parsing the call expression
10862 before surrounding code has committed to the type of the expression.
10864 LOC is the location of the builtin call.
10866 FUNCTION is the DECL that has been invoked; it is known to be a builtin.
10867 PARAMS is the argument list for the call. The return value is non-null
10868 when expansion is complete, and null if normal processing should
10872 resolve_overloaded_builtin (location_t loc
, tree function
,
10873 vec
<tree
, va_gc
> *params
)
10875 enum built_in_function orig_code
= DECL_FUNCTION_CODE (function
);
10876 bool orig_format
= true;
10877 tree new_return
= NULL_TREE
;
10879 switch (DECL_BUILT_IN_CLASS (function
))
10881 case BUILT_IN_NORMAL
:
10884 if (targetm
.resolve_overloaded_builtin
)
10885 return targetm
.resolve_overloaded_builtin (loc
, function
, params
);
10892 /* Handle BUILT_IN_NORMAL here. */
10895 case BUILT_IN_ATOMIC_EXCHANGE
:
10896 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10897 case BUILT_IN_ATOMIC_LOAD
:
10898 case BUILT_IN_ATOMIC_STORE
:
10900 /* Handle these 4 together so that they can fall through to the next
10901 case if the call is transformed to an _N variant. */
10904 case BUILT_IN_ATOMIC_EXCHANGE
:
10906 if (resolve_overloaded_atomic_exchange (loc
, function
, params
,
10909 /* Change to the _N variant. */
10910 orig_code
= BUILT_IN_ATOMIC_EXCHANGE_N
;
10914 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10916 if (resolve_overloaded_atomic_compare_exchange (loc
, function
,
10920 /* Change to the _N variant. */
10921 orig_code
= BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
;
10924 case BUILT_IN_ATOMIC_LOAD
:
10926 if (resolve_overloaded_atomic_load (loc
, function
, params
,
10929 /* Change to the _N variant. */
10930 orig_code
= BUILT_IN_ATOMIC_LOAD_N
;
10933 case BUILT_IN_ATOMIC_STORE
:
10935 if (resolve_overloaded_atomic_store (loc
, function
, params
,
10938 /* Change to the _N variant. */
10939 orig_code
= BUILT_IN_ATOMIC_STORE_N
;
10943 gcc_unreachable ();
10945 /* Fallthrough to the normal processing. */
10947 case BUILT_IN_ATOMIC_EXCHANGE_N
:
10948 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
:
10949 case BUILT_IN_ATOMIC_LOAD_N
:
10950 case BUILT_IN_ATOMIC_STORE_N
:
10951 case BUILT_IN_ATOMIC_ADD_FETCH_N
:
10952 case BUILT_IN_ATOMIC_SUB_FETCH_N
:
10953 case BUILT_IN_ATOMIC_AND_FETCH_N
:
10954 case BUILT_IN_ATOMIC_NAND_FETCH_N
:
10955 case BUILT_IN_ATOMIC_XOR_FETCH_N
:
10956 case BUILT_IN_ATOMIC_OR_FETCH_N
:
10957 case BUILT_IN_ATOMIC_FETCH_ADD_N
:
10958 case BUILT_IN_ATOMIC_FETCH_SUB_N
:
10959 case BUILT_IN_ATOMIC_FETCH_AND_N
:
10960 case BUILT_IN_ATOMIC_FETCH_NAND_N
:
10961 case BUILT_IN_ATOMIC_FETCH_XOR_N
:
10962 case BUILT_IN_ATOMIC_FETCH_OR_N
:
10964 orig_format
= false;
10965 /* Fallthru for parameter processing. */
10967 case BUILT_IN_SYNC_FETCH_AND_ADD_N
:
10968 case BUILT_IN_SYNC_FETCH_AND_SUB_N
:
10969 case BUILT_IN_SYNC_FETCH_AND_OR_N
:
10970 case BUILT_IN_SYNC_FETCH_AND_AND_N
:
10971 case BUILT_IN_SYNC_FETCH_AND_XOR_N
:
10972 case BUILT_IN_SYNC_FETCH_AND_NAND_N
:
10973 case BUILT_IN_SYNC_ADD_AND_FETCH_N
:
10974 case BUILT_IN_SYNC_SUB_AND_FETCH_N
:
10975 case BUILT_IN_SYNC_OR_AND_FETCH_N
:
10976 case BUILT_IN_SYNC_AND_AND_FETCH_N
:
10977 case BUILT_IN_SYNC_XOR_AND_FETCH_N
:
10978 case BUILT_IN_SYNC_NAND_AND_FETCH_N
:
10979 case BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
:
10980 case BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N
:
10981 case BUILT_IN_SYNC_LOCK_TEST_AND_SET_N
:
10982 case BUILT_IN_SYNC_LOCK_RELEASE_N
:
10984 int n
= sync_resolve_size (function
, params
);
10985 tree new_function
, first_param
, result
;
10986 enum built_in_function fncode
;
10989 return error_mark_node
;
10991 fncode
= (enum built_in_function
)((int)orig_code
+ exact_log2 (n
) + 1);
10992 new_function
= builtin_decl_explicit (fncode
);
10993 if (!sync_resolve_params (loc
, function
, new_function
, params
,
10995 return error_mark_node
;
10997 first_param
= (*params
)[0];
10998 result
= build_function_call_vec (loc
, vNULL
, new_function
, params
,
11000 if (result
== error_mark_node
)
11002 if (orig_code
!= BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
11003 && orig_code
!= BUILT_IN_SYNC_LOCK_RELEASE_N
11004 && orig_code
!= BUILT_IN_ATOMIC_STORE_N
)
11005 result
= sync_resolve_return (first_param
, result
, orig_format
);
11007 /* If new_return is set, assign function to that expr and cast the
11008 result to void since the generic interface returned void. */
11011 /* Cast function result from I{1,2,4,8,16} to the required type. */
11012 result
= build1 (VIEW_CONVERT_EXPR
, TREE_TYPE (new_return
), result
);
11013 result
= build2 (MODIFY_EXPR
, TREE_TYPE (new_return
), new_return
,
11015 TREE_SIDE_EFFECTS (result
) = 1;
11016 protected_set_expr_location (result
, loc
);
11017 result
= convert (void_type_node
, result
);
11027 /* vector_types_compatible_elements_p is used in type checks of vectors
11028 values used as operands of binary operators. Where it returns true, and
11029 the other checks of the caller succeed (being vector types in he first
11030 place, and matching number of elements), we can just treat the types
11031 as essentially the same.
11032 Contrast with vector_targets_convertible_p, which is used for vector
11033 pointer types, and vector_types_convertible_p, which will allow
11034 language-specific matches under the control of flag_lax_vector_conversions,
11035 and might still require a conversion. */
11036 /* True if vector types T1 and T2 can be inputs to the same binary
11037 operator without conversion.
11038 We don't check the overall vector size here because some of our callers
11039 want to give different error messages when the vectors are compatible
11040 except for the element count. */
11043 vector_types_compatible_elements_p (tree t1
, tree t2
)
11045 bool opaque
= TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
);
11046 t1
= TREE_TYPE (t1
);
11047 t2
= TREE_TYPE (t2
);
11049 enum tree_code c1
= TREE_CODE (t1
), c2
= TREE_CODE (t2
);
11051 gcc_assert ((c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
|| c1
== FIXED_POINT_TYPE
)
11052 && (c2
== INTEGER_TYPE
|| c2
== REAL_TYPE
11053 || c2
== FIXED_POINT_TYPE
));
11055 t1
= c_common_signed_type (t1
);
11056 t2
= c_common_signed_type (t2
);
11057 /* Equality works here because c_common_signed_type uses
11058 TYPE_MAIN_VARIANT. */
11061 if (opaque
&& c1
== c2
11062 && (c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
)
11063 && TYPE_PRECISION (t1
) == TYPE_PRECISION (t2
))
11068 /* Check for missing format attributes on function pointers. LTYPE is
11069 the new type or left-hand side type. RTYPE is the old type or
11070 right-hand side type. Returns TRUE if LTYPE is missing the desired
11074 check_missing_format_attribute (tree ltype
, tree rtype
)
11076 tree
const ttr
= TREE_TYPE (rtype
), ttl
= TREE_TYPE (ltype
);
11079 for (ra
= TYPE_ATTRIBUTES (ttr
); ra
; ra
= TREE_CHAIN (ra
))
11080 if (is_attribute_p ("format", TREE_PURPOSE (ra
)))
11085 for (la
= TYPE_ATTRIBUTES (ttl
); la
; la
= TREE_CHAIN (la
))
11086 if (is_attribute_p ("format", TREE_PURPOSE (la
)))
11094 /* Subscripting with type char is likely to lose on a machine where
11095 chars are signed. So warn on any machine, but optionally. Don't
11096 warn for unsigned char since that type is safe. Don't warn for
11097 signed char because anyone who uses that must have done so
11098 deliberately. Furthermore, we reduce the false positive load by
11099 warning only for non-constant value of type char. */
11102 warn_array_subscript_with_type_char (tree index
)
11104 if (TYPE_MAIN_VARIANT (TREE_TYPE (index
)) == char_type_node
11105 && TREE_CODE (index
) != INTEGER_CST
)
11106 warning (OPT_Wchar_subscripts
, "array subscript has type %<char%>");
11109 /* Implement -Wparentheses for the unexpected C precedence rules, to
11110 cover cases like x + y << z which readers are likely to
11111 misinterpret. We have seen an expression in which CODE is a binary
11112 operator used to combine expressions ARG_LEFT and ARG_RIGHT, which
11113 before folding had CODE_LEFT and CODE_RIGHT. CODE_LEFT and
11114 CODE_RIGHT may be ERROR_MARK, which means that that side of the
11115 expression was not formed using a binary or unary operator, or it
11116 was enclosed in parentheses. */
11119 warn_about_parentheses (location_t loc
, enum tree_code code
,
11120 enum tree_code code_left
, tree arg_left
,
11121 enum tree_code code_right
, tree arg_right
)
11123 if (!warn_parentheses
)
11126 /* This macro tests that the expression ARG with original tree code
11127 CODE appears to be a boolean expression. or the result of folding a
11128 boolean expression. */
11129 #define APPEARS_TO_BE_BOOLEAN_EXPR_P(CODE, ARG) \
11130 (truth_value_p (TREE_CODE (ARG)) \
11131 || TREE_CODE (TREE_TYPE (ARG)) == BOOLEAN_TYPE \
11132 /* Folding may create 0 or 1 integers from other expressions. */ \
11133 || ((CODE) != INTEGER_CST \
11134 && (integer_onep (ARG) || integer_zerop (ARG))))
11139 if (code_left
== PLUS_EXPR
)
11140 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11141 "suggest parentheses around %<+%> inside %<<<%>");
11142 else if (code_right
== PLUS_EXPR
)
11143 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11144 "suggest parentheses around %<+%> inside %<<<%>");
11145 else if (code_left
== MINUS_EXPR
)
11146 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11147 "suggest parentheses around %<-%> inside %<<<%>");
11148 else if (code_right
== MINUS_EXPR
)
11149 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11150 "suggest parentheses around %<-%> inside %<<<%>");
11154 if (code_left
== PLUS_EXPR
)
11155 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11156 "suggest parentheses around %<+%> inside %<>>%>");
11157 else if (code_right
== PLUS_EXPR
)
11158 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11159 "suggest parentheses around %<+%> inside %<>>%>");
11160 else if (code_left
== MINUS_EXPR
)
11161 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11162 "suggest parentheses around %<-%> inside %<>>%>");
11163 else if (code_right
== MINUS_EXPR
)
11164 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11165 "suggest parentheses around %<-%> inside %<>>%>");
11168 case TRUTH_ORIF_EXPR
:
11169 if (code_left
== TRUTH_ANDIF_EXPR
)
11170 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11171 "suggest parentheses around %<&&%> within %<||%>");
11172 else if (code_right
== TRUTH_ANDIF_EXPR
)
11173 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11174 "suggest parentheses around %<&&%> within %<||%>");
11178 if (code_left
== BIT_AND_EXPR
|| code_left
== BIT_XOR_EXPR
11179 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
)
11180 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11181 "suggest parentheses around arithmetic in operand of %<|%>");
11182 else if (code_right
== BIT_AND_EXPR
|| code_right
== BIT_XOR_EXPR
11183 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
11184 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11185 "suggest parentheses around arithmetic in operand of %<|%>");
11186 /* Check cases like x|y==z */
11187 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11188 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11189 "suggest parentheses around comparison in operand of %<|%>");
11190 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11191 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11192 "suggest parentheses around comparison in operand of %<|%>");
11193 /* Check cases like !x | y */
11194 else if (code_left
== TRUTH_NOT_EXPR
11195 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
11196 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11197 "suggest parentheses around operand of "
11198 "%<!%> or change %<|%> to %<||%> or %<!%> to %<~%>");
11202 if (code_left
== BIT_AND_EXPR
11203 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
)
11204 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11205 "suggest parentheses around arithmetic in operand of %<^%>");
11206 else if (code_right
== BIT_AND_EXPR
11207 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
11208 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11209 "suggest parentheses around arithmetic in operand of %<^%>");
11210 /* Check cases like x^y==z */
11211 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11212 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11213 "suggest parentheses around comparison in operand of %<^%>");
11214 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11215 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11216 "suggest parentheses around comparison in operand of %<^%>");
11220 if (code_left
== PLUS_EXPR
)
11221 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11222 "suggest parentheses around %<+%> in operand of %<&%>");
11223 else if (code_right
== PLUS_EXPR
)
11224 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11225 "suggest parentheses around %<+%> in operand of %<&%>");
11226 else if (code_left
== MINUS_EXPR
)
11227 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11228 "suggest parentheses around %<-%> in operand of %<&%>");
11229 else if (code_right
== MINUS_EXPR
)
11230 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11231 "suggest parentheses around %<-%> in operand of %<&%>");
11232 /* Check cases like x&y==z */
11233 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11234 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11235 "suggest parentheses around comparison in operand of %<&%>");
11236 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11237 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11238 "suggest parentheses around comparison in operand of %<&%>");
11239 /* Check cases like !x & y */
11240 else if (code_left
== TRUTH_NOT_EXPR
11241 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
11242 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11243 "suggest parentheses around operand of "
11244 "%<!%> or change %<&%> to %<&&%> or %<!%> to %<~%>");
11248 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11249 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11250 "suggest parentheses around comparison in operand of %<==%>");
11251 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11252 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11253 "suggest parentheses around comparison in operand of %<==%>");
11256 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11257 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11258 "suggest parentheses around comparison in operand of %<!=%>");
11259 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11260 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11261 "suggest parentheses around comparison in operand of %<!=%>");
11265 if (TREE_CODE_CLASS (code
) == tcc_comparison
)
11267 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
11268 && code_left
!= NE_EXPR
&& code_left
!= EQ_EXPR
11269 && INTEGRAL_TYPE_P (TREE_TYPE (arg_left
)))
11270 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11271 "comparisons like %<X<=Y<=Z%> do not "
11272 "have their mathematical meaning");
11273 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
11274 && code_right
!= NE_EXPR
&& code_right
!= EQ_EXPR
11275 && INTEGRAL_TYPE_P (TREE_TYPE (arg_right
)))
11276 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11277 "comparisons like %<X<=Y<=Z%> do not "
11278 "have their mathematical meaning");
11282 #undef NOT_A_BOOLEAN_EXPR_P
11285 /* If LABEL (a LABEL_DECL) has not been used, issue a warning. */
11288 warn_for_unused_label (tree label
)
11290 if (!TREE_USED (label
))
11292 if (DECL_INITIAL (label
))
11293 warning (OPT_Wunused_label
, "label %q+D defined but not used", label
);
11295 warning (OPT_Wunused_label
, "label %q+D declared but not defined", label
);
11299 /* Warn for division by zero according to the value of DIVISOR. LOC
11300 is the location of the division operator. */
11303 warn_for_div_by_zero (location_t loc
, tree divisor
)
11305 /* If DIVISOR is zero, and has integral or fixed-point type, issue a warning
11306 about division by zero. Do not issue a warning if DIVISOR has a
11307 floating-point type, since we consider 0.0/0.0 a valid way of
11308 generating a NaN. */
11309 if (c_inhibit_evaluation_warnings
== 0
11310 && (integer_zerop (divisor
) || fixed_zerop (divisor
)))
11311 warning_at (loc
, OPT_Wdiv_by_zero
, "division by zero");
11314 /* Subroutine of build_binary_op. Give warnings for comparisons
11315 between signed and unsigned quantities that may fail. Do the
11316 checking based on the original operand trees ORIG_OP0 and ORIG_OP1,
11317 so that casts will be considered, but default promotions won't
11320 LOCATION is the location of the comparison operator.
11322 The arguments of this function map directly to local variables
11323 of build_binary_op. */
11326 warn_for_sign_compare (location_t location
,
11327 tree orig_op0
, tree orig_op1
,
11328 tree op0
, tree op1
,
11329 tree result_type
, enum tree_code resultcode
)
11331 int op0_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op0
));
11332 int op1_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op1
));
11333 int unsignedp0
, unsignedp1
;
11335 /* In C++, check for comparison of different enum types. */
11336 if (c_dialect_cxx()
11337 && TREE_CODE (TREE_TYPE (orig_op0
)) == ENUMERAL_TYPE
11338 && TREE_CODE (TREE_TYPE (orig_op1
)) == ENUMERAL_TYPE
11339 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0
))
11340 != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1
)))
11342 warning_at (location
,
11343 OPT_Wsign_compare
, "comparison between types %qT and %qT",
11344 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
));
11347 /* Do not warn if the comparison is being done in a signed type,
11348 since the signed type will only be chosen if it can represent
11349 all the values of the unsigned type. */
11350 if (!TYPE_UNSIGNED (result_type
))
11352 /* Do not warn if both operands are unsigned. */
11353 else if (op0_signed
== op1_signed
)
11357 tree sop
, uop
, base_type
;
11361 sop
= orig_op0
, uop
= orig_op1
;
11363 sop
= orig_op1
, uop
= orig_op0
;
11365 STRIP_TYPE_NOPS (sop
);
11366 STRIP_TYPE_NOPS (uop
);
11367 base_type
= (TREE_CODE (result_type
) == COMPLEX_TYPE
11368 ? TREE_TYPE (result_type
) : result_type
);
11370 /* Do not warn if the signed quantity is an unsuffixed integer
11371 literal (or some static constant expression involving such
11372 literals or a conditional expression involving such literals)
11373 and it is non-negative. */
11374 if (tree_expr_nonnegative_warnv_p (sop
, &ovf
))
11376 /* Do not warn if the comparison is an equality operation, the
11377 unsigned quantity is an integral constant, and it would fit
11378 in the result if the result were signed. */
11379 else if (TREE_CODE (uop
) == INTEGER_CST
11380 && (resultcode
== EQ_EXPR
|| resultcode
== NE_EXPR
)
11381 && int_fits_type_p (uop
, c_common_signed_type (base_type
)))
11383 /* In C, do not warn if the unsigned quantity is an enumeration
11384 constant and its maximum value would fit in the result if the
11385 result were signed. */
11386 else if (!c_dialect_cxx() && TREE_CODE (uop
) == INTEGER_CST
11387 && TREE_CODE (TREE_TYPE (uop
)) == ENUMERAL_TYPE
11388 && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (uop
)),
11389 c_common_signed_type (base_type
)))
11392 warning_at (location
,
11394 "comparison between signed and unsigned integer expressions");
11397 /* Warn if two unsigned values are being compared in a size larger
11398 than their original size, and one (and only one) is the result of
11399 a `~' operator. This comparison will always fail.
11401 Also warn if one operand is a constant, and the constant does not
11402 have all bits set that are set in the ~ operand when it is
11405 op0
= c_common_get_narrower (op0
, &unsignedp0
);
11406 op1
= c_common_get_narrower (op1
, &unsignedp1
);
11408 if ((TREE_CODE (op0
) == BIT_NOT_EXPR
)
11409 ^ (TREE_CODE (op1
) == BIT_NOT_EXPR
))
11411 if (TREE_CODE (op0
) == BIT_NOT_EXPR
)
11412 op0
= c_common_get_narrower (TREE_OPERAND (op0
, 0), &unsignedp0
);
11413 if (TREE_CODE (op1
) == BIT_NOT_EXPR
)
11414 op1
= c_common_get_narrower (TREE_OPERAND (op1
, 0), &unsignedp1
);
11416 if (tree_fits_shwi_p (op0
) || tree_fits_shwi_p (op1
))
11419 HOST_WIDE_INT constant
, mask
;
11423 if (tree_fits_shwi_p (op0
))
11426 unsignedp
= unsignedp1
;
11427 constant
= tree_to_shwi (op0
);
11432 unsignedp
= unsignedp0
;
11433 constant
= tree_to_shwi (op1
);
11436 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
11437 if (bits
< TYPE_PRECISION (result_type
)
11438 && bits
< HOST_BITS_PER_LONG
&& unsignedp
)
11440 mask
= (~ (HOST_WIDE_INT
) 0) << bits
;
11441 if ((mask
& constant
) != mask
)
11444 warning_at (location
, OPT_Wsign_compare
,
11445 "promoted ~unsigned is always non-zero");
11447 warning_at (location
, OPT_Wsign_compare
,
11448 "comparison of promoted ~unsigned with constant");
11452 else if (unsignedp0
&& unsignedp1
11453 && (TYPE_PRECISION (TREE_TYPE (op0
))
11454 < TYPE_PRECISION (result_type
))
11455 && (TYPE_PRECISION (TREE_TYPE (op1
))
11456 < TYPE_PRECISION (result_type
)))
11457 warning_at (location
, OPT_Wsign_compare
,
11458 "comparison of promoted ~unsigned with unsigned");
11462 /* RESULT_TYPE is the result of converting TYPE1 and TYPE2 to a common
11463 type via c_common_type. If -Wdouble-promotion is in use, and the
11464 conditions for warning have been met, issue a warning. GMSGID is
11465 the warning message. It must have two %T specifiers for the type
11466 that was converted (generally "float") and the type to which it was
11467 converted (generally "double), respectively. LOC is the location
11468 to which the awrning should refer. */
11471 do_warn_double_promotion (tree result_type
, tree type1
, tree type2
,
11472 const char *gmsgid
, location_t loc
)
11476 if (!warn_double_promotion
)
11478 /* If the conversion will not occur at run-time, there is no need to
11480 if (c_inhibit_evaluation_warnings
)
11482 if (TYPE_MAIN_VARIANT (result_type
) != double_type_node
11483 && TYPE_MAIN_VARIANT (result_type
) != complex_double_type_node
)
11485 if (TYPE_MAIN_VARIANT (type1
) == float_type_node
11486 || TYPE_MAIN_VARIANT (type1
) == complex_float_type_node
)
11487 source_type
= type1
;
11488 else if (TYPE_MAIN_VARIANT (type2
) == float_type_node
11489 || TYPE_MAIN_VARIANT (type2
) == complex_float_type_node
)
11490 source_type
= type2
;
11493 warning_at (loc
, OPT_Wdouble_promotion
, gmsgid
, source_type
, result_type
);
11496 /* Setup a TYPE_DECL node as a typedef representation.
11498 X is a TYPE_DECL for a typedef statement. Create a brand new
11499 ..._TYPE node (which will be just a variant of the existing
11500 ..._TYPE node with identical properties) and then install X
11501 as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
11503 The whole point here is to end up with a situation where each
11504 and every ..._TYPE node the compiler creates will be uniquely
11505 associated with AT MOST one node representing a typedef name.
11506 This way, even though the compiler substitutes corresponding
11507 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
11508 early on, later parts of the compiler can always do the reverse
11509 translation and get back the corresponding typedef name. For
11512 typedef struct S MY_TYPE;
11515 Later parts of the compiler might only know that `object' was of
11516 type `struct S' if it were not for code just below. With this
11517 code however, later parts of the compiler see something like:
11519 struct S' == struct S
11520 typedef struct S' MY_TYPE;
11523 And they can then deduce (from the node for type struct S') that
11524 the original object declaration was:
11528 Being able to do this is important for proper support of protoize,
11529 and also for generating precise symbolic debugging information
11530 which takes full account of the programmer's (typedef) vocabulary.
11532 Obviously, we don't want to generate a duplicate ..._TYPE node if
11533 the TYPE_DECL node that we are now processing really represents a
11534 standard built-in type. */
11537 set_underlying_type (tree x
)
11539 if (x
== error_mark_node
)
11541 if (DECL_IS_BUILTIN (x
))
11543 if (TYPE_NAME (TREE_TYPE (x
)) == 0)
11544 TYPE_NAME (TREE_TYPE (x
)) = x
;
11546 else if (TREE_TYPE (x
) != error_mark_node
11547 && DECL_ORIGINAL_TYPE (x
) == NULL_TREE
)
11549 tree tt
= TREE_TYPE (x
);
11550 DECL_ORIGINAL_TYPE (x
) = tt
;
11551 tt
= build_variant_type_copy (tt
);
11552 TYPE_STUB_DECL (tt
) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x
));
11553 TYPE_NAME (tt
) = x
;
11554 TREE_USED (tt
) = TREE_USED (x
);
11555 TREE_TYPE (x
) = tt
;
11559 /* Record the types used by the current global variable declaration
11560 being parsed, so that we can decide later to emit their debug info.
11561 Those types are in types_used_by_cur_var_decl, and we are going to
11562 store them in the types_used_by_vars_hash hash table.
11563 DECL is the declaration of the global variable that has been parsed. */
11566 record_types_used_by_current_var_decl (tree decl
)
11568 gcc_assert (decl
&& DECL_P (decl
) && TREE_STATIC (decl
));
11570 while (types_used_by_cur_var_decl
&& !types_used_by_cur_var_decl
->is_empty ())
11572 tree type
= types_used_by_cur_var_decl
->pop ();
11573 types_used_by_var_decl_insert (type
, decl
);
11577 /* If DECL is a typedef that is declared in the current function,
11578 record it for the purpose of -Wunused-local-typedefs. */
11581 record_locally_defined_typedef (tree decl
)
11583 struct c_language_function
*l
;
11585 if (!warn_unused_local_typedefs
11587 /* if this is not a locally defined typedef then we are not
11589 || !is_typedef_decl (decl
)
11590 || !decl_function_context (decl
))
11593 l
= (struct c_language_function
*) cfun
->language
;
11594 vec_safe_push (l
->local_typedefs
, decl
);
11597 /* If T is a TYPE_DECL declared locally, mark it as used. */
11600 maybe_record_typedef_use (tree t
)
11602 if (!is_typedef_decl (t
))
11605 TREE_USED (t
) = true;
11608 /* Warn if there are some unused locally defined typedefs in the
11609 current function. */
11612 maybe_warn_unused_local_typedefs (void)
11616 /* The number of times we have emitted -Wunused-local-typedefs
11617 warnings. If this is different from errorcount, that means some
11618 unrelated errors have been issued. In which case, we'll avoid
11619 emitting "unused-local-typedefs" warnings. */
11620 static int unused_local_typedefs_warn_count
;
11621 struct c_language_function
*l
;
11626 if ((l
= (struct c_language_function
*) cfun
->language
) == NULL
)
11629 if (warn_unused_local_typedefs
11630 && errorcount
== unused_local_typedefs_warn_count
)
11632 FOR_EACH_VEC_SAFE_ELT (l
->local_typedefs
, i
, decl
)
11633 if (!TREE_USED (decl
))
11634 warning_at (DECL_SOURCE_LOCATION (decl
),
11635 OPT_Wunused_local_typedefs
,
11636 "typedef %qD locally defined but not used", decl
);
11637 unused_local_typedefs_warn_count
= errorcount
;
11640 vec_free (l
->local_typedefs
);
11643 /* Warn about boolean expression compared with an integer value different
11644 from true/false. Warns also e.g. about "(i1 == i2) == 2".
11645 LOC is the location of the comparison, CODE is its code, OP0 and OP1
11646 are the operands of the comparison. The caller must ensure that
11647 either operand is a boolean expression. */
11650 maybe_warn_bool_compare (location_t loc
, enum tree_code code
, tree op0
,
11653 if (TREE_CODE_CLASS (code
) != tcc_comparison
)
11656 tree cst
= (TREE_CODE (op0
) == INTEGER_CST
)
11657 ? op0
: (TREE_CODE (op1
) == INTEGER_CST
) ? op1
: NULL_TREE
;
11661 if (!integer_zerop (cst
) && !integer_onep (cst
))
11663 int sign
= (TREE_CODE (op0
) == INTEGER_CST
)
11664 ? tree_int_cst_sgn (cst
) : -tree_int_cst_sgn (cst
);
11665 if (code
== EQ_EXPR
11666 || ((code
== GT_EXPR
|| code
== GE_EXPR
) && sign
< 0)
11667 || ((code
== LT_EXPR
|| code
== LE_EXPR
) && sign
> 0))
11668 warning_at (loc
, OPT_Wbool_compare
, "comparison of constant %qE "
11669 "with boolean expression is always false", cst
);
11671 warning_at (loc
, OPT_Wbool_compare
, "comparison of constant %qE "
11672 "with boolean expression is always true", cst
);
11676 /* The C and C++ parsers both use vectors to hold function arguments.
11677 For efficiency, we keep a cache of unused vectors. This is the
11680 typedef vec
<tree
, va_gc
> *tree_gc_vec
;
11681 static GTY((deletable
)) vec
<tree_gc_vec
, va_gc
> *tree_vector_cache
;
11683 /* Return a new vector from the cache. If the cache is empty,
11684 allocate a new vector. These vectors are GC'ed, so it is OK if the
11685 pointer is not released.. */
11688 make_tree_vector (void)
11690 if (tree_vector_cache
&& !tree_vector_cache
->is_empty ())
11691 return tree_vector_cache
->pop ();
11694 /* Passing 0 to vec::alloc returns NULL, and our callers require
11695 that we always return a non-NULL value. The vector code uses
11696 4 when growing a NULL vector, so we do too. */
11697 vec
<tree
, va_gc
> *v
;
11703 /* Release a vector of trees back to the cache. */
11706 release_tree_vector (vec
<tree
, va_gc
> *vec
)
11711 vec_safe_push (tree_vector_cache
, vec
);
11715 /* Get a new tree vector holding a single tree. */
11718 make_tree_vector_single (tree t
)
11720 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
11721 ret
->quick_push (t
);
11725 /* Get a new tree vector of the TREE_VALUEs of a TREE_LIST chain. */
11728 make_tree_vector_from_list (tree list
)
11730 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
11731 for (; list
; list
= TREE_CHAIN (list
))
11732 vec_safe_push (ret
, TREE_VALUE (list
));
11736 /* Get a new tree vector which is a copy of an existing one. */
11739 make_tree_vector_copy (const vec
<tree
, va_gc
> *orig
)
11741 vec
<tree
, va_gc
> *ret
;
11745 ret
= make_tree_vector ();
11746 vec_safe_reserve (ret
, vec_safe_length (orig
));
11747 FOR_EACH_VEC_SAFE_ELT (orig
, ix
, t
)
11748 ret
->quick_push (t
);
11752 /* Return true if KEYWORD starts a type specifier. */
11755 keyword_begins_type_specifier (enum rid keyword
)
11759 case RID_AUTO_TYPE
:
11772 case RID_DFLOAT128
:
11792 /* Return true if KEYWORD names a type qualifier. */
11795 keyword_is_type_qualifier (enum rid keyword
)
11809 /* Return true if KEYWORD names a storage class specifier.
11811 RID_TYPEDEF is not included in this list despite `typedef' being
11812 listed in C99 6.7.1.1. 6.7.1.3 indicates that `typedef' is listed as
11813 such for syntactic convenience only. */
11816 keyword_is_storage_class_specifier (enum rid keyword
)
11832 /* Return true if KEYWORD names a function-specifier [dcl.fct.spec]. */
11835 keyword_is_function_specifier (enum rid keyword
)
11849 /* Return true if KEYWORD names a decl-specifier [dcl.spec] or a
11850 declaration-specifier (C99 6.7). */
11853 keyword_is_decl_specifier (enum rid keyword
)
11855 if (keyword_is_storage_class_specifier (keyword
)
11856 || keyword_is_type_qualifier (keyword
)
11857 || keyword_is_function_specifier (keyword
))
11864 case RID_CONSTEXPR
:
11871 /* Initialize language-specific-bits of tree_contains_struct. */
11874 c_common_init_ts (void)
11876 MARK_TS_TYPED (C_MAYBE_CONST_EXPR
);
11877 MARK_TS_TYPED (EXCESS_PRECISION_EXPR
);
11878 MARK_TS_TYPED (ARRAY_NOTATION_REF
);
11881 /* Build a user-defined numeric literal out of an integer constant type VALUE
11882 with identifier SUFFIX. */
11885 build_userdef_literal (tree suffix_id
, tree value
,
11886 enum overflow_type overflow
, tree num_string
)
11888 tree literal
= make_node (USERDEF_LITERAL
);
11889 USERDEF_LITERAL_SUFFIX_ID (literal
) = suffix_id
;
11890 USERDEF_LITERAL_VALUE (literal
) = value
;
11891 USERDEF_LITERAL_OVERFLOW (literal
) = overflow
;
11892 USERDEF_LITERAL_NUM_STRING (literal
) = num_string
;
11896 /* For vector[index], convert the vector to a
11897 pointer of the underlying type. */
11899 convert_vector_to_pointer_for_subscript (location_t loc
,
11900 tree
* vecp
, tree index
)
11902 if (TREE_CODE (TREE_TYPE (*vecp
)) == VECTOR_TYPE
)
11904 tree type
= TREE_TYPE (*vecp
);
11907 if (TREE_CODE (index
) == INTEGER_CST
)
11908 if (!tree_fits_uhwi_p (index
)
11909 || tree_to_uhwi (index
) >= TYPE_VECTOR_SUBPARTS (type
))
11910 warning_at (loc
, OPT_Warray_bounds
, "index value is out of bound");
11912 c_common_mark_addressable_vec (*vecp
);
11913 type
= build_qualified_type (TREE_TYPE (type
), TYPE_QUALS (type
));
11914 type1
= build_pointer_type (TREE_TYPE (*vecp
));
11915 bool ref_all
= TYPE_REF_CAN_ALIAS_ALL (type1
);
11917 && !DECL_P (*vecp
))
11919 /* If the original vector isn't declared may_alias and it
11920 isn't a bare vector look if the subscripting would
11921 alias the vector we subscript, and if not, force ref-all. */
11922 alias_set_type vecset
= get_alias_set (*vecp
);
11923 alias_set_type sset
= get_alias_set (type
);
11924 if (!alias_sets_must_conflict_p (sset
, vecset
)
11925 && !alias_set_subset_of (sset
, vecset
))
11928 type
= build_pointer_type_for_mode (type
, ptr_mode
, ref_all
);
11929 *vecp
= build1 (ADDR_EXPR
, type1
, *vecp
);
11930 *vecp
= convert (type
, *vecp
);
11934 /* Determine which of the operands, if any, is a scalar that needs to be
11935 converted to a vector, for the range of operations. */
11937 scalar_to_vector (location_t loc
, enum tree_code code
, tree op0
, tree op1
,
11940 tree type0
= TREE_TYPE (op0
);
11941 tree type1
= TREE_TYPE (op1
);
11942 bool integer_only_op
= false;
11943 enum stv_conv ret
= stv_firstarg
;
11945 gcc_assert (TREE_CODE (type0
) == VECTOR_TYPE
11946 || TREE_CODE (type1
) == VECTOR_TYPE
);
11949 /* Most GENERIC binary expressions require homogeneous arguments.
11950 LSHIFT_EXPR and RSHIFT_EXPR are exceptions and accept a first
11951 argument that is a vector and a second one that is a scalar, so
11952 we never return stv_secondarg for them. */
11955 if (TREE_CODE (type0
) == INTEGER_TYPE
11956 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
11958 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
11961 error_at (loc
, "conversion of scalar %qT to vector %qT "
11962 "involves truncation", type0
, type1
);
11966 return stv_firstarg
;
11973 integer_only_op
= true;
11974 /* ... fall through ... */
11976 case VEC_COND_EXPR
:
11981 case TRUNC_DIV_EXPR
:
11982 case CEIL_DIV_EXPR
:
11983 case FLOOR_DIV_EXPR
:
11984 case ROUND_DIV_EXPR
:
11985 case EXACT_DIV_EXPR
:
11986 case TRUNC_MOD_EXPR
:
11987 case FLOOR_MOD_EXPR
:
11995 /* What about UNLT_EXPR? */
11996 if (TREE_CODE (type0
) == VECTOR_TYPE
)
11999 ret
= stv_secondarg
;
12000 /* Swap TYPE0 with TYPE1 and OP0 with OP1 */
12001 tmp
= type0
; type0
= type1
; type1
= tmp
;
12002 tmp
= op0
; op0
= op1
; op1
= tmp
;
12005 if (TREE_CODE (type0
) == INTEGER_TYPE
12006 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
12008 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
12011 error_at (loc
, "conversion of scalar %qT to vector %qT "
12012 "involves truncation", type0
, type1
);
12017 else if (!integer_only_op
12018 /* Allow integer --> real conversion if safe. */
12019 && (TREE_CODE (type0
) == REAL_TYPE
12020 || TREE_CODE (type0
) == INTEGER_TYPE
)
12021 && SCALAR_FLOAT_TYPE_P (TREE_TYPE (type1
)))
12023 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
12026 error_at (loc
, "conversion of scalar %qT to vector %qT "
12027 "involves truncation", type0
, type1
);
12036 return stv_nothing
;
12039 /* Return true iff ALIGN is an integral constant that is a fundamental
12040 alignment, as defined by [basic.align] in the c++-11
12045 [A fundamental alignment is represented by an alignment less than or
12046 equal to the greatest alignment supported by the implementation
12047 in all contexts, which is equal to
12048 alignof(max_align_t)]. */
12051 cxx_fundamental_alignment_p (unsigned align
)
12053 return (align
<= MAX (TYPE_ALIGN (long_long_integer_type_node
),
12054 TYPE_ALIGN (long_double_type_node
)));
12057 /* Return true if T is a pointer to a zero-sized aggregate. */
12060 pointer_to_zero_sized_aggr_p (tree t
)
12062 if (!POINTER_TYPE_P (t
))
12065 return (TYPE_SIZE (t
) && integer_zerop (TYPE_SIZE (t
)));
12068 #include "gt-c-family-c-common.h"