1 /* Subroutines shared by all languages that are variants of C.
2 Copyright (C) 1992-2013 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"
53 cpp_reader
*parse_in
; /* Declared in c-pragma.h. */
55 /* The following symbols are subsumed in the c_global_trees array, and
56 listed here individually for documentation purposes.
58 INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
60 tree short_integer_type_node;
61 tree long_integer_type_node;
62 tree long_long_integer_type_node;
63 tree int128_integer_type_node;
65 tree short_unsigned_type_node;
66 tree long_unsigned_type_node;
67 tree long_long_unsigned_type_node;
68 tree int128_unsigned_type_node;
70 tree truthvalue_type_node;
71 tree truthvalue_false_node;
72 tree truthvalue_true_node;
74 tree ptrdiff_type_node;
76 tree unsigned_char_type_node;
77 tree signed_char_type_node;
80 tree char16_type_node;
81 tree char32_type_node;
84 tree double_type_node;
85 tree long_double_type_node;
87 tree complex_integer_type_node;
88 tree complex_float_type_node;
89 tree complex_double_type_node;
90 tree complex_long_double_type_node;
92 tree dfloat32_type_node;
93 tree dfloat64_type_node;
94 tree_dfloat128_type_node;
100 tree intTI_type_node;
102 tree unsigned_intQI_type_node;
103 tree unsigned_intHI_type_node;
104 tree unsigned_intSI_type_node;
105 tree unsigned_intDI_type_node;
106 tree unsigned_intTI_type_node;
108 tree widest_integer_literal_type_node;
109 tree widest_unsigned_literal_type_node;
111 Nodes for types `void *' and `const void *'.
113 tree ptr_type_node, const_ptr_type_node;
115 Nodes for types `char *' and `const char *'.
117 tree string_type_node, const_string_type_node;
119 Type `char[SOMENUMBER]'.
120 Used when an array of char is needed and the size is irrelevant.
122 tree char_array_type_node;
124 Type `wchar_t[SOMENUMBER]' or something like it.
125 Used when a wide string literal is created.
127 tree wchar_array_type_node;
129 Type `char16_t[SOMENUMBER]' or something like it.
130 Used when a UTF-16 string literal is created.
132 tree char16_array_type_node;
134 Type `char32_t[SOMENUMBER]' or something like it.
135 Used when a UTF-32 string literal is created.
137 tree char32_array_type_node;
139 Type `int ()' -- used for implicit declaration of functions.
141 tree default_function_type;
143 A VOID_TYPE node, packaged in a TREE_LIST.
147 The lazily created VAR_DECLs for __FUNCTION__, __PRETTY_FUNCTION__,
148 and __func__. (C doesn't generate __FUNCTION__ and__PRETTY_FUNCTION__
149 VAR_DECLS, but C++ does.)
151 tree function_name_decl_node;
152 tree pretty_function_name_decl_node;
153 tree c99_function_name_decl_node;
155 Stack of nested function name VAR_DECLs.
157 tree saved_function_name_decls;
161 tree c_global_trees
[CTI_MAX
];
163 /* Switches common to the C front ends. */
165 /* Nonzero means don't output line number information. */
167 char flag_no_line_commands
;
169 /* Nonzero causes -E output not to be done, but directives such as
170 #define that have side effects are still obeyed. */
174 /* Nonzero means dump macros in some fashion. */
176 char flag_dump_macros
;
178 /* Nonzero means pass #include lines through to the output. */
180 char flag_dump_includes
;
182 /* Nonzero means process PCH files while preprocessing. */
184 bool flag_pch_preprocess
;
186 /* The file name to which we should write a precompiled header, or
187 NULL if no header will be written in this compile. */
189 const char *pch_file
;
191 /* 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
;
234 /* UPC language option variables. */
236 /* Nonzero whenever UPC -fupc-threads-N is asserted.
237 The value N gives the number of UPC threads to be
238 defined at compile-time. */
239 int flag_upc_threads
;
241 /* Nonzero whenever UPC -fupc-pthreads-model-* is asserted. */
242 int flag_upc_pthreads
;
244 /* The implementation model for UPC threads that
245 are mapped to POSIX threads, specified at compilation
246 time by the -fupc-pthreads-model-* switch. */
247 upc_pthreads_model_kind upc_pthreads_model
;
249 /* C++ language option variables. */
252 /* Nonzero means generate separate instantiation control files and
253 juggle them at link time. */
255 int flag_use_repository
;
257 /* The C++ dialect being used. C++98 is the default. */
259 enum cxx_dialect cxx_dialect
= cxx98
;
261 /* Maximum template instantiation depth. This limit exists to limit the
262 time it takes to notice excessively recursive template instantiations.
264 The default is lower than the 1024 recommended by the C++0x standard
265 because G++ runs out of stack before 1024 with highly recursive template
266 argument deduction substitution (g++.dg/cpp0x/enum11.C). */
268 int max_tinst_depth
= 900;
270 /* The elements of `ridpointers' are identifier nodes for the reserved
271 type names and storage classes. It is indexed by a RID_... value. */
274 tree (*make_fname_decl
) (location_t
, tree
, int);
276 /* Nonzero means don't warn about problems that occur when the code is
278 int c_inhibit_evaluation_warnings
;
280 /* Whether we are building a boolean conversion inside
281 convert_for_assignment, or some other late binary operation. If
282 build_binary_op is called for C (from code shared by C and C++) in
283 this case, then the operands have already been folded and the
284 result will not be folded again, so C_MAYBE_CONST_EXPR should not
286 bool in_late_binary_op
;
288 /* Whether lexing has been completed, so subsequent preprocessor
289 errors should use the compiler's input_location. */
290 bool done_lexing
= false;
292 /* Information about how a function name is generated. */
295 tree
*const decl
; /* pointer to the VAR_DECL. */
296 const unsigned rid
; /* RID number for the identifier. */
297 const int pretty
; /* How pretty is it? */
300 /* The three ways of getting then name of the current function. */
302 const struct fname_var_t fname_vars
[] =
304 /* C99 compliant __func__, must be first. */
305 {&c99_function_name_decl_node
, RID_C99_FUNCTION_NAME
, 0},
306 /* GCC __FUNCTION__ compliant. */
307 {&function_name_decl_node
, RID_FUNCTION_NAME
, 0},
308 /* GCC __PRETTY_FUNCTION__ compliant. */
309 {&pretty_function_name_decl_node
, RID_PRETTY_FUNCTION_NAME
, 1},
313 /* Global visibility options. */
314 struct visibility_flags visibility_options
;
316 static tree
c_fully_fold_internal (tree expr
, bool, bool *, bool *);
317 static tree
check_case_value (tree
);
318 static bool check_case_bounds (tree
, tree
, tree
*, tree
*);
320 static tree
handle_packed_attribute (tree
*, tree
, tree
, int, bool *);
321 static tree
handle_nocommon_attribute (tree
*, tree
, tree
, int, bool *);
322 static tree
handle_common_attribute (tree
*, tree
, tree
, int, bool *);
323 static tree
handle_noreturn_attribute (tree
*, tree
, tree
, int, bool *);
324 static tree
handle_hot_attribute (tree
*, tree
, tree
, int, bool *);
325 static tree
handle_cold_attribute (tree
*, tree
, tree
, int, bool *);
326 static tree
handle_no_sanitize_address_attribute (tree
*, tree
, tree
,
328 static tree
handle_no_address_safety_analysis_attribute (tree
*, tree
, tree
,
330 static tree
handle_no_sanitize_undefined_attribute (tree
*, tree
, tree
, int,
332 static tree
handle_noinline_attribute (tree
*, tree
, tree
, int, bool *);
333 static tree
handle_noclone_attribute (tree
*, tree
, tree
, int, bool *);
334 static tree
handle_leaf_attribute (tree
*, tree
, tree
, int, bool *);
335 static tree
handle_always_inline_attribute (tree
*, tree
, tree
, int,
337 static tree
handle_gnu_inline_attribute (tree
*, tree
, tree
, int, bool *);
338 static tree
handle_artificial_attribute (tree
*, tree
, tree
, int, bool *);
339 static tree
handle_flatten_attribute (tree
*, tree
, tree
, int, bool *);
340 static tree
handle_error_attribute (tree
*, tree
, tree
, int, bool *);
341 static tree
handle_used_attribute (tree
*, tree
, tree
, int, bool *);
342 static tree
handle_unused_attribute (tree
*, tree
, tree
, int, bool *);
343 static tree
handle_externally_visible_attribute (tree
*, tree
, tree
, int,
345 static tree
handle_const_attribute (tree
*, tree
, tree
, int, bool *);
346 static tree
handle_transparent_union_attribute (tree
*, tree
, tree
,
348 static tree
handle_constructor_attribute (tree
*, tree
, tree
, int, bool *);
349 static tree
handle_destructor_attribute (tree
*, tree
, tree
, int, bool *);
350 static tree
handle_mode_attribute (tree
*, tree
, tree
, int, bool *);
351 static tree
handle_section_attribute (tree
*, tree
, tree
, int, bool *);
352 static tree
handle_aligned_attribute (tree
*, tree
, tree
, int, bool *);
353 static tree
handle_weak_attribute (tree
*, tree
, tree
, int, bool *) ;
354 static tree
handle_alias_ifunc_attribute (bool, tree
*, tree
, tree
, bool *);
355 static tree
handle_ifunc_attribute (tree
*, tree
, tree
, int, bool *);
356 static tree
handle_alias_attribute (tree
*, tree
, tree
, int, bool *);
357 static tree
handle_weakref_attribute (tree
*, tree
, tree
, int, bool *) ;
358 static tree
handle_visibility_attribute (tree
*, tree
, tree
, int,
360 static tree
handle_tls_model_attribute (tree
*, tree
, tree
, int,
362 static tree
handle_no_instrument_function_attribute (tree
*, tree
,
364 static tree
handle_malloc_attribute (tree
*, tree
, tree
, int, bool *);
365 static tree
handle_returns_twice_attribute (tree
*, tree
, tree
, int, bool *);
366 static tree
handle_no_limit_stack_attribute (tree
*, tree
, tree
, int,
368 static tree
handle_pure_attribute (tree
*, tree
, tree
, int, bool *);
369 static tree
handle_tm_attribute (tree
*, tree
, tree
, int, bool *);
370 static tree
handle_tm_wrap_attribute (tree
*, tree
, tree
, int, bool *);
371 static tree
handle_novops_attribute (tree
*, tree
, tree
, int, bool *);
372 static tree
handle_deprecated_attribute (tree
*, tree
, tree
, int,
374 static tree
handle_vector_size_attribute (tree
*, tree
, tree
, int,
376 static tree
handle_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
377 static tree
handle_nothrow_attribute (tree
*, tree
, tree
, int, bool *);
378 static tree
handle_cleanup_attribute (tree
*, tree
, tree
, int, bool *);
379 static tree
handle_warn_unused_result_attribute (tree
*, tree
, tree
, int,
381 static tree
handle_sentinel_attribute (tree
*, tree
, tree
, int, bool *);
382 static tree
handle_type_generic_attribute (tree
*, tree
, tree
, int, bool *);
383 static tree
handle_alloc_size_attribute (tree
*, tree
, tree
, int, bool *);
384 static tree
handle_target_attribute (tree
*, tree
, tree
, int, bool *);
385 static tree
handle_optimize_attribute (tree
*, tree
, tree
, int, bool *);
386 static tree
ignore_attribute (tree
*, tree
, tree
, int, bool *);
387 static tree
handle_no_split_stack_attribute (tree
*, tree
, tree
, int, bool *);
388 static tree
handle_fnspec_attribute (tree
*, tree
, tree
, int, bool *);
389 static tree
handle_warn_unused_attribute (tree
*, tree
, tree
, int, bool *);
390 static tree
handle_returns_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
391 static tree
handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int,
393 static tree
handle_omp_declare_target_attribute (tree
*, tree
, tree
, int,
396 static void check_function_nonnull (tree
, int, tree
*);
397 static void check_nonnull_arg (void *, tree
, unsigned HOST_WIDE_INT
);
398 static bool nonnull_check_p (tree
, unsigned HOST_WIDE_INT
);
399 static bool get_nonnull_operand (tree
, unsigned HOST_WIDE_INT
*);
400 static int resort_field_decl_cmp (const void *, const void *);
402 /* Reserved words. The third field is a mask: keywords are disabled
403 if they match the mask.
406 C --std=c89: D_C99 | D_CXXONLY | D_OBJC | D_CXX_OBJC
407 C --std=c99: D_CXXONLY | D_OBJC
408 ObjC is like C except that D_OBJC and D_CXX_OBJC are not set
409 UPC is like C except that D_UPC is not set
410 C++ --std=c98: D_CONLY | D_CXXOX | D_OBJC | D_UPC
411 C++ --std=c0x: D_CONLY | D_OBJC | D_UPC
412 ObjC++ is like C++ except that D_OBJC is not set
414 If -fno-asm is used, D_ASM is added to the mask. If
415 -fno-gnu-keywords is used, D_EXT is added. If -fno-asm and C in
416 C89 mode, D_EXT89 is added for both -fno-asm and -fno-gnu-keywords.
417 In C with -Wc++-compat, we warn if D_CXXWARN is set.
419 Note the complication of the D_CXX_OBJC keywords. These are
420 reserved words such as 'class'. In C++, 'class' is a reserved
421 word. In Objective-C++ it is too. In Objective-C, it is a
422 reserved word too, but only if it follows an '@' sign.
424 const struct c_common_resword c_common_reswords
[] =
426 { "_Alignas", RID_ALIGNAS
, D_CONLY
},
427 { "_Alignof", RID_ALIGNOF
, D_CONLY
},
428 { "_Atomic", RID_ATOMIC
, D_CONLY
},
429 { "_Bool", RID_BOOL
, D_CONLY
},
430 { "_Complex", RID_COMPLEX
, 0 },
431 { "_Cilk_spawn", RID_CILK_SPAWN
, 0 },
432 { "_Cilk_sync", RID_CILK_SYNC
, 0 },
433 { "_Imaginary", RID_IMAGINARY
, D_CONLY
},
434 { "_Decimal32", RID_DFLOAT32
, D_CONLY
| D_EXT
},
435 { "_Decimal64", RID_DFLOAT64
, D_CONLY
| D_EXT
},
436 { "_Decimal128", RID_DFLOAT128
, D_CONLY
| D_EXT
},
437 { "_Fract", RID_FRACT
, D_CONLY
| D_EXT
},
438 { "_Accum", RID_ACCUM
, D_CONLY
| D_EXT
},
439 { "_Sat", RID_SAT
, D_CONLY
| D_EXT
},
440 { "_Static_assert", RID_STATIC_ASSERT
, D_CONLY
},
441 { "_Noreturn", RID_NORETURN
, D_CONLY
},
442 { "_Generic", RID_GENERIC
, D_CONLY
},
443 { "_Thread_local", RID_THREAD
, D_CONLY
},
444 { "__FUNCTION__", RID_FUNCTION_NAME
, 0 },
445 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME
, 0 },
446 { "__alignof", RID_ALIGNOF
, 0 },
447 { "__alignof__", RID_ALIGNOF
, 0 },
448 { "__asm", RID_ASM
, 0 },
449 { "__asm__", RID_ASM
, 0 },
450 { "__attribute", RID_ATTRIBUTE
, 0 },
451 { "__attribute__", RID_ATTRIBUTE
, 0 },
452 { "__auto_type", RID_AUTO_TYPE
, D_CONLY
},
453 { "__bases", RID_BASES
, D_CXXONLY
},
454 { "__builtin_choose_expr", RID_CHOOSE_EXPR
, D_CONLY
},
455 { "__builtin_complex", RID_BUILTIN_COMPLEX
, D_CONLY
},
456 { "__builtin_shuffle", RID_BUILTIN_SHUFFLE
, 0 },
457 { "__builtin_offsetof", RID_OFFSETOF
, 0 },
458 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P
, D_CONLY
},
459 { "__builtin_va_arg", RID_VA_ARG
, 0 },
460 { "__complex", RID_COMPLEX
, 0 },
461 { "__complex__", RID_COMPLEX
, 0 },
462 { "__const", RID_CONST
, 0 },
463 { "__const__", RID_CONST
, 0 },
464 { "__decltype", RID_DECLTYPE
, D_CXXONLY
},
465 { "__direct_bases", RID_DIRECT_BASES
, D_CXXONLY
},
466 { "__extension__", RID_EXTENSION
, 0 },
467 { "__func__", RID_C99_FUNCTION_NAME
, 0 },
468 { "__has_nothrow_assign", RID_HAS_NOTHROW_ASSIGN
, D_CXXONLY
},
469 { "__has_nothrow_constructor", RID_HAS_NOTHROW_CONSTRUCTOR
, D_CXXONLY
},
470 { "__has_nothrow_copy", RID_HAS_NOTHROW_COPY
, D_CXXONLY
},
471 { "__has_trivial_assign", RID_HAS_TRIVIAL_ASSIGN
, D_CXXONLY
},
472 { "__has_trivial_constructor", RID_HAS_TRIVIAL_CONSTRUCTOR
, D_CXXONLY
},
473 { "__has_trivial_copy", RID_HAS_TRIVIAL_COPY
, D_CXXONLY
},
474 { "__has_trivial_destructor", RID_HAS_TRIVIAL_DESTRUCTOR
, D_CXXONLY
},
475 { "__has_virtual_destructor", RID_HAS_VIRTUAL_DESTRUCTOR
, D_CXXONLY
},
476 { "__imag", RID_IMAGPART
, 0 },
477 { "__imag__", RID_IMAGPART
, 0 },
478 { "__inline", RID_INLINE
, 0 },
479 { "__inline__", RID_INLINE
, 0 },
480 { "__int128", RID_INT128
, 0 },
481 { "__is_abstract", RID_IS_ABSTRACT
, D_CXXONLY
},
482 { "__is_base_of", RID_IS_BASE_OF
, D_CXXONLY
},
483 { "__is_class", RID_IS_CLASS
, D_CXXONLY
},
484 { "__is_convertible_to", RID_IS_CONVERTIBLE_TO
, D_CXXONLY
},
485 { "__is_empty", RID_IS_EMPTY
, D_CXXONLY
},
486 { "__is_enum", RID_IS_ENUM
, D_CXXONLY
},
487 { "__is_final", RID_IS_FINAL
, D_CXXONLY
},
488 { "__is_literal_type", RID_IS_LITERAL_TYPE
, D_CXXONLY
},
489 { "__is_pod", RID_IS_POD
, D_CXXONLY
},
490 { "__is_polymorphic", RID_IS_POLYMORPHIC
, D_CXXONLY
},
491 { "__is_standard_layout", RID_IS_STD_LAYOUT
, D_CXXONLY
},
492 { "__is_trivial", RID_IS_TRIVIAL
, D_CXXONLY
},
493 { "__is_union", RID_IS_UNION
, D_CXXONLY
},
494 { "__label__", RID_LABEL
, 0 },
495 { "__null", RID_NULL
, 0 },
496 { "__real", RID_REALPART
, 0 },
497 { "__real__", RID_REALPART
, 0 },
498 { "__restrict", RID_RESTRICT
, 0 },
499 { "__restrict__", RID_RESTRICT
, 0 },
500 { "__signed", RID_SIGNED
, 0 },
501 { "__signed__", RID_SIGNED
, 0 },
502 { "__thread", RID_THREAD
, 0 },
503 { "__transaction_atomic", RID_TRANSACTION_ATOMIC
, 0 },
504 { "__transaction_relaxed", RID_TRANSACTION_RELAXED
, 0 },
505 { "__transaction_cancel", RID_TRANSACTION_CANCEL
, 0 },
506 { "__typeof", RID_TYPEOF
, 0 },
507 { "__typeof__", RID_TYPEOF
, 0 },
508 { "__underlying_type", RID_UNDERLYING_TYPE
, D_CXXONLY
},
509 { "__volatile", RID_VOLATILE
, 0 },
510 { "__volatile__", RID_VOLATILE
, 0 },
511 { "alignas", RID_ALIGNAS
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
512 { "alignof", RID_ALIGNOF
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
513 { "asm", RID_ASM
, D_ASM
},
514 { "auto", RID_AUTO
, 0 },
515 { "bool", RID_BOOL
, D_CXXONLY
| D_CXXWARN
},
516 { "break", RID_BREAK
, 0 },
517 { "case", RID_CASE
, 0 },
518 { "catch", RID_CATCH
, D_CXX_OBJC
| D_CXXWARN
},
519 { "char", RID_CHAR
, 0 },
520 { "char16_t", RID_CHAR16
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
521 { "char32_t", RID_CHAR32
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
522 { "class", RID_CLASS
, D_CXX_OBJC
| D_CXXWARN
},
523 { "const", RID_CONST
, 0 },
524 { "constexpr", RID_CONSTEXPR
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
525 { "const_cast", RID_CONSTCAST
, D_CXXONLY
| D_CXXWARN
},
526 { "continue", RID_CONTINUE
, 0 },
527 { "decltype", RID_DECLTYPE
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
528 { "default", RID_DEFAULT
, 0 },
529 { "delete", RID_DELETE
, D_CXXONLY
| D_CXXWARN
},
531 { "double", RID_DOUBLE
, 0 },
532 { "dynamic_cast", RID_DYNCAST
, D_CXXONLY
| D_CXXWARN
},
533 { "else", RID_ELSE
, 0 },
534 { "enum", RID_ENUM
, 0 },
535 { "explicit", RID_EXPLICIT
, D_CXXONLY
| D_CXXWARN
},
536 { "export", RID_EXPORT
, D_CXXONLY
| D_CXXWARN
},
537 { "extern", RID_EXTERN
, 0 },
538 { "false", RID_FALSE
, D_CXXONLY
| D_CXXWARN
},
539 { "float", RID_FLOAT
, 0 },
540 { "for", RID_FOR
, 0 },
541 { "friend", RID_FRIEND
, D_CXXONLY
| D_CXXWARN
},
542 { "goto", RID_GOTO
, 0 },
544 { "inline", RID_INLINE
, D_EXT89
},
545 { "int", RID_INT
, 0 },
546 { "long", RID_LONG
, 0 },
547 { "mutable", RID_MUTABLE
, D_CXXONLY
| D_CXXWARN
},
548 { "namespace", RID_NAMESPACE
, D_CXXONLY
| D_CXXWARN
},
549 { "new", RID_NEW
, D_CXXONLY
| D_CXXWARN
},
550 { "noexcept", RID_NOEXCEPT
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
551 { "nullptr", RID_NULLPTR
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
552 { "operator", RID_OPERATOR
, D_CXXONLY
| D_CXXWARN
},
553 { "private", RID_PRIVATE
, D_CXX_OBJC
| D_CXXWARN
},
554 { "protected", RID_PROTECTED
, D_CXX_OBJC
| D_CXXWARN
},
555 { "public", RID_PUBLIC
, D_CXX_OBJC
| D_CXXWARN
},
556 { "register", RID_REGISTER
, 0 },
557 { "reinterpret_cast", RID_REINTCAST
, D_CXXONLY
| D_CXXWARN
},
558 { "restrict", RID_RESTRICT
, D_CONLY
| D_C99
},
559 { "return", RID_RETURN
, 0 },
560 { "short", RID_SHORT
, 0 },
561 { "signed", RID_SIGNED
, 0 },
562 { "sizeof", RID_SIZEOF
, 0 },
563 { "static", RID_STATIC
, 0 },
564 { "static_assert", RID_STATIC_ASSERT
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
565 { "static_cast", RID_STATCAST
, D_CXXONLY
| D_CXXWARN
},
566 { "struct", RID_STRUCT
, 0 },
567 { "switch", RID_SWITCH
, 0 },
568 { "template", RID_TEMPLATE
, D_CXXONLY
| D_CXXWARN
},
569 { "this", RID_THIS
, D_CXXONLY
| D_CXXWARN
},
570 { "thread_local", RID_THREAD
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
571 { "throw", RID_THROW
, D_CXX_OBJC
| D_CXXWARN
},
572 { "true", RID_TRUE
, D_CXXONLY
| D_CXXWARN
},
573 { "try", RID_TRY
, D_CXX_OBJC
| D_CXXWARN
},
574 { "typedef", RID_TYPEDEF
, 0 },
575 { "typename", RID_TYPENAME
, D_CXXONLY
| D_CXXWARN
},
576 { "typeid", RID_TYPEID
, D_CXXONLY
| D_CXXWARN
},
577 { "typeof", RID_TYPEOF
, D_ASM
| D_EXT
},
578 { "union", RID_UNION
, 0 },
579 { "unsigned", RID_UNSIGNED
, 0 },
580 { "using", RID_USING
, D_CXXONLY
| D_CXXWARN
},
581 { "virtual", RID_VIRTUAL
, D_CXXONLY
| D_CXXWARN
},
582 { "void", RID_VOID
, 0 },
583 { "volatile", RID_VOLATILE
, 0 },
584 { "wchar_t", RID_WCHAR
, D_CXXONLY
},
585 { "while", RID_WHILE
, 0 },
586 /* These Objective-C keywords are recognized only immediately after
588 { "compatibility_alias", RID_AT_ALIAS
, D_OBJC
},
589 { "defs", RID_AT_DEFS
, D_OBJC
},
590 { "encode", RID_AT_ENCODE
, D_OBJC
},
591 { "end", RID_AT_END
, D_OBJC
},
592 { "implementation", RID_AT_IMPLEMENTATION
, D_OBJC
},
593 { "interface", RID_AT_INTERFACE
, D_OBJC
},
594 { "protocol", RID_AT_PROTOCOL
, D_OBJC
},
595 { "selector", RID_AT_SELECTOR
, D_OBJC
},
596 { "finally", RID_AT_FINALLY
, D_OBJC
},
597 { "synchronized", RID_AT_SYNCHRONIZED
, D_OBJC
},
598 { "optional", RID_AT_OPTIONAL
, D_OBJC
},
599 { "required", RID_AT_REQUIRED
, D_OBJC
},
600 { "property", RID_AT_PROPERTY
, D_OBJC
},
601 { "package", RID_AT_PACKAGE
, D_OBJC
},
602 { "synthesize", RID_AT_SYNTHESIZE
, D_OBJC
},
603 { "dynamic", RID_AT_DYNAMIC
, D_OBJC
},
604 /* These are recognized only in protocol-qualifier context
606 { "bycopy", RID_BYCOPY
, D_OBJC
},
607 { "byref", RID_BYREF
, D_OBJC
},
608 { "in", RID_IN
, D_OBJC
},
609 { "inout", RID_INOUT
, D_OBJC
},
610 { "oneway", RID_ONEWAY
, D_OBJC
},
611 { "out", RID_OUT
, D_OBJC
},
614 { "shared", RID_SHARED
, D_UPC
},
615 { "relaxed", RID_RELAXED
, D_UPC
},
616 { "strict", RID_STRICT
, D_UPC
},
617 { "upc_barrier", RID_UPC_BARRIER
, D_UPC
},
618 { "upc_blocksizeof", RID_UPC_BLOCKSIZEOF
, D_UPC
},
619 { "upc_elemsizeof", RID_UPC_ELEMSIZEOF
, D_UPC
},
620 { "upc_forall", RID_UPC_FORALL
, D_UPC
},
621 { "upc_localsizeof", RID_UPC_LOCALSIZEOF
, D_UPC
},
622 { "upc_notify", RID_UPC_NOTIFY
, D_UPC
},
623 { "upc_wait", RID_UPC_WAIT
, D_UPC
},
625 /* These are recognized inside a property attribute list */
626 { "assign", RID_ASSIGN
, D_OBJC
},
627 { "copy", RID_COPY
, D_OBJC
},
628 { "getter", RID_GETTER
, D_OBJC
},
629 { "nonatomic", RID_NONATOMIC
, D_OBJC
},
630 { "readonly", RID_READONLY
, D_OBJC
},
631 { "readwrite", RID_READWRITE
, D_OBJC
},
632 { "retain", RID_RETAIN
, D_OBJC
},
633 { "setter", RID_SETTER
, D_OBJC
},
636 const unsigned int num_c_common_reswords
=
637 sizeof c_common_reswords
/ sizeof (struct c_common_resword
);
639 /* Table of machine-independent attributes common to all C-like languages. */
640 const struct attribute_spec c_common_attribute_table
[] =
642 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
643 affects_type_identity } */
644 { "packed", 0, 0, false, false, false,
645 handle_packed_attribute
, false},
646 { "nocommon", 0, 0, true, false, false,
647 handle_nocommon_attribute
, false},
648 { "common", 0, 0, true, false, false,
649 handle_common_attribute
, false },
650 /* FIXME: logically, noreturn attributes should be listed as
651 "false, true, true" and apply to function types. But implementing this
652 would require all the places in the compiler that use TREE_THIS_VOLATILE
653 on a decl to identify non-returning functions to be located and fixed
654 to check the function type instead. */
655 { "noreturn", 0, 0, true, false, false,
656 handle_noreturn_attribute
, false },
657 { "volatile", 0, 0, true, false, false,
658 handle_noreturn_attribute
, false },
659 { "noinline", 0, 0, true, false, false,
660 handle_noinline_attribute
, false },
661 { "noclone", 0, 0, true, false, false,
662 handle_noclone_attribute
, false },
663 { "leaf", 0, 0, true, false, false,
664 handle_leaf_attribute
, false },
665 { "always_inline", 0, 0, true, false, false,
666 handle_always_inline_attribute
, false },
667 { "gnu_inline", 0, 0, true, false, false,
668 handle_gnu_inline_attribute
, false },
669 { "artificial", 0, 0, true, false, false,
670 handle_artificial_attribute
, false },
671 { "flatten", 0, 0, true, false, false,
672 handle_flatten_attribute
, false },
673 { "used", 0, 0, true, false, false,
674 handle_used_attribute
, false },
675 { "unused", 0, 0, false, false, false,
676 handle_unused_attribute
, false },
677 { "externally_visible", 0, 0, true, false, false,
678 handle_externally_visible_attribute
, false },
679 /* The same comments as for noreturn attributes apply to const ones. */
680 { "const", 0, 0, true, false, false,
681 handle_const_attribute
, false },
682 { "transparent_union", 0, 0, false, false, false,
683 handle_transparent_union_attribute
, false },
684 { "constructor", 0, 1, true, false, false,
685 handle_constructor_attribute
, false },
686 { "destructor", 0, 1, true, false, false,
687 handle_destructor_attribute
, false },
688 { "mode", 1, 1, false, true, false,
689 handle_mode_attribute
, false },
690 { "section", 1, 1, true, false, false,
691 handle_section_attribute
, false },
692 { "aligned", 0, 1, false, false, false,
693 handle_aligned_attribute
, false },
694 { "weak", 0, 0, true, false, false,
695 handle_weak_attribute
, false },
696 { "ifunc", 1, 1, true, false, false,
697 handle_ifunc_attribute
, false },
698 { "alias", 1, 1, true, false, false,
699 handle_alias_attribute
, false },
700 { "weakref", 0, 1, true, false, false,
701 handle_weakref_attribute
, false },
702 { "no_instrument_function", 0, 0, true, false, false,
703 handle_no_instrument_function_attribute
,
705 { "malloc", 0, 0, true, false, false,
706 handle_malloc_attribute
, false },
707 { "returns_twice", 0, 0, true, false, false,
708 handle_returns_twice_attribute
, false },
709 { "no_stack_limit", 0, 0, true, false, false,
710 handle_no_limit_stack_attribute
, false },
711 { "pure", 0, 0, true, false, false,
712 handle_pure_attribute
, false },
713 { "transaction_callable", 0, 0, false, true, false,
714 handle_tm_attribute
, false },
715 { "transaction_unsafe", 0, 0, false, true, false,
716 handle_tm_attribute
, false },
717 { "transaction_safe", 0, 0, false, true, false,
718 handle_tm_attribute
, false },
719 { "transaction_may_cancel_outer", 0, 0, false, true, false,
720 handle_tm_attribute
, false },
721 /* ??? These two attributes didn't make the transition from the
722 Intel language document to the multi-vendor language document. */
723 { "transaction_pure", 0, 0, false, true, false,
724 handle_tm_attribute
, false },
725 { "transaction_wrap", 1, 1, true, false, false,
726 handle_tm_wrap_attribute
, false },
727 /* For internal use (marking of builtins) only. The name contains space
728 to prevent its usage in source code. */
729 { "no vops", 0, 0, true, false, false,
730 handle_novops_attribute
, false },
731 { "deprecated", 0, 1, false, false, false,
732 handle_deprecated_attribute
, false },
733 { "vector_size", 1, 1, false, true, false,
734 handle_vector_size_attribute
, false },
735 { "visibility", 1, 1, false, false, false,
736 handle_visibility_attribute
, false },
737 { "tls_model", 1, 1, true, false, false,
738 handle_tls_model_attribute
, false },
739 { "nonnull", 0, -1, false, true, true,
740 handle_nonnull_attribute
, false },
741 { "nothrow", 0, 0, true, false, false,
742 handle_nothrow_attribute
, false },
743 { "may_alias", 0, 0, false, true, false, NULL
, false },
744 { "cleanup", 1, 1, true, false, false,
745 handle_cleanup_attribute
, false },
746 { "warn_unused_result", 0, 0, false, true, true,
747 handle_warn_unused_result_attribute
, false },
748 { "sentinel", 0, 1, false, true, true,
749 handle_sentinel_attribute
, false },
750 /* For internal use (marking of builtins) only. The name contains space
751 to prevent its usage in source code. */
752 { "type generic", 0, 0, false, true, true,
753 handle_type_generic_attribute
, false },
754 { "alloc_size", 1, 2, false, true, true,
755 handle_alloc_size_attribute
, false },
756 { "cold", 0, 0, true, false, false,
757 handle_cold_attribute
, false },
758 { "hot", 0, 0, true, false, false,
759 handle_hot_attribute
, false },
760 { "no_address_safety_analysis",
761 0, 0, true, false, false,
762 handle_no_address_safety_analysis_attribute
,
764 { "no_sanitize_address", 0, 0, true, false, false,
765 handle_no_sanitize_address_attribute
,
767 { "no_sanitize_undefined", 0, 0, true, false, false,
768 handle_no_sanitize_undefined_attribute
,
770 { "warning", 1, 1, true, false, false,
771 handle_error_attribute
, false },
772 { "error", 1, 1, true, false, false,
773 handle_error_attribute
, false },
774 { "target", 1, -1, true, false, false,
775 handle_target_attribute
, false },
776 { "optimize", 1, -1, true, false, false,
777 handle_optimize_attribute
, false },
778 /* For internal use only. The leading '*' both prevents its usage in
779 source code and signals that it may be overridden by machine tables. */
780 { "*tm regparm", 0, 0, false, true, true,
781 ignore_attribute
, false },
782 { "no_split_stack", 0, 0, true, false, false,
783 handle_no_split_stack_attribute
, false },
784 /* For internal use (marking of builtins and runtime functions) only.
785 The name contains space to prevent its usage in source code. */
786 { "fn spec", 1, 1, false, true, true,
787 handle_fnspec_attribute
, false },
788 { "warn_unused", 0, 0, false, false, false,
789 handle_warn_unused_attribute
, false },
790 { "returns_nonnull", 0, 0, false, true, true,
791 handle_returns_nonnull_attribute
, false },
792 { "omp declare simd", 0, -1, true, false, false,
793 handle_omp_declare_simd_attribute
, false },
794 { "cilk simd function", 0, -1, true, false, false,
795 handle_omp_declare_simd_attribute
, false },
796 { "omp declare target", 0, 0, true, false, false,
797 handle_omp_declare_target_attribute
, false },
798 { NULL
, 0, 0, false, false, false, NULL
, false }
801 /* Give the specifications for the format attributes, used by C and all
804 const struct attribute_spec c_common_format_attribute_table
[] =
806 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
807 affects_type_identity } */
808 { "format", 3, 3, false, true, true,
809 handle_format_attribute
, false },
810 { "format_arg", 1, 1, false, true, true,
811 handle_format_arg_attribute
, false },
812 { NULL
, 0, 0, false, false, false, NULL
, false }
815 /* Return identifier for address space AS. */
818 c_addr_space_name (addr_space_t as
)
820 int rid
= RID_FIRST_ADDR_SPACE
+ as
;
821 gcc_assert (ridpointers
[rid
]);
822 return IDENTIFIER_POINTER (ridpointers
[rid
]);
825 /* Push current bindings for the function name VAR_DECLS. */
828 start_fname_decls (void)
831 tree saved
= NULL_TREE
;
833 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
835 tree decl
= *fname_vars
[ix
].decl
;
839 saved
= tree_cons (decl
, build_int_cst (integer_type_node
, ix
),
841 *fname_vars
[ix
].decl
= NULL_TREE
;
844 if (saved
|| saved_function_name_decls
)
845 /* Normally they'll have been NULL, so only push if we've got a
846 stack, or they are non-NULL. */
847 saved_function_name_decls
= tree_cons (saved
, NULL_TREE
,
848 saved_function_name_decls
);
851 /* Finish up the current bindings, adding them into the current function's
852 statement tree. This must be done _before_ finish_stmt_tree is called.
853 If there is no current function, we must be at file scope and no statements
854 are involved. Pop the previous bindings. */
857 finish_fname_decls (void)
860 tree stmts
= NULL_TREE
;
861 tree stack
= saved_function_name_decls
;
863 for (; stack
&& TREE_VALUE (stack
); stack
= TREE_CHAIN (stack
))
864 append_to_statement_list (TREE_VALUE (stack
), &stmts
);
868 tree
*bodyp
= &DECL_SAVED_TREE (current_function_decl
);
870 if (TREE_CODE (*bodyp
) == BIND_EXPR
)
871 bodyp
= &BIND_EXPR_BODY (*bodyp
);
873 append_to_statement_list_force (*bodyp
, &stmts
);
877 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
878 *fname_vars
[ix
].decl
= NULL_TREE
;
882 /* We had saved values, restore them. */
885 for (saved
= TREE_PURPOSE (stack
); saved
; saved
= TREE_CHAIN (saved
))
887 tree decl
= TREE_PURPOSE (saved
);
888 unsigned ix
= TREE_INT_CST_LOW (TREE_VALUE (saved
));
890 *fname_vars
[ix
].decl
= decl
;
892 stack
= TREE_CHAIN (stack
);
894 saved_function_name_decls
= stack
;
897 /* Return the text name of the current function, suitably prettified
898 by PRETTY_P. Return string must be freed by caller. */
901 fname_as_string (int pretty_p
)
903 const char *name
= "top level";
906 cpp_string cstr
= { 0, 0 }, strname
;
914 if (current_function_decl
)
915 name
= lang_hooks
.decl_printable_name (current_function_decl
, vrb
);
917 len
= strlen (name
) + 3; /* Two for '"'s. One for NULL. */
919 namep
= XNEWVEC (char, len
);
920 snprintf (namep
, len
, "\"%s\"", name
);
921 strname
.text
= (unsigned char *) namep
;
922 strname
.len
= len
- 1;
924 if (cpp_interpret_string (parse_in
, &strname
, 1, &cstr
, CPP_STRING
))
927 return (const char *) cstr
.text
;
933 /* Return the VAR_DECL for a const char array naming the current
934 function. If the VAR_DECL has not yet been created, create it
935 now. RID indicates how it should be formatted and IDENTIFIER_NODE
936 ID is its name (unfortunately C and C++ hold the RID values of
937 keywords in different places, so we can't derive RID from ID in
938 this language independent code. LOC is the location of the
942 fname_decl (location_t loc
, unsigned int rid
, tree id
)
945 tree decl
= NULL_TREE
;
947 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
948 if (fname_vars
[ix
].rid
== rid
)
951 decl
= *fname_vars
[ix
].decl
;
954 /* If a tree is built here, it would normally have the lineno of
955 the current statement. Later this tree will be moved to the
956 beginning of the function and this line number will be wrong.
957 To avoid this problem set the lineno to 0 here; that prevents
958 it from appearing in the RTL. */
960 location_t saved_location
= input_location
;
961 input_location
= UNKNOWN_LOCATION
;
963 stmts
= push_stmt_list ();
964 decl
= (*make_fname_decl
) (loc
, id
, fname_vars
[ix
].pretty
);
965 stmts
= pop_stmt_list (stmts
);
966 if (!IS_EMPTY_STMT (stmts
))
967 saved_function_name_decls
968 = tree_cons (decl
, stmts
, saved_function_name_decls
);
969 *fname_vars
[ix
].decl
= decl
;
970 input_location
= saved_location
;
972 if (!ix
&& !current_function_decl
)
973 pedwarn (loc
, 0, "%qD is not defined outside of function scope", decl
);
978 /* Given a STRING_CST, give it a suitable array-of-chars data type. */
981 fix_string_type (tree value
)
983 int length
= TREE_STRING_LENGTH (value
);
985 tree e_type
, i_type
, a_type
;
987 /* Compute the number of elements, for the array type. */
988 if (TREE_TYPE (value
) == char_array_type_node
|| !TREE_TYPE (value
))
991 e_type
= char_type_node
;
993 else if (TREE_TYPE (value
) == char16_array_type_node
)
995 nchars
= length
/ (TYPE_PRECISION (char16_type_node
) / BITS_PER_UNIT
);
996 e_type
= char16_type_node
;
998 else if (TREE_TYPE (value
) == char32_array_type_node
)
1000 nchars
= length
/ (TYPE_PRECISION (char32_type_node
) / BITS_PER_UNIT
);
1001 e_type
= char32_type_node
;
1005 nchars
= length
/ (TYPE_PRECISION (wchar_type_node
) / BITS_PER_UNIT
);
1006 e_type
= wchar_type_node
;
1009 /* C89 2.2.4.1, C99 5.2.4.1 (Translation limits). The analogous
1010 limit in C++98 Annex B is very large (65536) and is not normative,
1011 so we do not diagnose it (warn_overlength_strings is forced off
1012 in c_common_post_options). */
1013 if (warn_overlength_strings
)
1015 const int nchars_max
= flag_isoc99
? 4095 : 509;
1016 const int relevant_std
= flag_isoc99
? 99 : 90;
1017 if (nchars
- 1 > nchars_max
)
1018 /* Translators: The %d after 'ISO C' will be 90 or 99. Do not
1019 separate the %d from the 'C'. 'ISO' should not be
1020 translated, but it may be moved after 'C%d' in languages
1021 where modifiers follow nouns. */
1022 pedwarn (input_location
, OPT_Woverlength_strings
,
1023 "string length %qd is greater than the length %qd "
1024 "ISO C%d compilers are required to support",
1025 nchars
- 1, nchars_max
, relevant_std
);
1028 /* Create the array type for the string constant. The ISO C++
1029 standard says that a string literal has type `const char[N]' or
1030 `const wchar_t[N]'. We use the same logic when invoked as a C
1031 front-end with -Wwrite-strings.
1032 ??? We should change the type of an expression depending on the
1033 state of a warning flag. We should just be warning -- see how
1034 this is handled in the C++ front-end for the deprecated implicit
1035 conversion from string literals to `char*' or `wchar_t*'.
1037 The C++ front end relies on TYPE_MAIN_VARIANT of a cv-qualified
1038 array type being the unqualified version of that type.
1039 Therefore, if we are constructing an array of const char, we must
1040 construct the matching unqualified array type first. The C front
1041 end does not require this, but it does no harm, so we do it
1043 i_type
= build_index_type (size_int (nchars
- 1));
1044 a_type
= build_array_type (e_type
, i_type
);
1045 if (c_dialect_cxx() || warn_write_strings
)
1046 a_type
= c_build_qualified_type (a_type
, TYPE_QUAL_CONST
);
1048 TREE_TYPE (value
) = a_type
;
1049 TREE_CONSTANT (value
) = 1;
1050 TREE_READONLY (value
) = 1;
1051 TREE_STATIC (value
) = 1;
1055 /* If DISABLE is true, stop issuing warnings. This is used when
1056 parsing code that we know will not be executed. This function may
1057 be called multiple times, and works as a stack. */
1060 c_disable_warnings (bool disable
)
1064 ++c_inhibit_evaluation_warnings
;
1065 fold_defer_overflow_warnings ();
1069 /* If ENABLE is true, reenable issuing warnings. */
1072 c_enable_warnings (bool enable
)
1076 --c_inhibit_evaluation_warnings
;
1077 fold_undefer_and_ignore_overflow_warnings ();
1081 /* Fully fold EXPR, an expression that was not folded (beyond integer
1082 constant expressions and null pointer constants) when being built
1083 up. If IN_INIT, this is in a static initializer and certain
1084 changes are made to the folding done. Clear *MAYBE_CONST if
1085 MAYBE_CONST is not NULL and EXPR is definitely not a constant
1086 expression because it contains an evaluated operator (in C99) or an
1087 operator outside of sizeof returning an integer constant (in C90)
1088 not permitted in constant expressions, or because it contains an
1089 evaluated arithmetic overflow. (*MAYBE_CONST should typically be
1090 set to true by callers before calling this function.) Return the
1091 folded expression. Function arguments have already been folded
1092 before calling this function, as have the contents of SAVE_EXPR,
1093 TARGET_EXPR, BIND_EXPR, VA_ARG_EXPR, OBJ_TYPE_REF and
1094 C_MAYBE_CONST_EXPR. */
1097 c_fully_fold (tree expr
, bool in_init
, bool *maybe_const
)
1100 tree eptype
= NULL_TREE
;
1102 bool maybe_const_itself
= true;
1103 location_t loc
= EXPR_LOCATION (expr
);
1105 /* This function is not relevant to C++ because C++ folds while
1106 parsing, and may need changes to be correct for C++ when C++
1107 stops folding while parsing. */
1108 if (c_dialect_cxx ())
1112 maybe_const
= &dummy
;
1113 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
1115 eptype
= TREE_TYPE (expr
);
1116 expr
= TREE_OPERAND (expr
, 0);
1118 ret
= c_fully_fold_internal (expr
, in_init
, maybe_const
,
1119 &maybe_const_itself
);
1121 ret
= fold_convert_loc (loc
, eptype
, ret
);
1122 *maybe_const
&= maybe_const_itself
;
1126 /* Internal helper for c_fully_fold. EXPR and IN_INIT are as for
1127 c_fully_fold. *MAYBE_CONST_OPERANDS is cleared because of operands
1128 not permitted, while *MAYBE_CONST_ITSELF is cleared because of
1129 arithmetic overflow (for C90, *MAYBE_CONST_OPERANDS is carried from
1130 both evaluated and unevaluated subexpressions while
1131 *MAYBE_CONST_ITSELF is carried from only evaluated
1135 c_fully_fold_internal (tree expr
, bool in_init
, bool *maybe_const_operands
,
1136 bool *maybe_const_itself
)
1139 enum tree_code code
= TREE_CODE (expr
);
1140 enum tree_code_class kind
= TREE_CODE_CLASS (code
);
1141 location_t loc
= EXPR_LOCATION (expr
);
1142 tree op0
, op1
, op2
, op3
;
1143 tree orig_op0
, orig_op1
, orig_op2
;
1144 bool op0_const
= true, op1_const
= true, op2_const
= true;
1145 bool op0_const_self
= true, op1_const_self
= true, op2_const_self
= true;
1146 bool nowarning
= TREE_NO_WARNING (expr
);
1149 /* This function is not relevant to C++ because C++ folds while
1150 parsing, and may need changes to be correct for C++ when C++
1151 stops folding while parsing. */
1152 if (c_dialect_cxx ())
1155 /* Constants, declarations, statements, errors, SAVE_EXPRs and
1156 anything else not counted as an expression cannot usefully be
1157 folded further at this point. */
1158 if (!IS_EXPR_CODE_CLASS (kind
)
1159 || kind
== tcc_statement
1160 || code
== SAVE_EXPR
)
1163 /* Operands of variable-length expressions (function calls) have
1164 already been folded, as have __builtin_* function calls, and such
1165 expressions cannot occur in constant expressions. */
1166 if (kind
== tcc_vl_exp
)
1168 *maybe_const_operands
= false;
1173 if (code
== C_MAYBE_CONST_EXPR
)
1175 tree pre
= C_MAYBE_CONST_EXPR_PRE (expr
);
1176 tree inner
= C_MAYBE_CONST_EXPR_EXPR (expr
);
1177 if (C_MAYBE_CONST_EXPR_NON_CONST (expr
))
1178 *maybe_const_operands
= false;
1179 if (C_MAYBE_CONST_EXPR_INT_OPERANDS (expr
))
1180 *maybe_const_itself
= false;
1181 if (pre
&& !in_init
)
1182 ret
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr
), pre
, inner
);
1188 /* Assignment, increment, decrement, function call and comma
1189 operators, and statement expressions, cannot occur in constant
1190 expressions if evaluated / outside of sizeof. (Function calls
1191 were handled above, though VA_ARG_EXPR is treated like a function
1192 call here, and statement expressions are handled through
1193 C_MAYBE_CONST_EXPR to avoid folding inside them.) */
1197 case PREDECREMENT_EXPR
:
1198 case PREINCREMENT_EXPR
:
1199 case POSTDECREMENT_EXPR
:
1200 case POSTINCREMENT_EXPR
:
1202 *maybe_const_operands
= false;
1209 *maybe_const_operands
= false;
1217 /* Fold individual tree codes as appropriate. */
1220 case COMPOUND_LITERAL_EXPR
:
1221 /* Any non-constancy will have been marked in a containing
1222 C_MAYBE_CONST_EXPR; there is no more folding to do here. */
1226 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1227 op1
= TREE_OPERAND (expr
, 1);
1228 op2
= TREE_OPERAND (expr
, 2);
1229 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1230 maybe_const_itself
);
1231 STRIP_TYPE_NOPS (op0
);
1232 if (op0
!= orig_op0
)
1233 ret
= build3 (COMPONENT_REF
, TREE_TYPE (expr
), op0
, op1
, op2
);
1236 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1237 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1242 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1243 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1244 op2
= TREE_OPERAND (expr
, 2);
1245 op3
= TREE_OPERAND (expr
, 3);
1246 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1247 maybe_const_itself
);
1248 STRIP_TYPE_NOPS (op0
);
1249 op1
= c_fully_fold_internal (op1
, in_init
, maybe_const_operands
,
1250 maybe_const_itself
);
1251 STRIP_TYPE_NOPS (op1
);
1252 op1
= decl_constant_value_for_optimization (op1
);
1253 if (op0
!= orig_op0
|| op1
!= orig_op1
)
1254 ret
= build4 (ARRAY_REF
, TREE_TYPE (expr
), op0
, op1
, op2
, op3
);
1257 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1258 TREE_SIDE_EFFECTS (ret
) = TREE_SIDE_EFFECTS (expr
);
1259 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1266 case PREDECREMENT_EXPR
:
1267 case PREINCREMENT_EXPR
:
1268 case POSTDECREMENT_EXPR
:
1269 case POSTINCREMENT_EXPR
:
1273 case POINTER_PLUS_EXPR
:
1274 case TRUNC_DIV_EXPR
:
1276 case FLOOR_DIV_EXPR
:
1277 case TRUNC_MOD_EXPR
:
1279 case EXACT_DIV_EXPR
:
1292 case TRUTH_AND_EXPR
:
1294 case TRUTH_XOR_EXPR
:
1295 case UNORDERED_EXPR
:
1302 /* Binary operations evaluating both arguments (increment and
1303 decrement are binary internally in GCC). */
1304 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1305 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1306 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1307 maybe_const_itself
);
1308 STRIP_TYPE_NOPS (op0
);
1309 if (code
!= MODIFY_EXPR
1310 && code
!= PREDECREMENT_EXPR
1311 && code
!= PREINCREMENT_EXPR
1312 && code
!= POSTDECREMENT_EXPR
1313 && code
!= POSTINCREMENT_EXPR
)
1314 op0
= decl_constant_value_for_optimization (op0
);
1315 /* The RHS of a MODIFY_EXPR was fully folded when building that
1316 expression for the sake of conversion warnings. */
1317 if (code
!= MODIFY_EXPR
)
1318 op1
= c_fully_fold_internal (op1
, in_init
, maybe_const_operands
,
1319 maybe_const_itself
);
1320 STRIP_TYPE_NOPS (op1
);
1321 op1
= decl_constant_value_for_optimization (op1
);
1322 if (op0
!= orig_op0
|| op1
!= orig_op1
|| in_init
)
1324 ? fold_build2_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
)
1325 : fold_build2_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
);
1328 if (TREE_OVERFLOW_P (ret
)
1329 && !TREE_OVERFLOW_P (op0
)
1330 && !TREE_OVERFLOW_P (op1
))
1331 overflow_warning (EXPR_LOCATION (expr
), ret
);
1332 if ((code
== LSHIFT_EXPR
|| code
== RSHIFT_EXPR
)
1333 && TREE_CODE (orig_op1
) != INTEGER_CST
1334 && TREE_CODE (op1
) == INTEGER_CST
1335 && (TREE_CODE (TREE_TYPE (orig_op0
)) == INTEGER_TYPE
1336 || TREE_CODE (TREE_TYPE (orig_op0
)) == FIXED_POINT_TYPE
)
1337 && TREE_CODE (TREE_TYPE (orig_op1
)) == INTEGER_TYPE
1338 && c_inhibit_evaluation_warnings
== 0)
1340 if (tree_int_cst_sgn (op1
) < 0)
1341 warning_at (loc
, 0, (code
== LSHIFT_EXPR
1342 ? G_("left shift count is negative")
1343 : G_("right shift count is negative")));
1344 else if (compare_tree_int (op1
,
1345 TYPE_PRECISION (TREE_TYPE (orig_op0
)))
1347 warning_at (loc
, 0, (code
== LSHIFT_EXPR
1348 ? G_("left shift count >= width of type")
1349 : G_("right shift count >= width of type")));
1354 case FIX_TRUNC_EXPR
:
1357 case ADDR_SPACE_CONVERT_EXPR
:
1358 case VIEW_CONVERT_EXPR
:
1359 case NON_LVALUE_EXPR
:
1362 case TRUTH_NOT_EXPR
:
1367 /* Unary operations. */
1368 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1369 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1370 maybe_const_itself
);
1371 STRIP_TYPE_NOPS (op0
);
1372 if (code
!= ADDR_EXPR
&& code
!= REALPART_EXPR
&& code
!= IMAGPART_EXPR
)
1373 op0
= decl_constant_value_for_optimization (op0
);
1374 /* ??? Cope with user tricks that amount to offsetof. The middle-end is
1375 not prepared to deal with them if they occur in initializers.
1376 Avoid attempts to fold references to UPC shared components
1377 due to the complexities of UPC pointer-to-shared arithmetic. */
1379 && code
== ADDR_EXPR
1380 && (op1
= get_base_address (op0
)) != NULL_TREE
1381 && TREE_CODE (op1
) == INDIRECT_REF
1382 && !upc_shared_type_p (TREE_TYPE (op1
))
1383 && TREE_CONSTANT (TREE_OPERAND (op1
, 0)))
1384 ret
= fold_convert_loc (loc
, TREE_TYPE (expr
), fold_offsetof_1 (op0
));
1385 else if (op0
!= orig_op0
|| in_init
)
1387 ? fold_build1_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
)
1388 : fold_build1_loc (loc
, code
, TREE_TYPE (expr
), op0
);
1391 if (code
== INDIRECT_REF
1393 && TREE_CODE (ret
) == INDIRECT_REF
)
1395 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1396 TREE_SIDE_EFFECTS (ret
) = TREE_SIDE_EFFECTS (expr
);
1397 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1401 case FIX_TRUNC_EXPR
:
1404 /* Don't warn about explicit conversions. We will already
1405 have warned about suspect implicit conversions. */
1409 if (TREE_OVERFLOW_P (ret
) && !TREE_OVERFLOW_P (op0
))
1410 overflow_warning (EXPR_LOCATION (expr
), ret
);
1415 case TRUTH_ANDIF_EXPR
:
1416 case TRUTH_ORIF_EXPR
:
1417 /* Binary operations not necessarily evaluating both
1419 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1420 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1421 op0
= c_fully_fold_internal (op0
, in_init
, &op0_const
, &op0_const_self
);
1422 STRIP_TYPE_NOPS (op0
);
1424 unused_p
= (op0
== (code
== TRUTH_ANDIF_EXPR
1425 ? truthvalue_false_node
1426 : truthvalue_true_node
));
1427 c_disable_warnings (unused_p
);
1428 op1
= c_fully_fold_internal (op1
, in_init
, &op1_const
, &op1_const_self
);
1429 STRIP_TYPE_NOPS (op1
);
1430 c_enable_warnings (unused_p
);
1432 if (op0
!= orig_op0
|| op1
!= orig_op1
|| in_init
)
1434 ? fold_build2_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
)
1435 : fold_build2_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
);
1438 *maybe_const_operands
&= op0_const
;
1439 *maybe_const_itself
&= op0_const_self
;
1443 && (code
== TRUTH_ANDIF_EXPR
1444 ? op0
== truthvalue_false_node
1445 : op0
== truthvalue_true_node
)))
1446 *maybe_const_operands
&= op1_const
;
1449 && (code
== TRUTH_ANDIF_EXPR
1450 ? op0
== truthvalue_false_node
1451 : op0
== truthvalue_true_node
)))
1452 *maybe_const_itself
&= op1_const_self
;
1456 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1457 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1458 orig_op2
= op2
= TREE_OPERAND (expr
, 2);
1459 op0
= c_fully_fold_internal (op0
, in_init
, &op0_const
, &op0_const_self
);
1461 STRIP_TYPE_NOPS (op0
);
1462 c_disable_warnings (op0
== truthvalue_false_node
);
1463 op1
= c_fully_fold_internal (op1
, in_init
, &op1_const
, &op1_const_self
);
1464 STRIP_TYPE_NOPS (op1
);
1465 c_enable_warnings (op0
== truthvalue_false_node
);
1467 c_disable_warnings (op0
== truthvalue_true_node
);
1468 op2
= c_fully_fold_internal (op2
, in_init
, &op2_const
, &op2_const_self
);
1469 STRIP_TYPE_NOPS (op2
);
1470 c_enable_warnings (op0
== truthvalue_true_node
);
1472 if (op0
!= orig_op0
|| op1
!= orig_op1
|| op2
!= orig_op2
)
1473 ret
= fold_build3_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
, op2
);
1476 *maybe_const_operands
&= op0_const
;
1477 *maybe_const_itself
&= op0_const_self
;
1481 && op0
== truthvalue_false_node
))
1482 *maybe_const_operands
&= op1_const
;
1485 && op0
== truthvalue_false_node
))
1486 *maybe_const_itself
&= op1_const_self
;
1490 && op0
== truthvalue_true_node
))
1491 *maybe_const_operands
&= op2_const
;
1494 && op0
== truthvalue_true_node
))
1495 *maybe_const_itself
&= op2_const_self
;
1498 case EXCESS_PRECISION_EXPR
:
1499 /* Each case where an operand with excess precision may be
1500 encountered must remove the EXCESS_PRECISION_EXPR around
1501 inner operands and possibly put one around the whole
1502 expression or possibly convert to the semantic type (which
1503 c_fully_fold does); we cannot tell at this stage which is
1504 appropriate in any particular case. */
1508 /* Various codes may appear through folding built-in functions
1509 and their arguments. */
1514 /* Some folding may introduce NON_LVALUE_EXPRs; all lvalue checks
1515 have been done by this point, so remove them again. */
1516 nowarning
|= TREE_NO_WARNING (ret
);
1517 STRIP_TYPE_NOPS (ret
);
1518 if (nowarning
&& !TREE_NO_WARNING (ret
))
1520 if (!CAN_HAVE_LOCATION_P (ret
))
1521 ret
= build1 (NOP_EXPR
, TREE_TYPE (ret
), ret
);
1522 TREE_NO_WARNING (ret
) = 1;
1525 protected_set_expr_location (ret
, loc
);
1529 /* If not optimizing, EXP is not a VAR_DECL, or EXP has array type,
1530 return EXP. Otherwise, return either EXP or its known constant
1531 value (if it has one), but return EXP if EXP has mode BLKmode. ???
1532 Is the BLKmode test appropriate? */
1535 decl_constant_value_for_optimization (tree exp
)
1539 /* This function is only used by C, for c_fully_fold and other
1540 optimization, and may not be correct for C++. */
1541 if (c_dialect_cxx ())
1545 || TREE_CODE (exp
) != VAR_DECL
1546 || TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
1547 || DECL_MODE (exp
) == BLKmode
)
1550 ret
= decl_constant_value (exp
);
1551 /* Avoid unwanted tree sharing between the initializer and current
1552 function's body where the tree can be modified e.g. by the
1554 if (ret
!= exp
&& TREE_STATIC (exp
))
1555 ret
= unshare_expr (ret
);
1559 /* Print a warning if a constant expression had overflow in folding.
1560 Invoke this function on every expression that the language
1561 requires to be a constant expression.
1562 Note the ANSI C standard says it is erroneous for a
1563 constant expression to overflow. */
1566 constant_expression_warning (tree value
)
1568 if (warn_overflow
&& pedantic
1569 && (TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1570 || TREE_CODE (value
) == FIXED_CST
1571 || TREE_CODE (value
) == VECTOR_CST
1572 || TREE_CODE (value
) == COMPLEX_CST
)
1573 && TREE_OVERFLOW (value
))
1574 pedwarn (input_location
, OPT_Woverflow
, "overflow in constant expression");
1577 /* The same as above but print an unconditional error. */
1579 constant_expression_error (tree value
)
1581 if ((TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1582 || TREE_CODE (value
) == FIXED_CST
1583 || TREE_CODE (value
) == VECTOR_CST
1584 || TREE_CODE (value
) == COMPLEX_CST
)
1585 && TREE_OVERFLOW (value
))
1586 error ("overflow in constant expression");
1589 /* Print a warning if an expression had overflow in folding and its
1592 Invoke this function on every expression that
1593 (1) appears in the source code, and
1594 (2) is a constant expression that overflowed, and
1595 (3) is not already checked by convert_and_check;
1596 however, do not invoke this function on operands of explicit casts
1597 or when the expression is the result of an operator and any operand
1598 already overflowed. */
1601 overflow_warning (location_t loc
, tree value
)
1603 if (c_inhibit_evaluation_warnings
!= 0)
1606 switch (TREE_CODE (value
))
1609 warning_at (loc
, OPT_Woverflow
, "integer overflow in expression");
1613 warning_at (loc
, OPT_Woverflow
,
1614 "floating point overflow in expression");
1618 warning_at (loc
, OPT_Woverflow
, "fixed-point overflow in expression");
1622 warning_at (loc
, OPT_Woverflow
, "vector overflow in expression");
1626 if (TREE_CODE (TREE_REALPART (value
)) == INTEGER_CST
)
1627 warning_at (loc
, OPT_Woverflow
,
1628 "complex integer overflow in expression");
1629 else if (TREE_CODE (TREE_REALPART (value
)) == REAL_CST
)
1630 warning_at (loc
, OPT_Woverflow
,
1631 "complex floating point overflow in expression");
1639 /* Warn about uses of logical || / && operator in a context where it
1640 is likely that the bitwise equivalent was intended by the
1641 programmer. We have seen an expression in which CODE is a binary
1642 operator used to combine expressions OP_LEFT and OP_RIGHT, which before folding
1643 had CODE_LEFT and CODE_RIGHT, into an expression of type TYPE. */
1645 warn_logical_operator (location_t location
, enum tree_code code
, tree type
,
1646 enum tree_code code_left
, tree op_left
,
1647 enum tree_code
ARG_UNUSED (code_right
), tree op_right
)
1649 int or_op
= (code
== TRUTH_ORIF_EXPR
|| code
== TRUTH_OR_EXPR
);
1650 int in0_p
, in1_p
, in_p
;
1651 tree low0
, low1
, low
, high0
, high1
, high
, lhs
, rhs
, tem
;
1652 bool strict_overflow_p
= false;
1654 if (code
!= TRUTH_ANDIF_EXPR
1655 && code
!= TRUTH_AND_EXPR
1656 && code
!= TRUTH_ORIF_EXPR
1657 && code
!= TRUTH_OR_EXPR
)
1660 /* Warn if &&/|| are being used in a context where it is
1661 likely that the bitwise equivalent was intended by the
1662 programmer. That is, an expression such as op && MASK
1663 where op should not be any boolean expression, nor a
1664 constant, and mask seems to be a non-boolean integer constant. */
1665 if (!truth_value_p (code_left
)
1666 && INTEGRAL_TYPE_P (TREE_TYPE (op_left
))
1667 && !CONSTANT_CLASS_P (op_left
)
1668 && !TREE_NO_WARNING (op_left
)
1669 && TREE_CODE (op_right
) == INTEGER_CST
1670 && !integer_zerop (op_right
)
1671 && !integer_onep (op_right
))
1674 warning_at (location
, OPT_Wlogical_op
, "logical %<or%>"
1675 " applied to non-boolean constant");
1677 warning_at (location
, OPT_Wlogical_op
, "logical %<and%>"
1678 " applied to non-boolean constant");
1679 TREE_NO_WARNING (op_left
) = true;
1683 /* We do not warn for constants because they are typical of macro
1684 expansions that test for features. */
1685 if (CONSTANT_CLASS_P (op_left
) || CONSTANT_CLASS_P (op_right
))
1688 /* This warning only makes sense with logical operands. */
1689 if (!(truth_value_p (TREE_CODE (op_left
))
1690 || INTEGRAL_TYPE_P (TREE_TYPE (op_left
)))
1691 || !(truth_value_p (TREE_CODE (op_right
))
1692 || INTEGRAL_TYPE_P (TREE_TYPE (op_right
))))
1696 /* We first test whether either side separately is trivially true
1697 (with OR) or trivially false (with AND). If so, do not warn.
1698 This is a common idiom for testing ranges of data types in
1700 lhs
= make_range (op_left
, &in0_p
, &low0
, &high0
, &strict_overflow_p
);
1703 if (TREE_CODE (lhs
) == C_MAYBE_CONST_EXPR
)
1704 lhs
= C_MAYBE_CONST_EXPR_EXPR (lhs
);
1706 /* If this is an OR operation, invert both sides; now, the result
1707 should be always false to get a warning. */
1711 tem
= build_range_check (UNKNOWN_LOCATION
, type
, lhs
, in0_p
, low0
, high0
);
1712 if (tem
&& integer_zerop (tem
))
1715 rhs
= make_range (op_right
, &in1_p
, &low1
, &high1
, &strict_overflow_p
);
1718 if (TREE_CODE (rhs
) == C_MAYBE_CONST_EXPR
)
1719 rhs
= C_MAYBE_CONST_EXPR_EXPR (rhs
);
1721 /* If this is an OR operation, invert both sides; now, the result
1722 should be always false to get a warning. */
1726 tem
= build_range_check (UNKNOWN_LOCATION
, type
, rhs
, in1_p
, low1
, high1
);
1727 if (tem
&& integer_zerop (tem
))
1730 /* If both expressions have the same operand, if we can merge the
1731 ranges, and if the range test is always false, then warn. */
1732 if (operand_equal_p (lhs
, rhs
, 0)
1733 && merge_ranges (&in_p
, &low
, &high
, in0_p
, low0
, high0
,
1735 && 0 != (tem
= build_range_check (UNKNOWN_LOCATION
,
1736 type
, lhs
, in_p
, low
, high
))
1737 && integer_zerop (tem
))
1740 warning_at (location
, OPT_Wlogical_op
,
1742 "of collectively exhaustive tests is always true");
1744 warning_at (location
, OPT_Wlogical_op
,
1746 "of mutually exclusive tests is always false");
1751 /* Warn if EXP contains any computations whose results are not used.
1752 Return true if a warning is printed; false otherwise. LOCUS is the
1753 (potential) location of the expression. */
1756 warn_if_unused_value (const_tree exp
, location_t locus
)
1759 if (TREE_USED (exp
) || TREE_NO_WARNING (exp
))
1762 /* Don't warn about void constructs. This includes casting to void,
1763 void function calls, and statement expressions with a final cast
1765 if (VOID_TYPE_P (TREE_TYPE (exp
)))
1768 if (EXPR_HAS_LOCATION (exp
))
1769 locus
= EXPR_LOCATION (exp
);
1771 switch (TREE_CODE (exp
))
1773 case PREINCREMENT_EXPR
:
1774 case POSTINCREMENT_EXPR
:
1775 case PREDECREMENT_EXPR
:
1776 case POSTDECREMENT_EXPR
:
1781 case TRY_CATCH_EXPR
:
1782 case WITH_CLEANUP_EXPR
:
1788 /* For a binding, warn if no side effect within it. */
1789 exp
= BIND_EXPR_BODY (exp
);
1793 case NON_LVALUE_EXPR
:
1795 exp
= TREE_OPERAND (exp
, 0);
1798 case TRUTH_ORIF_EXPR
:
1799 case TRUTH_ANDIF_EXPR
:
1800 /* In && or ||, warn if 2nd operand has no side effect. */
1801 exp
= TREE_OPERAND (exp
, 1);
1805 if (warn_if_unused_value (TREE_OPERAND (exp
, 0), locus
))
1807 /* Let people do `(foo (), 0)' without a warning. */
1808 if (TREE_CONSTANT (TREE_OPERAND (exp
, 1)))
1810 exp
= TREE_OPERAND (exp
, 1);
1814 /* If this is an expression with side effects, don't warn; this
1815 case commonly appears in macro expansions. */
1816 if (TREE_SIDE_EFFECTS (exp
))
1821 /* Don't warn about automatic dereferencing of references, since
1822 the user cannot control it. */
1823 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == REFERENCE_TYPE
)
1825 exp
= TREE_OPERAND (exp
, 0);
1831 /* Referencing a volatile value is a side effect, so don't warn. */
1832 if ((DECL_P (exp
) || REFERENCE_CLASS_P (exp
))
1833 && TREE_THIS_VOLATILE (exp
))
1836 /* If this is an expression which has no operands, there is no value
1837 to be unused. There are no such language-independent codes,
1838 but front ends may define such. */
1839 if (EXPRESSION_CLASS_P (exp
) && TREE_OPERAND_LENGTH (exp
) == 0)
1843 return warning_at (locus
, OPT_Wunused_value
, "value computed is not used");
1848 /* Print a warning about casts that might indicate violation
1849 of strict aliasing rules if -Wstrict-aliasing is used and
1850 strict aliasing mode is in effect. OTYPE is the original
1851 TREE_TYPE of EXPR, and TYPE the type we're casting to. */
1854 strict_aliasing_warning (tree otype
, tree type
, tree expr
)
1856 /* Strip pointer conversion chains and get to the correct original type. */
1858 otype
= TREE_TYPE (expr
);
1860 if (!(flag_strict_aliasing
1861 && POINTER_TYPE_P (type
)
1862 && POINTER_TYPE_P (otype
)
1863 && !VOID_TYPE_P (TREE_TYPE (type
)))
1864 /* If the type we are casting to is a ref-all pointer
1865 dereferencing it is always valid. */
1866 || TYPE_REF_CAN_ALIAS_ALL (type
))
1869 if ((warn_strict_aliasing
> 1) && TREE_CODE (expr
) == ADDR_EXPR
1870 && (DECL_P (TREE_OPERAND (expr
, 0))
1871 || handled_component_p (TREE_OPERAND (expr
, 0))))
1873 /* Casting the address of an object to non void pointer. Warn
1874 if the cast breaks type based aliasing. */
1875 if (!COMPLETE_TYPE_P (TREE_TYPE (type
)) && warn_strict_aliasing
== 2)
1877 warning (OPT_Wstrict_aliasing
, "type-punning to incomplete type "
1878 "might break strict-aliasing rules");
1883 /* warn_strict_aliasing >= 3. This includes the default (3).
1884 Only warn if the cast is dereferenced immediately. */
1885 alias_set_type set1
=
1886 get_alias_set (TREE_TYPE (TREE_OPERAND (expr
, 0)));
1887 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
1889 if (set1
!= set2
&& set2
!= 0
1890 && (set1
== 0 || !alias_sets_conflict_p (set1
, set2
)))
1892 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1893 "pointer will break strict-aliasing rules");
1896 else if (warn_strict_aliasing
== 2
1897 && !alias_sets_must_conflict_p (set1
, set2
))
1899 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1900 "pointer might break strict-aliasing rules");
1906 if ((warn_strict_aliasing
== 1) && !VOID_TYPE_P (TREE_TYPE (otype
)))
1908 /* At this level, warn for any conversions, even if an address is
1909 not taken in the same statement. This will likely produce many
1910 false positives, but could be useful to pinpoint problems that
1911 are not revealed at higher levels. */
1912 alias_set_type set1
= get_alias_set (TREE_TYPE (otype
));
1913 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
1914 if (!COMPLETE_TYPE_P (type
)
1915 || !alias_sets_must_conflict_p (set1
, set2
))
1917 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1918 "pointer might break strict-aliasing rules");
1926 /* Warn about memset (&a, 0, sizeof (&a)); and similar mistakes with
1927 sizeof as last operand of certain builtins. */
1930 sizeof_pointer_memaccess_warning (location_t
*sizeof_arg_loc
, tree callee
,
1931 vec
<tree
, va_gc
> *params
, tree
*sizeof_arg
,
1932 bool (*comp_types
) (tree
, tree
))
1934 tree type
, dest
= NULL_TREE
, src
= NULL_TREE
, tem
;
1935 bool strop
= false, cmp
= false;
1936 unsigned int idx
= ~0;
1939 if (TREE_CODE (callee
) != FUNCTION_DECL
1940 || DECL_BUILT_IN_CLASS (callee
) != BUILT_IN_NORMAL
1941 || vec_safe_length (params
) <= 1)
1944 switch (DECL_FUNCTION_CODE (callee
))
1946 case BUILT_IN_STRNCMP
:
1947 case BUILT_IN_STRNCASECMP
:
1950 case BUILT_IN_STRNCPY
:
1951 case BUILT_IN_STRNCPY_CHK
:
1952 case BUILT_IN_STRNCAT
:
1953 case BUILT_IN_STRNCAT_CHK
:
1954 case BUILT_IN_STPNCPY
:
1955 case BUILT_IN_STPNCPY_CHK
:
1958 case BUILT_IN_MEMCPY
:
1959 case BUILT_IN_MEMCPY_CHK
:
1960 case BUILT_IN_MEMMOVE
:
1961 case BUILT_IN_MEMMOVE_CHK
:
1962 if (params
->length () < 3)
1965 dest
= (*params
)[0];
1968 case BUILT_IN_BCOPY
:
1969 if (params
->length () < 3)
1972 dest
= (*params
)[1];
1975 case BUILT_IN_MEMCMP
:
1977 if (params
->length () < 3)
1980 dest
= (*params
)[0];
1984 case BUILT_IN_MEMSET
:
1985 case BUILT_IN_MEMSET_CHK
:
1986 if (params
->length () < 3)
1988 dest
= (*params
)[0];
1991 case BUILT_IN_BZERO
:
1992 dest
= (*params
)[0];
1995 case BUILT_IN_STRNDUP
:
2000 case BUILT_IN_MEMCHR
:
2001 if (params
->length () < 3)
2006 case BUILT_IN_SNPRINTF
:
2007 case BUILT_IN_SNPRINTF_CHK
:
2008 case BUILT_IN_VSNPRINTF
:
2009 case BUILT_IN_VSNPRINTF_CHK
:
2010 dest
= (*params
)[0];
2021 if (sizeof_arg
[idx
] == NULL
|| sizeof_arg
[idx
] == error_mark_node
)
2024 type
= TYPE_P (sizeof_arg
[idx
])
2025 ? sizeof_arg
[idx
] : TREE_TYPE (sizeof_arg
[idx
]);
2026 if (!POINTER_TYPE_P (type
))
2030 && (tem
= tree_strip_nop_conversions (dest
))
2031 && POINTER_TYPE_P (TREE_TYPE (tem
))
2032 && comp_types (TREE_TYPE (TREE_TYPE (tem
)), type
))
2036 && (tem
= tree_strip_nop_conversions (src
))
2037 && POINTER_TYPE_P (TREE_TYPE (tem
))
2038 && comp_types (TREE_TYPE (TREE_TYPE (tem
)), type
))
2041 loc
= sizeof_arg_loc
[idx
];
2045 if (!TYPE_P (sizeof_arg
[idx
])
2046 && operand_equal_p (dest
, sizeof_arg
[idx
], 0)
2047 && comp_types (TREE_TYPE (dest
), type
))
2049 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2050 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2051 "argument to %<sizeof%> in %qD call is the same "
2052 "expression as the destination; did you mean to "
2053 "remove the addressof?", callee
);
2054 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2055 == TYPE_PRECISION (char_type_node
))
2057 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2058 "argument to %<sizeof%> in %qD call is the same "
2059 "expression as the destination; did you mean to "
2060 "provide an explicit length?", callee
);
2062 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2063 "argument to %<sizeof%> in %qD call is the same "
2064 "expression as the destination; did you mean to "
2065 "dereference it?", callee
);
2069 if (POINTER_TYPE_P (TREE_TYPE (dest
))
2071 && comp_types (TREE_TYPE (dest
), type
)
2072 && !VOID_TYPE_P (TREE_TYPE (type
)))
2074 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2075 "argument to %<sizeof%> in %qD call is the same "
2076 "pointer type %qT as the destination; expected %qT "
2077 "or an explicit length", callee
, TREE_TYPE (dest
),
2078 TREE_TYPE (TREE_TYPE (dest
)));
2085 if (!TYPE_P (sizeof_arg
[idx
])
2086 && operand_equal_p (src
, sizeof_arg
[idx
], 0)
2087 && comp_types (TREE_TYPE (src
), type
))
2089 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2090 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2091 "argument to %<sizeof%> in %qD call is the same "
2092 "expression as the source; did you mean to "
2093 "remove the addressof?", callee
);
2094 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2095 == TYPE_PRECISION (char_type_node
))
2097 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2098 "argument to %<sizeof%> in %qD call is the same "
2099 "expression as the source; did you mean to "
2100 "provide an explicit length?", callee
);
2102 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2103 "argument to %<sizeof%> in %qD call is the same "
2104 "expression as the source; did you mean to "
2105 "dereference it?", callee
);
2109 if (POINTER_TYPE_P (TREE_TYPE (src
))
2111 && comp_types (TREE_TYPE (src
), type
)
2112 && !VOID_TYPE_P (TREE_TYPE (type
)))
2114 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2115 "argument to %<sizeof%> in %qD call is the same "
2116 "pointer type %qT as the source; expected %qT "
2117 "or an explicit length", callee
, TREE_TYPE (src
),
2118 TREE_TYPE (TREE_TYPE (src
)));
2125 if (!TYPE_P (sizeof_arg
[idx
])
2126 && operand_equal_p (dest
, sizeof_arg
[idx
], 0)
2127 && comp_types (TREE_TYPE (dest
), type
))
2129 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2130 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2131 "argument to %<sizeof%> in %qD call is the same "
2132 "expression as the first source; did you mean to "
2133 "remove the addressof?", callee
);
2134 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2135 == TYPE_PRECISION (char_type_node
))
2137 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2138 "argument to %<sizeof%> in %qD call is the same "
2139 "expression as the first source; did you mean to "
2140 "provide an explicit length?", callee
);
2142 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2143 "argument to %<sizeof%> in %qD call is the same "
2144 "expression as the first source; did you mean to "
2145 "dereference it?", callee
);
2149 if (POINTER_TYPE_P (TREE_TYPE (dest
))
2151 && comp_types (TREE_TYPE (dest
), type
)
2152 && !VOID_TYPE_P (TREE_TYPE (type
)))
2154 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2155 "argument to %<sizeof%> in %qD call is the same "
2156 "pointer type %qT as the first source; expected %qT "
2157 "or an explicit length", callee
, TREE_TYPE (dest
),
2158 TREE_TYPE (TREE_TYPE (dest
)));
2165 if (!TYPE_P (sizeof_arg
[idx
])
2166 && operand_equal_p (src
, sizeof_arg
[idx
], 0)
2167 && comp_types (TREE_TYPE (src
), type
))
2169 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2170 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2171 "argument to %<sizeof%> in %qD call is the same "
2172 "expression as the second source; did you mean to "
2173 "remove the addressof?", callee
);
2174 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2175 == TYPE_PRECISION (char_type_node
))
2177 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2178 "argument to %<sizeof%> in %qD call is the same "
2179 "expression as the second source; did you mean to "
2180 "provide an explicit length?", callee
);
2182 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2183 "argument to %<sizeof%> in %qD call is the same "
2184 "expression as the second source; did you mean to "
2185 "dereference it?", callee
);
2189 if (POINTER_TYPE_P (TREE_TYPE (src
))
2191 && comp_types (TREE_TYPE (src
), type
)
2192 && !VOID_TYPE_P (TREE_TYPE (type
)))
2194 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2195 "argument to %<sizeof%> in %qD call is the same "
2196 "pointer type %qT as the second source; expected %qT "
2197 "or an explicit length", callee
, TREE_TYPE (src
),
2198 TREE_TYPE (TREE_TYPE (src
)));
2205 /* Warn for unlikely, improbable, or stupid DECL declarations
2209 check_main_parameter_types (tree decl
)
2211 function_args_iterator iter
;
2215 FOREACH_FUNCTION_ARGS (TREE_TYPE (decl
), type
, iter
)
2217 /* XXX void_type_node belies the abstraction. */
2218 if (type
== void_type_node
|| type
== error_mark_node
)
2225 if (TYPE_MAIN_VARIANT (type
) != integer_type_node
)
2226 pedwarn (input_location
, OPT_Wmain
,
2227 "first argument of %q+D should be %<int%>", decl
);
2231 if (TREE_CODE (type
) != POINTER_TYPE
2232 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
2233 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
2235 pedwarn (input_location
, OPT_Wmain
,
2236 "second argument of %q+D should be %<char **%>", decl
);
2240 if (TREE_CODE (type
) != POINTER_TYPE
2241 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
2242 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
2244 pedwarn (input_location
, OPT_Wmain
,
2245 "third argument of %q+D should probably be "
2246 "%<char **%>", decl
);
2251 /* It is intentional that this message does not mention the third
2252 argument because it's only mentioned in an appendix of the
2254 if (argct
> 0 && (argct
< 2 || argct
> 3))
2255 pedwarn (input_location
, OPT_Wmain
,
2256 "%q+D takes only zero or two arguments", decl
);
2259 /* vector_targets_convertible_p is used for vector pointer types. The
2260 callers perform various checks that the qualifiers are satisfactory,
2261 while OTOH vector_targets_convertible_p ignores the number of elements
2262 in the vectors. That's fine with vector pointers as we can consider,
2263 say, a vector of 8 elements as two consecutive vectors of 4 elements,
2264 and that does not require and conversion of the pointer values.
2265 In contrast, vector_types_convertible_p and
2266 vector_types_compatible_elements_p are used for vector value types. */
2267 /* True if pointers to distinct types T1 and T2 can be converted to
2268 each other without an explicit cast. Only returns true for opaque
2271 vector_targets_convertible_p (const_tree t1
, const_tree t2
)
2273 if (TREE_CODE (t1
) == VECTOR_TYPE
&& TREE_CODE (t2
) == VECTOR_TYPE
2274 && (TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2275 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2281 /* vector_types_convertible_p is used for vector value types.
2282 It could in principle call vector_targets_convertible_p as a subroutine,
2283 but then the check for vector type would be duplicated with its callers,
2284 and also the purpose of vector_targets_convertible_p would become
2286 Where vector_types_convertible_p returns true, a conversion might still be
2287 needed to make the types match.
2288 In contrast, vector_targets_convertible_p is used for vector pointer
2289 values, and vector_types_compatible_elements_p is used specifically
2290 in the context for binary operators, as a check if use is possible without
2292 /* True if vector types T1 and T2 can be converted to each other
2293 without an explicit cast. If EMIT_LAX_NOTE is true, and T1 and T2
2294 can only be converted with -flax-vector-conversions yet that is not
2295 in effect, emit a note telling the user about that option if such
2296 a note has not previously been emitted. */
2298 vector_types_convertible_p (const_tree t1
, const_tree t2
, bool emit_lax_note
)
2300 static bool emitted_lax_note
= false;
2301 bool convertible_lax
;
2303 if ((TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2304 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2308 (tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
))
2309 && (TREE_CODE (TREE_TYPE (t1
)) != REAL_TYPE
||
2310 TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
))
2311 && (INTEGRAL_TYPE_P (TREE_TYPE (t1
))
2312 == INTEGRAL_TYPE_P (TREE_TYPE (t2
))));
2314 if (!convertible_lax
|| flag_lax_vector_conversions
)
2315 return convertible_lax
;
2317 if (TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
)
2318 && lang_hooks
.types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
2321 if (emit_lax_note
&& !emitted_lax_note
)
2323 emitted_lax_note
= true;
2324 inform (input_location
, "use -flax-vector-conversions to permit "
2325 "conversions between vectors with differing "
2326 "element types or numbers of subparts");
2332 /* Build a VEC_PERM_EXPR if V0, V1 and MASK are not error_mark_nodes
2333 and have vector types, V0 has the same type as V1, and the number of
2334 elements of V0, V1, MASK is the same.
2336 In case V1 is a NULL_TREE it is assumed that __builtin_shuffle was
2337 called with two arguments. In this case implementation passes the
2338 first argument twice in order to share the same tree code. This fact
2339 could enable the mask-values being twice the vector length. This is
2340 an implementation accident and this semantics is not guaranteed to
2343 c_build_vec_perm_expr (location_t loc
, tree v0
, tree v1
, tree mask
,
2348 bool maybe_const
= false;
2349 bool two_arguments
= false;
2351 if (v1
== NULL_TREE
)
2353 two_arguments
= true;
2357 if (v0
== error_mark_node
|| v1
== error_mark_node
2358 || mask
== error_mark_node
)
2359 return error_mark_node
;
2361 if (TREE_CODE (TREE_TYPE (mask
)) != VECTOR_TYPE
2362 || TREE_CODE (TREE_TYPE (TREE_TYPE (mask
))) != INTEGER_TYPE
)
2365 error_at (loc
, "__builtin_shuffle last argument must "
2366 "be an integer vector");
2367 return error_mark_node
;
2370 if (TREE_CODE (TREE_TYPE (v0
)) != VECTOR_TYPE
2371 || TREE_CODE (TREE_TYPE (v1
)) != VECTOR_TYPE
)
2374 error_at (loc
, "__builtin_shuffle arguments must be vectors");
2375 return error_mark_node
;
2378 if (TYPE_MAIN_VARIANT (TREE_TYPE (v0
)) != TYPE_MAIN_VARIANT (TREE_TYPE (v1
)))
2381 error_at (loc
, "__builtin_shuffle argument vectors must be of "
2383 return error_mark_node
;
2386 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (v0
))
2387 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
))
2388 && TYPE_VECTOR_SUBPARTS (TREE_TYPE (v1
))
2389 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
)))
2392 error_at (loc
, "__builtin_shuffle number of elements of the "
2393 "argument vector(s) and the mask vector should "
2395 return error_mark_node
;
2398 if (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (v0
))))
2399 != GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (mask
)))))
2402 error_at (loc
, "__builtin_shuffle argument vector(s) inner type "
2403 "must have the same size as inner type of the mask");
2404 return error_mark_node
;
2407 if (!c_dialect_cxx ())
2409 /* Avoid C_MAYBE_CONST_EXPRs inside VEC_PERM_EXPR. */
2410 v0
= c_fully_fold (v0
, false, &maybe_const
);
2411 wrap
&= maybe_const
;
2414 v1
= v0
= save_expr (v0
);
2417 v1
= c_fully_fold (v1
, false, &maybe_const
);
2418 wrap
&= maybe_const
;
2421 mask
= c_fully_fold (mask
, false, &maybe_const
);
2422 wrap
&= maybe_const
;
2424 else if (two_arguments
)
2425 v1
= v0
= save_expr (v0
);
2427 ret
= build3_loc (loc
, VEC_PERM_EXPR
, TREE_TYPE (v0
), v0
, v1
, mask
);
2429 if (!c_dialect_cxx () && !wrap
)
2430 ret
= c_wrap_maybe_const (ret
, true);
2435 /* Like tree.c:get_narrower, but retain conversion from C++0x scoped enum
2436 to integral type. */
2439 c_common_get_narrower (tree op
, int *unsignedp_ptr
)
2441 op
= get_narrower (op
, unsignedp_ptr
);
2443 if (TREE_CODE (TREE_TYPE (op
)) == ENUMERAL_TYPE
2444 && ENUM_IS_SCOPED (TREE_TYPE (op
)))
2446 /* C++0x scoped enumerations don't implicitly convert to integral
2447 type; if we stripped an explicit conversion to a larger type we
2448 need to replace it so common_type will still work. */
2449 tree type
= c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op
)),
2450 TYPE_UNSIGNED (TREE_TYPE (op
)));
2451 op
= fold_convert (type
, op
);
2456 /* This is a helper function of build_binary_op.
2458 For certain operations if both args were extended from the same
2459 smaller type, do the arithmetic in that type and then extend.
2461 BITWISE indicates a bitwise operation.
2462 For them, this optimization is safe only if
2463 both args are zero-extended or both are sign-extended.
2464 Otherwise, we might change the result.
2465 Eg, (short)-1 | (unsigned short)-1 is (int)-1
2466 but calculated in (unsigned short) it would be (unsigned short)-1.
2469 shorten_binary_op (tree result_type
, tree op0
, tree op1
, bool bitwise
)
2471 int unsigned0
, unsigned1
;
2476 /* Cast OP0 and OP1 to RESULT_TYPE. Doing so prevents
2477 excessive narrowing when we call get_narrower below. For
2478 example, suppose that OP0 is of unsigned int extended
2479 from signed char and that RESULT_TYPE is long long int.
2480 If we explicitly cast OP0 to RESULT_TYPE, OP0 would look
2483 (long long int) (unsigned int) signed_char
2485 which get_narrower would narrow down to
2487 (unsigned int) signed char
2489 If we do not cast OP0 first, get_narrower would return
2490 signed_char, which is inconsistent with the case of the
2492 op0
= convert (result_type
, op0
);
2493 op1
= convert (result_type
, op1
);
2495 arg0
= c_common_get_narrower (op0
, &unsigned0
);
2496 arg1
= c_common_get_narrower (op1
, &unsigned1
);
2498 /* UNS is 1 if the operation to be done is an unsigned one. */
2499 uns
= TYPE_UNSIGNED (result_type
);
2501 /* Handle the case that OP0 (or OP1) does not *contain* a conversion
2502 but it *requires* conversion to FINAL_TYPE. */
2504 if ((TYPE_PRECISION (TREE_TYPE (op0
))
2505 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2506 && TREE_TYPE (op0
) != result_type
)
2507 unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2508 if ((TYPE_PRECISION (TREE_TYPE (op1
))
2509 == TYPE_PRECISION (TREE_TYPE (arg1
)))
2510 && TREE_TYPE (op1
) != result_type
)
2511 unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2513 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
2515 /* For bitwise operations, signedness of nominal type
2516 does not matter. Consider only how operands were extended. */
2520 /* Note that in all three cases below we refrain from optimizing
2521 an unsigned operation on sign-extended args.
2522 That would not be valid. */
2524 /* Both args variable: if both extended in same way
2525 from same width, do it in that width.
2526 Do it unsigned if args were zero-extended. */
2527 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
2528 < TYPE_PRECISION (result_type
))
2529 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2530 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2531 && unsigned0
== unsigned1
2532 && (unsigned0
|| !uns
))
2533 return c_common_signed_or_unsigned_type
2534 (unsigned0
, common_type (TREE_TYPE (arg0
), TREE_TYPE (arg1
)));
2536 else if (TREE_CODE (arg0
) == INTEGER_CST
2537 && (unsigned1
|| !uns
)
2538 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2539 < TYPE_PRECISION (result_type
))
2541 = c_common_signed_or_unsigned_type (unsigned1
,
2543 && !POINTER_TYPE_P (type
)
2544 && int_fits_type_p (arg0
, type
))
2547 else if (TREE_CODE (arg1
) == INTEGER_CST
2548 && (unsigned0
|| !uns
)
2549 && (TYPE_PRECISION (TREE_TYPE (arg0
))
2550 < TYPE_PRECISION (result_type
))
2552 = c_common_signed_or_unsigned_type (unsigned0
,
2554 && !POINTER_TYPE_P (type
)
2555 && int_fits_type_p (arg1
, type
))
2561 /* Checks if expression EXPR of real/integer type cannot be converted
2562 to the real/integer type TYPE. Function returns non-zero when:
2563 * EXPR is a constant which cannot be exactly converted to TYPE
2564 * EXPR is not a constant and size of EXPR's type > than size of TYPE,
2565 for EXPR type and TYPE being both integers or both real.
2566 * EXPR is not a constant of real type and TYPE is an integer.
2567 * EXPR is not a constant of integer type which cannot be
2568 exactly converted to real type.
2569 Function allows conversions between types of different signedness and
2570 can return SAFE_CONVERSION (zero) in that case. Function can produce
2571 signedness warnings if PRODUCE_WARNS is true. */
2572 enum conversion_safety
2573 unsafe_conversion_p (tree type
, tree expr
, bool produce_warns
)
2575 enum conversion_safety give_warning
= SAFE_CONVERSION
; /* is 0 or false */
2576 tree expr_type
= TREE_TYPE (expr
);
2577 location_t loc
= EXPR_LOC_OR_LOC (expr
, input_location
);
2579 if (TREE_CODE (expr
) == REAL_CST
|| TREE_CODE (expr
) == INTEGER_CST
)
2581 /* Warn for real constant that is not an exact integer converted
2583 if (TREE_CODE (expr_type
) == REAL_TYPE
2584 && TREE_CODE (type
) == INTEGER_TYPE
)
2586 if (!real_isinteger (TREE_REAL_CST_PTR (expr
), TYPE_MODE (expr_type
)))
2587 give_warning
= UNSAFE_REAL
;
2589 /* Warn for an integer constant that does not fit into integer type. */
2590 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2591 && TREE_CODE (type
) == INTEGER_TYPE
2592 && !int_fits_type_p (expr
, type
))
2594 if (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)
2595 && tree_int_cst_sgn (expr
) < 0)
2598 warning_at (loc
, OPT_Wsign_conversion
, "negative integer"
2599 " implicitly converted to unsigned type");
2601 else if (!TYPE_UNSIGNED (type
) && TYPE_UNSIGNED (expr_type
))
2604 warning_at (loc
, OPT_Wsign_conversion
, "conversion of unsigned"
2605 " constant value to negative integer");
2608 give_warning
= UNSAFE_OTHER
;
2610 else if (TREE_CODE (type
) == REAL_TYPE
)
2612 /* Warn for an integer constant that does not fit into real type. */
2613 if (TREE_CODE (expr_type
) == INTEGER_TYPE
)
2615 REAL_VALUE_TYPE a
= real_value_from_int_cst (0, expr
);
2616 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2617 give_warning
= UNSAFE_REAL
;
2619 /* Warn for a real constant that does not fit into a smaller
2621 else if (TREE_CODE (expr_type
) == REAL_TYPE
2622 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2624 REAL_VALUE_TYPE a
= TREE_REAL_CST (expr
);
2625 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2626 give_warning
= UNSAFE_REAL
;
2632 /* Warn for real types converted to integer types. */
2633 if (TREE_CODE (expr_type
) == REAL_TYPE
2634 && TREE_CODE (type
) == INTEGER_TYPE
)
2635 give_warning
= UNSAFE_REAL
;
2637 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2638 && TREE_CODE (type
) == INTEGER_TYPE
)
2640 /* Don't warn about unsigned char y = 0xff, x = (int) y; */
2641 expr
= get_unwidened (expr
, 0);
2642 expr_type
= TREE_TYPE (expr
);
2644 /* Don't warn for short y; short x = ((int)y & 0xff); */
2645 if (TREE_CODE (expr
) == BIT_AND_EXPR
2646 || TREE_CODE (expr
) == BIT_IOR_EXPR
2647 || TREE_CODE (expr
) == BIT_XOR_EXPR
)
2649 /* If both args were extended from a shortest type,
2650 use that type if that is safe. */
2651 expr_type
= shorten_binary_op (expr_type
,
2652 TREE_OPERAND (expr
, 0),
2653 TREE_OPERAND (expr
, 1),
2656 if (TREE_CODE (expr
) == BIT_AND_EXPR
)
2658 tree op0
= TREE_OPERAND (expr
, 0);
2659 tree op1
= TREE_OPERAND (expr
, 1);
2660 bool unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2661 bool unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2663 /* If one of the operands is a non-negative constant
2664 that fits in the target type, then the type of the
2665 other operand does not matter. */
2666 if ((TREE_CODE (op0
) == INTEGER_CST
2667 && int_fits_type_p (op0
, c_common_signed_type (type
))
2668 && int_fits_type_p (op0
, c_common_unsigned_type (type
)))
2669 || (TREE_CODE (op1
) == INTEGER_CST
2670 && int_fits_type_p (op1
, c_common_signed_type (type
))
2671 && int_fits_type_p (op1
,
2672 c_common_unsigned_type (type
))))
2673 return SAFE_CONVERSION
;
2674 /* If constant is unsigned and fits in the target
2675 type, then the result will also fit. */
2676 else if ((TREE_CODE (op0
) == INTEGER_CST
2678 && int_fits_type_p (op0
, type
))
2679 || (TREE_CODE (op1
) == INTEGER_CST
2681 && int_fits_type_p (op1
, type
)))
2682 return SAFE_CONVERSION
;
2685 /* Warn for integer types converted to smaller integer types. */
2686 if (TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2687 give_warning
= UNSAFE_OTHER
;
2689 /* When they are the same width but different signedness,
2690 then the value may change. */
2691 else if (((TYPE_PRECISION (type
) == TYPE_PRECISION (expr_type
)
2692 && TYPE_UNSIGNED (expr_type
) != TYPE_UNSIGNED (type
))
2693 /* Even when converted to a bigger type, if the type is
2694 unsigned but expr is signed, then negative values
2696 || (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)))
2698 warning_at (loc
, OPT_Wsign_conversion
, "conversion to %qT from %qT "
2699 "may change the sign of the result",
2703 /* Warn for integer types converted to real types if and only if
2704 all the range of values of the integer type cannot be
2705 represented by the real type. */
2706 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2707 && TREE_CODE (type
) == REAL_TYPE
)
2709 tree type_low_bound
, type_high_bound
;
2710 REAL_VALUE_TYPE real_low_bound
, real_high_bound
;
2712 /* Don't warn about char y = 0xff; float x = (int) y; */
2713 expr
= get_unwidened (expr
, 0);
2714 expr_type
= TREE_TYPE (expr
);
2716 type_low_bound
= TYPE_MIN_VALUE (expr_type
);
2717 type_high_bound
= TYPE_MAX_VALUE (expr_type
);
2718 real_low_bound
= real_value_from_int_cst (0, type_low_bound
);
2719 real_high_bound
= real_value_from_int_cst (0, type_high_bound
);
2721 if (!exact_real_truncate (TYPE_MODE (type
), &real_low_bound
)
2722 || !exact_real_truncate (TYPE_MODE (type
), &real_high_bound
))
2723 give_warning
= UNSAFE_OTHER
;
2726 /* Warn for real types converted to smaller real types. */
2727 else if (TREE_CODE (expr_type
) == REAL_TYPE
2728 && TREE_CODE (type
) == REAL_TYPE
2729 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2730 give_warning
= UNSAFE_REAL
;
2733 return give_warning
;
2736 /* Warns if the conversion of EXPR to TYPE may alter a value.
2737 This is a helper function for warnings_for_convert_and_check. */
2740 conversion_warning (tree type
, tree expr
)
2742 tree expr_type
= TREE_TYPE (expr
);
2743 location_t loc
= EXPR_LOC_OR_LOC (expr
, input_location
);
2744 enum conversion_safety conversion_kind
;
2746 if (!warn_conversion
&& !warn_sign_conversion
&& !warn_float_conversion
)
2749 switch (TREE_CODE (expr
))
2757 case TRUTH_ANDIF_EXPR
:
2758 case TRUTH_ORIF_EXPR
:
2759 case TRUTH_AND_EXPR
:
2761 case TRUTH_XOR_EXPR
:
2762 case TRUTH_NOT_EXPR
:
2763 /* Conversion from boolean to a signed:1 bit-field (which only
2764 can hold the values 0 and -1) doesn't lose information - but
2765 it does change the value. */
2766 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
2767 warning_at (loc
, OPT_Wconversion
,
2768 "conversion to %qT from boolean expression", type
);
2773 conversion_kind
= unsafe_conversion_p (type
, expr
, true);
2774 if (conversion_kind
== UNSAFE_REAL
)
2775 warning_at (loc
, OPT_Wfloat_conversion
,
2776 "conversion to %qT alters %qT constant value",
2778 else if (conversion_kind
)
2779 warning_at (loc
, OPT_Wconversion
,
2780 "conversion to %qT alters %qT constant value",
2786 /* In case of COND_EXPR, we do not care about the type of
2787 COND_EXPR, only about the conversion of each operand. */
2788 tree op1
= TREE_OPERAND (expr
, 1);
2789 tree op2
= TREE_OPERAND (expr
, 2);
2791 conversion_warning (type
, op1
);
2792 conversion_warning (type
, op2
);
2796 default: /* 'expr' is not a constant. */
2797 conversion_kind
= unsafe_conversion_p (type
, expr
, true);
2798 if (conversion_kind
== UNSAFE_REAL
)
2799 warning_at (loc
, OPT_Wfloat_conversion
,
2800 "conversion to %qT from %qT may alter its value",
2802 else if (conversion_kind
)
2803 warning_at (loc
, OPT_Wconversion
,
2804 "conversion to %qT from %qT may alter its value",
2809 /* Produce warnings after a conversion. RESULT is the result of
2810 converting EXPR to TYPE. This is a helper function for
2811 convert_and_check and cp_convert_and_check. */
2814 warnings_for_convert_and_check (tree type
, tree expr
, tree result
)
2816 location_t loc
= EXPR_LOC_OR_LOC (expr
, input_location
);
2818 if (TREE_CODE (expr
) == INTEGER_CST
2819 && (TREE_CODE (type
) == INTEGER_TYPE
2820 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2821 && !int_fits_type_p (expr
, type
))
2823 /* Do not diagnose overflow in a constant expression merely
2824 because a conversion overflowed. */
2825 if (TREE_OVERFLOW (result
))
2826 TREE_OVERFLOW (result
) = TREE_OVERFLOW (expr
);
2828 if (TYPE_UNSIGNED (type
))
2830 /* This detects cases like converting -129 or 256 to
2832 if (!int_fits_type_p (expr
, c_common_signed_type (type
)))
2833 warning_at (loc
, OPT_Woverflow
,
2834 "large integer implicitly truncated to unsigned type");
2836 conversion_warning (type
, expr
);
2838 else if (!int_fits_type_p (expr
, c_common_unsigned_type (type
)))
2839 warning (OPT_Woverflow
,
2840 "overflow in implicit constant conversion");
2841 /* No warning for converting 0x80000000 to int. */
2843 && (TREE_CODE (TREE_TYPE (expr
)) != INTEGER_TYPE
2844 || TYPE_PRECISION (TREE_TYPE (expr
))
2845 != TYPE_PRECISION (type
)))
2846 warning_at (loc
, OPT_Woverflow
,
2847 "overflow in implicit constant conversion");
2850 conversion_warning (type
, expr
);
2852 else if ((TREE_CODE (result
) == INTEGER_CST
2853 || TREE_CODE (result
) == FIXED_CST
) && TREE_OVERFLOW (result
))
2854 warning_at (loc
, OPT_Woverflow
,
2855 "overflow in implicit constant conversion");
2857 conversion_warning (type
, expr
);
2861 /* Convert EXPR to TYPE, warning about conversion problems with constants.
2862 Invoke this function on every expression that is converted implicitly,
2863 i.e. because of language rules and not because of an explicit cast. */
2866 convert_and_check (tree type
, tree expr
)
2869 tree expr_for_warning
;
2871 /* Convert from a value with possible excess precision rather than
2872 via the semantic type, but do not warn about values not fitting
2873 exactly in the semantic type. */
2874 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
2876 tree orig_type
= TREE_TYPE (expr
);
2877 expr
= TREE_OPERAND (expr
, 0);
2878 expr_for_warning
= convert (orig_type
, expr
);
2879 if (orig_type
== type
)
2880 return expr_for_warning
;
2883 expr_for_warning
= expr
;
2885 if (TREE_TYPE (expr
) == type
)
2888 result
= convert (type
, expr
);
2890 if (c_inhibit_evaluation_warnings
== 0
2891 && !TREE_OVERFLOW_P (expr
)
2892 && result
!= error_mark_node
)
2893 warnings_for_convert_and_check (type
, expr_for_warning
, result
);
2898 /* A node in a list that describes references to variables (EXPR), which are
2899 either read accesses if WRITER is zero, or write accesses, in which case
2900 WRITER is the parent of EXPR. */
2907 /* Used to implement a cache the results of a call to verify_tree. We only
2908 use this for SAVE_EXPRs. */
2911 struct tlist_cache
*next
;
2912 struct tlist
*cache_before_sp
;
2913 struct tlist
*cache_after_sp
;
2917 /* Obstack to use when allocating tlist structures, and corresponding
2919 static struct obstack tlist_obstack
;
2920 static char *tlist_firstobj
= 0;
2922 /* Keep track of the identifiers we've warned about, so we can avoid duplicate
2924 static struct tlist
*warned_ids
;
2925 /* SAVE_EXPRs need special treatment. We process them only once and then
2926 cache the results. */
2927 static struct tlist_cache
*save_expr_cache
;
2929 static void add_tlist (struct tlist
**, struct tlist
*, tree
, int);
2930 static void merge_tlist (struct tlist
**, struct tlist
*, int);
2931 static void verify_tree (tree
, struct tlist
**, struct tlist
**, tree
);
2932 static int warning_candidate_p (tree
);
2933 static bool candidate_equal_p (const_tree
, const_tree
);
2934 static void warn_for_collisions (struct tlist
*);
2935 static void warn_for_collisions_1 (tree
, tree
, struct tlist
*, int);
2936 static struct tlist
*new_tlist (struct tlist
*, tree
, tree
);
2938 /* Create a new struct tlist and fill in its fields. */
2939 static struct tlist
*
2940 new_tlist (struct tlist
*next
, tree t
, tree writer
)
2943 l
= XOBNEW (&tlist_obstack
, struct tlist
);
2950 /* Add duplicates of the nodes found in ADD to the list *TO. If EXCLUDE_WRITER
2951 is nonnull, we ignore any node we find which has a writer equal to it. */
2954 add_tlist (struct tlist
**to
, struct tlist
*add
, tree exclude_writer
, int copy
)
2958 struct tlist
*next
= add
->next
;
2961 if (!exclude_writer
|| !candidate_equal_p (add
->writer
, exclude_writer
))
2962 *to
= copy
? new_tlist (*to
, add
->expr
, add
->writer
) : add
;
2967 /* Merge the nodes of ADD into TO. This merging process is done so that for
2968 each variable that already exists in TO, no new node is added; however if
2969 there is a write access recorded in ADD, and an occurrence on TO is only
2970 a read access, then the occurrence in TO will be modified to record the
2974 merge_tlist (struct tlist
**to
, struct tlist
*add
, int copy
)
2976 struct tlist
**end
= to
;
2979 end
= &(*end
)->next
;
2985 struct tlist
*next
= add
->next
;
2987 for (tmp2
= *to
; tmp2
; tmp2
= tmp2
->next
)
2988 if (candidate_equal_p (tmp2
->expr
, add
->expr
))
2992 tmp2
->writer
= add
->writer
;
2996 *end
= copy
? add
: new_tlist (NULL
, add
->expr
, add
->writer
);
2997 end
= &(*end
)->next
;
3004 /* WRITTEN is a variable, WRITER is its parent. Warn if any of the variable
3005 references in list LIST conflict with it, excluding reads if ONLY writers
3009 warn_for_collisions_1 (tree written
, tree writer
, struct tlist
*list
,
3014 /* Avoid duplicate warnings. */
3015 for (tmp
= warned_ids
; tmp
; tmp
= tmp
->next
)
3016 if (candidate_equal_p (tmp
->expr
, written
))
3021 if (candidate_equal_p (list
->expr
, written
)
3022 && !candidate_equal_p (list
->writer
, writer
)
3023 && (!only_writes
|| list
->writer
))
3025 warned_ids
= new_tlist (warned_ids
, written
, NULL_TREE
);
3026 warning_at (EXPR_LOC_OR_LOC (writer
, input_location
),
3027 OPT_Wsequence_point
, "operation on %qE may be undefined",
3034 /* Given a list LIST of references to variables, find whether any of these
3035 can cause conflicts due to missing sequence points. */
3038 warn_for_collisions (struct tlist
*list
)
3042 for (tmp
= list
; tmp
; tmp
= tmp
->next
)
3045 warn_for_collisions_1 (tmp
->expr
, tmp
->writer
, list
, 0);
3049 /* Return nonzero if X is a tree that can be verified by the sequence point
3052 warning_candidate_p (tree x
)
3054 if (DECL_P (x
) && DECL_ARTIFICIAL (x
))
3057 if (TREE_CODE (x
) == BLOCK
)
3060 /* VOID_TYPE_P (TREE_TYPE (x)) is workaround for cp/tree.c
3061 (lvalue_p) crash on TRY/CATCH. */
3062 if (TREE_TYPE (x
) == NULL_TREE
|| VOID_TYPE_P (TREE_TYPE (x
)))
3068 /* No point to track non-const calls, they will never satisfy
3070 if (TREE_CODE (x
) == CALL_EXPR
&& (call_expr_flags (x
) & ECF_CONST
) == 0)
3073 if (TREE_CODE (x
) == STRING_CST
)
3079 /* Return nonzero if X and Y appear to be the same candidate (or NULL) */
3081 candidate_equal_p (const_tree x
, const_tree y
)
3083 return (x
== y
) || (x
&& y
&& operand_equal_p (x
, y
, 0));
3086 /* Walk the tree X, and record accesses to variables. If X is written by the
3087 parent tree, WRITER is the parent.
3088 We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP. If this
3089 expression or its only operand forces a sequence point, then everything up
3090 to the sequence point is stored in PBEFORE_SP. Everything else gets stored
3092 Once we return, we will have emitted warnings if any subexpression before
3093 such a sequence point could be undefined. On a higher level, however, the
3094 sequence point may not be relevant, and we'll merge the two lists.
3096 Example: (b++, a) + b;
3097 The call that processes the COMPOUND_EXPR will store the increment of B
3098 in PBEFORE_SP, and the use of A in PNO_SP. The higher-level call that
3099 processes the PLUS_EXPR will need to merge the two lists so that
3100 eventually, all accesses end up on the same list (and we'll warn about the
3101 unordered subexpressions b++ and b.
3103 A note on merging. If we modify the former example so that our expression
3106 care must be taken not simply to add all three expressions into the final
3107 PNO_SP list. The function merge_tlist takes care of that by merging the
3108 before-SP list of the COMPOUND_EXPR into its after-SP list in a special
3109 way, so that no more than one access to B is recorded. */
3112 verify_tree (tree x
, struct tlist
**pbefore_sp
, struct tlist
**pno_sp
,
3115 struct tlist
*tmp_before
, *tmp_nosp
, *tmp_list2
, *tmp_list3
;
3116 enum tree_code code
;
3117 enum tree_code_class cl
;
3119 /* X may be NULL if it is the operand of an empty statement expression
3125 code
= TREE_CODE (x
);
3126 cl
= TREE_CODE_CLASS (code
);
3128 if (warning_candidate_p (x
))
3129 *pno_sp
= new_tlist (*pno_sp
, x
, writer
);
3138 case TRUTH_ANDIF_EXPR
:
3139 case TRUTH_ORIF_EXPR
:
3140 tmp_before
= tmp_nosp
= tmp_list3
= 0;
3141 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3142 warn_for_collisions (tmp_nosp
);
3143 merge_tlist (pbefore_sp
, tmp_before
, 0);
3144 merge_tlist (pbefore_sp
, tmp_nosp
, 0);
3145 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, pno_sp
, NULL_TREE
);
3146 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3150 tmp_before
= tmp_list2
= 0;
3151 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_list2
, NULL_TREE
);
3152 warn_for_collisions (tmp_list2
);
3153 merge_tlist (pbefore_sp
, tmp_before
, 0);
3154 merge_tlist (pbefore_sp
, tmp_list2
, 1);
3156 tmp_list3
= tmp_nosp
= 0;
3157 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, &tmp_nosp
, NULL_TREE
);
3158 warn_for_collisions (tmp_nosp
);
3159 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3161 tmp_list3
= tmp_list2
= 0;
3162 verify_tree (TREE_OPERAND (x
, 2), &tmp_list3
, &tmp_list2
, NULL_TREE
);
3163 warn_for_collisions (tmp_list2
);
3164 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3165 /* Rather than add both tmp_nosp and tmp_list2, we have to merge the
3166 two first, to avoid warning for (a ? b++ : b++). */
3167 merge_tlist (&tmp_nosp
, tmp_list2
, 0);
3168 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3171 case PREDECREMENT_EXPR
:
3172 case PREINCREMENT_EXPR
:
3173 case POSTDECREMENT_EXPR
:
3174 case POSTINCREMENT_EXPR
:
3175 verify_tree (TREE_OPERAND (x
, 0), pno_sp
, pno_sp
, x
);
3179 tmp_before
= tmp_nosp
= tmp_list3
= 0;
3180 verify_tree (TREE_OPERAND (x
, 1), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3181 verify_tree (TREE_OPERAND (x
, 0), &tmp_list3
, &tmp_list3
, x
);
3182 /* Expressions inside the LHS are not ordered wrt. the sequence points
3183 in the RHS. Example:
3185 Despite the fact that the modification of "a" is in the before_sp
3186 list (tmp_before), it conflicts with the use of "a" in the LHS.
3187 We can handle this by adding the contents of tmp_list3
3188 to those of tmp_before, and redoing the collision warnings for that
3190 add_tlist (&tmp_before
, tmp_list3
, x
, 1);
3191 warn_for_collisions (tmp_before
);
3192 /* Exclude the LHS itself here; we first have to merge it into the
3193 tmp_nosp list. This is done to avoid warning for "a = a"; if we
3194 didn't exclude the LHS, we'd get it twice, once as a read and once
3196 add_tlist (pno_sp
, tmp_list3
, x
, 0);
3197 warn_for_collisions_1 (TREE_OPERAND (x
, 0), x
, tmp_nosp
, 1);
3199 merge_tlist (pbefore_sp
, tmp_before
, 0);
3200 if (warning_candidate_p (TREE_OPERAND (x
, 0)))
3201 merge_tlist (&tmp_nosp
, new_tlist (NULL
, TREE_OPERAND (x
, 0), x
), 0);
3202 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 1);
3206 /* We need to warn about conflicts among arguments and conflicts between
3207 args and the function address. Side effects of the function address,
3208 however, are not ordered by the sequence point of the call. */
3210 call_expr_arg_iterator iter
;
3212 tmp_before
= tmp_nosp
= 0;
3213 verify_tree (CALL_EXPR_FN (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3214 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, x
)
3216 tmp_list2
= tmp_list3
= 0;
3217 verify_tree (arg
, &tmp_list2
, &tmp_list3
, NULL_TREE
);
3218 merge_tlist (&tmp_list3
, tmp_list2
, 0);
3219 add_tlist (&tmp_before
, tmp_list3
, NULL_TREE
, 0);
3221 add_tlist (&tmp_before
, tmp_nosp
, NULL_TREE
, 0);
3222 warn_for_collisions (tmp_before
);
3223 add_tlist (pbefore_sp
, tmp_before
, NULL_TREE
, 0);
3228 /* Scan all the list, e.g. indices of multi dimensional array. */
3231 tmp_before
= tmp_nosp
= 0;
3232 verify_tree (TREE_VALUE (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3233 merge_tlist (&tmp_nosp
, tmp_before
, 0);
3234 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3241 struct tlist_cache
*t
;
3242 for (t
= save_expr_cache
; t
; t
= t
->next
)
3243 if (candidate_equal_p (t
->expr
, x
))
3248 t
= XOBNEW (&tlist_obstack
, struct tlist_cache
);
3249 t
->next
= save_expr_cache
;
3251 save_expr_cache
= t
;
3253 tmp_before
= tmp_nosp
= 0;
3254 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3255 warn_for_collisions (tmp_nosp
);
3260 struct tlist
*t
= tmp_nosp
;
3262 merge_tlist (&tmp_list3
, t
, 0);
3264 t
->cache_before_sp
= tmp_before
;
3265 t
->cache_after_sp
= tmp_list3
;
3267 merge_tlist (pbefore_sp
, t
->cache_before_sp
, 1);
3268 add_tlist (pno_sp
, t
->cache_after_sp
, NULL_TREE
, 1);
3273 x
= TREE_OPERAND (x
, 0);
3280 /* For other expressions, simply recurse on their operands.
3281 Manual tail recursion for unary expressions.
3282 Other non-expressions need not be processed. */
3283 if (cl
== tcc_unary
)
3285 x
= TREE_OPERAND (x
, 0);
3289 else if (IS_EXPR_CODE_CLASS (cl
))
3292 int max
= TREE_OPERAND_LENGTH (x
);
3293 for (lp
= 0; lp
< max
; lp
++)
3295 tmp_before
= tmp_nosp
= 0;
3296 verify_tree (TREE_OPERAND (x
, lp
), &tmp_before
, &tmp_nosp
, 0);
3297 merge_tlist (&tmp_nosp
, tmp_before
, 0);
3298 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3305 /* Try to warn for undefined behavior in EXPR due to missing sequence
3309 verify_sequence_points (tree expr
)
3311 struct tlist
*before_sp
= 0, *after_sp
= 0;
3314 save_expr_cache
= 0;
3315 if (tlist_firstobj
== 0)
3317 gcc_obstack_init (&tlist_obstack
);
3318 tlist_firstobj
= (char *) obstack_alloc (&tlist_obstack
, 0);
3321 verify_tree (expr
, &before_sp
, &after_sp
, 0);
3322 warn_for_collisions (after_sp
);
3323 obstack_free (&tlist_obstack
, tlist_firstobj
);
3326 /* Validate the expression after `case' and apply default promotions. */
3329 check_case_value (tree value
)
3331 if (value
== NULL_TREE
)
3334 if (TREE_CODE (value
) == INTEGER_CST
)
3335 /* Promote char or short to int. */
3336 value
= perform_integral_promotions (value
);
3337 else if (value
!= error_mark_node
)
3339 error ("case label does not reduce to an integer constant");
3340 value
= error_mark_node
;
3343 constant_expression_warning (value
);
3348 /* See if the case values LOW and HIGH are in the range of the original
3349 type (i.e. before the default conversion to int) of the switch testing
3351 TYPE is the promoted type of the testing expression, and ORIG_TYPE is
3352 the type before promoting it. CASE_LOW_P is a pointer to the lower
3353 bound of the case label, and CASE_HIGH_P is the upper bound or NULL
3354 if the case is not a case range.
3355 The caller has to make sure that we are not called with NULL for
3356 CASE_LOW_P (i.e. the default case).
3357 Returns true if the case label is in range of ORIG_TYPE (saturated or
3358 untouched) or false if the label is out of range. */
3361 check_case_bounds (tree type
, tree orig_type
,
3362 tree
*case_low_p
, tree
*case_high_p
)
3364 tree min_value
, max_value
;
3365 tree case_low
= *case_low_p
;
3366 tree case_high
= case_high_p
? *case_high_p
: case_low
;
3368 /* If there was a problem with the original type, do nothing. */
3369 if (orig_type
== error_mark_node
)
3372 min_value
= TYPE_MIN_VALUE (orig_type
);
3373 max_value
= TYPE_MAX_VALUE (orig_type
);
3375 /* Case label is less than minimum for type. */
3376 if (tree_int_cst_compare (case_low
, min_value
) < 0
3377 && tree_int_cst_compare (case_high
, min_value
) < 0)
3379 warning (0, "case label value is less than minimum value for type");
3383 /* Case value is greater than maximum for type. */
3384 if (tree_int_cst_compare (case_low
, max_value
) > 0
3385 && tree_int_cst_compare (case_high
, max_value
) > 0)
3387 warning (0, "case label value exceeds maximum value for type");
3391 /* Saturate lower case label value to minimum. */
3392 if (tree_int_cst_compare (case_high
, min_value
) >= 0
3393 && tree_int_cst_compare (case_low
, min_value
) < 0)
3395 warning (0, "lower value in case label range"
3396 " less than minimum value for type");
3397 case_low
= min_value
;
3400 /* Saturate upper case label value to maximum. */
3401 if (tree_int_cst_compare (case_low
, max_value
) <= 0
3402 && tree_int_cst_compare (case_high
, max_value
) > 0)
3404 warning (0, "upper value in case label range"
3405 " exceeds maximum value for type");
3406 case_high
= max_value
;
3409 if (*case_low_p
!= case_low
)
3410 *case_low_p
= convert (type
, case_low
);
3411 if (case_high_p
&& *case_high_p
!= case_high
)
3412 *case_high_p
= convert (type
, case_high
);
3417 /* Return an integer type with BITS bits of precision,
3418 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
3421 c_common_type_for_size (unsigned int bits
, int unsignedp
)
3423 if (bits
== TYPE_PRECISION (integer_type_node
))
3424 return unsignedp
? unsigned_type_node
: integer_type_node
;
3426 if (bits
== TYPE_PRECISION (signed_char_type_node
))
3427 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3429 if (bits
== TYPE_PRECISION (short_integer_type_node
))
3430 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3432 if (bits
== TYPE_PRECISION (long_integer_type_node
))
3433 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3435 if (bits
== TYPE_PRECISION (long_long_integer_type_node
))
3436 return (unsignedp
? long_long_unsigned_type_node
3437 : long_long_integer_type_node
);
3439 if (int128_integer_type_node
3440 && bits
== TYPE_PRECISION (int128_integer_type_node
))
3441 return (unsignedp
? int128_unsigned_type_node
3442 : int128_integer_type_node
);
3444 if (bits
== TYPE_PRECISION (widest_integer_literal_type_node
))
3445 return (unsignedp
? widest_unsigned_literal_type_node
3446 : widest_integer_literal_type_node
);
3448 if (bits
<= TYPE_PRECISION (intQI_type_node
))
3449 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3451 if (bits
<= TYPE_PRECISION (intHI_type_node
))
3452 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3454 if (bits
<= TYPE_PRECISION (intSI_type_node
))
3455 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3457 if (bits
<= TYPE_PRECISION (intDI_type_node
))
3458 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3463 /* Return a fixed-point type that has at least IBIT ibits and FBIT fbits
3464 that is unsigned if UNSIGNEDP is nonzero, otherwise signed;
3465 and saturating if SATP is nonzero, otherwise not saturating. */
3468 c_common_fixed_point_type_for_size (unsigned int ibit
, unsigned int fbit
,
3469 int unsignedp
, int satp
)
3471 enum machine_mode mode
;
3473 mode
= unsignedp
? UQQmode
: QQmode
;
3475 mode
= unsignedp
? UHAmode
: HAmode
;
3477 for (; mode
!= VOIDmode
; mode
= GET_MODE_WIDER_MODE (mode
))
3478 if (GET_MODE_IBIT (mode
) >= ibit
&& GET_MODE_FBIT (mode
) >= fbit
)
3481 if (mode
== VOIDmode
|| !targetm
.scalar_mode_supported_p (mode
))
3483 sorry ("GCC cannot support operators with integer types and "
3484 "fixed-point types that have too many integral and "
3485 "fractional bits together");
3489 return c_common_type_for_mode (mode
, satp
);
3492 /* Used for communication between c_common_type_for_mode and
3493 c_register_builtin_type. */
3494 static GTY(()) tree registered_builtin_types
;
3496 /* Return a data type that has machine mode MODE.
3497 If the mode is an integer,
3498 then UNSIGNEDP selects between signed and unsigned types.
3499 If the mode is a fixed-point mode,
3500 then UNSIGNEDP selects between saturating and nonsaturating types. */
3503 c_common_type_for_mode (enum machine_mode mode
, int unsignedp
)
3507 if (mode
== TYPE_MODE (integer_type_node
))
3508 return unsignedp
? unsigned_type_node
: integer_type_node
;
3510 if (mode
== TYPE_MODE (signed_char_type_node
))
3511 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3513 if (mode
== TYPE_MODE (short_integer_type_node
))
3514 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3516 if (mode
== TYPE_MODE (long_integer_type_node
))
3517 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3519 if (mode
== TYPE_MODE (long_long_integer_type_node
))
3520 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3522 if (int128_integer_type_node
3523 && mode
== TYPE_MODE (int128_integer_type_node
))
3524 return unsignedp
? int128_unsigned_type_node
: int128_integer_type_node
;
3526 if (mode
== TYPE_MODE (widest_integer_literal_type_node
))
3527 return unsignedp
? widest_unsigned_literal_type_node
3528 : widest_integer_literal_type_node
;
3531 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3534 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3537 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3540 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3542 #if HOST_BITS_PER_WIDE_INT >= 64
3543 if (mode
== TYPE_MODE (intTI_type_node
))
3544 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3547 if (mode
== TYPE_MODE (float_type_node
))
3548 return float_type_node
;
3550 if (mode
== TYPE_MODE (double_type_node
))
3551 return double_type_node
;
3553 if (mode
== TYPE_MODE (long_double_type_node
))
3554 return long_double_type_node
;
3556 if (mode
== TYPE_MODE (void_type_node
))
3557 return void_type_node
;
3559 if (mode
== TYPE_MODE (build_pointer_type (char_type_node
)))
3561 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3562 : make_signed_type (GET_MODE_PRECISION (mode
)));
3564 if (mode
== TYPE_MODE (build_pointer_type (integer_type_node
)))
3566 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3567 : make_signed_type (GET_MODE_PRECISION (mode
)));
3569 if (COMPLEX_MODE_P (mode
))
3571 enum machine_mode inner_mode
;
3574 if (mode
== TYPE_MODE (complex_float_type_node
))
3575 return complex_float_type_node
;
3576 if (mode
== TYPE_MODE (complex_double_type_node
))
3577 return complex_double_type_node
;
3578 if (mode
== TYPE_MODE (complex_long_double_type_node
))
3579 return complex_long_double_type_node
;
3581 if (mode
== TYPE_MODE (complex_integer_type_node
) && !unsignedp
)
3582 return complex_integer_type_node
;
3584 inner_mode
= GET_MODE_INNER (mode
);
3585 inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3586 if (inner_type
!= NULL_TREE
)
3587 return build_complex_type (inner_type
);
3589 else if (VECTOR_MODE_P (mode
))
3591 enum machine_mode inner_mode
= GET_MODE_INNER (mode
);
3592 tree inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3593 if (inner_type
!= NULL_TREE
)
3594 return build_vector_type_for_mode (inner_type
, mode
);
3597 if (mode
== TYPE_MODE (dfloat32_type_node
))
3598 return dfloat32_type_node
;
3599 if (mode
== TYPE_MODE (dfloat64_type_node
))
3600 return dfloat64_type_node
;
3601 if (mode
== TYPE_MODE (dfloat128_type_node
))
3602 return dfloat128_type_node
;
3604 if (ALL_SCALAR_FIXED_POINT_MODE_P (mode
))
3606 if (mode
== TYPE_MODE (short_fract_type_node
))
3607 return unsignedp
? sat_short_fract_type_node
: short_fract_type_node
;
3608 if (mode
== TYPE_MODE (fract_type_node
))
3609 return unsignedp
? sat_fract_type_node
: fract_type_node
;
3610 if (mode
== TYPE_MODE (long_fract_type_node
))
3611 return unsignedp
? sat_long_fract_type_node
: long_fract_type_node
;
3612 if (mode
== TYPE_MODE (long_long_fract_type_node
))
3613 return unsignedp
? sat_long_long_fract_type_node
3614 : long_long_fract_type_node
;
3616 if (mode
== TYPE_MODE (unsigned_short_fract_type_node
))
3617 return unsignedp
? sat_unsigned_short_fract_type_node
3618 : unsigned_short_fract_type_node
;
3619 if (mode
== TYPE_MODE (unsigned_fract_type_node
))
3620 return unsignedp
? sat_unsigned_fract_type_node
3621 : unsigned_fract_type_node
;
3622 if (mode
== TYPE_MODE (unsigned_long_fract_type_node
))
3623 return unsignedp
? sat_unsigned_long_fract_type_node
3624 : unsigned_long_fract_type_node
;
3625 if (mode
== TYPE_MODE (unsigned_long_long_fract_type_node
))
3626 return unsignedp
? sat_unsigned_long_long_fract_type_node
3627 : unsigned_long_long_fract_type_node
;
3629 if (mode
== TYPE_MODE (short_accum_type_node
))
3630 return unsignedp
? sat_short_accum_type_node
: short_accum_type_node
;
3631 if (mode
== TYPE_MODE (accum_type_node
))
3632 return unsignedp
? sat_accum_type_node
: accum_type_node
;
3633 if (mode
== TYPE_MODE (long_accum_type_node
))
3634 return unsignedp
? sat_long_accum_type_node
: long_accum_type_node
;
3635 if (mode
== TYPE_MODE (long_long_accum_type_node
))
3636 return unsignedp
? sat_long_long_accum_type_node
3637 : long_long_accum_type_node
;
3639 if (mode
== TYPE_MODE (unsigned_short_accum_type_node
))
3640 return unsignedp
? sat_unsigned_short_accum_type_node
3641 : unsigned_short_accum_type_node
;
3642 if (mode
== TYPE_MODE (unsigned_accum_type_node
))
3643 return unsignedp
? sat_unsigned_accum_type_node
3644 : unsigned_accum_type_node
;
3645 if (mode
== TYPE_MODE (unsigned_long_accum_type_node
))
3646 return unsignedp
? sat_unsigned_long_accum_type_node
3647 : unsigned_long_accum_type_node
;
3648 if (mode
== TYPE_MODE (unsigned_long_long_accum_type_node
))
3649 return unsignedp
? sat_unsigned_long_long_accum_type_node
3650 : unsigned_long_long_accum_type_node
;
3653 return unsignedp
? sat_qq_type_node
: qq_type_node
;
3655 return unsignedp
? sat_hq_type_node
: hq_type_node
;
3657 return unsignedp
? sat_sq_type_node
: sq_type_node
;
3659 return unsignedp
? sat_dq_type_node
: dq_type_node
;
3661 return unsignedp
? sat_tq_type_node
: tq_type_node
;
3663 if (mode
== UQQmode
)
3664 return unsignedp
? sat_uqq_type_node
: uqq_type_node
;
3665 if (mode
== UHQmode
)
3666 return unsignedp
? sat_uhq_type_node
: uhq_type_node
;
3667 if (mode
== USQmode
)
3668 return unsignedp
? sat_usq_type_node
: usq_type_node
;
3669 if (mode
== UDQmode
)
3670 return unsignedp
? sat_udq_type_node
: udq_type_node
;
3671 if (mode
== UTQmode
)
3672 return unsignedp
? sat_utq_type_node
: utq_type_node
;
3675 return unsignedp
? sat_ha_type_node
: ha_type_node
;
3677 return unsignedp
? sat_sa_type_node
: sa_type_node
;
3679 return unsignedp
? sat_da_type_node
: da_type_node
;
3681 return unsignedp
? sat_ta_type_node
: ta_type_node
;
3683 if (mode
== UHAmode
)
3684 return unsignedp
? sat_uha_type_node
: uha_type_node
;
3685 if (mode
== USAmode
)
3686 return unsignedp
? sat_usa_type_node
: usa_type_node
;
3687 if (mode
== UDAmode
)
3688 return unsignedp
? sat_uda_type_node
: uda_type_node
;
3689 if (mode
== UTAmode
)
3690 return unsignedp
? sat_uta_type_node
: uta_type_node
;
3693 for (t
= registered_builtin_types
; t
; t
= TREE_CHAIN (t
))
3694 if (TYPE_MODE (TREE_VALUE (t
)) == mode
3695 && !!unsignedp
== !!TYPE_UNSIGNED (TREE_VALUE (t
)))
3696 return TREE_VALUE (t
);
3702 c_common_unsigned_type (tree type
)
3704 return c_common_signed_or_unsigned_type (1, type
);
3707 /* Return a signed type the same as TYPE in other respects. */
3710 c_common_signed_type (tree type
)
3712 return c_common_signed_or_unsigned_type (0, type
);
3715 /* Return a type the same as TYPE except unsigned or
3716 signed according to UNSIGNEDP. */
3719 c_common_signed_or_unsigned_type (int unsignedp
, tree type
)
3723 /* This block of code emulates the behavior of the old
3724 c_common_unsigned_type. In particular, it returns
3725 long_unsigned_type_node if passed a long, even when a int would
3726 have the same size. This is necessary for warnings to work
3727 correctly in archs where sizeof(int) == sizeof(long) */
3729 type1
= TYPE_MAIN_VARIANT (type
);
3730 if (type1
== signed_char_type_node
|| type1
== char_type_node
|| type1
== unsigned_char_type_node
)
3731 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3732 if (type1
== integer_type_node
|| type1
== unsigned_type_node
)
3733 return unsignedp
? unsigned_type_node
: integer_type_node
;
3734 if (type1
== short_integer_type_node
|| type1
== short_unsigned_type_node
)
3735 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3736 if (type1
== long_integer_type_node
|| type1
== long_unsigned_type_node
)
3737 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3738 if (type1
== long_long_integer_type_node
|| type1
== long_long_unsigned_type_node
)
3739 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3740 if (int128_integer_type_node
3741 && (type1
== int128_integer_type_node
3742 || type1
== int128_unsigned_type_node
))
3743 return unsignedp
? int128_unsigned_type_node
: int128_integer_type_node
;
3744 if (type1
== widest_integer_literal_type_node
|| type1
== widest_unsigned_literal_type_node
)
3745 return unsignedp
? widest_unsigned_literal_type_node
: widest_integer_literal_type_node
;
3746 #if HOST_BITS_PER_WIDE_INT >= 64
3747 if (type1
== intTI_type_node
|| type1
== unsigned_intTI_type_node
)
3748 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3750 if (type1
== intDI_type_node
|| type1
== unsigned_intDI_type_node
)
3751 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3752 if (type1
== intSI_type_node
|| type1
== unsigned_intSI_type_node
)
3753 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3754 if (type1
== intHI_type_node
|| type1
== unsigned_intHI_type_node
)
3755 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3756 if (type1
== intQI_type_node
|| type1
== unsigned_intQI_type_node
)
3757 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3759 #define C_COMMON_FIXED_TYPES(NAME) \
3760 if (type1 == short_ ## NAME ## _type_node \
3761 || type1 == unsigned_short_ ## NAME ## _type_node) \
3762 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
3763 : short_ ## NAME ## _type_node; \
3764 if (type1 == NAME ## _type_node \
3765 || type1 == unsigned_ ## NAME ## _type_node) \
3766 return unsignedp ? unsigned_ ## NAME ## _type_node \
3767 : NAME ## _type_node; \
3768 if (type1 == long_ ## NAME ## _type_node \
3769 || type1 == unsigned_long_ ## NAME ## _type_node) \
3770 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
3771 : long_ ## NAME ## _type_node; \
3772 if (type1 == long_long_ ## NAME ## _type_node \
3773 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
3774 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
3775 : long_long_ ## NAME ## _type_node;
3777 #define C_COMMON_FIXED_MODE_TYPES(NAME) \
3778 if (type1 == NAME ## _type_node \
3779 || type1 == u ## NAME ## _type_node) \
3780 return unsignedp ? u ## NAME ## _type_node \
3781 : NAME ## _type_node;
3783 #define C_COMMON_FIXED_TYPES_SAT(NAME) \
3784 if (type1 == sat_ ## short_ ## NAME ## _type_node \
3785 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
3786 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
3787 : sat_ ## short_ ## NAME ## _type_node; \
3788 if (type1 == sat_ ## NAME ## _type_node \
3789 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
3790 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
3791 : sat_ ## NAME ## _type_node; \
3792 if (type1 == sat_ ## long_ ## NAME ## _type_node \
3793 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
3794 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
3795 : sat_ ## long_ ## NAME ## _type_node; \
3796 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
3797 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
3798 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
3799 : sat_ ## long_long_ ## NAME ## _type_node;
3801 #define C_COMMON_FIXED_MODE_TYPES_SAT(NAME) \
3802 if (type1 == sat_ ## NAME ## _type_node \
3803 || type1 == sat_ ## u ## NAME ## _type_node) \
3804 return unsignedp ? sat_ ## u ## NAME ## _type_node \
3805 : sat_ ## NAME ## _type_node;
3807 C_COMMON_FIXED_TYPES (fract
);
3808 C_COMMON_FIXED_TYPES_SAT (fract
);
3809 C_COMMON_FIXED_TYPES (accum
);
3810 C_COMMON_FIXED_TYPES_SAT (accum
);
3812 C_COMMON_FIXED_MODE_TYPES (qq
);
3813 C_COMMON_FIXED_MODE_TYPES (hq
);
3814 C_COMMON_FIXED_MODE_TYPES (sq
);
3815 C_COMMON_FIXED_MODE_TYPES (dq
);
3816 C_COMMON_FIXED_MODE_TYPES (tq
);
3817 C_COMMON_FIXED_MODE_TYPES_SAT (qq
);
3818 C_COMMON_FIXED_MODE_TYPES_SAT (hq
);
3819 C_COMMON_FIXED_MODE_TYPES_SAT (sq
);
3820 C_COMMON_FIXED_MODE_TYPES_SAT (dq
);
3821 C_COMMON_FIXED_MODE_TYPES_SAT (tq
);
3822 C_COMMON_FIXED_MODE_TYPES (ha
);
3823 C_COMMON_FIXED_MODE_TYPES (sa
);
3824 C_COMMON_FIXED_MODE_TYPES (da
);
3825 C_COMMON_FIXED_MODE_TYPES (ta
);
3826 C_COMMON_FIXED_MODE_TYPES_SAT (ha
);
3827 C_COMMON_FIXED_MODE_TYPES_SAT (sa
);
3828 C_COMMON_FIXED_MODE_TYPES_SAT (da
);
3829 C_COMMON_FIXED_MODE_TYPES_SAT (ta
);
3831 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
3832 the precision; they have precision set to match their range, but
3833 may use a wider mode to match an ABI. If we change modes, we may
3834 wind up with bad conversions. For INTEGER_TYPEs in C, must check
3835 the precision as well, so as to yield correct results for
3836 bit-field types. C++ does not have these separate bit-field
3837 types, and producing a signed or unsigned variant of an
3838 ENUMERAL_TYPE may cause other problems as well. */
3840 if (!INTEGRAL_TYPE_P (type
)
3841 || TYPE_UNSIGNED (type
) == unsignedp
)
3844 #define TYPE_OK(node) \
3845 (TYPE_MODE (type) == TYPE_MODE (node) \
3846 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
3847 if (TYPE_OK (signed_char_type_node
))
3848 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3849 if (TYPE_OK (integer_type_node
))
3850 return unsignedp
? unsigned_type_node
: integer_type_node
;
3851 if (TYPE_OK (short_integer_type_node
))
3852 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3853 if (TYPE_OK (long_integer_type_node
))
3854 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3855 if (TYPE_OK (long_long_integer_type_node
))
3856 return (unsignedp
? long_long_unsigned_type_node
3857 : long_long_integer_type_node
);
3858 if (int128_integer_type_node
&& TYPE_OK (int128_integer_type_node
))
3859 return (unsignedp
? int128_unsigned_type_node
3860 : int128_integer_type_node
);
3861 if (TYPE_OK (widest_integer_literal_type_node
))
3862 return (unsignedp
? widest_unsigned_literal_type_node
3863 : widest_integer_literal_type_node
);
3865 #if HOST_BITS_PER_WIDE_INT >= 64
3866 if (TYPE_OK (intTI_type_node
))
3867 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3869 if (TYPE_OK (intDI_type_node
))
3870 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3871 if (TYPE_OK (intSI_type_node
))
3872 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3873 if (TYPE_OK (intHI_type_node
))
3874 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3875 if (TYPE_OK (intQI_type_node
))
3876 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3879 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
3882 /* Build a bit-field integer type for the given WIDTH and UNSIGNEDP. */
3885 c_build_bitfield_integer_type (unsigned HOST_WIDE_INT width
, int unsignedp
)
3887 /* Extended integer types of the same width as a standard type have
3888 lesser rank, so those of the same width as int promote to int or
3889 unsigned int and are valid for printf formats expecting int or
3890 unsigned int. To avoid such special cases, avoid creating
3891 extended integer types for bit-fields if a standard integer type
3893 if (width
== TYPE_PRECISION (integer_type_node
))
3894 return unsignedp
? unsigned_type_node
: integer_type_node
;
3895 if (width
== TYPE_PRECISION (signed_char_type_node
))
3896 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3897 if (width
== TYPE_PRECISION (short_integer_type_node
))
3898 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3899 if (width
== TYPE_PRECISION (long_integer_type_node
))
3900 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3901 if (width
== TYPE_PRECISION (long_long_integer_type_node
))
3902 return (unsignedp
? long_long_unsigned_type_node
3903 : long_long_integer_type_node
);
3904 if (int128_integer_type_node
3905 && width
== TYPE_PRECISION (int128_integer_type_node
))
3906 return (unsignedp
? int128_unsigned_type_node
3907 : int128_integer_type_node
);
3908 return build_nonstandard_integer_type (width
, unsignedp
);
3911 /* The C version of the register_builtin_type langhook. */
3914 c_register_builtin_type (tree type
, const char* name
)
3918 decl
= build_decl (UNKNOWN_LOCATION
,
3919 TYPE_DECL
, get_identifier (name
), type
);
3920 DECL_ARTIFICIAL (decl
) = 1;
3921 if (!TYPE_NAME (type
))
3922 TYPE_NAME (type
) = decl
;
3925 registered_builtin_types
= tree_cons (0, type
, registered_builtin_types
);
3928 /* Print an error message for invalid operands to arith operation
3929 CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
3930 LOCATION is the location of the message. */
3933 binary_op_error (location_t location
, enum tree_code code
,
3934 tree type0
, tree type1
)
3941 opname
= "+"; break;
3943 opname
= "-"; break;
3945 opname
= "*"; break;
3947 opname
= "max"; break;
3949 opname
= "min"; break;
3951 opname
= "=="; break;
3953 opname
= "!="; break;
3955 opname
= "<="; break;
3957 opname
= ">="; break;
3959 opname
= "<"; break;
3961 opname
= ">"; break;
3963 opname
= "<<"; break;
3965 opname
= ">>"; break;
3966 case TRUNC_MOD_EXPR
:
3967 case FLOOR_MOD_EXPR
:
3968 opname
= "%"; break;
3969 case TRUNC_DIV_EXPR
:
3970 case FLOOR_DIV_EXPR
:
3971 opname
= "/"; break;
3973 opname
= "&"; break;
3975 opname
= "|"; break;
3976 case TRUTH_ANDIF_EXPR
:
3977 opname
= "&&"; break;
3978 case TRUTH_ORIF_EXPR
:
3979 opname
= "||"; break;
3981 opname
= "^"; break;
3986 "invalid operands to binary %s (have %qT and %qT)", opname
,
3990 /* Given an expression as a tree, return its original type. Do this
3991 by stripping any conversion that preserves the sign and precision. */
3993 expr_original_type (tree expr
)
3995 STRIP_SIGN_NOPS (expr
);
3996 return TREE_TYPE (expr
);
3999 /* Subroutine of build_binary_op, used for comparison operations.
4000 See if the operands have both been converted from subword integer types
4001 and, if so, perhaps change them both back to their original type.
4002 This function is also responsible for converting the two operands
4003 to the proper common type for comparison.
4005 The arguments of this function are all pointers to local variables
4006 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
4007 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
4009 If this function returns nonzero, it means that the comparison has
4010 a constant value. What this function returns is an expression for
4014 shorten_compare (tree
*op0_ptr
, tree
*op1_ptr
, tree
*restype_ptr
,
4015 enum tree_code
*rescode_ptr
)
4018 tree op0
= *op0_ptr
;
4019 tree op1
= *op1_ptr
;
4020 int unsignedp0
, unsignedp1
;
4022 tree primop0
, primop1
;
4023 enum tree_code code
= *rescode_ptr
;
4024 location_t loc
= EXPR_LOC_OR_LOC (op0
, input_location
);
4026 /* Throw away any conversions to wider types
4027 already present in the operands. */
4029 primop0
= c_common_get_narrower (op0
, &unsignedp0
);
4030 primop1
= c_common_get_narrower (op1
, &unsignedp1
);
4032 /* If primopN is first sign-extended from primopN's precision to opN's
4033 precision, then zero-extended from opN's precision to
4034 *restype_ptr precision, shortenings might be invalid. */
4035 if (TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (TREE_TYPE (op0
))
4036 && TYPE_PRECISION (TREE_TYPE (op0
)) < TYPE_PRECISION (*restype_ptr
)
4038 && TYPE_UNSIGNED (TREE_TYPE (op0
)))
4040 if (TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (TREE_TYPE (op1
))
4041 && TYPE_PRECISION (TREE_TYPE (op1
)) < TYPE_PRECISION (*restype_ptr
)
4043 && TYPE_UNSIGNED (TREE_TYPE (op1
)))
4046 /* Handle the case that OP0 does not *contain* a conversion
4047 but it *requires* conversion to FINAL_TYPE. */
4049 if (op0
== primop0
&& TREE_TYPE (op0
) != *restype_ptr
)
4050 unsignedp0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
4051 if (op1
== primop1
&& TREE_TYPE (op1
) != *restype_ptr
)
4052 unsignedp1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
4054 /* If one of the operands must be floated, we cannot optimize. */
4055 real1
= TREE_CODE (TREE_TYPE (primop0
)) == REAL_TYPE
;
4056 real2
= TREE_CODE (TREE_TYPE (primop1
)) == REAL_TYPE
;
4058 /* If first arg is constant, swap the args (changing operation
4059 so value is preserved), for canonicalization. Don't do this if
4060 the second arg is 0. */
4062 if (TREE_CONSTANT (primop0
)
4063 && !integer_zerop (primop1
) && !real_zerop (primop1
)
4064 && !fixed_zerop (primop1
))
4067 int temi
= unsignedp0
;
4075 unsignedp0
= unsignedp1
;
4098 *rescode_ptr
= code
;
4101 /* If comparing an integer against a constant more bits wide,
4102 maybe we can deduce a value of 1 or 0 independent of the data.
4103 Or else truncate the constant now
4104 rather than extend the variable at run time.
4106 This is only interesting if the constant is the wider arg.
4107 Also, it is not safe if the constant is unsigned and the
4108 variable arg is signed, since in this case the variable
4109 would be sign-extended and then regarded as unsigned.
4110 Our technique fails in this case because the lowest/highest
4111 possible unsigned results don't follow naturally from the
4112 lowest/highest possible values of the variable operand.
4113 For just EQ_EXPR and NE_EXPR there is another technique that
4114 could be used: see if the constant can be faithfully represented
4115 in the other operand's type, by truncating it and reextending it
4116 and see if that preserves the constant's value. */
4118 if (!real1
&& !real2
4119 && TREE_CODE (TREE_TYPE (primop0
)) != FIXED_POINT_TYPE
4120 && TREE_CODE (primop1
) == INTEGER_CST
4121 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
))
4123 int min_gt
, max_gt
, min_lt
, max_lt
;
4124 tree maxval
, minval
;
4125 /* 1 if comparison is nominally unsigned. */
4126 int unsignedp
= TYPE_UNSIGNED (*restype_ptr
);
4129 type
= c_common_signed_or_unsigned_type (unsignedp0
,
4130 TREE_TYPE (primop0
));
4132 maxval
= TYPE_MAX_VALUE (type
);
4133 minval
= TYPE_MIN_VALUE (type
);
4135 if (unsignedp
&& !unsignedp0
)
4136 *restype_ptr
= c_common_signed_type (*restype_ptr
);
4138 if (TREE_TYPE (primop1
) != *restype_ptr
)
4140 /* Convert primop1 to target type, but do not introduce
4141 additional overflow. We know primop1 is an int_cst. */
4142 primop1
= force_fit_type_double (*restype_ptr
,
4143 tree_to_double_int (primop1
),
4144 0, TREE_OVERFLOW (primop1
));
4146 if (type
!= *restype_ptr
)
4148 minval
= convert (*restype_ptr
, minval
);
4149 maxval
= convert (*restype_ptr
, maxval
);
4152 if (unsignedp
&& unsignedp0
)
4154 min_gt
= INT_CST_LT_UNSIGNED (primop1
, minval
);
4155 max_gt
= INT_CST_LT_UNSIGNED (primop1
, maxval
);
4156 min_lt
= INT_CST_LT_UNSIGNED (minval
, primop1
);
4157 max_lt
= INT_CST_LT_UNSIGNED (maxval
, primop1
);
4161 min_gt
= INT_CST_LT (primop1
, minval
);
4162 max_gt
= INT_CST_LT (primop1
, maxval
);
4163 min_lt
= INT_CST_LT (minval
, primop1
);
4164 max_lt
= INT_CST_LT (maxval
, primop1
);
4168 /* This used to be a switch, but Genix compiler can't handle that. */
4169 if (code
== NE_EXPR
)
4171 if (max_lt
|| min_gt
)
4172 val
= truthvalue_true_node
;
4174 else if (code
== EQ_EXPR
)
4176 if (max_lt
|| min_gt
)
4177 val
= truthvalue_false_node
;
4179 else if (code
== LT_EXPR
)
4182 val
= truthvalue_true_node
;
4184 val
= truthvalue_false_node
;
4186 else if (code
== GT_EXPR
)
4189 val
= truthvalue_true_node
;
4191 val
= truthvalue_false_node
;
4193 else if (code
== LE_EXPR
)
4196 val
= truthvalue_true_node
;
4198 val
= truthvalue_false_node
;
4200 else if (code
== GE_EXPR
)
4203 val
= truthvalue_true_node
;
4205 val
= truthvalue_false_node
;
4208 /* If primop0 was sign-extended and unsigned comparison specd,
4209 we did a signed comparison above using the signed type bounds.
4210 But the comparison we output must be unsigned.
4212 Also, for inequalities, VAL is no good; but if the signed
4213 comparison had *any* fixed result, it follows that the
4214 unsigned comparison just tests the sign in reverse
4215 (positive values are LE, negative ones GE).
4216 So we can generate an unsigned comparison
4217 against an extreme value of the signed type. */
4219 if (unsignedp
&& !unsignedp0
)
4226 primop1
= TYPE_MIN_VALUE (type
);
4232 primop1
= TYPE_MAX_VALUE (type
);
4239 type
= c_common_unsigned_type (type
);
4242 if (TREE_CODE (primop0
) != INTEGER_CST
4243 && c_inhibit_evaluation_warnings
== 0)
4245 if (val
== truthvalue_false_node
)
4246 warning_at (loc
, OPT_Wtype_limits
,
4247 "comparison is always false due to limited range of data type");
4248 if (val
== truthvalue_true_node
)
4249 warning_at (loc
, OPT_Wtype_limits
,
4250 "comparison is always true due to limited range of data type");
4255 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4256 if (TREE_SIDE_EFFECTS (primop0
))
4257 return build2 (COMPOUND_EXPR
, TREE_TYPE (val
), primop0
, val
);
4261 /* Value is not predetermined, but do the comparison
4262 in the type of the operand that is not constant.
4263 TYPE is already properly set. */
4266 /* If either arg is decimal float and the other is float, find the
4267 proper common type to use for comparison. */
4268 else if (real1
&& real2
4269 && (DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0
)))
4270 || DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1
)))))
4271 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
4273 else if (real1
&& real2
4274 && (TYPE_PRECISION (TREE_TYPE (primop0
))
4275 == TYPE_PRECISION (TREE_TYPE (primop1
))))
4276 type
= TREE_TYPE (primop0
);
4278 /* If args' natural types are both narrower than nominal type
4279 and both extend in the same manner, compare them
4280 in the type of the wider arg.
4281 Otherwise must actually extend both to the nominal
4282 common type lest different ways of extending
4284 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
4286 else if (unsignedp0
== unsignedp1
&& real1
== real2
4287 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
)
4288 && TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (*restype_ptr
))
4290 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
4291 type
= c_common_signed_or_unsigned_type (unsignedp0
4292 || TYPE_UNSIGNED (*restype_ptr
),
4294 /* Make sure shorter operand is extended the right way
4295 to match the longer operand. */
4297 = convert (c_common_signed_or_unsigned_type (unsignedp0
,
4298 TREE_TYPE (primop0
)),
4301 = convert (c_common_signed_or_unsigned_type (unsignedp1
,
4302 TREE_TYPE (primop1
)),
4307 /* Here we must do the comparison on the nominal type
4308 using the args exactly as we received them. */
4309 type
= *restype_ptr
;
4313 if (!real1
&& !real2
&& integer_zerop (primop1
)
4314 && TYPE_UNSIGNED (*restype_ptr
))
4317 /* All unsigned values are >= 0, so we warn. However,
4318 if OP0 is a constant that is >= 0, the signedness of
4319 the comparison isn't an issue, so suppress the
4322 warn_type_limits
&& !in_system_header_at (loc
)
4323 && c_inhibit_evaluation_warnings
== 0
4324 && !(TREE_CODE (primop0
) == INTEGER_CST
4325 && !TREE_OVERFLOW (convert (c_common_signed_type (type
),
4327 /* Do not warn for enumeration types. */
4328 && (TREE_CODE (expr_original_type (primop0
)) != ENUMERAL_TYPE
);
4334 warning_at (loc
, OPT_Wtype_limits
,
4335 "comparison of unsigned expression >= 0 is always true");
4336 value
= truthvalue_true_node
;
4341 warning_at (loc
, OPT_Wtype_limits
,
4342 "comparison of unsigned expression < 0 is always false");
4343 value
= truthvalue_false_node
;
4352 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4353 if (TREE_SIDE_EFFECTS (primop0
))
4354 return build2 (COMPOUND_EXPR
, TREE_TYPE (value
),
4361 *op0_ptr
= convert (type
, primop0
);
4362 *op1_ptr
= convert (type
, primop1
);
4364 *restype_ptr
= truthvalue_type_node
;
4369 /* Return a tree for the sum or difference (RESULTCODE says which)
4370 of pointer PTROP and integer INTOP. */
4373 pointer_int_sum (location_t loc
, enum tree_code resultcode
,
4374 tree ptrop
, tree intop
, bool complain
)
4378 /* The result is a pointer of the same type that is being added. */
4379 tree result_type
= TREE_TYPE (ptrop
);
4381 /* If the pointer lives in UPC shared memory, then
4382 drop the 'shared' qualifier. */
4383 if (TREE_SHARED (ptrop
) || upc_shared_type_p (result_type
))
4384 result_type
= build_upc_unshared_type (result_type
);
4386 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
4388 if (complain
&& warn_pointer_arith
)
4389 pedwarn (loc
, OPT_Wpointer_arith
,
4390 "pointer of type %<void *%> used in arithmetic");
4392 return error_mark_node
;
4393 size_exp
= integer_one_node
;
4395 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
4397 if (complain
&& warn_pointer_arith
)
4398 pedwarn (loc
, OPT_Wpointer_arith
,
4399 "pointer to a function used in arithmetic");
4401 return error_mark_node
;
4402 size_exp
= integer_one_node
;
4405 size_exp
= size_in_bytes (TREE_TYPE (result_type
));
4407 /* We are manipulating pointer values, so we don't need to warn
4408 about relying on undefined signed overflow. We disable the
4409 warning here because we use integer types so fold won't know that
4410 they are really pointers. */
4411 fold_defer_overflow_warnings ();
4413 /* If what we are about to multiply by the size of the elements
4414 contains a constant term, apply distributive law
4415 and multiply that constant term separately.
4416 This helps produce common subexpressions. */
4417 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
4418 && !TREE_CONSTANT (intop
)
4419 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
4420 && TREE_CONSTANT (size_exp
)
4421 /* If the constant comes from pointer subtraction,
4422 skip this optimization--it would cause an error. */
4423 && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop
, 0))) == INTEGER_TYPE
4424 /* If the constant is unsigned, and smaller than the pointer size,
4425 then we must skip this optimization. This is because it could cause
4426 an overflow error if the constant is negative but INTOP is not. */
4427 && (!TYPE_UNSIGNED (TREE_TYPE (intop
))
4428 || (TYPE_PRECISION (TREE_TYPE (intop
))
4429 == TYPE_PRECISION (TREE_TYPE (ptrop
)))))
4431 enum tree_code subcode
= resultcode
;
4432 tree int_type
= TREE_TYPE (intop
);
4433 if (TREE_CODE (intop
) == MINUS_EXPR
)
4434 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
4435 /* Convert both subexpression types to the type of intop,
4436 because weird cases involving pointer arithmetic
4437 can result in a sum or difference with different type args. */
4438 ptrop
= build_binary_op (EXPR_LOCATION (TREE_OPERAND (intop
, 1)),
4440 convert (int_type
, TREE_OPERAND (intop
, 1)), 1);
4441 intop
= convert (int_type
, TREE_OPERAND (intop
, 0));
4444 /* Convert the integer argument to a type the same size as sizetype
4445 so the multiply won't overflow spuriously. */
4446 if (TYPE_PRECISION (TREE_TYPE (intop
)) != TYPE_PRECISION (sizetype
)
4447 || TYPE_UNSIGNED (TREE_TYPE (intop
)) != TYPE_UNSIGNED (sizetype
))
4448 intop
= convert (c_common_type_for_size (TYPE_PRECISION (sizetype
),
4449 TYPE_UNSIGNED (sizetype
)), intop
);
4451 /* Replace the integer argument with a suitable product by the object size.
4452 Do this multiplication as signed, then convert to the appropriate type
4453 for the pointer operation and disregard an overflow that occurred only
4454 because of the sign-extension change in the latter conversion. */
4456 tree t
= build_binary_op (loc
,
4458 convert (TREE_TYPE (intop
), size_exp
), 1);
4459 intop
= convert (sizetype
, t
);
4460 if (TREE_OVERFLOW_P (intop
) && !TREE_OVERFLOW (t
))
4461 intop
= build_int_cst_wide (TREE_TYPE (intop
), TREE_INT_CST_LOW (intop
),
4462 TREE_INT_CST_HIGH (intop
));
4465 /* Create the sum or difference. */
4466 if (resultcode
== MINUS_EXPR
)
4467 intop
= fold_build1_loc (loc
, NEGATE_EXPR
, sizetype
, intop
);
4469 ret
= fold_build_pointer_plus_loc (loc
, ptrop
, intop
);
4471 fold_undefer_and_ignore_overflow_warnings ();
4476 /* Wrap a C_MAYBE_CONST_EXPR around an expression that is fully folded
4477 and if NON_CONST is known not to be permitted in an evaluated part
4478 of a constant expression. */
4481 c_wrap_maybe_const (tree expr
, bool non_const
)
4483 bool nowarning
= TREE_NO_WARNING (expr
);
4484 location_t loc
= EXPR_LOCATION (expr
);
4486 /* This should never be called for C++. */
4487 if (c_dialect_cxx ())
4490 /* The result of folding may have a NOP_EXPR to set TREE_NO_WARNING. */
4491 STRIP_TYPE_NOPS (expr
);
4492 expr
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (expr
), NULL
, expr
);
4493 C_MAYBE_CONST_EXPR_NON_CONST (expr
) = non_const
;
4495 TREE_NO_WARNING (expr
) = 1;
4496 protected_set_expr_location (expr
, loc
);
4501 /* Wrap a SAVE_EXPR around EXPR, if appropriate. Like save_expr, but
4502 for C folds the inside expression and wraps a C_MAYBE_CONST_EXPR
4503 around the SAVE_EXPR if needed so that c_fully_fold does not need
4504 to look inside SAVE_EXPRs. */
4507 c_save_expr (tree expr
)
4509 bool maybe_const
= true;
4510 if (c_dialect_cxx ())
4511 return save_expr (expr
);
4512 expr
= c_fully_fold (expr
, false, &maybe_const
);
4513 expr
= save_expr (expr
);
4515 expr
= c_wrap_maybe_const (expr
, true);
4519 /* Return whether EXPR is a declaration whose address can never be
4523 decl_with_nonnull_addr_p (const_tree expr
)
4525 return (DECL_P (expr
)
4526 && (TREE_CODE (expr
) == PARM_DECL
4527 || TREE_CODE (expr
) == LABEL_DECL
4528 || !DECL_WEAK (expr
)));
4531 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
4532 or for an `if' or `while' statement or ?..: exp. It should already
4533 have been validated to be of suitable type; otherwise, a bad
4534 diagnostic may result.
4536 The EXPR is located at LOCATION.
4538 This preparation consists of taking the ordinary
4539 representation of an expression expr and producing a valid tree
4540 boolean expression describing whether expr is nonzero. We could
4541 simply always do build_binary_op (NE_EXPR, expr, truthvalue_false_node, 1),
4542 but we optimize comparisons, &&, ||, and !.
4544 The resulting type should always be `truthvalue_type_node'. */
4547 c_common_truthvalue_conversion (location_t location
, tree expr
)
4549 switch (TREE_CODE (expr
))
4551 case EQ_EXPR
: case NE_EXPR
: case UNEQ_EXPR
: case LTGT_EXPR
:
4552 case LE_EXPR
: case GE_EXPR
: case LT_EXPR
: case GT_EXPR
:
4553 case UNLE_EXPR
: case UNGE_EXPR
: case UNLT_EXPR
: case UNGT_EXPR
:
4554 case ORDERED_EXPR
: case UNORDERED_EXPR
:
4555 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4557 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4558 TREE_OPERAND (expr
, 0), TREE_OPERAND (expr
, 1));
4561 case TRUTH_ANDIF_EXPR
:
4562 case TRUTH_ORIF_EXPR
:
4563 case TRUTH_AND_EXPR
:
4565 case TRUTH_XOR_EXPR
:
4566 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4568 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4569 c_common_truthvalue_conversion (location
,
4570 TREE_OPERAND (expr
, 0)),
4571 c_common_truthvalue_conversion (location
,
4572 TREE_OPERAND (expr
, 1)));
4575 case TRUTH_NOT_EXPR
:
4576 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4578 expr
= build1 (TREE_CODE (expr
), truthvalue_type_node
,
4579 c_common_truthvalue_conversion (location
,
4580 TREE_OPERAND (expr
, 0)));
4587 return integer_zerop (expr
) ? truthvalue_false_node
4588 : truthvalue_true_node
;
4591 return real_compare (NE_EXPR
, &TREE_REAL_CST (expr
), &dconst0
)
4592 ? truthvalue_true_node
4593 : truthvalue_false_node
;
4596 return fixed_compare (NE_EXPR
, &TREE_FIXED_CST (expr
),
4597 &FCONST0 (TYPE_MODE (TREE_TYPE (expr
))))
4598 ? truthvalue_true_node
4599 : truthvalue_false_node
;
4602 expr
= build_unary_op (location
, ADDR_EXPR
, expr
, 0);
4607 tree inner
= TREE_OPERAND (expr
, 0);
4608 if (decl_with_nonnull_addr_p (inner
))
4610 /* Common Ada/Pascal programmer's mistake. */
4611 warning_at (location
,
4613 "the address of %qD will always evaluate as %<true%>",
4615 return truthvalue_true_node
;
4621 expr
= build_binary_op (EXPR_LOCATION (expr
),
4622 (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1))
4623 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4624 c_common_truthvalue_conversion (location
,
4625 TREE_OPERAND (expr
, 0)),
4626 c_common_truthvalue_conversion (location
,
4627 TREE_OPERAND (expr
, 1)),
4634 case EXCESS_PRECISION_EXPR
:
4635 /* These don't change whether an object is nonzero or zero. */
4636 return c_common_truthvalue_conversion (location
, TREE_OPERAND (expr
, 0));
4640 /* These don't change whether an object is zero or nonzero, but
4641 we can't ignore them if their second arg has side-effects. */
4642 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1)))
4644 expr
= build2 (COMPOUND_EXPR
, truthvalue_type_node
,
4645 TREE_OPERAND (expr
, 1),
4646 c_common_truthvalue_conversion
4647 (location
, TREE_OPERAND (expr
, 0)));
4651 return c_common_truthvalue_conversion (location
,
4652 TREE_OPERAND (expr
, 0));
4655 /* Distribute the conversion into the arms of a COND_EXPR. */
4656 if (c_dialect_cxx ())
4658 tree op1
= TREE_OPERAND (expr
, 1);
4659 tree op2
= TREE_OPERAND (expr
, 2);
4660 /* In C++ one of the arms might have void type if it is throw. */
4661 if (!VOID_TYPE_P (TREE_TYPE (op1
)))
4662 op1
= c_common_truthvalue_conversion (location
, op1
);
4663 if (!VOID_TYPE_P (TREE_TYPE (op2
)))
4664 op2
= c_common_truthvalue_conversion (location
, op2
);
4665 expr
= fold_build3_loc (location
, COND_EXPR
, truthvalue_type_node
,
4666 TREE_OPERAND (expr
, 0), op1
, op2
);
4671 /* Folding will happen later for C. */
4672 expr
= build3 (COND_EXPR
, truthvalue_type_node
,
4673 TREE_OPERAND (expr
, 0),
4674 c_common_truthvalue_conversion (location
,
4675 TREE_OPERAND (expr
, 1)),
4676 c_common_truthvalue_conversion (location
,
4677 TREE_OPERAND (expr
, 2)));
4683 tree totype
= TREE_TYPE (expr
);
4684 tree fromtype
= TREE_TYPE (TREE_OPERAND (expr
, 0));
4686 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
4687 since that affects how `default_conversion' will behave. */
4688 if (TREE_CODE (totype
) == REFERENCE_TYPE
4689 || TREE_CODE (fromtype
) == REFERENCE_TYPE
)
4691 /* Don't strip a conversion from C++0x scoped enum, since they
4692 don't implicitly convert to other types. */
4693 if (TREE_CODE (fromtype
) == ENUMERAL_TYPE
4694 && ENUM_IS_SCOPED (fromtype
))
4696 /* If this isn't narrowing the argument, we can ignore it. */
4697 if (TYPE_PRECISION (totype
) >= TYPE_PRECISION (fromtype
))
4698 return c_common_truthvalue_conversion (location
,
4699 TREE_OPERAND (expr
, 0));
4704 if (!TREE_NO_WARNING (expr
)
4705 && warn_parentheses
)
4707 warning (OPT_Wparentheses
,
4708 "suggest parentheses around assignment used as truth value");
4709 TREE_NO_WARNING (expr
) = 1;
4717 if (TREE_CODE (TREE_TYPE (expr
)) == COMPLEX_TYPE
)
4719 tree t
= (in_late_binary_op
? save_expr (expr
) : c_save_expr (expr
));
4720 expr
= (build_binary_op
4721 (EXPR_LOCATION (expr
),
4722 (TREE_SIDE_EFFECTS (expr
)
4723 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4724 c_common_truthvalue_conversion
4726 build_unary_op (location
, REALPART_EXPR
, t
, 0)),
4727 c_common_truthvalue_conversion
4729 build_unary_op (location
, IMAGPART_EXPR
, t
, 0)),
4734 if (TREE_CODE (TREE_TYPE (expr
)) == FIXED_POINT_TYPE
)
4736 tree fixed_zero_node
= build_fixed (TREE_TYPE (expr
),
4738 (TREE_TYPE (expr
))));
4739 return build_binary_op (location
, NE_EXPR
, expr
, fixed_zero_node
, 1);
4742 return build_binary_op (location
, NE_EXPR
, expr
, integer_zero_node
, 1);
4745 protected_set_expr_location (expr
, location
);
4749 static void def_builtin_1 (enum built_in_function fncode
,
4751 enum built_in_class fnclass
,
4752 tree fntype
, tree libtype
,
4753 bool both_p
, bool fallback_p
, bool nonansi_p
,
4754 tree fnattrs
, bool implicit_p
);
4757 /* Apply the TYPE_QUALS to the new DECL. */
4760 c_apply_type_quals_to_decl (int type_quals
, tree decl
)
4762 tree type
= TREE_TYPE (decl
);
4764 if (type
== error_mark_node
)
4767 if ((type_quals
& TYPE_QUAL_CONST
)
4768 || (type
&& TREE_CODE (type
) == REFERENCE_TYPE
))
4769 /* We used to check TYPE_NEEDS_CONSTRUCTING here, but now a constexpr
4770 constructor can produce constant init, so rely on cp_finish_decl to
4771 clear TREE_READONLY if the variable has non-constant init. */
4772 TREE_READONLY (decl
) = 1;
4773 if (type_quals
& TYPE_QUAL_VOLATILE
)
4775 TREE_SIDE_EFFECTS (decl
) = 1;
4776 TREE_THIS_VOLATILE (decl
) = 1;
4778 if (type_quals
& TYPE_QUAL_RESTRICT
)
4780 while (type
&& TREE_CODE (type
) == ARRAY_TYPE
)
4781 /* Allow 'restrict' on arrays of pointers.
4782 FIXME currently we just ignore it. */
4783 type
= TREE_TYPE (type
);
4785 || !POINTER_TYPE_P (type
)
4786 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type
)))
4787 error ("invalid use of %<restrict%>");
4789 if (type_quals
& TYPE_QUAL_SHARED
)
4791 TREE_SHARED (decl
) = 1;
4792 if (type_quals
& TYPE_QUAL_STRICT
)
4793 TREE_STRICT(decl
) = 1;
4794 else if (type_quals
& TYPE_QUAL_RELAXED
)
4795 TREE_RELAXED(decl
) = 1;
4796 /* The declaration's type should have been previously defined
4797 as a UPC shared type. */
4798 gcc_assert (upc_shared_type_p (type
));
4802 /* Hash function for the problem of multiple type definitions in
4803 different files. This must hash all types that will compare
4804 equal via comptypes to the same value. In practice it hashes
4805 on some of the simple stuff and leaves the details to comptypes. */
4808 c_type_hash (const void *p
)
4812 const_tree
const t
= (const_tree
) p
;
4814 switch (TREE_CODE (t
))
4816 /* For pointers, hash on pointee type plus some swizzling. */
4818 return c_type_hash (TREE_TYPE (t
)) ^ 0x3003003;
4819 /* Hash on number of elements and total size. */
4822 t2
= TYPE_VALUES (t
);
4826 t2
= TYPE_FIELDS (t
);
4828 case QUAL_UNION_TYPE
:
4830 t2
= TYPE_FIELDS (t
);
4834 t2
= TYPE_FIELDS (t
);
4839 /* FIXME: We want to use a DECL_CHAIN iteration method here, but
4840 TYPE_VALUES of ENUMERAL_TYPEs is stored as a TREE_LIST. */
4841 n_elements
= list_length (t2
);
4842 /* We might have a VLA here. */
4843 if (TREE_CODE (TYPE_SIZE (t
)) != INTEGER_CST
)
4846 size
= TREE_INT_CST_LOW (TYPE_SIZE (t
));
4847 return ((size
<< 24) | (n_elements
<< shift
));
4850 static GTY((param_is (union tree_node
))) htab_t type_hash_table
;
4852 /* Return the typed-based alias set for T, which may be an expression
4853 or a type. Return -1 if we don't do anything special. */
4856 c_common_get_alias_set (tree t
)
4861 /* For VLAs, use the alias set of the element type rather than the
4862 default of alias set 0 for types compared structurally. */
4863 if (TYPE_P (t
) && TYPE_STRUCTURAL_EQUALITY_P (t
))
4865 if (TREE_CODE (t
) == ARRAY_TYPE
)
4866 return get_alias_set (TREE_TYPE (t
));
4870 /* Permit type-punning when accessing a union, provided the access
4871 is directly through the union. For example, this code does not
4872 permit taking the address of a union member and then storing
4873 through it. Even the type-punning allowed here is a GCC
4874 extension, albeit a common and useful one; the C standard says
4875 that such accesses have implementation-defined behavior. */
4877 TREE_CODE (u
) == COMPONENT_REF
|| TREE_CODE (u
) == ARRAY_REF
;
4878 u
= TREE_OPERAND (u
, 0))
4879 if (TREE_CODE (u
) == COMPONENT_REF
4880 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u
, 0))) == UNION_TYPE
)
4883 /* That's all the expressions we handle specially. */
4887 /* The C standard guarantees that any object may be accessed via an
4888 lvalue that has character type. */
4889 if (t
== char_type_node
4890 || t
== signed_char_type_node
4891 || t
== unsigned_char_type_node
)
4894 /* The C standard specifically allows aliasing between signed and
4895 unsigned variants of the same type. We treat the signed
4896 variant as canonical. */
4897 if (TREE_CODE (t
) == INTEGER_TYPE
&& TYPE_UNSIGNED (t
))
4899 tree t1
= c_common_signed_type (t
);
4901 /* t1 == t can happen for boolean nodes which are always unsigned. */
4903 return get_alias_set (t1
);
4906 /* For the time being, make UPC pointers-to-shared conflict
4907 with everything else. Ideally, UPC pointers-to-shared should
4908 only conflict with the internal type used to represent
4909 the UPC pointer-to-shared (i.e., upc_pts_rep_type_node). */
4911 if (TYPE_P (t
) ? (TREE_CODE (t
) == POINTER_TYPE
4912 && upc_shared_type_p (TREE_TYPE (t
)))
4914 && TREE_CODE (TREE_TYPE (t
)) == POINTER_TYPE
4915 && upc_shared_type_p (TREE_TYPE (TREE_TYPE (t
)))))
4918 /* Handle the case of multiple type nodes referring to "the same" type,
4919 which occurs with IMA. These share an alias set. FIXME: Currently only
4920 C90 is handled. (In C99 type compatibility is not transitive, which
4921 complicates things mightily. The alias set splay trees can theoretically
4922 represent this, but insertion is tricky when you consider all the
4923 different orders things might arrive in.) */
4925 if (c_language
!= clk_c
|| flag_isoc99
)
4928 /* Save time if there's only one input file. */
4929 if (num_in_fnames
== 1)
4932 /* Pointers need special handling if they point to any type that
4933 needs special handling (below). */
4934 if (TREE_CODE (t
) == POINTER_TYPE
)
4937 /* Find bottom type under any nested POINTERs. */
4938 for (t2
= TREE_TYPE (t
);
4939 TREE_CODE (t2
) == POINTER_TYPE
;
4940 t2
= TREE_TYPE (t2
))
4942 if (TREE_CODE (t2
) != RECORD_TYPE
4943 && TREE_CODE (t2
) != ENUMERAL_TYPE
4944 && TREE_CODE (t2
) != QUAL_UNION_TYPE
4945 && TREE_CODE (t2
) != UNION_TYPE
)
4947 if (TYPE_SIZE (t2
) == 0)
4950 /* These are the only cases that need special handling. */
4951 if (TREE_CODE (t
) != RECORD_TYPE
4952 && TREE_CODE (t
) != ENUMERAL_TYPE
4953 && TREE_CODE (t
) != QUAL_UNION_TYPE
4954 && TREE_CODE (t
) != UNION_TYPE
4955 && TREE_CODE (t
) != POINTER_TYPE
)
4958 if (TYPE_SIZE (t
) == 0)
4961 /* Look up t in hash table. Only one of the compatible types within each
4962 alias set is recorded in the table. */
4963 if (!type_hash_table
)
4964 type_hash_table
= htab_create_ggc (1021, c_type_hash
,
4965 (htab_eq
) lang_hooks
.types_compatible_p
,
4967 slot
= htab_find_slot (type_hash_table
, t
, INSERT
);
4970 TYPE_ALIAS_SET (t
) = TYPE_ALIAS_SET ((tree
)*slot
);
4971 return TYPE_ALIAS_SET ((tree
)*slot
);
4974 /* Our caller will assign and record (in t) a new alias set; all we need
4975 to do is remember t in the hash table. */
4981 /* Return the value of THREADS.
4983 UPC defines a reserved variable, THREADS, which returns the
4984 number of threads that will be created when the UPC program
4985 executes. The value of threads can be specified at runtime via
4986 the -fupc-threads=N switch, where N is an integer specifying
4987 the number of threads. When the value of THREADS is specified
4988 at compile-time, this is called the "static threads compilation
4991 In the static threads compilation environment, THREADS is a
4992 pre-defined preprocessor macro with the value, N.
4994 If no value for threads is given at compile-time, then the value
4995 must be specified when the application program is executed.
4996 This method of establishing the value of THREADS is called
4997 the "dynamic threads compilation environment". */
5000 upc_num_threads (void)
5003 gcc_assert (flag_upc
);
5004 n
= flag_upc_threads
? ssize_int (flag_upc_threads
)
5005 : lookup_name (get_identifier ("THREADS"));
5008 error ("the UPC-required THREADS variable is undefined; "
5009 "when compiling pre-processed source, "
5010 "all -fupc-* switches must be passed on the command line, "
5011 "asserting the same values as supplied when the "
5012 "original source file was preprocessed");
5019 /* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where
5020 the IS_SIZEOF parameter indicates which operator is being applied.
5021 The COMPLAIN flag controls whether we should diagnose possibly
5022 ill-formed constructs or not. LOC is the location of the SIZEOF or
5023 TYPEOF operator. If MIN_ALIGNOF, the least alignment required for
5024 a type in any context should be returned, rather than the normal
5025 alignment for that type. */
5028 c_sizeof_or_alignof_type (location_t loc
,
5029 tree type
, bool is_sizeof
, bool min_alignof
,
5032 const char *op_name
;
5034 enum tree_code type_code
= TREE_CODE (type
);
5036 op_name
= is_sizeof
? "sizeof" : "__alignof__";
5038 if (type_code
== FUNCTION_TYPE
)
5042 if (complain
&& warn_pointer_arith
)
5043 pedwarn (loc
, OPT_Wpointer_arith
,
5044 "invalid application of %<sizeof%> to a function type");
5046 return error_mark_node
;
5047 value
= size_one_node
;
5053 if (c_dialect_cxx ())
5054 pedwarn (loc
, OPT_Wpedantic
, "ISO C++ does not permit "
5055 "%<alignof%> applied to a function type");
5057 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not permit "
5058 "%<_Alignof%> applied to a function type");
5060 value
= size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
5063 else if (type_code
== VOID_TYPE
|| type_code
== ERROR_MARK
)
5067 if (type_code
== VOID_TYPE
&& upc_shared_type_p (type
))
5068 error_at (loc
, "invalid application of %qs"
5069 " to %<shared void%> type", op_name
);
5070 else if (type_code
== VOID_TYPE
&& warn_pointer_arith
)
5071 pedwarn (loc
, pedantic
? OPT_Wpedantic
: OPT_Wpointer_arith
,
5072 "invalid application of %qs to a void type", op_name
);
5075 return error_mark_node
;
5076 value
= size_one_node
;
5078 else if (!COMPLETE_TYPE_P (type
)
5079 && (!c_dialect_cxx () || is_sizeof
|| type_code
!= ARRAY_TYPE
))
5082 error_at (loc
, "invalid application of %qs to incomplete type %qT",
5084 return error_mark_node
;
5086 else if (c_dialect_cxx () && type_code
== ARRAY_TYPE
5087 && !COMPLETE_TYPE_P (TREE_TYPE (type
)))
5090 error_at (loc
, "invalid application of %qs to array type %qT of "
5091 "incomplete element type", op_name
, type
);
5092 return error_mark_node
;
5097 /* Convert in case a char is more than one unit. */
5098 value
= size_binop_loc (loc
, CEIL_DIV_EXPR
, TYPE_SIZE_UNIT (type
),
5099 size_int (TYPE_PRECISION (char_type_node
)
5101 else if (min_alignof
)
5103 unsigned int align
= TYPE_ALIGN (type
);
5104 align
= MIN (align
, BIGGEST_ALIGNMENT
);
5105 #ifdef BIGGEST_FIELD_ALIGNMENT
5106 align
= MIN (align
, BIGGEST_FIELD_ALIGNMENT
);
5108 unsigned int field_align
= align
;
5109 #ifdef ADJUST_FIELD_ALIGN
5110 tree field
= build_decl (UNKNOWN_LOCATION
, FIELD_DECL
, NULL_TREE
,
5112 field_align
= ADJUST_FIELD_ALIGN (field
, field_align
);
5114 align
= MIN (align
, field_align
);
5115 value
= size_int (align
/ BITS_PER_UNIT
);
5118 value
= size_int (TYPE_ALIGN_UNIT (type
));
5121 if (is_sizeof
&& (TREE_CODE (type
) == ARRAY_TYPE
)
5122 && upc_shared_type_p (type
)
5123 && TYPE_HAS_THREADS_FACTOR (type
))
5125 const tree n_threads
= convert (sizetype
, upc_num_threads ());
5126 value
= size_binop (MULT_EXPR
, value
, n_threads
);
5129 /* VALUE will have the middle-end integer type sizetype.
5130 However, we should really return a value of type `size_t',
5131 which is just a typedef for an ordinary integer type. */
5132 value
= fold_convert_loc (loc
, size_type_node
, value
);
5137 /* Implement the __alignof keyword: Return the minimum required
5138 alignment of EXPR, measured in bytes. For VAR_DECLs,
5139 FUNCTION_DECLs and FIELD_DECLs return DECL_ALIGN (which can be set
5140 from an "aligned" __attribute__ specification). LOC is the
5141 location of the ALIGNOF operator. */
5144 c_alignof_expr (location_t loc
, tree expr
)
5148 if (VAR_OR_FUNCTION_DECL_P (expr
))
5149 t
= size_int (DECL_ALIGN_UNIT (expr
));
5151 else if (TREE_CODE (expr
) == COMPONENT_REF
5152 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
, 1)))
5154 error_at (loc
, "%<__alignof%> applied to a bit-field");
5157 else if (TREE_CODE (expr
) == COMPONENT_REF
5158 && TREE_CODE (TREE_OPERAND (expr
, 1)) == FIELD_DECL
)
5159 t
= size_int (DECL_ALIGN_UNIT (TREE_OPERAND (expr
, 1)));
5161 else if (TREE_CODE (expr
) == INDIRECT_REF
)
5163 tree t
= TREE_OPERAND (expr
, 0);
5165 int bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
5167 while (CONVERT_EXPR_P (t
)
5168 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
5172 t
= TREE_OPERAND (t
, 0);
5173 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
5174 if (thisalign
> bestalign
)
5175 best
= t
, bestalign
= thisalign
;
5177 return c_alignof (loc
, TREE_TYPE (TREE_TYPE (best
)));
5180 return c_alignof (loc
, TREE_TYPE (expr
));
5182 return fold_convert_loc (loc
, size_type_node
, t
);
5185 /* Handle C and C++ default attributes. */
5187 enum built_in_attribute
5189 #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
5190 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
5191 #define DEF_ATTR_STRING(ENUM, VALUE) ENUM,
5192 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
5193 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
5194 #include "builtin-attrs.def"
5195 #undef DEF_ATTR_NULL_TREE
5197 #undef DEF_ATTR_STRING
5198 #undef DEF_ATTR_IDENT
5199 #undef DEF_ATTR_TREE_LIST
5203 static GTY(()) tree built_in_attributes
[(int) ATTR_LAST
];
5205 static void c_init_attributes (void);
5209 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
5210 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
5211 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
5212 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
5213 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
5214 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
5215 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
5216 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) NAME,
5217 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) NAME,
5218 #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8) NAME,
5219 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
5220 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
5221 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
5222 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
5223 #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
5224 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG6) \
5226 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
5227 #include "builtin-types.def"
5228 #undef DEF_PRIMITIVE_TYPE
5229 #undef DEF_FUNCTION_TYPE_0
5230 #undef DEF_FUNCTION_TYPE_1
5231 #undef DEF_FUNCTION_TYPE_2
5232 #undef DEF_FUNCTION_TYPE_3
5233 #undef DEF_FUNCTION_TYPE_4
5234 #undef DEF_FUNCTION_TYPE_5
5235 #undef DEF_FUNCTION_TYPE_6
5236 #undef DEF_FUNCTION_TYPE_7
5237 #undef DEF_FUNCTION_TYPE_8
5238 #undef DEF_FUNCTION_TYPE_VAR_0
5239 #undef DEF_FUNCTION_TYPE_VAR_1
5240 #undef DEF_FUNCTION_TYPE_VAR_2
5241 #undef DEF_FUNCTION_TYPE_VAR_3
5242 #undef DEF_FUNCTION_TYPE_VAR_4
5243 #undef DEF_FUNCTION_TYPE_VAR_5
5244 #undef DEF_POINTER_TYPE
5248 typedef enum c_builtin_type builtin_type
;
5250 /* A temporary array for c_common_nodes_and_builtins. Used in
5251 communication with def_fn_type. */
5252 static tree builtin_types
[(int) BT_LAST
+ 1];
5254 /* A helper function for c_common_nodes_and_builtins. Build function type
5255 for DEF with return type RET and N arguments. If VAR is true, then the
5256 function should be variadic after those N arguments.
5258 Takes special care not to ICE if any of the types involved are
5259 error_mark_node, which indicates that said type is not in fact available
5260 (see builtin_type_for_size). In which case the function type as a whole
5261 should be error_mark_node. */
5264 def_fn_type (builtin_type def
, builtin_type ret
, bool var
, int n
, ...)
5267 tree
*args
= XALLOCAVEC (tree
, n
);
5272 for (i
= 0; i
< n
; ++i
)
5274 builtin_type a
= (builtin_type
) va_arg (list
, int);
5275 t
= builtin_types
[a
];
5276 if (t
== error_mark_node
)
5281 t
= builtin_types
[ret
];
5282 if (t
== error_mark_node
)
5285 t
= build_varargs_function_type_array (t
, n
, args
);
5287 t
= build_function_type_array (t
, n
, args
);
5290 builtin_types
[def
] = t
;
5294 /* Build builtin functions common to both C and C++ language
5298 c_define_builtins (tree va_list_ref_type_node
, tree va_list_arg_type_node
)
5300 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
5301 builtin_types[ENUM] = VALUE;
5302 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
5303 def_fn_type (ENUM, RETURN, 0, 0);
5304 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
5305 def_fn_type (ENUM, RETURN, 0, 1, ARG1);
5306 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
5307 def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
5308 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
5309 def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
5310 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
5311 def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
5312 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5313 def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
5314 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5316 def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
5317 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5319 def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
5320 #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5322 def_fn_type (ENUM, RETURN, 0, 8, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
5324 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
5325 def_fn_type (ENUM, RETURN, 1, 0);
5326 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
5327 def_fn_type (ENUM, RETURN, 1, 1, ARG1);
5328 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
5329 def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
5330 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
5331 def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
5332 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
5333 def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
5334 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5335 def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
5336 #define DEF_POINTER_TYPE(ENUM, TYPE) \
5337 builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
5339 #include "builtin-types.def"
5341 #undef DEF_PRIMITIVE_TYPE
5342 #undef DEF_FUNCTION_TYPE_1
5343 #undef DEF_FUNCTION_TYPE_2
5344 #undef DEF_FUNCTION_TYPE_3
5345 #undef DEF_FUNCTION_TYPE_4
5346 #undef DEF_FUNCTION_TYPE_5
5347 #undef DEF_FUNCTION_TYPE_6
5348 #undef DEF_FUNCTION_TYPE_VAR_0
5349 #undef DEF_FUNCTION_TYPE_VAR_1
5350 #undef DEF_FUNCTION_TYPE_VAR_2
5351 #undef DEF_FUNCTION_TYPE_VAR_3
5352 #undef DEF_FUNCTION_TYPE_VAR_4
5353 #undef DEF_FUNCTION_TYPE_VAR_5
5354 #undef DEF_POINTER_TYPE
5355 builtin_types
[(int) BT_LAST
] = NULL_TREE
;
5357 c_init_attributes ();
5359 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P, \
5360 NONANSI_P, ATTRS, IMPLICIT, COND) \
5362 def_builtin_1 (ENUM, NAME, CLASS, \
5363 builtin_types[(int) TYPE], \
5364 builtin_types[(int) LIBTYPE], \
5365 BOTH_P, FALLBACK_P, NONANSI_P, \
5366 built_in_attributes[(int) ATTRS], IMPLICIT);
5367 #include "builtins.def"
5370 targetm
.init_builtins ();
5372 build_common_builtin_nodes ();
5374 if (flag_enable_cilkplus
)
5375 cilk_init_builtins ();
5378 /* Like get_identifier, but avoid warnings about null arguments when
5379 the argument may be NULL for targets where GCC lacks stdint.h type
5383 c_get_ident (const char *id
)
5385 return get_identifier (id
);
5388 /* Build tree nodes and builtin functions common to both C and C++ language
5392 c_common_nodes_and_builtins (void)
5394 int char16_type_size
;
5395 int char32_type_size
;
5396 int wchar_type_size
;
5397 tree array_domain_type
;
5398 tree va_list_ref_type_node
;
5399 tree va_list_arg_type_node
;
5401 build_common_tree_nodes (flag_signed_char
, flag_short_double
);
5403 /* Define `int' and `char' first so that dbx will output them first. */
5404 record_builtin_type (RID_INT
, NULL
, integer_type_node
);
5405 record_builtin_type (RID_CHAR
, "char", char_type_node
);
5407 /* `signed' is the same as `int'. FIXME: the declarations of "signed",
5408 "unsigned long", "long long unsigned" and "unsigned short" were in C++
5409 but not C. Are the conditionals here needed? */
5410 if (c_dialect_cxx ())
5411 record_builtin_type (RID_SIGNED
, NULL
, integer_type_node
);
5412 record_builtin_type (RID_LONG
, "long int", long_integer_type_node
);
5413 record_builtin_type (RID_UNSIGNED
, "unsigned int", unsigned_type_node
);
5414 record_builtin_type (RID_MAX
, "long unsigned int",
5415 long_unsigned_type_node
);
5416 if (int128_integer_type_node
!= NULL_TREE
)
5418 record_builtin_type (RID_INT128
, "__int128",
5419 int128_integer_type_node
);
5420 record_builtin_type (RID_MAX
, "__int128 unsigned",
5421 int128_unsigned_type_node
);
5423 if (c_dialect_cxx ())
5424 record_builtin_type (RID_MAX
, "unsigned long", long_unsigned_type_node
);
5425 record_builtin_type (RID_MAX
, "long long int",
5426 long_long_integer_type_node
);
5427 record_builtin_type (RID_MAX
, "long long unsigned int",
5428 long_long_unsigned_type_node
);
5429 if (c_dialect_cxx ())
5430 record_builtin_type (RID_MAX
, "long long unsigned",
5431 long_long_unsigned_type_node
);
5432 record_builtin_type (RID_SHORT
, "short int", short_integer_type_node
);
5433 record_builtin_type (RID_MAX
, "short unsigned int",
5434 short_unsigned_type_node
);
5435 if (c_dialect_cxx ())
5436 record_builtin_type (RID_MAX
, "unsigned short",
5437 short_unsigned_type_node
);
5439 /* Define both `signed char' and `unsigned char'. */
5440 record_builtin_type (RID_MAX
, "signed char", signed_char_type_node
);
5441 record_builtin_type (RID_MAX
, "unsigned char", unsigned_char_type_node
);
5443 /* These are types that c_common_type_for_size and
5444 c_common_type_for_mode use. */
5445 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5446 TYPE_DECL
, NULL_TREE
,
5448 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5449 TYPE_DECL
, NULL_TREE
,
5451 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5452 TYPE_DECL
, NULL_TREE
,
5454 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5455 TYPE_DECL
, NULL_TREE
,
5457 #if HOST_BITS_PER_WIDE_INT >= 64
5458 if (targetm
.scalar_mode_supported_p (TImode
))
5459 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5461 get_identifier ("__int128_t"),
5464 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5465 TYPE_DECL
, NULL_TREE
,
5466 unsigned_intQI_type_node
));
5467 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5468 TYPE_DECL
, NULL_TREE
,
5469 unsigned_intHI_type_node
));
5470 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5471 TYPE_DECL
, NULL_TREE
,
5472 unsigned_intSI_type_node
));
5473 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5474 TYPE_DECL
, NULL_TREE
,
5475 unsigned_intDI_type_node
));
5476 #if HOST_BITS_PER_WIDE_INT >= 64
5477 if (targetm
.scalar_mode_supported_p (TImode
))
5478 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5480 get_identifier ("__uint128_t"),
5481 unsigned_intTI_type_node
));
5484 /* Create the widest literal types. */
5485 widest_integer_literal_type_node
5486 = make_signed_type (HOST_BITS_PER_WIDE_INT
* 2);
5487 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5488 TYPE_DECL
, NULL_TREE
,
5489 widest_integer_literal_type_node
));
5491 widest_unsigned_literal_type_node
5492 = make_unsigned_type (HOST_BITS_PER_WIDE_INT
* 2);
5493 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5494 TYPE_DECL
, NULL_TREE
,
5495 widest_unsigned_literal_type_node
));
5497 signed_size_type_node
= c_common_signed_type (size_type_node
);
5500 TREE_TYPE (identifier_global_value (get_identifier (PID_TYPE
)));
5502 record_builtin_type (RID_FLOAT
, NULL
, float_type_node
);
5503 record_builtin_type (RID_DOUBLE
, NULL
, double_type_node
);
5504 record_builtin_type (RID_MAX
, "long double", long_double_type_node
);
5506 /* Only supported decimal floating point extension if the target
5507 actually supports underlying modes. */
5508 if (targetm
.scalar_mode_supported_p (SDmode
)
5509 && targetm
.scalar_mode_supported_p (DDmode
)
5510 && targetm
.scalar_mode_supported_p (TDmode
))
5512 record_builtin_type (RID_DFLOAT32
, NULL
, dfloat32_type_node
);
5513 record_builtin_type (RID_DFLOAT64
, NULL
, dfloat64_type_node
);
5514 record_builtin_type (RID_DFLOAT128
, NULL
, dfloat128_type_node
);
5517 if (targetm
.fixed_point_supported_p ())
5519 record_builtin_type (RID_MAX
, "short _Fract", short_fract_type_node
);
5520 record_builtin_type (RID_FRACT
, NULL
, fract_type_node
);
5521 record_builtin_type (RID_MAX
, "long _Fract", long_fract_type_node
);
5522 record_builtin_type (RID_MAX
, "long long _Fract",
5523 long_long_fract_type_node
);
5524 record_builtin_type (RID_MAX
, "unsigned short _Fract",
5525 unsigned_short_fract_type_node
);
5526 record_builtin_type (RID_MAX
, "unsigned _Fract",
5527 unsigned_fract_type_node
);
5528 record_builtin_type (RID_MAX
, "unsigned long _Fract",
5529 unsigned_long_fract_type_node
);
5530 record_builtin_type (RID_MAX
, "unsigned long long _Fract",
5531 unsigned_long_long_fract_type_node
);
5532 record_builtin_type (RID_MAX
, "_Sat short _Fract",
5533 sat_short_fract_type_node
);
5534 record_builtin_type (RID_MAX
, "_Sat _Fract", sat_fract_type_node
);
5535 record_builtin_type (RID_MAX
, "_Sat long _Fract",
5536 sat_long_fract_type_node
);
5537 record_builtin_type (RID_MAX
, "_Sat long long _Fract",
5538 sat_long_long_fract_type_node
);
5539 record_builtin_type (RID_MAX
, "_Sat unsigned short _Fract",
5540 sat_unsigned_short_fract_type_node
);
5541 record_builtin_type (RID_MAX
, "_Sat unsigned _Fract",
5542 sat_unsigned_fract_type_node
);
5543 record_builtin_type (RID_MAX
, "_Sat unsigned long _Fract",
5544 sat_unsigned_long_fract_type_node
);
5545 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Fract",
5546 sat_unsigned_long_long_fract_type_node
);
5547 record_builtin_type (RID_MAX
, "short _Accum", short_accum_type_node
);
5548 record_builtin_type (RID_ACCUM
, NULL
, accum_type_node
);
5549 record_builtin_type (RID_MAX
, "long _Accum", long_accum_type_node
);
5550 record_builtin_type (RID_MAX
, "long long _Accum",
5551 long_long_accum_type_node
);
5552 record_builtin_type (RID_MAX
, "unsigned short _Accum",
5553 unsigned_short_accum_type_node
);
5554 record_builtin_type (RID_MAX
, "unsigned _Accum",
5555 unsigned_accum_type_node
);
5556 record_builtin_type (RID_MAX
, "unsigned long _Accum",
5557 unsigned_long_accum_type_node
);
5558 record_builtin_type (RID_MAX
, "unsigned long long _Accum",
5559 unsigned_long_long_accum_type_node
);
5560 record_builtin_type (RID_MAX
, "_Sat short _Accum",
5561 sat_short_accum_type_node
);
5562 record_builtin_type (RID_MAX
, "_Sat _Accum", sat_accum_type_node
);
5563 record_builtin_type (RID_MAX
, "_Sat long _Accum",
5564 sat_long_accum_type_node
);
5565 record_builtin_type (RID_MAX
, "_Sat long long _Accum",
5566 sat_long_long_accum_type_node
);
5567 record_builtin_type (RID_MAX
, "_Sat unsigned short _Accum",
5568 sat_unsigned_short_accum_type_node
);
5569 record_builtin_type (RID_MAX
, "_Sat unsigned _Accum",
5570 sat_unsigned_accum_type_node
);
5571 record_builtin_type (RID_MAX
, "_Sat unsigned long _Accum",
5572 sat_unsigned_long_accum_type_node
);
5573 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Accum",
5574 sat_unsigned_long_long_accum_type_node
);
5578 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5580 get_identifier ("complex int"),
5581 complex_integer_type_node
));
5582 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5584 get_identifier ("complex float"),
5585 complex_float_type_node
));
5586 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5588 get_identifier ("complex double"),
5589 complex_double_type_node
));
5590 lang_hooks
.decls
.pushdecl
5591 (build_decl (UNKNOWN_LOCATION
,
5592 TYPE_DECL
, get_identifier ("complex long double"),
5593 complex_long_double_type_node
));
5595 if (c_dialect_cxx ())
5596 /* For C++, make fileptr_type_node a distinct void * type until
5597 FILE type is defined. */
5598 fileptr_type_node
= build_variant_type_copy (ptr_type_node
);
5600 record_builtin_type (RID_VOID
, NULL
, void_type_node
);
5602 /* Set the TYPE_NAME for any variants that were built before
5603 record_builtin_type gave names to the built-in types. */
5605 tree void_name
= TYPE_NAME (void_type_node
);
5606 TYPE_NAME (void_type_node
) = NULL_TREE
;
5607 TYPE_NAME (build_qualified_type (void_type_node
, TYPE_QUAL_CONST
))
5609 TYPE_NAME (void_type_node
) = void_name
;
5612 /* This node must not be shared. */
5613 void_zero_node
= make_node (INTEGER_CST
);
5614 TREE_TYPE (void_zero_node
) = void_type_node
;
5616 void_list_node
= build_void_list_node ();
5618 /* Make a type to be the domain of a few array types
5619 whose domains don't really matter.
5620 200 is small enough that it always fits in size_t
5621 and large enough that it can hold most function names for the
5622 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
5623 array_domain_type
= build_index_type (size_int (200));
5625 /* Make a type for arrays of characters.
5626 With luck nothing will ever really depend on the length of this
5628 char_array_type_node
5629 = build_array_type (char_type_node
, array_domain_type
);
5631 string_type_node
= build_pointer_type (char_type_node
);
5632 const_string_type_node
5633 = build_pointer_type (build_qualified_type
5634 (char_type_node
, TYPE_QUAL_CONST
));
5636 /* This is special for C++ so functions can be overloaded. */
5637 wchar_type_node
= get_identifier (MODIFIED_WCHAR_TYPE
);
5638 wchar_type_node
= TREE_TYPE (identifier_global_value (wchar_type_node
));
5639 wchar_type_size
= TYPE_PRECISION (wchar_type_node
);
5640 underlying_wchar_type_node
= wchar_type_node
;
5641 if (c_dialect_cxx ())
5643 if (TYPE_UNSIGNED (wchar_type_node
))
5644 wchar_type_node
= make_unsigned_type (wchar_type_size
);
5646 wchar_type_node
= make_signed_type (wchar_type_size
);
5647 record_builtin_type (RID_WCHAR
, "wchar_t", wchar_type_node
);
5650 /* This is for wide string constants. */
5651 wchar_array_type_node
5652 = build_array_type (wchar_type_node
, array_domain_type
);
5654 /* Define 'char16_t'. */
5655 char16_type_node
= get_identifier (CHAR16_TYPE
);
5656 char16_type_node
= TREE_TYPE (identifier_global_value (char16_type_node
));
5657 char16_type_size
= TYPE_PRECISION (char16_type_node
);
5658 if (c_dialect_cxx ())
5660 char16_type_node
= make_unsigned_type (char16_type_size
);
5662 if (cxx_dialect
>= cxx11
)
5663 record_builtin_type (RID_CHAR16
, "char16_t", char16_type_node
);
5666 /* This is for UTF-16 string constants. */
5667 char16_array_type_node
5668 = build_array_type (char16_type_node
, array_domain_type
);
5670 /* Define 'char32_t'. */
5671 char32_type_node
= get_identifier (CHAR32_TYPE
);
5672 char32_type_node
= TREE_TYPE (identifier_global_value (char32_type_node
));
5673 char32_type_size
= TYPE_PRECISION (char32_type_node
);
5674 if (c_dialect_cxx ())
5676 char32_type_node
= make_unsigned_type (char32_type_size
);
5678 if (cxx_dialect
>= cxx11
)
5679 record_builtin_type (RID_CHAR32
, "char32_t", char32_type_node
);
5682 /* This is for UTF-32 string constants. */
5683 char32_array_type_node
5684 = build_array_type (char32_type_node
, array_domain_type
);
5687 TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE
)));
5690 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE
)));
5692 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE
)));
5694 if (SIG_ATOMIC_TYPE
)
5695 sig_atomic_type_node
=
5696 TREE_TYPE (identifier_global_value (c_get_ident (SIG_ATOMIC_TYPE
)));
5699 TREE_TYPE (identifier_global_value (c_get_ident (INT8_TYPE
)));
5702 TREE_TYPE (identifier_global_value (c_get_ident (INT16_TYPE
)));
5705 TREE_TYPE (identifier_global_value (c_get_ident (INT32_TYPE
)));
5708 TREE_TYPE (identifier_global_value (c_get_ident (INT64_TYPE
)));
5711 TREE_TYPE (identifier_global_value (c_get_ident (UINT8_TYPE
)));
5713 c_uint16_type_node
=
5714 TREE_TYPE (identifier_global_value (c_get_ident (UINT16_TYPE
)));
5716 c_uint32_type_node
=
5717 TREE_TYPE (identifier_global_value (c_get_ident (UINT32_TYPE
)));
5719 c_uint64_type_node
=
5720 TREE_TYPE (identifier_global_value (c_get_ident (UINT64_TYPE
)));
5721 if (INT_LEAST8_TYPE
)
5722 int_least8_type_node
=
5723 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST8_TYPE
)));
5724 if (INT_LEAST16_TYPE
)
5725 int_least16_type_node
=
5726 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST16_TYPE
)));
5727 if (INT_LEAST32_TYPE
)
5728 int_least32_type_node
=
5729 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST32_TYPE
)));
5730 if (INT_LEAST64_TYPE
)
5731 int_least64_type_node
=
5732 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST64_TYPE
)));
5733 if (UINT_LEAST8_TYPE
)
5734 uint_least8_type_node
=
5735 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST8_TYPE
)));
5736 if (UINT_LEAST16_TYPE
)
5737 uint_least16_type_node
=
5738 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST16_TYPE
)));
5739 if (UINT_LEAST32_TYPE
)
5740 uint_least32_type_node
=
5741 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST32_TYPE
)));
5742 if (UINT_LEAST64_TYPE
)
5743 uint_least64_type_node
=
5744 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST64_TYPE
)));
5746 int_fast8_type_node
=
5747 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST8_TYPE
)));
5748 if (INT_FAST16_TYPE
)
5749 int_fast16_type_node
=
5750 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST16_TYPE
)));
5751 if (INT_FAST32_TYPE
)
5752 int_fast32_type_node
=
5753 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST32_TYPE
)));
5754 if (INT_FAST64_TYPE
)
5755 int_fast64_type_node
=
5756 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST64_TYPE
)));
5757 if (UINT_FAST8_TYPE
)
5758 uint_fast8_type_node
=
5759 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST8_TYPE
)));
5760 if (UINT_FAST16_TYPE
)
5761 uint_fast16_type_node
=
5762 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST16_TYPE
)));
5763 if (UINT_FAST32_TYPE
)
5764 uint_fast32_type_node
=
5765 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST32_TYPE
)));
5766 if (UINT_FAST64_TYPE
)
5767 uint_fast64_type_node
=
5768 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST64_TYPE
)));
5771 TREE_TYPE (identifier_global_value (c_get_ident (INTPTR_TYPE
)));
5774 TREE_TYPE (identifier_global_value (c_get_ident (UINTPTR_TYPE
)));
5776 default_function_type
5777 = build_varargs_function_type_list (integer_type_node
, NULL_TREE
);
5779 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE
)));
5780 unsigned_ptrdiff_type_node
= c_common_unsigned_type (ptrdiff_type_node
);
5782 lang_hooks
.decls
.pushdecl
5783 (build_decl (UNKNOWN_LOCATION
,
5784 TYPE_DECL
, get_identifier ("__builtin_va_list"),
5785 va_list_type_node
));
5786 if (targetm
.enum_va_list_p
)
5792 for (l
= 0; targetm
.enum_va_list_p (l
, &pname
, &ptype
); ++l
)
5794 lang_hooks
.decls
.pushdecl
5795 (build_decl (UNKNOWN_LOCATION
,
5796 TYPE_DECL
, get_identifier (pname
),
5802 if (TREE_CODE (va_list_type_node
) == ARRAY_TYPE
)
5804 va_list_arg_type_node
= va_list_ref_type_node
=
5805 build_pointer_type (TREE_TYPE (va_list_type_node
));
5809 va_list_arg_type_node
= va_list_type_node
;
5810 va_list_ref_type_node
= build_reference_type (va_list_type_node
);
5813 if (!flag_preprocess_only
)
5814 c_define_builtins (va_list_ref_type_node
, va_list_arg_type_node
);
5816 main_identifier_node
= get_identifier ("main");
5818 /* Create the built-in __null node. It is important that this is
5820 null_node
= make_node (INTEGER_CST
);
5821 TREE_TYPE (null_node
) = c_common_type_for_size (POINTER_SIZE
, 0);
5823 /* Since builtin_types isn't gc'ed, don't export these nodes. */
5824 memset (builtin_types
, 0, sizeof (builtin_types
));
5827 /* The number of named compound-literals generated thus far. */
5828 static GTY(()) int compound_literal_number
;
5830 /* Set DECL_NAME for DECL, a VAR_DECL for a compound-literal. */
5833 set_compound_literal_name (tree decl
)
5836 ASM_FORMAT_PRIVATE_NAME (name
, "__compound_literal",
5837 compound_literal_number
);
5838 compound_literal_number
++;
5839 DECL_NAME (decl
) = get_identifier (name
);
5843 build_va_arg (location_t loc
, tree expr
, tree type
)
5845 expr
= build1 (VA_ARG_EXPR
, type
, expr
);
5846 SET_EXPR_LOCATION (expr
, loc
);
5851 /* Linked list of disabled built-in functions. */
5853 typedef struct disabled_builtin
5856 struct disabled_builtin
*next
;
5858 static disabled_builtin
*disabled_builtins
= NULL
;
5860 static bool builtin_function_disabled_p (const char *);
5862 /* Disable a built-in function specified by -fno-builtin-NAME. If NAME
5863 begins with "__builtin_", give an error. */
5866 disable_builtin_function (const char *name
)
5868 if (strncmp (name
, "__builtin_", strlen ("__builtin_")) == 0)
5869 error ("cannot disable built-in function %qs", name
);
5872 disabled_builtin
*new_disabled_builtin
= XNEW (disabled_builtin
);
5873 new_disabled_builtin
->name
= name
;
5874 new_disabled_builtin
->next
= disabled_builtins
;
5875 disabled_builtins
= new_disabled_builtin
;
5880 /* Return true if the built-in function NAME has been disabled, false
5884 builtin_function_disabled_p (const char *name
)
5886 disabled_builtin
*p
;
5887 for (p
= disabled_builtins
; p
!= NULL
; p
= p
->next
)
5889 if (strcmp (name
, p
->name
) == 0)
5896 /* Worker for DEF_BUILTIN.
5897 Possibly define a builtin function with one or two names.
5898 Does not declare a non-__builtin_ function if flag_no_builtin, or if
5899 nonansi_p and flag_no_nonansi_builtin. */
5902 def_builtin_1 (enum built_in_function fncode
,
5904 enum built_in_class fnclass
,
5905 tree fntype
, tree libtype
,
5906 bool both_p
, bool fallback_p
, bool nonansi_p
,
5907 tree fnattrs
, bool implicit_p
)
5910 const char *libname
;
5912 if (fntype
== error_mark_node
)
5915 gcc_assert ((!both_p
&& !fallback_p
)
5916 || !strncmp (name
, "__builtin_",
5917 strlen ("__builtin_")));
5919 libname
= name
+ strlen ("__builtin_");
5920 decl
= add_builtin_function (name
, fntype
, fncode
, fnclass
,
5921 (fallback_p
? libname
: NULL
),
5924 set_builtin_decl (fncode
, decl
, implicit_p
);
5927 && !flag_no_builtin
&& !builtin_function_disabled_p (libname
)
5928 && !(nonansi_p
&& flag_no_nonansi_builtin
))
5929 add_builtin_function (libname
, libtype
, fncode
, fnclass
,
5933 /* Nonzero if the type T promotes to int. This is (nearly) the
5934 integral promotions defined in ISO C99 6.3.1.1/2. */
5937 c_promoting_integer_type_p (const_tree t
)
5939 switch (TREE_CODE (t
))
5942 return (TYPE_MAIN_VARIANT (t
) == char_type_node
5943 || TYPE_MAIN_VARIANT (t
) == signed_char_type_node
5944 || TYPE_MAIN_VARIANT (t
) == unsigned_char_type_node
5945 || TYPE_MAIN_VARIANT (t
) == short_integer_type_node
5946 || TYPE_MAIN_VARIANT (t
) == short_unsigned_type_node
5947 || TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
));
5950 /* ??? Technically all enumerations not larger than an int
5951 promote to an int. But this is used along code paths
5952 that only want to notice a size change. */
5953 return TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
);
5963 /* Return 1 if PARMS specifies a fixed number of parameters
5964 and none of their types is affected by default promotions. */
5967 self_promoting_args_p (const_tree parms
)
5970 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
5972 tree type
= TREE_VALUE (t
);
5974 if (type
== error_mark_node
)
5977 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
5983 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
5986 if (c_promoting_integer_type_p (type
))
5992 /* Recursively remove any '*' or '&' operator from TYPE. */
5994 strip_pointer_operator (tree t
)
5996 while (POINTER_TYPE_P (t
))
6001 /* Recursively remove pointer or array type from TYPE. */
6003 strip_pointer_or_array_types (tree t
)
6005 while (TREE_CODE (t
) == ARRAY_TYPE
|| POINTER_TYPE_P (t
))
6010 /* Used to compare case labels. K1 and K2 are actually tree nodes
6011 representing case labels, or NULL_TREE for a `default' label.
6012 Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after
6013 K2, and 0 if K1 and K2 are equal. */
6016 case_compare (splay_tree_key k1
, splay_tree_key k2
)
6018 /* Consider a NULL key (such as arises with a `default' label) to be
6019 smaller than anything else. */
6025 return tree_int_cst_compare ((tree
) k1
, (tree
) k2
);
6028 /* Process a case label, located at LOC, for the range LOW_VALUE
6029 ... HIGH_VALUE. If LOW_VALUE and HIGH_VALUE are both NULL_TREE
6030 then this case label is actually a `default' label. If only
6031 HIGH_VALUE is NULL_TREE, then case label was declared using the
6032 usual C/C++ syntax, rather than the GNU case range extension.
6033 CASES is a tree containing all the case ranges processed so far;
6034 COND is the condition for the switch-statement itself. Returns the
6035 CASE_LABEL_EXPR created, or ERROR_MARK_NODE if no CASE_LABEL_EXPR
6039 c_add_case_label (location_t loc
, splay_tree cases
, tree cond
, tree orig_type
,
6040 tree low_value
, tree high_value
)
6045 splay_tree_node node
;
6047 /* Create the LABEL_DECL itself. */
6048 label
= create_artificial_label (loc
);
6050 /* If there was an error processing the switch condition, bail now
6051 before we get more confused. */
6052 if (!cond
|| cond
== error_mark_node
)
6055 if ((low_value
&& TREE_TYPE (low_value
)
6056 && POINTER_TYPE_P (TREE_TYPE (low_value
)))
6057 || (high_value
&& TREE_TYPE (high_value
)
6058 && POINTER_TYPE_P (TREE_TYPE (high_value
))))
6060 error_at (loc
, "pointers are not permitted as case values");
6064 /* Case ranges are a GNU extension. */
6066 pedwarn (loc
, OPT_Wpedantic
,
6067 "range expressions in switch statements are non-standard");
6069 type
= TREE_TYPE (cond
);
6072 low_value
= check_case_value (low_value
);
6073 low_value
= convert_and_check (type
, low_value
);
6074 if (low_value
== error_mark_node
)
6079 high_value
= check_case_value (high_value
);
6080 high_value
= convert_and_check (type
, high_value
);
6081 if (high_value
== error_mark_node
)
6085 if (low_value
&& high_value
)
6087 /* If the LOW_VALUE and HIGH_VALUE are the same, then this isn't
6088 really a case range, even though it was written that way.
6089 Remove the HIGH_VALUE to simplify later processing. */
6090 if (tree_int_cst_equal (low_value
, high_value
))
6091 high_value
= NULL_TREE
;
6092 else if (!tree_int_cst_lt (low_value
, high_value
))
6093 warning_at (loc
, 0, "empty range specified");
6096 /* See if the case is in range of the type of the original testing
6097 expression. If both low_value and high_value are out of range,
6098 don't insert the case label and return NULL_TREE. */
6100 && !check_case_bounds (type
, orig_type
,
6101 &low_value
, high_value
? &high_value
: NULL
))
6104 /* Look up the LOW_VALUE in the table of case labels we already
6106 node
= splay_tree_lookup (cases
, (splay_tree_key
) low_value
);
6107 /* If there was not an exact match, check for overlapping ranges.
6108 There's no need to do this if there's no LOW_VALUE or HIGH_VALUE;
6109 that's a `default' label and the only overlap is an exact match. */
6110 if (!node
&& (low_value
|| high_value
))
6112 splay_tree_node low_bound
;
6113 splay_tree_node high_bound
;
6115 /* Even though there wasn't an exact match, there might be an
6116 overlap between this case range and another case range.
6117 Since we've (inductively) not allowed any overlapping case
6118 ranges, we simply need to find the greatest low case label
6119 that is smaller that LOW_VALUE, and the smallest low case
6120 label that is greater than LOW_VALUE. If there is an overlap
6121 it will occur in one of these two ranges. */
6122 low_bound
= splay_tree_predecessor (cases
,
6123 (splay_tree_key
) low_value
);
6124 high_bound
= splay_tree_successor (cases
,
6125 (splay_tree_key
) low_value
);
6127 /* Check to see if the LOW_BOUND overlaps. It is smaller than
6128 the LOW_VALUE, so there is no need to check unless the
6129 LOW_BOUND is in fact itself a case range. */
6131 && CASE_HIGH ((tree
) low_bound
->value
)
6132 && tree_int_cst_compare (CASE_HIGH ((tree
) low_bound
->value
),
6135 /* Check to see if the HIGH_BOUND overlaps. The low end of that
6136 range is bigger than the low end of the current range, so we
6137 are only interested if the current range is a real range, and
6138 not an ordinary case label. */
6141 && (tree_int_cst_compare ((tree
) high_bound
->key
,
6146 /* If there was an overlap, issue an error. */
6149 tree duplicate
= CASE_LABEL ((tree
) node
->value
);
6153 error_at (loc
, "duplicate (or overlapping) case value");
6154 error_at (DECL_SOURCE_LOCATION (duplicate
),
6155 "this is the first entry overlapping that value");
6159 error_at (loc
, "duplicate case value") ;
6160 error_at (DECL_SOURCE_LOCATION (duplicate
), "previously used here");
6164 error_at (loc
, "multiple default labels in one switch");
6165 error_at (DECL_SOURCE_LOCATION (duplicate
),
6166 "this is the first default label");
6171 /* Add a CASE_LABEL to the statement-tree. */
6172 case_label
= add_stmt (build_case_label (low_value
, high_value
, label
));
6173 /* Register this case label in the splay tree. */
6174 splay_tree_insert (cases
,
6175 (splay_tree_key
) low_value
,
6176 (splay_tree_value
) case_label
);
6181 /* Add a label so that the back-end doesn't think that the beginning of
6182 the switch is unreachable. Note that we do not add a case label, as
6183 that just leads to duplicates and thence to failure later on. */
6186 tree t
= create_artificial_label (loc
);
6187 add_stmt (build_stmt (loc
, LABEL_EXPR
, t
));
6189 return error_mark_node
;
6192 /* Subroutines of c_do_switch_warnings, called via splay_tree_foreach.
6193 Used to verify that case values match up with enumerator values. */
6196 match_case_to_enum_1 (tree key
, tree type
, tree label
)
6198 char buf
[2 + 2*HOST_BITS_PER_WIDE_INT
/4 + 1];
6200 /* ??? Not working too hard to print the double-word value.
6201 Should perhaps be done with %lwd in the diagnostic routines? */
6202 if (TREE_INT_CST_HIGH (key
) == 0)
6203 snprintf (buf
, sizeof (buf
), HOST_WIDE_INT_PRINT_UNSIGNED
,
6204 TREE_INT_CST_LOW (key
));
6205 else if (!TYPE_UNSIGNED (type
)
6206 && TREE_INT_CST_HIGH (key
) == -1
6207 && TREE_INT_CST_LOW (key
) != 0)
6208 snprintf (buf
, sizeof (buf
), "-" HOST_WIDE_INT_PRINT_UNSIGNED
,
6209 -TREE_INT_CST_LOW (key
));
6211 snprintf (buf
, sizeof (buf
), HOST_WIDE_INT_PRINT_DOUBLE_HEX
,
6212 (unsigned HOST_WIDE_INT
) TREE_INT_CST_HIGH (key
),
6213 (unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (key
));
6215 if (TYPE_NAME (type
) == 0)
6216 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
6217 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
6218 "case value %qs not in enumerated type",
6221 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
6222 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
6223 "case value %qs not in enumerated type %qT",
6227 /* Subroutine of c_do_switch_warnings, called via splay_tree_foreach.
6228 Used to verify that case values match up with enumerator values. */
6231 match_case_to_enum (splay_tree_node node
, void *data
)
6233 tree label
= (tree
) node
->value
;
6234 tree type
= (tree
) data
;
6236 /* Skip default case. */
6237 if (!CASE_LOW (label
))
6240 /* If CASE_LOW_SEEN is not set, that means CASE_LOW did not appear
6241 when we did our enum->case scan. Reset our scratch bit after. */
6242 if (!CASE_LOW_SEEN (label
))
6243 match_case_to_enum_1 (CASE_LOW (label
), type
, label
);
6245 CASE_LOW_SEEN (label
) = 0;
6247 /* If CASE_HIGH is non-null, we have a range. If CASE_HIGH_SEEN is
6248 not set, that means that CASE_HIGH did not appear when we did our
6249 enum->case scan. Reset our scratch bit after. */
6250 if (CASE_HIGH (label
))
6252 if (!CASE_HIGH_SEEN (label
))
6253 match_case_to_enum_1 (CASE_HIGH (label
), type
, label
);
6255 CASE_HIGH_SEEN (label
) = 0;
6261 /* Handle -Wswitch*. Called from the front end after parsing the
6262 switch construct. */
6263 /* ??? Should probably be somewhere generic, since other languages
6264 besides C and C++ would want this. At the moment, however, C/C++
6265 are the only tree-ssa languages that support enumerations at all,
6266 so the point is moot. */
6269 c_do_switch_warnings (splay_tree cases
, location_t switch_location
,
6270 tree type
, tree cond
)
6272 splay_tree_node default_node
;
6273 splay_tree_node node
;
6276 if (!warn_switch
&& !warn_switch_enum
&& !warn_switch_default
)
6279 default_node
= splay_tree_lookup (cases
, (splay_tree_key
) NULL
);
6281 warning_at (switch_location
, OPT_Wswitch_default
,
6282 "switch missing default case");
6284 /* From here on, we only care about about enumerated types. */
6285 if (!type
|| TREE_CODE (type
) != ENUMERAL_TYPE
)
6288 /* From here on, we only care about -Wswitch and -Wswitch-enum. */
6289 if (!warn_switch_enum
&& !warn_switch
)
6292 /* Check the cases. Warn about case values which are not members of
6293 the enumerated type. For -Wswitch-enum, or for -Wswitch when
6294 there is no default case, check that exactly all enumeration
6295 literals are covered by the cases. */
6297 /* Clearing COND if it is not an integer constant simplifies
6298 the tests inside the loop below. */
6299 if (TREE_CODE (cond
) != INTEGER_CST
)
6302 /* The time complexity here is O(N*lg(N)) worst case, but for the
6303 common case of monotonically increasing enumerators, it is
6304 O(N), since the nature of the splay tree will keep the next
6305 element adjacent to the root at all times. */
6307 for (chain
= TYPE_VALUES (type
); chain
; chain
= TREE_CHAIN (chain
))
6309 tree value
= TREE_VALUE (chain
);
6310 if (TREE_CODE (value
) == CONST_DECL
)
6311 value
= DECL_INITIAL (value
);
6312 node
= splay_tree_lookup (cases
, (splay_tree_key
) value
);
6315 /* Mark the CASE_LOW part of the case entry as seen. */
6316 tree label
= (tree
) node
->value
;
6317 CASE_LOW_SEEN (label
) = 1;
6321 /* Even though there wasn't an exact match, there might be a
6322 case range which includes the enumerator's value. */
6323 node
= splay_tree_predecessor (cases
, (splay_tree_key
) value
);
6324 if (node
&& CASE_HIGH ((tree
) node
->value
))
6326 tree label
= (tree
) node
->value
;
6327 int cmp
= tree_int_cst_compare (CASE_HIGH (label
), value
);
6330 /* If we match the upper bound exactly, mark the CASE_HIGH
6331 part of the case entry as seen. */
6333 CASE_HIGH_SEEN (label
) = 1;
6338 /* We've now determined that this enumerated literal isn't
6339 handled by the case labels of the switch statement. */
6341 /* If the switch expression is a constant, we only really care
6342 about whether that constant is handled by the switch. */
6343 if (cond
&& tree_int_cst_compare (cond
, value
))
6346 /* If there is a default_node, the only relevant option is
6347 Wswitch-enum. Otherwise, if both are enabled then we prefer
6348 to warn using -Wswitch because -Wswitch is enabled by -Wall
6349 while -Wswitch-enum is explicit. */
6350 warning_at (switch_location
,
6351 (default_node
|| !warn_switch
6354 "enumeration value %qE not handled in switch",
6355 TREE_PURPOSE (chain
));
6358 /* Warn if there are case expressions that don't correspond to
6359 enumerators. This can occur since C and C++ don't enforce
6360 type-checking of assignments to enumeration variables.
6362 The time complexity here is now always O(N) worst case, since
6363 we should have marked both the lower bound and upper bound of
6364 every disjoint case label, with CASE_LOW_SEEN and CASE_HIGH_SEEN
6365 above. This scan also resets those fields. */
6367 splay_tree_foreach (cases
, match_case_to_enum
, type
);
6370 /* Finish an expression taking the address of LABEL (an
6371 IDENTIFIER_NODE). Returns an expression for the address.
6373 LOC is the location for the expression returned. */
6376 finish_label_address_expr (tree label
, location_t loc
)
6380 pedwarn (input_location
, OPT_Wpedantic
, "taking the address of a label is non-standard");
6382 if (label
== error_mark_node
)
6383 return error_mark_node
;
6385 label
= lookup_label (label
);
6386 if (label
== NULL_TREE
)
6387 result
= null_pointer_node
;
6390 TREE_USED (label
) = 1;
6391 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
6392 /* The current function is not necessarily uninlinable.
6393 Computed gotos are incompatible with inlining, but the value
6394 here could be used only in a diagnostic, for example. */
6395 protected_set_expr_location (result
, loc
);
6402 /* Given a boolean expression ARG, return a tree representing an increment
6403 or decrement (as indicated by CODE) of ARG. The front end must check for
6404 invalid cases (e.g., decrement in C++). */
6406 boolean_increment (enum tree_code code
, tree arg
)
6409 tree true_res
= build_int_cst (TREE_TYPE (arg
), 1);
6411 arg
= stabilize_reference (arg
);
6414 case PREINCREMENT_EXPR
:
6415 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
6417 case POSTINCREMENT_EXPR
:
6418 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
6419 arg
= save_expr (arg
);
6420 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
6421 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
6423 case PREDECREMENT_EXPR
:
6424 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
6425 invert_truthvalue_loc (input_location
, arg
));
6427 case POSTDECREMENT_EXPR
:
6428 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
6429 invert_truthvalue_loc (input_location
, arg
));
6430 arg
= save_expr (arg
);
6431 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
6432 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
6437 TREE_SIDE_EFFECTS (val
) = 1;
6441 /* Built-in macros for stddef.h and stdint.h, that require macros
6442 defined in this file. */
6444 c_stddef_cpp_builtins(void)
6446 builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE
, 0);
6447 builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE
, 0);
6448 builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE
, 0);
6449 builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE
, 0);
6450 builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE
, 0);
6451 builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE
, 0);
6452 builtin_define_with_value ("__CHAR16_TYPE__", CHAR16_TYPE
, 0);
6453 builtin_define_with_value ("__CHAR32_TYPE__", CHAR32_TYPE
, 0);
6454 if (SIG_ATOMIC_TYPE
)
6455 builtin_define_with_value ("__SIG_ATOMIC_TYPE__", SIG_ATOMIC_TYPE
, 0);
6457 builtin_define_with_value ("__INT8_TYPE__", INT8_TYPE
, 0);
6459 builtin_define_with_value ("__INT16_TYPE__", INT16_TYPE
, 0);
6461 builtin_define_with_value ("__INT32_TYPE__", INT32_TYPE
, 0);
6463 builtin_define_with_value ("__INT64_TYPE__", INT64_TYPE
, 0);
6465 builtin_define_with_value ("__UINT8_TYPE__", UINT8_TYPE
, 0);
6467 builtin_define_with_value ("__UINT16_TYPE__", UINT16_TYPE
, 0);
6469 builtin_define_with_value ("__UINT32_TYPE__", UINT32_TYPE
, 0);
6471 builtin_define_with_value ("__UINT64_TYPE__", UINT64_TYPE
, 0);
6472 if (INT_LEAST8_TYPE
)
6473 builtin_define_with_value ("__INT_LEAST8_TYPE__", INT_LEAST8_TYPE
, 0);
6474 if (INT_LEAST16_TYPE
)
6475 builtin_define_with_value ("__INT_LEAST16_TYPE__", INT_LEAST16_TYPE
, 0);
6476 if (INT_LEAST32_TYPE
)
6477 builtin_define_with_value ("__INT_LEAST32_TYPE__", INT_LEAST32_TYPE
, 0);
6478 if (INT_LEAST64_TYPE
)
6479 builtin_define_with_value ("__INT_LEAST64_TYPE__", INT_LEAST64_TYPE
, 0);
6480 if (UINT_LEAST8_TYPE
)
6481 builtin_define_with_value ("__UINT_LEAST8_TYPE__", UINT_LEAST8_TYPE
, 0);
6482 if (UINT_LEAST16_TYPE
)
6483 builtin_define_with_value ("__UINT_LEAST16_TYPE__", UINT_LEAST16_TYPE
, 0);
6484 if (UINT_LEAST32_TYPE
)
6485 builtin_define_with_value ("__UINT_LEAST32_TYPE__", UINT_LEAST32_TYPE
, 0);
6486 if (UINT_LEAST64_TYPE
)
6487 builtin_define_with_value ("__UINT_LEAST64_TYPE__", UINT_LEAST64_TYPE
, 0);
6489 builtin_define_with_value ("__INT_FAST8_TYPE__", INT_FAST8_TYPE
, 0);
6490 if (INT_FAST16_TYPE
)
6491 builtin_define_with_value ("__INT_FAST16_TYPE__", INT_FAST16_TYPE
, 0);
6492 if (INT_FAST32_TYPE
)
6493 builtin_define_with_value ("__INT_FAST32_TYPE__", INT_FAST32_TYPE
, 0);
6494 if (INT_FAST64_TYPE
)
6495 builtin_define_with_value ("__INT_FAST64_TYPE__", INT_FAST64_TYPE
, 0);
6496 if (UINT_FAST8_TYPE
)
6497 builtin_define_with_value ("__UINT_FAST8_TYPE__", UINT_FAST8_TYPE
, 0);
6498 if (UINT_FAST16_TYPE
)
6499 builtin_define_with_value ("__UINT_FAST16_TYPE__", UINT_FAST16_TYPE
, 0);
6500 if (UINT_FAST32_TYPE
)
6501 builtin_define_with_value ("__UINT_FAST32_TYPE__", UINT_FAST32_TYPE
, 0);
6502 if (UINT_FAST64_TYPE
)
6503 builtin_define_with_value ("__UINT_FAST64_TYPE__", UINT_FAST64_TYPE
, 0);
6505 builtin_define_with_value ("__INTPTR_TYPE__", INTPTR_TYPE
, 0);
6507 builtin_define_with_value ("__UINTPTR_TYPE__", UINTPTR_TYPE
, 0);
6511 c_init_attributes (void)
6513 /* Fill in the built_in_attributes array. */
6514 #define DEF_ATTR_NULL_TREE(ENUM) \
6515 built_in_attributes[(int) ENUM] = NULL_TREE;
6516 #define DEF_ATTR_INT(ENUM, VALUE) \
6517 built_in_attributes[(int) ENUM] = build_int_cst (integer_type_node, VALUE);
6518 #define DEF_ATTR_STRING(ENUM, VALUE) \
6519 built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
6520 #define DEF_ATTR_IDENT(ENUM, STRING) \
6521 built_in_attributes[(int) ENUM] = get_identifier (STRING);
6522 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
6523 built_in_attributes[(int) ENUM] \
6524 = tree_cons (built_in_attributes[(int) PURPOSE], \
6525 built_in_attributes[(int) VALUE], \
6526 built_in_attributes[(int) CHAIN]);
6527 #include "builtin-attrs.def"
6528 #undef DEF_ATTR_NULL_TREE
6530 #undef DEF_ATTR_IDENT
6531 #undef DEF_ATTR_TREE_LIST
6534 /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain
6535 identifier as an argument, so the front end shouldn't look it up. */
6538 attribute_takes_identifier_p (const_tree attr_id
)
6540 const struct attribute_spec
*spec
= lookup_attribute_spec (attr_id
);
6542 /* Unknown attribute that we'll end up ignoring, return true so we
6543 don't complain about an identifier argument. */
6545 else if (!strcmp ("mode", spec
->name
)
6546 || !strcmp ("format", spec
->name
)
6547 || !strcmp ("cleanup", spec
->name
))
6550 return targetm
.attribute_takes_identifier_p (attr_id
);
6553 /* Attribute handlers common to C front ends. */
6555 /* Handle a "packed" attribute; arguments as in
6556 struct attribute_spec.handler. */
6559 handle_packed_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6560 int flags
, bool *no_add_attrs
)
6564 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6565 *node
= build_variant_type_copy (*node
);
6566 TYPE_PACKED (*node
) = 1;
6568 else if (TREE_CODE (*node
) == FIELD_DECL
)
6570 if (TYPE_ALIGN (TREE_TYPE (*node
)) <= BITS_PER_UNIT
6571 /* Still pack bitfields. */
6572 && ! DECL_INITIAL (*node
))
6573 warning (OPT_Wattributes
,
6574 "%qE attribute ignored for field of type %qT",
6575 name
, TREE_TYPE (*node
));
6577 DECL_PACKED (*node
) = 1;
6579 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
6580 used for DECL_REGISTER. It wouldn't mean anything anyway.
6581 We can't set DECL_PACKED on the type of a TYPE_DECL, because
6582 that changes what the typedef is typing. */
6585 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6586 *no_add_attrs
= true;
6592 /* Handle a "nocommon" attribute; arguments as in
6593 struct attribute_spec.handler. */
6596 handle_nocommon_attribute (tree
*node
, tree name
,
6597 tree
ARG_UNUSED (args
),
6598 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6600 if (TREE_CODE (*node
) == VAR_DECL
)
6601 DECL_COMMON (*node
) = 0;
6604 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6605 *no_add_attrs
= true;
6611 /* Handle a "common" attribute; arguments as in
6612 struct attribute_spec.handler. */
6615 handle_common_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6616 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6618 if (TREE_CODE (*node
) == VAR_DECL
)
6619 DECL_COMMON (*node
) = 1;
6622 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6623 *no_add_attrs
= true;
6629 /* Handle a "noreturn" attribute; arguments as in
6630 struct attribute_spec.handler. */
6633 handle_noreturn_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6634 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6636 tree type
= TREE_TYPE (*node
);
6638 /* See FIXME comment in c_common_attribute_table. */
6639 if (TREE_CODE (*node
) == FUNCTION_DECL
6640 || objc_method_decl (TREE_CODE (*node
)))
6641 TREE_THIS_VOLATILE (*node
) = 1;
6642 else if (TREE_CODE (type
) == POINTER_TYPE
6643 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
6645 = build_pointer_type
6646 (build_type_variant (TREE_TYPE (type
),
6647 TYPE_READONLY (TREE_TYPE (type
)), 1));
6650 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6651 *no_add_attrs
= true;
6657 /* Handle a "hot" and attribute; arguments as in
6658 struct attribute_spec.handler. */
6661 handle_hot_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6662 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6664 if (TREE_CODE (*node
) == FUNCTION_DECL
6665 || TREE_CODE (*node
) == LABEL_DECL
)
6667 if (lookup_attribute ("cold", DECL_ATTRIBUTES (*node
)) != NULL
)
6669 warning (OPT_Wattributes
, "%qE attribute conflicts with attribute %s",
6671 *no_add_attrs
= true;
6673 /* Most of the rest of the hot processing is done later with
6674 lookup_attribute. */
6678 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6679 *no_add_attrs
= true;
6685 /* Handle a "cold" and attribute; arguments as in
6686 struct attribute_spec.handler. */
6689 handle_cold_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6690 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6692 if (TREE_CODE (*node
) == FUNCTION_DECL
6693 || TREE_CODE (*node
) == LABEL_DECL
)
6695 if (lookup_attribute ("hot", DECL_ATTRIBUTES (*node
)) != NULL
)
6697 warning (OPT_Wattributes
, "%qE attribute conflicts with attribute %s",
6699 *no_add_attrs
= true;
6701 /* Most of the rest of the cold processing is done later with
6702 lookup_attribute. */
6706 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6707 *no_add_attrs
= true;
6713 /* Handle a "no_sanitize_address" attribute; arguments as in
6714 struct attribute_spec.handler. */
6717 handle_no_sanitize_address_attribute (tree
*node
, tree name
, tree
, int,
6720 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6722 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6723 *no_add_attrs
= true;
6729 /* Handle a "no_address_safety_analysis" attribute; arguments as in
6730 struct attribute_spec.handler. */
6733 handle_no_address_safety_analysis_attribute (tree
*node
, tree name
, tree
, int,
6736 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6737 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6738 else if (!lookup_attribute ("no_sanitize_address", DECL_ATTRIBUTES (*node
)))
6739 DECL_ATTRIBUTES (*node
)
6740 = tree_cons (get_identifier ("no_sanitize_address"),
6741 NULL_TREE
, DECL_ATTRIBUTES (*node
));
6742 *no_add_attrs
= true;
6746 /* Handle a "no_sanitize_undefined" attribute; arguments as in
6747 struct attribute_spec.handler. */
6750 handle_no_sanitize_undefined_attribute (tree
*node
, tree name
, tree
, int,
6753 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6755 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6756 *no_add_attrs
= true;
6762 /* Handle a "noinline" attribute; arguments as in
6763 struct attribute_spec.handler. */
6766 handle_noinline_attribute (tree
*node
, tree name
,
6767 tree
ARG_UNUSED (args
),
6768 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6770 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6771 DECL_UNINLINABLE (*node
) = 1;
6774 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6775 *no_add_attrs
= true;
6781 /* Handle a "noclone" attribute; arguments as in
6782 struct attribute_spec.handler. */
6785 handle_noclone_attribute (tree
*node
, tree name
,
6786 tree
ARG_UNUSED (args
),
6787 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6789 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6791 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6792 *no_add_attrs
= true;
6798 /* Handle a "always_inline" attribute; arguments as in
6799 struct attribute_spec.handler. */
6802 handle_always_inline_attribute (tree
*node
, tree name
,
6803 tree
ARG_UNUSED (args
),
6804 int ARG_UNUSED (flags
),
6807 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6809 /* Set the attribute and mark it for disregarding inline
6811 DECL_DISREGARD_INLINE_LIMITS (*node
) = 1;
6815 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6816 *no_add_attrs
= true;
6822 /* Handle a "gnu_inline" attribute; arguments as in
6823 struct attribute_spec.handler. */
6826 handle_gnu_inline_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 "leaf" attribute; arguments as in
6846 struct attribute_spec.handler. */
6849 handle_leaf_attribute (tree
*node
, tree name
,
6850 tree
ARG_UNUSED (args
),
6851 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6853 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6855 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6856 *no_add_attrs
= true;
6858 if (!TREE_PUBLIC (*node
))
6860 warning (OPT_Wattributes
, "%qE attribute has no effect on unit local functions", name
);
6861 *no_add_attrs
= true;
6867 /* Handle an "artificial" attribute; arguments as in
6868 struct attribute_spec.handler. */
6871 handle_artificial_attribute (tree
*node
, tree name
,
6872 tree
ARG_UNUSED (args
),
6873 int ARG_UNUSED (flags
),
6876 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
6878 /* Do nothing else, just set the attribute. We'll get at
6879 it later with lookup_attribute. */
6883 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6884 *no_add_attrs
= true;
6890 /* Handle a "flatten" attribute; arguments as in
6891 struct attribute_spec.handler. */
6894 handle_flatten_attribute (tree
*node
, tree name
,
6895 tree args ATTRIBUTE_UNUSED
,
6896 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
6898 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6899 /* Do nothing else, just set the attribute. We'll get at
6900 it later with lookup_attribute. */
6904 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6905 *no_add_attrs
= true;
6911 /* Handle a "warning" or "error" attribute; arguments as in
6912 struct attribute_spec.handler. */
6915 handle_error_attribute (tree
*node
, tree name
, tree args
,
6916 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6918 if (TREE_CODE (*node
) == FUNCTION_DECL
6919 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
6920 /* Do nothing else, just set the attribute. We'll get at
6921 it later with lookup_attribute. */
6925 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6926 *no_add_attrs
= true;
6932 /* Handle a "used" attribute; arguments as in
6933 struct attribute_spec.handler. */
6936 handle_used_attribute (tree
*pnode
, tree name
, tree
ARG_UNUSED (args
),
6937 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6941 if (TREE_CODE (node
) == FUNCTION_DECL
6942 || (TREE_CODE (node
) == VAR_DECL
&& TREE_STATIC (node
))
6943 || (TREE_CODE (node
) == TYPE_DECL
))
6945 TREE_USED (node
) = 1;
6946 DECL_PRESERVE_P (node
) = 1;
6947 if (TREE_CODE (node
) == VAR_DECL
)
6948 DECL_READ_P (node
) = 1;
6952 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6953 *no_add_attrs
= true;
6959 /* Handle a "unused" attribute; arguments as in
6960 struct attribute_spec.handler. */
6963 handle_unused_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6964 int flags
, bool *no_add_attrs
)
6970 if (TREE_CODE (decl
) == PARM_DECL
6971 || TREE_CODE (decl
) == VAR_DECL
6972 || TREE_CODE (decl
) == FUNCTION_DECL
6973 || TREE_CODE (decl
) == LABEL_DECL
6974 || TREE_CODE (decl
) == TYPE_DECL
)
6976 TREE_USED (decl
) = 1;
6977 if (TREE_CODE (decl
) == VAR_DECL
6978 || TREE_CODE (decl
) == PARM_DECL
)
6979 DECL_READ_P (decl
) = 1;
6983 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6984 *no_add_attrs
= true;
6989 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6990 *node
= build_variant_type_copy (*node
);
6991 TREE_USED (*node
) = 1;
6997 /* Handle a "externally_visible" attribute; arguments as in
6998 struct attribute_spec.handler. */
7001 handle_externally_visible_attribute (tree
*pnode
, tree name
,
7002 tree
ARG_UNUSED (args
),
7003 int ARG_UNUSED (flags
),
7008 if (TREE_CODE (node
) == FUNCTION_DECL
|| TREE_CODE (node
) == VAR_DECL
)
7010 if ((!TREE_STATIC (node
) && TREE_CODE (node
) != FUNCTION_DECL
7011 && !DECL_EXTERNAL (node
)) || !TREE_PUBLIC (node
))
7013 warning (OPT_Wattributes
,
7014 "%qE attribute have effect only on public objects", name
);
7015 *no_add_attrs
= true;
7020 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7021 *no_add_attrs
= true;
7027 /* Handle a "const" attribute; arguments as in
7028 struct attribute_spec.handler. */
7031 handle_const_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7032 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7034 tree type
= TREE_TYPE (*node
);
7036 /* See FIXME comment on noreturn in c_common_attribute_table. */
7037 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7038 TREE_READONLY (*node
) = 1;
7039 else if (TREE_CODE (type
) == POINTER_TYPE
7040 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
7042 = build_pointer_type
7043 (build_type_variant (TREE_TYPE (type
), 1,
7044 TREE_THIS_VOLATILE (TREE_TYPE (type
))));
7047 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7048 *no_add_attrs
= true;
7054 /* Handle a "transparent_union" attribute; arguments as in
7055 struct attribute_spec.handler. */
7058 handle_transparent_union_attribute (tree
*node
, tree name
,
7059 tree
ARG_UNUSED (args
), int flags
,
7064 *no_add_attrs
= true;
7067 if (TREE_CODE (*node
) == TYPE_DECL
7068 && ! (flags
& ATTR_FLAG_CXX11
))
7069 node
= &TREE_TYPE (*node
);
7072 if (TREE_CODE (type
) == UNION_TYPE
)
7074 /* Make sure that the first field will work for a transparent union.
7075 If the type isn't complete yet, leave the check to the code in
7077 if (TYPE_SIZE (type
))
7079 tree first
= first_field (type
);
7080 if (first
== NULL_TREE
7081 || DECL_ARTIFICIAL (first
)
7082 || TYPE_MODE (type
) != DECL_MODE (first
))
7086 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7088 /* If the type isn't complete yet, setting the flag
7089 on a variant wouldn't ever be checked. */
7090 if (!TYPE_SIZE (type
))
7093 /* build_duplicate_type doesn't work for C++. */
7094 if (c_dialect_cxx ())
7097 /* A type variant isn't good enough, since we don't a cast
7098 to such a type removed as a no-op. */
7099 *node
= type
= build_duplicate_type (type
);
7102 TYPE_TRANSPARENT_AGGR (type
) = 1;
7107 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7111 /* Subroutine of handle_{con,de}structor_attribute. Evaluate ARGS to
7112 get the requested priority for a constructor or destructor,
7113 possibly issuing diagnostics for invalid or reserved
7116 static priority_type
7117 get_priority (tree args
, bool is_destructor
)
7123 return DEFAULT_INIT_PRIORITY
;
7125 if (!SUPPORTS_INIT_PRIORITY
)
7128 error ("destructor priorities are not supported");
7130 error ("constructor priorities are not supported");
7131 return DEFAULT_INIT_PRIORITY
;
7134 arg
= TREE_VALUE (args
);
7135 if (TREE_CODE (arg
) == IDENTIFIER_NODE
)
7137 if (arg
== error_mark_node
)
7138 return DEFAULT_INIT_PRIORITY
;
7139 arg
= default_conversion (arg
);
7140 if (!tree_fits_shwi_p (arg
)
7141 || !INTEGRAL_TYPE_P (TREE_TYPE (arg
)))
7144 pri
= tree_to_shwi (arg
);
7145 if (pri
< 0 || pri
> MAX_INIT_PRIORITY
)
7148 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
7152 "destructor priorities from 0 to %d are reserved "
7153 "for the implementation",
7154 MAX_RESERVED_INIT_PRIORITY
);
7157 "constructor priorities from 0 to %d are reserved "
7158 "for the implementation",
7159 MAX_RESERVED_INIT_PRIORITY
);
7165 error ("destructor priorities must be integers from 0 to %d inclusive",
7168 error ("constructor priorities must be integers from 0 to %d inclusive",
7170 return DEFAULT_INIT_PRIORITY
;
7173 /* Handle a "constructor" attribute; arguments as in
7174 struct attribute_spec.handler. */
7177 handle_constructor_attribute (tree
*node
, tree name
, tree args
,
7178 int ARG_UNUSED (flags
),
7182 tree type
= TREE_TYPE (decl
);
7184 if (TREE_CODE (decl
) == FUNCTION_DECL
7185 && TREE_CODE (type
) == FUNCTION_TYPE
7186 && decl_function_context (decl
) == 0)
7188 priority_type priority
;
7189 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
7190 priority
= get_priority (args
, /*is_destructor=*/false);
7191 SET_DECL_INIT_PRIORITY (decl
, priority
);
7192 TREE_USED (decl
) = 1;
7196 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7197 *no_add_attrs
= true;
7203 /* Handle a "destructor" attribute; arguments as in
7204 struct attribute_spec.handler. */
7207 handle_destructor_attribute (tree
*node
, tree name
, tree args
,
7208 int ARG_UNUSED (flags
),
7212 tree type
= TREE_TYPE (decl
);
7214 if (TREE_CODE (decl
) == FUNCTION_DECL
7215 && TREE_CODE (type
) == FUNCTION_TYPE
7216 && decl_function_context (decl
) == 0)
7218 priority_type priority
;
7219 DECL_STATIC_DESTRUCTOR (decl
) = 1;
7220 priority
= get_priority (args
, /*is_destructor=*/true);
7221 SET_DECL_FINI_PRIORITY (decl
, priority
);
7222 TREE_USED (decl
) = 1;
7226 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7227 *no_add_attrs
= true;
7233 /* Nonzero if the mode is a valid vector mode for this architecture.
7234 This returns nonzero even if there is no hardware support for the
7235 vector mode, but we can emulate with narrower modes. */
7238 vector_mode_valid_p (enum machine_mode mode
)
7240 enum mode_class mclass
= GET_MODE_CLASS (mode
);
7241 enum machine_mode innermode
;
7243 /* Doh! What's going on? */
7244 if (mclass
!= MODE_VECTOR_INT
7245 && mclass
!= MODE_VECTOR_FLOAT
7246 && mclass
!= MODE_VECTOR_FRACT
7247 && mclass
!= MODE_VECTOR_UFRACT
7248 && mclass
!= MODE_VECTOR_ACCUM
7249 && mclass
!= MODE_VECTOR_UACCUM
)
7252 /* Hardware support. Woo hoo! */
7253 if (targetm
.vector_mode_supported_p (mode
))
7256 innermode
= GET_MODE_INNER (mode
);
7258 /* We should probably return 1 if requesting V4DI and we have no DI,
7259 but we have V2DI, but this is probably very unlikely. */
7261 /* If we have support for the inner mode, we can safely emulate it.
7262 We may not have V2DI, but me can emulate with a pair of DIs. */
7263 return targetm
.scalar_mode_supported_p (innermode
);
7267 /* Handle a "mode" attribute; arguments as in
7268 struct attribute_spec.handler. */
7271 handle_mode_attribute (tree
*node
, tree name
, tree args
,
7272 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7275 tree ident
= TREE_VALUE (args
);
7277 *no_add_attrs
= true;
7279 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
7280 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7284 const char *p
= IDENTIFIER_POINTER (ident
);
7285 int len
= strlen (p
);
7286 enum machine_mode mode
= VOIDmode
;
7290 if (len
> 4 && p
[0] == '_' && p
[1] == '_'
7291 && p
[len
- 1] == '_' && p
[len
- 2] == '_')
7293 char *newp
= (char *) alloca (len
- 1);
7295 strcpy (newp
, &p
[2]);
7296 newp
[len
- 4] = '\0';
7300 /* Change this type to have a type with the specified mode.
7301 First check for the special modes. */
7302 if (!strcmp (p
, "byte"))
7304 else if (!strcmp (p
, "word"))
7306 else if (!strcmp (p
, "pointer"))
7308 else if (!strcmp (p
, "libgcc_cmp_return"))
7309 mode
= targetm
.libgcc_cmp_return_mode ();
7310 else if (!strcmp (p
, "libgcc_shift_count"))
7311 mode
= targetm
.libgcc_shift_count_mode ();
7312 else if (!strcmp (p
, "unwind_word"))
7313 mode
= targetm
.unwind_word_mode ();
7315 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
7316 if (!strcmp (p
, GET_MODE_NAME (j
)))
7318 mode
= (enum machine_mode
) j
;
7322 if (mode
== VOIDmode
)
7324 error ("unknown machine mode %qE", ident
);
7329 switch (GET_MODE_CLASS (mode
))
7332 case MODE_PARTIAL_INT
:
7334 case MODE_DECIMAL_FLOAT
:
7339 valid_mode
= targetm
.scalar_mode_supported_p (mode
);
7342 case MODE_COMPLEX_INT
:
7343 case MODE_COMPLEX_FLOAT
:
7344 valid_mode
= targetm
.scalar_mode_supported_p (GET_MODE_INNER (mode
));
7347 case MODE_VECTOR_INT
:
7348 case MODE_VECTOR_FLOAT
:
7349 case MODE_VECTOR_FRACT
:
7350 case MODE_VECTOR_UFRACT
:
7351 case MODE_VECTOR_ACCUM
:
7352 case MODE_VECTOR_UACCUM
:
7353 warning (OPT_Wattributes
, "specifying vector types with "
7354 "__attribute__ ((mode)) is deprecated");
7355 warning (OPT_Wattributes
,
7356 "use __attribute__ ((vector_size)) instead");
7357 valid_mode
= vector_mode_valid_p (mode
);
7365 error ("unable to emulate %qs", p
);
7369 if (POINTER_TYPE_P (type
))
7371 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
7372 tree (*fn
)(tree
, enum machine_mode
, bool);
7374 if (!targetm
.addr_space
.valid_pointer_mode (mode
, as
))
7376 error ("invalid pointer mode %qs", p
);
7380 if (TREE_CODE (type
) == POINTER_TYPE
)
7381 fn
= build_pointer_type_for_mode
;
7383 fn
= build_reference_type_for_mode
;
7384 typefm
= fn (TREE_TYPE (type
), mode
, false);
7388 /* For fixed-point modes, we need to test if the signness of type
7389 and the machine mode are consistent. */
7390 if (ALL_FIXED_POINT_MODE_P (mode
)
7391 && TYPE_UNSIGNED (type
) != UNSIGNED_FIXED_POINT_MODE_P (mode
))
7393 error ("signedness of type and machine mode %qs don%'t match", p
);
7396 /* For fixed-point modes, we need to pass saturating info. */
7397 typefm
= lang_hooks
.types
.type_for_mode (mode
,
7398 ALL_FIXED_POINT_MODE_P (mode
) ? TYPE_SATURATING (type
)
7399 : TYPE_UNSIGNED (type
));
7402 if (typefm
== NULL_TREE
)
7404 error ("no data type for mode %qs", p
);
7407 else if (TREE_CODE (type
) == ENUMERAL_TYPE
)
7409 /* For enumeral types, copy the precision from the integer
7410 type returned above. If not an INTEGER_TYPE, we can't use
7411 this mode for this type. */
7412 if (TREE_CODE (typefm
) != INTEGER_TYPE
)
7414 error ("cannot use mode %qs for enumeral types", p
);
7418 if (flags
& ATTR_FLAG_TYPE_IN_PLACE
)
7420 TYPE_PRECISION (type
) = TYPE_PRECISION (typefm
);
7425 /* We cannot build a type variant, as there's code that assumes
7426 that TYPE_MAIN_VARIANT has the same mode. This includes the
7427 debug generators. Instead, create a subrange type. This
7428 results in all of the enumeral values being emitted only once
7429 in the original, and the subtype gets them by reference. */
7430 if (TYPE_UNSIGNED (type
))
7431 typefm
= make_unsigned_type (TYPE_PRECISION (typefm
));
7433 typefm
= make_signed_type (TYPE_PRECISION (typefm
));
7434 TREE_TYPE (typefm
) = type
;
7437 else if (VECTOR_MODE_P (mode
)
7438 ? TREE_CODE (type
) != TREE_CODE (TREE_TYPE (typefm
))
7439 : TREE_CODE (type
) != TREE_CODE (typefm
))
7441 error ("mode %qs applied to inappropriate type", p
);
7451 /* Handle a "section" attribute; arguments as in
7452 struct attribute_spec.handler. */
7455 handle_section_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7456 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7460 if (targetm_common
.have_named_sections
)
7462 user_defined_section_attribute
= true;
7464 if ((TREE_CODE (decl
) == FUNCTION_DECL
7465 || TREE_CODE (decl
) == VAR_DECL
)
7466 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
7468 if (TREE_CODE (decl
) == VAR_DECL
7469 && current_function_decl
!= NULL_TREE
7470 && !TREE_STATIC (decl
))
7472 error_at (DECL_SOURCE_LOCATION (decl
),
7473 "section attribute cannot be specified for "
7475 *no_add_attrs
= true;
7478 /* The decl may have already been given a section attribute
7479 from a previous declaration. Ensure they match. */
7480 else if (DECL_SECTION_NAME (decl
) != NULL_TREE
7481 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl
)),
7482 TREE_STRING_POINTER (TREE_VALUE (args
))) != 0)
7484 error ("section of %q+D conflicts with previous declaration",
7486 *no_add_attrs
= true;
7488 else if (TREE_CODE (decl
) == VAR_DECL
7489 && !targetm
.have_tls
&& targetm
.emutls
.tmpl_section
7490 && DECL_THREAD_LOCAL_P (decl
))
7492 error ("section of %q+D cannot be overridden", *node
);
7493 *no_add_attrs
= true;
7496 DECL_SECTION_NAME (decl
) = TREE_VALUE (args
);
7500 error ("section attribute not allowed for %q+D", *node
);
7501 *no_add_attrs
= true;
7506 error_at (DECL_SOURCE_LOCATION (*node
),
7507 "section attributes are not supported for this target");
7508 *no_add_attrs
= true;
7514 /* Check whether ALIGN is a valid user-specified alignment. If so,
7515 return its base-2 log; if not, output an error and return -1. If
7516 ALLOW_ZERO then 0 is valid and should result in a return of -1 with
7519 check_user_alignment (const_tree align
, bool allow_zero
)
7523 if (TREE_CODE (align
) != INTEGER_CST
7524 || !INTEGRAL_TYPE_P (TREE_TYPE (align
)))
7526 error ("requested alignment is not an integer constant");
7529 else if (allow_zero
&& integer_zerop (align
))
7531 else if (tree_int_cst_sgn (align
) == -1
7532 || (i
= tree_log2 (align
)) == -1)
7534 error ("requested alignment is not a positive power of 2");
7537 else if (i
>= HOST_BITS_PER_INT
- BITS_PER_UNIT_LOG
)
7539 error ("requested alignment is too large");
7546 If in c++-11, check if the c++-11 alignment constraint with respect
7547 to fundamental alignment (in [dcl.align]) are satisfied. If not in
7548 c++-11 mode, does nothing.
7552 [* if the constant expression evaluates to a fundamental alignment,
7553 the alignment requirement of the declared entity shall be the
7554 specified fundamental alignment.
7556 * if the constant expression evaluates to an extended alignment
7557 and the implementation supports that alignment in the context
7558 of the declaration, the alignment of the declared entity shall
7561 * if the constant expression evaluates to an extended alignment
7562 and the implementation does not support that alignment in the
7563 context of the declaration, the program is ill-formed]. */
7566 check_cxx_fundamental_alignment_constraints (tree node
,
7570 bool alignment_too_large_p
= false;
7571 unsigned requested_alignment
= 1U << align_log
;
7572 unsigned max_align
= 0;
7574 if ((!(flags
& ATTR_FLAG_CXX11
) && !warn_cxx_compat
)
7575 || (node
== NULL_TREE
|| node
== error_mark_node
))
7578 if (cxx_fundamental_alignment_p (requested_alignment
))
7583 if (TREE_STATIC (node
))
7585 /* For file scope variables and static members, the target
7586 supports alignments that are at most
7587 MAX_OFILE_ALIGNMENT. */
7588 if (requested_alignment
> (max_align
= MAX_OFILE_ALIGNMENT
))
7589 alignment_too_large_p
= true;
7593 #ifdef BIGGEST_FIELD_ALIGNMENT
7594 #define MAX_TARGET_FIELD_ALIGNMENT BIGGEST_FIELD_ALIGNMENT
7596 #define MAX_TARGET_FIELD_ALIGNMENT BIGGEST_ALIGNMENT
7598 /* For non-static members, the target supports either
7599 alignments that at most either BIGGEST_FIELD_ALIGNMENT
7600 if it is defined or BIGGEST_ALIGNMENT. */
7601 max_align
= MAX_TARGET_FIELD_ALIGNMENT
;
7602 if (TREE_CODE (node
) == FIELD_DECL
7603 && requested_alignment
> (max_align
= MAX_TARGET_FIELD_ALIGNMENT
))
7604 alignment_too_large_p
= true;
7605 #undef MAX_TARGET_FIELD_ALIGNMENT
7606 /* For stack variables, the target supports at most
7607 MAX_STACK_ALIGNMENT. */
7608 else if (decl_function_context (node
) != NULL
7609 && requested_alignment
> (max_align
= MAX_STACK_ALIGNMENT
))
7610 alignment_too_large_p
= true;
7613 else if (TYPE_P (node
))
7615 /* Let's be liberal for types. */
7616 if (requested_alignment
> (max_align
= BIGGEST_ALIGNMENT
))
7617 alignment_too_large_p
= true;
7620 if (alignment_too_large_p
)
7621 pedwarn (input_location
, OPT_Wattributes
,
7622 "requested alignment %d is larger than %d",
7623 requested_alignment
, max_align
);
7625 return !alignment_too_large_p
;
7628 /* Handle a "aligned" attribute; arguments as in
7629 struct attribute_spec.handler. */
7632 handle_aligned_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7633 int flags
, bool *no_add_attrs
)
7635 tree decl
= NULL_TREE
;
7638 tree align_expr
= (args
? TREE_VALUE (args
)
7639 : size_int (ATTRIBUTE_ALIGNED_VALUE
/ BITS_PER_UNIT
));
7645 type
= &TREE_TYPE (decl
);
7646 is_type
= TREE_CODE (*node
) == TYPE_DECL
;
7648 else if (TYPE_P (*node
))
7649 type
= node
, is_type
= 1;
7651 if ((i
= check_user_alignment (align_expr
, false)) == -1
7652 || !check_cxx_fundamental_alignment_constraints (*node
, i
, flags
))
7653 *no_add_attrs
= true;
7656 if ((flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7657 /* OK, modify the type in place. */;
7658 /* If we have a TYPE_DECL, then copy the type, so that we
7659 don't accidentally modify a builtin type. See pushdecl. */
7660 else if (decl
&& TREE_TYPE (decl
) != error_mark_node
7661 && DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
)
7663 tree tt
= TREE_TYPE (decl
);
7664 *type
= build_variant_type_copy (*type
);
7665 DECL_ORIGINAL_TYPE (decl
) = tt
;
7666 TYPE_NAME (*type
) = decl
;
7667 TREE_USED (*type
) = TREE_USED (decl
);
7668 TREE_TYPE (decl
) = *type
;
7671 *type
= build_variant_type_copy (*type
);
7673 TYPE_ALIGN (*type
) = (1U << i
) * BITS_PER_UNIT
;
7674 TYPE_USER_ALIGN (*type
) = 1;
7676 else if (! VAR_OR_FUNCTION_DECL_P (decl
)
7677 && TREE_CODE (decl
) != FIELD_DECL
)
7679 error ("alignment may not be specified for %q+D", decl
);
7680 *no_add_attrs
= true;
7682 else if (DECL_USER_ALIGN (decl
)
7683 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
7684 /* C++-11 [dcl.align/4]:
7686 When multiple alignment-specifiers are specified for an
7687 entity, the alignment requirement shall be set to the
7688 strictest specified alignment.
7690 This formally comes from the c++11 specification but we are
7691 doing it for the GNU attribute syntax as well. */
7692 *no_add_attrs
= true;
7693 else if (TREE_CODE (decl
) == FUNCTION_DECL
7694 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
7696 if (DECL_USER_ALIGN (decl
))
7697 error ("alignment for %q+D was previously specified as %d "
7698 "and may not be decreased", decl
,
7699 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
7701 error ("alignment for %q+D must be at least %d", decl
,
7702 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
7703 *no_add_attrs
= true;
7707 DECL_ALIGN (decl
) = (1U << i
) * BITS_PER_UNIT
;
7708 DECL_USER_ALIGN (decl
) = 1;
7714 /* Handle a "weak" attribute; arguments as in
7715 struct attribute_spec.handler. */
7718 handle_weak_attribute (tree
*node
, tree name
,
7719 tree
ARG_UNUSED (args
),
7720 int ARG_UNUSED (flags
),
7721 bool * ARG_UNUSED (no_add_attrs
))
7723 if (TREE_CODE (*node
) == FUNCTION_DECL
7724 && DECL_DECLARED_INLINE_P (*node
))
7726 warning (OPT_Wattributes
, "inline function %q+D declared weak", *node
);
7727 *no_add_attrs
= true;
7729 else if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
7731 error ("indirect function %q+D cannot be declared weak", *node
);
7732 *no_add_attrs
= true;
7735 else if (TREE_CODE (*node
) == FUNCTION_DECL
7736 || TREE_CODE (*node
) == VAR_DECL
)
7737 declare_weak (*node
);
7739 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7744 /* Handle an "alias" or "ifunc" attribute; arguments as in
7745 struct attribute_spec.handler, except that IS_ALIAS tells us
7746 whether this is an alias as opposed to ifunc attribute. */
7749 handle_alias_ifunc_attribute (bool is_alias
, tree
*node
, tree name
, tree args
,
7754 if (TREE_CODE (decl
) != FUNCTION_DECL
7755 && (!is_alias
|| TREE_CODE (decl
) != VAR_DECL
))
7757 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7758 *no_add_attrs
= true;
7760 else if ((TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INITIAL (decl
))
7761 || (TREE_CODE (decl
) != FUNCTION_DECL
7762 && TREE_PUBLIC (decl
) && !DECL_EXTERNAL (decl
))
7763 /* A static variable declaration is always a tentative definition,
7764 but the alias is a non-tentative definition which overrides. */
7765 || (TREE_CODE (decl
) != FUNCTION_DECL
7766 && ! TREE_PUBLIC (decl
) && DECL_INITIAL (decl
)))
7768 error ("%q+D defined both normally and as %qE attribute", decl
, name
);
7769 *no_add_attrs
= true;
7773 && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
7774 || lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
))))
7776 error ("weak %q+D cannot be defined %qE", decl
, name
);
7777 *no_add_attrs
= true;
7781 /* Note that the very first time we process a nested declaration,
7782 decl_function_context will not be set. Indeed, *would* never
7783 be set except for the DECL_INITIAL/DECL_EXTERNAL frobbery that
7784 we do below. After such frobbery, pushdecl would set the context.
7785 In any case, this is never what we want. */
7786 else if (decl_function_context (decl
) == 0 && current_function_decl
== NULL
)
7790 id
= TREE_VALUE (args
);
7791 if (TREE_CODE (id
) != STRING_CST
)
7793 error ("attribute %qE argument not a string", name
);
7794 *no_add_attrs
= true;
7797 id
= get_identifier (TREE_STRING_POINTER (id
));
7798 /* This counts as a use of the object pointed to. */
7801 if (TREE_CODE (decl
) == FUNCTION_DECL
)
7802 DECL_INITIAL (decl
) = error_mark_node
;
7804 TREE_STATIC (decl
) = 1;
7807 /* ifuncs are also aliases, so set that attribute too. */
7808 DECL_ATTRIBUTES (decl
)
7809 = tree_cons (get_identifier ("alias"), args
, DECL_ATTRIBUTES (decl
));
7813 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7814 *no_add_attrs
= true;
7820 /* Handle an "alias" or "ifunc" attribute; arguments as in
7821 struct attribute_spec.handler. */
7824 handle_ifunc_attribute (tree
*node
, tree name
, tree args
,
7825 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7827 return handle_alias_ifunc_attribute (false, node
, name
, args
, no_add_attrs
);
7830 /* Handle an "alias" or "ifunc" attribute; arguments as in
7831 struct attribute_spec.handler. */
7834 handle_alias_attribute (tree
*node
, tree name
, tree args
,
7835 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7837 return handle_alias_ifunc_attribute (true, node
, name
, args
, no_add_attrs
);
7840 /* Handle a "weakref" attribute; arguments as in struct
7841 attribute_spec.handler. */
7844 handle_weakref_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7845 int flags
, bool *no_add_attrs
)
7847 tree attr
= NULL_TREE
;
7849 /* We must ignore the attribute when it is associated with
7850 local-scoped decls, since attribute alias is ignored and many
7851 such symbols do not even have a DECL_WEAK field. */
7852 if (decl_function_context (*node
)
7853 || current_function_decl
7854 || (TREE_CODE (*node
) != VAR_DECL
&& TREE_CODE (*node
) != FUNCTION_DECL
))
7856 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7857 *no_add_attrs
= true;
7861 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
7863 error ("indirect function %q+D cannot be declared weakref", *node
);
7864 *no_add_attrs
= true;
7868 /* The idea here is that `weakref("name")' mutates into `weakref,
7869 alias("name")', and weakref without arguments, in turn,
7870 implicitly adds weak. */
7874 attr
= tree_cons (get_identifier ("alias"), args
, attr
);
7875 attr
= tree_cons (get_identifier ("weakref"), NULL_TREE
, attr
);
7877 *no_add_attrs
= true;
7879 decl_attributes (node
, attr
, flags
);
7883 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node
)))
7884 error_at (DECL_SOURCE_LOCATION (*node
),
7885 "weakref attribute must appear before alias attribute");
7887 /* Can't call declare_weak because it wants this to be TREE_PUBLIC,
7888 and that isn't supported; and because it wants to add it to
7889 the list of weak decls, which isn't helpful. */
7890 DECL_WEAK (*node
) = 1;
7896 /* Handle an "visibility" attribute; arguments as in
7897 struct attribute_spec.handler. */
7900 handle_visibility_attribute (tree
*node
, tree name
, tree args
,
7901 int ARG_UNUSED (flags
),
7902 bool *ARG_UNUSED (no_add_attrs
))
7905 tree id
= TREE_VALUE (args
);
7906 enum symbol_visibility vis
;
7910 if (TREE_CODE (*node
) == ENUMERAL_TYPE
)
7912 else if (TREE_CODE (*node
) != RECORD_TYPE
&& TREE_CODE (*node
) != UNION_TYPE
)
7914 warning (OPT_Wattributes
, "%qE attribute ignored on non-class types",
7918 else if (TYPE_FIELDS (*node
))
7920 error ("%qE attribute ignored because %qT is already defined",
7925 else if (decl_function_context (decl
) != 0 || !TREE_PUBLIC (decl
))
7927 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7931 if (TREE_CODE (id
) != STRING_CST
)
7933 error ("visibility argument not a string");
7937 /* If this is a type, set the visibility on the type decl. */
7940 decl
= TYPE_NAME (decl
);
7943 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
7945 warning (OPT_Wattributes
, "%qE attribute ignored on types",
7951 if (strcmp (TREE_STRING_POINTER (id
), "default") == 0)
7952 vis
= VISIBILITY_DEFAULT
;
7953 else if (strcmp (TREE_STRING_POINTER (id
), "internal") == 0)
7954 vis
= VISIBILITY_INTERNAL
;
7955 else if (strcmp (TREE_STRING_POINTER (id
), "hidden") == 0)
7956 vis
= VISIBILITY_HIDDEN
;
7957 else if (strcmp (TREE_STRING_POINTER (id
), "protected") == 0)
7958 vis
= VISIBILITY_PROTECTED
;
7961 error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
7962 vis
= VISIBILITY_DEFAULT
;
7965 if (DECL_VISIBILITY_SPECIFIED (decl
)
7966 && vis
!= DECL_VISIBILITY (decl
))
7968 tree attributes
= (TYPE_P (*node
)
7969 ? TYPE_ATTRIBUTES (*node
)
7970 : DECL_ATTRIBUTES (decl
));
7971 if (lookup_attribute ("visibility", attributes
))
7972 error ("%qD redeclared with different visibility", decl
);
7973 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
7974 && lookup_attribute ("dllimport", attributes
))
7975 error ("%qD was declared %qs which implies default visibility",
7977 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
7978 && lookup_attribute ("dllexport", attributes
))
7979 error ("%qD was declared %qs which implies default visibility",
7983 DECL_VISIBILITY (decl
) = vis
;
7984 DECL_VISIBILITY_SPECIFIED (decl
) = 1;
7986 /* Go ahead and attach the attribute to the node as well. This is needed
7987 so we can determine whether we have VISIBILITY_DEFAULT because the
7988 visibility was not specified, or because it was explicitly overridden
7989 from the containing scope. */
7994 /* Determine the ELF symbol visibility for DECL, which is either a
7995 variable or a function. It is an error to use this function if a
7996 definition of DECL is not available in this translation unit.
7997 Returns true if the final visibility has been determined by this
7998 function; false if the caller is free to make additional
8002 c_determine_visibility (tree decl
)
8004 gcc_assert (TREE_CODE (decl
) == VAR_DECL
8005 || TREE_CODE (decl
) == FUNCTION_DECL
);
8007 /* If the user explicitly specified the visibility with an
8008 attribute, honor that. DECL_VISIBILITY will have been set during
8009 the processing of the attribute. We check for an explicit
8010 attribute, rather than just checking DECL_VISIBILITY_SPECIFIED,
8011 to distinguish the use of an attribute from the use of a "#pragma
8012 GCC visibility push(...)"; in the latter case we still want other
8013 considerations to be able to overrule the #pragma. */
8014 if (lookup_attribute ("visibility", DECL_ATTRIBUTES (decl
))
8015 || (TARGET_DLLIMPORT_DECL_ATTRIBUTES
8016 && (lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl
))
8017 || lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl
)))))
8020 /* Set default visibility to whatever the user supplied with
8021 visibility_specified depending on #pragma GCC visibility. */
8022 if (!DECL_VISIBILITY_SPECIFIED (decl
))
8024 if (visibility_options
.inpragma
8025 || DECL_VISIBILITY (decl
) != default_visibility
)
8027 DECL_VISIBILITY (decl
) = default_visibility
;
8028 DECL_VISIBILITY_SPECIFIED (decl
) = visibility_options
.inpragma
;
8029 /* If visibility changed and DECL already has DECL_RTL, ensure
8030 symbol flags are updated. */
8031 if (((TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
))
8032 || TREE_CODE (decl
) == FUNCTION_DECL
)
8033 && DECL_RTL_SET_P (decl
))
8034 make_decl_rtl (decl
);
8040 /* Handle an "tls_model" attribute; arguments as in
8041 struct attribute_spec.handler. */
8044 handle_tls_model_attribute (tree
*node
, tree name
, tree args
,
8045 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8049 enum tls_model kind
;
8051 *no_add_attrs
= true;
8053 if (TREE_CODE (decl
) != VAR_DECL
|| !DECL_THREAD_LOCAL_P (decl
))
8055 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8059 kind
= DECL_TLS_MODEL (decl
);
8060 id
= TREE_VALUE (args
);
8061 if (TREE_CODE (id
) != STRING_CST
)
8063 error ("tls_model argument not a string");
8067 if (!strcmp (TREE_STRING_POINTER (id
), "local-exec"))
8068 kind
= TLS_MODEL_LOCAL_EXEC
;
8069 else if (!strcmp (TREE_STRING_POINTER (id
), "initial-exec"))
8070 kind
= TLS_MODEL_INITIAL_EXEC
;
8071 else if (!strcmp (TREE_STRING_POINTER (id
), "local-dynamic"))
8072 kind
= optimize
? TLS_MODEL_LOCAL_DYNAMIC
: TLS_MODEL_GLOBAL_DYNAMIC
;
8073 else if (!strcmp (TREE_STRING_POINTER (id
), "global-dynamic"))
8074 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
8076 error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
8078 DECL_TLS_MODEL (decl
) = kind
;
8082 /* Handle a "no_instrument_function" attribute; arguments as in
8083 struct attribute_spec.handler. */
8086 handle_no_instrument_function_attribute (tree
*node
, tree name
,
8087 tree
ARG_UNUSED (args
),
8088 int ARG_UNUSED (flags
),
8093 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8095 error_at (DECL_SOURCE_LOCATION (decl
),
8096 "%qE attribute applies only to functions", name
);
8097 *no_add_attrs
= true;
8099 else if (DECL_INITIAL (decl
))
8101 error_at (DECL_SOURCE_LOCATION (decl
),
8102 "can%'t set %qE attribute after definition", name
);
8103 *no_add_attrs
= true;
8106 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
8111 /* Handle a "malloc" attribute; arguments as in
8112 struct attribute_spec.handler. */
8115 handle_malloc_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8116 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8118 if (TREE_CODE (*node
) == FUNCTION_DECL
8119 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node
))))
8120 DECL_IS_MALLOC (*node
) = 1;
8123 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8124 *no_add_attrs
= true;
8130 /* Handle a "alloc_size" attribute; arguments as in
8131 struct attribute_spec.handler. */
8134 handle_alloc_size_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
8135 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8137 unsigned arg_count
= type_num_arguments (*node
);
8138 for (; args
; args
= TREE_CHAIN (args
))
8140 tree position
= TREE_VALUE (args
);
8142 if (TREE_CODE (position
) != INTEGER_CST
8143 || TREE_INT_CST_HIGH (position
)
8144 || TREE_INT_CST_LOW (position
) < 1
8145 || TREE_INT_CST_LOW (position
) > arg_count
)
8147 warning (OPT_Wattributes
,
8148 "alloc_size parameter outside range");
8149 *no_add_attrs
= true;
8156 /* Handle a "fn spec" attribute; arguments as in
8157 struct attribute_spec.handler. */
8160 handle_fnspec_attribute (tree
*node ATTRIBUTE_UNUSED
, tree
ARG_UNUSED (name
),
8161 tree args
, int ARG_UNUSED (flags
),
8162 bool *no_add_attrs ATTRIBUTE_UNUSED
)
8165 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
8166 && !TREE_CHAIN (args
));
8170 /* Handle a "warn_unused" attribute; arguments as in
8171 struct attribute_spec.handler. */
8174 handle_warn_unused_attribute (tree
*node
, tree name
,
8175 tree args ATTRIBUTE_UNUSED
,
8176 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
8179 /* Do nothing else, just set the attribute. We'll get at
8180 it later with lookup_attribute. */
8184 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8185 *no_add_attrs
= true;
8191 /* Handle an "omp declare simd" attribute; arguments as in
8192 struct attribute_spec.handler. */
8195 handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int, bool *)
8200 /* Handle an "omp declare target" attribute; arguments as in
8201 struct attribute_spec.handler. */
8204 handle_omp_declare_target_attribute (tree
*, tree
, tree
, int, bool *)
8209 /* Handle a "returns_twice" attribute; arguments as in
8210 struct attribute_spec.handler. */
8213 handle_returns_twice_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8214 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8216 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8217 DECL_IS_RETURNS_TWICE (*node
) = 1;
8220 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8221 *no_add_attrs
= true;
8227 /* Handle a "no_limit_stack" attribute; arguments as in
8228 struct attribute_spec.handler. */
8231 handle_no_limit_stack_attribute (tree
*node
, tree name
,
8232 tree
ARG_UNUSED (args
),
8233 int ARG_UNUSED (flags
),
8238 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8240 error_at (DECL_SOURCE_LOCATION (decl
),
8241 "%qE attribute applies only to functions", name
);
8242 *no_add_attrs
= true;
8244 else if (DECL_INITIAL (decl
))
8246 error_at (DECL_SOURCE_LOCATION (decl
),
8247 "can%'t set %qE attribute after definition", name
);
8248 *no_add_attrs
= true;
8251 DECL_NO_LIMIT_STACK (decl
) = 1;
8256 /* Handle a "pure" attribute; arguments as in
8257 struct attribute_spec.handler. */
8260 handle_pure_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8261 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8263 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8264 DECL_PURE_P (*node
) = 1;
8265 /* ??? TODO: Support types. */
8268 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8269 *no_add_attrs
= true;
8275 /* Digest an attribute list destined for a transactional memory statement.
8276 ALLOWED is the set of attributes that are allowed for this statement;
8277 return the attribute we parsed. Multiple attributes are never allowed. */
8280 parse_tm_stmt_attr (tree attrs
, int allowed
)
8285 for ( ; attrs
; attrs
= TREE_CHAIN (attrs
))
8287 tree a
= TREE_PURPOSE (attrs
);
8290 if (is_attribute_p ("outer", a
))
8291 m
= TM_STMT_ATTR_OUTER
;
8293 if ((m
& allowed
) == 0)
8295 warning (OPT_Wattributes
, "%qE attribute directive ignored", a
);
8304 else if (m_seen
== m
)
8305 warning (OPT_Wattributes
, "%qE attribute duplicated", a
);
8307 warning (OPT_Wattributes
, "%qE attribute follows %qE", a
, a_seen
);
8313 /* Transform a TM attribute name into a maskable integer and back.
8314 Note that NULL (i.e. no attribute) is mapped to UNKNOWN, corresponding
8315 to how the lack of an attribute is treated. */
8318 tm_attr_to_mask (tree attr
)
8322 if (is_attribute_p ("transaction_safe", attr
))
8323 return TM_ATTR_SAFE
;
8324 if (is_attribute_p ("transaction_callable", attr
))
8325 return TM_ATTR_CALLABLE
;
8326 if (is_attribute_p ("transaction_pure", attr
))
8327 return TM_ATTR_PURE
;
8328 if (is_attribute_p ("transaction_unsafe", attr
))
8329 return TM_ATTR_IRREVOCABLE
;
8330 if (is_attribute_p ("transaction_may_cancel_outer", attr
))
8331 return TM_ATTR_MAY_CANCEL_OUTER
;
8336 tm_mask_to_attr (int mask
)
8342 str
= "transaction_safe";
8344 case TM_ATTR_CALLABLE
:
8345 str
= "transaction_callable";
8348 str
= "transaction_pure";
8350 case TM_ATTR_IRREVOCABLE
:
8351 str
= "transaction_unsafe";
8353 case TM_ATTR_MAY_CANCEL_OUTER
:
8354 str
= "transaction_may_cancel_outer";
8359 return get_identifier (str
);
8362 /* Return the first TM attribute seen in LIST. */
8365 find_tm_attribute (tree list
)
8367 for (; list
; list
= TREE_CHAIN (list
))
8369 tree name
= TREE_PURPOSE (list
);
8370 if (tm_attr_to_mask (name
) != 0)
8376 /* Handle the TM attributes; arguments as in struct attribute_spec.handler.
8377 Here we accept only function types, and verify that none of the other
8378 function TM attributes are also applied. */
8379 /* ??? We need to accept class types for C++, but not C. This greatly
8380 complicates this function, since we can no longer rely on the extra
8381 processing given by function_type_required. */
8384 handle_tm_attribute (tree
*node
, tree name
, tree args
,
8385 int flags
, bool *no_add_attrs
)
8387 /* Only one path adds the attribute; others don't. */
8388 *no_add_attrs
= true;
8390 switch (TREE_CODE (*node
))
8394 /* Only tm_callable and tm_safe apply to classes. */
8395 if (tm_attr_to_mask (name
) & ~(TM_ATTR_SAFE
| TM_ATTR_CALLABLE
))
8402 tree old_name
= find_tm_attribute (TYPE_ATTRIBUTES (*node
));
8403 if (old_name
== name
)
8405 else if (old_name
!= NULL_TREE
)
8406 error ("type was previously declared %qE", old_name
);
8408 *no_add_attrs
= false;
8414 enum tree_code subcode
= TREE_CODE (TREE_TYPE (*node
));
8415 if (subcode
== FUNCTION_TYPE
|| subcode
== METHOD_TYPE
)
8417 tree fn_tmp
= TREE_TYPE (*node
);
8418 decl_attributes (&fn_tmp
, tree_cons (name
, args
, NULL
), 0);
8419 *node
= build_pointer_type (fn_tmp
);
8426 /* If a function is next, pass it on to be tried next. */
8427 if (flags
& (int) ATTR_FLAG_FUNCTION_NEXT
)
8428 return tree_cons (name
, args
, NULL
);
8431 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8438 /* Handle the TM_WRAP attribute; arguments as in
8439 struct attribute_spec.handler. */
8442 handle_tm_wrap_attribute (tree
*node
, tree name
, tree args
,
8443 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8447 /* We don't need the attribute even on success, since we
8448 record the entry in an external table. */
8449 *no_add_attrs
= true;
8451 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8452 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8455 tree wrap_decl
= TREE_VALUE (args
);
8456 if (TREE_CODE (wrap_decl
) != IDENTIFIER_NODE
8457 && TREE_CODE (wrap_decl
) != VAR_DECL
8458 && TREE_CODE (wrap_decl
) != FUNCTION_DECL
)
8459 error ("%qE argument not an identifier", name
);
8462 if (TREE_CODE (wrap_decl
) == IDENTIFIER_NODE
)
8463 wrap_decl
= lookup_name (wrap_decl
);
8464 if (wrap_decl
&& TREE_CODE (wrap_decl
) == FUNCTION_DECL
)
8466 if (lang_hooks
.types_compatible_p (TREE_TYPE (decl
),
8467 TREE_TYPE (wrap_decl
)))
8468 record_tm_replacement (wrap_decl
, decl
);
8470 error ("%qD is not compatible with %qD", wrap_decl
, decl
);
8473 error ("transaction_wrap argument is not a function");
8480 /* Ignore the given attribute. Used when this attribute may be usefully
8481 overridden by the target, but is not used generically. */
8484 ignore_attribute (tree
* ARG_UNUSED (node
), tree
ARG_UNUSED (name
),
8485 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
8488 *no_add_attrs
= true;
8492 /* Handle a "no vops" attribute; arguments as in
8493 struct attribute_spec.handler. */
8496 handle_novops_attribute (tree
*node
, tree
ARG_UNUSED (name
),
8497 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
8498 bool *ARG_UNUSED (no_add_attrs
))
8500 gcc_assert (TREE_CODE (*node
) == FUNCTION_DECL
);
8501 DECL_IS_NOVOPS (*node
) = 1;
8505 /* Handle a "deprecated" attribute; arguments as in
8506 struct attribute_spec.handler. */
8509 handle_deprecated_attribute (tree
*node
, tree name
,
8510 tree args
, int flags
,
8513 tree type
= NULL_TREE
;
8515 tree what
= NULL_TREE
;
8518 *no_add_attrs
= true;
8519 else if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
8521 error ("deprecated message is not a string");
8522 *no_add_attrs
= true;
8528 type
= TREE_TYPE (decl
);
8530 if (TREE_CODE (decl
) == TYPE_DECL
8531 || TREE_CODE (decl
) == PARM_DECL
8532 || TREE_CODE (decl
) == VAR_DECL
8533 || TREE_CODE (decl
) == FUNCTION_DECL
8534 || TREE_CODE (decl
) == FIELD_DECL
8535 || objc_method_decl (TREE_CODE (decl
)))
8536 TREE_DEPRECATED (decl
) = 1;
8540 else if (TYPE_P (*node
))
8542 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
8543 *node
= build_variant_type_copy (*node
);
8544 TREE_DEPRECATED (*node
) = 1;
8552 *no_add_attrs
= true;
8553 if (type
&& TYPE_NAME (type
))
8555 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
8556 what
= TYPE_NAME (*node
);
8557 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
8558 && DECL_NAME (TYPE_NAME (type
)))
8559 what
= DECL_NAME (TYPE_NAME (type
));
8562 warning (OPT_Wattributes
, "%qE attribute ignored for %qE", name
, what
);
8564 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8570 /* Handle a "vector_size" attribute; arguments as in
8571 struct attribute_spec.handler. */
8574 handle_vector_size_attribute (tree
*node
, tree name
, tree args
,
8575 int ARG_UNUSED (flags
),
8578 unsigned HOST_WIDE_INT vecsize
, nunits
;
8579 enum machine_mode orig_mode
;
8580 tree type
= *node
, new_type
, size
;
8582 *no_add_attrs
= true;
8584 size
= TREE_VALUE (args
);
8586 if (!tree_fits_uhwi_p (size
))
8588 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8592 /* Get the vector size (in bytes). */
8593 vecsize
= tree_to_uhwi (size
);
8595 /* We need to provide for vector pointers, vector arrays, and
8596 functions returning vectors. For example:
8598 __attribute__((vector_size(16))) short *foo;
8600 In this case, the mode is SI, but the type being modified is
8601 HI, so we need to look further. */
8603 while (POINTER_TYPE_P (type
)
8604 || TREE_CODE (type
) == FUNCTION_TYPE
8605 || TREE_CODE (type
) == METHOD_TYPE
8606 || TREE_CODE (type
) == ARRAY_TYPE
8607 || TREE_CODE (type
) == OFFSET_TYPE
)
8608 type
= TREE_TYPE (type
);
8610 /* Get the mode of the type being modified. */
8611 orig_mode
= TYPE_MODE (type
);
8613 if ((!INTEGRAL_TYPE_P (type
)
8614 && !SCALAR_FLOAT_TYPE_P (type
)
8615 && !FIXED_POINT_TYPE_P (type
))
8616 || (!SCALAR_FLOAT_MODE_P (orig_mode
)
8617 && GET_MODE_CLASS (orig_mode
) != MODE_INT
8618 && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode
))
8619 || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
8620 || TREE_CODE (type
) == BOOLEAN_TYPE
)
8622 error ("invalid vector type for attribute %qE", name
);
8626 if (vecsize
% tree_to_uhwi (TYPE_SIZE_UNIT (type
)))
8628 error ("vector size not an integral multiple of component size");
8634 error ("zero vector size");
8638 /* Calculate how many units fit in the vector. */
8639 nunits
= vecsize
/ tree_to_uhwi (TYPE_SIZE_UNIT (type
));
8640 if (nunits
& (nunits
- 1))
8642 error ("number of components of the vector not a power of two");
8646 new_type
= build_vector_type (type
, nunits
);
8648 /* Build back pointers if needed. */
8649 *node
= lang_hooks
.types
.reconstruct_complex_type (*node
, new_type
);
8654 /* Handle the "nonnull" attribute. */
8656 handle_nonnull_attribute (tree
*node
, tree
ARG_UNUSED (name
),
8657 tree args
, int ARG_UNUSED (flags
),
8661 unsigned HOST_WIDE_INT attr_arg_num
;
8663 /* If no arguments are specified, all pointer arguments should be
8664 non-null. Verify a full prototype is given so that the arguments
8665 will have the correct types when we actually check them later. */
8668 if (!prototype_p (type
))
8670 error ("nonnull attribute without arguments on a non-prototype");
8671 *no_add_attrs
= true;
8676 /* Argument list specified. Verify that each argument number references
8677 a pointer argument. */
8678 for (attr_arg_num
= 1; args
; args
= TREE_CHAIN (args
))
8680 unsigned HOST_WIDE_INT arg_num
= 0, ck_num
;
8682 if (!get_nonnull_operand (TREE_VALUE (args
), &arg_num
))
8684 error ("nonnull argument has invalid operand number (argument %lu)",
8685 (unsigned long) attr_arg_num
);
8686 *no_add_attrs
= true;
8690 if (prototype_p (type
))
8692 function_args_iterator iter
;
8695 function_args_iter_init (&iter
, type
);
8696 for (ck_num
= 1; ; ck_num
++, function_args_iter_next (&iter
))
8698 argument
= function_args_iter_cond (&iter
);
8699 if (argument
== NULL_TREE
|| ck_num
== arg_num
)
8704 || TREE_CODE (argument
) == VOID_TYPE
)
8706 error ("nonnull argument with out-of-range operand number (argument %lu, operand %lu)",
8707 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
8708 *no_add_attrs
= true;
8712 if (TREE_CODE (argument
) != POINTER_TYPE
)
8714 error ("nonnull argument references non-pointer operand (argument %lu, operand %lu)",
8715 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
8716 *no_add_attrs
= true;
8725 /* Check the argument list of a function call for null in argument slots
8726 that are marked as requiring a non-null pointer argument. The NARGS
8727 arguments are passed in the array ARGARRAY.
8731 check_function_nonnull (tree attrs
, int nargs
, tree
*argarray
)
8736 attrs
= lookup_attribute ("nonnull", attrs
);
8737 if (attrs
== NULL_TREE
)
8741 /* See if any of the nonnull attributes has no arguments. If so,
8742 then every pointer argument is checked (in which case the check
8743 for pointer type is done in check_nonnull_arg). */
8744 if (TREE_VALUE (a
) != NULL_TREE
)
8746 a
= lookup_attribute ("nonnull", TREE_CHAIN (a
));
8747 while (a
!= NULL_TREE
&& TREE_VALUE (a
) != NULL_TREE
);
8750 for (i
= 0; i
< nargs
; i
++)
8751 check_function_arguments_recurse (check_nonnull_arg
, NULL
, argarray
[i
],
8755 /* Walk the argument list. If we encounter an argument number we
8756 should check for non-null, do it. */
8757 for (i
= 0; i
< nargs
; i
++)
8759 for (a
= attrs
; ; a
= TREE_CHAIN (a
))
8761 a
= lookup_attribute ("nonnull", a
);
8762 if (a
== NULL_TREE
|| nonnull_check_p (TREE_VALUE (a
), i
+ 1))
8767 check_function_arguments_recurse (check_nonnull_arg
, NULL
,
8768 argarray
[i
], i
+ 1);
8773 /* Check that the Nth argument of a function call (counting backwards
8774 from the end) is a (pointer)0. The NARGS arguments are passed in the
8778 check_function_sentinel (const_tree fntype
, int nargs
, tree
*argarray
)
8780 tree attr
= lookup_attribute ("sentinel", TYPE_ATTRIBUTES (fntype
));
8787 function_args_iterator iter
;
8790 /* Skip over the named arguments. */
8791 FOREACH_FUNCTION_ARGS (fntype
, t
, iter
)
8798 if (TREE_VALUE (attr
))
8800 tree p
= TREE_VALUE (TREE_VALUE (attr
));
8801 pos
= TREE_INT_CST_LOW (p
);
8804 /* The sentinel must be one of the varargs, i.e.
8805 in position >= the number of fixed arguments. */
8806 if ((nargs
- 1 - pos
) < len
)
8808 warning (OPT_Wformat_
,
8809 "not enough variable arguments to fit a sentinel");
8813 /* Validate the sentinel. */
8814 sentinel
= argarray
[nargs
- 1 - pos
];
8815 if ((!POINTER_TYPE_P (TREE_TYPE (sentinel
))
8816 || !integer_zerop (sentinel
))
8817 /* Although __null (in C++) is only an integer we allow it
8818 nevertheless, as we are guaranteed that it's exactly
8819 as wide as a pointer, and we don't want to force
8820 users to cast the NULL they have written there.
8821 We warn with -Wstrict-null-sentinel, though. */
8822 && (warn_strict_null_sentinel
|| null_node
!= sentinel
))
8823 warning (OPT_Wformat_
, "missing sentinel in function call");
8827 /* Helper for check_function_nonnull; given a list of operands which
8828 must be non-null in ARGS, determine if operand PARAM_NUM should be
8832 nonnull_check_p (tree args
, unsigned HOST_WIDE_INT param_num
)
8834 unsigned HOST_WIDE_INT arg_num
= 0;
8836 for (; args
; args
= TREE_CHAIN (args
))
8838 bool found
= get_nonnull_operand (TREE_VALUE (args
), &arg_num
);
8842 if (arg_num
== param_num
)
8848 /* Check that the function argument PARAM (which is operand number
8849 PARAM_NUM) is non-null. This is called by check_function_nonnull
8850 via check_function_arguments_recurse. */
8853 check_nonnull_arg (void * ARG_UNUSED (ctx
), tree param
,
8854 unsigned HOST_WIDE_INT param_num
)
8856 /* Just skip checking the argument if it's not a pointer. This can
8857 happen if the "nonnull" attribute was given without an operand
8858 list (which means to check every pointer argument). */
8860 if (TREE_CODE (TREE_TYPE (param
)) != POINTER_TYPE
)
8863 if (integer_zerop (param
))
8864 warning (OPT_Wnonnull
, "null argument where non-null required "
8865 "(argument %lu)", (unsigned long) param_num
);
8868 /* Helper for nonnull attribute handling; fetch the operand number
8869 from the attribute argument list. */
8872 get_nonnull_operand (tree arg_num_expr
, unsigned HOST_WIDE_INT
*valp
)
8874 /* Verify the arg number is a constant. */
8875 if (TREE_CODE (arg_num_expr
) != INTEGER_CST
8876 || TREE_INT_CST_HIGH (arg_num_expr
) != 0)
8879 *valp
= TREE_INT_CST_LOW (arg_num_expr
);
8883 /* Handle a "nothrow" attribute; arguments as in
8884 struct attribute_spec.handler. */
8887 handle_nothrow_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8888 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8890 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8891 TREE_NOTHROW (*node
) = 1;
8892 /* ??? TODO: Support types. */
8895 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8896 *no_add_attrs
= true;
8902 /* Handle a "cleanup" attribute; arguments as in
8903 struct attribute_spec.handler. */
8906 handle_cleanup_attribute (tree
*node
, tree name
, tree args
,
8907 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8910 tree cleanup_id
, cleanup_decl
;
8912 /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
8913 for global destructors in C++. This requires infrastructure that
8914 we don't have generically at the moment. It's also not a feature
8915 we'd be missing too much, since we do have attribute constructor. */
8916 if (TREE_CODE (decl
) != VAR_DECL
|| TREE_STATIC (decl
))
8918 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8919 *no_add_attrs
= true;
8923 /* Verify that the argument is a function in scope. */
8924 /* ??? We could support pointers to functions here as well, if
8925 that was considered desirable. */
8926 cleanup_id
= TREE_VALUE (args
);
8927 if (TREE_CODE (cleanup_id
) != IDENTIFIER_NODE
)
8929 error ("cleanup argument not an identifier");
8930 *no_add_attrs
= true;
8933 cleanup_decl
= lookup_name (cleanup_id
);
8934 if (!cleanup_decl
|| TREE_CODE (cleanup_decl
) != FUNCTION_DECL
)
8936 error ("cleanup argument not a function");
8937 *no_add_attrs
= true;
8941 /* That the function has proper type is checked with the
8942 eventual call to build_function_call. */
8947 /* Handle a "warn_unused_result" attribute. No special handling. */
8950 handle_warn_unused_result_attribute (tree
*node
, tree name
,
8951 tree
ARG_UNUSED (args
),
8952 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8954 /* Ignore the attribute for functions not returning any value. */
8955 if (VOID_TYPE_P (TREE_TYPE (*node
)))
8957 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8958 *no_add_attrs
= true;
8964 /* Handle a "sentinel" attribute. */
8967 handle_sentinel_attribute (tree
*node
, tree name
, tree args
,
8968 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8970 if (!prototype_p (*node
))
8972 warning (OPT_Wattributes
,
8973 "%qE attribute requires prototypes with named arguments", name
);
8974 *no_add_attrs
= true;
8978 if (!stdarg_p (*node
))
8980 warning (OPT_Wattributes
,
8981 "%qE attribute only applies to variadic functions", name
);
8982 *no_add_attrs
= true;
8988 tree position
= TREE_VALUE (args
);
8990 if (TREE_CODE (position
) != INTEGER_CST
)
8992 warning (OPT_Wattributes
,
8993 "requested position is not an integer constant");
8994 *no_add_attrs
= true;
8998 if (tree_int_cst_lt (position
, integer_zero_node
))
9000 warning (OPT_Wattributes
,
9001 "requested position is less than zero");
9002 *no_add_attrs
= true;
9010 /* Handle a "type_generic" attribute. */
9013 handle_type_generic_attribute (tree
*node
, tree
ARG_UNUSED (name
),
9014 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
9015 bool * ARG_UNUSED (no_add_attrs
))
9017 /* Ensure we have a function type. */
9018 gcc_assert (TREE_CODE (*node
) == FUNCTION_TYPE
);
9020 /* Ensure we have a variadic function. */
9021 gcc_assert (!prototype_p (*node
) || stdarg_p (*node
));
9026 /* Handle a "target" attribute. */
9029 handle_target_attribute (tree
*node
, tree name
, tree args
, int flags
,
9032 /* Ensure we have a function type. */
9033 if (TREE_CODE (*node
) != FUNCTION_DECL
)
9035 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9036 *no_add_attrs
= true;
9038 else if (! targetm
.target_option
.valid_attribute_p (*node
, name
, args
,
9040 *no_add_attrs
= true;
9045 /* Arguments being collected for optimization. */
9046 typedef const char *const_char_p
; /* For DEF_VEC_P. */
9047 static GTY(()) vec
<const_char_p
, va_gc
> *optimize_args
;
9050 /* Inner function to convert a TREE_LIST to argv string to parse the optimize
9051 options in ARGS. ATTR_P is true if this is for attribute(optimize), and
9052 false for #pragma GCC optimize. */
9055 parse_optimize_options (tree args
, bool attr_p
)
9060 int saved_flag_strict_aliasing
;
9061 const char **opt_argv
;
9062 struct cl_decoded_option
*decoded_options
;
9063 unsigned int decoded_options_count
;
9066 /* Build up argv vector. Just in case the string is stored away, use garbage
9067 collected strings. */
9068 vec_safe_truncate (optimize_args
, 0);
9069 vec_safe_push (optimize_args
, (const char *) NULL
);
9071 for (ap
= args
; ap
!= NULL_TREE
; ap
= TREE_CHAIN (ap
))
9073 tree value
= TREE_VALUE (ap
);
9075 if (TREE_CODE (value
) == INTEGER_CST
)
9078 sprintf (buffer
, "-O%ld", (long) TREE_INT_CST_LOW (value
));
9079 vec_safe_push (optimize_args
, ggc_strdup (buffer
));
9082 else if (TREE_CODE (value
) == STRING_CST
)
9084 /* Split string into multiple substrings. */
9085 size_t len
= TREE_STRING_LENGTH (value
);
9086 char *p
= ASTRDUP (TREE_STRING_POINTER (value
));
9087 char *end
= p
+ len
;
9091 while (next_p
!= NULL
)
9097 comma
= strchr (p
, ',');
9110 r
= q
= (char *) ggc_alloc_atomic (len2
+ 3);
9112 /* If the user supplied -Oxxx or -fxxx, only allow -Oxxx or -fxxx
9114 if (*p
== '-' && p
[1] != 'O' && p
[1] != 'f')
9118 warning (OPT_Wattributes
,
9119 "bad option %s to optimize attribute", p
);
9121 warning (OPT_Wpragmas
,
9122 "bad option %s to pragma attribute", p
);
9130 /* Assume that Ox is -Ox, a numeric value is -Ox, a s by
9131 itself is -Os, and any other switch begins with a -f. */
9132 if ((*p
>= '0' && *p
<= '9')
9133 || (p
[0] == 's' && p
[1] == '\0'))
9139 memcpy (r
, p
, len2
);
9141 vec_safe_push (optimize_args
, (const char *) q
);
9147 opt_argc
= optimize_args
->length ();
9148 opt_argv
= (const char **) alloca (sizeof (char *) * (opt_argc
+ 1));
9150 for (i
= 1; i
< opt_argc
; i
++)
9151 opt_argv
[i
] = (*optimize_args
)[i
];
9153 saved_flag_strict_aliasing
= flag_strict_aliasing
;
9155 /* Now parse the options. */
9156 decode_cmdline_options_to_array_default_mask (opt_argc
, opt_argv
,
9158 &decoded_options_count
);
9159 decode_options (&global_options
, &global_options_set
,
9160 decoded_options
, decoded_options_count
,
9161 input_location
, global_dc
);
9163 targetm
.override_options_after_change();
9165 /* Don't allow changing -fstrict-aliasing. */
9166 flag_strict_aliasing
= saved_flag_strict_aliasing
;
9168 optimize_args
->truncate (0);
9172 /* For handling "optimize" attribute. arguments as in
9173 struct attribute_spec.handler. */
9176 handle_optimize_attribute (tree
*node
, tree name
, tree args
,
9177 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9179 /* Ensure we have a function type. */
9180 if (TREE_CODE (*node
) != FUNCTION_DECL
)
9182 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9183 *no_add_attrs
= true;
9187 struct cl_optimization cur_opts
;
9188 tree old_opts
= DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
);
9190 /* Save current options. */
9191 cl_optimization_save (&cur_opts
, &global_options
);
9193 /* If we previously had some optimization options, use them as the
9196 cl_optimization_restore (&global_options
,
9197 TREE_OPTIMIZATION (old_opts
));
9199 /* Parse options, and update the vector. */
9200 parse_optimize_options (args
, true);
9201 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
)
9202 = build_optimization_node (&global_options
);
9204 /* Restore current options. */
9205 cl_optimization_restore (&global_options
, &cur_opts
);
9211 /* Handle a "no_split_stack" attribute. */
9214 handle_no_split_stack_attribute (tree
*node
, tree name
,
9215 tree
ARG_UNUSED (args
),
9216 int ARG_UNUSED (flags
),
9221 if (TREE_CODE (decl
) != FUNCTION_DECL
)
9223 error_at (DECL_SOURCE_LOCATION (decl
),
9224 "%qE attribute applies only to functions", name
);
9225 *no_add_attrs
= true;
9227 else if (DECL_INITIAL (decl
))
9229 error_at (DECL_SOURCE_LOCATION (decl
),
9230 "can%'t set %qE attribute after definition", name
);
9231 *no_add_attrs
= true;
9237 /* Handle a "returns_nonnull" attribute; arguments as in
9238 struct attribute_spec.handler. */
9241 handle_returns_nonnull_attribute (tree
*node
, tree
, tree
, int,
9244 // Even without a prototype we still have a return type we can check.
9245 if (TREE_CODE (TREE_TYPE (*node
)) != POINTER_TYPE
)
9247 error ("returns_nonnull attribute on a function not returning a pointer");
9248 *no_add_attrs
= true;
9254 /* Check for valid arguments being passed to a function with FNTYPE.
9255 There are NARGS arguments in the array ARGARRAY. */
9257 check_function_arguments (const_tree fntype
, int nargs
, tree
*argarray
)
9259 /* Check for null being passed in a pointer argument that must be
9260 non-null. We also need to do this if format checking is enabled. */
9263 check_function_nonnull (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
9265 /* Check for errors in format strings. */
9267 if (warn_format
|| warn_suggest_attribute_format
)
9268 check_function_format (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
9271 check_function_sentinel (fntype
, nargs
, argarray
);
9274 /* Generic argument checking recursion routine. PARAM is the argument to
9275 be checked. PARAM_NUM is the number of the argument. CALLBACK is invoked
9276 once the argument is resolved. CTX is context for the callback. */
9278 check_function_arguments_recurse (void (*callback
)
9279 (void *, tree
, unsigned HOST_WIDE_INT
),
9280 void *ctx
, tree param
,
9281 unsigned HOST_WIDE_INT param_num
)
9283 if (CONVERT_EXPR_P (param
)
9284 && (TYPE_PRECISION (TREE_TYPE (param
))
9285 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (param
, 0)))))
9287 /* Strip coercion. */
9288 check_function_arguments_recurse (callback
, ctx
,
9289 TREE_OPERAND (param
, 0), param_num
);
9293 if (TREE_CODE (param
) == CALL_EXPR
)
9295 tree type
= TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (param
)));
9297 bool found_format_arg
= false;
9299 /* See if this is a call to a known internationalization function
9300 that modifies a format arg. Such a function may have multiple
9301 format_arg attributes (for example, ngettext). */
9303 for (attrs
= TYPE_ATTRIBUTES (type
);
9305 attrs
= TREE_CHAIN (attrs
))
9306 if (is_attribute_p ("format_arg", TREE_PURPOSE (attrs
)))
9309 tree format_num_expr
;
9312 call_expr_arg_iterator iter
;
9314 /* Extract the argument number, which was previously checked
9316 format_num_expr
= TREE_VALUE (TREE_VALUE (attrs
));
9318 format_num
= tree_to_uhwi (format_num_expr
);
9320 for (inner_arg
= first_call_expr_arg (param
, &iter
), i
= 1;
9322 inner_arg
= next_call_expr_arg (&iter
), i
++)
9323 if (i
== format_num
)
9325 check_function_arguments_recurse (callback
, ctx
,
9326 inner_arg
, param_num
);
9327 found_format_arg
= true;
9332 /* If we found a format_arg attribute and did a recursive check,
9333 we are done with checking this argument. Otherwise, we continue
9334 and this will be considered a non-literal. */
9335 if (found_format_arg
)
9339 if (TREE_CODE (param
) == COND_EXPR
)
9341 /* Check both halves of the conditional expression. */
9342 check_function_arguments_recurse (callback
, ctx
,
9343 TREE_OPERAND (param
, 1), param_num
);
9344 check_function_arguments_recurse (callback
, ctx
,
9345 TREE_OPERAND (param
, 2), param_num
);
9349 (*callback
) (ctx
, param
, param_num
);
9352 /* Checks for a builtin function FNDECL that the number of arguments
9353 NARGS against the required number REQUIRED and issues an error if
9354 there is a mismatch. Returns true if the number of arguments is
9355 correct, otherwise false. */
9358 builtin_function_validate_nargs (tree fndecl
, int nargs
, int required
)
9360 if (nargs
< required
)
9362 error_at (input_location
,
9363 "not enough arguments to function %qE", fndecl
);
9366 else if (nargs
> required
)
9368 error_at (input_location
,
9369 "too many arguments to function %qE", fndecl
);
9375 /* Verifies the NARGS arguments ARGS to the builtin function FNDECL.
9376 Returns false if there was an error, otherwise true. */
9379 check_builtin_function_arguments (tree fndecl
, int nargs
, tree
*args
)
9381 if (!DECL_BUILT_IN (fndecl
)
9382 || DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_NORMAL
)
9385 switch (DECL_FUNCTION_CODE (fndecl
))
9387 case BUILT_IN_CONSTANT_P
:
9388 return builtin_function_validate_nargs (fndecl
, nargs
, 1);
9390 case BUILT_IN_ISFINITE
:
9391 case BUILT_IN_ISINF
:
9392 case BUILT_IN_ISINF_SIGN
:
9393 case BUILT_IN_ISNAN
:
9394 case BUILT_IN_ISNORMAL
:
9395 if (builtin_function_validate_nargs (fndecl
, nargs
, 1))
9397 if (TREE_CODE (TREE_TYPE (args
[0])) != REAL_TYPE
)
9399 error ("non-floating-point argument in call to "
9400 "function %qE", fndecl
);
9407 case BUILT_IN_ISGREATER
:
9408 case BUILT_IN_ISGREATEREQUAL
:
9409 case BUILT_IN_ISLESS
:
9410 case BUILT_IN_ISLESSEQUAL
:
9411 case BUILT_IN_ISLESSGREATER
:
9412 case BUILT_IN_ISUNORDERED
:
9413 if (builtin_function_validate_nargs (fndecl
, nargs
, 2))
9415 enum tree_code code0
, code1
;
9416 code0
= TREE_CODE (TREE_TYPE (args
[0]));
9417 code1
= TREE_CODE (TREE_TYPE (args
[1]));
9418 if (!((code0
== REAL_TYPE
&& code1
== REAL_TYPE
)
9419 || (code0
== REAL_TYPE
&& code1
== INTEGER_TYPE
)
9420 || (code0
== INTEGER_TYPE
&& code1
== REAL_TYPE
)))
9422 error ("non-floating-point arguments in call to "
9423 "function %qE", fndecl
);
9430 case BUILT_IN_FPCLASSIFY
:
9431 if (builtin_function_validate_nargs (fndecl
, nargs
, 6))
9436 if (TREE_CODE (args
[i
]) != INTEGER_CST
)
9438 error ("non-const integer argument %u in call to function %qE",
9443 if (TREE_CODE (TREE_TYPE (args
[5])) != REAL_TYPE
)
9445 error ("non-floating-point argument in call to function %qE",
9453 case BUILT_IN_ASSUME_ALIGNED
:
9454 if (builtin_function_validate_nargs (fndecl
, nargs
, 2 + (nargs
> 2)))
9456 if (nargs
>= 3 && TREE_CODE (TREE_TYPE (args
[2])) != INTEGER_TYPE
)
9458 error ("non-integer argument 3 in call to function %qE", fndecl
);
9470 /* Function to help qsort sort FIELD_DECLs by name order. */
9473 field_decl_cmp (const void *x_p
, const void *y_p
)
9475 const tree
*const x
= (const tree
*const) x_p
;
9476 const tree
*const y
= (const tree
*const) y_p
;
9478 if (DECL_NAME (*x
) == DECL_NAME (*y
))
9479 /* A nontype is "greater" than a type. */
9480 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
9481 if (DECL_NAME (*x
) == NULL_TREE
)
9483 if (DECL_NAME (*y
) == NULL_TREE
)
9485 if (DECL_NAME (*x
) < DECL_NAME (*y
))
9491 gt_pointer_operator new_value
;
9495 /* This routine compares two fields like field_decl_cmp but using the
9496 pointer operator in resort_data. */
9499 resort_field_decl_cmp (const void *x_p
, const void *y_p
)
9501 const tree
*const x
= (const tree
*const) x_p
;
9502 const tree
*const y
= (const tree
*const) y_p
;
9504 if (DECL_NAME (*x
) == DECL_NAME (*y
))
9505 /* A nontype is "greater" than a type. */
9506 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
9507 if (DECL_NAME (*x
) == NULL_TREE
)
9509 if (DECL_NAME (*y
) == NULL_TREE
)
9512 tree d1
= DECL_NAME (*x
);
9513 tree d2
= DECL_NAME (*y
);
9514 resort_data
.new_value (&d1
, resort_data
.cookie
);
9515 resort_data
.new_value (&d2
, resort_data
.cookie
);
9522 /* Resort DECL_SORTED_FIELDS because pointers have been reordered. */
9525 resort_sorted_fields (void *obj
,
9526 void * ARG_UNUSED (orig_obj
),
9527 gt_pointer_operator new_value
,
9530 struct sorted_fields_type
*sf
= (struct sorted_fields_type
*) obj
;
9531 resort_data
.new_value
= new_value
;
9532 resort_data
.cookie
= cookie
;
9533 qsort (&sf
->elts
[0], sf
->len
, sizeof (tree
),
9534 resort_field_decl_cmp
);
9537 /* Subroutine of c_parse_error.
9538 Return the result of concatenating LHS and RHS. RHS is really
9539 a string literal, its first character is indicated by RHS_START and
9540 RHS_SIZE is its length (including the terminating NUL character).
9542 The caller is responsible for deleting the returned pointer. */
9545 catenate_strings (const char *lhs
, const char *rhs_start
, int rhs_size
)
9547 const int lhs_size
= strlen (lhs
);
9548 char *result
= XNEWVEC (char, lhs_size
+ rhs_size
);
9549 strncpy (result
, lhs
, lhs_size
);
9550 strncpy (result
+ lhs_size
, rhs_start
, rhs_size
);
9554 /* Issue the error given by GMSGID, indicating that it occurred before
9555 TOKEN, which had the associated VALUE. */
9558 c_parse_error (const char *gmsgid
, enum cpp_ttype token_type
,
9559 tree value
, unsigned char token_flags
)
9561 #define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2))
9563 char *message
= NULL
;
9565 if (token_type
== CPP_EOF
)
9566 message
= catenate_messages (gmsgid
, " at end of input");
9567 else if (token_type
== CPP_CHAR
9568 || token_type
== CPP_WCHAR
9569 || token_type
== CPP_CHAR16
9570 || token_type
== CPP_CHAR32
)
9572 unsigned int val
= TREE_INT_CST_LOW (value
);
9591 if (val
<= UCHAR_MAX
&& ISGRAPH (val
))
9592 message
= catenate_messages (gmsgid
, " before %s'%c'");
9594 message
= catenate_messages (gmsgid
, " before %s'\\x%x'");
9596 error (message
, prefix
, val
);
9600 else if (token_type
== CPP_CHAR_USERDEF
9601 || token_type
== CPP_WCHAR_USERDEF
9602 || token_type
== CPP_CHAR16_USERDEF
9603 || token_type
== CPP_CHAR32_USERDEF
)
9604 message
= catenate_messages (gmsgid
,
9605 " before user-defined character literal");
9606 else if (token_type
== CPP_STRING_USERDEF
9607 || token_type
== CPP_WSTRING_USERDEF
9608 || token_type
== CPP_STRING16_USERDEF
9609 || token_type
== CPP_STRING32_USERDEF
9610 || token_type
== CPP_UTF8STRING_USERDEF
)
9611 message
= catenate_messages (gmsgid
, " before user-defined string literal");
9612 else if (token_type
== CPP_STRING
9613 || token_type
== CPP_WSTRING
9614 || token_type
== CPP_STRING16
9615 || token_type
== CPP_STRING32
9616 || token_type
== CPP_UTF8STRING
)
9617 message
= catenate_messages (gmsgid
, " before string constant");
9618 else if (token_type
== CPP_NUMBER
)
9619 message
= catenate_messages (gmsgid
, " before numeric constant");
9620 else if (token_type
== CPP_NAME
)
9622 message
= catenate_messages (gmsgid
, " before %qE");
9623 error (message
, value
);
9627 else if (token_type
== CPP_PRAGMA
)
9628 message
= catenate_messages (gmsgid
, " before %<#pragma%>");
9629 else if (token_type
== CPP_PRAGMA_EOL
)
9630 message
= catenate_messages (gmsgid
, " before end of line");
9631 else if (token_type
== CPP_DECLTYPE
)
9632 message
= catenate_messages (gmsgid
, " before %<decltype%>");
9633 else if (token_type
< N_TTYPES
)
9635 message
= catenate_messages (gmsgid
, " before %qs token");
9636 error (message
, cpp_type2name (token_type
, token_flags
));
9648 #undef catenate_messages
9651 /* Mapping for cpp message reasons to the options that enable them. */
9653 struct reason_option_codes_t
9655 const int reason
; /* cpplib message reason. */
9656 const int option_code
; /* gcc option that controls this message. */
9659 static const struct reason_option_codes_t option_codes
[] = {
9660 {CPP_W_DEPRECATED
, OPT_Wdeprecated
},
9661 {CPP_W_COMMENTS
, OPT_Wcomment
},
9662 {CPP_W_TRIGRAPHS
, OPT_Wtrigraphs
},
9663 {CPP_W_MULTICHAR
, OPT_Wmultichar
},
9664 {CPP_W_TRADITIONAL
, OPT_Wtraditional
},
9665 {CPP_W_LONG_LONG
, OPT_Wlong_long
},
9666 {CPP_W_ENDIF_LABELS
, OPT_Wendif_labels
},
9667 {CPP_W_VARIADIC_MACROS
, OPT_Wvariadic_macros
},
9668 {CPP_W_BUILTIN_MACRO_REDEFINED
, OPT_Wbuiltin_macro_redefined
},
9669 {CPP_W_UNDEF
, OPT_Wundef
},
9670 {CPP_W_UNUSED_MACROS
, OPT_Wunused_macros
},
9671 {CPP_W_CXX_OPERATOR_NAMES
, OPT_Wc___compat
},
9672 {CPP_W_NORMALIZE
, OPT_Wnormalized_
},
9673 {CPP_W_INVALID_PCH
, OPT_Winvalid_pch
},
9674 {CPP_W_WARNING_DIRECTIVE
, OPT_Wcpp
},
9675 {CPP_W_LITERAL_SUFFIX
, OPT_Wliteral_suffix
},
9676 {CPP_W_DATE_TIME
, OPT_Wdate_time
},
9680 /* Return the gcc option code associated with the reason for a cpp
9681 message, or 0 if none. */
9684 c_option_controlling_cpp_error (int reason
)
9686 const struct reason_option_codes_t
*entry
;
9688 for (entry
= option_codes
; entry
->reason
!= CPP_W_NONE
; entry
++)
9690 if (entry
->reason
== reason
)
9691 return entry
->option_code
;
9696 /* Callback from cpp_error for PFILE to print diagnostics from the
9697 preprocessor. The diagnostic is of type LEVEL, with REASON set
9698 to the reason code if LEVEL is represents a warning, at location
9699 LOCATION unless this is after lexing and the compiler's location
9700 should be used instead, with column number possibly overridden by
9701 COLUMN_OVERRIDE if not zero; MSG is the translated message and AP
9702 the arguments. Returns true if a diagnostic was emitted, false
9706 c_cpp_error (cpp_reader
*pfile ATTRIBUTE_UNUSED
, int level
, int reason
,
9707 location_t location
, unsigned int column_override
,
9708 const char *msg
, va_list *ap
)
9710 diagnostic_info diagnostic
;
9711 diagnostic_t dlevel
;
9712 bool save_warn_system_headers
= global_dc
->dc_warn_system_headers
;
9717 case CPP_DL_WARNING_SYSHDR
:
9720 global_dc
->dc_warn_system_headers
= 1;
9722 case CPP_DL_WARNING
:
9725 dlevel
= DK_WARNING
;
9727 case CPP_DL_PEDWARN
:
9728 if (flag_no_output
&& !flag_pedantic_errors
)
9730 dlevel
= DK_PEDWARN
;
9748 location
= input_location
;
9749 diagnostic_set_info_translated (&diagnostic
, msg
, ap
,
9751 if (column_override
)
9752 diagnostic_override_column (&diagnostic
, column_override
);
9753 diagnostic_override_option_index (&diagnostic
,
9754 c_option_controlling_cpp_error (reason
));
9755 ret
= report_diagnostic (&diagnostic
);
9756 if (level
== CPP_DL_WARNING_SYSHDR
)
9757 global_dc
->dc_warn_system_headers
= save_warn_system_headers
;
9761 /* Convert a character from the host to the target execution character
9762 set. cpplib handles this, mostly. */
9765 c_common_to_target_charset (HOST_WIDE_INT c
)
9767 /* Character constants in GCC proper are sign-extended under -fsigned-char,
9768 zero-extended under -fno-signed-char. cpplib insists that characters
9769 and character constants are always unsigned. Hence we must convert
9771 cppchar_t uc
= ((cppchar_t
)c
) & ((((cppchar_t
)1) << CHAR_BIT
)-1);
9773 uc
= cpp_host_to_exec_charset (parse_in
, uc
);
9775 if (flag_signed_char
)
9776 return ((HOST_WIDE_INT
)uc
) << (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
)
9777 >> (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
);
9782 /* Fold an offsetof-like expression. EXPR is a nested sequence of component
9783 references with an INDIRECT_REF of a constant at the bottom; much like the
9784 traditional rendering of offsetof as a macro. Return the folded result. */
9787 fold_offsetof_1 (tree expr
)
9791 switch (TREE_CODE (expr
))
9797 error ("cannot apply %<offsetof%> to static data member %qD", expr
);
9798 return error_mark_node
;
9802 error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded");
9803 return error_mark_node
;
9807 if (!TREE_CONSTANT (TREE_OPERAND (expr
, 0)))
9809 error ("cannot apply %<offsetof%> to a non constant address");
9810 return error_mark_node
;
9812 return TREE_OPERAND (expr
, 0);
9815 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0));
9816 if (base
== error_mark_node
)
9819 t
= TREE_OPERAND (expr
, 1);
9820 if (DECL_C_BIT_FIELD (t
))
9822 error ("attempt to take address of bit-field structure "
9824 return error_mark_node
;
9826 off
= size_binop_loc (input_location
, PLUS_EXPR
, DECL_FIELD_OFFSET (t
),
9827 size_int (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (t
))
9832 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0));
9833 if (base
== error_mark_node
)
9836 t
= TREE_OPERAND (expr
, 1);
9838 /* Check if the offset goes beyond the upper bound of the array. */
9839 if (TREE_CODE (t
) == INTEGER_CST
&& tree_int_cst_sgn (t
) >= 0)
9841 tree upbound
= array_ref_up_bound (expr
);
9842 if (upbound
!= NULL_TREE
9843 && TREE_CODE (upbound
) == INTEGER_CST
9844 && !tree_int_cst_equal (upbound
,
9845 TYPE_MAX_VALUE (TREE_TYPE (upbound
))))
9847 upbound
= size_binop (PLUS_EXPR
, upbound
,
9848 build_int_cst (TREE_TYPE (upbound
), 1));
9849 if (tree_int_cst_lt (upbound
, t
))
9853 for (v
= TREE_OPERAND (expr
, 0);
9854 TREE_CODE (v
) == COMPONENT_REF
;
9855 v
= TREE_OPERAND (v
, 0))
9856 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v
, 0)))
9859 tree fld_chain
= DECL_CHAIN (TREE_OPERAND (v
, 1));
9860 for (; fld_chain
; fld_chain
= DECL_CHAIN (fld_chain
))
9861 if (TREE_CODE (fld_chain
) == FIELD_DECL
)
9867 /* Don't warn if the array might be considered a poor
9868 man's flexible array member with a very permissive
9869 definition thereof. */
9870 if (TREE_CODE (v
) == ARRAY_REF
9871 || TREE_CODE (v
) == COMPONENT_REF
)
9872 warning (OPT_Warray_bounds
,
9873 "index %E denotes an offset "
9874 "greater than size of %qT",
9875 t
, TREE_TYPE (TREE_OPERAND (expr
, 0)));
9880 t
= convert (sizetype
, t
);
9881 off
= size_binop (MULT_EXPR
, TYPE_SIZE_UNIT (TREE_TYPE (expr
)), t
);
9885 /* Handle static members of volatile structs. */
9886 t
= TREE_OPERAND (expr
, 1);
9887 gcc_assert (TREE_CODE (t
) == VAR_DECL
);
9888 return fold_offsetof_1 (t
);
9894 return fold_build_pointer_plus (base
, off
);
9897 /* Likewise, but convert it to the return type of offsetof. */
9900 fold_offsetof (tree expr
)
9902 return convert (size_type_node
, fold_offsetof_1 (expr
));
9905 /* Warn for A ?: C expressions (with B omitted) where A is a boolean
9906 expression, because B will always be true. */
9909 warn_for_omitted_condop (location_t location
, tree cond
)
9911 if (truth_value_p (TREE_CODE (cond
)))
9912 warning_at (location
, OPT_Wparentheses
,
9913 "the omitted middle operand in ?: will always be %<true%>, "
9914 "suggest explicit middle operand");
9917 /* Give an error for storing into ARG, which is 'const'. USE indicates
9918 how ARG was being used. */
9921 readonly_error (location_t loc
, tree arg
, enum lvalue_use use
)
9923 gcc_assert (use
== lv_assign
|| use
== lv_increment
|| use
== lv_decrement
9925 /* Using this macro rather than (for example) arrays of messages
9926 ensures that all the format strings are checked at compile
9928 #define READONLY_MSG(A, I, D, AS) (use == lv_assign ? (A) \
9929 : (use == lv_increment ? (I) \
9930 : (use == lv_decrement ? (D) : (AS))))
9931 if (TREE_CODE (arg
) == COMPONENT_REF
)
9933 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg
, 0))))
9934 error_at (loc
, READONLY_MSG (G_("assignment of member "
9935 "%qD in read-only object"),
9936 G_("increment of member "
9937 "%qD in read-only object"),
9938 G_("decrement of member "
9939 "%qD in read-only object"),
9940 G_("member %qD in read-only object "
9941 "used as %<asm%> output")),
9942 TREE_OPERAND (arg
, 1));
9944 error_at (loc
, READONLY_MSG (G_("assignment of read-only member %qD"),
9945 G_("increment of read-only member %qD"),
9946 G_("decrement of read-only member %qD"),
9947 G_("read-only member %qD used as %<asm%> output")),
9948 TREE_OPERAND (arg
, 1));
9950 else if (TREE_CODE (arg
) == VAR_DECL
)
9951 error_at (loc
, READONLY_MSG (G_("assignment of read-only variable %qD"),
9952 G_("increment of read-only variable %qD"),
9953 G_("decrement of read-only variable %qD"),
9954 G_("read-only variable %qD used as %<asm%> output")),
9956 else if (TREE_CODE (arg
) == PARM_DECL
)
9957 error_at (loc
, READONLY_MSG (G_("assignment of read-only parameter %qD"),
9958 G_("increment of read-only parameter %qD"),
9959 G_("decrement of read-only parameter %qD"),
9960 G_("read-only parameter %qD use as %<asm%> output")),
9962 else if (TREE_CODE (arg
) == RESULT_DECL
)
9964 gcc_assert (c_dialect_cxx ());
9965 error_at (loc
, READONLY_MSG (G_("assignment of "
9966 "read-only named return value %qD"),
9968 "read-only named return value %qD"),
9970 "read-only named return value %qD"),
9971 G_("read-only named return value %qD "
9972 "used as %<asm%>output")),
9975 else if (TREE_CODE (arg
) == FUNCTION_DECL
)
9976 error_at (loc
, READONLY_MSG (G_("assignment of function %qD"),
9977 G_("increment of function %qD"),
9978 G_("decrement of function %qD"),
9979 G_("function %qD used as %<asm%> output")),
9982 error_at (loc
, READONLY_MSG (G_("assignment of read-only location %qE"),
9983 G_("increment of read-only location %qE"),
9984 G_("decrement of read-only location %qE"),
9985 G_("read-only location %qE used as %<asm%> output")),
9989 /* Print an error message for an invalid lvalue. USE says
9990 how the lvalue is being used and so selects the error message. LOC
9991 is the location for the error. */
9994 lvalue_error (location_t loc
, enum lvalue_use use
)
9999 error_at (loc
, "lvalue required as left operand of assignment");
10002 error_at (loc
, "lvalue required as increment operand");
10005 error_at (loc
, "lvalue required as decrement operand");
10008 error_at (loc
, "lvalue required as unary %<&%> operand");
10011 error_at (loc
, "lvalue required in asm statement");
10014 gcc_unreachable ();
10018 /* Print an error message for an invalid indirection of type TYPE.
10019 ERRSTRING is the name of the operator for the indirection. */
10022 invalid_indirection_error (location_t loc
, tree type
, ref_operator errstring
)
10027 gcc_assert (c_dialect_cxx ());
10028 error_at (loc
, "invalid type argument (have %qT)", type
);
10030 case RO_ARRAY_INDEXING
:
10032 "invalid type argument of array indexing (have %qT)",
10035 case RO_UNARY_STAR
:
10037 "invalid type argument of unary %<*%> (have %qT)",
10042 "invalid type argument of %<->%> (have %qT)",
10045 case RO_ARROW_STAR
:
10047 "invalid type argument of %<->*%> (have %qT)",
10050 case RO_IMPLICIT_CONVERSION
:
10052 "invalid type argument of implicit conversion (have %qT)",
10056 gcc_unreachable ();
10060 /* *PTYPE is an incomplete array. Complete it with a domain based on
10061 INITIAL_VALUE. If INITIAL_VALUE is not present, use 1 if DO_DEFAULT
10062 is true. Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
10063 2 if INITIAL_VALUE was NULL, and 3 if INITIAL_VALUE was empty. */
10066 complete_array_type (tree
*ptype
, tree initial_value
, bool do_default
)
10068 tree maxindex
, type
, main_type
, elt
, unqual_elt
;
10069 int failure
= 0, quals
;
10070 hashval_t hashcode
= 0;
10071 bool overflow_p
= false;
10073 maxindex
= size_zero_node
;
10076 if (TREE_CODE (initial_value
) == STRING_CST
)
10079 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value
)));
10080 maxindex
= size_int (TREE_STRING_LENGTH (initial_value
)/eltsize
- 1);
10082 else if (TREE_CODE (initial_value
) == CONSTRUCTOR
)
10084 vec
<constructor_elt
, va_gc
> *v
= CONSTRUCTOR_ELTS (initial_value
);
10086 if (vec_safe_is_empty (v
))
10090 maxindex
= ssize_int (-1);
10095 unsigned HOST_WIDE_INT cnt
;
10096 constructor_elt
*ce
;
10097 bool fold_p
= false;
10100 maxindex
= (*v
)[0].index
, fold_p
= true;
10102 curindex
= maxindex
;
10104 for (cnt
= 1; vec_safe_iterate (v
, cnt
, &ce
); cnt
++)
10106 bool curfold_p
= false;
10108 curindex
= ce
->index
, curfold_p
= true;
10113 /* Since we treat size types now as ordinary
10114 unsigned types, we need an explicit overflow
10116 tree orig
= curindex
;
10117 curindex
= fold_convert (sizetype
, curindex
);
10118 overflow_p
|= tree_int_cst_lt (curindex
, orig
);
10120 curindex
= size_binop (PLUS_EXPR
, curindex
,
10123 if (tree_int_cst_lt (maxindex
, curindex
))
10124 maxindex
= curindex
, fold_p
= curfold_p
;
10128 tree orig
= maxindex
;
10129 maxindex
= fold_convert (sizetype
, maxindex
);
10130 overflow_p
|= tree_int_cst_lt (maxindex
, orig
);
10136 /* Make an error message unless that happened already. */
10137 if (initial_value
!= error_mark_node
)
10149 /* Force an indefinite layout factor. */
10150 if (upc_shared_type_p (type
))
10151 type
= c_build_qualified_type_1 (type
, TYPE_QUAL_SHARED
, size_zero_node
);
10152 elt
= TREE_TYPE (type
);
10153 quals
= TYPE_QUALS (strip_array_types (elt
));
10157 unqual_elt
= c_build_qualified_type (elt
, KEEP_QUAL_ADDR_SPACE (quals
));
10159 /* Using build_distinct_type_copy and modifying things afterward instead
10160 of using build_array_type to create a new type preserves all of the
10161 TYPE_LANG_FLAG_? bits that the front end may have set. */
10162 main_type
= build_distinct_type_copy (TYPE_MAIN_VARIANT (type
));
10163 TREE_TYPE (main_type
) = unqual_elt
;
10164 TYPE_DOMAIN (main_type
)
10165 = build_range_type (TREE_TYPE (maxindex
),
10166 build_int_cst (TREE_TYPE (maxindex
), 0), maxindex
);
10167 layout_type (main_type
);
10169 /* Make sure we have the canonical MAIN_TYPE. */
10170 hashcode
= iterative_hash_object (TYPE_HASH (unqual_elt
), hashcode
);
10171 hashcode
= iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (main_type
)),
10173 main_type
= type_hash_canon (hashcode
, main_type
);
10175 /* Fix the canonical type. */
10176 if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type
))
10177 || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type
)))
10178 SET_TYPE_STRUCTURAL_EQUALITY (main_type
);
10179 else if (TYPE_CANONICAL (TREE_TYPE (main_type
)) != TREE_TYPE (main_type
)
10180 || (TYPE_CANONICAL (TYPE_DOMAIN (main_type
))
10181 != TYPE_DOMAIN (main_type
)))
10182 TYPE_CANONICAL (main_type
)
10183 = build_array_type (TYPE_CANONICAL (TREE_TYPE (main_type
)),
10184 TYPE_CANONICAL (TYPE_DOMAIN (main_type
)));
10186 TYPE_CANONICAL (main_type
) = main_type
;
10191 type
= c_build_qualified_type (main_type
, quals
);
10193 if (COMPLETE_TYPE_P (type
)
10194 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
10195 && (overflow_p
|| TREE_OVERFLOW (TYPE_SIZE_UNIT (type
))))
10197 error ("size of array is too large");
10198 /* If we proceed with the array type as it is, we'll eventually
10199 crash in tree_to_[su]hwi(). */
10200 type
= error_mark_node
;
10207 /* Like c_mark_addressable but don't check register qualifier. */
10209 c_common_mark_addressable_vec (tree t
)
10211 while (handled_component_p (t
))
10212 t
= TREE_OPERAND (t
, 0);
10213 if (TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != PARM_DECL
)
10215 TREE_ADDRESSABLE (t
) = 1;
10220 /* Used to help initialize the builtin-types.def table. When a type of
10221 the correct size doesn't exist, use error_mark_node instead of NULL.
10222 The later results in segfaults even when a decl using the type doesn't
10226 builtin_type_for_size (int size
, bool unsignedp
)
10228 tree type
= c_common_type_for_size (size
, unsignedp
);
10229 return type
? type
: error_mark_node
;
10232 /* A helper function for resolve_overloaded_builtin in resolving the
10233 overloaded __sync_ builtins. Returns a positive power of 2 if the
10234 first operand of PARAMS is a pointer to a supported data type.
10235 Returns 0 if an error is encountered. */
10238 sync_resolve_size (tree function
, vec
<tree
, va_gc
> *params
)
10245 error ("too few arguments to function %qE", function
);
10249 type
= TREE_TYPE ((*params
)[0]);
10250 if (TREE_CODE (type
) != POINTER_TYPE
)
10253 type
= TREE_TYPE (type
);
10254 if (!INTEGRAL_TYPE_P (type
) && !POINTER_TYPE_P (type
))
10257 size
= tree_to_uhwi (TYPE_SIZE_UNIT (type
));
10258 if (size
== 1 || size
== 2 || size
== 4 || size
== 8 || size
== 16)
10262 error ("incompatible type for argument %d of %qE", 1, function
);
10266 /* A helper function for resolve_overloaded_builtin. Adds casts to
10267 PARAMS to make arguments match up with those of FUNCTION. Drops
10268 the variadic arguments at the end. Returns false if some error
10269 was encountered; true on success. */
10272 sync_resolve_params (location_t loc
, tree orig_function
, tree function
,
10273 vec
<tree
, va_gc
> *params
, bool orig_format
)
10275 function_args_iterator iter
;
10277 unsigned int parmnum
;
10279 function_args_iter_init (&iter
, TREE_TYPE (function
));
10280 /* We've declared the implementation functions to use "volatile void *"
10281 as the pointer parameter, so we shouldn't get any complaints from the
10282 call to check_function_arguments what ever type the user used. */
10283 function_args_iter_next (&iter
);
10284 ptype
= TREE_TYPE (TREE_TYPE ((*params
)[0]));
10285 ptype
= TYPE_MAIN_VARIANT (ptype
);
10287 /* For the rest of the values, we need to cast these to FTYPE, so that we
10288 don't get warnings for passing pointer types, etc. */
10292 tree val
, arg_type
;
10294 arg_type
= function_args_iter_cond (&iter
);
10295 /* XXX void_type_node belies the abstraction. */
10296 if (arg_type
== void_type_node
)
10300 if (params
->length () <= parmnum
)
10302 error_at (loc
, "too few arguments to function %qE", orig_function
);
10306 /* Only convert parameters if arg_type is unsigned integer type with
10307 new format sync routines, i.e. don't attempt to convert pointer
10308 arguments (e.g. EXPECTED argument of __atomic_compare_exchange_n),
10309 bool arguments (e.g. WEAK argument) or signed int arguments (memmodel
10311 if (TREE_CODE (arg_type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (arg_type
))
10313 /* Ideally for the first conversion we'd use convert_for_assignment
10314 so that we get warnings for anything that doesn't match the pointer
10315 type. This isn't portable across the C and C++ front ends atm. */
10316 val
= (*params
)[parmnum
];
10317 val
= convert (ptype
, val
);
10318 val
= convert (arg_type
, val
);
10319 (*params
)[parmnum
] = val
;
10322 function_args_iter_next (&iter
);
10325 /* __atomic routines are not variadic. */
10326 if (!orig_format
&& params
->length () != parmnum
+ 1)
10328 error_at (loc
, "too many arguments to function %qE", orig_function
);
10332 /* The definition of these primitives is variadic, with the remaining
10333 being "an optional list of variables protected by the memory barrier".
10334 No clue what that's supposed to mean, precisely, but we consider all
10335 call-clobbered variables to be protected so we're safe. */
10336 params
->truncate (parmnum
+ 1);
10341 /* A helper function for resolve_overloaded_builtin. Adds a cast to
10342 RESULT to make it match the type of the first pointer argument in
10346 sync_resolve_return (tree first_param
, tree result
, bool orig_format
)
10348 tree ptype
= TREE_TYPE (TREE_TYPE (first_param
));
10349 tree rtype
= TREE_TYPE (result
);
10350 ptype
= TYPE_MAIN_VARIANT (ptype
);
10352 /* New format doesn't require casting unless the types are the same size. */
10353 if (orig_format
|| tree_int_cst_equal (TYPE_SIZE (ptype
), TYPE_SIZE (rtype
)))
10354 return convert (ptype
, result
);
10359 /* This function verifies the PARAMS to generic atomic FUNCTION.
10360 It returns the size if all the parameters are the same size, otherwise
10361 0 is returned if the parameters are invalid. */
10364 get_atomic_generic_size (location_t loc
, tree function
,
10365 vec
<tree
, va_gc
> *params
)
10367 unsigned int n_param
;
10368 unsigned int n_model
;
10373 /* Determine the parameter makeup. */
10374 switch (DECL_FUNCTION_CODE (function
))
10376 case BUILT_IN_ATOMIC_EXCHANGE
:
10380 case BUILT_IN_ATOMIC_LOAD
:
10381 case BUILT_IN_ATOMIC_STORE
:
10385 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10390 gcc_unreachable ();
10393 if (vec_safe_length (params
) != n_param
)
10395 error_at (loc
, "incorrect number of arguments to function %qE", function
);
10399 /* Get type of first parameter, and determine its size. */
10400 type_0
= TREE_TYPE ((*params
)[0]);
10401 if (TREE_CODE (type_0
) != POINTER_TYPE
|| VOID_TYPE_P (TREE_TYPE (type_0
)))
10403 error_at (loc
, "argument 1 of %qE must be a non-void pointer type",
10408 /* Types must be compile time constant sizes. */
10409 if (TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type_0
)))) != INTEGER_CST
)
10412 "argument 1 of %qE must be a pointer to a constant size type",
10417 size_0
= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type_0
)));
10419 /* Zero size objects are not allowed. */
10423 "argument 1 of %qE must be a pointer to a nonzero size object",
10428 /* Check each other parameter is a pointer and the same size. */
10429 for (x
= 0; x
< n_param
- n_model
; x
++)
10432 tree type
= TREE_TYPE ((*params
)[x
]);
10433 /* __atomic_compare_exchange has a bool in the 4th position, skip it. */
10434 if (n_param
== 6 && x
== 3)
10436 if (!POINTER_TYPE_P (type
))
10438 error_at (loc
, "argument %d of %qE must be a pointer type", x
+ 1,
10442 size
= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type
)));
10443 if (size
!= size_0
)
10445 error_at (loc
, "size mismatch in argument %d of %qE", x
+ 1,
10451 /* Check memory model parameters for validity. */
10452 for (x
= n_param
- n_model
; x
< n_param
; x
++)
10454 tree p
= (*params
)[x
];
10455 if (TREE_CODE (p
) == INTEGER_CST
)
10457 int i
= tree_to_uhwi (p
);
10458 if (i
< 0 || (i
& MEMMODEL_MASK
) >= MEMMODEL_LAST
)
10460 warning_at (loc
, OPT_Winvalid_memory_model
,
10461 "invalid memory model argument %d of %qE", x
+ 1,
10466 if (!INTEGRAL_TYPE_P (TREE_TYPE (p
)))
10468 error_at (loc
, "non-integer memory model argument %d of %qE", x
+ 1,
10478 /* This will take an __atomic_ generic FUNCTION call, and add a size parameter N
10479 at the beginning of the parameter list PARAMS representing the size of the
10480 objects. This is to match the library ABI requirement. LOC is the location
10481 of the function call.
10482 The new function is returned if it needed rebuilding, otherwise NULL_TREE is
10483 returned to allow the external call to be constructed. */
10486 add_atomic_size_parameter (unsigned n
, location_t loc
, tree function
,
10487 vec
<tree
, va_gc
> *params
)
10491 /* Insert a SIZE_T parameter as the first param. If there isn't
10492 enough space, allocate a new vector and recursively re-build with that. */
10493 if (!params
->space (1))
10495 unsigned int z
, len
;
10496 vec
<tree
, va_gc
> *v
;
10499 len
= params
->length ();
10500 vec_alloc (v
, len
+ 1);
10501 for (z
= 0; z
< len
; z
++)
10502 v
->quick_push ((*params
)[z
]);
10503 f
= build_function_call_vec (loc
, function
, v
, NULL
);
10508 /* Add the size parameter and leave as a function call for processing. */
10509 size_node
= build_int_cst (size_type_node
, n
);
10510 params
->quick_insert (0, size_node
);
10515 /* Return whether atomic operations for naturally aligned N-byte
10516 arguments are supported, whether inline or through libatomic. */
10518 atomic_size_supported_p (int n
)
10529 return targetm
.scalar_mode_supported_p (TImode
);
10536 /* This will process an __atomic_exchange function call, determine whether it
10537 needs to be mapped to the _N variation, or turned into a library call.
10538 LOC is the location of the builtin call.
10539 FUNCTION is the DECL that has been invoked;
10540 PARAMS is the argument list for the call. The return value is non-null
10541 TRUE is returned if it is translated into the proper format for a call to the
10542 external library, and NEW_RETURN is set the tree for that function.
10543 FALSE is returned if processing for the _N variation is required, and
10544 NEW_RETURN is set to the the return value the result is copied into. */
10546 resolve_overloaded_atomic_exchange (location_t loc
, tree function
,
10547 vec
<tree
, va_gc
> *params
, tree
*new_return
)
10549 tree p0
, p1
, p2
, p3
;
10550 tree I_type
, I_type_ptr
;
10551 int n
= get_atomic_generic_size (loc
, function
, params
);
10553 /* Size of 0 is an error condition. */
10556 *new_return
= error_mark_node
;
10560 /* If not a lock-free size, change to the library generic format. */
10561 if (!atomic_size_supported_p (n
))
10563 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10567 /* Otherwise there is a lockfree match, transform the call from:
10568 void fn(T* mem, T* desired, T* return, model)
10570 *return = (T) (fn (In* mem, (In) *desired, model)) */
10577 /* Create pointer to appropriate size. */
10578 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10579 I_type_ptr
= build_pointer_type (I_type
);
10581 /* Convert object pointer to required type. */
10582 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10584 /* Convert new value to required type, and dereference it. */
10585 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
10586 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
10589 /* Move memory model to the 3rd position, and end param list. */
10591 params
->truncate (3);
10593 /* Convert return pointer and dereference it for later assignment. */
10594 *new_return
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
10600 /* This will process an __atomic_compare_exchange function call, determine
10601 whether it needs to be mapped to the _N variation, or turned into a lib call.
10602 LOC is the location of the builtin call.
10603 FUNCTION is the DECL that has been invoked;
10604 PARAMS is the argument list for the call. The return value is non-null
10605 TRUE is returned if it is translated into the proper format for a call to the
10606 external library, and NEW_RETURN is set the tree for that function.
10607 FALSE is returned if processing for the _N variation is required. */
10610 resolve_overloaded_atomic_compare_exchange (location_t loc
, tree function
,
10611 vec
<tree
, va_gc
> *params
,
10615 tree I_type
, I_type_ptr
;
10616 int n
= get_atomic_generic_size (loc
, function
, params
);
10618 /* Size of 0 is an error condition. */
10621 *new_return
= error_mark_node
;
10625 /* If not a lock-free size, change to the library generic format. */
10626 if (!atomic_size_supported_p (n
))
10628 /* The library generic format does not have the weak parameter, so
10629 remove it from the param list. Since a parameter has been removed,
10630 we can be sure that there is room for the SIZE_T parameter, meaning
10631 there will not be a recursive rebuilding of the parameter list, so
10632 there is no danger this will be done twice. */
10635 (*params
)[3] = (*params
)[4];
10636 (*params
)[4] = (*params
)[5];
10637 params
->truncate (5);
10639 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10643 /* Otherwise, there is a match, so the call needs to be transformed from:
10644 bool fn(T* mem, T* desired, T* return, weak, success, failure)
10646 bool fn ((In *)mem, (In *)expected, (In) *desired, weak, succ, fail) */
10652 /* Create pointer to appropriate size. */
10653 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10654 I_type_ptr
= build_pointer_type (I_type
);
10656 /* Convert object pointer to required type. */
10657 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10660 /* Convert expected pointer to required type. */
10661 p1
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p1
);
10664 /* Convert desired value to required type, and dereference it. */
10665 p2
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
10666 p2
= build1 (VIEW_CONVERT_EXPR
, I_type
, p2
);
10669 /* The rest of the parameters are fine. NULL means no special return value
10671 *new_return
= NULL
;
10676 /* This will process an __atomic_load function call, determine whether it
10677 needs to be mapped to the _N variation, or turned into a library call.
10678 LOC is the location of the builtin call.
10679 FUNCTION is the DECL that has been invoked;
10680 PARAMS is the argument list for the call. The return value is non-null
10681 TRUE is returned if it is translated into the proper format for a call to the
10682 external library, and NEW_RETURN is set the tree for that function.
10683 FALSE is returned if processing for the _N variation is required, and
10684 NEW_RETURN is set to the the return value the result is copied into. */
10687 resolve_overloaded_atomic_load (location_t loc
, tree function
,
10688 vec
<tree
, va_gc
> *params
, tree
*new_return
)
10691 tree I_type
, I_type_ptr
;
10692 int n
= get_atomic_generic_size (loc
, function
, params
);
10694 /* Size of 0 is an error condition. */
10697 *new_return
= error_mark_node
;
10701 /* If not a lock-free size, change to the library generic format. */
10702 if (!atomic_size_supported_p (n
))
10704 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10708 /* Otherwise, there is a match, so the call needs to be transformed from:
10709 void fn(T* mem, T* return, model)
10711 *return = (T) (fn ((In *) mem, model)) */
10717 /* Create pointer to appropriate size. */
10718 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10719 I_type_ptr
= build_pointer_type (I_type
);
10721 /* Convert object pointer to required type. */
10722 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10725 /* Move memory model to the 2nd position, and end param list. */
10727 params
->truncate (2);
10729 /* Convert return pointer and dereference it for later assignment. */
10730 *new_return
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
10736 /* This will process an __atomic_store function call, determine whether it
10737 needs to be mapped to the _N variation, or turned into a library call.
10738 LOC is the location of the builtin call.
10739 FUNCTION is the DECL that has been invoked;
10740 PARAMS is the argument list for the call. The return value is non-null
10741 TRUE is returned if it is translated into the proper format for a call to the
10742 external library, and NEW_RETURN is set the tree for that function.
10743 FALSE is returned if processing for the _N variation is required, and
10744 NEW_RETURN is set to the the return value the result is copied into. */
10747 resolve_overloaded_atomic_store (location_t loc
, tree function
,
10748 vec
<tree
, va_gc
> *params
, tree
*new_return
)
10751 tree I_type
, I_type_ptr
;
10752 int n
= get_atomic_generic_size (loc
, function
, params
);
10754 /* Size of 0 is an error condition. */
10757 *new_return
= error_mark_node
;
10761 /* If not a lock-free size, change to the library generic format. */
10762 if (!atomic_size_supported_p (n
))
10764 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10768 /* Otherwise, there is a match, so the call needs to be transformed from:
10769 void fn(T* mem, T* value, model)
10771 fn ((In *) mem, (In) *value, model) */
10776 /* Create pointer to appropriate size. */
10777 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10778 I_type_ptr
= build_pointer_type (I_type
);
10780 /* Convert object pointer to required type. */
10781 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10784 /* Convert new value to required type, and dereference it. */
10785 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
10786 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
10789 /* The memory model is in the right spot already. Return is void. */
10790 *new_return
= NULL_TREE
;
10796 /* Some builtin functions are placeholders for other expressions. This
10797 function should be called immediately after parsing the call expression
10798 before surrounding code has committed to the type of the expression.
10800 LOC is the location of the builtin call.
10802 FUNCTION is the DECL that has been invoked; it is known to be a builtin.
10803 PARAMS is the argument list for the call. The return value is non-null
10804 when expansion is complete, and null if normal processing should
10808 resolve_overloaded_builtin (location_t loc
, tree function
,
10809 vec
<tree
, va_gc
> *params
)
10811 enum built_in_function orig_code
= DECL_FUNCTION_CODE (function
);
10812 bool orig_format
= true;
10813 tree new_return
= NULL_TREE
;
10815 switch (DECL_BUILT_IN_CLASS (function
))
10817 case BUILT_IN_NORMAL
:
10820 if (targetm
.resolve_overloaded_builtin
)
10821 return targetm
.resolve_overloaded_builtin (loc
, function
, params
);
10828 /* Handle BUILT_IN_NORMAL here. */
10831 case BUILT_IN_ATOMIC_EXCHANGE
:
10832 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10833 case BUILT_IN_ATOMIC_LOAD
:
10834 case BUILT_IN_ATOMIC_STORE
:
10836 /* Handle these 4 together so that they can fall through to the next
10837 case if the call is transformed to an _N variant. */
10840 case BUILT_IN_ATOMIC_EXCHANGE
:
10842 if (resolve_overloaded_atomic_exchange (loc
, function
, params
,
10845 /* Change to the _N variant. */
10846 orig_code
= BUILT_IN_ATOMIC_EXCHANGE_N
;
10850 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10852 if (resolve_overloaded_atomic_compare_exchange (loc
, function
,
10856 /* Change to the _N variant. */
10857 orig_code
= BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
;
10860 case BUILT_IN_ATOMIC_LOAD
:
10862 if (resolve_overloaded_atomic_load (loc
, function
, params
,
10865 /* Change to the _N variant. */
10866 orig_code
= BUILT_IN_ATOMIC_LOAD_N
;
10869 case BUILT_IN_ATOMIC_STORE
:
10871 if (resolve_overloaded_atomic_store (loc
, function
, params
,
10874 /* Change to the _N variant. */
10875 orig_code
= BUILT_IN_ATOMIC_STORE_N
;
10879 gcc_unreachable ();
10881 /* Fallthrough to the normal processing. */
10883 case BUILT_IN_ATOMIC_EXCHANGE_N
:
10884 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
:
10885 case BUILT_IN_ATOMIC_LOAD_N
:
10886 case BUILT_IN_ATOMIC_STORE_N
:
10887 case BUILT_IN_ATOMIC_ADD_FETCH_N
:
10888 case BUILT_IN_ATOMIC_SUB_FETCH_N
:
10889 case BUILT_IN_ATOMIC_AND_FETCH_N
:
10890 case BUILT_IN_ATOMIC_NAND_FETCH_N
:
10891 case BUILT_IN_ATOMIC_XOR_FETCH_N
:
10892 case BUILT_IN_ATOMIC_OR_FETCH_N
:
10893 case BUILT_IN_ATOMIC_FETCH_ADD_N
:
10894 case BUILT_IN_ATOMIC_FETCH_SUB_N
:
10895 case BUILT_IN_ATOMIC_FETCH_AND_N
:
10896 case BUILT_IN_ATOMIC_FETCH_NAND_N
:
10897 case BUILT_IN_ATOMIC_FETCH_XOR_N
:
10898 case BUILT_IN_ATOMIC_FETCH_OR_N
:
10900 orig_format
= false;
10901 /* Fallthru for parameter processing. */
10903 case BUILT_IN_SYNC_FETCH_AND_ADD_N
:
10904 case BUILT_IN_SYNC_FETCH_AND_SUB_N
:
10905 case BUILT_IN_SYNC_FETCH_AND_OR_N
:
10906 case BUILT_IN_SYNC_FETCH_AND_AND_N
:
10907 case BUILT_IN_SYNC_FETCH_AND_XOR_N
:
10908 case BUILT_IN_SYNC_FETCH_AND_NAND_N
:
10909 case BUILT_IN_SYNC_ADD_AND_FETCH_N
:
10910 case BUILT_IN_SYNC_SUB_AND_FETCH_N
:
10911 case BUILT_IN_SYNC_OR_AND_FETCH_N
:
10912 case BUILT_IN_SYNC_AND_AND_FETCH_N
:
10913 case BUILT_IN_SYNC_XOR_AND_FETCH_N
:
10914 case BUILT_IN_SYNC_NAND_AND_FETCH_N
:
10915 case BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
:
10916 case BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N
:
10917 case BUILT_IN_SYNC_LOCK_TEST_AND_SET_N
:
10918 case BUILT_IN_SYNC_LOCK_RELEASE_N
:
10920 int n
= sync_resolve_size (function
, params
);
10921 tree new_function
, first_param
, result
;
10922 enum built_in_function fncode
;
10925 return error_mark_node
;
10927 fncode
= (enum built_in_function
)((int)orig_code
+ exact_log2 (n
) + 1);
10928 new_function
= builtin_decl_explicit (fncode
);
10929 if (!sync_resolve_params (loc
, function
, new_function
, params
,
10931 return error_mark_node
;
10933 first_param
= (*params
)[0];
10934 result
= build_function_call_vec (loc
, new_function
, params
, NULL
);
10935 if (result
== error_mark_node
)
10937 if (orig_code
!= BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
10938 && orig_code
!= BUILT_IN_SYNC_LOCK_RELEASE_N
10939 && orig_code
!= BUILT_IN_ATOMIC_STORE_N
)
10940 result
= sync_resolve_return (first_param
, result
, orig_format
);
10942 /* If new_return is set, assign function to that expr and cast the
10943 result to void since the generic interface returned void. */
10946 /* Cast function result from I{1,2,4,8,16} to the required type. */
10947 result
= build1 (VIEW_CONVERT_EXPR
, TREE_TYPE (new_return
), result
);
10948 result
= build2 (MODIFY_EXPR
, TREE_TYPE (new_return
), new_return
,
10950 TREE_SIDE_EFFECTS (result
) = 1;
10951 protected_set_expr_location (result
, loc
);
10952 result
= convert (void_type_node
, result
);
10962 /* vector_types_compatible_elements_p is used in type checks of vectors
10963 values used as operands of binary operators. Where it returns true, and
10964 the other checks of the caller succeed (being vector types in he first
10965 place, and matching number of elements), we can just treat the types
10966 as essentially the same.
10967 Contrast with vector_targets_convertible_p, which is used for vector
10968 pointer types, and vector_types_convertible_p, which will allow
10969 language-specific matches under the control of flag_lax_vector_conversions,
10970 and might still require a conversion. */
10971 /* True if vector types T1 and T2 can be inputs to the same binary
10972 operator without conversion.
10973 We don't check the overall vector size here because some of our callers
10974 want to give different error messages when the vectors are compatible
10975 except for the element count. */
10978 vector_types_compatible_elements_p (tree t1
, tree t2
)
10980 bool opaque
= TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
);
10981 t1
= TREE_TYPE (t1
);
10982 t2
= TREE_TYPE (t2
);
10984 enum tree_code c1
= TREE_CODE (t1
), c2
= TREE_CODE (t2
);
10986 gcc_assert ((c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
|| c1
== FIXED_POINT_TYPE
)
10987 && (c2
== INTEGER_TYPE
|| c2
== REAL_TYPE
10988 || c2
== FIXED_POINT_TYPE
));
10990 t1
= c_common_signed_type (t1
);
10991 t2
= c_common_signed_type (t2
);
10992 /* Equality works here because c_common_signed_type uses
10993 TYPE_MAIN_VARIANT. */
10996 if (opaque
&& c1
== c2
10997 && (c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
)
10998 && TYPE_PRECISION (t1
) == TYPE_PRECISION (t2
))
11003 /* Check for missing format attributes on function pointers. LTYPE is
11004 the new type or left-hand side type. RTYPE is the old type or
11005 right-hand side type. Returns TRUE if LTYPE is missing the desired
11009 check_missing_format_attribute (tree ltype
, tree rtype
)
11011 tree
const ttr
= TREE_TYPE (rtype
), ttl
= TREE_TYPE (ltype
);
11014 for (ra
= TYPE_ATTRIBUTES (ttr
); ra
; ra
= TREE_CHAIN (ra
))
11015 if (is_attribute_p ("format", TREE_PURPOSE (ra
)))
11020 for (la
= TYPE_ATTRIBUTES (ttl
); la
; la
= TREE_CHAIN (la
))
11021 if (is_attribute_p ("format", TREE_PURPOSE (la
)))
11029 /* Subscripting with type char is likely to lose on a machine where
11030 chars are signed. So warn on any machine, but optionally. Don't
11031 warn for unsigned char since that type is safe. Don't warn for
11032 signed char because anyone who uses that must have done so
11033 deliberately. Furthermore, we reduce the false positive load by
11034 warning only for non-constant value of type char. */
11037 warn_array_subscript_with_type_char (tree index
)
11039 if (TYPE_MAIN_VARIANT (TREE_TYPE (index
)) == char_type_node
11040 && TREE_CODE (index
) != INTEGER_CST
)
11041 warning (OPT_Wchar_subscripts
, "array subscript has type %<char%>");
11044 /* Implement -Wparentheses for the unexpected C precedence rules, to
11045 cover cases like x + y << z which readers are likely to
11046 misinterpret. We have seen an expression in which CODE is a binary
11047 operator used to combine expressions ARG_LEFT and ARG_RIGHT, which
11048 before folding had CODE_LEFT and CODE_RIGHT. CODE_LEFT and
11049 CODE_RIGHT may be ERROR_MARK, which means that that side of the
11050 expression was not formed using a binary or unary operator, or it
11051 was enclosed in parentheses. */
11054 warn_about_parentheses (location_t loc
, enum tree_code code
,
11055 enum tree_code code_left
, tree arg_left
,
11056 enum tree_code code_right
, tree arg_right
)
11058 if (!warn_parentheses
)
11061 /* This macro tests that the expression ARG with original tree code
11062 CODE appears to be a boolean expression. or the result of folding a
11063 boolean expression. */
11064 #define APPEARS_TO_BE_BOOLEAN_EXPR_P(CODE, ARG) \
11065 (truth_value_p (TREE_CODE (ARG)) \
11066 || TREE_CODE (TREE_TYPE (ARG)) == BOOLEAN_TYPE \
11067 /* Folding may create 0 or 1 integers from other expressions. */ \
11068 || ((CODE) != INTEGER_CST \
11069 && (integer_onep (ARG) || integer_zerop (ARG))))
11074 if (code_left
== PLUS_EXPR
)
11075 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11076 "suggest parentheses around %<+%> inside %<<<%>");
11077 else if (code_right
== PLUS_EXPR
)
11078 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11079 "suggest parentheses around %<+%> inside %<<<%>");
11080 else if (code_left
== MINUS_EXPR
)
11081 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11082 "suggest parentheses around %<-%> inside %<<<%>");
11083 else if (code_right
== MINUS_EXPR
)
11084 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11085 "suggest parentheses around %<-%> inside %<<<%>");
11089 if (code_left
== PLUS_EXPR
)
11090 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11091 "suggest parentheses around %<+%> inside %<>>%>");
11092 else if (code_right
== PLUS_EXPR
)
11093 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11094 "suggest parentheses around %<+%> inside %<>>%>");
11095 else if (code_left
== MINUS_EXPR
)
11096 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11097 "suggest parentheses around %<-%> inside %<>>%>");
11098 else if (code_right
== MINUS_EXPR
)
11099 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11100 "suggest parentheses around %<-%> inside %<>>%>");
11103 case TRUTH_ORIF_EXPR
:
11104 if (code_left
== TRUTH_ANDIF_EXPR
)
11105 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11106 "suggest parentheses around %<&&%> within %<||%>");
11107 else if (code_right
== TRUTH_ANDIF_EXPR
)
11108 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11109 "suggest parentheses around %<&&%> within %<||%>");
11113 if (code_left
== BIT_AND_EXPR
|| code_left
== BIT_XOR_EXPR
11114 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
)
11115 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11116 "suggest parentheses around arithmetic in operand of %<|%>");
11117 else if (code_right
== BIT_AND_EXPR
|| code_right
== BIT_XOR_EXPR
11118 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
11119 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11120 "suggest parentheses around arithmetic in operand of %<|%>");
11121 /* Check cases like x|y==z */
11122 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11123 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11124 "suggest parentheses around comparison in operand of %<|%>");
11125 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11126 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11127 "suggest parentheses around comparison in operand of %<|%>");
11128 /* Check cases like !x | y */
11129 else if (code_left
== TRUTH_NOT_EXPR
11130 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
11131 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11132 "suggest parentheses around operand of "
11133 "%<!%> or change %<|%> to %<||%> or %<!%> to %<~%>");
11137 if (code_left
== BIT_AND_EXPR
11138 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
)
11139 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11140 "suggest parentheses around arithmetic in operand of %<^%>");
11141 else if (code_right
== BIT_AND_EXPR
11142 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
11143 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11144 "suggest parentheses around arithmetic in operand of %<^%>");
11145 /* Check cases like x^y==z */
11146 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11147 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11148 "suggest parentheses around comparison in operand of %<^%>");
11149 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11150 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11151 "suggest parentheses around comparison in operand of %<^%>");
11155 if (code_left
== PLUS_EXPR
)
11156 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11157 "suggest parentheses around %<+%> in operand of %<&%>");
11158 else if (code_right
== PLUS_EXPR
)
11159 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11160 "suggest parentheses around %<+%> in operand of %<&%>");
11161 else if (code_left
== MINUS_EXPR
)
11162 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11163 "suggest parentheses around %<-%> in operand of %<&%>");
11164 else if (code_right
== MINUS_EXPR
)
11165 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11166 "suggest parentheses around %<-%> in operand of %<&%>");
11167 /* Check cases like x&y==z */
11168 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11169 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11170 "suggest parentheses around comparison in operand of %<&%>");
11171 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11172 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11173 "suggest parentheses around comparison in operand of %<&%>");
11174 /* Check cases like !x & y */
11175 else if (code_left
== TRUTH_NOT_EXPR
11176 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
11177 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11178 "suggest parentheses around operand of "
11179 "%<!%> or change %<&%> to %<&&%> or %<!%> to %<~%>");
11183 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11184 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11185 "suggest parentheses around comparison in operand of %<==%>");
11186 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11187 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11188 "suggest parentheses around comparison in operand of %<==%>");
11191 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11192 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11193 "suggest parentheses around comparison in operand of %<!=%>");
11194 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11195 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11196 "suggest parentheses around comparison in operand of %<!=%>");
11200 if (TREE_CODE_CLASS (code
) == tcc_comparison
)
11202 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
11203 && code_left
!= NE_EXPR
&& code_left
!= EQ_EXPR
11204 && INTEGRAL_TYPE_P (TREE_TYPE (arg_left
)))
11205 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11206 "comparisons like %<X<=Y<=Z%> do not "
11207 "have their mathematical meaning");
11208 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
11209 && code_right
!= NE_EXPR
&& code_right
!= EQ_EXPR
11210 && INTEGRAL_TYPE_P (TREE_TYPE (arg_right
)))
11211 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11212 "comparisons like %<X<=Y<=Z%> do not "
11213 "have their mathematical meaning");
11217 #undef NOT_A_BOOLEAN_EXPR_P
11220 /* If LABEL (a LABEL_DECL) has not been used, issue a warning. */
11223 warn_for_unused_label (tree label
)
11225 if (!TREE_USED (label
))
11227 if (DECL_INITIAL (label
))
11228 warning (OPT_Wunused_label
, "label %q+D defined but not used", label
);
11230 warning (OPT_Wunused_label
, "label %q+D declared but not defined", label
);
11234 /* Warn for division by zero according to the value of DIVISOR. LOC
11235 is the location of the division operator. */
11238 warn_for_div_by_zero (location_t loc
, tree divisor
)
11240 /* If DIVISOR is zero, and has integral or fixed-point type, issue a warning
11241 about division by zero. Do not issue a warning if DIVISOR has a
11242 floating-point type, since we consider 0.0/0.0 a valid way of
11243 generating a NaN. */
11244 if (c_inhibit_evaluation_warnings
== 0
11245 && (integer_zerop (divisor
) || fixed_zerop (divisor
)))
11246 warning_at (loc
, OPT_Wdiv_by_zero
, "division by zero");
11249 /* Subroutine of build_binary_op. Give warnings for comparisons
11250 between signed and unsigned quantities that may fail. Do the
11251 checking based on the original operand trees ORIG_OP0 and ORIG_OP1,
11252 so that casts will be considered, but default promotions won't
11255 LOCATION is the location of the comparison operator.
11257 The arguments of this function map directly to local variables
11258 of build_binary_op. */
11261 warn_for_sign_compare (location_t location
,
11262 tree orig_op0
, tree orig_op1
,
11263 tree op0
, tree op1
,
11264 tree result_type
, enum tree_code resultcode
)
11266 int op0_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op0
));
11267 int op1_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op1
));
11268 int unsignedp0
, unsignedp1
;
11270 /* In C++, check for comparison of different enum types. */
11271 if (c_dialect_cxx()
11272 && TREE_CODE (TREE_TYPE (orig_op0
)) == ENUMERAL_TYPE
11273 && TREE_CODE (TREE_TYPE (orig_op1
)) == ENUMERAL_TYPE
11274 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0
))
11275 != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1
)))
11277 warning_at (location
,
11278 OPT_Wsign_compare
, "comparison between types %qT and %qT",
11279 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
));
11282 /* Do not warn if the comparison is being done in a signed type,
11283 since the signed type will only be chosen if it can represent
11284 all the values of the unsigned type. */
11285 if (!TYPE_UNSIGNED (result_type
))
11287 /* Do not warn if both operands are unsigned. */
11288 else if (op0_signed
== op1_signed
)
11292 tree sop
, uop
, base_type
;
11296 sop
= orig_op0
, uop
= orig_op1
;
11298 sop
= orig_op1
, uop
= orig_op0
;
11300 STRIP_TYPE_NOPS (sop
);
11301 STRIP_TYPE_NOPS (uop
);
11302 base_type
= (TREE_CODE (result_type
) == COMPLEX_TYPE
11303 ? TREE_TYPE (result_type
) : result_type
);
11305 /* Do not warn if the signed quantity is an unsuffixed integer
11306 literal (or some static constant expression involving such
11307 literals or a conditional expression involving such literals)
11308 and it is non-negative. */
11309 if (tree_expr_nonnegative_warnv_p (sop
, &ovf
))
11311 /* Do not warn if the comparison is an equality operation, the
11312 unsigned quantity is an integral constant, and it would fit
11313 in the result if the result were signed. */
11314 else if (TREE_CODE (uop
) == INTEGER_CST
11315 && (resultcode
== EQ_EXPR
|| resultcode
== NE_EXPR
)
11316 && int_fits_type_p (uop
, c_common_signed_type (base_type
)))
11318 /* In C, do not warn if the unsigned quantity is an enumeration
11319 constant and its maximum value would fit in the result if the
11320 result were signed. */
11321 else if (!c_dialect_cxx() && TREE_CODE (uop
) == INTEGER_CST
11322 && TREE_CODE (TREE_TYPE (uop
)) == ENUMERAL_TYPE
11323 && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (uop
)),
11324 c_common_signed_type (base_type
)))
11327 warning_at (location
,
11329 "comparison between signed and unsigned integer expressions");
11332 /* Warn if two unsigned values are being compared in a size larger
11333 than their original size, and one (and only one) is the result of
11334 a `~' operator. This comparison will always fail.
11336 Also warn if one operand is a constant, and the constant does not
11337 have all bits set that are set in the ~ operand when it is
11340 op0
= c_common_get_narrower (op0
, &unsignedp0
);
11341 op1
= c_common_get_narrower (op1
, &unsignedp1
);
11343 if ((TREE_CODE (op0
) == BIT_NOT_EXPR
)
11344 ^ (TREE_CODE (op1
) == BIT_NOT_EXPR
))
11346 if (TREE_CODE (op0
) == BIT_NOT_EXPR
)
11347 op0
= c_common_get_narrower (TREE_OPERAND (op0
, 0), &unsignedp0
);
11348 if (TREE_CODE (op1
) == BIT_NOT_EXPR
)
11349 op1
= c_common_get_narrower (TREE_OPERAND (op1
, 0), &unsignedp1
);
11351 if (tree_fits_shwi_p (op0
) || tree_fits_shwi_p (op1
))
11354 HOST_WIDE_INT constant
, mask
;
11358 if (tree_fits_shwi_p (op0
))
11361 unsignedp
= unsignedp1
;
11362 constant
= tree_to_shwi (op0
);
11367 unsignedp
= unsignedp0
;
11368 constant
= tree_to_shwi (op1
);
11371 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
11372 if (bits
< TYPE_PRECISION (result_type
)
11373 && bits
< HOST_BITS_PER_LONG
&& unsignedp
)
11375 mask
= (~ (HOST_WIDE_INT
) 0) << bits
;
11376 if ((mask
& constant
) != mask
)
11379 warning (OPT_Wsign_compare
,
11380 "promoted ~unsigned is always non-zero");
11382 warning_at (location
, OPT_Wsign_compare
,
11383 "comparison of promoted ~unsigned with constant");
11387 else if (unsignedp0
&& unsignedp1
11388 && (TYPE_PRECISION (TREE_TYPE (op0
))
11389 < TYPE_PRECISION (result_type
))
11390 && (TYPE_PRECISION (TREE_TYPE (op1
))
11391 < TYPE_PRECISION (result_type
)))
11392 warning_at (location
, OPT_Wsign_compare
,
11393 "comparison of promoted ~unsigned with unsigned");
11397 /* RESULT_TYPE is the result of converting TYPE1 and TYPE2 to a common
11398 type via c_common_type. If -Wdouble-promotion is in use, and the
11399 conditions for warning have been met, issue a warning. GMSGID is
11400 the warning message. It must have two %T specifiers for the type
11401 that was converted (generally "float") and the type to which it was
11402 converted (generally "double), respectively. LOC is the location
11403 to which the awrning should refer. */
11406 do_warn_double_promotion (tree result_type
, tree type1
, tree type2
,
11407 const char *gmsgid
, location_t loc
)
11411 if (!warn_double_promotion
)
11413 /* If the conversion will not occur at run-time, there is no need to
11415 if (c_inhibit_evaluation_warnings
)
11417 if (TYPE_MAIN_VARIANT (result_type
) != double_type_node
11418 && TYPE_MAIN_VARIANT (result_type
) != complex_double_type_node
)
11420 if (TYPE_MAIN_VARIANT (type1
) == float_type_node
11421 || TYPE_MAIN_VARIANT (type1
) == complex_float_type_node
)
11422 source_type
= type1
;
11423 else if (TYPE_MAIN_VARIANT (type2
) == float_type_node
11424 || TYPE_MAIN_VARIANT (type2
) == complex_float_type_node
)
11425 source_type
= type2
;
11428 warning_at (loc
, OPT_Wdouble_promotion
, gmsgid
, source_type
, result_type
);
11431 /* Setup a TYPE_DECL node as a typedef representation.
11433 X is a TYPE_DECL for a typedef statement. Create a brand new
11434 ..._TYPE node (which will be just a variant of the existing
11435 ..._TYPE node with identical properties) and then install X
11436 as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
11438 The whole point here is to end up with a situation where each
11439 and every ..._TYPE node the compiler creates will be uniquely
11440 associated with AT MOST one node representing a typedef name.
11441 This way, even though the compiler substitutes corresponding
11442 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
11443 early on, later parts of the compiler can always do the reverse
11444 translation and get back the corresponding typedef name. For
11447 typedef struct S MY_TYPE;
11450 Later parts of the compiler might only know that `object' was of
11451 type `struct S' if it were not for code just below. With this
11452 code however, later parts of the compiler see something like:
11454 struct S' == struct S
11455 typedef struct S' MY_TYPE;
11458 And they can then deduce (from the node for type struct S') that
11459 the original object declaration was:
11463 Being able to do this is important for proper support of protoize,
11464 and also for generating precise symbolic debugging information
11465 which takes full account of the programmer's (typedef) vocabulary.
11467 Obviously, we don't want to generate a duplicate ..._TYPE node if
11468 the TYPE_DECL node that we are now processing really represents a
11469 standard built-in type. */
11472 set_underlying_type (tree x
)
11474 if (x
== error_mark_node
)
11476 if (DECL_IS_BUILTIN (x
))
11478 if (TYPE_NAME (TREE_TYPE (x
)) == 0)
11479 TYPE_NAME (TREE_TYPE (x
)) = x
;
11481 else if (TREE_TYPE (x
) != error_mark_node
11482 && DECL_ORIGINAL_TYPE (x
) == NULL_TREE
)
11484 tree tt
= TREE_TYPE (x
);
11485 DECL_ORIGINAL_TYPE (x
) = tt
;
11486 tt
= build_variant_type_copy (tt
);
11487 TYPE_STUB_DECL (tt
) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x
));
11488 TYPE_NAME (tt
) = x
;
11489 TREE_USED (tt
) = TREE_USED (x
);
11490 TREE_TYPE (x
) = tt
;
11494 /* Record the types used by the current global variable declaration
11495 being parsed, so that we can decide later to emit their debug info.
11496 Those types are in types_used_by_cur_var_decl, and we are going to
11497 store them in the types_used_by_vars_hash hash table.
11498 DECL is the declaration of the global variable that has been parsed. */
11501 record_types_used_by_current_var_decl (tree decl
)
11503 gcc_assert (decl
&& DECL_P (decl
) && TREE_STATIC (decl
));
11505 while (types_used_by_cur_var_decl
&& !types_used_by_cur_var_decl
->is_empty ())
11507 tree type
= types_used_by_cur_var_decl
->pop ();
11508 types_used_by_var_decl_insert (type
, decl
);
11512 /* If DECL is a typedef that is declared in the current function,
11513 record it for the purpose of -Wunused-local-typedefs. */
11516 record_locally_defined_typedef (tree decl
)
11518 struct c_language_function
*l
;
11520 if (!warn_unused_local_typedefs
11522 /* if this is not a locally defined typedef then we are not
11524 || !is_typedef_decl (decl
)
11525 || !decl_function_context (decl
))
11528 l
= (struct c_language_function
*) cfun
->language
;
11529 vec_safe_push (l
->local_typedefs
, decl
);
11532 /* If T is a TYPE_DECL declared locally, mark it as used. */
11535 maybe_record_typedef_use (tree t
)
11537 if (!is_typedef_decl (t
))
11540 TREE_USED (t
) = true;
11543 /* Warn if there are some unused locally defined typedefs in the
11544 current function. */
11547 maybe_warn_unused_local_typedefs (void)
11551 /* The number of times we have emitted -Wunused-local-typedefs
11552 warnings. If this is different from errorcount, that means some
11553 unrelated errors have been issued. In which case, we'll avoid
11554 emitting "unused-local-typedefs" warnings. */
11555 static int unused_local_typedefs_warn_count
;
11556 struct c_language_function
*l
;
11561 if ((l
= (struct c_language_function
*) cfun
->language
) == NULL
)
11564 if (warn_unused_local_typedefs
11565 && errorcount
== unused_local_typedefs_warn_count
)
11567 FOR_EACH_VEC_SAFE_ELT (l
->local_typedefs
, i
, decl
)
11568 if (!TREE_USED (decl
))
11569 warning_at (DECL_SOURCE_LOCATION (decl
),
11570 OPT_Wunused_local_typedefs
,
11571 "typedef %qD locally defined but not used", decl
);
11572 unused_local_typedefs_warn_count
= errorcount
;
11575 vec_free (l
->local_typedefs
);
11578 /* The C and C++ parsers both use vectors to hold function arguments.
11579 For efficiency, we keep a cache of unused vectors. This is the
11582 typedef vec
<tree
, va_gc
> *tree_gc_vec
;
11583 static GTY((deletable
)) vec
<tree_gc_vec
, va_gc
> *tree_vector_cache
;
11585 /* Return a new vector from the cache. If the cache is empty,
11586 allocate a new vector. These vectors are GC'ed, so it is OK if the
11587 pointer is not released.. */
11590 make_tree_vector (void)
11592 if (tree_vector_cache
&& !tree_vector_cache
->is_empty ())
11593 return tree_vector_cache
->pop ();
11596 /* Passing 0 to vec::alloc returns NULL, and our callers require
11597 that we always return a non-NULL value. The vector code uses
11598 4 when growing a NULL vector, so we do too. */
11599 vec
<tree
, va_gc
> *v
;
11605 /* Release a vector of trees back to the cache. */
11608 release_tree_vector (vec
<tree
, va_gc
> *vec
)
11613 vec_safe_push (tree_vector_cache
, vec
);
11617 /* Get a new tree vector holding a single tree. */
11620 make_tree_vector_single (tree t
)
11622 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
11623 ret
->quick_push (t
);
11627 /* Get a new tree vector of the TREE_VALUEs of a TREE_LIST chain. */
11630 make_tree_vector_from_list (tree list
)
11632 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
11633 for (; list
; list
= TREE_CHAIN (list
))
11634 vec_safe_push (ret
, TREE_VALUE (list
));
11638 /* Get a new tree vector which is a copy of an existing one. */
11641 make_tree_vector_copy (const vec
<tree
, va_gc
> *orig
)
11643 vec
<tree
, va_gc
> *ret
;
11647 ret
= make_tree_vector ();
11648 vec_safe_reserve (ret
, vec_safe_length (orig
));
11649 FOR_EACH_VEC_SAFE_ELT (orig
, ix
, t
)
11650 ret
->quick_push (t
);
11654 /* Return true if KEYWORD starts a type specifier. */
11657 keyword_begins_type_specifier (enum rid keyword
)
11661 case RID_AUTO_TYPE
:
11674 case RID_DFLOAT128
:
11694 /* Return true if KEYWORD names a type qualifier. */
11697 keyword_is_type_qualifier (enum rid keyword
)
11711 /* Return true if KEYWORD names a storage class specifier.
11713 RID_TYPEDEF is not included in this list despite `typedef' being
11714 listed in C99 6.7.1.1. 6.7.1.3 indicates that `typedef' is listed as
11715 such for syntactic convenience only. */
11718 keyword_is_storage_class_specifier (enum rid keyword
)
11734 /* Return true if KEYWORD names a function-specifier [dcl.fct.spec]. */
11737 keyword_is_function_specifier (enum rid keyword
)
11751 /* Return true if KEYWORD names a decl-specifier [dcl.spec] or a
11752 declaration-specifier (C99 6.7). */
11755 keyword_is_decl_specifier (enum rid keyword
)
11757 if (keyword_is_storage_class_specifier (keyword
)
11758 || keyword_is_type_qualifier (keyword
)
11759 || keyword_is_function_specifier (keyword
))
11766 case RID_CONSTEXPR
:
11773 /* Initialize language-specific-bits of tree_contains_struct. */
11776 c_common_init_ts (void)
11778 MARK_TS_TYPED (C_MAYBE_CONST_EXPR
);
11779 MARK_TS_TYPED (EXCESS_PRECISION_EXPR
);
11780 MARK_TS_TYPED (ARRAY_NOTATION_REF
);
11781 MARK_TS_COMMON (UPC_FORALL_STMT
);
11782 MARK_TS_COMMON (UPC_SYNC_STMT
);
11785 /* Build a user-defined numeric literal out of an integer constant type VALUE
11786 with identifier SUFFIX. */
11789 build_userdef_literal (tree suffix_id
, tree value
,
11790 enum overflow_type overflow
, tree num_string
)
11792 tree literal
= make_node (USERDEF_LITERAL
);
11793 USERDEF_LITERAL_SUFFIX_ID (literal
) = suffix_id
;
11794 USERDEF_LITERAL_VALUE (literal
) = value
;
11795 USERDEF_LITERAL_OVERFLOW (literal
) = overflow
;
11796 USERDEF_LITERAL_NUM_STRING (literal
) = num_string
;
11800 /* For vector[index], convert the vector to a
11801 pointer of the underlying type. */
11803 convert_vector_to_pointer_for_subscript (location_t loc
,
11804 tree
* vecp
, tree index
)
11806 if (TREE_CODE (TREE_TYPE (*vecp
)) == VECTOR_TYPE
)
11808 tree type
= TREE_TYPE (*vecp
);
11811 if (TREE_CODE (index
) == INTEGER_CST
)
11812 if (!tree_fits_uhwi_p (index
)
11813 || tree_to_uhwi (index
) >= TYPE_VECTOR_SUBPARTS (type
))
11814 warning_at (loc
, OPT_Warray_bounds
, "index value is out of bound");
11816 c_common_mark_addressable_vec (*vecp
);
11817 type
= build_qualified_type (TREE_TYPE (type
), TYPE_QUALS (type
));
11818 type
= build_pointer_type (type
);
11819 type1
= build_pointer_type (TREE_TYPE (*vecp
));
11820 *vecp
= build1 (ADDR_EXPR
, type1
, *vecp
);
11821 *vecp
= convert (type
, *vecp
);
11825 /* Determine which of the operands, if any, is a scalar that needs to be
11826 converted to a vector, for the range of operations. */
11828 scalar_to_vector (location_t loc
, enum tree_code code
, tree op0
, tree op1
,
11831 tree type0
= TREE_TYPE (op0
);
11832 tree type1
= TREE_TYPE (op1
);
11833 bool integer_only_op
= false;
11834 enum stv_conv ret
= stv_firstarg
;
11836 gcc_assert (TREE_CODE (type0
) == VECTOR_TYPE
11837 || TREE_CODE (type1
) == VECTOR_TYPE
);
11840 /* Most GENERIC binary expressions require homogeneous arguments.
11841 LSHIFT_EXPR and RSHIFT_EXPR are exceptions and accept a first
11842 argument that is a vector and a second one that is a scalar, so
11843 we never return stv_secondarg for them. */
11846 if (TREE_CODE (type0
) == INTEGER_TYPE
11847 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
11849 if (unsafe_conversion_p (TREE_TYPE (type1
), op0
, false))
11852 error_at (loc
, "conversion of scalar %qT to vector %qT "
11853 "involves truncation", type0
, type1
);
11857 return stv_firstarg
;
11864 integer_only_op
= true;
11865 /* ... fall through ... */
11867 case VEC_COND_EXPR
:
11872 case TRUNC_DIV_EXPR
:
11873 case CEIL_DIV_EXPR
:
11874 case FLOOR_DIV_EXPR
:
11875 case ROUND_DIV_EXPR
:
11876 case EXACT_DIV_EXPR
:
11877 case TRUNC_MOD_EXPR
:
11878 case FLOOR_MOD_EXPR
:
11886 /* What about UNLT_EXPR? */
11887 if (TREE_CODE (type0
) == VECTOR_TYPE
)
11890 ret
= stv_secondarg
;
11891 /* Swap TYPE0 with TYPE1 and OP0 with OP1 */
11892 tmp
= type0
; type0
= type1
; type1
= tmp
;
11893 tmp
= op0
; op0
= op1
; op1
= tmp
;
11896 if (TREE_CODE (type0
) == INTEGER_TYPE
11897 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
11899 if (unsafe_conversion_p (TREE_TYPE (type1
), op0
, false))
11902 error_at (loc
, "conversion of scalar %qT to vector %qT "
11903 "involves truncation", type0
, type1
);
11908 else if (!integer_only_op
11909 /* Allow integer --> real conversion if safe. */
11910 && (TREE_CODE (type0
) == REAL_TYPE
11911 || TREE_CODE (type0
) == INTEGER_TYPE
)
11912 && SCALAR_FLOAT_TYPE_P (TREE_TYPE (type1
)))
11914 if (unsafe_conversion_p (TREE_TYPE (type1
), op0
, false))
11917 error_at (loc
, "conversion of scalar %qT to vector %qT "
11918 "involves truncation", type0
, type1
);
11927 return stv_nothing
;
11930 /* Return true iff ALIGN is an integral constant that is a fundamental
11931 alignment, as defined by [basic.align] in the c++-11
11936 [A fundamental alignment is represented by an alignment less than or
11937 equal to the greatest alignment supported by the implementation
11938 in all contexts, which is equal to
11939 alignof(max_align_t)]. */
11942 cxx_fundamental_alignment_p (unsigned align
)
11944 return (align
<= MAX (TYPE_ALIGN (long_long_integer_type_node
),
11945 TYPE_ALIGN (long_double_type_node
)));
11948 #include "gt-c-family-c-common.h"