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"
35 #include "common/common-target.h"
36 #include "langhooks.h"
37 #include "tree-inline.h"
39 #include "diagnostic.h"
40 #include "tree-iterator.h"
42 #include "tree-mudflap.h"
45 #include "target-def.h"
46 #include "wide-int-print.h"
48 cpp_reader
*parse_in
; /* Declared in c-pragma.h. */
50 /* The following symbols are subsumed in the c_global_trees array, and
51 listed here individually for documentation purposes.
53 INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
55 tree short_integer_type_node;
56 tree long_integer_type_node;
57 tree long_long_integer_type_node;
58 tree int128_integer_type_node;
60 tree short_unsigned_type_node;
61 tree long_unsigned_type_node;
62 tree long_long_unsigned_type_node;
63 tree int128_unsigned_type_node;
65 tree truthvalue_type_node;
66 tree truthvalue_false_node;
67 tree truthvalue_true_node;
69 tree ptrdiff_type_node;
71 tree unsigned_char_type_node;
72 tree signed_char_type_node;
75 tree char16_type_node;
76 tree char32_type_node;
79 tree double_type_node;
80 tree long_double_type_node;
82 tree complex_integer_type_node;
83 tree complex_float_type_node;
84 tree complex_double_type_node;
85 tree complex_long_double_type_node;
87 tree dfloat32_type_node;
88 tree dfloat64_type_node;
89 tree_dfloat128_type_node;
97 tree unsigned_intQI_type_node;
98 tree unsigned_intHI_type_node;
99 tree unsigned_intSI_type_node;
100 tree unsigned_intDI_type_node;
101 tree unsigned_intTI_type_node;
103 tree widest_integer_literal_type_node;
104 tree widest_unsigned_literal_type_node;
106 Nodes for types `void *' and `const void *'.
108 tree ptr_type_node, const_ptr_type_node;
110 Nodes for types `char *' and `const char *'.
112 tree string_type_node, const_string_type_node;
114 Type `char[SOMENUMBER]'.
115 Used when an array of char is needed and the size is irrelevant.
117 tree char_array_type_node;
119 Type `int[SOMENUMBER]' or something like it.
120 Used when an array of int needed and the size is irrelevant.
122 tree int_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_noinline_attribute (tree
*, tree
, tree
, int, bool *);
316 static tree
handle_noclone_attribute (tree
*, tree
, tree
, int, bool *);
317 static tree
handle_leaf_attribute (tree
*, tree
, tree
, int, bool *);
318 static tree
handle_always_inline_attribute (tree
*, tree
, tree
, int,
320 static tree
handle_gnu_inline_attribute (tree
*, tree
, tree
, int, bool *);
321 static tree
handle_artificial_attribute (tree
*, tree
, tree
, int, bool *);
322 static tree
handle_flatten_attribute (tree
*, tree
, tree
, int, bool *);
323 static tree
handle_error_attribute (tree
*, tree
, tree
, int, bool *);
324 static tree
handle_used_attribute (tree
*, tree
, tree
, int, bool *);
325 static tree
handle_unused_attribute (tree
*, tree
, tree
, int, bool *);
326 static tree
handle_externally_visible_attribute (tree
*, tree
, tree
, int,
328 static tree
handle_const_attribute (tree
*, tree
, tree
, int, bool *);
329 static tree
handle_transparent_union_attribute (tree
*, tree
, tree
,
331 static tree
handle_constructor_attribute (tree
*, tree
, tree
, int, bool *);
332 static tree
handle_destructor_attribute (tree
*, tree
, tree
, int, bool *);
333 static tree
handle_mode_attribute (tree
*, tree
, tree
, int, bool *);
334 static tree
handle_section_attribute (tree
*, tree
, tree
, int, bool *);
335 static tree
handle_aligned_attribute (tree
*, tree
, tree
, int, bool *);
336 static tree
handle_weak_attribute (tree
*, tree
, tree
, int, bool *) ;
337 static tree
handle_alias_ifunc_attribute (bool, tree
*, tree
, tree
, bool *);
338 static tree
handle_ifunc_attribute (tree
*, tree
, tree
, int, bool *);
339 static tree
handle_alias_attribute (tree
*, tree
, tree
, int, bool *);
340 static tree
handle_weakref_attribute (tree
*, tree
, tree
, int, bool *) ;
341 static tree
handle_visibility_attribute (tree
*, tree
, tree
, int,
343 static tree
handle_tls_model_attribute (tree
*, tree
, tree
, int,
345 static tree
handle_no_instrument_function_attribute (tree
*, tree
,
347 static tree
handle_malloc_attribute (tree
*, tree
, tree
, int, bool *);
348 static tree
handle_returns_twice_attribute (tree
*, tree
, tree
, int, bool *);
349 static tree
handle_no_limit_stack_attribute (tree
*, tree
, tree
, int,
351 static tree
handle_pure_attribute (tree
*, tree
, tree
, int, bool *);
352 static tree
handle_tm_attribute (tree
*, tree
, tree
, int, bool *);
353 static tree
handle_tm_wrap_attribute (tree
*, tree
, tree
, int, bool *);
354 static tree
handle_novops_attribute (tree
*, tree
, tree
, int, bool *);
355 static tree
handle_deprecated_attribute (tree
*, tree
, tree
, int,
357 static tree
handle_vector_size_attribute (tree
*, tree
, tree
, int,
359 static tree
handle_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
360 static tree
handle_nothrow_attribute (tree
*, tree
, tree
, int, bool *);
361 static tree
handle_cleanup_attribute (tree
*, tree
, tree
, int, bool *);
362 static tree
handle_warn_unused_result_attribute (tree
*, tree
, tree
, int,
364 static tree
handle_sentinel_attribute (tree
*, tree
, tree
, int, bool *);
365 static tree
handle_type_generic_attribute (tree
*, tree
, tree
, int, bool *);
366 static tree
handle_alloc_size_attribute (tree
*, tree
, tree
, int, bool *);
367 static tree
handle_target_attribute (tree
*, tree
, tree
, int, bool *);
368 static tree
handle_optimize_attribute (tree
*, tree
, tree
, int, bool *);
369 static tree
ignore_attribute (tree
*, tree
, tree
, int, bool *);
370 static tree
handle_no_split_stack_attribute (tree
*, tree
, tree
, int, bool *);
371 static tree
handle_fnspec_attribute (tree
*, tree
, tree
, int, bool *);
372 static tree
handle_warn_unused_attribute (tree
*, tree
, tree
, int, bool *);
374 static void check_function_nonnull (tree
, int, tree
*);
375 static void check_nonnull_arg (void *, tree
, unsigned HOST_WIDE_INT
);
376 static bool nonnull_check_p (tree
, unsigned HOST_WIDE_INT
);
377 static bool get_nonnull_operand (tree
, unsigned HOST_WIDE_INT
*);
378 static int resort_field_decl_cmp (const void *, const void *);
380 /* Reserved words. The third field is a mask: keywords are disabled
381 if they match the mask.
384 C --std=c89: D_C99 | D_CXXONLY | D_OBJC | D_CXX_OBJC
385 C --std=c99: D_CXXONLY | D_OBJC
386 ObjC is like C except that D_OBJC and D_CXX_OBJC are not set
387 C++ --std=c98: D_CONLY | D_CXXOX | D_OBJC
388 C++ --std=c0x: D_CONLY | D_OBJC
389 ObjC++ is like C++ except that D_OBJC is not set
391 If -fno-asm is used, D_ASM is added to the mask. If
392 -fno-gnu-keywords is used, D_EXT is added. If -fno-asm and C in
393 C89 mode, D_EXT89 is added for both -fno-asm and -fno-gnu-keywords.
394 In C with -Wc++-compat, we warn if D_CXXWARN is set.
396 Note the complication of the D_CXX_OBJC keywords. These are
397 reserved words such as 'class'. In C++, 'class' is a reserved
398 word. In Objective-C++ it is too. In Objective-C, it is a
399 reserved word too, but only if it follows an '@' sign.
401 const struct c_common_resword c_common_reswords
[] =
403 { "_Alignas", RID_ALIGNAS
, D_CONLY
},
404 { "_Alignof", RID_ALIGNOF
, D_CONLY
},
405 { "_Bool", RID_BOOL
, D_CONLY
},
406 { "_Complex", RID_COMPLEX
, 0 },
407 { "_Imaginary", RID_IMAGINARY
, D_CONLY
},
408 { "_Decimal32", RID_DFLOAT32
, D_CONLY
| D_EXT
},
409 { "_Decimal64", RID_DFLOAT64
, D_CONLY
| D_EXT
},
410 { "_Decimal128", RID_DFLOAT128
, D_CONLY
| D_EXT
},
411 { "_Fract", RID_FRACT
, D_CONLY
| D_EXT
},
412 { "_Accum", RID_ACCUM
, D_CONLY
| D_EXT
},
413 { "_Sat", RID_SAT
, D_CONLY
| D_EXT
},
414 { "_Static_assert", RID_STATIC_ASSERT
, D_CONLY
},
415 { "_Noreturn", RID_NORETURN
, D_CONLY
},
416 { "_Generic", RID_GENERIC
, D_CONLY
},
417 { "__FUNCTION__", RID_FUNCTION_NAME
, 0 },
418 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME
, 0 },
419 { "__alignof", RID_ALIGNOF
, 0 },
420 { "__alignof__", RID_ALIGNOF
, 0 },
421 { "__asm", RID_ASM
, 0 },
422 { "__asm__", RID_ASM
, 0 },
423 { "__attribute", RID_ATTRIBUTE
, 0 },
424 { "__attribute__", RID_ATTRIBUTE
, 0 },
425 { "__bases", RID_BASES
, D_CXXONLY
},
426 { "__builtin_choose_expr", RID_CHOOSE_EXPR
, D_CONLY
},
427 { "__builtin_complex", RID_BUILTIN_COMPLEX
, D_CONLY
},
428 { "__builtin_shuffle", RID_BUILTIN_SHUFFLE
, 0 },
429 { "__builtin_offsetof", RID_OFFSETOF
, 0 },
430 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P
, D_CONLY
},
431 { "__builtin_va_arg", RID_VA_ARG
, 0 },
432 { "__complex", RID_COMPLEX
, 0 },
433 { "__complex__", RID_COMPLEX
, 0 },
434 { "__const", RID_CONST
, 0 },
435 { "__const__", RID_CONST
, 0 },
436 { "__decltype", RID_DECLTYPE
, D_CXXONLY
},
437 { "__direct_bases", RID_DIRECT_BASES
, D_CXXONLY
},
438 { "__extension__", RID_EXTENSION
, 0 },
439 { "__func__", RID_C99_FUNCTION_NAME
, 0 },
440 { "__has_nothrow_assign", RID_HAS_NOTHROW_ASSIGN
, D_CXXONLY
},
441 { "__has_nothrow_constructor", RID_HAS_NOTHROW_CONSTRUCTOR
, D_CXXONLY
},
442 { "__has_nothrow_copy", RID_HAS_NOTHROW_COPY
, D_CXXONLY
},
443 { "__has_trivial_assign", RID_HAS_TRIVIAL_ASSIGN
, D_CXXONLY
},
444 { "__has_trivial_constructor", RID_HAS_TRIVIAL_CONSTRUCTOR
, D_CXXONLY
},
445 { "__has_trivial_copy", RID_HAS_TRIVIAL_COPY
, D_CXXONLY
},
446 { "__has_trivial_destructor", RID_HAS_TRIVIAL_DESTRUCTOR
, D_CXXONLY
},
447 { "__has_virtual_destructor", RID_HAS_VIRTUAL_DESTRUCTOR
, D_CXXONLY
},
448 { "__imag", RID_IMAGPART
, 0 },
449 { "__imag__", RID_IMAGPART
, 0 },
450 { "__inline", RID_INLINE
, 0 },
451 { "__inline__", RID_INLINE
, 0 },
452 { "__int128", RID_INT128
, 0 },
453 { "__is_abstract", RID_IS_ABSTRACT
, D_CXXONLY
},
454 { "__is_base_of", RID_IS_BASE_OF
, D_CXXONLY
},
455 { "__is_class", RID_IS_CLASS
, D_CXXONLY
},
456 { "__is_convertible_to", RID_IS_CONVERTIBLE_TO
, D_CXXONLY
},
457 { "__is_empty", RID_IS_EMPTY
, D_CXXONLY
},
458 { "__is_enum", RID_IS_ENUM
, D_CXXONLY
},
459 { "__is_final", RID_IS_FINAL
, D_CXXONLY
},
460 { "__is_literal_type", RID_IS_LITERAL_TYPE
, D_CXXONLY
},
461 { "__is_pod", RID_IS_POD
, D_CXXONLY
},
462 { "__is_polymorphic", RID_IS_POLYMORPHIC
, D_CXXONLY
},
463 { "__is_standard_layout", RID_IS_STD_LAYOUT
, D_CXXONLY
},
464 { "__is_trivial", RID_IS_TRIVIAL
, D_CXXONLY
},
465 { "__is_union", RID_IS_UNION
, D_CXXONLY
},
466 { "__label__", RID_LABEL
, 0 },
467 { "__null", RID_NULL
, 0 },
468 { "__real", RID_REALPART
, 0 },
469 { "__real__", RID_REALPART
, 0 },
470 { "__restrict", RID_RESTRICT
, 0 },
471 { "__restrict__", RID_RESTRICT
, 0 },
472 { "__signed", RID_SIGNED
, 0 },
473 { "__signed__", RID_SIGNED
, 0 },
474 { "__thread", RID_THREAD
, 0 },
475 { "__transaction_atomic", RID_TRANSACTION_ATOMIC
, 0 },
476 { "__transaction_relaxed", RID_TRANSACTION_RELAXED
, 0 },
477 { "__transaction_cancel", RID_TRANSACTION_CANCEL
, 0 },
478 { "__typeof", RID_TYPEOF
, 0 },
479 { "__typeof__", RID_TYPEOF
, 0 },
480 { "__underlying_type", RID_UNDERLYING_TYPE
, D_CXXONLY
},
481 { "__volatile", RID_VOLATILE
, 0 },
482 { "__volatile__", RID_VOLATILE
, 0 },
483 { "alignas", RID_ALIGNAS
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
484 { "alignof", RID_ALIGNOF
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
485 { "asm", RID_ASM
, D_ASM
},
486 { "auto", RID_AUTO
, 0 },
487 { "bool", RID_BOOL
, D_CXXONLY
| D_CXXWARN
},
488 { "break", RID_BREAK
, 0 },
489 { "case", RID_CASE
, 0 },
490 { "catch", RID_CATCH
, D_CXX_OBJC
| D_CXXWARN
},
491 { "char", RID_CHAR
, 0 },
492 { "char16_t", RID_CHAR16
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
493 { "char32_t", RID_CHAR32
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
494 { "class", RID_CLASS
, D_CXX_OBJC
| D_CXXWARN
},
495 { "const", RID_CONST
, 0 },
496 { "constexpr", RID_CONSTEXPR
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
497 { "const_cast", RID_CONSTCAST
, D_CXXONLY
| D_CXXWARN
},
498 { "continue", RID_CONTINUE
, 0 },
499 { "decltype", RID_DECLTYPE
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
500 { "default", RID_DEFAULT
, 0 },
501 { "delete", RID_DELETE
, D_CXXONLY
| D_CXXWARN
},
503 { "double", RID_DOUBLE
, 0 },
504 { "dynamic_cast", RID_DYNCAST
, D_CXXONLY
| D_CXXWARN
},
505 { "else", RID_ELSE
, 0 },
506 { "enum", RID_ENUM
, 0 },
507 { "explicit", RID_EXPLICIT
, D_CXXONLY
| D_CXXWARN
},
508 { "export", RID_EXPORT
, D_CXXONLY
| D_CXXWARN
},
509 { "extern", RID_EXTERN
, 0 },
510 { "false", RID_FALSE
, D_CXXONLY
| D_CXXWARN
},
511 { "float", RID_FLOAT
, 0 },
512 { "for", RID_FOR
, 0 },
513 { "friend", RID_FRIEND
, D_CXXONLY
| D_CXXWARN
},
514 { "goto", RID_GOTO
, 0 },
516 { "inline", RID_INLINE
, D_EXT89
},
517 { "int", RID_INT
, 0 },
518 { "long", RID_LONG
, 0 },
519 { "mutable", RID_MUTABLE
, D_CXXONLY
| D_CXXWARN
},
520 { "namespace", RID_NAMESPACE
, D_CXXONLY
| D_CXXWARN
},
521 { "new", RID_NEW
, D_CXXONLY
| D_CXXWARN
},
522 { "noexcept", RID_NOEXCEPT
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
523 { "nullptr", RID_NULLPTR
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
524 { "operator", RID_OPERATOR
, D_CXXONLY
| D_CXXWARN
},
525 { "private", RID_PRIVATE
, D_CXX_OBJC
| D_CXXWARN
},
526 { "protected", RID_PROTECTED
, D_CXX_OBJC
| D_CXXWARN
},
527 { "public", RID_PUBLIC
, D_CXX_OBJC
| D_CXXWARN
},
528 { "register", RID_REGISTER
, 0 },
529 { "reinterpret_cast", RID_REINTCAST
, D_CXXONLY
| D_CXXWARN
},
530 { "restrict", RID_RESTRICT
, D_CONLY
| D_C99
},
531 { "return", RID_RETURN
, 0 },
532 { "short", RID_SHORT
, 0 },
533 { "signed", RID_SIGNED
, 0 },
534 { "sizeof", RID_SIZEOF
, 0 },
535 { "static", RID_STATIC
, 0 },
536 { "static_assert", RID_STATIC_ASSERT
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
537 { "static_cast", RID_STATCAST
, D_CXXONLY
| D_CXXWARN
},
538 { "struct", RID_STRUCT
, 0 },
539 { "switch", RID_SWITCH
, 0 },
540 { "template", RID_TEMPLATE
, D_CXXONLY
| D_CXXWARN
},
541 { "this", RID_THIS
, D_CXXONLY
| D_CXXWARN
},
542 { "thread_local", RID_THREAD
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
543 { "throw", RID_THROW
, D_CXX_OBJC
| D_CXXWARN
},
544 { "true", RID_TRUE
, D_CXXONLY
| D_CXXWARN
},
545 { "try", RID_TRY
, D_CXX_OBJC
| D_CXXWARN
},
546 { "typedef", RID_TYPEDEF
, 0 },
547 { "typename", RID_TYPENAME
, D_CXXONLY
| D_CXXWARN
},
548 { "typeid", RID_TYPEID
, D_CXXONLY
| D_CXXWARN
},
549 { "typeof", RID_TYPEOF
, D_ASM
| D_EXT
},
550 { "union", RID_UNION
, 0 },
551 { "unsigned", RID_UNSIGNED
, 0 },
552 { "using", RID_USING
, D_CXXONLY
| D_CXXWARN
},
553 { "virtual", RID_VIRTUAL
, D_CXXONLY
| D_CXXWARN
},
554 { "void", RID_VOID
, 0 },
555 { "volatile", RID_VOLATILE
, 0 },
556 { "wchar_t", RID_WCHAR
, D_CXXONLY
},
557 { "while", RID_WHILE
, 0 },
558 /* These Objective-C keywords are recognized only immediately after
560 { "compatibility_alias", RID_AT_ALIAS
, D_OBJC
},
561 { "defs", RID_AT_DEFS
, D_OBJC
},
562 { "encode", RID_AT_ENCODE
, D_OBJC
},
563 { "end", RID_AT_END
, D_OBJC
},
564 { "implementation", RID_AT_IMPLEMENTATION
, D_OBJC
},
565 { "interface", RID_AT_INTERFACE
, D_OBJC
},
566 { "protocol", RID_AT_PROTOCOL
, D_OBJC
},
567 { "selector", RID_AT_SELECTOR
, D_OBJC
},
568 { "finally", RID_AT_FINALLY
, D_OBJC
},
569 { "synchronized", RID_AT_SYNCHRONIZED
, D_OBJC
},
570 { "optional", RID_AT_OPTIONAL
, D_OBJC
},
571 { "required", RID_AT_REQUIRED
, D_OBJC
},
572 { "property", RID_AT_PROPERTY
, D_OBJC
},
573 { "package", RID_AT_PACKAGE
, D_OBJC
},
574 { "synthesize", RID_AT_SYNTHESIZE
, D_OBJC
},
575 { "dynamic", RID_AT_DYNAMIC
, D_OBJC
},
576 /* These are recognized only in protocol-qualifier context
578 { "bycopy", RID_BYCOPY
, D_OBJC
},
579 { "byref", RID_BYREF
, D_OBJC
},
580 { "in", RID_IN
, D_OBJC
},
581 { "inout", RID_INOUT
, D_OBJC
},
582 { "oneway", RID_ONEWAY
, D_OBJC
},
583 { "out", RID_OUT
, D_OBJC
},
584 /* These are recognized inside a property attribute list */
585 { "assign", RID_ASSIGN
, D_OBJC
},
586 { "copy", RID_COPY
, D_OBJC
},
587 { "getter", RID_GETTER
, D_OBJC
},
588 { "nonatomic", RID_NONATOMIC
, D_OBJC
},
589 { "readonly", RID_READONLY
, D_OBJC
},
590 { "readwrite", RID_READWRITE
, D_OBJC
},
591 { "retain", RID_RETAIN
, D_OBJC
},
592 { "setter", RID_SETTER
, D_OBJC
},
595 const unsigned int num_c_common_reswords
=
596 sizeof c_common_reswords
/ sizeof (struct c_common_resword
);
598 /* Table of machine-independent attributes common to all C-like languages. */
599 const struct attribute_spec c_common_attribute_table
[] =
601 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
602 affects_type_identity } */
603 { "packed", 0, 0, false, false, false,
604 handle_packed_attribute
, false},
605 { "nocommon", 0, 0, true, false, false,
606 handle_nocommon_attribute
, false},
607 { "common", 0, 0, true, false, false,
608 handle_common_attribute
, false },
609 /* FIXME: logically, noreturn attributes should be listed as
610 "false, true, true" and apply to function types. But implementing this
611 would require all the places in the compiler that use TREE_THIS_VOLATILE
612 on a decl to identify non-returning functions to be located and fixed
613 to check the function type instead. */
614 { "noreturn", 0, 0, true, false, false,
615 handle_noreturn_attribute
, false },
616 { "volatile", 0, 0, true, false, false,
617 handle_noreturn_attribute
, false },
618 { "noinline", 0, 0, true, false, false,
619 handle_noinline_attribute
, false },
620 { "noclone", 0, 0, true, false, false,
621 handle_noclone_attribute
, false },
622 { "leaf", 0, 0, true, false, false,
623 handle_leaf_attribute
, false },
624 { "always_inline", 0, 0, true, false, false,
625 handle_always_inline_attribute
, false },
626 { "gnu_inline", 0, 0, true, false, false,
627 handle_gnu_inline_attribute
, false },
628 { "artificial", 0, 0, true, false, false,
629 handle_artificial_attribute
, false },
630 { "flatten", 0, 0, true, false, false,
631 handle_flatten_attribute
, false },
632 { "used", 0, 0, true, false, false,
633 handle_used_attribute
, false },
634 { "unused", 0, 0, false, false, false,
635 handle_unused_attribute
, false },
636 { "externally_visible", 0, 0, true, false, false,
637 handle_externally_visible_attribute
, false },
638 /* The same comments as for noreturn attributes apply to const ones. */
639 { "const", 0, 0, true, false, false,
640 handle_const_attribute
, false },
641 { "transparent_union", 0, 0, false, false, false,
642 handle_transparent_union_attribute
, false },
643 { "constructor", 0, 1, true, false, false,
644 handle_constructor_attribute
, false },
645 { "destructor", 0, 1, true, false, false,
646 handle_destructor_attribute
, false },
647 { "mode", 1, 1, false, true, false,
648 handle_mode_attribute
, false },
649 { "section", 1, 1, true, false, false,
650 handle_section_attribute
, false },
651 { "aligned", 0, 1, false, false, false,
652 handle_aligned_attribute
, false },
653 { "weak", 0, 0, true, false, false,
654 handle_weak_attribute
, false },
655 { "ifunc", 1, 1, true, false, false,
656 handle_ifunc_attribute
, false },
657 { "alias", 1, 1, true, false, false,
658 handle_alias_attribute
, false },
659 { "weakref", 0, 1, true, false, false,
660 handle_weakref_attribute
, false },
661 { "no_instrument_function", 0, 0, true, false, false,
662 handle_no_instrument_function_attribute
,
664 { "malloc", 0, 0, true, false, false,
665 handle_malloc_attribute
, false },
666 { "returns_twice", 0, 0, true, false, false,
667 handle_returns_twice_attribute
, false },
668 { "no_stack_limit", 0, 0, true, false, false,
669 handle_no_limit_stack_attribute
, false },
670 { "pure", 0, 0, true, false, false,
671 handle_pure_attribute
, false },
672 { "transaction_callable", 0, 0, false, true, false,
673 handle_tm_attribute
, false },
674 { "transaction_unsafe", 0, 0, false, true, false,
675 handle_tm_attribute
, false },
676 { "transaction_safe", 0, 0, false, true, false,
677 handle_tm_attribute
, false },
678 { "transaction_may_cancel_outer", 0, 0, false, true, false,
679 handle_tm_attribute
, false },
680 /* ??? These two attributes didn't make the transition from the
681 Intel language document to the multi-vendor language document. */
682 { "transaction_pure", 0, 0, false, true, false,
683 handle_tm_attribute
, false },
684 { "transaction_wrap", 1, 1, true, false, false,
685 handle_tm_wrap_attribute
, false },
686 /* For internal use (marking of builtins) only. The name contains space
687 to prevent its usage in source code. */
688 { "no vops", 0, 0, true, false, false,
689 handle_novops_attribute
, false },
690 { "deprecated", 0, 1, false, false, false,
691 handle_deprecated_attribute
, false },
692 { "vector_size", 1, 1, false, true, false,
693 handle_vector_size_attribute
, false },
694 { "visibility", 1, 1, false, false, false,
695 handle_visibility_attribute
, false },
696 { "tls_model", 1, 1, true, false, false,
697 handle_tls_model_attribute
, false },
698 { "nonnull", 0, -1, false, true, true,
699 handle_nonnull_attribute
, false },
700 { "nothrow", 0, 0, true, false, false,
701 handle_nothrow_attribute
, false },
702 { "may_alias", 0, 0, false, true, false, NULL
, false },
703 { "cleanup", 1, 1, true, false, false,
704 handle_cleanup_attribute
, false },
705 { "warn_unused_result", 0, 0, false, true, true,
706 handle_warn_unused_result_attribute
, false },
707 { "sentinel", 0, 1, false, true, true,
708 handle_sentinel_attribute
, false },
709 /* For internal use (marking of builtins) only. The name contains space
710 to prevent its usage in source code. */
711 { "type generic", 0, 0, false, true, true,
712 handle_type_generic_attribute
, false },
713 { "alloc_size", 1, 2, false, true, true,
714 handle_alloc_size_attribute
, false },
715 { "cold", 0, 0, true, false, false,
716 handle_cold_attribute
, false },
717 { "hot", 0, 0, true, false, false,
718 handle_hot_attribute
, false },
719 { "no_address_safety_analysis",
720 0, 0, true, false, false,
721 handle_no_address_safety_analysis_attribute
,
723 { "no_sanitize_address", 0, 0, true, false, false,
724 handle_no_sanitize_address_attribute
,
726 { "warning", 1, 1, true, false, false,
727 handle_error_attribute
, false },
728 { "error", 1, 1, true, false, false,
729 handle_error_attribute
, false },
730 { "target", 1, -1, true, false, false,
731 handle_target_attribute
, false },
732 { "optimize", 1, -1, true, false, false,
733 handle_optimize_attribute
, false },
734 /* For internal use only. The leading '*' both prevents its usage in
735 source code and signals that it may be overridden by machine tables. */
736 { "*tm regparm", 0, 0, false, true, true,
737 ignore_attribute
, false },
738 { "no_split_stack", 0, 0, true, false, false,
739 handle_no_split_stack_attribute
, false },
740 /* For internal use (marking of builtins and runtime functions) only.
741 The name contains space to prevent its usage in source code. */
742 { "fn spec", 1, 1, false, true, true,
743 handle_fnspec_attribute
, false },
744 { "warn_unused", 0, 0, false, false, false,
745 handle_warn_unused_attribute
, false },
746 { NULL
, 0, 0, false, false, false, NULL
, false }
749 /* Give the specifications for the format attributes, used by C and all
752 const struct attribute_spec c_common_format_attribute_table
[] =
754 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
755 affects_type_identity } */
756 { "format", 3, 3, false, true, true,
757 handle_format_attribute
, false },
758 { "format_arg", 1, 1, false, true, true,
759 handle_format_arg_attribute
, false },
760 { NULL
, 0, 0, false, false, false, NULL
, false }
763 /* Return identifier for address space AS. */
766 c_addr_space_name (addr_space_t as
)
768 int rid
= RID_FIRST_ADDR_SPACE
+ as
;
769 gcc_assert (ridpointers
[rid
]);
770 return IDENTIFIER_POINTER (ridpointers
[rid
]);
773 /* Push current bindings for the function name VAR_DECLS. */
776 start_fname_decls (void)
779 tree saved
= NULL_TREE
;
781 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
783 tree decl
= *fname_vars
[ix
].decl
;
787 saved
= tree_cons (decl
, build_int_cst (integer_type_node
, ix
),
789 *fname_vars
[ix
].decl
= NULL_TREE
;
792 if (saved
|| saved_function_name_decls
)
793 /* Normally they'll have been NULL, so only push if we've got a
794 stack, or they are non-NULL. */
795 saved_function_name_decls
= tree_cons (saved
, NULL_TREE
,
796 saved_function_name_decls
);
799 /* Finish up the current bindings, adding them into the current function's
800 statement tree. This must be done _before_ finish_stmt_tree is called.
801 If there is no current function, we must be at file scope and no statements
802 are involved. Pop the previous bindings. */
805 finish_fname_decls (void)
808 tree stmts
= NULL_TREE
;
809 tree stack
= saved_function_name_decls
;
811 for (; stack
&& TREE_VALUE (stack
); stack
= TREE_CHAIN (stack
))
812 append_to_statement_list (TREE_VALUE (stack
), &stmts
);
816 tree
*bodyp
= &DECL_SAVED_TREE (current_function_decl
);
818 if (TREE_CODE (*bodyp
) == BIND_EXPR
)
819 bodyp
= &BIND_EXPR_BODY (*bodyp
);
821 append_to_statement_list_force (*bodyp
, &stmts
);
825 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
826 *fname_vars
[ix
].decl
= NULL_TREE
;
830 /* We had saved values, restore them. */
833 for (saved
= TREE_PURPOSE (stack
); saved
; saved
= TREE_CHAIN (saved
))
835 tree decl
= TREE_PURPOSE (saved
);
836 unsigned ix
= tree_to_hwi (TREE_VALUE (saved
));
838 *fname_vars
[ix
].decl
= decl
;
840 stack
= TREE_CHAIN (stack
);
842 saved_function_name_decls
= stack
;
845 /* Return the text name of the current function, suitably prettified
846 by PRETTY_P. Return string must be freed by caller. */
849 fname_as_string (int pretty_p
)
851 const char *name
= "top level";
854 cpp_string cstr
= { 0, 0 }, strname
;
862 if (current_function_decl
)
863 name
= lang_hooks
.decl_printable_name (current_function_decl
, vrb
);
865 len
= strlen (name
) + 3; /* Two for '"'s. One for NULL. */
867 namep
= XNEWVEC (char, len
);
868 snprintf (namep
, len
, "\"%s\"", name
);
869 strname
.text
= (unsigned char *) namep
;
870 strname
.len
= len
- 1;
872 if (cpp_interpret_string (parse_in
, &strname
, 1, &cstr
, CPP_STRING
))
875 return (const char *) cstr
.text
;
881 /* Return the VAR_DECL for a const char array naming the current
882 function. If the VAR_DECL has not yet been created, create it
883 now. RID indicates how it should be formatted and IDENTIFIER_NODE
884 ID is its name (unfortunately C and C++ hold the RID values of
885 keywords in different places, so we can't derive RID from ID in
886 this language independent code. LOC is the location of the
890 fname_decl (location_t loc
, unsigned int rid
, tree id
)
893 tree decl
= NULL_TREE
;
895 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
896 if (fname_vars
[ix
].rid
== rid
)
899 decl
= *fname_vars
[ix
].decl
;
902 /* If a tree is built here, it would normally have the lineno of
903 the current statement. Later this tree will be moved to the
904 beginning of the function and this line number will be wrong.
905 To avoid this problem set the lineno to 0 here; that prevents
906 it from appearing in the RTL. */
908 location_t saved_location
= input_location
;
909 input_location
= UNKNOWN_LOCATION
;
911 stmts
= push_stmt_list ();
912 decl
= (*make_fname_decl
) (loc
, id
, fname_vars
[ix
].pretty
);
913 stmts
= pop_stmt_list (stmts
);
914 if (!IS_EMPTY_STMT (stmts
))
915 saved_function_name_decls
916 = tree_cons (decl
, stmts
, saved_function_name_decls
);
917 *fname_vars
[ix
].decl
= decl
;
918 input_location
= saved_location
;
920 if (!ix
&& !current_function_decl
)
921 pedwarn (loc
, 0, "%qD is not defined outside of function scope", decl
);
926 /* Given a STRING_CST, give it a suitable array-of-chars data type. */
929 fix_string_type (tree value
)
931 int length
= TREE_STRING_LENGTH (value
);
933 tree e_type
, i_type
, a_type
;
935 /* Compute the number of elements, for the array type. */
936 if (TREE_TYPE (value
) == char_array_type_node
|| !TREE_TYPE (value
))
939 e_type
= char_type_node
;
941 else if (TREE_TYPE (value
) == char16_array_type_node
)
943 nchars
= length
/ (TYPE_PRECISION (char16_type_node
) / BITS_PER_UNIT
);
944 e_type
= char16_type_node
;
946 else if (TREE_TYPE (value
) == char32_array_type_node
)
948 nchars
= length
/ (TYPE_PRECISION (char32_type_node
) / BITS_PER_UNIT
);
949 e_type
= char32_type_node
;
953 nchars
= length
/ (TYPE_PRECISION (wchar_type_node
) / BITS_PER_UNIT
);
954 e_type
= wchar_type_node
;
957 /* C89 2.2.4.1, C99 5.2.4.1 (Translation limits). The analogous
958 limit in C++98 Annex B is very large (65536) and is not normative,
959 so we do not diagnose it (warn_overlength_strings is forced off
960 in c_common_post_options). */
961 if (warn_overlength_strings
)
963 const int nchars_max
= flag_isoc99
? 4095 : 509;
964 const int relevant_std
= flag_isoc99
? 99 : 90;
965 if (nchars
- 1 > nchars_max
)
966 /* Translators: The %d after 'ISO C' will be 90 or 99. Do not
967 separate the %d from the 'C'. 'ISO' should not be
968 translated, but it may be moved after 'C%d' in languages
969 where modifiers follow nouns. */
970 pedwarn (input_location
, OPT_Woverlength_strings
,
971 "string length %qd is greater than the length %qd "
972 "ISO C%d compilers are required to support",
973 nchars
- 1, nchars_max
, relevant_std
);
976 /* Create the array type for the string constant. The ISO C++
977 standard says that a string literal has type `const char[N]' or
978 `const wchar_t[N]'. We use the same logic when invoked as a C
979 front-end with -Wwrite-strings.
980 ??? We should change the type of an expression depending on the
981 state of a warning flag. We should just be warning -- see how
982 this is handled in the C++ front-end for the deprecated implicit
983 conversion from string literals to `char*' or `wchar_t*'.
985 The C++ front end relies on TYPE_MAIN_VARIANT of a cv-qualified
986 array type being the unqualified version of that type.
987 Therefore, if we are constructing an array of const char, we must
988 construct the matching unqualified array type first. The C front
989 end does not require this, but it does no harm, so we do it
991 i_type
= build_index_type (size_int (nchars
- 1));
992 a_type
= build_array_type (e_type
, i_type
);
993 if (c_dialect_cxx() || warn_write_strings
)
994 a_type
= c_build_qualified_type (a_type
, TYPE_QUAL_CONST
);
996 TREE_TYPE (value
) = a_type
;
997 TREE_CONSTANT (value
) = 1;
998 TREE_READONLY (value
) = 1;
999 TREE_STATIC (value
) = 1;
1003 /* If DISABLE is true, stop issuing warnings. This is used when
1004 parsing code that we know will not be executed. This function may
1005 be called multiple times, and works as a stack. */
1008 c_disable_warnings (bool disable
)
1012 ++c_inhibit_evaluation_warnings
;
1013 fold_defer_overflow_warnings ();
1017 /* If ENABLE is true, reenable issuing warnings. */
1020 c_enable_warnings (bool enable
)
1024 --c_inhibit_evaluation_warnings
;
1025 fold_undefer_and_ignore_overflow_warnings ();
1029 /* Fully fold EXPR, an expression that was not folded (beyond integer
1030 constant expressions and null pointer constants) when being built
1031 up. If IN_INIT, this is in a static initializer and certain
1032 changes are made to the folding done. Clear *MAYBE_CONST if
1033 MAYBE_CONST is not NULL and EXPR is definitely not a constant
1034 expression because it contains an evaluated operator (in C99) or an
1035 operator outside of sizeof returning an integer constant (in C90)
1036 not permitted in constant expressions, or because it contains an
1037 evaluated arithmetic overflow. (*MAYBE_CONST should typically be
1038 set to true by callers before calling this function.) Return the
1039 folded expression. Function arguments have already been folded
1040 before calling this function, as have the contents of SAVE_EXPR,
1041 TARGET_EXPR, BIND_EXPR, VA_ARG_EXPR, OBJ_TYPE_REF and
1042 C_MAYBE_CONST_EXPR. */
1045 c_fully_fold (tree expr
, bool in_init
, bool *maybe_const
)
1048 tree eptype
= NULL_TREE
;
1050 bool maybe_const_itself
= true;
1051 location_t loc
= EXPR_LOCATION (expr
);
1053 /* This function is not relevant to C++ because C++ folds while
1054 parsing, and may need changes to be correct for C++ when C++
1055 stops folding while parsing. */
1056 if (c_dialect_cxx ())
1060 maybe_const
= &dummy
;
1061 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
1063 eptype
= TREE_TYPE (expr
);
1064 expr
= TREE_OPERAND (expr
, 0);
1066 ret
= c_fully_fold_internal (expr
, in_init
, maybe_const
,
1067 &maybe_const_itself
);
1069 ret
= fold_convert_loc (loc
, eptype
, ret
);
1070 *maybe_const
&= maybe_const_itself
;
1074 /* Internal helper for c_fully_fold. EXPR and IN_INIT are as for
1075 c_fully_fold. *MAYBE_CONST_OPERANDS is cleared because of operands
1076 not permitted, while *MAYBE_CONST_ITSELF is cleared because of
1077 arithmetic overflow (for C90, *MAYBE_CONST_OPERANDS is carried from
1078 both evaluated and unevaluated subexpressions while
1079 *MAYBE_CONST_ITSELF is carried from only evaluated
1083 c_fully_fold_internal (tree expr
, bool in_init
, bool *maybe_const_operands
,
1084 bool *maybe_const_itself
)
1087 enum tree_code code
= TREE_CODE (expr
);
1088 enum tree_code_class kind
= TREE_CODE_CLASS (code
);
1089 location_t loc
= EXPR_LOCATION (expr
);
1090 tree op0
, op1
, op2
, op3
;
1091 tree orig_op0
, orig_op1
, orig_op2
;
1092 bool op0_const
= true, op1_const
= true, op2_const
= true;
1093 bool op0_const_self
= true, op1_const_self
= true, op2_const_self
= true;
1094 bool nowarning
= TREE_NO_WARNING (expr
);
1097 /* This function is not relevant to C++ because C++ folds while
1098 parsing, and may need changes to be correct for C++ when C++
1099 stops folding while parsing. */
1100 if (c_dialect_cxx ())
1103 /* Constants, declarations, statements, errors, SAVE_EXPRs and
1104 anything else not counted as an expression cannot usefully be
1105 folded further at this point. */
1106 if (!IS_EXPR_CODE_CLASS (kind
)
1107 || kind
== tcc_statement
1108 || code
== SAVE_EXPR
)
1111 /* Operands of variable-length expressions (function calls) have
1112 already been folded, as have __builtin_* function calls, and such
1113 expressions cannot occur in constant expressions. */
1114 if (kind
== tcc_vl_exp
)
1116 *maybe_const_operands
= false;
1121 if (code
== C_MAYBE_CONST_EXPR
)
1123 tree pre
= C_MAYBE_CONST_EXPR_PRE (expr
);
1124 tree inner
= C_MAYBE_CONST_EXPR_EXPR (expr
);
1125 if (C_MAYBE_CONST_EXPR_NON_CONST (expr
))
1126 *maybe_const_operands
= false;
1127 if (C_MAYBE_CONST_EXPR_INT_OPERANDS (expr
))
1128 *maybe_const_itself
= false;
1129 if (pre
&& !in_init
)
1130 ret
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr
), pre
, inner
);
1136 /* Assignment, increment, decrement, function call and comma
1137 operators, and statement expressions, cannot occur in constant
1138 expressions if evaluated / outside of sizeof. (Function calls
1139 were handled above, though VA_ARG_EXPR is treated like a function
1140 call here, and statement expressions are handled through
1141 C_MAYBE_CONST_EXPR to avoid folding inside them.) */
1145 case PREDECREMENT_EXPR
:
1146 case PREINCREMENT_EXPR
:
1147 case POSTDECREMENT_EXPR
:
1148 case POSTINCREMENT_EXPR
:
1150 *maybe_const_operands
= false;
1157 *maybe_const_operands
= false;
1165 /* Fold individual tree codes as appropriate. */
1168 case COMPOUND_LITERAL_EXPR
:
1169 /* Any non-constancy will have been marked in a containing
1170 C_MAYBE_CONST_EXPR; there is no more folding to do here. */
1174 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1175 op1
= TREE_OPERAND (expr
, 1);
1176 op2
= TREE_OPERAND (expr
, 2);
1177 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1178 maybe_const_itself
);
1179 STRIP_TYPE_NOPS (op0
);
1180 if (op0
!= orig_op0
)
1181 ret
= build3 (COMPONENT_REF
, TREE_TYPE (expr
), op0
, op1
, op2
);
1184 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1185 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1190 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1191 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1192 op2
= TREE_OPERAND (expr
, 2);
1193 op3
= TREE_OPERAND (expr
, 3);
1194 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1195 maybe_const_itself
);
1196 STRIP_TYPE_NOPS (op0
);
1197 op1
= c_fully_fold_internal (op1
, in_init
, maybe_const_operands
,
1198 maybe_const_itself
);
1199 STRIP_TYPE_NOPS (op1
);
1200 op1
= decl_constant_value_for_optimization (op1
);
1201 if (op0
!= orig_op0
|| op1
!= orig_op1
)
1202 ret
= build4 (ARRAY_REF
, TREE_TYPE (expr
), op0
, op1
, op2
, op3
);
1205 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1206 TREE_SIDE_EFFECTS (ret
) = TREE_SIDE_EFFECTS (expr
);
1207 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1214 case PREDECREMENT_EXPR
:
1215 case PREINCREMENT_EXPR
:
1216 case POSTDECREMENT_EXPR
:
1217 case POSTINCREMENT_EXPR
:
1221 case POINTER_PLUS_EXPR
:
1222 case TRUNC_DIV_EXPR
:
1224 case FLOOR_DIV_EXPR
:
1225 case TRUNC_MOD_EXPR
:
1227 case EXACT_DIV_EXPR
:
1240 case TRUTH_AND_EXPR
:
1242 case TRUTH_XOR_EXPR
:
1243 case UNORDERED_EXPR
:
1250 /* Binary operations evaluating both arguments (increment and
1251 decrement are binary internally in GCC). */
1252 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1253 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1254 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1255 maybe_const_itself
);
1256 STRIP_TYPE_NOPS (op0
);
1257 if (code
!= MODIFY_EXPR
1258 && code
!= PREDECREMENT_EXPR
1259 && code
!= PREINCREMENT_EXPR
1260 && code
!= POSTDECREMENT_EXPR
1261 && code
!= POSTINCREMENT_EXPR
)
1262 op0
= decl_constant_value_for_optimization (op0
);
1263 /* The RHS of a MODIFY_EXPR was fully folded when building that
1264 expression for the sake of conversion warnings. */
1265 if (code
!= MODIFY_EXPR
)
1266 op1
= c_fully_fold_internal (op1
, in_init
, maybe_const_operands
,
1267 maybe_const_itself
);
1268 STRIP_TYPE_NOPS (op1
);
1269 op1
= decl_constant_value_for_optimization (op1
);
1270 if (op0
!= orig_op0
|| op1
!= orig_op1
|| in_init
)
1272 ? fold_build2_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
)
1273 : fold_build2_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
);
1276 if (TREE_OVERFLOW_P (ret
)
1277 && !TREE_OVERFLOW_P (op0
)
1278 && !TREE_OVERFLOW_P (op1
))
1279 overflow_warning (EXPR_LOCATION (expr
), ret
);
1280 if ((code
== LSHIFT_EXPR
|| code
== RSHIFT_EXPR
)
1281 && TREE_CODE (orig_op1
) != INTEGER_CST
1282 && TREE_CODE (op1
) == INTEGER_CST
1283 && (TREE_CODE (TREE_TYPE (orig_op0
)) == INTEGER_TYPE
1284 || TREE_CODE (TREE_TYPE (orig_op0
)) == FIXED_POINT_TYPE
)
1285 && TREE_CODE (TREE_TYPE (orig_op1
)) == INTEGER_TYPE
1286 && c_inhibit_evaluation_warnings
== 0)
1288 if (tree_int_cst_sgn (op1
) < 0)
1289 warning_at (loc
, 0, (code
== LSHIFT_EXPR
1290 ? G_("left shift count is negative")
1291 : G_("right shift count is negative")));
1292 else if (compare_tree_int (op1
,
1293 TYPE_PRECISION (TREE_TYPE (orig_op0
)))
1295 warning_at (loc
, 0, (code
== LSHIFT_EXPR
1296 ? G_("left shift count >= width of type")
1297 : G_("right shift count >= width of type")));
1302 case FIX_TRUNC_EXPR
:
1305 case VIEW_CONVERT_EXPR
:
1306 case NON_LVALUE_EXPR
:
1309 case TRUTH_NOT_EXPR
:
1314 /* Unary operations. */
1315 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1316 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1317 maybe_const_itself
);
1318 STRIP_TYPE_NOPS (op0
);
1319 if (code
!= ADDR_EXPR
&& code
!= REALPART_EXPR
&& code
!= IMAGPART_EXPR
)
1320 op0
= decl_constant_value_for_optimization (op0
);
1321 /* ??? Cope with user tricks that amount to offsetof. The middle-end is
1322 not prepared to deal with them if they occur in initializers. */
1324 && code
== ADDR_EXPR
1325 && (op1
= get_base_address (op0
)) != NULL_TREE
1326 && TREE_CODE (op1
) == INDIRECT_REF
1327 && TREE_CONSTANT (TREE_OPERAND (op1
, 0)))
1328 ret
= fold_convert_loc (loc
, TREE_TYPE (expr
), fold_offsetof_1 (op0
));
1329 else if (op0
!= orig_op0
|| in_init
)
1331 ? fold_build1_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
)
1332 : fold_build1_loc (loc
, code
, TREE_TYPE (expr
), op0
);
1335 if (code
== INDIRECT_REF
1337 && TREE_CODE (ret
) == INDIRECT_REF
)
1339 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1340 TREE_SIDE_EFFECTS (ret
) = TREE_SIDE_EFFECTS (expr
);
1341 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1345 case FIX_TRUNC_EXPR
:
1348 /* Don't warn about explicit conversions. We will already
1349 have warned about suspect implicit conversions. */
1353 if (TREE_OVERFLOW_P (ret
) && !TREE_OVERFLOW_P (op0
))
1354 overflow_warning (EXPR_LOCATION (expr
), ret
);
1359 case TRUTH_ANDIF_EXPR
:
1360 case TRUTH_ORIF_EXPR
:
1361 /* Binary operations not necessarily evaluating both
1363 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1364 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1365 op0
= c_fully_fold_internal (op0
, in_init
, &op0_const
, &op0_const_self
);
1366 STRIP_TYPE_NOPS (op0
);
1368 unused_p
= (op0
== (code
== TRUTH_ANDIF_EXPR
1369 ? truthvalue_false_node
1370 : truthvalue_true_node
));
1371 c_disable_warnings (unused_p
);
1372 op1
= c_fully_fold_internal (op1
, in_init
, &op1_const
, &op1_const_self
);
1373 STRIP_TYPE_NOPS (op1
);
1374 c_enable_warnings (unused_p
);
1376 if (op0
!= orig_op0
|| op1
!= orig_op1
|| in_init
)
1378 ? fold_build2_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
)
1379 : fold_build2_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
);
1382 *maybe_const_operands
&= op0_const
;
1383 *maybe_const_itself
&= op0_const_self
;
1387 && (code
== TRUTH_ANDIF_EXPR
1388 ? op0
== truthvalue_false_node
1389 : op0
== truthvalue_true_node
)))
1390 *maybe_const_operands
&= op1_const
;
1393 && (code
== TRUTH_ANDIF_EXPR
1394 ? op0
== truthvalue_false_node
1395 : op0
== truthvalue_true_node
)))
1396 *maybe_const_itself
&= op1_const_self
;
1400 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1401 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1402 orig_op2
= op2
= TREE_OPERAND (expr
, 2);
1403 op0
= c_fully_fold_internal (op0
, in_init
, &op0_const
, &op0_const_self
);
1405 STRIP_TYPE_NOPS (op0
);
1406 c_disable_warnings (op0
== truthvalue_false_node
);
1407 op1
= c_fully_fold_internal (op1
, in_init
, &op1_const
, &op1_const_self
);
1408 STRIP_TYPE_NOPS (op1
);
1409 c_enable_warnings (op0
== truthvalue_false_node
);
1411 c_disable_warnings (op0
== truthvalue_true_node
);
1412 op2
= c_fully_fold_internal (op2
, in_init
, &op2_const
, &op2_const_self
);
1413 STRIP_TYPE_NOPS (op2
);
1414 c_enable_warnings (op0
== truthvalue_true_node
);
1416 if (op0
!= orig_op0
|| op1
!= orig_op1
|| op2
!= orig_op2
)
1417 ret
= fold_build3_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
, op2
);
1420 *maybe_const_operands
&= op0_const
;
1421 *maybe_const_itself
&= op0_const_self
;
1425 && op0
== truthvalue_false_node
))
1426 *maybe_const_operands
&= op1_const
;
1429 && op0
== truthvalue_false_node
))
1430 *maybe_const_itself
&= op1_const_self
;
1434 && op0
== truthvalue_true_node
))
1435 *maybe_const_operands
&= op2_const
;
1438 && op0
== truthvalue_true_node
))
1439 *maybe_const_itself
&= op2_const_self
;
1442 case EXCESS_PRECISION_EXPR
:
1443 /* Each case where an operand with excess precision may be
1444 encountered must remove the EXCESS_PRECISION_EXPR around
1445 inner operands and possibly put one around the whole
1446 expression or possibly convert to the semantic type (which
1447 c_fully_fold does); we cannot tell at this stage which is
1448 appropriate in any particular case. */
1452 /* Various codes may appear through folding built-in functions
1453 and their arguments. */
1458 /* Some folding may introduce NON_LVALUE_EXPRs; all lvalue checks
1459 have been done by this point, so remove them again. */
1460 nowarning
|= TREE_NO_WARNING (ret
);
1461 STRIP_TYPE_NOPS (ret
);
1462 if (nowarning
&& !TREE_NO_WARNING (ret
))
1464 if (!CAN_HAVE_LOCATION_P (ret
))
1465 ret
= build1 (NOP_EXPR
, TREE_TYPE (ret
), ret
);
1466 TREE_NO_WARNING (ret
) = 1;
1469 protected_set_expr_location (ret
, loc
);
1473 /* If not optimizing, EXP is not a VAR_DECL, or EXP has array type,
1474 return EXP. Otherwise, return either EXP or its known constant
1475 value (if it has one), but return EXP if EXP has mode BLKmode. ???
1476 Is the BLKmode test appropriate? */
1479 decl_constant_value_for_optimization (tree exp
)
1483 /* This function is only used by C, for c_fully_fold and other
1484 optimization, and may not be correct for C++. */
1485 if (c_dialect_cxx ())
1489 || TREE_CODE (exp
) != VAR_DECL
1490 || TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
1491 || DECL_MODE (exp
) == BLKmode
)
1494 ret
= decl_constant_value (exp
);
1495 /* Avoid unwanted tree sharing between the initializer and current
1496 function's body where the tree can be modified e.g. by the
1498 if (ret
!= exp
&& TREE_STATIC (exp
))
1499 ret
= unshare_expr (ret
);
1503 /* Print a warning if a constant expression had overflow in folding.
1504 Invoke this function on every expression that the language
1505 requires to be a constant expression.
1506 Note the ANSI C standard says it is erroneous for a
1507 constant expression to overflow. */
1510 constant_expression_warning (tree value
)
1512 if (warn_overflow
&& pedantic
1513 && (TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1514 || TREE_CODE (value
) == FIXED_CST
1515 || TREE_CODE (value
) == VECTOR_CST
1516 || TREE_CODE (value
) == COMPLEX_CST
)
1517 && TREE_OVERFLOW (value
))
1518 pedwarn (input_location
, OPT_Woverflow
, "overflow in constant expression");
1521 /* The same as above but print an unconditional error. */
1523 constant_expression_error (tree value
)
1525 if ((TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1526 || TREE_CODE (value
) == FIXED_CST
1527 || TREE_CODE (value
) == VECTOR_CST
1528 || TREE_CODE (value
) == COMPLEX_CST
)
1529 && TREE_OVERFLOW (value
))
1530 error ("overflow in constant expression");
1533 /* Print a warning if an expression had overflow in folding and its
1536 Invoke this function on every expression that
1537 (1) appears in the source code, and
1538 (2) is a constant expression that overflowed, and
1539 (3) is not already checked by convert_and_check;
1540 however, do not invoke this function on operands of explicit casts
1541 or when the expression is the result of an operator and any operand
1542 already overflowed. */
1545 overflow_warning (location_t loc
, tree value
)
1547 if (c_inhibit_evaluation_warnings
!= 0)
1550 switch (TREE_CODE (value
))
1553 warning_at (loc
, OPT_Woverflow
, "integer overflow in expression");
1557 warning_at (loc
, OPT_Woverflow
,
1558 "floating point overflow in expression");
1562 warning_at (loc
, OPT_Woverflow
, "fixed-point overflow in expression");
1566 warning_at (loc
, OPT_Woverflow
, "vector overflow in expression");
1570 if (TREE_CODE (TREE_REALPART (value
)) == INTEGER_CST
)
1571 warning_at (loc
, OPT_Woverflow
,
1572 "complex integer overflow in expression");
1573 else if (TREE_CODE (TREE_REALPART (value
)) == REAL_CST
)
1574 warning_at (loc
, OPT_Woverflow
,
1575 "complex floating point overflow in expression");
1583 /* Warn about uses of logical || / && operator in a context where it
1584 is likely that the bitwise equivalent was intended by the
1585 programmer. We have seen an expression in which CODE is a binary
1586 operator used to combine expressions OP_LEFT and OP_RIGHT, which before folding
1587 had CODE_LEFT and CODE_RIGHT, into an expression of type TYPE. */
1589 warn_logical_operator (location_t location
, enum tree_code code
, tree type
,
1590 enum tree_code code_left
, tree op_left
,
1591 enum tree_code
ARG_UNUSED (code_right
), tree op_right
)
1593 int or_op
= (code
== TRUTH_ORIF_EXPR
|| code
== TRUTH_OR_EXPR
);
1594 int in0_p
, in1_p
, in_p
;
1595 tree low0
, low1
, low
, high0
, high1
, high
, lhs
, rhs
, tem
;
1596 bool strict_overflow_p
= false;
1598 if (code
!= TRUTH_ANDIF_EXPR
1599 && code
!= TRUTH_AND_EXPR
1600 && code
!= TRUTH_ORIF_EXPR
1601 && code
!= TRUTH_OR_EXPR
)
1604 /* Warn if &&/|| are being used in a context where it is
1605 likely that the bitwise equivalent was intended by the
1606 programmer. That is, an expression such as op && MASK
1607 where op should not be any boolean expression, nor a
1608 constant, and mask seems to be a non-boolean integer constant. */
1609 if (!truth_value_p (code_left
)
1610 && INTEGRAL_TYPE_P (TREE_TYPE (op_left
))
1611 && !CONSTANT_CLASS_P (op_left
)
1612 && !TREE_NO_WARNING (op_left
)
1613 && TREE_CODE (op_right
) == INTEGER_CST
1614 && !integer_zerop (op_right
)
1615 && !integer_onep (op_right
))
1618 warning_at (location
, OPT_Wlogical_op
, "logical %<or%>"
1619 " applied to non-boolean constant");
1621 warning_at (location
, OPT_Wlogical_op
, "logical %<and%>"
1622 " applied to non-boolean constant");
1623 TREE_NO_WARNING (op_left
) = true;
1627 /* We do not warn for constants because they are typical of macro
1628 expansions that test for features. */
1629 if (CONSTANT_CLASS_P (op_left
) || CONSTANT_CLASS_P (op_right
))
1632 /* This warning only makes sense with logical operands. */
1633 if (!(truth_value_p (TREE_CODE (op_left
))
1634 || INTEGRAL_TYPE_P (TREE_TYPE (op_left
)))
1635 || !(truth_value_p (TREE_CODE (op_right
))
1636 || INTEGRAL_TYPE_P (TREE_TYPE (op_right
))))
1640 /* We first test whether either side separately is trivially true
1641 (with OR) or trivially false (with AND). If so, do not warn.
1642 This is a common idiom for testing ranges of data types in
1644 lhs
= make_range (op_left
, &in0_p
, &low0
, &high0
, &strict_overflow_p
);
1647 if (TREE_CODE (lhs
) == C_MAYBE_CONST_EXPR
)
1648 lhs
= C_MAYBE_CONST_EXPR_EXPR (lhs
);
1650 /* If this is an OR operation, invert both sides; now, the result
1651 should be always false to get a warning. */
1655 tem
= build_range_check (UNKNOWN_LOCATION
, type
, lhs
, in0_p
, low0
, high0
);
1656 if (tem
&& integer_zerop (tem
))
1659 rhs
= make_range (op_right
, &in1_p
, &low1
, &high1
, &strict_overflow_p
);
1662 if (TREE_CODE (rhs
) == C_MAYBE_CONST_EXPR
)
1663 rhs
= C_MAYBE_CONST_EXPR_EXPR (rhs
);
1665 /* If this is an OR operation, invert both sides; now, the result
1666 should be always false to get a warning. */
1670 tem
= build_range_check (UNKNOWN_LOCATION
, type
, rhs
, in1_p
, low1
, high1
);
1671 if (tem
&& integer_zerop (tem
))
1674 /* If both expressions have the same operand, if we can merge the
1675 ranges, and if the range test is always false, then warn. */
1676 if (operand_equal_p (lhs
, rhs
, 0)
1677 && merge_ranges (&in_p
, &low
, &high
, in0_p
, low0
, high0
,
1679 && 0 != (tem
= build_range_check (UNKNOWN_LOCATION
,
1680 type
, lhs
, in_p
, low
, high
))
1681 && integer_zerop (tem
))
1684 warning_at (location
, OPT_Wlogical_op
,
1686 "of collectively exhaustive tests is always true");
1688 warning_at (location
, OPT_Wlogical_op
,
1690 "of mutually exclusive tests is always false");
1695 /* Warn if EXP contains any computations whose results are not used.
1696 Return true if a warning is printed; false otherwise. LOCUS is the
1697 (potential) location of the expression. */
1700 warn_if_unused_value (const_tree exp
, location_t locus
)
1703 if (TREE_USED (exp
) || TREE_NO_WARNING (exp
))
1706 /* Don't warn about void constructs. This includes casting to void,
1707 void function calls, and statement expressions with a final cast
1709 if (VOID_TYPE_P (TREE_TYPE (exp
)))
1712 if (EXPR_HAS_LOCATION (exp
))
1713 locus
= EXPR_LOCATION (exp
);
1715 switch (TREE_CODE (exp
))
1717 case PREINCREMENT_EXPR
:
1718 case POSTINCREMENT_EXPR
:
1719 case PREDECREMENT_EXPR
:
1720 case POSTDECREMENT_EXPR
:
1725 case TRY_CATCH_EXPR
:
1726 case WITH_CLEANUP_EXPR
:
1732 /* For a binding, warn if no side effect within it. */
1733 exp
= BIND_EXPR_BODY (exp
);
1737 case NON_LVALUE_EXPR
:
1739 exp
= TREE_OPERAND (exp
, 0);
1742 case TRUTH_ORIF_EXPR
:
1743 case TRUTH_ANDIF_EXPR
:
1744 /* In && or ||, warn if 2nd operand has no side effect. */
1745 exp
= TREE_OPERAND (exp
, 1);
1749 if (warn_if_unused_value (TREE_OPERAND (exp
, 0), locus
))
1751 /* Let people do `(foo (), 0)' without a warning. */
1752 if (TREE_CONSTANT (TREE_OPERAND (exp
, 1)))
1754 exp
= TREE_OPERAND (exp
, 1);
1758 /* If this is an expression with side effects, don't warn; this
1759 case commonly appears in macro expansions. */
1760 if (TREE_SIDE_EFFECTS (exp
))
1765 /* Don't warn about automatic dereferencing of references, since
1766 the user cannot control it. */
1767 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == REFERENCE_TYPE
)
1769 exp
= TREE_OPERAND (exp
, 0);
1775 /* Referencing a volatile value is a side effect, so don't warn. */
1776 if ((DECL_P (exp
) || REFERENCE_CLASS_P (exp
))
1777 && TREE_THIS_VOLATILE (exp
))
1780 /* If this is an expression which has no operands, there is no value
1781 to be unused. There are no such language-independent codes,
1782 but front ends may define such. */
1783 if (EXPRESSION_CLASS_P (exp
) && TREE_OPERAND_LENGTH (exp
) == 0)
1787 return warning_at (locus
, OPT_Wunused_value
, "value computed is not used");
1792 /* Print a warning about casts that might indicate violation
1793 of strict aliasing rules if -Wstrict-aliasing is used and
1794 strict aliasing mode is in effect. OTYPE is the original
1795 TREE_TYPE of EXPR, and TYPE the type we're casting to. */
1798 strict_aliasing_warning (tree otype
, tree type
, tree expr
)
1800 /* Strip pointer conversion chains and get to the correct original type. */
1802 otype
= TREE_TYPE (expr
);
1804 if (!(flag_strict_aliasing
1805 && POINTER_TYPE_P (type
)
1806 && POINTER_TYPE_P (otype
)
1807 && !VOID_TYPE_P (TREE_TYPE (type
)))
1808 /* If the type we are casting to is a ref-all pointer
1809 dereferencing it is always valid. */
1810 || TYPE_REF_CAN_ALIAS_ALL (type
))
1813 if ((warn_strict_aliasing
> 1) && TREE_CODE (expr
) == ADDR_EXPR
1814 && (DECL_P (TREE_OPERAND (expr
, 0))
1815 || handled_component_p (TREE_OPERAND (expr
, 0))))
1817 /* Casting the address of an object to non void pointer. Warn
1818 if the cast breaks type based aliasing. */
1819 if (!COMPLETE_TYPE_P (TREE_TYPE (type
)) && warn_strict_aliasing
== 2)
1821 warning (OPT_Wstrict_aliasing
, "type-punning to incomplete type "
1822 "might break strict-aliasing rules");
1827 /* warn_strict_aliasing >= 3. This includes the default (3).
1828 Only warn if the cast is dereferenced immediately. */
1829 alias_set_type set1
=
1830 get_alias_set (TREE_TYPE (TREE_OPERAND (expr
, 0)));
1831 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
1833 if (set1
!= set2
&& set2
!= 0
1834 && (set1
== 0 || !alias_sets_conflict_p (set1
, set2
)))
1836 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1837 "pointer will break strict-aliasing rules");
1840 else if (warn_strict_aliasing
== 2
1841 && !alias_sets_must_conflict_p (set1
, set2
))
1843 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1844 "pointer might break strict-aliasing rules");
1850 if ((warn_strict_aliasing
== 1) && !VOID_TYPE_P (TREE_TYPE (otype
)))
1852 /* At this level, warn for any conversions, even if an address is
1853 not taken in the same statement. This will likely produce many
1854 false positives, but could be useful to pinpoint problems that
1855 are not revealed at higher levels. */
1856 alias_set_type set1
= get_alias_set (TREE_TYPE (otype
));
1857 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
1858 if (!COMPLETE_TYPE_P (type
)
1859 || !alias_sets_must_conflict_p (set1
, set2
))
1861 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1862 "pointer might break strict-aliasing rules");
1870 /* Warn about memset (&a, 0, sizeof (&a)); and similar mistakes with
1871 sizeof as last operand of certain builtins. */
1874 sizeof_pointer_memaccess_warning (location_t
*sizeof_arg_loc
, tree callee
,
1875 vec
<tree
, va_gc
> *params
, tree
*sizeof_arg
,
1876 bool (*comp_types
) (tree
, tree
))
1878 tree type
, dest
= NULL_TREE
, src
= NULL_TREE
, tem
;
1879 bool strop
= false, cmp
= false;
1880 unsigned int idx
= ~0;
1883 if (TREE_CODE (callee
) != FUNCTION_DECL
1884 || DECL_BUILT_IN_CLASS (callee
) != BUILT_IN_NORMAL
1885 || vec_safe_length (params
) <= 1)
1888 switch (DECL_FUNCTION_CODE (callee
))
1890 case BUILT_IN_STRNCMP
:
1891 case BUILT_IN_STRNCASECMP
:
1894 case BUILT_IN_STRNCPY
:
1895 case BUILT_IN_STRNCPY_CHK
:
1896 case BUILT_IN_STRNCAT
:
1897 case BUILT_IN_STRNCAT_CHK
:
1898 case BUILT_IN_STPNCPY
:
1899 case BUILT_IN_STPNCPY_CHK
:
1902 case BUILT_IN_MEMCPY
:
1903 case BUILT_IN_MEMCPY_CHK
:
1904 case BUILT_IN_MEMMOVE
:
1905 case BUILT_IN_MEMMOVE_CHK
:
1906 if (params
->length () < 3)
1909 dest
= (*params
)[0];
1912 case BUILT_IN_BCOPY
:
1913 if (params
->length () < 3)
1916 dest
= (*params
)[1];
1919 case BUILT_IN_MEMCMP
:
1921 if (params
->length () < 3)
1924 dest
= (*params
)[0];
1928 case BUILT_IN_MEMSET
:
1929 case BUILT_IN_MEMSET_CHK
:
1930 if (params
->length () < 3)
1932 dest
= (*params
)[0];
1935 case BUILT_IN_BZERO
:
1936 dest
= (*params
)[0];
1939 case BUILT_IN_STRNDUP
:
1944 case BUILT_IN_MEMCHR
:
1945 if (params
->length () < 3)
1950 case BUILT_IN_SNPRINTF
:
1951 case BUILT_IN_SNPRINTF_CHK
:
1952 case BUILT_IN_VSNPRINTF
:
1953 case BUILT_IN_VSNPRINTF_CHK
:
1954 dest
= (*params
)[0];
1965 if (sizeof_arg
[idx
] == NULL
|| sizeof_arg
[idx
] == error_mark_node
)
1968 type
= TYPE_P (sizeof_arg
[idx
])
1969 ? sizeof_arg
[idx
] : TREE_TYPE (sizeof_arg
[idx
]);
1970 if (!POINTER_TYPE_P (type
))
1974 && (tem
= tree_strip_nop_conversions (dest
))
1975 && POINTER_TYPE_P (TREE_TYPE (tem
))
1976 && comp_types (TREE_TYPE (TREE_TYPE (tem
)), type
))
1980 && (tem
= tree_strip_nop_conversions (src
))
1981 && POINTER_TYPE_P (TREE_TYPE (tem
))
1982 && comp_types (TREE_TYPE (TREE_TYPE (tem
)), type
))
1985 loc
= sizeof_arg_loc
[idx
];
1989 if (!TYPE_P (sizeof_arg
[idx
])
1990 && operand_equal_p (dest
, sizeof_arg
[idx
], 0)
1991 && comp_types (TREE_TYPE (dest
), type
))
1993 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
1994 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1995 "argument to %<sizeof%> in %qD call is the same "
1996 "expression as the destination; did you mean to "
1997 "remove the addressof?", callee
);
1998 else if ((TYPE_PRECISION (TREE_TYPE (type
))
1999 == TYPE_PRECISION (char_type_node
))
2001 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2002 "argument to %<sizeof%> in %qD call is the same "
2003 "expression as the destination; did you mean to "
2004 "provide an explicit length?", callee
);
2006 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2007 "argument to %<sizeof%> in %qD call is the same "
2008 "expression as the destination; did you mean to "
2009 "dereference it?", callee
);
2013 if (POINTER_TYPE_P (TREE_TYPE (dest
))
2015 && comp_types (TREE_TYPE (dest
), type
)
2016 && !VOID_TYPE_P (TREE_TYPE (type
)))
2018 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2019 "argument to %<sizeof%> in %qD call is the same "
2020 "pointer type %qT as the destination; expected %qT "
2021 "or an explicit length", callee
, TREE_TYPE (dest
),
2022 TREE_TYPE (TREE_TYPE (dest
)));
2029 if (!TYPE_P (sizeof_arg
[idx
])
2030 && operand_equal_p (src
, sizeof_arg
[idx
], 0)
2031 && comp_types (TREE_TYPE (src
), type
))
2033 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2034 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2035 "argument to %<sizeof%> in %qD call is the same "
2036 "expression as the source; did you mean to "
2037 "remove the addressof?", callee
);
2038 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2039 == TYPE_PRECISION (char_type_node
))
2041 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2042 "argument to %<sizeof%> in %qD call is the same "
2043 "expression as the source; did you mean to "
2044 "provide an explicit length?", callee
);
2046 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2047 "argument to %<sizeof%> in %qD call is the same "
2048 "expression as the source; did you mean to "
2049 "dereference it?", callee
);
2053 if (POINTER_TYPE_P (TREE_TYPE (src
))
2055 && comp_types (TREE_TYPE (src
), type
)
2056 && !VOID_TYPE_P (TREE_TYPE (type
)))
2058 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2059 "argument to %<sizeof%> in %qD call is the same "
2060 "pointer type %qT as the source; expected %qT "
2061 "or an explicit length", callee
, TREE_TYPE (src
),
2062 TREE_TYPE (TREE_TYPE (src
)));
2069 if (!TYPE_P (sizeof_arg
[idx
])
2070 && operand_equal_p (dest
, sizeof_arg
[idx
], 0)
2071 && comp_types (TREE_TYPE (dest
), type
))
2073 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2074 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2075 "argument to %<sizeof%> in %qD call is the same "
2076 "expression as the first source; did you mean to "
2077 "remove the addressof?", callee
);
2078 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2079 == TYPE_PRECISION (char_type_node
))
2081 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2082 "argument to %<sizeof%> in %qD call is the same "
2083 "expression as the first source; did you mean to "
2084 "provide an explicit length?", callee
);
2086 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2087 "argument to %<sizeof%> in %qD call is the same "
2088 "expression as the first source; did you mean to "
2089 "dereference it?", callee
);
2093 if (POINTER_TYPE_P (TREE_TYPE (dest
))
2095 && comp_types (TREE_TYPE (dest
), type
)
2096 && !VOID_TYPE_P (TREE_TYPE (type
)))
2098 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2099 "argument to %<sizeof%> in %qD call is the same "
2100 "pointer type %qT as the first source; expected %qT "
2101 "or an explicit length", callee
, TREE_TYPE (dest
),
2102 TREE_TYPE (TREE_TYPE (dest
)));
2109 if (!TYPE_P (sizeof_arg
[idx
])
2110 && operand_equal_p (src
, sizeof_arg
[idx
], 0)
2111 && comp_types (TREE_TYPE (src
), type
))
2113 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2114 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2115 "argument to %<sizeof%> in %qD call is the same "
2116 "expression as the second source; did you mean to "
2117 "remove the addressof?", callee
);
2118 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2119 == TYPE_PRECISION (char_type_node
))
2121 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2122 "argument to %<sizeof%> in %qD call is the same "
2123 "expression as the second source; did you mean to "
2124 "provide an explicit length?", callee
);
2126 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2127 "argument to %<sizeof%> in %qD call is the same "
2128 "expression as the second source; did you mean to "
2129 "dereference it?", callee
);
2133 if (POINTER_TYPE_P (TREE_TYPE (src
))
2135 && comp_types (TREE_TYPE (src
), type
)
2136 && !VOID_TYPE_P (TREE_TYPE (type
)))
2138 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2139 "argument to %<sizeof%> in %qD call is the same "
2140 "pointer type %qT as the second source; expected %qT "
2141 "or an explicit length", callee
, TREE_TYPE (src
),
2142 TREE_TYPE (TREE_TYPE (src
)));
2149 /* Warn for unlikely, improbable, or stupid DECL declarations
2153 check_main_parameter_types (tree decl
)
2155 function_args_iterator iter
;
2159 FOREACH_FUNCTION_ARGS (TREE_TYPE (decl
), type
, iter
)
2161 /* XXX void_type_node belies the abstraction. */
2162 if (type
== void_type_node
|| type
== error_mark_node
)
2169 if (TYPE_MAIN_VARIANT (type
) != integer_type_node
)
2170 pedwarn (input_location
, OPT_Wmain
,
2171 "first argument of %q+D should be %<int%>", decl
);
2175 if (TREE_CODE (type
) != POINTER_TYPE
2176 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
2177 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
2179 pedwarn (input_location
, OPT_Wmain
,
2180 "second argument of %q+D should be %<char **%>", decl
);
2184 if (TREE_CODE (type
) != POINTER_TYPE
2185 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
2186 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
2188 pedwarn (input_location
, OPT_Wmain
,
2189 "third argument of %q+D should probably be "
2190 "%<char **%>", decl
);
2195 /* It is intentional that this message does not mention the third
2196 argument because it's only mentioned in an appendix of the
2198 if (argct
> 0 && (argct
< 2 || argct
> 3))
2199 pedwarn (input_location
, OPT_Wmain
,
2200 "%q+D takes only zero or two arguments", decl
);
2203 /* True if pointers to distinct types T1 and T2 can be converted to
2204 each other without an explicit cast. Only returns true for opaque
2207 vector_targets_convertible_p (const_tree t1
, const_tree t2
)
2209 if (TREE_CODE (t1
) == VECTOR_TYPE
&& TREE_CODE (t2
) == VECTOR_TYPE
2210 && (TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2211 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2217 /* True if vector types T1 and T2 can be converted to each other
2218 without an explicit cast. If EMIT_LAX_NOTE is true, and T1 and T2
2219 can only be converted with -flax-vector-conversions yet that is not
2220 in effect, emit a note telling the user about that option if such
2221 a note has not previously been emitted. */
2223 vector_types_convertible_p (const_tree t1
, const_tree t2
, bool emit_lax_note
)
2225 static bool emitted_lax_note
= false;
2226 bool convertible_lax
;
2228 if ((TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2229 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2233 (tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
))
2234 && (TREE_CODE (TREE_TYPE (t1
)) != REAL_TYPE
||
2235 TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
))
2236 && (INTEGRAL_TYPE_P (TREE_TYPE (t1
))
2237 == INTEGRAL_TYPE_P (TREE_TYPE (t2
))));
2239 if (!convertible_lax
|| flag_lax_vector_conversions
)
2240 return convertible_lax
;
2242 if (TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
)
2243 && lang_hooks
.types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
2246 if (emit_lax_note
&& !emitted_lax_note
)
2248 emitted_lax_note
= true;
2249 inform (input_location
, "use -flax-vector-conversions to permit "
2250 "conversions between vectors with differing "
2251 "element types or numbers of subparts");
2257 /* Build a VEC_PERM_EXPR if V0, V1 and MASK are not error_mark_nodes
2258 and have vector types, V0 has the same type as V1, and the number of
2259 elements of V0, V1, MASK is the same.
2261 In case V1 is a NULL_TREE it is assumed that __builtin_shuffle was
2262 called with two arguments. In this case implementation passes the
2263 first argument twice in order to share the same tree code. This fact
2264 could enable the mask-values being twice the vector length. This is
2265 an implementation accident and this semantics is not guaranteed to
2268 c_build_vec_perm_expr (location_t loc
, tree v0
, tree v1
, tree mask
,
2273 bool maybe_const
= false;
2274 bool two_arguments
= false;
2276 if (v1
== NULL_TREE
)
2278 two_arguments
= true;
2282 if (v0
== error_mark_node
|| v1
== error_mark_node
2283 || mask
== error_mark_node
)
2284 return error_mark_node
;
2286 if (TREE_CODE (TREE_TYPE (mask
)) != VECTOR_TYPE
2287 || TREE_CODE (TREE_TYPE (TREE_TYPE (mask
))) != INTEGER_TYPE
)
2290 error_at (loc
, "__builtin_shuffle last argument must "
2291 "be an integer vector");
2292 return error_mark_node
;
2295 if (TREE_CODE (TREE_TYPE (v0
)) != VECTOR_TYPE
2296 || TREE_CODE (TREE_TYPE (v1
)) != VECTOR_TYPE
)
2299 error_at (loc
, "__builtin_shuffle arguments must be vectors");
2300 return error_mark_node
;
2303 if (TYPE_MAIN_VARIANT (TREE_TYPE (v0
)) != TYPE_MAIN_VARIANT (TREE_TYPE (v1
)))
2306 error_at (loc
, "__builtin_shuffle argument vectors must be of "
2308 return error_mark_node
;
2311 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (v0
))
2312 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
))
2313 && TYPE_VECTOR_SUBPARTS (TREE_TYPE (v1
))
2314 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
)))
2317 error_at (loc
, "__builtin_shuffle number of elements of the "
2318 "argument vector(s) and the mask vector should "
2320 return error_mark_node
;
2323 if (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (v0
))))
2324 != GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (mask
)))))
2327 error_at (loc
, "__builtin_shuffle argument vector(s) inner type "
2328 "must have the same size as inner type of the mask");
2329 return error_mark_node
;
2332 if (!c_dialect_cxx ())
2334 /* Avoid C_MAYBE_CONST_EXPRs inside VEC_PERM_EXPR. */
2335 v0
= c_fully_fold (v0
, false, &maybe_const
);
2336 wrap
&= maybe_const
;
2339 v1
= v0
= save_expr (v0
);
2342 v1
= c_fully_fold (v1
, false, &maybe_const
);
2343 wrap
&= maybe_const
;
2346 mask
= c_fully_fold (mask
, false, &maybe_const
);
2347 wrap
&= maybe_const
;
2349 else if (two_arguments
)
2350 v1
= v0
= save_expr (v0
);
2352 ret
= build3_loc (loc
, VEC_PERM_EXPR
, TREE_TYPE (v0
), v0
, v1
, mask
);
2354 if (!c_dialect_cxx () && !wrap
)
2355 ret
= c_wrap_maybe_const (ret
, true);
2360 /* Like tree.c:get_narrower, but retain conversion from C++0x scoped enum
2361 to integral type. */
2364 c_common_get_narrower (tree op
, int *unsignedp_ptr
)
2366 op
= get_narrower (op
, unsignedp_ptr
);
2368 if (TREE_CODE (TREE_TYPE (op
)) == ENUMERAL_TYPE
2369 && ENUM_IS_SCOPED (TREE_TYPE (op
)))
2371 /* C++0x scoped enumerations don't implicitly convert to integral
2372 type; if we stripped an explicit conversion to a larger type we
2373 need to replace it so common_type will still work. */
2374 tree type
= c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op
)),
2375 TYPE_UNSIGNED (TREE_TYPE (op
)));
2376 op
= fold_convert (type
, op
);
2381 /* This is a helper function of build_binary_op.
2383 For certain operations if both args were extended from the same
2384 smaller type, do the arithmetic in that type and then extend.
2386 BITWISE indicates a bitwise operation.
2387 For them, this optimization is safe only if
2388 both args are zero-extended or both are sign-extended.
2389 Otherwise, we might change the result.
2390 Eg, (short)-1 | (unsigned short)-1 is (int)-1
2391 but calculated in (unsigned short) it would be (unsigned short)-1.
2394 shorten_binary_op (tree result_type
, tree op0
, tree op1
, bool bitwise
)
2396 int unsigned0
, unsigned1
;
2401 /* Cast OP0 and OP1 to RESULT_TYPE. Doing so prevents
2402 excessive narrowing when we call get_narrower below. For
2403 example, suppose that OP0 is of unsigned int extended
2404 from signed char and that RESULT_TYPE is long long int.
2405 If we explicitly cast OP0 to RESULT_TYPE, OP0 would look
2408 (long long int) (unsigned int) signed_char
2410 which get_narrower would narrow down to
2412 (unsigned int) signed char
2414 If we do not cast OP0 first, get_narrower would return
2415 signed_char, which is inconsistent with the case of the
2417 op0
= convert (result_type
, op0
);
2418 op1
= convert (result_type
, op1
);
2420 arg0
= c_common_get_narrower (op0
, &unsigned0
);
2421 arg1
= c_common_get_narrower (op1
, &unsigned1
);
2423 /* UNS is 1 if the operation to be done is an unsigned one. */
2424 uns
= TYPE_UNSIGNED (result_type
);
2426 /* Handle the case that OP0 (or OP1) does not *contain* a conversion
2427 but it *requires* conversion to FINAL_TYPE. */
2429 if ((TYPE_PRECISION (TREE_TYPE (op0
))
2430 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2431 && TREE_TYPE (op0
) != result_type
)
2432 unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2433 if ((TYPE_PRECISION (TREE_TYPE (op1
))
2434 == TYPE_PRECISION (TREE_TYPE (arg1
)))
2435 && TREE_TYPE (op1
) != result_type
)
2436 unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2438 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
2440 /* For bitwise operations, signedness of nominal type
2441 does not matter. Consider only how operands were extended. */
2445 /* Note that in all three cases below we refrain from optimizing
2446 an unsigned operation on sign-extended args.
2447 That would not be valid. */
2449 /* Both args variable: if both extended in same way
2450 from same width, do it in that width.
2451 Do it unsigned if args were zero-extended. */
2452 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
2453 < TYPE_PRECISION (result_type
))
2454 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2455 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2456 && unsigned0
== unsigned1
2457 && (unsigned0
|| !uns
))
2458 return c_common_signed_or_unsigned_type
2459 (unsigned0
, common_type (TREE_TYPE (arg0
), TREE_TYPE (arg1
)));
2461 else if (TREE_CODE (arg0
) == INTEGER_CST
2462 && (unsigned1
|| !uns
)
2463 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2464 < TYPE_PRECISION (result_type
))
2466 = c_common_signed_or_unsigned_type (unsigned1
,
2468 && !POINTER_TYPE_P (type
)
2469 && int_fits_type_p (arg0
, type
))
2472 else if (TREE_CODE (arg1
) == INTEGER_CST
2473 && (unsigned0
|| !uns
)
2474 && (TYPE_PRECISION (TREE_TYPE (arg0
))
2475 < TYPE_PRECISION (result_type
))
2477 = c_common_signed_or_unsigned_type (unsigned0
,
2479 && !POINTER_TYPE_P (type
)
2480 && int_fits_type_p (arg1
, type
))
2486 /* Checks if expression EXPR of real/integer type cannot be converted
2487 to the real/integer type TYPE. Function returns true when:
2488 * EXPR is a constant which cannot be exactly converted to TYPE
2489 * EXPR is not a constant and size of EXPR's type > than size of TYPE,
2490 for EXPR type and TYPE being both integers or both real.
2491 * EXPR is not a constant of real type and TYPE is an integer.
2492 * EXPR is not a constant of integer type which cannot be
2493 exactly converted to real type.
2494 Function allows conversions between types of different signedness and
2495 does not return true in that case. Function can produce signedness
2496 warnings if PRODUCE_WARNS is true. */
2498 unsafe_conversion_p (tree type
, tree expr
, bool produce_warns
)
2500 bool give_warning
= false;
2501 tree expr_type
= TREE_TYPE (expr
);
2502 location_t loc
= EXPR_LOC_OR_HERE (expr
);
2504 if (TREE_CODE (expr
) == REAL_CST
|| TREE_CODE (expr
) == INTEGER_CST
)
2506 /* Warn for real constant that is not an exact integer converted
2508 if (TREE_CODE (expr_type
) == REAL_TYPE
2509 && TREE_CODE (type
) == INTEGER_TYPE
)
2511 if (!real_isinteger (TREE_REAL_CST_PTR (expr
), TYPE_MODE (expr_type
)))
2512 give_warning
= true;
2514 /* Warn for an integer constant that does not fit into integer type. */
2515 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2516 && TREE_CODE (type
) == INTEGER_TYPE
2517 && !int_fits_type_p (expr
, type
))
2519 if (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)
2520 && tree_int_cst_sgn (expr
) < 0)
2523 warning_at (loc
, OPT_Wsign_conversion
, "negative integer"
2524 " implicitly converted to unsigned type");
2526 else if (!TYPE_UNSIGNED (type
) && TYPE_UNSIGNED (expr_type
))
2529 warning_at (loc
, OPT_Wsign_conversion
, "conversion of unsigned"
2530 " constant value to negative integer");
2533 give_warning
= true;
2535 else if (TREE_CODE (type
) == REAL_TYPE
)
2537 /* Warn for an integer constant that does not fit into real type. */
2538 if (TREE_CODE (expr_type
) == INTEGER_TYPE
)
2540 REAL_VALUE_TYPE a
= real_value_from_int_cst (0, expr
);
2541 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2542 give_warning
= true;
2544 /* Warn for a real constant that does not fit into a smaller
2546 else if (TREE_CODE (expr_type
) == REAL_TYPE
2547 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2549 REAL_VALUE_TYPE a
= TREE_REAL_CST (expr
);
2550 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2551 give_warning
= true;
2557 /* Warn for real types converted to integer types. */
2558 if (TREE_CODE (expr_type
) == REAL_TYPE
2559 && TREE_CODE (type
) == INTEGER_TYPE
)
2560 give_warning
= true;
2562 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2563 && TREE_CODE (type
) == INTEGER_TYPE
)
2565 /* Don't warn about unsigned char y = 0xff, x = (int) y; */
2566 expr
= get_unwidened (expr
, 0);
2567 expr_type
= TREE_TYPE (expr
);
2569 /* Don't warn for short y; short x = ((int)y & 0xff); */
2570 if (TREE_CODE (expr
) == BIT_AND_EXPR
2571 || TREE_CODE (expr
) == BIT_IOR_EXPR
2572 || TREE_CODE (expr
) == BIT_XOR_EXPR
)
2574 /* If both args were extended from a shortest type,
2575 use that type if that is safe. */
2576 expr_type
= shorten_binary_op (expr_type
,
2577 TREE_OPERAND (expr
, 0),
2578 TREE_OPERAND (expr
, 1),
2581 if (TREE_CODE (expr
) == BIT_AND_EXPR
)
2583 tree op0
= TREE_OPERAND (expr
, 0);
2584 tree op1
= TREE_OPERAND (expr
, 1);
2585 bool unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2586 bool unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2588 /* If one of the operands is a non-negative constant
2589 that fits in the target type, then the type of the
2590 other operand does not matter. */
2591 if ((TREE_CODE (op0
) == INTEGER_CST
2592 && int_fits_type_p (op0
, c_common_signed_type (type
))
2593 && int_fits_type_p (op0
, c_common_unsigned_type (type
)))
2594 || (TREE_CODE (op1
) == INTEGER_CST
2595 && int_fits_type_p (op1
, c_common_signed_type (type
))
2596 && int_fits_type_p (op1
,
2597 c_common_unsigned_type (type
))))
2599 /* If constant is unsigned and fits in the target
2600 type, then the result will also fit. */
2601 else if ((TREE_CODE (op0
) == INTEGER_CST
2603 && int_fits_type_p (op0
, type
))
2604 || (TREE_CODE (op1
) == INTEGER_CST
2606 && int_fits_type_p (op1
, type
)))
2610 /* Warn for integer types converted to smaller integer types. */
2611 if (TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2612 give_warning
= true;
2614 /* When they are the same width but different signedness,
2615 then the value may change. */
2616 else if (((TYPE_PRECISION (type
) == TYPE_PRECISION (expr_type
)
2617 && TYPE_UNSIGNED (expr_type
) != TYPE_UNSIGNED (type
))
2618 /* Even when converted to a bigger type, if the type is
2619 unsigned but expr is signed, then negative values
2621 || (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)))
2623 warning_at (loc
, OPT_Wsign_conversion
, "conversion to %qT from %qT "
2624 "may change the sign of the result",
2628 /* Warn for integer types converted to real types if and only if
2629 all the range of values of the integer type cannot be
2630 represented by the real type. */
2631 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2632 && TREE_CODE (type
) == REAL_TYPE
)
2634 tree type_low_bound
, type_high_bound
;
2635 REAL_VALUE_TYPE real_low_bound
, real_high_bound
;
2637 /* Don't warn about char y = 0xff; float x = (int) y; */
2638 expr
= get_unwidened (expr
, 0);
2639 expr_type
= TREE_TYPE (expr
);
2641 type_low_bound
= TYPE_MIN_VALUE (expr_type
);
2642 type_high_bound
= TYPE_MAX_VALUE (expr_type
);
2643 real_low_bound
= real_value_from_int_cst (0, type_low_bound
);
2644 real_high_bound
= real_value_from_int_cst (0, type_high_bound
);
2646 if (!exact_real_truncate (TYPE_MODE (type
), &real_low_bound
)
2647 || !exact_real_truncate (TYPE_MODE (type
), &real_high_bound
))
2648 give_warning
= true;
2651 /* Warn for real types converted to smaller real types. */
2652 else if (TREE_CODE (expr_type
) == REAL_TYPE
2653 && TREE_CODE (type
) == REAL_TYPE
2654 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2655 give_warning
= true;
2658 return give_warning
;
2661 /* Warns if the conversion of EXPR to TYPE may alter a value.
2662 This is a helper function for warnings_for_convert_and_check. */
2665 conversion_warning (tree type
, tree expr
)
2667 tree expr_type
= TREE_TYPE (expr
);
2668 location_t loc
= EXPR_LOC_OR_HERE (expr
);
2670 if (!warn_conversion
&& !warn_sign_conversion
)
2673 switch (TREE_CODE (expr
))
2681 case TRUTH_ANDIF_EXPR
:
2682 case TRUTH_ORIF_EXPR
:
2683 case TRUTH_AND_EXPR
:
2685 case TRUTH_XOR_EXPR
:
2686 case TRUTH_NOT_EXPR
:
2687 /* Conversion from boolean to a signed:1 bit-field (which only
2688 can hold the values 0 and -1) doesn't lose information - but
2689 it does change the value. */
2690 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
2691 warning_at (loc
, OPT_Wconversion
,
2692 "conversion to %qT from boolean expression", type
);
2697 if (unsafe_conversion_p (type
, expr
, true))
2698 warning_at (loc
, OPT_Wconversion
,
2699 "conversion to %qT alters %qT constant value",
2705 /* In case of COND_EXPR, we do not care about the type of
2706 COND_EXPR, only about the conversion of each operand. */
2707 tree op1
= TREE_OPERAND (expr
, 1);
2708 tree op2
= TREE_OPERAND (expr
, 2);
2710 conversion_warning (type
, op1
);
2711 conversion_warning (type
, op2
);
2715 default: /* 'expr' is not a constant. */
2716 if (unsafe_conversion_p (type
, expr
, true))
2717 warning_at (loc
, OPT_Wconversion
,
2718 "conversion to %qT from %qT may alter its value",
2723 /* Produce warnings after a conversion. RESULT is the result of
2724 converting EXPR to TYPE. This is a helper function for
2725 convert_and_check and cp_convert_and_check. */
2728 warnings_for_convert_and_check (tree type
, tree expr
, tree result
)
2730 location_t loc
= EXPR_LOC_OR_HERE (expr
);
2732 if (TREE_CODE (expr
) == INTEGER_CST
2733 && (TREE_CODE (type
) == INTEGER_TYPE
2734 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2735 && !int_fits_type_p (expr
, type
))
2737 /* Do not diagnose overflow in a constant expression merely
2738 because a conversion overflowed. */
2739 if (TREE_OVERFLOW (result
))
2740 TREE_OVERFLOW (result
) = TREE_OVERFLOW (expr
);
2742 if (TYPE_UNSIGNED (type
))
2744 /* This detects cases like converting -129 or 256 to
2746 if (!int_fits_type_p (expr
, c_common_signed_type (type
)))
2747 warning_at (loc
, OPT_Woverflow
,
2748 "large integer implicitly truncated to unsigned type");
2750 conversion_warning (type
, expr
);
2752 else if (!int_fits_type_p (expr
, c_common_unsigned_type (type
)))
2753 warning (OPT_Woverflow
,
2754 "overflow in implicit constant conversion");
2755 /* No warning for converting 0x80000000 to int. */
2757 && (TREE_CODE (TREE_TYPE (expr
)) != INTEGER_TYPE
2758 || TYPE_PRECISION (TREE_TYPE (expr
))
2759 != TYPE_PRECISION (type
)))
2760 warning_at (loc
, OPT_Woverflow
,
2761 "overflow in implicit constant conversion");
2764 conversion_warning (type
, expr
);
2766 else if ((TREE_CODE (result
) == INTEGER_CST
2767 || TREE_CODE (result
) == FIXED_CST
) && TREE_OVERFLOW (result
))
2768 warning_at (loc
, OPT_Woverflow
,
2769 "overflow in implicit constant conversion");
2771 conversion_warning (type
, expr
);
2775 /* Convert EXPR to TYPE, warning about conversion problems with constants.
2776 Invoke this function on every expression that is converted implicitly,
2777 i.e. because of language rules and not because of an explicit cast. */
2780 convert_and_check (tree type
, tree expr
)
2783 tree expr_for_warning
;
2785 /* Convert from a value with possible excess precision rather than
2786 via the semantic type, but do not warn about values not fitting
2787 exactly in the semantic type. */
2788 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
2790 tree orig_type
= TREE_TYPE (expr
);
2791 expr
= TREE_OPERAND (expr
, 0);
2792 expr_for_warning
= convert (orig_type
, expr
);
2793 if (orig_type
== type
)
2794 return expr_for_warning
;
2797 expr_for_warning
= expr
;
2799 if (TREE_TYPE (expr
) == type
)
2802 result
= convert (type
, expr
);
2804 if (c_inhibit_evaluation_warnings
== 0
2805 && !TREE_OVERFLOW_P (expr
)
2806 && result
!= error_mark_node
)
2807 warnings_for_convert_and_check (type
, expr_for_warning
, result
);
2812 /* A node in a list that describes references to variables (EXPR), which are
2813 either read accesses if WRITER is zero, or write accesses, in which case
2814 WRITER is the parent of EXPR. */
2821 /* Used to implement a cache the results of a call to verify_tree. We only
2822 use this for SAVE_EXPRs. */
2825 struct tlist_cache
*next
;
2826 struct tlist
*cache_before_sp
;
2827 struct tlist
*cache_after_sp
;
2831 /* Obstack to use when allocating tlist structures, and corresponding
2833 static struct obstack tlist_obstack
;
2834 static char *tlist_firstobj
= 0;
2836 /* Keep track of the identifiers we've warned about, so we can avoid duplicate
2838 static struct tlist
*warned_ids
;
2839 /* SAVE_EXPRs need special treatment. We process them only once and then
2840 cache the results. */
2841 static struct tlist_cache
*save_expr_cache
;
2843 static void add_tlist (struct tlist
**, struct tlist
*, tree
, int);
2844 static void merge_tlist (struct tlist
**, struct tlist
*, int);
2845 static void verify_tree (tree
, struct tlist
**, struct tlist
**, tree
);
2846 static int warning_candidate_p (tree
);
2847 static bool candidate_equal_p (const_tree
, const_tree
);
2848 static void warn_for_collisions (struct tlist
*);
2849 static void warn_for_collisions_1 (tree
, tree
, struct tlist
*, int);
2850 static struct tlist
*new_tlist (struct tlist
*, tree
, tree
);
2852 /* Create a new struct tlist and fill in its fields. */
2853 static struct tlist
*
2854 new_tlist (struct tlist
*next
, tree t
, tree writer
)
2857 l
= XOBNEW (&tlist_obstack
, struct tlist
);
2864 /* Add duplicates of the nodes found in ADD to the list *TO. If EXCLUDE_WRITER
2865 is nonnull, we ignore any node we find which has a writer equal to it. */
2868 add_tlist (struct tlist
**to
, struct tlist
*add
, tree exclude_writer
, int copy
)
2872 struct tlist
*next
= add
->next
;
2875 if (!exclude_writer
|| !candidate_equal_p (add
->writer
, exclude_writer
))
2876 *to
= copy
? new_tlist (*to
, add
->expr
, add
->writer
) : add
;
2881 /* Merge the nodes of ADD into TO. This merging process is done so that for
2882 each variable that already exists in TO, no new node is added; however if
2883 there is a write access recorded in ADD, and an occurrence on TO is only
2884 a read access, then the occurrence in TO will be modified to record the
2888 merge_tlist (struct tlist
**to
, struct tlist
*add
, int copy
)
2890 struct tlist
**end
= to
;
2893 end
= &(*end
)->next
;
2899 struct tlist
*next
= add
->next
;
2901 for (tmp2
= *to
; tmp2
; tmp2
= tmp2
->next
)
2902 if (candidate_equal_p (tmp2
->expr
, add
->expr
))
2906 tmp2
->writer
= add
->writer
;
2910 *end
= copy
? add
: new_tlist (NULL
, add
->expr
, add
->writer
);
2911 end
= &(*end
)->next
;
2918 /* WRITTEN is a variable, WRITER is its parent. Warn if any of the variable
2919 references in list LIST conflict with it, excluding reads if ONLY writers
2923 warn_for_collisions_1 (tree written
, tree writer
, struct tlist
*list
,
2928 /* Avoid duplicate warnings. */
2929 for (tmp
= warned_ids
; tmp
; tmp
= tmp
->next
)
2930 if (candidate_equal_p (tmp
->expr
, written
))
2935 if (candidate_equal_p (list
->expr
, written
)
2936 && !candidate_equal_p (list
->writer
, writer
)
2937 && (!only_writes
|| list
->writer
))
2939 warned_ids
= new_tlist (warned_ids
, written
, NULL_TREE
);
2940 warning_at (EXPR_LOC_OR_HERE (writer
),
2941 OPT_Wsequence_point
, "operation on %qE may be undefined",
2948 /* Given a list LIST of references to variables, find whether any of these
2949 can cause conflicts due to missing sequence points. */
2952 warn_for_collisions (struct tlist
*list
)
2956 for (tmp
= list
; tmp
; tmp
= tmp
->next
)
2959 warn_for_collisions_1 (tmp
->expr
, tmp
->writer
, list
, 0);
2963 /* Return nonzero if X is a tree that can be verified by the sequence point
2966 warning_candidate_p (tree x
)
2968 if (DECL_P (x
) && DECL_ARTIFICIAL (x
))
2971 if (TREE_CODE (x
) == BLOCK
)
2974 /* VOID_TYPE_P (TREE_TYPE (x)) is workaround for cp/tree.c
2975 (lvalue_p) crash on TRY/CATCH. */
2976 if (TREE_TYPE (x
) == NULL_TREE
|| VOID_TYPE_P (TREE_TYPE (x
)))
2982 /* No point to track non-const calls, they will never satisfy
2984 if (TREE_CODE (x
) == CALL_EXPR
&& (call_expr_flags (x
) & ECF_CONST
) == 0)
2987 if (TREE_CODE (x
) == STRING_CST
)
2993 /* Return nonzero if X and Y appear to be the same candidate (or NULL) */
2995 candidate_equal_p (const_tree x
, const_tree y
)
2997 return (x
== y
) || (x
&& y
&& operand_equal_p (x
, y
, 0));
3000 /* Walk the tree X, and record accesses to variables. If X is written by the
3001 parent tree, WRITER is the parent.
3002 We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP. If this
3003 expression or its only operand forces a sequence point, then everything up
3004 to the sequence point is stored in PBEFORE_SP. Everything else gets stored
3006 Once we return, we will have emitted warnings if any subexpression before
3007 such a sequence point could be undefined. On a higher level, however, the
3008 sequence point may not be relevant, and we'll merge the two lists.
3010 Example: (b++, a) + b;
3011 The call that processes the COMPOUND_EXPR will store the increment of B
3012 in PBEFORE_SP, and the use of A in PNO_SP. The higher-level call that
3013 processes the PLUS_EXPR will need to merge the two lists so that
3014 eventually, all accesses end up on the same list (and we'll warn about the
3015 unordered subexpressions b++ and b.
3017 A note on merging. If we modify the former example so that our expression
3020 care must be taken not simply to add all three expressions into the final
3021 PNO_SP list. The function merge_tlist takes care of that by merging the
3022 before-SP list of the COMPOUND_EXPR into its after-SP list in a special
3023 way, so that no more than one access to B is recorded. */
3026 verify_tree (tree x
, struct tlist
**pbefore_sp
, struct tlist
**pno_sp
,
3029 struct tlist
*tmp_before
, *tmp_nosp
, *tmp_list2
, *tmp_list3
;
3030 enum tree_code code
;
3031 enum tree_code_class cl
;
3033 /* X may be NULL if it is the operand of an empty statement expression
3039 code
= TREE_CODE (x
);
3040 cl
= TREE_CODE_CLASS (code
);
3042 if (warning_candidate_p (x
))
3043 *pno_sp
= new_tlist (*pno_sp
, x
, writer
);
3052 case TRUTH_ANDIF_EXPR
:
3053 case TRUTH_ORIF_EXPR
:
3054 tmp_before
= tmp_nosp
= tmp_list3
= 0;
3055 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3056 warn_for_collisions (tmp_nosp
);
3057 merge_tlist (pbefore_sp
, tmp_before
, 0);
3058 merge_tlist (pbefore_sp
, tmp_nosp
, 0);
3059 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, pno_sp
, NULL_TREE
);
3060 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3064 tmp_before
= tmp_list2
= 0;
3065 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_list2
, NULL_TREE
);
3066 warn_for_collisions (tmp_list2
);
3067 merge_tlist (pbefore_sp
, tmp_before
, 0);
3068 merge_tlist (pbefore_sp
, tmp_list2
, 1);
3070 tmp_list3
= tmp_nosp
= 0;
3071 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, &tmp_nosp
, NULL_TREE
);
3072 warn_for_collisions (tmp_nosp
);
3073 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3075 tmp_list3
= tmp_list2
= 0;
3076 verify_tree (TREE_OPERAND (x
, 2), &tmp_list3
, &tmp_list2
, NULL_TREE
);
3077 warn_for_collisions (tmp_list2
);
3078 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3079 /* Rather than add both tmp_nosp and tmp_list2, we have to merge the
3080 two first, to avoid warning for (a ? b++ : b++). */
3081 merge_tlist (&tmp_nosp
, tmp_list2
, 0);
3082 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3085 case PREDECREMENT_EXPR
:
3086 case PREINCREMENT_EXPR
:
3087 case POSTDECREMENT_EXPR
:
3088 case POSTINCREMENT_EXPR
:
3089 verify_tree (TREE_OPERAND (x
, 0), pno_sp
, pno_sp
, x
);
3093 tmp_before
= tmp_nosp
= tmp_list3
= 0;
3094 verify_tree (TREE_OPERAND (x
, 1), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3095 verify_tree (TREE_OPERAND (x
, 0), &tmp_list3
, &tmp_list3
, x
);
3096 /* Expressions inside the LHS are not ordered wrt. the sequence points
3097 in the RHS. Example:
3099 Despite the fact that the modification of "a" is in the before_sp
3100 list (tmp_before), it conflicts with the use of "a" in the LHS.
3101 We can handle this by adding the contents of tmp_list3
3102 to those of tmp_before, and redoing the collision warnings for that
3104 add_tlist (&tmp_before
, tmp_list3
, x
, 1);
3105 warn_for_collisions (tmp_before
);
3106 /* Exclude the LHS itself here; we first have to merge it into the
3107 tmp_nosp list. This is done to avoid warning for "a = a"; if we
3108 didn't exclude the LHS, we'd get it twice, once as a read and once
3110 add_tlist (pno_sp
, tmp_list3
, x
, 0);
3111 warn_for_collisions_1 (TREE_OPERAND (x
, 0), x
, tmp_nosp
, 1);
3113 merge_tlist (pbefore_sp
, tmp_before
, 0);
3114 if (warning_candidate_p (TREE_OPERAND (x
, 0)))
3115 merge_tlist (&tmp_nosp
, new_tlist (NULL
, TREE_OPERAND (x
, 0), x
), 0);
3116 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 1);
3120 /* We need to warn about conflicts among arguments and conflicts between
3121 args and the function address. Side effects of the function address,
3122 however, are not ordered by the sequence point of the call. */
3124 call_expr_arg_iterator iter
;
3126 tmp_before
= tmp_nosp
= 0;
3127 verify_tree (CALL_EXPR_FN (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3128 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, x
)
3130 tmp_list2
= tmp_list3
= 0;
3131 verify_tree (arg
, &tmp_list2
, &tmp_list3
, NULL_TREE
);
3132 merge_tlist (&tmp_list3
, tmp_list2
, 0);
3133 add_tlist (&tmp_before
, tmp_list3
, NULL_TREE
, 0);
3135 add_tlist (&tmp_before
, tmp_nosp
, NULL_TREE
, 0);
3136 warn_for_collisions (tmp_before
);
3137 add_tlist (pbefore_sp
, tmp_before
, NULL_TREE
, 0);
3142 /* Scan all the list, e.g. indices of multi dimensional array. */
3145 tmp_before
= tmp_nosp
= 0;
3146 verify_tree (TREE_VALUE (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3147 merge_tlist (&tmp_nosp
, tmp_before
, 0);
3148 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3155 struct tlist_cache
*t
;
3156 for (t
= save_expr_cache
; t
; t
= t
->next
)
3157 if (candidate_equal_p (t
->expr
, x
))
3162 t
= XOBNEW (&tlist_obstack
, struct tlist_cache
);
3163 t
->next
= save_expr_cache
;
3165 save_expr_cache
= t
;
3167 tmp_before
= tmp_nosp
= 0;
3168 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3169 warn_for_collisions (tmp_nosp
);
3174 struct tlist
*t
= tmp_nosp
;
3176 merge_tlist (&tmp_list3
, t
, 0);
3178 t
->cache_before_sp
= tmp_before
;
3179 t
->cache_after_sp
= tmp_list3
;
3181 merge_tlist (pbefore_sp
, t
->cache_before_sp
, 1);
3182 add_tlist (pno_sp
, t
->cache_after_sp
, NULL_TREE
, 1);
3187 x
= TREE_OPERAND (x
, 0);
3194 /* For other expressions, simply recurse on their operands.
3195 Manual tail recursion for unary expressions.
3196 Other non-expressions need not be processed. */
3197 if (cl
== tcc_unary
)
3199 x
= TREE_OPERAND (x
, 0);
3203 else if (IS_EXPR_CODE_CLASS (cl
))
3206 int max
= TREE_OPERAND_LENGTH (x
);
3207 for (lp
= 0; lp
< max
; lp
++)
3209 tmp_before
= tmp_nosp
= 0;
3210 verify_tree (TREE_OPERAND (x
, lp
), &tmp_before
, &tmp_nosp
, 0);
3211 merge_tlist (&tmp_nosp
, tmp_before
, 0);
3212 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3219 /* Try to warn for undefined behavior in EXPR due to missing sequence
3223 verify_sequence_points (tree expr
)
3225 struct tlist
*before_sp
= 0, *after_sp
= 0;
3228 save_expr_cache
= 0;
3229 if (tlist_firstobj
== 0)
3231 gcc_obstack_init (&tlist_obstack
);
3232 tlist_firstobj
= (char *) obstack_alloc (&tlist_obstack
, 0);
3235 verify_tree (expr
, &before_sp
, &after_sp
, 0);
3236 warn_for_collisions (after_sp
);
3237 obstack_free (&tlist_obstack
, tlist_firstobj
);
3240 /* Validate the expression after `case' and apply default promotions. */
3243 check_case_value (tree value
)
3245 if (value
== NULL_TREE
)
3248 if (TREE_CODE (value
) == INTEGER_CST
)
3249 /* Promote char or short to int. */
3250 value
= perform_integral_promotions (value
);
3251 else if (value
!= error_mark_node
)
3253 error ("case label does not reduce to an integer constant");
3254 value
= error_mark_node
;
3257 constant_expression_warning (value
);
3262 /* See if the case values LOW and HIGH are in the range of the original
3263 type (i.e. before the default conversion to int) of the switch testing
3265 TYPE is the promoted type of the testing expression, and ORIG_TYPE is
3266 the type before promoting it. CASE_LOW_P is a pointer to the lower
3267 bound of the case label, and CASE_HIGH_P is the upper bound or NULL
3268 if the case is not a case range.
3269 The caller has to make sure that we are not called with NULL for
3270 CASE_LOW_P (i.e. the default case).
3271 Returns true if the case label is in range of ORIG_TYPE (saturated or
3272 untouched) or false if the label is out of range. */
3275 check_case_bounds (tree type
, tree orig_type
,
3276 tree
*case_low_p
, tree
*case_high_p
)
3278 tree min_value
, max_value
;
3279 tree case_low
= *case_low_p
;
3280 tree case_high
= case_high_p
? *case_high_p
: case_low
;
3282 /* If there was a problem with the original type, do nothing. */
3283 if (orig_type
== error_mark_node
)
3286 min_value
= TYPE_MIN_VALUE (orig_type
);
3287 max_value
= TYPE_MAX_VALUE (orig_type
);
3289 /* Case label is less than minimum for type. */
3290 if (tree_int_cst_compare (case_low
, min_value
) < 0
3291 && tree_int_cst_compare (case_high
, min_value
) < 0)
3293 warning (0, "case label value is less than minimum value for type");
3297 /* Case value is greater than maximum for type. */
3298 if (tree_int_cst_compare (case_low
, max_value
) > 0
3299 && tree_int_cst_compare (case_high
, max_value
) > 0)
3301 warning (0, "case label value exceeds maximum value for type");
3305 /* Saturate lower case label value to minimum. */
3306 if (tree_int_cst_compare (case_high
, min_value
) >= 0
3307 && tree_int_cst_compare (case_low
, min_value
) < 0)
3309 warning (0, "lower value in case label range"
3310 " less than minimum value for type");
3311 case_low
= min_value
;
3314 /* Saturate upper case label value to maximum. */
3315 if (tree_int_cst_compare (case_low
, max_value
) <= 0
3316 && tree_int_cst_compare (case_high
, max_value
) > 0)
3318 warning (0, "upper value in case label range"
3319 " exceeds maximum value for type");
3320 case_high
= max_value
;
3323 if (*case_low_p
!= case_low
)
3324 *case_low_p
= convert (type
, case_low
);
3325 if (case_high_p
&& *case_high_p
!= case_high
)
3326 *case_high_p
= convert (type
, case_high
);
3331 /* Return an integer type with BITS bits of precision,
3332 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
3335 c_common_type_for_size (unsigned int bits
, int unsignedp
)
3337 if (bits
== TYPE_PRECISION (integer_type_node
))
3338 return unsignedp
? unsigned_type_node
: integer_type_node
;
3340 if (bits
== TYPE_PRECISION (signed_char_type_node
))
3341 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3343 if (bits
== TYPE_PRECISION (short_integer_type_node
))
3344 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3346 if (bits
== TYPE_PRECISION (long_integer_type_node
))
3347 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3349 if (bits
== TYPE_PRECISION (long_long_integer_type_node
))
3350 return (unsignedp
? long_long_unsigned_type_node
3351 : long_long_integer_type_node
);
3353 if (int128_integer_type_node
3354 && bits
== TYPE_PRECISION (int128_integer_type_node
))
3355 return (unsignedp
? int128_unsigned_type_node
3356 : int128_integer_type_node
);
3358 if (bits
== TYPE_PRECISION (widest_integer_literal_type_node
))
3359 return (unsignedp
? widest_unsigned_literal_type_node
3360 : widest_integer_literal_type_node
);
3362 if (bits
<= TYPE_PRECISION (intQI_type_node
))
3363 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3365 if (bits
<= TYPE_PRECISION (intHI_type_node
))
3366 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3368 if (bits
<= TYPE_PRECISION (intSI_type_node
))
3369 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3371 if (bits
<= TYPE_PRECISION (intDI_type_node
))
3372 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3377 /* Return a fixed-point type that has at least IBIT ibits and FBIT fbits
3378 that is unsigned if UNSIGNEDP is nonzero, otherwise signed;
3379 and saturating if SATP is nonzero, otherwise not saturating. */
3382 c_common_fixed_point_type_for_size (unsigned int ibit
, unsigned int fbit
,
3383 int unsignedp
, int satp
)
3385 enum machine_mode mode
;
3387 mode
= unsignedp
? UQQmode
: QQmode
;
3389 mode
= unsignedp
? UHAmode
: HAmode
;
3391 for (; mode
!= VOIDmode
; mode
= GET_MODE_WIDER_MODE (mode
))
3392 if (GET_MODE_IBIT (mode
) >= ibit
&& GET_MODE_FBIT (mode
) >= fbit
)
3395 if (mode
== VOIDmode
|| !targetm
.scalar_mode_supported_p (mode
))
3397 sorry ("GCC cannot support operators with integer types and "
3398 "fixed-point types that have too many integral and "
3399 "fractional bits together");
3403 return c_common_type_for_mode (mode
, satp
);
3406 /* Used for communication between c_common_type_for_mode and
3407 c_register_builtin_type. */
3408 static GTY(()) tree registered_builtin_types
;
3410 /* Return a data type that has machine mode MODE.
3411 If the mode is an integer,
3412 then UNSIGNEDP selects between signed and unsigned types.
3413 If the mode is a fixed-point mode,
3414 then UNSIGNEDP selects between saturating and nonsaturating types. */
3417 c_common_type_for_mode (enum machine_mode mode
, int unsignedp
)
3421 if (mode
== TYPE_MODE (integer_type_node
))
3422 return unsignedp
? unsigned_type_node
: integer_type_node
;
3424 if (mode
== TYPE_MODE (signed_char_type_node
))
3425 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3427 if (mode
== TYPE_MODE (short_integer_type_node
))
3428 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3430 if (mode
== TYPE_MODE (long_integer_type_node
))
3431 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3433 if (mode
== TYPE_MODE (long_long_integer_type_node
))
3434 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3436 if (int128_integer_type_node
3437 && mode
== TYPE_MODE (int128_integer_type_node
))
3438 return unsignedp
? int128_unsigned_type_node
: int128_integer_type_node
;
3440 if (mode
== TYPE_MODE (widest_integer_literal_type_node
))
3441 return unsignedp
? widest_unsigned_literal_type_node
3442 : widest_integer_literal_type_node
;
3445 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3448 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3451 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3454 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3456 #if HOST_BITS_PER_WIDE_INT >= 64
3457 if (mode
== TYPE_MODE (intTI_type_node
))
3458 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3461 if (mode
== TYPE_MODE (float_type_node
))
3462 return float_type_node
;
3464 if (mode
== TYPE_MODE (double_type_node
))
3465 return double_type_node
;
3467 if (mode
== TYPE_MODE (long_double_type_node
))
3468 return long_double_type_node
;
3470 if (mode
== TYPE_MODE (void_type_node
))
3471 return void_type_node
;
3473 if (mode
== TYPE_MODE (build_pointer_type (char_type_node
)))
3475 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3476 : make_signed_type (GET_MODE_PRECISION (mode
)));
3478 if (mode
== TYPE_MODE (build_pointer_type (integer_type_node
)))
3480 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3481 : make_signed_type (GET_MODE_PRECISION (mode
)));
3483 if (COMPLEX_MODE_P (mode
))
3485 enum machine_mode inner_mode
;
3488 if (mode
== TYPE_MODE (complex_float_type_node
))
3489 return complex_float_type_node
;
3490 if (mode
== TYPE_MODE (complex_double_type_node
))
3491 return complex_double_type_node
;
3492 if (mode
== TYPE_MODE (complex_long_double_type_node
))
3493 return complex_long_double_type_node
;
3495 if (mode
== TYPE_MODE (complex_integer_type_node
) && !unsignedp
)
3496 return complex_integer_type_node
;
3498 inner_mode
= GET_MODE_INNER (mode
);
3499 inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3500 if (inner_type
!= NULL_TREE
)
3501 return build_complex_type (inner_type
);
3503 else if (VECTOR_MODE_P (mode
))
3505 enum machine_mode inner_mode
= GET_MODE_INNER (mode
);
3506 tree inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3507 if (inner_type
!= NULL_TREE
)
3508 return build_vector_type_for_mode (inner_type
, mode
);
3511 if (mode
== TYPE_MODE (dfloat32_type_node
))
3512 return dfloat32_type_node
;
3513 if (mode
== TYPE_MODE (dfloat64_type_node
))
3514 return dfloat64_type_node
;
3515 if (mode
== TYPE_MODE (dfloat128_type_node
))
3516 return dfloat128_type_node
;
3518 if (ALL_SCALAR_FIXED_POINT_MODE_P (mode
))
3520 if (mode
== TYPE_MODE (short_fract_type_node
))
3521 return unsignedp
? sat_short_fract_type_node
: short_fract_type_node
;
3522 if (mode
== TYPE_MODE (fract_type_node
))
3523 return unsignedp
? sat_fract_type_node
: fract_type_node
;
3524 if (mode
== TYPE_MODE (long_fract_type_node
))
3525 return unsignedp
? sat_long_fract_type_node
: long_fract_type_node
;
3526 if (mode
== TYPE_MODE (long_long_fract_type_node
))
3527 return unsignedp
? sat_long_long_fract_type_node
3528 : long_long_fract_type_node
;
3530 if (mode
== TYPE_MODE (unsigned_short_fract_type_node
))
3531 return unsignedp
? sat_unsigned_short_fract_type_node
3532 : unsigned_short_fract_type_node
;
3533 if (mode
== TYPE_MODE (unsigned_fract_type_node
))
3534 return unsignedp
? sat_unsigned_fract_type_node
3535 : unsigned_fract_type_node
;
3536 if (mode
== TYPE_MODE (unsigned_long_fract_type_node
))
3537 return unsignedp
? sat_unsigned_long_fract_type_node
3538 : unsigned_long_fract_type_node
;
3539 if (mode
== TYPE_MODE (unsigned_long_long_fract_type_node
))
3540 return unsignedp
? sat_unsigned_long_long_fract_type_node
3541 : unsigned_long_long_fract_type_node
;
3543 if (mode
== TYPE_MODE (short_accum_type_node
))
3544 return unsignedp
? sat_short_accum_type_node
: short_accum_type_node
;
3545 if (mode
== TYPE_MODE (accum_type_node
))
3546 return unsignedp
? sat_accum_type_node
: accum_type_node
;
3547 if (mode
== TYPE_MODE (long_accum_type_node
))
3548 return unsignedp
? sat_long_accum_type_node
: long_accum_type_node
;
3549 if (mode
== TYPE_MODE (long_long_accum_type_node
))
3550 return unsignedp
? sat_long_long_accum_type_node
3551 : long_long_accum_type_node
;
3553 if (mode
== TYPE_MODE (unsigned_short_accum_type_node
))
3554 return unsignedp
? sat_unsigned_short_accum_type_node
3555 : unsigned_short_accum_type_node
;
3556 if (mode
== TYPE_MODE (unsigned_accum_type_node
))
3557 return unsignedp
? sat_unsigned_accum_type_node
3558 : unsigned_accum_type_node
;
3559 if (mode
== TYPE_MODE (unsigned_long_accum_type_node
))
3560 return unsignedp
? sat_unsigned_long_accum_type_node
3561 : unsigned_long_accum_type_node
;
3562 if (mode
== TYPE_MODE (unsigned_long_long_accum_type_node
))
3563 return unsignedp
? sat_unsigned_long_long_accum_type_node
3564 : unsigned_long_long_accum_type_node
;
3567 return unsignedp
? sat_qq_type_node
: qq_type_node
;
3569 return unsignedp
? sat_hq_type_node
: hq_type_node
;
3571 return unsignedp
? sat_sq_type_node
: sq_type_node
;
3573 return unsignedp
? sat_dq_type_node
: dq_type_node
;
3575 return unsignedp
? sat_tq_type_node
: tq_type_node
;
3577 if (mode
== UQQmode
)
3578 return unsignedp
? sat_uqq_type_node
: uqq_type_node
;
3579 if (mode
== UHQmode
)
3580 return unsignedp
? sat_uhq_type_node
: uhq_type_node
;
3581 if (mode
== USQmode
)
3582 return unsignedp
? sat_usq_type_node
: usq_type_node
;
3583 if (mode
== UDQmode
)
3584 return unsignedp
? sat_udq_type_node
: udq_type_node
;
3585 if (mode
== UTQmode
)
3586 return unsignedp
? sat_utq_type_node
: utq_type_node
;
3589 return unsignedp
? sat_ha_type_node
: ha_type_node
;
3591 return unsignedp
? sat_sa_type_node
: sa_type_node
;
3593 return unsignedp
? sat_da_type_node
: da_type_node
;
3595 return unsignedp
? sat_ta_type_node
: ta_type_node
;
3597 if (mode
== UHAmode
)
3598 return unsignedp
? sat_uha_type_node
: uha_type_node
;
3599 if (mode
== USAmode
)
3600 return unsignedp
? sat_usa_type_node
: usa_type_node
;
3601 if (mode
== UDAmode
)
3602 return unsignedp
? sat_uda_type_node
: uda_type_node
;
3603 if (mode
== UTAmode
)
3604 return unsignedp
? sat_uta_type_node
: uta_type_node
;
3607 for (t
= registered_builtin_types
; t
; t
= TREE_CHAIN (t
))
3608 if (TYPE_MODE (TREE_VALUE (t
)) == mode
3609 && !!unsignedp
== !!TYPE_UNSIGNED (TREE_VALUE (t
)))
3610 return TREE_VALUE (t
);
3616 c_common_unsigned_type (tree type
)
3618 return c_common_signed_or_unsigned_type (1, type
);
3621 /* Return a signed type the same as TYPE in other respects. */
3624 c_common_signed_type (tree type
)
3626 return c_common_signed_or_unsigned_type (0, type
);
3629 /* Return a type the same as TYPE except unsigned or
3630 signed according to UNSIGNEDP. */
3633 c_common_signed_or_unsigned_type (int unsignedp
, tree type
)
3637 /* This block of code emulates the behavior of the old
3638 c_common_unsigned_type. In particular, it returns
3639 long_unsigned_type_node if passed a long, even when a int would
3640 have the same size. This is necessary for warnings to work
3641 correctly in archs where sizeof(int) == sizeof(long) */
3643 type1
= TYPE_MAIN_VARIANT (type
);
3644 if (type1
== signed_char_type_node
|| type1
== char_type_node
|| type1
== unsigned_char_type_node
)
3645 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3646 if (type1
== integer_type_node
|| type1
== unsigned_type_node
)
3647 return unsignedp
? unsigned_type_node
: integer_type_node
;
3648 if (type1
== short_integer_type_node
|| type1
== short_unsigned_type_node
)
3649 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3650 if (type1
== long_integer_type_node
|| type1
== long_unsigned_type_node
)
3651 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3652 if (type1
== long_long_integer_type_node
|| type1
== long_long_unsigned_type_node
)
3653 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3654 if (int128_integer_type_node
3655 && (type1
== int128_integer_type_node
3656 || type1
== int128_unsigned_type_node
))
3657 return unsignedp
? int128_unsigned_type_node
: int128_integer_type_node
;
3658 if (type1
== widest_integer_literal_type_node
|| type1
== widest_unsigned_literal_type_node
)
3659 return unsignedp
? widest_unsigned_literal_type_node
: widest_integer_literal_type_node
;
3660 #if HOST_BITS_PER_WIDE_INT >= 64
3661 if (type1
== intTI_type_node
|| type1
== unsigned_intTI_type_node
)
3662 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3664 if (type1
== intDI_type_node
|| type1
== unsigned_intDI_type_node
)
3665 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3666 if (type1
== intSI_type_node
|| type1
== unsigned_intSI_type_node
)
3667 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3668 if (type1
== intHI_type_node
|| type1
== unsigned_intHI_type_node
)
3669 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3670 if (type1
== intQI_type_node
|| type1
== unsigned_intQI_type_node
)
3671 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3673 #define C_COMMON_FIXED_TYPES(NAME) \
3674 if (type1 == short_ ## NAME ## _type_node \
3675 || type1 == unsigned_short_ ## NAME ## _type_node) \
3676 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
3677 : short_ ## NAME ## _type_node; \
3678 if (type1 == NAME ## _type_node \
3679 || type1 == unsigned_ ## NAME ## _type_node) \
3680 return unsignedp ? unsigned_ ## NAME ## _type_node \
3681 : NAME ## _type_node; \
3682 if (type1 == long_ ## NAME ## _type_node \
3683 || type1 == unsigned_long_ ## NAME ## _type_node) \
3684 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
3685 : long_ ## NAME ## _type_node; \
3686 if (type1 == long_long_ ## NAME ## _type_node \
3687 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
3688 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
3689 : long_long_ ## NAME ## _type_node;
3691 #define C_COMMON_FIXED_MODE_TYPES(NAME) \
3692 if (type1 == NAME ## _type_node \
3693 || type1 == u ## NAME ## _type_node) \
3694 return unsignedp ? u ## NAME ## _type_node \
3695 : NAME ## _type_node;
3697 #define C_COMMON_FIXED_TYPES_SAT(NAME) \
3698 if (type1 == sat_ ## short_ ## NAME ## _type_node \
3699 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
3700 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
3701 : sat_ ## short_ ## NAME ## _type_node; \
3702 if (type1 == sat_ ## NAME ## _type_node \
3703 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
3704 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
3705 : sat_ ## NAME ## _type_node; \
3706 if (type1 == sat_ ## long_ ## NAME ## _type_node \
3707 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
3708 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
3709 : sat_ ## long_ ## NAME ## _type_node; \
3710 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
3711 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
3712 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
3713 : sat_ ## long_long_ ## NAME ## _type_node;
3715 #define C_COMMON_FIXED_MODE_TYPES_SAT(NAME) \
3716 if (type1 == sat_ ## NAME ## _type_node \
3717 || type1 == sat_ ## u ## NAME ## _type_node) \
3718 return unsignedp ? sat_ ## u ## NAME ## _type_node \
3719 : sat_ ## NAME ## _type_node;
3721 C_COMMON_FIXED_TYPES (fract
);
3722 C_COMMON_FIXED_TYPES_SAT (fract
);
3723 C_COMMON_FIXED_TYPES (accum
);
3724 C_COMMON_FIXED_TYPES_SAT (accum
);
3726 C_COMMON_FIXED_MODE_TYPES (qq
);
3727 C_COMMON_FIXED_MODE_TYPES (hq
);
3728 C_COMMON_FIXED_MODE_TYPES (sq
);
3729 C_COMMON_FIXED_MODE_TYPES (dq
);
3730 C_COMMON_FIXED_MODE_TYPES (tq
);
3731 C_COMMON_FIXED_MODE_TYPES_SAT (qq
);
3732 C_COMMON_FIXED_MODE_TYPES_SAT (hq
);
3733 C_COMMON_FIXED_MODE_TYPES_SAT (sq
);
3734 C_COMMON_FIXED_MODE_TYPES_SAT (dq
);
3735 C_COMMON_FIXED_MODE_TYPES_SAT (tq
);
3736 C_COMMON_FIXED_MODE_TYPES (ha
);
3737 C_COMMON_FIXED_MODE_TYPES (sa
);
3738 C_COMMON_FIXED_MODE_TYPES (da
);
3739 C_COMMON_FIXED_MODE_TYPES (ta
);
3740 C_COMMON_FIXED_MODE_TYPES_SAT (ha
);
3741 C_COMMON_FIXED_MODE_TYPES_SAT (sa
);
3742 C_COMMON_FIXED_MODE_TYPES_SAT (da
);
3743 C_COMMON_FIXED_MODE_TYPES_SAT (ta
);
3745 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
3746 the precision; they have precision set to match their range, but
3747 may use a wider mode to match an ABI. If we change modes, we may
3748 wind up with bad conversions. For INTEGER_TYPEs in C, must check
3749 the precision as well, so as to yield correct results for
3750 bit-field types. C++ does not have these separate bit-field
3751 types, and producing a signed or unsigned variant of an
3752 ENUMERAL_TYPE may cause other problems as well. */
3754 if (!INTEGRAL_TYPE_P (type
)
3755 || TYPE_UNSIGNED (type
) == unsignedp
)
3758 #define TYPE_OK(node) \
3759 (TYPE_MODE (type) == TYPE_MODE (node) \
3760 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
3761 if (TYPE_OK (signed_char_type_node
))
3762 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3763 if (TYPE_OK (integer_type_node
))
3764 return unsignedp
? unsigned_type_node
: integer_type_node
;
3765 if (TYPE_OK (short_integer_type_node
))
3766 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3767 if (TYPE_OK (long_integer_type_node
))
3768 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3769 if (TYPE_OK (long_long_integer_type_node
))
3770 return (unsignedp
? long_long_unsigned_type_node
3771 : long_long_integer_type_node
);
3772 if (int128_integer_type_node
&& TYPE_OK (int128_integer_type_node
))
3773 return (unsignedp
? int128_unsigned_type_node
3774 : int128_integer_type_node
);
3775 if (TYPE_OK (widest_integer_literal_type_node
))
3776 return (unsignedp
? widest_unsigned_literal_type_node
3777 : widest_integer_literal_type_node
);
3779 #if HOST_BITS_PER_WIDE_INT >= 64
3780 if (TYPE_OK (intTI_type_node
))
3781 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3783 if (TYPE_OK (intDI_type_node
))
3784 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3785 if (TYPE_OK (intSI_type_node
))
3786 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3787 if (TYPE_OK (intHI_type_node
))
3788 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3789 if (TYPE_OK (intQI_type_node
))
3790 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3793 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
3796 /* Build a bit-field integer type for the given WIDTH and UNSIGNEDP. */
3799 c_build_bitfield_integer_type (unsigned HOST_WIDE_INT width
, int unsignedp
)
3801 /* Extended integer types of the same width as a standard type have
3802 lesser rank, so those of the same width as int promote to int or
3803 unsigned int and are valid for printf formats expecting int or
3804 unsigned int. To avoid such special cases, avoid creating
3805 extended integer types for bit-fields if a standard integer type
3807 if (width
== TYPE_PRECISION (integer_type_node
))
3808 return unsignedp
? unsigned_type_node
: integer_type_node
;
3809 if (width
== TYPE_PRECISION (signed_char_type_node
))
3810 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3811 if (width
== TYPE_PRECISION (short_integer_type_node
))
3812 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3813 if (width
== TYPE_PRECISION (long_integer_type_node
))
3814 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3815 if (width
== TYPE_PRECISION (long_long_integer_type_node
))
3816 return (unsignedp
? long_long_unsigned_type_node
3817 : long_long_integer_type_node
);
3818 if (int128_integer_type_node
3819 && width
== TYPE_PRECISION (int128_integer_type_node
))
3820 return (unsignedp
? int128_unsigned_type_node
3821 : int128_integer_type_node
);
3822 return build_nonstandard_integer_type (width
, unsignedp
);
3825 /* The C version of the register_builtin_type langhook. */
3828 c_register_builtin_type (tree type
, const char* name
)
3832 decl
= build_decl (UNKNOWN_LOCATION
,
3833 TYPE_DECL
, get_identifier (name
), type
);
3834 DECL_ARTIFICIAL (decl
) = 1;
3835 if (!TYPE_NAME (type
))
3836 TYPE_NAME (type
) = decl
;
3839 registered_builtin_types
= tree_cons (0, type
, registered_builtin_types
);
3842 /* Print an error message for invalid operands to arith operation
3843 CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
3844 LOCATION is the location of the message. */
3847 binary_op_error (location_t location
, enum tree_code code
,
3848 tree type0
, tree type1
)
3855 opname
= "+"; break;
3857 opname
= "-"; break;
3859 opname
= "*"; break;
3861 opname
= "max"; break;
3863 opname
= "min"; break;
3865 opname
= "=="; break;
3867 opname
= "!="; break;
3869 opname
= "<="; break;
3871 opname
= ">="; break;
3873 opname
= "<"; break;
3875 opname
= ">"; break;
3877 opname
= "<<"; break;
3879 opname
= ">>"; break;
3880 case TRUNC_MOD_EXPR
:
3881 case FLOOR_MOD_EXPR
:
3882 opname
= "%"; break;
3883 case TRUNC_DIV_EXPR
:
3884 case FLOOR_DIV_EXPR
:
3885 opname
= "/"; break;
3887 opname
= "&"; break;
3889 opname
= "|"; break;
3890 case TRUTH_ANDIF_EXPR
:
3891 opname
= "&&"; break;
3892 case TRUTH_ORIF_EXPR
:
3893 opname
= "||"; break;
3895 opname
= "^"; break;
3900 "invalid operands to binary %s (have %qT and %qT)", opname
,
3904 /* Given an expression as a tree, return its original type. Do this
3905 by stripping any conversion that preserves the sign and precision. */
3907 expr_original_type (tree expr
)
3909 STRIP_SIGN_NOPS (expr
);
3910 return TREE_TYPE (expr
);
3913 /* Subroutine of build_binary_op, used for comparison operations.
3914 See if the operands have both been converted from subword integer types
3915 and, if so, perhaps change them both back to their original type.
3916 This function is also responsible for converting the two operands
3917 to the proper common type for comparison.
3919 The arguments of this function are all pointers to local variables
3920 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
3921 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
3923 If this function returns nonzero, it means that the comparison has
3924 a constant value. What this function returns is an expression for
3928 shorten_compare (tree
*op0_ptr
, tree
*op1_ptr
, tree
*restype_ptr
,
3929 enum tree_code
*rescode_ptr
)
3932 tree op0
= *op0_ptr
;
3933 tree op1
= *op1_ptr
;
3934 int unsignedp0
, unsignedp1
;
3936 tree primop0
, primop1
;
3937 enum tree_code code
= *rescode_ptr
;
3938 location_t loc
= EXPR_LOC_OR_HERE (op0
);
3940 /* Throw away any conversions to wider types
3941 already present in the operands. */
3943 primop0
= c_common_get_narrower (op0
, &unsignedp0
);
3944 primop1
= c_common_get_narrower (op1
, &unsignedp1
);
3946 /* If primopN is first sign-extended from primopN's precision to opN's
3947 precision, then zero-extended from opN's precision to
3948 *restype_ptr precision, shortenings might be invalid. */
3949 if (TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (TREE_TYPE (op0
))
3950 && TYPE_PRECISION (TREE_TYPE (op0
)) < TYPE_PRECISION (*restype_ptr
)
3952 && TYPE_UNSIGNED (TREE_TYPE (op0
)))
3954 if (TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (TREE_TYPE (op1
))
3955 && TYPE_PRECISION (TREE_TYPE (op1
)) < TYPE_PRECISION (*restype_ptr
)
3957 && TYPE_UNSIGNED (TREE_TYPE (op1
)))
3960 /* Handle the case that OP0 does not *contain* a conversion
3961 but it *requires* conversion to FINAL_TYPE. */
3963 if (op0
== primop0
&& TREE_TYPE (op0
) != *restype_ptr
)
3964 unsignedp0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
3965 if (op1
== primop1
&& TREE_TYPE (op1
) != *restype_ptr
)
3966 unsignedp1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
3968 /* If one of the operands must be floated, we cannot optimize. */
3969 real1
= TREE_CODE (TREE_TYPE (primop0
)) == REAL_TYPE
;
3970 real2
= TREE_CODE (TREE_TYPE (primop1
)) == REAL_TYPE
;
3972 /* If first arg is constant, swap the args (changing operation
3973 so value is preserved), for canonicalization. Don't do this if
3974 the second arg is 0. */
3976 if (TREE_CONSTANT (primop0
)
3977 && !integer_zerop (primop1
) && !real_zerop (primop1
)
3978 && !fixed_zerop (primop1
))
3981 int temi
= unsignedp0
;
3989 unsignedp0
= unsignedp1
;
4012 *rescode_ptr
= code
;
4015 /* If comparing an integer against a constant more bits wide,
4016 maybe we can deduce a value of 1 or 0 independent of the data.
4017 Or else truncate the constant now
4018 rather than extend the variable at run time.
4020 This is only interesting if the constant is the wider arg.
4021 Also, it is not safe if the constant is unsigned and the
4022 variable arg is signed, since in this case the variable
4023 would be sign-extended and then regarded as unsigned.
4024 Our technique fails in this case because the lowest/highest
4025 possible unsigned results don't follow naturally from the
4026 lowest/highest possible values of the variable operand.
4027 For just EQ_EXPR and NE_EXPR there is another technique that
4028 could be used: see if the constant can be faithfully represented
4029 in the other operand's type, by truncating it and reextending it
4030 and see if that preserves the constant's value. */
4032 if (!real1
&& !real2
4033 && TREE_CODE (TREE_TYPE (primop0
)) != FIXED_POINT_TYPE
4034 && TREE_CODE (primop1
) == INTEGER_CST
4035 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
))
4037 int min_gt
, max_gt
, min_lt
, max_lt
;
4038 tree maxval
, minval
;
4039 /* 1 if comparison is nominally unsigned. */
4040 int unsignedp
= TYPE_UNSIGNED (*restype_ptr
);
4043 type
= c_common_signed_or_unsigned_type (unsignedp0
,
4044 TREE_TYPE (primop0
));
4046 maxval
= TYPE_MAX_VALUE (type
);
4047 minval
= TYPE_MIN_VALUE (type
);
4049 if (unsignedp
&& !unsignedp0
)
4050 *restype_ptr
= c_common_signed_type (*restype_ptr
);
4052 if (TREE_TYPE (primop1
) != *restype_ptr
)
4054 /* Convert primop1 to target type, but do not introduce
4055 additional overflow. We know primop1 is an int_cst. */
4056 primop1
= force_fit_type (*restype_ptr
,
4057 wide_int (primop1
).force_to_size (TYPE_PRECISION (*restype_ptr
),
4058 TYPE_SIGN (TREE_TYPE (primop1
))),
4059 0, TREE_OVERFLOW (primop1
));
4061 if (type
!= *restype_ptr
)
4063 minval
= convert (*restype_ptr
, minval
);
4064 maxval
= convert (*restype_ptr
, maxval
);
4067 if (unsignedp
&& unsignedp0
)
4069 min_gt
= INT_CST_LT_UNSIGNED (primop1
, minval
);
4070 max_gt
= INT_CST_LT_UNSIGNED (primop1
, maxval
);
4071 min_lt
= INT_CST_LT_UNSIGNED (minval
, primop1
);
4072 max_lt
= INT_CST_LT_UNSIGNED (maxval
, primop1
);
4076 min_gt
= INT_CST_LT (primop1
, minval
);
4077 max_gt
= INT_CST_LT (primop1
, maxval
);
4078 min_lt
= INT_CST_LT (minval
, primop1
);
4079 max_lt
= INT_CST_LT (maxval
, primop1
);
4083 /* This used to be a switch, but Genix compiler can't handle that. */
4084 if (code
== NE_EXPR
)
4086 if (max_lt
|| min_gt
)
4087 val
= truthvalue_true_node
;
4089 else if (code
== EQ_EXPR
)
4091 if (max_lt
|| min_gt
)
4092 val
= truthvalue_false_node
;
4094 else if (code
== LT_EXPR
)
4097 val
= truthvalue_true_node
;
4099 val
= truthvalue_false_node
;
4101 else if (code
== GT_EXPR
)
4104 val
= truthvalue_true_node
;
4106 val
= truthvalue_false_node
;
4108 else if (code
== LE_EXPR
)
4111 val
= truthvalue_true_node
;
4113 val
= truthvalue_false_node
;
4115 else if (code
== GE_EXPR
)
4118 val
= truthvalue_true_node
;
4120 val
= truthvalue_false_node
;
4123 /* If primop0 was sign-extended and unsigned comparison specd,
4124 we did a signed comparison above using the signed type bounds.
4125 But the comparison we output must be unsigned.
4127 Also, for inequalities, VAL is no good; but if the signed
4128 comparison had *any* fixed result, it follows that the
4129 unsigned comparison just tests the sign in reverse
4130 (positive values are LE, negative ones GE).
4131 So we can generate an unsigned comparison
4132 against an extreme value of the signed type. */
4134 if (unsignedp
&& !unsignedp0
)
4141 primop1
= TYPE_MIN_VALUE (type
);
4147 primop1
= TYPE_MAX_VALUE (type
);
4154 type
= c_common_unsigned_type (type
);
4157 if (TREE_CODE (primop0
) != INTEGER_CST
4158 && c_inhibit_evaluation_warnings
== 0)
4160 if (val
== truthvalue_false_node
)
4161 warning_at (loc
, OPT_Wtype_limits
,
4162 "comparison is always false due to limited range of data type");
4163 if (val
== truthvalue_true_node
)
4164 warning_at (loc
, OPT_Wtype_limits
,
4165 "comparison is always true due to limited range of data type");
4170 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4171 if (TREE_SIDE_EFFECTS (primop0
))
4172 return build2 (COMPOUND_EXPR
, TREE_TYPE (val
), primop0
, val
);
4176 /* Value is not predetermined, but do the comparison
4177 in the type of the operand that is not constant.
4178 TYPE is already properly set. */
4181 /* If either arg is decimal float and the other is float, find the
4182 proper common type to use for comparison. */
4183 else if (real1
&& real2
4184 && (DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0
)))
4185 || DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1
)))))
4186 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
4188 else if (real1
&& real2
4189 && (TYPE_PRECISION (TREE_TYPE (primop0
))
4190 == TYPE_PRECISION (TREE_TYPE (primop1
))))
4191 type
= TREE_TYPE (primop0
);
4193 /* If args' natural types are both narrower than nominal type
4194 and both extend in the same manner, compare them
4195 in the type of the wider arg.
4196 Otherwise must actually extend both to the nominal
4197 common type lest different ways of extending
4199 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
4201 else if (unsignedp0
== unsignedp1
&& real1
== real2
4202 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
)
4203 && TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (*restype_ptr
))
4205 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
4206 type
= c_common_signed_or_unsigned_type (unsignedp0
4207 || TYPE_UNSIGNED (*restype_ptr
),
4209 /* Make sure shorter operand is extended the right way
4210 to match the longer operand. */
4212 = convert (c_common_signed_or_unsigned_type (unsignedp0
,
4213 TREE_TYPE (primop0
)),
4216 = convert (c_common_signed_or_unsigned_type (unsignedp1
,
4217 TREE_TYPE (primop1
)),
4222 /* Here we must do the comparison on the nominal type
4223 using the args exactly as we received them. */
4224 type
= *restype_ptr
;
4228 if (!real1
&& !real2
&& integer_zerop (primop1
)
4229 && TYPE_UNSIGNED (*restype_ptr
))
4232 /* All unsigned values are >= 0, so we warn. However,
4233 if OP0 is a constant that is >= 0, the signedness of
4234 the comparison isn't an issue, so suppress the
4237 warn_type_limits
&& !in_system_header
4238 && c_inhibit_evaluation_warnings
== 0
4239 && !(TREE_CODE (primop0
) == INTEGER_CST
4240 && !TREE_OVERFLOW (convert (c_common_signed_type (type
),
4242 /* Do not warn for enumeration types. */
4243 && (TREE_CODE (expr_original_type (primop0
)) != ENUMERAL_TYPE
);
4249 warning_at (loc
, OPT_Wtype_limits
,
4250 "comparison of unsigned expression >= 0 is always true");
4251 value
= truthvalue_true_node
;
4256 warning_at (loc
, OPT_Wtype_limits
,
4257 "comparison of unsigned expression < 0 is always false");
4258 value
= truthvalue_false_node
;
4267 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4268 if (TREE_SIDE_EFFECTS (primop0
))
4269 return build2 (COMPOUND_EXPR
, TREE_TYPE (value
),
4276 *op0_ptr
= convert (type
, primop0
);
4277 *op1_ptr
= convert (type
, primop1
);
4279 *restype_ptr
= truthvalue_type_node
;
4284 /* Return a tree for the sum or difference (RESULTCODE says which)
4285 of pointer PTROP and integer INTOP. */
4288 pointer_int_sum (location_t loc
, enum tree_code resultcode
,
4289 tree ptrop
, tree intop
, bool complain
)
4293 /* The result is a pointer of the same type that is being added. */
4294 tree result_type
= TREE_TYPE (ptrop
);
4296 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
4298 if (complain
&& warn_pointer_arith
)
4299 pedwarn (loc
, OPT_Wpointer_arith
,
4300 "pointer of type %<void *%> used in arithmetic");
4302 return error_mark_node
;
4303 size_exp
= integer_one_node
;
4305 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
4307 if (complain
&& warn_pointer_arith
)
4308 pedwarn (loc
, OPT_Wpointer_arith
,
4309 "pointer to a function used in arithmetic");
4311 return error_mark_node
;
4312 size_exp
= integer_one_node
;
4315 size_exp
= size_in_bytes (TREE_TYPE (result_type
));
4317 /* We are manipulating pointer values, so we don't need to warn
4318 about relying on undefined signed overflow. We disable the
4319 warning here because we use integer types so fold won't know that
4320 they are really pointers. */
4321 fold_defer_overflow_warnings ();
4323 /* If what we are about to multiply by the size of the elements
4324 contains a constant term, apply distributive law
4325 and multiply that constant term separately.
4326 This helps produce common subexpressions. */
4327 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
4328 && !TREE_CONSTANT (intop
)
4329 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
4330 && TREE_CONSTANT (size_exp
)
4331 /* If the constant comes from pointer subtraction,
4332 skip this optimization--it would cause an error. */
4333 && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop
, 0))) == INTEGER_TYPE
4334 /* If the constant is unsigned, and smaller than the pointer size,
4335 then we must skip this optimization. This is because it could cause
4336 an overflow error if the constant is negative but INTOP is not. */
4337 && (!TYPE_UNSIGNED (TREE_TYPE (intop
))
4338 || (TYPE_PRECISION (TREE_TYPE (intop
))
4339 == TYPE_PRECISION (TREE_TYPE (ptrop
)))))
4341 enum tree_code subcode
= resultcode
;
4342 tree int_type
= TREE_TYPE (intop
);
4343 if (TREE_CODE (intop
) == MINUS_EXPR
)
4344 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
4345 /* Convert both subexpression types to the type of intop,
4346 because weird cases involving pointer arithmetic
4347 can result in a sum or difference with different type args. */
4348 ptrop
= build_binary_op (EXPR_LOCATION (TREE_OPERAND (intop
, 1)),
4350 convert (int_type
, TREE_OPERAND (intop
, 1)), 1);
4351 intop
= convert (int_type
, TREE_OPERAND (intop
, 0));
4354 /* Convert the integer argument to a type the same size as sizetype
4355 so the multiply won't overflow spuriously. */
4356 if (TYPE_PRECISION (TREE_TYPE (intop
)) != TYPE_PRECISION (sizetype
)
4357 || TYPE_UNSIGNED (TREE_TYPE (intop
)) != TYPE_UNSIGNED (sizetype
))
4358 intop
= convert (c_common_type_for_size (TYPE_PRECISION (sizetype
),
4359 TYPE_UNSIGNED (sizetype
)), intop
);
4361 /* Replace the integer argument with a suitable product by the object size.
4362 Do this multiplication as signed, then convert to the appropriate type
4363 for the pointer operation and disregard an overflow that occurred only
4364 because of the sign-extension change in the latter conversion. */
4366 tree t
= build_binary_op (loc
,
4368 convert (TREE_TYPE (intop
), size_exp
), 1);
4369 intop
= convert (sizetype
, t
);
4370 if (TREE_OVERFLOW_P (intop
) && !TREE_OVERFLOW (t
))
4371 intop
= wide_int_to_tree (TREE_TYPE (intop
), intop
);
4374 /* Create the sum or difference. */
4375 if (resultcode
== MINUS_EXPR
)
4376 intop
= fold_build1_loc (loc
, NEGATE_EXPR
, sizetype
, intop
);
4378 ret
= fold_build_pointer_plus_loc (loc
, ptrop
, intop
);
4380 fold_undefer_and_ignore_overflow_warnings ();
4385 /* Wrap a C_MAYBE_CONST_EXPR around an expression that is fully folded
4386 and if NON_CONST is known not to be permitted in an evaluated part
4387 of a constant expression. */
4390 c_wrap_maybe_const (tree expr
, bool non_const
)
4392 bool nowarning
= TREE_NO_WARNING (expr
);
4393 location_t loc
= EXPR_LOCATION (expr
);
4395 /* This should never be called for C++. */
4396 if (c_dialect_cxx ())
4399 /* The result of folding may have a NOP_EXPR to set TREE_NO_WARNING. */
4400 STRIP_TYPE_NOPS (expr
);
4401 expr
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (expr
), NULL
, expr
);
4402 C_MAYBE_CONST_EXPR_NON_CONST (expr
) = non_const
;
4404 TREE_NO_WARNING (expr
) = 1;
4405 protected_set_expr_location (expr
, loc
);
4410 /* Wrap a SAVE_EXPR around EXPR, if appropriate. Like save_expr, but
4411 for C folds the inside expression and wraps a C_MAYBE_CONST_EXPR
4412 around the SAVE_EXPR if needed so that c_fully_fold does not need
4413 to look inside SAVE_EXPRs. */
4416 c_save_expr (tree expr
)
4418 bool maybe_const
= true;
4419 if (c_dialect_cxx ())
4420 return save_expr (expr
);
4421 expr
= c_fully_fold (expr
, false, &maybe_const
);
4422 expr
= save_expr (expr
);
4424 expr
= c_wrap_maybe_const (expr
, true);
4428 /* Return whether EXPR is a declaration whose address can never be
4432 decl_with_nonnull_addr_p (const_tree expr
)
4434 return (DECL_P (expr
)
4435 && (TREE_CODE (expr
) == PARM_DECL
4436 || TREE_CODE (expr
) == LABEL_DECL
4437 || !DECL_WEAK (expr
)));
4440 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
4441 or for an `if' or `while' statement or ?..: exp. It should already
4442 have been validated to be of suitable type; otherwise, a bad
4443 diagnostic may result.
4445 The EXPR is located at LOCATION.
4447 This preparation consists of taking the ordinary
4448 representation of an expression expr and producing a valid tree
4449 boolean expression describing whether expr is nonzero. We could
4450 simply always do build_binary_op (NE_EXPR, expr, truthvalue_false_node, 1),
4451 but we optimize comparisons, &&, ||, and !.
4453 The resulting type should always be `truthvalue_type_node'. */
4456 c_common_truthvalue_conversion (location_t location
, tree expr
)
4458 switch (TREE_CODE (expr
))
4460 case EQ_EXPR
: case NE_EXPR
: case UNEQ_EXPR
: case LTGT_EXPR
:
4461 case LE_EXPR
: case GE_EXPR
: case LT_EXPR
: case GT_EXPR
:
4462 case UNLE_EXPR
: case UNGE_EXPR
: case UNLT_EXPR
: case UNGT_EXPR
:
4463 case ORDERED_EXPR
: case UNORDERED_EXPR
:
4464 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4466 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4467 TREE_OPERAND (expr
, 0), TREE_OPERAND (expr
, 1));
4470 case TRUTH_ANDIF_EXPR
:
4471 case TRUTH_ORIF_EXPR
:
4472 case TRUTH_AND_EXPR
:
4474 case TRUTH_XOR_EXPR
:
4475 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4477 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4478 c_common_truthvalue_conversion (location
,
4479 TREE_OPERAND (expr
, 0)),
4480 c_common_truthvalue_conversion (location
,
4481 TREE_OPERAND (expr
, 1)));
4484 case TRUTH_NOT_EXPR
:
4485 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4487 expr
= build1 (TREE_CODE (expr
), truthvalue_type_node
,
4488 c_common_truthvalue_conversion (location
,
4489 TREE_OPERAND (expr
, 0)));
4496 return integer_zerop (expr
) ? truthvalue_false_node
4497 : truthvalue_true_node
;
4500 return real_compare (NE_EXPR
, &TREE_REAL_CST (expr
), &dconst0
)
4501 ? truthvalue_true_node
4502 : truthvalue_false_node
;
4505 return fixed_compare (NE_EXPR
, &TREE_FIXED_CST (expr
),
4506 &FCONST0 (TYPE_MODE (TREE_TYPE (expr
))))
4507 ? truthvalue_true_node
4508 : truthvalue_false_node
;
4511 expr
= build_unary_op (location
, ADDR_EXPR
, expr
, 0);
4516 tree inner
= TREE_OPERAND (expr
, 0);
4517 if (decl_with_nonnull_addr_p (inner
))
4519 /* Common Ada/Pascal programmer's mistake. */
4520 warning_at (location
,
4522 "the address of %qD will always evaluate as %<true%>",
4524 return truthvalue_true_node
;
4530 expr
= build_binary_op (EXPR_LOCATION (expr
),
4531 (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1))
4532 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4533 c_common_truthvalue_conversion (location
,
4534 TREE_OPERAND (expr
, 0)),
4535 c_common_truthvalue_conversion (location
,
4536 TREE_OPERAND (expr
, 1)),
4543 case EXCESS_PRECISION_EXPR
:
4544 /* These don't change whether an object is nonzero or zero. */
4545 return c_common_truthvalue_conversion (location
, TREE_OPERAND (expr
, 0));
4549 /* These don't change whether an object is zero or nonzero, but
4550 we can't ignore them if their second arg has side-effects. */
4551 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1)))
4553 expr
= build2 (COMPOUND_EXPR
, truthvalue_type_node
,
4554 TREE_OPERAND (expr
, 1),
4555 c_common_truthvalue_conversion
4556 (location
, TREE_OPERAND (expr
, 0)));
4560 return c_common_truthvalue_conversion (location
,
4561 TREE_OPERAND (expr
, 0));
4564 /* Distribute the conversion into the arms of a COND_EXPR. */
4565 if (c_dialect_cxx ())
4567 tree op1
= TREE_OPERAND (expr
, 1);
4568 tree op2
= TREE_OPERAND (expr
, 2);
4569 /* In C++ one of the arms might have void type if it is throw. */
4570 if (!VOID_TYPE_P (TREE_TYPE (op1
)))
4571 op1
= c_common_truthvalue_conversion (location
, op1
);
4572 if (!VOID_TYPE_P (TREE_TYPE (op2
)))
4573 op2
= c_common_truthvalue_conversion (location
, op2
);
4574 expr
= fold_build3_loc (location
, COND_EXPR
, truthvalue_type_node
,
4575 TREE_OPERAND (expr
, 0), op1
, op2
);
4580 /* Folding will happen later for C. */
4581 expr
= build3 (COND_EXPR
, truthvalue_type_node
,
4582 TREE_OPERAND (expr
, 0),
4583 c_common_truthvalue_conversion (location
,
4584 TREE_OPERAND (expr
, 1)),
4585 c_common_truthvalue_conversion (location
,
4586 TREE_OPERAND (expr
, 2)));
4592 tree totype
= TREE_TYPE (expr
);
4593 tree fromtype
= TREE_TYPE (TREE_OPERAND (expr
, 0));
4595 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
4596 since that affects how `default_conversion' will behave. */
4597 if (TREE_CODE (totype
) == REFERENCE_TYPE
4598 || TREE_CODE (fromtype
) == REFERENCE_TYPE
)
4600 /* Don't strip a conversion from C++0x scoped enum, since they
4601 don't implicitly convert to other types. */
4602 if (TREE_CODE (fromtype
) == ENUMERAL_TYPE
4603 && ENUM_IS_SCOPED (fromtype
))
4605 /* If this isn't narrowing the argument, we can ignore it. */
4606 if (TYPE_PRECISION (totype
) >= TYPE_PRECISION (fromtype
))
4607 return c_common_truthvalue_conversion (location
,
4608 TREE_OPERAND (expr
, 0));
4613 if (!TREE_NO_WARNING (expr
)
4614 && warn_parentheses
)
4616 warning (OPT_Wparentheses
,
4617 "suggest parentheses around assignment used as truth value");
4618 TREE_NO_WARNING (expr
) = 1;
4626 if (TREE_CODE (TREE_TYPE (expr
)) == COMPLEX_TYPE
)
4628 tree t
= (in_late_binary_op
? save_expr (expr
) : c_save_expr (expr
));
4629 expr
= (build_binary_op
4630 (EXPR_LOCATION (expr
),
4631 (TREE_SIDE_EFFECTS (expr
)
4632 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4633 c_common_truthvalue_conversion
4635 build_unary_op (location
, REALPART_EXPR
, t
, 0)),
4636 c_common_truthvalue_conversion
4638 build_unary_op (location
, IMAGPART_EXPR
, t
, 0)),
4643 if (TREE_CODE (TREE_TYPE (expr
)) == FIXED_POINT_TYPE
)
4645 tree fixed_zero_node
= build_fixed (TREE_TYPE (expr
),
4647 (TREE_TYPE (expr
))));
4648 return build_binary_op (location
, NE_EXPR
, expr
, fixed_zero_node
, 1);
4651 return build_binary_op (location
, NE_EXPR
, expr
, integer_zero_node
, 1);
4654 protected_set_expr_location (expr
, location
);
4658 static void def_builtin_1 (enum built_in_function fncode
,
4660 enum built_in_class fnclass
,
4661 tree fntype
, tree libtype
,
4662 bool both_p
, bool fallback_p
, bool nonansi_p
,
4663 tree fnattrs
, bool implicit_p
);
4666 /* Apply the TYPE_QUALS to the new DECL. */
4669 c_apply_type_quals_to_decl (int type_quals
, tree decl
)
4671 tree type
= TREE_TYPE (decl
);
4673 if (type
== error_mark_node
)
4676 if ((type_quals
& TYPE_QUAL_CONST
)
4677 || (type
&& TREE_CODE (type
) == REFERENCE_TYPE
))
4678 /* We used to check TYPE_NEEDS_CONSTRUCTING here, but now a constexpr
4679 constructor can produce constant init, so rely on cp_finish_decl to
4680 clear TREE_READONLY if the variable has non-constant init. */
4681 TREE_READONLY (decl
) = 1;
4682 if (type_quals
& TYPE_QUAL_VOLATILE
)
4684 TREE_SIDE_EFFECTS (decl
) = 1;
4685 TREE_THIS_VOLATILE (decl
) = 1;
4687 if (type_quals
& TYPE_QUAL_RESTRICT
)
4689 while (type
&& TREE_CODE (type
) == ARRAY_TYPE
)
4690 /* Allow 'restrict' on arrays of pointers.
4691 FIXME currently we just ignore it. */
4692 type
= TREE_TYPE (type
);
4694 || !POINTER_TYPE_P (type
)
4695 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type
)))
4696 error ("invalid use of %<restrict%>");
4700 /* Hash function for the problem of multiple type definitions in
4701 different files. This must hash all types that will compare
4702 equal via comptypes to the same value. In practice it hashes
4703 on some of the simple stuff and leaves the details to comptypes. */
4706 c_type_hash (const void *p
)
4710 const_tree
const t
= (const_tree
) p
;
4712 switch (TREE_CODE (t
))
4714 /* For pointers, hash on pointee type plus some swizzling. */
4716 return c_type_hash (TREE_TYPE (t
)) ^ 0x3003003;
4717 /* Hash on number of elements and total size. */
4720 t2
= TYPE_VALUES (t
);
4724 t2
= TYPE_FIELDS (t
);
4726 case QUAL_UNION_TYPE
:
4728 t2
= TYPE_FIELDS (t
);
4732 t2
= TYPE_FIELDS (t
);
4737 /* FIXME: We want to use a DECL_CHAIN iteration method here, but
4738 TYPE_VALUES of ENUMERAL_TYPEs is stored as a TREE_LIST. */
4739 n_elements
= list_length (t2
);
4740 /* We might have a VLA here. */
4741 if (TREE_CODE (TYPE_SIZE (t
)) != INTEGER_CST
)
4744 size
= tree_to_hwi (TYPE_SIZE (t
));
4745 return ((size
<< 24) | (n_elements
<< shift
));
4748 static GTY((param_is (union tree_node
))) htab_t type_hash_table
;
4750 /* Return the typed-based alias set for T, which may be an expression
4751 or a type. Return -1 if we don't do anything special. */
4754 c_common_get_alias_set (tree t
)
4759 /* For VLAs, use the alias set of the element type rather than the
4760 default of alias set 0 for types compared structurally. */
4761 if (TYPE_P (t
) && TYPE_STRUCTURAL_EQUALITY_P (t
))
4763 if (TREE_CODE (t
) == ARRAY_TYPE
)
4764 return get_alias_set (TREE_TYPE (t
));
4768 /* Permit type-punning when accessing a union, provided the access
4769 is directly through the union. For example, this code does not
4770 permit taking the address of a union member and then storing
4771 through it. Even the type-punning allowed here is a GCC
4772 extension, albeit a common and useful one; the C standard says
4773 that such accesses have implementation-defined behavior. */
4775 TREE_CODE (u
) == COMPONENT_REF
|| TREE_CODE (u
) == ARRAY_REF
;
4776 u
= TREE_OPERAND (u
, 0))
4777 if (TREE_CODE (u
) == COMPONENT_REF
4778 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u
, 0))) == UNION_TYPE
)
4781 /* That's all the expressions we handle specially. */
4785 /* The C standard guarantees that any object may be accessed via an
4786 lvalue that has character type. */
4787 if (t
== char_type_node
4788 || t
== signed_char_type_node
4789 || t
== unsigned_char_type_node
)
4792 /* The C standard specifically allows aliasing between signed and
4793 unsigned variants of the same type. We treat the signed
4794 variant as canonical. */
4795 if (TREE_CODE (t
) == INTEGER_TYPE
&& TYPE_UNSIGNED (t
))
4797 tree t1
= c_common_signed_type (t
);
4799 /* t1 == t can happen for boolean nodes which are always unsigned. */
4801 return get_alias_set (t1
);
4804 /* Handle the case of multiple type nodes referring to "the same" type,
4805 which occurs with IMA. These share an alias set. FIXME: Currently only
4806 C90 is handled. (In C99 type compatibility is not transitive, which
4807 complicates things mightily. The alias set splay trees can theoretically
4808 represent this, but insertion is tricky when you consider all the
4809 different orders things might arrive in.) */
4811 if (c_language
!= clk_c
|| flag_isoc99
)
4814 /* Save time if there's only one input file. */
4815 if (num_in_fnames
== 1)
4818 /* Pointers need special handling if they point to any type that
4819 needs special handling (below). */
4820 if (TREE_CODE (t
) == POINTER_TYPE
)
4823 /* Find bottom type under any nested POINTERs. */
4824 for (t2
= TREE_TYPE (t
);
4825 TREE_CODE (t2
) == POINTER_TYPE
;
4826 t2
= TREE_TYPE (t2
))
4828 if (TREE_CODE (t2
) != RECORD_TYPE
4829 && TREE_CODE (t2
) != ENUMERAL_TYPE
4830 && TREE_CODE (t2
) != QUAL_UNION_TYPE
4831 && TREE_CODE (t2
) != UNION_TYPE
)
4833 if (TYPE_SIZE (t2
) == 0)
4836 /* These are the only cases that need special handling. */
4837 if (TREE_CODE (t
) != RECORD_TYPE
4838 && TREE_CODE (t
) != ENUMERAL_TYPE
4839 && TREE_CODE (t
) != QUAL_UNION_TYPE
4840 && TREE_CODE (t
) != UNION_TYPE
4841 && TREE_CODE (t
) != POINTER_TYPE
)
4844 if (TYPE_SIZE (t
) == 0)
4847 /* Look up t in hash table. Only one of the compatible types within each
4848 alias set is recorded in the table. */
4849 if (!type_hash_table
)
4850 type_hash_table
= htab_create_ggc (1021, c_type_hash
,
4851 (htab_eq
) lang_hooks
.types_compatible_p
,
4853 slot
= htab_find_slot (type_hash_table
, t
, INSERT
);
4856 TYPE_ALIAS_SET (t
) = TYPE_ALIAS_SET ((tree
)*slot
);
4857 return TYPE_ALIAS_SET ((tree
)*slot
);
4860 /* Our caller will assign and record (in t) a new alias set; all we need
4861 to do is remember t in the hash table. */
4867 /* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where
4868 the second parameter indicates which OPERATOR is being applied.
4869 The COMPLAIN flag controls whether we should diagnose possibly
4870 ill-formed constructs or not. LOC is the location of the SIZEOF or
4874 c_sizeof_or_alignof_type (location_t loc
,
4875 tree type
, bool is_sizeof
, int complain
)
4877 const char *op_name
;
4879 enum tree_code type_code
= TREE_CODE (type
);
4881 op_name
= is_sizeof
? "sizeof" : "__alignof__";
4883 if (type_code
== FUNCTION_TYPE
)
4887 if (complain
&& warn_pointer_arith
)
4888 pedwarn (loc
, OPT_Wpointer_arith
,
4889 "invalid application of %<sizeof%> to a function type");
4891 return error_mark_node
;
4892 value
= size_one_node
;
4898 if (c_dialect_cxx ())
4899 pedwarn (loc
, OPT_Wpedantic
, "ISO C++ does not permit "
4900 "%<alignof%> applied to a function type");
4902 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not permit "
4903 "%<_Alignof%> applied to a function type");
4905 value
= size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
4908 else if (type_code
== VOID_TYPE
|| type_code
== ERROR_MARK
)
4910 if (type_code
== VOID_TYPE
4911 && complain
&& warn_pointer_arith
)
4912 pedwarn (loc
, OPT_Wpointer_arith
,
4913 "invalid application of %qs to a void type", op_name
);
4915 return error_mark_node
;
4916 value
= size_one_node
;
4918 else if (!COMPLETE_TYPE_P (type
)
4919 && (!c_dialect_cxx () || is_sizeof
|| type_code
!= ARRAY_TYPE
))
4922 error_at (loc
, "invalid application of %qs to incomplete type %qT",
4924 return error_mark_node
;
4926 else if (c_dialect_cxx () && type_code
== ARRAY_TYPE
4927 && !COMPLETE_TYPE_P (TREE_TYPE (type
)))
4930 error_at (loc
, "invalid application of %qs to array type %qT of "
4931 "incomplete element type", op_name
, type
);
4932 return error_mark_node
;
4937 /* Convert in case a char is more than one unit. */
4938 value
= size_binop_loc (loc
, CEIL_DIV_EXPR
, TYPE_SIZE_UNIT (type
),
4939 size_int (TYPE_PRECISION (char_type_node
)
4942 value
= size_int (TYPE_ALIGN_UNIT (type
));
4945 /* VALUE will have the middle-end integer type sizetype.
4946 However, we should really return a value of type `size_t',
4947 which is just a typedef for an ordinary integer type. */
4948 value
= fold_convert_loc (loc
, size_type_node
, value
);
4953 /* Implement the __alignof keyword: Return the minimum required
4954 alignment of EXPR, measured in bytes. For VAR_DECLs,
4955 FUNCTION_DECLs and FIELD_DECLs return DECL_ALIGN (which can be set
4956 from an "aligned" __attribute__ specification). LOC is the
4957 location of the ALIGNOF operator. */
4960 c_alignof_expr (location_t loc
, tree expr
)
4964 if (VAR_OR_FUNCTION_DECL_P (expr
))
4965 t
= size_int (DECL_ALIGN_UNIT (expr
));
4967 else if (TREE_CODE (expr
) == COMPONENT_REF
4968 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
, 1)))
4970 error_at (loc
, "%<__alignof%> applied to a bit-field");
4973 else if (TREE_CODE (expr
) == COMPONENT_REF
4974 && TREE_CODE (TREE_OPERAND (expr
, 1)) == FIELD_DECL
)
4975 t
= size_int (DECL_ALIGN_UNIT (TREE_OPERAND (expr
, 1)));
4977 else if (TREE_CODE (expr
) == INDIRECT_REF
)
4979 tree t
= TREE_OPERAND (expr
, 0);
4981 int bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
4983 while (CONVERT_EXPR_P (t
)
4984 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
4988 t
= TREE_OPERAND (t
, 0);
4989 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
4990 if (thisalign
> bestalign
)
4991 best
= t
, bestalign
= thisalign
;
4993 return c_alignof (loc
, TREE_TYPE (TREE_TYPE (best
)));
4996 return c_alignof (loc
, TREE_TYPE (expr
));
4998 return fold_convert_loc (loc
, size_type_node
, t
);
5001 /* Handle C and C++ default attributes. */
5003 enum built_in_attribute
5005 #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
5006 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
5007 #define DEF_ATTR_STRING(ENUM, VALUE) ENUM,
5008 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
5009 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
5010 #include "builtin-attrs.def"
5011 #undef DEF_ATTR_NULL_TREE
5013 #undef DEF_ATTR_STRING
5014 #undef DEF_ATTR_IDENT
5015 #undef DEF_ATTR_TREE_LIST
5019 static GTY(()) tree built_in_attributes
[(int) ATTR_LAST
];
5021 static void c_init_attributes (void);
5025 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
5026 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
5027 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
5028 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
5029 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
5030 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
5031 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
5032 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) NAME,
5033 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) NAME,
5034 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
5035 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
5036 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
5037 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
5038 #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
5039 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG6) \
5041 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
5042 #include "builtin-types.def"
5043 #undef DEF_PRIMITIVE_TYPE
5044 #undef DEF_FUNCTION_TYPE_0
5045 #undef DEF_FUNCTION_TYPE_1
5046 #undef DEF_FUNCTION_TYPE_2
5047 #undef DEF_FUNCTION_TYPE_3
5048 #undef DEF_FUNCTION_TYPE_4
5049 #undef DEF_FUNCTION_TYPE_5
5050 #undef DEF_FUNCTION_TYPE_6
5051 #undef DEF_FUNCTION_TYPE_7
5052 #undef DEF_FUNCTION_TYPE_VAR_0
5053 #undef DEF_FUNCTION_TYPE_VAR_1
5054 #undef DEF_FUNCTION_TYPE_VAR_2
5055 #undef DEF_FUNCTION_TYPE_VAR_3
5056 #undef DEF_FUNCTION_TYPE_VAR_4
5057 #undef DEF_FUNCTION_TYPE_VAR_5
5058 #undef DEF_POINTER_TYPE
5062 typedef enum c_builtin_type builtin_type
;
5064 /* A temporary array for c_common_nodes_and_builtins. Used in
5065 communication with def_fn_type. */
5066 static tree builtin_types
[(int) BT_LAST
+ 1];
5068 /* A helper function for c_common_nodes_and_builtins. Build function type
5069 for DEF with return type RET and N arguments. If VAR is true, then the
5070 function should be variadic after those N arguments.
5072 Takes special care not to ICE if any of the types involved are
5073 error_mark_node, which indicates that said type is not in fact available
5074 (see builtin_type_for_size). In which case the function type as a whole
5075 should be error_mark_node. */
5078 def_fn_type (builtin_type def
, builtin_type ret
, bool var
, int n
, ...)
5081 tree
*args
= XALLOCAVEC (tree
, n
);
5086 for (i
= 0; i
< n
; ++i
)
5088 builtin_type a
= (builtin_type
) va_arg (list
, int);
5089 t
= builtin_types
[a
];
5090 if (t
== error_mark_node
)
5095 t
= builtin_types
[ret
];
5096 if (t
== error_mark_node
)
5099 t
= build_varargs_function_type_array (t
, n
, args
);
5101 t
= build_function_type_array (t
, n
, args
);
5104 builtin_types
[def
] = t
;
5108 /* Build builtin functions common to both C and C++ language
5112 c_define_builtins (tree va_list_ref_type_node
, tree va_list_arg_type_node
)
5114 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
5115 builtin_types[ENUM] = VALUE;
5116 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
5117 def_fn_type (ENUM, RETURN, 0, 0);
5118 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
5119 def_fn_type (ENUM, RETURN, 0, 1, ARG1);
5120 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
5121 def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
5122 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
5123 def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
5124 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
5125 def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
5126 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5127 def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
5128 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5130 def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
5131 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5133 def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
5134 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
5135 def_fn_type (ENUM, RETURN, 1, 0);
5136 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
5137 def_fn_type (ENUM, RETURN, 1, 1, ARG1);
5138 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
5139 def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
5140 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
5141 def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
5142 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
5143 def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
5144 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5145 def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
5146 #define DEF_POINTER_TYPE(ENUM, TYPE) \
5147 builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
5149 #include "builtin-types.def"
5151 #undef DEF_PRIMITIVE_TYPE
5152 #undef DEF_FUNCTION_TYPE_1
5153 #undef DEF_FUNCTION_TYPE_2
5154 #undef DEF_FUNCTION_TYPE_3
5155 #undef DEF_FUNCTION_TYPE_4
5156 #undef DEF_FUNCTION_TYPE_5
5157 #undef DEF_FUNCTION_TYPE_6
5158 #undef DEF_FUNCTION_TYPE_VAR_0
5159 #undef DEF_FUNCTION_TYPE_VAR_1
5160 #undef DEF_FUNCTION_TYPE_VAR_2
5161 #undef DEF_FUNCTION_TYPE_VAR_3
5162 #undef DEF_FUNCTION_TYPE_VAR_4
5163 #undef DEF_FUNCTION_TYPE_VAR_5
5164 #undef DEF_POINTER_TYPE
5165 builtin_types
[(int) BT_LAST
] = NULL_TREE
;
5167 c_init_attributes ();
5169 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P, \
5170 NONANSI_P, ATTRS, IMPLICIT, COND) \
5172 def_builtin_1 (ENUM, NAME, CLASS, \
5173 builtin_types[(int) TYPE], \
5174 builtin_types[(int) LIBTYPE], \
5175 BOTH_P, FALLBACK_P, NONANSI_P, \
5176 built_in_attributes[(int) ATTRS], IMPLICIT);
5177 #include "builtins.def"
5180 targetm
.init_builtins ();
5182 build_common_builtin_nodes ();
5188 /* Like get_identifier, but avoid warnings about null arguments when
5189 the argument may be NULL for targets where GCC lacks stdint.h type
5193 c_get_ident (const char *id
)
5195 return get_identifier (id
);
5198 /* Build tree nodes and builtin functions common to both C and C++ language
5202 c_common_nodes_and_builtins (void)
5204 int char16_type_size
;
5205 int char32_type_size
;
5206 int wchar_type_size
;
5207 tree array_domain_type
;
5208 tree va_list_ref_type_node
;
5209 tree va_list_arg_type_node
;
5211 build_common_tree_nodes (flag_signed_char
, flag_short_double
);
5213 /* Define `int' and `char' first so that dbx will output them first. */
5214 record_builtin_type (RID_INT
, NULL
, integer_type_node
);
5215 record_builtin_type (RID_CHAR
, "char", char_type_node
);
5217 /* `signed' is the same as `int'. FIXME: the declarations of "signed",
5218 "unsigned long", "long long unsigned" and "unsigned short" were in C++
5219 but not C. Are the conditionals here needed? */
5220 if (c_dialect_cxx ())
5221 record_builtin_type (RID_SIGNED
, NULL
, integer_type_node
);
5222 record_builtin_type (RID_LONG
, "long int", long_integer_type_node
);
5223 record_builtin_type (RID_UNSIGNED
, "unsigned int", unsigned_type_node
);
5224 record_builtin_type (RID_MAX
, "long unsigned int",
5225 long_unsigned_type_node
);
5226 if (int128_integer_type_node
!= NULL_TREE
)
5228 record_builtin_type (RID_INT128
, "__int128",
5229 int128_integer_type_node
);
5230 record_builtin_type (RID_MAX
, "__int128 unsigned",
5231 int128_unsigned_type_node
);
5233 if (c_dialect_cxx ())
5234 record_builtin_type (RID_MAX
, "unsigned long", long_unsigned_type_node
);
5235 record_builtin_type (RID_MAX
, "long long int",
5236 long_long_integer_type_node
);
5237 record_builtin_type (RID_MAX
, "long long unsigned int",
5238 long_long_unsigned_type_node
);
5239 if (c_dialect_cxx ())
5240 record_builtin_type (RID_MAX
, "long long unsigned",
5241 long_long_unsigned_type_node
);
5242 record_builtin_type (RID_SHORT
, "short int", short_integer_type_node
);
5243 record_builtin_type (RID_MAX
, "short unsigned int",
5244 short_unsigned_type_node
);
5245 if (c_dialect_cxx ())
5246 record_builtin_type (RID_MAX
, "unsigned short",
5247 short_unsigned_type_node
);
5249 /* Define both `signed char' and `unsigned char'. */
5250 record_builtin_type (RID_MAX
, "signed char", signed_char_type_node
);
5251 record_builtin_type (RID_MAX
, "unsigned char", unsigned_char_type_node
);
5253 /* These are types that c_common_type_for_size and
5254 c_common_type_for_mode use. */
5255 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5256 TYPE_DECL
, NULL_TREE
,
5258 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5259 TYPE_DECL
, NULL_TREE
,
5261 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5262 TYPE_DECL
, NULL_TREE
,
5264 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5265 TYPE_DECL
, NULL_TREE
,
5267 #if HOST_BITS_PER_WIDE_INT >= 64
5268 if (targetm
.scalar_mode_supported_p (TImode
))
5269 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5271 get_identifier ("__int128_t"),
5274 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5275 TYPE_DECL
, NULL_TREE
,
5276 unsigned_intQI_type_node
));
5277 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5278 TYPE_DECL
, NULL_TREE
,
5279 unsigned_intHI_type_node
));
5280 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5281 TYPE_DECL
, NULL_TREE
,
5282 unsigned_intSI_type_node
));
5283 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5284 TYPE_DECL
, NULL_TREE
,
5285 unsigned_intDI_type_node
));
5286 #if HOST_BITS_PER_WIDE_INT >= 64
5287 if (targetm
.scalar_mode_supported_p (TImode
))
5288 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5290 get_identifier ("__uint128_t"),
5291 unsigned_intTI_type_node
));
5294 /* Create the widest literal types. */
5295 widest_integer_literal_type_node
5296 = make_signed_type (HOST_BITS_PER_WIDE_INT
* 2);
5297 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5298 TYPE_DECL
, NULL_TREE
,
5299 widest_integer_literal_type_node
));
5301 widest_unsigned_literal_type_node
5302 = make_unsigned_type (HOST_BITS_PER_WIDE_INT
* 2);
5303 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5304 TYPE_DECL
, NULL_TREE
,
5305 widest_unsigned_literal_type_node
));
5307 signed_size_type_node
= c_common_signed_type (size_type_node
);
5310 TREE_TYPE (identifier_global_value (get_identifier (PID_TYPE
)));
5312 record_builtin_type (RID_FLOAT
, NULL
, float_type_node
);
5313 record_builtin_type (RID_DOUBLE
, NULL
, double_type_node
);
5314 record_builtin_type (RID_MAX
, "long double", long_double_type_node
);
5316 /* Only supported decimal floating point extension if the target
5317 actually supports underlying modes. */
5318 if (targetm
.scalar_mode_supported_p (SDmode
)
5319 && targetm
.scalar_mode_supported_p (DDmode
)
5320 && targetm
.scalar_mode_supported_p (TDmode
))
5322 record_builtin_type (RID_DFLOAT32
, NULL
, dfloat32_type_node
);
5323 record_builtin_type (RID_DFLOAT64
, NULL
, dfloat64_type_node
);
5324 record_builtin_type (RID_DFLOAT128
, NULL
, dfloat128_type_node
);
5327 if (targetm
.fixed_point_supported_p ())
5329 record_builtin_type (RID_MAX
, "short _Fract", short_fract_type_node
);
5330 record_builtin_type (RID_FRACT
, NULL
, fract_type_node
);
5331 record_builtin_type (RID_MAX
, "long _Fract", long_fract_type_node
);
5332 record_builtin_type (RID_MAX
, "long long _Fract",
5333 long_long_fract_type_node
);
5334 record_builtin_type (RID_MAX
, "unsigned short _Fract",
5335 unsigned_short_fract_type_node
);
5336 record_builtin_type (RID_MAX
, "unsigned _Fract",
5337 unsigned_fract_type_node
);
5338 record_builtin_type (RID_MAX
, "unsigned long _Fract",
5339 unsigned_long_fract_type_node
);
5340 record_builtin_type (RID_MAX
, "unsigned long long _Fract",
5341 unsigned_long_long_fract_type_node
);
5342 record_builtin_type (RID_MAX
, "_Sat short _Fract",
5343 sat_short_fract_type_node
);
5344 record_builtin_type (RID_MAX
, "_Sat _Fract", sat_fract_type_node
);
5345 record_builtin_type (RID_MAX
, "_Sat long _Fract",
5346 sat_long_fract_type_node
);
5347 record_builtin_type (RID_MAX
, "_Sat long long _Fract",
5348 sat_long_long_fract_type_node
);
5349 record_builtin_type (RID_MAX
, "_Sat unsigned short _Fract",
5350 sat_unsigned_short_fract_type_node
);
5351 record_builtin_type (RID_MAX
, "_Sat unsigned _Fract",
5352 sat_unsigned_fract_type_node
);
5353 record_builtin_type (RID_MAX
, "_Sat unsigned long _Fract",
5354 sat_unsigned_long_fract_type_node
);
5355 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Fract",
5356 sat_unsigned_long_long_fract_type_node
);
5357 record_builtin_type (RID_MAX
, "short _Accum", short_accum_type_node
);
5358 record_builtin_type (RID_ACCUM
, NULL
, accum_type_node
);
5359 record_builtin_type (RID_MAX
, "long _Accum", long_accum_type_node
);
5360 record_builtin_type (RID_MAX
, "long long _Accum",
5361 long_long_accum_type_node
);
5362 record_builtin_type (RID_MAX
, "unsigned short _Accum",
5363 unsigned_short_accum_type_node
);
5364 record_builtin_type (RID_MAX
, "unsigned _Accum",
5365 unsigned_accum_type_node
);
5366 record_builtin_type (RID_MAX
, "unsigned long _Accum",
5367 unsigned_long_accum_type_node
);
5368 record_builtin_type (RID_MAX
, "unsigned long long _Accum",
5369 unsigned_long_long_accum_type_node
);
5370 record_builtin_type (RID_MAX
, "_Sat short _Accum",
5371 sat_short_accum_type_node
);
5372 record_builtin_type (RID_MAX
, "_Sat _Accum", sat_accum_type_node
);
5373 record_builtin_type (RID_MAX
, "_Sat long _Accum",
5374 sat_long_accum_type_node
);
5375 record_builtin_type (RID_MAX
, "_Sat long long _Accum",
5376 sat_long_long_accum_type_node
);
5377 record_builtin_type (RID_MAX
, "_Sat unsigned short _Accum",
5378 sat_unsigned_short_accum_type_node
);
5379 record_builtin_type (RID_MAX
, "_Sat unsigned _Accum",
5380 sat_unsigned_accum_type_node
);
5381 record_builtin_type (RID_MAX
, "_Sat unsigned long _Accum",
5382 sat_unsigned_long_accum_type_node
);
5383 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Accum",
5384 sat_unsigned_long_long_accum_type_node
);
5388 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5390 get_identifier ("complex int"),
5391 complex_integer_type_node
));
5392 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5394 get_identifier ("complex float"),
5395 complex_float_type_node
));
5396 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5398 get_identifier ("complex double"),
5399 complex_double_type_node
));
5400 lang_hooks
.decls
.pushdecl
5401 (build_decl (UNKNOWN_LOCATION
,
5402 TYPE_DECL
, get_identifier ("complex long double"),
5403 complex_long_double_type_node
));
5405 if (c_dialect_cxx ())
5406 /* For C++, make fileptr_type_node a distinct void * type until
5407 FILE type is defined. */
5408 fileptr_type_node
= build_variant_type_copy (ptr_type_node
);
5410 record_builtin_type (RID_VOID
, NULL
, void_type_node
);
5412 /* Set the TYPE_NAME for any variants that were built before
5413 record_builtin_type gave names to the built-in types. */
5415 tree void_name
= TYPE_NAME (void_type_node
);
5416 TYPE_NAME (void_type_node
) = NULL_TREE
;
5417 TYPE_NAME (build_qualified_type (void_type_node
, TYPE_QUAL_CONST
))
5419 TYPE_NAME (void_type_node
) = void_name
;
5422 /* This node must not be shared. */
5423 void_zero_node
= make_int_cst (1);
5424 TREE_TYPE (void_zero_node
) = void_type_node
;
5426 void_list_node
= build_void_list_node ();
5428 /* Make a type to be the domain of a few array types
5429 whose domains don't really matter.
5430 200 is small enough that it always fits in size_t
5431 and large enough that it can hold most function names for the
5432 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
5433 array_domain_type
= build_index_type (size_int (200));
5435 /* Make a type for arrays of characters.
5436 With luck nothing will ever really depend on the length of this
5438 char_array_type_node
5439 = build_array_type (char_type_node
, array_domain_type
);
5441 /* Likewise for arrays of ints. */
5443 = build_array_type (integer_type_node
, array_domain_type
);
5445 string_type_node
= build_pointer_type (char_type_node
);
5446 const_string_type_node
5447 = build_pointer_type (build_qualified_type
5448 (char_type_node
, TYPE_QUAL_CONST
));
5450 /* This is special for C++ so functions can be overloaded. */
5451 wchar_type_node
= get_identifier (MODIFIED_WCHAR_TYPE
);
5452 wchar_type_node
= TREE_TYPE (identifier_global_value (wchar_type_node
));
5453 wchar_type_size
= TYPE_PRECISION (wchar_type_node
);
5454 underlying_wchar_type_node
= wchar_type_node
;
5455 if (c_dialect_cxx ())
5457 if (TYPE_UNSIGNED (wchar_type_node
))
5458 wchar_type_node
= make_unsigned_type (wchar_type_size
);
5460 wchar_type_node
= make_signed_type (wchar_type_size
);
5461 record_builtin_type (RID_WCHAR
, "wchar_t", wchar_type_node
);
5464 /* This is for wide string constants. */
5465 wchar_array_type_node
5466 = build_array_type (wchar_type_node
, array_domain_type
);
5468 /* Define 'char16_t'. */
5469 char16_type_node
= get_identifier (CHAR16_TYPE
);
5470 char16_type_node
= TREE_TYPE (identifier_global_value (char16_type_node
));
5471 char16_type_size
= TYPE_PRECISION (char16_type_node
);
5472 if (c_dialect_cxx ())
5474 char16_type_node
= make_unsigned_type (char16_type_size
);
5476 if (cxx_dialect
>= cxx11
)
5477 record_builtin_type (RID_CHAR16
, "char16_t", char16_type_node
);
5480 /* This is for UTF-16 string constants. */
5481 char16_array_type_node
5482 = build_array_type (char16_type_node
, array_domain_type
);
5484 /* Define 'char32_t'. */
5485 char32_type_node
= get_identifier (CHAR32_TYPE
);
5486 char32_type_node
= TREE_TYPE (identifier_global_value (char32_type_node
));
5487 char32_type_size
= TYPE_PRECISION (char32_type_node
);
5488 if (c_dialect_cxx ())
5490 char32_type_node
= make_unsigned_type (char32_type_size
);
5492 if (cxx_dialect
>= cxx11
)
5493 record_builtin_type (RID_CHAR32
, "char32_t", char32_type_node
);
5496 /* This is for UTF-32 string constants. */
5497 char32_array_type_node
5498 = build_array_type (char32_type_node
, array_domain_type
);
5501 TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE
)));
5504 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE
)));
5506 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE
)));
5508 if (SIG_ATOMIC_TYPE
)
5509 sig_atomic_type_node
=
5510 TREE_TYPE (identifier_global_value (c_get_ident (SIG_ATOMIC_TYPE
)));
5513 TREE_TYPE (identifier_global_value (c_get_ident (INT8_TYPE
)));
5516 TREE_TYPE (identifier_global_value (c_get_ident (INT16_TYPE
)));
5519 TREE_TYPE (identifier_global_value (c_get_ident (INT32_TYPE
)));
5522 TREE_TYPE (identifier_global_value (c_get_ident (INT64_TYPE
)));
5525 TREE_TYPE (identifier_global_value (c_get_ident (UINT8_TYPE
)));
5527 c_uint16_type_node
=
5528 TREE_TYPE (identifier_global_value (c_get_ident (UINT16_TYPE
)));
5530 c_uint32_type_node
=
5531 TREE_TYPE (identifier_global_value (c_get_ident (UINT32_TYPE
)));
5533 c_uint64_type_node
=
5534 TREE_TYPE (identifier_global_value (c_get_ident (UINT64_TYPE
)));
5535 if (INT_LEAST8_TYPE
)
5536 int_least8_type_node
=
5537 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST8_TYPE
)));
5538 if (INT_LEAST16_TYPE
)
5539 int_least16_type_node
=
5540 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST16_TYPE
)));
5541 if (INT_LEAST32_TYPE
)
5542 int_least32_type_node
=
5543 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST32_TYPE
)));
5544 if (INT_LEAST64_TYPE
)
5545 int_least64_type_node
=
5546 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST64_TYPE
)));
5547 if (UINT_LEAST8_TYPE
)
5548 uint_least8_type_node
=
5549 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST8_TYPE
)));
5550 if (UINT_LEAST16_TYPE
)
5551 uint_least16_type_node
=
5552 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST16_TYPE
)));
5553 if (UINT_LEAST32_TYPE
)
5554 uint_least32_type_node
=
5555 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST32_TYPE
)));
5556 if (UINT_LEAST64_TYPE
)
5557 uint_least64_type_node
=
5558 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST64_TYPE
)));
5560 int_fast8_type_node
=
5561 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST8_TYPE
)));
5562 if (INT_FAST16_TYPE
)
5563 int_fast16_type_node
=
5564 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST16_TYPE
)));
5565 if (INT_FAST32_TYPE
)
5566 int_fast32_type_node
=
5567 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST32_TYPE
)));
5568 if (INT_FAST64_TYPE
)
5569 int_fast64_type_node
=
5570 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST64_TYPE
)));
5571 if (UINT_FAST8_TYPE
)
5572 uint_fast8_type_node
=
5573 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST8_TYPE
)));
5574 if (UINT_FAST16_TYPE
)
5575 uint_fast16_type_node
=
5576 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST16_TYPE
)));
5577 if (UINT_FAST32_TYPE
)
5578 uint_fast32_type_node
=
5579 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST32_TYPE
)));
5580 if (UINT_FAST64_TYPE
)
5581 uint_fast64_type_node
=
5582 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST64_TYPE
)));
5585 TREE_TYPE (identifier_global_value (c_get_ident (INTPTR_TYPE
)));
5588 TREE_TYPE (identifier_global_value (c_get_ident (UINTPTR_TYPE
)));
5590 default_function_type
5591 = build_varargs_function_type_list (integer_type_node
, NULL_TREE
);
5593 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE
)));
5594 unsigned_ptrdiff_type_node
= c_common_unsigned_type (ptrdiff_type_node
);
5596 lang_hooks
.decls
.pushdecl
5597 (build_decl (UNKNOWN_LOCATION
,
5598 TYPE_DECL
, get_identifier ("__builtin_va_list"),
5599 va_list_type_node
));
5600 if (targetm
.enum_va_list_p
)
5606 for (l
= 0; targetm
.enum_va_list_p (l
, &pname
, &ptype
); ++l
)
5608 lang_hooks
.decls
.pushdecl
5609 (build_decl (UNKNOWN_LOCATION
,
5610 TYPE_DECL
, get_identifier (pname
),
5616 if (TREE_CODE (va_list_type_node
) == ARRAY_TYPE
)
5618 va_list_arg_type_node
= va_list_ref_type_node
=
5619 build_pointer_type (TREE_TYPE (va_list_type_node
));
5623 va_list_arg_type_node
= va_list_type_node
;
5624 va_list_ref_type_node
= build_reference_type (va_list_type_node
);
5627 if (!flag_preprocess_only
)
5628 c_define_builtins (va_list_ref_type_node
, va_list_arg_type_node
);
5630 main_identifier_node
= get_identifier ("main");
5632 /* Create the built-in __null node. It is important that this is
5634 null_node
= make_int_cst (1);
5635 TREE_TYPE (null_node
) = c_common_type_for_size (POINTER_SIZE
, 0);
5637 /* Since builtin_types isn't gc'ed, don't export these nodes. */
5638 memset (builtin_types
, 0, sizeof (builtin_types
));
5641 /* The number of named compound-literals generated thus far. */
5642 static GTY(()) int compound_literal_number
;
5644 /* Set DECL_NAME for DECL, a VAR_DECL for a compound-literal. */
5647 set_compound_literal_name (tree decl
)
5650 ASM_FORMAT_PRIVATE_NAME (name
, "__compound_literal",
5651 compound_literal_number
);
5652 compound_literal_number
++;
5653 DECL_NAME (decl
) = get_identifier (name
);
5657 build_va_arg (location_t loc
, tree expr
, tree type
)
5659 expr
= build1 (VA_ARG_EXPR
, type
, expr
);
5660 SET_EXPR_LOCATION (expr
, loc
);
5665 /* Linked list of disabled built-in functions. */
5667 typedef struct disabled_builtin
5670 struct disabled_builtin
*next
;
5672 static disabled_builtin
*disabled_builtins
= NULL
;
5674 static bool builtin_function_disabled_p (const char *);
5676 /* Disable a built-in function specified by -fno-builtin-NAME. If NAME
5677 begins with "__builtin_", give an error. */
5680 disable_builtin_function (const char *name
)
5682 if (strncmp (name
, "__builtin_", strlen ("__builtin_")) == 0)
5683 error ("cannot disable built-in function %qs", name
);
5686 disabled_builtin
*new_disabled_builtin
= XNEW (disabled_builtin
);
5687 new_disabled_builtin
->name
= name
;
5688 new_disabled_builtin
->next
= disabled_builtins
;
5689 disabled_builtins
= new_disabled_builtin
;
5694 /* Return true if the built-in function NAME has been disabled, false
5698 builtin_function_disabled_p (const char *name
)
5700 disabled_builtin
*p
;
5701 for (p
= disabled_builtins
; p
!= NULL
; p
= p
->next
)
5703 if (strcmp (name
, p
->name
) == 0)
5710 /* Worker for DEF_BUILTIN.
5711 Possibly define a builtin function with one or two names.
5712 Does not declare a non-__builtin_ function if flag_no_builtin, or if
5713 nonansi_p and flag_no_nonansi_builtin. */
5716 def_builtin_1 (enum built_in_function fncode
,
5718 enum built_in_class fnclass
,
5719 tree fntype
, tree libtype
,
5720 bool both_p
, bool fallback_p
, bool nonansi_p
,
5721 tree fnattrs
, bool implicit_p
)
5724 const char *libname
;
5726 if (fntype
== error_mark_node
)
5729 gcc_assert ((!both_p
&& !fallback_p
)
5730 || !strncmp (name
, "__builtin_",
5731 strlen ("__builtin_")));
5733 libname
= name
+ strlen ("__builtin_");
5734 decl
= add_builtin_function (name
, fntype
, fncode
, fnclass
,
5735 (fallback_p
? libname
: NULL
),
5738 set_builtin_decl (fncode
, decl
, implicit_p
);
5741 && !flag_no_builtin
&& !builtin_function_disabled_p (libname
)
5742 && !(nonansi_p
&& flag_no_nonansi_builtin
))
5743 add_builtin_function (libname
, libtype
, fncode
, fnclass
,
5747 /* Nonzero if the type T promotes to int. This is (nearly) the
5748 integral promotions defined in ISO C99 6.3.1.1/2. */
5751 c_promoting_integer_type_p (const_tree t
)
5753 switch (TREE_CODE (t
))
5756 return (TYPE_MAIN_VARIANT (t
) == char_type_node
5757 || TYPE_MAIN_VARIANT (t
) == signed_char_type_node
5758 || TYPE_MAIN_VARIANT (t
) == unsigned_char_type_node
5759 || TYPE_MAIN_VARIANT (t
) == short_integer_type_node
5760 || TYPE_MAIN_VARIANT (t
) == short_unsigned_type_node
5761 || TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
));
5764 /* ??? Technically all enumerations not larger than an int
5765 promote to an int. But this is used along code paths
5766 that only want to notice a size change. */
5767 return TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
);
5777 /* Return 1 if PARMS specifies a fixed number of parameters
5778 and none of their types is affected by default promotions. */
5781 self_promoting_args_p (const_tree parms
)
5784 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
5786 tree type
= TREE_VALUE (t
);
5788 if (type
== error_mark_node
)
5791 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
5797 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
5800 if (c_promoting_integer_type_p (type
))
5806 /* Recursively remove any '*' or '&' operator from TYPE. */
5808 strip_pointer_operator (tree t
)
5810 while (POINTER_TYPE_P (t
))
5815 /* Recursively remove pointer or array type from TYPE. */
5817 strip_pointer_or_array_types (tree t
)
5819 while (TREE_CODE (t
) == ARRAY_TYPE
|| POINTER_TYPE_P (t
))
5824 /* Used to compare case labels. K1 and K2 are actually tree nodes
5825 representing case labels, or NULL_TREE for a `default' label.
5826 Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after
5827 K2, and 0 if K1 and K2 are equal. */
5830 case_compare (splay_tree_key k1
, splay_tree_key k2
)
5832 /* Consider a NULL key (such as arises with a `default' label) to be
5833 smaller than anything else. */
5839 return tree_int_cst_compare ((tree
) k1
, (tree
) k2
);
5842 /* Process a case label, located at LOC, for the range LOW_VALUE
5843 ... HIGH_VALUE. If LOW_VALUE and HIGH_VALUE are both NULL_TREE
5844 then this case label is actually a `default' label. If only
5845 HIGH_VALUE is NULL_TREE, then case label was declared using the
5846 usual C/C++ syntax, rather than the GNU case range extension.
5847 CASES is a tree containing all the case ranges processed so far;
5848 COND is the condition for the switch-statement itself. Returns the
5849 CASE_LABEL_EXPR created, or ERROR_MARK_NODE if no CASE_LABEL_EXPR
5853 c_add_case_label (location_t loc
, splay_tree cases
, tree cond
, tree orig_type
,
5854 tree low_value
, tree high_value
)
5859 splay_tree_node node
;
5861 /* Create the LABEL_DECL itself. */
5862 label
= create_artificial_label (loc
);
5864 /* If there was an error processing the switch condition, bail now
5865 before we get more confused. */
5866 if (!cond
|| cond
== error_mark_node
)
5869 if ((low_value
&& TREE_TYPE (low_value
)
5870 && POINTER_TYPE_P (TREE_TYPE (low_value
)))
5871 || (high_value
&& TREE_TYPE (high_value
)
5872 && POINTER_TYPE_P (TREE_TYPE (high_value
))))
5874 error_at (loc
, "pointers are not permitted as case values");
5878 /* Case ranges are a GNU extension. */
5880 pedwarn (loc
, OPT_Wpedantic
,
5881 "range expressions in switch statements are non-standard");
5883 type
= TREE_TYPE (cond
);
5886 low_value
= check_case_value (low_value
);
5887 low_value
= convert_and_check (type
, low_value
);
5888 if (low_value
== error_mark_node
)
5893 high_value
= check_case_value (high_value
);
5894 high_value
= convert_and_check (type
, high_value
);
5895 if (high_value
== error_mark_node
)
5899 if (low_value
&& high_value
)
5901 /* If the LOW_VALUE and HIGH_VALUE are the same, then this isn't
5902 really a case range, even though it was written that way.
5903 Remove the HIGH_VALUE to simplify later processing. */
5904 if (tree_int_cst_equal (low_value
, high_value
))
5905 high_value
= NULL_TREE
;
5906 else if (!tree_int_cst_lt (low_value
, high_value
))
5907 warning_at (loc
, 0, "empty range specified");
5910 /* See if the case is in range of the type of the original testing
5911 expression. If both low_value and high_value are out of range,
5912 don't insert the case label and return NULL_TREE. */
5914 && !check_case_bounds (type
, orig_type
,
5915 &low_value
, high_value
? &high_value
: NULL
))
5918 /* Look up the LOW_VALUE in the table of case labels we already
5920 node
= splay_tree_lookup (cases
, (splay_tree_key
) low_value
);
5921 /* If there was not an exact match, check for overlapping ranges.
5922 There's no need to do this if there's no LOW_VALUE or HIGH_VALUE;
5923 that's a `default' label and the only overlap is an exact match. */
5924 if (!node
&& (low_value
|| high_value
))
5926 splay_tree_node low_bound
;
5927 splay_tree_node high_bound
;
5929 /* Even though there wasn't an exact match, there might be an
5930 overlap between this case range and another case range.
5931 Since we've (inductively) not allowed any overlapping case
5932 ranges, we simply need to find the greatest low case label
5933 that is smaller that LOW_VALUE, and the smallest low case
5934 label that is greater than LOW_VALUE. If there is an overlap
5935 it will occur in one of these two ranges. */
5936 low_bound
= splay_tree_predecessor (cases
,
5937 (splay_tree_key
) low_value
);
5938 high_bound
= splay_tree_successor (cases
,
5939 (splay_tree_key
) low_value
);
5941 /* Check to see if the LOW_BOUND overlaps. It is smaller than
5942 the LOW_VALUE, so there is no need to check unless the
5943 LOW_BOUND is in fact itself a case range. */
5945 && CASE_HIGH ((tree
) low_bound
->value
)
5946 && tree_int_cst_compare (CASE_HIGH ((tree
) low_bound
->value
),
5949 /* Check to see if the HIGH_BOUND overlaps. The low end of that
5950 range is bigger than the low end of the current range, so we
5951 are only interested if the current range is a real range, and
5952 not an ordinary case label. */
5955 && (tree_int_cst_compare ((tree
) high_bound
->key
,
5960 /* If there was an overlap, issue an error. */
5963 tree duplicate
= CASE_LABEL ((tree
) node
->value
);
5967 error_at (loc
, "duplicate (or overlapping) case value");
5968 error_at (DECL_SOURCE_LOCATION (duplicate
),
5969 "this is the first entry overlapping that value");
5973 error_at (loc
, "duplicate case value") ;
5974 error_at (DECL_SOURCE_LOCATION (duplicate
), "previously used here");
5978 error_at (loc
, "multiple default labels in one switch");
5979 error_at (DECL_SOURCE_LOCATION (duplicate
),
5980 "this is the first default label");
5985 /* Add a CASE_LABEL to the statement-tree. */
5986 case_label
= add_stmt (build_case_label (low_value
, high_value
, label
));
5987 /* Register this case label in the splay tree. */
5988 splay_tree_insert (cases
,
5989 (splay_tree_key
) low_value
,
5990 (splay_tree_value
) case_label
);
5995 /* Add a label so that the back-end doesn't think that the beginning of
5996 the switch is unreachable. Note that we do not add a case label, as
5997 that just leads to duplicates and thence to failure later on. */
6000 tree t
= create_artificial_label (loc
);
6001 add_stmt (build_stmt (loc
, LABEL_EXPR
, t
));
6003 return error_mark_node
;
6006 /* Subroutines of c_do_switch_warnings, called via splay_tree_foreach.
6007 Used to verify that case values match up with enumerator values. */
6010 match_case_to_enum_1 (tree key
, tree type
, tree label
)
6012 char buf
[WIDE_INT_PRINT_BUFFER_SIZE
];
6014 if (tree_fits_hwi_p (key
, TYPE_SIGN (type
)))
6015 print_dec (key
, buf
, TYPE_SIGN (type
));
6017 print_hex (key
, buf
);
6019 if (TYPE_NAME (type
) == 0)
6020 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
6021 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
6022 "case value %qs not in enumerated type",
6025 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
6026 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
6027 "case value %qs not in enumerated type %qT",
6031 /* Subroutine of c_do_switch_warnings, called via splay_tree_foreach.
6032 Used to verify that case values match up with enumerator values. */
6035 match_case_to_enum (splay_tree_node node
, void *data
)
6037 tree label
= (tree
) node
->value
;
6038 tree type
= (tree
) data
;
6040 /* Skip default case. */
6041 if (!CASE_LOW (label
))
6044 /* If CASE_LOW_SEEN is not set, that means CASE_LOW did not appear
6045 when we did our enum->case scan. Reset our scratch bit after. */
6046 if (!CASE_LOW_SEEN (label
))
6047 match_case_to_enum_1 (CASE_LOW (label
), type
, label
);
6049 CASE_LOW_SEEN (label
) = 0;
6051 /* If CASE_HIGH is non-null, we have a range. If CASE_HIGH_SEEN is
6052 not set, that means that CASE_HIGH did not appear when we did our
6053 enum->case scan. Reset our scratch bit after. */
6054 if (CASE_HIGH (label
))
6056 if (!CASE_HIGH_SEEN (label
))
6057 match_case_to_enum_1 (CASE_HIGH (label
), type
, label
);
6059 CASE_HIGH_SEEN (label
) = 0;
6065 /* Handle -Wswitch*. Called from the front end after parsing the
6066 switch construct. */
6067 /* ??? Should probably be somewhere generic, since other languages
6068 besides C and C++ would want this. At the moment, however, C/C++
6069 are the only tree-ssa languages that support enumerations at all,
6070 so the point is moot. */
6073 c_do_switch_warnings (splay_tree cases
, location_t switch_location
,
6074 tree type
, tree cond
)
6076 splay_tree_node default_node
;
6077 splay_tree_node node
;
6080 if (!warn_switch
&& !warn_switch_enum
&& !warn_switch_default
)
6083 default_node
= splay_tree_lookup (cases
, (splay_tree_key
) NULL
);
6085 warning_at (switch_location
, OPT_Wswitch_default
,
6086 "switch missing default case");
6088 /* From here on, we only care about about enumerated types. */
6089 if (!type
|| TREE_CODE (type
) != ENUMERAL_TYPE
)
6092 /* From here on, we only care about -Wswitch and -Wswitch-enum. */
6093 if (!warn_switch_enum
&& !warn_switch
)
6096 /* Check the cases. Warn about case values which are not members of
6097 the enumerated type. For -Wswitch-enum, or for -Wswitch when
6098 there is no default case, check that exactly all enumeration
6099 literals are covered by the cases. */
6101 /* Clearing COND if it is not an integer constant simplifies
6102 the tests inside the loop below. */
6103 if (TREE_CODE (cond
) != INTEGER_CST
)
6106 /* The time complexity here is O(N*lg(N)) worst case, but for the
6107 common case of monotonically increasing enumerators, it is
6108 O(N), since the nature of the splay tree will keep the next
6109 element adjacent to the root at all times. */
6111 for (chain
= TYPE_VALUES (type
); chain
; chain
= TREE_CHAIN (chain
))
6113 tree value
= TREE_VALUE (chain
);
6114 if (TREE_CODE (value
) == CONST_DECL
)
6115 value
= DECL_INITIAL (value
);
6116 node
= splay_tree_lookup (cases
, (splay_tree_key
) value
);
6119 /* Mark the CASE_LOW part of the case entry as seen. */
6120 tree label
= (tree
) node
->value
;
6121 CASE_LOW_SEEN (label
) = 1;
6125 /* Even though there wasn't an exact match, there might be a
6126 case range which includes the enumerator's value. */
6127 node
= splay_tree_predecessor (cases
, (splay_tree_key
) value
);
6128 if (node
&& CASE_HIGH ((tree
) node
->value
))
6130 tree label
= (tree
) node
->value
;
6131 int cmp
= tree_int_cst_compare (CASE_HIGH (label
), value
);
6134 /* If we match the upper bound exactly, mark the CASE_HIGH
6135 part of the case entry as seen. */
6137 CASE_HIGH_SEEN (label
) = 1;
6142 /* We've now determined that this enumerated literal isn't
6143 handled by the case labels of the switch statement. */
6145 /* If the switch expression is a constant, we only really care
6146 about whether that constant is handled by the switch. */
6147 if (cond
&& tree_int_cst_compare (cond
, value
))
6150 /* If there is a default_node, the only relevant option is
6151 Wswitch-enum. Otherwise, if both are enabled then we prefer
6152 to warn using -Wswitch because -Wswitch is enabled by -Wall
6153 while -Wswitch-enum is explicit. */
6154 warning_at (switch_location
,
6155 (default_node
|| !warn_switch
6158 "enumeration value %qE not handled in switch",
6159 TREE_PURPOSE (chain
));
6162 /* Warn if there are case expressions that don't correspond to
6163 enumerators. This can occur since C and C++ don't enforce
6164 type-checking of assignments to enumeration variables.
6166 The time complexity here is now always O(N) worst case, since
6167 we should have marked both the lower bound and upper bound of
6168 every disjoint case label, with CASE_LOW_SEEN and CASE_HIGH_SEEN
6169 above. This scan also resets those fields. */
6171 splay_tree_foreach (cases
, match_case_to_enum
, type
);
6174 /* Finish an expression taking the address of LABEL (an
6175 IDENTIFIER_NODE). Returns an expression for the address.
6177 LOC is the location for the expression returned. */
6180 finish_label_address_expr (tree label
, location_t loc
)
6184 pedwarn (input_location
, OPT_Wpedantic
, "taking the address of a label is non-standard");
6186 if (label
== error_mark_node
)
6187 return error_mark_node
;
6189 label
= lookup_label (label
);
6190 if (label
== NULL_TREE
)
6191 result
= null_pointer_node
;
6194 TREE_USED (label
) = 1;
6195 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
6196 /* The current function is not necessarily uninlinable.
6197 Computed gotos are incompatible with inlining, but the value
6198 here could be used only in a diagnostic, for example. */
6199 protected_set_expr_location (result
, loc
);
6206 /* Given a boolean expression ARG, return a tree representing an increment
6207 or decrement (as indicated by CODE) of ARG. The front end must check for
6208 invalid cases (e.g., decrement in C++). */
6210 boolean_increment (enum tree_code code
, tree arg
)
6213 tree true_res
= build_int_cst (TREE_TYPE (arg
), 1);
6215 arg
= stabilize_reference (arg
);
6218 case PREINCREMENT_EXPR
:
6219 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
6221 case POSTINCREMENT_EXPR
:
6222 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
6223 arg
= save_expr (arg
);
6224 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
6225 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
6227 case PREDECREMENT_EXPR
:
6228 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
6229 invert_truthvalue_loc (input_location
, arg
));
6231 case POSTDECREMENT_EXPR
:
6232 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
6233 invert_truthvalue_loc (input_location
, arg
));
6234 arg
= save_expr (arg
);
6235 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
6236 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
6241 TREE_SIDE_EFFECTS (val
) = 1;
6245 /* Built-in macros for stddef.h and stdint.h, that require macros
6246 defined in this file. */
6248 c_stddef_cpp_builtins(void)
6250 builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE
, 0);
6251 builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE
, 0);
6252 builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE
, 0);
6253 builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE
, 0);
6254 builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE
, 0);
6255 builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE
, 0);
6256 builtin_define_with_value ("__CHAR16_TYPE__", CHAR16_TYPE
, 0);
6257 builtin_define_with_value ("__CHAR32_TYPE__", CHAR32_TYPE
, 0);
6258 if (SIG_ATOMIC_TYPE
)
6259 builtin_define_with_value ("__SIG_ATOMIC_TYPE__", SIG_ATOMIC_TYPE
, 0);
6261 builtin_define_with_value ("__INT8_TYPE__", INT8_TYPE
, 0);
6263 builtin_define_with_value ("__INT16_TYPE__", INT16_TYPE
, 0);
6265 builtin_define_with_value ("__INT32_TYPE__", INT32_TYPE
, 0);
6267 builtin_define_with_value ("__INT64_TYPE__", INT64_TYPE
, 0);
6269 builtin_define_with_value ("__UINT8_TYPE__", UINT8_TYPE
, 0);
6271 builtin_define_with_value ("__UINT16_TYPE__", UINT16_TYPE
, 0);
6273 builtin_define_with_value ("__UINT32_TYPE__", UINT32_TYPE
, 0);
6275 builtin_define_with_value ("__UINT64_TYPE__", UINT64_TYPE
, 0);
6276 if (INT_LEAST8_TYPE
)
6277 builtin_define_with_value ("__INT_LEAST8_TYPE__", INT_LEAST8_TYPE
, 0);
6278 if (INT_LEAST16_TYPE
)
6279 builtin_define_with_value ("__INT_LEAST16_TYPE__", INT_LEAST16_TYPE
, 0);
6280 if (INT_LEAST32_TYPE
)
6281 builtin_define_with_value ("__INT_LEAST32_TYPE__", INT_LEAST32_TYPE
, 0);
6282 if (INT_LEAST64_TYPE
)
6283 builtin_define_with_value ("__INT_LEAST64_TYPE__", INT_LEAST64_TYPE
, 0);
6284 if (UINT_LEAST8_TYPE
)
6285 builtin_define_with_value ("__UINT_LEAST8_TYPE__", UINT_LEAST8_TYPE
, 0);
6286 if (UINT_LEAST16_TYPE
)
6287 builtin_define_with_value ("__UINT_LEAST16_TYPE__", UINT_LEAST16_TYPE
, 0);
6288 if (UINT_LEAST32_TYPE
)
6289 builtin_define_with_value ("__UINT_LEAST32_TYPE__", UINT_LEAST32_TYPE
, 0);
6290 if (UINT_LEAST64_TYPE
)
6291 builtin_define_with_value ("__UINT_LEAST64_TYPE__", UINT_LEAST64_TYPE
, 0);
6293 builtin_define_with_value ("__INT_FAST8_TYPE__", INT_FAST8_TYPE
, 0);
6294 if (INT_FAST16_TYPE
)
6295 builtin_define_with_value ("__INT_FAST16_TYPE__", INT_FAST16_TYPE
, 0);
6296 if (INT_FAST32_TYPE
)
6297 builtin_define_with_value ("__INT_FAST32_TYPE__", INT_FAST32_TYPE
, 0);
6298 if (INT_FAST64_TYPE
)
6299 builtin_define_with_value ("__INT_FAST64_TYPE__", INT_FAST64_TYPE
, 0);
6300 if (UINT_FAST8_TYPE
)
6301 builtin_define_with_value ("__UINT_FAST8_TYPE__", UINT_FAST8_TYPE
, 0);
6302 if (UINT_FAST16_TYPE
)
6303 builtin_define_with_value ("__UINT_FAST16_TYPE__", UINT_FAST16_TYPE
, 0);
6304 if (UINT_FAST32_TYPE
)
6305 builtin_define_with_value ("__UINT_FAST32_TYPE__", UINT_FAST32_TYPE
, 0);
6306 if (UINT_FAST64_TYPE
)
6307 builtin_define_with_value ("__UINT_FAST64_TYPE__", UINT_FAST64_TYPE
, 0);
6309 builtin_define_with_value ("__INTPTR_TYPE__", INTPTR_TYPE
, 0);
6311 builtin_define_with_value ("__UINTPTR_TYPE__", UINTPTR_TYPE
, 0);
6315 c_init_attributes (void)
6317 /* Fill in the built_in_attributes array. */
6318 #define DEF_ATTR_NULL_TREE(ENUM) \
6319 built_in_attributes[(int) ENUM] = NULL_TREE;
6320 #define DEF_ATTR_INT(ENUM, VALUE) \
6321 built_in_attributes[(int) ENUM] = build_int_cst (integer_type_node, VALUE);
6322 #define DEF_ATTR_STRING(ENUM, VALUE) \
6323 built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
6324 #define DEF_ATTR_IDENT(ENUM, STRING) \
6325 built_in_attributes[(int) ENUM] = get_identifier (STRING);
6326 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
6327 built_in_attributes[(int) ENUM] \
6328 = tree_cons (built_in_attributes[(int) PURPOSE], \
6329 built_in_attributes[(int) VALUE], \
6330 built_in_attributes[(int) CHAIN]);
6331 #include "builtin-attrs.def"
6332 #undef DEF_ATTR_NULL_TREE
6334 #undef DEF_ATTR_IDENT
6335 #undef DEF_ATTR_TREE_LIST
6338 /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain
6339 identifier as an argument, so the front end shouldn't look it up. */
6342 attribute_takes_identifier_p (const_tree attr_id
)
6344 const struct attribute_spec
*spec
= lookup_attribute_spec (attr_id
);
6346 /* Unknown attribute that we'll end up ignoring, return true so we
6347 don't complain about an identifier argument. */
6349 else if (!strcmp ("mode", spec
->name
)
6350 || !strcmp ("format", spec
->name
)
6351 || !strcmp ("cleanup", spec
->name
))
6354 return targetm
.attribute_takes_identifier_p (attr_id
);
6357 /* Attribute handlers common to C front ends. */
6359 /* Handle a "packed" attribute; arguments as in
6360 struct attribute_spec.handler. */
6363 handle_packed_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6364 int flags
, bool *no_add_attrs
)
6368 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6369 *node
= build_variant_type_copy (*node
);
6370 TYPE_PACKED (*node
) = 1;
6372 else if (TREE_CODE (*node
) == FIELD_DECL
)
6374 if (TYPE_ALIGN (TREE_TYPE (*node
)) <= BITS_PER_UNIT
6375 /* Still pack bitfields. */
6376 && ! DECL_INITIAL (*node
))
6377 warning (OPT_Wattributes
,
6378 "%qE attribute ignored for field of type %qT",
6379 name
, TREE_TYPE (*node
));
6381 DECL_PACKED (*node
) = 1;
6383 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
6384 used for DECL_REGISTER. It wouldn't mean anything anyway.
6385 We can't set DECL_PACKED on the type of a TYPE_DECL, because
6386 that changes what the typedef is typing. */
6389 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6390 *no_add_attrs
= true;
6396 /* Handle a "nocommon" attribute; arguments as in
6397 struct attribute_spec.handler. */
6400 handle_nocommon_attribute (tree
*node
, tree name
,
6401 tree
ARG_UNUSED (args
),
6402 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6404 if (TREE_CODE (*node
) == VAR_DECL
)
6405 DECL_COMMON (*node
) = 0;
6408 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6409 *no_add_attrs
= true;
6415 /* Handle a "common" attribute; arguments as in
6416 struct attribute_spec.handler. */
6419 handle_common_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6420 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6422 if (TREE_CODE (*node
) == VAR_DECL
)
6423 DECL_COMMON (*node
) = 1;
6426 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6427 *no_add_attrs
= true;
6433 /* Handle a "noreturn" attribute; arguments as in
6434 struct attribute_spec.handler. */
6437 handle_noreturn_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6438 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6440 tree type
= TREE_TYPE (*node
);
6442 /* See FIXME comment in c_common_attribute_table. */
6443 if (TREE_CODE (*node
) == FUNCTION_DECL
6444 || objc_method_decl (TREE_CODE (*node
)))
6445 TREE_THIS_VOLATILE (*node
) = 1;
6446 else if (TREE_CODE (type
) == POINTER_TYPE
6447 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
6449 = build_pointer_type
6450 (build_type_variant (TREE_TYPE (type
),
6451 TYPE_READONLY (TREE_TYPE (type
)), 1));
6454 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6455 *no_add_attrs
= true;
6461 /* Handle a "hot" and attribute; arguments as in
6462 struct attribute_spec.handler. */
6465 handle_hot_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6466 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6468 if (TREE_CODE (*node
) == FUNCTION_DECL
6469 || TREE_CODE (*node
) == LABEL_DECL
)
6471 if (lookup_attribute ("cold", DECL_ATTRIBUTES (*node
)) != NULL
)
6473 warning (OPT_Wattributes
, "%qE attribute conflicts with attribute %s",
6475 *no_add_attrs
= true;
6477 /* Most of the rest of the hot processing is done later with
6478 lookup_attribute. */
6482 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6483 *no_add_attrs
= true;
6489 /* Handle a "cold" and attribute; arguments as in
6490 struct attribute_spec.handler. */
6493 handle_cold_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6494 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6496 if (TREE_CODE (*node
) == FUNCTION_DECL
6497 || TREE_CODE (*node
) == LABEL_DECL
)
6499 if (lookup_attribute ("hot", DECL_ATTRIBUTES (*node
)) != NULL
)
6501 warning (OPT_Wattributes
, "%qE attribute conflicts with attribute %s",
6503 *no_add_attrs
= true;
6505 /* Most of the rest of the cold processing is done later with
6506 lookup_attribute. */
6510 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6511 *no_add_attrs
= true;
6517 /* Handle a "no_sanitize_address" attribute; arguments as in
6518 struct attribute_spec.handler. */
6521 handle_no_sanitize_address_attribute (tree
*node
, tree name
, tree
, int,
6524 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6526 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6527 *no_add_attrs
= true;
6533 /* Handle a "no_address_safety_analysis" attribute; arguments as in
6534 struct attribute_spec.handler. */
6537 handle_no_address_safety_analysis_attribute (tree
*node
, tree name
, tree
, int,
6540 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6541 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6542 else if (!lookup_attribute ("no_sanitize_address", DECL_ATTRIBUTES (*node
)))
6543 DECL_ATTRIBUTES (*node
)
6544 = tree_cons (get_identifier ("no_sanitize_address"),
6545 NULL_TREE
, DECL_ATTRIBUTES (*node
));
6546 *no_add_attrs
= true;
6550 /* Handle a "noinline" attribute; arguments as in
6551 struct attribute_spec.handler. */
6554 handle_noinline_attribute (tree
*node
, tree name
,
6555 tree
ARG_UNUSED (args
),
6556 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6558 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6559 DECL_UNINLINABLE (*node
) = 1;
6562 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6563 *no_add_attrs
= true;
6569 /* Handle a "noclone" attribute; arguments as in
6570 struct attribute_spec.handler. */
6573 handle_noclone_attribute (tree
*node
, tree name
,
6574 tree
ARG_UNUSED (args
),
6575 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6577 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6579 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6580 *no_add_attrs
= true;
6586 /* Handle a "always_inline" attribute; arguments as in
6587 struct attribute_spec.handler. */
6590 handle_always_inline_attribute (tree
*node
, tree name
,
6591 tree
ARG_UNUSED (args
),
6592 int ARG_UNUSED (flags
),
6595 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6597 /* Set the attribute and mark it for disregarding inline
6599 DECL_DISREGARD_INLINE_LIMITS (*node
) = 1;
6603 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6604 *no_add_attrs
= true;
6610 /* Handle a "gnu_inline" attribute; arguments as in
6611 struct attribute_spec.handler. */
6614 handle_gnu_inline_attribute (tree
*node
, tree name
,
6615 tree
ARG_UNUSED (args
),
6616 int ARG_UNUSED (flags
),
6619 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
6621 /* Do nothing else, just set the attribute. We'll get at
6622 it later with lookup_attribute. */
6626 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6627 *no_add_attrs
= true;
6633 /* Handle a "leaf" attribute; arguments as in
6634 struct attribute_spec.handler. */
6637 handle_leaf_attribute (tree
*node
, tree name
,
6638 tree
ARG_UNUSED (args
),
6639 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6641 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6643 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6644 *no_add_attrs
= true;
6646 if (!TREE_PUBLIC (*node
))
6648 warning (OPT_Wattributes
, "%qE attribute has no effect on unit local functions", name
);
6649 *no_add_attrs
= true;
6655 /* Handle an "artificial" attribute; arguments as in
6656 struct attribute_spec.handler. */
6659 handle_artificial_attribute (tree
*node
, tree name
,
6660 tree
ARG_UNUSED (args
),
6661 int ARG_UNUSED (flags
),
6664 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
6666 /* Do nothing else, just set the attribute. We'll get at
6667 it later with lookup_attribute. */
6671 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6672 *no_add_attrs
= true;
6678 /* Handle a "flatten" attribute; arguments as in
6679 struct attribute_spec.handler. */
6682 handle_flatten_attribute (tree
*node
, tree name
,
6683 tree args ATTRIBUTE_UNUSED
,
6684 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
6686 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6687 /* Do nothing else, just set the attribute. We'll get at
6688 it later with lookup_attribute. */
6692 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6693 *no_add_attrs
= true;
6699 /* Handle a "warning" or "error" attribute; arguments as in
6700 struct attribute_spec.handler. */
6703 handle_error_attribute (tree
*node
, tree name
, tree args
,
6704 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6706 if (TREE_CODE (*node
) == FUNCTION_DECL
6707 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
6708 /* Do nothing else, just set the attribute. We'll get at
6709 it later with lookup_attribute. */
6713 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6714 *no_add_attrs
= true;
6720 /* Handle a "used" attribute; arguments as in
6721 struct attribute_spec.handler. */
6724 handle_used_attribute (tree
*pnode
, tree name
, tree
ARG_UNUSED (args
),
6725 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6729 if (TREE_CODE (node
) == FUNCTION_DECL
6730 || (TREE_CODE (node
) == VAR_DECL
&& TREE_STATIC (node
))
6731 || (TREE_CODE (node
) == TYPE_DECL
))
6733 TREE_USED (node
) = 1;
6734 DECL_PRESERVE_P (node
) = 1;
6735 if (TREE_CODE (node
) == VAR_DECL
)
6736 DECL_READ_P (node
) = 1;
6740 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6741 *no_add_attrs
= true;
6747 /* Handle a "unused" attribute; arguments as in
6748 struct attribute_spec.handler. */
6751 handle_unused_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6752 int flags
, bool *no_add_attrs
)
6758 if (TREE_CODE (decl
) == PARM_DECL
6759 || TREE_CODE (decl
) == VAR_DECL
6760 || TREE_CODE (decl
) == FUNCTION_DECL
6761 || TREE_CODE (decl
) == LABEL_DECL
6762 || TREE_CODE (decl
) == TYPE_DECL
)
6764 TREE_USED (decl
) = 1;
6765 if (TREE_CODE (decl
) == VAR_DECL
6766 || TREE_CODE (decl
) == PARM_DECL
)
6767 DECL_READ_P (decl
) = 1;
6771 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6772 *no_add_attrs
= true;
6777 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6778 *node
= build_variant_type_copy (*node
);
6779 TREE_USED (*node
) = 1;
6785 /* Handle a "externally_visible" attribute; arguments as in
6786 struct attribute_spec.handler. */
6789 handle_externally_visible_attribute (tree
*pnode
, tree name
,
6790 tree
ARG_UNUSED (args
),
6791 int ARG_UNUSED (flags
),
6796 if (TREE_CODE (node
) == FUNCTION_DECL
|| TREE_CODE (node
) == VAR_DECL
)
6798 if ((!TREE_STATIC (node
) && TREE_CODE (node
) != FUNCTION_DECL
6799 && !DECL_EXTERNAL (node
)) || !TREE_PUBLIC (node
))
6801 warning (OPT_Wattributes
,
6802 "%qE attribute have effect only on public objects", name
);
6803 *no_add_attrs
= true;
6808 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6809 *no_add_attrs
= true;
6815 /* Handle a "const" attribute; arguments as in
6816 struct attribute_spec.handler. */
6819 handle_const_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6820 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6822 tree type
= TREE_TYPE (*node
);
6824 /* See FIXME comment on noreturn in c_common_attribute_table. */
6825 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6826 TREE_READONLY (*node
) = 1;
6827 else if (TREE_CODE (type
) == POINTER_TYPE
6828 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
6830 = build_pointer_type
6831 (build_type_variant (TREE_TYPE (type
), 1,
6832 TREE_THIS_VOLATILE (TREE_TYPE (type
))));
6835 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6836 *no_add_attrs
= true;
6842 /* Handle a "transparent_union" attribute; arguments as in
6843 struct attribute_spec.handler. */
6846 handle_transparent_union_attribute (tree
*node
, tree name
,
6847 tree
ARG_UNUSED (args
), int flags
,
6852 *no_add_attrs
= true;
6855 if (TREE_CODE (*node
) == TYPE_DECL
6856 && ! (flags
& ATTR_FLAG_CXX11
))
6857 node
= &TREE_TYPE (*node
);
6860 if (TREE_CODE (type
) == UNION_TYPE
)
6862 /* Make sure that the first field will work for a transparent union.
6863 If the type isn't complete yet, leave the check to the code in
6865 if (TYPE_SIZE (type
))
6867 tree first
= first_field (type
);
6868 if (first
== NULL_TREE
6869 || DECL_ARTIFICIAL (first
)
6870 || TYPE_MODE (type
) != DECL_MODE (first
))
6874 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6876 /* If the type isn't complete yet, setting the flag
6877 on a variant wouldn't ever be checked. */
6878 if (!TYPE_SIZE (type
))
6881 /* build_duplicate_type doesn't work for C++. */
6882 if (c_dialect_cxx ())
6885 /* A type variant isn't good enough, since we don't a cast
6886 to such a type removed as a no-op. */
6887 *node
= type
= build_duplicate_type (type
);
6890 TYPE_TRANSPARENT_AGGR (type
) = 1;
6895 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6899 /* Subroutine of handle_{con,de}structor_attribute. Evaluate ARGS to
6900 get the requested priority for a constructor or destructor,
6901 possibly issuing diagnostics for invalid or reserved
6904 static priority_type
6905 get_priority (tree args
, bool is_destructor
)
6911 return DEFAULT_INIT_PRIORITY
;
6913 if (!SUPPORTS_INIT_PRIORITY
)
6916 error ("destructor priorities are not supported");
6918 error ("constructor priorities are not supported");
6919 return DEFAULT_INIT_PRIORITY
;
6922 arg
= TREE_VALUE (args
);
6923 arg
= default_conversion (arg
);
6924 if (!tree_fits_shwi_p (arg
)
6925 || !INTEGRAL_TYPE_P (TREE_TYPE (arg
)))
6928 pri
= tree_to_shwi (arg
);
6929 if (pri
< 0 || pri
> MAX_INIT_PRIORITY
)
6932 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
6936 "destructor priorities from 0 to %d are reserved "
6937 "for the implementation",
6938 MAX_RESERVED_INIT_PRIORITY
);
6941 "constructor priorities from 0 to %d are reserved "
6942 "for the implementation",
6943 MAX_RESERVED_INIT_PRIORITY
);
6949 error ("destructor priorities must be integers from 0 to %d inclusive",
6952 error ("constructor priorities must be integers from 0 to %d inclusive",
6954 return DEFAULT_INIT_PRIORITY
;
6957 /* Handle a "constructor" attribute; arguments as in
6958 struct attribute_spec.handler. */
6961 handle_constructor_attribute (tree
*node
, tree name
, tree args
,
6962 int ARG_UNUSED (flags
),
6966 tree type
= TREE_TYPE (decl
);
6968 if (TREE_CODE (decl
) == FUNCTION_DECL
6969 && TREE_CODE (type
) == FUNCTION_TYPE
6970 && decl_function_context (decl
) == 0)
6972 priority_type priority
;
6973 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
6974 priority
= get_priority (args
, /*is_destructor=*/false);
6975 SET_DECL_INIT_PRIORITY (decl
, priority
);
6976 TREE_USED (decl
) = 1;
6980 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6981 *no_add_attrs
= true;
6987 /* Handle a "destructor" attribute; arguments as in
6988 struct attribute_spec.handler. */
6991 handle_destructor_attribute (tree
*node
, tree name
, tree args
,
6992 int ARG_UNUSED (flags
),
6996 tree type
= TREE_TYPE (decl
);
6998 if (TREE_CODE (decl
) == FUNCTION_DECL
6999 && TREE_CODE (type
) == FUNCTION_TYPE
7000 && decl_function_context (decl
) == 0)
7002 priority_type priority
;
7003 DECL_STATIC_DESTRUCTOR (decl
) = 1;
7004 priority
= get_priority (args
, /*is_destructor=*/true);
7005 SET_DECL_FINI_PRIORITY (decl
, priority
);
7006 TREE_USED (decl
) = 1;
7010 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7011 *no_add_attrs
= true;
7017 /* Nonzero if the mode is a valid vector mode for this architecture.
7018 This returns nonzero even if there is no hardware support for the
7019 vector mode, but we can emulate with narrower modes. */
7022 vector_mode_valid_p (enum machine_mode mode
)
7024 enum mode_class mclass
= GET_MODE_CLASS (mode
);
7025 enum machine_mode innermode
;
7027 /* Doh! What's going on? */
7028 if (mclass
!= MODE_VECTOR_INT
7029 && mclass
!= MODE_VECTOR_FLOAT
7030 && mclass
!= MODE_VECTOR_FRACT
7031 && mclass
!= MODE_VECTOR_UFRACT
7032 && mclass
!= MODE_VECTOR_ACCUM
7033 && mclass
!= MODE_VECTOR_UACCUM
)
7036 /* Hardware support. Woo hoo! */
7037 if (targetm
.vector_mode_supported_p (mode
))
7040 innermode
= GET_MODE_INNER (mode
);
7042 /* We should probably return 1 if requesting V4DI and we have no DI,
7043 but we have V2DI, but this is probably very unlikely. */
7045 /* If we have support for the inner mode, we can safely emulate it.
7046 We may not have V2DI, but me can emulate with a pair of DIs. */
7047 return targetm
.scalar_mode_supported_p (innermode
);
7051 /* Handle a "mode" attribute; arguments as in
7052 struct attribute_spec.handler. */
7055 handle_mode_attribute (tree
*node
, tree name
, tree args
,
7056 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7059 tree ident
= TREE_VALUE (args
);
7061 *no_add_attrs
= true;
7063 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
7064 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7068 const char *p
= IDENTIFIER_POINTER (ident
);
7069 int len
= strlen (p
);
7070 enum machine_mode mode
= VOIDmode
;
7074 if (len
> 4 && p
[0] == '_' && p
[1] == '_'
7075 && p
[len
- 1] == '_' && p
[len
- 2] == '_')
7077 char *newp
= (char *) alloca (len
- 1);
7079 strcpy (newp
, &p
[2]);
7080 newp
[len
- 4] = '\0';
7084 /* Change this type to have a type with the specified mode.
7085 First check for the special modes. */
7086 if (!strcmp (p
, "byte"))
7088 else if (!strcmp (p
, "word"))
7090 else if (!strcmp (p
, "pointer"))
7092 else if (!strcmp (p
, "libgcc_cmp_return"))
7093 mode
= targetm
.libgcc_cmp_return_mode ();
7094 else if (!strcmp (p
, "libgcc_shift_count"))
7095 mode
= targetm
.libgcc_shift_count_mode ();
7096 else if (!strcmp (p
, "unwind_word"))
7097 mode
= targetm
.unwind_word_mode ();
7099 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
7100 if (!strcmp (p
, GET_MODE_NAME (j
)))
7102 mode
= (enum machine_mode
) j
;
7106 if (mode
== VOIDmode
)
7108 error ("unknown machine mode %qE", ident
);
7113 switch (GET_MODE_CLASS (mode
))
7116 case MODE_PARTIAL_INT
:
7118 case MODE_DECIMAL_FLOAT
:
7123 valid_mode
= targetm
.scalar_mode_supported_p (mode
);
7126 case MODE_COMPLEX_INT
:
7127 case MODE_COMPLEX_FLOAT
:
7128 valid_mode
= targetm
.scalar_mode_supported_p (GET_MODE_INNER (mode
));
7131 case MODE_VECTOR_INT
:
7132 case MODE_VECTOR_FLOAT
:
7133 case MODE_VECTOR_FRACT
:
7134 case MODE_VECTOR_UFRACT
:
7135 case MODE_VECTOR_ACCUM
:
7136 case MODE_VECTOR_UACCUM
:
7137 warning (OPT_Wattributes
, "specifying vector types with "
7138 "__attribute__ ((mode)) is deprecated");
7139 warning (OPT_Wattributes
,
7140 "use __attribute__ ((vector_size)) instead");
7141 valid_mode
= vector_mode_valid_p (mode
);
7149 error ("unable to emulate %qs", p
);
7153 if (POINTER_TYPE_P (type
))
7155 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
7156 tree (*fn
)(tree
, enum machine_mode
, bool);
7158 if (!targetm
.addr_space
.valid_pointer_mode (mode
, as
))
7160 error ("invalid pointer mode %qs", p
);
7164 if (TREE_CODE (type
) == POINTER_TYPE
)
7165 fn
= build_pointer_type_for_mode
;
7167 fn
= build_reference_type_for_mode
;
7168 typefm
= fn (TREE_TYPE (type
), mode
, false);
7172 /* For fixed-point modes, we need to test if the signness of type
7173 and the machine mode are consistent. */
7174 if (ALL_FIXED_POINT_MODE_P (mode
)
7175 && TYPE_UNSIGNED (type
) != UNSIGNED_FIXED_POINT_MODE_P (mode
))
7177 error ("signedness of type and machine mode %qs don%'t match", p
);
7180 /* For fixed-point modes, we need to pass saturating info. */
7181 typefm
= lang_hooks
.types
.type_for_mode (mode
,
7182 ALL_FIXED_POINT_MODE_P (mode
) ? TYPE_SATURATING (type
)
7183 : TYPE_UNSIGNED (type
));
7186 if (typefm
== NULL_TREE
)
7188 error ("no data type for mode %qs", p
);
7191 else if (TREE_CODE (type
) == ENUMERAL_TYPE
)
7193 /* For enumeral types, copy the precision from the integer
7194 type returned above. If not an INTEGER_TYPE, we can't use
7195 this mode for this type. */
7196 if (TREE_CODE (typefm
) != INTEGER_TYPE
)
7198 error ("cannot use mode %qs for enumeral types", p
);
7202 if (flags
& ATTR_FLAG_TYPE_IN_PLACE
)
7204 TYPE_PRECISION (type
) = TYPE_PRECISION (typefm
);
7209 /* We cannot build a type variant, as there's code that assumes
7210 that TYPE_MAIN_VARIANT has the same mode. This includes the
7211 debug generators. Instead, create a subrange type. This
7212 results in all of the enumeral values being emitted only once
7213 in the original, and the subtype gets them by reference. */
7214 if (TYPE_UNSIGNED (type
))
7215 typefm
= make_unsigned_type (TYPE_PRECISION (typefm
));
7217 typefm
= make_signed_type (TYPE_PRECISION (typefm
));
7218 TREE_TYPE (typefm
) = type
;
7221 else if (VECTOR_MODE_P (mode
)
7222 ? TREE_CODE (type
) != TREE_CODE (TREE_TYPE (typefm
))
7223 : TREE_CODE (type
) != TREE_CODE (typefm
))
7225 error ("mode %qs applied to inappropriate type", p
);
7235 /* Handle a "section" attribute; arguments as in
7236 struct attribute_spec.handler. */
7239 handle_section_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7240 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7244 if (targetm_common
.have_named_sections
)
7246 user_defined_section_attribute
= true;
7248 if ((TREE_CODE (decl
) == FUNCTION_DECL
7249 || TREE_CODE (decl
) == VAR_DECL
)
7250 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
7252 if (TREE_CODE (decl
) == VAR_DECL
7253 && current_function_decl
!= NULL_TREE
7254 && !TREE_STATIC (decl
))
7256 error_at (DECL_SOURCE_LOCATION (decl
),
7257 "section attribute cannot be specified for "
7259 *no_add_attrs
= true;
7262 /* The decl may have already been given a section attribute
7263 from a previous declaration. Ensure they match. */
7264 else if (DECL_SECTION_NAME (decl
) != NULL_TREE
7265 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl
)),
7266 TREE_STRING_POINTER (TREE_VALUE (args
))) != 0)
7268 error ("section of %q+D conflicts with previous declaration",
7270 *no_add_attrs
= true;
7272 else if (TREE_CODE (decl
) == VAR_DECL
7273 && !targetm
.have_tls
&& targetm
.emutls
.tmpl_section
7274 && DECL_THREAD_LOCAL_P (decl
))
7276 error ("section of %q+D cannot be overridden", *node
);
7277 *no_add_attrs
= true;
7280 DECL_SECTION_NAME (decl
) = TREE_VALUE (args
);
7284 error ("section attribute not allowed for %q+D", *node
);
7285 *no_add_attrs
= true;
7290 error_at (DECL_SOURCE_LOCATION (*node
),
7291 "section attributes are not supported for this target");
7292 *no_add_attrs
= true;
7298 /* Check whether ALIGN is a valid user-specified alignment. If so,
7299 return its base-2 log; if not, output an error and return -1. If
7300 ALLOW_ZERO then 0 is valid and should result in a return of -1 with
7303 check_user_alignment (const_tree align
, bool allow_zero
)
7307 if (TREE_CODE (align
) != INTEGER_CST
7308 || !INTEGRAL_TYPE_P (TREE_TYPE (align
)))
7310 error ("requested alignment is not an integer constant");
7313 else if (allow_zero
&& integer_zerop (align
))
7315 else if (tree_int_cst_sgn (align
) == -1
7316 || (i
= tree_log2 (align
)) == -1)
7318 error ("requested alignment is not a positive power of 2");
7321 else if (i
>= HOST_BITS_PER_INT
- BITS_PER_UNIT_LOG
)
7323 error ("requested alignment is too large");
7330 If in c++-11, check if the c++-11 alignment constraint with respect
7331 to fundamental alignment (in [dcl.align]) are satisfied. If not in
7332 c++-11 mode, does nothing.
7336 [* if the constant expression evaluates to a fundamental alignment,
7337 the alignment requirement of the declared entity shall be the
7338 specified fundamental alignment.
7340 * if the constant expression evaluates to an extended alignment
7341 and the implementation supports that alignment in the context
7342 of the declaration, the alignment of the declared entity shall
7345 * if the constant expression evaluates to an extended alignment
7346 and the implementation does not support that alignment in the
7347 context of the declaration, the program is ill-formed]. */
7350 check_cxx_fundamental_alignment_constraints (tree node
,
7354 bool alignment_too_large_p
= false;
7355 unsigned requested_alignment
= 1U << align_log
;
7356 unsigned max_align
= 0;
7358 if ((!(flags
& ATTR_FLAG_CXX11
) && !warn_cxx_compat
)
7359 || (node
== NULL_TREE
|| node
== error_mark_node
))
7362 if (cxx_fundamental_alignment_p (requested_alignment
))
7367 if (TREE_STATIC (node
))
7369 /* For file scope variables and static members, the target
7370 supports alignments that are at most
7371 MAX_OFILE_ALIGNMENT. */
7372 if (requested_alignment
> (max_align
= MAX_OFILE_ALIGNMENT
))
7373 alignment_too_large_p
= true;
7377 #ifdef BIGGEST_FIELD_ALIGNMENT
7378 #define MAX_TARGET_FIELD_ALIGNMENT BIGGEST_FIELD_ALIGNMENT
7380 #define MAX_TARGET_FIELD_ALIGNMENT BIGGEST_ALIGNMENT
7382 /* For non-static members, the target supports either
7383 alignments that at most either BIGGEST_FIELD_ALIGNMENT
7384 if it is defined or BIGGEST_ALIGNMENT. */
7385 max_align
= MAX_TARGET_FIELD_ALIGNMENT
;
7386 if (TREE_CODE (node
) == FIELD_DECL
7387 && requested_alignment
> (max_align
= MAX_TARGET_FIELD_ALIGNMENT
))
7388 alignment_too_large_p
= true;
7389 #undef MAX_TARGET_FIELD_ALIGNMENT
7390 /* For stack variables, the target supports at most
7391 MAX_STACK_ALIGNMENT. */
7392 else if (decl_function_context (node
) != NULL
7393 && requested_alignment
> (max_align
= MAX_STACK_ALIGNMENT
))
7394 alignment_too_large_p
= true;
7397 else if (TYPE_P (node
))
7399 /* Let's be liberal for types. */
7400 if (requested_alignment
> (max_align
= BIGGEST_ALIGNMENT
))
7401 alignment_too_large_p
= true;
7404 if (alignment_too_large_p
)
7405 pedwarn (input_location
, OPT_Wattributes
,
7406 "requested alignment %d is larger than %d",
7407 requested_alignment
, max_align
);
7409 return !alignment_too_large_p
;
7412 /* Handle a "aligned" attribute; arguments as in
7413 struct attribute_spec.handler. */
7416 handle_aligned_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7417 int flags
, bool *no_add_attrs
)
7419 tree decl
= NULL_TREE
;
7422 tree align_expr
= (args
? TREE_VALUE (args
)
7423 : size_int (ATTRIBUTE_ALIGNED_VALUE
/ BITS_PER_UNIT
));
7429 type
= &TREE_TYPE (decl
);
7430 is_type
= TREE_CODE (*node
) == TYPE_DECL
;
7432 else if (TYPE_P (*node
))
7433 type
= node
, is_type
= 1;
7435 if ((i
= check_user_alignment (align_expr
, false)) == -1
7436 || !check_cxx_fundamental_alignment_constraints (*node
, i
, flags
))
7437 *no_add_attrs
= true;
7440 if ((flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7441 /* OK, modify the type in place. */;
7442 /* If we have a TYPE_DECL, then copy the type, so that we
7443 don't accidentally modify a builtin type. See pushdecl. */
7444 else if (decl
&& TREE_TYPE (decl
) != error_mark_node
7445 && DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
)
7447 tree tt
= TREE_TYPE (decl
);
7448 *type
= build_variant_type_copy (*type
);
7449 DECL_ORIGINAL_TYPE (decl
) = tt
;
7450 TYPE_NAME (*type
) = decl
;
7451 TREE_USED (*type
) = TREE_USED (decl
);
7452 TREE_TYPE (decl
) = *type
;
7455 *type
= build_variant_type_copy (*type
);
7457 TYPE_ALIGN (*type
) = (1U << i
) * BITS_PER_UNIT
;
7458 TYPE_USER_ALIGN (*type
) = 1;
7460 else if (! VAR_OR_FUNCTION_DECL_P (decl
)
7461 && TREE_CODE (decl
) != FIELD_DECL
)
7463 error ("alignment may not be specified for %q+D", decl
);
7464 *no_add_attrs
= true;
7466 else if (DECL_USER_ALIGN (decl
)
7467 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
7468 /* C++-11 [dcl.align/4]:
7470 When multiple alignment-specifiers are specified for an
7471 entity, the alignment requirement shall be set to the
7472 strictest specified alignment.
7474 This formally comes from the c++11 specification but we are
7475 doing it for the GNU attribute syntax as well. */
7476 *no_add_attrs
= true;
7477 else if (TREE_CODE (decl
) == FUNCTION_DECL
7478 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
7480 if (DECL_USER_ALIGN (decl
))
7481 error ("alignment for %q+D was previously specified as %d "
7482 "and may not be decreased", decl
,
7483 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
7485 error ("alignment for %q+D must be at least %d", decl
,
7486 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
7487 *no_add_attrs
= true;
7491 DECL_ALIGN (decl
) = (1U << i
) * BITS_PER_UNIT
;
7492 DECL_USER_ALIGN (decl
) = 1;
7498 /* Handle a "weak" attribute; arguments as in
7499 struct attribute_spec.handler. */
7502 handle_weak_attribute (tree
*node
, tree name
,
7503 tree
ARG_UNUSED (args
),
7504 int ARG_UNUSED (flags
),
7505 bool * ARG_UNUSED (no_add_attrs
))
7507 if (TREE_CODE (*node
) == FUNCTION_DECL
7508 && DECL_DECLARED_INLINE_P (*node
))
7510 warning (OPT_Wattributes
, "inline function %q+D declared weak", *node
);
7511 *no_add_attrs
= true;
7513 else if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
7515 error ("indirect function %q+D cannot be declared weak", *node
);
7516 *no_add_attrs
= true;
7519 else if (TREE_CODE (*node
) == FUNCTION_DECL
7520 || TREE_CODE (*node
) == VAR_DECL
)
7521 declare_weak (*node
);
7523 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7528 /* Handle an "alias" or "ifunc" attribute; arguments as in
7529 struct attribute_spec.handler, except that IS_ALIAS tells us
7530 whether this is an alias as opposed to ifunc attribute. */
7533 handle_alias_ifunc_attribute (bool is_alias
, tree
*node
, tree name
, tree args
,
7538 if (TREE_CODE (decl
) != FUNCTION_DECL
7539 && (!is_alias
|| TREE_CODE (decl
) != VAR_DECL
))
7541 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7542 *no_add_attrs
= true;
7544 else if ((TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INITIAL (decl
))
7545 || (TREE_CODE (decl
) != FUNCTION_DECL
7546 && TREE_PUBLIC (decl
) && !DECL_EXTERNAL (decl
))
7547 /* A static variable declaration is always a tentative definition,
7548 but the alias is a non-tentative definition which overrides. */
7549 || (TREE_CODE (decl
) != FUNCTION_DECL
7550 && ! TREE_PUBLIC (decl
) && DECL_INITIAL (decl
)))
7552 error ("%q+D defined both normally and as %qE attribute", decl
, name
);
7553 *no_add_attrs
= true;
7557 && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
7558 || lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
))))
7560 error ("weak %q+D cannot be defined %qE", decl
, name
);
7561 *no_add_attrs
= true;
7565 /* Note that the very first time we process a nested declaration,
7566 decl_function_context will not be set. Indeed, *would* never
7567 be set except for the DECL_INITIAL/DECL_EXTERNAL frobbery that
7568 we do below. After such frobbery, pushdecl would set the context.
7569 In any case, this is never what we want. */
7570 else if (decl_function_context (decl
) == 0 && current_function_decl
== NULL
)
7574 id
= TREE_VALUE (args
);
7575 if (TREE_CODE (id
) != STRING_CST
)
7577 error ("attribute %qE argument not a string", name
);
7578 *no_add_attrs
= true;
7581 id
= get_identifier (TREE_STRING_POINTER (id
));
7582 /* This counts as a use of the object pointed to. */
7585 if (TREE_CODE (decl
) == FUNCTION_DECL
)
7586 DECL_INITIAL (decl
) = error_mark_node
;
7588 TREE_STATIC (decl
) = 1;
7591 /* ifuncs are also aliases, so set that attribute too. */
7592 DECL_ATTRIBUTES (decl
)
7593 = tree_cons (get_identifier ("alias"), args
, DECL_ATTRIBUTES (decl
));
7597 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7598 *no_add_attrs
= true;
7604 /* Handle an "alias" or "ifunc" attribute; arguments as in
7605 struct attribute_spec.handler. */
7608 handle_ifunc_attribute (tree
*node
, tree name
, tree args
,
7609 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7611 return handle_alias_ifunc_attribute (false, node
, name
, args
, no_add_attrs
);
7614 /* Handle an "alias" or "ifunc" attribute; arguments as in
7615 struct attribute_spec.handler. */
7618 handle_alias_attribute (tree
*node
, tree name
, tree args
,
7619 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7621 return handle_alias_ifunc_attribute (true, node
, name
, args
, no_add_attrs
);
7624 /* Handle a "weakref" attribute; arguments as in struct
7625 attribute_spec.handler. */
7628 handle_weakref_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7629 int flags
, bool *no_add_attrs
)
7631 tree attr
= NULL_TREE
;
7633 /* We must ignore the attribute when it is associated with
7634 local-scoped decls, since attribute alias is ignored and many
7635 such symbols do not even have a DECL_WEAK field. */
7636 if (decl_function_context (*node
)
7637 || current_function_decl
7638 || (TREE_CODE (*node
) != VAR_DECL
&& TREE_CODE (*node
) != FUNCTION_DECL
))
7640 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7641 *no_add_attrs
= true;
7645 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
7647 error ("indirect function %q+D cannot be declared weakref", *node
);
7648 *no_add_attrs
= true;
7652 /* The idea here is that `weakref("name")' mutates into `weakref,
7653 alias("name")', and weakref without arguments, in turn,
7654 implicitly adds weak. */
7658 attr
= tree_cons (get_identifier ("alias"), args
, attr
);
7659 attr
= tree_cons (get_identifier ("weakref"), NULL_TREE
, attr
);
7661 *no_add_attrs
= true;
7663 decl_attributes (node
, attr
, flags
);
7667 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node
)))
7668 error_at (DECL_SOURCE_LOCATION (*node
),
7669 "weakref attribute must appear before alias attribute");
7671 /* Can't call declare_weak because it wants this to be TREE_PUBLIC,
7672 and that isn't supported; and because it wants to add it to
7673 the list of weak decls, which isn't helpful. */
7674 DECL_WEAK (*node
) = 1;
7680 /* Handle an "visibility" attribute; arguments as in
7681 struct attribute_spec.handler. */
7684 handle_visibility_attribute (tree
*node
, tree name
, tree args
,
7685 int ARG_UNUSED (flags
),
7686 bool *ARG_UNUSED (no_add_attrs
))
7689 tree id
= TREE_VALUE (args
);
7690 enum symbol_visibility vis
;
7694 if (TREE_CODE (*node
) == ENUMERAL_TYPE
)
7696 else if (TREE_CODE (*node
) != RECORD_TYPE
&& TREE_CODE (*node
) != UNION_TYPE
)
7698 warning (OPT_Wattributes
, "%qE attribute ignored on non-class types",
7702 else if (TYPE_FIELDS (*node
))
7704 error ("%qE attribute ignored because %qT is already defined",
7709 else if (decl_function_context (decl
) != 0 || !TREE_PUBLIC (decl
))
7711 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7715 if (TREE_CODE (id
) != STRING_CST
)
7717 error ("visibility argument not a string");
7721 /* If this is a type, set the visibility on the type decl. */
7724 decl
= TYPE_NAME (decl
);
7727 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
7729 warning (OPT_Wattributes
, "%qE attribute ignored on types",
7735 if (strcmp (TREE_STRING_POINTER (id
), "default") == 0)
7736 vis
= VISIBILITY_DEFAULT
;
7737 else if (strcmp (TREE_STRING_POINTER (id
), "internal") == 0)
7738 vis
= VISIBILITY_INTERNAL
;
7739 else if (strcmp (TREE_STRING_POINTER (id
), "hidden") == 0)
7740 vis
= VISIBILITY_HIDDEN
;
7741 else if (strcmp (TREE_STRING_POINTER (id
), "protected") == 0)
7742 vis
= VISIBILITY_PROTECTED
;
7745 error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
7746 vis
= VISIBILITY_DEFAULT
;
7749 if (DECL_VISIBILITY_SPECIFIED (decl
)
7750 && vis
!= DECL_VISIBILITY (decl
))
7752 tree attributes
= (TYPE_P (*node
)
7753 ? TYPE_ATTRIBUTES (*node
)
7754 : DECL_ATTRIBUTES (decl
));
7755 if (lookup_attribute ("visibility", attributes
))
7756 error ("%qD redeclared with different visibility", decl
);
7757 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
7758 && lookup_attribute ("dllimport", attributes
))
7759 error ("%qD was declared %qs which implies default visibility",
7761 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
7762 && lookup_attribute ("dllexport", attributes
))
7763 error ("%qD was declared %qs which implies default visibility",
7767 DECL_VISIBILITY (decl
) = vis
;
7768 DECL_VISIBILITY_SPECIFIED (decl
) = 1;
7770 /* Go ahead and attach the attribute to the node as well. This is needed
7771 so we can determine whether we have VISIBILITY_DEFAULT because the
7772 visibility was not specified, or because it was explicitly overridden
7773 from the containing scope. */
7778 /* Determine the ELF symbol visibility for DECL, which is either a
7779 variable or a function. It is an error to use this function if a
7780 definition of DECL is not available in this translation unit.
7781 Returns true if the final visibility has been determined by this
7782 function; false if the caller is free to make additional
7786 c_determine_visibility (tree decl
)
7788 gcc_assert (TREE_CODE (decl
) == VAR_DECL
7789 || TREE_CODE (decl
) == FUNCTION_DECL
);
7791 /* If the user explicitly specified the visibility with an
7792 attribute, honor that. DECL_VISIBILITY will have been set during
7793 the processing of the attribute. We check for an explicit
7794 attribute, rather than just checking DECL_VISIBILITY_SPECIFIED,
7795 to distinguish the use of an attribute from the use of a "#pragma
7796 GCC visibility push(...)"; in the latter case we still want other
7797 considerations to be able to overrule the #pragma. */
7798 if (lookup_attribute ("visibility", DECL_ATTRIBUTES (decl
))
7799 || (TARGET_DLLIMPORT_DECL_ATTRIBUTES
7800 && (lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl
))
7801 || lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl
)))))
7804 /* Set default visibility to whatever the user supplied with
7805 visibility_specified depending on #pragma GCC visibility. */
7806 if (!DECL_VISIBILITY_SPECIFIED (decl
))
7808 if (visibility_options
.inpragma
7809 || DECL_VISIBILITY (decl
) != default_visibility
)
7811 DECL_VISIBILITY (decl
) = default_visibility
;
7812 DECL_VISIBILITY_SPECIFIED (decl
) = visibility_options
.inpragma
;
7813 /* If visibility changed and DECL already has DECL_RTL, ensure
7814 symbol flags are updated. */
7815 if (((TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
))
7816 || TREE_CODE (decl
) == FUNCTION_DECL
)
7817 && DECL_RTL_SET_P (decl
))
7818 make_decl_rtl (decl
);
7824 /* Handle an "tls_model" attribute; arguments as in
7825 struct attribute_spec.handler. */
7828 handle_tls_model_attribute (tree
*node
, tree name
, tree args
,
7829 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7833 enum tls_model kind
;
7835 *no_add_attrs
= true;
7837 if (TREE_CODE (decl
) != VAR_DECL
|| !DECL_THREAD_LOCAL_P (decl
))
7839 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7843 kind
= DECL_TLS_MODEL (decl
);
7844 id
= TREE_VALUE (args
);
7845 if (TREE_CODE (id
) != STRING_CST
)
7847 error ("tls_model argument not a string");
7851 if (!strcmp (TREE_STRING_POINTER (id
), "local-exec"))
7852 kind
= TLS_MODEL_LOCAL_EXEC
;
7853 else if (!strcmp (TREE_STRING_POINTER (id
), "initial-exec"))
7854 kind
= TLS_MODEL_INITIAL_EXEC
;
7855 else if (!strcmp (TREE_STRING_POINTER (id
), "local-dynamic"))
7856 kind
= optimize
? TLS_MODEL_LOCAL_DYNAMIC
: TLS_MODEL_GLOBAL_DYNAMIC
;
7857 else if (!strcmp (TREE_STRING_POINTER (id
), "global-dynamic"))
7858 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
7860 error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
7862 DECL_TLS_MODEL (decl
) = kind
;
7866 /* Handle a "no_instrument_function" attribute; arguments as in
7867 struct attribute_spec.handler. */
7870 handle_no_instrument_function_attribute (tree
*node
, tree name
,
7871 tree
ARG_UNUSED (args
),
7872 int ARG_UNUSED (flags
),
7877 if (TREE_CODE (decl
) != FUNCTION_DECL
)
7879 error_at (DECL_SOURCE_LOCATION (decl
),
7880 "%qE attribute applies only to functions", name
);
7881 *no_add_attrs
= true;
7883 else if (DECL_INITIAL (decl
))
7885 error_at (DECL_SOURCE_LOCATION (decl
),
7886 "can%'t set %qE attribute after definition", name
);
7887 *no_add_attrs
= true;
7890 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
7895 /* Handle a "malloc" attribute; arguments as in
7896 struct attribute_spec.handler. */
7899 handle_malloc_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7900 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7902 if (TREE_CODE (*node
) == FUNCTION_DECL
7903 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node
))))
7904 DECL_IS_MALLOC (*node
) = 1;
7907 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7908 *no_add_attrs
= true;
7914 /* Handle a "alloc_size" attribute; arguments as in
7915 struct attribute_spec.handler. */
7918 handle_alloc_size_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7919 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7921 unsigned arg_count
= type_num_arguments (*node
);
7922 for (; args
; args
= TREE_CHAIN (args
))
7924 tree position
= TREE_VALUE (args
);
7927 if (TREE_CODE (position
) != INTEGER_CST
7928 || (p
= wide_int (position
)).ltu_p (1)
7929 || p
.gtu_p (arg_count
) )
7931 warning (OPT_Wattributes
,
7932 "alloc_size parameter outside range");
7933 *no_add_attrs
= true;
7940 /* Handle a "fn spec" attribute; arguments as in
7941 struct attribute_spec.handler. */
7944 handle_fnspec_attribute (tree
*node ATTRIBUTE_UNUSED
, tree
ARG_UNUSED (name
),
7945 tree args
, int ARG_UNUSED (flags
),
7946 bool *no_add_attrs ATTRIBUTE_UNUSED
)
7949 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
7950 && !TREE_CHAIN (args
));
7954 /* Handle a "warn_unused" attribute; arguments as in
7955 struct attribute_spec.handler. */
7958 handle_warn_unused_attribute (tree
*node
, tree name
,
7959 tree args ATTRIBUTE_UNUSED
,
7960 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
7963 /* Do nothing else, just set the attribute. We'll get at
7964 it later with lookup_attribute. */
7968 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7969 *no_add_attrs
= true;
7975 /* Handle a "returns_twice" attribute; arguments as in
7976 struct attribute_spec.handler. */
7979 handle_returns_twice_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7980 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7982 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7983 DECL_IS_RETURNS_TWICE (*node
) = 1;
7986 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7987 *no_add_attrs
= true;
7993 /* Handle a "no_limit_stack" attribute; arguments as in
7994 struct attribute_spec.handler. */
7997 handle_no_limit_stack_attribute (tree
*node
, tree name
,
7998 tree
ARG_UNUSED (args
),
7999 int ARG_UNUSED (flags
),
8004 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8006 error_at (DECL_SOURCE_LOCATION (decl
),
8007 "%qE attribute applies only to functions", name
);
8008 *no_add_attrs
= true;
8010 else if (DECL_INITIAL (decl
))
8012 error_at (DECL_SOURCE_LOCATION (decl
),
8013 "can%'t set %qE attribute after definition", name
);
8014 *no_add_attrs
= true;
8017 DECL_NO_LIMIT_STACK (decl
) = 1;
8022 /* Handle a "pure" attribute; arguments as in
8023 struct attribute_spec.handler. */
8026 handle_pure_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8027 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8029 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8030 DECL_PURE_P (*node
) = 1;
8031 /* ??? TODO: Support types. */
8034 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8035 *no_add_attrs
= true;
8041 /* Digest an attribute list destined for a transactional memory statement.
8042 ALLOWED is the set of attributes that are allowed for this statement;
8043 return the attribute we parsed. Multiple attributes are never allowed. */
8046 parse_tm_stmt_attr (tree attrs
, int allowed
)
8051 for ( ; attrs
; attrs
= TREE_CHAIN (attrs
))
8053 tree a
= TREE_PURPOSE (attrs
);
8056 if (is_attribute_p ("outer", a
))
8057 m
= TM_STMT_ATTR_OUTER
;
8059 if ((m
& allowed
) == 0)
8061 warning (OPT_Wattributes
, "%qE attribute directive ignored", a
);
8070 else if (m_seen
== m
)
8071 warning (OPT_Wattributes
, "%qE attribute duplicated", a
);
8073 warning (OPT_Wattributes
, "%qE attribute follows %qE", a
, a_seen
);
8079 /* Transform a TM attribute name into a maskable integer and back.
8080 Note that NULL (i.e. no attribute) is mapped to UNKNOWN, corresponding
8081 to how the lack of an attribute is treated. */
8084 tm_attr_to_mask (tree attr
)
8088 if (is_attribute_p ("transaction_safe", attr
))
8089 return TM_ATTR_SAFE
;
8090 if (is_attribute_p ("transaction_callable", attr
))
8091 return TM_ATTR_CALLABLE
;
8092 if (is_attribute_p ("transaction_pure", attr
))
8093 return TM_ATTR_PURE
;
8094 if (is_attribute_p ("transaction_unsafe", attr
))
8095 return TM_ATTR_IRREVOCABLE
;
8096 if (is_attribute_p ("transaction_may_cancel_outer", attr
))
8097 return TM_ATTR_MAY_CANCEL_OUTER
;
8102 tm_mask_to_attr (int mask
)
8108 str
= "transaction_safe";
8110 case TM_ATTR_CALLABLE
:
8111 str
= "transaction_callable";
8114 str
= "transaction_pure";
8116 case TM_ATTR_IRREVOCABLE
:
8117 str
= "transaction_unsafe";
8119 case TM_ATTR_MAY_CANCEL_OUTER
:
8120 str
= "transaction_may_cancel_outer";
8125 return get_identifier (str
);
8128 /* Return the first TM attribute seen in LIST. */
8131 find_tm_attribute (tree list
)
8133 for (; list
; list
= TREE_CHAIN (list
))
8135 tree name
= TREE_PURPOSE (list
);
8136 if (tm_attr_to_mask (name
) != 0)
8142 /* Handle the TM attributes; arguments as in struct attribute_spec.handler.
8143 Here we accept only function types, and verify that none of the other
8144 function TM attributes are also applied. */
8145 /* ??? We need to accept class types for C++, but not C. This greatly
8146 complicates this function, since we can no longer rely on the extra
8147 processing given by function_type_required. */
8150 handle_tm_attribute (tree
*node
, tree name
, tree args
,
8151 int flags
, bool *no_add_attrs
)
8153 /* Only one path adds the attribute; others don't. */
8154 *no_add_attrs
= true;
8156 switch (TREE_CODE (*node
))
8160 /* Only tm_callable and tm_safe apply to classes. */
8161 if (tm_attr_to_mask (name
) & ~(TM_ATTR_SAFE
| TM_ATTR_CALLABLE
))
8168 tree old_name
= find_tm_attribute (TYPE_ATTRIBUTES (*node
));
8169 if (old_name
== name
)
8171 else if (old_name
!= NULL_TREE
)
8172 error ("type was previously declared %qE", old_name
);
8174 *no_add_attrs
= false;
8180 enum tree_code subcode
= TREE_CODE (TREE_TYPE (*node
));
8181 if (subcode
== FUNCTION_TYPE
|| subcode
== METHOD_TYPE
)
8183 tree fn_tmp
= TREE_TYPE (*node
);
8184 decl_attributes (&fn_tmp
, tree_cons (name
, args
, NULL
), 0);
8185 *node
= build_pointer_type (fn_tmp
);
8192 /* If a function is next, pass it on to be tried next. */
8193 if (flags
& (int) ATTR_FLAG_FUNCTION_NEXT
)
8194 return tree_cons (name
, args
, NULL
);
8197 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8204 /* Handle the TM_WRAP attribute; arguments as in
8205 struct attribute_spec.handler. */
8208 handle_tm_wrap_attribute (tree
*node
, tree name
, tree args
,
8209 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8213 /* We don't need the attribute even on success, since we
8214 record the entry in an external table. */
8215 *no_add_attrs
= true;
8217 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8218 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8221 tree wrap_decl
= TREE_VALUE (args
);
8222 if (TREE_CODE (wrap_decl
) != IDENTIFIER_NODE
8223 && TREE_CODE (wrap_decl
) != VAR_DECL
8224 && TREE_CODE (wrap_decl
) != FUNCTION_DECL
)
8225 error ("%qE argument not an identifier", name
);
8228 if (TREE_CODE (wrap_decl
) == IDENTIFIER_NODE
)
8229 wrap_decl
= lookup_name (wrap_decl
);
8230 if (wrap_decl
&& TREE_CODE (wrap_decl
) == FUNCTION_DECL
)
8232 if (lang_hooks
.types_compatible_p (TREE_TYPE (decl
),
8233 TREE_TYPE (wrap_decl
)))
8234 record_tm_replacement (wrap_decl
, decl
);
8236 error ("%qD is not compatible with %qD", wrap_decl
, decl
);
8239 error ("transaction_wrap argument is not a function");
8246 /* Ignore the given attribute. Used when this attribute may be usefully
8247 overridden by the target, but is not used generically. */
8250 ignore_attribute (tree
* ARG_UNUSED (node
), tree
ARG_UNUSED (name
),
8251 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
8254 *no_add_attrs
= true;
8258 /* Handle a "no vops" attribute; arguments as in
8259 struct attribute_spec.handler. */
8262 handle_novops_attribute (tree
*node
, tree
ARG_UNUSED (name
),
8263 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
8264 bool *ARG_UNUSED (no_add_attrs
))
8266 gcc_assert (TREE_CODE (*node
) == FUNCTION_DECL
);
8267 DECL_IS_NOVOPS (*node
) = 1;
8271 /* Handle a "deprecated" attribute; arguments as in
8272 struct attribute_spec.handler. */
8275 handle_deprecated_attribute (tree
*node
, tree name
,
8276 tree args
, int flags
,
8279 tree type
= NULL_TREE
;
8281 tree what
= NULL_TREE
;
8284 *no_add_attrs
= true;
8285 else if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
8287 error ("deprecated message is not a string");
8288 *no_add_attrs
= true;
8294 type
= TREE_TYPE (decl
);
8296 if (TREE_CODE (decl
) == TYPE_DECL
8297 || TREE_CODE (decl
) == PARM_DECL
8298 || TREE_CODE (decl
) == VAR_DECL
8299 || TREE_CODE (decl
) == FUNCTION_DECL
8300 || TREE_CODE (decl
) == FIELD_DECL
8301 || objc_method_decl (TREE_CODE (decl
)))
8302 TREE_DEPRECATED (decl
) = 1;
8306 else if (TYPE_P (*node
))
8308 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
8309 *node
= build_variant_type_copy (*node
);
8310 TREE_DEPRECATED (*node
) = 1;
8318 *no_add_attrs
= true;
8319 if (type
&& TYPE_NAME (type
))
8321 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
8322 what
= TYPE_NAME (*node
);
8323 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
8324 && DECL_NAME (TYPE_NAME (type
)))
8325 what
= DECL_NAME (TYPE_NAME (type
));
8328 warning (OPT_Wattributes
, "%qE attribute ignored for %qE", name
, what
);
8330 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8336 /* Handle a "vector_size" attribute; arguments as in
8337 struct attribute_spec.handler. */
8340 handle_vector_size_attribute (tree
*node
, tree name
, tree args
,
8341 int ARG_UNUSED (flags
),
8344 unsigned HOST_WIDE_INT vecsize
, nunits
;
8345 enum machine_mode orig_mode
;
8346 tree type
= *node
, new_type
, size
;
8348 *no_add_attrs
= true;
8350 size
= TREE_VALUE (args
);
8352 if (!tree_fits_uhwi_p (size
))
8354 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8358 /* Get the vector size (in bytes). */
8359 vecsize
= tree_to_uhwi (size
);
8361 /* We need to provide for vector pointers, vector arrays, and
8362 functions returning vectors. For example:
8364 __attribute__((vector_size(16))) short *foo;
8366 In this case, the mode is SI, but the type being modified is
8367 HI, so we need to look further. */
8369 while (POINTER_TYPE_P (type
)
8370 || TREE_CODE (type
) == FUNCTION_TYPE
8371 || TREE_CODE (type
) == METHOD_TYPE
8372 || TREE_CODE (type
) == ARRAY_TYPE
8373 || TREE_CODE (type
) == OFFSET_TYPE
)
8374 type
= TREE_TYPE (type
);
8376 /* Get the mode of the type being modified. */
8377 orig_mode
= TYPE_MODE (type
);
8379 if ((!INTEGRAL_TYPE_P (type
)
8380 && !SCALAR_FLOAT_TYPE_P (type
)
8381 && !FIXED_POINT_TYPE_P (type
))
8382 || (!SCALAR_FLOAT_MODE_P (orig_mode
)
8383 && GET_MODE_CLASS (orig_mode
) != MODE_INT
8384 && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode
))
8385 || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
8386 || TREE_CODE (type
) == BOOLEAN_TYPE
)
8388 error ("invalid vector type for attribute %qE", name
);
8392 if (vecsize
% tree_to_uhwi (TYPE_SIZE_UNIT (type
)))
8394 error ("vector size not an integral multiple of component size");
8400 error ("zero vector size");
8404 /* Calculate how many units fit in the vector. */
8405 nunits
= vecsize
/ tree_to_uhwi (TYPE_SIZE_UNIT (type
));
8406 if (nunits
& (nunits
- 1))
8408 error ("number of components of the vector not a power of two");
8412 new_type
= build_vector_type (type
, nunits
);
8414 /* Build back pointers if needed. */
8415 *node
= lang_hooks
.types
.reconstruct_complex_type (*node
, new_type
);
8420 /* Handle the "nonnull" attribute. */
8422 handle_nonnull_attribute (tree
*node
, tree
ARG_UNUSED (name
),
8423 tree args
, int ARG_UNUSED (flags
),
8427 unsigned HOST_WIDE_INT attr_arg_num
;
8429 /* If no arguments are specified, all pointer arguments should be
8430 non-null. Verify a full prototype is given so that the arguments
8431 will have the correct types when we actually check them later. */
8434 if (!prototype_p (type
))
8436 error ("nonnull attribute without arguments on a non-prototype");
8437 *no_add_attrs
= true;
8442 /* Argument list specified. Verify that each argument number references
8443 a pointer argument. */
8444 for (attr_arg_num
= 1; args
; args
= TREE_CHAIN (args
))
8446 unsigned HOST_WIDE_INT arg_num
= 0, ck_num
;
8448 if (!get_nonnull_operand (TREE_VALUE (args
), &arg_num
))
8450 error ("nonnull argument has invalid operand number (argument %lu)",
8451 (unsigned long) attr_arg_num
);
8452 *no_add_attrs
= true;
8456 if (prototype_p (type
))
8458 function_args_iterator iter
;
8461 function_args_iter_init (&iter
, type
);
8462 for (ck_num
= 1; ; ck_num
++, function_args_iter_next (&iter
))
8464 argument
= function_args_iter_cond (&iter
);
8465 if (argument
== NULL_TREE
|| ck_num
== arg_num
)
8470 || TREE_CODE (argument
) == VOID_TYPE
)
8472 error ("nonnull argument with out-of-range operand number (argument %lu, operand %lu)",
8473 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
8474 *no_add_attrs
= true;
8478 if (TREE_CODE (argument
) != POINTER_TYPE
)
8480 error ("nonnull argument references non-pointer operand (argument %lu, operand %lu)",
8481 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
8482 *no_add_attrs
= true;
8491 /* Check the argument list of a function call for null in argument slots
8492 that are marked as requiring a non-null pointer argument. The NARGS
8493 arguments are passed in the array ARGARRAY.
8497 check_function_nonnull (tree attrs
, int nargs
, tree
*argarray
)
8502 attrs
= lookup_attribute ("nonnull", attrs
);
8503 if (attrs
== NULL_TREE
)
8507 /* See if any of the nonnull attributes has no arguments. If so,
8508 then every pointer argument is checked (in which case the check
8509 for pointer type is done in check_nonnull_arg). */
8510 if (TREE_VALUE (a
) != NULL_TREE
)
8512 a
= lookup_attribute ("nonnull", TREE_CHAIN (a
));
8513 while (a
!= NULL_TREE
&& TREE_VALUE (a
) != NULL_TREE
);
8516 for (i
= 0; i
< nargs
; i
++)
8517 check_function_arguments_recurse (check_nonnull_arg
, NULL
, argarray
[i
],
8521 /* Walk the argument list. If we encounter an argument number we
8522 should check for non-null, do it. */
8523 for (i
= 0; i
< nargs
; i
++)
8525 for (a
= attrs
; ; a
= TREE_CHAIN (a
))
8527 a
= lookup_attribute ("nonnull", a
);
8528 if (a
== NULL_TREE
|| nonnull_check_p (TREE_VALUE (a
), i
+ 1))
8533 check_function_arguments_recurse (check_nonnull_arg
, NULL
,
8534 argarray
[i
], i
+ 1);
8539 /* Check that the Nth argument of a function call (counting backwards
8540 from the end) is a (pointer)0. The NARGS arguments are passed in the
8544 check_function_sentinel (const_tree fntype
, int nargs
, tree
*argarray
)
8546 tree attr
= lookup_attribute ("sentinel", TYPE_ATTRIBUTES (fntype
));
8553 function_args_iterator iter
;
8556 /* Skip over the named arguments. */
8557 FOREACH_FUNCTION_ARGS (fntype
, t
, iter
)
8564 if (TREE_VALUE (attr
))
8566 tree p
= TREE_VALUE (TREE_VALUE (attr
));
8567 pos
= tree_to_hwi (p
);
8570 /* The sentinel must be one of the varargs, i.e.
8571 in position >= the number of fixed arguments. */
8572 if ((nargs
- 1 - pos
) < len
)
8574 warning (OPT_Wformat_
,
8575 "not enough variable arguments to fit a sentinel");
8579 /* Validate the sentinel. */
8580 sentinel
= argarray
[nargs
- 1 - pos
];
8581 if ((!POINTER_TYPE_P (TREE_TYPE (sentinel
))
8582 || !integer_zerop (sentinel
))
8583 /* Although __null (in C++) is only an integer we allow it
8584 nevertheless, as we are guaranteed that it's exactly
8585 as wide as a pointer, and we don't want to force
8586 users to cast the NULL they have written there.
8587 We warn with -Wstrict-null-sentinel, though. */
8588 && (warn_strict_null_sentinel
|| null_node
!= sentinel
))
8589 warning (OPT_Wformat_
, "missing sentinel in function call");
8593 /* Helper for check_function_nonnull; given a list of operands which
8594 must be non-null in ARGS, determine if operand PARAM_NUM should be
8598 nonnull_check_p (tree args
, unsigned HOST_WIDE_INT param_num
)
8600 unsigned HOST_WIDE_INT arg_num
= 0;
8602 for (; args
; args
= TREE_CHAIN (args
))
8604 bool found
= get_nonnull_operand (TREE_VALUE (args
), &arg_num
);
8608 if (arg_num
== param_num
)
8614 /* Check that the function argument PARAM (which is operand number
8615 PARAM_NUM) is non-null. This is called by check_function_nonnull
8616 via check_function_arguments_recurse. */
8619 check_nonnull_arg (void * ARG_UNUSED (ctx
), tree param
,
8620 unsigned HOST_WIDE_INT param_num
)
8622 /* Just skip checking the argument if it's not a pointer. This can
8623 happen if the "nonnull" attribute was given without an operand
8624 list (which means to check every pointer argument). */
8626 if (TREE_CODE (TREE_TYPE (param
)) != POINTER_TYPE
)
8629 if (integer_zerop (param
))
8630 warning (OPT_Wnonnull
, "null argument where non-null required "
8631 "(argument %lu)", (unsigned long) param_num
);
8634 /* Helper for nonnull attribute handling; fetch the operand number
8635 from the attribute argument list. */
8638 get_nonnull_operand (tree arg_num_expr
, unsigned HOST_WIDE_INT
*valp
)
8640 /* Verify the arg number is a small constant. */
8641 if (cst_fits_uhwi_p (arg_num_expr
))
8643 *valp
= tree_to_hwi (arg_num_expr
);
8650 /* Handle a "nothrow" attribute; arguments as in
8651 struct attribute_spec.handler. */
8654 handle_nothrow_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8655 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8657 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8658 TREE_NOTHROW (*node
) = 1;
8659 /* ??? TODO: Support types. */
8662 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8663 *no_add_attrs
= true;
8669 /* Handle a "cleanup" attribute; arguments as in
8670 struct attribute_spec.handler. */
8673 handle_cleanup_attribute (tree
*node
, tree name
, tree args
,
8674 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8677 tree cleanup_id
, cleanup_decl
;
8679 /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
8680 for global destructors in C++. This requires infrastructure that
8681 we don't have generically at the moment. It's also not a feature
8682 we'd be missing too much, since we do have attribute constructor. */
8683 if (TREE_CODE (decl
) != VAR_DECL
|| TREE_STATIC (decl
))
8685 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8686 *no_add_attrs
= true;
8690 /* Verify that the argument is a function in scope. */
8691 /* ??? We could support pointers to functions here as well, if
8692 that was considered desirable. */
8693 cleanup_id
= TREE_VALUE (args
);
8694 if (TREE_CODE (cleanup_id
) != IDENTIFIER_NODE
)
8696 error ("cleanup argument not an identifier");
8697 *no_add_attrs
= true;
8700 cleanup_decl
= lookup_name (cleanup_id
);
8701 if (!cleanup_decl
|| TREE_CODE (cleanup_decl
) != FUNCTION_DECL
)
8703 error ("cleanup argument not a function");
8704 *no_add_attrs
= true;
8708 /* That the function has proper type is checked with the
8709 eventual call to build_function_call. */
8714 /* Handle a "warn_unused_result" attribute. No special handling. */
8717 handle_warn_unused_result_attribute (tree
*node
, tree name
,
8718 tree
ARG_UNUSED (args
),
8719 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8721 /* Ignore the attribute for functions not returning any value. */
8722 if (VOID_TYPE_P (TREE_TYPE (*node
)))
8724 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8725 *no_add_attrs
= true;
8731 /* Handle a "sentinel" attribute. */
8734 handle_sentinel_attribute (tree
*node
, tree name
, tree args
,
8735 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8737 if (!prototype_p (*node
))
8739 warning (OPT_Wattributes
,
8740 "%qE attribute requires prototypes with named arguments", name
);
8741 *no_add_attrs
= true;
8745 if (!stdarg_p (*node
))
8747 warning (OPT_Wattributes
,
8748 "%qE attribute only applies to variadic functions", name
);
8749 *no_add_attrs
= true;
8755 tree position
= TREE_VALUE (args
);
8757 if (TREE_CODE (position
) != INTEGER_CST
)
8759 warning (OPT_Wattributes
,
8760 "requested position is not an integer constant");
8761 *no_add_attrs
= true;
8765 if (tree_int_cst_lt (position
, integer_zero_node
))
8767 warning (OPT_Wattributes
,
8768 "requested position is less than zero");
8769 *no_add_attrs
= true;
8777 /* Handle a "type_generic" attribute. */
8780 handle_type_generic_attribute (tree
*node
, tree
ARG_UNUSED (name
),
8781 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
8782 bool * ARG_UNUSED (no_add_attrs
))
8784 /* Ensure we have a function type. */
8785 gcc_assert (TREE_CODE (*node
) == FUNCTION_TYPE
);
8787 /* Ensure we have a variadic function. */
8788 gcc_assert (!prototype_p (*node
) || stdarg_p (*node
));
8793 /* Handle a "target" attribute. */
8796 handle_target_attribute (tree
*node
, tree name
, tree args
, int flags
,
8799 /* Ensure we have a function type. */
8800 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8802 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8803 *no_add_attrs
= true;
8805 else if (! targetm
.target_option
.valid_attribute_p (*node
, name
, args
,
8807 *no_add_attrs
= true;
8812 /* Arguments being collected for optimization. */
8813 typedef const char *const_char_p
; /* For DEF_VEC_P. */
8814 static GTY(()) vec
<const_char_p
, va_gc
> *optimize_args
;
8817 /* Inner function to convert a TREE_LIST to argv string to parse the optimize
8818 options in ARGS. ATTR_P is true if this is for attribute(optimize), and
8819 false for #pragma GCC optimize. */
8822 parse_optimize_options (tree args
, bool attr_p
)
8827 int saved_flag_strict_aliasing
;
8828 const char **opt_argv
;
8829 struct cl_decoded_option
*decoded_options
;
8830 unsigned int decoded_options_count
;
8833 /* Build up argv vector. Just in case the string is stored away, use garbage
8834 collected strings. */
8835 vec_safe_truncate (optimize_args
, 0);
8836 vec_safe_push (optimize_args
, (const char *) NULL
);
8838 for (ap
= args
; ap
!= NULL_TREE
; ap
= TREE_CHAIN (ap
))
8840 tree value
= TREE_VALUE (ap
);
8842 if (TREE_CODE (value
) == INTEGER_CST
)
8845 sprintf (buffer
, "-O%ld", (long) tree_to_hwi (value
));
8846 vec_safe_push (optimize_args
, ggc_strdup (buffer
));
8849 else if (TREE_CODE (value
) == STRING_CST
)
8851 /* Split string into multiple substrings. */
8852 size_t len
= TREE_STRING_LENGTH (value
);
8853 char *p
= ASTRDUP (TREE_STRING_POINTER (value
));
8854 char *end
= p
+ len
;
8858 while (next_p
!= NULL
)
8864 comma
= strchr (p
, ',');
8877 r
= q
= (char *) ggc_alloc_atomic (len2
+ 3);
8879 /* If the user supplied -Oxxx or -fxxx, only allow -Oxxx or -fxxx
8881 if (*p
== '-' && p
[1] != 'O' && p
[1] != 'f')
8885 warning (OPT_Wattributes
,
8886 "bad option %s to optimize attribute", p
);
8888 warning (OPT_Wpragmas
,
8889 "bad option %s to pragma attribute", p
);
8897 /* Assume that Ox is -Ox, a numeric value is -Ox, a s by
8898 itself is -Os, and any other switch begins with a -f. */
8899 if ((*p
>= '0' && *p
<= '9')
8900 || (p
[0] == 's' && p
[1] == '\0'))
8906 memcpy (r
, p
, len2
);
8908 vec_safe_push (optimize_args
, (const char *) q
);
8914 opt_argc
= optimize_args
->length ();
8915 opt_argv
= (const char **) alloca (sizeof (char *) * (opt_argc
+ 1));
8917 for (i
= 1; i
< opt_argc
; i
++)
8918 opt_argv
[i
] = (*optimize_args
)[i
];
8920 saved_flag_strict_aliasing
= flag_strict_aliasing
;
8922 /* Now parse the options. */
8923 decode_cmdline_options_to_array_default_mask (opt_argc
, opt_argv
,
8925 &decoded_options_count
);
8926 decode_options (&global_options
, &global_options_set
,
8927 decoded_options
, decoded_options_count
,
8928 input_location
, global_dc
);
8930 targetm
.override_options_after_change();
8932 /* Don't allow changing -fstrict-aliasing. */
8933 flag_strict_aliasing
= saved_flag_strict_aliasing
;
8935 optimize_args
->truncate (0);
8939 /* For handling "optimize" attribute. arguments as in
8940 struct attribute_spec.handler. */
8943 handle_optimize_attribute (tree
*node
, tree name
, tree args
,
8944 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8946 /* Ensure we have a function type. */
8947 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8949 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8950 *no_add_attrs
= true;
8954 struct cl_optimization cur_opts
;
8955 tree old_opts
= DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
);
8957 /* Save current options. */
8958 cl_optimization_save (&cur_opts
, &global_options
);
8960 /* If we previously had some optimization options, use them as the
8963 cl_optimization_restore (&global_options
,
8964 TREE_OPTIMIZATION (old_opts
));
8966 /* Parse options, and update the vector. */
8967 parse_optimize_options (args
, true);
8968 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
)
8969 = build_optimization_node ();
8971 /* Restore current options. */
8972 cl_optimization_restore (&global_options
, &cur_opts
);
8978 /* Handle a "no_split_stack" attribute. */
8981 handle_no_split_stack_attribute (tree
*node
, tree name
,
8982 tree
ARG_UNUSED (args
),
8983 int ARG_UNUSED (flags
),
8988 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8990 error_at (DECL_SOURCE_LOCATION (decl
),
8991 "%qE attribute applies only to functions", name
);
8992 *no_add_attrs
= true;
8994 else if (DECL_INITIAL (decl
))
8996 error_at (DECL_SOURCE_LOCATION (decl
),
8997 "can%'t set %qE attribute after definition", name
);
8998 *no_add_attrs
= true;
9004 /* Check for valid arguments being passed to a function with FNTYPE.
9005 There are NARGS arguments in the array ARGARRAY. */
9007 check_function_arguments (const_tree fntype
, int nargs
, tree
*argarray
)
9009 /* Check for null being passed in a pointer argument that must be
9010 non-null. We also need to do this if format checking is enabled. */
9013 check_function_nonnull (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
9015 /* Check for errors in format strings. */
9017 if (warn_format
|| warn_suggest_attribute_format
)
9018 check_function_format (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
9021 check_function_sentinel (fntype
, nargs
, argarray
);
9024 /* Generic argument checking recursion routine. PARAM is the argument to
9025 be checked. PARAM_NUM is the number of the argument. CALLBACK is invoked
9026 once the argument is resolved. CTX is context for the callback. */
9028 check_function_arguments_recurse (void (*callback
)
9029 (void *, tree
, unsigned HOST_WIDE_INT
),
9030 void *ctx
, tree param
,
9031 unsigned HOST_WIDE_INT param_num
)
9033 if (CONVERT_EXPR_P (param
)
9034 && (TYPE_PRECISION (TREE_TYPE (param
))
9035 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (param
, 0)))))
9037 /* Strip coercion. */
9038 check_function_arguments_recurse (callback
, ctx
,
9039 TREE_OPERAND (param
, 0), param_num
);
9043 if (TREE_CODE (param
) == CALL_EXPR
)
9045 tree type
= TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (param
)));
9047 bool found_format_arg
= false;
9049 /* See if this is a call to a known internationalization function
9050 that modifies a format arg. Such a function may have multiple
9051 format_arg attributes (for example, ngettext). */
9053 for (attrs
= TYPE_ATTRIBUTES (type
);
9055 attrs
= TREE_CHAIN (attrs
))
9056 if (is_attribute_p ("format_arg", TREE_PURPOSE (attrs
)))
9059 tree format_num_expr
;
9062 call_expr_arg_iterator iter
;
9064 /* Extract the argument number, which was previously checked
9066 format_num_expr
= TREE_VALUE (TREE_VALUE (attrs
));
9068 gcc_assert (tree_fits_uhwi_p (format_num_expr
));
9070 format_num
= tree_to_uhwi (format_num_expr
);
9072 for (inner_arg
= first_call_expr_arg (param
, &iter
), i
= 1;
9074 inner_arg
= next_call_expr_arg (&iter
), i
++)
9075 if (i
== format_num
)
9077 check_function_arguments_recurse (callback
, ctx
,
9078 inner_arg
, param_num
);
9079 found_format_arg
= true;
9084 /* If we found a format_arg attribute and did a recursive check,
9085 we are done with checking this argument. Otherwise, we continue
9086 and this will be considered a non-literal. */
9087 if (found_format_arg
)
9091 if (TREE_CODE (param
) == COND_EXPR
)
9093 /* Check both halves of the conditional expression. */
9094 check_function_arguments_recurse (callback
, ctx
,
9095 TREE_OPERAND (param
, 1), param_num
);
9096 check_function_arguments_recurse (callback
, ctx
,
9097 TREE_OPERAND (param
, 2), param_num
);
9101 (*callback
) (ctx
, param
, param_num
);
9104 /* Checks for a builtin function FNDECL that the number of arguments
9105 NARGS against the required number REQUIRED and issues an error if
9106 there is a mismatch. Returns true if the number of arguments is
9107 correct, otherwise false. */
9110 builtin_function_validate_nargs (tree fndecl
, int nargs
, int required
)
9112 if (nargs
< required
)
9114 error_at (input_location
,
9115 "not enough arguments to function %qE", fndecl
);
9118 else if (nargs
> required
)
9120 error_at (input_location
,
9121 "too many arguments to function %qE", fndecl
);
9127 /* Verifies the NARGS arguments ARGS to the builtin function FNDECL.
9128 Returns false if there was an error, otherwise true. */
9131 check_builtin_function_arguments (tree fndecl
, int nargs
, tree
*args
)
9133 if (!DECL_BUILT_IN (fndecl
)
9134 || DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_NORMAL
)
9137 switch (DECL_FUNCTION_CODE (fndecl
))
9139 case BUILT_IN_CONSTANT_P
:
9140 return builtin_function_validate_nargs (fndecl
, nargs
, 1);
9142 case BUILT_IN_ISFINITE
:
9143 case BUILT_IN_ISINF
:
9144 case BUILT_IN_ISINF_SIGN
:
9145 case BUILT_IN_ISNAN
:
9146 case BUILT_IN_ISNORMAL
:
9147 if (builtin_function_validate_nargs (fndecl
, nargs
, 1))
9149 if (TREE_CODE (TREE_TYPE (args
[0])) != REAL_TYPE
)
9151 error ("non-floating-point argument in call to "
9152 "function %qE", fndecl
);
9159 case BUILT_IN_ISGREATER
:
9160 case BUILT_IN_ISGREATEREQUAL
:
9161 case BUILT_IN_ISLESS
:
9162 case BUILT_IN_ISLESSEQUAL
:
9163 case BUILT_IN_ISLESSGREATER
:
9164 case BUILT_IN_ISUNORDERED
:
9165 if (builtin_function_validate_nargs (fndecl
, nargs
, 2))
9167 enum tree_code code0
, code1
;
9168 code0
= TREE_CODE (TREE_TYPE (args
[0]));
9169 code1
= TREE_CODE (TREE_TYPE (args
[1]));
9170 if (!((code0
== REAL_TYPE
&& code1
== REAL_TYPE
)
9171 || (code0
== REAL_TYPE
&& code1
== INTEGER_TYPE
)
9172 || (code0
== INTEGER_TYPE
&& code1
== REAL_TYPE
)))
9174 error ("non-floating-point arguments in call to "
9175 "function %qE", fndecl
);
9182 case BUILT_IN_FPCLASSIFY
:
9183 if (builtin_function_validate_nargs (fndecl
, nargs
, 6))
9188 if (TREE_CODE (args
[i
]) != INTEGER_CST
)
9190 error ("non-const integer argument %u in call to function %qE",
9195 if (TREE_CODE (TREE_TYPE (args
[5])) != REAL_TYPE
)
9197 error ("non-floating-point argument in call to function %qE",
9205 case BUILT_IN_ASSUME_ALIGNED
:
9206 if (builtin_function_validate_nargs (fndecl
, nargs
, 2 + (nargs
> 2)))
9208 if (nargs
>= 3 && TREE_CODE (TREE_TYPE (args
[2])) != INTEGER_TYPE
)
9210 error ("non-integer argument 3 in call to function %qE", fndecl
);
9222 /* Function to help qsort sort FIELD_DECLs by name order. */
9225 field_decl_cmp (const void *x_p
, const void *y_p
)
9227 const tree
*const x
= (const tree
*const) x_p
;
9228 const tree
*const y
= (const tree
*const) y_p
;
9230 if (DECL_NAME (*x
) == DECL_NAME (*y
))
9231 /* A nontype is "greater" than a type. */
9232 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
9233 if (DECL_NAME (*x
) == NULL_TREE
)
9235 if (DECL_NAME (*y
) == NULL_TREE
)
9237 if (DECL_NAME (*x
) < DECL_NAME (*y
))
9243 gt_pointer_operator new_value
;
9247 /* This routine compares two fields like field_decl_cmp but using the
9248 pointer operator in resort_data. */
9251 resort_field_decl_cmp (const void *x_p
, const void *y_p
)
9253 const tree
*const x
= (const tree
*const) x_p
;
9254 const tree
*const y
= (const tree
*const) y_p
;
9256 if (DECL_NAME (*x
) == DECL_NAME (*y
))
9257 /* A nontype is "greater" than a type. */
9258 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
9259 if (DECL_NAME (*x
) == NULL_TREE
)
9261 if (DECL_NAME (*y
) == NULL_TREE
)
9264 tree d1
= DECL_NAME (*x
);
9265 tree d2
= DECL_NAME (*y
);
9266 resort_data
.new_value (&d1
, resort_data
.cookie
);
9267 resort_data
.new_value (&d2
, resort_data
.cookie
);
9274 /* Resort DECL_SORTED_FIELDS because pointers have been reordered. */
9277 resort_sorted_fields (void *obj
,
9278 void * ARG_UNUSED (orig_obj
),
9279 gt_pointer_operator new_value
,
9282 struct sorted_fields_type
*sf
= (struct sorted_fields_type
*) obj
;
9283 resort_data
.new_value
= new_value
;
9284 resort_data
.cookie
= cookie
;
9285 qsort (&sf
->elts
[0], sf
->len
, sizeof (tree
),
9286 resort_field_decl_cmp
);
9289 /* Subroutine of c_parse_error.
9290 Return the result of concatenating LHS and RHS. RHS is really
9291 a string literal, its first character is indicated by RHS_START and
9292 RHS_SIZE is its length (including the terminating NUL character).
9294 The caller is responsible for deleting the returned pointer. */
9297 catenate_strings (const char *lhs
, const char *rhs_start
, int rhs_size
)
9299 const int lhs_size
= strlen (lhs
);
9300 char *result
= XNEWVEC (char, lhs_size
+ rhs_size
);
9301 strncpy (result
, lhs
, lhs_size
);
9302 strncpy (result
+ lhs_size
, rhs_start
, rhs_size
);
9306 /* Issue the error given by GMSGID, indicating that it occurred before
9307 TOKEN, which had the associated VALUE. */
9310 c_parse_error (const char *gmsgid
, enum cpp_ttype token_type
,
9311 tree value
, unsigned char token_flags
)
9313 #define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2))
9315 char *message
= NULL
;
9317 if (token_type
== CPP_EOF
)
9318 message
= catenate_messages (gmsgid
, " at end of input");
9319 else if (token_type
== CPP_CHAR
9320 || token_type
== CPP_WCHAR
9321 || token_type
== CPP_CHAR16
9322 || token_type
== CPP_CHAR32
)
9324 unsigned int val
= tree_to_hwi (value
);
9343 if (val
<= UCHAR_MAX
&& ISGRAPH (val
))
9344 message
= catenate_messages (gmsgid
, " before %s'%c'");
9346 message
= catenate_messages (gmsgid
, " before %s'\\x%x'");
9348 error (message
, prefix
, val
);
9352 else if (token_type
== CPP_CHAR_USERDEF
9353 || token_type
== CPP_WCHAR_USERDEF
9354 || token_type
== CPP_CHAR16_USERDEF
9355 || token_type
== CPP_CHAR32_USERDEF
)
9356 message
= catenate_messages (gmsgid
,
9357 " before user-defined character literal");
9358 else if (token_type
== CPP_STRING_USERDEF
9359 || token_type
== CPP_WSTRING_USERDEF
9360 || token_type
== CPP_STRING16_USERDEF
9361 || token_type
== CPP_STRING32_USERDEF
9362 || token_type
== CPP_UTF8STRING_USERDEF
)
9363 message
= catenate_messages (gmsgid
, " before user-defined string literal");
9364 else if (token_type
== CPP_STRING
9365 || token_type
== CPP_WSTRING
9366 || token_type
== CPP_STRING16
9367 || token_type
== CPP_STRING32
9368 || token_type
== CPP_UTF8STRING
)
9369 message
= catenate_messages (gmsgid
, " before string constant");
9370 else if (token_type
== CPP_NUMBER
)
9371 message
= catenate_messages (gmsgid
, " before numeric constant");
9372 else if (token_type
== CPP_NAME
)
9374 message
= catenate_messages (gmsgid
, " before %qE");
9375 error (message
, value
);
9379 else if (token_type
== CPP_PRAGMA
)
9380 message
= catenate_messages (gmsgid
, " before %<#pragma%>");
9381 else if (token_type
== CPP_PRAGMA_EOL
)
9382 message
= catenate_messages (gmsgid
, " before end of line");
9383 else if (token_type
== CPP_DECLTYPE
)
9384 message
= catenate_messages (gmsgid
, " before %<decltype%>");
9385 else if (token_type
< N_TTYPES
)
9387 message
= catenate_messages (gmsgid
, " before %qs token");
9388 error (message
, cpp_type2name (token_type
, token_flags
));
9400 #undef catenate_messages
9403 /* Mapping for cpp message reasons to the options that enable them. */
9405 struct reason_option_codes_t
9407 const int reason
; /* cpplib message reason. */
9408 const int option_code
; /* gcc option that controls this message. */
9411 static const struct reason_option_codes_t option_codes
[] = {
9412 {CPP_W_DEPRECATED
, OPT_Wdeprecated
},
9413 {CPP_W_COMMENTS
, OPT_Wcomment
},
9414 {CPP_W_TRIGRAPHS
, OPT_Wtrigraphs
},
9415 {CPP_W_MULTICHAR
, OPT_Wmultichar
},
9416 {CPP_W_TRADITIONAL
, OPT_Wtraditional
},
9417 {CPP_W_LONG_LONG
, OPT_Wlong_long
},
9418 {CPP_W_ENDIF_LABELS
, OPT_Wendif_labels
},
9419 {CPP_W_VARIADIC_MACROS
, OPT_Wvariadic_macros
},
9420 {CPP_W_BUILTIN_MACRO_REDEFINED
, OPT_Wbuiltin_macro_redefined
},
9421 {CPP_W_UNDEF
, OPT_Wundef
},
9422 {CPP_W_UNUSED_MACROS
, OPT_Wunused_macros
},
9423 {CPP_W_CXX_OPERATOR_NAMES
, OPT_Wc___compat
},
9424 {CPP_W_NORMALIZE
, OPT_Wnormalized_
},
9425 {CPP_W_INVALID_PCH
, OPT_Winvalid_pch
},
9426 {CPP_W_WARNING_DIRECTIVE
, OPT_Wcpp
},
9427 {CPP_W_LITERAL_SUFFIX
, OPT_Wliteral_suffix
},
9431 /* Return the gcc option code associated with the reason for a cpp
9432 message, or 0 if none. */
9435 c_option_controlling_cpp_error (int reason
)
9437 const struct reason_option_codes_t
*entry
;
9439 for (entry
= option_codes
; entry
->reason
!= CPP_W_NONE
; entry
++)
9441 if (entry
->reason
== reason
)
9442 return entry
->option_code
;
9447 /* Callback from cpp_error for PFILE to print diagnostics from the
9448 preprocessor. The diagnostic is of type LEVEL, with REASON set
9449 to the reason code if LEVEL is represents a warning, at location
9450 LOCATION unless this is after lexing and the compiler's location
9451 should be used instead, with column number possibly overridden by
9452 COLUMN_OVERRIDE if not zero; MSG is the translated message and AP
9453 the arguments. Returns true if a diagnostic was emitted, false
9457 c_cpp_error (cpp_reader
*pfile ATTRIBUTE_UNUSED
, int level
, int reason
,
9458 location_t location
, unsigned int column_override
,
9459 const char *msg
, va_list *ap
)
9461 diagnostic_info diagnostic
;
9462 diagnostic_t dlevel
;
9463 bool save_warn_system_headers
= global_dc
->dc_warn_system_headers
;
9468 case CPP_DL_WARNING_SYSHDR
:
9471 global_dc
->dc_warn_system_headers
= 1;
9473 case CPP_DL_WARNING
:
9476 dlevel
= DK_WARNING
;
9478 case CPP_DL_PEDWARN
:
9479 if (flag_no_output
&& !flag_pedantic_errors
)
9481 dlevel
= DK_PEDWARN
;
9499 location
= input_location
;
9500 diagnostic_set_info_translated (&diagnostic
, msg
, ap
,
9502 if (column_override
)
9503 diagnostic_override_column (&diagnostic
, column_override
);
9504 diagnostic_override_option_index (&diagnostic
,
9505 c_option_controlling_cpp_error (reason
));
9506 ret
= report_diagnostic (&diagnostic
);
9507 if (level
== CPP_DL_WARNING_SYSHDR
)
9508 global_dc
->dc_warn_system_headers
= save_warn_system_headers
;
9512 /* Convert a character from the host to the target execution character
9513 set. cpplib handles this, mostly. */
9516 c_common_to_target_charset (HOST_WIDE_INT c
)
9518 /* Character constants in GCC proper are sign-extended under -fsigned-char,
9519 zero-extended under -fno-signed-char. cpplib insists that characters
9520 and character constants are always unsigned. Hence we must convert
9522 cppchar_t uc
= ((cppchar_t
)c
) & ((((cppchar_t
)1) << CHAR_BIT
)-1);
9524 uc
= cpp_host_to_exec_charset (parse_in
, uc
);
9526 if (flag_signed_char
)
9527 return ((HOST_WIDE_INT
)uc
) << (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
)
9528 >> (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
);
9533 /* Fold an offsetof-like expression. EXPR is a nested sequence of component
9534 references with an INDIRECT_REF of a constant at the bottom; much like the
9535 traditional rendering of offsetof as a macro. Return the folded result. */
9538 fold_offsetof_1 (tree expr
)
9542 switch (TREE_CODE (expr
))
9548 error ("cannot apply %<offsetof%> to static data member %qD", expr
);
9549 return error_mark_node
;
9553 error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded");
9554 return error_mark_node
;
9558 if (!TREE_CONSTANT (TREE_OPERAND (expr
, 0)))
9560 error ("cannot apply %<offsetof%> to a non constant address");
9561 return error_mark_node
;
9563 return TREE_OPERAND (expr
, 0);
9566 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0));
9567 if (base
== error_mark_node
)
9570 t
= TREE_OPERAND (expr
, 1);
9571 if (DECL_C_BIT_FIELD (t
))
9573 error ("attempt to take address of bit-field structure "
9575 return error_mark_node
;
9577 off
= size_binop_loc (input_location
, PLUS_EXPR
, DECL_FIELD_OFFSET (t
),
9578 size_int (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (t
))
9583 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0));
9584 if (base
== error_mark_node
)
9587 t
= TREE_OPERAND (expr
, 1);
9589 /* Check if the offset goes beyond the upper bound of the array. */
9590 if (TREE_CODE (t
) == INTEGER_CST
&& tree_int_cst_sgn (t
) >= 0)
9592 tree upbound
= array_ref_up_bound (expr
);
9593 if (upbound
!= NULL_TREE
9594 && TREE_CODE (upbound
) == INTEGER_CST
9595 && !tree_int_cst_equal (upbound
,
9596 TYPE_MAX_VALUE (TREE_TYPE (upbound
))))
9598 upbound
= size_binop (PLUS_EXPR
, upbound
,
9599 build_int_cst (TREE_TYPE (upbound
), 1));
9600 if (tree_int_cst_lt (upbound
, t
))
9604 for (v
= TREE_OPERAND (expr
, 0);
9605 TREE_CODE (v
) == COMPONENT_REF
;
9606 v
= TREE_OPERAND (v
, 0))
9607 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v
, 0)))
9610 tree fld_chain
= DECL_CHAIN (TREE_OPERAND (v
, 1));
9611 for (; fld_chain
; fld_chain
= DECL_CHAIN (fld_chain
))
9612 if (TREE_CODE (fld_chain
) == FIELD_DECL
)
9618 /* Don't warn if the array might be considered a poor
9619 man's flexible array member with a very permissive
9620 definition thereof. */
9621 if (TREE_CODE (v
) == ARRAY_REF
9622 || TREE_CODE (v
) == COMPONENT_REF
)
9623 warning (OPT_Warray_bounds
,
9624 "index %E denotes an offset "
9625 "greater than size of %qT",
9626 t
, TREE_TYPE (TREE_OPERAND (expr
, 0)));
9631 t
= convert (sizetype
, t
);
9632 off
= size_binop (MULT_EXPR
, TYPE_SIZE_UNIT (TREE_TYPE (expr
)), t
);
9636 /* Handle static members of volatile structs. */
9637 t
= TREE_OPERAND (expr
, 1);
9638 gcc_assert (TREE_CODE (t
) == VAR_DECL
);
9639 return fold_offsetof_1 (t
);
9645 return fold_build_pointer_plus (base
, off
);
9648 /* Likewise, but convert it to the return type of offsetof. */
9651 fold_offsetof (tree expr
)
9653 return convert (size_type_node
, fold_offsetof_1 (expr
));
9656 /* Warn for A ?: C expressions (with B omitted) where A is a boolean
9657 expression, because B will always be true. */
9660 warn_for_omitted_condop (location_t location
, tree cond
)
9662 if (truth_value_p (TREE_CODE (cond
)))
9663 warning_at (location
, OPT_Wparentheses
,
9664 "the omitted middle operand in ?: will always be %<true%>, "
9665 "suggest explicit middle operand");
9668 /* Give an error for storing into ARG, which is 'const'. USE indicates
9669 how ARG was being used. */
9672 readonly_error (tree arg
, enum lvalue_use use
)
9674 gcc_assert (use
== lv_assign
|| use
== lv_increment
|| use
== lv_decrement
9676 /* Using this macro rather than (for example) arrays of messages
9677 ensures that all the format strings are checked at compile
9679 #define READONLY_MSG(A, I, D, AS) (use == lv_assign ? (A) \
9680 : (use == lv_increment ? (I) \
9681 : (use == lv_decrement ? (D) : (AS))))
9682 if (TREE_CODE (arg
) == COMPONENT_REF
)
9684 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg
, 0))))
9685 error (READONLY_MSG (G_("assignment of member "
9686 "%qD in read-only object"),
9687 G_("increment of member "
9688 "%qD in read-only object"),
9689 G_("decrement of member "
9690 "%qD in read-only object"),
9691 G_("member %qD in read-only object "
9692 "used as %<asm%> output")),
9693 TREE_OPERAND (arg
, 1));
9695 error (READONLY_MSG (G_("assignment of read-only member %qD"),
9696 G_("increment of read-only member %qD"),
9697 G_("decrement of read-only member %qD"),
9698 G_("read-only member %qD used as %<asm%> output")),
9699 TREE_OPERAND (arg
, 1));
9701 else if (TREE_CODE (arg
) == VAR_DECL
)
9702 error (READONLY_MSG (G_("assignment of read-only variable %qD"),
9703 G_("increment of read-only variable %qD"),
9704 G_("decrement of read-only variable %qD"),
9705 G_("read-only variable %qD used as %<asm%> output")),
9707 else if (TREE_CODE (arg
) == PARM_DECL
)
9708 error (READONLY_MSG (G_("assignment of read-only parameter %qD"),
9709 G_("increment of read-only parameter %qD"),
9710 G_("decrement of read-only parameter %qD"),
9711 G_("read-only parameter %qD use as %<asm%> output")),
9713 else if (TREE_CODE (arg
) == RESULT_DECL
)
9715 gcc_assert (c_dialect_cxx ());
9716 error (READONLY_MSG (G_("assignment of "
9717 "read-only named return value %qD"),
9719 "read-only named return value %qD"),
9721 "read-only named return value %qD"),
9722 G_("read-only named return value %qD "
9723 "used as %<asm%>output")),
9726 else if (TREE_CODE (arg
) == FUNCTION_DECL
)
9727 error (READONLY_MSG (G_("assignment of function %qD"),
9728 G_("increment of function %qD"),
9729 G_("decrement of function %qD"),
9730 G_("function %qD used as %<asm%> output")),
9733 error (READONLY_MSG (G_("assignment of read-only location %qE"),
9734 G_("increment of read-only location %qE"),
9735 G_("decrement of read-only location %qE"),
9736 G_("read-only location %qE used as %<asm%> output")),
9740 /* Print an error message for an invalid lvalue. USE says
9741 how the lvalue is being used and so selects the error message. LOC
9742 is the location for the error. */
9745 lvalue_error (location_t loc
, enum lvalue_use use
)
9750 error_at (loc
, "lvalue required as left operand of assignment");
9753 error_at (loc
, "lvalue required as increment operand");
9756 error_at (loc
, "lvalue required as decrement operand");
9759 error_at (loc
, "lvalue required as unary %<&%> operand");
9762 error_at (loc
, "lvalue required in asm statement");
9769 /* Print an error message for an invalid indirection of type TYPE.
9770 ERRSTRING is the name of the operator for the indirection. */
9773 invalid_indirection_error (location_t loc
, tree type
, ref_operator errstring
)
9778 gcc_assert (c_dialect_cxx ());
9779 error_at (loc
, "invalid type argument (have %qT)", type
);
9781 case RO_ARRAY_INDEXING
:
9783 "invalid type argument of array indexing (have %qT)",
9788 "invalid type argument of unary %<*%> (have %qT)",
9793 "invalid type argument of %<->%> (have %qT)",
9796 case RO_IMPLICIT_CONVERSION
:
9798 "invalid type argument of implicit conversion (have %qT)",
9806 /* *PTYPE is an incomplete array. Complete it with a domain based on
9807 INITIAL_VALUE. If INITIAL_VALUE is not present, use 1 if DO_DEFAULT
9808 is true. Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
9809 2 if INITIAL_VALUE was NULL, and 3 if INITIAL_VALUE was empty. */
9812 complete_array_type (tree
*ptype
, tree initial_value
, bool do_default
)
9814 tree maxindex
, type
, main_type
, elt
, unqual_elt
;
9815 int failure
= 0, quals
;
9816 hashval_t hashcode
= 0;
9817 bool overflow_p
= false;
9819 maxindex
= size_zero_node
;
9822 if (TREE_CODE (initial_value
) == STRING_CST
)
9825 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value
)));
9826 maxindex
= size_int (TREE_STRING_LENGTH (initial_value
)/eltsize
- 1);
9828 else if (TREE_CODE (initial_value
) == CONSTRUCTOR
)
9830 vec
<constructor_elt
, va_gc
> *v
= CONSTRUCTOR_ELTS (initial_value
);
9832 if (vec_safe_is_empty (v
))
9836 maxindex
= ssize_int (-1);
9841 unsigned HOST_WIDE_INT cnt
;
9842 constructor_elt
*ce
;
9843 bool fold_p
= false;
9846 maxindex
= (*v
)[0].index
, fold_p
= true;
9848 curindex
= maxindex
;
9850 for (cnt
= 1; vec_safe_iterate (v
, cnt
, &ce
); cnt
++)
9852 bool curfold_p
= false;
9854 curindex
= ce
->index
, curfold_p
= true;
9859 /* Since we treat size types now as ordinary
9860 unsigned types, we need an explicit overflow
9862 tree orig
= curindex
;
9863 curindex
= fold_convert (sizetype
, curindex
);
9864 overflow_p
|= tree_int_cst_lt (curindex
, orig
);
9866 curindex
= size_binop (PLUS_EXPR
, curindex
,
9869 if (tree_int_cst_lt (maxindex
, curindex
))
9870 maxindex
= curindex
, fold_p
= curfold_p
;
9874 tree orig
= maxindex
;
9875 maxindex
= fold_convert (sizetype
, maxindex
);
9876 overflow_p
|= tree_int_cst_lt (maxindex
, orig
);
9882 /* Make an error message unless that happened already. */
9883 if (initial_value
!= error_mark_node
)
9895 elt
= TREE_TYPE (type
);
9896 quals
= TYPE_QUALS (strip_array_types (elt
));
9900 unqual_elt
= c_build_qualified_type (elt
, KEEP_QUAL_ADDR_SPACE (quals
));
9902 /* Using build_distinct_type_copy and modifying things afterward instead
9903 of using build_array_type to create a new type preserves all of the
9904 TYPE_LANG_FLAG_? bits that the front end may have set. */
9905 main_type
= build_distinct_type_copy (TYPE_MAIN_VARIANT (type
));
9906 TREE_TYPE (main_type
) = unqual_elt
;
9907 TYPE_DOMAIN (main_type
)
9908 = build_range_type (TREE_TYPE (maxindex
),
9909 build_int_cst (TREE_TYPE (maxindex
), 0), maxindex
);
9910 layout_type (main_type
);
9912 /* Make sure we have the canonical MAIN_TYPE. */
9913 hashcode
= iterative_hash_object (TYPE_HASH (unqual_elt
), hashcode
);
9914 hashcode
= iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (main_type
)),
9916 main_type
= type_hash_canon (hashcode
, main_type
);
9918 /* Fix the canonical type. */
9919 if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type
))
9920 || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type
)))
9921 SET_TYPE_STRUCTURAL_EQUALITY (main_type
);
9922 else if (TYPE_CANONICAL (TREE_TYPE (main_type
)) != TREE_TYPE (main_type
)
9923 || (TYPE_CANONICAL (TYPE_DOMAIN (main_type
))
9924 != TYPE_DOMAIN (main_type
)))
9925 TYPE_CANONICAL (main_type
)
9926 = build_array_type (TYPE_CANONICAL (TREE_TYPE (main_type
)),
9927 TYPE_CANONICAL (TYPE_DOMAIN (main_type
)));
9929 TYPE_CANONICAL (main_type
) = main_type
;
9934 type
= c_build_qualified_type (main_type
, quals
);
9936 if (COMPLETE_TYPE_P (type
)
9937 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
9938 && (overflow_p
|| TREE_OVERFLOW (TYPE_SIZE_UNIT (type
))))
9940 error ("size of array is too large");
9941 /* If we proceed with the array type as it is, we'll eventually
9942 crash in tree_to_uhwi(). */
9943 type
= error_mark_node
;
9950 /* Like c_mark_addressable but don't check register qualifier. */
9952 c_common_mark_addressable_vec (tree t
)
9954 while (handled_component_p (t
))
9955 t
= TREE_OPERAND (t
, 0);
9956 if (TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != PARM_DECL
)
9958 TREE_ADDRESSABLE (t
) = 1;
9963 /* Used to help initialize the builtin-types.def table. When a type of
9964 the correct size doesn't exist, use error_mark_node instead of NULL.
9965 The later results in segfaults even when a decl using the type doesn't
9969 builtin_type_for_size (int size
, bool unsignedp
)
9971 tree type
= c_common_type_for_size (size
, unsignedp
);
9972 return type
? type
: error_mark_node
;
9975 /* A helper function for resolve_overloaded_builtin in resolving the
9976 overloaded __sync_ builtins. Returns a positive power of 2 if the
9977 first operand of PARAMS is a pointer to a supported data type.
9978 Returns 0 if an error is encountered. */
9981 sync_resolve_size (tree function
, vec
<tree
, va_gc
> *params
)
9988 error ("too few arguments to function %qE", function
);
9992 type
= TREE_TYPE ((*params
)[0]);
9993 if (TREE_CODE (type
) != POINTER_TYPE
)
9996 type
= TREE_TYPE (type
);
9997 if (!INTEGRAL_TYPE_P (type
) && !POINTER_TYPE_P (type
))
10000 size
= tree_to_uhwi (TYPE_SIZE_UNIT (type
));
10001 if (size
== 1 || size
== 2 || size
== 4 || size
== 8 || size
== 16)
10005 error ("incompatible type for argument %d of %qE", 1, function
);
10009 /* A helper function for resolve_overloaded_builtin. Adds casts to
10010 PARAMS to make arguments match up with those of FUNCTION. Drops
10011 the variadic arguments at the end. Returns false if some error
10012 was encountered; true on success. */
10015 sync_resolve_params (location_t loc
, tree orig_function
, tree function
,
10016 vec
<tree
, va_gc
> *params
, bool orig_format
)
10018 function_args_iterator iter
;
10020 unsigned int parmnum
;
10022 function_args_iter_init (&iter
, TREE_TYPE (function
));
10023 /* We've declared the implementation functions to use "volatile void *"
10024 as the pointer parameter, so we shouldn't get any complaints from the
10025 call to check_function_arguments what ever type the user used. */
10026 function_args_iter_next (&iter
);
10027 ptype
= TREE_TYPE (TREE_TYPE ((*params
)[0]));
10029 /* For the rest of the values, we need to cast these to FTYPE, so that we
10030 don't get warnings for passing pointer types, etc. */
10034 tree val
, arg_type
;
10036 arg_type
= function_args_iter_cond (&iter
);
10037 /* XXX void_type_node belies the abstraction. */
10038 if (arg_type
== void_type_node
)
10042 if (params
->length () <= parmnum
)
10044 error_at (loc
, "too few arguments to function %qE", orig_function
);
10048 /* Only convert parameters if arg_type is unsigned integer type with
10049 new format sync routines, i.e. don't attempt to convert pointer
10050 arguments (e.g. EXPECTED argument of __atomic_compare_exchange_n),
10051 bool arguments (e.g. WEAK argument) or signed int arguments (memmodel
10053 if (TREE_CODE (arg_type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (arg_type
))
10055 /* Ideally for the first conversion we'd use convert_for_assignment
10056 so that we get warnings for anything that doesn't match the pointer
10057 type. This isn't portable across the C and C++ front ends atm. */
10058 val
= (*params
)[parmnum
];
10059 val
= convert (ptype
, val
);
10060 val
= convert (arg_type
, val
);
10061 (*params
)[parmnum
] = val
;
10064 function_args_iter_next (&iter
);
10067 /* __atomic routines are not variadic. */
10068 if (!orig_format
&& params
->length () != parmnum
+ 1)
10070 error_at (loc
, "too many arguments to function %qE", orig_function
);
10074 /* The definition of these primitives is variadic, with the remaining
10075 being "an optional list of variables protected by the memory barrier".
10076 No clue what that's supposed to mean, precisely, but we consider all
10077 call-clobbered variables to be protected so we're safe. */
10078 params
->truncate (parmnum
+ 1);
10083 /* A helper function for resolve_overloaded_builtin. Adds a cast to
10084 RESULT to make it match the type of the first pointer argument in
10088 sync_resolve_return (tree first_param
, tree result
, bool orig_format
)
10090 tree ptype
= TREE_TYPE (TREE_TYPE (first_param
));
10091 tree rtype
= TREE_TYPE (result
);
10092 ptype
= TYPE_MAIN_VARIANT (ptype
);
10094 /* New format doesn't require casting unless the types are the same size. */
10095 if (orig_format
|| tree_int_cst_equal (TYPE_SIZE (ptype
), TYPE_SIZE (rtype
)))
10096 return convert (ptype
, result
);
10101 /* This function verifies the PARAMS to generic atomic FUNCTION.
10102 It returns the size if all the parameters are the same size, otherwise
10103 0 is returned if the parameters are invalid. */
10106 get_atomic_generic_size (location_t loc
, tree function
,
10107 vec
<tree
, va_gc
> *params
)
10109 unsigned int n_param
;
10110 unsigned int n_model
;
10115 /* Determine the parameter makeup. */
10116 switch (DECL_FUNCTION_CODE (function
))
10118 case BUILT_IN_ATOMIC_EXCHANGE
:
10122 case BUILT_IN_ATOMIC_LOAD
:
10123 case BUILT_IN_ATOMIC_STORE
:
10127 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10132 gcc_unreachable ();
10135 if (vec_safe_length (params
) != n_param
)
10137 error_at (loc
, "incorrect number of arguments to function %qE", function
);
10141 /* Get type of first parameter, and determine its size. */
10142 type_0
= TREE_TYPE ((*params
)[0]);
10143 if (TREE_CODE (type_0
) != POINTER_TYPE
|| VOID_TYPE_P (TREE_TYPE (type_0
)))
10145 error_at (loc
, "argument 1 of %qE must be a non-void pointer type",
10150 /* Types must be compile time constant sizes. */
10151 if (TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type_0
)))) != INTEGER_CST
)
10154 "argument 1 of %qE must be a pointer to a constant size type",
10159 size_0
= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type_0
)));
10161 /* Zero size objects are not allowed. */
10165 "argument 1 of %qE must be a pointer to a nonzero size object",
10170 /* Check each other parameter is a pointer and the same size. */
10171 for (x
= 0; x
< n_param
- n_model
; x
++)
10174 tree type
= TREE_TYPE ((*params
)[x
]);
10175 /* __atomic_compare_exchange has a bool in the 4th position, skip it. */
10176 if (n_param
== 6 && x
== 3)
10178 if (!POINTER_TYPE_P (type
))
10180 error_at (loc
, "argument %d of %qE must be a pointer type", x
+ 1,
10184 size
= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type
)));
10185 if (size
!= size_0
)
10187 error_at (loc
, "size mismatch in argument %d of %qE", x
+ 1,
10193 /* Check memory model parameters for validity. */
10194 for (x
= n_param
- n_model
; x
< n_param
; x
++)
10196 tree p
= (*params
)[x
];
10197 if (TREE_CODE (p
) == INTEGER_CST
)
10199 int i
= tree_to_uhwi (p
);
10200 if (i
< 0 || (i
& MEMMODEL_MASK
) >= MEMMODEL_LAST
)
10202 warning_at (loc
, OPT_Winvalid_memory_model
,
10203 "invalid memory model argument %d of %qE", x
+ 1,
10208 if (!INTEGRAL_TYPE_P (TREE_TYPE (p
)))
10210 error_at (loc
, "non-integer memory model argument %d of %qE", x
+ 1,
10220 /* This will take an __atomic_ generic FUNCTION call, and add a size parameter N
10221 at the beginning of the parameter list PARAMS representing the size of the
10222 objects. This is to match the library ABI requirement. LOC is the location
10223 of the function call.
10224 The new function is returned if it needed rebuilding, otherwise NULL_TREE is
10225 returned to allow the external call to be constructed. */
10228 add_atomic_size_parameter (unsigned n
, location_t loc
, tree function
,
10229 vec
<tree
, va_gc
> *params
)
10233 /* Insert a SIZE_T parameter as the first param. If there isn't
10234 enough space, allocate a new vector and recursively re-build with that. */
10235 if (!params
->space (1))
10237 unsigned int z
, len
;
10238 vec
<tree
, va_gc
> *v
;
10241 len
= params
->length ();
10242 vec_alloc (v
, len
+ 1);
10243 for (z
= 0; z
< len
; z
++)
10244 v
->quick_push ((*params
)[z
]);
10245 f
= build_function_call_vec (loc
, function
, v
, NULL
);
10250 /* Add the size parameter and leave as a function call for processing. */
10251 size_node
= build_int_cst (size_type_node
, n
);
10252 params
->quick_insert (0, size_node
);
10257 /* This will process an __atomic_exchange function call, determine whether it
10258 needs to be mapped to the _N variation, or turned into a library call.
10259 LOC is the location of the builtin call.
10260 FUNCTION is the DECL that has been invoked;
10261 PARAMS is the argument list for the call. The return value is non-null
10262 TRUE is returned if it is translated into the proper format for a call to the
10263 external library, and NEW_RETURN is set the tree for that function.
10264 FALSE is returned if processing for the _N variation is required, and
10265 NEW_RETURN is set to the the return value the result is copied into. */
10267 resolve_overloaded_atomic_exchange (location_t loc
, tree function
,
10268 vec
<tree
, va_gc
> *params
, tree
*new_return
)
10270 tree p0
, p1
, p2
, p3
;
10271 tree I_type
, I_type_ptr
;
10272 int n
= get_atomic_generic_size (loc
, function
, params
);
10274 /* Size of 0 is an error condition. */
10277 *new_return
= error_mark_node
;
10281 /* If not a lock-free size, change to the library generic format. */
10282 if (n
!= 1 && n
!= 2 && n
!= 4 && n
!= 8 && n
!= 16)
10284 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10288 /* Otherwise there is a lockfree match, transform the call from:
10289 void fn(T* mem, T* desired, T* return, model)
10291 *return = (T) (fn (In* mem, (In) *desired, model)) */
10298 /* Create pointer to appropriate size. */
10299 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10300 I_type_ptr
= build_pointer_type (I_type
);
10302 /* Convert object pointer to required type. */
10303 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10305 /* Convert new value to required type, and dereference it. */
10306 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
10307 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
10310 /* Move memory model to the 3rd position, and end param list. */
10312 params
->truncate (3);
10314 /* Convert return pointer and dereference it for later assignment. */
10315 *new_return
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
10321 /* This will process an __atomic_compare_exchange function call, determine
10322 whether it needs to be mapped to the _N variation, or turned into a lib call.
10323 LOC is the location of the builtin call.
10324 FUNCTION is the DECL that has been invoked;
10325 PARAMS is the argument list for the call. The return value is non-null
10326 TRUE is returned if it is translated into the proper format for a call to the
10327 external library, and NEW_RETURN is set the tree for that function.
10328 FALSE is returned if processing for the _N variation is required. */
10331 resolve_overloaded_atomic_compare_exchange (location_t loc
, tree function
,
10332 vec
<tree
, va_gc
> *params
,
10336 tree I_type
, I_type_ptr
;
10337 int n
= get_atomic_generic_size (loc
, function
, params
);
10339 /* Size of 0 is an error condition. */
10342 *new_return
= error_mark_node
;
10346 /* If not a lock-free size, change to the library generic format. */
10347 if (n
!= 1 && n
!= 2 && n
!= 4 && n
!= 8 && n
!= 16)
10349 /* The library generic format does not have the weak parameter, so
10350 remove it from the param list. Since a parameter has been removed,
10351 we can be sure that there is room for the SIZE_T parameter, meaning
10352 there will not be a recursive rebuilding of the parameter list, so
10353 there is no danger this will be done twice. */
10356 (*params
)[3] = (*params
)[4];
10357 (*params
)[4] = (*params
)[5];
10358 params
->truncate (5);
10360 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10364 /* Otherwise, there is a match, so the call needs to be transformed from:
10365 bool fn(T* mem, T* desired, T* return, weak, success, failure)
10367 bool fn ((In *)mem, (In *)expected, (In) *desired, weak, succ, fail) */
10373 /* Create pointer to appropriate size. */
10374 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10375 I_type_ptr
= build_pointer_type (I_type
);
10377 /* Convert object pointer to required type. */
10378 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10381 /* Convert expected pointer to required type. */
10382 p1
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p1
);
10385 /* Convert desired value to required type, and dereference it. */
10386 p2
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
10387 p2
= build1 (VIEW_CONVERT_EXPR
, I_type
, p2
);
10390 /* The rest of the parameters are fine. NULL means no special return value
10392 *new_return
= NULL
;
10397 /* This will process an __atomic_load function call, determine whether it
10398 needs to be mapped to the _N variation, or turned into a library call.
10399 LOC is the location of the builtin call.
10400 FUNCTION is the DECL that has been invoked;
10401 PARAMS is the argument list for the call. The return value is non-null
10402 TRUE is returned if it is translated into the proper format for a call to the
10403 external library, and NEW_RETURN is set the tree for that function.
10404 FALSE is returned if processing for the _N variation is required, and
10405 NEW_RETURN is set to the the return value the result is copied into. */
10408 resolve_overloaded_atomic_load (location_t loc
, tree function
,
10409 vec
<tree
, va_gc
> *params
, tree
*new_return
)
10412 tree I_type
, I_type_ptr
;
10413 int n
= get_atomic_generic_size (loc
, function
, params
);
10415 /* Size of 0 is an error condition. */
10418 *new_return
= error_mark_node
;
10422 /* If not a lock-free size, change to the library generic format. */
10423 if (n
!= 1 && n
!= 2 && n
!= 4 && n
!= 8 && n
!= 16)
10425 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10429 /* Otherwise, there is a match, so the call needs to be transformed from:
10430 void fn(T* mem, T* return, model)
10432 *return = (T) (fn ((In *) mem, model)) */
10438 /* Create pointer to appropriate size. */
10439 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10440 I_type_ptr
= build_pointer_type (I_type
);
10442 /* Convert object pointer to required type. */
10443 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10446 /* Move memory model to the 2nd position, and end param list. */
10448 params
->truncate (2);
10450 /* Convert return pointer and dereference it for later assignment. */
10451 *new_return
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
10457 /* This will process an __atomic_store function call, determine whether it
10458 needs to be mapped to the _N variation, or turned into a library call.
10459 LOC is the location of the builtin call.
10460 FUNCTION is the DECL that has been invoked;
10461 PARAMS is the argument list for the call. The return value is non-null
10462 TRUE is returned if it is translated into the proper format for a call to the
10463 external library, and NEW_RETURN is set the tree for that function.
10464 FALSE is returned if processing for the _N variation is required, and
10465 NEW_RETURN is set to the the return value the result is copied into. */
10468 resolve_overloaded_atomic_store (location_t loc
, tree function
,
10469 vec
<tree
, va_gc
> *params
, tree
*new_return
)
10472 tree I_type
, I_type_ptr
;
10473 int n
= get_atomic_generic_size (loc
, function
, params
);
10475 /* Size of 0 is an error condition. */
10478 *new_return
= error_mark_node
;
10482 /* If not a lock-free size, change to the library generic format. */
10483 if (n
!= 1 && n
!= 2 && n
!= 4 && n
!= 8 && n
!= 16)
10485 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10489 /* Otherwise, there is a match, so the call needs to be transformed from:
10490 void fn(T* mem, T* value, model)
10492 fn ((In *) mem, (In) *value, model) */
10497 /* Create pointer to appropriate size. */
10498 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10499 I_type_ptr
= build_pointer_type (I_type
);
10501 /* Convert object pointer to required type. */
10502 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10505 /* Convert new value to required type, and dereference it. */
10506 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
10507 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
10510 /* The memory model is in the right spot already. Return is void. */
10511 *new_return
= NULL_TREE
;
10517 /* Some builtin functions are placeholders for other expressions. This
10518 function should be called immediately after parsing the call expression
10519 before surrounding code has committed to the type of the expression.
10521 LOC is the location of the builtin call.
10523 FUNCTION is the DECL that has been invoked; it is known to be a builtin.
10524 PARAMS is the argument list for the call. The return value is non-null
10525 when expansion is complete, and null if normal processing should
10529 resolve_overloaded_builtin (location_t loc
, tree function
,
10530 vec
<tree
, va_gc
> *params
)
10532 enum built_in_function orig_code
= DECL_FUNCTION_CODE (function
);
10533 bool orig_format
= true;
10534 tree new_return
= NULL_TREE
;
10536 switch (DECL_BUILT_IN_CLASS (function
))
10538 case BUILT_IN_NORMAL
:
10541 if (targetm
.resolve_overloaded_builtin
)
10542 return targetm
.resolve_overloaded_builtin (loc
, function
, params
);
10549 /* Handle BUILT_IN_NORMAL here. */
10552 case BUILT_IN_ATOMIC_EXCHANGE
:
10553 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10554 case BUILT_IN_ATOMIC_LOAD
:
10555 case BUILT_IN_ATOMIC_STORE
:
10557 /* Handle these 4 together so that they can fall through to the next
10558 case if the call is transformed to an _N variant. */
10561 case BUILT_IN_ATOMIC_EXCHANGE
:
10563 if (resolve_overloaded_atomic_exchange (loc
, function
, params
,
10566 /* Change to the _N variant. */
10567 orig_code
= BUILT_IN_ATOMIC_EXCHANGE_N
;
10571 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10573 if (resolve_overloaded_atomic_compare_exchange (loc
, function
,
10577 /* Change to the _N variant. */
10578 orig_code
= BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
;
10581 case BUILT_IN_ATOMIC_LOAD
:
10583 if (resolve_overloaded_atomic_load (loc
, function
, params
,
10586 /* Change to the _N variant. */
10587 orig_code
= BUILT_IN_ATOMIC_LOAD_N
;
10590 case BUILT_IN_ATOMIC_STORE
:
10592 if (resolve_overloaded_atomic_store (loc
, function
, params
,
10595 /* Change to the _N variant. */
10596 orig_code
= BUILT_IN_ATOMIC_STORE_N
;
10600 gcc_unreachable ();
10602 /* Fallthrough to the normal processing. */
10604 case BUILT_IN_ATOMIC_EXCHANGE_N
:
10605 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
:
10606 case BUILT_IN_ATOMIC_LOAD_N
:
10607 case BUILT_IN_ATOMIC_STORE_N
:
10608 case BUILT_IN_ATOMIC_ADD_FETCH_N
:
10609 case BUILT_IN_ATOMIC_SUB_FETCH_N
:
10610 case BUILT_IN_ATOMIC_AND_FETCH_N
:
10611 case BUILT_IN_ATOMIC_NAND_FETCH_N
:
10612 case BUILT_IN_ATOMIC_XOR_FETCH_N
:
10613 case BUILT_IN_ATOMIC_OR_FETCH_N
:
10614 case BUILT_IN_ATOMIC_FETCH_ADD_N
:
10615 case BUILT_IN_ATOMIC_FETCH_SUB_N
:
10616 case BUILT_IN_ATOMIC_FETCH_AND_N
:
10617 case BUILT_IN_ATOMIC_FETCH_NAND_N
:
10618 case BUILT_IN_ATOMIC_FETCH_XOR_N
:
10619 case BUILT_IN_ATOMIC_FETCH_OR_N
:
10621 orig_format
= false;
10622 /* Fallthru for parameter processing. */
10624 case BUILT_IN_SYNC_FETCH_AND_ADD_N
:
10625 case BUILT_IN_SYNC_FETCH_AND_SUB_N
:
10626 case BUILT_IN_SYNC_FETCH_AND_OR_N
:
10627 case BUILT_IN_SYNC_FETCH_AND_AND_N
:
10628 case BUILT_IN_SYNC_FETCH_AND_XOR_N
:
10629 case BUILT_IN_SYNC_FETCH_AND_NAND_N
:
10630 case BUILT_IN_SYNC_ADD_AND_FETCH_N
:
10631 case BUILT_IN_SYNC_SUB_AND_FETCH_N
:
10632 case BUILT_IN_SYNC_OR_AND_FETCH_N
:
10633 case BUILT_IN_SYNC_AND_AND_FETCH_N
:
10634 case BUILT_IN_SYNC_XOR_AND_FETCH_N
:
10635 case BUILT_IN_SYNC_NAND_AND_FETCH_N
:
10636 case BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
:
10637 case BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N
:
10638 case BUILT_IN_SYNC_LOCK_TEST_AND_SET_N
:
10639 case BUILT_IN_SYNC_LOCK_RELEASE_N
:
10641 int n
= sync_resolve_size (function
, params
);
10642 tree new_function
, first_param
, result
;
10643 enum built_in_function fncode
;
10646 return error_mark_node
;
10648 fncode
= (enum built_in_function
)((int)orig_code
+ exact_log2 (n
) + 1);
10649 new_function
= builtin_decl_explicit (fncode
);
10650 if (!sync_resolve_params (loc
, function
, new_function
, params
,
10652 return error_mark_node
;
10654 first_param
= (*params
)[0];
10655 result
= build_function_call_vec (loc
, new_function
, params
, NULL
);
10656 if (result
== error_mark_node
)
10658 if (orig_code
!= BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
10659 && orig_code
!= BUILT_IN_SYNC_LOCK_RELEASE_N
10660 && orig_code
!= BUILT_IN_ATOMIC_STORE_N
)
10661 result
= sync_resolve_return (first_param
, result
, orig_format
);
10663 /* If new_return is set, assign function to that expr and cast the
10664 result to void since the generic interface returned void. */
10667 /* Cast function result from I{1,2,4,8,16} to the required type. */
10668 result
= build1 (VIEW_CONVERT_EXPR
, TREE_TYPE (new_return
), result
);
10669 result
= build2 (MODIFY_EXPR
, TREE_TYPE (new_return
), new_return
,
10671 TREE_SIDE_EFFECTS (result
) = 1;
10672 protected_set_expr_location (result
, loc
);
10673 result
= convert (void_type_node
, result
);
10683 /* Ignoring their sign, return true if two scalar types are the same. */
10685 same_scalar_type_ignoring_signedness (tree t1
, tree t2
)
10687 enum tree_code c1
= TREE_CODE (t1
), c2
= TREE_CODE (t2
);
10689 gcc_assert ((c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
|| c1
== FIXED_POINT_TYPE
)
10690 && (c2
== INTEGER_TYPE
|| c2
== REAL_TYPE
10691 || c2
== FIXED_POINT_TYPE
));
10693 /* Equality works here because c_common_signed_type uses
10694 TYPE_MAIN_VARIANT. */
10695 return c_common_signed_type (t1
)
10696 == c_common_signed_type (t2
);
10699 /* Check for missing format attributes on function pointers. LTYPE is
10700 the new type or left-hand side type. RTYPE is the old type or
10701 right-hand side type. Returns TRUE if LTYPE is missing the desired
10705 check_missing_format_attribute (tree ltype
, tree rtype
)
10707 tree
const ttr
= TREE_TYPE (rtype
), ttl
= TREE_TYPE (ltype
);
10710 for (ra
= TYPE_ATTRIBUTES (ttr
); ra
; ra
= TREE_CHAIN (ra
))
10711 if (is_attribute_p ("format", TREE_PURPOSE (ra
)))
10716 for (la
= TYPE_ATTRIBUTES (ttl
); la
; la
= TREE_CHAIN (la
))
10717 if (is_attribute_p ("format", TREE_PURPOSE (la
)))
10725 /* Subscripting with type char is likely to lose on a machine where
10726 chars are signed. So warn on any machine, but optionally. Don't
10727 warn for unsigned char since that type is safe. Don't warn for
10728 signed char because anyone who uses that must have done so
10729 deliberately. Furthermore, we reduce the false positive load by
10730 warning only for non-constant value of type char. */
10733 warn_array_subscript_with_type_char (tree index
)
10735 if (TYPE_MAIN_VARIANT (TREE_TYPE (index
)) == char_type_node
10736 && TREE_CODE (index
) != INTEGER_CST
)
10737 warning (OPT_Wchar_subscripts
, "array subscript has type %<char%>");
10740 /* Implement -Wparentheses for the unexpected C precedence rules, to
10741 cover cases like x + y << z which readers are likely to
10742 misinterpret. We have seen an expression in which CODE is a binary
10743 operator used to combine expressions ARG_LEFT and ARG_RIGHT, which
10744 before folding had CODE_LEFT and CODE_RIGHT. CODE_LEFT and
10745 CODE_RIGHT may be ERROR_MARK, which means that that side of the
10746 expression was not formed using a binary or unary operator, or it
10747 was enclosed in parentheses. */
10750 warn_about_parentheses (location_t loc
, enum tree_code code
,
10751 enum tree_code code_left
, tree arg_left
,
10752 enum tree_code code_right
, tree arg_right
)
10754 if (!warn_parentheses
)
10757 /* This macro tests that the expression ARG with original tree code
10758 CODE appears to be a boolean expression. or the result of folding a
10759 boolean expression. */
10760 #define APPEARS_TO_BE_BOOLEAN_EXPR_P(CODE, ARG) \
10761 (truth_value_p (TREE_CODE (ARG)) \
10762 || TREE_CODE (TREE_TYPE (ARG)) == BOOLEAN_TYPE \
10763 /* Folding may create 0 or 1 integers from other expressions. */ \
10764 || ((CODE) != INTEGER_CST \
10765 && (integer_onep (ARG) || integer_zerop (ARG))))
10770 if (code_left
== PLUS_EXPR
)
10771 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10772 "suggest parentheses around %<+%> inside %<<<%>");
10773 else if (code_right
== PLUS_EXPR
)
10774 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10775 "suggest parentheses around %<+%> inside %<<<%>");
10776 else if (code_left
== MINUS_EXPR
)
10777 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10778 "suggest parentheses around %<-%> inside %<<<%>");
10779 else if (code_right
== MINUS_EXPR
)
10780 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10781 "suggest parentheses around %<-%> inside %<<<%>");
10785 if (code_left
== PLUS_EXPR
)
10786 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10787 "suggest parentheses around %<+%> inside %<>>%>");
10788 else if (code_right
== PLUS_EXPR
)
10789 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10790 "suggest parentheses around %<+%> inside %<>>%>");
10791 else if (code_left
== MINUS_EXPR
)
10792 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10793 "suggest parentheses around %<-%> inside %<>>%>");
10794 else if (code_right
== MINUS_EXPR
)
10795 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10796 "suggest parentheses around %<-%> inside %<>>%>");
10799 case TRUTH_ORIF_EXPR
:
10800 if (code_left
== TRUTH_ANDIF_EXPR
)
10801 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10802 "suggest parentheses around %<&&%> within %<||%>");
10803 else if (code_right
== TRUTH_ANDIF_EXPR
)
10804 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10805 "suggest parentheses around %<&&%> within %<||%>");
10809 if (code_left
== BIT_AND_EXPR
|| code_left
== BIT_XOR_EXPR
10810 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
)
10811 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10812 "suggest parentheses around arithmetic in operand of %<|%>");
10813 else if (code_right
== BIT_AND_EXPR
|| code_right
== BIT_XOR_EXPR
10814 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
10815 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10816 "suggest parentheses around arithmetic in operand of %<|%>");
10817 /* Check cases like x|y==z */
10818 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
10819 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10820 "suggest parentheses around comparison in operand of %<|%>");
10821 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
10822 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10823 "suggest parentheses around comparison in operand of %<|%>");
10824 /* Check cases like !x | y */
10825 else if (code_left
== TRUTH_NOT_EXPR
10826 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
10827 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10828 "suggest parentheses around operand of "
10829 "%<!%> or change %<|%> to %<||%> or %<!%> to %<~%>");
10833 if (code_left
== BIT_AND_EXPR
10834 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
)
10835 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10836 "suggest parentheses around arithmetic in operand of %<^%>");
10837 else if (code_right
== BIT_AND_EXPR
10838 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
10839 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10840 "suggest parentheses around arithmetic in operand of %<^%>");
10841 /* Check cases like x^y==z */
10842 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
10843 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10844 "suggest parentheses around comparison in operand of %<^%>");
10845 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
10846 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10847 "suggest parentheses around comparison in operand of %<^%>");
10851 if (code_left
== PLUS_EXPR
)
10852 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10853 "suggest parentheses around %<+%> in operand of %<&%>");
10854 else if (code_right
== PLUS_EXPR
)
10855 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10856 "suggest parentheses around %<+%> in operand of %<&%>");
10857 else if (code_left
== MINUS_EXPR
)
10858 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10859 "suggest parentheses around %<-%> in operand of %<&%>");
10860 else if (code_right
== MINUS_EXPR
)
10861 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10862 "suggest parentheses around %<-%> in operand of %<&%>");
10863 /* Check cases like x&y==z */
10864 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
10865 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10866 "suggest parentheses around comparison in operand of %<&%>");
10867 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
10868 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10869 "suggest parentheses around comparison in operand of %<&%>");
10870 /* Check cases like !x & y */
10871 else if (code_left
== TRUTH_NOT_EXPR
10872 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
10873 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10874 "suggest parentheses around operand of "
10875 "%<!%> or change %<&%> to %<&&%> or %<!%> to %<~%>");
10879 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
10880 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10881 "suggest parentheses around comparison in operand of %<==%>");
10882 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
10883 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10884 "suggest parentheses around comparison in operand of %<==%>");
10887 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
10888 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10889 "suggest parentheses around comparison in operand of %<!=%>");
10890 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
10891 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10892 "suggest parentheses around comparison in operand of %<!=%>");
10896 if (TREE_CODE_CLASS (code
) == tcc_comparison
)
10898 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
10899 && code_left
!= NE_EXPR
&& code_left
!= EQ_EXPR
10900 && INTEGRAL_TYPE_P (TREE_TYPE (arg_left
)))
10901 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10902 "comparisons like %<X<=Y<=Z%> do not "
10903 "have their mathematical meaning");
10904 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
10905 && code_right
!= NE_EXPR
&& code_right
!= EQ_EXPR
10906 && INTEGRAL_TYPE_P (TREE_TYPE (arg_right
)))
10907 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10908 "comparisons like %<X<=Y<=Z%> do not "
10909 "have their mathematical meaning");
10913 #undef NOT_A_BOOLEAN_EXPR_P
10916 /* If LABEL (a LABEL_DECL) has not been used, issue a warning. */
10919 warn_for_unused_label (tree label
)
10921 if (!TREE_USED (label
))
10923 if (DECL_INITIAL (label
))
10924 warning (OPT_Wunused_label
, "label %q+D defined but not used", label
);
10926 warning (OPT_Wunused_label
, "label %q+D declared but not defined", label
);
10930 /* Warn for division by zero according to the value of DIVISOR. LOC
10931 is the location of the division operator. */
10934 warn_for_div_by_zero (location_t loc
, tree divisor
)
10936 /* If DIVISOR is zero, and has integral or fixed-point type, issue a warning
10937 about division by zero. Do not issue a warning if DIVISOR has a
10938 floating-point type, since we consider 0.0/0.0 a valid way of
10939 generating a NaN. */
10940 if (c_inhibit_evaluation_warnings
== 0
10941 && (integer_zerop (divisor
) || fixed_zerop (divisor
)))
10942 warning_at (loc
, OPT_Wdiv_by_zero
, "division by zero");
10945 /* Subroutine of build_binary_op. Give warnings for comparisons
10946 between signed and unsigned quantities that may fail. Do the
10947 checking based on the original operand trees ORIG_OP0 and ORIG_OP1,
10948 so that casts will be considered, but default promotions won't
10951 LOCATION is the location of the comparison operator.
10953 The arguments of this function map directly to local variables
10954 of build_binary_op. */
10957 warn_for_sign_compare (location_t location
,
10958 tree orig_op0
, tree orig_op1
,
10959 tree op0
, tree op1
,
10960 tree result_type
, enum tree_code resultcode
)
10962 int op0_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op0
));
10963 int op1_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op1
));
10964 int unsignedp0
, unsignedp1
;
10966 /* In C++, check for comparison of different enum types. */
10967 if (c_dialect_cxx()
10968 && TREE_CODE (TREE_TYPE (orig_op0
)) == ENUMERAL_TYPE
10969 && TREE_CODE (TREE_TYPE (orig_op1
)) == ENUMERAL_TYPE
10970 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0
))
10971 != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1
)))
10973 warning_at (location
,
10974 OPT_Wsign_compare
, "comparison between types %qT and %qT",
10975 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
));
10978 /* Do not warn if the comparison is being done in a signed type,
10979 since the signed type will only be chosen if it can represent
10980 all the values of the unsigned type. */
10981 if (!TYPE_UNSIGNED (result_type
))
10983 /* Do not warn if both operands are unsigned. */
10984 else if (op0_signed
== op1_signed
)
10988 tree sop
, uop
, base_type
;
10992 sop
= orig_op0
, uop
= orig_op1
;
10994 sop
= orig_op1
, uop
= orig_op0
;
10996 STRIP_TYPE_NOPS (sop
);
10997 STRIP_TYPE_NOPS (uop
);
10998 base_type
= (TREE_CODE (result_type
) == COMPLEX_TYPE
10999 ? TREE_TYPE (result_type
) : result_type
);
11001 /* Do not warn if the signed quantity is an unsuffixed integer
11002 literal (or some static constant expression involving such
11003 literals or a conditional expression involving such literals)
11004 and it is non-negative. */
11005 if (tree_expr_nonnegative_warnv_p (sop
, &ovf
))
11007 /* Do not warn if the comparison is an equality operation, the
11008 unsigned quantity is an integral constant, and it would fit
11009 in the result if the result were signed. */
11010 else if (TREE_CODE (uop
) == INTEGER_CST
11011 && (resultcode
== EQ_EXPR
|| resultcode
== NE_EXPR
)
11012 && int_fits_type_p (uop
, c_common_signed_type (base_type
)))
11014 /* In C, do not warn if the unsigned quantity is an enumeration
11015 constant and its maximum value would fit in the result if the
11016 result were signed. */
11017 else if (!c_dialect_cxx() && TREE_CODE (uop
) == INTEGER_CST
11018 && TREE_CODE (TREE_TYPE (uop
)) == ENUMERAL_TYPE
11019 && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (uop
)),
11020 c_common_signed_type (base_type
)))
11023 warning_at (location
,
11025 "comparison between signed and unsigned integer expressions");
11028 /* Warn if two unsigned values are being compared in a size larger
11029 than their original size, and one (and only one) is the result of
11030 a `~' operator. This comparison will always fail.
11032 Also warn if one operand is a constant, and the constant does not
11033 have all bits set that are set in the ~ operand when it is
11036 op0
= c_common_get_narrower (op0
, &unsignedp0
);
11037 op1
= c_common_get_narrower (op1
, &unsignedp1
);
11039 if ((TREE_CODE (op0
) == BIT_NOT_EXPR
)
11040 ^ (TREE_CODE (op1
) == BIT_NOT_EXPR
))
11042 if (TREE_CODE (op0
) == BIT_NOT_EXPR
)
11043 op0
= c_common_get_narrower (TREE_OPERAND (op0
, 0), &unsignedp0
);
11044 if (TREE_CODE (op1
) == BIT_NOT_EXPR
)
11045 op1
= c_common_get_narrower (TREE_OPERAND (op1
, 0), &unsignedp1
);
11047 if (tree_fits_shwi_p (op0
) || tree_fits_shwi_p (op1
))
11050 HOST_WIDE_INT constant
, mask
;
11054 if (tree_fits_shwi_p (op0
))
11057 unsignedp
= unsignedp1
;
11058 constant
= tree_to_shwi (op0
);
11063 unsignedp
= unsignedp0
;
11064 constant
= tree_to_shwi (op1
);
11067 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
11068 if (bits
< TYPE_PRECISION (result_type
)
11069 && bits
< HOST_BITS_PER_LONG
&& unsignedp
)
11071 mask
= (~ (HOST_WIDE_INT
) 0) << bits
;
11072 if ((mask
& constant
) != mask
)
11075 warning (OPT_Wsign_compare
,
11076 "promoted ~unsigned is always non-zero");
11078 warning_at (location
, OPT_Wsign_compare
,
11079 "comparison of promoted ~unsigned with constant");
11083 else if (unsignedp0
&& unsignedp1
11084 && (TYPE_PRECISION (TREE_TYPE (op0
))
11085 < TYPE_PRECISION (result_type
))
11086 && (TYPE_PRECISION (TREE_TYPE (op1
))
11087 < TYPE_PRECISION (result_type
)))
11088 warning_at (location
, OPT_Wsign_compare
,
11089 "comparison of promoted ~unsigned with unsigned");
11093 /* RESULT_TYPE is the result of converting TYPE1 and TYPE2 to a common
11094 type via c_common_type. If -Wdouble-promotion is in use, and the
11095 conditions for warning have been met, issue a warning. GMSGID is
11096 the warning message. It must have two %T specifiers for the type
11097 that was converted (generally "float") and the type to which it was
11098 converted (generally "double), respectively. LOC is the location
11099 to which the awrning should refer. */
11102 do_warn_double_promotion (tree result_type
, tree type1
, tree type2
,
11103 const char *gmsgid
, location_t loc
)
11107 if (!warn_double_promotion
)
11109 /* If the conversion will not occur at run-time, there is no need to
11111 if (c_inhibit_evaluation_warnings
)
11113 if (TYPE_MAIN_VARIANT (result_type
) != double_type_node
11114 && TYPE_MAIN_VARIANT (result_type
) != complex_double_type_node
)
11116 if (TYPE_MAIN_VARIANT (type1
) == float_type_node
11117 || TYPE_MAIN_VARIANT (type1
) == complex_float_type_node
)
11118 source_type
= type1
;
11119 else if (TYPE_MAIN_VARIANT (type2
) == float_type_node
11120 || TYPE_MAIN_VARIANT (type2
) == complex_float_type_node
)
11121 source_type
= type2
;
11124 warning_at (loc
, OPT_Wdouble_promotion
, gmsgid
, source_type
, result_type
);
11127 /* Setup a TYPE_DECL node as a typedef representation.
11129 X is a TYPE_DECL for a typedef statement. Create a brand new
11130 ..._TYPE node (which will be just a variant of the existing
11131 ..._TYPE node with identical properties) and then install X
11132 as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
11134 The whole point here is to end up with a situation where each
11135 and every ..._TYPE node the compiler creates will be uniquely
11136 associated with AT MOST one node representing a typedef name.
11137 This way, even though the compiler substitutes corresponding
11138 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
11139 early on, later parts of the compiler can always do the reverse
11140 translation and get back the corresponding typedef name. For
11143 typedef struct S MY_TYPE;
11146 Later parts of the compiler might only know that `object' was of
11147 type `struct S' if it were not for code just below. With this
11148 code however, later parts of the compiler see something like:
11150 struct S' == struct S
11151 typedef struct S' MY_TYPE;
11154 And they can then deduce (from the node for type struct S') that
11155 the original object declaration was:
11159 Being able to do this is important for proper support of protoize,
11160 and also for generating precise symbolic debugging information
11161 which takes full account of the programmer's (typedef) vocabulary.
11163 Obviously, we don't want to generate a duplicate ..._TYPE node if
11164 the TYPE_DECL node that we are now processing really represents a
11165 standard built-in type. */
11168 set_underlying_type (tree x
)
11170 if (x
== error_mark_node
)
11172 if (DECL_IS_BUILTIN (x
))
11174 if (TYPE_NAME (TREE_TYPE (x
)) == 0)
11175 TYPE_NAME (TREE_TYPE (x
)) = x
;
11177 else if (TREE_TYPE (x
) != error_mark_node
11178 && DECL_ORIGINAL_TYPE (x
) == NULL_TREE
)
11180 tree tt
= TREE_TYPE (x
);
11181 DECL_ORIGINAL_TYPE (x
) = tt
;
11182 tt
= build_variant_type_copy (tt
);
11183 TYPE_STUB_DECL (tt
) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x
));
11184 TYPE_NAME (tt
) = x
;
11185 TREE_USED (tt
) = TREE_USED (x
);
11186 TREE_TYPE (x
) = tt
;
11190 /* Record the types used by the current global variable declaration
11191 being parsed, so that we can decide later to emit their debug info.
11192 Those types are in types_used_by_cur_var_decl, and we are going to
11193 store them in the types_used_by_vars_hash hash table.
11194 DECL is the declaration of the global variable that has been parsed. */
11197 record_types_used_by_current_var_decl (tree decl
)
11199 gcc_assert (decl
&& DECL_P (decl
) && TREE_STATIC (decl
));
11201 while (types_used_by_cur_var_decl
&& !types_used_by_cur_var_decl
->is_empty ())
11203 tree type
= types_used_by_cur_var_decl
->pop ();
11204 types_used_by_var_decl_insert (type
, decl
);
11208 /* If DECL is a typedef that is declared in the current function,
11209 record it for the purpose of -Wunused-local-typedefs. */
11212 record_locally_defined_typedef (tree decl
)
11214 struct c_language_function
*l
;
11216 if (!warn_unused_local_typedefs
11218 /* if this is not a locally defined typedef then we are not
11220 || !is_typedef_decl (decl
)
11221 || !decl_function_context (decl
))
11224 l
= (struct c_language_function
*) cfun
->language
;
11225 vec_safe_push (l
->local_typedefs
, decl
);
11228 /* If T is a TYPE_DECL declared locally, mark it as used. */
11231 maybe_record_typedef_use (tree t
)
11233 if (!is_typedef_decl (t
))
11236 TREE_USED (t
) = true;
11239 /* Warn if there are some unused locally defined typedefs in the
11240 current function. */
11243 maybe_warn_unused_local_typedefs (void)
11247 /* The number of times we have emitted -Wunused-local-typedefs
11248 warnings. If this is different from errorcount, that means some
11249 unrelated errors have been issued. In which case, we'll avoid
11250 emitting "unused-local-typedefs" warnings. */
11251 static int unused_local_typedefs_warn_count
;
11252 struct c_language_function
*l
;
11257 if ((l
= (struct c_language_function
*) cfun
->language
) == NULL
)
11260 if (warn_unused_local_typedefs
11261 && errorcount
== unused_local_typedefs_warn_count
)
11263 FOR_EACH_VEC_SAFE_ELT (l
->local_typedefs
, i
, decl
)
11264 if (!TREE_USED (decl
))
11265 warning_at (DECL_SOURCE_LOCATION (decl
),
11266 OPT_Wunused_local_typedefs
,
11267 "typedef %qD locally defined but not used", decl
);
11268 unused_local_typedefs_warn_count
= errorcount
;
11271 vec_free (l
->local_typedefs
);
11274 /* The C and C++ parsers both use vectors to hold function arguments.
11275 For efficiency, we keep a cache of unused vectors. This is the
11278 typedef vec
<tree
, va_gc
> *tree_gc_vec
;
11279 static GTY((deletable
)) vec
<tree_gc_vec
, va_gc
> *tree_vector_cache
;
11281 /* Return a new vector from the cache. If the cache is empty,
11282 allocate a new vector. These vectors are GC'ed, so it is OK if the
11283 pointer is not released.. */
11286 make_tree_vector (void)
11288 if (tree_vector_cache
&& !tree_vector_cache
->is_empty ())
11289 return tree_vector_cache
->pop ();
11292 /* Passing 0 to vec::alloc returns NULL, and our callers require
11293 that we always return a non-NULL value. The vector code uses
11294 4 when growing a NULL vector, so we do too. */
11295 vec
<tree
, va_gc
> *v
;
11301 /* Release a vector of trees back to the cache. */
11304 release_tree_vector (vec
<tree
, va_gc
> *vec
)
11309 vec_safe_push (tree_vector_cache
, vec
);
11313 /* Get a new tree vector holding a single tree. */
11316 make_tree_vector_single (tree t
)
11318 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
11319 ret
->quick_push (t
);
11323 /* Get a new tree vector of the TREE_VALUEs of a TREE_LIST chain. */
11326 make_tree_vector_from_list (tree list
)
11328 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
11329 for (; list
; list
= TREE_CHAIN (list
))
11330 vec_safe_push (ret
, TREE_VALUE (list
));
11334 /* Get a new tree vector which is a copy of an existing one. */
11337 make_tree_vector_copy (const vec
<tree
, va_gc
> *orig
)
11339 vec
<tree
, va_gc
> *ret
;
11343 ret
= make_tree_vector ();
11344 vec_safe_reserve (ret
, vec_safe_length (orig
));
11345 FOR_EACH_VEC_SAFE_ELT (orig
, ix
, t
)
11346 ret
->quick_push (t
);
11350 /* Return true if KEYWORD starts a type specifier. */
11353 keyword_begins_type_specifier (enum rid keyword
)
11369 case RID_DFLOAT128
:
11389 /* Return true if KEYWORD names a type qualifier. */
11392 keyword_is_type_qualifier (enum rid keyword
)
11405 /* Return true if KEYWORD names a storage class specifier.
11407 RID_TYPEDEF is not included in this list despite `typedef' being
11408 listed in C99 6.7.1.1. 6.7.1.3 indicates that `typedef' is listed as
11409 such for syntactic convenience only. */
11412 keyword_is_storage_class_specifier (enum rid keyword
)
11428 /* Return true if KEYWORD names a function-specifier [dcl.fct.spec]. */
11431 keyword_is_function_specifier (enum rid keyword
)
11445 /* Return true if KEYWORD names a decl-specifier [dcl.spec] or a
11446 declaration-specifier (C99 6.7). */
11449 keyword_is_decl_specifier (enum rid keyword
)
11451 if (keyword_is_storage_class_specifier (keyword
)
11452 || keyword_is_type_qualifier (keyword
)
11453 || keyword_is_function_specifier (keyword
))
11460 case RID_CONSTEXPR
:
11467 /* Initialize language-specific-bits of tree_contains_struct. */
11470 c_common_init_ts (void)
11472 MARK_TS_TYPED (C_MAYBE_CONST_EXPR
);
11473 MARK_TS_TYPED (EXCESS_PRECISION_EXPR
);
11474 MARK_TS_TYPED (ARRAY_NOTATION_REF
);
11477 /* Build a user-defined numeric literal out of an integer constant type VALUE
11478 with identifier SUFFIX. */
11481 build_userdef_literal (tree suffix_id
, tree value
,
11482 enum overflow_type overflow
, tree num_string
)
11484 tree literal
= make_node (USERDEF_LITERAL
);
11485 USERDEF_LITERAL_SUFFIX_ID (literal
) = suffix_id
;
11486 USERDEF_LITERAL_VALUE (literal
) = value
;
11487 USERDEF_LITERAL_OVERFLOW (literal
) = overflow
;
11488 USERDEF_LITERAL_NUM_STRING (literal
) = num_string
;
11492 /* For vector[index], convert the vector to a
11493 pointer of the underlying type. */
11495 convert_vector_to_pointer_for_subscript (location_t loc
,
11496 tree
* vecp
, tree index
)
11498 if (TREE_CODE (TREE_TYPE (*vecp
)) == VECTOR_TYPE
)
11500 tree type
= TREE_TYPE (*vecp
);
11503 if (TREE_CODE (index
) == INTEGER_CST
)
11504 if (!tree_fits_uhwi_p (index
)
11505 || ((unsigned HOST_WIDE_INT
) tree_to_uhwi (index
)
11506 >= TYPE_VECTOR_SUBPARTS (type
)))
11507 warning_at (loc
, OPT_Warray_bounds
, "index value is out of bound");
11509 c_common_mark_addressable_vec (*vecp
);
11510 type
= build_qualified_type (TREE_TYPE (type
), TYPE_QUALS (type
));
11511 type
= build_pointer_type (type
);
11512 type1
= build_pointer_type (TREE_TYPE (*vecp
));
11513 *vecp
= build1 (ADDR_EXPR
, type1
, *vecp
);
11514 *vecp
= convert (type
, *vecp
);
11518 /* Determine which of the operands, if any, is a scalar that needs to be
11519 converted to a vector, for the range of operations. */
11521 scalar_to_vector (location_t loc
, enum tree_code code
, tree op0
, tree op1
,
11524 tree type0
= TREE_TYPE (op0
);
11525 tree type1
= TREE_TYPE (op1
);
11526 bool integer_only_op
= false;
11527 enum stv_conv ret
= stv_firstarg
;
11529 gcc_assert (TREE_CODE (type0
) == VECTOR_TYPE
11530 || TREE_CODE (type1
) == VECTOR_TYPE
);
11533 /* Most GENERIC binary expressions require homogeneous arguments.
11534 LSHIFT_EXPR and RSHIFT_EXPR are exceptions and accept a first
11535 argument that is a vector and a second one that is a scalar, so
11536 we never return stv_secondarg for them. */
11539 if (TREE_CODE (type0
) == INTEGER_TYPE
11540 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
11542 if (unsafe_conversion_p (TREE_TYPE (type1
), op0
, false))
11545 error_at (loc
, "conversion of scalar %qT to vector %qT "
11546 "involves truncation", type0
, type1
);
11550 return stv_firstarg
;
11557 integer_only_op
= true;
11558 /* ... fall through ... */
11560 case VEC_COND_EXPR
:
11565 case TRUNC_DIV_EXPR
:
11566 case CEIL_DIV_EXPR
:
11567 case FLOOR_DIV_EXPR
:
11568 case ROUND_DIV_EXPR
:
11569 case EXACT_DIV_EXPR
:
11570 case TRUNC_MOD_EXPR
:
11571 case FLOOR_MOD_EXPR
:
11579 /* What about UNLT_EXPR? */
11580 if (TREE_CODE (type0
) == VECTOR_TYPE
)
11583 ret
= stv_secondarg
;
11584 /* Swap TYPE0 with TYPE1 and OP0 with OP1 */
11585 tmp
= type0
; type0
= type1
; type1
= tmp
;
11586 tmp
= op0
; op0
= op1
; op1
= tmp
;
11589 if (TREE_CODE (type0
) == INTEGER_TYPE
11590 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
11592 if (unsafe_conversion_p (TREE_TYPE (type1
), op0
, false))
11595 error_at (loc
, "conversion of scalar %qT to vector %qT "
11596 "involves truncation", type0
, type1
);
11601 else if (!integer_only_op
11602 /* Allow integer --> real conversion if safe. */
11603 && (TREE_CODE (type0
) == REAL_TYPE
11604 || TREE_CODE (type0
) == INTEGER_TYPE
)
11605 && SCALAR_FLOAT_TYPE_P (TREE_TYPE (type1
)))
11607 if (unsafe_conversion_p (TREE_TYPE (type1
), op0
, false))
11610 error_at (loc
, "conversion of scalar %qT to vector %qT "
11611 "involves truncation", type0
, type1
);
11620 return stv_nothing
;
11623 /* Return true iff ALIGN is an integral constant that is a fundamental
11624 alignment, as defined by [basic.align] in the c++-11
11629 [A fundamental alignment is represented by an alignment less than or
11630 equal to the greatest alignment supported by the implementation
11631 in all contexts, which is equal to
11632 alignof(max_align_t)]. */
11635 cxx_fundamental_alignment_p (unsigned align
)
11637 return (align
<= MAX (TYPE_ALIGN (long_long_integer_type_node
),
11638 TYPE_ALIGN (long_double_type_node
)));
11641 #include "gt-c-family-c-common.h"