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"
47 cpp_reader
*parse_in
; /* Declared in c-pragma.h. */
49 /* The following symbols are subsumed in the c_global_trees array, and
50 listed here individually for documentation purposes.
52 INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
54 tree short_integer_type_node;
55 tree long_integer_type_node;
56 tree long_long_integer_type_node;
57 tree int128_integer_type_node;
59 tree short_unsigned_type_node;
60 tree long_unsigned_type_node;
61 tree long_long_unsigned_type_node;
62 tree int128_unsigned_type_node;
64 tree truthvalue_type_node;
65 tree truthvalue_false_node;
66 tree truthvalue_true_node;
68 tree ptrdiff_type_node;
70 tree unsigned_char_type_node;
71 tree signed_char_type_node;
74 tree char16_type_node;
75 tree char32_type_node;
78 tree double_type_node;
79 tree long_double_type_node;
81 tree complex_integer_type_node;
82 tree complex_float_type_node;
83 tree complex_double_type_node;
84 tree complex_long_double_type_node;
86 tree dfloat32_type_node;
87 tree dfloat64_type_node;
88 tree_dfloat128_type_node;
96 tree unsigned_intQI_type_node;
97 tree unsigned_intHI_type_node;
98 tree unsigned_intSI_type_node;
99 tree unsigned_intDI_type_node;
100 tree unsigned_intTI_type_node;
102 tree widest_integer_literal_type_node;
103 tree widest_unsigned_literal_type_node;
105 Nodes for types `void *' and `const void *'.
107 tree ptr_type_node, const_ptr_type_node;
109 Nodes for types `char *' and `const char *'.
111 tree string_type_node, const_string_type_node;
113 Type `char[SOMENUMBER]'.
114 Used when an array of char is needed and the size is irrelevant.
116 tree char_array_type_node;
118 Type `int[SOMENUMBER]' or something like it.
119 Used when an array of int needed and the size is irrelevant.
121 tree int_array_type_node;
123 Type `wchar_t[SOMENUMBER]' or something like it.
124 Used when a wide string literal is created.
126 tree wchar_array_type_node;
128 Type `char16_t[SOMENUMBER]' or something like it.
129 Used when a UTF-16 string literal is created.
131 tree char16_array_type_node;
133 Type `char32_t[SOMENUMBER]' or something like it.
134 Used when a UTF-32 string literal is created.
136 tree char32_array_type_node;
138 Type `int ()' -- used for implicit declaration of functions.
140 tree default_function_type;
142 A VOID_TYPE node, packaged in a TREE_LIST.
146 The lazily created VAR_DECLs for __FUNCTION__, __PRETTY_FUNCTION__,
147 and __func__. (C doesn't generate __FUNCTION__ and__PRETTY_FUNCTION__
148 VAR_DECLS, but C++ does.)
150 tree function_name_decl_node;
151 tree pretty_function_name_decl_node;
152 tree c99_function_name_decl_node;
154 Stack of nested function name VAR_DECLs.
156 tree saved_function_name_decls;
160 tree c_global_trees
[CTI_MAX
];
162 /* Switches common to the C front ends. */
164 /* Nonzero means don't output line number information. */
166 char flag_no_line_commands
;
168 /* Nonzero causes -E output not to be done, but directives such as
169 #define that have side effects are still obeyed. */
173 /* Nonzero means dump macros in some fashion. */
175 char flag_dump_macros
;
177 /* Nonzero means pass #include lines through to the output. */
179 char flag_dump_includes
;
181 /* Nonzero means process PCH files while preprocessing. */
183 bool flag_pch_preprocess
;
185 /* The file name to which we should write a precompiled header, or
186 NULL if no header will be written in this compile. */
188 const char *pch_file
;
190 /* Nonzero if an ISO standard was selected. It rejects macros in the
194 /* C/ObjC language option variables. */
197 /* Nonzero means allow type mismatches in conditional expressions;
198 just make their values `void'. */
200 int flag_cond_mismatch
;
202 /* Nonzero means enable C89 Amendment 1 features. */
206 /* Nonzero means use the ISO C99 (or C11) dialect of C. */
210 /* Nonzero means use the ISO C11 dialect of C. */
214 /* Nonzero means that we have builtin functions, and main is an int. */
219 /* ObjC language option variables. */
222 /* Tells the compiler that this is a special run. Do not perform any
223 compiling, instead we are to test some platform dependent features
224 and output a C header file with appropriate definitions. */
226 int print_struct_values
;
228 /* Tells the compiler what is the constant string class for ObjC. */
230 const char *constant_string_class_name
;
233 /* C++ language option variables. */
236 /* Nonzero means generate separate instantiation control files and
237 juggle them at link time. */
239 int flag_use_repository
;
241 /* The C++ dialect being used. C++98 is the default. */
243 enum cxx_dialect cxx_dialect
= cxx98
;
245 /* Maximum template instantiation depth. This limit exists to limit the
246 time it takes to notice excessively recursive template instantiations.
248 The default is lower than the 1024 recommended by the C++0x standard
249 because G++ runs out of stack before 1024 with highly recursive template
250 argument deduction substitution (g++.dg/cpp0x/enum11.C). */
252 int max_tinst_depth
= 900;
254 /* The elements of `ridpointers' are identifier nodes for the reserved
255 type names and storage classes. It is indexed by a RID_... value. */
258 tree (*make_fname_decl
) (location_t
, tree
, int);
260 /* Nonzero means don't warn about problems that occur when the code is
262 int c_inhibit_evaluation_warnings
;
264 /* Whether we are building a boolean conversion inside
265 convert_for_assignment, or some other late binary operation. If
266 build_binary_op is called for C (from code shared by C and C++) in
267 this case, then the operands have already been folded and the
268 result will not be folded again, so C_MAYBE_CONST_EXPR should not
270 bool in_late_binary_op
;
272 /* Whether lexing has been completed, so subsequent preprocessor
273 errors should use the compiler's input_location. */
274 bool done_lexing
= false;
276 /* Information about how a function name is generated. */
279 tree
*const decl
; /* pointer to the VAR_DECL. */
280 const unsigned rid
; /* RID number for the identifier. */
281 const int pretty
; /* How pretty is it? */
284 /* The three ways of getting then name of the current function. */
286 const struct fname_var_t fname_vars
[] =
288 /* C99 compliant __func__, must be first. */
289 {&c99_function_name_decl_node
, RID_C99_FUNCTION_NAME
, 0},
290 /* GCC __FUNCTION__ compliant. */
291 {&function_name_decl_node
, RID_FUNCTION_NAME
, 0},
292 /* GCC __PRETTY_FUNCTION__ compliant. */
293 {&pretty_function_name_decl_node
, RID_PRETTY_FUNCTION_NAME
, 1},
297 /* Global visibility options. */
298 struct visibility_flags visibility_options
;
300 static tree
c_fully_fold_internal (tree expr
, bool, bool *, bool *);
301 static tree
check_case_value (tree
);
302 static bool check_case_bounds (tree
, tree
, tree
*, tree
*);
304 static tree
handle_packed_attribute (tree
*, tree
, tree
, int, bool *);
305 static tree
handle_nocommon_attribute (tree
*, tree
, tree
, int, bool *);
306 static tree
handle_common_attribute (tree
*, tree
, tree
, int, bool *);
307 static tree
handle_noreturn_attribute (tree
*, tree
, tree
, int, bool *);
308 static tree
handle_hot_attribute (tree
*, tree
, tree
, int, bool *);
309 static tree
handle_cold_attribute (tree
*, tree
, tree
, int, bool *);
310 static tree
handle_no_sanitize_address_attribute (tree
*, tree
, tree
,
312 static tree
handle_no_address_safety_analysis_attribute (tree
*, tree
, tree
,
314 static tree
handle_noinline_attribute (tree
*, tree
, tree
, int, bool *);
315 static tree
handle_noclone_attribute (tree
*, tree
, tree
, int, bool *);
316 static tree
handle_leaf_attribute (tree
*, tree
, tree
, int, bool *);
317 static tree
handle_always_inline_attribute (tree
*, tree
, tree
, int,
319 static tree
handle_gnu_inline_attribute (tree
*, tree
, tree
, int, bool *);
320 static tree
handle_artificial_attribute (tree
*, tree
, tree
, int, bool *);
321 static tree
handle_flatten_attribute (tree
*, tree
, tree
, int, bool *);
322 static tree
handle_error_attribute (tree
*, tree
, tree
, int, bool *);
323 static tree
handle_used_attribute (tree
*, tree
, tree
, int, bool *);
324 static tree
handle_unused_attribute (tree
*, tree
, tree
, int, bool *);
325 static tree
handle_externally_visible_attribute (tree
*, tree
, tree
, int,
327 static tree
handle_const_attribute (tree
*, tree
, tree
, int, bool *);
328 static tree
handle_transparent_union_attribute (tree
*, tree
, tree
,
330 static tree
handle_constructor_attribute (tree
*, tree
, tree
, int, bool *);
331 static tree
handle_destructor_attribute (tree
*, tree
, tree
, int, bool *);
332 static tree
handle_mode_attribute (tree
*, tree
, tree
, int, bool *);
333 static tree
handle_section_attribute (tree
*, tree
, tree
, int, bool *);
334 static tree
handle_aligned_attribute (tree
*, tree
, tree
, int, bool *);
335 static tree
handle_weak_attribute (tree
*, tree
, tree
, int, bool *) ;
336 static tree
handle_alias_ifunc_attribute (bool, tree
*, tree
, tree
, bool *);
337 static tree
handle_ifunc_attribute (tree
*, tree
, tree
, int, bool *);
338 static tree
handle_alias_attribute (tree
*, tree
, tree
, int, bool *);
339 static tree
handle_weakref_attribute (tree
*, tree
, tree
, int, bool *) ;
340 static tree
handle_visibility_attribute (tree
*, tree
, tree
, int,
342 static tree
handle_tls_model_attribute (tree
*, tree
, tree
, int,
344 static tree
handle_no_instrument_function_attribute (tree
*, tree
,
346 static tree
handle_malloc_attribute (tree
*, tree
, tree
, int, bool *);
347 static tree
handle_returns_twice_attribute (tree
*, tree
, tree
, int, bool *);
348 static tree
handle_no_limit_stack_attribute (tree
*, tree
, tree
, int,
350 static tree
handle_pure_attribute (tree
*, tree
, tree
, int, bool *);
351 static tree
handle_tm_attribute (tree
*, tree
, tree
, int, bool *);
352 static tree
handle_tm_wrap_attribute (tree
*, tree
, tree
, int, bool *);
353 static tree
handle_novops_attribute (tree
*, tree
, tree
, int, bool *);
354 static tree
handle_deprecated_attribute (tree
*, tree
, tree
, int,
356 static tree
handle_vector_size_attribute (tree
*, tree
, tree
, int,
358 static tree
handle_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
359 static tree
handle_nothrow_attribute (tree
*, tree
, tree
, int, bool *);
360 static tree
handle_cleanup_attribute (tree
*, tree
, tree
, int, bool *);
361 static tree
handle_warn_unused_result_attribute (tree
*, tree
, tree
, int,
363 static tree
handle_sentinel_attribute (tree
*, tree
, tree
, int, bool *);
364 static tree
handle_type_generic_attribute (tree
*, tree
, tree
, int, bool *);
365 static tree
handle_alloc_size_attribute (tree
*, tree
, tree
, int, bool *);
366 static tree
handle_target_attribute (tree
*, tree
, tree
, int, bool *);
367 static tree
handle_optimize_attribute (tree
*, tree
, tree
, int, bool *);
368 static tree
ignore_attribute (tree
*, tree
, tree
, int, bool *);
369 static tree
handle_no_split_stack_attribute (tree
*, tree
, tree
, int, bool *);
370 static tree
handle_fnspec_attribute (tree
*, tree
, tree
, int, bool *);
371 static tree
handle_warn_unused_attribute (tree
*, tree
, tree
, int, bool *);
373 static void check_function_nonnull (tree
, int, tree
*);
374 static void check_nonnull_arg (void *, tree
, unsigned HOST_WIDE_INT
);
375 static bool nonnull_check_p (tree
, unsigned HOST_WIDE_INT
);
376 static bool get_nonnull_operand (tree
, unsigned HOST_WIDE_INT
*);
377 static int resort_field_decl_cmp (const void *, const void *);
379 /* Reserved words. The third field is a mask: keywords are disabled
380 if they match the mask.
383 C --std=c89: D_C99 | D_CXXONLY | D_OBJC | D_CXX_OBJC
384 C --std=c99: D_CXXONLY | D_OBJC
385 ObjC is like C except that D_OBJC and D_CXX_OBJC are not set
386 C++ --std=c98: D_CONLY | D_CXXOX | D_OBJC
387 C++ --std=c0x: D_CONLY | D_OBJC
388 ObjC++ is like C++ except that D_OBJC is not set
390 If -fno-asm is used, D_ASM is added to the mask. If
391 -fno-gnu-keywords is used, D_EXT is added. If -fno-asm and C in
392 C89 mode, D_EXT89 is added for both -fno-asm and -fno-gnu-keywords.
393 In C with -Wc++-compat, we warn if D_CXXWARN is set.
395 Note the complication of the D_CXX_OBJC keywords. These are
396 reserved words such as 'class'. In C++, 'class' is a reserved
397 word. In Objective-C++ it is too. In Objective-C, it is a
398 reserved word too, but only if it follows an '@' sign.
400 const struct c_common_resword c_common_reswords
[] =
402 { "_Alignas", RID_ALIGNAS
, D_CONLY
},
403 { "_Alignof", RID_ALIGNOF
, D_CONLY
},
404 { "_Bool", RID_BOOL
, D_CONLY
},
405 { "_Complex", RID_COMPLEX
, 0 },
406 { "_Imaginary", RID_IMAGINARY
, D_CONLY
},
407 { "_Decimal32", RID_DFLOAT32
, D_CONLY
| D_EXT
},
408 { "_Decimal64", RID_DFLOAT64
, D_CONLY
| D_EXT
},
409 { "_Decimal128", RID_DFLOAT128
, D_CONLY
| D_EXT
},
410 { "_Fract", RID_FRACT
, D_CONLY
| D_EXT
},
411 { "_Accum", RID_ACCUM
, D_CONLY
| D_EXT
},
412 { "_Sat", RID_SAT
, D_CONLY
| D_EXT
},
413 { "_Static_assert", RID_STATIC_ASSERT
, D_CONLY
},
414 { "_Noreturn", RID_NORETURN
, D_CONLY
},
415 { "_Generic", RID_GENERIC
, D_CONLY
},
416 { "__FUNCTION__", RID_FUNCTION_NAME
, 0 },
417 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME
, 0 },
418 { "__alignof", RID_ALIGNOF
, 0 },
419 { "__alignof__", RID_ALIGNOF
, 0 },
420 { "__asm", RID_ASM
, 0 },
421 { "__asm__", RID_ASM
, 0 },
422 { "__attribute", RID_ATTRIBUTE
, 0 },
423 { "__attribute__", RID_ATTRIBUTE
, 0 },
424 { "__bases", RID_BASES
, D_CXXONLY
},
425 { "__builtin_choose_expr", RID_CHOOSE_EXPR
, D_CONLY
},
426 { "__builtin_complex", RID_BUILTIN_COMPLEX
, D_CONLY
},
427 { "__builtin_shuffle", RID_BUILTIN_SHUFFLE
, 0 },
428 { "__builtin_offsetof", RID_OFFSETOF
, 0 },
429 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P
, D_CONLY
},
430 { "__builtin_va_arg", RID_VA_ARG
, 0 },
431 { "__complex", RID_COMPLEX
, 0 },
432 { "__complex__", RID_COMPLEX
, 0 },
433 { "__const", RID_CONST
, 0 },
434 { "__const__", RID_CONST
, 0 },
435 { "__decltype", RID_DECLTYPE
, D_CXXONLY
},
436 { "__direct_bases", RID_DIRECT_BASES
, D_CXXONLY
},
437 { "__extension__", RID_EXTENSION
, 0 },
438 { "__func__", RID_C99_FUNCTION_NAME
, 0 },
439 { "__has_nothrow_assign", RID_HAS_NOTHROW_ASSIGN
, D_CXXONLY
},
440 { "__has_nothrow_constructor", RID_HAS_NOTHROW_CONSTRUCTOR
, D_CXXONLY
},
441 { "__has_nothrow_copy", RID_HAS_NOTHROW_COPY
, D_CXXONLY
},
442 { "__has_trivial_assign", RID_HAS_TRIVIAL_ASSIGN
, D_CXXONLY
},
443 { "__has_trivial_constructor", RID_HAS_TRIVIAL_CONSTRUCTOR
, D_CXXONLY
},
444 { "__has_trivial_copy", RID_HAS_TRIVIAL_COPY
, D_CXXONLY
},
445 { "__has_trivial_destructor", RID_HAS_TRIVIAL_DESTRUCTOR
, D_CXXONLY
},
446 { "__has_virtual_destructor", RID_HAS_VIRTUAL_DESTRUCTOR
, D_CXXONLY
},
447 { "__imag", RID_IMAGPART
, 0 },
448 { "__imag__", RID_IMAGPART
, 0 },
449 { "__inline", RID_INLINE
, 0 },
450 { "__inline__", RID_INLINE
, 0 },
451 { "__int128", RID_INT128
, 0 },
452 { "__is_abstract", RID_IS_ABSTRACT
, D_CXXONLY
},
453 { "__is_base_of", RID_IS_BASE_OF
, D_CXXONLY
},
454 { "__is_class", RID_IS_CLASS
, D_CXXONLY
},
455 { "__is_convertible_to", RID_IS_CONVERTIBLE_TO
, D_CXXONLY
},
456 { "__is_empty", RID_IS_EMPTY
, D_CXXONLY
},
457 { "__is_enum", RID_IS_ENUM
, D_CXXONLY
},
458 { "__is_final", RID_IS_FINAL
, D_CXXONLY
},
459 { "__is_literal_type", RID_IS_LITERAL_TYPE
, D_CXXONLY
},
460 { "__is_pod", RID_IS_POD
, D_CXXONLY
},
461 { "__is_polymorphic", RID_IS_POLYMORPHIC
, D_CXXONLY
},
462 { "__is_standard_layout", RID_IS_STD_LAYOUT
, D_CXXONLY
},
463 { "__is_trivial", RID_IS_TRIVIAL
, D_CXXONLY
},
464 { "__is_union", RID_IS_UNION
, D_CXXONLY
},
465 { "__label__", RID_LABEL
, 0 },
466 { "__null", RID_NULL
, 0 },
467 { "__real", RID_REALPART
, 0 },
468 { "__real__", RID_REALPART
, 0 },
469 { "__restrict", RID_RESTRICT
, 0 },
470 { "__restrict__", RID_RESTRICT
, 0 },
471 { "__signed", RID_SIGNED
, 0 },
472 { "__signed__", RID_SIGNED
, 0 },
473 { "__thread", RID_THREAD
, 0 },
474 { "__transaction_atomic", RID_TRANSACTION_ATOMIC
, 0 },
475 { "__transaction_relaxed", RID_TRANSACTION_RELAXED
, 0 },
476 { "__transaction_cancel", RID_TRANSACTION_CANCEL
, 0 },
477 { "__typeof", RID_TYPEOF
, 0 },
478 { "__typeof__", RID_TYPEOF
, 0 },
479 { "__underlying_type", RID_UNDERLYING_TYPE
, D_CXXONLY
},
480 { "__volatile", RID_VOLATILE
, 0 },
481 { "__volatile__", RID_VOLATILE
, 0 },
482 { "alignas", RID_ALIGNAS
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
483 { "alignof", RID_ALIGNOF
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
484 { "asm", RID_ASM
, D_ASM
},
485 { "auto", RID_AUTO
, 0 },
486 { "bool", RID_BOOL
, D_CXXONLY
| D_CXXWARN
},
487 { "break", RID_BREAK
, 0 },
488 { "case", RID_CASE
, 0 },
489 { "catch", RID_CATCH
, D_CXX_OBJC
| D_CXXWARN
},
490 { "char", RID_CHAR
, 0 },
491 { "char16_t", RID_CHAR16
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
492 { "char32_t", RID_CHAR32
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
493 { "class", RID_CLASS
, D_CXX_OBJC
| D_CXXWARN
},
494 { "const", RID_CONST
, 0 },
495 { "constexpr", RID_CONSTEXPR
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
496 { "const_cast", RID_CONSTCAST
, D_CXXONLY
| D_CXXWARN
},
497 { "continue", RID_CONTINUE
, 0 },
498 { "decltype", RID_DECLTYPE
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
499 { "default", RID_DEFAULT
, 0 },
500 { "delete", RID_DELETE
, D_CXXONLY
| D_CXXWARN
},
502 { "double", RID_DOUBLE
, 0 },
503 { "dynamic_cast", RID_DYNCAST
, D_CXXONLY
| D_CXXWARN
},
504 { "else", RID_ELSE
, 0 },
505 { "enum", RID_ENUM
, 0 },
506 { "explicit", RID_EXPLICIT
, D_CXXONLY
| D_CXXWARN
},
507 { "export", RID_EXPORT
, D_CXXONLY
| D_CXXWARN
},
508 { "extern", RID_EXTERN
, 0 },
509 { "false", RID_FALSE
, D_CXXONLY
| D_CXXWARN
},
510 { "float", RID_FLOAT
, 0 },
511 { "for", RID_FOR
, 0 },
512 { "friend", RID_FRIEND
, D_CXXONLY
| D_CXXWARN
},
513 { "goto", RID_GOTO
, 0 },
515 { "inline", RID_INLINE
, D_EXT89
},
516 { "int", RID_INT
, 0 },
517 { "long", RID_LONG
, 0 },
518 { "mutable", RID_MUTABLE
, D_CXXONLY
| D_CXXWARN
},
519 { "namespace", RID_NAMESPACE
, D_CXXONLY
| D_CXXWARN
},
520 { "new", RID_NEW
, D_CXXONLY
| D_CXXWARN
},
521 { "noexcept", RID_NOEXCEPT
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
522 { "nullptr", RID_NULLPTR
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
523 { "operator", RID_OPERATOR
, D_CXXONLY
| D_CXXWARN
},
524 { "private", RID_PRIVATE
, D_CXX_OBJC
| D_CXXWARN
},
525 { "protected", RID_PROTECTED
, D_CXX_OBJC
| D_CXXWARN
},
526 { "public", RID_PUBLIC
, D_CXX_OBJC
| D_CXXWARN
},
527 { "register", RID_REGISTER
, 0 },
528 { "reinterpret_cast", RID_REINTCAST
, D_CXXONLY
| D_CXXWARN
},
529 { "restrict", RID_RESTRICT
, D_CONLY
| D_C99
},
530 { "return", RID_RETURN
, 0 },
531 { "short", RID_SHORT
, 0 },
532 { "signed", RID_SIGNED
, 0 },
533 { "sizeof", RID_SIZEOF
, 0 },
534 { "static", RID_STATIC
, 0 },
535 { "static_assert", RID_STATIC_ASSERT
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
536 { "static_cast", RID_STATCAST
, D_CXXONLY
| D_CXXWARN
},
537 { "struct", RID_STRUCT
, 0 },
538 { "switch", RID_SWITCH
, 0 },
539 { "template", RID_TEMPLATE
, D_CXXONLY
| D_CXXWARN
},
540 { "this", RID_THIS
, D_CXXONLY
| D_CXXWARN
},
541 { "thread_local", RID_THREAD
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
542 { "throw", RID_THROW
, D_CXX_OBJC
| D_CXXWARN
},
543 { "true", RID_TRUE
, D_CXXONLY
| D_CXXWARN
},
544 { "try", RID_TRY
, D_CXX_OBJC
| D_CXXWARN
},
545 { "typedef", RID_TYPEDEF
, 0 },
546 { "typename", RID_TYPENAME
, D_CXXONLY
| D_CXXWARN
},
547 { "typeid", RID_TYPEID
, D_CXXONLY
| D_CXXWARN
},
548 { "typeof", RID_TYPEOF
, D_ASM
| D_EXT
},
549 { "union", RID_UNION
, 0 },
550 { "unsigned", RID_UNSIGNED
, 0 },
551 { "using", RID_USING
, D_CXXONLY
| D_CXXWARN
},
552 { "virtual", RID_VIRTUAL
, D_CXXONLY
| D_CXXWARN
},
553 { "void", RID_VOID
, 0 },
554 { "volatile", RID_VOLATILE
, 0 },
555 { "wchar_t", RID_WCHAR
, D_CXXONLY
},
556 { "while", RID_WHILE
, 0 },
557 /* These Objective-C keywords are recognized only immediately after
559 { "compatibility_alias", RID_AT_ALIAS
, D_OBJC
},
560 { "defs", RID_AT_DEFS
, D_OBJC
},
561 { "encode", RID_AT_ENCODE
, D_OBJC
},
562 { "end", RID_AT_END
, D_OBJC
},
563 { "implementation", RID_AT_IMPLEMENTATION
, D_OBJC
},
564 { "interface", RID_AT_INTERFACE
, D_OBJC
},
565 { "protocol", RID_AT_PROTOCOL
, D_OBJC
},
566 { "selector", RID_AT_SELECTOR
, D_OBJC
},
567 { "finally", RID_AT_FINALLY
, D_OBJC
},
568 { "synchronized", RID_AT_SYNCHRONIZED
, D_OBJC
},
569 { "optional", RID_AT_OPTIONAL
, D_OBJC
},
570 { "required", RID_AT_REQUIRED
, D_OBJC
},
571 { "property", RID_AT_PROPERTY
, D_OBJC
},
572 { "package", RID_AT_PACKAGE
, D_OBJC
},
573 { "synthesize", RID_AT_SYNTHESIZE
, D_OBJC
},
574 { "dynamic", RID_AT_DYNAMIC
, D_OBJC
},
575 /* These are recognized only in protocol-qualifier context
577 { "bycopy", RID_BYCOPY
, D_OBJC
},
578 { "byref", RID_BYREF
, D_OBJC
},
579 { "in", RID_IN
, D_OBJC
},
580 { "inout", RID_INOUT
, D_OBJC
},
581 { "oneway", RID_ONEWAY
, D_OBJC
},
582 { "out", RID_OUT
, D_OBJC
},
583 /* These are recognized inside a property attribute list */
584 { "assign", RID_ASSIGN
, D_OBJC
},
585 { "copy", RID_COPY
, D_OBJC
},
586 { "getter", RID_GETTER
, D_OBJC
},
587 { "nonatomic", RID_NONATOMIC
, D_OBJC
},
588 { "readonly", RID_READONLY
, D_OBJC
},
589 { "readwrite", RID_READWRITE
, D_OBJC
},
590 { "retain", RID_RETAIN
, D_OBJC
},
591 { "setter", RID_SETTER
, D_OBJC
},
594 const unsigned int num_c_common_reswords
=
595 sizeof c_common_reswords
/ sizeof (struct c_common_resword
);
597 /* Table of machine-independent attributes common to all C-like languages. */
598 const struct attribute_spec c_common_attribute_table
[] =
600 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
601 affects_type_identity } */
602 { "packed", 0, 0, false, false, false,
603 handle_packed_attribute
, false},
604 { "nocommon", 0, 0, true, false, false,
605 handle_nocommon_attribute
, false},
606 { "common", 0, 0, true, false, false,
607 handle_common_attribute
, false },
608 /* FIXME: logically, noreturn attributes should be listed as
609 "false, true, true" and apply to function types. But implementing this
610 would require all the places in the compiler that use TREE_THIS_VOLATILE
611 on a decl to identify non-returning functions to be located and fixed
612 to check the function type instead. */
613 { "noreturn", 0, 0, true, false, false,
614 handle_noreturn_attribute
, false },
615 { "volatile", 0, 0, true, false, false,
616 handle_noreturn_attribute
, false },
617 { "noinline", 0, 0, true, false, false,
618 handle_noinline_attribute
, false },
619 { "noclone", 0, 0, true, false, false,
620 handle_noclone_attribute
, false },
621 { "leaf", 0, 0, true, false, false,
622 handle_leaf_attribute
, false },
623 { "always_inline", 0, 0, true, false, false,
624 handle_always_inline_attribute
, false },
625 { "gnu_inline", 0, 0, true, false, false,
626 handle_gnu_inline_attribute
, false },
627 { "artificial", 0, 0, true, false, false,
628 handle_artificial_attribute
, false },
629 { "flatten", 0, 0, true, false, false,
630 handle_flatten_attribute
, false },
631 { "used", 0, 0, true, false, false,
632 handle_used_attribute
, false },
633 { "unused", 0, 0, false, false, false,
634 handle_unused_attribute
, false },
635 { "externally_visible", 0, 0, true, false, false,
636 handle_externally_visible_attribute
, false },
637 /* The same comments as for noreturn attributes apply to const ones. */
638 { "const", 0, 0, true, false, false,
639 handle_const_attribute
, false },
640 { "transparent_union", 0, 0, false, false, false,
641 handle_transparent_union_attribute
, false },
642 { "constructor", 0, 1, true, false, false,
643 handle_constructor_attribute
, false },
644 { "destructor", 0, 1, true, false, false,
645 handle_destructor_attribute
, false },
646 { "mode", 1, 1, false, true, false,
647 handle_mode_attribute
, false },
648 { "section", 1, 1, true, false, false,
649 handle_section_attribute
, false },
650 { "aligned", 0, 1, false, false, false,
651 handle_aligned_attribute
, false },
652 { "weak", 0, 0, true, false, false,
653 handle_weak_attribute
, false },
654 { "ifunc", 1, 1, true, false, false,
655 handle_ifunc_attribute
, false },
656 { "alias", 1, 1, true, false, false,
657 handle_alias_attribute
, false },
658 { "weakref", 0, 1, true, false, false,
659 handle_weakref_attribute
, false },
660 { "no_instrument_function", 0, 0, true, false, false,
661 handle_no_instrument_function_attribute
,
663 { "malloc", 0, 0, true, false, false,
664 handle_malloc_attribute
, false },
665 { "returns_twice", 0, 0, true, false, false,
666 handle_returns_twice_attribute
, false },
667 { "no_stack_limit", 0, 0, true, false, false,
668 handle_no_limit_stack_attribute
, false },
669 { "pure", 0, 0, true, false, false,
670 handle_pure_attribute
, false },
671 { "transaction_callable", 0, 0, false, true, false,
672 handle_tm_attribute
, false },
673 { "transaction_unsafe", 0, 0, false, true, false,
674 handle_tm_attribute
, false },
675 { "transaction_safe", 0, 0, false, true, false,
676 handle_tm_attribute
, false },
677 { "transaction_may_cancel_outer", 0, 0, false, true, false,
678 handle_tm_attribute
, false },
679 /* ??? These two attributes didn't make the transition from the
680 Intel language document to the multi-vendor language document. */
681 { "transaction_pure", 0, 0, false, true, false,
682 handle_tm_attribute
, false },
683 { "transaction_wrap", 1, 1, true, false, false,
684 handle_tm_wrap_attribute
, false },
685 /* For internal use (marking of builtins) only. The name contains space
686 to prevent its usage in source code. */
687 { "no vops", 0, 0, true, false, false,
688 handle_novops_attribute
, false },
689 { "deprecated", 0, 1, false, false, false,
690 handle_deprecated_attribute
, false },
691 { "vector_size", 1, 1, false, true, false,
692 handle_vector_size_attribute
, false },
693 { "visibility", 1, 1, false, false, false,
694 handle_visibility_attribute
, false },
695 { "tls_model", 1, 1, true, false, false,
696 handle_tls_model_attribute
, false },
697 { "nonnull", 0, -1, false, true, true,
698 handle_nonnull_attribute
, false },
699 { "nothrow", 0, 0, true, false, false,
700 handle_nothrow_attribute
, false },
701 { "may_alias", 0, 0, false, true, false, NULL
, false },
702 { "cleanup", 1, 1, true, false, false,
703 handle_cleanup_attribute
, false },
704 { "warn_unused_result", 0, 0, false, true, true,
705 handle_warn_unused_result_attribute
, false },
706 { "sentinel", 0, 1, false, true, true,
707 handle_sentinel_attribute
, false },
708 /* For internal use (marking of builtins) only. The name contains space
709 to prevent its usage in source code. */
710 { "type generic", 0, 0, false, true, true,
711 handle_type_generic_attribute
, false },
712 { "alloc_size", 1, 2, false, true, true,
713 handle_alloc_size_attribute
, false },
714 { "cold", 0, 0, true, false, false,
715 handle_cold_attribute
, false },
716 { "hot", 0, 0, true, false, false,
717 handle_hot_attribute
, false },
718 { "no_address_safety_analysis",
719 0, 0, true, false, false,
720 handle_no_address_safety_analysis_attribute
,
722 { "no_sanitize_address", 0, 0, true, false, false,
723 handle_no_sanitize_address_attribute
,
725 { "warning", 1, 1, true, false, false,
726 handle_error_attribute
, false },
727 { "error", 1, 1, true, false, false,
728 handle_error_attribute
, false },
729 { "target", 1, -1, true, false, false,
730 handle_target_attribute
, false },
731 { "optimize", 1, -1, true, false, false,
732 handle_optimize_attribute
, false },
733 /* For internal use only. The leading '*' both prevents its usage in
734 source code and signals that it may be overridden by machine tables. */
735 { "*tm regparm", 0, 0, false, true, true,
736 ignore_attribute
, false },
737 { "no_split_stack", 0, 0, true, false, false,
738 handle_no_split_stack_attribute
, false },
739 /* For internal use (marking of builtins and runtime functions) only.
740 The name contains space to prevent its usage in source code. */
741 { "fn spec", 1, 1, false, true, true,
742 handle_fnspec_attribute
, false },
743 { "warn_unused", 0, 0, false, false, false,
744 handle_warn_unused_attribute
, false },
745 { NULL
, 0, 0, false, false, false, NULL
, false }
748 /* Give the specifications for the format attributes, used by C and all
751 const struct attribute_spec c_common_format_attribute_table
[] =
753 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
754 affects_type_identity } */
755 { "format", 3, 3, false, true, true,
756 handle_format_attribute
, false },
757 { "format_arg", 1, 1, false, true, true,
758 handle_format_arg_attribute
, false },
759 { NULL
, 0, 0, false, false, false, NULL
, false }
762 /* Return identifier for address space AS. */
765 c_addr_space_name (addr_space_t as
)
767 int rid
= RID_FIRST_ADDR_SPACE
+ as
;
768 gcc_assert (ridpointers
[rid
]);
769 return IDENTIFIER_POINTER (ridpointers
[rid
]);
772 /* Push current bindings for the function name VAR_DECLS. */
775 start_fname_decls (void)
778 tree saved
= NULL_TREE
;
780 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
782 tree decl
= *fname_vars
[ix
].decl
;
786 saved
= tree_cons (decl
, build_int_cst (integer_type_node
, ix
),
788 *fname_vars
[ix
].decl
= NULL_TREE
;
791 if (saved
|| saved_function_name_decls
)
792 /* Normally they'll have been NULL, so only push if we've got a
793 stack, or they are non-NULL. */
794 saved_function_name_decls
= tree_cons (saved
, NULL_TREE
,
795 saved_function_name_decls
);
798 /* Finish up the current bindings, adding them into the current function's
799 statement tree. This must be done _before_ finish_stmt_tree is called.
800 If there is no current function, we must be at file scope and no statements
801 are involved. Pop the previous bindings. */
804 finish_fname_decls (void)
807 tree stmts
= NULL_TREE
;
808 tree stack
= saved_function_name_decls
;
810 for (; stack
&& TREE_VALUE (stack
); stack
= TREE_CHAIN (stack
))
811 append_to_statement_list (TREE_VALUE (stack
), &stmts
);
815 tree
*bodyp
= &DECL_SAVED_TREE (current_function_decl
);
817 if (TREE_CODE (*bodyp
) == BIND_EXPR
)
818 bodyp
= &BIND_EXPR_BODY (*bodyp
);
820 append_to_statement_list_force (*bodyp
, &stmts
);
824 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
825 *fname_vars
[ix
].decl
= NULL_TREE
;
829 /* We had saved values, restore them. */
832 for (saved
= TREE_PURPOSE (stack
); saved
; saved
= TREE_CHAIN (saved
))
834 tree decl
= TREE_PURPOSE (saved
);
835 unsigned ix
= TREE_INT_CST_LOW (TREE_VALUE (saved
));
837 *fname_vars
[ix
].decl
= decl
;
839 stack
= TREE_CHAIN (stack
);
841 saved_function_name_decls
= stack
;
844 /* Return the text name of the current function, suitably prettified
845 by PRETTY_P. Return string must be freed by caller. */
848 fname_as_string (int pretty_p
)
850 const char *name
= "top level";
853 cpp_string cstr
= { 0, 0 }, strname
;
861 if (current_function_decl
)
862 name
= lang_hooks
.decl_printable_name (current_function_decl
, vrb
);
864 len
= strlen (name
) + 3; /* Two for '"'s. One for NULL. */
866 namep
= XNEWVEC (char, len
);
867 snprintf (namep
, len
, "\"%s\"", name
);
868 strname
.text
= (unsigned char *) namep
;
869 strname
.len
= len
- 1;
871 if (cpp_interpret_string (parse_in
, &strname
, 1, &cstr
, CPP_STRING
))
874 return (const char *) cstr
.text
;
880 /* Return the VAR_DECL for a const char array naming the current
881 function. If the VAR_DECL has not yet been created, create it
882 now. RID indicates how it should be formatted and IDENTIFIER_NODE
883 ID is its name (unfortunately C and C++ hold the RID values of
884 keywords in different places, so we can't derive RID from ID in
885 this language independent code. LOC is the location of the
889 fname_decl (location_t loc
, unsigned int rid
, tree id
)
892 tree decl
= NULL_TREE
;
894 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
895 if (fname_vars
[ix
].rid
== rid
)
898 decl
= *fname_vars
[ix
].decl
;
901 /* If a tree is built here, it would normally have the lineno of
902 the current statement. Later this tree will be moved to the
903 beginning of the function and this line number will be wrong.
904 To avoid this problem set the lineno to 0 here; that prevents
905 it from appearing in the RTL. */
907 location_t saved_location
= input_location
;
908 input_location
= UNKNOWN_LOCATION
;
910 stmts
= push_stmt_list ();
911 decl
= (*make_fname_decl
) (loc
, id
, fname_vars
[ix
].pretty
);
912 stmts
= pop_stmt_list (stmts
);
913 if (!IS_EMPTY_STMT (stmts
))
914 saved_function_name_decls
915 = tree_cons (decl
, stmts
, saved_function_name_decls
);
916 *fname_vars
[ix
].decl
= decl
;
917 input_location
= saved_location
;
919 if (!ix
&& !current_function_decl
)
920 pedwarn (loc
, 0, "%qD is not defined outside of function scope", decl
);
925 /* Given a STRING_CST, give it a suitable array-of-chars data type. */
928 fix_string_type (tree value
)
930 int length
= TREE_STRING_LENGTH (value
);
932 tree e_type
, i_type
, a_type
;
934 /* Compute the number of elements, for the array type. */
935 if (TREE_TYPE (value
) == char_array_type_node
|| !TREE_TYPE (value
))
938 e_type
= char_type_node
;
940 else if (TREE_TYPE (value
) == char16_array_type_node
)
942 nchars
= length
/ (TYPE_PRECISION (char16_type_node
) / BITS_PER_UNIT
);
943 e_type
= char16_type_node
;
945 else if (TREE_TYPE (value
) == char32_array_type_node
)
947 nchars
= length
/ (TYPE_PRECISION (char32_type_node
) / BITS_PER_UNIT
);
948 e_type
= char32_type_node
;
952 nchars
= length
/ (TYPE_PRECISION (wchar_type_node
) / BITS_PER_UNIT
);
953 e_type
= wchar_type_node
;
956 /* C89 2.2.4.1, C99 5.2.4.1 (Translation limits). The analogous
957 limit in C++98 Annex B is very large (65536) and is not normative,
958 so we do not diagnose it (warn_overlength_strings is forced off
959 in c_common_post_options). */
960 if (warn_overlength_strings
)
962 const int nchars_max
= flag_isoc99
? 4095 : 509;
963 const int relevant_std
= flag_isoc99
? 99 : 90;
964 if (nchars
- 1 > nchars_max
)
965 /* Translators: The %d after 'ISO C' will be 90 or 99. Do not
966 separate the %d from the 'C'. 'ISO' should not be
967 translated, but it may be moved after 'C%d' in languages
968 where modifiers follow nouns. */
969 pedwarn (input_location
, OPT_Woverlength_strings
,
970 "string length %qd is greater than the length %qd "
971 "ISO C%d compilers are required to support",
972 nchars
- 1, nchars_max
, relevant_std
);
975 /* Create the array type for the string constant. The ISO C++
976 standard says that a string literal has type `const char[N]' or
977 `const wchar_t[N]'. We use the same logic when invoked as a C
978 front-end with -Wwrite-strings.
979 ??? We should change the type of an expression depending on the
980 state of a warning flag. We should just be warning -- see how
981 this is handled in the C++ front-end for the deprecated implicit
982 conversion from string literals to `char*' or `wchar_t*'.
984 The C++ front end relies on TYPE_MAIN_VARIANT of a cv-qualified
985 array type being the unqualified version of that type.
986 Therefore, if we are constructing an array of const char, we must
987 construct the matching unqualified array type first. The C front
988 end does not require this, but it does no harm, so we do it
990 i_type
= build_index_type (size_int (nchars
- 1));
991 a_type
= build_array_type (e_type
, i_type
);
992 if (c_dialect_cxx() || warn_write_strings
)
993 a_type
= c_build_qualified_type (a_type
, TYPE_QUAL_CONST
);
995 TREE_TYPE (value
) = a_type
;
996 TREE_CONSTANT (value
) = 1;
997 TREE_READONLY (value
) = 1;
998 TREE_STATIC (value
) = 1;
1002 /* If DISABLE is true, stop issuing warnings. This is used when
1003 parsing code that we know will not be executed. This function may
1004 be called multiple times, and works as a stack. */
1007 c_disable_warnings (bool disable
)
1011 ++c_inhibit_evaluation_warnings
;
1012 fold_defer_overflow_warnings ();
1016 /* If ENABLE is true, reenable issuing warnings. */
1019 c_enable_warnings (bool enable
)
1023 --c_inhibit_evaluation_warnings
;
1024 fold_undefer_and_ignore_overflow_warnings ();
1028 /* Fully fold EXPR, an expression that was not folded (beyond integer
1029 constant expressions and null pointer constants) when being built
1030 up. If IN_INIT, this is in a static initializer and certain
1031 changes are made to the folding done. Clear *MAYBE_CONST if
1032 MAYBE_CONST is not NULL and EXPR is definitely not a constant
1033 expression because it contains an evaluated operator (in C99) or an
1034 operator outside of sizeof returning an integer constant (in C90)
1035 not permitted in constant expressions, or because it contains an
1036 evaluated arithmetic overflow. (*MAYBE_CONST should typically be
1037 set to true by callers before calling this function.) Return the
1038 folded expression. Function arguments have already been folded
1039 before calling this function, as have the contents of SAVE_EXPR,
1040 TARGET_EXPR, BIND_EXPR, VA_ARG_EXPR, OBJ_TYPE_REF and
1041 C_MAYBE_CONST_EXPR. */
1044 c_fully_fold (tree expr
, bool in_init
, bool *maybe_const
)
1047 tree eptype
= NULL_TREE
;
1049 bool maybe_const_itself
= true;
1050 location_t loc
= EXPR_LOCATION (expr
);
1052 /* This function is not relevant to C++ because C++ folds while
1053 parsing, and may need changes to be correct for C++ when C++
1054 stops folding while parsing. */
1055 if (c_dialect_cxx ())
1059 maybe_const
= &dummy
;
1060 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
1062 eptype
= TREE_TYPE (expr
);
1063 expr
= TREE_OPERAND (expr
, 0);
1065 ret
= c_fully_fold_internal (expr
, in_init
, maybe_const
,
1066 &maybe_const_itself
);
1068 ret
= fold_convert_loc (loc
, eptype
, ret
);
1069 *maybe_const
&= maybe_const_itself
;
1073 /* Internal helper for c_fully_fold. EXPR and IN_INIT are as for
1074 c_fully_fold. *MAYBE_CONST_OPERANDS is cleared because of operands
1075 not permitted, while *MAYBE_CONST_ITSELF is cleared because of
1076 arithmetic overflow (for C90, *MAYBE_CONST_OPERANDS is carried from
1077 both evaluated and unevaluated subexpressions while
1078 *MAYBE_CONST_ITSELF is carried from only evaluated
1082 c_fully_fold_internal (tree expr
, bool in_init
, bool *maybe_const_operands
,
1083 bool *maybe_const_itself
)
1086 enum tree_code code
= TREE_CODE (expr
);
1087 enum tree_code_class kind
= TREE_CODE_CLASS (code
);
1088 location_t loc
= EXPR_LOCATION (expr
);
1089 tree op0
, op1
, op2
, op3
;
1090 tree orig_op0
, orig_op1
, orig_op2
;
1091 bool op0_const
= true, op1_const
= true, op2_const
= true;
1092 bool op0_const_self
= true, op1_const_self
= true, op2_const_self
= true;
1093 bool nowarning
= TREE_NO_WARNING (expr
);
1096 /* This function is not relevant to C++ because C++ folds while
1097 parsing, and may need changes to be correct for C++ when C++
1098 stops folding while parsing. */
1099 if (c_dialect_cxx ())
1102 /* Constants, declarations, statements, errors, SAVE_EXPRs and
1103 anything else not counted as an expression cannot usefully be
1104 folded further at this point. */
1105 if (!IS_EXPR_CODE_CLASS (kind
)
1106 || kind
== tcc_statement
1107 || code
== SAVE_EXPR
)
1110 /* Operands of variable-length expressions (function calls) have
1111 already been folded, as have __builtin_* function calls, and such
1112 expressions cannot occur in constant expressions. */
1113 if (kind
== tcc_vl_exp
)
1115 *maybe_const_operands
= false;
1120 if (code
== C_MAYBE_CONST_EXPR
)
1122 tree pre
= C_MAYBE_CONST_EXPR_PRE (expr
);
1123 tree inner
= C_MAYBE_CONST_EXPR_EXPR (expr
);
1124 if (C_MAYBE_CONST_EXPR_NON_CONST (expr
))
1125 *maybe_const_operands
= false;
1126 if (C_MAYBE_CONST_EXPR_INT_OPERANDS (expr
))
1127 *maybe_const_itself
= false;
1128 if (pre
&& !in_init
)
1129 ret
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr
), pre
, inner
);
1135 /* Assignment, increment, decrement, function call and comma
1136 operators, and statement expressions, cannot occur in constant
1137 expressions if evaluated / outside of sizeof. (Function calls
1138 were handled above, though VA_ARG_EXPR is treated like a function
1139 call here, and statement expressions are handled through
1140 C_MAYBE_CONST_EXPR to avoid folding inside them.) */
1144 case PREDECREMENT_EXPR
:
1145 case PREINCREMENT_EXPR
:
1146 case POSTDECREMENT_EXPR
:
1147 case POSTINCREMENT_EXPR
:
1149 *maybe_const_operands
= false;
1156 *maybe_const_operands
= false;
1164 /* Fold individual tree codes as appropriate. */
1167 case COMPOUND_LITERAL_EXPR
:
1168 /* Any non-constancy will have been marked in a containing
1169 C_MAYBE_CONST_EXPR; there is no more folding to do here. */
1173 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1174 op1
= TREE_OPERAND (expr
, 1);
1175 op2
= TREE_OPERAND (expr
, 2);
1176 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1177 maybe_const_itself
);
1178 STRIP_TYPE_NOPS (op0
);
1179 if (op0
!= orig_op0
)
1180 ret
= build3 (COMPONENT_REF
, TREE_TYPE (expr
), op0
, op1
, op2
);
1183 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1184 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1189 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1190 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1191 op2
= TREE_OPERAND (expr
, 2);
1192 op3
= TREE_OPERAND (expr
, 3);
1193 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1194 maybe_const_itself
);
1195 STRIP_TYPE_NOPS (op0
);
1196 op1
= c_fully_fold_internal (op1
, in_init
, maybe_const_operands
,
1197 maybe_const_itself
);
1198 STRIP_TYPE_NOPS (op1
);
1199 op1
= decl_constant_value_for_optimization (op1
);
1200 if (op0
!= orig_op0
|| op1
!= orig_op1
)
1201 ret
= build4 (ARRAY_REF
, TREE_TYPE (expr
), op0
, op1
, op2
, op3
);
1204 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1205 TREE_SIDE_EFFECTS (ret
) = TREE_SIDE_EFFECTS (expr
);
1206 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1213 case PREDECREMENT_EXPR
:
1214 case PREINCREMENT_EXPR
:
1215 case POSTDECREMENT_EXPR
:
1216 case POSTINCREMENT_EXPR
:
1220 case POINTER_PLUS_EXPR
:
1221 case TRUNC_DIV_EXPR
:
1223 case FLOOR_DIV_EXPR
:
1224 case TRUNC_MOD_EXPR
:
1226 case EXACT_DIV_EXPR
:
1239 case TRUTH_AND_EXPR
:
1241 case TRUTH_XOR_EXPR
:
1242 case UNORDERED_EXPR
:
1249 /* Binary operations evaluating both arguments (increment and
1250 decrement are binary internally in GCC). */
1251 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1252 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1253 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1254 maybe_const_itself
);
1255 STRIP_TYPE_NOPS (op0
);
1256 if (code
!= MODIFY_EXPR
1257 && code
!= PREDECREMENT_EXPR
1258 && code
!= PREINCREMENT_EXPR
1259 && code
!= POSTDECREMENT_EXPR
1260 && code
!= POSTINCREMENT_EXPR
)
1261 op0
= decl_constant_value_for_optimization (op0
);
1262 /* The RHS of a MODIFY_EXPR was fully folded when building that
1263 expression for the sake of conversion warnings. */
1264 if (code
!= MODIFY_EXPR
)
1265 op1
= c_fully_fold_internal (op1
, in_init
, maybe_const_operands
,
1266 maybe_const_itself
);
1267 STRIP_TYPE_NOPS (op1
);
1268 op1
= decl_constant_value_for_optimization (op1
);
1269 if (op0
!= orig_op0
|| op1
!= orig_op1
|| in_init
)
1271 ? fold_build2_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
)
1272 : fold_build2_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
);
1275 if (TREE_OVERFLOW_P (ret
)
1276 && !TREE_OVERFLOW_P (op0
)
1277 && !TREE_OVERFLOW_P (op1
))
1278 overflow_warning (EXPR_LOCATION (expr
), ret
);
1279 if ((code
== LSHIFT_EXPR
|| code
== RSHIFT_EXPR
)
1280 && TREE_CODE (orig_op1
) != INTEGER_CST
1281 && TREE_CODE (op1
) == INTEGER_CST
1282 && (TREE_CODE (TREE_TYPE (orig_op0
)) == INTEGER_TYPE
1283 || TREE_CODE (TREE_TYPE (orig_op0
)) == FIXED_POINT_TYPE
)
1284 && TREE_CODE (TREE_TYPE (orig_op1
)) == INTEGER_TYPE
1285 && c_inhibit_evaluation_warnings
== 0)
1287 if (tree_int_cst_sgn (op1
) < 0)
1288 warning_at (loc
, 0, (code
== LSHIFT_EXPR
1289 ? G_("left shift count is negative")
1290 : G_("right shift count is negative")));
1291 else if (compare_tree_int (op1
,
1292 TYPE_PRECISION (TREE_TYPE (orig_op0
)))
1294 warning_at (loc
, 0, (code
== LSHIFT_EXPR
1295 ? G_("left shift count >= width of type")
1296 : G_("right shift count >= width of type")));
1301 case FIX_TRUNC_EXPR
:
1304 case VIEW_CONVERT_EXPR
:
1305 case NON_LVALUE_EXPR
:
1308 case TRUTH_NOT_EXPR
:
1313 /* Unary operations. */
1314 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1315 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1316 maybe_const_itself
);
1317 STRIP_TYPE_NOPS (op0
);
1318 if (code
!= ADDR_EXPR
&& code
!= REALPART_EXPR
&& code
!= IMAGPART_EXPR
)
1319 op0
= decl_constant_value_for_optimization (op0
);
1320 /* ??? Cope with user tricks that amount to offsetof. The middle-end is
1321 not prepared to deal with them if they occur in initializers. */
1323 && code
== ADDR_EXPR
1324 && (op1
= get_base_address (op0
)) != NULL_TREE
1325 && TREE_CODE (op1
) == INDIRECT_REF
1326 && TREE_CONSTANT (TREE_OPERAND (op1
, 0)))
1327 ret
= fold_convert_loc (loc
, TREE_TYPE (expr
), fold_offsetof_1 (op0
));
1328 else if (op0
!= orig_op0
|| in_init
)
1330 ? fold_build1_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
)
1331 : fold_build1_loc (loc
, code
, TREE_TYPE (expr
), op0
);
1334 if (code
== INDIRECT_REF
1336 && TREE_CODE (ret
) == INDIRECT_REF
)
1338 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1339 TREE_SIDE_EFFECTS (ret
) = TREE_SIDE_EFFECTS (expr
);
1340 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1344 case FIX_TRUNC_EXPR
:
1347 /* Don't warn about explicit conversions. We will already
1348 have warned about suspect implicit conversions. */
1352 if (TREE_OVERFLOW_P (ret
) && !TREE_OVERFLOW_P (op0
))
1353 overflow_warning (EXPR_LOCATION (expr
), ret
);
1358 case TRUTH_ANDIF_EXPR
:
1359 case TRUTH_ORIF_EXPR
:
1360 /* Binary operations not necessarily evaluating both
1362 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1363 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1364 op0
= c_fully_fold_internal (op0
, in_init
, &op0_const
, &op0_const_self
);
1365 STRIP_TYPE_NOPS (op0
);
1367 unused_p
= (op0
== (code
== TRUTH_ANDIF_EXPR
1368 ? truthvalue_false_node
1369 : truthvalue_true_node
));
1370 c_disable_warnings (unused_p
);
1371 op1
= c_fully_fold_internal (op1
, in_init
, &op1_const
, &op1_const_self
);
1372 STRIP_TYPE_NOPS (op1
);
1373 c_enable_warnings (unused_p
);
1375 if (op0
!= orig_op0
|| op1
!= orig_op1
|| in_init
)
1377 ? fold_build2_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
)
1378 : fold_build2_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
);
1381 *maybe_const_operands
&= op0_const
;
1382 *maybe_const_itself
&= op0_const_self
;
1386 && (code
== TRUTH_ANDIF_EXPR
1387 ? op0
== truthvalue_false_node
1388 : op0
== truthvalue_true_node
)))
1389 *maybe_const_operands
&= op1_const
;
1392 && (code
== TRUTH_ANDIF_EXPR
1393 ? op0
== truthvalue_false_node
1394 : op0
== truthvalue_true_node
)))
1395 *maybe_const_itself
&= op1_const_self
;
1399 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1400 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1401 orig_op2
= op2
= TREE_OPERAND (expr
, 2);
1402 op0
= c_fully_fold_internal (op0
, in_init
, &op0_const
, &op0_const_self
);
1404 STRIP_TYPE_NOPS (op0
);
1405 c_disable_warnings (op0
== truthvalue_false_node
);
1406 op1
= c_fully_fold_internal (op1
, in_init
, &op1_const
, &op1_const_self
);
1407 STRIP_TYPE_NOPS (op1
);
1408 c_enable_warnings (op0
== truthvalue_false_node
);
1410 c_disable_warnings (op0
== truthvalue_true_node
);
1411 op2
= c_fully_fold_internal (op2
, in_init
, &op2_const
, &op2_const_self
);
1412 STRIP_TYPE_NOPS (op2
);
1413 c_enable_warnings (op0
== truthvalue_true_node
);
1415 if (op0
!= orig_op0
|| op1
!= orig_op1
|| op2
!= orig_op2
)
1416 ret
= fold_build3_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
, op2
);
1419 *maybe_const_operands
&= op0_const
;
1420 *maybe_const_itself
&= op0_const_self
;
1424 && op0
== truthvalue_false_node
))
1425 *maybe_const_operands
&= op1_const
;
1428 && op0
== truthvalue_false_node
))
1429 *maybe_const_itself
&= op1_const_self
;
1433 && op0
== truthvalue_true_node
))
1434 *maybe_const_operands
&= op2_const
;
1437 && op0
== truthvalue_true_node
))
1438 *maybe_const_itself
&= op2_const_self
;
1441 case EXCESS_PRECISION_EXPR
:
1442 /* Each case where an operand with excess precision may be
1443 encountered must remove the EXCESS_PRECISION_EXPR around
1444 inner operands and possibly put one around the whole
1445 expression or possibly convert to the semantic type (which
1446 c_fully_fold does); we cannot tell at this stage which is
1447 appropriate in any particular case. */
1451 /* Various codes may appear through folding built-in functions
1452 and their arguments. */
1457 /* Some folding may introduce NON_LVALUE_EXPRs; all lvalue checks
1458 have been done by this point, so remove them again. */
1459 nowarning
|= TREE_NO_WARNING (ret
);
1460 STRIP_TYPE_NOPS (ret
);
1461 if (nowarning
&& !TREE_NO_WARNING (ret
))
1463 if (!CAN_HAVE_LOCATION_P (ret
))
1464 ret
= build1 (NOP_EXPR
, TREE_TYPE (ret
), ret
);
1465 TREE_NO_WARNING (ret
) = 1;
1468 protected_set_expr_location (ret
, loc
);
1472 /* If not optimizing, EXP is not a VAR_DECL, or EXP has array type,
1473 return EXP. Otherwise, return either EXP or its known constant
1474 value (if it has one), but return EXP if EXP has mode BLKmode. ???
1475 Is the BLKmode test appropriate? */
1478 decl_constant_value_for_optimization (tree exp
)
1482 /* This function is only used by C, for c_fully_fold and other
1483 optimization, and may not be correct for C++. */
1484 if (c_dialect_cxx ())
1488 || TREE_CODE (exp
) != VAR_DECL
1489 || TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
1490 || DECL_MODE (exp
) == BLKmode
)
1493 ret
= decl_constant_value (exp
);
1494 /* Avoid unwanted tree sharing between the initializer and current
1495 function's body where the tree can be modified e.g. by the
1497 if (ret
!= exp
&& TREE_STATIC (exp
))
1498 ret
= unshare_expr (ret
);
1502 /* Print a warning if a constant expression had overflow in folding.
1503 Invoke this function on every expression that the language
1504 requires to be a constant expression.
1505 Note the ANSI C standard says it is erroneous for a
1506 constant expression to overflow. */
1509 constant_expression_warning (tree value
)
1511 if (warn_overflow
&& pedantic
1512 && (TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1513 || TREE_CODE (value
) == FIXED_CST
1514 || TREE_CODE (value
) == VECTOR_CST
1515 || TREE_CODE (value
) == COMPLEX_CST
)
1516 && TREE_OVERFLOW (value
))
1517 pedwarn (input_location
, OPT_Woverflow
, "overflow in constant expression");
1520 /* The same as above but print an unconditional error. */
1522 constant_expression_error (tree value
)
1524 if ((TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1525 || TREE_CODE (value
) == FIXED_CST
1526 || TREE_CODE (value
) == VECTOR_CST
1527 || TREE_CODE (value
) == COMPLEX_CST
)
1528 && TREE_OVERFLOW (value
))
1529 error ("overflow in constant expression");
1532 /* Print a warning if an expression had overflow in folding and its
1535 Invoke this function on every expression that
1536 (1) appears in the source code, and
1537 (2) is a constant expression that overflowed, and
1538 (3) is not already checked by convert_and_check;
1539 however, do not invoke this function on operands of explicit casts
1540 or when the expression is the result of an operator and any operand
1541 already overflowed. */
1544 overflow_warning (location_t loc
, tree value
)
1546 if (c_inhibit_evaluation_warnings
!= 0)
1549 switch (TREE_CODE (value
))
1552 warning_at (loc
, OPT_Woverflow
, "integer overflow in expression");
1556 warning_at (loc
, OPT_Woverflow
,
1557 "floating point overflow in expression");
1561 warning_at (loc
, OPT_Woverflow
, "fixed-point overflow in expression");
1565 warning_at (loc
, OPT_Woverflow
, "vector overflow in expression");
1569 if (TREE_CODE (TREE_REALPART (value
)) == INTEGER_CST
)
1570 warning_at (loc
, OPT_Woverflow
,
1571 "complex integer overflow in expression");
1572 else if (TREE_CODE (TREE_REALPART (value
)) == REAL_CST
)
1573 warning_at (loc
, OPT_Woverflow
,
1574 "complex floating point overflow in expression");
1582 /* Warn about uses of logical || / && operator in a context where it
1583 is likely that the bitwise equivalent was intended by the
1584 programmer. We have seen an expression in which CODE is a binary
1585 operator used to combine expressions OP_LEFT and OP_RIGHT, which before folding
1586 had CODE_LEFT and CODE_RIGHT, into an expression of type TYPE. */
1588 warn_logical_operator (location_t location
, enum tree_code code
, tree type
,
1589 enum tree_code code_left
, tree op_left
,
1590 enum tree_code
ARG_UNUSED (code_right
), tree op_right
)
1592 int or_op
= (code
== TRUTH_ORIF_EXPR
|| code
== TRUTH_OR_EXPR
);
1593 int in0_p
, in1_p
, in_p
;
1594 tree low0
, low1
, low
, high0
, high1
, high
, lhs
, rhs
, tem
;
1595 bool strict_overflow_p
= false;
1597 if (code
!= TRUTH_ANDIF_EXPR
1598 && code
!= TRUTH_AND_EXPR
1599 && code
!= TRUTH_ORIF_EXPR
1600 && code
!= TRUTH_OR_EXPR
)
1603 /* Warn if &&/|| are being used in a context where it is
1604 likely that the bitwise equivalent was intended by the
1605 programmer. That is, an expression such as op && MASK
1606 where op should not be any boolean expression, nor a
1607 constant, and mask seems to be a non-boolean integer constant. */
1608 if (!truth_value_p (code_left
)
1609 && INTEGRAL_TYPE_P (TREE_TYPE (op_left
))
1610 && !CONSTANT_CLASS_P (op_left
)
1611 && !TREE_NO_WARNING (op_left
)
1612 && TREE_CODE (op_right
) == INTEGER_CST
1613 && !integer_zerop (op_right
)
1614 && !integer_onep (op_right
))
1617 warning_at (location
, OPT_Wlogical_op
, "logical %<or%>"
1618 " applied to non-boolean constant");
1620 warning_at (location
, OPT_Wlogical_op
, "logical %<and%>"
1621 " applied to non-boolean constant");
1622 TREE_NO_WARNING (op_left
) = true;
1626 /* We do not warn for constants because they are typical of macro
1627 expansions that test for features. */
1628 if (CONSTANT_CLASS_P (op_left
) || CONSTANT_CLASS_P (op_right
))
1631 /* This warning only makes sense with logical operands. */
1632 if (!(truth_value_p (TREE_CODE (op_left
))
1633 || INTEGRAL_TYPE_P (TREE_TYPE (op_left
)))
1634 || !(truth_value_p (TREE_CODE (op_right
))
1635 || INTEGRAL_TYPE_P (TREE_TYPE (op_right
))))
1639 /* We first test whether either side separately is trivially true
1640 (with OR) or trivially false (with AND). If so, do not warn.
1641 This is a common idiom for testing ranges of data types in
1643 lhs
= make_range (op_left
, &in0_p
, &low0
, &high0
, &strict_overflow_p
);
1646 if (TREE_CODE (lhs
) == C_MAYBE_CONST_EXPR
)
1647 lhs
= C_MAYBE_CONST_EXPR_EXPR (lhs
);
1649 /* If this is an OR operation, invert both sides; now, the result
1650 should be always false to get a warning. */
1654 tem
= build_range_check (UNKNOWN_LOCATION
, type
, lhs
, in0_p
, low0
, high0
);
1655 if (tem
&& integer_zerop (tem
))
1658 rhs
= make_range (op_right
, &in1_p
, &low1
, &high1
, &strict_overflow_p
);
1661 if (TREE_CODE (rhs
) == C_MAYBE_CONST_EXPR
)
1662 rhs
= C_MAYBE_CONST_EXPR_EXPR (rhs
);
1664 /* If this is an OR operation, invert both sides; now, the result
1665 should be always false to get a warning. */
1669 tem
= build_range_check (UNKNOWN_LOCATION
, type
, rhs
, in1_p
, low1
, high1
);
1670 if (tem
&& integer_zerop (tem
))
1673 /* If both expressions have the same operand, if we can merge the
1674 ranges, and if the range test is always false, then warn. */
1675 if (operand_equal_p (lhs
, rhs
, 0)
1676 && merge_ranges (&in_p
, &low
, &high
, in0_p
, low0
, high0
,
1678 && 0 != (tem
= build_range_check (UNKNOWN_LOCATION
,
1679 type
, lhs
, in_p
, low
, high
))
1680 && integer_zerop (tem
))
1683 warning_at (location
, OPT_Wlogical_op
,
1685 "of collectively exhaustive tests is always true");
1687 warning_at (location
, OPT_Wlogical_op
,
1689 "of mutually exclusive tests is always false");
1694 /* Warn if EXP contains any computations whose results are not used.
1695 Return true if a warning is printed; false otherwise. LOCUS is the
1696 (potential) location of the expression. */
1699 warn_if_unused_value (const_tree exp
, location_t locus
)
1702 if (TREE_USED (exp
) || TREE_NO_WARNING (exp
))
1705 /* Don't warn about void constructs. This includes casting to void,
1706 void function calls, and statement expressions with a final cast
1708 if (VOID_TYPE_P (TREE_TYPE (exp
)))
1711 if (EXPR_HAS_LOCATION (exp
))
1712 locus
= EXPR_LOCATION (exp
);
1714 switch (TREE_CODE (exp
))
1716 case PREINCREMENT_EXPR
:
1717 case POSTINCREMENT_EXPR
:
1718 case PREDECREMENT_EXPR
:
1719 case POSTDECREMENT_EXPR
:
1724 case TRY_CATCH_EXPR
:
1725 case WITH_CLEANUP_EXPR
:
1731 /* For a binding, warn if no side effect within it. */
1732 exp
= BIND_EXPR_BODY (exp
);
1736 case NON_LVALUE_EXPR
:
1738 exp
= TREE_OPERAND (exp
, 0);
1741 case TRUTH_ORIF_EXPR
:
1742 case TRUTH_ANDIF_EXPR
:
1743 /* In && or ||, warn if 2nd operand has no side effect. */
1744 exp
= TREE_OPERAND (exp
, 1);
1748 if (warn_if_unused_value (TREE_OPERAND (exp
, 0), locus
))
1750 /* Let people do `(foo (), 0)' without a warning. */
1751 if (TREE_CONSTANT (TREE_OPERAND (exp
, 1)))
1753 exp
= TREE_OPERAND (exp
, 1);
1757 /* If this is an expression with side effects, don't warn; this
1758 case commonly appears in macro expansions. */
1759 if (TREE_SIDE_EFFECTS (exp
))
1764 /* Don't warn about automatic dereferencing of references, since
1765 the user cannot control it. */
1766 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == REFERENCE_TYPE
)
1768 exp
= TREE_OPERAND (exp
, 0);
1774 /* Referencing a volatile value is a side effect, so don't warn. */
1775 if ((DECL_P (exp
) || REFERENCE_CLASS_P (exp
))
1776 && TREE_THIS_VOLATILE (exp
))
1779 /* If this is an expression which has no operands, there is no value
1780 to be unused. There are no such language-independent codes,
1781 but front ends may define such. */
1782 if (EXPRESSION_CLASS_P (exp
) && TREE_OPERAND_LENGTH (exp
) == 0)
1786 return warning_at (locus
, OPT_Wunused_value
, "value computed is not used");
1791 /* Print a warning about casts that might indicate violation
1792 of strict aliasing rules if -Wstrict-aliasing is used and
1793 strict aliasing mode is in effect. OTYPE is the original
1794 TREE_TYPE of EXPR, and TYPE the type we're casting to. */
1797 strict_aliasing_warning (tree otype
, tree type
, tree expr
)
1799 /* Strip pointer conversion chains and get to the correct original type. */
1801 otype
= TREE_TYPE (expr
);
1803 if (!(flag_strict_aliasing
1804 && POINTER_TYPE_P (type
)
1805 && POINTER_TYPE_P (otype
)
1806 && !VOID_TYPE_P (TREE_TYPE (type
)))
1807 /* If the type we are casting to is a ref-all pointer
1808 dereferencing it is always valid. */
1809 || TYPE_REF_CAN_ALIAS_ALL (type
))
1812 if ((warn_strict_aliasing
> 1) && TREE_CODE (expr
) == ADDR_EXPR
1813 && (DECL_P (TREE_OPERAND (expr
, 0))
1814 || handled_component_p (TREE_OPERAND (expr
, 0))))
1816 /* Casting the address of an object to non void pointer. Warn
1817 if the cast breaks type based aliasing. */
1818 if (!COMPLETE_TYPE_P (TREE_TYPE (type
)) && warn_strict_aliasing
== 2)
1820 warning (OPT_Wstrict_aliasing
, "type-punning to incomplete type "
1821 "might break strict-aliasing rules");
1826 /* warn_strict_aliasing >= 3. This includes the default (3).
1827 Only warn if the cast is dereferenced immediately. */
1828 alias_set_type set1
=
1829 get_alias_set (TREE_TYPE (TREE_OPERAND (expr
, 0)));
1830 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
1832 if (set1
!= set2
&& set2
!= 0
1833 && (set1
== 0 || !alias_sets_conflict_p (set1
, set2
)))
1835 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1836 "pointer will break strict-aliasing rules");
1839 else if (warn_strict_aliasing
== 2
1840 && !alias_sets_must_conflict_p (set1
, set2
))
1842 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1843 "pointer might break strict-aliasing rules");
1849 if ((warn_strict_aliasing
== 1) && !VOID_TYPE_P (TREE_TYPE (otype
)))
1851 /* At this level, warn for any conversions, even if an address is
1852 not taken in the same statement. This will likely produce many
1853 false positives, but could be useful to pinpoint problems that
1854 are not revealed at higher levels. */
1855 alias_set_type set1
= get_alias_set (TREE_TYPE (otype
));
1856 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
1857 if (!COMPLETE_TYPE_P (type
)
1858 || !alias_sets_must_conflict_p (set1
, set2
))
1860 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1861 "pointer might break strict-aliasing rules");
1869 /* Warn about memset (&a, 0, sizeof (&a)); and similar mistakes with
1870 sizeof as last operand of certain builtins. */
1873 sizeof_pointer_memaccess_warning (location_t
*sizeof_arg_loc
, tree callee
,
1874 vec
<tree
, va_gc
> *params
, tree
*sizeof_arg
,
1875 bool (*comp_types
) (tree
, tree
))
1877 tree type
, dest
= NULL_TREE
, src
= NULL_TREE
, tem
;
1878 bool strop
= false, cmp
= false;
1879 unsigned int idx
= ~0;
1882 if (TREE_CODE (callee
) != FUNCTION_DECL
1883 || DECL_BUILT_IN_CLASS (callee
) != BUILT_IN_NORMAL
1884 || vec_safe_length (params
) <= 1)
1887 switch (DECL_FUNCTION_CODE (callee
))
1889 case BUILT_IN_STRNCMP
:
1890 case BUILT_IN_STRNCASECMP
:
1893 case BUILT_IN_STRNCPY
:
1894 case BUILT_IN_STRNCPY_CHK
:
1895 case BUILT_IN_STRNCAT
:
1896 case BUILT_IN_STRNCAT_CHK
:
1897 case BUILT_IN_STPNCPY
:
1898 case BUILT_IN_STPNCPY_CHK
:
1901 case BUILT_IN_MEMCPY
:
1902 case BUILT_IN_MEMCPY_CHK
:
1903 case BUILT_IN_MEMMOVE
:
1904 case BUILT_IN_MEMMOVE_CHK
:
1905 if (params
->length () < 3)
1908 dest
= (*params
)[0];
1911 case BUILT_IN_BCOPY
:
1912 if (params
->length () < 3)
1915 dest
= (*params
)[1];
1918 case BUILT_IN_MEMCMP
:
1920 if (params
->length () < 3)
1923 dest
= (*params
)[0];
1927 case BUILT_IN_MEMSET
:
1928 case BUILT_IN_MEMSET_CHK
:
1929 if (params
->length () < 3)
1931 dest
= (*params
)[0];
1934 case BUILT_IN_BZERO
:
1935 dest
= (*params
)[0];
1938 case BUILT_IN_STRNDUP
:
1943 case BUILT_IN_MEMCHR
:
1944 if (params
->length () < 3)
1949 case BUILT_IN_SNPRINTF
:
1950 case BUILT_IN_SNPRINTF_CHK
:
1951 case BUILT_IN_VSNPRINTF
:
1952 case BUILT_IN_VSNPRINTF_CHK
:
1953 dest
= (*params
)[0];
1964 if (sizeof_arg
[idx
] == NULL
|| sizeof_arg
[idx
] == error_mark_node
)
1967 type
= TYPE_P (sizeof_arg
[idx
])
1968 ? sizeof_arg
[idx
] : TREE_TYPE (sizeof_arg
[idx
]);
1969 if (!POINTER_TYPE_P (type
))
1973 && (tem
= tree_strip_nop_conversions (dest
))
1974 && POINTER_TYPE_P (TREE_TYPE (tem
))
1975 && comp_types (TREE_TYPE (TREE_TYPE (tem
)), type
))
1979 && (tem
= tree_strip_nop_conversions (src
))
1980 && POINTER_TYPE_P (TREE_TYPE (tem
))
1981 && comp_types (TREE_TYPE (TREE_TYPE (tem
)), type
))
1984 loc
= sizeof_arg_loc
[idx
];
1988 if (!TYPE_P (sizeof_arg
[idx
])
1989 && operand_equal_p (dest
, sizeof_arg
[idx
], 0)
1990 && comp_types (TREE_TYPE (dest
), type
))
1992 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
1993 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
1994 "argument to %<sizeof%> in %qD call is the same "
1995 "expression as the destination; did you mean to "
1996 "remove the addressof?", callee
);
1997 else if ((TYPE_PRECISION (TREE_TYPE (type
))
1998 == TYPE_PRECISION (char_type_node
))
2000 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2001 "argument to %<sizeof%> in %qD call is the same "
2002 "expression as the destination; did you mean to "
2003 "provide an explicit length?", callee
);
2005 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2006 "argument to %<sizeof%> in %qD call is the same "
2007 "expression as the destination; did you mean to "
2008 "dereference it?", callee
);
2012 if (POINTER_TYPE_P (TREE_TYPE (dest
))
2014 && comp_types (TREE_TYPE (dest
), type
)
2015 && !VOID_TYPE_P (TREE_TYPE (type
)))
2017 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2018 "argument to %<sizeof%> in %qD call is the same "
2019 "pointer type %qT as the destination; expected %qT "
2020 "or an explicit length", callee
, TREE_TYPE (dest
),
2021 TREE_TYPE (TREE_TYPE (dest
)));
2028 if (!TYPE_P (sizeof_arg
[idx
])
2029 && operand_equal_p (src
, sizeof_arg
[idx
], 0)
2030 && comp_types (TREE_TYPE (src
), type
))
2032 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2033 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2034 "argument to %<sizeof%> in %qD call is the same "
2035 "expression as the source; did you mean to "
2036 "remove the addressof?", callee
);
2037 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2038 == TYPE_PRECISION (char_type_node
))
2040 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2041 "argument to %<sizeof%> in %qD call is the same "
2042 "expression as the source; did you mean to "
2043 "provide an explicit length?", callee
);
2045 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2046 "argument to %<sizeof%> in %qD call is the same "
2047 "expression as the source; did you mean to "
2048 "dereference it?", callee
);
2052 if (POINTER_TYPE_P (TREE_TYPE (src
))
2054 && comp_types (TREE_TYPE (src
), type
)
2055 && !VOID_TYPE_P (TREE_TYPE (type
)))
2057 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2058 "argument to %<sizeof%> in %qD call is the same "
2059 "pointer type %qT as the source; expected %qT "
2060 "or an explicit length", callee
, TREE_TYPE (src
),
2061 TREE_TYPE (TREE_TYPE (src
)));
2068 if (!TYPE_P (sizeof_arg
[idx
])
2069 && operand_equal_p (dest
, sizeof_arg
[idx
], 0)
2070 && comp_types (TREE_TYPE (dest
), type
))
2072 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2073 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2074 "argument to %<sizeof%> in %qD call is the same "
2075 "expression as the first source; did you mean to "
2076 "remove the addressof?", callee
);
2077 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2078 == TYPE_PRECISION (char_type_node
))
2080 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2081 "argument to %<sizeof%> in %qD call is the same "
2082 "expression as the first source; did you mean to "
2083 "provide an explicit length?", callee
);
2085 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2086 "argument to %<sizeof%> in %qD call is the same "
2087 "expression as the first source; did you mean to "
2088 "dereference it?", callee
);
2092 if (POINTER_TYPE_P (TREE_TYPE (dest
))
2094 && comp_types (TREE_TYPE (dest
), type
)
2095 && !VOID_TYPE_P (TREE_TYPE (type
)))
2097 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2098 "argument to %<sizeof%> in %qD call is the same "
2099 "pointer type %qT as the first source; expected %qT "
2100 "or an explicit length", callee
, TREE_TYPE (dest
),
2101 TREE_TYPE (TREE_TYPE (dest
)));
2108 if (!TYPE_P (sizeof_arg
[idx
])
2109 && operand_equal_p (src
, sizeof_arg
[idx
], 0)
2110 && comp_types (TREE_TYPE (src
), type
))
2112 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2113 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2114 "argument to %<sizeof%> in %qD call is the same "
2115 "expression as the second source; did you mean to "
2116 "remove the addressof?", callee
);
2117 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2118 == TYPE_PRECISION (char_type_node
))
2120 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2121 "argument to %<sizeof%> in %qD call is the same "
2122 "expression as the second source; did you mean to "
2123 "provide an explicit length?", callee
);
2125 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2126 "argument to %<sizeof%> in %qD call is the same "
2127 "expression as the second source; did you mean to "
2128 "dereference it?", callee
);
2132 if (POINTER_TYPE_P (TREE_TYPE (src
))
2134 && comp_types (TREE_TYPE (src
), type
)
2135 && !VOID_TYPE_P (TREE_TYPE (type
)))
2137 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2138 "argument to %<sizeof%> in %qD call is the same "
2139 "pointer type %qT as the second source; expected %qT "
2140 "or an explicit length", callee
, TREE_TYPE (src
),
2141 TREE_TYPE (TREE_TYPE (src
)));
2148 /* Warn for unlikely, improbable, or stupid DECL declarations
2152 check_main_parameter_types (tree decl
)
2154 function_args_iterator iter
;
2158 FOREACH_FUNCTION_ARGS (TREE_TYPE (decl
), type
, iter
)
2160 /* XXX void_type_node belies the abstraction. */
2161 if (type
== void_type_node
|| type
== error_mark_node
)
2168 if (TYPE_MAIN_VARIANT (type
) != integer_type_node
)
2169 pedwarn (input_location
, OPT_Wmain
,
2170 "first argument of %q+D should be %<int%>", decl
);
2174 if (TREE_CODE (type
) != POINTER_TYPE
2175 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
2176 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
2178 pedwarn (input_location
, OPT_Wmain
,
2179 "second argument of %q+D should be %<char **%>", decl
);
2183 if (TREE_CODE (type
) != POINTER_TYPE
2184 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
2185 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
2187 pedwarn (input_location
, OPT_Wmain
,
2188 "third argument of %q+D should probably be "
2189 "%<char **%>", decl
);
2194 /* It is intentional that this message does not mention the third
2195 argument because it's only mentioned in an appendix of the
2197 if (argct
> 0 && (argct
< 2 || argct
> 3))
2198 pedwarn (input_location
, OPT_Wmain
,
2199 "%q+D takes only zero or two arguments", decl
);
2202 /* True if pointers to distinct types T1 and T2 can be converted to
2203 each other without an explicit cast. Only returns true for opaque
2206 vector_targets_convertible_p (const_tree t1
, const_tree t2
)
2208 if (TREE_CODE (t1
) == VECTOR_TYPE
&& TREE_CODE (t2
) == VECTOR_TYPE
2209 && (TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2210 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2216 /* True if vector types T1 and T2 can be converted to each other
2217 without an explicit cast. If EMIT_LAX_NOTE is true, and T1 and T2
2218 can only be converted with -flax-vector-conversions yet that is not
2219 in effect, emit a note telling the user about that option if such
2220 a note has not previously been emitted. */
2222 vector_types_convertible_p (const_tree t1
, const_tree t2
, bool emit_lax_note
)
2224 static bool emitted_lax_note
= false;
2225 bool convertible_lax
;
2227 if ((TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2228 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2232 (tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
))
2233 && (TREE_CODE (TREE_TYPE (t1
)) != REAL_TYPE
||
2234 TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
))
2235 && (INTEGRAL_TYPE_P (TREE_TYPE (t1
))
2236 == INTEGRAL_TYPE_P (TREE_TYPE (t2
))));
2238 if (!convertible_lax
|| flag_lax_vector_conversions
)
2239 return convertible_lax
;
2241 if (TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
)
2242 && lang_hooks
.types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
2245 if (emit_lax_note
&& !emitted_lax_note
)
2247 emitted_lax_note
= true;
2248 inform (input_location
, "use -flax-vector-conversions to permit "
2249 "conversions between vectors with differing "
2250 "element types or numbers of subparts");
2256 /* Build a VEC_PERM_EXPR if V0, V1 and MASK are not error_mark_nodes
2257 and have vector types, V0 has the same type as V1, and the number of
2258 elements of V0, V1, MASK is the same.
2260 In case V1 is a NULL_TREE it is assumed that __builtin_shuffle was
2261 called with two arguments. In this case implementation passes the
2262 first argument twice in order to share the same tree code. This fact
2263 could enable the mask-values being twice the vector length. This is
2264 an implementation accident and this semantics is not guaranteed to
2267 c_build_vec_perm_expr (location_t loc
, tree v0
, tree v1
, tree mask
,
2272 bool maybe_const
= false;
2273 bool two_arguments
= false;
2275 if (v1
== NULL_TREE
)
2277 two_arguments
= true;
2281 if (v0
== error_mark_node
|| v1
== error_mark_node
2282 || mask
== error_mark_node
)
2283 return error_mark_node
;
2285 if (TREE_CODE (TREE_TYPE (mask
)) != VECTOR_TYPE
2286 || TREE_CODE (TREE_TYPE (TREE_TYPE (mask
))) != INTEGER_TYPE
)
2289 error_at (loc
, "__builtin_shuffle last argument must "
2290 "be an integer vector");
2291 return error_mark_node
;
2294 if (TREE_CODE (TREE_TYPE (v0
)) != VECTOR_TYPE
2295 || TREE_CODE (TREE_TYPE (v1
)) != VECTOR_TYPE
)
2298 error_at (loc
, "__builtin_shuffle arguments must be vectors");
2299 return error_mark_node
;
2302 if (TYPE_MAIN_VARIANT (TREE_TYPE (v0
)) != TYPE_MAIN_VARIANT (TREE_TYPE (v1
)))
2305 error_at (loc
, "__builtin_shuffle argument vectors must be of "
2307 return error_mark_node
;
2310 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (v0
))
2311 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
))
2312 && TYPE_VECTOR_SUBPARTS (TREE_TYPE (v1
))
2313 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
)))
2316 error_at (loc
, "__builtin_shuffle number of elements of the "
2317 "argument vector(s) and the mask vector should "
2319 return error_mark_node
;
2322 if (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (v0
))))
2323 != GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (mask
)))))
2326 error_at (loc
, "__builtin_shuffle argument vector(s) inner type "
2327 "must have the same size as inner type of the mask");
2328 return error_mark_node
;
2331 if (!c_dialect_cxx ())
2333 /* Avoid C_MAYBE_CONST_EXPRs inside VEC_PERM_EXPR. */
2334 v0
= c_fully_fold (v0
, false, &maybe_const
);
2335 wrap
&= maybe_const
;
2338 v1
= v0
= save_expr (v0
);
2341 v1
= c_fully_fold (v1
, false, &maybe_const
);
2342 wrap
&= maybe_const
;
2345 mask
= c_fully_fold (mask
, false, &maybe_const
);
2346 wrap
&= maybe_const
;
2348 else if (two_arguments
)
2349 v1
= v0
= save_expr (v0
);
2351 ret
= build3_loc (loc
, VEC_PERM_EXPR
, TREE_TYPE (v0
), v0
, v1
, mask
);
2353 if (!c_dialect_cxx () && !wrap
)
2354 ret
= c_wrap_maybe_const (ret
, true);
2359 /* Like tree.c:get_narrower, but retain conversion from C++0x scoped enum
2360 to integral type. */
2363 c_common_get_narrower (tree op
, int *unsignedp_ptr
)
2365 op
= get_narrower (op
, unsignedp_ptr
);
2367 if (TREE_CODE (TREE_TYPE (op
)) == ENUMERAL_TYPE
2368 && ENUM_IS_SCOPED (TREE_TYPE (op
)))
2370 /* C++0x scoped enumerations don't implicitly convert to integral
2371 type; if we stripped an explicit conversion to a larger type we
2372 need to replace it so common_type will still work. */
2373 tree type
= c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op
)),
2374 TYPE_UNSIGNED (TREE_TYPE (op
)));
2375 op
= fold_convert (type
, op
);
2380 /* This is a helper function of build_binary_op.
2382 For certain operations if both args were extended from the same
2383 smaller type, do the arithmetic in that type and then extend.
2385 BITWISE indicates a bitwise operation.
2386 For them, this optimization is safe only if
2387 both args are zero-extended or both are sign-extended.
2388 Otherwise, we might change the result.
2389 Eg, (short)-1 | (unsigned short)-1 is (int)-1
2390 but calculated in (unsigned short) it would be (unsigned short)-1.
2393 shorten_binary_op (tree result_type
, tree op0
, tree op1
, bool bitwise
)
2395 int unsigned0
, unsigned1
;
2400 /* Cast OP0 and OP1 to RESULT_TYPE. Doing so prevents
2401 excessive narrowing when we call get_narrower below. For
2402 example, suppose that OP0 is of unsigned int extended
2403 from signed char and that RESULT_TYPE is long long int.
2404 If we explicitly cast OP0 to RESULT_TYPE, OP0 would look
2407 (long long int) (unsigned int) signed_char
2409 which get_narrower would narrow down to
2411 (unsigned int) signed char
2413 If we do not cast OP0 first, get_narrower would return
2414 signed_char, which is inconsistent with the case of the
2416 op0
= convert (result_type
, op0
);
2417 op1
= convert (result_type
, op1
);
2419 arg0
= c_common_get_narrower (op0
, &unsigned0
);
2420 arg1
= c_common_get_narrower (op1
, &unsigned1
);
2422 /* UNS is 1 if the operation to be done is an unsigned one. */
2423 uns
= TYPE_UNSIGNED (result_type
);
2425 /* Handle the case that OP0 (or OP1) does not *contain* a conversion
2426 but it *requires* conversion to FINAL_TYPE. */
2428 if ((TYPE_PRECISION (TREE_TYPE (op0
))
2429 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2430 && TREE_TYPE (op0
) != result_type
)
2431 unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2432 if ((TYPE_PRECISION (TREE_TYPE (op1
))
2433 == TYPE_PRECISION (TREE_TYPE (arg1
)))
2434 && TREE_TYPE (op1
) != result_type
)
2435 unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2437 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
2439 /* For bitwise operations, signedness of nominal type
2440 does not matter. Consider only how operands were extended. */
2444 /* Note that in all three cases below we refrain from optimizing
2445 an unsigned operation on sign-extended args.
2446 That would not be valid. */
2448 /* Both args variable: if both extended in same way
2449 from same width, do it in that width.
2450 Do it unsigned if args were zero-extended. */
2451 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
2452 < TYPE_PRECISION (result_type
))
2453 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2454 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2455 && unsigned0
== unsigned1
2456 && (unsigned0
|| !uns
))
2457 return c_common_signed_or_unsigned_type
2458 (unsigned0
, common_type (TREE_TYPE (arg0
), TREE_TYPE (arg1
)));
2460 else if (TREE_CODE (arg0
) == INTEGER_CST
2461 && (unsigned1
|| !uns
)
2462 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2463 < TYPE_PRECISION (result_type
))
2465 = c_common_signed_or_unsigned_type (unsigned1
,
2467 && !POINTER_TYPE_P (type
)
2468 && int_fits_type_p (arg0
, type
))
2471 else if (TREE_CODE (arg1
) == INTEGER_CST
2472 && (unsigned0
|| !uns
)
2473 && (TYPE_PRECISION (TREE_TYPE (arg0
))
2474 < TYPE_PRECISION (result_type
))
2476 = c_common_signed_or_unsigned_type (unsigned0
,
2478 && !POINTER_TYPE_P (type
)
2479 && int_fits_type_p (arg1
, type
))
2485 /* Checks if expression EXPR of real/integer type cannot be converted
2486 to the real/integer type TYPE. Function returns true when:
2487 * EXPR is a constant which cannot be exactly converted to TYPE
2488 * EXPR is not a constant and size of EXPR's type > than size of TYPE,
2489 for EXPR type and TYPE being both integers or both real.
2490 * EXPR is not a constant of real type and TYPE is an integer.
2491 * EXPR is not a constant of integer type which cannot be
2492 exactly converted to real type.
2493 Function allows conversions between types of different signedness and
2494 does not return true in that case. Function can produce signedness
2495 warnings if PRODUCE_WARNS is true. */
2497 unsafe_conversion_p (tree type
, tree expr
, bool produce_warns
)
2499 bool give_warning
= false;
2500 tree expr_type
= TREE_TYPE (expr
);
2501 location_t loc
= EXPR_LOC_OR_HERE (expr
);
2503 if (TREE_CODE (expr
) == REAL_CST
|| TREE_CODE (expr
) == INTEGER_CST
)
2505 /* Warn for real constant that is not an exact integer converted
2507 if (TREE_CODE (expr_type
) == REAL_TYPE
2508 && TREE_CODE (type
) == INTEGER_TYPE
)
2510 if (!real_isinteger (TREE_REAL_CST_PTR (expr
), TYPE_MODE (expr_type
)))
2511 give_warning
= true;
2513 /* Warn for an integer constant that does not fit into integer type. */
2514 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2515 && TREE_CODE (type
) == INTEGER_TYPE
2516 && !int_fits_type_p (expr
, type
))
2518 if (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)
2519 && tree_int_cst_sgn (expr
) < 0)
2522 warning_at (loc
, OPT_Wsign_conversion
, "negative integer"
2523 " implicitly converted to unsigned type");
2525 else if (!TYPE_UNSIGNED (type
) && TYPE_UNSIGNED (expr_type
))
2528 warning_at (loc
, OPT_Wsign_conversion
, "conversion of unsigned"
2529 " constant value to negative integer");
2532 give_warning
= true;
2534 else if (TREE_CODE (type
) == REAL_TYPE
)
2536 /* Warn for an integer constant that does not fit into real type. */
2537 if (TREE_CODE (expr_type
) == INTEGER_TYPE
)
2539 REAL_VALUE_TYPE a
= real_value_from_int_cst (0, expr
);
2540 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2541 give_warning
= true;
2543 /* Warn for a real constant that does not fit into a smaller
2545 else if (TREE_CODE (expr_type
) == REAL_TYPE
2546 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2548 REAL_VALUE_TYPE a
= TREE_REAL_CST (expr
);
2549 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2550 give_warning
= true;
2556 /* Warn for real types converted to integer types. */
2557 if (TREE_CODE (expr_type
) == REAL_TYPE
2558 && TREE_CODE (type
) == INTEGER_TYPE
)
2559 give_warning
= true;
2561 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2562 && TREE_CODE (type
) == INTEGER_TYPE
)
2564 /* Don't warn about unsigned char y = 0xff, x = (int) y; */
2565 expr
= get_unwidened (expr
, 0);
2566 expr_type
= TREE_TYPE (expr
);
2568 /* Don't warn for short y; short x = ((int)y & 0xff); */
2569 if (TREE_CODE (expr
) == BIT_AND_EXPR
2570 || TREE_CODE (expr
) == BIT_IOR_EXPR
2571 || TREE_CODE (expr
) == BIT_XOR_EXPR
)
2573 /* If both args were extended from a shortest type,
2574 use that type if that is safe. */
2575 expr_type
= shorten_binary_op (expr_type
,
2576 TREE_OPERAND (expr
, 0),
2577 TREE_OPERAND (expr
, 1),
2580 if (TREE_CODE (expr
) == BIT_AND_EXPR
)
2582 tree op0
= TREE_OPERAND (expr
, 0);
2583 tree op1
= TREE_OPERAND (expr
, 1);
2584 bool unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2585 bool unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2587 /* If one of the operands is a non-negative constant
2588 that fits in the target type, then the type of the
2589 other operand does not matter. */
2590 if ((TREE_CODE (op0
) == INTEGER_CST
2591 && int_fits_type_p (op0
, c_common_signed_type (type
))
2592 && int_fits_type_p (op0
, c_common_unsigned_type (type
)))
2593 || (TREE_CODE (op1
) == INTEGER_CST
2594 && int_fits_type_p (op1
, c_common_signed_type (type
))
2595 && int_fits_type_p (op1
,
2596 c_common_unsigned_type (type
))))
2598 /* If constant is unsigned and fits in the target
2599 type, then the result will also fit. */
2600 else if ((TREE_CODE (op0
) == INTEGER_CST
2602 && int_fits_type_p (op0
, type
))
2603 || (TREE_CODE (op1
) == INTEGER_CST
2605 && int_fits_type_p (op1
, type
)))
2609 /* Warn for integer types converted to smaller integer types. */
2610 if (TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2611 give_warning
= true;
2613 /* When they are the same width but different signedness,
2614 then the value may change. */
2615 else if (((TYPE_PRECISION (type
) == TYPE_PRECISION (expr_type
)
2616 && TYPE_UNSIGNED (expr_type
) != TYPE_UNSIGNED (type
))
2617 /* Even when converted to a bigger type, if the type is
2618 unsigned but expr is signed, then negative values
2620 || (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)))
2622 warning_at (loc
, OPT_Wsign_conversion
, "conversion to %qT from %qT "
2623 "may change the sign of the result",
2627 /* Warn for integer types converted to real types if and only if
2628 all the range of values of the integer type cannot be
2629 represented by the real type. */
2630 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2631 && TREE_CODE (type
) == REAL_TYPE
)
2633 tree type_low_bound
, type_high_bound
;
2634 REAL_VALUE_TYPE real_low_bound
, real_high_bound
;
2636 /* Don't warn about char y = 0xff; float x = (int) y; */
2637 expr
= get_unwidened (expr
, 0);
2638 expr_type
= TREE_TYPE (expr
);
2640 type_low_bound
= TYPE_MIN_VALUE (expr_type
);
2641 type_high_bound
= TYPE_MAX_VALUE (expr_type
);
2642 real_low_bound
= real_value_from_int_cst (0, type_low_bound
);
2643 real_high_bound
= real_value_from_int_cst (0, type_high_bound
);
2645 if (!exact_real_truncate (TYPE_MODE (type
), &real_low_bound
)
2646 || !exact_real_truncate (TYPE_MODE (type
), &real_high_bound
))
2647 give_warning
= true;
2650 /* Warn for real types converted to smaller real types. */
2651 else if (TREE_CODE (expr_type
) == REAL_TYPE
2652 && TREE_CODE (type
) == REAL_TYPE
2653 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2654 give_warning
= true;
2657 return give_warning
;
2660 /* Warns if the conversion of EXPR to TYPE may alter a value.
2661 This is a helper function for warnings_for_convert_and_check. */
2664 conversion_warning (tree type
, tree expr
)
2666 tree expr_type
= TREE_TYPE (expr
);
2667 location_t loc
= EXPR_LOC_OR_HERE (expr
);
2669 if (!warn_conversion
&& !warn_sign_conversion
)
2672 switch (TREE_CODE (expr
))
2680 case TRUTH_ANDIF_EXPR
:
2681 case TRUTH_ORIF_EXPR
:
2682 case TRUTH_AND_EXPR
:
2684 case TRUTH_XOR_EXPR
:
2685 case TRUTH_NOT_EXPR
:
2686 /* Conversion from boolean to a signed:1 bit-field (which only
2687 can hold the values 0 and -1) doesn't lose information - but
2688 it does change the value. */
2689 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
2690 warning_at (loc
, OPT_Wconversion
,
2691 "conversion to %qT from boolean expression", type
);
2696 if (unsafe_conversion_p (type
, expr
, true))
2697 warning_at (loc
, OPT_Wconversion
,
2698 "conversion to %qT alters %qT constant value",
2704 /* In case of COND_EXPR, we do not care about the type of
2705 COND_EXPR, only about the conversion of each operand. */
2706 tree op1
= TREE_OPERAND (expr
, 1);
2707 tree op2
= TREE_OPERAND (expr
, 2);
2709 conversion_warning (type
, op1
);
2710 conversion_warning (type
, op2
);
2714 default: /* 'expr' is not a constant. */
2715 if (unsafe_conversion_p (type
, expr
, true))
2716 warning_at (loc
, OPT_Wconversion
,
2717 "conversion to %qT from %qT may alter its value",
2722 /* Produce warnings after a conversion. RESULT is the result of
2723 converting EXPR to TYPE. This is a helper function for
2724 convert_and_check and cp_convert_and_check. */
2727 warnings_for_convert_and_check (tree type
, tree expr
, tree result
)
2729 location_t loc
= EXPR_LOC_OR_HERE (expr
);
2731 if (TREE_CODE (expr
) == INTEGER_CST
2732 && (TREE_CODE (type
) == INTEGER_TYPE
2733 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2734 && !int_fits_type_p (expr
, type
))
2736 /* Do not diagnose overflow in a constant expression merely
2737 because a conversion overflowed. */
2738 if (TREE_OVERFLOW (result
))
2739 TREE_OVERFLOW (result
) = TREE_OVERFLOW (expr
);
2741 if (TYPE_UNSIGNED (type
))
2743 /* This detects cases like converting -129 or 256 to
2745 if (!int_fits_type_p (expr
, c_common_signed_type (type
)))
2746 warning_at (loc
, OPT_Woverflow
,
2747 "large integer implicitly truncated to unsigned type");
2749 conversion_warning (type
, expr
);
2751 else if (!int_fits_type_p (expr
, c_common_unsigned_type (type
)))
2752 warning (OPT_Woverflow
,
2753 "overflow in implicit constant conversion");
2754 /* No warning for converting 0x80000000 to int. */
2756 && (TREE_CODE (TREE_TYPE (expr
)) != INTEGER_TYPE
2757 || TYPE_PRECISION (TREE_TYPE (expr
))
2758 != TYPE_PRECISION (type
)))
2759 warning_at (loc
, OPT_Woverflow
,
2760 "overflow in implicit constant conversion");
2763 conversion_warning (type
, expr
);
2765 else if ((TREE_CODE (result
) == INTEGER_CST
2766 || TREE_CODE (result
) == FIXED_CST
) && TREE_OVERFLOW (result
))
2767 warning_at (loc
, OPT_Woverflow
,
2768 "overflow in implicit constant conversion");
2770 conversion_warning (type
, expr
);
2774 /* Convert EXPR to TYPE, warning about conversion problems with constants.
2775 Invoke this function on every expression that is converted implicitly,
2776 i.e. because of language rules and not because of an explicit cast. */
2779 convert_and_check (tree type
, tree expr
)
2782 tree expr_for_warning
;
2784 /* Convert from a value with possible excess precision rather than
2785 via the semantic type, but do not warn about values not fitting
2786 exactly in the semantic type. */
2787 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
2789 tree orig_type
= TREE_TYPE (expr
);
2790 expr
= TREE_OPERAND (expr
, 0);
2791 expr_for_warning
= convert (orig_type
, expr
);
2792 if (orig_type
== type
)
2793 return expr_for_warning
;
2796 expr_for_warning
= expr
;
2798 if (TREE_TYPE (expr
) == type
)
2801 result
= convert (type
, expr
);
2803 if (c_inhibit_evaluation_warnings
== 0
2804 && !TREE_OVERFLOW_P (expr
)
2805 && result
!= error_mark_node
)
2806 warnings_for_convert_and_check (type
, expr_for_warning
, result
);
2811 /* A node in a list that describes references to variables (EXPR), which are
2812 either read accesses if WRITER is zero, or write accesses, in which case
2813 WRITER is the parent of EXPR. */
2820 /* Used to implement a cache the results of a call to verify_tree. We only
2821 use this for SAVE_EXPRs. */
2824 struct tlist_cache
*next
;
2825 struct tlist
*cache_before_sp
;
2826 struct tlist
*cache_after_sp
;
2830 /* Obstack to use when allocating tlist structures, and corresponding
2832 static struct obstack tlist_obstack
;
2833 static char *tlist_firstobj
= 0;
2835 /* Keep track of the identifiers we've warned about, so we can avoid duplicate
2837 static struct tlist
*warned_ids
;
2838 /* SAVE_EXPRs need special treatment. We process them only once and then
2839 cache the results. */
2840 static struct tlist_cache
*save_expr_cache
;
2842 static void add_tlist (struct tlist
**, struct tlist
*, tree
, int);
2843 static void merge_tlist (struct tlist
**, struct tlist
*, int);
2844 static void verify_tree (tree
, struct tlist
**, struct tlist
**, tree
);
2845 static int warning_candidate_p (tree
);
2846 static bool candidate_equal_p (const_tree
, const_tree
);
2847 static void warn_for_collisions (struct tlist
*);
2848 static void warn_for_collisions_1 (tree
, tree
, struct tlist
*, int);
2849 static struct tlist
*new_tlist (struct tlist
*, tree
, tree
);
2851 /* Create a new struct tlist and fill in its fields. */
2852 static struct tlist
*
2853 new_tlist (struct tlist
*next
, tree t
, tree writer
)
2856 l
= XOBNEW (&tlist_obstack
, struct tlist
);
2863 /* Add duplicates of the nodes found in ADD to the list *TO. If EXCLUDE_WRITER
2864 is nonnull, we ignore any node we find which has a writer equal to it. */
2867 add_tlist (struct tlist
**to
, struct tlist
*add
, tree exclude_writer
, int copy
)
2871 struct tlist
*next
= add
->next
;
2874 if (!exclude_writer
|| !candidate_equal_p (add
->writer
, exclude_writer
))
2875 *to
= copy
? new_tlist (*to
, add
->expr
, add
->writer
) : add
;
2880 /* Merge the nodes of ADD into TO. This merging process is done so that for
2881 each variable that already exists in TO, no new node is added; however if
2882 there is a write access recorded in ADD, and an occurrence on TO is only
2883 a read access, then the occurrence in TO will be modified to record the
2887 merge_tlist (struct tlist
**to
, struct tlist
*add
, int copy
)
2889 struct tlist
**end
= to
;
2892 end
= &(*end
)->next
;
2898 struct tlist
*next
= add
->next
;
2900 for (tmp2
= *to
; tmp2
; tmp2
= tmp2
->next
)
2901 if (candidate_equal_p (tmp2
->expr
, add
->expr
))
2905 tmp2
->writer
= add
->writer
;
2909 *end
= copy
? add
: new_tlist (NULL
, add
->expr
, add
->writer
);
2910 end
= &(*end
)->next
;
2917 /* WRITTEN is a variable, WRITER is its parent. Warn if any of the variable
2918 references in list LIST conflict with it, excluding reads if ONLY writers
2922 warn_for_collisions_1 (tree written
, tree writer
, struct tlist
*list
,
2927 /* Avoid duplicate warnings. */
2928 for (tmp
= warned_ids
; tmp
; tmp
= tmp
->next
)
2929 if (candidate_equal_p (tmp
->expr
, written
))
2934 if (candidate_equal_p (list
->expr
, written
)
2935 && !candidate_equal_p (list
->writer
, writer
)
2936 && (!only_writes
|| list
->writer
))
2938 warned_ids
= new_tlist (warned_ids
, written
, NULL_TREE
);
2939 warning_at (EXPR_LOC_OR_HERE (writer
),
2940 OPT_Wsequence_point
, "operation on %qE may be undefined",
2947 /* Given a list LIST of references to variables, find whether any of these
2948 can cause conflicts due to missing sequence points. */
2951 warn_for_collisions (struct tlist
*list
)
2955 for (tmp
= list
; tmp
; tmp
= tmp
->next
)
2958 warn_for_collisions_1 (tmp
->expr
, tmp
->writer
, list
, 0);
2962 /* Return nonzero if X is a tree that can be verified by the sequence point
2965 warning_candidate_p (tree x
)
2967 if (DECL_P (x
) && DECL_ARTIFICIAL (x
))
2970 if (TREE_CODE (x
) == BLOCK
)
2973 /* VOID_TYPE_P (TREE_TYPE (x)) is workaround for cp/tree.c
2974 (lvalue_p) crash on TRY/CATCH. */
2975 if (TREE_TYPE (x
) == NULL_TREE
|| VOID_TYPE_P (TREE_TYPE (x
)))
2981 /* No point to track non-const calls, they will never satisfy
2983 if (TREE_CODE (x
) == CALL_EXPR
&& (call_expr_flags (x
) & ECF_CONST
) == 0)
2986 if (TREE_CODE (x
) == STRING_CST
)
2992 /* Return nonzero if X and Y appear to be the same candidate (or NULL) */
2994 candidate_equal_p (const_tree x
, const_tree y
)
2996 return (x
== y
) || (x
&& y
&& operand_equal_p (x
, y
, 0));
2999 /* Walk the tree X, and record accesses to variables. If X is written by the
3000 parent tree, WRITER is the parent.
3001 We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP. If this
3002 expression or its only operand forces a sequence point, then everything up
3003 to the sequence point is stored in PBEFORE_SP. Everything else gets stored
3005 Once we return, we will have emitted warnings if any subexpression before
3006 such a sequence point could be undefined. On a higher level, however, the
3007 sequence point may not be relevant, and we'll merge the two lists.
3009 Example: (b++, a) + b;
3010 The call that processes the COMPOUND_EXPR will store the increment of B
3011 in PBEFORE_SP, and the use of A in PNO_SP. The higher-level call that
3012 processes the PLUS_EXPR will need to merge the two lists so that
3013 eventually, all accesses end up on the same list (and we'll warn about the
3014 unordered subexpressions b++ and b.
3016 A note on merging. If we modify the former example so that our expression
3019 care must be taken not simply to add all three expressions into the final
3020 PNO_SP list. The function merge_tlist takes care of that by merging the
3021 before-SP list of the COMPOUND_EXPR into its after-SP list in a special
3022 way, so that no more than one access to B is recorded. */
3025 verify_tree (tree x
, struct tlist
**pbefore_sp
, struct tlist
**pno_sp
,
3028 struct tlist
*tmp_before
, *tmp_nosp
, *tmp_list2
, *tmp_list3
;
3029 enum tree_code code
;
3030 enum tree_code_class cl
;
3032 /* X may be NULL if it is the operand of an empty statement expression
3038 code
= TREE_CODE (x
);
3039 cl
= TREE_CODE_CLASS (code
);
3041 if (warning_candidate_p (x
))
3042 *pno_sp
= new_tlist (*pno_sp
, x
, writer
);
3051 case TRUTH_ANDIF_EXPR
:
3052 case TRUTH_ORIF_EXPR
:
3053 tmp_before
= tmp_nosp
= tmp_list3
= 0;
3054 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3055 warn_for_collisions (tmp_nosp
);
3056 merge_tlist (pbefore_sp
, tmp_before
, 0);
3057 merge_tlist (pbefore_sp
, tmp_nosp
, 0);
3058 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, pno_sp
, NULL_TREE
);
3059 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3063 tmp_before
= tmp_list2
= 0;
3064 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_list2
, NULL_TREE
);
3065 warn_for_collisions (tmp_list2
);
3066 merge_tlist (pbefore_sp
, tmp_before
, 0);
3067 merge_tlist (pbefore_sp
, tmp_list2
, 1);
3069 tmp_list3
= tmp_nosp
= 0;
3070 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, &tmp_nosp
, NULL_TREE
);
3071 warn_for_collisions (tmp_nosp
);
3072 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3074 tmp_list3
= tmp_list2
= 0;
3075 verify_tree (TREE_OPERAND (x
, 2), &tmp_list3
, &tmp_list2
, NULL_TREE
);
3076 warn_for_collisions (tmp_list2
);
3077 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3078 /* Rather than add both tmp_nosp and tmp_list2, we have to merge the
3079 two first, to avoid warning for (a ? b++ : b++). */
3080 merge_tlist (&tmp_nosp
, tmp_list2
, 0);
3081 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3084 case PREDECREMENT_EXPR
:
3085 case PREINCREMENT_EXPR
:
3086 case POSTDECREMENT_EXPR
:
3087 case POSTINCREMENT_EXPR
:
3088 verify_tree (TREE_OPERAND (x
, 0), pno_sp
, pno_sp
, x
);
3092 tmp_before
= tmp_nosp
= tmp_list3
= 0;
3093 verify_tree (TREE_OPERAND (x
, 1), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3094 verify_tree (TREE_OPERAND (x
, 0), &tmp_list3
, &tmp_list3
, x
);
3095 /* Expressions inside the LHS are not ordered wrt. the sequence points
3096 in the RHS. Example:
3098 Despite the fact that the modification of "a" is in the before_sp
3099 list (tmp_before), it conflicts with the use of "a" in the LHS.
3100 We can handle this by adding the contents of tmp_list3
3101 to those of tmp_before, and redoing the collision warnings for that
3103 add_tlist (&tmp_before
, tmp_list3
, x
, 1);
3104 warn_for_collisions (tmp_before
);
3105 /* Exclude the LHS itself here; we first have to merge it into the
3106 tmp_nosp list. This is done to avoid warning for "a = a"; if we
3107 didn't exclude the LHS, we'd get it twice, once as a read and once
3109 add_tlist (pno_sp
, tmp_list3
, x
, 0);
3110 warn_for_collisions_1 (TREE_OPERAND (x
, 0), x
, tmp_nosp
, 1);
3112 merge_tlist (pbefore_sp
, tmp_before
, 0);
3113 if (warning_candidate_p (TREE_OPERAND (x
, 0)))
3114 merge_tlist (&tmp_nosp
, new_tlist (NULL
, TREE_OPERAND (x
, 0), x
), 0);
3115 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 1);
3119 /* We need to warn about conflicts among arguments and conflicts between
3120 args and the function address. Side effects of the function address,
3121 however, are not ordered by the sequence point of the call. */
3123 call_expr_arg_iterator iter
;
3125 tmp_before
= tmp_nosp
= 0;
3126 verify_tree (CALL_EXPR_FN (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3127 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, x
)
3129 tmp_list2
= tmp_list3
= 0;
3130 verify_tree (arg
, &tmp_list2
, &tmp_list3
, NULL_TREE
);
3131 merge_tlist (&tmp_list3
, tmp_list2
, 0);
3132 add_tlist (&tmp_before
, tmp_list3
, NULL_TREE
, 0);
3134 add_tlist (&tmp_before
, tmp_nosp
, NULL_TREE
, 0);
3135 warn_for_collisions (tmp_before
);
3136 add_tlist (pbefore_sp
, tmp_before
, NULL_TREE
, 0);
3141 /* Scan all the list, e.g. indices of multi dimensional array. */
3144 tmp_before
= tmp_nosp
= 0;
3145 verify_tree (TREE_VALUE (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3146 merge_tlist (&tmp_nosp
, tmp_before
, 0);
3147 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3154 struct tlist_cache
*t
;
3155 for (t
= save_expr_cache
; t
; t
= t
->next
)
3156 if (candidate_equal_p (t
->expr
, x
))
3161 t
= XOBNEW (&tlist_obstack
, struct tlist_cache
);
3162 t
->next
= save_expr_cache
;
3164 save_expr_cache
= t
;
3166 tmp_before
= tmp_nosp
= 0;
3167 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3168 warn_for_collisions (tmp_nosp
);
3173 struct tlist
*t
= tmp_nosp
;
3175 merge_tlist (&tmp_list3
, t
, 0);
3177 t
->cache_before_sp
= tmp_before
;
3178 t
->cache_after_sp
= tmp_list3
;
3180 merge_tlist (pbefore_sp
, t
->cache_before_sp
, 1);
3181 add_tlist (pno_sp
, t
->cache_after_sp
, NULL_TREE
, 1);
3186 x
= TREE_OPERAND (x
, 0);
3193 /* For other expressions, simply recurse on their operands.
3194 Manual tail recursion for unary expressions.
3195 Other non-expressions need not be processed. */
3196 if (cl
== tcc_unary
)
3198 x
= TREE_OPERAND (x
, 0);
3202 else if (IS_EXPR_CODE_CLASS (cl
))
3205 int max
= TREE_OPERAND_LENGTH (x
);
3206 for (lp
= 0; lp
< max
; lp
++)
3208 tmp_before
= tmp_nosp
= 0;
3209 verify_tree (TREE_OPERAND (x
, lp
), &tmp_before
, &tmp_nosp
, 0);
3210 merge_tlist (&tmp_nosp
, tmp_before
, 0);
3211 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3218 /* Try to warn for undefined behavior in EXPR due to missing sequence
3222 verify_sequence_points (tree expr
)
3224 struct tlist
*before_sp
= 0, *after_sp
= 0;
3227 save_expr_cache
= 0;
3228 if (tlist_firstobj
== 0)
3230 gcc_obstack_init (&tlist_obstack
);
3231 tlist_firstobj
= (char *) obstack_alloc (&tlist_obstack
, 0);
3234 verify_tree (expr
, &before_sp
, &after_sp
, 0);
3235 warn_for_collisions (after_sp
);
3236 obstack_free (&tlist_obstack
, tlist_firstobj
);
3239 /* Validate the expression after `case' and apply default promotions. */
3242 check_case_value (tree value
)
3244 if (value
== NULL_TREE
)
3247 if (TREE_CODE (value
) == INTEGER_CST
)
3248 /* Promote char or short to int. */
3249 value
= perform_integral_promotions (value
);
3250 else if (value
!= error_mark_node
)
3252 error ("case label does not reduce to an integer constant");
3253 value
= error_mark_node
;
3256 constant_expression_warning (value
);
3261 /* See if the case values LOW and HIGH are in the range of the original
3262 type (i.e. before the default conversion to int) of the switch testing
3264 TYPE is the promoted type of the testing expression, and ORIG_TYPE is
3265 the type before promoting it. CASE_LOW_P is a pointer to the lower
3266 bound of the case label, and CASE_HIGH_P is the upper bound or NULL
3267 if the case is not a case range.
3268 The caller has to make sure that we are not called with NULL for
3269 CASE_LOW_P (i.e. the default case).
3270 Returns true if the case label is in range of ORIG_TYPE (saturated or
3271 untouched) or false if the label is out of range. */
3274 check_case_bounds (tree type
, tree orig_type
,
3275 tree
*case_low_p
, tree
*case_high_p
)
3277 tree min_value
, max_value
;
3278 tree case_low
= *case_low_p
;
3279 tree case_high
= case_high_p
? *case_high_p
: case_low
;
3281 /* If there was a problem with the original type, do nothing. */
3282 if (orig_type
== error_mark_node
)
3285 min_value
= TYPE_MIN_VALUE (orig_type
);
3286 max_value
= TYPE_MAX_VALUE (orig_type
);
3288 /* Case label is less than minimum for type. */
3289 if (tree_int_cst_compare (case_low
, min_value
) < 0
3290 && tree_int_cst_compare (case_high
, min_value
) < 0)
3292 warning (0, "case label value is less than minimum value for type");
3296 /* Case value is greater than maximum for type. */
3297 if (tree_int_cst_compare (case_low
, max_value
) > 0
3298 && tree_int_cst_compare (case_high
, max_value
) > 0)
3300 warning (0, "case label value exceeds maximum value for type");
3304 /* Saturate lower case label value to minimum. */
3305 if (tree_int_cst_compare (case_high
, min_value
) >= 0
3306 && tree_int_cst_compare (case_low
, min_value
) < 0)
3308 warning (0, "lower value in case label range"
3309 " less than minimum value for type");
3310 case_low
= min_value
;
3313 /* Saturate upper case label value to maximum. */
3314 if (tree_int_cst_compare (case_low
, max_value
) <= 0
3315 && tree_int_cst_compare (case_high
, max_value
) > 0)
3317 warning (0, "upper value in case label range"
3318 " exceeds maximum value for type");
3319 case_high
= max_value
;
3322 if (*case_low_p
!= case_low
)
3323 *case_low_p
= convert (type
, case_low
);
3324 if (case_high_p
&& *case_high_p
!= case_high
)
3325 *case_high_p
= convert (type
, case_high
);
3330 /* Return an integer type with BITS bits of precision,
3331 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
3334 c_common_type_for_size (unsigned int bits
, int unsignedp
)
3336 if (bits
== TYPE_PRECISION (integer_type_node
))
3337 return unsignedp
? unsigned_type_node
: integer_type_node
;
3339 if (bits
== TYPE_PRECISION (signed_char_type_node
))
3340 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3342 if (bits
== TYPE_PRECISION (short_integer_type_node
))
3343 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3345 if (bits
== TYPE_PRECISION (long_integer_type_node
))
3346 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3348 if (bits
== TYPE_PRECISION (long_long_integer_type_node
))
3349 return (unsignedp
? long_long_unsigned_type_node
3350 : long_long_integer_type_node
);
3352 if (int128_integer_type_node
3353 && bits
== TYPE_PRECISION (int128_integer_type_node
))
3354 return (unsignedp
? int128_unsigned_type_node
3355 : int128_integer_type_node
);
3357 if (bits
== TYPE_PRECISION (widest_integer_literal_type_node
))
3358 return (unsignedp
? widest_unsigned_literal_type_node
3359 : widest_integer_literal_type_node
);
3361 if (bits
<= TYPE_PRECISION (intQI_type_node
))
3362 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3364 if (bits
<= TYPE_PRECISION (intHI_type_node
))
3365 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3367 if (bits
<= TYPE_PRECISION (intSI_type_node
))
3368 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3370 if (bits
<= TYPE_PRECISION (intDI_type_node
))
3371 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3376 /* Return a fixed-point type that has at least IBIT ibits and FBIT fbits
3377 that is unsigned if UNSIGNEDP is nonzero, otherwise signed;
3378 and saturating if SATP is nonzero, otherwise not saturating. */
3381 c_common_fixed_point_type_for_size (unsigned int ibit
, unsigned int fbit
,
3382 int unsignedp
, int satp
)
3384 enum machine_mode mode
;
3386 mode
= unsignedp
? UQQmode
: QQmode
;
3388 mode
= unsignedp
? UHAmode
: HAmode
;
3390 for (; mode
!= VOIDmode
; mode
= GET_MODE_WIDER_MODE (mode
))
3391 if (GET_MODE_IBIT (mode
) >= ibit
&& GET_MODE_FBIT (mode
) >= fbit
)
3394 if (mode
== VOIDmode
|| !targetm
.scalar_mode_supported_p (mode
))
3396 sorry ("GCC cannot support operators with integer types and "
3397 "fixed-point types that have too many integral and "
3398 "fractional bits together");
3402 return c_common_type_for_mode (mode
, satp
);
3405 /* Used for communication between c_common_type_for_mode and
3406 c_register_builtin_type. */
3407 static GTY(()) tree registered_builtin_types
;
3409 /* Return a data type that has machine mode MODE.
3410 If the mode is an integer,
3411 then UNSIGNEDP selects between signed and unsigned types.
3412 If the mode is a fixed-point mode,
3413 then UNSIGNEDP selects between saturating and nonsaturating types. */
3416 c_common_type_for_mode (enum machine_mode mode
, int unsignedp
)
3420 if (mode
== TYPE_MODE (integer_type_node
))
3421 return unsignedp
? unsigned_type_node
: integer_type_node
;
3423 if (mode
== TYPE_MODE (signed_char_type_node
))
3424 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3426 if (mode
== TYPE_MODE (short_integer_type_node
))
3427 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3429 if (mode
== TYPE_MODE (long_integer_type_node
))
3430 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3432 if (mode
== TYPE_MODE (long_long_integer_type_node
))
3433 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3435 if (int128_integer_type_node
3436 && mode
== TYPE_MODE (int128_integer_type_node
))
3437 return unsignedp
? int128_unsigned_type_node
: int128_integer_type_node
;
3439 if (mode
== TYPE_MODE (widest_integer_literal_type_node
))
3440 return unsignedp
? widest_unsigned_literal_type_node
3441 : widest_integer_literal_type_node
;
3444 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3447 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3450 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3453 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3455 #if HOST_BITS_PER_WIDE_INT >= 64
3456 if (mode
== TYPE_MODE (intTI_type_node
))
3457 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3460 if (mode
== TYPE_MODE (float_type_node
))
3461 return float_type_node
;
3463 if (mode
== TYPE_MODE (double_type_node
))
3464 return double_type_node
;
3466 if (mode
== TYPE_MODE (long_double_type_node
))
3467 return long_double_type_node
;
3469 if (mode
== TYPE_MODE (void_type_node
))
3470 return void_type_node
;
3472 if (mode
== TYPE_MODE (build_pointer_type (char_type_node
)))
3474 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3475 : make_signed_type (GET_MODE_PRECISION (mode
)));
3477 if (mode
== TYPE_MODE (build_pointer_type (integer_type_node
)))
3479 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3480 : make_signed_type (GET_MODE_PRECISION (mode
)));
3482 if (COMPLEX_MODE_P (mode
))
3484 enum machine_mode inner_mode
;
3487 if (mode
== TYPE_MODE (complex_float_type_node
))
3488 return complex_float_type_node
;
3489 if (mode
== TYPE_MODE (complex_double_type_node
))
3490 return complex_double_type_node
;
3491 if (mode
== TYPE_MODE (complex_long_double_type_node
))
3492 return complex_long_double_type_node
;
3494 if (mode
== TYPE_MODE (complex_integer_type_node
) && !unsignedp
)
3495 return complex_integer_type_node
;
3497 inner_mode
= GET_MODE_INNER (mode
);
3498 inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3499 if (inner_type
!= NULL_TREE
)
3500 return build_complex_type (inner_type
);
3502 else if (VECTOR_MODE_P (mode
))
3504 enum machine_mode inner_mode
= GET_MODE_INNER (mode
);
3505 tree inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3506 if (inner_type
!= NULL_TREE
)
3507 return build_vector_type_for_mode (inner_type
, mode
);
3510 if (mode
== TYPE_MODE (dfloat32_type_node
))
3511 return dfloat32_type_node
;
3512 if (mode
== TYPE_MODE (dfloat64_type_node
))
3513 return dfloat64_type_node
;
3514 if (mode
== TYPE_MODE (dfloat128_type_node
))
3515 return dfloat128_type_node
;
3517 if (ALL_SCALAR_FIXED_POINT_MODE_P (mode
))
3519 if (mode
== TYPE_MODE (short_fract_type_node
))
3520 return unsignedp
? sat_short_fract_type_node
: short_fract_type_node
;
3521 if (mode
== TYPE_MODE (fract_type_node
))
3522 return unsignedp
? sat_fract_type_node
: fract_type_node
;
3523 if (mode
== TYPE_MODE (long_fract_type_node
))
3524 return unsignedp
? sat_long_fract_type_node
: long_fract_type_node
;
3525 if (mode
== TYPE_MODE (long_long_fract_type_node
))
3526 return unsignedp
? sat_long_long_fract_type_node
3527 : long_long_fract_type_node
;
3529 if (mode
== TYPE_MODE (unsigned_short_fract_type_node
))
3530 return unsignedp
? sat_unsigned_short_fract_type_node
3531 : unsigned_short_fract_type_node
;
3532 if (mode
== TYPE_MODE (unsigned_fract_type_node
))
3533 return unsignedp
? sat_unsigned_fract_type_node
3534 : unsigned_fract_type_node
;
3535 if (mode
== TYPE_MODE (unsigned_long_fract_type_node
))
3536 return unsignedp
? sat_unsigned_long_fract_type_node
3537 : unsigned_long_fract_type_node
;
3538 if (mode
== TYPE_MODE (unsigned_long_long_fract_type_node
))
3539 return unsignedp
? sat_unsigned_long_long_fract_type_node
3540 : unsigned_long_long_fract_type_node
;
3542 if (mode
== TYPE_MODE (short_accum_type_node
))
3543 return unsignedp
? sat_short_accum_type_node
: short_accum_type_node
;
3544 if (mode
== TYPE_MODE (accum_type_node
))
3545 return unsignedp
? sat_accum_type_node
: accum_type_node
;
3546 if (mode
== TYPE_MODE (long_accum_type_node
))
3547 return unsignedp
? sat_long_accum_type_node
: long_accum_type_node
;
3548 if (mode
== TYPE_MODE (long_long_accum_type_node
))
3549 return unsignedp
? sat_long_long_accum_type_node
3550 : long_long_accum_type_node
;
3552 if (mode
== TYPE_MODE (unsigned_short_accum_type_node
))
3553 return unsignedp
? sat_unsigned_short_accum_type_node
3554 : unsigned_short_accum_type_node
;
3555 if (mode
== TYPE_MODE (unsigned_accum_type_node
))
3556 return unsignedp
? sat_unsigned_accum_type_node
3557 : unsigned_accum_type_node
;
3558 if (mode
== TYPE_MODE (unsigned_long_accum_type_node
))
3559 return unsignedp
? sat_unsigned_long_accum_type_node
3560 : unsigned_long_accum_type_node
;
3561 if (mode
== TYPE_MODE (unsigned_long_long_accum_type_node
))
3562 return unsignedp
? sat_unsigned_long_long_accum_type_node
3563 : unsigned_long_long_accum_type_node
;
3566 return unsignedp
? sat_qq_type_node
: qq_type_node
;
3568 return unsignedp
? sat_hq_type_node
: hq_type_node
;
3570 return unsignedp
? sat_sq_type_node
: sq_type_node
;
3572 return unsignedp
? sat_dq_type_node
: dq_type_node
;
3574 return unsignedp
? sat_tq_type_node
: tq_type_node
;
3576 if (mode
== UQQmode
)
3577 return unsignedp
? sat_uqq_type_node
: uqq_type_node
;
3578 if (mode
== UHQmode
)
3579 return unsignedp
? sat_uhq_type_node
: uhq_type_node
;
3580 if (mode
== USQmode
)
3581 return unsignedp
? sat_usq_type_node
: usq_type_node
;
3582 if (mode
== UDQmode
)
3583 return unsignedp
? sat_udq_type_node
: udq_type_node
;
3584 if (mode
== UTQmode
)
3585 return unsignedp
? sat_utq_type_node
: utq_type_node
;
3588 return unsignedp
? sat_ha_type_node
: ha_type_node
;
3590 return unsignedp
? sat_sa_type_node
: sa_type_node
;
3592 return unsignedp
? sat_da_type_node
: da_type_node
;
3594 return unsignedp
? sat_ta_type_node
: ta_type_node
;
3596 if (mode
== UHAmode
)
3597 return unsignedp
? sat_uha_type_node
: uha_type_node
;
3598 if (mode
== USAmode
)
3599 return unsignedp
? sat_usa_type_node
: usa_type_node
;
3600 if (mode
== UDAmode
)
3601 return unsignedp
? sat_uda_type_node
: uda_type_node
;
3602 if (mode
== UTAmode
)
3603 return unsignedp
? sat_uta_type_node
: uta_type_node
;
3606 for (t
= registered_builtin_types
; t
; t
= TREE_CHAIN (t
))
3607 if (TYPE_MODE (TREE_VALUE (t
)) == mode
3608 && !!unsignedp
== !!TYPE_UNSIGNED (TREE_VALUE (t
)))
3609 return TREE_VALUE (t
);
3615 c_common_unsigned_type (tree type
)
3617 return c_common_signed_or_unsigned_type (1, type
);
3620 /* Return a signed type the same as TYPE in other respects. */
3623 c_common_signed_type (tree type
)
3625 return c_common_signed_or_unsigned_type (0, type
);
3628 /* Return a type the same as TYPE except unsigned or
3629 signed according to UNSIGNEDP. */
3632 c_common_signed_or_unsigned_type (int unsignedp
, tree type
)
3636 /* This block of code emulates the behavior of the old
3637 c_common_unsigned_type. In particular, it returns
3638 long_unsigned_type_node if passed a long, even when a int would
3639 have the same size. This is necessary for warnings to work
3640 correctly in archs where sizeof(int) == sizeof(long) */
3642 type1
= TYPE_MAIN_VARIANT (type
);
3643 if (type1
== signed_char_type_node
|| type1
== char_type_node
|| type1
== unsigned_char_type_node
)
3644 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3645 if (type1
== integer_type_node
|| type1
== unsigned_type_node
)
3646 return unsignedp
? unsigned_type_node
: integer_type_node
;
3647 if (type1
== short_integer_type_node
|| type1
== short_unsigned_type_node
)
3648 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3649 if (type1
== long_integer_type_node
|| type1
== long_unsigned_type_node
)
3650 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3651 if (type1
== long_long_integer_type_node
|| type1
== long_long_unsigned_type_node
)
3652 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3653 if (int128_integer_type_node
3654 && (type1
== int128_integer_type_node
3655 || type1
== int128_unsigned_type_node
))
3656 return unsignedp
? int128_unsigned_type_node
: int128_integer_type_node
;
3657 if (type1
== widest_integer_literal_type_node
|| type1
== widest_unsigned_literal_type_node
)
3658 return unsignedp
? widest_unsigned_literal_type_node
: widest_integer_literal_type_node
;
3659 #if HOST_BITS_PER_WIDE_INT >= 64
3660 if (type1
== intTI_type_node
|| type1
== unsigned_intTI_type_node
)
3661 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3663 if (type1
== intDI_type_node
|| type1
== unsigned_intDI_type_node
)
3664 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3665 if (type1
== intSI_type_node
|| type1
== unsigned_intSI_type_node
)
3666 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3667 if (type1
== intHI_type_node
|| type1
== unsigned_intHI_type_node
)
3668 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3669 if (type1
== intQI_type_node
|| type1
== unsigned_intQI_type_node
)
3670 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3672 #define C_COMMON_FIXED_TYPES(NAME) \
3673 if (type1 == short_ ## NAME ## _type_node \
3674 || type1 == unsigned_short_ ## NAME ## _type_node) \
3675 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
3676 : short_ ## NAME ## _type_node; \
3677 if (type1 == NAME ## _type_node \
3678 || type1 == unsigned_ ## NAME ## _type_node) \
3679 return unsignedp ? unsigned_ ## NAME ## _type_node \
3680 : NAME ## _type_node; \
3681 if (type1 == long_ ## NAME ## _type_node \
3682 || type1 == unsigned_long_ ## NAME ## _type_node) \
3683 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
3684 : long_ ## NAME ## _type_node; \
3685 if (type1 == long_long_ ## NAME ## _type_node \
3686 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
3687 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
3688 : long_long_ ## NAME ## _type_node;
3690 #define C_COMMON_FIXED_MODE_TYPES(NAME) \
3691 if (type1 == NAME ## _type_node \
3692 || type1 == u ## NAME ## _type_node) \
3693 return unsignedp ? u ## NAME ## _type_node \
3694 : NAME ## _type_node;
3696 #define C_COMMON_FIXED_TYPES_SAT(NAME) \
3697 if (type1 == sat_ ## short_ ## NAME ## _type_node \
3698 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
3699 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
3700 : sat_ ## short_ ## NAME ## _type_node; \
3701 if (type1 == sat_ ## NAME ## _type_node \
3702 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
3703 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
3704 : sat_ ## NAME ## _type_node; \
3705 if (type1 == sat_ ## long_ ## NAME ## _type_node \
3706 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
3707 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
3708 : sat_ ## long_ ## NAME ## _type_node; \
3709 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
3710 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
3711 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
3712 : sat_ ## long_long_ ## NAME ## _type_node;
3714 #define C_COMMON_FIXED_MODE_TYPES_SAT(NAME) \
3715 if (type1 == sat_ ## NAME ## _type_node \
3716 || type1 == sat_ ## u ## NAME ## _type_node) \
3717 return unsignedp ? sat_ ## u ## NAME ## _type_node \
3718 : sat_ ## NAME ## _type_node;
3720 C_COMMON_FIXED_TYPES (fract
);
3721 C_COMMON_FIXED_TYPES_SAT (fract
);
3722 C_COMMON_FIXED_TYPES (accum
);
3723 C_COMMON_FIXED_TYPES_SAT (accum
);
3725 C_COMMON_FIXED_MODE_TYPES (qq
);
3726 C_COMMON_FIXED_MODE_TYPES (hq
);
3727 C_COMMON_FIXED_MODE_TYPES (sq
);
3728 C_COMMON_FIXED_MODE_TYPES (dq
);
3729 C_COMMON_FIXED_MODE_TYPES (tq
);
3730 C_COMMON_FIXED_MODE_TYPES_SAT (qq
);
3731 C_COMMON_FIXED_MODE_TYPES_SAT (hq
);
3732 C_COMMON_FIXED_MODE_TYPES_SAT (sq
);
3733 C_COMMON_FIXED_MODE_TYPES_SAT (dq
);
3734 C_COMMON_FIXED_MODE_TYPES_SAT (tq
);
3735 C_COMMON_FIXED_MODE_TYPES (ha
);
3736 C_COMMON_FIXED_MODE_TYPES (sa
);
3737 C_COMMON_FIXED_MODE_TYPES (da
);
3738 C_COMMON_FIXED_MODE_TYPES (ta
);
3739 C_COMMON_FIXED_MODE_TYPES_SAT (ha
);
3740 C_COMMON_FIXED_MODE_TYPES_SAT (sa
);
3741 C_COMMON_FIXED_MODE_TYPES_SAT (da
);
3742 C_COMMON_FIXED_MODE_TYPES_SAT (ta
);
3744 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
3745 the precision; they have precision set to match their range, but
3746 may use a wider mode to match an ABI. If we change modes, we may
3747 wind up with bad conversions. For INTEGER_TYPEs in C, must check
3748 the precision as well, so as to yield correct results for
3749 bit-field types. C++ does not have these separate bit-field
3750 types, and producing a signed or unsigned variant of an
3751 ENUMERAL_TYPE may cause other problems as well. */
3753 if (!INTEGRAL_TYPE_P (type
)
3754 || TYPE_UNSIGNED (type
) == unsignedp
)
3757 #define TYPE_OK(node) \
3758 (TYPE_MODE (type) == TYPE_MODE (node) \
3759 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
3760 if (TYPE_OK (signed_char_type_node
))
3761 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3762 if (TYPE_OK (integer_type_node
))
3763 return unsignedp
? unsigned_type_node
: integer_type_node
;
3764 if (TYPE_OK (short_integer_type_node
))
3765 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3766 if (TYPE_OK (long_integer_type_node
))
3767 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3768 if (TYPE_OK (long_long_integer_type_node
))
3769 return (unsignedp
? long_long_unsigned_type_node
3770 : long_long_integer_type_node
);
3771 if (int128_integer_type_node
&& TYPE_OK (int128_integer_type_node
))
3772 return (unsignedp
? int128_unsigned_type_node
3773 : int128_integer_type_node
);
3774 if (TYPE_OK (widest_integer_literal_type_node
))
3775 return (unsignedp
? widest_unsigned_literal_type_node
3776 : widest_integer_literal_type_node
);
3778 #if HOST_BITS_PER_WIDE_INT >= 64
3779 if (TYPE_OK (intTI_type_node
))
3780 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3782 if (TYPE_OK (intDI_type_node
))
3783 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3784 if (TYPE_OK (intSI_type_node
))
3785 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3786 if (TYPE_OK (intHI_type_node
))
3787 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3788 if (TYPE_OK (intQI_type_node
))
3789 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3792 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
3795 /* Build a bit-field integer type for the given WIDTH and UNSIGNEDP. */
3798 c_build_bitfield_integer_type (unsigned HOST_WIDE_INT width
, int unsignedp
)
3800 /* Extended integer types of the same width as a standard type have
3801 lesser rank, so those of the same width as int promote to int or
3802 unsigned int and are valid for printf formats expecting int or
3803 unsigned int. To avoid such special cases, avoid creating
3804 extended integer types for bit-fields if a standard integer type
3806 if (width
== TYPE_PRECISION (integer_type_node
))
3807 return unsignedp
? unsigned_type_node
: integer_type_node
;
3808 if (width
== TYPE_PRECISION (signed_char_type_node
))
3809 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3810 if (width
== TYPE_PRECISION (short_integer_type_node
))
3811 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3812 if (width
== TYPE_PRECISION (long_integer_type_node
))
3813 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3814 if (width
== TYPE_PRECISION (long_long_integer_type_node
))
3815 return (unsignedp
? long_long_unsigned_type_node
3816 : long_long_integer_type_node
);
3817 if (int128_integer_type_node
3818 && width
== TYPE_PRECISION (int128_integer_type_node
))
3819 return (unsignedp
? int128_unsigned_type_node
3820 : int128_integer_type_node
);
3821 return build_nonstandard_integer_type (width
, unsignedp
);
3824 /* The C version of the register_builtin_type langhook. */
3827 c_register_builtin_type (tree type
, const char* name
)
3831 decl
= build_decl (UNKNOWN_LOCATION
,
3832 TYPE_DECL
, get_identifier (name
), type
);
3833 DECL_ARTIFICIAL (decl
) = 1;
3834 if (!TYPE_NAME (type
))
3835 TYPE_NAME (type
) = decl
;
3838 registered_builtin_types
= tree_cons (0, type
, registered_builtin_types
);
3841 /* Print an error message for invalid operands to arith operation
3842 CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
3843 LOCATION is the location of the message. */
3846 binary_op_error (location_t location
, enum tree_code code
,
3847 tree type0
, tree type1
)
3854 opname
= "+"; break;
3856 opname
= "-"; break;
3858 opname
= "*"; break;
3860 opname
= "max"; break;
3862 opname
= "min"; break;
3864 opname
= "=="; break;
3866 opname
= "!="; break;
3868 opname
= "<="; break;
3870 opname
= ">="; break;
3872 opname
= "<"; break;
3874 opname
= ">"; break;
3876 opname
= "<<"; break;
3878 opname
= ">>"; break;
3879 case TRUNC_MOD_EXPR
:
3880 case FLOOR_MOD_EXPR
:
3881 opname
= "%"; break;
3882 case TRUNC_DIV_EXPR
:
3883 case FLOOR_DIV_EXPR
:
3884 opname
= "/"; break;
3886 opname
= "&"; break;
3888 opname
= "|"; break;
3889 case TRUTH_ANDIF_EXPR
:
3890 opname
= "&&"; break;
3891 case TRUTH_ORIF_EXPR
:
3892 opname
= "||"; break;
3894 opname
= "^"; break;
3899 "invalid operands to binary %s (have %qT and %qT)", opname
,
3903 /* Given an expression as a tree, return its original type. Do this
3904 by stripping any conversion that preserves the sign and precision. */
3906 expr_original_type (tree expr
)
3908 STRIP_SIGN_NOPS (expr
);
3909 return TREE_TYPE (expr
);
3912 /* Subroutine of build_binary_op, used for comparison operations.
3913 See if the operands have both been converted from subword integer types
3914 and, if so, perhaps change them both back to their original type.
3915 This function is also responsible for converting the two operands
3916 to the proper common type for comparison.
3918 The arguments of this function are all pointers to local variables
3919 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
3920 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
3922 If this function returns nonzero, it means that the comparison has
3923 a constant value. What this function returns is an expression for
3927 shorten_compare (tree
*op0_ptr
, tree
*op1_ptr
, tree
*restype_ptr
,
3928 enum tree_code
*rescode_ptr
)
3931 tree op0
= *op0_ptr
;
3932 tree op1
= *op1_ptr
;
3933 int unsignedp0
, unsignedp1
;
3935 tree primop0
, primop1
;
3936 enum tree_code code
= *rescode_ptr
;
3937 location_t loc
= EXPR_LOC_OR_HERE (op0
);
3939 /* Throw away any conversions to wider types
3940 already present in the operands. */
3942 primop0
= c_common_get_narrower (op0
, &unsignedp0
);
3943 primop1
= c_common_get_narrower (op1
, &unsignedp1
);
3945 /* If primopN is first sign-extended from primopN's precision to opN's
3946 precision, then zero-extended from opN's precision to
3947 *restype_ptr precision, shortenings might be invalid. */
3948 if (TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (TREE_TYPE (op0
))
3949 && TYPE_PRECISION (TREE_TYPE (op0
)) < TYPE_PRECISION (*restype_ptr
)
3951 && TYPE_UNSIGNED (TREE_TYPE (op0
)))
3953 if (TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (TREE_TYPE (op1
))
3954 && TYPE_PRECISION (TREE_TYPE (op1
)) < TYPE_PRECISION (*restype_ptr
)
3956 && TYPE_UNSIGNED (TREE_TYPE (op1
)))
3959 /* Handle the case that OP0 does not *contain* a conversion
3960 but it *requires* conversion to FINAL_TYPE. */
3962 if (op0
== primop0
&& TREE_TYPE (op0
) != *restype_ptr
)
3963 unsignedp0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
3964 if (op1
== primop1
&& TREE_TYPE (op1
) != *restype_ptr
)
3965 unsignedp1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
3967 /* If one of the operands must be floated, we cannot optimize. */
3968 real1
= TREE_CODE (TREE_TYPE (primop0
)) == REAL_TYPE
;
3969 real2
= TREE_CODE (TREE_TYPE (primop1
)) == REAL_TYPE
;
3971 /* If first arg is constant, swap the args (changing operation
3972 so value is preserved), for canonicalization. Don't do this if
3973 the second arg is 0. */
3975 if (TREE_CONSTANT (primop0
)
3976 && !integer_zerop (primop1
) && !real_zerop (primop1
)
3977 && !fixed_zerop (primop1
))
3980 int temi
= unsignedp0
;
3988 unsignedp0
= unsignedp1
;
4011 *rescode_ptr
= code
;
4014 /* If comparing an integer against a constant more bits wide,
4015 maybe we can deduce a value of 1 or 0 independent of the data.
4016 Or else truncate the constant now
4017 rather than extend the variable at run time.
4019 This is only interesting if the constant is the wider arg.
4020 Also, it is not safe if the constant is unsigned and the
4021 variable arg is signed, since in this case the variable
4022 would be sign-extended and then regarded as unsigned.
4023 Our technique fails in this case because the lowest/highest
4024 possible unsigned results don't follow naturally from the
4025 lowest/highest possible values of the variable operand.
4026 For just EQ_EXPR and NE_EXPR there is another technique that
4027 could be used: see if the constant can be faithfully represented
4028 in the other operand's type, by truncating it and reextending it
4029 and see if that preserves the constant's value. */
4031 if (!real1
&& !real2
4032 && TREE_CODE (TREE_TYPE (primop0
)) != FIXED_POINT_TYPE
4033 && TREE_CODE (primop1
) == INTEGER_CST
4034 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
))
4036 int min_gt
, max_gt
, min_lt
, max_lt
;
4037 tree maxval
, minval
;
4038 /* 1 if comparison is nominally unsigned. */
4039 int unsignedp
= TYPE_UNSIGNED (*restype_ptr
);
4042 type
= c_common_signed_or_unsigned_type (unsignedp0
,
4043 TREE_TYPE (primop0
));
4045 maxval
= TYPE_MAX_VALUE (type
);
4046 minval
= TYPE_MIN_VALUE (type
);
4048 if (unsignedp
&& !unsignedp0
)
4049 *restype_ptr
= c_common_signed_type (*restype_ptr
);
4051 if (TREE_TYPE (primop1
) != *restype_ptr
)
4053 /* Convert primop1 to target type, but do not introduce
4054 additional overflow. We know primop1 is an int_cst. */
4055 primop1
= force_fit_type_double (*restype_ptr
,
4056 tree_to_double_int (primop1
),
4057 0, TREE_OVERFLOW (primop1
));
4059 if (type
!= *restype_ptr
)
4061 minval
= convert (*restype_ptr
, minval
);
4062 maxval
= convert (*restype_ptr
, maxval
);
4065 if (unsignedp
&& unsignedp0
)
4067 min_gt
= INT_CST_LT_UNSIGNED (primop1
, minval
);
4068 max_gt
= INT_CST_LT_UNSIGNED (primop1
, maxval
);
4069 min_lt
= INT_CST_LT_UNSIGNED (minval
, primop1
);
4070 max_lt
= INT_CST_LT_UNSIGNED (maxval
, primop1
);
4074 min_gt
= INT_CST_LT (primop1
, minval
);
4075 max_gt
= INT_CST_LT (primop1
, maxval
);
4076 min_lt
= INT_CST_LT (minval
, primop1
);
4077 max_lt
= INT_CST_LT (maxval
, primop1
);
4081 /* This used to be a switch, but Genix compiler can't handle that. */
4082 if (code
== NE_EXPR
)
4084 if (max_lt
|| min_gt
)
4085 val
= truthvalue_true_node
;
4087 else if (code
== EQ_EXPR
)
4089 if (max_lt
|| min_gt
)
4090 val
= truthvalue_false_node
;
4092 else if (code
== LT_EXPR
)
4095 val
= truthvalue_true_node
;
4097 val
= truthvalue_false_node
;
4099 else if (code
== GT_EXPR
)
4102 val
= truthvalue_true_node
;
4104 val
= truthvalue_false_node
;
4106 else if (code
== LE_EXPR
)
4109 val
= truthvalue_true_node
;
4111 val
= truthvalue_false_node
;
4113 else if (code
== GE_EXPR
)
4116 val
= truthvalue_true_node
;
4118 val
= truthvalue_false_node
;
4121 /* If primop0 was sign-extended and unsigned comparison specd,
4122 we did a signed comparison above using the signed type bounds.
4123 But the comparison we output must be unsigned.
4125 Also, for inequalities, VAL is no good; but if the signed
4126 comparison had *any* fixed result, it follows that the
4127 unsigned comparison just tests the sign in reverse
4128 (positive values are LE, negative ones GE).
4129 So we can generate an unsigned comparison
4130 against an extreme value of the signed type. */
4132 if (unsignedp
&& !unsignedp0
)
4139 primop1
= TYPE_MIN_VALUE (type
);
4145 primop1
= TYPE_MAX_VALUE (type
);
4152 type
= c_common_unsigned_type (type
);
4155 if (TREE_CODE (primop0
) != INTEGER_CST
4156 && c_inhibit_evaluation_warnings
== 0)
4158 if (val
== truthvalue_false_node
)
4159 warning_at (loc
, OPT_Wtype_limits
,
4160 "comparison is always false due to limited range of data type");
4161 if (val
== truthvalue_true_node
)
4162 warning_at (loc
, OPT_Wtype_limits
,
4163 "comparison is always true due to limited range of data type");
4168 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4169 if (TREE_SIDE_EFFECTS (primop0
))
4170 return build2 (COMPOUND_EXPR
, TREE_TYPE (val
), primop0
, val
);
4174 /* Value is not predetermined, but do the comparison
4175 in the type of the operand that is not constant.
4176 TYPE is already properly set. */
4179 /* If either arg is decimal float and the other is float, find the
4180 proper common type to use for comparison. */
4181 else if (real1
&& real2
4182 && (DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0
)))
4183 || DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1
)))))
4184 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
4186 else if (real1
&& real2
4187 && (TYPE_PRECISION (TREE_TYPE (primop0
))
4188 == TYPE_PRECISION (TREE_TYPE (primop1
))))
4189 type
= TREE_TYPE (primop0
);
4191 /* If args' natural types are both narrower than nominal type
4192 and both extend in the same manner, compare them
4193 in the type of the wider arg.
4194 Otherwise must actually extend both to the nominal
4195 common type lest different ways of extending
4197 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
4199 else if (unsignedp0
== unsignedp1
&& real1
== real2
4200 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
)
4201 && TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (*restype_ptr
))
4203 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
4204 type
= c_common_signed_or_unsigned_type (unsignedp0
4205 || TYPE_UNSIGNED (*restype_ptr
),
4207 /* Make sure shorter operand is extended the right way
4208 to match the longer operand. */
4210 = convert (c_common_signed_or_unsigned_type (unsignedp0
,
4211 TREE_TYPE (primop0
)),
4214 = convert (c_common_signed_or_unsigned_type (unsignedp1
,
4215 TREE_TYPE (primop1
)),
4220 /* Here we must do the comparison on the nominal type
4221 using the args exactly as we received them. */
4222 type
= *restype_ptr
;
4226 if (!real1
&& !real2
&& integer_zerop (primop1
)
4227 && TYPE_UNSIGNED (*restype_ptr
))
4230 /* All unsigned values are >= 0, so we warn. However,
4231 if OP0 is a constant that is >= 0, the signedness of
4232 the comparison isn't an issue, so suppress the
4235 warn_type_limits
&& !in_system_header
4236 && c_inhibit_evaluation_warnings
== 0
4237 && !(TREE_CODE (primop0
) == INTEGER_CST
4238 && !TREE_OVERFLOW (convert (c_common_signed_type (type
),
4240 /* Do not warn for enumeration types. */
4241 && (TREE_CODE (expr_original_type (primop0
)) != ENUMERAL_TYPE
);
4247 warning_at (loc
, OPT_Wtype_limits
,
4248 "comparison of unsigned expression >= 0 is always true");
4249 value
= truthvalue_true_node
;
4254 warning_at (loc
, OPT_Wtype_limits
,
4255 "comparison of unsigned expression < 0 is always false");
4256 value
= truthvalue_false_node
;
4265 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4266 if (TREE_SIDE_EFFECTS (primop0
))
4267 return build2 (COMPOUND_EXPR
, TREE_TYPE (value
),
4274 *op0_ptr
= convert (type
, primop0
);
4275 *op1_ptr
= convert (type
, primop1
);
4277 *restype_ptr
= truthvalue_type_node
;
4282 /* Return a tree for the sum or difference (RESULTCODE says which)
4283 of pointer PTROP and integer INTOP. */
4286 pointer_int_sum (location_t loc
, enum tree_code resultcode
,
4287 tree ptrop
, tree intop
)
4291 /* The result is a pointer of the same type that is being added. */
4292 tree result_type
= TREE_TYPE (ptrop
);
4294 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
4296 pedwarn (loc
, OPT_Wpointer_arith
,
4297 "pointer of type %<void *%> used in arithmetic");
4298 size_exp
= integer_one_node
;
4300 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
4302 pedwarn (loc
, OPT_Wpointer_arith
,
4303 "pointer to a function used in arithmetic");
4304 size_exp
= integer_one_node
;
4307 size_exp
= size_in_bytes (TREE_TYPE (result_type
));
4309 /* We are manipulating pointer values, so we don't need to warn
4310 about relying on undefined signed overflow. We disable the
4311 warning here because we use integer types so fold won't know that
4312 they are really pointers. */
4313 fold_defer_overflow_warnings ();
4315 /* If what we are about to multiply by the size of the elements
4316 contains a constant term, apply distributive law
4317 and multiply that constant term separately.
4318 This helps produce common subexpressions. */
4319 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
4320 && !TREE_CONSTANT (intop
)
4321 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
4322 && TREE_CONSTANT (size_exp
)
4323 /* If the constant comes from pointer subtraction,
4324 skip this optimization--it would cause an error. */
4325 && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop
, 0))) == INTEGER_TYPE
4326 /* If the constant is unsigned, and smaller than the pointer size,
4327 then we must skip this optimization. This is because it could cause
4328 an overflow error if the constant is negative but INTOP is not. */
4329 && (!TYPE_UNSIGNED (TREE_TYPE (intop
))
4330 || (TYPE_PRECISION (TREE_TYPE (intop
))
4331 == TYPE_PRECISION (TREE_TYPE (ptrop
)))))
4333 enum tree_code subcode
= resultcode
;
4334 tree int_type
= TREE_TYPE (intop
);
4335 if (TREE_CODE (intop
) == MINUS_EXPR
)
4336 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
4337 /* Convert both subexpression types to the type of intop,
4338 because weird cases involving pointer arithmetic
4339 can result in a sum or difference with different type args. */
4340 ptrop
= build_binary_op (EXPR_LOCATION (TREE_OPERAND (intop
, 1)),
4342 convert (int_type
, TREE_OPERAND (intop
, 1)), 1);
4343 intop
= convert (int_type
, TREE_OPERAND (intop
, 0));
4346 /* Convert the integer argument to a type the same size as sizetype
4347 so the multiply won't overflow spuriously. */
4348 if (TYPE_PRECISION (TREE_TYPE (intop
)) != TYPE_PRECISION (sizetype
)
4349 || TYPE_UNSIGNED (TREE_TYPE (intop
)) != TYPE_UNSIGNED (sizetype
))
4350 intop
= convert (c_common_type_for_size (TYPE_PRECISION (sizetype
),
4351 TYPE_UNSIGNED (sizetype
)), intop
);
4353 /* Replace the integer argument with a suitable product by the object size.
4354 Do this multiplication as signed, then convert to the appropriate type
4355 for the pointer operation and disregard an overflow that occurred only
4356 because of the sign-extension change in the latter conversion. */
4358 tree t
= build_binary_op (loc
,
4360 convert (TREE_TYPE (intop
), size_exp
), 1);
4361 intop
= convert (sizetype
, t
);
4362 if (TREE_OVERFLOW_P (intop
) && !TREE_OVERFLOW (t
))
4363 intop
= build_int_cst_wide (TREE_TYPE (intop
), TREE_INT_CST_LOW (intop
),
4364 TREE_INT_CST_HIGH (intop
));
4367 /* Create the sum or difference. */
4368 if (resultcode
== MINUS_EXPR
)
4369 intop
= fold_build1_loc (loc
, NEGATE_EXPR
, sizetype
, intop
);
4371 ret
= fold_build_pointer_plus_loc (loc
, ptrop
, intop
);
4373 fold_undefer_and_ignore_overflow_warnings ();
4378 /* Wrap a C_MAYBE_CONST_EXPR around an expression that is fully folded
4379 and if NON_CONST is known not to be permitted in an evaluated part
4380 of a constant expression. */
4383 c_wrap_maybe_const (tree expr
, bool non_const
)
4385 bool nowarning
= TREE_NO_WARNING (expr
);
4386 location_t loc
= EXPR_LOCATION (expr
);
4388 /* This should never be called for C++. */
4389 if (c_dialect_cxx ())
4392 /* The result of folding may have a NOP_EXPR to set TREE_NO_WARNING. */
4393 STRIP_TYPE_NOPS (expr
);
4394 expr
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (expr
), NULL
, expr
);
4395 C_MAYBE_CONST_EXPR_NON_CONST (expr
) = non_const
;
4397 TREE_NO_WARNING (expr
) = 1;
4398 protected_set_expr_location (expr
, loc
);
4403 /* Wrap a SAVE_EXPR around EXPR, if appropriate. Like save_expr, but
4404 for C folds the inside expression and wraps a C_MAYBE_CONST_EXPR
4405 around the SAVE_EXPR if needed so that c_fully_fold does not need
4406 to look inside SAVE_EXPRs. */
4409 c_save_expr (tree expr
)
4411 bool maybe_const
= true;
4412 if (c_dialect_cxx ())
4413 return save_expr (expr
);
4414 expr
= c_fully_fold (expr
, false, &maybe_const
);
4415 expr
= save_expr (expr
);
4417 expr
= c_wrap_maybe_const (expr
, true);
4421 /* Return whether EXPR is a declaration whose address can never be
4425 decl_with_nonnull_addr_p (const_tree expr
)
4427 return (DECL_P (expr
)
4428 && (TREE_CODE (expr
) == PARM_DECL
4429 || TREE_CODE (expr
) == LABEL_DECL
4430 || !DECL_WEAK (expr
)));
4433 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
4434 or for an `if' or `while' statement or ?..: exp. It should already
4435 have been validated to be of suitable type; otherwise, a bad
4436 diagnostic may result.
4438 The EXPR is located at LOCATION.
4440 This preparation consists of taking the ordinary
4441 representation of an expression expr and producing a valid tree
4442 boolean expression describing whether expr is nonzero. We could
4443 simply always do build_binary_op (NE_EXPR, expr, truthvalue_false_node, 1),
4444 but we optimize comparisons, &&, ||, and !.
4446 The resulting type should always be `truthvalue_type_node'. */
4449 c_common_truthvalue_conversion (location_t location
, tree expr
)
4451 switch (TREE_CODE (expr
))
4453 case EQ_EXPR
: case NE_EXPR
: case UNEQ_EXPR
: case LTGT_EXPR
:
4454 case LE_EXPR
: case GE_EXPR
: case LT_EXPR
: case GT_EXPR
:
4455 case UNLE_EXPR
: case UNGE_EXPR
: case UNLT_EXPR
: case UNGT_EXPR
:
4456 case ORDERED_EXPR
: case UNORDERED_EXPR
:
4457 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4459 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4460 TREE_OPERAND (expr
, 0), TREE_OPERAND (expr
, 1));
4463 case TRUTH_ANDIF_EXPR
:
4464 case TRUTH_ORIF_EXPR
:
4465 case TRUTH_AND_EXPR
:
4467 case TRUTH_XOR_EXPR
:
4468 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4470 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4471 c_common_truthvalue_conversion (location
,
4472 TREE_OPERAND (expr
, 0)),
4473 c_common_truthvalue_conversion (location
,
4474 TREE_OPERAND (expr
, 1)));
4477 case TRUTH_NOT_EXPR
:
4478 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4480 expr
= build1 (TREE_CODE (expr
), truthvalue_type_node
,
4481 c_common_truthvalue_conversion (location
,
4482 TREE_OPERAND (expr
, 0)));
4489 return integer_zerop (expr
) ? truthvalue_false_node
4490 : truthvalue_true_node
;
4493 return real_compare (NE_EXPR
, &TREE_REAL_CST (expr
), &dconst0
)
4494 ? truthvalue_true_node
4495 : truthvalue_false_node
;
4498 return fixed_compare (NE_EXPR
, &TREE_FIXED_CST (expr
),
4499 &FCONST0 (TYPE_MODE (TREE_TYPE (expr
))))
4500 ? truthvalue_true_node
4501 : truthvalue_false_node
;
4504 expr
= build_unary_op (location
, ADDR_EXPR
, expr
, 0);
4509 tree inner
= TREE_OPERAND (expr
, 0);
4510 if (decl_with_nonnull_addr_p (inner
))
4512 /* Common Ada/Pascal programmer's mistake. */
4513 warning_at (location
,
4515 "the address of %qD will always evaluate as %<true%>",
4517 return truthvalue_true_node
;
4523 expr
= build_binary_op (EXPR_LOCATION (expr
),
4524 (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1))
4525 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4526 c_common_truthvalue_conversion (location
,
4527 TREE_OPERAND (expr
, 0)),
4528 c_common_truthvalue_conversion (location
,
4529 TREE_OPERAND (expr
, 1)),
4536 case EXCESS_PRECISION_EXPR
:
4537 /* These don't change whether an object is nonzero or zero. */
4538 return c_common_truthvalue_conversion (location
, TREE_OPERAND (expr
, 0));
4542 /* These don't change whether an object is zero or nonzero, but
4543 we can't ignore them if their second arg has side-effects. */
4544 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1)))
4546 expr
= build2 (COMPOUND_EXPR
, truthvalue_type_node
,
4547 TREE_OPERAND (expr
, 1),
4548 c_common_truthvalue_conversion
4549 (location
, TREE_OPERAND (expr
, 0)));
4553 return c_common_truthvalue_conversion (location
,
4554 TREE_OPERAND (expr
, 0));
4557 /* Distribute the conversion into the arms of a COND_EXPR. */
4558 if (c_dialect_cxx ())
4560 tree op1
= TREE_OPERAND (expr
, 1);
4561 tree op2
= TREE_OPERAND (expr
, 2);
4562 /* In C++ one of the arms might have void type if it is throw. */
4563 if (!VOID_TYPE_P (TREE_TYPE (op1
)))
4564 op1
= c_common_truthvalue_conversion (location
, op1
);
4565 if (!VOID_TYPE_P (TREE_TYPE (op2
)))
4566 op2
= c_common_truthvalue_conversion (location
, op2
);
4567 expr
= fold_build3_loc (location
, COND_EXPR
, truthvalue_type_node
,
4568 TREE_OPERAND (expr
, 0), op1
, op2
);
4573 /* Folding will happen later for C. */
4574 expr
= build3 (COND_EXPR
, truthvalue_type_node
,
4575 TREE_OPERAND (expr
, 0),
4576 c_common_truthvalue_conversion (location
,
4577 TREE_OPERAND (expr
, 1)),
4578 c_common_truthvalue_conversion (location
,
4579 TREE_OPERAND (expr
, 2)));
4585 tree totype
= TREE_TYPE (expr
);
4586 tree fromtype
= TREE_TYPE (TREE_OPERAND (expr
, 0));
4588 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
4589 since that affects how `default_conversion' will behave. */
4590 if (TREE_CODE (totype
) == REFERENCE_TYPE
4591 || TREE_CODE (fromtype
) == REFERENCE_TYPE
)
4593 /* Don't strip a conversion from C++0x scoped enum, since they
4594 don't implicitly convert to other types. */
4595 if (TREE_CODE (fromtype
) == ENUMERAL_TYPE
4596 && ENUM_IS_SCOPED (fromtype
))
4598 /* If this isn't narrowing the argument, we can ignore it. */
4599 if (TYPE_PRECISION (totype
) >= TYPE_PRECISION (fromtype
))
4600 return c_common_truthvalue_conversion (location
,
4601 TREE_OPERAND (expr
, 0));
4606 if (!TREE_NO_WARNING (expr
)
4607 && warn_parentheses
)
4609 warning (OPT_Wparentheses
,
4610 "suggest parentheses around assignment used as truth value");
4611 TREE_NO_WARNING (expr
) = 1;
4619 if (TREE_CODE (TREE_TYPE (expr
)) == COMPLEX_TYPE
)
4621 tree t
= (in_late_binary_op
? save_expr (expr
) : c_save_expr (expr
));
4622 expr
= (build_binary_op
4623 (EXPR_LOCATION (expr
),
4624 (TREE_SIDE_EFFECTS (expr
)
4625 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4626 c_common_truthvalue_conversion
4628 build_unary_op (location
, REALPART_EXPR
, t
, 0)),
4629 c_common_truthvalue_conversion
4631 build_unary_op (location
, IMAGPART_EXPR
, t
, 0)),
4636 if (TREE_CODE (TREE_TYPE (expr
)) == FIXED_POINT_TYPE
)
4638 tree fixed_zero_node
= build_fixed (TREE_TYPE (expr
),
4640 (TREE_TYPE (expr
))));
4641 return build_binary_op (location
, NE_EXPR
, expr
, fixed_zero_node
, 1);
4644 return build_binary_op (location
, NE_EXPR
, expr
, integer_zero_node
, 1);
4647 protected_set_expr_location (expr
, location
);
4651 static void def_builtin_1 (enum built_in_function fncode
,
4653 enum built_in_class fnclass
,
4654 tree fntype
, tree libtype
,
4655 bool both_p
, bool fallback_p
, bool nonansi_p
,
4656 tree fnattrs
, bool implicit_p
);
4659 /* Apply the TYPE_QUALS to the new DECL. */
4662 c_apply_type_quals_to_decl (int type_quals
, tree decl
)
4664 tree type
= TREE_TYPE (decl
);
4666 if (type
== error_mark_node
)
4669 if ((type_quals
& TYPE_QUAL_CONST
)
4670 || (type
&& TREE_CODE (type
) == REFERENCE_TYPE
))
4671 /* We used to check TYPE_NEEDS_CONSTRUCTING here, but now a constexpr
4672 constructor can produce constant init, so rely on cp_finish_decl to
4673 clear TREE_READONLY if the variable has non-constant init. */
4674 TREE_READONLY (decl
) = 1;
4675 if (type_quals
& TYPE_QUAL_VOLATILE
)
4677 TREE_SIDE_EFFECTS (decl
) = 1;
4678 TREE_THIS_VOLATILE (decl
) = 1;
4680 if (type_quals
& TYPE_QUAL_RESTRICT
)
4682 while (type
&& TREE_CODE (type
) == ARRAY_TYPE
)
4683 /* Allow 'restrict' on arrays of pointers.
4684 FIXME currently we just ignore it. */
4685 type
= TREE_TYPE (type
);
4687 || !POINTER_TYPE_P (type
)
4688 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type
)))
4689 error ("invalid use of %<restrict%>");
4693 /* Hash function for the problem of multiple type definitions in
4694 different files. This must hash all types that will compare
4695 equal via comptypes to the same value. In practice it hashes
4696 on some of the simple stuff and leaves the details to comptypes. */
4699 c_type_hash (const void *p
)
4703 const_tree
const t
= (const_tree
) p
;
4705 switch (TREE_CODE (t
))
4707 /* For pointers, hash on pointee type plus some swizzling. */
4709 return c_type_hash (TREE_TYPE (t
)) ^ 0x3003003;
4710 /* Hash on number of elements and total size. */
4713 t2
= TYPE_VALUES (t
);
4717 t2
= TYPE_FIELDS (t
);
4719 case QUAL_UNION_TYPE
:
4721 t2
= TYPE_FIELDS (t
);
4725 t2
= TYPE_FIELDS (t
);
4730 /* FIXME: We want to use a DECL_CHAIN iteration method here, but
4731 TYPE_VALUES of ENUMERAL_TYPEs is stored as a TREE_LIST. */
4732 n_elements
= list_length (t2
);
4733 /* We might have a VLA here. */
4734 if (TREE_CODE (TYPE_SIZE (t
)) != INTEGER_CST
)
4737 size
= TREE_INT_CST_LOW (TYPE_SIZE (t
));
4738 return ((size
<< 24) | (n_elements
<< shift
));
4741 static GTY((param_is (union tree_node
))) htab_t type_hash_table
;
4743 /* Return the typed-based alias set for T, which may be an expression
4744 or a type. Return -1 if we don't do anything special. */
4747 c_common_get_alias_set (tree t
)
4752 /* For VLAs, use the alias set of the element type rather than the
4753 default of alias set 0 for types compared structurally. */
4754 if (TYPE_P (t
) && TYPE_STRUCTURAL_EQUALITY_P (t
))
4756 if (TREE_CODE (t
) == ARRAY_TYPE
)
4757 return get_alias_set (TREE_TYPE (t
));
4761 /* Permit type-punning when accessing a union, provided the access
4762 is directly through the union. For example, this code does not
4763 permit taking the address of a union member and then storing
4764 through it. Even the type-punning allowed here is a GCC
4765 extension, albeit a common and useful one; the C standard says
4766 that such accesses have implementation-defined behavior. */
4768 TREE_CODE (u
) == COMPONENT_REF
|| TREE_CODE (u
) == ARRAY_REF
;
4769 u
= TREE_OPERAND (u
, 0))
4770 if (TREE_CODE (u
) == COMPONENT_REF
4771 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u
, 0))) == UNION_TYPE
)
4774 /* That's all the expressions we handle specially. */
4778 /* The C standard guarantees that any object may be accessed via an
4779 lvalue that has character type. */
4780 if (t
== char_type_node
4781 || t
== signed_char_type_node
4782 || t
== unsigned_char_type_node
)
4785 /* The C standard specifically allows aliasing between signed and
4786 unsigned variants of the same type. We treat the signed
4787 variant as canonical. */
4788 if (TREE_CODE (t
) == INTEGER_TYPE
&& TYPE_UNSIGNED (t
))
4790 tree t1
= c_common_signed_type (t
);
4792 /* t1 == t can happen for boolean nodes which are always unsigned. */
4794 return get_alias_set (t1
);
4797 /* Handle the case of multiple type nodes referring to "the same" type,
4798 which occurs with IMA. These share an alias set. FIXME: Currently only
4799 C90 is handled. (In C99 type compatibility is not transitive, which
4800 complicates things mightily. The alias set splay trees can theoretically
4801 represent this, but insertion is tricky when you consider all the
4802 different orders things might arrive in.) */
4804 if (c_language
!= clk_c
|| flag_isoc99
)
4807 /* Save time if there's only one input file. */
4808 if (num_in_fnames
== 1)
4811 /* Pointers need special handling if they point to any type that
4812 needs special handling (below). */
4813 if (TREE_CODE (t
) == POINTER_TYPE
)
4816 /* Find bottom type under any nested POINTERs. */
4817 for (t2
= TREE_TYPE (t
);
4818 TREE_CODE (t2
) == POINTER_TYPE
;
4819 t2
= TREE_TYPE (t2
))
4821 if (TREE_CODE (t2
) != RECORD_TYPE
4822 && TREE_CODE (t2
) != ENUMERAL_TYPE
4823 && TREE_CODE (t2
) != QUAL_UNION_TYPE
4824 && TREE_CODE (t2
) != UNION_TYPE
)
4826 if (TYPE_SIZE (t2
) == 0)
4829 /* These are the only cases that need special handling. */
4830 if (TREE_CODE (t
) != RECORD_TYPE
4831 && TREE_CODE (t
) != ENUMERAL_TYPE
4832 && TREE_CODE (t
) != QUAL_UNION_TYPE
4833 && TREE_CODE (t
) != UNION_TYPE
4834 && TREE_CODE (t
) != POINTER_TYPE
)
4837 if (TYPE_SIZE (t
) == 0)
4840 /* Look up t in hash table. Only one of the compatible types within each
4841 alias set is recorded in the table. */
4842 if (!type_hash_table
)
4843 type_hash_table
= htab_create_ggc (1021, c_type_hash
,
4844 (htab_eq
) lang_hooks
.types_compatible_p
,
4846 slot
= htab_find_slot (type_hash_table
, t
, INSERT
);
4849 TYPE_ALIAS_SET (t
) = TYPE_ALIAS_SET ((tree
)*slot
);
4850 return TYPE_ALIAS_SET ((tree
)*slot
);
4853 /* Our caller will assign and record (in t) a new alias set; all we need
4854 to do is remember t in the hash table. */
4860 /* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where
4861 the second parameter indicates which OPERATOR is being applied.
4862 The COMPLAIN flag controls whether we should diagnose possibly
4863 ill-formed constructs or not. LOC is the location of the SIZEOF or
4867 c_sizeof_or_alignof_type (location_t loc
,
4868 tree type
, bool is_sizeof
, int complain
)
4870 const char *op_name
;
4872 enum tree_code type_code
= TREE_CODE (type
);
4874 op_name
= is_sizeof
? "sizeof" : "__alignof__";
4876 if (type_code
== FUNCTION_TYPE
)
4880 if (complain
&& warn_pointer_arith
)
4881 pedwarn (loc
, OPT_Wpointer_arith
,
4882 "invalid application of %<sizeof%> to a function type");
4884 return error_mark_node
;
4885 value
= size_one_node
;
4891 if (c_dialect_cxx ())
4892 pedwarn (loc
, OPT_Wpedantic
, "ISO C++ does not permit "
4893 "%<alignof%> applied to a function type");
4895 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not permit "
4896 "%<_Alignof%> applied to a function type");
4898 value
= size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
4901 else if (type_code
== VOID_TYPE
|| type_code
== ERROR_MARK
)
4903 if (type_code
== VOID_TYPE
4904 && complain
&& warn_pointer_arith
)
4905 pedwarn (loc
, OPT_Wpointer_arith
,
4906 "invalid application of %qs to a void type", op_name
);
4908 return error_mark_node
;
4909 value
= size_one_node
;
4911 else if (!COMPLETE_TYPE_P (type
)
4912 && (!c_dialect_cxx () || is_sizeof
|| type_code
!= ARRAY_TYPE
))
4915 error_at (loc
, "invalid application of %qs to incomplete type %qT",
4917 return error_mark_node
;
4919 else if (c_dialect_cxx () && type_code
== ARRAY_TYPE
4920 && !COMPLETE_TYPE_P (TREE_TYPE (type
)))
4923 error_at (loc
, "invalid application of %qs to array type %qT of "
4924 "incomplete element type", op_name
, type
);
4925 return error_mark_node
;
4930 /* Convert in case a char is more than one unit. */
4931 value
= size_binop_loc (loc
, CEIL_DIV_EXPR
, TYPE_SIZE_UNIT (type
),
4932 size_int (TYPE_PRECISION (char_type_node
)
4935 value
= size_int (TYPE_ALIGN_UNIT (type
));
4938 /* VALUE will have the middle-end integer type sizetype.
4939 However, we should really return a value of type `size_t',
4940 which is just a typedef for an ordinary integer type. */
4941 value
= fold_convert_loc (loc
, size_type_node
, value
);
4946 /* Implement the __alignof keyword: Return the minimum required
4947 alignment of EXPR, measured in bytes. For VAR_DECLs,
4948 FUNCTION_DECLs and FIELD_DECLs return DECL_ALIGN (which can be set
4949 from an "aligned" __attribute__ specification). LOC is the
4950 location of the ALIGNOF operator. */
4953 c_alignof_expr (location_t loc
, tree expr
)
4957 if (VAR_OR_FUNCTION_DECL_P (expr
))
4958 t
= size_int (DECL_ALIGN_UNIT (expr
));
4960 else if (TREE_CODE (expr
) == COMPONENT_REF
4961 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
, 1)))
4963 error_at (loc
, "%<__alignof%> applied to a bit-field");
4966 else if (TREE_CODE (expr
) == COMPONENT_REF
4967 && TREE_CODE (TREE_OPERAND (expr
, 1)) == FIELD_DECL
)
4968 t
= size_int (DECL_ALIGN_UNIT (TREE_OPERAND (expr
, 1)));
4970 else if (TREE_CODE (expr
) == INDIRECT_REF
)
4972 tree t
= TREE_OPERAND (expr
, 0);
4974 int bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
4976 while (CONVERT_EXPR_P (t
)
4977 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
4981 t
= TREE_OPERAND (t
, 0);
4982 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
4983 if (thisalign
> bestalign
)
4984 best
= t
, bestalign
= thisalign
;
4986 return c_alignof (loc
, TREE_TYPE (TREE_TYPE (best
)));
4989 return c_alignof (loc
, TREE_TYPE (expr
));
4991 return fold_convert_loc (loc
, size_type_node
, t
);
4994 /* Handle C and C++ default attributes. */
4996 enum built_in_attribute
4998 #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
4999 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
5000 #define DEF_ATTR_STRING(ENUM, VALUE) ENUM,
5001 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
5002 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
5003 #include "builtin-attrs.def"
5004 #undef DEF_ATTR_NULL_TREE
5006 #undef DEF_ATTR_STRING
5007 #undef DEF_ATTR_IDENT
5008 #undef DEF_ATTR_TREE_LIST
5012 static GTY(()) tree built_in_attributes
[(int) ATTR_LAST
];
5014 static void c_init_attributes (void);
5018 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
5019 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
5020 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
5021 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
5022 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
5023 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
5024 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
5025 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) NAME,
5026 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) NAME,
5027 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
5028 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
5029 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
5030 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
5031 #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
5032 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG6) \
5034 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
5035 #include "builtin-types.def"
5036 #undef DEF_PRIMITIVE_TYPE
5037 #undef DEF_FUNCTION_TYPE_0
5038 #undef DEF_FUNCTION_TYPE_1
5039 #undef DEF_FUNCTION_TYPE_2
5040 #undef DEF_FUNCTION_TYPE_3
5041 #undef DEF_FUNCTION_TYPE_4
5042 #undef DEF_FUNCTION_TYPE_5
5043 #undef DEF_FUNCTION_TYPE_6
5044 #undef DEF_FUNCTION_TYPE_7
5045 #undef DEF_FUNCTION_TYPE_VAR_0
5046 #undef DEF_FUNCTION_TYPE_VAR_1
5047 #undef DEF_FUNCTION_TYPE_VAR_2
5048 #undef DEF_FUNCTION_TYPE_VAR_3
5049 #undef DEF_FUNCTION_TYPE_VAR_4
5050 #undef DEF_FUNCTION_TYPE_VAR_5
5051 #undef DEF_POINTER_TYPE
5055 typedef enum c_builtin_type builtin_type
;
5057 /* A temporary array for c_common_nodes_and_builtins. Used in
5058 communication with def_fn_type. */
5059 static tree builtin_types
[(int) BT_LAST
+ 1];
5061 /* A helper function for c_common_nodes_and_builtins. Build function type
5062 for DEF with return type RET and N arguments. If VAR is true, then the
5063 function should be variadic after those N arguments.
5065 Takes special care not to ICE if any of the types involved are
5066 error_mark_node, which indicates that said type is not in fact available
5067 (see builtin_type_for_size). In which case the function type as a whole
5068 should be error_mark_node. */
5071 def_fn_type (builtin_type def
, builtin_type ret
, bool var
, int n
, ...)
5074 tree
*args
= XALLOCAVEC (tree
, n
);
5079 for (i
= 0; i
< n
; ++i
)
5081 builtin_type a
= (builtin_type
) va_arg (list
, int);
5082 t
= builtin_types
[a
];
5083 if (t
== error_mark_node
)
5088 t
= builtin_types
[ret
];
5089 if (t
== error_mark_node
)
5092 t
= build_varargs_function_type_array (t
, n
, args
);
5094 t
= build_function_type_array (t
, n
, args
);
5097 builtin_types
[def
] = t
;
5101 /* Build builtin functions common to both C and C++ language
5105 c_define_builtins (tree va_list_ref_type_node
, tree va_list_arg_type_node
)
5107 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
5108 builtin_types[ENUM] = VALUE;
5109 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
5110 def_fn_type (ENUM, RETURN, 0, 0);
5111 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
5112 def_fn_type (ENUM, RETURN, 0, 1, ARG1);
5113 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
5114 def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
5115 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
5116 def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
5117 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
5118 def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
5119 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5120 def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
5121 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5123 def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
5124 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5126 def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
5127 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
5128 def_fn_type (ENUM, RETURN, 1, 0);
5129 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
5130 def_fn_type (ENUM, RETURN, 1, 1, ARG1);
5131 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
5132 def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
5133 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
5134 def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
5135 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
5136 def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
5137 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5138 def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
5139 #define DEF_POINTER_TYPE(ENUM, TYPE) \
5140 builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
5142 #include "builtin-types.def"
5144 #undef DEF_PRIMITIVE_TYPE
5145 #undef DEF_FUNCTION_TYPE_1
5146 #undef DEF_FUNCTION_TYPE_2
5147 #undef DEF_FUNCTION_TYPE_3
5148 #undef DEF_FUNCTION_TYPE_4
5149 #undef DEF_FUNCTION_TYPE_5
5150 #undef DEF_FUNCTION_TYPE_6
5151 #undef DEF_FUNCTION_TYPE_VAR_0
5152 #undef DEF_FUNCTION_TYPE_VAR_1
5153 #undef DEF_FUNCTION_TYPE_VAR_2
5154 #undef DEF_FUNCTION_TYPE_VAR_3
5155 #undef DEF_FUNCTION_TYPE_VAR_4
5156 #undef DEF_FUNCTION_TYPE_VAR_5
5157 #undef DEF_POINTER_TYPE
5158 builtin_types
[(int) BT_LAST
] = NULL_TREE
;
5160 c_init_attributes ();
5162 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P, \
5163 NONANSI_P, ATTRS, IMPLICIT, COND) \
5165 def_builtin_1 (ENUM, NAME, CLASS, \
5166 builtin_types[(int) TYPE], \
5167 builtin_types[(int) LIBTYPE], \
5168 BOTH_P, FALLBACK_P, NONANSI_P, \
5169 built_in_attributes[(int) ATTRS], IMPLICIT);
5170 #include "builtins.def"
5173 targetm
.init_builtins ();
5175 build_common_builtin_nodes ();
5181 /* Like get_identifier, but avoid warnings about null arguments when
5182 the argument may be NULL for targets where GCC lacks stdint.h type
5186 c_get_ident (const char *id
)
5188 return get_identifier (id
);
5191 /* Build tree nodes and builtin functions common to both C and C++ language
5195 c_common_nodes_and_builtins (void)
5197 int char16_type_size
;
5198 int char32_type_size
;
5199 int wchar_type_size
;
5200 tree array_domain_type
;
5201 tree va_list_ref_type_node
;
5202 tree va_list_arg_type_node
;
5204 build_common_tree_nodes (flag_signed_char
, flag_short_double
);
5206 /* Define `int' and `char' first so that dbx will output them first. */
5207 record_builtin_type (RID_INT
, NULL
, integer_type_node
);
5208 record_builtin_type (RID_CHAR
, "char", char_type_node
);
5210 /* `signed' is the same as `int'. FIXME: the declarations of "signed",
5211 "unsigned long", "long long unsigned" and "unsigned short" were in C++
5212 but not C. Are the conditionals here needed? */
5213 if (c_dialect_cxx ())
5214 record_builtin_type (RID_SIGNED
, NULL
, integer_type_node
);
5215 record_builtin_type (RID_LONG
, "long int", long_integer_type_node
);
5216 record_builtin_type (RID_UNSIGNED
, "unsigned int", unsigned_type_node
);
5217 record_builtin_type (RID_MAX
, "long unsigned int",
5218 long_unsigned_type_node
);
5219 if (int128_integer_type_node
!= NULL_TREE
)
5221 record_builtin_type (RID_INT128
, "__int128",
5222 int128_integer_type_node
);
5223 record_builtin_type (RID_MAX
, "__int128 unsigned",
5224 int128_unsigned_type_node
);
5226 if (c_dialect_cxx ())
5227 record_builtin_type (RID_MAX
, "unsigned long", long_unsigned_type_node
);
5228 record_builtin_type (RID_MAX
, "long long int",
5229 long_long_integer_type_node
);
5230 record_builtin_type (RID_MAX
, "long long unsigned int",
5231 long_long_unsigned_type_node
);
5232 if (c_dialect_cxx ())
5233 record_builtin_type (RID_MAX
, "long long unsigned",
5234 long_long_unsigned_type_node
);
5235 record_builtin_type (RID_SHORT
, "short int", short_integer_type_node
);
5236 record_builtin_type (RID_MAX
, "short unsigned int",
5237 short_unsigned_type_node
);
5238 if (c_dialect_cxx ())
5239 record_builtin_type (RID_MAX
, "unsigned short",
5240 short_unsigned_type_node
);
5242 /* Define both `signed char' and `unsigned char'. */
5243 record_builtin_type (RID_MAX
, "signed char", signed_char_type_node
);
5244 record_builtin_type (RID_MAX
, "unsigned char", unsigned_char_type_node
);
5246 /* These are types that c_common_type_for_size and
5247 c_common_type_for_mode use. */
5248 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5249 TYPE_DECL
, NULL_TREE
,
5251 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5252 TYPE_DECL
, NULL_TREE
,
5254 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5255 TYPE_DECL
, NULL_TREE
,
5257 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5258 TYPE_DECL
, NULL_TREE
,
5260 #if HOST_BITS_PER_WIDE_INT >= 64
5261 if (targetm
.scalar_mode_supported_p (TImode
))
5262 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5264 get_identifier ("__int128_t"),
5267 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5268 TYPE_DECL
, NULL_TREE
,
5269 unsigned_intQI_type_node
));
5270 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5271 TYPE_DECL
, NULL_TREE
,
5272 unsigned_intHI_type_node
));
5273 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5274 TYPE_DECL
, NULL_TREE
,
5275 unsigned_intSI_type_node
));
5276 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5277 TYPE_DECL
, NULL_TREE
,
5278 unsigned_intDI_type_node
));
5279 #if HOST_BITS_PER_WIDE_INT >= 64
5280 if (targetm
.scalar_mode_supported_p (TImode
))
5281 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5283 get_identifier ("__uint128_t"),
5284 unsigned_intTI_type_node
));
5287 /* Create the widest literal types. */
5288 widest_integer_literal_type_node
5289 = make_signed_type (HOST_BITS_PER_WIDE_INT
* 2);
5290 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5291 TYPE_DECL
, NULL_TREE
,
5292 widest_integer_literal_type_node
));
5294 widest_unsigned_literal_type_node
5295 = make_unsigned_type (HOST_BITS_PER_WIDE_INT
* 2);
5296 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5297 TYPE_DECL
, NULL_TREE
,
5298 widest_unsigned_literal_type_node
));
5300 signed_size_type_node
= c_common_signed_type (size_type_node
);
5303 TREE_TYPE (identifier_global_value (get_identifier (PID_TYPE
)));
5305 record_builtin_type (RID_FLOAT
, NULL
, float_type_node
);
5306 record_builtin_type (RID_DOUBLE
, NULL
, double_type_node
);
5307 record_builtin_type (RID_MAX
, "long double", long_double_type_node
);
5309 /* Only supported decimal floating point extension if the target
5310 actually supports underlying modes. */
5311 if (targetm
.scalar_mode_supported_p (SDmode
)
5312 && targetm
.scalar_mode_supported_p (DDmode
)
5313 && targetm
.scalar_mode_supported_p (TDmode
))
5315 record_builtin_type (RID_DFLOAT32
, NULL
, dfloat32_type_node
);
5316 record_builtin_type (RID_DFLOAT64
, NULL
, dfloat64_type_node
);
5317 record_builtin_type (RID_DFLOAT128
, NULL
, dfloat128_type_node
);
5320 if (targetm
.fixed_point_supported_p ())
5322 record_builtin_type (RID_MAX
, "short _Fract", short_fract_type_node
);
5323 record_builtin_type (RID_FRACT
, NULL
, fract_type_node
);
5324 record_builtin_type (RID_MAX
, "long _Fract", long_fract_type_node
);
5325 record_builtin_type (RID_MAX
, "long long _Fract",
5326 long_long_fract_type_node
);
5327 record_builtin_type (RID_MAX
, "unsigned short _Fract",
5328 unsigned_short_fract_type_node
);
5329 record_builtin_type (RID_MAX
, "unsigned _Fract",
5330 unsigned_fract_type_node
);
5331 record_builtin_type (RID_MAX
, "unsigned long _Fract",
5332 unsigned_long_fract_type_node
);
5333 record_builtin_type (RID_MAX
, "unsigned long long _Fract",
5334 unsigned_long_long_fract_type_node
);
5335 record_builtin_type (RID_MAX
, "_Sat short _Fract",
5336 sat_short_fract_type_node
);
5337 record_builtin_type (RID_MAX
, "_Sat _Fract", sat_fract_type_node
);
5338 record_builtin_type (RID_MAX
, "_Sat long _Fract",
5339 sat_long_fract_type_node
);
5340 record_builtin_type (RID_MAX
, "_Sat long long _Fract",
5341 sat_long_long_fract_type_node
);
5342 record_builtin_type (RID_MAX
, "_Sat unsigned short _Fract",
5343 sat_unsigned_short_fract_type_node
);
5344 record_builtin_type (RID_MAX
, "_Sat unsigned _Fract",
5345 sat_unsigned_fract_type_node
);
5346 record_builtin_type (RID_MAX
, "_Sat unsigned long _Fract",
5347 sat_unsigned_long_fract_type_node
);
5348 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Fract",
5349 sat_unsigned_long_long_fract_type_node
);
5350 record_builtin_type (RID_MAX
, "short _Accum", short_accum_type_node
);
5351 record_builtin_type (RID_ACCUM
, NULL
, accum_type_node
);
5352 record_builtin_type (RID_MAX
, "long _Accum", long_accum_type_node
);
5353 record_builtin_type (RID_MAX
, "long long _Accum",
5354 long_long_accum_type_node
);
5355 record_builtin_type (RID_MAX
, "unsigned short _Accum",
5356 unsigned_short_accum_type_node
);
5357 record_builtin_type (RID_MAX
, "unsigned _Accum",
5358 unsigned_accum_type_node
);
5359 record_builtin_type (RID_MAX
, "unsigned long _Accum",
5360 unsigned_long_accum_type_node
);
5361 record_builtin_type (RID_MAX
, "unsigned long long _Accum",
5362 unsigned_long_long_accum_type_node
);
5363 record_builtin_type (RID_MAX
, "_Sat short _Accum",
5364 sat_short_accum_type_node
);
5365 record_builtin_type (RID_MAX
, "_Sat _Accum", sat_accum_type_node
);
5366 record_builtin_type (RID_MAX
, "_Sat long _Accum",
5367 sat_long_accum_type_node
);
5368 record_builtin_type (RID_MAX
, "_Sat long long _Accum",
5369 sat_long_long_accum_type_node
);
5370 record_builtin_type (RID_MAX
, "_Sat unsigned short _Accum",
5371 sat_unsigned_short_accum_type_node
);
5372 record_builtin_type (RID_MAX
, "_Sat unsigned _Accum",
5373 sat_unsigned_accum_type_node
);
5374 record_builtin_type (RID_MAX
, "_Sat unsigned long _Accum",
5375 sat_unsigned_long_accum_type_node
);
5376 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Accum",
5377 sat_unsigned_long_long_accum_type_node
);
5381 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5383 get_identifier ("complex int"),
5384 complex_integer_type_node
));
5385 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5387 get_identifier ("complex float"),
5388 complex_float_type_node
));
5389 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5391 get_identifier ("complex double"),
5392 complex_double_type_node
));
5393 lang_hooks
.decls
.pushdecl
5394 (build_decl (UNKNOWN_LOCATION
,
5395 TYPE_DECL
, get_identifier ("complex long double"),
5396 complex_long_double_type_node
));
5398 if (c_dialect_cxx ())
5399 /* For C++, make fileptr_type_node a distinct void * type until
5400 FILE type is defined. */
5401 fileptr_type_node
= build_variant_type_copy (ptr_type_node
);
5403 record_builtin_type (RID_VOID
, NULL
, void_type_node
);
5405 /* Set the TYPE_NAME for any variants that were built before
5406 record_builtin_type gave names to the built-in types. */
5408 tree void_name
= TYPE_NAME (void_type_node
);
5409 TYPE_NAME (void_type_node
) = NULL_TREE
;
5410 TYPE_NAME (build_qualified_type (void_type_node
, TYPE_QUAL_CONST
))
5412 TYPE_NAME (void_type_node
) = void_name
;
5415 /* This node must not be shared. */
5416 void_zero_node
= make_node (INTEGER_CST
);
5417 TREE_TYPE (void_zero_node
) = void_type_node
;
5419 void_list_node
= build_void_list_node ();
5421 /* Make a type to be the domain of a few array types
5422 whose domains don't really matter.
5423 200 is small enough that it always fits in size_t
5424 and large enough that it can hold most function names for the
5425 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
5426 array_domain_type
= build_index_type (size_int (200));
5428 /* Make a type for arrays of characters.
5429 With luck nothing will ever really depend on the length of this
5431 char_array_type_node
5432 = build_array_type (char_type_node
, array_domain_type
);
5434 /* Likewise for arrays of ints. */
5436 = build_array_type (integer_type_node
, array_domain_type
);
5438 string_type_node
= build_pointer_type (char_type_node
);
5439 const_string_type_node
5440 = build_pointer_type (build_qualified_type
5441 (char_type_node
, TYPE_QUAL_CONST
));
5443 /* This is special for C++ so functions can be overloaded. */
5444 wchar_type_node
= get_identifier (MODIFIED_WCHAR_TYPE
);
5445 wchar_type_node
= TREE_TYPE (identifier_global_value (wchar_type_node
));
5446 wchar_type_size
= TYPE_PRECISION (wchar_type_node
);
5447 underlying_wchar_type_node
= wchar_type_node
;
5448 if (c_dialect_cxx ())
5450 if (TYPE_UNSIGNED (wchar_type_node
))
5451 wchar_type_node
= make_unsigned_type (wchar_type_size
);
5453 wchar_type_node
= make_signed_type (wchar_type_size
);
5454 record_builtin_type (RID_WCHAR
, "wchar_t", wchar_type_node
);
5457 /* This is for wide string constants. */
5458 wchar_array_type_node
5459 = build_array_type (wchar_type_node
, array_domain_type
);
5461 /* Define 'char16_t'. */
5462 char16_type_node
= get_identifier (CHAR16_TYPE
);
5463 char16_type_node
= TREE_TYPE (identifier_global_value (char16_type_node
));
5464 char16_type_size
= TYPE_PRECISION (char16_type_node
);
5465 if (c_dialect_cxx ())
5467 char16_type_node
= make_unsigned_type (char16_type_size
);
5469 if (cxx_dialect
>= cxx11
)
5470 record_builtin_type (RID_CHAR16
, "char16_t", char16_type_node
);
5473 /* This is for UTF-16 string constants. */
5474 char16_array_type_node
5475 = build_array_type (char16_type_node
, array_domain_type
);
5477 /* Define 'char32_t'. */
5478 char32_type_node
= get_identifier (CHAR32_TYPE
);
5479 char32_type_node
= TREE_TYPE (identifier_global_value (char32_type_node
));
5480 char32_type_size
= TYPE_PRECISION (char32_type_node
);
5481 if (c_dialect_cxx ())
5483 char32_type_node
= make_unsigned_type (char32_type_size
);
5485 if (cxx_dialect
>= cxx11
)
5486 record_builtin_type (RID_CHAR32
, "char32_t", char32_type_node
);
5489 /* This is for UTF-32 string constants. */
5490 char32_array_type_node
5491 = build_array_type (char32_type_node
, array_domain_type
);
5494 TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE
)));
5497 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE
)));
5499 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE
)));
5501 if (SIG_ATOMIC_TYPE
)
5502 sig_atomic_type_node
=
5503 TREE_TYPE (identifier_global_value (c_get_ident (SIG_ATOMIC_TYPE
)));
5506 TREE_TYPE (identifier_global_value (c_get_ident (INT8_TYPE
)));
5509 TREE_TYPE (identifier_global_value (c_get_ident (INT16_TYPE
)));
5512 TREE_TYPE (identifier_global_value (c_get_ident (INT32_TYPE
)));
5515 TREE_TYPE (identifier_global_value (c_get_ident (INT64_TYPE
)));
5518 TREE_TYPE (identifier_global_value (c_get_ident (UINT8_TYPE
)));
5520 c_uint16_type_node
=
5521 TREE_TYPE (identifier_global_value (c_get_ident (UINT16_TYPE
)));
5523 c_uint32_type_node
=
5524 TREE_TYPE (identifier_global_value (c_get_ident (UINT32_TYPE
)));
5526 c_uint64_type_node
=
5527 TREE_TYPE (identifier_global_value (c_get_ident (UINT64_TYPE
)));
5528 if (INT_LEAST8_TYPE
)
5529 int_least8_type_node
=
5530 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST8_TYPE
)));
5531 if (INT_LEAST16_TYPE
)
5532 int_least16_type_node
=
5533 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST16_TYPE
)));
5534 if (INT_LEAST32_TYPE
)
5535 int_least32_type_node
=
5536 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST32_TYPE
)));
5537 if (INT_LEAST64_TYPE
)
5538 int_least64_type_node
=
5539 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST64_TYPE
)));
5540 if (UINT_LEAST8_TYPE
)
5541 uint_least8_type_node
=
5542 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST8_TYPE
)));
5543 if (UINT_LEAST16_TYPE
)
5544 uint_least16_type_node
=
5545 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST16_TYPE
)));
5546 if (UINT_LEAST32_TYPE
)
5547 uint_least32_type_node
=
5548 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST32_TYPE
)));
5549 if (UINT_LEAST64_TYPE
)
5550 uint_least64_type_node
=
5551 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST64_TYPE
)));
5553 int_fast8_type_node
=
5554 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST8_TYPE
)));
5555 if (INT_FAST16_TYPE
)
5556 int_fast16_type_node
=
5557 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST16_TYPE
)));
5558 if (INT_FAST32_TYPE
)
5559 int_fast32_type_node
=
5560 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST32_TYPE
)));
5561 if (INT_FAST64_TYPE
)
5562 int_fast64_type_node
=
5563 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST64_TYPE
)));
5564 if (UINT_FAST8_TYPE
)
5565 uint_fast8_type_node
=
5566 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST8_TYPE
)));
5567 if (UINT_FAST16_TYPE
)
5568 uint_fast16_type_node
=
5569 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST16_TYPE
)));
5570 if (UINT_FAST32_TYPE
)
5571 uint_fast32_type_node
=
5572 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST32_TYPE
)));
5573 if (UINT_FAST64_TYPE
)
5574 uint_fast64_type_node
=
5575 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST64_TYPE
)));
5578 TREE_TYPE (identifier_global_value (c_get_ident (INTPTR_TYPE
)));
5581 TREE_TYPE (identifier_global_value (c_get_ident (UINTPTR_TYPE
)));
5583 default_function_type
5584 = build_varargs_function_type_list (integer_type_node
, NULL_TREE
);
5586 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE
)));
5587 unsigned_ptrdiff_type_node
= c_common_unsigned_type (ptrdiff_type_node
);
5589 lang_hooks
.decls
.pushdecl
5590 (build_decl (UNKNOWN_LOCATION
,
5591 TYPE_DECL
, get_identifier ("__builtin_va_list"),
5592 va_list_type_node
));
5593 if (targetm
.enum_va_list_p
)
5599 for (l
= 0; targetm
.enum_va_list_p (l
, &pname
, &ptype
); ++l
)
5601 lang_hooks
.decls
.pushdecl
5602 (build_decl (UNKNOWN_LOCATION
,
5603 TYPE_DECL
, get_identifier (pname
),
5609 if (TREE_CODE (va_list_type_node
) == ARRAY_TYPE
)
5611 va_list_arg_type_node
= va_list_ref_type_node
=
5612 build_pointer_type (TREE_TYPE (va_list_type_node
));
5616 va_list_arg_type_node
= va_list_type_node
;
5617 va_list_ref_type_node
= build_reference_type (va_list_type_node
);
5620 if (!flag_preprocess_only
)
5621 c_define_builtins (va_list_ref_type_node
, va_list_arg_type_node
);
5623 main_identifier_node
= get_identifier ("main");
5625 /* Create the built-in __null node. It is important that this is
5627 null_node
= make_node (INTEGER_CST
);
5628 TREE_TYPE (null_node
) = c_common_type_for_size (POINTER_SIZE
, 0);
5630 /* Since builtin_types isn't gc'ed, don't export these nodes. */
5631 memset (builtin_types
, 0, sizeof (builtin_types
));
5634 /* The number of named compound-literals generated thus far. */
5635 static GTY(()) int compound_literal_number
;
5637 /* Set DECL_NAME for DECL, a VAR_DECL for a compound-literal. */
5640 set_compound_literal_name (tree decl
)
5643 ASM_FORMAT_PRIVATE_NAME (name
, "__compound_literal",
5644 compound_literal_number
);
5645 compound_literal_number
++;
5646 DECL_NAME (decl
) = get_identifier (name
);
5650 build_va_arg (location_t loc
, tree expr
, tree type
)
5652 expr
= build1 (VA_ARG_EXPR
, type
, expr
);
5653 SET_EXPR_LOCATION (expr
, loc
);
5658 /* Linked list of disabled built-in functions. */
5660 typedef struct disabled_builtin
5663 struct disabled_builtin
*next
;
5665 static disabled_builtin
*disabled_builtins
= NULL
;
5667 static bool builtin_function_disabled_p (const char *);
5669 /* Disable a built-in function specified by -fno-builtin-NAME. If NAME
5670 begins with "__builtin_", give an error. */
5673 disable_builtin_function (const char *name
)
5675 if (strncmp (name
, "__builtin_", strlen ("__builtin_")) == 0)
5676 error ("cannot disable built-in function %qs", name
);
5679 disabled_builtin
*new_disabled_builtin
= XNEW (disabled_builtin
);
5680 new_disabled_builtin
->name
= name
;
5681 new_disabled_builtin
->next
= disabled_builtins
;
5682 disabled_builtins
= new_disabled_builtin
;
5687 /* Return true if the built-in function NAME has been disabled, false
5691 builtin_function_disabled_p (const char *name
)
5693 disabled_builtin
*p
;
5694 for (p
= disabled_builtins
; p
!= NULL
; p
= p
->next
)
5696 if (strcmp (name
, p
->name
) == 0)
5703 /* Worker for DEF_BUILTIN.
5704 Possibly define a builtin function with one or two names.
5705 Does not declare a non-__builtin_ function if flag_no_builtin, or if
5706 nonansi_p and flag_no_nonansi_builtin. */
5709 def_builtin_1 (enum built_in_function fncode
,
5711 enum built_in_class fnclass
,
5712 tree fntype
, tree libtype
,
5713 bool both_p
, bool fallback_p
, bool nonansi_p
,
5714 tree fnattrs
, bool implicit_p
)
5717 const char *libname
;
5719 if (fntype
== error_mark_node
)
5722 gcc_assert ((!both_p
&& !fallback_p
)
5723 || !strncmp (name
, "__builtin_",
5724 strlen ("__builtin_")));
5726 libname
= name
+ strlen ("__builtin_");
5727 decl
= add_builtin_function (name
, fntype
, fncode
, fnclass
,
5728 (fallback_p
? libname
: NULL
),
5731 set_builtin_decl (fncode
, decl
, implicit_p
);
5734 && !flag_no_builtin
&& !builtin_function_disabled_p (libname
)
5735 && !(nonansi_p
&& flag_no_nonansi_builtin
))
5736 add_builtin_function (libname
, libtype
, fncode
, fnclass
,
5740 /* Nonzero if the type T promotes to int. This is (nearly) the
5741 integral promotions defined in ISO C99 6.3.1.1/2. */
5744 c_promoting_integer_type_p (const_tree t
)
5746 switch (TREE_CODE (t
))
5749 return (TYPE_MAIN_VARIANT (t
) == char_type_node
5750 || TYPE_MAIN_VARIANT (t
) == signed_char_type_node
5751 || TYPE_MAIN_VARIANT (t
) == unsigned_char_type_node
5752 || TYPE_MAIN_VARIANT (t
) == short_integer_type_node
5753 || TYPE_MAIN_VARIANT (t
) == short_unsigned_type_node
5754 || TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
));
5757 /* ??? Technically all enumerations not larger than an int
5758 promote to an int. But this is used along code paths
5759 that only want to notice a size change. */
5760 return TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
);
5770 /* Return 1 if PARMS specifies a fixed number of parameters
5771 and none of their types is affected by default promotions. */
5774 self_promoting_args_p (const_tree parms
)
5777 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
5779 tree type
= TREE_VALUE (t
);
5781 if (type
== error_mark_node
)
5784 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
5790 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
5793 if (c_promoting_integer_type_p (type
))
5799 /* Recursively remove any '*' or '&' operator from TYPE. */
5801 strip_pointer_operator (tree t
)
5803 while (POINTER_TYPE_P (t
))
5808 /* Recursively remove pointer or array type from TYPE. */
5810 strip_pointer_or_array_types (tree t
)
5812 while (TREE_CODE (t
) == ARRAY_TYPE
|| POINTER_TYPE_P (t
))
5817 /* Used to compare case labels. K1 and K2 are actually tree nodes
5818 representing case labels, or NULL_TREE for a `default' label.
5819 Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after
5820 K2, and 0 if K1 and K2 are equal. */
5823 case_compare (splay_tree_key k1
, splay_tree_key k2
)
5825 /* Consider a NULL key (such as arises with a `default' label) to be
5826 smaller than anything else. */
5832 return tree_int_cst_compare ((tree
) k1
, (tree
) k2
);
5835 /* Process a case label, located at LOC, for the range LOW_VALUE
5836 ... HIGH_VALUE. If LOW_VALUE and HIGH_VALUE are both NULL_TREE
5837 then this case label is actually a `default' label. If only
5838 HIGH_VALUE is NULL_TREE, then case label was declared using the
5839 usual C/C++ syntax, rather than the GNU case range extension.
5840 CASES is a tree containing all the case ranges processed so far;
5841 COND is the condition for the switch-statement itself. Returns the
5842 CASE_LABEL_EXPR created, or ERROR_MARK_NODE if no CASE_LABEL_EXPR
5846 c_add_case_label (location_t loc
, splay_tree cases
, tree cond
, tree orig_type
,
5847 tree low_value
, tree high_value
)
5852 splay_tree_node node
;
5854 /* Create the LABEL_DECL itself. */
5855 label
= create_artificial_label (loc
);
5857 /* If there was an error processing the switch condition, bail now
5858 before we get more confused. */
5859 if (!cond
|| cond
== error_mark_node
)
5862 if ((low_value
&& TREE_TYPE (low_value
)
5863 && POINTER_TYPE_P (TREE_TYPE (low_value
)))
5864 || (high_value
&& TREE_TYPE (high_value
)
5865 && POINTER_TYPE_P (TREE_TYPE (high_value
))))
5867 error_at (loc
, "pointers are not permitted as case values");
5871 /* Case ranges are a GNU extension. */
5873 pedwarn (loc
, OPT_Wpedantic
,
5874 "range expressions in switch statements are non-standard");
5876 type
= TREE_TYPE (cond
);
5879 low_value
= check_case_value (low_value
);
5880 low_value
= convert_and_check (type
, low_value
);
5881 if (low_value
== error_mark_node
)
5886 high_value
= check_case_value (high_value
);
5887 high_value
= convert_and_check (type
, high_value
);
5888 if (high_value
== error_mark_node
)
5892 if (low_value
&& high_value
)
5894 /* If the LOW_VALUE and HIGH_VALUE are the same, then this isn't
5895 really a case range, even though it was written that way.
5896 Remove the HIGH_VALUE to simplify later processing. */
5897 if (tree_int_cst_equal (low_value
, high_value
))
5898 high_value
= NULL_TREE
;
5899 else if (!tree_int_cst_lt (low_value
, high_value
))
5900 warning_at (loc
, 0, "empty range specified");
5903 /* See if the case is in range of the type of the original testing
5904 expression. If both low_value and high_value are out of range,
5905 don't insert the case label and return NULL_TREE. */
5907 && !check_case_bounds (type
, orig_type
,
5908 &low_value
, high_value
? &high_value
: NULL
))
5911 /* Look up the LOW_VALUE in the table of case labels we already
5913 node
= splay_tree_lookup (cases
, (splay_tree_key
) low_value
);
5914 /* If there was not an exact match, check for overlapping ranges.
5915 There's no need to do this if there's no LOW_VALUE or HIGH_VALUE;
5916 that's a `default' label and the only overlap is an exact match. */
5917 if (!node
&& (low_value
|| high_value
))
5919 splay_tree_node low_bound
;
5920 splay_tree_node high_bound
;
5922 /* Even though there wasn't an exact match, there might be an
5923 overlap between this case range and another case range.
5924 Since we've (inductively) not allowed any overlapping case
5925 ranges, we simply need to find the greatest low case label
5926 that is smaller that LOW_VALUE, and the smallest low case
5927 label that is greater than LOW_VALUE. If there is an overlap
5928 it will occur in one of these two ranges. */
5929 low_bound
= splay_tree_predecessor (cases
,
5930 (splay_tree_key
) low_value
);
5931 high_bound
= splay_tree_successor (cases
,
5932 (splay_tree_key
) low_value
);
5934 /* Check to see if the LOW_BOUND overlaps. It is smaller than
5935 the LOW_VALUE, so there is no need to check unless the
5936 LOW_BOUND is in fact itself a case range. */
5938 && CASE_HIGH ((tree
) low_bound
->value
)
5939 && tree_int_cst_compare (CASE_HIGH ((tree
) low_bound
->value
),
5942 /* Check to see if the HIGH_BOUND overlaps. The low end of that
5943 range is bigger than the low end of the current range, so we
5944 are only interested if the current range is a real range, and
5945 not an ordinary case label. */
5948 && (tree_int_cst_compare ((tree
) high_bound
->key
,
5953 /* If there was an overlap, issue an error. */
5956 tree duplicate
= CASE_LABEL ((tree
) node
->value
);
5960 error_at (loc
, "duplicate (or overlapping) case value");
5961 error_at (DECL_SOURCE_LOCATION (duplicate
),
5962 "this is the first entry overlapping that value");
5966 error_at (loc
, "duplicate case value") ;
5967 error_at (DECL_SOURCE_LOCATION (duplicate
), "previously used here");
5971 error_at (loc
, "multiple default labels in one switch");
5972 error_at (DECL_SOURCE_LOCATION (duplicate
),
5973 "this is the first default label");
5978 /* Add a CASE_LABEL to the statement-tree. */
5979 case_label
= add_stmt (build_case_label (low_value
, high_value
, label
));
5980 /* Register this case label in the splay tree. */
5981 splay_tree_insert (cases
,
5982 (splay_tree_key
) low_value
,
5983 (splay_tree_value
) case_label
);
5988 /* Add a label so that the back-end doesn't think that the beginning of
5989 the switch is unreachable. Note that we do not add a case label, as
5990 that just leads to duplicates and thence to failure later on. */
5993 tree t
= create_artificial_label (loc
);
5994 add_stmt (build_stmt (loc
, LABEL_EXPR
, t
));
5996 return error_mark_node
;
5999 /* Subroutines of c_do_switch_warnings, called via splay_tree_foreach.
6000 Used to verify that case values match up with enumerator values. */
6003 match_case_to_enum_1 (tree key
, tree type
, tree label
)
6005 char buf
[2 + 2*HOST_BITS_PER_WIDE_INT
/4 + 1];
6007 /* ??? Not working too hard to print the double-word value.
6008 Should perhaps be done with %lwd in the diagnostic routines? */
6009 if (TREE_INT_CST_HIGH (key
) == 0)
6010 snprintf (buf
, sizeof (buf
), HOST_WIDE_INT_PRINT_UNSIGNED
,
6011 TREE_INT_CST_LOW (key
));
6012 else if (!TYPE_UNSIGNED (type
)
6013 && TREE_INT_CST_HIGH (key
) == -1
6014 && TREE_INT_CST_LOW (key
) != 0)
6015 snprintf (buf
, sizeof (buf
), "-" HOST_WIDE_INT_PRINT_UNSIGNED
,
6016 -TREE_INT_CST_LOW (key
));
6018 snprintf (buf
, sizeof (buf
), HOST_WIDE_INT_PRINT_DOUBLE_HEX
,
6019 (unsigned HOST_WIDE_INT
) TREE_INT_CST_HIGH (key
),
6020 (unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (key
));
6022 if (TYPE_NAME (type
) == 0)
6023 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
6024 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
6025 "case value %qs not in enumerated type",
6028 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
6029 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
6030 "case value %qs not in enumerated type %qT",
6034 /* Subroutine of c_do_switch_warnings, called via splay_tree_foreach.
6035 Used to verify that case values match up with enumerator values. */
6038 match_case_to_enum (splay_tree_node node
, void *data
)
6040 tree label
= (tree
) node
->value
;
6041 tree type
= (tree
) data
;
6043 /* Skip default case. */
6044 if (!CASE_LOW (label
))
6047 /* If CASE_LOW_SEEN is not set, that means CASE_LOW did not appear
6048 when we did our enum->case scan. Reset our scratch bit after. */
6049 if (!CASE_LOW_SEEN (label
))
6050 match_case_to_enum_1 (CASE_LOW (label
), type
, label
);
6052 CASE_LOW_SEEN (label
) = 0;
6054 /* If CASE_HIGH is non-null, we have a range. If CASE_HIGH_SEEN is
6055 not set, that means that CASE_HIGH did not appear when we did our
6056 enum->case scan. Reset our scratch bit after. */
6057 if (CASE_HIGH (label
))
6059 if (!CASE_HIGH_SEEN (label
))
6060 match_case_to_enum_1 (CASE_HIGH (label
), type
, label
);
6062 CASE_HIGH_SEEN (label
) = 0;
6068 /* Handle -Wswitch*. Called from the front end after parsing the
6069 switch construct. */
6070 /* ??? Should probably be somewhere generic, since other languages
6071 besides C and C++ would want this. At the moment, however, C/C++
6072 are the only tree-ssa languages that support enumerations at all,
6073 so the point is moot. */
6076 c_do_switch_warnings (splay_tree cases
, location_t switch_location
,
6077 tree type
, tree cond
)
6079 splay_tree_node default_node
;
6080 splay_tree_node node
;
6083 if (!warn_switch
&& !warn_switch_enum
&& !warn_switch_default
)
6086 default_node
= splay_tree_lookup (cases
, (splay_tree_key
) NULL
);
6088 warning_at (switch_location
, OPT_Wswitch_default
,
6089 "switch missing default case");
6091 /* From here on, we only care about about enumerated types. */
6092 if (!type
|| TREE_CODE (type
) != ENUMERAL_TYPE
)
6095 /* From here on, we only care about -Wswitch and -Wswitch-enum. */
6096 if (!warn_switch_enum
&& !warn_switch
)
6099 /* Check the cases. Warn about case values which are not members of
6100 the enumerated type. For -Wswitch-enum, or for -Wswitch when
6101 there is no default case, check that exactly all enumeration
6102 literals are covered by the cases. */
6104 /* Clearing COND if it is not an integer constant simplifies
6105 the tests inside the loop below. */
6106 if (TREE_CODE (cond
) != INTEGER_CST
)
6109 /* The time complexity here is O(N*lg(N)) worst case, but for the
6110 common case of monotonically increasing enumerators, it is
6111 O(N), since the nature of the splay tree will keep the next
6112 element adjacent to the root at all times. */
6114 for (chain
= TYPE_VALUES (type
); chain
; chain
= TREE_CHAIN (chain
))
6116 tree value
= TREE_VALUE (chain
);
6117 if (TREE_CODE (value
) == CONST_DECL
)
6118 value
= DECL_INITIAL (value
);
6119 node
= splay_tree_lookup (cases
, (splay_tree_key
) value
);
6122 /* Mark the CASE_LOW part of the case entry as seen. */
6123 tree label
= (tree
) node
->value
;
6124 CASE_LOW_SEEN (label
) = 1;
6128 /* Even though there wasn't an exact match, there might be a
6129 case range which includes the enumerator's value. */
6130 node
= splay_tree_predecessor (cases
, (splay_tree_key
) value
);
6131 if (node
&& CASE_HIGH ((tree
) node
->value
))
6133 tree label
= (tree
) node
->value
;
6134 int cmp
= tree_int_cst_compare (CASE_HIGH (label
), value
);
6137 /* If we match the upper bound exactly, mark the CASE_HIGH
6138 part of the case entry as seen. */
6140 CASE_HIGH_SEEN (label
) = 1;
6145 /* We've now determined that this enumerated literal isn't
6146 handled by the case labels of the switch statement. */
6148 /* If the switch expression is a constant, we only really care
6149 about whether that constant is handled by the switch. */
6150 if (cond
&& tree_int_cst_compare (cond
, value
))
6153 /* If there is a default_node, the only relevant option is
6154 Wswitch-enum. Otherwise, if both are enabled then we prefer
6155 to warn using -Wswitch because -Wswitch is enabled by -Wall
6156 while -Wswitch-enum is explicit. */
6157 warning_at (switch_location
,
6158 (default_node
|| !warn_switch
6161 "enumeration value %qE not handled in switch",
6162 TREE_PURPOSE (chain
));
6165 /* Warn if there are case expressions that don't correspond to
6166 enumerators. This can occur since C and C++ don't enforce
6167 type-checking of assignments to enumeration variables.
6169 The time complexity here is now always O(N) worst case, since
6170 we should have marked both the lower bound and upper bound of
6171 every disjoint case label, with CASE_LOW_SEEN and CASE_HIGH_SEEN
6172 above. This scan also resets those fields. */
6174 splay_tree_foreach (cases
, match_case_to_enum
, type
);
6177 /* Finish an expression taking the address of LABEL (an
6178 IDENTIFIER_NODE). Returns an expression for the address.
6180 LOC is the location for the expression returned. */
6183 finish_label_address_expr (tree label
, location_t loc
)
6187 pedwarn (input_location
, OPT_Wpedantic
, "taking the address of a label is non-standard");
6189 if (label
== error_mark_node
)
6190 return error_mark_node
;
6192 label
= lookup_label (label
);
6193 if (label
== NULL_TREE
)
6194 result
= null_pointer_node
;
6197 TREE_USED (label
) = 1;
6198 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
6199 /* The current function is not necessarily uninlinable.
6200 Computed gotos are incompatible with inlining, but the value
6201 here could be used only in a diagnostic, for example. */
6202 protected_set_expr_location (result
, loc
);
6209 /* Given a boolean expression ARG, return a tree representing an increment
6210 or decrement (as indicated by CODE) of ARG. The front end must check for
6211 invalid cases (e.g., decrement in C++). */
6213 boolean_increment (enum tree_code code
, tree arg
)
6216 tree true_res
= build_int_cst (TREE_TYPE (arg
), 1);
6218 arg
= stabilize_reference (arg
);
6221 case PREINCREMENT_EXPR
:
6222 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
6224 case POSTINCREMENT_EXPR
:
6225 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
6226 arg
= save_expr (arg
);
6227 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
6228 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
6230 case PREDECREMENT_EXPR
:
6231 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
6232 invert_truthvalue_loc (input_location
, arg
));
6234 case POSTDECREMENT_EXPR
:
6235 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
6236 invert_truthvalue_loc (input_location
, arg
));
6237 arg
= save_expr (arg
);
6238 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
6239 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
6244 TREE_SIDE_EFFECTS (val
) = 1;
6248 /* Built-in macros for stddef.h and stdint.h, that require macros
6249 defined in this file. */
6251 c_stddef_cpp_builtins(void)
6253 builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE
, 0);
6254 builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE
, 0);
6255 builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE
, 0);
6256 builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE
, 0);
6257 builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE
, 0);
6258 builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE
, 0);
6259 builtin_define_with_value ("__CHAR16_TYPE__", CHAR16_TYPE
, 0);
6260 builtin_define_with_value ("__CHAR32_TYPE__", CHAR32_TYPE
, 0);
6261 if (SIG_ATOMIC_TYPE
)
6262 builtin_define_with_value ("__SIG_ATOMIC_TYPE__", SIG_ATOMIC_TYPE
, 0);
6264 builtin_define_with_value ("__INT8_TYPE__", INT8_TYPE
, 0);
6266 builtin_define_with_value ("__INT16_TYPE__", INT16_TYPE
, 0);
6268 builtin_define_with_value ("__INT32_TYPE__", INT32_TYPE
, 0);
6270 builtin_define_with_value ("__INT64_TYPE__", INT64_TYPE
, 0);
6272 builtin_define_with_value ("__UINT8_TYPE__", UINT8_TYPE
, 0);
6274 builtin_define_with_value ("__UINT16_TYPE__", UINT16_TYPE
, 0);
6276 builtin_define_with_value ("__UINT32_TYPE__", UINT32_TYPE
, 0);
6278 builtin_define_with_value ("__UINT64_TYPE__", UINT64_TYPE
, 0);
6279 if (INT_LEAST8_TYPE
)
6280 builtin_define_with_value ("__INT_LEAST8_TYPE__", INT_LEAST8_TYPE
, 0);
6281 if (INT_LEAST16_TYPE
)
6282 builtin_define_with_value ("__INT_LEAST16_TYPE__", INT_LEAST16_TYPE
, 0);
6283 if (INT_LEAST32_TYPE
)
6284 builtin_define_with_value ("__INT_LEAST32_TYPE__", INT_LEAST32_TYPE
, 0);
6285 if (INT_LEAST64_TYPE
)
6286 builtin_define_with_value ("__INT_LEAST64_TYPE__", INT_LEAST64_TYPE
, 0);
6287 if (UINT_LEAST8_TYPE
)
6288 builtin_define_with_value ("__UINT_LEAST8_TYPE__", UINT_LEAST8_TYPE
, 0);
6289 if (UINT_LEAST16_TYPE
)
6290 builtin_define_with_value ("__UINT_LEAST16_TYPE__", UINT_LEAST16_TYPE
, 0);
6291 if (UINT_LEAST32_TYPE
)
6292 builtin_define_with_value ("__UINT_LEAST32_TYPE__", UINT_LEAST32_TYPE
, 0);
6293 if (UINT_LEAST64_TYPE
)
6294 builtin_define_with_value ("__UINT_LEAST64_TYPE__", UINT_LEAST64_TYPE
, 0);
6296 builtin_define_with_value ("__INT_FAST8_TYPE__", INT_FAST8_TYPE
, 0);
6297 if (INT_FAST16_TYPE
)
6298 builtin_define_with_value ("__INT_FAST16_TYPE__", INT_FAST16_TYPE
, 0);
6299 if (INT_FAST32_TYPE
)
6300 builtin_define_with_value ("__INT_FAST32_TYPE__", INT_FAST32_TYPE
, 0);
6301 if (INT_FAST64_TYPE
)
6302 builtin_define_with_value ("__INT_FAST64_TYPE__", INT_FAST64_TYPE
, 0);
6303 if (UINT_FAST8_TYPE
)
6304 builtin_define_with_value ("__UINT_FAST8_TYPE__", UINT_FAST8_TYPE
, 0);
6305 if (UINT_FAST16_TYPE
)
6306 builtin_define_with_value ("__UINT_FAST16_TYPE__", UINT_FAST16_TYPE
, 0);
6307 if (UINT_FAST32_TYPE
)
6308 builtin_define_with_value ("__UINT_FAST32_TYPE__", UINT_FAST32_TYPE
, 0);
6309 if (UINT_FAST64_TYPE
)
6310 builtin_define_with_value ("__UINT_FAST64_TYPE__", UINT_FAST64_TYPE
, 0);
6312 builtin_define_with_value ("__INTPTR_TYPE__", INTPTR_TYPE
, 0);
6314 builtin_define_with_value ("__UINTPTR_TYPE__", UINTPTR_TYPE
, 0);
6318 c_init_attributes (void)
6320 /* Fill in the built_in_attributes array. */
6321 #define DEF_ATTR_NULL_TREE(ENUM) \
6322 built_in_attributes[(int) ENUM] = NULL_TREE;
6323 #define DEF_ATTR_INT(ENUM, VALUE) \
6324 built_in_attributes[(int) ENUM] = build_int_cst (integer_type_node, VALUE);
6325 #define DEF_ATTR_STRING(ENUM, VALUE) \
6326 built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
6327 #define DEF_ATTR_IDENT(ENUM, STRING) \
6328 built_in_attributes[(int) ENUM] = get_identifier (STRING);
6329 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
6330 built_in_attributes[(int) ENUM] \
6331 = tree_cons (built_in_attributes[(int) PURPOSE], \
6332 built_in_attributes[(int) VALUE], \
6333 built_in_attributes[(int) CHAIN]);
6334 #include "builtin-attrs.def"
6335 #undef DEF_ATTR_NULL_TREE
6337 #undef DEF_ATTR_IDENT
6338 #undef DEF_ATTR_TREE_LIST
6341 /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain
6342 identifier as an argument, so the front end shouldn't look it up. */
6345 attribute_takes_identifier_p (const_tree attr_id
)
6347 const struct attribute_spec
*spec
= lookup_attribute_spec (attr_id
);
6349 /* Unknown attribute that we'll end up ignoring, return true so we
6350 don't complain about an identifier argument. */
6352 else if (!strcmp ("mode", spec
->name
)
6353 || !strcmp ("format", spec
->name
)
6354 || !strcmp ("cleanup", spec
->name
))
6357 return targetm
.attribute_takes_identifier_p (attr_id
);
6360 /* Attribute handlers common to C front ends. */
6362 /* Handle a "packed" attribute; arguments as in
6363 struct attribute_spec.handler. */
6366 handle_packed_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6367 int flags
, bool *no_add_attrs
)
6371 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6372 *node
= build_variant_type_copy (*node
);
6373 TYPE_PACKED (*node
) = 1;
6375 else if (TREE_CODE (*node
) == FIELD_DECL
)
6377 if (TYPE_ALIGN (TREE_TYPE (*node
)) <= BITS_PER_UNIT
6378 /* Still pack bitfields. */
6379 && ! DECL_INITIAL (*node
))
6380 warning (OPT_Wattributes
,
6381 "%qE attribute ignored for field of type %qT",
6382 name
, TREE_TYPE (*node
));
6384 DECL_PACKED (*node
) = 1;
6386 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
6387 used for DECL_REGISTER. It wouldn't mean anything anyway.
6388 We can't set DECL_PACKED on the type of a TYPE_DECL, because
6389 that changes what the typedef is typing. */
6392 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6393 *no_add_attrs
= true;
6399 /* Handle a "nocommon" attribute; arguments as in
6400 struct attribute_spec.handler. */
6403 handle_nocommon_attribute (tree
*node
, tree name
,
6404 tree
ARG_UNUSED (args
),
6405 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6407 if (TREE_CODE (*node
) == VAR_DECL
)
6408 DECL_COMMON (*node
) = 0;
6411 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6412 *no_add_attrs
= true;
6418 /* Handle a "common" attribute; arguments as in
6419 struct attribute_spec.handler. */
6422 handle_common_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6423 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6425 if (TREE_CODE (*node
) == VAR_DECL
)
6426 DECL_COMMON (*node
) = 1;
6429 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6430 *no_add_attrs
= true;
6436 /* Handle a "noreturn" attribute; arguments as in
6437 struct attribute_spec.handler. */
6440 handle_noreturn_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6441 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6443 tree type
= TREE_TYPE (*node
);
6445 /* See FIXME comment in c_common_attribute_table. */
6446 if (TREE_CODE (*node
) == FUNCTION_DECL
6447 || objc_method_decl (TREE_CODE (*node
)))
6448 TREE_THIS_VOLATILE (*node
) = 1;
6449 else if (TREE_CODE (type
) == POINTER_TYPE
6450 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
6452 = build_pointer_type
6453 (build_type_variant (TREE_TYPE (type
),
6454 TYPE_READONLY (TREE_TYPE (type
)), 1));
6457 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6458 *no_add_attrs
= true;
6464 /* Handle a "hot" and attribute; arguments as in
6465 struct attribute_spec.handler. */
6468 handle_hot_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6469 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6471 if (TREE_CODE (*node
) == FUNCTION_DECL
6472 || TREE_CODE (*node
) == LABEL_DECL
)
6474 if (lookup_attribute ("cold", DECL_ATTRIBUTES (*node
)) != NULL
)
6476 warning (OPT_Wattributes
, "%qE attribute conflicts with attribute %s",
6478 *no_add_attrs
= true;
6480 /* Most of the rest of the hot processing is done later with
6481 lookup_attribute. */
6485 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6486 *no_add_attrs
= true;
6492 /* Handle a "cold" and attribute; arguments as in
6493 struct attribute_spec.handler. */
6496 handle_cold_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6497 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6499 if (TREE_CODE (*node
) == FUNCTION_DECL
6500 || TREE_CODE (*node
) == LABEL_DECL
)
6502 if (lookup_attribute ("hot", DECL_ATTRIBUTES (*node
)) != NULL
)
6504 warning (OPT_Wattributes
, "%qE attribute conflicts with attribute %s",
6506 *no_add_attrs
= true;
6508 /* Most of the rest of the cold processing is done later with
6509 lookup_attribute. */
6513 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6514 *no_add_attrs
= true;
6520 /* Handle a "no_sanitize_address" attribute; arguments as in
6521 struct attribute_spec.handler. */
6524 handle_no_sanitize_address_attribute (tree
*node
, tree name
, tree
, int,
6527 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6529 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6530 *no_add_attrs
= true;
6536 /* Handle a "no_address_safety_analysis" attribute; arguments as in
6537 struct attribute_spec.handler. */
6540 handle_no_address_safety_analysis_attribute (tree
*node
, tree name
, tree
, int,
6543 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6544 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6545 else if (!lookup_attribute ("no_sanitize_address", DECL_ATTRIBUTES (*node
)))
6546 DECL_ATTRIBUTES (*node
)
6547 = tree_cons (get_identifier ("no_sanitize_address"),
6548 NULL_TREE
, DECL_ATTRIBUTES (*node
));
6549 *no_add_attrs
= true;
6553 /* Handle a "noinline" attribute; arguments as in
6554 struct attribute_spec.handler. */
6557 handle_noinline_attribute (tree
*node
, tree name
,
6558 tree
ARG_UNUSED (args
),
6559 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6561 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6562 DECL_UNINLINABLE (*node
) = 1;
6565 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6566 *no_add_attrs
= true;
6572 /* Handle a "noclone" attribute; arguments as in
6573 struct attribute_spec.handler. */
6576 handle_noclone_attribute (tree
*node
, tree name
,
6577 tree
ARG_UNUSED (args
),
6578 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6580 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6582 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6583 *no_add_attrs
= true;
6589 /* Handle a "always_inline" attribute; arguments as in
6590 struct attribute_spec.handler. */
6593 handle_always_inline_attribute (tree
*node
, tree name
,
6594 tree
ARG_UNUSED (args
),
6595 int ARG_UNUSED (flags
),
6598 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6600 /* Set the attribute and mark it for disregarding inline
6602 DECL_DISREGARD_INLINE_LIMITS (*node
) = 1;
6606 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6607 *no_add_attrs
= true;
6613 /* Handle a "gnu_inline" attribute; arguments as in
6614 struct attribute_spec.handler. */
6617 handle_gnu_inline_attribute (tree
*node
, tree name
,
6618 tree
ARG_UNUSED (args
),
6619 int ARG_UNUSED (flags
),
6622 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
6624 /* Do nothing else, just set the attribute. We'll get at
6625 it later with lookup_attribute. */
6629 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6630 *no_add_attrs
= true;
6636 /* Handle a "leaf" attribute; arguments as in
6637 struct attribute_spec.handler. */
6640 handle_leaf_attribute (tree
*node
, tree name
,
6641 tree
ARG_UNUSED (args
),
6642 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6644 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6646 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6647 *no_add_attrs
= true;
6649 if (!TREE_PUBLIC (*node
))
6651 warning (OPT_Wattributes
, "%qE attribute has no effect on unit local functions", name
);
6652 *no_add_attrs
= true;
6658 /* Handle an "artificial" attribute; arguments as in
6659 struct attribute_spec.handler. */
6662 handle_artificial_attribute (tree
*node
, tree name
,
6663 tree
ARG_UNUSED (args
),
6664 int ARG_UNUSED (flags
),
6667 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
6669 /* Do nothing else, just set the attribute. We'll get at
6670 it later with lookup_attribute. */
6674 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6675 *no_add_attrs
= true;
6681 /* Handle a "flatten" attribute; arguments as in
6682 struct attribute_spec.handler. */
6685 handle_flatten_attribute (tree
*node
, tree name
,
6686 tree args ATTRIBUTE_UNUSED
,
6687 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
6689 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6690 /* Do nothing else, just set the attribute. We'll get at
6691 it later with lookup_attribute. */
6695 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6696 *no_add_attrs
= true;
6702 /* Handle a "warning" or "error" attribute; arguments as in
6703 struct attribute_spec.handler. */
6706 handle_error_attribute (tree
*node
, tree name
, tree args
,
6707 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6709 if (TREE_CODE (*node
) == FUNCTION_DECL
6710 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
6711 /* Do nothing else, just set the attribute. We'll get at
6712 it later with lookup_attribute. */
6716 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6717 *no_add_attrs
= true;
6723 /* Handle a "used" attribute; arguments as in
6724 struct attribute_spec.handler. */
6727 handle_used_attribute (tree
*pnode
, tree name
, tree
ARG_UNUSED (args
),
6728 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6732 if (TREE_CODE (node
) == FUNCTION_DECL
6733 || (TREE_CODE (node
) == VAR_DECL
&& TREE_STATIC (node
))
6734 || (TREE_CODE (node
) == TYPE_DECL
))
6736 TREE_USED (node
) = 1;
6737 DECL_PRESERVE_P (node
) = 1;
6738 if (TREE_CODE (node
) == VAR_DECL
)
6739 DECL_READ_P (node
) = 1;
6743 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6744 *no_add_attrs
= true;
6750 /* Handle a "unused" attribute; arguments as in
6751 struct attribute_spec.handler. */
6754 handle_unused_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6755 int flags
, bool *no_add_attrs
)
6761 if (TREE_CODE (decl
) == PARM_DECL
6762 || TREE_CODE (decl
) == VAR_DECL
6763 || TREE_CODE (decl
) == FUNCTION_DECL
6764 || TREE_CODE (decl
) == LABEL_DECL
6765 || TREE_CODE (decl
) == TYPE_DECL
)
6767 TREE_USED (decl
) = 1;
6768 if (TREE_CODE (decl
) == VAR_DECL
6769 || TREE_CODE (decl
) == PARM_DECL
)
6770 DECL_READ_P (decl
) = 1;
6774 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6775 *no_add_attrs
= true;
6780 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6781 *node
= build_variant_type_copy (*node
);
6782 TREE_USED (*node
) = 1;
6788 /* Handle a "externally_visible" attribute; arguments as in
6789 struct attribute_spec.handler. */
6792 handle_externally_visible_attribute (tree
*pnode
, tree name
,
6793 tree
ARG_UNUSED (args
),
6794 int ARG_UNUSED (flags
),
6799 if (TREE_CODE (node
) == FUNCTION_DECL
|| TREE_CODE (node
) == VAR_DECL
)
6801 if ((!TREE_STATIC (node
) && TREE_CODE (node
) != FUNCTION_DECL
6802 && !DECL_EXTERNAL (node
)) || !TREE_PUBLIC (node
))
6804 warning (OPT_Wattributes
,
6805 "%qE attribute have effect only on public objects", name
);
6806 *no_add_attrs
= true;
6811 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6812 *no_add_attrs
= true;
6818 /* Handle a "const" attribute; arguments as in
6819 struct attribute_spec.handler. */
6822 handle_const_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6823 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6825 tree type
= TREE_TYPE (*node
);
6827 /* See FIXME comment on noreturn in c_common_attribute_table. */
6828 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6829 TREE_READONLY (*node
) = 1;
6830 else if (TREE_CODE (type
) == POINTER_TYPE
6831 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
6833 = build_pointer_type
6834 (build_type_variant (TREE_TYPE (type
), 1,
6835 TREE_THIS_VOLATILE (TREE_TYPE (type
))));
6838 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6839 *no_add_attrs
= true;
6845 /* Handle a "transparent_union" attribute; arguments as in
6846 struct attribute_spec.handler. */
6849 handle_transparent_union_attribute (tree
*node
, tree name
,
6850 tree
ARG_UNUSED (args
), int flags
,
6855 *no_add_attrs
= true;
6858 if (TREE_CODE (*node
) == TYPE_DECL
6859 && ! (flags
& ATTR_FLAG_CXX11
))
6860 node
= &TREE_TYPE (*node
);
6863 if (TREE_CODE (type
) == UNION_TYPE
)
6865 /* Make sure that the first field will work for a transparent union.
6866 If the type isn't complete yet, leave the check to the code in
6868 if (TYPE_SIZE (type
))
6870 tree first
= first_field (type
);
6871 if (first
== NULL_TREE
6872 || DECL_ARTIFICIAL (first
)
6873 || TYPE_MODE (type
) != DECL_MODE (first
))
6877 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6879 /* If the type isn't complete yet, setting the flag
6880 on a variant wouldn't ever be checked. */
6881 if (!TYPE_SIZE (type
))
6884 /* build_duplicate_type doesn't work for C++. */
6885 if (c_dialect_cxx ())
6888 /* A type variant isn't good enough, since we don't a cast
6889 to such a type removed as a no-op. */
6890 *node
= type
= build_duplicate_type (type
);
6893 TYPE_TRANSPARENT_AGGR (type
) = 1;
6898 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6902 /* Subroutine of handle_{con,de}structor_attribute. Evaluate ARGS to
6903 get the requested priority for a constructor or destructor,
6904 possibly issuing diagnostics for invalid or reserved
6907 static priority_type
6908 get_priority (tree args
, bool is_destructor
)
6914 return DEFAULT_INIT_PRIORITY
;
6916 if (!SUPPORTS_INIT_PRIORITY
)
6919 error ("destructor priorities are not supported");
6921 error ("constructor priorities are not supported");
6922 return DEFAULT_INIT_PRIORITY
;
6925 arg
= TREE_VALUE (args
);
6926 arg
= default_conversion (arg
);
6927 if (!host_integerp (arg
, /*pos=*/0)
6928 || !INTEGRAL_TYPE_P (TREE_TYPE (arg
)))
6931 pri
= tree_low_cst (arg
, /*pos=*/0);
6932 if (pri
< 0 || pri
> MAX_INIT_PRIORITY
)
6935 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
6939 "destructor priorities from 0 to %d are reserved "
6940 "for the implementation",
6941 MAX_RESERVED_INIT_PRIORITY
);
6944 "constructor priorities from 0 to %d are reserved "
6945 "for the implementation",
6946 MAX_RESERVED_INIT_PRIORITY
);
6952 error ("destructor priorities must be integers from 0 to %d inclusive",
6955 error ("constructor priorities must be integers from 0 to %d inclusive",
6957 return DEFAULT_INIT_PRIORITY
;
6960 /* Handle a "constructor" attribute; arguments as in
6961 struct attribute_spec.handler. */
6964 handle_constructor_attribute (tree
*node
, tree name
, tree args
,
6965 int ARG_UNUSED (flags
),
6969 tree type
= TREE_TYPE (decl
);
6971 if (TREE_CODE (decl
) == FUNCTION_DECL
6972 && TREE_CODE (type
) == FUNCTION_TYPE
6973 && decl_function_context (decl
) == 0)
6975 priority_type priority
;
6976 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
6977 priority
= get_priority (args
, /*is_destructor=*/false);
6978 SET_DECL_INIT_PRIORITY (decl
, priority
);
6979 TREE_USED (decl
) = 1;
6983 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6984 *no_add_attrs
= true;
6990 /* Handle a "destructor" attribute; arguments as in
6991 struct attribute_spec.handler. */
6994 handle_destructor_attribute (tree
*node
, tree name
, tree args
,
6995 int ARG_UNUSED (flags
),
6999 tree type
= TREE_TYPE (decl
);
7001 if (TREE_CODE (decl
) == FUNCTION_DECL
7002 && TREE_CODE (type
) == FUNCTION_TYPE
7003 && decl_function_context (decl
) == 0)
7005 priority_type priority
;
7006 DECL_STATIC_DESTRUCTOR (decl
) = 1;
7007 priority
= get_priority (args
, /*is_destructor=*/true);
7008 SET_DECL_FINI_PRIORITY (decl
, priority
);
7009 TREE_USED (decl
) = 1;
7013 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7014 *no_add_attrs
= true;
7020 /* Nonzero if the mode is a valid vector mode for this architecture.
7021 This returns nonzero even if there is no hardware support for the
7022 vector mode, but we can emulate with narrower modes. */
7025 vector_mode_valid_p (enum machine_mode mode
)
7027 enum mode_class mclass
= GET_MODE_CLASS (mode
);
7028 enum machine_mode innermode
;
7030 /* Doh! What's going on? */
7031 if (mclass
!= MODE_VECTOR_INT
7032 && mclass
!= MODE_VECTOR_FLOAT
7033 && mclass
!= MODE_VECTOR_FRACT
7034 && mclass
!= MODE_VECTOR_UFRACT
7035 && mclass
!= MODE_VECTOR_ACCUM
7036 && mclass
!= MODE_VECTOR_UACCUM
)
7039 /* Hardware support. Woo hoo! */
7040 if (targetm
.vector_mode_supported_p (mode
))
7043 innermode
= GET_MODE_INNER (mode
);
7045 /* We should probably return 1 if requesting V4DI and we have no DI,
7046 but we have V2DI, but this is probably very unlikely. */
7048 /* If we have support for the inner mode, we can safely emulate it.
7049 We may not have V2DI, but me can emulate with a pair of DIs. */
7050 return targetm
.scalar_mode_supported_p (innermode
);
7054 /* Handle a "mode" attribute; arguments as in
7055 struct attribute_spec.handler. */
7058 handle_mode_attribute (tree
*node
, tree name
, tree args
,
7059 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7062 tree ident
= TREE_VALUE (args
);
7064 *no_add_attrs
= true;
7066 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
7067 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7071 const char *p
= IDENTIFIER_POINTER (ident
);
7072 int len
= strlen (p
);
7073 enum machine_mode mode
= VOIDmode
;
7077 if (len
> 4 && p
[0] == '_' && p
[1] == '_'
7078 && p
[len
- 1] == '_' && p
[len
- 2] == '_')
7080 char *newp
= (char *) alloca (len
- 1);
7082 strcpy (newp
, &p
[2]);
7083 newp
[len
- 4] = '\0';
7087 /* Change this type to have a type with the specified mode.
7088 First check for the special modes. */
7089 if (!strcmp (p
, "byte"))
7091 else if (!strcmp (p
, "word"))
7093 else if (!strcmp (p
, "pointer"))
7095 else if (!strcmp (p
, "libgcc_cmp_return"))
7096 mode
= targetm
.libgcc_cmp_return_mode ();
7097 else if (!strcmp (p
, "libgcc_shift_count"))
7098 mode
= targetm
.libgcc_shift_count_mode ();
7099 else if (!strcmp (p
, "unwind_word"))
7100 mode
= targetm
.unwind_word_mode ();
7102 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
7103 if (!strcmp (p
, GET_MODE_NAME (j
)))
7105 mode
= (enum machine_mode
) j
;
7109 if (mode
== VOIDmode
)
7111 error ("unknown machine mode %qE", ident
);
7116 switch (GET_MODE_CLASS (mode
))
7119 case MODE_PARTIAL_INT
:
7121 case MODE_DECIMAL_FLOAT
:
7126 valid_mode
= targetm
.scalar_mode_supported_p (mode
);
7129 case MODE_COMPLEX_INT
:
7130 case MODE_COMPLEX_FLOAT
:
7131 valid_mode
= targetm
.scalar_mode_supported_p (GET_MODE_INNER (mode
));
7134 case MODE_VECTOR_INT
:
7135 case MODE_VECTOR_FLOAT
:
7136 case MODE_VECTOR_FRACT
:
7137 case MODE_VECTOR_UFRACT
:
7138 case MODE_VECTOR_ACCUM
:
7139 case MODE_VECTOR_UACCUM
:
7140 warning (OPT_Wattributes
, "specifying vector types with "
7141 "__attribute__ ((mode)) is deprecated");
7142 warning (OPT_Wattributes
,
7143 "use __attribute__ ((vector_size)) instead");
7144 valid_mode
= vector_mode_valid_p (mode
);
7152 error ("unable to emulate %qs", p
);
7156 if (POINTER_TYPE_P (type
))
7158 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
7159 tree (*fn
)(tree
, enum machine_mode
, bool);
7161 if (!targetm
.addr_space
.valid_pointer_mode (mode
, as
))
7163 error ("invalid pointer mode %qs", p
);
7167 if (TREE_CODE (type
) == POINTER_TYPE
)
7168 fn
= build_pointer_type_for_mode
;
7170 fn
= build_reference_type_for_mode
;
7171 typefm
= fn (TREE_TYPE (type
), mode
, false);
7175 /* For fixed-point modes, we need to test if the signness of type
7176 and the machine mode are consistent. */
7177 if (ALL_FIXED_POINT_MODE_P (mode
)
7178 && TYPE_UNSIGNED (type
) != UNSIGNED_FIXED_POINT_MODE_P (mode
))
7180 error ("signedness of type and machine mode %qs don%'t match", p
);
7183 /* For fixed-point modes, we need to pass saturating info. */
7184 typefm
= lang_hooks
.types
.type_for_mode (mode
,
7185 ALL_FIXED_POINT_MODE_P (mode
) ? TYPE_SATURATING (type
)
7186 : TYPE_UNSIGNED (type
));
7189 if (typefm
== NULL_TREE
)
7191 error ("no data type for mode %qs", p
);
7194 else if (TREE_CODE (type
) == ENUMERAL_TYPE
)
7196 /* For enumeral types, copy the precision from the integer
7197 type returned above. If not an INTEGER_TYPE, we can't use
7198 this mode for this type. */
7199 if (TREE_CODE (typefm
) != INTEGER_TYPE
)
7201 error ("cannot use mode %qs for enumeral types", p
);
7205 if (flags
& ATTR_FLAG_TYPE_IN_PLACE
)
7207 TYPE_PRECISION (type
) = TYPE_PRECISION (typefm
);
7212 /* We cannot build a type variant, as there's code that assumes
7213 that TYPE_MAIN_VARIANT has the same mode. This includes the
7214 debug generators. Instead, create a subrange type. This
7215 results in all of the enumeral values being emitted only once
7216 in the original, and the subtype gets them by reference. */
7217 if (TYPE_UNSIGNED (type
))
7218 typefm
= make_unsigned_type (TYPE_PRECISION (typefm
));
7220 typefm
= make_signed_type (TYPE_PRECISION (typefm
));
7221 TREE_TYPE (typefm
) = type
;
7224 else if (VECTOR_MODE_P (mode
)
7225 ? TREE_CODE (type
) != TREE_CODE (TREE_TYPE (typefm
))
7226 : TREE_CODE (type
) != TREE_CODE (typefm
))
7228 error ("mode %qs applied to inappropriate type", p
);
7238 /* Handle a "section" attribute; arguments as in
7239 struct attribute_spec.handler. */
7242 handle_section_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7243 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7247 if (targetm_common
.have_named_sections
)
7249 user_defined_section_attribute
= true;
7251 if ((TREE_CODE (decl
) == FUNCTION_DECL
7252 || TREE_CODE (decl
) == VAR_DECL
)
7253 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
7255 if (TREE_CODE (decl
) == VAR_DECL
7256 && current_function_decl
!= NULL_TREE
7257 && !TREE_STATIC (decl
))
7259 error_at (DECL_SOURCE_LOCATION (decl
),
7260 "section attribute cannot be specified for "
7262 *no_add_attrs
= true;
7265 /* The decl may have already been given a section attribute
7266 from a previous declaration. Ensure they match. */
7267 else if (DECL_SECTION_NAME (decl
) != NULL_TREE
7268 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl
)),
7269 TREE_STRING_POINTER (TREE_VALUE (args
))) != 0)
7271 error ("section of %q+D conflicts with previous declaration",
7273 *no_add_attrs
= true;
7275 else if (TREE_CODE (decl
) == VAR_DECL
7276 && !targetm
.have_tls
&& targetm
.emutls
.tmpl_section
7277 && DECL_THREAD_LOCAL_P (decl
))
7279 error ("section of %q+D cannot be overridden", *node
);
7280 *no_add_attrs
= true;
7283 DECL_SECTION_NAME (decl
) = TREE_VALUE (args
);
7287 error ("section attribute not allowed for %q+D", *node
);
7288 *no_add_attrs
= true;
7293 error_at (DECL_SOURCE_LOCATION (*node
),
7294 "section attributes are not supported for this target");
7295 *no_add_attrs
= true;
7301 /* Check whether ALIGN is a valid user-specified alignment. If so,
7302 return its base-2 log; if not, output an error and return -1. If
7303 ALLOW_ZERO then 0 is valid and should result in a return of -1 with
7306 check_user_alignment (const_tree align
, bool allow_zero
)
7310 if (TREE_CODE (align
) != INTEGER_CST
7311 || !INTEGRAL_TYPE_P (TREE_TYPE (align
)))
7313 error ("requested alignment is not an integer constant");
7316 else if (allow_zero
&& integer_zerop (align
))
7318 else if (tree_int_cst_sgn (align
) == -1
7319 || (i
= tree_log2 (align
)) == -1)
7321 error ("requested alignment is not a positive power of 2");
7324 else if (i
>= HOST_BITS_PER_INT
- BITS_PER_UNIT_LOG
)
7326 error ("requested alignment is too large");
7333 If in c++-11, check if the c++-11 alignment constraint with respect
7334 to fundamental alignment (in [dcl.align]) are satisfied. If not in
7335 c++-11 mode, does nothing.
7339 [* if the constant expression evaluates to a fundamental alignment,
7340 the alignment requirement of the declared entity shall be the
7341 specified fundamental alignment.
7343 * if the constant expression evaluates to an extended alignment
7344 and the implementation supports that alignment in the context
7345 of the declaration, the alignment of the declared entity shall
7348 * if the constant expression evaluates to an extended alignment
7349 and the implementation does not support that alignment in the
7350 context of the declaration, the program is ill-formed]. */
7353 check_cxx_fundamental_alignment_constraints (tree node
,
7357 bool alignment_too_large_p
= false;
7358 unsigned requested_alignment
= 1U << align_log
;
7359 unsigned max_align
= 0;
7361 if ((!(flags
& ATTR_FLAG_CXX11
) && !warn_cxx_compat
)
7362 || (node
== NULL_TREE
|| node
== error_mark_node
))
7365 if (cxx_fundamental_alignment_p (requested_alignment
))
7370 if (TREE_STATIC (node
))
7372 /* For file scope variables and static members, the target
7373 supports alignments that are at most
7374 MAX_OFILE_ALIGNMENT. */
7375 if (requested_alignment
> (max_align
= MAX_OFILE_ALIGNMENT
))
7376 alignment_too_large_p
= true;
7380 #ifdef BIGGEST_FIELD_ALIGNMENT
7381 #define MAX_TARGET_FIELD_ALIGNMENT BIGGEST_FIELD_ALIGNMENT
7383 #define MAX_TARGET_FIELD_ALIGNMENT BIGGEST_ALIGNMENT
7385 /* For non-static members, the target supports either
7386 alignments that at most either BIGGEST_FIELD_ALIGNMENT
7387 if it is defined or BIGGEST_ALIGNMENT. */
7388 max_align
= MAX_TARGET_FIELD_ALIGNMENT
;
7389 if (TREE_CODE (node
) == FIELD_DECL
7390 && requested_alignment
> (max_align
= MAX_TARGET_FIELD_ALIGNMENT
))
7391 alignment_too_large_p
= true;
7392 #undef MAX_TARGET_FIELD_ALIGNMENT
7393 /* For stack variables, the target supports at most
7394 MAX_STACK_ALIGNMENT. */
7395 else if (decl_function_context (node
) != NULL
7396 && requested_alignment
> (max_align
= MAX_STACK_ALIGNMENT
))
7397 alignment_too_large_p
= true;
7400 else if (TYPE_P (node
))
7402 /* Let's be liberal for types. */
7403 if (requested_alignment
> (max_align
= BIGGEST_ALIGNMENT
))
7404 alignment_too_large_p
= true;
7407 if (alignment_too_large_p
)
7408 pedwarn (input_location
, OPT_Wattributes
,
7409 "requested alignment %d is larger than %d",
7410 requested_alignment
, max_align
);
7412 return !alignment_too_large_p
;
7415 /* Handle a "aligned" attribute; arguments as in
7416 struct attribute_spec.handler. */
7419 handle_aligned_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7420 int flags
, bool *no_add_attrs
)
7422 tree decl
= NULL_TREE
;
7425 tree align_expr
= (args
? TREE_VALUE (args
)
7426 : size_int (ATTRIBUTE_ALIGNED_VALUE
/ BITS_PER_UNIT
));
7432 type
= &TREE_TYPE (decl
);
7433 is_type
= TREE_CODE (*node
) == TYPE_DECL
;
7435 else if (TYPE_P (*node
))
7436 type
= node
, is_type
= 1;
7438 if ((i
= check_user_alignment (align_expr
, false)) == -1
7439 || !check_cxx_fundamental_alignment_constraints (*node
, i
, flags
))
7440 *no_add_attrs
= true;
7443 if ((flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7444 /* OK, modify the type in place. */;
7445 /* If we have a TYPE_DECL, then copy the type, so that we
7446 don't accidentally modify a builtin type. See pushdecl. */
7447 else if (decl
&& TREE_TYPE (decl
) != error_mark_node
7448 && DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
)
7450 tree tt
= TREE_TYPE (decl
);
7451 *type
= build_variant_type_copy (*type
);
7452 DECL_ORIGINAL_TYPE (decl
) = tt
;
7453 TYPE_NAME (*type
) = decl
;
7454 TREE_USED (*type
) = TREE_USED (decl
);
7455 TREE_TYPE (decl
) = *type
;
7458 *type
= build_variant_type_copy (*type
);
7460 TYPE_ALIGN (*type
) = (1U << i
) * BITS_PER_UNIT
;
7461 TYPE_USER_ALIGN (*type
) = 1;
7463 else if (! VAR_OR_FUNCTION_DECL_P (decl
)
7464 && TREE_CODE (decl
) != FIELD_DECL
)
7466 error ("alignment may not be specified for %q+D", decl
);
7467 *no_add_attrs
= true;
7469 else if (DECL_USER_ALIGN (decl
)
7470 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
7471 /* C++-11 [dcl.align/4]:
7473 When multiple alignment-specifiers are specified for an
7474 entity, the alignment requirement shall be set to the
7475 strictest specified alignment.
7477 This formally comes from the c++11 specification but we are
7478 doing it for the GNU attribute syntax as well. */
7479 *no_add_attrs
= true;
7480 else if (TREE_CODE (decl
) == FUNCTION_DECL
7481 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
7483 if (DECL_USER_ALIGN (decl
))
7484 error ("alignment for %q+D was previously specified as %d "
7485 "and may not be decreased", decl
,
7486 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
7488 error ("alignment for %q+D must be at least %d", decl
,
7489 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
7490 *no_add_attrs
= true;
7494 DECL_ALIGN (decl
) = (1U << i
) * BITS_PER_UNIT
;
7495 DECL_USER_ALIGN (decl
) = 1;
7501 /* Handle a "weak" attribute; arguments as in
7502 struct attribute_spec.handler. */
7505 handle_weak_attribute (tree
*node
, tree name
,
7506 tree
ARG_UNUSED (args
),
7507 int ARG_UNUSED (flags
),
7508 bool * ARG_UNUSED (no_add_attrs
))
7510 if (TREE_CODE (*node
) == FUNCTION_DECL
7511 && DECL_DECLARED_INLINE_P (*node
))
7513 warning (OPT_Wattributes
, "inline function %q+D declared weak", *node
);
7514 *no_add_attrs
= true;
7516 else if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
7518 error ("indirect function %q+D cannot be declared weak", *node
);
7519 *no_add_attrs
= true;
7522 else if (TREE_CODE (*node
) == FUNCTION_DECL
7523 || TREE_CODE (*node
) == VAR_DECL
)
7524 declare_weak (*node
);
7526 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7531 /* Handle an "alias" or "ifunc" attribute; arguments as in
7532 struct attribute_spec.handler, except that IS_ALIAS tells us
7533 whether this is an alias as opposed to ifunc attribute. */
7536 handle_alias_ifunc_attribute (bool is_alias
, tree
*node
, tree name
, tree args
,
7541 if (TREE_CODE (decl
) != FUNCTION_DECL
7542 && (!is_alias
|| TREE_CODE (decl
) != VAR_DECL
))
7544 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7545 *no_add_attrs
= true;
7547 else if ((TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INITIAL (decl
))
7548 || (TREE_CODE (decl
) != FUNCTION_DECL
7549 && TREE_PUBLIC (decl
) && !DECL_EXTERNAL (decl
))
7550 /* A static variable declaration is always a tentative definition,
7551 but the alias is a non-tentative definition which overrides. */
7552 || (TREE_CODE (decl
) != FUNCTION_DECL
7553 && ! TREE_PUBLIC (decl
) && DECL_INITIAL (decl
)))
7555 error ("%q+D defined both normally and as %qE attribute", decl
, name
);
7556 *no_add_attrs
= true;
7560 && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
7561 || lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
))))
7563 error ("weak %q+D cannot be defined %qE", decl
, name
);
7564 *no_add_attrs
= true;
7568 /* Note that the very first time we process a nested declaration,
7569 decl_function_context will not be set. Indeed, *would* never
7570 be set except for the DECL_INITIAL/DECL_EXTERNAL frobbery that
7571 we do below. After such frobbery, pushdecl would set the context.
7572 In any case, this is never what we want. */
7573 else if (decl_function_context (decl
) == 0 && current_function_decl
== NULL
)
7577 id
= TREE_VALUE (args
);
7578 if (TREE_CODE (id
) != STRING_CST
)
7580 error ("attribute %qE argument not a string", name
);
7581 *no_add_attrs
= true;
7584 id
= get_identifier (TREE_STRING_POINTER (id
));
7585 /* This counts as a use of the object pointed to. */
7588 if (TREE_CODE (decl
) == FUNCTION_DECL
)
7589 DECL_INITIAL (decl
) = error_mark_node
;
7591 TREE_STATIC (decl
) = 1;
7594 /* ifuncs are also aliases, so set that attribute too. */
7595 DECL_ATTRIBUTES (decl
)
7596 = tree_cons (get_identifier ("alias"), args
, DECL_ATTRIBUTES (decl
));
7600 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7601 *no_add_attrs
= true;
7607 /* Handle an "alias" or "ifunc" attribute; arguments as in
7608 struct attribute_spec.handler. */
7611 handle_ifunc_attribute (tree
*node
, tree name
, tree args
,
7612 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7614 return handle_alias_ifunc_attribute (false, node
, name
, args
, no_add_attrs
);
7617 /* Handle an "alias" or "ifunc" attribute; arguments as in
7618 struct attribute_spec.handler. */
7621 handle_alias_attribute (tree
*node
, tree name
, tree args
,
7622 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7624 return handle_alias_ifunc_attribute (true, node
, name
, args
, no_add_attrs
);
7627 /* Handle a "weakref" attribute; arguments as in struct
7628 attribute_spec.handler. */
7631 handle_weakref_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7632 int flags
, bool *no_add_attrs
)
7634 tree attr
= NULL_TREE
;
7636 /* We must ignore the attribute when it is associated with
7637 local-scoped decls, since attribute alias is ignored and many
7638 such symbols do not even have a DECL_WEAK field. */
7639 if (decl_function_context (*node
)
7640 || current_function_decl
7641 || (TREE_CODE (*node
) != VAR_DECL
&& TREE_CODE (*node
) != FUNCTION_DECL
))
7643 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7644 *no_add_attrs
= true;
7648 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
7650 error ("indirect function %q+D cannot be declared weakref", *node
);
7651 *no_add_attrs
= true;
7655 /* The idea here is that `weakref("name")' mutates into `weakref,
7656 alias("name")', and weakref without arguments, in turn,
7657 implicitly adds weak. */
7661 attr
= tree_cons (get_identifier ("alias"), args
, attr
);
7662 attr
= tree_cons (get_identifier ("weakref"), NULL_TREE
, attr
);
7664 *no_add_attrs
= true;
7666 decl_attributes (node
, attr
, flags
);
7670 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node
)))
7671 error_at (DECL_SOURCE_LOCATION (*node
),
7672 "weakref attribute must appear before alias attribute");
7674 /* Can't call declare_weak because it wants this to be TREE_PUBLIC,
7675 and that isn't supported; and because it wants to add it to
7676 the list of weak decls, which isn't helpful. */
7677 DECL_WEAK (*node
) = 1;
7683 /* Handle an "visibility" attribute; arguments as in
7684 struct attribute_spec.handler. */
7687 handle_visibility_attribute (tree
*node
, tree name
, tree args
,
7688 int ARG_UNUSED (flags
),
7689 bool *ARG_UNUSED (no_add_attrs
))
7692 tree id
= TREE_VALUE (args
);
7693 enum symbol_visibility vis
;
7697 if (TREE_CODE (*node
) == ENUMERAL_TYPE
)
7699 else if (TREE_CODE (*node
) != RECORD_TYPE
&& TREE_CODE (*node
) != UNION_TYPE
)
7701 warning (OPT_Wattributes
, "%qE attribute ignored on non-class types",
7705 else if (TYPE_FIELDS (*node
))
7707 error ("%qE attribute ignored because %qT is already defined",
7712 else if (decl_function_context (decl
) != 0 || !TREE_PUBLIC (decl
))
7714 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7718 if (TREE_CODE (id
) != STRING_CST
)
7720 error ("visibility argument not a string");
7724 /* If this is a type, set the visibility on the type decl. */
7727 decl
= TYPE_NAME (decl
);
7730 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
7732 warning (OPT_Wattributes
, "%qE attribute ignored on types",
7738 if (strcmp (TREE_STRING_POINTER (id
), "default") == 0)
7739 vis
= VISIBILITY_DEFAULT
;
7740 else if (strcmp (TREE_STRING_POINTER (id
), "internal") == 0)
7741 vis
= VISIBILITY_INTERNAL
;
7742 else if (strcmp (TREE_STRING_POINTER (id
), "hidden") == 0)
7743 vis
= VISIBILITY_HIDDEN
;
7744 else if (strcmp (TREE_STRING_POINTER (id
), "protected") == 0)
7745 vis
= VISIBILITY_PROTECTED
;
7748 error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
7749 vis
= VISIBILITY_DEFAULT
;
7752 if (DECL_VISIBILITY_SPECIFIED (decl
)
7753 && vis
!= DECL_VISIBILITY (decl
))
7755 tree attributes
= (TYPE_P (*node
)
7756 ? TYPE_ATTRIBUTES (*node
)
7757 : DECL_ATTRIBUTES (decl
));
7758 if (lookup_attribute ("visibility", attributes
))
7759 error ("%qD redeclared with different visibility", decl
);
7760 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
7761 && lookup_attribute ("dllimport", attributes
))
7762 error ("%qD was declared %qs which implies default visibility",
7764 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
7765 && lookup_attribute ("dllexport", attributes
))
7766 error ("%qD was declared %qs which implies default visibility",
7770 DECL_VISIBILITY (decl
) = vis
;
7771 DECL_VISIBILITY_SPECIFIED (decl
) = 1;
7773 /* Go ahead and attach the attribute to the node as well. This is needed
7774 so we can determine whether we have VISIBILITY_DEFAULT because the
7775 visibility was not specified, or because it was explicitly overridden
7776 from the containing scope. */
7781 /* Determine the ELF symbol visibility for DECL, which is either a
7782 variable or a function. It is an error to use this function if a
7783 definition of DECL is not available in this translation unit.
7784 Returns true if the final visibility has been determined by this
7785 function; false if the caller is free to make additional
7789 c_determine_visibility (tree decl
)
7791 gcc_assert (TREE_CODE (decl
) == VAR_DECL
7792 || TREE_CODE (decl
) == FUNCTION_DECL
);
7794 /* If the user explicitly specified the visibility with an
7795 attribute, honor that. DECL_VISIBILITY will have been set during
7796 the processing of the attribute. We check for an explicit
7797 attribute, rather than just checking DECL_VISIBILITY_SPECIFIED,
7798 to distinguish the use of an attribute from the use of a "#pragma
7799 GCC visibility push(...)"; in the latter case we still want other
7800 considerations to be able to overrule the #pragma. */
7801 if (lookup_attribute ("visibility", DECL_ATTRIBUTES (decl
))
7802 || (TARGET_DLLIMPORT_DECL_ATTRIBUTES
7803 && (lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl
))
7804 || lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl
)))))
7807 /* Set default visibility to whatever the user supplied with
7808 visibility_specified depending on #pragma GCC visibility. */
7809 if (!DECL_VISIBILITY_SPECIFIED (decl
))
7811 if (visibility_options
.inpragma
7812 || DECL_VISIBILITY (decl
) != default_visibility
)
7814 DECL_VISIBILITY (decl
) = default_visibility
;
7815 DECL_VISIBILITY_SPECIFIED (decl
) = visibility_options
.inpragma
;
7816 /* If visibility changed and DECL already has DECL_RTL, ensure
7817 symbol flags are updated. */
7818 if (((TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
))
7819 || TREE_CODE (decl
) == FUNCTION_DECL
)
7820 && DECL_RTL_SET_P (decl
))
7821 make_decl_rtl (decl
);
7827 /* Handle an "tls_model" attribute; arguments as in
7828 struct attribute_spec.handler. */
7831 handle_tls_model_attribute (tree
*node
, tree name
, tree args
,
7832 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7836 enum tls_model kind
;
7838 *no_add_attrs
= true;
7840 if (TREE_CODE (decl
) != VAR_DECL
|| !DECL_THREAD_LOCAL_P (decl
))
7842 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7846 kind
= DECL_TLS_MODEL (decl
);
7847 id
= TREE_VALUE (args
);
7848 if (TREE_CODE (id
) != STRING_CST
)
7850 error ("tls_model argument not a string");
7854 if (!strcmp (TREE_STRING_POINTER (id
), "local-exec"))
7855 kind
= TLS_MODEL_LOCAL_EXEC
;
7856 else if (!strcmp (TREE_STRING_POINTER (id
), "initial-exec"))
7857 kind
= TLS_MODEL_INITIAL_EXEC
;
7858 else if (!strcmp (TREE_STRING_POINTER (id
), "local-dynamic"))
7859 kind
= optimize
? TLS_MODEL_LOCAL_DYNAMIC
: TLS_MODEL_GLOBAL_DYNAMIC
;
7860 else if (!strcmp (TREE_STRING_POINTER (id
), "global-dynamic"))
7861 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
7863 error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
7865 DECL_TLS_MODEL (decl
) = kind
;
7869 /* Handle a "no_instrument_function" attribute; arguments as in
7870 struct attribute_spec.handler. */
7873 handle_no_instrument_function_attribute (tree
*node
, tree name
,
7874 tree
ARG_UNUSED (args
),
7875 int ARG_UNUSED (flags
),
7880 if (TREE_CODE (decl
) != FUNCTION_DECL
)
7882 error_at (DECL_SOURCE_LOCATION (decl
),
7883 "%qE attribute applies only to functions", name
);
7884 *no_add_attrs
= true;
7886 else if (DECL_INITIAL (decl
))
7888 error_at (DECL_SOURCE_LOCATION (decl
),
7889 "can%'t set %qE attribute after definition", name
);
7890 *no_add_attrs
= true;
7893 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
7898 /* Handle a "malloc" attribute; arguments as in
7899 struct attribute_spec.handler. */
7902 handle_malloc_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7903 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7905 if (TREE_CODE (*node
) == FUNCTION_DECL
7906 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node
))))
7907 DECL_IS_MALLOC (*node
) = 1;
7910 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7911 *no_add_attrs
= true;
7917 /* Handle a "alloc_size" attribute; arguments as in
7918 struct attribute_spec.handler. */
7921 handle_alloc_size_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7922 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7924 unsigned arg_count
= type_num_arguments (*node
);
7925 for (; args
; args
= TREE_CHAIN (args
))
7927 tree position
= TREE_VALUE (args
);
7929 if (TREE_CODE (position
) != INTEGER_CST
7930 || TREE_INT_CST_HIGH (position
)
7931 || TREE_INT_CST_LOW (position
) < 1
7932 || TREE_INT_CST_LOW (position
) > arg_count
)
7934 warning (OPT_Wattributes
,
7935 "alloc_size parameter outside range");
7936 *no_add_attrs
= true;
7943 /* Handle a "fn spec" attribute; arguments as in
7944 struct attribute_spec.handler. */
7947 handle_fnspec_attribute (tree
*node ATTRIBUTE_UNUSED
, tree
ARG_UNUSED (name
),
7948 tree args
, int ARG_UNUSED (flags
),
7949 bool *no_add_attrs ATTRIBUTE_UNUSED
)
7952 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
7953 && !TREE_CHAIN (args
));
7957 /* Handle a "warn_unused" attribute; arguments as in
7958 struct attribute_spec.handler. */
7961 handle_warn_unused_attribute (tree
*node
, tree name
,
7962 tree args ATTRIBUTE_UNUSED
,
7963 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
7966 /* Do nothing else, just set the attribute. We'll get at
7967 it later with lookup_attribute. */
7971 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7972 *no_add_attrs
= true;
7978 /* Handle a "returns_twice" attribute; arguments as in
7979 struct attribute_spec.handler. */
7982 handle_returns_twice_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7983 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7985 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7986 DECL_IS_RETURNS_TWICE (*node
) = 1;
7989 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7990 *no_add_attrs
= true;
7996 /* Handle a "no_limit_stack" attribute; arguments as in
7997 struct attribute_spec.handler. */
8000 handle_no_limit_stack_attribute (tree
*node
, tree name
,
8001 tree
ARG_UNUSED (args
),
8002 int ARG_UNUSED (flags
),
8007 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8009 error_at (DECL_SOURCE_LOCATION (decl
),
8010 "%qE attribute applies only to functions", name
);
8011 *no_add_attrs
= true;
8013 else if (DECL_INITIAL (decl
))
8015 error_at (DECL_SOURCE_LOCATION (decl
),
8016 "can%'t set %qE attribute after definition", name
);
8017 *no_add_attrs
= true;
8020 DECL_NO_LIMIT_STACK (decl
) = 1;
8025 /* Handle a "pure" attribute; arguments as in
8026 struct attribute_spec.handler. */
8029 handle_pure_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8030 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8032 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8033 DECL_PURE_P (*node
) = 1;
8034 /* ??? TODO: Support types. */
8037 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8038 *no_add_attrs
= true;
8044 /* Digest an attribute list destined for a transactional memory statement.
8045 ALLOWED is the set of attributes that are allowed for this statement;
8046 return the attribute we parsed. Multiple attributes are never allowed. */
8049 parse_tm_stmt_attr (tree attrs
, int allowed
)
8054 for ( ; attrs
; attrs
= TREE_CHAIN (attrs
))
8056 tree a
= TREE_PURPOSE (attrs
);
8059 if (is_attribute_p ("outer", a
))
8060 m
= TM_STMT_ATTR_OUTER
;
8062 if ((m
& allowed
) == 0)
8064 warning (OPT_Wattributes
, "%qE attribute directive ignored", a
);
8073 else if (m_seen
== m
)
8074 warning (OPT_Wattributes
, "%qE attribute duplicated", a
);
8076 warning (OPT_Wattributes
, "%qE attribute follows %qE", a
, a_seen
);
8082 /* Transform a TM attribute name into a maskable integer and back.
8083 Note that NULL (i.e. no attribute) is mapped to UNKNOWN, corresponding
8084 to how the lack of an attribute is treated. */
8087 tm_attr_to_mask (tree attr
)
8091 if (is_attribute_p ("transaction_safe", attr
))
8092 return TM_ATTR_SAFE
;
8093 if (is_attribute_p ("transaction_callable", attr
))
8094 return TM_ATTR_CALLABLE
;
8095 if (is_attribute_p ("transaction_pure", attr
))
8096 return TM_ATTR_PURE
;
8097 if (is_attribute_p ("transaction_unsafe", attr
))
8098 return TM_ATTR_IRREVOCABLE
;
8099 if (is_attribute_p ("transaction_may_cancel_outer", attr
))
8100 return TM_ATTR_MAY_CANCEL_OUTER
;
8105 tm_mask_to_attr (int mask
)
8111 str
= "transaction_safe";
8113 case TM_ATTR_CALLABLE
:
8114 str
= "transaction_callable";
8117 str
= "transaction_pure";
8119 case TM_ATTR_IRREVOCABLE
:
8120 str
= "transaction_unsafe";
8122 case TM_ATTR_MAY_CANCEL_OUTER
:
8123 str
= "transaction_may_cancel_outer";
8128 return get_identifier (str
);
8131 /* Return the first TM attribute seen in LIST. */
8134 find_tm_attribute (tree list
)
8136 for (; list
; list
= TREE_CHAIN (list
))
8138 tree name
= TREE_PURPOSE (list
);
8139 if (tm_attr_to_mask (name
) != 0)
8145 /* Handle the TM attributes; arguments as in struct attribute_spec.handler.
8146 Here we accept only function types, and verify that none of the other
8147 function TM attributes are also applied. */
8148 /* ??? We need to accept class types for C++, but not C. This greatly
8149 complicates this function, since we can no longer rely on the extra
8150 processing given by function_type_required. */
8153 handle_tm_attribute (tree
*node
, tree name
, tree args
,
8154 int flags
, bool *no_add_attrs
)
8156 /* Only one path adds the attribute; others don't. */
8157 *no_add_attrs
= true;
8159 switch (TREE_CODE (*node
))
8163 /* Only tm_callable and tm_safe apply to classes. */
8164 if (tm_attr_to_mask (name
) & ~(TM_ATTR_SAFE
| TM_ATTR_CALLABLE
))
8171 tree old_name
= find_tm_attribute (TYPE_ATTRIBUTES (*node
));
8172 if (old_name
== name
)
8174 else if (old_name
!= NULL_TREE
)
8175 error ("type was previously declared %qE", old_name
);
8177 *no_add_attrs
= false;
8183 enum tree_code subcode
= TREE_CODE (TREE_TYPE (*node
));
8184 if (subcode
== FUNCTION_TYPE
|| subcode
== METHOD_TYPE
)
8186 tree fn_tmp
= TREE_TYPE (*node
);
8187 decl_attributes (&fn_tmp
, tree_cons (name
, args
, NULL
), 0);
8188 *node
= build_pointer_type (fn_tmp
);
8195 /* If a function is next, pass it on to be tried next. */
8196 if (flags
& (int) ATTR_FLAG_FUNCTION_NEXT
)
8197 return tree_cons (name
, args
, NULL
);
8200 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8207 /* Handle the TM_WRAP attribute; arguments as in
8208 struct attribute_spec.handler. */
8211 handle_tm_wrap_attribute (tree
*node
, tree name
, tree args
,
8212 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8216 /* We don't need the attribute even on success, since we
8217 record the entry in an external table. */
8218 *no_add_attrs
= true;
8220 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8221 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8224 tree wrap_decl
= TREE_VALUE (args
);
8225 if (TREE_CODE (wrap_decl
) != IDENTIFIER_NODE
8226 && TREE_CODE (wrap_decl
) != VAR_DECL
8227 && TREE_CODE (wrap_decl
) != FUNCTION_DECL
)
8228 error ("%qE argument not an identifier", name
);
8231 if (TREE_CODE (wrap_decl
) == IDENTIFIER_NODE
)
8232 wrap_decl
= lookup_name (wrap_decl
);
8233 if (wrap_decl
&& TREE_CODE (wrap_decl
) == FUNCTION_DECL
)
8235 if (lang_hooks
.types_compatible_p (TREE_TYPE (decl
),
8236 TREE_TYPE (wrap_decl
)))
8237 record_tm_replacement (wrap_decl
, decl
);
8239 error ("%qD is not compatible with %qD", wrap_decl
, decl
);
8242 error ("transaction_wrap argument is not a function");
8249 /* Ignore the given attribute. Used when this attribute may be usefully
8250 overridden by the target, but is not used generically. */
8253 ignore_attribute (tree
* ARG_UNUSED (node
), tree
ARG_UNUSED (name
),
8254 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
8257 *no_add_attrs
= true;
8261 /* Handle a "no vops" attribute; arguments as in
8262 struct attribute_spec.handler. */
8265 handle_novops_attribute (tree
*node
, tree
ARG_UNUSED (name
),
8266 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
8267 bool *ARG_UNUSED (no_add_attrs
))
8269 gcc_assert (TREE_CODE (*node
) == FUNCTION_DECL
);
8270 DECL_IS_NOVOPS (*node
) = 1;
8274 /* Handle a "deprecated" attribute; arguments as in
8275 struct attribute_spec.handler. */
8278 handle_deprecated_attribute (tree
*node
, tree name
,
8279 tree args
, int flags
,
8282 tree type
= NULL_TREE
;
8284 tree what
= NULL_TREE
;
8287 *no_add_attrs
= true;
8288 else if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
8290 error ("deprecated message is not a string");
8291 *no_add_attrs
= true;
8297 type
= TREE_TYPE (decl
);
8299 if (TREE_CODE (decl
) == TYPE_DECL
8300 || TREE_CODE (decl
) == PARM_DECL
8301 || TREE_CODE (decl
) == VAR_DECL
8302 || TREE_CODE (decl
) == FUNCTION_DECL
8303 || TREE_CODE (decl
) == FIELD_DECL
8304 || objc_method_decl (TREE_CODE (decl
)))
8305 TREE_DEPRECATED (decl
) = 1;
8309 else if (TYPE_P (*node
))
8311 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
8312 *node
= build_variant_type_copy (*node
);
8313 TREE_DEPRECATED (*node
) = 1;
8321 *no_add_attrs
= true;
8322 if (type
&& TYPE_NAME (type
))
8324 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
8325 what
= TYPE_NAME (*node
);
8326 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
8327 && DECL_NAME (TYPE_NAME (type
)))
8328 what
= DECL_NAME (TYPE_NAME (type
));
8331 warning (OPT_Wattributes
, "%qE attribute ignored for %qE", name
, what
);
8333 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8339 /* Handle a "vector_size" attribute; arguments as in
8340 struct attribute_spec.handler. */
8343 handle_vector_size_attribute (tree
*node
, tree name
, tree args
,
8344 int ARG_UNUSED (flags
),
8347 unsigned HOST_WIDE_INT vecsize
, nunits
;
8348 enum machine_mode orig_mode
;
8349 tree type
= *node
, new_type
, size
;
8351 *no_add_attrs
= true;
8353 size
= TREE_VALUE (args
);
8355 if (!host_integerp (size
, 1))
8357 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8361 /* Get the vector size (in bytes). */
8362 vecsize
= tree_low_cst (size
, 1);
8364 /* We need to provide for vector pointers, vector arrays, and
8365 functions returning vectors. For example:
8367 __attribute__((vector_size(16))) short *foo;
8369 In this case, the mode is SI, but the type being modified is
8370 HI, so we need to look further. */
8372 while (POINTER_TYPE_P (type
)
8373 || TREE_CODE (type
) == FUNCTION_TYPE
8374 || TREE_CODE (type
) == METHOD_TYPE
8375 || TREE_CODE (type
) == ARRAY_TYPE
8376 || TREE_CODE (type
) == OFFSET_TYPE
)
8377 type
= TREE_TYPE (type
);
8379 /* Get the mode of the type being modified. */
8380 orig_mode
= TYPE_MODE (type
);
8382 if ((!INTEGRAL_TYPE_P (type
)
8383 && !SCALAR_FLOAT_TYPE_P (type
)
8384 && !FIXED_POINT_TYPE_P (type
))
8385 || (!SCALAR_FLOAT_MODE_P (orig_mode
)
8386 && GET_MODE_CLASS (orig_mode
) != MODE_INT
8387 && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode
))
8388 || !host_integerp (TYPE_SIZE_UNIT (type
), 1)
8389 || TREE_CODE (type
) == BOOLEAN_TYPE
)
8391 error ("invalid vector type for attribute %qE", name
);
8395 if (vecsize
% tree_low_cst (TYPE_SIZE_UNIT (type
), 1))
8397 error ("vector size not an integral multiple of component size");
8403 error ("zero vector size");
8407 /* Calculate how many units fit in the vector. */
8408 nunits
= vecsize
/ tree_low_cst (TYPE_SIZE_UNIT (type
), 1);
8409 if (nunits
& (nunits
- 1))
8411 error ("number of components of the vector not a power of two");
8415 new_type
= build_vector_type (type
, nunits
);
8417 /* Build back pointers if needed. */
8418 *node
= lang_hooks
.types
.reconstruct_complex_type (*node
, new_type
);
8423 /* Handle the "nonnull" attribute. */
8425 handle_nonnull_attribute (tree
*node
, tree
ARG_UNUSED (name
),
8426 tree args
, int ARG_UNUSED (flags
),
8430 unsigned HOST_WIDE_INT attr_arg_num
;
8432 /* If no arguments are specified, all pointer arguments should be
8433 non-null. Verify a full prototype is given so that the arguments
8434 will have the correct types when we actually check them later. */
8437 if (!prototype_p (type
))
8439 error ("nonnull attribute without arguments on a non-prototype");
8440 *no_add_attrs
= true;
8445 /* Argument list specified. Verify that each argument number references
8446 a pointer argument. */
8447 for (attr_arg_num
= 1; args
; args
= TREE_CHAIN (args
))
8449 unsigned HOST_WIDE_INT arg_num
= 0, ck_num
;
8451 if (!get_nonnull_operand (TREE_VALUE (args
), &arg_num
))
8453 error ("nonnull argument has invalid operand number (argument %lu)",
8454 (unsigned long) attr_arg_num
);
8455 *no_add_attrs
= true;
8459 if (prototype_p (type
))
8461 function_args_iterator iter
;
8464 function_args_iter_init (&iter
, type
);
8465 for (ck_num
= 1; ; ck_num
++, function_args_iter_next (&iter
))
8467 argument
= function_args_iter_cond (&iter
);
8468 if (argument
== NULL_TREE
|| ck_num
== arg_num
)
8473 || TREE_CODE (argument
) == VOID_TYPE
)
8475 error ("nonnull argument with out-of-range operand number (argument %lu, operand %lu)",
8476 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
8477 *no_add_attrs
= true;
8481 if (TREE_CODE (argument
) != POINTER_TYPE
)
8483 error ("nonnull argument references non-pointer operand (argument %lu, operand %lu)",
8484 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
8485 *no_add_attrs
= true;
8494 /* Check the argument list of a function call for null in argument slots
8495 that are marked as requiring a non-null pointer argument. The NARGS
8496 arguments are passed in the array ARGARRAY.
8500 check_function_nonnull (tree attrs
, int nargs
, tree
*argarray
)
8505 attrs
= lookup_attribute ("nonnull", attrs
);
8506 if (attrs
== NULL_TREE
)
8510 /* See if any of the nonnull attributes has no arguments. If so,
8511 then every pointer argument is checked (in which case the check
8512 for pointer type is done in check_nonnull_arg). */
8513 if (TREE_VALUE (a
) != NULL_TREE
)
8515 a
= lookup_attribute ("nonnull", TREE_CHAIN (a
));
8516 while (a
!= NULL_TREE
&& TREE_VALUE (a
) != NULL_TREE
);
8519 for (i
= 0; i
< nargs
; i
++)
8520 check_function_arguments_recurse (check_nonnull_arg
, NULL
, argarray
[i
],
8524 /* Walk the argument list. If we encounter an argument number we
8525 should check for non-null, do it. */
8526 for (i
= 0; i
< nargs
; i
++)
8528 for (a
= attrs
; ; a
= TREE_CHAIN (a
))
8530 a
= lookup_attribute ("nonnull", a
);
8531 if (a
== NULL_TREE
|| nonnull_check_p (TREE_VALUE (a
), i
+ 1))
8536 check_function_arguments_recurse (check_nonnull_arg
, NULL
,
8537 argarray
[i
], i
+ 1);
8542 /* Check that the Nth argument of a function call (counting backwards
8543 from the end) is a (pointer)0. The NARGS arguments are passed in the
8547 check_function_sentinel (const_tree fntype
, int nargs
, tree
*argarray
)
8549 tree attr
= lookup_attribute ("sentinel", TYPE_ATTRIBUTES (fntype
));
8556 function_args_iterator iter
;
8559 /* Skip over the named arguments. */
8560 FOREACH_FUNCTION_ARGS (fntype
, t
, iter
)
8567 if (TREE_VALUE (attr
))
8569 tree p
= TREE_VALUE (TREE_VALUE (attr
));
8570 pos
= TREE_INT_CST_LOW (p
);
8573 /* The sentinel must be one of the varargs, i.e.
8574 in position >= the number of fixed arguments. */
8575 if ((nargs
- 1 - pos
) < len
)
8577 warning (OPT_Wformat_
,
8578 "not enough variable arguments to fit a sentinel");
8582 /* Validate the sentinel. */
8583 sentinel
= argarray
[nargs
- 1 - pos
];
8584 if ((!POINTER_TYPE_P (TREE_TYPE (sentinel
))
8585 || !integer_zerop (sentinel
))
8586 /* Although __null (in C++) is only an integer we allow it
8587 nevertheless, as we are guaranteed that it's exactly
8588 as wide as a pointer, and we don't want to force
8589 users to cast the NULL they have written there.
8590 We warn with -Wstrict-null-sentinel, though. */
8591 && (warn_strict_null_sentinel
|| null_node
!= sentinel
))
8592 warning (OPT_Wformat_
, "missing sentinel in function call");
8596 /* Helper for check_function_nonnull; given a list of operands which
8597 must be non-null in ARGS, determine if operand PARAM_NUM should be
8601 nonnull_check_p (tree args
, unsigned HOST_WIDE_INT param_num
)
8603 unsigned HOST_WIDE_INT arg_num
= 0;
8605 for (; args
; args
= TREE_CHAIN (args
))
8607 bool found
= get_nonnull_operand (TREE_VALUE (args
), &arg_num
);
8611 if (arg_num
== param_num
)
8617 /* Check that the function argument PARAM (which is operand number
8618 PARAM_NUM) is non-null. This is called by check_function_nonnull
8619 via check_function_arguments_recurse. */
8622 check_nonnull_arg (void * ARG_UNUSED (ctx
), tree param
,
8623 unsigned HOST_WIDE_INT param_num
)
8625 /* Just skip checking the argument if it's not a pointer. This can
8626 happen if the "nonnull" attribute was given without an operand
8627 list (which means to check every pointer argument). */
8629 if (TREE_CODE (TREE_TYPE (param
)) != POINTER_TYPE
)
8632 if (integer_zerop (param
))
8633 warning (OPT_Wnonnull
, "null argument where non-null required "
8634 "(argument %lu)", (unsigned long) param_num
);
8637 /* Helper for nonnull attribute handling; fetch the operand number
8638 from the attribute argument list. */
8641 get_nonnull_operand (tree arg_num_expr
, unsigned HOST_WIDE_INT
*valp
)
8643 /* Verify the arg number is a constant. */
8644 if (TREE_CODE (arg_num_expr
) != INTEGER_CST
8645 || TREE_INT_CST_HIGH (arg_num_expr
) != 0)
8648 *valp
= TREE_INT_CST_LOW (arg_num_expr
);
8652 /* Handle a "nothrow" attribute; arguments as in
8653 struct attribute_spec.handler. */
8656 handle_nothrow_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8657 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8659 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8660 TREE_NOTHROW (*node
) = 1;
8661 /* ??? TODO: Support types. */
8664 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8665 *no_add_attrs
= true;
8671 /* Handle a "cleanup" attribute; arguments as in
8672 struct attribute_spec.handler. */
8675 handle_cleanup_attribute (tree
*node
, tree name
, tree args
,
8676 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8679 tree cleanup_id
, cleanup_decl
;
8681 /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
8682 for global destructors in C++. This requires infrastructure that
8683 we don't have generically at the moment. It's also not a feature
8684 we'd be missing too much, since we do have attribute constructor. */
8685 if (TREE_CODE (decl
) != VAR_DECL
|| TREE_STATIC (decl
))
8687 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8688 *no_add_attrs
= true;
8692 /* Verify that the argument is a function in scope. */
8693 /* ??? We could support pointers to functions here as well, if
8694 that was considered desirable. */
8695 cleanup_id
= TREE_VALUE (args
);
8696 if (TREE_CODE (cleanup_id
) != IDENTIFIER_NODE
)
8698 error ("cleanup argument not an identifier");
8699 *no_add_attrs
= true;
8702 cleanup_decl
= lookup_name (cleanup_id
);
8703 if (!cleanup_decl
|| TREE_CODE (cleanup_decl
) != FUNCTION_DECL
)
8705 error ("cleanup argument not a function");
8706 *no_add_attrs
= true;
8710 /* That the function has proper type is checked with the
8711 eventual call to build_function_call. */
8716 /* Handle a "warn_unused_result" attribute. No special handling. */
8719 handle_warn_unused_result_attribute (tree
*node
, tree name
,
8720 tree
ARG_UNUSED (args
),
8721 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8723 /* Ignore the attribute for functions not returning any value. */
8724 if (VOID_TYPE_P (TREE_TYPE (*node
)))
8726 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8727 *no_add_attrs
= true;
8733 /* Handle a "sentinel" attribute. */
8736 handle_sentinel_attribute (tree
*node
, tree name
, tree args
,
8737 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8739 if (!prototype_p (*node
))
8741 warning (OPT_Wattributes
,
8742 "%qE attribute requires prototypes with named arguments", name
);
8743 *no_add_attrs
= true;
8747 if (!stdarg_p (*node
))
8749 warning (OPT_Wattributes
,
8750 "%qE attribute only applies to variadic functions", name
);
8751 *no_add_attrs
= true;
8757 tree position
= TREE_VALUE (args
);
8759 if (TREE_CODE (position
) != INTEGER_CST
)
8761 warning (OPT_Wattributes
,
8762 "requested position is not an integer constant");
8763 *no_add_attrs
= true;
8767 if (tree_int_cst_lt (position
, integer_zero_node
))
8769 warning (OPT_Wattributes
,
8770 "requested position is less than zero");
8771 *no_add_attrs
= true;
8779 /* Handle a "type_generic" attribute. */
8782 handle_type_generic_attribute (tree
*node
, tree
ARG_UNUSED (name
),
8783 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
8784 bool * ARG_UNUSED (no_add_attrs
))
8786 /* Ensure we have a function type. */
8787 gcc_assert (TREE_CODE (*node
) == FUNCTION_TYPE
);
8789 /* Ensure we have a variadic function. */
8790 gcc_assert (!prototype_p (*node
) || stdarg_p (*node
));
8795 /* Handle a "target" attribute. */
8798 handle_target_attribute (tree
*node
, tree name
, tree args
, int flags
,
8801 /* Ensure we have a function type. */
8802 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8804 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8805 *no_add_attrs
= true;
8807 else if (! targetm
.target_option
.valid_attribute_p (*node
, name
, args
,
8809 *no_add_attrs
= true;
8814 /* Arguments being collected for optimization. */
8815 typedef const char *const_char_p
; /* For DEF_VEC_P. */
8816 static GTY(()) vec
<const_char_p
, va_gc
> *optimize_args
;
8819 /* Inner function to convert a TREE_LIST to argv string to parse the optimize
8820 options in ARGS. ATTR_P is true if this is for attribute(optimize), and
8821 false for #pragma GCC optimize. */
8824 parse_optimize_options (tree args
, bool attr_p
)
8829 int saved_flag_strict_aliasing
;
8830 const char **opt_argv
;
8831 struct cl_decoded_option
*decoded_options
;
8832 unsigned int decoded_options_count
;
8835 /* Build up argv vector. Just in case the string is stored away, use garbage
8836 collected strings. */
8837 vec_safe_truncate (optimize_args
, 0);
8838 vec_safe_push (optimize_args
, (const char *) NULL
);
8840 for (ap
= args
; ap
!= NULL_TREE
; ap
= TREE_CHAIN (ap
))
8842 tree value
= TREE_VALUE (ap
);
8844 if (TREE_CODE (value
) == INTEGER_CST
)
8847 sprintf (buffer
, "-O%ld", (long) TREE_INT_CST_LOW (value
));
8848 vec_safe_push (optimize_args
, ggc_strdup (buffer
));
8851 else if (TREE_CODE (value
) == STRING_CST
)
8853 /* Split string into multiple substrings. */
8854 size_t len
= TREE_STRING_LENGTH (value
);
8855 char *p
= ASTRDUP (TREE_STRING_POINTER (value
));
8856 char *end
= p
+ len
;
8860 while (next_p
!= NULL
)
8866 comma
= strchr (p
, ',');
8879 r
= q
= (char *) ggc_alloc_atomic (len2
+ 3);
8881 /* If the user supplied -Oxxx or -fxxx, only allow -Oxxx or -fxxx
8883 if (*p
== '-' && p
[1] != 'O' && p
[1] != 'f')
8887 warning (OPT_Wattributes
,
8888 "bad option %s to optimize attribute", p
);
8890 warning (OPT_Wpragmas
,
8891 "bad option %s to pragma attribute", p
);
8899 /* Assume that Ox is -Ox, a numeric value is -Ox, a s by
8900 itself is -Os, and any other switch begins with a -f. */
8901 if ((*p
>= '0' && *p
<= '9')
8902 || (p
[0] == 's' && p
[1] == '\0'))
8908 memcpy (r
, p
, len2
);
8910 vec_safe_push (optimize_args
, (const char *) q
);
8916 opt_argc
= optimize_args
->length ();
8917 opt_argv
= (const char **) alloca (sizeof (char *) * (opt_argc
+ 1));
8919 for (i
= 1; i
< opt_argc
; i
++)
8920 opt_argv
[i
] = (*optimize_args
)[i
];
8922 saved_flag_strict_aliasing
= flag_strict_aliasing
;
8924 /* Now parse the options. */
8925 decode_cmdline_options_to_array_default_mask (opt_argc
, opt_argv
,
8927 &decoded_options_count
);
8928 decode_options (&global_options
, &global_options_set
,
8929 decoded_options
, decoded_options_count
,
8930 input_location
, global_dc
);
8932 targetm
.override_options_after_change();
8934 /* Don't allow changing -fstrict-aliasing. */
8935 flag_strict_aliasing
= saved_flag_strict_aliasing
;
8937 optimize_args
->truncate (0);
8941 /* For handling "optimize" attribute. arguments as in
8942 struct attribute_spec.handler. */
8945 handle_optimize_attribute (tree
*node
, tree name
, tree args
,
8946 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8948 /* Ensure we have a function type. */
8949 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8951 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8952 *no_add_attrs
= true;
8956 struct cl_optimization cur_opts
;
8957 tree old_opts
= DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
);
8959 /* Save current options. */
8960 cl_optimization_save (&cur_opts
, &global_options
);
8962 /* If we previously had some optimization options, use them as the
8965 cl_optimization_restore (&global_options
,
8966 TREE_OPTIMIZATION (old_opts
));
8968 /* Parse options, and update the vector. */
8969 parse_optimize_options (args
, true);
8970 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
)
8971 = build_optimization_node ();
8973 /* Restore current options. */
8974 cl_optimization_restore (&global_options
, &cur_opts
);
8980 /* Handle a "no_split_stack" attribute. */
8983 handle_no_split_stack_attribute (tree
*node
, tree name
,
8984 tree
ARG_UNUSED (args
),
8985 int ARG_UNUSED (flags
),
8990 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8992 error_at (DECL_SOURCE_LOCATION (decl
),
8993 "%qE attribute applies only to functions", name
);
8994 *no_add_attrs
= true;
8996 else if (DECL_INITIAL (decl
))
8998 error_at (DECL_SOURCE_LOCATION (decl
),
8999 "can%'t set %qE attribute after definition", name
);
9000 *no_add_attrs
= true;
9006 /* Check for valid arguments being passed to a function with FNTYPE.
9007 There are NARGS arguments in the array ARGARRAY. */
9009 check_function_arguments (const_tree fntype
, int nargs
, tree
*argarray
)
9011 /* Check for null being passed in a pointer argument that must be
9012 non-null. We also need to do this if format checking is enabled. */
9015 check_function_nonnull (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
9017 /* Check for errors in format strings. */
9019 if (warn_format
|| warn_suggest_attribute_format
)
9020 check_function_format (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
9023 check_function_sentinel (fntype
, nargs
, argarray
);
9026 /* Generic argument checking recursion routine. PARAM is the argument to
9027 be checked. PARAM_NUM is the number of the argument. CALLBACK is invoked
9028 once the argument is resolved. CTX is context for the callback. */
9030 check_function_arguments_recurse (void (*callback
)
9031 (void *, tree
, unsigned HOST_WIDE_INT
),
9032 void *ctx
, tree param
,
9033 unsigned HOST_WIDE_INT param_num
)
9035 if (CONVERT_EXPR_P (param
)
9036 && (TYPE_PRECISION (TREE_TYPE (param
))
9037 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (param
, 0)))))
9039 /* Strip coercion. */
9040 check_function_arguments_recurse (callback
, ctx
,
9041 TREE_OPERAND (param
, 0), param_num
);
9045 if (TREE_CODE (param
) == CALL_EXPR
)
9047 tree type
= TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (param
)));
9049 bool found_format_arg
= false;
9051 /* See if this is a call to a known internationalization function
9052 that modifies a format arg. Such a function may have multiple
9053 format_arg attributes (for example, ngettext). */
9055 for (attrs
= TYPE_ATTRIBUTES (type
);
9057 attrs
= TREE_CHAIN (attrs
))
9058 if (is_attribute_p ("format_arg", TREE_PURPOSE (attrs
)))
9061 tree format_num_expr
;
9064 call_expr_arg_iterator iter
;
9066 /* Extract the argument number, which was previously checked
9068 format_num_expr
= TREE_VALUE (TREE_VALUE (attrs
));
9070 gcc_assert (TREE_CODE (format_num_expr
) == INTEGER_CST
9071 && !TREE_INT_CST_HIGH (format_num_expr
));
9073 format_num
= TREE_INT_CST_LOW (format_num_expr
);
9075 for (inner_arg
= first_call_expr_arg (param
, &iter
), i
= 1;
9077 inner_arg
= next_call_expr_arg (&iter
), i
++)
9078 if (i
== format_num
)
9080 check_function_arguments_recurse (callback
, ctx
,
9081 inner_arg
, param_num
);
9082 found_format_arg
= true;
9087 /* If we found a format_arg attribute and did a recursive check,
9088 we are done with checking this argument. Otherwise, we continue
9089 and this will be considered a non-literal. */
9090 if (found_format_arg
)
9094 if (TREE_CODE (param
) == COND_EXPR
)
9096 /* Check both halves of the conditional expression. */
9097 check_function_arguments_recurse (callback
, ctx
,
9098 TREE_OPERAND (param
, 1), param_num
);
9099 check_function_arguments_recurse (callback
, ctx
,
9100 TREE_OPERAND (param
, 2), param_num
);
9104 (*callback
) (ctx
, param
, param_num
);
9107 /* Checks for a builtin function FNDECL that the number of arguments
9108 NARGS against the required number REQUIRED and issues an error if
9109 there is a mismatch. Returns true if the number of arguments is
9110 correct, otherwise false. */
9113 builtin_function_validate_nargs (tree fndecl
, int nargs
, int required
)
9115 if (nargs
< required
)
9117 error_at (input_location
,
9118 "not enough arguments to function %qE", fndecl
);
9121 else if (nargs
> required
)
9123 error_at (input_location
,
9124 "too many arguments to function %qE", fndecl
);
9130 /* Verifies the NARGS arguments ARGS to the builtin function FNDECL.
9131 Returns false if there was an error, otherwise true. */
9134 check_builtin_function_arguments (tree fndecl
, int nargs
, tree
*args
)
9136 if (!DECL_BUILT_IN (fndecl
)
9137 || DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_NORMAL
)
9140 switch (DECL_FUNCTION_CODE (fndecl
))
9142 case BUILT_IN_CONSTANT_P
:
9143 return builtin_function_validate_nargs (fndecl
, nargs
, 1);
9145 case BUILT_IN_ISFINITE
:
9146 case BUILT_IN_ISINF
:
9147 case BUILT_IN_ISINF_SIGN
:
9148 case BUILT_IN_ISNAN
:
9149 case BUILT_IN_ISNORMAL
:
9150 if (builtin_function_validate_nargs (fndecl
, nargs
, 1))
9152 if (TREE_CODE (TREE_TYPE (args
[0])) != REAL_TYPE
)
9154 error ("non-floating-point argument in call to "
9155 "function %qE", fndecl
);
9162 case BUILT_IN_ISGREATER
:
9163 case BUILT_IN_ISGREATEREQUAL
:
9164 case BUILT_IN_ISLESS
:
9165 case BUILT_IN_ISLESSEQUAL
:
9166 case BUILT_IN_ISLESSGREATER
:
9167 case BUILT_IN_ISUNORDERED
:
9168 if (builtin_function_validate_nargs (fndecl
, nargs
, 2))
9170 enum tree_code code0
, code1
;
9171 code0
= TREE_CODE (TREE_TYPE (args
[0]));
9172 code1
= TREE_CODE (TREE_TYPE (args
[1]));
9173 if (!((code0
== REAL_TYPE
&& code1
== REAL_TYPE
)
9174 || (code0
== REAL_TYPE
&& code1
== INTEGER_TYPE
)
9175 || (code0
== INTEGER_TYPE
&& code1
== REAL_TYPE
)))
9177 error ("non-floating-point arguments in call to "
9178 "function %qE", fndecl
);
9185 case BUILT_IN_FPCLASSIFY
:
9186 if (builtin_function_validate_nargs (fndecl
, nargs
, 6))
9191 if (TREE_CODE (args
[i
]) != INTEGER_CST
)
9193 error ("non-const integer argument %u in call to function %qE",
9198 if (TREE_CODE (TREE_TYPE (args
[5])) != REAL_TYPE
)
9200 error ("non-floating-point argument in call to function %qE",
9208 case BUILT_IN_ASSUME_ALIGNED
:
9209 if (builtin_function_validate_nargs (fndecl
, nargs
, 2 + (nargs
> 2)))
9211 if (nargs
>= 3 && TREE_CODE (TREE_TYPE (args
[2])) != INTEGER_TYPE
)
9213 error ("non-integer argument 3 in call to function %qE", fndecl
);
9225 /* Function to help qsort sort FIELD_DECLs by name order. */
9228 field_decl_cmp (const void *x_p
, const void *y_p
)
9230 const tree
*const x
= (const tree
*const) x_p
;
9231 const tree
*const y
= (const tree
*const) y_p
;
9233 if (DECL_NAME (*x
) == DECL_NAME (*y
))
9234 /* A nontype is "greater" than a type. */
9235 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
9236 if (DECL_NAME (*x
) == NULL_TREE
)
9238 if (DECL_NAME (*y
) == NULL_TREE
)
9240 if (DECL_NAME (*x
) < DECL_NAME (*y
))
9246 gt_pointer_operator new_value
;
9250 /* This routine compares two fields like field_decl_cmp but using the
9251 pointer operator in resort_data. */
9254 resort_field_decl_cmp (const void *x_p
, const void *y_p
)
9256 const tree
*const x
= (const tree
*const) x_p
;
9257 const tree
*const y
= (const tree
*const) y_p
;
9259 if (DECL_NAME (*x
) == DECL_NAME (*y
))
9260 /* A nontype is "greater" than a type. */
9261 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
9262 if (DECL_NAME (*x
) == NULL_TREE
)
9264 if (DECL_NAME (*y
) == NULL_TREE
)
9267 tree d1
= DECL_NAME (*x
);
9268 tree d2
= DECL_NAME (*y
);
9269 resort_data
.new_value (&d1
, resort_data
.cookie
);
9270 resort_data
.new_value (&d2
, resort_data
.cookie
);
9277 /* Resort DECL_SORTED_FIELDS because pointers have been reordered. */
9280 resort_sorted_fields (void *obj
,
9281 void * ARG_UNUSED (orig_obj
),
9282 gt_pointer_operator new_value
,
9285 struct sorted_fields_type
*sf
= (struct sorted_fields_type
*) obj
;
9286 resort_data
.new_value
= new_value
;
9287 resort_data
.cookie
= cookie
;
9288 qsort (&sf
->elts
[0], sf
->len
, sizeof (tree
),
9289 resort_field_decl_cmp
);
9292 /* Subroutine of c_parse_error.
9293 Return the result of concatenating LHS and RHS. RHS is really
9294 a string literal, its first character is indicated by RHS_START and
9295 RHS_SIZE is its length (including the terminating NUL character).
9297 The caller is responsible for deleting the returned pointer. */
9300 catenate_strings (const char *lhs
, const char *rhs_start
, int rhs_size
)
9302 const int lhs_size
= strlen (lhs
);
9303 char *result
= XNEWVEC (char, lhs_size
+ rhs_size
);
9304 strncpy (result
, lhs
, lhs_size
);
9305 strncpy (result
+ lhs_size
, rhs_start
, rhs_size
);
9309 /* Issue the error given by GMSGID, indicating that it occurred before
9310 TOKEN, which had the associated VALUE. */
9313 c_parse_error (const char *gmsgid
, enum cpp_ttype token_type
,
9314 tree value
, unsigned char token_flags
)
9316 #define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2))
9318 char *message
= NULL
;
9320 if (token_type
== CPP_EOF
)
9321 message
= catenate_messages (gmsgid
, " at end of input");
9322 else if (token_type
== CPP_CHAR
9323 || token_type
== CPP_WCHAR
9324 || token_type
== CPP_CHAR16
9325 || token_type
== CPP_CHAR32
)
9327 unsigned int val
= TREE_INT_CST_LOW (value
);
9346 if (val
<= UCHAR_MAX
&& ISGRAPH (val
))
9347 message
= catenate_messages (gmsgid
, " before %s'%c'");
9349 message
= catenate_messages (gmsgid
, " before %s'\\x%x'");
9351 error (message
, prefix
, val
);
9355 else if (token_type
== CPP_STRING
9356 || token_type
== CPP_WSTRING
9357 || token_type
== CPP_STRING16
9358 || token_type
== CPP_STRING32
9359 || token_type
== CPP_UTF8STRING
)
9360 message
= catenate_messages (gmsgid
, " before string constant");
9361 else if (token_type
== CPP_NUMBER
)
9362 message
= catenate_messages (gmsgid
, " before numeric constant");
9363 else if (token_type
== CPP_NAME
)
9365 message
= catenate_messages (gmsgid
, " before %qE");
9366 error (message
, value
);
9370 else if (token_type
== CPP_PRAGMA
)
9371 message
= catenate_messages (gmsgid
, " before %<#pragma%>");
9372 else if (token_type
== CPP_PRAGMA_EOL
)
9373 message
= catenate_messages (gmsgid
, " before end of line");
9374 else if (token_type
== CPP_DECLTYPE
)
9375 message
= catenate_messages (gmsgid
, " before %<decltype%>");
9376 else if (token_type
< N_TTYPES
)
9378 message
= catenate_messages (gmsgid
, " before %qs token");
9379 error (message
, cpp_type2name (token_type
, token_flags
));
9391 #undef catenate_messages
9394 /* Mapping for cpp message reasons to the options that enable them. */
9396 struct reason_option_codes_t
9398 const int reason
; /* cpplib message reason. */
9399 const int option_code
; /* gcc option that controls this message. */
9402 static const struct reason_option_codes_t option_codes
[] = {
9403 {CPP_W_DEPRECATED
, OPT_Wdeprecated
},
9404 {CPP_W_COMMENTS
, OPT_Wcomment
},
9405 {CPP_W_TRIGRAPHS
, OPT_Wtrigraphs
},
9406 {CPP_W_MULTICHAR
, OPT_Wmultichar
},
9407 {CPP_W_TRADITIONAL
, OPT_Wtraditional
},
9408 {CPP_W_LONG_LONG
, OPT_Wlong_long
},
9409 {CPP_W_ENDIF_LABELS
, OPT_Wendif_labels
},
9410 {CPP_W_VARIADIC_MACROS
, OPT_Wvariadic_macros
},
9411 {CPP_W_BUILTIN_MACRO_REDEFINED
, OPT_Wbuiltin_macro_redefined
},
9412 {CPP_W_UNDEF
, OPT_Wundef
},
9413 {CPP_W_UNUSED_MACROS
, OPT_Wunused_macros
},
9414 {CPP_W_CXX_OPERATOR_NAMES
, OPT_Wc___compat
},
9415 {CPP_W_NORMALIZE
, OPT_Wnormalized_
},
9416 {CPP_W_INVALID_PCH
, OPT_Winvalid_pch
},
9417 {CPP_W_WARNING_DIRECTIVE
, OPT_Wcpp
},
9418 {CPP_W_LITERAL_SUFFIX
, OPT_Wliteral_suffix
},
9422 /* Return the gcc option code associated with the reason for a cpp
9423 message, or 0 if none. */
9426 c_option_controlling_cpp_error (int reason
)
9428 const struct reason_option_codes_t
*entry
;
9430 for (entry
= option_codes
; entry
->reason
!= CPP_W_NONE
; entry
++)
9432 if (entry
->reason
== reason
)
9433 return entry
->option_code
;
9438 /* Callback from cpp_error for PFILE to print diagnostics from the
9439 preprocessor. The diagnostic is of type LEVEL, with REASON set
9440 to the reason code if LEVEL is represents a warning, at location
9441 LOCATION unless this is after lexing and the compiler's location
9442 should be used instead, with column number possibly overridden by
9443 COLUMN_OVERRIDE if not zero; MSG is the translated message and AP
9444 the arguments. Returns true if a diagnostic was emitted, false
9448 c_cpp_error (cpp_reader
*pfile ATTRIBUTE_UNUSED
, int level
, int reason
,
9449 location_t location
, unsigned int column_override
,
9450 const char *msg
, va_list *ap
)
9452 diagnostic_info diagnostic
;
9453 diagnostic_t dlevel
;
9454 bool save_warn_system_headers
= global_dc
->dc_warn_system_headers
;
9459 case CPP_DL_WARNING_SYSHDR
:
9462 global_dc
->dc_warn_system_headers
= 1;
9464 case CPP_DL_WARNING
:
9467 dlevel
= DK_WARNING
;
9469 case CPP_DL_PEDWARN
:
9470 if (flag_no_output
&& !flag_pedantic_errors
)
9472 dlevel
= DK_PEDWARN
;
9490 location
= input_location
;
9491 diagnostic_set_info_translated (&diagnostic
, msg
, ap
,
9493 if (column_override
)
9494 diagnostic_override_column (&diagnostic
, column_override
);
9495 diagnostic_override_option_index (&diagnostic
,
9496 c_option_controlling_cpp_error (reason
));
9497 ret
= report_diagnostic (&diagnostic
);
9498 if (level
== CPP_DL_WARNING_SYSHDR
)
9499 global_dc
->dc_warn_system_headers
= save_warn_system_headers
;
9503 /* Convert a character from the host to the target execution character
9504 set. cpplib handles this, mostly. */
9507 c_common_to_target_charset (HOST_WIDE_INT c
)
9509 /* Character constants in GCC proper are sign-extended under -fsigned-char,
9510 zero-extended under -fno-signed-char. cpplib insists that characters
9511 and character constants are always unsigned. Hence we must convert
9513 cppchar_t uc
= ((cppchar_t
)c
) & ((((cppchar_t
)1) << CHAR_BIT
)-1);
9515 uc
= cpp_host_to_exec_charset (parse_in
, uc
);
9517 if (flag_signed_char
)
9518 return ((HOST_WIDE_INT
)uc
) << (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
)
9519 >> (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
);
9524 /* Fold an offsetof-like expression. EXPR is a nested sequence of component
9525 references with an INDIRECT_REF of a constant at the bottom; much like the
9526 traditional rendering of offsetof as a macro. Return the folded result. */
9529 fold_offsetof_1 (tree expr
)
9533 switch (TREE_CODE (expr
))
9539 error ("cannot apply %<offsetof%> to static data member %qD", expr
);
9540 return error_mark_node
;
9544 error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded");
9545 return error_mark_node
;
9549 if (!TREE_CONSTANT (TREE_OPERAND (expr
, 0)))
9551 error ("cannot apply %<offsetof%> to a non constant address");
9552 return error_mark_node
;
9554 return TREE_OPERAND (expr
, 0);
9557 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0));
9558 if (base
== error_mark_node
)
9561 t
= TREE_OPERAND (expr
, 1);
9562 if (DECL_C_BIT_FIELD (t
))
9564 error ("attempt to take address of bit-field structure "
9566 return error_mark_node
;
9568 off
= size_binop_loc (input_location
, PLUS_EXPR
, DECL_FIELD_OFFSET (t
),
9569 size_int (tree_low_cst (DECL_FIELD_BIT_OFFSET (t
),
9575 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0));
9576 if (base
== error_mark_node
)
9579 t
= TREE_OPERAND (expr
, 1);
9581 /* Check if the offset goes beyond the upper bound of the array. */
9582 if (TREE_CODE (t
) == INTEGER_CST
&& tree_int_cst_sgn (t
) >= 0)
9584 tree upbound
= array_ref_up_bound (expr
);
9585 if (upbound
!= NULL_TREE
9586 && TREE_CODE (upbound
) == INTEGER_CST
9587 && !tree_int_cst_equal (upbound
,
9588 TYPE_MAX_VALUE (TREE_TYPE (upbound
))))
9590 upbound
= size_binop (PLUS_EXPR
, upbound
,
9591 build_int_cst (TREE_TYPE (upbound
), 1));
9592 if (tree_int_cst_lt (upbound
, t
))
9596 for (v
= TREE_OPERAND (expr
, 0);
9597 TREE_CODE (v
) == COMPONENT_REF
;
9598 v
= TREE_OPERAND (v
, 0))
9599 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v
, 0)))
9602 tree fld_chain
= DECL_CHAIN (TREE_OPERAND (v
, 1));
9603 for (; fld_chain
; fld_chain
= DECL_CHAIN (fld_chain
))
9604 if (TREE_CODE (fld_chain
) == FIELD_DECL
)
9610 /* Don't warn if the array might be considered a poor
9611 man's flexible array member with a very permissive
9612 definition thereof. */
9613 if (TREE_CODE (v
) == ARRAY_REF
9614 || TREE_CODE (v
) == COMPONENT_REF
)
9615 warning (OPT_Warray_bounds
,
9616 "index %E denotes an offset "
9617 "greater than size of %qT",
9618 t
, TREE_TYPE (TREE_OPERAND (expr
, 0)));
9623 t
= convert (sizetype
, t
);
9624 off
= size_binop (MULT_EXPR
, TYPE_SIZE_UNIT (TREE_TYPE (expr
)), t
);
9628 /* Handle static members of volatile structs. */
9629 t
= TREE_OPERAND (expr
, 1);
9630 gcc_assert (TREE_CODE (t
) == VAR_DECL
);
9631 return fold_offsetof_1 (t
);
9637 return fold_build_pointer_plus (base
, off
);
9640 /* Likewise, but convert it to the return type of offsetof. */
9643 fold_offsetof (tree expr
)
9645 return convert (size_type_node
, fold_offsetof_1 (expr
));
9648 /* Warn for A ?: C expressions (with B omitted) where A is a boolean
9649 expression, because B will always be true. */
9652 warn_for_omitted_condop (location_t location
, tree cond
)
9654 if (truth_value_p (TREE_CODE (cond
)))
9655 warning_at (location
, OPT_Wparentheses
,
9656 "the omitted middle operand in ?: will always be %<true%>, "
9657 "suggest explicit middle operand");
9660 /* Give an error for storing into ARG, which is 'const'. USE indicates
9661 how ARG was being used. */
9664 readonly_error (tree arg
, enum lvalue_use use
)
9666 gcc_assert (use
== lv_assign
|| use
== lv_increment
|| use
== lv_decrement
9668 /* Using this macro rather than (for example) arrays of messages
9669 ensures that all the format strings are checked at compile
9671 #define READONLY_MSG(A, I, D, AS) (use == lv_assign ? (A) \
9672 : (use == lv_increment ? (I) \
9673 : (use == lv_decrement ? (D) : (AS))))
9674 if (TREE_CODE (arg
) == COMPONENT_REF
)
9676 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg
, 0))))
9677 error (READONLY_MSG (G_("assignment of member "
9678 "%qD in read-only object"),
9679 G_("increment of member "
9680 "%qD in read-only object"),
9681 G_("decrement of member "
9682 "%qD in read-only object"),
9683 G_("member %qD in read-only object "
9684 "used as %<asm%> output")),
9685 TREE_OPERAND (arg
, 1));
9687 error (READONLY_MSG (G_("assignment of read-only member %qD"),
9688 G_("increment of read-only member %qD"),
9689 G_("decrement of read-only member %qD"),
9690 G_("read-only member %qD used as %<asm%> output")),
9691 TREE_OPERAND (arg
, 1));
9693 else if (TREE_CODE (arg
) == VAR_DECL
)
9694 error (READONLY_MSG (G_("assignment of read-only variable %qD"),
9695 G_("increment of read-only variable %qD"),
9696 G_("decrement of read-only variable %qD"),
9697 G_("read-only variable %qD used as %<asm%> output")),
9699 else if (TREE_CODE (arg
) == PARM_DECL
)
9700 error (READONLY_MSG (G_("assignment of read-only parameter %qD"),
9701 G_("increment of read-only parameter %qD"),
9702 G_("decrement of read-only parameter %qD"),
9703 G_("read-only parameter %qD use as %<asm%> output")),
9705 else if (TREE_CODE (arg
) == RESULT_DECL
)
9707 gcc_assert (c_dialect_cxx ());
9708 error (READONLY_MSG (G_("assignment of "
9709 "read-only named return value %qD"),
9711 "read-only named return value %qD"),
9713 "read-only named return value %qD"),
9714 G_("read-only named return value %qD "
9715 "used as %<asm%>output")),
9718 else if (TREE_CODE (arg
) == FUNCTION_DECL
)
9719 error (READONLY_MSG (G_("assignment of function %qD"),
9720 G_("increment of function %qD"),
9721 G_("decrement of function %qD"),
9722 G_("function %qD used as %<asm%> output")),
9725 error (READONLY_MSG (G_("assignment of read-only location %qE"),
9726 G_("increment of read-only location %qE"),
9727 G_("decrement of read-only location %qE"),
9728 G_("read-only location %qE used as %<asm%> output")),
9732 /* Print an error message for an invalid lvalue. USE says
9733 how the lvalue is being used and so selects the error message. LOC
9734 is the location for the error. */
9737 lvalue_error (location_t loc
, enum lvalue_use use
)
9742 error_at (loc
, "lvalue required as left operand of assignment");
9745 error_at (loc
, "lvalue required as increment operand");
9748 error_at (loc
, "lvalue required as decrement operand");
9751 error_at (loc
, "lvalue required as unary %<&%> operand");
9754 error_at (loc
, "lvalue required in asm statement");
9761 /* Print an error message for an invalid indirection of type TYPE.
9762 ERRSTRING is the name of the operator for the indirection. */
9765 invalid_indirection_error (location_t loc
, tree type
, ref_operator errstring
)
9770 gcc_assert (c_dialect_cxx ());
9771 error_at (loc
, "invalid type argument (have %qT)", type
);
9773 case RO_ARRAY_INDEXING
:
9775 "invalid type argument of array indexing (have %qT)",
9780 "invalid type argument of unary %<*%> (have %qT)",
9785 "invalid type argument of %<->%> (have %qT)",
9788 case RO_IMPLICIT_CONVERSION
:
9790 "invalid type argument of implicit conversion (have %qT)",
9798 /* *PTYPE is an incomplete array. Complete it with a domain based on
9799 INITIAL_VALUE. If INITIAL_VALUE is not present, use 1 if DO_DEFAULT
9800 is true. Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
9801 2 if INITIAL_VALUE was NULL, and 3 if INITIAL_VALUE was empty. */
9804 complete_array_type (tree
*ptype
, tree initial_value
, bool do_default
)
9806 tree maxindex
, type
, main_type
, elt
, unqual_elt
;
9807 int failure
= 0, quals
;
9808 hashval_t hashcode
= 0;
9809 bool overflow_p
= false;
9811 maxindex
= size_zero_node
;
9814 if (TREE_CODE (initial_value
) == STRING_CST
)
9817 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value
)));
9818 maxindex
= size_int (TREE_STRING_LENGTH (initial_value
)/eltsize
- 1);
9820 else if (TREE_CODE (initial_value
) == CONSTRUCTOR
)
9822 vec
<constructor_elt
, va_gc
> *v
= CONSTRUCTOR_ELTS (initial_value
);
9824 if (vec_safe_is_empty (v
))
9828 maxindex
= ssize_int (-1);
9833 unsigned HOST_WIDE_INT cnt
;
9834 constructor_elt
*ce
;
9835 bool fold_p
= false;
9838 maxindex
= (*v
)[0].index
, fold_p
= true;
9840 curindex
= maxindex
;
9842 for (cnt
= 1; vec_safe_iterate (v
, cnt
, &ce
); cnt
++)
9844 bool curfold_p
= false;
9846 curindex
= ce
->index
, curfold_p
= true;
9851 /* Since we treat size types now as ordinary
9852 unsigned types, we need an explicit overflow
9854 tree orig
= curindex
;
9855 curindex
= fold_convert (sizetype
, curindex
);
9856 overflow_p
|= tree_int_cst_lt (curindex
, orig
);
9858 curindex
= size_binop (PLUS_EXPR
, curindex
,
9861 if (tree_int_cst_lt (maxindex
, curindex
))
9862 maxindex
= curindex
, fold_p
= curfold_p
;
9866 tree orig
= maxindex
;
9867 maxindex
= fold_convert (sizetype
, maxindex
);
9868 overflow_p
|= tree_int_cst_lt (maxindex
, orig
);
9874 /* Make an error message unless that happened already. */
9875 if (initial_value
!= error_mark_node
)
9887 elt
= TREE_TYPE (type
);
9888 quals
= TYPE_QUALS (strip_array_types (elt
));
9892 unqual_elt
= c_build_qualified_type (elt
, KEEP_QUAL_ADDR_SPACE (quals
));
9894 /* Using build_distinct_type_copy and modifying things afterward instead
9895 of using build_array_type to create a new type preserves all of the
9896 TYPE_LANG_FLAG_? bits that the front end may have set. */
9897 main_type
= build_distinct_type_copy (TYPE_MAIN_VARIANT (type
));
9898 TREE_TYPE (main_type
) = unqual_elt
;
9899 TYPE_DOMAIN (main_type
)
9900 = build_range_type (TREE_TYPE (maxindex
),
9901 build_int_cst (TREE_TYPE (maxindex
), 0), maxindex
);
9902 layout_type (main_type
);
9904 /* Make sure we have the canonical MAIN_TYPE. */
9905 hashcode
= iterative_hash_object (TYPE_HASH (unqual_elt
), hashcode
);
9906 hashcode
= iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (main_type
)),
9908 main_type
= type_hash_canon (hashcode
, main_type
);
9910 /* Fix the canonical type. */
9911 if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type
))
9912 || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type
)))
9913 SET_TYPE_STRUCTURAL_EQUALITY (main_type
);
9914 else if (TYPE_CANONICAL (TREE_TYPE (main_type
)) != TREE_TYPE (main_type
)
9915 || (TYPE_CANONICAL (TYPE_DOMAIN (main_type
))
9916 != TYPE_DOMAIN (main_type
)))
9917 TYPE_CANONICAL (main_type
)
9918 = build_array_type (TYPE_CANONICAL (TREE_TYPE (main_type
)),
9919 TYPE_CANONICAL (TYPE_DOMAIN (main_type
)));
9921 TYPE_CANONICAL (main_type
) = main_type
;
9926 type
= c_build_qualified_type (main_type
, quals
);
9928 if (COMPLETE_TYPE_P (type
)
9929 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
9930 && (overflow_p
|| TREE_OVERFLOW (TYPE_SIZE_UNIT (type
))))
9932 error ("size of array is too large");
9933 /* If we proceed with the array type as it is, we'll eventually
9934 crash in tree_low_cst(). */
9935 type
= error_mark_node
;
9942 /* Like c_mark_addressable but don't check register qualifier. */
9944 c_common_mark_addressable_vec (tree t
)
9946 while (handled_component_p (t
))
9947 t
= TREE_OPERAND (t
, 0);
9948 if (TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != PARM_DECL
)
9950 TREE_ADDRESSABLE (t
) = 1;
9955 /* Used to help initialize the builtin-types.def table. When a type of
9956 the correct size doesn't exist, use error_mark_node instead of NULL.
9957 The later results in segfaults even when a decl using the type doesn't
9961 builtin_type_for_size (int size
, bool unsignedp
)
9963 tree type
= c_common_type_for_size (size
, unsignedp
);
9964 return type
? type
: error_mark_node
;
9967 /* A helper function for resolve_overloaded_builtin in resolving the
9968 overloaded __sync_ builtins. Returns a positive power of 2 if the
9969 first operand of PARAMS is a pointer to a supported data type.
9970 Returns 0 if an error is encountered. */
9973 sync_resolve_size (tree function
, vec
<tree
, va_gc
> *params
)
9980 error ("too few arguments to function %qE", function
);
9984 type
= TREE_TYPE ((*params
)[0]);
9985 if (TREE_CODE (type
) != POINTER_TYPE
)
9988 type
= TREE_TYPE (type
);
9989 if (!INTEGRAL_TYPE_P (type
) && !POINTER_TYPE_P (type
))
9992 size
= tree_low_cst (TYPE_SIZE_UNIT (type
), 1);
9993 if (size
== 1 || size
== 2 || size
== 4 || size
== 8 || size
== 16)
9997 error ("incompatible type for argument %d of %qE", 1, function
);
10001 /* A helper function for resolve_overloaded_builtin. Adds casts to
10002 PARAMS to make arguments match up with those of FUNCTION. Drops
10003 the variadic arguments at the end. Returns false if some error
10004 was encountered; true on success. */
10007 sync_resolve_params (location_t loc
, tree orig_function
, tree function
,
10008 vec
<tree
, va_gc
> *params
, bool orig_format
)
10010 function_args_iterator iter
;
10012 unsigned int parmnum
;
10014 function_args_iter_init (&iter
, TREE_TYPE (function
));
10015 /* We've declared the implementation functions to use "volatile void *"
10016 as the pointer parameter, so we shouldn't get any complaints from the
10017 call to check_function_arguments what ever type the user used. */
10018 function_args_iter_next (&iter
);
10019 ptype
= TREE_TYPE (TREE_TYPE ((*params
)[0]));
10021 /* For the rest of the values, we need to cast these to FTYPE, so that we
10022 don't get warnings for passing pointer types, etc. */
10026 tree val
, arg_type
;
10028 arg_type
= function_args_iter_cond (&iter
);
10029 /* XXX void_type_node belies the abstraction. */
10030 if (arg_type
== void_type_node
)
10034 if (params
->length () <= parmnum
)
10036 error_at (loc
, "too few arguments to function %qE", orig_function
);
10040 /* Only convert parameters if arg_type is unsigned integer type with
10041 new format sync routines, i.e. don't attempt to convert pointer
10042 arguments (e.g. EXPECTED argument of __atomic_compare_exchange_n),
10043 bool arguments (e.g. WEAK argument) or signed int arguments (memmodel
10045 if (TREE_CODE (arg_type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (arg_type
))
10047 /* Ideally for the first conversion we'd use convert_for_assignment
10048 so that we get warnings for anything that doesn't match the pointer
10049 type. This isn't portable across the C and C++ front ends atm. */
10050 val
= (*params
)[parmnum
];
10051 val
= convert (ptype
, val
);
10052 val
= convert (arg_type
, val
);
10053 (*params
)[parmnum
] = val
;
10056 function_args_iter_next (&iter
);
10059 /* __atomic routines are not variadic. */
10060 if (!orig_format
&& params
->length () != parmnum
+ 1)
10062 error_at (loc
, "too many arguments to function %qE", orig_function
);
10066 /* The definition of these primitives is variadic, with the remaining
10067 being "an optional list of variables protected by the memory barrier".
10068 No clue what that's supposed to mean, precisely, but we consider all
10069 call-clobbered variables to be protected so we're safe. */
10070 params
->truncate (parmnum
+ 1);
10075 /* A helper function for resolve_overloaded_builtin. Adds a cast to
10076 RESULT to make it match the type of the first pointer argument in
10080 sync_resolve_return (tree first_param
, tree result
, bool orig_format
)
10082 tree ptype
= TREE_TYPE (TREE_TYPE (first_param
));
10083 tree rtype
= TREE_TYPE (result
);
10084 ptype
= TYPE_MAIN_VARIANT (ptype
);
10086 /* New format doesn't require casting unless the types are the same size. */
10087 if (orig_format
|| tree_int_cst_equal (TYPE_SIZE (ptype
), TYPE_SIZE (rtype
)))
10088 return convert (ptype
, result
);
10093 /* This function verifies the PARAMS to generic atomic FUNCTION.
10094 It returns the size if all the parameters are the same size, otherwise
10095 0 is returned if the parameters are invalid. */
10098 get_atomic_generic_size (location_t loc
, tree function
,
10099 vec
<tree
, va_gc
> *params
)
10101 unsigned int n_param
;
10102 unsigned int n_model
;
10107 /* Determine the parameter makeup. */
10108 switch (DECL_FUNCTION_CODE (function
))
10110 case BUILT_IN_ATOMIC_EXCHANGE
:
10114 case BUILT_IN_ATOMIC_LOAD
:
10115 case BUILT_IN_ATOMIC_STORE
:
10119 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10124 gcc_unreachable ();
10127 if (vec_safe_length (params
) != n_param
)
10129 error_at (loc
, "incorrect number of arguments to function %qE", function
);
10133 /* Get type of first parameter, and determine its size. */
10134 type_0
= TREE_TYPE ((*params
)[0]);
10135 if (TREE_CODE (type_0
) != POINTER_TYPE
|| VOID_TYPE_P (TREE_TYPE (type_0
)))
10137 error_at (loc
, "argument 1 of %qE must be a non-void pointer type",
10142 /* Types must be compile time constant sizes. */
10143 if (TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type_0
)))) != INTEGER_CST
)
10146 "argument 1 of %qE must be a pointer to a constant size type",
10151 size_0
= tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (type_0
)), 1);
10153 /* Zero size objects are not allowed. */
10157 "argument 1 of %qE must be a pointer to a nonzero size object",
10162 /* Check each other parameter is a pointer and the same size. */
10163 for (x
= 0; x
< n_param
- n_model
; x
++)
10166 tree type
= TREE_TYPE ((*params
)[x
]);
10167 /* __atomic_compare_exchange has a bool in the 4th position, skip it. */
10168 if (n_param
== 6 && x
== 3)
10170 if (!POINTER_TYPE_P (type
))
10172 error_at (loc
, "argument %d of %qE must be a pointer type", x
+ 1,
10176 size
= tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (type
)), 1);
10177 if (size
!= size_0
)
10179 error_at (loc
, "size mismatch in argument %d of %qE", x
+ 1,
10185 /* Check memory model parameters for validity. */
10186 for (x
= n_param
- n_model
; x
< n_param
; x
++)
10188 tree p
= (*params
)[x
];
10189 if (TREE_CODE (p
) == INTEGER_CST
)
10191 int i
= tree_low_cst (p
, 1);
10192 if (i
< 0 || (i
& MEMMODEL_MASK
) >= MEMMODEL_LAST
)
10194 warning_at (loc
, OPT_Winvalid_memory_model
,
10195 "invalid memory model argument %d of %qE", x
+ 1,
10200 if (!INTEGRAL_TYPE_P (TREE_TYPE (p
)))
10202 error_at (loc
, "non-integer memory model argument %d of %qE", x
+ 1,
10212 /* This will take an __atomic_ generic FUNCTION call, and add a size parameter N
10213 at the beginning of the parameter list PARAMS representing the size of the
10214 objects. This is to match the library ABI requirement. LOC is the location
10215 of the function call.
10216 The new function is returned if it needed rebuilding, otherwise NULL_TREE is
10217 returned to allow the external call to be constructed. */
10220 add_atomic_size_parameter (unsigned n
, location_t loc
, tree function
,
10221 vec
<tree
, va_gc
> *params
)
10225 /* Insert a SIZE_T parameter as the first param. If there isn't
10226 enough space, allocate a new vector and recursively re-build with that. */
10227 if (!params
->space (1))
10229 unsigned int z
, len
;
10230 vec
<tree
, va_gc
> *v
;
10233 len
= params
->length ();
10234 vec_alloc (v
, len
+ 1);
10235 for (z
= 0; z
< len
; z
++)
10236 v
->quick_push ((*params
)[z
]);
10237 f
= build_function_call_vec (loc
, function
, v
, NULL
);
10242 /* Add the size parameter and leave as a function call for processing. */
10243 size_node
= build_int_cst (size_type_node
, n
);
10244 params
->quick_insert (0, size_node
);
10249 /* This will process an __atomic_exchange function call, determine whether it
10250 needs to be mapped to the _N variation, or turned into a library call.
10251 LOC is the location of the builtin call.
10252 FUNCTION is the DECL that has been invoked;
10253 PARAMS is the argument list for the call. The return value is non-null
10254 TRUE is returned if it is translated into the proper format for a call to the
10255 external library, and NEW_RETURN is set the tree for that function.
10256 FALSE is returned if processing for the _N variation is required, and
10257 NEW_RETURN is set to the the return value the result is copied into. */
10259 resolve_overloaded_atomic_exchange (location_t loc
, tree function
,
10260 vec
<tree
, va_gc
> *params
, tree
*new_return
)
10262 tree p0
, p1
, p2
, p3
;
10263 tree I_type
, I_type_ptr
;
10264 int n
= get_atomic_generic_size (loc
, function
, params
);
10266 /* Size of 0 is an error condition. */
10269 *new_return
= error_mark_node
;
10273 /* If not a lock-free size, change to the library generic format. */
10274 if (n
!= 1 && n
!= 2 && n
!= 4 && n
!= 8 && n
!= 16)
10276 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10280 /* Otherwise there is a lockfree match, transform the call from:
10281 void fn(T* mem, T* desired, T* return, model)
10283 *return = (T) (fn (In* mem, (In) *desired, model)) */
10290 /* Create pointer to appropriate size. */
10291 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10292 I_type_ptr
= build_pointer_type (I_type
);
10294 /* Convert object pointer to required type. */
10295 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10297 /* Convert new value to required type, and dereference it. */
10298 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
10299 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
10302 /* Move memory model to the 3rd position, and end param list. */
10304 params
->truncate (3);
10306 /* Convert return pointer and dereference it for later assignment. */
10307 *new_return
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
10313 /* This will process an __atomic_compare_exchange function call, determine
10314 whether it needs to be mapped to the _N variation, or turned into a lib call.
10315 LOC is the location of the builtin call.
10316 FUNCTION is the DECL that has been invoked;
10317 PARAMS is the argument list for the call. The return value is non-null
10318 TRUE is returned if it is translated into the proper format for a call to the
10319 external library, and NEW_RETURN is set the tree for that function.
10320 FALSE is returned if processing for the _N variation is required. */
10323 resolve_overloaded_atomic_compare_exchange (location_t loc
, tree function
,
10324 vec
<tree
, va_gc
> *params
,
10328 tree I_type
, I_type_ptr
;
10329 int n
= get_atomic_generic_size (loc
, function
, params
);
10331 /* Size of 0 is an error condition. */
10334 *new_return
= error_mark_node
;
10338 /* If not a lock-free size, change to the library generic format. */
10339 if (n
!= 1 && n
!= 2 && n
!= 4 && n
!= 8 && n
!= 16)
10341 /* The library generic format does not have the weak parameter, so
10342 remove it from the param list. Since a parameter has been removed,
10343 we can be sure that there is room for the SIZE_T parameter, meaning
10344 there will not be a recursive rebuilding of the parameter list, so
10345 there is no danger this will be done twice. */
10348 (*params
)[3] = (*params
)[4];
10349 (*params
)[4] = (*params
)[5];
10350 params
->truncate (5);
10352 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10356 /* Otherwise, there is a match, so the call needs to be transformed from:
10357 bool fn(T* mem, T* desired, T* return, weak, success, failure)
10359 bool fn ((In *)mem, (In *)expected, (In) *desired, weak, succ, fail) */
10365 /* Create pointer to appropriate size. */
10366 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10367 I_type_ptr
= build_pointer_type (I_type
);
10369 /* Convert object pointer to required type. */
10370 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10373 /* Convert expected pointer to required type. */
10374 p1
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p1
);
10377 /* Convert desired value to required type, and dereference it. */
10378 p2
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
10379 p2
= build1 (VIEW_CONVERT_EXPR
, I_type
, p2
);
10382 /* The rest of the parameters are fine. NULL means no special return value
10384 *new_return
= NULL
;
10389 /* This will process an __atomic_load function call, determine whether it
10390 needs to be mapped to the _N variation, or turned into a library call.
10391 LOC is the location of the builtin call.
10392 FUNCTION is the DECL that has been invoked;
10393 PARAMS is the argument list for the call. The return value is non-null
10394 TRUE is returned if it is translated into the proper format for a call to the
10395 external library, and NEW_RETURN is set the tree for that function.
10396 FALSE is returned if processing for the _N variation is required, and
10397 NEW_RETURN is set to the the return value the result is copied into. */
10400 resolve_overloaded_atomic_load (location_t loc
, tree function
,
10401 vec
<tree
, va_gc
> *params
, tree
*new_return
)
10404 tree I_type
, I_type_ptr
;
10405 int n
= get_atomic_generic_size (loc
, function
, params
);
10407 /* Size of 0 is an error condition. */
10410 *new_return
= error_mark_node
;
10414 /* If not a lock-free size, change to the library generic format. */
10415 if (n
!= 1 && n
!= 2 && n
!= 4 && n
!= 8 && n
!= 16)
10417 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10421 /* Otherwise, there is a match, so the call needs to be transformed from:
10422 void fn(T* mem, T* return, model)
10424 *return = (T) (fn ((In *) mem, model)) */
10430 /* Create pointer to appropriate size. */
10431 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10432 I_type_ptr
= build_pointer_type (I_type
);
10434 /* Convert object pointer to required type. */
10435 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10438 /* Move memory model to the 2nd position, and end param list. */
10440 params
->truncate (2);
10442 /* Convert return pointer and dereference it for later assignment. */
10443 *new_return
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
10449 /* This will process an __atomic_store function call, determine whether it
10450 needs to be mapped to the _N variation, or turned into a library call.
10451 LOC is the location of the builtin call.
10452 FUNCTION is the DECL that has been invoked;
10453 PARAMS is the argument list for the call. The return value is non-null
10454 TRUE is returned if it is translated into the proper format for a call to the
10455 external library, and NEW_RETURN is set the tree for that function.
10456 FALSE is returned if processing for the _N variation is required, and
10457 NEW_RETURN is set to the the return value the result is copied into. */
10460 resolve_overloaded_atomic_store (location_t loc
, tree function
,
10461 vec
<tree
, va_gc
> *params
, tree
*new_return
)
10464 tree I_type
, I_type_ptr
;
10465 int n
= get_atomic_generic_size (loc
, function
, params
);
10467 /* Size of 0 is an error condition. */
10470 *new_return
= error_mark_node
;
10474 /* If not a lock-free size, change to the library generic format. */
10475 if (n
!= 1 && n
!= 2 && n
!= 4 && n
!= 8 && n
!= 16)
10477 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10481 /* Otherwise, there is a match, so the call needs to be transformed from:
10482 void fn(T* mem, T* value, model)
10484 fn ((In *) mem, (In) *value, model) */
10489 /* Create pointer to appropriate size. */
10490 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10491 I_type_ptr
= build_pointer_type (I_type
);
10493 /* Convert object pointer to required type. */
10494 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10497 /* Convert new value to required type, and dereference it. */
10498 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
10499 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
10502 /* The memory model is in the right spot already. Return is void. */
10503 *new_return
= NULL_TREE
;
10509 /* Some builtin functions are placeholders for other expressions. This
10510 function should be called immediately after parsing the call expression
10511 before surrounding code has committed to the type of the expression.
10513 LOC is the location of the builtin call.
10515 FUNCTION is the DECL that has been invoked; it is known to be a builtin.
10516 PARAMS is the argument list for the call. The return value is non-null
10517 when expansion is complete, and null if normal processing should
10521 resolve_overloaded_builtin (location_t loc
, tree function
,
10522 vec
<tree
, va_gc
> *params
)
10524 enum built_in_function orig_code
= DECL_FUNCTION_CODE (function
);
10525 bool orig_format
= true;
10526 tree new_return
= NULL_TREE
;
10528 switch (DECL_BUILT_IN_CLASS (function
))
10530 case BUILT_IN_NORMAL
:
10533 if (targetm
.resolve_overloaded_builtin
)
10534 return targetm
.resolve_overloaded_builtin (loc
, function
, params
);
10541 /* Handle BUILT_IN_NORMAL here. */
10544 case BUILT_IN_ATOMIC_EXCHANGE
:
10545 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10546 case BUILT_IN_ATOMIC_LOAD
:
10547 case BUILT_IN_ATOMIC_STORE
:
10549 /* Handle these 4 together so that they can fall through to the next
10550 case if the call is transformed to an _N variant. */
10553 case BUILT_IN_ATOMIC_EXCHANGE
:
10555 if (resolve_overloaded_atomic_exchange (loc
, function
, params
,
10558 /* Change to the _N variant. */
10559 orig_code
= BUILT_IN_ATOMIC_EXCHANGE_N
;
10563 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10565 if (resolve_overloaded_atomic_compare_exchange (loc
, function
,
10569 /* Change to the _N variant. */
10570 orig_code
= BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
;
10573 case BUILT_IN_ATOMIC_LOAD
:
10575 if (resolve_overloaded_atomic_load (loc
, function
, params
,
10578 /* Change to the _N variant. */
10579 orig_code
= BUILT_IN_ATOMIC_LOAD_N
;
10582 case BUILT_IN_ATOMIC_STORE
:
10584 if (resolve_overloaded_atomic_store (loc
, function
, params
,
10587 /* Change to the _N variant. */
10588 orig_code
= BUILT_IN_ATOMIC_STORE_N
;
10592 gcc_unreachable ();
10594 /* Fallthrough to the normal processing. */
10596 case BUILT_IN_ATOMIC_EXCHANGE_N
:
10597 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
:
10598 case BUILT_IN_ATOMIC_LOAD_N
:
10599 case BUILT_IN_ATOMIC_STORE_N
:
10600 case BUILT_IN_ATOMIC_ADD_FETCH_N
:
10601 case BUILT_IN_ATOMIC_SUB_FETCH_N
:
10602 case BUILT_IN_ATOMIC_AND_FETCH_N
:
10603 case BUILT_IN_ATOMIC_NAND_FETCH_N
:
10604 case BUILT_IN_ATOMIC_XOR_FETCH_N
:
10605 case BUILT_IN_ATOMIC_OR_FETCH_N
:
10606 case BUILT_IN_ATOMIC_FETCH_ADD_N
:
10607 case BUILT_IN_ATOMIC_FETCH_SUB_N
:
10608 case BUILT_IN_ATOMIC_FETCH_AND_N
:
10609 case BUILT_IN_ATOMIC_FETCH_NAND_N
:
10610 case BUILT_IN_ATOMIC_FETCH_XOR_N
:
10611 case BUILT_IN_ATOMIC_FETCH_OR_N
:
10613 orig_format
= false;
10614 /* Fallthru for parameter processing. */
10616 case BUILT_IN_SYNC_FETCH_AND_ADD_N
:
10617 case BUILT_IN_SYNC_FETCH_AND_SUB_N
:
10618 case BUILT_IN_SYNC_FETCH_AND_OR_N
:
10619 case BUILT_IN_SYNC_FETCH_AND_AND_N
:
10620 case BUILT_IN_SYNC_FETCH_AND_XOR_N
:
10621 case BUILT_IN_SYNC_FETCH_AND_NAND_N
:
10622 case BUILT_IN_SYNC_ADD_AND_FETCH_N
:
10623 case BUILT_IN_SYNC_SUB_AND_FETCH_N
:
10624 case BUILT_IN_SYNC_OR_AND_FETCH_N
:
10625 case BUILT_IN_SYNC_AND_AND_FETCH_N
:
10626 case BUILT_IN_SYNC_XOR_AND_FETCH_N
:
10627 case BUILT_IN_SYNC_NAND_AND_FETCH_N
:
10628 case BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
:
10629 case BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N
:
10630 case BUILT_IN_SYNC_LOCK_TEST_AND_SET_N
:
10631 case BUILT_IN_SYNC_LOCK_RELEASE_N
:
10633 int n
= sync_resolve_size (function
, params
);
10634 tree new_function
, first_param
, result
;
10635 enum built_in_function fncode
;
10638 return error_mark_node
;
10640 fncode
= (enum built_in_function
)((int)orig_code
+ exact_log2 (n
) + 1);
10641 new_function
= builtin_decl_explicit (fncode
);
10642 if (!sync_resolve_params (loc
, function
, new_function
, params
,
10644 return error_mark_node
;
10646 first_param
= (*params
)[0];
10647 result
= build_function_call_vec (loc
, new_function
, params
, NULL
);
10648 if (result
== error_mark_node
)
10650 if (orig_code
!= BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
10651 && orig_code
!= BUILT_IN_SYNC_LOCK_RELEASE_N
10652 && orig_code
!= BUILT_IN_ATOMIC_STORE_N
)
10653 result
= sync_resolve_return (first_param
, result
, orig_format
);
10655 /* If new_return is set, assign function to that expr and cast the
10656 result to void since the generic interface returned void. */
10659 /* Cast function result from I{1,2,4,8,16} to the required type. */
10660 result
= build1 (VIEW_CONVERT_EXPR
, TREE_TYPE (new_return
), result
);
10661 result
= build2 (MODIFY_EXPR
, TREE_TYPE (new_return
), new_return
,
10663 TREE_SIDE_EFFECTS (result
) = 1;
10664 protected_set_expr_location (result
, loc
);
10665 result
= convert (void_type_node
, result
);
10675 /* Ignoring their sign, return true if two scalar types are the same. */
10677 same_scalar_type_ignoring_signedness (tree t1
, tree t2
)
10679 enum tree_code c1
= TREE_CODE (t1
), c2
= TREE_CODE (t2
);
10681 gcc_assert ((c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
|| c1
== FIXED_POINT_TYPE
)
10682 && (c2
== INTEGER_TYPE
|| c2
== REAL_TYPE
10683 || c2
== FIXED_POINT_TYPE
));
10685 /* Equality works here because c_common_signed_type uses
10686 TYPE_MAIN_VARIANT. */
10687 return c_common_signed_type (t1
)
10688 == c_common_signed_type (t2
);
10691 /* Check for missing format attributes on function pointers. LTYPE is
10692 the new type or left-hand side type. RTYPE is the old type or
10693 right-hand side type. Returns TRUE if LTYPE is missing the desired
10697 check_missing_format_attribute (tree ltype
, tree rtype
)
10699 tree
const ttr
= TREE_TYPE (rtype
), ttl
= TREE_TYPE (ltype
);
10702 for (ra
= TYPE_ATTRIBUTES (ttr
); ra
; ra
= TREE_CHAIN (ra
))
10703 if (is_attribute_p ("format", TREE_PURPOSE (ra
)))
10708 for (la
= TYPE_ATTRIBUTES (ttl
); la
; la
= TREE_CHAIN (la
))
10709 if (is_attribute_p ("format", TREE_PURPOSE (la
)))
10717 /* Subscripting with type char is likely to lose on a machine where
10718 chars are signed. So warn on any machine, but optionally. Don't
10719 warn for unsigned char since that type is safe. Don't warn for
10720 signed char because anyone who uses that must have done so
10721 deliberately. Furthermore, we reduce the false positive load by
10722 warning only for non-constant value of type char. */
10725 warn_array_subscript_with_type_char (tree index
)
10727 if (TYPE_MAIN_VARIANT (TREE_TYPE (index
)) == char_type_node
10728 && TREE_CODE (index
) != INTEGER_CST
)
10729 warning (OPT_Wchar_subscripts
, "array subscript has type %<char%>");
10732 /* Implement -Wparentheses for the unexpected C precedence rules, to
10733 cover cases like x + y << z which readers are likely to
10734 misinterpret. We have seen an expression in which CODE is a binary
10735 operator used to combine expressions ARG_LEFT and ARG_RIGHT, which
10736 before folding had CODE_LEFT and CODE_RIGHT. CODE_LEFT and
10737 CODE_RIGHT may be ERROR_MARK, which means that that side of the
10738 expression was not formed using a binary or unary operator, or it
10739 was enclosed in parentheses. */
10742 warn_about_parentheses (location_t loc
, enum tree_code code
,
10743 enum tree_code code_left
, tree arg_left
,
10744 enum tree_code code_right
, tree arg_right
)
10746 if (!warn_parentheses
)
10749 /* This macro tests that the expression ARG with original tree code
10750 CODE appears to be a boolean expression. or the result of folding a
10751 boolean expression. */
10752 #define APPEARS_TO_BE_BOOLEAN_EXPR_P(CODE, ARG) \
10753 (truth_value_p (TREE_CODE (ARG)) \
10754 || TREE_CODE (TREE_TYPE (ARG)) == BOOLEAN_TYPE \
10755 /* Folding may create 0 or 1 integers from other expressions. */ \
10756 || ((CODE) != INTEGER_CST \
10757 && (integer_onep (ARG) || integer_zerop (ARG))))
10762 if (code_left
== PLUS_EXPR
)
10763 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10764 "suggest parentheses around %<+%> inside %<<<%>");
10765 else if (code_right
== PLUS_EXPR
)
10766 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10767 "suggest parentheses around %<+%> inside %<<<%>");
10768 else if (code_left
== MINUS_EXPR
)
10769 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10770 "suggest parentheses around %<-%> inside %<<<%>");
10771 else if (code_right
== MINUS_EXPR
)
10772 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10773 "suggest parentheses around %<-%> inside %<<<%>");
10777 if (code_left
== PLUS_EXPR
)
10778 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10779 "suggest parentheses around %<+%> inside %<>>%>");
10780 else if (code_right
== PLUS_EXPR
)
10781 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10782 "suggest parentheses around %<+%> inside %<>>%>");
10783 else if (code_left
== MINUS_EXPR
)
10784 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10785 "suggest parentheses around %<-%> inside %<>>%>");
10786 else if (code_right
== MINUS_EXPR
)
10787 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10788 "suggest parentheses around %<-%> inside %<>>%>");
10791 case TRUTH_ORIF_EXPR
:
10792 if (code_left
== TRUTH_ANDIF_EXPR
)
10793 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10794 "suggest parentheses around %<&&%> within %<||%>");
10795 else if (code_right
== TRUTH_ANDIF_EXPR
)
10796 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10797 "suggest parentheses around %<&&%> within %<||%>");
10801 if (code_left
== BIT_AND_EXPR
|| code_left
== BIT_XOR_EXPR
10802 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
)
10803 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10804 "suggest parentheses around arithmetic in operand of %<|%>");
10805 else if (code_right
== BIT_AND_EXPR
|| code_right
== BIT_XOR_EXPR
10806 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
10807 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10808 "suggest parentheses around arithmetic in operand of %<|%>");
10809 /* Check cases like x|y==z */
10810 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
10811 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10812 "suggest parentheses around comparison in operand of %<|%>");
10813 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
10814 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10815 "suggest parentheses around comparison in operand of %<|%>");
10816 /* Check cases like !x | y */
10817 else if (code_left
== TRUTH_NOT_EXPR
10818 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
10819 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10820 "suggest parentheses around operand of "
10821 "%<!%> or change %<|%> to %<||%> or %<!%> to %<~%>");
10825 if (code_left
== BIT_AND_EXPR
10826 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
)
10827 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10828 "suggest parentheses around arithmetic in operand of %<^%>");
10829 else if (code_right
== BIT_AND_EXPR
10830 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
10831 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10832 "suggest parentheses around arithmetic in operand of %<^%>");
10833 /* Check cases like x^y==z */
10834 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
10835 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10836 "suggest parentheses around comparison in operand of %<^%>");
10837 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
10838 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10839 "suggest parentheses around comparison in operand of %<^%>");
10843 if (code_left
== PLUS_EXPR
)
10844 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10845 "suggest parentheses around %<+%> in operand of %<&%>");
10846 else if (code_right
== PLUS_EXPR
)
10847 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10848 "suggest parentheses around %<+%> in operand of %<&%>");
10849 else if (code_left
== MINUS_EXPR
)
10850 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10851 "suggest parentheses around %<-%> in operand of %<&%>");
10852 else if (code_right
== MINUS_EXPR
)
10853 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10854 "suggest parentheses around %<-%> in operand of %<&%>");
10855 /* Check cases like x&y==z */
10856 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
10857 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10858 "suggest parentheses around comparison in operand of %<&%>");
10859 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
10860 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10861 "suggest parentheses around comparison in operand of %<&%>");
10862 /* Check cases like !x & y */
10863 else if (code_left
== TRUTH_NOT_EXPR
10864 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
10865 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10866 "suggest parentheses around operand of "
10867 "%<!%> or change %<&%> to %<&&%> or %<!%> to %<~%>");
10871 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
10872 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10873 "suggest parentheses around comparison in operand of %<==%>");
10874 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
10875 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10876 "suggest parentheses around comparison in operand of %<==%>");
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 %<!=%>");
10888 if (TREE_CODE_CLASS (code
) == tcc_comparison
)
10890 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
10891 && code_left
!= NE_EXPR
&& code_left
!= EQ_EXPR
10892 && INTEGRAL_TYPE_P (TREE_TYPE (arg_left
)))
10893 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
10894 "comparisons like %<X<=Y<=Z%> do not "
10895 "have their mathematical meaning");
10896 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
10897 && code_right
!= NE_EXPR
&& code_right
!= EQ_EXPR
10898 && INTEGRAL_TYPE_P (TREE_TYPE (arg_right
)))
10899 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
10900 "comparisons like %<X<=Y<=Z%> do not "
10901 "have their mathematical meaning");
10905 #undef NOT_A_BOOLEAN_EXPR_P
10908 /* If LABEL (a LABEL_DECL) has not been used, issue a warning. */
10911 warn_for_unused_label (tree label
)
10913 if (!TREE_USED (label
))
10915 if (DECL_INITIAL (label
))
10916 warning (OPT_Wunused_label
, "label %q+D defined but not used", label
);
10918 warning (OPT_Wunused_label
, "label %q+D declared but not defined", label
);
10922 /* Warn for division by zero according to the value of DIVISOR. LOC
10923 is the location of the division operator. */
10926 warn_for_div_by_zero (location_t loc
, tree divisor
)
10928 /* If DIVISOR is zero, and has integral or fixed-point type, issue a warning
10929 about division by zero. Do not issue a warning if DIVISOR has a
10930 floating-point type, since we consider 0.0/0.0 a valid way of
10931 generating a NaN. */
10932 if (c_inhibit_evaluation_warnings
== 0
10933 && (integer_zerop (divisor
) || fixed_zerop (divisor
)))
10934 warning_at (loc
, OPT_Wdiv_by_zero
, "division by zero");
10937 /* Subroutine of build_binary_op. Give warnings for comparisons
10938 between signed and unsigned quantities that may fail. Do the
10939 checking based on the original operand trees ORIG_OP0 and ORIG_OP1,
10940 so that casts will be considered, but default promotions won't
10943 LOCATION is the location of the comparison operator.
10945 The arguments of this function map directly to local variables
10946 of build_binary_op. */
10949 warn_for_sign_compare (location_t location
,
10950 tree orig_op0
, tree orig_op1
,
10951 tree op0
, tree op1
,
10952 tree result_type
, enum tree_code resultcode
)
10954 int op0_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op0
));
10955 int op1_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op1
));
10956 int unsignedp0
, unsignedp1
;
10958 /* In C++, check for comparison of different enum types. */
10959 if (c_dialect_cxx()
10960 && TREE_CODE (TREE_TYPE (orig_op0
)) == ENUMERAL_TYPE
10961 && TREE_CODE (TREE_TYPE (orig_op1
)) == ENUMERAL_TYPE
10962 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0
))
10963 != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1
)))
10965 warning_at (location
,
10966 OPT_Wsign_compare
, "comparison between types %qT and %qT",
10967 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
));
10970 /* Do not warn if the comparison is being done in a signed type,
10971 since the signed type will only be chosen if it can represent
10972 all the values of the unsigned type. */
10973 if (!TYPE_UNSIGNED (result_type
))
10975 /* Do not warn if both operands are unsigned. */
10976 else if (op0_signed
== op1_signed
)
10980 tree sop
, uop
, base_type
;
10984 sop
= orig_op0
, uop
= orig_op1
;
10986 sop
= orig_op1
, uop
= orig_op0
;
10988 STRIP_TYPE_NOPS (sop
);
10989 STRIP_TYPE_NOPS (uop
);
10990 base_type
= (TREE_CODE (result_type
) == COMPLEX_TYPE
10991 ? TREE_TYPE (result_type
) : result_type
);
10993 /* Do not warn if the signed quantity is an unsuffixed integer
10994 literal (or some static constant expression involving such
10995 literals or a conditional expression involving such literals)
10996 and it is non-negative. */
10997 if (tree_expr_nonnegative_warnv_p (sop
, &ovf
))
10999 /* Do not warn if the comparison is an equality operation, the
11000 unsigned quantity is an integral constant, and it would fit
11001 in the result if the result were signed. */
11002 else if (TREE_CODE (uop
) == INTEGER_CST
11003 && (resultcode
== EQ_EXPR
|| resultcode
== NE_EXPR
)
11004 && int_fits_type_p (uop
, c_common_signed_type (base_type
)))
11006 /* In C, do not warn if the unsigned quantity is an enumeration
11007 constant and its maximum value would fit in the result if the
11008 result were signed. */
11009 else if (!c_dialect_cxx() && TREE_CODE (uop
) == INTEGER_CST
11010 && TREE_CODE (TREE_TYPE (uop
)) == ENUMERAL_TYPE
11011 && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (uop
)),
11012 c_common_signed_type (base_type
)))
11015 warning_at (location
,
11017 "comparison between signed and unsigned integer expressions");
11020 /* Warn if two unsigned values are being compared in a size larger
11021 than their original size, and one (and only one) is the result of
11022 a `~' operator. This comparison will always fail.
11024 Also warn if one operand is a constant, and the constant does not
11025 have all bits set that are set in the ~ operand when it is
11028 op0
= c_common_get_narrower (op0
, &unsignedp0
);
11029 op1
= c_common_get_narrower (op1
, &unsignedp1
);
11031 if ((TREE_CODE (op0
) == BIT_NOT_EXPR
)
11032 ^ (TREE_CODE (op1
) == BIT_NOT_EXPR
))
11034 if (TREE_CODE (op0
) == BIT_NOT_EXPR
)
11035 op0
= c_common_get_narrower (TREE_OPERAND (op0
, 0), &unsignedp0
);
11036 if (TREE_CODE (op1
) == BIT_NOT_EXPR
)
11037 op1
= c_common_get_narrower (TREE_OPERAND (op1
, 0), &unsignedp1
);
11039 if (host_integerp (op0
, 0) || host_integerp (op1
, 0))
11042 HOST_WIDE_INT constant
, mask
;
11046 if (host_integerp (op0
, 0))
11049 unsignedp
= unsignedp1
;
11050 constant
= tree_low_cst (op0
, 0);
11055 unsignedp
= unsignedp0
;
11056 constant
= tree_low_cst (op1
, 0);
11059 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
11060 if (bits
< TYPE_PRECISION (result_type
)
11061 && bits
< HOST_BITS_PER_LONG
&& unsignedp
)
11063 mask
= (~ (HOST_WIDE_INT
) 0) << bits
;
11064 if ((mask
& constant
) != mask
)
11067 warning (OPT_Wsign_compare
,
11068 "promoted ~unsigned is always non-zero");
11070 warning_at (location
, OPT_Wsign_compare
,
11071 "comparison of promoted ~unsigned with constant");
11075 else if (unsignedp0
&& unsignedp1
11076 && (TYPE_PRECISION (TREE_TYPE (op0
))
11077 < TYPE_PRECISION (result_type
))
11078 && (TYPE_PRECISION (TREE_TYPE (op1
))
11079 < TYPE_PRECISION (result_type
)))
11080 warning_at (location
, OPT_Wsign_compare
,
11081 "comparison of promoted ~unsigned with unsigned");
11085 /* RESULT_TYPE is the result of converting TYPE1 and TYPE2 to a common
11086 type via c_common_type. If -Wdouble-promotion is in use, and the
11087 conditions for warning have been met, issue a warning. GMSGID is
11088 the warning message. It must have two %T specifiers for the type
11089 that was converted (generally "float") and the type to which it was
11090 converted (generally "double), respectively. LOC is the location
11091 to which the awrning should refer. */
11094 do_warn_double_promotion (tree result_type
, tree type1
, tree type2
,
11095 const char *gmsgid
, location_t loc
)
11099 if (!warn_double_promotion
)
11101 /* If the conversion will not occur at run-time, there is no need to
11103 if (c_inhibit_evaluation_warnings
)
11105 if (TYPE_MAIN_VARIANT (result_type
) != double_type_node
11106 && TYPE_MAIN_VARIANT (result_type
) != complex_double_type_node
)
11108 if (TYPE_MAIN_VARIANT (type1
) == float_type_node
11109 || TYPE_MAIN_VARIANT (type1
) == complex_float_type_node
)
11110 source_type
= type1
;
11111 else if (TYPE_MAIN_VARIANT (type2
) == float_type_node
11112 || TYPE_MAIN_VARIANT (type2
) == complex_float_type_node
)
11113 source_type
= type2
;
11116 warning_at (loc
, OPT_Wdouble_promotion
, gmsgid
, source_type
, result_type
);
11119 /* Setup a TYPE_DECL node as a typedef representation.
11121 X is a TYPE_DECL for a typedef statement. Create a brand new
11122 ..._TYPE node (which will be just a variant of the existing
11123 ..._TYPE node with identical properties) and then install X
11124 as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
11126 The whole point here is to end up with a situation where each
11127 and every ..._TYPE node the compiler creates will be uniquely
11128 associated with AT MOST one node representing a typedef name.
11129 This way, even though the compiler substitutes corresponding
11130 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
11131 early on, later parts of the compiler can always do the reverse
11132 translation and get back the corresponding typedef name. For
11135 typedef struct S MY_TYPE;
11138 Later parts of the compiler might only know that `object' was of
11139 type `struct S' if it were not for code just below. With this
11140 code however, later parts of the compiler see something like:
11142 struct S' == struct S
11143 typedef struct S' MY_TYPE;
11146 And they can then deduce (from the node for type struct S') that
11147 the original object declaration was:
11151 Being able to do this is important for proper support of protoize,
11152 and also for generating precise symbolic debugging information
11153 which takes full account of the programmer's (typedef) vocabulary.
11155 Obviously, we don't want to generate a duplicate ..._TYPE node if
11156 the TYPE_DECL node that we are now processing really represents a
11157 standard built-in type. */
11160 set_underlying_type (tree x
)
11162 if (x
== error_mark_node
)
11164 if (DECL_IS_BUILTIN (x
))
11166 if (TYPE_NAME (TREE_TYPE (x
)) == 0)
11167 TYPE_NAME (TREE_TYPE (x
)) = x
;
11169 else if (TREE_TYPE (x
) != error_mark_node
11170 && DECL_ORIGINAL_TYPE (x
) == NULL_TREE
)
11172 tree tt
= TREE_TYPE (x
);
11173 DECL_ORIGINAL_TYPE (x
) = tt
;
11174 tt
= build_variant_type_copy (tt
);
11175 TYPE_STUB_DECL (tt
) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x
));
11176 TYPE_NAME (tt
) = x
;
11177 TREE_USED (tt
) = TREE_USED (x
);
11178 TREE_TYPE (x
) = tt
;
11182 /* Record the types used by the current global variable declaration
11183 being parsed, so that we can decide later to emit their debug info.
11184 Those types are in types_used_by_cur_var_decl, and we are going to
11185 store them in the types_used_by_vars_hash hash table.
11186 DECL is the declaration of the global variable that has been parsed. */
11189 record_types_used_by_current_var_decl (tree decl
)
11191 gcc_assert (decl
&& DECL_P (decl
) && TREE_STATIC (decl
));
11193 while (types_used_by_cur_var_decl
&& !types_used_by_cur_var_decl
->is_empty ())
11195 tree type
= types_used_by_cur_var_decl
->pop ();
11196 types_used_by_var_decl_insert (type
, decl
);
11200 /* If DECL is a typedef that is declared in the current function,
11201 record it for the purpose of -Wunused-local-typedefs. */
11204 record_locally_defined_typedef (tree decl
)
11206 struct c_language_function
*l
;
11208 if (!warn_unused_local_typedefs
11210 /* if this is not a locally defined typedef then we are not
11212 || !is_typedef_decl (decl
)
11213 || !decl_function_context (decl
))
11216 l
= (struct c_language_function
*) cfun
->language
;
11217 vec_safe_push (l
->local_typedefs
, decl
);
11220 /* If T is a TYPE_DECL declared locally, mark it as used. */
11223 maybe_record_typedef_use (tree t
)
11225 if (!is_typedef_decl (t
))
11228 TREE_USED (t
) = true;
11231 /* Warn if there are some unused locally defined typedefs in the
11232 current function. */
11235 maybe_warn_unused_local_typedefs (void)
11239 /* The number of times we have emitted -Wunused-local-typedefs
11240 warnings. If this is different from errorcount, that means some
11241 unrelated errors have been issued. In which case, we'll avoid
11242 emitting "unused-local-typedefs" warnings. */
11243 static int unused_local_typedefs_warn_count
;
11244 struct c_language_function
*l
;
11249 if ((l
= (struct c_language_function
*) cfun
->language
) == NULL
)
11252 if (warn_unused_local_typedefs
11253 && errorcount
== unused_local_typedefs_warn_count
)
11255 FOR_EACH_VEC_SAFE_ELT (l
->local_typedefs
, i
, decl
)
11256 if (!TREE_USED (decl
))
11257 warning_at (DECL_SOURCE_LOCATION (decl
),
11258 OPT_Wunused_local_typedefs
,
11259 "typedef %qD locally defined but not used", decl
);
11260 unused_local_typedefs_warn_count
= errorcount
;
11263 vec_free (l
->local_typedefs
);
11266 /* The C and C++ parsers both use vectors to hold function arguments.
11267 For efficiency, we keep a cache of unused vectors. This is the
11270 typedef vec
<tree
, va_gc
> *tree_gc_vec
;
11271 static GTY((deletable
)) vec
<tree_gc_vec
, va_gc
> *tree_vector_cache
;
11273 /* Return a new vector from the cache. If the cache is empty,
11274 allocate a new vector. These vectors are GC'ed, so it is OK if the
11275 pointer is not released.. */
11278 make_tree_vector (void)
11280 if (tree_vector_cache
&& !tree_vector_cache
->is_empty ())
11281 return tree_vector_cache
->pop ();
11284 /* Passing 0 to vec::alloc returns NULL, and our callers require
11285 that we always return a non-NULL value. The vector code uses
11286 4 when growing a NULL vector, so we do too. */
11287 vec
<tree
, va_gc
> *v
;
11293 /* Release a vector of trees back to the cache. */
11296 release_tree_vector (vec
<tree
, va_gc
> *vec
)
11301 vec_safe_push (tree_vector_cache
, vec
);
11305 /* Get a new tree vector holding a single tree. */
11308 make_tree_vector_single (tree t
)
11310 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
11311 ret
->quick_push (t
);
11315 /* Get a new tree vector of the TREE_VALUEs of a TREE_LIST chain. */
11318 make_tree_vector_from_list (tree list
)
11320 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
11321 for (; list
; list
= TREE_CHAIN (list
))
11322 vec_safe_push (ret
, TREE_VALUE (list
));
11326 /* Get a new tree vector which is a copy of an existing one. */
11329 make_tree_vector_copy (const vec
<tree
, va_gc
> *orig
)
11331 vec
<tree
, va_gc
> *ret
;
11335 ret
= make_tree_vector ();
11336 vec_safe_reserve (ret
, vec_safe_length (orig
));
11337 FOR_EACH_VEC_SAFE_ELT (orig
, ix
, t
)
11338 ret
->quick_push (t
);
11342 /* Return true if KEYWORD starts a type specifier. */
11345 keyword_begins_type_specifier (enum rid keyword
)
11361 case RID_DFLOAT128
:
11381 /* Return true if KEYWORD names a type qualifier. */
11384 keyword_is_type_qualifier (enum rid keyword
)
11397 /* Return true if KEYWORD names a storage class specifier.
11399 RID_TYPEDEF is not included in this list despite `typedef' being
11400 listed in C99 6.7.1.1. 6.7.1.3 indicates that `typedef' is listed as
11401 such for syntactic convenience only. */
11404 keyword_is_storage_class_specifier (enum rid keyword
)
11420 /* Return true if KEYWORD names a function-specifier [dcl.fct.spec]. */
11423 keyword_is_function_specifier (enum rid keyword
)
11437 /* Return true if KEYWORD names a decl-specifier [dcl.spec] or a
11438 declaration-specifier (C99 6.7). */
11441 keyword_is_decl_specifier (enum rid keyword
)
11443 if (keyword_is_storage_class_specifier (keyword
)
11444 || keyword_is_type_qualifier (keyword
)
11445 || keyword_is_function_specifier (keyword
))
11452 case RID_CONSTEXPR
:
11459 /* Initialize language-specific-bits of tree_contains_struct. */
11462 c_common_init_ts (void)
11464 MARK_TS_TYPED (C_MAYBE_CONST_EXPR
);
11465 MARK_TS_TYPED (EXCESS_PRECISION_EXPR
);
11466 MARK_TS_TYPED (ARRAY_NOTATION_REF
);
11469 /* Build a user-defined numeric literal out of an integer constant type VALUE
11470 with identifier SUFFIX. */
11473 build_userdef_literal (tree suffix_id
, tree value
,
11474 enum overflow_type overflow
, tree num_string
)
11476 tree literal
= make_node (USERDEF_LITERAL
);
11477 USERDEF_LITERAL_SUFFIX_ID (literal
) = suffix_id
;
11478 USERDEF_LITERAL_VALUE (literal
) = value
;
11479 USERDEF_LITERAL_OVERFLOW (literal
) = overflow
;
11480 USERDEF_LITERAL_NUM_STRING (literal
) = num_string
;
11484 /* For vector[index], convert the vector to a
11485 pointer of the underlying type. */
11487 convert_vector_to_pointer_for_subscript (location_t loc
,
11488 tree
* vecp
, tree index
)
11490 if (TREE_CODE (TREE_TYPE (*vecp
)) == VECTOR_TYPE
)
11492 tree type
= TREE_TYPE (*vecp
);
11495 if (TREE_CODE (index
) == INTEGER_CST
)
11496 if (!host_integerp (index
, 1)
11497 || ((unsigned HOST_WIDE_INT
) tree_low_cst (index
, 1)
11498 >= TYPE_VECTOR_SUBPARTS (type
)))
11499 warning_at (loc
, OPT_Warray_bounds
, "index value is out of bound");
11501 c_common_mark_addressable_vec (*vecp
);
11502 type
= build_qualified_type (TREE_TYPE (type
), TYPE_QUALS (type
));
11503 type
= build_pointer_type (type
);
11504 type1
= build_pointer_type (TREE_TYPE (*vecp
));
11505 *vecp
= build1 (ADDR_EXPR
, type1
, *vecp
);
11506 *vecp
= convert (type
, *vecp
);
11510 /* Determine which of the operands, if any, is a scalar that needs to be
11511 converted to a vector, for the range of operations. */
11513 scalar_to_vector (location_t loc
, enum tree_code code
, tree op0
, tree op1
,
11516 tree type0
= TREE_TYPE (op0
);
11517 tree type1
= TREE_TYPE (op1
);
11518 bool integer_only_op
= false;
11519 enum stv_conv ret
= stv_firstarg
;
11521 gcc_assert (TREE_CODE (type0
) == VECTOR_TYPE
11522 || TREE_CODE (type1
) == VECTOR_TYPE
);
11525 /* Most GENERIC binary expressions require homogeneous arguments.
11526 LSHIFT_EXPR and RSHIFT_EXPR are exceptions and accept a first
11527 argument that is a vector and a second one that is a scalar, so
11528 we never return stv_secondarg for them. */
11531 if (TREE_CODE (type0
) == INTEGER_TYPE
11532 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
11534 if (unsafe_conversion_p (TREE_TYPE (type1
), op0
, false))
11537 error_at (loc
, "conversion of scalar %qT to vector %qT "
11538 "involves truncation", type0
, type1
);
11542 return stv_firstarg
;
11549 integer_only_op
= true;
11550 /* ... fall through ... */
11552 case VEC_COND_EXPR
:
11557 case TRUNC_DIV_EXPR
:
11558 case CEIL_DIV_EXPR
:
11559 case FLOOR_DIV_EXPR
:
11560 case ROUND_DIV_EXPR
:
11561 case EXACT_DIV_EXPR
:
11562 case TRUNC_MOD_EXPR
:
11563 case FLOOR_MOD_EXPR
:
11571 /* What about UNLT_EXPR? */
11572 if (TREE_CODE (type0
) == VECTOR_TYPE
)
11575 ret
= stv_secondarg
;
11576 /* Swap TYPE0 with TYPE1 and OP0 with OP1 */
11577 tmp
= type0
; type0
= type1
; type1
= tmp
;
11578 tmp
= op0
; op0
= op1
; op1
= tmp
;
11581 if (TREE_CODE (type0
) == INTEGER_TYPE
11582 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
11584 if (unsafe_conversion_p (TREE_TYPE (type1
), op0
, false))
11587 error_at (loc
, "conversion of scalar %qT to vector %qT "
11588 "involves truncation", type0
, type1
);
11593 else if (!integer_only_op
11594 /* Allow integer --> real conversion if safe. */
11595 && (TREE_CODE (type0
) == REAL_TYPE
11596 || TREE_CODE (type0
) == INTEGER_TYPE
)
11597 && SCALAR_FLOAT_TYPE_P (TREE_TYPE (type1
)))
11599 if (unsafe_conversion_p (TREE_TYPE (type1
), op0
, false))
11602 error_at (loc
, "conversion of scalar %qT to vector %qT "
11603 "involves truncation", type0
, type1
);
11612 return stv_nothing
;
11615 /* Return true iff ALIGN is an integral constant that is a fundamental
11616 alignment, as defined by [basic.align] in the c++-11
11621 [A fundamental alignment is represented by an alignment less than or
11622 equal to the greatest alignment supported by the implementation
11623 in all contexts, which is equal to
11624 alignof(max_align_t)]. */
11627 cxx_fundamental_alignment_p (unsigned align
)
11629 return (align
<= MAX (TYPE_ALIGN (long_long_integer_type_node
),
11630 TYPE_ALIGN (long_double_type_node
)));
11633 #include "gt-c-family-c-common.h"