1 /* Subroutines shared by all languages that are variants of C.
2 Copyright (C) 1992-2015 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/>. */
20 #define GCC_C_COMMON_C
24 #include "coretypes.h"
31 #include "fold-const.h"
32 #include "stor-layout.h"
34 #include "stringpool.h"
37 #include "trans-mem.h"
45 #include "common/common-target.h"
46 #include "langhooks.h"
47 #include "tree-inline.h"
49 #include "diagnostic.h"
50 #include "tree-iterator.h"
55 #include "plugin-api.h"
59 #include "hard-reg-set.h"
64 #include "target-def.h"
66 #include "wide-int-print.h"
67 #include "gimple-expr.h"
69 cpp_reader
*parse_in
; /* Declared in c-pragma.h. */
71 /* The following symbols are subsumed in the c_global_trees array, and
72 listed here individually for documentation purposes.
74 INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
76 tree short_integer_type_node;
77 tree long_integer_type_node;
78 tree long_long_integer_type_node;
80 tree short_unsigned_type_node;
81 tree long_unsigned_type_node;
82 tree long_long_unsigned_type_node;
84 tree truthvalue_type_node;
85 tree truthvalue_false_node;
86 tree truthvalue_true_node;
88 tree ptrdiff_type_node;
90 tree unsigned_char_type_node;
91 tree signed_char_type_node;
94 tree char16_type_node;
95 tree char32_type_node;
98 tree double_type_node;
99 tree long_double_type_node;
101 tree complex_integer_type_node;
102 tree complex_float_type_node;
103 tree complex_double_type_node;
104 tree complex_long_double_type_node;
106 tree dfloat32_type_node;
107 tree dfloat64_type_node;
108 tree_dfloat128_type_node;
110 tree intQI_type_node;
111 tree intHI_type_node;
112 tree intSI_type_node;
113 tree intDI_type_node;
114 tree intTI_type_node;
116 tree unsigned_intQI_type_node;
117 tree unsigned_intHI_type_node;
118 tree unsigned_intSI_type_node;
119 tree unsigned_intDI_type_node;
120 tree unsigned_intTI_type_node;
122 tree widest_integer_literal_type_node;
123 tree widest_unsigned_literal_type_node;
125 Nodes for types `void *' and `const void *'.
127 tree ptr_type_node, const_ptr_type_node;
129 Nodes for types `char *' and `const char *'.
131 tree string_type_node, const_string_type_node;
133 Type `char[SOMENUMBER]'.
134 Used when an array of char is needed and the size is irrelevant.
136 tree char_array_type_node;
138 Type `wchar_t[SOMENUMBER]' or something like it.
139 Used when a wide string literal is created.
141 tree wchar_array_type_node;
143 Type `char16_t[SOMENUMBER]' or something like it.
144 Used when a UTF-16 string literal is created.
146 tree char16_array_type_node;
148 Type `char32_t[SOMENUMBER]' or something like it.
149 Used when a UTF-32 string literal is created.
151 tree char32_array_type_node;
153 Type `int ()' -- used for implicit declaration of functions.
155 tree default_function_type;
157 A VOID_TYPE node, packaged in a TREE_LIST.
161 The lazily created VAR_DECLs for __FUNCTION__, __PRETTY_FUNCTION__,
162 and __func__. (C doesn't generate __FUNCTION__ and__PRETTY_FUNCTION__
163 VAR_DECLS, but C++ does.)
165 tree function_name_decl_node;
166 tree pretty_function_name_decl_node;
167 tree c99_function_name_decl_node;
169 Stack of nested function name VAR_DECLs.
171 tree saved_function_name_decls;
175 tree c_global_trees
[CTI_MAX
];
177 /* Switches common to the C front ends. */
179 /* Nonzero means don't output line number information. */
181 char flag_no_line_commands
;
183 /* Nonzero causes -E output not to be done, but directives such as
184 #define that have side effects are still obeyed. */
188 /* Nonzero means dump macros in some fashion. */
190 char flag_dump_macros
;
192 /* Nonzero means pass #include lines through to the output. */
194 char flag_dump_includes
;
196 /* Nonzero means process PCH files while preprocessing. */
198 bool flag_pch_preprocess
;
200 /* The file name to which we should write a precompiled header, or
201 NULL if no header will be written in this compile. */
203 const char *pch_file
;
205 /* Nonzero if an ISO standard was selected. It rejects macros in the
210 /* C/ObjC language option variables. */
213 /* Nonzero means allow type mismatches in conditional expressions;
214 just make their values `void'. */
216 int flag_cond_mismatch
;
218 /* Nonzero means enable C89 Amendment 1 features. */
222 /* Nonzero means use the ISO C99 (or C11) dialect of C. */
226 /* Nonzero means use the ISO C11 dialect of C. */
230 /* Nonzero means that we have builtin functions, and main is an int. */
235 /* ObjC language option variables. */
238 /* Tells the compiler that this is a special run. Do not perform any
239 compiling, instead we are to test some platform dependent features
240 and output a C header file with appropriate definitions. */
242 int print_struct_values
;
244 /* Tells the compiler what is the constant string class for ObjC. */
246 const char *constant_string_class_name
;
248 /* UPC language option variables. */
250 /* Nonzero whenever UPC -fupc-threads-N is asserted.
251 The value N gives the number of UPC threads to be
252 defined at compile-time. */
253 int flag_upc_threads
;
255 /* Nonzero whenever UPC -fupc-pthreads-model-* is asserted. */
256 int flag_upc_pthreads
;
258 /* The implementation model for UPC threads that
259 are mapped to POSIX threads, specified at compilation
260 time by the -fupc-pthreads-model-* switch. */
261 upc_pthreads_model_kind upc_pthreads_model
;
263 /* C++ language option variables. */
266 /* Nonzero means generate separate instantiation control files and
267 juggle them at link time. */
269 int flag_use_repository
;
271 /* The C++ dialect being used. C++98 is the default. */
273 enum cxx_dialect cxx_dialect
= cxx98
;
275 /* Maximum template instantiation depth. This limit exists to limit the
276 time it takes to notice excessively recursive template instantiations.
278 The default is lower than the 1024 recommended by the C++0x standard
279 because G++ runs out of stack before 1024 with highly recursive template
280 argument deduction substitution (g++.dg/cpp0x/enum11.C). */
282 int max_tinst_depth
= 900;
284 /* The elements of `ridpointers' are identifier nodes for the reserved
285 type names and storage classes. It is indexed by a RID_... value. */
288 tree (*make_fname_decl
) (location_t
, tree
, int);
290 /* Nonzero means don't warn about problems that occur when the code is
292 int c_inhibit_evaluation_warnings
;
294 /* Whether we are building a boolean conversion inside
295 convert_for_assignment, or some other late binary operation. If
296 build_binary_op is called for C (from code shared by C and C++) in
297 this case, then the operands have already been folded and the
298 result will not be folded again, so C_MAYBE_CONST_EXPR should not
300 bool in_late_binary_op
;
302 /* Whether lexing has been completed, so subsequent preprocessor
303 errors should use the compiler's input_location. */
304 bool done_lexing
= false;
306 /* Information about how a function name is generated. */
309 tree
*const decl
; /* pointer to the VAR_DECL. */
310 const unsigned rid
; /* RID number for the identifier. */
311 const int pretty
; /* How pretty is it? */
314 /* The three ways of getting then name of the current function. */
316 const struct fname_var_t fname_vars
[] =
318 /* C99 compliant __func__, must be first. */
319 {&c99_function_name_decl_node
, RID_C99_FUNCTION_NAME
, 0},
320 /* GCC __FUNCTION__ compliant. */
321 {&function_name_decl_node
, RID_FUNCTION_NAME
, 0},
322 /* GCC __PRETTY_FUNCTION__ compliant. */
323 {&pretty_function_name_decl_node
, RID_PRETTY_FUNCTION_NAME
, 1},
327 /* Global visibility options. */
328 struct visibility_flags visibility_options
;
330 static tree
c_fully_fold_internal (tree expr
, bool, bool *, bool *);
331 static tree
check_case_value (location_t
, tree
);
332 static bool check_case_bounds (location_t
, tree
, tree
, tree
*, tree
*);
334 static tree
handle_packed_attribute (tree
*, tree
, tree
, int, bool *);
335 static tree
handle_nocommon_attribute (tree
*, tree
, tree
, int, bool *);
336 static tree
handle_common_attribute (tree
*, tree
, tree
, int, bool *);
337 static tree
handle_noreturn_attribute (tree
*, tree
, tree
, int, bool *);
338 static tree
handle_hot_attribute (tree
*, tree
, tree
, int, bool *);
339 static tree
handle_cold_attribute (tree
*, tree
, tree
, int, bool *);
340 static tree
handle_no_sanitize_address_attribute (tree
*, tree
, tree
,
342 static tree
handle_no_address_safety_analysis_attribute (tree
*, tree
, tree
,
344 static tree
handle_no_sanitize_undefined_attribute (tree
*, tree
, tree
, int,
346 static tree
handle_stack_protect_attribute (tree
*, tree
, tree
, int, bool *);
347 static tree
handle_noinline_attribute (tree
*, tree
, tree
, int, bool *);
348 static tree
handle_noclone_attribute (tree
*, tree
, tree
, int, bool *);
349 static tree
handle_noicf_attribute (tree
*, tree
, tree
, int, bool *);
350 static tree
handle_leaf_attribute (tree
*, tree
, tree
, int, bool *);
351 static tree
handle_always_inline_attribute (tree
*, tree
, tree
, int,
353 static tree
handle_gnu_inline_attribute (tree
*, tree
, tree
, int, bool *);
354 static tree
handle_artificial_attribute (tree
*, tree
, tree
, int, bool *);
355 static tree
handle_flatten_attribute (tree
*, tree
, tree
, int, bool *);
356 static tree
handle_error_attribute (tree
*, tree
, tree
, int, bool *);
357 static tree
handle_used_attribute (tree
*, tree
, tree
, int, bool *);
358 static tree
handle_unused_attribute (tree
*, tree
, tree
, int, bool *);
359 static tree
handle_externally_visible_attribute (tree
*, tree
, tree
, int,
361 static tree
handle_no_reorder_attribute (tree
*, tree
, tree
, int,
363 static tree
handle_const_attribute (tree
*, tree
, tree
, int, bool *);
364 static tree
handle_transparent_union_attribute (tree
*, tree
, tree
,
366 static tree
handle_constructor_attribute (tree
*, tree
, tree
, int, bool *);
367 static tree
handle_destructor_attribute (tree
*, tree
, tree
, int, bool *);
368 static tree
handle_mode_attribute (tree
*, tree
, tree
, int, bool *);
369 static tree
handle_section_attribute (tree
*, tree
, tree
, int, bool *);
370 static tree
handle_aligned_attribute (tree
*, tree
, tree
, int, bool *);
371 static tree
handle_weak_attribute (tree
*, tree
, tree
, int, bool *) ;
372 static tree
handle_alias_ifunc_attribute (bool, tree
*, tree
, tree
, bool *);
373 static tree
handle_ifunc_attribute (tree
*, tree
, tree
, int, bool *);
374 static tree
handle_alias_attribute (tree
*, tree
, tree
, int, bool *);
375 static tree
handle_weakref_attribute (tree
*, tree
, tree
, int, bool *) ;
376 static tree
handle_visibility_attribute (tree
*, tree
, tree
, int,
378 static tree
handle_tls_model_attribute (tree
*, tree
, tree
, int,
380 static tree
handle_no_instrument_function_attribute (tree
*, tree
,
382 static tree
handle_malloc_attribute (tree
*, tree
, tree
, int, bool *);
383 static tree
handle_returns_twice_attribute (tree
*, tree
, tree
, int, bool *);
384 static tree
handle_no_limit_stack_attribute (tree
*, tree
, tree
, int,
386 static tree
handle_pure_attribute (tree
*, tree
, tree
, int, bool *);
387 static tree
handle_tm_attribute (tree
*, tree
, tree
, int, bool *);
388 static tree
handle_tm_wrap_attribute (tree
*, tree
, tree
, int, bool *);
389 static tree
handle_novops_attribute (tree
*, tree
, tree
, int, bool *);
390 static tree
handle_deprecated_attribute (tree
*, tree
, tree
, int,
392 static tree
handle_vector_size_attribute (tree
*, tree
, tree
, int,
394 static tree
handle_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
395 static tree
handle_nothrow_attribute (tree
*, tree
, tree
, int, bool *);
396 static tree
handle_cleanup_attribute (tree
*, tree
, tree
, int, bool *);
397 static tree
handle_warn_unused_result_attribute (tree
*, tree
, tree
, int,
399 static tree
handle_sentinel_attribute (tree
*, tree
, tree
, int, bool *);
400 static tree
handle_type_generic_attribute (tree
*, tree
, tree
, int, bool *);
401 static tree
handle_alloc_size_attribute (tree
*, tree
, tree
, int, bool *);
402 static tree
handle_alloc_align_attribute (tree
*, tree
, tree
, int, bool *);
403 static tree
handle_assume_aligned_attribute (tree
*, tree
, tree
, int, bool *);
404 static tree
handle_target_attribute (tree
*, tree
, tree
, int, bool *);
405 static tree
handle_optimize_attribute (tree
*, tree
, tree
, int, bool *);
406 static tree
ignore_attribute (tree
*, tree
, tree
, int, bool *);
407 static tree
handle_no_split_stack_attribute (tree
*, tree
, tree
, int, bool *);
408 static tree
handle_fnspec_attribute (tree
*, tree
, tree
, int, bool *);
409 static tree
handle_warn_unused_attribute (tree
*, tree
, tree
, int, bool *);
410 static tree
handle_returns_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
411 static tree
handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int,
413 static tree
handle_omp_declare_target_attribute (tree
*, tree
, tree
, int,
415 static tree
handle_designated_init_attribute (tree
*, tree
, tree
, int, bool *);
416 static tree
handle_bnd_variable_size_attribute (tree
*, tree
, tree
, int, bool *);
417 static tree
handle_bnd_legacy (tree
*, tree
, tree
, int, bool *);
418 static tree
handle_bnd_instrument (tree
*, tree
, tree
, int, bool *);
420 static void check_function_nonnull (tree
, int, tree
*);
421 static void check_nonnull_arg (void *, tree
, unsigned HOST_WIDE_INT
);
422 static bool nonnull_check_p (tree
, unsigned HOST_WIDE_INT
);
423 static bool get_nonnull_operand (tree
, unsigned HOST_WIDE_INT
*);
424 static int resort_field_decl_cmp (const void *, const void *);
426 /* Reserved words. The third field is a mask: keywords are disabled
427 if they match the mask.
430 C --std=c89: D_C99 | D_CXXONLY | D_OBJC | D_CXX_OBJC
431 C --std=c99: D_CXXONLY | D_OBJC
432 ObjC is like C except that D_OBJC and D_CXX_OBJC are not set
433 UPC is like C except that D_UPC is not set
434 C++ --std=c98: D_CONLY | D_CXXOX | D_OBJC | D_UPC
435 C++ --std=c0x: D_CONLY | D_OBJC | D_UPC
436 ObjC++ is like C++ except that D_OBJC is not set
438 If -fno-asm is used, D_ASM is added to the mask. If
439 -fno-gnu-keywords is used, D_EXT is added. If -fno-asm and C in
440 C89 mode, D_EXT89 is added for both -fno-asm and -fno-gnu-keywords.
441 In C with -Wc++-compat, we warn if D_CXXWARN is set.
443 Note the complication of the D_CXX_OBJC keywords. These are
444 reserved words such as 'class'. In C++, 'class' is a reserved
445 word. In Objective-C++ it is too. In Objective-C, it is a
446 reserved word too, but only if it follows an '@' sign.
448 const struct c_common_resword c_common_reswords
[] =
450 { "_Alignas", RID_ALIGNAS
, D_CONLY
},
451 { "_Alignof", RID_ALIGNOF
, D_CONLY
},
452 { "_Atomic", RID_ATOMIC
, D_CONLY
},
453 { "_Bool", RID_BOOL
, D_CONLY
},
454 { "_Complex", RID_COMPLEX
, 0 },
455 { "_Cilk_spawn", RID_CILK_SPAWN
, 0 },
456 { "_Cilk_sync", RID_CILK_SYNC
, 0 },
457 { "_Cilk_for", RID_CILK_FOR
, 0 },
458 { "_Imaginary", RID_IMAGINARY
, D_CONLY
},
459 { "_Decimal32", RID_DFLOAT32
, D_CONLY
| D_EXT
},
460 { "_Decimal64", RID_DFLOAT64
, D_CONLY
| D_EXT
},
461 { "_Decimal128", RID_DFLOAT128
, D_CONLY
| D_EXT
},
462 { "_Fract", RID_FRACT
, D_CONLY
| D_EXT
},
463 { "_Accum", RID_ACCUM
, D_CONLY
| D_EXT
},
464 { "_Sat", RID_SAT
, D_CONLY
| D_EXT
},
465 { "_Static_assert", RID_STATIC_ASSERT
, D_CONLY
},
466 { "_Noreturn", RID_NORETURN
, D_CONLY
},
467 { "_Generic", RID_GENERIC
, D_CONLY
},
468 { "_Thread_local", RID_THREAD
, D_CONLY
},
469 { "__FUNCTION__", RID_FUNCTION_NAME
, 0 },
470 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME
, 0 },
471 { "__alignof", RID_ALIGNOF
, 0 },
472 { "__alignof__", RID_ALIGNOF
, 0 },
473 { "__asm", RID_ASM
, 0 },
474 { "__asm__", RID_ASM
, 0 },
475 { "__attribute", RID_ATTRIBUTE
, 0 },
476 { "__attribute__", RID_ATTRIBUTE
, 0 },
477 { "__auto_type", RID_AUTO_TYPE
, D_CONLY
},
478 { "__bases", RID_BASES
, D_CXXONLY
},
479 { "__builtin_call_with_static_chain",
480 RID_BUILTIN_CALL_WITH_STATIC_CHAIN
, D_CONLY
},
481 { "__builtin_choose_expr", RID_CHOOSE_EXPR
, D_CONLY
},
482 { "__builtin_complex", RID_BUILTIN_COMPLEX
, D_CONLY
},
483 { "__builtin_shuffle", RID_BUILTIN_SHUFFLE
, 0 },
484 { "__builtin_offsetof", RID_OFFSETOF
, 0 },
485 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P
, D_CONLY
},
486 { "__builtin_va_arg", RID_VA_ARG
, 0 },
487 { "__complex", RID_COMPLEX
, 0 },
488 { "__complex__", RID_COMPLEX
, 0 },
489 { "__const", RID_CONST
, 0 },
490 { "__const__", RID_CONST
, 0 },
491 { "__decltype", RID_DECLTYPE
, D_CXXONLY
},
492 { "__direct_bases", RID_DIRECT_BASES
, D_CXXONLY
},
493 { "__extension__", RID_EXTENSION
, 0 },
494 { "__func__", RID_C99_FUNCTION_NAME
, 0 },
495 { "__has_nothrow_assign", RID_HAS_NOTHROW_ASSIGN
, D_CXXONLY
},
496 { "__has_nothrow_constructor", RID_HAS_NOTHROW_CONSTRUCTOR
, D_CXXONLY
},
497 { "__has_nothrow_copy", RID_HAS_NOTHROW_COPY
, D_CXXONLY
},
498 { "__has_trivial_assign", RID_HAS_TRIVIAL_ASSIGN
, D_CXXONLY
},
499 { "__has_trivial_constructor", RID_HAS_TRIVIAL_CONSTRUCTOR
, D_CXXONLY
},
500 { "__has_trivial_copy", RID_HAS_TRIVIAL_COPY
, D_CXXONLY
},
501 { "__has_trivial_destructor", RID_HAS_TRIVIAL_DESTRUCTOR
, D_CXXONLY
},
502 { "__has_virtual_destructor", RID_HAS_VIRTUAL_DESTRUCTOR
, D_CXXONLY
},
503 { "__imag", RID_IMAGPART
, 0 },
504 { "__imag__", RID_IMAGPART
, 0 },
505 { "__inline", RID_INLINE
, 0 },
506 { "__inline__", RID_INLINE
, 0 },
507 { "__is_abstract", RID_IS_ABSTRACT
, D_CXXONLY
},
508 { "__is_base_of", RID_IS_BASE_OF
, D_CXXONLY
},
509 { "__is_class", RID_IS_CLASS
, D_CXXONLY
},
510 { "__is_empty", RID_IS_EMPTY
, D_CXXONLY
},
511 { "__is_enum", RID_IS_ENUM
, D_CXXONLY
},
512 { "__is_final", RID_IS_FINAL
, D_CXXONLY
},
513 { "__is_literal_type", RID_IS_LITERAL_TYPE
, D_CXXONLY
},
514 { "__is_pod", RID_IS_POD
, D_CXXONLY
},
515 { "__is_polymorphic", RID_IS_POLYMORPHIC
, D_CXXONLY
},
516 { "__is_standard_layout", RID_IS_STD_LAYOUT
, D_CXXONLY
},
517 { "__is_trivial", RID_IS_TRIVIAL
, D_CXXONLY
},
518 { "__is_trivially_assignable", RID_IS_TRIVIALLY_ASSIGNABLE
, D_CXXONLY
},
519 { "__is_trivially_constructible", RID_IS_TRIVIALLY_CONSTRUCTIBLE
, D_CXXONLY
},
520 { "__is_trivially_copyable", RID_IS_TRIVIALLY_COPYABLE
, D_CXXONLY
},
521 { "__is_union", RID_IS_UNION
, D_CXXONLY
},
522 { "__label__", RID_LABEL
, 0 },
523 { "__null", RID_NULL
, 0 },
524 { "__real", RID_REALPART
, 0 },
525 { "__real__", RID_REALPART
, 0 },
526 { "__restrict", RID_RESTRICT
, 0 },
527 { "__restrict__", RID_RESTRICT
, 0 },
528 { "__signed", RID_SIGNED
, 0 },
529 { "__signed__", RID_SIGNED
, 0 },
530 { "__thread", RID_THREAD
, 0 },
531 { "__transaction_atomic", RID_TRANSACTION_ATOMIC
, 0 },
532 { "__transaction_relaxed", RID_TRANSACTION_RELAXED
, 0 },
533 { "__transaction_cancel", RID_TRANSACTION_CANCEL
, 0 },
534 { "__typeof", RID_TYPEOF
, 0 },
535 { "__typeof__", RID_TYPEOF
, 0 },
536 { "__underlying_type", RID_UNDERLYING_TYPE
, D_CXXONLY
},
537 { "__volatile", RID_VOLATILE
, 0 },
538 { "__volatile__", RID_VOLATILE
, 0 },
539 { "alignas", RID_ALIGNAS
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
540 { "alignof", RID_ALIGNOF
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
541 { "asm", RID_ASM
, D_ASM
},
542 { "auto", RID_AUTO
, 0 },
543 { "bool", RID_BOOL
, D_CXXONLY
| D_CXXWARN
},
544 { "break", RID_BREAK
, 0 },
545 { "case", RID_CASE
, 0 },
546 { "catch", RID_CATCH
, D_CXX_OBJC
| D_CXXWARN
},
547 { "char", RID_CHAR
, 0 },
548 { "char16_t", RID_CHAR16
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
549 { "char32_t", RID_CHAR32
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
550 { "class", RID_CLASS
, D_CXX_OBJC
| D_CXXWARN
},
551 { "const", RID_CONST
, 0 },
552 { "constexpr", RID_CONSTEXPR
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
553 { "const_cast", RID_CONSTCAST
, D_CXXONLY
| D_CXXWARN
},
554 { "continue", RID_CONTINUE
, 0 },
555 { "decltype", RID_DECLTYPE
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
556 { "default", RID_DEFAULT
, 0 },
557 { "delete", RID_DELETE
, D_CXXONLY
| D_CXXWARN
},
559 { "double", RID_DOUBLE
, 0 },
560 { "dynamic_cast", RID_DYNCAST
, D_CXXONLY
| D_CXXWARN
},
561 { "else", RID_ELSE
, 0 },
562 { "enum", RID_ENUM
, 0 },
563 { "explicit", RID_EXPLICIT
, D_CXXONLY
| D_CXXWARN
},
564 { "export", RID_EXPORT
, D_CXXONLY
| D_CXXWARN
},
565 { "extern", RID_EXTERN
, 0 },
566 { "false", RID_FALSE
, D_CXXONLY
| D_CXXWARN
},
567 { "float", RID_FLOAT
, 0 },
568 { "for", RID_FOR
, 0 },
569 { "friend", RID_FRIEND
, D_CXXONLY
| D_CXXWARN
},
570 { "goto", RID_GOTO
, 0 },
572 { "inline", RID_INLINE
, D_EXT89
},
573 { "int", RID_INT
, 0 },
574 { "long", RID_LONG
, 0 },
575 { "mutable", RID_MUTABLE
, D_CXXONLY
| D_CXXWARN
},
576 { "namespace", RID_NAMESPACE
, D_CXXONLY
| D_CXXWARN
},
577 { "new", RID_NEW
, D_CXXONLY
| D_CXXWARN
},
578 { "noexcept", RID_NOEXCEPT
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
579 { "nullptr", RID_NULLPTR
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
580 { "operator", RID_OPERATOR
, D_CXXONLY
| D_CXXWARN
},
581 { "private", RID_PRIVATE
, D_CXX_OBJC
| D_CXXWARN
},
582 { "protected", RID_PROTECTED
, D_CXX_OBJC
| D_CXXWARN
},
583 { "public", RID_PUBLIC
, D_CXX_OBJC
| D_CXXWARN
},
584 { "register", RID_REGISTER
, 0 },
585 { "reinterpret_cast", RID_REINTCAST
, D_CXXONLY
| D_CXXWARN
},
586 { "restrict", RID_RESTRICT
, D_CONLY
| D_C99
},
587 { "return", RID_RETURN
, 0 },
588 { "short", RID_SHORT
, 0 },
589 { "signed", RID_SIGNED
, 0 },
590 { "sizeof", RID_SIZEOF
, 0 },
591 { "static", RID_STATIC
, 0 },
592 { "static_assert", RID_STATIC_ASSERT
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
593 { "static_cast", RID_STATCAST
, D_CXXONLY
| D_CXXWARN
},
594 { "struct", RID_STRUCT
, 0 },
595 { "switch", RID_SWITCH
, 0 },
596 { "template", RID_TEMPLATE
, D_CXXONLY
| D_CXXWARN
},
597 { "this", RID_THIS
, D_CXXONLY
| D_CXXWARN
},
598 { "thread_local", RID_THREAD
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
599 { "throw", RID_THROW
, D_CXX_OBJC
| D_CXXWARN
},
600 { "true", RID_TRUE
, D_CXXONLY
| D_CXXWARN
},
601 { "try", RID_TRY
, D_CXX_OBJC
| D_CXXWARN
},
602 { "typedef", RID_TYPEDEF
, 0 },
603 { "typename", RID_TYPENAME
, D_CXXONLY
| D_CXXWARN
},
604 { "typeid", RID_TYPEID
, D_CXXONLY
| D_CXXWARN
},
605 { "typeof", RID_TYPEOF
, D_ASM
| D_EXT
},
606 { "union", RID_UNION
, 0 },
607 { "unsigned", RID_UNSIGNED
, 0 },
608 { "using", RID_USING
, D_CXXONLY
| D_CXXWARN
},
609 { "virtual", RID_VIRTUAL
, D_CXXONLY
| D_CXXWARN
},
610 { "void", RID_VOID
, 0 },
611 { "volatile", RID_VOLATILE
, 0 },
612 { "wchar_t", RID_WCHAR
, D_CXXONLY
},
613 { "while", RID_WHILE
, 0 },
614 /* These Objective-C keywords are recognized only immediately after
616 { "compatibility_alias", RID_AT_ALIAS
, D_OBJC
},
617 { "defs", RID_AT_DEFS
, D_OBJC
},
618 { "encode", RID_AT_ENCODE
, D_OBJC
},
619 { "end", RID_AT_END
, D_OBJC
},
620 { "implementation", RID_AT_IMPLEMENTATION
, D_OBJC
},
621 { "interface", RID_AT_INTERFACE
, D_OBJC
},
622 { "protocol", RID_AT_PROTOCOL
, D_OBJC
},
623 { "selector", RID_AT_SELECTOR
, D_OBJC
},
624 { "finally", RID_AT_FINALLY
, D_OBJC
},
625 { "synchronized", RID_AT_SYNCHRONIZED
, D_OBJC
},
626 { "optional", RID_AT_OPTIONAL
, D_OBJC
},
627 { "required", RID_AT_REQUIRED
, D_OBJC
},
628 { "property", RID_AT_PROPERTY
, D_OBJC
},
629 { "package", RID_AT_PACKAGE
, D_OBJC
},
630 { "synthesize", RID_AT_SYNTHESIZE
, D_OBJC
},
631 { "dynamic", RID_AT_DYNAMIC
, D_OBJC
},
632 /* These are recognized only in protocol-qualifier context
634 { "bycopy", RID_BYCOPY
, D_OBJC
},
635 { "byref", RID_BYREF
, D_OBJC
},
636 { "in", RID_IN
, D_OBJC
},
637 { "inout", RID_INOUT
, D_OBJC
},
638 { "oneway", RID_ONEWAY
, D_OBJC
},
639 { "out", RID_OUT
, D_OBJC
},
642 { "shared", RID_SHARED
, D_UPC
},
643 { "relaxed", RID_RELAXED
, D_UPC
},
644 { "strict", RID_STRICT
, D_UPC
},
645 { "upc_barrier", RID_UPC_BARRIER
, D_UPC
},
646 { "upc_blocksizeof", RID_UPC_BLOCKSIZEOF
, D_UPC
},
647 { "upc_elemsizeof", RID_UPC_ELEMSIZEOF
, D_UPC
},
648 { "upc_forall", RID_UPC_FORALL
, D_UPC
},
649 { "upc_localsizeof", RID_UPC_LOCALSIZEOF
, D_UPC
},
650 { "upc_notify", RID_UPC_NOTIFY
, D_UPC
},
651 { "upc_wait", RID_UPC_WAIT
, D_UPC
},
653 /* These are recognized inside a property attribute list */
654 { "assign", RID_ASSIGN
, D_OBJC
},
655 { "copy", RID_COPY
, D_OBJC
},
656 { "getter", RID_GETTER
, D_OBJC
},
657 { "nonatomic", RID_NONATOMIC
, D_OBJC
},
658 { "readonly", RID_READONLY
, D_OBJC
},
659 { "readwrite", RID_READWRITE
, D_OBJC
},
660 { "retain", RID_RETAIN
, D_OBJC
},
661 { "setter", RID_SETTER
, D_OBJC
},
664 const unsigned int num_c_common_reswords
=
665 sizeof c_common_reswords
/ sizeof (struct c_common_resword
);
667 /* Table of machine-independent attributes common to all C-like languages.
669 All attributes referencing arguments should be additionally processed
670 in chkp_copy_function_type_adding_bounds for correct instrumentation
671 by Pointer Bounds Checker.
672 Current list of processed common attributes: nonnull. */
673 const struct attribute_spec c_common_attribute_table
[] =
675 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
676 affects_type_identity } */
677 { "packed", 0, 0, false, false, false,
678 handle_packed_attribute
, false},
679 { "nocommon", 0, 0, true, false, false,
680 handle_nocommon_attribute
, false},
681 { "common", 0, 0, true, false, false,
682 handle_common_attribute
, false },
683 /* FIXME: logically, noreturn attributes should be listed as
684 "false, true, true" and apply to function types. But implementing this
685 would require all the places in the compiler that use TREE_THIS_VOLATILE
686 on a decl to identify non-returning functions to be located and fixed
687 to check the function type instead. */
688 { "noreturn", 0, 0, true, false, false,
689 handle_noreturn_attribute
, false },
690 { "volatile", 0, 0, true, false, false,
691 handle_noreturn_attribute
, false },
692 { "stack_protect", 0, 0, true, false, false,
693 handle_stack_protect_attribute
, false },
694 { "noinline", 0, 0, true, false, false,
695 handle_noinline_attribute
, false },
696 { "noclone", 0, 0, true, false, false,
697 handle_noclone_attribute
, false },
698 { "no_icf", 0, 0, true, false, false,
699 handle_noicf_attribute
, false },
700 { "leaf", 0, 0, true, false, false,
701 handle_leaf_attribute
, false },
702 { "always_inline", 0, 0, true, false, false,
703 handle_always_inline_attribute
, false },
704 { "gnu_inline", 0, 0, true, false, false,
705 handle_gnu_inline_attribute
, false },
706 { "artificial", 0, 0, true, false, false,
707 handle_artificial_attribute
, false },
708 { "flatten", 0, 0, true, false, false,
709 handle_flatten_attribute
, false },
710 { "used", 0, 0, true, false, false,
711 handle_used_attribute
, false },
712 { "unused", 0, 0, false, false, false,
713 handle_unused_attribute
, false },
714 { "externally_visible", 0, 0, true, false, false,
715 handle_externally_visible_attribute
, false },
716 { "no_reorder", 0, 0, true, false, false,
717 handle_no_reorder_attribute
, false },
718 /* The same comments as for noreturn attributes apply to const ones. */
719 { "const", 0, 0, true, false, false,
720 handle_const_attribute
, false },
721 { "transparent_union", 0, 0, false, false, false,
722 handle_transparent_union_attribute
, false },
723 { "constructor", 0, 1, true, false, false,
724 handle_constructor_attribute
, false },
725 { "destructor", 0, 1, true, false, false,
726 handle_destructor_attribute
, false },
727 { "mode", 1, 1, false, true, false,
728 handle_mode_attribute
, false },
729 { "section", 1, 1, true, false, false,
730 handle_section_attribute
, false },
731 { "aligned", 0, 1, false, false, false,
732 handle_aligned_attribute
, false },
733 { "weak", 0, 0, true, false, false,
734 handle_weak_attribute
, false },
735 { "ifunc", 1, 1, true, false, false,
736 handle_ifunc_attribute
, false },
737 { "alias", 1, 1, true, false, false,
738 handle_alias_attribute
, false },
739 { "weakref", 0, 1, true, false, false,
740 handle_weakref_attribute
, false },
741 { "no_instrument_function", 0, 0, true, false, false,
742 handle_no_instrument_function_attribute
,
744 { "malloc", 0, 0, true, false, false,
745 handle_malloc_attribute
, false },
746 { "returns_twice", 0, 0, true, false, false,
747 handle_returns_twice_attribute
, false },
748 { "no_stack_limit", 0, 0, true, false, false,
749 handle_no_limit_stack_attribute
, false },
750 { "pure", 0, 0, true, false, false,
751 handle_pure_attribute
, false },
752 { "transaction_callable", 0, 0, false, true, false,
753 handle_tm_attribute
, false },
754 { "transaction_unsafe", 0, 0, false, true, false,
755 handle_tm_attribute
, false },
756 { "transaction_safe", 0, 0, false, true, false,
757 handle_tm_attribute
, false },
758 { "transaction_may_cancel_outer", 0, 0, false, true, false,
759 handle_tm_attribute
, false },
760 /* ??? These two attributes didn't make the transition from the
761 Intel language document to the multi-vendor language document. */
762 { "transaction_pure", 0, 0, false, true, false,
763 handle_tm_attribute
, false },
764 { "transaction_wrap", 1, 1, true, false, false,
765 handle_tm_wrap_attribute
, false },
766 /* For internal use (marking of builtins) only. The name contains space
767 to prevent its usage in source code. */
768 { "no vops", 0, 0, true, false, false,
769 handle_novops_attribute
, false },
770 { "deprecated", 0, 1, false, false, false,
771 handle_deprecated_attribute
, false },
772 { "vector_size", 1, 1, false, true, false,
773 handle_vector_size_attribute
, false },
774 { "visibility", 1, 1, false, false, false,
775 handle_visibility_attribute
, false },
776 { "tls_model", 1, 1, true, false, false,
777 handle_tls_model_attribute
, false },
778 { "nonnull", 0, -1, false, true, true,
779 handle_nonnull_attribute
, false },
780 { "nothrow", 0, 0, true, false, false,
781 handle_nothrow_attribute
, false },
782 { "may_alias", 0, 0, false, true, false, NULL
, false },
783 { "cleanup", 1, 1, true, false, false,
784 handle_cleanup_attribute
, false },
785 { "warn_unused_result", 0, 0, false, true, true,
786 handle_warn_unused_result_attribute
, false },
787 { "sentinel", 0, 1, false, true, true,
788 handle_sentinel_attribute
, false },
789 /* For internal use (marking of builtins) only. The name contains space
790 to prevent its usage in source code. */
791 { "type generic", 0, 0, false, true, true,
792 handle_type_generic_attribute
, false },
793 { "alloc_size", 1, 2, false, true, true,
794 handle_alloc_size_attribute
, false },
795 { "cold", 0, 0, true, false, false,
796 handle_cold_attribute
, false },
797 { "hot", 0, 0, true, false, false,
798 handle_hot_attribute
, false },
799 { "no_address_safety_analysis",
800 0, 0, true, false, false,
801 handle_no_address_safety_analysis_attribute
,
803 { "no_sanitize_address", 0, 0, true, false, false,
804 handle_no_sanitize_address_attribute
,
806 { "no_sanitize_thread", 0, 0, true, false, false,
807 handle_no_sanitize_address_attribute
,
809 { "no_sanitize_undefined", 0, 0, true, false, false,
810 handle_no_sanitize_undefined_attribute
,
812 { "warning", 1, 1, true, false, false,
813 handle_error_attribute
, false },
814 { "error", 1, 1, true, false, false,
815 handle_error_attribute
, false },
816 { "target", 1, -1, true, false, false,
817 handle_target_attribute
, false },
818 { "optimize", 1, -1, true, false, false,
819 handle_optimize_attribute
, false },
820 /* For internal use only. The leading '*' both prevents its usage in
821 source code and signals that it may be overridden by machine tables. */
822 { "*tm regparm", 0, 0, false, true, true,
823 ignore_attribute
, false },
824 { "no_split_stack", 0, 0, true, false, false,
825 handle_no_split_stack_attribute
, false },
826 /* For internal use (marking of builtins and runtime functions) only.
827 The name contains space to prevent its usage in source code. */
828 { "fn spec", 1, 1, false, true, true,
829 handle_fnspec_attribute
, false },
830 { "warn_unused", 0, 0, false, false, false,
831 handle_warn_unused_attribute
, false },
832 { "returns_nonnull", 0, 0, false, true, true,
833 handle_returns_nonnull_attribute
, false },
834 { "omp declare simd", 0, -1, true, false, false,
835 handle_omp_declare_simd_attribute
, false },
836 { "cilk simd function", 0, -1, true, false, false,
837 handle_omp_declare_simd_attribute
, false },
838 { "omp declare target", 0, 0, true, false, false,
839 handle_omp_declare_target_attribute
, false },
840 { "alloc_align", 1, 1, false, true, true,
841 handle_alloc_align_attribute
, false },
842 { "assume_aligned", 1, 2, false, true, true,
843 handle_assume_aligned_attribute
, false },
844 { "designated_init", 0, 0, false, true, false,
845 handle_designated_init_attribute
, false },
846 { "bnd_variable_size", 0, 0, true, false, false,
847 handle_bnd_variable_size_attribute
, false },
848 { "bnd_legacy", 0, 0, true, false, false,
849 handle_bnd_legacy
, false },
850 { "bnd_instrument", 0, 0, true, false, false,
851 handle_bnd_instrument
, false },
852 { NULL
, 0, 0, false, false, false, NULL
, false }
855 /* Give the specifications for the format attributes, used by C and all
858 All attributes referencing arguments should be additionally processed
859 in chkp_copy_function_type_adding_bounds for correct instrumentation
860 by Pointer Bounds Checker.
861 Current list of processed format attributes: format, format_arg. */
862 const struct attribute_spec c_common_format_attribute_table
[] =
864 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
865 affects_type_identity } */
866 { "format", 3, 3, false, true, true,
867 handle_format_attribute
, false },
868 { "format_arg", 1, 1, false, true, true,
869 handle_format_arg_attribute
, false },
870 { NULL
, 0, 0, false, false, false, NULL
, false }
873 /* Return identifier for address space AS. */
876 c_addr_space_name (addr_space_t as
)
878 int rid
= RID_FIRST_ADDR_SPACE
+ as
;
879 gcc_assert (ridpointers
[rid
]);
880 return IDENTIFIER_POINTER (ridpointers
[rid
]);
883 /* Push current bindings for the function name VAR_DECLS. */
886 start_fname_decls (void)
889 tree saved
= NULL_TREE
;
891 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
893 tree decl
= *fname_vars
[ix
].decl
;
897 saved
= tree_cons (decl
, build_int_cst (integer_type_node
, ix
),
899 *fname_vars
[ix
].decl
= NULL_TREE
;
902 if (saved
|| saved_function_name_decls
)
903 /* Normally they'll have been NULL, so only push if we've got a
904 stack, or they are non-NULL. */
905 saved_function_name_decls
= tree_cons (saved
, NULL_TREE
,
906 saved_function_name_decls
);
909 /* Finish up the current bindings, adding them into the current function's
910 statement tree. This must be done _before_ finish_stmt_tree is called.
911 If there is no current function, we must be at file scope and no statements
912 are involved. Pop the previous bindings. */
915 finish_fname_decls (void)
918 tree stmts
= NULL_TREE
;
919 tree stack
= saved_function_name_decls
;
921 for (; stack
&& TREE_VALUE (stack
); stack
= TREE_CHAIN (stack
))
922 append_to_statement_list (TREE_VALUE (stack
), &stmts
);
926 tree
*bodyp
= &DECL_SAVED_TREE (current_function_decl
);
928 if (TREE_CODE (*bodyp
) == BIND_EXPR
)
929 bodyp
= &BIND_EXPR_BODY (*bodyp
);
931 append_to_statement_list_force (*bodyp
, &stmts
);
935 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
936 *fname_vars
[ix
].decl
= NULL_TREE
;
940 /* We had saved values, restore them. */
943 for (saved
= TREE_PURPOSE (stack
); saved
; saved
= TREE_CHAIN (saved
))
945 tree decl
= TREE_PURPOSE (saved
);
946 unsigned ix
= TREE_INT_CST_LOW (TREE_VALUE (saved
));
948 *fname_vars
[ix
].decl
= decl
;
950 stack
= TREE_CHAIN (stack
);
952 saved_function_name_decls
= stack
;
955 /* Return the text name of the current function, suitably prettified
956 by PRETTY_P. Return string must be freed by caller. */
959 fname_as_string (int pretty_p
)
961 const char *name
= "top level";
964 cpp_string cstr
= { 0, 0 }, strname
;
972 if (current_function_decl
)
973 name
= lang_hooks
.decl_printable_name (current_function_decl
, vrb
);
975 len
= strlen (name
) + 3; /* Two for '"'s. One for NULL. */
977 namep
= XNEWVEC (char, len
);
978 snprintf (namep
, len
, "\"%s\"", name
);
979 strname
.text
= (unsigned char *) namep
;
980 strname
.len
= len
- 1;
982 if (cpp_interpret_string (parse_in
, &strname
, 1, &cstr
, CPP_STRING
))
985 return (const char *) cstr
.text
;
991 /* Return the VAR_DECL for a const char array naming the current
992 function. If the VAR_DECL has not yet been created, create it
993 now. RID indicates how it should be formatted and IDENTIFIER_NODE
994 ID is its name (unfortunately C and C++ hold the RID values of
995 keywords in different places, so we can't derive RID from ID in
996 this language independent code. LOC is the location of the
1000 fname_decl (location_t loc
, unsigned int rid
, tree id
)
1003 tree decl
= NULL_TREE
;
1005 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
1006 if (fname_vars
[ix
].rid
== rid
)
1009 decl
= *fname_vars
[ix
].decl
;
1012 /* If a tree is built here, it would normally have the lineno of
1013 the current statement. Later this tree will be moved to the
1014 beginning of the function and this line number will be wrong.
1015 To avoid this problem set the lineno to 0 here; that prevents
1016 it from appearing in the RTL. */
1018 location_t saved_location
= input_location
;
1019 input_location
= UNKNOWN_LOCATION
;
1021 stmts
= push_stmt_list ();
1022 decl
= (*make_fname_decl
) (loc
, id
, fname_vars
[ix
].pretty
);
1023 stmts
= pop_stmt_list (stmts
);
1024 if (!IS_EMPTY_STMT (stmts
))
1025 saved_function_name_decls
1026 = tree_cons (decl
, stmts
, saved_function_name_decls
);
1027 *fname_vars
[ix
].decl
= decl
;
1028 input_location
= saved_location
;
1030 if (!ix
&& !current_function_decl
)
1031 pedwarn (loc
, 0, "%qD is not defined outside of function scope", decl
);
1036 /* Given a STRING_CST, give it a suitable array-of-chars data type. */
1039 fix_string_type (tree value
)
1041 int length
= TREE_STRING_LENGTH (value
);
1043 tree e_type
, i_type
, a_type
;
1045 /* Compute the number of elements, for the array type. */
1046 if (TREE_TYPE (value
) == char_array_type_node
|| !TREE_TYPE (value
))
1049 e_type
= char_type_node
;
1051 else if (TREE_TYPE (value
) == char16_array_type_node
)
1053 nchars
= length
/ (TYPE_PRECISION (char16_type_node
) / BITS_PER_UNIT
);
1054 e_type
= char16_type_node
;
1056 else if (TREE_TYPE (value
) == char32_array_type_node
)
1058 nchars
= length
/ (TYPE_PRECISION (char32_type_node
) / BITS_PER_UNIT
);
1059 e_type
= char32_type_node
;
1063 nchars
= length
/ (TYPE_PRECISION (wchar_type_node
) / BITS_PER_UNIT
);
1064 e_type
= wchar_type_node
;
1067 /* C89 2.2.4.1, C99 5.2.4.1 (Translation limits). The analogous
1068 limit in C++98 Annex B is very large (65536) and is not normative,
1069 so we do not diagnose it (warn_overlength_strings is forced off
1070 in c_common_post_options). */
1071 if (warn_overlength_strings
)
1073 const int nchars_max
= flag_isoc99
? 4095 : 509;
1074 const int relevant_std
= flag_isoc99
? 99 : 90;
1075 if (nchars
- 1 > nchars_max
)
1076 /* Translators: The %d after 'ISO C' will be 90 or 99. Do not
1077 separate the %d from the 'C'. 'ISO' should not be
1078 translated, but it may be moved after 'C%d' in languages
1079 where modifiers follow nouns. */
1080 pedwarn (input_location
, OPT_Woverlength_strings
,
1081 "string length %qd is greater than the length %qd "
1082 "ISO C%d compilers are required to support",
1083 nchars
- 1, nchars_max
, relevant_std
);
1086 /* Create the array type for the string constant. The ISO C++
1087 standard says that a string literal has type `const char[N]' or
1088 `const wchar_t[N]'. We use the same logic when invoked as a C
1089 front-end with -Wwrite-strings.
1090 ??? We should change the type of an expression depending on the
1091 state of a warning flag. We should just be warning -- see how
1092 this is handled in the C++ front-end for the deprecated implicit
1093 conversion from string literals to `char*' or `wchar_t*'.
1095 The C++ front end relies on TYPE_MAIN_VARIANT of a cv-qualified
1096 array type being the unqualified version of that type.
1097 Therefore, if we are constructing an array of const char, we must
1098 construct the matching unqualified array type first. The C front
1099 end does not require this, but it does no harm, so we do it
1101 i_type
= build_index_type (size_int (nchars
- 1));
1102 a_type
= build_array_type (e_type
, i_type
);
1103 if (c_dialect_cxx() || warn_write_strings
)
1104 a_type
= c_build_qualified_type (a_type
, TYPE_QUAL_CONST
);
1106 TREE_TYPE (value
) = a_type
;
1107 TREE_CONSTANT (value
) = 1;
1108 TREE_READONLY (value
) = 1;
1109 TREE_STATIC (value
) = 1;
1113 /* If DISABLE is true, stop issuing warnings. This is used when
1114 parsing code that we know will not be executed. This function may
1115 be called multiple times, and works as a stack. */
1118 c_disable_warnings (bool disable
)
1122 ++c_inhibit_evaluation_warnings
;
1123 fold_defer_overflow_warnings ();
1127 /* If ENABLE is true, reenable issuing warnings. */
1130 c_enable_warnings (bool enable
)
1134 --c_inhibit_evaluation_warnings
;
1135 fold_undefer_and_ignore_overflow_warnings ();
1139 /* Fully fold EXPR, an expression that was not folded (beyond integer
1140 constant expressions and null pointer constants) when being built
1141 up. If IN_INIT, this is in a static initializer and certain
1142 changes are made to the folding done. Clear *MAYBE_CONST if
1143 MAYBE_CONST is not NULL and EXPR is definitely not a constant
1144 expression because it contains an evaluated operator (in C99) or an
1145 operator outside of sizeof returning an integer constant (in C90)
1146 not permitted in constant expressions, or because it contains an
1147 evaluated arithmetic overflow. (*MAYBE_CONST should typically be
1148 set to true by callers before calling this function.) Return the
1149 folded expression. Function arguments have already been folded
1150 before calling this function, as have the contents of SAVE_EXPR,
1151 TARGET_EXPR, BIND_EXPR, VA_ARG_EXPR, OBJ_TYPE_REF and
1152 C_MAYBE_CONST_EXPR. */
1155 c_fully_fold (tree expr
, bool in_init
, bool *maybe_const
)
1158 tree eptype
= NULL_TREE
;
1160 bool maybe_const_itself
= true;
1161 location_t loc
= EXPR_LOCATION (expr
);
1163 /* This function is not relevant to C++ because C++ folds while
1164 parsing, and may need changes to be correct for C++ when C++
1165 stops folding while parsing. */
1166 if (c_dialect_cxx ())
1170 maybe_const
= &dummy
;
1171 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
1173 eptype
= TREE_TYPE (expr
);
1174 expr
= TREE_OPERAND (expr
, 0);
1176 ret
= c_fully_fold_internal (expr
, in_init
, maybe_const
,
1177 &maybe_const_itself
);
1179 ret
= fold_convert_loc (loc
, eptype
, ret
);
1180 *maybe_const
&= maybe_const_itself
;
1184 /* Internal helper for c_fully_fold. EXPR and IN_INIT are as for
1185 c_fully_fold. *MAYBE_CONST_OPERANDS is cleared because of operands
1186 not permitted, while *MAYBE_CONST_ITSELF is cleared because of
1187 arithmetic overflow (for C90, *MAYBE_CONST_OPERANDS is carried from
1188 both evaluated and unevaluated subexpressions while
1189 *MAYBE_CONST_ITSELF is carried from only evaluated
1193 c_fully_fold_internal (tree expr
, bool in_init
, bool *maybe_const_operands
,
1194 bool *maybe_const_itself
)
1197 enum tree_code code
= TREE_CODE (expr
);
1198 enum tree_code_class kind
= TREE_CODE_CLASS (code
);
1199 location_t loc
= EXPR_LOCATION (expr
);
1200 tree op0
, op1
, op2
, op3
;
1201 tree orig_op0
, orig_op1
, orig_op2
;
1202 bool op0_const
= true, op1_const
= true, op2_const
= true;
1203 bool op0_const_self
= true, op1_const_self
= true, op2_const_self
= true;
1204 bool nowarning
= TREE_NO_WARNING (expr
);
1207 /* This function is not relevant to C++ because C++ folds while
1208 parsing, and may need changes to be correct for C++ when C++
1209 stops folding while parsing. */
1210 if (c_dialect_cxx ())
1213 /* Constants, declarations, statements, errors, SAVE_EXPRs and
1214 anything else not counted as an expression cannot usefully be
1215 folded further at this point. */
1216 if (!IS_EXPR_CODE_CLASS (kind
)
1217 || kind
== tcc_statement
1218 || code
== SAVE_EXPR
)
1221 /* Operands of variable-length expressions (function calls) have
1222 already been folded, as have __builtin_* function calls, and such
1223 expressions cannot occur in constant expressions. */
1224 if (kind
== tcc_vl_exp
)
1226 *maybe_const_operands
= false;
1231 if (code
== C_MAYBE_CONST_EXPR
)
1233 tree pre
= C_MAYBE_CONST_EXPR_PRE (expr
);
1234 tree inner
= C_MAYBE_CONST_EXPR_EXPR (expr
);
1235 if (C_MAYBE_CONST_EXPR_NON_CONST (expr
))
1236 *maybe_const_operands
= false;
1237 if (C_MAYBE_CONST_EXPR_INT_OPERANDS (expr
))
1238 *maybe_const_itself
= false;
1239 if (pre
&& !in_init
)
1240 ret
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr
), pre
, inner
);
1246 /* Assignment, increment, decrement, function call and comma
1247 operators, and statement expressions, cannot occur in constant
1248 expressions if evaluated / outside of sizeof. (Function calls
1249 were handled above, though VA_ARG_EXPR is treated like a function
1250 call here, and statement expressions are handled through
1251 C_MAYBE_CONST_EXPR to avoid folding inside them.) */
1255 case PREDECREMENT_EXPR
:
1256 case PREINCREMENT_EXPR
:
1257 case POSTDECREMENT_EXPR
:
1258 case POSTINCREMENT_EXPR
:
1260 *maybe_const_operands
= false;
1267 *maybe_const_operands
= false;
1275 /* Fold individual tree codes as appropriate. */
1278 case COMPOUND_LITERAL_EXPR
:
1279 /* Any non-constancy will have been marked in a containing
1280 C_MAYBE_CONST_EXPR; there is no more folding to do here. */
1284 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1285 op1
= TREE_OPERAND (expr
, 1);
1286 op2
= TREE_OPERAND (expr
, 2);
1287 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1288 maybe_const_itself
);
1289 STRIP_TYPE_NOPS (op0
);
1290 if (op0
!= orig_op0
)
1291 ret
= build3 (COMPONENT_REF
, TREE_TYPE (expr
), op0
, op1
, op2
);
1294 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1295 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1300 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1301 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1302 op2
= TREE_OPERAND (expr
, 2);
1303 op3
= TREE_OPERAND (expr
, 3);
1304 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1305 maybe_const_itself
);
1306 STRIP_TYPE_NOPS (op0
);
1307 op1
= c_fully_fold_internal (op1
, in_init
, maybe_const_operands
,
1308 maybe_const_itself
);
1309 STRIP_TYPE_NOPS (op1
);
1310 op1
= decl_constant_value_for_optimization (op1
);
1311 if (op0
!= orig_op0
|| op1
!= orig_op1
)
1312 ret
= build4 (ARRAY_REF
, TREE_TYPE (expr
), op0
, op1
, op2
, op3
);
1315 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1316 TREE_SIDE_EFFECTS (ret
) = TREE_SIDE_EFFECTS (expr
);
1317 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1324 case PREDECREMENT_EXPR
:
1325 case PREINCREMENT_EXPR
:
1326 case POSTDECREMENT_EXPR
:
1327 case POSTINCREMENT_EXPR
:
1331 case POINTER_PLUS_EXPR
:
1332 case TRUNC_DIV_EXPR
:
1334 case FLOOR_DIV_EXPR
:
1335 case TRUNC_MOD_EXPR
:
1337 case EXACT_DIV_EXPR
:
1350 case TRUTH_AND_EXPR
:
1352 case TRUTH_XOR_EXPR
:
1353 case UNORDERED_EXPR
:
1360 /* Binary operations evaluating both arguments (increment and
1361 decrement are binary internally in GCC). */
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
, maybe_const_operands
,
1365 maybe_const_itself
);
1366 STRIP_TYPE_NOPS (op0
);
1367 if (code
!= MODIFY_EXPR
1368 && code
!= PREDECREMENT_EXPR
1369 && code
!= PREINCREMENT_EXPR
1370 && code
!= POSTDECREMENT_EXPR
1371 && code
!= POSTINCREMENT_EXPR
)
1372 op0
= decl_constant_value_for_optimization (op0
);
1373 /* The RHS of a MODIFY_EXPR was fully folded when building that
1374 expression for the sake of conversion warnings. */
1375 if (code
!= MODIFY_EXPR
)
1376 op1
= c_fully_fold_internal (op1
, in_init
, maybe_const_operands
,
1377 maybe_const_itself
);
1378 STRIP_TYPE_NOPS (op1
);
1379 op1
= decl_constant_value_for_optimization (op1
);
1380 if (op0
!= orig_op0
|| op1
!= orig_op1
|| in_init
)
1382 ? fold_build2_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
)
1383 : fold_build2_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
);
1386 if (TREE_OVERFLOW_P (ret
)
1387 && !TREE_OVERFLOW_P (op0
)
1388 && !TREE_OVERFLOW_P (op1
))
1389 overflow_warning (EXPR_LOCATION (expr
), ret
);
1390 if ((code
== LSHIFT_EXPR
|| code
== RSHIFT_EXPR
)
1391 && TREE_CODE (orig_op1
) != INTEGER_CST
1392 && TREE_CODE (op1
) == INTEGER_CST
1393 && (TREE_CODE (TREE_TYPE (orig_op0
)) == INTEGER_TYPE
1394 || TREE_CODE (TREE_TYPE (orig_op0
)) == FIXED_POINT_TYPE
)
1395 && TREE_CODE (TREE_TYPE (orig_op1
)) == INTEGER_TYPE
1396 && c_inhibit_evaluation_warnings
== 0)
1398 if (tree_int_cst_sgn (op1
) < 0)
1399 warning_at (loc
, 0, (code
== LSHIFT_EXPR
1400 ? G_("left shift count is negative")
1401 : G_("right shift count is negative")));
1402 else if (compare_tree_int (op1
,
1403 TYPE_PRECISION (TREE_TYPE (orig_op0
)))
1405 warning_at (loc
, 0, (code
== LSHIFT_EXPR
1406 ? G_("left shift count >= width of type")
1407 : G_("right shift count >= width of type")));
1409 if ((code
== TRUNC_DIV_EXPR
1410 || code
== CEIL_DIV_EXPR
1411 || code
== FLOOR_DIV_EXPR
1412 || code
== EXACT_DIV_EXPR
1413 || code
== TRUNC_MOD_EXPR
)
1414 && TREE_CODE (orig_op1
) != INTEGER_CST
1415 && TREE_CODE (op1
) == INTEGER_CST
1416 && (TREE_CODE (TREE_TYPE (orig_op0
)) == INTEGER_TYPE
1417 || TREE_CODE (TREE_TYPE (orig_op0
)) == FIXED_POINT_TYPE
)
1418 && TREE_CODE (TREE_TYPE (orig_op1
)) == INTEGER_TYPE
)
1419 warn_for_div_by_zero (loc
, op1
);
1423 case FIX_TRUNC_EXPR
:
1426 case ADDR_SPACE_CONVERT_EXPR
:
1427 case VIEW_CONVERT_EXPR
:
1428 case NON_LVALUE_EXPR
:
1431 case TRUTH_NOT_EXPR
:
1436 /* Unary operations. */
1437 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1438 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1439 maybe_const_itself
);
1440 STRIP_TYPE_NOPS (op0
);
1441 if (code
!= ADDR_EXPR
&& code
!= REALPART_EXPR
&& code
!= IMAGPART_EXPR
)
1442 op0
= decl_constant_value_for_optimization (op0
);
1443 /* ??? Cope with user tricks that amount to offsetof. The middle-end is
1444 not prepared to deal with them if they occur in initializers.
1445 Avoid attempts to fold references to UPC shared components
1446 due to the complexities of UPC pointer-to-shared arithmetic. */
1448 && code
== ADDR_EXPR
1449 && (op1
= get_base_address (op0
)) != NULL_TREE
1450 && TREE_CODE (op1
) == INDIRECT_REF
1451 && !upc_shared_type_p (TREE_TYPE (op1
))
1452 && TREE_CONSTANT (TREE_OPERAND (op1
, 0)))
1453 ret
= fold_convert_loc (loc
, TREE_TYPE (expr
), fold_offsetof_1 (op0
));
1454 else if (op0
!= orig_op0
|| in_init
)
1456 ? fold_build1_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
)
1457 : fold_build1_loc (loc
, code
, TREE_TYPE (expr
), op0
);
1460 if (code
== INDIRECT_REF
1462 && TREE_CODE (ret
) == INDIRECT_REF
)
1464 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1465 TREE_SIDE_EFFECTS (ret
) = TREE_SIDE_EFFECTS (expr
);
1466 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1470 case FIX_TRUNC_EXPR
:
1473 /* Don't warn about explicit conversions. We will already
1474 have warned about suspect implicit conversions. */
1478 if (TREE_OVERFLOW_P (ret
) && !TREE_OVERFLOW_P (op0
))
1479 overflow_warning (EXPR_LOCATION (expr
), ret
);
1484 case TRUTH_ANDIF_EXPR
:
1485 case TRUTH_ORIF_EXPR
:
1486 /* Binary operations not necessarily evaluating both
1488 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1489 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1490 op0
= c_fully_fold_internal (op0
, in_init
, &op0_const
, &op0_const_self
);
1491 STRIP_TYPE_NOPS (op0
);
1493 unused_p
= (op0
== (code
== TRUTH_ANDIF_EXPR
1494 ? truthvalue_false_node
1495 : truthvalue_true_node
));
1496 c_disable_warnings (unused_p
);
1497 op1
= c_fully_fold_internal (op1
, in_init
, &op1_const
, &op1_const_self
);
1498 STRIP_TYPE_NOPS (op1
);
1499 c_enable_warnings (unused_p
);
1501 if (op0
!= orig_op0
|| op1
!= orig_op1
|| in_init
)
1503 ? fold_build2_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
)
1504 : fold_build2_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
);
1507 *maybe_const_operands
&= op0_const
;
1508 *maybe_const_itself
&= op0_const_self
;
1512 && (code
== TRUTH_ANDIF_EXPR
1513 ? op0
== truthvalue_false_node
1514 : op0
== truthvalue_true_node
)))
1515 *maybe_const_operands
&= op1_const
;
1518 && (code
== TRUTH_ANDIF_EXPR
1519 ? op0
== truthvalue_false_node
1520 : op0
== truthvalue_true_node
)))
1521 *maybe_const_itself
&= op1_const_self
;
1525 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1526 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1527 orig_op2
= op2
= TREE_OPERAND (expr
, 2);
1528 op0
= c_fully_fold_internal (op0
, in_init
, &op0_const
, &op0_const_self
);
1530 STRIP_TYPE_NOPS (op0
);
1531 c_disable_warnings (op0
== truthvalue_false_node
);
1532 op1
= c_fully_fold_internal (op1
, in_init
, &op1_const
, &op1_const_self
);
1533 STRIP_TYPE_NOPS (op1
);
1534 c_enable_warnings (op0
== truthvalue_false_node
);
1536 c_disable_warnings (op0
== truthvalue_true_node
);
1537 op2
= c_fully_fold_internal (op2
, in_init
, &op2_const
, &op2_const_self
);
1538 STRIP_TYPE_NOPS (op2
);
1539 c_enable_warnings (op0
== truthvalue_true_node
);
1541 if (op0
!= orig_op0
|| op1
!= orig_op1
|| op2
!= orig_op2
)
1542 ret
= fold_build3_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
, op2
);
1545 *maybe_const_operands
&= op0_const
;
1546 *maybe_const_itself
&= op0_const_self
;
1550 && op0
== truthvalue_false_node
))
1551 *maybe_const_operands
&= op1_const
;
1554 && op0
== truthvalue_false_node
))
1555 *maybe_const_itself
&= op1_const_self
;
1559 && op0
== truthvalue_true_node
))
1560 *maybe_const_operands
&= op2_const
;
1563 && op0
== truthvalue_true_node
))
1564 *maybe_const_itself
&= op2_const_self
;
1567 case EXCESS_PRECISION_EXPR
:
1568 /* Each case where an operand with excess precision may be
1569 encountered must remove the EXCESS_PRECISION_EXPR around
1570 inner operands and possibly put one around the whole
1571 expression or possibly convert to the semantic type (which
1572 c_fully_fold does); we cannot tell at this stage which is
1573 appropriate in any particular case. */
1577 /* Various codes may appear through folding built-in functions
1578 and their arguments. */
1583 /* Some folding may introduce NON_LVALUE_EXPRs; all lvalue checks
1584 have been done by this point, so remove them again. */
1585 nowarning
|= TREE_NO_WARNING (ret
);
1586 STRIP_TYPE_NOPS (ret
);
1587 if (nowarning
&& !TREE_NO_WARNING (ret
))
1589 if (!CAN_HAVE_LOCATION_P (ret
))
1590 ret
= build1 (NOP_EXPR
, TREE_TYPE (ret
), ret
);
1591 TREE_NO_WARNING (ret
) = 1;
1594 protected_set_expr_location (ret
, loc
);
1598 /* If not optimizing, EXP is not a VAR_DECL, or EXP has array type,
1599 return EXP. Otherwise, return either EXP or its known constant
1600 value (if it has one), but return EXP if EXP has mode BLKmode. ???
1601 Is the BLKmode test appropriate? */
1604 decl_constant_value_for_optimization (tree exp
)
1608 /* This function is only used by C, for c_fully_fold and other
1609 optimization, and may not be correct for C++. */
1610 if (c_dialect_cxx ())
1614 || TREE_CODE (exp
) != VAR_DECL
1615 || TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
1616 || DECL_MODE (exp
) == BLKmode
)
1619 ret
= decl_constant_value (exp
);
1620 /* Avoid unwanted tree sharing between the initializer and current
1621 function's body where the tree can be modified e.g. by the
1623 if (ret
!= exp
&& TREE_STATIC (exp
))
1624 ret
= unshare_expr (ret
);
1628 /* Print a warning if a constant expression had overflow in folding.
1629 Invoke this function on every expression that the language
1630 requires to be a constant expression.
1631 Note the ANSI C standard says it is erroneous for a
1632 constant expression to overflow. */
1635 constant_expression_warning (tree value
)
1637 if (warn_overflow
&& pedantic
1638 && (TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1639 || TREE_CODE (value
) == FIXED_CST
1640 || TREE_CODE (value
) == VECTOR_CST
1641 || TREE_CODE (value
) == COMPLEX_CST
)
1642 && TREE_OVERFLOW (value
))
1643 pedwarn (input_location
, OPT_Woverflow
, "overflow in constant expression");
1646 /* The same as above but print an unconditional error. */
1648 constant_expression_error (tree value
)
1650 if ((TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1651 || TREE_CODE (value
) == FIXED_CST
1652 || TREE_CODE (value
) == VECTOR_CST
1653 || TREE_CODE (value
) == COMPLEX_CST
)
1654 && TREE_OVERFLOW (value
))
1655 error ("overflow in constant expression");
1658 /* Print a warning if an expression had overflow in folding and its
1661 Invoke this function on every expression that
1662 (1) appears in the source code, and
1663 (2) is a constant expression that overflowed, and
1664 (3) is not already checked by convert_and_check;
1665 however, do not invoke this function on operands of explicit casts
1666 or when the expression is the result of an operator and any operand
1667 already overflowed. */
1670 overflow_warning (location_t loc
, tree value
)
1672 if (c_inhibit_evaluation_warnings
!= 0)
1675 switch (TREE_CODE (value
))
1678 warning_at (loc
, OPT_Woverflow
, "integer overflow in expression");
1682 warning_at (loc
, OPT_Woverflow
,
1683 "floating point overflow in expression");
1687 warning_at (loc
, OPT_Woverflow
, "fixed-point overflow in expression");
1691 warning_at (loc
, OPT_Woverflow
, "vector overflow in expression");
1695 if (TREE_CODE (TREE_REALPART (value
)) == INTEGER_CST
)
1696 warning_at (loc
, OPT_Woverflow
,
1697 "complex integer overflow in expression");
1698 else if (TREE_CODE (TREE_REALPART (value
)) == REAL_CST
)
1699 warning_at (loc
, OPT_Woverflow
,
1700 "complex floating point overflow in expression");
1708 /* Warn about uses of logical || / && operator in a context where it
1709 is likely that the bitwise equivalent was intended by the
1710 programmer. We have seen an expression in which CODE is a binary
1711 operator used to combine expressions OP_LEFT and OP_RIGHT, which before folding
1712 had CODE_LEFT and CODE_RIGHT, into an expression of type TYPE. */
1714 warn_logical_operator (location_t location
, enum tree_code code
, tree type
,
1715 enum tree_code code_left
, tree op_left
,
1716 enum tree_code
ARG_UNUSED (code_right
), tree op_right
)
1718 int or_op
= (code
== TRUTH_ORIF_EXPR
|| code
== TRUTH_OR_EXPR
);
1719 int in0_p
, in1_p
, in_p
;
1720 tree low0
, low1
, low
, high0
, high1
, high
, lhs
, rhs
, tem
;
1721 bool strict_overflow_p
= false;
1723 if (code
!= TRUTH_ANDIF_EXPR
1724 && code
!= TRUTH_AND_EXPR
1725 && code
!= TRUTH_ORIF_EXPR
1726 && code
!= TRUTH_OR_EXPR
)
1729 /* Warn if &&/|| are being used in a context where it is
1730 likely that the bitwise equivalent was intended by the
1731 programmer. That is, an expression such as op && MASK
1732 where op should not be any boolean expression, nor a
1733 constant, and mask seems to be a non-boolean integer constant. */
1734 if (!truth_value_p (code_left
)
1735 && INTEGRAL_TYPE_P (TREE_TYPE (op_left
))
1736 && !CONSTANT_CLASS_P (op_left
)
1737 && !TREE_NO_WARNING (op_left
)
1738 && TREE_CODE (op_right
) == INTEGER_CST
1739 && !integer_zerop (op_right
)
1740 && !integer_onep (op_right
))
1743 warning_at (location
, OPT_Wlogical_op
, "logical %<or%>"
1744 " applied to non-boolean constant");
1746 warning_at (location
, OPT_Wlogical_op
, "logical %<and%>"
1747 " applied to non-boolean constant");
1748 TREE_NO_WARNING (op_left
) = true;
1752 /* We do not warn for constants because they are typical of macro
1753 expansions that test for features. */
1754 if (CONSTANT_CLASS_P (op_left
) || CONSTANT_CLASS_P (op_right
))
1757 /* This warning only makes sense with logical operands. */
1758 if (!(truth_value_p (TREE_CODE (op_left
))
1759 || INTEGRAL_TYPE_P (TREE_TYPE (op_left
)))
1760 || !(truth_value_p (TREE_CODE (op_right
))
1761 || INTEGRAL_TYPE_P (TREE_TYPE (op_right
))))
1764 /* The range computations only work with scalars. */
1765 if (VECTOR_TYPE_P (TREE_TYPE (op_left
))
1766 || VECTOR_TYPE_P (TREE_TYPE (op_right
)))
1769 /* We first test whether either side separately is trivially true
1770 (with OR) or trivially false (with AND). If so, do not warn.
1771 This is a common idiom for testing ranges of data types in
1773 lhs
= make_range (op_left
, &in0_p
, &low0
, &high0
, &strict_overflow_p
);
1776 if (TREE_CODE (lhs
) == C_MAYBE_CONST_EXPR
)
1777 lhs
= C_MAYBE_CONST_EXPR_EXPR (lhs
);
1779 /* If this is an OR operation, invert both sides; now, the result
1780 should be always false to get a warning. */
1784 tem
= build_range_check (UNKNOWN_LOCATION
, type
, lhs
, in0_p
, low0
, high0
);
1785 if (tem
&& integer_zerop (tem
))
1788 rhs
= make_range (op_right
, &in1_p
, &low1
, &high1
, &strict_overflow_p
);
1791 if (TREE_CODE (rhs
) == C_MAYBE_CONST_EXPR
)
1792 rhs
= C_MAYBE_CONST_EXPR_EXPR (rhs
);
1794 /* If this is an OR operation, invert both sides; now, the result
1795 should be always false to get a warning. */
1799 tem
= build_range_check (UNKNOWN_LOCATION
, type
, rhs
, in1_p
, low1
, high1
);
1800 if (tem
&& integer_zerop (tem
))
1803 /* If both expressions have the same operand, if we can merge the
1804 ranges, and if the range test is always false, then warn. */
1805 if (operand_equal_p (lhs
, rhs
, 0)
1806 && merge_ranges (&in_p
, &low
, &high
, in0_p
, low0
, high0
,
1808 && 0 != (tem
= build_range_check (UNKNOWN_LOCATION
,
1809 type
, lhs
, in_p
, low
, high
))
1810 && integer_zerop (tem
))
1813 warning_at (location
, OPT_Wlogical_op
,
1815 "of collectively exhaustive tests is always true");
1817 warning_at (location
, OPT_Wlogical_op
,
1819 "of mutually exclusive tests is always false");
1823 /* Warn about logical not used on the left hand side operand of a comparison.
1824 This function assumes that the LHS is inside of TRUTH_NOT_EXPR.
1825 Do not warn if RHS is of a boolean type. */
1828 warn_logical_not_parentheses (location_t location
, enum tree_code code
,
1831 if (TREE_CODE_CLASS (code
) != tcc_comparison
1832 || TREE_TYPE (rhs
) == NULL_TREE
1833 || TREE_CODE (TREE_TYPE (rhs
)) == BOOLEAN_TYPE
)
1836 /* Don't warn for !x == 0 or !y != 0, those are equivalent to
1837 !(x == 0) or !(y != 0). */
1838 if ((code
== EQ_EXPR
|| code
== NE_EXPR
)
1839 && integer_zerop (rhs
))
1842 warning_at (location
, OPT_Wlogical_not_parentheses
,
1843 "logical not is only applied to the left hand side of "
1847 /* Warn if EXP contains any computations whose results are not used.
1848 Return true if a warning is printed; false otherwise. LOCUS is the
1849 (potential) location of the expression. */
1852 warn_if_unused_value (const_tree exp
, location_t locus
)
1855 if (TREE_USED (exp
) || TREE_NO_WARNING (exp
))
1858 /* Don't warn about void constructs. This includes casting to void,
1859 void function calls, and statement expressions with a final cast
1861 if (VOID_TYPE_P (TREE_TYPE (exp
)))
1864 if (EXPR_HAS_LOCATION (exp
))
1865 locus
= EXPR_LOCATION (exp
);
1867 switch (TREE_CODE (exp
))
1869 case PREINCREMENT_EXPR
:
1870 case POSTINCREMENT_EXPR
:
1871 case PREDECREMENT_EXPR
:
1872 case POSTDECREMENT_EXPR
:
1877 case TRY_CATCH_EXPR
:
1878 case WITH_CLEANUP_EXPR
:
1884 /* For a binding, warn if no side effect within it. */
1885 exp
= BIND_EXPR_BODY (exp
);
1889 case NON_LVALUE_EXPR
:
1891 exp
= TREE_OPERAND (exp
, 0);
1894 case TRUTH_ORIF_EXPR
:
1895 case TRUTH_ANDIF_EXPR
:
1896 /* In && or ||, warn if 2nd operand has no side effect. */
1897 exp
= TREE_OPERAND (exp
, 1);
1901 if (warn_if_unused_value (TREE_OPERAND (exp
, 0), locus
))
1903 /* Let people do `(foo (), 0)' without a warning. */
1904 if (TREE_CONSTANT (TREE_OPERAND (exp
, 1)))
1906 exp
= TREE_OPERAND (exp
, 1);
1910 /* If this is an expression with side effects, don't warn; this
1911 case commonly appears in macro expansions. */
1912 if (TREE_SIDE_EFFECTS (exp
))
1917 /* Don't warn about automatic dereferencing of references, since
1918 the user cannot control it. */
1919 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == REFERENCE_TYPE
)
1921 exp
= TREE_OPERAND (exp
, 0);
1927 /* Referencing a volatile value is a side effect, so don't warn. */
1928 if ((DECL_P (exp
) || REFERENCE_CLASS_P (exp
))
1929 && TREE_THIS_VOLATILE (exp
))
1932 /* If this is an expression which has no operands, there is no value
1933 to be unused. There are no such language-independent codes,
1934 but front ends may define such. */
1935 if (EXPRESSION_CLASS_P (exp
) && TREE_OPERAND_LENGTH (exp
) == 0)
1939 return warning_at (locus
, OPT_Wunused_value
, "value computed is not used");
1944 /* Print a warning about casts that might indicate violation
1945 of strict aliasing rules if -Wstrict-aliasing is used and
1946 strict aliasing mode is in effect. OTYPE is the original
1947 TREE_TYPE of EXPR, and TYPE the type we're casting to. */
1950 strict_aliasing_warning (tree otype
, tree type
, tree expr
)
1952 /* Strip pointer conversion chains and get to the correct original type. */
1954 otype
= TREE_TYPE (expr
);
1956 if (!(flag_strict_aliasing
1957 && POINTER_TYPE_P (type
)
1958 && POINTER_TYPE_P (otype
)
1959 && !VOID_TYPE_P (TREE_TYPE (type
)))
1960 /* If the type we are casting to is a ref-all pointer
1961 dereferencing it is always valid. */
1962 || TYPE_REF_CAN_ALIAS_ALL (type
))
1965 if ((warn_strict_aliasing
> 1) && TREE_CODE (expr
) == ADDR_EXPR
1966 && (DECL_P (TREE_OPERAND (expr
, 0))
1967 || handled_component_p (TREE_OPERAND (expr
, 0))))
1969 /* Casting the address of an object to non void pointer. Warn
1970 if the cast breaks type based aliasing. */
1971 if (!COMPLETE_TYPE_P (TREE_TYPE (type
)) && warn_strict_aliasing
== 2)
1973 warning (OPT_Wstrict_aliasing
, "type-punning to incomplete type "
1974 "might break strict-aliasing rules");
1979 /* warn_strict_aliasing >= 3. This includes the default (3).
1980 Only warn if the cast is dereferenced immediately. */
1981 alias_set_type set1
=
1982 get_alias_set (TREE_TYPE (TREE_OPERAND (expr
, 0)));
1983 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
1985 if (set1
!= set2
&& set2
!= 0
1986 && (set1
== 0 || !alias_sets_conflict_p (set1
, set2
)))
1988 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1989 "pointer will break strict-aliasing rules");
1992 else if (warn_strict_aliasing
== 2
1993 && !alias_sets_must_conflict_p (set1
, set2
))
1995 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1996 "pointer might break strict-aliasing rules");
2002 if ((warn_strict_aliasing
== 1) && !VOID_TYPE_P (TREE_TYPE (otype
)))
2004 /* At this level, warn for any conversions, even if an address is
2005 not taken in the same statement. This will likely produce many
2006 false positives, but could be useful to pinpoint problems that
2007 are not revealed at higher levels. */
2008 alias_set_type set1
= get_alias_set (TREE_TYPE (otype
));
2009 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
2010 if (!COMPLETE_TYPE_P (type
)
2011 || !alias_sets_must_conflict_p (set1
, set2
))
2013 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
2014 "pointer might break strict-aliasing rules");
2022 /* Warn about memset (&a, 0, sizeof (&a)); and similar mistakes with
2023 sizeof as last operand of certain builtins. */
2026 sizeof_pointer_memaccess_warning (location_t
*sizeof_arg_loc
, tree callee
,
2027 vec
<tree
, va_gc
> *params
, tree
*sizeof_arg
,
2028 bool (*comp_types
) (tree
, tree
))
2030 tree type
, dest
= NULL_TREE
, src
= NULL_TREE
, tem
;
2031 bool strop
= false, cmp
= false;
2032 unsigned int idx
= ~0;
2035 if (TREE_CODE (callee
) != FUNCTION_DECL
2036 || DECL_BUILT_IN_CLASS (callee
) != BUILT_IN_NORMAL
2037 || vec_safe_length (params
) <= 1)
2040 switch (DECL_FUNCTION_CODE (callee
))
2042 case BUILT_IN_STRNCMP
:
2043 case BUILT_IN_STRNCASECMP
:
2046 case BUILT_IN_STRNCPY
:
2047 case BUILT_IN_STRNCPY_CHK
:
2048 case BUILT_IN_STRNCAT
:
2049 case BUILT_IN_STRNCAT_CHK
:
2050 case BUILT_IN_STPNCPY
:
2051 case BUILT_IN_STPNCPY_CHK
:
2054 case BUILT_IN_MEMCPY
:
2055 case BUILT_IN_MEMCPY_CHK
:
2056 case BUILT_IN_MEMMOVE
:
2057 case BUILT_IN_MEMMOVE_CHK
:
2058 if (params
->length () < 3)
2061 dest
= (*params
)[0];
2064 case BUILT_IN_BCOPY
:
2065 if (params
->length () < 3)
2068 dest
= (*params
)[1];
2071 case BUILT_IN_MEMCMP
:
2073 if (params
->length () < 3)
2076 dest
= (*params
)[0];
2080 case BUILT_IN_MEMSET
:
2081 case BUILT_IN_MEMSET_CHK
:
2082 if (params
->length () < 3)
2084 dest
= (*params
)[0];
2087 case BUILT_IN_BZERO
:
2088 dest
= (*params
)[0];
2091 case BUILT_IN_STRNDUP
:
2096 case BUILT_IN_MEMCHR
:
2097 if (params
->length () < 3)
2102 case BUILT_IN_SNPRINTF
:
2103 case BUILT_IN_SNPRINTF_CHK
:
2104 case BUILT_IN_VSNPRINTF
:
2105 case BUILT_IN_VSNPRINTF_CHK
:
2106 dest
= (*params
)[0];
2117 if (sizeof_arg
[idx
] == NULL
|| sizeof_arg
[idx
] == error_mark_node
)
2120 type
= TYPE_P (sizeof_arg
[idx
])
2121 ? sizeof_arg
[idx
] : TREE_TYPE (sizeof_arg
[idx
]);
2122 if (!POINTER_TYPE_P (type
))
2126 && (tem
= tree_strip_nop_conversions (dest
))
2127 && POINTER_TYPE_P (TREE_TYPE (tem
))
2128 && comp_types (TREE_TYPE (TREE_TYPE (tem
)), type
))
2132 && (tem
= tree_strip_nop_conversions (src
))
2133 && POINTER_TYPE_P (TREE_TYPE (tem
))
2134 && comp_types (TREE_TYPE (TREE_TYPE (tem
)), type
))
2137 loc
= sizeof_arg_loc
[idx
];
2141 if (!TYPE_P (sizeof_arg
[idx
])
2142 && operand_equal_p (dest
, sizeof_arg
[idx
], 0)
2143 && comp_types (TREE_TYPE (dest
), type
))
2145 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2146 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2147 "argument to %<sizeof%> in %qD call is the same "
2148 "expression as the destination; did you mean to "
2149 "remove the addressof?", callee
);
2150 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2151 == TYPE_PRECISION (char_type_node
))
2153 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2154 "argument to %<sizeof%> in %qD call is the same "
2155 "expression as the destination; did you mean to "
2156 "provide an explicit length?", callee
);
2158 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2159 "argument to %<sizeof%> in %qD call is the same "
2160 "expression as the destination; did you mean to "
2161 "dereference it?", callee
);
2165 if (POINTER_TYPE_P (TREE_TYPE (dest
))
2167 && comp_types (TREE_TYPE (dest
), type
)
2168 && !VOID_TYPE_P (TREE_TYPE (type
)))
2170 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2171 "argument to %<sizeof%> in %qD call is the same "
2172 "pointer type %qT as the destination; expected %qT "
2173 "or an explicit length", callee
, TREE_TYPE (dest
),
2174 TREE_TYPE (TREE_TYPE (dest
)));
2181 if (!TYPE_P (sizeof_arg
[idx
])
2182 && operand_equal_p (src
, sizeof_arg
[idx
], 0)
2183 && comp_types (TREE_TYPE (src
), type
))
2185 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2186 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2187 "argument to %<sizeof%> in %qD call is the same "
2188 "expression as the source; did you mean to "
2189 "remove the addressof?", callee
);
2190 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2191 == TYPE_PRECISION (char_type_node
))
2193 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2194 "argument to %<sizeof%> in %qD call is the same "
2195 "expression as the source; did you mean to "
2196 "provide an explicit length?", callee
);
2198 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2199 "argument to %<sizeof%> in %qD call is the same "
2200 "expression as the source; did you mean to "
2201 "dereference it?", callee
);
2205 if (POINTER_TYPE_P (TREE_TYPE (src
))
2207 && comp_types (TREE_TYPE (src
), type
)
2208 && !VOID_TYPE_P (TREE_TYPE (type
)))
2210 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2211 "argument to %<sizeof%> in %qD call is the same "
2212 "pointer type %qT as the source; expected %qT "
2213 "or an explicit length", callee
, TREE_TYPE (src
),
2214 TREE_TYPE (TREE_TYPE (src
)));
2221 if (!TYPE_P (sizeof_arg
[idx
])
2222 && operand_equal_p (dest
, sizeof_arg
[idx
], 0)
2223 && comp_types (TREE_TYPE (dest
), type
))
2225 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2226 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2227 "argument to %<sizeof%> in %qD call is the same "
2228 "expression as the first source; did you mean to "
2229 "remove the addressof?", callee
);
2230 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2231 == TYPE_PRECISION (char_type_node
))
2233 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2234 "argument to %<sizeof%> in %qD call is the same "
2235 "expression as the first source; did you mean to "
2236 "provide an explicit length?", callee
);
2238 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2239 "argument to %<sizeof%> in %qD call is the same "
2240 "expression as the first source; did you mean to "
2241 "dereference it?", callee
);
2245 if (POINTER_TYPE_P (TREE_TYPE (dest
))
2247 && comp_types (TREE_TYPE (dest
), type
)
2248 && !VOID_TYPE_P (TREE_TYPE (type
)))
2250 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2251 "argument to %<sizeof%> in %qD call is the same "
2252 "pointer type %qT as the first source; expected %qT "
2253 "or an explicit length", callee
, TREE_TYPE (dest
),
2254 TREE_TYPE (TREE_TYPE (dest
)));
2261 if (!TYPE_P (sizeof_arg
[idx
])
2262 && operand_equal_p (src
, sizeof_arg
[idx
], 0)
2263 && comp_types (TREE_TYPE (src
), type
))
2265 if (TREE_CODE (sizeof_arg
[idx
]) == ADDR_EXPR
&& !strop
)
2266 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2267 "argument to %<sizeof%> in %qD call is the same "
2268 "expression as the second source; did you mean to "
2269 "remove the addressof?", callee
);
2270 else if ((TYPE_PRECISION (TREE_TYPE (type
))
2271 == TYPE_PRECISION (char_type_node
))
2273 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2274 "argument to %<sizeof%> in %qD call is the same "
2275 "expression as the second source; did you mean to "
2276 "provide an explicit length?", callee
);
2278 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2279 "argument to %<sizeof%> in %qD call is the same "
2280 "expression as the second source; did you mean to "
2281 "dereference it?", callee
);
2285 if (POINTER_TYPE_P (TREE_TYPE (src
))
2287 && comp_types (TREE_TYPE (src
), type
)
2288 && !VOID_TYPE_P (TREE_TYPE (type
)))
2290 warning_at (loc
, OPT_Wsizeof_pointer_memaccess
,
2291 "argument to %<sizeof%> in %qD call is the same "
2292 "pointer type %qT as the second source; expected %qT "
2293 "or an explicit length", callee
, TREE_TYPE (src
),
2294 TREE_TYPE (TREE_TYPE (src
)));
2301 /* Warn for unlikely, improbable, or stupid DECL declarations
2305 check_main_parameter_types (tree decl
)
2307 function_args_iterator iter
;
2311 FOREACH_FUNCTION_ARGS (TREE_TYPE (decl
), type
, iter
)
2313 /* XXX void_type_node belies the abstraction. */
2314 if (type
== void_type_node
|| type
== error_mark_node
)
2318 if (TYPE_ATOMIC (t
))
2319 pedwarn (input_location
, OPT_Wmain
,
2320 "%<_Atomic%>-qualified parameter type %qT of %q+D",
2322 while (POINTER_TYPE_P (t
))
2325 if (TYPE_ATOMIC (t
))
2326 pedwarn (input_location
, OPT_Wmain
,
2327 "%<_Atomic%>-qualified parameter type %qT of %q+D",
2335 if (TYPE_MAIN_VARIANT (type
) != integer_type_node
)
2336 pedwarn (input_location
, OPT_Wmain
,
2337 "first argument of %q+D should be %<int%>", decl
);
2341 if (TREE_CODE (type
) != POINTER_TYPE
2342 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
2343 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
2345 pedwarn (input_location
, OPT_Wmain
,
2346 "second argument of %q+D should be %<char **%>", decl
);
2350 if (TREE_CODE (type
) != POINTER_TYPE
2351 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
2352 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
2354 pedwarn (input_location
, OPT_Wmain
,
2355 "third argument of %q+D should probably be "
2356 "%<char **%>", decl
);
2361 /* It is intentional that this message does not mention the third
2362 argument because it's only mentioned in an appendix of the
2364 if (argct
> 0 && (argct
< 2 || argct
> 3))
2365 pedwarn (input_location
, OPT_Wmain
,
2366 "%q+D takes only zero or two arguments", decl
);
2368 if (stdarg_p (TREE_TYPE (decl
)))
2369 pedwarn (input_location
, OPT_Wmain
,
2370 "%q+D declared as variadic function", decl
);
2373 /* vector_targets_convertible_p is used for vector pointer types. The
2374 callers perform various checks that the qualifiers are satisfactory,
2375 while OTOH vector_targets_convertible_p ignores the number of elements
2376 in the vectors. That's fine with vector pointers as we can consider,
2377 say, a vector of 8 elements as two consecutive vectors of 4 elements,
2378 and that does not require and conversion of the pointer values.
2379 In contrast, vector_types_convertible_p and
2380 vector_types_compatible_elements_p are used for vector value types. */
2381 /* True if pointers to distinct types T1 and T2 can be converted to
2382 each other without an explicit cast. Only returns true for opaque
2385 vector_targets_convertible_p (const_tree t1
, const_tree t2
)
2387 if (TREE_CODE (t1
) == VECTOR_TYPE
&& TREE_CODE (t2
) == VECTOR_TYPE
2388 && (TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2389 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2395 /* vector_types_convertible_p is used for vector value types.
2396 It could in principle call vector_targets_convertible_p as a subroutine,
2397 but then the check for vector type would be duplicated with its callers,
2398 and also the purpose of vector_targets_convertible_p would become
2400 Where vector_types_convertible_p returns true, a conversion might still be
2401 needed to make the types match.
2402 In contrast, vector_targets_convertible_p is used for vector pointer
2403 values, and vector_types_compatible_elements_p is used specifically
2404 in the context for binary operators, as a check if use is possible without
2406 /* True if vector types T1 and T2 can be converted to each other
2407 without an explicit cast. If EMIT_LAX_NOTE is true, and T1 and T2
2408 can only be converted with -flax-vector-conversions yet that is not
2409 in effect, emit a note telling the user about that option if such
2410 a note has not previously been emitted. */
2412 vector_types_convertible_p (const_tree t1
, const_tree t2
, bool emit_lax_note
)
2414 static bool emitted_lax_note
= false;
2415 bool convertible_lax
;
2417 if ((TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2418 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2422 (tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
))
2423 && (TREE_CODE (TREE_TYPE (t1
)) != REAL_TYPE
||
2424 TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
))
2425 && (INTEGRAL_TYPE_P (TREE_TYPE (t1
))
2426 == INTEGRAL_TYPE_P (TREE_TYPE (t2
))));
2428 if (!convertible_lax
|| flag_lax_vector_conversions
)
2429 return convertible_lax
;
2431 if (TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
)
2432 && lang_hooks
.types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
2435 if (emit_lax_note
&& !emitted_lax_note
)
2437 emitted_lax_note
= true;
2438 inform (input_location
, "use -flax-vector-conversions to permit "
2439 "conversions between vectors with differing "
2440 "element types or numbers of subparts");
2446 /* Build a VEC_PERM_EXPR if V0, V1 and MASK are not error_mark_nodes
2447 and have vector types, V0 has the same type as V1, and the number of
2448 elements of V0, V1, MASK is the same.
2450 In case V1 is a NULL_TREE it is assumed that __builtin_shuffle was
2451 called with two arguments. In this case implementation passes the
2452 first argument twice in order to share the same tree code. This fact
2453 could enable the mask-values being twice the vector length. This is
2454 an implementation accident and this semantics is not guaranteed to
2457 c_build_vec_perm_expr (location_t loc
, tree v0
, tree v1
, tree mask
,
2462 bool maybe_const
= false;
2463 bool two_arguments
= false;
2465 if (v1
== NULL_TREE
)
2467 two_arguments
= true;
2471 if (v0
== error_mark_node
|| v1
== error_mark_node
2472 || mask
== error_mark_node
)
2473 return error_mark_node
;
2475 if (TREE_CODE (TREE_TYPE (mask
)) != VECTOR_TYPE
2476 || TREE_CODE (TREE_TYPE (TREE_TYPE (mask
))) != INTEGER_TYPE
)
2479 error_at (loc
, "__builtin_shuffle last argument must "
2480 "be an integer vector");
2481 return error_mark_node
;
2484 if (TREE_CODE (TREE_TYPE (v0
)) != VECTOR_TYPE
2485 || TREE_CODE (TREE_TYPE (v1
)) != VECTOR_TYPE
)
2488 error_at (loc
, "__builtin_shuffle arguments must be vectors");
2489 return error_mark_node
;
2492 if (TYPE_MAIN_VARIANT (TREE_TYPE (v0
)) != TYPE_MAIN_VARIANT (TREE_TYPE (v1
)))
2495 error_at (loc
, "__builtin_shuffle argument vectors must be of "
2497 return error_mark_node
;
2500 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (v0
))
2501 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
))
2502 && TYPE_VECTOR_SUBPARTS (TREE_TYPE (v1
))
2503 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
)))
2506 error_at (loc
, "__builtin_shuffle number of elements of the "
2507 "argument vector(s) and the mask vector should "
2509 return error_mark_node
;
2512 if (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (v0
))))
2513 != GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (mask
)))))
2516 error_at (loc
, "__builtin_shuffle argument vector(s) inner type "
2517 "must have the same size as inner type of the mask");
2518 return error_mark_node
;
2521 if (!c_dialect_cxx ())
2523 /* Avoid C_MAYBE_CONST_EXPRs inside VEC_PERM_EXPR. */
2524 v0
= c_fully_fold (v0
, false, &maybe_const
);
2525 wrap
&= maybe_const
;
2528 v1
= v0
= save_expr (v0
);
2531 v1
= c_fully_fold (v1
, false, &maybe_const
);
2532 wrap
&= maybe_const
;
2535 mask
= c_fully_fold (mask
, false, &maybe_const
);
2536 wrap
&= maybe_const
;
2538 else if (two_arguments
)
2539 v1
= v0
= save_expr (v0
);
2541 ret
= build3_loc (loc
, VEC_PERM_EXPR
, TREE_TYPE (v0
), v0
, v1
, mask
);
2543 if (!c_dialect_cxx () && !wrap
)
2544 ret
= c_wrap_maybe_const (ret
, true);
2549 /* Like tree.c:get_narrower, but retain conversion from C++0x scoped enum
2550 to integral type. */
2553 c_common_get_narrower (tree op
, int *unsignedp_ptr
)
2555 op
= get_narrower (op
, unsignedp_ptr
);
2557 if (TREE_CODE (TREE_TYPE (op
)) == ENUMERAL_TYPE
2558 && ENUM_IS_SCOPED (TREE_TYPE (op
)))
2560 /* C++0x scoped enumerations don't implicitly convert to integral
2561 type; if we stripped an explicit conversion to a larger type we
2562 need to replace it so common_type will still work. */
2563 tree type
= c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op
)),
2564 TYPE_UNSIGNED (TREE_TYPE (op
)));
2565 op
= fold_convert (type
, op
);
2570 /* This is a helper function of build_binary_op.
2572 For certain operations if both args were extended from the same
2573 smaller type, do the arithmetic in that type and then extend.
2575 BITWISE indicates a bitwise operation.
2576 For them, this optimization is safe only if
2577 both args are zero-extended or both are sign-extended.
2578 Otherwise, we might change the result.
2579 Eg, (short)-1 | (unsigned short)-1 is (int)-1
2580 but calculated in (unsigned short) it would be (unsigned short)-1.
2583 shorten_binary_op (tree result_type
, tree op0
, tree op1
, bool bitwise
)
2585 int unsigned0
, unsigned1
;
2590 /* Cast OP0 and OP1 to RESULT_TYPE. Doing so prevents
2591 excessive narrowing when we call get_narrower below. For
2592 example, suppose that OP0 is of unsigned int extended
2593 from signed char and that RESULT_TYPE is long long int.
2594 If we explicitly cast OP0 to RESULT_TYPE, OP0 would look
2597 (long long int) (unsigned int) signed_char
2599 which get_narrower would narrow down to
2601 (unsigned int) signed char
2603 If we do not cast OP0 first, get_narrower would return
2604 signed_char, which is inconsistent with the case of the
2606 op0
= convert (result_type
, op0
);
2607 op1
= convert (result_type
, op1
);
2609 arg0
= c_common_get_narrower (op0
, &unsigned0
);
2610 arg1
= c_common_get_narrower (op1
, &unsigned1
);
2612 /* UNS is 1 if the operation to be done is an unsigned one. */
2613 uns
= TYPE_UNSIGNED (result_type
);
2615 /* Handle the case that OP0 (or OP1) does not *contain* a conversion
2616 but it *requires* conversion to FINAL_TYPE. */
2618 if ((TYPE_PRECISION (TREE_TYPE (op0
))
2619 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2620 && TREE_TYPE (op0
) != result_type
)
2621 unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2622 if ((TYPE_PRECISION (TREE_TYPE (op1
))
2623 == TYPE_PRECISION (TREE_TYPE (arg1
)))
2624 && TREE_TYPE (op1
) != result_type
)
2625 unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2627 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
2629 /* For bitwise operations, signedness of nominal type
2630 does not matter. Consider only how operands were extended. */
2634 /* Note that in all three cases below we refrain from optimizing
2635 an unsigned operation on sign-extended args.
2636 That would not be valid. */
2638 /* Both args variable: if both extended in same way
2639 from same width, do it in that width.
2640 Do it unsigned if args were zero-extended. */
2641 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
2642 < TYPE_PRECISION (result_type
))
2643 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2644 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2645 && unsigned0
== unsigned1
2646 && (unsigned0
|| !uns
))
2647 return c_common_signed_or_unsigned_type
2648 (unsigned0
, common_type (TREE_TYPE (arg0
), TREE_TYPE (arg1
)));
2650 else if (TREE_CODE (arg0
) == INTEGER_CST
2651 && (unsigned1
|| !uns
)
2652 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2653 < TYPE_PRECISION (result_type
))
2655 = c_common_signed_or_unsigned_type (unsigned1
,
2657 && !POINTER_TYPE_P (type
)
2658 && int_fits_type_p (arg0
, type
))
2661 else if (TREE_CODE (arg1
) == INTEGER_CST
2662 && (unsigned0
|| !uns
)
2663 && (TYPE_PRECISION (TREE_TYPE (arg0
))
2664 < TYPE_PRECISION (result_type
))
2666 = c_common_signed_or_unsigned_type (unsigned0
,
2668 && !POINTER_TYPE_P (type
)
2669 && int_fits_type_p (arg1
, type
))
2675 /* Checks if expression EXPR of real/integer type cannot be converted
2676 to the real/integer type TYPE. Function returns non-zero when:
2677 * EXPR is a constant which cannot be exactly converted to TYPE.
2678 * EXPR is not a constant and size of EXPR's type > than size of TYPE,
2679 for EXPR type and TYPE being both integers or both real.
2680 * EXPR is not a constant of real type and TYPE is an integer.
2681 * EXPR is not a constant of integer type which cannot be
2682 exactly converted to real type.
2683 Function allows conversions between types of different signedness and
2684 can return SAFE_CONVERSION (zero) in that case. Function can produce
2685 signedness warnings if PRODUCE_WARNS is true. */
2687 enum conversion_safety
2688 unsafe_conversion_p (location_t loc
, tree type
, tree expr
, bool produce_warns
)
2690 enum conversion_safety give_warning
= SAFE_CONVERSION
; /* is 0 or false */
2691 tree expr_type
= TREE_TYPE (expr
);
2692 loc
= expansion_point_location_if_in_system_header (loc
);
2694 if (TREE_CODE (expr
) == REAL_CST
|| TREE_CODE (expr
) == INTEGER_CST
)
2696 /* Warn for real constant that is not an exact integer converted
2698 if (TREE_CODE (expr_type
) == REAL_TYPE
2699 && TREE_CODE (type
) == INTEGER_TYPE
)
2701 if (!real_isinteger (TREE_REAL_CST_PTR (expr
), TYPE_MODE (expr_type
)))
2702 give_warning
= UNSAFE_REAL
;
2704 /* Warn for an integer constant that does not fit into integer type. */
2705 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2706 && TREE_CODE (type
) == INTEGER_TYPE
2707 && !int_fits_type_p (expr
, type
))
2709 if (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)
2710 && tree_int_cst_sgn (expr
) < 0)
2713 warning_at (loc
, OPT_Wsign_conversion
, "negative integer"
2714 " implicitly converted to unsigned type");
2716 else if (!TYPE_UNSIGNED (type
) && TYPE_UNSIGNED (expr_type
))
2719 warning_at (loc
, OPT_Wsign_conversion
, "conversion of unsigned"
2720 " constant value to negative integer");
2723 give_warning
= UNSAFE_OTHER
;
2725 else if (TREE_CODE (type
) == REAL_TYPE
)
2727 /* Warn for an integer constant that does not fit into real type. */
2728 if (TREE_CODE (expr_type
) == INTEGER_TYPE
)
2730 REAL_VALUE_TYPE a
= real_value_from_int_cst (0, expr
);
2731 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2732 give_warning
= UNSAFE_REAL
;
2734 /* Warn for a real constant that does not fit into a smaller
2736 else if (TREE_CODE (expr_type
) == REAL_TYPE
2737 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2739 REAL_VALUE_TYPE a
= TREE_REAL_CST (expr
);
2740 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2741 give_warning
= UNSAFE_REAL
;
2747 /* Warn for real types converted to integer types. */
2748 if (TREE_CODE (expr_type
) == REAL_TYPE
2749 && TREE_CODE (type
) == INTEGER_TYPE
)
2750 give_warning
= UNSAFE_REAL
;
2752 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2753 && TREE_CODE (type
) == INTEGER_TYPE
)
2755 /* Don't warn about unsigned char y = 0xff, x = (int) y; */
2756 expr
= get_unwidened (expr
, 0);
2757 expr_type
= TREE_TYPE (expr
);
2759 /* Don't warn for short y; short x = ((int)y & 0xff); */
2760 if (TREE_CODE (expr
) == BIT_AND_EXPR
2761 || TREE_CODE (expr
) == BIT_IOR_EXPR
2762 || TREE_CODE (expr
) == BIT_XOR_EXPR
)
2764 /* If both args were extended from a shortest type,
2765 use that type if that is safe. */
2766 expr_type
= shorten_binary_op (expr_type
,
2767 TREE_OPERAND (expr
, 0),
2768 TREE_OPERAND (expr
, 1),
2771 if (TREE_CODE (expr
) == BIT_AND_EXPR
)
2773 tree op0
= TREE_OPERAND (expr
, 0);
2774 tree op1
= TREE_OPERAND (expr
, 1);
2775 bool unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2776 bool unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2778 /* If one of the operands is a non-negative constant
2779 that fits in the target type, then the type of the
2780 other operand does not matter. */
2781 if ((TREE_CODE (op0
) == INTEGER_CST
2782 && int_fits_type_p (op0
, c_common_signed_type (type
))
2783 && int_fits_type_p (op0
, c_common_unsigned_type (type
)))
2784 || (TREE_CODE (op1
) == INTEGER_CST
2785 && int_fits_type_p (op1
, c_common_signed_type (type
))
2786 && int_fits_type_p (op1
,
2787 c_common_unsigned_type (type
))))
2788 return SAFE_CONVERSION
;
2789 /* If constant is unsigned and fits in the target
2790 type, then the result will also fit. */
2791 else if ((TREE_CODE (op0
) == INTEGER_CST
2793 && int_fits_type_p (op0
, type
))
2794 || (TREE_CODE (op1
) == INTEGER_CST
2796 && int_fits_type_p (op1
, type
)))
2797 return SAFE_CONVERSION
;
2800 /* Warn for integer types converted to smaller integer types. */
2801 if (TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2802 give_warning
= UNSAFE_OTHER
;
2804 /* When they are the same width but different signedness,
2805 then the value may change. */
2806 else if (((TYPE_PRECISION (type
) == TYPE_PRECISION (expr_type
)
2807 && TYPE_UNSIGNED (expr_type
) != TYPE_UNSIGNED (type
))
2808 /* Even when converted to a bigger type, if the type is
2809 unsigned but expr is signed, then negative values
2811 || (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)))
2813 warning_at (loc
, OPT_Wsign_conversion
, "conversion to %qT from %qT "
2814 "may change the sign of the result",
2818 /* Warn for integer types converted to real types if and only if
2819 all the range of values of the integer type cannot be
2820 represented by the real type. */
2821 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2822 && TREE_CODE (type
) == REAL_TYPE
)
2824 tree type_low_bound
, type_high_bound
;
2825 REAL_VALUE_TYPE real_low_bound
, real_high_bound
;
2827 /* Don't warn about char y = 0xff; float x = (int) y; */
2828 expr
= get_unwidened (expr
, 0);
2829 expr_type
= TREE_TYPE (expr
);
2831 type_low_bound
= TYPE_MIN_VALUE (expr_type
);
2832 type_high_bound
= TYPE_MAX_VALUE (expr_type
);
2833 real_low_bound
= real_value_from_int_cst (0, type_low_bound
);
2834 real_high_bound
= real_value_from_int_cst (0, type_high_bound
);
2836 if (!exact_real_truncate (TYPE_MODE (type
), &real_low_bound
)
2837 || !exact_real_truncate (TYPE_MODE (type
), &real_high_bound
))
2838 give_warning
= UNSAFE_OTHER
;
2841 /* Warn for real types converted to smaller real types. */
2842 else if (TREE_CODE (expr_type
) == REAL_TYPE
2843 && TREE_CODE (type
) == REAL_TYPE
2844 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2845 give_warning
= UNSAFE_REAL
;
2848 return give_warning
;
2851 /* Warns if the conversion of EXPR to TYPE may alter a value.
2852 This is a helper function for warnings_for_convert_and_check. */
2855 conversion_warning (location_t loc
, tree type
, tree expr
)
2857 tree expr_type
= TREE_TYPE (expr
);
2858 enum conversion_safety conversion_kind
;
2860 if (!warn_conversion
&& !warn_sign_conversion
&& !warn_float_conversion
)
2863 /* This may happen, because for LHS op= RHS we preevaluate
2864 RHS and create C_MAYBE_CONST_EXPR <SAVE_EXPR <RHS>>, which
2865 means we could no longer see the code of the EXPR. */
2866 if (TREE_CODE (expr
) == C_MAYBE_CONST_EXPR
)
2867 expr
= C_MAYBE_CONST_EXPR_EXPR (expr
);
2868 if (TREE_CODE (expr
) == SAVE_EXPR
)
2869 expr
= TREE_OPERAND (expr
, 0);
2871 switch (TREE_CODE (expr
))
2879 case TRUTH_ANDIF_EXPR
:
2880 case TRUTH_ORIF_EXPR
:
2881 case TRUTH_AND_EXPR
:
2883 case TRUTH_XOR_EXPR
:
2884 case TRUTH_NOT_EXPR
:
2885 /* Conversion from boolean to a signed:1 bit-field (which only
2886 can hold the values 0 and -1) doesn't lose information - but
2887 it does change the value. */
2888 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
2889 warning_at (loc
, OPT_Wconversion
,
2890 "conversion to %qT from boolean expression", type
);
2895 conversion_kind
= unsafe_conversion_p (loc
, type
, expr
, true);
2896 if (conversion_kind
== UNSAFE_REAL
)
2897 warning_at (loc
, OPT_Wfloat_conversion
,
2898 "conversion to %qT alters %qT constant value",
2900 else if (conversion_kind
)
2901 warning_at (loc
, OPT_Wconversion
,
2902 "conversion to %qT alters %qT constant value",
2908 /* In case of COND_EXPR, we do not care about the type of
2909 COND_EXPR, only about the conversion of each operand. */
2910 tree op1
= TREE_OPERAND (expr
, 1);
2911 tree op2
= TREE_OPERAND (expr
, 2);
2913 conversion_warning (loc
, type
, op1
);
2914 conversion_warning (loc
, type
, op2
);
2918 default: /* 'expr' is not a constant. */
2919 conversion_kind
= unsafe_conversion_p (loc
, type
, expr
, true);
2920 if (conversion_kind
== UNSAFE_REAL
)
2921 warning_at (loc
, OPT_Wfloat_conversion
,
2922 "conversion to %qT from %qT may alter its value",
2924 else if (conversion_kind
)
2925 warning_at (loc
, OPT_Wconversion
,
2926 "conversion to %qT from %qT may alter its value",
2931 /* Produce warnings after a conversion. RESULT is the result of
2932 converting EXPR to TYPE. This is a helper function for
2933 convert_and_check and cp_convert_and_check. */
2936 warnings_for_convert_and_check (location_t loc
, tree type
, tree expr
,
2939 loc
= expansion_point_location_if_in_system_header (loc
);
2941 if (TREE_CODE (expr
) == INTEGER_CST
2942 && (TREE_CODE (type
) == INTEGER_TYPE
2943 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2944 && !int_fits_type_p (expr
, type
))
2946 /* Do not diagnose overflow in a constant expression merely
2947 because a conversion overflowed. */
2948 if (TREE_OVERFLOW (result
))
2949 TREE_OVERFLOW (result
) = TREE_OVERFLOW (expr
);
2951 if (TYPE_UNSIGNED (type
))
2953 /* This detects cases like converting -129 or 256 to
2955 if (!int_fits_type_p (expr
, c_common_signed_type (type
)))
2956 warning_at (loc
, OPT_Woverflow
,
2957 "large integer implicitly truncated to unsigned type");
2959 conversion_warning (loc
, type
, expr
);
2961 else if (!int_fits_type_p (expr
, c_common_unsigned_type (type
)))
2962 warning_at (loc
, OPT_Woverflow
,
2963 "overflow in implicit constant conversion");
2964 /* No warning for converting 0x80000000 to int. */
2966 && (TREE_CODE (TREE_TYPE (expr
)) != INTEGER_TYPE
2967 || TYPE_PRECISION (TREE_TYPE (expr
))
2968 != TYPE_PRECISION (type
)))
2969 warning_at (loc
, OPT_Woverflow
,
2970 "overflow in implicit constant conversion");
2973 conversion_warning (loc
, type
, expr
);
2975 else if ((TREE_CODE (result
) == INTEGER_CST
2976 || TREE_CODE (result
) == FIXED_CST
) && TREE_OVERFLOW (result
))
2977 warning_at (loc
, OPT_Woverflow
,
2978 "overflow in implicit constant conversion");
2980 conversion_warning (loc
, type
, expr
);
2984 /* Convert EXPR to TYPE, warning about conversion problems with constants.
2985 Invoke this function on every expression that is converted implicitly,
2986 i.e. because of language rules and not because of an explicit cast. */
2989 convert_and_check (location_t loc
, tree type
, tree expr
)
2992 tree expr_for_warning
;
2994 /* Convert from a value with possible excess precision rather than
2995 via the semantic type, but do not warn about values not fitting
2996 exactly in the semantic type. */
2997 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
2999 tree orig_type
= TREE_TYPE (expr
);
3000 expr
= TREE_OPERAND (expr
, 0);
3001 expr_for_warning
= convert (orig_type
, expr
);
3002 if (orig_type
== type
)
3003 return expr_for_warning
;
3006 expr_for_warning
= expr
;
3008 if (TREE_TYPE (expr
) == type
)
3011 result
= convert (type
, expr
);
3013 if (c_inhibit_evaluation_warnings
== 0
3014 && !TREE_OVERFLOW_P (expr
)
3015 && result
!= error_mark_node
)
3016 warnings_for_convert_and_check (loc
, type
, expr_for_warning
, result
);
3021 /* A node in a list that describes references to variables (EXPR), which are
3022 either read accesses if WRITER is zero, or write accesses, in which case
3023 WRITER is the parent of EXPR. */
3030 /* Used to implement a cache the results of a call to verify_tree. We only
3031 use this for SAVE_EXPRs. */
3034 struct tlist_cache
*next
;
3035 struct tlist
*cache_before_sp
;
3036 struct tlist
*cache_after_sp
;
3040 /* Obstack to use when allocating tlist structures, and corresponding
3042 static struct obstack tlist_obstack
;
3043 static char *tlist_firstobj
= 0;
3045 /* Keep track of the identifiers we've warned about, so we can avoid duplicate
3047 static struct tlist
*warned_ids
;
3048 /* SAVE_EXPRs need special treatment. We process them only once and then
3049 cache the results. */
3050 static struct tlist_cache
*save_expr_cache
;
3052 static void add_tlist (struct tlist
**, struct tlist
*, tree
, int);
3053 static void merge_tlist (struct tlist
**, struct tlist
*, int);
3054 static void verify_tree (tree
, struct tlist
**, struct tlist
**, tree
);
3055 static int warning_candidate_p (tree
);
3056 static bool candidate_equal_p (const_tree
, const_tree
);
3057 static void warn_for_collisions (struct tlist
*);
3058 static void warn_for_collisions_1 (tree
, tree
, struct tlist
*, int);
3059 static struct tlist
*new_tlist (struct tlist
*, tree
, tree
);
3061 /* Create a new struct tlist and fill in its fields. */
3062 static struct tlist
*
3063 new_tlist (struct tlist
*next
, tree t
, tree writer
)
3066 l
= XOBNEW (&tlist_obstack
, struct tlist
);
3073 /* Add duplicates of the nodes found in ADD to the list *TO. If EXCLUDE_WRITER
3074 is nonnull, we ignore any node we find which has a writer equal to it. */
3077 add_tlist (struct tlist
**to
, struct tlist
*add
, tree exclude_writer
, int copy
)
3081 struct tlist
*next
= add
->next
;
3084 if (!exclude_writer
|| !candidate_equal_p (add
->writer
, exclude_writer
))
3085 *to
= copy
? new_tlist (*to
, add
->expr
, add
->writer
) : add
;
3090 /* Merge the nodes of ADD into TO. This merging process is done so that for
3091 each variable that already exists in TO, no new node is added; however if
3092 there is a write access recorded in ADD, and an occurrence on TO is only
3093 a read access, then the occurrence in TO will be modified to record the
3097 merge_tlist (struct tlist
**to
, struct tlist
*add
, int copy
)
3099 struct tlist
**end
= to
;
3102 end
= &(*end
)->next
;
3108 struct tlist
*next
= add
->next
;
3110 for (tmp2
= *to
; tmp2
; tmp2
= tmp2
->next
)
3111 if (candidate_equal_p (tmp2
->expr
, add
->expr
))
3115 tmp2
->writer
= add
->writer
;
3119 *end
= copy
? new_tlist (NULL
, add
->expr
, add
->writer
) : add
;
3120 end
= &(*end
)->next
;
3127 /* WRITTEN is a variable, WRITER is its parent. Warn if any of the variable
3128 references in list LIST conflict with it, excluding reads if ONLY writers
3132 warn_for_collisions_1 (tree written
, tree writer
, struct tlist
*list
,
3137 /* Avoid duplicate warnings. */
3138 for (tmp
= warned_ids
; tmp
; tmp
= tmp
->next
)
3139 if (candidate_equal_p (tmp
->expr
, written
))
3144 if (candidate_equal_p (list
->expr
, written
)
3145 && !candidate_equal_p (list
->writer
, writer
)
3146 && (!only_writes
|| list
->writer
))
3148 warned_ids
= new_tlist (warned_ids
, written
, NULL_TREE
);
3149 warning_at (EXPR_LOC_OR_LOC (writer
, input_location
),
3150 OPT_Wsequence_point
, "operation on %qE may be undefined",
3157 /* Given a list LIST of references to variables, find whether any of these
3158 can cause conflicts due to missing sequence points. */
3161 warn_for_collisions (struct tlist
*list
)
3165 for (tmp
= list
; tmp
; tmp
= tmp
->next
)
3168 warn_for_collisions_1 (tmp
->expr
, tmp
->writer
, list
, 0);
3172 /* Return nonzero if X is a tree that can be verified by the sequence point
3175 warning_candidate_p (tree x
)
3177 if (DECL_P (x
) && DECL_ARTIFICIAL (x
))
3180 if (TREE_CODE (x
) == BLOCK
)
3183 /* VOID_TYPE_P (TREE_TYPE (x)) is workaround for cp/tree.c
3184 (lvalue_p) crash on TRY/CATCH. */
3185 if (TREE_TYPE (x
) == NULL_TREE
|| VOID_TYPE_P (TREE_TYPE (x
)))
3191 /* No point to track non-const calls, they will never satisfy
3193 if (TREE_CODE (x
) == CALL_EXPR
&& (call_expr_flags (x
) & ECF_CONST
) == 0)
3196 if (TREE_CODE (x
) == STRING_CST
)
3202 /* Return nonzero if X and Y appear to be the same candidate (or NULL) */
3204 candidate_equal_p (const_tree x
, const_tree y
)
3206 return (x
== y
) || (x
&& y
&& operand_equal_p (x
, y
, 0));
3209 /* Walk the tree X, and record accesses to variables. If X is written by the
3210 parent tree, WRITER is the parent.
3211 We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP. If this
3212 expression or its only operand forces a sequence point, then everything up
3213 to the sequence point is stored in PBEFORE_SP. Everything else gets stored
3215 Once we return, we will have emitted warnings if any subexpression before
3216 such a sequence point could be undefined. On a higher level, however, the
3217 sequence point may not be relevant, and we'll merge the two lists.
3219 Example: (b++, a) + b;
3220 The call that processes the COMPOUND_EXPR will store the increment of B
3221 in PBEFORE_SP, and the use of A in PNO_SP. The higher-level call that
3222 processes the PLUS_EXPR will need to merge the two lists so that
3223 eventually, all accesses end up on the same list (and we'll warn about the
3224 unordered subexpressions b++ and b.
3226 A note on merging. If we modify the former example so that our expression
3229 care must be taken not simply to add all three expressions into the final
3230 PNO_SP list. The function merge_tlist takes care of that by merging the
3231 before-SP list of the COMPOUND_EXPR into its after-SP list in a special
3232 way, so that no more than one access to B is recorded. */
3235 verify_tree (tree x
, struct tlist
**pbefore_sp
, struct tlist
**pno_sp
,
3238 struct tlist
*tmp_before
, *tmp_nosp
, *tmp_list2
, *tmp_list3
;
3239 enum tree_code code
;
3240 enum tree_code_class cl
;
3242 /* X may be NULL if it is the operand of an empty statement expression
3248 code
= TREE_CODE (x
);
3249 cl
= TREE_CODE_CLASS (code
);
3251 if (warning_candidate_p (x
))
3252 *pno_sp
= new_tlist (*pno_sp
, x
, writer
);
3261 case TRUTH_ANDIF_EXPR
:
3262 case TRUTH_ORIF_EXPR
:
3263 tmp_before
= tmp_nosp
= tmp_list3
= 0;
3264 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3265 warn_for_collisions (tmp_nosp
);
3266 merge_tlist (pbefore_sp
, tmp_before
, 0);
3267 merge_tlist (pbefore_sp
, tmp_nosp
, 0);
3268 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, pno_sp
, NULL_TREE
);
3269 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3273 tmp_before
= tmp_list2
= 0;
3274 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_list2
, NULL_TREE
);
3275 warn_for_collisions (tmp_list2
);
3276 merge_tlist (pbefore_sp
, tmp_before
, 0);
3277 merge_tlist (pbefore_sp
, tmp_list2
, 0);
3279 tmp_list3
= tmp_nosp
= 0;
3280 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, &tmp_nosp
, NULL_TREE
);
3281 warn_for_collisions (tmp_nosp
);
3282 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3284 tmp_list3
= tmp_list2
= 0;
3285 verify_tree (TREE_OPERAND (x
, 2), &tmp_list3
, &tmp_list2
, NULL_TREE
);
3286 warn_for_collisions (tmp_list2
);
3287 merge_tlist (pbefore_sp
, tmp_list3
, 0);
3288 /* Rather than add both tmp_nosp and tmp_list2, we have to merge the
3289 two first, to avoid warning for (a ? b++ : b++). */
3290 merge_tlist (&tmp_nosp
, tmp_list2
, 0);
3291 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3294 case PREDECREMENT_EXPR
:
3295 case PREINCREMENT_EXPR
:
3296 case POSTDECREMENT_EXPR
:
3297 case POSTINCREMENT_EXPR
:
3298 verify_tree (TREE_OPERAND (x
, 0), pno_sp
, pno_sp
, x
);
3302 tmp_before
= tmp_nosp
= tmp_list3
= 0;
3303 verify_tree (TREE_OPERAND (x
, 1), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3304 verify_tree (TREE_OPERAND (x
, 0), &tmp_list3
, &tmp_list3
, x
);
3305 /* Expressions inside the LHS are not ordered wrt. the sequence points
3306 in the RHS. Example:
3308 Despite the fact that the modification of "a" is in the before_sp
3309 list (tmp_before), it conflicts with the use of "a" in the LHS.
3310 We can handle this by adding the contents of tmp_list3
3311 to those of tmp_before, and redoing the collision warnings for that
3313 add_tlist (&tmp_before
, tmp_list3
, x
, 1);
3314 warn_for_collisions (tmp_before
);
3315 /* Exclude the LHS itself here; we first have to merge it into the
3316 tmp_nosp list. This is done to avoid warning for "a = a"; if we
3317 didn't exclude the LHS, we'd get it twice, once as a read and once
3319 add_tlist (pno_sp
, tmp_list3
, x
, 0);
3320 warn_for_collisions_1 (TREE_OPERAND (x
, 0), x
, tmp_nosp
, 1);
3322 merge_tlist (pbefore_sp
, tmp_before
, 0);
3323 if (warning_candidate_p (TREE_OPERAND (x
, 0)))
3324 merge_tlist (&tmp_nosp
, new_tlist (NULL
, TREE_OPERAND (x
, 0), x
), 0);
3325 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 1);
3329 /* We need to warn about conflicts among arguments and conflicts between
3330 args and the function address. Side effects of the function address,
3331 however, are not ordered by the sequence point of the call. */
3333 call_expr_arg_iterator iter
;
3335 tmp_before
= tmp_nosp
= 0;
3336 verify_tree (CALL_EXPR_FN (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3337 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, x
)
3339 tmp_list2
= tmp_list3
= 0;
3340 verify_tree (arg
, &tmp_list2
, &tmp_list3
, NULL_TREE
);
3341 merge_tlist (&tmp_list3
, tmp_list2
, 0);
3342 add_tlist (&tmp_before
, tmp_list3
, NULL_TREE
, 0);
3344 add_tlist (&tmp_before
, tmp_nosp
, NULL_TREE
, 0);
3345 warn_for_collisions (tmp_before
);
3346 add_tlist (pbefore_sp
, tmp_before
, NULL_TREE
, 0);
3351 /* Scan all the list, e.g. indices of multi dimensional array. */
3354 tmp_before
= tmp_nosp
= 0;
3355 verify_tree (TREE_VALUE (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3356 merge_tlist (&tmp_nosp
, tmp_before
, 0);
3357 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3364 struct tlist_cache
*t
;
3365 for (t
= save_expr_cache
; t
; t
= t
->next
)
3366 if (candidate_equal_p (t
->expr
, x
))
3371 t
= XOBNEW (&tlist_obstack
, struct tlist_cache
);
3372 t
->next
= save_expr_cache
;
3374 save_expr_cache
= t
;
3376 tmp_before
= tmp_nosp
= 0;
3377 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
3378 warn_for_collisions (tmp_nosp
);
3381 merge_tlist (&tmp_list3
, tmp_nosp
, 0);
3382 t
->cache_before_sp
= tmp_before
;
3383 t
->cache_after_sp
= tmp_list3
;
3385 merge_tlist (pbefore_sp
, t
->cache_before_sp
, 1);
3386 add_tlist (pno_sp
, t
->cache_after_sp
, NULL_TREE
, 1);
3391 x
= TREE_OPERAND (x
, 0);
3398 /* For other expressions, simply recurse on their operands.
3399 Manual tail recursion for unary expressions.
3400 Other non-expressions need not be processed. */
3401 if (cl
== tcc_unary
)
3403 x
= TREE_OPERAND (x
, 0);
3407 else if (IS_EXPR_CODE_CLASS (cl
))
3410 int max
= TREE_OPERAND_LENGTH (x
);
3411 for (lp
= 0; lp
< max
; lp
++)
3413 tmp_before
= tmp_nosp
= 0;
3414 verify_tree (TREE_OPERAND (x
, lp
), &tmp_before
, &tmp_nosp
, 0);
3415 merge_tlist (&tmp_nosp
, tmp_before
, 0);
3416 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
3423 /* Try to warn for undefined behavior in EXPR due to missing sequence
3427 verify_sequence_points (tree expr
)
3429 struct tlist
*before_sp
= 0, *after_sp
= 0;
3432 save_expr_cache
= 0;
3433 if (tlist_firstobj
== 0)
3435 gcc_obstack_init (&tlist_obstack
);
3436 tlist_firstobj
= (char *) obstack_alloc (&tlist_obstack
, 0);
3439 verify_tree (expr
, &before_sp
, &after_sp
, 0);
3440 warn_for_collisions (after_sp
);
3441 obstack_free (&tlist_obstack
, tlist_firstobj
);
3444 /* Validate the expression after `case' and apply default promotions. */
3447 check_case_value (location_t loc
, tree value
)
3449 if (value
== NULL_TREE
)
3452 if (TREE_CODE (value
) == INTEGER_CST
)
3453 /* Promote char or short to int. */
3454 value
= perform_integral_promotions (value
);
3455 else if (value
!= error_mark_node
)
3457 error_at (loc
, "case label does not reduce to an integer constant");
3458 value
= error_mark_node
;
3461 constant_expression_warning (value
);
3466 /* See if the case values LOW and HIGH are in the range of the original
3467 type (i.e. before the default conversion to int) of the switch testing
3469 TYPE is the promoted type of the testing expression, and ORIG_TYPE is
3470 the type before promoting it. CASE_LOW_P is a pointer to the lower
3471 bound of the case label, and CASE_HIGH_P is the upper bound or NULL
3472 if the case is not a case range.
3473 The caller has to make sure that we are not called with NULL for
3474 CASE_LOW_P (i.e. the default case).
3475 Returns true if the case label is in range of ORIG_TYPE (saturated or
3476 untouched) or false if the label is out of range. */
3479 check_case_bounds (location_t loc
, tree type
, tree orig_type
,
3480 tree
*case_low_p
, tree
*case_high_p
)
3482 tree min_value
, max_value
;
3483 tree case_low
= *case_low_p
;
3484 tree case_high
= case_high_p
? *case_high_p
: case_low
;
3486 /* If there was a problem with the original type, do nothing. */
3487 if (orig_type
== error_mark_node
)
3490 min_value
= TYPE_MIN_VALUE (orig_type
);
3491 max_value
= TYPE_MAX_VALUE (orig_type
);
3493 /* Case label is less than minimum for type. */
3494 if (tree_int_cst_compare (case_low
, min_value
) < 0
3495 && tree_int_cst_compare (case_high
, min_value
) < 0)
3497 warning_at (loc
, 0, "case label value is less than minimum value "
3502 /* Case value is greater than maximum for type. */
3503 if (tree_int_cst_compare (case_low
, max_value
) > 0
3504 && tree_int_cst_compare (case_high
, max_value
) > 0)
3506 warning_at (loc
, 0, "case label value exceeds maximum value for type");
3510 /* Saturate lower case label value to minimum. */
3511 if (tree_int_cst_compare (case_high
, min_value
) >= 0
3512 && tree_int_cst_compare (case_low
, min_value
) < 0)
3514 warning_at (loc
, 0, "lower value in case label range"
3515 " less than minimum value for type");
3516 case_low
= min_value
;
3519 /* Saturate upper case label value to maximum. */
3520 if (tree_int_cst_compare (case_low
, max_value
) <= 0
3521 && tree_int_cst_compare (case_high
, max_value
) > 0)
3523 warning_at (loc
, 0, "upper value in case label range"
3524 " exceeds maximum value for type");
3525 case_high
= max_value
;
3528 if (*case_low_p
!= case_low
)
3529 *case_low_p
= convert (type
, case_low
);
3530 if (case_high_p
&& *case_high_p
!= case_high
)
3531 *case_high_p
= convert (type
, case_high
);
3536 /* Return an integer type with BITS bits of precision,
3537 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
3540 c_common_type_for_size (unsigned int bits
, int unsignedp
)
3544 if (bits
== TYPE_PRECISION (integer_type_node
))
3545 return unsignedp
? unsigned_type_node
: integer_type_node
;
3547 if (bits
== TYPE_PRECISION (signed_char_type_node
))
3548 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3550 if (bits
== TYPE_PRECISION (short_integer_type_node
))
3551 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3553 if (bits
== TYPE_PRECISION (long_integer_type_node
))
3554 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3556 if (bits
== TYPE_PRECISION (long_long_integer_type_node
))
3557 return (unsignedp
? long_long_unsigned_type_node
3558 : long_long_integer_type_node
);
3560 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
3561 if (int_n_enabled_p
[i
]
3562 && bits
== int_n_data
[i
].bitsize
)
3563 return (unsignedp
? int_n_trees
[i
].unsigned_type
3564 : int_n_trees
[i
].signed_type
);
3566 if (bits
== TYPE_PRECISION (widest_integer_literal_type_node
))
3567 return (unsignedp
? widest_unsigned_literal_type_node
3568 : widest_integer_literal_type_node
);
3570 if (bits
<= TYPE_PRECISION (intQI_type_node
))
3571 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3573 if (bits
<= TYPE_PRECISION (intHI_type_node
))
3574 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3576 if (bits
<= TYPE_PRECISION (intSI_type_node
))
3577 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3579 if (bits
<= TYPE_PRECISION (intDI_type_node
))
3580 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3585 /* Return a fixed-point type that has at least IBIT ibits and FBIT fbits
3586 that is unsigned if UNSIGNEDP is nonzero, otherwise signed;
3587 and saturating if SATP is nonzero, otherwise not saturating. */
3590 c_common_fixed_point_type_for_size (unsigned int ibit
, unsigned int fbit
,
3591 int unsignedp
, int satp
)
3595 mode
= unsignedp
? UQQmode
: QQmode
;
3597 mode
= unsignedp
? UHAmode
: HAmode
;
3599 for (; mode
!= VOIDmode
; mode
= GET_MODE_WIDER_MODE (mode
))
3600 if (GET_MODE_IBIT (mode
) >= ibit
&& GET_MODE_FBIT (mode
) >= fbit
)
3603 if (mode
== VOIDmode
|| !targetm
.scalar_mode_supported_p (mode
))
3605 sorry ("GCC cannot support operators with integer types and "
3606 "fixed-point types that have too many integral and "
3607 "fractional bits together");
3611 return c_common_type_for_mode (mode
, satp
);
3614 /* Used for communication between c_common_type_for_mode and
3615 c_register_builtin_type. */
3616 tree registered_builtin_types
;
3618 /* Return a data type that has machine mode MODE.
3619 If the mode is an integer,
3620 then UNSIGNEDP selects between signed and unsigned types.
3621 If the mode is a fixed-point mode,
3622 then UNSIGNEDP selects between saturating and nonsaturating types. */
3625 c_common_type_for_mode (machine_mode mode
, int unsignedp
)
3630 if (mode
== TYPE_MODE (integer_type_node
))
3631 return unsignedp
? unsigned_type_node
: integer_type_node
;
3633 if (mode
== TYPE_MODE (signed_char_type_node
))
3634 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3636 if (mode
== TYPE_MODE (short_integer_type_node
))
3637 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3639 if (mode
== TYPE_MODE (long_integer_type_node
))
3640 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3642 if (mode
== TYPE_MODE (long_long_integer_type_node
))
3643 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3645 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
3646 if (int_n_enabled_p
[i
]
3647 && mode
== int_n_data
[i
].m
)
3648 return (unsignedp
? int_n_trees
[i
].unsigned_type
3649 : int_n_trees
[i
].signed_type
);
3651 if (mode
== TYPE_MODE (widest_integer_literal_type_node
))
3652 return unsignedp
? widest_unsigned_literal_type_node
3653 : widest_integer_literal_type_node
;
3656 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3659 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3662 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3665 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3667 #if HOST_BITS_PER_WIDE_INT >= 64
3668 if (mode
== TYPE_MODE (intTI_type_node
))
3669 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3672 if (mode
== TYPE_MODE (float_type_node
))
3673 return float_type_node
;
3675 if (mode
== TYPE_MODE (double_type_node
))
3676 return double_type_node
;
3678 if (mode
== TYPE_MODE (long_double_type_node
))
3679 return long_double_type_node
;
3681 if (mode
== TYPE_MODE (void_type_node
))
3682 return void_type_node
;
3684 if (mode
== TYPE_MODE (build_pointer_type (char_type_node
)))
3686 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3687 : make_signed_type (GET_MODE_PRECISION (mode
)));
3689 if (mode
== TYPE_MODE (build_pointer_type (integer_type_node
)))
3691 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3692 : make_signed_type (GET_MODE_PRECISION (mode
)));
3694 if (COMPLEX_MODE_P (mode
))
3696 machine_mode inner_mode
;
3699 if (mode
== TYPE_MODE (complex_float_type_node
))
3700 return complex_float_type_node
;
3701 if (mode
== TYPE_MODE (complex_double_type_node
))
3702 return complex_double_type_node
;
3703 if (mode
== TYPE_MODE (complex_long_double_type_node
))
3704 return complex_long_double_type_node
;
3706 if (mode
== TYPE_MODE (complex_integer_type_node
) && !unsignedp
)
3707 return complex_integer_type_node
;
3709 inner_mode
= GET_MODE_INNER (mode
);
3710 inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3711 if (inner_type
!= NULL_TREE
)
3712 return build_complex_type (inner_type
);
3714 else if (VECTOR_MODE_P (mode
))
3716 machine_mode inner_mode
= GET_MODE_INNER (mode
);
3717 tree inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3718 if (inner_type
!= NULL_TREE
)
3719 return build_vector_type_for_mode (inner_type
, mode
);
3722 if (mode
== TYPE_MODE (dfloat32_type_node
))
3723 return dfloat32_type_node
;
3724 if (mode
== TYPE_MODE (dfloat64_type_node
))
3725 return dfloat64_type_node
;
3726 if (mode
== TYPE_MODE (dfloat128_type_node
))
3727 return dfloat128_type_node
;
3729 if (ALL_SCALAR_FIXED_POINT_MODE_P (mode
))
3731 if (mode
== TYPE_MODE (short_fract_type_node
))
3732 return unsignedp
? sat_short_fract_type_node
: short_fract_type_node
;
3733 if (mode
== TYPE_MODE (fract_type_node
))
3734 return unsignedp
? sat_fract_type_node
: fract_type_node
;
3735 if (mode
== TYPE_MODE (long_fract_type_node
))
3736 return unsignedp
? sat_long_fract_type_node
: long_fract_type_node
;
3737 if (mode
== TYPE_MODE (long_long_fract_type_node
))
3738 return unsignedp
? sat_long_long_fract_type_node
3739 : long_long_fract_type_node
;
3741 if (mode
== TYPE_MODE (unsigned_short_fract_type_node
))
3742 return unsignedp
? sat_unsigned_short_fract_type_node
3743 : unsigned_short_fract_type_node
;
3744 if (mode
== TYPE_MODE (unsigned_fract_type_node
))
3745 return unsignedp
? sat_unsigned_fract_type_node
3746 : unsigned_fract_type_node
;
3747 if (mode
== TYPE_MODE (unsigned_long_fract_type_node
))
3748 return unsignedp
? sat_unsigned_long_fract_type_node
3749 : unsigned_long_fract_type_node
;
3750 if (mode
== TYPE_MODE (unsigned_long_long_fract_type_node
))
3751 return unsignedp
? sat_unsigned_long_long_fract_type_node
3752 : unsigned_long_long_fract_type_node
;
3754 if (mode
== TYPE_MODE (short_accum_type_node
))
3755 return unsignedp
? sat_short_accum_type_node
: short_accum_type_node
;
3756 if (mode
== TYPE_MODE (accum_type_node
))
3757 return unsignedp
? sat_accum_type_node
: accum_type_node
;
3758 if (mode
== TYPE_MODE (long_accum_type_node
))
3759 return unsignedp
? sat_long_accum_type_node
: long_accum_type_node
;
3760 if (mode
== TYPE_MODE (long_long_accum_type_node
))
3761 return unsignedp
? sat_long_long_accum_type_node
3762 : long_long_accum_type_node
;
3764 if (mode
== TYPE_MODE (unsigned_short_accum_type_node
))
3765 return unsignedp
? sat_unsigned_short_accum_type_node
3766 : unsigned_short_accum_type_node
;
3767 if (mode
== TYPE_MODE (unsigned_accum_type_node
))
3768 return unsignedp
? sat_unsigned_accum_type_node
3769 : unsigned_accum_type_node
;
3770 if (mode
== TYPE_MODE (unsigned_long_accum_type_node
))
3771 return unsignedp
? sat_unsigned_long_accum_type_node
3772 : unsigned_long_accum_type_node
;
3773 if (mode
== TYPE_MODE (unsigned_long_long_accum_type_node
))
3774 return unsignedp
? sat_unsigned_long_long_accum_type_node
3775 : unsigned_long_long_accum_type_node
;
3778 return unsignedp
? sat_qq_type_node
: qq_type_node
;
3780 return unsignedp
? sat_hq_type_node
: hq_type_node
;
3782 return unsignedp
? sat_sq_type_node
: sq_type_node
;
3784 return unsignedp
? sat_dq_type_node
: dq_type_node
;
3786 return unsignedp
? sat_tq_type_node
: tq_type_node
;
3788 if (mode
== UQQmode
)
3789 return unsignedp
? sat_uqq_type_node
: uqq_type_node
;
3790 if (mode
== UHQmode
)
3791 return unsignedp
? sat_uhq_type_node
: uhq_type_node
;
3792 if (mode
== USQmode
)
3793 return unsignedp
? sat_usq_type_node
: usq_type_node
;
3794 if (mode
== UDQmode
)
3795 return unsignedp
? sat_udq_type_node
: udq_type_node
;
3796 if (mode
== UTQmode
)
3797 return unsignedp
? sat_utq_type_node
: utq_type_node
;
3800 return unsignedp
? sat_ha_type_node
: ha_type_node
;
3802 return unsignedp
? sat_sa_type_node
: sa_type_node
;
3804 return unsignedp
? sat_da_type_node
: da_type_node
;
3806 return unsignedp
? sat_ta_type_node
: ta_type_node
;
3808 if (mode
== UHAmode
)
3809 return unsignedp
? sat_uha_type_node
: uha_type_node
;
3810 if (mode
== USAmode
)
3811 return unsignedp
? sat_usa_type_node
: usa_type_node
;
3812 if (mode
== UDAmode
)
3813 return unsignedp
? sat_uda_type_node
: uda_type_node
;
3814 if (mode
== UTAmode
)
3815 return unsignedp
? sat_uta_type_node
: uta_type_node
;
3818 for (t
= registered_builtin_types
; t
; t
= TREE_CHAIN (t
))
3819 if (TYPE_MODE (TREE_VALUE (t
)) == mode
3820 && !!unsignedp
== !!TYPE_UNSIGNED (TREE_VALUE (t
)))
3821 return TREE_VALUE (t
);
3827 c_common_unsigned_type (tree type
)
3829 return c_common_signed_or_unsigned_type (1, type
);
3832 /* Return a signed type the same as TYPE in other respects. */
3835 c_common_signed_type (tree type
)
3837 return c_common_signed_or_unsigned_type (0, type
);
3840 /* Return a type the same as TYPE except unsigned or
3841 signed according to UNSIGNEDP. */
3844 c_common_signed_or_unsigned_type (int unsignedp
, tree type
)
3849 /* This block of code emulates the behavior of the old
3850 c_common_unsigned_type. In particular, it returns
3851 long_unsigned_type_node if passed a long, even when a int would
3852 have the same size. This is necessary for warnings to work
3853 correctly in archs where sizeof(int) == sizeof(long) */
3855 type1
= TYPE_MAIN_VARIANT (type
);
3856 if (type1
== signed_char_type_node
|| type1
== char_type_node
|| type1
== unsigned_char_type_node
)
3857 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3858 if (type1
== integer_type_node
|| type1
== unsigned_type_node
)
3859 return unsignedp
? unsigned_type_node
: integer_type_node
;
3860 if (type1
== short_integer_type_node
|| type1
== short_unsigned_type_node
)
3861 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3862 if (type1
== long_integer_type_node
|| type1
== long_unsigned_type_node
)
3863 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3864 if (type1
== long_long_integer_type_node
|| type1
== long_long_unsigned_type_node
)
3865 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3867 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
3868 if (int_n_enabled_p
[i
]
3869 && (type1
== int_n_trees
[i
].unsigned_type
3870 || type1
== int_n_trees
[i
].signed_type
))
3871 return (unsignedp
? int_n_trees
[i
].unsigned_type
3872 : int_n_trees
[i
].signed_type
);
3874 if (type1
== widest_integer_literal_type_node
|| type1
== widest_unsigned_literal_type_node
)
3875 return unsignedp
? widest_unsigned_literal_type_node
: widest_integer_literal_type_node
;
3876 #if HOST_BITS_PER_WIDE_INT >= 64
3877 if (type1
== intTI_type_node
|| type1
== unsigned_intTI_type_node
)
3878 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3880 if (type1
== intDI_type_node
|| type1
== unsigned_intDI_type_node
)
3881 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3882 if (type1
== intSI_type_node
|| type1
== unsigned_intSI_type_node
)
3883 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3884 if (type1
== intHI_type_node
|| type1
== unsigned_intHI_type_node
)
3885 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3886 if (type1
== intQI_type_node
|| type1
== unsigned_intQI_type_node
)
3887 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3889 #define C_COMMON_FIXED_TYPES(NAME) \
3890 if (type1 == short_ ## NAME ## _type_node \
3891 || type1 == unsigned_short_ ## NAME ## _type_node) \
3892 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
3893 : short_ ## NAME ## _type_node; \
3894 if (type1 == NAME ## _type_node \
3895 || type1 == unsigned_ ## NAME ## _type_node) \
3896 return unsignedp ? unsigned_ ## NAME ## _type_node \
3897 : NAME ## _type_node; \
3898 if (type1 == long_ ## NAME ## _type_node \
3899 || type1 == unsigned_long_ ## NAME ## _type_node) \
3900 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
3901 : long_ ## NAME ## _type_node; \
3902 if (type1 == long_long_ ## NAME ## _type_node \
3903 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
3904 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
3905 : long_long_ ## NAME ## _type_node;
3907 #define C_COMMON_FIXED_MODE_TYPES(NAME) \
3908 if (type1 == NAME ## _type_node \
3909 || type1 == u ## NAME ## _type_node) \
3910 return unsignedp ? u ## NAME ## _type_node \
3911 : NAME ## _type_node;
3913 #define C_COMMON_FIXED_TYPES_SAT(NAME) \
3914 if (type1 == sat_ ## short_ ## NAME ## _type_node \
3915 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
3916 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
3917 : sat_ ## short_ ## NAME ## _type_node; \
3918 if (type1 == sat_ ## NAME ## _type_node \
3919 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
3920 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
3921 : sat_ ## NAME ## _type_node; \
3922 if (type1 == sat_ ## long_ ## NAME ## _type_node \
3923 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
3924 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
3925 : sat_ ## long_ ## NAME ## _type_node; \
3926 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
3927 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
3928 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
3929 : sat_ ## long_long_ ## NAME ## _type_node;
3931 #define C_COMMON_FIXED_MODE_TYPES_SAT(NAME) \
3932 if (type1 == sat_ ## NAME ## _type_node \
3933 || type1 == sat_ ## u ## NAME ## _type_node) \
3934 return unsignedp ? sat_ ## u ## NAME ## _type_node \
3935 : sat_ ## NAME ## _type_node;
3937 C_COMMON_FIXED_TYPES (fract
);
3938 C_COMMON_FIXED_TYPES_SAT (fract
);
3939 C_COMMON_FIXED_TYPES (accum
);
3940 C_COMMON_FIXED_TYPES_SAT (accum
);
3942 C_COMMON_FIXED_MODE_TYPES (qq
);
3943 C_COMMON_FIXED_MODE_TYPES (hq
);
3944 C_COMMON_FIXED_MODE_TYPES (sq
);
3945 C_COMMON_FIXED_MODE_TYPES (dq
);
3946 C_COMMON_FIXED_MODE_TYPES (tq
);
3947 C_COMMON_FIXED_MODE_TYPES_SAT (qq
);
3948 C_COMMON_FIXED_MODE_TYPES_SAT (hq
);
3949 C_COMMON_FIXED_MODE_TYPES_SAT (sq
);
3950 C_COMMON_FIXED_MODE_TYPES_SAT (dq
);
3951 C_COMMON_FIXED_MODE_TYPES_SAT (tq
);
3952 C_COMMON_FIXED_MODE_TYPES (ha
);
3953 C_COMMON_FIXED_MODE_TYPES (sa
);
3954 C_COMMON_FIXED_MODE_TYPES (da
);
3955 C_COMMON_FIXED_MODE_TYPES (ta
);
3956 C_COMMON_FIXED_MODE_TYPES_SAT (ha
);
3957 C_COMMON_FIXED_MODE_TYPES_SAT (sa
);
3958 C_COMMON_FIXED_MODE_TYPES_SAT (da
);
3959 C_COMMON_FIXED_MODE_TYPES_SAT (ta
);
3961 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
3962 the precision; they have precision set to match their range, but
3963 may use a wider mode to match an ABI. If we change modes, we may
3964 wind up with bad conversions. For INTEGER_TYPEs in C, must check
3965 the precision as well, so as to yield correct results for
3966 bit-field types. C++ does not have these separate bit-field
3967 types, and producing a signed or unsigned variant of an
3968 ENUMERAL_TYPE may cause other problems as well. */
3970 if (!INTEGRAL_TYPE_P (type
)
3971 || TYPE_UNSIGNED (type
) == unsignedp
)
3974 #define TYPE_OK(node) \
3975 (TYPE_MODE (type) == TYPE_MODE (node) \
3976 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
3977 if (TYPE_OK (signed_char_type_node
))
3978 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3979 if (TYPE_OK (integer_type_node
))
3980 return unsignedp
? unsigned_type_node
: integer_type_node
;
3981 if (TYPE_OK (short_integer_type_node
))
3982 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3983 if (TYPE_OK (long_integer_type_node
))
3984 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3985 if (TYPE_OK (long_long_integer_type_node
))
3986 return (unsignedp
? long_long_unsigned_type_node
3987 : long_long_integer_type_node
);
3989 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
3990 if (int_n_enabled_p
[i
]
3991 && TYPE_MODE (type
) == int_n_data
[i
].m
3992 && TYPE_PRECISION (type
) == int_n_data
[i
].bitsize
)
3993 return (unsignedp
? int_n_trees
[i
].unsigned_type
3994 : int_n_trees
[i
].signed_type
);
3996 if (TYPE_OK (widest_integer_literal_type_node
))
3997 return (unsignedp
? widest_unsigned_literal_type_node
3998 : widest_integer_literal_type_node
);
4000 #if HOST_BITS_PER_WIDE_INT >= 64
4001 if (TYPE_OK (intTI_type_node
))
4002 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
4004 if (TYPE_OK (intDI_type_node
))
4005 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
4006 if (TYPE_OK (intSI_type_node
))
4007 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
4008 if (TYPE_OK (intHI_type_node
))
4009 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
4010 if (TYPE_OK (intQI_type_node
))
4011 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
4014 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
4017 /* Build a bit-field integer type for the given WIDTH and UNSIGNEDP. */
4020 c_build_bitfield_integer_type (unsigned HOST_WIDE_INT width
, int unsignedp
)
4024 /* Extended integer types of the same width as a standard type have
4025 lesser rank, so those of the same width as int promote to int or
4026 unsigned int and are valid for printf formats expecting int or
4027 unsigned int. To avoid such special cases, avoid creating
4028 extended integer types for bit-fields if a standard integer type
4030 if (width
== TYPE_PRECISION (integer_type_node
))
4031 return unsignedp
? unsigned_type_node
: integer_type_node
;
4032 if (width
== TYPE_PRECISION (signed_char_type_node
))
4033 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
4034 if (width
== TYPE_PRECISION (short_integer_type_node
))
4035 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
4036 if (width
== TYPE_PRECISION (long_integer_type_node
))
4037 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
4038 if (width
== TYPE_PRECISION (long_long_integer_type_node
))
4039 return (unsignedp
? long_long_unsigned_type_node
4040 : long_long_integer_type_node
);
4041 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
4042 if (int_n_enabled_p
[i
]
4043 && width
== int_n_data
[i
].bitsize
)
4044 return (unsignedp
? int_n_trees
[i
].unsigned_type
4045 : int_n_trees
[i
].signed_type
);
4046 return build_nonstandard_integer_type (width
, unsignedp
);
4049 /* The C version of the register_builtin_type langhook. */
4052 c_register_builtin_type (tree type
, const char* name
)
4056 decl
= build_decl (UNKNOWN_LOCATION
,
4057 TYPE_DECL
, get_identifier (name
), type
);
4058 DECL_ARTIFICIAL (decl
) = 1;
4059 if (!TYPE_NAME (type
))
4060 TYPE_NAME (type
) = decl
;
4063 registered_builtin_types
= tree_cons (0, type
, registered_builtin_types
);
4066 /* Print an error message for invalid operands to arith operation
4067 CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
4068 LOCATION is the location of the message. */
4071 binary_op_error (location_t location
, enum tree_code code
,
4072 tree type0
, tree type1
)
4079 opname
= "+"; break;
4081 opname
= "-"; break;
4083 opname
= "*"; break;
4085 opname
= "max"; break;
4087 opname
= "min"; break;
4089 opname
= "=="; break;
4091 opname
= "!="; break;
4093 opname
= "<="; break;
4095 opname
= ">="; break;
4097 opname
= "<"; break;
4099 opname
= ">"; break;
4101 opname
= "<<"; break;
4103 opname
= ">>"; break;
4104 case TRUNC_MOD_EXPR
:
4105 case FLOOR_MOD_EXPR
:
4106 opname
= "%"; break;
4107 case TRUNC_DIV_EXPR
:
4108 case FLOOR_DIV_EXPR
:
4109 opname
= "/"; break;
4111 opname
= "&"; break;
4113 opname
= "|"; break;
4114 case TRUTH_ANDIF_EXPR
:
4115 opname
= "&&"; break;
4116 case TRUTH_ORIF_EXPR
:
4117 opname
= "||"; break;
4119 opname
= "^"; break;
4124 "invalid operands to binary %s (have %qT and %qT)", opname
,
4128 /* Given an expression as a tree, return its original type. Do this
4129 by stripping any conversion that preserves the sign and precision. */
4131 expr_original_type (tree expr
)
4133 STRIP_SIGN_NOPS (expr
);
4134 return TREE_TYPE (expr
);
4137 /* Subroutine of build_binary_op, used for comparison operations.
4138 See if the operands have both been converted from subword integer types
4139 and, if so, perhaps change them both back to their original type.
4140 This function is also responsible for converting the two operands
4141 to the proper common type for comparison.
4143 The arguments of this function are all pointers to local variables
4144 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
4145 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
4147 LOC is the location of the comparison.
4149 If this function returns nonzero, it means that the comparison has
4150 a constant value. What this function returns is an expression for
4154 shorten_compare (location_t loc
, tree
*op0_ptr
, tree
*op1_ptr
,
4155 tree
*restype_ptr
, enum tree_code
*rescode_ptr
)
4158 tree op0
= *op0_ptr
;
4159 tree op1
= *op1_ptr
;
4160 int unsignedp0
, unsignedp1
;
4162 tree primop0
, primop1
;
4163 enum tree_code code
= *rescode_ptr
;
4165 /* Throw away any conversions to wider types
4166 already present in the operands. */
4168 primop0
= c_common_get_narrower (op0
, &unsignedp0
);
4169 primop1
= c_common_get_narrower (op1
, &unsignedp1
);
4171 /* If primopN is first sign-extended from primopN's precision to opN's
4172 precision, then zero-extended from opN's precision to
4173 *restype_ptr precision, shortenings might be invalid. */
4174 if (TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (TREE_TYPE (op0
))
4175 && TYPE_PRECISION (TREE_TYPE (op0
)) < TYPE_PRECISION (*restype_ptr
)
4177 && TYPE_UNSIGNED (TREE_TYPE (op0
)))
4179 if (TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (TREE_TYPE (op1
))
4180 && TYPE_PRECISION (TREE_TYPE (op1
)) < TYPE_PRECISION (*restype_ptr
)
4182 && TYPE_UNSIGNED (TREE_TYPE (op1
)))
4185 /* Handle the case that OP0 does not *contain* a conversion
4186 but it *requires* conversion to FINAL_TYPE. */
4188 if (op0
== primop0
&& TREE_TYPE (op0
) != *restype_ptr
)
4189 unsignedp0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
4190 if (op1
== primop1
&& TREE_TYPE (op1
) != *restype_ptr
)
4191 unsignedp1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
4193 /* If one of the operands must be floated, we cannot optimize. */
4194 real1
= TREE_CODE (TREE_TYPE (primop0
)) == REAL_TYPE
;
4195 real2
= TREE_CODE (TREE_TYPE (primop1
)) == REAL_TYPE
;
4197 /* If first arg is constant, swap the args (changing operation
4198 so value is preserved), for canonicalization. Don't do this if
4199 the second arg is 0. */
4201 if (TREE_CONSTANT (primop0
)
4202 && !integer_zerop (primop1
) && !real_zerop (primop1
)
4203 && !fixed_zerop (primop1
))
4206 int temi
= unsignedp0
;
4214 unsignedp0
= unsignedp1
;
4237 *rescode_ptr
= code
;
4240 /* If comparing an integer against a constant more bits wide,
4241 maybe we can deduce a value of 1 or 0 independent of the data.
4242 Or else truncate the constant now
4243 rather than extend the variable at run time.
4245 This is only interesting if the constant is the wider arg.
4246 Also, it is not safe if the constant is unsigned and the
4247 variable arg is signed, since in this case the variable
4248 would be sign-extended and then regarded as unsigned.
4249 Our technique fails in this case because the lowest/highest
4250 possible unsigned results don't follow naturally from the
4251 lowest/highest possible values of the variable operand.
4252 For just EQ_EXPR and NE_EXPR there is another technique that
4253 could be used: see if the constant can be faithfully represented
4254 in the other operand's type, by truncating it and reextending it
4255 and see if that preserves the constant's value. */
4257 if (!real1
&& !real2
4258 && TREE_CODE (TREE_TYPE (primop0
)) != FIXED_POINT_TYPE
4259 && TREE_CODE (primop1
) == INTEGER_CST
4260 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
))
4262 int min_gt
, max_gt
, min_lt
, max_lt
;
4263 tree maxval
, minval
;
4264 /* 1 if comparison is nominally unsigned. */
4265 int unsignedp
= TYPE_UNSIGNED (*restype_ptr
);
4268 type
= c_common_signed_or_unsigned_type (unsignedp0
,
4269 TREE_TYPE (primop0
));
4271 maxval
= TYPE_MAX_VALUE (type
);
4272 minval
= TYPE_MIN_VALUE (type
);
4274 if (unsignedp
&& !unsignedp0
)
4275 *restype_ptr
= c_common_signed_type (*restype_ptr
);
4277 if (TREE_TYPE (primop1
) != *restype_ptr
)
4279 /* Convert primop1 to target type, but do not introduce
4280 additional overflow. We know primop1 is an int_cst. */
4281 primop1
= force_fit_type (*restype_ptr
,
4284 TYPE_PRECISION (*restype_ptr
),
4285 TYPE_SIGN (TREE_TYPE (primop1
))),
4286 0, TREE_OVERFLOW (primop1
));
4288 if (type
!= *restype_ptr
)
4290 minval
= convert (*restype_ptr
, minval
);
4291 maxval
= convert (*restype_ptr
, maxval
);
4294 min_gt
= tree_int_cst_lt (primop1
, minval
);
4295 max_gt
= tree_int_cst_lt (primop1
, maxval
);
4296 min_lt
= tree_int_cst_lt (minval
, primop1
);
4297 max_lt
= tree_int_cst_lt (maxval
, primop1
);
4300 /* This used to be a switch, but Genix compiler can't handle that. */
4301 if (code
== NE_EXPR
)
4303 if (max_lt
|| min_gt
)
4304 val
= truthvalue_true_node
;
4306 else if (code
== EQ_EXPR
)
4308 if (max_lt
|| min_gt
)
4309 val
= truthvalue_false_node
;
4311 else if (code
== LT_EXPR
)
4314 val
= truthvalue_true_node
;
4316 val
= truthvalue_false_node
;
4318 else if (code
== GT_EXPR
)
4321 val
= truthvalue_true_node
;
4323 val
= truthvalue_false_node
;
4325 else if (code
== LE_EXPR
)
4328 val
= truthvalue_true_node
;
4330 val
= truthvalue_false_node
;
4332 else if (code
== GE_EXPR
)
4335 val
= truthvalue_true_node
;
4337 val
= truthvalue_false_node
;
4340 /* If primop0 was sign-extended and unsigned comparison specd,
4341 we did a signed comparison above using the signed type bounds.
4342 But the comparison we output must be unsigned.
4344 Also, for inequalities, VAL is no good; but if the signed
4345 comparison had *any* fixed result, it follows that the
4346 unsigned comparison just tests the sign in reverse
4347 (positive values are LE, negative ones GE).
4348 So we can generate an unsigned comparison
4349 against an extreme value of the signed type. */
4351 if (unsignedp
&& !unsignedp0
)
4358 primop1
= TYPE_MIN_VALUE (type
);
4364 primop1
= TYPE_MAX_VALUE (type
);
4371 type
= c_common_unsigned_type (type
);
4374 if (TREE_CODE (primop0
) != INTEGER_CST
)
4376 if (val
== truthvalue_false_node
)
4377 warning_at (loc
, OPT_Wtype_limits
,
4378 "comparison is always false due to limited range of data type");
4379 if (val
== truthvalue_true_node
)
4380 warning_at (loc
, OPT_Wtype_limits
,
4381 "comparison is always true due to limited range of data type");
4386 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4387 if (TREE_SIDE_EFFECTS (primop0
))
4388 return build2 (COMPOUND_EXPR
, TREE_TYPE (val
), primop0
, val
);
4392 /* Value is not predetermined, but do the comparison
4393 in the type of the operand that is not constant.
4394 TYPE is already properly set. */
4397 /* If either arg is decimal float and the other is float, find the
4398 proper common type to use for comparison. */
4399 else if (real1
&& real2
4400 && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0
)))
4401 && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1
))))
4402 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
4404 /* If either arg is decimal float and the other is float, fail. */
4405 else if (real1
&& real2
4406 && (DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0
)))
4407 || DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1
)))))
4410 else if (real1
&& real2
4411 && (TYPE_PRECISION (TREE_TYPE (primop0
))
4412 == TYPE_PRECISION (TREE_TYPE (primop1
))))
4413 type
= TREE_TYPE (primop0
);
4415 /* If args' natural types are both narrower than nominal type
4416 and both extend in the same manner, compare them
4417 in the type of the wider arg.
4418 Otherwise must actually extend both to the nominal
4419 common type lest different ways of extending
4421 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
4423 else if (unsignedp0
== unsignedp1
&& real1
== real2
4424 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
)
4425 && TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (*restype_ptr
))
4427 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
4428 type
= c_common_signed_or_unsigned_type (unsignedp0
4429 || TYPE_UNSIGNED (*restype_ptr
),
4431 /* Make sure shorter operand is extended the right way
4432 to match the longer operand. */
4434 = convert (c_common_signed_or_unsigned_type (unsignedp0
,
4435 TREE_TYPE (primop0
)),
4438 = convert (c_common_signed_or_unsigned_type (unsignedp1
,
4439 TREE_TYPE (primop1
)),
4444 /* Here we must do the comparison on the nominal type
4445 using the args exactly as we received them. */
4446 type
= *restype_ptr
;
4450 if (!real1
&& !real2
&& integer_zerop (primop1
)
4451 && TYPE_UNSIGNED (*restype_ptr
))
4454 /* All unsigned values are >= 0, so we warn. However,
4455 if OP0 is a constant that is >= 0, the signedness of
4456 the comparison isn't an issue, so suppress the
4459 warn_type_limits
&& !in_system_header_at (loc
)
4460 && !(TREE_CODE (primop0
) == INTEGER_CST
4461 && !TREE_OVERFLOW (convert (c_common_signed_type (type
),
4463 /* Do not warn for enumeration types. */
4464 && (TREE_CODE (expr_original_type (primop0
)) != ENUMERAL_TYPE
);
4470 warning_at (loc
, OPT_Wtype_limits
,
4471 "comparison of unsigned expression >= 0 is always true");
4472 value
= truthvalue_true_node
;
4477 warning_at (loc
, OPT_Wtype_limits
,
4478 "comparison of unsigned expression < 0 is always false");
4479 value
= truthvalue_false_node
;
4488 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4489 if (TREE_SIDE_EFFECTS (primop0
))
4490 return build2 (COMPOUND_EXPR
, TREE_TYPE (value
),
4497 *op0_ptr
= convert (type
, primop0
);
4498 *op1_ptr
= convert (type
, primop1
);
4500 *restype_ptr
= truthvalue_type_node
;
4505 /* Return a tree for the sum or difference (RESULTCODE says which)
4506 of pointer PTROP and integer INTOP. */
4509 pointer_int_sum (location_t loc
, enum tree_code resultcode
,
4510 tree ptrop
, tree intop
, bool complain
)
4514 /* The result is a pointer of the same type that is being added. */
4515 tree result_type
= TREE_TYPE (ptrop
);
4517 /* If the pointer lives in UPC shared memory, then
4518 drop the 'shared' qualifier. */
4519 if (TREE_SHARED (ptrop
) || upc_shared_type_p (result_type
))
4520 result_type
= build_upc_unshared_type (result_type
);
4522 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
4524 if (complain
&& warn_pointer_arith
)
4525 pedwarn (loc
, OPT_Wpointer_arith
,
4526 "pointer of type %<void *%> used in arithmetic");
4528 return error_mark_node
;
4529 size_exp
= integer_one_node
;
4531 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
4533 if (complain
&& warn_pointer_arith
)
4534 pedwarn (loc
, OPT_Wpointer_arith
,
4535 "pointer to a function used in arithmetic");
4537 return error_mark_node
;
4538 size_exp
= integer_one_node
;
4541 size_exp
= size_in_bytes (TREE_TYPE (result_type
));
4543 /* We are manipulating pointer values, so we don't need to warn
4544 about relying on undefined signed overflow. We disable the
4545 warning here because we use integer types so fold won't know that
4546 they are really pointers. */
4547 fold_defer_overflow_warnings ();
4549 /* If what we are about to multiply by the size of the elements
4550 contains a constant term, apply distributive law
4551 and multiply that constant term separately.
4552 This helps produce common subexpressions. */
4553 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
4554 && !TREE_CONSTANT (intop
)
4555 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
4556 && TREE_CONSTANT (size_exp
)
4557 /* If the constant comes from pointer subtraction,
4558 skip this optimization--it would cause an error. */
4559 && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop
, 0))) == INTEGER_TYPE
4560 /* If the constant is unsigned, and smaller than the pointer size,
4561 then we must skip this optimization. This is because it could cause
4562 an overflow error if the constant is negative but INTOP is not. */
4563 && (!TYPE_UNSIGNED (TREE_TYPE (intop
))
4564 || (TYPE_PRECISION (TREE_TYPE (intop
))
4565 == TYPE_PRECISION (TREE_TYPE (ptrop
)))))
4567 enum tree_code subcode
= resultcode
;
4568 tree int_type
= TREE_TYPE (intop
);
4569 if (TREE_CODE (intop
) == MINUS_EXPR
)
4570 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
4571 /* Convert both subexpression types to the type of intop,
4572 because weird cases involving pointer arithmetic
4573 can result in a sum or difference with different type args. */
4574 ptrop
= build_binary_op (EXPR_LOCATION (TREE_OPERAND (intop
, 1)),
4576 convert (int_type
, TREE_OPERAND (intop
, 1)), 1);
4577 intop
= convert (int_type
, TREE_OPERAND (intop
, 0));
4580 /* Convert the integer argument to a type the same size as sizetype
4581 so the multiply won't overflow spuriously. */
4582 if (TYPE_PRECISION (TREE_TYPE (intop
)) != TYPE_PRECISION (sizetype
)
4583 || TYPE_UNSIGNED (TREE_TYPE (intop
)) != TYPE_UNSIGNED (sizetype
))
4584 intop
= convert (c_common_type_for_size (TYPE_PRECISION (sizetype
),
4585 TYPE_UNSIGNED (sizetype
)), intop
);
4587 /* Replace the integer argument with a suitable product by the object size.
4588 Do this multiplication as signed, then convert to the appropriate type
4589 for the pointer operation and disregard an overflow that occurred only
4590 because of the sign-extension change in the latter conversion. */
4592 tree t
= build_binary_op (loc
,
4594 convert (TREE_TYPE (intop
), size_exp
), 1);
4595 intop
= convert (sizetype
, t
);
4596 if (TREE_OVERFLOW_P (intop
) && !TREE_OVERFLOW (t
))
4597 intop
= wide_int_to_tree (TREE_TYPE (intop
), intop
);
4600 /* Create the sum or difference. */
4601 if (resultcode
== MINUS_EXPR
)
4602 intop
= fold_build1_loc (loc
, NEGATE_EXPR
, sizetype
, intop
);
4604 ret
= fold_build_pointer_plus_loc (loc
, ptrop
, intop
);
4606 fold_undefer_and_ignore_overflow_warnings ();
4611 /* Wrap a C_MAYBE_CONST_EXPR around an expression that is fully folded
4612 and if NON_CONST is known not to be permitted in an evaluated part
4613 of a constant expression. */
4616 c_wrap_maybe_const (tree expr
, bool non_const
)
4618 bool nowarning
= TREE_NO_WARNING (expr
);
4619 location_t loc
= EXPR_LOCATION (expr
);
4621 /* This should never be called for C++. */
4622 if (c_dialect_cxx ())
4625 /* The result of folding may have a NOP_EXPR to set TREE_NO_WARNING. */
4626 STRIP_TYPE_NOPS (expr
);
4627 expr
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (expr
), NULL
, expr
);
4628 C_MAYBE_CONST_EXPR_NON_CONST (expr
) = non_const
;
4630 TREE_NO_WARNING (expr
) = 1;
4631 protected_set_expr_location (expr
, loc
);
4636 /* Wrap a SAVE_EXPR around EXPR, if appropriate. Like save_expr, but
4637 for C folds the inside expression and wraps a C_MAYBE_CONST_EXPR
4638 around the SAVE_EXPR if needed so that c_fully_fold does not need
4639 to look inside SAVE_EXPRs. */
4642 c_save_expr (tree expr
)
4644 bool maybe_const
= true;
4645 if (c_dialect_cxx ())
4646 return save_expr (expr
);
4647 expr
= c_fully_fold (expr
, false, &maybe_const
);
4648 expr
= save_expr (expr
);
4650 expr
= c_wrap_maybe_const (expr
, true);
4654 /* Return whether EXPR is a declaration whose address can never be
4658 decl_with_nonnull_addr_p (const_tree expr
)
4660 return (DECL_P (expr
)
4661 && (TREE_CODE (expr
) == PARM_DECL
4662 || TREE_CODE (expr
) == LABEL_DECL
4663 || !DECL_WEAK (expr
)));
4666 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
4667 or for an `if' or `while' statement or ?..: exp. It should already
4668 have been validated to be of suitable type; otherwise, a bad
4669 diagnostic may result.
4671 The EXPR is located at LOCATION.
4673 This preparation consists of taking the ordinary
4674 representation of an expression expr and producing a valid tree
4675 boolean expression describing whether expr is nonzero. We could
4676 simply always do build_binary_op (NE_EXPR, expr, truthvalue_false_node, 1),
4677 but we optimize comparisons, &&, ||, and !.
4679 The resulting type should always be `truthvalue_type_node'. */
4682 c_common_truthvalue_conversion (location_t location
, tree expr
)
4684 switch (TREE_CODE (expr
))
4686 case EQ_EXPR
: case NE_EXPR
: case UNEQ_EXPR
: case LTGT_EXPR
:
4687 case LE_EXPR
: case GE_EXPR
: case LT_EXPR
: case GT_EXPR
:
4688 case UNLE_EXPR
: case UNGE_EXPR
: case UNLT_EXPR
: case UNGT_EXPR
:
4689 case ORDERED_EXPR
: case UNORDERED_EXPR
:
4690 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4692 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4693 TREE_OPERAND (expr
, 0), TREE_OPERAND (expr
, 1));
4696 case TRUTH_ANDIF_EXPR
:
4697 case TRUTH_ORIF_EXPR
:
4698 case TRUTH_AND_EXPR
:
4700 case TRUTH_XOR_EXPR
:
4701 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4703 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4704 c_common_truthvalue_conversion (location
,
4705 TREE_OPERAND (expr
, 0)),
4706 c_common_truthvalue_conversion (location
,
4707 TREE_OPERAND (expr
, 1)));
4710 case TRUTH_NOT_EXPR
:
4711 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4713 expr
= build1 (TREE_CODE (expr
), truthvalue_type_node
,
4714 c_common_truthvalue_conversion (location
,
4715 TREE_OPERAND (expr
, 0)));
4722 return integer_zerop (expr
) ? truthvalue_false_node
4723 : truthvalue_true_node
;
4726 return real_compare (NE_EXPR
, &TREE_REAL_CST (expr
), &dconst0
)
4727 ? truthvalue_true_node
4728 : truthvalue_false_node
;
4731 return fixed_compare (NE_EXPR
, &TREE_FIXED_CST (expr
),
4732 &FCONST0 (TYPE_MODE (TREE_TYPE (expr
))))
4733 ? truthvalue_true_node
4734 : truthvalue_false_node
;
4737 expr
= build_unary_op (location
, ADDR_EXPR
, expr
, 0);
4742 tree inner
= TREE_OPERAND (expr
, 0);
4743 if (decl_with_nonnull_addr_p (inner
))
4745 /* Common Ada/Pascal programmer's mistake. */
4746 warning_at (location
,
4748 "the address of %qD will always evaluate as %<true%>",
4750 return truthvalue_true_node
;
4756 expr
= build_binary_op (EXPR_LOCATION (expr
),
4757 (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1))
4758 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4759 c_common_truthvalue_conversion (location
,
4760 TREE_OPERAND (expr
, 0)),
4761 c_common_truthvalue_conversion (location
,
4762 TREE_OPERAND (expr
, 1)),
4769 case EXCESS_PRECISION_EXPR
:
4770 /* These don't change whether an object is nonzero or zero. */
4771 return c_common_truthvalue_conversion (location
, TREE_OPERAND (expr
, 0));
4775 /* These don't change whether an object is zero or nonzero, but
4776 we can't ignore them if their second arg has side-effects. */
4777 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1)))
4779 expr
= build2 (COMPOUND_EXPR
, truthvalue_type_node
,
4780 TREE_OPERAND (expr
, 1),
4781 c_common_truthvalue_conversion
4782 (location
, TREE_OPERAND (expr
, 0)));
4786 return c_common_truthvalue_conversion (location
,
4787 TREE_OPERAND (expr
, 0));
4790 /* Distribute the conversion into the arms of a COND_EXPR. */
4791 if (c_dialect_cxx ())
4793 tree op1
= TREE_OPERAND (expr
, 1);
4794 tree op2
= TREE_OPERAND (expr
, 2);
4795 /* In C++ one of the arms might have void type if it is throw. */
4796 if (!VOID_TYPE_P (TREE_TYPE (op1
)))
4797 op1
= c_common_truthvalue_conversion (location
, op1
);
4798 if (!VOID_TYPE_P (TREE_TYPE (op2
)))
4799 op2
= c_common_truthvalue_conversion (location
, op2
);
4800 expr
= fold_build3_loc (location
, COND_EXPR
, truthvalue_type_node
,
4801 TREE_OPERAND (expr
, 0), op1
, op2
);
4806 /* Folding will happen later for C. */
4807 expr
= build3 (COND_EXPR
, truthvalue_type_node
,
4808 TREE_OPERAND (expr
, 0),
4809 c_common_truthvalue_conversion (location
,
4810 TREE_OPERAND (expr
, 1)),
4811 c_common_truthvalue_conversion (location
,
4812 TREE_OPERAND (expr
, 2)));
4818 tree totype
= TREE_TYPE (expr
);
4819 tree fromtype
= TREE_TYPE (TREE_OPERAND (expr
, 0));
4821 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
4822 since that affects how `default_conversion' will behave. */
4823 if (TREE_CODE (totype
) == REFERENCE_TYPE
4824 || TREE_CODE (fromtype
) == REFERENCE_TYPE
)
4826 /* Don't strip a conversion from C++0x scoped enum, since they
4827 don't implicitly convert to other types. */
4828 if (TREE_CODE (fromtype
) == ENUMERAL_TYPE
4829 && ENUM_IS_SCOPED (fromtype
))
4831 /* If this isn't narrowing the argument, we can ignore it. */
4832 if (TYPE_PRECISION (totype
) >= TYPE_PRECISION (fromtype
))
4833 return c_common_truthvalue_conversion (location
,
4834 TREE_OPERAND (expr
, 0));
4839 if (!TREE_NO_WARNING (expr
)
4840 && warn_parentheses
)
4842 warning (OPT_Wparentheses
,
4843 "suggest parentheses around assignment used as truth value");
4844 TREE_NO_WARNING (expr
) = 1;
4852 if (TREE_CODE (TREE_TYPE (expr
)) == COMPLEX_TYPE
)
4854 tree t
= (in_late_binary_op
? save_expr (expr
) : c_save_expr (expr
));
4855 expr
= (build_binary_op
4856 (EXPR_LOCATION (expr
),
4857 (TREE_SIDE_EFFECTS (expr
)
4858 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4859 c_common_truthvalue_conversion
4861 build_unary_op (location
, REALPART_EXPR
, t
, 0)),
4862 c_common_truthvalue_conversion
4864 build_unary_op (location
, IMAGPART_EXPR
, t
, 0)),
4869 if (TREE_CODE (TREE_TYPE (expr
)) == FIXED_POINT_TYPE
)
4871 tree fixed_zero_node
= build_fixed (TREE_TYPE (expr
),
4873 (TREE_TYPE (expr
))));
4874 return build_binary_op (location
, NE_EXPR
, expr
, fixed_zero_node
, 1);
4877 return build_binary_op (location
, NE_EXPR
, expr
, integer_zero_node
, 1);
4880 protected_set_expr_location (expr
, location
);
4884 static void def_builtin_1 (enum built_in_function fncode
,
4886 enum built_in_class fnclass
,
4887 tree fntype
, tree libtype
,
4888 bool both_p
, bool fallback_p
, bool nonansi_p
,
4889 tree fnattrs
, bool implicit_p
);
4892 /* Apply the TYPE_QUALS to the new DECL. */
4895 c_apply_type_quals_to_decl (int type_quals
, tree decl
)
4897 tree type
= TREE_TYPE (decl
);
4899 if (type
== error_mark_node
)
4902 if ((type_quals
& TYPE_QUAL_CONST
)
4903 || (type
&& TREE_CODE (type
) == REFERENCE_TYPE
))
4904 /* We used to check TYPE_NEEDS_CONSTRUCTING here, but now a constexpr
4905 constructor can produce constant init, so rely on cp_finish_decl to
4906 clear TREE_READONLY if the variable has non-constant init. */
4907 TREE_READONLY (decl
) = 1;
4908 if (type_quals
& TYPE_QUAL_VOLATILE
)
4910 TREE_SIDE_EFFECTS (decl
) = 1;
4911 TREE_THIS_VOLATILE (decl
) = 1;
4913 if (type_quals
& TYPE_QUAL_RESTRICT
)
4915 while (type
&& TREE_CODE (type
) == ARRAY_TYPE
)
4916 /* Allow 'restrict' on arrays of pointers.
4917 FIXME currently we just ignore it. */
4918 type
= TREE_TYPE (type
);
4920 || !POINTER_TYPE_P (type
)
4921 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type
)))
4922 error ("invalid use of %<restrict%>");
4924 if (type_quals
& TYPE_QUAL_UPC_SHARED
)
4926 TREE_SHARED (decl
) = 1;
4927 if (type_quals
& TYPE_QUAL_UPC_STRICT
)
4928 TREE_STRICT(decl
) = 1;
4929 else if (type_quals
& TYPE_QUAL_UPC_RELAXED
)
4930 TREE_RELAXED(decl
) = 1;
4931 /* The declaration's type should have been previously defined
4932 as a UPC shared type. */
4933 gcc_assert (upc_shared_type_p (type
));
4937 struct c_type_hasher
: ggc_hasher
<tree
>
4939 static hashval_t
hash (tree
);
4940 static bool equal (tree
, tree
);
4943 /* Hash function for the problem of multiple type definitions in
4944 different files. This must hash all types that will compare
4945 equal via comptypes to the same value. In practice it hashes
4946 on some of the simple stuff and leaves the details to comptypes. */
4949 c_type_hasher::hash (tree t
)
4954 switch (TREE_CODE (t
))
4956 /* For pointers, hash on pointee type plus some swizzling. */
4958 return hash (TREE_TYPE (t
)) ^ 0x3003003;
4959 /* Hash on number of elements and total size. */
4962 t2
= TYPE_VALUES (t
);
4966 t2
= TYPE_FIELDS (t
);
4968 case QUAL_UNION_TYPE
:
4970 t2
= TYPE_FIELDS (t
);
4974 t2
= TYPE_FIELDS (t
);
4979 /* FIXME: We want to use a DECL_CHAIN iteration method here, but
4980 TYPE_VALUES of ENUMERAL_TYPEs is stored as a TREE_LIST. */
4981 n_elements
= list_length (t2
);
4982 /* We might have a VLA here. */
4983 if (TREE_CODE (TYPE_SIZE (t
)) != INTEGER_CST
)
4986 size
= TREE_INT_CST_LOW (TYPE_SIZE (t
));
4987 return ((size
<< 24) | (n_elements
<< shift
));
4991 c_type_hasher::equal (tree t1
, tree t2
)
4993 return lang_hooks
.types_compatible_p (t1
, t2
);
4996 static GTY(()) hash_table
<c_type_hasher
> *type_hash_table
;
4998 /* Return the typed-based alias set for T, which may be an expression
4999 or a type. Return -1 if we don't do anything special. */
5002 c_common_get_alias_set (tree t
)
5006 /* For VLAs, use the alias set of the element type rather than the
5007 default of alias set 0 for types compared structurally. */
5008 if (TYPE_P (t
) && TYPE_STRUCTURAL_EQUALITY_P (t
))
5010 if (TREE_CODE (t
) == ARRAY_TYPE
)
5011 return get_alias_set (TREE_TYPE (t
));
5015 /* Permit type-punning when accessing a union, provided the access
5016 is directly through the union. For example, this code does not
5017 permit taking the address of a union member and then storing
5018 through it. Even the type-punning allowed here is a GCC
5019 extension, albeit a common and useful one; the C standard says
5020 that such accesses have implementation-defined behavior. */
5022 TREE_CODE (u
) == COMPONENT_REF
|| TREE_CODE (u
) == ARRAY_REF
;
5023 u
= TREE_OPERAND (u
, 0))
5024 if (TREE_CODE (u
) == COMPONENT_REF
5025 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u
, 0))) == UNION_TYPE
)
5028 /* That's all the expressions we handle specially. */
5032 /* The C standard guarantees that any object may be accessed via an
5033 lvalue that has character type. */
5034 if (t
== char_type_node
5035 || t
== signed_char_type_node
5036 || t
== unsigned_char_type_node
)
5039 /* The C standard specifically allows aliasing between signed and
5040 unsigned variants of the same type. We treat the signed
5041 variant as canonical. */
5042 if (TREE_CODE (t
) == INTEGER_TYPE
&& TYPE_UNSIGNED (t
))
5044 tree t1
= c_common_signed_type (t
);
5046 /* t1 == t can happen for boolean nodes which are always unsigned. */
5048 return get_alias_set (t1
);
5051 /* For the time being, make UPC pointers-to-shared conflict
5052 with everything else. Ideally, UPC pointers-to-shared should
5053 only conflict with the internal type used to represent
5054 the UPC pointer-to-shared (i.e., upc_pts_rep_type_node). */
5056 if (TYPE_P (t
) ? (TREE_CODE (t
) == POINTER_TYPE
5057 && upc_shared_type_p (TREE_TYPE (t
)))
5059 && TREE_CODE (TREE_TYPE (t
)) == POINTER_TYPE
5060 && upc_shared_type_p (TREE_TYPE (TREE_TYPE (t
)))))
5063 /* Handle the case of multiple type nodes referring to "the same" type,
5064 which occurs with IMA. These share an alias set. FIXME: Currently only
5065 C90 is handled. (In C99 type compatibility is not transitive, which
5066 complicates things mightily. The alias set splay trees can theoretically
5067 represent this, but insertion is tricky when you consider all the
5068 different orders things might arrive in.) */
5070 if (c_language
!= clk_c
|| flag_isoc99
)
5073 /* Save time if there's only one input file. */
5074 if (num_in_fnames
== 1)
5077 /* Pointers need special handling if they point to any type that
5078 needs special handling (below). */
5079 if (TREE_CODE (t
) == POINTER_TYPE
)
5082 /* Find bottom type under any nested POINTERs. */
5083 for (t2
= TREE_TYPE (t
);
5084 TREE_CODE (t2
) == POINTER_TYPE
;
5085 t2
= TREE_TYPE (t2
))
5087 if (TREE_CODE (t2
) != RECORD_TYPE
5088 && TREE_CODE (t2
) != ENUMERAL_TYPE
5089 && TREE_CODE (t2
) != QUAL_UNION_TYPE
5090 && TREE_CODE (t2
) != UNION_TYPE
)
5092 if (TYPE_SIZE (t2
) == 0)
5095 /* These are the only cases that need special handling. */
5096 if (TREE_CODE (t
) != RECORD_TYPE
5097 && TREE_CODE (t
) != ENUMERAL_TYPE
5098 && TREE_CODE (t
) != QUAL_UNION_TYPE
5099 && TREE_CODE (t
) != UNION_TYPE
5100 && TREE_CODE (t
) != POINTER_TYPE
)
5103 if (TYPE_SIZE (t
) == 0)
5106 /* Look up t in hash table. Only one of the compatible types within each
5107 alias set is recorded in the table. */
5108 if (!type_hash_table
)
5109 type_hash_table
= hash_table
<c_type_hasher
>::create_ggc (1021);
5110 tree
*slot
= type_hash_table
->find_slot (t
, INSERT
);
5113 TYPE_ALIAS_SET (t
) = TYPE_ALIAS_SET ((tree
)*slot
);
5114 return TYPE_ALIAS_SET ((tree
)*slot
);
5117 /* Our caller will assign and record (in t) a new alias set; all we need
5118 to do is remember t in the hash table. */
5124 /* Return the value of THREADS.
5126 UPC defines a reserved variable, THREADS, which returns the
5127 number of threads that will be created when the UPC program
5128 executes. The value of threads can be specified at runtime via
5129 the -fupc-threads=N switch, where N is an integer specifying
5130 the number of threads. When the value of THREADS is specified
5131 at compile-time, this is called the "static threads compilation
5134 In the static threads compilation environment, THREADS is a
5135 pre-defined preprocessor macro with the value, N.
5137 If no value for threads is given at compile-time, then the value
5138 must be specified when the application program is executed.
5139 This method of establishing the value of THREADS is called
5140 the "dynamic threads compilation environment". */
5143 upc_num_threads (void)
5146 gcc_assert (flag_upc
);
5147 n
= flag_upc_threads
? ssize_int (flag_upc_threads
)
5148 : lookup_name (get_identifier ("THREADS"));
5151 error ("the UPC-required THREADS variable is undefined; "
5152 "when compiling pre-processed source, "
5153 "all -fupc-* switches must be passed on the command line, "
5154 "asserting the same values as supplied when the "
5155 "original source file was preprocessed");
5162 /* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where
5163 the IS_SIZEOF parameter indicates which operator is being applied.
5164 The COMPLAIN flag controls whether we should diagnose possibly
5165 ill-formed constructs or not. LOC is the location of the SIZEOF or
5166 TYPEOF operator. If MIN_ALIGNOF, the least alignment required for
5167 a type in any context should be returned, rather than the normal
5168 alignment for that type. */
5171 c_sizeof_or_alignof_type (location_t loc
,
5172 tree type
, bool is_sizeof
, bool min_alignof
,
5175 const char *op_name
;
5177 enum tree_code type_code
= TREE_CODE (type
);
5179 op_name
= is_sizeof
? "sizeof" : "__alignof__";
5181 if (type_code
== FUNCTION_TYPE
)
5185 if (complain
&& warn_pointer_arith
)
5186 pedwarn (loc
, OPT_Wpointer_arith
,
5187 "invalid application of %<sizeof%> to a function type");
5189 return error_mark_node
;
5190 value
= size_one_node
;
5196 if (c_dialect_cxx ())
5197 pedwarn (loc
, OPT_Wpedantic
, "ISO C++ does not permit "
5198 "%<alignof%> applied to a function type");
5200 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not permit "
5201 "%<_Alignof%> applied to a function type");
5203 value
= size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
5206 else if (type_code
== VOID_TYPE
|| type_code
== ERROR_MARK
)
5210 if (type_code
== VOID_TYPE
&& upc_shared_type_p (type
))
5211 error_at (loc
, "invalid application of %qs"
5212 " to %<shared void%> type", op_name
);
5213 else if (type_code
== VOID_TYPE
&& warn_pointer_arith
)
5214 pedwarn (loc
, pedantic
? OPT_Wpedantic
: OPT_Wpointer_arith
,
5215 "invalid application of %qs to a void type", op_name
);
5218 return error_mark_node
;
5219 value
= size_one_node
;
5221 else if (!COMPLETE_TYPE_P (type
)
5222 && (!c_dialect_cxx () || is_sizeof
|| type_code
!= ARRAY_TYPE
))
5225 error_at (loc
, "invalid application of %qs to incomplete type %qT",
5227 return error_mark_node
;
5229 else if (c_dialect_cxx () && type_code
== ARRAY_TYPE
5230 && !COMPLETE_TYPE_P (TREE_TYPE (type
)))
5233 error_at (loc
, "invalid application of %qs to array type %qT of "
5234 "incomplete element type", op_name
, type
);
5235 return error_mark_node
;
5240 /* Convert in case a char is more than one unit. */
5241 value
= size_binop_loc (loc
, CEIL_DIV_EXPR
, TYPE_SIZE_UNIT (type
),
5242 size_int (TYPE_PRECISION (char_type_node
)
5244 else if (min_alignof
)
5245 value
= size_int (min_align_of_type (type
));
5247 value
= size_int (TYPE_ALIGN_UNIT (type
));
5250 if (is_sizeof
&& (TREE_CODE (type
) == ARRAY_TYPE
)
5251 && upc_shared_type_p (type
)
5252 && TYPE_HAS_THREADS_FACTOR (type
))
5254 const tree n_threads
= convert (sizetype
, upc_num_threads ());
5255 value
= size_binop (MULT_EXPR
, value
, n_threads
);
5258 /* VALUE will have the middle-end integer type sizetype.
5259 However, we should really return a value of type `size_t',
5260 which is just a typedef for an ordinary integer type. */
5261 value
= fold_convert_loc (loc
, size_type_node
, value
);
5266 /* Implement the __alignof keyword: Return the minimum required
5267 alignment of EXPR, measured in bytes. For VAR_DECLs,
5268 FUNCTION_DECLs and FIELD_DECLs return DECL_ALIGN (which can be set
5269 from an "aligned" __attribute__ specification). LOC is the
5270 location of the ALIGNOF operator. */
5273 c_alignof_expr (location_t loc
, tree expr
)
5277 if (VAR_OR_FUNCTION_DECL_P (expr
))
5278 t
= size_int (DECL_ALIGN_UNIT (expr
));
5280 else if (TREE_CODE (expr
) == COMPONENT_REF
5281 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
, 1)))
5283 error_at (loc
, "%<__alignof%> applied to a bit-field");
5286 else if (TREE_CODE (expr
) == COMPONENT_REF
5287 && TREE_CODE (TREE_OPERAND (expr
, 1)) == FIELD_DECL
)
5288 t
= size_int (DECL_ALIGN_UNIT (TREE_OPERAND (expr
, 1)));
5290 else if (TREE_CODE (expr
) == INDIRECT_REF
)
5292 tree t
= TREE_OPERAND (expr
, 0);
5294 int bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
5296 while (CONVERT_EXPR_P (t
)
5297 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
5301 t
= TREE_OPERAND (t
, 0);
5302 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
5303 if (thisalign
> bestalign
)
5304 best
= t
, bestalign
= thisalign
;
5306 return c_alignof (loc
, TREE_TYPE (TREE_TYPE (best
)));
5309 return c_alignof (loc
, TREE_TYPE (expr
));
5311 return fold_convert_loc (loc
, size_type_node
, t
);
5314 /* Handle C and C++ default attributes. */
5316 enum built_in_attribute
5318 #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
5319 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
5320 #define DEF_ATTR_STRING(ENUM, VALUE) ENUM,
5321 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
5322 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
5323 #include "builtin-attrs.def"
5324 #undef DEF_ATTR_NULL_TREE
5326 #undef DEF_ATTR_STRING
5327 #undef DEF_ATTR_IDENT
5328 #undef DEF_ATTR_TREE_LIST
5332 static GTY(()) tree built_in_attributes
[(int) ATTR_LAST
];
5334 static void c_init_attributes (void);
5338 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
5339 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
5340 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
5341 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
5342 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
5343 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
5344 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
5345 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5347 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5349 #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5350 ARG6, ARG7, ARG8) NAME,
5351 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
5352 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
5353 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
5354 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
5355 #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
5356 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5358 #define DEF_FUNCTION_TYPE_VAR_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5360 #define DEF_FUNCTION_TYPE_VAR_11(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5361 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) NAME,
5362 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
5363 #include "builtin-types.def"
5364 #undef DEF_PRIMITIVE_TYPE
5365 #undef DEF_FUNCTION_TYPE_0
5366 #undef DEF_FUNCTION_TYPE_1
5367 #undef DEF_FUNCTION_TYPE_2
5368 #undef DEF_FUNCTION_TYPE_3
5369 #undef DEF_FUNCTION_TYPE_4
5370 #undef DEF_FUNCTION_TYPE_5
5371 #undef DEF_FUNCTION_TYPE_6
5372 #undef DEF_FUNCTION_TYPE_7
5373 #undef DEF_FUNCTION_TYPE_8
5374 #undef DEF_FUNCTION_TYPE_VAR_0
5375 #undef DEF_FUNCTION_TYPE_VAR_1
5376 #undef DEF_FUNCTION_TYPE_VAR_2
5377 #undef DEF_FUNCTION_TYPE_VAR_3
5378 #undef DEF_FUNCTION_TYPE_VAR_4
5379 #undef DEF_FUNCTION_TYPE_VAR_5
5380 #undef DEF_FUNCTION_TYPE_VAR_7
5381 #undef DEF_FUNCTION_TYPE_VAR_11
5382 #undef DEF_POINTER_TYPE
5386 typedef enum c_builtin_type builtin_type
;
5388 /* A temporary array for c_common_nodes_and_builtins. Used in
5389 communication with def_fn_type. */
5390 static tree builtin_types
[(int) BT_LAST
+ 1];
5392 /* A helper function for c_common_nodes_and_builtins. Build function type
5393 for DEF with return type RET and N arguments. If VAR is true, then the
5394 function should be variadic after those N arguments.
5396 Takes special care not to ICE if any of the types involved are
5397 error_mark_node, which indicates that said type is not in fact available
5398 (see builtin_type_for_size). In which case the function type as a whole
5399 should be error_mark_node. */
5402 def_fn_type (builtin_type def
, builtin_type ret
, bool var
, int n
, ...)
5405 tree
*args
= XALLOCAVEC (tree
, n
);
5410 for (i
= 0; i
< n
; ++i
)
5412 builtin_type a
= (builtin_type
) va_arg (list
, int);
5413 t
= builtin_types
[a
];
5414 if (t
== error_mark_node
)
5419 t
= builtin_types
[ret
];
5420 if (t
== error_mark_node
)
5423 t
= build_varargs_function_type_array (t
, n
, args
);
5425 t
= build_function_type_array (t
, n
, args
);
5428 builtin_types
[def
] = t
;
5432 /* Build builtin functions common to both C and C++ language
5436 c_define_builtins (tree va_list_ref_type_node
, tree va_list_arg_type_node
)
5438 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
5439 builtin_types[ENUM] = VALUE;
5440 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
5441 def_fn_type (ENUM, RETURN, 0, 0);
5442 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
5443 def_fn_type (ENUM, RETURN, 0, 1, ARG1);
5444 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
5445 def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
5446 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
5447 def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
5448 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
5449 def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
5450 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5451 def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
5452 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5454 def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
5455 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5457 def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
5458 #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5460 def_fn_type (ENUM, RETURN, 0, 8, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
5462 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
5463 def_fn_type (ENUM, RETURN, 1, 0);
5464 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
5465 def_fn_type (ENUM, RETURN, 1, 1, ARG1);
5466 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
5467 def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
5468 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
5469 def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
5470 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
5471 def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
5472 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
5473 def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
5474 #define DEF_FUNCTION_TYPE_VAR_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5476 def_fn_type (ENUM, RETURN, 1, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
5477 #define DEF_FUNCTION_TYPE_VAR_11(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
5478 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) \
5479 def_fn_type (ENUM, RETURN, 1, 11, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
5480 ARG7, ARG8, ARG9, ARG10, ARG11);
5481 #define DEF_POINTER_TYPE(ENUM, TYPE) \
5482 builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
5484 #include "builtin-types.def"
5486 #undef DEF_PRIMITIVE_TYPE
5487 #undef DEF_FUNCTION_TYPE_0
5488 #undef DEF_FUNCTION_TYPE_1
5489 #undef DEF_FUNCTION_TYPE_2
5490 #undef DEF_FUNCTION_TYPE_3
5491 #undef DEF_FUNCTION_TYPE_4
5492 #undef DEF_FUNCTION_TYPE_5
5493 #undef DEF_FUNCTION_TYPE_6
5494 #undef DEF_FUNCTION_TYPE_7
5495 #undef DEF_FUNCTION_TYPE_8
5496 #undef DEF_FUNCTION_TYPE_VAR_0
5497 #undef DEF_FUNCTION_TYPE_VAR_1
5498 #undef DEF_FUNCTION_TYPE_VAR_2
5499 #undef DEF_FUNCTION_TYPE_VAR_3
5500 #undef DEF_FUNCTION_TYPE_VAR_4
5501 #undef DEF_FUNCTION_TYPE_VAR_5
5502 #undef DEF_FUNCTION_TYPE_VAR_7
5503 #undef DEF_FUNCTION_TYPE_VAR_11
5504 #undef DEF_POINTER_TYPE
5505 builtin_types
[(int) BT_LAST
] = NULL_TREE
;
5507 c_init_attributes ();
5509 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P, \
5510 NONANSI_P, ATTRS, IMPLICIT, COND) \
5512 def_builtin_1 (ENUM, NAME, CLASS, \
5513 builtin_types[(int) TYPE], \
5514 builtin_types[(int) LIBTYPE], \
5515 BOTH_P, FALLBACK_P, NONANSI_P, \
5516 built_in_attributes[(int) ATTRS], IMPLICIT);
5517 #include "builtins.def"
5520 targetm
.init_builtins ();
5522 build_common_builtin_nodes ();
5525 cilk_init_builtins ();
5528 /* Like get_identifier, but avoid warnings about null arguments when
5529 the argument may be NULL for targets where GCC lacks stdint.h type
5533 c_get_ident (const char *id
)
5535 return get_identifier (id
);
5538 /* Build tree nodes and builtin functions common to both C and C++ language
5542 c_common_nodes_and_builtins (void)
5544 int char16_type_size
;
5545 int char32_type_size
;
5546 int wchar_type_size
;
5547 tree array_domain_type
;
5548 tree va_list_ref_type_node
;
5549 tree va_list_arg_type_node
;
5552 build_common_tree_nodes (flag_signed_char
, flag_short_double
);
5554 /* Define `int' and `char' first so that dbx will output them first. */
5555 record_builtin_type (RID_INT
, NULL
, integer_type_node
);
5556 record_builtin_type (RID_CHAR
, "char", char_type_node
);
5558 /* `signed' is the same as `int'. FIXME: the declarations of "signed",
5559 "unsigned long", "long long unsigned" and "unsigned short" were in C++
5560 but not C. Are the conditionals here needed? */
5561 if (c_dialect_cxx ())
5562 record_builtin_type (RID_SIGNED
, NULL
, integer_type_node
);
5563 record_builtin_type (RID_LONG
, "long int", long_integer_type_node
);
5564 record_builtin_type (RID_UNSIGNED
, "unsigned int", unsigned_type_node
);
5565 record_builtin_type (RID_MAX
, "long unsigned int",
5566 long_unsigned_type_node
);
5568 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
5572 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
5573 record_builtin_type ((enum rid
)(RID_FIRST_INT_N
+ i
), name
,
5574 int_n_trees
[i
].signed_type
);
5575 sprintf (name
, "__int%d unsigned", int_n_data
[i
].bitsize
);
5576 record_builtin_type (RID_MAX
, name
, int_n_trees
[i
].unsigned_type
);
5579 if (c_dialect_cxx ())
5580 record_builtin_type (RID_MAX
, "unsigned long", long_unsigned_type_node
);
5581 record_builtin_type (RID_MAX
, "long long int",
5582 long_long_integer_type_node
);
5583 record_builtin_type (RID_MAX
, "long long unsigned int",
5584 long_long_unsigned_type_node
);
5585 if (c_dialect_cxx ())
5586 record_builtin_type (RID_MAX
, "long long unsigned",
5587 long_long_unsigned_type_node
);
5588 record_builtin_type (RID_SHORT
, "short int", short_integer_type_node
);
5589 record_builtin_type (RID_MAX
, "short unsigned int",
5590 short_unsigned_type_node
);
5591 if (c_dialect_cxx ())
5592 record_builtin_type (RID_MAX
, "unsigned short",
5593 short_unsigned_type_node
);
5595 /* Define both `signed char' and `unsigned char'. */
5596 record_builtin_type (RID_MAX
, "signed char", signed_char_type_node
);
5597 record_builtin_type (RID_MAX
, "unsigned char", unsigned_char_type_node
);
5599 /* These are types that c_common_type_for_size and
5600 c_common_type_for_mode use. */
5601 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5602 TYPE_DECL
, NULL_TREE
,
5604 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5605 TYPE_DECL
, NULL_TREE
,
5607 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5608 TYPE_DECL
, NULL_TREE
,
5610 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5611 TYPE_DECL
, NULL_TREE
,
5613 #if HOST_BITS_PER_WIDE_INT >= 64
5614 /* Note that this is different than the __int128 type that's part of
5615 the generic __intN support. */
5616 if (targetm
.scalar_mode_supported_p (TImode
))
5617 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5619 get_identifier ("__int128_t"),
5622 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5623 TYPE_DECL
, NULL_TREE
,
5624 unsigned_intQI_type_node
));
5625 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5626 TYPE_DECL
, NULL_TREE
,
5627 unsigned_intHI_type_node
));
5628 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5629 TYPE_DECL
, NULL_TREE
,
5630 unsigned_intSI_type_node
));
5631 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5632 TYPE_DECL
, NULL_TREE
,
5633 unsigned_intDI_type_node
));
5634 #if HOST_BITS_PER_WIDE_INT >= 64
5635 if (targetm
.scalar_mode_supported_p (TImode
))
5636 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5638 get_identifier ("__uint128_t"),
5639 unsigned_intTI_type_node
));
5642 /* Create the widest literal types. */
5643 widest_integer_literal_type_node
5644 = make_signed_type (HOST_BITS_PER_WIDE_INT
* 2);
5645 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5646 TYPE_DECL
, NULL_TREE
,
5647 widest_integer_literal_type_node
));
5649 widest_unsigned_literal_type_node
5650 = make_unsigned_type (HOST_BITS_PER_WIDE_INT
* 2);
5651 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5652 TYPE_DECL
, NULL_TREE
,
5653 widest_unsigned_literal_type_node
));
5655 signed_size_type_node
= c_common_signed_type (size_type_node
);
5658 TREE_TYPE (identifier_global_value (get_identifier (PID_TYPE
)));
5660 record_builtin_type (RID_FLOAT
, NULL
, float_type_node
);
5661 record_builtin_type (RID_DOUBLE
, NULL
, double_type_node
);
5662 record_builtin_type (RID_MAX
, "long double", long_double_type_node
);
5664 /* Only supported decimal floating point extension if the target
5665 actually supports underlying modes. */
5666 if (targetm
.scalar_mode_supported_p (SDmode
)
5667 && targetm
.scalar_mode_supported_p (DDmode
)
5668 && targetm
.scalar_mode_supported_p (TDmode
))
5670 record_builtin_type (RID_DFLOAT32
, NULL
, dfloat32_type_node
);
5671 record_builtin_type (RID_DFLOAT64
, NULL
, dfloat64_type_node
);
5672 record_builtin_type (RID_DFLOAT128
, NULL
, dfloat128_type_node
);
5675 if (targetm
.fixed_point_supported_p ())
5677 record_builtin_type (RID_MAX
, "short _Fract", short_fract_type_node
);
5678 record_builtin_type (RID_FRACT
, NULL
, fract_type_node
);
5679 record_builtin_type (RID_MAX
, "long _Fract", long_fract_type_node
);
5680 record_builtin_type (RID_MAX
, "long long _Fract",
5681 long_long_fract_type_node
);
5682 record_builtin_type (RID_MAX
, "unsigned short _Fract",
5683 unsigned_short_fract_type_node
);
5684 record_builtin_type (RID_MAX
, "unsigned _Fract",
5685 unsigned_fract_type_node
);
5686 record_builtin_type (RID_MAX
, "unsigned long _Fract",
5687 unsigned_long_fract_type_node
);
5688 record_builtin_type (RID_MAX
, "unsigned long long _Fract",
5689 unsigned_long_long_fract_type_node
);
5690 record_builtin_type (RID_MAX
, "_Sat short _Fract",
5691 sat_short_fract_type_node
);
5692 record_builtin_type (RID_MAX
, "_Sat _Fract", sat_fract_type_node
);
5693 record_builtin_type (RID_MAX
, "_Sat long _Fract",
5694 sat_long_fract_type_node
);
5695 record_builtin_type (RID_MAX
, "_Sat long long _Fract",
5696 sat_long_long_fract_type_node
);
5697 record_builtin_type (RID_MAX
, "_Sat unsigned short _Fract",
5698 sat_unsigned_short_fract_type_node
);
5699 record_builtin_type (RID_MAX
, "_Sat unsigned _Fract",
5700 sat_unsigned_fract_type_node
);
5701 record_builtin_type (RID_MAX
, "_Sat unsigned long _Fract",
5702 sat_unsigned_long_fract_type_node
);
5703 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Fract",
5704 sat_unsigned_long_long_fract_type_node
);
5705 record_builtin_type (RID_MAX
, "short _Accum", short_accum_type_node
);
5706 record_builtin_type (RID_ACCUM
, NULL
, accum_type_node
);
5707 record_builtin_type (RID_MAX
, "long _Accum", long_accum_type_node
);
5708 record_builtin_type (RID_MAX
, "long long _Accum",
5709 long_long_accum_type_node
);
5710 record_builtin_type (RID_MAX
, "unsigned short _Accum",
5711 unsigned_short_accum_type_node
);
5712 record_builtin_type (RID_MAX
, "unsigned _Accum",
5713 unsigned_accum_type_node
);
5714 record_builtin_type (RID_MAX
, "unsigned long _Accum",
5715 unsigned_long_accum_type_node
);
5716 record_builtin_type (RID_MAX
, "unsigned long long _Accum",
5717 unsigned_long_long_accum_type_node
);
5718 record_builtin_type (RID_MAX
, "_Sat short _Accum",
5719 sat_short_accum_type_node
);
5720 record_builtin_type (RID_MAX
, "_Sat _Accum", sat_accum_type_node
);
5721 record_builtin_type (RID_MAX
, "_Sat long _Accum",
5722 sat_long_accum_type_node
);
5723 record_builtin_type (RID_MAX
, "_Sat long long _Accum",
5724 sat_long_long_accum_type_node
);
5725 record_builtin_type (RID_MAX
, "_Sat unsigned short _Accum",
5726 sat_unsigned_short_accum_type_node
);
5727 record_builtin_type (RID_MAX
, "_Sat unsigned _Accum",
5728 sat_unsigned_accum_type_node
);
5729 record_builtin_type (RID_MAX
, "_Sat unsigned long _Accum",
5730 sat_unsigned_long_accum_type_node
);
5731 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Accum",
5732 sat_unsigned_long_long_accum_type_node
);
5736 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5738 get_identifier ("complex int"),
5739 complex_integer_type_node
));
5740 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5742 get_identifier ("complex float"),
5743 complex_float_type_node
));
5744 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5746 get_identifier ("complex double"),
5747 complex_double_type_node
));
5748 lang_hooks
.decls
.pushdecl
5749 (build_decl (UNKNOWN_LOCATION
,
5750 TYPE_DECL
, get_identifier ("complex long double"),
5751 complex_long_double_type_node
));
5753 if (c_dialect_cxx ())
5754 /* For C++, make fileptr_type_node a distinct void * type until
5755 FILE type is defined. */
5756 fileptr_type_node
= build_variant_type_copy (ptr_type_node
);
5758 record_builtin_type (RID_VOID
, NULL
, void_type_node
);
5760 /* Set the TYPE_NAME for any variants that were built before
5761 record_builtin_type gave names to the built-in types. */
5763 tree void_name
= TYPE_NAME (void_type_node
);
5764 TYPE_NAME (void_type_node
) = NULL_TREE
;
5765 TYPE_NAME (build_qualified_type (void_type_node
, TYPE_QUAL_CONST
))
5767 TYPE_NAME (void_type_node
) = void_name
;
5770 void_list_node
= build_void_list_node ();
5772 /* Make a type to be the domain of a few array types
5773 whose domains don't really matter.
5774 200 is small enough that it always fits in size_t
5775 and large enough that it can hold most function names for the
5776 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
5777 array_domain_type
= build_index_type (size_int (200));
5779 /* Make a type for arrays of characters.
5780 With luck nothing will ever really depend on the length of this
5782 char_array_type_node
5783 = build_array_type (char_type_node
, array_domain_type
);
5785 string_type_node
= build_pointer_type (char_type_node
);
5786 const_string_type_node
5787 = build_pointer_type (build_qualified_type
5788 (char_type_node
, TYPE_QUAL_CONST
));
5790 /* This is special for C++ so functions can be overloaded. */
5791 wchar_type_node
= get_identifier (MODIFIED_WCHAR_TYPE
);
5792 wchar_type_node
= TREE_TYPE (identifier_global_value (wchar_type_node
));
5793 wchar_type_size
= TYPE_PRECISION (wchar_type_node
);
5794 underlying_wchar_type_node
= wchar_type_node
;
5795 if (c_dialect_cxx ())
5797 if (TYPE_UNSIGNED (wchar_type_node
))
5798 wchar_type_node
= make_unsigned_type (wchar_type_size
);
5800 wchar_type_node
= make_signed_type (wchar_type_size
);
5801 record_builtin_type (RID_WCHAR
, "wchar_t", wchar_type_node
);
5804 /* This is for wide string constants. */
5805 wchar_array_type_node
5806 = build_array_type (wchar_type_node
, array_domain_type
);
5808 /* Define 'char16_t'. */
5809 char16_type_node
= get_identifier (CHAR16_TYPE
);
5810 char16_type_node
= TREE_TYPE (identifier_global_value (char16_type_node
));
5811 char16_type_size
= TYPE_PRECISION (char16_type_node
);
5812 if (c_dialect_cxx ())
5814 char16_type_node
= make_unsigned_type (char16_type_size
);
5816 if (cxx_dialect
>= cxx11
)
5817 record_builtin_type (RID_CHAR16
, "char16_t", char16_type_node
);
5820 /* This is for UTF-16 string constants. */
5821 char16_array_type_node
5822 = build_array_type (char16_type_node
, array_domain_type
);
5824 /* Define 'char32_t'. */
5825 char32_type_node
= get_identifier (CHAR32_TYPE
);
5826 char32_type_node
= TREE_TYPE (identifier_global_value (char32_type_node
));
5827 char32_type_size
= TYPE_PRECISION (char32_type_node
);
5828 if (c_dialect_cxx ())
5830 char32_type_node
= make_unsigned_type (char32_type_size
);
5832 if (cxx_dialect
>= cxx11
)
5833 record_builtin_type (RID_CHAR32
, "char32_t", char32_type_node
);
5836 /* This is for UTF-32 string constants. */
5837 char32_array_type_node
5838 = build_array_type (char32_type_node
, array_domain_type
);
5841 TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE
)));
5844 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE
)));
5846 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE
)));
5848 if (SIG_ATOMIC_TYPE
)
5849 sig_atomic_type_node
=
5850 TREE_TYPE (identifier_global_value (c_get_ident (SIG_ATOMIC_TYPE
)));
5853 TREE_TYPE (identifier_global_value (c_get_ident (INT8_TYPE
)));
5856 TREE_TYPE (identifier_global_value (c_get_ident (INT16_TYPE
)));
5859 TREE_TYPE (identifier_global_value (c_get_ident (INT32_TYPE
)));
5862 TREE_TYPE (identifier_global_value (c_get_ident (INT64_TYPE
)));
5865 TREE_TYPE (identifier_global_value (c_get_ident (UINT8_TYPE
)));
5867 c_uint16_type_node
= uint16_type_node
=
5868 TREE_TYPE (identifier_global_value (c_get_ident (UINT16_TYPE
)));
5870 c_uint32_type_node
= uint32_type_node
=
5871 TREE_TYPE (identifier_global_value (c_get_ident (UINT32_TYPE
)));
5873 c_uint64_type_node
= uint64_type_node
=
5874 TREE_TYPE (identifier_global_value (c_get_ident (UINT64_TYPE
)));
5875 if (INT_LEAST8_TYPE
)
5876 int_least8_type_node
=
5877 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST8_TYPE
)));
5878 if (INT_LEAST16_TYPE
)
5879 int_least16_type_node
=
5880 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST16_TYPE
)));
5881 if (INT_LEAST32_TYPE
)
5882 int_least32_type_node
=
5883 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST32_TYPE
)));
5884 if (INT_LEAST64_TYPE
)
5885 int_least64_type_node
=
5886 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST64_TYPE
)));
5887 if (UINT_LEAST8_TYPE
)
5888 uint_least8_type_node
=
5889 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST8_TYPE
)));
5890 if (UINT_LEAST16_TYPE
)
5891 uint_least16_type_node
=
5892 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST16_TYPE
)));
5893 if (UINT_LEAST32_TYPE
)
5894 uint_least32_type_node
=
5895 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST32_TYPE
)));
5896 if (UINT_LEAST64_TYPE
)
5897 uint_least64_type_node
=
5898 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST64_TYPE
)));
5900 int_fast8_type_node
=
5901 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST8_TYPE
)));
5902 if (INT_FAST16_TYPE
)
5903 int_fast16_type_node
=
5904 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST16_TYPE
)));
5905 if (INT_FAST32_TYPE
)
5906 int_fast32_type_node
=
5907 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST32_TYPE
)));
5908 if (INT_FAST64_TYPE
)
5909 int_fast64_type_node
=
5910 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST64_TYPE
)));
5911 if (UINT_FAST8_TYPE
)
5912 uint_fast8_type_node
=
5913 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST8_TYPE
)));
5914 if (UINT_FAST16_TYPE
)
5915 uint_fast16_type_node
=
5916 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST16_TYPE
)));
5917 if (UINT_FAST32_TYPE
)
5918 uint_fast32_type_node
=
5919 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST32_TYPE
)));
5920 if (UINT_FAST64_TYPE
)
5921 uint_fast64_type_node
=
5922 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST64_TYPE
)));
5925 TREE_TYPE (identifier_global_value (c_get_ident (INTPTR_TYPE
)));
5928 TREE_TYPE (identifier_global_value (c_get_ident (UINTPTR_TYPE
)));
5930 default_function_type
5931 = build_varargs_function_type_list (integer_type_node
, NULL_TREE
);
5933 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE
)));
5934 unsigned_ptrdiff_type_node
= c_common_unsigned_type (ptrdiff_type_node
);
5936 lang_hooks
.decls
.pushdecl
5937 (build_decl (UNKNOWN_LOCATION
,
5938 TYPE_DECL
, get_identifier ("__builtin_va_list"),
5939 va_list_type_node
));
5940 if (targetm
.enum_va_list_p
)
5946 for (l
= 0; targetm
.enum_va_list_p (l
, &pname
, &ptype
); ++l
)
5948 lang_hooks
.decls
.pushdecl
5949 (build_decl (UNKNOWN_LOCATION
,
5950 TYPE_DECL
, get_identifier (pname
),
5956 if (TREE_CODE (va_list_type_node
) == ARRAY_TYPE
)
5958 va_list_arg_type_node
= va_list_ref_type_node
=
5959 build_pointer_type (TREE_TYPE (va_list_type_node
));
5963 va_list_arg_type_node
= va_list_type_node
;
5964 va_list_ref_type_node
= build_reference_type (va_list_type_node
);
5967 if (!flag_preprocess_only
)
5968 c_define_builtins (va_list_ref_type_node
, va_list_arg_type_node
);
5970 main_identifier_node
= get_identifier ("main");
5972 /* Create the built-in __null node. It is important that this is
5974 null_node
= make_int_cst (1, 1);
5975 TREE_TYPE (null_node
) = c_common_type_for_size (POINTER_SIZE
, 0);
5977 /* Since builtin_types isn't gc'ed, don't export these nodes. */
5978 memset (builtin_types
, 0, sizeof (builtin_types
));
5981 /* The number of named compound-literals generated thus far. */
5982 static GTY(()) int compound_literal_number
;
5984 /* Set DECL_NAME for DECL, a VAR_DECL for a compound-literal. */
5987 set_compound_literal_name (tree decl
)
5990 ASM_FORMAT_PRIVATE_NAME (name
, "__compound_literal",
5991 compound_literal_number
);
5992 compound_literal_number
++;
5993 DECL_NAME (decl
) = get_identifier (name
);
5997 build_va_arg (location_t loc
, tree expr
, tree type
)
5999 expr
= build1 (VA_ARG_EXPR
, type
, expr
);
6000 SET_EXPR_LOCATION (expr
, loc
);
6005 /* Linked list of disabled built-in functions. */
6007 typedef struct disabled_builtin
6010 struct disabled_builtin
*next
;
6012 static disabled_builtin
*disabled_builtins
= NULL
;
6014 static bool builtin_function_disabled_p (const char *);
6016 /* Disable a built-in function specified by -fno-builtin-NAME. If NAME
6017 begins with "__builtin_", give an error. */
6020 disable_builtin_function (const char *name
)
6022 if (strncmp (name
, "__builtin_", strlen ("__builtin_")) == 0)
6023 error ("cannot disable built-in function %qs", name
);
6026 disabled_builtin
*new_disabled_builtin
= XNEW (disabled_builtin
);
6027 new_disabled_builtin
->name
= name
;
6028 new_disabled_builtin
->next
= disabled_builtins
;
6029 disabled_builtins
= new_disabled_builtin
;
6034 /* Return true if the built-in function NAME has been disabled, false
6038 builtin_function_disabled_p (const char *name
)
6040 disabled_builtin
*p
;
6041 for (p
= disabled_builtins
; p
!= NULL
; p
= p
->next
)
6043 if (strcmp (name
, p
->name
) == 0)
6050 /* Worker for DEF_BUILTIN.
6051 Possibly define a builtin function with one or two names.
6052 Does not declare a non-__builtin_ function if flag_no_builtin, or if
6053 nonansi_p and flag_no_nonansi_builtin. */
6056 def_builtin_1 (enum built_in_function fncode
,
6058 enum built_in_class fnclass
,
6059 tree fntype
, tree libtype
,
6060 bool both_p
, bool fallback_p
, bool nonansi_p
,
6061 tree fnattrs
, bool implicit_p
)
6064 const char *libname
;
6066 if (fntype
== error_mark_node
)
6069 gcc_assert ((!both_p
&& !fallback_p
)
6070 || !strncmp (name
, "__builtin_",
6071 strlen ("__builtin_")));
6073 libname
= name
+ strlen ("__builtin_");
6074 decl
= add_builtin_function (name
, fntype
, fncode
, fnclass
,
6075 (fallback_p
? libname
: NULL
),
6078 set_builtin_decl (fncode
, decl
, implicit_p
);
6081 && !flag_no_builtin
&& !builtin_function_disabled_p (libname
)
6082 && !(nonansi_p
&& flag_no_nonansi_builtin
))
6083 add_builtin_function (libname
, libtype
, fncode
, fnclass
,
6087 /* Nonzero if the type T promotes to int. This is (nearly) the
6088 integral promotions defined in ISO C99 6.3.1.1/2. */
6091 c_promoting_integer_type_p (const_tree t
)
6093 switch (TREE_CODE (t
))
6096 return (TYPE_MAIN_VARIANT (t
) == char_type_node
6097 || TYPE_MAIN_VARIANT (t
) == signed_char_type_node
6098 || TYPE_MAIN_VARIANT (t
) == unsigned_char_type_node
6099 || TYPE_MAIN_VARIANT (t
) == short_integer_type_node
6100 || TYPE_MAIN_VARIANT (t
) == short_unsigned_type_node
6101 || TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
));
6104 /* ??? Technically all enumerations not larger than an int
6105 promote to an int. But this is used along code paths
6106 that only want to notice a size change. */
6107 return TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
);
6117 /* Return 1 if PARMS specifies a fixed number of parameters
6118 and none of their types is affected by default promotions. */
6121 self_promoting_args_p (const_tree parms
)
6124 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
6126 tree type
= TREE_VALUE (t
);
6128 if (type
== error_mark_node
)
6131 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
6137 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
6140 if (c_promoting_integer_type_p (type
))
6146 /* Recursively remove any '*' or '&' operator from TYPE. */
6148 strip_pointer_operator (tree t
)
6150 while (POINTER_TYPE_P (t
))
6155 /* Recursively remove pointer or array type from TYPE. */
6157 strip_pointer_or_array_types (tree t
)
6159 while (TREE_CODE (t
) == ARRAY_TYPE
|| POINTER_TYPE_P (t
))
6164 /* Used to compare case labels. K1 and K2 are actually tree nodes
6165 representing case labels, or NULL_TREE for a `default' label.
6166 Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after
6167 K2, and 0 if K1 and K2 are equal. */
6170 case_compare (splay_tree_key k1
, splay_tree_key k2
)
6172 /* Consider a NULL key (such as arises with a `default' label) to be
6173 smaller than anything else. */
6179 return tree_int_cst_compare ((tree
) k1
, (tree
) k2
);
6182 /* Process a case label, located at LOC, for the range LOW_VALUE
6183 ... HIGH_VALUE. If LOW_VALUE and HIGH_VALUE are both NULL_TREE
6184 then this case label is actually a `default' label. If only
6185 HIGH_VALUE is NULL_TREE, then case label was declared using the
6186 usual C/C++ syntax, rather than the GNU case range extension.
6187 CASES is a tree containing all the case ranges processed so far;
6188 COND is the condition for the switch-statement itself. Returns the
6189 CASE_LABEL_EXPR created, or ERROR_MARK_NODE if no CASE_LABEL_EXPR
6193 c_add_case_label (location_t loc
, splay_tree cases
, tree cond
, tree orig_type
,
6194 tree low_value
, tree high_value
)
6199 splay_tree_node node
;
6201 /* Create the LABEL_DECL itself. */
6202 label
= create_artificial_label (loc
);
6204 /* If there was an error processing the switch condition, bail now
6205 before we get more confused. */
6206 if (!cond
|| cond
== error_mark_node
)
6209 if ((low_value
&& TREE_TYPE (low_value
)
6210 && POINTER_TYPE_P (TREE_TYPE (low_value
)))
6211 || (high_value
&& TREE_TYPE (high_value
)
6212 && POINTER_TYPE_P (TREE_TYPE (high_value
))))
6214 error_at (loc
, "pointers are not permitted as case values");
6218 /* Case ranges are a GNU extension. */
6220 pedwarn (loc
, OPT_Wpedantic
,
6221 "range expressions in switch statements are non-standard");
6223 type
= TREE_TYPE (cond
);
6226 low_value
= check_case_value (loc
, low_value
);
6227 low_value
= convert_and_check (loc
, type
, low_value
);
6228 if (low_value
== error_mark_node
)
6233 high_value
= check_case_value (loc
, high_value
);
6234 high_value
= convert_and_check (loc
, type
, high_value
);
6235 if (high_value
== error_mark_node
)
6239 if (low_value
&& high_value
)
6241 /* If the LOW_VALUE and HIGH_VALUE are the same, then this isn't
6242 really a case range, even though it was written that way.
6243 Remove the HIGH_VALUE to simplify later processing. */
6244 if (tree_int_cst_equal (low_value
, high_value
))
6245 high_value
= NULL_TREE
;
6246 else if (!tree_int_cst_lt (low_value
, high_value
))
6247 warning_at (loc
, 0, "empty range specified");
6250 /* See if the case is in range of the type of the original testing
6251 expression. If both low_value and high_value are out of range,
6252 don't insert the case label and return NULL_TREE. */
6254 && !check_case_bounds (loc
, type
, orig_type
,
6255 &low_value
, high_value
? &high_value
: NULL
))
6258 /* Look up the LOW_VALUE in the table of case labels we already
6260 node
= splay_tree_lookup (cases
, (splay_tree_key
) low_value
);
6261 /* If there was not an exact match, check for overlapping ranges.
6262 There's no need to do this if there's no LOW_VALUE or HIGH_VALUE;
6263 that's a `default' label and the only overlap is an exact match. */
6264 if (!node
&& (low_value
|| high_value
))
6266 splay_tree_node low_bound
;
6267 splay_tree_node high_bound
;
6269 /* Even though there wasn't an exact match, there might be an
6270 overlap between this case range and another case range.
6271 Since we've (inductively) not allowed any overlapping case
6272 ranges, we simply need to find the greatest low case label
6273 that is smaller that LOW_VALUE, and the smallest low case
6274 label that is greater than LOW_VALUE. If there is an overlap
6275 it will occur in one of these two ranges. */
6276 low_bound
= splay_tree_predecessor (cases
,
6277 (splay_tree_key
) low_value
);
6278 high_bound
= splay_tree_successor (cases
,
6279 (splay_tree_key
) low_value
);
6281 /* Check to see if the LOW_BOUND overlaps. It is smaller than
6282 the LOW_VALUE, so there is no need to check unless the
6283 LOW_BOUND is in fact itself a case range. */
6285 && CASE_HIGH ((tree
) low_bound
->value
)
6286 && tree_int_cst_compare (CASE_HIGH ((tree
) low_bound
->value
),
6289 /* Check to see if the HIGH_BOUND overlaps. The low end of that
6290 range is bigger than the low end of the current range, so we
6291 are only interested if the current range is a real range, and
6292 not an ordinary case label. */
6295 && (tree_int_cst_compare ((tree
) high_bound
->key
,
6300 /* If there was an overlap, issue an error. */
6303 tree duplicate
= CASE_LABEL ((tree
) node
->value
);
6307 error_at (loc
, "duplicate (or overlapping) case value");
6308 error_at (DECL_SOURCE_LOCATION (duplicate
),
6309 "this is the first entry overlapping that value");
6313 error_at (loc
, "duplicate case value") ;
6314 error_at (DECL_SOURCE_LOCATION (duplicate
), "previously used here");
6318 error_at (loc
, "multiple default labels in one switch");
6319 error_at (DECL_SOURCE_LOCATION (duplicate
),
6320 "this is the first default label");
6325 /* Add a CASE_LABEL to the statement-tree. */
6326 case_label
= add_stmt (build_case_label (low_value
, high_value
, label
));
6327 /* Register this case label in the splay tree. */
6328 splay_tree_insert (cases
,
6329 (splay_tree_key
) low_value
,
6330 (splay_tree_value
) case_label
);
6335 /* Add a label so that the back-end doesn't think that the beginning of
6336 the switch is unreachable. Note that we do not add a case label, as
6337 that just leads to duplicates and thence to failure later on. */
6340 tree t
= create_artificial_label (loc
);
6341 add_stmt (build_stmt (loc
, LABEL_EXPR
, t
));
6343 return error_mark_node
;
6346 /* Subroutines of c_do_switch_warnings, called via splay_tree_foreach.
6347 Used to verify that case values match up with enumerator values. */
6350 match_case_to_enum_1 (tree key
, tree type
, tree label
)
6352 char buf
[WIDE_INT_PRINT_BUFFER_SIZE
];
6354 if (tree_fits_uhwi_p (key
))
6355 print_dec (key
, buf
, UNSIGNED
);
6356 else if (tree_fits_shwi_p (key
))
6357 print_dec (key
, buf
, SIGNED
);
6359 print_hex (key
, buf
);
6361 if (TYPE_NAME (type
) == 0)
6362 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
6363 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
6364 "case value %qs not in enumerated type",
6367 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
6368 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
6369 "case value %qs not in enumerated type %qT",
6373 /* Subroutine of c_do_switch_warnings, called via splay_tree_foreach.
6374 Used to verify that case values match up with enumerator values. */
6377 match_case_to_enum (splay_tree_node node
, void *data
)
6379 tree label
= (tree
) node
->value
;
6380 tree type
= (tree
) data
;
6382 /* Skip default case. */
6383 if (!CASE_LOW (label
))
6386 /* If CASE_LOW_SEEN is not set, that means CASE_LOW did not appear
6387 when we did our enum->case scan. Reset our scratch bit after. */
6388 if (!CASE_LOW_SEEN (label
))
6389 match_case_to_enum_1 (CASE_LOW (label
), type
, label
);
6391 CASE_LOW_SEEN (label
) = 0;
6393 /* If CASE_HIGH is non-null, we have a range. If CASE_HIGH_SEEN is
6394 not set, that means that CASE_HIGH did not appear when we did our
6395 enum->case scan. Reset our scratch bit after. */
6396 if (CASE_HIGH (label
))
6398 if (!CASE_HIGH_SEEN (label
))
6399 match_case_to_enum_1 (CASE_HIGH (label
), type
, label
);
6401 CASE_HIGH_SEEN (label
) = 0;
6407 /* Handle -Wswitch*. Called from the front end after parsing the
6408 switch construct. */
6409 /* ??? Should probably be somewhere generic, since other languages
6410 besides C and C++ would want this. At the moment, however, C/C++
6411 are the only tree-ssa languages that support enumerations at all,
6412 so the point is moot. */
6415 c_do_switch_warnings (splay_tree cases
, location_t switch_location
,
6416 tree type
, tree cond
)
6418 splay_tree_node default_node
;
6419 splay_tree_node node
;
6422 if (!warn_switch
&& !warn_switch_enum
&& !warn_switch_default
)
6425 default_node
= splay_tree_lookup (cases
, (splay_tree_key
) NULL
);
6427 warning_at (switch_location
, OPT_Wswitch_default
,
6428 "switch missing default case");
6430 /* From here on, we only care about about enumerated types. */
6431 if (!type
|| TREE_CODE (type
) != ENUMERAL_TYPE
)
6434 /* From here on, we only care about -Wswitch and -Wswitch-enum. */
6435 if (!warn_switch_enum
&& !warn_switch
)
6438 /* Check the cases. Warn about case values which are not members of
6439 the enumerated type. For -Wswitch-enum, or for -Wswitch when
6440 there is no default case, check that exactly all enumeration
6441 literals are covered by the cases. */
6443 /* Clearing COND if it is not an integer constant simplifies
6444 the tests inside the loop below. */
6445 if (TREE_CODE (cond
) != INTEGER_CST
)
6448 /* The time complexity here is O(N*lg(N)) worst case, but for the
6449 common case of monotonically increasing enumerators, it is
6450 O(N), since the nature of the splay tree will keep the next
6451 element adjacent to the root at all times. */
6453 for (chain
= TYPE_VALUES (type
); chain
; chain
= TREE_CHAIN (chain
))
6455 tree value
= TREE_VALUE (chain
);
6456 if (TREE_CODE (value
) == CONST_DECL
)
6457 value
= DECL_INITIAL (value
);
6458 node
= splay_tree_lookup (cases
, (splay_tree_key
) value
);
6461 /* Mark the CASE_LOW part of the case entry as seen. */
6462 tree label
= (tree
) node
->value
;
6463 CASE_LOW_SEEN (label
) = 1;
6467 /* Even though there wasn't an exact match, there might be a
6468 case range which includes the enumerator's value. */
6469 node
= splay_tree_predecessor (cases
, (splay_tree_key
) value
);
6470 if (node
&& CASE_HIGH ((tree
) node
->value
))
6472 tree label
= (tree
) node
->value
;
6473 int cmp
= tree_int_cst_compare (CASE_HIGH (label
), value
);
6476 /* If we match the upper bound exactly, mark the CASE_HIGH
6477 part of the case entry as seen. */
6479 CASE_HIGH_SEEN (label
) = 1;
6484 /* We've now determined that this enumerated literal isn't
6485 handled by the case labels of the switch statement. */
6487 /* If the switch expression is a constant, we only really care
6488 about whether that constant is handled by the switch. */
6489 if (cond
&& tree_int_cst_compare (cond
, value
))
6492 /* If there is a default_node, the only relevant option is
6493 Wswitch-enum. Otherwise, if both are enabled then we prefer
6494 to warn using -Wswitch because -Wswitch is enabled by -Wall
6495 while -Wswitch-enum is explicit. */
6496 warning_at (switch_location
,
6497 (default_node
|| !warn_switch
6500 "enumeration value %qE not handled in switch",
6501 TREE_PURPOSE (chain
));
6504 /* Warn if there are case expressions that don't correspond to
6505 enumerators. This can occur since C and C++ don't enforce
6506 type-checking of assignments to enumeration variables.
6508 The time complexity here is now always O(N) worst case, since
6509 we should have marked both the lower bound and upper bound of
6510 every disjoint case label, with CASE_LOW_SEEN and CASE_HIGH_SEEN
6511 above. This scan also resets those fields. */
6513 splay_tree_foreach (cases
, match_case_to_enum
, type
);
6516 /* Finish an expression taking the address of LABEL (an
6517 IDENTIFIER_NODE). Returns an expression for the address.
6519 LOC is the location for the expression returned. */
6522 finish_label_address_expr (tree label
, location_t loc
)
6526 pedwarn (input_location
, OPT_Wpedantic
, "taking the address of a label is non-standard");
6528 if (label
== error_mark_node
)
6529 return error_mark_node
;
6531 label
= lookup_label (label
);
6532 if (label
== NULL_TREE
)
6533 result
= null_pointer_node
;
6536 TREE_USED (label
) = 1;
6537 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
6538 /* The current function is not necessarily uninlinable.
6539 Computed gotos are incompatible with inlining, but the value
6540 here could be used only in a diagnostic, for example. */
6541 protected_set_expr_location (result
, loc
);
6548 /* Given a boolean expression ARG, return a tree representing an increment
6549 or decrement (as indicated by CODE) of ARG. The front end must check for
6550 invalid cases (e.g., decrement in C++). */
6552 boolean_increment (enum tree_code code
, tree arg
)
6555 tree true_res
= build_int_cst (TREE_TYPE (arg
), 1);
6557 arg
= stabilize_reference (arg
);
6560 case PREINCREMENT_EXPR
:
6561 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
6563 case POSTINCREMENT_EXPR
:
6564 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
6565 arg
= save_expr (arg
);
6566 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
6567 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
6569 case PREDECREMENT_EXPR
:
6570 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
6571 invert_truthvalue_loc (input_location
, arg
));
6573 case POSTDECREMENT_EXPR
:
6574 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
6575 invert_truthvalue_loc (input_location
, arg
));
6576 arg
= save_expr (arg
);
6577 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
6578 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
6583 TREE_SIDE_EFFECTS (val
) = 1;
6587 /* Built-in macros for stddef.h and stdint.h, that require macros
6588 defined in this file. */
6590 c_stddef_cpp_builtins(void)
6592 builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE
, 0);
6593 builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE
, 0);
6594 builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE
, 0);
6595 builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE
, 0);
6596 builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE
, 0);
6597 builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE
, 0);
6598 builtin_define_with_value ("__CHAR16_TYPE__", CHAR16_TYPE
, 0);
6599 builtin_define_with_value ("__CHAR32_TYPE__", CHAR32_TYPE
, 0);
6600 if (SIG_ATOMIC_TYPE
)
6601 builtin_define_with_value ("__SIG_ATOMIC_TYPE__", SIG_ATOMIC_TYPE
, 0);
6603 builtin_define_with_value ("__INT8_TYPE__", INT8_TYPE
, 0);
6605 builtin_define_with_value ("__INT16_TYPE__", INT16_TYPE
, 0);
6607 builtin_define_with_value ("__INT32_TYPE__", INT32_TYPE
, 0);
6609 builtin_define_with_value ("__INT64_TYPE__", INT64_TYPE
, 0);
6611 builtin_define_with_value ("__UINT8_TYPE__", UINT8_TYPE
, 0);
6613 builtin_define_with_value ("__UINT16_TYPE__", UINT16_TYPE
, 0);
6615 builtin_define_with_value ("__UINT32_TYPE__", UINT32_TYPE
, 0);
6617 builtin_define_with_value ("__UINT64_TYPE__", UINT64_TYPE
, 0);
6618 if (INT_LEAST8_TYPE
)
6619 builtin_define_with_value ("__INT_LEAST8_TYPE__", INT_LEAST8_TYPE
, 0);
6620 if (INT_LEAST16_TYPE
)
6621 builtin_define_with_value ("__INT_LEAST16_TYPE__", INT_LEAST16_TYPE
, 0);
6622 if (INT_LEAST32_TYPE
)
6623 builtin_define_with_value ("__INT_LEAST32_TYPE__", INT_LEAST32_TYPE
, 0);
6624 if (INT_LEAST64_TYPE
)
6625 builtin_define_with_value ("__INT_LEAST64_TYPE__", INT_LEAST64_TYPE
, 0);
6626 if (UINT_LEAST8_TYPE
)
6627 builtin_define_with_value ("__UINT_LEAST8_TYPE__", UINT_LEAST8_TYPE
, 0);
6628 if (UINT_LEAST16_TYPE
)
6629 builtin_define_with_value ("__UINT_LEAST16_TYPE__", UINT_LEAST16_TYPE
, 0);
6630 if (UINT_LEAST32_TYPE
)
6631 builtin_define_with_value ("__UINT_LEAST32_TYPE__", UINT_LEAST32_TYPE
, 0);
6632 if (UINT_LEAST64_TYPE
)
6633 builtin_define_with_value ("__UINT_LEAST64_TYPE__", UINT_LEAST64_TYPE
, 0);
6635 builtin_define_with_value ("__INT_FAST8_TYPE__", INT_FAST8_TYPE
, 0);
6636 if (INT_FAST16_TYPE
)
6637 builtin_define_with_value ("__INT_FAST16_TYPE__", INT_FAST16_TYPE
, 0);
6638 if (INT_FAST32_TYPE
)
6639 builtin_define_with_value ("__INT_FAST32_TYPE__", INT_FAST32_TYPE
, 0);
6640 if (INT_FAST64_TYPE
)
6641 builtin_define_with_value ("__INT_FAST64_TYPE__", INT_FAST64_TYPE
, 0);
6642 if (UINT_FAST8_TYPE
)
6643 builtin_define_with_value ("__UINT_FAST8_TYPE__", UINT_FAST8_TYPE
, 0);
6644 if (UINT_FAST16_TYPE
)
6645 builtin_define_with_value ("__UINT_FAST16_TYPE__", UINT_FAST16_TYPE
, 0);
6646 if (UINT_FAST32_TYPE
)
6647 builtin_define_with_value ("__UINT_FAST32_TYPE__", UINT_FAST32_TYPE
, 0);
6648 if (UINT_FAST64_TYPE
)
6649 builtin_define_with_value ("__UINT_FAST64_TYPE__", UINT_FAST64_TYPE
, 0);
6651 builtin_define_with_value ("__INTPTR_TYPE__", INTPTR_TYPE
, 0);
6653 builtin_define_with_value ("__UINTPTR_TYPE__", UINTPTR_TYPE
, 0);
6657 c_init_attributes (void)
6659 /* Fill in the built_in_attributes array. */
6660 #define DEF_ATTR_NULL_TREE(ENUM) \
6661 built_in_attributes[(int) ENUM] = NULL_TREE;
6662 #define DEF_ATTR_INT(ENUM, VALUE) \
6663 built_in_attributes[(int) ENUM] = build_int_cst (integer_type_node, VALUE);
6664 #define DEF_ATTR_STRING(ENUM, VALUE) \
6665 built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
6666 #define DEF_ATTR_IDENT(ENUM, STRING) \
6667 built_in_attributes[(int) ENUM] = get_identifier (STRING);
6668 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
6669 built_in_attributes[(int) ENUM] \
6670 = tree_cons (built_in_attributes[(int) PURPOSE], \
6671 built_in_attributes[(int) VALUE], \
6672 built_in_attributes[(int) CHAIN]);
6673 #include "builtin-attrs.def"
6674 #undef DEF_ATTR_NULL_TREE
6676 #undef DEF_ATTR_IDENT
6677 #undef DEF_ATTR_TREE_LIST
6680 /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain
6681 identifier as an argument, so the front end shouldn't look it up. */
6684 attribute_takes_identifier_p (const_tree attr_id
)
6686 const struct attribute_spec
*spec
= lookup_attribute_spec (attr_id
);
6688 /* Unknown attribute that we'll end up ignoring, return true so we
6689 don't complain about an identifier argument. */
6691 else if (!strcmp ("mode", spec
->name
)
6692 || !strcmp ("format", spec
->name
)
6693 || !strcmp ("cleanup", spec
->name
))
6696 return targetm
.attribute_takes_identifier_p (attr_id
);
6699 /* Attribute handlers common to C front ends. */
6701 /* Handle a "packed" attribute; arguments as in
6702 struct attribute_spec.handler. */
6705 handle_packed_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6706 int flags
, bool *no_add_attrs
)
6710 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6711 *node
= build_variant_type_copy (*node
);
6712 TYPE_PACKED (*node
) = 1;
6714 else if (TREE_CODE (*node
) == FIELD_DECL
)
6716 if (TYPE_ALIGN (TREE_TYPE (*node
)) <= BITS_PER_UNIT
6717 /* Still pack bitfields. */
6718 && ! DECL_INITIAL (*node
))
6719 warning (OPT_Wattributes
,
6720 "%qE attribute ignored for field of type %qT",
6721 name
, TREE_TYPE (*node
));
6723 DECL_PACKED (*node
) = 1;
6725 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
6726 used for DECL_REGISTER. It wouldn't mean anything anyway.
6727 We can't set DECL_PACKED on the type of a TYPE_DECL, because
6728 that changes what the typedef is typing. */
6731 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6732 *no_add_attrs
= true;
6738 /* Handle a "nocommon" attribute; arguments as in
6739 struct attribute_spec.handler. */
6742 handle_nocommon_attribute (tree
*node
, tree name
,
6743 tree
ARG_UNUSED (args
),
6744 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6746 if (TREE_CODE (*node
) == VAR_DECL
)
6747 DECL_COMMON (*node
) = 0;
6750 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6751 *no_add_attrs
= true;
6757 /* Handle a "common" attribute; arguments as in
6758 struct attribute_spec.handler. */
6761 handle_common_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6762 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6764 if (TREE_CODE (*node
) == VAR_DECL
)
6765 DECL_COMMON (*node
) = 1;
6768 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6769 *no_add_attrs
= true;
6775 /* Handle a "noreturn" attribute; arguments as in
6776 struct attribute_spec.handler. */
6779 handle_noreturn_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6780 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6782 tree type
= TREE_TYPE (*node
);
6784 /* See FIXME comment in c_common_attribute_table. */
6785 if (TREE_CODE (*node
) == FUNCTION_DECL
6786 || objc_method_decl (TREE_CODE (*node
)))
6787 TREE_THIS_VOLATILE (*node
) = 1;
6788 else if (TREE_CODE (type
) == POINTER_TYPE
6789 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
6791 = (build_qualified_type
6793 (build_type_variant (TREE_TYPE (type
),
6794 TYPE_READONLY (TREE_TYPE (type
)), 1)),
6795 TYPE_QUALS (type
)));
6798 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6799 *no_add_attrs
= true;
6805 /* Handle a "hot" and attribute; arguments as in
6806 struct attribute_spec.handler. */
6809 handle_hot_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6810 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6812 if (TREE_CODE (*node
) == FUNCTION_DECL
6813 || TREE_CODE (*node
) == LABEL_DECL
)
6815 if (lookup_attribute ("cold", DECL_ATTRIBUTES (*node
)) != NULL
)
6817 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
6818 "with attribute %qs", name
, "cold");
6819 *no_add_attrs
= true;
6821 /* Most of the rest of the hot processing is done later with
6822 lookup_attribute. */
6826 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6827 *no_add_attrs
= true;
6833 /* Handle a "cold" and attribute; arguments as in
6834 struct attribute_spec.handler. */
6837 handle_cold_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6838 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6840 if (TREE_CODE (*node
) == FUNCTION_DECL
6841 || TREE_CODE (*node
) == LABEL_DECL
)
6843 if (lookup_attribute ("hot", DECL_ATTRIBUTES (*node
)) != NULL
)
6845 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
6846 "with attribute %qs", name
, "hot");
6847 *no_add_attrs
= true;
6849 /* Most of the rest of the cold processing is done later with
6850 lookup_attribute. */
6854 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6855 *no_add_attrs
= true;
6861 /* Handle a "no_sanitize_address" attribute; arguments as in
6862 struct attribute_spec.handler. */
6865 handle_no_sanitize_address_attribute (tree
*node
, tree name
, tree
, int,
6868 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6870 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6871 *no_add_attrs
= true;
6877 /* Handle a "no_address_safety_analysis" attribute; arguments as in
6878 struct attribute_spec.handler. */
6881 handle_no_address_safety_analysis_attribute (tree
*node
, tree name
, tree
, int,
6884 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6885 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6886 else if (!lookup_attribute ("no_sanitize_address", DECL_ATTRIBUTES (*node
)))
6887 DECL_ATTRIBUTES (*node
)
6888 = tree_cons (get_identifier ("no_sanitize_address"),
6889 NULL_TREE
, DECL_ATTRIBUTES (*node
));
6890 *no_add_attrs
= true;
6894 /* Handle a "no_sanitize_undefined" attribute; arguments as in
6895 struct attribute_spec.handler. */
6898 handle_no_sanitize_undefined_attribute (tree
*node
, tree name
, tree
, int,
6901 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6903 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6904 *no_add_attrs
= true;
6910 /* Handle a "stack_protect" attribute; arguments as in
6911 struct attribute_spec.handler. */
6913 handle_stack_protect_attribute (tree
*node
, tree name
, tree
, int,
6916 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6918 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6919 *no_add_attrs
= true;
6922 DECL_ATTRIBUTES (*node
)
6923 = tree_cons (get_identifier ("stack_protect"),
6924 NULL_TREE
, DECL_ATTRIBUTES (*node
));
6929 /* Handle a "noinline" attribute; arguments as in
6930 struct attribute_spec.handler. */
6933 handle_noinline_attribute (tree
*node
, tree name
,
6934 tree
ARG_UNUSED (args
),
6935 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6937 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6939 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node
)))
6941 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
6942 "with attribute %qs", name
, "always_inline");
6943 *no_add_attrs
= true;
6946 DECL_UNINLINABLE (*node
) = 1;
6950 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6951 *no_add_attrs
= true;
6957 /* Handle a "noclone" attribute; arguments as in
6958 struct attribute_spec.handler. */
6961 handle_noclone_attribute (tree
*node
, tree name
,
6962 tree
ARG_UNUSED (args
),
6963 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6965 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6967 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6968 *no_add_attrs
= true;
6974 /* Handle a "no_icf" attribute; arguments as in
6975 struct attribute_spec.handler. */
6978 handle_noicf_attribute (tree
*node
, tree name
,
6979 tree
ARG_UNUSED (args
),
6980 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6982 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6984 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6985 *no_add_attrs
= true;
6992 /* Handle a "always_inline" attribute; arguments as in
6993 struct attribute_spec.handler. */
6996 handle_always_inline_attribute (tree
*node
, tree name
,
6997 tree
ARG_UNUSED (args
),
6998 int ARG_UNUSED (flags
),
7001 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7003 if (lookup_attribute ("noinline", DECL_ATTRIBUTES (*node
)))
7005 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
7006 "with %qs attribute", name
, "noinline");
7007 *no_add_attrs
= true;
7010 /* Set the attribute and mark it for disregarding inline
7012 DECL_DISREGARD_INLINE_LIMITS (*node
) = 1;
7016 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7017 *no_add_attrs
= true;
7023 /* Handle a "gnu_inline" attribute; arguments as in
7024 struct attribute_spec.handler. */
7027 handle_gnu_inline_attribute (tree
*node
, tree name
,
7028 tree
ARG_UNUSED (args
),
7029 int ARG_UNUSED (flags
),
7032 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
7034 /* Do nothing else, just set the attribute. We'll get at
7035 it later with lookup_attribute. */
7039 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7040 *no_add_attrs
= true;
7046 /* Handle a "leaf" attribute; arguments as in
7047 struct attribute_spec.handler. */
7050 handle_leaf_attribute (tree
*node
, tree name
,
7051 tree
ARG_UNUSED (args
),
7052 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7054 if (TREE_CODE (*node
) != FUNCTION_DECL
)
7056 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7057 *no_add_attrs
= true;
7059 if (!TREE_PUBLIC (*node
))
7061 warning (OPT_Wattributes
, "%qE attribute has no effect on unit local functions", name
);
7062 *no_add_attrs
= true;
7068 /* Handle an "artificial" attribute; arguments as in
7069 struct attribute_spec.handler. */
7072 handle_artificial_attribute (tree
*node
, tree name
,
7073 tree
ARG_UNUSED (args
),
7074 int ARG_UNUSED (flags
),
7077 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
7079 /* Do nothing else, just set the attribute. We'll get at
7080 it later with lookup_attribute. */
7084 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7085 *no_add_attrs
= true;
7091 /* Handle a "flatten" attribute; arguments as in
7092 struct attribute_spec.handler. */
7095 handle_flatten_attribute (tree
*node
, tree name
,
7096 tree args ATTRIBUTE_UNUSED
,
7097 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
7099 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7100 /* Do nothing else, just set the attribute. We'll get at
7101 it later with lookup_attribute. */
7105 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7106 *no_add_attrs
= true;
7112 /* Handle a "warning" or "error" attribute; arguments as in
7113 struct attribute_spec.handler. */
7116 handle_error_attribute (tree
*node
, tree name
, tree args
,
7117 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7119 if (TREE_CODE (*node
) == FUNCTION_DECL
7120 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
7121 /* Do nothing else, just set the attribute. We'll get at
7122 it later with lookup_attribute. */
7126 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7127 *no_add_attrs
= true;
7133 /* Handle a "used" attribute; arguments as in
7134 struct attribute_spec.handler. */
7137 handle_used_attribute (tree
*pnode
, tree name
, tree
ARG_UNUSED (args
),
7138 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7142 if (TREE_CODE (node
) == FUNCTION_DECL
7143 || (TREE_CODE (node
) == VAR_DECL
&& TREE_STATIC (node
))
7144 || (TREE_CODE (node
) == TYPE_DECL
))
7146 TREE_USED (node
) = 1;
7147 DECL_PRESERVE_P (node
) = 1;
7148 if (TREE_CODE (node
) == VAR_DECL
)
7149 DECL_READ_P (node
) = 1;
7153 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7154 *no_add_attrs
= true;
7160 /* Handle a "unused" attribute; arguments as in
7161 struct attribute_spec.handler. */
7164 handle_unused_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7165 int flags
, bool *no_add_attrs
)
7171 if (TREE_CODE (decl
) == PARM_DECL
7172 || TREE_CODE (decl
) == VAR_DECL
7173 || TREE_CODE (decl
) == FUNCTION_DECL
7174 || TREE_CODE (decl
) == LABEL_DECL
7175 || TREE_CODE (decl
) == TYPE_DECL
)
7177 TREE_USED (decl
) = 1;
7178 if (TREE_CODE (decl
) == VAR_DECL
7179 || TREE_CODE (decl
) == PARM_DECL
)
7180 DECL_READ_P (decl
) = 1;
7184 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7185 *no_add_attrs
= true;
7190 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7191 *node
= build_variant_type_copy (*node
);
7192 TREE_USED (*node
) = 1;
7198 /* Handle a "externally_visible" attribute; arguments as in
7199 struct attribute_spec.handler. */
7202 handle_externally_visible_attribute (tree
*pnode
, tree name
,
7203 tree
ARG_UNUSED (args
),
7204 int ARG_UNUSED (flags
),
7209 if (TREE_CODE (node
) == FUNCTION_DECL
|| TREE_CODE (node
) == VAR_DECL
)
7211 if ((!TREE_STATIC (node
) && TREE_CODE (node
) != FUNCTION_DECL
7212 && !DECL_EXTERNAL (node
)) || !TREE_PUBLIC (node
))
7214 warning (OPT_Wattributes
,
7215 "%qE attribute have effect only on public objects", name
);
7216 *no_add_attrs
= true;
7221 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7222 *no_add_attrs
= true;
7228 /* Handle the "no_reorder" attribute. Arguments as in
7229 struct attribute_spec.handler. */
7232 handle_no_reorder_attribute (tree
*pnode
,
7240 if ((TREE_CODE (node
) != FUNCTION_DECL
&& TREE_CODE (node
) != VAR_DECL
)
7241 && !(TREE_STATIC (node
) || DECL_EXTERNAL (node
)))
7243 warning (OPT_Wattributes
,
7244 "%qE attribute only affects top level objects",
7246 *no_add_attrs
= true;
7252 /* Handle a "const" attribute; arguments as in
7253 struct attribute_spec.handler. */
7256 handle_const_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7257 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7259 tree type
= TREE_TYPE (*node
);
7261 /* See FIXME comment on noreturn in c_common_attribute_table. */
7262 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7263 TREE_READONLY (*node
) = 1;
7264 else if (TREE_CODE (type
) == POINTER_TYPE
7265 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
7267 = (build_qualified_type
7269 (build_type_variant (TREE_TYPE (type
), 1,
7270 TREE_THIS_VOLATILE (TREE_TYPE (type
)))),
7271 TYPE_QUALS (type
)));
7274 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7275 *no_add_attrs
= true;
7281 /* Handle a "transparent_union" attribute; arguments as in
7282 struct attribute_spec.handler. */
7285 handle_transparent_union_attribute (tree
*node
, tree name
,
7286 tree
ARG_UNUSED (args
), int flags
,
7291 *no_add_attrs
= true;
7294 if (TREE_CODE (*node
) == TYPE_DECL
7295 && ! (flags
& ATTR_FLAG_CXX11
))
7296 node
= &TREE_TYPE (*node
);
7299 if (TREE_CODE (type
) == UNION_TYPE
)
7301 /* Make sure that the first field will work for a transparent union.
7302 If the type isn't complete yet, leave the check to the code in
7304 if (TYPE_SIZE (type
))
7306 tree first
= first_field (type
);
7307 if (first
== NULL_TREE
7308 || DECL_ARTIFICIAL (first
)
7309 || TYPE_MODE (type
) != DECL_MODE (first
))
7313 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7315 /* If the type isn't complete yet, setting the flag
7316 on a variant wouldn't ever be checked. */
7317 if (!TYPE_SIZE (type
))
7320 /* build_duplicate_type doesn't work for C++. */
7321 if (c_dialect_cxx ())
7324 /* A type variant isn't good enough, since we don't a cast
7325 to such a type removed as a no-op. */
7326 *node
= type
= build_duplicate_type (type
);
7329 TYPE_TRANSPARENT_AGGR (type
) = 1;
7334 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7338 /* Subroutine of handle_{con,de}structor_attribute. Evaluate ARGS to
7339 get the requested priority for a constructor or destructor,
7340 possibly issuing diagnostics for invalid or reserved
7343 static priority_type
7344 get_priority (tree args
, bool is_destructor
)
7350 return DEFAULT_INIT_PRIORITY
;
7352 if (!SUPPORTS_INIT_PRIORITY
)
7355 error ("destructor priorities are not supported");
7357 error ("constructor priorities are not supported");
7358 return DEFAULT_INIT_PRIORITY
;
7361 arg
= TREE_VALUE (args
);
7362 if (TREE_CODE (arg
) == IDENTIFIER_NODE
)
7364 if (arg
== error_mark_node
)
7365 return DEFAULT_INIT_PRIORITY
;
7366 arg
= default_conversion (arg
);
7367 if (!tree_fits_shwi_p (arg
)
7368 || !INTEGRAL_TYPE_P (TREE_TYPE (arg
)))
7371 pri
= tree_to_shwi (arg
);
7372 if (pri
< 0 || pri
> MAX_INIT_PRIORITY
)
7375 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
7379 "destructor priorities from 0 to %d are reserved "
7380 "for the implementation",
7381 MAX_RESERVED_INIT_PRIORITY
);
7384 "constructor priorities from 0 to %d are reserved "
7385 "for the implementation",
7386 MAX_RESERVED_INIT_PRIORITY
);
7392 error ("destructor priorities must be integers from 0 to %d inclusive",
7395 error ("constructor priorities must be integers from 0 to %d inclusive",
7397 return DEFAULT_INIT_PRIORITY
;
7400 /* Handle a "constructor" attribute; arguments as in
7401 struct attribute_spec.handler. */
7404 handle_constructor_attribute (tree
*node
, tree name
, tree args
,
7405 int ARG_UNUSED (flags
),
7409 tree type
= TREE_TYPE (decl
);
7411 if (TREE_CODE (decl
) == FUNCTION_DECL
7412 && TREE_CODE (type
) == FUNCTION_TYPE
7413 && decl_function_context (decl
) == 0)
7415 priority_type priority
;
7416 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
7417 priority
= get_priority (args
, /*is_destructor=*/false);
7418 SET_DECL_INIT_PRIORITY (decl
, priority
);
7419 TREE_USED (decl
) = 1;
7423 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7424 *no_add_attrs
= true;
7430 /* Handle a "destructor" attribute; arguments as in
7431 struct attribute_spec.handler. */
7434 handle_destructor_attribute (tree
*node
, tree name
, tree args
,
7435 int ARG_UNUSED (flags
),
7439 tree type
= TREE_TYPE (decl
);
7441 if (TREE_CODE (decl
) == FUNCTION_DECL
7442 && TREE_CODE (type
) == FUNCTION_TYPE
7443 && decl_function_context (decl
) == 0)
7445 priority_type priority
;
7446 DECL_STATIC_DESTRUCTOR (decl
) = 1;
7447 priority
= get_priority (args
, /*is_destructor=*/true);
7448 SET_DECL_FINI_PRIORITY (decl
, priority
);
7449 TREE_USED (decl
) = 1;
7453 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7454 *no_add_attrs
= true;
7460 /* Nonzero if the mode is a valid vector mode for this architecture.
7461 This returns nonzero even if there is no hardware support for the
7462 vector mode, but we can emulate with narrower modes. */
7465 vector_mode_valid_p (machine_mode mode
)
7467 enum mode_class mclass
= GET_MODE_CLASS (mode
);
7468 machine_mode innermode
;
7470 /* Doh! What's going on? */
7471 if (mclass
!= MODE_VECTOR_INT
7472 && mclass
!= MODE_VECTOR_FLOAT
7473 && mclass
!= MODE_VECTOR_FRACT
7474 && mclass
!= MODE_VECTOR_UFRACT
7475 && mclass
!= MODE_VECTOR_ACCUM
7476 && mclass
!= MODE_VECTOR_UACCUM
)
7479 /* Hardware support. Woo hoo! */
7480 if (targetm
.vector_mode_supported_p (mode
))
7483 innermode
= GET_MODE_INNER (mode
);
7485 /* We should probably return 1 if requesting V4DI and we have no DI,
7486 but we have V2DI, but this is probably very unlikely. */
7488 /* If we have support for the inner mode, we can safely emulate it.
7489 We may not have V2DI, but me can emulate with a pair of DIs. */
7490 return targetm
.scalar_mode_supported_p (innermode
);
7494 /* Handle a "mode" attribute; arguments as in
7495 struct attribute_spec.handler. */
7498 handle_mode_attribute (tree
*node
, tree name
, tree args
,
7499 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7502 tree ident
= TREE_VALUE (args
);
7504 *no_add_attrs
= true;
7506 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
7507 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7511 const char *p
= IDENTIFIER_POINTER (ident
);
7512 int len
= strlen (p
);
7513 machine_mode mode
= VOIDmode
;
7517 if (len
> 4 && p
[0] == '_' && p
[1] == '_'
7518 && p
[len
- 1] == '_' && p
[len
- 2] == '_')
7520 char *newp
= (char *) alloca (len
- 1);
7522 strcpy (newp
, &p
[2]);
7523 newp
[len
- 4] = '\0';
7527 /* Change this type to have a type with the specified mode.
7528 First check for the special modes. */
7529 if (!strcmp (p
, "byte"))
7531 else if (!strcmp (p
, "word"))
7533 else if (!strcmp (p
, "pointer"))
7535 else if (!strcmp (p
, "libgcc_cmp_return"))
7536 mode
= targetm
.libgcc_cmp_return_mode ();
7537 else if (!strcmp (p
, "libgcc_shift_count"))
7538 mode
= targetm
.libgcc_shift_count_mode ();
7539 else if (!strcmp (p
, "unwind_word"))
7540 mode
= targetm
.unwind_word_mode ();
7542 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
7543 if (!strcmp (p
, GET_MODE_NAME (j
)))
7545 mode
= (machine_mode
) j
;
7549 if (mode
== VOIDmode
)
7551 error ("unknown machine mode %qE", ident
);
7556 switch (GET_MODE_CLASS (mode
))
7559 case MODE_PARTIAL_INT
:
7561 case MODE_DECIMAL_FLOAT
:
7566 valid_mode
= targetm
.scalar_mode_supported_p (mode
);
7569 case MODE_COMPLEX_INT
:
7570 case MODE_COMPLEX_FLOAT
:
7571 valid_mode
= targetm
.scalar_mode_supported_p (GET_MODE_INNER (mode
));
7574 case MODE_VECTOR_INT
:
7575 case MODE_VECTOR_FLOAT
:
7576 case MODE_VECTOR_FRACT
:
7577 case MODE_VECTOR_UFRACT
:
7578 case MODE_VECTOR_ACCUM
:
7579 case MODE_VECTOR_UACCUM
:
7580 warning (OPT_Wattributes
, "specifying vector types with "
7581 "__attribute__ ((mode)) is deprecated");
7582 warning (OPT_Wattributes
,
7583 "use __attribute__ ((vector_size)) instead");
7584 valid_mode
= vector_mode_valid_p (mode
);
7592 error ("unable to emulate %qs", p
);
7596 if (POINTER_TYPE_P (type
))
7598 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
7599 tree (*fn
)(tree
, machine_mode
, bool);
7601 if (!targetm
.addr_space
.valid_pointer_mode (mode
, as
))
7603 error ("invalid pointer mode %qs", p
);
7607 if (TREE_CODE (type
) == POINTER_TYPE
)
7608 fn
= build_pointer_type_for_mode
;
7610 fn
= build_reference_type_for_mode
;
7611 typefm
= fn (TREE_TYPE (type
), mode
, false);
7615 /* For fixed-point modes, we need to test if the signness of type
7616 and the machine mode are consistent. */
7617 if (ALL_FIXED_POINT_MODE_P (mode
)
7618 && TYPE_UNSIGNED (type
) != UNSIGNED_FIXED_POINT_MODE_P (mode
))
7620 error ("signedness of type and machine mode %qs don%'t match", p
);
7623 /* For fixed-point modes, we need to pass saturating info. */
7624 typefm
= lang_hooks
.types
.type_for_mode (mode
,
7625 ALL_FIXED_POINT_MODE_P (mode
) ? TYPE_SATURATING (type
)
7626 : TYPE_UNSIGNED (type
));
7629 if (typefm
== NULL_TREE
)
7631 error ("no data type for mode %qs", p
);
7634 else if (TREE_CODE (type
) == ENUMERAL_TYPE
)
7636 /* For enumeral types, copy the precision from the integer
7637 type returned above. If not an INTEGER_TYPE, we can't use
7638 this mode for this type. */
7639 if (TREE_CODE (typefm
) != INTEGER_TYPE
)
7641 error ("cannot use mode %qs for enumeral types", p
);
7645 if (flags
& ATTR_FLAG_TYPE_IN_PLACE
)
7647 TYPE_PRECISION (type
) = TYPE_PRECISION (typefm
);
7652 /* We cannot build a type variant, as there's code that assumes
7653 that TYPE_MAIN_VARIANT has the same mode. This includes the
7654 debug generators. Instead, create a subrange type. This
7655 results in all of the enumeral values being emitted only once
7656 in the original, and the subtype gets them by reference. */
7657 if (TYPE_UNSIGNED (type
))
7658 typefm
= make_unsigned_type (TYPE_PRECISION (typefm
));
7660 typefm
= make_signed_type (TYPE_PRECISION (typefm
));
7661 TREE_TYPE (typefm
) = type
;
7664 else if (VECTOR_MODE_P (mode
)
7665 ? TREE_CODE (type
) != TREE_CODE (TREE_TYPE (typefm
))
7666 : TREE_CODE (type
) != TREE_CODE (typefm
))
7668 error ("mode %qs applied to inappropriate type", p
);
7678 /* Handle a "section" attribute; arguments as in
7679 struct attribute_spec.handler. */
7682 handle_section_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7683 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7687 if (targetm_common
.have_named_sections
)
7689 user_defined_section_attribute
= true;
7691 if ((TREE_CODE (decl
) == FUNCTION_DECL
7692 || TREE_CODE (decl
) == VAR_DECL
)
7693 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
7695 if (TREE_CODE (decl
) == VAR_DECL
7696 && current_function_decl
!= NULL_TREE
7697 && !TREE_STATIC (decl
))
7699 error_at (DECL_SOURCE_LOCATION (decl
),
7700 "section attribute cannot be specified for "
7702 *no_add_attrs
= true;
7705 /* The decl may have already been given a section attribute
7706 from a previous declaration. Ensure they match. */
7707 else if (DECL_SECTION_NAME (decl
) != NULL
7708 && strcmp (DECL_SECTION_NAME (decl
),
7709 TREE_STRING_POINTER (TREE_VALUE (args
))) != 0)
7711 error ("section of %q+D conflicts with previous declaration",
7713 *no_add_attrs
= true;
7715 else if (TREE_CODE (decl
) == VAR_DECL
7716 && !targetm
.have_tls
&& targetm
.emutls
.tmpl_section
7717 && DECL_THREAD_LOCAL_P (decl
))
7719 error ("section of %q+D cannot be overridden", *node
);
7720 *no_add_attrs
= true;
7723 set_decl_section_name (decl
,
7724 TREE_STRING_POINTER (TREE_VALUE (args
)));
7728 error ("section attribute not allowed for %q+D", *node
);
7729 *no_add_attrs
= true;
7734 error_at (DECL_SOURCE_LOCATION (*node
),
7735 "section attributes are not supported for this target");
7736 *no_add_attrs
= true;
7742 /* Check whether ALIGN is a valid user-specified alignment. If so,
7743 return its base-2 log; if not, output an error and return -1. If
7744 ALLOW_ZERO then 0 is valid and should result in a return of -1 with
7747 check_user_alignment (const_tree align
, bool allow_zero
)
7751 if (error_operand_p (align
))
7753 if (TREE_CODE (align
) != INTEGER_CST
7754 || !INTEGRAL_TYPE_P (TREE_TYPE (align
)))
7756 error ("requested alignment is not an integer constant");
7759 else if (allow_zero
&& integer_zerop (align
))
7761 else if (tree_int_cst_sgn (align
) == -1
7762 || (i
= tree_log2 (align
)) == -1)
7764 error ("requested alignment is not a positive power of 2");
7767 else if (i
>= HOST_BITS_PER_INT
- BITS_PER_UNIT_LOG
)
7769 error ("requested alignment is too large");
7776 If in c++-11, check if the c++-11 alignment constraint with respect
7777 to fundamental alignment (in [dcl.align]) are satisfied. If not in
7778 c++-11 mode, does nothing.
7782 [* if the constant expression evaluates to a fundamental alignment,
7783 the alignment requirement of the declared entity shall be the
7784 specified fundamental alignment.
7786 * if the constant expression evaluates to an extended alignment
7787 and the implementation supports that alignment in the context
7788 of the declaration, the alignment of the declared entity shall
7791 * if the constant expression evaluates to an extended alignment
7792 and the implementation does not support that alignment in the
7793 context of the declaration, the program is ill-formed]. */
7796 check_cxx_fundamental_alignment_constraints (tree node
,
7800 bool alignment_too_large_p
= false;
7801 unsigned requested_alignment
= 1U << align_log
;
7802 unsigned max_align
= 0;
7804 if ((!(flags
& ATTR_FLAG_CXX11
) && !warn_cxx_compat
)
7805 || (node
== NULL_TREE
|| node
== error_mark_node
))
7808 if (cxx_fundamental_alignment_p (requested_alignment
))
7813 if (TREE_STATIC (node
))
7815 /* For file scope variables and static members, the target
7816 supports alignments that are at most
7817 MAX_OFILE_ALIGNMENT. */
7818 if (requested_alignment
> (max_align
= MAX_OFILE_ALIGNMENT
))
7819 alignment_too_large_p
= true;
7823 #ifdef BIGGEST_FIELD_ALIGNMENT
7824 #define MAX_TARGET_FIELD_ALIGNMENT BIGGEST_FIELD_ALIGNMENT
7826 #define MAX_TARGET_FIELD_ALIGNMENT BIGGEST_ALIGNMENT
7828 /* For non-static members, the target supports either
7829 alignments that at most either BIGGEST_FIELD_ALIGNMENT
7830 if it is defined or BIGGEST_ALIGNMENT. */
7831 max_align
= MAX_TARGET_FIELD_ALIGNMENT
;
7832 if (TREE_CODE (node
) == FIELD_DECL
7833 && requested_alignment
> (max_align
= MAX_TARGET_FIELD_ALIGNMENT
))
7834 alignment_too_large_p
= true;
7835 #undef MAX_TARGET_FIELD_ALIGNMENT
7836 /* For stack variables, the target supports at most
7837 MAX_STACK_ALIGNMENT. */
7838 else if (decl_function_context (node
) != NULL
7839 && requested_alignment
> (max_align
= MAX_STACK_ALIGNMENT
))
7840 alignment_too_large_p
= true;
7843 else if (TYPE_P (node
))
7845 /* Let's be liberal for types. */
7846 if (requested_alignment
> (max_align
= BIGGEST_ALIGNMENT
))
7847 alignment_too_large_p
= true;
7850 if (alignment_too_large_p
)
7851 pedwarn (input_location
, OPT_Wattributes
,
7852 "requested alignment %d is larger than %d",
7853 requested_alignment
, max_align
);
7855 return !alignment_too_large_p
;
7858 /* Handle a "aligned" attribute; arguments as in
7859 struct attribute_spec.handler. */
7862 handle_aligned_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7863 int flags
, bool *no_add_attrs
)
7865 tree decl
= NULL_TREE
;
7873 align_expr
= TREE_VALUE (args
);
7874 if (align_expr
&& TREE_CODE (align_expr
) != IDENTIFIER_NODE
7875 && TREE_CODE (align_expr
) != FUNCTION_DECL
)
7876 align_expr
= default_conversion (align_expr
);
7879 align_expr
= size_int (ATTRIBUTE_ALIGNED_VALUE
/ BITS_PER_UNIT
);
7884 type
= &TREE_TYPE (decl
);
7885 is_type
= TREE_CODE (*node
) == TYPE_DECL
;
7887 else if (TYPE_P (*node
))
7888 type
= node
, is_type
= 1;
7890 if ((i
= check_user_alignment (align_expr
, false)) == -1
7891 || !check_cxx_fundamental_alignment_constraints (*node
, i
, flags
))
7892 *no_add_attrs
= true;
7895 if ((flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7896 /* OK, modify the type in place. */;
7897 /* If we have a TYPE_DECL, then copy the type, so that we
7898 don't accidentally modify a builtin type. See pushdecl. */
7899 else if (decl
&& TREE_TYPE (decl
) != error_mark_node
7900 && DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
)
7902 tree tt
= TREE_TYPE (decl
);
7903 *type
= build_variant_type_copy (*type
);
7904 DECL_ORIGINAL_TYPE (decl
) = tt
;
7905 TYPE_NAME (*type
) = decl
;
7906 TREE_USED (*type
) = TREE_USED (decl
);
7907 TREE_TYPE (decl
) = *type
;
7910 *type
= build_variant_type_copy (*type
);
7912 TYPE_ALIGN (*type
) = (1U << i
) * BITS_PER_UNIT
;
7913 TYPE_USER_ALIGN (*type
) = 1;
7915 else if (! VAR_OR_FUNCTION_DECL_P (decl
)
7916 && TREE_CODE (decl
) != FIELD_DECL
)
7918 error ("alignment may not be specified for %q+D", decl
);
7919 *no_add_attrs
= true;
7921 else if (DECL_USER_ALIGN (decl
)
7922 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
7923 /* C++-11 [dcl.align/4]:
7925 When multiple alignment-specifiers are specified for an
7926 entity, the alignment requirement shall be set to the
7927 strictest specified alignment.
7929 This formally comes from the c++11 specification but we are
7930 doing it for the GNU attribute syntax as well. */
7931 *no_add_attrs
= true;
7932 else if (TREE_CODE (decl
) == FUNCTION_DECL
7933 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
7935 if (DECL_USER_ALIGN (decl
))
7936 error ("alignment for %q+D was previously specified as %d "
7937 "and may not be decreased", decl
,
7938 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
7940 error ("alignment for %q+D must be at least %d", decl
,
7941 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
7942 *no_add_attrs
= true;
7946 DECL_ALIGN (decl
) = (1U << i
) * BITS_PER_UNIT
;
7947 DECL_USER_ALIGN (decl
) = 1;
7953 /* Handle a "weak" attribute; arguments as in
7954 struct attribute_spec.handler. */
7957 handle_weak_attribute (tree
*node
, tree name
,
7958 tree
ARG_UNUSED (args
),
7959 int ARG_UNUSED (flags
),
7960 bool * ARG_UNUSED (no_add_attrs
))
7962 if (TREE_CODE (*node
) == FUNCTION_DECL
7963 && DECL_DECLARED_INLINE_P (*node
))
7965 warning (OPT_Wattributes
, "inline function %q+D declared weak", *node
);
7966 *no_add_attrs
= true;
7968 else if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
7970 error ("indirect function %q+D cannot be declared weak", *node
);
7971 *no_add_attrs
= true;
7974 else if (TREE_CODE (*node
) == FUNCTION_DECL
7975 || TREE_CODE (*node
) == VAR_DECL
)
7977 struct symtab_node
*n
= symtab_node::get (*node
);
7978 if (n
&& n
->refuse_visibility_changes
)
7979 error ("%+D declared weak after being used", *node
);
7980 declare_weak (*node
);
7983 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7988 /* Handle an "alias" or "ifunc" attribute; arguments as in
7989 struct attribute_spec.handler, except that IS_ALIAS tells us
7990 whether this is an alias as opposed to ifunc attribute. */
7993 handle_alias_ifunc_attribute (bool is_alias
, tree
*node
, tree name
, tree args
,
7998 if (TREE_CODE (decl
) != FUNCTION_DECL
7999 && (!is_alias
|| TREE_CODE (decl
) != VAR_DECL
))
8001 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8002 *no_add_attrs
= true;
8004 else if ((TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INITIAL (decl
))
8005 || (TREE_CODE (decl
) != FUNCTION_DECL
8006 && TREE_PUBLIC (decl
) && !DECL_EXTERNAL (decl
))
8007 /* A static variable declaration is always a tentative definition,
8008 but the alias is a non-tentative definition which overrides. */
8009 || (TREE_CODE (decl
) != FUNCTION_DECL
8010 && ! TREE_PUBLIC (decl
) && DECL_INITIAL (decl
)))
8012 error ("%q+D defined both normally and as %qE attribute", decl
, name
);
8013 *no_add_attrs
= true;
8017 && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
8018 || lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
))))
8020 error ("weak %q+D cannot be defined %qE", decl
, name
);
8021 *no_add_attrs
= true;
8025 /* Note that the very first time we process a nested declaration,
8026 decl_function_context will not be set. Indeed, *would* never
8027 be set except for the DECL_INITIAL/DECL_EXTERNAL frobbery that
8028 we do below. After such frobbery, pushdecl would set the context.
8029 In any case, this is never what we want. */
8030 else if (decl_function_context (decl
) == 0 && current_function_decl
== NULL
)
8034 id
= TREE_VALUE (args
);
8035 if (TREE_CODE (id
) != STRING_CST
)
8037 error ("attribute %qE argument not a string", name
);
8038 *no_add_attrs
= true;
8041 id
= get_identifier (TREE_STRING_POINTER (id
));
8042 /* This counts as a use of the object pointed to. */
8045 if (TREE_CODE (decl
) == FUNCTION_DECL
)
8046 DECL_INITIAL (decl
) = error_mark_node
;
8048 TREE_STATIC (decl
) = 1;
8051 /* ifuncs are also aliases, so set that attribute too. */
8052 DECL_ATTRIBUTES (decl
)
8053 = tree_cons (get_identifier ("alias"), args
, DECL_ATTRIBUTES (decl
));
8057 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8058 *no_add_attrs
= true;
8061 if (decl_in_symtab_p (*node
))
8063 struct symtab_node
*n
= symtab_node::get (decl
);
8064 if (n
&& n
->refuse_visibility_changes
)
8067 error ("%+D declared alias after being used", decl
);
8069 error ("%+D declared ifunc after being used", decl
);
8077 /* Handle an "alias" or "ifunc" attribute; arguments as in
8078 struct attribute_spec.handler. */
8081 handle_ifunc_attribute (tree
*node
, tree name
, tree args
,
8082 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8084 return handle_alias_ifunc_attribute (false, node
, name
, args
, no_add_attrs
);
8087 /* Handle an "alias" or "ifunc" attribute; arguments as in
8088 struct attribute_spec.handler. */
8091 handle_alias_attribute (tree
*node
, tree name
, tree args
,
8092 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8094 return handle_alias_ifunc_attribute (true, node
, name
, args
, no_add_attrs
);
8097 /* Handle a "weakref" attribute; arguments as in struct
8098 attribute_spec.handler. */
8101 handle_weakref_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
8102 int flags
, bool *no_add_attrs
)
8104 tree attr
= NULL_TREE
;
8106 /* We must ignore the attribute when it is associated with
8107 local-scoped decls, since attribute alias is ignored and many
8108 such symbols do not even have a DECL_WEAK field. */
8109 if (decl_function_context (*node
)
8110 || current_function_decl
8111 || (TREE_CODE (*node
) != VAR_DECL
&& TREE_CODE (*node
) != FUNCTION_DECL
))
8113 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8114 *no_add_attrs
= true;
8118 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
8120 error ("indirect function %q+D cannot be declared weakref", *node
);
8121 *no_add_attrs
= true;
8125 /* The idea here is that `weakref("name")' mutates into `weakref,
8126 alias("name")', and weakref without arguments, in turn,
8127 implicitly adds weak. */
8131 attr
= tree_cons (get_identifier ("alias"), args
, attr
);
8132 attr
= tree_cons (get_identifier ("weakref"), NULL_TREE
, attr
);
8134 *no_add_attrs
= true;
8136 decl_attributes (node
, attr
, flags
);
8140 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node
)))
8141 error_at (DECL_SOURCE_LOCATION (*node
),
8142 "weakref attribute must appear before alias attribute");
8144 /* Can't call declare_weak because it wants this to be TREE_PUBLIC,
8145 and that isn't supported; and because it wants to add it to
8146 the list of weak decls, which isn't helpful. */
8147 DECL_WEAK (*node
) = 1;
8150 if (decl_in_symtab_p (*node
))
8152 struct symtab_node
*n
= symtab_node::get (*node
);
8153 if (n
&& n
->refuse_visibility_changes
)
8154 error ("%+D declared weakref after being used", *node
);
8160 /* Handle an "visibility" attribute; arguments as in
8161 struct attribute_spec.handler. */
8164 handle_visibility_attribute (tree
*node
, tree name
, tree args
,
8165 int ARG_UNUSED (flags
),
8166 bool *ARG_UNUSED (no_add_attrs
))
8169 tree id
= TREE_VALUE (args
);
8170 enum symbol_visibility vis
;
8174 if (TREE_CODE (*node
) == ENUMERAL_TYPE
)
8176 else if (TREE_CODE (*node
) != RECORD_TYPE
&& TREE_CODE (*node
) != UNION_TYPE
)
8178 warning (OPT_Wattributes
, "%qE attribute ignored on non-class types",
8182 else if (TYPE_FIELDS (*node
))
8184 error ("%qE attribute ignored because %qT is already defined",
8189 else if (decl_function_context (decl
) != 0 || !TREE_PUBLIC (decl
))
8191 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8195 if (TREE_CODE (id
) != STRING_CST
)
8197 error ("visibility argument not a string");
8201 /* If this is a type, set the visibility on the type decl. */
8204 decl
= TYPE_NAME (decl
);
8207 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
8209 warning (OPT_Wattributes
, "%qE attribute ignored on types",
8215 if (strcmp (TREE_STRING_POINTER (id
), "default") == 0)
8216 vis
= VISIBILITY_DEFAULT
;
8217 else if (strcmp (TREE_STRING_POINTER (id
), "internal") == 0)
8218 vis
= VISIBILITY_INTERNAL
;
8219 else if (strcmp (TREE_STRING_POINTER (id
), "hidden") == 0)
8220 vis
= VISIBILITY_HIDDEN
;
8221 else if (strcmp (TREE_STRING_POINTER (id
), "protected") == 0)
8222 vis
= VISIBILITY_PROTECTED
;
8225 error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
8226 vis
= VISIBILITY_DEFAULT
;
8229 if (DECL_VISIBILITY_SPECIFIED (decl
)
8230 && vis
!= DECL_VISIBILITY (decl
))
8232 tree attributes
= (TYPE_P (*node
)
8233 ? TYPE_ATTRIBUTES (*node
)
8234 : DECL_ATTRIBUTES (decl
));
8235 if (lookup_attribute ("visibility", attributes
))
8236 error ("%qD redeclared with different visibility", decl
);
8237 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
8238 && lookup_attribute ("dllimport", attributes
))
8239 error ("%qD was declared %qs which implies default visibility",
8241 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
8242 && lookup_attribute ("dllexport", attributes
))
8243 error ("%qD was declared %qs which implies default visibility",
8247 DECL_VISIBILITY (decl
) = vis
;
8248 DECL_VISIBILITY_SPECIFIED (decl
) = 1;
8250 /* Go ahead and attach the attribute to the node as well. This is needed
8251 so we can determine whether we have VISIBILITY_DEFAULT because the
8252 visibility was not specified, or because it was explicitly overridden
8253 from the containing scope. */
8258 /* Determine the ELF symbol visibility for DECL, which is either a
8259 variable or a function. It is an error to use this function if a
8260 definition of DECL is not available in this translation unit.
8261 Returns true if the final visibility has been determined by this
8262 function; false if the caller is free to make additional
8266 c_determine_visibility (tree decl
)
8268 gcc_assert (TREE_CODE (decl
) == VAR_DECL
8269 || TREE_CODE (decl
) == FUNCTION_DECL
);
8271 /* If the user explicitly specified the visibility with an
8272 attribute, honor that. DECL_VISIBILITY will have been set during
8273 the processing of the attribute. We check for an explicit
8274 attribute, rather than just checking DECL_VISIBILITY_SPECIFIED,
8275 to distinguish the use of an attribute from the use of a "#pragma
8276 GCC visibility push(...)"; in the latter case we still want other
8277 considerations to be able to overrule the #pragma. */
8278 if (lookup_attribute ("visibility", DECL_ATTRIBUTES (decl
))
8279 || (TARGET_DLLIMPORT_DECL_ATTRIBUTES
8280 && (lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl
))
8281 || lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl
)))))
8284 /* Set default visibility to whatever the user supplied with
8285 visibility_specified depending on #pragma GCC visibility. */
8286 if (!DECL_VISIBILITY_SPECIFIED (decl
))
8288 if (visibility_options
.inpragma
8289 || DECL_VISIBILITY (decl
) != default_visibility
)
8291 DECL_VISIBILITY (decl
) = default_visibility
;
8292 DECL_VISIBILITY_SPECIFIED (decl
) = visibility_options
.inpragma
;
8293 /* If visibility changed and DECL already has DECL_RTL, ensure
8294 symbol flags are updated. */
8295 if (((TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
))
8296 || TREE_CODE (decl
) == FUNCTION_DECL
)
8297 && DECL_RTL_SET_P (decl
))
8298 make_decl_rtl (decl
);
8304 /* Handle an "tls_model" attribute; arguments as in
8305 struct attribute_spec.handler. */
8308 handle_tls_model_attribute (tree
*node
, tree name
, tree args
,
8309 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8313 enum tls_model kind
;
8315 *no_add_attrs
= true;
8317 if (TREE_CODE (decl
) != VAR_DECL
|| !DECL_THREAD_LOCAL_P (decl
))
8319 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8323 kind
= DECL_TLS_MODEL (decl
);
8324 id
= TREE_VALUE (args
);
8325 if (TREE_CODE (id
) != STRING_CST
)
8327 error ("tls_model argument not a string");
8331 if (!strcmp (TREE_STRING_POINTER (id
), "local-exec"))
8332 kind
= TLS_MODEL_LOCAL_EXEC
;
8333 else if (!strcmp (TREE_STRING_POINTER (id
), "initial-exec"))
8334 kind
= TLS_MODEL_INITIAL_EXEC
;
8335 else if (!strcmp (TREE_STRING_POINTER (id
), "local-dynamic"))
8336 kind
= optimize
? TLS_MODEL_LOCAL_DYNAMIC
: TLS_MODEL_GLOBAL_DYNAMIC
;
8337 else if (!strcmp (TREE_STRING_POINTER (id
), "global-dynamic"))
8338 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
8340 error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
8342 set_decl_tls_model (decl
, kind
);
8346 /* Handle a "no_instrument_function" attribute; arguments as in
8347 struct attribute_spec.handler. */
8350 handle_no_instrument_function_attribute (tree
*node
, tree name
,
8351 tree
ARG_UNUSED (args
),
8352 int ARG_UNUSED (flags
),
8357 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8359 error_at (DECL_SOURCE_LOCATION (decl
),
8360 "%qE attribute applies only to functions", name
);
8361 *no_add_attrs
= true;
8364 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
8369 /* Handle a "malloc" attribute; arguments as in
8370 struct attribute_spec.handler. */
8373 handle_malloc_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8374 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8376 if (TREE_CODE (*node
) == FUNCTION_DECL
8377 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node
))))
8378 DECL_IS_MALLOC (*node
) = 1;
8381 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8382 *no_add_attrs
= true;
8388 /* Handle a "alloc_size" attribute; arguments as in
8389 struct attribute_spec.handler. */
8392 handle_alloc_size_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
8393 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8395 unsigned arg_count
= type_num_arguments (*node
);
8396 for (; args
; args
= TREE_CHAIN (args
))
8398 tree position
= TREE_VALUE (args
);
8399 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
8400 && TREE_CODE (position
) != FUNCTION_DECL
)
8401 position
= default_conversion (position
);
8403 if (!tree_fits_uhwi_p (position
)
8405 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
8407 warning (OPT_Wattributes
,
8408 "alloc_size parameter outside range");
8409 *no_add_attrs
= true;
8416 /* Handle a "alloc_align" attribute; arguments as in
8417 struct attribute_spec.handler. */
8420 handle_alloc_align_attribute (tree
*node
, tree
, tree args
, int,
8423 unsigned arg_count
= type_num_arguments (*node
);
8424 tree position
= TREE_VALUE (args
);
8425 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
)
8426 position
= default_conversion (position
);
8428 if (!tree_fits_uhwi_p (position
)
8430 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
8432 warning (OPT_Wattributes
,
8433 "alloc_align parameter outside range");
8434 *no_add_attrs
= true;
8440 /* Handle a "assume_aligned" attribute; arguments as in
8441 struct attribute_spec.handler. */
8444 handle_assume_aligned_attribute (tree
*, tree
, tree args
, int,
8447 for (; args
; args
= TREE_CHAIN (args
))
8449 tree position
= TREE_VALUE (args
);
8450 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
8451 && TREE_CODE (position
) != FUNCTION_DECL
)
8452 position
= default_conversion (position
);
8454 if (TREE_CODE (position
) != INTEGER_CST
)
8456 warning (OPT_Wattributes
,
8457 "assume_aligned parameter not integer constant");
8458 *no_add_attrs
= true;
8465 /* Handle a "fn spec" attribute; arguments as in
8466 struct attribute_spec.handler. */
8469 handle_fnspec_attribute (tree
*node ATTRIBUTE_UNUSED
, tree
ARG_UNUSED (name
),
8470 tree args
, int ARG_UNUSED (flags
),
8471 bool *no_add_attrs ATTRIBUTE_UNUSED
)
8474 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
8475 && !TREE_CHAIN (args
));
8479 /* Handle a "bnd_variable_size" attribute; arguments as in
8480 struct attribute_spec.handler. */
8483 handle_bnd_variable_size_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8484 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8486 if (TREE_CODE (*node
) != FIELD_DECL
)
8488 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8489 *no_add_attrs
= true;
8495 /* Handle a "bnd_legacy" attribute; arguments as in
8496 struct attribute_spec.handler. */
8499 handle_bnd_legacy (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8500 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8502 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8504 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8505 *no_add_attrs
= true;
8511 /* Handle a "bnd_instrument" attribute; arguments as in
8512 struct attribute_spec.handler. */
8515 handle_bnd_instrument (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8516 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8518 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8520 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8521 *no_add_attrs
= true;
8527 /* Handle a "warn_unused" attribute; arguments as in
8528 struct attribute_spec.handler. */
8531 handle_warn_unused_attribute (tree
*node
, tree name
,
8532 tree args ATTRIBUTE_UNUSED
,
8533 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
8536 /* Do nothing else, just set the attribute. We'll get at
8537 it later with lookup_attribute. */
8541 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8542 *no_add_attrs
= true;
8548 /* Handle an "omp declare simd" attribute; arguments as in
8549 struct attribute_spec.handler. */
8552 handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int, bool *)
8557 /* Handle an "omp declare target" attribute; arguments as in
8558 struct attribute_spec.handler. */
8561 handle_omp_declare_target_attribute (tree
*, tree
, tree
, int, bool *)
8566 /* Handle a "returns_twice" attribute; arguments as in
8567 struct attribute_spec.handler. */
8570 handle_returns_twice_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8571 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8573 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8574 DECL_IS_RETURNS_TWICE (*node
) = 1;
8577 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8578 *no_add_attrs
= true;
8584 /* Handle a "no_limit_stack" attribute; arguments as in
8585 struct attribute_spec.handler. */
8588 handle_no_limit_stack_attribute (tree
*node
, tree name
,
8589 tree
ARG_UNUSED (args
),
8590 int ARG_UNUSED (flags
),
8595 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8597 error_at (DECL_SOURCE_LOCATION (decl
),
8598 "%qE attribute applies only to functions", name
);
8599 *no_add_attrs
= true;
8601 else if (DECL_INITIAL (decl
))
8603 error_at (DECL_SOURCE_LOCATION (decl
),
8604 "can%'t set %qE attribute after definition", name
);
8605 *no_add_attrs
= true;
8608 DECL_NO_LIMIT_STACK (decl
) = 1;
8613 /* Handle a "pure" attribute; arguments as in
8614 struct attribute_spec.handler. */
8617 handle_pure_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8618 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8620 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8621 DECL_PURE_P (*node
) = 1;
8622 /* ??? TODO: Support types. */
8625 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8626 *no_add_attrs
= true;
8632 /* Digest an attribute list destined for a transactional memory statement.
8633 ALLOWED is the set of attributes that are allowed for this statement;
8634 return the attribute we parsed. Multiple attributes are never allowed. */
8637 parse_tm_stmt_attr (tree attrs
, int allowed
)
8642 for ( ; attrs
; attrs
= TREE_CHAIN (attrs
))
8644 tree a
= TREE_PURPOSE (attrs
);
8647 if (is_attribute_p ("outer", a
))
8648 m
= TM_STMT_ATTR_OUTER
;
8650 if ((m
& allowed
) == 0)
8652 warning (OPT_Wattributes
, "%qE attribute directive ignored", a
);
8661 else if (m_seen
== m
)
8662 warning (OPT_Wattributes
, "%qE attribute duplicated", a
);
8664 warning (OPT_Wattributes
, "%qE attribute follows %qE", a
, a_seen
);
8670 /* Transform a TM attribute name into a maskable integer and back.
8671 Note that NULL (i.e. no attribute) is mapped to UNKNOWN, corresponding
8672 to how the lack of an attribute is treated. */
8675 tm_attr_to_mask (tree attr
)
8679 if (is_attribute_p ("transaction_safe", attr
))
8680 return TM_ATTR_SAFE
;
8681 if (is_attribute_p ("transaction_callable", attr
))
8682 return TM_ATTR_CALLABLE
;
8683 if (is_attribute_p ("transaction_pure", attr
))
8684 return TM_ATTR_PURE
;
8685 if (is_attribute_p ("transaction_unsafe", attr
))
8686 return TM_ATTR_IRREVOCABLE
;
8687 if (is_attribute_p ("transaction_may_cancel_outer", attr
))
8688 return TM_ATTR_MAY_CANCEL_OUTER
;
8693 tm_mask_to_attr (int mask
)
8699 str
= "transaction_safe";
8701 case TM_ATTR_CALLABLE
:
8702 str
= "transaction_callable";
8705 str
= "transaction_pure";
8707 case TM_ATTR_IRREVOCABLE
:
8708 str
= "transaction_unsafe";
8710 case TM_ATTR_MAY_CANCEL_OUTER
:
8711 str
= "transaction_may_cancel_outer";
8716 return get_identifier (str
);
8719 /* Return the first TM attribute seen in LIST. */
8722 find_tm_attribute (tree list
)
8724 for (; list
; list
= TREE_CHAIN (list
))
8726 tree name
= TREE_PURPOSE (list
);
8727 if (tm_attr_to_mask (name
) != 0)
8733 /* Handle the TM attributes; arguments as in struct attribute_spec.handler.
8734 Here we accept only function types, and verify that none of the other
8735 function TM attributes are also applied. */
8736 /* ??? We need to accept class types for C++, but not C. This greatly
8737 complicates this function, since we can no longer rely on the extra
8738 processing given by function_type_required. */
8741 handle_tm_attribute (tree
*node
, tree name
, tree args
,
8742 int flags
, bool *no_add_attrs
)
8744 /* Only one path adds the attribute; others don't. */
8745 *no_add_attrs
= true;
8747 switch (TREE_CODE (*node
))
8751 /* Only tm_callable and tm_safe apply to classes. */
8752 if (tm_attr_to_mask (name
) & ~(TM_ATTR_SAFE
| TM_ATTR_CALLABLE
))
8759 tree old_name
= find_tm_attribute (TYPE_ATTRIBUTES (*node
));
8760 if (old_name
== name
)
8762 else if (old_name
!= NULL_TREE
)
8763 error ("type was previously declared %qE", old_name
);
8765 *no_add_attrs
= false;
8771 enum tree_code subcode
= TREE_CODE (TREE_TYPE (*node
));
8772 if (subcode
== FUNCTION_TYPE
|| subcode
== METHOD_TYPE
)
8774 tree fn_tmp
= TREE_TYPE (*node
);
8775 decl_attributes (&fn_tmp
, tree_cons (name
, args
, NULL
), 0);
8776 *node
= build_pointer_type (fn_tmp
);
8783 /* If a function is next, pass it on to be tried next. */
8784 if (flags
& (int) ATTR_FLAG_FUNCTION_NEXT
)
8785 return tree_cons (name
, args
, NULL
);
8788 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8795 /* Handle the TM_WRAP attribute; arguments as in
8796 struct attribute_spec.handler. */
8799 handle_tm_wrap_attribute (tree
*node
, tree name
, tree args
,
8800 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8804 /* We don't need the attribute even on success, since we
8805 record the entry in an external table. */
8806 *no_add_attrs
= true;
8808 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8809 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8812 tree wrap_decl
= TREE_VALUE (args
);
8813 if (error_operand_p (wrap_decl
))
8815 else if (TREE_CODE (wrap_decl
) != IDENTIFIER_NODE
8816 && TREE_CODE (wrap_decl
) != VAR_DECL
8817 && TREE_CODE (wrap_decl
) != FUNCTION_DECL
)
8818 error ("%qE argument not an identifier", name
);
8821 if (TREE_CODE (wrap_decl
) == IDENTIFIER_NODE
)
8822 wrap_decl
= lookup_name (wrap_decl
);
8823 if (wrap_decl
&& TREE_CODE (wrap_decl
) == FUNCTION_DECL
)
8825 if (lang_hooks
.types_compatible_p (TREE_TYPE (decl
),
8826 TREE_TYPE (wrap_decl
)))
8827 record_tm_replacement (wrap_decl
, decl
);
8829 error ("%qD is not compatible with %qD", wrap_decl
, decl
);
8832 error ("%qE argument is not a function", name
);
8839 /* Ignore the given attribute. Used when this attribute may be usefully
8840 overridden by the target, but is not used generically. */
8843 ignore_attribute (tree
* ARG_UNUSED (node
), tree
ARG_UNUSED (name
),
8844 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
8847 *no_add_attrs
= true;
8851 /* Handle a "no vops" attribute; arguments as in
8852 struct attribute_spec.handler. */
8855 handle_novops_attribute (tree
*node
, tree
ARG_UNUSED (name
),
8856 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
8857 bool *ARG_UNUSED (no_add_attrs
))
8859 gcc_assert (TREE_CODE (*node
) == FUNCTION_DECL
);
8860 DECL_IS_NOVOPS (*node
) = 1;
8864 /* Handle a "deprecated" attribute; arguments as in
8865 struct attribute_spec.handler. */
8868 handle_deprecated_attribute (tree
*node
, tree name
,
8869 tree args
, int flags
,
8872 tree type
= NULL_TREE
;
8874 tree what
= NULL_TREE
;
8877 *no_add_attrs
= true;
8878 else if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
8880 error ("deprecated message is not a string");
8881 *no_add_attrs
= true;
8887 type
= TREE_TYPE (decl
);
8889 if (TREE_CODE (decl
) == TYPE_DECL
8890 || TREE_CODE (decl
) == PARM_DECL
8891 || TREE_CODE (decl
) == VAR_DECL
8892 || TREE_CODE (decl
) == FUNCTION_DECL
8893 || TREE_CODE (decl
) == FIELD_DECL
8894 || objc_method_decl (TREE_CODE (decl
)))
8895 TREE_DEPRECATED (decl
) = 1;
8899 else if (TYPE_P (*node
))
8901 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
8902 *node
= build_variant_type_copy (*node
);
8903 TREE_DEPRECATED (*node
) = 1;
8911 *no_add_attrs
= true;
8912 if (type
&& TYPE_NAME (type
))
8914 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
8915 what
= TYPE_NAME (*node
);
8916 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
8917 && DECL_NAME (TYPE_NAME (type
)))
8918 what
= DECL_NAME (TYPE_NAME (type
));
8921 warning (OPT_Wattributes
, "%qE attribute ignored for %qE", name
, what
);
8923 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8929 /* Handle a "vector_size" attribute; arguments as in
8930 struct attribute_spec.handler. */
8933 handle_vector_size_attribute (tree
*node
, tree name
, tree args
,
8934 int ARG_UNUSED (flags
),
8937 unsigned HOST_WIDE_INT vecsize
, nunits
;
8938 machine_mode orig_mode
;
8939 tree type
= *node
, new_type
, size
;
8941 *no_add_attrs
= true;
8943 size
= TREE_VALUE (args
);
8944 if (size
&& TREE_CODE (size
) != IDENTIFIER_NODE
8945 && TREE_CODE (size
) != FUNCTION_DECL
)
8946 size
= default_conversion (size
);
8948 if (!tree_fits_uhwi_p (size
))
8950 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8954 /* Get the vector size (in bytes). */
8955 vecsize
= tree_to_uhwi (size
);
8957 /* We need to provide for vector pointers, vector arrays, and
8958 functions returning vectors. For example:
8960 __attribute__((vector_size(16))) short *foo;
8962 In this case, the mode is SI, but the type being modified is
8963 HI, so we need to look further. */
8965 while (POINTER_TYPE_P (type
)
8966 || TREE_CODE (type
) == FUNCTION_TYPE
8967 || TREE_CODE (type
) == METHOD_TYPE
8968 || TREE_CODE (type
) == ARRAY_TYPE
8969 || TREE_CODE (type
) == OFFSET_TYPE
)
8970 type
= TREE_TYPE (type
);
8972 /* Get the mode of the type being modified. */
8973 orig_mode
= TYPE_MODE (type
);
8975 if ((!INTEGRAL_TYPE_P (type
)
8976 && !SCALAR_FLOAT_TYPE_P (type
)
8977 && !FIXED_POINT_TYPE_P (type
))
8978 || (!SCALAR_FLOAT_MODE_P (orig_mode
)
8979 && GET_MODE_CLASS (orig_mode
) != MODE_INT
8980 && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode
))
8981 || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
8982 || TREE_CODE (type
) == BOOLEAN_TYPE
)
8984 error ("invalid vector type for attribute %qE", name
);
8988 if (vecsize
% tree_to_uhwi (TYPE_SIZE_UNIT (type
)))
8990 error ("vector size not an integral multiple of component size");
8996 error ("zero vector size");
9000 /* Calculate how many units fit in the vector. */
9001 nunits
= vecsize
/ tree_to_uhwi (TYPE_SIZE_UNIT (type
));
9002 if (nunits
& (nunits
- 1))
9004 error ("number of components of the vector not a power of two");
9008 new_type
= build_vector_type (type
, nunits
);
9010 /* Build back pointers if needed. */
9011 *node
= lang_hooks
.types
.reconstruct_complex_type (*node
, new_type
);
9016 /* Handle the "nonnull" attribute. */
9018 handle_nonnull_attribute (tree
*node
, tree
ARG_UNUSED (name
),
9019 tree args
, int ARG_UNUSED (flags
),
9023 unsigned HOST_WIDE_INT attr_arg_num
;
9025 /* If no arguments are specified, all pointer arguments should be
9026 non-null. Verify a full prototype is given so that the arguments
9027 will have the correct types when we actually check them later. */
9030 if (!prototype_p (type
))
9032 error ("nonnull attribute without arguments on a non-prototype");
9033 *no_add_attrs
= true;
9038 /* Argument list specified. Verify that each argument number references
9039 a pointer argument. */
9040 for (attr_arg_num
= 1; args
; attr_arg_num
++, args
= TREE_CHAIN (args
))
9042 unsigned HOST_WIDE_INT arg_num
= 0, ck_num
;
9044 tree arg
= TREE_VALUE (args
);
9045 if (arg
&& TREE_CODE (arg
) != IDENTIFIER_NODE
9046 && TREE_CODE (arg
) != FUNCTION_DECL
)
9047 arg
= default_conversion (arg
);
9049 if (!get_nonnull_operand (arg
, &arg_num
))
9051 error ("nonnull argument has invalid operand number (argument %lu)",
9052 (unsigned long) attr_arg_num
);
9053 *no_add_attrs
= true;
9057 if (prototype_p (type
))
9059 function_args_iterator iter
;
9062 function_args_iter_init (&iter
, type
);
9063 for (ck_num
= 1; ; ck_num
++, function_args_iter_next (&iter
))
9065 argument
= function_args_iter_cond (&iter
);
9066 if (argument
== NULL_TREE
|| ck_num
== arg_num
)
9071 || TREE_CODE (argument
) == VOID_TYPE
)
9073 error ("nonnull argument with out-of-range operand number (argument %lu, operand %lu)",
9074 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
9075 *no_add_attrs
= true;
9079 if (TREE_CODE (argument
) != POINTER_TYPE
)
9081 error ("nonnull argument references non-pointer operand (argument %lu, operand %lu)",
9082 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
9083 *no_add_attrs
= true;
9092 /* Check the argument list of a function call for null in argument slots
9093 that are marked as requiring a non-null pointer argument. The NARGS
9094 arguments are passed in the array ARGARRAY.
9098 check_function_nonnull (tree attrs
, int nargs
, tree
*argarray
)
9103 attrs
= lookup_attribute ("nonnull", attrs
);
9104 if (attrs
== NULL_TREE
)
9108 /* See if any of the nonnull attributes has no arguments. If so,
9109 then every pointer argument is checked (in which case the check
9110 for pointer type is done in check_nonnull_arg). */
9111 if (TREE_VALUE (a
) != NULL_TREE
)
9113 a
= lookup_attribute ("nonnull", TREE_CHAIN (a
));
9114 while (a
!= NULL_TREE
&& TREE_VALUE (a
) != NULL_TREE
);
9117 for (i
= 0; i
< nargs
; i
++)
9118 check_function_arguments_recurse (check_nonnull_arg
, NULL
, argarray
[i
],
9122 /* Walk the argument list. If we encounter an argument number we
9123 should check for non-null, do it. */
9124 for (i
= 0; i
< nargs
; i
++)
9126 for (a
= attrs
; ; a
= TREE_CHAIN (a
))
9128 a
= lookup_attribute ("nonnull", a
);
9129 if (a
== NULL_TREE
|| nonnull_check_p (TREE_VALUE (a
), i
+ 1))
9134 check_function_arguments_recurse (check_nonnull_arg
, NULL
,
9135 argarray
[i
], i
+ 1);
9140 /* Check that the Nth argument of a function call (counting backwards
9141 from the end) is a (pointer)0. The NARGS arguments are passed in the
9145 check_function_sentinel (const_tree fntype
, int nargs
, tree
*argarray
)
9147 tree attr
= lookup_attribute ("sentinel", TYPE_ATTRIBUTES (fntype
));
9154 function_args_iterator iter
;
9157 /* Skip over the named arguments. */
9158 FOREACH_FUNCTION_ARGS (fntype
, t
, iter
)
9165 if (TREE_VALUE (attr
))
9167 tree p
= TREE_VALUE (TREE_VALUE (attr
));
9168 pos
= TREE_INT_CST_LOW (p
);
9171 /* The sentinel must be one of the varargs, i.e.
9172 in position >= the number of fixed arguments. */
9173 if ((nargs
- 1 - pos
) < len
)
9175 warning (OPT_Wformat_
,
9176 "not enough variable arguments to fit a sentinel");
9180 /* Validate the sentinel. */
9181 sentinel
= argarray
[nargs
- 1 - pos
];
9182 if ((!POINTER_TYPE_P (TREE_TYPE (sentinel
))
9183 || !integer_zerop (sentinel
))
9184 /* Although __null (in C++) is only an integer we allow it
9185 nevertheless, as we are guaranteed that it's exactly
9186 as wide as a pointer, and we don't want to force
9187 users to cast the NULL they have written there.
9188 We warn with -Wstrict-null-sentinel, though. */
9189 && (warn_strict_null_sentinel
|| null_node
!= sentinel
))
9190 warning (OPT_Wformat_
, "missing sentinel in function call");
9194 /* Helper for check_function_nonnull; given a list of operands which
9195 must be non-null in ARGS, determine if operand PARAM_NUM should be
9199 nonnull_check_p (tree args
, unsigned HOST_WIDE_INT param_num
)
9201 unsigned HOST_WIDE_INT arg_num
= 0;
9203 for (; args
; args
= TREE_CHAIN (args
))
9205 bool found
= get_nonnull_operand (TREE_VALUE (args
), &arg_num
);
9209 if (arg_num
== param_num
)
9215 /* Check that the function argument PARAM (which is operand number
9216 PARAM_NUM) is non-null. This is called by check_function_nonnull
9217 via check_function_arguments_recurse. */
9220 check_nonnull_arg (void * ARG_UNUSED (ctx
), tree param
,
9221 unsigned HOST_WIDE_INT param_num
)
9223 /* Just skip checking the argument if it's not a pointer. This can
9224 happen if the "nonnull" attribute was given without an operand
9225 list (which means to check every pointer argument). */
9227 if (TREE_CODE (TREE_TYPE (param
)) != POINTER_TYPE
)
9230 if (integer_zerop (param
))
9231 warning (OPT_Wnonnull
, "null argument where non-null required "
9232 "(argument %lu)", (unsigned long) param_num
);
9235 /* Helper for nonnull attribute handling; fetch the operand number
9236 from the attribute argument list. */
9239 get_nonnull_operand (tree arg_num_expr
, unsigned HOST_WIDE_INT
*valp
)
9241 /* Verify the arg number is a small constant. */
9242 if (tree_fits_uhwi_p (arg_num_expr
))
9244 *valp
= TREE_INT_CST_LOW (arg_num_expr
);
9251 /* Handle a "nothrow" attribute; arguments as in
9252 struct attribute_spec.handler. */
9255 handle_nothrow_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
9256 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9258 if (TREE_CODE (*node
) == FUNCTION_DECL
)
9259 TREE_NOTHROW (*node
) = 1;
9260 /* ??? TODO: Support types. */
9263 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9264 *no_add_attrs
= true;
9270 /* Handle a "cleanup" attribute; arguments as in
9271 struct attribute_spec.handler. */
9274 handle_cleanup_attribute (tree
*node
, tree name
, tree args
,
9275 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9278 tree cleanup_id
, cleanup_decl
;
9280 /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
9281 for global destructors in C++. This requires infrastructure that
9282 we don't have generically at the moment. It's also not a feature
9283 we'd be missing too much, since we do have attribute constructor. */
9284 if (TREE_CODE (decl
) != VAR_DECL
|| TREE_STATIC (decl
))
9286 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9287 *no_add_attrs
= true;
9291 /* Verify that the argument is a function in scope. */
9292 /* ??? We could support pointers to functions here as well, if
9293 that was considered desirable. */
9294 cleanup_id
= TREE_VALUE (args
);
9295 if (TREE_CODE (cleanup_id
) != IDENTIFIER_NODE
)
9297 error ("cleanup argument not an identifier");
9298 *no_add_attrs
= true;
9301 cleanup_decl
= lookup_name (cleanup_id
);
9302 if (!cleanup_decl
|| TREE_CODE (cleanup_decl
) != FUNCTION_DECL
)
9304 error ("cleanup argument not a function");
9305 *no_add_attrs
= true;
9309 /* That the function has proper type is checked with the
9310 eventual call to build_function_call. */
9315 /* Handle a "warn_unused_result" attribute. No special handling. */
9318 handle_warn_unused_result_attribute (tree
*node
, tree name
,
9319 tree
ARG_UNUSED (args
),
9320 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9322 /* Ignore the attribute for functions not returning any value. */
9323 if (VOID_TYPE_P (TREE_TYPE (*node
)))
9325 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9326 *no_add_attrs
= true;
9332 /* Handle a "sentinel" attribute. */
9335 handle_sentinel_attribute (tree
*node
, tree name
, tree args
,
9336 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9338 if (!prototype_p (*node
))
9340 warning (OPT_Wattributes
,
9341 "%qE attribute requires prototypes with named arguments", name
);
9342 *no_add_attrs
= true;
9346 if (!stdarg_p (*node
))
9348 warning (OPT_Wattributes
,
9349 "%qE attribute only applies to variadic functions", name
);
9350 *no_add_attrs
= true;
9356 tree position
= TREE_VALUE (args
);
9357 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
9358 && TREE_CODE (position
) != FUNCTION_DECL
)
9359 position
= default_conversion (position
);
9361 if (TREE_CODE (position
) != INTEGER_CST
9362 || !INTEGRAL_TYPE_P (TREE_TYPE (position
)))
9364 warning (OPT_Wattributes
,
9365 "requested position is not an integer constant");
9366 *no_add_attrs
= true;
9370 if (tree_int_cst_lt (position
, integer_zero_node
))
9372 warning (OPT_Wattributes
,
9373 "requested position is less than zero");
9374 *no_add_attrs
= true;
9382 /* Handle a "type_generic" attribute. */
9385 handle_type_generic_attribute (tree
*node
, tree
ARG_UNUSED (name
),
9386 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
9387 bool * ARG_UNUSED (no_add_attrs
))
9389 /* Ensure we have a function type. */
9390 gcc_assert (TREE_CODE (*node
) == FUNCTION_TYPE
);
9392 /* Ensure we have a variadic function. */
9393 gcc_assert (!prototype_p (*node
) || stdarg_p (*node
));
9398 /* Handle a "target" attribute. */
9401 handle_target_attribute (tree
*node
, tree name
, tree args
, int flags
,
9404 /* Ensure we have a function type. */
9405 if (TREE_CODE (*node
) != FUNCTION_DECL
)
9407 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9408 *no_add_attrs
= true;
9410 else if (! targetm
.target_option
.valid_attribute_p (*node
, name
, args
,
9412 *no_add_attrs
= true;
9417 /* Arguments being collected for optimization. */
9418 typedef const char *const_char_p
; /* For DEF_VEC_P. */
9419 static GTY(()) vec
<const_char_p
, va_gc
> *optimize_args
;
9422 /* Inner function to convert a TREE_LIST to argv string to parse the optimize
9423 options in ARGS. ATTR_P is true if this is for attribute(optimize), and
9424 false for #pragma GCC optimize. */
9427 parse_optimize_options (tree args
, bool attr_p
)
9432 int saved_flag_strict_aliasing
;
9433 const char **opt_argv
;
9434 struct cl_decoded_option
*decoded_options
;
9435 unsigned int decoded_options_count
;
9438 /* Build up argv vector. Just in case the string is stored away, use garbage
9439 collected strings. */
9440 vec_safe_truncate (optimize_args
, 0);
9441 vec_safe_push (optimize_args
, (const char *) NULL
);
9443 for (ap
= args
; ap
!= NULL_TREE
; ap
= TREE_CHAIN (ap
))
9445 tree value
= TREE_VALUE (ap
);
9447 if (TREE_CODE (value
) == INTEGER_CST
)
9450 sprintf (buffer
, "-O%ld", (long) TREE_INT_CST_LOW (value
));
9451 vec_safe_push (optimize_args
, ggc_strdup (buffer
));
9454 else if (TREE_CODE (value
) == STRING_CST
)
9456 /* Split string into multiple substrings. */
9457 size_t len
= TREE_STRING_LENGTH (value
);
9458 char *p
= ASTRDUP (TREE_STRING_POINTER (value
));
9459 char *end
= p
+ len
;
9463 while (next_p
!= NULL
)
9469 comma
= strchr (p
, ',');
9482 r
= q
= (char *) ggc_alloc_atomic (len2
+ 3);
9484 /* If the user supplied -Oxxx or -fxxx, only allow -Oxxx or -fxxx
9486 if (*p
== '-' && p
[1] != 'O' && p
[1] != 'f')
9490 warning (OPT_Wattributes
,
9491 "bad option %s to optimize attribute", p
);
9493 warning (OPT_Wpragmas
,
9494 "bad option %s to pragma attribute", p
);
9502 /* Assume that Ox is -Ox, a numeric value is -Ox, a s by
9503 itself is -Os, and any other switch begins with a -f. */
9504 if ((*p
>= '0' && *p
<= '9')
9505 || (p
[0] == 's' && p
[1] == '\0'))
9511 memcpy (r
, p
, len2
);
9513 vec_safe_push (optimize_args
, (const char *) q
);
9519 opt_argc
= optimize_args
->length ();
9520 opt_argv
= (const char **) alloca (sizeof (char *) * (opt_argc
+ 1));
9522 for (i
= 1; i
< opt_argc
; i
++)
9523 opt_argv
[i
] = (*optimize_args
)[i
];
9525 saved_flag_strict_aliasing
= flag_strict_aliasing
;
9527 /* Now parse the options. */
9528 decode_cmdline_options_to_array_default_mask (opt_argc
, opt_argv
,
9530 &decoded_options_count
);
9531 decode_options (&global_options
, &global_options_set
,
9532 decoded_options
, decoded_options_count
,
9533 input_location
, global_dc
);
9535 targetm
.override_options_after_change();
9537 /* Don't allow changing -fstrict-aliasing. */
9538 flag_strict_aliasing
= saved_flag_strict_aliasing
;
9540 optimize_args
->truncate (0);
9544 /* For handling "optimize" attribute. arguments as in
9545 struct attribute_spec.handler. */
9548 handle_optimize_attribute (tree
*node
, tree name
, tree args
,
9549 int ARG_UNUSED (flags
), bool *no_add_attrs
)
9551 /* Ensure we have a function type. */
9552 if (TREE_CODE (*node
) != FUNCTION_DECL
)
9554 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
9555 *no_add_attrs
= true;
9559 struct cl_optimization cur_opts
;
9560 tree old_opts
= DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
);
9562 /* Save current options. */
9563 cl_optimization_save (&cur_opts
, &global_options
);
9565 /* If we previously had some optimization options, use them as the
9568 cl_optimization_restore (&global_options
,
9569 TREE_OPTIMIZATION (old_opts
));
9571 /* Parse options, and update the vector. */
9572 parse_optimize_options (args
, true);
9573 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
)
9574 = build_optimization_node (&global_options
);
9576 /* Restore current options. */
9577 cl_optimization_restore (&global_options
, &cur_opts
);
9583 /* Handle a "no_split_stack" attribute. */
9586 handle_no_split_stack_attribute (tree
*node
, tree name
,
9587 tree
ARG_UNUSED (args
),
9588 int ARG_UNUSED (flags
),
9593 if (TREE_CODE (decl
) != FUNCTION_DECL
)
9595 error_at (DECL_SOURCE_LOCATION (decl
),
9596 "%qE attribute applies only to functions", name
);
9597 *no_add_attrs
= true;
9599 else if (DECL_INITIAL (decl
))
9601 error_at (DECL_SOURCE_LOCATION (decl
),
9602 "can%'t set %qE attribute after definition", name
);
9603 *no_add_attrs
= true;
9609 /* Handle a "returns_nonnull" attribute; arguments as in
9610 struct attribute_spec.handler. */
9613 handle_returns_nonnull_attribute (tree
*node
, tree
, tree
, int,
9616 // Even without a prototype we still have a return type we can check.
9617 if (TREE_CODE (TREE_TYPE (*node
)) != POINTER_TYPE
)
9619 error ("returns_nonnull attribute on a function not returning a pointer");
9620 *no_add_attrs
= true;
9625 /* Handle a "designated_init" attribute; arguments as in
9626 struct attribute_spec.handler. */
9629 handle_designated_init_attribute (tree
*node
, tree name
, tree
, int,
9632 if (TREE_CODE (*node
) != RECORD_TYPE
)
9634 error ("%qE attribute is only valid on %<struct%> type", name
);
9635 *no_add_attrs
= true;
9641 /* Check for valid arguments being passed to a function with FNTYPE.
9642 There are NARGS arguments in the array ARGARRAY. */
9644 check_function_arguments (const_tree fntype
, int nargs
, tree
*argarray
)
9646 /* Check for null being passed in a pointer argument that must be
9647 non-null. We also need to do this if format checking is enabled. */
9650 check_function_nonnull (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
9652 /* Check for errors in format strings. */
9654 if (warn_format
|| warn_suggest_attribute_format
)
9655 check_function_format (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
9658 check_function_sentinel (fntype
, nargs
, argarray
);
9661 /* Generic argument checking recursion routine. PARAM is the argument to
9662 be checked. PARAM_NUM is the number of the argument. CALLBACK is invoked
9663 once the argument is resolved. CTX is context for the callback. */
9665 check_function_arguments_recurse (void (*callback
)
9666 (void *, tree
, unsigned HOST_WIDE_INT
),
9667 void *ctx
, tree param
,
9668 unsigned HOST_WIDE_INT param_num
)
9670 if (CONVERT_EXPR_P (param
)
9671 && (TYPE_PRECISION (TREE_TYPE (param
))
9672 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (param
, 0)))))
9674 /* Strip coercion. */
9675 check_function_arguments_recurse (callback
, ctx
,
9676 TREE_OPERAND (param
, 0), param_num
);
9680 if (TREE_CODE (param
) == CALL_EXPR
)
9682 tree type
= TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (param
)));
9684 bool found_format_arg
= false;
9686 /* See if this is a call to a known internationalization function
9687 that modifies a format arg. Such a function may have multiple
9688 format_arg attributes (for example, ngettext). */
9690 for (attrs
= TYPE_ATTRIBUTES (type
);
9692 attrs
= TREE_CHAIN (attrs
))
9693 if (is_attribute_p ("format_arg", TREE_PURPOSE (attrs
)))
9696 tree format_num_expr
;
9699 call_expr_arg_iterator iter
;
9701 /* Extract the argument number, which was previously checked
9703 format_num_expr
= TREE_VALUE (TREE_VALUE (attrs
));
9705 format_num
= tree_to_uhwi (format_num_expr
);
9707 for (inner_arg
= first_call_expr_arg (param
, &iter
), i
= 1;
9709 inner_arg
= next_call_expr_arg (&iter
), i
++)
9710 if (i
== format_num
)
9712 check_function_arguments_recurse (callback
, ctx
,
9713 inner_arg
, param_num
);
9714 found_format_arg
= true;
9719 /* If we found a format_arg attribute and did a recursive check,
9720 we are done with checking this argument. Otherwise, we continue
9721 and this will be considered a non-literal. */
9722 if (found_format_arg
)
9726 if (TREE_CODE (param
) == COND_EXPR
)
9728 /* Check both halves of the conditional expression. */
9729 check_function_arguments_recurse (callback
, ctx
,
9730 TREE_OPERAND (param
, 1), param_num
);
9731 check_function_arguments_recurse (callback
, ctx
,
9732 TREE_OPERAND (param
, 2), param_num
);
9736 (*callback
) (ctx
, param
, param_num
);
9739 /* Checks for a builtin function FNDECL that the number of arguments
9740 NARGS against the required number REQUIRED and issues an error if
9741 there is a mismatch. Returns true if the number of arguments is
9742 correct, otherwise false. */
9745 builtin_function_validate_nargs (tree fndecl
, int nargs
, int required
)
9747 if (nargs
< required
)
9749 error_at (input_location
,
9750 "not enough arguments to function %qE", fndecl
);
9753 else if (nargs
> required
)
9755 error_at (input_location
,
9756 "too many arguments to function %qE", fndecl
);
9762 /* Verifies the NARGS arguments ARGS to the builtin function FNDECL.
9763 Returns false if there was an error, otherwise true. */
9766 check_builtin_function_arguments (tree fndecl
, int nargs
, tree
*args
)
9768 if (!DECL_BUILT_IN (fndecl
)
9769 || DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_NORMAL
)
9772 switch (DECL_FUNCTION_CODE (fndecl
))
9774 case BUILT_IN_CONSTANT_P
:
9775 return builtin_function_validate_nargs (fndecl
, nargs
, 1);
9777 case BUILT_IN_ISFINITE
:
9778 case BUILT_IN_ISINF
:
9779 case BUILT_IN_ISINF_SIGN
:
9780 case BUILT_IN_ISNAN
:
9781 case BUILT_IN_ISNORMAL
:
9782 if (builtin_function_validate_nargs (fndecl
, nargs
, 1))
9784 if (TREE_CODE (TREE_TYPE (args
[0])) != REAL_TYPE
)
9786 error ("non-floating-point argument in call to "
9787 "function %qE", fndecl
);
9794 case BUILT_IN_ISGREATER
:
9795 case BUILT_IN_ISGREATEREQUAL
:
9796 case BUILT_IN_ISLESS
:
9797 case BUILT_IN_ISLESSEQUAL
:
9798 case BUILT_IN_ISLESSGREATER
:
9799 case BUILT_IN_ISUNORDERED
:
9800 if (builtin_function_validate_nargs (fndecl
, nargs
, 2))
9802 enum tree_code code0
, code1
;
9803 code0
= TREE_CODE (TREE_TYPE (args
[0]));
9804 code1
= TREE_CODE (TREE_TYPE (args
[1]));
9805 if (!((code0
== REAL_TYPE
&& code1
== REAL_TYPE
)
9806 || (code0
== REAL_TYPE
&& code1
== INTEGER_TYPE
)
9807 || (code0
== INTEGER_TYPE
&& code1
== REAL_TYPE
)))
9809 error ("non-floating-point arguments in call to "
9810 "function %qE", fndecl
);
9817 case BUILT_IN_FPCLASSIFY
:
9818 if (builtin_function_validate_nargs (fndecl
, nargs
, 6))
9823 if (TREE_CODE (args
[i
]) != INTEGER_CST
)
9825 error ("non-const integer argument %u in call to function %qE",
9830 if (TREE_CODE (TREE_TYPE (args
[5])) != REAL_TYPE
)
9832 error ("non-floating-point argument in call to function %qE",
9840 case BUILT_IN_ASSUME_ALIGNED
:
9841 if (builtin_function_validate_nargs (fndecl
, nargs
, 2 + (nargs
> 2)))
9843 if (nargs
>= 3 && TREE_CODE (TREE_TYPE (args
[2])) != INTEGER_TYPE
)
9845 error ("non-integer argument 3 in call to function %qE", fndecl
);
9852 case BUILT_IN_ADD_OVERFLOW
:
9853 case BUILT_IN_SUB_OVERFLOW
:
9854 case BUILT_IN_MUL_OVERFLOW
:
9855 if (builtin_function_validate_nargs (fndecl
, nargs
, 3))
9858 for (i
= 0; i
< 2; i
++)
9859 if (!INTEGRAL_TYPE_P (TREE_TYPE (args
[i
])))
9861 error ("argument %u in call to function %qE does not have "
9862 "integral type", i
+ 1, fndecl
);
9865 if (TREE_CODE (TREE_TYPE (args
[2])) != POINTER_TYPE
9866 || TREE_CODE (TREE_TYPE (TREE_TYPE (args
[2]))) != INTEGER_TYPE
)
9868 error ("argument 3 in call to function %qE does not have "
9869 "pointer to integer type", fndecl
);
9881 /* Function to help qsort sort FIELD_DECLs by name order. */
9884 field_decl_cmp (const void *x_p
, const void *y_p
)
9886 const tree
*const x
= (const tree
*const) x_p
;
9887 const tree
*const y
= (const tree
*const) y_p
;
9889 if (DECL_NAME (*x
) == DECL_NAME (*y
))
9890 /* A nontype is "greater" than a type. */
9891 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
9892 if (DECL_NAME (*x
) == NULL_TREE
)
9894 if (DECL_NAME (*y
) == NULL_TREE
)
9896 if (DECL_NAME (*x
) < DECL_NAME (*y
))
9902 gt_pointer_operator new_value
;
9906 /* This routine compares two fields like field_decl_cmp but using the
9907 pointer operator in resort_data. */
9910 resort_field_decl_cmp (const void *x_p
, const void *y_p
)
9912 const tree
*const x
= (const tree
*const) x_p
;
9913 const tree
*const y
= (const tree
*const) y_p
;
9915 if (DECL_NAME (*x
) == DECL_NAME (*y
))
9916 /* A nontype is "greater" than a type. */
9917 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
9918 if (DECL_NAME (*x
) == NULL_TREE
)
9920 if (DECL_NAME (*y
) == NULL_TREE
)
9923 tree d1
= DECL_NAME (*x
);
9924 tree d2
= DECL_NAME (*y
);
9925 resort_data
.new_value (&d1
, resort_data
.cookie
);
9926 resort_data
.new_value (&d2
, resort_data
.cookie
);
9933 /* Resort DECL_SORTED_FIELDS because pointers have been reordered. */
9936 resort_sorted_fields (void *obj
,
9937 void * ARG_UNUSED (orig_obj
),
9938 gt_pointer_operator new_value
,
9941 struct sorted_fields_type
*sf
= (struct sorted_fields_type
*) obj
;
9942 resort_data
.new_value
= new_value
;
9943 resort_data
.cookie
= cookie
;
9944 qsort (&sf
->elts
[0], sf
->len
, sizeof (tree
),
9945 resort_field_decl_cmp
);
9948 /* Subroutine of c_parse_error.
9949 Return the result of concatenating LHS and RHS. RHS is really
9950 a string literal, its first character is indicated by RHS_START and
9951 RHS_SIZE is its length (including the terminating NUL character).
9953 The caller is responsible for deleting the returned pointer. */
9956 catenate_strings (const char *lhs
, const char *rhs_start
, int rhs_size
)
9958 const int lhs_size
= strlen (lhs
);
9959 char *result
= XNEWVEC (char, lhs_size
+ rhs_size
);
9960 strncpy (result
, lhs
, lhs_size
);
9961 strncpy (result
+ lhs_size
, rhs_start
, rhs_size
);
9965 /* Issue the error given by GMSGID, indicating that it occurred before
9966 TOKEN, which had the associated VALUE. */
9969 c_parse_error (const char *gmsgid
, enum cpp_ttype token_type
,
9970 tree value
, unsigned char token_flags
)
9972 #define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2))
9974 char *message
= NULL
;
9976 if (token_type
== CPP_EOF
)
9977 message
= catenate_messages (gmsgid
, " at end of input");
9978 else if (token_type
== CPP_CHAR
9979 || token_type
== CPP_WCHAR
9980 || token_type
== CPP_CHAR16
9981 || token_type
== CPP_CHAR32
)
9983 unsigned int val
= TREE_INT_CST_LOW (value
);
10002 if (val
<= UCHAR_MAX
&& ISGRAPH (val
))
10003 message
= catenate_messages (gmsgid
, " before %s'%c'");
10005 message
= catenate_messages (gmsgid
, " before %s'\\x%x'");
10007 error (message
, prefix
, val
);
10011 else if (token_type
== CPP_CHAR_USERDEF
10012 || token_type
== CPP_WCHAR_USERDEF
10013 || token_type
== CPP_CHAR16_USERDEF
10014 || token_type
== CPP_CHAR32_USERDEF
)
10015 message
= catenate_messages (gmsgid
,
10016 " before user-defined character literal");
10017 else if (token_type
== CPP_STRING_USERDEF
10018 || token_type
== CPP_WSTRING_USERDEF
10019 || token_type
== CPP_STRING16_USERDEF
10020 || token_type
== CPP_STRING32_USERDEF
10021 || token_type
== CPP_UTF8STRING_USERDEF
)
10022 message
= catenate_messages (gmsgid
, " before user-defined string literal");
10023 else if (token_type
== CPP_STRING
10024 || token_type
== CPP_WSTRING
10025 || token_type
== CPP_STRING16
10026 || token_type
== CPP_STRING32
10027 || token_type
== CPP_UTF8STRING
)
10028 message
= catenate_messages (gmsgid
, " before string constant");
10029 else if (token_type
== CPP_NUMBER
)
10030 message
= catenate_messages (gmsgid
, " before numeric constant");
10031 else if (token_type
== CPP_NAME
)
10033 message
= catenate_messages (gmsgid
, " before %qE");
10034 error (message
, value
);
10038 else if (token_type
== CPP_PRAGMA
)
10039 message
= catenate_messages (gmsgid
, " before %<#pragma%>");
10040 else if (token_type
== CPP_PRAGMA_EOL
)
10041 message
= catenate_messages (gmsgid
, " before end of line");
10042 else if (token_type
== CPP_DECLTYPE
)
10043 message
= catenate_messages (gmsgid
, " before %<decltype%>");
10044 else if (token_type
< N_TTYPES
)
10046 message
= catenate_messages (gmsgid
, " before %qs token");
10047 error (message
, cpp_type2name (token_type
, token_flags
));
10059 #undef catenate_messages
10062 /* Return the gcc option code associated with the reason for a cpp
10063 message, or 0 if none. */
10066 c_option_controlling_cpp_error (int reason
)
10068 const struct cpp_reason_option_codes_t
*entry
;
10070 for (entry
= cpp_reason_option_codes
; entry
->reason
!= CPP_W_NONE
; entry
++)
10072 if (entry
->reason
== reason
)
10073 return entry
->option_code
;
10078 /* Callback from cpp_error for PFILE to print diagnostics from the
10079 preprocessor. The diagnostic is of type LEVEL, with REASON set
10080 to the reason code if LEVEL is represents a warning, at location
10081 LOCATION unless this is after lexing and the compiler's location
10082 should be used instead, with column number possibly overridden by
10083 COLUMN_OVERRIDE if not zero; MSG is the translated message and AP
10084 the arguments. Returns true if a diagnostic was emitted, false
10088 c_cpp_error (cpp_reader
*pfile ATTRIBUTE_UNUSED
, int level
, int reason
,
10089 location_t location
, unsigned int column_override
,
10090 const char *msg
, va_list *ap
)
10092 diagnostic_info diagnostic
;
10093 diagnostic_t dlevel
;
10094 bool save_warn_system_headers
= global_dc
->dc_warn_system_headers
;
10099 case CPP_DL_WARNING_SYSHDR
:
10100 if (flag_no_output
)
10102 global_dc
->dc_warn_system_headers
= 1;
10103 /* Fall through. */
10104 case CPP_DL_WARNING
:
10105 if (flag_no_output
)
10107 dlevel
= DK_WARNING
;
10109 case CPP_DL_PEDWARN
:
10110 if (flag_no_output
&& !flag_pedantic_errors
)
10112 dlevel
= DK_PEDWARN
;
10127 gcc_unreachable ();
10130 location
= input_location
;
10131 diagnostic_set_info_translated (&diagnostic
, msg
, ap
,
10133 if (column_override
)
10134 diagnostic_override_column (&diagnostic
, column_override
);
10135 diagnostic_override_option_index (&diagnostic
,
10136 c_option_controlling_cpp_error (reason
));
10137 ret
= report_diagnostic (&diagnostic
);
10138 if (level
== CPP_DL_WARNING_SYSHDR
)
10139 global_dc
->dc_warn_system_headers
= save_warn_system_headers
;
10143 /* Convert a character from the host to the target execution character
10144 set. cpplib handles this, mostly. */
10147 c_common_to_target_charset (HOST_WIDE_INT c
)
10149 /* Character constants in GCC proper are sign-extended under -fsigned-char,
10150 zero-extended under -fno-signed-char. cpplib insists that characters
10151 and character constants are always unsigned. Hence we must convert
10153 cppchar_t uc
= ((cppchar_t
)c
) & ((((cppchar_t
)1) << CHAR_BIT
)-1);
10155 uc
= cpp_host_to_exec_charset (parse_in
, uc
);
10157 if (flag_signed_char
)
10158 return ((HOST_WIDE_INT
)uc
) << (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
)
10159 >> (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
);
10164 /* Fold an offsetof-like expression. EXPR is a nested sequence of component
10165 references with an INDIRECT_REF of a constant at the bottom; much like the
10166 traditional rendering of offsetof as a macro. Return the folded result. */
10169 fold_offsetof_1 (tree expr
)
10173 switch (TREE_CODE (expr
))
10179 error ("cannot apply %<offsetof%> to static data member %qD", expr
);
10180 return error_mark_node
;
10184 error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded");
10185 return error_mark_node
;
10189 if (!TREE_CONSTANT (TREE_OPERAND (expr
, 0)))
10191 error ("cannot apply %<offsetof%> to a non constant address");
10192 return error_mark_node
;
10194 return TREE_OPERAND (expr
, 0);
10196 case COMPONENT_REF
:
10197 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0));
10198 if (base
== error_mark_node
)
10201 t
= TREE_OPERAND (expr
, 1);
10202 if (DECL_C_BIT_FIELD (t
))
10204 error ("attempt to take address of bit-field structure "
10206 return error_mark_node
;
10208 off
= size_binop_loc (input_location
, PLUS_EXPR
, DECL_FIELD_OFFSET (t
),
10209 size_int (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (t
))
10214 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0));
10215 if (base
== error_mark_node
)
10218 t
= TREE_OPERAND (expr
, 1);
10220 /* Check if the offset goes beyond the upper bound of the array. */
10221 if (TREE_CODE (t
) == INTEGER_CST
&& tree_int_cst_sgn (t
) >= 0)
10223 tree upbound
= array_ref_up_bound (expr
);
10224 if (upbound
!= NULL_TREE
10225 && TREE_CODE (upbound
) == INTEGER_CST
10226 && !tree_int_cst_equal (upbound
,
10227 TYPE_MAX_VALUE (TREE_TYPE (upbound
))))
10229 upbound
= size_binop (PLUS_EXPR
, upbound
,
10230 build_int_cst (TREE_TYPE (upbound
), 1));
10231 if (tree_int_cst_lt (upbound
, t
))
10235 for (v
= TREE_OPERAND (expr
, 0);
10236 TREE_CODE (v
) == COMPONENT_REF
;
10237 v
= TREE_OPERAND (v
, 0))
10238 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v
, 0)))
10241 tree fld_chain
= DECL_CHAIN (TREE_OPERAND (v
, 1));
10242 for (; fld_chain
; fld_chain
= DECL_CHAIN (fld_chain
))
10243 if (TREE_CODE (fld_chain
) == FIELD_DECL
)
10249 /* Don't warn if the array might be considered a poor
10250 man's flexible array member with a very permissive
10251 definition thereof. */
10252 if (TREE_CODE (v
) == ARRAY_REF
10253 || TREE_CODE (v
) == COMPONENT_REF
)
10254 warning (OPT_Warray_bounds
,
10255 "index %E denotes an offset "
10256 "greater than size of %qT",
10257 t
, TREE_TYPE (TREE_OPERAND (expr
, 0)));
10262 t
= convert (sizetype
, t
);
10263 off
= size_binop (MULT_EXPR
, TYPE_SIZE_UNIT (TREE_TYPE (expr
)), t
);
10266 case COMPOUND_EXPR
:
10267 /* Handle static members of volatile structs. */
10268 t
= TREE_OPERAND (expr
, 1);
10269 gcc_assert (TREE_CODE (t
) == VAR_DECL
);
10270 return fold_offsetof_1 (t
);
10273 gcc_unreachable ();
10276 return fold_build_pointer_plus (base
, off
);
10279 /* Likewise, but convert it to the return type of offsetof. */
10282 fold_offsetof (tree expr
)
10284 return convert (size_type_node
, fold_offsetof_1 (expr
));
10287 /* Warn for A ?: C expressions (with B omitted) where A is a boolean
10288 expression, because B will always be true. */
10291 warn_for_omitted_condop (location_t location
, tree cond
)
10293 if (truth_value_p (TREE_CODE (cond
)))
10294 warning_at (location
, OPT_Wparentheses
,
10295 "the omitted middle operand in ?: will always be %<true%>, "
10296 "suggest explicit middle operand");
10299 /* Give an error for storing into ARG, which is 'const'. USE indicates
10300 how ARG was being used. */
10303 readonly_error (location_t loc
, tree arg
, enum lvalue_use use
)
10305 gcc_assert (use
== lv_assign
|| use
== lv_increment
|| use
== lv_decrement
10307 /* Using this macro rather than (for example) arrays of messages
10308 ensures that all the format strings are checked at compile
10310 #define READONLY_MSG(A, I, D, AS) (use == lv_assign ? (A) \
10311 : (use == lv_increment ? (I) \
10312 : (use == lv_decrement ? (D) : (AS))))
10313 if (TREE_CODE (arg
) == COMPONENT_REF
)
10315 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg
, 0))))
10316 error_at (loc
, READONLY_MSG (G_("assignment of member "
10317 "%qD in read-only object"),
10318 G_("increment of member "
10319 "%qD in read-only object"),
10320 G_("decrement of member "
10321 "%qD in read-only object"),
10322 G_("member %qD in read-only object "
10323 "used as %<asm%> output")),
10324 TREE_OPERAND (arg
, 1));
10326 error_at (loc
, READONLY_MSG (G_("assignment of read-only member %qD"),
10327 G_("increment of read-only member %qD"),
10328 G_("decrement of read-only member %qD"),
10329 G_("read-only member %qD used as %<asm%> output")),
10330 TREE_OPERAND (arg
, 1));
10332 else if (TREE_CODE (arg
) == VAR_DECL
)
10333 error_at (loc
, READONLY_MSG (G_("assignment of read-only variable %qD"),
10334 G_("increment of read-only variable %qD"),
10335 G_("decrement of read-only variable %qD"),
10336 G_("read-only variable %qD used as %<asm%> output")),
10338 else if (TREE_CODE (arg
) == PARM_DECL
)
10339 error_at (loc
, READONLY_MSG (G_("assignment of read-only parameter %qD"),
10340 G_("increment of read-only parameter %qD"),
10341 G_("decrement of read-only parameter %qD"),
10342 G_("read-only parameter %qD use as %<asm%> output")),
10344 else if (TREE_CODE (arg
) == RESULT_DECL
)
10346 gcc_assert (c_dialect_cxx ());
10347 error_at (loc
, READONLY_MSG (G_("assignment of "
10348 "read-only named return value %qD"),
10350 "read-only named return value %qD"),
10352 "read-only named return value %qD"),
10353 G_("read-only named return value %qD "
10354 "used as %<asm%>output")),
10357 else if (TREE_CODE (arg
) == FUNCTION_DECL
)
10358 error_at (loc
, READONLY_MSG (G_("assignment of function %qD"),
10359 G_("increment of function %qD"),
10360 G_("decrement of function %qD"),
10361 G_("function %qD used as %<asm%> output")),
10364 error_at (loc
, READONLY_MSG (G_("assignment of read-only location %qE"),
10365 G_("increment of read-only location %qE"),
10366 G_("decrement of read-only location %qE"),
10367 G_("read-only location %qE used as %<asm%> output")),
10371 /* Print an error message for an invalid lvalue. USE says
10372 how the lvalue is being used and so selects the error message. LOC
10373 is the location for the error. */
10376 lvalue_error (location_t loc
, enum lvalue_use use
)
10381 error_at (loc
, "lvalue required as left operand of assignment");
10384 error_at (loc
, "lvalue required as increment operand");
10387 error_at (loc
, "lvalue required as decrement operand");
10390 error_at (loc
, "lvalue required as unary %<&%> operand");
10393 error_at (loc
, "lvalue required in asm statement");
10396 gcc_unreachable ();
10400 /* Print an error message for an invalid indirection of type TYPE.
10401 ERRSTRING is the name of the operator for the indirection. */
10404 invalid_indirection_error (location_t loc
, tree type
, ref_operator errstring
)
10409 gcc_assert (c_dialect_cxx ());
10410 error_at (loc
, "invalid type argument (have %qT)", type
);
10412 case RO_ARRAY_INDEXING
:
10414 "invalid type argument of array indexing (have %qT)",
10417 case RO_UNARY_STAR
:
10419 "invalid type argument of unary %<*%> (have %qT)",
10424 "invalid type argument of %<->%> (have %qT)",
10427 case RO_ARROW_STAR
:
10429 "invalid type argument of %<->*%> (have %qT)",
10432 case RO_IMPLICIT_CONVERSION
:
10434 "invalid type argument of implicit conversion (have %qT)",
10438 gcc_unreachable ();
10442 /* *PTYPE is an incomplete array. Complete it with a domain based on
10443 INITIAL_VALUE. If INITIAL_VALUE is not present, use 1 if DO_DEFAULT
10444 is true. Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
10445 2 if INITIAL_VALUE was NULL, and 3 if INITIAL_VALUE was empty. */
10448 complete_array_type (tree
*ptype
, tree initial_value
, bool do_default
)
10450 tree maxindex
, type
, main_type
, elt
, unqual_elt
;
10451 int failure
= 0, quals
;
10452 hashval_t hashcode
= 0;
10453 bool overflow_p
= false;
10455 maxindex
= size_zero_node
;
10458 if (TREE_CODE (initial_value
) == STRING_CST
)
10461 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value
)));
10462 maxindex
= size_int (TREE_STRING_LENGTH (initial_value
)/eltsize
- 1);
10464 else if (TREE_CODE (initial_value
) == CONSTRUCTOR
)
10466 vec
<constructor_elt
, va_gc
> *v
= CONSTRUCTOR_ELTS (initial_value
);
10468 if (vec_safe_is_empty (v
))
10472 maxindex
= ssize_int (-1);
10477 unsigned HOST_WIDE_INT cnt
;
10478 constructor_elt
*ce
;
10479 bool fold_p
= false;
10482 maxindex
= (*v
)[0].index
, fold_p
= true;
10484 curindex
= maxindex
;
10486 for (cnt
= 1; vec_safe_iterate (v
, cnt
, &ce
); cnt
++)
10488 bool curfold_p
= false;
10490 curindex
= ce
->index
, curfold_p
= true;
10495 /* Since we treat size types now as ordinary
10496 unsigned types, we need an explicit overflow
10498 tree orig
= curindex
;
10499 curindex
= fold_convert (sizetype
, curindex
);
10500 overflow_p
|= tree_int_cst_lt (curindex
, orig
);
10502 curindex
= size_binop (PLUS_EXPR
, curindex
,
10505 if (tree_int_cst_lt (maxindex
, curindex
))
10506 maxindex
= curindex
, fold_p
= curfold_p
;
10510 tree orig
= maxindex
;
10511 maxindex
= fold_convert (sizetype
, maxindex
);
10512 overflow_p
|= tree_int_cst_lt (maxindex
, orig
);
10518 /* Make an error message unless that happened already. */
10519 if (initial_value
!= error_mark_node
)
10531 /* Force an indefinite layout factor. */
10532 if (upc_shared_type_p (type
))
10533 type
= c_build_qualified_type_1 (type
, TYPE_QUAL_UPC_SHARED
,
10535 elt
= TREE_TYPE (type
);
10536 quals
= TYPE_QUALS (strip_array_types (elt
));
10540 unqual_elt
= c_build_qualified_type (elt
, KEEP_QUAL_ADDR_SPACE (quals
));
10542 /* Using build_distinct_type_copy and modifying things afterward instead
10543 of using build_array_type to create a new type preserves all of the
10544 TYPE_LANG_FLAG_? bits that the front end may have set. */
10545 main_type
= build_distinct_type_copy (TYPE_MAIN_VARIANT (type
));
10546 TREE_TYPE (main_type
) = unqual_elt
;
10547 TYPE_DOMAIN (main_type
)
10548 = build_range_type (TREE_TYPE (maxindex
),
10549 build_int_cst (TREE_TYPE (maxindex
), 0), maxindex
);
10550 layout_type (main_type
);
10552 /* Make sure we have the canonical MAIN_TYPE. */
10553 hashcode
= iterative_hash_object (TYPE_HASH (unqual_elt
), hashcode
);
10554 hashcode
= iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (main_type
)),
10556 main_type
= type_hash_canon (hashcode
, main_type
);
10558 /* Fix the canonical type. */
10559 if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type
))
10560 || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type
)))
10561 SET_TYPE_STRUCTURAL_EQUALITY (main_type
);
10562 else if (TYPE_CANONICAL (TREE_TYPE (main_type
)) != TREE_TYPE (main_type
)
10563 || (TYPE_CANONICAL (TYPE_DOMAIN (main_type
))
10564 != TYPE_DOMAIN (main_type
)))
10565 TYPE_CANONICAL (main_type
)
10566 = build_array_type (TYPE_CANONICAL (TREE_TYPE (main_type
)),
10567 TYPE_CANONICAL (TYPE_DOMAIN (main_type
)));
10569 TYPE_CANONICAL (main_type
) = main_type
;
10574 type
= c_build_qualified_type (main_type
, quals
);
10576 if (COMPLETE_TYPE_P (type
)
10577 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
10578 && (overflow_p
|| TREE_OVERFLOW (TYPE_SIZE_UNIT (type
))))
10580 error ("size of array is too large");
10581 /* If we proceed with the array type as it is, we'll eventually
10582 crash in tree_to_[su]hwi(). */
10583 type
= error_mark_node
;
10590 /* Like c_mark_addressable but don't check register qualifier. */
10592 c_common_mark_addressable_vec (tree t
)
10594 while (handled_component_p (t
))
10595 t
= TREE_OPERAND (t
, 0);
10596 if (TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != PARM_DECL
)
10598 TREE_ADDRESSABLE (t
) = 1;
10603 /* Used to help initialize the builtin-types.def table. When a type of
10604 the correct size doesn't exist, use error_mark_node instead of NULL.
10605 The later results in segfaults even when a decl using the type doesn't
10609 builtin_type_for_size (int size
, bool unsignedp
)
10611 tree type
= c_common_type_for_size (size
, unsignedp
);
10612 return type
? type
: error_mark_node
;
10615 /* A helper function for resolve_overloaded_builtin in resolving the
10616 overloaded __sync_ builtins. Returns a positive power of 2 if the
10617 first operand of PARAMS is a pointer to a supported data type.
10618 Returns 0 if an error is encountered. */
10621 sync_resolve_size (tree function
, vec
<tree
, va_gc
> *params
)
10628 error ("too few arguments to function %qE", function
);
10632 type
= TREE_TYPE ((*params
)[0]);
10633 if (TREE_CODE (type
) == ARRAY_TYPE
)
10635 /* Force array-to-pointer decay for C++. */
10636 gcc_assert (c_dialect_cxx());
10637 (*params
)[0] = default_conversion ((*params
)[0]);
10638 type
= TREE_TYPE ((*params
)[0]);
10640 if (TREE_CODE (type
) != POINTER_TYPE
)
10643 type
= TREE_TYPE (type
);
10644 if (!INTEGRAL_TYPE_P (type
) && !POINTER_TYPE_P (type
))
10647 size
= tree_to_uhwi (TYPE_SIZE_UNIT (type
));
10648 if (size
== 1 || size
== 2 || size
== 4 || size
== 8 || size
== 16)
10652 error ("incompatible type for argument %d of %qE", 1, function
);
10656 /* A helper function for resolve_overloaded_builtin. Adds casts to
10657 PARAMS to make arguments match up with those of FUNCTION. Drops
10658 the variadic arguments at the end. Returns false if some error
10659 was encountered; true on success. */
10662 sync_resolve_params (location_t loc
, tree orig_function
, tree function
,
10663 vec
<tree
, va_gc
> *params
, bool orig_format
)
10665 function_args_iterator iter
;
10667 unsigned int parmnum
;
10669 function_args_iter_init (&iter
, TREE_TYPE (function
));
10670 /* We've declared the implementation functions to use "volatile void *"
10671 as the pointer parameter, so we shouldn't get any complaints from the
10672 call to check_function_arguments what ever type the user used. */
10673 function_args_iter_next (&iter
);
10674 ptype
= TREE_TYPE (TREE_TYPE ((*params
)[0]));
10675 ptype
= TYPE_MAIN_VARIANT (ptype
);
10677 /* For the rest of the values, we need to cast these to FTYPE, so that we
10678 don't get warnings for passing pointer types, etc. */
10682 tree val
, arg_type
;
10684 arg_type
= function_args_iter_cond (&iter
);
10685 /* XXX void_type_node belies the abstraction. */
10686 if (arg_type
== void_type_node
)
10690 if (params
->length () <= parmnum
)
10692 error_at (loc
, "too few arguments to function %qE", orig_function
);
10696 /* Only convert parameters if arg_type is unsigned integer type with
10697 new format sync routines, i.e. don't attempt to convert pointer
10698 arguments (e.g. EXPECTED argument of __atomic_compare_exchange_n),
10699 bool arguments (e.g. WEAK argument) or signed int arguments (memmodel
10701 if (TREE_CODE (arg_type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (arg_type
))
10703 /* Ideally for the first conversion we'd use convert_for_assignment
10704 so that we get warnings for anything that doesn't match the pointer
10705 type. This isn't portable across the C and C++ front ends atm. */
10706 val
= (*params
)[parmnum
];
10707 val
= convert (ptype
, val
);
10708 val
= convert (arg_type
, val
);
10709 (*params
)[parmnum
] = val
;
10712 function_args_iter_next (&iter
);
10715 /* __atomic routines are not variadic. */
10716 if (!orig_format
&& params
->length () != parmnum
+ 1)
10718 error_at (loc
, "too many arguments to function %qE", orig_function
);
10722 /* The definition of these primitives is variadic, with the remaining
10723 being "an optional list of variables protected by the memory barrier".
10724 No clue what that's supposed to mean, precisely, but we consider all
10725 call-clobbered variables to be protected so we're safe. */
10726 params
->truncate (parmnum
+ 1);
10731 /* A helper function for resolve_overloaded_builtin. Adds a cast to
10732 RESULT to make it match the type of the first pointer argument in
10736 sync_resolve_return (tree first_param
, tree result
, bool orig_format
)
10738 tree ptype
= TREE_TYPE (TREE_TYPE (first_param
));
10739 tree rtype
= TREE_TYPE (result
);
10740 ptype
= TYPE_MAIN_VARIANT (ptype
);
10742 /* New format doesn't require casting unless the types are the same size. */
10743 if (orig_format
|| tree_int_cst_equal (TYPE_SIZE (ptype
), TYPE_SIZE (rtype
)))
10744 return convert (ptype
, result
);
10749 /* This function verifies the PARAMS to generic atomic FUNCTION.
10750 It returns the size if all the parameters are the same size, otherwise
10751 0 is returned if the parameters are invalid. */
10754 get_atomic_generic_size (location_t loc
, tree function
,
10755 vec
<tree
, va_gc
> *params
)
10757 unsigned int n_param
;
10758 unsigned int n_model
;
10763 /* Determine the parameter makeup. */
10764 switch (DECL_FUNCTION_CODE (function
))
10766 case BUILT_IN_ATOMIC_EXCHANGE
:
10770 case BUILT_IN_ATOMIC_LOAD
:
10771 case BUILT_IN_ATOMIC_STORE
:
10775 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10780 gcc_unreachable ();
10783 if (vec_safe_length (params
) != n_param
)
10785 error_at (loc
, "incorrect number of arguments to function %qE", function
);
10789 /* Get type of first parameter, and determine its size. */
10790 type_0
= TREE_TYPE ((*params
)[0]);
10791 if (TREE_CODE (type_0
) == ARRAY_TYPE
)
10793 /* Force array-to-pointer decay for C++. */
10794 gcc_assert (c_dialect_cxx());
10795 (*params
)[0] = default_conversion ((*params
)[0]);
10796 type_0
= TREE_TYPE ((*params
)[0]);
10798 if (TREE_CODE (type_0
) != POINTER_TYPE
|| VOID_TYPE_P (TREE_TYPE (type_0
)))
10800 error_at (loc
, "argument 1 of %qE must be a non-void pointer type",
10805 /* Types must be compile time constant sizes. */
10806 if (TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type_0
)))) != INTEGER_CST
)
10809 "argument 1 of %qE must be a pointer to a constant size type",
10814 size_0
= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type_0
)));
10816 /* Zero size objects are not allowed. */
10820 "argument 1 of %qE must be a pointer to a nonzero size object",
10825 /* Check each other parameter is a pointer and the same size. */
10826 for (x
= 0; x
< n_param
- n_model
; x
++)
10829 tree type
= TREE_TYPE ((*params
)[x
]);
10830 /* __atomic_compare_exchange has a bool in the 4th position, skip it. */
10831 if (n_param
== 6 && x
== 3)
10833 if (!POINTER_TYPE_P (type
))
10835 error_at (loc
, "argument %d of %qE must be a pointer type", x
+ 1,
10839 tree type_size
= TYPE_SIZE_UNIT (TREE_TYPE (type
));
10840 size
= type_size
? tree_to_uhwi (type_size
) : 0;
10841 if (size
!= size_0
)
10843 error_at (loc
, "size mismatch in argument %d of %qE", x
+ 1,
10849 /* Check memory model parameters for validity. */
10850 for (x
= n_param
- n_model
; x
< n_param
; x
++)
10852 tree p
= (*params
)[x
];
10853 if (TREE_CODE (p
) == INTEGER_CST
)
10855 int i
= tree_to_uhwi (p
);
10856 if (i
< 0 || (i
& MEMMODEL_MASK
) >= MEMMODEL_LAST
)
10858 warning_at (loc
, OPT_Winvalid_memory_model
,
10859 "invalid memory model argument %d of %qE", x
+ 1,
10864 if (!INTEGRAL_TYPE_P (TREE_TYPE (p
)))
10866 error_at (loc
, "non-integer memory model argument %d of %qE", x
+ 1,
10876 /* This will take an __atomic_ generic FUNCTION call, and add a size parameter N
10877 at the beginning of the parameter list PARAMS representing the size of the
10878 objects. This is to match the library ABI requirement. LOC is the location
10879 of the function call.
10880 The new function is returned if it needed rebuilding, otherwise NULL_TREE is
10881 returned to allow the external call to be constructed. */
10884 add_atomic_size_parameter (unsigned n
, location_t loc
, tree function
,
10885 vec
<tree
, va_gc
> *params
)
10889 /* Insert a SIZE_T parameter as the first param. If there isn't
10890 enough space, allocate a new vector and recursively re-build with that. */
10891 if (!params
->space (1))
10893 unsigned int z
, len
;
10894 vec
<tree
, va_gc
> *v
;
10897 len
= params
->length ();
10898 vec_alloc (v
, len
+ 1);
10899 v
->quick_push (build_int_cst (size_type_node
, n
));
10900 for (z
= 0; z
< len
; z
++)
10901 v
->quick_push ((*params
)[z
]);
10902 f
= build_function_call_vec (loc
, vNULL
, function
, v
, NULL
);
10907 /* Add the size parameter and leave as a function call for processing. */
10908 size_node
= build_int_cst (size_type_node
, n
);
10909 params
->quick_insert (0, size_node
);
10914 /* Return whether atomic operations for naturally aligned N-byte
10915 arguments are supported, whether inline or through libatomic. */
10917 atomic_size_supported_p (int n
)
10928 return targetm
.scalar_mode_supported_p (TImode
);
10935 /* This will process an __atomic_exchange function call, determine whether it
10936 needs to be mapped to the _N variation, or turned into a library call.
10937 LOC is the location of the builtin call.
10938 FUNCTION is the DECL that has been invoked;
10939 PARAMS is the argument list for the call. The return value is non-null
10940 TRUE is returned if it is translated into the proper format for a call to the
10941 external library, and NEW_RETURN is set the tree for that function.
10942 FALSE is returned if processing for the _N variation is required, and
10943 NEW_RETURN is set to the the return value the result is copied into. */
10945 resolve_overloaded_atomic_exchange (location_t loc
, tree function
,
10946 vec
<tree
, va_gc
> *params
, tree
*new_return
)
10948 tree p0
, p1
, p2
, p3
;
10949 tree I_type
, I_type_ptr
;
10950 int n
= get_atomic_generic_size (loc
, function
, params
);
10952 /* Size of 0 is an error condition. */
10955 *new_return
= error_mark_node
;
10959 /* If not a lock-free size, change to the library generic format. */
10960 if (!atomic_size_supported_p (n
))
10962 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10966 /* Otherwise there is a lockfree match, transform the call from:
10967 void fn(T* mem, T* desired, T* return, model)
10969 *return = (T) (fn (In* mem, (In) *desired, model)) */
10976 /* Create pointer to appropriate size. */
10977 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10978 I_type_ptr
= build_pointer_type (I_type
);
10980 /* Convert object pointer to required type. */
10981 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10983 /* Convert new value to required type, and dereference it. */
10984 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
10985 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
10988 /* Move memory model to the 3rd position, and end param list. */
10990 params
->truncate (3);
10992 /* Convert return pointer and dereference it for later assignment. */
10993 *new_return
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
10999 /* This will process an __atomic_compare_exchange function call, determine
11000 whether it needs to be mapped to the _N variation, or turned into a lib call.
11001 LOC is the location of the builtin call.
11002 FUNCTION is the DECL that has been invoked;
11003 PARAMS is the argument list for the call. The return value is non-null
11004 TRUE is returned if it is translated into the proper format for a call to the
11005 external library, and NEW_RETURN is set the tree for that function.
11006 FALSE is returned if processing for the _N variation is required. */
11009 resolve_overloaded_atomic_compare_exchange (location_t loc
, tree function
,
11010 vec
<tree
, va_gc
> *params
,
11014 tree I_type
, I_type_ptr
;
11015 int n
= get_atomic_generic_size (loc
, function
, params
);
11017 /* Size of 0 is an error condition. */
11020 *new_return
= error_mark_node
;
11024 /* If not a lock-free size, change to the library generic format. */
11025 if (!atomic_size_supported_p (n
))
11027 /* The library generic format does not have the weak parameter, so
11028 remove it from the param list. Since a parameter has been removed,
11029 we can be sure that there is room for the SIZE_T parameter, meaning
11030 there will not be a recursive rebuilding of the parameter list, so
11031 there is no danger this will be done twice. */
11034 (*params
)[3] = (*params
)[4];
11035 (*params
)[4] = (*params
)[5];
11036 params
->truncate (5);
11038 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
11042 /* Otherwise, there is a match, so the call needs to be transformed from:
11043 bool fn(T* mem, T* desired, T* return, weak, success, failure)
11045 bool fn ((In *)mem, (In *)expected, (In) *desired, weak, succ, fail) */
11051 /* Create pointer to appropriate size. */
11052 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
11053 I_type_ptr
= build_pointer_type (I_type
);
11055 /* Convert object pointer to required type. */
11056 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
11059 /* Convert expected pointer to required type. */
11060 p1
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p1
);
11063 /* Convert desired value to required type, and dereference it. */
11064 p2
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
11065 p2
= build1 (VIEW_CONVERT_EXPR
, I_type
, p2
);
11068 /* The rest of the parameters are fine. NULL means no special return value
11070 *new_return
= NULL
;
11075 /* This will process an __atomic_load function call, determine whether it
11076 needs to be mapped to the _N variation, or turned into a library call.
11077 LOC is the location of the builtin call.
11078 FUNCTION is the DECL that has been invoked;
11079 PARAMS is the argument list for the call. The return value is non-null
11080 TRUE is returned if it is translated into the proper format for a call to the
11081 external library, and NEW_RETURN is set the tree for that function.
11082 FALSE is returned if processing for the _N variation is required, and
11083 NEW_RETURN is set to the the return value the result is copied into. */
11086 resolve_overloaded_atomic_load (location_t loc
, tree function
,
11087 vec
<tree
, va_gc
> *params
, tree
*new_return
)
11090 tree I_type
, I_type_ptr
;
11091 int n
= get_atomic_generic_size (loc
, function
, params
);
11093 /* Size of 0 is an error condition. */
11096 *new_return
= error_mark_node
;
11100 /* If not a lock-free size, change to the library generic format. */
11101 if (!atomic_size_supported_p (n
))
11103 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
11107 /* Otherwise, there is a match, so the call needs to be transformed from:
11108 void fn(T* mem, T* return, model)
11110 *return = (T) (fn ((In *) mem, model)) */
11116 /* Create pointer to appropriate size. */
11117 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
11118 I_type_ptr
= build_pointer_type (I_type
);
11120 /* Convert object pointer to required type. */
11121 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
11124 /* Move memory model to the 2nd position, and end param list. */
11126 params
->truncate (2);
11128 /* Convert return pointer and dereference it for later assignment. */
11129 *new_return
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
11135 /* This will process an __atomic_store function call, determine whether it
11136 needs to be mapped to the _N variation, or turned into a library call.
11137 LOC is the location of the builtin call.
11138 FUNCTION is the DECL that has been invoked;
11139 PARAMS is the argument list for the call. The return value is non-null
11140 TRUE is returned if it is translated into the proper format for a call to the
11141 external library, and NEW_RETURN is set the tree for that function.
11142 FALSE is returned if processing for the _N variation is required, and
11143 NEW_RETURN is set to the the return value the result is copied into. */
11146 resolve_overloaded_atomic_store (location_t loc
, tree function
,
11147 vec
<tree
, va_gc
> *params
, tree
*new_return
)
11150 tree I_type
, I_type_ptr
;
11151 int n
= get_atomic_generic_size (loc
, function
, params
);
11153 /* Size of 0 is an error condition. */
11156 *new_return
= error_mark_node
;
11160 /* If not a lock-free size, change to the library generic format. */
11161 if (!atomic_size_supported_p (n
))
11163 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
11167 /* Otherwise, there is a match, so the call needs to be transformed from:
11168 void fn(T* mem, T* value, model)
11170 fn ((In *) mem, (In) *value, model) */
11175 /* Create pointer to appropriate size. */
11176 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
11177 I_type_ptr
= build_pointer_type (I_type
);
11179 /* Convert object pointer to required type. */
11180 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
11183 /* Convert new value to required type, and dereference it. */
11184 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
11185 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
11188 /* The memory model is in the right spot already. Return is void. */
11189 *new_return
= NULL_TREE
;
11195 /* Some builtin functions are placeholders for other expressions. This
11196 function should be called immediately after parsing the call expression
11197 before surrounding code has committed to the type of the expression.
11199 LOC is the location of the builtin call.
11201 FUNCTION is the DECL that has been invoked; it is known to be a builtin.
11202 PARAMS is the argument list for the call. The return value is non-null
11203 when expansion is complete, and null if normal processing should
11207 resolve_overloaded_builtin (location_t loc
, tree function
,
11208 vec
<tree
, va_gc
> *params
)
11210 enum built_in_function orig_code
= DECL_FUNCTION_CODE (function
);
11211 bool orig_format
= true;
11212 tree new_return
= NULL_TREE
;
11214 switch (DECL_BUILT_IN_CLASS (function
))
11216 case BUILT_IN_NORMAL
:
11219 if (targetm
.resolve_overloaded_builtin
)
11220 return targetm
.resolve_overloaded_builtin (loc
, function
, params
);
11227 /* Handle BUILT_IN_NORMAL here. */
11230 case BUILT_IN_ATOMIC_EXCHANGE
:
11231 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
11232 case BUILT_IN_ATOMIC_LOAD
:
11233 case BUILT_IN_ATOMIC_STORE
:
11235 /* Handle these 4 together so that they can fall through to the next
11236 case if the call is transformed to an _N variant. */
11239 case BUILT_IN_ATOMIC_EXCHANGE
:
11241 if (resolve_overloaded_atomic_exchange (loc
, function
, params
,
11244 /* Change to the _N variant. */
11245 orig_code
= BUILT_IN_ATOMIC_EXCHANGE_N
;
11249 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
11251 if (resolve_overloaded_atomic_compare_exchange (loc
, function
,
11255 /* Change to the _N variant. */
11256 orig_code
= BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
;
11259 case BUILT_IN_ATOMIC_LOAD
:
11261 if (resolve_overloaded_atomic_load (loc
, function
, params
,
11264 /* Change to the _N variant. */
11265 orig_code
= BUILT_IN_ATOMIC_LOAD_N
;
11268 case BUILT_IN_ATOMIC_STORE
:
11270 if (resolve_overloaded_atomic_store (loc
, function
, params
,
11273 /* Change to the _N variant. */
11274 orig_code
= BUILT_IN_ATOMIC_STORE_N
;
11278 gcc_unreachable ();
11280 /* Fallthrough to the normal processing. */
11282 case BUILT_IN_ATOMIC_EXCHANGE_N
:
11283 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
:
11284 case BUILT_IN_ATOMIC_LOAD_N
:
11285 case BUILT_IN_ATOMIC_STORE_N
:
11286 case BUILT_IN_ATOMIC_ADD_FETCH_N
:
11287 case BUILT_IN_ATOMIC_SUB_FETCH_N
:
11288 case BUILT_IN_ATOMIC_AND_FETCH_N
:
11289 case BUILT_IN_ATOMIC_NAND_FETCH_N
:
11290 case BUILT_IN_ATOMIC_XOR_FETCH_N
:
11291 case BUILT_IN_ATOMIC_OR_FETCH_N
:
11292 case BUILT_IN_ATOMIC_FETCH_ADD_N
:
11293 case BUILT_IN_ATOMIC_FETCH_SUB_N
:
11294 case BUILT_IN_ATOMIC_FETCH_AND_N
:
11295 case BUILT_IN_ATOMIC_FETCH_NAND_N
:
11296 case BUILT_IN_ATOMIC_FETCH_XOR_N
:
11297 case BUILT_IN_ATOMIC_FETCH_OR_N
:
11299 orig_format
= false;
11300 /* Fallthru for parameter processing. */
11302 case BUILT_IN_SYNC_FETCH_AND_ADD_N
:
11303 case BUILT_IN_SYNC_FETCH_AND_SUB_N
:
11304 case BUILT_IN_SYNC_FETCH_AND_OR_N
:
11305 case BUILT_IN_SYNC_FETCH_AND_AND_N
:
11306 case BUILT_IN_SYNC_FETCH_AND_XOR_N
:
11307 case BUILT_IN_SYNC_FETCH_AND_NAND_N
:
11308 case BUILT_IN_SYNC_ADD_AND_FETCH_N
:
11309 case BUILT_IN_SYNC_SUB_AND_FETCH_N
:
11310 case BUILT_IN_SYNC_OR_AND_FETCH_N
:
11311 case BUILT_IN_SYNC_AND_AND_FETCH_N
:
11312 case BUILT_IN_SYNC_XOR_AND_FETCH_N
:
11313 case BUILT_IN_SYNC_NAND_AND_FETCH_N
:
11314 case BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
:
11315 case BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N
:
11316 case BUILT_IN_SYNC_LOCK_TEST_AND_SET_N
:
11317 case BUILT_IN_SYNC_LOCK_RELEASE_N
:
11319 int n
= sync_resolve_size (function
, params
);
11320 tree new_function
, first_param
, result
;
11321 enum built_in_function fncode
;
11324 return error_mark_node
;
11326 fncode
= (enum built_in_function
)((int)orig_code
+ exact_log2 (n
) + 1);
11327 new_function
= builtin_decl_explicit (fncode
);
11328 if (!sync_resolve_params (loc
, function
, new_function
, params
,
11330 return error_mark_node
;
11332 first_param
= (*params
)[0];
11333 result
= build_function_call_vec (loc
, vNULL
, new_function
, params
,
11335 if (result
== error_mark_node
)
11337 if (orig_code
!= BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
11338 && orig_code
!= BUILT_IN_SYNC_LOCK_RELEASE_N
11339 && orig_code
!= BUILT_IN_ATOMIC_STORE_N
)
11340 result
= sync_resolve_return (first_param
, result
, orig_format
);
11342 /* If new_return is set, assign function to that expr and cast the
11343 result to void since the generic interface returned void. */
11346 /* Cast function result from I{1,2,4,8,16} to the required type. */
11347 result
= build1 (VIEW_CONVERT_EXPR
, TREE_TYPE (new_return
), result
);
11348 result
= build2 (MODIFY_EXPR
, TREE_TYPE (new_return
), new_return
,
11350 TREE_SIDE_EFFECTS (result
) = 1;
11351 protected_set_expr_location (result
, loc
);
11352 result
= convert (void_type_node
, result
);
11362 /* vector_types_compatible_elements_p is used in type checks of vectors
11363 values used as operands of binary operators. Where it returns true, and
11364 the other checks of the caller succeed (being vector types in he first
11365 place, and matching number of elements), we can just treat the types
11366 as essentially the same.
11367 Contrast with vector_targets_convertible_p, which is used for vector
11368 pointer types, and vector_types_convertible_p, which will allow
11369 language-specific matches under the control of flag_lax_vector_conversions,
11370 and might still require a conversion. */
11371 /* True if vector types T1 and T2 can be inputs to the same binary
11372 operator without conversion.
11373 We don't check the overall vector size here because some of our callers
11374 want to give different error messages when the vectors are compatible
11375 except for the element count. */
11378 vector_types_compatible_elements_p (tree t1
, tree t2
)
11380 bool opaque
= TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
);
11381 t1
= TREE_TYPE (t1
);
11382 t2
= TREE_TYPE (t2
);
11384 enum tree_code c1
= TREE_CODE (t1
), c2
= TREE_CODE (t2
);
11386 gcc_assert ((c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
|| c1
== FIXED_POINT_TYPE
)
11387 && (c2
== INTEGER_TYPE
|| c2
== REAL_TYPE
11388 || c2
== FIXED_POINT_TYPE
));
11390 t1
= c_common_signed_type (t1
);
11391 t2
= c_common_signed_type (t2
);
11392 /* Equality works here because c_common_signed_type uses
11393 TYPE_MAIN_VARIANT. */
11396 if (opaque
&& c1
== c2
11397 && (c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
)
11398 && TYPE_PRECISION (t1
) == TYPE_PRECISION (t2
))
11403 /* Check for missing format attributes on function pointers. LTYPE is
11404 the new type or left-hand side type. RTYPE is the old type or
11405 right-hand side type. Returns TRUE if LTYPE is missing the desired
11409 check_missing_format_attribute (tree ltype
, tree rtype
)
11411 tree
const ttr
= TREE_TYPE (rtype
), ttl
= TREE_TYPE (ltype
);
11414 for (ra
= TYPE_ATTRIBUTES (ttr
); ra
; ra
= TREE_CHAIN (ra
))
11415 if (is_attribute_p ("format", TREE_PURPOSE (ra
)))
11420 for (la
= TYPE_ATTRIBUTES (ttl
); la
; la
= TREE_CHAIN (la
))
11421 if (is_attribute_p ("format", TREE_PURPOSE (la
)))
11429 /* Subscripting with type char is likely to lose on a machine where
11430 chars are signed. So warn on any machine, but optionally. Don't
11431 warn for unsigned char since that type is safe. Don't warn for
11432 signed char because anyone who uses that must have done so
11433 deliberately. Furthermore, we reduce the false positive load by
11434 warning only for non-constant value of type char. */
11437 warn_array_subscript_with_type_char (location_t loc
, tree index
)
11439 if (TYPE_MAIN_VARIANT (TREE_TYPE (index
)) == char_type_node
11440 && TREE_CODE (index
) != INTEGER_CST
)
11441 warning_at (loc
, OPT_Wchar_subscripts
,
11442 "array subscript has type %<char%>");
11445 /* Implement -Wparentheses for the unexpected C precedence rules, to
11446 cover cases like x + y << z which readers are likely to
11447 misinterpret. We have seen an expression in which CODE is a binary
11448 operator used to combine expressions ARG_LEFT and ARG_RIGHT, which
11449 before folding had CODE_LEFT and CODE_RIGHT. CODE_LEFT and
11450 CODE_RIGHT may be ERROR_MARK, which means that that side of the
11451 expression was not formed using a binary or unary operator, or it
11452 was enclosed in parentheses. */
11455 warn_about_parentheses (location_t loc
, enum tree_code code
,
11456 enum tree_code code_left
, tree arg_left
,
11457 enum tree_code code_right
, tree arg_right
)
11459 if (!warn_parentheses
)
11462 /* This macro tests that the expression ARG with original tree code
11463 CODE appears to be a boolean expression. or the result of folding a
11464 boolean expression. */
11465 #define APPEARS_TO_BE_BOOLEAN_EXPR_P(CODE, ARG) \
11466 (truth_value_p (TREE_CODE (ARG)) \
11467 || TREE_CODE (TREE_TYPE (ARG)) == BOOLEAN_TYPE \
11468 /* Folding may create 0 or 1 integers from other expressions. */ \
11469 || ((CODE) != INTEGER_CST \
11470 && (integer_onep (ARG) || integer_zerop (ARG))))
11475 if (code_left
== PLUS_EXPR
)
11476 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11477 "suggest parentheses around %<+%> inside %<<<%>");
11478 else if (code_right
== PLUS_EXPR
)
11479 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11480 "suggest parentheses around %<+%> inside %<<<%>");
11481 else if (code_left
== MINUS_EXPR
)
11482 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11483 "suggest parentheses around %<-%> inside %<<<%>");
11484 else if (code_right
== MINUS_EXPR
)
11485 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11486 "suggest parentheses around %<-%> inside %<<<%>");
11490 if (code_left
== PLUS_EXPR
)
11491 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11492 "suggest parentheses around %<+%> inside %<>>%>");
11493 else if (code_right
== PLUS_EXPR
)
11494 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11495 "suggest parentheses around %<+%> inside %<>>%>");
11496 else if (code_left
== MINUS_EXPR
)
11497 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11498 "suggest parentheses around %<-%> inside %<>>%>");
11499 else if (code_right
== MINUS_EXPR
)
11500 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11501 "suggest parentheses around %<-%> inside %<>>%>");
11504 case TRUTH_ORIF_EXPR
:
11505 if (code_left
== TRUTH_ANDIF_EXPR
)
11506 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11507 "suggest parentheses around %<&&%> within %<||%>");
11508 else if (code_right
== TRUTH_ANDIF_EXPR
)
11509 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11510 "suggest parentheses around %<&&%> within %<||%>");
11514 if (code_left
== BIT_AND_EXPR
|| code_left
== BIT_XOR_EXPR
11515 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
)
11516 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11517 "suggest parentheses around arithmetic in operand of %<|%>");
11518 else if (code_right
== BIT_AND_EXPR
|| code_right
== BIT_XOR_EXPR
11519 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
11520 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11521 "suggest parentheses around arithmetic in operand of %<|%>");
11522 /* Check cases like x|y==z */
11523 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11524 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11525 "suggest parentheses around comparison in operand of %<|%>");
11526 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11527 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11528 "suggest parentheses around comparison in operand of %<|%>");
11529 /* Check cases like !x | y */
11530 else if (code_left
== TRUTH_NOT_EXPR
11531 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
11532 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11533 "suggest parentheses around operand of "
11534 "%<!%> or change %<|%> to %<||%> or %<!%> to %<~%>");
11538 if (code_left
== BIT_AND_EXPR
11539 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
)
11540 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11541 "suggest parentheses around arithmetic in operand of %<^%>");
11542 else if (code_right
== BIT_AND_EXPR
11543 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
11544 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11545 "suggest parentheses around arithmetic in operand of %<^%>");
11546 /* Check cases like x^y==z */
11547 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11548 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11549 "suggest parentheses around comparison in operand of %<^%>");
11550 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11551 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11552 "suggest parentheses around comparison in operand of %<^%>");
11556 if (code_left
== PLUS_EXPR
)
11557 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11558 "suggest parentheses around %<+%> in operand of %<&%>");
11559 else if (code_right
== PLUS_EXPR
)
11560 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11561 "suggest parentheses around %<+%> in operand of %<&%>");
11562 else if (code_left
== MINUS_EXPR
)
11563 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11564 "suggest parentheses around %<-%> in operand of %<&%>");
11565 else if (code_right
== MINUS_EXPR
)
11566 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11567 "suggest parentheses around %<-%> in operand of %<&%>");
11568 /* Check cases like x&y==z */
11569 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11570 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11571 "suggest parentheses around comparison in operand of %<&%>");
11572 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11573 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11574 "suggest parentheses around comparison in operand of %<&%>");
11575 /* Check cases like !x & y */
11576 else if (code_left
== TRUTH_NOT_EXPR
11577 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
11578 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11579 "suggest parentheses around operand of "
11580 "%<!%> or change %<&%> to %<&&%> or %<!%> to %<~%>");
11584 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11585 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11586 "suggest parentheses around comparison in operand of %<==%>");
11587 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11588 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11589 "suggest parentheses around comparison in operand of %<==%>");
11592 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
)
11593 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11594 "suggest parentheses around comparison in operand of %<!=%>");
11595 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
)
11596 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11597 "suggest parentheses around comparison in operand of %<!=%>");
11601 if (TREE_CODE_CLASS (code
) == tcc_comparison
)
11603 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
11604 && code_left
!= NE_EXPR
&& code_left
!= EQ_EXPR
11605 && INTEGRAL_TYPE_P (TREE_TYPE (arg_left
)))
11606 warning_at (EXPR_LOC_OR_LOC (arg_left
, loc
), OPT_Wparentheses
,
11607 "comparisons like %<X<=Y<=Z%> do not "
11608 "have their mathematical meaning");
11609 else if (TREE_CODE_CLASS (code_right
) == tcc_comparison
11610 && code_right
!= NE_EXPR
&& code_right
!= EQ_EXPR
11611 && INTEGRAL_TYPE_P (TREE_TYPE (arg_right
)))
11612 warning_at (EXPR_LOC_OR_LOC (arg_right
, loc
), OPT_Wparentheses
,
11613 "comparisons like %<X<=Y<=Z%> do not "
11614 "have their mathematical meaning");
11618 #undef NOT_A_BOOLEAN_EXPR_P
11621 /* If LABEL (a LABEL_DECL) has not been used, issue a warning. */
11624 warn_for_unused_label (tree label
)
11626 if (!TREE_USED (label
))
11628 if (DECL_INITIAL (label
))
11629 warning (OPT_Wunused_label
, "label %q+D defined but not used", label
);
11631 warning (OPT_Wunused_label
, "label %q+D declared but not defined", label
);
11635 /* Warn for division by zero according to the value of DIVISOR. LOC
11636 is the location of the division operator. */
11639 warn_for_div_by_zero (location_t loc
, tree divisor
)
11641 /* If DIVISOR is zero, and has integral or fixed-point type, issue a warning
11642 about division by zero. Do not issue a warning if DIVISOR has a
11643 floating-point type, since we consider 0.0/0.0 a valid way of
11644 generating a NaN. */
11645 if (c_inhibit_evaluation_warnings
== 0
11646 && (integer_zerop (divisor
) || fixed_zerop (divisor
)))
11647 warning_at (loc
, OPT_Wdiv_by_zero
, "division by zero");
11650 /* Subroutine of build_binary_op. Give warnings for comparisons
11651 between signed and unsigned quantities that may fail. Do the
11652 checking based on the original operand trees ORIG_OP0 and ORIG_OP1,
11653 so that casts will be considered, but default promotions won't
11656 LOCATION is the location of the comparison operator.
11658 The arguments of this function map directly to local variables
11659 of build_binary_op. */
11662 warn_for_sign_compare (location_t location
,
11663 tree orig_op0
, tree orig_op1
,
11664 tree op0
, tree op1
,
11665 tree result_type
, enum tree_code resultcode
)
11667 int op0_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op0
));
11668 int op1_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op1
));
11669 int unsignedp0
, unsignedp1
;
11671 /* In C++, check for comparison of different enum types. */
11672 if (c_dialect_cxx()
11673 && TREE_CODE (TREE_TYPE (orig_op0
)) == ENUMERAL_TYPE
11674 && TREE_CODE (TREE_TYPE (orig_op1
)) == ENUMERAL_TYPE
11675 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0
))
11676 != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1
)))
11678 warning_at (location
,
11679 OPT_Wsign_compare
, "comparison between types %qT and %qT",
11680 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
));
11683 /* Do not warn if the comparison is being done in a signed type,
11684 since the signed type will only be chosen if it can represent
11685 all the values of the unsigned type. */
11686 if (!TYPE_UNSIGNED (result_type
))
11688 /* Do not warn if both operands are unsigned. */
11689 else if (op0_signed
== op1_signed
)
11693 tree sop
, uop
, base_type
;
11697 sop
= orig_op0
, uop
= orig_op1
;
11699 sop
= orig_op1
, uop
= orig_op0
;
11701 STRIP_TYPE_NOPS (sop
);
11702 STRIP_TYPE_NOPS (uop
);
11703 base_type
= (TREE_CODE (result_type
) == COMPLEX_TYPE
11704 ? TREE_TYPE (result_type
) : result_type
);
11706 /* Do not warn if the signed quantity is an unsuffixed integer
11707 literal (or some static constant expression involving such
11708 literals or a conditional expression involving such literals)
11709 and it is non-negative. */
11710 if (tree_expr_nonnegative_warnv_p (sop
, &ovf
))
11712 /* Do not warn if the comparison is an equality operation, the
11713 unsigned quantity is an integral constant, and it would fit
11714 in the result if the result were signed. */
11715 else if (TREE_CODE (uop
) == INTEGER_CST
11716 && (resultcode
== EQ_EXPR
|| resultcode
== NE_EXPR
)
11717 && int_fits_type_p (uop
, c_common_signed_type (base_type
)))
11719 /* In C, do not warn if the unsigned quantity is an enumeration
11720 constant and its maximum value would fit in the result if the
11721 result were signed. */
11722 else if (!c_dialect_cxx() && TREE_CODE (uop
) == INTEGER_CST
11723 && TREE_CODE (TREE_TYPE (uop
)) == ENUMERAL_TYPE
11724 && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (uop
)),
11725 c_common_signed_type (base_type
)))
11728 warning_at (location
,
11730 "comparison between signed and unsigned integer expressions");
11733 /* Warn if two unsigned values are being compared in a size larger
11734 than their original size, and one (and only one) is the result of
11735 a `~' operator. This comparison will always fail.
11737 Also warn if one operand is a constant, and the constant does not
11738 have all bits set that are set in the ~ operand when it is
11741 op0
= c_common_get_narrower (op0
, &unsignedp0
);
11742 op1
= c_common_get_narrower (op1
, &unsignedp1
);
11744 if ((TREE_CODE (op0
) == BIT_NOT_EXPR
)
11745 ^ (TREE_CODE (op1
) == BIT_NOT_EXPR
))
11747 if (TREE_CODE (op0
) == BIT_NOT_EXPR
)
11748 op0
= c_common_get_narrower (TREE_OPERAND (op0
, 0), &unsignedp0
);
11749 if (TREE_CODE (op1
) == BIT_NOT_EXPR
)
11750 op1
= c_common_get_narrower (TREE_OPERAND (op1
, 0), &unsignedp1
);
11752 if (tree_fits_shwi_p (op0
) || tree_fits_shwi_p (op1
))
11755 HOST_WIDE_INT constant
, mask
;
11759 if (tree_fits_shwi_p (op0
))
11762 unsignedp
= unsignedp1
;
11763 constant
= tree_to_shwi (op0
);
11768 unsignedp
= unsignedp0
;
11769 constant
= tree_to_shwi (op1
);
11772 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
11773 if (bits
< TYPE_PRECISION (result_type
)
11774 && bits
< HOST_BITS_PER_LONG
&& unsignedp
)
11776 mask
= (~ (HOST_WIDE_INT
) 0) << bits
;
11777 if ((mask
& constant
) != mask
)
11780 warning_at (location
, OPT_Wsign_compare
,
11781 "promoted ~unsigned is always non-zero");
11783 warning_at (location
, OPT_Wsign_compare
,
11784 "comparison of promoted ~unsigned with constant");
11788 else if (unsignedp0
&& unsignedp1
11789 && (TYPE_PRECISION (TREE_TYPE (op0
))
11790 < TYPE_PRECISION (result_type
))
11791 && (TYPE_PRECISION (TREE_TYPE (op1
))
11792 < TYPE_PRECISION (result_type
)))
11793 warning_at (location
, OPT_Wsign_compare
,
11794 "comparison of promoted ~unsigned with unsigned");
11798 /* RESULT_TYPE is the result of converting TYPE1 and TYPE2 to a common
11799 type via c_common_type. If -Wdouble-promotion is in use, and the
11800 conditions for warning have been met, issue a warning. GMSGID is
11801 the warning message. It must have two %T specifiers for the type
11802 that was converted (generally "float") and the type to which it was
11803 converted (generally "double), respectively. LOC is the location
11804 to which the awrning should refer. */
11807 do_warn_double_promotion (tree result_type
, tree type1
, tree type2
,
11808 const char *gmsgid
, location_t loc
)
11812 if (!warn_double_promotion
)
11814 /* If the conversion will not occur at run-time, there is no need to
11816 if (c_inhibit_evaluation_warnings
)
11818 if (TYPE_MAIN_VARIANT (result_type
) != double_type_node
11819 && TYPE_MAIN_VARIANT (result_type
) != complex_double_type_node
)
11821 if (TYPE_MAIN_VARIANT (type1
) == float_type_node
11822 || TYPE_MAIN_VARIANT (type1
) == complex_float_type_node
)
11823 source_type
= type1
;
11824 else if (TYPE_MAIN_VARIANT (type2
) == float_type_node
11825 || TYPE_MAIN_VARIANT (type2
) == complex_float_type_node
)
11826 source_type
= type2
;
11829 warning_at (loc
, OPT_Wdouble_promotion
, gmsgid
, source_type
, result_type
);
11832 /* Setup a TYPE_DECL node as a typedef representation.
11834 X is a TYPE_DECL for a typedef statement. Create a brand new
11835 ..._TYPE node (which will be just a variant of the existing
11836 ..._TYPE node with identical properties) and then install X
11837 as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
11839 The whole point here is to end up with a situation where each
11840 and every ..._TYPE node the compiler creates will be uniquely
11841 associated with AT MOST one node representing a typedef name.
11842 This way, even though the compiler substitutes corresponding
11843 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
11844 early on, later parts of the compiler can always do the reverse
11845 translation and get back the corresponding typedef name. For
11848 typedef struct S MY_TYPE;
11851 Later parts of the compiler might only know that `object' was of
11852 type `struct S' if it were not for code just below. With this
11853 code however, later parts of the compiler see something like:
11855 struct S' == struct S
11856 typedef struct S' MY_TYPE;
11859 And they can then deduce (from the node for type struct S') that
11860 the original object declaration was:
11864 Being able to do this is important for proper support of protoize,
11865 and also for generating precise symbolic debugging information
11866 which takes full account of the programmer's (typedef) vocabulary.
11868 Obviously, we don't want to generate a duplicate ..._TYPE node if
11869 the TYPE_DECL node that we are now processing really represents a
11870 standard built-in type. */
11873 set_underlying_type (tree x
)
11875 if (x
== error_mark_node
)
11877 if (DECL_IS_BUILTIN (x
))
11879 if (TYPE_NAME (TREE_TYPE (x
)) == 0)
11880 TYPE_NAME (TREE_TYPE (x
)) = x
;
11882 else if (TREE_TYPE (x
) != error_mark_node
11883 && DECL_ORIGINAL_TYPE (x
) == NULL_TREE
)
11885 tree tt
= TREE_TYPE (x
);
11886 DECL_ORIGINAL_TYPE (x
) = tt
;
11887 tt
= build_variant_type_copy (tt
);
11888 TYPE_STUB_DECL (tt
) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x
));
11889 TYPE_NAME (tt
) = x
;
11890 TREE_USED (tt
) = TREE_USED (x
);
11891 TREE_TYPE (x
) = tt
;
11895 /* Record the types used by the current global variable declaration
11896 being parsed, so that we can decide later to emit their debug info.
11897 Those types are in types_used_by_cur_var_decl, and we are going to
11898 store them in the types_used_by_vars_hash hash table.
11899 DECL is the declaration of the global variable that has been parsed. */
11902 record_types_used_by_current_var_decl (tree decl
)
11904 gcc_assert (decl
&& DECL_P (decl
) && TREE_STATIC (decl
));
11906 while (types_used_by_cur_var_decl
&& !types_used_by_cur_var_decl
->is_empty ())
11908 tree type
= types_used_by_cur_var_decl
->pop ();
11909 types_used_by_var_decl_insert (type
, decl
);
11913 /* If DECL is a typedef that is declared in the current function,
11914 record it for the purpose of -Wunused-local-typedefs. */
11917 record_locally_defined_typedef (tree decl
)
11919 struct c_language_function
*l
;
11921 if (!warn_unused_local_typedefs
11923 /* if this is not a locally defined typedef then we are not
11925 || !is_typedef_decl (decl
)
11926 || !decl_function_context (decl
))
11929 l
= (struct c_language_function
*) cfun
->language
;
11930 vec_safe_push (l
->local_typedefs
, decl
);
11933 /* If T is a TYPE_DECL declared locally, mark it as used. */
11936 maybe_record_typedef_use (tree t
)
11938 if (!is_typedef_decl (t
))
11941 TREE_USED (t
) = true;
11944 /* Warn if there are some unused locally defined typedefs in the
11945 current function. */
11948 maybe_warn_unused_local_typedefs (void)
11952 /* The number of times we have emitted -Wunused-local-typedefs
11953 warnings. If this is different from errorcount, that means some
11954 unrelated errors have been issued. In which case, we'll avoid
11955 emitting "unused-local-typedefs" warnings. */
11956 static int unused_local_typedefs_warn_count
;
11957 struct c_language_function
*l
;
11962 if ((l
= (struct c_language_function
*) cfun
->language
) == NULL
)
11965 if (warn_unused_local_typedefs
11966 && errorcount
== unused_local_typedefs_warn_count
)
11968 FOR_EACH_VEC_SAFE_ELT (l
->local_typedefs
, i
, decl
)
11969 if (!TREE_USED (decl
))
11970 warning_at (DECL_SOURCE_LOCATION (decl
),
11971 OPT_Wunused_local_typedefs
,
11972 "typedef %qD locally defined but not used", decl
);
11973 unused_local_typedefs_warn_count
= errorcount
;
11976 vec_free (l
->local_typedefs
);
11979 /* Warn about boolean expression compared with an integer value different
11980 from true/false. Warns also e.g. about "(i1 == i2) == 2".
11981 LOC is the location of the comparison, CODE is its code, OP0 and OP1
11982 are the operands of the comparison. The caller must ensure that
11983 either operand is a boolean expression. */
11986 maybe_warn_bool_compare (location_t loc
, enum tree_code code
, tree op0
,
11989 if (TREE_CODE_CLASS (code
) != tcc_comparison
)
11992 tree cst
= (TREE_CODE (op0
) == INTEGER_CST
)
11993 ? op0
: (TREE_CODE (op1
) == INTEGER_CST
) ? op1
: NULL_TREE
;
11997 if (!integer_zerop (cst
) && !integer_onep (cst
))
11999 int sign
= (TREE_CODE (op0
) == INTEGER_CST
)
12000 ? tree_int_cst_sgn (cst
) : -tree_int_cst_sgn (cst
);
12001 if (code
== EQ_EXPR
12002 || ((code
== GT_EXPR
|| code
== GE_EXPR
) && sign
< 0)
12003 || ((code
== LT_EXPR
|| code
== LE_EXPR
) && sign
> 0))
12004 warning_at (loc
, OPT_Wbool_compare
, "comparison of constant %qE "
12005 "with boolean expression is always false", cst
);
12007 warning_at (loc
, OPT_Wbool_compare
, "comparison of constant %qE "
12008 "with boolean expression is always true", cst
);
12012 /* The C and C++ parsers both use vectors to hold function arguments.
12013 For efficiency, we keep a cache of unused vectors. This is the
12016 typedef vec
<tree
, va_gc
> *tree_gc_vec
;
12017 static GTY((deletable
)) vec
<tree_gc_vec
, va_gc
> *tree_vector_cache
;
12019 /* Return a new vector from the cache. If the cache is empty,
12020 allocate a new vector. These vectors are GC'ed, so it is OK if the
12021 pointer is not released.. */
12024 make_tree_vector (void)
12026 if (tree_vector_cache
&& !tree_vector_cache
->is_empty ())
12027 return tree_vector_cache
->pop ();
12030 /* Passing 0 to vec::alloc returns NULL, and our callers require
12031 that we always return a non-NULL value. The vector code uses
12032 4 when growing a NULL vector, so we do too. */
12033 vec
<tree
, va_gc
> *v
;
12039 /* Release a vector of trees back to the cache. */
12042 release_tree_vector (vec
<tree
, va_gc
> *vec
)
12047 vec_safe_push (tree_vector_cache
, vec
);
12051 /* Get a new tree vector holding a single tree. */
12054 make_tree_vector_single (tree t
)
12056 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
12057 ret
->quick_push (t
);
12061 /* Get a new tree vector of the TREE_VALUEs of a TREE_LIST chain. */
12064 make_tree_vector_from_list (tree list
)
12066 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
12067 for (; list
; list
= TREE_CHAIN (list
))
12068 vec_safe_push (ret
, TREE_VALUE (list
));
12072 /* Get a new tree vector which is a copy of an existing one. */
12075 make_tree_vector_copy (const vec
<tree
, va_gc
> *orig
)
12077 vec
<tree
, va_gc
> *ret
;
12081 ret
= make_tree_vector ();
12082 vec_safe_reserve (ret
, vec_safe_length (orig
));
12083 FOR_EACH_VEC_SAFE_ELT (orig
, ix
, t
)
12084 ret
->quick_push (t
);
12088 /* Return true if KEYWORD starts a type specifier. */
12091 keyword_begins_type_specifier (enum rid keyword
)
12095 case RID_AUTO_TYPE
:
12107 case RID_DFLOAT128
:
12123 if (keyword
>= RID_FIRST_INT_N
12124 && keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
12125 && int_n_enabled_p
[keyword
-RID_FIRST_INT_N
])
12131 /* Return true if KEYWORD names a type qualifier. */
12134 keyword_is_type_qualifier (enum rid keyword
)
12148 /* Return true if KEYWORD names a storage class specifier.
12150 RID_TYPEDEF is not included in this list despite `typedef' being
12151 listed in C99 6.7.1.1. 6.7.1.3 indicates that `typedef' is listed as
12152 such for syntactic convenience only. */
12155 keyword_is_storage_class_specifier (enum rid keyword
)
12171 /* Return true if KEYWORD names a function-specifier [dcl.fct.spec]. */
12174 keyword_is_function_specifier (enum rid keyword
)
12188 /* Return true if KEYWORD names a decl-specifier [dcl.spec] or a
12189 declaration-specifier (C99 6.7). */
12192 keyword_is_decl_specifier (enum rid keyword
)
12194 if (keyword_is_storage_class_specifier (keyword
)
12195 || keyword_is_type_qualifier (keyword
)
12196 || keyword_is_function_specifier (keyword
))
12203 case RID_CONSTEXPR
:
12210 /* Initialize language-specific-bits of tree_contains_struct. */
12213 c_common_init_ts (void)
12215 MARK_TS_TYPED (C_MAYBE_CONST_EXPR
);
12216 MARK_TS_TYPED (EXCESS_PRECISION_EXPR
);
12217 MARK_TS_TYPED (ARRAY_NOTATION_REF
);
12218 MARK_TS_COMMON (UPC_FORALL_STMT
);
12219 MARK_TS_COMMON (UPC_SYNC_STMT
);
12222 /* Build a user-defined numeric literal out of an integer constant type VALUE
12223 with identifier SUFFIX. */
12226 build_userdef_literal (tree suffix_id
, tree value
,
12227 enum overflow_type overflow
, tree num_string
)
12229 tree literal
= make_node (USERDEF_LITERAL
);
12230 USERDEF_LITERAL_SUFFIX_ID (literal
) = suffix_id
;
12231 USERDEF_LITERAL_VALUE (literal
) = value
;
12232 USERDEF_LITERAL_OVERFLOW (literal
) = overflow
;
12233 USERDEF_LITERAL_NUM_STRING (literal
) = num_string
;
12237 /* For vector[index], convert the vector to a
12238 pointer of the underlying type. Return true if the resulting
12239 ARRAY_REF should not be an lvalue. */
12242 convert_vector_to_pointer_for_subscript (location_t loc
,
12243 tree
*vecp
, tree index
)
12246 if (TREE_CODE (TREE_TYPE (*vecp
)) == VECTOR_TYPE
)
12248 tree type
= TREE_TYPE (*vecp
);
12251 ret
= !lvalue_p (*vecp
);
12252 if (TREE_CODE (index
) == INTEGER_CST
)
12253 if (!tree_fits_uhwi_p (index
)
12254 || tree_to_uhwi (index
) >= TYPE_VECTOR_SUBPARTS (type
))
12255 warning_at (loc
, OPT_Warray_bounds
, "index value is out of bound");
12259 tree tmp
= create_tmp_var_raw (type
);
12260 DECL_SOURCE_LOCATION (tmp
) = loc
;
12261 *vecp
= c_save_expr (*vecp
);
12262 if (TREE_CODE (*vecp
) == C_MAYBE_CONST_EXPR
)
12264 bool non_const
= C_MAYBE_CONST_EXPR_NON_CONST (*vecp
);
12265 *vecp
= C_MAYBE_CONST_EXPR_EXPR (*vecp
);
12267 = c_wrap_maybe_const (build4 (TARGET_EXPR
, type
, tmp
,
12268 *vecp
, NULL_TREE
, NULL_TREE
),
12272 *vecp
= build4 (TARGET_EXPR
, type
, tmp
, *vecp
,
12273 NULL_TREE
, NULL_TREE
);
12274 SET_EXPR_LOCATION (*vecp
, loc
);
12275 c_common_mark_addressable_vec (tmp
);
12278 c_common_mark_addressable_vec (*vecp
);
12279 type
= build_qualified_type (TREE_TYPE (type
), TYPE_QUALS (type
));
12280 type1
= build_pointer_type (TREE_TYPE (*vecp
));
12281 bool ref_all
= TYPE_REF_CAN_ALIAS_ALL (type1
);
12283 && !DECL_P (*vecp
))
12285 /* If the original vector isn't declared may_alias and it
12286 isn't a bare vector look if the subscripting would
12287 alias the vector we subscript, and if not, force ref-all. */
12288 alias_set_type vecset
= get_alias_set (*vecp
);
12289 alias_set_type sset
= get_alias_set (type
);
12290 if (!alias_sets_must_conflict_p (sset
, vecset
)
12291 && !alias_set_subset_of (sset
, vecset
))
12294 type
= build_pointer_type_for_mode (type
, ptr_mode
, ref_all
);
12295 *vecp
= build1 (ADDR_EXPR
, type1
, *vecp
);
12296 *vecp
= convert (type
, *vecp
);
12301 /* Determine which of the operands, if any, is a scalar that needs to be
12302 converted to a vector, for the range of operations. */
12304 scalar_to_vector (location_t loc
, enum tree_code code
, tree op0
, tree op1
,
12307 tree type0
= TREE_TYPE (op0
);
12308 tree type1
= TREE_TYPE (op1
);
12309 bool integer_only_op
= false;
12310 enum stv_conv ret
= stv_firstarg
;
12312 gcc_assert (TREE_CODE (type0
) == VECTOR_TYPE
12313 || TREE_CODE (type1
) == VECTOR_TYPE
);
12316 /* Most GENERIC binary expressions require homogeneous arguments.
12317 LSHIFT_EXPR and RSHIFT_EXPR are exceptions and accept a first
12318 argument that is a vector and a second one that is a scalar, so
12319 we never return stv_secondarg for them. */
12322 if (TREE_CODE (type0
) == INTEGER_TYPE
12323 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
12325 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
12328 error_at (loc
, "conversion of scalar %qT to vector %qT "
12329 "involves truncation", type0
, type1
);
12333 return stv_firstarg
;
12340 integer_only_op
= true;
12341 /* ... fall through ... */
12343 case VEC_COND_EXPR
:
12348 case TRUNC_DIV_EXPR
:
12349 case CEIL_DIV_EXPR
:
12350 case FLOOR_DIV_EXPR
:
12351 case ROUND_DIV_EXPR
:
12352 case EXACT_DIV_EXPR
:
12353 case TRUNC_MOD_EXPR
:
12354 case FLOOR_MOD_EXPR
:
12362 /* What about UNLT_EXPR? */
12363 if (TREE_CODE (type0
) == VECTOR_TYPE
)
12366 ret
= stv_secondarg
;
12367 /* Swap TYPE0 with TYPE1 and OP0 with OP1 */
12368 tmp
= type0
; type0
= type1
; type1
= tmp
;
12369 tmp
= op0
; op0
= op1
; op1
= tmp
;
12372 if (TREE_CODE (type0
) == INTEGER_TYPE
12373 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
12375 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
12378 error_at (loc
, "conversion of scalar %qT to vector %qT "
12379 "involves truncation", type0
, type1
);
12384 else if (!integer_only_op
12385 /* Allow integer --> real conversion if safe. */
12386 && (TREE_CODE (type0
) == REAL_TYPE
12387 || TREE_CODE (type0
) == INTEGER_TYPE
)
12388 && SCALAR_FLOAT_TYPE_P (TREE_TYPE (type1
)))
12390 if (unsafe_conversion_p (loc
, TREE_TYPE (type1
), op0
, false))
12393 error_at (loc
, "conversion of scalar %qT to vector %qT "
12394 "involves truncation", type0
, type1
);
12403 return stv_nothing
;
12406 /* Return true iff ALIGN is an integral constant that is a fundamental
12407 alignment, as defined by [basic.align] in the c++-11
12412 [A fundamental alignment is represented by an alignment less than or
12413 equal to the greatest alignment supported by the implementation
12414 in all contexts, which is equal to
12415 alignof(max_align_t)]. */
12418 cxx_fundamental_alignment_p (unsigned align
)
12420 return (align
<= MAX (TYPE_ALIGN (long_long_integer_type_node
),
12421 TYPE_ALIGN (long_double_type_node
)));
12424 /* Return true if T is a pointer to a zero-sized aggregate. */
12427 pointer_to_zero_sized_aggr_p (tree t
)
12429 if (!POINTER_TYPE_P (t
))
12432 return (TYPE_SIZE (t
) && integer_zerop (TYPE_SIZE (t
)));
12435 #include "gt-c-family-c-common.h"