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"
26 #include "fold-const.h"
27 #include "stor-layout.h"
29 #include "stringpool.h"
32 #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++11 is the default. */
245 enum cxx_dialect cxx_dialect
= cxx11
;
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 (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_const_attribute (tree
*, tree
, tree
, int, bool *);
332 static tree
handle_transparent_union_attribute (tree
*, tree
, tree
,
334 static tree
handle_constructor_attribute (tree
*, tree
, tree
, int, bool *);
335 static tree
handle_destructor_attribute (tree
*, tree
, tree
, int, bool *);
336 static tree
handle_mode_attribute (tree
*, tree
, tree
, int, bool *);
337 static tree
handle_section_attribute (tree
*, tree
, tree
, int, bool *);
338 static tree
handle_aligned_attribute (tree
*, tree
, tree
, int, bool *);
339 static tree
handle_weak_attribute (tree
*, tree
, tree
, int, bool *) ;
340 static tree
handle_alias_ifunc_attribute (bool, tree
*, tree
, tree
, bool *);
341 static tree
handle_ifunc_attribute (tree
*, tree
, tree
, int, bool *);
342 static tree
handle_alias_attribute (tree
*, tree
, tree
, int, bool *);
343 static tree
handle_weakref_attribute (tree
*, tree
, tree
, int, bool *) ;
344 static tree
handle_visibility_attribute (tree
*, tree
, tree
, int,
346 static tree
handle_tls_model_attribute (tree
*, tree
, tree
, int,
348 static tree
handle_no_instrument_function_attribute (tree
*, tree
,
350 static tree
handle_malloc_attribute (tree
*, tree
, tree
, int, bool *);
351 static tree
handle_returns_twice_attribute (tree
*, tree
, tree
, int, bool *);
352 static tree
handle_no_limit_stack_attribute (tree
*, tree
, tree
, int,
354 static tree
handle_pure_attribute (tree
*, tree
, tree
, int, bool *);
355 static tree
handle_tm_attribute (tree
*, tree
, tree
, int, bool *);
356 static tree
handle_tm_wrap_attribute (tree
*, tree
, tree
, int, bool *);
357 static tree
handle_novops_attribute (tree
*, tree
, tree
, int, bool *);
358 static tree
handle_deprecated_attribute (tree
*, tree
, tree
, int,
360 static tree
handle_vector_size_attribute (tree
*, tree
, tree
, int,
362 static tree
handle_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
363 static tree
handle_nothrow_attribute (tree
*, tree
, tree
, int, bool *);
364 static tree
handle_cleanup_attribute (tree
*, tree
, tree
, int, bool *);
365 static tree
handle_warn_unused_result_attribute (tree
*, tree
, tree
, int,
367 static tree
handle_sentinel_attribute (tree
*, tree
, tree
, int, bool *);
368 static tree
handle_type_generic_attribute (tree
*, tree
, tree
, int, bool *);
369 static tree
handle_alloc_size_attribute (tree
*, tree
, tree
, int, bool *);
370 static tree
handle_alloc_align_attribute (tree
*, tree
, tree
, int, bool *);
371 static tree
handle_assume_aligned_attribute (tree
*, tree
, tree
, int, bool *);
372 static tree
handle_target_attribute (tree
*, tree
, tree
, int, bool *);
373 static tree
handle_optimize_attribute (tree
*, tree
, tree
, int, bool *);
374 static tree
ignore_attribute (tree
*, tree
, tree
, int, bool *);
375 static tree
handle_no_split_stack_attribute (tree
*, tree
, tree
, int, bool *);
376 static tree
handle_fnspec_attribute (tree
*, tree
, tree
, int, bool *);
377 static tree
handle_warn_unused_attribute (tree
*, tree
, tree
, int, bool *);
378 static tree
handle_returns_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
379 static tree
handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int,
381 static tree
handle_omp_declare_target_attribute (tree
*, tree
, tree
, int,
384 static void check_function_nonnull (tree
, int, tree
*);
385 static void check_nonnull_arg (void *, tree
, unsigned HOST_WIDE_INT
);
386 static bool nonnull_check_p (tree
, unsigned HOST_WIDE_INT
);
387 static bool get_nonnull_operand (tree
, unsigned HOST_WIDE_INT
*);
388 static int resort_field_decl_cmp (const void *, const void *);
390 /* Reserved words. The third field is a mask: keywords are disabled
391 if they match the mask.
394 C --std=c89: D_C99 | D_CXXONLY | D_OBJC | D_CXX_OBJC
395 C --std=c99: D_CXXONLY | D_OBJC
396 ObjC is like C except that D_OBJC and D_CXX_OBJC are not set
397 C++ --std=c98: D_CONLY | D_CXXOX | D_OBJC
398 C++ --std=c0x: D_CONLY | D_OBJC
399 ObjC++ is like C++ except that D_OBJC is not set
401 If -fno-asm is used, D_ASM is added to the mask. If
402 -fno-gnu-keywords is used, D_EXT is added. If -fno-asm and C in
403 C89 mode, D_EXT89 is added for both -fno-asm and -fno-gnu-keywords.
404 In C with -Wc++-compat, we warn if D_CXXWARN is set.
406 Note the complication of the D_CXX_OBJC keywords. These are
407 reserved words such as 'class'. In C++, 'class' is a reserved
408 word. In Objective-C++ it is too. In Objective-C, it is a
409 reserved word too, but only if it follows an '@' sign.
411 const struct c_common_resword c_common_reswords
[] =
413 { "_Alignas", RID_ALIGNAS
, D_CONLY
},
414 { "_Alignof", RID_ALIGNOF
, D_CONLY
},
415 { "_Atomic", RID_ATOMIC
, D_CONLY
},
416 { "_Bool", RID_BOOL
, D_CONLY
},
417 { "_Complex", RID_COMPLEX
, 0 },
418 { "_Cilk_spawn", RID_CILK_SPAWN
, 0 },
419 { "_Cilk_sync", RID_CILK_SYNC
, 0 },
420 { "_Imaginary", RID_IMAGINARY
, D_CONLY
},
421 { "_Decimal32", RID_DFLOAT32
, D_CONLY
| D_EXT
},
422 { "_Decimal64", RID_DFLOAT64
, D_CONLY
| D_EXT
},
423 { "_Decimal128", RID_DFLOAT128
, D_CONLY
| D_EXT
},
424 { "_Fract", RID_FRACT
, D_CONLY
| D_EXT
},
425 { "_Accum", RID_ACCUM
, D_CONLY
| D_EXT
},
426 { "_Sat", RID_SAT
, D_CONLY
| D_EXT
},
427 { "_Static_assert", RID_STATIC_ASSERT
, D_CONLY
},
428 { "_Noreturn", RID_NORETURN
, D_CONLY
},
429 { "_Generic", RID_GENERIC
, D_CONLY
},
430 { "_Thread_local", RID_THREAD
, D_CONLY
},
431 { "__FUNCTION__", RID_FUNCTION_NAME
, 0 },
432 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME
, 0 },
433 { "__alignof", RID_ALIGNOF
, 0 },
434 { "__alignof__", RID_ALIGNOF
, 0 },
435 { "__asm", RID_ASM
, 0 },
436 { "__asm__", RID_ASM
, 0 },
437 { "__attribute", RID_ATTRIBUTE
, 0 },
438 { "__attribute__", RID_ATTRIBUTE
, 0 },
439 { "__auto_type", RID_AUTO_TYPE
, D_CONLY
},
440 { "__bases", RID_BASES
, D_CXXONLY
},
441 { "__builtin_choose_expr", RID_CHOOSE_EXPR
, D_CONLY
},
442 { "__builtin_complex", RID_BUILTIN_COMPLEX
, D_CONLY
},
443 { "__builtin_shuffle", RID_BUILTIN_SHUFFLE
, 0 },
444 { "__builtin_offsetof", RID_OFFSETOF
, 0 },
445 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P
, D_CONLY
},
446 { "__builtin_va_arg", RID_VA_ARG
, 0 },
447 { "__complex", RID_COMPLEX
, 0 },
448 { "__complex__", RID_COMPLEX
, 0 },
449 { "__const", RID_CONST
, 0 },
450 { "__const__", RID_CONST
, 0 },
451 { "__decltype", RID_DECLTYPE
, D_CXXONLY
},
452 { "__direct_bases", RID_DIRECT_BASES
, D_CXXONLY
},
453 { "__extension__", RID_EXTENSION
, 0 },
454 { "__func__", RID_C99_FUNCTION_NAME
, 0 },
455 { "__has_nothrow_assign", RID_HAS_NOTHROW_ASSIGN
, D_CXXONLY
},
456 { "__has_nothrow_constructor", RID_HAS_NOTHROW_CONSTRUCTOR
, D_CXXONLY
},
457 { "__has_nothrow_copy", RID_HAS_NOTHROW_COPY
, D_CXXONLY
},
458 { "__has_trivial_assign", RID_HAS_TRIVIAL_ASSIGN
, D_CXXONLY
},
459 { "__has_trivial_constructor", RID_HAS_TRIVIAL_CONSTRUCTOR
, D_CXXONLY
},
460 { "__has_trivial_copy", RID_HAS_TRIVIAL_COPY
, D_CXXONLY
},
461 { "__has_trivial_destructor", RID_HAS_TRIVIAL_DESTRUCTOR
, D_CXXONLY
},
462 { "__has_virtual_destructor", RID_HAS_VIRTUAL_DESTRUCTOR
, D_CXXONLY
},
463 { "__imag", RID_IMAGPART
, 0 },
464 { "__imag__", RID_IMAGPART
, 0 },
465 { "__inline", RID_INLINE
, 0 },
466 { "__inline__", RID_INLINE
, 0 },
467 { "__int128", RID_INT128
, 0 },
468 { "__is_abstract", RID_IS_ABSTRACT
, D_CXXONLY
},
469 { "__is_base_of", RID_IS_BASE_OF
, D_CXXONLY
},
470 { "__is_class", RID_IS_CLASS
, D_CXXONLY
},
471 { "__is_convertible_to", RID_IS_CONVERTIBLE_TO
, D_CXXONLY
},
472 { "__is_empty", RID_IS_EMPTY
, D_CXXONLY
},
473 { "__is_enum", RID_IS_ENUM
, D_CXXONLY
},
474 { "__is_final", RID_IS_FINAL
, D_CXXONLY
},
475 { "__is_literal_type", RID_IS_LITERAL_TYPE
, D_CXXONLY
},
476 { "__is_pod", RID_IS_POD
, D_CXXONLY
},
477 { "__is_polymorphic", RID_IS_POLYMORPHIC
, D_CXXONLY
},
478 { "__is_same_as", RID_IS_SAME_AS
, D_CXXONLY
},
479 { "__is_standard_layout", RID_IS_STD_LAYOUT
, D_CXXONLY
},
480 { "__is_trivial", RID_IS_TRIVIAL
, D_CXXONLY
},
481 { "__is_union", RID_IS_UNION
, D_CXXONLY
},
482 { "__label__", RID_LABEL
, 0 },
483 { "__null", RID_NULL
, 0 },
484 { "__real", RID_REALPART
, 0 },
485 { "__real__", RID_REALPART
, 0 },
486 { "__restrict", RID_RESTRICT
, 0 },
487 { "__restrict__", RID_RESTRICT
, 0 },
488 { "__signed", RID_SIGNED
, 0 },
489 { "__signed__", RID_SIGNED
, 0 },
490 { "__thread", RID_THREAD
, 0 },
491 { "__transaction_atomic", RID_TRANSACTION_ATOMIC
, 0 },
492 { "__transaction_relaxed", RID_TRANSACTION_RELAXED
, 0 },
493 { "__transaction_cancel", RID_TRANSACTION_CANCEL
, 0 },
494 { "__typeof", RID_TYPEOF
, 0 },
495 { "__typeof__", RID_TYPEOF
, 0 },
496 { "__underlying_type", RID_UNDERLYING_TYPE
, D_CXXONLY
},
497 { "__volatile", RID_VOLATILE
, 0 },
498 { "__volatile__", RID_VOLATILE
, 0 },
499 { "alignas", RID_ALIGNAS
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
500 { "alignof", RID_ALIGNOF
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
501 { "asm", RID_ASM
, D_ASM
},
502 { "auto", RID_AUTO
, 0 },
503 { "bool", RID_BOOL
, D_CXXONLY
| D_CXXWARN
},
504 { "break", RID_BREAK
, 0 },
505 { "case", RID_CASE
, 0 },
506 { "catch", RID_CATCH
, D_CXX_OBJC
| D_CXXWARN
},
507 { "char", RID_CHAR
, 0 },
508 { "char16_t", RID_CHAR16
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
509 { "char32_t", RID_CHAR32
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
510 { "class", RID_CLASS
, D_CXX_OBJC
| D_CXXWARN
},
511 { "const", RID_CONST
, 0 },
512 { "constexpr", RID_CONSTEXPR
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
513 { "const_cast", RID_CONSTCAST
, D_CXXONLY
| D_CXXWARN
},
514 { "continue", RID_CONTINUE
, 0 },
515 { "decltype", RID_DECLTYPE
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
516 { "default", RID_DEFAULT
, 0 },
517 { "delete", RID_DELETE
, D_CXXONLY
| D_CXXWARN
},
519 { "double", RID_DOUBLE
, 0 },
520 { "dynamic_cast", RID_DYNCAST
, D_CXXONLY
| D_CXXWARN
},
521 { "else", RID_ELSE
, 0 },
522 { "enum", RID_ENUM
, 0 },
523 { "explicit", RID_EXPLICIT
, D_CXXONLY
| D_CXXWARN
},
524 { "export", RID_EXPORT
, D_CXXONLY
| D_CXXWARN
},
525 { "extern", RID_EXTERN
, 0 },
526 { "false", RID_FALSE
, D_CXXONLY
| D_CXXWARN
},
527 { "float", RID_FLOAT
, 0 },
528 { "for", RID_FOR
, 0 },
529 { "friend", RID_FRIEND
, D_CXXONLY
| D_CXXWARN
},
530 { "goto", RID_GOTO
, 0 },
532 { "inline", RID_INLINE
, D_EXT89
},
533 { "int", RID_INT
, 0 },
534 { "long", RID_LONG
, 0 },
535 { "mutable", RID_MUTABLE
, D_CXXONLY
| D_CXXWARN
},
536 { "namespace", RID_NAMESPACE
, D_CXXONLY
| D_CXXWARN
},
537 { "new", RID_NEW
, D_CXXONLY
| D_CXXWARN
},
538 { "noexcept", RID_NOEXCEPT
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
539 { "nullptr", RID_NULLPTR
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
540 { "operator", RID_OPERATOR
, D_CXXONLY
| D_CXXWARN
},
541 { "private", RID_PRIVATE
, D_CXX_OBJC
| D_CXXWARN
},
542 { "protected", RID_PROTECTED
, D_CXX_OBJC
| D_CXXWARN
},
543 { "public", RID_PUBLIC
, D_CXX_OBJC
| D_CXXWARN
},
544 { "register", RID_REGISTER
, 0 },
545 { "reinterpret_cast", RID_REINTCAST
, D_CXXONLY
| D_CXXWARN
},
546 { "restrict", RID_RESTRICT
, D_CONLY
| D_C99
},
547 { "return", RID_RETURN
, 0 },
548 { "short", RID_SHORT
, 0 },
549 { "signed", RID_SIGNED
, 0 },
550 { "sizeof", RID_SIZEOF
, 0 },
551 { "static", RID_STATIC
, 0 },
552 { "static_assert", RID_STATIC_ASSERT
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
553 { "static_cast", RID_STATCAST
, D_CXXONLY
| D_CXXWARN
},
554 { "struct", RID_STRUCT
, 0 },
555 { "switch", RID_SWITCH
, 0 },
556 { "template", RID_TEMPLATE
, D_CXXONLY
| D_CXXWARN
},
557 { "this", RID_THIS
, D_CXXONLY
| D_CXXWARN
},
558 { "thread_local", RID_THREAD
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
559 { "throw", RID_THROW
, D_CXX_OBJC
| D_CXXWARN
},
560 { "true", RID_TRUE
, D_CXXONLY
| D_CXXWARN
},
561 { "try", RID_TRY
, D_CXX_OBJC
| D_CXXWARN
},
562 { "typedef", RID_TYPEDEF
, 0 },
563 { "typename", RID_TYPENAME
, D_CXXONLY
| D_CXXWARN
},
564 { "typeid", RID_TYPEID
, D_CXXONLY
| D_CXXWARN
},
565 { "typeof", RID_TYPEOF
, D_ASM
| D_EXT
},
566 { "union", RID_UNION
, 0 },
567 { "unsigned", RID_UNSIGNED
, 0 },
568 { "using", RID_USING
, D_CXXONLY
| D_CXXWARN
},
569 { "virtual", RID_VIRTUAL
, D_CXXONLY
| D_CXXWARN
},
570 { "void", RID_VOID
, 0 },
571 { "volatile", RID_VOLATILE
, 0 },
572 { "wchar_t", RID_WCHAR
, D_CXXONLY
},
573 { "while", RID_WHILE
, 0 },
575 /* Concepts-related keywords */
576 { "concept", RID_CONCEPT
, D_CXX_CONCEPTS_FLAGS
| D_CXXWARN
},
577 { "requires", RID_REQUIRES
, D_CXX_CONCEPTS_FLAGS
| D_CXXWARN
},
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 /* The same comments as for noreturn attributes apply to const ones. */
660 { "const", 0, 0, true, false, false,
661 handle_const_attribute
, false },
662 { "transparent_union", 0, 0, false, false, false,
663 handle_transparent_union_attribute
, false },
664 { "constructor", 0, 1, true, false, false,
665 handle_constructor_attribute
, false },
666 { "destructor", 0, 1, true, false, false,
667 handle_destructor_attribute
, false },
668 { "mode", 1, 1, false, true, false,
669 handle_mode_attribute
, false },
670 { "section", 1, 1, true, false, false,
671 handle_section_attribute
, false },
672 { "aligned", 0, 1, false, false, false,
673 handle_aligned_attribute
, false },
674 { "weak", 0, 0, true, false, false,
675 handle_weak_attribute
, false },
676 { "ifunc", 1, 1, true, false, false,
677 handle_ifunc_attribute
, false },
678 { "alias", 1, 1, true, false, false,
679 handle_alias_attribute
, false },
680 { "weakref", 0, 1, true, false, false,
681 handle_weakref_attribute
, false },
682 { "no_instrument_function", 0, 0, true, false, false,
683 handle_no_instrument_function_attribute
,
685 { "malloc", 0, 0, true, false, false,
686 handle_malloc_attribute
, false },
687 { "returns_twice", 0, 0, true, false, false,
688 handle_returns_twice_attribute
, false },
689 { "no_stack_limit", 0, 0, true, false, false,
690 handle_no_limit_stack_attribute
, false },
691 { "pure", 0, 0, true, false, false,
692 handle_pure_attribute
, false },
693 { "transaction_callable", 0, 0, false, true, false,
694 handle_tm_attribute
, false },
695 { "transaction_unsafe", 0, 0, false, true, false,
696 handle_tm_attribute
, false },
697 { "transaction_safe", 0, 0, false, true, false,
698 handle_tm_attribute
, false },
699 { "transaction_may_cancel_outer", 0, 0, false, true, false,
700 handle_tm_attribute
, false },
701 /* ??? These two attributes didn't make the transition from the
702 Intel language document to the multi-vendor language document. */
703 { "transaction_pure", 0, 0, false, true, false,
704 handle_tm_attribute
, false },
705 { "transaction_wrap", 1, 1, true, false, false,
706 handle_tm_wrap_attribute
, false },
707 /* For internal use (marking of builtins) only. The name contains space
708 to prevent its usage in source code. */
709 { "no vops", 0, 0, true, false, false,
710 handle_novops_attribute
, false },
711 { "deprecated", 0, 1, false, false, false,
712 handle_deprecated_attribute
, false },
713 { "vector_size", 1, 1, false, true, false,
714 handle_vector_size_attribute
, false },
715 { "visibility", 1, 1, false, false, false,
716 handle_visibility_attribute
, false },
717 { "tls_model", 1, 1, true, false, false,
718 handle_tls_model_attribute
, false },
719 { "nonnull", 0, -1, false, true, true,
720 handle_nonnull_attribute
, false },
721 { "nothrow", 0, 0, true, false, false,
722 handle_nothrow_attribute
, false },
723 { "may_alias", 0, 0, false, true, false, NULL
, false },
724 { "cleanup", 1, 1, true, false, false,
725 handle_cleanup_attribute
, false },
726 { "warn_unused_result", 0, 0, false, true, true,
727 handle_warn_unused_result_attribute
, false },
728 { "sentinel", 0, 1, false, true, true,
729 handle_sentinel_attribute
, false },
730 /* For internal use (marking of builtins) only. The name contains space
731 to prevent its usage in source code. */
732 { "type generic", 0, 0, false, true, true,
733 handle_type_generic_attribute
, false },
734 { "alloc_size", 1, 2, false, true, true,
735 handle_alloc_size_attribute
, false },
736 { "cold", 0, 0, true, false, false,
737 handle_cold_attribute
, false },
738 { "hot", 0, 0, true, false, false,
739 handle_hot_attribute
, false },
740 { "no_address_safety_analysis",
741 0, 0, true, false, false,
742 handle_no_address_safety_analysis_attribute
,
744 { "no_sanitize_address", 0, 0, true, false, false,
745 handle_no_sanitize_address_attribute
,
747 { "no_sanitize_undefined", 0, 0, true, false, false,
748 handle_no_sanitize_undefined_attribute
,
750 { "warning", 1, 1, true, false, false,
751 handle_error_attribute
, false },
752 { "error", 1, 1, true, false, false,
753 handle_error_attribute
, false },
754 { "target", 1, -1, true, false, false,
755 handle_target_attribute
, false },
756 { "optimize", 1, -1, true, false, false,
757 handle_optimize_attribute
, false },
758 /* For internal use only. The leading '*' both prevents its usage in
759 source code and signals that it may be overridden by machine tables. */
760 { "*tm regparm", 0, 0, false, true, true,
761 ignore_attribute
, false },
762 { "no_split_stack", 0, 0, true, false, false,
763 handle_no_split_stack_attribute
, false },
764 /* For internal use (marking of builtins and runtime functions) only.
765 The name contains space to prevent its usage in source code. */
766 { "fn spec", 1, 1, false, true, true,
767 handle_fnspec_attribute
, false },
768 { "warn_unused", 0, 0, false, false, false,
769 handle_warn_unused_attribute
, false },
770 { "returns_nonnull", 0, 0, false, true, true,
771 handle_returns_nonnull_attribute
, false },
772 { "omp declare simd", 0, -1, true, false, false,
773 handle_omp_declare_simd_attribute
, false },
774 { "cilk simd function", 0, -1, true, false, false,
775 handle_omp_declare_simd_attribute
, false },
776 { "omp declare target", 0, 0, true, false, false,
777 handle_omp_declare_target_attribute
, false },
778 { "alloc_align", 1, 1, false, true, true,
779 handle_alloc_align_attribute
, false },
780 { "assume_aligned", 1, 2, false, true, true,
781 handle_assume_aligned_attribute
, false },
782 { NULL
, 0, 0, false, false, false, NULL
, false }
785 /* Give the specifications for the format attributes, used by C and all
788 const struct attribute_spec c_common_format_attribute_table
[] =
790 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
791 affects_type_identity } */
792 { "format", 3, 3, false, true, true,
793 handle_format_attribute
, false },
794 { "format_arg", 1, 1, false, true, true,
795 handle_format_arg_attribute
, false },
796 { NULL
, 0, 0, false, false, false, NULL
, false }
799 /* Return identifier for address space AS. */
802 c_addr_space_name (addr_space_t as
)
804 int rid
= RID_FIRST_ADDR_SPACE
+ as
;
805 gcc_assert (ridpointers
[rid
]);
806 return IDENTIFIER_POINTER (ridpointers
[rid
]);
809 /* Push current bindings for the function name VAR_DECLS. */
812 start_fname_decls (void)
815 tree saved
= NULL_TREE
;
817 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
819 tree decl
= *fname_vars
[ix
].decl
;
823 saved
= tree_cons (decl
, build_int_cst (integer_type_node
, ix
),
825 *fname_vars
[ix
].decl
= NULL_TREE
;
828 if (saved
|| saved_function_name_decls
)
829 /* Normally they'll have been NULL, so only push if we've got a
830 stack, or they are non-NULL. */
831 saved_function_name_decls
= tree_cons (saved
, NULL_TREE
,
832 saved_function_name_decls
);
835 /* Finish up the current bindings, adding them into the current function's
836 statement tree. This must be done _before_ finish_stmt_tree is called.
837 If there is no current function, we must be at file scope and no statements
838 are involved. Pop the previous bindings. */
841 finish_fname_decls (void)
844 tree stmts
= NULL_TREE
;
845 tree stack
= saved_function_name_decls
;
847 for (; stack
&& TREE_VALUE (stack
); stack
= TREE_CHAIN (stack
))
848 append_to_statement_list (TREE_VALUE (stack
), &stmts
);
852 tree
*bodyp
= &DECL_SAVED_TREE (current_function_decl
);
854 if (TREE_CODE (*bodyp
) == BIND_EXPR
)
855 bodyp
= &BIND_EXPR_BODY (*bodyp
);
857 append_to_statement_list_force (*bodyp
, &stmts
);
861 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
862 *fname_vars
[ix
].decl
= NULL_TREE
;
866 /* We had saved values, restore them. */
869 for (saved
= TREE_PURPOSE (stack
); saved
; saved
= TREE_CHAIN (saved
))
871 tree decl
= TREE_PURPOSE (saved
);
872 unsigned ix
= TREE_INT_CST_LOW (TREE_VALUE (saved
));
874 *fname_vars
[ix
].decl
= decl
;
876 stack
= TREE_CHAIN (stack
);
878 saved_function_name_decls
= stack
;
881 /* Return the text name of the current function, suitably prettified
882 by PRETTY_P. Return string must be freed by caller. */
885 fname_as_string (int pretty_p
)
887 const char *name
= "top level";
890 cpp_string cstr
= { 0, 0 }, strname
;
898 if (current_function_decl
)
899 name
= lang_hooks
.decl_printable_name (current_function_decl
, vrb
);
901 len
= strlen (name
) + 3; /* Two for '"'s. One for NULL. */
903 namep
= XNEWVEC (char, len
);
904 snprintf (namep
, len
, "\"%s\"", name
);
905 strname
.text
= (unsigned char *) namep
;
906 strname
.len
= len
- 1;
908 if (cpp_interpret_string (parse_in
, &strname
, 1, &cstr
, CPP_STRING
))
911 return (const char *) cstr
.text
;
917 /* Return the VAR_DECL for a const char array naming the current
918 function. If the VAR_DECL has not yet been created, create it
919 now. RID indicates how it should be formatted and IDENTIFIER_NODE
920 ID is its name (unfortunately C and C++ hold the RID values of
921 keywords in different places, so we can't derive RID from ID in
922 this language independent code. LOC is the location of the
926 fname_decl (location_t loc
, unsigned int rid
, tree id
)
929 tree decl
= NULL_TREE
;
931 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
932 if (fname_vars
[ix
].rid
== rid
)
935 decl
= *fname_vars
[ix
].decl
;
938 /* If a tree is built here, it would normally have the lineno of
939 the current statement. Later this tree will be moved to the
940 beginning of the function and this line number will be wrong.
941 To avoid this problem set the lineno to 0 here; that prevents
942 it from appearing in the RTL. */
944 location_t saved_location
= input_location
;
945 input_location
= UNKNOWN_LOCATION
;
947 stmts
= push_stmt_list ();
948 decl
= (*make_fname_decl
) (loc
, id
, fname_vars
[ix
].pretty
);
949 stmts
= pop_stmt_list (stmts
);
950 if (!IS_EMPTY_STMT (stmts
))
951 saved_function_name_decls
952 = tree_cons (decl
, stmts
, saved_function_name_decls
);
953 *fname_vars
[ix
].decl
= decl
;
954 input_location
= saved_location
;
956 if (!ix
&& !current_function_decl
)
957 pedwarn (loc
, 0, "%qD is not defined outside of function scope", decl
);
962 /* Given a STRING_CST, give it a suitable array-of-chars data type. */
965 fix_string_type (tree value
)
967 int length
= TREE_STRING_LENGTH (value
);
969 tree e_type
, i_type
, a_type
;
971 /* Compute the number of elements, for the array type. */
972 if (TREE_TYPE (value
) == char_array_type_node
|| !TREE_TYPE (value
))
975 e_type
= char_type_node
;
977 else if (TREE_TYPE (value
) == char16_array_type_node
)
979 nchars
= length
/ (TYPE_PRECISION (char16_type_node
) / BITS_PER_UNIT
);
980 e_type
= char16_type_node
;
982 else if (TREE_TYPE (value
) == char32_array_type_node
)
984 nchars
= length
/ (TYPE_PRECISION (char32_type_node
) / BITS_PER_UNIT
);
985 e_type
= char32_type_node
;
989 nchars
= length
/ (TYPE_PRECISION (wchar_type_node
) / BITS_PER_UNIT
);
990 e_type
= wchar_type_node
;
993 /* C89 2.2.4.1, C99 5.2.4.1 (Translation limits). The analogous
994 limit in C++98 Annex B is very large (65536) and is not normative,
995 so we do not diagnose it (warn_overlength_strings is forced off
996 in c_common_post_options). */
997 if (warn_overlength_strings
)
999 const int nchars_max
= flag_isoc99
? 4095 : 509;
1000 const int relevant_std
= flag_isoc99
? 99 : 90;
1001 if (nchars
- 1 > nchars_max
)
1002 /* Translators: The %d after 'ISO C' will be 90 or 99. Do not
1003 separate the %d from the 'C'. 'ISO' should not be
1004 translated, but it may be moved after 'C%d' in languages
1005 where modifiers follow nouns. */
1006 pedwarn (input_location
, OPT_Woverlength_strings
,
1007 "string length %qd is greater than the length %qd "
1008 "ISO C%d compilers are required to support",
1009 nchars
- 1, nchars_max
, relevant_std
);
1012 /* Create the array type for the string constant. The ISO C++
1013 standard says that a string literal has type `const char[N]' or
1014 `const wchar_t[N]'. We use the same logic when invoked as a C
1015 front-end with -Wwrite-strings.
1016 ??? We should change the type of an expression depending on the
1017 state of a warning flag. We should just be warning -- see how
1018 this is handled in the C++ front-end for the deprecated implicit
1019 conversion from string literals to `char*' or `wchar_t*'.
1021 The C++ front end relies on TYPE_MAIN_VARIANT of a cv-qualified
1022 array type being the unqualified version of that type.
1023 Therefore, if we are constructing an array of const char, we must
1024 construct the matching unqualified array type first. The C front
1025 end does not require this, but it does no harm, so we do it
1027 i_type
= build_index_type (size_int (nchars
- 1));
1028 a_type
= build_array_type (e_type
, i_type
);
1029 if (c_dialect_cxx() || warn_write_strings
)
1030 a_type
= c_build_qualified_type (a_type
, TYPE_QUAL_CONST
);
1032 TREE_TYPE (value
) = a_type
;
1033 TREE_CONSTANT (value
) = 1;
1034 TREE_READONLY (value
) = 1;
1035 TREE_STATIC (value
) = 1;
1039 /* If DISABLE is true, stop issuing warnings. This is used when
1040 parsing code that we know will not be executed. This function may
1041 be called multiple times, and works as a stack. */
1044 c_disable_warnings (bool disable
)
1048 ++c_inhibit_evaluation_warnings
;
1049 fold_defer_overflow_warnings ();
1053 /* If ENABLE is true, reenable issuing warnings. */
1056 c_enable_warnings (bool enable
)
1060 --c_inhibit_evaluation_warnings
;
1061 fold_undefer_and_ignore_overflow_warnings ();
1065 /* Fully fold EXPR, an expression that was not folded (beyond integer
1066 constant expressions and null pointer constants) when being built
1067 up. If IN_INIT, this is in a static initializer and certain
1068 changes are made to the folding done. Clear *MAYBE_CONST if
1069 MAYBE_CONST is not NULL and EXPR is definitely not a constant
1070 expression because it contains an evaluated operator (in C99) or an
1071 operator outside of sizeof returning an integer constant (in C90)
1072 not permitted in constant expressions, or because it contains an
1073 evaluated arithmetic overflow. (*MAYBE_CONST should typically be
1074 set to true by callers before calling this function.) Return the
1075 folded expression. Function arguments have already been folded
1076 before calling this function, as have the contents of SAVE_EXPR,
1077 TARGET_EXPR, BIND_EXPR, VA_ARG_EXPR, OBJ_TYPE_REF and
1078 C_MAYBE_CONST_EXPR. */
1081 c_fully_fold (tree expr
, bool in_init
, bool *maybe_const
)
1084 tree eptype
= NULL_TREE
;
1086 bool maybe_const_itself
= true;
1087 location_t loc
= EXPR_LOCATION (expr
);
1089 /* This function is not relevant to C++ because C++ folds while
1090 parsing, and may need changes to be correct for C++ when C++
1091 stops folding while parsing. */
1092 if (c_dialect_cxx ())
1096 maybe_const
= &dummy
;
1097 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
1099 eptype
= TREE_TYPE (expr
);
1100 expr
= TREE_OPERAND (expr
, 0);
1102 ret
= c_fully_fold_internal (expr
, in_init
, maybe_const
,
1103 &maybe_const_itself
);
1105 ret
= fold_convert_loc (loc
, eptype
, ret
);
1106 *maybe_const
&= maybe_const_itself
;
1110 /* Internal helper for c_fully_fold. EXPR and IN_INIT are as for
1111 c_fully_fold. *MAYBE_CONST_OPERANDS is cleared because of operands
1112 not permitted, while *MAYBE_CONST_ITSELF is cleared because of
1113 arithmetic overflow (for C90, *MAYBE_CONST_OPERANDS is carried from
1114 both evaluated and unevaluated subexpressions while
1115 *MAYBE_CONST_ITSELF is carried from only evaluated
1119 c_fully_fold_internal (tree expr
, bool in_init
, bool *maybe_const_operands
,
1120 bool *maybe_const_itself
)
1123 enum tree_code code
= TREE_CODE (expr
);
1124 enum tree_code_class kind
= TREE_CODE_CLASS (code
);
1125 location_t loc
= EXPR_LOCATION (expr
);
1126 tree op0
, op1
, op2
, op3
;
1127 tree orig_op0
, orig_op1
, orig_op2
;
1128 bool op0_const
= true, op1_const
= true, op2_const
= true;
1129 bool op0_const_self
= true, op1_const_self
= true, op2_const_self
= true;
1130 bool nowarning
= TREE_NO_WARNING (expr
);
1133 /* This function is not relevant to C++ because C++ folds while
1134 parsing, and may need changes to be correct for C++ when C++
1135 stops folding while parsing. */
1136 if (c_dialect_cxx ())
1139 /* Constants, declarations, statements, errors, SAVE_EXPRs and
1140 anything else not counted as an expression cannot usefully be
1141 folded further at this point. */
1142 if (!IS_EXPR_CODE_CLASS (kind
)
1143 || kind
== tcc_statement
1144 || code
== SAVE_EXPR
)
1147 /* Operands of variable-length expressions (function calls) have
1148 already been folded, as have __builtin_* function calls, and such
1149 expressions cannot occur in constant expressions. */
1150 if (kind
== tcc_vl_exp
)
1152 *maybe_const_operands
= false;
1157 if (code
== C_MAYBE_CONST_EXPR
)
1159 tree pre
= C_MAYBE_CONST_EXPR_PRE (expr
);
1160 tree inner
= C_MAYBE_CONST_EXPR_EXPR (expr
);
1161 if (C_MAYBE_CONST_EXPR_NON_CONST (expr
))
1162 *maybe_const_operands
= false;
1163 if (C_MAYBE_CONST_EXPR_INT_OPERANDS (expr
))
1164 *maybe_const_itself
= false;
1165 if (pre
&& !in_init
)
1166 ret
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr
), pre
, inner
);
1172 /* Assignment, increment, decrement, function call and comma
1173 operators, and statement expressions, cannot occur in constant
1174 expressions if evaluated / outside of sizeof. (Function calls
1175 were handled above, though VA_ARG_EXPR is treated like a function
1176 call here, and statement expressions are handled through
1177 C_MAYBE_CONST_EXPR to avoid folding inside them.) */
1181 case PREDECREMENT_EXPR
:
1182 case PREINCREMENT_EXPR
:
1183 case POSTDECREMENT_EXPR
:
1184 case POSTINCREMENT_EXPR
:
1186 *maybe_const_operands
= false;
1193 *maybe_const_operands
= false;
1201 /* Fold individual tree codes as appropriate. */
1204 case COMPOUND_LITERAL_EXPR
:
1205 /* Any non-constancy will have been marked in a containing
1206 C_MAYBE_CONST_EXPR; there is no more folding to do here. */
1210 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1211 op1
= TREE_OPERAND (expr
, 1);
1212 op2
= TREE_OPERAND (expr
, 2);
1213 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1214 maybe_const_itself
);
1215 STRIP_TYPE_NOPS (op0
);
1216 if (op0
!= orig_op0
)
1217 ret
= build3 (COMPONENT_REF
, TREE_TYPE (expr
), op0
, op1
, op2
);
1220 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1221 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1226 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1227 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1228 op2
= TREE_OPERAND (expr
, 2);
1229 op3
= TREE_OPERAND (expr
, 3);
1230 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1231 maybe_const_itself
);
1232 STRIP_TYPE_NOPS (op0
);
1233 op1
= c_fully_fold_internal (op1
, in_init
, maybe_const_operands
,
1234 maybe_const_itself
);
1235 STRIP_TYPE_NOPS (op1
);
1236 op1
= decl_constant_value_for_optimization (op1
);
1237 if (op0
!= orig_op0
|| op1
!= orig_op1
)
1238 ret
= build4 (ARRAY_REF
, TREE_TYPE (expr
), op0
, op1
, op2
, op3
);
1241 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1242 TREE_SIDE_EFFECTS (ret
) = TREE_SIDE_EFFECTS (expr
);
1243 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1250 case PREDECREMENT_EXPR
:
1251 case PREINCREMENT_EXPR
:
1252 case POSTDECREMENT_EXPR
:
1253 case POSTINCREMENT_EXPR
:
1257 case POINTER_PLUS_EXPR
:
1258 case TRUNC_DIV_EXPR
:
1260 case FLOOR_DIV_EXPR
:
1261 case TRUNC_MOD_EXPR
:
1263 case EXACT_DIV_EXPR
:
1276 case TRUTH_AND_EXPR
:
1278 case TRUTH_XOR_EXPR
:
1279 case UNORDERED_EXPR
:
1286 /* Binary operations evaluating both arguments (increment and
1287 decrement are binary internally in GCC). */
1288 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1289 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1290 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1291 maybe_const_itself
);
1292 STRIP_TYPE_NOPS (op0
);
1293 if (code
!= MODIFY_EXPR
1294 && code
!= PREDECREMENT_EXPR
1295 && code
!= PREINCREMENT_EXPR
1296 && code
!= POSTDECREMENT_EXPR
1297 && code
!= POSTINCREMENT_EXPR
)
1298 op0
= decl_constant_value_for_optimization (op0
);
1299 /* The RHS of a MODIFY_EXPR was fully folded when building that
1300 expression for the sake of conversion warnings. */
1301 if (code
!= MODIFY_EXPR
)
1302 op1
= c_fully_fold_internal (op1
, in_init
, maybe_const_operands
,
1303 maybe_const_itself
);
1304 STRIP_TYPE_NOPS (op1
);
1305 op1
= decl_constant_value_for_optimization (op1
);
1306 if (op0
!= orig_op0
|| op1
!= orig_op1
|| in_init
)
1308 ? fold_build2_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
)
1309 : fold_build2_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
);
1312 if (TREE_OVERFLOW_P (ret
)
1313 && !TREE_OVERFLOW_P (op0
)
1314 && !TREE_OVERFLOW_P (op1
))
1315 overflow_warning (EXPR_LOCATION (expr
), ret
);
1316 if ((code
== LSHIFT_EXPR
|| code
== RSHIFT_EXPR
)
1317 && TREE_CODE (orig_op1
) != INTEGER_CST
1318 && TREE_CODE (op1
) == INTEGER_CST
1319 && (TREE_CODE (TREE_TYPE (orig_op0
)) == INTEGER_TYPE
1320 || TREE_CODE (TREE_TYPE (orig_op0
)) == FIXED_POINT_TYPE
)
1321 && TREE_CODE (TREE_TYPE (orig_op1
)) == INTEGER_TYPE
1322 && c_inhibit_evaluation_warnings
== 0)
1324 if (tree_int_cst_sgn (op1
) < 0)
1325 warning_at (loc
, 0, (code
== LSHIFT_EXPR
1326 ? G_("left shift count is negative")
1327 : G_("right shift count is negative")));
1328 else if (compare_tree_int (op1
,
1329 TYPE_PRECISION (TREE_TYPE (orig_op0
)))
1331 warning_at (loc
, 0, (code
== LSHIFT_EXPR
1332 ? G_("left shift count >= width of type")
1333 : G_("right shift count >= width of type")));
1338 case FIX_TRUNC_EXPR
:
1341 case ADDR_SPACE_CONVERT_EXPR
:
1342 case VIEW_CONVERT_EXPR
:
1343 case NON_LVALUE_EXPR
:
1346 case TRUTH_NOT_EXPR
:
1351 /* Unary operations. */
1352 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1353 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1354 maybe_const_itself
);
1355 STRIP_TYPE_NOPS (op0
);
1356 if (code
!= ADDR_EXPR
&& code
!= REALPART_EXPR
&& code
!= IMAGPART_EXPR
)
1357 op0
= decl_constant_value_for_optimization (op0
);
1358 /* ??? Cope with user tricks that amount to offsetof. The middle-end is
1359 not prepared to deal with them if they occur in initializers. */
1361 && code
== ADDR_EXPR
1362 && (op1
= get_base_address (op0
)) != NULL_TREE
1363 && TREE_CODE (op1
) == INDIRECT_REF
1364 && TREE_CONSTANT (TREE_OPERAND (op1
, 0)))
1365 ret
= fold_convert_loc (loc
, TREE_TYPE (expr
), fold_offsetof_1 (op0
));
1366 else if (op0
!= orig_op0
|| in_init
)
1368 ? fold_build1_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
)
1369 : fold_build1_loc (loc
, code
, TREE_TYPE (expr
), op0
);
1372 if (code
== INDIRECT_REF
1374 && TREE_CODE (ret
) == INDIRECT_REF
)
1376 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1377 TREE_SIDE_EFFECTS (ret
) = TREE_SIDE_EFFECTS (expr
);
1378 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1382 case FIX_TRUNC_EXPR
:
1385 /* Don't warn about explicit conversions. We will already
1386 have warned about suspect implicit conversions. */
1390 if (TREE_OVERFLOW_P (ret
) && !TREE_OVERFLOW_P (op0
))
1391 overflow_warning (EXPR_LOCATION (expr
), ret
);
1396 case TRUTH_ANDIF_EXPR
:
1397 case TRUTH_ORIF_EXPR
:
1398 /* Binary operations not necessarily evaluating both
1400 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1401 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1402 op0
= c_fully_fold_internal (op0
, in_init
, &op0_const
, &op0_const_self
);
1403 STRIP_TYPE_NOPS (op0
);
1405 unused_p
= (op0
== (code
== TRUTH_ANDIF_EXPR
1406 ? truthvalue_false_node
1407 : truthvalue_true_node
));
1408 c_disable_warnings (unused_p
);
1409 op1
= c_fully_fold_internal (op1
, in_init
, &op1_const
, &op1_const_self
);
1410 STRIP_TYPE_NOPS (op1
);
1411 c_enable_warnings (unused_p
);
1413 if (op0
!= orig_op0
|| op1
!= orig_op1
|| in_init
)
1415 ? fold_build2_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
)
1416 : fold_build2_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
);
1419 *maybe_const_operands
&= op0_const
;
1420 *maybe_const_itself
&= op0_const_self
;
1424 && (code
== TRUTH_ANDIF_EXPR
1425 ? op0
== truthvalue_false_node
1426 : op0
== truthvalue_true_node
)))
1427 *maybe_const_operands
&= op1_const
;
1430 && (code
== TRUTH_ANDIF_EXPR
1431 ? op0
== truthvalue_false_node
1432 : op0
== truthvalue_true_node
)))
1433 *maybe_const_itself
&= op1_const_self
;
1437 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1438 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1439 orig_op2
= op2
= TREE_OPERAND (expr
, 2);
1440 op0
= c_fully_fold_internal (op0
, in_init
, &op0_const
, &op0_const_self
);
1442 STRIP_TYPE_NOPS (op0
);
1443 c_disable_warnings (op0
== truthvalue_false_node
);
1444 op1
= c_fully_fold_internal (op1
, in_init
, &op1_const
, &op1_const_self
);
1445 STRIP_TYPE_NOPS (op1
);
1446 c_enable_warnings (op0
== truthvalue_false_node
);
1448 c_disable_warnings (op0
== truthvalue_true_node
);
1449 op2
= c_fully_fold_internal (op2
, in_init
, &op2_const
, &op2_const_self
);
1450 STRIP_TYPE_NOPS (op2
);
1451 c_enable_warnings (op0
== truthvalue_true_node
);
1453 if (op0
!= orig_op0
|| op1
!= orig_op1
|| op2
!= orig_op2
)
1454 ret
= fold_build3_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
, op2
);
1457 *maybe_const_operands
&= op0_const
;
1458 *maybe_const_itself
&= op0_const_self
;
1462 && op0
== truthvalue_false_node
))
1463 *maybe_const_operands
&= op1_const
;
1466 && op0
== truthvalue_false_node
))
1467 *maybe_const_itself
&= op1_const_self
;
1471 && op0
== truthvalue_true_node
))
1472 *maybe_const_operands
&= op2_const
;
1475 && op0
== truthvalue_true_node
))
1476 *maybe_const_itself
&= op2_const_self
;
1479 case EXCESS_PRECISION_EXPR
:
1480 /* Each case where an operand with excess precision may be
1481 encountered must remove the EXCESS_PRECISION_EXPR around
1482 inner operands and possibly put one around the whole
1483 expression or possibly convert to the semantic type (which
1484 c_fully_fold does); we cannot tell at this stage which is
1485 appropriate in any particular case. */
1489 /* Various codes may appear through folding built-in functions
1490 and their arguments. */
1495 /* Some folding may introduce NON_LVALUE_EXPRs; all lvalue checks
1496 have been done by this point, so remove them again. */
1497 nowarning
|= TREE_NO_WARNING (ret
);
1498 STRIP_TYPE_NOPS (ret
);
1499 if (nowarning
&& !TREE_NO_WARNING (ret
))
1501 if (!CAN_HAVE_LOCATION_P (ret
))
1502 ret
= build1 (NOP_EXPR
, TREE_TYPE (ret
), ret
);
1503 TREE_NO_WARNING (ret
) = 1;
1506 protected_set_expr_location (ret
, loc
);
1510 /* If not optimizing, EXP is not a VAR_DECL, or EXP has array type,
1511 return EXP. Otherwise, return either EXP or its known constant
1512 value (if it has one), but return EXP if EXP has mode BLKmode. ???
1513 Is the BLKmode test appropriate? */
1516 decl_constant_value_for_optimization (tree exp
)
1520 /* This function is only used by C, for c_fully_fold and other
1521 optimization, and may not be correct for C++. */
1522 if (c_dialect_cxx ())
1526 || TREE_CODE (exp
) != VAR_DECL
1527 || TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
1528 || DECL_MODE (exp
) == BLKmode
)
1531 ret
= decl_constant_value (exp
);
1532 /* Avoid unwanted tree sharing between the initializer and current
1533 function's body where the tree can be modified e.g. by the
1535 if (ret
!= exp
&& TREE_STATIC (exp
))
1536 ret
= unshare_expr (ret
);
1540 /* Print a warning if a constant expression had overflow in folding.
1541 Invoke this function on every expression that the language
1542 requires to be a constant expression.
1543 Note the ANSI C standard says it is erroneous for a
1544 constant expression to overflow. */
1547 constant_expression_warning (tree value
)
1549 if (warn_overflow
&& pedantic
1550 && (TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1551 || TREE_CODE (value
) == FIXED_CST
1552 || TREE_CODE (value
) == VECTOR_CST
1553 || TREE_CODE (value
) == COMPLEX_CST
)
1554 && TREE_OVERFLOW (value
))
1555 pedwarn (input_location
, OPT_Woverflow
, "overflow in constant expression");
1558 /* The same as above but print an unconditional error. */
1560 constant_expression_error (tree value
)
1562 if ((TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1563 || TREE_CODE (value
) == FIXED_CST
1564 || TREE_CODE (value
) == VECTOR_CST
1565 || TREE_CODE (value
) == COMPLEX_CST
)
1566 && TREE_OVERFLOW (value
))
1567 error ("overflow in constant expression");
1570 /* Print a warning if an expression had overflow in folding and its
1573 Invoke this function on every expression that
1574 (1) appears in the source code, and
1575 (2) is a constant expression that overflowed, and
1576 (3) is not already checked by convert_and_check;
1577 however, do not invoke this function on operands of explicit casts
1578 or when the expression is the result of an operator and any operand
1579 already overflowed. */
1582 overflow_warning (location_t loc
, tree value
)
1584 if (c_inhibit_evaluation_warnings
!= 0)
1587 switch (TREE_CODE (value
))
1590 warning_at (loc
, OPT_Woverflow
, "integer overflow in expression");
1594 warning_at (loc
, OPT_Woverflow
,
1595 "floating point overflow in expression");
1599 warning_at (loc
, OPT_Woverflow
, "fixed-point overflow in expression");
1603 warning_at (loc
, OPT_Woverflow
, "vector overflow in expression");
1607 if (TREE_CODE (TREE_REALPART (value
)) == INTEGER_CST
)
1608 warning_at (loc
, OPT_Woverflow
,
1609 "complex integer overflow in expression");
1610 else if (TREE_CODE (TREE_REALPART (value
)) == REAL_CST
)
1611 warning_at (loc
, OPT_Woverflow
,
1612 "complex floating point overflow in expression");
1620 /* Warn about uses of logical || / && operator in a context where it
1621 is likely that the bitwise equivalent was intended by the
1622 programmer. We have seen an expression in which CODE is a binary
1623 operator used to combine expressions OP_LEFT and OP_RIGHT, which before folding
1624 had CODE_LEFT and CODE_RIGHT, into an expression of type TYPE. */
1626 warn_logical_operator (location_t location
, enum tree_code code
, tree type
,
1627 enum tree_code code_left
, tree op_left
,
1628 enum tree_code
ARG_UNUSED (code_right
), tree op_right
)
1630 int or_op
= (code
== TRUTH_ORIF_EXPR
|| code
== TRUTH_OR_EXPR
);
1631 int in0_p
, in1_p
, in_p
;
1632 tree low0
, low1
, low
, high0
, high1
, high
, lhs
, rhs
, tem
;
1633 bool strict_overflow_p
= false;
1635 if (code
!= TRUTH_ANDIF_EXPR
1636 && code
!= TRUTH_AND_EXPR
1637 && code
!= TRUTH_ORIF_EXPR
1638 && code
!= TRUTH_OR_EXPR
)
1641 /* Warn if &&/|| are being used in a context where it is
1642 likely that the bitwise equivalent was intended by the
1643 programmer. That is, an expression such as op && MASK
1644 where op should not be any boolean expression, nor a
1645 constant, and mask seems to be a non-boolean integer constant. */
1646 if (!truth_value_p (code_left
)
1647 && INTEGRAL_TYPE_P (TREE_TYPE (op_left
))
1648 && !CONSTANT_CLASS_P (op_left
)
1649 && !TREE_NO_WARNING (op_left
)
1650 && TREE_CODE (op_right
) == INTEGER_CST
1651 && !integer_zerop (op_right
)
1652 && !integer_onep (op_right
))
1655 warning_at (location
, OPT_Wlogical_op
, "logical %<or%>"
1656 " applied to non-boolean constant");
1658 warning_at (location
, OPT_Wlogical_op
, "logical %<and%>"
1659 " applied to non-boolean constant");
1660 TREE_NO_WARNING (op_left
) = true;
1664 /* We do not warn for constants because they are typical of macro
1665 expansions that test for features. */
1666 if (CONSTANT_CLASS_P (op_left
) || CONSTANT_CLASS_P (op_right
))
1669 /* This warning only makes sense with logical operands. */
1670 if (!(truth_value_p (TREE_CODE (op_left
))
1671 || INTEGRAL_TYPE_P (TREE_TYPE (op_left
)))
1672 || !(truth_value_p (TREE_CODE (op_right
))
1673 || INTEGRAL_TYPE_P (TREE_TYPE (op_right
))))
1677 /* We first test whether either side separately is trivially true
1678 (with OR) or trivially false (with AND). If so, do not warn.
1679 This is a common idiom for testing ranges of data types in
1681 lhs
= make_range (op_left
, &in0_p
, &low0
, &high0
, &strict_overflow_p
);
1684 if (TREE_CODE (lhs
) == C_MAYBE_CONST_EXPR
)
1685 lhs
= C_MAYBE_CONST_EXPR_EXPR (lhs
);
1687 /* If this is an OR operation, invert both sides; now, the result
1688 should be always false to get a warning. */
1692 tem
= build_range_check (UNKNOWN_LOCATION
, type
, lhs
, in0_p
, low0
, high0
);
1693 if (tem
&& integer_zerop (tem
))
1696 rhs
= make_range (op_right
, &in1_p
, &low1
, &high1
, &strict_overflow_p
);
1699 if (TREE_CODE (rhs
) == C_MAYBE_CONST_EXPR
)
1700 rhs
= C_MAYBE_CONST_EXPR_EXPR (rhs
);
1702 /* If this is an OR operation, invert both sides; now, the result
1703 should be always false to get a warning. */
1707 tem
= build_range_check (UNKNOWN_LOCATION
, type
, rhs
, in1_p
, low1
, high1
);
1708 if (tem
&& integer_zerop (tem
))
1711 /* If both expressions have the same operand, if we can merge the
1712 ranges, and if the range test is always false, then warn. */
1713 if (operand_equal_p (lhs
, rhs
, 0)
1714 && merge_ranges (&in_p
, &low
, &high
, in0_p
, low0
, high0
,
1716 && 0 != (tem
= build_range_check (UNKNOWN_LOCATION
,
1717 type
, lhs
, in_p
, low
, high
))
1718 && integer_zerop (tem
))
1721 warning_at (location
, OPT_Wlogical_op
,
1723 "of collectively exhaustive tests is always true");
1725 warning_at (location
, OPT_Wlogical_op
,
1727 "of mutually exclusive tests is always false");
1731 /* Warn about logical not used on the left hand side operand of a comparison.
1732 This function assumes that the LHS is inside of TRUTH_NOT_EXPR.
1733 Do not warn if the LHS or RHS is of a boolean or a vector type. */
1736 warn_logical_not_parentheses (location_t location
, enum tree_code code
,
1739 if (TREE_CODE_CLASS (code
) != tcc_comparison
)
1741 if (TREE_TYPE (lhs
) == NULL_TREE
1742 || TREE_TYPE (rhs
) == NULL_TREE
)
1744 else if (TREE_CODE (TREE_TYPE (lhs
)) == BOOLEAN_TYPE
1745 || TREE_CODE (TREE_TYPE (rhs
)) == BOOLEAN_TYPE
1746 || VECTOR_TYPE_P (TREE_TYPE (lhs
))
1747 || VECTOR_TYPE_P (TREE_TYPE (rhs
)))
1750 warning_at (location
, OPT_Wlogical_not_parentheses
,
1751 "logical not is only applied to the left hand side of "
1755 /* Warn if EXP contains any computations whose results are not used.
1756 Return true if a warning is printed; false otherwise. LOCUS is the
1757 (potential) location of the expression. */
1760 warn_if_unused_value (const_tree exp
, location_t locus
)
1763 if (TREE_USED (exp
) || TREE_NO_WARNING (exp
))
1766 /* Don't warn about void constructs. This includes casting to void,
1767 void function calls, and statement expressions with a final cast
1769 if (VOID_TYPE_P (TREE_TYPE (exp
)))
1772 if (EXPR_HAS_LOCATION (exp
))
1773 locus
= EXPR_LOCATION (exp
);
1775 switch (TREE_CODE (exp
))
1777 case PREINCREMENT_EXPR
:
1778 case POSTINCREMENT_EXPR
:
1779 case PREDECREMENT_EXPR
:
1780 case POSTDECREMENT_EXPR
:
1785 case TRY_CATCH_EXPR
:
1786 case WITH_CLEANUP_EXPR
:
1792 /* For a binding, warn if no side effect within it. */
1793 exp
= BIND_EXPR_BODY (exp
);
1797 case NON_LVALUE_EXPR
:
1799 exp
= TREE_OPERAND (exp
, 0);
1802 case TRUTH_ORIF_EXPR
:
1803 case TRUTH_ANDIF_EXPR
:
1804 /* In && or ||, warn if 2nd operand has no side effect. */
1805 exp
= TREE_OPERAND (exp
, 1);
1809 if (warn_if_unused_value (TREE_OPERAND (exp
, 0), locus
))
1811 /* Let people do `(foo (), 0)' without a warning. */
1812 if (TREE_CONSTANT (TREE_OPERAND (exp
, 1)))
1814 exp
= TREE_OPERAND (exp
, 1);
1818 /* If this is an expression with side effects, don't warn; this
1819 case commonly appears in macro expansions. */
1820 if (TREE_SIDE_EFFECTS (exp
))
1825 /* Don't warn about automatic dereferencing of references, since
1826 the user cannot control it. */
1827 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == REFERENCE_TYPE
)
1829 exp
= TREE_OPERAND (exp
, 0);
1835 /* Referencing a volatile value is a side effect, so don't warn. */
1836 if ((DECL_P (exp
) || REFERENCE_CLASS_P (exp
))
1837 && TREE_THIS_VOLATILE (exp
))
1840 /* If this is an expression which has no operands, there is no value
1841 to be unused. There are no such language-independent codes,
1842 but front ends may define such. */
1843 if (EXPRESSION_CLASS_P (exp
) && TREE_OPERAND_LENGTH (exp
) == 0)
1847 return warning_at (locus
, OPT_Wunused_value
, "value computed is not used");
1852 /* Print a warning about casts that might indicate violation
1853 of strict aliasing rules if -Wstrict-aliasing is used and
1854 strict aliasing mode is in effect. OTYPE is the original
1855 TREE_TYPE of EXPR, and TYPE the type we're casting to. */
1858 strict_aliasing_warning (tree otype
, tree type
, tree expr
)
1860 /* Strip pointer conversion chains and get to the correct original type. */
1862 otype
= TREE_TYPE (expr
);
1864 if (!(flag_strict_aliasing
1865 && POINTER_TYPE_P (type
)
1866 && POINTER_TYPE_P (otype
)
1867 && !VOID_TYPE_P (TREE_TYPE (type
)))
1868 /* If the type we are casting to is a ref-all pointer
1869 dereferencing it is always valid. */
1870 || TYPE_REF_CAN_ALIAS_ALL (type
))
1873 if ((warn_strict_aliasing
> 1) && TREE_CODE (expr
) == ADDR_EXPR
1874 && (DECL_P (TREE_OPERAND (expr
, 0))
1875 || handled_component_p (TREE_OPERAND (expr
, 0))))
1877 /* Casting the address of an object to non void pointer. Warn
1878 if the cast breaks type based aliasing. */
1879 if (!COMPLETE_TYPE_P (TREE_TYPE (type
)) && warn_strict_aliasing
== 2)
1881 warning (OPT_Wstrict_aliasing
, "type-punning to incomplete type "
1882 "might break strict-aliasing rules");
1887 /* warn_strict_aliasing >= 3. This includes the default (3).
1888 Only warn if the cast is dereferenced immediately. */
1889 alias_set_type set1
=
1890 get_alias_set (TREE_TYPE (TREE_OPERAND (expr
, 0)));
1891 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
1893 if (set1
!= set2
&& set2
!= 0
1894 && (set1
== 0 || !alias_sets_conflict_p (set1
, set2
)))
1896 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1897 "pointer will break strict-aliasing rules");
1900 else if (warn_strict_aliasing
== 2
1901 && !alias_sets_must_conflict_p (set1
, set2
))
1903 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1904 "pointer might break strict-aliasing rules");
1910 if ((warn_strict_aliasing
== 1) && !VOID_TYPE_P (TREE_TYPE (otype
)))
1912 /* At this level, warn for any conversions, even if an address is
1913 not taken in the same statement. This will likely produce many
1914 false positives, but could be useful to pinpoint problems that
1915 are not revealed at higher levels. */
1916 alias_set_type set1
= get_alias_set (TREE_TYPE (otype
));
1917 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
1918 if (!COMPLETE_TYPE_P (type
)
1919 || !alias_sets_must_conflict_p (set1
, set2
))
1921 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1922 "pointer might break strict-aliasing rules");
1930 /* Warn about memset (&a, 0, sizeof (&a)); and similar mistakes with
1931 sizeof as last operand of certain builtins. */
1934 sizeof_pointer_memaccess_warning (location_t
*sizeof_arg_loc
, tree callee
,
1935 vec
<tree
, va_gc
> *params
, tree
*sizeof_arg
,
1936 bool (*comp_types
) (tree
, tree
))
1938 tree type
, dest
= NULL_TREE
, src
= NULL_TREE
, tem
;
1939 bool strop
= false, cmp
= false;
1940 unsigned int idx
= ~0;
1943 if (TREE_CODE (callee
) != FUNCTION_DECL
1944 || DECL_BUILT_IN_CLASS (callee
) != BUILT_IN_NORMAL
1945 || vec_safe_length (params
) <= 1)
1948 switch (DECL_FUNCTION_CODE (callee
))
1950 case BUILT_IN_STRNCMP
:
1951 case BUILT_IN_STRNCASECMP
:
1954 case BUILT_IN_STRNCPY
:
1955 case BUILT_IN_STRNCPY_CHK
:
1956 case BUILT_IN_STRNCAT
:
1957 case BUILT_IN_STRNCAT_CHK
:
1958 case BUILT_IN_STPNCPY
:
1959 case BUILT_IN_STPNCPY_CHK
:
1962 case BUILT_IN_MEMCPY
:
1963 case BUILT_IN_MEMCPY_CHK
:
1964 case BUILT_IN_MEMMOVE
:
1965 case BUILT_IN_MEMMOVE_CHK
:
1966 if (params
->length () < 3)
1969 dest
= (*params
)[0];
1972 case BUILT_IN_BCOPY
:
1973 if (params
->length () < 3)
1976 dest
= (*params
)[1];
1979 case BUILT_IN_MEMCMP
:
1981 if (params
->length () < 3)
1984 dest
= (*params
)[0];
1988 case BUILT_IN_MEMSET
:
1989 case BUILT_IN_MEMSET_CHK
:
1990 if (params
->length () < 3)
1992 dest
= (*params
)[0];
1995 case BUILT_IN_BZERO
:
1996 dest
= (*params
)[0];
1999 case BUILT_IN_STRNDUP
:
2004 case BUILT_IN_MEMCHR
:
2005 if (params
->length () < 3)
2010 case BUILT_IN_SNPRINTF
:
2011 case BUILT_IN_SNPRINTF_CHK
:
2012 case BUILT_IN_VSNPRINTF
:
2013 case BUILT_IN_VSNPRINTF_CHK
:
2014 dest
= (*params
)[0];
2025 if (sizeof_arg
[idx
] == NULL
|| sizeof_arg
[idx
] == error_mark_node
)
2028 type
= TYPE_P (sizeof_arg
[idx
])
2029 ? sizeof_arg
[idx
] : TREE_TYPE (sizeof_arg
[idx
]);
2030 if (!POINTER_TYPE_P (type
))
2034 && (tem
= tree_strip_nop_conversions (dest
))
2035 && POINTER_TYPE_P (TREE_TYPE (tem
))
2036 && comp_types (TREE_TYPE (TREE_TYPE (tem
)), type
))
2040 && (tem
= tree_strip_nop_conversions (src
))
2041 && POINTER_TYPE_P (TREE_TYPE (tem
))
2042 && comp_types (TREE_TYPE (TREE_TYPE (tem
)), type
))
2045 loc
= sizeof_arg_loc
[idx
];
2049 if (!TYPE_P (sizeof_arg
[idx
])
2050 && operand_equal_p (dest
, sizeof_arg
[idx
], 0)
2051 && comp_types (TREE_TYPE (dest
), type
))
2053 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2054 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2055 "argument to %<sizeof%> in %qD call is the same "
2056 "expression as the destination; did you mean to "
2057 "remove the addressof?", callee
);
2058 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2059 == TYPE_PRECISION (char_type_node
))
2061 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2062 "argument to %<sizeof%> in %qD call is the same "
2063 "expression as the destination; did you mean to "
2064 "provide an explicit length?", callee
);
2066 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2067 "argument to %<sizeof%> in %qD call is the same "
2068 "expression as the destination; did you mean to "
2069 "dereference it?", callee
);
2073 if (POINTER_TYPE_P (TREE_TYPE (dest
))
2075 && comp_types (TREE_TYPE (dest
), type
)
2076 && !VOID_TYPE_P (TREE_TYPE (type
)))
2078 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2079 "argument to %<sizeof%> in %qD call is the same "
2080 "pointer type %qT as the destination; expected %qT "
2081 "or an explicit length", callee
, TREE_TYPE (dest
),
2082 TREE_TYPE (TREE_TYPE (dest
)));
2089 if (!TYPE_P (sizeof_arg
[idx
])
2090 && operand_equal_p (src
, sizeof_arg
[idx
], 0)
2091 && comp_types (TREE_TYPE (src
), type
))
2093 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2094 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2095 "argument to %<sizeof%> in %qD call is the same "
2096 "expression as the source; did you mean to "
2097 "remove the addressof?", callee
);
2098 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2099 == TYPE_PRECISION (char_type_node
))
2101 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2102 "argument to %<sizeof%> in %qD call is the same "
2103 "expression as the source; did you mean to "
2104 "provide an explicit length?", callee
);
2106 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2107 "argument to %<sizeof%> in %qD call is the same "
2108 "expression as the source; did you mean to "
2109 "dereference it?", callee
);
2113 if (POINTER_TYPE_P (TREE_TYPE (src
))
2115 && comp_types (TREE_TYPE (src
), type
)
2116 && !VOID_TYPE_P (TREE_TYPE (type
)))
2118 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2119 "argument to %<sizeof%> in %qD call is the same "
2120 "pointer type %qT as the source; expected %qT "
2121 "or an explicit length", callee
, TREE_TYPE (src
),
2122 TREE_TYPE (TREE_TYPE (src
)));
2129 if (!TYPE_P (sizeof_arg
[idx
])
2130 && operand_equal_p (dest
, sizeof_arg
[idx
], 0)
2131 && comp_types (TREE_TYPE (dest
), type
))
2133 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2134 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2135 "argument to %<sizeof%> in %qD call is the same "
2136 "expression as the first source; did you mean to "
2137 "remove the addressof?", callee
);
2138 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2139 == TYPE_PRECISION (char_type_node
))
2141 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2142 "argument to %<sizeof%> in %qD call is the same "
2143 "expression as the first source; did you mean to "
2144 "provide an explicit length?", callee
);
2146 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2147 "argument to %<sizeof%> in %qD call is the same "
2148 "expression as the first source; did you mean to "
2149 "dereference it?", callee
);
2153 if (POINTER_TYPE_P (TREE_TYPE (dest
))
2155 && comp_types (TREE_TYPE (dest
), type
)
2156 && !VOID_TYPE_P (TREE_TYPE (type
)))
2158 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2159 "argument to %<sizeof%> in %qD call is the same "
2160 "pointer type %qT as the first source; expected %qT "
2161 "or an explicit length", callee
, TREE_TYPE (dest
),
2162 TREE_TYPE (TREE_TYPE (dest
)));
2169 if (!TYPE_P (sizeof_arg
[idx
])
2170 && operand_equal_p (src
, sizeof_arg
[idx
], 0)
2171 && comp_types (TREE_TYPE (src
), type
))
2173 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2174 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2175 "argument to %<sizeof%> in %qD call is the same "
2176 "expression as the second source; did you mean to "
2177 "remove the addressof?", callee
);
2178 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2179 == TYPE_PRECISION (char_type_node
))
2181 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2182 "argument to %<sizeof%> in %qD call is the same "
2183 "expression as the second source; did you mean to "
2184 "provide an explicit length?", callee
);
2186 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2187 "argument to %<sizeof%> in %qD call is the same "
2188 "expression as the second source; did you mean to "
2189 "dereference it?", callee
);
2193 if (POINTER_TYPE_P (TREE_TYPE (src
))
2195 && comp_types (TREE_TYPE (src
), type
)
2196 && !VOID_TYPE_P (TREE_TYPE (type
)))
2198 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2199 "argument to %<sizeof%> in %qD call is the same "
2200 "pointer type %qT as the second source; expected %qT "
2201 "or an explicit length", callee
, TREE_TYPE (src
),
2202 TREE_TYPE (TREE_TYPE (src
)));
2209 /* Warn for unlikely, improbable, or stupid DECL declarations
2213 check_main_parameter_types (tree decl
)
2215 function_args_iterator iter
;
2219 FOREACH_FUNCTION_ARGS (TREE_TYPE (decl
), type
, iter
)
2221 /* XXX void_type_node belies the abstraction. */
2222 if (type
== void_type_node
|| type
== error_mark_node
)
2226 if (TYPE_ATOMIC (t
))
2227 pedwarn (input_location
, OPT_Wmain
,
2228 "%<_Atomic%>-qualified parameter type %qT of %q+D",
2230 while (POINTER_TYPE_P (t
))
2233 if (TYPE_ATOMIC (t
))
2234 pedwarn (input_location
, OPT_Wmain
,
2235 "%<_Atomic%>-qualified parameter type %qT of %q+D",
2243 if (TYPE_MAIN_VARIANT (type
) != integer_type_node
)
2244 pedwarn (input_location
, OPT_Wmain
,
2245 "first argument of %q+D should be %<int%>", decl
);
2249 if (TREE_CODE (type
) != POINTER_TYPE
2250 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
2251 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
2253 pedwarn (input_location
, OPT_Wmain
,
2254 "second argument of %q+D should be %<char **%>", decl
);
2258 if (TREE_CODE (type
) != POINTER_TYPE
2259 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
2260 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
2262 pedwarn (input_location
, OPT_Wmain
,
2263 "third argument of %q+D should probably be "
2264 "%<char **%>", decl
);
2269 /* It is intentional that this message does not mention the third
2270 argument because it's only mentioned in an appendix of the
2272 if (argct
> 0 && (argct
< 2 || argct
> 3))
2273 pedwarn (input_location
, OPT_Wmain
,
2274 "%q+D takes only zero or two arguments", decl
);
2276 if (stdarg_p (TREE_TYPE (decl
)))
2277 pedwarn (input_location
, OPT_Wmain
,
2278 "%q+D declared as variadic function", decl
);
2281 /* vector_targets_convertible_p is used for vector pointer types. The
2282 callers perform various checks that the qualifiers are satisfactory,
2283 while OTOH vector_targets_convertible_p ignores the number of elements
2284 in the vectors. That's fine with vector pointers as we can consider,
2285 say, a vector of 8 elements as two consecutive vectors of 4 elements,
2286 and that does not require and conversion of the pointer values.
2287 In contrast, vector_types_convertible_p and
2288 vector_types_compatible_elements_p are used for vector value types. */
2289 /* True if pointers to distinct types T1 and T2 can be converted to
2290 each other without an explicit cast. Only returns true for opaque
2293 vector_targets_convertible_p (const_tree t1
, const_tree t2
)
2295 if (TREE_CODE (t1
) == VECTOR_TYPE
&& TREE_CODE (t2
) == VECTOR_TYPE
2296 && (TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2297 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2303 /* vector_types_convertible_p is used for vector value types.
2304 It could in principle call vector_targets_convertible_p as a subroutine,
2305 but then the check for vector type would be duplicated with its callers,
2306 and also the purpose of vector_targets_convertible_p would become
2308 Where vector_types_convertible_p returns true, a conversion might still be
2309 needed to make the types match.
2310 In contrast, vector_targets_convertible_p is used for vector pointer
2311 values, and vector_types_compatible_elements_p is used specifically
2312 in the context for binary operators, as a check if use is possible without
2314 /* True if vector types T1 and T2 can be converted to each other
2315 without an explicit cast. If EMIT_LAX_NOTE is true, and T1 and T2
2316 can only be converted with -flax-vector-conversions yet that is not
2317 in effect, emit a note telling the user about that option if such
2318 a note has not previously been emitted. */
2320 vector_types_convertible_p (const_tree t1
, const_tree t2
, bool emit_lax_note
)
2322 static bool emitted_lax_note
= false;
2323 bool convertible_lax
;
2325 if ((TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2326 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2330 (tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
))
2331 && (TREE_CODE (TREE_TYPE (t1
)) != REAL_TYPE
||
2332 TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
))
2333 && (INTEGRAL_TYPE_P (TREE_TYPE (t1
))
2334 == INTEGRAL_TYPE_P (TREE_TYPE (t2
))));
2336 if (!convertible_lax
|| flag_lax_vector_conversions
)
2337 return convertible_lax
;
2339 if (TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
)
2340 && lang_hooks
.types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
2343 if (emit_lax_note
&& !emitted_lax_note
)
2345 emitted_lax_note
= true;
2346 inform (input_location
, "use -flax-vector-conversions to permit "
2347 "conversions between vectors with differing "
2348 "element types or numbers of subparts");
2354 /* Build a VEC_PERM_EXPR if V0, V1 and MASK are not error_mark_nodes
2355 and have vector types, V0 has the same type as V1, and the number of
2356 elements of V0, V1, MASK is the same.
2358 In case V1 is a NULL_TREE it is assumed that __builtin_shuffle was
2359 called with two arguments. In this case implementation passes the
2360 first argument twice in order to share the same tree code. This fact
2361 could enable the mask-values being twice the vector length. This is
2362 an implementation accident and this semantics is not guaranteed to
2365 c_build_vec_perm_expr (location_t loc
, tree v0
, tree v1
, tree mask
,
2370 bool maybe_const
= false;
2371 bool two_arguments
= false;
2373 if (v1
== NULL_TREE
)
2375 two_arguments
= true;
2379 if (v0
== error_mark_node
|| v1
== error_mark_node
2380 || mask
== error_mark_node
)
2381 return error_mark_node
;
2383 if (TREE_CODE (TREE_TYPE (mask
)) != VECTOR_TYPE
2384 || TREE_CODE (TREE_TYPE (TREE_TYPE (mask
))) != INTEGER_TYPE
)
2387 error_at (loc
, "__builtin_shuffle last argument must "
2388 "be an integer vector");
2389 return error_mark_node
;
2392 if (TREE_CODE (TREE_TYPE (v0
)) != VECTOR_TYPE
2393 || TREE_CODE (TREE_TYPE (v1
)) != VECTOR_TYPE
)
2396 error_at (loc
, "__builtin_shuffle arguments must be vectors");
2397 return error_mark_node
;
2400 if (TYPE_MAIN_VARIANT (TREE_TYPE (v0
)) != TYPE_MAIN_VARIANT (TREE_TYPE (v1
)))
2403 error_at (loc
, "__builtin_shuffle argument vectors must be of "
2405 return error_mark_node
;
2408 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (v0
))
2409 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
))
2410 && TYPE_VECTOR_SUBPARTS (TREE_TYPE (v1
))
2411 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
)))
2414 error_at (loc
, "__builtin_shuffle number of elements of the "
2415 "argument vector(s) and the mask vector should "
2417 return error_mark_node
;
2420 if (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (v0
))))
2421 != GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (mask
)))))
2424 error_at (loc
, "__builtin_shuffle argument vector(s) inner type "
2425 "must have the same size as inner type of the mask");
2426 return error_mark_node
;
2429 if (!c_dialect_cxx ())
2431 /* Avoid C_MAYBE_CONST_EXPRs inside VEC_PERM_EXPR. */
2432 v0
= c_fully_fold (v0
, false, &maybe_const
);
2433 wrap
&= maybe_const
;
2436 v1
= v0
= save_expr (v0
);
2439 v1
= c_fully_fold (v1
, false, &maybe_const
);
2440 wrap
&= maybe_const
;
2443 mask
= c_fully_fold (mask
, false, &maybe_const
);
2444 wrap
&= maybe_const
;
2446 else if (two_arguments
)
2447 v1
= v0
= save_expr (v0
);
2449 ret
= build3_loc (loc
, VEC_PERM_EXPR
, TREE_TYPE (v0
), v0
, v1
, mask
);
2451 if (!c_dialect_cxx () && !wrap
)
2452 ret
= c_wrap_maybe_const (ret
, true);
2457 /* Like tree.c:get_narrower, but retain conversion from C++0x scoped enum
2458 to integral type. */
2461 c_common_get_narrower (tree op
, int *unsignedp_ptr
)
2463 op
= get_narrower (op
, unsignedp_ptr
);
2465 if (TREE_CODE (TREE_TYPE (op
)) == ENUMERAL_TYPE
2466 && ENUM_IS_SCOPED (TREE_TYPE (op
)))
2468 /* C++0x scoped enumerations don't implicitly convert to integral
2469 type; if we stripped an explicit conversion to a larger type we
2470 need to replace it so common_type will still work. */
2471 tree type
= c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op
)),
2472 TYPE_UNSIGNED (TREE_TYPE (op
)));
2473 op
= fold_convert (type
, op
);
2478 /* This is a helper function of build_binary_op.
2480 For certain operations if both args were extended from the same
2481 smaller type, do the arithmetic in that type and then extend.
2483 BITWISE indicates a bitwise operation.
2484 For them, this optimization is safe only if
2485 both args are zero-extended or both are sign-extended.
2486 Otherwise, we might change the result.
2487 Eg, (short)-1 | (unsigned short)-1 is (int)-1
2488 but calculated in (unsigned short) it would be (unsigned short)-1.
2491 shorten_binary_op (tree result_type
, tree op0
, tree op1
, bool bitwise
)
2493 int unsigned0
, unsigned1
;
2498 /* Cast OP0 and OP1 to RESULT_TYPE. Doing so prevents
2499 excessive narrowing when we call get_narrower below. For
2500 example, suppose that OP0 is of unsigned int extended
2501 from signed char and that RESULT_TYPE is long long int.
2502 If we explicitly cast OP0 to RESULT_TYPE, OP0 would look
2505 (long long int) (unsigned int) signed_char
2507 which get_narrower would narrow down to
2509 (unsigned int) signed char
2511 If we do not cast OP0 first, get_narrower would return
2512 signed_char, which is inconsistent with the case of the
2514 op0
= convert (result_type
, op0
);
2515 op1
= convert (result_type
, op1
);
2517 arg0
= c_common_get_narrower (op0
, &unsigned0
);
2518 arg1
= c_common_get_narrower (op1
, &unsigned1
);
2520 /* UNS is 1 if the operation to be done is an unsigned one. */
2521 uns
= TYPE_UNSIGNED (result_type
);
2523 /* Handle the case that OP0 (or OP1) does not *contain* a conversion
2524 but it *requires* conversion to FINAL_TYPE. */
2526 if ((TYPE_PRECISION (TREE_TYPE (op0
))
2527 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2528 && TREE_TYPE (op0
) != result_type
)
2529 unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2530 if ((TYPE_PRECISION (TREE_TYPE (op1
))
2531 == TYPE_PRECISION (TREE_TYPE (arg1
)))
2532 && TREE_TYPE (op1
) != result_type
)
2533 unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2535 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
2537 /* For bitwise operations, signedness of nominal type
2538 does not matter. Consider only how operands were extended. */
2542 /* Note that in all three cases below we refrain from optimizing
2543 an unsigned operation on sign-extended args.
2544 That would not be valid. */
2546 /* Both args variable: if both extended in same way
2547 from same width, do it in that width.
2548 Do it unsigned if args were zero-extended. */
2549 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
2550 < TYPE_PRECISION (result_type
))
2551 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2552 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2553 && unsigned0
== unsigned1
2554 && (unsigned0
|| !uns
))
2555 return c_common_signed_or_unsigned_type
2556 (unsigned0
, common_type (TREE_TYPE (arg0
), TREE_TYPE (arg1
)));
2558 else if (TREE_CODE (arg0
) == INTEGER_CST
2559 && (unsigned1
|| !uns
)
2560 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2561 < TYPE_PRECISION (result_type
))
2563 = c_common_signed_or_unsigned_type (unsigned1
,
2565 && !POINTER_TYPE_P (type
)
2566 && int_fits_type_p (arg0
, type
))
2569 else if (TREE_CODE (arg1
) == INTEGER_CST
2570 && (unsigned0
|| !uns
)
2571 && (TYPE_PRECISION (TREE_TYPE (arg0
))
2572 < TYPE_PRECISION (result_type
))
2574 = c_common_signed_or_unsigned_type (unsigned0
,
2576 && !POINTER_TYPE_P (type
)
2577 && int_fits_type_p (arg1
, type
))
2583 /* Checks if expression EXPR of real/integer type cannot be converted
2584 to the real/integer type TYPE. Function returns non-zero when:
2585 * EXPR is a constant which cannot be exactly converted to TYPE.
2586 * EXPR is not a constant and size of EXPR's type > than size of TYPE,
2587 for EXPR type and TYPE being both integers or both real.
2588 * EXPR is not a constant of real type and TYPE is an integer.
2589 * EXPR is not a constant of integer type which cannot be
2590 exactly converted to real type.
2591 Function allows conversions between types of different signedness and
2592 can return SAFE_CONVERSION (zero) in that case. Function can produce
2593 signedness warnings if PRODUCE_WARNS is true. */
2595 enum conversion_safety
2596 unsafe_conversion_p (location_t loc
, tree type
, tree expr
, bool produce_warns
)
2598 enum conversion_safety give_warning
= SAFE_CONVERSION
; /* is 0 or false */
2599 tree expr_type
= TREE_TYPE (expr
);
2600 loc
= expansion_point_location_if_in_system_header (loc
);
2602 if (TREE_CODE (expr
) == REAL_CST
|| TREE_CODE (expr
) == INTEGER_CST
)
2604 /* Warn for real constant that is not an exact integer converted
2606 if (TREE_CODE (expr_type
) == REAL_TYPE
2607 && TREE_CODE (type
) == INTEGER_TYPE
)
2609 if (!real_isinteger (TREE_REAL_CST_PTR (expr
), TYPE_MODE (expr_type
)))
2610 give_warning
= UNSAFE_REAL
;
2612 /* Warn for an integer constant that does not fit into integer type. */
2613 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2614 && TREE_CODE (type
) == INTEGER_TYPE
2615 && !int_fits_type_p (expr
, type
))
2617 if (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)
2618 && tree_int_cst_sgn (expr
) < 0)
2621 warning_at (loc
, OPT_Wsign_conversion
, "negative integer"
2622 " implicitly converted to unsigned type");
2624 else if (!TYPE_UNSIGNED (type
) && TYPE_UNSIGNED (expr_type
))
2627 warning_at (loc
, OPT_Wsign_conversion
, "conversion of unsigned"
2628 " constant value to negative integer");
2631 give_warning
= UNSAFE_OTHER
;
2633 else if (TREE_CODE (type
) == REAL_TYPE
)
2635 /* Warn for an integer constant that does not fit into real type. */
2636 if (TREE_CODE (expr_type
) == INTEGER_TYPE
)
2638 REAL_VALUE_TYPE a
= real_value_from_int_cst (0, expr
);
2639 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2640 give_warning
= UNSAFE_REAL
;
2642 /* Warn for a real constant that does not fit into a smaller
2644 else if (TREE_CODE (expr_type
) == REAL_TYPE
2645 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2647 REAL_VALUE_TYPE a
= TREE_REAL_CST (expr
);
2648 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2649 give_warning
= UNSAFE_REAL
;
2655 /* Warn for real types converted to integer types. */
2656 if (TREE_CODE (expr_type
) == REAL_TYPE
2657 && TREE_CODE (type
) == INTEGER_TYPE
)
2658 give_warning
= UNSAFE_REAL
;
2660 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2661 && TREE_CODE (type
) == INTEGER_TYPE
)
2663 /* Don't warn about unsigned char y = 0xff, x = (int) y; */
2664 expr
= get_unwidened (expr
, 0);
2665 expr_type
= TREE_TYPE (expr
);
2667 /* Don't warn for short y; short x = ((int)y & 0xff); */
2668 if (TREE_CODE (expr
) == BIT_AND_EXPR
2669 || TREE_CODE (expr
) == BIT_IOR_EXPR
2670 || TREE_CODE (expr
) == BIT_XOR_EXPR
)
2672 /* If both args were extended from a shortest type,
2673 use that type if that is safe. */
2674 expr_type
= shorten_binary_op (expr_type
,
2675 TREE_OPERAND (expr
, 0),
2676 TREE_OPERAND (expr
, 1),
2679 if (TREE_CODE (expr
) == BIT_AND_EXPR
)
2681 tree op0
= TREE_OPERAND (expr
, 0);
2682 tree op1
= TREE_OPERAND (expr
, 1);
2683 bool unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2684 bool unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2686 /* If one of the operands is a non-negative constant
2687 that fits in the target type, then the type of the
2688 other operand does not matter. */
2689 if ((TREE_CODE (op0
) == INTEGER_CST
2690 && int_fits_type_p (op0
, c_common_signed_type (type
))
2691 && int_fits_type_p (op0
, c_common_unsigned_type (type
)))
2692 || (TREE_CODE (op1
) == INTEGER_CST
2693 && int_fits_type_p (op1
, c_common_signed_type (type
))
2694 && int_fits_type_p (op1
,
2695 c_common_unsigned_type (type
))))
2696 return SAFE_CONVERSION
;
2697 /* If constant is unsigned and fits in the target
2698 type, then the result will also fit. */
2699 else if ((TREE_CODE (op0
) == INTEGER_CST
2701 && int_fits_type_p (op0
, type
))
2702 || (TREE_CODE (op1
) == INTEGER_CST
2704 && int_fits_type_p (op1
, type
)))
2705 return SAFE_CONVERSION
;
2708 /* Warn for integer types converted to smaller integer types. */
2709 if (TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2710 give_warning
= UNSAFE_OTHER
;
2712 /* When they are the same width but different signedness,
2713 then the value may change. */
2714 else if (((TYPE_PRECISION (type
) == TYPE_PRECISION (expr_type
)
2715 && TYPE_UNSIGNED (expr_type
) != TYPE_UNSIGNED (type
))
2716 /* Even when converted to a bigger type, if the type is
2717 unsigned but expr is signed, then negative values
2719 || (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)))
2721 warning_at (loc
, OPT_Wsign_conversion
, "conversion to %qT from %qT "
2722 "may change the sign of the result",
2726 /* Warn for integer types converted to real types if and only if
2727 all the range of values of the integer type cannot be
2728 represented by the real type. */
2729 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2730 && TREE_CODE (type
) == REAL_TYPE
)
2732 tree type_low_bound
, type_high_bound
;
2733 REAL_VALUE_TYPE real_low_bound
, real_high_bound
;
2735 /* Don't warn about char y = 0xff; float x = (int) y; */
2736 expr
= get_unwidened (expr
, 0);
2737 expr_type
= TREE_TYPE (expr
);
2739 type_low_bound
= TYPE_MIN_VALUE (expr_type
);
2740 type_high_bound
= TYPE_MAX_VALUE (expr_type
);
2741 real_low_bound
= real_value_from_int_cst (0, type_low_bound
);
2742 real_high_bound
= real_value_from_int_cst (0, type_high_bound
);
2744 if (!exact_real_truncate (TYPE_MODE (type
), &real_low_bound
)
2745 || !exact_real_truncate (TYPE_MODE (type
), &real_high_bound
))
2746 give_warning
= UNSAFE_OTHER
;
2749 /* Warn for real types converted to smaller real types. */
2750 else if (TREE_CODE (expr_type
) == REAL_TYPE
2751 && TREE_CODE (type
) == REAL_TYPE
2752 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2753 give_warning
= UNSAFE_REAL
;
2756 return give_warning
;
2759 /* Warns if the conversion of EXPR to TYPE may alter a value.
2760 This is a helper function for warnings_for_convert_and_check. */
2763 conversion_warning (location_t loc
, tree type
, tree expr
)
2765 tree expr_type
= TREE_TYPE (expr
);
2766 enum conversion_safety conversion_kind
;
2768 if (!warn_conversion
&& !warn_sign_conversion
&& !warn_float_conversion
)
2771 /* This may happen, because for LHS op= RHS we preevaluate
2772 RHS and create C_MAYBE_CONST_EXPR <SAVE_EXPR <RHS>>, which
2773 means we could no longer see the code of the EXPR. */
2774 if (TREE_CODE (expr
) == C_MAYBE_CONST_EXPR
)
2775 expr
= C_MAYBE_CONST_EXPR_EXPR (expr
);
2776 if (TREE_CODE (expr
) == SAVE_EXPR
)
2777 expr
= TREE_OPERAND (expr
, 0);
2779 switch (TREE_CODE (expr
))
2787 case TRUTH_ANDIF_EXPR
:
2788 case TRUTH_ORIF_EXPR
:
2789 case TRUTH_AND_EXPR
:
2791 case TRUTH_XOR_EXPR
:
2792 case TRUTH_NOT_EXPR
:
2793 /* Conversion from boolean to a signed:1 bit-field (which only
2794 can hold the values 0 and -1) doesn't lose information - but
2795 it does change the value. */
2796 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
2797 warning_at (loc
, OPT_Wconversion
,
2798 "conversion to %qT from boolean expression", type
);
2803 conversion_kind
= unsafe_conversion_p (loc
, type
, expr
, true);
2804 if (conversion_kind
== UNSAFE_REAL
)
2805 warning_at (loc
, OPT_Wfloat_conversion
,
2806 "conversion to %qT alters %qT constant value",
2808 else if (conversion_kind
)
2809 warning_at (loc
, OPT_Wconversion
,
2810 "conversion to %qT alters %qT constant value",
2816 /* In case of COND_EXPR, we do not care about the type of
2817 COND_EXPR, only about the conversion of each operand. */
2818 tree op1
= TREE_OPERAND (expr
, 1);
2819 tree op2
= TREE_OPERAND (expr
, 2);
2821 conversion_warning (loc
, type
, op1
);
2822 conversion_warning (loc
, type
, op2
);
2826 default: /* 'expr' is not a constant. */
2827 conversion_kind
= unsafe_conversion_p (loc
, type
, expr
, true);
2828 if (conversion_kind
== UNSAFE_REAL
)
2829 warning_at (loc
, OPT_Wfloat_conversion
,
2830 "conversion to %qT from %qT may alter its value",
2832 else if (conversion_kind
)
2833 warning_at (loc
, OPT_Wconversion
,
2834 "conversion to %qT from %qT may alter its value",
2839 /* Produce warnings after a conversion. RESULT is the result of
2840 converting EXPR to TYPE. This is a helper function for
2841 convert_and_check and cp_convert_and_check. */
2844 warnings_for_convert_and_check (location_t loc
, tree type
, tree expr
,
2847 loc
= expansion_point_location_if_in_system_header (loc
);
2849 if (TREE_CODE (expr
) == INTEGER_CST
2850 && (TREE_CODE (type
) == INTEGER_TYPE
2851 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2852 && !int_fits_type_p (expr
, type
))
2854 /* Do not diagnose overflow in a constant expression merely
2855 because a conversion overflowed. */
2856 if (TREE_OVERFLOW (result
))
2857 TREE_OVERFLOW (result
) = TREE_OVERFLOW (expr
);
2859 if (TYPE_UNSIGNED (type
))
2861 /* This detects cases like converting -129 or 256 to
2863 if (!int_fits_type_p (expr
, c_common_signed_type (type
)))
2864 warning_at (loc
, OPT_Woverflow
,
2865 "large integer implicitly truncated to unsigned type");
2867 conversion_warning (loc
, type
, expr
);
2869 else if (!int_fits_type_p (expr
, c_common_unsigned_type (type
)))
2870 warning_at (loc
, OPT_Woverflow
,
2871 "overflow in implicit constant conversion");
2872 /* No warning for converting 0x80000000 to int. */
2874 && (TREE_CODE (TREE_TYPE (expr
)) != INTEGER_TYPE
2875 || TYPE_PRECISION (TREE_TYPE (expr
))
2876 != TYPE_PRECISION (type
)))
2877 warning_at (loc
, OPT_Woverflow
,
2878 "overflow in implicit constant conversion");
2881 conversion_warning (loc
, type
, expr
);
2883 else if ((TREE_CODE (result
) == INTEGER_CST
2884 || TREE_CODE (result
) == FIXED_CST
) && TREE_OVERFLOW (result
))
2885 warning_at (loc
, OPT_Woverflow
,
2886 "overflow in implicit constant conversion");
2888 conversion_warning (loc
, type
, expr
);
2892 /* Convert EXPR to TYPE, warning about conversion problems with constants.
2893 Invoke this function on every expression that is converted implicitly,
2894 i.e. because of language rules and not because of an explicit cast. */
2897 convert_and_check (location_t loc
, tree type
, tree expr
)
2900 tree expr_for_warning
;
2902 /* Convert from a value with possible excess precision rather than
2903 via the semantic type, but do not warn about values not fitting
2904 exactly in the semantic type. */
2905 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
2907 tree orig_type
= TREE_TYPE (expr
);
2908 expr
= TREE_OPERAND (expr
, 0);
2909 expr_for_warning
= convert (orig_type
, expr
);
2910 if (orig_type
== type
)
2911 return expr_for_warning
;
2914 expr_for_warning
= expr
;
2916 if (TREE_TYPE (expr
) == type
)
2919 result
= convert (type
, expr
);
2921 if (c_inhibit_evaluation_warnings
== 0
2922 && !TREE_OVERFLOW_P (expr
)
2923 && result
!= error_mark_node
)
2924 warnings_for_convert_and_check (loc
, type
, expr_for_warning
, result
);
2929 /* A node in a list that describes references to variables (EXPR), which are
2930 either read accesses if WRITER is zero, or write accesses, in which case
2931 WRITER is the parent of EXPR. */
2938 /* Used to implement a cache the results of a call to verify_tree. We only
2939 use this for SAVE_EXPRs. */
2942 struct tlist_cache
*next
;
2943 struct tlist
*cache_before_sp
;
2944 struct tlist
*cache_after_sp
;
2948 /* Obstack to use when allocating tlist structures, and corresponding
2950 static struct obstack tlist_obstack
;
2951 static char *tlist_firstobj
= 0;
2953 /* Keep track of the identifiers we've warned about, so we can avoid duplicate
2955 static struct tlist
*warned_ids
;
2956 /* SAVE_EXPRs need special treatment. We process them only once and then
2957 cache the results. */
2958 static struct tlist_cache
*save_expr_cache
;
2960 static void add_tlist (struct tlist
**, struct tlist
*, tree
, int);
2961 static void merge_tlist (struct tlist
**, struct tlist
*, int);
2962 static void verify_tree (tree
, struct tlist
**, struct tlist
**, tree
);
2963 static int warning_candidate_p (tree
);
2964 static bool candidate_equal_p (const_tree
, const_tree
);
2965 static void warn_for_collisions (struct tlist
*);
2966 static void warn_for_collisions_1 (tree
, tree
, struct tlist
*, int);
2967 static struct tlist
*new_tlist (struct tlist
*, tree
, tree
);
2969 /* Create a new struct tlist and fill in its fields. */
2970 static struct tlist
*
2971 new_tlist (struct tlist
*next
, tree t
, tree writer
)
2974 l
= XOBNEW (&tlist_obstack
, struct tlist
);
2981 /* Add duplicates of the nodes found in ADD to the list *TO. If EXCLUDE_WRITER
2982 is nonnull, we ignore any node we find which has a writer equal to it. */
2985 add_tlist (struct tlist
**to
, struct tlist
*add
, tree exclude_writer
, int copy
)
2989 struct tlist
*next
= add
->next
;
2992 if (!exclude_writer
|| !candidate_equal_p (add
->writer
, exclude_writer
))
2993 *to
= copy
? new_tlist (*to
, add
->expr
, add
->writer
) : add
;
2998 /* Merge the nodes of ADD into TO. This merging process is done so that for
2999 each variable that already exists in TO, no new node is added; however if
3000 there is a write access recorded in ADD, and an occurrence on TO is only
3001 a read access, then the occurrence in TO will be modified to record the
3005 merge_tlist (struct tlist
**to
, struct tlist
*add
, int copy
)
3007 struct tlist
**end
= to
;
3010 end
= &(*end
)->next
;
3016 struct tlist
*next
= add
->next
;
3018 for (tmp2
= *to
; tmp2
; tmp2
= tmp2
->next
)
3019 if (candidate_equal_p (tmp2
->expr
, add
->expr
))
3023 tmp2
->writer
= add
->writer
;
3027 *end
= copy
? new_tlist (NULL
, add
->expr
, add
->writer
) : add
;
3028 end
= &(*end
)->next
;
3035 /* WRITTEN is a variable, WRITER is its parent. Warn if any of the variable
3036 references in list LIST conflict with it, excluding reads if ONLY writers
3040 warn_for_collisions_1 (tree written
, tree writer
, struct tlist
*list
,
3045 /* Avoid duplicate warnings. */
3046 for (tmp
= warned_ids
; tmp
; tmp
= tmp
->next
)
3047 if (candidate_equal_p (tmp
->expr
, written
))
3052 if (candidate_equal_p (list
->expr
, written
)
3053 && !candidate_equal_p (list
->writer
, writer
)
3054 && (!only_writes
|| list
->writer
))
3056 warned_ids
= new_tlist (warned_ids
, written
, NULL_TREE
);
3057 warning_at (EXPR_LOC_OR_LOC (writer
, input_location
),
3058 OPT_Wsequence_point
, "operation on %qE may be undefined",
3065 /* Given a list LIST of references to variables, find whether any of these
3066 can cause conflicts due to missing sequence points. */
3069 warn_for_collisions (struct tlist
*list
)
3073 for (tmp
= list
; tmp
; tmp
= tmp
->next
)
3076 warn_for_collisions_1 (tmp
->expr
, tmp
->writer
, list
, 0);
3080 /* Return nonzero if X is a tree that can be verified by the sequence point
3083 warning_candidate_p (tree x
)
3085 if (DECL_P (x
) && DECL_ARTIFICIAL (x
))
3088 if (TREE_CODE (x
) == BLOCK
)
3091 /* VOID_TYPE_P (TREE_TYPE (x)) is workaround for cp/tree.c
3092 (lvalue_p) crash on TRY/CATCH. */
3093 if (TREE_TYPE (x
) == NULL_TREE
|| VOID_TYPE_P (TREE_TYPE (x
)))
3099 /* No point to track non-const calls, they will never satisfy
3101 if (TREE_CODE (x
) == CALL_EXPR
&& (call_expr_flags (x
) & ECF_CONST
) == 0)
3104 if (TREE_CODE (x
) == STRING_CST
)
3110 /* Return nonzero if X and Y appear to be the same candidate (or NULL) */
3112 candidate_equal_p (const_tree x
, const_tree y
)
3114 return (x
== y
) || (x
&& y
&& operand_equal_p (x
, y
, 0));
3117 /* Walk the tree X, and record accesses to variables. If X is written by the
3118 parent tree, WRITER is the parent.
3119 We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP. If this
3120 expression or its only operand forces a sequence point, then everything up
3121 to the sequence point is stored in PBEFORE_SP. Everything else gets stored
3123 Once we return, we will have emitted warnings if any subexpression before
3124 such a sequence point could be undefined. On a higher level, however, the
3125 sequence point may not be relevant, and we'll merge the two lists.
3127 Example: (b++, a) + b;
3128 The call that processes the COMPOUND_EXPR will store the increment of B
3129 in PBEFORE_SP, and the use of A in PNO_SP. The higher-level call that
3130 processes the PLUS_EXPR will need to merge the two lists so that
3131 eventually, all accesses end up on the same list (and we'll warn about the
3132 unordered subexpressions b++ and b.
3134 A note on merging. If we modify the former example so that our expression
3137 care must be taken not simply to add all three expressions into the final
3138 PNO_SP list. The function merge_tlist takes care of that by merging the
3139 before-SP list of the COMPOUND_EXPR into its after-SP list in a special
3140 way, so that no more than one access to B is recorded. */
3143 verify_tree (tree x
, struct tlist
**pbefore_sp
, struct tlist
**pno_sp
,
3146 struct tlist
*tmp_before
, *tmp_nosp
, *tmp_list2
, *tmp_list3
;
3147 enum tree_code code
;
3148 enum tree_code_class cl
;
3150 /* X may be NULL if it is the operand of an empty statement expression
3156 code
= TREE_CODE (x
);
3157 cl
= TREE_CODE_CLASS (code
);
3159 if (warning_candidate_p (x
))
3160 *pno_sp
= new_tlist (*pno_sp
, x
, writer
);
3169 case TRUTH_ANDIF_EXPR
:
3170 case TRUTH_ORIF_EXPR
:
3171 tmp_before
= tmp_nosp
= tmp_list3
= 0;
3172 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3173 warn_for_collisions (tmp_nosp
);
3174 merge_tlist (pbefore_sp
, tmp_before
, 0);
3175 merge_tlist (pbefore_sp
, tmp_nosp
, 0);
3176 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, pno_sp
, NULL_TREE
);
3177 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3181 tmp_before
= tmp_list2
= 0;
3182 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_list2
, NULL_TREE
);
3183 warn_for_collisions (tmp_list2
);
3184 merge_tlist (pbefore_sp
, tmp_before
, 0);
3185 merge_tlist (pbefore_sp
, tmp_list2
, 0);
3187 tmp_list3
= tmp_nosp
= 0;
3188 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, &tmp_nosp
, NULL_TREE
);
3189 warn_for_collisions (tmp_nosp
);
3190 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3192 tmp_list3
= tmp_list2
= 0;
3193 verify_tree (TREE_OPERAND (x
, 2), &tmp_list3
, &tmp_list2
, NULL_TREE
);
3194 warn_for_collisions (tmp_list2
);
3195 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3196 /* Rather than add both tmp_nosp and tmp_list2, we have to merge the
3197 two first, to avoid warning for (a ? b++ : b++). */
3198 merge_tlist (&tmp_nosp
, tmp_list2
, 0);
3199 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3202 case PREDECREMENT_EXPR
:
3203 case PREINCREMENT_EXPR
:
3204 case POSTDECREMENT_EXPR
:
3205 case POSTINCREMENT_EXPR
:
3206 verify_tree (TREE_OPERAND (x
, 0), pno_sp
, pno_sp
, x
);
3210 tmp_before
= tmp_nosp
= tmp_list3
= 0;
3211 verify_tree (TREE_OPERAND (x
, 1), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3212 verify_tree (TREE_OPERAND (x
, 0), &tmp_list3
, &tmp_list3
, x
);
3213 /* Expressions inside the LHS are not ordered wrt. the sequence points
3214 in the RHS. Example:
3216 Despite the fact that the modification of "a" is in the before_sp
3217 list (tmp_before), it conflicts with the use of "a" in the LHS.
3218 We can handle this by adding the contents of tmp_list3
3219 to those of tmp_before, and redoing the collision warnings for that
3221 add_tlist (&tmp_before
, tmp_list3
, x
, 1);
3222 warn_for_collisions (tmp_before
);
3223 /* Exclude the LHS itself here; we first have to merge it into the
3224 tmp_nosp list. This is done to avoid warning for "a = a"; if we
3225 didn't exclude the LHS, we'd get it twice, once as a read and once
3227 add_tlist (pno_sp
, tmp_list3
, x
, 0);
3228 warn_for_collisions_1 (TREE_OPERAND (x
, 0), x
, tmp_nosp
, 1);
3230 merge_tlist (pbefore_sp
, tmp_before
, 0);
3231 if (warning_candidate_p (TREE_OPERAND (x
, 0)))
3232 merge_tlist (&tmp_nosp
, new_tlist (NULL
, TREE_OPERAND (x
, 0), x
), 0);
3233 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 1);
3237 /* We need to warn about conflicts among arguments and conflicts between
3238 args and the function address. Side effects of the function address,
3239 however, are not ordered by the sequence point of the call. */
3241 call_expr_arg_iterator iter
;
3243 tmp_before
= tmp_nosp
= 0;
3244 verify_tree (CALL_EXPR_FN (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3245 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, x
)
3247 tmp_list2
= tmp_list3
= 0;
3248 verify_tree (arg
, &tmp_list2
, &tmp_list3
, NULL_TREE
);
3249 merge_tlist (&tmp_list3
, tmp_list2
, 0);
3250 add_tlist (&tmp_before
, tmp_list3
, NULL_TREE
, 0);
3252 add_tlist (&tmp_before
, tmp_nosp
, NULL_TREE
, 0);
3253 warn_for_collisions (tmp_before
);
3254 add_tlist (pbefore_sp
, tmp_before
, NULL_TREE
, 0);
3259 /* Scan all the list, e.g. indices of multi dimensional array. */
3262 tmp_before
= tmp_nosp
= 0;
3263 verify_tree (TREE_VALUE (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3264 merge_tlist (&tmp_nosp
, tmp_before
, 0);
3265 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3272 struct tlist_cache
*t
;
3273 for (t
= save_expr_cache
; t
; t
= t
->next
)
3274 if (candidate_equal_p (t
->expr
, x
))
3279 t
= XOBNEW (&tlist_obstack
, struct tlist_cache
);
3280 t
->next
= save_expr_cache
;
3282 save_expr_cache
= t
;
3284 tmp_before
= tmp_nosp
= 0;
3285 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3286 warn_for_collisions (tmp_nosp
);
3289 merge_tlist (&tmp_list3
, tmp_nosp
, 0);
3290 t
->cache_before_sp
= tmp_before
;
3291 t
->cache_after_sp
= tmp_list3
;
3293 merge_tlist (pbefore_sp
, t
->cache_before_sp
, 1);
3294 add_tlist (pno_sp
, t
->cache_after_sp
, NULL_TREE
, 1);
3299 x
= TREE_OPERAND (x
, 0);
3306 /* For other expressions, simply recurse on their operands.
3307 Manual tail recursion for unary expressions.
3308 Other non-expressions need not be processed. */
3309 if (cl
== tcc_unary
)
3311 x
= TREE_OPERAND (x
, 0);
3315 else if (IS_EXPR_CODE_CLASS (cl
))
3318 int max
= TREE_OPERAND_LENGTH (x
);
3319 for (lp
= 0; lp
< max
; lp
++)
3321 tmp_before
= tmp_nosp
= 0;
3322 verify_tree (TREE_OPERAND (x
, lp
), &tmp_before
, &tmp_nosp
, 0);
3323 merge_tlist (&tmp_nosp
, tmp_before
, 0);
3324 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3331 /* Try to warn for undefined behavior in EXPR due to missing sequence
3335 verify_sequence_points (tree expr
)
3337 struct tlist
*before_sp
= 0, *after_sp
= 0;
3340 save_expr_cache
= 0;
3341 if (tlist_firstobj
== 0)
3343 gcc_obstack_init (&tlist_obstack
);
3344 tlist_firstobj
= (char *) obstack_alloc (&tlist_obstack
, 0);
3347 verify_tree (expr
, &before_sp
, &after_sp
, 0);
3348 warn_for_collisions (after_sp
);
3349 obstack_free (&tlist_obstack
, tlist_firstobj
);
3352 /* Validate the expression after `case' and apply default promotions. */
3355 check_case_value (tree value
)
3357 if (value
== NULL_TREE
)
3360 if (TREE_CODE (value
) == INTEGER_CST
)
3361 /* Promote char or short to int. */
3362 value
= perform_integral_promotions (value
);
3363 else if (value
!= error_mark_node
)
3365 error ("case label does not reduce to an integer constant");
3366 value
= error_mark_node
;
3369 constant_expression_warning (value
);
3374 /* See if the case values LOW and HIGH are in the range of the original
3375 type (i.e. before the default conversion to int) of the switch testing
3377 TYPE is the promoted type of the testing expression, and ORIG_TYPE is
3378 the type before promoting it. CASE_LOW_P is a pointer to the lower
3379 bound of the case label, and CASE_HIGH_P is the upper bound or NULL
3380 if the case is not a case range.
3381 The caller has to make sure that we are not called with NULL for
3382 CASE_LOW_P (i.e. the default case).
3383 Returns true if the case label is in range of ORIG_TYPE (saturated or
3384 untouched) or false if the label is out of range. */
3387 check_case_bounds (location_t loc
, tree type
, tree orig_type
,
3388 tree
*case_low_p
, tree
*case_high_p
)
3390 tree min_value
, max_value
;
3391 tree case_low
= *case_low_p
;
3392 tree case_high
= case_high_p
? *case_high_p
: case_low
;
3394 /* If there was a problem with the original type, do nothing. */
3395 if (orig_type
== error_mark_node
)
3398 min_value
= TYPE_MIN_VALUE (orig_type
);
3399 max_value
= TYPE_MAX_VALUE (orig_type
);
3401 /* Case label is less than minimum for type. */
3402 if (tree_int_cst_compare (case_low
, min_value
) < 0
3403 && tree_int_cst_compare (case_high
, min_value
) < 0)
3405 warning_at (loc
, 0, "case label value is less than minimum value "
3410 /* Case value is greater than maximum for type. */
3411 if (tree_int_cst_compare (case_low
, max_value
) > 0
3412 && tree_int_cst_compare (case_high
, max_value
) > 0)
3414 warning_at (loc
, 0, "case label value exceeds maximum value for type");
3418 /* Saturate lower case label value to minimum. */
3419 if (tree_int_cst_compare (case_high
, min_value
) >= 0
3420 && tree_int_cst_compare (case_low
, min_value
) < 0)
3422 warning_at (loc
, 0, "lower value in case label range"
3423 " less than minimum value for type");
3424 case_low
= min_value
;
3427 /* Saturate upper case label value to maximum. */
3428 if (tree_int_cst_compare (case_low
, max_value
) <= 0
3429 && tree_int_cst_compare (case_high
, max_value
) > 0)
3431 warning_at (loc
, 0, "upper value in case label range"
3432 " exceeds maximum value for type");
3433 case_high
= max_value
;
3436 if (*case_low_p
!= case_low
)
3437 *case_low_p
= convert (type
, case_low
);
3438 if (case_high_p
&& *case_high_p
!= case_high
)
3439 *case_high_p
= convert (type
, case_high
);
3444 /* Return an integer type with BITS bits of precision,
3445 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
3448 c_common_type_for_size (unsigned int bits
, int unsignedp
)
3450 if (bits
== TYPE_PRECISION (integer_type_node
))
3451 return unsignedp
? unsigned_type_node
: integer_type_node
;
3453 if (bits
== TYPE_PRECISION (signed_char_type_node
))
3454 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3456 if (bits
== TYPE_PRECISION (short_integer_type_node
))
3457 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3459 if (bits
== TYPE_PRECISION (long_integer_type_node
))
3460 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3462 if (bits
== TYPE_PRECISION (long_long_integer_type_node
))
3463 return (unsignedp
? long_long_unsigned_type_node
3464 : long_long_integer_type_node
);
3466 if (int128_integer_type_node
3467 && bits
== TYPE_PRECISION (int128_integer_type_node
))
3468 return (unsignedp
? int128_unsigned_type_node
3469 : int128_integer_type_node
);
3471 if (bits
== TYPE_PRECISION (widest_integer_literal_type_node
))
3472 return (unsignedp
? widest_unsigned_literal_type_node
3473 : widest_integer_literal_type_node
);
3475 if (bits
<= TYPE_PRECISION (intQI_type_node
))
3476 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3478 if (bits
<= TYPE_PRECISION (intHI_type_node
))
3479 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3481 if (bits
<= TYPE_PRECISION (intSI_type_node
))
3482 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3484 if (bits
<= TYPE_PRECISION (intDI_type_node
))
3485 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3490 /* Return a fixed-point type that has at least IBIT ibits and FBIT fbits
3491 that is unsigned if UNSIGNEDP is nonzero, otherwise signed;
3492 and saturating if SATP is nonzero, otherwise not saturating. */
3495 c_common_fixed_point_type_for_size (unsigned int ibit
, unsigned int fbit
,
3496 int unsignedp
, int satp
)
3498 enum machine_mode mode
;
3500 mode
= unsignedp
? UQQmode
: QQmode
;
3502 mode
= unsignedp
? UHAmode
: HAmode
;
3504 for (; mode
!= VOIDmode
; mode
= GET_MODE_WIDER_MODE (mode
))
3505 if (GET_MODE_IBIT (mode
) >= ibit
&& GET_MODE_FBIT (mode
) >= fbit
)
3508 if (mode
== VOIDmode
|| !targetm
.scalar_mode_supported_p (mode
))
3510 sorry ("GCC cannot support operators with integer types and "
3511 "fixed-point types that have too many integral and "
3512 "fractional bits together");
3516 return c_common_type_for_mode (mode
, satp
);
3519 /* Used for communication between c_common_type_for_mode and
3520 c_register_builtin_type. */
3521 tree registered_builtin_types
;
3523 /* Return a data type that has machine mode MODE.
3524 If the mode is an integer,
3525 then UNSIGNEDP selects between signed and unsigned types.
3526 If the mode is a fixed-point mode,
3527 then UNSIGNEDP selects between saturating and nonsaturating types. */
3530 c_common_type_for_mode (enum machine_mode mode
, int unsignedp
)
3534 if (mode
== TYPE_MODE (integer_type_node
))
3535 return unsignedp
? unsigned_type_node
: integer_type_node
;
3537 if (mode
== TYPE_MODE (signed_char_type_node
))
3538 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3540 if (mode
== TYPE_MODE (short_integer_type_node
))
3541 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3543 if (mode
== TYPE_MODE (long_integer_type_node
))
3544 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3546 if (mode
== TYPE_MODE (long_long_integer_type_node
))
3547 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3549 if (int128_integer_type_node
3550 && mode
== TYPE_MODE (int128_integer_type_node
))
3551 return unsignedp
? int128_unsigned_type_node
: int128_integer_type_node
;
3553 if (mode
== TYPE_MODE (widest_integer_literal_type_node
))
3554 return unsignedp
? widest_unsigned_literal_type_node
3555 : widest_integer_literal_type_node
;
3558 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3561 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3564 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3567 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3569 #if HOST_BITS_PER_WIDE_INT >= 64
3570 if (mode
== TYPE_MODE (intTI_type_node
))
3571 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3574 if (mode
== TYPE_MODE (float_type_node
))
3575 return float_type_node
;
3577 if (mode
== TYPE_MODE (double_type_node
))
3578 return double_type_node
;
3580 if (mode
== TYPE_MODE (long_double_type_node
))
3581 return long_double_type_node
;
3583 if (mode
== TYPE_MODE (void_type_node
))
3584 return void_type_node
;
3586 if (mode
== TYPE_MODE (build_pointer_type (char_type_node
)))
3588 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3589 : make_signed_type (GET_MODE_PRECISION (mode
)));
3591 if (mode
== TYPE_MODE (build_pointer_type (integer_type_node
)))
3593 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3594 : make_signed_type (GET_MODE_PRECISION (mode
)));
3596 if (COMPLEX_MODE_P (mode
))
3598 enum machine_mode inner_mode
;
3601 if (mode
== TYPE_MODE (complex_float_type_node
))
3602 return complex_float_type_node
;
3603 if (mode
== TYPE_MODE (complex_double_type_node
))
3604 return complex_double_type_node
;
3605 if (mode
== TYPE_MODE (complex_long_double_type_node
))
3606 return complex_long_double_type_node
;
3608 if (mode
== TYPE_MODE (complex_integer_type_node
) && !unsignedp
)
3609 return complex_integer_type_node
;
3611 inner_mode
= GET_MODE_INNER (mode
);
3612 inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3613 if (inner_type
!= NULL_TREE
)
3614 return build_complex_type (inner_type
);
3616 else if (VECTOR_MODE_P (mode
))
3618 enum machine_mode inner_mode
= GET_MODE_INNER (mode
);
3619 tree inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3620 if (inner_type
!= NULL_TREE
)
3621 return build_vector_type_for_mode (inner_type
, mode
);
3624 if (mode
== TYPE_MODE (dfloat32_type_node
))
3625 return dfloat32_type_node
;
3626 if (mode
== TYPE_MODE (dfloat64_type_node
))
3627 return dfloat64_type_node
;
3628 if (mode
== TYPE_MODE (dfloat128_type_node
))
3629 return dfloat128_type_node
;
3631 if (ALL_SCALAR_FIXED_POINT_MODE_P (mode
))
3633 if (mode
== TYPE_MODE (short_fract_type_node
))
3634 return unsignedp
? sat_short_fract_type_node
: short_fract_type_node
;
3635 if (mode
== TYPE_MODE (fract_type_node
))
3636 return unsignedp
? sat_fract_type_node
: fract_type_node
;
3637 if (mode
== TYPE_MODE (long_fract_type_node
))
3638 return unsignedp
? sat_long_fract_type_node
: long_fract_type_node
;
3639 if (mode
== TYPE_MODE (long_long_fract_type_node
))
3640 return unsignedp
? sat_long_long_fract_type_node
3641 : long_long_fract_type_node
;
3643 if (mode
== TYPE_MODE (unsigned_short_fract_type_node
))
3644 return unsignedp
? sat_unsigned_short_fract_type_node
3645 : unsigned_short_fract_type_node
;
3646 if (mode
== TYPE_MODE (unsigned_fract_type_node
))
3647 return unsignedp
? sat_unsigned_fract_type_node
3648 : unsigned_fract_type_node
;
3649 if (mode
== TYPE_MODE (unsigned_long_fract_type_node
))
3650 return unsignedp
? sat_unsigned_long_fract_type_node
3651 : unsigned_long_fract_type_node
;
3652 if (mode
== TYPE_MODE (unsigned_long_long_fract_type_node
))
3653 return unsignedp
? sat_unsigned_long_long_fract_type_node
3654 : unsigned_long_long_fract_type_node
;
3656 if (mode
== TYPE_MODE (short_accum_type_node
))
3657 return unsignedp
? sat_short_accum_type_node
: short_accum_type_node
;
3658 if (mode
== TYPE_MODE (accum_type_node
))
3659 return unsignedp
? sat_accum_type_node
: accum_type_node
;
3660 if (mode
== TYPE_MODE (long_accum_type_node
))
3661 return unsignedp
? sat_long_accum_type_node
: long_accum_type_node
;
3662 if (mode
== TYPE_MODE (long_long_accum_type_node
))
3663 return unsignedp
? sat_long_long_accum_type_node
3664 : long_long_accum_type_node
;
3666 if (mode
== TYPE_MODE (unsigned_short_accum_type_node
))
3667 return unsignedp
? sat_unsigned_short_accum_type_node
3668 : unsigned_short_accum_type_node
;
3669 if (mode
== TYPE_MODE (unsigned_accum_type_node
))
3670 return unsignedp
? sat_unsigned_accum_type_node
3671 : unsigned_accum_type_node
;
3672 if (mode
== TYPE_MODE (unsigned_long_accum_type_node
))
3673 return unsignedp
? sat_unsigned_long_accum_type_node
3674 : unsigned_long_accum_type_node
;
3675 if (mode
== TYPE_MODE (unsigned_long_long_accum_type_node
))
3676 return unsignedp
? sat_unsigned_long_long_accum_type_node
3677 : unsigned_long_long_accum_type_node
;
3680 return unsignedp
? sat_qq_type_node
: qq_type_node
;
3682 return unsignedp
? sat_hq_type_node
: hq_type_node
;
3684 return unsignedp
? sat_sq_type_node
: sq_type_node
;
3686 return unsignedp
? sat_dq_type_node
: dq_type_node
;
3688 return unsignedp
? sat_tq_type_node
: tq_type_node
;
3690 if (mode
== UQQmode
)
3691 return unsignedp
? sat_uqq_type_node
: uqq_type_node
;
3692 if (mode
== UHQmode
)
3693 return unsignedp
? sat_uhq_type_node
: uhq_type_node
;
3694 if (mode
== USQmode
)
3695 return unsignedp
? sat_usq_type_node
: usq_type_node
;
3696 if (mode
== UDQmode
)
3697 return unsignedp
? sat_udq_type_node
: udq_type_node
;
3698 if (mode
== UTQmode
)
3699 return unsignedp
? sat_utq_type_node
: utq_type_node
;
3702 return unsignedp
? sat_ha_type_node
: ha_type_node
;
3704 return unsignedp
? sat_sa_type_node
: sa_type_node
;
3706 return unsignedp
? sat_da_type_node
: da_type_node
;
3708 return unsignedp
? sat_ta_type_node
: ta_type_node
;
3710 if (mode
== UHAmode
)
3711 return unsignedp
? sat_uha_type_node
: uha_type_node
;
3712 if (mode
== USAmode
)
3713 return unsignedp
? sat_usa_type_node
: usa_type_node
;
3714 if (mode
== UDAmode
)
3715 return unsignedp
? sat_uda_type_node
: uda_type_node
;
3716 if (mode
== UTAmode
)
3717 return unsignedp
? sat_uta_type_node
: uta_type_node
;
3720 for (t
= registered_builtin_types
; t
; t
= TREE_CHAIN (t
))
3721 if (TYPE_MODE (TREE_VALUE (t
)) == mode
3722 && !!unsignedp
== !!TYPE_UNSIGNED (TREE_VALUE (t
)))
3723 return TREE_VALUE (t
);
3729 c_common_unsigned_type (tree type
)
3731 return c_common_signed_or_unsigned_type (1, type
);
3734 /* Return a signed type the same as TYPE in other respects. */
3737 c_common_signed_type (tree type
)
3739 return c_common_signed_or_unsigned_type (0, type
);
3742 /* Return a type the same as TYPE except unsigned or
3743 signed according to UNSIGNEDP. */
3746 c_common_signed_or_unsigned_type (int unsignedp
, tree type
)
3750 /* This block of code emulates the behavior of the old
3751 c_common_unsigned_type. In particular, it returns
3752 long_unsigned_type_node if passed a long, even when a int would
3753 have the same size. This is necessary for warnings to work
3754 correctly in archs where sizeof(int) == sizeof(long) */
3756 type1
= TYPE_MAIN_VARIANT (type
);
3757 if (type1
== signed_char_type_node
|| type1
== char_type_node
|| type1
== unsigned_char_type_node
)
3758 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3759 if (type1
== integer_type_node
|| type1
== unsigned_type_node
)
3760 return unsignedp
? unsigned_type_node
: integer_type_node
;
3761 if (type1
== short_integer_type_node
|| type1
== short_unsigned_type_node
)
3762 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3763 if (type1
== long_integer_type_node
|| type1
== long_unsigned_type_node
)
3764 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3765 if (type1
== long_long_integer_type_node
|| type1
== long_long_unsigned_type_node
)
3766 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3767 if (int128_integer_type_node
3768 && (type1
== int128_integer_type_node
3769 || type1
== int128_unsigned_type_node
))
3770 return unsignedp
? int128_unsigned_type_node
: int128_integer_type_node
;
3771 if (type1
== widest_integer_literal_type_node
|| type1
== widest_unsigned_literal_type_node
)
3772 return unsignedp
? widest_unsigned_literal_type_node
: widest_integer_literal_type_node
;
3773 #if HOST_BITS_PER_WIDE_INT >= 64
3774 if (type1
== intTI_type_node
|| type1
== unsigned_intTI_type_node
)
3775 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3777 if (type1
== intDI_type_node
|| type1
== unsigned_intDI_type_node
)
3778 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3779 if (type1
== intSI_type_node
|| type1
== unsigned_intSI_type_node
)
3780 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3781 if (type1
== intHI_type_node
|| type1
== unsigned_intHI_type_node
)
3782 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3783 if (type1
== intQI_type_node
|| type1
== unsigned_intQI_type_node
)
3784 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3786 #define C_COMMON_FIXED_TYPES(NAME) \
3787 if (type1 == short_ ## NAME ## _type_node \
3788 || type1 == unsigned_short_ ## NAME ## _type_node) \
3789 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
3790 : short_ ## NAME ## _type_node; \
3791 if (type1 == NAME ## _type_node \
3792 || type1 == unsigned_ ## NAME ## _type_node) \
3793 return unsignedp ? unsigned_ ## NAME ## _type_node \
3794 : NAME ## _type_node; \
3795 if (type1 == long_ ## NAME ## _type_node \
3796 || type1 == unsigned_long_ ## NAME ## _type_node) \
3797 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
3798 : long_ ## NAME ## _type_node; \
3799 if (type1 == long_long_ ## NAME ## _type_node \
3800 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
3801 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
3802 : long_long_ ## NAME ## _type_node;
3804 #define C_COMMON_FIXED_MODE_TYPES(NAME) \
3805 if (type1 == NAME ## _type_node \
3806 || type1 == u ## NAME ## _type_node) \
3807 return unsignedp ? u ## NAME ## _type_node \
3808 : NAME ## _type_node;
3810 #define C_COMMON_FIXED_TYPES_SAT(NAME) \
3811 if (type1 == sat_ ## short_ ## NAME ## _type_node \
3812 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
3813 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
3814 : sat_ ## short_ ## NAME ## _type_node; \
3815 if (type1 == sat_ ## NAME ## _type_node \
3816 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
3817 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
3818 : sat_ ## NAME ## _type_node; \
3819 if (type1 == sat_ ## long_ ## NAME ## _type_node \
3820 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
3821 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
3822 : sat_ ## long_ ## NAME ## _type_node; \
3823 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
3824 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
3825 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
3826 : sat_ ## long_long_ ## NAME ## _type_node;
3828 #define C_COMMON_FIXED_MODE_TYPES_SAT(NAME) \
3829 if (type1 == sat_ ## NAME ## _type_node \
3830 || type1 == sat_ ## u ## NAME ## _type_node) \
3831 return unsignedp ? sat_ ## u ## NAME ## _type_node \
3832 : sat_ ## NAME ## _type_node;
3834 C_COMMON_FIXED_TYPES (fract
);
3835 C_COMMON_FIXED_TYPES_SAT (fract
);
3836 C_COMMON_FIXED_TYPES (accum
);
3837 C_COMMON_FIXED_TYPES_SAT (accum
);
3839 C_COMMON_FIXED_MODE_TYPES (qq
);
3840 C_COMMON_FIXED_MODE_TYPES (hq
);
3841 C_COMMON_FIXED_MODE_TYPES (sq
);
3842 C_COMMON_FIXED_MODE_TYPES (dq
);
3843 C_COMMON_FIXED_MODE_TYPES (tq
);
3844 C_COMMON_FIXED_MODE_TYPES_SAT (qq
);
3845 C_COMMON_FIXED_MODE_TYPES_SAT (hq
);
3846 C_COMMON_FIXED_MODE_TYPES_SAT (sq
);
3847 C_COMMON_FIXED_MODE_TYPES_SAT (dq
);
3848 C_COMMON_FIXED_MODE_TYPES_SAT (tq
);
3849 C_COMMON_FIXED_MODE_TYPES (ha
);
3850 C_COMMON_FIXED_MODE_TYPES (sa
);
3851 C_COMMON_FIXED_MODE_TYPES (da
);
3852 C_COMMON_FIXED_MODE_TYPES (ta
);
3853 C_COMMON_FIXED_MODE_TYPES_SAT (ha
);
3854 C_COMMON_FIXED_MODE_TYPES_SAT (sa
);
3855 C_COMMON_FIXED_MODE_TYPES_SAT (da
);
3856 C_COMMON_FIXED_MODE_TYPES_SAT (ta
);
3858 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
3859 the precision; they have precision set to match their range, but
3860 may use a wider mode to match an ABI. If we change modes, we may
3861 wind up with bad conversions. For INTEGER_TYPEs in C, must check
3862 the precision as well, so as to yield correct results for
3863 bit-field types. C++ does not have these separate bit-field
3864 types, and producing a signed or unsigned variant of an
3865 ENUMERAL_TYPE may cause other problems as well. */
3867 if (!INTEGRAL_TYPE_P (type
)
3868 || TYPE_UNSIGNED (type
) == unsignedp
)
3871 #define TYPE_OK(node) \
3872 (TYPE_MODE (type) == TYPE_MODE (node) \
3873 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
3874 if (TYPE_OK (signed_char_type_node
))
3875 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3876 if (TYPE_OK (integer_type_node
))
3877 return unsignedp
? unsigned_type_node
: integer_type_node
;
3878 if (TYPE_OK (short_integer_type_node
))
3879 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3880 if (TYPE_OK (long_integer_type_node
))
3881 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3882 if (TYPE_OK (long_long_integer_type_node
))
3883 return (unsignedp
? long_long_unsigned_type_node
3884 : long_long_integer_type_node
);
3885 if (int128_integer_type_node
&& TYPE_OK (int128_integer_type_node
))
3886 return (unsignedp
? int128_unsigned_type_node
3887 : int128_integer_type_node
);
3888 if (TYPE_OK (widest_integer_literal_type_node
))
3889 return (unsignedp
? widest_unsigned_literal_type_node
3890 : widest_integer_literal_type_node
);
3892 #if HOST_BITS_PER_WIDE_INT >= 64
3893 if (TYPE_OK (intTI_type_node
))
3894 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3896 if (TYPE_OK (intDI_type_node
))
3897 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3898 if (TYPE_OK (intSI_type_node
))
3899 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3900 if (TYPE_OK (intHI_type_node
))
3901 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3902 if (TYPE_OK (intQI_type_node
))
3903 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3906 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
3909 /* Build a bit-field integer type for the given WIDTH and UNSIGNEDP. */
3912 c_build_bitfield_integer_type (unsigned HOST_WIDE_INT width
, int unsignedp
)
3914 /* Extended integer types of the same width as a standard type have
3915 lesser rank, so those of the same width as int promote to int or
3916 unsigned int and are valid for printf formats expecting int or
3917 unsigned int. To avoid such special cases, avoid creating
3918 extended integer types for bit-fields if a standard integer type
3920 if (width
== TYPE_PRECISION (integer_type_node
))
3921 return unsignedp
? unsigned_type_node
: integer_type_node
;
3922 if (width
== TYPE_PRECISION (signed_char_type_node
))
3923 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3924 if (width
== TYPE_PRECISION (short_integer_type_node
))
3925 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3926 if (width
== TYPE_PRECISION (long_integer_type_node
))
3927 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3928 if (width
== TYPE_PRECISION (long_long_integer_type_node
))
3929 return (unsignedp
? long_long_unsigned_type_node
3930 : long_long_integer_type_node
);
3931 if (int128_integer_type_node
3932 && width
== TYPE_PRECISION (int128_integer_type_node
))
3933 return (unsignedp
? int128_unsigned_type_node
3934 : int128_integer_type_node
);
3935 return build_nonstandard_integer_type (width
, unsignedp
);
3938 /* The C version of the register_builtin_type langhook. */
3941 c_register_builtin_type (tree type
, const char* name
)
3945 decl
= build_decl (UNKNOWN_LOCATION
,
3946 TYPE_DECL
, get_identifier (name
), type
);
3947 DECL_ARTIFICIAL (decl
) = 1;
3948 if (!TYPE_NAME (type
))
3949 TYPE_NAME (type
) = decl
;
3952 registered_builtin_types
= tree_cons (0, type
, registered_builtin_types
);
3955 /* Print an error message for invalid operands to arith operation
3956 CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
3957 LOCATION is the location of the message. */
3960 binary_op_error (location_t location
, enum tree_code code
,
3961 tree type0
, tree type1
)
3968 opname
= "+"; break;
3970 opname
= "-"; break;
3972 opname
= "*"; break;
3974 opname
= "max"; break;
3976 opname
= "min"; break;
3978 opname
= "=="; break;
3980 opname
= "!="; break;
3982 opname
= "<="; break;
3984 opname
= ">="; break;
3986 opname
= "<"; break;
3988 opname
= ">"; break;
3990 opname
= "<<"; break;
3992 opname
= ">>"; break;
3993 case TRUNC_MOD_EXPR
:
3994 case FLOOR_MOD_EXPR
:
3995 opname
= "%"; break;
3996 case TRUNC_DIV_EXPR
:
3997 case FLOOR_DIV_EXPR
:
3998 opname
= "/"; break;
4000 opname
= "&"; break;
4002 opname
= "|"; break;
4003 case TRUTH_ANDIF_EXPR
:
4004 opname
= "&&"; break;
4005 case TRUTH_ORIF_EXPR
:
4006 opname
= "||"; break;
4008 opname
= "^"; break;
4013 "invalid operands to binary %s (have %qT and %qT)", opname
,
4017 /* Given an expression as a tree, return its original type. Do this
4018 by stripping any conversion that preserves the sign and precision. */
4020 expr_original_type (tree expr
)
4022 STRIP_SIGN_NOPS (expr
);
4023 return TREE_TYPE (expr
);
4026 /* Subroutine of build_binary_op, used for comparison operations.
4027 See if the operands have both been converted from subword integer types
4028 and, if so, perhaps change them both back to their original type.
4029 This function is also responsible for converting the two operands
4030 to the proper common type for comparison.
4032 The arguments of this function are all pointers to local variables
4033 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
4034 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
4036 LOC is the location of the comparison.
4038 If this function returns nonzero, it means that the comparison has
4039 a constant value. What this function returns is an expression for
4043 shorten_compare (location_t loc
, tree
*op0_ptr
, tree
*op1_ptr
,
4044 tree
*restype_ptr
, enum tree_code
*rescode_ptr
)
4047 tree op0
= *op0_ptr
;
4048 tree op1
= *op1_ptr
;
4049 int unsignedp0
, unsignedp1
;
4051 tree primop0
, primop1
;
4052 enum tree_code code
= *rescode_ptr
;
4054 /* Throw away any conversions to wider types
4055 already present in the operands. */
4057 primop0
= c_common_get_narrower (op0
, &unsignedp0
);
4058 primop1
= c_common_get_narrower (op1
, &unsignedp1
);
4060 /* If primopN is first sign-extended from primopN's precision to opN's
4061 precision, then zero-extended from opN's precision to
4062 *restype_ptr precision, shortenings might be invalid. */
4063 if (TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (TREE_TYPE (op0
))
4064 && TYPE_PRECISION (TREE_TYPE (op0
)) < TYPE_PRECISION (*restype_ptr
)
4066 && TYPE_UNSIGNED (TREE_TYPE (op0
)))
4068 if (TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (TREE_TYPE (op1
))
4069 && TYPE_PRECISION (TREE_TYPE (op1
)) < TYPE_PRECISION (*restype_ptr
)
4071 && TYPE_UNSIGNED (TREE_TYPE (op1
)))
4074 /* Handle the case that OP0 does not *contain* a conversion
4075 but it *requires* conversion to FINAL_TYPE. */
4077 if (op0
== primop0
&& TREE_TYPE (op0
) != *restype_ptr
)
4078 unsignedp0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
4079 if (op1
== primop1
&& TREE_TYPE (op1
) != *restype_ptr
)
4080 unsignedp1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
4082 /* If one of the operands must be floated, we cannot optimize. */
4083 real1
= TREE_CODE (TREE_TYPE (primop0
)) == REAL_TYPE
;
4084 real2
= TREE_CODE (TREE_TYPE (primop1
)) == REAL_TYPE
;
4086 /* If first arg is constant, swap the args (changing operation
4087 so value is preserved), for canonicalization. Don't do this if
4088 the second arg is 0. */
4090 if (TREE_CONSTANT (primop0
)
4091 && !integer_zerop (primop1
) && !real_zerop (primop1
)
4092 && !fixed_zerop (primop1
))
4095 int temi
= unsignedp0
;
4103 unsignedp0
= unsignedp1
;
4126 *rescode_ptr
= code
;
4129 /* If comparing an integer against a constant more bits wide,
4130 maybe we can deduce a value of 1 or 0 independent of the data.
4131 Or else truncate the constant now
4132 rather than extend the variable at run time.
4134 This is only interesting if the constant is the wider arg.
4135 Also, it is not safe if the constant is unsigned and the
4136 variable arg is signed, since in this case the variable
4137 would be sign-extended and then regarded as unsigned.
4138 Our technique fails in this case because the lowest/highest
4139 possible unsigned results don't follow naturally from the
4140 lowest/highest possible values of the variable operand.
4141 For just EQ_EXPR and NE_EXPR there is another technique that
4142 could be used: see if the constant can be faithfully represented
4143 in the other operand's type, by truncating it and reextending it
4144 and see if that preserves the constant's value. */
4146 if (!real1
&& !real2
4147 && TREE_CODE (TREE_TYPE (primop0
)) != FIXED_POINT_TYPE
4148 && TREE_CODE (primop1
) == INTEGER_CST
4149 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
))
4151 int min_gt
, max_gt
, min_lt
, max_lt
;
4152 tree maxval
, minval
;
4153 /* 1 if comparison is nominally unsigned. */
4154 int unsignedp
= TYPE_UNSIGNED (*restype_ptr
);
4157 type
= c_common_signed_or_unsigned_type (unsignedp0
,
4158 TREE_TYPE (primop0
));
4160 maxval
= TYPE_MAX_VALUE (type
);
4161 minval
= TYPE_MIN_VALUE (type
);
4163 if (unsignedp
&& !unsignedp0
)
4164 *restype_ptr
= c_common_signed_type (*restype_ptr
);
4166 if (TREE_TYPE (primop1
) != *restype_ptr
)
4168 /* Convert primop1 to target type, but do not introduce
4169 additional overflow. We know primop1 is an int_cst. */
4170 primop1
= force_fit_type (*restype_ptr
,
4173 TYPE_PRECISION (*restype_ptr
),
4174 TYPE_SIGN (TREE_TYPE (primop1
))),
4175 0, TREE_OVERFLOW (primop1
));
4177 if (type
!= *restype_ptr
)
4179 minval
= convert (*restype_ptr
, minval
);
4180 maxval
= convert (*restype_ptr
, maxval
);
4183 min_gt
= tree_int_cst_lt (primop1
, minval
);
4184 max_gt
= tree_int_cst_lt (primop1
, maxval
);
4185 min_lt
= tree_int_cst_lt (minval
, primop1
);
4186 max_lt
= tree_int_cst_lt (maxval
, primop1
);
4189 /* This used to be a switch, but Genix compiler can't handle that. */
4190 if (code
== NE_EXPR
)
4192 if (max_lt
|| min_gt
)
4193 val
= truthvalue_true_node
;
4195 else if (code
== EQ_EXPR
)
4197 if (max_lt
|| min_gt
)
4198 val
= truthvalue_false_node
;
4200 else if (code
== LT_EXPR
)
4203 val
= truthvalue_true_node
;
4205 val
= truthvalue_false_node
;
4207 else if (code
== GT_EXPR
)
4210 val
= truthvalue_true_node
;
4212 val
= truthvalue_false_node
;
4214 else if (code
== LE_EXPR
)
4217 val
= truthvalue_true_node
;
4219 val
= truthvalue_false_node
;
4221 else if (code
== GE_EXPR
)
4224 val
= truthvalue_true_node
;
4226 val
= truthvalue_false_node
;
4229 /* If primop0 was sign-extended and unsigned comparison specd,
4230 we did a signed comparison above using the signed type bounds.
4231 But the comparison we output must be unsigned.
4233 Also, for inequalities, VAL is no good; but if the signed
4234 comparison had *any* fixed result, it follows that the
4235 unsigned comparison just tests the sign in reverse
4236 (positive values are LE, negative ones GE).
4237 So we can generate an unsigned comparison
4238 against an extreme value of the signed type. */
4240 if (unsignedp
&& !unsignedp0
)
4247 primop1
= TYPE_MIN_VALUE (type
);
4253 primop1
= TYPE_MAX_VALUE (type
);
4260 type
= c_common_unsigned_type (type
);
4263 if (TREE_CODE (primop0
) != INTEGER_CST
)
4265 if (val
== truthvalue_false_node
)
4266 warning_at (loc
, OPT_Wtype_limits
,
4267 "comparison is always false due to limited range of data type");
4268 if (val
== truthvalue_true_node
)
4269 warning_at (loc
, OPT_Wtype_limits
,
4270 "comparison is always true due to limited range of data type");
4275 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4276 if (TREE_SIDE_EFFECTS (primop0
))
4277 return build2 (COMPOUND_EXPR
, TREE_TYPE (val
), primop0
, val
);
4281 /* Value is not predetermined, but do the comparison
4282 in the type of the operand that is not constant.
4283 TYPE is already properly set. */
4286 /* If either arg is decimal float and the other is float, find the
4287 proper common type to use for comparison. */
4288 else if (real1
&& real2
4289 && (DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0
)))
4290 || DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1
)))))
4291 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
4293 else if (real1
&& real2
4294 && (TYPE_PRECISION (TREE_TYPE (primop0
))
4295 == TYPE_PRECISION (TREE_TYPE (primop1
))))
4296 type
= TREE_TYPE (primop0
);
4298 /* If args' natural types are both narrower than nominal type
4299 and both extend in the same manner, compare them
4300 in the type of the wider arg.
4301 Otherwise must actually extend both to the nominal
4302 common type lest different ways of extending
4304 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
4306 else if (unsignedp0
== unsignedp1
&& real1
== real2
4307 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
)
4308 && TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (*restype_ptr
))
4310 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
4311 type
= c_common_signed_or_unsigned_type (unsignedp0
4312 || TYPE_UNSIGNED (*restype_ptr
),
4314 /* Make sure shorter operand is extended the right way
4315 to match the longer operand. */
4317 = convert (c_common_signed_or_unsigned_type (unsignedp0
,
4318 TREE_TYPE (primop0
)),
4321 = convert (c_common_signed_or_unsigned_type (unsignedp1
,
4322 TREE_TYPE (primop1
)),
4327 /* Here we must do the comparison on the nominal type
4328 using the args exactly as we received them. */
4329 type
= *restype_ptr
;
4333 if (!real1
&& !real2
&& integer_zerop (primop1
)
4334 && TYPE_UNSIGNED (*restype_ptr
))
4337 /* All unsigned values are >= 0, so we warn. However,
4338 if OP0 is a constant that is >= 0, the signedness of
4339 the comparison isn't an issue, so suppress the
4342 warn_type_limits
&& !in_system_header_at (loc
)
4343 && !(TREE_CODE (primop0
) == INTEGER_CST
4344 && !TREE_OVERFLOW (convert (c_common_signed_type (type
),
4346 /* Do not warn for enumeration types. */
4347 && (TREE_CODE (expr_original_type (primop0
)) != ENUMERAL_TYPE
);
4353 warning_at (loc
, OPT_Wtype_limits
,
4354 "comparison of unsigned expression >= 0 is always true");
4355 value
= truthvalue_true_node
;
4360 warning_at (loc
, OPT_Wtype_limits
,
4361 "comparison of unsigned expression < 0 is always false");
4362 value
= truthvalue_false_node
;
4371 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4372 if (TREE_SIDE_EFFECTS (primop0
))
4373 return build2 (COMPOUND_EXPR
, TREE_TYPE (value
),
4380 *op0_ptr
= convert (type
, primop0
);
4381 *op1_ptr
= convert (type
, primop1
);
4383 *restype_ptr
= truthvalue_type_node
;
4388 /* Return a tree for the sum or difference (RESULTCODE says which)
4389 of pointer PTROP and integer INTOP. */
4392 pointer_int_sum (location_t loc
, enum tree_code resultcode
,
4393 tree ptrop
, tree intop
, bool complain
)
4397 /* The result is a pointer of the same type that is being added. */
4398 tree result_type
= TREE_TYPE (ptrop
);
4400 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
4402 if (complain
&& warn_pointer_arith
)
4403 pedwarn (loc
, OPT_Wpointer_arith
,
4404 "pointer of type %<void *%> used in arithmetic");
4406 return error_mark_node
;
4407 size_exp
= integer_one_node
;
4409 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
4411 if (complain
&& warn_pointer_arith
)
4412 pedwarn (loc
, OPT_Wpointer_arith
,
4413 "pointer to a function used in arithmetic");
4415 return error_mark_node
;
4416 size_exp
= integer_one_node
;
4419 size_exp
= size_in_bytes (TREE_TYPE (result_type
));
4421 /* We are manipulating pointer values, so we don't need to warn
4422 about relying on undefined signed overflow. We disable the
4423 warning here because we use integer types so fold won't know that
4424 they are really pointers. */
4425 fold_defer_overflow_warnings ();
4427 /* If what we are about to multiply by the size of the elements
4428 contains a constant term, apply distributive law
4429 and multiply that constant term separately.
4430 This helps produce common subexpressions. */
4431 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
4432 && !TREE_CONSTANT (intop
)
4433 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
4434 && TREE_CONSTANT (size_exp
)
4435 /* If the constant comes from pointer subtraction,
4436 skip this optimization--it would cause an error. */
4437 && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop
, 0))) == INTEGER_TYPE
4438 /* If the constant is unsigned, and smaller than the pointer size,
4439 then we must skip this optimization. This is because it could cause
4440 an overflow error if the constant is negative but INTOP is not. */
4441 && (!TYPE_UNSIGNED (TREE_TYPE (intop
))
4442 || (TYPE_PRECISION (TREE_TYPE (intop
))
4443 == TYPE_PRECISION (TREE_TYPE (ptrop
)))))
4445 enum tree_code subcode
= resultcode
;
4446 tree int_type
= TREE_TYPE (intop
);
4447 if (TREE_CODE (intop
) == MINUS_EXPR
)
4448 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
4449 /* Convert both subexpression types to the type of intop,
4450 because weird cases involving pointer arithmetic
4451 can result in a sum or difference with different type args. */
4452 ptrop
= build_binary_op (EXPR_LOCATION (TREE_OPERAND (intop
, 1)),
4454 convert (int_type
, TREE_OPERAND (intop
, 1)), 1);
4455 intop
= convert (int_type
, TREE_OPERAND (intop
, 0));
4458 /* Convert the integer argument to a type the same size as sizetype
4459 so the multiply won't overflow spuriously. */
4460 if (TYPE_PRECISION (TREE_TYPE (intop
)) != TYPE_PRECISION (sizetype
)
4461 || TYPE_UNSIGNED (TREE_TYPE (intop
)) != TYPE_UNSIGNED (sizetype
))
4462 intop
= convert (c_common_type_for_size (TYPE_PRECISION (sizetype
),
4463 TYPE_UNSIGNED (sizetype
)), intop
);
4465 /* Replace the integer argument with a suitable product by the object size.
4466 Do this multiplication as signed, then convert to the appropriate type
4467 for the pointer operation and disregard an overflow that occurred only
4468 because of the sign-extension change in the latter conversion. */
4470 tree t
= build_binary_op (loc
,
4472 convert (TREE_TYPE (intop
), size_exp
), 1);
4473 intop
= convert (sizetype
, t
);
4474 if (TREE_OVERFLOW_P (intop
) && !TREE_OVERFLOW (t
))
4475 intop
= wide_int_to_tree (TREE_TYPE (intop
), intop
);
4478 /* Create the sum or difference. */
4479 if (resultcode
== MINUS_EXPR
)
4480 intop
= fold_build1_loc (loc
, NEGATE_EXPR
, sizetype
, intop
);
4482 ret
= fold_build_pointer_plus_loc (loc
, ptrop
, intop
);
4484 fold_undefer_and_ignore_overflow_warnings ();
4489 /* Wrap a C_MAYBE_CONST_EXPR around an expression that is fully folded
4490 and if NON_CONST is known not to be permitted in an evaluated part
4491 of a constant expression. */
4494 c_wrap_maybe_const (tree expr
, bool non_const
)
4496 bool nowarning
= TREE_NO_WARNING (expr
);
4497 location_t loc
= EXPR_LOCATION (expr
);
4499 /* This should never be called for C++. */
4500 if (c_dialect_cxx ())
4503 /* The result of folding may have a NOP_EXPR to set TREE_NO_WARNING. */
4504 STRIP_TYPE_NOPS (expr
);
4505 expr
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (expr
), NULL
, expr
);
4506 C_MAYBE_CONST_EXPR_NON_CONST (expr
) = non_const
;
4508 TREE_NO_WARNING (expr
) = 1;
4509 protected_set_expr_location (expr
, loc
);
4514 /* Wrap a SAVE_EXPR around EXPR, if appropriate. Like save_expr, but
4515 for C folds the inside expression and wraps a C_MAYBE_CONST_EXPR
4516 around the SAVE_EXPR if needed so that c_fully_fold does not need
4517 to look inside SAVE_EXPRs. */
4520 c_save_expr (tree expr
)
4522 bool maybe_const
= true;
4523 if (c_dialect_cxx ())
4524 return save_expr (expr
);
4525 expr
= c_fully_fold (expr
, false, &maybe_const
);
4526 expr
= save_expr (expr
);
4528 expr
= c_wrap_maybe_const (expr
, true);
4532 /* Return whether EXPR is a declaration whose address can never be
4536 decl_with_nonnull_addr_p (const_tree expr
)
4538 return (DECL_P (expr
)
4539 && (TREE_CODE (expr
) == PARM_DECL
4540 || TREE_CODE (expr
) == LABEL_DECL
4541 || !DECL_WEAK (expr
)));
4544 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
4545 or for an `if' or `while' statement or ?..: exp. It should already
4546 have been validated to be of suitable type; otherwise, a bad
4547 diagnostic may result.
4549 The EXPR is located at LOCATION.
4551 This preparation consists of taking the ordinary
4552 representation of an expression expr and producing a valid tree
4553 boolean expression describing whether expr is nonzero. We could
4554 simply always do build_binary_op (NE_EXPR, expr, truthvalue_false_node, 1),
4555 but we optimize comparisons, &&, ||, and !.
4557 The resulting type should always be `truthvalue_type_node'. */
4560 c_common_truthvalue_conversion (location_t location
, tree expr
)
4562 switch (TREE_CODE (expr
))
4564 case EQ_EXPR
: case NE_EXPR
: case UNEQ_EXPR
: case LTGT_EXPR
:
4565 case LE_EXPR
: case GE_EXPR
: case LT_EXPR
: case GT_EXPR
:
4566 case UNLE_EXPR
: case UNGE_EXPR
: case UNLT_EXPR
: case UNGT_EXPR
:
4567 case ORDERED_EXPR
: case UNORDERED_EXPR
:
4568 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4570 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4571 TREE_OPERAND (expr
, 0), TREE_OPERAND (expr
, 1));
4574 case TRUTH_ANDIF_EXPR
:
4575 case TRUTH_ORIF_EXPR
:
4576 case TRUTH_AND_EXPR
:
4578 case TRUTH_XOR_EXPR
:
4579 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4581 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4582 c_common_truthvalue_conversion (location
,
4583 TREE_OPERAND (expr
, 0)),
4584 c_common_truthvalue_conversion (location
,
4585 TREE_OPERAND (expr
, 1)));
4588 case TRUTH_NOT_EXPR
:
4589 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4591 expr
= build1 (TREE_CODE (expr
), truthvalue_type_node
,
4592 c_common_truthvalue_conversion (location
,
4593 TREE_OPERAND (expr
, 0)));
4600 return integer_zerop (expr
) ? truthvalue_false_node
4601 : truthvalue_true_node
;
4604 return real_compare (NE_EXPR
, &TREE_REAL_CST (expr
), &dconst0
)
4605 ? truthvalue_true_node
4606 : truthvalue_false_node
;
4609 return fixed_compare (NE_EXPR
, &TREE_FIXED_CST (expr
),
4610 &FCONST0 (TYPE_MODE (TREE_TYPE (expr
))))
4611 ? truthvalue_true_node
4612 : truthvalue_false_node
;
4615 expr
= build_unary_op (location
, ADDR_EXPR
, expr
, 0);
4620 tree inner
= TREE_OPERAND (expr
, 0);
4621 if (decl_with_nonnull_addr_p (inner
))
4623 /* Common Ada/Pascal programmer's mistake. */
4624 warning_at (location
,
4626 "the address of %qD will always evaluate as %<true%>",
4628 return truthvalue_true_node
;
4634 expr
= build_binary_op (EXPR_LOCATION (expr
),
4635 (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1))
4636 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4637 c_common_truthvalue_conversion (location
,
4638 TREE_OPERAND (expr
, 0)),
4639 c_common_truthvalue_conversion (location
,
4640 TREE_OPERAND (expr
, 1)),
4647 case EXCESS_PRECISION_EXPR
:
4648 /* These don't change whether an object is nonzero or zero. */
4649 return c_common_truthvalue_conversion (location
, TREE_OPERAND (expr
, 0));
4653 /* These don't change whether an object is zero or nonzero, but
4654 we can't ignore them if their second arg has side-effects. */
4655 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1)))
4657 expr
= build2 (COMPOUND_EXPR
, truthvalue_type_node
,
4658 TREE_OPERAND (expr
, 1),
4659 c_common_truthvalue_conversion
4660 (location
, TREE_OPERAND (expr
, 0)));
4664 return c_common_truthvalue_conversion (location
,
4665 TREE_OPERAND (expr
, 0));
4668 /* Distribute the conversion into the arms of a COND_EXPR. */
4669 if (c_dialect_cxx ())
4671 tree op1
= TREE_OPERAND (expr
, 1);
4672 tree op2
= TREE_OPERAND (expr
, 2);
4673 /* In C++ one of the arms might have void type if it is throw. */
4674 if (!VOID_TYPE_P (TREE_TYPE (op1
)))
4675 op1
= c_common_truthvalue_conversion (location
, op1
);
4676 if (!VOID_TYPE_P (TREE_TYPE (op2
)))
4677 op2
= c_common_truthvalue_conversion (location
, op2
);
4678 expr
= fold_build3_loc (location
, COND_EXPR
, truthvalue_type_node
,
4679 TREE_OPERAND (expr
, 0), op1
, op2
);
4684 /* Folding will happen later for C. */
4685 expr
= build3 (COND_EXPR
, truthvalue_type_node
,
4686 TREE_OPERAND (expr
, 0),
4687 c_common_truthvalue_conversion (location
,
4688 TREE_OPERAND (expr
, 1)),
4689 c_common_truthvalue_conversion (location
,
4690 TREE_OPERAND (expr
, 2)));
4696 tree totype
= TREE_TYPE (expr
);
4697 tree fromtype
= TREE_TYPE (TREE_OPERAND (expr
, 0));
4699 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
4700 since that affects how `default_conversion' will behave. */
4701 if (TREE_CODE (totype
) == REFERENCE_TYPE
4702 || TREE_CODE (fromtype
) == REFERENCE_TYPE
)
4704 /* Don't strip a conversion from C++0x scoped enum, since they
4705 don't implicitly convert to other types. */
4706 if (TREE_CODE (fromtype
) == ENUMERAL_TYPE
4707 && ENUM_IS_SCOPED (fromtype
))
4709 /* If this isn't narrowing the argument, we can ignore it. */
4710 if (TYPE_PRECISION (totype
) >= TYPE_PRECISION (fromtype
))
4711 return c_common_truthvalue_conversion (location
,
4712 TREE_OPERAND (expr
, 0));
4717 if (!TREE_NO_WARNING (expr
)
4718 && warn_parentheses
)
4720 warning (OPT_Wparentheses
,
4721 "suggest parentheses around assignment used as truth value");
4722 TREE_NO_WARNING (expr
) = 1;
4730 if (TREE_CODE (TREE_TYPE (expr
)) == COMPLEX_TYPE
)
4732 tree t
= (in_late_binary_op
? save_expr (expr
) : c_save_expr (expr
));
4733 expr
= (build_binary_op
4734 (EXPR_LOCATION (expr
),
4735 (TREE_SIDE_EFFECTS (expr
)
4736 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4737 c_common_truthvalue_conversion
4739 build_unary_op (location
, REALPART_EXPR
, t
, 0)),
4740 c_common_truthvalue_conversion
4742 build_unary_op (location
, IMAGPART_EXPR
, t
, 0)),
4747 if (TREE_CODE (TREE_TYPE (expr
)) == FIXED_POINT_TYPE
)
4749 tree fixed_zero_node
= build_fixed (TREE_TYPE (expr
),
4751 (TREE_TYPE (expr
))));
4752 return build_binary_op (location
, NE_EXPR
, expr
, fixed_zero_node
, 1);
4755 return build_binary_op (location
, NE_EXPR
, expr
, integer_zero_node
, 1);
4758 protected_set_expr_location (expr
, location
);
4762 static void def_builtin_1 (enum built_in_function fncode
,
4764 enum built_in_class fnclass
,
4765 tree fntype
, tree libtype
,
4766 bool both_p
, bool fallback_p
, bool nonansi_p
,
4767 tree fnattrs
, bool implicit_p
);
4770 /* Apply the TYPE_QUALS to the new DECL. */
4773 c_apply_type_quals_to_decl (int type_quals
, tree decl
)
4775 tree type
= TREE_TYPE (decl
);
4777 if (type
== error_mark_node
)
4780 if ((type_quals
& TYPE_QUAL_CONST
)
4781 || (type
&& TREE_CODE (type
) == REFERENCE_TYPE
))
4782 /* We used to check TYPE_NEEDS_CONSTRUCTING here, but now a constexpr
4783 constructor can produce constant init, so rely on cp_finish_decl to
4784 clear TREE_READONLY if the variable has non-constant init. */
4785 TREE_READONLY (decl
) = 1;
4786 if (type_quals
& TYPE_QUAL_VOLATILE
)
4788 TREE_SIDE_EFFECTS (decl
) = 1;
4789 TREE_THIS_VOLATILE (decl
) = 1;
4791 if (type_quals
& TYPE_QUAL_RESTRICT
)
4793 while (type
&& TREE_CODE (type
) == ARRAY_TYPE
)
4794 /* Allow 'restrict' on arrays of pointers.
4795 FIXME currently we just ignore it. */
4796 type
= TREE_TYPE (type
);
4798 || !POINTER_TYPE_P (type
)
4799 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type
)))
4800 error ("invalid use of %<restrict%>");
4804 /* Hash function for the problem of multiple type definitions in
4805 different files. This must hash all types that will compare
4806 equal via comptypes to the same value. In practice it hashes
4807 on some of the simple stuff and leaves the details to comptypes. */
4810 c_type_hash (const void *p
)
4814 const_tree
const t
= (const_tree
) p
;
4816 switch (TREE_CODE (t
))
4818 /* For pointers, hash on pointee type plus some swizzling. */
4820 return c_type_hash (TREE_TYPE (t
)) ^ 0x3003003;
4821 /* Hash on number of elements and total size. */
4824 t2
= TYPE_VALUES (t
);
4828 t2
= TYPE_FIELDS (t
);
4830 case QUAL_UNION_TYPE
:
4832 t2
= TYPE_FIELDS (t
);
4836 t2
= TYPE_FIELDS (t
);
4841 /* FIXME: We want to use a DECL_CHAIN iteration method here, but
4842 TYPE_VALUES of ENUMERAL_TYPEs is stored as a TREE_LIST. */
4843 n_elements
= list_length (t2
);
4844 /* We might have a VLA here. */
4845 if (TREE_CODE (TYPE_SIZE (t
)) != INTEGER_CST
)
4848 size
= TREE_INT_CST_LOW (TYPE_SIZE (t
));
4849 return ((size
<< 24) | (n_elements
<< shift
));
4852 static GTY((param_is (union tree_node
))) htab_t type_hash_table
;
4854 /* Return the typed-based alias set for T, which may be an expression
4855 or a type. Return -1 if we don't do anything special. */
4858 c_common_get_alias_set (tree t
)
4863 /* For VLAs, use the alias set of the element type rather than the
4864 default of alias set 0 for types compared structurally. */
4865 if (TYPE_P (t
) && TYPE_STRUCTURAL_EQUALITY_P (t
))
4867 if (TREE_CODE (t
) == ARRAY_TYPE
)
4868 return get_alias_set (TREE_TYPE (t
));
4872 /* Permit type-punning when accessing a union, provided the access
4873 is directly through the union. For example, this code does not
4874 permit taking the address of a union member and then storing
4875 through it. Even the type-punning allowed here is a GCC
4876 extension, albeit a common and useful one; the C standard says
4877 that such accesses have implementation-defined behavior. */
4879 TREE_CODE (u
) == COMPONENT_REF
|| TREE_CODE (u
) == ARRAY_REF
;
4880 u
= TREE_OPERAND (u
, 0))
4881 if (TREE_CODE (u
) == COMPONENT_REF
4882 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u
, 0))) == UNION_TYPE
)
4885 /* That's all the expressions we handle specially. */
4889 /* The C standard guarantees that any object may be accessed via an
4890 lvalue that has character type. */
4891 if (t
== char_type_node
4892 || t
== signed_char_type_node
4893 || t
== unsigned_char_type_node
)
4896 /* The C standard specifically allows aliasing between signed and
4897 unsigned variants of the same type. We treat the signed
4898 variant as canonical. */
4899 if (TREE_CODE (t
) == INTEGER_TYPE
&& TYPE_UNSIGNED (t
))
4901 tree t1
= c_common_signed_type (t
);
4903 /* t1 == t can happen for boolean nodes which are always unsigned. */
4905 return get_alias_set (t1
);
4908 /* Handle the case of multiple type nodes referring to "the same" type,
4909 which occurs with IMA. These share an alias set. FIXME: Currently only
4910 C90 is handled. (In C99 type compatibility is not transitive, which
4911 complicates things mightily. The alias set splay trees can theoretically
4912 represent this, but insertion is tricky when you consider all the
4913 different orders things might arrive in.) */
4915 if (c_language
!= clk_c
|| flag_isoc99
)
4918 /* Save time if there's only one input file. */
4919 if (num_in_fnames
== 1)
4922 /* Pointers need special handling if they point to any type that
4923 needs special handling (below). */
4924 if (TREE_CODE (t
) == POINTER_TYPE
)
4927 /* Find bottom type under any nested POINTERs. */
4928 for (t2
= TREE_TYPE (t
);
4929 TREE_CODE (t2
) == POINTER_TYPE
;
4930 t2
= TREE_TYPE (t2
))
4932 if (TREE_CODE (t2
) != RECORD_TYPE
4933 && TREE_CODE (t2
) != ENUMERAL_TYPE
4934 && TREE_CODE (t2
) != QUAL_UNION_TYPE
4935 && TREE_CODE (t2
) != UNION_TYPE
)
4937 if (TYPE_SIZE (t2
) == 0)
4940 /* These are the only cases that need special handling. */
4941 if (TREE_CODE (t
) != RECORD_TYPE
4942 && TREE_CODE (t
) != ENUMERAL_TYPE
4943 && TREE_CODE (t
) != QUAL_UNION_TYPE
4944 && TREE_CODE (t
) != UNION_TYPE
4945 && TREE_CODE (t
) != POINTER_TYPE
)
4948 if (TYPE_SIZE (t
) == 0)
4951 /* Look up t in hash table. Only one of the compatible types within each
4952 alias set is recorded in the table. */
4953 if (!type_hash_table
)
4954 type_hash_table
= htab_create_ggc (1021, c_type_hash
,
4955 (htab_eq
) lang_hooks
.types_compatible_p
,
4957 slot
= htab_find_slot (type_hash_table
, t
, INSERT
);
4960 TYPE_ALIAS_SET (t
) = TYPE_ALIAS_SET ((tree
)*slot
);
4961 return TYPE_ALIAS_SET ((tree
)*slot
);
4964 /* Our caller will assign and record (in t) a new alias set; all we need
4965 to do is remember t in the hash table. */
4971 /* Return the least alignment required for type TYPE. */
4974 min_align_of_type (tree type
)
4976 unsigned int align
= TYPE_ALIGN (type
);
4977 align
= MIN (align
, BIGGEST_ALIGNMENT
);
4978 #ifdef BIGGEST_FIELD_ALIGNMENT
4979 align
= MIN (align
, BIGGEST_FIELD_ALIGNMENT
);
4981 unsigned int field_align
= align
;
4982 #ifdef ADJUST_FIELD_ALIGN
4983 tree field
= build_decl (UNKNOWN_LOCATION
, FIELD_DECL
, NULL_TREE
,
4985 field_align
= ADJUST_FIELD_ALIGN (field
, field_align
);
4987 align
= MIN (align
, field_align
);
4988 return align
/ BITS_PER_UNIT
;
4991 /* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where
4992 the IS_SIZEOF parameter indicates which operator is being applied.
4993 The COMPLAIN flag controls whether we should diagnose possibly
4994 ill-formed constructs or not. LOC is the location of the SIZEOF or
4995 TYPEOF operator. If MIN_ALIGNOF, the least alignment required for
4996 a type in any context should be returned, rather than the normal
4997 alignment for that type. */
5000 c_sizeof_or_alignof_type (location_t loc
,
5001 tree type
, bool is_sizeof
, bool min_alignof
,
5004 const char *op_name
;
5006 enum tree_code type_code
= TREE_CODE (type
);
5008 op_name
= is_sizeof
? "sizeof" : "__alignof__";
5010 if (type_code
== FUNCTION_TYPE
)
5014 if (complain
&& warn_pointer_arith
)
5015 pedwarn (loc
, OPT_Wpointer_arith
,
5016 "invalid application of %<sizeof%> to a function type");
5018 return error_mark_node
;
5019 value
= size_one_node
;
5025 if (c_dialect_cxx ())
5026 pedwarn (loc
, OPT_Wpedantic
, "ISO C++ does not permit "
5027 "%<alignof%> applied to a function type");
5029 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not permit "
5030 "%<_Alignof%> applied to a function type");
5032 value
= size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
5035 else if (type_code
== VOID_TYPE
|| type_code
== ERROR_MARK
)
5037 if (type_code
== VOID_TYPE
5038 && complain
&& warn_pointer_arith
)
5039 pedwarn (loc
, OPT_Wpointer_arith
,
5040 "invalid application of %qs to a void type", op_name
);
5042 return error_mark_node
;
5043 value
= size_one_node
;
5045 else if (!COMPLETE_TYPE_P (type
)
5046 && (!c_dialect_cxx () || is_sizeof
|| type_code
!= ARRAY_TYPE
))
5049 error_at (loc
, "invalid application of %qs to incomplete type %qT",
5051 return error_mark_node
;
5053 else if (c_dialect_cxx () && type_code
== ARRAY_TYPE
5054 && !COMPLETE_TYPE_P (TREE_TYPE (type
)))
5057 error_at (loc
, "invalid application of %qs to array type %qT of "
5058 "incomplete element type", op_name
, type
);
5059 return error_mark_node
;
5064 /* Convert in case a char is more than one unit. */
5065 value
= size_binop_loc (loc
, CEIL_DIV_EXPR
, TYPE_SIZE_UNIT (type
),
5066 size_int (TYPE_PRECISION (char_type_node
)
5068 else if (min_alignof
)
5069 value
= size_int (min_align_of_type (type
));
5071 value
= size_int (TYPE_ALIGN_UNIT (type
));
5074 /* VALUE will have the middle-end integer type sizetype.
5075 However, we should really return a value of type `size_t',
5076 which is just a typedef for an ordinary integer type. */
5077 value
= fold_convert_loc (loc
, size_type_node
, value
);
5082 /* Implement the __alignof keyword: Return the minimum required
5083 alignment of EXPR, measured in bytes. For VAR_DECLs,
5084 FUNCTION_DECLs and FIELD_DECLs return DECL_ALIGN (which can be set
5085 from an "aligned" __attribute__ specification). LOC is the
5086 location of the ALIGNOF operator. */
5089 c_alignof_expr (location_t loc
, tree expr
)
5093 if (VAR_OR_FUNCTION_DECL_P (expr
))
5094 t
= size_int (DECL_ALIGN_UNIT (expr
));
5096 else if (TREE_CODE (expr
) == COMPONENT_REF
5097 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
, 1)))
5099 error_at (loc
, "%<__alignof%> applied to a bit-field");
5102 else if (TREE_CODE (expr
) == COMPONENT_REF
5103 && TREE_CODE (TREE_OPERAND (expr
, 1)) == FIELD_DECL
)
5104 t
= size_int (DECL_ALIGN_UNIT (TREE_OPERAND (expr
, 1)));
5106 else if (TREE_CODE (expr
) == INDIRECT_REF
)
5108 tree t
= TREE_OPERAND (expr
, 0);
5110 int bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
5112 while (CONVERT_EXPR_P (t
)
5113 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
5117 t
= TREE_OPERAND (t
, 0);
5118 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
5119 if (thisalign
> bestalign
)
5120 best
= t
, bestalign
= thisalign
;
5122 return c_alignof (loc
, TREE_TYPE (TREE_TYPE (best
)));
5125 return c_alignof (loc
, TREE_TYPE (expr
));
5127 return fold_convert_loc (loc
, size_type_node
, t
);
5130 /* Handle C and C++ default attributes. */
5132 enum built_in_attribute
5134 #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
5135 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
5136 #define DEF_ATTR_STRING(ENUM, VALUE) ENUM,
5137 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
5138 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
5139 #include "builtin-attrs.def"
5140 #undef DEF_ATTR_NULL_TREE
5142 #undef DEF_ATTR_STRING
5143 #undef DEF_ATTR_IDENT
5144 #undef DEF_ATTR_TREE_LIST
5148 static GTY(()) tree built_in_attributes
[(int) ATTR_LAST
];
5150 static void c_init_attributes (void);
5154 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
5155 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
5156 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
5157 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
5158 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
5159 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
5160 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
5161 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5163 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5165 #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5166 ARG6, ARG7, ARG8) NAME,
5167 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
5168 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
5169 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
5170 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
5171 #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
5172 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5174 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
5175 #include "builtin-types.def"
5176 #undef DEF_PRIMITIVE_TYPE
5177 #undef DEF_FUNCTION_TYPE_0
5178 #undef DEF_FUNCTION_TYPE_1
5179 #undef DEF_FUNCTION_TYPE_2
5180 #undef DEF_FUNCTION_TYPE_3
5181 #undef DEF_FUNCTION_TYPE_4
5182 #undef DEF_FUNCTION_TYPE_5
5183 #undef DEF_FUNCTION_TYPE_6
5184 #undef DEF_FUNCTION_TYPE_7
5185 #undef DEF_FUNCTION_TYPE_8
5186 #undef DEF_FUNCTION_TYPE_VAR_0
5187 #undef DEF_FUNCTION_TYPE_VAR_1
5188 #undef DEF_FUNCTION_TYPE_VAR_2
5189 #undef DEF_FUNCTION_TYPE_VAR_3
5190 #undef DEF_FUNCTION_TYPE_VAR_4
5191 #undef DEF_FUNCTION_TYPE_VAR_5
5192 #undef DEF_POINTER_TYPE
5196 typedef enum c_builtin_type builtin_type
;
5198 /* A temporary array for c_common_nodes_and_builtins. Used in
5199 communication with def_fn_type. */
5200 static tree builtin_types
[(int) BT_LAST
+ 1];
5202 /* A helper function for c_common_nodes_and_builtins. Build function type
5203 for DEF with return type RET and N arguments. If VAR is true, then the
5204 function should be variadic after those N arguments.
5206 Takes special care not to ICE if any of the types involved are
5207 error_mark_node, which indicates that said type is not in fact available
5208 (see builtin_type_for_size). In which case the function type as a whole
5209 should be error_mark_node. */
5212 def_fn_type (builtin_type def
, builtin_type ret
, bool var
, int n
, ...)
5215 tree
*args
= XALLOCAVEC (tree
, n
);
5220 for (i
= 0; i
< n
; ++i
)
5222 builtin_type a
= (builtin_type
) va_arg (list
, int);
5223 t
= builtin_types
[a
];
5224 if (t
== error_mark_node
)
5229 t
= builtin_types
[ret
];
5230 if (t
== error_mark_node
)
5233 t
= build_varargs_function_type_array (t
, n
, args
);
5235 t
= build_function_type_array (t
, n
, args
);
5238 builtin_types
[def
] = t
;
5242 /* Build builtin functions common to both C and C++ language
5246 c_define_builtins (tree va_list_ref_type_node
, tree va_list_arg_type_node
)
5248 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
5249 builtin_types[ENUM] = VALUE;
5250 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
5251 def_fn_type (ENUM, RETURN, 0, 0);
5252 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
5253 def_fn_type (ENUM, RETURN, 0, 1, ARG1);
5254 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
5255 def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
5256 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
5257 def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
5258 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
5259 def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
5260 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5261 def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
5262 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5264 def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
5265 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5267 def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
5268 #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5270 def_fn_type (ENUM, RETURN, 0, 8, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
5272 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
5273 def_fn_type (ENUM, RETURN, 1, 0);
5274 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
5275 def_fn_type (ENUM, RETURN, 1, 1, ARG1);
5276 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
5277 def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
5278 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
5279 def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
5280 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
5281 def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
5282 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5283 def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
5284 #define DEF_POINTER_TYPE(ENUM, TYPE) \
5285 builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
5287 #include "builtin-types.def"
5289 #undef DEF_PRIMITIVE_TYPE
5290 #undef DEF_FUNCTION_TYPE_0
5291 #undef DEF_FUNCTION_TYPE_1
5292 #undef DEF_FUNCTION_TYPE_2
5293 #undef DEF_FUNCTION_TYPE_3
5294 #undef DEF_FUNCTION_TYPE_4
5295 #undef DEF_FUNCTION_TYPE_5
5296 #undef DEF_FUNCTION_TYPE_6
5297 #undef DEF_FUNCTION_TYPE_7
5298 #undef DEF_FUNCTION_TYPE_8
5299 #undef DEF_FUNCTION_TYPE_VAR_0
5300 #undef DEF_FUNCTION_TYPE_VAR_1
5301 #undef DEF_FUNCTION_TYPE_VAR_2
5302 #undef DEF_FUNCTION_TYPE_VAR_3
5303 #undef DEF_FUNCTION_TYPE_VAR_4
5304 #undef DEF_FUNCTION_TYPE_VAR_5
5305 #undef DEF_POINTER_TYPE
5306 builtin_types
[(int) BT_LAST
] = NULL_TREE
;
5308 c_init_attributes ();
5310 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P, \
5311 NONANSI_P, ATTRS, IMPLICIT, COND) \
5313 def_builtin_1 (ENUM, NAME, CLASS, \
5314 builtin_types[(int) TYPE], \
5315 builtin_types[(int) LIBTYPE], \
5316 BOTH_P, FALLBACK_P, NONANSI_P, \
5317 built_in_attributes[(int) ATTRS], IMPLICIT);
5318 #include "builtins.def"
5321 targetm
.init_builtins ();
5323 build_common_builtin_nodes ();
5326 cilk_init_builtins ();
5329 /* Like get_identifier, but avoid warnings about null arguments when
5330 the argument may be NULL for targets where GCC lacks stdint.h type
5334 c_get_ident (const char *id
)
5336 return get_identifier (id
);
5339 /* Build tree nodes and builtin functions common to both C and C++ language
5343 c_common_nodes_and_builtins (void)
5345 int char16_type_size
;
5346 int char32_type_size
;
5347 int wchar_type_size
;
5348 tree array_domain_type
;
5349 tree va_list_ref_type_node
;
5350 tree va_list_arg_type_node
;
5352 build_common_tree_nodes (flag_signed_char
, flag_short_double
);
5354 /* Define `int' and `char' first so that dbx will output them first. */
5355 record_builtin_type (RID_INT
, NULL
, integer_type_node
);
5356 record_builtin_type (RID_CHAR
, "char", char_type_node
);
5358 /* `signed' is the same as `int'. FIXME: the declarations of "signed",
5359 "unsigned long", "long long unsigned" and "unsigned short" were in C++
5360 but not C. Are the conditionals here needed? */
5361 if (c_dialect_cxx ())
5362 record_builtin_type (RID_SIGNED
, NULL
, integer_type_node
);
5363 record_builtin_type (RID_LONG
, "long int", long_integer_type_node
);
5364 record_builtin_type (RID_UNSIGNED
, "unsigned int", unsigned_type_node
);
5365 record_builtin_type (RID_MAX
, "long unsigned int",
5366 long_unsigned_type_node
);
5367 if (int128_integer_type_node
!= NULL_TREE
)
5369 record_builtin_type (RID_INT128
, "__int128",
5370 int128_integer_type_node
);
5371 record_builtin_type (RID_MAX
, "__int128 unsigned",
5372 int128_unsigned_type_node
);
5374 if (c_dialect_cxx ())
5375 record_builtin_type (RID_MAX
, "unsigned long", long_unsigned_type_node
);
5376 record_builtin_type (RID_MAX
, "long long int",
5377 long_long_integer_type_node
);
5378 record_builtin_type (RID_MAX
, "long long unsigned int",
5379 long_long_unsigned_type_node
);
5380 if (c_dialect_cxx ())
5381 record_builtin_type (RID_MAX
, "long long unsigned",
5382 long_long_unsigned_type_node
);
5383 record_builtin_type (RID_SHORT
, "short int", short_integer_type_node
);
5384 record_builtin_type (RID_MAX
, "short unsigned int",
5385 short_unsigned_type_node
);
5386 if (c_dialect_cxx ())
5387 record_builtin_type (RID_MAX
, "unsigned short",
5388 short_unsigned_type_node
);
5390 /* Define both `signed char' and `unsigned char'. */
5391 record_builtin_type (RID_MAX
, "signed char", signed_char_type_node
);
5392 record_builtin_type (RID_MAX
, "unsigned char", unsigned_char_type_node
);
5394 /* These are types that c_common_type_for_size and
5395 c_common_type_for_mode use. */
5396 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5397 TYPE_DECL
, NULL_TREE
,
5399 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5400 TYPE_DECL
, NULL_TREE
,
5402 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5403 TYPE_DECL
, NULL_TREE
,
5405 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5406 TYPE_DECL
, NULL_TREE
,
5408 #if HOST_BITS_PER_WIDE_INT >= 64
5409 if (targetm
.scalar_mode_supported_p (TImode
))
5410 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5412 get_identifier ("__int128_t"),
5415 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5416 TYPE_DECL
, NULL_TREE
,
5417 unsigned_intQI_type_node
));
5418 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5419 TYPE_DECL
, NULL_TREE
,
5420 unsigned_intHI_type_node
));
5421 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5422 TYPE_DECL
, NULL_TREE
,
5423 unsigned_intSI_type_node
));
5424 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5425 TYPE_DECL
, NULL_TREE
,
5426 unsigned_intDI_type_node
));
5427 #if HOST_BITS_PER_WIDE_INT >= 64
5428 if (targetm
.scalar_mode_supported_p (TImode
))
5429 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5431 get_identifier ("__uint128_t"),
5432 unsigned_intTI_type_node
));
5435 /* Create the widest literal types. */
5436 widest_integer_literal_type_node
5437 = make_signed_type (HOST_BITS_PER_WIDE_INT
* 2);
5438 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5439 TYPE_DECL
, NULL_TREE
,
5440 widest_integer_literal_type_node
));
5442 widest_unsigned_literal_type_node
5443 = make_unsigned_type (HOST_BITS_PER_WIDE_INT
* 2);
5444 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5445 TYPE_DECL
, NULL_TREE
,
5446 widest_unsigned_literal_type_node
));
5448 signed_size_type_node
= c_common_signed_type (size_type_node
);
5451 TREE_TYPE (identifier_global_value (get_identifier (PID_TYPE
)));
5453 record_builtin_type (RID_FLOAT
, NULL
, float_type_node
);
5454 record_builtin_type (RID_DOUBLE
, NULL
, double_type_node
);
5455 record_builtin_type (RID_MAX
, "long double", long_double_type_node
);
5457 /* Only supported decimal floating point extension if the target
5458 actually supports underlying modes. */
5459 if (targetm
.scalar_mode_supported_p (SDmode
)
5460 && targetm
.scalar_mode_supported_p (DDmode
)
5461 && targetm
.scalar_mode_supported_p (TDmode
))
5463 record_builtin_type (RID_DFLOAT32
, NULL
, dfloat32_type_node
);
5464 record_builtin_type (RID_DFLOAT64
, NULL
, dfloat64_type_node
);
5465 record_builtin_type (RID_DFLOAT128
, NULL
, dfloat128_type_node
);
5468 if (targetm
.fixed_point_supported_p ())
5470 record_builtin_type (RID_MAX
, "short _Fract", short_fract_type_node
);
5471 record_builtin_type (RID_FRACT
, NULL
, fract_type_node
);
5472 record_builtin_type (RID_MAX
, "long _Fract", long_fract_type_node
);
5473 record_builtin_type (RID_MAX
, "long long _Fract",
5474 long_long_fract_type_node
);
5475 record_builtin_type (RID_MAX
, "unsigned short _Fract",
5476 unsigned_short_fract_type_node
);
5477 record_builtin_type (RID_MAX
, "unsigned _Fract",
5478 unsigned_fract_type_node
);
5479 record_builtin_type (RID_MAX
, "unsigned long _Fract",
5480 unsigned_long_fract_type_node
);
5481 record_builtin_type (RID_MAX
, "unsigned long long _Fract",
5482 unsigned_long_long_fract_type_node
);
5483 record_builtin_type (RID_MAX
, "_Sat short _Fract",
5484 sat_short_fract_type_node
);
5485 record_builtin_type (RID_MAX
, "_Sat _Fract", sat_fract_type_node
);
5486 record_builtin_type (RID_MAX
, "_Sat long _Fract",
5487 sat_long_fract_type_node
);
5488 record_builtin_type (RID_MAX
, "_Sat long long _Fract",
5489 sat_long_long_fract_type_node
);
5490 record_builtin_type (RID_MAX
, "_Sat unsigned short _Fract",
5491 sat_unsigned_short_fract_type_node
);
5492 record_builtin_type (RID_MAX
, "_Sat unsigned _Fract",
5493 sat_unsigned_fract_type_node
);
5494 record_builtin_type (RID_MAX
, "_Sat unsigned long _Fract",
5495 sat_unsigned_long_fract_type_node
);
5496 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Fract",
5497 sat_unsigned_long_long_fract_type_node
);
5498 record_builtin_type (RID_MAX
, "short _Accum", short_accum_type_node
);
5499 record_builtin_type (RID_ACCUM
, NULL
, accum_type_node
);
5500 record_builtin_type (RID_MAX
, "long _Accum", long_accum_type_node
);
5501 record_builtin_type (RID_MAX
, "long long _Accum",
5502 long_long_accum_type_node
);
5503 record_builtin_type (RID_MAX
, "unsigned short _Accum",
5504 unsigned_short_accum_type_node
);
5505 record_builtin_type (RID_MAX
, "unsigned _Accum",
5506 unsigned_accum_type_node
);
5507 record_builtin_type (RID_MAX
, "unsigned long _Accum",
5508 unsigned_long_accum_type_node
);
5509 record_builtin_type (RID_MAX
, "unsigned long long _Accum",
5510 unsigned_long_long_accum_type_node
);
5511 record_builtin_type (RID_MAX
, "_Sat short _Accum",
5512 sat_short_accum_type_node
);
5513 record_builtin_type (RID_MAX
, "_Sat _Accum", sat_accum_type_node
);
5514 record_builtin_type (RID_MAX
, "_Sat long _Accum",
5515 sat_long_accum_type_node
);
5516 record_builtin_type (RID_MAX
, "_Sat long long _Accum",
5517 sat_long_long_accum_type_node
);
5518 record_builtin_type (RID_MAX
, "_Sat unsigned short _Accum",
5519 sat_unsigned_short_accum_type_node
);
5520 record_builtin_type (RID_MAX
, "_Sat unsigned _Accum",
5521 sat_unsigned_accum_type_node
);
5522 record_builtin_type (RID_MAX
, "_Sat unsigned long _Accum",
5523 sat_unsigned_long_accum_type_node
);
5524 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Accum",
5525 sat_unsigned_long_long_accum_type_node
);
5529 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5531 get_identifier ("complex int"),
5532 complex_integer_type_node
));
5533 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5535 get_identifier ("complex float"),
5536 complex_float_type_node
));
5537 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5539 get_identifier ("complex double"),
5540 complex_double_type_node
));
5541 lang_hooks
.decls
.pushdecl
5542 (build_decl (UNKNOWN_LOCATION
,
5543 TYPE_DECL
, get_identifier ("complex long double"),
5544 complex_long_double_type_node
));
5546 if (c_dialect_cxx ())
5547 /* For C++, make fileptr_type_node a distinct void * type until
5548 FILE type is defined. */
5549 fileptr_type_node
= build_variant_type_copy (ptr_type_node
);
5551 record_builtin_type (RID_VOID
, NULL
, void_type_node
);
5553 /* Set the TYPE_NAME for any variants that were built before
5554 record_builtin_type gave names to the built-in types. */
5556 tree void_name
= TYPE_NAME (void_type_node
);
5557 TYPE_NAME (void_type_node
) = NULL_TREE
;
5558 TYPE_NAME (build_qualified_type (void_type_node
, TYPE_QUAL_CONST
))
5560 TYPE_NAME (void_type_node
) = void_name
;
5563 void_list_node
= build_void_list_node ();
5565 /* Make a type to be the domain of a few array types
5566 whose domains don't really matter.
5567 200 is small enough that it always fits in size_t
5568 and large enough that it can hold most function names for the
5569 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
5570 array_domain_type
= build_index_type (size_int (200));
5572 /* Make a type for arrays of characters.
5573 With luck nothing will ever really depend on the length of this
5575 char_array_type_node
5576 = build_array_type (char_type_node
, array_domain_type
);
5578 string_type_node
= build_pointer_type (char_type_node
);
5579 const_string_type_node
5580 = build_pointer_type (build_qualified_type
5581 (char_type_node
, TYPE_QUAL_CONST
));
5583 /* This is special for C++ so functions can be overloaded. */
5584 wchar_type_node
= get_identifier (MODIFIED_WCHAR_TYPE
);
5585 wchar_type_node
= TREE_TYPE (identifier_global_value (wchar_type_node
));
5586 wchar_type_size
= TYPE_PRECISION (wchar_type_node
);
5587 underlying_wchar_type_node
= wchar_type_node
;
5588 if (c_dialect_cxx ())
5590 if (TYPE_UNSIGNED (wchar_type_node
))
5591 wchar_type_node
= make_unsigned_type (wchar_type_size
);
5593 wchar_type_node
= make_signed_type (wchar_type_size
);
5594 record_builtin_type (RID_WCHAR
, "wchar_t", wchar_type_node
);
5597 /* This is for wide string constants. */
5598 wchar_array_type_node
5599 = build_array_type (wchar_type_node
, array_domain_type
);
5601 /* Define 'char16_t'. */
5602 char16_type_node
= get_identifier (CHAR16_TYPE
);
5603 char16_type_node
= TREE_TYPE (identifier_global_value (char16_type_node
));
5604 char16_type_size
= TYPE_PRECISION (char16_type_node
);
5605 if (c_dialect_cxx ())
5607 char16_type_node
= make_unsigned_type (char16_type_size
);
5609 if (cxx_dialect
>= cxx11
)
5610 record_builtin_type (RID_CHAR16
, "char16_t", char16_type_node
);
5613 /* This is for UTF-16 string constants. */
5614 char16_array_type_node
5615 = build_array_type (char16_type_node
, array_domain_type
);
5617 /* Define 'char32_t'. */
5618 char32_type_node
= get_identifier (CHAR32_TYPE
);
5619 char32_type_node
= TREE_TYPE (identifier_global_value (char32_type_node
));
5620 char32_type_size
= TYPE_PRECISION (char32_type_node
);
5621 if (c_dialect_cxx ())
5623 char32_type_node
= make_unsigned_type (char32_type_size
);
5625 if (cxx_dialect
>= cxx11
)
5626 record_builtin_type (RID_CHAR32
, "char32_t", char32_type_node
);
5629 /* This is for UTF-32 string constants. */
5630 char32_array_type_node
5631 = build_array_type (char32_type_node
, array_domain_type
);
5634 TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE
)));
5637 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE
)));
5639 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE
)));
5641 if (SIG_ATOMIC_TYPE
)
5642 sig_atomic_type_node
=
5643 TREE_TYPE (identifier_global_value (c_get_ident (SIG_ATOMIC_TYPE
)));
5646 TREE_TYPE (identifier_global_value (c_get_ident (INT8_TYPE
)));
5649 TREE_TYPE (identifier_global_value (c_get_ident (INT16_TYPE
)));
5652 TREE_TYPE (identifier_global_value (c_get_ident (INT32_TYPE
)));
5655 TREE_TYPE (identifier_global_value (c_get_ident (INT64_TYPE
)));
5658 TREE_TYPE (identifier_global_value (c_get_ident (UINT8_TYPE
)));
5660 c_uint16_type_node
= uint16_type_node
=
5661 TREE_TYPE (identifier_global_value (c_get_ident (UINT16_TYPE
)));
5663 c_uint32_type_node
= uint32_type_node
=
5664 TREE_TYPE (identifier_global_value (c_get_ident (UINT32_TYPE
)));
5666 c_uint64_type_node
= uint64_type_node
=
5667 TREE_TYPE (identifier_global_value (c_get_ident (UINT64_TYPE
)));
5668 if (INT_LEAST8_TYPE
)
5669 int_least8_type_node
=
5670 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST8_TYPE
)));
5671 if (INT_LEAST16_TYPE
)
5672 int_least16_type_node
=
5673 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST16_TYPE
)));
5674 if (INT_LEAST32_TYPE
)
5675 int_least32_type_node
=
5676 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST32_TYPE
)));
5677 if (INT_LEAST64_TYPE
)
5678 int_least64_type_node
=
5679 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST64_TYPE
)));
5680 if (UINT_LEAST8_TYPE
)
5681 uint_least8_type_node
=
5682 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST8_TYPE
)));
5683 if (UINT_LEAST16_TYPE
)
5684 uint_least16_type_node
=
5685 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST16_TYPE
)));
5686 if (UINT_LEAST32_TYPE
)
5687 uint_least32_type_node
=
5688 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST32_TYPE
)));
5689 if (UINT_LEAST64_TYPE
)
5690 uint_least64_type_node
=
5691 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST64_TYPE
)));
5693 int_fast8_type_node
=
5694 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST8_TYPE
)));
5695 if (INT_FAST16_TYPE
)
5696 int_fast16_type_node
=
5697 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST16_TYPE
)));
5698 if (INT_FAST32_TYPE
)
5699 int_fast32_type_node
=
5700 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST32_TYPE
)));
5701 if (INT_FAST64_TYPE
)
5702 int_fast64_type_node
=
5703 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST64_TYPE
)));
5704 if (UINT_FAST8_TYPE
)
5705 uint_fast8_type_node
=
5706 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST8_TYPE
)));
5707 if (UINT_FAST16_TYPE
)
5708 uint_fast16_type_node
=
5709 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST16_TYPE
)));
5710 if (UINT_FAST32_TYPE
)
5711 uint_fast32_type_node
=
5712 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST32_TYPE
)));
5713 if (UINT_FAST64_TYPE
)
5714 uint_fast64_type_node
=
5715 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST64_TYPE
)));
5718 TREE_TYPE (identifier_global_value (c_get_ident (INTPTR_TYPE
)));
5721 TREE_TYPE (identifier_global_value (c_get_ident (UINTPTR_TYPE
)));
5723 default_function_type
5724 = build_varargs_function_type_list (integer_type_node
, NULL_TREE
);
5726 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE
)));
5727 unsigned_ptrdiff_type_node
= c_common_unsigned_type (ptrdiff_type_node
);
5729 lang_hooks
.decls
.pushdecl
5730 (build_decl (UNKNOWN_LOCATION
,
5731 TYPE_DECL
, get_identifier ("__builtin_va_list"),
5732 va_list_type_node
));
5733 if (targetm
.enum_va_list_p
)
5739 for (l
= 0; targetm
.enum_va_list_p (l
, &pname
, &ptype
); ++l
)
5741 lang_hooks
.decls
.pushdecl
5742 (build_decl (UNKNOWN_LOCATION
,
5743 TYPE_DECL
, get_identifier (pname
),
5749 if (TREE_CODE (va_list_type_node
) == ARRAY_TYPE
)
5751 va_list_arg_type_node
= va_list_ref_type_node
=
5752 build_pointer_type (TREE_TYPE (va_list_type_node
));
5756 va_list_arg_type_node
= va_list_type_node
;
5757 va_list_ref_type_node
= build_reference_type (va_list_type_node
);
5760 if (!flag_preprocess_only
)
5761 c_define_builtins (va_list_ref_type_node
, va_list_arg_type_node
);
5763 main_identifier_node
= get_identifier ("main");
5765 /* Create the built-in __null node. It is important that this is
5767 null_node
= make_int_cst (1, 1);
5768 TREE_TYPE (null_node
) = c_common_type_for_size (POINTER_SIZE
, 0);
5770 /* Since builtin_types isn't gc'ed, don't export these nodes. */
5771 memset (builtin_types
, 0, sizeof (builtin_types
));
5774 /* The number of named compound-literals generated thus far. */
5775 static GTY(()) int compound_literal_number
;
5777 /* Set DECL_NAME for DECL, a VAR_DECL for a compound-literal. */
5780 set_compound_literal_name (tree decl
)
5783 ASM_FORMAT_PRIVATE_NAME (name
, "__compound_literal",
5784 compound_literal_number
);
5785 compound_literal_number
++;
5786 DECL_NAME (decl
) = get_identifier (name
);
5790 build_va_arg (location_t loc
, tree expr
, tree type
)
5792 expr
= build1 (VA_ARG_EXPR
, type
, expr
);
5793 SET_EXPR_LOCATION (expr
, loc
);
5798 /* Linked list of disabled built-in functions. */
5800 typedef struct disabled_builtin
5803 struct disabled_builtin
*next
;
5805 static disabled_builtin
*disabled_builtins
= NULL
;
5807 static bool builtin_function_disabled_p (const char *);
5809 /* Disable a built-in function specified by -fno-builtin-NAME. If NAME
5810 begins with "__builtin_", give an error. */
5813 disable_builtin_function (const char *name
)
5815 if (strncmp (name
, "__builtin_", strlen ("__builtin_")) == 0)
5816 error ("cannot disable built-in function %qs", name
);
5819 disabled_builtin
*new_disabled_builtin
= XNEW (disabled_builtin
);
5820 new_disabled_builtin
->name
= name
;
5821 new_disabled_builtin
->next
= disabled_builtins
;
5822 disabled_builtins
= new_disabled_builtin
;
5827 /* Return true if the built-in function NAME has been disabled, false
5831 builtin_function_disabled_p (const char *name
)
5833 disabled_builtin
*p
;
5834 for (p
= disabled_builtins
; p
!= NULL
; p
= p
->next
)
5836 if (strcmp (name
, p
->name
) == 0)
5843 /* Worker for DEF_BUILTIN.
5844 Possibly define a builtin function with one or two names.
5845 Does not declare a non-__builtin_ function if flag_no_builtin, or if
5846 nonansi_p and flag_no_nonansi_builtin. */
5849 def_builtin_1 (enum built_in_function fncode
,
5851 enum built_in_class fnclass
,
5852 tree fntype
, tree libtype
,
5853 bool both_p
, bool fallback_p
, bool nonansi_p
,
5854 tree fnattrs
, bool implicit_p
)
5857 const char *libname
;
5859 if (fntype
== error_mark_node
)
5862 gcc_assert ((!both_p
&& !fallback_p
)
5863 || !strncmp (name
, "__builtin_",
5864 strlen ("__builtin_")));
5866 libname
= name
+ strlen ("__builtin_");
5867 decl
= add_builtin_function (name
, fntype
, fncode
, fnclass
,
5868 (fallback_p
? libname
: NULL
),
5871 set_builtin_decl (fncode
, decl
, implicit_p
);
5874 && !flag_no_builtin
&& !builtin_function_disabled_p (libname
)
5875 && !(nonansi_p
&& flag_no_nonansi_builtin
))
5876 add_builtin_function (libname
, libtype
, fncode
, fnclass
,
5880 /* Nonzero if the type T promotes to int. This is (nearly) the
5881 integral promotions defined in ISO C99 6.3.1.1/2. */
5884 c_promoting_integer_type_p (const_tree t
)
5886 switch (TREE_CODE (t
))
5889 return (TYPE_MAIN_VARIANT (t
) == char_type_node
5890 || TYPE_MAIN_VARIANT (t
) == signed_char_type_node
5891 || TYPE_MAIN_VARIANT (t
) == unsigned_char_type_node
5892 || TYPE_MAIN_VARIANT (t
) == short_integer_type_node
5893 || TYPE_MAIN_VARIANT (t
) == short_unsigned_type_node
5894 || TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
));
5897 /* ??? Technically all enumerations not larger than an int
5898 promote to an int. But this is used along code paths
5899 that only want to notice a size change. */
5900 return TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
);
5910 /* Return 1 if PARMS specifies a fixed number of parameters
5911 and none of their types is affected by default promotions. */
5914 self_promoting_args_p (const_tree parms
)
5917 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
5919 tree type
= TREE_VALUE (t
);
5921 if (type
== error_mark_node
)
5924 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
5930 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
5933 if (c_promoting_integer_type_p (type
))
5939 /* Recursively remove any '*' or '&' operator from TYPE. */
5941 strip_pointer_operator (tree t
)
5943 while (POINTER_TYPE_P (t
))
5948 /* Recursively remove pointer or array type from TYPE. */
5950 strip_pointer_or_array_types (tree t
)
5952 while (TREE_CODE (t
) == ARRAY_TYPE
|| POINTER_TYPE_P (t
))
5957 /* Used to compare case labels. K1 and K2 are actually tree nodes
5958 representing case labels, or NULL_TREE for a `default' label.
5959 Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after
5960 K2, and 0 if K1 and K2 are equal. */
5963 case_compare (splay_tree_key k1
, splay_tree_key k2
)
5965 /* Consider a NULL key (such as arises with a `default' label) to be
5966 smaller than anything else. */
5972 return tree_int_cst_compare ((tree
) k1
, (tree
) k2
);
5975 /* Process a case label, located at LOC, for the range LOW_VALUE
5976 ... HIGH_VALUE. If LOW_VALUE and HIGH_VALUE are both NULL_TREE
5977 then this case label is actually a `default' label. If only
5978 HIGH_VALUE is NULL_TREE, then case label was declared using the
5979 usual C/C++ syntax, rather than the GNU case range extension.
5980 CASES is a tree containing all the case ranges processed so far;
5981 COND is the condition for the switch-statement itself. Returns the
5982 CASE_LABEL_EXPR created, or ERROR_MARK_NODE if no CASE_LABEL_EXPR
5986 c_add_case_label (location_t loc
, splay_tree cases
, tree cond
, tree orig_type
,
5987 tree low_value
, tree high_value
)
5992 splay_tree_node node
;
5994 /* Create the LABEL_DECL itself. */
5995 label
= create_artificial_label (loc
);
5997 /* If there was an error processing the switch condition, bail now
5998 before we get more confused. */
5999 if (!cond
|| cond
== error_mark_node
)
6002 if ((low_value
&& TREE_TYPE (low_value
)
6003 && POINTER_TYPE_P (TREE_TYPE (low_value
)))
6004 || (high_value
&& TREE_TYPE (high_value
)
6005 && POINTER_TYPE_P (TREE_TYPE (high_value
))))
6007 error_at (loc
, "pointers are not permitted as case values");
6011 /* Case ranges are a GNU extension. */
6013 pedwarn (loc
, OPT_Wpedantic
,
6014 "range expressions in switch statements are non-standard");
6016 type
= TREE_TYPE (cond
);
6019 low_value
= check_case_value (low_value
);
6020 low_value
= convert_and_check (loc
, type
, low_value
);
6021 if (low_value
== error_mark_node
)
6026 high_value
= check_case_value (high_value
);
6027 high_value
= convert_and_check (loc
, type
, high_value
);
6028 if (high_value
== error_mark_node
)
6032 if (low_value
&& high_value
)
6034 /* If the LOW_VALUE and HIGH_VALUE are the same, then this isn't
6035 really a case range, even though it was written that way.
6036 Remove the HIGH_VALUE to simplify later processing. */
6037 if (tree_int_cst_equal (low_value
, high_value
))
6038 high_value
= NULL_TREE
;
6039 else if (!tree_int_cst_lt (low_value
, high_value
))
6040 warning_at (loc
, 0, "empty range specified");
6043 /* See if the case is in range of the type of the original testing
6044 expression. If both low_value and high_value are out of range,
6045 don't insert the case label and return NULL_TREE. */
6047 && !check_case_bounds (loc
, type
, orig_type
,
6048 &low_value
, high_value
? &high_value
: NULL
))
6051 /* Look up the LOW_VALUE in the table of case labels we already
6053 node
= splay_tree_lookup (cases
, (splay_tree_key
) low_value
);
6054 /* If there was not an exact match, check for overlapping ranges.
6055 There's no need to do this if there's no LOW_VALUE or HIGH_VALUE;
6056 that's a `default' label and the only overlap is an exact match. */
6057 if (!node
&& (low_value
|| high_value
))
6059 splay_tree_node low_bound
;
6060 splay_tree_node high_bound
;
6062 /* Even though there wasn't an exact match, there might be an
6063 overlap between this case range and another case range.
6064 Since we've (inductively) not allowed any overlapping case
6065 ranges, we simply need to find the greatest low case label
6066 that is smaller that LOW_VALUE, and the smallest low case
6067 label that is greater than LOW_VALUE. If there is an overlap
6068 it will occur in one of these two ranges. */
6069 low_bound
= splay_tree_predecessor (cases
,
6070 (splay_tree_key
) low_value
);
6071 high_bound
= splay_tree_successor (cases
,
6072 (splay_tree_key
) low_value
);
6074 /* Check to see if the LOW_BOUND overlaps. It is smaller than
6075 the LOW_VALUE, so there is no need to check unless the
6076 LOW_BOUND is in fact itself a case range. */
6078 && CASE_HIGH ((tree
) low_bound
->value
)
6079 && tree_int_cst_compare (CASE_HIGH ((tree
) low_bound
->value
),
6082 /* Check to see if the HIGH_BOUND overlaps. The low end of that
6083 range is bigger than the low end of the current range, so we
6084 are only interested if the current range is a real range, and
6085 not an ordinary case label. */
6088 && (tree_int_cst_compare ((tree
) high_bound
->key
,
6093 /* If there was an overlap, issue an error. */
6096 tree duplicate
= CASE_LABEL ((tree
) node
->value
);
6100 error_at (loc
, "duplicate (or overlapping) case value");
6101 error_at (DECL_SOURCE_LOCATION (duplicate
),
6102 "this is the first entry overlapping that value");
6106 error_at (loc
, "duplicate case value") ;
6107 error_at (DECL_SOURCE_LOCATION (duplicate
), "previously used here");
6111 error_at (loc
, "multiple default labels in one switch");
6112 error_at (DECL_SOURCE_LOCATION (duplicate
),
6113 "this is the first default label");
6118 /* Add a CASE_LABEL to the statement-tree. */
6119 case_label
= add_stmt (build_case_label (low_value
, high_value
, label
));
6120 /* Register this case label in the splay tree. */
6121 splay_tree_insert (cases
,
6122 (splay_tree_key
) low_value
,
6123 (splay_tree_value
) case_label
);
6128 /* Add a label so that the back-end doesn't think that the beginning of
6129 the switch is unreachable. Note that we do not add a case label, as
6130 that just leads to duplicates and thence to failure later on. */
6133 tree t
= create_artificial_label (loc
);
6134 add_stmt (build_stmt (loc
, LABEL_EXPR
, t
));
6136 return error_mark_node
;
6139 /* Subroutines of c_do_switch_warnings, called via splay_tree_foreach.
6140 Used to verify that case values match up with enumerator values. */
6143 match_case_to_enum_1 (tree key
, tree type
, tree label
)
6145 char buf
[WIDE_INT_PRINT_BUFFER_SIZE
];
6147 if (tree_fits_uhwi_p (key
))
6148 print_dec (key
, buf
, UNSIGNED
);
6149 else if (tree_fits_shwi_p (key
))
6150 print_dec (key
, buf
, SIGNED
);
6152 print_hex (key
, buf
);
6154 if (TYPE_NAME (type
) == 0)
6155 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
6156 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
6157 "case value %qs not in enumerated type",
6160 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
6161 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
6162 "case value %qs not in enumerated type %qT",
6166 /* Subroutine of c_do_switch_warnings, called via splay_tree_foreach.
6167 Used to verify that case values match up with enumerator values. */
6170 match_case_to_enum (splay_tree_node node
, void *data
)
6172 tree label
= (tree
) node
->value
;
6173 tree type
= (tree
) data
;
6175 /* Skip default case. */
6176 if (!CASE_LOW (label
))
6179 /* If CASE_LOW_SEEN is not set, that means CASE_LOW did not appear
6180 when we did our enum->case scan. Reset our scratch bit after. */
6181 if (!CASE_LOW_SEEN (label
))
6182 match_case_to_enum_1 (CASE_LOW (label
), type
, label
);
6184 CASE_LOW_SEEN (label
) = 0;
6186 /* If CASE_HIGH is non-null, we have a range. If CASE_HIGH_SEEN is
6187 not set, that means that CASE_HIGH did not appear when we did our
6188 enum->case scan. Reset our scratch bit after. */
6189 if (CASE_HIGH (label
))
6191 if (!CASE_HIGH_SEEN (label
))
6192 match_case_to_enum_1 (CASE_HIGH (label
), type
, label
);
6194 CASE_HIGH_SEEN (label
) = 0;
6200 /* Handle -Wswitch*. Called from the front end after parsing the
6201 switch construct. */
6202 /* ??? Should probably be somewhere generic, since other languages
6203 besides C and C++ would want this. At the moment, however, C/C++
6204 are the only tree-ssa languages that support enumerations at all,
6205 so the point is moot. */
6208 c_do_switch_warnings (splay_tree cases
, location_t switch_location
,
6209 tree type
, tree cond
)
6211 splay_tree_node default_node
;
6212 splay_tree_node node
;
6215 if (!warn_switch
&& !warn_switch_enum
&& !warn_switch_default
)
6218 default_node
= splay_tree_lookup (cases
, (splay_tree_key
) NULL
);
6220 warning_at (switch_location
, OPT_Wswitch_default
,
6221 "switch missing default case");
6223 /* From here on, we only care about about enumerated types. */
6224 if (!type
|| TREE_CODE (type
) != ENUMERAL_TYPE
)
6227 /* From here on, we only care about -Wswitch and -Wswitch-enum. */
6228 if (!warn_switch_enum
&& !warn_switch
)
6231 /* Check the cases. Warn about case values which are not members of
6232 the enumerated type. For -Wswitch-enum, or for -Wswitch when
6233 there is no default case, check that exactly all enumeration
6234 literals are covered by the cases. */
6236 /* Clearing COND if it is not an integer constant simplifies
6237 the tests inside the loop below. */
6238 if (TREE_CODE (cond
) != INTEGER_CST
)
6241 /* The time complexity here is O(N*lg(N)) worst case, but for the
6242 common case of monotonically increasing enumerators, it is
6243 O(N), since the nature of the splay tree will keep the next
6244 element adjacent to the root at all times. */
6246 for (chain
= TYPE_VALUES (type
); chain
; chain
= TREE_CHAIN (chain
))
6248 tree value
= TREE_VALUE (chain
);
6249 if (TREE_CODE (value
) == CONST_DECL
)
6250 value
= DECL_INITIAL (value
);
6251 node
= splay_tree_lookup (cases
, (splay_tree_key
) value
);
6254 /* Mark the CASE_LOW part of the case entry as seen. */
6255 tree label
= (tree
) node
->value
;
6256 CASE_LOW_SEEN (label
) = 1;
6260 /* Even though there wasn't an exact match, there might be a
6261 case range which includes the enumerator's value. */
6262 node
= splay_tree_predecessor (cases
, (splay_tree_key
) value
);
6263 if (node
&& CASE_HIGH ((tree
) node
->value
))
6265 tree label
= (tree
) node
->value
;
6266 int cmp
= tree_int_cst_compare (CASE_HIGH (label
), value
);
6269 /* If we match the upper bound exactly, mark the CASE_HIGH
6270 part of the case entry as seen. */
6272 CASE_HIGH_SEEN (label
) = 1;
6277 /* We've now determined that this enumerated literal isn't
6278 handled by the case labels of the switch statement. */
6280 /* If the switch expression is a constant, we only really care
6281 about whether that constant is handled by the switch. */
6282 if (cond
&& tree_int_cst_compare (cond
, value
))
6285 /* If there is a default_node, the only relevant option is
6286 Wswitch-enum. Otherwise, if both are enabled then we prefer
6287 to warn using -Wswitch because -Wswitch is enabled by -Wall
6288 while -Wswitch-enum is explicit. */
6289 warning_at (switch_location
,
6290 (default_node
|| !warn_switch
6293 "enumeration value %qE not handled in switch",
6294 TREE_PURPOSE (chain
));
6297 /* Warn if there are case expressions that don't correspond to
6298 enumerators. This can occur since C and C++ don't enforce
6299 type-checking of assignments to enumeration variables.
6301 The time complexity here is now always O(N) worst case, since
6302 we should have marked both the lower bound and upper bound of
6303 every disjoint case label, with CASE_LOW_SEEN and CASE_HIGH_SEEN
6304 above. This scan also resets those fields. */
6306 splay_tree_foreach (cases
, match_case_to_enum
, type
);
6309 /* Finish an expression taking the address of LABEL (an
6310 IDENTIFIER_NODE). Returns an expression for the address.
6312 LOC is the location for the expression returned. */
6315 finish_label_address_expr (tree label
, location_t loc
)
6319 pedwarn (input_location
, OPT_Wpedantic
, "taking the address of a label is non-standard");
6321 if (label
== error_mark_node
)
6322 return error_mark_node
;
6324 label
= lookup_label (label
);
6325 if (label
== NULL_TREE
)
6326 result
= null_pointer_node
;
6329 TREE_USED (label
) = 1;
6330 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
6331 /* The current function is not necessarily uninlinable.
6332 Computed gotos are incompatible with inlining, but the value
6333 here could be used only in a diagnostic, for example. */
6334 protected_set_expr_location (result
, loc
);
6341 /* Given a boolean expression ARG, return a tree representing an increment
6342 or decrement (as indicated by CODE) of ARG. The front end must check for
6343 invalid cases (e.g., decrement in C++). */
6345 boolean_increment (enum tree_code code
, tree arg
)
6348 tree true_res
= build_int_cst (TREE_TYPE (arg
), 1);
6350 arg
= stabilize_reference (arg
);
6353 case PREINCREMENT_EXPR
:
6354 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
6356 case POSTINCREMENT_EXPR
:
6357 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
6358 arg
= save_expr (arg
);
6359 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
6360 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
6362 case PREDECREMENT_EXPR
:
6363 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
6364 invert_truthvalue_loc (input_location
, arg
));
6366 case POSTDECREMENT_EXPR
:
6367 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
6368 invert_truthvalue_loc (input_location
, arg
));
6369 arg
= save_expr (arg
);
6370 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
6371 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
6376 TREE_SIDE_EFFECTS (val
) = 1;
6380 /* Built-in macros for stddef.h and stdint.h, that require macros
6381 defined in this file. */
6383 c_stddef_cpp_builtins(void)
6385 builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE
, 0);
6386 builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE
, 0);
6387 builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE
, 0);
6388 builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE
, 0);
6389 builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE
, 0);
6390 builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE
, 0);
6391 builtin_define_with_value ("__CHAR16_TYPE__", CHAR16_TYPE
, 0);
6392 builtin_define_with_value ("__CHAR32_TYPE__", CHAR32_TYPE
, 0);
6393 if (SIG_ATOMIC_TYPE
)
6394 builtin_define_with_value ("__SIG_ATOMIC_TYPE__", SIG_ATOMIC_TYPE
, 0);
6396 builtin_define_with_value ("__INT8_TYPE__", INT8_TYPE
, 0);
6398 builtin_define_with_value ("__INT16_TYPE__", INT16_TYPE
, 0);
6400 builtin_define_with_value ("__INT32_TYPE__", INT32_TYPE
, 0);
6402 builtin_define_with_value ("__INT64_TYPE__", INT64_TYPE
, 0);
6404 builtin_define_with_value ("__UINT8_TYPE__", UINT8_TYPE
, 0);
6406 builtin_define_with_value ("__UINT16_TYPE__", UINT16_TYPE
, 0);
6408 builtin_define_with_value ("__UINT32_TYPE__", UINT32_TYPE
, 0);
6410 builtin_define_with_value ("__UINT64_TYPE__", UINT64_TYPE
, 0);
6411 if (INT_LEAST8_TYPE
)
6412 builtin_define_with_value ("__INT_LEAST8_TYPE__", INT_LEAST8_TYPE
, 0);
6413 if (INT_LEAST16_TYPE
)
6414 builtin_define_with_value ("__INT_LEAST16_TYPE__", INT_LEAST16_TYPE
, 0);
6415 if (INT_LEAST32_TYPE
)
6416 builtin_define_with_value ("__INT_LEAST32_TYPE__", INT_LEAST32_TYPE
, 0);
6417 if (INT_LEAST64_TYPE
)
6418 builtin_define_with_value ("__INT_LEAST64_TYPE__", INT_LEAST64_TYPE
, 0);
6419 if (UINT_LEAST8_TYPE
)
6420 builtin_define_with_value ("__UINT_LEAST8_TYPE__", UINT_LEAST8_TYPE
, 0);
6421 if (UINT_LEAST16_TYPE
)
6422 builtin_define_with_value ("__UINT_LEAST16_TYPE__", UINT_LEAST16_TYPE
, 0);
6423 if (UINT_LEAST32_TYPE
)
6424 builtin_define_with_value ("__UINT_LEAST32_TYPE__", UINT_LEAST32_TYPE
, 0);
6425 if (UINT_LEAST64_TYPE
)
6426 builtin_define_with_value ("__UINT_LEAST64_TYPE__", UINT_LEAST64_TYPE
, 0);
6428 builtin_define_with_value ("__INT_FAST8_TYPE__", INT_FAST8_TYPE
, 0);
6429 if (INT_FAST16_TYPE
)
6430 builtin_define_with_value ("__INT_FAST16_TYPE__", INT_FAST16_TYPE
, 0);
6431 if (INT_FAST32_TYPE
)
6432 builtin_define_with_value ("__INT_FAST32_TYPE__", INT_FAST32_TYPE
, 0);
6433 if (INT_FAST64_TYPE
)
6434 builtin_define_with_value ("__INT_FAST64_TYPE__", INT_FAST64_TYPE
, 0);
6435 if (UINT_FAST8_TYPE
)
6436 builtin_define_with_value ("__UINT_FAST8_TYPE__", UINT_FAST8_TYPE
, 0);
6437 if (UINT_FAST16_TYPE
)
6438 builtin_define_with_value ("__UINT_FAST16_TYPE__", UINT_FAST16_TYPE
, 0);
6439 if (UINT_FAST32_TYPE
)
6440 builtin_define_with_value ("__UINT_FAST32_TYPE__", UINT_FAST32_TYPE
, 0);
6441 if (UINT_FAST64_TYPE
)
6442 builtin_define_with_value ("__UINT_FAST64_TYPE__", UINT_FAST64_TYPE
, 0);
6444 builtin_define_with_value ("__INTPTR_TYPE__", INTPTR_TYPE
, 0);
6446 builtin_define_with_value ("__UINTPTR_TYPE__", UINTPTR_TYPE
, 0);
6450 c_init_attributes (void)
6452 /* Fill in the built_in_attributes array. */
6453 #define DEF_ATTR_NULL_TREE(ENUM) \
6454 built_in_attributes[(int) ENUM] = NULL_TREE;
6455 #define DEF_ATTR_INT(ENUM, VALUE) \
6456 built_in_attributes[(int) ENUM] = build_int_cst (integer_type_node, VALUE);
6457 #define DEF_ATTR_STRING(ENUM, VALUE) \
6458 built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
6459 #define DEF_ATTR_IDENT(ENUM, STRING) \
6460 built_in_attributes[(int) ENUM] = get_identifier (STRING);
6461 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
6462 built_in_attributes[(int) ENUM] \
6463 = tree_cons (built_in_attributes[(int) PURPOSE], \
6464 built_in_attributes[(int) VALUE], \
6465 built_in_attributes[(int) CHAIN]);
6466 #include "builtin-attrs.def"
6467 #undef DEF_ATTR_NULL_TREE
6469 #undef DEF_ATTR_IDENT
6470 #undef DEF_ATTR_TREE_LIST
6473 /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain
6474 identifier as an argument, so the front end shouldn't look it up. */
6477 attribute_takes_identifier_p (const_tree attr_id
)
6479 const struct attribute_spec
*spec
= lookup_attribute_spec (attr_id
);
6481 /* Unknown attribute that we'll end up ignoring, return true so we
6482 don't complain about an identifier argument. */
6484 else if (!strcmp ("mode", spec
->name
)
6485 || !strcmp ("format", spec
->name
)
6486 || !strcmp ("cleanup", spec
->name
))
6489 return targetm
.attribute_takes_identifier_p (attr_id
);
6492 /* Attribute handlers common to C front ends. */
6494 /* Handle a "packed" attribute; arguments as in
6495 struct attribute_spec.handler. */
6498 handle_packed_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6499 int flags
, bool *no_add_attrs
)
6503 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6504 *node
= build_variant_type_copy (*node
);
6505 TYPE_PACKED (*node
) = 1;
6507 else if (TREE_CODE (*node
) == FIELD_DECL
)
6509 if (TYPE_ALIGN (TREE_TYPE (*node
)) <= BITS_PER_UNIT
6510 /* Still pack bitfields. */
6511 && ! DECL_INITIAL (*node
))
6512 warning (OPT_Wattributes
,
6513 "%qE attribute ignored for field of type %qT",
6514 name
, TREE_TYPE (*node
));
6516 DECL_PACKED (*node
) = 1;
6518 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
6519 used for DECL_REGISTER. It wouldn't mean anything anyway.
6520 We can't set DECL_PACKED on the type of a TYPE_DECL, because
6521 that changes what the typedef is typing. */
6524 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6525 *no_add_attrs
= true;
6531 /* Handle a "nocommon" attribute; arguments as in
6532 struct attribute_spec.handler. */
6535 handle_nocommon_attribute (tree
*node
, tree name
,
6536 tree
ARG_UNUSED (args
),
6537 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6539 if (TREE_CODE (*node
) == VAR_DECL
)
6540 DECL_COMMON (*node
) = 0;
6543 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6544 *no_add_attrs
= true;
6550 /* Handle a "common" attribute; arguments as in
6551 struct attribute_spec.handler. */
6554 handle_common_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6555 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6557 if (TREE_CODE (*node
) == VAR_DECL
)
6558 DECL_COMMON (*node
) = 1;
6561 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6562 *no_add_attrs
= true;
6568 /* Handle a "noreturn" attribute; arguments as in
6569 struct attribute_spec.handler. */
6572 handle_noreturn_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6573 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6575 tree type
= TREE_TYPE (*node
);
6577 /* See FIXME comment in c_common_attribute_table. */
6578 if (TREE_CODE (*node
) == FUNCTION_DECL
6579 || objc_method_decl (TREE_CODE (*node
)))
6580 TREE_THIS_VOLATILE (*node
) = 1;
6581 else if (TREE_CODE (type
) == POINTER_TYPE
6582 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
6584 = build_pointer_type
6585 (build_type_variant (TREE_TYPE (type
),
6586 TYPE_READONLY (TREE_TYPE (type
)), 1));
6589 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6590 *no_add_attrs
= true;
6596 /* Handle a "hot" and attribute; arguments as in
6597 struct attribute_spec.handler. */
6600 handle_hot_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6601 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6603 if (TREE_CODE (*node
) == FUNCTION_DECL
6604 || TREE_CODE (*node
) == LABEL_DECL
)
6606 if (lookup_attribute ("cold", DECL_ATTRIBUTES (*node
)) != NULL
)
6608 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
6609 "with attribute %qs", name
, "cold");
6610 *no_add_attrs
= true;
6612 /* Most of the rest of the hot processing is done later with
6613 lookup_attribute. */
6617 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6618 *no_add_attrs
= true;
6624 /* Handle a "cold" and attribute; arguments as in
6625 struct attribute_spec.handler. */
6628 handle_cold_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6629 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6631 if (TREE_CODE (*node
) == FUNCTION_DECL
6632 || TREE_CODE (*node
) == LABEL_DECL
)
6634 if (lookup_attribute ("hot", DECL_ATTRIBUTES (*node
)) != NULL
)
6636 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
6637 "with attribute %qs", name
, "hot");
6638 *no_add_attrs
= true;
6640 /* Most of the rest of the cold processing is done later with
6641 lookup_attribute. */
6645 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6646 *no_add_attrs
= true;
6652 /* Handle a "no_sanitize_address" attribute; arguments as in
6653 struct attribute_spec.handler. */
6656 handle_no_sanitize_address_attribute (tree
*node
, tree name
, tree
, int,
6659 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6661 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6662 *no_add_attrs
= true;
6668 /* Handle a "no_address_safety_analysis" attribute; arguments as in
6669 struct attribute_spec.handler. */
6672 handle_no_address_safety_analysis_attribute (tree
*node
, tree name
, tree
, int,
6675 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6676 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6677 else if (!lookup_attribute ("no_sanitize_address", DECL_ATTRIBUTES (*node
)))
6678 DECL_ATTRIBUTES (*node
)
6679 = tree_cons (get_identifier ("no_sanitize_address"),
6680 NULL_TREE
, DECL_ATTRIBUTES (*node
));
6681 *no_add_attrs
= true;
6685 /* Handle a "no_sanitize_undefined" attribute; arguments as in
6686 struct attribute_spec.handler. */
6689 handle_no_sanitize_undefined_attribute (tree
*node
, tree name
, tree
, int,
6692 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6694 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6695 *no_add_attrs
= true;
6701 /* Handle a "noinline" attribute; arguments as in
6702 struct attribute_spec.handler. */
6705 handle_noinline_attribute (tree
*node
, tree name
,
6706 tree
ARG_UNUSED (args
),
6707 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6709 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6711 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node
)))
6713 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
6714 "with attribute %qs", name
, "always_inline");
6715 *no_add_attrs
= true;
6718 DECL_UNINLINABLE (*node
) = 1;
6722 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6723 *no_add_attrs
= true;
6729 /* Handle a "noclone" attribute; arguments as in
6730 struct attribute_spec.handler. */
6733 handle_noclone_attribute (tree
*node
, tree name
,
6734 tree
ARG_UNUSED (args
),
6735 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6737 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6739 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6740 *no_add_attrs
= true;
6746 /* Handle a "always_inline" attribute; arguments as in
6747 struct attribute_spec.handler. */
6750 handle_always_inline_attribute (tree
*node
, tree name
,
6751 tree
ARG_UNUSED (args
),
6752 int ARG_UNUSED (flags
),
6755 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6757 if (lookup_attribute ("noinline", DECL_ATTRIBUTES (*node
)))
6759 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
6760 "with %qs attribute", name
, "noinline");
6761 *no_add_attrs
= true;
6764 /* Set the attribute and mark it for disregarding inline
6766 DECL_DISREGARD_INLINE_LIMITS (*node
) = 1;
6770 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6771 *no_add_attrs
= true;
6777 /* Handle a "gnu_inline" attribute; arguments as in
6778 struct attribute_spec.handler. */
6781 handle_gnu_inline_attribute (tree
*node
, tree name
,
6782 tree
ARG_UNUSED (args
),
6783 int ARG_UNUSED (flags
),
6786 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
6788 /* Do nothing else, just set the attribute. We'll get at
6789 it later with lookup_attribute. */
6793 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6794 *no_add_attrs
= true;
6800 /* Handle a "leaf" attribute; arguments as in
6801 struct attribute_spec.handler. */
6804 handle_leaf_attribute (tree
*node
, tree name
,
6805 tree
ARG_UNUSED (args
),
6806 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6808 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6810 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6811 *no_add_attrs
= true;
6813 if (!TREE_PUBLIC (*node
))
6815 warning (OPT_Wattributes
, "%qE attribute has no effect on unit local functions", name
);
6816 *no_add_attrs
= true;
6822 /* Handle an "artificial" attribute; arguments as in
6823 struct attribute_spec.handler. */
6826 handle_artificial_attribute (tree
*node
, tree name
,
6827 tree
ARG_UNUSED (args
),
6828 int ARG_UNUSED (flags
),
6831 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
6833 /* Do nothing else, just set the attribute. We'll get at
6834 it later with lookup_attribute. */
6838 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6839 *no_add_attrs
= true;
6845 /* Handle a "flatten" attribute; arguments as in
6846 struct attribute_spec.handler. */
6849 handle_flatten_attribute (tree
*node
, tree name
,
6850 tree args ATTRIBUTE_UNUSED
,
6851 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
6853 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6854 /* Do nothing else, just set the attribute. We'll get at
6855 it later with lookup_attribute. */
6859 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6860 *no_add_attrs
= true;
6866 /* Handle a "warning" or "error" attribute; arguments as in
6867 struct attribute_spec.handler. */
6870 handle_error_attribute (tree
*node
, tree name
, tree args
,
6871 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6873 if (TREE_CODE (*node
) == FUNCTION_DECL
6874 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
6875 /* Do nothing else, just set the attribute. We'll get at
6876 it later with lookup_attribute. */
6880 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6881 *no_add_attrs
= true;
6887 /* Handle a "used" attribute; arguments as in
6888 struct attribute_spec.handler. */
6891 handle_used_attribute (tree
*pnode
, tree name
, tree
ARG_UNUSED (args
),
6892 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6896 if (TREE_CODE (node
) == FUNCTION_DECL
6897 || (TREE_CODE (node
) == VAR_DECL
&& TREE_STATIC (node
))
6898 || (TREE_CODE (node
) == TYPE_DECL
))
6900 TREE_USED (node
) = 1;
6901 DECL_PRESERVE_P (node
) = 1;
6902 if (TREE_CODE (node
) == VAR_DECL
)
6903 DECL_READ_P (node
) = 1;
6907 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6908 *no_add_attrs
= true;
6914 /* Handle a "unused" attribute; arguments as in
6915 struct attribute_spec.handler. */
6918 handle_unused_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6919 int flags
, bool *no_add_attrs
)
6925 if (TREE_CODE (decl
) == PARM_DECL
6926 || TREE_CODE (decl
) == VAR_DECL
6927 || TREE_CODE (decl
) == FUNCTION_DECL
6928 || TREE_CODE (decl
) == LABEL_DECL
6929 || TREE_CODE (decl
) == TYPE_DECL
)
6931 TREE_USED (decl
) = 1;
6932 if (TREE_CODE (decl
) == VAR_DECL
6933 || TREE_CODE (decl
) == PARM_DECL
)
6934 DECL_READ_P (decl
) = 1;
6938 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6939 *no_add_attrs
= true;
6944 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6945 *node
= build_variant_type_copy (*node
);
6946 TREE_USED (*node
) = 1;
6952 /* Handle a "externally_visible" attribute; arguments as in
6953 struct attribute_spec.handler. */
6956 handle_externally_visible_attribute (tree
*pnode
, tree name
,
6957 tree
ARG_UNUSED (args
),
6958 int ARG_UNUSED (flags
),
6963 if (TREE_CODE (node
) == FUNCTION_DECL
|| TREE_CODE (node
) == VAR_DECL
)
6965 if ((!TREE_STATIC (node
) && TREE_CODE (node
) != FUNCTION_DECL
6966 && !DECL_EXTERNAL (node
)) || !TREE_PUBLIC (node
))
6968 warning (OPT_Wattributes
,
6969 "%qE attribute have effect only on public objects", name
);
6970 *no_add_attrs
= true;
6975 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6976 *no_add_attrs
= true;
6982 /* Handle a "const" attribute; arguments as in
6983 struct attribute_spec.handler. */
6986 handle_const_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6987 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6989 tree type
= TREE_TYPE (*node
);
6991 /* See FIXME comment on noreturn in c_common_attribute_table. */
6992 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6993 TREE_READONLY (*node
) = 1;
6994 else if (TREE_CODE (type
) == POINTER_TYPE
6995 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
6997 = build_pointer_type
6998 (build_type_variant (TREE_TYPE (type
), 1,
6999 TREE_THIS_VOLATILE (TREE_TYPE (type
))));
7002 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7003 *no_add_attrs
= true;
7009 /* Handle a "transparent_union" attribute; arguments as in
7010 struct attribute_spec.handler. */
7013 handle_transparent_union_attribute (tree
*node
, tree name
,
7014 tree
ARG_UNUSED (args
), int flags
,
7019 *no_add_attrs
= true;
7022 if (TREE_CODE (*node
) == TYPE_DECL
7023 && ! (flags
& ATTR_FLAG_CXX11
))
7024 node
= &TREE_TYPE (*node
);
7027 if (TREE_CODE (type
) == UNION_TYPE
)
7029 /* Make sure that the first field will work for a transparent union.
7030 If the type isn't complete yet, leave the check to the code in
7032 if (TYPE_SIZE (type
))
7034 tree first
= first_field (type
);
7035 if (first
== NULL_TREE
7036 || DECL_ARTIFICIAL (first
)
7037 || TYPE_MODE (type
) != DECL_MODE (first
))
7041 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7043 /* If the type isn't complete yet, setting the flag
7044 on a variant wouldn't ever be checked. */
7045 if (!TYPE_SIZE (type
))
7048 /* build_duplicate_type doesn't work for C++. */
7049 if (c_dialect_cxx ())
7052 /* A type variant isn't good enough, since we don't a cast
7053 to such a type removed as a no-op. */
7054 *node
= type
= build_duplicate_type (type
);
7057 TYPE_TRANSPARENT_AGGR (type
) = 1;
7062 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7066 /* Subroutine of handle_{con,de}structor_attribute. Evaluate ARGS to
7067 get the requested priority for a constructor or destructor,
7068 possibly issuing diagnostics for invalid or reserved
7071 static priority_type
7072 get_priority (tree args
, bool is_destructor
)
7078 return DEFAULT_INIT_PRIORITY
;
7080 if (!SUPPORTS_INIT_PRIORITY
)
7083 error ("destructor priorities are not supported");
7085 error ("constructor priorities are not supported");
7086 return DEFAULT_INIT_PRIORITY
;
7089 arg
= TREE_VALUE (args
);
7090 if (TREE_CODE (arg
) == IDENTIFIER_NODE
)
7092 if (arg
== error_mark_node
)
7093 return DEFAULT_INIT_PRIORITY
;
7094 arg
= default_conversion (arg
);
7095 if (!tree_fits_shwi_p (arg
)
7096 || !INTEGRAL_TYPE_P (TREE_TYPE (arg
)))
7099 pri
= tree_to_shwi (arg
);
7100 if (pri
< 0 || pri
> MAX_INIT_PRIORITY
)
7103 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
7107 "destructor priorities from 0 to %d are reserved "
7108 "for the implementation",
7109 MAX_RESERVED_INIT_PRIORITY
);
7112 "constructor priorities from 0 to %d are reserved "
7113 "for the implementation",
7114 MAX_RESERVED_INIT_PRIORITY
);
7120 error ("destructor priorities must be integers from 0 to %d inclusive",
7123 error ("constructor priorities must be integers from 0 to %d inclusive",
7125 return DEFAULT_INIT_PRIORITY
;
7128 /* Handle a "constructor" attribute; arguments as in
7129 struct attribute_spec.handler. */
7132 handle_constructor_attribute (tree
*node
, tree name
, tree args
,
7133 int ARG_UNUSED (flags
),
7137 tree type
= TREE_TYPE (decl
);
7139 if (TREE_CODE (decl
) == FUNCTION_DECL
7140 && TREE_CODE (type
) == FUNCTION_TYPE
7141 && decl_function_context (decl
) == 0)
7143 priority_type priority
;
7144 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
7145 priority
= get_priority (args
, /*is_destructor=*/false);
7146 SET_DECL_INIT_PRIORITY (decl
, priority
);
7147 TREE_USED (decl
) = 1;
7151 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7152 *no_add_attrs
= true;
7158 /* Handle a "destructor" attribute; arguments as in
7159 struct attribute_spec.handler. */
7162 handle_destructor_attribute (tree
*node
, tree name
, tree args
,
7163 int ARG_UNUSED (flags
),
7167 tree type
= TREE_TYPE (decl
);
7169 if (TREE_CODE (decl
) == FUNCTION_DECL
7170 && TREE_CODE (type
) == FUNCTION_TYPE
7171 && decl_function_context (decl
) == 0)
7173 priority_type priority
;
7174 DECL_STATIC_DESTRUCTOR (decl
) = 1;
7175 priority
= get_priority (args
, /*is_destructor=*/true);
7176 SET_DECL_FINI_PRIORITY (decl
, priority
);
7177 TREE_USED (decl
) = 1;
7181 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7182 *no_add_attrs
= true;
7188 /* Nonzero if the mode is a valid vector mode for this architecture.
7189 This returns nonzero even if there is no hardware support for the
7190 vector mode, but we can emulate with narrower modes. */
7193 vector_mode_valid_p (enum machine_mode mode
)
7195 enum mode_class mclass
= GET_MODE_CLASS (mode
);
7196 enum machine_mode innermode
;
7198 /* Doh! What's going on? */
7199 if (mclass
!= MODE_VECTOR_INT
7200 && mclass
!= MODE_VECTOR_FLOAT
7201 && mclass
!= MODE_VECTOR_FRACT
7202 && mclass
!= MODE_VECTOR_UFRACT
7203 && mclass
!= MODE_VECTOR_ACCUM
7204 && mclass
!= MODE_VECTOR_UACCUM
)
7207 /* Hardware support. Woo hoo! */
7208 if (targetm
.vector_mode_supported_p (mode
))
7211 innermode
= GET_MODE_INNER (mode
);
7213 /* We should probably return 1 if requesting V4DI and we have no DI,
7214 but we have V2DI, but this is probably very unlikely. */
7216 /* If we have support for the inner mode, we can safely emulate it.
7217 We may not have V2DI, but me can emulate with a pair of DIs. */
7218 return targetm
.scalar_mode_supported_p (innermode
);
7222 /* Handle a "mode" attribute; arguments as in
7223 struct attribute_spec.handler. */
7226 handle_mode_attribute (tree
*node
, tree name
, tree args
,
7227 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7230 tree ident
= TREE_VALUE (args
);
7232 *no_add_attrs
= true;
7234 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
7235 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7239 const char *p
= IDENTIFIER_POINTER (ident
);
7240 int len
= strlen (p
);
7241 enum machine_mode mode
= VOIDmode
;
7245 if (len
> 4 && p
[0] == '_' && p
[1] == '_'
7246 && p
[len
- 1] == '_' && p
[len
- 2] == '_')
7248 char *newp
= (char *) alloca (len
- 1);
7250 strcpy (newp
, &p
[2]);
7251 newp
[len
- 4] = '\0';
7255 /* Change this type to have a type with the specified mode.
7256 First check for the special modes. */
7257 if (!strcmp (p
, "byte"))
7259 else if (!strcmp (p
, "word"))
7261 else if (!strcmp (p
, "pointer"))
7263 else if (!strcmp (p
, "libgcc_cmp_return"))
7264 mode
= targetm
.libgcc_cmp_return_mode ();
7265 else if (!strcmp (p
, "libgcc_shift_count"))
7266 mode
= targetm
.libgcc_shift_count_mode ();
7267 else if (!strcmp (p
, "unwind_word"))
7268 mode
= targetm
.unwind_word_mode ();
7270 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
7271 if (!strcmp (p
, GET_MODE_NAME (j
)))
7273 mode
= (enum machine_mode
) j
;
7277 if (mode
== VOIDmode
)
7279 error ("unknown machine mode %qE", ident
);
7284 switch (GET_MODE_CLASS (mode
))
7287 case MODE_PARTIAL_INT
:
7289 case MODE_DECIMAL_FLOAT
:
7294 valid_mode
= targetm
.scalar_mode_supported_p (mode
);
7297 case MODE_COMPLEX_INT
:
7298 case MODE_COMPLEX_FLOAT
:
7299 valid_mode
= targetm
.scalar_mode_supported_p (GET_MODE_INNER (mode
));
7302 case MODE_VECTOR_INT
:
7303 case MODE_VECTOR_FLOAT
:
7304 case MODE_VECTOR_FRACT
:
7305 case MODE_VECTOR_UFRACT
:
7306 case MODE_VECTOR_ACCUM
:
7307 case MODE_VECTOR_UACCUM
:
7308 warning (OPT_Wattributes
, "specifying vector types with "
7309 "__attribute__ ((mode)) is deprecated");
7310 warning (OPT_Wattributes
,
7311 "use __attribute__ ((vector_size)) instead");
7312 valid_mode
= vector_mode_valid_p (mode
);
7320 error ("unable to emulate %qs", p
);
7324 if (POINTER_TYPE_P (type
))
7326 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
7327 tree (*fn
)(tree
, enum machine_mode
, bool);
7329 if (!targetm
.addr_space
.valid_pointer_mode (mode
, as
))
7331 error ("invalid pointer mode %qs", p
);
7335 if (TREE_CODE (type
) == POINTER_TYPE
)
7336 fn
= build_pointer_type_for_mode
;
7338 fn
= build_reference_type_for_mode
;
7339 typefm
= fn (TREE_TYPE (type
), mode
, false);
7343 /* For fixed-point modes, we need to test if the signness of type
7344 and the machine mode are consistent. */
7345 if (ALL_FIXED_POINT_MODE_P (mode
)
7346 && TYPE_UNSIGNED (type
) != UNSIGNED_FIXED_POINT_MODE_P (mode
))
7348 error ("signedness of type and machine mode %qs don%'t match", p
);
7351 /* For fixed-point modes, we need to pass saturating info. */
7352 typefm
= lang_hooks
.types
.type_for_mode (mode
,
7353 ALL_FIXED_POINT_MODE_P (mode
) ? TYPE_SATURATING (type
)
7354 : TYPE_UNSIGNED (type
));
7357 if (typefm
== NULL_TREE
)
7359 error ("no data type for mode %qs", p
);
7362 else if (TREE_CODE (type
) == ENUMERAL_TYPE
)
7364 /* For enumeral types, copy the precision from the integer
7365 type returned above. If not an INTEGER_TYPE, we can't use
7366 this mode for this type. */
7367 if (TREE_CODE (typefm
) != INTEGER_TYPE
)
7369 error ("cannot use mode %qs for enumeral types", p
);
7373 if (flags
& ATTR_FLAG_TYPE_IN_PLACE
)
7375 TYPE_PRECISION (type
) = TYPE_PRECISION (typefm
);
7380 /* We cannot build a type variant, as there's code that assumes
7381 that TYPE_MAIN_VARIANT has the same mode. This includes the
7382 debug generators. Instead, create a subrange type. This
7383 results in all of the enumeral values being emitted only once
7384 in the original, and the subtype gets them by reference. */
7385 if (TYPE_UNSIGNED (type
))
7386 typefm
= make_unsigned_type (TYPE_PRECISION (typefm
));
7388 typefm
= make_signed_type (TYPE_PRECISION (typefm
));
7389 TREE_TYPE (typefm
) = type
;
7392 else if (VECTOR_MODE_P (mode
)
7393 ? TREE_CODE (type
) != TREE_CODE (TREE_TYPE (typefm
))
7394 : TREE_CODE (type
) != TREE_CODE (typefm
))
7396 error ("mode %qs applied to inappropriate type", p
);
7406 /* Handle a "section" attribute; arguments as in
7407 struct attribute_spec.handler. */
7410 handle_section_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7411 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7415 if (targetm_common
.have_named_sections
)
7417 user_defined_section_attribute
= true;
7419 if ((TREE_CODE (decl
) == FUNCTION_DECL
7420 || TREE_CODE (decl
) == VAR_DECL
)
7421 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
7423 if (TREE_CODE (decl
) == VAR_DECL
7424 && current_function_decl
!= NULL_TREE
7425 && !TREE_STATIC (decl
))
7427 error_at (DECL_SOURCE_LOCATION (decl
),
7428 "section attribute cannot be specified for "
7430 *no_add_attrs
= true;
7433 /* The decl may have already been given a section attribute
7434 from a previous declaration. Ensure they match. */
7435 else if (DECL_SECTION_NAME (decl
) != NULL
7436 && strcmp (DECL_SECTION_NAME (decl
),
7437 TREE_STRING_POINTER (TREE_VALUE (args
))) != 0)
7439 error ("section of %q+D conflicts with previous declaration",
7441 *no_add_attrs
= true;
7443 else if (TREE_CODE (decl
) == VAR_DECL
7444 && !targetm
.have_tls
&& targetm
.emutls
.tmpl_section
7445 && DECL_THREAD_LOCAL_P (decl
))
7447 error ("section of %q+D cannot be overridden", *node
);
7448 *no_add_attrs
= true;
7451 set_decl_section_name (decl
,
7452 TREE_STRING_POINTER (TREE_VALUE (args
)));
7456 error ("section attribute not allowed for %q+D", *node
);
7457 *no_add_attrs
= true;
7462 error_at (DECL_SOURCE_LOCATION (*node
),
7463 "section attributes are not supported for this target");
7464 *no_add_attrs
= true;
7470 /* Check whether ALIGN is a valid user-specified alignment. If so,
7471 return its base-2 log; if not, output an error and return -1. If
7472 ALLOW_ZERO then 0 is valid and should result in a return of -1 with
7475 check_user_alignment (const_tree align
, bool allow_zero
)
7479 if (error_operand_p (align
))
7481 if (TREE_CODE (align
) != INTEGER_CST
7482 || !INTEGRAL_TYPE_P (TREE_TYPE (align
)))
7484 error ("requested alignment is not an integer constant");
7487 else if (allow_zero
&& integer_zerop (align
))
7489 else if (tree_int_cst_sgn (align
) == -1
7490 || (i
= tree_log2 (align
)) == -1)
7492 error ("requested alignment is not a positive power of 2");
7495 else if (i
>= HOST_BITS_PER_INT
- BITS_PER_UNIT_LOG
)
7497 error ("requested alignment is too large");
7504 If in c++-11, check if the c++-11 alignment constraint with respect
7505 to fundamental alignment (in [dcl.align]) are satisfied. If not in
7506 c++-11 mode, does nothing.
7510 [* if the constant expression evaluates to a fundamental alignment,
7511 the alignment requirement of the declared entity shall be the
7512 specified fundamental alignment.
7514 * if the constant expression evaluates to an extended alignment
7515 and the implementation supports that alignment in the context
7516 of the declaration, the alignment of the declared entity shall
7519 * if the constant expression evaluates to an extended alignment
7520 and the implementation does not support that alignment in the
7521 context of the declaration, the program is ill-formed]. */
7524 check_cxx_fundamental_alignment_constraints (tree node
,
7528 bool alignment_too_large_p
= false;
7529 unsigned requested_alignment
= 1U << align_log
;
7530 unsigned max_align
= 0;
7532 if ((!(flags
& ATTR_FLAG_CXX11
) && !warn_cxx_compat
)
7533 || (node
== NULL_TREE
|| node
== error_mark_node
))
7536 if (cxx_fundamental_alignment_p (requested_alignment
))
7541 if (TREE_STATIC (node
))
7543 /* For file scope variables and static members, the target
7544 supports alignments that are at most
7545 MAX_OFILE_ALIGNMENT. */
7546 if (requested_alignment
> (max_align
= MAX_OFILE_ALIGNMENT
))
7547 alignment_too_large_p
= true;
7551 #ifdef BIGGEST_FIELD_ALIGNMENT
7552 #define MAX_TARGET_FIELD_ALIGNMENT BIGGEST_FIELD_ALIGNMENT
7554 #define MAX_TARGET_FIELD_ALIGNMENT BIGGEST_ALIGNMENT
7556 /* For non-static members, the target supports either
7557 alignments that at most either BIGGEST_FIELD_ALIGNMENT
7558 if it is defined or BIGGEST_ALIGNMENT. */
7559 max_align
= MAX_TARGET_FIELD_ALIGNMENT
;
7560 if (TREE_CODE (node
) == FIELD_DECL
7561 && requested_alignment
> (max_align
= MAX_TARGET_FIELD_ALIGNMENT
))
7562 alignment_too_large_p
= true;
7563 #undef MAX_TARGET_FIELD_ALIGNMENT
7564 /* For stack variables, the target supports at most
7565 MAX_STACK_ALIGNMENT. */
7566 else if (decl_function_context (node
) != NULL
7567 && requested_alignment
> (max_align
= MAX_STACK_ALIGNMENT
))
7568 alignment_too_large_p
= true;
7571 else if (TYPE_P (node
))
7573 /* Let's be liberal for types. */
7574 if (requested_alignment
> (max_align
= BIGGEST_ALIGNMENT
))
7575 alignment_too_large_p
= true;
7578 if (alignment_too_large_p
)
7579 pedwarn (input_location
, OPT_Wattributes
,
7580 "requested alignment %d is larger than %d",
7581 requested_alignment
, max_align
);
7583 return !alignment_too_large_p
;
7586 /* Handle a "aligned" attribute; arguments as in
7587 struct attribute_spec.handler. */
7590 handle_aligned_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7591 int flags
, bool *no_add_attrs
)
7593 tree decl
= NULL_TREE
;
7601 align_expr
= TREE_VALUE (args
);
7602 if (align_expr
&& TREE_CODE (align_expr
) != IDENTIFIER_NODE
7603 && TREE_CODE (align_expr
) != FUNCTION_DECL
)
7604 align_expr
= default_conversion (align_expr
);
7607 align_expr
= size_int (ATTRIBUTE_ALIGNED_VALUE
/ BITS_PER_UNIT
);
7612 type
= &TREE_TYPE (decl
);
7613 is_type
= TREE_CODE (*node
) == TYPE_DECL
;
7615 else if (TYPE_P (*node
))
7616 type
= node
, is_type
= 1;
7618 if ((i
= check_user_alignment (align_expr
, false)) == -1
7619 || !check_cxx_fundamental_alignment_constraints (*node
, i
, flags
))
7620 *no_add_attrs
= true;
7623 if ((flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7624 /* OK, modify the type in place. */;
7625 /* If we have a TYPE_DECL, then copy the type, so that we
7626 don't accidentally modify a builtin type. See pushdecl. */
7627 else if (decl
&& TREE_TYPE (decl
) != error_mark_node
7628 && DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
)
7630 tree tt
= TREE_TYPE (decl
);
7631 *type
= build_variant_type_copy (*type
);
7632 DECL_ORIGINAL_TYPE (decl
) = tt
;
7633 TYPE_NAME (*type
) = decl
;
7634 TREE_USED (*type
) = TREE_USED (decl
);
7635 TREE_TYPE (decl
) = *type
;
7638 *type
= build_variant_type_copy (*type
);
7640 TYPE_ALIGN (*type
) = (1U << i
) * BITS_PER_UNIT
;
7641 TYPE_USER_ALIGN (*type
) = 1;
7643 else if (! VAR_OR_FUNCTION_DECL_P (decl
)
7644 && TREE_CODE (decl
) != FIELD_DECL
)
7646 error ("alignment may not be specified for %q+D", decl
);
7647 *no_add_attrs
= true;
7649 else if (DECL_USER_ALIGN (decl
)
7650 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
7651 /* C++-11 [dcl.align/4]:
7653 When multiple alignment-specifiers are specified for an
7654 entity, the alignment requirement shall be set to the
7655 strictest specified alignment.
7657 This formally comes from the c++11 specification but we are
7658 doing it for the GNU attribute syntax as well. */
7659 *no_add_attrs
= true;
7660 else if (TREE_CODE (decl
) == FUNCTION_DECL
7661 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
7663 if (DECL_USER_ALIGN (decl
))
7664 error ("alignment for %q+D was previously specified as %d "
7665 "and may not be decreased", decl
,
7666 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
7668 error ("alignment for %q+D must be at least %d", decl
,
7669 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
7670 *no_add_attrs
= true;
7674 DECL_ALIGN (decl
) = (1U << i
) * BITS_PER_UNIT
;
7675 DECL_USER_ALIGN (decl
) = 1;
7681 /* Handle a "weak" attribute; arguments as in
7682 struct attribute_spec.handler. */
7685 handle_weak_attribute (tree
*node
, tree name
,
7686 tree
ARG_UNUSED (args
),
7687 int ARG_UNUSED (flags
),
7688 bool * ARG_UNUSED (no_add_attrs
))
7690 if (TREE_CODE (*node
) == FUNCTION_DECL
7691 && DECL_DECLARED_INLINE_P (*node
))
7693 warning (OPT_Wattributes
, "inline function %q+D declared weak", *node
);
7694 *no_add_attrs
= true;
7696 else if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
7698 error ("indirect function %q+D cannot be declared weak", *node
);
7699 *no_add_attrs
= true;
7702 else if (TREE_CODE (*node
) == FUNCTION_DECL
7703 || TREE_CODE (*node
) == VAR_DECL
)
7704 declare_weak (*node
);
7706 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7711 /* Handle an "alias" or "ifunc" attribute; arguments as in
7712 struct attribute_spec.handler, except that IS_ALIAS tells us
7713 whether this is an alias as opposed to ifunc attribute. */
7716 handle_alias_ifunc_attribute (bool is_alias
, tree
*node
, tree name
, tree args
,
7721 if (TREE_CODE (decl
) != FUNCTION_DECL
7722 && (!is_alias
|| TREE_CODE (decl
) != VAR_DECL
))
7724 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7725 *no_add_attrs
= true;
7727 else if ((TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INITIAL (decl
))
7728 || (TREE_CODE (decl
) != FUNCTION_DECL
7729 && TREE_PUBLIC (decl
) && !DECL_EXTERNAL (decl
))
7730 /* A static variable declaration is always a tentative definition,
7731 but the alias is a non-tentative definition which overrides. */
7732 || (TREE_CODE (decl
) != FUNCTION_DECL
7733 && ! TREE_PUBLIC (decl
) && DECL_INITIAL (decl
)))
7735 error ("%q+D defined both normally and as %qE attribute", decl
, name
);
7736 *no_add_attrs
= true;
7740 && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
7741 || lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
))))
7743 error ("weak %q+D cannot be defined %qE", decl
, name
);
7744 *no_add_attrs
= true;
7748 /* Note that the very first time we process a nested declaration,
7749 decl_function_context will not be set. Indeed, *would* never
7750 be set except for the DECL_INITIAL/DECL_EXTERNAL frobbery that
7751 we do below. After such frobbery, pushdecl would set the context.
7752 In any case, this is never what we want. */
7753 else if (decl_function_context (decl
) == 0 && current_function_decl
== NULL
)
7757 id
= TREE_VALUE (args
);
7758 if (TREE_CODE (id
) != STRING_CST
)
7760 error ("attribute %qE argument not a string", name
);
7761 *no_add_attrs
= true;
7764 id
= get_identifier (TREE_STRING_POINTER (id
));
7765 /* This counts as a use of the object pointed to. */
7768 if (TREE_CODE (decl
) == FUNCTION_DECL
)
7769 DECL_INITIAL (decl
) = error_mark_node
;
7771 TREE_STATIC (decl
) = 1;
7774 /* ifuncs are also aliases, so set that attribute too. */
7775 DECL_ATTRIBUTES (decl
)
7776 = tree_cons (get_identifier ("alias"), args
, DECL_ATTRIBUTES (decl
));
7780 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7781 *no_add_attrs
= true;
7787 /* Handle an "alias" or "ifunc" attribute; arguments as in
7788 struct attribute_spec.handler. */
7791 handle_ifunc_attribute (tree
*node
, tree name
, tree args
,
7792 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7794 return handle_alias_ifunc_attribute (false, node
, name
, args
, no_add_attrs
);
7797 /* Handle an "alias" or "ifunc" attribute; arguments as in
7798 struct attribute_spec.handler. */
7801 handle_alias_attribute (tree
*node
, tree name
, tree args
,
7802 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7804 return handle_alias_ifunc_attribute (true, node
, name
, args
, no_add_attrs
);
7807 /* Handle a "weakref" attribute; arguments as in struct
7808 attribute_spec.handler. */
7811 handle_weakref_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7812 int flags
, bool *no_add_attrs
)
7814 tree attr
= NULL_TREE
;
7816 /* We must ignore the attribute when it is associated with
7817 local-scoped decls, since attribute alias is ignored and many
7818 such symbols do not even have a DECL_WEAK field. */
7819 if (decl_function_context (*node
)
7820 || current_function_decl
7821 || (TREE_CODE (*node
) != VAR_DECL
&& TREE_CODE (*node
) != FUNCTION_DECL
))
7823 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7824 *no_add_attrs
= true;
7828 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
7830 error ("indirect function %q+D cannot be declared weakref", *node
);
7831 *no_add_attrs
= true;
7835 /* The idea here is that `weakref("name")' mutates into `weakref,
7836 alias("name")', and weakref without arguments, in turn,
7837 implicitly adds weak. */
7841 attr
= tree_cons (get_identifier ("alias"), args
, attr
);
7842 attr
= tree_cons (get_identifier ("weakref"), NULL_TREE
, attr
);
7844 *no_add_attrs
= true;
7846 decl_attributes (node
, attr
, flags
);
7850 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node
)))
7851 error_at (DECL_SOURCE_LOCATION (*node
),
7852 "weakref attribute must appear before alias attribute");
7854 /* Can't call declare_weak because it wants this to be TREE_PUBLIC,
7855 and that isn't supported; and because it wants to add it to
7856 the list of weak decls, which isn't helpful. */
7857 DECL_WEAK (*node
) = 1;
7863 /* Handle an "visibility" attribute; arguments as in
7864 struct attribute_spec.handler. */
7867 handle_visibility_attribute (tree
*node
, tree name
, tree args
,
7868 int ARG_UNUSED (flags
),
7869 bool *ARG_UNUSED (no_add_attrs
))
7872 tree id
= TREE_VALUE (args
);
7873 enum symbol_visibility vis
;
7877 if (TREE_CODE (*node
) == ENUMERAL_TYPE
)
7879 else if (TREE_CODE (*node
) != RECORD_TYPE
&& TREE_CODE (*node
) != UNION_TYPE
)
7881 warning (OPT_Wattributes
, "%qE attribute ignored on non-class types",
7885 else if (TYPE_FIELDS (*node
))
7887 error ("%qE attribute ignored because %qT is already defined",
7892 else if (decl_function_context (decl
) != 0 || !TREE_PUBLIC (decl
))
7894 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7898 if (TREE_CODE (id
) != STRING_CST
)
7900 error ("visibility argument not a string");
7904 /* If this is a type, set the visibility on the type decl. */
7907 decl
= TYPE_NAME (decl
);
7910 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
7912 warning (OPT_Wattributes
, "%qE attribute ignored on types",
7918 if (strcmp (TREE_STRING_POINTER (id
), "default") == 0)
7919 vis
= VISIBILITY_DEFAULT
;
7920 else if (strcmp (TREE_STRING_POINTER (id
), "internal") == 0)
7921 vis
= VISIBILITY_INTERNAL
;
7922 else if (strcmp (TREE_STRING_POINTER (id
), "hidden") == 0)
7923 vis
= VISIBILITY_HIDDEN
;
7924 else if (strcmp (TREE_STRING_POINTER (id
), "protected") == 0)
7925 vis
= VISIBILITY_PROTECTED
;
7928 error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
7929 vis
= VISIBILITY_DEFAULT
;
7932 if (DECL_VISIBILITY_SPECIFIED (decl
)
7933 && vis
!= DECL_VISIBILITY (decl
))
7935 tree attributes
= (TYPE_P (*node
)
7936 ? TYPE_ATTRIBUTES (*node
)
7937 : DECL_ATTRIBUTES (decl
));
7938 if (lookup_attribute ("visibility", attributes
))
7939 error ("%qD redeclared with different visibility", decl
);
7940 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
7941 && lookup_attribute ("dllimport", attributes
))
7942 error ("%qD was declared %qs which implies default visibility",
7944 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
7945 && lookup_attribute ("dllexport", attributes
))
7946 error ("%qD was declared %qs which implies default visibility",
7950 DECL_VISIBILITY (decl
) = vis
;
7951 DECL_VISIBILITY_SPECIFIED (decl
) = 1;
7953 /* Go ahead and attach the attribute to the node as well. This is needed
7954 so we can determine whether we have VISIBILITY_DEFAULT because the
7955 visibility was not specified, or because it was explicitly overridden
7956 from the containing scope. */
7961 /* Determine the ELF symbol visibility for DECL, which is either a
7962 variable or a function. It is an error to use this function if a
7963 definition of DECL is not available in this translation unit.
7964 Returns true if the final visibility has been determined by this
7965 function; false if the caller is free to make additional
7969 c_determine_visibility (tree decl
)
7971 gcc_assert (TREE_CODE (decl
) == VAR_DECL
7972 || TREE_CODE (decl
) == FUNCTION_DECL
);
7974 /* If the user explicitly specified the visibility with an
7975 attribute, honor that. DECL_VISIBILITY will have been set during
7976 the processing of the attribute. We check for an explicit
7977 attribute, rather than just checking DECL_VISIBILITY_SPECIFIED,
7978 to distinguish the use of an attribute from the use of a "#pragma
7979 GCC visibility push(...)"; in the latter case we still want other
7980 considerations to be able to overrule the #pragma. */
7981 if (lookup_attribute ("visibility", DECL_ATTRIBUTES (decl
))
7982 || (TARGET_DLLIMPORT_DECL_ATTRIBUTES
7983 && (lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl
))
7984 || lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl
)))))
7987 /* Set default visibility to whatever the user supplied with
7988 visibility_specified depending on #pragma GCC visibility. */
7989 if (!DECL_VISIBILITY_SPECIFIED (decl
))
7991 if (visibility_options
.inpragma
7992 || DECL_VISIBILITY (decl
) != default_visibility
)
7994 DECL_VISIBILITY (decl
) = default_visibility
;
7995 DECL_VISIBILITY_SPECIFIED (decl
) = visibility_options
.inpragma
;
7996 /* If visibility changed and DECL already has DECL_RTL, ensure
7997 symbol flags are updated. */
7998 if (((TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
))
7999 || TREE_CODE (decl
) == FUNCTION_DECL
)
8000 && DECL_RTL_SET_P (decl
))
8001 make_decl_rtl (decl
);
8007 /* Handle an "tls_model" attribute; arguments as in
8008 struct attribute_spec.handler. */
8011 handle_tls_model_attribute (tree
*node
, tree name
, tree args
,
8012 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8016 enum tls_model kind
;
8018 *no_add_attrs
= true;
8020 if (TREE_CODE (decl
) != VAR_DECL
|| !DECL_THREAD_LOCAL_P (decl
))
8022 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8026 kind
= DECL_TLS_MODEL (decl
);
8027 id
= TREE_VALUE (args
);
8028 if (TREE_CODE (id
) != STRING_CST
)
8030 error ("tls_model argument not a string");
8034 if (!strcmp (TREE_STRING_POINTER (id
), "local-exec"))
8035 kind
= TLS_MODEL_LOCAL_EXEC
;
8036 else if (!strcmp (TREE_STRING_POINTER (id
), "initial-exec"))
8037 kind
= TLS_MODEL_INITIAL_EXEC
;
8038 else if (!strcmp (TREE_STRING_POINTER (id
), "local-dynamic"))
8039 kind
= optimize
? TLS_MODEL_LOCAL_DYNAMIC
: TLS_MODEL_GLOBAL_DYNAMIC
;
8040 else if (!strcmp (TREE_STRING_POINTER (id
), "global-dynamic"))
8041 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
8043 error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
8045 set_decl_tls_model (decl
, kind
);
8049 /* Handle a "no_instrument_function" attribute; arguments as in
8050 struct attribute_spec.handler. */
8053 handle_no_instrument_function_attribute (tree
*node
, tree name
,
8054 tree
ARG_UNUSED (args
),
8055 int ARG_UNUSED (flags
),
8060 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8062 error_at (DECL_SOURCE_LOCATION (decl
),
8063 "%qE attribute applies only to functions", name
);
8064 *no_add_attrs
= true;
8067 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
8072 /* Handle a "malloc" attribute; arguments as in
8073 struct attribute_spec.handler. */
8076 handle_malloc_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8077 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8079 if (TREE_CODE (*node
) == FUNCTION_DECL
8080 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node
))))
8081 DECL_IS_MALLOC (*node
) = 1;
8084 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8085 *no_add_attrs
= true;
8091 /* Handle a "alloc_size" attribute; arguments as in
8092 struct attribute_spec.handler. */
8095 handle_alloc_size_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
8096 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8098 unsigned arg_count
= type_num_arguments (*node
);
8099 for (; args
; args
= TREE_CHAIN (args
))
8101 tree position
= TREE_VALUE (args
);
8102 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
8103 && TREE_CODE (position
) != FUNCTION_DECL
)
8104 position
= default_conversion (position
);
8106 if (!tree_fits_uhwi_p (position
)
8108 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
8110 warning (OPT_Wattributes
,
8111 "alloc_size parameter outside range");
8112 *no_add_attrs
= true;
8119 /* Handle a "alloc_align" attribute; arguments as in
8120 struct attribute_spec.handler. */
8123 handle_alloc_align_attribute (tree
*node
, tree
, tree args
, int,
8126 unsigned arg_count
= type_num_arguments (*node
);
8127 tree position
= TREE_VALUE (args
);
8128 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
)
8129 position
= default_conversion (position
);
8131 if (!tree_fits_uhwi_p (position
)
8133 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
8135 warning (OPT_Wattributes
,
8136 "alloc_align parameter outside range");
8137 *no_add_attrs
= true;
8143 /* Handle a "assume_aligned" attribute; arguments as in
8144 struct attribute_spec.handler. */
8147 handle_assume_aligned_attribute (tree
*, tree
, tree args
, int,
8150 for (; args
; args
= TREE_CHAIN (args
))
8152 tree position
= TREE_VALUE (args
);
8153 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
8154 && TREE_CODE (position
) != FUNCTION_DECL
)
8155 position
= default_conversion (position
);
8157 if (TREE_CODE (position
) != INTEGER_CST
)
8159 warning (OPT_Wattributes
,
8160 "assume_aligned parameter not integer constant");
8161 *no_add_attrs
= true;
8168 /* Handle a "fn spec" attribute; arguments as in
8169 struct attribute_spec.handler. */
8172 handle_fnspec_attribute (tree
*node ATTRIBUTE_UNUSED
, tree
ARG_UNUSED (name
),
8173 tree args
, int ARG_UNUSED (flags
),
8174 bool *no_add_attrs ATTRIBUTE_UNUSED
)
8177 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
8178 && !TREE_CHAIN (args
));
8182 /* Handle a "warn_unused" attribute; arguments as in
8183 struct attribute_spec.handler. */
8186 handle_warn_unused_attribute (tree
*node
, tree name
,
8187 tree args ATTRIBUTE_UNUSED
,
8188 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
8191 /* Do nothing else, just set the attribute. We'll get at
8192 it later with lookup_attribute. */
8196 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8197 *no_add_attrs
= true;
8203 /* Handle an "omp declare simd" attribute; arguments as in
8204 struct attribute_spec.handler. */
8207 handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int, bool *)
8212 /* Handle an "omp declare target" attribute; arguments as in
8213 struct attribute_spec.handler. */
8216 handle_omp_declare_target_attribute (tree
*, tree
, tree
, int, bool *)
8221 /* Handle a "returns_twice" attribute; arguments as in
8222 struct attribute_spec.handler. */
8225 handle_returns_twice_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8226 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8228 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8229 DECL_IS_RETURNS_TWICE (*node
) = 1;
8232 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8233 *no_add_attrs
= true;
8239 /* Handle a "no_limit_stack" attribute; arguments as in
8240 struct attribute_spec.handler. */
8243 handle_no_limit_stack_attribute (tree
*node
, tree name
,
8244 tree
ARG_UNUSED (args
),
8245 int ARG_UNUSED (flags
),
8250 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8252 error_at (DECL_SOURCE_LOCATION (decl
),
8253 "%qE attribute applies only to functions", name
);
8254 *no_add_attrs
= true;
8256 else if (DECL_INITIAL (decl
))
8258 error_at (DECL_SOURCE_LOCATION (decl
),
8259 "can%'t set %qE attribute after definition", name
);
8260 *no_add_attrs
= true;
8263 DECL_NO_LIMIT_STACK (decl
) = 1;
8268 /* Handle a "pure" attribute; arguments as in
8269 struct attribute_spec.handler. */
8272 handle_pure_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8273 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8275 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8276 DECL_PURE_P (*node
) = 1;
8277 /* ??? TODO: Support types. */
8280 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8281 *no_add_attrs
= true;
8287 /* Digest an attribute list destined for a transactional memory statement.
8288 ALLOWED is the set of attributes that are allowed for this statement;
8289 return the attribute we parsed. Multiple attributes are never allowed. */
8292 parse_tm_stmt_attr (tree attrs
, int allowed
)
8297 for ( ; attrs
; attrs
= TREE_CHAIN (attrs
))
8299 tree a
= TREE_PURPOSE (attrs
);
8302 if (is_attribute_p ("outer", a
))
8303 m
= TM_STMT_ATTR_OUTER
;
8305 if ((m
& allowed
) == 0)
8307 warning (OPT_Wattributes
, "%qE attribute directive ignored", a
);
8316 else if (m_seen
== m
)
8317 warning (OPT_Wattributes
, "%qE attribute duplicated", a
);
8319 warning (OPT_Wattributes
, "%qE attribute follows %qE", a
, a_seen
);
8325 /* Transform a TM attribute name into a maskable integer and back.
8326 Note that NULL (i.e. no attribute) is mapped to UNKNOWN, corresponding
8327 to how the lack of an attribute is treated. */
8330 tm_attr_to_mask (tree attr
)
8334 if (is_attribute_p ("transaction_safe", attr
))
8335 return TM_ATTR_SAFE
;
8336 if (is_attribute_p ("transaction_callable", attr
))
8337 return TM_ATTR_CALLABLE
;
8338 if (is_attribute_p ("transaction_pure", attr
))
8339 return TM_ATTR_PURE
;
8340 if (is_attribute_p ("transaction_unsafe", attr
))
8341 return TM_ATTR_IRREVOCABLE
;
8342 if (is_attribute_p ("transaction_may_cancel_outer", attr
))
8343 return TM_ATTR_MAY_CANCEL_OUTER
;
8348 tm_mask_to_attr (int mask
)
8354 str
= "transaction_safe";
8356 case TM_ATTR_CALLABLE
:
8357 str
= "transaction_callable";
8360 str
= "transaction_pure";
8362 case TM_ATTR_IRREVOCABLE
:
8363 str
= "transaction_unsafe";
8365 case TM_ATTR_MAY_CANCEL_OUTER
:
8366 str
= "transaction_may_cancel_outer";
8371 return get_identifier (str
);
8374 /* Return the first TM attribute seen in LIST. */
8377 find_tm_attribute (tree list
)
8379 for (; list
; list
= TREE_CHAIN (list
))
8381 tree name
= TREE_PURPOSE (list
);
8382 if (tm_attr_to_mask (name
) != 0)
8388 /* Handle the TM attributes; arguments as in struct attribute_spec.handler.
8389 Here we accept only function types, and verify that none of the other
8390 function TM attributes are also applied. */
8391 /* ??? We need to accept class types for C++, but not C. This greatly
8392 complicates this function, since we can no longer rely on the extra
8393 processing given by function_type_required. */
8396 handle_tm_attribute (tree
*node
, tree name
, tree args
,
8397 int flags
, bool *no_add_attrs
)
8399 /* Only one path adds the attribute; others don't. */
8400 *no_add_attrs
= true;
8402 switch (TREE_CODE (*node
))
8406 /* Only tm_callable and tm_safe apply to classes. */
8407 if (tm_attr_to_mask (name
) & ~(TM_ATTR_SAFE
| TM_ATTR_CALLABLE
))
8414 tree old_name
= find_tm_attribute (TYPE_ATTRIBUTES (*node
));
8415 if (old_name
== name
)
8417 else if (old_name
!= NULL_TREE
)
8418 error ("type was previously declared %qE", old_name
);
8420 *no_add_attrs
= false;
8426 enum tree_code subcode
= TREE_CODE (TREE_TYPE (*node
));
8427 if (subcode
== FUNCTION_TYPE
|| subcode
== METHOD_TYPE
)
8429 tree fn_tmp
= TREE_TYPE (*node
);
8430 decl_attributes (&fn_tmp
, tree_cons (name
, args
, NULL
), 0);
8431 *node
= build_pointer_type (fn_tmp
);
8438 /* If a function is next, pass it on to be tried next. */
8439 if (flags
& (int) ATTR_FLAG_FUNCTION_NEXT
)
8440 return tree_cons (name
, args
, NULL
);
8443 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8450 /* Handle the TM_WRAP attribute; arguments as in
8451 struct attribute_spec.handler. */
8454 handle_tm_wrap_attribute (tree
*node
, tree name
, tree args
,
8455 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8459 /* We don't need the attribute even on success, since we
8460 record the entry in an external table. */
8461 *no_add_attrs
= true;
8463 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8464 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8467 tree wrap_decl
= TREE_VALUE (args
);
8468 if (error_operand_p (wrap_decl
))
8470 else if (TREE_CODE (wrap_decl
) != IDENTIFIER_NODE
8471 && TREE_CODE (wrap_decl
) != VAR_DECL
8472 && TREE_CODE (wrap_decl
) != FUNCTION_DECL
)
8473 error ("%qE argument not an identifier", name
);
8476 if (TREE_CODE (wrap_decl
) == IDENTIFIER_NODE
)
8477 wrap_decl
= lookup_name (wrap_decl
);
8478 if (wrap_decl
&& TREE_CODE (wrap_decl
) == FUNCTION_DECL
)
8480 if (lang_hooks
.types_compatible_p (TREE_TYPE (decl
),
8481 TREE_TYPE (wrap_decl
)))
8482 record_tm_replacement (wrap_decl
, decl
);
8484 error ("%qD is not compatible with %qD", wrap_decl
, decl
);
8487 error ("%qE argument is not a function", name
);
8494 /* Ignore the given attribute. Used when this attribute may be usefully
8495 overridden by the target, but is not used generically. */
8498 ignore_attribute (tree
* ARG_UNUSED (node
), tree
ARG_UNUSED (name
),
8499 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
8502 *no_add_attrs
= true;
8506 /* Handle a "no vops" attribute; arguments as in
8507 struct attribute_spec.handler. */
8510 handle_novops_attribute (tree
*node
, tree
ARG_UNUSED (name
),
8511 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
8512 bool *ARG_UNUSED (no_add_attrs
))
8514 gcc_assert (TREE_CODE (*node
) == FUNCTION_DECL
);
8515 DECL_IS_NOVOPS (*node
) = 1;
8519 /* Handle a "deprecated" attribute; arguments as in
8520 struct attribute_spec.handler. */
8523 handle_deprecated_attribute (tree
*node
, tree name
,
8524 tree args
, int flags
,
8527 tree type
= NULL_TREE
;
8529 tree what
= NULL_TREE
;
8532 *no_add_attrs
= true;
8533 else if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
8535 error ("deprecated message is not a string");
8536 *no_add_attrs
= true;
8542 type
= TREE_TYPE (decl
);
8544 if (TREE_CODE (decl
) == TYPE_DECL
8545 || TREE_CODE (decl
) == PARM_DECL
8546 || TREE_CODE (decl
) == VAR_DECL
8547 || TREE_CODE (decl
) == FUNCTION_DECL
8548 || TREE_CODE (decl
) == FIELD_DECL
8549 || objc_method_decl (TREE_CODE (decl
)))
8550 TREE_DEPRECATED (decl
) = 1;
8554 else if (TYPE_P (*node
))
8556 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
8557 *node
= build_variant_type_copy (*node
);
8558 TREE_DEPRECATED (*node
) = 1;
8566 *no_add_attrs
= true;
8567 if (type
&& TYPE_NAME (type
))
8569 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
8570 what
= TYPE_NAME (*node
);
8571 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
8572 && DECL_NAME (TYPE_NAME (type
)))
8573 what
= DECL_NAME (TYPE_NAME (type
));
8576 warning (OPT_Wattributes
, "%qE attribute ignored for %qE", name
, what
);
8578 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8584 /* Handle a "vector_size" attribute; arguments as in
8585 struct attribute_spec.handler. */
8588 handle_vector_size_attribute (tree
*node
, tree name
, tree args
,
8589 int ARG_UNUSED (flags
),
8592 unsigned HOST_WIDE_INT vecsize
, nunits
;
8593 enum machine_mode orig_mode
;
8594 tree type
= *node
, new_type
, size
;
8596 *no_add_attrs
= true;
8598 size
= TREE_VALUE (args
);
8599 if (size
&& TREE_CODE (size
) != IDENTIFIER_NODE
8600 && TREE_CODE (size
) != FUNCTION_DECL
)
8601 size
= default_conversion (size
);
8603 if (!tree_fits_uhwi_p (size
))
8605 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8609 /* Get the vector size (in bytes). */
8610 vecsize
= tree_to_uhwi (size
);
8612 /* We need to provide for vector pointers, vector arrays, and
8613 functions returning vectors. For example:
8615 __attribute__((vector_size(16))) short *foo;
8617 In this case, the mode is SI, but the type being modified is
8618 HI, so we need to look further. */
8620 while (POINTER_TYPE_P (type
)
8621 || TREE_CODE (type
) == FUNCTION_TYPE
8622 || TREE_CODE (type
) == METHOD_TYPE
8623 || TREE_CODE (type
) == ARRAY_TYPE
8624 || TREE_CODE (type
) == OFFSET_TYPE
)
8625 type
= TREE_TYPE (type
);
8627 /* Get the mode of the type being modified. */
8628 orig_mode
= TYPE_MODE (type
);
8630 if ((!INTEGRAL_TYPE_P (type
)
8631 && !SCALAR_FLOAT_TYPE_P (type
)
8632 && !FIXED_POINT_TYPE_P (type
))
8633 || (!SCALAR_FLOAT_MODE_P (orig_mode
)
8634 && GET_MODE_CLASS (orig_mode
) != MODE_INT
8635 && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode
))
8636 || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
8637 || TREE_CODE (type
) == BOOLEAN_TYPE
)
8639 error ("invalid vector type for attribute %qE", name
);
8643 if (vecsize
% tree_to_uhwi (TYPE_SIZE_UNIT (type
)))
8645 error ("vector size not an integral multiple of component size");
8651 error ("zero vector size");
8655 /* Calculate how many units fit in the vector. */
8656 nunits
= vecsize
/ tree_to_uhwi (TYPE_SIZE_UNIT (type
));
8657 if (nunits
& (nunits
- 1))
8659 error ("number of components of the vector not a power of two");
8663 new_type
= build_vector_type (type
, nunits
);
8665 /* Build back pointers if needed. */
8666 *node
= lang_hooks
.types
.reconstruct_complex_type (*node
, new_type
);
8671 /* Handle the "nonnull" attribute. */
8673 handle_nonnull_attribute (tree
*node
, tree
ARG_UNUSED (name
),
8674 tree args
, int ARG_UNUSED (flags
),
8678 unsigned HOST_WIDE_INT attr_arg_num
;
8680 /* If no arguments are specified, all pointer arguments should be
8681 non-null. Verify a full prototype is given so that the arguments
8682 will have the correct types when we actually check them later. */
8685 if (!prototype_p (type
))
8687 error ("nonnull attribute without arguments on a non-prototype");
8688 *no_add_attrs
= true;
8693 /* Argument list specified. Verify that each argument number references
8694 a pointer argument. */
8695 for (attr_arg_num
= 1; args
; attr_arg_num
++, args
= TREE_CHAIN (args
))
8697 unsigned HOST_WIDE_INT arg_num
= 0, ck_num
;
8699 tree arg
= TREE_VALUE (args
);
8700 if (arg
&& TREE_CODE (arg
) != IDENTIFIER_NODE
8701 && TREE_CODE (arg
) != FUNCTION_DECL
)
8702 arg
= default_conversion (arg
);
8704 if (!get_nonnull_operand (arg
, &arg_num
))
8706 error ("nonnull argument has invalid operand number (argument %lu)",
8707 (unsigned long) attr_arg_num
);
8708 *no_add_attrs
= true;
8712 if (prototype_p (type
))
8714 function_args_iterator iter
;
8717 function_args_iter_init (&iter
, type
);
8718 for (ck_num
= 1; ; ck_num
++, function_args_iter_next (&iter
))
8720 argument
= function_args_iter_cond (&iter
);
8721 if (argument
== NULL_TREE
|| ck_num
== arg_num
)
8726 || TREE_CODE (argument
) == VOID_TYPE
)
8728 error ("nonnull argument with out-of-range operand number (argument %lu, operand %lu)",
8729 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
8730 *no_add_attrs
= true;
8734 if (TREE_CODE (argument
) != POINTER_TYPE
)
8736 error ("nonnull argument references non-pointer operand (argument %lu, operand %lu)",
8737 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
8738 *no_add_attrs
= true;
8747 /* Check the argument list of a function call for null in argument slots
8748 that are marked as requiring a non-null pointer argument. The NARGS
8749 arguments are passed in the array ARGARRAY.
8753 check_function_nonnull (tree attrs
, int nargs
, tree
*argarray
)
8758 attrs
= lookup_attribute ("nonnull", attrs
);
8759 if (attrs
== NULL_TREE
)
8763 /* See if any of the nonnull attributes has no arguments. If so,
8764 then every pointer argument is checked (in which case the check
8765 for pointer type is done in check_nonnull_arg). */
8766 if (TREE_VALUE (a
) != NULL_TREE
)
8768 a
= lookup_attribute ("nonnull", TREE_CHAIN (a
));
8769 while (a
!= NULL_TREE
&& TREE_VALUE (a
) != NULL_TREE
);
8772 for (i
= 0; i
< nargs
; i
++)
8773 check_function_arguments_recurse (check_nonnull_arg
, NULL
, argarray
[i
],
8777 /* Walk the argument list. If we encounter an argument number we
8778 should check for non-null, do it. */
8779 for (i
= 0; i
< nargs
; i
++)
8781 for (a
= attrs
; ; a
= TREE_CHAIN (a
))
8783 a
= lookup_attribute ("nonnull", a
);
8784 if (a
== NULL_TREE
|| nonnull_check_p (TREE_VALUE (a
), i
+ 1))
8789 check_function_arguments_recurse (check_nonnull_arg
, NULL
,
8790 argarray
[i
], i
+ 1);
8795 /* Check that the Nth argument of a function call (counting backwards
8796 from the end) is a (pointer)0. The NARGS arguments are passed in the
8800 check_function_sentinel (const_tree fntype
, int nargs
, tree
*argarray
)
8802 tree attr
= lookup_attribute ("sentinel", TYPE_ATTRIBUTES (fntype
));
8809 function_args_iterator iter
;
8812 /* Skip over the named arguments. */
8813 FOREACH_FUNCTION_ARGS (fntype
, t
, iter
)
8820 if (TREE_VALUE (attr
))
8822 tree p
= TREE_VALUE (TREE_VALUE (attr
));
8823 pos
= TREE_INT_CST_LOW (p
);
8826 /* The sentinel must be one of the varargs, i.e.
8827 in position >= the number of fixed arguments. */
8828 if ((nargs
- 1 - pos
) < len
)
8830 warning (OPT_Wformat_
,
8831 "not enough variable arguments to fit a sentinel");
8835 /* Validate the sentinel. */
8836 sentinel
= argarray
[nargs
- 1 - pos
];
8837 if ((!POINTER_TYPE_P (TREE_TYPE (sentinel
))
8838 || !integer_zerop (sentinel
))
8839 /* Although __null (in C++) is only an integer we allow it
8840 nevertheless, as we are guaranteed that it's exactly
8841 as wide as a pointer, and we don't want to force
8842 users to cast the NULL they have written there.
8843 We warn with -Wstrict-null-sentinel, though. */
8844 && (warn_strict_null_sentinel
|| null_node
!= sentinel
))
8845 warning (OPT_Wformat_
, "missing sentinel in function call");
8849 /* Helper for check_function_nonnull; given a list of operands which
8850 must be non-null in ARGS, determine if operand PARAM_NUM should be
8854 nonnull_check_p (tree args
, unsigned HOST_WIDE_INT param_num
)
8856 unsigned HOST_WIDE_INT arg_num
= 0;
8858 for (; args
; args
= TREE_CHAIN (args
))
8860 bool found
= get_nonnull_operand (TREE_VALUE (args
), &arg_num
);
8864 if (arg_num
== param_num
)
8870 /* Check that the function argument PARAM (which is operand number
8871 PARAM_NUM) is non-null. This is called by check_function_nonnull
8872 via check_function_arguments_recurse. */
8875 check_nonnull_arg (void * ARG_UNUSED (ctx
), tree param
,
8876 unsigned HOST_WIDE_INT param_num
)
8878 /* Just skip checking the argument if it's not a pointer. This can
8879 happen if the "nonnull" attribute was given without an operand
8880 list (which means to check every pointer argument). */
8882 if (TREE_CODE (TREE_TYPE (param
)) != POINTER_TYPE
)
8885 if (integer_zerop (param
))
8886 warning (OPT_Wnonnull
, "null argument where non-null required "
8887 "(argument %lu)", (unsigned long) param_num
);
8890 /* Helper for nonnull attribute handling; fetch the operand number
8891 from the attribute argument list. */
8894 get_nonnull_operand (tree arg_num_expr
, unsigned HOST_WIDE_INT
*valp
)
8896 /* Verify the arg number is a small constant. */
8897 if (tree_fits_uhwi_p (arg_num_expr
))
8899 *valp
= TREE_INT_CST_LOW (arg_num_expr
);
8906 /* Handle a "nothrow" attribute; arguments as in
8907 struct attribute_spec.handler. */
8910 handle_nothrow_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8911 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8913 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8914 TREE_NOTHROW (*node
) = 1;
8915 /* ??? TODO: Support types. */
8918 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8919 *no_add_attrs
= true;
8925 /* Handle a "cleanup" attribute; arguments as in
8926 struct attribute_spec.handler. */
8929 handle_cleanup_attribute (tree
*node
, tree name
, tree args
,
8930 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8933 tree cleanup_id
, cleanup_decl
;
8935 /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
8936 for global destructors in C++. This requires infrastructure that
8937 we don't have generically at the moment. It's also not a feature
8938 we'd be missing too much, since we do have attribute constructor. */
8939 if (TREE_CODE (decl
) != VAR_DECL
|| TREE_STATIC (decl
))
8941 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8942 *no_add_attrs
= true;
8946 /* Verify that the argument is a function in scope. */
8947 /* ??? We could support pointers to functions here as well, if
8948 that was considered desirable. */
8949 cleanup_id
= TREE_VALUE (args
);
8950 if (TREE_CODE (cleanup_id
) != IDENTIFIER_NODE
)
8952 error ("cleanup argument not an identifier");
8953 *no_add_attrs
= true;
8956 cleanup_decl
= lookup_name (cleanup_id
);
8957 if (!cleanup_decl
|| TREE_CODE (cleanup_decl
) != FUNCTION_DECL
)
8959 error ("cleanup argument not a function");
8960 *no_add_attrs
= true;
8964 /* That the function has proper type is checked with the
8965 eventual call to build_function_call. */
8970 /* Handle a "warn_unused_result" attribute. No special handling. */
8973 handle_warn_unused_result_attribute (tree
*node
, tree name
,
8974 tree
ARG_UNUSED (args
),
8975 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8977 /* Ignore the attribute for functions not returning any value. */
8978 if (VOID_TYPE_P (TREE_TYPE (*node
)))
8980 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8981 *no_add_attrs
= true;
8987 /* Handle a "sentinel" attribute. */
8990 handle_sentinel_attribute (tree
*node
, tree name
, tree args
,
8991 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8993 if (!prototype_p (*node
))
8995 warning (OPT_Wattributes
,
8996 "%qE attribute requires prototypes with named arguments", name
);
8997 *no_add_attrs
= true;
9001 if (!stdarg_p (*node
))
9003 warning (OPT_Wattributes
,
9004 "%qE attribute only applies to variadic functions", name
);
9005 *no_add_attrs
= true;
9011 tree position
= TREE_VALUE (args
);
9012 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
9013 && TREE_CODE (position
) != FUNCTION_DECL
)
9014 position
= default_conversion (position
);
9016 if (TREE_CODE (position
) != INTEGER_CST
9017 || !INTEGRAL_TYPE_P (TREE_TYPE (position
)))
9019 warning (OPT_Wattributes
,
9020 "requested position is not an integer constant");
9021 *no_add_attrs
= true;
9025 if (tree_int_cst_lt (position
, integer_zero_node
))
9027 warning (OPT_Wattributes
,
9028 "requested position is less than zero");
9029 *no_add_attrs
= true;
9037 /* Handle a "type_generic" attribute. */
9040 handle_type_generic_attribute (tree
*node
, tree
ARG_UNUSED (name
),
9041 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
9042 bool * ARG_UNUSED (no_add_attrs
))
9044 /* Ensure we have a function type. */
9045 gcc_assert (TREE_CODE (*node
) == FUNCTION_TYPE
);
9047 /* Ensure we have a variadic function. */
9048 gcc_assert (!prototype_p (*node
) || stdarg_p (*node
));
9053 /* Handle a "target" attribute. */
9056 handle_target_attribute (tree
*node
, tree name
, tree args
, int flags
,
9059 /* Ensure we have a function type. */
9060 if (TREE_CODE (*node
) != FUNCTION_DECL
)
9062 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9063 *no_add_attrs
= true;
9065 else if (! targetm
.target_option
.valid_attribute_p (*node
, name
, args
,
9067 *no_add_attrs
= true;
9072 /* Arguments being collected for optimization. */
9073 typedef const char *const_char_p
; /* For DEF_VEC_P. */
9074 static GTY(()) vec
<const_char_p
, va_gc
> *optimize_args
;
9077 /* Inner function to convert a TREE_LIST to argv string to parse the optimize
9078 options in ARGS. ATTR_P is true if this is for attribute(optimize), and
9079 false for #pragma GCC optimize. */
9082 parse_optimize_options (tree args
, bool attr_p
)
9087 int saved_flag_strict_aliasing
;
9088 const char **opt_argv
;
9089 struct cl_decoded_option
*decoded_options
;
9090 unsigned int decoded_options_count
;
9093 /* Build up argv vector. Just in case the string is stored away, use garbage
9094 collected strings. */
9095 vec_safe_truncate (optimize_args
, 0);
9096 vec_safe_push (optimize_args
, (const char *) NULL
);
9098 for (ap
= args
; ap
!= NULL_TREE
; ap
= TREE_CHAIN (ap
))
9100 tree value
= TREE_VALUE (ap
);
9102 if (TREE_CODE (value
) == INTEGER_CST
)
9105 sprintf (buffer
, "-O%ld", (long) TREE_INT_CST_LOW (value
));
9106 vec_safe_push (optimize_args
, ggc_strdup (buffer
));
9109 else if (TREE_CODE (value
) == STRING_CST
)
9111 /* Split string into multiple substrings. */
9112 size_t len
= TREE_STRING_LENGTH (value
);
9113 char *p
= ASTRDUP (TREE_STRING_POINTER (value
));
9114 char *end
= p
+ len
;
9118 while (next_p
!= NULL
)
9124 comma
= strchr (p
, ',');
9137 r
= q
= (char *) ggc_alloc_atomic (len2
+ 3);
9139 /* If the user supplied -Oxxx or -fxxx, only allow -Oxxx or -fxxx
9141 if (*p
== '-' && p
[1] != 'O' && p
[1] != 'f')
9145 warning (OPT_Wattributes
,
9146 "bad option %s to optimize attribute", p
);
9148 warning (OPT_Wpragmas
,
9149 "bad option %s to pragma attribute", p
);
9157 /* Assume that Ox is -Ox, a numeric value is -Ox, a s by
9158 itself is -Os, and any other switch begins with a -f. */
9159 if ((*p
>= '0' && *p
<= '9')
9160 || (p
[0] == 's' && p
[1] == '\0'))
9166 memcpy (r
, p
, len2
);
9168 vec_safe_push (optimize_args
, (const char *) q
);
9174 opt_argc
= optimize_args
->length ();
9175 opt_argv
= (const char **) alloca (sizeof (char *) * (opt_argc
+ 1));
9177 for (i
= 1; i
< opt_argc
; i
++)
9178 opt_argv
[i
] = (*optimize_args
)[i
];
9180 saved_flag_strict_aliasing
= flag_strict_aliasing
;
9182 /* Now parse the options. */
9183 decode_cmdline_options_to_array_default_mask (opt_argc
, opt_argv
,
9185 &decoded_options_count
);
9186 decode_options (&global_options
, &global_options_set
,
9187 decoded_options
, decoded_options_count
,
9188 input_location
, global_dc
);
9190 targetm
.override_options_after_change();
9192 /* Don't allow changing -fstrict-aliasing. */
9193 flag_strict_aliasing
= saved_flag_strict_aliasing
;
9195 optimize_args
->truncate (0);
9199 /* For handling "optimize" attribute. arguments as in
9200 struct attribute_spec.handler. */
9203 handle_optimize_attribute (tree
*node
, tree name
, tree args
,
9204 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9206 /* Ensure we have a function type. */
9207 if (TREE_CODE (*node
) != FUNCTION_DECL
)
9209 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9210 *no_add_attrs
= true;
9214 struct cl_optimization cur_opts
;
9215 tree old_opts
= DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
);
9217 /* Save current options. */
9218 cl_optimization_save (&cur_opts
, &global_options
);
9220 /* If we previously had some optimization options, use them as the
9223 cl_optimization_restore (&global_options
,
9224 TREE_OPTIMIZATION (old_opts
));
9226 /* Parse options, and update the vector. */
9227 parse_optimize_options (args
, true);
9228 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
)
9229 = build_optimization_node (&global_options
);
9231 /* Restore current options. */
9232 cl_optimization_restore (&global_options
, &cur_opts
);
9238 /* Handle a "no_split_stack" attribute. */
9241 handle_no_split_stack_attribute (tree
*node
, tree name
,
9242 tree
ARG_UNUSED (args
),
9243 int ARG_UNUSED (flags
),
9248 if (TREE_CODE (decl
) != FUNCTION_DECL
)
9250 error_at (DECL_SOURCE_LOCATION (decl
),
9251 "%qE attribute applies only to functions", name
);
9252 *no_add_attrs
= true;
9254 else if (DECL_INITIAL (decl
))
9256 error_at (DECL_SOURCE_LOCATION (decl
),
9257 "can%'t set %qE attribute after definition", name
);
9258 *no_add_attrs
= true;
9264 /* Handle a "returns_nonnull" attribute; arguments as in
9265 struct attribute_spec.handler. */
9268 handle_returns_nonnull_attribute (tree
*node
, tree
, tree
, int,
9271 // Even without a prototype we still have a return type we can check.
9272 if (TREE_CODE (TREE_TYPE (*node
)) != POINTER_TYPE
)
9274 error ("returns_nonnull attribute on a function not returning a pointer");
9275 *no_add_attrs
= true;
9281 /* Check for valid arguments being passed to a function with FNTYPE.
9282 There are NARGS arguments in the array ARGARRAY. */
9284 check_function_arguments (const_tree fntype
, int nargs
, tree
*argarray
)
9286 /* Check for null being passed in a pointer argument that must be
9287 non-null. We also need to do this if format checking is enabled. */
9290 check_function_nonnull (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
9292 /* Check for errors in format strings. */
9294 if (warn_format
|| warn_suggest_attribute_format
)
9295 check_function_format (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
9298 check_function_sentinel (fntype
, nargs
, argarray
);
9301 /* Generic argument checking recursion routine. PARAM is the argument to
9302 be checked. PARAM_NUM is the number of the argument. CALLBACK is invoked
9303 once the argument is resolved. CTX is context for the callback. */
9305 check_function_arguments_recurse (void (*callback
)
9306 (void *, tree
, unsigned HOST_WIDE_INT
),
9307 void *ctx
, tree param
,
9308 unsigned HOST_WIDE_INT param_num
)
9310 if (CONVERT_EXPR_P (param
)
9311 && (TYPE_PRECISION (TREE_TYPE (param
))
9312 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (param
, 0)))))
9314 /* Strip coercion. */
9315 check_function_arguments_recurse (callback
, ctx
,
9316 TREE_OPERAND (param
, 0), param_num
);
9320 if (TREE_CODE (param
) == CALL_EXPR
)
9322 tree type
= TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (param
)));
9324 bool found_format_arg
= false;
9326 /* See if this is a call to a known internationalization function
9327 that modifies a format arg. Such a function may have multiple
9328 format_arg attributes (for example, ngettext). */
9330 for (attrs
= TYPE_ATTRIBUTES (type
);
9332 attrs
= TREE_CHAIN (attrs
))
9333 if (is_attribute_p ("format_arg", TREE_PURPOSE (attrs
)))
9336 tree format_num_expr
;
9339 call_expr_arg_iterator iter
;
9341 /* Extract the argument number, which was previously checked
9343 format_num_expr
= TREE_VALUE (TREE_VALUE (attrs
));
9345 format_num
= tree_to_uhwi (format_num_expr
);
9347 for (inner_arg
= first_call_expr_arg (param
, &iter
), i
= 1;
9349 inner_arg
= next_call_expr_arg (&iter
), i
++)
9350 if (i
== format_num
)
9352 check_function_arguments_recurse (callback
, ctx
,
9353 inner_arg
, param_num
);
9354 found_format_arg
= true;
9359 /* If we found a format_arg attribute and did a recursive check,
9360 we are done with checking this argument. Otherwise, we continue
9361 and this will be considered a non-literal. */
9362 if (found_format_arg
)
9366 if (TREE_CODE (param
) == COND_EXPR
)
9368 /* Check both halves of the conditional expression. */
9369 check_function_arguments_recurse (callback
, ctx
,
9370 TREE_OPERAND (param
, 1), param_num
);
9371 check_function_arguments_recurse (callback
, ctx
,
9372 TREE_OPERAND (param
, 2), param_num
);
9376 (*callback
) (ctx
, param
, param_num
);
9379 /* Checks for a builtin function FNDECL that the number of arguments
9380 NARGS against the required number REQUIRED and issues an error if
9381 there is a mismatch. Returns true if the number of arguments is
9382 correct, otherwise false. */
9385 builtin_function_validate_nargs (tree fndecl
, int nargs
, int required
)
9387 if (nargs
< required
)
9389 error_at (input_location
,
9390 "not enough arguments to function %qE", fndecl
);
9393 else if (nargs
> required
)
9395 error_at (input_location
,
9396 "too many arguments to function %qE", fndecl
);
9402 /* Verifies the NARGS arguments ARGS to the builtin function FNDECL.
9403 Returns false if there was an error, otherwise true. */
9406 check_builtin_function_arguments (tree fndecl
, int nargs
, tree
*args
)
9408 if (!DECL_BUILT_IN (fndecl
)
9409 || DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_NORMAL
)
9412 switch (DECL_FUNCTION_CODE (fndecl
))
9414 case BUILT_IN_CONSTANT_P
:
9415 return builtin_function_validate_nargs (fndecl
, nargs
, 1);
9417 case BUILT_IN_ISFINITE
:
9418 case BUILT_IN_ISINF
:
9419 case BUILT_IN_ISINF_SIGN
:
9420 case BUILT_IN_ISNAN
:
9421 case BUILT_IN_ISNORMAL
:
9422 if (builtin_function_validate_nargs (fndecl
, nargs
, 1))
9424 if (TREE_CODE (TREE_TYPE (args
[0])) != REAL_TYPE
)
9426 error ("non-floating-point argument in call to "
9427 "function %qE", fndecl
);
9434 case BUILT_IN_ISGREATER
:
9435 case BUILT_IN_ISGREATEREQUAL
:
9436 case BUILT_IN_ISLESS
:
9437 case BUILT_IN_ISLESSEQUAL
:
9438 case BUILT_IN_ISLESSGREATER
:
9439 case BUILT_IN_ISUNORDERED
:
9440 if (builtin_function_validate_nargs (fndecl
, nargs
, 2))
9442 enum tree_code code0
, code1
;
9443 code0
= TREE_CODE (TREE_TYPE (args
[0]));
9444 code1
= TREE_CODE (TREE_TYPE (args
[1]));
9445 if (!((code0
== REAL_TYPE
&& code1
== REAL_TYPE
)
9446 || (code0
== REAL_TYPE
&& code1
== INTEGER_TYPE
)
9447 || (code0
== INTEGER_TYPE
&& code1
== REAL_TYPE
)))
9449 error ("non-floating-point arguments in call to "
9450 "function %qE", fndecl
);
9457 case BUILT_IN_FPCLASSIFY
:
9458 if (builtin_function_validate_nargs (fndecl
, nargs
, 6))
9463 if (TREE_CODE (args
[i
]) != INTEGER_CST
)
9465 error ("non-const integer argument %u in call to function %qE",
9470 if (TREE_CODE (TREE_TYPE (args
[5])) != REAL_TYPE
)
9472 error ("non-floating-point argument in call to function %qE",
9480 case BUILT_IN_ASSUME_ALIGNED
:
9481 if (builtin_function_validate_nargs (fndecl
, nargs
, 2 + (nargs
> 2)))
9483 if (nargs
>= 3 && TREE_CODE (TREE_TYPE (args
[2])) != INTEGER_TYPE
)
9485 error ("non-integer argument 3 in call to function %qE", fndecl
);
9497 /* Function to help qsort sort FIELD_DECLs by name order. */
9500 field_decl_cmp (const void *x_p
, const void *y_p
)
9502 const tree
*const x
= (const tree
*const) x_p
;
9503 const tree
*const y
= (const tree
*const) y_p
;
9505 if (DECL_NAME (*x
) == DECL_NAME (*y
))
9506 /* A nontype is "greater" than a type. */
9507 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
9508 if (DECL_NAME (*x
) == NULL_TREE
)
9510 if (DECL_NAME (*y
) == NULL_TREE
)
9512 if (DECL_NAME (*x
) < DECL_NAME (*y
))
9518 gt_pointer_operator new_value
;
9522 /* This routine compares two fields like field_decl_cmp but using the
9523 pointer operator in resort_data. */
9526 resort_field_decl_cmp (const void *x_p
, const void *y_p
)
9528 const tree
*const x
= (const tree
*const) x_p
;
9529 const tree
*const y
= (const tree
*const) y_p
;
9531 if (DECL_NAME (*x
) == DECL_NAME (*y
))
9532 /* A nontype is "greater" than a type. */
9533 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
9534 if (DECL_NAME (*x
) == NULL_TREE
)
9536 if (DECL_NAME (*y
) == NULL_TREE
)
9539 tree d1
= DECL_NAME (*x
);
9540 tree d2
= DECL_NAME (*y
);
9541 resort_data
.new_value (&d1
, resort_data
.cookie
);
9542 resort_data
.new_value (&d2
, resort_data
.cookie
);
9549 /* Resort DECL_SORTED_FIELDS because pointers have been reordered. */
9552 resort_sorted_fields (void *obj
,
9553 void * ARG_UNUSED (orig_obj
),
9554 gt_pointer_operator new_value
,
9557 struct sorted_fields_type
*sf
= (struct sorted_fields_type
*) obj
;
9558 resort_data
.new_value
= new_value
;
9559 resort_data
.cookie
= cookie
;
9560 qsort (&sf
->elts
[0], sf
->len
, sizeof (tree
),
9561 resort_field_decl_cmp
);
9564 /* Subroutine of c_parse_error.
9565 Return the result of concatenating LHS and RHS. RHS is really
9566 a string literal, its first character is indicated by RHS_START and
9567 RHS_SIZE is its length (including the terminating NUL character).
9569 The caller is responsible for deleting the returned pointer. */
9572 catenate_strings (const char *lhs
, const char *rhs_start
, int rhs_size
)
9574 const int lhs_size
= strlen (lhs
);
9575 char *result
= XNEWVEC (char, lhs_size
+ rhs_size
);
9576 strncpy (result
, lhs
, lhs_size
);
9577 strncpy (result
+ lhs_size
, rhs_start
, rhs_size
);
9581 /* Issue the error given by GMSGID, indicating that it occurred before
9582 TOKEN, which had the associated VALUE. */
9585 c_parse_error (const char *gmsgid
, enum cpp_ttype token_type
,
9586 tree value
, unsigned char token_flags
)
9588 #define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2))
9590 char *message
= NULL
;
9592 if (token_type
== CPP_EOF
)
9593 message
= catenate_messages (gmsgid
, " at end of input");
9594 else if (token_type
== CPP_CHAR
9595 || token_type
== CPP_WCHAR
9596 || token_type
== CPP_CHAR16
9597 || token_type
== CPP_CHAR32
)
9599 unsigned int val
= TREE_INT_CST_LOW (value
);
9618 if (val
<= UCHAR_MAX
&& ISGRAPH (val
))
9619 message
= catenate_messages (gmsgid
, " before %s'%c'");
9621 message
= catenate_messages (gmsgid
, " before %s'\\x%x'");
9623 error (message
, prefix
, val
);
9627 else if (token_type
== CPP_CHAR_USERDEF
9628 || token_type
== CPP_WCHAR_USERDEF
9629 || token_type
== CPP_CHAR16_USERDEF
9630 || token_type
== CPP_CHAR32_USERDEF
)
9631 message
= catenate_messages (gmsgid
,
9632 " before user-defined character literal");
9633 else if (token_type
== CPP_STRING_USERDEF
9634 || token_type
== CPP_WSTRING_USERDEF
9635 || token_type
== CPP_STRING16_USERDEF
9636 || token_type
== CPP_STRING32_USERDEF
9637 || token_type
== CPP_UTF8STRING_USERDEF
)
9638 message
= catenate_messages (gmsgid
, " before user-defined string literal");
9639 else if (token_type
== CPP_STRING
9640 || token_type
== CPP_WSTRING
9641 || token_type
== CPP_STRING16
9642 || token_type
== CPP_STRING32
9643 || token_type
== CPP_UTF8STRING
)
9644 message
= catenate_messages (gmsgid
, " before string constant");
9645 else if (token_type
== CPP_NUMBER
)
9646 message
= catenate_messages (gmsgid
, " before numeric constant");
9647 else if (token_type
== CPP_NAME
)
9649 message
= catenate_messages (gmsgid
, " before %qE");
9650 error (message
, value
);
9654 else if (token_type
== CPP_PRAGMA
)
9655 message
= catenate_messages (gmsgid
, " before %<#pragma%>");
9656 else if (token_type
== CPP_PRAGMA_EOL
)
9657 message
= catenate_messages (gmsgid
, " before end of line");
9658 else if (token_type
== CPP_DECLTYPE
)
9659 message
= catenate_messages (gmsgid
, " before %<decltype%>");
9660 else if (token_type
< N_TTYPES
)
9662 message
= catenate_messages (gmsgid
, " before %qs token");
9663 error (message
, cpp_type2name (token_type
, token_flags
));
9675 #undef catenate_messages
9678 /* Mapping for cpp message reasons to the options that enable them. */
9680 struct reason_option_codes_t
9682 const int reason
; /* cpplib message reason. */
9683 const int option_code
; /* gcc option that controls this message. */
9686 static const struct reason_option_codes_t option_codes
[] = {
9687 {CPP_W_DEPRECATED
, OPT_Wdeprecated
},
9688 {CPP_W_COMMENTS
, OPT_Wcomment
},
9689 {CPP_W_TRIGRAPHS
, OPT_Wtrigraphs
},
9690 {CPP_W_MULTICHAR
, OPT_Wmultichar
},
9691 {CPP_W_TRADITIONAL
, OPT_Wtraditional
},
9692 {CPP_W_LONG_LONG
, OPT_Wlong_long
},
9693 {CPP_W_ENDIF_LABELS
, OPT_Wendif_labels
},
9694 {CPP_W_VARIADIC_MACROS
, OPT_Wvariadic_macros
},
9695 {CPP_W_BUILTIN_MACRO_REDEFINED
, OPT_Wbuiltin_macro_redefined
},
9696 {CPP_W_UNDEF
, OPT_Wundef
},
9697 {CPP_W_UNUSED_MACROS
, OPT_Wunused_macros
},
9698 {CPP_W_CXX_OPERATOR_NAMES
, OPT_Wc___compat
},
9699 {CPP_W_NORMALIZE
, OPT_Wnormalized_
},
9700 {CPP_W_INVALID_PCH
, OPT_Winvalid_pch
},
9701 {CPP_W_WARNING_DIRECTIVE
, OPT_Wcpp
},
9702 {CPP_W_LITERAL_SUFFIX
, OPT_Wliteral_suffix
},
9703 {CPP_W_DATE_TIME
, OPT_Wdate_time
},
9707 /* Return the gcc option code associated with the reason for a cpp
9708 message, or 0 if none. */
9711 c_option_controlling_cpp_error (int reason
)
9713 const struct reason_option_codes_t
*entry
;
9715 for (entry
= option_codes
; entry
->reason
!= CPP_W_NONE
; entry
++)
9717 if (entry
->reason
== reason
)
9718 return entry
->option_code
;
9723 /* Callback from cpp_error for PFILE to print diagnostics from the
9724 preprocessor. The diagnostic is of type LEVEL, with REASON set
9725 to the reason code if LEVEL is represents a warning, at location
9726 LOCATION unless this is after lexing and the compiler's location
9727 should be used instead, with column number possibly overridden by
9728 COLUMN_OVERRIDE if not zero; MSG is the translated message and AP
9729 the arguments. Returns true if a diagnostic was emitted, false
9733 c_cpp_error (cpp_reader
*pfile ATTRIBUTE_UNUSED
, int level
, int reason
,
9734 location_t location
, unsigned int column_override
,
9735 const char *msg
, va_list *ap
)
9737 diagnostic_info diagnostic
;
9738 diagnostic_t dlevel
;
9739 bool save_warn_system_headers
= global_dc
->dc_warn_system_headers
;
9744 case CPP_DL_WARNING_SYSHDR
:
9747 global_dc
->dc_warn_system_headers
= 1;
9749 case CPP_DL_WARNING
:
9752 dlevel
= DK_WARNING
;
9754 case CPP_DL_PEDWARN
:
9755 if (flag_no_output
&& !flag_pedantic_errors
)
9757 dlevel
= DK_PEDWARN
;
9775 location
= input_location
;
9776 diagnostic_set_info_translated (&diagnostic
, msg
, ap
,
9778 if (column_override
)
9779 diagnostic_override_column (&diagnostic
, column_override
);
9780 diagnostic_override_option_index (&diagnostic
,
9781 c_option_controlling_cpp_error (reason
));
9782 ret
= report_diagnostic (&diagnostic
);
9783 if (level
== CPP_DL_WARNING_SYSHDR
)
9784 global_dc
->dc_warn_system_headers
= save_warn_system_headers
;
9788 /* Convert a character from the host to the target execution character
9789 set. cpplib handles this, mostly. */
9792 c_common_to_target_charset (HOST_WIDE_INT c
)
9794 /* Character constants in GCC proper are sign-extended under -fsigned-char,
9795 zero-extended under -fno-signed-char. cpplib insists that characters
9796 and character constants are always unsigned. Hence we must convert
9798 cppchar_t uc
= ((cppchar_t
)c
) & ((((cppchar_t
)1) << CHAR_BIT
)-1);
9800 uc
= cpp_host_to_exec_charset (parse_in
, uc
);
9802 if (flag_signed_char
)
9803 return ((HOST_WIDE_INT
)uc
) << (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
)
9804 >> (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
);
9809 /* Fold an offsetof-like expression. EXPR is a nested sequence of component
9810 references with an INDIRECT_REF of a constant at the bottom; much like the
9811 traditional rendering of offsetof as a macro. Return the folded result. */
9814 fold_offsetof_1 (tree expr
)
9818 switch (TREE_CODE (expr
))
9824 error ("cannot apply %<offsetof%> to static data member %qD", expr
);
9825 return error_mark_node
;
9829 error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded");
9830 return error_mark_node
;
9834 if (!TREE_CONSTANT (TREE_OPERAND (expr
, 0)))
9836 error ("cannot apply %<offsetof%> to a non constant address");
9837 return error_mark_node
;
9839 return TREE_OPERAND (expr
, 0);
9842 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0));
9843 if (base
== error_mark_node
)
9846 t
= TREE_OPERAND (expr
, 1);
9847 if (DECL_C_BIT_FIELD (t
))
9849 error ("attempt to take address of bit-field structure "
9851 return error_mark_node
;
9853 off
= size_binop_loc (input_location
, PLUS_EXPR
, DECL_FIELD_OFFSET (t
),
9854 size_int (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (t
))
9859 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0));
9860 if (base
== error_mark_node
)
9863 t
= TREE_OPERAND (expr
, 1);
9865 /* Check if the offset goes beyond the upper bound of the array. */
9866 if (TREE_CODE (t
) == INTEGER_CST
&& tree_int_cst_sgn (t
) >= 0)
9868 tree upbound
= array_ref_up_bound (expr
);
9869 if (upbound
!= NULL_TREE
9870 && TREE_CODE (upbound
) == INTEGER_CST
9871 && !tree_int_cst_equal (upbound
,
9872 TYPE_MAX_VALUE (TREE_TYPE (upbound
))))
9874 upbound
= size_binop (PLUS_EXPR
, upbound
,
9875 build_int_cst (TREE_TYPE (upbound
), 1));
9876 if (tree_int_cst_lt (upbound
, t
))
9880 for (v
= TREE_OPERAND (expr
, 0);
9881 TREE_CODE (v
) == COMPONENT_REF
;
9882 v
= TREE_OPERAND (v
, 0))
9883 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v
, 0)))
9886 tree fld_chain
= DECL_CHAIN (TREE_OPERAND (v
, 1));
9887 for (; fld_chain
; fld_chain
= DECL_CHAIN (fld_chain
))
9888 if (TREE_CODE (fld_chain
) == FIELD_DECL
)
9894 /* Don't warn if the array might be considered a poor
9895 man's flexible array member with a very permissive
9896 definition thereof. */
9897 if (TREE_CODE (v
) == ARRAY_REF
9898 || TREE_CODE (v
) == COMPONENT_REF
)
9899 warning (OPT_Warray_bounds
,
9900 "index %E denotes an offset "
9901 "greater than size of %qT",
9902 t
, TREE_TYPE (TREE_OPERAND (expr
, 0)));
9907 t
= convert (sizetype
, t
);
9908 off
= size_binop (MULT_EXPR
, TYPE_SIZE_UNIT (TREE_TYPE (expr
)), t
);
9912 /* Handle static members of volatile structs. */
9913 t
= TREE_OPERAND (expr
, 1);
9914 gcc_assert (TREE_CODE (t
) == VAR_DECL
);
9915 return fold_offsetof_1 (t
);
9921 return fold_build_pointer_plus (base
, off
);
9924 /* Likewise, but convert it to the return type of offsetof. */
9927 fold_offsetof (tree expr
)
9929 return convert (size_type_node
, fold_offsetof_1 (expr
));
9932 /* Warn for A ?: C expressions (with B omitted) where A is a boolean
9933 expression, because B will always be true. */
9936 warn_for_omitted_condop (location_t location
, tree cond
)
9938 if (truth_value_p (TREE_CODE (cond
)))
9939 warning_at (location
, OPT_Wparentheses
,
9940 "the omitted middle operand in ?: will always be %<true%>, "
9941 "suggest explicit middle operand");
9944 /* Give an error for storing into ARG, which is 'const'. USE indicates
9945 how ARG was being used. */
9948 readonly_error (location_t loc
, tree arg
, enum lvalue_use use
)
9950 gcc_assert (use
== lv_assign
|| use
== lv_increment
|| use
== lv_decrement
9952 /* Using this macro rather than (for example) arrays of messages
9953 ensures that all the format strings are checked at compile
9955 #define READONLY_MSG(A, I, D, AS) (use == lv_assign ? (A) \
9956 : (use == lv_increment ? (I) \
9957 : (use == lv_decrement ? (D) : (AS))))
9958 if (TREE_CODE (arg
) == COMPONENT_REF
)
9960 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg
, 0))))
9961 error_at (loc
, READONLY_MSG (G_("assignment of member "
9962 "%qD in read-only object"),
9963 G_("increment of member "
9964 "%qD in read-only object"),
9965 G_("decrement of member "
9966 "%qD in read-only object"),
9967 G_("member %qD in read-only object "
9968 "used as %<asm%> output")),
9969 TREE_OPERAND (arg
, 1));
9971 error_at (loc
, READONLY_MSG (G_("assignment of read-only member %qD"),
9972 G_("increment of read-only member %qD"),
9973 G_("decrement of read-only member %qD"),
9974 G_("read-only member %qD used as %<asm%> output")),
9975 TREE_OPERAND (arg
, 1));
9977 else if (TREE_CODE (arg
) == VAR_DECL
)
9978 error_at (loc
, READONLY_MSG (G_("assignment of read-only variable %qD"),
9979 G_("increment of read-only variable %qD"),
9980 G_("decrement of read-only variable %qD"),
9981 G_("read-only variable %qD used as %<asm%> output")),
9983 else if (TREE_CODE (arg
) == PARM_DECL
)
9984 error_at (loc
, READONLY_MSG (G_("assignment of read-only parameter %qD"),
9985 G_("increment of read-only parameter %qD"),
9986 G_("decrement of read-only parameter %qD"),
9987 G_("read-only parameter %qD use as %<asm%> output")),
9989 else if (TREE_CODE (arg
) == RESULT_DECL
)
9991 gcc_assert (c_dialect_cxx ());
9992 error_at (loc
, READONLY_MSG (G_("assignment of "
9993 "read-only named return value %qD"),
9995 "read-only named return value %qD"),
9997 "read-only named return value %qD"),
9998 G_("read-only named return value %qD "
9999 "used as %<asm%>output")),
10002 else if (TREE_CODE (arg
) == FUNCTION_DECL
)
10003 error_at (loc
, READONLY_MSG (G_("assignment of function %qD"),
10004 G_("increment of function %qD"),
10005 G_("decrement of function %qD"),
10006 G_("function %qD used as %<asm%> output")),
10009 error_at (loc
, READONLY_MSG (G_("assignment of read-only location %qE"),
10010 G_("increment of read-only location %qE"),
10011 G_("decrement of read-only location %qE"),
10012 G_("read-only location %qE used as %<asm%> output")),
10016 /* Print an error message for an invalid lvalue. USE says
10017 how the lvalue is being used and so selects the error message. LOC
10018 is the location for the error. */
10021 lvalue_error (location_t loc
, enum lvalue_use use
)
10026 error_at (loc
, "lvalue required as left operand of assignment");
10029 error_at (loc
, "lvalue required as increment operand");
10032 error_at (loc
, "lvalue required as decrement operand");
10035 error_at (loc
, "lvalue required as unary %<&%> operand");
10038 error_at (loc
, "lvalue required in asm statement");
10041 gcc_unreachable ();
10045 /* Print an error message for an invalid indirection of type TYPE.
10046 ERRSTRING is the name of the operator for the indirection. */
10049 invalid_indirection_error (location_t loc
, tree type
, ref_operator errstring
)
10054 gcc_assert (c_dialect_cxx ());
10055 error_at (loc
, "invalid type argument (have %qT)", type
);
10057 case RO_ARRAY_INDEXING
:
10059 "invalid type argument of array indexing (have %qT)",
10062 case RO_UNARY_STAR
:
10064 "invalid type argument of unary %<*%> (have %qT)",
10069 "invalid type argument of %<->%> (have %qT)",
10072 case RO_ARROW_STAR
:
10074 "invalid type argument of %<->*%> (have %qT)",
10077 case RO_IMPLICIT_CONVERSION
:
10079 "invalid type argument of implicit conversion (have %qT)",
10083 gcc_unreachable ();
10087 /* *PTYPE is an incomplete array. Complete it with a domain based on
10088 INITIAL_VALUE. If INITIAL_VALUE is not present, use 1 if DO_DEFAULT
10089 is true. Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
10090 2 if INITIAL_VALUE was NULL, and 3 if INITIAL_VALUE was empty. */
10093 complete_array_type (tree
*ptype
, tree initial_value
, bool do_default
)
10095 tree maxindex
, type
, main_type
, elt
, unqual_elt
;
10096 int failure
= 0, quals
;
10097 hashval_t hashcode
= 0;
10098 bool overflow_p
= false;
10100 maxindex
= size_zero_node
;
10103 if (TREE_CODE (initial_value
) == STRING_CST
)
10106 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value
)));
10107 maxindex
= size_int (TREE_STRING_LENGTH (initial_value
)/eltsize
- 1);
10109 else if (TREE_CODE (initial_value
) == CONSTRUCTOR
)
10111 vec
<constructor_elt
, va_gc
> *v
= CONSTRUCTOR_ELTS (initial_value
);
10113 if (vec_safe_is_empty (v
))
10117 maxindex
= ssize_int (-1);
10122 unsigned HOST_WIDE_INT cnt
;
10123 constructor_elt
*ce
;
10124 bool fold_p
= false;
10127 maxindex
= (*v
)[0].index
, fold_p
= true;
10129 curindex
= maxindex
;
10131 for (cnt
= 1; vec_safe_iterate (v
, cnt
, &ce
); cnt
++)
10133 bool curfold_p
= false;
10135 curindex
= ce
->index
, curfold_p
= true;
10140 /* Since we treat size types now as ordinary
10141 unsigned types, we need an explicit overflow
10143 tree orig
= curindex
;
10144 curindex
= fold_convert (sizetype
, curindex
);
10145 overflow_p
|= tree_int_cst_lt (curindex
, orig
);
10147 curindex
= size_binop (PLUS_EXPR
, curindex
,
10150 if (tree_int_cst_lt (maxindex
, curindex
))
10151 maxindex
= curindex
, fold_p
= curfold_p
;
10155 tree orig
= maxindex
;
10156 maxindex
= fold_convert (sizetype
, maxindex
);
10157 overflow_p
|= tree_int_cst_lt (maxindex
, orig
);
10163 /* Make an error message unless that happened already. */
10164 if (initial_value
!= error_mark_node
)
10176 elt
= TREE_TYPE (type
);
10177 quals
= TYPE_QUALS (strip_array_types (elt
));
10181 unqual_elt
= c_build_qualified_type (elt
, KEEP_QUAL_ADDR_SPACE (quals
));
10183 /* Using build_distinct_type_copy and modifying things afterward instead
10184 of using build_array_type to create a new type preserves all of the
10185 TYPE_LANG_FLAG_? bits that the front end may have set. */
10186 main_type
= build_distinct_type_copy (TYPE_MAIN_VARIANT (type
));
10187 TREE_TYPE (main_type
) = unqual_elt
;
10188 TYPE_DOMAIN (main_type
)
10189 = build_range_type (TREE_TYPE (maxindex
),
10190 build_int_cst (TREE_TYPE (maxindex
), 0), maxindex
);
10191 layout_type (main_type
);
10193 /* Make sure we have the canonical MAIN_TYPE. */
10194 hashcode
= iterative_hash_object (TYPE_HASH (unqual_elt
), hashcode
);
10195 hashcode
= iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (main_type
)),
10197 main_type
= type_hash_canon (hashcode
, main_type
);
10199 /* Fix the canonical type. */
10200 if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type
))
10201 || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type
)))
10202 SET_TYPE_STRUCTURAL_EQUALITY (main_type
);
10203 else if (TYPE_CANONICAL (TREE_TYPE (main_type
)) != TREE_TYPE (main_type
)
10204 || (TYPE_CANONICAL (TYPE_DOMAIN (main_type
))
10205 != TYPE_DOMAIN (main_type
)))
10206 TYPE_CANONICAL (main_type
)
10207 = build_array_type (TYPE_CANONICAL (TREE_TYPE (main_type
)),
10208 TYPE_CANONICAL (TYPE_DOMAIN (main_type
)));
10210 TYPE_CANONICAL (main_type
) = main_type
;
10215 type
= c_build_qualified_type (main_type
, quals
);
10217 if (COMPLETE_TYPE_P (type
)
10218 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
10219 && (overflow_p
|| TREE_OVERFLOW (TYPE_SIZE_UNIT (type
))))
10221 error ("size of array is too large");
10222 /* If we proceed with the array type as it is, we'll eventually
10223 crash in tree_to_[su]hwi(). */
10224 type
= error_mark_node
;
10231 /* Like c_mark_addressable but don't check register qualifier. */
10233 c_common_mark_addressable_vec (tree t
)
10235 while (handled_component_p (t
))
10236 t
= TREE_OPERAND (t
, 0);
10237 if (TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != PARM_DECL
)
10239 TREE_ADDRESSABLE (t
) = 1;
10244 /* Used to help initialize the builtin-types.def table. When a type of
10245 the correct size doesn't exist, use error_mark_node instead of NULL.
10246 The later results in segfaults even when a decl using the type doesn't
10250 builtin_type_for_size (int size
, bool unsignedp
)
10252 tree type
= c_common_type_for_size (size
, unsignedp
);
10253 return type
? type
: error_mark_node
;
10256 /* A helper function for resolve_overloaded_builtin in resolving the
10257 overloaded __sync_ builtins. Returns a positive power of 2 if the
10258 first operand of PARAMS is a pointer to a supported data type.
10259 Returns 0 if an error is encountered. */
10262 sync_resolve_size (tree function
, vec
<tree
, va_gc
> *params
)
10269 error ("too few arguments to function %qE", function
);
10273 type
= TREE_TYPE ((*params
)[0]);
10274 if (TREE_CODE (type
) == ARRAY_TYPE
)
10276 /* Force array-to-pointer decay for C++. */
10277 gcc_assert (c_dialect_cxx());
10278 (*params
)[0] = default_conversion ((*params
)[0]);
10279 type
= TREE_TYPE ((*params
)[0]);
10281 if (TREE_CODE (type
) != POINTER_TYPE
)
10284 type
= TREE_TYPE (type
);
10285 if (!INTEGRAL_TYPE_P (type
) && !POINTER_TYPE_P (type
))
10288 size
= tree_to_uhwi (TYPE_SIZE_UNIT (type
));
10289 if (size
== 1 || size
== 2 || size
== 4 || size
== 8 || size
== 16)
10293 error ("incompatible type for argument %d of %qE", 1, function
);
10297 /* A helper function for resolve_overloaded_builtin. Adds casts to
10298 PARAMS to make arguments match up with those of FUNCTION. Drops
10299 the variadic arguments at the end. Returns false if some error
10300 was encountered; true on success. */
10303 sync_resolve_params (location_t loc
, tree orig_function
, tree function
,
10304 vec
<tree
, va_gc
> *params
, bool orig_format
)
10306 function_args_iterator iter
;
10308 unsigned int parmnum
;
10310 function_args_iter_init (&iter
, TREE_TYPE (function
));
10311 /* We've declared the implementation functions to use "volatile void *"
10312 as the pointer parameter, so we shouldn't get any complaints from the
10313 call to check_function_arguments what ever type the user used. */
10314 function_args_iter_next (&iter
);
10315 ptype
= TREE_TYPE (TREE_TYPE ((*params
)[0]));
10316 ptype
= TYPE_MAIN_VARIANT (ptype
);
10318 /* For the rest of the values, we need to cast these to FTYPE, so that we
10319 don't get warnings for passing pointer types, etc. */
10323 tree val
, arg_type
;
10325 arg_type
= function_args_iter_cond (&iter
);
10326 /* XXX void_type_node belies the abstraction. */
10327 if (arg_type
== void_type_node
)
10331 if (params
->length () <= parmnum
)
10333 error_at (loc
, "too few arguments to function %qE", orig_function
);
10337 /* Only convert parameters if arg_type is unsigned integer type with
10338 new format sync routines, i.e. don't attempt to convert pointer
10339 arguments (e.g. EXPECTED argument of __atomic_compare_exchange_n),
10340 bool arguments (e.g. WEAK argument) or signed int arguments (memmodel
10342 if (TREE_CODE (arg_type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (arg_type
))
10344 /* Ideally for the first conversion we'd use convert_for_assignment
10345 so that we get warnings for anything that doesn't match the pointer
10346 type. This isn't portable across the C and C++ front ends atm. */
10347 val
= (*params
)[parmnum
];
10348 val
= convert (ptype
, val
);
10349 val
= convert (arg_type
, val
);
10350 (*params
)[parmnum
] = val
;
10353 function_args_iter_next (&iter
);
10356 /* __atomic routines are not variadic. */
10357 if (!orig_format
&& params
->length () != parmnum
+ 1)
10359 error_at (loc
, "too many arguments to function %qE", orig_function
);
10363 /* The definition of these primitives is variadic, with the remaining
10364 being "an optional list of variables protected by the memory barrier".
10365 No clue what that's supposed to mean, precisely, but we consider all
10366 call-clobbered variables to be protected so we're safe. */
10367 params
->truncate (parmnum
+ 1);
10372 /* A helper function for resolve_overloaded_builtin. Adds a cast to
10373 RESULT to make it match the type of the first pointer argument in
10377 sync_resolve_return (tree first_param
, tree result
, bool orig_format
)
10379 tree ptype
= TREE_TYPE (TREE_TYPE (first_param
));
10380 tree rtype
= TREE_TYPE (result
);
10381 ptype
= TYPE_MAIN_VARIANT (ptype
);
10383 /* New format doesn't require casting unless the types are the same size. */
10384 if (orig_format
|| tree_int_cst_equal (TYPE_SIZE (ptype
), TYPE_SIZE (rtype
)))
10385 return convert (ptype
, result
);
10390 /* This function verifies the PARAMS to generic atomic FUNCTION.
10391 It returns the size if all the parameters are the same size, otherwise
10392 0 is returned if the parameters are invalid. */
10395 get_atomic_generic_size (location_t loc
, tree function
,
10396 vec
<tree
, va_gc
> *params
)
10398 unsigned int n_param
;
10399 unsigned int n_model
;
10404 /* Determine the parameter makeup. */
10405 switch (DECL_FUNCTION_CODE (function
))
10407 case BUILT_IN_ATOMIC_EXCHANGE
:
10411 case BUILT_IN_ATOMIC_LOAD
:
10412 case BUILT_IN_ATOMIC_STORE
:
10416 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10421 gcc_unreachable ();
10424 if (vec_safe_length (params
) != n_param
)
10426 error_at (loc
, "incorrect number of arguments to function %qE", function
);
10430 /* Get type of first parameter, and determine its size. */
10431 type_0
= TREE_TYPE ((*params
)[0]);
10432 if (TREE_CODE (type_0
) == ARRAY_TYPE
)
10434 /* Force array-to-pointer decay for C++. */
10435 gcc_assert (c_dialect_cxx());
10436 (*params
)[0] = default_conversion ((*params
)[0]);
10437 type_0
= TREE_TYPE ((*params
)[0]);
10439 if (TREE_CODE (type_0
) != POINTER_TYPE
|| VOID_TYPE_P (TREE_TYPE (type_0
)))
10441 error_at (loc
, "argument 1 of %qE must be a non-void pointer type",
10446 /* Types must be compile time constant sizes. */
10447 if (TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type_0
)))) != INTEGER_CST
)
10450 "argument 1 of %qE must be a pointer to a constant size type",
10455 size_0
= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type_0
)));
10457 /* Zero size objects are not allowed. */
10461 "argument 1 of %qE must be a pointer to a nonzero size object",
10466 /* Check each other parameter is a pointer and the same size. */
10467 for (x
= 0; x
< n_param
- n_model
; x
++)
10470 tree type
= TREE_TYPE ((*params
)[x
]);
10471 /* __atomic_compare_exchange has a bool in the 4th position, skip it. */
10472 if (n_param
== 6 && x
== 3)
10474 if (!POINTER_TYPE_P (type
))
10476 error_at (loc
, "argument %d of %qE must be a pointer type", x
+ 1,
10480 tree type_size
= TYPE_SIZE_UNIT (TREE_TYPE (type
));
10481 size
= type_size
? tree_to_uhwi (type_size
) : 0;
10482 if (size
!= size_0
)
10484 error_at (loc
, "size mismatch in argument %d of %qE", x
+ 1,
10490 /* Check memory model parameters for validity. */
10491 for (x
= n_param
- n_model
; x
< n_param
; x
++)
10493 tree p
= (*params
)[x
];
10494 if (TREE_CODE (p
) == INTEGER_CST
)
10496 int i
= tree_to_uhwi (p
);
10497 if (i
< 0 || (i
& MEMMODEL_MASK
) >= MEMMODEL_LAST
)
10499 warning_at (loc
, OPT_Winvalid_memory_model
,
10500 "invalid memory model argument %d of %qE", x
+ 1,
10505 if (!INTEGRAL_TYPE_P (TREE_TYPE (p
)))
10507 error_at (loc
, "non-integer memory model argument %d of %qE", x
+ 1,
10517 /* This will take an __atomic_ generic FUNCTION call, and add a size parameter N
10518 at the beginning of the parameter list PARAMS representing the size of the
10519 objects. This is to match the library ABI requirement. LOC is the location
10520 of the function call.
10521 The new function is returned if it needed rebuilding, otherwise NULL_TREE is
10522 returned to allow the external call to be constructed. */
10525 add_atomic_size_parameter (unsigned n
, location_t loc
, tree function
,
10526 vec
<tree
, va_gc
> *params
)
10530 /* Insert a SIZE_T parameter as the first param. If there isn't
10531 enough space, allocate a new vector and recursively re-build with that. */
10532 if (!params
->space (1))
10534 unsigned int z
, len
;
10535 vec
<tree
, va_gc
> *v
;
10538 len
= params
->length ();
10539 vec_alloc (v
, len
+ 1);
10540 v
->quick_push (build_int_cst (size_type_node
, n
));
10541 for (z
= 0; z
< len
; z
++)
10542 v
->quick_push ((*params
)[z
]);
10543 f
= build_function_call_vec (loc
, vNULL
, function
, v
, NULL
);
10548 /* Add the size parameter and leave as a function call for processing. */
10549 size_node
= build_int_cst (size_type_node
, n
);
10550 params
->quick_insert (0, size_node
);
10555 /* Return whether atomic operations for naturally aligned N-byte
10556 arguments are supported, whether inline or through libatomic. */
10558 atomic_size_supported_p (int n
)
10569 return targetm
.scalar_mode_supported_p (TImode
);
10576 /* This will process an __atomic_exchange function call, determine whether it
10577 needs to be mapped to the _N variation, or turned into a library call.
10578 LOC is the location of the builtin call.
10579 FUNCTION is the DECL that has been invoked;
10580 PARAMS is the argument list for the call. The return value is non-null
10581 TRUE is returned if it is translated into the proper format for a call to the
10582 external library, and NEW_RETURN is set the tree for that function.
10583 FALSE is returned if processing for the _N variation is required, and
10584 NEW_RETURN is set to the the return value the result is copied into. */
10586 resolve_overloaded_atomic_exchange (location_t loc
, tree function
,
10587 vec
<tree
, va_gc
> *params
, tree
*new_return
)
10589 tree p0
, p1
, p2
, p3
;
10590 tree I_type
, I_type_ptr
;
10591 int n
= get_atomic_generic_size (loc
, function
, params
);
10593 /* Size of 0 is an error condition. */
10596 *new_return
= error_mark_node
;
10600 /* If not a lock-free size, change to the library generic format. */
10601 if (!atomic_size_supported_p (n
))
10603 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10607 /* Otherwise there is a lockfree match, transform the call from:
10608 void fn(T* mem, T* desired, T* return, model)
10610 *return = (T) (fn (In* mem, (In) *desired, model)) */
10617 /* Create pointer to appropriate size. */
10618 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10619 I_type_ptr
= build_pointer_type (I_type
);
10621 /* Convert object pointer to required type. */
10622 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10624 /* Convert new value to required type, and dereference it. */
10625 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
10626 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
10629 /* Move memory model to the 3rd position, and end param list. */
10631 params
->truncate (3);
10633 /* Convert return pointer and dereference it for later assignment. */
10634 *new_return
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
10640 /* This will process an __atomic_compare_exchange function call, determine
10641 whether it needs to be mapped to the _N variation, or turned into a lib call.
10642 LOC is the location of the builtin call.
10643 FUNCTION is the DECL that has been invoked;
10644 PARAMS is the argument list for the call. The return value is non-null
10645 TRUE is returned if it is translated into the proper format for a call to the
10646 external library, and NEW_RETURN is set the tree for that function.
10647 FALSE is returned if processing for the _N variation is required. */
10650 resolve_overloaded_atomic_compare_exchange (location_t loc
, tree function
,
10651 vec
<tree
, va_gc
> *params
,
10655 tree I_type
, I_type_ptr
;
10656 int n
= get_atomic_generic_size (loc
, function
, params
);
10658 /* Size of 0 is an error condition. */
10661 *new_return
= error_mark_node
;
10665 /* If not a lock-free size, change to the library generic format. */
10666 if (!atomic_size_supported_p (n
))
10668 /* The library generic format does not have the weak parameter, so
10669 remove it from the param list. Since a parameter has been removed,
10670 we can be sure that there is room for the SIZE_T parameter, meaning
10671 there will not be a recursive rebuilding of the parameter list, so
10672 there is no danger this will be done twice. */
10675 (*params
)[3] = (*params
)[4];
10676 (*params
)[4] = (*params
)[5];
10677 params
->truncate (5);
10679 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10683 /* Otherwise, there is a match, so the call needs to be transformed from:
10684 bool fn(T* mem, T* desired, T* return, weak, success, failure)
10686 bool fn ((In *)mem, (In *)expected, (In) *desired, weak, succ, fail) */
10692 /* Create pointer to appropriate size. */
10693 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10694 I_type_ptr
= build_pointer_type (I_type
);
10696 /* Convert object pointer to required type. */
10697 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10700 /* Convert expected pointer to required type. */
10701 p1
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p1
);
10704 /* Convert desired value to required type, and dereference it. */
10705 p2
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
10706 p2
= build1 (VIEW_CONVERT_EXPR
, I_type
, p2
);
10709 /* The rest of the parameters are fine. NULL means no special return value
10711 *new_return
= NULL
;
10716 /* This will process an __atomic_load function call, determine whether it
10717 needs to be mapped to the _N variation, or turned into a library call.
10718 LOC is the location of the builtin call.
10719 FUNCTION is the DECL that has been invoked;
10720 PARAMS is the argument list for the call. The return value is non-null
10721 TRUE is returned if it is translated into the proper format for a call to the
10722 external library, and NEW_RETURN is set the tree for that function.
10723 FALSE is returned if processing for the _N variation is required, and
10724 NEW_RETURN is set to the the return value the result is copied into. */
10727 resolve_overloaded_atomic_load (location_t loc
, tree function
,
10728 vec
<tree
, va_gc
> *params
, tree
*new_return
)
10731 tree I_type
, I_type_ptr
;
10732 int n
= get_atomic_generic_size (loc
, function
, params
);
10734 /* Size of 0 is an error condition. */
10737 *new_return
= error_mark_node
;
10741 /* If not a lock-free size, change to the library generic format. */
10742 if (!atomic_size_supported_p (n
))
10744 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10748 /* Otherwise, there is a match, so the call needs to be transformed from:
10749 void fn(T* mem, T* return, model)
10751 *return = (T) (fn ((In *) mem, model)) */
10757 /* Create pointer to appropriate size. */
10758 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10759 I_type_ptr
= build_pointer_type (I_type
);
10761 /* Convert object pointer to required type. */
10762 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10765 /* Move memory model to the 2nd position, and end param list. */
10767 params
->truncate (2);
10769 /* Convert return pointer and dereference it for later assignment. */
10770 *new_return
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
10776 /* This will process an __atomic_store function call, determine whether it
10777 needs to be mapped to the _N variation, or turned into a library call.
10778 LOC is the location of the builtin call.
10779 FUNCTION is the DECL that has been invoked;
10780 PARAMS is the argument list for the call. The return value is non-null
10781 TRUE is returned if it is translated into the proper format for a call to the
10782 external library, and NEW_RETURN is set the tree for that function.
10783 FALSE is returned if processing for the _N variation is required, and
10784 NEW_RETURN is set to the the return value the result is copied into. */
10787 resolve_overloaded_atomic_store (location_t loc
, tree function
,
10788 vec
<tree
, va_gc
> *params
, tree
*new_return
)
10791 tree I_type
, I_type_ptr
;
10792 int n
= get_atomic_generic_size (loc
, function
, params
);
10794 /* Size of 0 is an error condition. */
10797 *new_return
= error_mark_node
;
10801 /* If not a lock-free size, change to the library generic format. */
10802 if (!atomic_size_supported_p (n
))
10804 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10808 /* Otherwise, there is a match, so the call needs to be transformed from:
10809 void fn(T* mem, T* value, model)
10811 fn ((In *) mem, (In) *value, model) */
10816 /* Create pointer to appropriate size. */
10817 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10818 I_type_ptr
= build_pointer_type (I_type
);
10820 /* Convert object pointer to required type. */
10821 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10824 /* Convert new value to required type, and dereference it. */
10825 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
10826 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
10829 /* The memory model is in the right spot already. Return is void. */
10830 *new_return
= NULL_TREE
;
10836 /* Some builtin functions are placeholders for other expressions. This
10837 function should be called immediately after parsing the call expression
10838 before surrounding code has committed to the type of the expression.
10840 LOC is the location of the builtin call.
10842 FUNCTION is the DECL that has been invoked; it is known to be a builtin.
10843 PARAMS is the argument list for the call. The return value is non-null
10844 when expansion is complete, and null if normal processing should
10848 resolve_overloaded_builtin (location_t loc
, tree function
,
10849 vec
<tree
, va_gc
> *params
)
10851 enum built_in_function orig_code
= DECL_FUNCTION_CODE (function
);
10852 bool orig_format
= true;
10853 tree new_return
= NULL_TREE
;
10855 switch (DECL_BUILT_IN_CLASS (function
))
10857 case BUILT_IN_NORMAL
:
10860 if (targetm
.resolve_overloaded_builtin
)
10861 return targetm
.resolve_overloaded_builtin (loc
, function
, params
);
10868 /* Handle BUILT_IN_NORMAL here. */
10871 case BUILT_IN_ATOMIC_EXCHANGE
:
10872 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10873 case BUILT_IN_ATOMIC_LOAD
:
10874 case BUILT_IN_ATOMIC_STORE
:
10876 /* Handle these 4 together so that they can fall through to the next
10877 case if the call is transformed to an _N variant. */
10880 case BUILT_IN_ATOMIC_EXCHANGE
:
10882 if (resolve_overloaded_atomic_exchange (loc
, function
, params
,
10885 /* Change to the _N variant. */
10886 orig_code
= BUILT_IN_ATOMIC_EXCHANGE_N
;
10890 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10892 if (resolve_overloaded_atomic_compare_exchange (loc
, function
,
10896 /* Change to the _N variant. */
10897 orig_code
= BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
;
10900 case BUILT_IN_ATOMIC_LOAD
:
10902 if (resolve_overloaded_atomic_load (loc
, function
, params
,
10905 /* Change to the _N variant. */
10906 orig_code
= BUILT_IN_ATOMIC_LOAD_N
;
10909 case BUILT_IN_ATOMIC_STORE
:
10911 if (resolve_overloaded_atomic_store (loc
, function
, params
,
10914 /* Change to the _N variant. */
10915 orig_code
= BUILT_IN_ATOMIC_STORE_N
;
10919 gcc_unreachable ();
10921 /* Fallthrough to the normal processing. */
10923 case BUILT_IN_ATOMIC_EXCHANGE_N
:
10924 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
:
10925 case BUILT_IN_ATOMIC_LOAD_N
:
10926 case BUILT_IN_ATOMIC_STORE_N
:
10927 case BUILT_IN_ATOMIC_ADD_FETCH_N
:
10928 case BUILT_IN_ATOMIC_SUB_FETCH_N
:
10929 case BUILT_IN_ATOMIC_AND_FETCH_N
:
10930 case BUILT_IN_ATOMIC_NAND_FETCH_N
:
10931 case BUILT_IN_ATOMIC_XOR_FETCH_N
:
10932 case BUILT_IN_ATOMIC_OR_FETCH_N
:
10933 case BUILT_IN_ATOMIC_FETCH_ADD_N
:
10934 case BUILT_IN_ATOMIC_FETCH_SUB_N
:
10935 case BUILT_IN_ATOMIC_FETCH_AND_N
:
10936 case BUILT_IN_ATOMIC_FETCH_NAND_N
:
10937 case BUILT_IN_ATOMIC_FETCH_XOR_N
:
10938 case BUILT_IN_ATOMIC_FETCH_OR_N
:
10940 orig_format
= false;
10941 /* Fallthru for parameter processing. */
10943 case BUILT_IN_SYNC_FETCH_AND_ADD_N
:
10944 case BUILT_IN_SYNC_FETCH_AND_SUB_N
:
10945 case BUILT_IN_SYNC_FETCH_AND_OR_N
:
10946 case BUILT_IN_SYNC_FETCH_AND_AND_N
:
10947 case BUILT_IN_SYNC_FETCH_AND_XOR_N
:
10948 case BUILT_IN_SYNC_FETCH_AND_NAND_N
:
10949 case BUILT_IN_SYNC_ADD_AND_FETCH_N
:
10950 case BUILT_IN_SYNC_SUB_AND_FETCH_N
:
10951 case BUILT_IN_SYNC_OR_AND_FETCH_N
:
10952 case BUILT_IN_SYNC_AND_AND_FETCH_N
:
10953 case BUILT_IN_SYNC_XOR_AND_FETCH_N
:
10954 case BUILT_IN_SYNC_NAND_AND_FETCH_N
:
10955 case BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
:
10956 case BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N
:
10957 case BUILT_IN_SYNC_LOCK_TEST_AND_SET_N
:
10958 case BUILT_IN_SYNC_LOCK_RELEASE_N
:
10960 int n
= sync_resolve_size (function
, params
);
10961 tree new_function
, first_param
, result
;
10962 enum built_in_function fncode
;
10965 return error_mark_node
;
10967 fncode
= (enum built_in_function
)((int)orig_code
+ exact_log2 (n
) + 1);
10968 new_function
= builtin_decl_explicit (fncode
);
10969 if (!sync_resolve_params (loc
, function
, new_function
, params
,
10971 return error_mark_node
;
10973 first_param
= (*params
)[0];
10974 result
= build_function_call_vec (loc
, vNULL
, new_function
, params
,
10976 if (result
== error_mark_node
)
10978 if (orig_code
!= BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
10979 && orig_code
!= BUILT_IN_SYNC_LOCK_RELEASE_N
10980 && orig_code
!= BUILT_IN_ATOMIC_STORE_N
)
10981 result
= sync_resolve_return (first_param
, result
, orig_format
);
10983 /* If new_return is set, assign function to that expr and cast the
10984 result to void since the generic interface returned void. */
10987 /* Cast function result from I{1,2,4,8,16} to the required type. */
10988 result
= build1 (VIEW_CONVERT_EXPR
, TREE_TYPE (new_return
), result
);
10989 result
= build2 (MODIFY_EXPR
, TREE_TYPE (new_return
), new_return
,
10991 TREE_SIDE_EFFECTS (result
) = 1;
10992 protected_set_expr_location (result
, loc
);
10993 result
= convert (void_type_node
, result
);
11003 /* vector_types_compatible_elements_p is used in type checks of vectors
11004 values used as operands of binary operators. Where it returns true, and
11005 the other checks of the caller succeed (being vector types in he first
11006 place, and matching number of elements), we can just treat the types
11007 as essentially the same.
11008 Contrast with vector_targets_convertible_p, which is used for vector
11009 pointer types, and vector_types_convertible_p, which will allow
11010 language-specific matches under the control of flag_lax_vector_conversions,
11011 and might still require a conversion. */
11012 /* True if vector types T1 and T2 can be inputs to the same binary
11013 operator without conversion.
11014 We don't check the overall vector size here because some of our callers
11015 want to give different error messages when the vectors are compatible
11016 except for the element count. */
11019 vector_types_compatible_elements_p (tree t1
, tree t2
)
11021 bool opaque
= TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
);
11022 t1
= TREE_TYPE (t1
);
11023 t2
= TREE_TYPE (t2
);
11025 enum tree_code c1
= TREE_CODE (t1
), c2
= TREE_CODE (t2
);
11027 gcc_assert ((c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
|| c1
== FIXED_POINT_TYPE
)
11028 && (c2
== INTEGER_TYPE
|| c2
== REAL_TYPE
11029 || c2
== FIXED_POINT_TYPE
));
11031 t1
= c_common_signed_type (t1
);
11032 t2
= c_common_signed_type (t2
);
11033 /* Equality works here because c_common_signed_type uses
11034 TYPE_MAIN_VARIANT. */
11037 if (opaque
&& c1
== c2
11038 && (c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
)
11039 && TYPE_PRECISION (t1
) == TYPE_PRECISION (t2
))
11044 /* Check for missing format attributes on function pointers. LTYPE is
11045 the new type or left-hand side type. RTYPE is the old type or
11046 right-hand side type. Returns TRUE if LTYPE is missing the desired
11050 check_missing_format_attribute (tree ltype
, tree rtype
)
11052 tree
const ttr
= TREE_TYPE (rtype
), ttl
= TREE_TYPE (ltype
);
11055 for (ra
= TYPE_ATTRIBUTES (ttr
); ra
; ra
= TREE_CHAIN (ra
))
11056 if (is_attribute_p ("format", TREE_PURPOSE (ra
)))
11061 for (la
= TYPE_ATTRIBUTES (ttl
); la
; la
= TREE_CHAIN (la
))
11062 if (is_attribute_p ("format", TREE_PURPOSE (la
)))
11070 /* Subscripting with type char is likely to lose on a machine where
11071 chars are signed. So warn on any machine, but optionally. Don't
11072 warn for unsigned char since that type is safe. Don't warn for
11073 signed char because anyone who uses that must have done so
11074 deliberately. Furthermore, we reduce the false positive load by
11075 warning only for non-constant value of type char. */
11078 warn_array_subscript_with_type_char (tree index
)
11080 if (TYPE_MAIN_VARIANT (TREE_TYPE (index
)) == char_type_node
11081 && TREE_CODE (index
) != INTEGER_CST
)
11082 warning (OPT_Wchar_subscripts
, "array subscript has type %<char%>");
11085 /* Implement -Wparentheses for the unexpected C precedence rules, to
11086 cover cases like x + y << z which readers are likely to
11087 misinterpret. We have seen an expression in which CODE is a binary
11088 operator used to combine expressions ARG_LEFT and ARG_RIGHT, which
11089 before folding had CODE_LEFT and CODE_RIGHT. CODE_LEFT and
11090 CODE_RIGHT may be ERROR_MARK, which means that that side of the
11091 expression was not formed using a binary or unary operator, or it
11092 was enclosed in parentheses. */
11095 warn_about_parentheses (location_t loc
, enum tree_code code
,
11096 enum tree_code code_left
, tree arg_left
,
11097 enum tree_code code_right
, tree arg_right
)
11099 if (!warn_parentheses
)
11102 /* This macro tests that the expression ARG with original tree code
11103 CODE appears to be a boolean expression. or the result of folding a
11104 boolean expression. */
11105 #define APPEARS_TO_BE_BOOLEAN_EXPR_P(CODE, ARG) \
11106 (truth_value_p (TREE_CODE (ARG)) \
11107 || TREE_CODE (TREE_TYPE (ARG)) == BOOLEAN_TYPE \
11108 /* Folding may create 0 or 1 integers from other expressions. */ \
11109 || ((CODE) != INTEGER_CST \
11110 && (integer_onep (ARG) || integer_zerop (ARG))))
11115 if (code_left
== PLUS_EXPR
)
11116 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11117 "suggest parentheses around %<+%> inside %<<<%>");
11118 else if (code_right
== PLUS_EXPR
)
11119 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11120 "suggest parentheses around %<+%> inside %<<<%>");
11121 else if (code_left
== MINUS_EXPR
)
11122 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11123 "suggest parentheses around %<-%> inside %<<<%>");
11124 else if (code_right
== MINUS_EXPR
)
11125 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11126 "suggest parentheses around %<-%> inside %<<<%>");
11130 if (code_left
== PLUS_EXPR
)
11131 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11132 "suggest parentheses around %<+%> inside %<>>%>");
11133 else if (code_right
== PLUS_EXPR
)
11134 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11135 "suggest parentheses around %<+%> inside %<>>%>");
11136 else if (code_left
== MINUS_EXPR
)
11137 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11138 "suggest parentheses around %<-%> inside %<>>%>");
11139 else if (code_right
== MINUS_EXPR
)
11140 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11141 "suggest parentheses around %<-%> inside %<>>%>");
11144 case TRUTH_ORIF_EXPR
:
11145 if (code_left
== TRUTH_ANDIF_EXPR
)
11146 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11147 "suggest parentheses around %<&&%> within %<||%>");
11148 else if (code_right
== TRUTH_ANDIF_EXPR
)
11149 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11150 "suggest parentheses around %<&&%> within %<||%>");
11154 if (code_left
== BIT_AND_EXPR
|| code_left
== BIT_XOR_EXPR
11155 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
)
11156 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11157 "suggest parentheses around arithmetic in operand of %<|%>");
11158 else if (code_right
== BIT_AND_EXPR
|| code_right
== BIT_XOR_EXPR
11159 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
11160 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11161 "suggest parentheses around arithmetic in operand of %<|%>");
11162 /* Check cases like x|y==z */
11163 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11164 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11165 "suggest parentheses around comparison in operand of %<|%>");
11166 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11167 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11168 "suggest parentheses around comparison in operand of %<|%>");
11169 /* Check cases like !x | y */
11170 else if (code_left
== TRUTH_NOT_EXPR
11171 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
11172 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11173 "suggest parentheses around operand of "
11174 "%<!%> or change %<|%> to %<||%> or %<!%> to %<~%>");
11178 if (code_left
== BIT_AND_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
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 %<^%>");
11196 if (code_left
== PLUS_EXPR
)
11197 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11198 "suggest parentheses around %<+%> in operand of %<&%>");
11199 else if (code_right
== PLUS_EXPR
)
11200 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11201 "suggest parentheses around %<+%> in operand of %<&%>");
11202 else if (code_left
== MINUS_EXPR
)
11203 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11204 "suggest parentheses around %<-%> in operand of %<&%>");
11205 else if (code_right
== MINUS_EXPR
)
11206 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11207 "suggest parentheses around %<-%> in operand of %<&%>");
11208 /* Check cases like x&y==z */
11209 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11210 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11211 "suggest parentheses around comparison in operand of %<&%>");
11212 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11213 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11214 "suggest parentheses around comparison in operand of %<&%>");
11215 /* Check cases like !x & y */
11216 else if (code_left
== TRUTH_NOT_EXPR
11217 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
11218 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11219 "suggest parentheses around operand of "
11220 "%<!%> or change %<&%> to %<&&%> or %<!%> to %<~%>");
11224 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11225 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11226 "suggest parentheses around comparison in operand of %<==%>");
11227 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11228 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11229 "suggest parentheses around comparison in operand of %<==%>");
11232 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11233 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11234 "suggest parentheses around comparison in operand of %<!=%>");
11235 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11236 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11237 "suggest parentheses around comparison in operand of %<!=%>");
11241 if (TREE_CODE_CLASS (code
) == tcc_comparison
)
11243 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
11244 && code_left
!= NE_EXPR
&& code_left
!= EQ_EXPR
11245 && INTEGRAL_TYPE_P (TREE_TYPE (arg_left
)))
11246 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11247 "comparisons like %<X<=Y<=Z%> do not "
11248 "have their mathematical meaning");
11249 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
11250 && code_right
!= NE_EXPR
&& code_right
!= EQ_EXPR
11251 && INTEGRAL_TYPE_P (TREE_TYPE (arg_right
)))
11252 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11253 "comparisons like %<X<=Y<=Z%> do not "
11254 "have their mathematical meaning");
11258 #undef NOT_A_BOOLEAN_EXPR_P
11261 /* If LABEL (a LABEL_DECL) has not been used, issue a warning. */
11264 warn_for_unused_label (tree label
)
11266 if (!TREE_USED (label
))
11268 if (DECL_INITIAL (label
))
11269 warning (OPT_Wunused_label
, "label %q+D defined but not used", label
);
11271 warning (OPT_Wunused_label
, "label %q+D declared but not defined", label
);
11275 /* Warn for division by zero according to the value of DIVISOR. LOC
11276 is the location of the division operator. */
11279 warn_for_div_by_zero (location_t loc
, tree divisor
)
11281 /* If DIVISOR is zero, and has integral or fixed-point type, issue a warning
11282 about division by zero. Do not issue a warning if DIVISOR has a
11283 floating-point type, since we consider 0.0/0.0 a valid way of
11284 generating a NaN. */
11285 if (c_inhibit_evaluation_warnings
== 0
11286 && (integer_zerop (divisor
) || fixed_zerop (divisor
)))
11287 warning_at (loc
, OPT_Wdiv_by_zero
, "division by zero");
11290 /* Subroutine of build_binary_op. Give warnings for comparisons
11291 between signed and unsigned quantities that may fail. Do the
11292 checking based on the original operand trees ORIG_OP0 and ORIG_OP1,
11293 so that casts will be considered, but default promotions won't
11296 LOCATION is the location of the comparison operator.
11298 The arguments of this function map directly to local variables
11299 of build_binary_op. */
11302 warn_for_sign_compare (location_t location
,
11303 tree orig_op0
, tree orig_op1
,
11304 tree op0
, tree op1
,
11305 tree result_type
, enum tree_code resultcode
)
11307 int op0_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op0
));
11308 int op1_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op1
));
11309 int unsignedp0
, unsignedp1
;
11311 /* In C++, check for comparison of different enum types. */
11312 if (c_dialect_cxx()
11313 && TREE_CODE (TREE_TYPE (orig_op0
)) == ENUMERAL_TYPE
11314 && TREE_CODE (TREE_TYPE (orig_op1
)) == ENUMERAL_TYPE
11315 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0
))
11316 != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1
)))
11318 warning_at (location
,
11319 OPT_Wsign_compare
, "comparison between types %qT and %qT",
11320 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
));
11323 /* Do not warn if the comparison is being done in a signed type,
11324 since the signed type will only be chosen if it can represent
11325 all the values of the unsigned type. */
11326 if (!TYPE_UNSIGNED (result_type
))
11328 /* Do not warn if both operands are unsigned. */
11329 else if (op0_signed
== op1_signed
)
11333 tree sop
, uop
, base_type
;
11337 sop
= orig_op0
, uop
= orig_op1
;
11339 sop
= orig_op1
, uop
= orig_op0
;
11341 STRIP_TYPE_NOPS (sop
);
11342 STRIP_TYPE_NOPS (uop
);
11343 base_type
= (TREE_CODE (result_type
) == COMPLEX_TYPE
11344 ? TREE_TYPE (result_type
) : result_type
);
11346 /* Do not warn if the signed quantity is an unsuffixed integer
11347 literal (or some static constant expression involving such
11348 literals or a conditional expression involving such literals)
11349 and it is non-negative. */
11350 if (tree_expr_nonnegative_warnv_p (sop
, &ovf
))
11352 /* Do not warn if the comparison is an equality operation, the
11353 unsigned quantity is an integral constant, and it would fit
11354 in the result if the result were signed. */
11355 else if (TREE_CODE (uop
) == INTEGER_CST
11356 && (resultcode
== EQ_EXPR
|| resultcode
== NE_EXPR
)
11357 && int_fits_type_p (uop
, c_common_signed_type (base_type
)))
11359 /* In C, do not warn if the unsigned quantity is an enumeration
11360 constant and its maximum value would fit in the result if the
11361 result were signed. */
11362 else if (!c_dialect_cxx() && TREE_CODE (uop
) == INTEGER_CST
11363 && TREE_CODE (TREE_TYPE (uop
)) == ENUMERAL_TYPE
11364 && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (uop
)),
11365 c_common_signed_type (base_type
)))
11368 warning_at (location
,
11370 "comparison between signed and unsigned integer expressions");
11373 /* Warn if two unsigned values are being compared in a size larger
11374 than their original size, and one (and only one) is the result of
11375 a `~' operator. This comparison will always fail.
11377 Also warn if one operand is a constant, and the constant does not
11378 have all bits set that are set in the ~ operand when it is
11381 op0
= c_common_get_narrower (op0
, &unsignedp0
);
11382 op1
= c_common_get_narrower (op1
, &unsignedp1
);
11384 if ((TREE_CODE (op0
) == BIT_NOT_EXPR
)
11385 ^ (TREE_CODE (op1
) == BIT_NOT_EXPR
))
11387 if (TREE_CODE (op0
) == BIT_NOT_EXPR
)
11388 op0
= c_common_get_narrower (TREE_OPERAND (op0
, 0), &unsignedp0
);
11389 if (TREE_CODE (op1
) == BIT_NOT_EXPR
)
11390 op1
= c_common_get_narrower (TREE_OPERAND (op1
, 0), &unsignedp1
);
11392 if (tree_fits_shwi_p (op0
) || tree_fits_shwi_p (op1
))
11395 HOST_WIDE_INT constant
, mask
;
11399 if (tree_fits_shwi_p (op0
))
11402 unsignedp
= unsignedp1
;
11403 constant
= tree_to_shwi (op0
);
11408 unsignedp
= unsignedp0
;
11409 constant
= tree_to_shwi (op1
);
11412 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
11413 if (bits
< TYPE_PRECISION (result_type
)
11414 && bits
< HOST_BITS_PER_LONG
&& unsignedp
)
11416 mask
= (~ (HOST_WIDE_INT
) 0) << bits
;
11417 if ((mask
& constant
) != mask
)
11420 warning_at (location
, OPT_Wsign_compare
,
11421 "promoted ~unsigned is always non-zero");
11423 warning_at (location
, OPT_Wsign_compare
,
11424 "comparison of promoted ~unsigned with constant");
11428 else if (unsignedp0
&& unsignedp1
11429 && (TYPE_PRECISION (TREE_TYPE (op0
))
11430 < TYPE_PRECISION (result_type
))
11431 && (TYPE_PRECISION (TREE_TYPE (op1
))
11432 < TYPE_PRECISION (result_type
)))
11433 warning_at (location
, OPT_Wsign_compare
,
11434 "comparison of promoted ~unsigned with unsigned");
11438 /* RESULT_TYPE is the result of converting TYPE1 and TYPE2 to a common
11439 type via c_common_type. If -Wdouble-promotion is in use, and the
11440 conditions for warning have been met, issue a warning. GMSGID is
11441 the warning message. It must have two %T specifiers for the type
11442 that was converted (generally "float") and the type to which it was
11443 converted (generally "double), respectively. LOC is the location
11444 to which the awrning should refer. */
11447 do_warn_double_promotion (tree result_type
, tree type1
, tree type2
,
11448 const char *gmsgid
, location_t loc
)
11452 if (!warn_double_promotion
)
11454 /* If the conversion will not occur at run-time, there is no need to
11456 if (c_inhibit_evaluation_warnings
)
11458 if (TYPE_MAIN_VARIANT (result_type
) != double_type_node
11459 && TYPE_MAIN_VARIANT (result_type
) != complex_double_type_node
)
11461 if (TYPE_MAIN_VARIANT (type1
) == float_type_node
11462 || TYPE_MAIN_VARIANT (type1
) == complex_float_type_node
)
11463 source_type
= type1
;
11464 else if (TYPE_MAIN_VARIANT (type2
) == float_type_node
11465 || TYPE_MAIN_VARIANT (type2
) == complex_float_type_node
)
11466 source_type
= type2
;
11469 warning_at (loc
, OPT_Wdouble_promotion
, gmsgid
, source_type
, result_type
);
11472 /* Setup a TYPE_DECL node as a typedef representation.
11474 X is a TYPE_DECL for a typedef statement. Create a brand new
11475 ..._TYPE node (which will be just a variant of the existing
11476 ..._TYPE node with identical properties) and then install X
11477 as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
11479 The whole point here is to end up with a situation where each
11480 and every ..._TYPE node the compiler creates will be uniquely
11481 associated with AT MOST one node representing a typedef name.
11482 This way, even though the compiler substitutes corresponding
11483 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
11484 early on, later parts of the compiler can always do the reverse
11485 translation and get back the corresponding typedef name. For
11488 typedef struct S MY_TYPE;
11491 Later parts of the compiler might only know that `object' was of
11492 type `struct S' if it were not for code just below. With this
11493 code however, later parts of the compiler see something like:
11495 struct S' == struct S
11496 typedef struct S' MY_TYPE;
11499 And they can then deduce (from the node for type struct S') that
11500 the original object declaration was:
11504 Being able to do this is important for proper support of protoize,
11505 and also for generating precise symbolic debugging information
11506 which takes full account of the programmer's (typedef) vocabulary.
11508 Obviously, we don't want to generate a duplicate ..._TYPE node if
11509 the TYPE_DECL node that we are now processing really represents a
11510 standard built-in type. */
11513 set_underlying_type (tree x
)
11515 if (x
== error_mark_node
)
11517 if (DECL_IS_BUILTIN (x
))
11519 if (TYPE_NAME (TREE_TYPE (x
)) == 0)
11520 TYPE_NAME (TREE_TYPE (x
)) = x
;
11522 else if (TREE_TYPE (x
) != error_mark_node
11523 && DECL_ORIGINAL_TYPE (x
) == NULL_TREE
)
11525 tree tt
= TREE_TYPE (x
);
11526 DECL_ORIGINAL_TYPE (x
) = tt
;
11527 tt
= build_variant_type_copy (tt
);
11528 TYPE_STUB_DECL (tt
) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x
));
11529 TYPE_NAME (tt
) = x
;
11530 TREE_USED (tt
) = TREE_USED (x
);
11531 TREE_TYPE (x
) = tt
;
11535 /* Record the types used by the current global variable declaration
11536 being parsed, so that we can decide later to emit their debug info.
11537 Those types are in types_used_by_cur_var_decl, and we are going to
11538 store them in the types_used_by_vars_hash hash table.
11539 DECL is the declaration of the global variable that has been parsed. */
11542 record_types_used_by_current_var_decl (tree decl
)
11544 gcc_assert (decl
&& DECL_P (decl
) && TREE_STATIC (decl
));
11546 while (types_used_by_cur_var_decl
&& !types_used_by_cur_var_decl
->is_empty ())
11548 tree type
= types_used_by_cur_var_decl
->pop ();
11549 types_used_by_var_decl_insert (type
, decl
);
11553 /* If DECL is a typedef that is declared in the current function,
11554 record it for the purpose of -Wunused-local-typedefs. */
11557 record_locally_defined_typedef (tree decl
)
11559 struct c_language_function
*l
;
11561 if (!warn_unused_local_typedefs
11563 /* if this is not a locally defined typedef then we are not
11565 || !is_typedef_decl (decl
)
11566 || !decl_function_context (decl
))
11569 l
= (struct c_language_function
*) cfun
->language
;
11570 vec_safe_push (l
->local_typedefs
, decl
);
11573 /* If T is a TYPE_DECL declared locally, mark it as used. */
11576 maybe_record_typedef_use (tree t
)
11578 if (!is_typedef_decl (t
))
11581 TREE_USED (t
) = true;
11584 /* Warn if there are some unused locally defined typedefs in the
11585 current function. */
11588 maybe_warn_unused_local_typedefs (void)
11592 /* The number of times we have emitted -Wunused-local-typedefs
11593 warnings. If this is different from errorcount, that means some
11594 unrelated errors have been issued. In which case, we'll avoid
11595 emitting "unused-local-typedefs" warnings. */
11596 static int unused_local_typedefs_warn_count
;
11597 struct c_language_function
*l
;
11602 if ((l
= (struct c_language_function
*) cfun
->language
) == NULL
)
11605 if (warn_unused_local_typedefs
11606 && errorcount
== unused_local_typedefs_warn_count
)
11608 FOR_EACH_VEC_SAFE_ELT (l
->local_typedefs
, i
, decl
)
11609 if (!TREE_USED (decl
))
11610 warning_at (DECL_SOURCE_LOCATION (decl
),
11611 OPT_Wunused_local_typedefs
,
11612 "typedef %qD locally defined but not used", decl
);
11613 unused_local_typedefs_warn_count
= errorcount
;
11616 vec_free (l
->local_typedefs
);
11619 /* The C and C++ parsers both use vectors to hold function arguments.
11620 For efficiency, we keep a cache of unused vectors. This is the
11623 typedef vec
<tree
, va_gc
> *tree_gc_vec
;
11624 static GTY((deletable
)) vec
<tree_gc_vec
, va_gc
> *tree_vector_cache
;
11626 /* Return a new vector from the cache. If the cache is empty,
11627 allocate a new vector. These vectors are GC'ed, so it is OK if the
11628 pointer is not released.. */
11631 make_tree_vector (void)
11633 if (tree_vector_cache
&& !tree_vector_cache
->is_empty ())
11634 return tree_vector_cache
->pop ();
11637 /* Passing 0 to vec::alloc returns NULL, and our callers require
11638 that we always return a non-NULL value. The vector code uses
11639 4 when growing a NULL vector, so we do too. */
11640 vec
<tree
, va_gc
> *v
;
11646 /* Release a vector of trees back to the cache. */
11649 release_tree_vector (vec
<tree
, va_gc
> *vec
)
11654 vec_safe_push (tree_vector_cache
, vec
);
11658 /* Get a new tree vector holding a single tree. */
11661 make_tree_vector_single (tree t
)
11663 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
11664 ret
->quick_push (t
);
11668 /* Get a new tree vector of the TREE_VALUEs of a TREE_LIST chain. */
11671 make_tree_vector_from_list (tree list
)
11673 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
11674 for (; list
; list
= TREE_CHAIN (list
))
11675 vec_safe_push (ret
, TREE_VALUE (list
));
11679 /* Get a new tree vector which is a copy of an existing one. */
11682 make_tree_vector_copy (const vec
<tree
, va_gc
> *orig
)
11684 vec
<tree
, va_gc
> *ret
;
11688 ret
= make_tree_vector ();
11689 vec_safe_reserve (ret
, vec_safe_length (orig
));
11690 FOR_EACH_VEC_SAFE_ELT (orig
, ix
, t
)
11691 ret
->quick_push (t
);
11695 /* Return true if KEYWORD starts a type specifier. */
11698 keyword_begins_type_specifier (enum rid keyword
)
11702 case RID_AUTO_TYPE
:
11715 case RID_DFLOAT128
:
11735 /* Return true if KEYWORD names a type qualifier. */
11738 keyword_is_type_qualifier (enum rid keyword
)
11752 /* Return true if KEYWORD names a storage class specifier.
11754 RID_TYPEDEF is not included in this list despite `typedef' being
11755 listed in C99 6.7.1.1. 6.7.1.3 indicates that `typedef' is listed as
11756 such for syntactic convenience only. */
11759 keyword_is_storage_class_specifier (enum rid keyword
)
11775 /* Return true if KEYWORD names a function-specifier [dcl.fct.spec]. */
11778 keyword_is_function_specifier (enum rid keyword
)
11792 /* Return true if KEYWORD names a decl-specifier [dcl.spec] or a
11793 declaration-specifier (C99 6.7). */
11796 keyword_is_decl_specifier (enum rid keyword
)
11798 if (keyword_is_storage_class_specifier (keyword
)
11799 || keyword_is_type_qualifier (keyword
)
11800 || keyword_is_function_specifier (keyword
))
11807 case RID_CONSTEXPR
:
11814 /* Initialize language-specific-bits of tree_contains_struct. */
11817 c_common_init_ts (void)
11819 MARK_TS_TYPED (C_MAYBE_CONST_EXPR
);
11820 MARK_TS_TYPED (EXCESS_PRECISION_EXPR
);
11821 MARK_TS_TYPED (ARRAY_NOTATION_REF
);
11824 /* Build a user-defined numeric literal out of an integer constant type VALUE
11825 with identifier SUFFIX. */
11828 build_userdef_literal (tree suffix_id
, tree value
,
11829 enum overflow_type overflow
, tree num_string
)
11831 tree literal
= make_node (USERDEF_LITERAL
);
11832 USERDEF_LITERAL_SUFFIX_ID (literal
) = suffix_id
;
11833 USERDEF_LITERAL_VALUE (literal
) = value
;
11834 USERDEF_LITERAL_OVERFLOW (literal
) = overflow
;
11835 USERDEF_LITERAL_NUM_STRING (literal
) = num_string
;
11839 /* For vector[index], convert the vector to a
11840 pointer of the underlying type. */
11842 convert_vector_to_pointer_for_subscript (location_t loc
,
11843 tree
* vecp
, tree index
)
11845 if (TREE_CODE (TREE_TYPE (*vecp
)) == VECTOR_TYPE
)
11847 tree type
= TREE_TYPE (*vecp
);
11850 if (TREE_CODE (index
) == INTEGER_CST
)
11851 if (!tree_fits_uhwi_p (index
)
11852 || tree_to_uhwi (index
) >= TYPE_VECTOR_SUBPARTS (type
))
11853 warning_at (loc
, OPT_Warray_bounds
, "index value is out of bound");
11855 c_common_mark_addressable_vec (*vecp
);
11856 type
= build_qualified_type (TREE_TYPE (type
), TYPE_QUALS (type
));
11857 type1
= build_pointer_type (TREE_TYPE (*vecp
));
11858 bool ref_all
= TYPE_REF_CAN_ALIAS_ALL (type1
);
11860 && !DECL_P (*vecp
))
11862 /* If the original vector isn't declared may_alias and it
11863 isn't a bare vector look if the subscripting would
11864 alias the vector we subscript, and if not, force ref-all. */
11865 alias_set_type vecset
= get_alias_set (*vecp
);
11866 alias_set_type sset
= get_alias_set (type
);
11867 if (!alias_sets_must_conflict_p (sset
, vecset
)
11868 && !alias_set_subset_of (sset
, vecset
))
11871 type
= build_pointer_type_for_mode (type
, ptr_mode
, ref_all
);
11872 *vecp
= build1 (ADDR_EXPR
, type1
, *vecp
);
11873 *vecp
= convert (type
, *vecp
);
11877 /* Determine which of the operands, if any, is a scalar that needs to be
11878 converted to a vector, for the range of operations. */
11880 scalar_to_vector (location_t loc
, enum tree_code code
, tree op0
, tree op1
,
11883 tree type0
= TREE_TYPE (op0
);
11884 tree type1
= TREE_TYPE (op1
);
11885 bool integer_only_op
= false;
11886 enum stv_conv ret
= stv_firstarg
;
11888 gcc_assert (TREE_CODE (type0
) == VECTOR_TYPE
11889 || TREE_CODE (type1
) == VECTOR_TYPE
);
11892 /* Most GENERIC binary expressions require homogeneous arguments.
11893 LSHIFT_EXPR and RSHIFT_EXPR are exceptions and accept a first
11894 argument that is a vector and a second one that is a scalar, so
11895 we never return stv_secondarg for them. */
11898 if (TREE_CODE (type0
) == INTEGER_TYPE
11899 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
11901 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
11904 error_at (loc
, "conversion of scalar %qT to vector %qT "
11905 "involves truncation", type0
, type1
);
11909 return stv_firstarg
;
11916 integer_only_op
= true;
11917 /* ... fall through ... */
11919 case VEC_COND_EXPR
:
11924 case TRUNC_DIV_EXPR
:
11925 case CEIL_DIV_EXPR
:
11926 case FLOOR_DIV_EXPR
:
11927 case ROUND_DIV_EXPR
:
11928 case EXACT_DIV_EXPR
:
11929 case TRUNC_MOD_EXPR
:
11930 case FLOOR_MOD_EXPR
:
11938 /* What about UNLT_EXPR? */
11939 if (TREE_CODE (type0
) == VECTOR_TYPE
)
11942 ret
= stv_secondarg
;
11943 /* Swap TYPE0 with TYPE1 and OP0 with OP1 */
11944 tmp
= type0
; type0
= type1
; type1
= tmp
;
11945 tmp
= op0
; op0
= op1
; op1
= tmp
;
11948 if (TREE_CODE (type0
) == INTEGER_TYPE
11949 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
11951 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
11954 error_at (loc
, "conversion of scalar %qT to vector %qT "
11955 "involves truncation", type0
, type1
);
11960 else if (!integer_only_op
11961 /* Allow integer --> real conversion if safe. */
11962 && (TREE_CODE (type0
) == REAL_TYPE
11963 || TREE_CODE (type0
) == INTEGER_TYPE
)
11964 && SCALAR_FLOAT_TYPE_P (TREE_TYPE (type1
)))
11966 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
11969 error_at (loc
, "conversion of scalar %qT to vector %qT "
11970 "involves truncation", type0
, type1
);
11979 return stv_nothing
;
11982 /* Return true iff ALIGN is an integral constant that is a fundamental
11983 alignment, as defined by [basic.align] in the c++-11
11988 [A fundamental alignment is represented by an alignment less than or
11989 equal to the greatest alignment supported by the implementation
11990 in all contexts, which is equal to
11991 alignof(max_align_t)]. */
11994 cxx_fundamental_alignment_p (unsigned align
)
11996 return (align
<= MAX (TYPE_ALIGN (long_long_integer_type_node
),
11997 TYPE_ALIGN (long_double_type_node
)));
12000 /* Return true if T is a pointer to a zero-sized aggregate. */
12003 pointer_to_zero_sized_aggr_p (tree t
)
12005 if (!POINTER_TYPE_P (t
))
12008 return (TYPE_SIZE (t
) && integer_zerop (TYPE_SIZE (t
)));
12011 #include "gt-c-family-c-common.h"