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
195 /* C/ObjC language option variables. */
198 /* Nonzero means allow type mismatches in conditional expressions;
199 just make their values `void'. */
201 int flag_cond_mismatch
;
203 /* Nonzero means enable C89 Amendment 1 features. */
207 /* Nonzero means use the ISO C99 (or C11) dialect of C. */
211 /* Nonzero means use the ISO C11 dialect of C. */
215 /* Nonzero means that we have builtin functions, and main is an int. */
220 /* ObjC language option variables. */
223 /* Tells the compiler that this is a special run. Do not perform any
224 compiling, instead we are to test some platform dependent features
225 and output a C header file with appropriate definitions. */
227 int print_struct_values
;
229 /* Tells the compiler what is the constant string class for ObjC. */
231 const char *constant_string_class_name
;
234 /* C++ language option variables. */
237 /* Nonzero means generate separate instantiation control files and
238 juggle them at link time. */
240 int flag_use_repository
;
242 /* The C++ dialect being used. C++98 is the default. */
244 enum cxx_dialect cxx_dialect
= cxx98
;
246 /* Maximum template instantiation depth. This limit exists to limit the
247 time it takes to notice excessively recursive template instantiations.
249 The default is lower than the 1024 recommended by the C++0x standard
250 because G++ runs out of stack before 1024 with highly recursive template
251 argument deduction substitution (g++.dg/cpp0x/enum11.C). */
253 int max_tinst_depth
= 900;
255 /* The elements of `ridpointers' are identifier nodes for the reserved
256 type names and storage classes. It is indexed by a RID_... value. */
259 tree (*make_fname_decl
) (location_t
, tree
, int);
261 /* Nonzero means don't warn about problems that occur when the code is
263 int c_inhibit_evaluation_warnings
;
265 /* Whether we are building a boolean conversion inside
266 convert_for_assignment, or some other late binary operation. If
267 build_binary_op is called for C (from code shared by C and C++) in
268 this case, then the operands have already been folded and the
269 result will not be folded again, so C_MAYBE_CONST_EXPR should not
271 bool in_late_binary_op
;
273 /* Whether lexing has been completed, so subsequent preprocessor
274 errors should use the compiler's input_location. */
275 bool done_lexing
= false;
277 /* Information about how a function name is generated. */
280 tree
*const decl
; /* pointer to the VAR_DECL. */
281 const unsigned rid
; /* RID number for the identifier. */
282 const int pretty
; /* How pretty is it? */
285 /* The three ways of getting then name of the current function. */
287 const struct fname_var_t fname_vars
[] =
289 /* C99 compliant __func__, must be first. */
290 {&c99_function_name_decl_node
, RID_C99_FUNCTION_NAME
, 0},
291 /* GCC __FUNCTION__ compliant. */
292 {&function_name_decl_node
, RID_FUNCTION_NAME
, 0},
293 /* GCC __PRETTY_FUNCTION__ compliant. */
294 {&pretty_function_name_decl_node
, RID_PRETTY_FUNCTION_NAME
, 1},
298 /* Global visibility options. */
299 struct visibility_flags visibility_options
;
301 static tree
c_fully_fold_internal (tree expr
, bool, bool *, bool *);
302 static tree
check_case_value (tree
);
303 static bool check_case_bounds (tree
, tree
, tree
*, tree
*);
305 static tree
handle_packed_attribute (tree
*, tree
, tree
, int, bool *);
306 static tree
handle_nocommon_attribute (tree
*, tree
, tree
, int, bool *);
307 static tree
handle_common_attribute (tree
*, tree
, tree
, int, bool *);
308 static tree
handle_noreturn_attribute (tree
*, tree
, tree
, int, bool *);
309 static tree
handle_hot_attribute (tree
*, tree
, tree
, int, bool *);
310 static tree
handle_cold_attribute (tree
*, tree
, tree
, int, bool *);
311 static tree
handle_no_sanitize_address_attribute (tree
*, tree
, tree
,
313 static tree
handle_no_address_safety_analysis_attribute (tree
*, tree
, tree
,
315 static tree
handle_no_sanitize_undefined_attribute (tree
*, tree
, tree
, int,
317 static tree
handle_noinline_attribute (tree
*, tree
, tree
, int, bool *);
318 static tree
handle_noclone_attribute (tree
*, tree
, tree
, int, bool *);
319 static tree
handle_leaf_attribute (tree
*, tree
, tree
, int, bool *);
320 static tree
handle_always_inline_attribute (tree
*, tree
, tree
, int,
322 static tree
handle_gnu_inline_attribute (tree
*, tree
, tree
, int, bool *);
323 static tree
handle_artificial_attribute (tree
*, tree
, tree
, int, bool *);
324 static tree
handle_flatten_attribute (tree
*, tree
, tree
, int, bool *);
325 static tree
handle_error_attribute (tree
*, tree
, tree
, int, bool *);
326 static tree
handle_used_attribute (tree
*, tree
, tree
, int, bool *);
327 static tree
handle_unused_attribute (tree
*, tree
, tree
, int, bool *);
328 static tree
handle_externally_visible_attribute (tree
*, tree
, tree
, int,
330 static tree
handle_const_attribute (tree
*, tree
, tree
, int, bool *);
331 static tree
handle_transparent_union_attribute (tree
*, tree
, tree
,
333 static tree
handle_constructor_attribute (tree
*, tree
, tree
, int, bool *);
334 static tree
handle_destructor_attribute (tree
*, tree
, tree
, int, bool *);
335 static tree
handle_mode_attribute (tree
*, tree
, tree
, int, bool *);
336 static tree
handle_section_attribute (tree
*, tree
, tree
, int, bool *);
337 static tree
handle_aligned_attribute (tree
*, tree
, tree
, int, bool *);
338 static tree
handle_weak_attribute (tree
*, tree
, tree
, int, bool *) ;
339 static tree
handle_alias_ifunc_attribute (bool, tree
*, tree
, tree
, bool *);
340 static tree
handle_ifunc_attribute (tree
*, tree
, tree
, int, bool *);
341 static tree
handle_alias_attribute (tree
*, tree
, tree
, int, bool *);
342 static tree
handle_weakref_attribute (tree
*, tree
, tree
, int, bool *) ;
343 static tree
handle_visibility_attribute (tree
*, tree
, tree
, int,
345 static tree
handle_tls_model_attribute (tree
*, tree
, tree
, int,
347 static tree
handle_no_instrument_function_attribute (tree
*, tree
,
349 static tree
handle_malloc_attribute (tree
*, tree
, tree
, int, bool *);
350 static tree
handle_returns_twice_attribute (tree
*, tree
, tree
, int, bool *);
351 static tree
handle_no_limit_stack_attribute (tree
*, tree
, tree
, int,
353 static tree
handle_pure_attribute (tree
*, tree
, tree
, int, bool *);
354 static tree
handle_tm_attribute (tree
*, tree
, tree
, int, bool *);
355 static tree
handle_tm_wrap_attribute (tree
*, tree
, tree
, int, bool *);
356 static tree
handle_novops_attribute (tree
*, tree
, tree
, int, bool *);
357 static tree
handle_deprecated_attribute (tree
*, tree
, tree
, int,
359 static tree
handle_vector_size_attribute (tree
*, tree
, tree
, int,
361 static tree
handle_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
362 static tree
handle_nothrow_attribute (tree
*, tree
, tree
, int, bool *);
363 static tree
handle_cleanup_attribute (tree
*, tree
, tree
, int, bool *);
364 static tree
handle_warn_unused_result_attribute (tree
*, tree
, tree
, int,
366 static tree
handle_sentinel_attribute (tree
*, tree
, tree
, int, bool *);
367 static tree
handle_type_generic_attribute (tree
*, tree
, tree
, int, bool *);
368 static tree
handle_alloc_size_attribute (tree
*, tree
, tree
, int, bool *);
369 static tree
handle_target_attribute (tree
*, tree
, tree
, int, bool *);
370 static tree
handle_optimize_attribute (tree
*, tree
, tree
, int, bool *);
371 static tree
ignore_attribute (tree
*, tree
, tree
, int, bool *);
372 static tree
handle_no_split_stack_attribute (tree
*, tree
, tree
, int, bool *);
373 static tree
handle_fnspec_attribute (tree
*, tree
, tree
, int, bool *);
374 static tree
handle_warn_unused_attribute (tree
*, tree
, tree
, int, bool *);
375 static tree
handle_returns_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
376 static tree
handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int,
378 static tree
handle_omp_declare_target_attribute (tree
*, tree
, tree
, int,
381 static void check_function_nonnull (tree
, int, tree
*);
382 static void check_nonnull_arg (void *, tree
, unsigned HOST_WIDE_INT
);
383 static bool nonnull_check_p (tree
, unsigned HOST_WIDE_INT
);
384 static bool get_nonnull_operand (tree
, unsigned HOST_WIDE_INT
*);
385 static int resort_field_decl_cmp (const void *, const void *);
387 /* Reserved words. The third field is a mask: keywords are disabled
388 if they match the mask.
391 C --std=c89: D_C99 | D_CXXONLY | D_OBJC | D_CXX_OBJC
392 C --std=c99: D_CXXONLY | D_OBJC
393 ObjC is like C except that D_OBJC and D_CXX_OBJC are not set
394 C++ --std=c98: D_CONLY | D_CXXOX | D_OBJC
395 C++ --std=c0x: D_CONLY | D_OBJC
396 ObjC++ is like C++ except that D_OBJC is not set
398 If -fno-asm is used, D_ASM is added to the mask. If
399 -fno-gnu-keywords is used, D_EXT is added. If -fno-asm and C in
400 C89 mode, D_EXT89 is added for both -fno-asm and -fno-gnu-keywords.
401 In C with -Wc++-compat, we warn if D_CXXWARN is set.
403 Note the complication of the D_CXX_OBJC keywords. These are
404 reserved words such as 'class'. In C++, 'class' is a reserved
405 word. In Objective-C++ it is too. In Objective-C, it is a
406 reserved word too, but only if it follows an '@' sign.
408 const struct c_common_resword c_common_reswords
[] =
410 { "_Alignas", RID_ALIGNAS
, D_CONLY
},
411 { "_Alignof", RID_ALIGNOF
, D_CONLY
},
412 { "_Atomic", RID_ATOMIC
, D_CONLY
},
413 { "_Bool", RID_BOOL
, D_CONLY
},
414 { "_Complex", RID_COMPLEX
, 0 },
415 { "_Cilk_spawn", RID_CILK_SPAWN
, 0 },
416 { "_Cilk_sync", RID_CILK_SYNC
, 0 },
417 { "_Imaginary", RID_IMAGINARY
, D_CONLY
},
418 { "_Decimal32", RID_DFLOAT32
, D_CONLY
| D_EXT
},
419 { "_Decimal64", RID_DFLOAT64
, D_CONLY
| D_EXT
},
420 { "_Decimal128", RID_DFLOAT128
, D_CONLY
| D_EXT
},
421 { "_Fract", RID_FRACT
, D_CONLY
| D_EXT
},
422 { "_Accum", RID_ACCUM
, D_CONLY
| D_EXT
},
423 { "_Sat", RID_SAT
, D_CONLY
| D_EXT
},
424 { "_Static_assert", RID_STATIC_ASSERT
, D_CONLY
},
425 { "_Noreturn", RID_NORETURN
, D_CONLY
},
426 { "_Generic", RID_GENERIC
, D_CONLY
},
427 { "_Thread_local", RID_THREAD
, D_CONLY
},
428 { "__FUNCTION__", RID_FUNCTION_NAME
, 0 },
429 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME
, 0 },
430 { "__alignof", RID_ALIGNOF
, 0 },
431 { "__alignof__", RID_ALIGNOF
, 0 },
432 { "__asm", RID_ASM
, 0 },
433 { "__asm__", RID_ASM
, 0 },
434 { "__attribute", RID_ATTRIBUTE
, 0 },
435 { "__attribute__", RID_ATTRIBUTE
, 0 },
436 { "__auto_type", RID_AUTO_TYPE
, D_CONLY
},
437 { "__bases", RID_BASES
, D_CXXONLY
},
438 { "__builtin_choose_expr", RID_CHOOSE_EXPR
, D_CONLY
},
439 { "__builtin_complex", RID_BUILTIN_COMPLEX
, D_CONLY
},
440 { "__builtin_shuffle", RID_BUILTIN_SHUFFLE
, 0 },
441 { "__builtin_offsetof", RID_OFFSETOF
, 0 },
442 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P
, D_CONLY
},
443 { "__builtin_va_arg", RID_VA_ARG
, 0 },
444 { "__complex", RID_COMPLEX
, 0 },
445 { "__complex__", RID_COMPLEX
, 0 },
446 { "__const", RID_CONST
, 0 },
447 { "__const__", RID_CONST
, 0 },
448 { "__decltype", RID_DECLTYPE
, D_CXXONLY
},
449 { "__direct_bases", RID_DIRECT_BASES
, D_CXXONLY
},
450 { "__extension__", RID_EXTENSION
, 0 },
451 { "__func__", RID_C99_FUNCTION_NAME
, 0 },
452 { "__has_nothrow_assign", RID_HAS_NOTHROW_ASSIGN
, D_CXXONLY
},
453 { "__has_nothrow_constructor", RID_HAS_NOTHROW_CONSTRUCTOR
, D_CXXONLY
},
454 { "__has_nothrow_copy", RID_HAS_NOTHROW_COPY
, D_CXXONLY
},
455 { "__has_trivial_assign", RID_HAS_TRIVIAL_ASSIGN
, D_CXXONLY
},
456 { "__has_trivial_constructor", RID_HAS_TRIVIAL_CONSTRUCTOR
, D_CXXONLY
},
457 { "__has_trivial_copy", RID_HAS_TRIVIAL_COPY
, D_CXXONLY
},
458 { "__has_trivial_destructor", RID_HAS_TRIVIAL_DESTRUCTOR
, D_CXXONLY
},
459 { "__has_virtual_destructor", RID_HAS_VIRTUAL_DESTRUCTOR
, D_CXXONLY
},
460 { "__imag", RID_IMAGPART
, 0 },
461 { "__imag__", RID_IMAGPART
, 0 },
462 { "__inline", RID_INLINE
, 0 },
463 { "__inline__", RID_INLINE
, 0 },
464 { "__int128", RID_INT128
, 0 },
465 { "__is_abstract", RID_IS_ABSTRACT
, D_CXXONLY
},
466 { "__is_base_of", RID_IS_BASE_OF
, D_CXXONLY
},
467 { "__is_class", RID_IS_CLASS
, D_CXXONLY
},
468 { "__is_convertible_to", RID_IS_CONVERTIBLE_TO
, D_CXXONLY
},
469 { "__is_empty", RID_IS_EMPTY
, D_CXXONLY
},
470 { "__is_enum", RID_IS_ENUM
, D_CXXONLY
},
471 { "__is_final", RID_IS_FINAL
, D_CXXONLY
},
472 { "__is_literal_type", RID_IS_LITERAL_TYPE
, D_CXXONLY
},
473 { "__is_pod", RID_IS_POD
, D_CXXONLY
},
474 { "__is_polymorphic", RID_IS_POLYMORPHIC
, D_CXXONLY
},
475 { "__is_standard_layout", RID_IS_STD_LAYOUT
, D_CXXONLY
},
476 { "__is_trivial", RID_IS_TRIVIAL
, D_CXXONLY
},
477 { "__is_union", RID_IS_UNION
, D_CXXONLY
},
478 { "__label__", RID_LABEL
, 0 },
479 { "__null", RID_NULL
, 0 },
480 { "__real", RID_REALPART
, 0 },
481 { "__real__", RID_REALPART
, 0 },
482 { "__restrict", RID_RESTRICT
, 0 },
483 { "__restrict__", RID_RESTRICT
, 0 },
484 { "__signed", RID_SIGNED
, 0 },
485 { "__signed__", RID_SIGNED
, 0 },
486 { "__thread", RID_THREAD
, 0 },
487 { "__transaction_atomic", RID_TRANSACTION_ATOMIC
, 0 },
488 { "__transaction_relaxed", RID_TRANSACTION_RELAXED
, 0 },
489 { "__transaction_cancel", RID_TRANSACTION_CANCEL
, 0 },
490 { "__typeof", RID_TYPEOF
, 0 },
491 { "__typeof__", RID_TYPEOF
, 0 },
492 { "__underlying_type", RID_UNDERLYING_TYPE
, D_CXXONLY
},
493 { "__volatile", RID_VOLATILE
, 0 },
494 { "__volatile__", RID_VOLATILE
, 0 },
495 { "alignas", RID_ALIGNAS
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
496 { "alignof", RID_ALIGNOF
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
497 { "asm", RID_ASM
, D_ASM
},
498 { "auto", RID_AUTO
, 0 },
499 { "bool", RID_BOOL
, D_CXXONLY
| D_CXXWARN
},
500 { "break", RID_BREAK
, 0 },
501 { "case", RID_CASE
, 0 },
502 { "catch", RID_CATCH
, D_CXX_OBJC
| D_CXXWARN
},
503 { "char", RID_CHAR
, 0 },
504 { "char16_t", RID_CHAR16
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
505 { "char32_t", RID_CHAR32
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
506 { "class", RID_CLASS
, D_CXX_OBJC
| D_CXXWARN
},
507 { "const", RID_CONST
, 0 },
508 { "constexpr", RID_CONSTEXPR
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
509 { "const_cast", RID_CONSTCAST
, D_CXXONLY
| D_CXXWARN
},
510 { "continue", RID_CONTINUE
, 0 },
511 { "decltype", RID_DECLTYPE
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
512 { "default", RID_DEFAULT
, 0 },
513 { "delete", RID_DELETE
, D_CXXONLY
| D_CXXWARN
},
515 { "double", RID_DOUBLE
, 0 },
516 { "dynamic_cast", RID_DYNCAST
, D_CXXONLY
| D_CXXWARN
},
517 { "else", RID_ELSE
, 0 },
518 { "enum", RID_ENUM
, 0 },
519 { "explicit", RID_EXPLICIT
, D_CXXONLY
| D_CXXWARN
},
520 { "export", RID_EXPORT
, D_CXXONLY
| D_CXXWARN
},
521 { "extern", RID_EXTERN
, 0 },
522 { "false", RID_FALSE
, D_CXXONLY
| D_CXXWARN
},
523 { "float", RID_FLOAT
, 0 },
524 { "for", RID_FOR
, 0 },
525 { "friend", RID_FRIEND
, D_CXXONLY
| D_CXXWARN
},
526 { "goto", RID_GOTO
, 0 },
528 { "inline", RID_INLINE
, D_EXT89
},
529 { "int", RID_INT
, 0 },
530 { "long", RID_LONG
, 0 },
531 { "mutable", RID_MUTABLE
, D_CXXONLY
| D_CXXWARN
},
532 { "namespace", RID_NAMESPACE
, D_CXXONLY
| D_CXXWARN
},
533 { "new", RID_NEW
, D_CXXONLY
| D_CXXWARN
},
534 { "noexcept", RID_NOEXCEPT
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
535 { "nullptr", RID_NULLPTR
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
536 { "operator", RID_OPERATOR
, D_CXXONLY
| D_CXXWARN
},
537 { "private", RID_PRIVATE
, D_CXX_OBJC
| D_CXXWARN
},
538 { "protected", RID_PROTECTED
, D_CXX_OBJC
| D_CXXWARN
},
539 { "public", RID_PUBLIC
, D_CXX_OBJC
| D_CXXWARN
},
540 { "register", RID_REGISTER
, 0 },
541 { "reinterpret_cast", RID_REINTCAST
, D_CXXONLY
| D_CXXWARN
},
542 { "restrict", RID_RESTRICT
, D_CONLY
| D_C99
},
543 { "return", RID_RETURN
, 0 },
544 { "short", RID_SHORT
, 0 },
545 { "signed", RID_SIGNED
, 0 },
546 { "sizeof", RID_SIZEOF
, 0 },
547 { "static", RID_STATIC
, 0 },
548 { "static_assert", RID_STATIC_ASSERT
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
549 { "static_cast", RID_STATCAST
, D_CXXONLY
| D_CXXWARN
},
550 { "struct", RID_STRUCT
, 0 },
551 { "switch", RID_SWITCH
, 0 },
552 { "template", RID_TEMPLATE
, D_CXXONLY
| D_CXXWARN
},
553 { "this", RID_THIS
, D_CXXONLY
| D_CXXWARN
},
554 { "thread_local", RID_THREAD
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
555 { "throw", RID_THROW
, D_CXX_OBJC
| D_CXXWARN
},
556 { "true", RID_TRUE
, D_CXXONLY
| D_CXXWARN
},
557 { "try", RID_TRY
, D_CXX_OBJC
| D_CXXWARN
},
558 { "typedef", RID_TYPEDEF
, 0 },
559 { "typename", RID_TYPENAME
, D_CXXONLY
| D_CXXWARN
},
560 { "typeid", RID_TYPEID
, D_CXXONLY
| D_CXXWARN
},
561 { "typeof", RID_TYPEOF
, D_ASM
| D_EXT
},
562 { "union", RID_UNION
, 0 },
563 { "unsigned", RID_UNSIGNED
, 0 },
564 { "using", RID_USING
, D_CXXONLY
| D_CXXWARN
},
565 { "virtual", RID_VIRTUAL
, D_CXXONLY
| D_CXXWARN
},
566 { "void", RID_VOID
, 0 },
567 { "volatile", RID_VOLATILE
, 0 },
568 { "wchar_t", RID_WCHAR
, D_CXXONLY
},
569 { "while", RID_WHILE
, 0 },
570 /* These Objective-C keywords are recognized only immediately after
572 { "compatibility_alias", RID_AT_ALIAS
, D_OBJC
},
573 { "defs", RID_AT_DEFS
, D_OBJC
},
574 { "encode", RID_AT_ENCODE
, D_OBJC
},
575 { "end", RID_AT_END
, D_OBJC
},
576 { "implementation", RID_AT_IMPLEMENTATION
, D_OBJC
},
577 { "interface", RID_AT_INTERFACE
, D_OBJC
},
578 { "protocol", RID_AT_PROTOCOL
, D_OBJC
},
579 { "selector", RID_AT_SELECTOR
, D_OBJC
},
580 { "finally", RID_AT_FINALLY
, D_OBJC
},
581 { "synchronized", RID_AT_SYNCHRONIZED
, D_OBJC
},
582 { "optional", RID_AT_OPTIONAL
, D_OBJC
},
583 { "required", RID_AT_REQUIRED
, D_OBJC
},
584 { "property", RID_AT_PROPERTY
, D_OBJC
},
585 { "package", RID_AT_PACKAGE
, D_OBJC
},
586 { "synthesize", RID_AT_SYNTHESIZE
, D_OBJC
},
587 { "dynamic", RID_AT_DYNAMIC
, D_OBJC
},
588 /* These are recognized only in protocol-qualifier context
590 { "bycopy", RID_BYCOPY
, D_OBJC
},
591 { "byref", RID_BYREF
, D_OBJC
},
592 { "in", RID_IN
, D_OBJC
},
593 { "inout", RID_INOUT
, D_OBJC
},
594 { "oneway", RID_ONEWAY
, D_OBJC
},
595 { "out", RID_OUT
, D_OBJC
},
596 /* These are recognized inside a property attribute list */
597 { "assign", RID_ASSIGN
, D_OBJC
},
598 { "copy", RID_COPY
, D_OBJC
},
599 { "getter", RID_GETTER
, D_OBJC
},
600 { "nonatomic", RID_NONATOMIC
, D_OBJC
},
601 { "readonly", RID_READONLY
, D_OBJC
},
602 { "readwrite", RID_READWRITE
, D_OBJC
},
603 { "retain", RID_RETAIN
, D_OBJC
},
604 { "setter", RID_SETTER
, D_OBJC
},
607 const unsigned int num_c_common_reswords
=
608 sizeof c_common_reswords
/ sizeof (struct c_common_resword
);
610 /* Table of machine-independent attributes common to all C-like languages. */
611 const struct attribute_spec c_common_attribute_table
[] =
613 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
614 affects_type_identity } */
615 { "packed", 0, 0, false, false, false,
616 handle_packed_attribute
, false},
617 { "nocommon", 0, 0, true, false, false,
618 handle_nocommon_attribute
, false},
619 { "common", 0, 0, true, false, false,
620 handle_common_attribute
, false },
621 /* FIXME: logically, noreturn attributes should be listed as
622 "false, true, true" and apply to function types. But implementing this
623 would require all the places in the compiler that use TREE_THIS_VOLATILE
624 on a decl to identify non-returning functions to be located and fixed
625 to check the function type instead. */
626 { "noreturn", 0, 0, true, false, false,
627 handle_noreturn_attribute
, false },
628 { "volatile", 0, 0, true, false, false,
629 handle_noreturn_attribute
, false },
630 { "noinline", 0, 0, true, false, false,
631 handle_noinline_attribute
, false },
632 { "noclone", 0, 0, true, false, false,
633 handle_noclone_attribute
, false },
634 { "leaf", 0, 0, true, false, false,
635 handle_leaf_attribute
, false },
636 { "always_inline", 0, 0, true, false, false,
637 handle_always_inline_attribute
, false },
638 { "gnu_inline", 0, 0, true, false, false,
639 handle_gnu_inline_attribute
, false },
640 { "artificial", 0, 0, true, false, false,
641 handle_artificial_attribute
, false },
642 { "flatten", 0, 0, true, false, false,
643 handle_flatten_attribute
, false },
644 { "used", 0, 0, true, false, false,
645 handle_used_attribute
, false },
646 { "unused", 0, 0, false, false, false,
647 handle_unused_attribute
, false },
648 { "externally_visible", 0, 0, true, false, false,
649 handle_externally_visible_attribute
, false },
650 /* The same comments as for noreturn attributes apply to const ones. */
651 { "const", 0, 0, true, false, false,
652 handle_const_attribute
, false },
653 { "transparent_union", 0, 0, false, false, false,
654 handle_transparent_union_attribute
, false },
655 { "constructor", 0, 1, true, false, false,
656 handle_constructor_attribute
, false },
657 { "destructor", 0, 1, true, false, false,
658 handle_destructor_attribute
, false },
659 { "mode", 1, 1, false, true, false,
660 handle_mode_attribute
, false },
661 { "section", 1, 1, true, false, false,
662 handle_section_attribute
, false },
663 { "aligned", 0, 1, false, false, false,
664 handle_aligned_attribute
, false },
665 { "weak", 0, 0, true, false, false,
666 handle_weak_attribute
, false },
667 { "ifunc", 1, 1, true, false, false,
668 handle_ifunc_attribute
, false },
669 { "alias", 1, 1, true, false, false,
670 handle_alias_attribute
, false },
671 { "weakref", 0, 1, true, false, false,
672 handle_weakref_attribute
, false },
673 { "no_instrument_function", 0, 0, true, false, false,
674 handle_no_instrument_function_attribute
,
676 { "malloc", 0, 0, true, false, false,
677 handle_malloc_attribute
, false },
678 { "returns_twice", 0, 0, true, false, false,
679 handle_returns_twice_attribute
, false },
680 { "no_stack_limit", 0, 0, true, false, false,
681 handle_no_limit_stack_attribute
, false },
682 { "pure", 0, 0, true, false, false,
683 handle_pure_attribute
, false },
684 { "transaction_callable", 0, 0, false, true, false,
685 handle_tm_attribute
, false },
686 { "transaction_unsafe", 0, 0, false, true, false,
687 handle_tm_attribute
, false },
688 { "transaction_safe", 0, 0, false, true, false,
689 handle_tm_attribute
, false },
690 { "transaction_may_cancel_outer", 0, 0, false, true, false,
691 handle_tm_attribute
, false },
692 /* ??? These two attributes didn't make the transition from the
693 Intel language document to the multi-vendor language document. */
694 { "transaction_pure", 0, 0, false, true, false,
695 handle_tm_attribute
, false },
696 { "transaction_wrap", 1, 1, true, false, false,
697 handle_tm_wrap_attribute
, false },
698 /* For internal use (marking of builtins) only. The name contains space
699 to prevent its usage in source code. */
700 { "no vops", 0, 0, true, false, false,
701 handle_novops_attribute
, false },
702 { "deprecated", 0, 1, false, false, false,
703 handle_deprecated_attribute
, false },
704 { "vector_size", 1, 1, false, true, false,
705 handle_vector_size_attribute
, false },
706 { "visibility", 1, 1, false, false, false,
707 handle_visibility_attribute
, false },
708 { "tls_model", 1, 1, true, false, false,
709 handle_tls_model_attribute
, false },
710 { "nonnull", 0, -1, false, true, true,
711 handle_nonnull_attribute
, false },
712 { "nothrow", 0, 0, true, false, false,
713 handle_nothrow_attribute
, false },
714 { "may_alias", 0, 0, false, true, false, NULL
, false },
715 { "cleanup", 1, 1, true, false, false,
716 handle_cleanup_attribute
, false },
717 { "warn_unused_result", 0, 0, false, true, true,
718 handle_warn_unused_result_attribute
, false },
719 { "sentinel", 0, 1, false, true, true,
720 handle_sentinel_attribute
, false },
721 /* For internal use (marking of builtins) only. The name contains space
722 to prevent its usage in source code. */
723 { "type generic", 0, 0, false, true, true,
724 handle_type_generic_attribute
, false },
725 { "alloc_size", 1, 2, false, true, true,
726 handle_alloc_size_attribute
, false },
727 { "cold", 0, 0, true, false, false,
728 handle_cold_attribute
, false },
729 { "hot", 0, 0, true, false, false,
730 handle_hot_attribute
, false },
731 { "no_address_safety_analysis",
732 0, 0, true, false, false,
733 handle_no_address_safety_analysis_attribute
,
735 { "no_sanitize_address", 0, 0, true, false, false,
736 handle_no_sanitize_address_attribute
,
738 { "no_sanitize_undefined", 0, 0, true, false, false,
739 handle_no_sanitize_undefined_attribute
,
741 { "warning", 1, 1, true, false, false,
742 handle_error_attribute
, false },
743 { "error", 1, 1, true, false, false,
744 handle_error_attribute
, false },
745 { "target", 1, -1, true, false, false,
746 handle_target_attribute
, false },
747 { "optimize", 1, -1, true, false, false,
748 handle_optimize_attribute
, false },
749 /* For internal use only. The leading '*' both prevents its usage in
750 source code and signals that it may be overridden by machine tables. */
751 { "*tm regparm", 0, 0, false, true, true,
752 ignore_attribute
, false },
753 { "no_split_stack", 0, 0, true, false, false,
754 handle_no_split_stack_attribute
, false },
755 /* For internal use (marking of builtins and runtime functions) only.
756 The name contains space to prevent its usage in source code. */
757 { "fn spec", 1, 1, false, true, true,
758 handle_fnspec_attribute
, false },
759 { "warn_unused", 0, 0, false, false, false,
760 handle_warn_unused_attribute
, false },
761 { "returns_nonnull", 0, 0, false, true, true,
762 handle_returns_nonnull_attribute
, false },
763 { "omp declare simd", 0, -1, true, false, false,
764 handle_omp_declare_simd_attribute
, false },
765 { "omp declare target", 0, 0, true, false, false,
766 handle_omp_declare_target_attribute
, false },
767 { NULL
, 0, 0, false, false, false, NULL
, false }
770 /* Give the specifications for the format attributes, used by C and all
773 const struct attribute_spec c_common_format_attribute_table
[] =
775 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
776 affects_type_identity } */
777 { "format", 3, 3, false, true, true,
778 handle_format_attribute
, false },
779 { "format_arg", 1, 1, false, true, true,
780 handle_format_arg_attribute
, false },
781 { NULL
, 0, 0, false, false, false, NULL
, false }
784 /* Return identifier for address space AS. */
787 c_addr_space_name (addr_space_t as
)
789 int rid
= RID_FIRST_ADDR_SPACE
+ as
;
790 gcc_assert (ridpointers
[rid
]);
791 return IDENTIFIER_POINTER (ridpointers
[rid
]);
794 /* Push current bindings for the function name VAR_DECLS. */
797 start_fname_decls (void)
800 tree saved
= NULL_TREE
;
802 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
804 tree decl
= *fname_vars
[ix
].decl
;
808 saved
= tree_cons (decl
, build_int_cst (integer_type_node
, ix
),
810 *fname_vars
[ix
].decl
= NULL_TREE
;
813 if (saved
|| saved_function_name_decls
)
814 /* Normally they'll have been NULL, so only push if we've got a
815 stack, or they are non-NULL. */
816 saved_function_name_decls
= tree_cons (saved
, NULL_TREE
,
817 saved_function_name_decls
);
820 /* Finish up the current bindings, adding them into the current function's
821 statement tree. This must be done _before_ finish_stmt_tree is called.
822 If there is no current function, we must be at file scope and no statements
823 are involved. Pop the previous bindings. */
826 finish_fname_decls (void)
829 tree stmts
= NULL_TREE
;
830 tree stack
= saved_function_name_decls
;
832 for (; stack
&& TREE_VALUE (stack
); stack
= TREE_CHAIN (stack
))
833 append_to_statement_list (TREE_VALUE (stack
), &stmts
);
837 tree
*bodyp
= &DECL_SAVED_TREE (current_function_decl
);
839 if (TREE_CODE (*bodyp
) == BIND_EXPR
)
840 bodyp
= &BIND_EXPR_BODY (*bodyp
);
842 append_to_statement_list_force (*bodyp
, &stmts
);
846 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
847 *fname_vars
[ix
].decl
= NULL_TREE
;
851 /* We had saved values, restore them. */
854 for (saved
= TREE_PURPOSE (stack
); saved
; saved
= TREE_CHAIN (saved
))
856 tree decl
= TREE_PURPOSE (saved
);
857 unsigned ix
= TREE_INT_CST_LOW (TREE_VALUE (saved
));
859 *fname_vars
[ix
].decl
= decl
;
861 stack
= TREE_CHAIN (stack
);
863 saved_function_name_decls
= stack
;
866 /* Return the text name of the current function, suitably prettified
867 by PRETTY_P. Return string must be freed by caller. */
870 fname_as_string (int pretty_p
)
872 const char *name
= "top level";
875 cpp_string cstr
= { 0, 0 }, strname
;
883 if (current_function_decl
)
884 name
= lang_hooks
.decl_printable_name (current_function_decl
, vrb
);
886 len
= strlen (name
) + 3; /* Two for '"'s. One for NULL. */
888 namep
= XNEWVEC (char, len
);
889 snprintf (namep
, len
, "\"%s\"", name
);
890 strname
.text
= (unsigned char *) namep
;
891 strname
.len
= len
- 1;
893 if (cpp_interpret_string (parse_in
, &strname
, 1, &cstr
, CPP_STRING
))
896 return (const char *) cstr
.text
;
902 /* Return the VAR_DECL for a const char array naming the current
903 function. If the VAR_DECL has not yet been created, create it
904 now. RID indicates how it should be formatted and IDENTIFIER_NODE
905 ID is its name (unfortunately C and C++ hold the RID values of
906 keywords in different places, so we can't derive RID from ID in
907 this language independent code. LOC is the location of the
911 fname_decl (location_t loc
, unsigned int rid
, tree id
)
914 tree decl
= NULL_TREE
;
916 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
917 if (fname_vars
[ix
].rid
== rid
)
920 decl
= *fname_vars
[ix
].decl
;
923 /* If a tree is built here, it would normally have the lineno of
924 the current statement. Later this tree will be moved to the
925 beginning of the function and this line number will be wrong.
926 To avoid this problem set the lineno to 0 here; that prevents
927 it from appearing in the RTL. */
929 location_t saved_location
= input_location
;
930 input_location
= UNKNOWN_LOCATION
;
932 stmts
= push_stmt_list ();
933 decl
= (*make_fname_decl
) (loc
, id
, fname_vars
[ix
].pretty
);
934 stmts
= pop_stmt_list (stmts
);
935 if (!IS_EMPTY_STMT (stmts
))
936 saved_function_name_decls
937 = tree_cons (decl
, stmts
, saved_function_name_decls
);
938 *fname_vars
[ix
].decl
= decl
;
939 input_location
= saved_location
;
941 if (!ix
&& !current_function_decl
)
942 pedwarn (loc
, 0, "%qD is not defined outside of function scope", decl
);
947 /* Given a STRING_CST, give it a suitable array-of-chars data type. */
950 fix_string_type (tree value
)
952 int length
= TREE_STRING_LENGTH (value
);
954 tree e_type
, i_type
, a_type
;
956 /* Compute the number of elements, for the array type. */
957 if (TREE_TYPE (value
) == char_array_type_node
|| !TREE_TYPE (value
))
960 e_type
= char_type_node
;
962 else if (TREE_TYPE (value
) == char16_array_type_node
)
964 nchars
= length
/ (TYPE_PRECISION (char16_type_node
) / BITS_PER_UNIT
);
965 e_type
= char16_type_node
;
967 else if (TREE_TYPE (value
) == char32_array_type_node
)
969 nchars
= length
/ (TYPE_PRECISION (char32_type_node
) / BITS_PER_UNIT
);
970 e_type
= char32_type_node
;
974 nchars
= length
/ (TYPE_PRECISION (wchar_type_node
) / BITS_PER_UNIT
);
975 e_type
= wchar_type_node
;
978 /* C89 2.2.4.1, C99 5.2.4.1 (Translation limits). The analogous
979 limit in C++98 Annex B is very large (65536) and is not normative,
980 so we do not diagnose it (warn_overlength_strings is forced off
981 in c_common_post_options). */
982 if (warn_overlength_strings
)
984 const int nchars_max
= flag_isoc99
? 4095 : 509;
985 const int relevant_std
= flag_isoc99
? 99 : 90;
986 if (nchars
- 1 > nchars_max
)
987 /* Translators: The %d after 'ISO C' will be 90 or 99. Do not
988 separate the %d from the 'C'. 'ISO' should not be
989 translated, but it may be moved after 'C%d' in languages
990 where modifiers follow nouns. */
991 pedwarn (input_location
, OPT_Woverlength_strings
,
992 "string length %qd is greater than the length %qd "
993 "ISO C%d compilers are required to support",
994 nchars
- 1, nchars_max
, relevant_std
);
997 /* Create the array type for the string constant. The ISO C++
998 standard says that a string literal has type `const char[N]' or
999 `const wchar_t[N]'. We use the same logic when invoked as a C
1000 front-end with -Wwrite-strings.
1001 ??? We should change the type of an expression depending on the
1002 state of a warning flag. We should just be warning -- see how
1003 this is handled in the C++ front-end for the deprecated implicit
1004 conversion from string literals to `char*' or `wchar_t*'.
1006 The C++ front end relies on TYPE_MAIN_VARIANT of a cv-qualified
1007 array type being the unqualified version of that type.
1008 Therefore, if we are constructing an array of const char, we must
1009 construct the matching unqualified array type first. The C front
1010 end does not require this, but it does no harm, so we do it
1012 i_type
= build_index_type (size_int (nchars
- 1));
1013 a_type
= build_array_type (e_type
, i_type
);
1014 if (c_dialect_cxx() || warn_write_strings
)
1015 a_type
= c_build_qualified_type (a_type
, TYPE_QUAL_CONST
);
1017 TREE_TYPE (value
) = a_type
;
1018 TREE_CONSTANT (value
) = 1;
1019 TREE_READONLY (value
) = 1;
1020 TREE_STATIC (value
) = 1;
1024 /* If DISABLE is true, stop issuing warnings. This is used when
1025 parsing code that we know will not be executed. This function may
1026 be called multiple times, and works as a stack. */
1029 c_disable_warnings (bool disable
)
1033 ++c_inhibit_evaluation_warnings
;
1034 fold_defer_overflow_warnings ();
1038 /* If ENABLE is true, reenable issuing warnings. */
1041 c_enable_warnings (bool enable
)
1045 --c_inhibit_evaluation_warnings
;
1046 fold_undefer_and_ignore_overflow_warnings ();
1050 /* Fully fold EXPR, an expression that was not folded (beyond integer
1051 constant expressions and null pointer constants) when being built
1052 up. If IN_INIT, this is in a static initializer and certain
1053 changes are made to the folding done. Clear *MAYBE_CONST if
1054 MAYBE_CONST is not NULL and EXPR is definitely not a constant
1055 expression because it contains an evaluated operator (in C99) or an
1056 operator outside of sizeof returning an integer constant (in C90)
1057 not permitted in constant expressions, or because it contains an
1058 evaluated arithmetic overflow. (*MAYBE_CONST should typically be
1059 set to true by callers before calling this function.) Return the
1060 folded expression. Function arguments have already been folded
1061 before calling this function, as have the contents of SAVE_EXPR,
1062 TARGET_EXPR, BIND_EXPR, VA_ARG_EXPR, OBJ_TYPE_REF and
1063 C_MAYBE_CONST_EXPR. */
1066 c_fully_fold (tree expr
, bool in_init
, bool *maybe_const
)
1069 tree eptype
= NULL_TREE
;
1071 bool maybe_const_itself
= true;
1072 location_t loc
= EXPR_LOCATION (expr
);
1074 /* This function is not relevant to C++ because C++ folds while
1075 parsing, and may need changes to be correct for C++ when C++
1076 stops folding while parsing. */
1077 if (c_dialect_cxx ())
1081 maybe_const
= &dummy
;
1082 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
1084 eptype
= TREE_TYPE (expr
);
1085 expr
= TREE_OPERAND (expr
, 0);
1087 ret
= c_fully_fold_internal (expr
, in_init
, maybe_const
,
1088 &maybe_const_itself
);
1090 ret
= fold_convert_loc (loc
, eptype
, ret
);
1091 *maybe_const
&= maybe_const_itself
;
1095 /* Internal helper for c_fully_fold. EXPR and IN_INIT are as for
1096 c_fully_fold. *MAYBE_CONST_OPERANDS is cleared because of operands
1097 not permitted, while *MAYBE_CONST_ITSELF is cleared because of
1098 arithmetic overflow (for C90, *MAYBE_CONST_OPERANDS is carried from
1099 both evaluated and unevaluated subexpressions while
1100 *MAYBE_CONST_ITSELF is carried from only evaluated
1104 c_fully_fold_internal (tree expr
, bool in_init
, bool *maybe_const_operands
,
1105 bool *maybe_const_itself
)
1108 enum tree_code code
= TREE_CODE (expr
);
1109 enum tree_code_class kind
= TREE_CODE_CLASS (code
);
1110 location_t loc
= EXPR_LOCATION (expr
);
1111 tree op0
, op1
, op2
, op3
;
1112 tree orig_op0
, orig_op1
, orig_op2
;
1113 bool op0_const
= true, op1_const
= true, op2_const
= true;
1114 bool op0_const_self
= true, op1_const_self
= true, op2_const_self
= true;
1115 bool nowarning
= TREE_NO_WARNING (expr
);
1118 /* This function is not relevant to C++ because C++ folds while
1119 parsing, and may need changes to be correct for C++ when C++
1120 stops folding while parsing. */
1121 if (c_dialect_cxx ())
1124 /* Constants, declarations, statements, errors, SAVE_EXPRs and
1125 anything else not counted as an expression cannot usefully be
1126 folded further at this point. */
1127 if (!IS_EXPR_CODE_CLASS (kind
)
1128 || kind
== tcc_statement
1129 || code
== SAVE_EXPR
)
1132 /* Operands of variable-length expressions (function calls) have
1133 already been folded, as have __builtin_* function calls, and such
1134 expressions cannot occur in constant expressions. */
1135 if (kind
== tcc_vl_exp
)
1137 *maybe_const_operands
= false;
1142 if (code
== C_MAYBE_CONST_EXPR
)
1144 tree pre
= C_MAYBE_CONST_EXPR_PRE (expr
);
1145 tree inner
= C_MAYBE_CONST_EXPR_EXPR (expr
);
1146 if (C_MAYBE_CONST_EXPR_NON_CONST (expr
))
1147 *maybe_const_operands
= false;
1148 if (C_MAYBE_CONST_EXPR_INT_OPERANDS (expr
))
1149 *maybe_const_itself
= false;
1150 if (pre
&& !in_init
)
1151 ret
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr
), pre
, inner
);
1157 /* Assignment, increment, decrement, function call and comma
1158 operators, and statement expressions, cannot occur in constant
1159 expressions if evaluated / outside of sizeof. (Function calls
1160 were handled above, though VA_ARG_EXPR is treated like a function
1161 call here, and statement expressions are handled through
1162 C_MAYBE_CONST_EXPR to avoid folding inside them.) */
1166 case PREDECREMENT_EXPR
:
1167 case PREINCREMENT_EXPR
:
1168 case POSTDECREMENT_EXPR
:
1169 case POSTINCREMENT_EXPR
:
1171 *maybe_const_operands
= false;
1178 *maybe_const_operands
= false;
1186 /* Fold individual tree codes as appropriate. */
1189 case COMPOUND_LITERAL_EXPR
:
1190 /* Any non-constancy will have been marked in a containing
1191 C_MAYBE_CONST_EXPR; there is no more folding to do here. */
1195 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1196 op1
= TREE_OPERAND (expr
, 1);
1197 op2
= TREE_OPERAND (expr
, 2);
1198 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1199 maybe_const_itself
);
1200 STRIP_TYPE_NOPS (op0
);
1201 if (op0
!= orig_op0
)
1202 ret
= build3 (COMPONENT_REF
, TREE_TYPE (expr
), op0
, op1
, op2
);
1205 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1206 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1211 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1212 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1213 op2
= TREE_OPERAND (expr
, 2);
1214 op3
= TREE_OPERAND (expr
, 3);
1215 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1216 maybe_const_itself
);
1217 STRIP_TYPE_NOPS (op0
);
1218 op1
= c_fully_fold_internal (op1
, in_init
, maybe_const_operands
,
1219 maybe_const_itself
);
1220 STRIP_TYPE_NOPS (op1
);
1221 op1
= decl_constant_value_for_optimization (op1
);
1222 if (op0
!= orig_op0
|| op1
!= orig_op1
)
1223 ret
= build4 (ARRAY_REF
, TREE_TYPE (expr
), op0
, op1
, op2
, op3
);
1226 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1227 TREE_SIDE_EFFECTS (ret
) = TREE_SIDE_EFFECTS (expr
);
1228 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1235 case PREDECREMENT_EXPR
:
1236 case PREINCREMENT_EXPR
:
1237 case POSTDECREMENT_EXPR
:
1238 case POSTINCREMENT_EXPR
:
1242 case POINTER_PLUS_EXPR
:
1243 case TRUNC_DIV_EXPR
:
1245 case FLOOR_DIV_EXPR
:
1246 case TRUNC_MOD_EXPR
:
1248 case EXACT_DIV_EXPR
:
1261 case TRUTH_AND_EXPR
:
1263 case TRUTH_XOR_EXPR
:
1264 case UNORDERED_EXPR
:
1271 /* Binary operations evaluating both arguments (increment and
1272 decrement are binary internally in GCC). */
1273 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1274 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1275 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1276 maybe_const_itself
);
1277 STRIP_TYPE_NOPS (op0
);
1278 if (code
!= MODIFY_EXPR
1279 && code
!= PREDECREMENT_EXPR
1280 && code
!= PREINCREMENT_EXPR
1281 && code
!= POSTDECREMENT_EXPR
1282 && code
!= POSTINCREMENT_EXPR
)
1283 op0
= decl_constant_value_for_optimization (op0
);
1284 /* The RHS of a MODIFY_EXPR was fully folded when building that
1285 expression for the sake of conversion warnings. */
1286 if (code
!= MODIFY_EXPR
)
1287 op1
= c_fully_fold_internal (op1
, in_init
, maybe_const_operands
,
1288 maybe_const_itself
);
1289 STRIP_TYPE_NOPS (op1
);
1290 op1
= decl_constant_value_for_optimization (op1
);
1291 if (op0
!= orig_op0
|| op1
!= orig_op1
|| in_init
)
1293 ? fold_build2_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
)
1294 : fold_build2_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
);
1297 if (TREE_OVERFLOW_P (ret
)
1298 && !TREE_OVERFLOW_P (op0
)
1299 && !TREE_OVERFLOW_P (op1
))
1300 overflow_warning (EXPR_LOCATION (expr
), ret
);
1301 if ((code
== LSHIFT_EXPR
|| code
== RSHIFT_EXPR
)
1302 && TREE_CODE (orig_op1
) != INTEGER_CST
1303 && TREE_CODE (op1
) == INTEGER_CST
1304 && (TREE_CODE (TREE_TYPE (orig_op0
)) == INTEGER_TYPE
1305 || TREE_CODE (TREE_TYPE (orig_op0
)) == FIXED_POINT_TYPE
)
1306 && TREE_CODE (TREE_TYPE (orig_op1
)) == INTEGER_TYPE
1307 && c_inhibit_evaluation_warnings
== 0)
1309 if (tree_int_cst_sgn (op1
) < 0)
1310 warning_at (loc
, 0, (code
== LSHIFT_EXPR
1311 ? G_("left shift count is negative")
1312 : G_("right shift count is negative")));
1313 else if (compare_tree_int (op1
,
1314 TYPE_PRECISION (TREE_TYPE (orig_op0
)))
1316 warning_at (loc
, 0, (code
== LSHIFT_EXPR
1317 ? G_("left shift count >= width of type")
1318 : G_("right shift count >= width of type")));
1323 case FIX_TRUNC_EXPR
:
1326 case ADDR_SPACE_CONVERT_EXPR
:
1327 case VIEW_CONVERT_EXPR
:
1328 case NON_LVALUE_EXPR
:
1331 case TRUTH_NOT_EXPR
:
1336 /* Unary operations. */
1337 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1338 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1339 maybe_const_itself
);
1340 STRIP_TYPE_NOPS (op0
);
1341 if (code
!= ADDR_EXPR
&& code
!= REALPART_EXPR
&& code
!= IMAGPART_EXPR
)
1342 op0
= decl_constant_value_for_optimization (op0
);
1343 /* ??? Cope with user tricks that amount to offsetof. The middle-end is
1344 not prepared to deal with them if they occur in initializers. */
1346 && code
== ADDR_EXPR
1347 && (op1
= get_base_address (op0
)) != NULL_TREE
1348 && TREE_CODE (op1
) == INDIRECT_REF
1349 && TREE_CONSTANT (TREE_OPERAND (op1
, 0)))
1350 ret
= fold_convert_loc (loc
, TREE_TYPE (expr
), fold_offsetof_1 (op0
));
1351 else if (op0
!= orig_op0
|| in_init
)
1353 ? fold_build1_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
)
1354 : fold_build1_loc (loc
, code
, TREE_TYPE (expr
), op0
);
1357 if (code
== INDIRECT_REF
1359 && TREE_CODE (ret
) == INDIRECT_REF
)
1361 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1362 TREE_SIDE_EFFECTS (ret
) = TREE_SIDE_EFFECTS (expr
);
1363 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1367 case FIX_TRUNC_EXPR
:
1370 /* Don't warn about explicit conversions. We will already
1371 have warned about suspect implicit conversions. */
1375 if (TREE_OVERFLOW_P (ret
) && !TREE_OVERFLOW_P (op0
))
1376 overflow_warning (EXPR_LOCATION (expr
), ret
);
1381 case TRUTH_ANDIF_EXPR
:
1382 case TRUTH_ORIF_EXPR
:
1383 /* Binary operations not necessarily evaluating both
1385 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1386 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1387 op0
= c_fully_fold_internal (op0
, in_init
, &op0_const
, &op0_const_self
);
1388 STRIP_TYPE_NOPS (op0
);
1390 unused_p
= (op0
== (code
== TRUTH_ANDIF_EXPR
1391 ? truthvalue_false_node
1392 : truthvalue_true_node
));
1393 c_disable_warnings (unused_p
);
1394 op1
= c_fully_fold_internal (op1
, in_init
, &op1_const
, &op1_const_self
);
1395 STRIP_TYPE_NOPS (op1
);
1396 c_enable_warnings (unused_p
);
1398 if (op0
!= orig_op0
|| op1
!= orig_op1
|| in_init
)
1400 ? fold_build2_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
)
1401 : fold_build2_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
);
1404 *maybe_const_operands
&= op0_const
;
1405 *maybe_const_itself
&= op0_const_self
;
1409 && (code
== TRUTH_ANDIF_EXPR
1410 ? op0
== truthvalue_false_node
1411 : op0
== truthvalue_true_node
)))
1412 *maybe_const_operands
&= op1_const
;
1415 && (code
== TRUTH_ANDIF_EXPR
1416 ? op0
== truthvalue_false_node
1417 : op0
== truthvalue_true_node
)))
1418 *maybe_const_itself
&= op1_const_self
;
1422 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1423 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1424 orig_op2
= op2
= TREE_OPERAND (expr
, 2);
1425 op0
= c_fully_fold_internal (op0
, in_init
, &op0_const
, &op0_const_self
);
1427 STRIP_TYPE_NOPS (op0
);
1428 c_disable_warnings (op0
== truthvalue_false_node
);
1429 op1
= c_fully_fold_internal (op1
, in_init
, &op1_const
, &op1_const_self
);
1430 STRIP_TYPE_NOPS (op1
);
1431 c_enable_warnings (op0
== truthvalue_false_node
);
1433 c_disable_warnings (op0
== truthvalue_true_node
);
1434 op2
= c_fully_fold_internal (op2
, in_init
, &op2_const
, &op2_const_self
);
1435 STRIP_TYPE_NOPS (op2
);
1436 c_enable_warnings (op0
== truthvalue_true_node
);
1438 if (op0
!= orig_op0
|| op1
!= orig_op1
|| op2
!= orig_op2
)
1439 ret
= fold_build3_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
, op2
);
1442 *maybe_const_operands
&= op0_const
;
1443 *maybe_const_itself
&= op0_const_self
;
1447 && op0
== truthvalue_false_node
))
1448 *maybe_const_operands
&= op1_const
;
1451 && op0
== truthvalue_false_node
))
1452 *maybe_const_itself
&= op1_const_self
;
1456 && op0
== truthvalue_true_node
))
1457 *maybe_const_operands
&= op2_const
;
1460 && op0
== truthvalue_true_node
))
1461 *maybe_const_itself
&= op2_const_self
;
1464 case EXCESS_PRECISION_EXPR
:
1465 /* Each case where an operand with excess precision may be
1466 encountered must remove the EXCESS_PRECISION_EXPR around
1467 inner operands and possibly put one around the whole
1468 expression or possibly convert to the semantic type (which
1469 c_fully_fold does); we cannot tell at this stage which is
1470 appropriate in any particular case. */
1474 /* Various codes may appear through folding built-in functions
1475 and their arguments. */
1480 /* Some folding may introduce NON_LVALUE_EXPRs; all lvalue checks
1481 have been done by this point, so remove them again. */
1482 nowarning
|= TREE_NO_WARNING (ret
);
1483 STRIP_TYPE_NOPS (ret
);
1484 if (nowarning
&& !TREE_NO_WARNING (ret
))
1486 if (!CAN_HAVE_LOCATION_P (ret
))
1487 ret
= build1 (NOP_EXPR
, TREE_TYPE (ret
), ret
);
1488 TREE_NO_WARNING (ret
) = 1;
1491 protected_set_expr_location (ret
, loc
);
1495 /* If not optimizing, EXP is not a VAR_DECL, or EXP has array type,
1496 return EXP. Otherwise, return either EXP or its known constant
1497 value (if it has one), but return EXP if EXP has mode BLKmode. ???
1498 Is the BLKmode test appropriate? */
1501 decl_constant_value_for_optimization (tree exp
)
1505 /* This function is only used by C, for c_fully_fold and other
1506 optimization, and may not be correct for C++. */
1507 if (c_dialect_cxx ())
1511 || TREE_CODE (exp
) != VAR_DECL
1512 || TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
1513 || DECL_MODE (exp
) == BLKmode
)
1516 ret
= decl_constant_value (exp
);
1517 /* Avoid unwanted tree sharing between the initializer and current
1518 function's body where the tree can be modified e.g. by the
1520 if (ret
!= exp
&& TREE_STATIC (exp
))
1521 ret
= unshare_expr (ret
);
1525 /* Print a warning if a constant expression had overflow in folding.
1526 Invoke this function on every expression that the language
1527 requires to be a constant expression.
1528 Note the ANSI C standard says it is erroneous for a
1529 constant expression to overflow. */
1532 constant_expression_warning (tree value
)
1534 if (warn_overflow
&& pedantic
1535 && (TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1536 || TREE_CODE (value
) == FIXED_CST
1537 || TREE_CODE (value
) == VECTOR_CST
1538 || TREE_CODE (value
) == COMPLEX_CST
)
1539 && TREE_OVERFLOW (value
))
1540 pedwarn (input_location
, OPT_Woverflow
, "overflow in constant expression");
1543 /* The same as above but print an unconditional error. */
1545 constant_expression_error (tree value
)
1547 if ((TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1548 || TREE_CODE (value
) == FIXED_CST
1549 || TREE_CODE (value
) == VECTOR_CST
1550 || TREE_CODE (value
) == COMPLEX_CST
)
1551 && TREE_OVERFLOW (value
))
1552 error ("overflow in constant expression");
1555 /* Print a warning if an expression had overflow in folding and its
1558 Invoke this function on every expression that
1559 (1) appears in the source code, and
1560 (2) is a constant expression that overflowed, and
1561 (3) is not already checked by convert_and_check;
1562 however, do not invoke this function on operands of explicit casts
1563 or when the expression is the result of an operator and any operand
1564 already overflowed. */
1567 overflow_warning (location_t loc
, tree value
)
1569 if (c_inhibit_evaluation_warnings
!= 0)
1572 switch (TREE_CODE (value
))
1575 warning_at (loc
, OPT_Woverflow
, "integer overflow in expression");
1579 warning_at (loc
, OPT_Woverflow
,
1580 "floating point overflow in expression");
1584 warning_at (loc
, OPT_Woverflow
, "fixed-point overflow in expression");
1588 warning_at (loc
, OPT_Woverflow
, "vector overflow in expression");
1592 if (TREE_CODE (TREE_REALPART (value
)) == INTEGER_CST
)
1593 warning_at (loc
, OPT_Woverflow
,
1594 "complex integer overflow in expression");
1595 else if (TREE_CODE (TREE_REALPART (value
)) == REAL_CST
)
1596 warning_at (loc
, OPT_Woverflow
,
1597 "complex floating point overflow in expression");
1605 /* Warn about uses of logical || / && operator in a context where it
1606 is likely that the bitwise equivalent was intended by the
1607 programmer. We have seen an expression in which CODE is a binary
1608 operator used to combine expressions OP_LEFT and OP_RIGHT, which before folding
1609 had CODE_LEFT and CODE_RIGHT, into an expression of type TYPE. */
1611 warn_logical_operator (location_t location
, enum tree_code code
, tree type
,
1612 enum tree_code code_left
, tree op_left
,
1613 enum tree_code
ARG_UNUSED (code_right
), tree op_right
)
1615 int or_op
= (code
== TRUTH_ORIF_EXPR
|| code
== TRUTH_OR_EXPR
);
1616 int in0_p
, in1_p
, in_p
;
1617 tree low0
, low1
, low
, high0
, high1
, high
, lhs
, rhs
, tem
;
1618 bool strict_overflow_p
= false;
1620 if (code
!= TRUTH_ANDIF_EXPR
1621 && code
!= TRUTH_AND_EXPR
1622 && code
!= TRUTH_ORIF_EXPR
1623 && code
!= TRUTH_OR_EXPR
)
1626 /* Warn if &&/|| are being used in a context where it is
1627 likely that the bitwise equivalent was intended by the
1628 programmer. That is, an expression such as op && MASK
1629 where op should not be any boolean expression, nor a
1630 constant, and mask seems to be a non-boolean integer constant. */
1631 if (!truth_value_p (code_left
)
1632 && INTEGRAL_TYPE_P (TREE_TYPE (op_left
))
1633 && !CONSTANT_CLASS_P (op_left
)
1634 && !TREE_NO_WARNING (op_left
)
1635 && TREE_CODE (op_right
) == INTEGER_CST
1636 && !integer_zerop (op_right
)
1637 && !integer_onep (op_right
))
1640 warning_at (location
, OPT_Wlogical_op
, "logical %<or%>"
1641 " applied to non-boolean constant");
1643 warning_at (location
, OPT_Wlogical_op
, "logical %<and%>"
1644 " applied to non-boolean constant");
1645 TREE_NO_WARNING (op_left
) = true;
1649 /* We do not warn for constants because they are typical of macro
1650 expansions that test for features. */
1651 if (CONSTANT_CLASS_P (op_left
) || CONSTANT_CLASS_P (op_right
))
1654 /* This warning only makes sense with logical operands. */
1655 if (!(truth_value_p (TREE_CODE (op_left
))
1656 || INTEGRAL_TYPE_P (TREE_TYPE (op_left
)))
1657 || !(truth_value_p (TREE_CODE (op_right
))
1658 || INTEGRAL_TYPE_P (TREE_TYPE (op_right
))))
1662 /* We first test whether either side separately is trivially true
1663 (with OR) or trivially false (with AND). If so, do not warn.
1664 This is a common idiom for testing ranges of data types in
1666 lhs
= make_range (op_left
, &in0_p
, &low0
, &high0
, &strict_overflow_p
);
1669 if (TREE_CODE (lhs
) == C_MAYBE_CONST_EXPR
)
1670 lhs
= C_MAYBE_CONST_EXPR_EXPR (lhs
);
1672 /* If this is an OR operation, invert both sides; now, the result
1673 should be always false to get a warning. */
1677 tem
= build_range_check (UNKNOWN_LOCATION
, type
, lhs
, in0_p
, low0
, high0
);
1678 if (tem
&& integer_zerop (tem
))
1681 rhs
= make_range (op_right
, &in1_p
, &low1
, &high1
, &strict_overflow_p
);
1684 if (TREE_CODE (rhs
) == C_MAYBE_CONST_EXPR
)
1685 rhs
= C_MAYBE_CONST_EXPR_EXPR (rhs
);
1687 /* If this is an OR operation, invert both sides; now, the result
1688 should be always false to get a warning. */
1692 tem
= build_range_check (UNKNOWN_LOCATION
, type
, rhs
, in1_p
, low1
, high1
);
1693 if (tem
&& integer_zerop (tem
))
1696 /* If both expressions have the same operand, if we can merge the
1697 ranges, and if the range test is always false, then warn. */
1698 if (operand_equal_p (lhs
, rhs
, 0)
1699 && merge_ranges (&in_p
, &low
, &high
, in0_p
, low0
, high0
,
1701 && 0 != (tem
= build_range_check (UNKNOWN_LOCATION
,
1702 type
, lhs
, in_p
, low
, high
))
1703 && integer_zerop (tem
))
1706 warning_at (location
, OPT_Wlogical_op
,
1708 "of collectively exhaustive tests is always true");
1710 warning_at (location
, OPT_Wlogical_op
,
1712 "of mutually exclusive tests is always false");
1717 /* Warn if EXP contains any computations whose results are not used.
1718 Return true if a warning is printed; false otherwise. LOCUS is the
1719 (potential) location of the expression. */
1722 warn_if_unused_value (const_tree exp
, location_t locus
)
1725 if (TREE_USED (exp
) || TREE_NO_WARNING (exp
))
1728 /* Don't warn about void constructs. This includes casting to void,
1729 void function calls, and statement expressions with a final cast
1731 if (VOID_TYPE_P (TREE_TYPE (exp
)))
1734 if (EXPR_HAS_LOCATION (exp
))
1735 locus
= EXPR_LOCATION (exp
);
1737 switch (TREE_CODE (exp
))
1739 case PREINCREMENT_EXPR
:
1740 case POSTINCREMENT_EXPR
:
1741 case PREDECREMENT_EXPR
:
1742 case POSTDECREMENT_EXPR
:
1747 case TRY_CATCH_EXPR
:
1748 case WITH_CLEANUP_EXPR
:
1754 /* For a binding, warn if no side effect within it. */
1755 exp
= BIND_EXPR_BODY (exp
);
1759 case NON_LVALUE_EXPR
:
1761 exp
= TREE_OPERAND (exp
, 0);
1764 case TRUTH_ORIF_EXPR
:
1765 case TRUTH_ANDIF_EXPR
:
1766 /* In && or ||, warn if 2nd operand has no side effect. */
1767 exp
= TREE_OPERAND (exp
, 1);
1771 if (warn_if_unused_value (TREE_OPERAND (exp
, 0), locus
))
1773 /* Let people do `(foo (), 0)' without a warning. */
1774 if (TREE_CONSTANT (TREE_OPERAND (exp
, 1)))
1776 exp
= TREE_OPERAND (exp
, 1);
1780 /* If this is an expression with side effects, don't warn; this
1781 case commonly appears in macro expansions. */
1782 if (TREE_SIDE_EFFECTS (exp
))
1787 /* Don't warn about automatic dereferencing of references, since
1788 the user cannot control it. */
1789 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == REFERENCE_TYPE
)
1791 exp
= TREE_OPERAND (exp
, 0);
1797 /* Referencing a volatile value is a side effect, so don't warn. */
1798 if ((DECL_P (exp
) || REFERENCE_CLASS_P (exp
))
1799 && TREE_THIS_VOLATILE (exp
))
1802 /* If this is an expression which has no operands, there is no value
1803 to be unused. There are no such language-independent codes,
1804 but front ends may define such. */
1805 if (EXPRESSION_CLASS_P (exp
) && TREE_OPERAND_LENGTH (exp
) == 0)
1809 return warning_at (locus
, OPT_Wunused_value
, "value computed is not used");
1814 /* Print a warning about casts that might indicate violation
1815 of strict aliasing rules if -Wstrict-aliasing is used and
1816 strict aliasing mode is in effect. OTYPE is the original
1817 TREE_TYPE of EXPR, and TYPE the type we're casting to. */
1820 strict_aliasing_warning (tree otype
, tree type
, tree expr
)
1822 /* Strip pointer conversion chains and get to the correct original type. */
1824 otype
= TREE_TYPE (expr
);
1826 if (!(flag_strict_aliasing
1827 && POINTER_TYPE_P (type
)
1828 && POINTER_TYPE_P (otype
)
1829 && !VOID_TYPE_P (TREE_TYPE (type
)))
1830 /* If the type we are casting to is a ref-all pointer
1831 dereferencing it is always valid. */
1832 || TYPE_REF_CAN_ALIAS_ALL (type
))
1835 if ((warn_strict_aliasing
> 1) && TREE_CODE (expr
) == ADDR_EXPR
1836 && (DECL_P (TREE_OPERAND (expr
, 0))
1837 || handled_component_p (TREE_OPERAND (expr
, 0))))
1839 /* Casting the address of an object to non void pointer. Warn
1840 if the cast breaks type based aliasing. */
1841 if (!COMPLETE_TYPE_P (TREE_TYPE (type
)) && warn_strict_aliasing
== 2)
1843 warning (OPT_Wstrict_aliasing
, "type-punning to incomplete type "
1844 "might break strict-aliasing rules");
1849 /* warn_strict_aliasing >= 3. This includes the default (3).
1850 Only warn if the cast is dereferenced immediately. */
1851 alias_set_type set1
=
1852 get_alias_set (TREE_TYPE (TREE_OPERAND (expr
, 0)));
1853 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
1855 if (set1
!= set2
&& set2
!= 0
1856 && (set1
== 0 || !alias_sets_conflict_p (set1
, set2
)))
1858 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1859 "pointer will break strict-aliasing rules");
1862 else if (warn_strict_aliasing
== 2
1863 && !alias_sets_must_conflict_p (set1
, set2
))
1865 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1866 "pointer might break strict-aliasing rules");
1872 if ((warn_strict_aliasing
== 1) && !VOID_TYPE_P (TREE_TYPE (otype
)))
1874 /* At this level, warn for any conversions, even if an address is
1875 not taken in the same statement. This will likely produce many
1876 false positives, but could be useful to pinpoint problems that
1877 are not revealed at higher levels. */
1878 alias_set_type set1
= get_alias_set (TREE_TYPE (otype
));
1879 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
1880 if (!COMPLETE_TYPE_P (type
)
1881 || !alias_sets_must_conflict_p (set1
, set2
))
1883 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1884 "pointer might break strict-aliasing rules");
1892 /* Warn about memset (&a, 0, sizeof (&a)); and similar mistakes with
1893 sizeof as last operand of certain builtins. */
1896 sizeof_pointer_memaccess_warning (location_t
*sizeof_arg_loc
, tree callee
,
1897 vec
<tree
, va_gc
> *params
, tree
*sizeof_arg
,
1898 bool (*comp_types
) (tree
, tree
))
1900 tree type
, dest
= NULL_TREE
, src
= NULL_TREE
, tem
;
1901 bool strop
= false, cmp
= false;
1902 unsigned int idx
= ~0;
1905 if (TREE_CODE (callee
) != FUNCTION_DECL
1906 || DECL_BUILT_IN_CLASS (callee
) != BUILT_IN_NORMAL
1907 || vec_safe_length (params
) <= 1)
1910 switch (DECL_FUNCTION_CODE (callee
))
1912 case BUILT_IN_STRNCMP
:
1913 case BUILT_IN_STRNCASECMP
:
1916 case BUILT_IN_STRNCPY
:
1917 case BUILT_IN_STRNCPY_CHK
:
1918 case BUILT_IN_STRNCAT
:
1919 case BUILT_IN_STRNCAT_CHK
:
1920 case BUILT_IN_STPNCPY
:
1921 case BUILT_IN_STPNCPY_CHK
:
1924 case BUILT_IN_MEMCPY
:
1925 case BUILT_IN_MEMCPY_CHK
:
1926 case BUILT_IN_MEMMOVE
:
1927 case BUILT_IN_MEMMOVE_CHK
:
1928 if (params
->length () < 3)
1931 dest
= (*params
)[0];
1934 case BUILT_IN_BCOPY
:
1935 if (params
->length () < 3)
1938 dest
= (*params
)[1];
1941 case BUILT_IN_MEMCMP
:
1943 if (params
->length () < 3)
1946 dest
= (*params
)[0];
1950 case BUILT_IN_MEMSET
:
1951 case BUILT_IN_MEMSET_CHK
:
1952 if (params
->length () < 3)
1954 dest
= (*params
)[0];
1957 case BUILT_IN_BZERO
:
1958 dest
= (*params
)[0];
1961 case BUILT_IN_STRNDUP
:
1966 case BUILT_IN_MEMCHR
:
1967 if (params
->length () < 3)
1972 case BUILT_IN_SNPRINTF
:
1973 case BUILT_IN_SNPRINTF_CHK
:
1974 case BUILT_IN_VSNPRINTF
:
1975 case BUILT_IN_VSNPRINTF_CHK
:
1976 dest
= (*params
)[0];
1987 if (sizeof_arg
[idx
] == NULL
|| sizeof_arg
[idx
] == error_mark_node
)
1990 type
= TYPE_P (sizeof_arg
[idx
])
1991 ? sizeof_arg
[idx
] : TREE_TYPE (sizeof_arg
[idx
]);
1992 if (!POINTER_TYPE_P (type
))
1996 && (tem
= tree_strip_nop_conversions (dest
))
1997 && POINTER_TYPE_P (TREE_TYPE (tem
))
1998 && comp_types (TREE_TYPE (TREE_TYPE (tem
)), type
))
2002 && (tem
= tree_strip_nop_conversions (src
))
2003 && POINTER_TYPE_P (TREE_TYPE (tem
))
2004 && comp_types (TREE_TYPE (TREE_TYPE (tem
)), type
))
2007 loc
= sizeof_arg_loc
[idx
];
2011 if (!TYPE_P (sizeof_arg
[idx
])
2012 && operand_equal_p (dest
, sizeof_arg
[idx
], 0)
2013 && comp_types (TREE_TYPE (dest
), type
))
2015 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2016 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2017 "argument to %<sizeof%> in %qD call is the same "
2018 "expression as the destination; did you mean to "
2019 "remove the addressof?", callee
);
2020 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2021 == TYPE_PRECISION (char_type_node
))
2023 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2024 "argument to %<sizeof%> in %qD call is the same "
2025 "expression as the destination; did you mean to "
2026 "provide an explicit length?", callee
);
2028 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2029 "argument to %<sizeof%> in %qD call is the same "
2030 "expression as the destination; did you mean to "
2031 "dereference it?", callee
);
2035 if (POINTER_TYPE_P (TREE_TYPE (dest
))
2037 && comp_types (TREE_TYPE (dest
), type
)
2038 && !VOID_TYPE_P (TREE_TYPE (type
)))
2040 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2041 "argument to %<sizeof%> in %qD call is the same "
2042 "pointer type %qT as the destination; expected %qT "
2043 "or an explicit length", callee
, TREE_TYPE (dest
),
2044 TREE_TYPE (TREE_TYPE (dest
)));
2051 if (!TYPE_P (sizeof_arg
[idx
])
2052 && operand_equal_p (src
, sizeof_arg
[idx
], 0)
2053 && comp_types (TREE_TYPE (src
), type
))
2055 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2056 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2057 "argument to %<sizeof%> in %qD call is the same "
2058 "expression as the source; did you mean to "
2059 "remove the addressof?", callee
);
2060 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2061 == TYPE_PRECISION (char_type_node
))
2063 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2064 "argument to %<sizeof%> in %qD call is the same "
2065 "expression as the source; did you mean to "
2066 "provide an explicit length?", callee
);
2068 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2069 "argument to %<sizeof%> in %qD call is the same "
2070 "expression as the source; did you mean to "
2071 "dereference it?", callee
);
2075 if (POINTER_TYPE_P (TREE_TYPE (src
))
2077 && comp_types (TREE_TYPE (src
), type
)
2078 && !VOID_TYPE_P (TREE_TYPE (type
)))
2080 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2081 "argument to %<sizeof%> in %qD call is the same "
2082 "pointer type %qT as the source; expected %qT "
2083 "or an explicit length", callee
, TREE_TYPE (src
),
2084 TREE_TYPE (TREE_TYPE (src
)));
2091 if (!TYPE_P (sizeof_arg
[idx
])
2092 && operand_equal_p (dest
, sizeof_arg
[idx
], 0)
2093 && comp_types (TREE_TYPE (dest
), type
))
2095 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2096 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2097 "argument to %<sizeof%> in %qD call is the same "
2098 "expression as the first source; did you mean to "
2099 "remove the addressof?", callee
);
2100 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2101 == TYPE_PRECISION (char_type_node
))
2103 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2104 "argument to %<sizeof%> in %qD call is the same "
2105 "expression as the first source; did you mean to "
2106 "provide an explicit length?", callee
);
2108 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2109 "argument to %<sizeof%> in %qD call is the same "
2110 "expression as the first source; did you mean to "
2111 "dereference it?", callee
);
2115 if (POINTER_TYPE_P (TREE_TYPE (dest
))
2117 && comp_types (TREE_TYPE (dest
), type
)
2118 && !VOID_TYPE_P (TREE_TYPE (type
)))
2120 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2121 "argument to %<sizeof%> in %qD call is the same "
2122 "pointer type %qT as the first source; expected %qT "
2123 "or an explicit length", callee
, TREE_TYPE (dest
),
2124 TREE_TYPE (TREE_TYPE (dest
)));
2131 if (!TYPE_P (sizeof_arg
[idx
])
2132 && operand_equal_p (src
, sizeof_arg
[idx
], 0)
2133 && comp_types (TREE_TYPE (src
), type
))
2135 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2136 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2137 "argument to %<sizeof%> in %qD call is the same "
2138 "expression as the second source; did you mean to "
2139 "remove the addressof?", callee
);
2140 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2141 == TYPE_PRECISION (char_type_node
))
2143 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2144 "argument to %<sizeof%> in %qD call is the same "
2145 "expression as the second source; did you mean to "
2146 "provide an explicit length?", callee
);
2148 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2149 "argument to %<sizeof%> in %qD call is the same "
2150 "expression as the second source; did you mean to "
2151 "dereference it?", callee
);
2155 if (POINTER_TYPE_P (TREE_TYPE (src
))
2157 && comp_types (TREE_TYPE (src
), type
)
2158 && !VOID_TYPE_P (TREE_TYPE (type
)))
2160 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2161 "argument to %<sizeof%> in %qD call is the same "
2162 "pointer type %qT as the second source; expected %qT "
2163 "or an explicit length", callee
, TREE_TYPE (src
),
2164 TREE_TYPE (TREE_TYPE (src
)));
2171 /* Warn for unlikely, improbable, or stupid DECL declarations
2175 check_main_parameter_types (tree decl
)
2177 function_args_iterator iter
;
2181 FOREACH_FUNCTION_ARGS (TREE_TYPE (decl
), type
, iter
)
2183 /* XXX void_type_node belies the abstraction. */
2184 if (type
== void_type_node
|| type
== error_mark_node
)
2191 if (TYPE_MAIN_VARIANT (type
) != integer_type_node
)
2192 pedwarn (input_location
, OPT_Wmain
,
2193 "first argument of %q+D should be %<int%>", decl
);
2197 if (TREE_CODE (type
) != POINTER_TYPE
2198 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
2199 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
2201 pedwarn (input_location
, OPT_Wmain
,
2202 "second argument of %q+D should be %<char **%>", decl
);
2206 if (TREE_CODE (type
) != POINTER_TYPE
2207 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
2208 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
2210 pedwarn (input_location
, OPT_Wmain
,
2211 "third argument of %q+D should probably be "
2212 "%<char **%>", decl
);
2217 /* It is intentional that this message does not mention the third
2218 argument because it's only mentioned in an appendix of the
2220 if (argct
> 0 && (argct
< 2 || argct
> 3))
2221 pedwarn (input_location
, OPT_Wmain
,
2222 "%q+D takes only zero or two arguments", decl
);
2225 /* vector_targets_convertible_p is used for vector pointer types. The
2226 callers perform various checks that the qualifiers are satisfactory,
2227 while OTOH vector_targets_convertible_p ignores the number of elements
2228 in the vectors. That's fine with vector pointers as we can consider,
2229 say, a vector of 8 elements as two consecutive vectors of 4 elements,
2230 and that does not require and conversion of the pointer values.
2231 In contrast, vector_types_convertible_p and
2232 vector_types_compatible_elements_p are used for vector value types. */
2233 /* True if pointers to distinct types T1 and T2 can be converted to
2234 each other without an explicit cast. Only returns true for opaque
2237 vector_targets_convertible_p (const_tree t1
, const_tree t2
)
2239 if (TREE_CODE (t1
) == VECTOR_TYPE
&& TREE_CODE (t2
) == VECTOR_TYPE
2240 && (TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2241 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2247 /* vector_types_convertible_p is used for vector value types.
2248 It could in principle call vector_targets_convertible_p as a subroutine,
2249 but then the check for vector type would be duplicated with its callers,
2250 and also the purpose of vector_targets_convertible_p would become
2252 Where vector_types_convertible_p returns true, a conversion might still be
2253 needed to make the types match.
2254 In contrast, vector_targets_convertible_p is used for vector pointer
2255 values, and vector_types_compatible_elements_p is used specifically
2256 in the context for binary operators, as a check if use is possible without
2258 /* True if vector types T1 and T2 can be converted to each other
2259 without an explicit cast. If EMIT_LAX_NOTE is true, and T1 and T2
2260 can only be converted with -flax-vector-conversions yet that is not
2261 in effect, emit a note telling the user about that option if such
2262 a note has not previously been emitted. */
2264 vector_types_convertible_p (const_tree t1
, const_tree t2
, bool emit_lax_note
)
2266 static bool emitted_lax_note
= false;
2267 bool convertible_lax
;
2269 if ((TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2270 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2274 (tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
))
2275 && (TREE_CODE (TREE_TYPE (t1
)) != REAL_TYPE
||
2276 TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
))
2277 && (INTEGRAL_TYPE_P (TREE_TYPE (t1
))
2278 == INTEGRAL_TYPE_P (TREE_TYPE (t2
))));
2280 if (!convertible_lax
|| flag_lax_vector_conversions
)
2281 return convertible_lax
;
2283 if (TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
)
2284 && lang_hooks
.types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
2287 if (emit_lax_note
&& !emitted_lax_note
)
2289 emitted_lax_note
= true;
2290 inform (input_location
, "use -flax-vector-conversions to permit "
2291 "conversions between vectors with differing "
2292 "element types or numbers of subparts");
2298 /* Build a VEC_PERM_EXPR if V0, V1 and MASK are not error_mark_nodes
2299 and have vector types, V0 has the same type as V1, and the number of
2300 elements of V0, V1, MASK is the same.
2302 In case V1 is a NULL_TREE it is assumed that __builtin_shuffle was
2303 called with two arguments. In this case implementation passes the
2304 first argument twice in order to share the same tree code. This fact
2305 could enable the mask-values being twice the vector length. This is
2306 an implementation accident and this semantics is not guaranteed to
2309 c_build_vec_perm_expr (location_t loc
, tree v0
, tree v1
, tree mask
,
2314 bool maybe_const
= false;
2315 bool two_arguments
= false;
2317 if (v1
== NULL_TREE
)
2319 two_arguments
= true;
2323 if (v0
== error_mark_node
|| v1
== error_mark_node
2324 || mask
== error_mark_node
)
2325 return error_mark_node
;
2327 if (TREE_CODE (TREE_TYPE (mask
)) != VECTOR_TYPE
2328 || TREE_CODE (TREE_TYPE (TREE_TYPE (mask
))) != INTEGER_TYPE
)
2331 error_at (loc
, "__builtin_shuffle last argument must "
2332 "be an integer vector");
2333 return error_mark_node
;
2336 if (TREE_CODE (TREE_TYPE (v0
)) != VECTOR_TYPE
2337 || TREE_CODE (TREE_TYPE (v1
)) != VECTOR_TYPE
)
2340 error_at (loc
, "__builtin_shuffle arguments must be vectors");
2341 return error_mark_node
;
2344 if (TYPE_MAIN_VARIANT (TREE_TYPE (v0
)) != TYPE_MAIN_VARIANT (TREE_TYPE (v1
)))
2347 error_at (loc
, "__builtin_shuffle argument vectors must be of "
2349 return error_mark_node
;
2352 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (v0
))
2353 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
))
2354 && TYPE_VECTOR_SUBPARTS (TREE_TYPE (v1
))
2355 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
)))
2358 error_at (loc
, "__builtin_shuffle number of elements of the "
2359 "argument vector(s) and the mask vector should "
2361 return error_mark_node
;
2364 if (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (v0
))))
2365 != GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (mask
)))))
2368 error_at (loc
, "__builtin_shuffle argument vector(s) inner type "
2369 "must have the same size as inner type of the mask");
2370 return error_mark_node
;
2373 if (!c_dialect_cxx ())
2375 /* Avoid C_MAYBE_CONST_EXPRs inside VEC_PERM_EXPR. */
2376 v0
= c_fully_fold (v0
, false, &maybe_const
);
2377 wrap
&= maybe_const
;
2380 v1
= v0
= save_expr (v0
);
2383 v1
= c_fully_fold (v1
, false, &maybe_const
);
2384 wrap
&= maybe_const
;
2387 mask
= c_fully_fold (mask
, false, &maybe_const
);
2388 wrap
&= maybe_const
;
2390 else if (two_arguments
)
2391 v1
= v0
= save_expr (v0
);
2393 ret
= build3_loc (loc
, VEC_PERM_EXPR
, TREE_TYPE (v0
), v0
, v1
, mask
);
2395 if (!c_dialect_cxx () && !wrap
)
2396 ret
= c_wrap_maybe_const (ret
, true);
2401 /* Like tree.c:get_narrower, but retain conversion from C++0x scoped enum
2402 to integral type. */
2405 c_common_get_narrower (tree op
, int *unsignedp_ptr
)
2407 op
= get_narrower (op
, unsignedp_ptr
);
2409 if (TREE_CODE (TREE_TYPE (op
)) == ENUMERAL_TYPE
2410 && ENUM_IS_SCOPED (TREE_TYPE (op
)))
2412 /* C++0x scoped enumerations don't implicitly convert to integral
2413 type; if we stripped an explicit conversion to a larger type we
2414 need to replace it so common_type will still work. */
2415 tree type
= c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op
)),
2416 TYPE_UNSIGNED (TREE_TYPE (op
)));
2417 op
= fold_convert (type
, op
);
2422 /* This is a helper function of build_binary_op.
2424 For certain operations if both args were extended from the same
2425 smaller type, do the arithmetic in that type and then extend.
2427 BITWISE indicates a bitwise operation.
2428 For them, this optimization is safe only if
2429 both args are zero-extended or both are sign-extended.
2430 Otherwise, we might change the result.
2431 Eg, (short)-1 | (unsigned short)-1 is (int)-1
2432 but calculated in (unsigned short) it would be (unsigned short)-1.
2435 shorten_binary_op (tree result_type
, tree op0
, tree op1
, bool bitwise
)
2437 int unsigned0
, unsigned1
;
2442 /* Cast OP0 and OP1 to RESULT_TYPE. Doing so prevents
2443 excessive narrowing when we call get_narrower below. For
2444 example, suppose that OP0 is of unsigned int extended
2445 from signed char and that RESULT_TYPE is long long int.
2446 If we explicitly cast OP0 to RESULT_TYPE, OP0 would look
2449 (long long int) (unsigned int) signed_char
2451 which get_narrower would narrow down to
2453 (unsigned int) signed char
2455 If we do not cast OP0 first, get_narrower would return
2456 signed_char, which is inconsistent with the case of the
2458 op0
= convert (result_type
, op0
);
2459 op1
= convert (result_type
, op1
);
2461 arg0
= c_common_get_narrower (op0
, &unsigned0
);
2462 arg1
= c_common_get_narrower (op1
, &unsigned1
);
2464 /* UNS is 1 if the operation to be done is an unsigned one. */
2465 uns
= TYPE_UNSIGNED (result_type
);
2467 /* Handle the case that OP0 (or OP1) does not *contain* a conversion
2468 but it *requires* conversion to FINAL_TYPE. */
2470 if ((TYPE_PRECISION (TREE_TYPE (op0
))
2471 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2472 && TREE_TYPE (op0
) != result_type
)
2473 unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2474 if ((TYPE_PRECISION (TREE_TYPE (op1
))
2475 == TYPE_PRECISION (TREE_TYPE (arg1
)))
2476 && TREE_TYPE (op1
) != result_type
)
2477 unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2479 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
2481 /* For bitwise operations, signedness of nominal type
2482 does not matter. Consider only how operands were extended. */
2486 /* Note that in all three cases below we refrain from optimizing
2487 an unsigned operation on sign-extended args.
2488 That would not be valid. */
2490 /* Both args variable: if both extended in same way
2491 from same width, do it in that width.
2492 Do it unsigned if args were zero-extended. */
2493 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
2494 < TYPE_PRECISION (result_type
))
2495 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2496 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2497 && unsigned0
== unsigned1
2498 && (unsigned0
|| !uns
))
2499 return c_common_signed_or_unsigned_type
2500 (unsigned0
, common_type (TREE_TYPE (arg0
), TREE_TYPE (arg1
)));
2502 else if (TREE_CODE (arg0
) == INTEGER_CST
2503 && (unsigned1
|| !uns
)
2504 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2505 < TYPE_PRECISION (result_type
))
2507 = c_common_signed_or_unsigned_type (unsigned1
,
2509 && !POINTER_TYPE_P (type
)
2510 && int_fits_type_p (arg0
, type
))
2513 else if (TREE_CODE (arg1
) == INTEGER_CST
2514 && (unsigned0
|| !uns
)
2515 && (TYPE_PRECISION (TREE_TYPE (arg0
))
2516 < TYPE_PRECISION (result_type
))
2518 = c_common_signed_or_unsigned_type (unsigned0
,
2520 && !POINTER_TYPE_P (type
)
2521 && int_fits_type_p (arg1
, type
))
2527 /* Checks if expression EXPR of real/integer type cannot be converted
2528 to the real/integer type TYPE. Function returns non-zero when:
2529 * EXPR is a constant which cannot be exactly converted to TYPE
2530 * EXPR is not a constant and size of EXPR's type > than size of TYPE,
2531 for EXPR type and TYPE being both integers or both real.
2532 * EXPR is not a constant of real type and TYPE is an integer.
2533 * EXPR is not a constant of integer type which cannot be
2534 exactly converted to real type.
2535 Function allows conversions between types of different signedness and
2536 can return SAFE_CONVERSION (zero) in that case. Function can produce
2537 signedness warnings if PRODUCE_WARNS is true. */
2538 enum conversion_safety
2539 unsafe_conversion_p (tree type
, tree expr
, bool produce_warns
)
2541 enum conversion_safety give_warning
= SAFE_CONVERSION
; /* is 0 or false */
2542 tree expr_type
= TREE_TYPE (expr
);
2543 location_t loc
= EXPR_LOC_OR_LOC (expr
, input_location
);
2545 if (TREE_CODE (expr
) == REAL_CST
|| TREE_CODE (expr
) == INTEGER_CST
)
2547 /* Warn for real constant that is not an exact integer converted
2549 if (TREE_CODE (expr_type
) == REAL_TYPE
2550 && TREE_CODE (type
) == INTEGER_TYPE
)
2552 if (!real_isinteger (TREE_REAL_CST_PTR (expr
), TYPE_MODE (expr_type
)))
2553 give_warning
= UNSAFE_REAL
;
2555 /* Warn for an integer constant that does not fit into integer type. */
2556 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2557 && TREE_CODE (type
) == INTEGER_TYPE
2558 && !int_fits_type_p (expr
, type
))
2560 if (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)
2561 && tree_int_cst_sgn (expr
) < 0)
2564 warning_at (loc
, OPT_Wsign_conversion
, "negative integer"
2565 " implicitly converted to unsigned type");
2567 else if (!TYPE_UNSIGNED (type
) && TYPE_UNSIGNED (expr_type
))
2570 warning_at (loc
, OPT_Wsign_conversion
, "conversion of unsigned"
2571 " constant value to negative integer");
2574 give_warning
= UNSAFE_OTHER
;
2576 else if (TREE_CODE (type
) == REAL_TYPE
)
2578 /* Warn for an integer constant that does not fit into real type. */
2579 if (TREE_CODE (expr_type
) == INTEGER_TYPE
)
2581 REAL_VALUE_TYPE a
= real_value_from_int_cst (0, expr
);
2582 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2583 give_warning
= UNSAFE_REAL
;
2585 /* Warn for a real constant that does not fit into a smaller
2587 else if (TREE_CODE (expr_type
) == REAL_TYPE
2588 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2590 REAL_VALUE_TYPE a
= TREE_REAL_CST (expr
);
2591 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2592 give_warning
= UNSAFE_REAL
;
2598 /* Warn for real types converted to integer types. */
2599 if (TREE_CODE (expr_type
) == REAL_TYPE
2600 && TREE_CODE (type
) == INTEGER_TYPE
)
2601 give_warning
= UNSAFE_REAL
;
2603 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2604 && TREE_CODE (type
) == INTEGER_TYPE
)
2606 /* Don't warn about unsigned char y = 0xff, x = (int) y; */
2607 expr
= get_unwidened (expr
, 0);
2608 expr_type
= TREE_TYPE (expr
);
2610 /* Don't warn for short y; short x = ((int)y & 0xff); */
2611 if (TREE_CODE (expr
) == BIT_AND_EXPR
2612 || TREE_CODE (expr
) == BIT_IOR_EXPR
2613 || TREE_CODE (expr
) == BIT_XOR_EXPR
)
2615 /* If both args were extended from a shortest type,
2616 use that type if that is safe. */
2617 expr_type
= shorten_binary_op (expr_type
,
2618 TREE_OPERAND (expr
, 0),
2619 TREE_OPERAND (expr
, 1),
2622 if (TREE_CODE (expr
) == BIT_AND_EXPR
)
2624 tree op0
= TREE_OPERAND (expr
, 0);
2625 tree op1
= TREE_OPERAND (expr
, 1);
2626 bool unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2627 bool unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2629 /* If one of the operands is a non-negative constant
2630 that fits in the target type, then the type of the
2631 other operand does not matter. */
2632 if ((TREE_CODE (op0
) == INTEGER_CST
2633 && int_fits_type_p (op0
, c_common_signed_type (type
))
2634 && int_fits_type_p (op0
, c_common_unsigned_type (type
)))
2635 || (TREE_CODE (op1
) == INTEGER_CST
2636 && int_fits_type_p (op1
, c_common_signed_type (type
))
2637 && int_fits_type_p (op1
,
2638 c_common_unsigned_type (type
))))
2639 return SAFE_CONVERSION
;
2640 /* If constant is unsigned and fits in the target
2641 type, then the result will also fit. */
2642 else if ((TREE_CODE (op0
) == INTEGER_CST
2644 && int_fits_type_p (op0
, type
))
2645 || (TREE_CODE (op1
) == INTEGER_CST
2647 && int_fits_type_p (op1
, type
)))
2648 return SAFE_CONVERSION
;
2651 /* Warn for integer types converted to smaller integer types. */
2652 if (TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2653 give_warning
= UNSAFE_OTHER
;
2655 /* When they are the same width but different signedness,
2656 then the value may change. */
2657 else if (((TYPE_PRECISION (type
) == TYPE_PRECISION (expr_type
)
2658 && TYPE_UNSIGNED (expr_type
) != TYPE_UNSIGNED (type
))
2659 /* Even when converted to a bigger type, if the type is
2660 unsigned but expr is signed, then negative values
2662 || (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)))
2664 warning_at (loc
, OPT_Wsign_conversion
, "conversion to %qT from %qT "
2665 "may change the sign of the result",
2669 /* Warn for integer types converted to real types if and only if
2670 all the range of values of the integer type cannot be
2671 represented by the real type. */
2672 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2673 && TREE_CODE (type
) == REAL_TYPE
)
2675 tree type_low_bound
, type_high_bound
;
2676 REAL_VALUE_TYPE real_low_bound
, real_high_bound
;
2678 /* Don't warn about char y = 0xff; float x = (int) y; */
2679 expr
= get_unwidened (expr
, 0);
2680 expr_type
= TREE_TYPE (expr
);
2682 type_low_bound
= TYPE_MIN_VALUE (expr_type
);
2683 type_high_bound
= TYPE_MAX_VALUE (expr_type
);
2684 real_low_bound
= real_value_from_int_cst (0, type_low_bound
);
2685 real_high_bound
= real_value_from_int_cst (0, type_high_bound
);
2687 if (!exact_real_truncate (TYPE_MODE (type
), &real_low_bound
)
2688 || !exact_real_truncate (TYPE_MODE (type
), &real_high_bound
))
2689 give_warning
= UNSAFE_OTHER
;
2692 /* Warn for real types converted to smaller real types. */
2693 else if (TREE_CODE (expr_type
) == REAL_TYPE
2694 && TREE_CODE (type
) == REAL_TYPE
2695 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2696 give_warning
= UNSAFE_REAL
;
2699 return give_warning
;
2702 /* Warns if the conversion of EXPR to TYPE may alter a value.
2703 This is a helper function for warnings_for_convert_and_check. */
2706 conversion_warning (tree type
, tree expr
)
2708 tree expr_type
= TREE_TYPE (expr
);
2709 location_t loc
= EXPR_LOC_OR_LOC (expr
, input_location
);
2710 enum conversion_safety conversion_kind
;
2712 if (!warn_conversion
&& !warn_sign_conversion
&& !warn_float_conversion
)
2715 switch (TREE_CODE (expr
))
2723 case TRUTH_ANDIF_EXPR
:
2724 case TRUTH_ORIF_EXPR
:
2725 case TRUTH_AND_EXPR
:
2727 case TRUTH_XOR_EXPR
:
2728 case TRUTH_NOT_EXPR
:
2729 /* Conversion from boolean to a signed:1 bit-field (which only
2730 can hold the values 0 and -1) doesn't lose information - but
2731 it does change the value. */
2732 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
2733 warning_at (loc
, OPT_Wconversion
,
2734 "conversion to %qT from boolean expression", type
);
2739 conversion_kind
= unsafe_conversion_p (type
, expr
, true);
2740 if (conversion_kind
== UNSAFE_REAL
)
2741 warning_at (loc
, OPT_Wfloat_conversion
,
2742 "conversion to %qT alters %qT constant value",
2744 else if (conversion_kind
)
2745 warning_at (loc
, OPT_Wconversion
,
2746 "conversion to %qT alters %qT constant value",
2752 /* In case of COND_EXPR, we do not care about the type of
2753 COND_EXPR, only about the conversion of each operand. */
2754 tree op1
= TREE_OPERAND (expr
, 1);
2755 tree op2
= TREE_OPERAND (expr
, 2);
2757 conversion_warning (type
, op1
);
2758 conversion_warning (type
, op2
);
2762 default: /* 'expr' is not a constant. */
2763 conversion_kind
= unsafe_conversion_p (type
, expr
, true);
2764 if (conversion_kind
== UNSAFE_REAL
)
2765 warning_at (loc
, OPT_Wfloat_conversion
,
2766 "conversion to %qT from %qT may alter its value",
2768 else if (conversion_kind
)
2769 warning_at (loc
, OPT_Wconversion
,
2770 "conversion to %qT from %qT may alter its value",
2775 /* Produce warnings after a conversion. RESULT is the result of
2776 converting EXPR to TYPE. This is a helper function for
2777 convert_and_check and cp_convert_and_check. */
2780 warnings_for_convert_and_check (tree type
, tree expr
, tree result
)
2782 location_t loc
= EXPR_LOC_OR_LOC (expr
, input_location
);
2784 if (TREE_CODE (expr
) == INTEGER_CST
2785 && (TREE_CODE (type
) == INTEGER_TYPE
2786 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2787 && !int_fits_type_p (expr
, type
))
2789 /* Do not diagnose overflow in a constant expression merely
2790 because a conversion overflowed. */
2791 if (TREE_OVERFLOW (result
))
2792 TREE_OVERFLOW (result
) = TREE_OVERFLOW (expr
);
2794 if (TYPE_UNSIGNED (type
))
2796 /* This detects cases like converting -129 or 256 to
2798 if (!int_fits_type_p (expr
, c_common_signed_type (type
)))
2799 warning_at (loc
, OPT_Woverflow
,
2800 "large integer implicitly truncated to unsigned type");
2802 conversion_warning (type
, expr
);
2804 else if (!int_fits_type_p (expr
, c_common_unsigned_type (type
)))
2805 warning (OPT_Woverflow
,
2806 "overflow in implicit constant conversion");
2807 /* No warning for converting 0x80000000 to int. */
2809 && (TREE_CODE (TREE_TYPE (expr
)) != INTEGER_TYPE
2810 || TYPE_PRECISION (TREE_TYPE (expr
))
2811 != TYPE_PRECISION (type
)))
2812 warning_at (loc
, OPT_Woverflow
,
2813 "overflow in implicit constant conversion");
2816 conversion_warning (type
, expr
);
2818 else if ((TREE_CODE (result
) == INTEGER_CST
2819 || TREE_CODE (result
) == FIXED_CST
) && TREE_OVERFLOW (result
))
2820 warning_at (loc
, OPT_Woverflow
,
2821 "overflow in implicit constant conversion");
2823 conversion_warning (type
, expr
);
2827 /* Convert EXPR to TYPE, warning about conversion problems with constants.
2828 Invoke this function on every expression that is converted implicitly,
2829 i.e. because of language rules and not because of an explicit cast. */
2832 convert_and_check (tree type
, tree expr
)
2835 tree expr_for_warning
;
2837 /* Convert from a value with possible excess precision rather than
2838 via the semantic type, but do not warn about values not fitting
2839 exactly in the semantic type. */
2840 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
2842 tree orig_type
= TREE_TYPE (expr
);
2843 expr
= TREE_OPERAND (expr
, 0);
2844 expr_for_warning
= convert (orig_type
, expr
);
2845 if (orig_type
== type
)
2846 return expr_for_warning
;
2849 expr_for_warning
= expr
;
2851 if (TREE_TYPE (expr
) == type
)
2854 result
= convert (type
, expr
);
2856 if (c_inhibit_evaluation_warnings
== 0
2857 && !TREE_OVERFLOW_P (expr
)
2858 && result
!= error_mark_node
)
2859 warnings_for_convert_and_check (type
, expr_for_warning
, result
);
2864 /* A node in a list that describes references to variables (EXPR), which are
2865 either read accesses if WRITER is zero, or write accesses, in which case
2866 WRITER is the parent of EXPR. */
2873 /* Used to implement a cache the results of a call to verify_tree. We only
2874 use this for SAVE_EXPRs. */
2877 struct tlist_cache
*next
;
2878 struct tlist
*cache_before_sp
;
2879 struct tlist
*cache_after_sp
;
2883 /* Obstack to use when allocating tlist structures, and corresponding
2885 static struct obstack tlist_obstack
;
2886 static char *tlist_firstobj
= 0;
2888 /* Keep track of the identifiers we've warned about, so we can avoid duplicate
2890 static struct tlist
*warned_ids
;
2891 /* SAVE_EXPRs need special treatment. We process them only once and then
2892 cache the results. */
2893 static struct tlist_cache
*save_expr_cache
;
2895 static void add_tlist (struct tlist
**, struct tlist
*, tree
, int);
2896 static void merge_tlist (struct tlist
**, struct tlist
*, int);
2897 static void verify_tree (tree
, struct tlist
**, struct tlist
**, tree
);
2898 static int warning_candidate_p (tree
);
2899 static bool candidate_equal_p (const_tree
, const_tree
);
2900 static void warn_for_collisions (struct tlist
*);
2901 static void warn_for_collisions_1 (tree
, tree
, struct tlist
*, int);
2902 static struct tlist
*new_tlist (struct tlist
*, tree
, tree
);
2904 /* Create a new struct tlist and fill in its fields. */
2905 static struct tlist
*
2906 new_tlist (struct tlist
*next
, tree t
, tree writer
)
2909 l
= XOBNEW (&tlist_obstack
, struct tlist
);
2916 /* Add duplicates of the nodes found in ADD to the list *TO. If EXCLUDE_WRITER
2917 is nonnull, we ignore any node we find which has a writer equal to it. */
2920 add_tlist (struct tlist
**to
, struct tlist
*add
, tree exclude_writer
, int copy
)
2924 struct tlist
*next
= add
->next
;
2927 if (!exclude_writer
|| !candidate_equal_p (add
->writer
, exclude_writer
))
2928 *to
= copy
? new_tlist (*to
, add
->expr
, add
->writer
) : add
;
2933 /* Merge the nodes of ADD into TO. This merging process is done so that for
2934 each variable that already exists in TO, no new node is added; however if
2935 there is a write access recorded in ADD, and an occurrence on TO is only
2936 a read access, then the occurrence in TO will be modified to record the
2940 merge_tlist (struct tlist
**to
, struct tlist
*add
, int copy
)
2942 struct tlist
**end
= to
;
2945 end
= &(*end
)->next
;
2951 struct tlist
*next
= add
->next
;
2953 for (tmp2
= *to
; tmp2
; tmp2
= tmp2
->next
)
2954 if (candidate_equal_p (tmp2
->expr
, add
->expr
))
2958 tmp2
->writer
= add
->writer
;
2962 *end
= copy
? add
: new_tlist (NULL
, add
->expr
, add
->writer
);
2963 end
= &(*end
)->next
;
2970 /* WRITTEN is a variable, WRITER is its parent. Warn if any of the variable
2971 references in list LIST conflict with it, excluding reads if ONLY writers
2975 warn_for_collisions_1 (tree written
, tree writer
, struct tlist
*list
,
2980 /* Avoid duplicate warnings. */
2981 for (tmp
= warned_ids
; tmp
; tmp
= tmp
->next
)
2982 if (candidate_equal_p (tmp
->expr
, written
))
2987 if (candidate_equal_p (list
->expr
, written
)
2988 && !candidate_equal_p (list
->writer
, writer
)
2989 && (!only_writes
|| list
->writer
))
2991 warned_ids
= new_tlist (warned_ids
, written
, NULL_TREE
);
2992 warning_at (EXPR_LOC_OR_LOC (writer
, input_location
),
2993 OPT_Wsequence_point
, "operation on %qE may be undefined",
3000 /* Given a list LIST of references to variables, find whether any of these
3001 can cause conflicts due to missing sequence points. */
3004 warn_for_collisions (struct tlist
*list
)
3008 for (tmp
= list
; tmp
; tmp
= tmp
->next
)
3011 warn_for_collisions_1 (tmp
->expr
, tmp
->writer
, list
, 0);
3015 /* Return nonzero if X is a tree that can be verified by the sequence point
3018 warning_candidate_p (tree x
)
3020 if (DECL_P (x
) && DECL_ARTIFICIAL (x
))
3023 if (TREE_CODE (x
) == BLOCK
)
3026 /* VOID_TYPE_P (TREE_TYPE (x)) is workaround for cp/tree.c
3027 (lvalue_p) crash on TRY/CATCH. */
3028 if (TREE_TYPE (x
) == NULL_TREE
|| VOID_TYPE_P (TREE_TYPE (x
)))
3034 /* No point to track non-const calls, they will never satisfy
3036 if (TREE_CODE (x
) == CALL_EXPR
&& (call_expr_flags (x
) & ECF_CONST
) == 0)
3039 if (TREE_CODE (x
) == STRING_CST
)
3045 /* Return nonzero if X and Y appear to be the same candidate (or NULL) */
3047 candidate_equal_p (const_tree x
, const_tree y
)
3049 return (x
== y
) || (x
&& y
&& operand_equal_p (x
, y
, 0));
3052 /* Walk the tree X, and record accesses to variables. If X is written by the
3053 parent tree, WRITER is the parent.
3054 We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP. If this
3055 expression or its only operand forces a sequence point, then everything up
3056 to the sequence point is stored in PBEFORE_SP. Everything else gets stored
3058 Once we return, we will have emitted warnings if any subexpression before
3059 such a sequence point could be undefined. On a higher level, however, the
3060 sequence point may not be relevant, and we'll merge the two lists.
3062 Example: (b++, a) + b;
3063 The call that processes the COMPOUND_EXPR will store the increment of B
3064 in PBEFORE_SP, and the use of A in PNO_SP. The higher-level call that
3065 processes the PLUS_EXPR will need to merge the two lists so that
3066 eventually, all accesses end up on the same list (and we'll warn about the
3067 unordered subexpressions b++ and b.
3069 A note on merging. If we modify the former example so that our expression
3072 care must be taken not simply to add all three expressions into the final
3073 PNO_SP list. The function merge_tlist takes care of that by merging the
3074 before-SP list of the COMPOUND_EXPR into its after-SP list in a special
3075 way, so that no more than one access to B is recorded. */
3078 verify_tree (tree x
, struct tlist
**pbefore_sp
, struct tlist
**pno_sp
,
3081 struct tlist
*tmp_before
, *tmp_nosp
, *tmp_list2
, *tmp_list3
;
3082 enum tree_code code
;
3083 enum tree_code_class cl
;
3085 /* X may be NULL if it is the operand of an empty statement expression
3091 code
= TREE_CODE (x
);
3092 cl
= TREE_CODE_CLASS (code
);
3094 if (warning_candidate_p (x
))
3095 *pno_sp
= new_tlist (*pno_sp
, x
, writer
);
3104 case TRUTH_ANDIF_EXPR
:
3105 case TRUTH_ORIF_EXPR
:
3106 tmp_before
= tmp_nosp
= tmp_list3
= 0;
3107 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3108 warn_for_collisions (tmp_nosp
);
3109 merge_tlist (pbefore_sp
, tmp_before
, 0);
3110 merge_tlist (pbefore_sp
, tmp_nosp
, 0);
3111 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, pno_sp
, NULL_TREE
);
3112 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3116 tmp_before
= tmp_list2
= 0;
3117 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_list2
, NULL_TREE
);
3118 warn_for_collisions (tmp_list2
);
3119 merge_tlist (pbefore_sp
, tmp_before
, 0);
3120 merge_tlist (pbefore_sp
, tmp_list2
, 1);
3122 tmp_list3
= tmp_nosp
= 0;
3123 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, &tmp_nosp
, NULL_TREE
);
3124 warn_for_collisions (tmp_nosp
);
3125 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3127 tmp_list3
= tmp_list2
= 0;
3128 verify_tree (TREE_OPERAND (x
, 2), &tmp_list3
, &tmp_list2
, NULL_TREE
);
3129 warn_for_collisions (tmp_list2
);
3130 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3131 /* Rather than add both tmp_nosp and tmp_list2, we have to merge the
3132 two first, to avoid warning for (a ? b++ : b++). */
3133 merge_tlist (&tmp_nosp
, tmp_list2
, 0);
3134 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3137 case PREDECREMENT_EXPR
:
3138 case PREINCREMENT_EXPR
:
3139 case POSTDECREMENT_EXPR
:
3140 case POSTINCREMENT_EXPR
:
3141 verify_tree (TREE_OPERAND (x
, 0), pno_sp
, pno_sp
, x
);
3145 tmp_before
= tmp_nosp
= tmp_list3
= 0;
3146 verify_tree (TREE_OPERAND (x
, 1), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3147 verify_tree (TREE_OPERAND (x
, 0), &tmp_list3
, &tmp_list3
, x
);
3148 /* Expressions inside the LHS are not ordered wrt. the sequence points
3149 in the RHS. Example:
3151 Despite the fact that the modification of "a" is in the before_sp
3152 list (tmp_before), it conflicts with the use of "a" in the LHS.
3153 We can handle this by adding the contents of tmp_list3
3154 to those of tmp_before, and redoing the collision warnings for that
3156 add_tlist (&tmp_before
, tmp_list3
, x
, 1);
3157 warn_for_collisions (tmp_before
);
3158 /* Exclude the LHS itself here; we first have to merge it into the
3159 tmp_nosp list. This is done to avoid warning for "a = a"; if we
3160 didn't exclude the LHS, we'd get it twice, once as a read and once
3162 add_tlist (pno_sp
, tmp_list3
, x
, 0);
3163 warn_for_collisions_1 (TREE_OPERAND (x
, 0), x
, tmp_nosp
, 1);
3165 merge_tlist (pbefore_sp
, tmp_before
, 0);
3166 if (warning_candidate_p (TREE_OPERAND (x
, 0)))
3167 merge_tlist (&tmp_nosp
, new_tlist (NULL
, TREE_OPERAND (x
, 0), x
), 0);
3168 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 1);
3172 /* We need to warn about conflicts among arguments and conflicts between
3173 args and the function address. Side effects of the function address,
3174 however, are not ordered by the sequence point of the call. */
3176 call_expr_arg_iterator iter
;
3178 tmp_before
= tmp_nosp
= 0;
3179 verify_tree (CALL_EXPR_FN (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3180 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, x
)
3182 tmp_list2
= tmp_list3
= 0;
3183 verify_tree (arg
, &tmp_list2
, &tmp_list3
, NULL_TREE
);
3184 merge_tlist (&tmp_list3
, tmp_list2
, 0);
3185 add_tlist (&tmp_before
, tmp_list3
, NULL_TREE
, 0);
3187 add_tlist (&tmp_before
, tmp_nosp
, NULL_TREE
, 0);
3188 warn_for_collisions (tmp_before
);
3189 add_tlist (pbefore_sp
, tmp_before
, NULL_TREE
, 0);
3194 /* Scan all the list, e.g. indices of multi dimensional array. */
3197 tmp_before
= tmp_nosp
= 0;
3198 verify_tree (TREE_VALUE (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3199 merge_tlist (&tmp_nosp
, tmp_before
, 0);
3200 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3207 struct tlist_cache
*t
;
3208 for (t
= save_expr_cache
; t
; t
= t
->next
)
3209 if (candidate_equal_p (t
->expr
, x
))
3214 t
= XOBNEW (&tlist_obstack
, struct tlist_cache
);
3215 t
->next
= save_expr_cache
;
3217 save_expr_cache
= t
;
3219 tmp_before
= tmp_nosp
= 0;
3220 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3221 warn_for_collisions (tmp_nosp
);
3226 struct tlist
*t
= tmp_nosp
;
3228 merge_tlist (&tmp_list3
, t
, 0);
3230 t
->cache_before_sp
= tmp_before
;
3231 t
->cache_after_sp
= tmp_list3
;
3233 merge_tlist (pbefore_sp
, t
->cache_before_sp
, 1);
3234 add_tlist (pno_sp
, t
->cache_after_sp
, NULL_TREE
, 1);
3239 x
= TREE_OPERAND (x
, 0);
3246 /* For other expressions, simply recurse on their operands.
3247 Manual tail recursion for unary expressions.
3248 Other non-expressions need not be processed. */
3249 if (cl
== tcc_unary
)
3251 x
= TREE_OPERAND (x
, 0);
3255 else if (IS_EXPR_CODE_CLASS (cl
))
3258 int max
= TREE_OPERAND_LENGTH (x
);
3259 for (lp
= 0; lp
< max
; lp
++)
3261 tmp_before
= tmp_nosp
= 0;
3262 verify_tree (TREE_OPERAND (x
, lp
), &tmp_before
, &tmp_nosp
, 0);
3263 merge_tlist (&tmp_nosp
, tmp_before
, 0);
3264 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3271 /* Try to warn for undefined behavior in EXPR due to missing sequence
3275 verify_sequence_points (tree expr
)
3277 struct tlist
*before_sp
= 0, *after_sp
= 0;
3280 save_expr_cache
= 0;
3281 if (tlist_firstobj
== 0)
3283 gcc_obstack_init (&tlist_obstack
);
3284 tlist_firstobj
= (char *) obstack_alloc (&tlist_obstack
, 0);
3287 verify_tree (expr
, &before_sp
, &after_sp
, 0);
3288 warn_for_collisions (after_sp
);
3289 obstack_free (&tlist_obstack
, tlist_firstobj
);
3292 /* Validate the expression after `case' and apply default promotions. */
3295 check_case_value (tree value
)
3297 if (value
== NULL_TREE
)
3300 if (TREE_CODE (value
) == INTEGER_CST
)
3301 /* Promote char or short to int. */
3302 value
= perform_integral_promotions (value
);
3303 else if (value
!= error_mark_node
)
3305 error ("case label does not reduce to an integer constant");
3306 value
= error_mark_node
;
3309 constant_expression_warning (value
);
3314 /* See if the case values LOW and HIGH are in the range of the original
3315 type (i.e. before the default conversion to int) of the switch testing
3317 TYPE is the promoted type of the testing expression, and ORIG_TYPE is
3318 the type before promoting it. CASE_LOW_P is a pointer to the lower
3319 bound of the case label, and CASE_HIGH_P is the upper bound or NULL
3320 if the case is not a case range.
3321 The caller has to make sure that we are not called with NULL for
3322 CASE_LOW_P (i.e. the default case).
3323 Returns true if the case label is in range of ORIG_TYPE (saturated or
3324 untouched) or false if the label is out of range. */
3327 check_case_bounds (tree type
, tree orig_type
,
3328 tree
*case_low_p
, tree
*case_high_p
)
3330 tree min_value
, max_value
;
3331 tree case_low
= *case_low_p
;
3332 tree case_high
= case_high_p
? *case_high_p
: case_low
;
3334 /* If there was a problem with the original type, do nothing. */
3335 if (orig_type
== error_mark_node
)
3338 min_value
= TYPE_MIN_VALUE (orig_type
);
3339 max_value
= TYPE_MAX_VALUE (orig_type
);
3341 /* Case label is less than minimum for type. */
3342 if (tree_int_cst_compare (case_low
, min_value
) < 0
3343 && tree_int_cst_compare (case_high
, min_value
) < 0)
3345 warning (0, "case label value is less than minimum value for type");
3349 /* Case value is greater than maximum for type. */
3350 if (tree_int_cst_compare (case_low
, max_value
) > 0
3351 && tree_int_cst_compare (case_high
, max_value
) > 0)
3353 warning (0, "case label value exceeds maximum value for type");
3357 /* Saturate lower case label value to minimum. */
3358 if (tree_int_cst_compare (case_high
, min_value
) >= 0
3359 && tree_int_cst_compare (case_low
, min_value
) < 0)
3361 warning (0, "lower value in case label range"
3362 " less than minimum value for type");
3363 case_low
= min_value
;
3366 /* Saturate upper case label value to maximum. */
3367 if (tree_int_cst_compare (case_low
, max_value
) <= 0
3368 && tree_int_cst_compare (case_high
, max_value
) > 0)
3370 warning (0, "upper value in case label range"
3371 " exceeds maximum value for type");
3372 case_high
= max_value
;
3375 if (*case_low_p
!= case_low
)
3376 *case_low_p
= convert (type
, case_low
);
3377 if (case_high_p
&& *case_high_p
!= case_high
)
3378 *case_high_p
= convert (type
, case_high
);
3383 /* Return an integer type with BITS bits of precision,
3384 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
3387 c_common_type_for_size (unsigned int bits
, int unsignedp
)
3389 if (bits
== TYPE_PRECISION (integer_type_node
))
3390 return unsignedp
? unsigned_type_node
: integer_type_node
;
3392 if (bits
== TYPE_PRECISION (signed_char_type_node
))
3393 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3395 if (bits
== TYPE_PRECISION (short_integer_type_node
))
3396 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3398 if (bits
== TYPE_PRECISION (long_integer_type_node
))
3399 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3401 if (bits
== TYPE_PRECISION (long_long_integer_type_node
))
3402 return (unsignedp
? long_long_unsigned_type_node
3403 : long_long_integer_type_node
);
3405 if (int128_integer_type_node
3406 && bits
== TYPE_PRECISION (int128_integer_type_node
))
3407 return (unsignedp
? int128_unsigned_type_node
3408 : int128_integer_type_node
);
3410 if (bits
== TYPE_PRECISION (widest_integer_literal_type_node
))
3411 return (unsignedp
? widest_unsigned_literal_type_node
3412 : widest_integer_literal_type_node
);
3414 if (bits
<= TYPE_PRECISION (intQI_type_node
))
3415 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3417 if (bits
<= TYPE_PRECISION (intHI_type_node
))
3418 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3420 if (bits
<= TYPE_PRECISION (intSI_type_node
))
3421 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3423 if (bits
<= TYPE_PRECISION (intDI_type_node
))
3424 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3429 /* Return a fixed-point type that has at least IBIT ibits and FBIT fbits
3430 that is unsigned if UNSIGNEDP is nonzero, otherwise signed;
3431 and saturating if SATP is nonzero, otherwise not saturating. */
3434 c_common_fixed_point_type_for_size (unsigned int ibit
, unsigned int fbit
,
3435 int unsignedp
, int satp
)
3437 enum machine_mode mode
;
3439 mode
= unsignedp
? UQQmode
: QQmode
;
3441 mode
= unsignedp
? UHAmode
: HAmode
;
3443 for (; mode
!= VOIDmode
; mode
= GET_MODE_WIDER_MODE (mode
))
3444 if (GET_MODE_IBIT (mode
) >= ibit
&& GET_MODE_FBIT (mode
) >= fbit
)
3447 if (mode
== VOIDmode
|| !targetm
.scalar_mode_supported_p (mode
))
3449 sorry ("GCC cannot support operators with integer types and "
3450 "fixed-point types that have too many integral and "
3451 "fractional bits together");
3455 return c_common_type_for_mode (mode
, satp
);
3458 /* Used for communication between c_common_type_for_mode and
3459 c_register_builtin_type. */
3460 static GTY(()) tree registered_builtin_types
;
3462 /* Return a data type that has machine mode MODE.
3463 If the mode is an integer,
3464 then UNSIGNEDP selects between signed and unsigned types.
3465 If the mode is a fixed-point mode,
3466 then UNSIGNEDP selects between saturating and nonsaturating types. */
3469 c_common_type_for_mode (enum machine_mode mode
, int unsignedp
)
3473 if (mode
== TYPE_MODE (integer_type_node
))
3474 return unsignedp
? unsigned_type_node
: integer_type_node
;
3476 if (mode
== TYPE_MODE (signed_char_type_node
))
3477 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3479 if (mode
== TYPE_MODE (short_integer_type_node
))
3480 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3482 if (mode
== TYPE_MODE (long_integer_type_node
))
3483 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3485 if (mode
== TYPE_MODE (long_long_integer_type_node
))
3486 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3488 if (int128_integer_type_node
3489 && mode
== TYPE_MODE (int128_integer_type_node
))
3490 return unsignedp
? int128_unsigned_type_node
: int128_integer_type_node
;
3492 if (mode
== TYPE_MODE (widest_integer_literal_type_node
))
3493 return unsignedp
? widest_unsigned_literal_type_node
3494 : widest_integer_literal_type_node
;
3497 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3500 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3503 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3506 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3508 #if HOST_BITS_PER_WIDE_INT >= 64
3509 if (mode
== TYPE_MODE (intTI_type_node
))
3510 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3513 if (mode
== TYPE_MODE (float_type_node
))
3514 return float_type_node
;
3516 if (mode
== TYPE_MODE (double_type_node
))
3517 return double_type_node
;
3519 if (mode
== TYPE_MODE (long_double_type_node
))
3520 return long_double_type_node
;
3522 if (mode
== TYPE_MODE (void_type_node
))
3523 return void_type_node
;
3525 if (mode
== TYPE_MODE (build_pointer_type (char_type_node
)))
3527 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3528 : make_signed_type (GET_MODE_PRECISION (mode
)));
3530 if (mode
== TYPE_MODE (build_pointer_type (integer_type_node
)))
3532 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3533 : make_signed_type (GET_MODE_PRECISION (mode
)));
3535 if (COMPLEX_MODE_P (mode
))
3537 enum machine_mode inner_mode
;
3540 if (mode
== TYPE_MODE (complex_float_type_node
))
3541 return complex_float_type_node
;
3542 if (mode
== TYPE_MODE (complex_double_type_node
))
3543 return complex_double_type_node
;
3544 if (mode
== TYPE_MODE (complex_long_double_type_node
))
3545 return complex_long_double_type_node
;
3547 if (mode
== TYPE_MODE (complex_integer_type_node
) && !unsignedp
)
3548 return complex_integer_type_node
;
3550 inner_mode
= GET_MODE_INNER (mode
);
3551 inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3552 if (inner_type
!= NULL_TREE
)
3553 return build_complex_type (inner_type
);
3555 else if (VECTOR_MODE_P (mode
))
3557 enum machine_mode inner_mode
= GET_MODE_INNER (mode
);
3558 tree inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3559 if (inner_type
!= NULL_TREE
)
3560 return build_vector_type_for_mode (inner_type
, mode
);
3563 if (mode
== TYPE_MODE (dfloat32_type_node
))
3564 return dfloat32_type_node
;
3565 if (mode
== TYPE_MODE (dfloat64_type_node
))
3566 return dfloat64_type_node
;
3567 if (mode
== TYPE_MODE (dfloat128_type_node
))
3568 return dfloat128_type_node
;
3570 if (ALL_SCALAR_FIXED_POINT_MODE_P (mode
))
3572 if (mode
== TYPE_MODE (short_fract_type_node
))
3573 return unsignedp
? sat_short_fract_type_node
: short_fract_type_node
;
3574 if (mode
== TYPE_MODE (fract_type_node
))
3575 return unsignedp
? sat_fract_type_node
: fract_type_node
;
3576 if (mode
== TYPE_MODE (long_fract_type_node
))
3577 return unsignedp
? sat_long_fract_type_node
: long_fract_type_node
;
3578 if (mode
== TYPE_MODE (long_long_fract_type_node
))
3579 return unsignedp
? sat_long_long_fract_type_node
3580 : long_long_fract_type_node
;
3582 if (mode
== TYPE_MODE (unsigned_short_fract_type_node
))
3583 return unsignedp
? sat_unsigned_short_fract_type_node
3584 : unsigned_short_fract_type_node
;
3585 if (mode
== TYPE_MODE (unsigned_fract_type_node
))
3586 return unsignedp
? sat_unsigned_fract_type_node
3587 : unsigned_fract_type_node
;
3588 if (mode
== TYPE_MODE (unsigned_long_fract_type_node
))
3589 return unsignedp
? sat_unsigned_long_fract_type_node
3590 : unsigned_long_fract_type_node
;
3591 if (mode
== TYPE_MODE (unsigned_long_long_fract_type_node
))
3592 return unsignedp
? sat_unsigned_long_long_fract_type_node
3593 : unsigned_long_long_fract_type_node
;
3595 if (mode
== TYPE_MODE (short_accum_type_node
))
3596 return unsignedp
? sat_short_accum_type_node
: short_accum_type_node
;
3597 if (mode
== TYPE_MODE (accum_type_node
))
3598 return unsignedp
? sat_accum_type_node
: accum_type_node
;
3599 if (mode
== TYPE_MODE (long_accum_type_node
))
3600 return unsignedp
? sat_long_accum_type_node
: long_accum_type_node
;
3601 if (mode
== TYPE_MODE (long_long_accum_type_node
))
3602 return unsignedp
? sat_long_long_accum_type_node
3603 : long_long_accum_type_node
;
3605 if (mode
== TYPE_MODE (unsigned_short_accum_type_node
))
3606 return unsignedp
? sat_unsigned_short_accum_type_node
3607 : unsigned_short_accum_type_node
;
3608 if (mode
== TYPE_MODE (unsigned_accum_type_node
))
3609 return unsignedp
? sat_unsigned_accum_type_node
3610 : unsigned_accum_type_node
;
3611 if (mode
== TYPE_MODE (unsigned_long_accum_type_node
))
3612 return unsignedp
? sat_unsigned_long_accum_type_node
3613 : unsigned_long_accum_type_node
;
3614 if (mode
== TYPE_MODE (unsigned_long_long_accum_type_node
))
3615 return unsignedp
? sat_unsigned_long_long_accum_type_node
3616 : unsigned_long_long_accum_type_node
;
3619 return unsignedp
? sat_qq_type_node
: qq_type_node
;
3621 return unsignedp
? sat_hq_type_node
: hq_type_node
;
3623 return unsignedp
? sat_sq_type_node
: sq_type_node
;
3625 return unsignedp
? sat_dq_type_node
: dq_type_node
;
3627 return unsignedp
? sat_tq_type_node
: tq_type_node
;
3629 if (mode
== UQQmode
)
3630 return unsignedp
? sat_uqq_type_node
: uqq_type_node
;
3631 if (mode
== UHQmode
)
3632 return unsignedp
? sat_uhq_type_node
: uhq_type_node
;
3633 if (mode
== USQmode
)
3634 return unsignedp
? sat_usq_type_node
: usq_type_node
;
3635 if (mode
== UDQmode
)
3636 return unsignedp
? sat_udq_type_node
: udq_type_node
;
3637 if (mode
== UTQmode
)
3638 return unsignedp
? sat_utq_type_node
: utq_type_node
;
3641 return unsignedp
? sat_ha_type_node
: ha_type_node
;
3643 return unsignedp
? sat_sa_type_node
: sa_type_node
;
3645 return unsignedp
? sat_da_type_node
: da_type_node
;
3647 return unsignedp
? sat_ta_type_node
: ta_type_node
;
3649 if (mode
== UHAmode
)
3650 return unsignedp
? sat_uha_type_node
: uha_type_node
;
3651 if (mode
== USAmode
)
3652 return unsignedp
? sat_usa_type_node
: usa_type_node
;
3653 if (mode
== UDAmode
)
3654 return unsignedp
? sat_uda_type_node
: uda_type_node
;
3655 if (mode
== UTAmode
)
3656 return unsignedp
? sat_uta_type_node
: uta_type_node
;
3659 for (t
= registered_builtin_types
; t
; t
= TREE_CHAIN (t
))
3660 if (TYPE_MODE (TREE_VALUE (t
)) == mode
3661 && !!unsignedp
== !!TYPE_UNSIGNED (TREE_VALUE (t
)))
3662 return TREE_VALUE (t
);
3668 c_common_unsigned_type (tree type
)
3670 return c_common_signed_or_unsigned_type (1, type
);
3673 /* Return a signed type the same as TYPE in other respects. */
3676 c_common_signed_type (tree type
)
3678 return c_common_signed_or_unsigned_type (0, type
);
3681 /* Return a type the same as TYPE except unsigned or
3682 signed according to UNSIGNEDP. */
3685 c_common_signed_or_unsigned_type (int unsignedp
, tree type
)
3689 /* This block of code emulates the behavior of the old
3690 c_common_unsigned_type. In particular, it returns
3691 long_unsigned_type_node if passed a long, even when a int would
3692 have the same size. This is necessary for warnings to work
3693 correctly in archs where sizeof(int) == sizeof(long) */
3695 type1
= TYPE_MAIN_VARIANT (type
);
3696 if (type1
== signed_char_type_node
|| type1
== char_type_node
|| type1
== unsigned_char_type_node
)
3697 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3698 if (type1
== integer_type_node
|| type1
== unsigned_type_node
)
3699 return unsignedp
? unsigned_type_node
: integer_type_node
;
3700 if (type1
== short_integer_type_node
|| type1
== short_unsigned_type_node
)
3701 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3702 if (type1
== long_integer_type_node
|| type1
== long_unsigned_type_node
)
3703 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3704 if (type1
== long_long_integer_type_node
|| type1
== long_long_unsigned_type_node
)
3705 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3706 if (int128_integer_type_node
3707 && (type1
== int128_integer_type_node
3708 || type1
== int128_unsigned_type_node
))
3709 return unsignedp
? int128_unsigned_type_node
: int128_integer_type_node
;
3710 if (type1
== widest_integer_literal_type_node
|| type1
== widest_unsigned_literal_type_node
)
3711 return unsignedp
? widest_unsigned_literal_type_node
: widest_integer_literal_type_node
;
3712 #if HOST_BITS_PER_WIDE_INT >= 64
3713 if (type1
== intTI_type_node
|| type1
== unsigned_intTI_type_node
)
3714 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3716 if (type1
== intDI_type_node
|| type1
== unsigned_intDI_type_node
)
3717 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3718 if (type1
== intSI_type_node
|| type1
== unsigned_intSI_type_node
)
3719 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3720 if (type1
== intHI_type_node
|| type1
== unsigned_intHI_type_node
)
3721 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3722 if (type1
== intQI_type_node
|| type1
== unsigned_intQI_type_node
)
3723 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3725 #define C_COMMON_FIXED_TYPES(NAME) \
3726 if (type1 == short_ ## NAME ## _type_node \
3727 || type1 == unsigned_short_ ## NAME ## _type_node) \
3728 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
3729 : short_ ## NAME ## _type_node; \
3730 if (type1 == NAME ## _type_node \
3731 || type1 == unsigned_ ## NAME ## _type_node) \
3732 return unsignedp ? unsigned_ ## NAME ## _type_node \
3733 : NAME ## _type_node; \
3734 if (type1 == long_ ## NAME ## _type_node \
3735 || type1 == unsigned_long_ ## NAME ## _type_node) \
3736 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
3737 : long_ ## NAME ## _type_node; \
3738 if (type1 == long_long_ ## NAME ## _type_node \
3739 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
3740 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
3741 : long_long_ ## NAME ## _type_node;
3743 #define C_COMMON_FIXED_MODE_TYPES(NAME) \
3744 if (type1 == NAME ## _type_node \
3745 || type1 == u ## NAME ## _type_node) \
3746 return unsignedp ? u ## NAME ## _type_node \
3747 : NAME ## _type_node;
3749 #define C_COMMON_FIXED_TYPES_SAT(NAME) \
3750 if (type1 == sat_ ## short_ ## NAME ## _type_node \
3751 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
3752 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
3753 : sat_ ## short_ ## NAME ## _type_node; \
3754 if (type1 == sat_ ## NAME ## _type_node \
3755 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
3756 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
3757 : sat_ ## NAME ## _type_node; \
3758 if (type1 == sat_ ## long_ ## NAME ## _type_node \
3759 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
3760 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
3761 : sat_ ## long_ ## NAME ## _type_node; \
3762 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
3763 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
3764 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
3765 : sat_ ## long_long_ ## NAME ## _type_node;
3767 #define C_COMMON_FIXED_MODE_TYPES_SAT(NAME) \
3768 if (type1 == sat_ ## NAME ## _type_node \
3769 || type1 == sat_ ## u ## NAME ## _type_node) \
3770 return unsignedp ? sat_ ## u ## NAME ## _type_node \
3771 : sat_ ## NAME ## _type_node;
3773 C_COMMON_FIXED_TYPES (fract
);
3774 C_COMMON_FIXED_TYPES_SAT (fract
);
3775 C_COMMON_FIXED_TYPES (accum
);
3776 C_COMMON_FIXED_TYPES_SAT (accum
);
3778 C_COMMON_FIXED_MODE_TYPES (qq
);
3779 C_COMMON_FIXED_MODE_TYPES (hq
);
3780 C_COMMON_FIXED_MODE_TYPES (sq
);
3781 C_COMMON_FIXED_MODE_TYPES (dq
);
3782 C_COMMON_FIXED_MODE_TYPES (tq
);
3783 C_COMMON_FIXED_MODE_TYPES_SAT (qq
);
3784 C_COMMON_FIXED_MODE_TYPES_SAT (hq
);
3785 C_COMMON_FIXED_MODE_TYPES_SAT (sq
);
3786 C_COMMON_FIXED_MODE_TYPES_SAT (dq
);
3787 C_COMMON_FIXED_MODE_TYPES_SAT (tq
);
3788 C_COMMON_FIXED_MODE_TYPES (ha
);
3789 C_COMMON_FIXED_MODE_TYPES (sa
);
3790 C_COMMON_FIXED_MODE_TYPES (da
);
3791 C_COMMON_FIXED_MODE_TYPES (ta
);
3792 C_COMMON_FIXED_MODE_TYPES_SAT (ha
);
3793 C_COMMON_FIXED_MODE_TYPES_SAT (sa
);
3794 C_COMMON_FIXED_MODE_TYPES_SAT (da
);
3795 C_COMMON_FIXED_MODE_TYPES_SAT (ta
);
3797 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
3798 the precision; they have precision set to match their range, but
3799 may use a wider mode to match an ABI. If we change modes, we may
3800 wind up with bad conversions. For INTEGER_TYPEs in C, must check
3801 the precision as well, so as to yield correct results for
3802 bit-field types. C++ does not have these separate bit-field
3803 types, and producing a signed or unsigned variant of an
3804 ENUMERAL_TYPE may cause other problems as well. */
3806 if (!INTEGRAL_TYPE_P (type
)
3807 || TYPE_UNSIGNED (type
) == unsignedp
)
3810 #define TYPE_OK(node) \
3811 (TYPE_MODE (type) == TYPE_MODE (node) \
3812 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
3813 if (TYPE_OK (signed_char_type_node
))
3814 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3815 if (TYPE_OK (integer_type_node
))
3816 return unsignedp
? unsigned_type_node
: integer_type_node
;
3817 if (TYPE_OK (short_integer_type_node
))
3818 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3819 if (TYPE_OK (long_integer_type_node
))
3820 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3821 if (TYPE_OK (long_long_integer_type_node
))
3822 return (unsignedp
? long_long_unsigned_type_node
3823 : long_long_integer_type_node
);
3824 if (int128_integer_type_node
&& TYPE_OK (int128_integer_type_node
))
3825 return (unsignedp
? int128_unsigned_type_node
3826 : int128_integer_type_node
);
3827 if (TYPE_OK (widest_integer_literal_type_node
))
3828 return (unsignedp
? widest_unsigned_literal_type_node
3829 : widest_integer_literal_type_node
);
3831 #if HOST_BITS_PER_WIDE_INT >= 64
3832 if (TYPE_OK (intTI_type_node
))
3833 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3835 if (TYPE_OK (intDI_type_node
))
3836 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3837 if (TYPE_OK (intSI_type_node
))
3838 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3839 if (TYPE_OK (intHI_type_node
))
3840 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3841 if (TYPE_OK (intQI_type_node
))
3842 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3845 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
3848 /* Build a bit-field integer type for the given WIDTH and UNSIGNEDP. */
3851 c_build_bitfield_integer_type (unsigned HOST_WIDE_INT width
, int unsignedp
)
3853 /* Extended integer types of the same width as a standard type have
3854 lesser rank, so those of the same width as int promote to int or
3855 unsigned int and are valid for printf formats expecting int or
3856 unsigned int. To avoid such special cases, avoid creating
3857 extended integer types for bit-fields if a standard integer type
3859 if (width
== TYPE_PRECISION (integer_type_node
))
3860 return unsignedp
? unsigned_type_node
: integer_type_node
;
3861 if (width
== TYPE_PRECISION (signed_char_type_node
))
3862 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3863 if (width
== TYPE_PRECISION (short_integer_type_node
))
3864 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3865 if (width
== TYPE_PRECISION (long_integer_type_node
))
3866 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3867 if (width
== TYPE_PRECISION (long_long_integer_type_node
))
3868 return (unsignedp
? long_long_unsigned_type_node
3869 : long_long_integer_type_node
);
3870 if (int128_integer_type_node
3871 && width
== TYPE_PRECISION (int128_integer_type_node
))
3872 return (unsignedp
? int128_unsigned_type_node
3873 : int128_integer_type_node
);
3874 return build_nonstandard_integer_type (width
, unsignedp
);
3877 /* The C version of the register_builtin_type langhook. */
3880 c_register_builtin_type (tree type
, const char* name
)
3884 decl
= build_decl (UNKNOWN_LOCATION
,
3885 TYPE_DECL
, get_identifier (name
), type
);
3886 DECL_ARTIFICIAL (decl
) = 1;
3887 if (!TYPE_NAME (type
))
3888 TYPE_NAME (type
) = decl
;
3891 registered_builtin_types
= tree_cons (0, type
, registered_builtin_types
);
3894 /* Print an error message for invalid operands to arith operation
3895 CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
3896 LOCATION is the location of the message. */
3899 binary_op_error (location_t location
, enum tree_code code
,
3900 tree type0
, tree type1
)
3907 opname
= "+"; break;
3909 opname
= "-"; break;
3911 opname
= "*"; break;
3913 opname
= "max"; break;
3915 opname
= "min"; break;
3917 opname
= "=="; break;
3919 opname
= "!="; break;
3921 opname
= "<="; break;
3923 opname
= ">="; break;
3925 opname
= "<"; break;
3927 opname
= ">"; break;
3929 opname
= "<<"; break;
3931 opname
= ">>"; break;
3932 case TRUNC_MOD_EXPR
:
3933 case FLOOR_MOD_EXPR
:
3934 opname
= "%"; break;
3935 case TRUNC_DIV_EXPR
:
3936 case FLOOR_DIV_EXPR
:
3937 opname
= "/"; break;
3939 opname
= "&"; break;
3941 opname
= "|"; break;
3942 case TRUTH_ANDIF_EXPR
:
3943 opname
= "&&"; break;
3944 case TRUTH_ORIF_EXPR
:
3945 opname
= "||"; break;
3947 opname
= "^"; break;
3952 "invalid operands to binary %s (have %qT and %qT)", opname
,
3956 /* Given an expression as a tree, return its original type. Do this
3957 by stripping any conversion that preserves the sign and precision. */
3959 expr_original_type (tree expr
)
3961 STRIP_SIGN_NOPS (expr
);
3962 return TREE_TYPE (expr
);
3965 /* Subroutine of build_binary_op, used for comparison operations.
3966 See if the operands have both been converted from subword integer types
3967 and, if so, perhaps change them both back to their original type.
3968 This function is also responsible for converting the two operands
3969 to the proper common type for comparison.
3971 The arguments of this function are all pointers to local variables
3972 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
3973 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
3975 If this function returns nonzero, it means that the comparison has
3976 a constant value. What this function returns is an expression for
3980 shorten_compare (tree
*op0_ptr
, tree
*op1_ptr
, tree
*restype_ptr
,
3981 enum tree_code
*rescode_ptr
)
3984 tree op0
= *op0_ptr
;
3985 tree op1
= *op1_ptr
;
3986 int unsignedp0
, unsignedp1
;
3988 tree primop0
, primop1
;
3989 enum tree_code code
= *rescode_ptr
;
3990 location_t loc
= EXPR_LOC_OR_LOC (op0
, input_location
);
3992 /* Throw away any conversions to wider types
3993 already present in the operands. */
3995 primop0
= c_common_get_narrower (op0
, &unsignedp0
);
3996 primop1
= c_common_get_narrower (op1
, &unsignedp1
);
3998 /* If primopN is first sign-extended from primopN's precision to opN's
3999 precision, then zero-extended from opN's precision to
4000 *restype_ptr precision, shortenings might be invalid. */
4001 if (TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (TREE_TYPE (op0
))
4002 && TYPE_PRECISION (TREE_TYPE (op0
)) < TYPE_PRECISION (*restype_ptr
)
4004 && TYPE_UNSIGNED (TREE_TYPE (op0
)))
4006 if (TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (TREE_TYPE (op1
))
4007 && TYPE_PRECISION (TREE_TYPE (op1
)) < TYPE_PRECISION (*restype_ptr
)
4009 && TYPE_UNSIGNED (TREE_TYPE (op1
)))
4012 /* Handle the case that OP0 does not *contain* a conversion
4013 but it *requires* conversion to FINAL_TYPE. */
4015 if (op0
== primop0
&& TREE_TYPE (op0
) != *restype_ptr
)
4016 unsignedp0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
4017 if (op1
== primop1
&& TREE_TYPE (op1
) != *restype_ptr
)
4018 unsignedp1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
4020 /* If one of the operands must be floated, we cannot optimize. */
4021 real1
= TREE_CODE (TREE_TYPE (primop0
)) == REAL_TYPE
;
4022 real2
= TREE_CODE (TREE_TYPE (primop1
)) == REAL_TYPE
;
4024 /* If first arg is constant, swap the args (changing operation
4025 so value is preserved), for canonicalization. Don't do this if
4026 the second arg is 0. */
4028 if (TREE_CONSTANT (primop0
)
4029 && !integer_zerop (primop1
) && !real_zerop (primop1
)
4030 && !fixed_zerop (primop1
))
4033 int temi
= unsignedp0
;
4041 unsignedp0
= unsignedp1
;
4064 *rescode_ptr
= code
;
4067 /* If comparing an integer against a constant more bits wide,
4068 maybe we can deduce a value of 1 or 0 independent of the data.
4069 Or else truncate the constant now
4070 rather than extend the variable at run time.
4072 This is only interesting if the constant is the wider arg.
4073 Also, it is not safe if the constant is unsigned and the
4074 variable arg is signed, since in this case the variable
4075 would be sign-extended and then regarded as unsigned.
4076 Our technique fails in this case because the lowest/highest
4077 possible unsigned results don't follow naturally from the
4078 lowest/highest possible values of the variable operand.
4079 For just EQ_EXPR and NE_EXPR there is another technique that
4080 could be used: see if the constant can be faithfully represented
4081 in the other operand's type, by truncating it and reextending it
4082 and see if that preserves the constant's value. */
4084 if (!real1
&& !real2
4085 && TREE_CODE (TREE_TYPE (primop0
)) != FIXED_POINT_TYPE
4086 && TREE_CODE (primop1
) == INTEGER_CST
4087 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
))
4089 int min_gt
, max_gt
, min_lt
, max_lt
;
4090 tree maxval
, minval
;
4091 /* 1 if comparison is nominally unsigned. */
4092 int unsignedp
= TYPE_UNSIGNED (*restype_ptr
);
4095 type
= c_common_signed_or_unsigned_type (unsignedp0
,
4096 TREE_TYPE (primop0
));
4098 maxval
= TYPE_MAX_VALUE (type
);
4099 minval
= TYPE_MIN_VALUE (type
);
4101 if (unsignedp
&& !unsignedp0
)
4102 *restype_ptr
= c_common_signed_type (*restype_ptr
);
4104 if (TREE_TYPE (primop1
) != *restype_ptr
)
4106 /* Convert primop1 to target type, but do not introduce
4107 additional overflow. We know primop1 is an int_cst. */
4108 primop1
= force_fit_type_double (*restype_ptr
,
4109 tree_to_double_int (primop1
),
4110 0, TREE_OVERFLOW (primop1
));
4112 if (type
!= *restype_ptr
)
4114 minval
= convert (*restype_ptr
, minval
);
4115 maxval
= convert (*restype_ptr
, maxval
);
4118 if (unsignedp
&& unsignedp0
)
4120 min_gt
= INT_CST_LT_UNSIGNED (primop1
, minval
);
4121 max_gt
= INT_CST_LT_UNSIGNED (primop1
, maxval
);
4122 min_lt
= INT_CST_LT_UNSIGNED (minval
, primop1
);
4123 max_lt
= INT_CST_LT_UNSIGNED (maxval
, primop1
);
4127 min_gt
= INT_CST_LT (primop1
, minval
);
4128 max_gt
= INT_CST_LT (primop1
, maxval
);
4129 min_lt
= INT_CST_LT (minval
, primop1
);
4130 max_lt
= INT_CST_LT (maxval
, primop1
);
4134 /* This used to be a switch, but Genix compiler can't handle that. */
4135 if (code
== NE_EXPR
)
4137 if (max_lt
|| min_gt
)
4138 val
= truthvalue_true_node
;
4140 else if (code
== EQ_EXPR
)
4142 if (max_lt
|| min_gt
)
4143 val
= truthvalue_false_node
;
4145 else if (code
== LT_EXPR
)
4148 val
= truthvalue_true_node
;
4150 val
= truthvalue_false_node
;
4152 else if (code
== GT_EXPR
)
4155 val
= truthvalue_true_node
;
4157 val
= truthvalue_false_node
;
4159 else if (code
== LE_EXPR
)
4162 val
= truthvalue_true_node
;
4164 val
= truthvalue_false_node
;
4166 else if (code
== GE_EXPR
)
4169 val
= truthvalue_true_node
;
4171 val
= truthvalue_false_node
;
4174 /* If primop0 was sign-extended and unsigned comparison specd,
4175 we did a signed comparison above using the signed type bounds.
4176 But the comparison we output must be unsigned.
4178 Also, for inequalities, VAL is no good; but if the signed
4179 comparison had *any* fixed result, it follows that the
4180 unsigned comparison just tests the sign in reverse
4181 (positive values are LE, negative ones GE).
4182 So we can generate an unsigned comparison
4183 against an extreme value of the signed type. */
4185 if (unsignedp
&& !unsignedp0
)
4192 primop1
= TYPE_MIN_VALUE (type
);
4198 primop1
= TYPE_MAX_VALUE (type
);
4205 type
= c_common_unsigned_type (type
);
4208 if (TREE_CODE (primop0
) != INTEGER_CST
4209 && c_inhibit_evaluation_warnings
== 0)
4211 if (val
== truthvalue_false_node
)
4212 warning_at (loc
, OPT_Wtype_limits
,
4213 "comparison is always false due to limited range of data type");
4214 if (val
== truthvalue_true_node
)
4215 warning_at (loc
, OPT_Wtype_limits
,
4216 "comparison is always true due to limited range of data type");
4221 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4222 if (TREE_SIDE_EFFECTS (primop0
))
4223 return build2 (COMPOUND_EXPR
, TREE_TYPE (val
), primop0
, val
);
4227 /* Value is not predetermined, but do the comparison
4228 in the type of the operand that is not constant.
4229 TYPE is already properly set. */
4232 /* If either arg is decimal float and the other is float, find the
4233 proper common type to use for comparison. */
4234 else if (real1
&& real2
4235 && (DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0
)))
4236 || DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1
)))))
4237 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
4239 else if (real1
&& real2
4240 && (TYPE_PRECISION (TREE_TYPE (primop0
))
4241 == TYPE_PRECISION (TREE_TYPE (primop1
))))
4242 type
= TREE_TYPE (primop0
);
4244 /* If args' natural types are both narrower than nominal type
4245 and both extend in the same manner, compare them
4246 in the type of the wider arg.
4247 Otherwise must actually extend both to the nominal
4248 common type lest different ways of extending
4250 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
4252 else if (unsignedp0
== unsignedp1
&& real1
== real2
4253 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
)
4254 && TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (*restype_ptr
))
4256 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
4257 type
= c_common_signed_or_unsigned_type (unsignedp0
4258 || TYPE_UNSIGNED (*restype_ptr
),
4260 /* Make sure shorter operand is extended the right way
4261 to match the longer operand. */
4263 = convert (c_common_signed_or_unsigned_type (unsignedp0
,
4264 TREE_TYPE (primop0
)),
4267 = convert (c_common_signed_or_unsigned_type (unsignedp1
,
4268 TREE_TYPE (primop1
)),
4273 /* Here we must do the comparison on the nominal type
4274 using the args exactly as we received them. */
4275 type
= *restype_ptr
;
4279 if (!real1
&& !real2
&& integer_zerop (primop1
)
4280 && TYPE_UNSIGNED (*restype_ptr
))
4283 /* All unsigned values are >= 0, so we warn. However,
4284 if OP0 is a constant that is >= 0, the signedness of
4285 the comparison isn't an issue, so suppress the
4288 warn_type_limits
&& !in_system_header_at (loc
)
4289 && c_inhibit_evaluation_warnings
== 0
4290 && !(TREE_CODE (primop0
) == INTEGER_CST
4291 && !TREE_OVERFLOW (convert (c_common_signed_type (type
),
4293 /* Do not warn for enumeration types. */
4294 && (TREE_CODE (expr_original_type (primop0
)) != ENUMERAL_TYPE
);
4300 warning_at (loc
, OPT_Wtype_limits
,
4301 "comparison of unsigned expression >= 0 is always true");
4302 value
= truthvalue_true_node
;
4307 warning_at (loc
, OPT_Wtype_limits
,
4308 "comparison of unsigned expression < 0 is always false");
4309 value
= truthvalue_false_node
;
4318 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4319 if (TREE_SIDE_EFFECTS (primop0
))
4320 return build2 (COMPOUND_EXPR
, TREE_TYPE (value
),
4327 *op0_ptr
= convert (type
, primop0
);
4328 *op1_ptr
= convert (type
, primop1
);
4330 *restype_ptr
= truthvalue_type_node
;
4335 /* Return a tree for the sum or difference (RESULTCODE says which)
4336 of pointer PTROP and integer INTOP. */
4339 pointer_int_sum (location_t loc
, enum tree_code resultcode
,
4340 tree ptrop
, tree intop
, bool complain
)
4344 /* The result is a pointer of the same type that is being added. */
4345 tree result_type
= TREE_TYPE (ptrop
);
4347 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
4349 if (complain
&& warn_pointer_arith
)
4350 pedwarn (loc
, OPT_Wpointer_arith
,
4351 "pointer of type %<void *%> used in arithmetic");
4353 return error_mark_node
;
4354 size_exp
= integer_one_node
;
4356 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
4358 if (complain
&& warn_pointer_arith
)
4359 pedwarn (loc
, OPT_Wpointer_arith
,
4360 "pointer to a function used in arithmetic");
4362 return error_mark_node
;
4363 size_exp
= integer_one_node
;
4366 size_exp
= size_in_bytes (TREE_TYPE (result_type
));
4368 /* We are manipulating pointer values, so we don't need to warn
4369 about relying on undefined signed overflow. We disable the
4370 warning here because we use integer types so fold won't know that
4371 they are really pointers. */
4372 fold_defer_overflow_warnings ();
4374 /* If what we are about to multiply by the size of the elements
4375 contains a constant term, apply distributive law
4376 and multiply that constant term separately.
4377 This helps produce common subexpressions. */
4378 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
4379 && !TREE_CONSTANT (intop
)
4380 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
4381 && TREE_CONSTANT (size_exp
)
4382 /* If the constant comes from pointer subtraction,
4383 skip this optimization--it would cause an error. */
4384 && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop
, 0))) == INTEGER_TYPE
4385 /* If the constant is unsigned, and smaller than the pointer size,
4386 then we must skip this optimization. This is because it could cause
4387 an overflow error if the constant is negative but INTOP is not. */
4388 && (!TYPE_UNSIGNED (TREE_TYPE (intop
))
4389 || (TYPE_PRECISION (TREE_TYPE (intop
))
4390 == TYPE_PRECISION (TREE_TYPE (ptrop
)))))
4392 enum tree_code subcode
= resultcode
;
4393 tree int_type
= TREE_TYPE (intop
);
4394 if (TREE_CODE (intop
) == MINUS_EXPR
)
4395 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
4396 /* Convert both subexpression types to the type of intop,
4397 because weird cases involving pointer arithmetic
4398 can result in a sum or difference with different type args. */
4399 ptrop
= build_binary_op (EXPR_LOCATION (TREE_OPERAND (intop
, 1)),
4401 convert (int_type
, TREE_OPERAND (intop
, 1)), 1);
4402 intop
= convert (int_type
, TREE_OPERAND (intop
, 0));
4405 /* Convert the integer argument to a type the same size as sizetype
4406 so the multiply won't overflow spuriously. */
4407 if (TYPE_PRECISION (TREE_TYPE (intop
)) != TYPE_PRECISION (sizetype
)
4408 || TYPE_UNSIGNED (TREE_TYPE (intop
)) != TYPE_UNSIGNED (sizetype
))
4409 intop
= convert (c_common_type_for_size (TYPE_PRECISION (sizetype
),
4410 TYPE_UNSIGNED (sizetype
)), intop
);
4412 /* Replace the integer argument with a suitable product by the object size.
4413 Do this multiplication as signed, then convert to the appropriate type
4414 for the pointer operation and disregard an overflow that occurred only
4415 because of the sign-extension change in the latter conversion. */
4417 tree t
= build_binary_op (loc
,
4419 convert (TREE_TYPE (intop
), size_exp
), 1);
4420 intop
= convert (sizetype
, t
);
4421 if (TREE_OVERFLOW_P (intop
) && !TREE_OVERFLOW (t
))
4422 intop
= build_int_cst_wide (TREE_TYPE (intop
), TREE_INT_CST_LOW (intop
),
4423 TREE_INT_CST_HIGH (intop
));
4426 /* Create the sum or difference. */
4427 if (resultcode
== MINUS_EXPR
)
4428 intop
= fold_build1_loc (loc
, NEGATE_EXPR
, sizetype
, intop
);
4430 ret
= fold_build_pointer_plus_loc (loc
, ptrop
, intop
);
4432 fold_undefer_and_ignore_overflow_warnings ();
4437 /* Wrap a C_MAYBE_CONST_EXPR around an expression that is fully folded
4438 and if NON_CONST is known not to be permitted in an evaluated part
4439 of a constant expression. */
4442 c_wrap_maybe_const (tree expr
, bool non_const
)
4444 bool nowarning
= TREE_NO_WARNING (expr
);
4445 location_t loc
= EXPR_LOCATION (expr
);
4447 /* This should never be called for C++. */
4448 if (c_dialect_cxx ())
4451 /* The result of folding may have a NOP_EXPR to set TREE_NO_WARNING. */
4452 STRIP_TYPE_NOPS (expr
);
4453 expr
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (expr
), NULL
, expr
);
4454 C_MAYBE_CONST_EXPR_NON_CONST (expr
) = non_const
;
4456 TREE_NO_WARNING (expr
) = 1;
4457 protected_set_expr_location (expr
, loc
);
4462 /* Wrap a SAVE_EXPR around EXPR, if appropriate. Like save_expr, but
4463 for C folds the inside expression and wraps a C_MAYBE_CONST_EXPR
4464 around the SAVE_EXPR if needed so that c_fully_fold does not need
4465 to look inside SAVE_EXPRs. */
4468 c_save_expr (tree expr
)
4470 bool maybe_const
= true;
4471 if (c_dialect_cxx ())
4472 return save_expr (expr
);
4473 expr
= c_fully_fold (expr
, false, &maybe_const
);
4474 expr
= save_expr (expr
);
4476 expr
= c_wrap_maybe_const (expr
, true);
4480 /* Return whether EXPR is a declaration whose address can never be
4484 decl_with_nonnull_addr_p (const_tree expr
)
4486 return (DECL_P (expr
)
4487 && (TREE_CODE (expr
) == PARM_DECL
4488 || TREE_CODE (expr
) == LABEL_DECL
4489 || !DECL_WEAK (expr
)));
4492 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
4493 or for an `if' or `while' statement or ?..: exp. It should already
4494 have been validated to be of suitable type; otherwise, a bad
4495 diagnostic may result.
4497 The EXPR is located at LOCATION.
4499 This preparation consists of taking the ordinary
4500 representation of an expression expr and producing a valid tree
4501 boolean expression describing whether expr is nonzero. We could
4502 simply always do build_binary_op (NE_EXPR, expr, truthvalue_false_node, 1),
4503 but we optimize comparisons, &&, ||, and !.
4505 The resulting type should always be `truthvalue_type_node'. */
4508 c_common_truthvalue_conversion (location_t location
, tree expr
)
4510 switch (TREE_CODE (expr
))
4512 case EQ_EXPR
: case NE_EXPR
: case UNEQ_EXPR
: case LTGT_EXPR
:
4513 case LE_EXPR
: case GE_EXPR
: case LT_EXPR
: case GT_EXPR
:
4514 case UNLE_EXPR
: case UNGE_EXPR
: case UNLT_EXPR
: case UNGT_EXPR
:
4515 case ORDERED_EXPR
: case UNORDERED_EXPR
:
4516 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4518 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4519 TREE_OPERAND (expr
, 0), TREE_OPERAND (expr
, 1));
4522 case TRUTH_ANDIF_EXPR
:
4523 case TRUTH_ORIF_EXPR
:
4524 case TRUTH_AND_EXPR
:
4526 case TRUTH_XOR_EXPR
:
4527 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4529 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4530 c_common_truthvalue_conversion (location
,
4531 TREE_OPERAND (expr
, 0)),
4532 c_common_truthvalue_conversion (location
,
4533 TREE_OPERAND (expr
, 1)));
4536 case TRUTH_NOT_EXPR
:
4537 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4539 expr
= build1 (TREE_CODE (expr
), truthvalue_type_node
,
4540 c_common_truthvalue_conversion (location
,
4541 TREE_OPERAND (expr
, 0)));
4548 return integer_zerop (expr
) ? truthvalue_false_node
4549 : truthvalue_true_node
;
4552 return real_compare (NE_EXPR
, &TREE_REAL_CST (expr
), &dconst0
)
4553 ? truthvalue_true_node
4554 : truthvalue_false_node
;
4557 return fixed_compare (NE_EXPR
, &TREE_FIXED_CST (expr
),
4558 &FCONST0 (TYPE_MODE (TREE_TYPE (expr
))))
4559 ? truthvalue_true_node
4560 : truthvalue_false_node
;
4563 expr
= build_unary_op (location
, ADDR_EXPR
, expr
, 0);
4568 tree inner
= TREE_OPERAND (expr
, 0);
4569 if (decl_with_nonnull_addr_p (inner
))
4571 /* Common Ada/Pascal programmer's mistake. */
4572 warning_at (location
,
4574 "the address of %qD will always evaluate as %<true%>",
4576 return truthvalue_true_node
;
4582 expr
= build_binary_op (EXPR_LOCATION (expr
),
4583 (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1))
4584 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4585 c_common_truthvalue_conversion (location
,
4586 TREE_OPERAND (expr
, 0)),
4587 c_common_truthvalue_conversion (location
,
4588 TREE_OPERAND (expr
, 1)),
4595 case EXCESS_PRECISION_EXPR
:
4596 /* These don't change whether an object is nonzero or zero. */
4597 return c_common_truthvalue_conversion (location
, TREE_OPERAND (expr
, 0));
4601 /* These don't change whether an object is zero or nonzero, but
4602 we can't ignore them if their second arg has side-effects. */
4603 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1)))
4605 expr
= build2 (COMPOUND_EXPR
, truthvalue_type_node
,
4606 TREE_OPERAND (expr
, 1),
4607 c_common_truthvalue_conversion
4608 (location
, TREE_OPERAND (expr
, 0)));
4612 return c_common_truthvalue_conversion (location
,
4613 TREE_OPERAND (expr
, 0));
4616 /* Distribute the conversion into the arms of a COND_EXPR. */
4617 if (c_dialect_cxx ())
4619 tree op1
= TREE_OPERAND (expr
, 1);
4620 tree op2
= TREE_OPERAND (expr
, 2);
4621 /* In C++ one of the arms might have void type if it is throw. */
4622 if (!VOID_TYPE_P (TREE_TYPE (op1
)))
4623 op1
= c_common_truthvalue_conversion (location
, op1
);
4624 if (!VOID_TYPE_P (TREE_TYPE (op2
)))
4625 op2
= c_common_truthvalue_conversion (location
, op2
);
4626 expr
= fold_build3_loc (location
, COND_EXPR
, truthvalue_type_node
,
4627 TREE_OPERAND (expr
, 0), op1
, op2
);
4632 /* Folding will happen later for C. */
4633 expr
= build3 (COND_EXPR
, truthvalue_type_node
,
4634 TREE_OPERAND (expr
, 0),
4635 c_common_truthvalue_conversion (location
,
4636 TREE_OPERAND (expr
, 1)),
4637 c_common_truthvalue_conversion (location
,
4638 TREE_OPERAND (expr
, 2)));
4644 tree totype
= TREE_TYPE (expr
);
4645 tree fromtype
= TREE_TYPE (TREE_OPERAND (expr
, 0));
4647 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
4648 since that affects how `default_conversion' will behave. */
4649 if (TREE_CODE (totype
) == REFERENCE_TYPE
4650 || TREE_CODE (fromtype
) == REFERENCE_TYPE
)
4652 /* Don't strip a conversion from C++0x scoped enum, since they
4653 don't implicitly convert to other types. */
4654 if (TREE_CODE (fromtype
) == ENUMERAL_TYPE
4655 && ENUM_IS_SCOPED (fromtype
))
4657 /* If this isn't narrowing the argument, we can ignore it. */
4658 if (TYPE_PRECISION (totype
) >= TYPE_PRECISION (fromtype
))
4659 return c_common_truthvalue_conversion (location
,
4660 TREE_OPERAND (expr
, 0));
4665 if (!TREE_NO_WARNING (expr
)
4666 && warn_parentheses
)
4668 warning (OPT_Wparentheses
,
4669 "suggest parentheses around assignment used as truth value");
4670 TREE_NO_WARNING (expr
) = 1;
4678 if (TREE_CODE (TREE_TYPE (expr
)) == COMPLEX_TYPE
)
4680 tree t
= (in_late_binary_op
? save_expr (expr
) : c_save_expr (expr
));
4681 expr
= (build_binary_op
4682 (EXPR_LOCATION (expr
),
4683 (TREE_SIDE_EFFECTS (expr
)
4684 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4685 c_common_truthvalue_conversion
4687 build_unary_op (location
, REALPART_EXPR
, t
, 0)),
4688 c_common_truthvalue_conversion
4690 build_unary_op (location
, IMAGPART_EXPR
, t
, 0)),
4695 if (TREE_CODE (TREE_TYPE (expr
)) == FIXED_POINT_TYPE
)
4697 tree fixed_zero_node
= build_fixed (TREE_TYPE (expr
),
4699 (TREE_TYPE (expr
))));
4700 return build_binary_op (location
, NE_EXPR
, expr
, fixed_zero_node
, 1);
4703 return build_binary_op (location
, NE_EXPR
, expr
, integer_zero_node
, 1);
4706 protected_set_expr_location (expr
, location
);
4710 static void def_builtin_1 (enum built_in_function fncode
,
4712 enum built_in_class fnclass
,
4713 tree fntype
, tree libtype
,
4714 bool both_p
, bool fallback_p
, bool nonansi_p
,
4715 tree fnattrs
, bool implicit_p
);
4718 /* Apply the TYPE_QUALS to the new DECL. */
4721 c_apply_type_quals_to_decl (int type_quals
, tree decl
)
4723 tree type
= TREE_TYPE (decl
);
4725 if (type
== error_mark_node
)
4728 if ((type_quals
& TYPE_QUAL_CONST
)
4729 || (type
&& TREE_CODE (type
) == REFERENCE_TYPE
))
4730 /* We used to check TYPE_NEEDS_CONSTRUCTING here, but now a constexpr
4731 constructor can produce constant init, so rely on cp_finish_decl to
4732 clear TREE_READONLY if the variable has non-constant init. */
4733 TREE_READONLY (decl
) = 1;
4734 if (type_quals
& TYPE_QUAL_VOLATILE
)
4736 TREE_SIDE_EFFECTS (decl
) = 1;
4737 TREE_THIS_VOLATILE (decl
) = 1;
4739 if (type_quals
& TYPE_QUAL_RESTRICT
)
4741 while (type
&& TREE_CODE (type
) == ARRAY_TYPE
)
4742 /* Allow 'restrict' on arrays of pointers.
4743 FIXME currently we just ignore it. */
4744 type
= TREE_TYPE (type
);
4746 || !POINTER_TYPE_P (type
)
4747 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type
)))
4748 error ("invalid use of %<restrict%>");
4752 /* Hash function for the problem of multiple type definitions in
4753 different files. This must hash all types that will compare
4754 equal via comptypes to the same value. In practice it hashes
4755 on some of the simple stuff and leaves the details to comptypes. */
4758 c_type_hash (const void *p
)
4762 const_tree
const t
= (const_tree
) p
;
4764 switch (TREE_CODE (t
))
4766 /* For pointers, hash on pointee type plus some swizzling. */
4768 return c_type_hash (TREE_TYPE (t
)) ^ 0x3003003;
4769 /* Hash on number of elements and total size. */
4772 t2
= TYPE_VALUES (t
);
4776 t2
= TYPE_FIELDS (t
);
4778 case QUAL_UNION_TYPE
:
4780 t2
= TYPE_FIELDS (t
);
4784 t2
= TYPE_FIELDS (t
);
4789 /* FIXME: We want to use a DECL_CHAIN iteration method here, but
4790 TYPE_VALUES of ENUMERAL_TYPEs is stored as a TREE_LIST. */
4791 n_elements
= list_length (t2
);
4792 /* We might have a VLA here. */
4793 if (TREE_CODE (TYPE_SIZE (t
)) != INTEGER_CST
)
4796 size
= TREE_INT_CST_LOW (TYPE_SIZE (t
));
4797 return ((size
<< 24) | (n_elements
<< shift
));
4800 static GTY((param_is (union tree_node
))) htab_t type_hash_table
;
4802 /* Return the typed-based alias set for T, which may be an expression
4803 or a type. Return -1 if we don't do anything special. */
4806 c_common_get_alias_set (tree t
)
4811 /* For VLAs, use the alias set of the element type rather than the
4812 default of alias set 0 for types compared structurally. */
4813 if (TYPE_P (t
) && TYPE_STRUCTURAL_EQUALITY_P (t
))
4815 if (TREE_CODE (t
) == ARRAY_TYPE
)
4816 return get_alias_set (TREE_TYPE (t
));
4820 /* Permit type-punning when accessing a union, provided the access
4821 is directly through the union. For example, this code does not
4822 permit taking the address of a union member and then storing
4823 through it. Even the type-punning allowed here is a GCC
4824 extension, albeit a common and useful one; the C standard says
4825 that such accesses have implementation-defined behavior. */
4827 TREE_CODE (u
) == COMPONENT_REF
|| TREE_CODE (u
) == ARRAY_REF
;
4828 u
= TREE_OPERAND (u
, 0))
4829 if (TREE_CODE (u
) == COMPONENT_REF
4830 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u
, 0))) == UNION_TYPE
)
4833 /* That's all the expressions we handle specially. */
4837 /* The C standard guarantees that any object may be accessed via an
4838 lvalue that has character type. */
4839 if (t
== char_type_node
4840 || t
== signed_char_type_node
4841 || t
== unsigned_char_type_node
)
4844 /* The C standard specifically allows aliasing between signed and
4845 unsigned variants of the same type. We treat the signed
4846 variant as canonical. */
4847 if (TREE_CODE (t
) == INTEGER_TYPE
&& TYPE_UNSIGNED (t
))
4849 tree t1
= c_common_signed_type (t
);
4851 /* t1 == t can happen for boolean nodes which are always unsigned. */
4853 return get_alias_set (t1
);
4856 /* Handle the case of multiple type nodes referring to "the same" type,
4857 which occurs with IMA. These share an alias set. FIXME: Currently only
4858 C90 is handled. (In C99 type compatibility is not transitive, which
4859 complicates things mightily. The alias set splay trees can theoretically
4860 represent this, but insertion is tricky when you consider all the
4861 different orders things might arrive in.) */
4863 if (c_language
!= clk_c
|| flag_isoc99
)
4866 /* Save time if there's only one input file. */
4867 if (num_in_fnames
== 1)
4870 /* Pointers need special handling if they point to any type that
4871 needs special handling (below). */
4872 if (TREE_CODE (t
) == POINTER_TYPE
)
4875 /* Find bottom type under any nested POINTERs. */
4876 for (t2
= TREE_TYPE (t
);
4877 TREE_CODE (t2
) == POINTER_TYPE
;
4878 t2
= TREE_TYPE (t2
))
4880 if (TREE_CODE (t2
) != RECORD_TYPE
4881 && TREE_CODE (t2
) != ENUMERAL_TYPE
4882 && TREE_CODE (t2
) != QUAL_UNION_TYPE
4883 && TREE_CODE (t2
) != UNION_TYPE
)
4885 if (TYPE_SIZE (t2
) == 0)
4888 /* These are the only cases that need special handling. */
4889 if (TREE_CODE (t
) != RECORD_TYPE
4890 && TREE_CODE (t
) != ENUMERAL_TYPE
4891 && TREE_CODE (t
) != QUAL_UNION_TYPE
4892 && TREE_CODE (t
) != UNION_TYPE
4893 && TREE_CODE (t
) != POINTER_TYPE
)
4896 if (TYPE_SIZE (t
) == 0)
4899 /* Look up t in hash table. Only one of the compatible types within each
4900 alias set is recorded in the table. */
4901 if (!type_hash_table
)
4902 type_hash_table
= htab_create_ggc (1021, c_type_hash
,
4903 (htab_eq
) lang_hooks
.types_compatible_p
,
4905 slot
= htab_find_slot (type_hash_table
, t
, INSERT
);
4908 TYPE_ALIAS_SET (t
) = TYPE_ALIAS_SET ((tree
)*slot
);
4909 return TYPE_ALIAS_SET ((tree
)*slot
);
4912 /* Our caller will assign and record (in t) a new alias set; all we need
4913 to do is remember t in the hash table. */
4919 /* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where
4920 the IS_SIZEOF parameter indicates which operator is being applied.
4921 The COMPLAIN flag controls whether we should diagnose possibly
4922 ill-formed constructs or not. LOC is the location of the SIZEOF or
4923 TYPEOF operator. If MIN_ALIGNOF, the least alignment required for
4924 a type in any context should be returned, rather than the normal
4925 alignment for that type. */
4928 c_sizeof_or_alignof_type (location_t loc
,
4929 tree type
, bool is_sizeof
, bool min_alignof
,
4932 const char *op_name
;
4934 enum tree_code type_code
= TREE_CODE (type
);
4936 op_name
= is_sizeof
? "sizeof" : "__alignof__";
4938 if (type_code
== FUNCTION_TYPE
)
4942 if (complain
&& warn_pointer_arith
)
4943 pedwarn (loc
, OPT_Wpointer_arith
,
4944 "invalid application of %<sizeof%> to a function type");
4946 return error_mark_node
;
4947 value
= size_one_node
;
4953 if (c_dialect_cxx ())
4954 pedwarn (loc
, OPT_Wpedantic
, "ISO C++ does not permit "
4955 "%<alignof%> applied to a function type");
4957 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not permit "
4958 "%<_Alignof%> applied to a function type");
4960 value
= size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
4963 else if (type_code
== VOID_TYPE
|| type_code
== ERROR_MARK
)
4965 if (type_code
== VOID_TYPE
4966 && complain
&& warn_pointer_arith
)
4967 pedwarn (loc
, OPT_Wpointer_arith
,
4968 "invalid application of %qs to a void type", op_name
);
4970 return error_mark_node
;
4971 value
= size_one_node
;
4973 else if (!COMPLETE_TYPE_P (type
)
4974 && (!c_dialect_cxx () || is_sizeof
|| type_code
!= ARRAY_TYPE
))
4977 error_at (loc
, "invalid application of %qs to incomplete type %qT",
4979 return error_mark_node
;
4981 else if (c_dialect_cxx () && type_code
== ARRAY_TYPE
4982 && !COMPLETE_TYPE_P (TREE_TYPE (type
)))
4985 error_at (loc
, "invalid application of %qs to array type %qT of "
4986 "incomplete element type", op_name
, type
);
4987 return error_mark_node
;
4992 /* Convert in case a char is more than one unit. */
4993 value
= size_binop_loc (loc
, CEIL_DIV_EXPR
, TYPE_SIZE_UNIT (type
),
4994 size_int (TYPE_PRECISION (char_type_node
)
4996 else if (min_alignof
)
4998 unsigned int align
= TYPE_ALIGN (type
);
4999 align
= MIN (align
, BIGGEST_ALIGNMENT
);
5000 #ifdef BIGGEST_FIELD_ALIGNMENT
5001 align
= MIN (align
, BIGGEST_FIELD_ALIGNMENT
);
5003 unsigned int field_align
= align
;
5004 #ifdef ADJUST_FIELD_ALIGN
5005 tree field
= build_decl (UNKNOWN_LOCATION
, FIELD_DECL
, NULL_TREE
,
5007 field_align
= ADJUST_FIELD_ALIGN (field
, field_align
);
5009 align
= MIN (align
, field_align
);
5010 value
= size_int (align
/ BITS_PER_UNIT
);
5013 value
= size_int (TYPE_ALIGN_UNIT (type
));
5016 /* VALUE will have the middle-end integer type sizetype.
5017 However, we should really return a value of type `size_t',
5018 which is just a typedef for an ordinary integer type. */
5019 value
= fold_convert_loc (loc
, size_type_node
, value
);
5024 /* Implement the __alignof keyword: Return the minimum required
5025 alignment of EXPR, measured in bytes. For VAR_DECLs,
5026 FUNCTION_DECLs and FIELD_DECLs return DECL_ALIGN (which can be set
5027 from an "aligned" __attribute__ specification). LOC is the
5028 location of the ALIGNOF operator. */
5031 c_alignof_expr (location_t loc
, tree expr
)
5035 if (VAR_OR_FUNCTION_DECL_P (expr
))
5036 t
= size_int (DECL_ALIGN_UNIT (expr
));
5038 else if (TREE_CODE (expr
) == COMPONENT_REF
5039 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
, 1)))
5041 error_at (loc
, "%<__alignof%> applied to a bit-field");
5044 else if (TREE_CODE (expr
) == COMPONENT_REF
5045 && TREE_CODE (TREE_OPERAND (expr
, 1)) == FIELD_DECL
)
5046 t
= size_int (DECL_ALIGN_UNIT (TREE_OPERAND (expr
, 1)));
5048 else if (TREE_CODE (expr
) == INDIRECT_REF
)
5050 tree t
= TREE_OPERAND (expr
, 0);
5052 int bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
5054 while (CONVERT_EXPR_P (t
)
5055 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
5059 t
= TREE_OPERAND (t
, 0);
5060 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
5061 if (thisalign
> bestalign
)
5062 best
= t
, bestalign
= thisalign
;
5064 return c_alignof (loc
, TREE_TYPE (TREE_TYPE (best
)));
5067 return c_alignof (loc
, TREE_TYPE (expr
));
5069 return fold_convert_loc (loc
, size_type_node
, t
);
5072 /* Handle C and C++ default attributes. */
5074 enum built_in_attribute
5076 #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
5077 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
5078 #define DEF_ATTR_STRING(ENUM, VALUE) ENUM,
5079 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
5080 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
5081 #include "builtin-attrs.def"
5082 #undef DEF_ATTR_NULL_TREE
5084 #undef DEF_ATTR_STRING
5085 #undef DEF_ATTR_IDENT
5086 #undef DEF_ATTR_TREE_LIST
5090 static GTY(()) tree built_in_attributes
[(int) ATTR_LAST
];
5092 static void c_init_attributes (void);
5096 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
5097 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
5098 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
5099 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
5100 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
5101 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
5102 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
5103 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) NAME,
5104 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) NAME,
5105 #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8) NAME,
5106 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
5107 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
5108 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
5109 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
5110 #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
5111 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG6) \
5113 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
5114 #include "builtin-types.def"
5115 #undef DEF_PRIMITIVE_TYPE
5116 #undef DEF_FUNCTION_TYPE_0
5117 #undef DEF_FUNCTION_TYPE_1
5118 #undef DEF_FUNCTION_TYPE_2
5119 #undef DEF_FUNCTION_TYPE_3
5120 #undef DEF_FUNCTION_TYPE_4
5121 #undef DEF_FUNCTION_TYPE_5
5122 #undef DEF_FUNCTION_TYPE_6
5123 #undef DEF_FUNCTION_TYPE_7
5124 #undef DEF_FUNCTION_TYPE_8
5125 #undef DEF_FUNCTION_TYPE_VAR_0
5126 #undef DEF_FUNCTION_TYPE_VAR_1
5127 #undef DEF_FUNCTION_TYPE_VAR_2
5128 #undef DEF_FUNCTION_TYPE_VAR_3
5129 #undef DEF_FUNCTION_TYPE_VAR_4
5130 #undef DEF_FUNCTION_TYPE_VAR_5
5131 #undef DEF_POINTER_TYPE
5135 typedef enum c_builtin_type builtin_type
;
5137 /* A temporary array for c_common_nodes_and_builtins. Used in
5138 communication with def_fn_type. */
5139 static tree builtin_types
[(int) BT_LAST
+ 1];
5141 /* A helper function for c_common_nodes_and_builtins. Build function type
5142 for DEF with return type RET and N arguments. If VAR is true, then the
5143 function should be variadic after those N arguments.
5145 Takes special care not to ICE if any of the types involved are
5146 error_mark_node, which indicates that said type is not in fact available
5147 (see builtin_type_for_size). In which case the function type as a whole
5148 should be error_mark_node. */
5151 def_fn_type (builtin_type def
, builtin_type ret
, bool var
, int n
, ...)
5154 tree
*args
= XALLOCAVEC (tree
, n
);
5159 for (i
= 0; i
< n
; ++i
)
5161 builtin_type a
= (builtin_type
) va_arg (list
, int);
5162 t
= builtin_types
[a
];
5163 if (t
== error_mark_node
)
5168 t
= builtin_types
[ret
];
5169 if (t
== error_mark_node
)
5172 t
= build_varargs_function_type_array (t
, n
, args
);
5174 t
= build_function_type_array (t
, n
, args
);
5177 builtin_types
[def
] = t
;
5181 /* Build builtin functions common to both C and C++ language
5185 c_define_builtins (tree va_list_ref_type_node
, tree va_list_arg_type_node
)
5187 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
5188 builtin_types[ENUM] = VALUE;
5189 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
5190 def_fn_type (ENUM, RETURN, 0, 0);
5191 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
5192 def_fn_type (ENUM, RETURN, 0, 1, ARG1);
5193 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
5194 def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
5195 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
5196 def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
5197 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
5198 def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
5199 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5200 def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
5201 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5203 def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
5204 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5206 def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
5207 #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5209 def_fn_type (ENUM, RETURN, 0, 8, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
5211 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
5212 def_fn_type (ENUM, RETURN, 1, 0);
5213 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
5214 def_fn_type (ENUM, RETURN, 1, 1, ARG1);
5215 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
5216 def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
5217 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
5218 def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
5219 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
5220 def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
5221 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5222 def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
5223 #define DEF_POINTER_TYPE(ENUM, TYPE) \
5224 builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
5226 #include "builtin-types.def"
5228 #undef DEF_PRIMITIVE_TYPE
5229 #undef DEF_FUNCTION_TYPE_1
5230 #undef DEF_FUNCTION_TYPE_2
5231 #undef DEF_FUNCTION_TYPE_3
5232 #undef DEF_FUNCTION_TYPE_4
5233 #undef DEF_FUNCTION_TYPE_5
5234 #undef DEF_FUNCTION_TYPE_6
5235 #undef DEF_FUNCTION_TYPE_VAR_0
5236 #undef DEF_FUNCTION_TYPE_VAR_1
5237 #undef DEF_FUNCTION_TYPE_VAR_2
5238 #undef DEF_FUNCTION_TYPE_VAR_3
5239 #undef DEF_FUNCTION_TYPE_VAR_4
5240 #undef DEF_FUNCTION_TYPE_VAR_5
5241 #undef DEF_POINTER_TYPE
5242 builtin_types
[(int) BT_LAST
] = NULL_TREE
;
5244 c_init_attributes ();
5246 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P, \
5247 NONANSI_P, ATTRS, IMPLICIT, COND) \
5249 def_builtin_1 (ENUM, NAME, CLASS, \
5250 builtin_types[(int) TYPE], \
5251 builtin_types[(int) LIBTYPE], \
5252 BOTH_P, FALLBACK_P, NONANSI_P, \
5253 built_in_attributes[(int) ATTRS], IMPLICIT);
5254 #include "builtins.def"
5257 targetm
.init_builtins ();
5259 build_common_builtin_nodes ();
5261 if (flag_enable_cilkplus
)
5262 cilk_init_builtins ();
5265 /* Like get_identifier, but avoid warnings about null arguments when
5266 the argument may be NULL for targets where GCC lacks stdint.h type
5270 c_get_ident (const char *id
)
5272 return get_identifier (id
);
5275 /* Build tree nodes and builtin functions common to both C and C++ language
5279 c_common_nodes_and_builtins (void)
5281 int char16_type_size
;
5282 int char32_type_size
;
5283 int wchar_type_size
;
5284 tree array_domain_type
;
5285 tree va_list_ref_type_node
;
5286 tree va_list_arg_type_node
;
5288 build_common_tree_nodes (flag_signed_char
, flag_short_double
);
5290 /* Define `int' and `char' first so that dbx will output them first. */
5291 record_builtin_type (RID_INT
, NULL
, integer_type_node
);
5292 record_builtin_type (RID_CHAR
, "char", char_type_node
);
5294 /* `signed' is the same as `int'. FIXME: the declarations of "signed",
5295 "unsigned long", "long long unsigned" and "unsigned short" were in C++
5296 but not C. Are the conditionals here needed? */
5297 if (c_dialect_cxx ())
5298 record_builtin_type (RID_SIGNED
, NULL
, integer_type_node
);
5299 record_builtin_type (RID_LONG
, "long int", long_integer_type_node
);
5300 record_builtin_type (RID_UNSIGNED
, "unsigned int", unsigned_type_node
);
5301 record_builtin_type (RID_MAX
, "long unsigned int",
5302 long_unsigned_type_node
);
5303 if (int128_integer_type_node
!= NULL_TREE
)
5305 record_builtin_type (RID_INT128
, "__int128",
5306 int128_integer_type_node
);
5307 record_builtin_type (RID_MAX
, "__int128 unsigned",
5308 int128_unsigned_type_node
);
5310 if (c_dialect_cxx ())
5311 record_builtin_type (RID_MAX
, "unsigned long", long_unsigned_type_node
);
5312 record_builtin_type (RID_MAX
, "long long int",
5313 long_long_integer_type_node
);
5314 record_builtin_type (RID_MAX
, "long long unsigned int",
5315 long_long_unsigned_type_node
);
5316 if (c_dialect_cxx ())
5317 record_builtin_type (RID_MAX
, "long long unsigned",
5318 long_long_unsigned_type_node
);
5319 record_builtin_type (RID_SHORT
, "short int", short_integer_type_node
);
5320 record_builtin_type (RID_MAX
, "short unsigned int",
5321 short_unsigned_type_node
);
5322 if (c_dialect_cxx ())
5323 record_builtin_type (RID_MAX
, "unsigned short",
5324 short_unsigned_type_node
);
5326 /* Define both `signed char' and `unsigned char'. */
5327 record_builtin_type (RID_MAX
, "signed char", signed_char_type_node
);
5328 record_builtin_type (RID_MAX
, "unsigned char", unsigned_char_type_node
);
5330 /* These are types that c_common_type_for_size and
5331 c_common_type_for_mode use. */
5332 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5333 TYPE_DECL
, NULL_TREE
,
5335 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5336 TYPE_DECL
, NULL_TREE
,
5338 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5339 TYPE_DECL
, NULL_TREE
,
5341 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5342 TYPE_DECL
, NULL_TREE
,
5344 #if HOST_BITS_PER_WIDE_INT >= 64
5345 if (targetm
.scalar_mode_supported_p (TImode
))
5346 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5348 get_identifier ("__int128_t"),
5351 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5352 TYPE_DECL
, NULL_TREE
,
5353 unsigned_intQI_type_node
));
5354 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5355 TYPE_DECL
, NULL_TREE
,
5356 unsigned_intHI_type_node
));
5357 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5358 TYPE_DECL
, NULL_TREE
,
5359 unsigned_intSI_type_node
));
5360 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5361 TYPE_DECL
, NULL_TREE
,
5362 unsigned_intDI_type_node
));
5363 #if HOST_BITS_PER_WIDE_INT >= 64
5364 if (targetm
.scalar_mode_supported_p (TImode
))
5365 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5367 get_identifier ("__uint128_t"),
5368 unsigned_intTI_type_node
));
5371 /* Create the widest literal types. */
5372 widest_integer_literal_type_node
5373 = make_signed_type (HOST_BITS_PER_WIDE_INT
* 2);
5374 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5375 TYPE_DECL
, NULL_TREE
,
5376 widest_integer_literal_type_node
));
5378 widest_unsigned_literal_type_node
5379 = make_unsigned_type (HOST_BITS_PER_WIDE_INT
* 2);
5380 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5381 TYPE_DECL
, NULL_TREE
,
5382 widest_unsigned_literal_type_node
));
5384 signed_size_type_node
= c_common_signed_type (size_type_node
);
5387 TREE_TYPE (identifier_global_value (get_identifier (PID_TYPE
)));
5389 record_builtin_type (RID_FLOAT
, NULL
, float_type_node
);
5390 record_builtin_type (RID_DOUBLE
, NULL
, double_type_node
);
5391 record_builtin_type (RID_MAX
, "long double", long_double_type_node
);
5393 /* Only supported decimal floating point extension if the target
5394 actually supports underlying modes. */
5395 if (targetm
.scalar_mode_supported_p (SDmode
)
5396 && targetm
.scalar_mode_supported_p (DDmode
)
5397 && targetm
.scalar_mode_supported_p (TDmode
))
5399 record_builtin_type (RID_DFLOAT32
, NULL
, dfloat32_type_node
);
5400 record_builtin_type (RID_DFLOAT64
, NULL
, dfloat64_type_node
);
5401 record_builtin_type (RID_DFLOAT128
, NULL
, dfloat128_type_node
);
5404 if (targetm
.fixed_point_supported_p ())
5406 record_builtin_type (RID_MAX
, "short _Fract", short_fract_type_node
);
5407 record_builtin_type (RID_FRACT
, NULL
, fract_type_node
);
5408 record_builtin_type (RID_MAX
, "long _Fract", long_fract_type_node
);
5409 record_builtin_type (RID_MAX
, "long long _Fract",
5410 long_long_fract_type_node
);
5411 record_builtin_type (RID_MAX
, "unsigned short _Fract",
5412 unsigned_short_fract_type_node
);
5413 record_builtin_type (RID_MAX
, "unsigned _Fract",
5414 unsigned_fract_type_node
);
5415 record_builtin_type (RID_MAX
, "unsigned long _Fract",
5416 unsigned_long_fract_type_node
);
5417 record_builtin_type (RID_MAX
, "unsigned long long _Fract",
5418 unsigned_long_long_fract_type_node
);
5419 record_builtin_type (RID_MAX
, "_Sat short _Fract",
5420 sat_short_fract_type_node
);
5421 record_builtin_type (RID_MAX
, "_Sat _Fract", sat_fract_type_node
);
5422 record_builtin_type (RID_MAX
, "_Sat long _Fract",
5423 sat_long_fract_type_node
);
5424 record_builtin_type (RID_MAX
, "_Sat long long _Fract",
5425 sat_long_long_fract_type_node
);
5426 record_builtin_type (RID_MAX
, "_Sat unsigned short _Fract",
5427 sat_unsigned_short_fract_type_node
);
5428 record_builtin_type (RID_MAX
, "_Sat unsigned _Fract",
5429 sat_unsigned_fract_type_node
);
5430 record_builtin_type (RID_MAX
, "_Sat unsigned long _Fract",
5431 sat_unsigned_long_fract_type_node
);
5432 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Fract",
5433 sat_unsigned_long_long_fract_type_node
);
5434 record_builtin_type (RID_MAX
, "short _Accum", short_accum_type_node
);
5435 record_builtin_type (RID_ACCUM
, NULL
, accum_type_node
);
5436 record_builtin_type (RID_MAX
, "long _Accum", long_accum_type_node
);
5437 record_builtin_type (RID_MAX
, "long long _Accum",
5438 long_long_accum_type_node
);
5439 record_builtin_type (RID_MAX
, "unsigned short _Accum",
5440 unsigned_short_accum_type_node
);
5441 record_builtin_type (RID_MAX
, "unsigned _Accum",
5442 unsigned_accum_type_node
);
5443 record_builtin_type (RID_MAX
, "unsigned long _Accum",
5444 unsigned_long_accum_type_node
);
5445 record_builtin_type (RID_MAX
, "unsigned long long _Accum",
5446 unsigned_long_long_accum_type_node
);
5447 record_builtin_type (RID_MAX
, "_Sat short _Accum",
5448 sat_short_accum_type_node
);
5449 record_builtin_type (RID_MAX
, "_Sat _Accum", sat_accum_type_node
);
5450 record_builtin_type (RID_MAX
, "_Sat long _Accum",
5451 sat_long_accum_type_node
);
5452 record_builtin_type (RID_MAX
, "_Sat long long _Accum",
5453 sat_long_long_accum_type_node
);
5454 record_builtin_type (RID_MAX
, "_Sat unsigned short _Accum",
5455 sat_unsigned_short_accum_type_node
);
5456 record_builtin_type (RID_MAX
, "_Sat unsigned _Accum",
5457 sat_unsigned_accum_type_node
);
5458 record_builtin_type (RID_MAX
, "_Sat unsigned long _Accum",
5459 sat_unsigned_long_accum_type_node
);
5460 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Accum",
5461 sat_unsigned_long_long_accum_type_node
);
5465 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5467 get_identifier ("complex int"),
5468 complex_integer_type_node
));
5469 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5471 get_identifier ("complex float"),
5472 complex_float_type_node
));
5473 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5475 get_identifier ("complex double"),
5476 complex_double_type_node
));
5477 lang_hooks
.decls
.pushdecl
5478 (build_decl (UNKNOWN_LOCATION
,
5479 TYPE_DECL
, get_identifier ("complex long double"),
5480 complex_long_double_type_node
));
5482 if (c_dialect_cxx ())
5483 /* For C++, make fileptr_type_node a distinct void * type until
5484 FILE type is defined. */
5485 fileptr_type_node
= build_variant_type_copy (ptr_type_node
);
5487 record_builtin_type (RID_VOID
, NULL
, void_type_node
);
5489 /* Set the TYPE_NAME for any variants that were built before
5490 record_builtin_type gave names to the built-in types. */
5492 tree void_name
= TYPE_NAME (void_type_node
);
5493 TYPE_NAME (void_type_node
) = NULL_TREE
;
5494 TYPE_NAME (build_qualified_type (void_type_node
, TYPE_QUAL_CONST
))
5496 TYPE_NAME (void_type_node
) = void_name
;
5499 /* This node must not be shared. */
5500 void_zero_node
= make_node (INTEGER_CST
);
5501 TREE_TYPE (void_zero_node
) = void_type_node
;
5503 void_list_node
= build_void_list_node ();
5505 /* Make a type to be the domain of a few array types
5506 whose domains don't really matter.
5507 200 is small enough that it always fits in size_t
5508 and large enough that it can hold most function names for the
5509 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
5510 array_domain_type
= build_index_type (size_int (200));
5512 /* Make a type for arrays of characters.
5513 With luck nothing will ever really depend on the length of this
5515 char_array_type_node
5516 = build_array_type (char_type_node
, array_domain_type
);
5518 string_type_node
= build_pointer_type (char_type_node
);
5519 const_string_type_node
5520 = build_pointer_type (build_qualified_type
5521 (char_type_node
, TYPE_QUAL_CONST
));
5523 /* This is special for C++ so functions can be overloaded. */
5524 wchar_type_node
= get_identifier (MODIFIED_WCHAR_TYPE
);
5525 wchar_type_node
= TREE_TYPE (identifier_global_value (wchar_type_node
));
5526 wchar_type_size
= TYPE_PRECISION (wchar_type_node
);
5527 underlying_wchar_type_node
= wchar_type_node
;
5528 if (c_dialect_cxx ())
5530 if (TYPE_UNSIGNED (wchar_type_node
))
5531 wchar_type_node
= make_unsigned_type (wchar_type_size
);
5533 wchar_type_node
= make_signed_type (wchar_type_size
);
5534 record_builtin_type (RID_WCHAR
, "wchar_t", wchar_type_node
);
5537 /* This is for wide string constants. */
5538 wchar_array_type_node
5539 = build_array_type (wchar_type_node
, array_domain_type
);
5541 /* Define 'char16_t'. */
5542 char16_type_node
= get_identifier (CHAR16_TYPE
);
5543 char16_type_node
= TREE_TYPE (identifier_global_value (char16_type_node
));
5544 char16_type_size
= TYPE_PRECISION (char16_type_node
);
5545 if (c_dialect_cxx ())
5547 char16_type_node
= make_unsigned_type (char16_type_size
);
5549 if (cxx_dialect
>= cxx11
)
5550 record_builtin_type (RID_CHAR16
, "char16_t", char16_type_node
);
5553 /* This is for UTF-16 string constants. */
5554 char16_array_type_node
5555 = build_array_type (char16_type_node
, array_domain_type
);
5557 /* Define 'char32_t'. */
5558 char32_type_node
= get_identifier (CHAR32_TYPE
);
5559 char32_type_node
= TREE_TYPE (identifier_global_value (char32_type_node
));
5560 char32_type_size
= TYPE_PRECISION (char32_type_node
);
5561 if (c_dialect_cxx ())
5563 char32_type_node
= make_unsigned_type (char32_type_size
);
5565 if (cxx_dialect
>= cxx11
)
5566 record_builtin_type (RID_CHAR32
, "char32_t", char32_type_node
);
5569 /* This is for UTF-32 string constants. */
5570 char32_array_type_node
5571 = build_array_type (char32_type_node
, array_domain_type
);
5574 TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE
)));
5577 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE
)));
5579 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE
)));
5581 if (SIG_ATOMIC_TYPE
)
5582 sig_atomic_type_node
=
5583 TREE_TYPE (identifier_global_value (c_get_ident (SIG_ATOMIC_TYPE
)));
5586 TREE_TYPE (identifier_global_value (c_get_ident (INT8_TYPE
)));
5589 TREE_TYPE (identifier_global_value (c_get_ident (INT16_TYPE
)));
5592 TREE_TYPE (identifier_global_value (c_get_ident (INT32_TYPE
)));
5595 TREE_TYPE (identifier_global_value (c_get_ident (INT64_TYPE
)));
5598 TREE_TYPE (identifier_global_value (c_get_ident (UINT8_TYPE
)));
5600 c_uint16_type_node
=
5601 TREE_TYPE (identifier_global_value (c_get_ident (UINT16_TYPE
)));
5603 c_uint32_type_node
=
5604 TREE_TYPE (identifier_global_value (c_get_ident (UINT32_TYPE
)));
5606 c_uint64_type_node
=
5607 TREE_TYPE (identifier_global_value (c_get_ident (UINT64_TYPE
)));
5608 if (INT_LEAST8_TYPE
)
5609 int_least8_type_node
=
5610 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST8_TYPE
)));
5611 if (INT_LEAST16_TYPE
)
5612 int_least16_type_node
=
5613 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST16_TYPE
)));
5614 if (INT_LEAST32_TYPE
)
5615 int_least32_type_node
=
5616 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST32_TYPE
)));
5617 if (INT_LEAST64_TYPE
)
5618 int_least64_type_node
=
5619 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST64_TYPE
)));
5620 if (UINT_LEAST8_TYPE
)
5621 uint_least8_type_node
=
5622 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST8_TYPE
)));
5623 if (UINT_LEAST16_TYPE
)
5624 uint_least16_type_node
=
5625 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST16_TYPE
)));
5626 if (UINT_LEAST32_TYPE
)
5627 uint_least32_type_node
=
5628 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST32_TYPE
)));
5629 if (UINT_LEAST64_TYPE
)
5630 uint_least64_type_node
=
5631 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST64_TYPE
)));
5633 int_fast8_type_node
=
5634 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST8_TYPE
)));
5635 if (INT_FAST16_TYPE
)
5636 int_fast16_type_node
=
5637 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST16_TYPE
)));
5638 if (INT_FAST32_TYPE
)
5639 int_fast32_type_node
=
5640 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST32_TYPE
)));
5641 if (INT_FAST64_TYPE
)
5642 int_fast64_type_node
=
5643 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST64_TYPE
)));
5644 if (UINT_FAST8_TYPE
)
5645 uint_fast8_type_node
=
5646 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST8_TYPE
)));
5647 if (UINT_FAST16_TYPE
)
5648 uint_fast16_type_node
=
5649 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST16_TYPE
)));
5650 if (UINT_FAST32_TYPE
)
5651 uint_fast32_type_node
=
5652 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST32_TYPE
)));
5653 if (UINT_FAST64_TYPE
)
5654 uint_fast64_type_node
=
5655 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST64_TYPE
)));
5658 TREE_TYPE (identifier_global_value (c_get_ident (INTPTR_TYPE
)));
5661 TREE_TYPE (identifier_global_value (c_get_ident (UINTPTR_TYPE
)));
5663 default_function_type
5664 = build_varargs_function_type_list (integer_type_node
, NULL_TREE
);
5666 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE
)));
5667 unsigned_ptrdiff_type_node
= c_common_unsigned_type (ptrdiff_type_node
);
5669 lang_hooks
.decls
.pushdecl
5670 (build_decl (UNKNOWN_LOCATION
,
5671 TYPE_DECL
, get_identifier ("__builtin_va_list"),
5672 va_list_type_node
));
5673 if (targetm
.enum_va_list_p
)
5679 for (l
= 0; targetm
.enum_va_list_p (l
, &pname
, &ptype
); ++l
)
5681 lang_hooks
.decls
.pushdecl
5682 (build_decl (UNKNOWN_LOCATION
,
5683 TYPE_DECL
, get_identifier (pname
),
5689 if (TREE_CODE (va_list_type_node
) == ARRAY_TYPE
)
5691 va_list_arg_type_node
= va_list_ref_type_node
=
5692 build_pointer_type (TREE_TYPE (va_list_type_node
));
5696 va_list_arg_type_node
= va_list_type_node
;
5697 va_list_ref_type_node
= build_reference_type (va_list_type_node
);
5700 if (!flag_preprocess_only
)
5701 c_define_builtins (va_list_ref_type_node
, va_list_arg_type_node
);
5703 main_identifier_node
= get_identifier ("main");
5705 /* Create the built-in __null node. It is important that this is
5707 null_node
= make_node (INTEGER_CST
);
5708 TREE_TYPE (null_node
) = c_common_type_for_size (POINTER_SIZE
, 0);
5710 /* Since builtin_types isn't gc'ed, don't export these nodes. */
5711 memset (builtin_types
, 0, sizeof (builtin_types
));
5714 /* The number of named compound-literals generated thus far. */
5715 static GTY(()) int compound_literal_number
;
5717 /* Set DECL_NAME for DECL, a VAR_DECL for a compound-literal. */
5720 set_compound_literal_name (tree decl
)
5723 ASM_FORMAT_PRIVATE_NAME (name
, "__compound_literal",
5724 compound_literal_number
);
5725 compound_literal_number
++;
5726 DECL_NAME (decl
) = get_identifier (name
);
5730 build_va_arg (location_t loc
, tree expr
, tree type
)
5732 expr
= build1 (VA_ARG_EXPR
, type
, expr
);
5733 SET_EXPR_LOCATION (expr
, loc
);
5738 /* Linked list of disabled built-in functions. */
5740 typedef struct disabled_builtin
5743 struct disabled_builtin
*next
;
5745 static disabled_builtin
*disabled_builtins
= NULL
;
5747 static bool builtin_function_disabled_p (const char *);
5749 /* Disable a built-in function specified by -fno-builtin-NAME. If NAME
5750 begins with "__builtin_", give an error. */
5753 disable_builtin_function (const char *name
)
5755 if (strncmp (name
, "__builtin_", strlen ("__builtin_")) == 0)
5756 error ("cannot disable built-in function %qs", name
);
5759 disabled_builtin
*new_disabled_builtin
= XNEW (disabled_builtin
);
5760 new_disabled_builtin
->name
= name
;
5761 new_disabled_builtin
->next
= disabled_builtins
;
5762 disabled_builtins
= new_disabled_builtin
;
5767 /* Return true if the built-in function NAME has been disabled, false
5771 builtin_function_disabled_p (const char *name
)
5773 disabled_builtin
*p
;
5774 for (p
= disabled_builtins
; p
!= NULL
; p
= p
->next
)
5776 if (strcmp (name
, p
->name
) == 0)
5783 /* Worker for DEF_BUILTIN.
5784 Possibly define a builtin function with one or two names.
5785 Does not declare a non-__builtin_ function if flag_no_builtin, or if
5786 nonansi_p and flag_no_nonansi_builtin. */
5789 def_builtin_1 (enum built_in_function fncode
,
5791 enum built_in_class fnclass
,
5792 tree fntype
, tree libtype
,
5793 bool both_p
, bool fallback_p
, bool nonansi_p
,
5794 tree fnattrs
, bool implicit_p
)
5797 const char *libname
;
5799 if (fntype
== error_mark_node
)
5802 gcc_assert ((!both_p
&& !fallback_p
)
5803 || !strncmp (name
, "__builtin_",
5804 strlen ("__builtin_")));
5806 libname
= name
+ strlen ("__builtin_");
5807 decl
= add_builtin_function (name
, fntype
, fncode
, fnclass
,
5808 (fallback_p
? libname
: NULL
),
5811 set_builtin_decl (fncode
, decl
, implicit_p
);
5814 && !flag_no_builtin
&& !builtin_function_disabled_p (libname
)
5815 && !(nonansi_p
&& flag_no_nonansi_builtin
))
5816 add_builtin_function (libname
, libtype
, fncode
, fnclass
,
5820 /* Nonzero if the type T promotes to int. This is (nearly) the
5821 integral promotions defined in ISO C99 6.3.1.1/2. */
5824 c_promoting_integer_type_p (const_tree t
)
5826 switch (TREE_CODE (t
))
5829 return (TYPE_MAIN_VARIANT (t
) == char_type_node
5830 || TYPE_MAIN_VARIANT (t
) == signed_char_type_node
5831 || TYPE_MAIN_VARIANT (t
) == unsigned_char_type_node
5832 || TYPE_MAIN_VARIANT (t
) == short_integer_type_node
5833 || TYPE_MAIN_VARIANT (t
) == short_unsigned_type_node
5834 || TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
));
5837 /* ??? Technically all enumerations not larger than an int
5838 promote to an int. But this is used along code paths
5839 that only want to notice a size change. */
5840 return TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
);
5850 /* Return 1 if PARMS specifies a fixed number of parameters
5851 and none of their types is affected by default promotions. */
5854 self_promoting_args_p (const_tree parms
)
5857 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
5859 tree type
= TREE_VALUE (t
);
5861 if (type
== error_mark_node
)
5864 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
5870 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
5873 if (c_promoting_integer_type_p (type
))
5879 /* Recursively remove any '*' or '&' operator from TYPE. */
5881 strip_pointer_operator (tree t
)
5883 while (POINTER_TYPE_P (t
))
5888 /* Recursively remove pointer or array type from TYPE. */
5890 strip_pointer_or_array_types (tree t
)
5892 while (TREE_CODE (t
) == ARRAY_TYPE
|| POINTER_TYPE_P (t
))
5897 /* Used to compare case labels. K1 and K2 are actually tree nodes
5898 representing case labels, or NULL_TREE for a `default' label.
5899 Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after
5900 K2, and 0 if K1 and K2 are equal. */
5903 case_compare (splay_tree_key k1
, splay_tree_key k2
)
5905 /* Consider a NULL key (such as arises with a `default' label) to be
5906 smaller than anything else. */
5912 return tree_int_cst_compare ((tree
) k1
, (tree
) k2
);
5915 /* Process a case label, located at LOC, for the range LOW_VALUE
5916 ... HIGH_VALUE. If LOW_VALUE and HIGH_VALUE are both NULL_TREE
5917 then this case label is actually a `default' label. If only
5918 HIGH_VALUE is NULL_TREE, then case label was declared using the
5919 usual C/C++ syntax, rather than the GNU case range extension.
5920 CASES is a tree containing all the case ranges processed so far;
5921 COND is the condition for the switch-statement itself. Returns the
5922 CASE_LABEL_EXPR created, or ERROR_MARK_NODE if no CASE_LABEL_EXPR
5926 c_add_case_label (location_t loc
, splay_tree cases
, tree cond
, tree orig_type
,
5927 tree low_value
, tree high_value
)
5932 splay_tree_node node
;
5934 /* Create the LABEL_DECL itself. */
5935 label
= create_artificial_label (loc
);
5937 /* If there was an error processing the switch condition, bail now
5938 before we get more confused. */
5939 if (!cond
|| cond
== error_mark_node
)
5942 if ((low_value
&& TREE_TYPE (low_value
)
5943 && POINTER_TYPE_P (TREE_TYPE (low_value
)))
5944 || (high_value
&& TREE_TYPE (high_value
)
5945 && POINTER_TYPE_P (TREE_TYPE (high_value
))))
5947 error_at (loc
, "pointers are not permitted as case values");
5951 /* Case ranges are a GNU extension. */
5953 pedwarn (loc
, OPT_Wpedantic
,
5954 "range expressions in switch statements are non-standard");
5956 type
= TREE_TYPE (cond
);
5959 low_value
= check_case_value (low_value
);
5960 low_value
= convert_and_check (type
, low_value
);
5961 if (low_value
== error_mark_node
)
5966 high_value
= check_case_value (high_value
);
5967 high_value
= convert_and_check (type
, high_value
);
5968 if (high_value
== error_mark_node
)
5972 if (low_value
&& high_value
)
5974 /* If the LOW_VALUE and HIGH_VALUE are the same, then this isn't
5975 really a case range, even though it was written that way.
5976 Remove the HIGH_VALUE to simplify later processing. */
5977 if (tree_int_cst_equal (low_value
, high_value
))
5978 high_value
= NULL_TREE
;
5979 else if (!tree_int_cst_lt (low_value
, high_value
))
5980 warning_at (loc
, 0, "empty range specified");
5983 /* See if the case is in range of the type of the original testing
5984 expression. If both low_value and high_value are out of range,
5985 don't insert the case label and return NULL_TREE. */
5987 && !check_case_bounds (type
, orig_type
,
5988 &low_value
, high_value
? &high_value
: NULL
))
5991 /* Look up the LOW_VALUE in the table of case labels we already
5993 node
= splay_tree_lookup (cases
, (splay_tree_key
) low_value
);
5994 /* If there was not an exact match, check for overlapping ranges.
5995 There's no need to do this if there's no LOW_VALUE or HIGH_VALUE;
5996 that's a `default' label and the only overlap is an exact match. */
5997 if (!node
&& (low_value
|| high_value
))
5999 splay_tree_node low_bound
;
6000 splay_tree_node high_bound
;
6002 /* Even though there wasn't an exact match, there might be an
6003 overlap between this case range and another case range.
6004 Since we've (inductively) not allowed any overlapping case
6005 ranges, we simply need to find the greatest low case label
6006 that is smaller that LOW_VALUE, and the smallest low case
6007 label that is greater than LOW_VALUE. If there is an overlap
6008 it will occur in one of these two ranges. */
6009 low_bound
= splay_tree_predecessor (cases
,
6010 (splay_tree_key
) low_value
);
6011 high_bound
= splay_tree_successor (cases
,
6012 (splay_tree_key
) low_value
);
6014 /* Check to see if the LOW_BOUND overlaps. It is smaller than
6015 the LOW_VALUE, so there is no need to check unless the
6016 LOW_BOUND is in fact itself a case range. */
6018 && CASE_HIGH ((tree
) low_bound
->value
)
6019 && tree_int_cst_compare (CASE_HIGH ((tree
) low_bound
->value
),
6022 /* Check to see if the HIGH_BOUND overlaps. The low end of that
6023 range is bigger than the low end of the current range, so we
6024 are only interested if the current range is a real range, and
6025 not an ordinary case label. */
6028 && (tree_int_cst_compare ((tree
) high_bound
->key
,
6033 /* If there was an overlap, issue an error. */
6036 tree duplicate
= CASE_LABEL ((tree
) node
->value
);
6040 error_at (loc
, "duplicate (or overlapping) case value");
6041 error_at (DECL_SOURCE_LOCATION (duplicate
),
6042 "this is the first entry overlapping that value");
6046 error_at (loc
, "duplicate case value") ;
6047 error_at (DECL_SOURCE_LOCATION (duplicate
), "previously used here");
6051 error_at (loc
, "multiple default labels in one switch");
6052 error_at (DECL_SOURCE_LOCATION (duplicate
),
6053 "this is the first default label");
6058 /* Add a CASE_LABEL to the statement-tree. */
6059 case_label
= add_stmt (build_case_label (low_value
, high_value
, label
));
6060 /* Register this case label in the splay tree. */
6061 splay_tree_insert (cases
,
6062 (splay_tree_key
) low_value
,
6063 (splay_tree_value
) case_label
);
6068 /* Add a label so that the back-end doesn't think that the beginning of
6069 the switch is unreachable. Note that we do not add a case label, as
6070 that just leads to duplicates and thence to failure later on. */
6073 tree t
= create_artificial_label (loc
);
6074 add_stmt (build_stmt (loc
, LABEL_EXPR
, t
));
6076 return error_mark_node
;
6079 /* Subroutines of c_do_switch_warnings, called via splay_tree_foreach.
6080 Used to verify that case values match up with enumerator values. */
6083 match_case_to_enum_1 (tree key
, tree type
, tree label
)
6085 char buf
[2 + 2*HOST_BITS_PER_WIDE_INT
/4 + 1];
6087 /* ??? Not working too hard to print the double-word value.
6088 Should perhaps be done with %lwd in the diagnostic routines? */
6089 if (TREE_INT_CST_HIGH (key
) == 0)
6090 snprintf (buf
, sizeof (buf
), HOST_WIDE_INT_PRINT_UNSIGNED
,
6091 TREE_INT_CST_LOW (key
));
6092 else if (!TYPE_UNSIGNED (type
)
6093 && TREE_INT_CST_HIGH (key
) == -1
6094 && TREE_INT_CST_LOW (key
) != 0)
6095 snprintf (buf
, sizeof (buf
), "-" HOST_WIDE_INT_PRINT_UNSIGNED
,
6096 -TREE_INT_CST_LOW (key
));
6098 snprintf (buf
, sizeof (buf
), HOST_WIDE_INT_PRINT_DOUBLE_HEX
,
6099 (unsigned HOST_WIDE_INT
) TREE_INT_CST_HIGH (key
),
6100 (unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (key
));
6102 if (TYPE_NAME (type
) == 0)
6103 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
6104 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
6105 "case value %qs not in enumerated type",
6108 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
6109 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
6110 "case value %qs not in enumerated type %qT",
6114 /* Subroutine of c_do_switch_warnings, called via splay_tree_foreach.
6115 Used to verify that case values match up with enumerator values. */
6118 match_case_to_enum (splay_tree_node node
, void *data
)
6120 tree label
= (tree
) node
->value
;
6121 tree type
= (tree
) data
;
6123 /* Skip default case. */
6124 if (!CASE_LOW (label
))
6127 /* If CASE_LOW_SEEN is not set, that means CASE_LOW did not appear
6128 when we did our enum->case scan. Reset our scratch bit after. */
6129 if (!CASE_LOW_SEEN (label
))
6130 match_case_to_enum_1 (CASE_LOW (label
), type
, label
);
6132 CASE_LOW_SEEN (label
) = 0;
6134 /* If CASE_HIGH is non-null, we have a range. If CASE_HIGH_SEEN is
6135 not set, that means that CASE_HIGH did not appear when we did our
6136 enum->case scan. Reset our scratch bit after. */
6137 if (CASE_HIGH (label
))
6139 if (!CASE_HIGH_SEEN (label
))
6140 match_case_to_enum_1 (CASE_HIGH (label
), type
, label
);
6142 CASE_HIGH_SEEN (label
) = 0;
6148 /* Handle -Wswitch*. Called from the front end after parsing the
6149 switch construct. */
6150 /* ??? Should probably be somewhere generic, since other languages
6151 besides C and C++ would want this. At the moment, however, C/C++
6152 are the only tree-ssa languages that support enumerations at all,
6153 so the point is moot. */
6156 c_do_switch_warnings (splay_tree cases
, location_t switch_location
,
6157 tree type
, tree cond
)
6159 splay_tree_node default_node
;
6160 splay_tree_node node
;
6163 if (!warn_switch
&& !warn_switch_enum
&& !warn_switch_default
)
6166 default_node
= splay_tree_lookup (cases
, (splay_tree_key
) NULL
);
6168 warning_at (switch_location
, OPT_Wswitch_default
,
6169 "switch missing default case");
6171 /* From here on, we only care about about enumerated types. */
6172 if (!type
|| TREE_CODE (type
) != ENUMERAL_TYPE
)
6175 /* From here on, we only care about -Wswitch and -Wswitch-enum. */
6176 if (!warn_switch_enum
&& !warn_switch
)
6179 /* Check the cases. Warn about case values which are not members of
6180 the enumerated type. For -Wswitch-enum, or for -Wswitch when
6181 there is no default case, check that exactly all enumeration
6182 literals are covered by the cases. */
6184 /* Clearing COND if it is not an integer constant simplifies
6185 the tests inside the loop below. */
6186 if (TREE_CODE (cond
) != INTEGER_CST
)
6189 /* The time complexity here is O(N*lg(N)) worst case, but for the
6190 common case of monotonically increasing enumerators, it is
6191 O(N), since the nature of the splay tree will keep the next
6192 element adjacent to the root at all times. */
6194 for (chain
= TYPE_VALUES (type
); chain
; chain
= TREE_CHAIN (chain
))
6196 tree value
= TREE_VALUE (chain
);
6197 if (TREE_CODE (value
) == CONST_DECL
)
6198 value
= DECL_INITIAL (value
);
6199 node
= splay_tree_lookup (cases
, (splay_tree_key
) value
);
6202 /* Mark the CASE_LOW part of the case entry as seen. */
6203 tree label
= (tree
) node
->value
;
6204 CASE_LOW_SEEN (label
) = 1;
6208 /* Even though there wasn't an exact match, there might be a
6209 case range which includes the enumerator's value. */
6210 node
= splay_tree_predecessor (cases
, (splay_tree_key
) value
);
6211 if (node
&& CASE_HIGH ((tree
) node
->value
))
6213 tree label
= (tree
) node
->value
;
6214 int cmp
= tree_int_cst_compare (CASE_HIGH (label
), value
);
6217 /* If we match the upper bound exactly, mark the CASE_HIGH
6218 part of the case entry as seen. */
6220 CASE_HIGH_SEEN (label
) = 1;
6225 /* We've now determined that this enumerated literal isn't
6226 handled by the case labels of the switch statement. */
6228 /* If the switch expression is a constant, we only really care
6229 about whether that constant is handled by the switch. */
6230 if (cond
&& tree_int_cst_compare (cond
, value
))
6233 /* If there is a default_node, the only relevant option is
6234 Wswitch-enum. Otherwise, if both are enabled then we prefer
6235 to warn using -Wswitch because -Wswitch is enabled by -Wall
6236 while -Wswitch-enum is explicit. */
6237 warning_at (switch_location
,
6238 (default_node
|| !warn_switch
6241 "enumeration value %qE not handled in switch",
6242 TREE_PURPOSE (chain
));
6245 /* Warn if there are case expressions that don't correspond to
6246 enumerators. This can occur since C and C++ don't enforce
6247 type-checking of assignments to enumeration variables.
6249 The time complexity here is now always O(N) worst case, since
6250 we should have marked both the lower bound and upper bound of
6251 every disjoint case label, with CASE_LOW_SEEN and CASE_HIGH_SEEN
6252 above. This scan also resets those fields. */
6254 splay_tree_foreach (cases
, match_case_to_enum
, type
);
6257 /* Finish an expression taking the address of LABEL (an
6258 IDENTIFIER_NODE). Returns an expression for the address.
6260 LOC is the location for the expression returned. */
6263 finish_label_address_expr (tree label
, location_t loc
)
6267 pedwarn (input_location
, OPT_Wpedantic
, "taking the address of a label is non-standard");
6269 if (label
== error_mark_node
)
6270 return error_mark_node
;
6272 label
= lookup_label (label
);
6273 if (label
== NULL_TREE
)
6274 result
= null_pointer_node
;
6277 TREE_USED (label
) = 1;
6278 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
6279 /* The current function is not necessarily uninlinable.
6280 Computed gotos are incompatible with inlining, but the value
6281 here could be used only in a diagnostic, for example. */
6282 protected_set_expr_location (result
, loc
);
6289 /* Given a boolean expression ARG, return a tree representing an increment
6290 or decrement (as indicated by CODE) of ARG. The front end must check for
6291 invalid cases (e.g., decrement in C++). */
6293 boolean_increment (enum tree_code code
, tree arg
)
6296 tree true_res
= build_int_cst (TREE_TYPE (arg
), 1);
6298 arg
= stabilize_reference (arg
);
6301 case PREINCREMENT_EXPR
:
6302 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
6304 case POSTINCREMENT_EXPR
:
6305 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
6306 arg
= save_expr (arg
);
6307 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
6308 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
6310 case PREDECREMENT_EXPR
:
6311 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
6312 invert_truthvalue_loc (input_location
, arg
));
6314 case POSTDECREMENT_EXPR
:
6315 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
6316 invert_truthvalue_loc (input_location
, arg
));
6317 arg
= save_expr (arg
);
6318 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
6319 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
6324 TREE_SIDE_EFFECTS (val
) = 1;
6328 /* Built-in macros for stddef.h and stdint.h, that require macros
6329 defined in this file. */
6331 c_stddef_cpp_builtins(void)
6333 builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE
, 0);
6334 builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE
, 0);
6335 builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE
, 0);
6336 builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE
, 0);
6337 builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE
, 0);
6338 builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE
, 0);
6339 builtin_define_with_value ("__CHAR16_TYPE__", CHAR16_TYPE
, 0);
6340 builtin_define_with_value ("__CHAR32_TYPE__", CHAR32_TYPE
, 0);
6341 if (SIG_ATOMIC_TYPE
)
6342 builtin_define_with_value ("__SIG_ATOMIC_TYPE__", SIG_ATOMIC_TYPE
, 0);
6344 builtin_define_with_value ("__INT8_TYPE__", INT8_TYPE
, 0);
6346 builtin_define_with_value ("__INT16_TYPE__", INT16_TYPE
, 0);
6348 builtin_define_with_value ("__INT32_TYPE__", INT32_TYPE
, 0);
6350 builtin_define_with_value ("__INT64_TYPE__", INT64_TYPE
, 0);
6352 builtin_define_with_value ("__UINT8_TYPE__", UINT8_TYPE
, 0);
6354 builtin_define_with_value ("__UINT16_TYPE__", UINT16_TYPE
, 0);
6356 builtin_define_with_value ("__UINT32_TYPE__", UINT32_TYPE
, 0);
6358 builtin_define_with_value ("__UINT64_TYPE__", UINT64_TYPE
, 0);
6359 if (INT_LEAST8_TYPE
)
6360 builtin_define_with_value ("__INT_LEAST8_TYPE__", INT_LEAST8_TYPE
, 0);
6361 if (INT_LEAST16_TYPE
)
6362 builtin_define_with_value ("__INT_LEAST16_TYPE__", INT_LEAST16_TYPE
, 0);
6363 if (INT_LEAST32_TYPE
)
6364 builtin_define_with_value ("__INT_LEAST32_TYPE__", INT_LEAST32_TYPE
, 0);
6365 if (INT_LEAST64_TYPE
)
6366 builtin_define_with_value ("__INT_LEAST64_TYPE__", INT_LEAST64_TYPE
, 0);
6367 if (UINT_LEAST8_TYPE
)
6368 builtin_define_with_value ("__UINT_LEAST8_TYPE__", UINT_LEAST8_TYPE
, 0);
6369 if (UINT_LEAST16_TYPE
)
6370 builtin_define_with_value ("__UINT_LEAST16_TYPE__", UINT_LEAST16_TYPE
, 0);
6371 if (UINT_LEAST32_TYPE
)
6372 builtin_define_with_value ("__UINT_LEAST32_TYPE__", UINT_LEAST32_TYPE
, 0);
6373 if (UINT_LEAST64_TYPE
)
6374 builtin_define_with_value ("__UINT_LEAST64_TYPE__", UINT_LEAST64_TYPE
, 0);
6376 builtin_define_with_value ("__INT_FAST8_TYPE__", INT_FAST8_TYPE
, 0);
6377 if (INT_FAST16_TYPE
)
6378 builtin_define_with_value ("__INT_FAST16_TYPE__", INT_FAST16_TYPE
, 0);
6379 if (INT_FAST32_TYPE
)
6380 builtin_define_with_value ("__INT_FAST32_TYPE__", INT_FAST32_TYPE
, 0);
6381 if (INT_FAST64_TYPE
)
6382 builtin_define_with_value ("__INT_FAST64_TYPE__", INT_FAST64_TYPE
, 0);
6383 if (UINT_FAST8_TYPE
)
6384 builtin_define_with_value ("__UINT_FAST8_TYPE__", UINT_FAST8_TYPE
, 0);
6385 if (UINT_FAST16_TYPE
)
6386 builtin_define_with_value ("__UINT_FAST16_TYPE__", UINT_FAST16_TYPE
, 0);
6387 if (UINT_FAST32_TYPE
)
6388 builtin_define_with_value ("__UINT_FAST32_TYPE__", UINT_FAST32_TYPE
, 0);
6389 if (UINT_FAST64_TYPE
)
6390 builtin_define_with_value ("__UINT_FAST64_TYPE__", UINT_FAST64_TYPE
, 0);
6392 builtin_define_with_value ("__INTPTR_TYPE__", INTPTR_TYPE
, 0);
6394 builtin_define_with_value ("__UINTPTR_TYPE__", UINTPTR_TYPE
, 0);
6398 c_init_attributes (void)
6400 /* Fill in the built_in_attributes array. */
6401 #define DEF_ATTR_NULL_TREE(ENUM) \
6402 built_in_attributes[(int) ENUM] = NULL_TREE;
6403 #define DEF_ATTR_INT(ENUM, VALUE) \
6404 built_in_attributes[(int) ENUM] = build_int_cst (integer_type_node, VALUE);
6405 #define DEF_ATTR_STRING(ENUM, VALUE) \
6406 built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
6407 #define DEF_ATTR_IDENT(ENUM, STRING) \
6408 built_in_attributes[(int) ENUM] = get_identifier (STRING);
6409 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
6410 built_in_attributes[(int) ENUM] \
6411 = tree_cons (built_in_attributes[(int) PURPOSE], \
6412 built_in_attributes[(int) VALUE], \
6413 built_in_attributes[(int) CHAIN]);
6414 #include "builtin-attrs.def"
6415 #undef DEF_ATTR_NULL_TREE
6417 #undef DEF_ATTR_IDENT
6418 #undef DEF_ATTR_TREE_LIST
6421 /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain
6422 identifier as an argument, so the front end shouldn't look it up. */
6425 attribute_takes_identifier_p (const_tree attr_id
)
6427 const struct attribute_spec
*spec
= lookup_attribute_spec (attr_id
);
6429 /* Unknown attribute that we'll end up ignoring, return true so we
6430 don't complain about an identifier argument. */
6432 else if (!strcmp ("mode", spec
->name
)
6433 || !strcmp ("format", spec
->name
)
6434 || !strcmp ("cleanup", spec
->name
))
6437 return targetm
.attribute_takes_identifier_p (attr_id
);
6440 /* Attribute handlers common to C front ends. */
6442 /* Handle a "packed" attribute; arguments as in
6443 struct attribute_spec.handler. */
6446 handle_packed_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6447 int flags
, bool *no_add_attrs
)
6451 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6452 *node
= build_variant_type_copy (*node
);
6453 TYPE_PACKED (*node
) = 1;
6455 else if (TREE_CODE (*node
) == FIELD_DECL
)
6457 if (TYPE_ALIGN (TREE_TYPE (*node
)) <= BITS_PER_UNIT
6458 /* Still pack bitfields. */
6459 && ! DECL_INITIAL (*node
))
6460 warning (OPT_Wattributes
,
6461 "%qE attribute ignored for field of type %qT",
6462 name
, TREE_TYPE (*node
));
6464 DECL_PACKED (*node
) = 1;
6466 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
6467 used for DECL_REGISTER. It wouldn't mean anything anyway.
6468 We can't set DECL_PACKED on the type of a TYPE_DECL, because
6469 that changes what the typedef is typing. */
6472 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6473 *no_add_attrs
= true;
6479 /* Handle a "nocommon" attribute; arguments as in
6480 struct attribute_spec.handler. */
6483 handle_nocommon_attribute (tree
*node
, tree name
,
6484 tree
ARG_UNUSED (args
),
6485 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6487 if (TREE_CODE (*node
) == VAR_DECL
)
6488 DECL_COMMON (*node
) = 0;
6491 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6492 *no_add_attrs
= true;
6498 /* Handle a "common" attribute; arguments as in
6499 struct attribute_spec.handler. */
6502 handle_common_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6503 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6505 if (TREE_CODE (*node
) == VAR_DECL
)
6506 DECL_COMMON (*node
) = 1;
6509 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6510 *no_add_attrs
= true;
6516 /* Handle a "noreturn" attribute; arguments as in
6517 struct attribute_spec.handler. */
6520 handle_noreturn_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6521 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6523 tree type
= TREE_TYPE (*node
);
6525 /* See FIXME comment in c_common_attribute_table. */
6526 if (TREE_CODE (*node
) == FUNCTION_DECL
6527 || objc_method_decl (TREE_CODE (*node
)))
6528 TREE_THIS_VOLATILE (*node
) = 1;
6529 else if (TREE_CODE (type
) == POINTER_TYPE
6530 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
6532 = build_pointer_type
6533 (build_type_variant (TREE_TYPE (type
),
6534 TYPE_READONLY (TREE_TYPE (type
)), 1));
6537 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6538 *no_add_attrs
= true;
6544 /* Handle a "hot" and attribute; arguments as in
6545 struct attribute_spec.handler. */
6548 handle_hot_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6549 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6551 if (TREE_CODE (*node
) == FUNCTION_DECL
6552 || TREE_CODE (*node
) == LABEL_DECL
)
6554 if (lookup_attribute ("cold", DECL_ATTRIBUTES (*node
)) != NULL
)
6556 warning (OPT_Wattributes
, "%qE attribute conflicts with attribute %s",
6558 *no_add_attrs
= true;
6560 /* Most of the rest of the hot processing is done later with
6561 lookup_attribute. */
6565 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6566 *no_add_attrs
= true;
6572 /* Handle a "cold" and attribute; arguments as in
6573 struct attribute_spec.handler. */
6576 handle_cold_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6577 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6579 if (TREE_CODE (*node
) == FUNCTION_DECL
6580 || TREE_CODE (*node
) == LABEL_DECL
)
6582 if (lookup_attribute ("hot", DECL_ATTRIBUTES (*node
)) != NULL
)
6584 warning (OPT_Wattributes
, "%qE attribute conflicts with attribute %s",
6586 *no_add_attrs
= true;
6588 /* Most of the rest of the cold processing is done later with
6589 lookup_attribute. */
6593 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6594 *no_add_attrs
= true;
6600 /* Handle a "no_sanitize_address" attribute; arguments as in
6601 struct attribute_spec.handler. */
6604 handle_no_sanitize_address_attribute (tree
*node
, tree name
, tree
, int,
6607 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6609 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6610 *no_add_attrs
= true;
6616 /* Handle a "no_address_safety_analysis" attribute; arguments as in
6617 struct attribute_spec.handler. */
6620 handle_no_address_safety_analysis_attribute (tree
*node
, tree name
, tree
, int,
6623 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6624 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6625 else if (!lookup_attribute ("no_sanitize_address", DECL_ATTRIBUTES (*node
)))
6626 DECL_ATTRIBUTES (*node
)
6627 = tree_cons (get_identifier ("no_sanitize_address"),
6628 NULL_TREE
, DECL_ATTRIBUTES (*node
));
6629 *no_add_attrs
= true;
6633 /* Handle a "no_sanitize_undefined" attribute; arguments as in
6634 struct attribute_spec.handler. */
6637 handle_no_sanitize_undefined_attribute (tree
*node
, tree name
, tree
, int,
6640 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6642 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6643 *no_add_attrs
= true;
6649 /* Handle a "noinline" attribute; arguments as in
6650 struct attribute_spec.handler. */
6653 handle_noinline_attribute (tree
*node
, tree name
,
6654 tree
ARG_UNUSED (args
),
6655 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6657 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6658 DECL_UNINLINABLE (*node
) = 1;
6661 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6662 *no_add_attrs
= true;
6668 /* Handle a "noclone" attribute; arguments as in
6669 struct attribute_spec.handler. */
6672 handle_noclone_attribute (tree
*node
, tree name
,
6673 tree
ARG_UNUSED (args
),
6674 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6676 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6678 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6679 *no_add_attrs
= true;
6685 /* Handle a "always_inline" attribute; arguments as in
6686 struct attribute_spec.handler. */
6689 handle_always_inline_attribute (tree
*node
, tree name
,
6690 tree
ARG_UNUSED (args
),
6691 int ARG_UNUSED (flags
),
6694 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6696 /* Set the attribute and mark it for disregarding inline
6698 DECL_DISREGARD_INLINE_LIMITS (*node
) = 1;
6702 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6703 *no_add_attrs
= true;
6709 /* Handle a "gnu_inline" attribute; arguments as in
6710 struct attribute_spec.handler. */
6713 handle_gnu_inline_attribute (tree
*node
, tree name
,
6714 tree
ARG_UNUSED (args
),
6715 int ARG_UNUSED (flags
),
6718 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
6720 /* Do nothing else, just set the attribute. We'll get at
6721 it later with lookup_attribute. */
6725 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6726 *no_add_attrs
= true;
6732 /* Handle a "leaf" attribute; arguments as in
6733 struct attribute_spec.handler. */
6736 handle_leaf_attribute (tree
*node
, tree name
,
6737 tree
ARG_UNUSED (args
),
6738 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6740 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6742 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6743 *no_add_attrs
= true;
6745 if (!TREE_PUBLIC (*node
))
6747 warning (OPT_Wattributes
, "%qE attribute has no effect on unit local functions", name
);
6748 *no_add_attrs
= true;
6754 /* Handle an "artificial" attribute; arguments as in
6755 struct attribute_spec.handler. */
6758 handle_artificial_attribute (tree
*node
, tree name
,
6759 tree
ARG_UNUSED (args
),
6760 int ARG_UNUSED (flags
),
6763 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
6765 /* Do nothing else, just set the attribute. We'll get at
6766 it later with lookup_attribute. */
6770 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6771 *no_add_attrs
= true;
6777 /* Handle a "flatten" attribute; arguments as in
6778 struct attribute_spec.handler. */
6781 handle_flatten_attribute (tree
*node
, tree name
,
6782 tree args ATTRIBUTE_UNUSED
,
6783 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
6785 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6786 /* Do nothing else, just set the attribute. We'll get at
6787 it later with lookup_attribute. */
6791 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6792 *no_add_attrs
= true;
6798 /* Handle a "warning" or "error" attribute; arguments as in
6799 struct attribute_spec.handler. */
6802 handle_error_attribute (tree
*node
, tree name
, tree args
,
6803 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6805 if (TREE_CODE (*node
) == FUNCTION_DECL
6806 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
6807 /* Do nothing else, just set the attribute. We'll get at
6808 it later with lookup_attribute. */
6812 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6813 *no_add_attrs
= true;
6819 /* Handle a "used" attribute; arguments as in
6820 struct attribute_spec.handler. */
6823 handle_used_attribute (tree
*pnode
, tree name
, tree
ARG_UNUSED (args
),
6824 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6828 if (TREE_CODE (node
) == FUNCTION_DECL
6829 || (TREE_CODE (node
) == VAR_DECL
&& TREE_STATIC (node
))
6830 || (TREE_CODE (node
) == TYPE_DECL
))
6832 TREE_USED (node
) = 1;
6833 DECL_PRESERVE_P (node
) = 1;
6834 if (TREE_CODE (node
) == VAR_DECL
)
6835 DECL_READ_P (node
) = 1;
6839 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6840 *no_add_attrs
= true;
6846 /* Handle a "unused" attribute; arguments as in
6847 struct attribute_spec.handler. */
6850 handle_unused_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6851 int flags
, bool *no_add_attrs
)
6857 if (TREE_CODE (decl
) == PARM_DECL
6858 || TREE_CODE (decl
) == VAR_DECL
6859 || TREE_CODE (decl
) == FUNCTION_DECL
6860 || TREE_CODE (decl
) == LABEL_DECL
6861 || TREE_CODE (decl
) == TYPE_DECL
)
6863 TREE_USED (decl
) = 1;
6864 if (TREE_CODE (decl
) == VAR_DECL
6865 || TREE_CODE (decl
) == PARM_DECL
)
6866 DECL_READ_P (decl
) = 1;
6870 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6871 *no_add_attrs
= true;
6876 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6877 *node
= build_variant_type_copy (*node
);
6878 TREE_USED (*node
) = 1;
6884 /* Handle a "externally_visible" attribute; arguments as in
6885 struct attribute_spec.handler. */
6888 handle_externally_visible_attribute (tree
*pnode
, tree name
,
6889 tree
ARG_UNUSED (args
),
6890 int ARG_UNUSED (flags
),
6895 if (TREE_CODE (node
) == FUNCTION_DECL
|| TREE_CODE (node
) == VAR_DECL
)
6897 if ((!TREE_STATIC (node
) && TREE_CODE (node
) != FUNCTION_DECL
6898 && !DECL_EXTERNAL (node
)) || !TREE_PUBLIC (node
))
6900 warning (OPT_Wattributes
,
6901 "%qE attribute have effect only on public objects", name
);
6902 *no_add_attrs
= true;
6907 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6908 *no_add_attrs
= true;
6914 /* Handle a "const" attribute; arguments as in
6915 struct attribute_spec.handler. */
6918 handle_const_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6919 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6921 tree type
= TREE_TYPE (*node
);
6923 /* See FIXME comment on noreturn in c_common_attribute_table. */
6924 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6925 TREE_READONLY (*node
) = 1;
6926 else if (TREE_CODE (type
) == POINTER_TYPE
6927 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
6929 = build_pointer_type
6930 (build_type_variant (TREE_TYPE (type
), 1,
6931 TREE_THIS_VOLATILE (TREE_TYPE (type
))));
6934 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6935 *no_add_attrs
= true;
6941 /* Handle a "transparent_union" attribute; arguments as in
6942 struct attribute_spec.handler. */
6945 handle_transparent_union_attribute (tree
*node
, tree name
,
6946 tree
ARG_UNUSED (args
), int flags
,
6951 *no_add_attrs
= true;
6954 if (TREE_CODE (*node
) == TYPE_DECL
6955 && ! (flags
& ATTR_FLAG_CXX11
))
6956 node
= &TREE_TYPE (*node
);
6959 if (TREE_CODE (type
) == UNION_TYPE
)
6961 /* Make sure that the first field will work for a transparent union.
6962 If the type isn't complete yet, leave the check to the code in
6964 if (TYPE_SIZE (type
))
6966 tree first
= first_field (type
);
6967 if (first
== NULL_TREE
6968 || DECL_ARTIFICIAL (first
)
6969 || TYPE_MODE (type
) != DECL_MODE (first
))
6973 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6975 /* If the type isn't complete yet, setting the flag
6976 on a variant wouldn't ever be checked. */
6977 if (!TYPE_SIZE (type
))
6980 /* build_duplicate_type doesn't work for C++. */
6981 if (c_dialect_cxx ())
6984 /* A type variant isn't good enough, since we don't a cast
6985 to such a type removed as a no-op. */
6986 *node
= type
= build_duplicate_type (type
);
6989 TYPE_TRANSPARENT_AGGR (type
) = 1;
6994 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6998 /* Subroutine of handle_{con,de}structor_attribute. Evaluate ARGS to
6999 get the requested priority for a constructor or destructor,
7000 possibly issuing diagnostics for invalid or reserved
7003 static priority_type
7004 get_priority (tree args
, bool is_destructor
)
7010 return DEFAULT_INIT_PRIORITY
;
7012 if (!SUPPORTS_INIT_PRIORITY
)
7015 error ("destructor priorities are not supported");
7017 error ("constructor priorities are not supported");
7018 return DEFAULT_INIT_PRIORITY
;
7021 arg
= TREE_VALUE (args
);
7022 if (TREE_CODE (arg
) == IDENTIFIER_NODE
)
7024 if (arg
== error_mark_node
)
7025 return DEFAULT_INIT_PRIORITY
;
7026 arg
= default_conversion (arg
);
7027 if (!tree_fits_shwi_p (arg
)
7028 || !INTEGRAL_TYPE_P (TREE_TYPE (arg
)))
7031 pri
= tree_to_shwi (arg
);
7032 if (pri
< 0 || pri
> MAX_INIT_PRIORITY
)
7035 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
7039 "destructor priorities from 0 to %d are reserved "
7040 "for the implementation",
7041 MAX_RESERVED_INIT_PRIORITY
);
7044 "constructor priorities from 0 to %d are reserved "
7045 "for the implementation",
7046 MAX_RESERVED_INIT_PRIORITY
);
7052 error ("destructor priorities must be integers from 0 to %d inclusive",
7055 error ("constructor priorities must be integers from 0 to %d inclusive",
7057 return DEFAULT_INIT_PRIORITY
;
7060 /* Handle a "constructor" attribute; arguments as in
7061 struct attribute_spec.handler. */
7064 handle_constructor_attribute (tree
*node
, tree name
, tree args
,
7065 int ARG_UNUSED (flags
),
7069 tree type
= TREE_TYPE (decl
);
7071 if (TREE_CODE (decl
) == FUNCTION_DECL
7072 && TREE_CODE (type
) == FUNCTION_TYPE
7073 && decl_function_context (decl
) == 0)
7075 priority_type priority
;
7076 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
7077 priority
= get_priority (args
, /*is_destructor=*/false);
7078 SET_DECL_INIT_PRIORITY (decl
, priority
);
7079 TREE_USED (decl
) = 1;
7083 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7084 *no_add_attrs
= true;
7090 /* Handle a "destructor" attribute; arguments as in
7091 struct attribute_spec.handler. */
7094 handle_destructor_attribute (tree
*node
, tree name
, tree args
,
7095 int ARG_UNUSED (flags
),
7099 tree type
= TREE_TYPE (decl
);
7101 if (TREE_CODE (decl
) == FUNCTION_DECL
7102 && TREE_CODE (type
) == FUNCTION_TYPE
7103 && decl_function_context (decl
) == 0)
7105 priority_type priority
;
7106 DECL_STATIC_DESTRUCTOR (decl
) = 1;
7107 priority
= get_priority (args
, /*is_destructor=*/true);
7108 SET_DECL_FINI_PRIORITY (decl
, priority
);
7109 TREE_USED (decl
) = 1;
7113 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7114 *no_add_attrs
= true;
7120 /* Nonzero if the mode is a valid vector mode for this architecture.
7121 This returns nonzero even if there is no hardware support for the
7122 vector mode, but we can emulate with narrower modes. */
7125 vector_mode_valid_p (enum machine_mode mode
)
7127 enum mode_class mclass
= GET_MODE_CLASS (mode
);
7128 enum machine_mode innermode
;
7130 /* Doh! What's going on? */
7131 if (mclass
!= MODE_VECTOR_INT
7132 && mclass
!= MODE_VECTOR_FLOAT
7133 && mclass
!= MODE_VECTOR_FRACT
7134 && mclass
!= MODE_VECTOR_UFRACT
7135 && mclass
!= MODE_VECTOR_ACCUM
7136 && mclass
!= MODE_VECTOR_UACCUM
)
7139 /* Hardware support. Woo hoo! */
7140 if (targetm
.vector_mode_supported_p (mode
))
7143 innermode
= GET_MODE_INNER (mode
);
7145 /* We should probably return 1 if requesting V4DI and we have no DI,
7146 but we have V2DI, but this is probably very unlikely. */
7148 /* If we have support for the inner mode, we can safely emulate it.
7149 We may not have V2DI, but me can emulate with a pair of DIs. */
7150 return targetm
.scalar_mode_supported_p (innermode
);
7154 /* Handle a "mode" attribute; arguments as in
7155 struct attribute_spec.handler. */
7158 handle_mode_attribute (tree
*node
, tree name
, tree args
,
7159 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7162 tree ident
= TREE_VALUE (args
);
7164 *no_add_attrs
= true;
7166 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
7167 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7171 const char *p
= IDENTIFIER_POINTER (ident
);
7172 int len
= strlen (p
);
7173 enum machine_mode mode
= VOIDmode
;
7177 if (len
> 4 && p
[0] == '_' && p
[1] == '_'
7178 && p
[len
- 1] == '_' && p
[len
- 2] == '_')
7180 char *newp
= (char *) alloca (len
- 1);
7182 strcpy (newp
, &p
[2]);
7183 newp
[len
- 4] = '\0';
7187 /* Change this type to have a type with the specified mode.
7188 First check for the special modes. */
7189 if (!strcmp (p
, "byte"))
7191 else if (!strcmp (p
, "word"))
7193 else if (!strcmp (p
, "pointer"))
7195 else if (!strcmp (p
, "libgcc_cmp_return"))
7196 mode
= targetm
.libgcc_cmp_return_mode ();
7197 else if (!strcmp (p
, "libgcc_shift_count"))
7198 mode
= targetm
.libgcc_shift_count_mode ();
7199 else if (!strcmp (p
, "unwind_word"))
7200 mode
= targetm
.unwind_word_mode ();
7202 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
7203 if (!strcmp (p
, GET_MODE_NAME (j
)))
7205 mode
= (enum machine_mode
) j
;
7209 if (mode
== VOIDmode
)
7211 error ("unknown machine mode %qE", ident
);
7216 switch (GET_MODE_CLASS (mode
))
7219 case MODE_PARTIAL_INT
:
7221 case MODE_DECIMAL_FLOAT
:
7226 valid_mode
= targetm
.scalar_mode_supported_p (mode
);
7229 case MODE_COMPLEX_INT
:
7230 case MODE_COMPLEX_FLOAT
:
7231 valid_mode
= targetm
.scalar_mode_supported_p (GET_MODE_INNER (mode
));
7234 case MODE_VECTOR_INT
:
7235 case MODE_VECTOR_FLOAT
:
7236 case MODE_VECTOR_FRACT
:
7237 case MODE_VECTOR_UFRACT
:
7238 case MODE_VECTOR_ACCUM
:
7239 case MODE_VECTOR_UACCUM
:
7240 warning (OPT_Wattributes
, "specifying vector types with "
7241 "__attribute__ ((mode)) is deprecated");
7242 warning (OPT_Wattributes
,
7243 "use __attribute__ ((vector_size)) instead");
7244 valid_mode
= vector_mode_valid_p (mode
);
7252 error ("unable to emulate %qs", p
);
7256 if (POINTER_TYPE_P (type
))
7258 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
7259 tree (*fn
)(tree
, enum machine_mode
, bool);
7261 if (!targetm
.addr_space
.valid_pointer_mode (mode
, as
))
7263 error ("invalid pointer mode %qs", p
);
7267 if (TREE_CODE (type
) == POINTER_TYPE
)
7268 fn
= build_pointer_type_for_mode
;
7270 fn
= build_reference_type_for_mode
;
7271 typefm
= fn (TREE_TYPE (type
), mode
, false);
7275 /* For fixed-point modes, we need to test if the signness of type
7276 and the machine mode are consistent. */
7277 if (ALL_FIXED_POINT_MODE_P (mode
)
7278 && TYPE_UNSIGNED (type
) != UNSIGNED_FIXED_POINT_MODE_P (mode
))
7280 error ("signedness of type and machine mode %qs don%'t match", p
);
7283 /* For fixed-point modes, we need to pass saturating info. */
7284 typefm
= lang_hooks
.types
.type_for_mode (mode
,
7285 ALL_FIXED_POINT_MODE_P (mode
) ? TYPE_SATURATING (type
)
7286 : TYPE_UNSIGNED (type
));
7289 if (typefm
== NULL_TREE
)
7291 error ("no data type for mode %qs", p
);
7294 else if (TREE_CODE (type
) == ENUMERAL_TYPE
)
7296 /* For enumeral types, copy the precision from the integer
7297 type returned above. If not an INTEGER_TYPE, we can't use
7298 this mode for this type. */
7299 if (TREE_CODE (typefm
) != INTEGER_TYPE
)
7301 error ("cannot use mode %qs for enumeral types", p
);
7305 if (flags
& ATTR_FLAG_TYPE_IN_PLACE
)
7307 TYPE_PRECISION (type
) = TYPE_PRECISION (typefm
);
7312 /* We cannot build a type variant, as there's code that assumes
7313 that TYPE_MAIN_VARIANT has the same mode. This includes the
7314 debug generators. Instead, create a subrange type. This
7315 results in all of the enumeral values being emitted only once
7316 in the original, and the subtype gets them by reference. */
7317 if (TYPE_UNSIGNED (type
))
7318 typefm
= make_unsigned_type (TYPE_PRECISION (typefm
));
7320 typefm
= make_signed_type (TYPE_PRECISION (typefm
));
7321 TREE_TYPE (typefm
) = type
;
7324 else if (VECTOR_MODE_P (mode
)
7325 ? TREE_CODE (type
) != TREE_CODE (TREE_TYPE (typefm
))
7326 : TREE_CODE (type
) != TREE_CODE (typefm
))
7328 error ("mode %qs applied to inappropriate type", p
);
7338 /* Handle a "section" attribute; arguments as in
7339 struct attribute_spec.handler. */
7342 handle_section_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7343 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7347 if (targetm_common
.have_named_sections
)
7349 user_defined_section_attribute
= true;
7351 if ((TREE_CODE (decl
) == FUNCTION_DECL
7352 || TREE_CODE (decl
) == VAR_DECL
)
7353 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
7355 if (TREE_CODE (decl
) == VAR_DECL
7356 && current_function_decl
!= NULL_TREE
7357 && !TREE_STATIC (decl
))
7359 error_at (DECL_SOURCE_LOCATION (decl
),
7360 "section attribute cannot be specified for "
7362 *no_add_attrs
= true;
7365 /* The decl may have already been given a section attribute
7366 from a previous declaration. Ensure they match. */
7367 else if (DECL_SECTION_NAME (decl
) != NULL_TREE
7368 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl
)),
7369 TREE_STRING_POINTER (TREE_VALUE (args
))) != 0)
7371 error ("section of %q+D conflicts with previous declaration",
7373 *no_add_attrs
= true;
7375 else if (TREE_CODE (decl
) == VAR_DECL
7376 && !targetm
.have_tls
&& targetm
.emutls
.tmpl_section
7377 && DECL_THREAD_LOCAL_P (decl
))
7379 error ("section of %q+D cannot be overridden", *node
);
7380 *no_add_attrs
= true;
7383 DECL_SECTION_NAME (decl
) = TREE_VALUE (args
);
7387 error ("section attribute not allowed for %q+D", *node
);
7388 *no_add_attrs
= true;
7393 error_at (DECL_SOURCE_LOCATION (*node
),
7394 "section attributes are not supported for this target");
7395 *no_add_attrs
= true;
7401 /* Check whether ALIGN is a valid user-specified alignment. If so,
7402 return its base-2 log; if not, output an error and return -1. If
7403 ALLOW_ZERO then 0 is valid and should result in a return of -1 with
7406 check_user_alignment (const_tree align
, bool allow_zero
)
7410 if (TREE_CODE (align
) != INTEGER_CST
7411 || !INTEGRAL_TYPE_P (TREE_TYPE (align
)))
7413 error ("requested alignment is not an integer constant");
7416 else if (allow_zero
&& integer_zerop (align
))
7418 else if (tree_int_cst_sgn (align
) == -1
7419 || (i
= tree_log2 (align
)) == -1)
7421 error ("requested alignment is not a positive power of 2");
7424 else if (i
>= HOST_BITS_PER_INT
- BITS_PER_UNIT_LOG
)
7426 error ("requested alignment is too large");
7433 If in c++-11, check if the c++-11 alignment constraint with respect
7434 to fundamental alignment (in [dcl.align]) are satisfied. If not in
7435 c++-11 mode, does nothing.
7439 [* if the constant expression evaluates to a fundamental alignment,
7440 the alignment requirement of the declared entity shall be the
7441 specified fundamental alignment.
7443 * if the constant expression evaluates to an extended alignment
7444 and the implementation supports that alignment in the context
7445 of the declaration, the alignment of the declared entity shall
7448 * if the constant expression evaluates to an extended alignment
7449 and the implementation does not support that alignment in the
7450 context of the declaration, the program is ill-formed]. */
7453 check_cxx_fundamental_alignment_constraints (tree node
,
7457 bool alignment_too_large_p
= false;
7458 unsigned requested_alignment
= 1U << align_log
;
7459 unsigned max_align
= 0;
7461 if ((!(flags
& ATTR_FLAG_CXX11
) && !warn_cxx_compat
)
7462 || (node
== NULL_TREE
|| node
== error_mark_node
))
7465 if (cxx_fundamental_alignment_p (requested_alignment
))
7470 if (TREE_STATIC (node
))
7472 /* For file scope variables and static members, the target
7473 supports alignments that are at most
7474 MAX_OFILE_ALIGNMENT. */
7475 if (requested_alignment
> (max_align
= MAX_OFILE_ALIGNMENT
))
7476 alignment_too_large_p
= true;
7480 #ifdef BIGGEST_FIELD_ALIGNMENT
7481 #define MAX_TARGET_FIELD_ALIGNMENT BIGGEST_FIELD_ALIGNMENT
7483 #define MAX_TARGET_FIELD_ALIGNMENT BIGGEST_ALIGNMENT
7485 /* For non-static members, the target supports either
7486 alignments that at most either BIGGEST_FIELD_ALIGNMENT
7487 if it is defined or BIGGEST_ALIGNMENT. */
7488 max_align
= MAX_TARGET_FIELD_ALIGNMENT
;
7489 if (TREE_CODE (node
) == FIELD_DECL
7490 && requested_alignment
> (max_align
= MAX_TARGET_FIELD_ALIGNMENT
))
7491 alignment_too_large_p
= true;
7492 #undef MAX_TARGET_FIELD_ALIGNMENT
7493 /* For stack variables, the target supports at most
7494 MAX_STACK_ALIGNMENT. */
7495 else if (decl_function_context (node
) != NULL
7496 && requested_alignment
> (max_align
= MAX_STACK_ALIGNMENT
))
7497 alignment_too_large_p
= true;
7500 else if (TYPE_P (node
))
7502 /* Let's be liberal for types. */
7503 if (requested_alignment
> (max_align
= BIGGEST_ALIGNMENT
))
7504 alignment_too_large_p
= true;
7507 if (alignment_too_large_p
)
7508 pedwarn (input_location
, OPT_Wattributes
,
7509 "requested alignment %d is larger than %d",
7510 requested_alignment
, max_align
);
7512 return !alignment_too_large_p
;
7515 /* Handle a "aligned" attribute; arguments as in
7516 struct attribute_spec.handler. */
7519 handle_aligned_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7520 int flags
, bool *no_add_attrs
)
7522 tree decl
= NULL_TREE
;
7525 tree align_expr
= (args
? TREE_VALUE (args
)
7526 : size_int (ATTRIBUTE_ALIGNED_VALUE
/ BITS_PER_UNIT
));
7532 type
= &TREE_TYPE (decl
);
7533 is_type
= TREE_CODE (*node
) == TYPE_DECL
;
7535 else if (TYPE_P (*node
))
7536 type
= node
, is_type
= 1;
7538 if ((i
= check_user_alignment (align_expr
, false)) == -1
7539 || !check_cxx_fundamental_alignment_constraints (*node
, i
, flags
))
7540 *no_add_attrs
= true;
7543 if ((flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7544 /* OK, modify the type in place. */;
7545 /* If we have a TYPE_DECL, then copy the type, so that we
7546 don't accidentally modify a builtin type. See pushdecl. */
7547 else if (decl
&& TREE_TYPE (decl
) != error_mark_node
7548 && DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
)
7550 tree tt
= TREE_TYPE (decl
);
7551 *type
= build_variant_type_copy (*type
);
7552 DECL_ORIGINAL_TYPE (decl
) = tt
;
7553 TYPE_NAME (*type
) = decl
;
7554 TREE_USED (*type
) = TREE_USED (decl
);
7555 TREE_TYPE (decl
) = *type
;
7558 *type
= build_variant_type_copy (*type
);
7560 TYPE_ALIGN (*type
) = (1U << i
) * BITS_PER_UNIT
;
7561 TYPE_USER_ALIGN (*type
) = 1;
7563 else if (! VAR_OR_FUNCTION_DECL_P (decl
)
7564 && TREE_CODE (decl
) != FIELD_DECL
)
7566 error ("alignment may not be specified for %q+D", decl
);
7567 *no_add_attrs
= true;
7569 else if (DECL_USER_ALIGN (decl
)
7570 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
7571 /* C++-11 [dcl.align/4]:
7573 When multiple alignment-specifiers are specified for an
7574 entity, the alignment requirement shall be set to the
7575 strictest specified alignment.
7577 This formally comes from the c++11 specification but we are
7578 doing it for the GNU attribute syntax as well. */
7579 *no_add_attrs
= true;
7580 else if (TREE_CODE (decl
) == FUNCTION_DECL
7581 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
7583 if (DECL_USER_ALIGN (decl
))
7584 error ("alignment for %q+D was previously specified as %d "
7585 "and may not be decreased", decl
,
7586 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
7588 error ("alignment for %q+D must be at least %d", decl
,
7589 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
7590 *no_add_attrs
= true;
7594 DECL_ALIGN (decl
) = (1U << i
) * BITS_PER_UNIT
;
7595 DECL_USER_ALIGN (decl
) = 1;
7601 /* Handle a "weak" attribute; arguments as in
7602 struct attribute_spec.handler. */
7605 handle_weak_attribute (tree
*node
, tree name
,
7606 tree
ARG_UNUSED (args
),
7607 int ARG_UNUSED (flags
),
7608 bool * ARG_UNUSED (no_add_attrs
))
7610 if (TREE_CODE (*node
) == FUNCTION_DECL
7611 && DECL_DECLARED_INLINE_P (*node
))
7613 warning (OPT_Wattributes
, "inline function %q+D declared weak", *node
);
7614 *no_add_attrs
= true;
7616 else if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
7618 error ("indirect function %q+D cannot be declared weak", *node
);
7619 *no_add_attrs
= true;
7622 else if (TREE_CODE (*node
) == FUNCTION_DECL
7623 || TREE_CODE (*node
) == VAR_DECL
)
7624 declare_weak (*node
);
7626 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7631 /* Handle an "alias" or "ifunc" attribute; arguments as in
7632 struct attribute_spec.handler, except that IS_ALIAS tells us
7633 whether this is an alias as opposed to ifunc attribute. */
7636 handle_alias_ifunc_attribute (bool is_alias
, tree
*node
, tree name
, tree args
,
7641 if (TREE_CODE (decl
) != FUNCTION_DECL
7642 && (!is_alias
|| TREE_CODE (decl
) != VAR_DECL
))
7644 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7645 *no_add_attrs
= true;
7647 else if ((TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INITIAL (decl
))
7648 || (TREE_CODE (decl
) != FUNCTION_DECL
7649 && TREE_PUBLIC (decl
) && !DECL_EXTERNAL (decl
))
7650 /* A static variable declaration is always a tentative definition,
7651 but the alias is a non-tentative definition which overrides. */
7652 || (TREE_CODE (decl
) != FUNCTION_DECL
7653 && ! TREE_PUBLIC (decl
) && DECL_INITIAL (decl
)))
7655 error ("%q+D defined both normally and as %qE attribute", decl
, name
);
7656 *no_add_attrs
= true;
7660 && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
7661 || lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
))))
7663 error ("weak %q+D cannot be defined %qE", decl
, name
);
7664 *no_add_attrs
= true;
7668 /* Note that the very first time we process a nested declaration,
7669 decl_function_context will not be set. Indeed, *would* never
7670 be set except for the DECL_INITIAL/DECL_EXTERNAL frobbery that
7671 we do below. After such frobbery, pushdecl would set the context.
7672 In any case, this is never what we want. */
7673 else if (decl_function_context (decl
) == 0 && current_function_decl
== NULL
)
7677 id
= TREE_VALUE (args
);
7678 if (TREE_CODE (id
) != STRING_CST
)
7680 error ("attribute %qE argument not a string", name
);
7681 *no_add_attrs
= true;
7684 id
= get_identifier (TREE_STRING_POINTER (id
));
7685 /* This counts as a use of the object pointed to. */
7688 if (TREE_CODE (decl
) == FUNCTION_DECL
)
7689 DECL_INITIAL (decl
) = error_mark_node
;
7691 TREE_STATIC (decl
) = 1;
7694 /* ifuncs are also aliases, so set that attribute too. */
7695 DECL_ATTRIBUTES (decl
)
7696 = tree_cons (get_identifier ("alias"), args
, DECL_ATTRIBUTES (decl
));
7700 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7701 *no_add_attrs
= true;
7707 /* Handle an "alias" or "ifunc" attribute; arguments as in
7708 struct attribute_spec.handler. */
7711 handle_ifunc_attribute (tree
*node
, tree name
, tree args
,
7712 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7714 return handle_alias_ifunc_attribute (false, node
, name
, args
, no_add_attrs
);
7717 /* Handle an "alias" or "ifunc" attribute; arguments as in
7718 struct attribute_spec.handler. */
7721 handle_alias_attribute (tree
*node
, tree name
, tree args
,
7722 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7724 return handle_alias_ifunc_attribute (true, node
, name
, args
, no_add_attrs
);
7727 /* Handle a "weakref" attribute; arguments as in struct
7728 attribute_spec.handler. */
7731 handle_weakref_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7732 int flags
, bool *no_add_attrs
)
7734 tree attr
= NULL_TREE
;
7736 /* We must ignore the attribute when it is associated with
7737 local-scoped decls, since attribute alias is ignored and many
7738 such symbols do not even have a DECL_WEAK field. */
7739 if (decl_function_context (*node
)
7740 || current_function_decl
7741 || (TREE_CODE (*node
) != VAR_DECL
&& TREE_CODE (*node
) != FUNCTION_DECL
))
7743 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7744 *no_add_attrs
= true;
7748 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
7750 error ("indirect function %q+D cannot be declared weakref", *node
);
7751 *no_add_attrs
= true;
7755 /* The idea here is that `weakref("name")' mutates into `weakref,
7756 alias("name")', and weakref without arguments, in turn,
7757 implicitly adds weak. */
7761 attr
= tree_cons (get_identifier ("alias"), args
, attr
);
7762 attr
= tree_cons (get_identifier ("weakref"), NULL_TREE
, attr
);
7764 *no_add_attrs
= true;
7766 decl_attributes (node
, attr
, flags
);
7770 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node
)))
7771 error_at (DECL_SOURCE_LOCATION (*node
),
7772 "weakref attribute must appear before alias attribute");
7774 /* Can't call declare_weak because it wants this to be TREE_PUBLIC,
7775 and that isn't supported; and because it wants to add it to
7776 the list of weak decls, which isn't helpful. */
7777 DECL_WEAK (*node
) = 1;
7783 /* Handle an "visibility" attribute; arguments as in
7784 struct attribute_spec.handler. */
7787 handle_visibility_attribute (tree
*node
, tree name
, tree args
,
7788 int ARG_UNUSED (flags
),
7789 bool *ARG_UNUSED (no_add_attrs
))
7792 tree id
= TREE_VALUE (args
);
7793 enum symbol_visibility vis
;
7797 if (TREE_CODE (*node
) == ENUMERAL_TYPE
)
7799 else if (TREE_CODE (*node
) != RECORD_TYPE
&& TREE_CODE (*node
) != UNION_TYPE
)
7801 warning (OPT_Wattributes
, "%qE attribute ignored on non-class types",
7805 else if (TYPE_FIELDS (*node
))
7807 error ("%qE attribute ignored because %qT is already defined",
7812 else if (decl_function_context (decl
) != 0 || !TREE_PUBLIC (decl
))
7814 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7818 if (TREE_CODE (id
) != STRING_CST
)
7820 error ("visibility argument not a string");
7824 /* If this is a type, set the visibility on the type decl. */
7827 decl
= TYPE_NAME (decl
);
7830 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
7832 warning (OPT_Wattributes
, "%qE attribute ignored on types",
7838 if (strcmp (TREE_STRING_POINTER (id
), "default") == 0)
7839 vis
= VISIBILITY_DEFAULT
;
7840 else if (strcmp (TREE_STRING_POINTER (id
), "internal") == 0)
7841 vis
= VISIBILITY_INTERNAL
;
7842 else if (strcmp (TREE_STRING_POINTER (id
), "hidden") == 0)
7843 vis
= VISIBILITY_HIDDEN
;
7844 else if (strcmp (TREE_STRING_POINTER (id
), "protected") == 0)
7845 vis
= VISIBILITY_PROTECTED
;
7848 error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
7849 vis
= VISIBILITY_DEFAULT
;
7852 if (DECL_VISIBILITY_SPECIFIED (decl
)
7853 && vis
!= DECL_VISIBILITY (decl
))
7855 tree attributes
= (TYPE_P (*node
)
7856 ? TYPE_ATTRIBUTES (*node
)
7857 : DECL_ATTRIBUTES (decl
));
7858 if (lookup_attribute ("visibility", attributes
))
7859 error ("%qD redeclared with different visibility", decl
);
7860 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
7861 && lookup_attribute ("dllimport", attributes
))
7862 error ("%qD was declared %qs which implies default visibility",
7864 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
7865 && lookup_attribute ("dllexport", attributes
))
7866 error ("%qD was declared %qs which implies default visibility",
7870 DECL_VISIBILITY (decl
) = vis
;
7871 DECL_VISIBILITY_SPECIFIED (decl
) = 1;
7873 /* Go ahead and attach the attribute to the node as well. This is needed
7874 so we can determine whether we have VISIBILITY_DEFAULT because the
7875 visibility was not specified, or because it was explicitly overridden
7876 from the containing scope. */
7881 /* Determine the ELF symbol visibility for DECL, which is either a
7882 variable or a function. It is an error to use this function if a
7883 definition of DECL is not available in this translation unit.
7884 Returns true if the final visibility has been determined by this
7885 function; false if the caller is free to make additional
7889 c_determine_visibility (tree decl
)
7891 gcc_assert (TREE_CODE (decl
) == VAR_DECL
7892 || TREE_CODE (decl
) == FUNCTION_DECL
);
7894 /* If the user explicitly specified the visibility with an
7895 attribute, honor that. DECL_VISIBILITY will have been set during
7896 the processing of the attribute. We check for an explicit
7897 attribute, rather than just checking DECL_VISIBILITY_SPECIFIED,
7898 to distinguish the use of an attribute from the use of a "#pragma
7899 GCC visibility push(...)"; in the latter case we still want other
7900 considerations to be able to overrule the #pragma. */
7901 if (lookup_attribute ("visibility", DECL_ATTRIBUTES (decl
))
7902 || (TARGET_DLLIMPORT_DECL_ATTRIBUTES
7903 && (lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl
))
7904 || lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl
)))))
7907 /* Set default visibility to whatever the user supplied with
7908 visibility_specified depending on #pragma GCC visibility. */
7909 if (!DECL_VISIBILITY_SPECIFIED (decl
))
7911 if (visibility_options
.inpragma
7912 || DECL_VISIBILITY (decl
) != default_visibility
)
7914 DECL_VISIBILITY (decl
) = default_visibility
;
7915 DECL_VISIBILITY_SPECIFIED (decl
) = visibility_options
.inpragma
;
7916 /* If visibility changed and DECL already has DECL_RTL, ensure
7917 symbol flags are updated. */
7918 if (((TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
))
7919 || TREE_CODE (decl
) == FUNCTION_DECL
)
7920 && DECL_RTL_SET_P (decl
))
7921 make_decl_rtl (decl
);
7927 /* Handle an "tls_model" attribute; arguments as in
7928 struct attribute_spec.handler. */
7931 handle_tls_model_attribute (tree
*node
, tree name
, tree args
,
7932 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7936 enum tls_model kind
;
7938 *no_add_attrs
= true;
7940 if (TREE_CODE (decl
) != VAR_DECL
|| !DECL_THREAD_LOCAL_P (decl
))
7942 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7946 kind
= DECL_TLS_MODEL (decl
);
7947 id
= TREE_VALUE (args
);
7948 if (TREE_CODE (id
) != STRING_CST
)
7950 error ("tls_model argument not a string");
7954 if (!strcmp (TREE_STRING_POINTER (id
), "local-exec"))
7955 kind
= TLS_MODEL_LOCAL_EXEC
;
7956 else if (!strcmp (TREE_STRING_POINTER (id
), "initial-exec"))
7957 kind
= TLS_MODEL_INITIAL_EXEC
;
7958 else if (!strcmp (TREE_STRING_POINTER (id
), "local-dynamic"))
7959 kind
= optimize
? TLS_MODEL_LOCAL_DYNAMIC
: TLS_MODEL_GLOBAL_DYNAMIC
;
7960 else if (!strcmp (TREE_STRING_POINTER (id
), "global-dynamic"))
7961 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
7963 error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
7965 DECL_TLS_MODEL (decl
) = kind
;
7969 /* Handle a "no_instrument_function" attribute; arguments as in
7970 struct attribute_spec.handler. */
7973 handle_no_instrument_function_attribute (tree
*node
, tree name
,
7974 tree
ARG_UNUSED (args
),
7975 int ARG_UNUSED (flags
),
7980 if (TREE_CODE (decl
) != FUNCTION_DECL
)
7982 error_at (DECL_SOURCE_LOCATION (decl
),
7983 "%qE attribute applies only to functions", name
);
7984 *no_add_attrs
= true;
7986 else if (DECL_INITIAL (decl
))
7988 error_at (DECL_SOURCE_LOCATION (decl
),
7989 "can%'t set %qE attribute after definition", name
);
7990 *no_add_attrs
= true;
7993 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
7998 /* Handle a "malloc" attribute; arguments as in
7999 struct attribute_spec.handler. */
8002 handle_malloc_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8003 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8005 if (TREE_CODE (*node
) == FUNCTION_DECL
8006 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node
))))
8007 DECL_IS_MALLOC (*node
) = 1;
8010 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8011 *no_add_attrs
= true;
8017 /* Handle a "alloc_size" attribute; arguments as in
8018 struct attribute_spec.handler. */
8021 handle_alloc_size_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
8022 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8024 unsigned arg_count
= type_num_arguments (*node
);
8025 for (; args
; args
= TREE_CHAIN (args
))
8027 tree position
= TREE_VALUE (args
);
8029 if (TREE_CODE (position
) != INTEGER_CST
8030 || TREE_INT_CST_HIGH (position
)
8031 || TREE_INT_CST_LOW (position
) < 1
8032 || TREE_INT_CST_LOW (position
) > arg_count
)
8034 warning (OPT_Wattributes
,
8035 "alloc_size parameter outside range");
8036 *no_add_attrs
= true;
8043 /* Handle a "fn spec" attribute; arguments as in
8044 struct attribute_spec.handler. */
8047 handle_fnspec_attribute (tree
*node ATTRIBUTE_UNUSED
, tree
ARG_UNUSED (name
),
8048 tree args
, int ARG_UNUSED (flags
),
8049 bool *no_add_attrs ATTRIBUTE_UNUSED
)
8052 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
8053 && !TREE_CHAIN (args
));
8057 /* Handle a "warn_unused" attribute; arguments as in
8058 struct attribute_spec.handler. */
8061 handle_warn_unused_attribute (tree
*node
, tree name
,
8062 tree args ATTRIBUTE_UNUSED
,
8063 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
8066 /* Do nothing else, just set the attribute. We'll get at
8067 it later with lookup_attribute. */
8071 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8072 *no_add_attrs
= true;
8078 /* Handle an "omp declare simd" attribute; arguments as in
8079 struct attribute_spec.handler. */
8082 handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int, bool *)
8087 /* Handle an "omp declare target" attribute; arguments as in
8088 struct attribute_spec.handler. */
8091 handle_omp_declare_target_attribute (tree
*, tree
, tree
, int, bool *)
8096 /* Handle a "returns_twice" attribute; arguments as in
8097 struct attribute_spec.handler. */
8100 handle_returns_twice_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8101 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8103 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8104 DECL_IS_RETURNS_TWICE (*node
) = 1;
8107 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8108 *no_add_attrs
= true;
8114 /* Handle a "no_limit_stack" attribute; arguments as in
8115 struct attribute_spec.handler. */
8118 handle_no_limit_stack_attribute (tree
*node
, tree name
,
8119 tree
ARG_UNUSED (args
),
8120 int ARG_UNUSED (flags
),
8125 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8127 error_at (DECL_SOURCE_LOCATION (decl
),
8128 "%qE attribute applies only to functions", name
);
8129 *no_add_attrs
= true;
8131 else if (DECL_INITIAL (decl
))
8133 error_at (DECL_SOURCE_LOCATION (decl
),
8134 "can%'t set %qE attribute after definition", name
);
8135 *no_add_attrs
= true;
8138 DECL_NO_LIMIT_STACK (decl
) = 1;
8143 /* Handle a "pure" attribute; arguments as in
8144 struct attribute_spec.handler. */
8147 handle_pure_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8148 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8150 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8151 DECL_PURE_P (*node
) = 1;
8152 /* ??? TODO: Support types. */
8155 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8156 *no_add_attrs
= true;
8162 /* Digest an attribute list destined for a transactional memory statement.
8163 ALLOWED is the set of attributes that are allowed for this statement;
8164 return the attribute we parsed. Multiple attributes are never allowed. */
8167 parse_tm_stmt_attr (tree attrs
, int allowed
)
8172 for ( ; attrs
; attrs
= TREE_CHAIN (attrs
))
8174 tree a
= TREE_PURPOSE (attrs
);
8177 if (is_attribute_p ("outer", a
))
8178 m
= TM_STMT_ATTR_OUTER
;
8180 if ((m
& allowed
) == 0)
8182 warning (OPT_Wattributes
, "%qE attribute directive ignored", a
);
8191 else if (m_seen
== m
)
8192 warning (OPT_Wattributes
, "%qE attribute duplicated", a
);
8194 warning (OPT_Wattributes
, "%qE attribute follows %qE", a
, a_seen
);
8200 /* Transform a TM attribute name into a maskable integer and back.
8201 Note that NULL (i.e. no attribute) is mapped to UNKNOWN, corresponding
8202 to how the lack of an attribute is treated. */
8205 tm_attr_to_mask (tree attr
)
8209 if (is_attribute_p ("transaction_safe", attr
))
8210 return TM_ATTR_SAFE
;
8211 if (is_attribute_p ("transaction_callable", attr
))
8212 return TM_ATTR_CALLABLE
;
8213 if (is_attribute_p ("transaction_pure", attr
))
8214 return TM_ATTR_PURE
;
8215 if (is_attribute_p ("transaction_unsafe", attr
))
8216 return TM_ATTR_IRREVOCABLE
;
8217 if (is_attribute_p ("transaction_may_cancel_outer", attr
))
8218 return TM_ATTR_MAY_CANCEL_OUTER
;
8223 tm_mask_to_attr (int mask
)
8229 str
= "transaction_safe";
8231 case TM_ATTR_CALLABLE
:
8232 str
= "transaction_callable";
8235 str
= "transaction_pure";
8237 case TM_ATTR_IRREVOCABLE
:
8238 str
= "transaction_unsafe";
8240 case TM_ATTR_MAY_CANCEL_OUTER
:
8241 str
= "transaction_may_cancel_outer";
8246 return get_identifier (str
);
8249 /* Return the first TM attribute seen in LIST. */
8252 find_tm_attribute (tree list
)
8254 for (; list
; list
= TREE_CHAIN (list
))
8256 tree name
= TREE_PURPOSE (list
);
8257 if (tm_attr_to_mask (name
) != 0)
8263 /* Handle the TM attributes; arguments as in struct attribute_spec.handler.
8264 Here we accept only function types, and verify that none of the other
8265 function TM attributes are also applied. */
8266 /* ??? We need to accept class types for C++, but not C. This greatly
8267 complicates this function, since we can no longer rely on the extra
8268 processing given by function_type_required. */
8271 handle_tm_attribute (tree
*node
, tree name
, tree args
,
8272 int flags
, bool *no_add_attrs
)
8274 /* Only one path adds the attribute; others don't. */
8275 *no_add_attrs
= true;
8277 switch (TREE_CODE (*node
))
8281 /* Only tm_callable and tm_safe apply to classes. */
8282 if (tm_attr_to_mask (name
) & ~(TM_ATTR_SAFE
| TM_ATTR_CALLABLE
))
8289 tree old_name
= find_tm_attribute (TYPE_ATTRIBUTES (*node
));
8290 if (old_name
== name
)
8292 else if (old_name
!= NULL_TREE
)
8293 error ("type was previously declared %qE", old_name
);
8295 *no_add_attrs
= false;
8301 enum tree_code subcode
= TREE_CODE (TREE_TYPE (*node
));
8302 if (subcode
== FUNCTION_TYPE
|| subcode
== METHOD_TYPE
)
8304 tree fn_tmp
= TREE_TYPE (*node
);
8305 decl_attributes (&fn_tmp
, tree_cons (name
, args
, NULL
), 0);
8306 *node
= build_pointer_type (fn_tmp
);
8313 /* If a function is next, pass it on to be tried next. */
8314 if (flags
& (int) ATTR_FLAG_FUNCTION_NEXT
)
8315 return tree_cons (name
, args
, NULL
);
8318 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8325 /* Handle the TM_WRAP attribute; arguments as in
8326 struct attribute_spec.handler. */
8329 handle_tm_wrap_attribute (tree
*node
, tree name
, tree args
,
8330 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8334 /* We don't need the attribute even on success, since we
8335 record the entry in an external table. */
8336 *no_add_attrs
= true;
8338 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8339 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8342 tree wrap_decl
= TREE_VALUE (args
);
8343 if (TREE_CODE (wrap_decl
) != IDENTIFIER_NODE
8344 && TREE_CODE (wrap_decl
) != VAR_DECL
8345 && TREE_CODE (wrap_decl
) != FUNCTION_DECL
)
8346 error ("%qE argument not an identifier", name
);
8349 if (TREE_CODE (wrap_decl
) == IDENTIFIER_NODE
)
8350 wrap_decl
= lookup_name (wrap_decl
);
8351 if (wrap_decl
&& TREE_CODE (wrap_decl
) == FUNCTION_DECL
)
8353 if (lang_hooks
.types_compatible_p (TREE_TYPE (decl
),
8354 TREE_TYPE (wrap_decl
)))
8355 record_tm_replacement (wrap_decl
, decl
);
8357 error ("%qD is not compatible with %qD", wrap_decl
, decl
);
8360 error ("transaction_wrap argument is not a function");
8367 /* Ignore the given attribute. Used when this attribute may be usefully
8368 overridden by the target, but is not used generically. */
8371 ignore_attribute (tree
* ARG_UNUSED (node
), tree
ARG_UNUSED (name
),
8372 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
8375 *no_add_attrs
= true;
8379 /* Handle a "no vops" attribute; arguments as in
8380 struct attribute_spec.handler. */
8383 handle_novops_attribute (tree
*node
, tree
ARG_UNUSED (name
),
8384 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
8385 bool *ARG_UNUSED (no_add_attrs
))
8387 gcc_assert (TREE_CODE (*node
) == FUNCTION_DECL
);
8388 DECL_IS_NOVOPS (*node
) = 1;
8392 /* Handle a "deprecated" attribute; arguments as in
8393 struct attribute_spec.handler. */
8396 handle_deprecated_attribute (tree
*node
, tree name
,
8397 tree args
, int flags
,
8400 tree type
= NULL_TREE
;
8402 tree what
= NULL_TREE
;
8405 *no_add_attrs
= true;
8406 else if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
8408 error ("deprecated message is not a string");
8409 *no_add_attrs
= true;
8415 type
= TREE_TYPE (decl
);
8417 if (TREE_CODE (decl
) == TYPE_DECL
8418 || TREE_CODE (decl
) == PARM_DECL
8419 || TREE_CODE (decl
) == VAR_DECL
8420 || TREE_CODE (decl
) == FUNCTION_DECL
8421 || TREE_CODE (decl
) == FIELD_DECL
8422 || objc_method_decl (TREE_CODE (decl
)))
8423 TREE_DEPRECATED (decl
) = 1;
8427 else if (TYPE_P (*node
))
8429 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
8430 *node
= build_variant_type_copy (*node
);
8431 TREE_DEPRECATED (*node
) = 1;
8439 *no_add_attrs
= true;
8440 if (type
&& TYPE_NAME (type
))
8442 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
8443 what
= TYPE_NAME (*node
);
8444 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
8445 && DECL_NAME (TYPE_NAME (type
)))
8446 what
= DECL_NAME (TYPE_NAME (type
));
8449 warning (OPT_Wattributes
, "%qE attribute ignored for %qE", name
, what
);
8451 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8457 /* Handle a "vector_size" attribute; arguments as in
8458 struct attribute_spec.handler. */
8461 handle_vector_size_attribute (tree
*node
, tree name
, tree args
,
8462 int ARG_UNUSED (flags
),
8465 unsigned HOST_WIDE_INT vecsize
, nunits
;
8466 enum machine_mode orig_mode
;
8467 tree type
= *node
, new_type
, size
;
8469 *no_add_attrs
= true;
8471 size
= TREE_VALUE (args
);
8473 if (!tree_fits_uhwi_p (size
))
8475 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8479 /* Get the vector size (in bytes). */
8480 vecsize
= tree_to_uhwi (size
);
8482 /* We need to provide for vector pointers, vector arrays, and
8483 functions returning vectors. For example:
8485 __attribute__((vector_size(16))) short *foo;
8487 In this case, the mode is SI, but the type being modified is
8488 HI, so we need to look further. */
8490 while (POINTER_TYPE_P (type
)
8491 || TREE_CODE (type
) == FUNCTION_TYPE
8492 || TREE_CODE (type
) == METHOD_TYPE
8493 || TREE_CODE (type
) == ARRAY_TYPE
8494 || TREE_CODE (type
) == OFFSET_TYPE
)
8495 type
= TREE_TYPE (type
);
8497 /* Get the mode of the type being modified. */
8498 orig_mode
= TYPE_MODE (type
);
8500 if ((!INTEGRAL_TYPE_P (type
)
8501 && !SCALAR_FLOAT_TYPE_P (type
)
8502 && !FIXED_POINT_TYPE_P (type
))
8503 || (!SCALAR_FLOAT_MODE_P (orig_mode
)
8504 && GET_MODE_CLASS (orig_mode
) != MODE_INT
8505 && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode
))
8506 || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
8507 || TREE_CODE (type
) == BOOLEAN_TYPE
)
8509 error ("invalid vector type for attribute %qE", name
);
8513 if (vecsize
% tree_to_uhwi (TYPE_SIZE_UNIT (type
)))
8515 error ("vector size not an integral multiple of component size");
8521 error ("zero vector size");
8525 /* Calculate how many units fit in the vector. */
8526 nunits
= vecsize
/ tree_to_uhwi (TYPE_SIZE_UNIT (type
));
8527 if (nunits
& (nunits
- 1))
8529 error ("number of components of the vector not a power of two");
8533 new_type
= build_vector_type (type
, nunits
);
8535 /* Build back pointers if needed. */
8536 *node
= lang_hooks
.types
.reconstruct_complex_type (*node
, new_type
);
8541 /* Handle the "nonnull" attribute. */
8543 handle_nonnull_attribute (tree
*node
, tree
ARG_UNUSED (name
),
8544 tree args
, int ARG_UNUSED (flags
),
8548 unsigned HOST_WIDE_INT attr_arg_num
;
8550 /* If no arguments are specified, all pointer arguments should be
8551 non-null. Verify a full prototype is given so that the arguments
8552 will have the correct types when we actually check them later. */
8555 if (!prototype_p (type
))
8557 error ("nonnull attribute without arguments on a non-prototype");
8558 *no_add_attrs
= true;
8563 /* Argument list specified. Verify that each argument number references
8564 a pointer argument. */
8565 for (attr_arg_num
= 1; args
; args
= TREE_CHAIN (args
))
8567 unsigned HOST_WIDE_INT arg_num
= 0, ck_num
;
8569 if (!get_nonnull_operand (TREE_VALUE (args
), &arg_num
))
8571 error ("nonnull argument has invalid operand number (argument %lu)",
8572 (unsigned long) attr_arg_num
);
8573 *no_add_attrs
= true;
8577 if (prototype_p (type
))
8579 function_args_iterator iter
;
8582 function_args_iter_init (&iter
, type
);
8583 for (ck_num
= 1; ; ck_num
++, function_args_iter_next (&iter
))
8585 argument
= function_args_iter_cond (&iter
);
8586 if (argument
== NULL_TREE
|| ck_num
== arg_num
)
8591 || TREE_CODE (argument
) == VOID_TYPE
)
8593 error ("nonnull argument with out-of-range operand number (argument %lu, operand %lu)",
8594 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
8595 *no_add_attrs
= true;
8599 if (TREE_CODE (argument
) != POINTER_TYPE
)
8601 error ("nonnull argument references non-pointer operand (argument %lu, operand %lu)",
8602 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
8603 *no_add_attrs
= true;
8612 /* Check the argument list of a function call for null in argument slots
8613 that are marked as requiring a non-null pointer argument. The NARGS
8614 arguments are passed in the array ARGARRAY.
8618 check_function_nonnull (tree attrs
, int nargs
, tree
*argarray
)
8623 attrs
= lookup_attribute ("nonnull", attrs
);
8624 if (attrs
== NULL_TREE
)
8628 /* See if any of the nonnull attributes has no arguments. If so,
8629 then every pointer argument is checked (in which case the check
8630 for pointer type is done in check_nonnull_arg). */
8631 if (TREE_VALUE (a
) != NULL_TREE
)
8633 a
= lookup_attribute ("nonnull", TREE_CHAIN (a
));
8634 while (a
!= NULL_TREE
&& TREE_VALUE (a
) != NULL_TREE
);
8637 for (i
= 0; i
< nargs
; i
++)
8638 check_function_arguments_recurse (check_nonnull_arg
, NULL
, argarray
[i
],
8642 /* Walk the argument list. If we encounter an argument number we
8643 should check for non-null, do it. */
8644 for (i
= 0; i
< nargs
; i
++)
8646 for (a
= attrs
; ; a
= TREE_CHAIN (a
))
8648 a
= lookup_attribute ("nonnull", a
);
8649 if (a
== NULL_TREE
|| nonnull_check_p (TREE_VALUE (a
), i
+ 1))
8654 check_function_arguments_recurse (check_nonnull_arg
, NULL
,
8655 argarray
[i
], i
+ 1);
8660 /* Check that the Nth argument of a function call (counting backwards
8661 from the end) is a (pointer)0. The NARGS arguments are passed in the
8665 check_function_sentinel (const_tree fntype
, int nargs
, tree
*argarray
)
8667 tree attr
= lookup_attribute ("sentinel", TYPE_ATTRIBUTES (fntype
));
8674 function_args_iterator iter
;
8677 /* Skip over the named arguments. */
8678 FOREACH_FUNCTION_ARGS (fntype
, t
, iter
)
8685 if (TREE_VALUE (attr
))
8687 tree p
= TREE_VALUE (TREE_VALUE (attr
));
8688 pos
= TREE_INT_CST_LOW (p
);
8691 /* The sentinel must be one of the varargs, i.e.
8692 in position >= the number of fixed arguments. */
8693 if ((nargs
- 1 - pos
) < len
)
8695 warning (OPT_Wformat_
,
8696 "not enough variable arguments to fit a sentinel");
8700 /* Validate the sentinel. */
8701 sentinel
= argarray
[nargs
- 1 - pos
];
8702 if ((!POINTER_TYPE_P (TREE_TYPE (sentinel
))
8703 || !integer_zerop (sentinel
))
8704 /* Although __null (in C++) is only an integer we allow it
8705 nevertheless, as we are guaranteed that it's exactly
8706 as wide as a pointer, and we don't want to force
8707 users to cast the NULL they have written there.
8708 We warn with -Wstrict-null-sentinel, though. */
8709 && (warn_strict_null_sentinel
|| null_node
!= sentinel
))
8710 warning (OPT_Wformat_
, "missing sentinel in function call");
8714 /* Helper for check_function_nonnull; given a list of operands which
8715 must be non-null in ARGS, determine if operand PARAM_NUM should be
8719 nonnull_check_p (tree args
, unsigned HOST_WIDE_INT param_num
)
8721 unsigned HOST_WIDE_INT arg_num
= 0;
8723 for (; args
; args
= TREE_CHAIN (args
))
8725 bool found
= get_nonnull_operand (TREE_VALUE (args
), &arg_num
);
8729 if (arg_num
== param_num
)
8735 /* Check that the function argument PARAM (which is operand number
8736 PARAM_NUM) is non-null. This is called by check_function_nonnull
8737 via check_function_arguments_recurse. */
8740 check_nonnull_arg (void * ARG_UNUSED (ctx
), tree param
,
8741 unsigned HOST_WIDE_INT param_num
)
8743 /* Just skip checking the argument if it's not a pointer. This can
8744 happen if the "nonnull" attribute was given without an operand
8745 list (which means to check every pointer argument). */
8747 if (TREE_CODE (TREE_TYPE (param
)) != POINTER_TYPE
)
8750 if (integer_zerop (param
))
8751 warning (OPT_Wnonnull
, "null argument where non-null required "
8752 "(argument %lu)", (unsigned long) param_num
);
8755 /* Helper for nonnull attribute handling; fetch the operand number
8756 from the attribute argument list. */
8759 get_nonnull_operand (tree arg_num_expr
, unsigned HOST_WIDE_INT
*valp
)
8761 /* Verify the arg number is a constant. */
8762 if (TREE_CODE (arg_num_expr
) != INTEGER_CST
8763 || TREE_INT_CST_HIGH (arg_num_expr
) != 0)
8766 *valp
= TREE_INT_CST_LOW (arg_num_expr
);
8770 /* Handle a "nothrow" attribute; arguments as in
8771 struct attribute_spec.handler. */
8774 handle_nothrow_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8775 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8777 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8778 TREE_NOTHROW (*node
) = 1;
8779 /* ??? TODO: Support types. */
8782 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8783 *no_add_attrs
= true;
8789 /* Handle a "cleanup" attribute; arguments as in
8790 struct attribute_spec.handler. */
8793 handle_cleanup_attribute (tree
*node
, tree name
, tree args
,
8794 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8797 tree cleanup_id
, cleanup_decl
;
8799 /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
8800 for global destructors in C++. This requires infrastructure that
8801 we don't have generically at the moment. It's also not a feature
8802 we'd be missing too much, since we do have attribute constructor. */
8803 if (TREE_CODE (decl
) != VAR_DECL
|| TREE_STATIC (decl
))
8805 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8806 *no_add_attrs
= true;
8810 /* Verify that the argument is a function in scope. */
8811 /* ??? We could support pointers to functions here as well, if
8812 that was considered desirable. */
8813 cleanup_id
= TREE_VALUE (args
);
8814 if (TREE_CODE (cleanup_id
) != IDENTIFIER_NODE
)
8816 error ("cleanup argument not an identifier");
8817 *no_add_attrs
= true;
8820 cleanup_decl
= lookup_name (cleanup_id
);
8821 if (!cleanup_decl
|| TREE_CODE (cleanup_decl
) != FUNCTION_DECL
)
8823 error ("cleanup argument not a function");
8824 *no_add_attrs
= true;
8828 /* That the function has proper type is checked with the
8829 eventual call to build_function_call. */
8834 /* Handle a "warn_unused_result" attribute. No special handling. */
8837 handle_warn_unused_result_attribute (tree
*node
, tree name
,
8838 tree
ARG_UNUSED (args
),
8839 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8841 /* Ignore the attribute for functions not returning any value. */
8842 if (VOID_TYPE_P (TREE_TYPE (*node
)))
8844 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8845 *no_add_attrs
= true;
8851 /* Handle a "sentinel" attribute. */
8854 handle_sentinel_attribute (tree
*node
, tree name
, tree args
,
8855 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8857 if (!prototype_p (*node
))
8859 warning (OPT_Wattributes
,
8860 "%qE attribute requires prototypes with named arguments", name
);
8861 *no_add_attrs
= true;
8865 if (!stdarg_p (*node
))
8867 warning (OPT_Wattributes
,
8868 "%qE attribute only applies to variadic functions", name
);
8869 *no_add_attrs
= true;
8875 tree position
= TREE_VALUE (args
);
8877 if (TREE_CODE (position
) != INTEGER_CST
)
8879 warning (OPT_Wattributes
,
8880 "requested position is not an integer constant");
8881 *no_add_attrs
= true;
8885 if (tree_int_cst_lt (position
, integer_zero_node
))
8887 warning (OPT_Wattributes
,
8888 "requested position is less than zero");
8889 *no_add_attrs
= true;
8897 /* Handle a "type_generic" attribute. */
8900 handle_type_generic_attribute (tree
*node
, tree
ARG_UNUSED (name
),
8901 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
8902 bool * ARG_UNUSED (no_add_attrs
))
8904 /* Ensure we have a function type. */
8905 gcc_assert (TREE_CODE (*node
) == FUNCTION_TYPE
);
8907 /* Ensure we have a variadic function. */
8908 gcc_assert (!prototype_p (*node
) || stdarg_p (*node
));
8913 /* Handle a "target" attribute. */
8916 handle_target_attribute (tree
*node
, tree name
, tree args
, int flags
,
8919 /* Ensure we have a function type. */
8920 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8922 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8923 *no_add_attrs
= true;
8925 else if (! targetm
.target_option
.valid_attribute_p (*node
, name
, args
,
8927 *no_add_attrs
= true;
8932 /* Arguments being collected for optimization. */
8933 typedef const char *const_char_p
; /* For DEF_VEC_P. */
8934 static GTY(()) vec
<const_char_p
, va_gc
> *optimize_args
;
8937 /* Inner function to convert a TREE_LIST to argv string to parse the optimize
8938 options in ARGS. ATTR_P is true if this is for attribute(optimize), and
8939 false for #pragma GCC optimize. */
8942 parse_optimize_options (tree args
, bool attr_p
)
8947 int saved_flag_strict_aliasing
;
8948 const char **opt_argv
;
8949 struct cl_decoded_option
*decoded_options
;
8950 unsigned int decoded_options_count
;
8953 /* Build up argv vector. Just in case the string is stored away, use garbage
8954 collected strings. */
8955 vec_safe_truncate (optimize_args
, 0);
8956 vec_safe_push (optimize_args
, (const char *) NULL
);
8958 for (ap
= args
; ap
!= NULL_TREE
; ap
= TREE_CHAIN (ap
))
8960 tree value
= TREE_VALUE (ap
);
8962 if (TREE_CODE (value
) == INTEGER_CST
)
8965 sprintf (buffer
, "-O%ld", (long) TREE_INT_CST_LOW (value
));
8966 vec_safe_push (optimize_args
, ggc_strdup (buffer
));
8969 else if (TREE_CODE (value
) == STRING_CST
)
8971 /* Split string into multiple substrings. */
8972 size_t len
= TREE_STRING_LENGTH (value
);
8973 char *p
= ASTRDUP (TREE_STRING_POINTER (value
));
8974 char *end
= p
+ len
;
8978 while (next_p
!= NULL
)
8984 comma
= strchr (p
, ',');
8997 r
= q
= (char *) ggc_alloc_atomic (len2
+ 3);
8999 /* If the user supplied -Oxxx or -fxxx, only allow -Oxxx or -fxxx
9001 if (*p
== '-' && p
[1] != 'O' && p
[1] != 'f')
9005 warning (OPT_Wattributes
,
9006 "bad option %s to optimize attribute", p
);
9008 warning (OPT_Wpragmas
,
9009 "bad option %s to pragma attribute", p
);
9017 /* Assume that Ox is -Ox, a numeric value is -Ox, a s by
9018 itself is -Os, and any other switch begins with a -f. */
9019 if ((*p
>= '0' && *p
<= '9')
9020 || (p
[0] == 's' && p
[1] == '\0'))
9026 memcpy (r
, p
, len2
);
9028 vec_safe_push (optimize_args
, (const char *) q
);
9034 opt_argc
= optimize_args
->length ();
9035 opt_argv
= (const char **) alloca (sizeof (char *) * (opt_argc
+ 1));
9037 for (i
= 1; i
< opt_argc
; i
++)
9038 opt_argv
[i
] = (*optimize_args
)[i
];
9040 saved_flag_strict_aliasing
= flag_strict_aliasing
;
9042 /* Now parse the options. */
9043 decode_cmdline_options_to_array_default_mask (opt_argc
, opt_argv
,
9045 &decoded_options_count
);
9046 decode_options (&global_options
, &global_options_set
,
9047 decoded_options
, decoded_options_count
,
9048 input_location
, global_dc
);
9050 targetm
.override_options_after_change();
9052 /* Don't allow changing -fstrict-aliasing. */
9053 flag_strict_aliasing
= saved_flag_strict_aliasing
;
9055 optimize_args
->truncate (0);
9059 /* For handling "optimize" attribute. arguments as in
9060 struct attribute_spec.handler. */
9063 handle_optimize_attribute (tree
*node
, tree name
, tree args
,
9064 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9066 /* Ensure we have a function type. */
9067 if (TREE_CODE (*node
) != FUNCTION_DECL
)
9069 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9070 *no_add_attrs
= true;
9074 struct cl_optimization cur_opts
;
9075 tree old_opts
= DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
);
9077 /* Save current options. */
9078 cl_optimization_save (&cur_opts
, &global_options
);
9080 /* If we previously had some optimization options, use them as the
9083 cl_optimization_restore (&global_options
,
9084 TREE_OPTIMIZATION (old_opts
));
9086 /* Parse options, and update the vector. */
9087 parse_optimize_options (args
, true);
9088 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
)
9089 = build_optimization_node (&global_options
);
9091 /* Restore current options. */
9092 cl_optimization_restore (&global_options
, &cur_opts
);
9098 /* Handle a "no_split_stack" attribute. */
9101 handle_no_split_stack_attribute (tree
*node
, tree name
,
9102 tree
ARG_UNUSED (args
),
9103 int ARG_UNUSED (flags
),
9108 if (TREE_CODE (decl
) != FUNCTION_DECL
)
9110 error_at (DECL_SOURCE_LOCATION (decl
),
9111 "%qE attribute applies only to functions", name
);
9112 *no_add_attrs
= true;
9114 else if (DECL_INITIAL (decl
))
9116 error_at (DECL_SOURCE_LOCATION (decl
),
9117 "can%'t set %qE attribute after definition", name
);
9118 *no_add_attrs
= true;
9124 /* Handle a "returns_nonnull" attribute; arguments as in
9125 struct attribute_spec.handler. */
9128 handle_returns_nonnull_attribute (tree
*node
, tree
, tree
, int,
9131 // Even without a prototype we still have a return type we can check.
9132 if (TREE_CODE (TREE_TYPE (*node
)) != POINTER_TYPE
)
9134 error ("returns_nonnull attribute on a function not returning a pointer");
9135 *no_add_attrs
= true;
9141 /* Check for valid arguments being passed to a function with FNTYPE.
9142 There are NARGS arguments in the array ARGARRAY. */
9144 check_function_arguments (const_tree fntype
, int nargs
, tree
*argarray
)
9146 /* Check for null being passed in a pointer argument that must be
9147 non-null. We also need to do this if format checking is enabled. */
9150 check_function_nonnull (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
9152 /* Check for errors in format strings. */
9154 if (warn_format
|| warn_suggest_attribute_format
)
9155 check_function_format (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
9158 check_function_sentinel (fntype
, nargs
, argarray
);
9161 /* Generic argument checking recursion routine. PARAM is the argument to
9162 be checked. PARAM_NUM is the number of the argument. CALLBACK is invoked
9163 once the argument is resolved. CTX is context for the callback. */
9165 check_function_arguments_recurse (void (*callback
)
9166 (void *, tree
, unsigned HOST_WIDE_INT
),
9167 void *ctx
, tree param
,
9168 unsigned HOST_WIDE_INT param_num
)
9170 if (CONVERT_EXPR_P (param
)
9171 && (TYPE_PRECISION (TREE_TYPE (param
))
9172 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (param
, 0)))))
9174 /* Strip coercion. */
9175 check_function_arguments_recurse (callback
, ctx
,
9176 TREE_OPERAND (param
, 0), param_num
);
9180 if (TREE_CODE (param
) == CALL_EXPR
)
9182 tree type
= TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (param
)));
9184 bool found_format_arg
= false;
9186 /* See if this is a call to a known internationalization function
9187 that modifies a format arg. Such a function may have multiple
9188 format_arg attributes (for example, ngettext). */
9190 for (attrs
= TYPE_ATTRIBUTES (type
);
9192 attrs
= TREE_CHAIN (attrs
))
9193 if (is_attribute_p ("format_arg", TREE_PURPOSE (attrs
)))
9196 tree format_num_expr
;
9199 call_expr_arg_iterator iter
;
9201 /* Extract the argument number, which was previously checked
9203 format_num_expr
= TREE_VALUE (TREE_VALUE (attrs
));
9205 format_num
= tree_to_uhwi (format_num_expr
);
9207 for (inner_arg
= first_call_expr_arg (param
, &iter
), i
= 1;
9209 inner_arg
= next_call_expr_arg (&iter
), i
++)
9210 if (i
== format_num
)
9212 check_function_arguments_recurse (callback
, ctx
,
9213 inner_arg
, param_num
);
9214 found_format_arg
= true;
9219 /* If we found a format_arg attribute and did a recursive check,
9220 we are done with checking this argument. Otherwise, we continue
9221 and this will be considered a non-literal. */
9222 if (found_format_arg
)
9226 if (TREE_CODE (param
) == COND_EXPR
)
9228 /* Check both halves of the conditional expression. */
9229 check_function_arguments_recurse (callback
, ctx
,
9230 TREE_OPERAND (param
, 1), param_num
);
9231 check_function_arguments_recurse (callback
, ctx
,
9232 TREE_OPERAND (param
, 2), param_num
);
9236 (*callback
) (ctx
, param
, param_num
);
9239 /* Checks for a builtin function FNDECL that the number of arguments
9240 NARGS against the required number REQUIRED and issues an error if
9241 there is a mismatch. Returns true if the number of arguments is
9242 correct, otherwise false. */
9245 builtin_function_validate_nargs (tree fndecl
, int nargs
, int required
)
9247 if (nargs
< required
)
9249 error_at (input_location
,
9250 "not enough arguments to function %qE", fndecl
);
9253 else if (nargs
> required
)
9255 error_at (input_location
,
9256 "too many arguments to function %qE", fndecl
);
9262 /* Verifies the NARGS arguments ARGS to the builtin function FNDECL.
9263 Returns false if there was an error, otherwise true. */
9266 check_builtin_function_arguments (tree fndecl
, int nargs
, tree
*args
)
9268 if (!DECL_BUILT_IN (fndecl
)
9269 || DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_NORMAL
)
9272 switch (DECL_FUNCTION_CODE (fndecl
))
9274 case BUILT_IN_CONSTANT_P
:
9275 return builtin_function_validate_nargs (fndecl
, nargs
, 1);
9277 case BUILT_IN_ISFINITE
:
9278 case BUILT_IN_ISINF
:
9279 case BUILT_IN_ISINF_SIGN
:
9280 case BUILT_IN_ISNAN
:
9281 case BUILT_IN_ISNORMAL
:
9282 if (builtin_function_validate_nargs (fndecl
, nargs
, 1))
9284 if (TREE_CODE (TREE_TYPE (args
[0])) != REAL_TYPE
)
9286 error ("non-floating-point argument in call to "
9287 "function %qE", fndecl
);
9294 case BUILT_IN_ISGREATER
:
9295 case BUILT_IN_ISGREATEREQUAL
:
9296 case BUILT_IN_ISLESS
:
9297 case BUILT_IN_ISLESSEQUAL
:
9298 case BUILT_IN_ISLESSGREATER
:
9299 case BUILT_IN_ISUNORDERED
:
9300 if (builtin_function_validate_nargs (fndecl
, nargs
, 2))
9302 enum tree_code code0
, code1
;
9303 code0
= TREE_CODE (TREE_TYPE (args
[0]));
9304 code1
= TREE_CODE (TREE_TYPE (args
[1]));
9305 if (!((code0
== REAL_TYPE
&& code1
== REAL_TYPE
)
9306 || (code0
== REAL_TYPE
&& code1
== INTEGER_TYPE
)
9307 || (code0
== INTEGER_TYPE
&& code1
== REAL_TYPE
)))
9309 error ("non-floating-point arguments in call to "
9310 "function %qE", fndecl
);
9317 case BUILT_IN_FPCLASSIFY
:
9318 if (builtin_function_validate_nargs (fndecl
, nargs
, 6))
9323 if (TREE_CODE (args
[i
]) != INTEGER_CST
)
9325 error ("non-const integer argument %u in call to function %qE",
9330 if (TREE_CODE (TREE_TYPE (args
[5])) != REAL_TYPE
)
9332 error ("non-floating-point argument in call to function %qE",
9340 case BUILT_IN_ASSUME_ALIGNED
:
9341 if (builtin_function_validate_nargs (fndecl
, nargs
, 2 + (nargs
> 2)))
9343 if (nargs
>= 3 && TREE_CODE (TREE_TYPE (args
[2])) != INTEGER_TYPE
)
9345 error ("non-integer argument 3 in call to function %qE", fndecl
);
9357 /* Function to help qsort sort FIELD_DECLs by name order. */
9360 field_decl_cmp (const void *x_p
, const void *y_p
)
9362 const tree
*const x
= (const tree
*const) x_p
;
9363 const tree
*const y
= (const tree
*const) y_p
;
9365 if (DECL_NAME (*x
) == DECL_NAME (*y
))
9366 /* A nontype is "greater" than a type. */
9367 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
9368 if (DECL_NAME (*x
) == NULL_TREE
)
9370 if (DECL_NAME (*y
) == NULL_TREE
)
9372 if (DECL_NAME (*x
) < DECL_NAME (*y
))
9378 gt_pointer_operator new_value
;
9382 /* This routine compares two fields like field_decl_cmp but using the
9383 pointer operator in resort_data. */
9386 resort_field_decl_cmp (const void *x_p
, const void *y_p
)
9388 const tree
*const x
= (const tree
*const) x_p
;
9389 const tree
*const y
= (const tree
*const) y_p
;
9391 if (DECL_NAME (*x
) == DECL_NAME (*y
))
9392 /* A nontype is "greater" than a type. */
9393 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
9394 if (DECL_NAME (*x
) == NULL_TREE
)
9396 if (DECL_NAME (*y
) == NULL_TREE
)
9399 tree d1
= DECL_NAME (*x
);
9400 tree d2
= DECL_NAME (*y
);
9401 resort_data
.new_value (&d1
, resort_data
.cookie
);
9402 resort_data
.new_value (&d2
, resort_data
.cookie
);
9409 /* Resort DECL_SORTED_FIELDS because pointers have been reordered. */
9412 resort_sorted_fields (void *obj
,
9413 void * ARG_UNUSED (orig_obj
),
9414 gt_pointer_operator new_value
,
9417 struct sorted_fields_type
*sf
= (struct sorted_fields_type
*) obj
;
9418 resort_data
.new_value
= new_value
;
9419 resort_data
.cookie
= cookie
;
9420 qsort (&sf
->elts
[0], sf
->len
, sizeof (tree
),
9421 resort_field_decl_cmp
);
9424 /* Subroutine of c_parse_error.
9425 Return the result of concatenating LHS and RHS. RHS is really
9426 a string literal, its first character is indicated by RHS_START and
9427 RHS_SIZE is its length (including the terminating NUL character).
9429 The caller is responsible for deleting the returned pointer. */
9432 catenate_strings (const char *lhs
, const char *rhs_start
, int rhs_size
)
9434 const int lhs_size
= strlen (lhs
);
9435 char *result
= XNEWVEC (char, lhs_size
+ rhs_size
);
9436 strncpy (result
, lhs
, lhs_size
);
9437 strncpy (result
+ lhs_size
, rhs_start
, rhs_size
);
9441 /* Issue the error given by GMSGID, indicating that it occurred before
9442 TOKEN, which had the associated VALUE. */
9445 c_parse_error (const char *gmsgid
, enum cpp_ttype token_type
,
9446 tree value
, unsigned char token_flags
)
9448 #define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2))
9450 char *message
= NULL
;
9452 if (token_type
== CPP_EOF
)
9453 message
= catenate_messages (gmsgid
, " at end of input");
9454 else if (token_type
== CPP_CHAR
9455 || token_type
== CPP_WCHAR
9456 || token_type
== CPP_CHAR16
9457 || token_type
== CPP_CHAR32
)
9459 unsigned int val
= TREE_INT_CST_LOW (value
);
9478 if (val
<= UCHAR_MAX
&& ISGRAPH (val
))
9479 message
= catenate_messages (gmsgid
, " before %s'%c'");
9481 message
= catenate_messages (gmsgid
, " before %s'\\x%x'");
9483 error (message
, prefix
, val
);
9487 else if (token_type
== CPP_CHAR_USERDEF
9488 || token_type
== CPP_WCHAR_USERDEF
9489 || token_type
== CPP_CHAR16_USERDEF
9490 || token_type
== CPP_CHAR32_USERDEF
)
9491 message
= catenate_messages (gmsgid
,
9492 " before user-defined character literal");
9493 else if (token_type
== CPP_STRING_USERDEF
9494 || token_type
== CPP_WSTRING_USERDEF
9495 || token_type
== CPP_STRING16_USERDEF
9496 || token_type
== CPP_STRING32_USERDEF
9497 || token_type
== CPP_UTF8STRING_USERDEF
)
9498 message
= catenate_messages (gmsgid
, " before user-defined string literal");
9499 else if (token_type
== CPP_STRING
9500 || token_type
== CPP_WSTRING
9501 || token_type
== CPP_STRING16
9502 || token_type
== CPP_STRING32
9503 || token_type
== CPP_UTF8STRING
)
9504 message
= catenate_messages (gmsgid
, " before string constant");
9505 else if (token_type
== CPP_NUMBER
)
9506 message
= catenate_messages (gmsgid
, " before numeric constant");
9507 else if (token_type
== CPP_NAME
)
9509 message
= catenate_messages (gmsgid
, " before %qE");
9510 error (message
, value
);
9514 else if (token_type
== CPP_PRAGMA
)
9515 message
= catenate_messages (gmsgid
, " before %<#pragma%>");
9516 else if (token_type
== CPP_PRAGMA_EOL
)
9517 message
= catenate_messages (gmsgid
, " before end of line");
9518 else if (token_type
== CPP_DECLTYPE
)
9519 message
= catenate_messages (gmsgid
, " before %<decltype%>");
9520 else if (token_type
< N_TTYPES
)
9522 message
= catenate_messages (gmsgid
, " before %qs token");
9523 error (message
, cpp_type2name (token_type
, token_flags
));
9535 #undef catenate_messages
9538 /* Mapping for cpp message reasons to the options that enable them. */
9540 struct reason_option_codes_t
9542 const int reason
; /* cpplib message reason. */
9543 const int option_code
; /* gcc option that controls this message. */
9546 static const struct reason_option_codes_t option_codes
[] = {
9547 {CPP_W_DEPRECATED
, OPT_Wdeprecated
},
9548 {CPP_W_COMMENTS
, OPT_Wcomment
},
9549 {CPP_W_TRIGRAPHS
, OPT_Wtrigraphs
},
9550 {CPP_W_MULTICHAR
, OPT_Wmultichar
},
9551 {CPP_W_TRADITIONAL
, OPT_Wtraditional
},
9552 {CPP_W_LONG_LONG
, OPT_Wlong_long
},
9553 {CPP_W_ENDIF_LABELS
, OPT_Wendif_labels
},
9554 {CPP_W_VARIADIC_MACROS
, OPT_Wvariadic_macros
},
9555 {CPP_W_BUILTIN_MACRO_REDEFINED
, OPT_Wbuiltin_macro_redefined
},
9556 {CPP_W_UNDEF
, OPT_Wundef
},
9557 {CPP_W_UNUSED_MACROS
, OPT_Wunused_macros
},
9558 {CPP_W_CXX_OPERATOR_NAMES
, OPT_Wc___compat
},
9559 {CPP_W_NORMALIZE
, OPT_Wnormalized_
},
9560 {CPP_W_INVALID_PCH
, OPT_Winvalid_pch
},
9561 {CPP_W_WARNING_DIRECTIVE
, OPT_Wcpp
},
9562 {CPP_W_LITERAL_SUFFIX
, OPT_Wliteral_suffix
},
9563 {CPP_W_DATE_TIME
, OPT_Wdate_time
},
9567 /* Return the gcc option code associated with the reason for a cpp
9568 message, or 0 if none. */
9571 c_option_controlling_cpp_error (int reason
)
9573 const struct reason_option_codes_t
*entry
;
9575 for (entry
= option_codes
; entry
->reason
!= CPP_W_NONE
; entry
++)
9577 if (entry
->reason
== reason
)
9578 return entry
->option_code
;
9583 /* Callback from cpp_error for PFILE to print diagnostics from the
9584 preprocessor. The diagnostic is of type LEVEL, with REASON set
9585 to the reason code if LEVEL is represents a warning, at location
9586 LOCATION unless this is after lexing and the compiler's location
9587 should be used instead, with column number possibly overridden by
9588 COLUMN_OVERRIDE if not zero; MSG is the translated message and AP
9589 the arguments. Returns true if a diagnostic was emitted, false
9593 c_cpp_error (cpp_reader
*pfile ATTRIBUTE_UNUSED
, int level
, int reason
,
9594 location_t location
, unsigned int column_override
,
9595 const char *msg
, va_list *ap
)
9597 diagnostic_info diagnostic
;
9598 diagnostic_t dlevel
;
9599 bool save_warn_system_headers
= global_dc
->dc_warn_system_headers
;
9604 case CPP_DL_WARNING_SYSHDR
:
9607 global_dc
->dc_warn_system_headers
= 1;
9609 case CPP_DL_WARNING
:
9612 dlevel
= DK_WARNING
;
9614 case CPP_DL_PEDWARN
:
9615 if (flag_no_output
&& !flag_pedantic_errors
)
9617 dlevel
= DK_PEDWARN
;
9635 location
= input_location
;
9636 diagnostic_set_info_translated (&diagnostic
, msg
, ap
,
9638 if (column_override
)
9639 diagnostic_override_column (&diagnostic
, column_override
);
9640 diagnostic_override_option_index (&diagnostic
,
9641 c_option_controlling_cpp_error (reason
));
9642 ret
= report_diagnostic (&diagnostic
);
9643 if (level
== CPP_DL_WARNING_SYSHDR
)
9644 global_dc
->dc_warn_system_headers
= save_warn_system_headers
;
9648 /* Convert a character from the host to the target execution character
9649 set. cpplib handles this, mostly. */
9652 c_common_to_target_charset (HOST_WIDE_INT c
)
9654 /* Character constants in GCC proper are sign-extended under -fsigned-char,
9655 zero-extended under -fno-signed-char. cpplib insists that characters
9656 and character constants are always unsigned. Hence we must convert
9658 cppchar_t uc
= ((cppchar_t
)c
) & ((((cppchar_t
)1) << CHAR_BIT
)-1);
9660 uc
= cpp_host_to_exec_charset (parse_in
, uc
);
9662 if (flag_signed_char
)
9663 return ((HOST_WIDE_INT
)uc
) << (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
)
9664 >> (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
);
9669 /* Fold an offsetof-like expression. EXPR is a nested sequence of component
9670 references with an INDIRECT_REF of a constant at the bottom; much like the
9671 traditional rendering of offsetof as a macro. Return the folded result. */
9674 fold_offsetof_1 (tree expr
)
9678 switch (TREE_CODE (expr
))
9684 error ("cannot apply %<offsetof%> to static data member %qD", expr
);
9685 return error_mark_node
;
9689 error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded");
9690 return error_mark_node
;
9694 if (!TREE_CONSTANT (TREE_OPERAND (expr
, 0)))
9696 error ("cannot apply %<offsetof%> to a non constant address");
9697 return error_mark_node
;
9699 return TREE_OPERAND (expr
, 0);
9702 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0));
9703 if (base
== error_mark_node
)
9706 t
= TREE_OPERAND (expr
, 1);
9707 if (DECL_C_BIT_FIELD (t
))
9709 error ("attempt to take address of bit-field structure "
9711 return error_mark_node
;
9713 off
= size_binop_loc (input_location
, PLUS_EXPR
, DECL_FIELD_OFFSET (t
),
9714 size_int (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (t
))
9719 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0));
9720 if (base
== error_mark_node
)
9723 t
= TREE_OPERAND (expr
, 1);
9725 /* Check if the offset goes beyond the upper bound of the array. */
9726 if (TREE_CODE (t
) == INTEGER_CST
&& tree_int_cst_sgn (t
) >= 0)
9728 tree upbound
= array_ref_up_bound (expr
);
9729 if (upbound
!= NULL_TREE
9730 && TREE_CODE (upbound
) == INTEGER_CST
9731 && !tree_int_cst_equal (upbound
,
9732 TYPE_MAX_VALUE (TREE_TYPE (upbound
))))
9734 upbound
= size_binop (PLUS_EXPR
, upbound
,
9735 build_int_cst (TREE_TYPE (upbound
), 1));
9736 if (tree_int_cst_lt (upbound
, t
))
9740 for (v
= TREE_OPERAND (expr
, 0);
9741 TREE_CODE (v
) == COMPONENT_REF
;
9742 v
= TREE_OPERAND (v
, 0))
9743 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v
, 0)))
9746 tree fld_chain
= DECL_CHAIN (TREE_OPERAND (v
, 1));
9747 for (; fld_chain
; fld_chain
= DECL_CHAIN (fld_chain
))
9748 if (TREE_CODE (fld_chain
) == FIELD_DECL
)
9754 /* Don't warn if the array might be considered a poor
9755 man's flexible array member with a very permissive
9756 definition thereof. */
9757 if (TREE_CODE (v
) == ARRAY_REF
9758 || TREE_CODE (v
) == COMPONENT_REF
)
9759 warning (OPT_Warray_bounds
,
9760 "index %E denotes an offset "
9761 "greater than size of %qT",
9762 t
, TREE_TYPE (TREE_OPERAND (expr
, 0)));
9767 t
= convert (sizetype
, t
);
9768 off
= size_binop (MULT_EXPR
, TYPE_SIZE_UNIT (TREE_TYPE (expr
)), t
);
9772 /* Handle static members of volatile structs. */
9773 t
= TREE_OPERAND (expr
, 1);
9774 gcc_assert (TREE_CODE (t
) == VAR_DECL
);
9775 return fold_offsetof_1 (t
);
9781 return fold_build_pointer_plus (base
, off
);
9784 /* Likewise, but convert it to the return type of offsetof. */
9787 fold_offsetof (tree expr
)
9789 return convert (size_type_node
, fold_offsetof_1 (expr
));
9792 /* Warn for A ?: C expressions (with B omitted) where A is a boolean
9793 expression, because B will always be true. */
9796 warn_for_omitted_condop (location_t location
, tree cond
)
9798 if (truth_value_p (TREE_CODE (cond
)))
9799 warning_at (location
, OPT_Wparentheses
,
9800 "the omitted middle operand in ?: will always be %<true%>, "
9801 "suggest explicit middle operand");
9804 /* Give an error for storing into ARG, which is 'const'. USE indicates
9805 how ARG was being used. */
9808 readonly_error (location_t loc
, tree arg
, enum lvalue_use use
)
9810 gcc_assert (use
== lv_assign
|| use
== lv_increment
|| use
== lv_decrement
9812 /* Using this macro rather than (for example) arrays of messages
9813 ensures that all the format strings are checked at compile
9815 #define READONLY_MSG(A, I, D, AS) (use == lv_assign ? (A) \
9816 : (use == lv_increment ? (I) \
9817 : (use == lv_decrement ? (D) : (AS))))
9818 if (TREE_CODE (arg
) == COMPONENT_REF
)
9820 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg
, 0))))
9821 error_at (loc
, READONLY_MSG (G_("assignment of member "
9822 "%qD in read-only object"),
9823 G_("increment of member "
9824 "%qD in read-only object"),
9825 G_("decrement of member "
9826 "%qD in read-only object"),
9827 G_("member %qD in read-only object "
9828 "used as %<asm%> output")),
9829 TREE_OPERAND (arg
, 1));
9831 error_at (loc
, READONLY_MSG (G_("assignment of read-only member %qD"),
9832 G_("increment of read-only member %qD"),
9833 G_("decrement of read-only member %qD"),
9834 G_("read-only member %qD used as %<asm%> output")),
9835 TREE_OPERAND (arg
, 1));
9837 else if (TREE_CODE (arg
) == VAR_DECL
)
9838 error_at (loc
, READONLY_MSG (G_("assignment of read-only variable %qD"),
9839 G_("increment of read-only variable %qD"),
9840 G_("decrement of read-only variable %qD"),
9841 G_("read-only variable %qD used as %<asm%> output")),
9843 else if (TREE_CODE (arg
) == PARM_DECL
)
9844 error_at (loc
, READONLY_MSG (G_("assignment of read-only parameter %qD"),
9845 G_("increment of read-only parameter %qD"),
9846 G_("decrement of read-only parameter %qD"),
9847 G_("read-only parameter %qD use as %<asm%> output")),
9849 else if (TREE_CODE (arg
) == RESULT_DECL
)
9851 gcc_assert (c_dialect_cxx ());
9852 error_at (loc
, READONLY_MSG (G_("assignment of "
9853 "read-only named return value %qD"),
9855 "read-only named return value %qD"),
9857 "read-only named return value %qD"),
9858 G_("read-only named return value %qD "
9859 "used as %<asm%>output")),
9862 else if (TREE_CODE (arg
) == FUNCTION_DECL
)
9863 error_at (loc
, READONLY_MSG (G_("assignment of function %qD"),
9864 G_("increment of function %qD"),
9865 G_("decrement of function %qD"),
9866 G_("function %qD used as %<asm%> output")),
9869 error_at (loc
, READONLY_MSG (G_("assignment of read-only location %qE"),
9870 G_("increment of read-only location %qE"),
9871 G_("decrement of read-only location %qE"),
9872 G_("read-only location %qE used as %<asm%> output")),
9876 /* Print an error message for an invalid lvalue. USE says
9877 how the lvalue is being used and so selects the error message. LOC
9878 is the location for the error. */
9881 lvalue_error (location_t loc
, enum lvalue_use use
)
9886 error_at (loc
, "lvalue required as left operand of assignment");
9889 error_at (loc
, "lvalue required as increment operand");
9892 error_at (loc
, "lvalue required as decrement operand");
9895 error_at (loc
, "lvalue required as unary %<&%> operand");
9898 error_at (loc
, "lvalue required in asm statement");
9905 /* Print an error message for an invalid indirection of type TYPE.
9906 ERRSTRING is the name of the operator for the indirection. */
9909 invalid_indirection_error (location_t loc
, tree type
, ref_operator errstring
)
9914 gcc_assert (c_dialect_cxx ());
9915 error_at (loc
, "invalid type argument (have %qT)", type
);
9917 case RO_ARRAY_INDEXING
:
9919 "invalid type argument of array indexing (have %qT)",
9924 "invalid type argument of unary %<*%> (have %qT)",
9929 "invalid type argument of %<->%> (have %qT)",
9934 "invalid type argument of %<->*%> (have %qT)",
9937 case RO_IMPLICIT_CONVERSION
:
9939 "invalid type argument of implicit conversion (have %qT)",
9947 /* *PTYPE is an incomplete array. Complete it with a domain based on
9948 INITIAL_VALUE. If INITIAL_VALUE is not present, use 1 if DO_DEFAULT
9949 is true. Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
9950 2 if INITIAL_VALUE was NULL, and 3 if INITIAL_VALUE was empty. */
9953 complete_array_type (tree
*ptype
, tree initial_value
, bool do_default
)
9955 tree maxindex
, type
, main_type
, elt
, unqual_elt
;
9956 int failure
= 0, quals
;
9957 hashval_t hashcode
= 0;
9958 bool overflow_p
= false;
9960 maxindex
= size_zero_node
;
9963 if (TREE_CODE (initial_value
) == STRING_CST
)
9966 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value
)));
9967 maxindex
= size_int (TREE_STRING_LENGTH (initial_value
)/eltsize
- 1);
9969 else if (TREE_CODE (initial_value
) == CONSTRUCTOR
)
9971 vec
<constructor_elt
, va_gc
> *v
= CONSTRUCTOR_ELTS (initial_value
);
9973 if (vec_safe_is_empty (v
))
9977 maxindex
= ssize_int (-1);
9982 unsigned HOST_WIDE_INT cnt
;
9983 constructor_elt
*ce
;
9984 bool fold_p
= false;
9987 maxindex
= (*v
)[0].index
, fold_p
= true;
9989 curindex
= maxindex
;
9991 for (cnt
= 1; vec_safe_iterate (v
, cnt
, &ce
); cnt
++)
9993 bool curfold_p
= false;
9995 curindex
= ce
->index
, curfold_p
= true;
10000 /* Since we treat size types now as ordinary
10001 unsigned types, we need an explicit overflow
10003 tree orig
= curindex
;
10004 curindex
= fold_convert (sizetype
, curindex
);
10005 overflow_p
|= tree_int_cst_lt (curindex
, orig
);
10007 curindex
= size_binop (PLUS_EXPR
, curindex
,
10010 if (tree_int_cst_lt (maxindex
, curindex
))
10011 maxindex
= curindex
, fold_p
= curfold_p
;
10015 tree orig
= maxindex
;
10016 maxindex
= fold_convert (sizetype
, maxindex
);
10017 overflow_p
|= tree_int_cst_lt (maxindex
, orig
);
10023 /* Make an error message unless that happened already. */
10024 if (initial_value
!= error_mark_node
)
10036 elt
= TREE_TYPE (type
);
10037 quals
= TYPE_QUALS (strip_array_types (elt
));
10041 unqual_elt
= c_build_qualified_type (elt
, KEEP_QUAL_ADDR_SPACE (quals
));
10043 /* Using build_distinct_type_copy and modifying things afterward instead
10044 of using build_array_type to create a new type preserves all of the
10045 TYPE_LANG_FLAG_? bits that the front end may have set. */
10046 main_type
= build_distinct_type_copy (TYPE_MAIN_VARIANT (type
));
10047 TREE_TYPE (main_type
) = unqual_elt
;
10048 TYPE_DOMAIN (main_type
)
10049 = build_range_type (TREE_TYPE (maxindex
),
10050 build_int_cst (TREE_TYPE (maxindex
), 0), maxindex
);
10051 layout_type (main_type
);
10053 /* Make sure we have the canonical MAIN_TYPE. */
10054 hashcode
= iterative_hash_object (TYPE_HASH (unqual_elt
), hashcode
);
10055 hashcode
= iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (main_type
)),
10057 main_type
= type_hash_canon (hashcode
, main_type
);
10059 /* Fix the canonical type. */
10060 if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type
))
10061 || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type
)))
10062 SET_TYPE_STRUCTURAL_EQUALITY (main_type
);
10063 else if (TYPE_CANONICAL (TREE_TYPE (main_type
)) != TREE_TYPE (main_type
)
10064 || (TYPE_CANONICAL (TYPE_DOMAIN (main_type
))
10065 != TYPE_DOMAIN (main_type
)))
10066 TYPE_CANONICAL (main_type
)
10067 = build_array_type (TYPE_CANONICAL (TREE_TYPE (main_type
)),
10068 TYPE_CANONICAL (TYPE_DOMAIN (main_type
)));
10070 TYPE_CANONICAL (main_type
) = main_type
;
10075 type
= c_build_qualified_type (main_type
, quals
);
10077 if (COMPLETE_TYPE_P (type
)
10078 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
10079 && (overflow_p
|| TREE_OVERFLOW (TYPE_SIZE_UNIT (type
))))
10081 error ("size of array is too large");
10082 /* If we proceed with the array type as it is, we'll eventually
10083 crash in tree_to_[su]hwi(). */
10084 type
= error_mark_node
;
10091 /* Like c_mark_addressable but don't check register qualifier. */
10093 c_common_mark_addressable_vec (tree t
)
10095 while (handled_component_p (t
))
10096 t
= TREE_OPERAND (t
, 0);
10097 if (TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != PARM_DECL
)
10099 TREE_ADDRESSABLE (t
) = 1;
10104 /* Used to help initialize the builtin-types.def table. When a type of
10105 the correct size doesn't exist, use error_mark_node instead of NULL.
10106 The later results in segfaults even when a decl using the type doesn't
10110 builtin_type_for_size (int size
, bool unsignedp
)
10112 tree type
= c_common_type_for_size (size
, unsignedp
);
10113 return type
? type
: error_mark_node
;
10116 /* A helper function for resolve_overloaded_builtin in resolving the
10117 overloaded __sync_ builtins. Returns a positive power of 2 if the
10118 first operand of PARAMS is a pointer to a supported data type.
10119 Returns 0 if an error is encountered. */
10122 sync_resolve_size (tree function
, vec
<tree
, va_gc
> *params
)
10129 error ("too few arguments to function %qE", function
);
10133 type
= TREE_TYPE ((*params
)[0]);
10134 if (TREE_CODE (type
) != POINTER_TYPE
)
10137 type
= TREE_TYPE (type
);
10138 if (!INTEGRAL_TYPE_P (type
) && !POINTER_TYPE_P (type
))
10141 size
= tree_to_uhwi (TYPE_SIZE_UNIT (type
));
10142 if (size
== 1 || size
== 2 || size
== 4 || size
== 8 || size
== 16)
10146 error ("incompatible type for argument %d of %qE", 1, function
);
10150 /* A helper function for resolve_overloaded_builtin. Adds casts to
10151 PARAMS to make arguments match up with those of FUNCTION. Drops
10152 the variadic arguments at the end. Returns false if some error
10153 was encountered; true on success. */
10156 sync_resolve_params (location_t loc
, tree orig_function
, tree function
,
10157 vec
<tree
, va_gc
> *params
, bool orig_format
)
10159 function_args_iterator iter
;
10161 unsigned int parmnum
;
10163 function_args_iter_init (&iter
, TREE_TYPE (function
));
10164 /* We've declared the implementation functions to use "volatile void *"
10165 as the pointer parameter, so we shouldn't get any complaints from the
10166 call to check_function_arguments what ever type the user used. */
10167 function_args_iter_next (&iter
);
10168 ptype
= TREE_TYPE (TREE_TYPE ((*params
)[0]));
10169 ptype
= TYPE_MAIN_VARIANT (ptype
);
10171 /* For the rest of the values, we need to cast these to FTYPE, so that we
10172 don't get warnings for passing pointer types, etc. */
10176 tree val
, arg_type
;
10178 arg_type
= function_args_iter_cond (&iter
);
10179 /* XXX void_type_node belies the abstraction. */
10180 if (arg_type
== void_type_node
)
10184 if (params
->length () <= parmnum
)
10186 error_at (loc
, "too few arguments to function %qE", orig_function
);
10190 /* Only convert parameters if arg_type is unsigned integer type with
10191 new format sync routines, i.e. don't attempt to convert pointer
10192 arguments (e.g. EXPECTED argument of __atomic_compare_exchange_n),
10193 bool arguments (e.g. WEAK argument) or signed int arguments (memmodel
10195 if (TREE_CODE (arg_type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (arg_type
))
10197 /* Ideally for the first conversion we'd use convert_for_assignment
10198 so that we get warnings for anything that doesn't match the pointer
10199 type. This isn't portable across the C and C++ front ends atm. */
10200 val
= (*params
)[parmnum
];
10201 val
= convert (ptype
, val
);
10202 val
= convert (arg_type
, val
);
10203 (*params
)[parmnum
] = val
;
10206 function_args_iter_next (&iter
);
10209 /* __atomic routines are not variadic. */
10210 if (!orig_format
&& params
->length () != parmnum
+ 1)
10212 error_at (loc
, "too many arguments to function %qE", orig_function
);
10216 /* The definition of these primitives is variadic, with the remaining
10217 being "an optional list of variables protected by the memory barrier".
10218 No clue what that's supposed to mean, precisely, but we consider all
10219 call-clobbered variables to be protected so we're safe. */
10220 params
->truncate (parmnum
+ 1);
10225 /* A helper function for resolve_overloaded_builtin. Adds a cast to
10226 RESULT to make it match the type of the first pointer argument in
10230 sync_resolve_return (tree first_param
, tree result
, bool orig_format
)
10232 tree ptype
= TREE_TYPE (TREE_TYPE (first_param
));
10233 tree rtype
= TREE_TYPE (result
);
10234 ptype
= TYPE_MAIN_VARIANT (ptype
);
10236 /* New format doesn't require casting unless the types are the same size. */
10237 if (orig_format
|| tree_int_cst_equal (TYPE_SIZE (ptype
), TYPE_SIZE (rtype
)))
10238 return convert (ptype
, result
);
10243 /* This function verifies the PARAMS to generic atomic FUNCTION.
10244 It returns the size if all the parameters are the same size, otherwise
10245 0 is returned if the parameters are invalid. */
10248 get_atomic_generic_size (location_t loc
, tree function
,
10249 vec
<tree
, va_gc
> *params
)
10251 unsigned int n_param
;
10252 unsigned int n_model
;
10257 /* Determine the parameter makeup. */
10258 switch (DECL_FUNCTION_CODE (function
))
10260 case BUILT_IN_ATOMIC_EXCHANGE
:
10264 case BUILT_IN_ATOMIC_LOAD
:
10265 case BUILT_IN_ATOMIC_STORE
:
10269 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10274 gcc_unreachable ();
10277 if (vec_safe_length (params
) != n_param
)
10279 error_at (loc
, "incorrect number of arguments to function %qE", function
);
10283 /* Get type of first parameter, and determine its size. */
10284 type_0
= TREE_TYPE ((*params
)[0]);
10285 if (TREE_CODE (type_0
) != POINTER_TYPE
|| VOID_TYPE_P (TREE_TYPE (type_0
)))
10287 error_at (loc
, "argument 1 of %qE must be a non-void pointer type",
10292 /* Types must be compile time constant sizes. */
10293 if (TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type_0
)))) != INTEGER_CST
)
10296 "argument 1 of %qE must be a pointer to a constant size type",
10301 size_0
= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type_0
)));
10303 /* Zero size objects are not allowed. */
10307 "argument 1 of %qE must be a pointer to a nonzero size object",
10312 /* Check each other parameter is a pointer and the same size. */
10313 for (x
= 0; x
< n_param
- n_model
; x
++)
10316 tree type
= TREE_TYPE ((*params
)[x
]);
10317 /* __atomic_compare_exchange has a bool in the 4th position, skip it. */
10318 if (n_param
== 6 && x
== 3)
10320 if (!POINTER_TYPE_P (type
))
10322 error_at (loc
, "argument %d of %qE must be a pointer type", x
+ 1,
10326 size
= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type
)));
10327 if (size
!= size_0
)
10329 error_at (loc
, "size mismatch in argument %d of %qE", x
+ 1,
10335 /* Check memory model parameters for validity. */
10336 for (x
= n_param
- n_model
; x
< n_param
; x
++)
10338 tree p
= (*params
)[x
];
10339 if (TREE_CODE (p
) == INTEGER_CST
)
10341 int i
= tree_to_uhwi (p
);
10342 if (i
< 0 || (i
& MEMMODEL_MASK
) >= MEMMODEL_LAST
)
10344 warning_at (loc
, OPT_Winvalid_memory_model
,
10345 "invalid memory model argument %d of %qE", x
+ 1,
10350 if (!INTEGRAL_TYPE_P (TREE_TYPE (p
)))
10352 error_at (loc
, "non-integer memory model argument %d of %qE", x
+ 1,
10362 /* This will take an __atomic_ generic FUNCTION call, and add a size parameter N
10363 at the beginning of the parameter list PARAMS representing the size of the
10364 objects. This is to match the library ABI requirement. LOC is the location
10365 of the function call.
10366 The new function is returned if it needed rebuilding, otherwise NULL_TREE is
10367 returned to allow the external call to be constructed. */
10370 add_atomic_size_parameter (unsigned n
, location_t loc
, tree function
,
10371 vec
<tree
, va_gc
> *params
)
10375 /* Insert a SIZE_T parameter as the first param. If there isn't
10376 enough space, allocate a new vector and recursively re-build with that. */
10377 if (!params
->space (1))
10379 unsigned int z
, len
;
10380 vec
<tree
, va_gc
> *v
;
10383 len
= params
->length ();
10384 vec_alloc (v
, len
+ 1);
10385 for (z
= 0; z
< len
; z
++)
10386 v
->quick_push ((*params
)[z
]);
10387 f
= build_function_call_vec (loc
, function
, v
, NULL
);
10392 /* Add the size parameter and leave as a function call for processing. */
10393 size_node
= build_int_cst (size_type_node
, n
);
10394 params
->quick_insert (0, size_node
);
10399 /* Return whether atomic operations for naturally aligned N-byte
10400 arguments are supported, whether inline or through libatomic. */
10402 atomic_size_supported_p (int n
)
10413 return targetm
.scalar_mode_supported_p (TImode
);
10420 /* This will process an __atomic_exchange function call, determine whether it
10421 needs to be mapped to the _N variation, or turned into a library call.
10422 LOC is the location of the builtin call.
10423 FUNCTION is the DECL that has been invoked;
10424 PARAMS is the argument list for the call. The return value is non-null
10425 TRUE is returned if it is translated into the proper format for a call to the
10426 external library, and NEW_RETURN is set the tree for that function.
10427 FALSE is returned if processing for the _N variation is required, and
10428 NEW_RETURN is set to the the return value the result is copied into. */
10430 resolve_overloaded_atomic_exchange (location_t loc
, tree function
,
10431 vec
<tree
, va_gc
> *params
, tree
*new_return
)
10433 tree p0
, p1
, p2
, p3
;
10434 tree I_type
, I_type_ptr
;
10435 int n
= get_atomic_generic_size (loc
, function
, params
);
10437 /* Size of 0 is an error condition. */
10440 *new_return
= error_mark_node
;
10444 /* If not a lock-free size, change to the library generic format. */
10445 if (!atomic_size_supported_p (n
))
10447 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10451 /* Otherwise there is a lockfree match, transform the call from:
10452 void fn(T* mem, T* desired, T* return, model)
10454 *return = (T) (fn (In* mem, (In) *desired, model)) */
10461 /* Create pointer to appropriate size. */
10462 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10463 I_type_ptr
= build_pointer_type (I_type
);
10465 /* Convert object pointer to required type. */
10466 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10468 /* Convert new value to required type, and dereference it. */
10469 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
10470 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
10473 /* Move memory model to the 3rd position, and end param list. */
10475 params
->truncate (3);
10477 /* Convert return pointer and dereference it for later assignment. */
10478 *new_return
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
10484 /* This will process an __atomic_compare_exchange function call, determine
10485 whether it needs to be mapped to the _N variation, or turned into a lib call.
10486 LOC is the location of the builtin call.
10487 FUNCTION is the DECL that has been invoked;
10488 PARAMS is the argument list for the call. The return value is non-null
10489 TRUE is returned if it is translated into the proper format for a call to the
10490 external library, and NEW_RETURN is set the tree for that function.
10491 FALSE is returned if processing for the _N variation is required. */
10494 resolve_overloaded_atomic_compare_exchange (location_t loc
, tree function
,
10495 vec
<tree
, va_gc
> *params
,
10499 tree I_type
, I_type_ptr
;
10500 int n
= get_atomic_generic_size (loc
, function
, params
);
10502 /* Size of 0 is an error condition. */
10505 *new_return
= error_mark_node
;
10509 /* If not a lock-free size, change to the library generic format. */
10510 if (!atomic_size_supported_p (n
))
10512 /* The library generic format does not have the weak parameter, so
10513 remove it from the param list. Since a parameter has been removed,
10514 we can be sure that there is room for the SIZE_T parameter, meaning
10515 there will not be a recursive rebuilding of the parameter list, so
10516 there is no danger this will be done twice. */
10519 (*params
)[3] = (*params
)[4];
10520 (*params
)[4] = (*params
)[5];
10521 params
->truncate (5);
10523 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10527 /* Otherwise, there is a match, so the call needs to be transformed from:
10528 bool fn(T* mem, T* desired, T* return, weak, success, failure)
10530 bool fn ((In *)mem, (In *)expected, (In) *desired, weak, succ, fail) */
10536 /* Create pointer to appropriate size. */
10537 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10538 I_type_ptr
= build_pointer_type (I_type
);
10540 /* Convert object pointer to required type. */
10541 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10544 /* Convert expected pointer to required type. */
10545 p1
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p1
);
10548 /* Convert desired value to required type, and dereference it. */
10549 p2
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
10550 p2
= build1 (VIEW_CONVERT_EXPR
, I_type
, p2
);
10553 /* The rest of the parameters are fine. NULL means no special return value
10555 *new_return
= NULL
;
10560 /* This will process an __atomic_load function call, determine whether it
10561 needs to be mapped to the _N variation, or turned into a library call.
10562 LOC is the location of the builtin call.
10563 FUNCTION is the DECL that has been invoked;
10564 PARAMS is the argument list for the call. The return value is non-null
10565 TRUE is returned if it is translated into the proper format for a call to the
10566 external library, and NEW_RETURN is set the tree for that function.
10567 FALSE is returned if processing for the _N variation is required, and
10568 NEW_RETURN is set to the the return value the result is copied into. */
10571 resolve_overloaded_atomic_load (location_t loc
, tree function
,
10572 vec
<tree
, va_gc
> *params
, tree
*new_return
)
10575 tree I_type
, I_type_ptr
;
10576 int n
= get_atomic_generic_size (loc
, function
, params
);
10578 /* Size of 0 is an error condition. */
10581 *new_return
= error_mark_node
;
10585 /* If not a lock-free size, change to the library generic format. */
10586 if (!atomic_size_supported_p (n
))
10588 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10592 /* Otherwise, there is a match, so the call needs to be transformed from:
10593 void fn(T* mem, T* return, model)
10595 *return = (T) (fn ((In *) mem, model)) */
10601 /* Create pointer to appropriate size. */
10602 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10603 I_type_ptr
= build_pointer_type (I_type
);
10605 /* Convert object pointer to required type. */
10606 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10609 /* Move memory model to the 2nd position, and end param list. */
10611 params
->truncate (2);
10613 /* Convert return pointer and dereference it for later assignment. */
10614 *new_return
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
10620 /* This will process an __atomic_store function call, determine whether it
10621 needs to be mapped to the _N variation, or turned into a library call.
10622 LOC is the location of the builtin call.
10623 FUNCTION is the DECL that has been invoked;
10624 PARAMS is the argument list for the call. The return value is non-null
10625 TRUE is returned if it is translated into the proper format for a call to the
10626 external library, and NEW_RETURN is set the tree for that function.
10627 FALSE is returned if processing for the _N variation is required, and
10628 NEW_RETURN is set to the the return value the result is copied into. */
10631 resolve_overloaded_atomic_store (location_t loc
, tree function
,
10632 vec
<tree
, va_gc
> *params
, tree
*new_return
)
10635 tree I_type
, I_type_ptr
;
10636 int n
= get_atomic_generic_size (loc
, function
, params
);
10638 /* Size of 0 is an error condition. */
10641 *new_return
= error_mark_node
;
10645 /* If not a lock-free size, change to the library generic format. */
10646 if (!atomic_size_supported_p (n
))
10648 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10652 /* Otherwise, there is a match, so the call needs to be transformed from:
10653 void fn(T* mem, T* value, model)
10655 fn ((In *) mem, (In) *value, model) */
10660 /* Create pointer to appropriate size. */
10661 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10662 I_type_ptr
= build_pointer_type (I_type
);
10664 /* Convert object pointer to required type. */
10665 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10668 /* Convert new value to required type, and dereference it. */
10669 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
10670 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
10673 /* The memory model is in the right spot already. Return is void. */
10674 *new_return
= NULL_TREE
;
10680 /* Some builtin functions are placeholders for other expressions. This
10681 function should be called immediately after parsing the call expression
10682 before surrounding code has committed to the type of the expression.
10684 LOC is the location of the builtin call.
10686 FUNCTION is the DECL that has been invoked; it is known to be a builtin.
10687 PARAMS is the argument list for the call. The return value is non-null
10688 when expansion is complete, and null if normal processing should
10692 resolve_overloaded_builtin (location_t loc
, tree function
,
10693 vec
<tree
, va_gc
> *params
)
10695 enum built_in_function orig_code
= DECL_FUNCTION_CODE (function
);
10696 bool orig_format
= true;
10697 tree new_return
= NULL_TREE
;
10699 switch (DECL_BUILT_IN_CLASS (function
))
10701 case BUILT_IN_NORMAL
:
10704 if (targetm
.resolve_overloaded_builtin
)
10705 return targetm
.resolve_overloaded_builtin (loc
, function
, params
);
10712 /* Handle BUILT_IN_NORMAL here. */
10715 case BUILT_IN_ATOMIC_EXCHANGE
:
10716 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10717 case BUILT_IN_ATOMIC_LOAD
:
10718 case BUILT_IN_ATOMIC_STORE
:
10720 /* Handle these 4 together so that they can fall through to the next
10721 case if the call is transformed to an _N variant. */
10724 case BUILT_IN_ATOMIC_EXCHANGE
:
10726 if (resolve_overloaded_atomic_exchange (loc
, function
, params
,
10729 /* Change to the _N variant. */
10730 orig_code
= BUILT_IN_ATOMIC_EXCHANGE_N
;
10734 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10736 if (resolve_overloaded_atomic_compare_exchange (loc
, function
,
10740 /* Change to the _N variant. */
10741 orig_code
= BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
;
10744 case BUILT_IN_ATOMIC_LOAD
:
10746 if (resolve_overloaded_atomic_load (loc
, function
, params
,
10749 /* Change to the _N variant. */
10750 orig_code
= BUILT_IN_ATOMIC_LOAD_N
;
10753 case BUILT_IN_ATOMIC_STORE
:
10755 if (resolve_overloaded_atomic_store (loc
, function
, params
,
10758 /* Change to the _N variant. */
10759 orig_code
= BUILT_IN_ATOMIC_STORE_N
;
10763 gcc_unreachable ();
10765 /* Fallthrough to the normal processing. */
10767 case BUILT_IN_ATOMIC_EXCHANGE_N
:
10768 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
:
10769 case BUILT_IN_ATOMIC_LOAD_N
:
10770 case BUILT_IN_ATOMIC_STORE_N
:
10771 case BUILT_IN_ATOMIC_ADD_FETCH_N
:
10772 case BUILT_IN_ATOMIC_SUB_FETCH_N
:
10773 case BUILT_IN_ATOMIC_AND_FETCH_N
:
10774 case BUILT_IN_ATOMIC_NAND_FETCH_N
:
10775 case BUILT_IN_ATOMIC_XOR_FETCH_N
:
10776 case BUILT_IN_ATOMIC_OR_FETCH_N
:
10777 case BUILT_IN_ATOMIC_FETCH_ADD_N
:
10778 case BUILT_IN_ATOMIC_FETCH_SUB_N
:
10779 case BUILT_IN_ATOMIC_FETCH_AND_N
:
10780 case BUILT_IN_ATOMIC_FETCH_NAND_N
:
10781 case BUILT_IN_ATOMIC_FETCH_XOR_N
:
10782 case BUILT_IN_ATOMIC_FETCH_OR_N
:
10784 orig_format
= false;
10785 /* Fallthru for parameter processing. */
10787 case BUILT_IN_SYNC_FETCH_AND_ADD_N
:
10788 case BUILT_IN_SYNC_FETCH_AND_SUB_N
:
10789 case BUILT_IN_SYNC_FETCH_AND_OR_N
:
10790 case BUILT_IN_SYNC_FETCH_AND_AND_N
:
10791 case BUILT_IN_SYNC_FETCH_AND_XOR_N
:
10792 case BUILT_IN_SYNC_FETCH_AND_NAND_N
:
10793 case BUILT_IN_SYNC_ADD_AND_FETCH_N
:
10794 case BUILT_IN_SYNC_SUB_AND_FETCH_N
:
10795 case BUILT_IN_SYNC_OR_AND_FETCH_N
:
10796 case BUILT_IN_SYNC_AND_AND_FETCH_N
:
10797 case BUILT_IN_SYNC_XOR_AND_FETCH_N
:
10798 case BUILT_IN_SYNC_NAND_AND_FETCH_N
:
10799 case BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
:
10800 case BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N
:
10801 case BUILT_IN_SYNC_LOCK_TEST_AND_SET_N
:
10802 case BUILT_IN_SYNC_LOCK_RELEASE_N
:
10804 int n
= sync_resolve_size (function
, params
);
10805 tree new_function
, first_param
, result
;
10806 enum built_in_function fncode
;
10809 return error_mark_node
;
10811 fncode
= (enum built_in_function
)((int)orig_code
+ exact_log2 (n
) + 1);
10812 new_function
= builtin_decl_explicit (fncode
);
10813 if (!sync_resolve_params (loc
, function
, new_function
, params
,
10815 return error_mark_node
;
10817 first_param
= (*params
)[0];
10818 result
= build_function_call_vec (loc
, new_function
, params
, NULL
);
10819 if (result
== error_mark_node
)
10821 if (orig_code
!= BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
10822 && orig_code
!= BUILT_IN_SYNC_LOCK_RELEASE_N
10823 && orig_code
!= BUILT_IN_ATOMIC_STORE_N
)
10824 result
= sync_resolve_return (first_param
, result
, orig_format
);
10826 /* If new_return is set, assign function to that expr and cast the
10827 result to void since the generic interface returned void. */
10830 /* Cast function result from I{1,2,4,8,16} to the required type. */
10831 result
= build1 (VIEW_CONVERT_EXPR
, TREE_TYPE (new_return
), result
);
10832 result
= build2 (MODIFY_EXPR
, TREE_TYPE (new_return
), new_return
,
10834 TREE_SIDE_EFFECTS (result
) = 1;
10835 protected_set_expr_location (result
, loc
);
10836 result
= convert (void_type_node
, result
);
10846 /* vector_types_compatible_elements_p is used in type checks of vectors
10847 values used as operands of binary operators. Where it returns true, and
10848 the other checks of the caller succeed (being vector types in he first
10849 place, and matching number of elements), we can just treat the types
10850 as essentially the same.
10851 Contrast with vector_targets_convertible_p, which is used for vector
10852 pointer types, and vector_types_convertible_p, which will allow
10853 language-specific matches under the control of flag_lax_vector_conversions,
10854 and might still require a conversion. */
10855 /* True if vector types T1 and T2 can be inputs to the same binary
10856 operator without conversion.
10857 We don't check the overall vector size here because some of our callers
10858 want to give different error messages when the vectors are compatible
10859 except for the element count. */
10862 vector_types_compatible_elements_p (tree t1
, tree t2
)
10864 bool opaque
= TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
);
10865 t1
= TREE_TYPE (t1
);
10866 t2
= TREE_TYPE (t2
);
10868 enum tree_code c1
= TREE_CODE (t1
), c2
= TREE_CODE (t2
);
10870 gcc_assert ((c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
|| c1
== FIXED_POINT_TYPE
)
10871 && (c2
== INTEGER_TYPE
|| c2
== REAL_TYPE
10872 || c2
== FIXED_POINT_TYPE
));
10874 t1
= c_common_signed_type (t1
);
10875 t2
= c_common_signed_type (t2
);
10876 /* Equality works here because c_common_signed_type uses
10877 TYPE_MAIN_VARIANT. */
10880 if (opaque
&& c1
== c2
10881 && (c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
)
10882 && TYPE_PRECISION (t1
) == TYPE_PRECISION (t2
))
10887 /* Check for missing format attributes on function pointers. LTYPE is
10888 the new type or left-hand side type. RTYPE is the old type or
10889 right-hand side type. Returns TRUE if LTYPE is missing the desired
10893 check_missing_format_attribute (tree ltype
, tree rtype
)
10895 tree
const ttr
= TREE_TYPE (rtype
), ttl
= TREE_TYPE (ltype
);
10898 for (ra
= TYPE_ATTRIBUTES (ttr
); ra
; ra
= TREE_CHAIN (ra
))
10899 if (is_attribute_p ("format", TREE_PURPOSE (ra
)))
10904 for (la
= TYPE_ATTRIBUTES (ttl
); la
; la
= TREE_CHAIN (la
))
10905 if (is_attribute_p ("format", TREE_PURPOSE (la
)))
10913 /* Subscripting with type char is likely to lose on a machine where
10914 chars are signed. So warn on any machine, but optionally. Don't
10915 warn for unsigned char since that type is safe. Don't warn for
10916 signed char because anyone who uses that must have done so
10917 deliberately. Furthermore, we reduce the false positive load by
10918 warning only for non-constant value of type char. */
10921 warn_array_subscript_with_type_char (tree index
)
10923 if (TYPE_MAIN_VARIANT (TREE_TYPE (index
)) == char_type_node
10924 && TREE_CODE (index
) != INTEGER_CST
)
10925 warning (OPT_Wchar_subscripts
, "array subscript has type %<char%>");
10928 /* Implement -Wparentheses for the unexpected C precedence rules, to
10929 cover cases like x + y << z which readers are likely to
10930 misinterpret. We have seen an expression in which CODE is a binary
10931 operator used to combine expressions ARG_LEFT and ARG_RIGHT, which
10932 before folding had CODE_LEFT and CODE_RIGHT. CODE_LEFT and
10933 CODE_RIGHT may be ERROR_MARK, which means that that side of the
10934 expression was not formed using a binary or unary operator, or it
10935 was enclosed in parentheses. */
10938 warn_about_parentheses (location_t loc
, enum tree_code code
,
10939 enum tree_code code_left
, tree arg_left
,
10940 enum tree_code code_right
, tree arg_right
)
10942 if (!warn_parentheses
)
10945 /* This macro tests that the expression ARG with original tree code
10946 CODE appears to be a boolean expression. or the result of folding a
10947 boolean expression. */
10948 #define APPEARS_TO_BE_BOOLEAN_EXPR_P(CODE, ARG) \
10949 (truth_value_p (TREE_CODE (ARG)) \
10950 || TREE_CODE (TREE_TYPE (ARG)) == BOOLEAN_TYPE \
10951 /* Folding may create 0 or 1 integers from other expressions. */ \
10952 || ((CODE) != INTEGER_CST \
10953 && (integer_onep (ARG) || integer_zerop (ARG))))
10958 if (code_left
== PLUS_EXPR
)
10959 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10960 "suggest parentheses around %<+%> inside %<<<%>");
10961 else if (code_right
== PLUS_EXPR
)
10962 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10963 "suggest parentheses around %<+%> inside %<<<%>");
10964 else if (code_left
== MINUS_EXPR
)
10965 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10966 "suggest parentheses around %<-%> inside %<<<%>");
10967 else if (code_right
== MINUS_EXPR
)
10968 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10969 "suggest parentheses around %<-%> inside %<<<%>");
10973 if (code_left
== PLUS_EXPR
)
10974 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10975 "suggest parentheses around %<+%> inside %<>>%>");
10976 else if (code_right
== PLUS_EXPR
)
10977 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10978 "suggest parentheses around %<+%> inside %<>>%>");
10979 else if (code_left
== MINUS_EXPR
)
10980 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10981 "suggest parentheses around %<-%> inside %<>>%>");
10982 else if (code_right
== MINUS_EXPR
)
10983 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10984 "suggest parentheses around %<-%> inside %<>>%>");
10987 case TRUTH_ORIF_EXPR
:
10988 if (code_left
== TRUTH_ANDIF_EXPR
)
10989 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10990 "suggest parentheses around %<&&%> within %<||%>");
10991 else if (code_right
== TRUTH_ANDIF_EXPR
)
10992 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10993 "suggest parentheses around %<&&%> within %<||%>");
10997 if (code_left
== BIT_AND_EXPR
|| code_left
== BIT_XOR_EXPR
10998 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
)
10999 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11000 "suggest parentheses around arithmetic in operand of %<|%>");
11001 else if (code_right
== BIT_AND_EXPR
|| code_right
== BIT_XOR_EXPR
11002 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
11003 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11004 "suggest parentheses around arithmetic in operand of %<|%>");
11005 /* Check cases like x|y==z */
11006 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11007 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11008 "suggest parentheses around comparison in operand of %<|%>");
11009 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11010 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11011 "suggest parentheses around comparison in operand of %<|%>");
11012 /* Check cases like !x | y */
11013 else if (code_left
== TRUTH_NOT_EXPR
11014 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
11015 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11016 "suggest parentheses around operand of "
11017 "%<!%> or change %<|%> to %<||%> or %<!%> to %<~%>");
11021 if (code_left
== BIT_AND_EXPR
11022 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
)
11023 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11024 "suggest parentheses around arithmetic in operand of %<^%>");
11025 else if (code_right
== BIT_AND_EXPR
11026 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
11027 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11028 "suggest parentheses around arithmetic in operand of %<^%>");
11029 /* Check cases like x^y==z */
11030 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11031 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11032 "suggest parentheses around comparison in operand of %<^%>");
11033 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11034 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11035 "suggest parentheses around comparison in operand of %<^%>");
11039 if (code_left
== PLUS_EXPR
)
11040 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11041 "suggest parentheses around %<+%> in operand of %<&%>");
11042 else if (code_right
== PLUS_EXPR
)
11043 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11044 "suggest parentheses around %<+%> in operand of %<&%>");
11045 else if (code_left
== MINUS_EXPR
)
11046 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11047 "suggest parentheses around %<-%> in operand of %<&%>");
11048 else if (code_right
== MINUS_EXPR
)
11049 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11050 "suggest parentheses around %<-%> in operand of %<&%>");
11051 /* Check cases like x&y==z */
11052 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11053 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11054 "suggest parentheses around comparison in operand of %<&%>");
11055 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11056 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11057 "suggest parentheses around comparison in operand of %<&%>");
11058 /* Check cases like !x & y */
11059 else if (code_left
== TRUTH_NOT_EXPR
11060 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
11061 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11062 "suggest parentheses around operand of "
11063 "%<!%> or change %<&%> to %<&&%> or %<!%> to %<~%>");
11067 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11068 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11069 "suggest parentheses around comparison in operand of %<==%>");
11070 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11071 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11072 "suggest parentheses around comparison in operand of %<==%>");
11075 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11076 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11077 "suggest parentheses around comparison in operand of %<!=%>");
11078 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11079 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11080 "suggest parentheses around comparison in operand of %<!=%>");
11084 if (TREE_CODE_CLASS (code
) == tcc_comparison
)
11086 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
11087 && code_left
!= NE_EXPR
&& code_left
!= EQ_EXPR
11088 && INTEGRAL_TYPE_P (TREE_TYPE (arg_left
)))
11089 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11090 "comparisons like %<X<=Y<=Z%> do not "
11091 "have their mathematical meaning");
11092 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
11093 && code_right
!= NE_EXPR
&& code_right
!= EQ_EXPR
11094 && INTEGRAL_TYPE_P (TREE_TYPE (arg_right
)))
11095 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11096 "comparisons like %<X<=Y<=Z%> do not "
11097 "have their mathematical meaning");
11101 #undef NOT_A_BOOLEAN_EXPR_P
11104 /* If LABEL (a LABEL_DECL) has not been used, issue a warning. */
11107 warn_for_unused_label (tree label
)
11109 if (!TREE_USED (label
))
11111 if (DECL_INITIAL (label
))
11112 warning (OPT_Wunused_label
, "label %q+D defined but not used", label
);
11114 warning (OPT_Wunused_label
, "label %q+D declared but not defined", label
);
11118 /* Warn for division by zero according to the value of DIVISOR. LOC
11119 is the location of the division operator. */
11122 warn_for_div_by_zero (location_t loc
, tree divisor
)
11124 /* If DIVISOR is zero, and has integral or fixed-point type, issue a warning
11125 about division by zero. Do not issue a warning if DIVISOR has a
11126 floating-point type, since we consider 0.0/0.0 a valid way of
11127 generating a NaN. */
11128 if (c_inhibit_evaluation_warnings
== 0
11129 && (integer_zerop (divisor
) || fixed_zerop (divisor
)))
11130 warning_at (loc
, OPT_Wdiv_by_zero
, "division by zero");
11133 /* Subroutine of build_binary_op. Give warnings for comparisons
11134 between signed and unsigned quantities that may fail. Do the
11135 checking based on the original operand trees ORIG_OP0 and ORIG_OP1,
11136 so that casts will be considered, but default promotions won't
11139 LOCATION is the location of the comparison operator.
11141 The arguments of this function map directly to local variables
11142 of build_binary_op. */
11145 warn_for_sign_compare (location_t location
,
11146 tree orig_op0
, tree orig_op1
,
11147 tree op0
, tree op1
,
11148 tree result_type
, enum tree_code resultcode
)
11150 int op0_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op0
));
11151 int op1_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op1
));
11152 int unsignedp0
, unsignedp1
;
11154 /* In C++, check for comparison of different enum types. */
11155 if (c_dialect_cxx()
11156 && TREE_CODE (TREE_TYPE (orig_op0
)) == ENUMERAL_TYPE
11157 && TREE_CODE (TREE_TYPE (orig_op1
)) == ENUMERAL_TYPE
11158 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0
))
11159 != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1
)))
11161 warning_at (location
,
11162 OPT_Wsign_compare
, "comparison between types %qT and %qT",
11163 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
));
11166 /* Do not warn if the comparison is being done in a signed type,
11167 since the signed type will only be chosen if it can represent
11168 all the values of the unsigned type. */
11169 if (!TYPE_UNSIGNED (result_type
))
11171 /* Do not warn if both operands are unsigned. */
11172 else if (op0_signed
== op1_signed
)
11176 tree sop
, uop
, base_type
;
11180 sop
= orig_op0
, uop
= orig_op1
;
11182 sop
= orig_op1
, uop
= orig_op0
;
11184 STRIP_TYPE_NOPS (sop
);
11185 STRIP_TYPE_NOPS (uop
);
11186 base_type
= (TREE_CODE (result_type
) == COMPLEX_TYPE
11187 ? TREE_TYPE (result_type
) : result_type
);
11189 /* Do not warn if the signed quantity is an unsuffixed integer
11190 literal (or some static constant expression involving such
11191 literals or a conditional expression involving such literals)
11192 and it is non-negative. */
11193 if (tree_expr_nonnegative_warnv_p (sop
, &ovf
))
11195 /* Do not warn if the comparison is an equality operation, the
11196 unsigned quantity is an integral constant, and it would fit
11197 in the result if the result were signed. */
11198 else if (TREE_CODE (uop
) == INTEGER_CST
11199 && (resultcode
== EQ_EXPR
|| resultcode
== NE_EXPR
)
11200 && int_fits_type_p (uop
, c_common_signed_type (base_type
)))
11202 /* In C, do not warn if the unsigned quantity is an enumeration
11203 constant and its maximum value would fit in the result if the
11204 result were signed. */
11205 else if (!c_dialect_cxx() && TREE_CODE (uop
) == INTEGER_CST
11206 && TREE_CODE (TREE_TYPE (uop
)) == ENUMERAL_TYPE
11207 && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (uop
)),
11208 c_common_signed_type (base_type
)))
11211 warning_at (location
,
11213 "comparison between signed and unsigned integer expressions");
11216 /* Warn if two unsigned values are being compared in a size larger
11217 than their original size, and one (and only one) is the result of
11218 a `~' operator. This comparison will always fail.
11220 Also warn if one operand is a constant, and the constant does not
11221 have all bits set that are set in the ~ operand when it is
11224 op0
= c_common_get_narrower (op0
, &unsignedp0
);
11225 op1
= c_common_get_narrower (op1
, &unsignedp1
);
11227 if ((TREE_CODE (op0
) == BIT_NOT_EXPR
)
11228 ^ (TREE_CODE (op1
) == BIT_NOT_EXPR
))
11230 if (TREE_CODE (op0
) == BIT_NOT_EXPR
)
11231 op0
= c_common_get_narrower (TREE_OPERAND (op0
, 0), &unsignedp0
);
11232 if (TREE_CODE (op1
) == BIT_NOT_EXPR
)
11233 op1
= c_common_get_narrower (TREE_OPERAND (op1
, 0), &unsignedp1
);
11235 if (tree_fits_shwi_p (op0
) || tree_fits_shwi_p (op1
))
11238 HOST_WIDE_INT constant
, mask
;
11242 if (tree_fits_shwi_p (op0
))
11245 unsignedp
= unsignedp1
;
11246 constant
= tree_to_shwi (op0
);
11251 unsignedp
= unsignedp0
;
11252 constant
= tree_to_shwi (op1
);
11255 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
11256 if (bits
< TYPE_PRECISION (result_type
)
11257 && bits
< HOST_BITS_PER_LONG
&& unsignedp
)
11259 mask
= (~ (HOST_WIDE_INT
) 0) << bits
;
11260 if ((mask
& constant
) != mask
)
11263 warning (OPT_Wsign_compare
,
11264 "promoted ~unsigned is always non-zero");
11266 warning_at (location
, OPT_Wsign_compare
,
11267 "comparison of promoted ~unsigned with constant");
11271 else if (unsignedp0
&& unsignedp1
11272 && (TYPE_PRECISION (TREE_TYPE (op0
))
11273 < TYPE_PRECISION (result_type
))
11274 && (TYPE_PRECISION (TREE_TYPE (op1
))
11275 < TYPE_PRECISION (result_type
)))
11276 warning_at (location
, OPT_Wsign_compare
,
11277 "comparison of promoted ~unsigned with unsigned");
11281 /* RESULT_TYPE is the result of converting TYPE1 and TYPE2 to a common
11282 type via c_common_type. If -Wdouble-promotion is in use, and the
11283 conditions for warning have been met, issue a warning. GMSGID is
11284 the warning message. It must have two %T specifiers for the type
11285 that was converted (generally "float") and the type to which it was
11286 converted (generally "double), respectively. LOC is the location
11287 to which the awrning should refer. */
11290 do_warn_double_promotion (tree result_type
, tree type1
, tree type2
,
11291 const char *gmsgid
, location_t loc
)
11295 if (!warn_double_promotion
)
11297 /* If the conversion will not occur at run-time, there is no need to
11299 if (c_inhibit_evaluation_warnings
)
11301 if (TYPE_MAIN_VARIANT (result_type
) != double_type_node
11302 && TYPE_MAIN_VARIANT (result_type
) != complex_double_type_node
)
11304 if (TYPE_MAIN_VARIANT (type1
) == float_type_node
11305 || TYPE_MAIN_VARIANT (type1
) == complex_float_type_node
)
11306 source_type
= type1
;
11307 else if (TYPE_MAIN_VARIANT (type2
) == float_type_node
11308 || TYPE_MAIN_VARIANT (type2
) == complex_float_type_node
)
11309 source_type
= type2
;
11312 warning_at (loc
, OPT_Wdouble_promotion
, gmsgid
, source_type
, result_type
);
11315 /* Setup a TYPE_DECL node as a typedef representation.
11317 X is a TYPE_DECL for a typedef statement. Create a brand new
11318 ..._TYPE node (which will be just a variant of the existing
11319 ..._TYPE node with identical properties) and then install X
11320 as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
11322 The whole point here is to end up with a situation where each
11323 and every ..._TYPE node the compiler creates will be uniquely
11324 associated with AT MOST one node representing a typedef name.
11325 This way, even though the compiler substitutes corresponding
11326 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
11327 early on, later parts of the compiler can always do the reverse
11328 translation and get back the corresponding typedef name. For
11331 typedef struct S MY_TYPE;
11334 Later parts of the compiler might only know that `object' was of
11335 type `struct S' if it were not for code just below. With this
11336 code however, later parts of the compiler see something like:
11338 struct S' == struct S
11339 typedef struct S' MY_TYPE;
11342 And they can then deduce (from the node for type struct S') that
11343 the original object declaration was:
11347 Being able to do this is important for proper support of protoize,
11348 and also for generating precise symbolic debugging information
11349 which takes full account of the programmer's (typedef) vocabulary.
11351 Obviously, we don't want to generate a duplicate ..._TYPE node if
11352 the TYPE_DECL node that we are now processing really represents a
11353 standard built-in type. */
11356 set_underlying_type (tree x
)
11358 if (x
== error_mark_node
)
11360 if (DECL_IS_BUILTIN (x
))
11362 if (TYPE_NAME (TREE_TYPE (x
)) == 0)
11363 TYPE_NAME (TREE_TYPE (x
)) = x
;
11365 else if (TREE_TYPE (x
) != error_mark_node
11366 && DECL_ORIGINAL_TYPE (x
) == NULL_TREE
)
11368 tree tt
= TREE_TYPE (x
);
11369 DECL_ORIGINAL_TYPE (x
) = tt
;
11370 tt
= build_variant_type_copy (tt
);
11371 TYPE_STUB_DECL (tt
) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x
));
11372 TYPE_NAME (tt
) = x
;
11373 TREE_USED (tt
) = TREE_USED (x
);
11374 TREE_TYPE (x
) = tt
;
11378 /* Record the types used by the current global variable declaration
11379 being parsed, so that we can decide later to emit their debug info.
11380 Those types are in types_used_by_cur_var_decl, and we are going to
11381 store them in the types_used_by_vars_hash hash table.
11382 DECL is the declaration of the global variable that has been parsed. */
11385 record_types_used_by_current_var_decl (tree decl
)
11387 gcc_assert (decl
&& DECL_P (decl
) && TREE_STATIC (decl
));
11389 while (types_used_by_cur_var_decl
&& !types_used_by_cur_var_decl
->is_empty ())
11391 tree type
= types_used_by_cur_var_decl
->pop ();
11392 types_used_by_var_decl_insert (type
, decl
);
11396 /* If DECL is a typedef that is declared in the current function,
11397 record it for the purpose of -Wunused-local-typedefs. */
11400 record_locally_defined_typedef (tree decl
)
11402 struct c_language_function
*l
;
11404 if (!warn_unused_local_typedefs
11406 /* if this is not a locally defined typedef then we are not
11408 || !is_typedef_decl (decl
)
11409 || !decl_function_context (decl
))
11412 l
= (struct c_language_function
*) cfun
->language
;
11413 vec_safe_push (l
->local_typedefs
, decl
);
11416 /* If T is a TYPE_DECL declared locally, mark it as used. */
11419 maybe_record_typedef_use (tree t
)
11421 if (!is_typedef_decl (t
))
11424 TREE_USED (t
) = true;
11427 /* Warn if there are some unused locally defined typedefs in the
11428 current function. */
11431 maybe_warn_unused_local_typedefs (void)
11435 /* The number of times we have emitted -Wunused-local-typedefs
11436 warnings. If this is different from errorcount, that means some
11437 unrelated errors have been issued. In which case, we'll avoid
11438 emitting "unused-local-typedefs" warnings. */
11439 static int unused_local_typedefs_warn_count
;
11440 struct c_language_function
*l
;
11445 if ((l
= (struct c_language_function
*) cfun
->language
) == NULL
)
11448 if (warn_unused_local_typedefs
11449 && errorcount
== unused_local_typedefs_warn_count
)
11451 FOR_EACH_VEC_SAFE_ELT (l
->local_typedefs
, i
, decl
)
11452 if (!TREE_USED (decl
))
11453 warning_at (DECL_SOURCE_LOCATION (decl
),
11454 OPT_Wunused_local_typedefs
,
11455 "typedef %qD locally defined but not used", decl
);
11456 unused_local_typedefs_warn_count
= errorcount
;
11459 vec_free (l
->local_typedefs
);
11462 /* The C and C++ parsers both use vectors to hold function arguments.
11463 For efficiency, we keep a cache of unused vectors. This is the
11466 typedef vec
<tree
, va_gc
> *tree_gc_vec
;
11467 static GTY((deletable
)) vec
<tree_gc_vec
, va_gc
> *tree_vector_cache
;
11469 /* Return a new vector from the cache. If the cache is empty,
11470 allocate a new vector. These vectors are GC'ed, so it is OK if the
11471 pointer is not released.. */
11474 make_tree_vector (void)
11476 if (tree_vector_cache
&& !tree_vector_cache
->is_empty ())
11477 return tree_vector_cache
->pop ();
11480 /* Passing 0 to vec::alloc returns NULL, and our callers require
11481 that we always return a non-NULL value. The vector code uses
11482 4 when growing a NULL vector, so we do too. */
11483 vec
<tree
, va_gc
> *v
;
11489 /* Release a vector of trees back to the cache. */
11492 release_tree_vector (vec
<tree
, va_gc
> *vec
)
11497 vec_safe_push (tree_vector_cache
, vec
);
11501 /* Get a new tree vector holding a single tree. */
11504 make_tree_vector_single (tree t
)
11506 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
11507 ret
->quick_push (t
);
11511 /* Get a new tree vector of the TREE_VALUEs of a TREE_LIST chain. */
11514 make_tree_vector_from_list (tree list
)
11516 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
11517 for (; list
; list
= TREE_CHAIN (list
))
11518 vec_safe_push (ret
, TREE_VALUE (list
));
11522 /* Get a new tree vector which is a copy of an existing one. */
11525 make_tree_vector_copy (const vec
<tree
, va_gc
> *orig
)
11527 vec
<tree
, va_gc
> *ret
;
11531 ret
= make_tree_vector ();
11532 vec_safe_reserve (ret
, vec_safe_length (orig
));
11533 FOR_EACH_VEC_SAFE_ELT (orig
, ix
, t
)
11534 ret
->quick_push (t
);
11538 /* Return true if KEYWORD starts a type specifier. */
11541 keyword_begins_type_specifier (enum rid keyword
)
11545 case RID_AUTO_TYPE
:
11558 case RID_DFLOAT128
:
11578 /* Return true if KEYWORD names a type qualifier. */
11581 keyword_is_type_qualifier (enum rid keyword
)
11595 /* Return true if KEYWORD names a storage class specifier.
11597 RID_TYPEDEF is not included in this list despite `typedef' being
11598 listed in C99 6.7.1.1. 6.7.1.3 indicates that `typedef' is listed as
11599 such for syntactic convenience only. */
11602 keyword_is_storage_class_specifier (enum rid keyword
)
11618 /* Return true if KEYWORD names a function-specifier [dcl.fct.spec]. */
11621 keyword_is_function_specifier (enum rid keyword
)
11635 /* Return true if KEYWORD names a decl-specifier [dcl.spec] or a
11636 declaration-specifier (C99 6.7). */
11639 keyword_is_decl_specifier (enum rid keyword
)
11641 if (keyword_is_storage_class_specifier (keyword
)
11642 || keyword_is_type_qualifier (keyword
)
11643 || keyword_is_function_specifier (keyword
))
11650 case RID_CONSTEXPR
:
11657 /* Initialize language-specific-bits of tree_contains_struct. */
11660 c_common_init_ts (void)
11662 MARK_TS_TYPED (C_MAYBE_CONST_EXPR
);
11663 MARK_TS_TYPED (EXCESS_PRECISION_EXPR
);
11664 MARK_TS_TYPED (ARRAY_NOTATION_REF
);
11667 /* Build a user-defined numeric literal out of an integer constant type VALUE
11668 with identifier SUFFIX. */
11671 build_userdef_literal (tree suffix_id
, tree value
,
11672 enum overflow_type overflow
, tree num_string
)
11674 tree literal
= make_node (USERDEF_LITERAL
);
11675 USERDEF_LITERAL_SUFFIX_ID (literal
) = suffix_id
;
11676 USERDEF_LITERAL_VALUE (literal
) = value
;
11677 USERDEF_LITERAL_OVERFLOW (literal
) = overflow
;
11678 USERDEF_LITERAL_NUM_STRING (literal
) = num_string
;
11682 /* For vector[index], convert the vector to a
11683 pointer of the underlying type. */
11685 convert_vector_to_pointer_for_subscript (location_t loc
,
11686 tree
* vecp
, tree index
)
11688 if (TREE_CODE (TREE_TYPE (*vecp
)) == VECTOR_TYPE
)
11690 tree type
= TREE_TYPE (*vecp
);
11693 if (TREE_CODE (index
) == INTEGER_CST
)
11694 if (!tree_fits_uhwi_p (index
)
11695 || tree_to_uhwi (index
) >= TYPE_VECTOR_SUBPARTS (type
))
11696 warning_at (loc
, OPT_Warray_bounds
, "index value is out of bound");
11698 c_common_mark_addressable_vec (*vecp
);
11699 type
= build_qualified_type (TREE_TYPE (type
), TYPE_QUALS (type
));
11700 type
= build_pointer_type (type
);
11701 type1
= build_pointer_type (TREE_TYPE (*vecp
));
11702 *vecp
= build1 (ADDR_EXPR
, type1
, *vecp
);
11703 *vecp
= convert (type
, *vecp
);
11707 /* Determine which of the operands, if any, is a scalar that needs to be
11708 converted to a vector, for the range of operations. */
11710 scalar_to_vector (location_t loc
, enum tree_code code
, tree op0
, tree op1
,
11713 tree type0
= TREE_TYPE (op0
);
11714 tree type1
= TREE_TYPE (op1
);
11715 bool integer_only_op
= false;
11716 enum stv_conv ret
= stv_firstarg
;
11718 gcc_assert (TREE_CODE (type0
) == VECTOR_TYPE
11719 || TREE_CODE (type1
) == VECTOR_TYPE
);
11722 /* Most GENERIC binary expressions require homogeneous arguments.
11723 LSHIFT_EXPR and RSHIFT_EXPR are exceptions and accept a first
11724 argument that is a vector and a second one that is a scalar, so
11725 we never return stv_secondarg for them. */
11728 if (TREE_CODE (type0
) == INTEGER_TYPE
11729 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
11731 if (unsafe_conversion_p (TREE_TYPE (type1
), op0
, false))
11734 error_at (loc
, "conversion of scalar %qT to vector %qT "
11735 "involves truncation", type0
, type1
);
11739 return stv_firstarg
;
11746 integer_only_op
= true;
11747 /* ... fall through ... */
11749 case VEC_COND_EXPR
:
11754 case TRUNC_DIV_EXPR
:
11755 case CEIL_DIV_EXPR
:
11756 case FLOOR_DIV_EXPR
:
11757 case ROUND_DIV_EXPR
:
11758 case EXACT_DIV_EXPR
:
11759 case TRUNC_MOD_EXPR
:
11760 case FLOOR_MOD_EXPR
:
11768 /* What about UNLT_EXPR? */
11769 if (TREE_CODE (type0
) == VECTOR_TYPE
)
11772 ret
= stv_secondarg
;
11773 /* Swap TYPE0 with TYPE1 and OP0 with OP1 */
11774 tmp
= type0
; type0
= type1
; type1
= tmp
;
11775 tmp
= op0
; op0
= op1
; op1
= tmp
;
11778 if (TREE_CODE (type0
) == INTEGER_TYPE
11779 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
11781 if (unsafe_conversion_p (TREE_TYPE (type1
), op0
, false))
11784 error_at (loc
, "conversion of scalar %qT to vector %qT "
11785 "involves truncation", type0
, type1
);
11790 else if (!integer_only_op
11791 /* Allow integer --> real conversion if safe. */
11792 && (TREE_CODE (type0
) == REAL_TYPE
11793 || TREE_CODE (type0
) == INTEGER_TYPE
)
11794 && SCALAR_FLOAT_TYPE_P (TREE_TYPE (type1
)))
11796 if (unsafe_conversion_p (TREE_TYPE (type1
), op0
, false))
11799 error_at (loc
, "conversion of scalar %qT to vector %qT "
11800 "involves truncation", type0
, type1
);
11809 return stv_nothing
;
11812 /* Return true iff ALIGN is an integral constant that is a fundamental
11813 alignment, as defined by [basic.align] in the c++-11
11818 [A fundamental alignment is represented by an alignment less than or
11819 equal to the greatest alignment supported by the implementation
11820 in all contexts, which is equal to
11821 alignof(max_align_t)]. */
11824 cxx_fundamental_alignment_p (unsigned align
)
11826 return (align
<= MAX (TYPE_ALIGN (long_long_integer_type_node
),
11827 TYPE_ALIGN (long_double_type_node
)));
11830 #include "gt-c-family-c-common.h"