1 /* Subroutines shared by all languages that are variants of C.
2 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
37 #include "common/common-target.h"
38 #include "langhooks.h"
39 #include "tree-inline.h"
41 #include "diagnostic.h"
42 #include "tree-iterator.h"
44 #include "tree-mudflap.h"
47 #include "target-def.h"
49 cpp_reader
*parse_in
; /* Declared in c-pragma.h. */
51 /* The following symbols are subsumed in the c_global_trees array, and
52 listed here individually for documentation purposes.
54 INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
56 tree short_integer_type_node;
57 tree long_integer_type_node;
58 tree long_long_integer_type_node;
59 tree int128_integer_type_node;
61 tree short_unsigned_type_node;
62 tree long_unsigned_type_node;
63 tree long_long_unsigned_type_node;
64 tree int128_unsigned_type_node;
66 tree truthvalue_type_node;
67 tree truthvalue_false_node;
68 tree truthvalue_true_node;
70 tree ptrdiff_type_node;
72 tree unsigned_char_type_node;
73 tree signed_char_type_node;
76 tree char16_type_node;
77 tree char32_type_node;
80 tree double_type_node;
81 tree long_double_type_node;
83 tree complex_integer_type_node;
84 tree complex_float_type_node;
85 tree complex_double_type_node;
86 tree complex_long_double_type_node;
88 tree dfloat32_type_node;
89 tree dfloat64_type_node;
90 tree_dfloat128_type_node;
98 tree unsigned_intQI_type_node;
99 tree unsigned_intHI_type_node;
100 tree unsigned_intSI_type_node;
101 tree unsigned_intDI_type_node;
102 tree unsigned_intTI_type_node;
104 tree widest_integer_literal_type_node;
105 tree widest_unsigned_literal_type_node;
107 Nodes for types `void *' and `const void *'.
109 tree ptr_type_node, const_ptr_type_node;
111 Nodes for types `char *' and `const char *'.
113 tree string_type_node, const_string_type_node;
115 Type `char[SOMENUMBER]'.
116 Used when an array of char is needed and the size is irrelevant.
118 tree char_array_type_node;
120 Type `int[SOMENUMBER]' or something like it.
121 Used when an array of int needed and the size is irrelevant.
123 tree int_array_type_node;
125 Type `wchar_t[SOMENUMBER]' or something like it.
126 Used when a wide string literal is created.
128 tree wchar_array_type_node;
130 Type `char16_t[SOMENUMBER]' or something like it.
131 Used when a UTF-16 string literal is created.
133 tree char16_array_type_node;
135 Type `char32_t[SOMENUMBER]' or something like it.
136 Used when a UTF-32 string literal is created.
138 tree char32_array_type_node;
140 Type `int ()' -- used for implicit declaration of functions.
142 tree default_function_type;
144 A VOID_TYPE node, packaged in a TREE_LIST.
148 The lazily created VAR_DECLs for __FUNCTION__, __PRETTY_FUNCTION__,
149 and __func__. (C doesn't generate __FUNCTION__ and__PRETTY_FUNCTION__
150 VAR_DECLS, but C++ does.)
152 tree function_name_decl_node;
153 tree pretty_function_name_decl_node;
154 tree c99_function_name_decl_node;
156 Stack of nested function name VAR_DECLs.
158 tree saved_function_name_decls;
162 tree c_global_trees
[CTI_MAX
];
164 /* Switches common to the C front ends. */
166 /* Nonzero means don't output line number information. */
168 char flag_no_line_commands
;
170 /* Nonzero causes -E output not to be done, but directives such as
171 #define that have side effects are still obeyed. */
175 /* Nonzero means dump macros in some fashion. */
177 char flag_dump_macros
;
179 /* Nonzero means pass #include lines through to the output. */
181 char flag_dump_includes
;
183 /* Nonzero means process PCH files while preprocessing. */
185 bool flag_pch_preprocess
;
187 /* The file name to which we should write a precompiled header, or
188 NULL if no header will be written in this compile. */
190 const char *pch_file
;
192 /* Nonzero if an ISO standard was selected. It rejects macros in the
196 /* Warn about #pragma directives that are not recognized. */
198 int warn_unknown_pragmas
; /* Tri state variable. */
200 /* Warn about format/argument anomalies in calls to formatted I/O functions
201 (*printf, *scanf, strftime, strfmon, etc.). */
205 /* C/ObjC language option variables. */
208 /* Nonzero means allow type mismatches in conditional expressions;
209 just make their values `void'. */
211 int flag_cond_mismatch
;
213 /* Nonzero means enable C89 Amendment 1 features. */
217 /* Nonzero means use the ISO C99 (or C11) dialect of C. */
221 /* Nonzero means use the ISO C11 dialect of C. */
225 /* Nonzero means that we have builtin functions, and main is an int. */
230 /* ObjC language option variables. */
233 /* Tells the compiler that this is a special run. Do not perform any
234 compiling, instead we are to test some platform dependent features
235 and output a C header file with appropriate definitions. */
237 int print_struct_values
;
239 /* Tells the compiler what is the constant string class for ObjC. */
241 const char *constant_string_class_name
;
244 /* C++ language option variables. */
247 /* Nonzero means generate separate instantiation control files and
248 juggle them at link time. */
250 int flag_use_repository
;
252 /* The C++ dialect being used. C++98 is the default. */
254 enum cxx_dialect cxx_dialect
= cxx98
;
256 /* Maximum template instantiation depth. This limit exists to limit the
257 time it takes to notice excessively recursive template instantiations.
259 The default is lower than the 1024 recommended by the C++0x standard
260 because G++ runs out of stack before 1024 with highly recursive template
261 argument deduction substitution (g++.dg/cpp0x/enum11.C). */
263 int max_tinst_depth
= 900;
265 /* The elements of `ridpointers' are identifier nodes for the reserved
266 type names and storage classes. It is indexed by a RID_... value. */
269 tree (*make_fname_decl
) (location_t
, tree
, int);
271 /* Nonzero means don't warn about problems that occur when the code is
273 int c_inhibit_evaluation_warnings
;
275 /* Whether we are building a boolean conversion inside
276 convert_for_assignment, or some other late binary operation. If
277 build_binary_op is called for C (from code shared by C and C++) in
278 this case, then the operands have already been folded and the
279 result will not be folded again, so C_MAYBE_CONST_EXPR should not
281 bool in_late_binary_op
;
283 /* Whether lexing has been completed, so subsequent preprocessor
284 errors should use the compiler's input_location. */
285 bool done_lexing
= false;
287 /* Information about how a function name is generated. */
290 tree
*const decl
; /* pointer to the VAR_DECL. */
291 const unsigned rid
; /* RID number for the identifier. */
292 const int pretty
; /* How pretty is it? */
295 /* The three ways of getting then name of the current function. */
297 const struct fname_var_t fname_vars
[] =
299 /* C99 compliant __func__, must be first. */
300 {&c99_function_name_decl_node
, RID_C99_FUNCTION_NAME
, 0},
301 /* GCC __FUNCTION__ compliant. */
302 {&function_name_decl_node
, RID_FUNCTION_NAME
, 0},
303 /* GCC __PRETTY_FUNCTION__ compliant. */
304 {&pretty_function_name_decl_node
, RID_PRETTY_FUNCTION_NAME
, 1},
308 /* Global visibility options. */
309 struct visibility_flags visibility_options
;
311 static tree
c_fully_fold_internal (tree expr
, bool, bool *, bool *);
312 static tree
check_case_value (tree
);
313 static bool check_case_bounds (tree
, tree
, tree
*, tree
*);
315 static tree
handle_packed_attribute (tree
*, tree
, tree
, int, bool *);
316 static tree
handle_nocommon_attribute (tree
*, tree
, tree
, int, bool *);
317 static tree
handle_common_attribute (tree
*, tree
, tree
, int, bool *);
318 static tree
handle_noreturn_attribute (tree
*, tree
, tree
, int, bool *);
319 static tree
handle_hot_attribute (tree
*, tree
, tree
, int, bool *);
320 static tree
handle_cold_attribute (tree
*, tree
, tree
, int, bool *);
321 static tree
handle_noinline_attribute (tree
*, tree
, tree
, int, bool *);
322 static tree
handle_noclone_attribute (tree
*, tree
, tree
, int, bool *);
323 static tree
handle_leaf_attribute (tree
*, tree
, tree
, int, bool *);
324 static tree
handle_always_inline_attribute (tree
*, tree
, tree
, int,
326 static tree
handle_gnu_inline_attribute (tree
*, tree
, tree
, int, bool *);
327 static tree
handle_artificial_attribute (tree
*, tree
, tree
, int, bool *);
328 static tree
handle_flatten_attribute (tree
*, tree
, tree
, int, bool *);
329 static tree
handle_error_attribute (tree
*, tree
, tree
, int, bool *);
330 static tree
handle_used_attribute (tree
*, tree
, tree
, int, bool *);
331 static tree
handle_unused_attribute (tree
*, tree
, tree
, int, bool *);
332 static tree
handle_externally_visible_attribute (tree
*, tree
, tree
, int,
334 static tree
handle_const_attribute (tree
*, tree
, tree
, int, bool *);
335 static tree
handle_transparent_union_attribute (tree
*, tree
, tree
,
337 static tree
handle_constructor_attribute (tree
*, tree
, tree
, int, bool *);
338 static tree
handle_destructor_attribute (tree
*, tree
, tree
, int, bool *);
339 static tree
handle_mode_attribute (tree
*, tree
, tree
, int, bool *);
340 static tree
handle_section_attribute (tree
*, tree
, tree
, int, bool *);
341 static tree
handle_aligned_attribute (tree
*, tree
, tree
, int, bool *);
342 static tree
handle_weak_attribute (tree
*, tree
, tree
, int, bool *) ;
343 static tree
handle_alias_ifunc_attribute (bool, tree
*, tree
, tree
, bool *);
344 static tree
handle_ifunc_attribute (tree
*, tree
, tree
, int, bool *);
345 static tree
handle_alias_attribute (tree
*, tree
, tree
, int, bool *);
346 static tree
handle_weakref_attribute (tree
*, tree
, tree
, int, bool *) ;
347 static tree
handle_visibility_attribute (tree
*, tree
, tree
, int,
349 static tree
handle_tls_model_attribute (tree
*, tree
, tree
, int,
351 static tree
handle_no_instrument_function_attribute (tree
*, tree
,
353 static tree
handle_malloc_attribute (tree
*, tree
, tree
, int, bool *);
354 static tree
handle_returns_twice_attribute (tree
*, tree
, tree
, int, bool *);
355 static tree
handle_no_limit_stack_attribute (tree
*, tree
, tree
, int,
357 static tree
handle_pure_attribute (tree
*, tree
, tree
, int, bool *);
358 static tree
handle_tm_attribute (tree
*, tree
, tree
, int, bool *);
359 static tree
handle_tm_wrap_attribute (tree
*, tree
, tree
, int, bool *);
360 static tree
handle_novops_attribute (tree
*, tree
, tree
, int, bool *);
361 static tree
handle_deprecated_attribute (tree
*, tree
, tree
, int,
363 static tree
handle_vector_size_attribute (tree
*, tree
, tree
, int,
365 static tree
handle_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
366 static tree
handle_nothrow_attribute (tree
*, tree
, tree
, int, bool *);
367 static tree
handle_cleanup_attribute (tree
*, tree
, tree
, int, bool *);
368 static tree
handle_warn_unused_result_attribute (tree
*, tree
, tree
, int,
370 static tree
handle_sentinel_attribute (tree
*, tree
, tree
, int, bool *);
371 static tree
handle_type_generic_attribute (tree
*, tree
, tree
, int, bool *);
372 static tree
handle_alloc_size_attribute (tree
*, tree
, tree
, int, bool *);
373 static tree
handle_target_attribute (tree
*, tree
, tree
, int, bool *);
374 static tree
handle_optimize_attribute (tree
*, tree
, tree
, int, bool *);
375 static tree
ignore_attribute (tree
*, tree
, tree
, int, bool *);
376 static tree
handle_no_split_stack_attribute (tree
*, tree
, tree
, int, bool *);
377 static tree
handle_fnspec_attribute (tree
*, tree
, tree
, int, bool *);
379 static void check_function_nonnull (tree
, int, tree
*);
380 static void check_nonnull_arg (void *, tree
, unsigned HOST_WIDE_INT
);
381 static bool nonnull_check_p (tree
, unsigned HOST_WIDE_INT
);
382 static bool get_nonnull_operand (tree
, unsigned HOST_WIDE_INT
*);
383 static int resort_field_decl_cmp (const void *, const void *);
385 /* Reserved words. The third field is a mask: keywords are disabled
386 if they match the mask.
389 C --std=c89: D_C99 | D_CXXONLY | D_OBJC | D_CXX_OBJC
390 C --std=c99: D_CXXONLY | D_OBJC
391 ObjC is like C except that D_OBJC and D_CXX_OBJC are not set
392 C++ --std=c98: D_CONLY | D_CXXOX | D_OBJC
393 C++ --std=c0x: D_CONLY | D_OBJC
394 ObjC++ is like C++ except that D_OBJC is not set
396 If -fno-asm is used, D_ASM is added to the mask. If
397 -fno-gnu-keywords is used, D_EXT is added. If -fno-asm and C in
398 C89 mode, D_EXT89 is added for both -fno-asm and -fno-gnu-keywords.
399 In C with -Wc++-compat, we warn if D_CXXWARN is set.
401 Note the complication of the D_CXX_OBJC keywords. These are
402 reserved words such as 'class'. In C++, 'class' is a reserved
403 word. In Objective-C++ it is too. In Objective-C, it is a
404 reserved word too, but only if it follows an '@' sign.
406 const struct c_common_resword c_common_reswords
[] =
408 { "_Alignas", RID_ALIGNAS
, D_CONLY
},
409 { "_Alignof", RID_ALIGNOF
, D_CONLY
},
410 { "_Bool", RID_BOOL
, D_CONLY
},
411 { "_Complex", RID_COMPLEX
, 0 },
412 { "_Imaginary", RID_IMAGINARY
, D_CONLY
},
413 { "_Decimal32", RID_DFLOAT32
, D_CONLY
| D_EXT
},
414 { "_Decimal64", RID_DFLOAT64
, D_CONLY
| D_EXT
},
415 { "_Decimal128", RID_DFLOAT128
, D_CONLY
| D_EXT
},
416 { "_Fract", RID_FRACT
, D_CONLY
| D_EXT
},
417 { "_Accum", RID_ACCUM
, D_CONLY
| D_EXT
},
418 { "_Sat", RID_SAT
, D_CONLY
| D_EXT
},
419 { "_Static_assert", RID_STATIC_ASSERT
, D_CONLY
},
420 { "_Noreturn", RID_NORETURN
, D_CONLY
},
421 { "__FUNCTION__", RID_FUNCTION_NAME
, 0 },
422 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME
, 0 },
423 { "__alignof", RID_ALIGNOF
, 0 },
424 { "__alignof__", RID_ALIGNOF
, 0 },
425 { "__asm", RID_ASM
, 0 },
426 { "__asm__", RID_ASM
, 0 },
427 { "__attribute", RID_ATTRIBUTE
, 0 },
428 { "__attribute__", RID_ATTRIBUTE
, 0 },
429 { "__bases", RID_BASES
, D_CXXONLY
},
430 { "__builtin_choose_expr", RID_CHOOSE_EXPR
, D_CONLY
},
431 { "__builtin_complex", RID_BUILTIN_COMPLEX
, D_CONLY
},
432 { "__builtin_shuffle", RID_BUILTIN_SHUFFLE
, 0 },
433 { "__builtin_offsetof", RID_OFFSETOF
, 0 },
434 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P
, D_CONLY
},
435 { "__builtin_va_arg", RID_VA_ARG
, 0 },
436 { "__complex", RID_COMPLEX
, 0 },
437 { "__complex__", RID_COMPLEX
, 0 },
438 { "__const", RID_CONST
, 0 },
439 { "__const__", RID_CONST
, 0 },
440 { "__decltype", RID_DECLTYPE
, D_CXXONLY
},
441 { "__direct_bases", RID_DIRECT_BASES
, D_CXXONLY
},
442 { "__extension__", RID_EXTENSION
, 0 },
443 { "__func__", RID_C99_FUNCTION_NAME
, 0 },
444 { "__has_nothrow_assign", RID_HAS_NOTHROW_ASSIGN
, D_CXXONLY
},
445 { "__has_nothrow_constructor", RID_HAS_NOTHROW_CONSTRUCTOR
, D_CXXONLY
},
446 { "__has_nothrow_copy", RID_HAS_NOTHROW_COPY
, D_CXXONLY
},
447 { "__has_trivial_assign", RID_HAS_TRIVIAL_ASSIGN
, D_CXXONLY
},
448 { "__has_trivial_constructor", RID_HAS_TRIVIAL_CONSTRUCTOR
, D_CXXONLY
},
449 { "__has_trivial_copy", RID_HAS_TRIVIAL_COPY
, D_CXXONLY
},
450 { "__has_trivial_destructor", RID_HAS_TRIVIAL_DESTRUCTOR
, D_CXXONLY
},
451 { "__has_virtual_destructor", RID_HAS_VIRTUAL_DESTRUCTOR
, D_CXXONLY
},
452 { "__imag", RID_IMAGPART
, 0 },
453 { "__imag__", RID_IMAGPART
, 0 },
454 { "__inline", RID_INLINE
, 0 },
455 { "__inline__", RID_INLINE
, 0 },
456 { "__int128", RID_INT128
, 0 },
457 { "__is_abstract", RID_IS_ABSTRACT
, D_CXXONLY
},
458 { "__is_base_of", RID_IS_BASE_OF
, D_CXXONLY
},
459 { "__is_class", RID_IS_CLASS
, D_CXXONLY
},
460 { "__is_convertible_to", RID_IS_CONVERTIBLE_TO
, D_CXXONLY
},
461 { "__is_empty", RID_IS_EMPTY
, D_CXXONLY
},
462 { "__is_enum", RID_IS_ENUM
, D_CXXONLY
},
463 { "__is_final", RID_IS_FINAL
, D_CXXONLY
},
464 { "__is_literal_type", RID_IS_LITERAL_TYPE
, D_CXXONLY
},
465 { "__is_pod", RID_IS_POD
, D_CXXONLY
},
466 { "__is_polymorphic", RID_IS_POLYMORPHIC
, D_CXXONLY
},
467 { "__is_standard_layout", RID_IS_STD_LAYOUT
, D_CXXONLY
},
468 { "__is_trivial", RID_IS_TRIVIAL
, D_CXXONLY
},
469 { "__is_union", RID_IS_UNION
, D_CXXONLY
},
470 { "__label__", RID_LABEL
, 0 },
471 { "__null", RID_NULL
, 0 },
472 { "__real", RID_REALPART
, 0 },
473 { "__real__", RID_REALPART
, 0 },
474 { "__restrict", RID_RESTRICT
, 0 },
475 { "__restrict__", RID_RESTRICT
, 0 },
476 { "__signed", RID_SIGNED
, 0 },
477 { "__signed__", RID_SIGNED
, 0 },
478 { "__thread", RID_THREAD
, 0 },
479 { "__transaction_atomic", RID_TRANSACTION_ATOMIC
, 0 },
480 { "__transaction_relaxed", RID_TRANSACTION_RELAXED
, 0 },
481 { "__transaction_cancel", RID_TRANSACTION_CANCEL
, 0 },
482 { "__typeof", RID_TYPEOF
, 0 },
483 { "__typeof__", RID_TYPEOF
, 0 },
484 { "__underlying_type", RID_UNDERLYING_TYPE
, D_CXXONLY
},
485 { "__volatile", RID_VOLATILE
, 0 },
486 { "__volatile__", RID_VOLATILE
, 0 },
487 { "alignof", RID_ALIGNOF
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
488 { "asm", RID_ASM
, D_ASM
},
489 { "auto", RID_AUTO
, 0 },
490 { "bool", RID_BOOL
, D_CXXONLY
| D_CXXWARN
},
491 { "break", RID_BREAK
, 0 },
492 { "case", RID_CASE
, 0 },
493 { "catch", RID_CATCH
, D_CXX_OBJC
| D_CXXWARN
},
494 { "char", RID_CHAR
, 0 },
495 { "char16_t", RID_CHAR16
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
496 { "char32_t", RID_CHAR32
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
497 { "class", RID_CLASS
, D_CXX_OBJC
| D_CXXWARN
},
498 { "const", RID_CONST
, 0 },
499 { "constexpr", RID_CONSTEXPR
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
500 { "const_cast", RID_CONSTCAST
, D_CXXONLY
| D_CXXWARN
},
501 { "continue", RID_CONTINUE
, 0 },
502 { "decltype", RID_DECLTYPE
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
503 { "default", RID_DEFAULT
, 0 },
504 { "delete", RID_DELETE
, D_CXXONLY
| D_CXXWARN
},
506 { "double", RID_DOUBLE
, 0 },
507 { "dynamic_cast", RID_DYNCAST
, D_CXXONLY
| D_CXXWARN
},
508 { "else", RID_ELSE
, 0 },
509 { "enum", RID_ENUM
, 0 },
510 { "explicit", RID_EXPLICIT
, D_CXXONLY
| D_CXXWARN
},
511 { "export", RID_EXPORT
, D_CXXONLY
| D_CXXWARN
},
512 { "extern", RID_EXTERN
, 0 },
513 { "false", RID_FALSE
, D_CXXONLY
| D_CXXWARN
},
514 { "float", RID_FLOAT
, 0 },
515 { "for", RID_FOR
, 0 },
516 { "friend", RID_FRIEND
, D_CXXONLY
| D_CXXWARN
},
517 { "goto", RID_GOTO
, 0 },
519 { "inline", RID_INLINE
, D_EXT89
},
520 { "int", RID_INT
, 0 },
521 { "long", RID_LONG
, 0 },
522 { "mutable", RID_MUTABLE
, D_CXXONLY
| D_CXXWARN
},
523 { "namespace", RID_NAMESPACE
, D_CXXONLY
| D_CXXWARN
},
524 { "new", RID_NEW
, D_CXXONLY
| D_CXXWARN
},
525 { "noexcept", RID_NOEXCEPT
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
526 { "nullptr", RID_NULLPTR
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
527 { "operator", RID_OPERATOR
, D_CXXONLY
| D_CXXWARN
},
528 { "private", RID_PRIVATE
, D_CXX_OBJC
| D_CXXWARN
},
529 { "protected", RID_PROTECTED
, D_CXX_OBJC
| D_CXXWARN
},
530 { "public", RID_PUBLIC
, D_CXX_OBJC
| D_CXXWARN
},
531 { "register", RID_REGISTER
, 0 },
532 { "reinterpret_cast", RID_REINTCAST
, D_CXXONLY
| D_CXXWARN
},
533 { "restrict", RID_RESTRICT
, D_CONLY
| D_C99
},
534 { "return", RID_RETURN
, 0 },
535 { "short", RID_SHORT
, 0 },
536 { "signed", RID_SIGNED
, 0 },
537 { "sizeof", RID_SIZEOF
, 0 },
538 { "static", RID_STATIC
, 0 },
539 { "static_assert", RID_STATIC_ASSERT
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
540 { "static_cast", RID_STATCAST
, D_CXXONLY
| D_CXXWARN
},
541 { "struct", RID_STRUCT
, 0 },
542 { "switch", RID_SWITCH
, 0 },
543 { "template", RID_TEMPLATE
, D_CXXONLY
| D_CXXWARN
},
544 { "this", RID_THIS
, D_CXXONLY
| D_CXXWARN
},
545 { "throw", RID_THROW
, D_CXX_OBJC
| D_CXXWARN
},
546 { "true", RID_TRUE
, D_CXXONLY
| D_CXXWARN
},
547 { "try", RID_TRY
, D_CXX_OBJC
| D_CXXWARN
},
548 { "typedef", RID_TYPEDEF
, 0 },
549 { "typename", RID_TYPENAME
, D_CXXONLY
| D_CXXWARN
},
550 { "typeid", RID_TYPEID
, D_CXXONLY
| D_CXXWARN
},
551 { "typeof", RID_TYPEOF
, D_ASM
| D_EXT
},
552 { "union", RID_UNION
, 0 },
553 { "unsigned", RID_UNSIGNED
, 0 },
554 { "using", RID_USING
, D_CXXONLY
| D_CXXWARN
},
555 { "virtual", RID_VIRTUAL
, D_CXXONLY
| D_CXXWARN
},
556 { "void", RID_VOID
, 0 },
557 { "volatile", RID_VOLATILE
, 0 },
558 { "wchar_t", RID_WCHAR
, D_CXXONLY
},
559 { "while", RID_WHILE
, 0 },
560 /* These Objective-C keywords are recognized only immediately after
562 { "compatibility_alias", RID_AT_ALIAS
, D_OBJC
},
563 { "defs", RID_AT_DEFS
, D_OBJC
},
564 { "encode", RID_AT_ENCODE
, D_OBJC
},
565 { "end", RID_AT_END
, D_OBJC
},
566 { "implementation", RID_AT_IMPLEMENTATION
, D_OBJC
},
567 { "interface", RID_AT_INTERFACE
, D_OBJC
},
568 { "protocol", RID_AT_PROTOCOL
, D_OBJC
},
569 { "selector", RID_AT_SELECTOR
, D_OBJC
},
570 { "finally", RID_AT_FINALLY
, D_OBJC
},
571 { "synchronized", RID_AT_SYNCHRONIZED
, D_OBJC
},
572 { "optional", RID_AT_OPTIONAL
, D_OBJC
},
573 { "required", RID_AT_REQUIRED
, D_OBJC
},
574 { "property", RID_AT_PROPERTY
, D_OBJC
},
575 { "package", RID_AT_PACKAGE
, D_OBJC
},
576 { "synthesize", RID_AT_SYNTHESIZE
, D_OBJC
},
577 { "dynamic", RID_AT_DYNAMIC
, D_OBJC
},
578 /* These are recognized only in protocol-qualifier context
580 { "bycopy", RID_BYCOPY
, D_OBJC
},
581 { "byref", RID_BYREF
, D_OBJC
},
582 { "in", RID_IN
, D_OBJC
},
583 { "inout", RID_INOUT
, D_OBJC
},
584 { "oneway", RID_ONEWAY
, D_OBJC
},
585 { "out", RID_OUT
, D_OBJC
},
586 /* These are recognized inside a property attribute list */
587 { "assign", RID_ASSIGN
, D_OBJC
},
588 { "copy", RID_COPY
, D_OBJC
},
589 { "getter", RID_GETTER
, D_OBJC
},
590 { "nonatomic", RID_NONATOMIC
, D_OBJC
},
591 { "readonly", RID_READONLY
, D_OBJC
},
592 { "readwrite", RID_READWRITE
, D_OBJC
},
593 { "retain", RID_RETAIN
, D_OBJC
},
594 { "setter", RID_SETTER
, D_OBJC
},
597 const unsigned int num_c_common_reswords
=
598 sizeof c_common_reswords
/ sizeof (struct c_common_resword
);
600 /* Table of machine-independent attributes common to all C-like languages. */
601 const struct attribute_spec c_common_attribute_table
[] =
603 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
604 affects_type_identity } */
605 { "packed", 0, 0, false, false, false,
606 handle_packed_attribute
, false},
607 { "nocommon", 0, 0, true, false, false,
608 handle_nocommon_attribute
, false},
609 { "common", 0, 0, true, false, false,
610 handle_common_attribute
, false },
611 /* FIXME: logically, noreturn attributes should be listed as
612 "false, true, true" and apply to function types. But implementing this
613 would require all the places in the compiler that use TREE_THIS_VOLATILE
614 on a decl to identify non-returning functions to be located and fixed
615 to check the function type instead. */
616 { "noreturn", 0, 0, true, false, false,
617 handle_noreturn_attribute
, false },
618 { "volatile", 0, 0, true, false, false,
619 handle_noreturn_attribute
, false },
620 { "noinline", 0, 0, true, false, false,
621 handle_noinline_attribute
, false },
622 { "noclone", 0, 0, true, false, false,
623 handle_noclone_attribute
, false },
624 { "leaf", 0, 0, true, false, false,
625 handle_leaf_attribute
, false },
626 { "always_inline", 0, 0, true, false, false,
627 handle_always_inline_attribute
, false },
628 { "gnu_inline", 0, 0, true, false, false,
629 handle_gnu_inline_attribute
, false },
630 { "artificial", 0, 0, true, false, false,
631 handle_artificial_attribute
, false },
632 { "flatten", 0, 0, true, false, false,
633 handle_flatten_attribute
, false },
634 { "used", 0, 0, true, false, false,
635 handle_used_attribute
, false },
636 { "unused", 0, 0, false, false, false,
637 handle_unused_attribute
, false },
638 { "externally_visible", 0, 0, true, false, false,
639 handle_externally_visible_attribute
, false },
640 /* The same comments as for noreturn attributes apply to const ones. */
641 { "const", 0, 0, true, false, false,
642 handle_const_attribute
, false },
643 { "transparent_union", 0, 0, false, false, false,
644 handle_transparent_union_attribute
, false },
645 { "constructor", 0, 1, true, false, false,
646 handle_constructor_attribute
, false },
647 { "destructor", 0, 1, true, false, false,
648 handle_destructor_attribute
, false },
649 { "mode", 1, 1, false, true, false,
650 handle_mode_attribute
, false },
651 { "section", 1, 1, true, false, false,
652 handle_section_attribute
, false },
653 { "aligned", 0, 1, false, false, false,
654 handle_aligned_attribute
, false },
655 { "weak", 0, 0, true, false, false,
656 handle_weak_attribute
, false },
657 { "ifunc", 1, 1, true, false, false,
658 handle_ifunc_attribute
, false },
659 { "alias", 1, 1, true, false, false,
660 handle_alias_attribute
, false },
661 { "weakref", 0, 1, true, false, false,
662 handle_weakref_attribute
, false },
663 { "no_instrument_function", 0, 0, true, false, false,
664 handle_no_instrument_function_attribute
,
666 { "malloc", 0, 0, true, false, false,
667 handle_malloc_attribute
, false },
668 { "returns_twice", 0, 0, true, false, false,
669 handle_returns_twice_attribute
, false },
670 { "no_stack_limit", 0, 0, true, false, false,
671 handle_no_limit_stack_attribute
, false },
672 { "pure", 0, 0, true, false, false,
673 handle_pure_attribute
, false },
674 { "transaction_callable", 0, 0, false, true, false,
675 handle_tm_attribute
, false },
676 { "transaction_unsafe", 0, 0, false, true, false,
677 handle_tm_attribute
, false },
678 { "transaction_safe", 0, 0, false, true, false,
679 handle_tm_attribute
, false },
680 { "transaction_may_cancel_outer", 0, 0, false, true, false,
681 handle_tm_attribute
, false },
682 /* ??? These two attributes didn't make the transition from the
683 Intel language document to the multi-vendor language document. */
684 { "transaction_pure", 0, 0, false, true, false,
685 handle_tm_attribute
, false },
686 { "transaction_wrap", 1, 1, true, false, false,
687 handle_tm_wrap_attribute
, false },
688 /* For internal use (marking of builtins) only. The name contains space
689 to prevent its usage in source code. */
690 { "no vops", 0, 0, true, false, false,
691 handle_novops_attribute
, false },
692 { "deprecated", 0, 1, false, false, false,
693 handle_deprecated_attribute
, false },
694 { "vector_size", 1, 1, false, true, false,
695 handle_vector_size_attribute
, false },
696 { "visibility", 1, 1, false, false, false,
697 handle_visibility_attribute
, false },
698 { "tls_model", 1, 1, true, false, false,
699 handle_tls_model_attribute
, false },
700 { "nonnull", 0, -1, false, true, true,
701 handle_nonnull_attribute
, false },
702 { "nothrow", 0, 0, true, false, false,
703 handle_nothrow_attribute
, false },
704 { "may_alias", 0, 0, false, true, false, NULL
, false },
705 { "cleanup", 1, 1, true, false, false,
706 handle_cleanup_attribute
, false },
707 { "warn_unused_result", 0, 0, false, true, true,
708 handle_warn_unused_result_attribute
, false },
709 { "sentinel", 0, 1, false, true, true,
710 handle_sentinel_attribute
, false },
711 /* For internal use (marking of builtins) only. The name contains space
712 to prevent its usage in source code. */
713 { "type generic", 0, 0, false, true, true,
714 handle_type_generic_attribute
, false },
715 { "alloc_size", 1, 2, false, true, true,
716 handle_alloc_size_attribute
, false },
717 { "cold", 0, 0, true, false, false,
718 handle_cold_attribute
, false },
719 { "hot", 0, 0, true, false, false,
720 handle_hot_attribute
, false },
721 { "warning", 1, 1, true, false, false,
722 handle_error_attribute
, false },
723 { "error", 1, 1, true, false, false,
724 handle_error_attribute
, false },
725 { "target", 1, -1, true, false, false,
726 handle_target_attribute
, false },
727 { "optimize", 1, -1, true, false, false,
728 handle_optimize_attribute
, false },
729 /* For internal use only. The leading '*' both prevents its usage in
730 source code and signals that it may be overridden by machine tables. */
731 { "*tm regparm", 0, 0, false, true, true,
732 ignore_attribute
, false },
733 { "no_split_stack", 0, 0, true, false, false,
734 handle_no_split_stack_attribute
, false },
735 /* For internal use (marking of builtins and runtime functions) only.
736 The name contains space to prevent its usage in source code. */
737 { "fn spec", 1, 1, false, true, true,
738 handle_fnspec_attribute
, false },
739 { NULL
, 0, 0, false, false, false, NULL
, false }
742 /* Give the specifications for the format attributes, used by C and all
745 const struct attribute_spec c_common_format_attribute_table
[] =
747 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
748 affects_type_identity } */
749 { "format", 3, 3, false, true, true,
750 handle_format_attribute
, false },
751 { "format_arg", 1, 1, false, true, true,
752 handle_format_arg_attribute
, false },
753 { NULL
, 0, 0, false, false, false, NULL
, false }
756 /* Return identifier for address space AS. */
759 c_addr_space_name (addr_space_t as
)
761 int rid
= RID_FIRST_ADDR_SPACE
+ as
;
762 gcc_assert (ridpointers
[rid
]);
763 return IDENTIFIER_POINTER (ridpointers
[rid
]);
766 /* Push current bindings for the function name VAR_DECLS. */
769 start_fname_decls (void)
772 tree saved
= NULL_TREE
;
774 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
776 tree decl
= *fname_vars
[ix
].decl
;
780 saved
= tree_cons (decl
, build_int_cst (integer_type_node
, ix
),
782 *fname_vars
[ix
].decl
= NULL_TREE
;
785 if (saved
|| saved_function_name_decls
)
786 /* Normally they'll have been NULL, so only push if we've got a
787 stack, or they are non-NULL. */
788 saved_function_name_decls
= tree_cons (saved
, NULL_TREE
,
789 saved_function_name_decls
);
792 /* Finish up the current bindings, adding them into the current function's
793 statement tree. This must be done _before_ finish_stmt_tree is called.
794 If there is no current function, we must be at file scope and no statements
795 are involved. Pop the previous bindings. */
798 finish_fname_decls (void)
801 tree stmts
= NULL_TREE
;
802 tree stack
= saved_function_name_decls
;
804 for (; stack
&& TREE_VALUE (stack
); stack
= TREE_CHAIN (stack
))
805 append_to_statement_list (TREE_VALUE (stack
), &stmts
);
809 tree
*bodyp
= &DECL_SAVED_TREE (current_function_decl
);
811 if (TREE_CODE (*bodyp
) == BIND_EXPR
)
812 bodyp
= &BIND_EXPR_BODY (*bodyp
);
814 append_to_statement_list_force (*bodyp
, &stmts
);
818 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
819 *fname_vars
[ix
].decl
= NULL_TREE
;
823 /* We had saved values, restore them. */
826 for (saved
= TREE_PURPOSE (stack
); saved
; saved
= TREE_CHAIN (saved
))
828 tree decl
= TREE_PURPOSE (saved
);
829 unsigned ix
= TREE_INT_CST_LOW (TREE_VALUE (saved
));
831 *fname_vars
[ix
].decl
= decl
;
833 stack
= TREE_CHAIN (stack
);
835 saved_function_name_decls
= stack
;
838 /* Return the text name of the current function, suitably prettified
839 by PRETTY_P. Return string must be freed by caller. */
842 fname_as_string (int pretty_p
)
844 const char *name
= "top level";
847 cpp_string cstr
= { 0, 0 }, strname
;
855 if (current_function_decl
)
856 name
= lang_hooks
.decl_printable_name (current_function_decl
, vrb
);
858 len
= strlen (name
) + 3; /* Two for '"'s. One for NULL. */
860 namep
= XNEWVEC (char, len
);
861 snprintf (namep
, len
, "\"%s\"", name
);
862 strname
.text
= (unsigned char *) namep
;
863 strname
.len
= len
- 1;
865 if (cpp_interpret_string (parse_in
, &strname
, 1, &cstr
, CPP_STRING
))
868 return (const char *) cstr
.text
;
874 /* Return the VAR_DECL for a const char array naming the current
875 function. If the VAR_DECL has not yet been created, create it
876 now. RID indicates how it should be formatted and IDENTIFIER_NODE
877 ID is its name (unfortunately C and C++ hold the RID values of
878 keywords in different places, so we can't derive RID from ID in
879 this language independent code. LOC is the location of the
883 fname_decl (location_t loc
, unsigned int rid
, tree id
)
886 tree decl
= NULL_TREE
;
888 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
889 if (fname_vars
[ix
].rid
== rid
)
892 decl
= *fname_vars
[ix
].decl
;
895 /* If a tree is built here, it would normally have the lineno of
896 the current statement. Later this tree will be moved to the
897 beginning of the function and this line number will be wrong.
898 To avoid this problem set the lineno to 0 here; that prevents
899 it from appearing in the RTL. */
901 location_t saved_location
= input_location
;
902 input_location
= UNKNOWN_LOCATION
;
904 stmts
= push_stmt_list ();
905 decl
= (*make_fname_decl
) (loc
, id
, fname_vars
[ix
].pretty
);
906 stmts
= pop_stmt_list (stmts
);
907 if (!IS_EMPTY_STMT (stmts
))
908 saved_function_name_decls
909 = tree_cons (decl
, stmts
, saved_function_name_decls
);
910 *fname_vars
[ix
].decl
= decl
;
911 input_location
= saved_location
;
913 if (!ix
&& !current_function_decl
)
914 pedwarn (loc
, 0, "%qD is not defined outside of function scope", decl
);
919 /* Given a STRING_CST, give it a suitable array-of-chars data type. */
922 fix_string_type (tree value
)
924 int length
= TREE_STRING_LENGTH (value
);
926 tree e_type
, i_type
, a_type
;
928 /* Compute the number of elements, for the array type. */
929 if (TREE_TYPE (value
) == char_array_type_node
|| !TREE_TYPE (value
))
932 e_type
= char_type_node
;
934 else if (TREE_TYPE (value
) == char16_array_type_node
)
936 nchars
= length
/ (TYPE_PRECISION (char16_type_node
) / BITS_PER_UNIT
);
937 e_type
= char16_type_node
;
939 else if (TREE_TYPE (value
) == char32_array_type_node
)
941 nchars
= length
/ (TYPE_PRECISION (char32_type_node
) / BITS_PER_UNIT
);
942 e_type
= char32_type_node
;
946 nchars
= length
/ (TYPE_PRECISION (wchar_type_node
) / BITS_PER_UNIT
);
947 e_type
= wchar_type_node
;
950 /* C89 2.2.4.1, C99 5.2.4.1 (Translation limits). The analogous
951 limit in C++98 Annex B is very large (65536) and is not normative,
952 so we do not diagnose it (warn_overlength_strings is forced off
953 in c_common_post_options). */
954 if (warn_overlength_strings
)
956 const int nchars_max
= flag_isoc99
? 4095 : 509;
957 const int relevant_std
= flag_isoc99
? 99 : 90;
958 if (nchars
- 1 > nchars_max
)
959 /* Translators: The %d after 'ISO C' will be 90 or 99. Do not
960 separate the %d from the 'C'. 'ISO' should not be
961 translated, but it may be moved after 'C%d' in languages
962 where modifiers follow nouns. */
963 pedwarn (input_location
, OPT_Woverlength_strings
,
964 "string length %qd is greater than the length %qd "
965 "ISO C%d compilers are required to support",
966 nchars
- 1, nchars_max
, relevant_std
);
969 /* Create the array type for the string constant. The ISO C++
970 standard says that a string literal has type `const char[N]' or
971 `const wchar_t[N]'. We use the same logic when invoked as a C
972 front-end with -Wwrite-strings.
973 ??? We should change the type of an expression depending on the
974 state of a warning flag. We should just be warning -- see how
975 this is handled in the C++ front-end for the deprecated implicit
976 conversion from string literals to `char*' or `wchar_t*'.
978 The C++ front end relies on TYPE_MAIN_VARIANT of a cv-qualified
979 array type being the unqualified version of that type.
980 Therefore, if we are constructing an array of const char, we must
981 construct the matching unqualified array type first. The C front
982 end does not require this, but it does no harm, so we do it
984 i_type
= build_index_type (size_int (nchars
- 1));
985 a_type
= build_array_type (e_type
, i_type
);
986 if (c_dialect_cxx() || warn_write_strings
)
987 a_type
= c_build_qualified_type (a_type
, TYPE_QUAL_CONST
);
989 TREE_TYPE (value
) = a_type
;
990 TREE_CONSTANT (value
) = 1;
991 TREE_READONLY (value
) = 1;
992 TREE_STATIC (value
) = 1;
996 /* If DISABLE is true, stop issuing warnings. This is used when
997 parsing code that we know will not be executed. This function may
998 be called multiple times, and works as a stack. */
1001 c_disable_warnings (bool disable
)
1005 ++c_inhibit_evaluation_warnings
;
1006 fold_defer_overflow_warnings ();
1010 /* If ENABLE is true, reenable issuing warnings. */
1013 c_enable_warnings (bool enable
)
1017 --c_inhibit_evaluation_warnings
;
1018 fold_undefer_and_ignore_overflow_warnings ();
1022 /* Fully fold EXPR, an expression that was not folded (beyond integer
1023 constant expressions and null pointer constants) when being built
1024 up. If IN_INIT, this is in a static initializer and certain
1025 changes are made to the folding done. Clear *MAYBE_CONST if
1026 MAYBE_CONST is not NULL and EXPR is definitely not a constant
1027 expression because it contains an evaluated operator (in C99) or an
1028 operator outside of sizeof returning an integer constant (in C90)
1029 not permitted in constant expressions, or because it contains an
1030 evaluated arithmetic overflow. (*MAYBE_CONST should typically be
1031 set to true by callers before calling this function.) Return the
1032 folded expression. Function arguments have already been folded
1033 before calling this function, as have the contents of SAVE_EXPR,
1034 TARGET_EXPR, BIND_EXPR, VA_ARG_EXPR, OBJ_TYPE_REF and
1035 C_MAYBE_CONST_EXPR. */
1038 c_fully_fold (tree expr
, bool in_init
, bool *maybe_const
)
1041 tree eptype
= NULL_TREE
;
1043 bool maybe_const_itself
= true;
1044 location_t loc
= EXPR_LOCATION (expr
);
1046 /* This function is not relevant to C++ because C++ folds while
1047 parsing, and may need changes to be correct for C++ when C++
1048 stops folding while parsing. */
1049 if (c_dialect_cxx ())
1053 maybe_const
= &dummy
;
1054 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
1056 eptype
= TREE_TYPE (expr
);
1057 expr
= TREE_OPERAND (expr
, 0);
1059 ret
= c_fully_fold_internal (expr
, in_init
, maybe_const
,
1060 &maybe_const_itself
);
1062 ret
= fold_convert_loc (loc
, eptype
, ret
);
1063 *maybe_const
&= maybe_const_itself
;
1067 /* Internal helper for c_fully_fold. EXPR and IN_INIT are as for
1068 c_fully_fold. *MAYBE_CONST_OPERANDS is cleared because of operands
1069 not permitted, while *MAYBE_CONST_ITSELF is cleared because of
1070 arithmetic overflow (for C90, *MAYBE_CONST_OPERANDS is carried from
1071 both evaluated and unevaluated subexpressions while
1072 *MAYBE_CONST_ITSELF is carried from only evaluated
1076 c_fully_fold_internal (tree expr
, bool in_init
, bool *maybe_const_operands
,
1077 bool *maybe_const_itself
)
1080 enum tree_code code
= TREE_CODE (expr
);
1081 enum tree_code_class kind
= TREE_CODE_CLASS (code
);
1082 location_t loc
= EXPR_LOCATION (expr
);
1083 tree op0
, op1
, op2
, op3
;
1084 tree orig_op0
, orig_op1
, orig_op2
;
1085 bool op0_const
= true, op1_const
= true, op2_const
= true;
1086 bool op0_const_self
= true, op1_const_self
= true, op2_const_self
= true;
1087 bool nowarning
= TREE_NO_WARNING (expr
);
1090 /* This function is not relevant to C++ because C++ folds while
1091 parsing, and may need changes to be correct for C++ when C++
1092 stops folding while parsing. */
1093 if (c_dialect_cxx ())
1096 /* Constants, declarations, statements, errors, SAVE_EXPRs and
1097 anything else not counted as an expression cannot usefully be
1098 folded further at this point. */
1099 if (!IS_EXPR_CODE_CLASS (kind
)
1100 || kind
== tcc_statement
1101 || code
== SAVE_EXPR
)
1104 /* Operands of variable-length expressions (function calls) have
1105 already been folded, as have __builtin_* function calls, and such
1106 expressions cannot occur in constant expressions. */
1107 if (kind
== tcc_vl_exp
)
1109 *maybe_const_operands
= false;
1114 if (code
== C_MAYBE_CONST_EXPR
)
1116 tree pre
= C_MAYBE_CONST_EXPR_PRE (expr
);
1117 tree inner
= C_MAYBE_CONST_EXPR_EXPR (expr
);
1118 if (C_MAYBE_CONST_EXPR_NON_CONST (expr
))
1119 *maybe_const_operands
= false;
1120 if (C_MAYBE_CONST_EXPR_INT_OPERANDS (expr
))
1121 *maybe_const_itself
= false;
1122 if (pre
&& !in_init
)
1123 ret
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr
), pre
, inner
);
1129 /* Assignment, increment, decrement, function call and comma
1130 operators, and statement expressions, cannot occur in constant
1131 expressions if evaluated / outside of sizeof. (Function calls
1132 were handled above, though VA_ARG_EXPR is treated like a function
1133 call here, and statement expressions are handled through
1134 C_MAYBE_CONST_EXPR to avoid folding inside them.) */
1138 case PREDECREMENT_EXPR
:
1139 case PREINCREMENT_EXPR
:
1140 case POSTDECREMENT_EXPR
:
1141 case POSTINCREMENT_EXPR
:
1143 *maybe_const_operands
= false;
1150 *maybe_const_operands
= false;
1158 /* Fold individual tree codes as appropriate. */
1161 case COMPOUND_LITERAL_EXPR
:
1162 /* Any non-constancy will have been marked in a containing
1163 C_MAYBE_CONST_EXPR; there is no more folding to do here. */
1167 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1168 op1
= TREE_OPERAND (expr
, 1);
1169 op2
= TREE_OPERAND (expr
, 2);
1170 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1171 maybe_const_itself
);
1172 STRIP_TYPE_NOPS (op0
);
1173 if (op0
!= orig_op0
)
1174 ret
= build3 (COMPONENT_REF
, TREE_TYPE (expr
), op0
, op1
, op2
);
1177 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1178 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1183 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1184 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1185 op2
= TREE_OPERAND (expr
, 2);
1186 op3
= TREE_OPERAND (expr
, 3);
1187 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1188 maybe_const_itself
);
1189 STRIP_TYPE_NOPS (op0
);
1190 op1
= c_fully_fold_internal (op1
, in_init
, maybe_const_operands
,
1191 maybe_const_itself
);
1192 STRIP_TYPE_NOPS (op1
);
1193 op1
= decl_constant_value_for_optimization (op1
);
1194 if (op0
!= orig_op0
|| op1
!= orig_op1
)
1195 ret
= build4 (ARRAY_REF
, TREE_TYPE (expr
), op0
, op1
, op2
, op3
);
1198 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1199 TREE_SIDE_EFFECTS (ret
) = TREE_SIDE_EFFECTS (expr
);
1200 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1207 case PREDECREMENT_EXPR
:
1208 case PREINCREMENT_EXPR
:
1209 case POSTDECREMENT_EXPR
:
1210 case POSTINCREMENT_EXPR
:
1214 case POINTER_PLUS_EXPR
:
1215 case TRUNC_DIV_EXPR
:
1217 case FLOOR_DIV_EXPR
:
1218 case TRUNC_MOD_EXPR
:
1220 case EXACT_DIV_EXPR
:
1233 case TRUTH_AND_EXPR
:
1235 case TRUTH_XOR_EXPR
:
1236 case UNORDERED_EXPR
:
1243 /* Binary operations evaluating both arguments (increment and
1244 decrement are binary internally in GCC). */
1245 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1246 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1247 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1248 maybe_const_itself
);
1249 STRIP_TYPE_NOPS (op0
);
1250 if (code
!= MODIFY_EXPR
1251 && code
!= PREDECREMENT_EXPR
1252 && code
!= PREINCREMENT_EXPR
1253 && code
!= POSTDECREMENT_EXPR
1254 && code
!= POSTINCREMENT_EXPR
)
1255 op0
= decl_constant_value_for_optimization (op0
);
1256 /* The RHS of a MODIFY_EXPR was fully folded when building that
1257 expression for the sake of conversion warnings. */
1258 if (code
!= MODIFY_EXPR
)
1259 op1
= c_fully_fold_internal (op1
, in_init
, maybe_const_operands
,
1260 maybe_const_itself
);
1261 STRIP_TYPE_NOPS (op1
);
1262 op1
= decl_constant_value_for_optimization (op1
);
1263 if (op0
!= orig_op0
|| op1
!= orig_op1
|| in_init
)
1265 ? fold_build2_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
)
1266 : fold_build2_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
);
1269 if (TREE_OVERFLOW_P (ret
)
1270 && !TREE_OVERFLOW_P (op0
)
1271 && !TREE_OVERFLOW_P (op1
))
1272 overflow_warning (EXPR_LOCATION (expr
), ret
);
1276 case FIX_TRUNC_EXPR
:
1279 case VIEW_CONVERT_EXPR
:
1280 case NON_LVALUE_EXPR
:
1283 case TRUTH_NOT_EXPR
:
1288 /* Unary operations. */
1289 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1290 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1291 maybe_const_itself
);
1292 STRIP_TYPE_NOPS (op0
);
1293 if (code
!= ADDR_EXPR
&& code
!= REALPART_EXPR
&& code
!= IMAGPART_EXPR
)
1294 op0
= decl_constant_value_for_optimization (op0
);
1295 /* ??? Cope with user tricks that amount to offsetof. The middle-end is
1296 not prepared to deal with them if they occur in initializers. */
1298 && code
== ADDR_EXPR
1299 && (op1
= get_base_address (op0
)) != NULL_TREE
1300 && TREE_CODE (op1
) == INDIRECT_REF
1301 && TREE_CONSTANT (TREE_OPERAND (op1
, 0)))
1302 ret
= fold_convert_loc (loc
, TREE_TYPE (expr
), fold_offsetof_1 (op0
));
1303 else if (op0
!= orig_op0
|| in_init
)
1305 ? fold_build1_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
)
1306 : fold_build1_loc (loc
, code
, TREE_TYPE (expr
), op0
);
1309 if (code
== INDIRECT_REF
1311 && TREE_CODE (ret
) == INDIRECT_REF
)
1313 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1314 TREE_SIDE_EFFECTS (ret
) = TREE_SIDE_EFFECTS (expr
);
1315 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1319 case FIX_TRUNC_EXPR
:
1322 /* Don't warn about explicit conversions. We will already
1323 have warned about suspect implicit conversions. */
1327 if (TREE_OVERFLOW_P (ret
) && !TREE_OVERFLOW_P (op0
))
1328 overflow_warning (EXPR_LOCATION (expr
), ret
);
1333 case TRUTH_ANDIF_EXPR
:
1334 case TRUTH_ORIF_EXPR
:
1335 /* Binary operations not necessarily evaluating both
1337 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1338 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1339 op0
= c_fully_fold_internal (op0
, in_init
, &op0_const
, &op0_const_self
);
1340 STRIP_TYPE_NOPS (op0
);
1342 unused_p
= (op0
== (code
== TRUTH_ANDIF_EXPR
1343 ? truthvalue_false_node
1344 : truthvalue_true_node
));
1345 c_disable_warnings (unused_p
);
1346 op1
= c_fully_fold_internal (op1
, in_init
, &op1_const
, &op1_const_self
);
1347 STRIP_TYPE_NOPS (op1
);
1348 c_enable_warnings (unused_p
);
1350 if (op0
!= orig_op0
|| op1
!= orig_op1
|| in_init
)
1352 ? fold_build2_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
)
1353 : fold_build2_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
);
1356 *maybe_const_operands
&= op0_const
;
1357 *maybe_const_itself
&= op0_const_self
;
1361 && (code
== TRUTH_ANDIF_EXPR
1362 ? op0
== truthvalue_false_node
1363 : op0
== truthvalue_true_node
)))
1364 *maybe_const_operands
&= op1_const
;
1367 && (code
== TRUTH_ANDIF_EXPR
1368 ? op0
== truthvalue_false_node
1369 : op0
== truthvalue_true_node
)))
1370 *maybe_const_itself
&= op1_const_self
;
1374 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1375 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1376 orig_op2
= op2
= TREE_OPERAND (expr
, 2);
1377 op0
= c_fully_fold_internal (op0
, in_init
, &op0_const
, &op0_const_self
);
1379 STRIP_TYPE_NOPS (op0
);
1380 c_disable_warnings (op0
== truthvalue_false_node
);
1381 op1
= c_fully_fold_internal (op1
, in_init
, &op1_const
, &op1_const_self
);
1382 STRIP_TYPE_NOPS (op1
);
1383 c_enable_warnings (op0
== truthvalue_false_node
);
1385 c_disable_warnings (op0
== truthvalue_true_node
);
1386 op2
= c_fully_fold_internal (op2
, in_init
, &op2_const
, &op2_const_self
);
1387 STRIP_TYPE_NOPS (op2
);
1388 c_enable_warnings (op0
== truthvalue_true_node
);
1390 if (op0
!= orig_op0
|| op1
!= orig_op1
|| op2
!= orig_op2
)
1391 ret
= fold_build3_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
, op2
);
1394 *maybe_const_operands
&= op0_const
;
1395 *maybe_const_itself
&= op0_const_self
;
1399 && op0
== truthvalue_false_node
))
1400 *maybe_const_operands
&= op1_const
;
1403 && op0
== truthvalue_false_node
))
1404 *maybe_const_itself
&= op1_const_self
;
1408 && op0
== truthvalue_true_node
))
1409 *maybe_const_operands
&= op2_const
;
1412 && op0
== truthvalue_true_node
))
1413 *maybe_const_itself
&= op2_const_self
;
1416 case EXCESS_PRECISION_EXPR
:
1417 /* Each case where an operand with excess precision may be
1418 encountered must remove the EXCESS_PRECISION_EXPR around
1419 inner operands and possibly put one around the whole
1420 expression or possibly convert to the semantic type (which
1421 c_fully_fold does); we cannot tell at this stage which is
1422 appropriate in any particular case. */
1426 /* Various codes may appear through folding built-in functions
1427 and their arguments. */
1432 /* Some folding may introduce NON_LVALUE_EXPRs; all lvalue checks
1433 have been done by this point, so remove them again. */
1434 nowarning
|= TREE_NO_WARNING (ret
);
1435 STRIP_TYPE_NOPS (ret
);
1436 if (nowarning
&& !TREE_NO_WARNING (ret
))
1438 if (!CAN_HAVE_LOCATION_P (ret
))
1439 ret
= build1 (NOP_EXPR
, TREE_TYPE (ret
), ret
);
1440 TREE_NO_WARNING (ret
) = 1;
1443 protected_set_expr_location (ret
, loc
);
1447 /* If not optimizing, EXP is not a VAR_DECL, or EXP has array type,
1448 return EXP. Otherwise, return either EXP or its known constant
1449 value (if it has one), but return EXP if EXP has mode BLKmode. ???
1450 Is the BLKmode test appropriate? */
1453 decl_constant_value_for_optimization (tree exp
)
1457 /* This function is only used by C, for c_fully_fold and other
1458 optimization, and may not be correct for C++. */
1459 if (c_dialect_cxx ())
1463 || TREE_CODE (exp
) != VAR_DECL
1464 || TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
1465 || DECL_MODE (exp
) == BLKmode
)
1468 ret
= decl_constant_value (exp
);
1469 /* Avoid unwanted tree sharing between the initializer and current
1470 function's body where the tree can be modified e.g. by the
1472 if (ret
!= exp
&& TREE_STATIC (exp
))
1473 ret
= unshare_expr (ret
);
1477 /* Print a warning if a constant expression had overflow in folding.
1478 Invoke this function on every expression that the language
1479 requires to be a constant expression.
1480 Note the ANSI C standard says it is erroneous for a
1481 constant expression to overflow. */
1484 constant_expression_warning (tree value
)
1486 if (warn_overflow
&& pedantic
1487 && (TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1488 || TREE_CODE (value
) == FIXED_CST
1489 || TREE_CODE (value
) == VECTOR_CST
1490 || TREE_CODE (value
) == COMPLEX_CST
)
1491 && TREE_OVERFLOW (value
))
1492 pedwarn (input_location
, OPT_Woverflow
, "overflow in constant expression");
1495 /* The same as above but print an unconditional error. */
1497 constant_expression_error (tree value
)
1499 if ((TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1500 || TREE_CODE (value
) == FIXED_CST
1501 || TREE_CODE (value
) == VECTOR_CST
1502 || TREE_CODE (value
) == COMPLEX_CST
)
1503 && TREE_OVERFLOW (value
))
1504 error ("overflow in constant expression");
1507 /* Print a warning if an expression had overflow in folding and its
1510 Invoke this function on every expression that
1511 (1) appears in the source code, and
1512 (2) is a constant expression that overflowed, and
1513 (3) is not already checked by convert_and_check;
1514 however, do not invoke this function on operands of explicit casts
1515 or when the expression is the result of an operator and any operand
1516 already overflowed. */
1519 overflow_warning (location_t loc
, tree value
)
1521 if (c_inhibit_evaluation_warnings
!= 0)
1524 switch (TREE_CODE (value
))
1527 warning_at (loc
, OPT_Woverflow
, "integer overflow in expression");
1531 warning_at (loc
, OPT_Woverflow
,
1532 "floating point overflow in expression");
1536 warning_at (loc
, OPT_Woverflow
, "fixed-point overflow in expression");
1540 warning_at (loc
, OPT_Woverflow
, "vector overflow in expression");
1544 if (TREE_CODE (TREE_REALPART (value
)) == INTEGER_CST
)
1545 warning_at (loc
, OPT_Woverflow
,
1546 "complex integer overflow in expression");
1547 else if (TREE_CODE (TREE_REALPART (value
)) == REAL_CST
)
1548 warning_at (loc
, OPT_Woverflow
,
1549 "complex floating point overflow in expression");
1557 /* Warn about uses of logical || / && operator in a context where it
1558 is likely that the bitwise equivalent was intended by the
1559 programmer. We have seen an expression in which CODE is a binary
1560 operator used to combine expressions OP_LEFT and OP_RIGHT, which before folding
1561 had CODE_LEFT and CODE_RIGHT, into an expression of type TYPE. */
1563 warn_logical_operator (location_t location
, enum tree_code code
, tree type
,
1564 enum tree_code code_left
, tree op_left
,
1565 enum tree_code
ARG_UNUSED (code_right
), tree op_right
)
1567 int or_op
= (code
== TRUTH_ORIF_EXPR
|| code
== TRUTH_OR_EXPR
);
1568 int in0_p
, in1_p
, in_p
;
1569 tree low0
, low1
, low
, high0
, high1
, high
, lhs
, rhs
, tem
;
1570 bool strict_overflow_p
= false;
1572 if (code
!= TRUTH_ANDIF_EXPR
1573 && code
!= TRUTH_AND_EXPR
1574 && code
!= TRUTH_ORIF_EXPR
1575 && code
!= TRUTH_OR_EXPR
)
1578 /* Warn if &&/|| are being used in a context where it is
1579 likely that the bitwise equivalent was intended by the
1580 programmer. That is, an expression such as op && MASK
1581 where op should not be any boolean expression, nor a
1582 constant, and mask seems to be a non-boolean integer constant. */
1583 if (!truth_value_p (code_left
)
1584 && INTEGRAL_TYPE_P (TREE_TYPE (op_left
))
1585 && !CONSTANT_CLASS_P (op_left
)
1586 && !TREE_NO_WARNING (op_left
)
1587 && TREE_CODE (op_right
) == INTEGER_CST
1588 && !integer_zerop (op_right
)
1589 && !integer_onep (op_right
))
1592 warning_at (location
, OPT_Wlogical_op
, "logical %<or%>"
1593 " applied to non-boolean constant");
1595 warning_at (location
, OPT_Wlogical_op
, "logical %<and%>"
1596 " applied to non-boolean constant");
1597 TREE_NO_WARNING (op_left
) = true;
1601 /* We do not warn for constants because they are typical of macro
1602 expansions that test for features. */
1603 if (CONSTANT_CLASS_P (op_left
) || CONSTANT_CLASS_P (op_right
))
1606 /* This warning only makes sense with logical operands. */
1607 if (!(truth_value_p (TREE_CODE (op_left
))
1608 || INTEGRAL_TYPE_P (TREE_TYPE (op_left
)))
1609 || !(truth_value_p (TREE_CODE (op_right
))
1610 || INTEGRAL_TYPE_P (TREE_TYPE (op_right
))))
1614 /* We first test whether either side separately is trivially true
1615 (with OR) or trivially false (with AND). If so, do not warn.
1616 This is a common idiom for testing ranges of data types in
1618 lhs
= make_range (op_left
, &in0_p
, &low0
, &high0
, &strict_overflow_p
);
1621 if (TREE_CODE (lhs
) == C_MAYBE_CONST_EXPR
)
1622 lhs
= C_MAYBE_CONST_EXPR_EXPR (lhs
);
1624 /* If this is an OR operation, invert both sides; now, the result
1625 should be always false to get a warning. */
1629 tem
= build_range_check (UNKNOWN_LOCATION
, type
, lhs
, in0_p
, low0
, high0
);
1630 if (tem
&& integer_zerop (tem
))
1633 rhs
= make_range (op_right
, &in1_p
, &low1
, &high1
, &strict_overflow_p
);
1636 if (TREE_CODE (rhs
) == C_MAYBE_CONST_EXPR
)
1637 rhs
= C_MAYBE_CONST_EXPR_EXPR (rhs
);
1639 /* If this is an OR operation, invert both sides; now, the result
1640 should be always false to get a warning. */
1644 tem
= build_range_check (UNKNOWN_LOCATION
, type
, rhs
, in1_p
, low1
, high1
);
1645 if (tem
&& integer_zerop (tem
))
1648 /* If both expressions have the same operand, if we can merge the
1649 ranges, and if the range test is always false, then warn. */
1650 if (operand_equal_p (lhs
, rhs
, 0)
1651 && merge_ranges (&in_p
, &low
, &high
, in0_p
, low0
, high0
,
1653 && 0 != (tem
= build_range_check (UNKNOWN_LOCATION
,
1654 type
, lhs
, in_p
, low
, high
))
1655 && integer_zerop (tem
))
1658 warning_at (location
, OPT_Wlogical_op
,
1660 "of collectively exhaustive tests is always true");
1662 warning_at (location
, OPT_Wlogical_op
,
1664 "of mutually exclusive tests is always false");
1669 /* Warn if EXP contains any computations whose results are not used.
1670 Return true if a warning is printed; false otherwise. LOCUS is the
1671 (potential) location of the expression. */
1674 warn_if_unused_value (const_tree exp
, location_t locus
)
1677 if (TREE_USED (exp
) || TREE_NO_WARNING (exp
))
1680 /* Don't warn about void constructs. This includes casting to void,
1681 void function calls, and statement expressions with a final cast
1683 if (VOID_TYPE_P (TREE_TYPE (exp
)))
1686 if (EXPR_HAS_LOCATION (exp
))
1687 locus
= EXPR_LOCATION (exp
);
1689 switch (TREE_CODE (exp
))
1691 case PREINCREMENT_EXPR
:
1692 case POSTINCREMENT_EXPR
:
1693 case PREDECREMENT_EXPR
:
1694 case POSTDECREMENT_EXPR
:
1699 case TRY_CATCH_EXPR
:
1700 case WITH_CLEANUP_EXPR
:
1706 /* For a binding, warn if no side effect within it. */
1707 exp
= BIND_EXPR_BODY (exp
);
1711 case NON_LVALUE_EXPR
:
1713 exp
= TREE_OPERAND (exp
, 0);
1716 case TRUTH_ORIF_EXPR
:
1717 case TRUTH_ANDIF_EXPR
:
1718 /* In && or ||, warn if 2nd operand has no side effect. */
1719 exp
= TREE_OPERAND (exp
, 1);
1723 if (warn_if_unused_value (TREE_OPERAND (exp
, 0), locus
))
1725 /* Let people do `(foo (), 0)' without a warning. */
1726 if (TREE_CONSTANT (TREE_OPERAND (exp
, 1)))
1728 exp
= TREE_OPERAND (exp
, 1);
1732 /* If this is an expression with side effects, don't warn; this
1733 case commonly appears in macro expansions. */
1734 if (TREE_SIDE_EFFECTS (exp
))
1739 /* Don't warn about automatic dereferencing of references, since
1740 the user cannot control it. */
1741 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == REFERENCE_TYPE
)
1743 exp
= TREE_OPERAND (exp
, 0);
1749 /* Referencing a volatile value is a side effect, so don't warn. */
1750 if ((DECL_P (exp
) || REFERENCE_CLASS_P (exp
))
1751 && TREE_THIS_VOLATILE (exp
))
1754 /* If this is an expression which has no operands, there is no value
1755 to be unused. There are no such language-independent codes,
1756 but front ends may define such. */
1757 if (EXPRESSION_CLASS_P (exp
) && TREE_OPERAND_LENGTH (exp
) == 0)
1761 return warning_at (locus
, OPT_Wunused_value
, "value computed is not used");
1766 /* Print a warning about casts that might indicate violation
1767 of strict aliasing rules if -Wstrict-aliasing is used and
1768 strict aliasing mode is in effect. OTYPE is the original
1769 TREE_TYPE of EXPR, and TYPE the type we're casting to. */
1772 strict_aliasing_warning (tree otype
, tree type
, tree expr
)
1774 /* Strip pointer conversion chains and get to the correct original type. */
1776 otype
= TREE_TYPE (expr
);
1778 if (!(flag_strict_aliasing
1779 && POINTER_TYPE_P (type
)
1780 && POINTER_TYPE_P (otype
)
1781 && !VOID_TYPE_P (TREE_TYPE (type
)))
1782 /* If the type we are casting to is a ref-all pointer
1783 dereferencing it is always valid. */
1784 || TYPE_REF_CAN_ALIAS_ALL (type
))
1787 if ((warn_strict_aliasing
> 1) && TREE_CODE (expr
) == ADDR_EXPR
1788 && (DECL_P (TREE_OPERAND (expr
, 0))
1789 || handled_component_p (TREE_OPERAND (expr
, 0))))
1791 /* Casting the address of an object to non void pointer. Warn
1792 if the cast breaks type based aliasing. */
1793 if (!COMPLETE_TYPE_P (TREE_TYPE (type
)) && warn_strict_aliasing
== 2)
1795 warning (OPT_Wstrict_aliasing
, "type-punning to incomplete type "
1796 "might break strict-aliasing rules");
1801 /* warn_strict_aliasing >= 3. This includes the default (3).
1802 Only warn if the cast is dereferenced immediately. */
1803 alias_set_type set1
=
1804 get_alias_set (TREE_TYPE (TREE_OPERAND (expr
, 0)));
1805 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
1807 if (set1
!= set2
&& set2
!= 0
1808 && (set1
== 0 || !alias_sets_conflict_p (set1
, set2
)))
1810 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1811 "pointer will break strict-aliasing rules");
1814 else if (warn_strict_aliasing
== 2
1815 && !alias_sets_must_conflict_p (set1
, set2
))
1817 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1818 "pointer might break strict-aliasing rules");
1824 if ((warn_strict_aliasing
== 1) && !VOID_TYPE_P (TREE_TYPE (otype
)))
1826 /* At this level, warn for any conversions, even if an address is
1827 not taken in the same statement. This will likely produce many
1828 false positives, but could be useful to pinpoint problems that
1829 are not revealed at higher levels. */
1830 alias_set_type set1
= get_alias_set (TREE_TYPE (otype
));
1831 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
1832 if (!COMPLETE_TYPE_P (type
)
1833 || !alias_sets_must_conflict_p (set1
, set2
))
1835 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1836 "pointer might break strict-aliasing rules");
1844 /* Warn for unlikely, improbable, or stupid DECL declarations
1848 check_main_parameter_types (tree decl
)
1850 function_args_iterator iter
;
1854 FOREACH_FUNCTION_ARGS (TREE_TYPE (decl
), type
, iter
)
1856 /* XXX void_type_node belies the abstraction. */
1857 if (type
== void_type_node
|| type
== error_mark_node
)
1864 if (TYPE_MAIN_VARIANT (type
) != integer_type_node
)
1865 pedwarn (input_location
, OPT_Wmain
,
1866 "first argument of %q+D should be %<int%>", decl
);
1870 if (TREE_CODE (type
) != POINTER_TYPE
1871 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
1872 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
1874 pedwarn (input_location
, OPT_Wmain
,
1875 "second argument of %q+D should be %<char **%>", decl
);
1879 if (TREE_CODE (type
) != POINTER_TYPE
1880 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
1881 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
1883 pedwarn (input_location
, OPT_Wmain
,
1884 "third argument of %q+D should probably be "
1885 "%<char **%>", decl
);
1890 /* It is intentional that this message does not mention the third
1891 argument because it's only mentioned in an appendix of the
1893 if (argct
> 0 && (argct
< 2 || argct
> 3))
1894 pedwarn (input_location
, OPT_Wmain
,
1895 "%q+D takes only zero or two arguments", decl
);
1898 /* True if pointers to distinct types T1 and T2 can be converted to
1899 each other without an explicit cast. Only returns true for opaque
1902 vector_targets_convertible_p (const_tree t1
, const_tree t2
)
1904 if (TREE_CODE (t1
) == VECTOR_TYPE
&& TREE_CODE (t2
) == VECTOR_TYPE
1905 && (TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
1906 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
1912 /* True if vector types T1 and T2 can be converted to each other
1913 without an explicit cast. If EMIT_LAX_NOTE is true, and T1 and T2
1914 can only be converted with -flax-vector-conversions yet that is not
1915 in effect, emit a note telling the user about that option if such
1916 a note has not previously been emitted. */
1918 vector_types_convertible_p (const_tree t1
, const_tree t2
, bool emit_lax_note
)
1920 static bool emitted_lax_note
= false;
1921 bool convertible_lax
;
1923 if ((TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
1924 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
1928 (tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
))
1929 && (TREE_CODE (TREE_TYPE (t1
)) != REAL_TYPE
||
1930 TYPE_PRECISION (t1
) == TYPE_PRECISION (t2
))
1931 && (INTEGRAL_TYPE_P (TREE_TYPE (t1
))
1932 == INTEGRAL_TYPE_P (TREE_TYPE (t2
))));
1934 if (!convertible_lax
|| flag_lax_vector_conversions
)
1935 return convertible_lax
;
1937 if (TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
)
1938 && lang_hooks
.types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
1941 if (emit_lax_note
&& !emitted_lax_note
)
1943 emitted_lax_note
= true;
1944 inform (input_location
, "use -flax-vector-conversions to permit "
1945 "conversions between vectors with differing "
1946 "element types or numbers of subparts");
1952 /* Build a VEC_PERM_EXPR if V0, V1 and MASK are not error_mark_nodes
1953 and have vector types, V0 has the same type as V1, and the number of
1954 elements of V0, V1, MASK is the same.
1956 In case V1 is a NULL_TREE it is assumed that __builtin_shuffle was
1957 called with two arguments. In this case implementation passes the
1958 first argument twice in order to share the same tree code. This fact
1959 could enable the mask-values being twice the vector length. This is
1960 an implementation accident and this semantics is not guaranteed to
1963 c_build_vec_perm_expr (location_t loc
, tree v0
, tree v1
, tree mask
)
1967 bool maybe_const
= false;
1968 bool two_arguments
= false;
1970 if (v1
== NULL_TREE
)
1972 two_arguments
= true;
1976 if (v0
== error_mark_node
|| v1
== error_mark_node
1977 || mask
== error_mark_node
)
1978 return error_mark_node
;
1980 if (TREE_CODE (TREE_TYPE (mask
)) != VECTOR_TYPE
1981 || TREE_CODE (TREE_TYPE (TREE_TYPE (mask
))) != INTEGER_TYPE
)
1983 error_at (loc
, "__builtin_shuffle last argument must "
1984 "be an integer vector");
1985 return error_mark_node
;
1988 if (TREE_CODE (TREE_TYPE (v0
)) != VECTOR_TYPE
1989 || TREE_CODE (TREE_TYPE (v1
)) != VECTOR_TYPE
)
1991 error_at (loc
, "__builtin_shuffle arguments must be vectors");
1992 return error_mark_node
;
1995 if (TYPE_MAIN_VARIANT (TREE_TYPE (v0
)) != TYPE_MAIN_VARIANT (TREE_TYPE (v1
)))
1997 error_at (loc
, "__builtin_shuffle argument vectors must be of "
1999 return error_mark_node
;
2002 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (v0
))
2003 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
))
2004 && TYPE_VECTOR_SUBPARTS (TREE_TYPE (v1
))
2005 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
)))
2007 error_at (loc
, "__builtin_shuffle number of elements of the "
2008 "argument vector(s) and the mask vector should "
2010 return error_mark_node
;
2013 if (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (v0
))))
2014 != GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (mask
)))))
2016 error_at (loc
, "__builtin_shuffle argument vector(s) inner type "
2017 "must have the same size as inner type of the mask");
2018 return error_mark_node
;
2021 if (!c_dialect_cxx ())
2023 /* Avoid C_MAYBE_CONST_EXPRs inside VEC_PERM_EXPR. */
2024 v0
= c_fully_fold (v0
, false, &maybe_const
);
2025 wrap
&= maybe_const
;
2028 v1
= v0
= save_expr (v0
);
2031 v1
= c_fully_fold (v1
, false, &maybe_const
);
2032 wrap
&= maybe_const
;
2035 mask
= c_fully_fold (mask
, false, &maybe_const
);
2036 wrap
&= maybe_const
;
2039 ret
= build3_loc (loc
, VEC_PERM_EXPR
, TREE_TYPE (v0
), v0
, v1
, mask
);
2041 if (!c_dialect_cxx () && !wrap
)
2042 ret
= c_wrap_maybe_const (ret
, true);
2047 /* Like tree.c:get_narrower, but retain conversion from C++0x scoped enum
2048 to integral type. */
2051 c_common_get_narrower (tree op
, int *unsignedp_ptr
)
2053 op
= get_narrower (op
, unsignedp_ptr
);
2055 if (TREE_CODE (TREE_TYPE (op
)) == ENUMERAL_TYPE
2056 && ENUM_IS_SCOPED (TREE_TYPE (op
)))
2058 /* C++0x scoped enumerations don't implicitly convert to integral
2059 type; if we stripped an explicit conversion to a larger type we
2060 need to replace it so common_type will still work. */
2061 tree type
= c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op
)),
2062 TYPE_UNSIGNED (TREE_TYPE (op
)));
2063 op
= fold_convert (type
, op
);
2068 /* This is a helper function of build_binary_op.
2070 For certain operations if both args were extended from the same
2071 smaller type, do the arithmetic in that type and then extend.
2073 BITWISE indicates a bitwise operation.
2074 For them, this optimization is safe only if
2075 both args are zero-extended or both are sign-extended.
2076 Otherwise, we might change the result.
2077 Eg, (short)-1 | (unsigned short)-1 is (int)-1
2078 but calculated in (unsigned short) it would be (unsigned short)-1.
2081 shorten_binary_op (tree result_type
, tree op0
, tree op1
, bool bitwise
)
2083 int unsigned0
, unsigned1
;
2088 /* Cast OP0 and OP1 to RESULT_TYPE. Doing so prevents
2089 excessive narrowing when we call get_narrower below. For
2090 example, suppose that OP0 is of unsigned int extended
2091 from signed char and that RESULT_TYPE is long long int.
2092 If we explicitly cast OP0 to RESULT_TYPE, OP0 would look
2095 (long long int) (unsigned int) signed_char
2097 which get_narrower would narrow down to
2099 (unsigned int) signed char
2101 If we do not cast OP0 first, get_narrower would return
2102 signed_char, which is inconsistent with the case of the
2104 op0
= convert (result_type
, op0
);
2105 op1
= convert (result_type
, op1
);
2107 arg0
= c_common_get_narrower (op0
, &unsigned0
);
2108 arg1
= c_common_get_narrower (op1
, &unsigned1
);
2110 /* UNS is 1 if the operation to be done is an unsigned one. */
2111 uns
= TYPE_UNSIGNED (result_type
);
2113 /* Handle the case that OP0 (or OP1) does not *contain* a conversion
2114 but it *requires* conversion to FINAL_TYPE. */
2116 if ((TYPE_PRECISION (TREE_TYPE (op0
))
2117 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2118 && TREE_TYPE (op0
) != result_type
)
2119 unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2120 if ((TYPE_PRECISION (TREE_TYPE (op1
))
2121 == TYPE_PRECISION (TREE_TYPE (arg1
)))
2122 && TREE_TYPE (op1
) != result_type
)
2123 unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2125 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
2127 /* For bitwise operations, signedness of nominal type
2128 does not matter. Consider only how operands were extended. */
2132 /* Note that in all three cases below we refrain from optimizing
2133 an unsigned operation on sign-extended args.
2134 That would not be valid. */
2136 /* Both args variable: if both extended in same way
2137 from same width, do it in that width.
2138 Do it unsigned if args were zero-extended. */
2139 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
2140 < TYPE_PRECISION (result_type
))
2141 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2142 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2143 && unsigned0
== unsigned1
2144 && (unsigned0
|| !uns
))
2145 return c_common_signed_or_unsigned_type
2146 (unsigned0
, common_type (TREE_TYPE (arg0
), TREE_TYPE (arg1
)));
2148 else if (TREE_CODE (arg0
) == INTEGER_CST
2149 && (unsigned1
|| !uns
)
2150 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2151 < TYPE_PRECISION (result_type
))
2153 = c_common_signed_or_unsigned_type (unsigned1
,
2155 && !POINTER_TYPE_P (type
)
2156 && int_fits_type_p (arg0
, type
))
2159 else if (TREE_CODE (arg1
) == INTEGER_CST
2160 && (unsigned0
|| !uns
)
2161 && (TYPE_PRECISION (TREE_TYPE (arg0
))
2162 < TYPE_PRECISION (result_type
))
2164 = c_common_signed_or_unsigned_type (unsigned0
,
2166 && !POINTER_TYPE_P (type
)
2167 && int_fits_type_p (arg1
, type
))
2173 /* Checks if expression EXPR of real/integer type cannot be converted
2174 to the real/integer type TYPE. Function returns true when:
2175 * EXPR is a constant which cannot be exactly converted to TYPE
2176 * EXPR is not a constant and size of EXPR's type > than size of TYPE,
2177 for EXPR type and TYPE being both integers or both real.
2178 * EXPR is not a constant of real type and TYPE is an integer.
2179 * EXPR is not a constant of integer type which cannot be
2180 exactly converted to real type.
2181 Function allows conversions between types of different signedness and
2182 does not return true in that case. Function can produce signedness
2183 warnings if PRODUCE_WARNS is true. */
2185 unsafe_conversion_p (tree type
, tree expr
, bool produce_warns
)
2187 bool give_warning
= false;
2188 tree expr_type
= TREE_TYPE (expr
);
2189 location_t loc
= EXPR_LOC_OR_HERE (expr
);
2191 if (TREE_CODE (expr
) == REAL_CST
|| TREE_CODE (expr
) == INTEGER_CST
)
2193 /* Warn for real constant that is not an exact integer converted
2195 if (TREE_CODE (expr_type
) == REAL_TYPE
2196 && TREE_CODE (type
) == INTEGER_TYPE
)
2198 if (!real_isinteger (TREE_REAL_CST_PTR (expr
), TYPE_MODE (expr_type
)))
2199 give_warning
= true;
2201 /* Warn for an integer constant that does not fit into integer type. */
2202 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2203 && TREE_CODE (type
) == INTEGER_TYPE
2204 && !int_fits_type_p (expr
, type
))
2206 if (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)
2207 && tree_int_cst_sgn (expr
) < 0)
2210 warning_at (loc
, OPT_Wsign_conversion
, "negative integer"
2211 " implicitly converted to unsigned type");
2213 else if (!TYPE_UNSIGNED (type
) && TYPE_UNSIGNED (expr_type
))
2216 warning_at (loc
, OPT_Wsign_conversion
, "conversion of unsigned"
2217 " constant value to negative integer");
2220 give_warning
= true;
2222 else if (TREE_CODE (type
) == REAL_TYPE
)
2224 /* Warn for an integer constant that does not fit into real type. */
2225 if (TREE_CODE (expr_type
) == INTEGER_TYPE
)
2227 REAL_VALUE_TYPE a
= real_value_from_int_cst (0, expr
);
2228 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2229 give_warning
= true;
2231 /* Warn for a real constant that does not fit into a smaller
2233 else if (TREE_CODE (expr_type
) == REAL_TYPE
2234 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2236 REAL_VALUE_TYPE a
= TREE_REAL_CST (expr
);
2237 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2238 give_warning
= true;
2244 /* Warn for real types converted to integer types. */
2245 if (TREE_CODE (expr_type
) == REAL_TYPE
2246 && TREE_CODE (type
) == INTEGER_TYPE
)
2247 give_warning
= true;
2249 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2250 && TREE_CODE (type
) == INTEGER_TYPE
)
2252 /* Don't warn about unsigned char y = 0xff, x = (int) y; */
2253 expr
= get_unwidened (expr
, 0);
2254 expr_type
= TREE_TYPE (expr
);
2256 /* Don't warn for short y; short x = ((int)y & 0xff); */
2257 if (TREE_CODE (expr
) == BIT_AND_EXPR
2258 || TREE_CODE (expr
) == BIT_IOR_EXPR
2259 || TREE_CODE (expr
) == BIT_XOR_EXPR
)
2261 /* If both args were extended from a shortest type,
2262 use that type if that is safe. */
2263 expr_type
= shorten_binary_op (expr_type
,
2264 TREE_OPERAND (expr
, 0),
2265 TREE_OPERAND (expr
, 1),
2268 if (TREE_CODE (expr
) == BIT_AND_EXPR
)
2270 tree op0
= TREE_OPERAND (expr
, 0);
2271 tree op1
= TREE_OPERAND (expr
, 1);
2272 bool unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2273 bool unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2275 /* If one of the operands is a non-negative constant
2276 that fits in the target type, then the type of the
2277 other operand does not matter. */
2278 if ((TREE_CODE (op0
) == INTEGER_CST
2279 && int_fits_type_p (op0
, c_common_signed_type (type
))
2280 && int_fits_type_p (op0
, c_common_unsigned_type (type
)))
2281 || (TREE_CODE (op1
) == INTEGER_CST
2282 && int_fits_type_p (op1
, c_common_signed_type (type
))
2283 && int_fits_type_p (op1
,
2284 c_common_unsigned_type (type
))))
2286 /* If constant is unsigned and fits in the target
2287 type, then the result will also fit. */
2288 else if ((TREE_CODE (op0
) == INTEGER_CST
2290 && int_fits_type_p (op0
, type
))
2291 || (TREE_CODE (op1
) == INTEGER_CST
2293 && int_fits_type_p (op1
, type
)))
2297 /* Warn for integer types converted to smaller integer types. */
2298 if (TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2299 give_warning
= true;
2301 /* When they are the same width but different signedness,
2302 then the value may change. */
2303 else if (((TYPE_PRECISION (type
) == TYPE_PRECISION (expr_type
)
2304 && TYPE_UNSIGNED (expr_type
) != TYPE_UNSIGNED (type
))
2305 /* Even when converted to a bigger type, if the type is
2306 unsigned but expr is signed, then negative values
2308 || (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)))
2310 warning_at (loc
, OPT_Wsign_conversion
, "conversion to %qT from %qT "
2311 "may change the sign of the result",
2315 /* Warn for integer types converted to real types if and only if
2316 all the range of values of the integer type cannot be
2317 represented by the real type. */
2318 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2319 && TREE_CODE (type
) == REAL_TYPE
)
2321 tree type_low_bound
, type_high_bound
;
2322 REAL_VALUE_TYPE real_low_bound
, real_high_bound
;
2324 /* Don't warn about char y = 0xff; float x = (int) y; */
2325 expr
= get_unwidened (expr
, 0);
2326 expr_type
= TREE_TYPE (expr
);
2328 type_low_bound
= TYPE_MIN_VALUE (expr_type
);
2329 type_high_bound
= TYPE_MAX_VALUE (expr_type
);
2330 real_low_bound
= real_value_from_int_cst (0, type_low_bound
);
2331 real_high_bound
= real_value_from_int_cst (0, type_high_bound
);
2333 if (!exact_real_truncate (TYPE_MODE (type
), &real_low_bound
)
2334 || !exact_real_truncate (TYPE_MODE (type
), &real_high_bound
))
2335 give_warning
= true;
2338 /* Warn for real types converted to smaller real types. */
2339 else if (TREE_CODE (expr_type
) == REAL_TYPE
2340 && TREE_CODE (type
) == REAL_TYPE
2341 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2342 give_warning
= true;
2345 return give_warning
;
2348 /* Warns if the conversion of EXPR to TYPE may alter a value.
2349 This is a helper function for warnings_for_convert_and_check. */
2352 conversion_warning (tree type
, tree expr
)
2354 tree expr_type
= TREE_TYPE (expr
);
2355 location_t loc
= EXPR_LOC_OR_HERE (expr
);
2357 if (!warn_conversion
&& !warn_sign_conversion
)
2360 switch (TREE_CODE (expr
))
2368 case TRUTH_ANDIF_EXPR
:
2369 case TRUTH_ORIF_EXPR
:
2370 case TRUTH_AND_EXPR
:
2372 case TRUTH_XOR_EXPR
:
2373 case TRUTH_NOT_EXPR
:
2374 /* Conversion from boolean to a signed:1 bit-field (which only
2375 can hold the values 0 and -1) doesn't lose information - but
2376 it does change the value. */
2377 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
2378 warning_at (loc
, OPT_Wconversion
,
2379 "conversion to %qT from boolean expression", type
);
2384 if (unsafe_conversion_p (type
, expr
, true))
2385 warning_at (loc
, OPT_Wconversion
,
2386 "conversion to %qT alters %qT constant value",
2392 /* In case of COND_EXPR, if both operands are constants or
2393 COND_EXPR, then we do not care about the type of COND_EXPR,
2394 only about the conversion of each operand. */
2395 tree op1
= TREE_OPERAND (expr
, 1);
2396 tree op2
= TREE_OPERAND (expr
, 2);
2398 if ((TREE_CODE (op1
) == REAL_CST
|| TREE_CODE (op1
) == INTEGER_CST
2399 || TREE_CODE (op1
) == COND_EXPR
)
2400 && (TREE_CODE (op2
) == REAL_CST
|| TREE_CODE (op2
) == INTEGER_CST
2401 || TREE_CODE (op2
) == COND_EXPR
))
2403 conversion_warning (type
, op1
);
2404 conversion_warning (type
, op2
);
2410 default: /* 'expr' is not a constant. */
2411 if (unsafe_conversion_p (type
, expr
, true))
2412 warning_at (loc
, OPT_Wconversion
,
2413 "conversion to %qT from %qT may alter its value",
2418 /* Produce warnings after a conversion. RESULT is the result of
2419 converting EXPR to TYPE. This is a helper function for
2420 convert_and_check and cp_convert_and_check. */
2423 warnings_for_convert_and_check (tree type
, tree expr
, tree result
)
2425 location_t loc
= EXPR_LOC_OR_HERE (expr
);
2427 if (TREE_CODE (expr
) == INTEGER_CST
2428 && (TREE_CODE (type
) == INTEGER_TYPE
2429 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2430 && !int_fits_type_p (expr
, type
))
2432 /* Do not diagnose overflow in a constant expression merely
2433 because a conversion overflowed. */
2434 if (TREE_OVERFLOW (result
))
2435 TREE_OVERFLOW (result
) = TREE_OVERFLOW (expr
);
2437 if (TYPE_UNSIGNED (type
))
2439 /* This detects cases like converting -129 or 256 to
2441 if (!int_fits_type_p (expr
, c_common_signed_type (type
)))
2442 warning_at (loc
, OPT_Woverflow
,
2443 "large integer implicitly truncated to unsigned type");
2445 conversion_warning (type
, expr
);
2447 else if (!int_fits_type_p (expr
, c_common_unsigned_type (type
)))
2448 warning (OPT_Woverflow
,
2449 "overflow in implicit constant conversion");
2450 /* No warning for converting 0x80000000 to int. */
2452 && (TREE_CODE (TREE_TYPE (expr
)) != INTEGER_TYPE
2453 || TYPE_PRECISION (TREE_TYPE (expr
))
2454 != TYPE_PRECISION (type
)))
2455 warning_at (loc
, OPT_Woverflow
,
2456 "overflow in implicit constant conversion");
2459 conversion_warning (type
, expr
);
2461 else if ((TREE_CODE (result
) == INTEGER_CST
2462 || TREE_CODE (result
) == FIXED_CST
) && TREE_OVERFLOW (result
))
2463 warning_at (loc
, OPT_Woverflow
,
2464 "overflow in implicit constant conversion");
2466 conversion_warning (type
, expr
);
2470 /* Convert EXPR to TYPE, warning about conversion problems with constants.
2471 Invoke this function on every expression that is converted implicitly,
2472 i.e. because of language rules and not because of an explicit cast. */
2475 convert_and_check (tree type
, tree expr
)
2478 tree expr_for_warning
;
2480 /* Convert from a value with possible excess precision rather than
2481 via the semantic type, but do not warn about values not fitting
2482 exactly in the semantic type. */
2483 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
2485 tree orig_type
= TREE_TYPE (expr
);
2486 expr
= TREE_OPERAND (expr
, 0);
2487 expr_for_warning
= convert (orig_type
, expr
);
2488 if (orig_type
== type
)
2489 return expr_for_warning
;
2492 expr_for_warning
= expr
;
2494 if (TREE_TYPE (expr
) == type
)
2497 result
= convert (type
, expr
);
2499 if (c_inhibit_evaluation_warnings
== 0
2500 && !TREE_OVERFLOW_P (expr
)
2501 && result
!= error_mark_node
)
2502 warnings_for_convert_and_check (type
, expr_for_warning
, result
);
2507 /* A node in a list that describes references to variables (EXPR), which are
2508 either read accesses if WRITER is zero, or write accesses, in which case
2509 WRITER is the parent of EXPR. */
2516 /* Used to implement a cache the results of a call to verify_tree. We only
2517 use this for SAVE_EXPRs. */
2520 struct tlist_cache
*next
;
2521 struct tlist
*cache_before_sp
;
2522 struct tlist
*cache_after_sp
;
2526 /* Obstack to use when allocating tlist structures, and corresponding
2528 static struct obstack tlist_obstack
;
2529 static char *tlist_firstobj
= 0;
2531 /* Keep track of the identifiers we've warned about, so we can avoid duplicate
2533 static struct tlist
*warned_ids
;
2534 /* SAVE_EXPRs need special treatment. We process them only once and then
2535 cache the results. */
2536 static struct tlist_cache
*save_expr_cache
;
2538 static void add_tlist (struct tlist
**, struct tlist
*, tree
, int);
2539 static void merge_tlist (struct tlist
**, struct tlist
*, int);
2540 static void verify_tree (tree
, struct tlist
**, struct tlist
**, tree
);
2541 static int warning_candidate_p (tree
);
2542 static bool candidate_equal_p (const_tree
, const_tree
);
2543 static void warn_for_collisions (struct tlist
*);
2544 static void warn_for_collisions_1 (tree
, tree
, struct tlist
*, int);
2545 static struct tlist
*new_tlist (struct tlist
*, tree
, tree
);
2547 /* Create a new struct tlist and fill in its fields. */
2548 static struct tlist
*
2549 new_tlist (struct tlist
*next
, tree t
, tree writer
)
2552 l
= XOBNEW (&tlist_obstack
, struct tlist
);
2559 /* Add duplicates of the nodes found in ADD to the list *TO. If EXCLUDE_WRITER
2560 is nonnull, we ignore any node we find which has a writer equal to it. */
2563 add_tlist (struct tlist
**to
, struct tlist
*add
, tree exclude_writer
, int copy
)
2567 struct tlist
*next
= add
->next
;
2570 if (!exclude_writer
|| !candidate_equal_p (add
->writer
, exclude_writer
))
2571 *to
= copy
? new_tlist (*to
, add
->expr
, add
->writer
) : add
;
2576 /* Merge the nodes of ADD into TO. This merging process is done so that for
2577 each variable that already exists in TO, no new node is added; however if
2578 there is a write access recorded in ADD, and an occurrence on TO is only
2579 a read access, then the occurrence in TO will be modified to record the
2583 merge_tlist (struct tlist
**to
, struct tlist
*add
, int copy
)
2585 struct tlist
**end
= to
;
2588 end
= &(*end
)->next
;
2594 struct tlist
*next
= add
->next
;
2596 for (tmp2
= *to
; tmp2
; tmp2
= tmp2
->next
)
2597 if (candidate_equal_p (tmp2
->expr
, add
->expr
))
2601 tmp2
->writer
= add
->writer
;
2605 *end
= copy
? add
: new_tlist (NULL
, add
->expr
, add
->writer
);
2606 end
= &(*end
)->next
;
2613 /* WRITTEN is a variable, WRITER is its parent. Warn if any of the variable
2614 references in list LIST conflict with it, excluding reads if ONLY writers
2618 warn_for_collisions_1 (tree written
, tree writer
, struct tlist
*list
,
2623 /* Avoid duplicate warnings. */
2624 for (tmp
= warned_ids
; tmp
; tmp
= tmp
->next
)
2625 if (candidate_equal_p (tmp
->expr
, written
))
2630 if (candidate_equal_p (list
->expr
, written
)
2631 && !candidate_equal_p (list
->writer
, writer
)
2632 && (!only_writes
|| list
->writer
))
2634 warned_ids
= new_tlist (warned_ids
, written
, NULL_TREE
);
2635 warning_at (EXPR_LOC_OR_HERE (writer
),
2636 OPT_Wsequence_point
, "operation on %qE may be undefined",
2643 /* Given a list LIST of references to variables, find whether any of these
2644 can cause conflicts due to missing sequence points. */
2647 warn_for_collisions (struct tlist
*list
)
2651 for (tmp
= list
; tmp
; tmp
= tmp
->next
)
2654 warn_for_collisions_1 (tmp
->expr
, tmp
->writer
, list
, 0);
2658 /* Return nonzero if X is a tree that can be verified by the sequence point
2661 warning_candidate_p (tree x
)
2663 if (DECL_P (x
) && DECL_ARTIFICIAL (x
))
2666 if (TREE_CODE (x
) == BLOCK
)
2669 /* VOID_TYPE_P (TREE_TYPE (x)) is workaround for cp/tree.c
2670 (lvalue_p) crash on TRY/CATCH. */
2671 if (TREE_TYPE (x
) == NULL_TREE
|| VOID_TYPE_P (TREE_TYPE (x
)))
2677 /* No point to track non-const calls, they will never satisfy
2679 if (TREE_CODE (x
) == CALL_EXPR
&& (call_expr_flags (x
) & ECF_CONST
) == 0)
2682 if (TREE_CODE (x
) == STRING_CST
)
2688 /* Return nonzero if X and Y appear to be the same candidate (or NULL) */
2690 candidate_equal_p (const_tree x
, const_tree y
)
2692 return (x
== y
) || (x
&& y
&& operand_equal_p (x
, y
, 0));
2695 /* Walk the tree X, and record accesses to variables. If X is written by the
2696 parent tree, WRITER is the parent.
2697 We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP. If this
2698 expression or its only operand forces a sequence point, then everything up
2699 to the sequence point is stored in PBEFORE_SP. Everything else gets stored
2701 Once we return, we will have emitted warnings if any subexpression before
2702 such a sequence point could be undefined. On a higher level, however, the
2703 sequence point may not be relevant, and we'll merge the two lists.
2705 Example: (b++, a) + b;
2706 The call that processes the COMPOUND_EXPR will store the increment of B
2707 in PBEFORE_SP, and the use of A in PNO_SP. The higher-level call that
2708 processes the PLUS_EXPR will need to merge the two lists so that
2709 eventually, all accesses end up on the same list (and we'll warn about the
2710 unordered subexpressions b++ and b.
2712 A note on merging. If we modify the former example so that our expression
2715 care must be taken not simply to add all three expressions into the final
2716 PNO_SP list. The function merge_tlist takes care of that by merging the
2717 before-SP list of the COMPOUND_EXPR into its after-SP list in a special
2718 way, so that no more than one access to B is recorded. */
2721 verify_tree (tree x
, struct tlist
**pbefore_sp
, struct tlist
**pno_sp
,
2724 struct tlist
*tmp_before
, *tmp_nosp
, *tmp_list2
, *tmp_list3
;
2725 enum tree_code code
;
2726 enum tree_code_class cl
;
2728 /* X may be NULL if it is the operand of an empty statement expression
2734 code
= TREE_CODE (x
);
2735 cl
= TREE_CODE_CLASS (code
);
2737 if (warning_candidate_p (x
))
2738 *pno_sp
= new_tlist (*pno_sp
, x
, writer
);
2746 case TRUTH_ANDIF_EXPR
:
2747 case TRUTH_ORIF_EXPR
:
2748 tmp_before
= tmp_nosp
= tmp_list3
= 0;
2749 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
2750 warn_for_collisions (tmp_nosp
);
2751 merge_tlist (pbefore_sp
, tmp_before
, 0);
2752 merge_tlist (pbefore_sp
, tmp_nosp
, 0);
2753 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, pno_sp
, NULL_TREE
);
2754 merge_tlist (pbefore_sp
, tmp_list3
, 0);
2758 tmp_before
= tmp_list2
= 0;
2759 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_list2
, NULL_TREE
);
2760 warn_for_collisions (tmp_list2
);
2761 merge_tlist (pbefore_sp
, tmp_before
, 0);
2762 merge_tlist (pbefore_sp
, tmp_list2
, 1);
2764 tmp_list3
= tmp_nosp
= 0;
2765 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, &tmp_nosp
, NULL_TREE
);
2766 warn_for_collisions (tmp_nosp
);
2767 merge_tlist (pbefore_sp
, tmp_list3
, 0);
2769 tmp_list3
= tmp_list2
= 0;
2770 verify_tree (TREE_OPERAND (x
, 2), &tmp_list3
, &tmp_list2
, NULL_TREE
);
2771 warn_for_collisions (tmp_list2
);
2772 merge_tlist (pbefore_sp
, tmp_list3
, 0);
2773 /* Rather than add both tmp_nosp and tmp_list2, we have to merge the
2774 two first, to avoid warning for (a ? b++ : b++). */
2775 merge_tlist (&tmp_nosp
, tmp_list2
, 0);
2776 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
2779 case PREDECREMENT_EXPR
:
2780 case PREINCREMENT_EXPR
:
2781 case POSTDECREMENT_EXPR
:
2782 case POSTINCREMENT_EXPR
:
2783 verify_tree (TREE_OPERAND (x
, 0), pno_sp
, pno_sp
, x
);
2787 tmp_before
= tmp_nosp
= tmp_list3
= 0;
2788 verify_tree (TREE_OPERAND (x
, 1), &tmp_before
, &tmp_nosp
, NULL_TREE
);
2789 verify_tree (TREE_OPERAND (x
, 0), &tmp_list3
, &tmp_list3
, x
);
2790 /* Expressions inside the LHS are not ordered wrt. the sequence points
2791 in the RHS. Example:
2793 Despite the fact that the modification of "a" is in the before_sp
2794 list (tmp_before), it conflicts with the use of "a" in the LHS.
2795 We can handle this by adding the contents of tmp_list3
2796 to those of tmp_before, and redoing the collision warnings for that
2798 add_tlist (&tmp_before
, tmp_list3
, x
, 1);
2799 warn_for_collisions (tmp_before
);
2800 /* Exclude the LHS itself here; we first have to merge it into the
2801 tmp_nosp list. This is done to avoid warning for "a = a"; if we
2802 didn't exclude the LHS, we'd get it twice, once as a read and once
2804 add_tlist (pno_sp
, tmp_list3
, x
, 0);
2805 warn_for_collisions_1 (TREE_OPERAND (x
, 0), x
, tmp_nosp
, 1);
2807 merge_tlist (pbefore_sp
, tmp_before
, 0);
2808 if (warning_candidate_p (TREE_OPERAND (x
, 0)))
2809 merge_tlist (&tmp_nosp
, new_tlist (NULL
, TREE_OPERAND (x
, 0), x
), 0);
2810 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 1);
2814 /* We need to warn about conflicts among arguments and conflicts between
2815 args and the function address. Side effects of the function address,
2816 however, are not ordered by the sequence point of the call. */
2818 call_expr_arg_iterator iter
;
2820 tmp_before
= tmp_nosp
= 0;
2821 verify_tree (CALL_EXPR_FN (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
2822 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, x
)
2824 tmp_list2
= tmp_list3
= 0;
2825 verify_tree (arg
, &tmp_list2
, &tmp_list3
, NULL_TREE
);
2826 merge_tlist (&tmp_list3
, tmp_list2
, 0);
2827 add_tlist (&tmp_before
, tmp_list3
, NULL_TREE
, 0);
2829 add_tlist (&tmp_before
, tmp_nosp
, NULL_TREE
, 0);
2830 warn_for_collisions (tmp_before
);
2831 add_tlist (pbefore_sp
, tmp_before
, NULL_TREE
, 0);
2836 /* Scan all the list, e.g. indices of multi dimensional array. */
2839 tmp_before
= tmp_nosp
= 0;
2840 verify_tree (TREE_VALUE (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
2841 merge_tlist (&tmp_nosp
, tmp_before
, 0);
2842 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
2849 struct tlist_cache
*t
;
2850 for (t
= save_expr_cache
; t
; t
= t
->next
)
2851 if (candidate_equal_p (t
->expr
, x
))
2856 t
= XOBNEW (&tlist_obstack
, struct tlist_cache
);
2857 t
->next
= save_expr_cache
;
2859 save_expr_cache
= t
;
2861 tmp_before
= tmp_nosp
= 0;
2862 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
2863 warn_for_collisions (tmp_nosp
);
2868 struct tlist
*t
= tmp_nosp
;
2870 merge_tlist (&tmp_list3
, t
, 0);
2872 t
->cache_before_sp
= tmp_before
;
2873 t
->cache_after_sp
= tmp_list3
;
2875 merge_tlist (pbefore_sp
, t
->cache_before_sp
, 1);
2876 add_tlist (pno_sp
, t
->cache_after_sp
, NULL_TREE
, 1);
2881 x
= TREE_OPERAND (x
, 0);
2888 /* For other expressions, simply recurse on their operands.
2889 Manual tail recursion for unary expressions.
2890 Other non-expressions need not be processed. */
2891 if (cl
== tcc_unary
)
2893 x
= TREE_OPERAND (x
, 0);
2897 else if (IS_EXPR_CODE_CLASS (cl
))
2900 int max
= TREE_OPERAND_LENGTH (x
);
2901 for (lp
= 0; lp
< max
; lp
++)
2903 tmp_before
= tmp_nosp
= 0;
2904 verify_tree (TREE_OPERAND (x
, lp
), &tmp_before
, &tmp_nosp
, 0);
2905 merge_tlist (&tmp_nosp
, tmp_before
, 0);
2906 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
2913 /* Try to warn for undefined behavior in EXPR due to missing sequence
2917 verify_sequence_points (tree expr
)
2919 struct tlist
*before_sp
= 0, *after_sp
= 0;
2922 save_expr_cache
= 0;
2923 if (tlist_firstobj
== 0)
2925 gcc_obstack_init (&tlist_obstack
);
2926 tlist_firstobj
= (char *) obstack_alloc (&tlist_obstack
, 0);
2929 verify_tree (expr
, &before_sp
, &after_sp
, 0);
2930 warn_for_collisions (after_sp
);
2931 obstack_free (&tlist_obstack
, tlist_firstobj
);
2934 /* Validate the expression after `case' and apply default promotions. */
2937 check_case_value (tree value
)
2939 if (value
== NULL_TREE
)
2942 if (TREE_CODE (value
) == INTEGER_CST
)
2943 /* Promote char or short to int. */
2944 value
= perform_integral_promotions (value
);
2945 else if (value
!= error_mark_node
)
2947 error ("case label does not reduce to an integer constant");
2948 value
= error_mark_node
;
2951 constant_expression_warning (value
);
2956 /* See if the case values LOW and HIGH are in the range of the original
2957 type (i.e. before the default conversion to int) of the switch testing
2959 TYPE is the promoted type of the testing expression, and ORIG_TYPE is
2960 the type before promoting it. CASE_LOW_P is a pointer to the lower
2961 bound of the case label, and CASE_HIGH_P is the upper bound or NULL
2962 if the case is not a case range.
2963 The caller has to make sure that we are not called with NULL for
2964 CASE_LOW_P (i.e. the default case).
2965 Returns true if the case label is in range of ORIG_TYPE (saturated or
2966 untouched) or false if the label is out of range. */
2969 check_case_bounds (tree type
, tree orig_type
,
2970 tree
*case_low_p
, tree
*case_high_p
)
2972 tree min_value
, max_value
;
2973 tree case_low
= *case_low_p
;
2974 tree case_high
= case_high_p
? *case_high_p
: case_low
;
2976 /* If there was a problem with the original type, do nothing. */
2977 if (orig_type
== error_mark_node
)
2980 min_value
= TYPE_MIN_VALUE (orig_type
);
2981 max_value
= TYPE_MAX_VALUE (orig_type
);
2983 /* Case label is less than minimum for type. */
2984 if (tree_int_cst_compare (case_low
, min_value
) < 0
2985 && tree_int_cst_compare (case_high
, min_value
) < 0)
2987 warning (0, "case label value is less than minimum value for type");
2991 /* Case value is greater than maximum for type. */
2992 if (tree_int_cst_compare (case_low
, max_value
) > 0
2993 && tree_int_cst_compare (case_high
, max_value
) > 0)
2995 warning (0, "case label value exceeds maximum value for type");
2999 /* Saturate lower case label value to minimum. */
3000 if (tree_int_cst_compare (case_high
, min_value
) >= 0
3001 && tree_int_cst_compare (case_low
, min_value
) < 0)
3003 warning (0, "lower value in case label range"
3004 " less than minimum value for type");
3005 case_low
= min_value
;
3008 /* Saturate upper case label value to maximum. */
3009 if (tree_int_cst_compare (case_low
, max_value
) <= 0
3010 && tree_int_cst_compare (case_high
, max_value
) > 0)
3012 warning (0, "upper value in case label range"
3013 " exceeds maximum value for type");
3014 case_high
= max_value
;
3017 if (*case_low_p
!= case_low
)
3018 *case_low_p
= convert (type
, case_low
);
3019 if (case_high_p
&& *case_high_p
!= case_high
)
3020 *case_high_p
= convert (type
, case_high
);
3025 /* Return an integer type with BITS bits of precision,
3026 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
3029 c_common_type_for_size (unsigned int bits
, int unsignedp
)
3031 if (bits
== TYPE_PRECISION (integer_type_node
))
3032 return unsignedp
? unsigned_type_node
: integer_type_node
;
3034 if (bits
== TYPE_PRECISION (signed_char_type_node
))
3035 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3037 if (bits
== TYPE_PRECISION (short_integer_type_node
))
3038 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3040 if (bits
== TYPE_PRECISION (long_integer_type_node
))
3041 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3043 if (bits
== TYPE_PRECISION (long_long_integer_type_node
))
3044 return (unsignedp
? long_long_unsigned_type_node
3045 : long_long_integer_type_node
);
3047 if (int128_integer_type_node
3048 && bits
== TYPE_PRECISION (int128_integer_type_node
))
3049 return (unsignedp
? int128_unsigned_type_node
3050 : int128_integer_type_node
);
3052 if (bits
== TYPE_PRECISION (widest_integer_literal_type_node
))
3053 return (unsignedp
? widest_unsigned_literal_type_node
3054 : widest_integer_literal_type_node
);
3056 if (bits
<= TYPE_PRECISION (intQI_type_node
))
3057 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3059 if (bits
<= TYPE_PRECISION (intHI_type_node
))
3060 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3062 if (bits
<= TYPE_PRECISION (intSI_type_node
))
3063 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3065 if (bits
<= TYPE_PRECISION (intDI_type_node
))
3066 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3071 /* Return a fixed-point type that has at least IBIT ibits and FBIT fbits
3072 that is unsigned if UNSIGNEDP is nonzero, otherwise signed;
3073 and saturating if SATP is nonzero, otherwise not saturating. */
3076 c_common_fixed_point_type_for_size (unsigned int ibit
, unsigned int fbit
,
3077 int unsignedp
, int satp
)
3079 enum machine_mode mode
;
3081 mode
= unsignedp
? UQQmode
: QQmode
;
3083 mode
= unsignedp
? UHAmode
: HAmode
;
3085 for (; mode
!= VOIDmode
; mode
= GET_MODE_WIDER_MODE (mode
))
3086 if (GET_MODE_IBIT (mode
) >= ibit
&& GET_MODE_FBIT (mode
) >= fbit
)
3089 if (mode
== VOIDmode
|| !targetm
.scalar_mode_supported_p (mode
))
3091 sorry ("GCC cannot support operators with integer types and "
3092 "fixed-point types that have too many integral and "
3093 "fractional bits together");
3097 return c_common_type_for_mode (mode
, satp
);
3100 /* Used for communication between c_common_type_for_mode and
3101 c_register_builtin_type. */
3102 static GTY(()) tree registered_builtin_types
;
3104 /* Return a data type that has machine mode MODE.
3105 If the mode is an integer,
3106 then UNSIGNEDP selects between signed and unsigned types.
3107 If the mode is a fixed-point mode,
3108 then UNSIGNEDP selects between saturating and nonsaturating types. */
3111 c_common_type_for_mode (enum machine_mode mode
, int unsignedp
)
3115 if (mode
== TYPE_MODE (integer_type_node
))
3116 return unsignedp
? unsigned_type_node
: integer_type_node
;
3118 if (mode
== TYPE_MODE (signed_char_type_node
))
3119 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3121 if (mode
== TYPE_MODE (short_integer_type_node
))
3122 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3124 if (mode
== TYPE_MODE (long_integer_type_node
))
3125 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3127 if (mode
== TYPE_MODE (long_long_integer_type_node
))
3128 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3130 if (int128_integer_type_node
3131 && mode
== TYPE_MODE (int128_integer_type_node
))
3132 return unsignedp
? int128_unsigned_type_node
: int128_integer_type_node
;
3134 if (mode
== TYPE_MODE (widest_integer_literal_type_node
))
3135 return unsignedp
? widest_unsigned_literal_type_node
3136 : widest_integer_literal_type_node
;
3139 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3142 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3145 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3148 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3150 #if HOST_BITS_PER_WIDE_INT >= 64
3151 if (mode
== TYPE_MODE (intTI_type_node
))
3152 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3155 if (mode
== TYPE_MODE (float_type_node
))
3156 return float_type_node
;
3158 if (mode
== TYPE_MODE (double_type_node
))
3159 return double_type_node
;
3161 if (mode
== TYPE_MODE (long_double_type_node
))
3162 return long_double_type_node
;
3164 if (mode
== TYPE_MODE (void_type_node
))
3165 return void_type_node
;
3167 if (mode
== TYPE_MODE (build_pointer_type (char_type_node
)))
3169 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3170 : make_signed_type (GET_MODE_PRECISION (mode
)));
3172 if (mode
== TYPE_MODE (build_pointer_type (integer_type_node
)))
3174 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3175 : make_signed_type (GET_MODE_PRECISION (mode
)));
3177 if (COMPLEX_MODE_P (mode
))
3179 enum machine_mode inner_mode
;
3182 if (mode
== TYPE_MODE (complex_float_type_node
))
3183 return complex_float_type_node
;
3184 if (mode
== TYPE_MODE (complex_double_type_node
))
3185 return complex_double_type_node
;
3186 if (mode
== TYPE_MODE (complex_long_double_type_node
))
3187 return complex_long_double_type_node
;
3189 if (mode
== TYPE_MODE (complex_integer_type_node
) && !unsignedp
)
3190 return complex_integer_type_node
;
3192 inner_mode
= GET_MODE_INNER (mode
);
3193 inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3194 if (inner_type
!= NULL_TREE
)
3195 return build_complex_type (inner_type
);
3197 else if (VECTOR_MODE_P (mode
))
3199 enum machine_mode inner_mode
= GET_MODE_INNER (mode
);
3200 tree inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3201 if (inner_type
!= NULL_TREE
)
3202 return build_vector_type_for_mode (inner_type
, mode
);
3205 if (mode
== TYPE_MODE (dfloat32_type_node
))
3206 return dfloat32_type_node
;
3207 if (mode
== TYPE_MODE (dfloat64_type_node
))
3208 return dfloat64_type_node
;
3209 if (mode
== TYPE_MODE (dfloat128_type_node
))
3210 return dfloat128_type_node
;
3212 if (ALL_SCALAR_FIXED_POINT_MODE_P (mode
))
3214 if (mode
== TYPE_MODE (short_fract_type_node
))
3215 return unsignedp
? sat_short_fract_type_node
: short_fract_type_node
;
3216 if (mode
== TYPE_MODE (fract_type_node
))
3217 return unsignedp
? sat_fract_type_node
: fract_type_node
;
3218 if (mode
== TYPE_MODE (long_fract_type_node
))
3219 return unsignedp
? sat_long_fract_type_node
: long_fract_type_node
;
3220 if (mode
== TYPE_MODE (long_long_fract_type_node
))
3221 return unsignedp
? sat_long_long_fract_type_node
3222 : long_long_fract_type_node
;
3224 if (mode
== TYPE_MODE (unsigned_short_fract_type_node
))
3225 return unsignedp
? sat_unsigned_short_fract_type_node
3226 : unsigned_short_fract_type_node
;
3227 if (mode
== TYPE_MODE (unsigned_fract_type_node
))
3228 return unsignedp
? sat_unsigned_fract_type_node
3229 : unsigned_fract_type_node
;
3230 if (mode
== TYPE_MODE (unsigned_long_fract_type_node
))
3231 return unsignedp
? sat_unsigned_long_fract_type_node
3232 : unsigned_long_fract_type_node
;
3233 if (mode
== TYPE_MODE (unsigned_long_long_fract_type_node
))
3234 return unsignedp
? sat_unsigned_long_long_fract_type_node
3235 : unsigned_long_long_fract_type_node
;
3237 if (mode
== TYPE_MODE (short_accum_type_node
))
3238 return unsignedp
? sat_short_accum_type_node
: short_accum_type_node
;
3239 if (mode
== TYPE_MODE (accum_type_node
))
3240 return unsignedp
? sat_accum_type_node
: accum_type_node
;
3241 if (mode
== TYPE_MODE (long_accum_type_node
))
3242 return unsignedp
? sat_long_accum_type_node
: long_accum_type_node
;
3243 if (mode
== TYPE_MODE (long_long_accum_type_node
))
3244 return unsignedp
? sat_long_long_accum_type_node
3245 : long_long_accum_type_node
;
3247 if (mode
== TYPE_MODE (unsigned_short_accum_type_node
))
3248 return unsignedp
? sat_unsigned_short_accum_type_node
3249 : unsigned_short_accum_type_node
;
3250 if (mode
== TYPE_MODE (unsigned_accum_type_node
))
3251 return unsignedp
? sat_unsigned_accum_type_node
3252 : unsigned_accum_type_node
;
3253 if (mode
== TYPE_MODE (unsigned_long_accum_type_node
))
3254 return unsignedp
? sat_unsigned_long_accum_type_node
3255 : unsigned_long_accum_type_node
;
3256 if (mode
== TYPE_MODE (unsigned_long_long_accum_type_node
))
3257 return unsignedp
? sat_unsigned_long_long_accum_type_node
3258 : unsigned_long_long_accum_type_node
;
3261 return unsignedp
? sat_qq_type_node
: qq_type_node
;
3263 return unsignedp
? sat_hq_type_node
: hq_type_node
;
3265 return unsignedp
? sat_sq_type_node
: sq_type_node
;
3267 return unsignedp
? sat_dq_type_node
: dq_type_node
;
3269 return unsignedp
? sat_tq_type_node
: tq_type_node
;
3271 if (mode
== UQQmode
)
3272 return unsignedp
? sat_uqq_type_node
: uqq_type_node
;
3273 if (mode
== UHQmode
)
3274 return unsignedp
? sat_uhq_type_node
: uhq_type_node
;
3275 if (mode
== USQmode
)
3276 return unsignedp
? sat_usq_type_node
: usq_type_node
;
3277 if (mode
== UDQmode
)
3278 return unsignedp
? sat_udq_type_node
: udq_type_node
;
3279 if (mode
== UTQmode
)
3280 return unsignedp
? sat_utq_type_node
: utq_type_node
;
3283 return unsignedp
? sat_ha_type_node
: ha_type_node
;
3285 return unsignedp
? sat_sa_type_node
: sa_type_node
;
3287 return unsignedp
? sat_da_type_node
: da_type_node
;
3289 return unsignedp
? sat_ta_type_node
: ta_type_node
;
3291 if (mode
== UHAmode
)
3292 return unsignedp
? sat_uha_type_node
: uha_type_node
;
3293 if (mode
== USAmode
)
3294 return unsignedp
? sat_usa_type_node
: usa_type_node
;
3295 if (mode
== UDAmode
)
3296 return unsignedp
? sat_uda_type_node
: uda_type_node
;
3297 if (mode
== UTAmode
)
3298 return unsignedp
? sat_uta_type_node
: uta_type_node
;
3301 for (t
= registered_builtin_types
; t
; t
= TREE_CHAIN (t
))
3302 if (TYPE_MODE (TREE_VALUE (t
)) == mode
3303 && !!unsignedp
== !!TYPE_UNSIGNED (TREE_VALUE (t
)))
3304 return TREE_VALUE (t
);
3310 c_common_unsigned_type (tree type
)
3312 return c_common_signed_or_unsigned_type (1, type
);
3315 /* Return a signed type the same as TYPE in other respects. */
3318 c_common_signed_type (tree type
)
3320 return c_common_signed_or_unsigned_type (0, type
);
3323 /* Return a type the same as TYPE except unsigned or
3324 signed according to UNSIGNEDP. */
3327 c_common_signed_or_unsigned_type (int unsignedp
, tree type
)
3331 /* This block of code emulates the behavior of the old
3332 c_common_unsigned_type. In particular, it returns
3333 long_unsigned_type_node if passed a long, even when a int would
3334 have the same size. This is necessary for warnings to work
3335 correctly in archs where sizeof(int) == sizeof(long) */
3337 type1
= TYPE_MAIN_VARIANT (type
);
3338 if (type1
== signed_char_type_node
|| type1
== char_type_node
|| type1
== unsigned_char_type_node
)
3339 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3340 if (type1
== integer_type_node
|| type1
== unsigned_type_node
)
3341 return unsignedp
? unsigned_type_node
: integer_type_node
;
3342 if (type1
== short_integer_type_node
|| type1
== short_unsigned_type_node
)
3343 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3344 if (type1
== long_integer_type_node
|| type1
== long_unsigned_type_node
)
3345 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3346 if (type1
== long_long_integer_type_node
|| type1
== long_long_unsigned_type_node
)
3347 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3348 if (int128_integer_type_node
3349 && (type1
== int128_integer_type_node
3350 || type1
== int128_unsigned_type_node
))
3351 return unsignedp
? int128_unsigned_type_node
: int128_integer_type_node
;
3352 if (type1
== widest_integer_literal_type_node
|| type1
== widest_unsigned_literal_type_node
)
3353 return unsignedp
? widest_unsigned_literal_type_node
: widest_integer_literal_type_node
;
3354 #if HOST_BITS_PER_WIDE_INT >= 64
3355 if (type1
== intTI_type_node
|| type1
== unsigned_intTI_type_node
)
3356 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3358 if (type1
== intDI_type_node
|| type1
== unsigned_intDI_type_node
)
3359 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3360 if (type1
== intSI_type_node
|| type1
== unsigned_intSI_type_node
)
3361 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3362 if (type1
== intHI_type_node
|| type1
== unsigned_intHI_type_node
)
3363 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3364 if (type1
== intQI_type_node
|| type1
== unsigned_intQI_type_node
)
3365 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3367 #define C_COMMON_FIXED_TYPES(NAME) \
3368 if (type1 == short_ ## NAME ## _type_node \
3369 || type1 == unsigned_short_ ## NAME ## _type_node) \
3370 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
3371 : short_ ## NAME ## _type_node; \
3372 if (type1 == NAME ## _type_node \
3373 || type1 == unsigned_ ## NAME ## _type_node) \
3374 return unsignedp ? unsigned_ ## NAME ## _type_node \
3375 : NAME ## _type_node; \
3376 if (type1 == long_ ## NAME ## _type_node \
3377 || type1 == unsigned_long_ ## NAME ## _type_node) \
3378 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
3379 : long_ ## NAME ## _type_node; \
3380 if (type1 == long_long_ ## NAME ## _type_node \
3381 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
3382 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
3383 : long_long_ ## NAME ## _type_node;
3385 #define C_COMMON_FIXED_MODE_TYPES(NAME) \
3386 if (type1 == NAME ## _type_node \
3387 || type1 == u ## NAME ## _type_node) \
3388 return unsignedp ? u ## NAME ## _type_node \
3389 : NAME ## _type_node;
3391 #define C_COMMON_FIXED_TYPES_SAT(NAME) \
3392 if (type1 == sat_ ## short_ ## NAME ## _type_node \
3393 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
3394 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
3395 : sat_ ## short_ ## NAME ## _type_node; \
3396 if (type1 == sat_ ## NAME ## _type_node \
3397 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
3398 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
3399 : sat_ ## NAME ## _type_node; \
3400 if (type1 == sat_ ## long_ ## NAME ## _type_node \
3401 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
3402 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
3403 : sat_ ## long_ ## NAME ## _type_node; \
3404 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
3405 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
3406 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
3407 : sat_ ## long_long_ ## NAME ## _type_node;
3409 #define C_COMMON_FIXED_MODE_TYPES_SAT(NAME) \
3410 if (type1 == sat_ ## NAME ## _type_node \
3411 || type1 == sat_ ## u ## NAME ## _type_node) \
3412 return unsignedp ? sat_ ## u ## NAME ## _type_node \
3413 : sat_ ## NAME ## _type_node;
3415 C_COMMON_FIXED_TYPES (fract
);
3416 C_COMMON_FIXED_TYPES_SAT (fract
);
3417 C_COMMON_FIXED_TYPES (accum
);
3418 C_COMMON_FIXED_TYPES_SAT (accum
);
3420 C_COMMON_FIXED_MODE_TYPES (qq
);
3421 C_COMMON_FIXED_MODE_TYPES (hq
);
3422 C_COMMON_FIXED_MODE_TYPES (sq
);
3423 C_COMMON_FIXED_MODE_TYPES (dq
);
3424 C_COMMON_FIXED_MODE_TYPES (tq
);
3425 C_COMMON_FIXED_MODE_TYPES_SAT (qq
);
3426 C_COMMON_FIXED_MODE_TYPES_SAT (hq
);
3427 C_COMMON_FIXED_MODE_TYPES_SAT (sq
);
3428 C_COMMON_FIXED_MODE_TYPES_SAT (dq
);
3429 C_COMMON_FIXED_MODE_TYPES_SAT (tq
);
3430 C_COMMON_FIXED_MODE_TYPES (ha
);
3431 C_COMMON_FIXED_MODE_TYPES (sa
);
3432 C_COMMON_FIXED_MODE_TYPES (da
);
3433 C_COMMON_FIXED_MODE_TYPES (ta
);
3434 C_COMMON_FIXED_MODE_TYPES_SAT (ha
);
3435 C_COMMON_FIXED_MODE_TYPES_SAT (sa
);
3436 C_COMMON_FIXED_MODE_TYPES_SAT (da
);
3437 C_COMMON_FIXED_MODE_TYPES_SAT (ta
);
3439 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
3440 the precision; they have precision set to match their range, but
3441 may use a wider mode to match an ABI. If we change modes, we may
3442 wind up with bad conversions. For INTEGER_TYPEs in C, must check
3443 the precision as well, so as to yield correct results for
3444 bit-field types. C++ does not have these separate bit-field
3445 types, and producing a signed or unsigned variant of an
3446 ENUMERAL_TYPE may cause other problems as well. */
3448 if (!INTEGRAL_TYPE_P (type
)
3449 || TYPE_UNSIGNED (type
) == unsignedp
)
3452 #define TYPE_OK(node) \
3453 (TYPE_MODE (type) == TYPE_MODE (node) \
3454 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
3455 if (TYPE_OK (signed_char_type_node
))
3456 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3457 if (TYPE_OK (integer_type_node
))
3458 return unsignedp
? unsigned_type_node
: integer_type_node
;
3459 if (TYPE_OK (short_integer_type_node
))
3460 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3461 if (TYPE_OK (long_integer_type_node
))
3462 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3463 if (TYPE_OK (long_long_integer_type_node
))
3464 return (unsignedp
? long_long_unsigned_type_node
3465 : long_long_integer_type_node
);
3466 if (int128_integer_type_node
&& TYPE_OK (int128_integer_type_node
))
3467 return (unsignedp
? int128_unsigned_type_node
3468 : int128_integer_type_node
);
3469 if (TYPE_OK (widest_integer_literal_type_node
))
3470 return (unsignedp
? widest_unsigned_literal_type_node
3471 : widest_integer_literal_type_node
);
3473 #if HOST_BITS_PER_WIDE_INT >= 64
3474 if (TYPE_OK (intTI_type_node
))
3475 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3477 if (TYPE_OK (intDI_type_node
))
3478 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3479 if (TYPE_OK (intSI_type_node
))
3480 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3481 if (TYPE_OK (intHI_type_node
))
3482 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3483 if (TYPE_OK (intQI_type_node
))
3484 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3487 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
3490 /* Build a bit-field integer type for the given WIDTH and UNSIGNEDP. */
3493 c_build_bitfield_integer_type (unsigned HOST_WIDE_INT width
, int unsignedp
)
3495 /* Extended integer types of the same width as a standard type have
3496 lesser rank, so those of the same width as int promote to int or
3497 unsigned int and are valid for printf formats expecting int or
3498 unsigned int. To avoid such special cases, avoid creating
3499 extended integer types for bit-fields if a standard integer type
3501 if (width
== TYPE_PRECISION (integer_type_node
))
3502 return unsignedp
? unsigned_type_node
: integer_type_node
;
3503 if (width
== TYPE_PRECISION (signed_char_type_node
))
3504 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3505 if (width
== TYPE_PRECISION (short_integer_type_node
))
3506 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3507 if (width
== TYPE_PRECISION (long_integer_type_node
))
3508 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3509 if (width
== TYPE_PRECISION (long_long_integer_type_node
))
3510 return (unsignedp
? long_long_unsigned_type_node
3511 : long_long_integer_type_node
);
3512 if (int128_integer_type_node
3513 && width
== TYPE_PRECISION (int128_integer_type_node
))
3514 return (unsignedp
? int128_unsigned_type_node
3515 : int128_integer_type_node
);
3516 return build_nonstandard_integer_type (width
, unsignedp
);
3519 /* The C version of the register_builtin_type langhook. */
3522 c_register_builtin_type (tree type
, const char* name
)
3526 decl
= build_decl (UNKNOWN_LOCATION
,
3527 TYPE_DECL
, get_identifier (name
), type
);
3528 DECL_ARTIFICIAL (decl
) = 1;
3529 if (!TYPE_NAME (type
))
3530 TYPE_NAME (type
) = decl
;
3533 registered_builtin_types
= tree_cons (0, type
, registered_builtin_types
);
3536 /* Print an error message for invalid operands to arith operation
3537 CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
3538 LOCATION is the location of the message. */
3541 binary_op_error (location_t location
, enum tree_code code
,
3542 tree type0
, tree type1
)
3549 opname
= "+"; break;
3551 opname
= "-"; break;
3553 opname
= "*"; break;
3555 opname
= "max"; break;
3557 opname
= "min"; break;
3559 opname
= "=="; break;
3561 opname
= "!="; break;
3563 opname
= "<="; break;
3565 opname
= ">="; break;
3567 opname
= "<"; break;
3569 opname
= ">"; break;
3571 opname
= "<<"; break;
3573 opname
= ">>"; break;
3574 case TRUNC_MOD_EXPR
:
3575 case FLOOR_MOD_EXPR
:
3576 opname
= "%"; break;
3577 case TRUNC_DIV_EXPR
:
3578 case FLOOR_DIV_EXPR
:
3579 opname
= "/"; break;
3581 opname
= "&"; break;
3583 opname
= "|"; break;
3584 case TRUTH_ANDIF_EXPR
:
3585 opname
= "&&"; break;
3586 case TRUTH_ORIF_EXPR
:
3587 opname
= "||"; break;
3589 opname
= "^"; break;
3594 "invalid operands to binary %s (have %qT and %qT)", opname
,
3598 /* Given an expression as a tree, return its original type. Do this
3599 by stripping any conversion that preserves the sign and precision. */
3601 expr_original_type (tree expr
)
3603 STRIP_SIGN_NOPS (expr
);
3604 return TREE_TYPE (expr
);
3607 /* Subroutine of build_binary_op, used for comparison operations.
3608 See if the operands have both been converted from subword integer types
3609 and, if so, perhaps change them both back to their original type.
3610 This function is also responsible for converting the two operands
3611 to the proper common type for comparison.
3613 The arguments of this function are all pointers to local variables
3614 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
3615 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
3617 If this function returns nonzero, it means that the comparison has
3618 a constant value. What this function returns is an expression for
3622 shorten_compare (tree
*op0_ptr
, tree
*op1_ptr
, tree
*restype_ptr
,
3623 enum tree_code
*rescode_ptr
)
3626 tree op0
= *op0_ptr
;
3627 tree op1
= *op1_ptr
;
3628 int unsignedp0
, unsignedp1
;
3630 tree primop0
, primop1
;
3631 enum tree_code code
= *rescode_ptr
;
3632 location_t loc
= EXPR_LOC_OR_HERE (op0
);
3634 /* Throw away any conversions to wider types
3635 already present in the operands. */
3637 primop0
= c_common_get_narrower (op0
, &unsignedp0
);
3638 primop1
= c_common_get_narrower (op1
, &unsignedp1
);
3640 /* If primopN is first sign-extended from primopN's precision to opN's
3641 precision, then zero-extended from opN's precision to
3642 *restype_ptr precision, shortenings might be invalid. */
3643 if (TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (TREE_TYPE (op0
))
3644 && TYPE_PRECISION (TREE_TYPE (op0
)) < TYPE_PRECISION (*restype_ptr
)
3646 && TYPE_UNSIGNED (TREE_TYPE (op0
)))
3648 if (TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (TREE_TYPE (op1
))
3649 && TYPE_PRECISION (TREE_TYPE (op1
)) < TYPE_PRECISION (*restype_ptr
)
3651 && TYPE_UNSIGNED (TREE_TYPE (op1
)))
3654 /* Handle the case that OP0 does not *contain* a conversion
3655 but it *requires* conversion to FINAL_TYPE. */
3657 if (op0
== primop0
&& TREE_TYPE (op0
) != *restype_ptr
)
3658 unsignedp0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
3659 if (op1
== primop1
&& TREE_TYPE (op1
) != *restype_ptr
)
3660 unsignedp1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
3662 /* If one of the operands must be floated, we cannot optimize. */
3663 real1
= TREE_CODE (TREE_TYPE (primop0
)) == REAL_TYPE
;
3664 real2
= TREE_CODE (TREE_TYPE (primop1
)) == REAL_TYPE
;
3666 /* If first arg is constant, swap the args (changing operation
3667 so value is preserved), for canonicalization. Don't do this if
3668 the second arg is 0. */
3670 if (TREE_CONSTANT (primop0
)
3671 && !integer_zerop (primop1
) && !real_zerop (primop1
)
3672 && !fixed_zerop (primop1
))
3675 int temi
= unsignedp0
;
3683 unsignedp0
= unsignedp1
;
3706 *rescode_ptr
= code
;
3709 /* If comparing an integer against a constant more bits wide,
3710 maybe we can deduce a value of 1 or 0 independent of the data.
3711 Or else truncate the constant now
3712 rather than extend the variable at run time.
3714 This is only interesting if the constant is the wider arg.
3715 Also, it is not safe if the constant is unsigned and the
3716 variable arg is signed, since in this case the variable
3717 would be sign-extended and then regarded as unsigned.
3718 Our technique fails in this case because the lowest/highest
3719 possible unsigned results don't follow naturally from the
3720 lowest/highest possible values of the variable operand.
3721 For just EQ_EXPR and NE_EXPR there is another technique that
3722 could be used: see if the constant can be faithfully represented
3723 in the other operand's type, by truncating it and reextending it
3724 and see if that preserves the constant's value. */
3726 if (!real1
&& !real2
3727 && TREE_CODE (TREE_TYPE (primop0
)) != FIXED_POINT_TYPE
3728 && TREE_CODE (primop1
) == INTEGER_CST
3729 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
))
3731 int min_gt
, max_gt
, min_lt
, max_lt
;
3732 tree maxval
, minval
;
3733 /* 1 if comparison is nominally unsigned. */
3734 int unsignedp
= TYPE_UNSIGNED (*restype_ptr
);
3737 type
= c_common_signed_or_unsigned_type (unsignedp0
,
3738 TREE_TYPE (primop0
));
3740 maxval
= TYPE_MAX_VALUE (type
);
3741 minval
= TYPE_MIN_VALUE (type
);
3743 if (unsignedp
&& !unsignedp0
)
3744 *restype_ptr
= c_common_signed_type (*restype_ptr
);
3746 if (TREE_TYPE (primop1
) != *restype_ptr
)
3748 /* Convert primop1 to target type, but do not introduce
3749 additional overflow. We know primop1 is an int_cst. */
3750 primop1
= force_fit_type_double (*restype_ptr
,
3751 tree_to_double_int (primop1
),
3752 0, TREE_OVERFLOW (primop1
));
3754 if (type
!= *restype_ptr
)
3756 minval
= convert (*restype_ptr
, minval
);
3757 maxval
= convert (*restype_ptr
, maxval
);
3760 if (unsignedp
&& unsignedp0
)
3762 min_gt
= INT_CST_LT_UNSIGNED (primop1
, minval
);
3763 max_gt
= INT_CST_LT_UNSIGNED (primop1
, maxval
);
3764 min_lt
= INT_CST_LT_UNSIGNED (minval
, primop1
);
3765 max_lt
= INT_CST_LT_UNSIGNED (maxval
, primop1
);
3769 min_gt
= INT_CST_LT (primop1
, minval
);
3770 max_gt
= INT_CST_LT (primop1
, maxval
);
3771 min_lt
= INT_CST_LT (minval
, primop1
);
3772 max_lt
= INT_CST_LT (maxval
, primop1
);
3776 /* This used to be a switch, but Genix compiler can't handle that. */
3777 if (code
== NE_EXPR
)
3779 if (max_lt
|| min_gt
)
3780 val
= truthvalue_true_node
;
3782 else if (code
== EQ_EXPR
)
3784 if (max_lt
|| min_gt
)
3785 val
= truthvalue_false_node
;
3787 else if (code
== LT_EXPR
)
3790 val
= truthvalue_true_node
;
3792 val
= truthvalue_false_node
;
3794 else if (code
== GT_EXPR
)
3797 val
= truthvalue_true_node
;
3799 val
= truthvalue_false_node
;
3801 else if (code
== LE_EXPR
)
3804 val
= truthvalue_true_node
;
3806 val
= truthvalue_false_node
;
3808 else if (code
== GE_EXPR
)
3811 val
= truthvalue_true_node
;
3813 val
= truthvalue_false_node
;
3816 /* If primop0 was sign-extended and unsigned comparison specd,
3817 we did a signed comparison above using the signed type bounds.
3818 But the comparison we output must be unsigned.
3820 Also, for inequalities, VAL is no good; but if the signed
3821 comparison had *any* fixed result, it follows that the
3822 unsigned comparison just tests the sign in reverse
3823 (positive values are LE, negative ones GE).
3824 So we can generate an unsigned comparison
3825 against an extreme value of the signed type. */
3827 if (unsignedp
&& !unsignedp0
)
3834 primop1
= TYPE_MIN_VALUE (type
);
3840 primop1
= TYPE_MAX_VALUE (type
);
3847 type
= c_common_unsigned_type (type
);
3850 if (TREE_CODE (primop0
) != INTEGER_CST
3851 && c_inhibit_evaluation_warnings
== 0)
3853 if (val
== truthvalue_false_node
)
3854 warning_at (loc
, OPT_Wtype_limits
,
3855 "comparison is always false due to limited range of data type");
3856 if (val
== truthvalue_true_node
)
3857 warning_at (loc
, OPT_Wtype_limits
,
3858 "comparison is always true due to limited range of data type");
3863 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
3864 if (TREE_SIDE_EFFECTS (primop0
))
3865 return build2 (COMPOUND_EXPR
, TREE_TYPE (val
), primop0
, val
);
3869 /* Value is not predetermined, but do the comparison
3870 in the type of the operand that is not constant.
3871 TYPE is already properly set. */
3874 /* If either arg is decimal float and the other is float, find the
3875 proper common type to use for comparison. */
3876 else if (real1
&& real2
3877 && (DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0
)))
3878 || DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1
)))))
3879 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
3881 else if (real1
&& real2
3882 && (TYPE_PRECISION (TREE_TYPE (primop0
))
3883 == TYPE_PRECISION (TREE_TYPE (primop1
))))
3884 type
= TREE_TYPE (primop0
);
3886 /* If args' natural types are both narrower than nominal type
3887 and both extend in the same manner, compare them
3888 in the type of the wider arg.
3889 Otherwise must actually extend both to the nominal
3890 common type lest different ways of extending
3892 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
3894 else if (unsignedp0
== unsignedp1
&& real1
== real2
3895 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
)
3896 && TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (*restype_ptr
))
3898 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
3899 type
= c_common_signed_or_unsigned_type (unsignedp0
3900 || TYPE_UNSIGNED (*restype_ptr
),
3902 /* Make sure shorter operand is extended the right way
3903 to match the longer operand. */
3905 = convert (c_common_signed_or_unsigned_type (unsignedp0
,
3906 TREE_TYPE (primop0
)),
3909 = convert (c_common_signed_or_unsigned_type (unsignedp1
,
3910 TREE_TYPE (primop1
)),
3915 /* Here we must do the comparison on the nominal type
3916 using the args exactly as we received them. */
3917 type
= *restype_ptr
;
3921 if (!real1
&& !real2
&& integer_zerop (primop1
)
3922 && TYPE_UNSIGNED (*restype_ptr
))
3925 /* All unsigned values are >= 0, so we warn. However,
3926 if OP0 is a constant that is >= 0, the signedness of
3927 the comparison isn't an issue, so suppress the
3930 warn_type_limits
&& !in_system_header
3931 && c_inhibit_evaluation_warnings
== 0
3932 && !(TREE_CODE (primop0
) == INTEGER_CST
3933 && !TREE_OVERFLOW (convert (c_common_signed_type (type
),
3935 /* Do not warn for enumeration types. */
3936 && (TREE_CODE (expr_original_type (primop0
)) != ENUMERAL_TYPE
);
3942 warning_at (loc
, OPT_Wtype_limits
,
3943 "comparison of unsigned expression >= 0 is always true");
3944 value
= truthvalue_true_node
;
3949 warning_at (loc
, OPT_Wtype_limits
,
3950 "comparison of unsigned expression < 0 is always false");
3951 value
= truthvalue_false_node
;
3960 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
3961 if (TREE_SIDE_EFFECTS (primop0
))
3962 return build2 (COMPOUND_EXPR
, TREE_TYPE (value
),
3969 *op0_ptr
= convert (type
, primop0
);
3970 *op1_ptr
= convert (type
, primop1
);
3972 *restype_ptr
= truthvalue_type_node
;
3977 /* Return a tree for the sum or difference (RESULTCODE says which)
3978 of pointer PTROP and integer INTOP. */
3981 pointer_int_sum (location_t loc
, enum tree_code resultcode
,
3982 tree ptrop
, tree intop
)
3986 /* The result is a pointer of the same type that is being added. */
3987 tree result_type
= TREE_TYPE (ptrop
);
3989 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
3991 pedwarn (loc
, pedantic
? OPT_Wpedantic
: OPT_Wpointer_arith
,
3992 "pointer of type %<void *%> used in arithmetic");
3993 size_exp
= integer_one_node
;
3995 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
3997 pedwarn (loc
, pedantic
? OPT_Wpedantic
: OPT_Wpointer_arith
,
3998 "pointer to a function used in arithmetic");
3999 size_exp
= integer_one_node
;
4001 else if (TREE_CODE (TREE_TYPE (result_type
)) == METHOD_TYPE
)
4003 pedwarn (loc
, pedantic
? OPT_Wpedantic
: OPT_Wpointer_arith
,
4004 "pointer to member function used in arithmetic");
4005 size_exp
= integer_one_node
;
4008 size_exp
= size_in_bytes (TREE_TYPE (result_type
));
4010 /* We are manipulating pointer values, so we don't need to warn
4011 about relying on undefined signed overflow. We disable the
4012 warning here because we use integer types so fold won't know that
4013 they are really pointers. */
4014 fold_defer_overflow_warnings ();
4016 /* If what we are about to multiply by the size of the elements
4017 contains a constant term, apply distributive law
4018 and multiply that constant term separately.
4019 This helps produce common subexpressions. */
4020 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
4021 && !TREE_CONSTANT (intop
)
4022 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
4023 && TREE_CONSTANT (size_exp
)
4024 /* If the constant comes from pointer subtraction,
4025 skip this optimization--it would cause an error. */
4026 && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop
, 0))) == INTEGER_TYPE
4027 /* If the constant is unsigned, and smaller than the pointer size,
4028 then we must skip this optimization. This is because it could cause
4029 an overflow error if the constant is negative but INTOP is not. */
4030 && (!TYPE_UNSIGNED (TREE_TYPE (intop
))
4031 || (TYPE_PRECISION (TREE_TYPE (intop
))
4032 == TYPE_PRECISION (TREE_TYPE (ptrop
)))))
4034 enum tree_code subcode
= resultcode
;
4035 tree int_type
= TREE_TYPE (intop
);
4036 if (TREE_CODE (intop
) == MINUS_EXPR
)
4037 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
4038 /* Convert both subexpression types to the type of intop,
4039 because weird cases involving pointer arithmetic
4040 can result in a sum or difference with different type args. */
4041 ptrop
= build_binary_op (EXPR_LOCATION (TREE_OPERAND (intop
, 1)),
4043 convert (int_type
, TREE_OPERAND (intop
, 1)), 1);
4044 intop
= convert (int_type
, TREE_OPERAND (intop
, 0));
4047 /* Convert the integer argument to a type the same size as sizetype
4048 so the multiply won't overflow spuriously. */
4049 if (TYPE_PRECISION (TREE_TYPE (intop
)) != TYPE_PRECISION (sizetype
)
4050 || TYPE_UNSIGNED (TREE_TYPE (intop
)) != TYPE_UNSIGNED (sizetype
))
4051 intop
= convert (c_common_type_for_size (TYPE_PRECISION (sizetype
),
4052 TYPE_UNSIGNED (sizetype
)), intop
);
4054 /* Replace the integer argument with a suitable product by the object size.
4055 Do this multiplication as signed, then convert to the appropriate type
4056 for the pointer operation and disregard an overflow that occurred only
4057 because of the sign-extension change in the latter conversion. */
4059 tree t
= build_binary_op (loc
,
4061 convert (TREE_TYPE (intop
), size_exp
), 1);
4062 intop
= convert (sizetype
, t
);
4063 if (TREE_OVERFLOW_P (intop
) && !TREE_OVERFLOW (t
))
4064 intop
= build_int_cst_wide (TREE_TYPE (intop
), TREE_INT_CST_LOW (intop
),
4065 TREE_INT_CST_HIGH (intop
));
4068 /* Create the sum or difference. */
4069 if (resultcode
== MINUS_EXPR
)
4070 intop
= fold_build1_loc (loc
, NEGATE_EXPR
, sizetype
, intop
);
4072 ret
= fold_build_pointer_plus_loc (loc
, ptrop
, intop
);
4074 fold_undefer_and_ignore_overflow_warnings ();
4079 /* Wrap a C_MAYBE_CONST_EXPR around an expression that is fully folded
4080 and if NON_CONST is known not to be permitted in an evaluated part
4081 of a constant expression. */
4084 c_wrap_maybe_const (tree expr
, bool non_const
)
4086 bool nowarning
= TREE_NO_WARNING (expr
);
4087 location_t loc
= EXPR_LOCATION (expr
);
4089 /* This should never be called for C++. */
4090 if (c_dialect_cxx ())
4093 /* The result of folding may have a NOP_EXPR to set TREE_NO_WARNING. */
4094 STRIP_TYPE_NOPS (expr
);
4095 expr
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (expr
), NULL
, expr
);
4096 C_MAYBE_CONST_EXPR_NON_CONST (expr
) = non_const
;
4098 TREE_NO_WARNING (expr
) = 1;
4099 protected_set_expr_location (expr
, loc
);
4104 /* Wrap a SAVE_EXPR around EXPR, if appropriate. Like save_expr, but
4105 for C folds the inside expression and wraps a C_MAYBE_CONST_EXPR
4106 around the SAVE_EXPR if needed so that c_fully_fold does not need
4107 to look inside SAVE_EXPRs. */
4110 c_save_expr (tree expr
)
4112 bool maybe_const
= true;
4113 if (c_dialect_cxx ())
4114 return save_expr (expr
);
4115 expr
= c_fully_fold (expr
, false, &maybe_const
);
4116 expr
= save_expr (expr
);
4118 expr
= c_wrap_maybe_const (expr
, true);
4122 /* Return whether EXPR is a declaration whose address can never be
4126 decl_with_nonnull_addr_p (const_tree expr
)
4128 return (DECL_P (expr
)
4129 && (TREE_CODE (expr
) == PARM_DECL
4130 || TREE_CODE (expr
) == LABEL_DECL
4131 || !DECL_WEAK (expr
)));
4134 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
4135 or for an `if' or `while' statement or ?..: exp. It should already
4136 have been validated to be of suitable type; otherwise, a bad
4137 diagnostic may result.
4139 The EXPR is located at LOCATION.
4141 This preparation consists of taking the ordinary
4142 representation of an expression expr and producing a valid tree
4143 boolean expression describing whether expr is nonzero. We could
4144 simply always do build_binary_op (NE_EXPR, expr, truthvalue_false_node, 1),
4145 but we optimize comparisons, &&, ||, and !.
4147 The resulting type should always be `truthvalue_type_node'. */
4150 c_common_truthvalue_conversion (location_t location
, tree expr
)
4152 switch (TREE_CODE (expr
))
4154 case EQ_EXPR
: case NE_EXPR
: case UNEQ_EXPR
: case LTGT_EXPR
:
4155 case LE_EXPR
: case GE_EXPR
: case LT_EXPR
: case GT_EXPR
:
4156 case UNLE_EXPR
: case UNGE_EXPR
: case UNLT_EXPR
: case UNGT_EXPR
:
4157 case ORDERED_EXPR
: case UNORDERED_EXPR
:
4158 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4160 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4161 TREE_OPERAND (expr
, 0), TREE_OPERAND (expr
, 1));
4164 case TRUTH_ANDIF_EXPR
:
4165 case TRUTH_ORIF_EXPR
:
4166 case TRUTH_AND_EXPR
:
4168 case TRUTH_XOR_EXPR
:
4169 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4171 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
4172 c_common_truthvalue_conversion (location
,
4173 TREE_OPERAND (expr
, 0)),
4174 c_common_truthvalue_conversion (location
,
4175 TREE_OPERAND (expr
, 1)));
4178 case TRUTH_NOT_EXPR
:
4179 if (TREE_TYPE (expr
) == truthvalue_type_node
)
4181 expr
= build1 (TREE_CODE (expr
), truthvalue_type_node
,
4182 c_common_truthvalue_conversion (location
,
4183 TREE_OPERAND (expr
, 0)));
4190 return integer_zerop (expr
) ? truthvalue_false_node
4191 : truthvalue_true_node
;
4194 return real_compare (NE_EXPR
, &TREE_REAL_CST (expr
), &dconst0
)
4195 ? truthvalue_true_node
4196 : truthvalue_false_node
;
4199 return fixed_compare (NE_EXPR
, &TREE_FIXED_CST (expr
),
4200 &FCONST0 (TYPE_MODE (TREE_TYPE (expr
))))
4201 ? truthvalue_true_node
4202 : truthvalue_false_node
;
4205 expr
= build_unary_op (location
, ADDR_EXPR
, expr
, 0);
4210 tree inner
= TREE_OPERAND (expr
, 0);
4211 if (decl_with_nonnull_addr_p (inner
))
4213 /* Common Ada/Pascal programmer's mistake. */
4214 warning_at (location
,
4216 "the address of %qD will always evaluate as %<true%>",
4218 return truthvalue_true_node
;
4224 expr
= build_binary_op (EXPR_LOCATION (expr
),
4225 (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1))
4226 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4227 c_common_truthvalue_conversion (location
,
4228 TREE_OPERAND (expr
, 0)),
4229 c_common_truthvalue_conversion (location
,
4230 TREE_OPERAND (expr
, 1)),
4237 case EXCESS_PRECISION_EXPR
:
4238 /* These don't change whether an object is nonzero or zero. */
4239 return c_common_truthvalue_conversion (location
, TREE_OPERAND (expr
, 0));
4243 /* These don't change whether an object is zero or nonzero, but
4244 we can't ignore them if their second arg has side-effects. */
4245 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1)))
4247 expr
= build2 (COMPOUND_EXPR
, truthvalue_type_node
,
4248 TREE_OPERAND (expr
, 1),
4249 c_common_truthvalue_conversion
4250 (location
, TREE_OPERAND (expr
, 0)));
4254 return c_common_truthvalue_conversion (location
,
4255 TREE_OPERAND (expr
, 0));
4258 /* Distribute the conversion into the arms of a COND_EXPR. */
4259 if (c_dialect_cxx ())
4261 tree op1
= TREE_OPERAND (expr
, 1);
4262 tree op2
= TREE_OPERAND (expr
, 2);
4263 /* In C++ one of the arms might have void type if it is throw. */
4264 if (!VOID_TYPE_P (TREE_TYPE (op1
)))
4265 op1
= c_common_truthvalue_conversion (location
, op1
);
4266 if (!VOID_TYPE_P (TREE_TYPE (op2
)))
4267 op2
= c_common_truthvalue_conversion (location
, op2
);
4268 expr
= fold_build3_loc (location
, COND_EXPR
, truthvalue_type_node
,
4269 TREE_OPERAND (expr
, 0), op1
, op2
);
4274 /* Folding will happen later for C. */
4275 expr
= build3 (COND_EXPR
, truthvalue_type_node
,
4276 TREE_OPERAND (expr
, 0),
4277 c_common_truthvalue_conversion (location
,
4278 TREE_OPERAND (expr
, 1)),
4279 c_common_truthvalue_conversion (location
,
4280 TREE_OPERAND (expr
, 2)));
4286 tree totype
= TREE_TYPE (expr
);
4287 tree fromtype
= TREE_TYPE (TREE_OPERAND (expr
, 0));
4289 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
4290 since that affects how `default_conversion' will behave. */
4291 if (TREE_CODE (totype
) == REFERENCE_TYPE
4292 || TREE_CODE (fromtype
) == REFERENCE_TYPE
)
4294 /* Don't strip a conversion from C++0x scoped enum, since they
4295 don't implicitly convert to other types. */
4296 if (TREE_CODE (fromtype
) == ENUMERAL_TYPE
4297 && ENUM_IS_SCOPED (fromtype
))
4299 /* If this isn't narrowing the argument, we can ignore it. */
4300 if (TYPE_PRECISION (totype
) >= TYPE_PRECISION (fromtype
))
4301 return c_common_truthvalue_conversion (location
,
4302 TREE_OPERAND (expr
, 0));
4307 if (!TREE_NO_WARNING (expr
)
4308 && warn_parentheses
)
4310 warning (OPT_Wparentheses
,
4311 "suggest parentheses around assignment used as truth value");
4312 TREE_NO_WARNING (expr
) = 1;
4320 if (TREE_CODE (TREE_TYPE (expr
)) == COMPLEX_TYPE
)
4322 tree t
= (in_late_binary_op
? save_expr (expr
) : c_save_expr (expr
));
4323 expr
= (build_binary_op
4324 (EXPR_LOCATION (expr
),
4325 (TREE_SIDE_EFFECTS (expr
)
4326 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4327 c_common_truthvalue_conversion
4329 build_unary_op (location
, REALPART_EXPR
, t
, 0)),
4330 c_common_truthvalue_conversion
4332 build_unary_op (location
, IMAGPART_EXPR
, t
, 0)),
4337 if (TREE_CODE (TREE_TYPE (expr
)) == FIXED_POINT_TYPE
)
4339 tree fixed_zero_node
= build_fixed (TREE_TYPE (expr
),
4341 (TREE_TYPE (expr
))));
4342 return build_binary_op (location
, NE_EXPR
, expr
, fixed_zero_node
, 1);
4345 return build_binary_op (location
, NE_EXPR
, expr
, integer_zero_node
, 1);
4348 protected_set_expr_location (expr
, location
);
4352 static void def_builtin_1 (enum built_in_function fncode
,
4354 enum built_in_class fnclass
,
4355 tree fntype
, tree libtype
,
4356 bool both_p
, bool fallback_p
, bool nonansi_p
,
4357 tree fnattrs
, bool implicit_p
);
4360 /* Apply the TYPE_QUALS to the new DECL. */
4363 c_apply_type_quals_to_decl (int type_quals
, tree decl
)
4365 tree type
= TREE_TYPE (decl
);
4367 if (type
== error_mark_node
)
4370 if ((type_quals
& TYPE_QUAL_CONST
)
4371 || (type
&& TREE_CODE (type
) == REFERENCE_TYPE
))
4372 /* We used to check TYPE_NEEDS_CONSTRUCTING here, but now a constexpr
4373 constructor can produce constant init, so rely on cp_finish_decl to
4374 clear TREE_READONLY if the variable has non-constant init. */
4375 TREE_READONLY (decl
) = 1;
4376 if (type_quals
& TYPE_QUAL_VOLATILE
)
4378 TREE_SIDE_EFFECTS (decl
) = 1;
4379 TREE_THIS_VOLATILE (decl
) = 1;
4381 if (type_quals
& TYPE_QUAL_RESTRICT
)
4383 while (type
&& TREE_CODE (type
) == ARRAY_TYPE
)
4384 /* Allow 'restrict' on arrays of pointers.
4385 FIXME currently we just ignore it. */
4386 type
= TREE_TYPE (type
);
4388 || !POINTER_TYPE_P (type
)
4389 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type
)))
4390 error ("invalid use of %<restrict%>");
4394 /* Hash function for the problem of multiple type definitions in
4395 different files. This must hash all types that will compare
4396 equal via comptypes to the same value. In practice it hashes
4397 on some of the simple stuff and leaves the details to comptypes. */
4400 c_type_hash (const void *p
)
4404 const_tree
const t
= (const_tree
) p
;
4406 switch (TREE_CODE (t
))
4408 /* For pointers, hash on pointee type plus some swizzling. */
4410 return c_type_hash (TREE_TYPE (t
)) ^ 0x3003003;
4411 /* Hash on number of elements and total size. */
4414 t2
= TYPE_VALUES (t
);
4418 t2
= TYPE_FIELDS (t
);
4420 case QUAL_UNION_TYPE
:
4422 t2
= TYPE_FIELDS (t
);
4426 t2
= TYPE_FIELDS (t
);
4431 /* FIXME: We want to use a DECL_CHAIN iteration method here, but
4432 TYPE_VALUES of ENUMERAL_TYPEs is stored as a TREE_LIST. */
4433 n_elements
= list_length (t2
);
4434 /* We might have a VLA here. */
4435 if (TREE_CODE (TYPE_SIZE (t
)) != INTEGER_CST
)
4438 size
= TREE_INT_CST_LOW (TYPE_SIZE (t
));
4439 return ((size
<< 24) | (n_elements
<< shift
));
4442 static GTY((param_is (union tree_node
))) htab_t type_hash_table
;
4444 /* Return the typed-based alias set for T, which may be an expression
4445 or a type. Return -1 if we don't do anything special. */
4448 c_common_get_alias_set (tree t
)
4453 /* For VLAs, use the alias set of the element type rather than the
4454 default of alias set 0 for types compared structurally. */
4455 if (TYPE_P (t
) && TYPE_STRUCTURAL_EQUALITY_P (t
))
4457 if (TREE_CODE (t
) == ARRAY_TYPE
)
4458 return get_alias_set (TREE_TYPE (t
));
4462 /* Permit type-punning when accessing a union, provided the access
4463 is directly through the union. For example, this code does not
4464 permit taking the address of a union member and then storing
4465 through it. Even the type-punning allowed here is a GCC
4466 extension, albeit a common and useful one; the C standard says
4467 that such accesses have implementation-defined behavior. */
4469 TREE_CODE (u
) == COMPONENT_REF
|| TREE_CODE (u
) == ARRAY_REF
;
4470 u
= TREE_OPERAND (u
, 0))
4471 if (TREE_CODE (u
) == COMPONENT_REF
4472 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u
, 0))) == UNION_TYPE
)
4475 /* That's all the expressions we handle specially. */
4479 /* The C standard guarantees that any object may be accessed via an
4480 lvalue that has character type. */
4481 if (t
== char_type_node
4482 || t
== signed_char_type_node
4483 || t
== unsigned_char_type_node
)
4486 /* The C standard specifically allows aliasing between signed and
4487 unsigned variants of the same type. We treat the signed
4488 variant as canonical. */
4489 if (TREE_CODE (t
) == INTEGER_TYPE
&& TYPE_UNSIGNED (t
))
4491 tree t1
= c_common_signed_type (t
);
4493 /* t1 == t can happen for boolean nodes which are always unsigned. */
4495 return get_alias_set (t1
);
4498 /* Handle the case of multiple type nodes referring to "the same" type,
4499 which occurs with IMA. These share an alias set. FIXME: Currently only
4500 C90 is handled. (In C99 type compatibility is not transitive, which
4501 complicates things mightily. The alias set splay trees can theoretically
4502 represent this, but insertion is tricky when you consider all the
4503 different orders things might arrive in.) */
4505 if (c_language
!= clk_c
|| flag_isoc99
)
4508 /* Save time if there's only one input file. */
4509 if (num_in_fnames
== 1)
4512 /* Pointers need special handling if they point to any type that
4513 needs special handling (below). */
4514 if (TREE_CODE (t
) == POINTER_TYPE
)
4517 /* Find bottom type under any nested POINTERs. */
4518 for (t2
= TREE_TYPE (t
);
4519 TREE_CODE (t2
) == POINTER_TYPE
;
4520 t2
= TREE_TYPE (t2
))
4522 if (TREE_CODE (t2
) != RECORD_TYPE
4523 && TREE_CODE (t2
) != ENUMERAL_TYPE
4524 && TREE_CODE (t2
) != QUAL_UNION_TYPE
4525 && TREE_CODE (t2
) != UNION_TYPE
)
4527 if (TYPE_SIZE (t2
) == 0)
4530 /* These are the only cases that need special handling. */
4531 if (TREE_CODE (t
) != RECORD_TYPE
4532 && TREE_CODE (t
) != ENUMERAL_TYPE
4533 && TREE_CODE (t
) != QUAL_UNION_TYPE
4534 && TREE_CODE (t
) != UNION_TYPE
4535 && TREE_CODE (t
) != POINTER_TYPE
)
4538 if (TYPE_SIZE (t
) == 0)
4541 /* Look up t in hash table. Only one of the compatible types within each
4542 alias set is recorded in the table. */
4543 if (!type_hash_table
)
4544 type_hash_table
= htab_create_ggc (1021, c_type_hash
,
4545 (htab_eq
) lang_hooks
.types_compatible_p
,
4547 slot
= htab_find_slot (type_hash_table
, t
, INSERT
);
4550 TYPE_ALIAS_SET (t
) = TYPE_ALIAS_SET ((tree
)*slot
);
4551 return TYPE_ALIAS_SET ((tree
)*slot
);
4554 /* Our caller will assign and record (in t) a new alias set; all we need
4555 to do is remember t in the hash table. */
4561 /* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where
4562 the second parameter indicates which OPERATOR is being applied.
4563 The COMPLAIN flag controls whether we should diagnose possibly
4564 ill-formed constructs or not. LOC is the location of the SIZEOF or
4568 c_sizeof_or_alignof_type (location_t loc
,
4569 tree type
, bool is_sizeof
, int complain
)
4571 const char *op_name
;
4573 enum tree_code type_code
= TREE_CODE (type
);
4575 op_name
= is_sizeof
? "sizeof" : "__alignof__";
4577 if (type_code
== FUNCTION_TYPE
)
4581 if (complain
&& (pedantic
|| warn_pointer_arith
))
4582 pedwarn (loc
, pedantic
? OPT_Wpedantic
: OPT_Wpointer_arith
,
4583 "invalid application of %<sizeof%> to a function type");
4585 return error_mark_node
;
4586 value
= size_one_node
;
4592 if (c_dialect_cxx ())
4593 pedwarn (loc
, OPT_Wpedantic
, "ISO C++ does not permit "
4594 "%<alignof%> applied to a function type");
4596 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not permit "
4597 "%<_Alignof%> applied to a function type");
4599 value
= size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
4602 else if (type_code
== VOID_TYPE
|| type_code
== ERROR_MARK
)
4604 if (type_code
== VOID_TYPE
4605 && complain
&& (pedantic
|| warn_pointer_arith
))
4606 pedwarn (loc
, pedantic
? OPT_Wpedantic
: OPT_Wpointer_arith
,
4607 "invalid application of %qs to a void type", op_name
);
4609 return error_mark_node
;
4610 value
= size_one_node
;
4612 else if (!COMPLETE_TYPE_P (type
)
4613 && (!c_dialect_cxx () || is_sizeof
|| type_code
!= ARRAY_TYPE
))
4616 error_at (loc
, "invalid application of %qs to incomplete type %qT",
4618 return error_mark_node
;
4620 else if (c_dialect_cxx () && type_code
== ARRAY_TYPE
4621 && !COMPLETE_TYPE_P (TREE_TYPE (type
)))
4624 error_at (loc
, "invalid application of %qs to array type %qT of "
4625 "incomplete element type", op_name
, type
);
4626 return error_mark_node
;
4631 /* Convert in case a char is more than one unit. */
4632 value
= size_binop_loc (loc
, CEIL_DIV_EXPR
, TYPE_SIZE_UNIT (type
),
4633 size_int (TYPE_PRECISION (char_type_node
)
4636 value
= size_int (TYPE_ALIGN_UNIT (type
));
4639 /* VALUE will have the middle-end integer type sizetype.
4640 However, we should really return a value of type `size_t',
4641 which is just a typedef for an ordinary integer type. */
4642 value
= fold_convert_loc (loc
, size_type_node
, value
);
4647 /* Implement the __alignof keyword: Return the minimum required
4648 alignment of EXPR, measured in bytes. For VAR_DECLs,
4649 FUNCTION_DECLs and FIELD_DECLs return DECL_ALIGN (which can be set
4650 from an "aligned" __attribute__ specification). LOC is the
4651 location of the ALIGNOF operator. */
4654 c_alignof_expr (location_t loc
, tree expr
)
4658 if (VAR_OR_FUNCTION_DECL_P (expr
))
4659 t
= size_int (DECL_ALIGN_UNIT (expr
));
4661 else if (TREE_CODE (expr
) == COMPONENT_REF
4662 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
, 1)))
4664 error_at (loc
, "%<__alignof%> applied to a bit-field");
4667 else if (TREE_CODE (expr
) == COMPONENT_REF
4668 && TREE_CODE (TREE_OPERAND (expr
, 1)) == FIELD_DECL
)
4669 t
= size_int (DECL_ALIGN_UNIT (TREE_OPERAND (expr
, 1)));
4671 else if (TREE_CODE (expr
) == INDIRECT_REF
)
4673 tree t
= TREE_OPERAND (expr
, 0);
4675 int bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
4677 while (CONVERT_EXPR_P (t
)
4678 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
4682 t
= TREE_OPERAND (t
, 0);
4683 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
4684 if (thisalign
> bestalign
)
4685 best
= t
, bestalign
= thisalign
;
4687 return c_alignof (loc
, TREE_TYPE (TREE_TYPE (best
)));
4690 return c_alignof (loc
, TREE_TYPE (expr
));
4692 return fold_convert_loc (loc
, size_type_node
, t
);
4695 /* Handle C and C++ default attributes. */
4697 enum built_in_attribute
4699 #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
4700 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
4701 #define DEF_ATTR_STRING(ENUM, VALUE) ENUM,
4702 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
4703 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
4704 #include "builtin-attrs.def"
4705 #undef DEF_ATTR_NULL_TREE
4707 #undef DEF_ATTR_STRING
4708 #undef DEF_ATTR_IDENT
4709 #undef DEF_ATTR_TREE_LIST
4713 static GTY(()) tree built_in_attributes
[(int) ATTR_LAST
];
4715 static void c_init_attributes (void);
4719 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
4720 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
4721 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
4722 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
4723 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
4724 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
4725 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
4726 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) NAME,
4727 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) NAME,
4728 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
4729 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
4730 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
4731 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
4732 #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
4733 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG6) \
4735 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
4736 #include "builtin-types.def"
4737 #undef DEF_PRIMITIVE_TYPE
4738 #undef DEF_FUNCTION_TYPE_0
4739 #undef DEF_FUNCTION_TYPE_1
4740 #undef DEF_FUNCTION_TYPE_2
4741 #undef DEF_FUNCTION_TYPE_3
4742 #undef DEF_FUNCTION_TYPE_4
4743 #undef DEF_FUNCTION_TYPE_5
4744 #undef DEF_FUNCTION_TYPE_6
4745 #undef DEF_FUNCTION_TYPE_7
4746 #undef DEF_FUNCTION_TYPE_VAR_0
4747 #undef DEF_FUNCTION_TYPE_VAR_1
4748 #undef DEF_FUNCTION_TYPE_VAR_2
4749 #undef DEF_FUNCTION_TYPE_VAR_3
4750 #undef DEF_FUNCTION_TYPE_VAR_4
4751 #undef DEF_FUNCTION_TYPE_VAR_5
4752 #undef DEF_POINTER_TYPE
4756 typedef enum c_builtin_type builtin_type
;
4758 /* A temporary array for c_common_nodes_and_builtins. Used in
4759 communication with def_fn_type. */
4760 static tree builtin_types
[(int) BT_LAST
+ 1];
4762 /* A helper function for c_common_nodes_and_builtins. Build function type
4763 for DEF with return type RET and N arguments. If VAR is true, then the
4764 function should be variadic after those N arguments.
4766 Takes special care not to ICE if any of the types involved are
4767 error_mark_node, which indicates that said type is not in fact available
4768 (see builtin_type_for_size). In which case the function type as a whole
4769 should be error_mark_node. */
4772 def_fn_type (builtin_type def
, builtin_type ret
, bool var
, int n
, ...)
4775 tree
*args
= XALLOCAVEC (tree
, n
);
4780 for (i
= 0; i
< n
; ++i
)
4782 builtin_type a
= (builtin_type
) va_arg (list
, int);
4783 t
= builtin_types
[a
];
4784 if (t
== error_mark_node
)
4789 t
= builtin_types
[ret
];
4790 if (t
== error_mark_node
)
4793 t
= build_varargs_function_type_array (t
, n
, args
);
4795 t
= build_function_type_array (t
, n
, args
);
4798 builtin_types
[def
] = t
;
4802 /* Build builtin functions common to both C and C++ language
4806 c_define_builtins (tree va_list_ref_type_node
, tree va_list_arg_type_node
)
4808 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
4809 builtin_types[ENUM] = VALUE;
4810 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
4811 def_fn_type (ENUM, RETURN, 0, 0);
4812 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
4813 def_fn_type (ENUM, RETURN, 0, 1, ARG1);
4814 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
4815 def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
4816 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
4817 def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
4818 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
4819 def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
4820 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
4821 def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
4822 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4824 def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
4825 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4827 def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
4828 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
4829 def_fn_type (ENUM, RETURN, 1, 0);
4830 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
4831 def_fn_type (ENUM, RETURN, 1, 1, ARG1);
4832 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
4833 def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
4834 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
4835 def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
4836 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
4837 def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
4838 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
4839 def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
4840 #define DEF_POINTER_TYPE(ENUM, TYPE) \
4841 builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
4843 #include "builtin-types.def"
4845 #undef DEF_PRIMITIVE_TYPE
4846 #undef DEF_FUNCTION_TYPE_1
4847 #undef DEF_FUNCTION_TYPE_2
4848 #undef DEF_FUNCTION_TYPE_3
4849 #undef DEF_FUNCTION_TYPE_4
4850 #undef DEF_FUNCTION_TYPE_5
4851 #undef DEF_FUNCTION_TYPE_6
4852 #undef DEF_FUNCTION_TYPE_VAR_0
4853 #undef DEF_FUNCTION_TYPE_VAR_1
4854 #undef DEF_FUNCTION_TYPE_VAR_2
4855 #undef DEF_FUNCTION_TYPE_VAR_3
4856 #undef DEF_FUNCTION_TYPE_VAR_4
4857 #undef DEF_FUNCTION_TYPE_VAR_5
4858 #undef DEF_POINTER_TYPE
4859 builtin_types
[(int) BT_LAST
] = NULL_TREE
;
4861 c_init_attributes ();
4863 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P, \
4864 NONANSI_P, ATTRS, IMPLICIT, COND) \
4866 def_builtin_1 (ENUM, NAME, CLASS, \
4867 builtin_types[(int) TYPE], \
4868 builtin_types[(int) LIBTYPE], \
4869 BOTH_P, FALLBACK_P, NONANSI_P, \
4870 built_in_attributes[(int) ATTRS], IMPLICIT);
4871 #include "builtins.def"
4874 targetm
.init_builtins ();
4876 build_common_builtin_nodes ();
4882 /* Like get_identifier, but avoid warnings about null arguments when
4883 the argument may be NULL for targets where GCC lacks stdint.h type
4887 c_get_ident (const char *id
)
4889 return get_identifier (id
);
4892 /* Build tree nodes and builtin functions common to both C and C++ language
4896 c_common_nodes_and_builtins (void)
4898 int char16_type_size
;
4899 int char32_type_size
;
4900 int wchar_type_size
;
4901 tree array_domain_type
;
4902 tree va_list_ref_type_node
;
4903 tree va_list_arg_type_node
;
4905 build_common_tree_nodes (flag_signed_char
, flag_short_double
);
4907 /* Define `int' and `char' first so that dbx will output them first. */
4908 record_builtin_type (RID_INT
, NULL
, integer_type_node
);
4909 record_builtin_type (RID_CHAR
, "char", char_type_node
);
4911 /* `signed' is the same as `int'. FIXME: the declarations of "signed",
4912 "unsigned long", "long long unsigned" and "unsigned short" were in C++
4913 but not C. Are the conditionals here needed? */
4914 if (c_dialect_cxx ())
4915 record_builtin_type (RID_SIGNED
, NULL
, integer_type_node
);
4916 record_builtin_type (RID_LONG
, "long int", long_integer_type_node
);
4917 record_builtin_type (RID_UNSIGNED
, "unsigned int", unsigned_type_node
);
4918 record_builtin_type (RID_MAX
, "long unsigned int",
4919 long_unsigned_type_node
);
4920 if (int128_integer_type_node
!= NULL_TREE
)
4922 record_builtin_type (RID_INT128
, "__int128",
4923 int128_integer_type_node
);
4924 record_builtin_type (RID_MAX
, "__int128 unsigned",
4925 int128_unsigned_type_node
);
4927 if (c_dialect_cxx ())
4928 record_builtin_type (RID_MAX
, "unsigned long", long_unsigned_type_node
);
4929 record_builtin_type (RID_MAX
, "long long int",
4930 long_long_integer_type_node
);
4931 record_builtin_type (RID_MAX
, "long long unsigned int",
4932 long_long_unsigned_type_node
);
4933 if (c_dialect_cxx ())
4934 record_builtin_type (RID_MAX
, "long long unsigned",
4935 long_long_unsigned_type_node
);
4936 record_builtin_type (RID_SHORT
, "short int", short_integer_type_node
);
4937 record_builtin_type (RID_MAX
, "short unsigned int",
4938 short_unsigned_type_node
);
4939 if (c_dialect_cxx ())
4940 record_builtin_type (RID_MAX
, "unsigned short",
4941 short_unsigned_type_node
);
4943 /* Define both `signed char' and `unsigned char'. */
4944 record_builtin_type (RID_MAX
, "signed char", signed_char_type_node
);
4945 record_builtin_type (RID_MAX
, "unsigned char", unsigned_char_type_node
);
4947 /* These are types that c_common_type_for_size and
4948 c_common_type_for_mode use. */
4949 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4950 TYPE_DECL
, NULL_TREE
,
4952 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4953 TYPE_DECL
, NULL_TREE
,
4955 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4956 TYPE_DECL
, NULL_TREE
,
4958 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4959 TYPE_DECL
, NULL_TREE
,
4961 #if HOST_BITS_PER_WIDE_INT >= 64
4962 if (targetm
.scalar_mode_supported_p (TImode
))
4963 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4965 get_identifier ("__int128_t"),
4968 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4969 TYPE_DECL
, NULL_TREE
,
4970 unsigned_intQI_type_node
));
4971 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4972 TYPE_DECL
, NULL_TREE
,
4973 unsigned_intHI_type_node
));
4974 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4975 TYPE_DECL
, NULL_TREE
,
4976 unsigned_intSI_type_node
));
4977 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4978 TYPE_DECL
, NULL_TREE
,
4979 unsigned_intDI_type_node
));
4980 #if HOST_BITS_PER_WIDE_INT >= 64
4981 if (targetm
.scalar_mode_supported_p (TImode
))
4982 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4984 get_identifier ("__uint128_t"),
4985 unsigned_intTI_type_node
));
4988 /* Create the widest literal types. */
4989 widest_integer_literal_type_node
4990 = make_signed_type (HOST_BITS_PER_WIDE_INT
* 2);
4991 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4992 TYPE_DECL
, NULL_TREE
,
4993 widest_integer_literal_type_node
));
4995 widest_unsigned_literal_type_node
4996 = make_unsigned_type (HOST_BITS_PER_WIDE_INT
* 2);
4997 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4998 TYPE_DECL
, NULL_TREE
,
4999 widest_unsigned_literal_type_node
));
5001 signed_size_type_node
= c_common_signed_type (size_type_node
);
5004 TREE_TYPE (identifier_global_value (get_identifier (PID_TYPE
)));
5006 record_builtin_type (RID_FLOAT
, NULL
, float_type_node
);
5007 record_builtin_type (RID_DOUBLE
, NULL
, double_type_node
);
5008 record_builtin_type (RID_MAX
, "long double", long_double_type_node
);
5010 /* Only supported decimal floating point extension if the target
5011 actually supports underlying modes. */
5012 if (targetm
.scalar_mode_supported_p (SDmode
)
5013 && targetm
.scalar_mode_supported_p (DDmode
)
5014 && targetm
.scalar_mode_supported_p (TDmode
))
5016 record_builtin_type (RID_DFLOAT32
, NULL
, dfloat32_type_node
);
5017 record_builtin_type (RID_DFLOAT64
, NULL
, dfloat64_type_node
);
5018 record_builtin_type (RID_DFLOAT128
, NULL
, dfloat128_type_node
);
5021 if (targetm
.fixed_point_supported_p ())
5023 record_builtin_type (RID_MAX
, "short _Fract", short_fract_type_node
);
5024 record_builtin_type (RID_FRACT
, NULL
, fract_type_node
);
5025 record_builtin_type (RID_MAX
, "long _Fract", long_fract_type_node
);
5026 record_builtin_type (RID_MAX
, "long long _Fract",
5027 long_long_fract_type_node
);
5028 record_builtin_type (RID_MAX
, "unsigned short _Fract",
5029 unsigned_short_fract_type_node
);
5030 record_builtin_type (RID_MAX
, "unsigned _Fract",
5031 unsigned_fract_type_node
);
5032 record_builtin_type (RID_MAX
, "unsigned long _Fract",
5033 unsigned_long_fract_type_node
);
5034 record_builtin_type (RID_MAX
, "unsigned long long _Fract",
5035 unsigned_long_long_fract_type_node
);
5036 record_builtin_type (RID_MAX
, "_Sat short _Fract",
5037 sat_short_fract_type_node
);
5038 record_builtin_type (RID_MAX
, "_Sat _Fract", sat_fract_type_node
);
5039 record_builtin_type (RID_MAX
, "_Sat long _Fract",
5040 sat_long_fract_type_node
);
5041 record_builtin_type (RID_MAX
, "_Sat long long _Fract",
5042 sat_long_long_fract_type_node
);
5043 record_builtin_type (RID_MAX
, "_Sat unsigned short _Fract",
5044 sat_unsigned_short_fract_type_node
);
5045 record_builtin_type (RID_MAX
, "_Sat unsigned _Fract",
5046 sat_unsigned_fract_type_node
);
5047 record_builtin_type (RID_MAX
, "_Sat unsigned long _Fract",
5048 sat_unsigned_long_fract_type_node
);
5049 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Fract",
5050 sat_unsigned_long_long_fract_type_node
);
5051 record_builtin_type (RID_MAX
, "short _Accum", short_accum_type_node
);
5052 record_builtin_type (RID_ACCUM
, NULL
, accum_type_node
);
5053 record_builtin_type (RID_MAX
, "long _Accum", long_accum_type_node
);
5054 record_builtin_type (RID_MAX
, "long long _Accum",
5055 long_long_accum_type_node
);
5056 record_builtin_type (RID_MAX
, "unsigned short _Accum",
5057 unsigned_short_accum_type_node
);
5058 record_builtin_type (RID_MAX
, "unsigned _Accum",
5059 unsigned_accum_type_node
);
5060 record_builtin_type (RID_MAX
, "unsigned long _Accum",
5061 unsigned_long_accum_type_node
);
5062 record_builtin_type (RID_MAX
, "unsigned long long _Accum",
5063 unsigned_long_long_accum_type_node
);
5064 record_builtin_type (RID_MAX
, "_Sat short _Accum",
5065 sat_short_accum_type_node
);
5066 record_builtin_type (RID_MAX
, "_Sat _Accum", sat_accum_type_node
);
5067 record_builtin_type (RID_MAX
, "_Sat long _Accum",
5068 sat_long_accum_type_node
);
5069 record_builtin_type (RID_MAX
, "_Sat long long _Accum",
5070 sat_long_long_accum_type_node
);
5071 record_builtin_type (RID_MAX
, "_Sat unsigned short _Accum",
5072 sat_unsigned_short_accum_type_node
);
5073 record_builtin_type (RID_MAX
, "_Sat unsigned _Accum",
5074 sat_unsigned_accum_type_node
);
5075 record_builtin_type (RID_MAX
, "_Sat unsigned long _Accum",
5076 sat_unsigned_long_accum_type_node
);
5077 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Accum",
5078 sat_unsigned_long_long_accum_type_node
);
5082 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5084 get_identifier ("complex int"),
5085 complex_integer_type_node
));
5086 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5088 get_identifier ("complex float"),
5089 complex_float_type_node
));
5090 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
5092 get_identifier ("complex double"),
5093 complex_double_type_node
));
5094 lang_hooks
.decls
.pushdecl
5095 (build_decl (UNKNOWN_LOCATION
,
5096 TYPE_DECL
, get_identifier ("complex long double"),
5097 complex_long_double_type_node
));
5099 if (c_dialect_cxx ())
5100 /* For C++, make fileptr_type_node a distinct void * type until
5101 FILE type is defined. */
5102 fileptr_type_node
= build_variant_type_copy (ptr_type_node
);
5104 record_builtin_type (RID_VOID
, NULL
, void_type_node
);
5106 /* Set the TYPE_NAME for any variants that were built before
5107 record_builtin_type gave names to the built-in types. */
5109 tree void_name
= TYPE_NAME (void_type_node
);
5110 TYPE_NAME (void_type_node
) = NULL_TREE
;
5111 TYPE_NAME (build_qualified_type (void_type_node
, TYPE_QUAL_CONST
))
5113 TYPE_NAME (void_type_node
) = void_name
;
5116 /* This node must not be shared. */
5117 void_zero_node
= make_node (INTEGER_CST
);
5118 TREE_TYPE (void_zero_node
) = void_type_node
;
5120 void_list_node
= build_void_list_node ();
5122 /* Make a type to be the domain of a few array types
5123 whose domains don't really matter.
5124 200 is small enough that it always fits in size_t
5125 and large enough that it can hold most function names for the
5126 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
5127 array_domain_type
= build_index_type (size_int (200));
5129 /* Make a type for arrays of characters.
5130 With luck nothing will ever really depend on the length of this
5132 char_array_type_node
5133 = build_array_type (char_type_node
, array_domain_type
);
5135 /* Likewise for arrays of ints. */
5137 = build_array_type (integer_type_node
, array_domain_type
);
5139 string_type_node
= build_pointer_type (char_type_node
);
5140 const_string_type_node
5141 = build_pointer_type (build_qualified_type
5142 (char_type_node
, TYPE_QUAL_CONST
));
5144 /* This is special for C++ so functions can be overloaded. */
5145 wchar_type_node
= get_identifier (MODIFIED_WCHAR_TYPE
);
5146 wchar_type_node
= TREE_TYPE (identifier_global_value (wchar_type_node
));
5147 wchar_type_size
= TYPE_PRECISION (wchar_type_node
);
5148 underlying_wchar_type_node
= wchar_type_node
;
5149 if (c_dialect_cxx ())
5151 if (TYPE_UNSIGNED (wchar_type_node
))
5152 wchar_type_node
= make_unsigned_type (wchar_type_size
);
5154 wchar_type_node
= make_signed_type (wchar_type_size
);
5155 record_builtin_type (RID_WCHAR
, "wchar_t", wchar_type_node
);
5158 /* This is for wide string constants. */
5159 wchar_array_type_node
5160 = build_array_type (wchar_type_node
, array_domain_type
);
5162 /* Define 'char16_t'. */
5163 char16_type_node
= get_identifier (CHAR16_TYPE
);
5164 char16_type_node
= TREE_TYPE (identifier_global_value (char16_type_node
));
5165 char16_type_size
= TYPE_PRECISION (char16_type_node
);
5166 if (c_dialect_cxx ())
5168 char16_type_node
= make_unsigned_type (char16_type_size
);
5170 if (cxx_dialect
>= cxx0x
)
5171 record_builtin_type (RID_CHAR16
, "char16_t", char16_type_node
);
5174 /* This is for UTF-16 string constants. */
5175 char16_array_type_node
5176 = build_array_type (char16_type_node
, array_domain_type
);
5178 /* Define 'char32_t'. */
5179 char32_type_node
= get_identifier (CHAR32_TYPE
);
5180 char32_type_node
= TREE_TYPE (identifier_global_value (char32_type_node
));
5181 char32_type_size
= TYPE_PRECISION (char32_type_node
);
5182 if (c_dialect_cxx ())
5184 char32_type_node
= make_unsigned_type (char32_type_size
);
5186 if (cxx_dialect
>= cxx0x
)
5187 record_builtin_type (RID_CHAR32
, "char32_t", char32_type_node
);
5190 /* This is for UTF-32 string constants. */
5191 char32_array_type_node
5192 = build_array_type (char32_type_node
, array_domain_type
);
5195 TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE
)));
5198 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE
)));
5200 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE
)));
5202 if (SIG_ATOMIC_TYPE
)
5203 sig_atomic_type_node
=
5204 TREE_TYPE (identifier_global_value (c_get_ident (SIG_ATOMIC_TYPE
)));
5207 TREE_TYPE (identifier_global_value (c_get_ident (INT8_TYPE
)));
5210 TREE_TYPE (identifier_global_value (c_get_ident (INT16_TYPE
)));
5213 TREE_TYPE (identifier_global_value (c_get_ident (INT32_TYPE
)));
5216 TREE_TYPE (identifier_global_value (c_get_ident (INT64_TYPE
)));
5219 TREE_TYPE (identifier_global_value (c_get_ident (UINT8_TYPE
)));
5221 c_uint16_type_node
=
5222 TREE_TYPE (identifier_global_value (c_get_ident (UINT16_TYPE
)));
5224 c_uint32_type_node
=
5225 TREE_TYPE (identifier_global_value (c_get_ident (UINT32_TYPE
)));
5227 c_uint64_type_node
=
5228 TREE_TYPE (identifier_global_value (c_get_ident (UINT64_TYPE
)));
5229 if (INT_LEAST8_TYPE
)
5230 int_least8_type_node
=
5231 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST8_TYPE
)));
5232 if (INT_LEAST16_TYPE
)
5233 int_least16_type_node
=
5234 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST16_TYPE
)));
5235 if (INT_LEAST32_TYPE
)
5236 int_least32_type_node
=
5237 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST32_TYPE
)));
5238 if (INT_LEAST64_TYPE
)
5239 int_least64_type_node
=
5240 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST64_TYPE
)));
5241 if (UINT_LEAST8_TYPE
)
5242 uint_least8_type_node
=
5243 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST8_TYPE
)));
5244 if (UINT_LEAST16_TYPE
)
5245 uint_least16_type_node
=
5246 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST16_TYPE
)));
5247 if (UINT_LEAST32_TYPE
)
5248 uint_least32_type_node
=
5249 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST32_TYPE
)));
5250 if (UINT_LEAST64_TYPE
)
5251 uint_least64_type_node
=
5252 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST64_TYPE
)));
5254 int_fast8_type_node
=
5255 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST8_TYPE
)));
5256 if (INT_FAST16_TYPE
)
5257 int_fast16_type_node
=
5258 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST16_TYPE
)));
5259 if (INT_FAST32_TYPE
)
5260 int_fast32_type_node
=
5261 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST32_TYPE
)));
5262 if (INT_FAST64_TYPE
)
5263 int_fast64_type_node
=
5264 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST64_TYPE
)));
5265 if (UINT_FAST8_TYPE
)
5266 uint_fast8_type_node
=
5267 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST8_TYPE
)));
5268 if (UINT_FAST16_TYPE
)
5269 uint_fast16_type_node
=
5270 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST16_TYPE
)));
5271 if (UINT_FAST32_TYPE
)
5272 uint_fast32_type_node
=
5273 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST32_TYPE
)));
5274 if (UINT_FAST64_TYPE
)
5275 uint_fast64_type_node
=
5276 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST64_TYPE
)));
5279 TREE_TYPE (identifier_global_value (c_get_ident (INTPTR_TYPE
)));
5282 TREE_TYPE (identifier_global_value (c_get_ident (UINTPTR_TYPE
)));
5284 default_function_type
5285 = build_varargs_function_type_list (integer_type_node
, NULL_TREE
);
5287 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE
)));
5288 unsigned_ptrdiff_type_node
= c_common_unsigned_type (ptrdiff_type_node
);
5290 lang_hooks
.decls
.pushdecl
5291 (build_decl (UNKNOWN_LOCATION
,
5292 TYPE_DECL
, get_identifier ("__builtin_va_list"),
5293 va_list_type_node
));
5294 if (targetm
.enum_va_list_p
)
5300 for (l
= 0; targetm
.enum_va_list_p (l
, &pname
, &ptype
); ++l
)
5302 lang_hooks
.decls
.pushdecl
5303 (build_decl (UNKNOWN_LOCATION
,
5304 TYPE_DECL
, get_identifier (pname
),
5310 if (TREE_CODE (va_list_type_node
) == ARRAY_TYPE
)
5312 va_list_arg_type_node
= va_list_ref_type_node
=
5313 build_pointer_type (TREE_TYPE (va_list_type_node
));
5317 va_list_arg_type_node
= va_list_type_node
;
5318 va_list_ref_type_node
= build_reference_type (va_list_type_node
);
5321 if (!flag_preprocess_only
)
5322 c_define_builtins (va_list_ref_type_node
, va_list_arg_type_node
);
5324 main_identifier_node
= get_identifier ("main");
5326 /* Create the built-in __null node. It is important that this is
5328 null_node
= make_node (INTEGER_CST
);
5329 TREE_TYPE (null_node
) = c_common_type_for_size (POINTER_SIZE
, 0);
5331 /* Since builtin_types isn't gc'ed, don't export these nodes. */
5332 memset (builtin_types
, 0, sizeof (builtin_types
));
5335 /* The number of named compound-literals generated thus far. */
5336 static GTY(()) int compound_literal_number
;
5338 /* Set DECL_NAME for DECL, a VAR_DECL for a compound-literal. */
5341 set_compound_literal_name (tree decl
)
5344 ASM_FORMAT_PRIVATE_NAME (name
, "__compound_literal",
5345 compound_literal_number
);
5346 compound_literal_number
++;
5347 DECL_NAME (decl
) = get_identifier (name
);
5351 build_va_arg (location_t loc
, tree expr
, tree type
)
5353 expr
= build1 (VA_ARG_EXPR
, type
, expr
);
5354 SET_EXPR_LOCATION (expr
, loc
);
5359 /* Linked list of disabled built-in functions. */
5361 typedef struct disabled_builtin
5364 struct disabled_builtin
*next
;
5366 static disabled_builtin
*disabled_builtins
= NULL
;
5368 static bool builtin_function_disabled_p (const char *);
5370 /* Disable a built-in function specified by -fno-builtin-NAME. If NAME
5371 begins with "__builtin_", give an error. */
5374 disable_builtin_function (const char *name
)
5376 if (strncmp (name
, "__builtin_", strlen ("__builtin_")) == 0)
5377 error ("cannot disable built-in function %qs", name
);
5380 disabled_builtin
*new_disabled_builtin
= XNEW (disabled_builtin
);
5381 new_disabled_builtin
->name
= name
;
5382 new_disabled_builtin
->next
= disabled_builtins
;
5383 disabled_builtins
= new_disabled_builtin
;
5388 /* Return true if the built-in function NAME has been disabled, false
5392 builtin_function_disabled_p (const char *name
)
5394 disabled_builtin
*p
;
5395 for (p
= disabled_builtins
; p
!= NULL
; p
= p
->next
)
5397 if (strcmp (name
, p
->name
) == 0)
5404 /* Worker for DEF_BUILTIN.
5405 Possibly define a builtin function with one or two names.
5406 Does not declare a non-__builtin_ function if flag_no_builtin, or if
5407 nonansi_p and flag_no_nonansi_builtin. */
5410 def_builtin_1 (enum built_in_function fncode
,
5412 enum built_in_class fnclass
,
5413 tree fntype
, tree libtype
,
5414 bool both_p
, bool fallback_p
, bool nonansi_p
,
5415 tree fnattrs
, bool implicit_p
)
5418 const char *libname
;
5420 if (fntype
== error_mark_node
)
5423 gcc_assert ((!both_p
&& !fallback_p
)
5424 || !strncmp (name
, "__builtin_",
5425 strlen ("__builtin_")));
5427 libname
= name
+ strlen ("__builtin_");
5428 decl
= add_builtin_function (name
, fntype
, fncode
, fnclass
,
5429 (fallback_p
? libname
: NULL
),
5432 set_builtin_decl (fncode
, decl
, implicit_p
);
5435 && !flag_no_builtin
&& !builtin_function_disabled_p (libname
)
5436 && !(nonansi_p
&& flag_no_nonansi_builtin
))
5437 add_builtin_function (libname
, libtype
, fncode
, fnclass
,
5441 /* Nonzero if the type T promotes to int. This is (nearly) the
5442 integral promotions defined in ISO C99 6.3.1.1/2. */
5445 c_promoting_integer_type_p (const_tree t
)
5447 switch (TREE_CODE (t
))
5450 return (TYPE_MAIN_VARIANT (t
) == char_type_node
5451 || TYPE_MAIN_VARIANT (t
) == signed_char_type_node
5452 || TYPE_MAIN_VARIANT (t
) == unsigned_char_type_node
5453 || TYPE_MAIN_VARIANT (t
) == short_integer_type_node
5454 || TYPE_MAIN_VARIANT (t
) == short_unsigned_type_node
5455 || TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
));
5458 /* ??? Technically all enumerations not larger than an int
5459 promote to an int. But this is used along code paths
5460 that only want to notice a size change. */
5461 return TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
);
5471 /* Return 1 if PARMS specifies a fixed number of parameters
5472 and none of their types is affected by default promotions. */
5475 self_promoting_args_p (const_tree parms
)
5478 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
5480 tree type
= TREE_VALUE (t
);
5482 if (type
== error_mark_node
)
5485 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
5491 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
5494 if (c_promoting_integer_type_p (type
))
5500 /* Recursively remove any '*' or '&' operator from TYPE. */
5502 strip_pointer_operator (tree t
)
5504 while (POINTER_TYPE_P (t
))
5509 /* Recursively remove pointer or array type from TYPE. */
5511 strip_pointer_or_array_types (tree t
)
5513 while (TREE_CODE (t
) == ARRAY_TYPE
|| POINTER_TYPE_P (t
))
5518 /* Used to compare case labels. K1 and K2 are actually tree nodes
5519 representing case labels, or NULL_TREE for a `default' label.
5520 Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after
5521 K2, and 0 if K1 and K2 are equal. */
5524 case_compare (splay_tree_key k1
, splay_tree_key k2
)
5526 /* Consider a NULL key (such as arises with a `default' label) to be
5527 smaller than anything else. */
5533 return tree_int_cst_compare ((tree
) k1
, (tree
) k2
);
5536 /* Process a case label, located at LOC, for the range LOW_VALUE
5537 ... HIGH_VALUE. If LOW_VALUE and HIGH_VALUE are both NULL_TREE
5538 then this case label is actually a `default' label. If only
5539 HIGH_VALUE is NULL_TREE, then case label was declared using the
5540 usual C/C++ syntax, rather than the GNU case range extension.
5541 CASES is a tree containing all the case ranges processed so far;
5542 COND is the condition for the switch-statement itself. Returns the
5543 CASE_LABEL_EXPR created, or ERROR_MARK_NODE if no CASE_LABEL_EXPR
5547 c_add_case_label (location_t loc
, splay_tree cases
, tree cond
, tree orig_type
,
5548 tree low_value
, tree high_value
)
5553 splay_tree_node node
;
5555 /* Create the LABEL_DECL itself. */
5556 label
= create_artificial_label (loc
);
5558 /* If there was an error processing the switch condition, bail now
5559 before we get more confused. */
5560 if (!cond
|| cond
== error_mark_node
)
5563 if ((low_value
&& TREE_TYPE (low_value
)
5564 && POINTER_TYPE_P (TREE_TYPE (low_value
)))
5565 || (high_value
&& TREE_TYPE (high_value
)
5566 && POINTER_TYPE_P (TREE_TYPE (high_value
))))
5568 error_at (loc
, "pointers are not permitted as case values");
5572 /* Case ranges are a GNU extension. */
5574 pedwarn (loc
, OPT_Wpedantic
,
5575 "range expressions in switch statements are non-standard");
5577 type
= TREE_TYPE (cond
);
5580 low_value
= check_case_value (low_value
);
5581 low_value
= convert_and_check (type
, low_value
);
5582 if (low_value
== error_mark_node
)
5587 high_value
= check_case_value (high_value
);
5588 high_value
= convert_and_check (type
, high_value
);
5589 if (high_value
== error_mark_node
)
5593 if (low_value
&& high_value
)
5595 /* If the LOW_VALUE and HIGH_VALUE are the same, then this isn't
5596 really a case range, even though it was written that way.
5597 Remove the HIGH_VALUE to simplify later processing. */
5598 if (tree_int_cst_equal (low_value
, high_value
))
5599 high_value
= NULL_TREE
;
5600 else if (!tree_int_cst_lt (low_value
, high_value
))
5601 warning_at (loc
, 0, "empty range specified");
5604 /* See if the case is in range of the type of the original testing
5605 expression. If both low_value and high_value are out of range,
5606 don't insert the case label and return NULL_TREE. */
5608 && !check_case_bounds (type
, orig_type
,
5609 &low_value
, high_value
? &high_value
: NULL
))
5612 /* Look up the LOW_VALUE in the table of case labels we already
5614 node
= splay_tree_lookup (cases
, (splay_tree_key
) low_value
);
5615 /* If there was not an exact match, check for overlapping ranges.
5616 There's no need to do this if there's no LOW_VALUE or HIGH_VALUE;
5617 that's a `default' label and the only overlap is an exact match. */
5618 if (!node
&& (low_value
|| high_value
))
5620 splay_tree_node low_bound
;
5621 splay_tree_node high_bound
;
5623 /* Even though there wasn't an exact match, there might be an
5624 overlap between this case range and another case range.
5625 Since we've (inductively) not allowed any overlapping case
5626 ranges, we simply need to find the greatest low case label
5627 that is smaller that LOW_VALUE, and the smallest low case
5628 label that is greater than LOW_VALUE. If there is an overlap
5629 it will occur in one of these two ranges. */
5630 low_bound
= splay_tree_predecessor (cases
,
5631 (splay_tree_key
) low_value
);
5632 high_bound
= splay_tree_successor (cases
,
5633 (splay_tree_key
) low_value
);
5635 /* Check to see if the LOW_BOUND overlaps. It is smaller than
5636 the LOW_VALUE, so there is no need to check unless the
5637 LOW_BOUND is in fact itself a case range. */
5639 && CASE_HIGH ((tree
) low_bound
->value
)
5640 && tree_int_cst_compare (CASE_HIGH ((tree
) low_bound
->value
),
5643 /* Check to see if the HIGH_BOUND overlaps. The low end of that
5644 range is bigger than the low end of the current range, so we
5645 are only interested if the current range is a real range, and
5646 not an ordinary case label. */
5649 && (tree_int_cst_compare ((tree
) high_bound
->key
,
5654 /* If there was an overlap, issue an error. */
5657 tree duplicate
= CASE_LABEL ((tree
) node
->value
);
5661 error_at (loc
, "duplicate (or overlapping) case value");
5662 error_at (DECL_SOURCE_LOCATION (duplicate
),
5663 "this is the first entry overlapping that value");
5667 error_at (loc
, "duplicate case value") ;
5668 error_at (DECL_SOURCE_LOCATION (duplicate
), "previously used here");
5672 error_at (loc
, "multiple default labels in one switch");
5673 error_at (DECL_SOURCE_LOCATION (duplicate
),
5674 "this is the first default label");
5679 /* Add a CASE_LABEL to the statement-tree. */
5680 case_label
= add_stmt (build_case_label (low_value
, high_value
, label
));
5681 /* Register this case label in the splay tree. */
5682 splay_tree_insert (cases
,
5683 (splay_tree_key
) low_value
,
5684 (splay_tree_value
) case_label
);
5689 /* Add a label so that the back-end doesn't think that the beginning of
5690 the switch is unreachable. Note that we do not add a case label, as
5691 that just leads to duplicates and thence to failure later on. */
5694 tree t
= create_artificial_label (loc
);
5695 add_stmt (build_stmt (loc
, LABEL_EXPR
, t
));
5697 return error_mark_node
;
5700 /* Subroutines of c_do_switch_warnings, called via splay_tree_foreach.
5701 Used to verify that case values match up with enumerator values. */
5704 match_case_to_enum_1 (tree key
, tree type
, tree label
)
5706 char buf
[2 + 2*HOST_BITS_PER_WIDE_INT
/4 + 1];
5708 /* ??? Not working too hard to print the double-word value.
5709 Should perhaps be done with %lwd in the diagnostic routines? */
5710 if (TREE_INT_CST_HIGH (key
) == 0)
5711 snprintf (buf
, sizeof (buf
), HOST_WIDE_INT_PRINT_UNSIGNED
,
5712 TREE_INT_CST_LOW (key
));
5713 else if (!TYPE_UNSIGNED (type
)
5714 && TREE_INT_CST_HIGH (key
) == -1
5715 && TREE_INT_CST_LOW (key
) != 0)
5716 snprintf (buf
, sizeof (buf
), "-" HOST_WIDE_INT_PRINT_UNSIGNED
,
5717 -TREE_INT_CST_LOW (key
));
5719 snprintf (buf
, sizeof (buf
), HOST_WIDE_INT_PRINT_DOUBLE_HEX
,
5720 (unsigned HOST_WIDE_INT
) TREE_INT_CST_HIGH (key
),
5721 (unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (key
));
5723 if (TYPE_NAME (type
) == 0)
5724 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
5725 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
5726 "case value %qs not in enumerated type",
5729 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
5730 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
5731 "case value %qs not in enumerated type %qT",
5735 /* Subroutine of c_do_switch_warnings, called via splay_tree_foreach.
5736 Used to verify that case values match up with enumerator values. */
5739 match_case_to_enum (splay_tree_node node
, void *data
)
5741 tree label
= (tree
) node
->value
;
5742 tree type
= (tree
) data
;
5744 /* Skip default case. */
5745 if (!CASE_LOW (label
))
5748 /* If CASE_LOW_SEEN is not set, that means CASE_LOW did not appear
5749 when we did our enum->case scan. Reset our scratch bit after. */
5750 if (!CASE_LOW_SEEN (label
))
5751 match_case_to_enum_1 (CASE_LOW (label
), type
, label
);
5753 CASE_LOW_SEEN (label
) = 0;
5755 /* If CASE_HIGH is non-null, we have a range. If CASE_HIGH_SEEN is
5756 not set, that means that CASE_HIGH did not appear when we did our
5757 enum->case scan. Reset our scratch bit after. */
5758 if (CASE_HIGH (label
))
5760 if (!CASE_HIGH_SEEN (label
))
5761 match_case_to_enum_1 (CASE_HIGH (label
), type
, label
);
5763 CASE_HIGH_SEEN (label
) = 0;
5769 /* Handle -Wswitch*. Called from the front end after parsing the
5770 switch construct. */
5771 /* ??? Should probably be somewhere generic, since other languages
5772 besides C and C++ would want this. At the moment, however, C/C++
5773 are the only tree-ssa languages that support enumerations at all,
5774 so the point is moot. */
5777 c_do_switch_warnings (splay_tree cases
, location_t switch_location
,
5778 tree type
, tree cond
)
5780 splay_tree_node default_node
;
5781 splay_tree_node node
;
5784 if (!warn_switch
&& !warn_switch_enum
&& !warn_switch_default
)
5787 default_node
= splay_tree_lookup (cases
, (splay_tree_key
) NULL
);
5789 warning_at (switch_location
, OPT_Wswitch_default
,
5790 "switch missing default case");
5792 /* From here on, we only care about about enumerated types. */
5793 if (!type
|| TREE_CODE (type
) != ENUMERAL_TYPE
)
5796 /* From here on, we only care about -Wswitch and -Wswitch-enum. */
5797 if (!warn_switch_enum
&& !warn_switch
)
5800 /* Check the cases. Warn about case values which are not members of
5801 the enumerated type. For -Wswitch-enum, or for -Wswitch when
5802 there is no default case, check that exactly all enumeration
5803 literals are covered by the cases. */
5805 /* Clearing COND if it is not an integer constant simplifies
5806 the tests inside the loop below. */
5807 if (TREE_CODE (cond
) != INTEGER_CST
)
5810 /* The time complexity here is O(N*lg(N)) worst case, but for the
5811 common case of monotonically increasing enumerators, it is
5812 O(N), since the nature of the splay tree will keep the next
5813 element adjacent to the root at all times. */
5815 for (chain
= TYPE_VALUES (type
); chain
; chain
= TREE_CHAIN (chain
))
5817 tree value
= TREE_VALUE (chain
);
5818 if (TREE_CODE (value
) == CONST_DECL
)
5819 value
= DECL_INITIAL (value
);
5820 node
= splay_tree_lookup (cases
, (splay_tree_key
) value
);
5823 /* Mark the CASE_LOW part of the case entry as seen. */
5824 tree label
= (tree
) node
->value
;
5825 CASE_LOW_SEEN (label
) = 1;
5829 /* Even though there wasn't an exact match, there might be a
5830 case range which includes the enumerator's value. */
5831 node
= splay_tree_predecessor (cases
, (splay_tree_key
) value
);
5832 if (node
&& CASE_HIGH ((tree
) node
->value
))
5834 tree label
= (tree
) node
->value
;
5835 int cmp
= tree_int_cst_compare (CASE_HIGH (label
), value
);
5838 /* If we match the upper bound exactly, mark the CASE_HIGH
5839 part of the case entry as seen. */
5841 CASE_HIGH_SEEN (label
) = 1;
5846 /* We've now determined that this enumerated literal isn't
5847 handled by the case labels of the switch statement. */
5849 /* If the switch expression is a constant, we only really care
5850 about whether that constant is handled by the switch. */
5851 if (cond
&& tree_int_cst_compare (cond
, value
))
5854 /* If there is a default_node, the only relevant option is
5855 Wswitch-enum. Otherwise, if both are enabled then we prefer
5856 to warn using -Wswitch because -Wswitch is enabled by -Wall
5857 while -Wswitch-enum is explicit. */
5858 warning_at (switch_location
,
5859 (default_node
|| !warn_switch
5862 "enumeration value %qE not handled in switch",
5863 TREE_PURPOSE (chain
));
5866 /* Warn if there are case expressions that don't correspond to
5867 enumerators. This can occur since C and C++ don't enforce
5868 type-checking of assignments to enumeration variables.
5870 The time complexity here is now always O(N) worst case, since
5871 we should have marked both the lower bound and upper bound of
5872 every disjoint case label, with CASE_LOW_SEEN and CASE_HIGH_SEEN
5873 above. This scan also resets those fields. */
5875 splay_tree_foreach (cases
, match_case_to_enum
, type
);
5878 /* Finish an expression taking the address of LABEL (an
5879 IDENTIFIER_NODE). Returns an expression for the address.
5881 LOC is the location for the expression returned. */
5884 finish_label_address_expr (tree label
, location_t loc
)
5888 pedwarn (input_location
, OPT_Wpedantic
, "taking the address of a label is non-standard");
5890 if (label
== error_mark_node
)
5891 return error_mark_node
;
5893 label
= lookup_label (label
);
5894 if (label
== NULL_TREE
)
5895 result
= null_pointer_node
;
5898 TREE_USED (label
) = 1;
5899 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
5900 /* The current function is not necessarily uninlinable.
5901 Computed gotos are incompatible with inlining, but the value
5902 here could be used only in a diagnostic, for example. */
5903 protected_set_expr_location (result
, loc
);
5910 /* Given a boolean expression ARG, return a tree representing an increment
5911 or decrement (as indicated by CODE) of ARG. The front end must check for
5912 invalid cases (e.g., decrement in C++). */
5914 boolean_increment (enum tree_code code
, tree arg
)
5917 tree true_res
= build_int_cst (TREE_TYPE (arg
), 1);
5919 arg
= stabilize_reference (arg
);
5922 case PREINCREMENT_EXPR
:
5923 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
5925 case POSTINCREMENT_EXPR
:
5926 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
5927 arg
= save_expr (arg
);
5928 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
5929 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
5931 case PREDECREMENT_EXPR
:
5932 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
5933 invert_truthvalue_loc (input_location
, arg
));
5935 case POSTDECREMENT_EXPR
:
5936 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
5937 invert_truthvalue_loc (input_location
, arg
));
5938 arg
= save_expr (arg
);
5939 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
5940 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
5945 TREE_SIDE_EFFECTS (val
) = 1;
5949 /* Built-in macros for stddef.h and stdint.h, that require macros
5950 defined in this file. */
5952 c_stddef_cpp_builtins(void)
5954 builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE
, 0);
5955 builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE
, 0);
5956 builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE
, 0);
5957 builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE
, 0);
5958 builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE
, 0);
5959 builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE
, 0);
5960 builtin_define_with_value ("__CHAR16_TYPE__", CHAR16_TYPE
, 0);
5961 builtin_define_with_value ("__CHAR32_TYPE__", CHAR32_TYPE
, 0);
5962 if (SIG_ATOMIC_TYPE
)
5963 builtin_define_with_value ("__SIG_ATOMIC_TYPE__", SIG_ATOMIC_TYPE
, 0);
5965 builtin_define_with_value ("__INT8_TYPE__", INT8_TYPE
, 0);
5967 builtin_define_with_value ("__INT16_TYPE__", INT16_TYPE
, 0);
5969 builtin_define_with_value ("__INT32_TYPE__", INT32_TYPE
, 0);
5971 builtin_define_with_value ("__INT64_TYPE__", INT64_TYPE
, 0);
5973 builtin_define_with_value ("__UINT8_TYPE__", UINT8_TYPE
, 0);
5975 builtin_define_with_value ("__UINT16_TYPE__", UINT16_TYPE
, 0);
5977 builtin_define_with_value ("__UINT32_TYPE__", UINT32_TYPE
, 0);
5979 builtin_define_with_value ("__UINT64_TYPE__", UINT64_TYPE
, 0);
5980 if (INT_LEAST8_TYPE
)
5981 builtin_define_with_value ("__INT_LEAST8_TYPE__", INT_LEAST8_TYPE
, 0);
5982 if (INT_LEAST16_TYPE
)
5983 builtin_define_with_value ("__INT_LEAST16_TYPE__", INT_LEAST16_TYPE
, 0);
5984 if (INT_LEAST32_TYPE
)
5985 builtin_define_with_value ("__INT_LEAST32_TYPE__", INT_LEAST32_TYPE
, 0);
5986 if (INT_LEAST64_TYPE
)
5987 builtin_define_with_value ("__INT_LEAST64_TYPE__", INT_LEAST64_TYPE
, 0);
5988 if (UINT_LEAST8_TYPE
)
5989 builtin_define_with_value ("__UINT_LEAST8_TYPE__", UINT_LEAST8_TYPE
, 0);
5990 if (UINT_LEAST16_TYPE
)
5991 builtin_define_with_value ("__UINT_LEAST16_TYPE__", UINT_LEAST16_TYPE
, 0);
5992 if (UINT_LEAST32_TYPE
)
5993 builtin_define_with_value ("__UINT_LEAST32_TYPE__", UINT_LEAST32_TYPE
, 0);
5994 if (UINT_LEAST64_TYPE
)
5995 builtin_define_with_value ("__UINT_LEAST64_TYPE__", UINT_LEAST64_TYPE
, 0);
5997 builtin_define_with_value ("__INT_FAST8_TYPE__", INT_FAST8_TYPE
, 0);
5998 if (INT_FAST16_TYPE
)
5999 builtin_define_with_value ("__INT_FAST16_TYPE__", INT_FAST16_TYPE
, 0);
6000 if (INT_FAST32_TYPE
)
6001 builtin_define_with_value ("__INT_FAST32_TYPE__", INT_FAST32_TYPE
, 0);
6002 if (INT_FAST64_TYPE
)
6003 builtin_define_with_value ("__INT_FAST64_TYPE__", INT_FAST64_TYPE
, 0);
6004 if (UINT_FAST8_TYPE
)
6005 builtin_define_with_value ("__UINT_FAST8_TYPE__", UINT_FAST8_TYPE
, 0);
6006 if (UINT_FAST16_TYPE
)
6007 builtin_define_with_value ("__UINT_FAST16_TYPE__", UINT_FAST16_TYPE
, 0);
6008 if (UINT_FAST32_TYPE
)
6009 builtin_define_with_value ("__UINT_FAST32_TYPE__", UINT_FAST32_TYPE
, 0);
6010 if (UINT_FAST64_TYPE
)
6011 builtin_define_with_value ("__UINT_FAST64_TYPE__", UINT_FAST64_TYPE
, 0);
6013 builtin_define_with_value ("__INTPTR_TYPE__", INTPTR_TYPE
, 0);
6015 builtin_define_with_value ("__UINTPTR_TYPE__", UINTPTR_TYPE
, 0);
6019 c_init_attributes (void)
6021 /* Fill in the built_in_attributes array. */
6022 #define DEF_ATTR_NULL_TREE(ENUM) \
6023 built_in_attributes[(int) ENUM] = NULL_TREE;
6024 #define DEF_ATTR_INT(ENUM, VALUE) \
6025 built_in_attributes[(int) ENUM] = build_int_cst (integer_type_node, VALUE);
6026 #define DEF_ATTR_STRING(ENUM, VALUE) \
6027 built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
6028 #define DEF_ATTR_IDENT(ENUM, STRING) \
6029 built_in_attributes[(int) ENUM] = get_identifier (STRING);
6030 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
6031 built_in_attributes[(int) ENUM] \
6032 = tree_cons (built_in_attributes[(int) PURPOSE], \
6033 built_in_attributes[(int) VALUE], \
6034 built_in_attributes[(int) CHAIN]);
6035 #include "builtin-attrs.def"
6036 #undef DEF_ATTR_NULL_TREE
6038 #undef DEF_ATTR_IDENT
6039 #undef DEF_ATTR_TREE_LIST
6042 /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain
6043 identifier as an argument, so the front end shouldn't look it up. */
6046 attribute_takes_identifier_p (const_tree attr_id
)
6048 const struct attribute_spec
*spec
= lookup_attribute_spec (attr_id
);
6050 /* Unknown attribute that we'll end up ignoring, return true so we
6051 don't complain about an identifier argument. */
6053 else if (!strcmp ("mode", spec
->name
)
6054 || !strcmp ("format", spec
->name
)
6055 || !strcmp ("cleanup", spec
->name
))
6058 return targetm
.attribute_takes_identifier_p (attr_id
);
6061 /* Attribute handlers common to C front ends. */
6063 /* Handle a "packed" attribute; arguments as in
6064 struct attribute_spec.handler. */
6067 handle_packed_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6068 int flags
, bool *no_add_attrs
)
6072 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6073 *node
= build_variant_type_copy (*node
);
6074 TYPE_PACKED (*node
) = 1;
6076 else if (TREE_CODE (*node
) == FIELD_DECL
)
6078 if (TYPE_ALIGN (TREE_TYPE (*node
)) <= BITS_PER_UNIT
6079 /* Still pack bitfields. */
6080 && ! DECL_INITIAL (*node
))
6081 warning (OPT_Wattributes
,
6082 "%qE attribute ignored for field of type %qT",
6083 name
, TREE_TYPE (*node
));
6085 DECL_PACKED (*node
) = 1;
6087 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
6088 used for DECL_REGISTER. It wouldn't mean anything anyway.
6089 We can't set DECL_PACKED on the type of a TYPE_DECL, because
6090 that changes what the typedef is typing. */
6093 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6094 *no_add_attrs
= true;
6100 /* Handle a "nocommon" attribute; arguments as in
6101 struct attribute_spec.handler. */
6104 handle_nocommon_attribute (tree
*node
, tree name
,
6105 tree
ARG_UNUSED (args
),
6106 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6108 if (TREE_CODE (*node
) == VAR_DECL
)
6109 DECL_COMMON (*node
) = 0;
6112 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6113 *no_add_attrs
= true;
6119 /* Handle a "common" attribute; arguments as in
6120 struct attribute_spec.handler. */
6123 handle_common_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6124 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6126 if (TREE_CODE (*node
) == VAR_DECL
)
6127 DECL_COMMON (*node
) = 1;
6130 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6131 *no_add_attrs
= true;
6137 /* Handle a "noreturn" attribute; arguments as in
6138 struct attribute_spec.handler. */
6141 handle_noreturn_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6142 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6144 tree type
= TREE_TYPE (*node
);
6146 /* See FIXME comment in c_common_attribute_table. */
6147 if (TREE_CODE (*node
) == FUNCTION_DECL
6148 || objc_method_decl (TREE_CODE (*node
)))
6149 TREE_THIS_VOLATILE (*node
) = 1;
6150 else if (TREE_CODE (type
) == POINTER_TYPE
6151 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
6153 = build_pointer_type
6154 (build_type_variant (TREE_TYPE (type
),
6155 TYPE_READONLY (TREE_TYPE (type
)), 1));
6158 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6159 *no_add_attrs
= true;
6165 /* Handle a "hot" and attribute; arguments as in
6166 struct attribute_spec.handler. */
6169 handle_hot_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6170 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6172 if (TREE_CODE (*node
) == FUNCTION_DECL
6173 || TREE_CODE (*node
) == LABEL_DECL
)
6175 if (lookup_attribute ("cold", DECL_ATTRIBUTES (*node
)) != NULL
)
6177 warning (OPT_Wattributes
, "%qE attribute conflicts with attribute %s",
6179 *no_add_attrs
= true;
6181 /* Most of the rest of the hot processing is done later with
6182 lookup_attribute. */
6186 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6187 *no_add_attrs
= true;
6193 /* Handle a "cold" and attribute; arguments as in
6194 struct attribute_spec.handler. */
6197 handle_cold_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6198 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6200 if (TREE_CODE (*node
) == FUNCTION_DECL
6201 || TREE_CODE (*node
) == LABEL_DECL
)
6203 if (lookup_attribute ("hot", DECL_ATTRIBUTES (*node
)) != NULL
)
6205 warning (OPT_Wattributes
, "%qE attribute conflicts with attribute %s",
6207 *no_add_attrs
= true;
6209 /* Most of the rest of the cold processing is done later with
6210 lookup_attribute. */
6214 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6215 *no_add_attrs
= true;
6221 /* Handle a "noinline" attribute; arguments as in
6222 struct attribute_spec.handler. */
6225 handle_noinline_attribute (tree
*node
, tree name
,
6226 tree
ARG_UNUSED (args
),
6227 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6229 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6230 DECL_UNINLINABLE (*node
) = 1;
6233 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6234 *no_add_attrs
= true;
6240 /* Handle a "noclone" attribute; arguments as in
6241 struct attribute_spec.handler. */
6244 handle_noclone_attribute (tree
*node
, tree name
,
6245 tree
ARG_UNUSED (args
),
6246 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6248 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6250 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6251 *no_add_attrs
= true;
6257 /* Handle a "always_inline" attribute; arguments as in
6258 struct attribute_spec.handler. */
6261 handle_always_inline_attribute (tree
*node
, tree name
,
6262 tree
ARG_UNUSED (args
),
6263 int ARG_UNUSED (flags
),
6266 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6268 /* Set the attribute and mark it for disregarding inline
6270 DECL_DISREGARD_INLINE_LIMITS (*node
) = 1;
6274 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6275 *no_add_attrs
= true;
6281 /* Handle a "gnu_inline" attribute; arguments as in
6282 struct attribute_spec.handler. */
6285 handle_gnu_inline_attribute (tree
*node
, tree name
,
6286 tree
ARG_UNUSED (args
),
6287 int ARG_UNUSED (flags
),
6290 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
6292 /* Do nothing else, just set the attribute. We'll get at
6293 it later with lookup_attribute. */
6297 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6298 *no_add_attrs
= true;
6304 /* Handle a "leaf" attribute; arguments as in
6305 struct attribute_spec.handler. */
6308 handle_leaf_attribute (tree
*node
, tree name
,
6309 tree
ARG_UNUSED (args
),
6310 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6312 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6314 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6315 *no_add_attrs
= true;
6317 if (!TREE_PUBLIC (*node
))
6319 warning (OPT_Wattributes
, "%qE attribute has no effect on unit local functions", name
);
6320 *no_add_attrs
= true;
6326 /* Handle an "artificial" attribute; arguments as in
6327 struct attribute_spec.handler. */
6330 handle_artificial_attribute (tree
*node
, tree name
,
6331 tree
ARG_UNUSED (args
),
6332 int ARG_UNUSED (flags
),
6335 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
6337 /* Do nothing else, just set the attribute. We'll get at
6338 it later with lookup_attribute. */
6342 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6343 *no_add_attrs
= true;
6349 /* Handle a "flatten" attribute; arguments as in
6350 struct attribute_spec.handler. */
6353 handle_flatten_attribute (tree
*node
, tree name
,
6354 tree args ATTRIBUTE_UNUSED
,
6355 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
6357 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6358 /* Do nothing else, just set the attribute. We'll get at
6359 it later with lookup_attribute. */
6363 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6364 *no_add_attrs
= true;
6370 /* Handle a "warning" or "error" attribute; arguments as in
6371 struct attribute_spec.handler. */
6374 handle_error_attribute (tree
*node
, tree name
, tree args
,
6375 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6377 if (TREE_CODE (*node
) == FUNCTION_DECL
6378 || TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
6379 /* Do nothing else, just set the attribute. We'll get at
6380 it later with lookup_attribute. */
6384 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6385 *no_add_attrs
= true;
6391 /* Handle a "used" attribute; arguments as in
6392 struct attribute_spec.handler. */
6395 handle_used_attribute (tree
*pnode
, tree name
, tree
ARG_UNUSED (args
),
6396 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6400 if (TREE_CODE (node
) == FUNCTION_DECL
6401 || (TREE_CODE (node
) == VAR_DECL
&& TREE_STATIC (node
))
6402 || (TREE_CODE (node
) == TYPE_DECL
))
6404 TREE_USED (node
) = 1;
6405 DECL_PRESERVE_P (node
) = 1;
6406 if (TREE_CODE (node
) == VAR_DECL
)
6407 DECL_READ_P (node
) = 1;
6411 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6412 *no_add_attrs
= true;
6418 /* Handle a "unused" attribute; arguments as in
6419 struct attribute_spec.handler. */
6422 handle_unused_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6423 int flags
, bool *no_add_attrs
)
6429 if (TREE_CODE (decl
) == PARM_DECL
6430 || TREE_CODE (decl
) == VAR_DECL
6431 || TREE_CODE (decl
) == FUNCTION_DECL
6432 || TREE_CODE (decl
) == LABEL_DECL
6433 || TREE_CODE (decl
) == TYPE_DECL
)
6435 TREE_USED (decl
) = 1;
6436 if (TREE_CODE (decl
) == VAR_DECL
6437 || TREE_CODE (decl
) == PARM_DECL
)
6438 DECL_READ_P (decl
) = 1;
6442 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6443 *no_add_attrs
= true;
6448 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6449 *node
= build_variant_type_copy (*node
);
6450 TREE_USED (*node
) = 1;
6456 /* Handle a "externally_visible" attribute; arguments as in
6457 struct attribute_spec.handler. */
6460 handle_externally_visible_attribute (tree
*pnode
, tree name
,
6461 tree
ARG_UNUSED (args
),
6462 int ARG_UNUSED (flags
),
6467 if (TREE_CODE (node
) == FUNCTION_DECL
|| TREE_CODE (node
) == VAR_DECL
)
6469 if ((!TREE_STATIC (node
) && TREE_CODE (node
) != FUNCTION_DECL
6470 && !DECL_EXTERNAL (node
)) || !TREE_PUBLIC (node
))
6472 warning (OPT_Wattributes
,
6473 "%qE attribute have effect only on public objects", name
);
6474 *no_add_attrs
= true;
6479 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6480 *no_add_attrs
= true;
6486 /* Handle a "const" attribute; arguments as in
6487 struct attribute_spec.handler. */
6490 handle_const_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6491 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6493 tree type
= TREE_TYPE (*node
);
6495 /* See FIXME comment on noreturn in c_common_attribute_table. */
6496 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6497 TREE_READONLY (*node
) = 1;
6498 else if (TREE_CODE (type
) == POINTER_TYPE
6499 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
6501 = build_pointer_type
6502 (build_type_variant (TREE_TYPE (type
), 1,
6503 TREE_THIS_VOLATILE (TREE_TYPE (type
))));
6506 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6507 *no_add_attrs
= true;
6513 /* Handle a "transparent_union" attribute; arguments as in
6514 struct attribute_spec.handler. */
6517 handle_transparent_union_attribute (tree
*node
, tree name
,
6518 tree
ARG_UNUSED (args
), int flags
,
6523 *no_add_attrs
= true;
6525 if (TREE_CODE (*node
) == TYPE_DECL
)
6526 node
= &TREE_TYPE (*node
);
6529 if (TREE_CODE (type
) == UNION_TYPE
)
6531 /* Make sure that the first field will work for a transparent union.
6532 If the type isn't complete yet, leave the check to the code in
6534 if (TYPE_SIZE (type
))
6536 tree first
= first_field (type
);
6537 if (first
== NULL_TREE
6538 || DECL_ARTIFICIAL (first
)
6539 || TYPE_MODE (type
) != DECL_MODE (first
))
6543 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6545 /* If the type isn't complete yet, setting the flag
6546 on a variant wouldn't ever be checked. */
6547 if (!TYPE_SIZE (type
))
6550 /* build_duplicate_type doesn't work for C++. */
6551 if (c_dialect_cxx ())
6554 /* A type variant isn't good enough, since we don't a cast
6555 to such a type removed as a no-op. */
6556 *node
= type
= build_duplicate_type (type
);
6559 TYPE_TRANSPARENT_AGGR (type
) = 1;
6564 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6568 /* Subroutine of handle_{con,de}structor_attribute. Evaluate ARGS to
6569 get the requested priority for a constructor or destructor,
6570 possibly issuing diagnostics for invalid or reserved
6573 static priority_type
6574 get_priority (tree args
, bool is_destructor
)
6580 return DEFAULT_INIT_PRIORITY
;
6582 if (!SUPPORTS_INIT_PRIORITY
)
6585 error ("destructor priorities are not supported");
6587 error ("constructor priorities are not supported");
6588 return DEFAULT_INIT_PRIORITY
;
6591 arg
= TREE_VALUE (args
);
6592 arg
= default_conversion (arg
);
6593 if (!host_integerp (arg
, /*pos=*/0)
6594 || !INTEGRAL_TYPE_P (TREE_TYPE (arg
)))
6597 pri
= tree_low_cst (arg
, /*pos=*/0);
6598 if (pri
< 0 || pri
> MAX_INIT_PRIORITY
)
6601 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
6605 "destructor priorities from 0 to %d are reserved "
6606 "for the implementation",
6607 MAX_RESERVED_INIT_PRIORITY
);
6610 "constructor priorities from 0 to %d are reserved "
6611 "for the implementation",
6612 MAX_RESERVED_INIT_PRIORITY
);
6618 error ("destructor priorities must be integers from 0 to %d inclusive",
6621 error ("constructor priorities must be integers from 0 to %d inclusive",
6623 return DEFAULT_INIT_PRIORITY
;
6626 /* Handle a "constructor" attribute; arguments as in
6627 struct attribute_spec.handler. */
6630 handle_constructor_attribute (tree
*node
, tree name
, tree args
,
6631 int ARG_UNUSED (flags
),
6635 tree type
= TREE_TYPE (decl
);
6637 if (TREE_CODE (decl
) == FUNCTION_DECL
6638 && TREE_CODE (type
) == FUNCTION_TYPE
6639 && decl_function_context (decl
) == 0)
6641 priority_type priority
;
6642 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
6643 priority
= get_priority (args
, /*is_destructor=*/false);
6644 SET_DECL_INIT_PRIORITY (decl
, priority
);
6645 TREE_USED (decl
) = 1;
6649 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6650 *no_add_attrs
= true;
6656 /* Handle a "destructor" attribute; arguments as in
6657 struct attribute_spec.handler. */
6660 handle_destructor_attribute (tree
*node
, tree name
, tree args
,
6661 int ARG_UNUSED (flags
),
6665 tree type
= TREE_TYPE (decl
);
6667 if (TREE_CODE (decl
) == FUNCTION_DECL
6668 && TREE_CODE (type
) == FUNCTION_TYPE
6669 && decl_function_context (decl
) == 0)
6671 priority_type priority
;
6672 DECL_STATIC_DESTRUCTOR (decl
) = 1;
6673 priority
= get_priority (args
, /*is_destructor=*/true);
6674 SET_DECL_FINI_PRIORITY (decl
, priority
);
6675 TREE_USED (decl
) = 1;
6679 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6680 *no_add_attrs
= true;
6686 /* Nonzero if the mode is a valid vector mode for this architecture.
6687 This returns nonzero even if there is no hardware support for the
6688 vector mode, but we can emulate with narrower modes. */
6691 vector_mode_valid_p (enum machine_mode mode
)
6693 enum mode_class mclass
= GET_MODE_CLASS (mode
);
6694 enum machine_mode innermode
;
6696 /* Doh! What's going on? */
6697 if (mclass
!= MODE_VECTOR_INT
6698 && mclass
!= MODE_VECTOR_FLOAT
6699 && mclass
!= MODE_VECTOR_FRACT
6700 && mclass
!= MODE_VECTOR_UFRACT
6701 && mclass
!= MODE_VECTOR_ACCUM
6702 && mclass
!= MODE_VECTOR_UACCUM
)
6705 /* Hardware support. Woo hoo! */
6706 if (targetm
.vector_mode_supported_p (mode
))
6709 innermode
= GET_MODE_INNER (mode
);
6711 /* We should probably return 1 if requesting V4DI and we have no DI,
6712 but we have V2DI, but this is probably very unlikely. */
6714 /* If we have support for the inner mode, we can safely emulate it.
6715 We may not have V2DI, but me can emulate with a pair of DIs. */
6716 return targetm
.scalar_mode_supported_p (innermode
);
6720 /* Handle a "mode" attribute; arguments as in
6721 struct attribute_spec.handler. */
6724 handle_mode_attribute (tree
*node
, tree name
, tree args
,
6725 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6728 tree ident
= TREE_VALUE (args
);
6730 *no_add_attrs
= true;
6732 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
6733 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6737 const char *p
= IDENTIFIER_POINTER (ident
);
6738 int len
= strlen (p
);
6739 enum machine_mode mode
= VOIDmode
;
6743 if (len
> 4 && p
[0] == '_' && p
[1] == '_'
6744 && p
[len
- 1] == '_' && p
[len
- 2] == '_')
6746 char *newp
= (char *) alloca (len
- 1);
6748 strcpy (newp
, &p
[2]);
6749 newp
[len
- 4] = '\0';
6753 /* Change this type to have a type with the specified mode.
6754 First check for the special modes. */
6755 if (!strcmp (p
, "byte"))
6757 else if (!strcmp (p
, "word"))
6759 else if (!strcmp (p
, "pointer"))
6761 else if (!strcmp (p
, "libgcc_cmp_return"))
6762 mode
= targetm
.libgcc_cmp_return_mode ();
6763 else if (!strcmp (p
, "libgcc_shift_count"))
6764 mode
= targetm
.libgcc_shift_count_mode ();
6765 else if (!strcmp (p
, "unwind_word"))
6766 mode
= targetm
.unwind_word_mode ();
6768 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
6769 if (!strcmp (p
, GET_MODE_NAME (j
)))
6771 mode
= (enum machine_mode
) j
;
6775 if (mode
== VOIDmode
)
6777 error ("unknown machine mode %qE", ident
);
6782 switch (GET_MODE_CLASS (mode
))
6785 case MODE_PARTIAL_INT
:
6787 case MODE_DECIMAL_FLOAT
:
6792 valid_mode
= targetm
.scalar_mode_supported_p (mode
);
6795 case MODE_COMPLEX_INT
:
6796 case MODE_COMPLEX_FLOAT
:
6797 valid_mode
= targetm
.scalar_mode_supported_p (GET_MODE_INNER (mode
));
6800 case MODE_VECTOR_INT
:
6801 case MODE_VECTOR_FLOAT
:
6802 case MODE_VECTOR_FRACT
:
6803 case MODE_VECTOR_UFRACT
:
6804 case MODE_VECTOR_ACCUM
:
6805 case MODE_VECTOR_UACCUM
:
6806 warning (OPT_Wattributes
, "specifying vector types with "
6807 "__attribute__ ((mode)) is deprecated");
6808 warning (OPT_Wattributes
,
6809 "use __attribute__ ((vector_size)) instead");
6810 valid_mode
= vector_mode_valid_p (mode
);
6818 error ("unable to emulate %qs", p
);
6822 if (POINTER_TYPE_P (type
))
6824 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
6825 tree (*fn
)(tree
, enum machine_mode
, bool);
6827 if (!targetm
.addr_space
.valid_pointer_mode (mode
, as
))
6829 error ("invalid pointer mode %qs", p
);
6833 if (TREE_CODE (type
) == POINTER_TYPE
)
6834 fn
= build_pointer_type_for_mode
;
6836 fn
= build_reference_type_for_mode
;
6837 typefm
= fn (TREE_TYPE (type
), mode
, false);
6841 /* For fixed-point modes, we need to test if the signness of type
6842 and the machine mode are consistent. */
6843 if (ALL_FIXED_POINT_MODE_P (mode
)
6844 && TYPE_UNSIGNED (type
) != UNSIGNED_FIXED_POINT_MODE_P (mode
))
6846 error ("signedness of type and machine mode %qs don%'t match", p
);
6849 /* For fixed-point modes, we need to pass saturating info. */
6850 typefm
= lang_hooks
.types
.type_for_mode (mode
,
6851 ALL_FIXED_POINT_MODE_P (mode
) ? TYPE_SATURATING (type
)
6852 : TYPE_UNSIGNED (type
));
6855 if (typefm
== NULL_TREE
)
6857 error ("no data type for mode %qs", p
);
6860 else if (TREE_CODE (type
) == ENUMERAL_TYPE
)
6862 /* For enumeral types, copy the precision from the integer
6863 type returned above. If not an INTEGER_TYPE, we can't use
6864 this mode for this type. */
6865 if (TREE_CODE (typefm
) != INTEGER_TYPE
)
6867 error ("cannot use mode %qs for enumeral types", p
);
6871 if (flags
& ATTR_FLAG_TYPE_IN_PLACE
)
6873 TYPE_PRECISION (type
) = TYPE_PRECISION (typefm
);
6878 /* We cannot build a type variant, as there's code that assumes
6879 that TYPE_MAIN_VARIANT has the same mode. This includes the
6880 debug generators. Instead, create a subrange type. This
6881 results in all of the enumeral values being emitted only once
6882 in the original, and the subtype gets them by reference. */
6883 if (TYPE_UNSIGNED (type
))
6884 typefm
= make_unsigned_type (TYPE_PRECISION (typefm
));
6886 typefm
= make_signed_type (TYPE_PRECISION (typefm
));
6887 TREE_TYPE (typefm
) = type
;
6890 else if (VECTOR_MODE_P (mode
)
6891 ? TREE_CODE (type
) != TREE_CODE (TREE_TYPE (typefm
))
6892 : TREE_CODE (type
) != TREE_CODE (typefm
))
6894 error ("mode %qs applied to inappropriate type", p
);
6904 /* Handle a "section" attribute; arguments as in
6905 struct attribute_spec.handler. */
6908 handle_section_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
6909 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6913 if (targetm_common
.have_named_sections
)
6915 user_defined_section_attribute
= true;
6917 if ((TREE_CODE (decl
) == FUNCTION_DECL
6918 || TREE_CODE (decl
) == VAR_DECL
)
6919 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
6921 if (TREE_CODE (decl
) == VAR_DECL
6922 && current_function_decl
!= NULL_TREE
6923 && !TREE_STATIC (decl
))
6925 error_at (DECL_SOURCE_LOCATION (decl
),
6926 "section attribute cannot be specified for "
6928 *no_add_attrs
= true;
6931 /* The decl may have already been given a section attribute
6932 from a previous declaration. Ensure they match. */
6933 else if (DECL_SECTION_NAME (decl
) != NULL_TREE
6934 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl
)),
6935 TREE_STRING_POINTER (TREE_VALUE (args
))) != 0)
6937 error ("section of %q+D conflicts with previous declaration",
6939 *no_add_attrs
= true;
6941 else if (TREE_CODE (decl
) == VAR_DECL
6942 && !targetm
.have_tls
&& targetm
.emutls
.tmpl_section
6943 && DECL_THREAD_LOCAL_P (decl
))
6945 error ("section of %q+D cannot be overridden", *node
);
6946 *no_add_attrs
= true;
6949 DECL_SECTION_NAME (decl
) = TREE_VALUE (args
);
6953 error ("section attribute not allowed for %q+D", *node
);
6954 *no_add_attrs
= true;
6959 error_at (DECL_SOURCE_LOCATION (*node
),
6960 "section attributes are not supported for this target");
6961 *no_add_attrs
= true;
6967 /* Check whether ALIGN is a valid user-specified alignment. If so,
6968 return its base-2 log; if not, output an error and return -1. If
6969 ALLOW_ZERO then 0 is valid and should result in a return of -1 with
6972 check_user_alignment (const_tree align
, bool allow_zero
)
6976 if (!INTEGRAL_TYPE_P (TREE_TYPE (align
))
6977 || TREE_CODE (align
) != INTEGER_CST
)
6979 error ("requested alignment is not an integer constant");
6982 else if (allow_zero
&& integer_zerop (align
))
6984 else if ((i
= tree_log2 (align
)) == -1)
6986 error ("requested alignment is not a power of 2");
6989 else if (i
>= HOST_BITS_PER_INT
- BITS_PER_UNIT_LOG
)
6991 error ("requested alignment is too large");
6997 /* Handle a "aligned" attribute; arguments as in
6998 struct attribute_spec.handler. */
7001 handle_aligned_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7002 int flags
, bool *no_add_attrs
)
7004 tree decl
= NULL_TREE
;
7007 tree align_expr
= (args
? TREE_VALUE (args
)
7008 : size_int (ATTRIBUTE_ALIGNED_VALUE
/ BITS_PER_UNIT
));
7014 type
= &TREE_TYPE (decl
);
7015 is_type
= TREE_CODE (*node
) == TYPE_DECL
;
7017 else if (TYPE_P (*node
))
7018 type
= node
, is_type
= 1;
7020 if ((i
= check_user_alignment (align_expr
, false)) == -1)
7021 *no_add_attrs
= true;
7024 if ((flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7025 /* OK, modify the type in place. */;
7026 /* If we have a TYPE_DECL, then copy the type, so that we
7027 don't accidentally modify a builtin type. See pushdecl. */
7028 else if (decl
&& TREE_TYPE (decl
) != error_mark_node
7029 && DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
)
7031 tree tt
= TREE_TYPE (decl
);
7032 *type
= build_variant_type_copy (*type
);
7033 DECL_ORIGINAL_TYPE (decl
) = tt
;
7034 TYPE_NAME (*type
) = decl
;
7035 TREE_USED (*type
) = TREE_USED (decl
);
7036 TREE_TYPE (decl
) = *type
;
7039 *type
= build_variant_type_copy (*type
);
7041 TYPE_ALIGN (*type
) = (1U << i
) * BITS_PER_UNIT
;
7042 TYPE_USER_ALIGN (*type
) = 1;
7044 else if (! VAR_OR_FUNCTION_DECL_P (decl
)
7045 && TREE_CODE (decl
) != FIELD_DECL
)
7047 error ("alignment may not be specified for %q+D", decl
);
7048 *no_add_attrs
= true;
7050 else if (TREE_CODE (decl
) == FUNCTION_DECL
7051 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
7053 if (DECL_USER_ALIGN (decl
))
7054 error ("alignment for %q+D was previously specified as %d "
7055 "and may not be decreased", decl
,
7056 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
7058 error ("alignment for %q+D must be at least %d", decl
,
7059 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
7060 *no_add_attrs
= true;
7064 DECL_ALIGN (decl
) = (1U << i
) * BITS_PER_UNIT
;
7065 DECL_USER_ALIGN (decl
) = 1;
7071 /* Handle a "weak" attribute; arguments as in
7072 struct attribute_spec.handler. */
7075 handle_weak_attribute (tree
*node
, tree name
,
7076 tree
ARG_UNUSED (args
),
7077 int ARG_UNUSED (flags
),
7078 bool * ARG_UNUSED (no_add_attrs
))
7080 if (TREE_CODE (*node
) == FUNCTION_DECL
7081 && DECL_DECLARED_INLINE_P (*node
))
7083 warning (OPT_Wattributes
, "inline function %q+D declared weak", *node
);
7084 *no_add_attrs
= true;
7086 else if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
7088 error ("indirect function %q+D cannot be declared weak", *node
);
7089 *no_add_attrs
= true;
7092 else if (TREE_CODE (*node
) == FUNCTION_DECL
7093 || TREE_CODE (*node
) == VAR_DECL
)
7094 declare_weak (*node
);
7096 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7101 /* Handle an "alias" or "ifunc" attribute; arguments as in
7102 struct attribute_spec.handler, except that IS_ALIAS tells us
7103 whether this is an alias as opposed to ifunc attribute. */
7106 handle_alias_ifunc_attribute (bool is_alias
, tree
*node
, tree name
, tree args
,
7111 if (TREE_CODE (decl
) != FUNCTION_DECL
7112 && (!is_alias
|| TREE_CODE (decl
) != VAR_DECL
))
7114 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7115 *no_add_attrs
= true;
7117 else if ((TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INITIAL (decl
))
7118 || (TREE_CODE (decl
) != FUNCTION_DECL
7119 && TREE_PUBLIC (decl
) && !DECL_EXTERNAL (decl
))
7120 /* A static variable declaration is always a tentative definition,
7121 but the alias is a non-tentative definition which overrides. */
7122 || (TREE_CODE (decl
) != FUNCTION_DECL
7123 && ! TREE_PUBLIC (decl
) && DECL_INITIAL (decl
)))
7125 error ("%q+D defined both normally and as %qE attribute", decl
, name
);
7126 *no_add_attrs
= true;
7130 && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
7131 || lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
))))
7133 error ("weak %q+D cannot be defined %qE", decl
, name
);
7134 *no_add_attrs
= true;
7138 /* Note that the very first time we process a nested declaration,
7139 decl_function_context will not be set. Indeed, *would* never
7140 be set except for the DECL_INITIAL/DECL_EXTERNAL frobbery that
7141 we do below. After such frobbery, pushdecl would set the context.
7142 In any case, this is never what we want. */
7143 else if (decl_function_context (decl
) == 0 && current_function_decl
== NULL
)
7147 id
= TREE_VALUE (args
);
7148 if (TREE_CODE (id
) != STRING_CST
)
7150 error ("attribute %qE argument not a string", name
);
7151 *no_add_attrs
= true;
7154 id
= get_identifier (TREE_STRING_POINTER (id
));
7155 /* This counts as a use of the object pointed to. */
7158 if (TREE_CODE (decl
) == FUNCTION_DECL
)
7159 DECL_INITIAL (decl
) = error_mark_node
;
7162 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
7163 DECL_EXTERNAL (decl
) = 1;
7165 DECL_EXTERNAL (decl
) = 0;
7166 TREE_STATIC (decl
) = 1;
7170 /* ifuncs are also aliases, so set that attribute too. */
7171 DECL_ATTRIBUTES (decl
)
7172 = tree_cons (get_identifier ("alias"), args
, DECL_ATTRIBUTES (decl
));
7176 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7177 *no_add_attrs
= true;
7183 /* Handle an "alias" or "ifunc" attribute; arguments as in
7184 struct attribute_spec.handler. */
7187 handle_ifunc_attribute (tree
*node
, tree name
, tree args
,
7188 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7190 return handle_alias_ifunc_attribute (false, node
, name
, args
, no_add_attrs
);
7193 /* Handle an "alias" or "ifunc" attribute; arguments as in
7194 struct attribute_spec.handler. */
7197 handle_alias_attribute (tree
*node
, tree name
, tree args
,
7198 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7200 return handle_alias_ifunc_attribute (true, node
, name
, args
, no_add_attrs
);
7203 /* Handle a "weakref" attribute; arguments as in struct
7204 attribute_spec.handler. */
7207 handle_weakref_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7208 int flags
, bool *no_add_attrs
)
7210 tree attr
= NULL_TREE
;
7212 /* We must ignore the attribute when it is associated with
7213 local-scoped decls, since attribute alias is ignored and many
7214 such symbols do not even have a DECL_WEAK field. */
7215 if (decl_function_context (*node
)
7216 || current_function_decl
7217 || (TREE_CODE (*node
) != VAR_DECL
&& TREE_CODE (*node
) != FUNCTION_DECL
))
7219 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7220 *no_add_attrs
= true;
7224 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
7226 error ("indirect function %q+D cannot be declared weakref", *node
);
7227 *no_add_attrs
= true;
7231 /* The idea here is that `weakref("name")' mutates into `weakref,
7232 alias("name")', and weakref without arguments, in turn,
7233 implicitly adds weak. */
7237 attr
= tree_cons (get_identifier ("alias"), args
, attr
);
7238 attr
= tree_cons (get_identifier ("weakref"), NULL_TREE
, attr
);
7240 *no_add_attrs
= true;
7242 decl_attributes (node
, attr
, flags
);
7246 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node
)))
7247 error_at (DECL_SOURCE_LOCATION (*node
),
7248 "weakref attribute must appear before alias attribute");
7250 /* Can't call declare_weak because it wants this to be TREE_PUBLIC,
7251 and that isn't supported; and because it wants to add it to
7252 the list of weak decls, which isn't helpful. */
7253 DECL_WEAK (*node
) = 1;
7259 /* Handle an "visibility" attribute; arguments as in
7260 struct attribute_spec.handler. */
7263 handle_visibility_attribute (tree
*node
, tree name
, tree args
,
7264 int ARG_UNUSED (flags
),
7265 bool *ARG_UNUSED (no_add_attrs
))
7268 tree id
= TREE_VALUE (args
);
7269 enum symbol_visibility vis
;
7273 if (TREE_CODE (*node
) == ENUMERAL_TYPE
)
7275 else if (TREE_CODE (*node
) != RECORD_TYPE
&& TREE_CODE (*node
) != UNION_TYPE
)
7277 warning (OPT_Wattributes
, "%qE attribute ignored on non-class types",
7281 else if (TYPE_FIELDS (*node
))
7283 error ("%qE attribute ignored because %qT is already defined",
7288 else if (decl_function_context (decl
) != 0 || !TREE_PUBLIC (decl
))
7290 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7294 if (TREE_CODE (id
) != STRING_CST
)
7296 error ("visibility argument not a string");
7300 /* If this is a type, set the visibility on the type decl. */
7303 decl
= TYPE_NAME (decl
);
7306 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
7308 warning (OPT_Wattributes
, "%qE attribute ignored on types",
7314 if (strcmp (TREE_STRING_POINTER (id
), "default") == 0)
7315 vis
= VISIBILITY_DEFAULT
;
7316 else if (strcmp (TREE_STRING_POINTER (id
), "internal") == 0)
7317 vis
= VISIBILITY_INTERNAL
;
7318 else if (strcmp (TREE_STRING_POINTER (id
), "hidden") == 0)
7319 vis
= VISIBILITY_HIDDEN
;
7320 else if (strcmp (TREE_STRING_POINTER (id
), "protected") == 0)
7321 vis
= VISIBILITY_PROTECTED
;
7324 error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
7325 vis
= VISIBILITY_DEFAULT
;
7328 if (DECL_VISIBILITY_SPECIFIED (decl
)
7329 && vis
!= DECL_VISIBILITY (decl
))
7331 tree attributes
= (TYPE_P (*node
)
7332 ? TYPE_ATTRIBUTES (*node
)
7333 : DECL_ATTRIBUTES (decl
));
7334 if (lookup_attribute ("visibility", attributes
))
7335 error ("%qD redeclared with different visibility", decl
);
7336 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
7337 && lookup_attribute ("dllimport", attributes
))
7338 error ("%qD was declared %qs which implies default visibility",
7340 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
7341 && lookup_attribute ("dllexport", attributes
))
7342 error ("%qD was declared %qs which implies default visibility",
7346 DECL_VISIBILITY (decl
) = vis
;
7347 DECL_VISIBILITY_SPECIFIED (decl
) = 1;
7349 /* Go ahead and attach the attribute to the node as well. This is needed
7350 so we can determine whether we have VISIBILITY_DEFAULT because the
7351 visibility was not specified, or because it was explicitly overridden
7352 from the containing scope. */
7357 /* Determine the ELF symbol visibility for DECL, which is either a
7358 variable or a function. It is an error to use this function if a
7359 definition of DECL is not available in this translation unit.
7360 Returns true if the final visibility has been determined by this
7361 function; false if the caller is free to make additional
7365 c_determine_visibility (tree decl
)
7367 gcc_assert (TREE_CODE (decl
) == VAR_DECL
7368 || TREE_CODE (decl
) == FUNCTION_DECL
);
7370 /* If the user explicitly specified the visibility with an
7371 attribute, honor that. DECL_VISIBILITY will have been set during
7372 the processing of the attribute. We check for an explicit
7373 attribute, rather than just checking DECL_VISIBILITY_SPECIFIED,
7374 to distinguish the use of an attribute from the use of a "#pragma
7375 GCC visibility push(...)"; in the latter case we still want other
7376 considerations to be able to overrule the #pragma. */
7377 if (lookup_attribute ("visibility", DECL_ATTRIBUTES (decl
))
7378 || (TARGET_DLLIMPORT_DECL_ATTRIBUTES
7379 && (lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl
))
7380 || lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl
)))))
7383 /* Set default visibility to whatever the user supplied with
7384 visibility_specified depending on #pragma GCC visibility. */
7385 if (!DECL_VISIBILITY_SPECIFIED (decl
))
7387 if (visibility_options
.inpragma
7388 || DECL_VISIBILITY (decl
) != default_visibility
)
7390 DECL_VISIBILITY (decl
) = default_visibility
;
7391 DECL_VISIBILITY_SPECIFIED (decl
) = visibility_options
.inpragma
;
7392 /* If visibility changed and DECL already has DECL_RTL, ensure
7393 symbol flags are updated. */
7394 if (((TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
))
7395 || TREE_CODE (decl
) == FUNCTION_DECL
)
7396 && DECL_RTL_SET_P (decl
))
7397 make_decl_rtl (decl
);
7403 /* Handle an "tls_model" attribute; arguments as in
7404 struct attribute_spec.handler. */
7407 handle_tls_model_attribute (tree
*node
, tree name
, tree args
,
7408 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7412 enum tls_model kind
;
7414 *no_add_attrs
= true;
7416 if (TREE_CODE (decl
) != VAR_DECL
|| !DECL_THREAD_LOCAL_P (decl
))
7418 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7422 kind
= DECL_TLS_MODEL (decl
);
7423 id
= TREE_VALUE (args
);
7424 if (TREE_CODE (id
) != STRING_CST
)
7426 error ("tls_model argument not a string");
7430 if (!strcmp (TREE_STRING_POINTER (id
), "local-exec"))
7431 kind
= TLS_MODEL_LOCAL_EXEC
;
7432 else if (!strcmp (TREE_STRING_POINTER (id
), "initial-exec"))
7433 kind
= TLS_MODEL_INITIAL_EXEC
;
7434 else if (!strcmp (TREE_STRING_POINTER (id
), "local-dynamic"))
7435 kind
= optimize
? TLS_MODEL_LOCAL_DYNAMIC
: TLS_MODEL_GLOBAL_DYNAMIC
;
7436 else if (!strcmp (TREE_STRING_POINTER (id
), "global-dynamic"))
7437 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
7439 error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
7441 DECL_TLS_MODEL (decl
) = kind
;
7445 /* Handle a "no_instrument_function" attribute; arguments as in
7446 struct attribute_spec.handler. */
7449 handle_no_instrument_function_attribute (tree
*node
, tree name
,
7450 tree
ARG_UNUSED (args
),
7451 int ARG_UNUSED (flags
),
7456 if (TREE_CODE (decl
) != FUNCTION_DECL
)
7458 error_at (DECL_SOURCE_LOCATION (decl
),
7459 "%qE attribute applies only to functions", name
);
7460 *no_add_attrs
= true;
7462 else if (DECL_INITIAL (decl
))
7464 error_at (DECL_SOURCE_LOCATION (decl
),
7465 "can%'t set %qE attribute after definition", name
);
7466 *no_add_attrs
= true;
7469 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
7474 /* Handle a "malloc" attribute; arguments as in
7475 struct attribute_spec.handler. */
7478 handle_malloc_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7479 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7481 if (TREE_CODE (*node
) == FUNCTION_DECL
7482 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node
))))
7483 DECL_IS_MALLOC (*node
) = 1;
7486 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7487 *no_add_attrs
= true;
7493 /* Handle a "alloc_size" attribute; arguments as in
7494 struct attribute_spec.handler. */
7497 handle_alloc_size_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7498 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7500 unsigned arg_count
= type_num_arguments (*node
);
7501 for (; args
; args
= TREE_CHAIN (args
))
7503 tree position
= TREE_VALUE (args
);
7505 if (TREE_CODE (position
) != INTEGER_CST
7506 || TREE_INT_CST_HIGH (position
)
7507 || TREE_INT_CST_LOW (position
) < 1
7508 || TREE_INT_CST_LOW (position
) > arg_count
)
7510 warning (OPT_Wattributes
,
7511 "alloc_size parameter outside range");
7512 *no_add_attrs
= true;
7519 /* Handle a "fn spec" attribute; arguments as in
7520 struct attribute_spec.handler. */
7523 handle_fnspec_attribute (tree
*node ATTRIBUTE_UNUSED
, tree
ARG_UNUSED (name
),
7524 tree args
, int ARG_UNUSED (flags
),
7525 bool *no_add_attrs ATTRIBUTE_UNUSED
)
7528 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
7529 && !TREE_CHAIN (args
));
7533 /* Handle a "returns_twice" attribute; arguments as in
7534 struct attribute_spec.handler. */
7537 handle_returns_twice_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7538 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7540 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7541 DECL_IS_RETURNS_TWICE (*node
) = 1;
7544 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7545 *no_add_attrs
= true;
7551 /* Handle a "no_limit_stack" attribute; arguments as in
7552 struct attribute_spec.handler. */
7555 handle_no_limit_stack_attribute (tree
*node
, tree name
,
7556 tree
ARG_UNUSED (args
),
7557 int ARG_UNUSED (flags
),
7562 if (TREE_CODE (decl
) != FUNCTION_DECL
)
7564 error_at (DECL_SOURCE_LOCATION (decl
),
7565 "%qE attribute applies only to functions", name
);
7566 *no_add_attrs
= true;
7568 else if (DECL_INITIAL (decl
))
7570 error_at (DECL_SOURCE_LOCATION (decl
),
7571 "can%'t set %qE attribute after definition", name
);
7572 *no_add_attrs
= true;
7575 DECL_NO_LIMIT_STACK (decl
) = 1;
7580 /* Handle a "pure" attribute; arguments as in
7581 struct attribute_spec.handler. */
7584 handle_pure_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7585 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7587 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7588 DECL_PURE_P (*node
) = 1;
7589 /* ??? TODO: Support types. */
7592 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7593 *no_add_attrs
= true;
7599 /* Digest an attribute list destined for a transactional memory statement.
7600 ALLOWED is the set of attributes that are allowed for this statement;
7601 return the attribute we parsed. Multiple attributes are never allowed. */
7604 parse_tm_stmt_attr (tree attrs
, int allowed
)
7609 for ( ; attrs
; attrs
= TREE_CHAIN (attrs
))
7611 tree a
= TREE_PURPOSE (attrs
);
7614 if (is_attribute_p ("outer", a
))
7615 m
= TM_STMT_ATTR_OUTER
;
7617 if ((m
& allowed
) == 0)
7619 warning (OPT_Wattributes
, "%qE attribute directive ignored", a
);
7628 else if (m_seen
== m
)
7629 warning (OPT_Wattributes
, "%qE attribute duplicated", a
);
7631 warning (OPT_Wattributes
, "%qE attribute follows %qE", a
, a_seen
);
7637 /* Transform a TM attribute name into a maskable integer and back.
7638 Note that NULL (i.e. no attribute) is mapped to UNKNOWN, corresponding
7639 to how the lack of an attribute is treated. */
7642 tm_attr_to_mask (tree attr
)
7646 if (is_attribute_p ("transaction_safe", attr
))
7647 return TM_ATTR_SAFE
;
7648 if (is_attribute_p ("transaction_callable", attr
))
7649 return TM_ATTR_CALLABLE
;
7650 if (is_attribute_p ("transaction_pure", attr
))
7651 return TM_ATTR_PURE
;
7652 if (is_attribute_p ("transaction_unsafe", attr
))
7653 return TM_ATTR_IRREVOCABLE
;
7654 if (is_attribute_p ("transaction_may_cancel_outer", attr
))
7655 return TM_ATTR_MAY_CANCEL_OUTER
;
7660 tm_mask_to_attr (int mask
)
7666 str
= "transaction_safe";
7668 case TM_ATTR_CALLABLE
:
7669 str
= "transaction_callable";
7672 str
= "transaction_pure";
7674 case TM_ATTR_IRREVOCABLE
:
7675 str
= "transaction_unsafe";
7677 case TM_ATTR_MAY_CANCEL_OUTER
:
7678 str
= "transaction_may_cancel_outer";
7683 return get_identifier (str
);
7686 /* Return the first TM attribute seen in LIST. */
7689 find_tm_attribute (tree list
)
7691 for (; list
; list
= TREE_CHAIN (list
))
7693 tree name
= TREE_PURPOSE (list
);
7694 if (tm_attr_to_mask (name
) != 0)
7700 /* Handle the TM attributes; arguments as in struct attribute_spec.handler.
7701 Here we accept only function types, and verify that none of the other
7702 function TM attributes are also applied. */
7703 /* ??? We need to accept class types for C++, but not C. This greatly
7704 complicates this function, since we can no longer rely on the extra
7705 processing given by function_type_required. */
7708 handle_tm_attribute (tree
*node
, tree name
, tree args
,
7709 int flags
, bool *no_add_attrs
)
7711 /* Only one path adds the attribute; others don't. */
7712 *no_add_attrs
= true;
7714 switch (TREE_CODE (*node
))
7718 /* Only tm_callable and tm_safe apply to classes. */
7719 if (tm_attr_to_mask (name
) & ~(TM_ATTR_SAFE
| TM_ATTR_CALLABLE
))
7726 tree old_name
= find_tm_attribute (TYPE_ATTRIBUTES (*node
));
7727 if (old_name
== name
)
7729 else if (old_name
!= NULL_TREE
)
7730 error ("type was previously declared %qE", old_name
);
7732 *no_add_attrs
= false;
7738 enum tree_code subcode
= TREE_CODE (TREE_TYPE (*node
));
7739 if (subcode
== FUNCTION_TYPE
|| subcode
== METHOD_TYPE
)
7741 tree fn_tmp
= TREE_TYPE (*node
);
7742 decl_attributes (&fn_tmp
, tree_cons (name
, args
, NULL
), 0);
7743 *node
= build_pointer_type (fn_tmp
);
7750 /* If a function is next, pass it on to be tried next. */
7751 if (flags
& (int) ATTR_FLAG_FUNCTION_NEXT
)
7752 return tree_cons (name
, args
, NULL
);
7755 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7762 /* Handle the TM_WRAP attribute; arguments as in
7763 struct attribute_spec.handler. */
7766 handle_tm_wrap_attribute (tree
*node
, tree name
, tree args
,
7767 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7771 /* We don't need the attribute even on success, since we
7772 record the entry in an external table. */
7773 *no_add_attrs
= true;
7775 if (TREE_CODE (decl
) != FUNCTION_DECL
)
7776 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7779 tree wrap_decl
= TREE_VALUE (args
);
7780 if (TREE_CODE (wrap_decl
) != IDENTIFIER_NODE
7781 && TREE_CODE (wrap_decl
) != VAR_DECL
7782 && TREE_CODE (wrap_decl
) != FUNCTION_DECL
)
7783 error ("%qE argument not an identifier", name
);
7786 if (TREE_CODE (wrap_decl
) == IDENTIFIER_NODE
)
7787 wrap_decl
= lookup_name (wrap_decl
);
7788 if (wrap_decl
&& TREE_CODE (wrap_decl
) == FUNCTION_DECL
)
7790 if (lang_hooks
.types_compatible_p (TREE_TYPE (decl
),
7791 TREE_TYPE (wrap_decl
)))
7792 record_tm_replacement (wrap_decl
, decl
);
7794 error ("%qD is not compatible with %qD", wrap_decl
, decl
);
7797 error ("transaction_wrap argument is not a function");
7804 /* Ignore the given attribute. Used when this attribute may be usefully
7805 overridden by the target, but is not used generically. */
7808 ignore_attribute (tree
* ARG_UNUSED (node
), tree
ARG_UNUSED (name
),
7809 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
7812 *no_add_attrs
= true;
7816 /* Handle a "no vops" attribute; arguments as in
7817 struct attribute_spec.handler. */
7820 handle_novops_attribute (tree
*node
, tree
ARG_UNUSED (name
),
7821 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
7822 bool *ARG_UNUSED (no_add_attrs
))
7824 gcc_assert (TREE_CODE (*node
) == FUNCTION_DECL
);
7825 DECL_IS_NOVOPS (*node
) = 1;
7829 /* Handle a "deprecated" attribute; arguments as in
7830 struct attribute_spec.handler. */
7833 handle_deprecated_attribute (tree
*node
, tree name
,
7834 tree args
, int flags
,
7837 tree type
= NULL_TREE
;
7839 tree what
= NULL_TREE
;
7842 *no_add_attrs
= true;
7843 else if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
7845 error ("deprecated message is not a string");
7846 *no_add_attrs
= true;
7852 type
= TREE_TYPE (decl
);
7854 if (TREE_CODE (decl
) == TYPE_DECL
7855 || TREE_CODE (decl
) == PARM_DECL
7856 || TREE_CODE (decl
) == VAR_DECL
7857 || TREE_CODE (decl
) == FUNCTION_DECL
7858 || TREE_CODE (decl
) == FIELD_DECL
7859 || objc_method_decl (TREE_CODE (decl
)))
7860 TREE_DEPRECATED (decl
) = 1;
7864 else if (TYPE_P (*node
))
7866 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7867 *node
= build_variant_type_copy (*node
);
7868 TREE_DEPRECATED (*node
) = 1;
7876 *no_add_attrs
= true;
7877 if (type
&& TYPE_NAME (type
))
7879 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
7880 what
= TYPE_NAME (*node
);
7881 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
7882 && DECL_NAME (TYPE_NAME (type
)))
7883 what
= DECL_NAME (TYPE_NAME (type
));
7886 warning (OPT_Wattributes
, "%qE attribute ignored for %qE", name
, what
);
7888 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7894 /* Handle a "vector_size" attribute; arguments as in
7895 struct attribute_spec.handler. */
7898 handle_vector_size_attribute (tree
*node
, tree name
, tree args
,
7899 int ARG_UNUSED (flags
),
7902 unsigned HOST_WIDE_INT vecsize
, nunits
;
7903 enum machine_mode orig_mode
;
7904 tree type
= *node
, new_type
, size
;
7906 *no_add_attrs
= true;
7908 size
= TREE_VALUE (args
);
7910 if (!host_integerp (size
, 1))
7912 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7916 /* Get the vector size (in bytes). */
7917 vecsize
= tree_low_cst (size
, 1);
7919 /* We need to provide for vector pointers, vector arrays, and
7920 functions returning vectors. For example:
7922 __attribute__((vector_size(16))) short *foo;
7924 In this case, the mode is SI, but the type being modified is
7925 HI, so we need to look further. */
7927 while (POINTER_TYPE_P (type
)
7928 || TREE_CODE (type
) == FUNCTION_TYPE
7929 || TREE_CODE (type
) == METHOD_TYPE
7930 || TREE_CODE (type
) == ARRAY_TYPE
7931 || TREE_CODE (type
) == OFFSET_TYPE
)
7932 type
= TREE_TYPE (type
);
7934 /* Get the mode of the type being modified. */
7935 orig_mode
= TYPE_MODE (type
);
7937 if ((!INTEGRAL_TYPE_P (type
)
7938 && !SCALAR_FLOAT_TYPE_P (type
)
7939 && !FIXED_POINT_TYPE_P (type
))
7940 || (!SCALAR_FLOAT_MODE_P (orig_mode
)
7941 && GET_MODE_CLASS (orig_mode
) != MODE_INT
7942 && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode
))
7943 || !host_integerp (TYPE_SIZE_UNIT (type
), 1)
7944 || TREE_CODE (type
) == BOOLEAN_TYPE
)
7946 error ("invalid vector type for attribute %qE", name
);
7950 if (vecsize
% tree_low_cst (TYPE_SIZE_UNIT (type
), 1))
7952 error ("vector size not an integral multiple of component size");
7958 error ("zero vector size");
7962 /* Calculate how many units fit in the vector. */
7963 nunits
= vecsize
/ tree_low_cst (TYPE_SIZE_UNIT (type
), 1);
7964 if (nunits
& (nunits
- 1))
7966 error ("number of components of the vector not a power of two");
7970 new_type
= build_vector_type (type
, nunits
);
7972 /* Build back pointers if needed. */
7973 *node
= lang_hooks
.types
.reconstruct_complex_type (*node
, new_type
);
7978 /* Handle the "nonnull" attribute. */
7980 handle_nonnull_attribute (tree
*node
, tree
ARG_UNUSED (name
),
7981 tree args
, int ARG_UNUSED (flags
),
7985 unsigned HOST_WIDE_INT attr_arg_num
;
7987 /* If no arguments are specified, all pointer arguments should be
7988 non-null. Verify a full prototype is given so that the arguments
7989 will have the correct types when we actually check them later. */
7992 if (!prototype_p (type
))
7994 error ("nonnull attribute without arguments on a non-prototype");
7995 *no_add_attrs
= true;
8000 /* Argument list specified. Verify that each argument number references
8001 a pointer argument. */
8002 for (attr_arg_num
= 1; args
; args
= TREE_CHAIN (args
))
8004 unsigned HOST_WIDE_INT arg_num
= 0, ck_num
;
8006 if (!get_nonnull_operand (TREE_VALUE (args
), &arg_num
))
8008 error ("nonnull argument has invalid operand number (argument %lu)",
8009 (unsigned long) attr_arg_num
);
8010 *no_add_attrs
= true;
8014 if (prototype_p (type
))
8016 function_args_iterator iter
;
8019 function_args_iter_init (&iter
, type
);
8020 for (ck_num
= 1; ; ck_num
++, function_args_iter_next (&iter
))
8022 argument
= function_args_iter_cond (&iter
);
8023 if (argument
== NULL_TREE
|| ck_num
== arg_num
)
8028 || TREE_CODE (argument
) == VOID_TYPE
)
8030 error ("nonnull argument with out-of-range operand number (argument %lu, operand %lu)",
8031 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
8032 *no_add_attrs
= true;
8036 if (TREE_CODE (argument
) != POINTER_TYPE
)
8038 error ("nonnull argument references non-pointer operand (argument %lu, operand %lu)",
8039 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
8040 *no_add_attrs
= true;
8049 /* Check the argument list of a function call for null in argument slots
8050 that are marked as requiring a non-null pointer argument. The NARGS
8051 arguments are passed in the array ARGARRAY.
8055 check_function_nonnull (tree attrs
, int nargs
, tree
*argarray
)
8060 attrs
= lookup_attribute ("nonnull", attrs
);
8061 if (attrs
== NULL_TREE
)
8065 /* See if any of the nonnull attributes has no arguments. If so,
8066 then every pointer argument is checked (in which case the check
8067 for pointer type is done in check_nonnull_arg). */
8068 if (TREE_VALUE (a
) != NULL_TREE
)
8070 a
= lookup_attribute ("nonnull", TREE_CHAIN (a
));
8071 while (a
!= NULL_TREE
&& TREE_VALUE (a
) != NULL_TREE
);
8074 for (i
= 0; i
< nargs
; i
++)
8075 check_function_arguments_recurse (check_nonnull_arg
, NULL
, argarray
[i
],
8079 /* Walk the argument list. If we encounter an argument number we
8080 should check for non-null, do it. */
8081 for (i
= 0; i
< nargs
; i
++)
8083 for (a
= attrs
; ; a
= TREE_CHAIN (a
))
8085 a
= lookup_attribute ("nonnull", a
);
8086 if (a
== NULL_TREE
|| nonnull_check_p (TREE_VALUE (a
), i
+ 1))
8091 check_function_arguments_recurse (check_nonnull_arg
, NULL
,
8092 argarray
[i
], i
+ 1);
8097 /* Check that the Nth argument of a function call (counting backwards
8098 from the end) is a (pointer)0. The NARGS arguments are passed in the
8102 check_function_sentinel (const_tree fntype
, int nargs
, tree
*argarray
)
8104 tree attr
= lookup_attribute ("sentinel", TYPE_ATTRIBUTES (fntype
));
8111 function_args_iterator iter
;
8114 /* Skip over the named arguments. */
8115 FOREACH_FUNCTION_ARGS (fntype
, t
, iter
)
8122 if (TREE_VALUE (attr
))
8124 tree p
= TREE_VALUE (TREE_VALUE (attr
));
8125 pos
= TREE_INT_CST_LOW (p
);
8128 /* The sentinel must be one of the varargs, i.e.
8129 in position >= the number of fixed arguments. */
8130 if ((nargs
- 1 - pos
) < len
)
8132 warning (OPT_Wformat
,
8133 "not enough variable arguments to fit a sentinel");
8137 /* Validate the sentinel. */
8138 sentinel
= argarray
[nargs
- 1 - pos
];
8139 if ((!POINTER_TYPE_P (TREE_TYPE (sentinel
))
8140 || !integer_zerop (sentinel
))
8141 /* Although __null (in C++) is only an integer we allow it
8142 nevertheless, as we are guaranteed that it's exactly
8143 as wide as a pointer, and we don't want to force
8144 users to cast the NULL they have written there.
8145 We warn with -Wstrict-null-sentinel, though. */
8146 && (warn_strict_null_sentinel
|| null_node
!= sentinel
))
8147 warning (OPT_Wformat
, "missing sentinel in function call");
8151 /* Helper for check_function_nonnull; given a list of operands which
8152 must be non-null in ARGS, determine if operand PARAM_NUM should be
8156 nonnull_check_p (tree args
, unsigned HOST_WIDE_INT param_num
)
8158 unsigned HOST_WIDE_INT arg_num
= 0;
8160 for (; args
; args
= TREE_CHAIN (args
))
8162 bool found
= get_nonnull_operand (TREE_VALUE (args
), &arg_num
);
8166 if (arg_num
== param_num
)
8172 /* Check that the function argument PARAM (which is operand number
8173 PARAM_NUM) is non-null. This is called by check_function_nonnull
8174 via check_function_arguments_recurse. */
8177 check_nonnull_arg (void * ARG_UNUSED (ctx
), tree param
,
8178 unsigned HOST_WIDE_INT param_num
)
8180 /* Just skip checking the argument if it's not a pointer. This can
8181 happen if the "nonnull" attribute was given without an operand
8182 list (which means to check every pointer argument). */
8184 if (TREE_CODE (TREE_TYPE (param
)) != POINTER_TYPE
)
8187 if (integer_zerop (param
))
8188 warning (OPT_Wnonnull
, "null argument where non-null required "
8189 "(argument %lu)", (unsigned long) param_num
);
8192 /* Helper for nonnull attribute handling; fetch the operand number
8193 from the attribute argument list. */
8196 get_nonnull_operand (tree arg_num_expr
, unsigned HOST_WIDE_INT
*valp
)
8198 /* Verify the arg number is a constant. */
8199 if (TREE_CODE (arg_num_expr
) != INTEGER_CST
8200 || TREE_INT_CST_HIGH (arg_num_expr
) != 0)
8203 *valp
= TREE_INT_CST_LOW (arg_num_expr
);
8207 /* Handle a "nothrow" attribute; arguments as in
8208 struct attribute_spec.handler. */
8211 handle_nothrow_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
8212 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8214 if (TREE_CODE (*node
) == FUNCTION_DECL
)
8215 TREE_NOTHROW (*node
) = 1;
8216 /* ??? TODO: Support types. */
8219 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8220 *no_add_attrs
= true;
8226 /* Handle a "cleanup" attribute; arguments as in
8227 struct attribute_spec.handler. */
8230 handle_cleanup_attribute (tree
*node
, tree name
, tree args
,
8231 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8234 tree cleanup_id
, cleanup_decl
;
8236 /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
8237 for global destructors in C++. This requires infrastructure that
8238 we don't have generically at the moment. It's also not a feature
8239 we'd be missing too much, since we do have attribute constructor. */
8240 if (TREE_CODE (decl
) != VAR_DECL
|| TREE_STATIC (decl
))
8242 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8243 *no_add_attrs
= true;
8247 /* Verify that the argument is a function in scope. */
8248 /* ??? We could support pointers to functions here as well, if
8249 that was considered desirable. */
8250 cleanup_id
= TREE_VALUE (args
);
8251 if (TREE_CODE (cleanup_id
) != IDENTIFIER_NODE
)
8253 error ("cleanup argument not an identifier");
8254 *no_add_attrs
= true;
8257 cleanup_decl
= lookup_name (cleanup_id
);
8258 if (!cleanup_decl
|| TREE_CODE (cleanup_decl
) != FUNCTION_DECL
)
8260 error ("cleanup argument not a function");
8261 *no_add_attrs
= true;
8265 /* That the function has proper type is checked with the
8266 eventual call to build_function_call. */
8271 /* Handle a "warn_unused_result" attribute. No special handling. */
8274 handle_warn_unused_result_attribute (tree
*node
, tree name
,
8275 tree
ARG_UNUSED (args
),
8276 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8278 /* Ignore the attribute for functions not returning any value. */
8279 if (VOID_TYPE_P (TREE_TYPE (*node
)))
8281 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8282 *no_add_attrs
= true;
8288 /* Handle a "sentinel" attribute. */
8291 handle_sentinel_attribute (tree
*node
, tree name
, tree args
,
8292 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8294 if (!prototype_p (*node
))
8296 warning (OPT_Wattributes
,
8297 "%qE attribute requires prototypes with named arguments", name
);
8298 *no_add_attrs
= true;
8302 if (!stdarg_p (*node
))
8304 warning (OPT_Wattributes
,
8305 "%qE attribute only applies to variadic functions", name
);
8306 *no_add_attrs
= true;
8312 tree position
= TREE_VALUE (args
);
8314 if (TREE_CODE (position
) != INTEGER_CST
)
8316 warning (OPT_Wattributes
,
8317 "requested position is not an integer constant");
8318 *no_add_attrs
= true;
8322 if (tree_int_cst_lt (position
, integer_zero_node
))
8324 warning (OPT_Wattributes
,
8325 "requested position is less than zero");
8326 *no_add_attrs
= true;
8334 /* Handle a "type_generic" attribute. */
8337 handle_type_generic_attribute (tree
*node
, tree
ARG_UNUSED (name
),
8338 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
8339 bool * ARG_UNUSED (no_add_attrs
))
8341 /* Ensure we have a function type. */
8342 gcc_assert (TREE_CODE (*node
) == FUNCTION_TYPE
);
8344 /* Ensure we have a variadic function. */
8345 gcc_assert (!prototype_p (*node
) || stdarg_p (*node
));
8350 /* Handle a "target" attribute. */
8353 handle_target_attribute (tree
*node
, tree name
, tree args
, int flags
,
8356 /* Ensure we have a function type. */
8357 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8359 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8360 *no_add_attrs
= true;
8362 else if (! targetm
.target_option
.valid_attribute_p (*node
, name
, args
,
8364 *no_add_attrs
= true;
8369 /* Arguments being collected for optimization. */
8370 typedef const char *const_char_p
; /* For DEF_VEC_P. */
8371 DEF_VEC_P(const_char_p
);
8372 DEF_VEC_ALLOC_P(const_char_p
, gc
);
8373 static GTY(()) VEC(const_char_p
, gc
) *optimize_args
;
8376 /* Inner function to convert a TREE_LIST to argv string to parse the optimize
8377 options in ARGS. ATTR_P is true if this is for attribute(optimize), and
8378 false for #pragma GCC optimize. */
8381 parse_optimize_options (tree args
, bool attr_p
)
8386 int saved_flag_strict_aliasing
;
8387 const char **opt_argv
;
8388 struct cl_decoded_option
*decoded_options
;
8389 unsigned int decoded_options_count
;
8392 /* Build up argv vector. Just in case the string is stored away, use garbage
8393 collected strings. */
8394 VEC_truncate (const_char_p
, optimize_args
, 0);
8395 VEC_safe_push (const_char_p
, gc
, optimize_args
, (const_char_p
)NULL
);
8397 for (ap
= args
; ap
!= NULL_TREE
; ap
= TREE_CHAIN (ap
))
8399 tree value
= TREE_VALUE (ap
);
8401 if (TREE_CODE (value
) == INTEGER_CST
)
8404 sprintf (buffer
, "-O%ld", (long) TREE_INT_CST_LOW (value
));
8405 VEC_safe_push (const_char_p
, gc
, optimize_args
, ggc_strdup (buffer
));
8408 else if (TREE_CODE (value
) == STRING_CST
)
8410 /* Split string into multiple substrings. */
8411 size_t len
= TREE_STRING_LENGTH (value
);
8412 char *p
= ASTRDUP (TREE_STRING_POINTER (value
));
8413 char *end
= p
+ len
;
8417 while (next_p
!= NULL
)
8423 comma
= strchr (p
, ',');
8436 r
= q
= (char *) ggc_alloc_atomic (len2
+ 3);
8438 /* If the user supplied -Oxxx or -fxxx, only allow -Oxxx or -fxxx
8440 if (*p
== '-' && p
[1] != 'O' && p
[1] != 'f')
8444 warning (OPT_Wattributes
,
8445 "bad option %s to optimize attribute", p
);
8447 warning (OPT_Wpragmas
,
8448 "bad option %s to pragma attribute", p
);
8456 /* Assume that Ox is -Ox, a numeric value is -Ox, a s by
8457 itself is -Os, and any other switch begins with a -f. */
8458 if ((*p
>= '0' && *p
<= '9')
8459 || (p
[0] == 's' && p
[1] == '\0'))
8465 memcpy (r
, p
, len2
);
8467 VEC_safe_push (const_char_p
, gc
, optimize_args
, q
);
8473 opt_argc
= VEC_length (const_char_p
, optimize_args
);
8474 opt_argv
= (const char **) alloca (sizeof (char *) * (opt_argc
+ 1));
8476 for (i
= 1; i
< opt_argc
; i
++)
8477 opt_argv
[i
] = VEC_index (const_char_p
, optimize_args
, i
);
8479 saved_flag_strict_aliasing
= flag_strict_aliasing
;
8481 /* Now parse the options. */
8482 decode_cmdline_options_to_array_default_mask (opt_argc
, opt_argv
,
8484 &decoded_options_count
);
8485 decode_options (&global_options
, &global_options_set
,
8486 decoded_options
, decoded_options_count
,
8487 input_location
, global_dc
);
8489 targetm
.override_options_after_change();
8491 /* Don't allow changing -fstrict-aliasing. */
8492 flag_strict_aliasing
= saved_flag_strict_aliasing
;
8494 VEC_truncate (const_char_p
, optimize_args
, 0);
8498 /* For handling "optimize" attribute. arguments as in
8499 struct attribute_spec.handler. */
8502 handle_optimize_attribute (tree
*node
, tree name
, tree args
,
8503 int ARG_UNUSED (flags
), bool *no_add_attrs
)
8505 /* Ensure we have a function type. */
8506 if (TREE_CODE (*node
) != FUNCTION_DECL
)
8508 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
8509 *no_add_attrs
= true;
8513 struct cl_optimization cur_opts
;
8514 tree old_opts
= DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
);
8516 /* Save current options. */
8517 cl_optimization_save (&cur_opts
, &global_options
);
8519 /* If we previously had some optimization options, use them as the
8522 cl_optimization_restore (&global_options
,
8523 TREE_OPTIMIZATION (old_opts
));
8525 /* Parse options, and update the vector. */
8526 parse_optimize_options (args
, true);
8527 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
)
8528 = build_optimization_node ();
8530 /* Restore current options. */
8531 cl_optimization_restore (&global_options
, &cur_opts
);
8537 /* Handle a "no_split_stack" attribute. */
8540 handle_no_split_stack_attribute (tree
*node
, tree name
,
8541 tree
ARG_UNUSED (args
),
8542 int ARG_UNUSED (flags
),
8547 if (TREE_CODE (decl
) != FUNCTION_DECL
)
8549 error_at (DECL_SOURCE_LOCATION (decl
),
8550 "%qE attribute applies only to functions", name
);
8551 *no_add_attrs
= true;
8553 else if (DECL_INITIAL (decl
))
8555 error_at (DECL_SOURCE_LOCATION (decl
),
8556 "can%'t set %qE attribute after definition", name
);
8557 *no_add_attrs
= true;
8563 /* Check for valid arguments being passed to a function with FNTYPE.
8564 There are NARGS arguments in the array ARGARRAY. */
8566 check_function_arguments (const_tree fntype
, int nargs
, tree
*argarray
)
8568 /* Check for null being passed in a pointer argument that must be
8569 non-null. We also need to do this if format checking is enabled. */
8572 check_function_nonnull (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
8574 /* Check for errors in format strings. */
8576 if (warn_format
|| warn_suggest_attribute_format
)
8577 check_function_format (TYPE_ATTRIBUTES (fntype
), nargs
, argarray
);
8580 check_function_sentinel (fntype
, nargs
, argarray
);
8583 /* Generic argument checking recursion routine. PARAM is the argument to
8584 be checked. PARAM_NUM is the number of the argument. CALLBACK is invoked
8585 once the argument is resolved. CTX is context for the callback. */
8587 check_function_arguments_recurse (void (*callback
)
8588 (void *, tree
, unsigned HOST_WIDE_INT
),
8589 void *ctx
, tree param
,
8590 unsigned HOST_WIDE_INT param_num
)
8592 if (CONVERT_EXPR_P (param
)
8593 && (TYPE_PRECISION (TREE_TYPE (param
))
8594 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (param
, 0)))))
8596 /* Strip coercion. */
8597 check_function_arguments_recurse (callback
, ctx
,
8598 TREE_OPERAND (param
, 0), param_num
);
8602 if (TREE_CODE (param
) == CALL_EXPR
)
8604 tree type
= TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (param
)));
8606 bool found_format_arg
= false;
8608 /* See if this is a call to a known internationalization function
8609 that modifies a format arg. Such a function may have multiple
8610 format_arg attributes (for example, ngettext). */
8612 for (attrs
= TYPE_ATTRIBUTES (type
);
8614 attrs
= TREE_CHAIN (attrs
))
8615 if (is_attribute_p ("format_arg", TREE_PURPOSE (attrs
)))
8618 tree format_num_expr
;
8621 call_expr_arg_iterator iter
;
8623 /* Extract the argument number, which was previously checked
8625 format_num_expr
= TREE_VALUE (TREE_VALUE (attrs
));
8627 gcc_assert (TREE_CODE (format_num_expr
) == INTEGER_CST
8628 && !TREE_INT_CST_HIGH (format_num_expr
));
8630 format_num
= TREE_INT_CST_LOW (format_num_expr
);
8632 for (inner_arg
= first_call_expr_arg (param
, &iter
), i
= 1;
8634 inner_arg
= next_call_expr_arg (&iter
), i
++)
8635 if (i
== format_num
)
8637 check_function_arguments_recurse (callback
, ctx
,
8638 inner_arg
, param_num
);
8639 found_format_arg
= true;
8644 /* If we found a format_arg attribute and did a recursive check,
8645 we are done with checking this argument. Otherwise, we continue
8646 and this will be considered a non-literal. */
8647 if (found_format_arg
)
8651 if (TREE_CODE (param
) == COND_EXPR
)
8653 /* Check both halves of the conditional expression. */
8654 check_function_arguments_recurse (callback
, ctx
,
8655 TREE_OPERAND (param
, 1), param_num
);
8656 check_function_arguments_recurse (callback
, ctx
,
8657 TREE_OPERAND (param
, 2), param_num
);
8661 (*callback
) (ctx
, param
, param_num
);
8664 /* Checks for a builtin function FNDECL that the number of arguments
8665 NARGS against the required number REQUIRED and issues an error if
8666 there is a mismatch. Returns true if the number of arguments is
8667 correct, otherwise false. */
8670 builtin_function_validate_nargs (tree fndecl
, int nargs
, int required
)
8672 if (nargs
< required
)
8674 error_at (input_location
,
8675 "not enough arguments to function %qE", fndecl
);
8678 else if (nargs
> required
)
8680 error_at (input_location
,
8681 "too many arguments to function %qE", fndecl
);
8687 /* Verifies the NARGS arguments ARGS to the builtin function FNDECL.
8688 Returns false if there was an error, otherwise true. */
8691 check_builtin_function_arguments (tree fndecl
, int nargs
, tree
*args
)
8693 if (!DECL_BUILT_IN (fndecl
)
8694 || DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_NORMAL
)
8697 switch (DECL_FUNCTION_CODE (fndecl
))
8699 case BUILT_IN_CONSTANT_P
:
8700 return builtin_function_validate_nargs (fndecl
, nargs
, 1);
8702 case BUILT_IN_ISFINITE
:
8703 case BUILT_IN_ISINF
:
8704 case BUILT_IN_ISINF_SIGN
:
8705 case BUILT_IN_ISNAN
:
8706 case BUILT_IN_ISNORMAL
:
8707 if (builtin_function_validate_nargs (fndecl
, nargs
, 1))
8709 if (TREE_CODE (TREE_TYPE (args
[0])) != REAL_TYPE
)
8711 error ("non-floating-point argument in call to "
8712 "function %qE", fndecl
);
8719 case BUILT_IN_ISGREATER
:
8720 case BUILT_IN_ISGREATEREQUAL
:
8721 case BUILT_IN_ISLESS
:
8722 case BUILT_IN_ISLESSEQUAL
:
8723 case BUILT_IN_ISLESSGREATER
:
8724 case BUILT_IN_ISUNORDERED
:
8725 if (builtin_function_validate_nargs (fndecl
, nargs
, 2))
8727 enum tree_code code0
, code1
;
8728 code0
= TREE_CODE (TREE_TYPE (args
[0]));
8729 code1
= TREE_CODE (TREE_TYPE (args
[1]));
8730 if (!((code0
== REAL_TYPE
&& code1
== REAL_TYPE
)
8731 || (code0
== REAL_TYPE
&& code1
== INTEGER_TYPE
)
8732 || (code0
== INTEGER_TYPE
&& code1
== REAL_TYPE
)))
8734 error ("non-floating-point arguments in call to "
8735 "function %qE", fndecl
);
8742 case BUILT_IN_FPCLASSIFY
:
8743 if (builtin_function_validate_nargs (fndecl
, nargs
, 6))
8748 if (TREE_CODE (args
[i
]) != INTEGER_CST
)
8750 error ("non-const integer argument %u in call to function %qE",
8755 if (TREE_CODE (TREE_TYPE (args
[5])) != REAL_TYPE
)
8757 error ("non-floating-point argument in call to function %qE",
8765 case BUILT_IN_ASSUME_ALIGNED
:
8766 if (builtin_function_validate_nargs (fndecl
, nargs
, 2 + (nargs
> 2)))
8768 if (nargs
>= 3 && TREE_CODE (TREE_TYPE (args
[2])) != INTEGER_TYPE
)
8770 error ("non-integer argument 3 in call to function %qE", fndecl
);
8782 /* Function to help qsort sort FIELD_DECLs by name order. */
8785 field_decl_cmp (const void *x_p
, const void *y_p
)
8787 const tree
*const x
= (const tree
*const) x_p
;
8788 const tree
*const y
= (const tree
*const) y_p
;
8790 if (DECL_NAME (*x
) == DECL_NAME (*y
))
8791 /* A nontype is "greater" than a type. */
8792 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
8793 if (DECL_NAME (*x
) == NULL_TREE
)
8795 if (DECL_NAME (*y
) == NULL_TREE
)
8797 if (DECL_NAME (*x
) < DECL_NAME (*y
))
8803 gt_pointer_operator new_value
;
8807 /* This routine compares two fields like field_decl_cmp but using the
8808 pointer operator in resort_data. */
8811 resort_field_decl_cmp (const void *x_p
, const void *y_p
)
8813 const tree
*const x
= (const tree
*const) x_p
;
8814 const tree
*const y
= (const tree
*const) y_p
;
8816 if (DECL_NAME (*x
) == DECL_NAME (*y
))
8817 /* A nontype is "greater" than a type. */
8818 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
8819 if (DECL_NAME (*x
) == NULL_TREE
)
8821 if (DECL_NAME (*y
) == NULL_TREE
)
8824 tree d1
= DECL_NAME (*x
);
8825 tree d2
= DECL_NAME (*y
);
8826 resort_data
.new_value (&d1
, resort_data
.cookie
);
8827 resort_data
.new_value (&d2
, resort_data
.cookie
);
8834 /* Resort DECL_SORTED_FIELDS because pointers have been reordered. */
8837 resort_sorted_fields (void *obj
,
8838 void * ARG_UNUSED (orig_obj
),
8839 gt_pointer_operator new_value
,
8842 struct sorted_fields_type
*sf
= (struct sorted_fields_type
*) obj
;
8843 resort_data
.new_value
= new_value
;
8844 resort_data
.cookie
= cookie
;
8845 qsort (&sf
->elts
[0], sf
->len
, sizeof (tree
),
8846 resort_field_decl_cmp
);
8849 /* Subroutine of c_parse_error.
8850 Return the result of concatenating LHS and RHS. RHS is really
8851 a string literal, its first character is indicated by RHS_START and
8852 RHS_SIZE is its length (including the terminating NUL character).
8854 The caller is responsible for deleting the returned pointer. */
8857 catenate_strings (const char *lhs
, const char *rhs_start
, int rhs_size
)
8859 const int lhs_size
= strlen (lhs
);
8860 char *result
= XNEWVEC (char, lhs_size
+ rhs_size
);
8861 strncpy (result
, lhs
, lhs_size
);
8862 strncpy (result
+ lhs_size
, rhs_start
, rhs_size
);
8866 /* Issue the error given by GMSGID, indicating that it occurred before
8867 TOKEN, which had the associated VALUE. */
8870 c_parse_error (const char *gmsgid
, enum cpp_ttype token_type
,
8871 tree value
, unsigned char token_flags
)
8873 #define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2))
8875 char *message
= NULL
;
8877 if (token_type
== CPP_EOF
)
8878 message
= catenate_messages (gmsgid
, " at end of input");
8879 else if (token_type
== CPP_CHAR
8880 || token_type
== CPP_WCHAR
8881 || token_type
== CPP_CHAR16
8882 || token_type
== CPP_CHAR32
)
8884 unsigned int val
= TREE_INT_CST_LOW (value
);
8903 if (val
<= UCHAR_MAX
&& ISGRAPH (val
))
8904 message
= catenate_messages (gmsgid
, " before %s'%c'");
8906 message
= catenate_messages (gmsgid
, " before %s'\\x%x'");
8908 error (message
, prefix
, val
);
8912 else if (token_type
== CPP_STRING
8913 || token_type
== CPP_WSTRING
8914 || token_type
== CPP_STRING16
8915 || token_type
== CPP_STRING32
8916 || token_type
== CPP_UTF8STRING
)
8917 message
= catenate_messages (gmsgid
, " before string constant");
8918 else if (token_type
== CPP_NUMBER
)
8919 message
= catenate_messages (gmsgid
, " before numeric constant");
8920 else if (token_type
== CPP_NAME
)
8922 message
= catenate_messages (gmsgid
, " before %qE");
8923 error (message
, value
);
8927 else if (token_type
== CPP_PRAGMA
)
8928 message
= catenate_messages (gmsgid
, " before %<#pragma%>");
8929 else if (token_type
== CPP_PRAGMA_EOL
)
8930 message
= catenate_messages (gmsgid
, " before end of line");
8931 else if (token_type
== CPP_DECLTYPE
)
8932 message
= catenate_messages (gmsgid
, " before %<decltype%>");
8933 else if (token_type
< N_TTYPES
)
8935 message
= catenate_messages (gmsgid
, " before %qs token");
8936 error (message
, cpp_type2name (token_type
, token_flags
));
8948 #undef catenate_messages
8951 /* Mapping for cpp message reasons to the options that enable them. */
8953 struct reason_option_codes_t
8955 const int reason
; /* cpplib message reason. */
8956 const int option_code
; /* gcc option that controls this message. */
8959 static const struct reason_option_codes_t option_codes
[] = {
8960 {CPP_W_DEPRECATED
, OPT_Wdeprecated
},
8961 {CPP_W_COMMENTS
, OPT_Wcomment
},
8962 {CPP_W_TRIGRAPHS
, OPT_Wtrigraphs
},
8963 {CPP_W_MULTICHAR
, OPT_Wmultichar
},
8964 {CPP_W_TRADITIONAL
, OPT_Wtraditional
},
8965 {CPP_W_LONG_LONG
, OPT_Wlong_long
},
8966 {CPP_W_ENDIF_LABELS
, OPT_Wendif_labels
},
8967 {CPP_W_VARIADIC_MACROS
, OPT_Wvariadic_macros
},
8968 {CPP_W_BUILTIN_MACRO_REDEFINED
, OPT_Wbuiltin_macro_redefined
},
8969 {CPP_W_UNDEF
, OPT_Wundef
},
8970 {CPP_W_UNUSED_MACROS
, OPT_Wunused_macros
},
8971 {CPP_W_CXX_OPERATOR_NAMES
, OPT_Wc___compat
},
8972 {CPP_W_NORMALIZE
, OPT_Wnormalized_
},
8973 {CPP_W_INVALID_PCH
, OPT_Winvalid_pch
},
8974 {CPP_W_WARNING_DIRECTIVE
, OPT_Wcpp
},
8975 {CPP_W_LITERAL_SUFFIX
, OPT_Wliteral_suffix
},
8979 /* Return the gcc option code associated with the reason for a cpp
8980 message, or 0 if none. */
8983 c_option_controlling_cpp_error (int reason
)
8985 const struct reason_option_codes_t
*entry
;
8987 for (entry
= option_codes
; entry
->reason
!= CPP_W_NONE
; entry
++)
8989 if (entry
->reason
== reason
)
8990 return entry
->option_code
;
8995 /* Callback from cpp_error for PFILE to print diagnostics from the
8996 preprocessor. The diagnostic is of type LEVEL, with REASON set
8997 to the reason code if LEVEL is represents a warning, at location
8998 LOCATION unless this is after lexing and the compiler's location
8999 should be used instead, with column number possibly overridden by
9000 COLUMN_OVERRIDE if not zero; MSG is the translated message and AP
9001 the arguments. Returns true if a diagnostic was emitted, false
9005 c_cpp_error (cpp_reader
*pfile ATTRIBUTE_UNUSED
, int level
, int reason
,
9006 location_t location
, unsigned int column_override
,
9007 const char *msg
, va_list *ap
)
9009 diagnostic_info diagnostic
;
9010 diagnostic_t dlevel
;
9011 bool save_warn_system_headers
= global_dc
->dc_warn_system_headers
;
9016 case CPP_DL_WARNING_SYSHDR
:
9019 global_dc
->dc_warn_system_headers
= 1;
9021 case CPP_DL_WARNING
:
9024 dlevel
= DK_WARNING
;
9026 case CPP_DL_PEDWARN
:
9027 if (flag_no_output
&& !flag_pedantic_errors
)
9029 dlevel
= DK_PEDWARN
;
9047 location
= input_location
;
9048 diagnostic_set_info_translated (&diagnostic
, msg
, ap
,
9050 if (column_override
)
9051 diagnostic_override_column (&diagnostic
, column_override
);
9052 diagnostic_override_option_index (&diagnostic
,
9053 c_option_controlling_cpp_error (reason
));
9054 ret
= report_diagnostic (&diagnostic
);
9055 if (level
== CPP_DL_WARNING_SYSHDR
)
9056 global_dc
->dc_warn_system_headers
= save_warn_system_headers
;
9060 /* Convert a character from the host to the target execution character
9061 set. cpplib handles this, mostly. */
9064 c_common_to_target_charset (HOST_WIDE_INT c
)
9066 /* Character constants in GCC proper are sign-extended under -fsigned-char,
9067 zero-extended under -fno-signed-char. cpplib insists that characters
9068 and character constants are always unsigned. Hence we must convert
9070 cppchar_t uc
= ((cppchar_t
)c
) & ((((cppchar_t
)1) << CHAR_BIT
)-1);
9072 uc
= cpp_host_to_exec_charset (parse_in
, uc
);
9074 if (flag_signed_char
)
9075 return ((HOST_WIDE_INT
)uc
) << (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
)
9076 >> (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
);
9081 /* Fold an offsetof-like expression. EXPR is a nested sequence of component
9082 references with an INDIRECT_REF of a constant at the bottom; much like the
9083 traditional rendering of offsetof as a macro. Return the folded result. */
9086 fold_offsetof_1 (tree expr
)
9090 switch (TREE_CODE (expr
))
9096 error ("cannot apply %<offsetof%> to static data member %qD", expr
);
9097 return error_mark_node
;
9101 error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded");
9102 return error_mark_node
;
9106 if (!TREE_CONSTANT (TREE_OPERAND (expr
, 0)))
9108 error ("cannot apply %<offsetof%> to a non constant address");
9109 return error_mark_node
;
9111 return TREE_OPERAND (expr
, 0);
9114 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0));
9115 if (base
== error_mark_node
)
9118 t
= TREE_OPERAND (expr
, 1);
9119 if (DECL_C_BIT_FIELD (t
))
9121 error ("attempt to take address of bit-field structure "
9123 return error_mark_node
;
9125 off
= size_binop_loc (input_location
, PLUS_EXPR
, DECL_FIELD_OFFSET (t
),
9126 size_int (tree_low_cst (DECL_FIELD_BIT_OFFSET (t
),
9132 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0));
9133 if (base
== error_mark_node
)
9136 t
= TREE_OPERAND (expr
, 1);
9138 /* Check if the offset goes beyond the upper bound of the array. */
9139 if (TREE_CODE (t
) == INTEGER_CST
&& tree_int_cst_sgn (t
) >= 0)
9141 tree upbound
= array_ref_up_bound (expr
);
9142 if (upbound
!= NULL_TREE
9143 && TREE_CODE (upbound
) == INTEGER_CST
9144 && !tree_int_cst_equal (upbound
,
9145 TYPE_MAX_VALUE (TREE_TYPE (upbound
))))
9147 upbound
= size_binop (PLUS_EXPR
, upbound
,
9148 build_int_cst (TREE_TYPE (upbound
), 1));
9149 if (tree_int_cst_lt (upbound
, t
))
9153 for (v
= TREE_OPERAND (expr
, 0);
9154 TREE_CODE (v
) == COMPONENT_REF
;
9155 v
= TREE_OPERAND (v
, 0))
9156 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v
, 0)))
9159 tree fld_chain
= DECL_CHAIN (TREE_OPERAND (v
, 1));
9160 for (; fld_chain
; fld_chain
= DECL_CHAIN (fld_chain
))
9161 if (TREE_CODE (fld_chain
) == FIELD_DECL
)
9167 /* Don't warn if the array might be considered a poor
9168 man's flexible array member with a very permissive
9169 definition thereof. */
9170 if (TREE_CODE (v
) == ARRAY_REF
9171 || TREE_CODE (v
) == COMPONENT_REF
)
9172 warning (OPT_Warray_bounds
,
9173 "index %E denotes an offset "
9174 "greater than size of %qT",
9175 t
, TREE_TYPE (TREE_OPERAND (expr
, 0)));
9180 t
= convert (sizetype
, t
);
9181 off
= size_binop (MULT_EXPR
, TYPE_SIZE_UNIT (TREE_TYPE (expr
)), t
);
9185 /* Handle static members of volatile structs. */
9186 t
= TREE_OPERAND (expr
, 1);
9187 gcc_assert (TREE_CODE (t
) == VAR_DECL
);
9188 return fold_offsetof_1 (t
);
9194 return fold_build_pointer_plus (base
, off
);
9197 /* Likewise, but convert it to the return type of offsetof. */
9200 fold_offsetof (tree expr
)
9202 return convert (size_type_node
, fold_offsetof_1 (expr
));
9205 /* Warn for A ?: C expressions (with B omitted) where A is a boolean
9206 expression, because B will always be true. */
9209 warn_for_omitted_condop (location_t location
, tree cond
)
9211 if (truth_value_p (TREE_CODE (cond
)))
9212 warning_at (location
, OPT_Wparentheses
,
9213 "the omitted middle operand in ?: will always be %<true%>, "
9214 "suggest explicit middle operand");
9217 /* Give an error for storing into ARG, which is 'const'. USE indicates
9218 how ARG was being used. */
9221 readonly_error (tree arg
, enum lvalue_use use
)
9223 gcc_assert (use
== lv_assign
|| use
== lv_increment
|| use
== lv_decrement
9225 /* Using this macro rather than (for example) arrays of messages
9226 ensures that all the format strings are checked at compile
9228 #define READONLY_MSG(A, I, D, AS) (use == lv_assign ? (A) \
9229 : (use == lv_increment ? (I) \
9230 : (use == lv_decrement ? (D) : (AS))))
9231 if (TREE_CODE (arg
) == COMPONENT_REF
)
9233 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg
, 0))))
9234 error (READONLY_MSG (G_("assignment of member "
9235 "%qD in read-only object"),
9236 G_("increment of member "
9237 "%qD in read-only object"),
9238 G_("decrement of member "
9239 "%qD in read-only object"),
9240 G_("member %qD in read-only object "
9241 "used as %<asm%> output")),
9242 TREE_OPERAND (arg
, 1));
9244 error (READONLY_MSG (G_("assignment of read-only member %qD"),
9245 G_("increment of read-only member %qD"),
9246 G_("decrement of read-only member %qD"),
9247 G_("read-only member %qD used as %<asm%> output")),
9248 TREE_OPERAND (arg
, 1));
9250 else if (TREE_CODE (arg
) == VAR_DECL
)
9251 error (READONLY_MSG (G_("assignment of read-only variable %qD"),
9252 G_("increment of read-only variable %qD"),
9253 G_("decrement of read-only variable %qD"),
9254 G_("read-only variable %qD used as %<asm%> output")),
9256 else if (TREE_CODE (arg
) == PARM_DECL
)
9257 error (READONLY_MSG (G_("assignment of read-only parameter %qD"),
9258 G_("increment of read-only parameter %qD"),
9259 G_("decrement of read-only parameter %qD"),
9260 G_("read-only parameter %qD use as %<asm%> output")),
9262 else if (TREE_CODE (arg
) == RESULT_DECL
)
9264 gcc_assert (c_dialect_cxx ());
9265 error (READONLY_MSG (G_("assignment of "
9266 "read-only named return value %qD"),
9268 "read-only named return value %qD"),
9270 "read-only named return value %qD"),
9271 G_("read-only named return value %qD "
9272 "used as %<asm%>output")),
9275 else if (TREE_CODE (arg
) == FUNCTION_DECL
)
9276 error (READONLY_MSG (G_("assignment of function %qD"),
9277 G_("increment of function %qD"),
9278 G_("decrement of function %qD"),
9279 G_("function %qD used as %<asm%> output")),
9282 error (READONLY_MSG (G_("assignment of read-only location %qE"),
9283 G_("increment of read-only location %qE"),
9284 G_("decrement of read-only location %qE"),
9285 G_("read-only location %qE used as %<asm%> output")),
9289 /* Print an error message for an invalid lvalue. USE says
9290 how the lvalue is being used and so selects the error message. LOC
9291 is the location for the error. */
9294 lvalue_error (location_t loc
, enum lvalue_use use
)
9299 error_at (loc
, "lvalue required as left operand of assignment");
9302 error_at (loc
, "lvalue required as increment operand");
9305 error_at (loc
, "lvalue required as decrement operand");
9308 error_at (loc
, "lvalue required as unary %<&%> operand");
9311 error_at (loc
, "lvalue required in asm statement");
9318 /* Print an error message for an invalid indirection of type TYPE.
9319 ERRSTRING is the name of the operator for the indirection. */
9322 invalid_indirection_error (location_t loc
, tree type
, ref_operator errstring
)
9327 gcc_assert (c_dialect_cxx ());
9328 error_at (loc
, "invalid type argument (have %qT)", type
);
9330 case RO_ARRAY_INDEXING
:
9332 "invalid type argument of array indexing (have %qT)",
9337 "invalid type argument of unary %<*%> (have %qT)",
9342 "invalid type argument of %<->%> (have %qT)",
9345 case RO_IMPLICIT_CONVERSION
:
9347 "invalid type argument of implicit conversion (have %qT)",
9355 /* *PTYPE is an incomplete array. Complete it with a domain based on
9356 INITIAL_VALUE. If INITIAL_VALUE is not present, use 1 if DO_DEFAULT
9357 is true. Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
9358 2 if INITIAL_VALUE was NULL, and 3 if INITIAL_VALUE was empty. */
9361 complete_array_type (tree
*ptype
, tree initial_value
, bool do_default
)
9363 tree maxindex
, type
, main_type
, elt
, unqual_elt
;
9364 int failure
= 0, quals
;
9365 hashval_t hashcode
= 0;
9367 maxindex
= size_zero_node
;
9370 if (TREE_CODE (initial_value
) == STRING_CST
)
9373 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value
)));
9374 maxindex
= size_int (TREE_STRING_LENGTH (initial_value
)/eltsize
- 1);
9376 else if (TREE_CODE (initial_value
) == CONSTRUCTOR
)
9378 VEC(constructor_elt
,gc
) *v
= CONSTRUCTOR_ELTS (initial_value
);
9380 if (VEC_empty (constructor_elt
, v
))
9384 maxindex
= ssize_int (-1);
9389 unsigned HOST_WIDE_INT cnt
;
9390 constructor_elt
*ce
;
9391 bool fold_p
= false;
9393 if (VEC_index (constructor_elt
, v
, 0).index
)
9394 maxindex
= fold_convert_loc (input_location
, sizetype
,
9395 VEC_index (constructor_elt
,
9397 curindex
= maxindex
;
9400 VEC_iterate (constructor_elt
, v
, cnt
, ce
);
9403 bool curfold_p
= false;
9405 curindex
= ce
->index
, curfold_p
= true;
9409 curindex
= fold_convert (sizetype
, curindex
);
9410 curindex
= size_binop (PLUS_EXPR
, curindex
,
9413 if (tree_int_cst_lt (maxindex
, curindex
))
9414 maxindex
= curindex
, fold_p
= curfold_p
;
9417 maxindex
= fold_convert (sizetype
, maxindex
);
9422 /* Make an error message unless that happened already. */
9423 if (initial_value
!= error_mark_node
)
9435 elt
= TREE_TYPE (type
);
9436 quals
= TYPE_QUALS (strip_array_types (elt
));
9440 unqual_elt
= c_build_qualified_type (elt
, KEEP_QUAL_ADDR_SPACE (quals
));
9442 /* Using build_distinct_type_copy and modifying things afterward instead
9443 of using build_array_type to create a new type preserves all of the
9444 TYPE_LANG_FLAG_? bits that the front end may have set. */
9445 main_type
= build_distinct_type_copy (TYPE_MAIN_VARIANT (type
));
9446 TREE_TYPE (main_type
) = unqual_elt
;
9447 TYPE_DOMAIN (main_type
)
9448 = build_range_type (TREE_TYPE (maxindex
),
9449 build_int_cst (TREE_TYPE (maxindex
), 0), maxindex
);
9450 layout_type (main_type
);
9452 /* Make sure we have the canonical MAIN_TYPE. */
9453 hashcode
= iterative_hash_object (TYPE_HASH (unqual_elt
), hashcode
);
9454 hashcode
= iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (main_type
)),
9456 main_type
= type_hash_canon (hashcode
, main_type
);
9458 /* Fix the canonical type. */
9459 if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type
))
9460 || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type
)))
9461 SET_TYPE_STRUCTURAL_EQUALITY (main_type
);
9462 else if (TYPE_CANONICAL (TREE_TYPE (main_type
)) != TREE_TYPE (main_type
)
9463 || (TYPE_CANONICAL (TYPE_DOMAIN (main_type
))
9464 != TYPE_DOMAIN (main_type
)))
9465 TYPE_CANONICAL (main_type
)
9466 = build_array_type (TYPE_CANONICAL (TREE_TYPE (main_type
)),
9467 TYPE_CANONICAL (TYPE_DOMAIN (main_type
)));
9469 TYPE_CANONICAL (main_type
) = main_type
;
9474 type
= c_build_qualified_type (main_type
, quals
);
9476 if (COMPLETE_TYPE_P (type
)
9477 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
9478 && TREE_OVERFLOW (TYPE_SIZE_UNIT (type
)))
9480 error ("size of array is too large");
9481 /* If we proceed with the array type as it is, we'll eventually
9482 crash in tree_low_cst(). */
9483 type
= error_mark_node
;
9490 /* Like c_mark_addressable but don't check register qualifier. */
9492 c_common_mark_addressable_vec (tree t
)
9494 while (handled_component_p (t
))
9495 t
= TREE_OPERAND (t
, 0);
9496 if (TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != PARM_DECL
)
9498 TREE_ADDRESSABLE (t
) = 1;
9503 /* Used to help initialize the builtin-types.def table. When a type of
9504 the correct size doesn't exist, use error_mark_node instead of NULL.
9505 The later results in segfaults even when a decl using the type doesn't
9509 builtin_type_for_size (int size
, bool unsignedp
)
9511 tree type
= c_common_type_for_size (size
, unsignedp
);
9512 return type
? type
: error_mark_node
;
9515 /* A helper function for resolve_overloaded_builtin in resolving the
9516 overloaded __sync_ builtins. Returns a positive power of 2 if the
9517 first operand of PARAMS is a pointer to a supported data type.
9518 Returns 0 if an error is encountered. */
9521 sync_resolve_size (tree function
, VEC(tree
,gc
) *params
)
9526 if (VEC_empty (tree
, params
))
9528 error ("too few arguments to function %qE", function
);
9532 type
= TREE_TYPE (VEC_index (tree
, params
, 0));
9533 if (TREE_CODE (type
) != POINTER_TYPE
)
9536 type
= TREE_TYPE (type
);
9537 if (!INTEGRAL_TYPE_P (type
) && !POINTER_TYPE_P (type
))
9540 size
= tree_low_cst (TYPE_SIZE_UNIT (type
), 1);
9541 if (size
== 1 || size
== 2 || size
== 4 || size
== 8 || size
== 16)
9545 error ("incompatible type for argument %d of %qE", 1, function
);
9549 /* A helper function for resolve_overloaded_builtin. Adds casts to
9550 PARAMS to make arguments match up with those of FUNCTION. Drops
9551 the variadic arguments at the end. Returns false if some error
9552 was encountered; true on success. */
9555 sync_resolve_params (location_t loc
, tree orig_function
, tree function
,
9556 VEC(tree
, gc
) *params
, bool orig_format
)
9558 function_args_iterator iter
;
9560 unsigned int parmnum
;
9562 function_args_iter_init (&iter
, TREE_TYPE (function
));
9563 /* We've declared the implementation functions to use "volatile void *"
9564 as the pointer parameter, so we shouldn't get any complaints from the
9565 call to check_function_arguments what ever type the user used. */
9566 function_args_iter_next (&iter
);
9567 ptype
= TREE_TYPE (TREE_TYPE (VEC_index (tree
, params
, 0)));
9569 /* For the rest of the values, we need to cast these to FTYPE, so that we
9570 don't get warnings for passing pointer types, etc. */
9576 arg_type
= function_args_iter_cond (&iter
);
9577 /* XXX void_type_node belies the abstraction. */
9578 if (arg_type
== void_type_node
)
9582 if (VEC_length (tree
, params
) <= parmnum
)
9584 error_at (loc
, "too few arguments to function %qE", orig_function
);
9588 /* Only convert parameters if arg_type is unsigned integer type with
9589 new format sync routines, i.e. don't attempt to convert pointer
9590 arguments (e.g. EXPECTED argument of __atomic_compare_exchange_n),
9591 bool arguments (e.g. WEAK argument) or signed int arguments (memmodel
9593 if (TREE_CODE (arg_type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (arg_type
))
9595 /* Ideally for the first conversion we'd use convert_for_assignment
9596 so that we get warnings for anything that doesn't match the pointer
9597 type. This isn't portable across the C and C++ front ends atm. */
9598 val
= VEC_index (tree
, params
, parmnum
);
9599 val
= convert (ptype
, val
);
9600 val
= convert (arg_type
, val
);
9601 VEC_replace (tree
, params
, parmnum
, val
);
9604 function_args_iter_next (&iter
);
9607 /* __atomic routines are not variadic. */
9608 if (!orig_format
&& VEC_length (tree
, params
) != parmnum
+ 1)
9610 error_at (loc
, "too many arguments to function %qE", orig_function
);
9614 /* The definition of these primitives is variadic, with the remaining
9615 being "an optional list of variables protected by the memory barrier".
9616 No clue what that's supposed to mean, precisely, but we consider all
9617 call-clobbered variables to be protected so we're safe. */
9618 VEC_truncate (tree
, params
, parmnum
+ 1);
9623 /* A helper function for resolve_overloaded_builtin. Adds a cast to
9624 RESULT to make it match the type of the first pointer argument in
9628 sync_resolve_return (tree first_param
, tree result
, bool orig_format
)
9630 tree ptype
= TREE_TYPE (TREE_TYPE (first_param
));
9631 tree rtype
= TREE_TYPE (result
);
9632 ptype
= TYPE_MAIN_VARIANT (ptype
);
9634 /* New format doesn't require casting unless the types are the same size. */
9635 if (orig_format
|| tree_int_cst_equal (TYPE_SIZE (ptype
), TYPE_SIZE (rtype
)))
9636 return convert (ptype
, result
);
9641 /* This function verifies the PARAMS to generic atomic FUNCTION.
9642 It returns the size if all the parameters are the same size, otherwise
9643 0 is returned if the parameters are invalid. */
9646 get_atomic_generic_size (location_t loc
, tree function
, VEC(tree
,gc
) *params
)
9648 unsigned int n_param
;
9649 unsigned int n_model
;
9654 /* Determine the parameter makeup. */
9655 switch (DECL_FUNCTION_CODE (function
))
9657 case BUILT_IN_ATOMIC_EXCHANGE
:
9661 case BUILT_IN_ATOMIC_LOAD
:
9662 case BUILT_IN_ATOMIC_STORE
:
9666 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
9674 if (VEC_length (tree
, params
) != n_param
)
9676 error_at (loc
, "incorrect number of arguments to function %qE", function
);
9680 /* Get type of first parameter, and determine its size. */
9681 type_0
= TREE_TYPE (VEC_index (tree
, params
, 0));
9682 if (TREE_CODE (type_0
) != POINTER_TYPE
|| VOID_TYPE_P (TREE_TYPE (type_0
)))
9684 error_at (loc
, "argument 1 of %qE must be a non-void pointer type",
9689 /* Types must be compile time constant sizes. */
9690 if (TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type_0
)))) != INTEGER_CST
)
9693 "argument 1 of %qE must be a pointer to a constant size type",
9698 size_0
= tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (type_0
)), 1);
9700 /* Zero size objects are not allowed. */
9704 "argument 1 of %qE must be a pointer to a nonzero size object",
9709 /* Check each other parameter is a pointer and the same size. */
9710 for (x
= 0; x
< n_param
- n_model
; x
++)
9713 tree type
= TREE_TYPE (VEC_index (tree
, params
, x
));
9714 /* __atomic_compare_exchange has a bool in the 4th postion, skip it. */
9715 if (n_param
== 6 && x
== 3)
9717 if (!POINTER_TYPE_P (type
))
9719 error_at (loc
, "argument %d of %qE must be a pointer type", x
+ 1,
9723 size
= tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (type
)), 1);
9726 error_at (loc
, "size mismatch in argument %d of %qE", x
+ 1,
9732 /* Check memory model parameters for validity. */
9733 for (x
= n_param
- n_model
; x
< n_param
; x
++)
9735 tree p
= VEC_index (tree
, params
, x
);
9736 if (TREE_CODE (p
) == INTEGER_CST
)
9738 int i
= tree_low_cst (p
, 1);
9739 if (i
< 0 || i
>= MEMMODEL_LAST
)
9741 warning_at (loc
, OPT_Winvalid_memory_model
,
9742 "invalid memory model argument %d of %qE", x
+ 1,
9747 if (!INTEGRAL_TYPE_P (TREE_TYPE (p
)))
9749 error_at (loc
, "non-integer memory model argument %d of %qE", x
+ 1,
9759 /* This will take an __atomic_ generic FUNCTION call, and add a size parameter N
9760 at the beginning of the parameter list PARAMS representing the size of the
9761 objects. This is to match the library ABI requirement. LOC is the location
9762 of the function call.
9763 The new function is returned if it needed rebuilding, otherwise NULL_TREE is
9764 returned to allow the external call to be constructed. */
9767 add_atomic_size_parameter (unsigned n
, location_t loc
, tree function
,
9768 VEC(tree
,gc
) *params
)
9772 /* Insert a SIZE_T parameter as the first param. If there isn't
9773 enough space, allocate a new vector and recursively re-build with that. */
9774 if (!VEC_space (tree
, params
, 1))
9776 unsigned int z
, len
;
9780 len
= VEC_length (tree
, params
);
9781 vec
= VEC_alloc (tree
, gc
, len
+ 1);
9782 for (z
= 0; z
< len
; z
++)
9783 VEC_quick_push (tree
, vec
, VEC_index (tree
, params
, z
));
9784 f
= build_function_call_vec (loc
, function
, vec
, NULL
);
9785 VEC_free (tree
, gc
, vec
);
9789 /* Add the size parameter and leave as a function call for processing. */
9790 size_node
= build_int_cst (size_type_node
, n
);
9791 VEC_quick_insert (tree
, params
, 0, size_node
);
9796 /* This will process an __atomic_exchange function call, determine whether it
9797 needs to be mapped to the _N variation, or turned into a library call.
9798 LOC is the location of the builtin call.
9799 FUNCTION is the DECL that has been invoked;
9800 PARAMS is the argument list for the call. The return value is non-null
9801 TRUE is returned if it is translated into the proper format for a call to the
9802 external library, and NEW_RETURN is set the tree for that function.
9803 FALSE is returned if processing for the _N variation is required, and
9804 NEW_RETURN is set to the the return value the result is copied into. */
9806 resolve_overloaded_atomic_exchange (location_t loc
, tree function
,
9807 VEC(tree
,gc
) *params
, tree
*new_return
)
9809 tree p0
, p1
, p2
, p3
;
9810 tree I_type
, I_type_ptr
;
9811 int n
= get_atomic_generic_size (loc
, function
, params
);
9813 /* Size of 0 is an error condition. */
9816 *new_return
= error_mark_node
;
9820 /* If not a lock-free size, change to the library generic format. */
9821 if (n
!= 1 && n
!= 2 && n
!= 4 && n
!= 8 && n
!= 16)
9823 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
9827 /* Otherwise there is a lockfree match, transform the call from:
9828 void fn(T* mem, T* desired, T* return, model)
9830 *return = (T) (fn (In* mem, (In) *desired, model)) */
9832 p0
= VEC_index (tree
, params
, 0);
9833 p1
= VEC_index (tree
, params
, 1);
9834 p2
= VEC_index (tree
, params
, 2);
9835 p3
= VEC_index (tree
, params
, 3);
9837 /* Create pointer to appropriate size. */
9838 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
9839 I_type_ptr
= build_pointer_type (I_type
);
9841 /* Convert object pointer to required type. */
9842 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
9843 VEC_replace (tree
, params
, 0, p0
);
9844 /* Convert new value to required type, and dereference it. */
9845 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
9846 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
9847 VEC_replace (tree
, params
, 1, p1
);
9849 /* Move memory model to the 3rd position, and end param list. */
9850 VEC_replace (tree
, params
, 2, p3
);
9851 VEC_truncate (tree
, params
, 3);
9853 /* Convert return pointer and dereference it for later assignment. */
9854 *new_return
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
9860 /* This will process an __atomic_compare_exchange function call, determine
9861 whether it needs to be mapped to the _N variation, or turned into a lib call.
9862 LOC is the location of the builtin call.
9863 FUNCTION is the DECL that has been invoked;
9864 PARAMS is the argument list for the call. The return value is non-null
9865 TRUE is returned if it is translated into the proper format for a call to the
9866 external library, and NEW_RETURN is set the tree for that function.
9867 FALSE is returned if processing for the _N variation is required. */
9870 resolve_overloaded_atomic_compare_exchange (location_t loc
, tree function
,
9871 VEC(tree
,gc
) *params
,
9875 tree I_type
, I_type_ptr
;
9876 int n
= get_atomic_generic_size (loc
, function
, params
);
9878 /* Size of 0 is an error condition. */
9881 *new_return
= error_mark_node
;
9885 /* If not a lock-free size, change to the library generic format. */
9886 if (n
!= 1 && n
!= 2 && n
!= 4 && n
!= 8 && n
!= 16)
9888 /* The library generic format does not have the weak parameter, so
9889 remove it from the param list. Since a parameter has been removed,
9890 we can be sure that there is room for the SIZE_T parameter, meaning
9891 there will not be a recursive rebuilding of the parameter list, so
9892 there is no danger this will be done twice. */
9895 VEC_replace (tree
, params
, 3, VEC_index (tree
, params
, 4));
9896 VEC_replace (tree
, params
, 4, VEC_index (tree
, params
, 5));
9897 VEC_truncate (tree
, params
, 5);
9899 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
9903 /* Otherwise, there is a match, so the call needs to be transformed from:
9904 bool fn(T* mem, T* desired, T* return, weak, success, failure)
9906 bool fn ((In *)mem, (In *)expected, (In) *desired, weak, succ, fail) */
9908 p0
= VEC_index (tree
, params
, 0);
9909 p1
= VEC_index (tree
, params
, 1);
9910 p2
= VEC_index (tree
, params
, 2);
9912 /* Create pointer to appropriate size. */
9913 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
9914 I_type_ptr
= build_pointer_type (I_type
);
9916 /* Convert object pointer to required type. */
9917 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
9918 VEC_replace (tree
, params
, 0, p0
);
9920 /* Convert expected pointer to required type. */
9921 p1
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p1
);
9922 VEC_replace (tree
, params
, 1, p1
);
9924 /* Convert desired value to required type, and dereference it. */
9925 p2
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
9926 p2
= build1 (VIEW_CONVERT_EXPR
, I_type
, p2
);
9927 VEC_replace (tree
, params
, 2, p2
);
9929 /* The rest of the parameters are fine. NULL means no special return value
9936 /* This will process an __atomic_load function call, determine whether it
9937 needs to be mapped to the _N variation, or turned into a library call.
9938 LOC is the location of the builtin call.
9939 FUNCTION is the DECL that has been invoked;
9940 PARAMS is the argument list for the call. The return value is non-null
9941 TRUE is returned if it is translated into the proper format for a call to the
9942 external library, and NEW_RETURN is set the tree for that function.
9943 FALSE is returned if processing for the _N variation is required, and
9944 NEW_RETURN is set to the the return value the result is copied into. */
9947 resolve_overloaded_atomic_load (location_t loc
, tree function
,
9948 VEC(tree
,gc
) *params
, tree
*new_return
)
9951 tree I_type
, I_type_ptr
;
9952 int n
= get_atomic_generic_size (loc
, function
, params
);
9954 /* Size of 0 is an error condition. */
9957 *new_return
= error_mark_node
;
9961 /* If not a lock-free size, change to the library generic format. */
9962 if (n
!= 1 && n
!= 2 && n
!= 4 && n
!= 8 && n
!= 16)
9964 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
9968 /* Otherwise, there is a match, so the call needs to be transformed from:
9969 void fn(T* mem, T* return, model)
9971 *return = (T) (fn ((In *) mem, model)) */
9973 p0
= VEC_index (tree
, params
, 0);
9974 p1
= VEC_index (tree
, params
, 1);
9975 p2
= VEC_index (tree
, params
, 2);
9977 /* Create pointer to appropriate size. */
9978 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
9979 I_type_ptr
= build_pointer_type (I_type
);
9981 /* Convert object pointer to required type. */
9982 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
9983 VEC_replace (tree
, params
, 0, p0
);
9985 /* Move memory model to the 2nd position, and end param list. */
9986 VEC_replace (tree
, params
, 1, p2
);
9987 VEC_truncate (tree
, params
, 2);
9989 /* Convert return pointer and dereference it for later assignment. */
9990 *new_return
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
9996 /* This will process an __atomic_store function call, determine whether it
9997 needs to be mapped to the _N variation, or turned into a library call.
9998 LOC is the location of the builtin call.
9999 FUNCTION is the DECL that has been invoked;
10000 PARAMS is the argument list for the call. The return value is non-null
10001 TRUE is returned if it is translated into the proper format for a call to the
10002 external library, and NEW_RETURN is set the tree for that function.
10003 FALSE is returned if processing for the _N variation is required, and
10004 NEW_RETURN is set to the the return value the result is copied into. */
10007 resolve_overloaded_atomic_store (location_t loc
, tree function
,
10008 VEC(tree
,gc
) *params
, tree
*new_return
)
10011 tree I_type
, I_type_ptr
;
10012 int n
= get_atomic_generic_size (loc
, function
, params
);
10014 /* Size of 0 is an error condition. */
10017 *new_return
= error_mark_node
;
10021 /* If not a lock-free size, change to the library generic format. */
10022 if (n
!= 1 && n
!= 2 && n
!= 4 && n
!= 8 && n
!= 16)
10024 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
10028 /* Otherwise, there is a match, so the call needs to be transformed from:
10029 void fn(T* mem, T* value, model)
10031 fn ((In *) mem, (In) *value, model) */
10033 p0
= VEC_index (tree
, params
, 0);
10034 p1
= VEC_index (tree
, params
, 1);
10036 /* Create pointer to appropriate size. */
10037 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
10038 I_type_ptr
= build_pointer_type (I_type
);
10040 /* Convert object pointer to required type. */
10041 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
10042 VEC_replace (tree
, params
, 0, p0
);
10044 /* Convert new value to required type, and dereference it. */
10045 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
10046 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
10047 VEC_replace (tree
, params
, 1, p1
);
10049 /* The memory model is in the right spot already. Return is void. */
10050 *new_return
= NULL_TREE
;
10056 /* Some builtin functions are placeholders for other expressions. This
10057 function should be called immediately after parsing the call expression
10058 before surrounding code has committed to the type of the expression.
10060 LOC is the location of the builtin call.
10062 FUNCTION is the DECL that has been invoked; it is known to be a builtin.
10063 PARAMS is the argument list for the call. The return value is non-null
10064 when expansion is complete, and null if normal processing should
10068 resolve_overloaded_builtin (location_t loc
, tree function
, VEC(tree
,gc
) *params
)
10070 enum built_in_function orig_code
= DECL_FUNCTION_CODE (function
);
10071 bool orig_format
= true;
10072 tree new_return
= NULL_TREE
;
10074 switch (DECL_BUILT_IN_CLASS (function
))
10076 case BUILT_IN_NORMAL
:
10079 if (targetm
.resolve_overloaded_builtin
)
10080 return targetm
.resolve_overloaded_builtin (loc
, function
, params
);
10087 /* Handle BUILT_IN_NORMAL here. */
10090 case BUILT_IN_ATOMIC_EXCHANGE
:
10091 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10092 case BUILT_IN_ATOMIC_LOAD
:
10093 case BUILT_IN_ATOMIC_STORE
:
10095 /* Handle these 4 together so that they can fall through to the next
10096 case if the call is transformed to an _N variant. */
10099 case BUILT_IN_ATOMIC_EXCHANGE
:
10101 if (resolve_overloaded_atomic_exchange (loc
, function
, params
,
10104 /* Change to the _N variant. */
10105 orig_code
= BUILT_IN_ATOMIC_EXCHANGE_N
;
10109 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
10111 if (resolve_overloaded_atomic_compare_exchange (loc
, function
,
10115 /* Change to the _N variant. */
10116 orig_code
= BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
;
10119 case BUILT_IN_ATOMIC_LOAD
:
10121 if (resolve_overloaded_atomic_load (loc
, function
, params
,
10124 /* Change to the _N variant. */
10125 orig_code
= BUILT_IN_ATOMIC_LOAD_N
;
10128 case BUILT_IN_ATOMIC_STORE
:
10130 if (resolve_overloaded_atomic_store (loc
, function
, params
,
10133 /* Change to the _N variant. */
10134 orig_code
= BUILT_IN_ATOMIC_STORE_N
;
10138 gcc_unreachable ();
10140 /* Fallthrough to the normal processing. */
10142 case BUILT_IN_ATOMIC_EXCHANGE_N
:
10143 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
:
10144 case BUILT_IN_ATOMIC_LOAD_N
:
10145 case BUILT_IN_ATOMIC_STORE_N
:
10146 case BUILT_IN_ATOMIC_ADD_FETCH_N
:
10147 case BUILT_IN_ATOMIC_SUB_FETCH_N
:
10148 case BUILT_IN_ATOMIC_AND_FETCH_N
:
10149 case BUILT_IN_ATOMIC_NAND_FETCH_N
:
10150 case BUILT_IN_ATOMIC_XOR_FETCH_N
:
10151 case BUILT_IN_ATOMIC_OR_FETCH_N
:
10152 case BUILT_IN_ATOMIC_FETCH_ADD_N
:
10153 case BUILT_IN_ATOMIC_FETCH_SUB_N
:
10154 case BUILT_IN_ATOMIC_FETCH_AND_N
:
10155 case BUILT_IN_ATOMIC_FETCH_NAND_N
:
10156 case BUILT_IN_ATOMIC_FETCH_XOR_N
:
10157 case BUILT_IN_ATOMIC_FETCH_OR_N
:
10159 orig_format
= false;
10160 /* Fallthru for parameter processing. */
10162 case BUILT_IN_SYNC_FETCH_AND_ADD_N
:
10163 case BUILT_IN_SYNC_FETCH_AND_SUB_N
:
10164 case BUILT_IN_SYNC_FETCH_AND_OR_N
:
10165 case BUILT_IN_SYNC_FETCH_AND_AND_N
:
10166 case BUILT_IN_SYNC_FETCH_AND_XOR_N
:
10167 case BUILT_IN_SYNC_FETCH_AND_NAND_N
:
10168 case BUILT_IN_SYNC_ADD_AND_FETCH_N
:
10169 case BUILT_IN_SYNC_SUB_AND_FETCH_N
:
10170 case BUILT_IN_SYNC_OR_AND_FETCH_N
:
10171 case BUILT_IN_SYNC_AND_AND_FETCH_N
:
10172 case BUILT_IN_SYNC_XOR_AND_FETCH_N
:
10173 case BUILT_IN_SYNC_NAND_AND_FETCH_N
:
10174 case BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
:
10175 case BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N
:
10176 case BUILT_IN_SYNC_LOCK_TEST_AND_SET_N
:
10177 case BUILT_IN_SYNC_LOCK_RELEASE_N
:
10179 int n
= sync_resolve_size (function
, params
);
10180 tree new_function
, first_param
, result
;
10181 enum built_in_function fncode
;
10184 return error_mark_node
;
10186 fncode
= (enum built_in_function
)((int)orig_code
+ exact_log2 (n
) + 1);
10187 new_function
= builtin_decl_explicit (fncode
);
10188 if (!sync_resolve_params (loc
, function
, new_function
, params
,
10190 return error_mark_node
;
10192 first_param
= VEC_index (tree
, params
, 0);
10193 result
= build_function_call_vec (loc
, new_function
, params
, NULL
);
10194 if (result
== error_mark_node
)
10196 if (orig_code
!= BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
10197 && orig_code
!= BUILT_IN_SYNC_LOCK_RELEASE_N
10198 && orig_code
!= BUILT_IN_ATOMIC_STORE_N
)
10199 result
= sync_resolve_return (first_param
, result
, orig_format
);
10201 /* If new_return is set, assign function to that expr and cast the
10202 result to void since the generic interface returned void. */
10205 /* Cast function result from I{1,2,4,8,16} to the required type. */
10206 result
= build1 (VIEW_CONVERT_EXPR
, TREE_TYPE (new_return
), result
);
10207 result
= build2 (MODIFY_EXPR
, TREE_TYPE (new_return
), new_return
,
10209 TREE_SIDE_EFFECTS (result
) = 1;
10210 protected_set_expr_location (result
, loc
);
10211 result
= convert (void_type_node
, result
);
10221 /* Ignoring their sign, return true if two scalar types are the same. */
10223 same_scalar_type_ignoring_signedness (tree t1
, tree t2
)
10225 enum tree_code c1
= TREE_CODE (t1
), c2
= TREE_CODE (t2
);
10227 gcc_assert ((c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
|| c1
== FIXED_POINT_TYPE
)
10228 && (c2
== INTEGER_TYPE
|| c2
== REAL_TYPE
10229 || c2
== FIXED_POINT_TYPE
));
10231 /* Equality works here because c_common_signed_type uses
10232 TYPE_MAIN_VARIANT. */
10233 return c_common_signed_type (t1
)
10234 == c_common_signed_type (t2
);
10237 /* Check for missing format attributes on function pointers. LTYPE is
10238 the new type or left-hand side type. RTYPE is the old type or
10239 right-hand side type. Returns TRUE if LTYPE is missing the desired
10243 check_missing_format_attribute (tree ltype
, tree rtype
)
10245 tree
const ttr
= TREE_TYPE (rtype
), ttl
= TREE_TYPE (ltype
);
10248 for (ra
= TYPE_ATTRIBUTES (ttr
); ra
; ra
= TREE_CHAIN (ra
))
10249 if (is_attribute_p ("format", TREE_PURPOSE (ra
)))
10254 for (la
= TYPE_ATTRIBUTES (ttl
); la
; la
= TREE_CHAIN (la
))
10255 if (is_attribute_p ("format", TREE_PURPOSE (la
)))
10263 /* Subscripting with type char is likely to lose on a machine where
10264 chars are signed. So warn on any machine, but optionally. Don't
10265 warn for unsigned char since that type is safe. Don't warn for
10266 signed char because anyone who uses that must have done so
10267 deliberately. Furthermore, we reduce the false positive load by
10268 warning only for non-constant value of type char. */
10271 warn_array_subscript_with_type_char (tree index
)
10273 if (TYPE_MAIN_VARIANT (TREE_TYPE (index
)) == char_type_node
10274 && TREE_CODE (index
) != INTEGER_CST
)
10275 warning (OPT_Wchar_subscripts
, "array subscript has type %<char%>");
10278 /* Implement -Wparentheses for the unexpected C precedence rules, to
10279 cover cases like x + y << z which readers are likely to
10280 misinterpret. We have seen an expression in which CODE is a binary
10281 operator used to combine expressions ARG_LEFT and ARG_RIGHT, which
10282 before folding had CODE_LEFT and CODE_RIGHT. CODE_LEFT and
10283 CODE_RIGHT may be ERROR_MARK, which means that that side of the
10284 expression was not formed using a binary or unary operator, or it
10285 was enclosed in parentheses. */
10288 warn_about_parentheses (enum tree_code code
,
10289 enum tree_code code_left
, tree arg_left
,
10290 enum tree_code code_right
, tree arg_right
)
10292 if (!warn_parentheses
)
10295 /* This macro tests that the expression ARG with original tree code
10296 CODE appears to be a boolean expression. or the result of folding a
10297 boolean expression. */
10298 #define APPEARS_TO_BE_BOOLEAN_EXPR_P(CODE, ARG) \
10299 (truth_value_p (TREE_CODE (ARG)) \
10300 || TREE_CODE (TREE_TYPE (ARG)) == BOOLEAN_TYPE \
10301 /* Folding may create 0 or 1 integers from other expressions. */ \
10302 || ((CODE) != INTEGER_CST \
10303 && (integer_onep (ARG) || integer_zerop (ARG))))
10308 if (code_left
== PLUS_EXPR
|| code_right
== PLUS_EXPR
)
10309 warning (OPT_Wparentheses
,
10310 "suggest parentheses around %<+%> inside %<<<%>");
10311 else if (code_left
== MINUS_EXPR
|| code_right
== MINUS_EXPR
)
10312 warning (OPT_Wparentheses
,
10313 "suggest parentheses around %<-%> inside %<<<%>");
10317 if (code_left
== PLUS_EXPR
|| code_right
== PLUS_EXPR
)
10318 warning (OPT_Wparentheses
,
10319 "suggest parentheses around %<+%> inside %<>>%>");
10320 else if (code_left
== MINUS_EXPR
|| code_right
== MINUS_EXPR
)
10321 warning (OPT_Wparentheses
,
10322 "suggest parentheses around %<-%> inside %<>>%>");
10325 case TRUTH_ORIF_EXPR
:
10326 if (code_left
== TRUTH_ANDIF_EXPR
|| code_right
== TRUTH_ANDIF_EXPR
)
10327 warning (OPT_Wparentheses
,
10328 "suggest parentheses around %<&&%> within %<||%>");
10332 if (code_left
== BIT_AND_EXPR
|| code_left
== BIT_XOR_EXPR
10333 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
10334 || code_right
== BIT_AND_EXPR
|| code_right
== BIT_XOR_EXPR
10335 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
10336 warning (OPT_Wparentheses
,
10337 "suggest parentheses around arithmetic in operand of %<|%>");
10338 /* Check cases like x|y==z */
10339 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
10340 || TREE_CODE_CLASS (code_right
) == tcc_comparison
)
10341 warning (OPT_Wparentheses
,
10342 "suggest parentheses around comparison in operand of %<|%>");
10343 /* Check cases like !x | y */
10344 else if (code_left
== TRUTH_NOT_EXPR
10345 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
10346 warning (OPT_Wparentheses
, "suggest parentheses around operand of "
10347 "%<!%> or change %<|%> to %<||%> or %<!%> to %<~%>");
10351 if (code_left
== BIT_AND_EXPR
10352 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
10353 || code_right
== BIT_AND_EXPR
10354 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
10355 warning (OPT_Wparentheses
,
10356 "suggest parentheses around arithmetic in operand of %<^%>");
10357 /* Check cases like x^y==z */
10358 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
10359 || TREE_CODE_CLASS (code_right
) == tcc_comparison
)
10360 warning (OPT_Wparentheses
,
10361 "suggest parentheses around comparison in operand of %<^%>");
10365 if (code_left
== PLUS_EXPR
|| code_right
== PLUS_EXPR
)
10366 warning (OPT_Wparentheses
,
10367 "suggest parentheses around %<+%> in operand of %<&%>");
10368 else if (code_left
== MINUS_EXPR
|| code_right
== MINUS_EXPR
)
10369 warning (OPT_Wparentheses
,
10370 "suggest parentheses around %<-%> in operand of %<&%>");
10371 /* Check cases like x&y==z */
10372 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
10373 || TREE_CODE_CLASS (code_right
) == tcc_comparison
)
10374 warning (OPT_Wparentheses
,
10375 "suggest parentheses around comparison in operand of %<&%>");
10376 /* Check cases like !x & y */
10377 else if (code_left
== TRUTH_NOT_EXPR
10378 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
10379 warning (OPT_Wparentheses
, "suggest parentheses around operand of "
10380 "%<!%> or change %<&%> to %<&&%> or %<!%> to %<~%>");
10384 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
10385 || TREE_CODE_CLASS (code_right
) == tcc_comparison
)
10386 warning (OPT_Wparentheses
,
10387 "suggest parentheses around comparison in operand of %<==%>");
10390 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
10391 || TREE_CODE_CLASS (code_right
) == tcc_comparison
)
10392 warning (OPT_Wparentheses
,
10393 "suggest parentheses around comparison in operand of %<!=%>");
10397 if (TREE_CODE_CLASS (code
) == tcc_comparison
10398 && ((TREE_CODE_CLASS (code_left
) == tcc_comparison
10399 && code_left
!= NE_EXPR
&& code_left
!= EQ_EXPR
10400 && INTEGRAL_TYPE_P (TREE_TYPE (arg_left
)))
10401 || (TREE_CODE_CLASS (code_right
) == tcc_comparison
10402 && code_right
!= NE_EXPR
&& code_right
!= EQ_EXPR
10403 && INTEGRAL_TYPE_P (TREE_TYPE (arg_right
)))))
10404 warning (OPT_Wparentheses
, "comparisons like %<X<=Y<=Z%> do not "
10405 "have their mathematical meaning");
10408 #undef NOT_A_BOOLEAN_EXPR_P
10411 /* If LABEL (a LABEL_DECL) has not been used, issue a warning. */
10414 warn_for_unused_label (tree label
)
10416 if (!TREE_USED (label
))
10418 if (DECL_INITIAL (label
))
10419 warning (OPT_Wunused_label
, "label %q+D defined but not used", label
);
10421 warning (OPT_Wunused_label
, "label %q+D declared but not defined", label
);
10425 /* Warn for division by zero according to the value of DIVISOR. LOC
10426 is the location of the division operator. */
10429 warn_for_div_by_zero (location_t loc
, tree divisor
)
10431 /* If DIVISOR is zero, and has integral or fixed-point type, issue a warning
10432 about division by zero. Do not issue a warning if DIVISOR has a
10433 floating-point type, since we consider 0.0/0.0 a valid way of
10434 generating a NaN. */
10435 if (c_inhibit_evaluation_warnings
== 0
10436 && (integer_zerop (divisor
) || fixed_zerop (divisor
)))
10437 warning_at (loc
, OPT_Wdiv_by_zero
, "division by zero");
10440 /* Subroutine of build_binary_op. Give warnings for comparisons
10441 between signed and unsigned quantities that may fail. Do the
10442 checking based on the original operand trees ORIG_OP0 and ORIG_OP1,
10443 so that casts will be considered, but default promotions won't
10446 LOCATION is the location of the comparison operator.
10448 The arguments of this function map directly to local variables
10449 of build_binary_op. */
10452 warn_for_sign_compare (location_t location
,
10453 tree orig_op0
, tree orig_op1
,
10454 tree op0
, tree op1
,
10455 tree result_type
, enum tree_code resultcode
)
10457 int op0_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op0
));
10458 int op1_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op1
));
10459 int unsignedp0
, unsignedp1
;
10461 /* In C++, check for comparison of different enum types. */
10462 if (c_dialect_cxx()
10463 && TREE_CODE (TREE_TYPE (orig_op0
)) == ENUMERAL_TYPE
10464 && TREE_CODE (TREE_TYPE (orig_op1
)) == ENUMERAL_TYPE
10465 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0
))
10466 != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1
)))
10468 warning_at (location
,
10469 OPT_Wsign_compare
, "comparison between types %qT and %qT",
10470 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
));
10473 /* Do not warn if the comparison is being done in a signed type,
10474 since the signed type will only be chosen if it can represent
10475 all the values of the unsigned type. */
10476 if (!TYPE_UNSIGNED (result_type
))
10478 /* Do not warn if both operands are unsigned. */
10479 else if (op0_signed
== op1_signed
)
10483 tree sop
, uop
, base_type
;
10487 sop
= orig_op0
, uop
= orig_op1
;
10489 sop
= orig_op1
, uop
= orig_op0
;
10491 STRIP_TYPE_NOPS (sop
);
10492 STRIP_TYPE_NOPS (uop
);
10493 base_type
= (TREE_CODE (result_type
) == COMPLEX_TYPE
10494 ? TREE_TYPE (result_type
) : result_type
);
10496 /* Do not warn if the signed quantity is an unsuffixed integer
10497 literal (or some static constant expression involving such
10498 literals or a conditional expression involving such literals)
10499 and it is non-negative. */
10500 if (tree_expr_nonnegative_warnv_p (sop
, &ovf
))
10502 /* Do not warn if the comparison is an equality operation, the
10503 unsigned quantity is an integral constant, and it would fit
10504 in the result if the result were signed. */
10505 else if (TREE_CODE (uop
) == INTEGER_CST
10506 && (resultcode
== EQ_EXPR
|| resultcode
== NE_EXPR
)
10507 && int_fits_type_p (uop
, c_common_signed_type (base_type
)))
10509 /* In C, do not warn if the unsigned quantity is an enumeration
10510 constant and its maximum value would fit in the result if the
10511 result were signed. */
10512 else if (!c_dialect_cxx() && TREE_CODE (uop
) == INTEGER_CST
10513 && TREE_CODE (TREE_TYPE (uop
)) == ENUMERAL_TYPE
10514 && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (uop
)),
10515 c_common_signed_type (base_type
)))
10518 warning_at (location
,
10520 "comparison between signed and unsigned integer expressions");
10523 /* Warn if two unsigned values are being compared in a size larger
10524 than their original size, and one (and only one) is the result of
10525 a `~' operator. This comparison will always fail.
10527 Also warn if one operand is a constant, and the constant does not
10528 have all bits set that are set in the ~ operand when it is
10531 op0
= c_common_get_narrower (op0
, &unsignedp0
);
10532 op1
= c_common_get_narrower (op1
, &unsignedp1
);
10534 if ((TREE_CODE (op0
) == BIT_NOT_EXPR
)
10535 ^ (TREE_CODE (op1
) == BIT_NOT_EXPR
))
10537 if (TREE_CODE (op0
) == BIT_NOT_EXPR
)
10538 op0
= c_common_get_narrower (TREE_OPERAND (op0
, 0), &unsignedp0
);
10539 if (TREE_CODE (op1
) == BIT_NOT_EXPR
)
10540 op1
= c_common_get_narrower (TREE_OPERAND (op1
, 0), &unsignedp1
);
10542 if (host_integerp (op0
, 0) || host_integerp (op1
, 0))
10545 HOST_WIDE_INT constant
, mask
;
10549 if (host_integerp (op0
, 0))
10552 unsignedp
= unsignedp1
;
10553 constant
= tree_low_cst (op0
, 0);
10558 unsignedp
= unsignedp0
;
10559 constant
= tree_low_cst (op1
, 0);
10562 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
10563 if (bits
< TYPE_PRECISION (result_type
)
10564 && bits
< HOST_BITS_PER_LONG
&& unsignedp
)
10566 mask
= (~ (HOST_WIDE_INT
) 0) << bits
;
10567 if ((mask
& constant
) != mask
)
10570 warning (OPT_Wsign_compare
,
10571 "promoted ~unsigned is always non-zero");
10573 warning_at (location
, OPT_Wsign_compare
,
10574 "comparison of promoted ~unsigned with constant");
10578 else if (unsignedp0
&& unsignedp1
10579 && (TYPE_PRECISION (TREE_TYPE (op0
))
10580 < TYPE_PRECISION (result_type
))
10581 && (TYPE_PRECISION (TREE_TYPE (op1
))
10582 < TYPE_PRECISION (result_type
)))
10583 warning_at (location
, OPT_Wsign_compare
,
10584 "comparison of promoted ~unsigned with unsigned");
10588 /* RESULT_TYPE is the result of converting TYPE1 and TYPE2 to a common
10589 type via c_common_type. If -Wdouble-promotion is in use, and the
10590 conditions for warning have been met, issue a warning. GMSGID is
10591 the warning message. It must have two %T specifiers for the type
10592 that was converted (generally "float") and the type to which it was
10593 converted (generally "double), respectively. LOC is the location
10594 to which the awrning should refer. */
10597 do_warn_double_promotion (tree result_type
, tree type1
, tree type2
,
10598 const char *gmsgid
, location_t loc
)
10602 if (!warn_double_promotion
)
10604 /* If the conversion will not occur at run-time, there is no need to
10606 if (c_inhibit_evaluation_warnings
)
10608 if (TYPE_MAIN_VARIANT (result_type
) != double_type_node
10609 && TYPE_MAIN_VARIANT (result_type
) != complex_double_type_node
)
10611 if (TYPE_MAIN_VARIANT (type1
) == float_type_node
10612 || TYPE_MAIN_VARIANT (type1
) == complex_float_type_node
)
10613 source_type
= type1
;
10614 else if (TYPE_MAIN_VARIANT (type2
) == float_type_node
10615 || TYPE_MAIN_VARIANT (type2
) == complex_float_type_node
)
10616 source_type
= type2
;
10619 warning_at (loc
, OPT_Wdouble_promotion
, gmsgid
, source_type
, result_type
);
10622 /* Setup a TYPE_DECL node as a typedef representation.
10624 X is a TYPE_DECL for a typedef statement. Create a brand new
10625 ..._TYPE node (which will be just a variant of the existing
10626 ..._TYPE node with identical properties) and then install X
10627 as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
10629 The whole point here is to end up with a situation where each
10630 and every ..._TYPE node the compiler creates will be uniquely
10631 associated with AT MOST one node representing a typedef name.
10632 This way, even though the compiler substitutes corresponding
10633 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
10634 early on, later parts of the compiler can always do the reverse
10635 translation and get back the corresponding typedef name. For
10638 typedef struct S MY_TYPE;
10641 Later parts of the compiler might only know that `object' was of
10642 type `struct S' if it were not for code just below. With this
10643 code however, later parts of the compiler see something like:
10645 struct S' == struct S
10646 typedef struct S' MY_TYPE;
10649 And they can then deduce (from the node for type struct S') that
10650 the original object declaration was:
10654 Being able to do this is important for proper support of protoize,
10655 and also for generating precise symbolic debugging information
10656 which takes full account of the programmer's (typedef) vocabulary.
10658 Obviously, we don't want to generate a duplicate ..._TYPE node if
10659 the TYPE_DECL node that we are now processing really represents a
10660 standard built-in type. */
10663 set_underlying_type (tree x
)
10665 if (x
== error_mark_node
)
10667 if (DECL_IS_BUILTIN (x
))
10669 if (TYPE_NAME (TREE_TYPE (x
)) == 0)
10670 TYPE_NAME (TREE_TYPE (x
)) = x
;
10672 else if (TREE_TYPE (x
) != error_mark_node
10673 && DECL_ORIGINAL_TYPE (x
) == NULL_TREE
)
10675 tree tt
= TREE_TYPE (x
);
10676 DECL_ORIGINAL_TYPE (x
) = tt
;
10677 tt
= build_variant_type_copy (tt
);
10678 TYPE_STUB_DECL (tt
) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x
));
10679 TYPE_NAME (tt
) = x
;
10680 TREE_USED (tt
) = TREE_USED (x
);
10681 TREE_TYPE (x
) = tt
;
10685 /* Record the types used by the current global variable declaration
10686 being parsed, so that we can decide later to emit their debug info.
10687 Those types are in types_used_by_cur_var_decl, and we are going to
10688 store them in the types_used_by_vars_hash hash table.
10689 DECL is the declaration of the global variable that has been parsed. */
10692 record_types_used_by_current_var_decl (tree decl
)
10694 gcc_assert (decl
&& DECL_P (decl
) && TREE_STATIC (decl
));
10696 while (!VEC_empty (tree
, types_used_by_cur_var_decl
))
10698 tree type
= VEC_pop (tree
, types_used_by_cur_var_decl
);
10699 types_used_by_var_decl_insert (type
, decl
);
10703 /* If DECL is a typedef that is declared in the current function,
10704 record it for the purpose of -Wunused-local-typedefs. */
10707 record_locally_defined_typedef (tree decl
)
10709 struct c_language_function
*l
;
10711 if (!warn_unused_local_typedefs
10713 /* if this is not a locally defined typedef then we are not
10715 || !is_typedef_decl (decl
)
10716 || !decl_function_context (decl
))
10719 l
= (struct c_language_function
*) cfun
->language
;
10720 VEC_safe_push (tree
, gc
, l
->local_typedefs
, decl
);
10723 /* If T is a TYPE_DECL declared locally, mark it as used. */
10726 maybe_record_typedef_use (tree t
)
10728 if (!is_typedef_decl (t
))
10731 TREE_USED (t
) = true;
10734 /* Warn if there are some unused locally defined typedefs in the
10735 current function. */
10738 maybe_warn_unused_local_typedefs (void)
10742 /* The number of times we have emitted -Wunused-local-typedefs
10743 warnings. If this is different from errorcount, that means some
10744 unrelated errors have been issued. In which case, we'll avoid
10745 emitting "unused-local-typedefs" warnings. */
10746 static int unused_local_typedefs_warn_count
;
10747 struct c_language_function
*l
;
10752 if ((l
= (struct c_language_function
*) cfun
->language
) == NULL
)
10755 if (warn_unused_local_typedefs
10756 && errorcount
== unused_local_typedefs_warn_count
)
10758 FOR_EACH_VEC_ELT (tree
, l
->local_typedefs
, i
, decl
)
10759 if (!TREE_USED (decl
))
10760 warning_at (DECL_SOURCE_LOCATION (decl
),
10761 OPT_Wunused_local_typedefs
,
10762 "typedef %qD locally defined but not used", decl
);
10763 unused_local_typedefs_warn_count
= errorcount
;
10766 if (l
->local_typedefs
)
10768 VEC_free (tree
, gc
, l
->local_typedefs
);
10769 l
->local_typedefs
= NULL
;
10773 /* The C and C++ parsers both use vectors to hold function arguments.
10774 For efficiency, we keep a cache of unused vectors. This is the
10777 typedef VEC(tree
,gc
)* tree_gc_vec
;
10778 DEF_VEC_P(tree_gc_vec
);
10779 DEF_VEC_ALLOC_P(tree_gc_vec
,gc
);
10780 static GTY((deletable
)) VEC(tree_gc_vec
,gc
) *tree_vector_cache
;
10782 /* Return a new vector from the cache. If the cache is empty,
10783 allocate a new vector. These vectors are GC'ed, so it is OK if the
10784 pointer is not released.. */
10787 make_tree_vector (void)
10789 if (!VEC_empty (tree_gc_vec
, tree_vector_cache
))
10790 return VEC_pop (tree_gc_vec
, tree_vector_cache
);
10793 /* Passing 0 to VEC_alloc returns NULL, and our callers require
10794 that we always return a non-NULL value. The vector code uses
10795 4 when growing a NULL vector, so we do too. */
10796 return VEC_alloc (tree
, gc
, 4);
10800 /* Release a vector of trees back to the cache. */
10803 release_tree_vector (VEC(tree
,gc
) *vec
)
10807 VEC_truncate (tree
, vec
, 0);
10808 VEC_safe_push (tree_gc_vec
, gc
, tree_vector_cache
, vec
);
10812 /* Get a new tree vector holding a single tree. */
10815 make_tree_vector_single (tree t
)
10817 VEC(tree
,gc
) *ret
= make_tree_vector ();
10818 VEC_quick_push (tree
, ret
, t
);
10822 /* Get a new tree vector of the TREE_VALUEs of a TREE_LIST chain. */
10825 make_tree_vector_from_list (tree list
)
10827 VEC(tree
,gc
) *ret
= make_tree_vector ();
10828 for (; list
; list
= TREE_CHAIN (list
))
10829 VEC_safe_push (tree
, gc
, ret
, TREE_VALUE (list
));
10833 /* Get a new tree vector which is a copy of an existing one. */
10836 make_tree_vector_copy (const VEC(tree
,gc
) *orig
)
10842 ret
= make_tree_vector ();
10843 VEC_reserve (tree
, gc
, ret
, VEC_length (tree
, orig
));
10844 FOR_EACH_VEC_ELT (tree
, orig
, ix
, t
)
10845 VEC_quick_push (tree
, ret
, t
);
10849 /* Return true if KEYWORD starts a type specifier. */
10852 keyword_begins_type_specifier (enum rid keyword
)
10868 case RID_DFLOAT128
:
10888 /* Return true if KEYWORD names a type qualifier. */
10891 keyword_is_type_qualifier (enum rid keyword
)
10904 /* Return true if KEYWORD names a storage class specifier.
10906 RID_TYPEDEF is not included in this list despite `typedef' being
10907 listed in C99 6.7.1.1. 6.7.1.3 indicates that `typedef' is listed as
10908 such for syntactic convenience only. */
10911 keyword_is_storage_class_specifier (enum rid keyword
)
10927 /* Return true if KEYWORD names a function-specifier [dcl.fct.spec]. */
10930 keyword_is_function_specifier (enum rid keyword
)
10944 /* Return true if KEYWORD names a decl-specifier [dcl.spec] or a
10945 declaration-specifier (C99 6.7). */
10948 keyword_is_decl_specifier (enum rid keyword
)
10950 if (keyword_is_storage_class_specifier (keyword
)
10951 || keyword_is_type_qualifier (keyword
)
10952 || keyword_is_function_specifier (keyword
))
10959 case RID_CONSTEXPR
:
10966 /* Initialize language-specific-bits of tree_contains_struct. */
10969 c_common_init_ts (void)
10971 MARK_TS_TYPED (C_MAYBE_CONST_EXPR
);
10972 MARK_TS_TYPED (EXCESS_PRECISION_EXPR
);
10975 /* Build a user-defined numeric literal out of an integer constant type VALUE
10976 with identifier SUFFIX. */
10979 build_userdef_literal (tree suffix_id
, tree value
, tree num_string
)
10981 tree literal
= make_node (USERDEF_LITERAL
);
10982 USERDEF_LITERAL_SUFFIX_ID (literal
) = suffix_id
;
10983 USERDEF_LITERAL_VALUE (literal
) = value
;
10984 USERDEF_LITERAL_NUM_STRING (literal
) = num_string
;
10988 /* For vector[index], convert the vector to a
10989 pointer of the underlying type. */
10991 convert_vector_to_pointer_for_subscript (location_t loc
,
10992 tree
* vecp
, tree index
)
10994 if (TREE_CODE (TREE_TYPE (*vecp
)) == VECTOR_TYPE
)
10996 tree type
= TREE_TYPE (*vecp
);
10999 if (TREE_CODE (index
) == INTEGER_CST
)
11000 if (!host_integerp (index
, 1)
11001 || ((unsigned HOST_WIDE_INT
) tree_low_cst (index
, 1)
11002 >= TYPE_VECTOR_SUBPARTS (type
)))
11003 warning_at (loc
, OPT_Warray_bounds
, "index value is out of bound");
11005 c_common_mark_addressable_vec (*vecp
);
11006 type
= build_qualified_type (TREE_TYPE (type
), TYPE_QUALS (type
));
11007 type
= build_pointer_type (type
);
11008 type1
= build_pointer_type (TREE_TYPE (*vecp
));
11009 *vecp
= build1 (ADDR_EXPR
, type1
, *vecp
);
11010 *vecp
= convert (type
, *vecp
);
11014 #include "gt-c-family-c-common.h"