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
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/>. */
22 /* FIXME: Still need to include rtl.h here (via expr.h) in a front-end file.
23 Pretend this is a back-end file. */
24 #undef IN_GCC_FRONTEND
28 #include "coretypes.h"
41 #include "langhooks.h"
42 #include "tree-inline.h"
45 #include "diagnostic.h"
46 #include "tree-iterator.h"
48 #include "tree-mudflap.h"
51 #include "target-def.h"
54 #include "expr.h" /* For vector_mode_valid_p */
56 /* FIXME: Needed for TARGET_ENUM_VA_LIST, which should be a target hook. */
59 cpp_reader
*parse_in
; /* Declared in c-pragma.h. */
61 /* The following symbols are subsumed in the c_global_trees array, and
62 listed here individually for documentation purposes.
64 INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
66 tree short_integer_type_node;
67 tree long_integer_type_node;
68 tree long_long_integer_type_node;
69 tree int128_integer_type_node;
71 tree short_unsigned_type_node;
72 tree long_unsigned_type_node;
73 tree long_long_unsigned_type_node;
74 tree int128_unsigned_type_node;
76 tree truthvalue_type_node;
77 tree truthvalue_false_node;
78 tree truthvalue_true_node;
80 tree ptrdiff_type_node;
82 tree unsigned_char_type_node;
83 tree signed_char_type_node;
86 tree char16_type_node;
87 tree char32_type_node;
90 tree double_type_node;
91 tree long_double_type_node;
93 tree complex_integer_type_node;
94 tree complex_float_type_node;
95 tree complex_double_type_node;
96 tree complex_long_double_type_node;
98 tree dfloat32_type_node;
99 tree dfloat64_type_node;
100 tree_dfloat128_type_node;
102 tree intQI_type_node;
103 tree intHI_type_node;
104 tree intSI_type_node;
105 tree intDI_type_node;
106 tree intTI_type_node;
108 tree unsigned_intQI_type_node;
109 tree unsigned_intHI_type_node;
110 tree unsigned_intSI_type_node;
111 tree unsigned_intDI_type_node;
112 tree unsigned_intTI_type_node;
114 tree widest_integer_literal_type_node;
115 tree widest_unsigned_literal_type_node;
117 Nodes for types `void *' and `const void *'.
119 tree ptr_type_node, const_ptr_type_node;
121 Nodes for types `char *' and `const char *'.
123 tree string_type_node, const_string_type_node;
125 Type `char[SOMENUMBER]'.
126 Used when an array of char is needed and the size is irrelevant.
128 tree char_array_type_node;
130 Type `int[SOMENUMBER]' or something like it.
131 Used when an array of int needed and the size is irrelevant.
133 tree int_array_type_node;
135 Type `wchar_t[SOMENUMBER]' or something like it.
136 Used when a wide string literal is created.
138 tree wchar_array_type_node;
140 Type `char16_t[SOMENUMBER]' or something like it.
141 Used when a UTF-16 string literal is created.
143 tree char16_array_type_node;
145 Type `char32_t[SOMENUMBER]' or something like it.
146 Used when a UTF-32 string literal is created.
148 tree char32_array_type_node;
150 Type `int ()' -- used for implicit declaration of functions.
152 tree default_function_type;
154 A VOID_TYPE node, packaged in a TREE_LIST.
158 The lazily created VAR_DECLs for __FUNCTION__, __PRETTY_FUNCTION__,
159 and __func__. (C doesn't generate __FUNCTION__ and__PRETTY_FUNCTION__
160 VAR_DECLS, but C++ does.)
162 tree function_name_decl_node;
163 tree pretty_function_name_decl_node;
164 tree c99_function_name_decl_node;
166 Stack of nested function name VAR_DECLs.
168 tree saved_function_name_decls;
172 tree c_global_trees
[CTI_MAX
];
174 /* Switches common to the C front ends. */
176 /* Nonzero if preprocessing only. */
178 int flag_preprocess_only
;
180 /* Nonzero means don't output line number information. */
182 char flag_no_line_commands
;
184 /* Nonzero causes -E output not to be done, but directives such as
185 #define that have side effects are still obeyed. */
189 /* Nonzero means dump macros in some fashion. */
191 char flag_dump_macros
;
193 /* Nonzero means pass #include lines through to the output. */
195 char flag_dump_includes
;
197 /* Nonzero means process PCH files while preprocessing. */
199 bool flag_pch_preprocess
;
201 /* The file name to which we should write a precompiled header, or
202 NULL if no header will be written in this compile. */
204 const char *pch_file
;
206 /* Nonzero if an ISO standard was selected. It rejects macros in the
210 /* Nonzero if -undef was given. It suppresses target built-in macros
214 /* Nonzero means don't recognize the non-ANSI builtin functions. */
218 /* Nonzero means don't recognize the non-ANSI builtin functions.
221 int flag_no_nonansi_builtin
;
223 /* Nonzero means give `double' the same size as `float'. */
225 int flag_short_double
;
227 /* Nonzero means give `wchar_t' the same size as `short'. */
229 int flag_short_wchar
;
231 /* Nonzero means allow implicit conversions between vectors with
232 differing numbers of subparts and/or differing element types. */
233 int flag_lax_vector_conversions
;
235 /* Nonzero means allow Microsoft extensions without warnings or errors. */
236 int flag_ms_extensions
;
238 /* Nonzero means don't recognize the keyword `asm'. */
242 /* Nonzero means to treat bitfields as signed unless they say `unsigned'. */
244 int flag_signed_bitfields
= 1;
246 /* Warn about #pragma directives that are not recognized. */
248 int warn_unknown_pragmas
; /* Tri state variable. */
250 /* Warn about format/argument anomalies in calls to formatted I/O functions
251 (*printf, *scanf, strftime, strfmon, etc.). */
255 /* Warn about using __null (as NULL in C++) as sentinel. For code compiled
256 with GCC this doesn't matter as __null is guaranteed to have the right
259 int warn_strict_null_sentinel
;
261 /* Zero means that faster, ...NonNil variants of objc_msgSend...
262 calls will be used in ObjC; passing nil receivers to such calls
263 will most likely result in crashes. */
264 int flag_nil_receivers
= 1;
266 /* Nonzero means that code generation will be altered to support
267 "zero-link" execution. This currently affects ObjC only, but may
268 affect other languages in the future. */
269 int flag_zero_link
= 0;
271 /* Nonzero means emit an '__OBJC, __image_info' for the current translation
272 unit. It will inform the ObjC runtime that class definition(s) herein
273 contained are to replace one(s) previously loaded. */
274 int flag_replace_objc_classes
= 0;
276 /* C/ObjC language option variables. */
279 /* Nonzero means allow type mismatches in conditional expressions;
280 just make their values `void'. */
282 int flag_cond_mismatch
;
284 /* Nonzero means enable C89 Amendment 1 features. */
288 /* Nonzero means use the ISO C99 (or C1X) dialect of C. */
292 /* Nonzero means use the ISO C1X dialect of C. */
296 /* Nonzero means that we have builtin functions, and main is an int. */
301 /* ObjC language option variables. */
304 /* Open and close the file for outputting class declarations, if
307 int flag_gen_declaration
;
309 /* Tells the compiler that this is a special run. Do not perform any
310 compiling, instead we are to test some platform dependent features
311 and output a C header file with appropriate definitions. */
313 int print_struct_values
;
315 /* Tells the compiler what is the constant string class for ObjC. */
317 const char *constant_string_class_name
;
320 /* C++ language option variables. */
323 /* Nonzero means don't recognize any extension keywords. */
325 int flag_no_gnu_keywords
;
327 /* Nonzero means do emit exported implementations of functions even if
328 they can be inlined. */
330 int flag_implement_inlines
= 1;
332 /* Nonzero means that implicit instantiations will be emitted if needed. */
334 int flag_implicit_templates
= 1;
336 /* Nonzero means that implicit instantiations of inline templates will be
337 emitted if needed, even if instantiations of non-inline templates
340 int flag_implicit_inline_templates
= 1;
342 /* Nonzero means generate separate instantiation control files and
343 juggle them at link time. */
345 int flag_use_repository
;
347 /* Nonzero if we want to issue diagnostics that the standard says are not
350 int flag_optional_diags
= 1;
352 /* Nonzero means we should attempt to elide constructors when possible. */
354 int flag_elide_constructors
= 1;
356 /* Nonzero means that member functions defined in class scope are
357 inline by default. */
359 int flag_default_inline
= 1;
361 /* Controls whether compiler generates 'type descriptor' that give
362 run-time type information. */
366 /* Nonzero if we want to conserve space in the .o files. We do this
367 by putting uninitialized data and runtime initialized data into
368 .common instead of .data at the expense of not flagging multiple
371 int flag_conserve_space
;
373 /* Nonzero if we want to obey access control semantics. */
375 int flag_access_control
= 1;
377 /* Nonzero if we want to check the return value of new and avoid calling
378 constructors if it is a null pointer. */
382 /* The C++ dialect being used. C++98 is the default. */
384 enum cxx_dialect cxx_dialect
= cxx98
;
386 /* Nonzero if we want the new ISO rules for pushing a new scope for `for'
387 initialization variables.
388 0: Old rules, set by -fno-for-scope.
389 2: New ISO rules, set by -ffor-scope.
390 1: Try to implement new ISO rules, but with backup compatibility
391 (and warnings). This is the default, for now. */
393 int flag_new_for_scope
= 1;
395 /* Nonzero if we want to emit defined symbols with common-like linkage as
396 weak symbols where possible, in order to conform to C++ semantics.
397 Otherwise, emit them as local symbols. */
401 /* 0 means we want the preprocessor to not emit line directives for
402 the current working directory. 1 means we want it to do it. -1
403 means we should decide depending on whether debugging information
404 is being emitted or not. */
406 int flag_working_directory
= -1;
408 /* Nonzero to use __cxa_atexit, rather than atexit, to register
409 destructors for local statics and global objects. '2' means it has been
410 set nonzero as a default, not by a command-line flag. */
412 int flag_use_cxa_atexit
= DEFAULT_USE_CXA_ATEXIT
;
414 /* Nonzero to use __cxa_get_exception_ptr in C++ exception-handling
415 code. '2' means it has not been set explicitly on the command line. */
417 int flag_use_cxa_get_exception_ptr
= 2;
419 /* Nonzero means to implement standard semantics for exception
420 specifications, calling unexpected if an exception is thrown that
421 doesn't match the specification. Zero means to treat them as
422 assertions and optimize accordingly, but not check them. */
424 int flag_enforce_eh_specs
= 1;
426 /* Nonzero means to generate thread-safe code for initializing local
429 int flag_threadsafe_statics
= 1;
431 /* Nonzero if we want to pretty-print template specializations as the
432 template signature followed by the arguments. */
434 int flag_pretty_templates
= 1;
436 /* Maximum template instantiation depth. This limit exists to limit the
437 time it takes to notice infinite template instantiations; the default
438 value of 1024 is likely to be in the next C++ standard. */
440 int max_tinst_depth
= 1024;
444 /* The elements of `ridpointers' are identifier nodes for the reserved
445 type names and storage classes. It is indexed by a RID_... value. */
448 tree (*make_fname_decl
) (location_t
, tree
, int);
450 /* Nonzero means don't warn about problems that occur when the code is
452 int c_inhibit_evaluation_warnings
;
454 /* Whether lexing has been completed, so subsequent preprocessor
455 errors should use the compiler's input_location. */
456 bool done_lexing
= false;
458 /* Information about how a function name is generated. */
461 tree
*const decl
; /* pointer to the VAR_DECL. */
462 const unsigned rid
; /* RID number for the identifier. */
463 const int pretty
; /* How pretty is it? */
466 /* The three ways of getting then name of the current function. */
468 const struct fname_var_t fname_vars
[] =
470 /* C99 compliant __func__, must be first. */
471 {&c99_function_name_decl_node
, RID_C99_FUNCTION_NAME
, 0},
472 /* GCC __FUNCTION__ compliant. */
473 {&function_name_decl_node
, RID_FUNCTION_NAME
, 0},
474 /* GCC __PRETTY_FUNCTION__ compliant. */
475 {&pretty_function_name_decl_node
, RID_PRETTY_FUNCTION_NAME
, 1},
479 static tree
c_fully_fold_internal (tree expr
, bool, bool *, bool *);
480 static tree
check_case_value (tree
);
481 static bool check_case_bounds (tree
, tree
, tree
*, tree
*);
483 static tree
handle_packed_attribute (tree
*, tree
, tree
, int, bool *);
484 static tree
handle_nocommon_attribute (tree
*, tree
, tree
, int, bool *);
485 static tree
handle_common_attribute (tree
*, tree
, tree
, int, bool *);
486 static tree
handle_noreturn_attribute (tree
*, tree
, tree
, int, bool *);
487 static tree
handle_hot_attribute (tree
*, tree
, tree
, int, bool *);
488 static tree
handle_cold_attribute (tree
*, tree
, tree
, int, bool *);
489 static tree
handle_noinline_attribute (tree
*, tree
, tree
, int, bool *);
490 static tree
handle_noclone_attribute (tree
*, tree
, tree
, int, bool *);
491 static tree
handle_always_inline_attribute (tree
*, tree
, tree
, int,
493 static tree
handle_gnu_inline_attribute (tree
*, tree
, tree
, int, bool *);
494 static tree
handle_artificial_attribute (tree
*, tree
, tree
, int, bool *);
495 static tree
handle_flatten_attribute (tree
*, tree
, tree
, int, bool *);
496 static tree
handle_error_attribute (tree
*, tree
, tree
, int, bool *);
497 static tree
handle_used_attribute (tree
*, tree
, tree
, int, bool *);
498 static tree
handle_unused_attribute (tree
*, tree
, tree
, int, bool *);
499 static tree
handle_externally_visible_attribute (tree
*, tree
, tree
, int,
501 static tree
handle_const_attribute (tree
*, tree
, tree
, int, bool *);
502 static tree
handle_transparent_union_attribute (tree
*, tree
, tree
,
504 static tree
handle_constructor_attribute (tree
*, tree
, tree
, int, bool *);
505 static tree
handle_destructor_attribute (tree
*, tree
, tree
, int, bool *);
506 static tree
handle_mode_attribute (tree
*, tree
, tree
, int, bool *);
507 static tree
handle_section_attribute (tree
*, tree
, tree
, int, bool *);
508 static tree
handle_aligned_attribute (tree
*, tree
, tree
, int, bool *);
509 static tree
handle_weak_attribute (tree
*, tree
, tree
, int, bool *) ;
510 static tree
handle_alias_attribute (tree
*, tree
, tree
, int, bool *);
511 static tree
handle_weakref_attribute (tree
*, tree
, tree
, int, bool *) ;
512 static tree
handle_visibility_attribute (tree
*, tree
, tree
, int,
514 static tree
handle_tls_model_attribute (tree
*, tree
, tree
, int,
516 static tree
handle_no_instrument_function_attribute (tree
*, tree
,
518 static tree
handle_malloc_attribute (tree
*, tree
, tree
, int, bool *);
519 static tree
handle_returns_twice_attribute (tree
*, tree
, tree
, int, bool *);
520 static tree
handle_no_limit_stack_attribute (tree
*, tree
, tree
, int,
522 static tree
handle_pure_attribute (tree
*, tree
, tree
, int, bool *);
523 static tree
handle_novops_attribute (tree
*, tree
, tree
, int, bool *);
524 static tree
handle_deprecated_attribute (tree
*, tree
, tree
, int,
526 static tree
handle_vector_size_attribute (tree
*, tree
, tree
, int,
528 static tree
handle_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
529 static tree
handle_nothrow_attribute (tree
*, tree
, tree
, int, bool *);
530 static tree
handle_cleanup_attribute (tree
*, tree
, tree
, int, bool *);
531 static tree
handle_warn_unused_result_attribute (tree
*, tree
, tree
, int,
533 static tree
handle_sentinel_attribute (tree
*, tree
, tree
, int, bool *);
534 static tree
handle_type_generic_attribute (tree
*, tree
, tree
, int, bool *);
535 static tree
handle_alloc_size_attribute (tree
*, tree
, tree
, int, bool *);
536 static tree
handle_target_attribute (tree
*, tree
, tree
, int, bool *);
537 static tree
handle_optimize_attribute (tree
*, tree
, tree
, int, bool *);
538 static tree
handle_fnspec_attribute (tree
*, tree
, tree
, int, bool *);
540 static void check_function_nonnull (tree
, int, tree
*);
541 static void check_nonnull_arg (void *, tree
, unsigned HOST_WIDE_INT
);
542 static bool nonnull_check_p (tree
, unsigned HOST_WIDE_INT
);
543 static bool get_nonnull_operand (tree
, unsigned HOST_WIDE_INT
*);
544 static int resort_field_decl_cmp (const void *, const void *);
546 /* Reserved words. The third field is a mask: keywords are disabled
547 if they match the mask.
550 C --std=c89: D_C99 | D_CXXONLY | D_OBJC | D_CXX_OBJC
551 C --std=c99: D_CXXONLY | D_OBJC
552 ObjC is like C except that D_OBJC and D_CXX_OBJC are not set
553 C++ --std=c98: D_CONLY | D_CXXOX | D_OBJC
554 C++ --std=c0x: D_CONLY | D_OBJC
555 ObjC++ is like C++ except that D_OBJC is not set
557 If -fno-asm is used, D_ASM is added to the mask. If
558 -fno-gnu-keywords is used, D_EXT is added. If -fno-asm and C in
559 C89 mode, D_EXT89 is added for both -fno-asm and -fno-gnu-keywords.
560 In C with -Wc++-compat, we warn if D_CXXWARN is set. */
562 const struct c_common_resword c_common_reswords
[] =
564 { "_Bool", RID_BOOL
, D_CONLY
},
565 { "_Complex", RID_COMPLEX
, 0 },
566 { "_Imaginary", RID_IMAGINARY
, D_CONLY
},
567 { "_Decimal32", RID_DFLOAT32
, D_CONLY
| D_EXT
},
568 { "_Decimal64", RID_DFLOAT64
, D_CONLY
| D_EXT
},
569 { "_Decimal128", RID_DFLOAT128
, D_CONLY
| D_EXT
},
570 { "_Fract", RID_FRACT
, D_CONLY
| D_EXT
},
571 { "_Accum", RID_ACCUM
, D_CONLY
| D_EXT
},
572 { "_Sat", RID_SAT
, D_CONLY
| D_EXT
},
573 { "_Static_assert", RID_STATIC_ASSERT
, D_CONLY
},
574 { "__FUNCTION__", RID_FUNCTION_NAME
, 0 },
575 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME
, 0 },
576 { "__alignof", RID_ALIGNOF
, 0 },
577 { "__alignof__", RID_ALIGNOF
, 0 },
578 { "__asm", RID_ASM
, 0 },
579 { "__asm__", RID_ASM
, 0 },
580 { "__attribute", RID_ATTRIBUTE
, 0 },
581 { "__attribute__", RID_ATTRIBUTE
, 0 },
582 { "__builtin_choose_expr", RID_CHOOSE_EXPR
, D_CONLY
},
583 { "__builtin_offsetof", RID_OFFSETOF
, 0 },
584 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P
, D_CONLY
},
585 { "__builtin_va_arg", RID_VA_ARG
, 0 },
586 { "__complex", RID_COMPLEX
, 0 },
587 { "__complex__", RID_COMPLEX
, 0 },
588 { "__const", RID_CONST
, 0 },
589 { "__const__", RID_CONST
, 0 },
590 { "__decltype", RID_DECLTYPE
, D_CXXONLY
},
591 { "__extension__", RID_EXTENSION
, 0 },
592 { "__func__", RID_C99_FUNCTION_NAME
, 0 },
593 { "__has_nothrow_assign", RID_HAS_NOTHROW_ASSIGN
, D_CXXONLY
},
594 { "__has_nothrow_constructor", RID_HAS_NOTHROW_CONSTRUCTOR
, D_CXXONLY
},
595 { "__has_nothrow_copy", RID_HAS_NOTHROW_COPY
, D_CXXONLY
},
596 { "__has_trivial_assign", RID_HAS_TRIVIAL_ASSIGN
, D_CXXONLY
},
597 { "__has_trivial_constructor", RID_HAS_TRIVIAL_CONSTRUCTOR
, D_CXXONLY
},
598 { "__has_trivial_copy", RID_HAS_TRIVIAL_COPY
, D_CXXONLY
},
599 { "__has_trivial_destructor", RID_HAS_TRIVIAL_DESTRUCTOR
, D_CXXONLY
},
600 { "__has_virtual_destructor", RID_HAS_VIRTUAL_DESTRUCTOR
, D_CXXONLY
},
601 { "__int128", RID_INT128
, 0 },
602 { "__is_abstract", RID_IS_ABSTRACT
, D_CXXONLY
},
603 { "__is_base_of", RID_IS_BASE_OF
, D_CXXONLY
},
604 { "__is_class", RID_IS_CLASS
, D_CXXONLY
},
605 { "__is_convertible_to", RID_IS_CONVERTIBLE_TO
, D_CXXONLY
},
606 { "__is_empty", RID_IS_EMPTY
, D_CXXONLY
},
607 { "__is_enum", RID_IS_ENUM
, D_CXXONLY
},
608 { "__is_pod", RID_IS_POD
, D_CXXONLY
},
609 { "__is_polymorphic", RID_IS_POLYMORPHIC
, D_CXXONLY
},
610 { "__is_standard_layout", RID_IS_STD_LAYOUT
, D_CXXONLY
},
611 { "__is_trivial", RID_IS_TRIVIAL
, D_CXXONLY
},
612 { "__is_union", RID_IS_UNION
, D_CXXONLY
},
613 { "__imag", RID_IMAGPART
, 0 },
614 { "__imag__", RID_IMAGPART
, 0 },
615 { "__inline", RID_INLINE
, 0 },
616 { "__inline__", RID_INLINE
, 0 },
617 { "__label__", RID_LABEL
, 0 },
618 { "__null", RID_NULL
, 0 },
619 { "__real", RID_REALPART
, 0 },
620 { "__real__", RID_REALPART
, 0 },
621 { "__restrict", RID_RESTRICT
, 0 },
622 { "__restrict__", RID_RESTRICT
, 0 },
623 { "__signed", RID_SIGNED
, 0 },
624 { "__signed__", RID_SIGNED
, 0 },
625 { "__thread", RID_THREAD
, 0 },
626 { "__typeof", RID_TYPEOF
, 0 },
627 { "__typeof__", RID_TYPEOF
, 0 },
628 { "__volatile", RID_VOLATILE
, 0 },
629 { "__volatile__", RID_VOLATILE
, 0 },
630 { "alignof", RID_ALIGNOF
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
631 { "asm", RID_ASM
, D_ASM
},
632 { "auto", RID_AUTO
, 0 },
633 { "bool", RID_BOOL
, D_CXXONLY
| D_CXXWARN
},
634 { "break", RID_BREAK
, 0 },
635 { "case", RID_CASE
, 0 },
636 { "catch", RID_CATCH
, D_CXX_OBJC
| D_CXXWARN
},
637 { "char", RID_CHAR
, 0 },
638 { "char16_t", RID_CHAR16
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
639 { "char32_t", RID_CHAR32
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
640 { "class", RID_CLASS
, D_CXX_OBJC
| D_CXXWARN
},
641 { "const", RID_CONST
, 0 },
642 { "constexpr", RID_CONSTEXPR
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
643 { "const_cast", RID_CONSTCAST
, D_CXXONLY
| D_CXXWARN
},
644 { "continue", RID_CONTINUE
, 0 },
645 { "decltype", RID_DECLTYPE
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
646 { "default", RID_DEFAULT
, 0 },
647 { "delete", RID_DELETE
, D_CXXONLY
| D_CXXWARN
},
649 { "double", RID_DOUBLE
, 0 },
650 { "dynamic_cast", RID_DYNCAST
, D_CXXONLY
| D_CXXWARN
},
651 { "else", RID_ELSE
, 0 },
652 { "enum", RID_ENUM
, 0 },
653 { "explicit", RID_EXPLICIT
, D_CXXONLY
| D_CXXWARN
},
654 { "export", RID_EXPORT
, D_CXXONLY
| D_CXXWARN
},
655 { "extern", RID_EXTERN
, 0 },
656 { "false", RID_FALSE
, D_CXXONLY
| D_CXXWARN
},
657 { "float", RID_FLOAT
, 0 },
658 { "for", RID_FOR
, 0 },
659 { "friend", RID_FRIEND
, D_CXXONLY
| D_CXXWARN
},
660 { "goto", RID_GOTO
, 0 },
662 { "inline", RID_INLINE
, D_EXT89
},
663 { "int", RID_INT
, 0 },
664 { "long", RID_LONG
, 0 },
665 { "mutable", RID_MUTABLE
, D_CXXONLY
| D_CXXWARN
},
666 { "namespace", RID_NAMESPACE
, D_CXXONLY
| D_CXXWARN
},
667 { "new", RID_NEW
, D_CXXONLY
| D_CXXWARN
},
668 { "nullptr", RID_NULLPTR
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
669 { "operator", RID_OPERATOR
, D_CXXONLY
| D_CXXWARN
},
670 { "private", RID_PRIVATE
, D_CXX_OBJC
| D_CXXWARN
},
671 { "protected", RID_PROTECTED
, D_CXX_OBJC
| D_CXXWARN
},
672 { "public", RID_PUBLIC
, D_CXX_OBJC
| D_CXXWARN
},
673 { "register", RID_REGISTER
, 0 },
674 { "reinterpret_cast", RID_REINTCAST
, D_CXXONLY
| D_CXXWARN
},
675 { "restrict", RID_RESTRICT
, D_CONLY
| D_C99
},
676 { "return", RID_RETURN
, 0 },
677 { "short", RID_SHORT
, 0 },
678 { "signed", RID_SIGNED
, 0 },
679 { "sizeof", RID_SIZEOF
, 0 },
680 { "static", RID_STATIC
, 0 },
681 { "static_assert", RID_STATIC_ASSERT
, D_CXXONLY
| D_CXX0X
| D_CXXWARN
},
682 { "static_cast", RID_STATCAST
, D_CXXONLY
| D_CXXWARN
},
683 { "struct", RID_STRUCT
, 0 },
684 { "switch", RID_SWITCH
, 0 },
685 { "template", RID_TEMPLATE
, D_CXXONLY
| D_CXXWARN
},
686 { "this", RID_THIS
, D_CXXONLY
| D_CXXWARN
},
687 { "throw", RID_THROW
, D_CXX_OBJC
| D_CXXWARN
},
688 { "true", RID_TRUE
, D_CXXONLY
| D_CXXWARN
},
689 { "try", RID_TRY
, D_CXX_OBJC
| D_CXXWARN
},
690 { "typedef", RID_TYPEDEF
, 0 },
691 { "typename", RID_TYPENAME
, D_CXXONLY
| D_CXXWARN
},
692 { "typeid", RID_TYPEID
, D_CXXONLY
| D_CXXWARN
},
693 { "typeof", RID_TYPEOF
, D_ASM
| D_EXT
},
694 { "union", RID_UNION
, 0 },
695 { "unsigned", RID_UNSIGNED
, 0 },
696 { "using", RID_USING
, D_CXXONLY
| D_CXXWARN
},
697 { "virtual", RID_VIRTUAL
, D_CXXONLY
| D_CXXWARN
},
698 { "void", RID_VOID
, 0 },
699 { "volatile", RID_VOLATILE
, 0 },
700 { "wchar_t", RID_WCHAR
, D_CXXONLY
},
701 { "while", RID_WHILE
, 0 },
702 /* These Objective-C keywords are recognized only immediately after
704 { "compatibility_alias", RID_AT_ALIAS
, D_OBJC
},
705 { "defs", RID_AT_DEFS
, D_OBJC
},
706 { "encode", RID_AT_ENCODE
, D_OBJC
},
707 { "end", RID_AT_END
, D_OBJC
},
708 { "implementation", RID_AT_IMPLEMENTATION
, D_OBJC
},
709 { "interface", RID_AT_INTERFACE
, D_OBJC
},
710 { "protocol", RID_AT_PROTOCOL
, D_OBJC
},
711 { "selector", RID_AT_SELECTOR
, D_OBJC
},
712 { "finally", RID_AT_FINALLY
, D_OBJC
},
713 { "synchronized", RID_AT_SYNCHRONIZED
, D_OBJC
},
714 /* These are recognized only in protocol-qualifier context
716 { "bycopy", RID_BYCOPY
, D_OBJC
},
717 { "byref", RID_BYREF
, D_OBJC
},
718 { "in", RID_IN
, D_OBJC
},
719 { "inout", RID_INOUT
, D_OBJC
},
720 { "oneway", RID_ONEWAY
, D_OBJC
},
721 { "out", RID_OUT
, D_OBJC
},
724 const unsigned int num_c_common_reswords
=
725 sizeof c_common_reswords
/ sizeof (struct c_common_resword
);
727 /* Table of machine-independent attributes common to all C-like languages. */
728 const struct attribute_spec c_common_attribute_table
[] =
730 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
731 { "packed", 0, 0, false, false, false,
732 handle_packed_attribute
},
733 { "nocommon", 0, 0, true, false, false,
734 handle_nocommon_attribute
},
735 { "common", 0, 0, true, false, false,
736 handle_common_attribute
},
737 /* FIXME: logically, noreturn attributes should be listed as
738 "false, true, true" and apply to function types. But implementing this
739 would require all the places in the compiler that use TREE_THIS_VOLATILE
740 on a decl to identify non-returning functions to be located and fixed
741 to check the function type instead. */
742 { "noreturn", 0, 0, true, false, false,
743 handle_noreturn_attribute
},
744 { "volatile", 0, 0, true, false, false,
745 handle_noreturn_attribute
},
746 { "noinline", 0, 0, true, false, false,
747 handle_noinline_attribute
},
748 { "noclone", 0, 0, true, false, false,
749 handle_noclone_attribute
},
750 { "always_inline", 0, 0, true, false, false,
751 handle_always_inline_attribute
},
752 { "gnu_inline", 0, 0, true, false, false,
753 handle_gnu_inline_attribute
},
754 { "artificial", 0, 0, true, false, false,
755 handle_artificial_attribute
},
756 { "flatten", 0, 0, true, false, false,
757 handle_flatten_attribute
},
758 { "used", 0, 0, true, false, false,
759 handle_used_attribute
},
760 { "unused", 0, 0, false, false, false,
761 handle_unused_attribute
},
762 { "externally_visible", 0, 0, true, false, false,
763 handle_externally_visible_attribute
},
764 /* The same comments as for noreturn attributes apply to const ones. */
765 { "const", 0, 0, true, false, false,
766 handle_const_attribute
},
767 { "transparent_union", 0, 0, false, false, false,
768 handle_transparent_union_attribute
},
769 { "constructor", 0, 1, true, false, false,
770 handle_constructor_attribute
},
771 { "destructor", 0, 1, true, false, false,
772 handle_destructor_attribute
},
773 { "mode", 1, 1, false, true, false,
774 handle_mode_attribute
},
775 { "section", 1, 1, true, false, false,
776 handle_section_attribute
},
777 { "aligned", 0, 1, false, false, false,
778 handle_aligned_attribute
},
779 { "weak", 0, 0, true, false, false,
780 handle_weak_attribute
},
781 { "alias", 1, 1, true, false, false,
782 handle_alias_attribute
},
783 { "weakref", 0, 1, true, false, false,
784 handle_weakref_attribute
},
785 { "no_instrument_function", 0, 0, true, false, false,
786 handle_no_instrument_function_attribute
},
787 { "malloc", 0, 0, true, false, false,
788 handle_malloc_attribute
},
789 { "returns_twice", 0, 0, true, false, false,
790 handle_returns_twice_attribute
},
791 { "no_stack_limit", 0, 0, true, false, false,
792 handle_no_limit_stack_attribute
},
793 { "pure", 0, 0, true, false, false,
794 handle_pure_attribute
},
795 /* For internal use (marking of builtins) only. The name contains space
796 to prevent its usage in source code. */
797 { "no vops", 0, 0, true, false, false,
798 handle_novops_attribute
},
799 { "deprecated", 0, 1, false, false, false,
800 handle_deprecated_attribute
},
801 { "vector_size", 1, 1, false, true, false,
802 handle_vector_size_attribute
},
803 { "visibility", 1, 1, false, false, false,
804 handle_visibility_attribute
},
805 { "tls_model", 1, 1, true, false, false,
806 handle_tls_model_attribute
},
807 { "nonnull", 0, -1, false, true, true,
808 handle_nonnull_attribute
},
809 { "nothrow", 0, 0, true, false, false,
810 handle_nothrow_attribute
},
811 { "may_alias", 0, 0, false, true, false, NULL
},
812 { "cleanup", 1, 1, true, false, false,
813 handle_cleanup_attribute
},
814 { "warn_unused_result", 0, 0, false, true, true,
815 handle_warn_unused_result_attribute
},
816 { "sentinel", 0, 1, false, true, true,
817 handle_sentinel_attribute
},
818 /* For internal use (marking of builtins) only. The name contains space
819 to prevent its usage in source code. */
820 { "type generic", 0, 0, false, true, true,
821 handle_type_generic_attribute
},
822 { "alloc_size", 1, 2, false, true, true,
823 handle_alloc_size_attribute
},
824 { "cold", 0, 0, true, false, false,
825 handle_cold_attribute
},
826 { "hot", 0, 0, true, false, false,
827 handle_hot_attribute
},
828 { "warning", 1, 1, true, false, false,
829 handle_error_attribute
},
830 { "error", 1, 1, true, false, false,
831 handle_error_attribute
},
832 { "target", 1, -1, true, false, false,
833 handle_target_attribute
},
834 { "optimize", 1, -1, true, false, false,
835 handle_optimize_attribute
},
836 /* For internal use (marking of builtins and runtime functions) only.
837 The name contains space to prevent its usage in source code. */
838 { "fn spec", 1, 1, false, true, true,
839 handle_fnspec_attribute
},
840 { NULL
, 0, 0, false, false, false, NULL
}
843 /* Give the specifications for the format attributes, used by C and all
846 const struct attribute_spec c_common_format_attribute_table
[] =
848 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
849 { "format", 3, 3, false, true, true,
850 handle_format_attribute
},
851 { "format_arg", 1, 1, false, true, true,
852 handle_format_arg_attribute
},
853 { NULL
, 0, 0, false, false, false, NULL
}
857 /* Register reserved keyword WORD as qualifier for address space AS. */
860 c_register_addr_space (const char *word
, addr_space_t as
)
862 int rid
= RID_FIRST_ADDR_SPACE
+ as
;
865 /* Address space qualifiers are only supported
866 in C with GNU extensions enabled. */
867 if (c_dialect_cxx () || c_dialect_objc () || flag_no_asm
)
870 id
= get_identifier (word
);
871 C_SET_RID_CODE (id
, rid
);
872 C_IS_RESERVED_WORD (id
) = 1;
873 ridpointers
[rid
] = id
;
876 /* Return identifier for address space AS. */
879 c_addr_space_name (addr_space_t as
)
881 int rid
= RID_FIRST_ADDR_SPACE
+ as
;
882 gcc_assert (ridpointers
[rid
]);
883 return IDENTIFIER_POINTER (ridpointers
[rid
]);
886 /* Push current bindings for the function name VAR_DECLS. */
889 start_fname_decls (void)
892 tree saved
= NULL_TREE
;
894 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
896 tree decl
= *fname_vars
[ix
].decl
;
900 saved
= tree_cons (decl
, build_int_cst (NULL_TREE
, ix
), saved
);
901 *fname_vars
[ix
].decl
= NULL_TREE
;
904 if (saved
|| saved_function_name_decls
)
905 /* Normally they'll have been NULL, so only push if we've got a
906 stack, or they are non-NULL. */
907 saved_function_name_decls
= tree_cons (saved
, NULL_TREE
,
908 saved_function_name_decls
);
911 /* Finish up the current bindings, adding them into the current function's
912 statement tree. This must be done _before_ finish_stmt_tree is called.
913 If there is no current function, we must be at file scope and no statements
914 are involved. Pop the previous bindings. */
917 finish_fname_decls (void)
920 tree stmts
= NULL_TREE
;
921 tree stack
= saved_function_name_decls
;
923 for (; stack
&& TREE_VALUE (stack
); stack
= TREE_CHAIN (stack
))
924 append_to_statement_list (TREE_VALUE (stack
), &stmts
);
928 tree
*bodyp
= &DECL_SAVED_TREE (current_function_decl
);
930 if (TREE_CODE (*bodyp
) == BIND_EXPR
)
931 bodyp
= &BIND_EXPR_BODY (*bodyp
);
933 append_to_statement_list_force (*bodyp
, &stmts
);
937 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
938 *fname_vars
[ix
].decl
= NULL_TREE
;
942 /* We had saved values, restore them. */
945 for (saved
= TREE_PURPOSE (stack
); saved
; saved
= TREE_CHAIN (saved
))
947 tree decl
= TREE_PURPOSE (saved
);
948 unsigned ix
= TREE_INT_CST_LOW (TREE_VALUE (saved
));
950 *fname_vars
[ix
].decl
= decl
;
952 stack
= TREE_CHAIN (stack
);
954 saved_function_name_decls
= stack
;
957 /* Return the text name of the current function, suitably prettified
958 by PRETTY_P. Return string must be freed by caller. */
961 fname_as_string (int pretty_p
)
963 const char *name
= "top level";
966 cpp_string cstr
= { 0, 0 }, strname
;
974 if (current_function_decl
)
975 name
= lang_hooks
.decl_printable_name (current_function_decl
, vrb
);
977 len
= strlen (name
) + 3; /* Two for '"'s. One for NULL. */
979 namep
= XNEWVEC (char, len
);
980 snprintf (namep
, len
, "\"%s\"", name
);
981 strname
.text
= (unsigned char *) namep
;
982 strname
.len
= len
- 1;
984 if (cpp_interpret_string (parse_in
, &strname
, 1, &cstr
, CPP_STRING
))
987 return (const char *) cstr
.text
;
993 /* Return the VAR_DECL for a const char array naming the current
994 function. If the VAR_DECL has not yet been created, create it
995 now. RID indicates how it should be formatted and IDENTIFIER_NODE
996 ID is its name (unfortunately C and C++ hold the RID values of
997 keywords in different places, so we can't derive RID from ID in
998 this language independent code. LOC is the location of the
1002 fname_decl (location_t loc
, unsigned int rid
, tree id
)
1005 tree decl
= NULL_TREE
;
1007 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
1008 if (fname_vars
[ix
].rid
== rid
)
1011 decl
= *fname_vars
[ix
].decl
;
1014 /* If a tree is built here, it would normally have the lineno of
1015 the current statement. Later this tree will be moved to the
1016 beginning of the function and this line number will be wrong.
1017 To avoid this problem set the lineno to 0 here; that prevents
1018 it from appearing in the RTL. */
1020 location_t saved_location
= input_location
;
1021 input_location
= UNKNOWN_LOCATION
;
1023 stmts
= push_stmt_list ();
1024 decl
= (*make_fname_decl
) (loc
, id
, fname_vars
[ix
].pretty
);
1025 stmts
= pop_stmt_list (stmts
);
1026 if (!IS_EMPTY_STMT (stmts
))
1027 saved_function_name_decls
1028 = tree_cons (decl
, stmts
, saved_function_name_decls
);
1029 *fname_vars
[ix
].decl
= decl
;
1030 input_location
= saved_location
;
1032 if (!ix
&& !current_function_decl
)
1033 pedwarn (loc
, 0, "%qD is not defined outside of function scope", decl
);
1038 /* Given a STRING_CST, give it a suitable array-of-chars data type. */
1041 fix_string_type (tree value
)
1043 int length
= TREE_STRING_LENGTH (value
);
1045 tree e_type
, i_type
, a_type
;
1047 /* Compute the number of elements, for the array type. */
1048 if (TREE_TYPE (value
) == char_array_type_node
|| !TREE_TYPE (value
))
1051 e_type
= char_type_node
;
1053 else if (TREE_TYPE (value
) == char16_array_type_node
)
1055 nchars
= length
/ (TYPE_PRECISION (char16_type_node
) / BITS_PER_UNIT
);
1056 e_type
= char16_type_node
;
1058 else if (TREE_TYPE (value
) == char32_array_type_node
)
1060 nchars
= length
/ (TYPE_PRECISION (char32_type_node
) / BITS_PER_UNIT
);
1061 e_type
= char32_type_node
;
1065 nchars
= length
/ (TYPE_PRECISION (wchar_type_node
) / BITS_PER_UNIT
);
1066 e_type
= wchar_type_node
;
1069 /* C89 2.2.4.1, C99 5.2.4.1 (Translation limits). The analogous
1070 limit in C++98 Annex B is very large (65536) and is not normative,
1071 so we do not diagnose it (warn_overlength_strings is forced off
1072 in c_common_post_options). */
1073 if (warn_overlength_strings
)
1075 const int nchars_max
= flag_isoc99
? 4095 : 509;
1076 const int relevant_std
= flag_isoc99
? 99 : 90;
1077 if (nchars
- 1 > nchars_max
)
1078 /* Translators: The %d after 'ISO C' will be 90 or 99. Do not
1079 separate the %d from the 'C'. 'ISO' should not be
1080 translated, but it may be moved after 'C%d' in languages
1081 where modifiers follow nouns. */
1082 pedwarn (input_location
, OPT_Woverlength_strings
,
1083 "string length %qd is greater than the length %qd "
1084 "ISO C%d compilers are required to support",
1085 nchars
- 1, nchars_max
, relevant_std
);
1088 /* Create the array type for the string constant. The ISO C++
1089 standard says that a string literal has type `const char[N]' or
1090 `const wchar_t[N]'. We use the same logic when invoked as a C
1091 front-end with -Wwrite-strings.
1092 ??? We should change the type of an expression depending on the
1093 state of a warning flag. We should just be warning -- see how
1094 this is handled in the C++ front-end for the deprecated implicit
1095 conversion from string literals to `char*' or `wchar_t*'.
1097 The C++ front end relies on TYPE_MAIN_VARIANT of a cv-qualified
1098 array type being the unqualified version of that type.
1099 Therefore, if we are constructing an array of const char, we must
1100 construct the matching unqualified array type first. The C front
1101 end does not require this, but it does no harm, so we do it
1103 i_type
= build_index_type (build_int_cst (NULL_TREE
, nchars
- 1));
1104 a_type
= build_array_type (e_type
, i_type
);
1105 if (c_dialect_cxx() || warn_write_strings
)
1106 a_type
= c_build_qualified_type (a_type
, TYPE_QUAL_CONST
);
1108 TREE_TYPE (value
) = a_type
;
1109 TREE_CONSTANT (value
) = 1;
1110 TREE_READONLY (value
) = 1;
1111 TREE_STATIC (value
) = 1;
1115 /* Fully fold EXPR, an expression that was not folded (beyond integer
1116 constant expressions and null pointer constants) when being built
1117 up. If IN_INIT, this is in a static initializer and certain
1118 changes are made to the folding done. Clear *MAYBE_CONST if
1119 MAYBE_CONST is not NULL and EXPR is definitely not a constant
1120 expression because it contains an evaluated operator (in C99) or an
1121 operator outside of sizeof returning an integer constant (in C90)
1122 not permitted in constant expressions, or because it contains an
1123 evaluated arithmetic overflow. (*MAYBE_CONST should typically be
1124 set to true by callers before calling this function.) Return the
1125 folded expression. Function arguments have already been folded
1126 before calling this function, as have the contents of SAVE_EXPR,
1127 TARGET_EXPR, BIND_EXPR, VA_ARG_EXPR, OBJ_TYPE_REF and
1128 C_MAYBE_CONST_EXPR. */
1131 c_fully_fold (tree expr
, bool in_init
, bool *maybe_const
)
1134 tree eptype
= NULL_TREE
;
1136 bool maybe_const_itself
= true;
1137 location_t loc
= EXPR_LOCATION (expr
);
1139 /* This function is not relevant to C++ because C++ folds while
1140 parsing, and may need changes to be correct for C++ when C++
1141 stops folding while parsing. */
1142 if (c_dialect_cxx ())
1146 maybe_const
= &dummy
;
1147 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
1149 eptype
= TREE_TYPE (expr
);
1150 expr
= TREE_OPERAND (expr
, 0);
1152 ret
= c_fully_fold_internal (expr
, in_init
, maybe_const
,
1153 &maybe_const_itself
);
1155 ret
= fold_convert_loc (loc
, eptype
, ret
);
1156 *maybe_const
&= maybe_const_itself
;
1160 /* Internal helper for c_fully_fold. EXPR and IN_INIT are as for
1161 c_fully_fold. *MAYBE_CONST_OPERANDS is cleared because of operands
1162 not permitted, while *MAYBE_CONST_ITSELF is cleared because of
1163 arithmetic overflow (for C90, *MAYBE_CONST_OPERANDS is carried from
1164 both evaluated and unevaluated subexpressions while
1165 *MAYBE_CONST_ITSELF is carried from only evaluated
1169 c_fully_fold_internal (tree expr
, bool in_init
, bool *maybe_const_operands
,
1170 bool *maybe_const_itself
)
1173 enum tree_code code
= TREE_CODE (expr
);
1174 enum tree_code_class kind
= TREE_CODE_CLASS (code
);
1175 location_t loc
= EXPR_LOCATION (expr
);
1176 tree op0
, op1
, op2
, op3
;
1177 tree orig_op0
, orig_op1
, orig_op2
;
1178 bool op0_const
= true, op1_const
= true, op2_const
= true;
1179 bool op0_const_self
= true, op1_const_self
= true, op2_const_self
= true;
1180 bool nowarning
= TREE_NO_WARNING (expr
);
1183 /* This function is not relevant to C++ because C++ folds while
1184 parsing, and may need changes to be correct for C++ when C++
1185 stops folding while parsing. */
1186 if (c_dialect_cxx ())
1189 /* Constants, declarations, statements, errors, SAVE_EXPRs and
1190 anything else not counted as an expression cannot usefully be
1191 folded further at this point. */
1192 if (!IS_EXPR_CODE_CLASS (kind
)
1193 || kind
== tcc_statement
1194 || code
== SAVE_EXPR
)
1197 /* Operands of variable-length expressions (function calls) have
1198 already been folded, as have __builtin_* function calls, and such
1199 expressions cannot occur in constant expressions. */
1200 if (kind
== tcc_vl_exp
)
1202 *maybe_const_operands
= false;
1207 if (code
== C_MAYBE_CONST_EXPR
)
1209 tree pre
= C_MAYBE_CONST_EXPR_PRE (expr
);
1210 tree inner
= C_MAYBE_CONST_EXPR_EXPR (expr
);
1211 if (C_MAYBE_CONST_EXPR_NON_CONST (expr
))
1212 *maybe_const_operands
= false;
1213 if (C_MAYBE_CONST_EXPR_INT_OPERANDS (expr
))
1214 *maybe_const_itself
= false;
1215 if (pre
&& !in_init
)
1216 ret
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr
), pre
, inner
);
1222 /* Assignment, increment, decrement, function call and comma
1223 operators, and statement expressions, cannot occur in constant
1224 expressions if evaluated / outside of sizeof. (Function calls
1225 were handled above, though VA_ARG_EXPR is treated like a function
1226 call here, and statement expressions are handled through
1227 C_MAYBE_CONST_EXPR to avoid folding inside them.) */
1231 case PREDECREMENT_EXPR
:
1232 case PREINCREMENT_EXPR
:
1233 case POSTDECREMENT_EXPR
:
1234 case POSTINCREMENT_EXPR
:
1236 *maybe_const_operands
= false;
1243 *maybe_const_operands
= false;
1251 /* Fold individual tree codes as appropriate. */
1254 case COMPOUND_LITERAL_EXPR
:
1255 /* Any non-constancy will have been marked in a containing
1256 C_MAYBE_CONST_EXPR; there is no more folding to do here. */
1260 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1261 op1
= TREE_OPERAND (expr
, 1);
1262 op2
= TREE_OPERAND (expr
, 2);
1263 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1264 maybe_const_itself
);
1265 STRIP_TYPE_NOPS (op0
);
1266 if (op0
!= orig_op0
)
1267 ret
= build3 (COMPONENT_REF
, TREE_TYPE (expr
), op0
, op1
, op2
);
1270 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1271 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1276 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1277 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1278 op2
= TREE_OPERAND (expr
, 2);
1279 op3
= TREE_OPERAND (expr
, 3);
1280 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1281 maybe_const_itself
);
1282 STRIP_TYPE_NOPS (op0
);
1283 op1
= c_fully_fold_internal (op1
, in_init
, maybe_const_operands
,
1284 maybe_const_itself
);
1285 STRIP_TYPE_NOPS (op1
);
1286 op1
= decl_constant_value_for_optimization (op1
);
1287 if (op0
!= orig_op0
|| op1
!= orig_op1
)
1288 ret
= build4 (ARRAY_REF
, TREE_TYPE (expr
), op0
, op1
, op2
, op3
);
1291 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1292 TREE_SIDE_EFFECTS (ret
) = TREE_SIDE_EFFECTS (expr
);
1293 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1300 case PREDECREMENT_EXPR
:
1301 case PREINCREMENT_EXPR
:
1302 case POSTDECREMENT_EXPR
:
1303 case POSTINCREMENT_EXPR
:
1307 case POINTER_PLUS_EXPR
:
1308 case TRUNC_DIV_EXPR
:
1310 case FLOOR_DIV_EXPR
:
1311 case TRUNC_MOD_EXPR
:
1313 case EXACT_DIV_EXPR
:
1326 case TRUTH_AND_EXPR
:
1328 case TRUTH_XOR_EXPR
:
1329 case UNORDERED_EXPR
:
1336 /* Binary operations evaluating both arguments (increment and
1337 decrement are binary internally in GCC). */
1338 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1339 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1340 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1341 maybe_const_itself
);
1342 STRIP_TYPE_NOPS (op0
);
1343 if (code
!= MODIFY_EXPR
1344 && code
!= PREDECREMENT_EXPR
1345 && code
!= PREINCREMENT_EXPR
1346 && code
!= POSTDECREMENT_EXPR
1347 && code
!= POSTINCREMENT_EXPR
)
1348 op0
= decl_constant_value_for_optimization (op0
);
1349 /* The RHS of a MODIFY_EXPR was fully folded when building that
1350 expression for the sake of conversion warnings. */
1351 if (code
!= MODIFY_EXPR
)
1352 op1
= c_fully_fold_internal (op1
, in_init
, maybe_const_operands
,
1353 maybe_const_itself
);
1354 STRIP_TYPE_NOPS (op1
);
1355 op1
= decl_constant_value_for_optimization (op1
);
1356 if (op0
!= orig_op0
|| op1
!= orig_op1
|| in_init
)
1358 ? fold_build2_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
)
1359 : fold_build2_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
);
1362 if (TREE_OVERFLOW_P (ret
)
1363 && !TREE_OVERFLOW_P (op0
)
1364 && !TREE_OVERFLOW_P (op1
))
1365 overflow_warning (EXPR_LOCATION (expr
), ret
);
1369 case FIX_TRUNC_EXPR
:
1372 case NON_LVALUE_EXPR
:
1375 case TRUTH_NOT_EXPR
:
1380 /* Unary operations. */
1381 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1382 op0
= c_fully_fold_internal (op0
, in_init
, maybe_const_operands
,
1383 maybe_const_itself
);
1384 STRIP_TYPE_NOPS (op0
);
1385 if (code
!= ADDR_EXPR
&& code
!= REALPART_EXPR
&& code
!= IMAGPART_EXPR
)
1386 op0
= decl_constant_value_for_optimization (op0
);
1387 if (op0
!= orig_op0
|| in_init
)
1389 ? fold_build1_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
)
1390 : fold_build1_loc (loc
, code
, TREE_TYPE (expr
), op0
);
1393 if (code
== INDIRECT_REF
1395 && TREE_CODE (ret
) == INDIRECT_REF
)
1397 TREE_READONLY (ret
) = TREE_READONLY (expr
);
1398 TREE_SIDE_EFFECTS (ret
) = TREE_SIDE_EFFECTS (expr
);
1399 TREE_THIS_VOLATILE (ret
) = TREE_THIS_VOLATILE (expr
);
1403 case FIX_TRUNC_EXPR
:
1406 /* Don't warn about explicit conversions. We will already
1407 have warned about suspect implicit conversions. */
1411 if (TREE_OVERFLOW_P (ret
) && !TREE_OVERFLOW_P (op0
))
1412 overflow_warning (EXPR_LOCATION (expr
), ret
);
1417 case TRUTH_ANDIF_EXPR
:
1418 case TRUTH_ORIF_EXPR
:
1419 /* Binary operations not necessarily evaluating both
1421 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1422 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1423 op0
= c_fully_fold_internal (op0
, in_init
, &op0_const
, &op0_const_self
);
1424 STRIP_TYPE_NOPS (op0
);
1426 unused_p
= (op0
== (code
== TRUTH_ANDIF_EXPR
1427 ? truthvalue_false_node
1428 : truthvalue_true_node
));
1429 c_inhibit_evaluation_warnings
+= unused_p
;
1430 op1
= c_fully_fold_internal (op1
, in_init
, &op1_const
, &op1_const_self
);
1431 STRIP_TYPE_NOPS (op1
);
1432 c_inhibit_evaluation_warnings
-= unused_p
;
1434 if (op0
!= orig_op0
|| op1
!= orig_op1
|| in_init
)
1436 ? fold_build2_initializer_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
)
1437 : fold_build2_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
);
1440 *maybe_const_operands
&= op0_const
;
1441 *maybe_const_itself
&= op0_const_self
;
1445 && (code
== TRUTH_ANDIF_EXPR
1446 ? op0
== truthvalue_false_node
1447 : op0
== truthvalue_true_node
)))
1448 *maybe_const_operands
&= op1_const
;
1451 && (code
== TRUTH_ANDIF_EXPR
1452 ? op0
== truthvalue_false_node
1453 : op0
== truthvalue_true_node
)))
1454 *maybe_const_itself
&= op1_const_self
;
1458 orig_op0
= op0
= TREE_OPERAND (expr
, 0);
1459 orig_op1
= op1
= TREE_OPERAND (expr
, 1);
1460 orig_op2
= op2
= TREE_OPERAND (expr
, 2);
1461 op0
= c_fully_fold_internal (op0
, in_init
, &op0_const
, &op0_const_self
);
1463 STRIP_TYPE_NOPS (op0
);
1464 c_inhibit_evaluation_warnings
+= (op0
== truthvalue_false_node
);
1465 op1
= c_fully_fold_internal (op1
, in_init
, &op1_const
, &op1_const_self
);
1466 STRIP_TYPE_NOPS (op1
);
1467 c_inhibit_evaluation_warnings
-= (op0
== truthvalue_false_node
);
1469 c_inhibit_evaluation_warnings
+= (op0
== truthvalue_true_node
);
1470 op2
= c_fully_fold_internal (op2
, in_init
, &op2_const
, &op2_const_self
);
1471 STRIP_TYPE_NOPS (op2
);
1472 c_inhibit_evaluation_warnings
-= (op0
== truthvalue_true_node
);
1474 if (op0
!= orig_op0
|| op1
!= orig_op1
|| op2
!= orig_op2
)
1475 ret
= fold_build3_loc (loc
, code
, TREE_TYPE (expr
), op0
, op1
, op2
);
1478 *maybe_const_operands
&= op0_const
;
1479 *maybe_const_itself
&= op0_const_self
;
1483 && op0
== truthvalue_false_node
))
1484 *maybe_const_operands
&= op1_const
;
1487 && op0
== truthvalue_false_node
))
1488 *maybe_const_itself
&= op1_const_self
;
1492 && op0
== truthvalue_true_node
))
1493 *maybe_const_operands
&= op2_const
;
1496 && op0
== truthvalue_true_node
))
1497 *maybe_const_itself
&= op2_const_self
;
1500 case EXCESS_PRECISION_EXPR
:
1501 /* Each case where an operand with excess precision may be
1502 encountered must remove the EXCESS_PRECISION_EXPR around
1503 inner operands and possibly put one around the whole
1504 expression or possibly convert to the semantic type (which
1505 c_fully_fold does); we cannot tell at this stage which is
1506 appropriate in any particular case. */
1510 /* Various codes may appear through folding built-in functions
1511 and their arguments. */
1516 /* Some folding may introduce NON_LVALUE_EXPRs; all lvalue checks
1517 have been done by this point, so remove them again. */
1518 nowarning
|= TREE_NO_WARNING (ret
);
1519 STRIP_TYPE_NOPS (ret
);
1520 if (nowarning
&& !TREE_NO_WARNING (ret
))
1522 if (!CAN_HAVE_LOCATION_P (ret
))
1523 ret
= build1 (NOP_EXPR
, TREE_TYPE (ret
), ret
);
1524 TREE_NO_WARNING (ret
) = 1;
1527 protected_set_expr_location (ret
, loc
);
1531 /* If not optimizing, EXP is not a VAR_DECL, or EXP has array type,
1532 return EXP. Otherwise, return either EXP or its known constant
1533 value (if it has one), but return EXP if EXP has mode BLKmode. ???
1534 Is the BLKmode test appropriate? */
1537 decl_constant_value_for_optimization (tree exp
)
1541 /* This function is only used by C, for c_fully_fold and other
1542 optimization, and may not be correct for C++. */
1543 if (c_dialect_cxx ())
1547 || TREE_CODE (exp
) != VAR_DECL
1548 || TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
1549 || DECL_MODE (exp
) == BLKmode
)
1552 ret
= decl_constant_value (exp
);
1553 /* Avoid unwanted tree sharing between the initializer and current
1554 function's body where the tree can be modified e.g. by the
1556 if (ret
!= exp
&& TREE_STATIC (exp
))
1557 ret
= unshare_expr (ret
);
1561 /* Print a warning if a constant expression had overflow in folding.
1562 Invoke this function on every expression that the language
1563 requires to be a constant expression.
1564 Note the ANSI C standard says it is erroneous for a
1565 constant expression to overflow. */
1568 constant_expression_warning (tree value
)
1570 if (warn_overflow
&& pedantic
1571 && (TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1572 || TREE_CODE (value
) == FIXED_CST
1573 || TREE_CODE (value
) == VECTOR_CST
1574 || TREE_CODE (value
) == COMPLEX_CST
)
1575 && TREE_OVERFLOW (value
))
1576 pedwarn (input_location
, OPT_Woverflow
, "overflow in constant expression");
1579 /* The same as above but print an unconditional error. */
1581 constant_expression_error (tree value
)
1583 if ((TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1584 || TREE_CODE (value
) == FIXED_CST
1585 || TREE_CODE (value
) == VECTOR_CST
1586 || TREE_CODE (value
) == COMPLEX_CST
)
1587 && TREE_OVERFLOW (value
))
1588 error ("overflow in constant expression");
1591 /* Print a warning if an expression had overflow in folding and its
1594 Invoke this function on every expression that
1595 (1) appears in the source code, and
1596 (2) is a constant expression that overflowed, and
1597 (3) is not already checked by convert_and_check;
1598 however, do not invoke this function on operands of explicit casts
1599 or when the expression is the result of an operator and any operand
1600 already overflowed. */
1603 overflow_warning (location_t loc
, tree value
)
1605 if (c_inhibit_evaluation_warnings
!= 0)
1608 switch (TREE_CODE (value
))
1611 warning_at (loc
, OPT_Woverflow
, "integer overflow in expression");
1615 warning_at (loc
, OPT_Woverflow
,
1616 "floating point overflow in expression");
1620 warning_at (loc
, OPT_Woverflow
, "fixed-point overflow in expression");
1624 warning_at (loc
, OPT_Woverflow
, "vector overflow in expression");
1628 if (TREE_CODE (TREE_REALPART (value
)) == INTEGER_CST
)
1629 warning_at (loc
, OPT_Woverflow
,
1630 "complex integer overflow in expression");
1631 else if (TREE_CODE (TREE_REALPART (value
)) == REAL_CST
)
1632 warning_at (loc
, OPT_Woverflow
,
1633 "complex floating point overflow in expression");
1641 /* Warn about uses of logical || / && operator in a context where it
1642 is likely that the bitwise equivalent was intended by the
1643 programmer. We have seen an expression in which CODE is a binary
1644 operator used to combine expressions OP_LEFT and OP_RIGHT, which before folding
1645 had CODE_LEFT and CODE_RIGHT, into an expression of type TYPE. */
1647 warn_logical_operator (location_t location
, enum tree_code code
, tree type
,
1648 enum tree_code code_left
, tree op_left
,
1649 enum tree_code
ARG_UNUSED (code_right
), tree op_right
)
1651 int or_op
= (code
== TRUTH_ORIF_EXPR
|| code
== TRUTH_OR_EXPR
);
1652 int in0_p
, in1_p
, in_p
;
1653 tree low0
, low1
, low
, high0
, high1
, high
, lhs
, rhs
, tem
;
1654 bool strict_overflow_p
= false;
1656 if (code
!= TRUTH_ANDIF_EXPR
1657 && code
!= TRUTH_AND_EXPR
1658 && code
!= TRUTH_ORIF_EXPR
1659 && code
!= TRUTH_OR_EXPR
)
1662 /* Warn if &&/|| are being used in a context where it is
1663 likely that the bitwise equivalent was intended by the
1664 programmer. That is, an expression such as op && MASK
1665 where op should not be any boolean expression, nor a
1666 constant, and mask seems to be a non-boolean integer constant. */
1667 if (!truth_value_p (code_left
)
1668 && INTEGRAL_TYPE_P (TREE_TYPE (op_left
))
1669 && !CONSTANT_CLASS_P (op_left
)
1670 && !TREE_NO_WARNING (op_left
)
1671 && TREE_CODE (op_right
) == INTEGER_CST
1672 && !integer_zerop (op_right
)
1673 && !integer_onep (op_right
))
1676 warning_at (location
, OPT_Wlogical_op
, "logical %<or%>"
1677 " applied to non-boolean constant");
1679 warning_at (location
, OPT_Wlogical_op
, "logical %<and%>"
1680 " applied to non-boolean constant");
1681 TREE_NO_WARNING (op_left
) = true;
1685 /* We do not warn for constants because they are typical of macro
1686 expansions that test for features. */
1687 if (CONSTANT_CLASS_P (op_left
) || CONSTANT_CLASS_P (op_right
))
1690 /* This warning only makes sense with logical operands. */
1691 if (!(truth_value_p (TREE_CODE (op_left
))
1692 || INTEGRAL_TYPE_P (TREE_TYPE (op_left
)))
1693 || !(truth_value_p (TREE_CODE (op_right
))
1694 || INTEGRAL_TYPE_P (TREE_TYPE (op_right
))))
1697 lhs
= make_range (op_left
, &in0_p
, &low0
, &high0
, &strict_overflow_p
);
1698 rhs
= make_range (op_right
, &in1_p
, &low1
, &high1
, &strict_overflow_p
);
1700 if (lhs
&& TREE_CODE (lhs
) == C_MAYBE_CONST_EXPR
)
1701 lhs
= C_MAYBE_CONST_EXPR_EXPR (lhs
);
1703 if (rhs
&& TREE_CODE (rhs
) == C_MAYBE_CONST_EXPR
)
1704 rhs
= C_MAYBE_CONST_EXPR_EXPR (rhs
);
1706 /* If this is an OR operation, invert both sides; we will invert
1707 again at the end. */
1709 in0_p
= !in0_p
, in1_p
= !in1_p
;
1711 /* If both expressions are the same, if we can merge the ranges, and we
1712 can build the range test, return it or it inverted. */
1713 if (lhs
&& rhs
&& operand_equal_p (lhs
, rhs
, 0)
1714 && merge_ranges (&in_p
, &low
, &high
, in0_p
, low0
, high0
,
1716 && 0 != (tem
= build_range_check (UNKNOWN_LOCATION
,
1717 type
, lhs
, in_p
, low
, high
)))
1719 if (TREE_CODE (tem
) != INTEGER_CST
)
1723 warning_at (location
, OPT_Wlogical_op
,
1725 "of collectively exhaustive tests is always true");
1727 warning_at (location
, OPT_Wlogical_op
,
1729 "of mutually exclusive tests is always false");
1734 /* Print a warning about casts that might indicate violation
1735 of strict aliasing rules if -Wstrict-aliasing is used and
1736 strict aliasing mode is in effect. OTYPE is the original
1737 TREE_TYPE of EXPR, and TYPE the type we're casting to. */
1740 strict_aliasing_warning (tree otype
, tree type
, tree expr
)
1742 /* Strip pointer conversion chains and get to the correct original type. */
1744 otype
= TREE_TYPE (expr
);
1746 if (!(flag_strict_aliasing
1747 && POINTER_TYPE_P (type
)
1748 && POINTER_TYPE_P (otype
)
1749 && !VOID_TYPE_P (TREE_TYPE (type
)))
1750 /* If the type we are casting to is a ref-all pointer
1751 dereferencing it is always valid. */
1752 || TYPE_REF_CAN_ALIAS_ALL (type
))
1755 if ((warn_strict_aliasing
> 1) && TREE_CODE (expr
) == ADDR_EXPR
1756 && (DECL_P (TREE_OPERAND (expr
, 0))
1757 || handled_component_p (TREE_OPERAND (expr
, 0))))
1759 /* Casting the address of an object to non void pointer. Warn
1760 if the cast breaks type based aliasing. */
1761 if (!COMPLETE_TYPE_P (TREE_TYPE (type
)) && warn_strict_aliasing
== 2)
1763 warning (OPT_Wstrict_aliasing
, "type-punning to incomplete type "
1764 "might break strict-aliasing rules");
1769 /* warn_strict_aliasing >= 3. This includes the default (3).
1770 Only warn if the cast is dereferenced immediately. */
1771 alias_set_type set1
=
1772 get_alias_set (TREE_TYPE (TREE_OPERAND (expr
, 0)));
1773 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
1775 if (set1
!= set2
&& set2
!= 0
1776 && (set1
== 0 || !alias_sets_conflict_p (set1
, set2
)))
1778 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1779 "pointer will break strict-aliasing rules");
1782 else if (warn_strict_aliasing
== 2
1783 && !alias_sets_must_conflict_p (set1
, set2
))
1785 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1786 "pointer might break strict-aliasing rules");
1792 if ((warn_strict_aliasing
== 1) && !VOID_TYPE_P (TREE_TYPE (otype
)))
1794 /* At this level, warn for any conversions, even if an address is
1795 not taken in the same statement. This will likely produce many
1796 false positives, but could be useful to pinpoint problems that
1797 are not revealed at higher levels. */
1798 alias_set_type set1
= get_alias_set (TREE_TYPE (otype
));
1799 alias_set_type set2
= get_alias_set (TREE_TYPE (type
));
1800 if (!COMPLETE_TYPE_P (type
)
1801 || !alias_sets_must_conflict_p (set1
, set2
))
1803 warning (OPT_Wstrict_aliasing
, "dereferencing type-punned "
1804 "pointer might break strict-aliasing rules");
1812 /* Warn for unlikely, improbable, or stupid DECL declarations
1816 check_main_parameter_types (tree decl
)
1821 for (args
= TYPE_ARG_TYPES (TREE_TYPE (decl
)); args
;
1822 args
= TREE_CHAIN (args
))
1824 tree type
= args
? TREE_VALUE (args
) : 0;
1826 if (type
== void_type_node
|| type
== error_mark_node
)
1833 if (TYPE_MAIN_VARIANT (type
) != integer_type_node
)
1834 pedwarn (input_location
, OPT_Wmain
, "first argument of %q+D should be %<int%>",
1839 if (TREE_CODE (type
) != POINTER_TYPE
1840 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
1841 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
1843 pedwarn (input_location
, OPT_Wmain
, "second argument of %q+D should be %<char **%>",
1848 if (TREE_CODE (type
) != POINTER_TYPE
1849 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
1850 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
1852 pedwarn (input_location
, OPT_Wmain
, "third argument of %q+D should probably be "
1853 "%<char **%>", decl
);
1858 /* It is intentional that this message does not mention the third
1859 argument because it's only mentioned in an appendix of the
1861 if (argct
> 0 && (argct
< 2 || argct
> 3))
1862 pedwarn (input_location
, OPT_Wmain
, "%q+D takes only zero or two arguments", decl
);
1865 /* True if pointers to distinct types T1 and T2 can be converted to
1866 each other without an explicit cast. Only returns true for opaque
1869 vector_targets_convertible_p (const_tree t1
, const_tree t2
)
1871 if (TREE_CODE (t1
) == VECTOR_TYPE
&& TREE_CODE (t2
) == VECTOR_TYPE
1872 && (TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
1873 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
1879 /* True if vector types T1 and T2 can be converted to each other
1880 without an explicit cast. If EMIT_LAX_NOTE is true, and T1 and T2
1881 can only be converted with -flax-vector-conversions yet that is not
1882 in effect, emit a note telling the user about that option if such
1883 a note has not previously been emitted. */
1885 vector_types_convertible_p (const_tree t1
, const_tree t2
, bool emit_lax_note
)
1887 static bool emitted_lax_note
= false;
1888 bool convertible_lax
;
1890 if ((TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
1891 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
1895 (tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
))
1896 && (TREE_CODE (TREE_TYPE (t1
)) != REAL_TYPE
||
1897 TYPE_PRECISION (t1
) == TYPE_PRECISION (t2
))
1898 && (INTEGRAL_TYPE_P (TREE_TYPE (t1
))
1899 == INTEGRAL_TYPE_P (TREE_TYPE (t2
))));
1901 if (!convertible_lax
|| flag_lax_vector_conversions
)
1902 return convertible_lax
;
1904 if (TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
)
1905 && lang_hooks
.types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
1908 if (emit_lax_note
&& !emitted_lax_note
)
1910 emitted_lax_note
= true;
1911 inform (input_location
, "use -flax-vector-conversions to permit "
1912 "conversions between vectors with differing "
1913 "element types or numbers of subparts");
1919 /* This is a helper function of build_binary_op.
1921 For certain operations if both args were extended from the same
1922 smaller type, do the arithmetic in that type and then extend.
1924 BITWISE indicates a bitwise operation.
1925 For them, this optimization is safe only if
1926 both args are zero-extended or both are sign-extended.
1927 Otherwise, we might change the result.
1928 Eg, (short)-1 | (unsigned short)-1 is (int)-1
1929 but calculated in (unsigned short) it would be (unsigned short)-1.
1931 tree
shorten_binary_op (tree result_type
, tree op0
, tree op1
, bool bitwise
)
1933 int unsigned0
, unsigned1
;
1938 /* Cast OP0 and OP1 to RESULT_TYPE. Doing so prevents
1939 excessive narrowing when we call get_narrower below. For
1940 example, suppose that OP0 is of unsigned int extended
1941 from signed char and that RESULT_TYPE is long long int.
1942 If we explicitly cast OP0 to RESULT_TYPE, OP0 would look
1945 (long long int) (unsigned int) signed_char
1947 which get_narrower would narrow down to
1949 (unsigned int) signed char
1951 If we do not cast OP0 first, get_narrower would return
1952 signed_char, which is inconsistent with the case of the
1954 op0
= convert (result_type
, op0
);
1955 op1
= convert (result_type
, op1
);
1957 arg0
= get_narrower (op0
, &unsigned0
);
1958 arg1
= get_narrower (op1
, &unsigned1
);
1960 /* UNS is 1 if the operation to be done is an unsigned one. */
1961 uns
= TYPE_UNSIGNED (result_type
);
1963 /* Handle the case that OP0 (or OP1) does not *contain* a conversion
1964 but it *requires* conversion to FINAL_TYPE. */
1966 if ((TYPE_PRECISION (TREE_TYPE (op0
))
1967 == TYPE_PRECISION (TREE_TYPE (arg0
)))
1968 && TREE_TYPE (op0
) != result_type
)
1969 unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
1970 if ((TYPE_PRECISION (TREE_TYPE (op1
))
1971 == TYPE_PRECISION (TREE_TYPE (arg1
)))
1972 && TREE_TYPE (op1
) != result_type
)
1973 unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
1975 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
1977 /* For bitwise operations, signedness of nominal type
1978 does not matter. Consider only how operands were extended. */
1982 /* Note that in all three cases below we refrain from optimizing
1983 an unsigned operation on sign-extended args.
1984 That would not be valid. */
1986 /* Both args variable: if both extended in same way
1987 from same width, do it in that width.
1988 Do it unsigned if args were zero-extended. */
1989 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
1990 < TYPE_PRECISION (result_type
))
1991 && (TYPE_PRECISION (TREE_TYPE (arg1
))
1992 == TYPE_PRECISION (TREE_TYPE (arg0
)))
1993 && unsigned0
== unsigned1
1994 && (unsigned0
|| !uns
))
1995 return c_common_signed_or_unsigned_type
1996 (unsigned0
, common_type (TREE_TYPE (arg0
), TREE_TYPE (arg1
)));
1998 else if (TREE_CODE (arg0
) == INTEGER_CST
1999 && (unsigned1
|| !uns
)
2000 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2001 < TYPE_PRECISION (result_type
))
2003 = c_common_signed_or_unsigned_type (unsigned1
,
2005 && !POINTER_TYPE_P (type
)
2006 && int_fits_type_p (arg0
, type
))
2009 else if (TREE_CODE (arg1
) == INTEGER_CST
2010 && (unsigned0
|| !uns
)
2011 && (TYPE_PRECISION (TREE_TYPE (arg0
))
2012 < TYPE_PRECISION (result_type
))
2014 = c_common_signed_or_unsigned_type (unsigned0
,
2016 && !POINTER_TYPE_P (type
)
2017 && int_fits_type_p (arg1
, type
))
2023 /* Warns if the conversion of EXPR to TYPE may alter a value.
2024 This is a helper function for warnings_for_convert_and_check. */
2027 conversion_warning (tree type
, tree expr
)
2029 bool give_warning
= false;
2032 const int expr_num_operands
= TREE_OPERAND_LENGTH (expr
);
2033 tree expr_type
= TREE_TYPE (expr
);
2035 if (!warn_conversion
&& !warn_sign_conversion
)
2038 /* If any operand is artificial, then this expression was generated
2039 by the compiler and we do not warn. */
2040 for (i
= 0; i
< expr_num_operands
; i
++)
2042 tree op
= TREE_OPERAND (expr
, i
);
2043 if (op
&& DECL_P (op
) && DECL_ARTIFICIAL (op
))
2047 switch (TREE_CODE (expr
))
2055 case TRUTH_ANDIF_EXPR
:
2056 case TRUTH_ORIF_EXPR
:
2057 case TRUTH_AND_EXPR
:
2059 case TRUTH_XOR_EXPR
:
2060 case TRUTH_NOT_EXPR
:
2061 /* Conversion from boolean to a signed:1 bit-field (which only
2062 can hold the values 0 and -1) doesn't lose information - but
2063 it does change the value. */
2064 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
2065 warning (OPT_Wconversion
,
2066 "conversion to %qT from boolean expression", type
);
2072 /* Warn for real constant that is not an exact integer converted
2074 if (TREE_CODE (expr_type
) == REAL_TYPE
2075 && TREE_CODE (type
) == INTEGER_TYPE
)
2077 if (!real_isinteger (TREE_REAL_CST_PTR (expr
), TYPE_MODE (expr_type
)))
2078 give_warning
= true;
2080 /* Warn for an integer constant that does not fit into integer type. */
2081 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2082 && TREE_CODE (type
) == INTEGER_TYPE
2083 && !int_fits_type_p (expr
, type
))
2085 if (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)
2086 && tree_int_cst_sgn (expr
) < 0)
2087 warning (OPT_Wsign_conversion
,
2088 "negative integer implicitly converted to unsigned type");
2089 else if (!TYPE_UNSIGNED (type
) && TYPE_UNSIGNED (expr_type
))
2090 warning (OPT_Wsign_conversion
, "conversion of unsigned constant "
2091 "value to negative integer");
2093 give_warning
= true;
2095 else if (TREE_CODE (type
) == REAL_TYPE
)
2097 /* Warn for an integer constant that does not fit into real type. */
2098 if (TREE_CODE (expr_type
) == INTEGER_TYPE
)
2100 REAL_VALUE_TYPE a
= real_value_from_int_cst (0, expr
);
2101 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2102 give_warning
= true;
2104 /* Warn for a real constant that does not fit into a smaller
2106 else if (TREE_CODE (expr_type
) == REAL_TYPE
2107 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2109 REAL_VALUE_TYPE a
= TREE_REAL_CST (expr
);
2110 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
2111 give_warning
= true;
2116 warning (OPT_Wconversion
,
2117 "conversion to %qT alters %qT constant value",
2124 /* In case of COND_EXPR, if both operands are constants or
2125 COND_EXPR, then we do not care about the type of COND_EXPR,
2126 only about the conversion of each operand. */
2127 tree op1
= TREE_OPERAND (expr
, 1);
2128 tree op2
= TREE_OPERAND (expr
, 2);
2130 if ((TREE_CODE (op1
) == REAL_CST
|| TREE_CODE (op1
) == INTEGER_CST
2131 || TREE_CODE (op1
) == COND_EXPR
)
2132 && (TREE_CODE (op2
) == REAL_CST
|| TREE_CODE (op2
) == INTEGER_CST
2133 || TREE_CODE (op2
) == COND_EXPR
))
2135 conversion_warning (type
, op1
);
2136 conversion_warning (type
, op2
);
2142 default: /* 'expr' is not a constant. */
2144 /* Warn for real types converted to integer types. */
2145 if (TREE_CODE (expr_type
) == REAL_TYPE
2146 && TREE_CODE (type
) == INTEGER_TYPE
)
2147 give_warning
= true;
2149 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2150 && TREE_CODE (type
) == INTEGER_TYPE
)
2152 /* Don't warn about unsigned char y = 0xff, x = (int) y; */
2153 expr
= get_unwidened (expr
, 0);
2154 expr_type
= TREE_TYPE (expr
);
2156 /* Don't warn for short y; short x = ((int)y & 0xff); */
2157 if (TREE_CODE (expr
) == BIT_AND_EXPR
2158 || TREE_CODE (expr
) == BIT_IOR_EXPR
2159 || TREE_CODE (expr
) == BIT_XOR_EXPR
)
2161 /* If both args were extended from a shortest type,
2162 use that type if that is safe. */
2163 expr_type
= shorten_binary_op (expr_type
,
2164 TREE_OPERAND (expr
, 0),
2165 TREE_OPERAND (expr
, 1),
2168 if (TREE_CODE (expr
) == BIT_AND_EXPR
)
2170 tree op0
= TREE_OPERAND (expr
, 0);
2171 tree op1
= TREE_OPERAND (expr
, 1);
2172 bool unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
2173 bool unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
2175 /* If one of the operands is a non-negative constant
2176 that fits in the target type, then the type of the
2177 other operand does not matter. */
2178 if ((TREE_CODE (op0
) == INTEGER_CST
2179 && int_fits_type_p (op0
, c_common_signed_type (type
))
2180 && int_fits_type_p (op0
, c_common_unsigned_type (type
)))
2181 || (TREE_CODE (op1
) == INTEGER_CST
2182 && int_fits_type_p (op1
, c_common_signed_type (type
))
2183 && int_fits_type_p (op1
,
2184 c_common_unsigned_type (type
))))
2186 /* If constant is unsigned and fits in the target
2187 type, then the result will also fit. */
2188 else if ((TREE_CODE (op0
) == INTEGER_CST
2190 && int_fits_type_p (op0
, type
))
2191 || (TREE_CODE (op1
) == INTEGER_CST
2193 && int_fits_type_p (op1
, type
)))
2197 /* Warn for integer types converted to smaller integer types. */
2198 if (TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2199 give_warning
= true;
2201 /* When they are the same width but different signedness,
2202 then the value may change. */
2203 else if ((TYPE_PRECISION (type
) == TYPE_PRECISION (expr_type
)
2204 && TYPE_UNSIGNED (expr_type
) != TYPE_UNSIGNED (type
))
2205 /* Even when converted to a bigger type, if the type is
2206 unsigned but expr is signed, then negative values
2208 || (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)))
2209 warning (OPT_Wsign_conversion
, "conversion to %qT from %qT "
2210 "may change the sign of the result",
2214 /* Warn for integer types converted to real types if and only if
2215 all the range of values of the integer type cannot be
2216 represented by the real type. */
2217 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
2218 && TREE_CODE (type
) == REAL_TYPE
)
2220 tree type_low_bound
, type_high_bound
;
2221 REAL_VALUE_TYPE real_low_bound
, real_high_bound
;
2223 /* Don't warn about char y = 0xff; float x = (int) y; */
2224 expr
= get_unwidened (expr
, 0);
2225 expr_type
= TREE_TYPE (expr
);
2227 type_low_bound
= TYPE_MIN_VALUE (expr_type
);
2228 type_high_bound
= TYPE_MAX_VALUE (expr_type
);
2229 real_low_bound
= real_value_from_int_cst (0, type_low_bound
);
2230 real_high_bound
= real_value_from_int_cst (0, type_high_bound
);
2232 if (!exact_real_truncate (TYPE_MODE (type
), &real_low_bound
)
2233 || !exact_real_truncate (TYPE_MODE (type
), &real_high_bound
))
2234 give_warning
= true;
2237 /* Warn for real types converted to smaller real types. */
2238 else if (TREE_CODE (expr_type
) == REAL_TYPE
2239 && TREE_CODE (type
) == REAL_TYPE
2240 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
2241 give_warning
= true;
2245 warning (OPT_Wconversion
,
2246 "conversion to %qT from %qT may alter its value",
2251 /* Produce warnings after a conversion. RESULT is the result of
2252 converting EXPR to TYPE. This is a helper function for
2253 convert_and_check and cp_convert_and_check. */
2256 warnings_for_convert_and_check (tree type
, tree expr
, tree result
)
2258 if (TREE_CODE (expr
) == INTEGER_CST
2259 && (TREE_CODE (type
) == INTEGER_TYPE
2260 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2261 && !int_fits_type_p (expr
, type
))
2263 /* Do not diagnose overflow in a constant expression merely
2264 because a conversion overflowed. */
2265 if (TREE_OVERFLOW (result
))
2266 TREE_OVERFLOW (result
) = TREE_OVERFLOW (expr
);
2268 if (TYPE_UNSIGNED (type
))
2270 /* This detects cases like converting -129 or 256 to
2272 if (!int_fits_type_p (expr
, c_common_signed_type (type
)))
2273 warning (OPT_Woverflow
,
2274 "large integer implicitly truncated to unsigned type");
2276 conversion_warning (type
, expr
);
2278 else if (!int_fits_type_p (expr
, c_common_unsigned_type (type
)))
2279 warning (OPT_Woverflow
,
2280 "overflow in implicit constant conversion");
2281 /* No warning for converting 0x80000000 to int. */
2283 && (TREE_CODE (TREE_TYPE (expr
)) != INTEGER_TYPE
2284 || TYPE_PRECISION (TREE_TYPE (expr
))
2285 != TYPE_PRECISION (type
)))
2286 warning (OPT_Woverflow
,
2287 "overflow in implicit constant conversion");
2290 conversion_warning (type
, expr
);
2292 else if ((TREE_CODE (result
) == INTEGER_CST
2293 || TREE_CODE (result
) == FIXED_CST
) && TREE_OVERFLOW (result
))
2294 warning (OPT_Woverflow
,
2295 "overflow in implicit constant conversion");
2297 conversion_warning (type
, expr
);
2301 /* Convert EXPR to TYPE, warning about conversion problems with constants.
2302 Invoke this function on every expression that is converted implicitly,
2303 i.e. because of language rules and not because of an explicit cast. */
2306 convert_and_check (tree type
, tree expr
)
2309 tree expr_for_warning
;
2311 /* Convert from a value with possible excess precision rather than
2312 via the semantic type, but do not warn about values not fitting
2313 exactly in the semantic type. */
2314 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
2316 tree orig_type
= TREE_TYPE (expr
);
2317 expr
= TREE_OPERAND (expr
, 0);
2318 expr_for_warning
= convert (orig_type
, expr
);
2319 if (orig_type
== type
)
2320 return expr_for_warning
;
2323 expr_for_warning
= expr
;
2325 if (TREE_TYPE (expr
) == type
)
2328 result
= convert (type
, expr
);
2330 if (c_inhibit_evaluation_warnings
== 0
2331 && !TREE_OVERFLOW_P (expr
)
2332 && result
!= error_mark_node
)
2333 warnings_for_convert_and_check (type
, expr_for_warning
, result
);
2338 /* A node in a list that describes references to variables (EXPR), which are
2339 either read accesses if WRITER is zero, or write accesses, in which case
2340 WRITER is the parent of EXPR. */
2347 /* Used to implement a cache the results of a call to verify_tree. We only
2348 use this for SAVE_EXPRs. */
2351 struct tlist_cache
*next
;
2352 struct tlist
*cache_before_sp
;
2353 struct tlist
*cache_after_sp
;
2357 /* Obstack to use when allocating tlist structures, and corresponding
2359 static struct obstack tlist_obstack
;
2360 static char *tlist_firstobj
= 0;
2362 /* Keep track of the identifiers we've warned about, so we can avoid duplicate
2364 static struct tlist
*warned_ids
;
2365 /* SAVE_EXPRs need special treatment. We process them only once and then
2366 cache the results. */
2367 static struct tlist_cache
*save_expr_cache
;
2369 static void add_tlist (struct tlist
**, struct tlist
*, tree
, int);
2370 static void merge_tlist (struct tlist
**, struct tlist
*, int);
2371 static void verify_tree (tree
, struct tlist
**, struct tlist
**, tree
);
2372 static int warning_candidate_p (tree
);
2373 static bool candidate_equal_p (const_tree
, const_tree
);
2374 static void warn_for_collisions (struct tlist
*);
2375 static void warn_for_collisions_1 (tree
, tree
, struct tlist
*, int);
2376 static struct tlist
*new_tlist (struct tlist
*, tree
, tree
);
2378 /* Create a new struct tlist and fill in its fields. */
2379 static struct tlist
*
2380 new_tlist (struct tlist
*next
, tree t
, tree writer
)
2383 l
= XOBNEW (&tlist_obstack
, struct tlist
);
2390 /* Add duplicates of the nodes found in ADD to the list *TO. If EXCLUDE_WRITER
2391 is nonnull, we ignore any node we find which has a writer equal to it. */
2394 add_tlist (struct tlist
**to
, struct tlist
*add
, tree exclude_writer
, int copy
)
2398 struct tlist
*next
= add
->next
;
2401 if (!exclude_writer
|| !candidate_equal_p (add
->writer
, exclude_writer
))
2402 *to
= copy
? new_tlist (*to
, add
->expr
, add
->writer
) : add
;
2407 /* Merge the nodes of ADD into TO. This merging process is done so that for
2408 each variable that already exists in TO, no new node is added; however if
2409 there is a write access recorded in ADD, and an occurrence on TO is only
2410 a read access, then the occurrence in TO will be modified to record the
2414 merge_tlist (struct tlist
**to
, struct tlist
*add
, int copy
)
2416 struct tlist
**end
= to
;
2419 end
= &(*end
)->next
;
2425 struct tlist
*next
= add
->next
;
2427 for (tmp2
= *to
; tmp2
; tmp2
= tmp2
->next
)
2428 if (candidate_equal_p (tmp2
->expr
, add
->expr
))
2432 tmp2
->writer
= add
->writer
;
2436 *end
= copy
? add
: new_tlist (NULL
, add
->expr
, add
->writer
);
2437 end
= &(*end
)->next
;
2444 /* WRITTEN is a variable, WRITER is its parent. Warn if any of the variable
2445 references in list LIST conflict with it, excluding reads if ONLY writers
2449 warn_for_collisions_1 (tree written
, tree writer
, struct tlist
*list
,
2454 /* Avoid duplicate warnings. */
2455 for (tmp
= warned_ids
; tmp
; tmp
= tmp
->next
)
2456 if (candidate_equal_p (tmp
->expr
, written
))
2461 if (candidate_equal_p (list
->expr
, written
)
2462 && !candidate_equal_p (list
->writer
, writer
)
2463 && (!only_writes
|| list
->writer
))
2465 warned_ids
= new_tlist (warned_ids
, written
, NULL_TREE
);
2466 warning_at (EXPR_HAS_LOCATION (writer
)
2467 ? EXPR_LOCATION (writer
) : input_location
,
2468 OPT_Wsequence_point
, "operation on %qE may be undefined",
2475 /* Given a list LIST of references to variables, find whether any of these
2476 can cause conflicts due to missing sequence points. */
2479 warn_for_collisions (struct tlist
*list
)
2483 for (tmp
= list
; tmp
; tmp
= tmp
->next
)
2486 warn_for_collisions_1 (tmp
->expr
, tmp
->writer
, list
, 0);
2490 /* Return nonzero if X is a tree that can be verified by the sequence point
2493 warning_candidate_p (tree x
)
2495 /* !VOID_TYPE_P (TREE_TYPE (x)) is workaround for cp/tree.c
2496 (lvalue_p) crash on TRY/CATCH. */
2497 return !(DECL_P (x
) && DECL_ARTIFICIAL (x
))
2498 && TREE_TYPE (x
) && !VOID_TYPE_P (TREE_TYPE (x
)) && lvalue_p (x
);
2501 /* Return nonzero if X and Y appear to be the same candidate (or NULL) */
2503 candidate_equal_p (const_tree x
, const_tree y
)
2505 return (x
== y
) || (x
&& y
&& operand_equal_p (x
, y
, 0));
2508 /* Walk the tree X, and record accesses to variables. If X is written by the
2509 parent tree, WRITER is the parent.
2510 We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP. If this
2511 expression or its only operand forces a sequence point, then everything up
2512 to the sequence point is stored in PBEFORE_SP. Everything else gets stored
2514 Once we return, we will have emitted warnings if any subexpression before
2515 such a sequence point could be undefined. On a higher level, however, the
2516 sequence point may not be relevant, and we'll merge the two lists.
2518 Example: (b++, a) + b;
2519 The call that processes the COMPOUND_EXPR will store the increment of B
2520 in PBEFORE_SP, and the use of A in PNO_SP. The higher-level call that
2521 processes the PLUS_EXPR will need to merge the two lists so that
2522 eventually, all accesses end up on the same list (and we'll warn about the
2523 unordered subexpressions b++ and b.
2525 A note on merging. If we modify the former example so that our expression
2528 care must be taken not simply to add all three expressions into the final
2529 PNO_SP list. The function merge_tlist takes care of that by merging the
2530 before-SP list of the COMPOUND_EXPR into its after-SP list in a special
2531 way, so that no more than one access to B is recorded. */
2534 verify_tree (tree x
, struct tlist
**pbefore_sp
, struct tlist
**pno_sp
,
2537 struct tlist
*tmp_before
, *tmp_nosp
, *tmp_list2
, *tmp_list3
;
2538 enum tree_code code
;
2539 enum tree_code_class cl
;
2541 /* X may be NULL if it is the operand of an empty statement expression
2547 code
= TREE_CODE (x
);
2548 cl
= TREE_CODE_CLASS (code
);
2550 if (warning_candidate_p (x
))
2551 *pno_sp
= new_tlist (*pno_sp
, x
, writer
);
2559 case TRUTH_ANDIF_EXPR
:
2560 case TRUTH_ORIF_EXPR
:
2561 tmp_before
= tmp_nosp
= tmp_list3
= 0;
2562 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
2563 warn_for_collisions (tmp_nosp
);
2564 merge_tlist (pbefore_sp
, tmp_before
, 0);
2565 merge_tlist (pbefore_sp
, tmp_nosp
, 0);
2566 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, pno_sp
, NULL_TREE
);
2567 merge_tlist (pbefore_sp
, tmp_list3
, 0);
2571 tmp_before
= tmp_list2
= 0;
2572 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_list2
, NULL_TREE
);
2573 warn_for_collisions (tmp_list2
);
2574 merge_tlist (pbefore_sp
, tmp_before
, 0);
2575 merge_tlist (pbefore_sp
, tmp_list2
, 1);
2577 tmp_list3
= tmp_nosp
= 0;
2578 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, &tmp_nosp
, NULL_TREE
);
2579 warn_for_collisions (tmp_nosp
);
2580 merge_tlist (pbefore_sp
, tmp_list3
, 0);
2582 tmp_list3
= tmp_list2
= 0;
2583 verify_tree (TREE_OPERAND (x
, 2), &tmp_list3
, &tmp_list2
, NULL_TREE
);
2584 warn_for_collisions (tmp_list2
);
2585 merge_tlist (pbefore_sp
, tmp_list3
, 0);
2586 /* Rather than add both tmp_nosp and tmp_list2, we have to merge the
2587 two first, to avoid warning for (a ? b++ : b++). */
2588 merge_tlist (&tmp_nosp
, tmp_list2
, 0);
2589 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
2592 case PREDECREMENT_EXPR
:
2593 case PREINCREMENT_EXPR
:
2594 case POSTDECREMENT_EXPR
:
2595 case POSTINCREMENT_EXPR
:
2596 verify_tree (TREE_OPERAND (x
, 0), pno_sp
, pno_sp
, x
);
2600 tmp_before
= tmp_nosp
= tmp_list3
= 0;
2601 verify_tree (TREE_OPERAND (x
, 1), &tmp_before
, &tmp_nosp
, NULL_TREE
);
2602 verify_tree (TREE_OPERAND (x
, 0), &tmp_list3
, &tmp_list3
, x
);
2603 /* Expressions inside the LHS are not ordered wrt. the sequence points
2604 in the RHS. Example:
2606 Despite the fact that the modification of "a" is in the before_sp
2607 list (tmp_before), it conflicts with the use of "a" in the LHS.
2608 We can handle this by adding the contents of tmp_list3
2609 to those of tmp_before, and redoing the collision warnings for that
2611 add_tlist (&tmp_before
, tmp_list3
, x
, 1);
2612 warn_for_collisions (tmp_before
);
2613 /* Exclude the LHS itself here; we first have to merge it into the
2614 tmp_nosp list. This is done to avoid warning for "a = a"; if we
2615 didn't exclude the LHS, we'd get it twice, once as a read and once
2617 add_tlist (pno_sp
, tmp_list3
, x
, 0);
2618 warn_for_collisions_1 (TREE_OPERAND (x
, 0), x
, tmp_nosp
, 1);
2620 merge_tlist (pbefore_sp
, tmp_before
, 0);
2621 if (warning_candidate_p (TREE_OPERAND (x
, 0)))
2622 merge_tlist (&tmp_nosp
, new_tlist (NULL
, TREE_OPERAND (x
, 0), x
), 0);
2623 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 1);
2627 /* We need to warn about conflicts among arguments and conflicts between
2628 args and the function address. Side effects of the function address,
2629 however, are not ordered by the sequence point of the call. */
2631 call_expr_arg_iterator iter
;
2633 tmp_before
= tmp_nosp
= 0;
2634 verify_tree (CALL_EXPR_FN (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
2635 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, x
)
2637 tmp_list2
= tmp_list3
= 0;
2638 verify_tree (arg
, &tmp_list2
, &tmp_list3
, NULL_TREE
);
2639 merge_tlist (&tmp_list3
, tmp_list2
, 0);
2640 add_tlist (&tmp_before
, tmp_list3
, NULL_TREE
, 0);
2642 add_tlist (&tmp_before
, tmp_nosp
, NULL_TREE
, 0);
2643 warn_for_collisions (tmp_before
);
2644 add_tlist (pbefore_sp
, tmp_before
, NULL_TREE
, 0);
2649 /* Scan all the list, e.g. indices of multi dimensional array. */
2652 tmp_before
= tmp_nosp
= 0;
2653 verify_tree (TREE_VALUE (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
2654 merge_tlist (&tmp_nosp
, tmp_before
, 0);
2655 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
2662 struct tlist_cache
*t
;
2663 for (t
= save_expr_cache
; t
; t
= t
->next
)
2664 if (candidate_equal_p (t
->expr
, x
))
2669 t
= XOBNEW (&tlist_obstack
, struct tlist_cache
);
2670 t
->next
= save_expr_cache
;
2672 save_expr_cache
= t
;
2674 tmp_before
= tmp_nosp
= 0;
2675 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
2676 warn_for_collisions (tmp_nosp
);
2681 struct tlist
*t
= tmp_nosp
;
2683 merge_tlist (&tmp_list3
, t
, 0);
2685 t
->cache_before_sp
= tmp_before
;
2686 t
->cache_after_sp
= tmp_list3
;
2688 merge_tlist (pbefore_sp
, t
->cache_before_sp
, 1);
2689 add_tlist (pno_sp
, t
->cache_after_sp
, NULL_TREE
, 1);
2694 x
= TREE_OPERAND (x
, 0);
2701 /* For other expressions, simply recurse on their operands.
2702 Manual tail recursion for unary expressions.
2703 Other non-expressions need not be processed. */
2704 if (cl
== tcc_unary
)
2706 x
= TREE_OPERAND (x
, 0);
2710 else if (IS_EXPR_CODE_CLASS (cl
))
2713 int max
= TREE_OPERAND_LENGTH (x
);
2714 for (lp
= 0; lp
< max
; lp
++)
2716 tmp_before
= tmp_nosp
= 0;
2717 verify_tree (TREE_OPERAND (x
, lp
), &tmp_before
, &tmp_nosp
, 0);
2718 merge_tlist (&tmp_nosp
, tmp_before
, 0);
2719 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
2726 /* Try to warn for undefined behavior in EXPR due to missing sequence
2730 verify_sequence_points (tree expr
)
2732 struct tlist
*before_sp
= 0, *after_sp
= 0;
2735 save_expr_cache
= 0;
2736 if (tlist_firstobj
== 0)
2738 gcc_obstack_init (&tlist_obstack
);
2739 tlist_firstobj
= (char *) obstack_alloc (&tlist_obstack
, 0);
2742 verify_tree (expr
, &before_sp
, &after_sp
, 0);
2743 warn_for_collisions (after_sp
);
2744 obstack_free (&tlist_obstack
, tlist_firstobj
);
2747 /* Validate the expression after `case' and apply default promotions. */
2750 check_case_value (tree value
)
2752 if (value
== NULL_TREE
)
2755 /* ??? Can we ever get nops here for a valid case value? We
2757 STRIP_TYPE_NOPS (value
);
2758 /* In C++, the following is allowed:
2761 switch (...) { case i: ... }
2763 So, we try to reduce the VALUE to a constant that way. */
2764 if (c_dialect_cxx ())
2766 value
= decl_constant_value (value
);
2767 STRIP_TYPE_NOPS (value
);
2768 value
= fold (value
);
2771 if (TREE_CODE (value
) == INTEGER_CST
)
2772 /* Promote char or short to int. */
2773 value
= perform_integral_promotions (value
);
2774 else if (value
!= error_mark_node
)
2776 error ("case label does not reduce to an integer constant");
2777 value
= error_mark_node
;
2780 constant_expression_warning (value
);
2785 /* See if the case values LOW and HIGH are in the range of the original
2786 type (i.e. before the default conversion to int) of the switch testing
2788 TYPE is the promoted type of the testing expression, and ORIG_TYPE is
2789 the type before promoting it. CASE_LOW_P is a pointer to the lower
2790 bound of the case label, and CASE_HIGH_P is the upper bound or NULL
2791 if the case is not a case range.
2792 The caller has to make sure that we are not called with NULL for
2793 CASE_LOW_P (i.e. the default case).
2794 Returns true if the case label is in range of ORIG_TYPE (saturated or
2795 untouched) or false if the label is out of range. */
2798 check_case_bounds (tree type
, tree orig_type
,
2799 tree
*case_low_p
, tree
*case_high_p
)
2801 tree min_value
, max_value
;
2802 tree case_low
= *case_low_p
;
2803 tree case_high
= case_high_p
? *case_high_p
: case_low
;
2805 /* If there was a problem with the original type, do nothing. */
2806 if (orig_type
== error_mark_node
)
2809 min_value
= TYPE_MIN_VALUE (orig_type
);
2810 max_value
= TYPE_MAX_VALUE (orig_type
);
2812 /* Case label is less than minimum for type. */
2813 if (tree_int_cst_compare (case_low
, min_value
) < 0
2814 && tree_int_cst_compare (case_high
, min_value
) < 0)
2816 warning (0, "case label value is less than minimum value for type");
2820 /* Case value is greater than maximum for type. */
2821 if (tree_int_cst_compare (case_low
, max_value
) > 0
2822 && tree_int_cst_compare (case_high
, max_value
) > 0)
2824 warning (0, "case label value exceeds maximum value for type");
2828 /* Saturate lower case label value to minimum. */
2829 if (tree_int_cst_compare (case_high
, min_value
) >= 0
2830 && tree_int_cst_compare (case_low
, min_value
) < 0)
2832 warning (0, "lower value in case label range"
2833 " less than minimum value for type");
2834 case_low
= min_value
;
2837 /* Saturate upper case label value to maximum. */
2838 if (tree_int_cst_compare (case_low
, max_value
) <= 0
2839 && tree_int_cst_compare (case_high
, max_value
) > 0)
2841 warning (0, "upper value in case label range"
2842 " exceeds maximum value for type");
2843 case_high
= max_value
;
2846 if (*case_low_p
!= case_low
)
2847 *case_low_p
= convert (type
, case_low
);
2848 if (case_high_p
&& *case_high_p
!= case_high
)
2849 *case_high_p
= convert (type
, case_high
);
2854 /* Return an integer type with BITS bits of precision,
2855 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
2858 c_common_type_for_size (unsigned int bits
, int unsignedp
)
2860 if (bits
== TYPE_PRECISION (integer_type_node
))
2861 return unsignedp
? unsigned_type_node
: integer_type_node
;
2863 if (bits
== TYPE_PRECISION (signed_char_type_node
))
2864 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
2866 if (bits
== TYPE_PRECISION (short_integer_type_node
))
2867 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
2869 if (bits
== TYPE_PRECISION (long_integer_type_node
))
2870 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
2872 if (bits
== TYPE_PRECISION (long_long_integer_type_node
))
2873 return (unsignedp
? long_long_unsigned_type_node
2874 : long_long_integer_type_node
);
2876 if (int128_integer_type_node
2877 && bits
== TYPE_PRECISION (int128_integer_type_node
))
2878 return (unsignedp
? int128_unsigned_type_node
2879 : int128_integer_type_node
);
2881 if (bits
== TYPE_PRECISION (widest_integer_literal_type_node
))
2882 return (unsignedp
? widest_unsigned_literal_type_node
2883 : widest_integer_literal_type_node
);
2885 if (bits
<= TYPE_PRECISION (intQI_type_node
))
2886 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
2888 if (bits
<= TYPE_PRECISION (intHI_type_node
))
2889 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
2891 if (bits
<= TYPE_PRECISION (intSI_type_node
))
2892 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
2894 if (bits
<= TYPE_PRECISION (intDI_type_node
))
2895 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
2900 /* Return a fixed-point type that has at least IBIT ibits and FBIT fbits
2901 that is unsigned if UNSIGNEDP is nonzero, otherwise signed;
2902 and saturating if SATP is nonzero, otherwise not saturating. */
2905 c_common_fixed_point_type_for_size (unsigned int ibit
, unsigned int fbit
,
2906 int unsignedp
, int satp
)
2908 enum machine_mode mode
;
2910 mode
= unsignedp
? UQQmode
: QQmode
;
2912 mode
= unsignedp
? UHAmode
: HAmode
;
2914 for (; mode
!= VOIDmode
; mode
= GET_MODE_WIDER_MODE (mode
))
2915 if (GET_MODE_IBIT (mode
) >= ibit
&& GET_MODE_FBIT (mode
) >= fbit
)
2918 if (mode
== VOIDmode
|| !targetm
.scalar_mode_supported_p (mode
))
2920 sorry ("GCC cannot support operators with integer types and "
2921 "fixed-point types that have too many integral and "
2922 "fractional bits together");
2926 return c_common_type_for_mode (mode
, satp
);
2929 /* Used for communication between c_common_type_for_mode and
2930 c_register_builtin_type. */
2931 static GTY(()) tree registered_builtin_types
;
2933 /* Return a data type that has machine mode MODE.
2934 If the mode is an integer,
2935 then UNSIGNEDP selects between signed and unsigned types.
2936 If the mode is a fixed-point mode,
2937 then UNSIGNEDP selects between saturating and nonsaturating types. */
2940 c_common_type_for_mode (enum machine_mode mode
, int unsignedp
)
2944 if (mode
== TYPE_MODE (integer_type_node
))
2945 return unsignedp
? unsigned_type_node
: integer_type_node
;
2947 if (mode
== TYPE_MODE (signed_char_type_node
))
2948 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
2950 if (mode
== TYPE_MODE (short_integer_type_node
))
2951 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
2953 if (mode
== TYPE_MODE (long_integer_type_node
))
2954 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
2956 if (mode
== TYPE_MODE (long_long_integer_type_node
))
2957 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
2959 if (int128_integer_type_node
2960 && mode
== TYPE_MODE (int128_integer_type_node
))
2961 return unsignedp
? int128_unsigned_type_node
: int128_integer_type_node
;
2963 if (mode
== TYPE_MODE (widest_integer_literal_type_node
))
2964 return unsignedp
? widest_unsigned_literal_type_node
2965 : widest_integer_literal_type_node
;
2968 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
2971 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
2974 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
2977 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
2979 #if HOST_BITS_PER_WIDE_INT >= 64
2980 if (mode
== TYPE_MODE (intTI_type_node
))
2981 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
2984 if (mode
== TYPE_MODE (float_type_node
))
2985 return float_type_node
;
2987 if (mode
== TYPE_MODE (double_type_node
))
2988 return double_type_node
;
2990 if (mode
== TYPE_MODE (long_double_type_node
))
2991 return long_double_type_node
;
2993 if (mode
== TYPE_MODE (void_type_node
))
2994 return void_type_node
;
2996 if (mode
== TYPE_MODE (build_pointer_type (char_type_node
)))
2998 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
2999 : make_signed_type (GET_MODE_PRECISION (mode
)));
3001 if (mode
== TYPE_MODE (build_pointer_type (integer_type_node
)))
3003 ? make_unsigned_type (GET_MODE_PRECISION (mode
))
3004 : make_signed_type (GET_MODE_PRECISION (mode
)));
3006 if (COMPLEX_MODE_P (mode
))
3008 enum machine_mode inner_mode
;
3011 if (mode
== TYPE_MODE (complex_float_type_node
))
3012 return complex_float_type_node
;
3013 if (mode
== TYPE_MODE (complex_double_type_node
))
3014 return complex_double_type_node
;
3015 if (mode
== TYPE_MODE (complex_long_double_type_node
))
3016 return complex_long_double_type_node
;
3018 if (mode
== TYPE_MODE (complex_integer_type_node
) && !unsignedp
)
3019 return complex_integer_type_node
;
3021 inner_mode
= GET_MODE_INNER (mode
);
3022 inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3023 if (inner_type
!= NULL_TREE
)
3024 return build_complex_type (inner_type
);
3026 else if (VECTOR_MODE_P (mode
))
3028 enum machine_mode inner_mode
= GET_MODE_INNER (mode
);
3029 tree inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
3030 if (inner_type
!= NULL_TREE
)
3031 return build_vector_type_for_mode (inner_type
, mode
);
3034 if (mode
== TYPE_MODE (dfloat32_type_node
))
3035 return dfloat32_type_node
;
3036 if (mode
== TYPE_MODE (dfloat64_type_node
))
3037 return dfloat64_type_node
;
3038 if (mode
== TYPE_MODE (dfloat128_type_node
))
3039 return dfloat128_type_node
;
3041 if (ALL_SCALAR_FIXED_POINT_MODE_P (mode
))
3043 if (mode
== TYPE_MODE (short_fract_type_node
))
3044 return unsignedp
? sat_short_fract_type_node
: short_fract_type_node
;
3045 if (mode
== TYPE_MODE (fract_type_node
))
3046 return unsignedp
? sat_fract_type_node
: fract_type_node
;
3047 if (mode
== TYPE_MODE (long_fract_type_node
))
3048 return unsignedp
? sat_long_fract_type_node
: long_fract_type_node
;
3049 if (mode
== TYPE_MODE (long_long_fract_type_node
))
3050 return unsignedp
? sat_long_long_fract_type_node
3051 : long_long_fract_type_node
;
3053 if (mode
== TYPE_MODE (unsigned_short_fract_type_node
))
3054 return unsignedp
? sat_unsigned_short_fract_type_node
3055 : unsigned_short_fract_type_node
;
3056 if (mode
== TYPE_MODE (unsigned_fract_type_node
))
3057 return unsignedp
? sat_unsigned_fract_type_node
3058 : unsigned_fract_type_node
;
3059 if (mode
== TYPE_MODE (unsigned_long_fract_type_node
))
3060 return unsignedp
? sat_unsigned_long_fract_type_node
3061 : unsigned_long_fract_type_node
;
3062 if (mode
== TYPE_MODE (unsigned_long_long_fract_type_node
))
3063 return unsignedp
? sat_unsigned_long_long_fract_type_node
3064 : unsigned_long_long_fract_type_node
;
3066 if (mode
== TYPE_MODE (short_accum_type_node
))
3067 return unsignedp
? sat_short_accum_type_node
: short_accum_type_node
;
3068 if (mode
== TYPE_MODE (accum_type_node
))
3069 return unsignedp
? sat_accum_type_node
: accum_type_node
;
3070 if (mode
== TYPE_MODE (long_accum_type_node
))
3071 return unsignedp
? sat_long_accum_type_node
: long_accum_type_node
;
3072 if (mode
== TYPE_MODE (long_long_accum_type_node
))
3073 return unsignedp
? sat_long_long_accum_type_node
3074 : long_long_accum_type_node
;
3076 if (mode
== TYPE_MODE (unsigned_short_accum_type_node
))
3077 return unsignedp
? sat_unsigned_short_accum_type_node
3078 : unsigned_short_accum_type_node
;
3079 if (mode
== TYPE_MODE (unsigned_accum_type_node
))
3080 return unsignedp
? sat_unsigned_accum_type_node
3081 : unsigned_accum_type_node
;
3082 if (mode
== TYPE_MODE (unsigned_long_accum_type_node
))
3083 return unsignedp
? sat_unsigned_long_accum_type_node
3084 : unsigned_long_accum_type_node
;
3085 if (mode
== TYPE_MODE (unsigned_long_long_accum_type_node
))
3086 return unsignedp
? sat_unsigned_long_long_accum_type_node
3087 : unsigned_long_long_accum_type_node
;
3090 return unsignedp
? sat_qq_type_node
: qq_type_node
;
3092 return unsignedp
? sat_hq_type_node
: hq_type_node
;
3094 return unsignedp
? sat_sq_type_node
: sq_type_node
;
3096 return unsignedp
? sat_dq_type_node
: dq_type_node
;
3098 return unsignedp
? sat_tq_type_node
: tq_type_node
;
3100 if (mode
== UQQmode
)
3101 return unsignedp
? sat_uqq_type_node
: uqq_type_node
;
3102 if (mode
== UHQmode
)
3103 return unsignedp
? sat_uhq_type_node
: uhq_type_node
;
3104 if (mode
== USQmode
)
3105 return unsignedp
? sat_usq_type_node
: usq_type_node
;
3106 if (mode
== UDQmode
)
3107 return unsignedp
? sat_udq_type_node
: udq_type_node
;
3108 if (mode
== UTQmode
)
3109 return unsignedp
? sat_utq_type_node
: utq_type_node
;
3112 return unsignedp
? sat_ha_type_node
: ha_type_node
;
3114 return unsignedp
? sat_sa_type_node
: sa_type_node
;
3116 return unsignedp
? sat_da_type_node
: da_type_node
;
3118 return unsignedp
? sat_ta_type_node
: ta_type_node
;
3120 if (mode
== UHAmode
)
3121 return unsignedp
? sat_uha_type_node
: uha_type_node
;
3122 if (mode
== USAmode
)
3123 return unsignedp
? sat_usa_type_node
: usa_type_node
;
3124 if (mode
== UDAmode
)
3125 return unsignedp
? sat_uda_type_node
: uda_type_node
;
3126 if (mode
== UTAmode
)
3127 return unsignedp
? sat_uta_type_node
: uta_type_node
;
3130 for (t
= registered_builtin_types
; t
; t
= TREE_CHAIN (t
))
3131 if (TYPE_MODE (TREE_VALUE (t
)) == mode
)
3132 return TREE_VALUE (t
);
3138 c_common_unsigned_type (tree type
)
3140 return c_common_signed_or_unsigned_type (1, type
);
3143 /* Return a signed type the same as TYPE in other respects. */
3146 c_common_signed_type (tree type
)
3148 return c_common_signed_or_unsigned_type (0, type
);
3151 /* Return a type the same as TYPE except unsigned or
3152 signed according to UNSIGNEDP. */
3155 c_common_signed_or_unsigned_type (int unsignedp
, tree type
)
3159 /* This block of code emulates the behavior of the old
3160 c_common_unsigned_type. In particular, it returns
3161 long_unsigned_type_node if passed a long, even when a int would
3162 have the same size. This is necessary for warnings to work
3163 correctly in archs where sizeof(int) == sizeof(long) */
3165 type1
= TYPE_MAIN_VARIANT (type
);
3166 if (type1
== signed_char_type_node
|| type1
== char_type_node
|| type1
== unsigned_char_type_node
)
3167 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3168 if (type1
== integer_type_node
|| type1
== unsigned_type_node
)
3169 return unsignedp
? unsigned_type_node
: integer_type_node
;
3170 if (type1
== short_integer_type_node
|| type1
== short_unsigned_type_node
)
3171 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3172 if (type1
== long_integer_type_node
|| type1
== long_unsigned_type_node
)
3173 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3174 if (type1
== long_long_integer_type_node
|| type1
== long_long_unsigned_type_node
)
3175 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
3176 if (int128_integer_type_node
3177 && (type1
== int128_integer_type_node
3178 || type1
== int128_unsigned_type_node
))
3179 return unsignedp
? int128_unsigned_type_node
: int128_integer_type_node
;
3180 if (type1
== widest_integer_literal_type_node
|| type1
== widest_unsigned_literal_type_node
)
3181 return unsignedp
? widest_unsigned_literal_type_node
: widest_integer_literal_type_node
;
3182 #if HOST_BITS_PER_WIDE_INT >= 64
3183 if (type1
== intTI_type_node
|| type1
== unsigned_intTI_type_node
)
3184 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3186 if (type1
== intDI_type_node
|| type1
== unsigned_intDI_type_node
)
3187 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3188 if (type1
== intSI_type_node
|| type1
== unsigned_intSI_type_node
)
3189 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3190 if (type1
== intHI_type_node
|| type1
== unsigned_intHI_type_node
)
3191 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3192 if (type1
== intQI_type_node
|| type1
== unsigned_intQI_type_node
)
3193 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3195 #define C_COMMON_FIXED_TYPES(NAME) \
3196 if (type1 == short_ ## NAME ## _type_node \
3197 || type1 == unsigned_short_ ## NAME ## _type_node) \
3198 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
3199 : short_ ## NAME ## _type_node; \
3200 if (type1 == NAME ## _type_node \
3201 || type1 == unsigned_ ## NAME ## _type_node) \
3202 return unsignedp ? unsigned_ ## NAME ## _type_node \
3203 : NAME ## _type_node; \
3204 if (type1 == long_ ## NAME ## _type_node \
3205 || type1 == unsigned_long_ ## NAME ## _type_node) \
3206 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
3207 : long_ ## NAME ## _type_node; \
3208 if (type1 == long_long_ ## NAME ## _type_node \
3209 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
3210 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
3211 : long_long_ ## NAME ## _type_node;
3213 #define C_COMMON_FIXED_MODE_TYPES(NAME) \
3214 if (type1 == NAME ## _type_node \
3215 || type1 == u ## NAME ## _type_node) \
3216 return unsignedp ? u ## NAME ## _type_node \
3217 : NAME ## _type_node;
3219 #define C_COMMON_FIXED_TYPES_SAT(NAME) \
3220 if (type1 == sat_ ## short_ ## NAME ## _type_node \
3221 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
3222 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
3223 : sat_ ## short_ ## NAME ## _type_node; \
3224 if (type1 == sat_ ## NAME ## _type_node \
3225 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
3226 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
3227 : sat_ ## NAME ## _type_node; \
3228 if (type1 == sat_ ## long_ ## NAME ## _type_node \
3229 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
3230 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
3231 : sat_ ## long_ ## NAME ## _type_node; \
3232 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
3233 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
3234 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
3235 : sat_ ## long_long_ ## NAME ## _type_node;
3237 #define C_COMMON_FIXED_MODE_TYPES_SAT(NAME) \
3238 if (type1 == sat_ ## NAME ## _type_node \
3239 || type1 == sat_ ## u ## NAME ## _type_node) \
3240 return unsignedp ? sat_ ## u ## NAME ## _type_node \
3241 : sat_ ## NAME ## _type_node;
3243 C_COMMON_FIXED_TYPES (fract
);
3244 C_COMMON_FIXED_TYPES_SAT (fract
);
3245 C_COMMON_FIXED_TYPES (accum
);
3246 C_COMMON_FIXED_TYPES_SAT (accum
);
3248 C_COMMON_FIXED_MODE_TYPES (qq
);
3249 C_COMMON_FIXED_MODE_TYPES (hq
);
3250 C_COMMON_FIXED_MODE_TYPES (sq
);
3251 C_COMMON_FIXED_MODE_TYPES (dq
);
3252 C_COMMON_FIXED_MODE_TYPES (tq
);
3253 C_COMMON_FIXED_MODE_TYPES_SAT (qq
);
3254 C_COMMON_FIXED_MODE_TYPES_SAT (hq
);
3255 C_COMMON_FIXED_MODE_TYPES_SAT (sq
);
3256 C_COMMON_FIXED_MODE_TYPES_SAT (dq
);
3257 C_COMMON_FIXED_MODE_TYPES_SAT (tq
);
3258 C_COMMON_FIXED_MODE_TYPES (ha
);
3259 C_COMMON_FIXED_MODE_TYPES (sa
);
3260 C_COMMON_FIXED_MODE_TYPES (da
);
3261 C_COMMON_FIXED_MODE_TYPES (ta
);
3262 C_COMMON_FIXED_MODE_TYPES_SAT (ha
);
3263 C_COMMON_FIXED_MODE_TYPES_SAT (sa
);
3264 C_COMMON_FIXED_MODE_TYPES_SAT (da
);
3265 C_COMMON_FIXED_MODE_TYPES_SAT (ta
);
3267 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
3268 the precision; they have precision set to match their range, but
3269 may use a wider mode to match an ABI. If we change modes, we may
3270 wind up with bad conversions. For INTEGER_TYPEs in C, must check
3271 the precision as well, so as to yield correct results for
3272 bit-field types. C++ does not have these separate bit-field
3273 types, and producing a signed or unsigned variant of an
3274 ENUMERAL_TYPE may cause other problems as well. */
3276 if (!INTEGRAL_TYPE_P (type
)
3277 || TYPE_UNSIGNED (type
) == unsignedp
)
3280 #define TYPE_OK(node) \
3281 (TYPE_MODE (type) == TYPE_MODE (node) \
3282 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
3283 if (TYPE_OK (signed_char_type_node
))
3284 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3285 if (TYPE_OK (integer_type_node
))
3286 return unsignedp
? unsigned_type_node
: integer_type_node
;
3287 if (TYPE_OK (short_integer_type_node
))
3288 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3289 if (TYPE_OK (long_integer_type_node
))
3290 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3291 if (TYPE_OK (long_long_integer_type_node
))
3292 return (unsignedp
? long_long_unsigned_type_node
3293 : long_long_integer_type_node
);
3294 if (int128_integer_type_node
&& TYPE_OK (int128_integer_type_node
))
3295 return (unsignedp
? int128_unsigned_type_node
3296 : int128_integer_type_node
);
3297 if (TYPE_OK (widest_integer_literal_type_node
))
3298 return (unsignedp
? widest_unsigned_literal_type_node
3299 : widest_integer_literal_type_node
);
3301 #if HOST_BITS_PER_WIDE_INT >= 64
3302 if (TYPE_OK (intTI_type_node
))
3303 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3305 if (TYPE_OK (intDI_type_node
))
3306 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3307 if (TYPE_OK (intSI_type_node
))
3308 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3309 if (TYPE_OK (intHI_type_node
))
3310 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3311 if (TYPE_OK (intQI_type_node
))
3312 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
3315 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
3318 /* Build a bit-field integer type for the given WIDTH and UNSIGNEDP. */
3321 c_build_bitfield_integer_type (unsigned HOST_WIDE_INT width
, int unsignedp
)
3323 /* Extended integer types of the same width as a standard type have
3324 lesser rank, so those of the same width as int promote to int or
3325 unsigned int and are valid for printf formats expecting int or
3326 unsigned int. To avoid such special cases, avoid creating
3327 extended integer types for bit-fields if a standard integer type
3329 if (width
== TYPE_PRECISION (integer_type_node
))
3330 return unsignedp
? unsigned_type_node
: integer_type_node
;
3331 if (width
== TYPE_PRECISION (signed_char_type_node
))
3332 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3333 if (width
== TYPE_PRECISION (short_integer_type_node
))
3334 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3335 if (width
== TYPE_PRECISION (long_integer_type_node
))
3336 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3337 if (width
== TYPE_PRECISION (long_long_integer_type_node
))
3338 return (unsignedp
? long_long_unsigned_type_node
3339 : long_long_integer_type_node
);
3340 if (int128_integer_type_node
3341 && width
== TYPE_PRECISION (int128_integer_type_node
))
3342 return (unsignedp
? int128_unsigned_type_node
3343 : int128_integer_type_node
);
3344 return build_nonstandard_integer_type (width
, unsignedp
);
3347 /* The C version of the register_builtin_type langhook. */
3350 c_register_builtin_type (tree type
, const char* name
)
3354 decl
= build_decl (UNKNOWN_LOCATION
,
3355 TYPE_DECL
, get_identifier (name
), type
);
3356 DECL_ARTIFICIAL (decl
) = 1;
3357 if (!TYPE_NAME (type
))
3358 TYPE_NAME (type
) = decl
;
3361 registered_builtin_types
= tree_cons (0, type
, registered_builtin_types
);
3364 /* Print an error message for invalid operands to arith operation
3365 CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
3366 LOCATION is the location of the message. */
3369 binary_op_error (location_t location
, enum tree_code code
,
3370 tree type0
, tree type1
)
3377 opname
= "+"; break;
3379 opname
= "-"; break;
3381 opname
= "*"; break;
3383 opname
= "max"; break;
3385 opname
= "min"; break;
3387 opname
= "=="; break;
3389 opname
= "!="; break;
3391 opname
= "<="; break;
3393 opname
= ">="; break;
3395 opname
= "<"; break;
3397 opname
= ">"; break;
3399 opname
= "<<"; break;
3401 opname
= ">>"; break;
3402 case TRUNC_MOD_EXPR
:
3403 case FLOOR_MOD_EXPR
:
3404 opname
= "%"; break;
3405 case TRUNC_DIV_EXPR
:
3406 case FLOOR_DIV_EXPR
:
3407 opname
= "/"; break;
3409 opname
= "&"; break;
3411 opname
= "|"; break;
3412 case TRUTH_ANDIF_EXPR
:
3413 opname
= "&&"; break;
3414 case TRUTH_ORIF_EXPR
:
3415 opname
= "||"; break;
3417 opname
= "^"; break;
3422 "invalid operands to binary %s (have %qT and %qT)", opname
,
3426 /* Subroutine of build_binary_op, used for comparison operations.
3427 See if the operands have both been converted from subword integer types
3428 and, if so, perhaps change them both back to their original type.
3429 This function is also responsible for converting the two operands
3430 to the proper common type for comparison.
3432 The arguments of this function are all pointers to local variables
3433 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
3434 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
3436 If this function returns nonzero, it means that the comparison has
3437 a constant value. What this function returns is an expression for
3441 shorten_compare (tree
*op0_ptr
, tree
*op1_ptr
, tree
*restype_ptr
,
3442 enum tree_code
*rescode_ptr
)
3445 tree op0
= *op0_ptr
;
3446 tree op1
= *op1_ptr
;
3447 int unsignedp0
, unsignedp1
;
3449 tree primop0
, primop1
;
3450 enum tree_code code
= *rescode_ptr
;
3452 /* Throw away any conversions to wider types
3453 already present in the operands. */
3455 primop0
= get_narrower (op0
, &unsignedp0
);
3456 primop1
= get_narrower (op1
, &unsignedp1
);
3458 /* Handle the case that OP0 does not *contain* a conversion
3459 but it *requires* conversion to FINAL_TYPE. */
3461 if (op0
== primop0
&& TREE_TYPE (op0
) != *restype_ptr
)
3462 unsignedp0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
3463 if (op1
== primop1
&& TREE_TYPE (op1
) != *restype_ptr
)
3464 unsignedp1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
3466 /* If one of the operands must be floated, we cannot optimize. */
3467 real1
= TREE_CODE (TREE_TYPE (primop0
)) == REAL_TYPE
;
3468 real2
= TREE_CODE (TREE_TYPE (primop1
)) == REAL_TYPE
;
3470 /* If first arg is constant, swap the args (changing operation
3471 so value is preserved), for canonicalization. Don't do this if
3472 the second arg is 0. */
3474 if (TREE_CONSTANT (primop0
)
3475 && !integer_zerop (primop1
) && !real_zerop (primop1
)
3476 && !fixed_zerop (primop1
))
3479 int temi
= unsignedp0
;
3487 unsignedp0
= unsignedp1
;
3510 *rescode_ptr
= code
;
3513 /* If comparing an integer against a constant more bits wide,
3514 maybe we can deduce a value of 1 or 0 independent of the data.
3515 Or else truncate the constant now
3516 rather than extend the variable at run time.
3518 This is only interesting if the constant is the wider arg.
3519 Also, it is not safe if the constant is unsigned and the
3520 variable arg is signed, since in this case the variable
3521 would be sign-extended and then regarded as unsigned.
3522 Our technique fails in this case because the lowest/highest
3523 possible unsigned results don't follow naturally from the
3524 lowest/highest possible values of the variable operand.
3525 For just EQ_EXPR and NE_EXPR there is another technique that
3526 could be used: see if the constant can be faithfully represented
3527 in the other operand's type, by truncating it and reextending it
3528 and see if that preserves the constant's value. */
3530 if (!real1
&& !real2
3531 && TREE_CODE (TREE_TYPE (primop0
)) != FIXED_POINT_TYPE
3532 && TREE_CODE (primop1
) == INTEGER_CST
3533 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
))
3535 int min_gt
, max_gt
, min_lt
, max_lt
;
3536 tree maxval
, minval
;
3537 /* 1 if comparison is nominally unsigned. */
3538 int unsignedp
= TYPE_UNSIGNED (*restype_ptr
);
3541 type
= c_common_signed_or_unsigned_type (unsignedp0
,
3542 TREE_TYPE (primop0
));
3544 maxval
= TYPE_MAX_VALUE (type
);
3545 minval
= TYPE_MIN_VALUE (type
);
3547 if (unsignedp
&& !unsignedp0
)
3548 *restype_ptr
= c_common_signed_type (*restype_ptr
);
3550 if (TREE_TYPE (primop1
) != *restype_ptr
)
3552 /* Convert primop1 to target type, but do not introduce
3553 additional overflow. We know primop1 is an int_cst. */
3554 primop1
= force_fit_type_double (*restype_ptr
,
3555 TREE_INT_CST_LOW (primop1
),
3556 TREE_INT_CST_HIGH (primop1
), 0,
3557 TREE_OVERFLOW (primop1
));
3559 if (type
!= *restype_ptr
)
3561 minval
= convert (*restype_ptr
, minval
);
3562 maxval
= convert (*restype_ptr
, maxval
);
3565 if (unsignedp
&& unsignedp0
)
3567 min_gt
= INT_CST_LT_UNSIGNED (primop1
, minval
);
3568 max_gt
= INT_CST_LT_UNSIGNED (primop1
, maxval
);
3569 min_lt
= INT_CST_LT_UNSIGNED (minval
, primop1
);
3570 max_lt
= INT_CST_LT_UNSIGNED (maxval
, primop1
);
3574 min_gt
= INT_CST_LT (primop1
, minval
);
3575 max_gt
= INT_CST_LT (primop1
, maxval
);
3576 min_lt
= INT_CST_LT (minval
, primop1
);
3577 max_lt
= INT_CST_LT (maxval
, primop1
);
3581 /* This used to be a switch, but Genix compiler can't handle that. */
3582 if (code
== NE_EXPR
)
3584 if (max_lt
|| min_gt
)
3585 val
= truthvalue_true_node
;
3587 else if (code
== EQ_EXPR
)
3589 if (max_lt
|| min_gt
)
3590 val
= truthvalue_false_node
;
3592 else if (code
== LT_EXPR
)
3595 val
= truthvalue_true_node
;
3597 val
= truthvalue_false_node
;
3599 else if (code
== GT_EXPR
)
3602 val
= truthvalue_true_node
;
3604 val
= truthvalue_false_node
;
3606 else if (code
== LE_EXPR
)
3609 val
= truthvalue_true_node
;
3611 val
= truthvalue_false_node
;
3613 else if (code
== GE_EXPR
)
3616 val
= truthvalue_true_node
;
3618 val
= truthvalue_false_node
;
3621 /* If primop0 was sign-extended and unsigned comparison specd,
3622 we did a signed comparison above using the signed type bounds.
3623 But the comparison we output must be unsigned.
3625 Also, for inequalities, VAL is no good; but if the signed
3626 comparison had *any* fixed result, it follows that the
3627 unsigned comparison just tests the sign in reverse
3628 (positive values are LE, negative ones GE).
3629 So we can generate an unsigned comparison
3630 against an extreme value of the signed type. */
3632 if (unsignedp
&& !unsignedp0
)
3639 primop1
= TYPE_MIN_VALUE (type
);
3645 primop1
= TYPE_MAX_VALUE (type
);
3652 type
= c_common_unsigned_type (type
);
3655 if (TREE_CODE (primop0
) != INTEGER_CST
)
3657 if (val
== truthvalue_false_node
)
3658 warning (OPT_Wtype_limits
, "comparison is always false due to limited range of data type");
3659 if (val
== truthvalue_true_node
)
3660 warning (OPT_Wtype_limits
, "comparison is always true due to limited range of data type");
3665 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
3666 if (TREE_SIDE_EFFECTS (primop0
))
3667 return build2 (COMPOUND_EXPR
, TREE_TYPE (val
), primop0
, val
);
3671 /* Value is not predetermined, but do the comparison
3672 in the type of the operand that is not constant.
3673 TYPE is already properly set. */
3676 /* If either arg is decimal float and the other is float, find the
3677 proper common type to use for comparison. */
3678 else if (real1
&& real2
3679 && (DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0
)))
3680 || DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1
)))))
3681 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
3683 else if (real1
&& real2
3684 && (TYPE_PRECISION (TREE_TYPE (primop0
))
3685 == TYPE_PRECISION (TREE_TYPE (primop1
))))
3686 type
= TREE_TYPE (primop0
);
3688 /* If args' natural types are both narrower than nominal type
3689 and both extend in the same manner, compare them
3690 in the type of the wider arg.
3691 Otherwise must actually extend both to the nominal
3692 common type lest different ways of extending
3694 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
3696 else if (unsignedp0
== unsignedp1
&& real1
== real2
3697 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
)
3698 && TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (*restype_ptr
))
3700 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
3701 type
= c_common_signed_or_unsigned_type (unsignedp0
3702 || TYPE_UNSIGNED (*restype_ptr
),
3704 /* Make sure shorter operand is extended the right way
3705 to match the longer operand. */
3707 = convert (c_common_signed_or_unsigned_type (unsignedp0
,
3708 TREE_TYPE (primop0
)),
3711 = convert (c_common_signed_or_unsigned_type (unsignedp1
,
3712 TREE_TYPE (primop1
)),
3717 /* Here we must do the comparison on the nominal type
3718 using the args exactly as we received them. */
3719 type
= *restype_ptr
;
3723 if (!real1
&& !real2
&& integer_zerop (primop1
)
3724 && TYPE_UNSIGNED (*restype_ptr
))
3730 /* All unsigned values are >= 0, so we warn. However,
3731 if OP0 is a constant that is >= 0, the signedness of
3732 the comparison isn't an issue, so suppress the
3734 if (warn_type_limits
&& !in_system_header
3735 && !(TREE_CODE (primop0
) == INTEGER_CST
3736 && !TREE_OVERFLOW (convert (c_common_signed_type (type
),
3738 warning (OPT_Wtype_limits
,
3739 "comparison of unsigned expression >= 0 is always true");
3740 value
= truthvalue_true_node
;
3744 if (warn_type_limits
&& !in_system_header
3745 && !(TREE_CODE (primop0
) == INTEGER_CST
3746 && !TREE_OVERFLOW (convert (c_common_signed_type (type
),
3748 warning (OPT_Wtype_limits
,
3749 "comparison of unsigned expression < 0 is always false");
3750 value
= truthvalue_false_node
;
3759 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
3760 if (TREE_SIDE_EFFECTS (primop0
))
3761 return build2 (COMPOUND_EXPR
, TREE_TYPE (value
),
3768 *op0_ptr
= convert (type
, primop0
);
3769 *op1_ptr
= convert (type
, primop1
);
3771 *restype_ptr
= truthvalue_type_node
;
3776 /* Return a tree for the sum or difference (RESULTCODE says which)
3777 of pointer PTROP and integer INTOP. */
3780 pointer_int_sum (location_t loc
, enum tree_code resultcode
,
3781 tree ptrop
, tree intop
)
3785 /* The result is a pointer of the same type that is being added. */
3786 tree result_type
= TREE_TYPE (ptrop
);
3788 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
3790 pedwarn (loc
, pedantic
? OPT_pedantic
: OPT_Wpointer_arith
,
3791 "pointer of type %<void *%> used in arithmetic");
3792 size_exp
= integer_one_node
;
3794 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
3796 pedwarn (loc
, pedantic
? OPT_pedantic
: OPT_Wpointer_arith
,
3797 "pointer to a function used in arithmetic");
3798 size_exp
= integer_one_node
;
3800 else if (TREE_CODE (TREE_TYPE (result_type
)) == METHOD_TYPE
)
3802 pedwarn (loc
, pedantic
? OPT_pedantic
: OPT_Wpointer_arith
,
3803 "pointer to member function used in arithmetic");
3804 size_exp
= integer_one_node
;
3807 size_exp
= size_in_bytes (TREE_TYPE (result_type
));
3809 /* We are manipulating pointer values, so we don't need to warn
3810 about relying on undefined signed overflow. We disable the
3811 warning here because we use integer types so fold won't know that
3812 they are really pointers. */
3813 fold_defer_overflow_warnings ();
3815 /* If what we are about to multiply by the size of the elements
3816 contains a constant term, apply distributive law
3817 and multiply that constant term separately.
3818 This helps produce common subexpressions. */
3819 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
3820 && !TREE_CONSTANT (intop
)
3821 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
3822 && TREE_CONSTANT (size_exp
)
3823 /* If the constant comes from pointer subtraction,
3824 skip this optimization--it would cause an error. */
3825 && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop
, 0))) == INTEGER_TYPE
3826 /* If the constant is unsigned, and smaller than the pointer size,
3827 then we must skip this optimization. This is because it could cause
3828 an overflow error if the constant is negative but INTOP is not. */
3829 && (!TYPE_UNSIGNED (TREE_TYPE (intop
))
3830 || (TYPE_PRECISION (TREE_TYPE (intop
))
3831 == TYPE_PRECISION (TREE_TYPE (ptrop
)))))
3833 enum tree_code subcode
= resultcode
;
3834 tree int_type
= TREE_TYPE (intop
);
3835 if (TREE_CODE (intop
) == MINUS_EXPR
)
3836 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
3837 /* Convert both subexpression types to the type of intop,
3838 because weird cases involving pointer arithmetic
3839 can result in a sum or difference with different type args. */
3840 ptrop
= build_binary_op (EXPR_LOCATION (TREE_OPERAND (intop
, 1)),
3842 convert (int_type
, TREE_OPERAND (intop
, 1)), 1);
3843 intop
= convert (int_type
, TREE_OPERAND (intop
, 0));
3846 /* Convert the integer argument to a type the same size as sizetype
3847 so the multiply won't overflow spuriously. */
3848 if (TYPE_PRECISION (TREE_TYPE (intop
)) != TYPE_PRECISION (sizetype
)
3849 || TYPE_UNSIGNED (TREE_TYPE (intop
)) != TYPE_UNSIGNED (sizetype
))
3850 intop
= convert (c_common_type_for_size (TYPE_PRECISION (sizetype
),
3851 TYPE_UNSIGNED (sizetype
)), intop
);
3853 /* Replace the integer argument with a suitable product by the object size.
3854 Do this multiplication as signed, then convert to the appropriate type
3855 for the pointer operation and disregard an overflow that occured only
3856 because of the sign-extension change in the latter conversion. */
3858 tree t
= build_binary_op (loc
,
3860 convert (TREE_TYPE (intop
), size_exp
), 1);
3861 intop
= convert (sizetype
, t
);
3862 if (TREE_OVERFLOW_P (intop
) && !TREE_OVERFLOW (t
))
3863 intop
= build_int_cst_wide (TREE_TYPE (intop
), TREE_INT_CST_LOW (intop
),
3864 TREE_INT_CST_HIGH (intop
));
3867 /* Create the sum or difference. */
3868 if (resultcode
== MINUS_EXPR
)
3869 intop
= fold_build1_loc (loc
, NEGATE_EXPR
, sizetype
, intop
);
3871 ret
= fold_build2_loc (loc
, POINTER_PLUS_EXPR
, result_type
, ptrop
, intop
);
3873 fold_undefer_and_ignore_overflow_warnings ();
3878 /* Wrap a C_MAYBE_CONST_EXPR around an expression that is fully folded
3879 and if NON_CONST is known not to be permitted in an evaluated part
3880 of a constant expression. */
3883 c_wrap_maybe_const (tree expr
, bool non_const
)
3885 bool nowarning
= TREE_NO_WARNING (expr
);
3886 location_t loc
= EXPR_LOCATION (expr
);
3888 /* This should never be called for C++. */
3889 if (c_dialect_cxx ())
3892 /* The result of folding may have a NOP_EXPR to set TREE_NO_WARNING. */
3893 STRIP_TYPE_NOPS (expr
);
3894 expr
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (expr
), NULL
, expr
);
3895 C_MAYBE_CONST_EXPR_NON_CONST (expr
) = non_const
;
3897 TREE_NO_WARNING (expr
) = 1;
3898 protected_set_expr_location (expr
, loc
);
3903 /* Wrap a SAVE_EXPR around EXPR, if appropriate. Like save_expr, but
3904 for C folds the inside expression and wraps a C_MAYBE_CONST_EXPR
3905 around the SAVE_EXPR if needed so that c_fully_fold does not need
3906 to look inside SAVE_EXPRs. */
3909 c_save_expr (tree expr
)
3911 bool maybe_const
= true;
3912 if (c_dialect_cxx ())
3913 return save_expr (expr
);
3914 expr
= c_fully_fold (expr
, false, &maybe_const
);
3915 expr
= save_expr (expr
);
3917 expr
= c_wrap_maybe_const (expr
, true);
3921 /* Return whether EXPR is a declaration whose address can never be
3925 decl_with_nonnull_addr_p (const_tree expr
)
3927 return (DECL_P (expr
)
3928 && (TREE_CODE (expr
) == PARM_DECL
3929 || TREE_CODE (expr
) == LABEL_DECL
3930 || !DECL_WEAK (expr
)));
3933 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
3934 or for an `if' or `while' statement or ?..: exp. It should already
3935 have been validated to be of suitable type; otherwise, a bad
3936 diagnostic may result.
3938 The EXPR is located at LOCATION.
3940 This preparation consists of taking the ordinary
3941 representation of an expression expr and producing a valid tree
3942 boolean expression describing whether expr is nonzero. We could
3943 simply always do build_binary_op (NE_EXPR, expr, truthvalue_false_node, 1),
3944 but we optimize comparisons, &&, ||, and !.
3946 The resulting type should always be `truthvalue_type_node'. */
3949 c_common_truthvalue_conversion (location_t location
, tree expr
)
3951 switch (TREE_CODE (expr
))
3953 case EQ_EXPR
: case NE_EXPR
: case UNEQ_EXPR
: case LTGT_EXPR
:
3954 case LE_EXPR
: case GE_EXPR
: case LT_EXPR
: case GT_EXPR
:
3955 case UNLE_EXPR
: case UNGE_EXPR
: case UNLT_EXPR
: case UNGT_EXPR
:
3956 case ORDERED_EXPR
: case UNORDERED_EXPR
:
3957 if (TREE_TYPE (expr
) == truthvalue_type_node
)
3959 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
3960 TREE_OPERAND (expr
, 0), TREE_OPERAND (expr
, 1));
3963 case TRUTH_ANDIF_EXPR
:
3964 case TRUTH_ORIF_EXPR
:
3965 case TRUTH_AND_EXPR
:
3967 case TRUTH_XOR_EXPR
:
3968 if (TREE_TYPE (expr
) == truthvalue_type_node
)
3970 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
3971 c_common_truthvalue_conversion (location
,
3972 TREE_OPERAND (expr
, 0)),
3973 c_common_truthvalue_conversion (location
,
3974 TREE_OPERAND (expr
, 1)));
3977 case TRUTH_NOT_EXPR
:
3978 if (TREE_TYPE (expr
) == truthvalue_type_node
)
3980 expr
= build1 (TREE_CODE (expr
), truthvalue_type_node
,
3981 c_common_truthvalue_conversion (location
,
3982 TREE_OPERAND (expr
, 0)));
3989 return integer_zerop (expr
) ? truthvalue_false_node
3990 : truthvalue_true_node
;
3993 return real_compare (NE_EXPR
, &TREE_REAL_CST (expr
), &dconst0
)
3994 ? truthvalue_true_node
3995 : truthvalue_false_node
;
3998 return fixed_compare (NE_EXPR
, &TREE_FIXED_CST (expr
),
3999 &FCONST0 (TYPE_MODE (TREE_TYPE (expr
))))
4000 ? truthvalue_true_node
4001 : truthvalue_false_node
;
4004 expr
= build_unary_op (location
, ADDR_EXPR
, expr
, 0);
4009 tree inner
= TREE_OPERAND (expr
, 0);
4010 if (decl_with_nonnull_addr_p (inner
))
4012 /* Common Ada/Pascal programmer's mistake. */
4013 warning_at (location
,
4015 "the address of %qD will always evaluate as %<true%>",
4017 return truthvalue_true_node
;
4020 /* If we still have a decl, it is possible for its address to
4021 be NULL, so we cannot optimize. */
4024 gcc_assert (DECL_WEAK (inner
));
4028 if (TREE_SIDE_EFFECTS (inner
))
4030 expr
= build2 (COMPOUND_EXPR
, truthvalue_type_node
,
4031 inner
, truthvalue_true_node
);
4035 return truthvalue_true_node
;
4039 expr
= build_binary_op (EXPR_LOCATION (expr
),
4040 (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1))
4041 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4042 c_common_truthvalue_conversion (location
,
4043 TREE_OPERAND (expr
, 0)),
4044 c_common_truthvalue_conversion (location
,
4045 TREE_OPERAND (expr
, 1)),
4052 case EXCESS_PRECISION_EXPR
:
4053 /* These don't change whether an object is nonzero or zero. */
4054 return c_common_truthvalue_conversion (location
, TREE_OPERAND (expr
, 0));
4058 /* These don't change whether an object is zero or nonzero, but
4059 we can't ignore them if their second arg has side-effects. */
4060 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1)))
4062 expr
= build2 (COMPOUND_EXPR
, truthvalue_type_node
,
4063 TREE_OPERAND (expr
, 1),
4064 c_common_truthvalue_conversion
4065 (location
, TREE_OPERAND (expr
, 0)));
4069 return c_common_truthvalue_conversion (location
,
4070 TREE_OPERAND (expr
, 0));
4073 /* Distribute the conversion into the arms of a COND_EXPR. */
4074 if (c_dialect_cxx ())
4076 expr
= fold_build3_loc (location
, COND_EXPR
, truthvalue_type_node
,
4077 TREE_OPERAND (expr
, 0),
4078 c_common_truthvalue_conversion (location
,
4081 c_common_truthvalue_conversion (location
,
4088 /* Folding will happen later for C. */
4089 expr
= build3 (COND_EXPR
, truthvalue_type_node
,
4090 TREE_OPERAND (expr
, 0),
4091 c_common_truthvalue_conversion (location
,
4092 TREE_OPERAND (expr
, 1)),
4093 c_common_truthvalue_conversion (location
,
4094 TREE_OPERAND (expr
, 2)));
4099 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
4100 since that affects how `default_conversion' will behave. */
4101 if (TREE_CODE (TREE_TYPE (expr
)) == REFERENCE_TYPE
4102 || TREE_CODE (TREE_TYPE (TREE_OPERAND (expr
, 0))) == REFERENCE_TYPE
)
4104 /* If this is widening the argument, we can ignore it. */
4105 if (TYPE_PRECISION (TREE_TYPE (expr
))
4106 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr
, 0))))
4107 return c_common_truthvalue_conversion (location
,
4108 TREE_OPERAND (expr
, 0));
4112 if (!TREE_NO_WARNING (expr
)
4113 && warn_parentheses
)
4115 warning (OPT_Wparentheses
,
4116 "suggest parentheses around assignment used as truth value");
4117 TREE_NO_WARNING (expr
) = 1;
4125 if (TREE_CODE (TREE_TYPE (expr
)) == COMPLEX_TYPE
)
4127 tree t
= c_save_expr (expr
);
4128 expr
= (build_binary_op
4129 (EXPR_LOCATION (expr
),
4130 (TREE_SIDE_EFFECTS (expr
)
4131 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
4132 c_common_truthvalue_conversion
4134 build_unary_op (location
, REALPART_EXPR
, t
, 0)),
4135 c_common_truthvalue_conversion
4137 build_unary_op (location
, IMAGPART_EXPR
, t
, 0)),
4142 if (TREE_CODE (TREE_TYPE (expr
)) == FIXED_POINT_TYPE
)
4144 tree fixed_zero_node
= build_fixed (TREE_TYPE (expr
),
4146 (TREE_TYPE (expr
))));
4147 return build_binary_op (location
, NE_EXPR
, expr
, fixed_zero_node
, 1);
4150 return build_binary_op (location
, NE_EXPR
, expr
, integer_zero_node
, 1);
4153 protected_set_expr_location (expr
, location
);
4157 static void def_builtin_1 (enum built_in_function fncode
,
4159 enum built_in_class fnclass
,
4160 tree fntype
, tree libtype
,
4161 bool both_p
, bool fallback_p
, bool nonansi_p
,
4162 tree fnattrs
, bool implicit_p
);
4165 /* Apply the TYPE_QUALS to the new DECL. */
4168 c_apply_type_quals_to_decl (int type_quals
, tree decl
)
4170 tree type
= TREE_TYPE (decl
);
4172 if (type
== error_mark_node
)
4175 if (((type_quals
& TYPE_QUAL_CONST
)
4176 || (type
&& TREE_CODE (type
) == REFERENCE_TYPE
))
4177 /* An object declared 'const' is only readonly after it is
4178 initialized. We don't have any way of expressing this currently,
4179 so we need to be conservative and unset TREE_READONLY for types
4180 with constructors. Otherwise aliasing code will ignore stores in
4181 an inline constructor. */
4182 && !(type
&& TYPE_NEEDS_CONSTRUCTING (type
)))
4183 TREE_READONLY (decl
) = 1;
4184 if (type_quals
& TYPE_QUAL_VOLATILE
)
4186 TREE_SIDE_EFFECTS (decl
) = 1;
4187 TREE_THIS_VOLATILE (decl
) = 1;
4189 if (type_quals
& TYPE_QUAL_RESTRICT
)
4191 while (type
&& TREE_CODE (type
) == ARRAY_TYPE
)
4192 /* Allow 'restrict' on arrays of pointers.
4193 FIXME currently we just ignore it. */
4194 type
= TREE_TYPE (type
);
4196 || !POINTER_TYPE_P (type
)
4197 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type
)))
4198 error ("invalid use of %<restrict%>");
4202 /* Hash function for the problem of multiple type definitions in
4203 different files. This must hash all types that will compare
4204 equal via comptypes to the same value. In practice it hashes
4205 on some of the simple stuff and leaves the details to comptypes. */
4208 c_type_hash (const void *p
)
4212 const_tree
const t
= (const_tree
) p
;
4214 switch (TREE_CODE (t
))
4216 /* For pointers, hash on pointee type plus some swizzling. */
4218 return c_type_hash (TREE_TYPE (t
)) ^ 0x3003003;
4219 /* Hash on number of elements and total size. */
4222 t2
= TYPE_VALUES (t
);
4226 t2
= TYPE_FIELDS (t
);
4228 case QUAL_UNION_TYPE
:
4230 t2
= TYPE_FIELDS (t
);
4234 t2
= TYPE_FIELDS (t
);
4239 for (; t2
; t2
= TREE_CHAIN (t2
))
4241 /* We might have a VLA here. */
4242 if (TREE_CODE (TYPE_SIZE (t
)) != INTEGER_CST
)
4245 size
= TREE_INT_CST_LOW (TYPE_SIZE (t
));
4246 return ((size
<< 24) | (i
<< shift
));
4249 static GTY((param_is (union tree_node
))) htab_t type_hash_table
;
4251 /* Return the typed-based alias set for T, which may be an expression
4252 or a type. Return -1 if we don't do anything special. */
4255 c_common_get_alias_set (tree t
)
4260 /* For VLAs, use the alias set of the element type rather than the
4261 default of alias set 0 for types compared structurally. */
4262 if (TYPE_P (t
) && TYPE_STRUCTURAL_EQUALITY_P (t
))
4264 if (TREE_CODE (t
) == ARRAY_TYPE
)
4265 return get_alias_set (TREE_TYPE (t
));
4269 /* Permit type-punning when accessing a union, provided the access
4270 is directly through the union. For example, this code does not
4271 permit taking the address of a union member and then storing
4272 through it. Even the type-punning allowed here is a GCC
4273 extension, albeit a common and useful one; the C standard says
4274 that such accesses have implementation-defined behavior. */
4276 TREE_CODE (u
) == COMPONENT_REF
|| TREE_CODE (u
) == ARRAY_REF
;
4277 u
= TREE_OPERAND (u
, 0))
4278 if (TREE_CODE (u
) == COMPONENT_REF
4279 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u
, 0))) == UNION_TYPE
)
4282 /* That's all the expressions we handle specially. */
4286 /* The C standard guarantees that any object may be accessed via an
4287 lvalue that has character type. */
4288 if (t
== char_type_node
4289 || t
== signed_char_type_node
4290 || t
== unsigned_char_type_node
)
4293 /* The C standard specifically allows aliasing between signed and
4294 unsigned variants of the same type. We treat the signed
4295 variant as canonical. */
4296 if (TREE_CODE (t
) == INTEGER_TYPE
&& TYPE_UNSIGNED (t
))
4298 tree t1
= c_common_signed_type (t
);
4300 /* t1 == t can happen for boolean nodes which are always unsigned. */
4302 return get_alias_set (t1
);
4304 else if (POINTER_TYPE_P (t
))
4308 /* Unfortunately, there is no canonical form of a pointer type.
4309 In particular, if we have `typedef int I', then `int *', and
4310 `I *' are different types. So, we have to pick a canonical
4311 representative. We do this below.
4313 Technically, this approach is actually more conservative that
4314 it needs to be. In particular, `const int *' and `int *'
4315 should be in different alias sets, according to the C and C++
4316 standard, since their types are not the same, and so,
4317 technically, an `int **' and `const int **' cannot point at
4320 But, the standard is wrong. In particular, this code is
4325 const int* const* cipp = ipp;
4327 And, it doesn't make sense for that to be legal unless you
4328 can dereference IPP and CIPP. So, we ignore cv-qualifiers on
4329 the pointed-to types. This issue has been reported to the
4331 t1
= build_type_no_quals (t
);
4333 return get_alias_set (t1
);
4336 /* Handle the case of multiple type nodes referring to "the same" type,
4337 which occurs with IMA. These share an alias set. FIXME: Currently only
4338 C90 is handled. (In C99 type compatibility is not transitive, which
4339 complicates things mightily. The alias set splay trees can theoretically
4340 represent this, but insertion is tricky when you consider all the
4341 different orders things might arrive in.) */
4343 if (c_language
!= clk_c
|| flag_isoc99
)
4346 /* Save time if there's only one input file. */
4347 if (num_in_fnames
== 1)
4350 /* Pointers need special handling if they point to any type that
4351 needs special handling (below). */
4352 if (TREE_CODE (t
) == POINTER_TYPE
)
4355 /* Find bottom type under any nested POINTERs. */
4356 for (t2
= TREE_TYPE (t
);
4357 TREE_CODE (t2
) == POINTER_TYPE
;
4358 t2
= TREE_TYPE (t2
))
4360 if (TREE_CODE (t2
) != RECORD_TYPE
4361 && TREE_CODE (t2
) != ENUMERAL_TYPE
4362 && TREE_CODE (t2
) != QUAL_UNION_TYPE
4363 && TREE_CODE (t2
) != UNION_TYPE
)
4365 if (TYPE_SIZE (t2
) == 0)
4368 /* These are the only cases that need special handling. */
4369 if (TREE_CODE (t
) != RECORD_TYPE
4370 && TREE_CODE (t
) != ENUMERAL_TYPE
4371 && TREE_CODE (t
) != QUAL_UNION_TYPE
4372 && TREE_CODE (t
) != UNION_TYPE
4373 && TREE_CODE (t
) != POINTER_TYPE
)
4376 if (TYPE_SIZE (t
) == 0)
4379 /* Look up t in hash table. Only one of the compatible types within each
4380 alias set is recorded in the table. */
4381 if (!type_hash_table
)
4382 type_hash_table
= htab_create_ggc (1021, c_type_hash
,
4383 (htab_eq
) lang_hooks
.types_compatible_p
,
4385 slot
= htab_find_slot (type_hash_table
, t
, INSERT
);
4388 TYPE_ALIAS_SET (t
) = TYPE_ALIAS_SET ((tree
)*slot
);
4389 return TYPE_ALIAS_SET ((tree
)*slot
);
4392 /* Our caller will assign and record (in t) a new alias set; all we need
4393 to do is remember t in the hash table. */
4399 /* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where
4400 the second parameter indicates which OPERATOR is being applied.
4401 The COMPLAIN flag controls whether we should diagnose possibly
4402 ill-formed constructs or not. LOC is the location of the SIZEOF or
4406 c_sizeof_or_alignof_type (location_t loc
,
4407 tree type
, bool is_sizeof
, int complain
)
4409 const char *op_name
;
4411 enum tree_code type_code
= TREE_CODE (type
);
4413 op_name
= is_sizeof
? "sizeof" : "__alignof__";
4415 if (type_code
== FUNCTION_TYPE
)
4419 if (complain
&& (pedantic
|| warn_pointer_arith
))
4420 pedwarn (loc
, pedantic
? OPT_pedantic
: OPT_Wpointer_arith
,
4421 "invalid application of %<sizeof%> to a function type");
4423 return error_mark_node
;
4424 value
= size_one_node
;
4427 value
= size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
4429 else if (type_code
== VOID_TYPE
|| type_code
== ERROR_MARK
)
4431 if (type_code
== VOID_TYPE
4432 && complain
&& (pedantic
|| warn_pointer_arith
))
4433 pedwarn (loc
, pedantic
? OPT_pedantic
: OPT_Wpointer_arith
,
4434 "invalid application of %qs to a void type", op_name
);
4436 return error_mark_node
;
4437 value
= size_one_node
;
4439 else if (!COMPLETE_TYPE_P (type
))
4442 error_at (loc
, "invalid application of %qs to incomplete type %qT ",
4444 return error_mark_node
;
4449 /* Convert in case a char is more than one unit. */
4450 value
= size_binop_loc (loc
, CEIL_DIV_EXPR
, TYPE_SIZE_UNIT (type
),
4451 size_int (TYPE_PRECISION (char_type_node
)
4454 value
= size_int (TYPE_ALIGN_UNIT (type
));
4457 /* VALUE will have an integer type with TYPE_IS_SIZETYPE set.
4458 TYPE_IS_SIZETYPE means that certain things (like overflow) will
4459 never happen. However, this node should really have type
4460 `size_t', which is just a typedef for an ordinary integer type. */
4461 value
= fold_convert_loc (loc
, size_type_node
, value
);
4462 gcc_assert (!TYPE_IS_SIZETYPE (TREE_TYPE (value
)));
4467 /* Implement the __alignof keyword: Return the minimum required
4468 alignment of EXPR, measured in bytes. For VAR_DECLs,
4469 FUNCTION_DECLs and FIELD_DECLs return DECL_ALIGN (which can be set
4470 from an "aligned" __attribute__ specification). LOC is the
4471 location of the ALIGNOF operator. */
4474 c_alignof_expr (location_t loc
, tree expr
)
4478 if (VAR_OR_FUNCTION_DECL_P (expr
))
4479 t
= size_int (DECL_ALIGN_UNIT (expr
));
4481 else if (TREE_CODE (expr
) == COMPONENT_REF
4482 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
, 1)))
4484 error_at (loc
, "%<__alignof%> applied to a bit-field");
4487 else if (TREE_CODE (expr
) == COMPONENT_REF
4488 && TREE_CODE (TREE_OPERAND (expr
, 1)) == FIELD_DECL
)
4489 t
= size_int (DECL_ALIGN_UNIT (TREE_OPERAND (expr
, 1)));
4491 else if (TREE_CODE (expr
) == INDIRECT_REF
)
4493 tree t
= TREE_OPERAND (expr
, 0);
4495 int bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
4497 while (CONVERT_EXPR_P (t
)
4498 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
4502 t
= TREE_OPERAND (t
, 0);
4503 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
4504 if (thisalign
> bestalign
)
4505 best
= t
, bestalign
= thisalign
;
4507 return c_alignof (loc
, TREE_TYPE (TREE_TYPE (best
)));
4510 return c_alignof (loc
, TREE_TYPE (expr
));
4512 return fold_convert_loc (loc
, size_type_node
, t
);
4515 /* Handle C and C++ default attributes. */
4517 enum built_in_attribute
4519 #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
4520 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
4521 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
4522 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
4523 #include "builtin-attrs.def"
4524 #undef DEF_ATTR_NULL_TREE
4526 #undef DEF_ATTR_IDENT
4527 #undef DEF_ATTR_TREE_LIST
4531 static GTY(()) tree built_in_attributes
[(int) ATTR_LAST
];
4533 static void c_init_attributes (void);
4537 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
4538 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
4539 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
4540 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
4541 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
4542 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
4543 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
4544 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) NAME,
4545 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) NAME,
4546 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
4547 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
4548 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
4549 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
4550 #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
4551 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG6) \
4553 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
4554 #include "builtin-types.def"
4555 #undef DEF_PRIMITIVE_TYPE
4556 #undef DEF_FUNCTION_TYPE_0
4557 #undef DEF_FUNCTION_TYPE_1
4558 #undef DEF_FUNCTION_TYPE_2
4559 #undef DEF_FUNCTION_TYPE_3
4560 #undef DEF_FUNCTION_TYPE_4
4561 #undef DEF_FUNCTION_TYPE_5
4562 #undef DEF_FUNCTION_TYPE_6
4563 #undef DEF_FUNCTION_TYPE_7
4564 #undef DEF_FUNCTION_TYPE_VAR_0
4565 #undef DEF_FUNCTION_TYPE_VAR_1
4566 #undef DEF_FUNCTION_TYPE_VAR_2
4567 #undef DEF_FUNCTION_TYPE_VAR_3
4568 #undef DEF_FUNCTION_TYPE_VAR_4
4569 #undef DEF_FUNCTION_TYPE_VAR_5
4570 #undef DEF_POINTER_TYPE
4574 typedef enum c_builtin_type builtin_type
;
4576 /* A temporary array for c_common_nodes_and_builtins. Used in
4577 communication with def_fn_type. */
4578 static tree builtin_types
[(int) BT_LAST
+ 1];
4580 /* A helper function for c_common_nodes_and_builtins. Build function type
4581 for DEF with return type RET and N arguments. If VAR is true, then the
4582 function should be variadic after those N arguments.
4584 Takes special care not to ICE if any of the types involved are
4585 error_mark_node, which indicates that said type is not in fact available
4586 (see builtin_type_for_size). In which case the function type as a whole
4587 should be error_mark_node. */
4590 def_fn_type (builtin_type def
, builtin_type ret
, bool var
, int n
, ...)
4592 tree args
= NULL
, t
;
4597 for (i
= 0; i
< n
; ++i
)
4599 builtin_type a
= (builtin_type
) va_arg (list
, int);
4600 t
= builtin_types
[a
];
4601 if (t
== error_mark_node
)
4603 args
= tree_cons (NULL_TREE
, t
, args
);
4607 args
= nreverse (args
);
4609 args
= chainon (args
, void_list_node
);
4611 t
= builtin_types
[ret
];
4612 if (t
== error_mark_node
)
4614 t
= build_function_type (t
, args
);
4617 builtin_types
[def
] = t
;
4620 /* Build builtin functions common to both C and C++ language
4624 c_define_builtins (tree va_list_ref_type_node
, tree va_list_arg_type_node
)
4626 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
4627 builtin_types[ENUM] = VALUE;
4628 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
4629 def_fn_type (ENUM, RETURN, 0, 0);
4630 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
4631 def_fn_type (ENUM, RETURN, 0, 1, ARG1);
4632 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
4633 def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
4634 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
4635 def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
4636 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
4637 def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
4638 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
4639 def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
4640 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4642 def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
4643 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4645 def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
4646 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
4647 def_fn_type (ENUM, RETURN, 1, 0);
4648 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
4649 def_fn_type (ENUM, RETURN, 1, 1, ARG1);
4650 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
4651 def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
4652 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
4653 def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
4654 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
4655 def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
4656 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
4657 def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
4658 #define DEF_POINTER_TYPE(ENUM, TYPE) \
4659 builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
4661 #include "builtin-types.def"
4663 #undef DEF_PRIMITIVE_TYPE
4664 #undef DEF_FUNCTION_TYPE_1
4665 #undef DEF_FUNCTION_TYPE_2
4666 #undef DEF_FUNCTION_TYPE_3
4667 #undef DEF_FUNCTION_TYPE_4
4668 #undef DEF_FUNCTION_TYPE_5
4669 #undef DEF_FUNCTION_TYPE_6
4670 #undef DEF_FUNCTION_TYPE_VAR_0
4671 #undef DEF_FUNCTION_TYPE_VAR_1
4672 #undef DEF_FUNCTION_TYPE_VAR_2
4673 #undef DEF_FUNCTION_TYPE_VAR_3
4674 #undef DEF_FUNCTION_TYPE_VAR_4
4675 #undef DEF_FUNCTION_TYPE_VAR_5
4676 #undef DEF_POINTER_TYPE
4677 builtin_types
[(int) BT_LAST
] = NULL_TREE
;
4679 c_init_attributes ();
4681 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P, \
4682 NONANSI_P, ATTRS, IMPLICIT, COND) \
4684 def_builtin_1 (ENUM, NAME, CLASS, \
4685 builtin_types[(int) TYPE], \
4686 builtin_types[(int) LIBTYPE], \
4687 BOTH_P, FALLBACK_P, NONANSI_P, \
4688 built_in_attributes[(int) ATTRS], IMPLICIT);
4689 #include "builtins.def"
4692 targetm
.init_builtins ();
4694 build_common_builtin_nodes ();
4700 /* Like get_identifier, but avoid warnings about null arguments when
4701 the argument may be NULL for targets where GCC lacks stdint.h type
4705 c_get_ident (const char *id
)
4707 return get_identifier (id
);
4710 /* Build tree nodes and builtin functions common to both C and C++ language
4714 c_common_nodes_and_builtins (void)
4716 int char16_type_size
;
4717 int char32_type_size
;
4718 int wchar_type_size
;
4719 tree array_domain_type
;
4720 tree va_list_ref_type_node
;
4721 tree va_list_arg_type_node
;
4723 /* Define `int' and `char' first so that dbx will output them first. */
4724 record_builtin_type (RID_INT
, NULL
, integer_type_node
);
4725 record_builtin_type (RID_CHAR
, "char", char_type_node
);
4727 /* `signed' is the same as `int'. FIXME: the declarations of "signed",
4728 "unsigned long", "long long unsigned" and "unsigned short" were in C++
4729 but not C. Are the conditionals here needed? */
4730 if (c_dialect_cxx ())
4731 record_builtin_type (RID_SIGNED
, NULL
, integer_type_node
);
4732 record_builtin_type (RID_LONG
, "long int", long_integer_type_node
);
4733 record_builtin_type (RID_UNSIGNED
, "unsigned int", unsigned_type_node
);
4734 record_builtin_type (RID_MAX
, "long unsigned int",
4735 long_unsigned_type_node
);
4736 if (int128_integer_type_node
!= NULL_TREE
)
4738 record_builtin_type (RID_INT128
, "__int128",
4739 int128_integer_type_node
);
4740 record_builtin_type (RID_MAX
, "__int128 unsigned",
4741 int128_unsigned_type_node
);
4743 if (c_dialect_cxx ())
4744 record_builtin_type (RID_MAX
, "unsigned long", long_unsigned_type_node
);
4745 record_builtin_type (RID_MAX
, "long long int",
4746 long_long_integer_type_node
);
4747 record_builtin_type (RID_MAX
, "long long unsigned int",
4748 long_long_unsigned_type_node
);
4749 if (c_dialect_cxx ())
4750 record_builtin_type (RID_MAX
, "long long unsigned",
4751 long_long_unsigned_type_node
);
4752 record_builtin_type (RID_SHORT
, "short int", short_integer_type_node
);
4753 record_builtin_type (RID_MAX
, "short unsigned int",
4754 short_unsigned_type_node
);
4755 if (c_dialect_cxx ())
4756 record_builtin_type (RID_MAX
, "unsigned short",
4757 short_unsigned_type_node
);
4759 /* Define both `signed char' and `unsigned char'. */
4760 record_builtin_type (RID_MAX
, "signed char", signed_char_type_node
);
4761 record_builtin_type (RID_MAX
, "unsigned char", unsigned_char_type_node
);
4763 /* These are types that c_common_type_for_size and
4764 c_common_type_for_mode use. */
4765 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4766 TYPE_DECL
, NULL_TREE
,
4768 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4769 TYPE_DECL
, NULL_TREE
,
4771 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4772 TYPE_DECL
, NULL_TREE
,
4774 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4775 TYPE_DECL
, NULL_TREE
,
4777 #if HOST_BITS_PER_WIDE_INT >= 64
4778 if (targetm
.scalar_mode_supported_p (TImode
))
4779 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4781 get_identifier ("__int128_t"),
4784 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4785 TYPE_DECL
, NULL_TREE
,
4786 unsigned_intQI_type_node
));
4787 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4788 TYPE_DECL
, NULL_TREE
,
4789 unsigned_intHI_type_node
));
4790 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4791 TYPE_DECL
, NULL_TREE
,
4792 unsigned_intSI_type_node
));
4793 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4794 TYPE_DECL
, NULL_TREE
,
4795 unsigned_intDI_type_node
));
4796 #if HOST_BITS_PER_WIDE_INT >= 64
4797 if (targetm
.scalar_mode_supported_p (TImode
))
4798 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4800 get_identifier ("__uint128_t"),
4801 unsigned_intTI_type_node
));
4804 /* Create the widest literal types. */
4805 widest_integer_literal_type_node
4806 = make_signed_type (HOST_BITS_PER_WIDE_INT
* 2);
4807 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4808 TYPE_DECL
, NULL_TREE
,
4809 widest_integer_literal_type_node
));
4811 widest_unsigned_literal_type_node
4812 = make_unsigned_type (HOST_BITS_PER_WIDE_INT
* 2);
4813 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4814 TYPE_DECL
, NULL_TREE
,
4815 widest_unsigned_literal_type_node
));
4817 /* `unsigned long' is the standard type for sizeof.
4818 Note that stddef.h uses `unsigned long',
4819 and this must agree, even if long and int are the same size. */
4821 TREE_TYPE (identifier_global_value (get_identifier (SIZE_TYPE
)));
4822 signed_size_type_node
= c_common_signed_type (size_type_node
);
4823 set_sizetype (size_type_node
);
4826 TREE_TYPE (identifier_global_value (get_identifier (PID_TYPE
)));
4828 build_common_tree_nodes_2 (flag_short_double
);
4830 record_builtin_type (RID_FLOAT
, NULL
, float_type_node
);
4831 record_builtin_type (RID_DOUBLE
, NULL
, double_type_node
);
4832 record_builtin_type (RID_MAX
, "long double", long_double_type_node
);
4834 /* Only supported decimal floating point extension if the target
4835 actually supports underlying modes. */
4836 if (targetm
.scalar_mode_supported_p (SDmode
)
4837 && targetm
.scalar_mode_supported_p (DDmode
)
4838 && targetm
.scalar_mode_supported_p (TDmode
))
4840 record_builtin_type (RID_DFLOAT32
, NULL
, dfloat32_type_node
);
4841 record_builtin_type (RID_DFLOAT64
, NULL
, dfloat64_type_node
);
4842 record_builtin_type (RID_DFLOAT128
, NULL
, dfloat128_type_node
);
4845 if (targetm
.fixed_point_supported_p ())
4847 record_builtin_type (RID_MAX
, "short _Fract", short_fract_type_node
);
4848 record_builtin_type (RID_FRACT
, NULL
, fract_type_node
);
4849 record_builtin_type (RID_MAX
, "long _Fract", long_fract_type_node
);
4850 record_builtin_type (RID_MAX
, "long long _Fract",
4851 long_long_fract_type_node
);
4852 record_builtin_type (RID_MAX
, "unsigned short _Fract",
4853 unsigned_short_fract_type_node
);
4854 record_builtin_type (RID_MAX
, "unsigned _Fract",
4855 unsigned_fract_type_node
);
4856 record_builtin_type (RID_MAX
, "unsigned long _Fract",
4857 unsigned_long_fract_type_node
);
4858 record_builtin_type (RID_MAX
, "unsigned long long _Fract",
4859 unsigned_long_long_fract_type_node
);
4860 record_builtin_type (RID_MAX
, "_Sat short _Fract",
4861 sat_short_fract_type_node
);
4862 record_builtin_type (RID_MAX
, "_Sat _Fract", sat_fract_type_node
);
4863 record_builtin_type (RID_MAX
, "_Sat long _Fract",
4864 sat_long_fract_type_node
);
4865 record_builtin_type (RID_MAX
, "_Sat long long _Fract",
4866 sat_long_long_fract_type_node
);
4867 record_builtin_type (RID_MAX
, "_Sat unsigned short _Fract",
4868 sat_unsigned_short_fract_type_node
);
4869 record_builtin_type (RID_MAX
, "_Sat unsigned _Fract",
4870 sat_unsigned_fract_type_node
);
4871 record_builtin_type (RID_MAX
, "_Sat unsigned long _Fract",
4872 sat_unsigned_long_fract_type_node
);
4873 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Fract",
4874 sat_unsigned_long_long_fract_type_node
);
4875 record_builtin_type (RID_MAX
, "short _Accum", short_accum_type_node
);
4876 record_builtin_type (RID_ACCUM
, NULL
, accum_type_node
);
4877 record_builtin_type (RID_MAX
, "long _Accum", long_accum_type_node
);
4878 record_builtin_type (RID_MAX
, "long long _Accum",
4879 long_long_accum_type_node
);
4880 record_builtin_type (RID_MAX
, "unsigned short _Accum",
4881 unsigned_short_accum_type_node
);
4882 record_builtin_type (RID_MAX
, "unsigned _Accum",
4883 unsigned_accum_type_node
);
4884 record_builtin_type (RID_MAX
, "unsigned long _Accum",
4885 unsigned_long_accum_type_node
);
4886 record_builtin_type (RID_MAX
, "unsigned long long _Accum",
4887 unsigned_long_long_accum_type_node
);
4888 record_builtin_type (RID_MAX
, "_Sat short _Accum",
4889 sat_short_accum_type_node
);
4890 record_builtin_type (RID_MAX
, "_Sat _Accum", sat_accum_type_node
);
4891 record_builtin_type (RID_MAX
, "_Sat long _Accum",
4892 sat_long_accum_type_node
);
4893 record_builtin_type (RID_MAX
, "_Sat long long _Accum",
4894 sat_long_long_accum_type_node
);
4895 record_builtin_type (RID_MAX
, "_Sat unsigned short _Accum",
4896 sat_unsigned_short_accum_type_node
);
4897 record_builtin_type (RID_MAX
, "_Sat unsigned _Accum",
4898 sat_unsigned_accum_type_node
);
4899 record_builtin_type (RID_MAX
, "_Sat unsigned long _Accum",
4900 sat_unsigned_long_accum_type_node
);
4901 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Accum",
4902 sat_unsigned_long_long_accum_type_node
);
4906 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4908 get_identifier ("complex int"),
4909 complex_integer_type_node
));
4910 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4912 get_identifier ("complex float"),
4913 complex_float_type_node
));
4914 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4916 get_identifier ("complex double"),
4917 complex_double_type_node
));
4918 lang_hooks
.decls
.pushdecl
4919 (build_decl (UNKNOWN_LOCATION
,
4920 TYPE_DECL
, get_identifier ("complex long double"),
4921 complex_long_double_type_node
));
4923 if (c_dialect_cxx ())
4924 /* For C++, make fileptr_type_node a distinct void * type until
4925 FILE type is defined. */
4926 fileptr_type_node
= build_variant_type_copy (ptr_type_node
);
4928 record_builtin_type (RID_VOID
, NULL
, void_type_node
);
4930 /* Set the TYPE_NAME for any variants that were built before
4931 record_builtin_type gave names to the built-in types. */
4933 tree void_name
= TYPE_NAME (void_type_node
);
4934 TYPE_NAME (void_type_node
) = NULL_TREE
;
4935 TYPE_NAME (build_qualified_type (void_type_node
, TYPE_QUAL_CONST
))
4937 TYPE_NAME (void_type_node
) = void_name
;
4940 /* This node must not be shared. */
4941 void_zero_node
= make_node (INTEGER_CST
);
4942 TREE_TYPE (void_zero_node
) = void_type_node
;
4944 void_list_node
= build_void_list_node ();
4946 /* Make a type to be the domain of a few array types
4947 whose domains don't really matter.
4948 200 is small enough that it always fits in size_t
4949 and large enough that it can hold most function names for the
4950 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
4951 array_domain_type
= build_index_type (size_int (200));
4953 /* Make a type for arrays of characters.
4954 With luck nothing will ever really depend on the length of this
4956 char_array_type_node
4957 = build_array_type (char_type_node
, array_domain_type
);
4959 /* Likewise for arrays of ints. */
4961 = build_array_type (integer_type_node
, array_domain_type
);
4963 string_type_node
= build_pointer_type (char_type_node
);
4964 const_string_type_node
4965 = build_pointer_type (build_qualified_type
4966 (char_type_node
, TYPE_QUAL_CONST
));
4968 /* This is special for C++ so functions can be overloaded. */
4969 wchar_type_node
= get_identifier (MODIFIED_WCHAR_TYPE
);
4970 wchar_type_node
= TREE_TYPE (identifier_global_value (wchar_type_node
));
4971 wchar_type_size
= TYPE_PRECISION (wchar_type_node
);
4972 underlying_wchar_type_node
= wchar_type_node
;
4973 if (c_dialect_cxx ())
4975 if (TYPE_UNSIGNED (wchar_type_node
))
4976 wchar_type_node
= make_unsigned_type (wchar_type_size
);
4978 wchar_type_node
= make_signed_type (wchar_type_size
);
4979 record_builtin_type (RID_WCHAR
, "wchar_t", wchar_type_node
);
4982 /* This is for wide string constants. */
4983 wchar_array_type_node
4984 = build_array_type (wchar_type_node
, array_domain_type
);
4986 /* Define 'char16_t'. */
4987 char16_type_node
= get_identifier (CHAR16_TYPE
);
4988 char16_type_node
= TREE_TYPE (identifier_global_value (char16_type_node
));
4989 char16_type_size
= TYPE_PRECISION (char16_type_node
);
4990 if (c_dialect_cxx ())
4992 char16_type_node
= make_unsigned_type (char16_type_size
);
4994 if (cxx_dialect
== cxx0x
)
4995 record_builtin_type (RID_CHAR16
, "char16_t", char16_type_node
);
4998 /* This is for UTF-16 string constants. */
4999 char16_array_type_node
5000 = build_array_type (char16_type_node
, array_domain_type
);
5002 /* Define 'char32_t'. */
5003 char32_type_node
= get_identifier (CHAR32_TYPE
);
5004 char32_type_node
= TREE_TYPE (identifier_global_value (char32_type_node
));
5005 char32_type_size
= TYPE_PRECISION (char32_type_node
);
5006 if (c_dialect_cxx ())
5008 char32_type_node
= make_unsigned_type (char32_type_size
);
5010 if (cxx_dialect
== cxx0x
)
5011 record_builtin_type (RID_CHAR32
, "char32_t", char32_type_node
);
5014 /* This is for UTF-32 string constants. */
5015 char32_array_type_node
5016 = build_array_type (char32_type_node
, array_domain_type
);
5019 TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE
)));
5022 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE
)));
5024 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE
)));
5026 if (SIG_ATOMIC_TYPE
)
5027 sig_atomic_type_node
=
5028 TREE_TYPE (identifier_global_value (c_get_ident (SIG_ATOMIC_TYPE
)));
5031 TREE_TYPE (identifier_global_value (c_get_ident (INT8_TYPE
)));
5034 TREE_TYPE (identifier_global_value (c_get_ident (INT16_TYPE
)));
5037 TREE_TYPE (identifier_global_value (c_get_ident (INT32_TYPE
)));
5040 TREE_TYPE (identifier_global_value (c_get_ident (INT64_TYPE
)));
5043 TREE_TYPE (identifier_global_value (c_get_ident (UINT8_TYPE
)));
5046 TREE_TYPE (identifier_global_value (c_get_ident (UINT16_TYPE
)));
5048 c_uint32_type_node
=
5049 TREE_TYPE (identifier_global_value (c_get_ident (UINT32_TYPE
)));
5051 c_uint64_type_node
=
5052 TREE_TYPE (identifier_global_value (c_get_ident (UINT64_TYPE
)));
5053 if (INT_LEAST8_TYPE
)
5054 int_least8_type_node
=
5055 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST8_TYPE
)));
5056 if (INT_LEAST16_TYPE
)
5057 int_least16_type_node
=
5058 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST16_TYPE
)));
5059 if (INT_LEAST32_TYPE
)
5060 int_least32_type_node
=
5061 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST32_TYPE
)));
5062 if (INT_LEAST64_TYPE
)
5063 int_least64_type_node
=
5064 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST64_TYPE
)));
5065 if (UINT_LEAST8_TYPE
)
5066 uint_least8_type_node
=
5067 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST8_TYPE
)));
5068 if (UINT_LEAST16_TYPE
)
5069 uint_least16_type_node
=
5070 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST16_TYPE
)));
5071 if (UINT_LEAST32_TYPE
)
5072 uint_least32_type_node
=
5073 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST32_TYPE
)));
5074 if (UINT_LEAST64_TYPE
)
5075 uint_least64_type_node
=
5076 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST64_TYPE
)));
5078 int_fast8_type_node
=
5079 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST8_TYPE
)));
5080 if (INT_FAST16_TYPE
)
5081 int_fast16_type_node
=
5082 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST16_TYPE
)));
5083 if (INT_FAST32_TYPE
)
5084 int_fast32_type_node
=
5085 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST32_TYPE
)));
5086 if (INT_FAST64_TYPE
)
5087 int_fast64_type_node
=
5088 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST64_TYPE
)));
5089 if (UINT_FAST8_TYPE
)
5090 uint_fast8_type_node
=
5091 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST8_TYPE
)));
5092 if (UINT_FAST16_TYPE
)
5093 uint_fast16_type_node
=
5094 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST16_TYPE
)));
5095 if (UINT_FAST32_TYPE
)
5096 uint_fast32_type_node
=
5097 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST32_TYPE
)));
5098 if (UINT_FAST64_TYPE
)
5099 uint_fast64_type_node
=
5100 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST64_TYPE
)));
5103 TREE_TYPE (identifier_global_value (c_get_ident (INTPTR_TYPE
)));
5106 TREE_TYPE (identifier_global_value (c_get_ident (UINTPTR_TYPE
)));
5108 default_function_type
= build_function_type (integer_type_node
, NULL_TREE
);
5110 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE
)));
5111 unsigned_ptrdiff_type_node
= c_common_unsigned_type (ptrdiff_type_node
);
5113 lang_hooks
.decls
.pushdecl
5114 (build_decl (UNKNOWN_LOCATION
,
5115 TYPE_DECL
, get_identifier ("__builtin_va_list"),
5116 va_list_type_node
));
5117 #ifdef TARGET_ENUM_VA_LIST
5122 for (l
= 0; TARGET_ENUM_VA_LIST (l
, &pname
, &ptype
); ++l
)
5124 lang_hooks
.decls
.pushdecl
5125 (build_decl (UNKNOWN_LOCATION
,
5126 TYPE_DECL
, get_identifier (pname
),
5133 if (TREE_CODE (va_list_type_node
) == ARRAY_TYPE
)
5135 va_list_arg_type_node
= va_list_ref_type_node
=
5136 build_pointer_type (TREE_TYPE (va_list_type_node
));
5140 va_list_arg_type_node
= va_list_type_node
;
5141 va_list_ref_type_node
= build_reference_type (va_list_type_node
);
5144 if (!flag_preprocess_only
)
5145 c_define_builtins (va_list_ref_type_node
, va_list_arg_type_node
);
5147 main_identifier_node
= get_identifier ("main");
5149 /* Create the built-in __null node. It is important that this is
5151 null_node
= make_node (INTEGER_CST
);
5152 TREE_TYPE (null_node
) = c_common_type_for_size (POINTER_SIZE
, 0);
5154 /* Since builtin_types isn't gc'ed, don't export these nodes. */
5155 memset (builtin_types
, 0, sizeof (builtin_types
));
5158 /* The number of named compound-literals generated thus far. */
5159 static GTY(()) int compound_literal_number
;
5161 /* Set DECL_NAME for DECL, a VAR_DECL for a compound-literal. */
5164 set_compound_literal_name (tree decl
)
5167 ASM_FORMAT_PRIVATE_NAME (name
, "__compound_literal",
5168 compound_literal_number
);
5169 compound_literal_number
++;
5170 DECL_NAME (decl
) = get_identifier (name
);
5174 build_va_arg (location_t loc
, tree expr
, tree type
)
5176 expr
= build1 (VA_ARG_EXPR
, type
, expr
);
5177 SET_EXPR_LOCATION (expr
, loc
);
5182 /* Linked list of disabled built-in functions. */
5184 typedef struct disabled_builtin
5187 struct disabled_builtin
*next
;
5189 static disabled_builtin
*disabled_builtins
= NULL
;
5191 static bool builtin_function_disabled_p (const char *);
5193 /* Disable a built-in function specified by -fno-builtin-NAME. If NAME
5194 begins with "__builtin_", give an error. */
5197 disable_builtin_function (const char *name
)
5199 if (strncmp (name
, "__builtin_", strlen ("__builtin_")) == 0)
5200 error ("cannot disable built-in function %qs", name
);
5203 disabled_builtin
*new_disabled_builtin
= XNEW (disabled_builtin
);
5204 new_disabled_builtin
->name
= name
;
5205 new_disabled_builtin
->next
= disabled_builtins
;
5206 disabled_builtins
= new_disabled_builtin
;
5211 /* Return true if the built-in function NAME has been disabled, false
5215 builtin_function_disabled_p (const char *name
)
5217 disabled_builtin
*p
;
5218 for (p
= disabled_builtins
; p
!= NULL
; p
= p
->next
)
5220 if (strcmp (name
, p
->name
) == 0)
5227 /* Worker for DEF_BUILTIN.
5228 Possibly define a builtin function with one or two names.
5229 Does not declare a non-__builtin_ function if flag_no_builtin, or if
5230 nonansi_p and flag_no_nonansi_builtin. */
5233 def_builtin_1 (enum built_in_function fncode
,
5235 enum built_in_class fnclass
,
5236 tree fntype
, tree libtype
,
5237 bool both_p
, bool fallback_p
, bool nonansi_p
,
5238 tree fnattrs
, bool implicit_p
)
5241 const char *libname
;
5243 if (fntype
== error_mark_node
)
5246 gcc_assert ((!both_p
&& !fallback_p
)
5247 || !strncmp (name
, "__builtin_",
5248 strlen ("__builtin_")));
5250 libname
= name
+ strlen ("__builtin_");
5251 decl
= add_builtin_function (name
, fntype
, fncode
, fnclass
,
5252 (fallback_p
? libname
: NULL
),
5255 && !flag_no_builtin
&& !builtin_function_disabled_p (libname
)
5256 && !(nonansi_p
&& flag_no_nonansi_builtin
))
5257 add_builtin_function (libname
, libtype
, fncode
, fnclass
,
5260 built_in_decls
[(int) fncode
] = decl
;
5262 implicit_built_in_decls
[(int) fncode
] = decl
;
5265 /* Nonzero if the type T promotes to int. This is (nearly) the
5266 integral promotions defined in ISO C99 6.3.1.1/2. */
5269 c_promoting_integer_type_p (const_tree t
)
5271 switch (TREE_CODE (t
))
5274 return (TYPE_MAIN_VARIANT (t
) == char_type_node
5275 || TYPE_MAIN_VARIANT (t
) == signed_char_type_node
5276 || TYPE_MAIN_VARIANT (t
) == unsigned_char_type_node
5277 || TYPE_MAIN_VARIANT (t
) == short_integer_type_node
5278 || TYPE_MAIN_VARIANT (t
) == short_unsigned_type_node
5279 || TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
));
5282 /* ??? Technically all enumerations not larger than an int
5283 promote to an int. But this is used along code paths
5284 that only want to notice a size change. */
5285 return TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
);
5295 /* Return 1 if PARMS specifies a fixed number of parameters
5296 and none of their types is affected by default promotions. */
5299 self_promoting_args_p (const_tree parms
)
5302 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
5304 tree type
= TREE_VALUE (t
);
5306 if (type
== error_mark_node
)
5309 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
5315 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
5318 if (c_promoting_integer_type_p (type
))
5324 /* Recursively remove any '*' or '&' operator from TYPE. */
5326 strip_pointer_operator (tree t
)
5328 while (POINTER_TYPE_P (t
))
5333 /* Recursively remove pointer or array type from TYPE. */
5335 strip_pointer_or_array_types (tree t
)
5337 while (TREE_CODE (t
) == ARRAY_TYPE
|| POINTER_TYPE_P (t
))
5342 /* Used to compare case labels. K1 and K2 are actually tree nodes
5343 representing case labels, or NULL_TREE for a `default' label.
5344 Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after
5345 K2, and 0 if K1 and K2 are equal. */
5348 case_compare (splay_tree_key k1
, splay_tree_key k2
)
5350 /* Consider a NULL key (such as arises with a `default' label) to be
5351 smaller than anything else. */
5357 return tree_int_cst_compare ((tree
) k1
, (tree
) k2
);
5360 /* Process a case label, located at LOC, for the range LOW_VALUE
5361 ... HIGH_VALUE. If LOW_VALUE and HIGH_VALUE are both NULL_TREE
5362 then this case label is actually a `default' label. If only
5363 HIGH_VALUE is NULL_TREE, then case label was declared using the
5364 usual C/C++ syntax, rather than the GNU case range extension.
5365 CASES is a tree containing all the case ranges processed so far;
5366 COND is the condition for the switch-statement itself. Returns the
5367 CASE_LABEL_EXPR created, or ERROR_MARK_NODE if no CASE_LABEL_EXPR
5371 c_add_case_label (location_t loc
, splay_tree cases
, tree cond
, tree orig_type
,
5372 tree low_value
, tree high_value
)
5377 splay_tree_node node
;
5379 /* Create the LABEL_DECL itself. */
5380 label
= create_artificial_label (loc
);
5382 /* If there was an error processing the switch condition, bail now
5383 before we get more confused. */
5384 if (!cond
|| cond
== error_mark_node
)
5387 if ((low_value
&& TREE_TYPE (low_value
)
5388 && POINTER_TYPE_P (TREE_TYPE (low_value
)))
5389 || (high_value
&& TREE_TYPE (high_value
)
5390 && POINTER_TYPE_P (TREE_TYPE (high_value
))))
5392 error_at (loc
, "pointers are not permitted as case values");
5396 /* Case ranges are a GNU extension. */
5398 pedwarn (loc
, OPT_pedantic
,
5399 "range expressions in switch statements are non-standard");
5401 type
= TREE_TYPE (cond
);
5404 low_value
= check_case_value (low_value
);
5405 low_value
= convert_and_check (type
, low_value
);
5406 if (low_value
== error_mark_node
)
5411 high_value
= check_case_value (high_value
);
5412 high_value
= convert_and_check (type
, high_value
);
5413 if (high_value
== error_mark_node
)
5417 if (low_value
&& high_value
)
5419 /* If the LOW_VALUE and HIGH_VALUE are the same, then this isn't
5420 really a case range, even though it was written that way.
5421 Remove the HIGH_VALUE to simplify later processing. */
5422 if (tree_int_cst_equal (low_value
, high_value
))
5423 high_value
= NULL_TREE
;
5424 else if (!tree_int_cst_lt (low_value
, high_value
))
5425 warning_at (loc
, 0, "empty range specified");
5428 /* See if the case is in range of the type of the original testing
5429 expression. If both low_value and high_value are out of range,
5430 don't insert the case label and return NULL_TREE. */
5432 && !check_case_bounds (type
, orig_type
,
5433 &low_value
, high_value
? &high_value
: NULL
))
5436 /* Look up the LOW_VALUE in the table of case labels we already
5438 node
= splay_tree_lookup (cases
, (splay_tree_key
) low_value
);
5439 /* If there was not an exact match, check for overlapping ranges.
5440 There's no need to do this if there's no LOW_VALUE or HIGH_VALUE;
5441 that's a `default' label and the only overlap is an exact match. */
5442 if (!node
&& (low_value
|| high_value
))
5444 splay_tree_node low_bound
;
5445 splay_tree_node high_bound
;
5447 /* Even though there wasn't an exact match, there might be an
5448 overlap between this case range and another case range.
5449 Since we've (inductively) not allowed any overlapping case
5450 ranges, we simply need to find the greatest low case label
5451 that is smaller that LOW_VALUE, and the smallest low case
5452 label that is greater than LOW_VALUE. If there is an overlap
5453 it will occur in one of these two ranges. */
5454 low_bound
= splay_tree_predecessor (cases
,
5455 (splay_tree_key
) low_value
);
5456 high_bound
= splay_tree_successor (cases
,
5457 (splay_tree_key
) low_value
);
5459 /* Check to see if the LOW_BOUND overlaps. It is smaller than
5460 the LOW_VALUE, so there is no need to check unless the
5461 LOW_BOUND is in fact itself a case range. */
5463 && CASE_HIGH ((tree
) low_bound
->value
)
5464 && tree_int_cst_compare (CASE_HIGH ((tree
) low_bound
->value
),
5467 /* Check to see if the HIGH_BOUND overlaps. The low end of that
5468 range is bigger than the low end of the current range, so we
5469 are only interested if the current range is a real range, and
5470 not an ordinary case label. */
5473 && (tree_int_cst_compare ((tree
) high_bound
->key
,
5478 /* If there was an overlap, issue an error. */
5481 tree duplicate
= CASE_LABEL ((tree
) node
->value
);
5485 error_at (loc
, "duplicate (or overlapping) case value");
5486 error_at (DECL_SOURCE_LOCATION (duplicate
),
5487 "this is the first entry overlapping that value");
5491 error_at (loc
, "duplicate case value") ;
5492 error_at (DECL_SOURCE_LOCATION (duplicate
), "previously used here");
5496 error_at (loc
, "multiple default labels in one switch");
5497 error_at (DECL_SOURCE_LOCATION (duplicate
),
5498 "this is the first default label");
5503 /* Add a CASE_LABEL to the statement-tree. */
5504 case_label
= add_stmt (build_case_label (loc
, low_value
, high_value
, label
));
5505 /* Register this case label in the splay tree. */
5506 splay_tree_insert (cases
,
5507 (splay_tree_key
) low_value
,
5508 (splay_tree_value
) case_label
);
5513 /* Add a label so that the back-end doesn't think that the beginning of
5514 the switch is unreachable. Note that we do not add a case label, as
5515 that just leads to duplicates and thence to failure later on. */
5518 tree t
= create_artificial_label (loc
);
5519 add_stmt (build_stmt (loc
, LABEL_EXPR
, t
));
5521 return error_mark_node
;
5524 /* Subroutines of c_do_switch_warnings, called via splay_tree_foreach.
5525 Used to verify that case values match up with enumerator values. */
5528 match_case_to_enum_1 (tree key
, tree type
, tree label
)
5530 char buf
[2 + 2*HOST_BITS_PER_WIDE_INT
/4 + 1];
5532 /* ??? Not working too hard to print the double-word value.
5533 Should perhaps be done with %lwd in the diagnostic routines? */
5534 if (TREE_INT_CST_HIGH (key
) == 0)
5535 snprintf (buf
, sizeof (buf
), HOST_WIDE_INT_PRINT_UNSIGNED
,
5536 TREE_INT_CST_LOW (key
));
5537 else if (!TYPE_UNSIGNED (type
)
5538 && TREE_INT_CST_HIGH (key
) == -1
5539 && TREE_INT_CST_LOW (key
) != 0)
5540 snprintf (buf
, sizeof (buf
), "-" HOST_WIDE_INT_PRINT_UNSIGNED
,
5541 -TREE_INT_CST_LOW (key
));
5543 snprintf (buf
, sizeof (buf
), HOST_WIDE_INT_PRINT_DOUBLE_HEX
,
5544 (unsigned HOST_WIDE_INT
) TREE_INT_CST_HIGH (key
),
5545 (unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (key
));
5547 if (TYPE_NAME (type
) == 0)
5548 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
5549 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
5550 "case value %qs not in enumerated type",
5553 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label
)),
5554 warn_switch
? OPT_Wswitch
: OPT_Wswitch_enum
,
5555 "case value %qs not in enumerated type %qT",
5559 /* Subroutine of c_do_switch_warnings, called via splay_tree_foreach.
5560 Used to verify that case values match up with enumerator values. */
5563 match_case_to_enum (splay_tree_node node
, void *data
)
5565 tree label
= (tree
) node
->value
;
5566 tree type
= (tree
) data
;
5568 /* Skip default case. */
5569 if (!CASE_LOW (label
))
5572 /* If CASE_LOW_SEEN is not set, that means CASE_LOW did not appear
5573 when we did our enum->case scan. Reset our scratch bit after. */
5574 if (!CASE_LOW_SEEN (label
))
5575 match_case_to_enum_1 (CASE_LOW (label
), type
, label
);
5577 CASE_LOW_SEEN (label
) = 0;
5579 /* If CASE_HIGH is non-null, we have a range. If CASE_HIGH_SEEN is
5580 not set, that means that CASE_HIGH did not appear when we did our
5581 enum->case scan. Reset our scratch bit after. */
5582 if (CASE_HIGH (label
))
5584 if (!CASE_HIGH_SEEN (label
))
5585 match_case_to_enum_1 (CASE_HIGH (label
), type
, label
);
5587 CASE_HIGH_SEEN (label
) = 0;
5593 /* Handle -Wswitch*. Called from the front end after parsing the
5594 switch construct. */
5595 /* ??? Should probably be somewhere generic, since other languages
5596 besides C and C++ would want this. At the moment, however, C/C++
5597 are the only tree-ssa languages that support enumerations at all,
5598 so the point is moot. */
5601 c_do_switch_warnings (splay_tree cases
, location_t switch_location
,
5602 tree type
, tree cond
)
5604 splay_tree_node default_node
;
5605 splay_tree_node node
;
5608 if (!warn_switch
&& !warn_switch_enum
&& !warn_switch_default
)
5611 default_node
= splay_tree_lookup (cases
, (splay_tree_key
) NULL
);
5613 warning_at (switch_location
, OPT_Wswitch_default
,
5614 "switch missing default case");
5616 /* From here on, we only care about about enumerated types. */
5617 if (!type
|| TREE_CODE (type
) != ENUMERAL_TYPE
)
5620 /* From here on, we only care about -Wswitch and -Wswitch-enum. */
5621 if (!warn_switch_enum
&& !warn_switch
)
5624 /* Check the cases. Warn about case values which are not members of
5625 the enumerated type. For -Wswitch-enum, or for -Wswitch when
5626 there is no default case, check that exactly all enumeration
5627 literals are covered by the cases. */
5629 /* Clearing COND if it is not an integer constant simplifies
5630 the tests inside the loop below. */
5631 if (TREE_CODE (cond
) != INTEGER_CST
)
5634 /* The time complexity here is O(N*lg(N)) worst case, but for the
5635 common case of monotonically increasing enumerators, it is
5636 O(N), since the nature of the splay tree will keep the next
5637 element adjacent to the root at all times. */
5639 for (chain
= TYPE_VALUES (type
); chain
; chain
= TREE_CHAIN (chain
))
5641 tree value
= TREE_VALUE (chain
);
5642 if (TREE_CODE (value
) == CONST_DECL
)
5643 value
= DECL_INITIAL (value
);
5644 node
= splay_tree_lookup (cases
, (splay_tree_key
) value
);
5647 /* Mark the CASE_LOW part of the case entry as seen. */
5648 tree label
= (tree
) node
->value
;
5649 CASE_LOW_SEEN (label
) = 1;
5653 /* Even though there wasn't an exact match, there might be a
5654 case range which includes the enumerator's value. */
5655 node
= splay_tree_predecessor (cases
, (splay_tree_key
) value
);
5656 if (node
&& CASE_HIGH ((tree
) node
->value
))
5658 tree label
= (tree
) node
->value
;
5659 int cmp
= tree_int_cst_compare (CASE_HIGH (label
), value
);
5662 /* If we match the upper bound exactly, mark the CASE_HIGH
5663 part of the case entry as seen. */
5665 CASE_HIGH_SEEN (label
) = 1;
5670 /* We've now determined that this enumerated literal isn't
5671 handled by the case labels of the switch statement. */
5673 /* If the switch expression is a constant, we only really care
5674 about whether that constant is handled by the switch. */
5675 if (cond
&& tree_int_cst_compare (cond
, value
))
5678 /* If there is a default_node, the only relevant option is
5679 Wswitch-enum. Otherwise, if both are enabled then we prefer
5680 to warn using -Wswitch because -Wswitch is enabled by -Wall
5681 while -Wswitch-enum is explicit. */
5682 warning_at (switch_location
,
5683 (default_node
|| !warn_switch
5686 "enumeration value %qE not handled in switch",
5687 TREE_PURPOSE (chain
));
5690 /* Warn if there are case expressions that don't correspond to
5691 enumerators. This can occur since C and C++ don't enforce
5692 type-checking of assignments to enumeration variables.
5694 The time complexity here is now always O(N) worst case, since
5695 we should have marked both the lower bound and upper bound of
5696 every disjoint case label, with CASE_LOW_SEEN and CASE_HIGH_SEEN
5697 above. This scan also resets those fields. */
5699 splay_tree_foreach (cases
, match_case_to_enum
, type
);
5702 /* Finish an expression taking the address of LABEL (an
5703 IDENTIFIER_NODE). Returns an expression for the address.
5705 LOC is the location for the expression returned. */
5708 finish_label_address_expr (tree label
, location_t loc
)
5712 pedwarn (input_location
, OPT_pedantic
, "taking the address of a label is non-standard");
5714 if (label
== error_mark_node
)
5715 return error_mark_node
;
5717 label
= lookup_label (label
);
5718 if (label
== NULL_TREE
)
5719 result
= null_pointer_node
;
5722 TREE_USED (label
) = 1;
5723 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
5724 /* The current function is not necessarily uninlinable.
5725 Computed gotos are incompatible with inlining, but the value
5726 here could be used only in a diagnostic, for example. */
5727 protected_set_expr_location (result
, loc
);
5734 /* Given a boolean expression ARG, return a tree representing an increment
5735 or decrement (as indicated by CODE) of ARG. The front end must check for
5736 invalid cases (e.g., decrement in C++). */
5738 boolean_increment (enum tree_code code
, tree arg
)
5741 tree true_res
= build_int_cst (TREE_TYPE (arg
), 1);
5743 arg
= stabilize_reference (arg
);
5746 case PREINCREMENT_EXPR
:
5747 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
5749 case POSTINCREMENT_EXPR
:
5750 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
5751 arg
= save_expr (arg
);
5752 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
5753 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
5755 case PREDECREMENT_EXPR
:
5756 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
5757 invert_truthvalue_loc (input_location
, arg
));
5759 case POSTDECREMENT_EXPR
:
5760 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
5761 invert_truthvalue_loc (input_location
, arg
));
5762 arg
= save_expr (arg
);
5763 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
5764 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
5769 TREE_SIDE_EFFECTS (val
) = 1;
5773 /* Built-in macros for stddef.h and stdint.h, that require macros
5774 defined in this file. */
5776 c_stddef_cpp_builtins(void)
5778 builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE
, 0);
5779 builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE
, 0);
5780 builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE
, 0);
5781 builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE
, 0);
5782 builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE
, 0);
5783 builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE
, 0);
5784 builtin_define_with_value ("__CHAR16_TYPE__", CHAR16_TYPE
, 0);
5785 builtin_define_with_value ("__CHAR32_TYPE__", CHAR32_TYPE
, 0);
5786 if (SIG_ATOMIC_TYPE
)
5787 builtin_define_with_value ("__SIG_ATOMIC_TYPE__", SIG_ATOMIC_TYPE
, 0);
5789 builtin_define_with_value ("__INT8_TYPE__", INT8_TYPE
, 0);
5791 builtin_define_with_value ("__INT16_TYPE__", INT16_TYPE
, 0);
5793 builtin_define_with_value ("__INT32_TYPE__", INT32_TYPE
, 0);
5795 builtin_define_with_value ("__INT64_TYPE__", INT64_TYPE
, 0);
5797 builtin_define_with_value ("__UINT8_TYPE__", UINT8_TYPE
, 0);
5799 builtin_define_with_value ("__UINT16_TYPE__", UINT16_TYPE
, 0);
5801 builtin_define_with_value ("__UINT32_TYPE__", UINT32_TYPE
, 0);
5803 builtin_define_with_value ("__UINT64_TYPE__", UINT64_TYPE
, 0);
5804 if (INT_LEAST8_TYPE
)
5805 builtin_define_with_value ("__INT_LEAST8_TYPE__", INT_LEAST8_TYPE
, 0);
5806 if (INT_LEAST16_TYPE
)
5807 builtin_define_with_value ("__INT_LEAST16_TYPE__", INT_LEAST16_TYPE
, 0);
5808 if (INT_LEAST32_TYPE
)
5809 builtin_define_with_value ("__INT_LEAST32_TYPE__", INT_LEAST32_TYPE
, 0);
5810 if (INT_LEAST64_TYPE
)
5811 builtin_define_with_value ("__INT_LEAST64_TYPE__", INT_LEAST64_TYPE
, 0);
5812 if (UINT_LEAST8_TYPE
)
5813 builtin_define_with_value ("__UINT_LEAST8_TYPE__", UINT_LEAST8_TYPE
, 0);
5814 if (UINT_LEAST16_TYPE
)
5815 builtin_define_with_value ("__UINT_LEAST16_TYPE__", UINT_LEAST16_TYPE
, 0);
5816 if (UINT_LEAST32_TYPE
)
5817 builtin_define_with_value ("__UINT_LEAST32_TYPE__", UINT_LEAST32_TYPE
, 0);
5818 if (UINT_LEAST64_TYPE
)
5819 builtin_define_with_value ("__UINT_LEAST64_TYPE__", UINT_LEAST64_TYPE
, 0);
5821 builtin_define_with_value ("__INT_FAST8_TYPE__", INT_FAST8_TYPE
, 0);
5822 if (INT_FAST16_TYPE
)
5823 builtin_define_with_value ("__INT_FAST16_TYPE__", INT_FAST16_TYPE
, 0);
5824 if (INT_FAST32_TYPE
)
5825 builtin_define_with_value ("__INT_FAST32_TYPE__", INT_FAST32_TYPE
, 0);
5826 if (INT_FAST64_TYPE
)
5827 builtin_define_with_value ("__INT_FAST64_TYPE__", INT_FAST64_TYPE
, 0);
5828 if (UINT_FAST8_TYPE
)
5829 builtin_define_with_value ("__UINT_FAST8_TYPE__", UINT_FAST8_TYPE
, 0);
5830 if (UINT_FAST16_TYPE
)
5831 builtin_define_with_value ("__UINT_FAST16_TYPE__", UINT_FAST16_TYPE
, 0);
5832 if (UINT_FAST32_TYPE
)
5833 builtin_define_with_value ("__UINT_FAST32_TYPE__", UINT_FAST32_TYPE
, 0);
5834 if (UINT_FAST64_TYPE
)
5835 builtin_define_with_value ("__UINT_FAST64_TYPE__", UINT_FAST64_TYPE
, 0);
5837 builtin_define_with_value ("__INTPTR_TYPE__", INTPTR_TYPE
, 0);
5839 builtin_define_with_value ("__UINTPTR_TYPE__", UINTPTR_TYPE
, 0);
5843 c_init_attributes (void)
5845 /* Fill in the built_in_attributes array. */
5846 #define DEF_ATTR_NULL_TREE(ENUM) \
5847 built_in_attributes[(int) ENUM] = NULL_TREE;
5848 #define DEF_ATTR_INT(ENUM, VALUE) \
5849 built_in_attributes[(int) ENUM] = build_int_cst (NULL_TREE, VALUE);
5850 #define DEF_ATTR_IDENT(ENUM, STRING) \
5851 built_in_attributes[(int) ENUM] = get_identifier (STRING);
5852 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
5853 built_in_attributes[(int) ENUM] \
5854 = tree_cons (built_in_attributes[(int) PURPOSE], \
5855 built_in_attributes[(int) VALUE], \
5856 built_in_attributes[(int) CHAIN]);
5857 #include "builtin-attrs.def"
5858 #undef DEF_ATTR_NULL_TREE
5860 #undef DEF_ATTR_IDENT
5861 #undef DEF_ATTR_TREE_LIST
5864 /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain
5865 identifier as an argument, so the front end shouldn't look it up. */
5868 attribute_takes_identifier_p (const_tree attr_id
)
5870 if (is_attribute_p ("mode", attr_id
)
5871 || is_attribute_p ("format", attr_id
)
5872 || is_attribute_p ("cleanup", attr_id
))
5875 return targetm
.attribute_takes_identifier_p (attr_id
);
5878 /* Attribute handlers common to C front ends. */
5880 /* Handle a "packed" attribute; arguments as in
5881 struct attribute_spec.handler. */
5884 handle_packed_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
5885 int flags
, bool *no_add_attrs
)
5889 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
5890 *node
= build_variant_type_copy (*node
);
5891 TYPE_PACKED (*node
) = 1;
5893 else if (TREE_CODE (*node
) == FIELD_DECL
)
5895 if (TYPE_ALIGN (TREE_TYPE (*node
)) <= BITS_PER_UNIT
5896 /* Still pack bitfields. */
5897 && ! DECL_INITIAL (*node
))
5898 warning (OPT_Wattributes
,
5899 "%qE attribute ignored for field of type %qT",
5900 name
, TREE_TYPE (*node
));
5902 DECL_PACKED (*node
) = 1;
5904 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
5905 used for DECL_REGISTER. It wouldn't mean anything anyway.
5906 We can't set DECL_PACKED on the type of a TYPE_DECL, because
5907 that changes what the typedef is typing. */
5910 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
5911 *no_add_attrs
= true;
5917 /* Handle a "nocommon" attribute; arguments as in
5918 struct attribute_spec.handler. */
5921 handle_nocommon_attribute (tree
*node
, tree name
,
5922 tree
ARG_UNUSED (args
),
5923 int ARG_UNUSED (flags
), bool *no_add_attrs
)
5925 if (TREE_CODE (*node
) == VAR_DECL
)
5926 DECL_COMMON (*node
) = 0;
5929 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
5930 *no_add_attrs
= true;
5936 /* Handle a "common" attribute; arguments as in
5937 struct attribute_spec.handler. */
5940 handle_common_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
5941 int ARG_UNUSED (flags
), bool *no_add_attrs
)
5943 if (TREE_CODE (*node
) == VAR_DECL
)
5944 DECL_COMMON (*node
) = 1;
5947 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
5948 *no_add_attrs
= true;
5954 /* Handle a "noreturn" attribute; arguments as in
5955 struct attribute_spec.handler. */
5958 handle_noreturn_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
5959 int ARG_UNUSED (flags
), bool *no_add_attrs
)
5961 tree type
= TREE_TYPE (*node
);
5963 /* See FIXME comment in c_common_attribute_table. */
5964 if (TREE_CODE (*node
) == FUNCTION_DECL
)
5965 TREE_THIS_VOLATILE (*node
) = 1;
5966 else if (TREE_CODE (type
) == POINTER_TYPE
5967 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
5969 = build_pointer_type
5970 (build_type_variant (TREE_TYPE (type
),
5971 TYPE_READONLY (TREE_TYPE (type
)), 1));
5974 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
5975 *no_add_attrs
= true;
5981 /* Handle a "hot" and attribute; arguments as in
5982 struct attribute_spec.handler. */
5985 handle_hot_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
5986 int ARG_UNUSED (flags
), bool *no_add_attrs
)
5988 if (TREE_CODE (*node
) == FUNCTION_DECL
)
5990 if (lookup_attribute ("cold", DECL_ATTRIBUTES (*node
)) != NULL
)
5992 warning (OPT_Wattributes
, "%qE attribute conflicts with attribute %s",
5994 *no_add_attrs
= true;
5996 /* Most of the rest of the hot processing is done later with
5997 lookup_attribute. */
6001 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6002 *no_add_attrs
= true;
6007 /* Handle a "cold" and attribute; arguments as in
6008 struct attribute_spec.handler. */
6011 handle_cold_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6012 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6014 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6016 if (lookup_attribute ("hot", DECL_ATTRIBUTES (*node
)) != NULL
)
6018 warning (OPT_Wattributes
, "%qE attribute conflicts with attribute %s",
6020 *no_add_attrs
= true;
6022 /* Most of the rest of the cold processing is done later with
6023 lookup_attribute. */
6027 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6028 *no_add_attrs
= true;
6034 /* Handle a "noinline" attribute; arguments as in
6035 struct attribute_spec.handler. */
6038 handle_noinline_attribute (tree
*node
, tree name
,
6039 tree
ARG_UNUSED (args
),
6040 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6042 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6043 DECL_UNINLINABLE (*node
) = 1;
6046 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6047 *no_add_attrs
= true;
6053 /* Handle a "noclone" attribute; arguments as in
6054 struct attribute_spec.handler. */
6057 handle_noclone_attribute (tree
*node
, tree name
,
6058 tree
ARG_UNUSED (args
),
6059 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6061 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6063 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6064 *no_add_attrs
= true;
6070 /* Handle a "always_inline" attribute; arguments as in
6071 struct attribute_spec.handler. */
6074 handle_always_inline_attribute (tree
*node
, tree name
,
6075 tree
ARG_UNUSED (args
),
6076 int ARG_UNUSED (flags
),
6079 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6081 /* Set the attribute and mark it for disregarding inline
6083 DECL_DISREGARD_INLINE_LIMITS (*node
) = 1;
6087 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6088 *no_add_attrs
= true;
6094 /* Handle a "gnu_inline" attribute; arguments as in
6095 struct attribute_spec.handler. */
6098 handle_gnu_inline_attribute (tree
*node
, tree name
,
6099 tree
ARG_UNUSED (args
),
6100 int ARG_UNUSED (flags
),
6103 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
6105 /* Do nothing else, just set the attribute. We'll get at
6106 it later with lookup_attribute. */
6110 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6111 *no_add_attrs
= true;
6117 /* Handle an "artificial" attribute; arguments as in
6118 struct attribute_spec.handler. */
6121 handle_artificial_attribute (tree
*node
, tree name
,
6122 tree
ARG_UNUSED (args
),
6123 int ARG_UNUSED (flags
),
6126 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
6128 /* Do nothing else, just set the attribute. We'll get at
6129 it later with lookup_attribute. */
6133 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6134 *no_add_attrs
= true;
6140 /* Handle a "flatten" attribute; arguments as in
6141 struct attribute_spec.handler. */
6144 handle_flatten_attribute (tree
*node
, tree name
,
6145 tree args ATTRIBUTE_UNUSED
,
6146 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
6148 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6149 /* Do nothing else, just set the attribute. We'll get at
6150 it later with lookup_attribute. */
6154 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6155 *no_add_attrs
= true;
6161 /* Handle a "warning" or "error" attribute; arguments as in
6162 struct attribute_spec.handler. */
6165 handle_error_attribute (tree
*node
, tree name
, tree args
,
6166 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6168 if (TREE_CODE (*node
) == FUNCTION_DECL
6169 || TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
6170 /* Do nothing else, just set the attribute. We'll get at
6171 it later with lookup_attribute. */
6175 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6176 *no_add_attrs
= true;
6182 /* Handle a "used" attribute; arguments as in
6183 struct attribute_spec.handler. */
6186 handle_used_attribute (tree
*pnode
, tree name
, tree
ARG_UNUSED (args
),
6187 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6191 if (TREE_CODE (node
) == FUNCTION_DECL
6192 || (TREE_CODE (node
) == VAR_DECL
&& TREE_STATIC (node
)))
6194 TREE_USED (node
) = 1;
6195 DECL_PRESERVE_P (node
) = 1;
6196 if (TREE_CODE (node
) == VAR_DECL
)
6197 DECL_READ_P (node
) = 1;
6201 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6202 *no_add_attrs
= true;
6208 /* Handle a "unused" attribute; arguments as in
6209 struct attribute_spec.handler. */
6212 handle_unused_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6213 int flags
, bool *no_add_attrs
)
6219 if (TREE_CODE (decl
) == PARM_DECL
6220 || TREE_CODE (decl
) == VAR_DECL
6221 || TREE_CODE (decl
) == FUNCTION_DECL
6222 || TREE_CODE (decl
) == LABEL_DECL
6223 || TREE_CODE (decl
) == TYPE_DECL
)
6225 TREE_USED (decl
) = 1;
6226 if (TREE_CODE (decl
) == VAR_DECL
6227 || TREE_CODE (decl
) == PARM_DECL
)
6228 DECL_READ_P (decl
) = 1;
6232 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6233 *no_add_attrs
= true;
6238 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6239 *node
= build_variant_type_copy (*node
);
6240 TREE_USED (*node
) = 1;
6246 /* Handle a "externally_visible" attribute; arguments as in
6247 struct attribute_spec.handler. */
6250 handle_externally_visible_attribute (tree
*pnode
, tree name
,
6251 tree
ARG_UNUSED (args
),
6252 int ARG_UNUSED (flags
),
6257 if (TREE_CODE (node
) == FUNCTION_DECL
|| TREE_CODE (node
) == VAR_DECL
)
6259 if ((!TREE_STATIC (node
) && TREE_CODE (node
) != FUNCTION_DECL
6260 && !DECL_EXTERNAL (node
)) || !TREE_PUBLIC (node
))
6262 warning (OPT_Wattributes
,
6263 "%qE attribute have effect only on public objects", name
);
6264 *no_add_attrs
= true;
6269 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6270 *no_add_attrs
= true;
6276 /* Handle a "const" attribute; arguments as in
6277 struct attribute_spec.handler. */
6280 handle_const_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
6281 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6283 tree type
= TREE_TYPE (*node
);
6285 /* See FIXME comment on noreturn in c_common_attribute_table. */
6286 if (TREE_CODE (*node
) == FUNCTION_DECL
)
6287 TREE_READONLY (*node
) = 1;
6288 else if (TREE_CODE (type
) == POINTER_TYPE
6289 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
6291 = build_pointer_type
6292 (build_type_variant (TREE_TYPE (type
), 1,
6293 TREE_THIS_VOLATILE (TREE_TYPE (type
))));
6296 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6297 *no_add_attrs
= true;
6303 /* Handle a "transparent_union" attribute; arguments as in
6304 struct attribute_spec.handler. */
6307 handle_transparent_union_attribute (tree
*node
, tree name
,
6308 tree
ARG_UNUSED (args
), int flags
,
6313 *no_add_attrs
= true;
6315 if (TREE_CODE (*node
) == TYPE_DECL
)
6316 node
= &TREE_TYPE (*node
);
6319 if (TREE_CODE (type
) == UNION_TYPE
)
6321 /* When IN_PLACE is set, leave the check for FIELDS and MODE to
6322 the code in finish_struct. */
6323 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6325 if (TYPE_FIELDS (type
) == NULL_TREE
6326 || TYPE_MODE (type
) != DECL_MODE (TYPE_FIELDS (type
)))
6329 /* A type variant isn't good enough, since we don't a cast
6330 to such a type removed as a no-op. */
6331 *node
= type
= build_duplicate_type (type
);
6334 TYPE_TRANSPARENT_AGGR (type
) = 1;
6339 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6343 /* Subroutine of handle_{con,de}structor_attribute. Evaluate ARGS to
6344 get the requested priority for a constructor or destructor,
6345 possibly issuing diagnostics for invalid or reserved
6348 static priority_type
6349 get_priority (tree args
, bool is_destructor
)
6355 return DEFAULT_INIT_PRIORITY
;
6357 if (!SUPPORTS_INIT_PRIORITY
)
6360 error ("destructor priorities are not supported");
6362 error ("constructor priorities are not supported");
6363 return DEFAULT_INIT_PRIORITY
;
6366 arg
= TREE_VALUE (args
);
6367 if (!host_integerp (arg
, /*pos=*/0)
6368 || !INTEGRAL_TYPE_P (TREE_TYPE (arg
)))
6371 pri
= tree_low_cst (TREE_VALUE (args
), /*pos=*/0);
6372 if (pri
< 0 || pri
> MAX_INIT_PRIORITY
)
6375 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
6379 "destructor priorities from 0 to %d are reserved "
6380 "for the implementation",
6381 MAX_RESERVED_INIT_PRIORITY
);
6384 "constructor priorities from 0 to %d are reserved "
6385 "for the implementation",
6386 MAX_RESERVED_INIT_PRIORITY
);
6392 error ("destructor priorities must be integers from 0 to %d inclusive",
6395 error ("constructor priorities must be integers from 0 to %d inclusive",
6397 return DEFAULT_INIT_PRIORITY
;
6400 /* Handle a "constructor" attribute; arguments as in
6401 struct attribute_spec.handler. */
6404 handle_constructor_attribute (tree
*node
, tree name
, tree args
,
6405 int ARG_UNUSED (flags
),
6409 tree type
= TREE_TYPE (decl
);
6411 if (TREE_CODE (decl
) == FUNCTION_DECL
6412 && TREE_CODE (type
) == FUNCTION_TYPE
6413 && decl_function_context (decl
) == 0)
6415 priority_type priority
;
6416 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
6417 priority
= get_priority (args
, /*is_destructor=*/false);
6418 SET_DECL_INIT_PRIORITY (decl
, priority
);
6419 TREE_USED (decl
) = 1;
6423 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6424 *no_add_attrs
= true;
6430 /* Handle a "destructor" attribute; arguments as in
6431 struct attribute_spec.handler. */
6434 handle_destructor_attribute (tree
*node
, tree name
, tree args
,
6435 int ARG_UNUSED (flags
),
6439 tree type
= TREE_TYPE (decl
);
6441 if (TREE_CODE (decl
) == FUNCTION_DECL
6442 && TREE_CODE (type
) == FUNCTION_TYPE
6443 && decl_function_context (decl
) == 0)
6445 priority_type priority
;
6446 DECL_STATIC_DESTRUCTOR (decl
) = 1;
6447 priority
= get_priority (args
, /*is_destructor=*/true);
6448 SET_DECL_FINI_PRIORITY (decl
, priority
);
6449 TREE_USED (decl
) = 1;
6453 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6454 *no_add_attrs
= true;
6460 /* Handle a "mode" attribute; arguments as in
6461 struct attribute_spec.handler. */
6464 handle_mode_attribute (tree
*node
, tree name
, tree args
,
6465 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6468 tree ident
= TREE_VALUE (args
);
6470 *no_add_attrs
= true;
6472 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
6473 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6477 const char *p
= IDENTIFIER_POINTER (ident
);
6478 int len
= strlen (p
);
6479 enum machine_mode mode
= VOIDmode
;
6483 if (len
> 4 && p
[0] == '_' && p
[1] == '_'
6484 && p
[len
- 1] == '_' && p
[len
- 2] == '_')
6486 char *newp
= (char *) alloca (len
- 1);
6488 strcpy (newp
, &p
[2]);
6489 newp
[len
- 4] = '\0';
6493 /* Change this type to have a type with the specified mode.
6494 First check for the special modes. */
6495 if (!strcmp (p
, "byte"))
6497 else if (!strcmp (p
, "word"))
6499 else if (!strcmp (p
, "pointer"))
6501 else if (!strcmp (p
, "libgcc_cmp_return"))
6502 mode
= targetm
.libgcc_cmp_return_mode ();
6503 else if (!strcmp (p
, "libgcc_shift_count"))
6504 mode
= targetm
.libgcc_shift_count_mode ();
6505 else if (!strcmp (p
, "unwind_word"))
6506 mode
= targetm
.unwind_word_mode ();
6508 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
6509 if (!strcmp (p
, GET_MODE_NAME (j
)))
6511 mode
= (enum machine_mode
) j
;
6515 if (mode
== VOIDmode
)
6517 error ("unknown machine mode %qE", ident
);
6522 switch (GET_MODE_CLASS (mode
))
6525 case MODE_PARTIAL_INT
:
6527 case MODE_DECIMAL_FLOAT
:
6532 valid_mode
= targetm
.scalar_mode_supported_p (mode
);
6535 case MODE_COMPLEX_INT
:
6536 case MODE_COMPLEX_FLOAT
:
6537 valid_mode
= targetm
.scalar_mode_supported_p (GET_MODE_INNER (mode
));
6540 case MODE_VECTOR_INT
:
6541 case MODE_VECTOR_FLOAT
:
6542 case MODE_VECTOR_FRACT
:
6543 case MODE_VECTOR_UFRACT
:
6544 case MODE_VECTOR_ACCUM
:
6545 case MODE_VECTOR_UACCUM
:
6546 warning (OPT_Wattributes
, "specifying vector types with "
6547 "__attribute__ ((mode)) is deprecated");
6548 warning (OPT_Wattributes
,
6549 "use __attribute__ ((vector_size)) instead");
6550 valid_mode
= vector_mode_valid_p (mode
);
6558 error ("unable to emulate %qs", p
);
6562 if (POINTER_TYPE_P (type
))
6564 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
6565 tree (*fn
)(tree
, enum machine_mode
, bool);
6567 if (!targetm
.addr_space
.valid_pointer_mode (mode
, as
))
6569 error ("invalid pointer mode %qs", p
);
6573 if (TREE_CODE (type
) == POINTER_TYPE
)
6574 fn
= build_pointer_type_for_mode
;
6576 fn
= build_reference_type_for_mode
;
6577 typefm
= fn (TREE_TYPE (type
), mode
, false);
6581 /* For fixed-point modes, we need to test if the signness of type
6582 and the machine mode are consistent. */
6583 if (ALL_FIXED_POINT_MODE_P (mode
)
6584 && TYPE_UNSIGNED (type
) != UNSIGNED_FIXED_POINT_MODE_P (mode
))
6586 error ("signness of type and machine mode %qs don't match", p
);
6589 /* For fixed-point modes, we need to pass saturating info. */
6590 typefm
= lang_hooks
.types
.type_for_mode (mode
,
6591 ALL_FIXED_POINT_MODE_P (mode
) ? TYPE_SATURATING (type
)
6592 : TYPE_UNSIGNED (type
));
6595 if (typefm
== NULL_TREE
)
6597 error ("no data type for mode %qs", p
);
6600 else if (TREE_CODE (type
) == ENUMERAL_TYPE
)
6602 /* For enumeral types, copy the precision from the integer
6603 type returned above. If not an INTEGER_TYPE, we can't use
6604 this mode for this type. */
6605 if (TREE_CODE (typefm
) != INTEGER_TYPE
)
6607 error ("cannot use mode %qs for enumeral types", p
);
6611 if (flags
& ATTR_FLAG_TYPE_IN_PLACE
)
6613 TYPE_PRECISION (type
) = TYPE_PRECISION (typefm
);
6618 /* We cannot build a type variant, as there's code that assumes
6619 that TYPE_MAIN_VARIANT has the same mode. This includes the
6620 debug generators. Instead, create a subrange type. This
6621 results in all of the enumeral values being emitted only once
6622 in the original, and the subtype gets them by reference. */
6623 if (TYPE_UNSIGNED (type
))
6624 typefm
= make_unsigned_type (TYPE_PRECISION (typefm
));
6626 typefm
= make_signed_type (TYPE_PRECISION (typefm
));
6627 TREE_TYPE (typefm
) = type
;
6630 else if (VECTOR_MODE_P (mode
)
6631 ? TREE_CODE (type
) != TREE_CODE (TREE_TYPE (typefm
))
6632 : TREE_CODE (type
) != TREE_CODE (typefm
))
6634 error ("mode %qs applied to inappropriate type", p
);
6644 /* Handle a "section" attribute; arguments as in
6645 struct attribute_spec.handler. */
6648 handle_section_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
6649 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6653 if (targetm
.have_named_sections
)
6655 user_defined_section_attribute
= true;
6657 if ((TREE_CODE (decl
) == FUNCTION_DECL
6658 || TREE_CODE (decl
) == VAR_DECL
)
6659 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
6661 if (TREE_CODE (decl
) == VAR_DECL
6662 && current_function_decl
!= NULL_TREE
6663 && !TREE_STATIC (decl
))
6665 error_at (DECL_SOURCE_LOCATION (decl
),
6666 "section attribute cannot be specified for "
6668 *no_add_attrs
= true;
6671 /* The decl may have already been given a section attribute
6672 from a previous declaration. Ensure they match. */
6673 else if (DECL_SECTION_NAME (decl
) != NULL_TREE
6674 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl
)),
6675 TREE_STRING_POINTER (TREE_VALUE (args
))) != 0)
6677 error ("section of %q+D conflicts with previous declaration",
6679 *no_add_attrs
= true;
6681 else if (TREE_CODE (decl
) == VAR_DECL
6682 && !targetm
.have_tls
&& targetm
.emutls
.tmpl_section
6683 && DECL_THREAD_LOCAL_P (decl
))
6685 error ("section of %q+D cannot be overridden", *node
);
6686 *no_add_attrs
= true;
6689 DECL_SECTION_NAME (decl
) = TREE_VALUE (args
);
6693 error ("section attribute not allowed for %q+D", *node
);
6694 *no_add_attrs
= true;
6699 error_at (DECL_SOURCE_LOCATION (*node
),
6700 "section attributes are not supported for this target");
6701 *no_add_attrs
= true;
6707 /* Handle a "aligned" attribute; arguments as in
6708 struct attribute_spec.handler. */
6711 handle_aligned_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
6712 int flags
, bool *no_add_attrs
)
6714 tree decl
= NULL_TREE
;
6717 tree align_expr
= (args
? TREE_VALUE (args
)
6718 : size_int (ATTRIBUTE_ALIGNED_VALUE
/ BITS_PER_UNIT
));
6724 type
= &TREE_TYPE (decl
);
6725 is_type
= TREE_CODE (*node
) == TYPE_DECL
;
6727 else if (TYPE_P (*node
))
6728 type
= node
, is_type
= 1;
6730 if (TREE_CODE (align_expr
) != INTEGER_CST
)
6732 error ("requested alignment is not a constant");
6733 *no_add_attrs
= true;
6735 else if ((i
= tree_log2 (align_expr
)) == -1)
6737 error ("requested alignment is not a power of 2");
6738 *no_add_attrs
= true;
6740 else if (i
>= HOST_BITS_PER_INT
- BITS_PER_UNIT_LOG
)
6742 error ("requested alignment is too large");
6743 *no_add_attrs
= true;
6747 if ((flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
6748 /* OK, modify the type in place. */;
6749 /* If we have a TYPE_DECL, then copy the type, so that we
6750 don't accidentally modify a builtin type. See pushdecl. */
6751 else if (decl
&& TREE_TYPE (decl
) != error_mark_node
6752 && DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
)
6754 tree tt
= TREE_TYPE (decl
);
6755 *type
= build_variant_type_copy (*type
);
6756 DECL_ORIGINAL_TYPE (decl
) = tt
;
6757 TYPE_NAME (*type
) = decl
;
6758 TREE_USED (*type
) = TREE_USED (decl
);
6759 TREE_TYPE (decl
) = *type
;
6762 *type
= build_variant_type_copy (*type
);
6764 TYPE_ALIGN (*type
) = (1U << i
) * BITS_PER_UNIT
;
6765 TYPE_USER_ALIGN (*type
) = 1;
6767 else if (! VAR_OR_FUNCTION_DECL_P (decl
)
6768 && TREE_CODE (decl
) != FIELD_DECL
)
6770 error ("alignment may not be specified for %q+D", decl
);
6771 *no_add_attrs
= true;
6773 else if (TREE_CODE (decl
) == FUNCTION_DECL
6774 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
6776 if (DECL_USER_ALIGN (decl
))
6777 error ("alignment for %q+D was previously specified as %d "
6778 "and may not be decreased", decl
,
6779 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
6781 error ("alignment for %q+D must be at least %d", decl
,
6782 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
6783 *no_add_attrs
= true;
6787 DECL_ALIGN (decl
) = (1U << i
) * BITS_PER_UNIT
;
6788 DECL_USER_ALIGN (decl
) = 1;
6794 /* Handle a "weak" attribute; arguments as in
6795 struct attribute_spec.handler. */
6798 handle_weak_attribute (tree
*node
, tree name
,
6799 tree
ARG_UNUSED (args
),
6800 int ARG_UNUSED (flags
),
6801 bool * ARG_UNUSED (no_add_attrs
))
6803 if (TREE_CODE (*node
) == FUNCTION_DECL
6804 && DECL_DECLARED_INLINE_P (*node
))
6806 error ("inline function %q+D cannot be declared weak", *node
);
6807 *no_add_attrs
= true;
6809 else if (TREE_CODE (*node
) == FUNCTION_DECL
6810 || TREE_CODE (*node
) == VAR_DECL
)
6811 declare_weak (*node
);
6813 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6818 /* Handle an "alias" attribute; arguments as in
6819 struct attribute_spec.handler. */
6822 handle_alias_attribute (tree
*node
, tree name
, tree args
,
6823 int ARG_UNUSED (flags
), bool *no_add_attrs
)
6827 if (TREE_CODE (decl
) != FUNCTION_DECL
&& TREE_CODE (decl
) != VAR_DECL
)
6829 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6830 *no_add_attrs
= true;
6832 else if ((TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INITIAL (decl
))
6833 || (TREE_CODE (decl
) != FUNCTION_DECL
6834 && TREE_PUBLIC (decl
) && !DECL_EXTERNAL (decl
))
6835 /* A static variable declaration is always a tentative definition,
6836 but the alias is a non-tentative definition which overrides. */
6837 || (TREE_CODE (decl
) != FUNCTION_DECL
6838 && ! TREE_PUBLIC (decl
) && DECL_INITIAL (decl
)))
6840 error ("%q+D defined both normally and as an alias", decl
);
6841 *no_add_attrs
= true;
6844 /* Note that the very first time we process a nested declaration,
6845 decl_function_context will not be set. Indeed, *would* never
6846 be set except for the DECL_INITIAL/DECL_EXTERNAL frobbery that
6847 we do below. After such frobbery, pushdecl would set the context.
6848 In any case, this is never what we want. */
6849 else if (decl_function_context (decl
) == 0 && current_function_decl
== NULL
)
6853 id
= TREE_VALUE (args
);
6854 if (TREE_CODE (id
) != STRING_CST
)
6856 error ("alias argument not a string");
6857 *no_add_attrs
= true;
6860 id
= get_identifier (TREE_STRING_POINTER (id
));
6861 /* This counts as a use of the object pointed to. */
6864 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6865 DECL_INITIAL (decl
) = error_mark_node
;
6868 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
6869 DECL_EXTERNAL (decl
) = 1;
6871 DECL_EXTERNAL (decl
) = 0;
6872 TREE_STATIC (decl
) = 1;
6877 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6878 *no_add_attrs
= true;
6884 /* Handle a "weakref" attribute; arguments as in struct
6885 attribute_spec.handler. */
6888 handle_weakref_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
6889 int flags
, bool *no_add_attrs
)
6891 tree attr
= NULL_TREE
;
6893 /* We must ignore the attribute when it is associated with
6894 local-scoped decls, since attribute alias is ignored and many
6895 such symbols do not even have a DECL_WEAK field. */
6896 if (decl_function_context (*node
)
6897 || current_function_decl
6898 || (TREE_CODE (*node
) != VAR_DECL
&& TREE_CODE (*node
) != FUNCTION_DECL
))
6900 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6901 *no_add_attrs
= true;
6905 /* The idea here is that `weakref("name")' mutates into `weakref,
6906 alias("name")', and weakref without arguments, in turn,
6907 implicitly adds weak. */
6911 attr
= tree_cons (get_identifier ("alias"), args
, attr
);
6912 attr
= tree_cons (get_identifier ("weakref"), NULL_TREE
, attr
);
6914 *no_add_attrs
= true;
6916 decl_attributes (node
, attr
, flags
);
6920 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node
)))
6921 error_at (DECL_SOURCE_LOCATION (*node
),
6922 "weakref attribute must appear before alias attribute");
6924 /* Can't call declare_weak because it wants this to be TREE_PUBLIC,
6925 and that isn't supported; and because it wants to add it to
6926 the list of weak decls, which isn't helpful. */
6927 DECL_WEAK (*node
) = 1;
6933 /* Handle an "visibility" attribute; arguments as in
6934 struct attribute_spec.handler. */
6937 handle_visibility_attribute (tree
*node
, tree name
, tree args
,
6938 int ARG_UNUSED (flags
),
6939 bool *ARG_UNUSED (no_add_attrs
))
6942 tree id
= TREE_VALUE (args
);
6943 enum symbol_visibility vis
;
6947 if (TREE_CODE (*node
) == ENUMERAL_TYPE
)
6949 else if (TREE_CODE (*node
) != RECORD_TYPE
&& TREE_CODE (*node
) != UNION_TYPE
)
6951 warning (OPT_Wattributes
, "%qE attribute ignored on non-class types",
6955 else if (TYPE_FIELDS (*node
))
6957 error ("%qE attribute ignored because %qT is already defined",
6962 else if (decl_function_context (decl
) != 0 || !TREE_PUBLIC (decl
))
6964 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6968 if (TREE_CODE (id
) != STRING_CST
)
6970 error ("visibility argument not a string");
6974 /* If this is a type, set the visibility on the type decl. */
6977 decl
= TYPE_NAME (decl
);
6980 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
6982 warning (OPT_Wattributes
, "%qE attribute ignored on types",
6988 if (strcmp (TREE_STRING_POINTER (id
), "default") == 0)
6989 vis
= VISIBILITY_DEFAULT
;
6990 else if (strcmp (TREE_STRING_POINTER (id
), "internal") == 0)
6991 vis
= VISIBILITY_INTERNAL
;
6992 else if (strcmp (TREE_STRING_POINTER (id
), "hidden") == 0)
6993 vis
= VISIBILITY_HIDDEN
;
6994 else if (strcmp (TREE_STRING_POINTER (id
), "protected") == 0)
6995 vis
= VISIBILITY_PROTECTED
;
6998 error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
6999 vis
= VISIBILITY_DEFAULT
;
7002 if (DECL_VISIBILITY_SPECIFIED (decl
)
7003 && vis
!= DECL_VISIBILITY (decl
))
7005 tree attributes
= (TYPE_P (*node
)
7006 ? TYPE_ATTRIBUTES (*node
)
7007 : DECL_ATTRIBUTES (decl
));
7008 if (lookup_attribute ("visibility", attributes
))
7009 error ("%qD redeclared with different visibility", decl
);
7010 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
7011 && lookup_attribute ("dllimport", attributes
))
7012 error ("%qD was declared %qs which implies default visibility",
7014 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
7015 && lookup_attribute ("dllexport", attributes
))
7016 error ("%qD was declared %qs which implies default visibility",
7020 DECL_VISIBILITY (decl
) = vis
;
7021 DECL_VISIBILITY_SPECIFIED (decl
) = 1;
7023 /* Go ahead and attach the attribute to the node as well. This is needed
7024 so we can determine whether we have VISIBILITY_DEFAULT because the
7025 visibility was not specified, or because it was explicitly overridden
7026 from the containing scope. */
7031 /* Determine the ELF symbol visibility for DECL, which is either a
7032 variable or a function. It is an error to use this function if a
7033 definition of DECL is not available in this translation unit.
7034 Returns true if the final visibility has been determined by this
7035 function; false if the caller is free to make additional
7039 c_determine_visibility (tree decl
)
7041 gcc_assert (TREE_CODE (decl
) == VAR_DECL
7042 || TREE_CODE (decl
) == FUNCTION_DECL
);
7044 /* If the user explicitly specified the visibility with an
7045 attribute, honor that. DECL_VISIBILITY will have been set during
7046 the processing of the attribute. We check for an explicit
7047 attribute, rather than just checking DECL_VISIBILITY_SPECIFIED,
7048 to distinguish the use of an attribute from the use of a "#pragma
7049 GCC visibility push(...)"; in the latter case we still want other
7050 considerations to be able to overrule the #pragma. */
7051 if (lookup_attribute ("visibility", DECL_ATTRIBUTES (decl
))
7052 || (TARGET_DLLIMPORT_DECL_ATTRIBUTES
7053 && (lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl
))
7054 || lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl
)))))
7057 /* Set default visibility to whatever the user supplied with
7058 visibility_specified depending on #pragma GCC visibility. */
7059 if (!DECL_VISIBILITY_SPECIFIED (decl
))
7061 if (visibility_options
.inpragma
7062 || DECL_VISIBILITY (decl
) != default_visibility
)
7064 DECL_VISIBILITY (decl
) = default_visibility
;
7065 DECL_VISIBILITY_SPECIFIED (decl
) = visibility_options
.inpragma
;
7066 /* If visibility changed and DECL already has DECL_RTL, ensure
7067 symbol flags are updated. */
7068 if (((TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
))
7069 || TREE_CODE (decl
) == FUNCTION_DECL
)
7070 && DECL_RTL_SET_P (decl
))
7071 make_decl_rtl (decl
);
7077 /* Handle an "tls_model" attribute; arguments as in
7078 struct attribute_spec.handler. */
7081 handle_tls_model_attribute (tree
*node
, tree name
, tree args
,
7082 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7086 enum tls_model kind
;
7088 *no_add_attrs
= true;
7090 if (TREE_CODE (decl
) != VAR_DECL
|| !DECL_THREAD_LOCAL_P (decl
))
7092 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7096 kind
= DECL_TLS_MODEL (decl
);
7097 id
= TREE_VALUE (args
);
7098 if (TREE_CODE (id
) != STRING_CST
)
7100 error ("tls_model argument not a string");
7104 if (!strcmp (TREE_STRING_POINTER (id
), "local-exec"))
7105 kind
= TLS_MODEL_LOCAL_EXEC
;
7106 else if (!strcmp (TREE_STRING_POINTER (id
), "initial-exec"))
7107 kind
= TLS_MODEL_INITIAL_EXEC
;
7108 else if (!strcmp (TREE_STRING_POINTER (id
), "local-dynamic"))
7109 kind
= optimize
? TLS_MODEL_LOCAL_DYNAMIC
: TLS_MODEL_GLOBAL_DYNAMIC
;
7110 else if (!strcmp (TREE_STRING_POINTER (id
), "global-dynamic"))
7111 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
7113 error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
7115 DECL_TLS_MODEL (decl
) = kind
;
7119 /* Handle a "no_instrument_function" attribute; arguments as in
7120 struct attribute_spec.handler. */
7123 handle_no_instrument_function_attribute (tree
*node
, tree name
,
7124 tree
ARG_UNUSED (args
),
7125 int ARG_UNUSED (flags
),
7130 if (TREE_CODE (decl
) != FUNCTION_DECL
)
7132 error_at (DECL_SOURCE_LOCATION (decl
),
7133 "%qE attribute applies only to functions", name
);
7134 *no_add_attrs
= true;
7136 else if (DECL_INITIAL (decl
))
7138 error_at (DECL_SOURCE_LOCATION (decl
),
7139 "can%'t set %qE attribute after definition", name
);
7140 *no_add_attrs
= true;
7143 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
7148 /* Handle a "malloc" attribute; arguments as in
7149 struct attribute_spec.handler. */
7152 handle_malloc_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7153 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7155 if (TREE_CODE (*node
) == FUNCTION_DECL
7156 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node
))))
7157 DECL_IS_MALLOC (*node
) = 1;
7160 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7161 *no_add_attrs
= true;
7167 /* Handle a "alloc_size" attribute; arguments as in
7168 struct attribute_spec.handler. */
7171 handle_alloc_size_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
7172 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7174 unsigned arg_count
= type_num_arguments (*node
);
7175 for (; args
; args
= TREE_CHAIN (args
))
7177 tree position
= TREE_VALUE (args
);
7179 if (TREE_CODE (position
) != INTEGER_CST
7180 || TREE_INT_CST_HIGH (position
)
7181 || TREE_INT_CST_LOW (position
) < 1
7182 || TREE_INT_CST_LOW (position
) > arg_count
)
7184 warning (OPT_Wattributes
,
7185 "alloc_size parameter outside range");
7186 *no_add_attrs
= true;
7193 /* Handle a "fn spec" attribute; arguments as in
7194 struct attribute_spec.handler. */
7197 handle_fnspec_attribute (tree
*node ATTRIBUTE_UNUSED
, tree
ARG_UNUSED (name
),
7198 tree args
, int ARG_UNUSED (flags
),
7199 bool *no_add_attrs ATTRIBUTE_UNUSED
)
7202 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
7203 && !TREE_CHAIN (args
));
7207 /* Handle a "returns_twice" attribute; arguments as in
7208 struct attribute_spec.handler. */
7211 handle_returns_twice_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7212 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7214 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7215 DECL_IS_RETURNS_TWICE (*node
) = 1;
7218 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7219 *no_add_attrs
= true;
7225 /* Handle a "no_limit_stack" attribute; arguments as in
7226 struct attribute_spec.handler. */
7229 handle_no_limit_stack_attribute (tree
*node
, tree name
,
7230 tree
ARG_UNUSED (args
),
7231 int ARG_UNUSED (flags
),
7236 if (TREE_CODE (decl
) != FUNCTION_DECL
)
7238 error_at (DECL_SOURCE_LOCATION (decl
),
7239 "%qE attribute applies only to functions", name
);
7240 *no_add_attrs
= true;
7242 else if (DECL_INITIAL (decl
))
7244 error_at (DECL_SOURCE_LOCATION (decl
),
7245 "can%'t set %qE attribute after definition", name
);
7246 *no_add_attrs
= true;
7249 DECL_NO_LIMIT_STACK (decl
) = 1;
7254 /* Handle a "pure" attribute; arguments as in
7255 struct attribute_spec.handler. */
7258 handle_pure_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7259 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7261 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7262 DECL_PURE_P (*node
) = 1;
7263 /* ??? TODO: Support types. */
7266 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7267 *no_add_attrs
= true;
7273 /* Handle a "no vops" attribute; arguments as in
7274 struct attribute_spec.handler. */
7277 handle_novops_attribute (tree
*node
, tree
ARG_UNUSED (name
),
7278 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
7279 bool *ARG_UNUSED (no_add_attrs
))
7281 gcc_assert (TREE_CODE (*node
) == FUNCTION_DECL
);
7282 DECL_IS_NOVOPS (*node
) = 1;
7286 /* Handle a "deprecated" attribute; arguments as in
7287 struct attribute_spec.handler. */
7290 handle_deprecated_attribute (tree
*node
, tree name
,
7291 tree args
, int flags
,
7294 tree type
= NULL_TREE
;
7296 tree what
= NULL_TREE
;
7299 *no_add_attrs
= true;
7300 else if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
7302 error ("deprecated message is not a string");
7303 *no_add_attrs
= true;
7309 type
= TREE_TYPE (decl
);
7311 if (TREE_CODE (decl
) == TYPE_DECL
7312 || TREE_CODE (decl
) == PARM_DECL
7313 || TREE_CODE (decl
) == VAR_DECL
7314 || TREE_CODE (decl
) == FUNCTION_DECL
7315 || TREE_CODE (decl
) == FIELD_DECL
)
7316 TREE_DEPRECATED (decl
) = 1;
7320 else if (TYPE_P (*node
))
7322 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
7323 *node
= build_variant_type_copy (*node
);
7324 TREE_DEPRECATED (*node
) = 1;
7332 *no_add_attrs
= true;
7333 if (type
&& TYPE_NAME (type
))
7335 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
7336 what
= TYPE_NAME (*node
);
7337 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
7338 && DECL_NAME (TYPE_NAME (type
)))
7339 what
= DECL_NAME (TYPE_NAME (type
));
7342 warning (OPT_Wattributes
, "%qE attribute ignored for %qE", name
, what
);
7344 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7350 /* Handle a "vector_size" attribute; arguments as in
7351 struct attribute_spec.handler. */
7354 handle_vector_size_attribute (tree
*node
, tree name
, tree args
,
7355 int ARG_UNUSED (flags
),
7358 unsigned HOST_WIDE_INT vecsize
, nunits
;
7359 enum machine_mode orig_mode
;
7360 tree type
= *node
, new_type
, size
;
7362 *no_add_attrs
= true;
7364 size
= TREE_VALUE (args
);
7366 if (!host_integerp (size
, 1))
7368 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7372 /* Get the vector size (in bytes). */
7373 vecsize
= tree_low_cst (size
, 1);
7375 /* We need to provide for vector pointers, vector arrays, and
7376 functions returning vectors. For example:
7378 __attribute__((vector_size(16))) short *foo;
7380 In this case, the mode is SI, but the type being modified is
7381 HI, so we need to look further. */
7383 while (POINTER_TYPE_P (type
)
7384 || TREE_CODE (type
) == FUNCTION_TYPE
7385 || TREE_CODE (type
) == METHOD_TYPE
7386 || TREE_CODE (type
) == ARRAY_TYPE
7387 || TREE_CODE (type
) == OFFSET_TYPE
)
7388 type
= TREE_TYPE (type
);
7390 /* Get the mode of the type being modified. */
7391 orig_mode
= TYPE_MODE (type
);
7393 if ((!INTEGRAL_TYPE_P (type
)
7394 && !SCALAR_FLOAT_TYPE_P (type
)
7395 && !FIXED_POINT_TYPE_P (type
))
7396 || (!SCALAR_FLOAT_MODE_P (orig_mode
)
7397 && GET_MODE_CLASS (orig_mode
) != MODE_INT
7398 && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode
))
7399 || !host_integerp (TYPE_SIZE_UNIT (type
), 1)
7400 || TREE_CODE (type
) == BOOLEAN_TYPE
)
7402 error ("invalid vector type for attribute %qE", name
);
7406 if (vecsize
% tree_low_cst (TYPE_SIZE_UNIT (type
), 1))
7408 error ("vector size not an integral multiple of component size");
7414 error ("zero vector size");
7418 /* Calculate how many units fit in the vector. */
7419 nunits
= vecsize
/ tree_low_cst (TYPE_SIZE_UNIT (type
), 1);
7420 if (nunits
& (nunits
- 1))
7422 error ("number of components of the vector not a power of two");
7426 new_type
= build_vector_type (type
, nunits
);
7428 /* Build back pointers if needed. */
7429 *node
= lang_hooks
.types
.reconstruct_complex_type (*node
, new_type
);
7434 /* Handle the "nonnull" attribute. */
7436 handle_nonnull_attribute (tree
*node
, tree
ARG_UNUSED (name
),
7437 tree args
, int ARG_UNUSED (flags
),
7441 unsigned HOST_WIDE_INT attr_arg_num
;
7443 /* If no arguments are specified, all pointer arguments should be
7444 non-null. Verify a full prototype is given so that the arguments
7445 will have the correct types when we actually check them later. */
7448 if (!TYPE_ARG_TYPES (type
))
7450 error ("nonnull attribute without arguments on a non-prototype");
7451 *no_add_attrs
= true;
7456 /* Argument list specified. Verify that each argument number references
7457 a pointer argument. */
7458 for (attr_arg_num
= 1; args
; args
= TREE_CHAIN (args
))
7461 unsigned HOST_WIDE_INT arg_num
= 0, ck_num
;
7463 if (!get_nonnull_operand (TREE_VALUE (args
), &arg_num
))
7465 error ("nonnull argument has invalid operand number (argument %lu)",
7466 (unsigned long) attr_arg_num
);
7467 *no_add_attrs
= true;
7471 argument
= TYPE_ARG_TYPES (type
);
7474 for (ck_num
= 1; ; ck_num
++)
7476 if (!argument
|| ck_num
== arg_num
)
7478 argument
= TREE_CHAIN (argument
);
7482 || TREE_CODE (TREE_VALUE (argument
)) == VOID_TYPE
)
7484 error ("nonnull argument with out-of-range operand number (argument %lu, operand %lu)",
7485 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
7486 *no_add_attrs
= true;
7490 if (TREE_CODE (TREE_VALUE (argument
)) != POINTER_TYPE
)
7492 error ("nonnull argument references non-pointer operand (argument %lu, operand %lu)",
7493 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
7494 *no_add_attrs
= true;
7503 /* Check the argument list of a function call for null in argument slots
7504 that are marked as requiring a non-null pointer argument. The NARGS
7505 arguments are passed in the array ARGARRAY.
7509 check_function_nonnull (tree attrs
, int nargs
, tree
*argarray
)
7514 for (a
= attrs
; a
; a
= TREE_CHAIN (a
))
7516 if (is_attribute_p ("nonnull", TREE_PURPOSE (a
)))
7518 args
= TREE_VALUE (a
);
7520 /* Walk the argument list. If we encounter an argument number we
7521 should check for non-null, do it. If the attribute has no args,
7522 then every pointer argument is checked (in which case the check
7523 for pointer type is done in check_nonnull_arg). */
7524 for (i
= 0; i
< nargs
; i
++)
7526 if (!args
|| nonnull_check_p (args
, i
+ 1))
7527 check_function_arguments_recurse (check_nonnull_arg
, NULL
,
7535 /* Check that the Nth argument of a function call (counting backwards
7536 from the end) is a (pointer)0. The NARGS arguments are passed in the
7540 check_function_sentinel (tree attrs
, int nargs
, tree
*argarray
, tree typelist
)
7542 tree attr
= lookup_attribute ("sentinel", attrs
);
7550 /* Skip over the named arguments. */
7551 while (typelist
&& len
< nargs
)
7553 typelist
= TREE_CHAIN (typelist
);
7557 if (TREE_VALUE (attr
))
7559 tree p
= TREE_VALUE (TREE_VALUE (attr
));
7560 pos
= TREE_INT_CST_LOW (p
);
7563 /* The sentinel must be one of the varargs, i.e.
7564 in position >= the number of fixed arguments. */
7565 if ((nargs
- 1 - pos
) < len
)
7567 warning (OPT_Wformat
,
7568 "not enough variable arguments to fit a sentinel");
7572 /* Validate the sentinel. */
7573 sentinel
= argarray
[nargs
- 1 - pos
];
7574 if ((!POINTER_TYPE_P (TREE_TYPE (sentinel
))
7575 || !integer_zerop (sentinel
))
7576 /* Although __null (in C++) is only an integer we allow it
7577 nevertheless, as we are guaranteed that it's exactly
7578 as wide as a pointer, and we don't want to force
7579 users to cast the NULL they have written there.
7580 We warn with -Wstrict-null-sentinel, though. */
7581 && (warn_strict_null_sentinel
|| null_node
!= sentinel
))
7582 warning (OPT_Wformat
, "missing sentinel in function call");
7586 /* Helper for check_function_nonnull; given a list of operands which
7587 must be non-null in ARGS, determine if operand PARAM_NUM should be
7591 nonnull_check_p (tree args
, unsigned HOST_WIDE_INT param_num
)
7593 unsigned HOST_WIDE_INT arg_num
= 0;
7595 for (; args
; args
= TREE_CHAIN (args
))
7597 bool found
= get_nonnull_operand (TREE_VALUE (args
), &arg_num
);
7601 if (arg_num
== param_num
)
7607 /* Check that the function argument PARAM (which is operand number
7608 PARAM_NUM) is non-null. This is called by check_function_nonnull
7609 via check_function_arguments_recurse. */
7612 check_nonnull_arg (void * ARG_UNUSED (ctx
), tree param
,
7613 unsigned HOST_WIDE_INT param_num
)
7615 /* Just skip checking the argument if it's not a pointer. This can
7616 happen if the "nonnull" attribute was given without an operand
7617 list (which means to check every pointer argument). */
7619 if (TREE_CODE (TREE_TYPE (param
)) != POINTER_TYPE
)
7622 if (integer_zerop (param
))
7623 warning (OPT_Wnonnull
, "null argument where non-null required "
7624 "(argument %lu)", (unsigned long) param_num
);
7627 /* Helper for nonnull attribute handling; fetch the operand number
7628 from the attribute argument list. */
7631 get_nonnull_operand (tree arg_num_expr
, unsigned HOST_WIDE_INT
*valp
)
7633 /* Verify the arg number is a constant. */
7634 if (TREE_CODE (arg_num_expr
) != INTEGER_CST
7635 || TREE_INT_CST_HIGH (arg_num_expr
) != 0)
7638 *valp
= TREE_INT_CST_LOW (arg_num_expr
);
7642 /* Handle a "nothrow" attribute; arguments as in
7643 struct attribute_spec.handler. */
7646 handle_nothrow_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
7647 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7649 if (TREE_CODE (*node
) == FUNCTION_DECL
)
7650 TREE_NOTHROW (*node
) = 1;
7651 /* ??? TODO: Support types. */
7654 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7655 *no_add_attrs
= true;
7661 /* Handle a "cleanup" attribute; arguments as in
7662 struct attribute_spec.handler. */
7665 handle_cleanup_attribute (tree
*node
, tree name
, tree args
,
7666 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7669 tree cleanup_id
, cleanup_decl
;
7671 /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
7672 for global destructors in C++. This requires infrastructure that
7673 we don't have generically at the moment. It's also not a feature
7674 we'd be missing too much, since we do have attribute constructor. */
7675 if (TREE_CODE (decl
) != VAR_DECL
|| TREE_STATIC (decl
))
7677 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7678 *no_add_attrs
= true;
7682 /* Verify that the argument is a function in scope. */
7683 /* ??? We could support pointers to functions here as well, if
7684 that was considered desirable. */
7685 cleanup_id
= TREE_VALUE (args
);
7686 if (TREE_CODE (cleanup_id
) != IDENTIFIER_NODE
)
7688 error ("cleanup argument not an identifier");
7689 *no_add_attrs
= true;
7692 cleanup_decl
= lookup_name (cleanup_id
);
7693 if (!cleanup_decl
|| TREE_CODE (cleanup_decl
) != FUNCTION_DECL
)
7695 error ("cleanup argument not a function");
7696 *no_add_attrs
= true;
7700 /* That the function has proper type is checked with the
7701 eventual call to build_function_call. */
7706 /* Handle a "warn_unused_result" attribute. No special handling. */
7709 handle_warn_unused_result_attribute (tree
*node
, tree name
,
7710 tree
ARG_UNUSED (args
),
7711 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7713 /* Ignore the attribute for functions not returning any value. */
7714 if (VOID_TYPE_P (TREE_TYPE (*node
)))
7716 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7717 *no_add_attrs
= true;
7723 /* Handle a "sentinel" attribute. */
7726 handle_sentinel_attribute (tree
*node
, tree name
, tree args
,
7727 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7729 tree params
= TYPE_ARG_TYPES (*node
);
7733 warning (OPT_Wattributes
,
7734 "%qE attribute requires prototypes with named arguments", name
);
7735 *no_add_attrs
= true;
7739 while (TREE_CHAIN (params
))
7740 params
= TREE_CHAIN (params
);
7742 if (VOID_TYPE_P (TREE_VALUE (params
)))
7744 warning (OPT_Wattributes
,
7745 "%qE attribute only applies to variadic functions", name
);
7746 *no_add_attrs
= true;
7752 tree position
= TREE_VALUE (args
);
7754 if (TREE_CODE (position
) != INTEGER_CST
)
7756 warning (OPT_Wattributes
,
7757 "requested position is not an integer constant");
7758 *no_add_attrs
= true;
7762 if (tree_int_cst_lt (position
, integer_zero_node
))
7764 warning (OPT_Wattributes
,
7765 "requested position is less than zero");
7766 *no_add_attrs
= true;
7774 /* Handle a "type_generic" attribute. */
7777 handle_type_generic_attribute (tree
*node
, tree
ARG_UNUSED (name
),
7778 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
7779 bool * ARG_UNUSED (no_add_attrs
))
7783 /* Ensure we have a function type. */
7784 gcc_assert (TREE_CODE (*node
) == FUNCTION_TYPE
);
7786 params
= TYPE_ARG_TYPES (*node
);
7787 while (params
&& ! VOID_TYPE_P (TREE_VALUE (params
)))
7788 params
= TREE_CHAIN (params
);
7790 /* Ensure we have a variadic function. */
7791 gcc_assert (!params
);
7796 /* Handle a "target" attribute. */
7799 handle_target_attribute (tree
*node
, tree name
, tree args
, int flags
,
7802 /* Ensure we have a function type. */
7803 if (TREE_CODE (*node
) != FUNCTION_DECL
)
7805 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7806 *no_add_attrs
= true;
7808 else if (! targetm
.target_option
.valid_attribute_p (*node
, name
, args
,
7810 *no_add_attrs
= true;
7815 /* Arguments being collected for optimization. */
7816 typedef const char *const_char_p
; /* For DEF_VEC_P. */
7817 DEF_VEC_P(const_char_p
);
7818 DEF_VEC_ALLOC_P(const_char_p
, gc
);
7819 static GTY(()) VEC(const_char_p
, gc
) *optimize_args
;
7822 /* Inner function to convert a TREE_LIST to argv string to parse the optimize
7823 options in ARGS. ATTR_P is true if this is for attribute(optimize), and
7824 false for #pragma GCC optimize. */
7827 parse_optimize_options (tree args
, bool attr_p
)
7832 int saved_flag_strict_aliasing
;
7833 const char **opt_argv
;
7836 /* Build up argv vector. Just in case the string is stored away, use garbage
7837 collected strings. */
7838 VEC_truncate (const_char_p
, optimize_args
, 0);
7839 VEC_safe_push (const_char_p
, gc
, optimize_args
, NULL
);
7841 for (ap
= args
; ap
!= NULL_TREE
; ap
= TREE_CHAIN (ap
))
7843 tree value
= TREE_VALUE (ap
);
7845 if (TREE_CODE (value
) == INTEGER_CST
)
7848 sprintf (buffer
, "-O%ld", (long) TREE_INT_CST_LOW (value
));
7849 VEC_safe_push (const_char_p
, gc
, optimize_args
, ggc_strdup (buffer
));
7852 else if (TREE_CODE (value
) == STRING_CST
)
7854 /* Split string into multiple substrings. */
7855 size_t len
= TREE_STRING_LENGTH (value
);
7856 char *p
= ASTRDUP (TREE_STRING_POINTER (value
));
7857 char *end
= p
+ len
;
7861 while (next_p
!= NULL
)
7867 comma
= strchr (p
, ',');
7880 r
= q
= (char *) ggc_alloc (len2
+ 3);
7882 /* If the user supplied -Oxxx or -fxxx, only allow -Oxxx or -fxxx
7884 if (*p
== '-' && p
[1] != 'O' && p
[1] != 'f')
7888 warning (OPT_Wattributes
,
7889 "Bad option %s to optimize attribute.", p
);
7891 warning (OPT_Wpragmas
,
7892 "Bad option %s to pragma attribute", p
);
7900 /* Assume that Ox is -Ox, a numeric value is -Ox, a s by
7901 itself is -Os, and any other switch begins with a -f. */
7902 if ((*p
>= '0' && *p
<= '9')
7903 || (p
[0] == 's' && p
[1] == '\0'))
7909 memcpy (r
, p
, len2
);
7911 VEC_safe_push (const_char_p
, gc
, optimize_args
, q
);
7917 opt_argc
= VEC_length (const_char_p
, optimize_args
);
7918 opt_argv
= (const char **) alloca (sizeof (char *) * (opt_argc
+ 1));
7920 for (i
= 1; i
< opt_argc
; i
++)
7921 opt_argv
[i
] = VEC_index (const_char_p
, optimize_args
, i
);
7923 saved_flag_strict_aliasing
= flag_strict_aliasing
;
7925 /* Now parse the options. */
7926 decode_options (opt_argc
, opt_argv
);
7928 targetm
.override_options_after_change();
7930 /* Don't allow changing -fstrict-aliasing. */
7931 flag_strict_aliasing
= saved_flag_strict_aliasing
;
7933 VEC_truncate (const_char_p
, optimize_args
, 0);
7937 /* For handling "optimize" attribute. arguments as in
7938 struct attribute_spec.handler. */
7941 handle_optimize_attribute (tree
*node
, tree name
, tree args
,
7942 int ARG_UNUSED (flags
), bool *no_add_attrs
)
7944 /* Ensure we have a function type. */
7945 if (TREE_CODE (*node
) != FUNCTION_DECL
)
7947 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
7948 *no_add_attrs
= true;
7952 struct cl_optimization cur_opts
;
7953 tree old_opts
= DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
);
7955 /* Save current options. */
7956 cl_optimization_save (&cur_opts
);
7958 /* If we previously had some optimization options, use them as the
7961 cl_optimization_restore (TREE_OPTIMIZATION (old_opts
));
7963 /* Parse options, and update the vector. */
7964 parse_optimize_options (args
, true);
7965 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
)
7966 = build_optimization_node ();
7968 /* Restore current options. */
7969 cl_optimization_restore (&cur_opts
);
7975 /* Check for valid arguments being passed to a function.
7976 ATTRS is a list of attributes. There are NARGS arguments in the array
7977 ARGARRAY. TYPELIST is the list of argument types for the function.
7980 check_function_arguments (tree attrs
, int nargs
, tree
*argarray
, tree typelist
)
7982 /* Check for null being passed in a pointer argument that must be
7983 non-null. We also need to do this if format checking is enabled. */
7986 check_function_nonnull (attrs
, nargs
, argarray
);
7988 /* Check for errors in format strings. */
7990 if (warn_format
|| warn_missing_format_attribute
)
7991 check_function_format (attrs
, nargs
, argarray
);
7994 check_function_sentinel (attrs
, nargs
, argarray
, typelist
);
7997 /* Generic argument checking recursion routine. PARAM is the argument to
7998 be checked. PARAM_NUM is the number of the argument. CALLBACK is invoked
7999 once the argument is resolved. CTX is context for the callback. */
8001 check_function_arguments_recurse (void (*callback
)
8002 (void *, tree
, unsigned HOST_WIDE_INT
),
8003 void *ctx
, tree param
,
8004 unsigned HOST_WIDE_INT param_num
)
8006 if (CONVERT_EXPR_P (param
)
8007 && (TYPE_PRECISION (TREE_TYPE (param
))
8008 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (param
, 0)))))
8010 /* Strip coercion. */
8011 check_function_arguments_recurse (callback
, ctx
,
8012 TREE_OPERAND (param
, 0), param_num
);
8016 if (TREE_CODE (param
) == CALL_EXPR
)
8018 tree type
= TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (param
)));
8020 bool found_format_arg
= false;
8022 /* See if this is a call to a known internationalization function
8023 that modifies a format arg. Such a function may have multiple
8024 format_arg attributes (for example, ngettext). */
8026 for (attrs
= TYPE_ATTRIBUTES (type
);
8028 attrs
= TREE_CHAIN (attrs
))
8029 if (is_attribute_p ("format_arg", TREE_PURPOSE (attrs
)))
8032 tree format_num_expr
;
8035 call_expr_arg_iterator iter
;
8037 /* Extract the argument number, which was previously checked
8039 format_num_expr
= TREE_VALUE (TREE_VALUE (attrs
));
8041 gcc_assert (TREE_CODE (format_num_expr
) == INTEGER_CST
8042 && !TREE_INT_CST_HIGH (format_num_expr
));
8044 format_num
= TREE_INT_CST_LOW (format_num_expr
);
8046 for (inner_arg
= first_call_expr_arg (param
, &iter
), i
= 1;
8048 inner_arg
= next_call_expr_arg (&iter
), i
++)
8049 if (i
== format_num
)
8051 check_function_arguments_recurse (callback
, ctx
,
8052 inner_arg
, param_num
);
8053 found_format_arg
= true;
8058 /* If we found a format_arg attribute and did a recursive check,
8059 we are done with checking this argument. Otherwise, we continue
8060 and this will be considered a non-literal. */
8061 if (found_format_arg
)
8065 if (TREE_CODE (param
) == COND_EXPR
)
8067 /* Check both halves of the conditional expression. */
8068 check_function_arguments_recurse (callback
, ctx
,
8069 TREE_OPERAND (param
, 1), param_num
);
8070 check_function_arguments_recurse (callback
, ctx
,
8071 TREE_OPERAND (param
, 2), param_num
);
8075 (*callback
) (ctx
, param
, param_num
);
8078 /* Checks for a builtin function FNDECL that the number of arguments
8079 NARGS against the required number REQUIRED and issues an error if
8080 there is a mismatch. Returns true if the number of arguments is
8081 correct, otherwise false. */
8084 builtin_function_validate_nargs (tree fndecl
, int nargs
, int required
)
8086 if (nargs
< required
)
8088 error_at (input_location
,
8089 "not enough arguments to function %qE", fndecl
);
8092 else if (nargs
> required
)
8094 error_at (input_location
,
8095 "too many arguments to function %qE", fndecl
);
8101 /* Verifies the NARGS arguments ARGS to the builtin function FNDECL.
8102 Returns false if there was an error, otherwise true. */
8105 check_builtin_function_arguments (tree fndecl
, int nargs
, tree
*args
)
8107 if (!DECL_BUILT_IN (fndecl
)
8108 || DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_NORMAL
)
8111 switch (DECL_FUNCTION_CODE (fndecl
))
8113 case BUILT_IN_CONSTANT_P
:
8114 return builtin_function_validate_nargs (fndecl
, nargs
, 1);
8116 case BUILT_IN_ISFINITE
:
8117 case BUILT_IN_ISINF
:
8118 case BUILT_IN_ISINF_SIGN
:
8119 case BUILT_IN_ISNAN
:
8120 case BUILT_IN_ISNORMAL
:
8121 if (builtin_function_validate_nargs (fndecl
, nargs
, 1))
8123 if (TREE_CODE (TREE_TYPE (args
[0])) != REAL_TYPE
)
8125 error ("non-floating-point argument in call to "
8126 "function %qE", fndecl
);
8133 case BUILT_IN_ISGREATER
:
8134 case BUILT_IN_ISGREATEREQUAL
:
8135 case BUILT_IN_ISLESS
:
8136 case BUILT_IN_ISLESSEQUAL
:
8137 case BUILT_IN_ISLESSGREATER
:
8138 case BUILT_IN_ISUNORDERED
:
8139 if (builtin_function_validate_nargs (fndecl
, nargs
, 2))
8141 enum tree_code code0
, code1
;
8142 code0
= TREE_CODE (TREE_TYPE (args
[0]));
8143 code1
= TREE_CODE (TREE_TYPE (args
[1]));
8144 if (!((code0
== REAL_TYPE
&& code1
== REAL_TYPE
)
8145 || (code0
== REAL_TYPE
&& code1
== INTEGER_TYPE
)
8146 || (code0
== INTEGER_TYPE
&& code1
== REAL_TYPE
)))
8148 error ("non-floating-point arguments in call to "
8149 "function %qE", fndecl
);
8156 case BUILT_IN_FPCLASSIFY
:
8157 if (builtin_function_validate_nargs (fndecl
, nargs
, 6))
8162 if (TREE_CODE (args
[i
]) != INTEGER_CST
)
8164 error ("non-const integer argument %u in call to function %qE",
8169 if (TREE_CODE (TREE_TYPE (args
[5])) != REAL_TYPE
)
8171 error ("non-floating-point argument in call to function %qE",
8184 /* Function to help qsort sort FIELD_DECLs by name order. */
8187 field_decl_cmp (const void *x_p
, const void *y_p
)
8189 const tree
*const x
= (const tree
*const) x_p
;
8190 const tree
*const y
= (const tree
*const) y_p
;
8192 if (DECL_NAME (*x
) == DECL_NAME (*y
))
8193 /* A nontype is "greater" than a type. */
8194 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
8195 if (DECL_NAME (*x
) == NULL_TREE
)
8197 if (DECL_NAME (*y
) == NULL_TREE
)
8199 if (DECL_NAME (*x
) < DECL_NAME (*y
))
8205 gt_pointer_operator new_value
;
8209 /* This routine compares two fields like field_decl_cmp but using the
8210 pointer operator in resort_data. */
8213 resort_field_decl_cmp (const void *x_p
, const void *y_p
)
8215 const tree
*const x
= (const tree
*const) x_p
;
8216 const tree
*const y
= (const tree
*const) y_p
;
8218 if (DECL_NAME (*x
) == DECL_NAME (*y
))
8219 /* A nontype is "greater" than a type. */
8220 return (TREE_CODE (*y
) == TYPE_DECL
) - (TREE_CODE (*x
) == TYPE_DECL
);
8221 if (DECL_NAME (*x
) == NULL_TREE
)
8223 if (DECL_NAME (*y
) == NULL_TREE
)
8226 tree d1
= DECL_NAME (*x
);
8227 tree d2
= DECL_NAME (*y
);
8228 resort_data
.new_value (&d1
, resort_data
.cookie
);
8229 resort_data
.new_value (&d2
, resort_data
.cookie
);
8236 /* Resort DECL_SORTED_FIELDS because pointers have been reordered. */
8239 resort_sorted_fields (void *obj
,
8240 void * ARG_UNUSED (orig_obj
),
8241 gt_pointer_operator new_value
,
8244 struct sorted_fields_type
*sf
= (struct sorted_fields_type
*) obj
;
8245 resort_data
.new_value
= new_value
;
8246 resort_data
.cookie
= cookie
;
8247 qsort (&sf
->elts
[0], sf
->len
, sizeof (tree
),
8248 resort_field_decl_cmp
);
8251 /* Subroutine of c_parse_error.
8252 Return the result of concatenating LHS and RHS. RHS is really
8253 a string literal, its first character is indicated by RHS_START and
8254 RHS_SIZE is its length (including the terminating NUL character).
8256 The caller is responsible for deleting the returned pointer. */
8259 catenate_strings (const char *lhs
, const char *rhs_start
, int rhs_size
)
8261 const int lhs_size
= strlen (lhs
);
8262 char *result
= XNEWVEC (char, lhs_size
+ rhs_size
);
8263 strncpy (result
, lhs
, lhs_size
);
8264 strncpy (result
+ lhs_size
, rhs_start
, rhs_size
);
8268 /* Issue the error given by GMSGID, indicating that it occurred before
8269 TOKEN, which had the associated VALUE. */
8272 c_parse_error (const char *gmsgid
, enum cpp_ttype token_type
,
8273 tree value
, unsigned char token_flags
)
8275 #define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2))
8277 char *message
= NULL
;
8279 if (token_type
== CPP_EOF
)
8280 message
= catenate_messages (gmsgid
, " at end of input");
8281 else if (token_type
== CPP_CHAR
8282 || token_type
== CPP_WCHAR
8283 || token_type
== CPP_CHAR16
8284 || token_type
== CPP_CHAR32
)
8286 unsigned int val
= TREE_INT_CST_LOW (value
);
8305 if (val
<= UCHAR_MAX
&& ISGRAPH (val
))
8306 message
= catenate_messages (gmsgid
, " before %s'%c'");
8308 message
= catenate_messages (gmsgid
, " before %s'\\x%x'");
8310 error (message
, prefix
, val
);
8314 else if (token_type
== CPP_STRING
8315 || token_type
== CPP_WSTRING
8316 || token_type
== CPP_STRING16
8317 || token_type
== CPP_STRING32
8318 || token_type
== CPP_UTF8STRING
)
8319 message
= catenate_messages (gmsgid
, " before string constant");
8320 else if (token_type
== CPP_NUMBER
)
8321 message
= catenate_messages (gmsgid
, " before numeric constant");
8322 else if (token_type
== CPP_NAME
)
8324 message
= catenate_messages (gmsgid
, " before %qE");
8325 error (message
, value
);
8329 else if (token_type
== CPP_PRAGMA
)
8330 message
= catenate_messages (gmsgid
, " before %<#pragma%>");
8331 else if (token_type
== CPP_PRAGMA_EOL
)
8332 message
= catenate_messages (gmsgid
, " before end of line");
8333 else if (token_type
< N_TTYPES
)
8335 message
= catenate_messages (gmsgid
, " before %qs token");
8336 error (message
, cpp_type2name (token_type
, token_flags
));
8348 #undef catenate_messages
8351 /* Mapping for cpp message reasons to the options that enable them. */
8353 struct reason_option_codes_t
8355 const int reason
; /* cpplib message reason. */
8356 const int option_code
; /* gcc option that controls this message. */
8359 static const struct reason_option_codes_t option_codes
[] = {
8360 {CPP_W_DEPRECATED
, OPT_Wdeprecated
},
8361 {CPP_W_COMMENTS
, OPT_Wcomments
},
8362 {CPP_W_TRIGRAPHS
, OPT_Wtrigraphs
},
8363 {CPP_W_MULTICHAR
, OPT_Wmultichar
},
8364 {CPP_W_TRADITIONAL
, OPT_Wtraditional
},
8365 {CPP_W_LONG_LONG
, OPT_Wlong_long
},
8366 {CPP_W_ENDIF_LABELS
, OPT_Wendif_labels
},
8367 {CPP_W_VARIADIC_MACROS
, OPT_Wvariadic_macros
},
8368 {CPP_W_BUILTIN_MACRO_REDEFINED
, OPT_Wbuiltin_macro_redefined
},
8369 {CPP_W_UNDEF
, OPT_Wundef
},
8370 {CPP_W_UNUSED_MACROS
, OPT_Wunused_macros
},
8371 {CPP_W_CXX_OPERATOR_NAMES
, OPT_Wc___compat
},
8372 {CPP_W_NORMALIZE
, OPT_Wnormalized_
},
8373 {CPP_W_INVALID_PCH
, OPT_Winvalid_pch
},
8374 {CPP_W_WARNING_DIRECTIVE
, OPT_Wcpp
},
8378 /* Return the gcc option code associated with the reason for a cpp
8379 message, or 0 if none. */
8382 c_option_controlling_cpp_error (int reason
)
8384 const struct reason_option_codes_t
*entry
;
8386 for (entry
= option_codes
; entry
->reason
!= CPP_W_NONE
; entry
++)
8388 if (entry
->reason
== reason
)
8389 return entry
->option_code
;
8394 /* Callback from cpp_error for PFILE to print diagnostics from the
8395 preprocessor. The diagnostic is of type LEVEL, with REASON set
8396 to the reason code if LEVEL is represents a warning, at location
8397 LOCATION unless this is after lexing and the compiler's location
8398 should be used instead, with column number possibly overridden by
8399 COLUMN_OVERRIDE if not zero; MSG is the translated message and AP
8400 the arguments. Returns true if a diagnostic was emitted, false
8404 c_cpp_error (cpp_reader
*pfile ATTRIBUTE_UNUSED
, int level
, int reason
,
8405 location_t location
, unsigned int column_override
,
8406 const char *msg
, va_list *ap
)
8408 diagnostic_info diagnostic
;
8409 diagnostic_t dlevel
;
8410 bool save_warn_system_headers
= global_dc
->warn_system_headers
;
8415 case CPP_DL_WARNING_SYSHDR
:
8418 global_dc
->warn_system_headers
= 1;
8420 case CPP_DL_WARNING
:
8423 dlevel
= DK_WARNING
;
8425 case CPP_DL_PEDWARN
:
8426 if (flag_no_output
&& !flag_pedantic_errors
)
8428 dlevel
= DK_PEDWARN
;
8446 location
= input_location
;
8447 diagnostic_set_info_translated (&diagnostic
, msg
, ap
,
8449 if (column_override
)
8450 diagnostic_override_column (&diagnostic
, column_override
);
8451 diagnostic_override_option_index (&diagnostic
,
8452 c_option_controlling_cpp_error (reason
));
8453 ret
= report_diagnostic (&diagnostic
);
8454 if (level
== CPP_DL_WARNING_SYSHDR
)
8455 global_dc
->warn_system_headers
= save_warn_system_headers
;
8459 /* Convert a character from the host to the target execution character
8460 set. cpplib handles this, mostly. */
8463 c_common_to_target_charset (HOST_WIDE_INT c
)
8465 /* Character constants in GCC proper are sign-extended under -fsigned-char,
8466 zero-extended under -fno-signed-char. cpplib insists that characters
8467 and character constants are always unsigned. Hence we must convert
8469 cppchar_t uc
= ((cppchar_t
)c
) & ((((cppchar_t
)1) << CHAR_BIT
)-1);
8471 uc
= cpp_host_to_exec_charset (parse_in
, uc
);
8473 if (flag_signed_char
)
8474 return ((HOST_WIDE_INT
)uc
) << (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
)
8475 >> (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
);
8480 /* Build the result of __builtin_offsetof. EXPR is a nested sequence of
8481 component references, with STOP_REF, or alternatively an INDIRECT_REF of
8482 NULL, at the bottom; much like the traditional rendering of offsetof as a
8483 macro. Returns the folded and properly cast result. */
8486 fold_offsetof_1 (tree expr
, tree stop_ref
)
8488 enum tree_code code
= PLUS_EXPR
;
8491 if (expr
== stop_ref
&& TREE_CODE (expr
) != ERROR_MARK
)
8492 return size_zero_node
;
8494 switch (TREE_CODE (expr
))
8500 error ("cannot apply %<offsetof%> to static data member %qD", expr
);
8501 return error_mark_node
;
8505 error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded");
8506 return error_mark_node
;
8510 if (!integer_zerop (TREE_OPERAND (expr
, 0)))
8512 error ("cannot apply %<offsetof%> to a non constant address");
8513 return error_mark_node
;
8515 return size_zero_node
;
8518 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0), stop_ref
);
8519 if (base
== error_mark_node
)
8522 t
= TREE_OPERAND (expr
, 1);
8523 if (DECL_C_BIT_FIELD (t
))
8525 error ("attempt to take address of bit-field structure "
8527 return error_mark_node
;
8529 off
= size_binop_loc (input_location
, PLUS_EXPR
, DECL_FIELD_OFFSET (t
),
8530 size_int (tree_low_cst (DECL_FIELD_BIT_OFFSET (t
),
8536 base
= fold_offsetof_1 (TREE_OPERAND (expr
, 0), stop_ref
);
8537 if (base
== error_mark_node
)
8540 t
= TREE_OPERAND (expr
, 1);
8541 if (TREE_CODE (t
) == INTEGER_CST
&& tree_int_cst_sgn (t
) < 0)
8544 t
= fold_build1_loc (input_location
, NEGATE_EXPR
, TREE_TYPE (t
), t
);
8546 t
= convert (sizetype
, t
);
8547 off
= size_binop (MULT_EXPR
, TYPE_SIZE_UNIT (TREE_TYPE (expr
)), t
);
8549 /* Check if the offset goes beyond the upper bound of the array. */
8550 if (code
== PLUS_EXPR
&& TREE_CODE (t
) == INTEGER_CST
)
8552 tree upbound
= array_ref_up_bound (expr
);
8553 if (upbound
!= NULL_TREE
8554 && TREE_CODE (upbound
) == INTEGER_CST
8555 && !tree_int_cst_equal (upbound
,
8556 TYPE_MAX_VALUE (TREE_TYPE (upbound
))))
8558 upbound
= size_binop (PLUS_EXPR
, upbound
,
8559 build_int_cst (TREE_TYPE (upbound
), 1));
8560 if (tree_int_cst_lt (upbound
, t
))
8564 for (v
= TREE_OPERAND (expr
, 0);
8565 TREE_CODE (v
) == COMPONENT_REF
;
8566 v
= TREE_OPERAND (v
, 0))
8567 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v
, 0)))
8570 tree fld_chain
= TREE_CHAIN (TREE_OPERAND (v
, 1));
8571 for (; fld_chain
; fld_chain
= TREE_CHAIN (fld_chain
))
8572 if (TREE_CODE (fld_chain
) == FIELD_DECL
)
8578 /* Don't warn if the array might be considered a poor
8579 man's flexible array member with a very permissive
8580 definition thereof. */
8581 if (TREE_CODE (v
) == ARRAY_REF
8582 || TREE_CODE (v
) == COMPONENT_REF
)
8583 warning (OPT_Warray_bounds
,
8584 "index %E denotes an offset "
8585 "greater than size of %qT",
8586 t
, TREE_TYPE (TREE_OPERAND (expr
, 0)));
8593 /* Handle static members of volatile structs. */
8594 t
= TREE_OPERAND (expr
, 1);
8595 gcc_assert (TREE_CODE (t
) == VAR_DECL
);
8596 return fold_offsetof_1 (t
, stop_ref
);
8602 return size_binop (code
, base
, off
);
8606 fold_offsetof (tree expr
, tree stop_ref
)
8608 /* Convert back from the internal sizetype to size_t. */
8609 return convert (size_type_node
, fold_offsetof_1 (expr
, stop_ref
));
8612 /* Print an error message for an invalid lvalue. USE says
8613 how the lvalue is being used and so selects the error message. */
8616 lvalue_error (enum lvalue_use use
)
8621 error ("lvalue required as left operand of assignment");
8624 error ("lvalue required as increment operand");
8627 error ("lvalue required as decrement operand");
8630 error ("lvalue required as unary %<&%> operand");
8633 error ("lvalue required in asm statement");
8640 /* *PTYPE is an incomplete array. Complete it with a domain based on
8641 INITIAL_VALUE. If INITIAL_VALUE is not present, use 1 if DO_DEFAULT
8642 is true. Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
8643 2 if INITIAL_VALUE was NULL, and 3 if INITIAL_VALUE was empty. */
8646 complete_array_type (tree
*ptype
, tree initial_value
, bool do_default
)
8648 tree maxindex
, type
, main_type
, elt
, unqual_elt
;
8649 int failure
= 0, quals
;
8650 hashval_t hashcode
= 0;
8652 maxindex
= size_zero_node
;
8655 if (TREE_CODE (initial_value
) == STRING_CST
)
8658 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value
)));
8659 maxindex
= size_int (TREE_STRING_LENGTH (initial_value
)/eltsize
- 1);
8661 else if (TREE_CODE (initial_value
) == CONSTRUCTOR
)
8663 VEC(constructor_elt
,gc
) *v
= CONSTRUCTOR_ELTS (initial_value
);
8665 if (VEC_empty (constructor_elt
, v
))
8669 maxindex
= integer_minus_one_node
;
8674 unsigned HOST_WIDE_INT cnt
;
8675 constructor_elt
*ce
;
8676 bool fold_p
= false;
8678 if (VEC_index (constructor_elt
, v
, 0)->index
)
8679 maxindex
= fold_convert_loc (input_location
, sizetype
,
8680 VEC_index (constructor_elt
,
8682 curindex
= maxindex
;
8685 VEC_iterate (constructor_elt
, v
, cnt
, ce
);
8688 bool curfold_p
= false;
8690 curindex
= ce
->index
, curfold_p
= true;
8694 curindex
= fold_convert (sizetype
, curindex
);
8695 curindex
= size_binop (PLUS_EXPR
, curindex
,
8698 if (tree_int_cst_lt (maxindex
, curindex
))
8699 maxindex
= curindex
, fold_p
= curfold_p
;
8702 maxindex
= fold_convert (sizetype
, maxindex
);
8707 /* Make an error message unless that happened already. */
8708 if (initial_value
!= error_mark_node
)
8720 elt
= TREE_TYPE (type
);
8721 quals
= TYPE_QUALS (strip_array_types (elt
));
8725 unqual_elt
= c_build_qualified_type (elt
, KEEP_QUAL_ADDR_SPACE (quals
));
8727 /* Using build_distinct_type_copy and modifying things afterward instead
8728 of using build_array_type to create a new type preserves all of the
8729 TYPE_LANG_FLAG_? bits that the front end may have set. */
8730 main_type
= build_distinct_type_copy (TYPE_MAIN_VARIANT (type
));
8731 TREE_TYPE (main_type
) = unqual_elt
;
8732 TYPE_DOMAIN (main_type
) = build_index_type (maxindex
);
8733 layout_type (main_type
);
8735 /* Make sure we have the canonical MAIN_TYPE. */
8736 hashcode
= iterative_hash_object (TYPE_HASH (unqual_elt
), hashcode
);
8737 hashcode
= iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (main_type
)),
8739 main_type
= type_hash_canon (hashcode
, main_type
);
8741 /* Fix the canonical type. */
8742 if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type
))
8743 || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type
)))
8744 SET_TYPE_STRUCTURAL_EQUALITY (main_type
);
8745 else if (TYPE_CANONICAL (TREE_TYPE (main_type
)) != TREE_TYPE (main_type
)
8746 || (TYPE_CANONICAL (TYPE_DOMAIN (main_type
))
8747 != TYPE_DOMAIN (main_type
)))
8748 TYPE_CANONICAL (main_type
)
8749 = build_array_type (TYPE_CANONICAL (TREE_TYPE (main_type
)),
8750 TYPE_CANONICAL (TYPE_DOMAIN (main_type
)));
8752 TYPE_CANONICAL (main_type
) = main_type
;
8757 type
= c_build_qualified_type (main_type
, quals
);
8759 if (COMPLETE_TYPE_P (type
)
8760 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
8761 && TREE_OVERFLOW (TYPE_SIZE_UNIT (type
)))
8763 error ("size of array is too large");
8764 /* If we proceed with the array type as it is, we'll eventually
8765 crash in tree_low_cst(). */
8766 type
= error_mark_node
;
8774 /* Used to help initialize the builtin-types.def table. When a type of
8775 the correct size doesn't exist, use error_mark_node instead of NULL.
8776 The later results in segfaults even when a decl using the type doesn't
8780 builtin_type_for_size (int size
, bool unsignedp
)
8782 tree type
= lang_hooks
.types
.type_for_size (size
, unsignedp
);
8783 return type
? type
: error_mark_node
;
8786 /* A helper function for resolve_overloaded_builtin in resolving the
8787 overloaded __sync_ builtins. Returns a positive power of 2 if the
8788 first operand of PARAMS is a pointer to a supported data type.
8789 Returns 0 if an error is encountered. */
8792 sync_resolve_size (tree function
, VEC(tree
,gc
) *params
)
8797 if (VEC_empty (tree
, params
))
8799 error ("too few arguments to function %qE", function
);
8803 type
= TREE_TYPE (VEC_index (tree
, params
, 0));
8804 if (TREE_CODE (type
) != POINTER_TYPE
)
8807 type
= TREE_TYPE (type
);
8808 if (!INTEGRAL_TYPE_P (type
) && !POINTER_TYPE_P (type
))
8811 size
= tree_low_cst (TYPE_SIZE_UNIT (type
), 1);
8812 if (size
== 1 || size
== 2 || size
== 4 || size
== 8 || size
== 16)
8816 error ("incompatible type for argument %d of %qE", 1, function
);
8820 /* A helper function for resolve_overloaded_builtin. Adds casts to
8821 PARAMS to make arguments match up with those of FUNCTION. Drops
8822 the variadic arguments at the end. Returns false if some error
8823 was encountered; true on success. */
8826 sync_resolve_params (tree orig_function
, tree function
, VEC(tree
, gc
) *params
)
8828 tree arg_types
= TYPE_ARG_TYPES (TREE_TYPE (function
));
8830 unsigned int parmnum
;
8832 /* We've declared the implementation functions to use "volatile void *"
8833 as the pointer parameter, so we shouldn't get any complaints from the
8834 call to check_function_arguments what ever type the user used. */
8835 arg_types
= TREE_CHAIN (arg_types
);
8836 ptype
= TREE_TYPE (TREE_TYPE (VEC_index (tree
, params
, 0)));
8838 /* For the rest of the values, we need to cast these to FTYPE, so that we
8839 don't get warnings for passing pointer types, etc. */
8841 while (arg_types
!= void_list_node
)
8846 if (VEC_length (tree
, params
) <= parmnum
)
8848 error ("too few arguments to function %qE", orig_function
);
8852 /* ??? Ideally for the first conversion we'd use convert_for_assignment
8853 so that we get warnings for anything that doesn't match the pointer
8854 type. This isn't portable across the C and C++ front ends atm. */
8855 val
= VEC_index (tree
, params
, parmnum
);
8856 val
= convert (ptype
, val
);
8857 val
= convert (TREE_VALUE (arg_types
), val
);
8858 VEC_replace (tree
, params
, parmnum
, val
);
8860 arg_types
= TREE_CHAIN (arg_types
);
8863 /* The definition of these primitives is variadic, with the remaining
8864 being "an optional list of variables protected by the memory barrier".
8865 No clue what that's supposed to mean, precisely, but we consider all
8866 call-clobbered variables to be protected so we're safe. */
8867 VEC_truncate (tree
, params
, parmnum
+ 1);
8872 /* A helper function for resolve_overloaded_builtin. Adds a cast to
8873 RESULT to make it match the type of the first pointer argument in
8877 sync_resolve_return (tree first_param
, tree result
)
8879 tree ptype
= TREE_TYPE (TREE_TYPE (first_param
));
8880 ptype
= TYPE_MAIN_VARIANT (ptype
);
8881 return convert (ptype
, result
);
8884 /* Some builtin functions are placeholders for other expressions. This
8885 function should be called immediately after parsing the call expression
8886 before surrounding code has committed to the type of the expression.
8888 LOC is the location of the builtin call.
8890 FUNCTION is the DECL that has been invoked; it is known to be a builtin.
8891 PARAMS is the argument list for the call. The return value is non-null
8892 when expansion is complete, and null if normal processing should
8896 resolve_overloaded_builtin (location_t loc
, tree function
, VEC(tree
,gc
) *params
)
8898 enum built_in_function orig_code
= DECL_FUNCTION_CODE (function
);
8899 switch (DECL_BUILT_IN_CLASS (function
))
8901 case BUILT_IN_NORMAL
:
8904 if (targetm
.resolve_overloaded_builtin
)
8905 return targetm
.resolve_overloaded_builtin (loc
, function
, params
);
8912 /* Handle BUILT_IN_NORMAL here. */
8915 case BUILT_IN_FETCH_AND_ADD_N
:
8916 case BUILT_IN_FETCH_AND_SUB_N
:
8917 case BUILT_IN_FETCH_AND_OR_N
:
8918 case BUILT_IN_FETCH_AND_AND_N
:
8919 case BUILT_IN_FETCH_AND_XOR_N
:
8920 case BUILT_IN_FETCH_AND_NAND_N
:
8921 case BUILT_IN_ADD_AND_FETCH_N
:
8922 case BUILT_IN_SUB_AND_FETCH_N
:
8923 case BUILT_IN_OR_AND_FETCH_N
:
8924 case BUILT_IN_AND_AND_FETCH_N
:
8925 case BUILT_IN_XOR_AND_FETCH_N
:
8926 case BUILT_IN_NAND_AND_FETCH_N
:
8927 case BUILT_IN_BOOL_COMPARE_AND_SWAP_N
:
8928 case BUILT_IN_VAL_COMPARE_AND_SWAP_N
:
8929 case BUILT_IN_LOCK_TEST_AND_SET_N
:
8930 case BUILT_IN_LOCK_RELEASE_N
:
8932 int n
= sync_resolve_size (function
, params
);
8933 tree new_function
, first_param
, result
;
8936 return error_mark_node
;
8938 new_function
= built_in_decls
[orig_code
+ exact_log2 (n
) + 1];
8939 if (!sync_resolve_params (function
, new_function
, params
))
8940 return error_mark_node
;
8942 first_param
= VEC_index (tree
, params
, 0);
8943 result
= build_function_call_vec (loc
, new_function
, params
, NULL
);
8944 if (orig_code
!= BUILT_IN_BOOL_COMPARE_AND_SWAP_N
8945 && orig_code
!= BUILT_IN_LOCK_RELEASE_N
)
8946 result
= sync_resolve_return (first_param
, result
);
8956 /* Ignoring their sign, return true if two scalar types are the same. */
8958 same_scalar_type_ignoring_signedness (tree t1
, tree t2
)
8960 enum tree_code c1
= TREE_CODE (t1
), c2
= TREE_CODE (t2
);
8962 gcc_assert ((c1
== INTEGER_TYPE
|| c1
== REAL_TYPE
|| c1
== FIXED_POINT_TYPE
)
8963 && (c2
== INTEGER_TYPE
|| c2
== REAL_TYPE
8964 || c2
== FIXED_POINT_TYPE
));
8966 /* Equality works here because c_common_signed_type uses
8967 TYPE_MAIN_VARIANT. */
8968 return c_common_signed_type (t1
)
8969 == c_common_signed_type (t2
);
8972 /* Check for missing format attributes on function pointers. LTYPE is
8973 the new type or left-hand side type. RTYPE is the old type or
8974 right-hand side type. Returns TRUE if LTYPE is missing the desired
8978 check_missing_format_attribute (tree ltype
, tree rtype
)
8980 tree
const ttr
= TREE_TYPE (rtype
), ttl
= TREE_TYPE (ltype
);
8983 for (ra
= TYPE_ATTRIBUTES (ttr
); ra
; ra
= TREE_CHAIN (ra
))
8984 if (is_attribute_p ("format", TREE_PURPOSE (ra
)))
8989 for (la
= TYPE_ATTRIBUTES (ttl
); la
; la
= TREE_CHAIN (la
))
8990 if (is_attribute_p ("format", TREE_PURPOSE (la
)))
8998 /* Subscripting with type char is likely to lose on a machine where
8999 chars are signed. So warn on any machine, but optionally. Don't
9000 warn for unsigned char since that type is safe. Don't warn for
9001 signed char because anyone who uses that must have done so
9002 deliberately. Furthermore, we reduce the false positive load by
9003 warning only for non-constant value of type char. */
9006 warn_array_subscript_with_type_char (tree index
)
9008 if (TYPE_MAIN_VARIANT (TREE_TYPE (index
)) == char_type_node
9009 && TREE_CODE (index
) != INTEGER_CST
)
9010 warning (OPT_Wchar_subscripts
, "array subscript has type %<char%>");
9013 /* Implement -Wparentheses for the unexpected C precedence rules, to
9014 cover cases like x + y << z which readers are likely to
9015 misinterpret. We have seen an expression in which CODE is a binary
9016 operator used to combine expressions ARG_LEFT and ARG_RIGHT, which
9017 before folding had CODE_LEFT and CODE_RIGHT. CODE_LEFT and
9018 CODE_RIGHT may be ERROR_MARK, which means that that side of the
9019 expression was not formed using a binary or unary operator, or it
9020 was enclosed in parentheses. */
9023 warn_about_parentheses (enum tree_code code
,
9024 enum tree_code code_left
, tree arg_left
,
9025 enum tree_code code_right
, tree arg_right
)
9027 if (!warn_parentheses
)
9030 /* This macro tests that the expression ARG with original tree code
9031 CODE appears to be a boolean expression. or the result of folding a
9032 boolean expression. */
9033 #define APPEARS_TO_BE_BOOLEAN_EXPR_P(CODE, ARG) \
9034 (truth_value_p (TREE_CODE (ARG)) \
9035 || TREE_CODE (TREE_TYPE (ARG)) == BOOLEAN_TYPE \
9036 /* Folding may create 0 or 1 integers from other expressions. */ \
9037 || ((CODE) != INTEGER_CST \
9038 && (integer_onep (ARG) || integer_zerop (ARG))))
9043 if (code_left
== PLUS_EXPR
|| code_right
== PLUS_EXPR
)
9044 warning (OPT_Wparentheses
,
9045 "suggest parentheses around %<+%> inside %<<<%>");
9046 else if (code_left
== MINUS_EXPR
|| code_right
== MINUS_EXPR
)
9047 warning (OPT_Wparentheses
,
9048 "suggest parentheses around %<-%> inside %<<<%>");
9052 if (code_left
== PLUS_EXPR
|| code_right
== PLUS_EXPR
)
9053 warning (OPT_Wparentheses
,
9054 "suggest parentheses around %<+%> inside %<>>%>");
9055 else if (code_left
== MINUS_EXPR
|| code_right
== MINUS_EXPR
)
9056 warning (OPT_Wparentheses
,
9057 "suggest parentheses around %<-%> inside %<>>%>");
9060 case TRUTH_ORIF_EXPR
:
9061 if (code_left
== TRUTH_ANDIF_EXPR
|| code_right
== TRUTH_ANDIF_EXPR
)
9062 warning (OPT_Wparentheses
,
9063 "suggest parentheses around %<&&%> within %<||%>");
9067 if (code_left
== BIT_AND_EXPR
|| code_left
== BIT_XOR_EXPR
9068 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
9069 || code_right
== BIT_AND_EXPR
|| code_right
== BIT_XOR_EXPR
9070 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
9071 warning (OPT_Wparentheses
,
9072 "suggest parentheses around arithmetic in operand of %<|%>");
9073 /* Check cases like x|y==z */
9074 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
9075 || TREE_CODE_CLASS (code_right
) == tcc_comparison
)
9076 warning (OPT_Wparentheses
,
9077 "suggest parentheses around comparison in operand of %<|%>");
9078 /* Check cases like !x | y */
9079 else if (code_left
== TRUTH_NOT_EXPR
9080 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
9081 warning (OPT_Wparentheses
, "suggest parentheses around operand of "
9082 "%<!%> or change %<|%> to %<||%> or %<!%> to %<~%>");
9086 if (code_left
== BIT_AND_EXPR
9087 || code_left
== PLUS_EXPR
|| code_left
== MINUS_EXPR
9088 || code_right
== BIT_AND_EXPR
9089 || code_right
== PLUS_EXPR
|| code_right
== MINUS_EXPR
)
9090 warning (OPT_Wparentheses
,
9091 "suggest parentheses around arithmetic in operand of %<^%>");
9092 /* Check cases like x^y==z */
9093 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
9094 || TREE_CODE_CLASS (code_right
) == tcc_comparison
)
9095 warning (OPT_Wparentheses
,
9096 "suggest parentheses around comparison in operand of %<^%>");
9100 if (code_left
== PLUS_EXPR
|| code_right
== PLUS_EXPR
)
9101 warning (OPT_Wparentheses
,
9102 "suggest parentheses around %<+%> in operand of %<&%>");
9103 else if (code_left
== MINUS_EXPR
|| code_right
== MINUS_EXPR
)
9104 warning (OPT_Wparentheses
,
9105 "suggest parentheses around %<-%> in operand of %<&%>");
9106 /* Check cases like x&y==z */
9107 else if (TREE_CODE_CLASS (code_left
) == tcc_comparison
9108 || TREE_CODE_CLASS (code_right
) == tcc_comparison
)
9109 warning (OPT_Wparentheses
,
9110 "suggest parentheses around comparison in operand of %<&%>");
9111 /* Check cases like !x & y */
9112 else if (code_left
== TRUTH_NOT_EXPR
9113 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right
, arg_right
))
9114 warning (OPT_Wparentheses
, "suggest parentheses around operand of "
9115 "%<!%> or change %<&%> to %<&&%> or %<!%> to %<~%>");
9119 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
9120 || TREE_CODE_CLASS (code_right
) == tcc_comparison
)
9121 warning (OPT_Wparentheses
,
9122 "suggest parentheses around comparison in operand of %<==%>");
9125 if (TREE_CODE_CLASS (code_left
) == tcc_comparison
9126 || TREE_CODE_CLASS (code_right
) == tcc_comparison
)
9127 warning (OPT_Wparentheses
,
9128 "suggest parentheses around comparison in operand of %<!=%>");
9132 if (TREE_CODE_CLASS (code
) == tcc_comparison
9133 && ((TREE_CODE_CLASS (code_left
) == tcc_comparison
9134 && code_left
!= NE_EXPR
&& code_left
!= EQ_EXPR
9135 && INTEGRAL_TYPE_P (TREE_TYPE (arg_left
)))
9136 || (TREE_CODE_CLASS (code_right
) == tcc_comparison
9137 && code_right
!= NE_EXPR
&& code_right
!= EQ_EXPR
9138 && INTEGRAL_TYPE_P (TREE_TYPE (arg_right
)))))
9139 warning (OPT_Wparentheses
, "comparisons like %<X<=Y<=Z%> do not "
9140 "have their mathematical meaning");
9143 #undef NOT_A_BOOLEAN_EXPR_P
9146 /* If LABEL (a LABEL_DECL) has not been used, issue a warning. */
9149 warn_for_unused_label (tree label
)
9151 if (!TREE_USED (label
))
9153 if (DECL_INITIAL (label
))
9154 warning (OPT_Wunused_label
, "label %q+D defined but not used", label
);
9156 warning (OPT_Wunused_label
, "label %q+D declared but not defined", label
);
9160 #ifndef TARGET_HAS_TARGETCM
9161 struct gcc_targetcm targetcm
= TARGETCM_INITIALIZER
;
9164 /* Warn for division by zero according to the value of DIVISOR. LOC
9165 is the location of the division operator. */
9168 warn_for_div_by_zero (location_t loc
, tree divisor
)
9170 /* If DIVISOR is zero, and has integral or fixed-point type, issue a warning
9171 about division by zero. Do not issue a warning if DIVISOR has a
9172 floating-point type, since we consider 0.0/0.0 a valid way of
9173 generating a NaN. */
9174 if (c_inhibit_evaluation_warnings
== 0
9175 && (integer_zerop (divisor
) || fixed_zerop (divisor
)))
9176 warning_at (loc
, OPT_Wdiv_by_zero
, "division by zero");
9179 /* Subroutine of build_binary_op. Give warnings for comparisons
9180 between signed and unsigned quantities that may fail. Do the
9181 checking based on the original operand trees ORIG_OP0 and ORIG_OP1,
9182 so that casts will be considered, but default promotions won't
9185 LOCATION is the location of the comparison operator.
9187 The arguments of this function map directly to local variables
9188 of build_binary_op. */
9191 warn_for_sign_compare (location_t location
,
9192 tree orig_op0
, tree orig_op1
,
9194 tree result_type
, enum tree_code resultcode
)
9196 int op0_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op0
));
9197 int op1_signed
= !TYPE_UNSIGNED (TREE_TYPE (orig_op1
));
9198 int unsignedp0
, unsignedp1
;
9200 /* In C++, check for comparison of different enum types. */
9202 && TREE_CODE (TREE_TYPE (orig_op0
)) == ENUMERAL_TYPE
9203 && TREE_CODE (TREE_TYPE (orig_op1
)) == ENUMERAL_TYPE
9204 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0
))
9205 != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1
)))
9207 warning_at (location
,
9208 OPT_Wsign_compare
, "comparison between types %qT and %qT",
9209 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
));
9212 /* Do not warn if the comparison is being done in a signed type,
9213 since the signed type will only be chosen if it can represent
9214 all the values of the unsigned type. */
9215 if (!TYPE_UNSIGNED (result_type
))
9217 /* Do not warn if both operands are unsigned. */
9218 else if (op0_signed
== op1_signed
)
9222 tree sop
, uop
, base_type
;
9226 sop
= orig_op0
, uop
= orig_op1
;
9228 sop
= orig_op1
, uop
= orig_op0
;
9230 STRIP_TYPE_NOPS (sop
);
9231 STRIP_TYPE_NOPS (uop
);
9232 base_type
= (TREE_CODE (result_type
) == COMPLEX_TYPE
9233 ? TREE_TYPE (result_type
) : result_type
);
9235 /* Do not warn if the signed quantity is an unsuffixed integer
9236 literal (or some static constant expression involving such
9237 literals or a conditional expression involving such literals)
9238 and it is non-negative. */
9239 if (tree_expr_nonnegative_warnv_p (sop
, &ovf
))
9241 /* Do not warn if the comparison is an equality operation, the
9242 unsigned quantity is an integral constant, and it would fit
9243 in the result if the result were signed. */
9244 else if (TREE_CODE (uop
) == INTEGER_CST
9245 && (resultcode
== EQ_EXPR
|| resultcode
== NE_EXPR
)
9246 && int_fits_type_p (uop
, c_common_signed_type (base_type
)))
9248 /* In C, do not warn if the unsigned quantity is an enumeration
9249 constant and its maximum value would fit in the result if the
9250 result were signed. */
9251 else if (!c_dialect_cxx() && TREE_CODE (uop
) == INTEGER_CST
9252 && TREE_CODE (TREE_TYPE (uop
)) == ENUMERAL_TYPE
9253 && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (uop
)),
9254 c_common_signed_type (base_type
)))
9257 warning_at (location
,
9259 "comparison between signed and unsigned integer expressions");
9262 /* Warn if two unsigned values are being compared in a size larger
9263 than their original size, and one (and only one) is the result of
9264 a `~' operator. This comparison will always fail.
9266 Also warn if one operand is a constant, and the constant does not
9267 have all bits set that are set in the ~ operand when it is
9270 op0
= get_narrower (op0
, &unsignedp0
);
9271 op1
= get_narrower (op1
, &unsignedp1
);
9273 if ((TREE_CODE (op0
) == BIT_NOT_EXPR
)
9274 ^ (TREE_CODE (op1
) == BIT_NOT_EXPR
))
9276 if (TREE_CODE (op0
) == BIT_NOT_EXPR
)
9277 op0
= get_narrower (TREE_OPERAND (op0
, 0), &unsignedp0
);
9278 if (TREE_CODE (op1
) == BIT_NOT_EXPR
)
9279 op1
= get_narrower (TREE_OPERAND (op1
, 0), &unsignedp1
);
9281 if (host_integerp (op0
, 0) || host_integerp (op1
, 0))
9284 HOST_WIDE_INT constant
, mask
;
9288 if (host_integerp (op0
, 0))
9291 unsignedp
= unsignedp1
;
9292 constant
= tree_low_cst (op0
, 0);
9297 unsignedp
= unsignedp0
;
9298 constant
= tree_low_cst (op1
, 0);
9301 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
9302 if (bits
< TYPE_PRECISION (result_type
)
9303 && bits
< HOST_BITS_PER_LONG
&& unsignedp
)
9305 mask
= (~ (HOST_WIDE_INT
) 0) << bits
;
9306 if ((mask
& constant
) != mask
)
9309 warning (OPT_Wsign_compare
,
9310 "promoted ~unsigned is always non-zero");
9312 warning_at (location
, OPT_Wsign_compare
,
9313 "comparison of promoted ~unsigned with constant");
9317 else if (unsignedp0
&& unsignedp1
9318 && (TYPE_PRECISION (TREE_TYPE (op0
))
9319 < TYPE_PRECISION (result_type
))
9320 && (TYPE_PRECISION (TREE_TYPE (op1
))
9321 < TYPE_PRECISION (result_type
)))
9322 warning_at (location
, OPT_Wsign_compare
,
9323 "comparison of promoted ~unsigned with unsigned");
9327 /* Setup a TYPE_DECL node as a typedef representation.
9329 X is a TYPE_DECL for a typedef statement. Create a brand new
9330 ..._TYPE node (which will be just a variant of the existing
9331 ..._TYPE node with identical properties) and then install X
9332 as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
9334 The whole point here is to end up with a situation where each
9335 and every ..._TYPE node the compiler creates will be uniquely
9336 associated with AT MOST one node representing a typedef name.
9337 This way, even though the compiler substitutes corresponding
9338 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
9339 early on, later parts of the compiler can always do the reverse
9340 translation and get back the corresponding typedef name. For
9343 typedef struct S MY_TYPE;
9346 Later parts of the compiler might only know that `object' was of
9347 type `struct S' if it were not for code just below. With this
9348 code however, later parts of the compiler see something like:
9350 struct S' == struct S
9351 typedef struct S' MY_TYPE;
9354 And they can then deduce (from the node for type struct S') that
9355 the original object declaration was:
9359 Being able to do this is important for proper support of protoize,
9360 and also for generating precise symbolic debugging information
9361 which takes full account of the programmer's (typedef) vocabulary.
9363 Obviously, we don't want to generate a duplicate ..._TYPE node if
9364 the TYPE_DECL node that we are now processing really represents a
9365 standard built-in type. */
9368 set_underlying_type (tree x
)
9370 if (x
== error_mark_node
)
9372 if (DECL_IS_BUILTIN (x
))
9374 if (TYPE_NAME (TREE_TYPE (x
)) == 0)
9375 TYPE_NAME (TREE_TYPE (x
)) = x
;
9377 else if (TREE_TYPE (x
) != error_mark_node
9378 && DECL_ORIGINAL_TYPE (x
) == NULL_TREE
)
9380 tree tt
= TREE_TYPE (x
);
9381 DECL_ORIGINAL_TYPE (x
) = tt
;
9382 tt
= build_variant_type_copy (tt
);
9383 TYPE_STUB_DECL (tt
) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x
));
9385 TREE_USED (tt
) = TREE_USED (x
);
9390 /* Returns true if X is a typedef decl. */
9393 is_typedef_decl (tree x
)
9395 return (x
&& TREE_CODE (x
) == TYPE_DECL
9396 && DECL_ORIGINAL_TYPE (x
) != NULL_TREE
);
9399 /* Record the types used by the current global variable declaration
9400 being parsed, so that we can decide later to emit their debug info.
9401 Those types are in types_used_by_cur_var_decl, and we are going to
9402 store them in the types_used_by_vars_hash hash table.
9403 DECL is the declaration of the global variable that has been parsed. */
9406 record_types_used_by_current_var_decl (tree decl
)
9408 gcc_assert (decl
&& DECL_P (decl
) && TREE_STATIC (decl
));
9410 if (types_used_by_cur_var_decl
)
9413 for (node
= types_used_by_cur_var_decl
;
9415 node
= TREE_CHAIN (node
))
9417 tree type
= TREE_PURPOSE (node
);
9418 types_used_by_var_decl_insert (type
, decl
);
9420 types_used_by_cur_var_decl
= NULL
;
9424 /* The C and C++ parsers both use vectors to hold function arguments.
9425 For efficiency, we keep a cache of unused vectors. This is the
9428 typedef VEC(tree
,gc
)* tree_gc_vec
;
9429 DEF_VEC_P(tree_gc_vec
);
9430 DEF_VEC_ALLOC_P(tree_gc_vec
,gc
);
9431 static GTY((deletable
)) VEC(tree_gc_vec
,gc
) *tree_vector_cache
;
9433 /* Return a new vector from the cache. If the cache is empty,
9434 allocate a new vector. These vectors are GC'ed, so it is OK if the
9435 pointer is not released.. */
9438 make_tree_vector (void)
9440 if (!VEC_empty (tree_gc_vec
, tree_vector_cache
))
9441 return VEC_pop (tree_gc_vec
, tree_vector_cache
);
9444 /* Passing 0 to VEC_alloc returns NULL, and our callers require
9445 that we always return a non-NULL value. The vector code uses
9446 4 when growing a NULL vector, so we do too. */
9447 return VEC_alloc (tree
, gc
, 4);
9451 /* Release a vector of trees back to the cache. */
9454 release_tree_vector (VEC(tree
,gc
) *vec
)
9458 VEC_truncate (tree
, vec
, 0);
9459 VEC_safe_push (tree_gc_vec
, gc
, tree_vector_cache
, vec
);
9463 /* Get a new tree vector holding a single tree. */
9466 make_tree_vector_single (tree t
)
9468 VEC(tree
,gc
) *ret
= make_tree_vector ();
9469 VEC_quick_push (tree
, ret
, t
);
9473 /* Get a new tree vector which is a copy of an existing one. */
9476 make_tree_vector_copy (const VEC(tree
,gc
) *orig
)
9482 ret
= make_tree_vector ();
9483 VEC_reserve (tree
, gc
, ret
, VEC_length (tree
, orig
));
9484 for (ix
= 0; VEC_iterate (tree
, orig
, ix
, t
); ++ix
)
9485 VEC_quick_push (tree
, ret
, t
);
9489 #include "gt-c-common.h"