]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/c-family/c-common.c
2011-01-11 Paul Thomas <pault@gcc.gnu.org>
[thirdparty/gcc.git] / gcc / c-family / c-common.c
CommitLineData
b0fc3e72 1/* Subroutines shared by all languages that are variants of C.
d513ec2f 2 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
fdd84b77 3 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
2d9d8740 4 Free Software Foundation, Inc.
b0fc3e72 5
f12b58b3 6This file is part of GCC.
b0fc3e72 7
f12b58b3 8GCC is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
8c4c00c1 10Software Foundation; either version 3, or (at your option) any later
f12b58b3 11version.
b0fc3e72 12
f12b58b3 13GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16for more details.
b0fc3e72 17
18You should have received a copy of the GNU General Public License
8c4c00c1 19along with GCC; see the file COPYING3. If not see
20<http://www.gnu.org/licenses/>. */
b0fc3e72 21
22#include "config.h"
405711de 23#include "system.h"
805e22b2 24#include "coretypes.h"
25#include "tm.h"
e48d0f41 26#include "intl.h"
b0fc3e72 27#include "tree.h"
b0fc3e72 28#include "flags.h"
cd03a192 29#include "output.h"
a3fa7feb 30#include "c-pragma.h"
dc12af01 31#include "ggc.h"
e41f0d80 32#include "c-common.h"
6c536c4f 33#include "c-objc.h"
d8c9779c 34#include "tm_p.h"
4e91a871 35#include "obstack.h"
a654e028 36#include "cpplib.h"
8ee295a7 37#include "target.h"
96554925 38#include "langhooks.h"
f3dde807 39#include "tree-inline.h"
69579044 40#include "toplev.h"
7f5f3953 41#include "diagnostic.h"
4ee9c684 42#include "tree-iterator.h"
43#include "hashtab.h"
b55af61c 44#include "tree-mudflap.h"
e08bd2f4 45#include "opts.h"
62eec3b4 46#include "cgraph.h"
b9fc964a 47#include "target-def.h"
979d3efc 48#include "libfuncs.h"
fd6f6435 49
90cc7820 50cpp_reader *parse_in; /* Declared in c-pragma.h. */
a654e028 51
72040e7e 52/* The following symbols are subsumed in the c_global_trees array, and
44e9fa65 53 listed here individually for documentation purposes.
72040e7e 54
55 INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
56
57 tree short_integer_type_node;
58 tree long_integer_type_node;
59 tree long_long_integer_type_node;
6388cfe2 60 tree int128_integer_type_node;
72040e7e 61
62 tree short_unsigned_type_node;
63 tree long_unsigned_type_node;
64 tree long_long_unsigned_type_node;
6388cfe2 65 tree int128_unsigned_type_node;
72040e7e 66
3c2239cf 67 tree truthvalue_type_node;
68 tree truthvalue_false_node;
69 tree truthvalue_true_node;
72040e7e 70
71 tree ptrdiff_type_node;
72
73 tree unsigned_char_type_node;
74 tree signed_char_type_node;
75 tree wchar_type_node;
72040e7e 76
924bbf02 77 tree char16_type_node;
78 tree char32_type_node;
79
72040e7e 80 tree float_type_node;
81 tree double_type_node;
82 tree long_double_type_node;
83
84 tree complex_integer_type_node;
85 tree complex_float_type_node;
86 tree complex_double_type_node;
87 tree complex_long_double_type_node;
88
c4503c0a 89 tree dfloat32_type_node;
90 tree dfloat64_type_node;
91 tree_dfloat128_type_node;
92
72040e7e 93 tree intQI_type_node;
94 tree intHI_type_node;
95 tree intSI_type_node;
96 tree intDI_type_node;
97 tree intTI_type_node;
98
99 tree unsigned_intQI_type_node;
100 tree unsigned_intHI_type_node;
101 tree unsigned_intSI_type_node;
102 tree unsigned_intDI_type_node;
103 tree unsigned_intTI_type_node;
104
105 tree widest_integer_literal_type_node;
106 tree widest_unsigned_literal_type_node;
107
108 Nodes for types `void *' and `const void *'.
109
110 tree ptr_type_node, const_ptr_type_node;
111
112 Nodes for types `char *' and `const char *'.
113
114 tree string_type_node, const_string_type_node;
115
116 Type `char[SOMENUMBER]'.
117 Used when an array of char is needed and the size is irrelevant.
118
119 tree char_array_type_node;
120
121 Type `int[SOMENUMBER]' or something like it.
122 Used when an array of int needed and the size is irrelevant.
123
124 tree int_array_type_node;
125
126 Type `wchar_t[SOMENUMBER]' or something like it.
127 Used when a wide string literal is created.
128
129 tree wchar_array_type_node;
130
924bbf02 131 Type `char16_t[SOMENUMBER]' or something like it.
132 Used when a UTF-16 string literal is created.
133
134 tree char16_array_type_node;
135
136 Type `char32_t[SOMENUMBER]' or something like it.
137 Used when a UTF-32 string literal is created.
138
139 tree char32_array_type_node;
140
72040e7e 141 Type `int ()' -- used for implicit declaration of functions.
142
143 tree default_function_type;
144
72040e7e 145 A VOID_TYPE node, packaged in a TREE_LIST.
146
147 tree void_list_node;
148
734c98be 149 The lazily created VAR_DECLs for __FUNCTION__, __PRETTY_FUNCTION__,
65b7f83f 150 and __func__. (C doesn't generate __FUNCTION__ and__PRETTY_FUNCTION__
151 VAR_DECLS, but C++ does.)
71d9fc9b 152
65b7f83f 153 tree function_name_decl_node;
734c98be 154 tree pretty_function_name_decl_node;
65b7f83f 155 tree c99_function_name_decl_node;
156
157 Stack of nested function name VAR_DECLs.
1cae46be 158
65b7f83f 159 tree saved_function_name_decls;
71d9fc9b 160
72040e7e 161*/
162
163tree c_global_trees[CTI_MAX];
573aba85 164\f
574a6990 165/* Switches common to the C front ends. */
166
f7070933 167/* Nonzero means don't output line number information. */
168
169char flag_no_line_commands;
170
171/* Nonzero causes -E output not to be done, but directives such as
172 #define that have side effects are still obeyed. */
173
174char flag_no_output;
175
176/* Nonzero means dump macros in some fashion. */
177
178char flag_dump_macros;
179
180/* Nonzero means pass #include lines through to the output. */
181
182char flag_dump_includes;
183
d718b525 184/* Nonzero means process PCH files while preprocessing. */
185
186bool flag_pch_preprocess;
187
573aba85 188/* The file name to which we should write a precompiled header, or
189 NULL if no header will be written in this compile. */
190
191const char *pch_file;
192
1ed9d5f5 193/* Nonzero if an ISO standard was selected. It rejects macros in the
194 user's namespace. */
195int flag_iso;
196
1cae46be 197/* Warn about #pragma directives that are not recognized. */
574a6990 198
1cae46be 199int warn_unknown_pragmas; /* Tri state variable. */
574a6990 200
574a6990 201/* Warn about format/argument anomalies in calls to formatted I/O functions
202 (*printf, *scanf, strftime, strfmon, etc.). */
203
204int warn_format;
205
574a6990 206/* C/ObjC language option variables. */
207
208
574a6990 209/* Nonzero means allow type mismatches in conditional expressions;
210 just make their values `void'. */
211
212int flag_cond_mismatch;
213
214/* Nonzero means enable C89 Amendment 1 features. */
215
216int flag_isoc94;
217
39012afb 218/* Nonzero means use the ISO C99 (or C1X) dialect of C. */
574a6990 219
220int flag_isoc99;
221
39012afb 222/* Nonzero means use the ISO C1X dialect of C. */
223
224int flag_isoc1x;
225
8b332087 226/* Nonzero means that we have builtin functions, and main is an int. */
574a6990 227
228int flag_hosted = 1;
229
574a6990 230
231/* ObjC language option variables. */
232
233
574a6990 234/* Tells the compiler that this is a special run. Do not perform any
235 compiling, instead we are to test some platform dependent features
236 and output a C header file with appropriate definitions. */
237
238int print_struct_values;
239
f0b5f617 240/* Tells the compiler what is the constant string class for ObjC. */
574a6990 241
242const char *constant_string_class_name;
243
574a6990 244
245/* C++ language option variables. */
246
247
574a6990 248/* Nonzero means generate separate instantiation control files and
249 juggle them at link time. */
250
251int flag_use_repository;
252
6dcdb5de 253/* The C++ dialect being used. C++98 is the default. */
0fe6eeac 254
6dcdb5de 255enum cxx_dialect cxx_dialect = cxx98;
0fe6eeac 256
9dcd0d49 257/* Maximum template instantiation depth. This limit exists to limit the
258 time it takes to notice infinite template instantiations; the default
259 value of 1024 is likely to be in the next C++ standard. */
574a6990 260
9dcd0d49 261int max_tinst_depth = 1024;
574a6990 262
263
264
988fc1d1 265/* The elements of `ridpointers' are identifier nodes for the reserved
266 type names and storage classes. It is indexed by a RID_... value. */
267tree *ridpointers;
268
e60a6f7b 269tree (*make_fname_decl) (location_t, tree, int);
9e5a737d 270
48d94ede 271/* Nonzero means don't warn about problems that occur when the code is
272 executed. */
273int c_inhibit_evaluation_warnings;
e78703c1 274
93be21c0 275/* Whether we are building a boolean conversion inside
276 convert_for_assignment, or some other late binary operation. If
277 build_binary_op is called for C (from code shared by C and C++) in
278 this case, then the operands have already been folded and the
279 result will not be folded again, so C_MAYBE_CONST_EXPR should not
280 be generated. */
281bool in_late_binary_op;
282
7f5f3953 283/* Whether lexing has been completed, so subsequent preprocessor
284 errors should use the compiler's input_location. */
285bool done_lexing = false;
286
2c0e001b 287/* Information about how a function name is generated. */
65b7f83f 288struct fname_var_t
289{
e99c3a1d 290 tree *const decl; /* pointer to the VAR_DECL. */
291 const unsigned rid; /* RID number for the identifier. */
292 const int pretty; /* How pretty is it? */
65b7f83f 293};
294
2c0e001b 295/* The three ways of getting then name of the current function. */
65b7f83f 296
297const struct fname_var_t fname_vars[] =
298{
2c0e001b 299 /* C99 compliant __func__, must be first. */
65b7f83f 300 {&c99_function_name_decl_node, RID_C99_FUNCTION_NAME, 0},
2c0e001b 301 /* GCC __FUNCTION__ compliant. */
65b7f83f 302 {&function_name_decl_node, RID_FUNCTION_NAME, 0},
2c0e001b 303 /* GCC __PRETTY_FUNCTION__ compliant. */
65b7f83f 304 {&pretty_function_name_decl_node, RID_PRETTY_FUNCTION_NAME, 1},
305 {NULL, 0, 0},
306};
307
79396169 308/* Global visibility options. */
309struct visibility_flags visibility_options;
310
a75b1c71 311static tree c_fully_fold_internal (tree expr, bool, bool *, bool *);
2ca392fd 312static tree check_case_value (tree);
313static bool check_case_bounds (tree, tree, tree *, tree *);
be43ff5a 314
1cae46be 315static tree handle_packed_attribute (tree *, tree, tree, int, bool *);
316static tree handle_nocommon_attribute (tree *, tree, tree, int, bool *);
317static tree handle_common_attribute (tree *, tree, tree, int, bool *);
318static tree handle_noreturn_attribute (tree *, tree, tree, int, bool *);
5de92639 319static tree handle_hot_attribute (tree *, tree, tree, int, bool *);
320static tree handle_cold_attribute (tree *, tree, tree, int, bool *);
1cae46be 321static tree handle_noinline_attribute (tree *, tree, tree, int, bool *);
bdb1f0d1 322static tree handle_noclone_attribute (tree *, tree, tree, int, bool *);
7bd95dfd 323static tree handle_leaf_attribute (tree *, tree, tree, int, bool *);
1cae46be 324static tree handle_always_inline_attribute (tree *, tree, tree, int,
325 bool *);
1b16fc45 326static tree handle_gnu_inline_attribute (tree *, tree, tree, int, bool *);
327static tree handle_artificial_attribute (tree *, tree, tree, int, bool *);
0cdd9887 328static tree handle_flatten_attribute (tree *, tree, tree, int, bool *);
10fc867f 329static tree handle_error_attribute (tree *, tree, tree, int, bool *);
1cae46be 330static tree handle_used_attribute (tree *, tree, tree, int, bool *);
331static tree handle_unused_attribute (tree *, tree, tree, int, bool *);
62eec3b4 332static tree handle_externally_visible_attribute (tree *, tree, tree, int,
333 bool *);
1cae46be 334static tree handle_const_attribute (tree *, tree, tree, int, bool *);
335static tree handle_transparent_union_attribute (tree *, tree, tree,
336 int, bool *);
337static tree handle_constructor_attribute (tree *, tree, tree, int, bool *);
338static tree handle_destructor_attribute (tree *, tree, tree, int, bool *);
339static tree handle_mode_attribute (tree *, tree, tree, int, bool *);
340static tree handle_section_attribute (tree *, tree, tree, int, bool *);
341static tree handle_aligned_attribute (tree *, tree, tree, int, bool *);
342static tree handle_weak_attribute (tree *, tree, tree, int, bool *) ;
85c0a25c 343static tree handle_alias_ifunc_attribute (bool, tree *, tree, tree, bool *);
344static tree handle_ifunc_attribute (tree *, tree, tree, int, bool *);
1cae46be 345static tree handle_alias_attribute (tree *, tree, tree, int, bool *);
f4a30bd7 346static tree handle_weakref_attribute (tree *, tree, tree, int, bool *) ;
1cae46be 347static tree handle_visibility_attribute (tree *, tree, tree, int,
348 bool *);
349static tree handle_tls_model_attribute (tree *, tree, tree, int,
350 bool *);
351static tree handle_no_instrument_function_attribute (tree *, tree,
352 tree, int, bool *);
353static tree handle_malloc_attribute (tree *, tree, tree, int, bool *);
26d1c5ff 354static tree handle_returns_twice_attribute (tree *, tree, tree, int, bool *);
1cae46be 355static tree handle_no_limit_stack_attribute (tree *, tree, tree, int,
356 bool *);
357static tree handle_pure_attribute (tree *, tree, tree, int, bool *);
fc09b200 358static tree handle_novops_attribute (tree *, tree, tree, int, bool *);
1cae46be 359static tree handle_deprecated_attribute (tree *, tree, tree, int,
360 bool *);
361static tree handle_vector_size_attribute (tree *, tree, tree, int,
362 bool *);
363static tree handle_nonnull_attribute (tree *, tree, tree, int, bool *);
364static tree handle_nothrow_attribute (tree *, tree, tree, int, bool *);
365static tree handle_cleanup_attribute (tree *, tree, tree, int, bool *);
8a8cdb8d 366static tree handle_warn_unused_result_attribute (tree *, tree, tree, int,
367 bool *);
bf6c8de0 368static tree handle_sentinel_attribute (tree *, tree, tree, int, bool *);
b5c26b42 369static tree handle_type_generic_attribute (tree *, tree, tree, int, bool *);
4a29c97c 370static tree handle_alloc_size_attribute (tree *, tree, tree, int, bool *);
24470055 371static tree handle_target_attribute (tree *, tree, tree, int, bool *);
46f8e3b0 372static tree handle_optimize_attribute (tree *, tree, tree, int, bool *);
48b14f50 373static tree handle_no_split_stack_attribute (tree *, tree, tree, int, bool *);
8ce86007 374static tree handle_fnspec_attribute (tree *, tree, tree, int, bool *);
1cae46be 375
d01f58f9 376static void check_function_nonnull (tree, int, tree *);
1cae46be 377static void check_nonnull_arg (void *, tree, unsigned HOST_WIDE_INT);
378static bool nonnull_check_p (tree, unsigned HOST_WIDE_INT);
379static bool get_nonnull_operand (tree, unsigned HOST_WIDE_INT *);
860251be 380static int resort_field_decl_cmp (const void *, const void *);
dbf6c367 381
5c6e5756 382/* Reserved words. The third field is a mask: keywords are disabled
383 if they match the mask.
384
385 Masks for languages:
386 C --std=c89: D_C99 | D_CXXONLY | D_OBJC | D_CXX_OBJC
387 C --std=c99: D_CXXONLY | D_OBJC
388 ObjC is like C except that D_OBJC and D_CXX_OBJC are not set
389 C++ --std=c98: D_CONLY | D_CXXOX | D_OBJC
390 C++ --std=c0x: D_CONLY | D_OBJC
391 ObjC++ is like C++ except that D_OBJC is not set
392
393 If -fno-asm is used, D_ASM is added to the mask. If
394 -fno-gnu-keywords is used, D_EXT is added. If -fno-asm and C in
395 C89 mode, D_EXT89 is added for both -fno-asm and -fno-gnu-keywords.
b27e241e 396 In C with -Wc++-compat, we warn if D_CXXWARN is set.
5c6e5756 397
b27e241e 398 Note the complication of the D_CXX_OBJC keywords. These are
399 reserved words such as 'class'. In C++, 'class' is a reserved
400 word. In Objective-C++ it is too. In Objective-C, it is a
401 reserved word too, but only if it follows an '@' sign.
402*/
5c6e5756 403const struct c_common_resword c_common_reswords[] =
404{
405 { "_Bool", RID_BOOL, D_CONLY },
406 { "_Complex", RID_COMPLEX, 0 },
c1800156 407 { "_Imaginary", RID_IMAGINARY, D_CONLY },
5c6e5756 408 { "_Decimal32", RID_DFLOAT32, D_CONLY | D_EXT },
409 { "_Decimal64", RID_DFLOAT64, D_CONLY | D_EXT },
410 { "_Decimal128", RID_DFLOAT128, D_CONLY | D_EXT },
411 { "_Fract", RID_FRACT, D_CONLY | D_EXT },
412 { "_Accum", RID_ACCUM, D_CONLY | D_EXT },
413 { "_Sat", RID_SAT, D_CONLY | D_EXT },
f80e7755 414 { "_Static_assert", RID_STATIC_ASSERT, D_CONLY },
5c6e5756 415 { "__FUNCTION__", RID_FUNCTION_NAME, 0 },
416 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
417 { "__alignof", RID_ALIGNOF, 0 },
418 { "__alignof__", RID_ALIGNOF, 0 },
419 { "__asm", RID_ASM, 0 },
420 { "__asm__", RID_ASM, 0 },
421 { "__attribute", RID_ATTRIBUTE, 0 },
422 { "__attribute__", RID_ATTRIBUTE, 0 },
423 { "__builtin_choose_expr", RID_CHOOSE_EXPR, D_CONLY },
424 { "__builtin_offsetof", RID_OFFSETOF, 0 },
425 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, D_CONLY },
426 { "__builtin_va_arg", RID_VA_ARG, 0 },
427 { "__complex", RID_COMPLEX, 0 },
428 { "__complex__", RID_COMPLEX, 0 },
429 { "__const", RID_CONST, 0 },
430 { "__const__", RID_CONST, 0 },
431 { "__decltype", RID_DECLTYPE, D_CXXONLY },
432 { "__extension__", RID_EXTENSION, 0 },
433 { "__func__", RID_C99_FUNCTION_NAME, 0 },
434 { "__has_nothrow_assign", RID_HAS_NOTHROW_ASSIGN, D_CXXONLY },
435 { "__has_nothrow_constructor", RID_HAS_NOTHROW_CONSTRUCTOR, D_CXXONLY },
436 { "__has_nothrow_copy", RID_HAS_NOTHROW_COPY, D_CXXONLY },
437 { "__has_trivial_assign", RID_HAS_TRIVIAL_ASSIGN, D_CXXONLY },
438 { "__has_trivial_constructor", RID_HAS_TRIVIAL_CONSTRUCTOR, D_CXXONLY },
439 { "__has_trivial_copy", RID_HAS_TRIVIAL_COPY, D_CXXONLY },
440 { "__has_trivial_destructor", RID_HAS_TRIVIAL_DESTRUCTOR, D_CXXONLY },
441 { "__has_virtual_destructor", RID_HAS_VIRTUAL_DESTRUCTOR, D_CXXONLY },
6388cfe2 442 { "__int128", RID_INT128, 0 },
5c6e5756 443 { "__is_abstract", RID_IS_ABSTRACT, D_CXXONLY },
444 { "__is_base_of", RID_IS_BASE_OF, D_CXXONLY },
445 { "__is_class", RID_IS_CLASS, D_CXXONLY },
446 { "__is_convertible_to", RID_IS_CONVERTIBLE_TO, D_CXXONLY },
447 { "__is_empty", RID_IS_EMPTY, D_CXXONLY },
448 { "__is_enum", RID_IS_ENUM, D_CXXONLY },
449 { "__is_pod", RID_IS_POD, D_CXXONLY },
450 { "__is_polymorphic", RID_IS_POLYMORPHIC, D_CXXONLY },
c1c67b4f 451 { "__is_standard_layout", RID_IS_STD_LAYOUT, D_CXXONLY },
452 { "__is_trivial", RID_IS_TRIVIAL, D_CXXONLY },
5c6e5756 453 { "__is_union", RID_IS_UNION, D_CXXONLY },
5290e253 454 { "__is_literal_type", RID_IS_LITERAL_TYPE, D_CXXONLY },
5c6e5756 455 { "__imag", RID_IMAGPART, 0 },
456 { "__imag__", RID_IMAGPART, 0 },
457 { "__inline", RID_INLINE, 0 },
458 { "__inline__", RID_INLINE, 0 },
459 { "__label__", RID_LABEL, 0 },
460 { "__null", RID_NULL, 0 },
461 { "__real", RID_REALPART, 0 },
462 { "__real__", RID_REALPART, 0 },
463 { "__restrict", RID_RESTRICT, 0 },
464 { "__restrict__", RID_RESTRICT, 0 },
465 { "__signed", RID_SIGNED, 0 },
466 { "__signed__", RID_SIGNED, 0 },
467 { "__thread", RID_THREAD, 0 },
468 { "__typeof", RID_TYPEOF, 0 },
469 { "__typeof__", RID_TYPEOF, 0 },
470 { "__volatile", RID_VOLATILE, 0 },
471 { "__volatile__", RID_VOLATILE, 0 },
e463efd7 472 { "alignof", RID_ALIGNOF, D_CXXONLY | D_CXX0X | D_CXXWARN },
5c6e5756 473 { "asm", RID_ASM, D_ASM },
474 { "auto", RID_AUTO, 0 },
dbd982c9 475 { "bool", RID_BOOL, D_CXXONLY | D_CXXWARN },
5c6e5756 476 { "break", RID_BREAK, 0 },
477 { "case", RID_CASE, 0 },
51030405 478 { "catch", RID_CATCH, D_CXX_OBJC | D_CXXWARN },
5c6e5756 479 { "char", RID_CHAR, 0 },
51030405 480 { "char16_t", RID_CHAR16, D_CXXONLY | D_CXX0X | D_CXXWARN },
481 { "char32_t", RID_CHAR32, D_CXXONLY | D_CXX0X | D_CXXWARN },
482 { "class", RID_CLASS, D_CXX_OBJC | D_CXXWARN },
5c6e5756 483 { "const", RID_CONST, 0 },
17814aca 484 { "constexpr", RID_CONSTEXPR, D_CXXONLY | D_CXX0X | D_CXXWARN },
5c6e5756 485 { "const_cast", RID_CONSTCAST, D_CXXONLY | D_CXXWARN },
486 { "continue", RID_CONTINUE, 0 },
51030405 487 { "decltype", RID_DECLTYPE, D_CXXONLY | D_CXX0X | D_CXXWARN },
5c6e5756 488 { "default", RID_DEFAULT, 0 },
51030405 489 { "delete", RID_DELETE, D_CXXONLY | D_CXXWARN },
5c6e5756 490 { "do", RID_DO, 0 },
491 { "double", RID_DOUBLE, 0 },
492 { "dynamic_cast", RID_DYNCAST, D_CXXONLY | D_CXXWARN },
493 { "else", RID_ELSE, 0 },
494 { "enum", RID_ENUM, 0 },
51030405 495 { "explicit", RID_EXPLICIT, D_CXXONLY | D_CXXWARN },
496 { "export", RID_EXPORT, D_CXXONLY | D_CXXWARN },
5c6e5756 497 { "extern", RID_EXTERN, 0 },
51030405 498 { "false", RID_FALSE, D_CXXONLY | D_CXXWARN },
5c6e5756 499 { "float", RID_FLOAT, 0 },
500 { "for", RID_FOR, 0 },
51030405 501 { "friend", RID_FRIEND, D_CXXONLY | D_CXXWARN },
5c6e5756 502 { "goto", RID_GOTO, 0 },
503 { "if", RID_IF, 0 },
504 { "inline", RID_INLINE, D_EXT89 },
505 { "int", RID_INT, 0 },
506 { "long", RID_LONG, 0 },
507 { "mutable", RID_MUTABLE, D_CXXONLY | D_CXXWARN },
51030405 508 { "namespace", RID_NAMESPACE, D_CXXONLY | D_CXXWARN },
509 { "new", RID_NEW, D_CXXONLY | D_CXXWARN },
98fe9664 510 { "noexcept", RID_NOEXCEPT, D_CXXONLY | D_CXX0X | D_CXXWARN },
6fe11077 511 { "nullptr", RID_NULLPTR, D_CXXONLY | D_CXX0X | D_CXXWARN },
51030405 512 { "operator", RID_OPERATOR, D_CXXONLY | D_CXXWARN },
513 { "private", RID_PRIVATE, D_CXX_OBJC | D_CXXWARN },
514 { "protected", RID_PROTECTED, D_CXX_OBJC | D_CXXWARN },
515 { "public", RID_PUBLIC, D_CXX_OBJC | D_CXXWARN },
5c6e5756 516 { "register", RID_REGISTER, 0 },
517 { "reinterpret_cast", RID_REINTCAST, D_CXXONLY | D_CXXWARN },
518 { "restrict", RID_RESTRICT, D_CONLY | D_C99 },
519 { "return", RID_RETURN, 0 },
520 { "short", RID_SHORT, 0 },
521 { "signed", RID_SIGNED, 0 },
522 { "sizeof", RID_SIZEOF, 0 },
523 { "static", RID_STATIC, 0 },
524 { "static_assert", RID_STATIC_ASSERT, D_CXXONLY | D_CXX0X | D_CXXWARN },
525 { "static_cast", RID_STATCAST, D_CXXONLY | D_CXXWARN },
526 { "struct", RID_STRUCT, 0 },
527 { "switch", RID_SWITCH, 0 },
51030405 528 { "template", RID_TEMPLATE, D_CXXONLY | D_CXXWARN },
529 { "this", RID_THIS, D_CXXONLY | D_CXXWARN },
530 { "throw", RID_THROW, D_CXX_OBJC | D_CXXWARN },
531 { "true", RID_TRUE, D_CXXONLY | D_CXXWARN },
532 { "try", RID_TRY, D_CXX_OBJC | D_CXXWARN },
5c6e5756 533 { "typedef", RID_TYPEDEF, 0 },
51030405 534 { "typename", RID_TYPENAME, D_CXXONLY | D_CXXWARN },
535 { "typeid", RID_TYPEID, D_CXXONLY | D_CXXWARN },
5c6e5756 536 { "typeof", RID_TYPEOF, D_ASM | D_EXT },
537 { "union", RID_UNION, 0 },
538 { "unsigned", RID_UNSIGNED, 0 },
51030405 539 { "using", RID_USING, D_CXXONLY | D_CXXWARN },
540 { "virtual", RID_VIRTUAL, D_CXXONLY | D_CXXWARN },
5c6e5756 541 { "void", RID_VOID, 0 },
542 { "volatile", RID_VOLATILE, 0 },
543 { "wchar_t", RID_WCHAR, D_CXXONLY },
544 { "while", RID_WHILE, 0 },
545 /* These Objective-C keywords are recognized only immediately after
546 an '@'. */
547 { "compatibility_alias", RID_AT_ALIAS, D_OBJC },
548 { "defs", RID_AT_DEFS, D_OBJC },
549 { "encode", RID_AT_ENCODE, D_OBJC },
550 { "end", RID_AT_END, D_OBJC },
551 { "implementation", RID_AT_IMPLEMENTATION, D_OBJC },
552 { "interface", RID_AT_INTERFACE, D_OBJC },
553 { "protocol", RID_AT_PROTOCOL, D_OBJC },
554 { "selector", RID_AT_SELECTOR, D_OBJC },
555 { "finally", RID_AT_FINALLY, D_OBJC },
556 { "synchronized", RID_AT_SYNCHRONIZED, D_OBJC },
069761fb 557 { "optional", RID_AT_OPTIONAL, D_OBJC },
558 { "required", RID_AT_REQUIRED, D_OBJC },
86c110ac 559 { "property", RID_AT_PROPERTY, D_OBJC },
4a8875ed 560 { "package", RID_AT_PACKAGE, D_OBJC },
e1f293c0 561 { "synthesize", RID_AT_SYNTHESIZE, D_OBJC },
562 { "dynamic", RID_AT_DYNAMIC, D_OBJC },
5c6e5756 563 /* These are recognized only in protocol-qualifier context
564 (see above) */
565 { "bycopy", RID_BYCOPY, D_OBJC },
566 { "byref", RID_BYREF, D_OBJC },
567 { "in", RID_IN, D_OBJC },
568 { "inout", RID_INOUT, D_OBJC },
569 { "oneway", RID_ONEWAY, D_OBJC },
570 { "out", RID_OUT, D_OBJC },
86c110ac 571 /* These are recognized inside a property attribute list */
7590f0e5 572 { "assign", RID_ASSIGN, D_OBJC },
573 { "copy", RID_COPY, D_OBJC },
86c110ac 574 { "getter", RID_GETTER, D_OBJC },
7590f0e5 575 { "nonatomic", RID_NONATOMIC, D_OBJC },
576 { "readonly", RID_READONLY, D_OBJC },
577 { "readwrite", RID_READWRITE, D_OBJC },
578 { "retain", RID_RETAIN, D_OBJC },
86c110ac 579 { "setter", RID_SETTER, D_OBJC },
5c6e5756 580};
581
582const unsigned int num_c_common_reswords =
583 sizeof c_common_reswords / sizeof (struct c_common_resword);
584
f8e93a2e 585/* Table of machine-independent attributes common to all C-like languages. */
586const struct attribute_spec c_common_attribute_table[] =
587{
588 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
589 { "packed", 0, 0, false, false, false,
1cae46be 590 handle_packed_attribute },
f8e93a2e 591 { "nocommon", 0, 0, true, false, false,
592 handle_nocommon_attribute },
593 { "common", 0, 0, true, false, false,
594 handle_common_attribute },
595 /* FIXME: logically, noreturn attributes should be listed as
596 "false, true, true" and apply to function types. But implementing this
597 would require all the places in the compiler that use TREE_THIS_VOLATILE
598 on a decl to identify non-returning functions to be located and fixed
599 to check the function type instead. */
600 { "noreturn", 0, 0, true, false, false,
601 handle_noreturn_attribute },
602 { "volatile", 0, 0, true, false, false,
603 handle_noreturn_attribute },
604 { "noinline", 0, 0, true, false, false,
605 handle_noinline_attribute },
bdb1f0d1 606 { "noclone", 0, 0, true, false, false,
607 handle_noclone_attribute },
7bd95dfd 608 { "leaf", 0, 0, true, false, false,
609 handle_leaf_attribute },
f8e93a2e 610 { "always_inline", 0, 0, true, false, false,
611 handle_always_inline_attribute },
541e4101 612 { "gnu_inline", 0, 0, true, false, false,
613 handle_gnu_inline_attribute },
1b16fc45 614 { "artificial", 0, 0, true, false, false,
615 handle_artificial_attribute },
0cdd9887 616 { "flatten", 0, 0, true, false, false,
a0c938f0 617 handle_flatten_attribute },
f8e93a2e 618 { "used", 0, 0, true, false, false,
619 handle_used_attribute },
620 { "unused", 0, 0, false, false, false,
621 handle_unused_attribute },
62eec3b4 622 { "externally_visible", 0, 0, true, false, false,
623 handle_externally_visible_attribute },
f8e93a2e 624 /* The same comments as for noreturn attributes apply to const ones. */
625 { "const", 0, 0, true, false, false,
626 handle_const_attribute },
627 { "transparent_union", 0, 0, false, false, false,
628 handle_transparent_union_attribute },
9af7fd5b 629 { "constructor", 0, 1, true, false, false,
f8e93a2e 630 handle_constructor_attribute },
9af7fd5b 631 { "destructor", 0, 1, true, false, false,
f8e93a2e 632 handle_destructor_attribute },
633 { "mode", 1, 1, false, true, false,
634 handle_mode_attribute },
635 { "section", 1, 1, true, false, false,
636 handle_section_attribute },
637 { "aligned", 0, 1, false, false, false,
638 handle_aligned_attribute },
639 { "weak", 0, 0, true, false, false,
640 handle_weak_attribute },
85c0a25c 641 { "ifunc", 1, 1, true, false, false,
642 handle_ifunc_attribute },
f8e93a2e 643 { "alias", 1, 1, true, false, false,
644 handle_alias_attribute },
f4a30bd7 645 { "weakref", 0, 1, true, false, false,
646 handle_weakref_attribute },
f8e93a2e 647 { "no_instrument_function", 0, 0, true, false, false,
648 handle_no_instrument_function_attribute },
649 { "malloc", 0, 0, true, false, false,
650 handle_malloc_attribute },
26d1c5ff 651 { "returns_twice", 0, 0, true, false, false,
652 handle_returns_twice_attribute },
f8e93a2e 653 { "no_stack_limit", 0, 0, true, false, false,
654 handle_no_limit_stack_attribute },
655 { "pure", 0, 0, true, false, false,
656 handle_pure_attribute },
fc09b200 657 /* For internal use (marking of builtins) only. The name contains space
658 to prevent its usage in source code. */
659 { "no vops", 0, 0, true, false, false,
660 handle_novops_attribute },
45c4e798 661 { "deprecated", 0, 1, false, false, false,
f8e93a2e 662 handle_deprecated_attribute },
663 { "vector_size", 1, 1, false, true, false,
664 handle_vector_size_attribute },
b212f378 665 { "visibility", 1, 1, false, false, false,
f8e93a2e 666 handle_visibility_attribute },
24dfead4 667 { "tls_model", 1, 1, true, false, false,
668 handle_tls_model_attribute },
dbf6c367 669 { "nonnull", 0, -1, false, true, true,
670 handle_nonnull_attribute },
fa987697 671 { "nothrow", 0, 0, true, false, false,
672 handle_nothrow_attribute },
cb59f969 673 { "may_alias", 0, 0, false, true, false, NULL },
7acb29a3 674 { "cleanup", 1, 1, true, false, false,
675 handle_cleanup_attribute },
8a8cdb8d 676 { "warn_unused_result", 0, 0, false, true, true,
677 handle_warn_unused_result_attribute },
50ca527f 678 { "sentinel", 0, 1, false, true, true,
bf6c8de0 679 handle_sentinel_attribute },
b5c26b42 680 /* For internal use (marking of builtins) only. The name contains space
681 to prevent its usage in source code. */
682 { "type generic", 0, 0, false, true, true,
683 handle_type_generic_attribute },
4a29c97c 684 { "alloc_size", 1, 2, false, true, true,
685 handle_alloc_size_attribute },
5de92639 686 { "cold", 0, 0, true, false, false,
687 handle_cold_attribute },
688 { "hot", 0, 0, true, false, false,
689 handle_hot_attribute },
10fc867f 690 { "warning", 1, 1, true, false, false,
691 handle_error_attribute },
692 { "error", 1, 1, true, false, false,
693 handle_error_attribute },
24470055 694 { "target", 1, -1, true, false, false,
695 handle_target_attribute },
46f8e3b0 696 { "optimize", 1, -1, true, false, false,
697 handle_optimize_attribute },
48b14f50 698 { "no_split_stack", 0, 0, true, false, false,
699 handle_no_split_stack_attribute },
8ce86007 700 /* For internal use (marking of builtins and runtime functions) only.
701 The name contains space to prevent its usage in source code. */
702 { "fn spec", 1, 1, false, true, true,
703 handle_fnspec_attribute },
f8e93a2e 704 { NULL, 0, 0, false, false, false, NULL }
705};
706
707/* Give the specifications for the format attributes, used by C and all
d716ce75 708 descendants. */
f8e93a2e 709
710const struct attribute_spec c_common_format_attribute_table[] =
711{
712 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
713 { "format", 3, 3, false, true, true,
714 handle_format_attribute },
715 { "format_arg", 1, 1, false, true, true,
716 handle_format_arg_attribute },
717 { NULL, 0, 0, false, false, false, NULL }
718};
719
6d5d708e 720/* Return identifier for address space AS. */
34208e18 721
6d5d708e 722const char *
723c_addr_space_name (addr_space_t as)
724{
34208e18 725 int rid = RID_FIRST_ADDR_SPACE + as;
726 gcc_assert (ridpointers [rid]);
727 return IDENTIFIER_POINTER (ridpointers [rid]);
6d5d708e 728}
729
2c0e001b 730/* Push current bindings for the function name VAR_DECLS. */
f4e3c278 731
732void
1cae46be 733start_fname_decls (void)
f4e3c278 734{
65b7f83f 735 unsigned ix;
736 tree saved = NULL_TREE;
1cae46be 737
65b7f83f 738 for (ix = 0; fname_vars[ix].decl; ix++)
739 {
740 tree decl = *fname_vars[ix].decl;
f4e3c278 741
65b7f83f 742 if (decl)
743 {
7016c612 744 saved = tree_cons (decl, build_int_cst (NULL_TREE, ix), saved);
65b7f83f 745 *fname_vars[ix].decl = NULL_TREE;
746 }
747 }
748 if (saved || saved_function_name_decls)
749 /* Normally they'll have been NULL, so only push if we've got a
750 stack, or they are non-NULL. */
751 saved_function_name_decls = tree_cons (saved, NULL_TREE,
752 saved_function_name_decls);
753}
754
2363ef00 755/* Finish up the current bindings, adding them into the current function's
756 statement tree. This must be done _before_ finish_stmt_tree is called.
757 If there is no current function, we must be at file scope and no statements
758 are involved. Pop the previous bindings. */
65b7f83f 759
760void
1cae46be 761finish_fname_decls (void)
65b7f83f 762{
763 unsigned ix;
2363ef00 764 tree stmts = NULL_TREE;
65b7f83f 765 tree stack = saved_function_name_decls;
766
767 for (; stack && TREE_VALUE (stack); stack = TREE_CHAIN (stack))
2363ef00 768 append_to_statement_list (TREE_VALUE (stack), &stmts);
1cae46be 769
2363ef00 770 if (stmts)
65b7f83f 771 {
2363ef00 772 tree *bodyp = &DECL_SAVED_TREE (current_function_decl);
5c423bd6 773
2363ef00 774 if (TREE_CODE (*bodyp) == BIND_EXPR)
775 bodyp = &BIND_EXPR_BODY (*bodyp);
81010c97 776
bc2b76e0 777 append_to_statement_list_force (*bodyp, &stmts);
2363ef00 778 *bodyp = stmts;
65b7f83f 779 }
1cae46be 780
65b7f83f 781 for (ix = 0; fname_vars[ix].decl; ix++)
782 *fname_vars[ix].decl = NULL_TREE;
1cae46be 783
65b7f83f 784 if (stack)
f4e3c278 785 {
2c0e001b 786 /* We had saved values, restore them. */
65b7f83f 787 tree saved;
788
789 for (saved = TREE_PURPOSE (stack); saved; saved = TREE_CHAIN (saved))
790 {
791 tree decl = TREE_PURPOSE (saved);
792 unsigned ix = TREE_INT_CST_LOW (TREE_VALUE (saved));
1cae46be 793
65b7f83f 794 *fname_vars[ix].decl = decl;
795 }
796 stack = TREE_CHAIN (stack);
f4e3c278 797 }
65b7f83f 798 saved_function_name_decls = stack;
799}
800
81010c97 801/* Return the text name of the current function, suitably prettified
5fc7fa69 802 by PRETTY_P. Return string must be freed by caller. */
65b7f83f 803
804const char *
1cae46be 805fname_as_string (int pretty_p)
65b7f83f 806{
9ad4bb1e 807 const char *name = "top level";
5fc7fa69 808 char *namep;
8115b8be 809 int vrb = 2, len;
810 cpp_string cstr = { 0, 0 }, strname;
9ad4bb1e 811
84166705 812 if (!pretty_p)
9ad4bb1e 813 {
814 name = "";
815 vrb = 0;
816 }
817
818 if (current_function_decl)
dc24ddbd 819 name = lang_hooks.decl_printable_name (current_function_decl, vrb);
9ad4bb1e 820
8115b8be 821 len = strlen (name) + 3; /* Two for '"'s. One for NULL. */
5fc7fa69 822
8115b8be 823 namep = XNEWVEC (char, len);
824 snprintf (namep, len, "\"%s\"", name);
825 strname.text = (unsigned char *) namep;
826 strname.len = len - 1;
5fc7fa69 827
924bbf02 828 if (cpp_interpret_string (parse_in, &strname, 1, &cstr, CPP_STRING))
8115b8be 829 {
830 XDELETEVEC (namep);
831 return (const char *) cstr.text;
5fc7fa69 832 }
5fc7fa69 833
834 return namep;
65b7f83f 835}
836
65b7f83f 837/* Return the VAR_DECL for a const char array naming the current
838 function. If the VAR_DECL has not yet been created, create it
839 now. RID indicates how it should be formatted and IDENTIFIER_NODE
840 ID is its name (unfortunately C and C++ hold the RID values of
841 keywords in different places, so we can't derive RID from ID in
e3b80d49 842 this language independent code. LOC is the location of the
843 function. */
65b7f83f 844
845tree
e3b80d49 846fname_decl (location_t loc, unsigned int rid, tree id)
65b7f83f 847{
848 unsigned ix;
849 tree decl = NULL_TREE;
850
851 for (ix = 0; fname_vars[ix].decl; ix++)
852 if (fname_vars[ix].rid == rid)
853 break;
854
855 decl = *fname_vars[ix].decl;
856 if (!decl)
f4e3c278 857 {
2222b3c6 858 /* If a tree is built here, it would normally have the lineno of
859 the current statement. Later this tree will be moved to the
860 beginning of the function and this line number will be wrong.
861 To avoid this problem set the lineno to 0 here; that prevents
7299020b 862 it from appearing in the RTL. */
2363ef00 863 tree stmts;
9a6486a6 864 location_t saved_location = input_location;
9a6486a6 865 input_location = UNKNOWN_LOCATION;
1cae46be 866
2363ef00 867 stmts = push_stmt_list ();
e60a6f7b 868 decl = (*make_fname_decl) (loc, id, fname_vars[ix].pretty);
2363ef00 869 stmts = pop_stmt_list (stmts);
870 if (!IS_EMPTY_STMT (stmts))
871 saved_function_name_decls
872 = tree_cons (decl, stmts, saved_function_name_decls);
65b7f83f 873 *fname_vars[ix].decl = decl;
9a6486a6 874 input_location = saved_location;
f4e3c278 875 }
65b7f83f 876 if (!ix && !current_function_decl)
e3b80d49 877 pedwarn (loc, 0, "%qD is not defined outside of function scope", decl);
81010c97 878
65b7f83f 879 return decl;
f4e3c278 880}
881
070236f0 882/* Given a STRING_CST, give it a suitable array-of-chars data type. */
b0fc3e72 883
884tree
1cae46be 885fix_string_type (tree value)
b0fc3e72 886{
070236f0 887 int length = TREE_STRING_LENGTH (value);
888 int nchars;
00d26680 889 tree e_type, i_type, a_type;
890
73be5127 891 /* Compute the number of elements, for the array type. */
924bbf02 892 if (TREE_TYPE (value) == char_array_type_node || !TREE_TYPE (value))
893 {
894 nchars = length;
895 e_type = char_type_node;
896 }
897 else if (TREE_TYPE (value) == char16_array_type_node)
898 {
899 nchars = length / (TYPE_PRECISION (char16_type_node) / BITS_PER_UNIT);
900 e_type = char16_type_node;
901 }
902 else if (TREE_TYPE (value) == char32_array_type_node)
903 {
904 nchars = length / (TYPE_PRECISION (char32_type_node) / BITS_PER_UNIT);
905 e_type = char32_type_node;
906 }
907 else
908 {
909 nchars = length / (TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT);
910 e_type = wchar_type_node;
911 }
b0fc3e72 912
1d752508 913 /* C89 2.2.4.1, C99 5.2.4.1 (Translation limits). The analogous
914 limit in C++98 Annex B is very large (65536) and is not normative,
915 so we do not diagnose it (warn_overlength_strings is forced off
916 in c_common_post_options). */
917 if (warn_overlength_strings)
918 {
919 const int nchars_max = flag_isoc99 ? 4095 : 509;
920 const int relevant_std = flag_isoc99 ? 99 : 90;
921 if (nchars - 1 > nchars_max)
922 /* Translators: The %d after 'ISO C' will be 90 or 99. Do not
923 separate the %d from the 'C'. 'ISO' should not be
924 translated, but it may be moved after 'C%d' in languages
925 where modifiers follow nouns. */
21ca8540 926 pedwarn (input_location, OPT_Woverlength_strings,
8864917d 927 "string length %qd is greater than the length %qd "
1d752508 928 "ISO C%d compilers are required to support",
929 nchars - 1, nchars_max, relevant_std);
930 }
82cfc7f7 931
390be14e 932 /* Create the array type for the string constant. The ISO C++
933 standard says that a string literal has type `const char[N]' or
934 `const wchar_t[N]'. We use the same logic when invoked as a C
935 front-end with -Wwrite-strings.
936 ??? We should change the type of an expression depending on the
937 state of a warning flag. We should just be warning -- see how
938 this is handled in the C++ front-end for the deprecated implicit
939 conversion from string literals to `char*' or `wchar_t*'.
00d26680 940
941 The C++ front end relies on TYPE_MAIN_VARIANT of a cv-qualified
942 array type being the unqualified version of that type.
943 Therefore, if we are constructing an array of const char, we must
944 construct the matching unqualified array type first. The C front
945 end does not require this, but it does no harm, so we do it
946 unconditionally. */
7016c612 947 i_type = build_index_type (build_int_cst (NULL_TREE, nchars - 1));
00d26680 948 a_type = build_array_type (e_type, i_type);
390be14e 949 if (c_dialect_cxx() || warn_write_strings)
aebc8537 950 a_type = c_build_qualified_type (a_type, TYPE_QUAL_CONST);
3a10ba35 951
00d26680 952 TREE_TYPE (value) = a_type;
b8e3b7ad 953 TREE_CONSTANT (value) = 1;
a814bad5 954 TREE_READONLY (value) = 1;
b0fc3e72 955 TREE_STATIC (value) = 1;
956 return value;
957}
958\f
a75b1c71 959/* Fully fold EXPR, an expression that was not folded (beyond integer
960 constant expressions and null pointer constants) when being built
961 up. If IN_INIT, this is in a static initializer and certain
962 changes are made to the folding done. Clear *MAYBE_CONST if
963 MAYBE_CONST is not NULL and EXPR is definitely not a constant
964 expression because it contains an evaluated operator (in C99) or an
965 operator outside of sizeof returning an integer constant (in C90)
966 not permitted in constant expressions, or because it contains an
967 evaluated arithmetic overflow. (*MAYBE_CONST should typically be
968 set to true by callers before calling this function.) Return the
969 folded expression. Function arguments have already been folded
970 before calling this function, as have the contents of SAVE_EXPR,
971 TARGET_EXPR, BIND_EXPR, VA_ARG_EXPR, OBJ_TYPE_REF and
972 C_MAYBE_CONST_EXPR. */
973
974tree
975c_fully_fold (tree expr, bool in_init, bool *maybe_const)
976{
977 tree ret;
c6418a4e 978 tree eptype = NULL_TREE;
a75b1c71 979 bool dummy = true;
980 bool maybe_const_itself = true;
389dd41b 981 location_t loc = EXPR_LOCATION (expr);
a75b1c71 982
983 /* This function is not relevant to C++ because C++ folds while
984 parsing, and may need changes to be correct for C++ when C++
985 stops folding while parsing. */
986 if (c_dialect_cxx ())
987 gcc_unreachable ();
988
989 if (!maybe_const)
990 maybe_const = &dummy;
c6418a4e 991 if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
992 {
993 eptype = TREE_TYPE (expr);
994 expr = TREE_OPERAND (expr, 0);
995 }
a75b1c71 996 ret = c_fully_fold_internal (expr, in_init, maybe_const,
997 &maybe_const_itself);
c6418a4e 998 if (eptype)
389dd41b 999 ret = fold_convert_loc (loc, eptype, ret);
a75b1c71 1000 *maybe_const &= maybe_const_itself;
1001 return ret;
1002}
1003
1004/* Internal helper for c_fully_fold. EXPR and IN_INIT are as for
1005 c_fully_fold. *MAYBE_CONST_OPERANDS is cleared because of operands
1006 not permitted, while *MAYBE_CONST_ITSELF is cleared because of
1007 arithmetic overflow (for C90, *MAYBE_CONST_OPERANDS is carried from
1008 both evaluated and unevaluated subexpressions while
1009 *MAYBE_CONST_ITSELF is carried from only evaluated
1010 subexpressions). */
1011
1012static tree
1013c_fully_fold_internal (tree expr, bool in_init, bool *maybe_const_operands,
1014 bool *maybe_const_itself)
1015{
1016 tree ret = expr;
1017 enum tree_code code = TREE_CODE (expr);
1018 enum tree_code_class kind = TREE_CODE_CLASS (code);
1019 location_t loc = EXPR_LOCATION (expr);
1020 tree op0, op1, op2, op3;
1021 tree orig_op0, orig_op1, orig_op2;
1022 bool op0_const = true, op1_const = true, op2_const = true;
1023 bool op0_const_self = true, op1_const_self = true, op2_const_self = true;
1024 bool nowarning = TREE_NO_WARNING (expr);
672d914b 1025 int unused_p;
a75b1c71 1026
1027 /* This function is not relevant to C++ because C++ folds while
1028 parsing, and may need changes to be correct for C++ when C++
1029 stops folding while parsing. */
1030 if (c_dialect_cxx ())
1031 gcc_unreachable ();
1032
1033 /* Constants, declarations, statements, errors, SAVE_EXPRs and
1034 anything else not counted as an expression cannot usefully be
1035 folded further at this point. */
1036 if (!IS_EXPR_CODE_CLASS (kind)
1037 || kind == tcc_statement
1038 || code == SAVE_EXPR)
1039 return expr;
1040
1041 /* Operands of variable-length expressions (function calls) have
1042 already been folded, as have __builtin_* function calls, and such
1043 expressions cannot occur in constant expressions. */
1044 if (kind == tcc_vl_exp)
1045 {
1046 *maybe_const_operands = false;
1047 ret = fold (expr);
1048 goto out;
1049 }
1050
1051 if (code == C_MAYBE_CONST_EXPR)
1052 {
1053 tree pre = C_MAYBE_CONST_EXPR_PRE (expr);
1054 tree inner = C_MAYBE_CONST_EXPR_EXPR (expr);
1055 if (C_MAYBE_CONST_EXPR_NON_CONST (expr))
1056 *maybe_const_operands = false;
1057 if (C_MAYBE_CONST_EXPR_INT_OPERANDS (expr))
1058 *maybe_const_itself = false;
1059 if (pre && !in_init)
1060 ret = build2 (COMPOUND_EXPR, TREE_TYPE (expr), pre, inner);
1061 else
1062 ret = inner;
1063 goto out;
1064 }
1065
1066 /* Assignment, increment, decrement, function call and comma
1067 operators, and statement expressions, cannot occur in constant
1068 expressions if evaluated / outside of sizeof. (Function calls
1069 were handled above, though VA_ARG_EXPR is treated like a function
1070 call here, and statement expressions are handled through
1071 C_MAYBE_CONST_EXPR to avoid folding inside them.) */
1072 switch (code)
1073 {
1074 case MODIFY_EXPR:
1075 case PREDECREMENT_EXPR:
1076 case PREINCREMENT_EXPR:
1077 case POSTDECREMENT_EXPR:
1078 case POSTINCREMENT_EXPR:
1079 case COMPOUND_EXPR:
1080 *maybe_const_operands = false;
1081 break;
1082
1083 case VA_ARG_EXPR:
1084 case TARGET_EXPR:
1085 case BIND_EXPR:
1086 case OBJ_TYPE_REF:
1087 *maybe_const_operands = false;
1088 ret = fold (expr);
1089 goto out;
1090
1091 default:
1092 break;
1093 }
1094
1095 /* Fold individual tree codes as appropriate. */
1096 switch (code)
1097 {
1098 case COMPOUND_LITERAL_EXPR:
1099 /* Any non-constancy will have been marked in a containing
1100 C_MAYBE_CONST_EXPR; there is no more folding to do here. */
1101 goto out;
1102
1103 case COMPONENT_REF:
1104 orig_op0 = op0 = TREE_OPERAND (expr, 0);
1105 op1 = TREE_OPERAND (expr, 1);
1106 op2 = TREE_OPERAND (expr, 2);
1107 op0 = c_fully_fold_internal (op0, in_init, maybe_const_operands,
1108 maybe_const_itself);
f59e3889 1109 STRIP_TYPE_NOPS (op0);
a75b1c71 1110 if (op0 != orig_op0)
1111 ret = build3 (COMPONENT_REF, TREE_TYPE (expr), op0, op1, op2);
1112 if (ret != expr)
1113 {
1114 TREE_READONLY (ret) = TREE_READONLY (expr);
1115 TREE_THIS_VOLATILE (ret) = TREE_THIS_VOLATILE (expr);
1116 }
1117 goto out;
1118
1119 case ARRAY_REF:
1120 orig_op0 = op0 = TREE_OPERAND (expr, 0);
1121 orig_op1 = op1 = TREE_OPERAND (expr, 1);
1122 op2 = TREE_OPERAND (expr, 2);
1123 op3 = TREE_OPERAND (expr, 3);
1124 op0 = c_fully_fold_internal (op0, in_init, maybe_const_operands,
1125 maybe_const_itself);
f59e3889 1126 STRIP_TYPE_NOPS (op0);
a75b1c71 1127 op1 = c_fully_fold_internal (op1, in_init, maybe_const_operands,
1128 maybe_const_itself);
f59e3889 1129 STRIP_TYPE_NOPS (op1);
a75b1c71 1130 op1 = decl_constant_value_for_optimization (op1);
1131 if (op0 != orig_op0 || op1 != orig_op1)
1132 ret = build4 (ARRAY_REF, TREE_TYPE (expr), op0, op1, op2, op3);
1133 if (ret != expr)
1134 {
1135 TREE_READONLY (ret) = TREE_READONLY (expr);
1136 TREE_SIDE_EFFECTS (ret) = TREE_SIDE_EFFECTS (expr);
1137 TREE_THIS_VOLATILE (ret) = TREE_THIS_VOLATILE (expr);
1138 }
1139 ret = fold (ret);
1140 goto out;
1141
1142 case COMPOUND_EXPR:
1143 case MODIFY_EXPR:
1144 case PREDECREMENT_EXPR:
1145 case PREINCREMENT_EXPR:
1146 case POSTDECREMENT_EXPR:
1147 case POSTINCREMENT_EXPR:
1148 case PLUS_EXPR:
1149 case MINUS_EXPR:
1150 case MULT_EXPR:
1151 case POINTER_PLUS_EXPR:
1152 case TRUNC_DIV_EXPR:
1153 case CEIL_DIV_EXPR:
1154 case FLOOR_DIV_EXPR:
1155 case TRUNC_MOD_EXPR:
1156 case RDIV_EXPR:
1157 case EXACT_DIV_EXPR:
1158 case LSHIFT_EXPR:
1159 case RSHIFT_EXPR:
1160 case BIT_IOR_EXPR:
1161 case BIT_XOR_EXPR:
1162 case BIT_AND_EXPR:
1163 case LT_EXPR:
1164 case LE_EXPR:
1165 case GT_EXPR:
1166 case GE_EXPR:
1167 case EQ_EXPR:
1168 case NE_EXPR:
1169 case COMPLEX_EXPR:
1170 case TRUTH_AND_EXPR:
1171 case TRUTH_OR_EXPR:
1172 case TRUTH_XOR_EXPR:
1173 case UNORDERED_EXPR:
1174 case ORDERED_EXPR:
1175 case UNLT_EXPR:
1176 case UNLE_EXPR:
1177 case UNGT_EXPR:
1178 case UNGE_EXPR:
1179 case UNEQ_EXPR:
1180 /* Binary operations evaluating both arguments (increment and
1181 decrement are binary internally in GCC). */
1182 orig_op0 = op0 = TREE_OPERAND (expr, 0);
1183 orig_op1 = op1 = TREE_OPERAND (expr, 1);
1184 op0 = c_fully_fold_internal (op0, in_init, maybe_const_operands,
1185 maybe_const_itself);
f59e3889 1186 STRIP_TYPE_NOPS (op0);
a75b1c71 1187 if (code != MODIFY_EXPR
1188 && code != PREDECREMENT_EXPR
1189 && code != PREINCREMENT_EXPR
1190 && code != POSTDECREMENT_EXPR
1191 && code != POSTINCREMENT_EXPR)
1192 op0 = decl_constant_value_for_optimization (op0);
1193 /* The RHS of a MODIFY_EXPR was fully folded when building that
1194 expression for the sake of conversion warnings. */
1195 if (code != MODIFY_EXPR)
1196 op1 = c_fully_fold_internal (op1, in_init, maybe_const_operands,
1197 maybe_const_itself);
f59e3889 1198 STRIP_TYPE_NOPS (op1);
a75b1c71 1199 op1 = decl_constant_value_for_optimization (op1);
1200 if (op0 != orig_op0 || op1 != orig_op1 || in_init)
1201 ret = in_init
389dd41b 1202 ? fold_build2_initializer_loc (loc, code, TREE_TYPE (expr), op0, op1)
1203 : fold_build2_loc (loc, code, TREE_TYPE (expr), op0, op1);
a75b1c71 1204 else
1205 ret = fold (expr);
672d914b 1206 if (TREE_OVERFLOW_P (ret)
1207 && !TREE_OVERFLOW_P (op0)
1208 && !TREE_OVERFLOW_P (op1))
1209 overflow_warning (EXPR_LOCATION (expr), ret);
a75b1c71 1210 goto out;
1211
1212 case INDIRECT_REF:
1213 case FIX_TRUNC_EXPR:
1214 case FLOAT_EXPR:
1215 CASE_CONVERT:
1216 case NON_LVALUE_EXPR:
1217 case NEGATE_EXPR:
1218 case BIT_NOT_EXPR:
1219 case TRUTH_NOT_EXPR:
1220 case ADDR_EXPR:
1221 case CONJ_EXPR:
1222 case REALPART_EXPR:
1223 case IMAGPART_EXPR:
1224 /* Unary operations. */
1225 orig_op0 = op0 = TREE_OPERAND (expr, 0);
1226 op0 = c_fully_fold_internal (op0, in_init, maybe_const_operands,
1227 maybe_const_itself);
f59e3889 1228 STRIP_TYPE_NOPS (op0);
a75b1c71 1229 if (code != ADDR_EXPR && code != REALPART_EXPR && code != IMAGPART_EXPR)
1230 op0 = decl_constant_value_for_optimization (op0);
1231 if (op0 != orig_op0 || in_init)
1232 ret = in_init
389dd41b 1233 ? fold_build1_initializer_loc (loc, code, TREE_TYPE (expr), op0)
1234 : fold_build1_loc (loc, code, TREE_TYPE (expr), op0);
a75b1c71 1235 else
1236 ret = fold (expr);
1237 if (code == INDIRECT_REF
1238 && ret != expr
1239 && TREE_CODE (ret) == INDIRECT_REF)
1240 {
1241 TREE_READONLY (ret) = TREE_READONLY (expr);
1242 TREE_SIDE_EFFECTS (ret) = TREE_SIDE_EFFECTS (expr);
1243 TREE_THIS_VOLATILE (ret) = TREE_THIS_VOLATILE (expr);
1244 }
672d914b 1245 switch (code)
1246 {
1247 case FIX_TRUNC_EXPR:
1248 case FLOAT_EXPR:
1249 CASE_CONVERT:
1250 /* Don't warn about explicit conversions. We will already
1251 have warned about suspect implicit conversions. */
1252 break;
1253
1254 default:
1255 if (TREE_OVERFLOW_P (ret) && !TREE_OVERFLOW_P (op0))
1256 overflow_warning (EXPR_LOCATION (expr), ret);
1257 break;
1258 }
a75b1c71 1259 goto out;
1260
1261 case TRUTH_ANDIF_EXPR:
1262 case TRUTH_ORIF_EXPR:
1263 /* Binary operations not necessarily evaluating both
1264 arguments. */
1265 orig_op0 = op0 = TREE_OPERAND (expr, 0);
1266 orig_op1 = op1 = TREE_OPERAND (expr, 1);
1267 op0 = c_fully_fold_internal (op0, in_init, &op0_const, &op0_const_self);
f59e3889 1268 STRIP_TYPE_NOPS (op0);
672d914b 1269
1270 unused_p = (op0 == (code == TRUTH_ANDIF_EXPR
1271 ? truthvalue_false_node
1272 : truthvalue_true_node));
1273 c_inhibit_evaluation_warnings += unused_p;
a75b1c71 1274 op1 = c_fully_fold_internal (op1, in_init, &op1_const, &op1_const_self);
f59e3889 1275 STRIP_TYPE_NOPS (op1);
672d914b 1276 c_inhibit_evaluation_warnings -= unused_p;
1277
a75b1c71 1278 if (op0 != orig_op0 || op1 != orig_op1 || in_init)
1279 ret = in_init
389dd41b 1280 ? fold_build2_initializer_loc (loc, code, TREE_TYPE (expr), op0, op1)
1281 : fold_build2_loc (loc, code, TREE_TYPE (expr), op0, op1);
a75b1c71 1282 else
1283 ret = fold (expr);
1284 *maybe_const_operands &= op0_const;
1285 *maybe_const_itself &= op0_const_self;
1286 if (!(flag_isoc99
1287 && op0_const
1288 && op0_const_self
1289 && (code == TRUTH_ANDIF_EXPR
1290 ? op0 == truthvalue_false_node
1291 : op0 == truthvalue_true_node)))
1292 *maybe_const_operands &= op1_const;
1293 if (!(op0_const
1294 && op0_const_self
1295 && (code == TRUTH_ANDIF_EXPR
1296 ? op0 == truthvalue_false_node
1297 : op0 == truthvalue_true_node)))
1298 *maybe_const_itself &= op1_const_self;
1299 goto out;
1300
1301 case COND_EXPR:
1302 orig_op0 = op0 = TREE_OPERAND (expr, 0);
1303 orig_op1 = op1 = TREE_OPERAND (expr, 1);
1304 orig_op2 = op2 = TREE_OPERAND (expr, 2);
1305 op0 = c_fully_fold_internal (op0, in_init, &op0_const, &op0_const_self);
672d914b 1306
f59e3889 1307 STRIP_TYPE_NOPS (op0);
672d914b 1308 c_inhibit_evaluation_warnings += (op0 == truthvalue_false_node);
a75b1c71 1309 op1 = c_fully_fold_internal (op1, in_init, &op1_const, &op1_const_self);
f59e3889 1310 STRIP_TYPE_NOPS (op1);
672d914b 1311 c_inhibit_evaluation_warnings -= (op0 == truthvalue_false_node);
1312
1313 c_inhibit_evaluation_warnings += (op0 == truthvalue_true_node);
a75b1c71 1314 op2 = c_fully_fold_internal (op2, in_init, &op2_const, &op2_const_self);
f59e3889 1315 STRIP_TYPE_NOPS (op2);
672d914b 1316 c_inhibit_evaluation_warnings -= (op0 == truthvalue_true_node);
1317
a75b1c71 1318 if (op0 != orig_op0 || op1 != orig_op1 || op2 != orig_op2)
389dd41b 1319 ret = fold_build3_loc (loc, code, TREE_TYPE (expr), op0, op1, op2);
a75b1c71 1320 else
1321 ret = fold (expr);
1322 *maybe_const_operands &= op0_const;
1323 *maybe_const_itself &= op0_const_self;
1324 if (!(flag_isoc99
1325 && op0_const
1326 && op0_const_self
1327 && op0 == truthvalue_false_node))
1328 *maybe_const_operands &= op1_const;
1329 if (!(op0_const
1330 && op0_const_self
1331 && op0 == truthvalue_false_node))
1332 *maybe_const_itself &= op1_const_self;
1333 if (!(flag_isoc99
1334 && op0_const
1335 && op0_const_self
1336 && op0 == truthvalue_true_node))
1337 *maybe_const_operands &= op2_const;
1338 if (!(op0_const
1339 && op0_const_self
1340 && op0 == truthvalue_true_node))
1341 *maybe_const_itself &= op2_const_self;
1342 goto out;
1343
c6418a4e 1344 case EXCESS_PRECISION_EXPR:
1345 /* Each case where an operand with excess precision may be
1346 encountered must remove the EXCESS_PRECISION_EXPR around
1347 inner operands and possibly put one around the whole
1348 expression or possibly convert to the semantic type (which
1349 c_fully_fold does); we cannot tell at this stage which is
1350 appropriate in any particular case. */
1351 gcc_unreachable ();
1352
a75b1c71 1353 default:
1354 /* Various codes may appear through folding built-in functions
1355 and their arguments. */
1356 goto out;
1357 }
1358
1359 out:
1360 /* Some folding may introduce NON_LVALUE_EXPRs; all lvalue checks
1361 have been done by this point, so remove them again. */
1362 nowarning |= TREE_NO_WARNING (ret);
1363 STRIP_TYPE_NOPS (ret);
1364 if (nowarning && !TREE_NO_WARNING (ret))
1365 {
1366 if (!CAN_HAVE_LOCATION_P (ret))
1367 ret = build1 (NOP_EXPR, TREE_TYPE (ret), ret);
1368 TREE_NO_WARNING (ret) = 1;
1369 }
1370 if (ret != expr)
1371 protected_set_expr_location (ret, loc);
1372 return ret;
1373}
1374
1375/* If not optimizing, EXP is not a VAR_DECL, or EXP has array type,
1376 return EXP. Otherwise, return either EXP or its known constant
1377 value (if it has one), but return EXP if EXP has mode BLKmode. ???
1378 Is the BLKmode test appropriate? */
1379
1380tree
1381decl_constant_value_for_optimization (tree exp)
1382{
1383 tree ret;
1384
1385 /* This function is only used by C, for c_fully_fold and other
1386 optimization, and may not be correct for C++. */
1387 if (c_dialect_cxx ())
1388 gcc_unreachable ();
1389
1390 if (!optimize
1391 || TREE_CODE (exp) != VAR_DECL
1392 || TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
1393 || DECL_MODE (exp) == BLKmode)
1394 return exp;
1395
1396 ret = decl_constant_value (exp);
1397 /* Avoid unwanted tree sharing between the initializer and current
1398 function's body where the tree can be modified e.g. by the
1399 gimplifier. */
1400 if (ret != exp && TREE_STATIC (exp))
1401 ret = unshare_expr (ret);
1402 return ret;
1403}
1404
2a1736ed 1405/* Print a warning if a constant expression had overflow in folding.
1406 Invoke this function on every expression that the language
1407 requires to be a constant expression.
1408 Note the ANSI C standard says it is erroneous for a
1409 constant expression to overflow. */
b2806639 1410
1411void
1cae46be 1412constant_expression_warning (tree value)
07317e69 1413{
48e1416a 1414 if (warn_overflow && pedantic
07317e69 1415 && (TREE_CODE (value) == INTEGER_CST || TREE_CODE (value) == REAL_CST
1416 || TREE_CODE (value) == FIXED_CST
1417 || TREE_CODE (value) == VECTOR_CST
1418 || TREE_CODE (value) == COMPLEX_CST)
1419 && TREE_OVERFLOW (value))
21ca8540 1420 pedwarn (input_location, OPT_Woverflow, "overflow in constant expression");
07317e69 1421}
1422
1423/* The same as above but print an unconditional error. */
1424void
1425constant_expression_error (tree value)
b2806639 1426{
837e1122 1427 if ((TREE_CODE (value) == INTEGER_CST || TREE_CODE (value) == REAL_CST
9421ebb9 1428 || TREE_CODE (value) == FIXED_CST
886cfd4f 1429 || TREE_CODE (value) == VECTOR_CST
837e1122 1430 || TREE_CODE (value) == COMPLEX_CST)
07317e69 1431 && TREE_OVERFLOW (value))
1432 error ("overflow in constant expression");
2a1736ed 1433}
1434
f170d67f 1435/* Print a warning if an expression had overflow in folding and its
1436 operands hadn't.
1437
2a1736ed 1438 Invoke this function on every expression that
1439 (1) appears in the source code, and
f170d67f 1440 (2) is a constant expression that overflowed, and
2a1736ed 1441 (3) is not already checked by convert_and_check;
f170d67f 1442 however, do not invoke this function on operands of explicit casts
1443 or when the expression is the result of an operator and any operand
1444 already overflowed. */
2a1736ed 1445
1446void
e60a6f7b 1447overflow_warning (location_t loc, tree value)
2a1736ed 1448{
48d94ede 1449 if (c_inhibit_evaluation_warnings != 0)
1450 return;
f170d67f 1451
1452 switch (TREE_CODE (value))
886cfd4f 1453 {
f170d67f 1454 case INTEGER_CST:
e60a6f7b 1455 warning_at (loc, OPT_Woverflow, "integer overflow in expression");
f170d67f 1456 break;
48e1416a 1457
f170d67f 1458 case REAL_CST:
e60a6f7b 1459 warning_at (loc, OPT_Woverflow,
1460 "floating point overflow in expression");
f170d67f 1461 break;
48e1416a 1462
9421ebb9 1463 case FIXED_CST:
e60a6f7b 1464 warning_at (loc, OPT_Woverflow, "fixed-point overflow in expression");
9421ebb9 1465 break;
1466
f170d67f 1467 case VECTOR_CST:
e60a6f7b 1468 warning_at (loc, OPT_Woverflow, "vector overflow in expression");
f170d67f 1469 break;
48e1416a 1470
f170d67f 1471 case COMPLEX_CST:
1472 if (TREE_CODE (TREE_REALPART (value)) == INTEGER_CST)
e60a6f7b 1473 warning_at (loc, OPT_Woverflow,
1474 "complex integer overflow in expression");
f170d67f 1475 else if (TREE_CODE (TREE_REALPART (value)) == REAL_CST)
e60a6f7b 1476 warning_at (loc, OPT_Woverflow,
1477 "complex floating point overflow in expression");
f170d67f 1478 break;
1479
1480 default:
1481 break;
886cfd4f 1482 }
2a1736ed 1483}
1484
03033af4 1485/* Warn about uses of logical || / && operator in a context where it
1486 is likely that the bitwise equivalent was intended by the
1487 programmer. We have seen an expression in which CODE is a binary
9c20c4fc 1488 operator used to combine expressions OP_LEFT and OP_RIGHT, which before folding
1489 had CODE_LEFT and CODE_RIGHT, into an expression of type TYPE. */
b13d1547 1490void
9c20c4fc 1491warn_logical_operator (location_t location, enum tree_code code, tree type,
48e1416a 1492 enum tree_code code_left, tree op_left,
03033af4 1493 enum tree_code ARG_UNUSED (code_right), tree op_right)
b13d1547 1494{
9c20c4fc 1495 int or_op = (code == TRUTH_ORIF_EXPR || code == TRUTH_OR_EXPR);
1496 int in0_p, in1_p, in_p;
1497 tree low0, low1, low, high0, high1, high, lhs, rhs, tem;
1498 bool strict_overflow_p = false;
1499
03033af4 1500 if (code != TRUTH_ANDIF_EXPR
1501 && code != TRUTH_AND_EXPR
1502 && code != TRUTH_ORIF_EXPR
1503 && code != TRUTH_OR_EXPR)
1504 return;
1505
1506 /* Warn if &&/|| are being used in a context where it is
1507 likely that the bitwise equivalent was intended by the
1508 programmer. That is, an expression such as op && MASK
1509 where op should not be any boolean expression, nor a
1510 constant, and mask seems to be a non-boolean integer constant. */
1511 if (!truth_value_p (code_left)
1512 && INTEGRAL_TYPE_P (TREE_TYPE (op_left))
1513 && !CONSTANT_CLASS_P (op_left)
1514 && !TREE_NO_WARNING (op_left)
1515 && TREE_CODE (op_right) == INTEGER_CST
1516 && !integer_zerop (op_right)
1517 && !integer_onep (op_right))
b13d1547 1518 {
9c20c4fc 1519 if (or_op)
03033af4 1520 warning_at (location, OPT_Wlogical_op, "logical %<or%>"
1521 " applied to non-boolean constant");
1522 else
1523 warning_at (location, OPT_Wlogical_op, "logical %<and%>"
1524 " applied to non-boolean constant");
1525 TREE_NO_WARNING (op_left) = true;
9c20c4fc 1526 return;
1527 }
1528
1529 /* We do not warn for constants because they are typical of macro
1530 expansions that test for features. */
1531 if (CONSTANT_CLASS_P (op_left) || CONSTANT_CLASS_P (op_right))
1532 return;
1533
1534 /* This warning only makes sense with logical operands. */
1535 if (!(truth_value_p (TREE_CODE (op_left))
1536 || INTEGRAL_TYPE_P (TREE_TYPE (op_left)))
1537 || !(truth_value_p (TREE_CODE (op_right))
1538 || INTEGRAL_TYPE_P (TREE_TYPE (op_right))))
1539 return;
1540
1541 lhs = make_range (op_left, &in0_p, &low0, &high0, &strict_overflow_p);
1542 rhs = make_range (op_right, &in1_p, &low1, &high1, &strict_overflow_p);
1543
1544 if (lhs && TREE_CODE (lhs) == C_MAYBE_CONST_EXPR)
1545 lhs = C_MAYBE_CONST_EXPR_EXPR (lhs);
1546
1547 if (rhs && TREE_CODE (rhs) == C_MAYBE_CONST_EXPR)
1548 rhs = C_MAYBE_CONST_EXPR_EXPR (rhs);
48e1416a 1549
9c20c4fc 1550 /* If this is an OR operation, invert both sides; we will invert
1551 again at the end. */
1552 if (or_op)
1553 in0_p = !in0_p, in1_p = !in1_p;
48e1416a 1554
9c20c4fc 1555 /* If both expressions are the same, if we can merge the ranges, and we
0969aa9b 1556 can build the range test, return it or it inverted. */
1557 if (lhs && rhs && operand_equal_p (lhs, rhs, 0)
9c20c4fc 1558 && merge_ranges (&in_p, &low, &high, in0_p, low0, high0,
1559 in1_p, low1, high1)
389dd41b 1560 && 0 != (tem = build_range_check (UNKNOWN_LOCATION,
1561 type, lhs, in_p, low, high)))
9c20c4fc 1562 {
1563 if (TREE_CODE (tem) != INTEGER_CST)
1564 return;
1565
1566 if (or_op)
1567 warning_at (location, OPT_Wlogical_op,
1568 "logical %<or%> "
1569 "of collectively exhaustive tests is always true");
1570 else
1571 warning_at (location, OPT_Wlogical_op,
1572 "logical %<and%> "
1573 "of mutually exclusive tests is always false");
b13d1547 1574 }
1575}
1576
1577
bcf22371 1578/* Print a warning about casts that might indicate violation
1579 of strict aliasing rules if -Wstrict-aliasing is used and
1e31ff37 1580 strict aliasing mode is in effect. OTYPE is the original
1581 TREE_TYPE of EXPR, and TYPE the type we're casting to. */
bcf22371 1582
e6fa0ea6 1583bool
1e31ff37 1584strict_aliasing_warning (tree otype, tree type, tree expr)
bcf22371 1585{
45bb3afb 1586 /* Strip pointer conversion chains and get to the correct original type. */
1587 STRIP_NOPS (expr);
1588 otype = TREE_TYPE (expr);
1589
f06537f2 1590 if (!(flag_strict_aliasing
1591 && POINTER_TYPE_P (type)
1592 && POINTER_TYPE_P (otype)
1593 && !VOID_TYPE_P (TREE_TYPE (type)))
1594 /* If the type we are casting to is a ref-all pointer
1595 dereferencing it is always valid. */
1596 || TYPE_REF_CAN_ALIAS_ALL (type))
e6fa0ea6 1597 return false;
1598
1599 if ((warn_strict_aliasing > 1) && TREE_CODE (expr) == ADDR_EXPR
bcf22371 1600 && (DECL_P (TREE_OPERAND (expr, 0))
e6fa0ea6 1601 || handled_component_p (TREE_OPERAND (expr, 0))))
bcf22371 1602 {
1603 /* Casting the address of an object to non void pointer. Warn
1604 if the cast breaks type based aliasing. */
e6fa0ea6 1605 if (!COMPLETE_TYPE_P (TREE_TYPE (type)) && warn_strict_aliasing == 2)
1606 {
1607 warning (OPT_Wstrict_aliasing, "type-punning to incomplete type "
1608 "might break strict-aliasing rules");
1609 return true;
1610 }
bcf22371 1611 else
1612 {
48e1416a 1613 /* warn_strict_aliasing >= 3. This includes the default (3).
e6fa0ea6 1614 Only warn if the cast is dereferenced immediately. */
32c2fdea 1615 alias_set_type set1 =
e6fa0ea6 1616 get_alias_set (TREE_TYPE (TREE_OPERAND (expr, 0)));
32c2fdea 1617 alias_set_type set2 = get_alias_set (TREE_TYPE (type));
bcf22371 1618
62d823d0 1619 if (set1 != set2 && set2 != 0
1620 && (set1 == 0 || !alias_sets_conflict_p (set1, set2)))
e6fa0ea6 1621 {
1622 warning (OPT_Wstrict_aliasing, "dereferencing type-punned "
1623 "pointer will break strict-aliasing rules");
1624 return true;
1625 }
1626 else if (warn_strict_aliasing == 2
879f881c 1627 && !alias_sets_must_conflict_p (set1, set2))
e6fa0ea6 1628 {
1629 warning (OPT_Wstrict_aliasing, "dereferencing type-punned "
1630 "pointer might break strict-aliasing rules");
1631 return true;
1632 }
bcf22371 1633 }
1634 }
e6fa0ea6 1635 else
1636 if ((warn_strict_aliasing == 1) && !VOID_TYPE_P (TREE_TYPE (otype)))
1637 {
1638 /* At this level, warn for any conversions, even if an address is
1639 not taken in the same statement. This will likely produce many
1640 false positives, but could be useful to pinpoint problems that
1641 are not revealed at higher levels. */
32c2fdea 1642 alias_set_type set1 = get_alias_set (TREE_TYPE (otype));
1643 alias_set_type set2 = get_alias_set (TREE_TYPE (type));
1644 if (!COMPLETE_TYPE_P (type)
879f881c 1645 || !alias_sets_must_conflict_p (set1, set2))
e6fa0ea6 1646 {
1647 warning (OPT_Wstrict_aliasing, "dereferencing type-punned "
1648 "pointer might break strict-aliasing rules");
1649 return true;
1650 }
1651 }
1652
1653 return false;
bcf22371 1654}
1655
3f08e399 1656/* Warn for unlikely, improbable, or stupid DECL declarations
1657 of `main'. */
1658
1659void
1660check_main_parameter_types (tree decl)
1661{
1662 tree args;
1663 int argct = 0;
1664
1665 for (args = TYPE_ARG_TYPES (TREE_TYPE (decl)); args;
1666 args = TREE_CHAIN (args))
1667 {
1668 tree type = args ? TREE_VALUE (args) : 0;
1669
7accad14 1670 if (type == void_type_node || type == error_mark_node )
3f08e399 1671 break;
1672
1673 ++argct;
1674 switch (argct)
1675 {
1676 case 1:
1677 if (TYPE_MAIN_VARIANT (type) != integer_type_node)
48e1416a 1678 pedwarn (input_location, OPT_Wmain, "first argument of %q+D should be %<int%>",
23efcc02 1679 decl);
3f08e399 1680 break;
1681
1682 case 2:
1683 if (TREE_CODE (type) != POINTER_TYPE
1684 || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
1685 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
1686 != char_type_node))
21ca8540 1687 pedwarn (input_location, OPT_Wmain, "second argument of %q+D should be %<char **%>",
23efcc02 1688 decl);
3f08e399 1689 break;
1690
1691 case 3:
1692 if (TREE_CODE (type) != POINTER_TYPE
1693 || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
1694 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
1695 != char_type_node))
21ca8540 1696 pedwarn (input_location, OPT_Wmain, "third argument of %q+D should probably be "
23efcc02 1697 "%<char **%>", decl);
3f08e399 1698 break;
1699 }
1700 }
1701
1702 /* It is intentional that this message does not mention the third
1703 argument because it's only mentioned in an appendix of the
1704 standard. */
1705 if (argct > 0 && (argct < 2 || argct > 3))
21ca8540 1706 pedwarn (input_location, OPT_Wmain, "%q+D takes only zero or two arguments", decl);
3f08e399 1707}
1708
ed7c4e62 1709/* True if pointers to distinct types T1 and T2 can be converted to
1710 each other without an explicit cast. Only returns true for opaque
1711 vector types. */
1712bool
1713vector_targets_convertible_p (const_tree t1, const_tree t2)
1714{
1715 if (TREE_CODE (t1) == VECTOR_TYPE && TREE_CODE (t2) == VECTOR_TYPE
8d125f7d 1716 && (TYPE_VECTOR_OPAQUE (t1) || TYPE_VECTOR_OPAQUE (t2))
ed7c4e62 1717 && tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2)))
1718 return true;
1719
1720 return false;
1721}
1722
546c4794 1723/* True if vector types T1 and T2 can be converted to each other
1724 without an explicit cast. If EMIT_LAX_NOTE is true, and T1 and T2
1725 can only be converted with -flax-vector-conversions yet that is not
1726 in effect, emit a note telling the user about that option if such
1727 a note has not previously been emitted. */
1728bool
9f627b1a 1729vector_types_convertible_p (const_tree t1, const_tree t2, bool emit_lax_note)
8b4b9810 1730{
546c4794 1731 static bool emitted_lax_note = false;
ae6db8ab 1732 bool convertible_lax;
1733
8d125f7d 1734 if ((TYPE_VECTOR_OPAQUE (t1) || TYPE_VECTOR_OPAQUE (t2))
ae6db8ab 1735 && tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2)))
1736 return true;
1737
1738 convertible_lax =
1739 (tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2))
1740 && (TREE_CODE (TREE_TYPE (t1)) != REAL_TYPE ||
1741 TYPE_PRECISION (t1) == TYPE_PRECISION (t2))
1742 && (INTEGRAL_TYPE_P (TREE_TYPE (t1))
1743 == INTEGRAL_TYPE_P (TREE_TYPE (t2))));
546c4794 1744
1745 if (!convertible_lax || flag_lax_vector_conversions)
1746 return convertible_lax;
1747
1748 if (TYPE_VECTOR_SUBPARTS (t1) == TYPE_VECTOR_SUBPARTS (t2)
29f51994 1749 && lang_hooks.types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2)))
546c4794 1750 return true;
1751
1752 if (emit_lax_note && !emitted_lax_note)
1753 {
1754 emitted_lax_note = true;
5bcc316e 1755 inform (input_location, "use -flax-vector-conversions to permit "
546c4794 1756 "conversions between vectors with differing "
1757 "element types or numbers of subparts");
1758 }
1759
1760 return false;
8b4b9810 1761}
1762
2561cea2 1763/* This is a helper function of build_binary_op.
1764
1765 For certain operations if both args were extended from the same
1766 smaller type, do the arithmetic in that type and then extend.
1767
1768 BITWISE indicates a bitwise operation.
1769 For them, this optimization is safe only if
1770 both args are zero-extended or both are sign-extended.
1771 Otherwise, we might change the result.
1772 Eg, (short)-1 | (unsigned short)-1 is (int)-1
48e1416a 1773 but calculated in (unsigned short) it would be (unsigned short)-1.
2561cea2 1774*/
1775tree shorten_binary_op (tree result_type, tree op0, tree op1, bool bitwise)
1776{
1777 int unsigned0, unsigned1;
1778 tree arg0, arg1;
1779 int uns;
1780 tree type;
1781
1782 /* Cast OP0 and OP1 to RESULT_TYPE. Doing so prevents
1783 excessive narrowing when we call get_narrower below. For
1784 example, suppose that OP0 is of unsigned int extended
1785 from signed char and that RESULT_TYPE is long long int.
1786 If we explicitly cast OP0 to RESULT_TYPE, OP0 would look
1787 like
48e1416a 1788
2561cea2 1789 (long long int) (unsigned int) signed_char
1790
1791 which get_narrower would narrow down to
48e1416a 1792
2561cea2 1793 (unsigned int) signed char
48e1416a 1794
2561cea2 1795 If we do not cast OP0 first, get_narrower would return
1796 signed_char, which is inconsistent with the case of the
1797 explicit cast. */
1798 op0 = convert (result_type, op0);
1799 op1 = convert (result_type, op1);
1800
1801 arg0 = get_narrower (op0, &unsigned0);
1802 arg1 = get_narrower (op1, &unsigned1);
1803
1804 /* UNS is 1 if the operation to be done is an unsigned one. */
1805 uns = TYPE_UNSIGNED (result_type);
1806
1807 /* Handle the case that OP0 (or OP1) does not *contain* a conversion
1808 but it *requires* conversion to FINAL_TYPE. */
48e1416a 1809
2561cea2 1810 if ((TYPE_PRECISION (TREE_TYPE (op0))
1811 == TYPE_PRECISION (TREE_TYPE (arg0)))
1812 && TREE_TYPE (op0) != result_type)
1813 unsigned0 = TYPE_UNSIGNED (TREE_TYPE (op0));
1814 if ((TYPE_PRECISION (TREE_TYPE (op1))
1815 == TYPE_PRECISION (TREE_TYPE (arg1)))
1816 && TREE_TYPE (op1) != result_type)
1817 unsigned1 = TYPE_UNSIGNED (TREE_TYPE (op1));
48e1416a 1818
2561cea2 1819 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
48e1416a 1820
2561cea2 1821 /* For bitwise operations, signedness of nominal type
1822 does not matter. Consider only how operands were extended. */
1823 if (bitwise)
1824 uns = unsigned0;
48e1416a 1825
2561cea2 1826 /* Note that in all three cases below we refrain from optimizing
1827 an unsigned operation on sign-extended args.
1828 That would not be valid. */
48e1416a 1829
2561cea2 1830 /* Both args variable: if both extended in same way
1831 from same width, do it in that width.
1832 Do it unsigned if args were zero-extended. */
1833 if ((TYPE_PRECISION (TREE_TYPE (arg0))
1834 < TYPE_PRECISION (result_type))
1835 && (TYPE_PRECISION (TREE_TYPE (arg1))
1836 == TYPE_PRECISION (TREE_TYPE (arg0)))
1837 && unsigned0 == unsigned1
1838 && (unsigned0 || !uns))
1839 return c_common_signed_or_unsigned_type
1840 (unsigned0, common_type (TREE_TYPE (arg0), TREE_TYPE (arg1)));
1841
1842 else if (TREE_CODE (arg0) == INTEGER_CST
1843 && (unsigned1 || !uns)
1844 && (TYPE_PRECISION (TREE_TYPE (arg1))
1845 < TYPE_PRECISION (result_type))
1846 && (type
1847 = c_common_signed_or_unsigned_type (unsigned1,
1848 TREE_TYPE (arg1)))
1849 && !POINTER_TYPE_P (type)
1850 && int_fits_type_p (arg0, type))
1851 return type;
1852
1853 else if (TREE_CODE (arg1) == INTEGER_CST
1854 && (unsigned0 || !uns)
1855 && (TYPE_PRECISION (TREE_TYPE (arg0))
1856 < TYPE_PRECISION (result_type))
1857 && (type
1858 = c_common_signed_or_unsigned_type (unsigned0,
1859 TREE_TYPE (arg0)))
1860 && !POINTER_TYPE_P (type)
1861 && int_fits_type_p (arg1, type))
1862 return type;
1863
1864 return result_type;
1865}
1866
d31d55f0 1867/* Warns if the conversion of EXPR to TYPE may alter a value.
59dd8856 1868 This is a helper function for warnings_for_convert_and_check. */
d31d55f0 1869
1870static void
1871conversion_warning (tree type, tree expr)
1872{
1873 bool give_warning = false;
1874
5b16c152 1875 int i;
1876 const int expr_num_operands = TREE_OPERAND_LENGTH (expr);
27259707 1877 tree expr_type = TREE_TYPE (expr);
8637f1db 1878 location_t loc = EXPR_LOC_OR_HERE (expr);
d31d55f0 1879
7ee0d227 1880 if (!warn_conversion && !warn_sign_conversion)
1881 return;
1882
5b16c152 1883 /* If any operand is artificial, then this expression was generated
1884 by the compiler and we do not warn. */
1885 for (i = 0; i < expr_num_operands; i++)
1886 {
1887 tree op = TREE_OPERAND (expr, i);
7bdc5064 1888 if (op && DECL_P (op) && DECL_ARTIFICIAL (op))
5b16c152 1889 return;
1890 }
1891
27259707 1892 switch (TREE_CODE (expr))
d31d55f0 1893 {
27259707 1894 case EQ_EXPR:
1895 case NE_EXPR:
1896 case LE_EXPR:
1897 case GE_EXPR:
1898 case LT_EXPR:
1899 case GT_EXPR:
1900 case TRUTH_ANDIF_EXPR:
1901 case TRUTH_ORIF_EXPR:
1902 case TRUTH_AND_EXPR:
1903 case TRUTH_OR_EXPR:
1904 case TRUTH_XOR_EXPR:
1905 case TRUTH_NOT_EXPR:
1906 /* Conversion from boolean to a signed:1 bit-field (which only
1907 can hold the values 0 and -1) doesn't lose information - but
1908 it does change the value. */
48e1416a 1909 if (TYPE_PRECISION (type) == 1 && !TYPE_UNSIGNED (type))
200dd99c 1910 warning_at (loc, OPT_Wconversion,
1911 "conversion to %qT from boolean expression", type);
27259707 1912 return;
1913
1914 case REAL_CST:
1915 case INTEGER_CST:
1916
d31d55f0 1917 /* Warn for real constant that is not an exact integer converted
1918 to integer type. */
27259707 1919 if (TREE_CODE (expr_type) == REAL_TYPE
d31d55f0 1920 && TREE_CODE (type) == INTEGER_TYPE)
1921 {
27259707 1922 if (!real_isinteger (TREE_REAL_CST_PTR (expr), TYPE_MODE (expr_type)))
d31d55f0 1923 give_warning = true;
1924 }
da1fb07b 1925 /* Warn for an integer constant that does not fit into integer type. */
27259707 1926 else if (TREE_CODE (expr_type) == INTEGER_TYPE
d31d55f0 1927 && TREE_CODE (type) == INTEGER_TYPE
da1fb07b 1928 && !int_fits_type_p (expr, type))
1929 {
48e1416a 1930 if (TYPE_UNSIGNED (type) && !TYPE_UNSIGNED (expr_type)
27259707 1931 && tree_int_cst_sgn (expr) < 0)
200dd99c 1932 warning_at (loc, OPT_Wsign_conversion, "negative integer"
1933 " implicitly converted to unsigned type");
27259707 1934 else if (!TYPE_UNSIGNED (type) && TYPE_UNSIGNED (expr_type))
200dd99c 1935 warning_at (loc, OPT_Wsign_conversion, "conversion of unsigned"
1936 " constant value to negative integer");
7ee0d227 1937 else
1938 give_warning = true;
da1fb07b 1939 }
d31d55f0 1940 else if (TREE_CODE (type) == REAL_TYPE)
1941 {
1942 /* Warn for an integer constant that does not fit into real type. */
27259707 1943 if (TREE_CODE (expr_type) == INTEGER_TYPE)
d31d55f0 1944 {
1945 REAL_VALUE_TYPE a = real_value_from_int_cst (0, expr);
1946 if (!exact_real_truncate (TYPE_MODE (type), &a))
1947 give_warning = true;
1948 }
1949 /* Warn for a real constant that does not fit into a smaller
1950 real type. */
27259707 1951 else if (TREE_CODE (expr_type) == REAL_TYPE
1952 && TYPE_PRECISION (type) < TYPE_PRECISION (expr_type))
d31d55f0 1953 {
1954 REAL_VALUE_TYPE a = TREE_REAL_CST (expr);
1955 if (!exact_real_truncate (TYPE_MODE (type), &a))
1956 give_warning = true;
1957 }
1958 }
1959
1960 if (give_warning)
200dd99c 1961 warning_at (loc, OPT_Wconversion,
1962 "conversion to %qT alters %qT constant value",
1963 type, expr_type);
27259707 1964
1965 return;
1966
1967 case COND_EXPR:
1968 {
1969 /* In case of COND_EXPR, if both operands are constants or
1970 COND_EXPR, then we do not care about the type of COND_EXPR,
1971 only about the conversion of each operand. */
1972 tree op1 = TREE_OPERAND (expr, 1);
1973 tree op2 = TREE_OPERAND (expr, 2);
1974
48e1416a 1975 if ((TREE_CODE (op1) == REAL_CST || TREE_CODE (op1) == INTEGER_CST
27259707 1976 || TREE_CODE (op1) == COND_EXPR)
1977 && (TREE_CODE (op2) == REAL_CST || TREE_CODE (op2) == INTEGER_CST
1978 || TREE_CODE (op2) == COND_EXPR))
1979 {
1980 conversion_warning (type, op1);
1981 conversion_warning (type, op2);
1982 return;
1983 }
1984 /* Fall through. */
1985 }
1986
1987 default: /* 'expr' is not a constant. */
2561cea2 1988
d31d55f0 1989 /* Warn for real types converted to integer types. */
2561cea2 1990 if (TREE_CODE (expr_type) == REAL_TYPE
d31d55f0 1991 && TREE_CODE (type) == INTEGER_TYPE)
1992 give_warning = true;
1993
2561cea2 1994 else if (TREE_CODE (expr_type) == INTEGER_TYPE
d31d55f0 1995 && TREE_CODE (type) == INTEGER_TYPE)
1996 {
69609004 1997 /* Don't warn about unsigned char y = 0xff, x = (int) y; */
f9d856a4 1998 expr = get_unwidened (expr, 0);
2561cea2 1999 expr_type = TREE_TYPE (expr);
69609004 2000
2561cea2 2001 /* Don't warn for short y; short x = ((int)y & 0xff); */
48e1416a 2002 if (TREE_CODE (expr) == BIT_AND_EXPR
2003 || TREE_CODE (expr) == BIT_IOR_EXPR
2561cea2 2004 || TREE_CODE (expr) == BIT_XOR_EXPR)
2005 {
27259707 2006 /* If both args were extended from a shortest type,
2007 use that type if that is safe. */
48e1416a 2008 expr_type = shorten_binary_op (expr_type,
2009 TREE_OPERAND (expr, 0),
2010 TREE_OPERAND (expr, 1),
2561cea2 2011 /* bitwise */1);
2012
2561cea2 2013 if (TREE_CODE (expr) == BIT_AND_EXPR)
2014 {
2015 tree op0 = TREE_OPERAND (expr, 0);
2016 tree op1 = TREE_OPERAND (expr, 1);
30de145b 2017 bool unsigned0 = TYPE_UNSIGNED (TREE_TYPE (op0));
2018 bool unsigned1 = TYPE_UNSIGNED (TREE_TYPE (op1));
2019
2020 /* If one of the operands is a non-negative constant
2021 that fits in the target type, then the type of the
2022 other operand does not matter. */
2561cea2 2023 if ((TREE_CODE (op0) == INTEGER_CST
2024 && int_fits_type_p (op0, c_common_signed_type (type))
2025 && int_fits_type_p (op0, c_common_unsigned_type (type)))
2026 || (TREE_CODE (op1) == INTEGER_CST
27259707 2027 && int_fits_type_p (op1, c_common_signed_type (type))
48e1416a 2028 && int_fits_type_p (op1,
27259707 2029 c_common_unsigned_type (type))))
2561cea2 2030 return;
30de145b 2031 /* If constant is unsigned and fits in the target
2032 type, then the result will also fit. */
2033 else if ((TREE_CODE (op0) == INTEGER_CST
48e1416a 2034 && unsigned0
30de145b 2035 && int_fits_type_p (op0, type))
2036 || (TREE_CODE (op1) == INTEGER_CST
2037 && unsigned1
2038 && int_fits_type_p (op1, type)))
2039 return;
2561cea2 2040 }
2041 }
d31d55f0 2042 /* Warn for integer types converted to smaller integer types. */
48e1416a 2043 if (TYPE_PRECISION (type) < TYPE_PRECISION (expr_type))
7ee0d227 2044 give_warning = true;
2045
2046 /* When they are the same width but different signedness,
2047 then the value may change. */
27259707 2048 else if ((TYPE_PRECISION (type) == TYPE_PRECISION (expr_type)
2561cea2 2049 && TYPE_UNSIGNED (expr_type) != TYPE_UNSIGNED (type))
7ee0d227 2050 /* Even when converted to a bigger type, if the type is
2051 unsigned but expr is signed, then negative values
2052 will be changed. */
2561cea2 2053 || (TYPE_UNSIGNED (type) && !TYPE_UNSIGNED (expr_type)))
200dd99c 2054 warning_at (loc, OPT_Wsign_conversion, "conversion to %qT from %qT "
2055 "may change the sign of the result",
2056 type, expr_type);
d31d55f0 2057 }
2058
2059 /* Warn for integer types converted to real types if and only if
2060 all the range of values of the integer type cannot be
2061 represented by the real type. */
2561cea2 2062 else if (TREE_CODE (expr_type) == INTEGER_TYPE
d31d55f0 2063 && TREE_CODE (type) == REAL_TYPE)
2064 {
4c2cfa81 2065 tree type_low_bound, type_high_bound;
2066 REAL_VALUE_TYPE real_low_bound, real_high_bound;
2067
2068 /* Don't warn about char y = 0xff; float x = (int) y; */
2069 expr = get_unwidened (expr, 0);
2070 expr_type = TREE_TYPE (expr);
2071
2072 type_low_bound = TYPE_MIN_VALUE (expr_type);
2073 type_high_bound = TYPE_MAX_VALUE (expr_type);
2074 real_low_bound = real_value_from_int_cst (0, type_low_bound);
2075 real_high_bound = real_value_from_int_cst (0, type_high_bound);
d31d55f0 2076
2077 if (!exact_real_truncate (TYPE_MODE (type), &real_low_bound)
2078 || !exact_real_truncate (TYPE_MODE (type), &real_high_bound))
2079 give_warning = true;
2080 }
2081
2082 /* Warn for real types converted to smaller real types. */
2561cea2 2083 else if (TREE_CODE (expr_type) == REAL_TYPE
d31d55f0 2084 && TREE_CODE (type) == REAL_TYPE
27259707 2085 && TYPE_PRECISION (type) < TYPE_PRECISION (expr_type))
d31d55f0 2086 give_warning = true;
2087
2088
2089 if (give_warning)
200dd99c 2090 warning_at (loc, OPT_Wconversion,
2091 "conversion to %qT from %qT may alter its value",
2092 type, expr_type);
d31d55f0 2093 }
2094}
2095
59dd8856 2096/* Produce warnings after a conversion. RESULT is the result of
2097 converting EXPR to TYPE. This is a helper function for
2098 convert_and_check and cp_convert_and_check. */
2a1736ed 2099
59dd8856 2100void
2101warnings_for_convert_and_check (tree type, tree expr, tree result)
2a1736ed 2102{
da1fb07b 2103 if (TREE_CODE (expr) == INTEGER_CST
2104 && (TREE_CODE (type) == INTEGER_TYPE
2105 || TREE_CODE (type) == ENUMERAL_TYPE)
2106 && !int_fits_type_p (expr, type))
2107 {
d31d55f0 2108 /* Do not diagnose overflow in a constant expression merely
2109 because a conversion overflowed. */
da1fb07b 2110 if (TREE_OVERFLOW (result))
eddad94a 2111 TREE_OVERFLOW (result) = TREE_OVERFLOW (expr);
2112
da1fb07b 2113 if (TYPE_UNSIGNED (type))
d31d55f0 2114 {
da1fb07b 2115 /* This detects cases like converting -129 or 256 to
2116 unsigned char. */
2117 if (!int_fits_type_p (expr, c_common_signed_type (type)))
2118 warning (OPT_Woverflow,
2119 "large integer implicitly truncated to unsigned type");
7ee0d227 2120 else
da1fb07b 2121 conversion_warning (type, expr);
2122 }
48e1416a 2123 else if (!int_fits_type_p (expr, c_common_unsigned_type (type)))
e0913805 2124 warning (OPT_Woverflow,
2125 "overflow in implicit constant conversion");
2126 /* No warning for converting 0x80000000 to int. */
2127 else if (pedantic
2128 && (TREE_CODE (TREE_TYPE (expr)) != INTEGER_TYPE
2129 || TYPE_PRECISION (TREE_TYPE (expr))
2130 != TYPE_PRECISION (type)))
2131 warning (OPT_Woverflow,
2132 "overflow in implicit constant conversion");
2133
7ee0d227 2134 else
e0913805 2135 conversion_warning (type, expr);
2a1736ed 2136 }
9421ebb9 2137 else if ((TREE_CODE (result) == INTEGER_CST
2138 || TREE_CODE (result) == FIXED_CST) && TREE_OVERFLOW (result))
da1fb07b 2139 warning (OPT_Woverflow,
2140 "overflow in implicit constant conversion");
7ee0d227 2141 else
da1fb07b 2142 conversion_warning (type, expr);
59dd8856 2143}
2144
2145
2146/* Convert EXPR to TYPE, warning about conversion problems with constants.
2147 Invoke this function on every expression that is converted implicitly,
2148 i.e. because of language rules and not because of an explicit cast. */
2149
2150tree
2151convert_and_check (tree type, tree expr)
2152{
2153 tree result;
c6418a4e 2154 tree expr_for_warning;
2155
2156 /* Convert from a value with possible excess precision rather than
2157 via the semantic type, but do not warn about values not fitting
2158 exactly in the semantic type. */
2159 if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
2160 {
2161 tree orig_type = TREE_TYPE (expr);
2162 expr = TREE_OPERAND (expr, 0);
2163 expr_for_warning = convert (orig_type, expr);
2164 if (orig_type == type)
2165 return expr_for_warning;
2166 }
2167 else
2168 expr_for_warning = expr;
59dd8856 2169
2170 if (TREE_TYPE (expr) == type)
2171 return expr;
48e1416a 2172
59dd8856 2173 result = convert (type, expr);
2174
48d94ede 2175 if (c_inhibit_evaluation_warnings == 0
2176 && !TREE_OVERFLOW_P (expr)
2177 && result != error_mark_node)
c6418a4e 2178 warnings_for_convert_and_check (type, expr_for_warning, result);
59dd8856 2179
da1fb07b 2180 return result;
b2806639 2181}
2182\f
4e91a871 2183/* A node in a list that describes references to variables (EXPR), which are
2184 either read accesses if WRITER is zero, or write accesses, in which case
2185 WRITER is the parent of EXPR. */
2186struct tlist
2187{
2188 struct tlist *next;
2189 tree expr, writer;
2190};
2191
2192/* Used to implement a cache the results of a call to verify_tree. We only
2193 use this for SAVE_EXPRs. */
2194struct tlist_cache
2195{
2196 struct tlist_cache *next;
2197 struct tlist *cache_before_sp;
2198 struct tlist *cache_after_sp;
2199 tree expr;
481c6ce6 2200};
2201
4e91a871 2202/* Obstack to use when allocating tlist structures, and corresponding
2203 firstobj. */
2204static struct obstack tlist_obstack;
2205static char *tlist_firstobj = 0;
2206
2207/* Keep track of the identifiers we've warned about, so we can avoid duplicate
2208 warnings. */
2209static struct tlist *warned_ids;
2210/* SAVE_EXPRs need special treatment. We process them only once and then
2211 cache the results. */
2212static struct tlist_cache *save_expr_cache;
2213
1cae46be 2214static void add_tlist (struct tlist **, struct tlist *, tree, int);
2215static void merge_tlist (struct tlist **, struct tlist *, int);
2216static void verify_tree (tree, struct tlist **, struct tlist **, tree);
2217static int warning_candidate_p (tree);
79973b57 2218static bool candidate_equal_p (const_tree, const_tree);
1cae46be 2219static void warn_for_collisions (struct tlist *);
2220static void warn_for_collisions_1 (tree, tree, struct tlist *, int);
2221static struct tlist *new_tlist (struct tlist *, tree, tree);
481c6ce6 2222
4e91a871 2223/* Create a new struct tlist and fill in its fields. */
2224static struct tlist *
1cae46be 2225new_tlist (struct tlist *next, tree t, tree writer)
4e91a871 2226{
2227 struct tlist *l;
9318f22c 2228 l = XOBNEW (&tlist_obstack, struct tlist);
4e91a871 2229 l->next = next;
2230 l->expr = t;
2231 l->writer = writer;
2232 return l;
2233}
2234
2235/* Add duplicates of the nodes found in ADD to the list *TO. If EXCLUDE_WRITER
2236 is nonnull, we ignore any node we find which has a writer equal to it. */
2237
2238static void
1cae46be 2239add_tlist (struct tlist **to, struct tlist *add, tree exclude_writer, int copy)
4e91a871 2240{
2241 while (add)
2242 {
2243 struct tlist *next = add->next;
84166705 2244 if (!copy)
4e91a871 2245 add->next = *to;
79973b57 2246 if (!exclude_writer || !candidate_equal_p (add->writer, exclude_writer))
4e91a871 2247 *to = copy ? new_tlist (*to, add->expr, add->writer) : add;
2248 add = next;
2249 }
2250}
2251
2252/* Merge the nodes of ADD into TO. This merging process is done so that for
2253 each variable that already exists in TO, no new node is added; however if
2254 there is a write access recorded in ADD, and an occurrence on TO is only
2255 a read access, then the occurrence in TO will be modified to record the
2256 write. */
481c6ce6 2257
2258static void
1cae46be 2259merge_tlist (struct tlist **to, struct tlist *add, int copy)
4e91a871 2260{
2261 struct tlist **end = to;
2262
2263 while (*end)
2264 end = &(*end)->next;
2265
2266 while (add)
2267 {
2268 int found = 0;
2269 struct tlist *tmp2;
2270 struct tlist *next = add->next;
2271
2272 for (tmp2 = *to; tmp2; tmp2 = tmp2->next)
79973b57 2273 if (candidate_equal_p (tmp2->expr, add->expr))
4e91a871 2274 {
2275 found = 1;
84166705 2276 if (!tmp2->writer)
4e91a871 2277 tmp2->writer = add->writer;
2278 }
84166705 2279 if (!found)
4e91a871 2280 {
2281 *end = copy ? add : new_tlist (NULL, add->expr, add->writer);
2282 end = &(*end)->next;
2283 *end = 0;
2284 }
2285 add = next;
2286 }
2287}
2288
2289/* WRITTEN is a variable, WRITER is its parent. Warn if any of the variable
2290 references in list LIST conflict with it, excluding reads if ONLY writers
2291 is nonzero. */
2292
2293static void
1cae46be 2294warn_for_collisions_1 (tree written, tree writer, struct tlist *list,
2295 int only_writes)
4e91a871 2296{
2297 struct tlist *tmp;
2298
2299 /* Avoid duplicate warnings. */
2300 for (tmp = warned_ids; tmp; tmp = tmp->next)
79973b57 2301 if (candidate_equal_p (tmp->expr, written))
4e91a871 2302 return;
2303
2304 while (list)
2305 {
79973b57 2306 if (candidate_equal_p (list->expr, written)
2307 && !candidate_equal_p (list->writer, writer)
2308 && (!only_writes || list->writer))
4e91a871 2309 {
2310 warned_ids = new_tlist (warned_ids, written, NULL_TREE);
8637f1db 2311 warning_at (EXPR_LOC_OR_HERE (writer),
6513b50d 2312 OPT_Wsequence_point, "operation on %qE may be undefined",
2313 list->expr);
4e91a871 2314 }
2315 list = list->next;
2316 }
2317}
2318
2319/* Given a list LIST of references to variables, find whether any of these
2320 can cause conflicts due to missing sequence points. */
2321
2322static void
1cae46be 2323warn_for_collisions (struct tlist *list)
4e91a871 2324{
2325 struct tlist *tmp;
1cae46be 2326
4e91a871 2327 for (tmp = list; tmp; tmp = tmp->next)
2328 {
2329 if (tmp->writer)
2330 warn_for_collisions_1 (tmp->expr, tmp->writer, list, 0);
2331 }
2332}
2333
734c98be 2334/* Return nonzero if X is a tree that can be verified by the sequence point
4e91a871 2335 warnings. */
2336static int
1cae46be 2337warning_candidate_p (tree x)
481c6ce6 2338{
6ef8d12f 2339 if (DECL_P (x) && DECL_ARTIFICIAL (x))
2340 return 0;
2341
2342 /* VOID_TYPE_P (TREE_TYPE (x)) is workaround for cp/tree.c
79973b57 2343 (lvalue_p) crash on TRY/CATCH. */
6ef8d12f 2344 if (TREE_TYPE (x) == NULL_TREE || VOID_TYPE_P (TREE_TYPE (x)))
2345 return 0;
2346
2347 if (!lvalue_p (x))
2348 return 0;
2349
2350 /* No point to track non-const calls, they will never satisfy
2351 operand_equal_p. */
2352 if (TREE_CODE (x) == CALL_EXPR && (call_expr_flags (x) & ECF_CONST) == 0)
2353 return 0;
2354
2355 if (TREE_CODE (x) == STRING_CST)
2356 return 0;
2357
2358 return 1;
79973b57 2359}
2360
2361/* Return nonzero if X and Y appear to be the same candidate (or NULL) */
2362static bool
2363candidate_equal_p (const_tree x, const_tree y)
2364{
2365 return (x == y) || (x && y && operand_equal_p (x, y, 0));
4e91a871 2366}
481c6ce6 2367
4e91a871 2368/* Walk the tree X, and record accesses to variables. If X is written by the
2369 parent tree, WRITER is the parent.
2370 We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP. If this
2371 expression or its only operand forces a sequence point, then everything up
2372 to the sequence point is stored in PBEFORE_SP. Everything else gets stored
2373 in PNO_SP.
2374 Once we return, we will have emitted warnings if any subexpression before
2375 such a sequence point could be undefined. On a higher level, however, the
2376 sequence point may not be relevant, and we'll merge the two lists.
2377
2378 Example: (b++, a) + b;
2379 The call that processes the COMPOUND_EXPR will store the increment of B
2380 in PBEFORE_SP, and the use of A in PNO_SP. The higher-level call that
2381 processes the PLUS_EXPR will need to merge the two lists so that
2382 eventually, all accesses end up on the same list (and we'll warn about the
2383 unordered subexpressions b++ and b.
2384
2385 A note on merging. If we modify the former example so that our expression
2386 becomes
2387 (b++, b) + a
2388 care must be taken not simply to add all three expressions into the final
2389 PNO_SP list. The function merge_tlist takes care of that by merging the
2390 before-SP list of the COMPOUND_EXPR into its after-SP list in a special
2391 way, so that no more than one access to B is recorded. */
481c6ce6 2392
4e91a871 2393static void
1cae46be 2394verify_tree (tree x, struct tlist **pbefore_sp, struct tlist **pno_sp,
2395 tree writer)
4e91a871 2396{
2397 struct tlist *tmp_before, *tmp_nosp, *tmp_list2, *tmp_list3;
2398 enum tree_code code;
ce45a448 2399 enum tree_code_class cl;
481c6ce6 2400
e5b75768 2401 /* X may be NULL if it is the operand of an empty statement expression
2402 ({ }). */
2403 if (x == NULL)
2404 return;
2405
4e91a871 2406 restart:
2407 code = TREE_CODE (x);
e916c70c 2408 cl = TREE_CODE_CLASS (code);
481c6ce6 2409
4e91a871 2410 if (warning_candidate_p (x))
79973b57 2411 *pno_sp = new_tlist (*pno_sp, x, writer);
4e91a871 2412
2413 switch (code)
2414 {
67b28e3e 2415 case CONSTRUCTOR:
2416 return;
2417
4e91a871 2418 case COMPOUND_EXPR:
2419 case TRUTH_ANDIF_EXPR:
2420 case TRUTH_ORIF_EXPR:
2421 tmp_before = tmp_nosp = tmp_list3 = 0;
2422 verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE);
2423 warn_for_collisions (tmp_nosp);
2424 merge_tlist (pbefore_sp, tmp_before, 0);
2425 merge_tlist (pbefore_sp, tmp_nosp, 0);
2426 verify_tree (TREE_OPERAND (x, 1), &tmp_list3, pno_sp, NULL_TREE);
2427 merge_tlist (pbefore_sp, tmp_list3, 0);
2428 return;
2429
2430 case COND_EXPR:
2431 tmp_before = tmp_list2 = 0;
2432 verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_list2, NULL_TREE);
2433 warn_for_collisions (tmp_list2);
2434 merge_tlist (pbefore_sp, tmp_before, 0);
2435 merge_tlist (pbefore_sp, tmp_list2, 1);
2436
2437 tmp_list3 = tmp_nosp = 0;
2438 verify_tree (TREE_OPERAND (x, 1), &tmp_list3, &tmp_nosp, NULL_TREE);
2439 warn_for_collisions (tmp_nosp);
2440 merge_tlist (pbefore_sp, tmp_list3, 0);
2441
2442 tmp_list3 = tmp_list2 = 0;
2443 verify_tree (TREE_OPERAND (x, 2), &tmp_list3, &tmp_list2, NULL_TREE);
2444 warn_for_collisions (tmp_list2);
2445 merge_tlist (pbefore_sp, tmp_list3, 0);
2446 /* Rather than add both tmp_nosp and tmp_list2, we have to merge the
2447 two first, to avoid warning for (a ? b++ : b++). */
2448 merge_tlist (&tmp_nosp, tmp_list2, 0);
2449 add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
2450 return;
2451
481c6ce6 2452 case PREDECREMENT_EXPR:
2453 case PREINCREMENT_EXPR:
2454 case POSTDECREMENT_EXPR:
2455 case POSTINCREMENT_EXPR:
4e91a871 2456 verify_tree (TREE_OPERAND (x, 0), pno_sp, pno_sp, x);
2457 return;
2458
2459 case MODIFY_EXPR:
2460 tmp_before = tmp_nosp = tmp_list3 = 0;
2461 verify_tree (TREE_OPERAND (x, 1), &tmp_before, &tmp_nosp, NULL_TREE);
2462 verify_tree (TREE_OPERAND (x, 0), &tmp_list3, &tmp_list3, x);
2463 /* Expressions inside the LHS are not ordered wrt. the sequence points
2464 in the RHS. Example:
2465 *a = (a++, 2)
2466 Despite the fact that the modification of "a" is in the before_sp
2467 list (tmp_before), it conflicts with the use of "a" in the LHS.
2468 We can handle this by adding the contents of tmp_list3
2469 to those of tmp_before, and redoing the collision warnings for that
2470 list. */
2471 add_tlist (&tmp_before, tmp_list3, x, 1);
2472 warn_for_collisions (tmp_before);
2473 /* Exclude the LHS itself here; we first have to merge it into the
2474 tmp_nosp list. This is done to avoid warning for "a = a"; if we
2475 didn't exclude the LHS, we'd get it twice, once as a read and once
2476 as a write. */
2477 add_tlist (pno_sp, tmp_list3, x, 0);
2478 warn_for_collisions_1 (TREE_OPERAND (x, 0), x, tmp_nosp, 1);
2479
2480 merge_tlist (pbefore_sp, tmp_before, 0);
2481 if (warning_candidate_p (TREE_OPERAND (x, 0)))
2482 merge_tlist (&tmp_nosp, new_tlist (NULL, TREE_OPERAND (x, 0), x), 0);
2483 add_tlist (pno_sp, tmp_nosp, NULL_TREE, 1);
2484 return;
481c6ce6 2485
2486 case CALL_EXPR:
4e91a871 2487 /* We need to warn about conflicts among arguments and conflicts between
2488 args and the function address. Side effects of the function address,
2489 however, are not ordered by the sequence point of the call. */
c2f47e15 2490 {
2491 call_expr_arg_iterator iter;
2492 tree arg;
48e1416a 2493 tmp_before = tmp_nosp = 0;
c2f47e15 2494 verify_tree (CALL_EXPR_FN (x), &tmp_before, &tmp_nosp, NULL_TREE);
2495 FOR_EACH_CALL_EXPR_ARG (arg, iter, x)
2496 {
2497 tmp_list2 = tmp_list3 = 0;
2498 verify_tree (arg, &tmp_list2, &tmp_list3, NULL_TREE);
2499 merge_tlist (&tmp_list3, tmp_list2, 0);
2500 add_tlist (&tmp_before, tmp_list3, NULL_TREE, 0);
2501 }
2502 add_tlist (&tmp_before, tmp_nosp, NULL_TREE, 0);
2503 warn_for_collisions (tmp_before);
2504 add_tlist (pbefore_sp, tmp_before, NULL_TREE, 0);
2505 return;
2506 }
481c6ce6 2507
2508 case TREE_LIST:
2509 /* Scan all the list, e.g. indices of multi dimensional array. */
2510 while (x)
2511 {
4e91a871 2512 tmp_before = tmp_nosp = 0;
2513 verify_tree (TREE_VALUE (x), &tmp_before, &tmp_nosp, NULL_TREE);
2514 merge_tlist (&tmp_nosp, tmp_before, 0);
2515 add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
481c6ce6 2516 x = TREE_CHAIN (x);
2517 }
4e91a871 2518 return;
481c6ce6 2519
4e91a871 2520 case SAVE_EXPR:
2521 {
2522 struct tlist_cache *t;
2523 for (t = save_expr_cache; t; t = t->next)
79973b57 2524 if (candidate_equal_p (t->expr, x))
4e91a871 2525 break;
481c6ce6 2526
84166705 2527 if (!t)
481c6ce6 2528 {
9318f22c 2529 t = XOBNEW (&tlist_obstack, struct tlist_cache);
4e91a871 2530 t->next = save_expr_cache;
2531 t->expr = x;
2532 save_expr_cache = t;
2533
2534 tmp_before = tmp_nosp = 0;
2535 verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE);
2536 warn_for_collisions (tmp_nosp);
2537
2538 tmp_list3 = 0;
2539 while (tmp_nosp)
2540 {
2541 struct tlist *t = tmp_nosp;
2542 tmp_nosp = t->next;
2543 merge_tlist (&tmp_list3, t, 0);
2544 }
2545 t->cache_before_sp = tmp_before;
2546 t->cache_after_sp = tmp_list3;
481c6ce6 2547 }
4e91a871 2548 merge_tlist (pbefore_sp, t->cache_before_sp, 1);
2549 add_tlist (pno_sp, t->cache_after_sp, NULL_TREE, 1);
2550 return;
2551 }
481c6ce6 2552
012916cb 2553 case ADDR_EXPR:
2554 x = TREE_OPERAND (x, 0);
2555 if (DECL_P (x))
2556 return;
2557 writer = 0;
2558 goto restart;
2559
ce45a448 2560 default:
2561 /* For other expressions, simply recurse on their operands.
a0c938f0 2562 Manual tail recursion for unary expressions.
ce45a448 2563 Other non-expressions need not be processed. */
2564 if (cl == tcc_unary)
2565 {
ce45a448 2566 x = TREE_OPERAND (x, 0);
2567 writer = 0;
2568 goto restart;
2569 }
2570 else if (IS_EXPR_CODE_CLASS (cl))
2571 {
2572 int lp;
c2f47e15 2573 int max = TREE_OPERAND_LENGTH (x);
ce45a448 2574 for (lp = 0; lp < max; lp++)
2575 {
2576 tmp_before = tmp_nosp = 0;
2577 verify_tree (TREE_OPERAND (x, lp), &tmp_before, &tmp_nosp, 0);
2578 merge_tlist (&tmp_nosp, tmp_before, 0);
2579 add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
2580 }
2581 }
2582 return;
481c6ce6 2583 }
481c6ce6 2584}
2585
974e2c0c 2586/* Try to warn for undefined behavior in EXPR due to missing sequence
481c6ce6 2587 points. */
2588
4b987fac 2589DEBUG_FUNCTION void
1cae46be 2590verify_sequence_points (tree expr)
481c6ce6 2591{
4e91a871 2592 struct tlist *before_sp = 0, *after_sp = 0;
481c6ce6 2593
4e91a871 2594 warned_ids = 0;
2595 save_expr_cache = 0;
2596 if (tlist_firstobj == 0)
481c6ce6 2597 {
4e91a871 2598 gcc_obstack_init (&tlist_obstack);
4fd61bc6 2599 tlist_firstobj = (char *) obstack_alloc (&tlist_obstack, 0);
481c6ce6 2600 }
2601
4e91a871 2602 verify_tree (expr, &before_sp, &after_sp, 0);
2603 warn_for_collisions (after_sp);
2604 obstack_free (&tlist_obstack, tlist_firstobj);
481c6ce6 2605}
b0fc3e72 2606\f
2607/* Validate the expression after `case' and apply default promotions. */
2608
2ca392fd 2609static tree
1cae46be 2610check_case_value (tree value)
b0fc3e72 2611{
2612 if (value == NULL_TREE)
2613 return value;
2614
b96dc121 2615 if (TREE_CODE (value) == INTEGER_CST)
2616 /* Promote char or short to int. */
2617 value = perform_integral_promotions (value);
2618 else if (value != error_mark_node)
b0fc3e72 2619 {
2620 error ("case label does not reduce to an integer constant");
2621 value = error_mark_node;
2622 }
b0fc3e72 2623
6433f1c2 2624 constant_expression_warning (value);
2625
b0fc3e72 2626 return value;
2627}
2628\f
2ca392fd 2629/* See if the case values LOW and HIGH are in the range of the original
5c9dae64 2630 type (i.e. before the default conversion to int) of the switch testing
2ca392fd 2631 expression.
2632 TYPE is the promoted type of the testing expression, and ORIG_TYPE is
91275768 2633 the type before promoting it. CASE_LOW_P is a pointer to the lower
2ca392fd 2634 bound of the case label, and CASE_HIGH_P is the upper bound or NULL
2635 if the case is not a case range.
2636 The caller has to make sure that we are not called with NULL for
5c9dae64 2637 CASE_LOW_P (i.e. the default case).
442e3cb9 2638 Returns true if the case label is in range of ORIG_TYPE (saturated or
2ca392fd 2639 untouched) or false if the label is out of range. */
2640
2641static bool
2642check_case_bounds (tree type, tree orig_type,
2643 tree *case_low_p, tree *case_high_p)
2644{
2645 tree min_value, max_value;
2646 tree case_low = *case_low_p;
2647 tree case_high = case_high_p ? *case_high_p : case_low;
2648
2649 /* If there was a problem with the original type, do nothing. */
2650 if (orig_type == error_mark_node)
2651 return true;
2652
2653 min_value = TYPE_MIN_VALUE (orig_type);
2654 max_value = TYPE_MAX_VALUE (orig_type);
2655
2656 /* Case label is less than minimum for type. */
2657 if (tree_int_cst_compare (case_low, min_value) < 0
2658 && tree_int_cst_compare (case_high, min_value) < 0)
2659 {
c3ceba8e 2660 warning (0, "case label value is less than minimum value for type");
2ca392fd 2661 return false;
2662 }
b27ac6b5 2663
2ca392fd 2664 /* Case value is greater than maximum for type. */
2665 if (tree_int_cst_compare (case_low, max_value) > 0
2666 && tree_int_cst_compare (case_high, max_value) > 0)
2667 {
c3ceba8e 2668 warning (0, "case label value exceeds maximum value for type");
2ca392fd 2669 return false;
2670 }
2671
2672 /* Saturate lower case label value to minimum. */
2673 if (tree_int_cst_compare (case_high, min_value) >= 0
2674 && tree_int_cst_compare (case_low, min_value) < 0)
2675 {
c3ceba8e 2676 warning (0, "lower value in case label range"
2ca392fd 2677 " less than minimum value for type");
2678 case_low = min_value;
2679 }
b27ac6b5 2680
2ca392fd 2681 /* Saturate upper case label value to maximum. */
2682 if (tree_int_cst_compare (case_low, max_value) <= 0
2683 && tree_int_cst_compare (case_high, max_value) > 0)
2684 {
c3ceba8e 2685 warning (0, "upper value in case label range"
2ca392fd 2686 " exceeds maximum value for type");
2687 case_high = max_value;
2688 }
2689
2690 if (*case_low_p != case_low)
2691 *case_low_p = convert (type, case_low);
2692 if (case_high_p && *case_high_p != case_high)
2693 *case_high_p = convert (type, case_high);
2694
2695 return true;
2696}
2697\f
b0fc3e72 2698/* Return an integer type with BITS bits of precision,
2699 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
2700
2701tree
1cae46be 2702c_common_type_for_size (unsigned int bits, int unsignedp)
b0fc3e72 2703{
46375237 2704 if (bits == TYPE_PRECISION (integer_type_node))
2705 return unsignedp ? unsigned_type_node : integer_type_node;
2706
bacde65a 2707 if (bits == TYPE_PRECISION (signed_char_type_node))
b0fc3e72 2708 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
2709
bacde65a 2710 if (bits == TYPE_PRECISION (short_integer_type_node))
b0fc3e72 2711 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
2712
bacde65a 2713 if (bits == TYPE_PRECISION (long_integer_type_node))
b0fc3e72 2714 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
2715
bacde65a 2716 if (bits == TYPE_PRECISION (long_long_integer_type_node))
b0fc3e72 2717 return (unsignedp ? long_long_unsigned_type_node
2718 : long_long_integer_type_node);
2719
6388cfe2 2720 if (int128_integer_type_node
2721 && bits == TYPE_PRECISION (int128_integer_type_node))
2722 return (unsignedp ? int128_unsigned_type_node
2723 : int128_integer_type_node);
2724
f57fa2ea 2725 if (bits == TYPE_PRECISION (widest_integer_literal_type_node))
2726 return (unsignedp ? widest_unsigned_literal_type_node
2727 : widest_integer_literal_type_node);
2728
bacde65a 2729 if (bits <= TYPE_PRECISION (intQI_type_node))
2730 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
2731
2732 if (bits <= TYPE_PRECISION (intHI_type_node))
2733 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
2734
2735 if (bits <= TYPE_PRECISION (intSI_type_node))
2736 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
2737
2738 if (bits <= TYPE_PRECISION (intDI_type_node))
2739 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
2740
b0fc3e72 2741 return 0;
2742}
2743
9421ebb9 2744/* Return a fixed-point type that has at least IBIT ibits and FBIT fbits
2745 that is unsigned if UNSIGNEDP is nonzero, otherwise signed;
2746 and saturating if SATP is nonzero, otherwise not saturating. */
2747
2748tree
2749c_common_fixed_point_type_for_size (unsigned int ibit, unsigned int fbit,
2750 int unsignedp, int satp)
2751{
2752 enum machine_mode mode;
2753 if (ibit == 0)
2754 mode = unsignedp ? UQQmode : QQmode;
2755 else
2756 mode = unsignedp ? UHAmode : HAmode;
2757
2758 for (; mode != VOIDmode; mode = GET_MODE_WIDER_MODE (mode))
2759 if (GET_MODE_IBIT (mode) >= ibit && GET_MODE_FBIT (mode) >= fbit)
2760 break;
2761
2762 if (mode == VOIDmode || !targetm.scalar_mode_supported_p (mode))
2763 {
2764 sorry ("GCC cannot support operators with integer types and "
2765 "fixed-point types that have too many integral and "
2766 "fractional bits together");
2767 return 0;
2768 }
2769
2770 return c_common_type_for_mode (mode, satp);
2771}
2772
5b247e9f 2773/* Used for communication between c_common_type_for_mode and
2774 c_register_builtin_type. */
2775static GTY(()) tree registered_builtin_types;
2776
b0fc3e72 2777/* Return a data type that has machine mode MODE.
2778 If the mode is an integer,
9421ebb9 2779 then UNSIGNEDP selects between signed and unsigned types.
2780 If the mode is a fixed-point mode,
2781 then UNSIGNEDP selects between saturating and nonsaturating types. */
b0fc3e72 2782
2783tree
1cae46be 2784c_common_type_for_mode (enum machine_mode mode, int unsignedp)
b0fc3e72 2785{
5b247e9f 2786 tree t;
2787
46375237 2788 if (mode == TYPE_MODE (integer_type_node))
2789 return unsignedp ? unsigned_type_node : integer_type_node;
2790
b0fc3e72 2791 if (mode == TYPE_MODE (signed_char_type_node))
2792 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
2793
2794 if (mode == TYPE_MODE (short_integer_type_node))
2795 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
2796
b0fc3e72 2797 if (mode == TYPE_MODE (long_integer_type_node))
2798 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
2799
2800 if (mode == TYPE_MODE (long_long_integer_type_node))
2801 return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;
2802
6388cfe2 2803 if (int128_integer_type_node
2804 && mode == TYPE_MODE (int128_integer_type_node))
2805 return unsignedp ? int128_unsigned_type_node : int128_integer_type_node;
2806
f57fa2ea 2807 if (mode == TYPE_MODE (widest_integer_literal_type_node))
44e9fa65 2808 return unsignedp ? widest_unsigned_literal_type_node
4ee9c684 2809 : widest_integer_literal_type_node;
f57fa2ea 2810
88ae7f04 2811 if (mode == QImode)
bacde65a 2812 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
2813
88ae7f04 2814 if (mode == HImode)
bacde65a 2815 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
2816
88ae7f04 2817 if (mode == SImode)
bacde65a 2818 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
2819
88ae7f04 2820 if (mode == DImode)
bacde65a 2821 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
2822
cc1cc1c7 2823#if HOST_BITS_PER_WIDE_INT >= 64
6274009c 2824 if (mode == TYPE_MODE (intTI_type_node))
2825 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
cc1cc1c7 2826#endif
6274009c 2827
b0fc3e72 2828 if (mode == TYPE_MODE (float_type_node))
2829 return float_type_node;
2830
2831 if (mode == TYPE_MODE (double_type_node))
2832 return double_type_node;
2833
2834 if (mode == TYPE_MODE (long_double_type_node))
2835 return long_double_type_node;
2836
545c2bde 2837 if (mode == TYPE_MODE (void_type_node))
2838 return void_type_node;
b27ac6b5 2839
b0fc3e72 2840 if (mode == TYPE_MODE (build_pointer_type (char_type_node)))
61b9b73c 2841 return (unsignedp
2842 ? make_unsigned_type (GET_MODE_PRECISION (mode))
2843 : make_signed_type (GET_MODE_PRECISION (mode)));
b0fc3e72 2844
2845 if (mode == TYPE_MODE (build_pointer_type (integer_type_node)))
61b9b73c 2846 return (unsignedp
2847 ? make_unsigned_type (GET_MODE_PRECISION (mode))
2848 : make_signed_type (GET_MODE_PRECISION (mode)));
b0fc3e72 2849
0dfc45b5 2850 if (COMPLEX_MODE_P (mode))
2851 {
2852 enum machine_mode inner_mode;
2853 tree inner_type;
2854
2855 if (mode == TYPE_MODE (complex_float_type_node))
2856 return complex_float_type_node;
2857 if (mode == TYPE_MODE (complex_double_type_node))
2858 return complex_double_type_node;
2859 if (mode == TYPE_MODE (complex_long_double_type_node))
2860 return complex_long_double_type_node;
2861
2862 if (mode == TYPE_MODE (complex_integer_type_node) && !unsignedp)
2863 return complex_integer_type_node;
2864
2865 inner_mode = GET_MODE_INNER (mode);
2866 inner_type = c_common_type_for_mode (inner_mode, unsignedp);
2867 if (inner_type != NULL_TREE)
2868 return build_complex_type (inner_type);
2869 }
2870 else if (VECTOR_MODE_P (mode))
4917c376 2871 {
2872 enum machine_mode inner_mode = GET_MODE_INNER (mode);
2873 tree inner_type = c_common_type_for_mode (inner_mode, unsignedp);
2874 if (inner_type != NULL_TREE)
2875 return build_vector_type_for_mode (inner_type, mode);
88ae7f04 2876 }
e2ea7e3a 2877
c4503c0a 2878 if (mode == TYPE_MODE (dfloat32_type_node))
2879 return dfloat32_type_node;
2880 if (mode == TYPE_MODE (dfloat64_type_node))
2881 return dfloat64_type_node;
2882 if (mode == TYPE_MODE (dfloat128_type_node))
2883 return dfloat128_type_node;
2884
9421ebb9 2885 if (ALL_SCALAR_FIXED_POINT_MODE_P (mode))
2886 {
2887 if (mode == TYPE_MODE (short_fract_type_node))
2888 return unsignedp ? sat_short_fract_type_node : short_fract_type_node;
2889 if (mode == TYPE_MODE (fract_type_node))
2890 return unsignedp ? sat_fract_type_node : fract_type_node;
2891 if (mode == TYPE_MODE (long_fract_type_node))
2892 return unsignedp ? sat_long_fract_type_node : long_fract_type_node;
2893 if (mode == TYPE_MODE (long_long_fract_type_node))
2894 return unsignedp ? sat_long_long_fract_type_node
2895 : long_long_fract_type_node;
2896
2897 if (mode == TYPE_MODE (unsigned_short_fract_type_node))
2898 return unsignedp ? sat_unsigned_short_fract_type_node
2899 : unsigned_short_fract_type_node;
2900 if (mode == TYPE_MODE (unsigned_fract_type_node))
2901 return unsignedp ? sat_unsigned_fract_type_node
2902 : unsigned_fract_type_node;
2903 if (mode == TYPE_MODE (unsigned_long_fract_type_node))
2904 return unsignedp ? sat_unsigned_long_fract_type_node
2905 : unsigned_long_fract_type_node;
2906 if (mode == TYPE_MODE (unsigned_long_long_fract_type_node))
2907 return unsignedp ? sat_unsigned_long_long_fract_type_node
2908 : unsigned_long_long_fract_type_node;
2909
2910 if (mode == TYPE_MODE (short_accum_type_node))
2911 return unsignedp ? sat_short_accum_type_node : short_accum_type_node;
2912 if (mode == TYPE_MODE (accum_type_node))
2913 return unsignedp ? sat_accum_type_node : accum_type_node;
2914 if (mode == TYPE_MODE (long_accum_type_node))
2915 return unsignedp ? sat_long_accum_type_node : long_accum_type_node;
2916 if (mode == TYPE_MODE (long_long_accum_type_node))
2917 return unsignedp ? sat_long_long_accum_type_node
2918 : long_long_accum_type_node;
2919
2920 if (mode == TYPE_MODE (unsigned_short_accum_type_node))
2921 return unsignedp ? sat_unsigned_short_accum_type_node
2922 : unsigned_short_accum_type_node;
2923 if (mode == TYPE_MODE (unsigned_accum_type_node))
2924 return unsignedp ? sat_unsigned_accum_type_node
2925 : unsigned_accum_type_node;
2926 if (mode == TYPE_MODE (unsigned_long_accum_type_node))
2927 return unsignedp ? sat_unsigned_long_accum_type_node
2928 : unsigned_long_accum_type_node;
2929 if (mode == TYPE_MODE (unsigned_long_long_accum_type_node))
2930 return unsignedp ? sat_unsigned_long_long_accum_type_node
2931 : unsigned_long_long_accum_type_node;
2932
2933 if (mode == QQmode)
2934 return unsignedp ? sat_qq_type_node : qq_type_node;
2935 if (mode == HQmode)
2936 return unsignedp ? sat_hq_type_node : hq_type_node;
2937 if (mode == SQmode)
2938 return unsignedp ? sat_sq_type_node : sq_type_node;
2939 if (mode == DQmode)
2940 return unsignedp ? sat_dq_type_node : dq_type_node;
2941 if (mode == TQmode)
2942 return unsignedp ? sat_tq_type_node : tq_type_node;
2943
2944 if (mode == UQQmode)
2945 return unsignedp ? sat_uqq_type_node : uqq_type_node;
2946 if (mode == UHQmode)
2947 return unsignedp ? sat_uhq_type_node : uhq_type_node;
2948 if (mode == USQmode)
2949 return unsignedp ? sat_usq_type_node : usq_type_node;
2950 if (mode == UDQmode)
2951 return unsignedp ? sat_udq_type_node : udq_type_node;
2952 if (mode == UTQmode)
2953 return unsignedp ? sat_utq_type_node : utq_type_node;
2954
2955 if (mode == HAmode)
2956 return unsignedp ? sat_ha_type_node : ha_type_node;
2957 if (mode == SAmode)
2958 return unsignedp ? sat_sa_type_node : sa_type_node;
2959 if (mode == DAmode)
2960 return unsignedp ? sat_da_type_node : da_type_node;
2961 if (mode == TAmode)
2962 return unsignedp ? sat_ta_type_node : ta_type_node;
2963
2964 if (mode == UHAmode)
2965 return unsignedp ? sat_uha_type_node : uha_type_node;
2966 if (mode == USAmode)
2967 return unsignedp ? sat_usa_type_node : usa_type_node;
2968 if (mode == UDAmode)
2969 return unsignedp ? sat_uda_type_node : uda_type_node;
2970 if (mode == UTAmode)
2971 return unsignedp ? sat_uta_type_node : uta_type_node;
2972 }
2973
5b247e9f 2974 for (t = registered_builtin_types; t; t = TREE_CHAIN (t))
2975 if (TYPE_MODE (TREE_VALUE (t)) == mode)
2976 return TREE_VALUE (t);
2977
b0fc3e72 2978 return 0;
2979}
20d39783 2980
11773141 2981tree
2982c_common_unsigned_type (tree type)
2983{
2984 return c_common_signed_or_unsigned_type (1, type);
2985}
2986
20d39783 2987/* Return a signed type the same as TYPE in other respects. */
2988
2989tree
1cae46be 2990c_common_signed_type (tree type)
20d39783 2991{
4070745f 2992 return c_common_signed_or_unsigned_type (0, type);
20d39783 2993}
2994
2995/* Return a type the same as TYPE except unsigned or
2996 signed according to UNSIGNEDP. */
2997
2998tree
1cae46be 2999c_common_signed_or_unsigned_type (int unsignedp, tree type)
20d39783 3000{
7a91101f 3001 tree type1;
20d39783 3002
7a91101f 3003 /* This block of code emulates the behavior of the old
3004 c_common_unsigned_type. In particular, it returns
3005 long_unsigned_type_node if passed a long, even when a int would
3006 have the same size. This is necessary for warnings to work
3007 correctly in archs where sizeof(int) == sizeof(long) */
3008
3009 type1 = TYPE_MAIN_VARIANT (type);
3010 if (type1 == signed_char_type_node || type1 == char_type_node || type1 == unsigned_char_type_node)
3011 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
3012 if (type1 == integer_type_node || type1 == unsigned_type_node)
3013 return unsignedp ? unsigned_type_node : integer_type_node;
3014 if (type1 == short_integer_type_node || type1 == short_unsigned_type_node)
3015 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
3016 if (type1 == long_integer_type_node || type1 == long_unsigned_type_node)
3017 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
3018 if (type1 == long_long_integer_type_node || type1 == long_long_unsigned_type_node)
3019 return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;
6388cfe2 3020 if (int128_integer_type_node
3021 && (type1 == int128_integer_type_node
3022 || type1 == int128_unsigned_type_node))
3023 return unsignedp ? int128_unsigned_type_node : int128_integer_type_node;
7a91101f 3024 if (type1 == widest_integer_literal_type_node || type1 == widest_unsigned_literal_type_node)
3025 return unsignedp ? widest_unsigned_literal_type_node : widest_integer_literal_type_node;
3026#if HOST_BITS_PER_WIDE_INT >= 64
3027 if (type1 == intTI_type_node || type1 == unsigned_intTI_type_node)
3028 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
3029#endif
3030 if (type1 == intDI_type_node || type1 == unsigned_intDI_type_node)
3031 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
3032 if (type1 == intSI_type_node || type1 == unsigned_intSI_type_node)
3033 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
3034 if (type1 == intHI_type_node || type1 == unsigned_intHI_type_node)
3035 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
3036 if (type1 == intQI_type_node || type1 == unsigned_intQI_type_node)
3037 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
3038
9f92e1a2 3039#define C_COMMON_FIXED_TYPES(NAME) \
3040 if (type1 == short_ ## NAME ## _type_node \
3041 || type1 == unsigned_short_ ## NAME ## _type_node) \
3042 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
3043 : short_ ## NAME ## _type_node; \
3044 if (type1 == NAME ## _type_node \
3045 || type1 == unsigned_ ## NAME ## _type_node) \
3046 return unsignedp ? unsigned_ ## NAME ## _type_node \
3047 : NAME ## _type_node; \
3048 if (type1 == long_ ## NAME ## _type_node \
3049 || type1 == unsigned_long_ ## NAME ## _type_node) \
3050 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
3051 : long_ ## NAME ## _type_node; \
3052 if (type1 == long_long_ ## NAME ## _type_node \
3053 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
3054 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
3055 : long_long_ ## NAME ## _type_node;
3056
3057#define C_COMMON_FIXED_MODE_TYPES(NAME) \
3058 if (type1 == NAME ## _type_node \
3059 || type1 == u ## NAME ## _type_node) \
3060 return unsignedp ? u ## NAME ## _type_node \
3061 : NAME ## _type_node;
3062
3063#define C_COMMON_FIXED_TYPES_SAT(NAME) \
3064 if (type1 == sat_ ## short_ ## NAME ## _type_node \
3065 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
3066 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
3067 : sat_ ## short_ ## NAME ## _type_node; \
3068 if (type1 == sat_ ## NAME ## _type_node \
3069 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
3070 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
3071 : sat_ ## NAME ## _type_node; \
3072 if (type1 == sat_ ## long_ ## NAME ## _type_node \
3073 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
3074 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
3075 : sat_ ## long_ ## NAME ## _type_node; \
3076 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
3077 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
3078 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
3079 : sat_ ## long_long_ ## NAME ## _type_node;
3080
3081#define C_COMMON_FIXED_MODE_TYPES_SAT(NAME) \
3082 if (type1 == sat_ ## NAME ## _type_node \
3083 || type1 == sat_ ## u ## NAME ## _type_node) \
3084 return unsignedp ? sat_ ## u ## NAME ## _type_node \
3085 : sat_ ## NAME ## _type_node;
3086
3087 C_COMMON_FIXED_TYPES (fract);
3088 C_COMMON_FIXED_TYPES_SAT (fract);
3089 C_COMMON_FIXED_TYPES (accum);
3090 C_COMMON_FIXED_TYPES_SAT (accum);
3091
3092 C_COMMON_FIXED_MODE_TYPES (qq);
3093 C_COMMON_FIXED_MODE_TYPES (hq);
3094 C_COMMON_FIXED_MODE_TYPES (sq);
3095 C_COMMON_FIXED_MODE_TYPES (dq);
3096 C_COMMON_FIXED_MODE_TYPES (tq);
3097 C_COMMON_FIXED_MODE_TYPES_SAT (qq);
3098 C_COMMON_FIXED_MODE_TYPES_SAT (hq);
3099 C_COMMON_FIXED_MODE_TYPES_SAT (sq);
3100 C_COMMON_FIXED_MODE_TYPES_SAT (dq);
3101 C_COMMON_FIXED_MODE_TYPES_SAT (tq);
3102 C_COMMON_FIXED_MODE_TYPES (ha);
3103 C_COMMON_FIXED_MODE_TYPES (sa);
3104 C_COMMON_FIXED_MODE_TYPES (da);
3105 C_COMMON_FIXED_MODE_TYPES (ta);
3106 C_COMMON_FIXED_MODE_TYPES_SAT (ha);
3107 C_COMMON_FIXED_MODE_TYPES_SAT (sa);
3108 C_COMMON_FIXED_MODE_TYPES_SAT (da);
3109 C_COMMON_FIXED_MODE_TYPES_SAT (ta);
9421ebb9 3110
4f7f7efd 3111 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
3112 the precision; they have precision set to match their range, but
3113 may use a wider mode to match an ABI. If we change modes, we may
3114 wind up with bad conversions. For INTEGER_TYPEs in C, must check
3115 the precision as well, so as to yield correct results for
3116 bit-field types. C++ does not have these separate bit-field
3117 types, and producing a signed or unsigned variant of an
3118 ENUMERAL_TYPE may cause other problems as well. */
3119
ac265864 3120 if (!INTEGRAL_TYPE_P (type)
3121 || TYPE_UNSIGNED (type) == unsignedp)
3122 return type;
3123
4f7f7efd 3124#define TYPE_OK(node) \
3125 (TYPE_MODE (type) == TYPE_MODE (node) \
0c4abe5b 3126 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
4f7f7efd 3127 if (TYPE_OK (signed_char_type_node))
20d39783 3128 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
4f7f7efd 3129 if (TYPE_OK (integer_type_node))
20d39783 3130 return unsignedp ? unsigned_type_node : integer_type_node;
4f7f7efd 3131 if (TYPE_OK (short_integer_type_node))
20d39783 3132 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
4f7f7efd 3133 if (TYPE_OK (long_integer_type_node))
20d39783 3134 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
4f7f7efd 3135 if (TYPE_OK (long_long_integer_type_node))
20d39783 3136 return (unsignedp ? long_long_unsigned_type_node
3137 : long_long_integer_type_node);
6388cfe2 3138 if (int128_integer_type_node && TYPE_OK (int128_integer_type_node))
3139 return (unsignedp ? int128_unsigned_type_node
3140 : int128_integer_type_node);
4f7f7efd 3141 if (TYPE_OK (widest_integer_literal_type_node))
20d39783 3142 return (unsignedp ? widest_unsigned_literal_type_node
3143 : widest_integer_literal_type_node);
ef11801e 3144
3145#if HOST_BITS_PER_WIDE_INT >= 64
4f7f7efd 3146 if (TYPE_OK (intTI_type_node))
ef11801e 3147 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
3148#endif
4f7f7efd 3149 if (TYPE_OK (intDI_type_node))
ef11801e 3150 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
4f7f7efd 3151 if (TYPE_OK (intSI_type_node))
ef11801e 3152 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
4f7f7efd 3153 if (TYPE_OK (intHI_type_node))
ef11801e 3154 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
4f7f7efd 3155 if (TYPE_OK (intQI_type_node))
ef11801e 3156 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
4f7f7efd 3157#undef TYPE_OK
ef11801e 3158
0c4abe5b 3159 return build_nonstandard_integer_type (TYPE_PRECISION (type), unsignedp);
20d39783 3160}
b268e47e 3161
c0e47fd4 3162/* Build a bit-field integer type for the given WIDTH and UNSIGNEDP. */
3163
3164tree
3165c_build_bitfield_integer_type (unsigned HOST_WIDE_INT width, int unsignedp)
3166{
3167 /* Extended integer types of the same width as a standard type have
3168 lesser rank, so those of the same width as int promote to int or
3169 unsigned int and are valid for printf formats expecting int or
3170 unsigned int. To avoid such special cases, avoid creating
3171 extended integer types for bit-fields if a standard integer type
3172 is available. */
3173 if (width == TYPE_PRECISION (integer_type_node))
3174 return unsignedp ? unsigned_type_node : integer_type_node;
3175 if (width == TYPE_PRECISION (signed_char_type_node))
3176 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
3177 if (width == TYPE_PRECISION (short_integer_type_node))
3178 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
3179 if (width == TYPE_PRECISION (long_integer_type_node))
3180 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
3181 if (width == TYPE_PRECISION (long_long_integer_type_node))
3182 return (unsignedp ? long_long_unsigned_type_node
3183 : long_long_integer_type_node);
6388cfe2 3184 if (int128_integer_type_node
3185 && width == TYPE_PRECISION (int128_integer_type_node))
3186 return (unsignedp ? int128_unsigned_type_node
3187 : int128_integer_type_node);
c0e47fd4 3188 return build_nonstandard_integer_type (width, unsignedp);
3189}
3190
b268e47e 3191/* The C version of the register_builtin_type langhook. */
3192
3193void
3194c_register_builtin_type (tree type, const char* name)
3195{
3196 tree decl;
3197
e60a6f7b 3198 decl = build_decl (UNKNOWN_LOCATION,
3199 TYPE_DECL, get_identifier (name), type);
b268e47e 3200 DECL_ARTIFICIAL (decl) = 1;
3201 if (!TYPE_NAME (type))
3202 TYPE_NAME (type) = decl;
3203 pushdecl (decl);
5b247e9f 3204
3205 registered_builtin_types = tree_cons (0, type, registered_builtin_types);
b268e47e 3206}
a9b9d10c 3207\f
aff9e656 3208/* Print an error message for invalid operands to arith operation
8e70fb09 3209 CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
3210 LOCATION is the location of the message. */
b0fc3e72 3211
3212void
8e70fb09 3213binary_op_error (location_t location, enum tree_code code,
3214 tree type0, tree type1)
b0fc3e72 3215{
19cb6b50 3216 const char *opname;
f03946e4 3217
b0fc3e72 3218 switch (code)
3219 {
b0fc3e72 3220 case PLUS_EXPR:
3221 opname = "+"; break;
3222 case MINUS_EXPR:
3223 opname = "-"; break;
3224 case MULT_EXPR:
3225 opname = "*"; break;
3226 case MAX_EXPR:
3227 opname = "max"; break;
3228 case MIN_EXPR:
3229 opname = "min"; break;
3230 case EQ_EXPR:
3231 opname = "=="; break;
3232 case NE_EXPR:
3233 opname = "!="; break;
3234 case LE_EXPR:
3235 opname = "<="; break;
3236 case GE_EXPR:
3237 opname = ">="; break;
3238 case LT_EXPR:
3239 opname = "<"; break;
3240 case GT_EXPR:
3241 opname = ">"; break;
3242 case LSHIFT_EXPR:
3243 opname = "<<"; break;
3244 case RSHIFT_EXPR:
3245 opname = ">>"; break;
3246 case TRUNC_MOD_EXPR:
66618a1e 3247 case FLOOR_MOD_EXPR:
b0fc3e72 3248 opname = "%"; break;
3249 case TRUNC_DIV_EXPR:
66618a1e 3250 case FLOOR_DIV_EXPR:
b0fc3e72 3251 opname = "/"; break;
3252 case BIT_AND_EXPR:
3253 opname = "&"; break;
3254 case BIT_IOR_EXPR:
3255 opname = "|"; break;
3256 case TRUTH_ANDIF_EXPR:
3257 opname = "&&"; break;
3258 case TRUTH_ORIF_EXPR:
3259 opname = "||"; break;
3260 case BIT_XOR_EXPR:
3261 opname = "^"; break;
31f820d2 3262 default:
315ba355 3263 gcc_unreachable ();
b0fc3e72 3264 }
8e70fb09 3265 error_at (location,
3266 "invalid operands to binary %s (have %qT and %qT)", opname,
3267 type0, type1);
b0fc3e72 3268}
3269\f
3270/* Subroutine of build_binary_op, used for comparison operations.
3271 See if the operands have both been converted from subword integer types
3272 and, if so, perhaps change them both back to their original type.
5b511807 3273 This function is also responsible for converting the two operands
3274 to the proper common type for comparison.
b0fc3e72 3275
3276 The arguments of this function are all pointers to local variables
3277 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
3278 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
3279
3280 If this function returns nonzero, it means that the comparison has
3281 a constant value. What this function returns is an expression for
3282 that value. */
3283
3284tree
1cae46be 3285shorten_compare (tree *op0_ptr, tree *op1_ptr, tree *restype_ptr,
3286 enum tree_code *rescode_ptr)
b0fc3e72 3287{
19cb6b50 3288 tree type;
b0fc3e72 3289 tree op0 = *op0_ptr;
3290 tree op1 = *op1_ptr;
3291 int unsignedp0, unsignedp1;
3292 int real1, real2;
3293 tree primop0, primop1;
3294 enum tree_code code = *rescode_ptr;
3295
3296 /* Throw away any conversions to wider types
3297 already present in the operands. */
3298
3299 primop0 = get_narrower (op0, &unsignedp0);
3300 primop1 = get_narrower (op1, &unsignedp1);
3301
3302 /* Handle the case that OP0 does not *contain* a conversion
3303 but it *requires* conversion to FINAL_TYPE. */
3304
3305 if (op0 == primop0 && TREE_TYPE (op0) != *restype_ptr)
78a8ed03 3306 unsignedp0 = TYPE_UNSIGNED (TREE_TYPE (op0));
b0fc3e72 3307 if (op1 == primop1 && TREE_TYPE (op1) != *restype_ptr)
78a8ed03 3308 unsignedp1 = TYPE_UNSIGNED (TREE_TYPE (op1));
b0fc3e72 3309
3310 /* If one of the operands must be floated, we cannot optimize. */
3311 real1 = TREE_CODE (TREE_TYPE (primop0)) == REAL_TYPE;
3312 real2 = TREE_CODE (TREE_TYPE (primop1)) == REAL_TYPE;
3313
3314 /* If first arg is constant, swap the args (changing operation
2bd278cc 3315 so value is preserved), for canonicalization. Don't do this if
3316 the second arg is 0. */
b0fc3e72 3317
2bd278cc 3318 if (TREE_CONSTANT (primop0)
9421ebb9 3319 && !integer_zerop (primop1) && !real_zerop (primop1)
3320 && !fixed_zerop (primop1))
b0fc3e72 3321 {
19cb6b50 3322 tree tem = primop0;
3323 int temi = unsignedp0;
b0fc3e72 3324 primop0 = primop1;
3325 primop1 = tem;
3326 tem = op0;
3327 op0 = op1;
3328 op1 = tem;
3329 *op0_ptr = op0;
3330 *op1_ptr = op1;
3331 unsignedp0 = unsignedp1;
3332 unsignedp1 = temi;
3333 temi = real1;
3334 real1 = real2;
3335 real2 = temi;
3336
3337 switch (code)
3338 {
3339 case LT_EXPR:
3340 code = GT_EXPR;
3341 break;
3342 case GT_EXPR:
3343 code = LT_EXPR;
3344 break;
3345 case LE_EXPR:
3346 code = GE_EXPR;
3347 break;
3348 case GE_EXPR:
3349 code = LE_EXPR;
3350 break;
31f820d2 3351 default:
3352 break;
b0fc3e72 3353 }
3354 *rescode_ptr = code;
3355 }
3356
3357 /* If comparing an integer against a constant more bits wide,
3358 maybe we can deduce a value of 1 or 0 independent of the data.
3359 Or else truncate the constant now
3360 rather than extend the variable at run time.
3361
3362 This is only interesting if the constant is the wider arg.
3363 Also, it is not safe if the constant is unsigned and the
3364 variable arg is signed, since in this case the variable
3365 would be sign-extended and then regarded as unsigned.
3366 Our technique fails in this case because the lowest/highest
3367 possible unsigned results don't follow naturally from the
3368 lowest/highest possible values of the variable operand.
3369 For just EQ_EXPR and NE_EXPR there is another technique that
3370 could be used: see if the constant can be faithfully represented
3371 in the other operand's type, by truncating it and reextending it
3372 and see if that preserves the constant's value. */
3373
3374 if (!real1 && !real2
9421ebb9 3375 && TREE_CODE (TREE_TYPE (primop0)) != FIXED_POINT_TYPE
b0fc3e72 3376 && TREE_CODE (primop1) == INTEGER_CST
3377 && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr))
3378 {
3379 int min_gt, max_gt, min_lt, max_lt;
3380 tree maxval, minval;
3381 /* 1 if comparison is nominally unsigned. */
78a8ed03 3382 int unsignedp = TYPE_UNSIGNED (*restype_ptr);
b0fc3e72 3383 tree val;
3384
4070745f 3385 type = c_common_signed_or_unsigned_type (unsignedp0,
3386 TREE_TYPE (primop0));
cda09c61 3387
b0fc3e72 3388 maxval = TYPE_MAX_VALUE (type);
3389 minval = TYPE_MIN_VALUE (type);
3390
3391 if (unsignedp && !unsignedp0)
4070745f 3392 *restype_ptr = c_common_signed_type (*restype_ptr);
b0fc3e72 3393
3394 if (TREE_TYPE (primop1) != *restype_ptr)
18dbec6f 3395 {
9a5e8086 3396 /* Convert primop1 to target type, but do not introduce
3397 additional overflow. We know primop1 is an int_cst. */
c8110c8f 3398 primop1 = force_fit_type_double (*restype_ptr,
d3237426 3399 tree_to_double_int (primop1),
3400 0, TREE_OVERFLOW (primop1));
18dbec6f 3401 }
b0fc3e72 3402 if (type != *restype_ptr)
3403 {
3404 minval = convert (*restype_ptr, minval);
3405 maxval = convert (*restype_ptr, maxval);
3406 }
3407
3408 if (unsignedp && unsignedp0)
3409 {
3410 min_gt = INT_CST_LT_UNSIGNED (primop1, minval);
3411 max_gt = INT_CST_LT_UNSIGNED (primop1, maxval);
3412 min_lt = INT_CST_LT_UNSIGNED (minval, primop1);
3413 max_lt = INT_CST_LT_UNSIGNED (maxval, primop1);
3414 }
3415 else
3416 {
3417 min_gt = INT_CST_LT (primop1, minval);
3418 max_gt = INT_CST_LT (primop1, maxval);
3419 min_lt = INT_CST_LT (minval, primop1);
3420 max_lt = INT_CST_LT (maxval, primop1);
3421 }
3422
3423 val = 0;
3424 /* This used to be a switch, but Genix compiler can't handle that. */
3425 if (code == NE_EXPR)
3426 {
3427 if (max_lt || min_gt)
3c2239cf 3428 val = truthvalue_true_node;
b0fc3e72 3429 }
3430 else if (code == EQ_EXPR)
3431 {
3432 if (max_lt || min_gt)
3c2239cf 3433 val = truthvalue_false_node;
b0fc3e72 3434 }
3435 else if (code == LT_EXPR)
3436 {
3437 if (max_lt)
3c2239cf 3438 val = truthvalue_true_node;
b0fc3e72 3439 if (!min_lt)
3c2239cf 3440 val = truthvalue_false_node;
b0fc3e72 3441 }
3442 else if (code == GT_EXPR)
3443 {
3444 if (min_gt)
3c2239cf 3445 val = truthvalue_true_node;
b0fc3e72 3446 if (!max_gt)
3c2239cf 3447 val = truthvalue_false_node;
b0fc3e72 3448 }
3449 else if (code == LE_EXPR)
3450 {
3451 if (!max_gt)
3c2239cf 3452 val = truthvalue_true_node;
b0fc3e72 3453 if (min_gt)
3c2239cf 3454 val = truthvalue_false_node;
b0fc3e72 3455 }
3456 else if (code == GE_EXPR)
3457 {
3458 if (!min_lt)
3c2239cf 3459 val = truthvalue_true_node;
b0fc3e72 3460 if (max_lt)
3c2239cf 3461 val = truthvalue_false_node;
b0fc3e72 3462 }
3463
3464 /* If primop0 was sign-extended and unsigned comparison specd,
3465 we did a signed comparison above using the signed type bounds.
3466 But the comparison we output must be unsigned.
3467
3468 Also, for inequalities, VAL is no good; but if the signed
3469 comparison had *any* fixed result, it follows that the
3470 unsigned comparison just tests the sign in reverse
3471 (positive values are LE, negative ones GE).
3472 So we can generate an unsigned comparison
3473 against an extreme value of the signed type. */
3474
3475 if (unsignedp && !unsignedp0)
3476 {
3477 if (val != 0)
3478 switch (code)
3479 {
3480 case LT_EXPR:
3481 case GE_EXPR:
3482 primop1 = TYPE_MIN_VALUE (type);
3483 val = 0;
3484 break;
3485
3486 case LE_EXPR:
3487 case GT_EXPR:
3488 primop1 = TYPE_MAX_VALUE (type);
3489 val = 0;
3490 break;
31f820d2 3491
3492 default:
3493 break;
b0fc3e72 3494 }
11773141 3495 type = c_common_unsigned_type (type);
b0fc3e72 3496 }
3497
fe5f2366 3498 if (TREE_CODE (primop0) != INTEGER_CST)
b0fc3e72 3499 {
3c2239cf 3500 if (val == truthvalue_false_node)
e6e352cb 3501 warning (OPT_Wtype_limits, "comparison is always false due to limited range of data type");
3c2239cf 3502 if (val == truthvalue_true_node)
e6e352cb 3503 warning (OPT_Wtype_limits, "comparison is always true due to limited range of data type");
b0fc3e72 3504 }
3505
3506 if (val != 0)
3507 {
3508 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
3509 if (TREE_SIDE_EFFECTS (primop0))
14ae0310 3510 return build2 (COMPOUND_EXPR, TREE_TYPE (val), primop0, val);
b0fc3e72 3511 return val;
3512 }
3513
3514 /* Value is not predetermined, but do the comparison
3515 in the type of the operand that is not constant.
3516 TYPE is already properly set. */
3517 }
c4503c0a 3518
3519 /* If either arg is decimal float and the other is float, find the
3520 proper common type to use for comparison. */
3521 else if (real1 && real2
3522 && (DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0)))
3523 || DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1)))))
3524 type = common_type (TREE_TYPE (primop0), TREE_TYPE (primop1));
3525
b0fc3e72 3526 else if (real1 && real2
2203bd5c 3527 && (TYPE_PRECISION (TREE_TYPE (primop0))
3528 == TYPE_PRECISION (TREE_TYPE (primop1))))
b0fc3e72 3529 type = TREE_TYPE (primop0);
3530
3531 /* If args' natural types are both narrower than nominal type
3532 and both extend in the same manner, compare them
3533 in the type of the wider arg.
3534 Otherwise must actually extend both to the nominal
3535 common type lest different ways of extending
3536 alter the result.
3537 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
3538
3539 else if (unsignedp0 == unsignedp1 && real1 == real2
3540 && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr)
3541 && TYPE_PRECISION (TREE_TYPE (primop1)) < TYPE_PRECISION (*restype_ptr))
3542 {
3543 type = common_type (TREE_TYPE (primop0), TREE_TYPE (primop1));
4070745f 3544 type = c_common_signed_or_unsigned_type (unsignedp0
78a8ed03 3545 || TYPE_UNSIGNED (*restype_ptr),
4070745f 3546 type);
b0fc3e72 3547 /* Make sure shorter operand is extended the right way
3548 to match the longer operand. */
4070745f 3549 primop0
3550 = convert (c_common_signed_or_unsigned_type (unsignedp0,
3551 TREE_TYPE (primop0)),
3552 primop0);
3553 primop1
3554 = convert (c_common_signed_or_unsigned_type (unsignedp1,
3555 TREE_TYPE (primop1)),
3556 primop1);
b0fc3e72 3557 }
3558 else
3559 {
3560 /* Here we must do the comparison on the nominal type
3561 using the args exactly as we received them. */
3562 type = *restype_ptr;
3563 primop0 = op0;
3564 primop1 = op1;
3565
3566 if (!real1 && !real2 && integer_zerop (primop1)
78a8ed03 3567 && TYPE_UNSIGNED (*restype_ptr))
b0fc3e72 3568 {
3569 tree value = 0;
3570 switch (code)
3571 {
3572 case GE_EXPR:
e6e352cb 3573 /* All unsigned values are >= 0, so we warn. However,
3574 if OP0 is a constant that is >= 0, the signedness of
3575 the comparison isn't an issue, so suppress the
3576 warning. */
3577 if (warn_type_limits && !in_system_header
84166705 3578 && !(TREE_CODE (primop0) == INTEGER_CST
3579 && !TREE_OVERFLOW (convert (c_common_signed_type (type),
3580 primop0))))
48e1416a 3581 warning (OPT_Wtype_limits,
e6e352cb 3582 "comparison of unsigned expression >= 0 is always true");
3c2239cf 3583 value = truthvalue_true_node;
b0fc3e72 3584 break;
3585
3586 case LT_EXPR:
e6e352cb 3587 if (warn_type_limits && !in_system_header
84166705 3588 && !(TREE_CODE (primop0) == INTEGER_CST
3589 && !TREE_OVERFLOW (convert (c_common_signed_type (type),
3590 primop0))))
48e1416a 3591 warning (OPT_Wtype_limits,
e6e352cb 3592 "comparison of unsigned expression < 0 is always false");
3c2239cf 3593 value = truthvalue_false_node;
31f820d2 3594 break;
3595
3596 default:
3597 break;
b0fc3e72 3598 }
3599
3600 if (value != 0)
3601 {
3602 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
3603 if (TREE_SIDE_EFFECTS (primop0))
14ae0310 3604 return build2 (COMPOUND_EXPR, TREE_TYPE (value),
3605 primop0, value);
b0fc3e72 3606 return value;
3607 }
3608 }
3609 }
3610
3611 *op0_ptr = convert (type, primop0);
3612 *op1_ptr = convert (type, primop1);
3613
3c2239cf 3614 *restype_ptr = truthvalue_type_node;
b0fc3e72 3615
3616 return 0;
3617}
3618\f
1c26100f 3619/* Return a tree for the sum or difference (RESULTCODE says which)
3620 of pointer PTROP and integer INTOP. */
3621
3622tree
389dd41b 3623pointer_int_sum (location_t loc, enum tree_code resultcode,
3624 tree ptrop, tree intop)
1c26100f 3625{
add6ee5e 3626 tree size_exp, ret;
1c26100f 3627
1c26100f 3628 /* The result is a pointer of the same type that is being added. */
1c26100f 3629 tree result_type = TREE_TYPE (ptrop);
3630
3631 if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE)
3632 {
48e1416a 3633 pedwarn (loc, pedantic ? OPT_pedantic : OPT_Wpointer_arith,
8864917d 3634 "pointer of type %<void *%> used in arithmetic");
1c26100f 3635 size_exp = integer_one_node;
3636 }
3637 else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE)
3638 {
48e1416a 3639 pedwarn (loc, pedantic ? OPT_pedantic : OPT_Wpointer_arith,
8864917d 3640 "pointer to a function used in arithmetic");
1c26100f 3641 size_exp = integer_one_node;
3642 }
3643 else if (TREE_CODE (TREE_TYPE (result_type)) == METHOD_TYPE)
3644 {
48e1416a 3645 pedwarn (loc, pedantic ? OPT_pedantic : OPT_Wpointer_arith,
8864917d 3646 "pointer to member function used in arithmetic");
1c26100f 3647 size_exp = integer_one_node;
3648 }
1c26100f 3649 else
3650 size_exp = size_in_bytes (TREE_TYPE (result_type));
3651
add6ee5e 3652 /* We are manipulating pointer values, so we don't need to warn
3653 about relying on undefined signed overflow. We disable the
3654 warning here because we use integer types so fold won't know that
3655 they are really pointers. */
3656 fold_defer_overflow_warnings ();
3657
1c26100f 3658 /* If what we are about to multiply by the size of the elements
3659 contains a constant term, apply distributive law
3660 and multiply that constant term separately.
3661 This helps produce common subexpressions. */
1c26100f 3662 if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR)
84166705 3663 && !TREE_CONSTANT (intop)
1c26100f 3664 && TREE_CONSTANT (TREE_OPERAND (intop, 1))
3665 && TREE_CONSTANT (size_exp)
3666 /* If the constant comes from pointer subtraction,
3667 skip this optimization--it would cause an error. */
3668 && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop, 0))) == INTEGER_TYPE
3669 /* If the constant is unsigned, and smaller than the pointer size,
3670 then we must skip this optimization. This is because it could cause
3671 an overflow error if the constant is negative but INTOP is not. */
84166705 3672 && (!TYPE_UNSIGNED (TREE_TYPE (intop))
1c26100f 3673 || (TYPE_PRECISION (TREE_TYPE (intop))
3674 == TYPE_PRECISION (TREE_TYPE (ptrop)))))
3675 {
3676 enum tree_code subcode = resultcode;
3677 tree int_type = TREE_TYPE (intop);
3678 if (TREE_CODE (intop) == MINUS_EXPR)
3679 subcode = (subcode == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR);
3680 /* Convert both subexpression types to the type of intop,
3681 because weird cases involving pointer arithmetic
3682 can result in a sum or difference with different type args. */
8e70fb09 3683 ptrop = build_binary_op (EXPR_LOCATION (TREE_OPERAND (intop, 1)),
3684 subcode, ptrop,
1c26100f 3685 convert (int_type, TREE_OPERAND (intop, 1)), 1);
3686 intop = convert (int_type, TREE_OPERAND (intop, 0));
3687 }
3688
3689 /* Convert the integer argument to a type the same size as sizetype
3690 so the multiply won't overflow spuriously. */
1c26100f 3691 if (TYPE_PRECISION (TREE_TYPE (intop)) != TYPE_PRECISION (sizetype)
78a8ed03 3692 || TYPE_UNSIGNED (TREE_TYPE (intop)) != TYPE_UNSIGNED (sizetype))
1cae46be 3693 intop = convert (c_common_type_for_size (TYPE_PRECISION (sizetype),
78a8ed03 3694 TYPE_UNSIGNED (sizetype)), intop);
1c26100f 3695
3696 /* Replace the integer argument with a suitable product by the object size.
c6feb9f1 3697 Do this multiplication as signed, then convert to the appropriate type
3698 for the pointer operation and disregard an overflow that occured only
3699 because of the sign-extension change in the latter conversion. */
3700 {
3701 tree t = build_binary_op (loc,
3702 MULT_EXPR, intop,
3703 convert (TREE_TYPE (intop), size_exp), 1);
3704 intop = convert (sizetype, t);
3705 if (TREE_OVERFLOW_P (intop) && !TREE_OVERFLOW (t))
3706 intop = build_int_cst_wide (TREE_TYPE (intop), TREE_INT_CST_LOW (intop),
3707 TREE_INT_CST_HIGH (intop));
3708 }
0de36bdb 3709
499e523f 3710 /* Create the sum or difference. */
0de36bdb 3711 if (resultcode == MINUS_EXPR)
389dd41b 3712 intop = fold_build1_loc (loc, NEGATE_EXPR, sizetype, intop);
1c26100f 3713
389dd41b 3714 ret = fold_build2_loc (loc, POINTER_PLUS_EXPR, result_type, ptrop, intop);
add6ee5e 3715
3716 fold_undefer_and_ignore_overflow_warnings ();
3717
3718 return ret;
1c26100f 3719}
3720\f
f59e3889 3721/* Wrap a C_MAYBE_CONST_EXPR around an expression that is fully folded
3722 and if NON_CONST is known not to be permitted in an evaluated part
3723 of a constant expression. */
3724
3725tree
3726c_wrap_maybe_const (tree expr, bool non_const)
3727{
3728 bool nowarning = TREE_NO_WARNING (expr);
3729 location_t loc = EXPR_LOCATION (expr);
3730
3731 /* This should never be called for C++. */
3732 if (c_dialect_cxx ())
3733 gcc_unreachable ();
3734
3735 /* The result of folding may have a NOP_EXPR to set TREE_NO_WARNING. */
3736 STRIP_TYPE_NOPS (expr);
3737 expr = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (expr), NULL, expr);
3738 C_MAYBE_CONST_EXPR_NON_CONST (expr) = non_const;
3739 if (nowarning)
3740 TREE_NO_WARNING (expr) = 1;
3741 protected_set_expr_location (expr, loc);
3742
3743 return expr;
3744}
3745
a75b1c71 3746/* Wrap a SAVE_EXPR around EXPR, if appropriate. Like save_expr, but
3747 for C folds the inside expression and wraps a C_MAYBE_CONST_EXPR
3748 around the SAVE_EXPR if needed so that c_fully_fold does not need
3749 to look inside SAVE_EXPRs. */
3750
3751tree
3752c_save_expr (tree expr)
3753{
3754 bool maybe_const = true;
3755 if (c_dialect_cxx ())
3756 return save_expr (expr);
3757 expr = c_fully_fold (expr, false, &maybe_const);
3758 expr = save_expr (expr);
3759 if (!maybe_const)
f59e3889 3760 expr = c_wrap_maybe_const (expr, true);
a75b1c71 3761 return expr;
3762}
3763
6b68e71a 3764/* Return whether EXPR is a declaration whose address can never be
3765 NULL. */
3766
3767bool
9f627b1a 3768decl_with_nonnull_addr_p (const_tree expr)
6b68e71a 3769{
3770 return (DECL_P (expr)
3771 && (TREE_CODE (expr) == PARM_DECL
3772 || TREE_CODE (expr) == LABEL_DECL
3773 || !DECL_WEAK (expr)));
3774}
3775
b0fc3e72 3776/* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
45a78cc0 3777 or for an `if' or `while' statement or ?..: exp. It should already
3778 have been validated to be of suitable type; otherwise, a bad
3779 diagnostic may result.
b0fc3e72 3780
8e70fb09 3781 The EXPR is located at LOCATION.
3782
b0fc3e72 3783 This preparation consists of taking the ordinary
3784 representation of an expression expr and producing a valid tree
3785 boolean expression describing whether expr is nonzero. We could
3c2239cf 3786 simply always do build_binary_op (NE_EXPR, expr, truthvalue_false_node, 1),
b0fc3e72 3787 but we optimize comparisons, &&, ||, and !.
3788
3c2239cf 3789 The resulting type should always be `truthvalue_type_node'. */
b0fc3e72 3790
3791tree
8e70fb09 3792c_common_truthvalue_conversion (location_t location, tree expr)
b0fc3e72 3793{
b0fc3e72 3794 switch (TREE_CODE (expr))
3795 {
318a728f 3796 case EQ_EXPR: case NE_EXPR: case UNEQ_EXPR: case LTGT_EXPR:
e1232ce2 3797 case LE_EXPR: case GE_EXPR: case LT_EXPR: case GT_EXPR:
3798 case UNLE_EXPR: case UNGE_EXPR: case UNLT_EXPR: case UNGT_EXPR:
3799 case ORDERED_EXPR: case UNORDERED_EXPR:
ce04dcdc 3800 if (TREE_TYPE (expr) == truthvalue_type_node)
3801 return expr;
e60a6f7b 3802 expr = build2 (TREE_CODE (expr), truthvalue_type_node,
ce04dcdc 3803 TREE_OPERAND (expr, 0), TREE_OPERAND (expr, 1));
e60a6f7b 3804 goto ret;
ce04dcdc 3805
b0fc3e72 3806 case TRUTH_ANDIF_EXPR:
3807 case TRUTH_ORIF_EXPR:
3808 case TRUTH_AND_EXPR:
3809 case TRUTH_OR_EXPR:
31f6e93c 3810 case TRUTH_XOR_EXPR:
ce04dcdc 3811 if (TREE_TYPE (expr) == truthvalue_type_node)
3812 return expr;
e60a6f7b 3813 expr = build2 (TREE_CODE (expr), truthvalue_type_node,
48e1416a 3814 c_common_truthvalue_conversion (location,
e60a6f7b 3815 TREE_OPERAND (expr, 0)),
3816 c_common_truthvalue_conversion (location,
3817 TREE_OPERAND (expr, 1)));
3818 goto ret;
3e851b85 3819
f6e28f72 3820 case TRUTH_NOT_EXPR:
ce04dcdc 3821 if (TREE_TYPE (expr) == truthvalue_type_node)
3822 return expr;
e60a6f7b 3823 expr = build1 (TREE_CODE (expr), truthvalue_type_node,
3824 c_common_truthvalue_conversion (location,
3825 TREE_OPERAND (expr, 0)));
3826 goto ret;
f6e28f72 3827
b0fc3e72 3828 case ERROR_MARK:
3829 return expr;
3830
3831 case INTEGER_CST:
eddad94a 3832 return integer_zerop (expr) ? truthvalue_false_node
3833 : truthvalue_true_node;
b0fc3e72 3834
3835 case REAL_CST:
5000e21c 3836 return real_compare (NE_EXPR, &TREE_REAL_CST (expr), &dconst0)
3837 ? truthvalue_true_node
3838 : truthvalue_false_node;
b0fc3e72 3839
9421ebb9 3840 case FIXED_CST:
3841 return fixed_compare (NE_EXPR, &TREE_FIXED_CST (expr),
3842 &FCONST0 (TYPE_MODE (TREE_TYPE (expr))))
3843 ? truthvalue_true_node
3844 : truthvalue_false_node;
3845
ce04dcdc 3846 case FUNCTION_DECL:
b6889cb0 3847 expr = build_unary_op (location, ADDR_EXPR, expr, 0);
ce04dcdc 3848 /* Fall through. */
3849
b0fc3e72 3850 case ADDR_EXPR:
ce871053 3851 {
ee7d4d6a 3852 tree inner = TREE_OPERAND (expr, 0);
6b68e71a 3853 if (decl_with_nonnull_addr_p (inner))
ce871053 3854 {
6b68e71a 3855 /* Common Ada/Pascal programmer's mistake. */
8e70fb09 3856 warning_at (location,
3857 OPT_Waddress,
3858 "the address of %qD will always evaluate as %<true%>",
3859 inner);
ce871053 3860 return truthvalue_true_node;
3861 }
d473d901 3862 break;
ce871053 3863 }
b0fc3e72 3864
2203bd5c 3865 case COMPLEX_EXPR:
e60a6f7b 3866 expr = build_binary_op (EXPR_LOCATION (expr),
8e70fb09 3867 (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1))
95809de4 3868 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
8e70fb09 3869 c_common_truthvalue_conversion (location,
3870 TREE_OPERAND (expr, 0)),
3871 c_common_truthvalue_conversion (location,
3872 TREE_OPERAND (expr, 1)),
2203bd5c 3873 0);
e60a6f7b 3874 goto ret;
2203bd5c 3875
b0fc3e72 3876 case NEGATE_EXPR:
3877 case ABS_EXPR:
3878 case FLOAT_EXPR:
c6418a4e 3879 case EXCESS_PRECISION_EXPR:
d10cfa8d 3880 /* These don't change whether an object is nonzero or zero. */
8e70fb09 3881 return c_common_truthvalue_conversion (location, TREE_OPERAND (expr, 0));
b0fc3e72 3882
3883 case LROTATE_EXPR:
3884 case RROTATE_EXPR:
d10cfa8d 3885 /* These don't change whether an object is zero or nonzero, but
b0fc3e72 3886 we can't ignore them if their second arg has side-effects. */
3887 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1)))
e60a6f7b 3888 {
3889 expr = build2 (COMPOUND_EXPR, truthvalue_type_node,
3890 TREE_OPERAND (expr, 1),
48e1416a 3891 c_common_truthvalue_conversion
e60a6f7b 3892 (location, TREE_OPERAND (expr, 0)));
3893 goto ret;
3894 }
b0fc3e72 3895 else
8e70fb09 3896 return c_common_truthvalue_conversion (location,
3897 TREE_OPERAND (expr, 0));
73be5127 3898
b0fc3e72 3899 case COND_EXPR:
3900 /* Distribute the conversion into the arms of a COND_EXPR. */
a75b1c71 3901 if (c_dialect_cxx ())
e60a6f7b 3902 {
389dd41b 3903 expr = fold_build3_loc (location, COND_EXPR, truthvalue_type_node,
e60a6f7b 3904 TREE_OPERAND (expr, 0),
3905 c_common_truthvalue_conversion (location,
3906 TREE_OPERAND (expr,
3907 1)),
3908 c_common_truthvalue_conversion (location,
3909 TREE_OPERAND (expr,
3910 2)));
3911 goto ret;
3912 }
a75b1c71 3913 else
e60a6f7b 3914 {
3915 /* Folding will happen later for C. */
3916 expr = build3 (COND_EXPR, truthvalue_type_node,
3917 TREE_OPERAND (expr, 0),
3918 c_common_truthvalue_conversion (location,
3919 TREE_OPERAND (expr, 1)),
3920 c_common_truthvalue_conversion (location,
3921 TREE_OPERAND (expr, 2)));
3922 goto ret;
3923 }
b0fc3e72 3924
72dd6141 3925 CASE_CONVERT:
b0fc3e72 3926 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
3927 since that affects how `default_conversion' will behave. */
3928 if (TREE_CODE (TREE_TYPE (expr)) == REFERENCE_TYPE
3929 || TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0))) == REFERENCE_TYPE)
3930 break;
b0fc3e72 3931 /* If this is widening the argument, we can ignore it. */
3932 if (TYPE_PRECISION (TREE_TYPE (expr))
3933 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0))))
8e70fb09 3934 return c_common_truthvalue_conversion (location,
3935 TREE_OPERAND (expr, 0));
b0fc3e72 3936 break;
3937
16837b18 3938 case MODIFY_EXPR:
60a0513e 3939 if (!TREE_NO_WARNING (expr)
3940 && warn_parentheses)
3941 {
3942 warning (OPT_Wparentheses,
3943 "suggest parentheses around assignment used as truth value");
3944 TREE_NO_WARNING (expr) = 1;
3945 }
16837b18 3946 break;
73be5127 3947
31f820d2 3948 default:
3949 break;
b0fc3e72 3950 }
3951
2ba726d2 3952 if (TREE_CODE (TREE_TYPE (expr)) == COMPLEX_TYPE)
a0748b7d 3953 {
93be21c0 3954 tree t = (in_late_binary_op ? save_expr (expr) : c_save_expr (expr));
e60a6f7b 3955 expr = (build_binary_op
8e70fb09 3956 (EXPR_LOCATION (expr),
3957 (TREE_SIDE_EFFECTS (expr)
a0748b7d 3958 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
b6889cb0 3959 c_common_truthvalue_conversion
3960 (location,
3961 build_unary_op (location, REALPART_EXPR, t, 0)),
3962 c_common_truthvalue_conversion
3963 (location,
3964 build_unary_op (location, IMAGPART_EXPR, t, 0)),
a0748b7d 3965 0));
e60a6f7b 3966 goto ret;
a0748b7d 3967 }
2ba726d2 3968
9421ebb9 3969 if (TREE_CODE (TREE_TYPE (expr)) == FIXED_POINT_TYPE)
3970 {
3971 tree fixed_zero_node = build_fixed (TREE_TYPE (expr),
3972 FCONST0 (TYPE_MODE
3973 (TREE_TYPE (expr))));
43158006 3974 return build_binary_op (location, NE_EXPR, expr, fixed_zero_node, 1);
9421ebb9 3975 }
e60a6f7b 3976 else
3977 return build_binary_op (location, NE_EXPR, expr, integer_zero_node, 1);
9421ebb9 3978
e60a6f7b 3979 ret:
3980 protected_set_expr_location (expr, location);
3981 return expr;
b0fc3e72 3982}
3983\f
3237155d 3984static void def_builtin_1 (enum built_in_function fncode,
3985 const char *name,
3986 enum built_in_class fnclass,
3987 tree fntype, tree libtype,
3988 bool both_p, bool fallback_p, bool nonansi_p,
3989 tree fnattrs, bool implicit_p);
0d4238dc 3990
a5b1863e 3991
3992/* Apply the TYPE_QUALS to the new DECL. */
3993
3994void
1cae46be 3995c_apply_type_quals_to_decl (int type_quals, tree decl)
a5b1863e 3996{
adfb367f 3997 tree type = TREE_TYPE (decl);
b27ac6b5 3998
e4eabbe4 3999 if (type == error_mark_node)
4000 return;
adfb367f 4001
4002 if (((type_quals & TYPE_QUAL_CONST)
4003 || (type && TREE_CODE (type) == REFERENCE_TYPE))
4004 /* An object declared 'const' is only readonly after it is
4005 initialized. We don't have any way of expressing this currently,
4006 so we need to be conservative and unset TREE_READONLY for types
4007 with constructors. Otherwise aliasing code will ignore stores in
4008 an inline constructor. */
4009 && !(type && TYPE_NEEDS_CONSTRUCTING (type)))
a5b1863e 4010 TREE_READONLY (decl) = 1;
4011 if (type_quals & TYPE_QUAL_VOLATILE)
4012 {
4013 TREE_SIDE_EFFECTS (decl) = 1;
4014 TREE_THIS_VOLATILE (decl) = 1;
4015 }
d91a20bc 4016 if (type_quals & TYPE_QUAL_RESTRICT)
a5b1863e 4017 {
adfb367f 4018 while (type && TREE_CODE (type) == ARRAY_TYPE)
4019 /* Allow 'restrict' on arrays of pointers.
4020 FIXME currently we just ignore it. */
4021 type = TREE_TYPE (type);
4022 if (!type
4023 || !POINTER_TYPE_P (type)
4024 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type)))
b0b1af64 4025 error ("invalid use of %<restrict%>");
a5b1863e 4026 }
4027}
4028
4ee9c684 4029/* Hash function for the problem of multiple type definitions in
4030 different files. This must hash all types that will compare
4031 equal via comptypes to the same value. In practice it hashes
0bed3869 4032 on some of the simple stuff and leaves the details to comptypes. */
4ee9c684 4033
4034static hashval_t
4035c_type_hash (const void *p)
4036{
4037 int i = 0;
4038 int shift, size;
aae87fc3 4039 const_tree const t = (const_tree) p;
4ee9c684 4040 tree t2;
4041 switch (TREE_CODE (t))
4042 {
fbf0afd1 4043 /* For pointers, hash on pointee type plus some swizzling. */
2363ef00 4044 case POINTER_TYPE:
4045 return c_type_hash (TREE_TYPE (t)) ^ 0x3003003;
4046 /* Hash on number of elements and total size. */
4047 case ENUMERAL_TYPE:
4048 shift = 3;
4049 t2 = TYPE_VALUES (t);
4050 break;
4051 case RECORD_TYPE:
4052 shift = 0;
4053 t2 = TYPE_FIELDS (t);
4054 break;
4055 case QUAL_UNION_TYPE:
4056 shift = 1;
4057 t2 = TYPE_FIELDS (t);
4058 break;
4059 case UNION_TYPE:
4060 shift = 2;
4061 t2 = TYPE_FIELDS (t);
4062 break;
4063 default:
231bd014 4064 gcc_unreachable ();
4ee9c684 4065 }
1767a056 4066 for (; t2; t2 = DECL_CHAIN (t2))
4ee9c684 4067 i++;
78c2e180 4068 /* We might have a VLA here. */
4069 if (TREE_CODE (TYPE_SIZE (t)) != INTEGER_CST)
4070 size = 0;
4071 else
4072 size = TREE_INT_CST_LOW (TYPE_SIZE (t));
4ee9c684 4073 return ((size << 24) | (i << shift));
4074}
4075
1ecd4018 4076static GTY((param_is (union tree_node))) htab_t type_hash_table;
4077
b5ba9f3a 4078/* Return the typed-based alias set for T, which may be an expression
f7c44134 4079 or a type. Return -1 if we don't do anything special. */
b5ba9f3a 4080
32c2fdea 4081alias_set_type
1cae46be 4082c_common_get_alias_set (tree t)
b5ba9f3a 4083{
be4f2de7 4084 tree u;
4ee9c684 4085 PTR *slot;
1cae46be 4086
e58c17e7 4087 /* For VLAs, use the alias set of the element type rather than the
4088 default of alias set 0 for types compared structurally. */
4089 if (TYPE_P (t) && TYPE_STRUCTURAL_EQUALITY_P (t))
4090 {
4091 if (TREE_CODE (t) == ARRAY_TYPE)
4092 return get_alias_set (TREE_TYPE (t));
4093 return -1;
4094 }
4095
be4f2de7 4096 /* Permit type-punning when accessing a union, provided the access
4097 is directly through the union. For example, this code does not
4098 permit taking the address of a union member and then storing
4099 through it. Even the type-punning allowed here is a GCC
4100 extension, albeit a common and useful one; the C standard says
4101 that such accesses have implementation-defined behavior. */
4102 for (u = t;
4103 TREE_CODE (u) == COMPONENT_REF || TREE_CODE (u) == ARRAY_REF;
4104 u = TREE_OPERAND (u, 0))
4105 if (TREE_CODE (u) == COMPONENT_REF
4106 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u, 0))) == UNION_TYPE)
4107 return 0;
1e2513d9 4108
9fcc3e54 4109 /* That's all the expressions we handle specially. */
84166705 4110 if (!TYPE_P (t))
9fcc3e54 4111 return -1;
4112
d716ce75 4113 /* The C standard guarantees that any object may be accessed via an
9fcc3e54 4114 lvalue that has character type. */
4115 if (t == char_type_node
4116 || t == signed_char_type_node
4117 || t == unsigned_char_type_node)
f7c44134 4118 return 0;
a5b1863e 4119
1607663f 4120 /* The C standard specifically allows aliasing between signed and
4121 unsigned variants of the same type. We treat the signed
4122 variant as canonical. */
78a8ed03 4123 if (TREE_CODE (t) == INTEGER_TYPE && TYPE_UNSIGNED (t))
a8868e19 4124 {
4070745f 4125 tree t1 = c_common_signed_type (t);
1607663f 4126
a8868e19 4127 /* t1 == t can happen for boolean nodes which are always unsigned. */
4128 if (t1 != t)
4129 return get_alias_set (t1);
4130 }
1e2513d9 4131
4ee9c684 4132 /* Handle the case of multiple type nodes referring to "the same" type,
4133 which occurs with IMA. These share an alias set. FIXME: Currently only
4134 C90 is handled. (In C99 type compatibility is not transitive, which
4135 complicates things mightily. The alias set splay trees can theoretically
4136 represent this, but insertion is tricky when you consider all the
4137 different orders things might arrive in.) */
4138
4139 if (c_language != clk_c || flag_isoc99)
4140 return -1;
4141
0bed3869 4142 /* Save time if there's only one input file. */
e08bd2f4 4143 if (num_in_fnames == 1)
4ee9c684 4144 return -1;
4145
4146 /* Pointers need special handling if they point to any type that
4147 needs special handling (below). */
4148 if (TREE_CODE (t) == POINTER_TYPE)
4149 {
4150 tree t2;
4151 /* Find bottom type under any nested POINTERs. */
b27ac6b5 4152 for (t2 = TREE_TYPE (t);
af592f67 4153 TREE_CODE (t2) == POINTER_TYPE;
4154 t2 = TREE_TYPE (t2))
4155 ;
b27ac6b5 4156 if (TREE_CODE (t2) != RECORD_TYPE
af592f67 4157 && TREE_CODE (t2) != ENUMERAL_TYPE
4158 && TREE_CODE (t2) != QUAL_UNION_TYPE
4159 && TREE_CODE (t2) != UNION_TYPE)
4160 return -1;
4ee9c684 4161 if (TYPE_SIZE (t2) == 0)
af592f67 4162 return -1;
4ee9c684 4163 }
4164 /* These are the only cases that need special handling. */
b27ac6b5 4165 if (TREE_CODE (t) != RECORD_TYPE
4ee9c684 4166 && TREE_CODE (t) != ENUMERAL_TYPE
4167 && TREE_CODE (t) != QUAL_UNION_TYPE
4168 && TREE_CODE (t) != UNION_TYPE
4169 && TREE_CODE (t) != POINTER_TYPE)
4170 return -1;
4171 /* Undefined? */
4172 if (TYPE_SIZE (t) == 0)
4173 return -1;
4174
b27ac6b5 4175 /* Look up t in hash table. Only one of the compatible types within each
4ee9c684 4176 alias set is recorded in the table. */
4177 if (!type_hash_table)
1ecd4018 4178 type_hash_table = htab_create_ggc (1021, c_type_hash,
4ee9c684 4179 (htab_eq) lang_hooks.types_compatible_p,
4180 NULL);
4181 slot = htab_find_slot (type_hash_table, t, INSERT);
4182 if (*slot != NULL)
ad16cb2c 4183 {
4184 TYPE_ALIAS_SET (t) = TYPE_ALIAS_SET ((tree)*slot);
4185 return TYPE_ALIAS_SET ((tree)*slot);
4186 }
4ee9c684 4187 else
4188 /* Our caller will assign and record (in t) a new alias set; all we need
4189 to do is remember t in the hash table. */
4190 *slot = t;
4191
f7c44134 4192 return -1;
b5ba9f3a 4193}
902b4e01 4194\f
e60a6f7b 4195/* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where
4196 the second parameter indicates which OPERATOR is being applied.
4197 The COMPLAIN flag controls whether we should diagnose possibly
4198 ill-formed constructs or not. LOC is the location of the SIZEOF or
4199 TYPEOF operator. */
908c697e 4200
902b4e01 4201tree
e60a6f7b 4202c_sizeof_or_alignof_type (location_t loc,
4203 tree type, bool is_sizeof, int complain)
902b4e01 4204{
d4c4d95c 4205 const char *op_name;
4206 tree value = NULL;
4207 enum tree_code type_code = TREE_CODE (type);
1cae46be 4208
908c697e 4209 op_name = is_sizeof ? "sizeof" : "__alignof__";
1cae46be 4210
d4c4d95c 4211 if (type_code == FUNCTION_TYPE)
902b4e01 4212 {
908c697e 4213 if (is_sizeof)
d4c4d95c 4214 {
d3a4d008 4215 if (complain && (pedantic || warn_pointer_arith))
48e1416a 4216 pedwarn (loc, pedantic ? OPT_pedantic : OPT_Wpointer_arith,
8864917d 4217 "invalid application of %<sizeof%> to a function type");
ebd21de4 4218 else if (!complain)
4219 return error_mark_node;
d4c4d95c 4220 value = size_one_node;
4221 }
4222 else
4223 value = size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
4224 }
4225 else if (type_code == VOID_TYPE || type_code == ERROR_MARK)
4226 {
1cae46be 4227 if (type_code == VOID_TYPE
d3a4d008 4228 && complain && (pedantic || warn_pointer_arith))
48e1416a 4229 pedwarn (loc, pedantic ? OPT_pedantic : OPT_Wpointer_arith,
8864917d 4230 "invalid application of %qs to a void type", op_name);
ebd21de4 4231 else if (!complain)
4232 return error_mark_node;
d4c4d95c 4233 value = size_one_node;
902b4e01 4234 }
902b4e01 4235 else if (!COMPLETE_TYPE_P (type))
4236 {
d3a4d008 4237 if (complain)
e60a6f7b 4238 error_at (loc, "invalid application of %qs to incomplete type %qT ",
4239 op_name, type);
9c719c74 4240 return error_mark_node;
902b4e01 4241 }
4242 else
d4c4d95c 4243 {
908c697e 4244 if (is_sizeof)
d4c4d95c 4245 /* Convert in case a char is more than one unit. */
389dd41b 4246 value = size_binop_loc (loc, CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
4247 size_int (TYPE_PRECISION (char_type_node)
4248 / BITS_PER_UNIT));
d4c4d95c 4249 else
d37625c0 4250 value = size_int (TYPE_ALIGN_UNIT (type));
d4c4d95c 4251 }
902b4e01 4252
d4c4d95c 4253 /* VALUE will have an integer type with TYPE_IS_SIZETYPE set.
4254 TYPE_IS_SIZETYPE means that certain things (like overflow) will
4255 never happen. However, this node should really have type
4256 `size_t', which is just a typedef for an ordinary integer type. */
389dd41b 4257 value = fold_convert_loc (loc, size_type_node, value);
1d8fc210 4258 gcc_assert (!TYPE_IS_SIZETYPE (TREE_TYPE (value)));
1cae46be 4259
d4c4d95c 4260 return value;
902b4e01 4261}
4262
4263/* Implement the __alignof keyword: Return the minimum required
097b5c8b 4264 alignment of EXPR, measured in bytes. For VAR_DECLs,
4265 FUNCTION_DECLs and FIELD_DECLs return DECL_ALIGN (which can be set
e60a6f7b 4266 from an "aligned" __attribute__ specification). LOC is the
4267 location of the ALIGNOF operator. */
72040e7e 4268
902b4e01 4269tree
e60a6f7b 4270c_alignof_expr (location_t loc, tree expr)
902b4e01 4271{
4272 tree t;
4273
097b5c8b 4274 if (VAR_OR_FUNCTION_DECL_P (expr))
d37625c0 4275 t = size_int (DECL_ALIGN_UNIT (expr));
1cae46be 4276
902b4e01 4277 else if (TREE_CODE (expr) == COMPONENT_REF
4278 && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1)))
4279 {
e60a6f7b 4280 error_at (loc, "%<__alignof%> applied to a bit-field");
902b4e01 4281 t = size_one_node;
4282 }
4283 else if (TREE_CODE (expr) == COMPONENT_REF
7cc7e163 4284 && TREE_CODE (TREE_OPERAND (expr, 1)) == FIELD_DECL)
d37625c0 4285 t = size_int (DECL_ALIGN_UNIT (TREE_OPERAND (expr, 1)));
1cae46be 4286
902b4e01 4287 else if (TREE_CODE (expr) == INDIRECT_REF)
4288 {
4289 tree t = TREE_OPERAND (expr, 0);
4290 tree best = t;
4291 int bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
1cae46be 4292
72dd6141 4293 while (CONVERT_EXPR_P (t)
7cc7e163 4294 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
902b4e01 4295 {
4296 int thisalign;
4297
4298 t = TREE_OPERAND (t, 0);
4299 thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
4300 if (thisalign > bestalign)
4301 best = t, bestalign = thisalign;
4302 }
e60a6f7b 4303 return c_alignof (loc, TREE_TYPE (TREE_TYPE (best)));
902b4e01 4304 }
4305 else
e60a6f7b 4306 return c_alignof (loc, TREE_TYPE (expr));
902b4e01 4307
389dd41b 4308 return fold_convert_loc (loc, size_type_node, t);
902b4e01 4309}
4310\f
8fe4a266 4311/* Handle C and C++ default attributes. */
4312
4313enum built_in_attribute
4314{
4315#define DEF_ATTR_NULL_TREE(ENUM) ENUM,
4316#define DEF_ATTR_INT(ENUM, VALUE) ENUM,
4317#define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
4318#define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
8fe4a266 4319#include "builtin-attrs.def"
4320#undef DEF_ATTR_NULL_TREE
4321#undef DEF_ATTR_INT
4322#undef DEF_ATTR_IDENT
4323#undef DEF_ATTR_TREE_LIST
8fe4a266 4324 ATTR_LAST
4325};
4326
4327static GTY(()) tree built_in_attributes[(int) ATTR_LAST];
4328
1cae46be 4329static void c_init_attributes (void);
8fe4a266 4330
27213ba3 4331enum c_builtin_type
72040e7e 4332{
d2d4bdde 4333#define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
4334#define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
4335#define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
4336#define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
4337#define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
4338#define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
0a39fd54 4339#define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
27213ba3 4340#define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) NAME,
4341#define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) NAME,
d2d4bdde 4342#define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
4343#define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
4344#define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
03901330 4345#define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
0a39fd54 4346#define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
4347#define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG6) \
4348 NAME,
d2d4bdde 4349#define DEF_POINTER_TYPE(NAME, TYPE) NAME,
4350#include "builtin-types.def"
4351#undef DEF_PRIMITIVE_TYPE
4352#undef DEF_FUNCTION_TYPE_0
4353#undef DEF_FUNCTION_TYPE_1
4354#undef DEF_FUNCTION_TYPE_2
4355#undef DEF_FUNCTION_TYPE_3
4356#undef DEF_FUNCTION_TYPE_4
0a39fd54 4357#undef DEF_FUNCTION_TYPE_5
4358#undef DEF_FUNCTION_TYPE_6
27213ba3 4359#undef DEF_FUNCTION_TYPE_7
d2d4bdde 4360#undef DEF_FUNCTION_TYPE_VAR_0
4361#undef DEF_FUNCTION_TYPE_VAR_1
4362#undef DEF_FUNCTION_TYPE_VAR_2
03901330 4363#undef DEF_FUNCTION_TYPE_VAR_3
0a39fd54 4364#undef DEF_FUNCTION_TYPE_VAR_4
4365#undef DEF_FUNCTION_TYPE_VAR_5
d2d4bdde 4366#undef DEF_POINTER_TYPE
27213ba3 4367 BT_LAST
4368};
4369
4370typedef enum c_builtin_type builtin_type;
d2d4bdde 4371
27213ba3 4372/* A temporary array for c_common_nodes_and_builtins. Used in
4373 communication with def_fn_type. */
4374static tree builtin_types[(int) BT_LAST + 1];
d2d4bdde 4375
27213ba3 4376/* A helper function for c_common_nodes_and_builtins. Build function type
4377 for DEF with return type RET and N arguments. If VAR is true, then the
4378 function should be variadic after those N arguments.
4379
4380 Takes special care not to ICE if any of the types involved are
4381 error_mark_node, which indicates that said type is not in fact available
4382 (see builtin_type_for_size). In which case the function type as a whole
4383 should be error_mark_node. */
4384
4385static void
4386def_fn_type (builtin_type def, builtin_type ret, bool var, int n, ...)
4387{
4388 tree args = NULL, t;
4389 va_list list;
4390 int i;
4391
4392 va_start (list, n);
4393 for (i = 0; i < n; ++i)
4394 {
7d339f93 4395 builtin_type a = (builtin_type) va_arg (list, int);
27213ba3 4396 t = builtin_types[a];
4397 if (t == error_mark_node)
4398 goto egress;
4399 args = tree_cons (NULL_TREE, t, args);
4400 }
4401 va_end (list);
4402
4403 args = nreverse (args);
4404 if (!var)
4405 args = chainon (args, void_list_node);
4406
4407 t = builtin_types[ret];
4408 if (t == error_mark_node)
4409 goto egress;
4410 t = build_function_type (t, args);
4411
4412 egress:
4413 builtin_types[def] = t;
4414}
4415
dce22712 4416/* Build builtin functions common to both C and C++ language
4417 frontends. */
4418
4419static void
4420c_define_builtins (tree va_list_ref_type_node, tree va_list_arg_type_node)
4421{
4422#define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
4423 builtin_types[ENUM] = VALUE;
4424#define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
4425 def_fn_type (ENUM, RETURN, 0, 0);
4426#define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
4427 def_fn_type (ENUM, RETURN, 0, 1, ARG1);
4428#define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
4429 def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
4430#define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
4431 def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
4432#define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
4433 def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
4434#define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
4435 def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
4436#define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4437 ARG6) \
4438 def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
4439#define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4440 ARG6, ARG7) \
4441 def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
4442#define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
4443 def_fn_type (ENUM, RETURN, 1, 0);
4444#define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
4445 def_fn_type (ENUM, RETURN, 1, 1, ARG1);
4446#define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
4447 def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
4448#define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
4449 def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
4450#define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
4451 def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
4452#define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
4453 def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
4454#define DEF_POINTER_TYPE(ENUM, TYPE) \
4455 builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
4456
4457#include "builtin-types.def"
4458
4459#undef DEF_PRIMITIVE_TYPE
4460#undef DEF_FUNCTION_TYPE_1
4461#undef DEF_FUNCTION_TYPE_2
4462#undef DEF_FUNCTION_TYPE_3
4463#undef DEF_FUNCTION_TYPE_4
4464#undef DEF_FUNCTION_TYPE_5
4465#undef DEF_FUNCTION_TYPE_6
4466#undef DEF_FUNCTION_TYPE_VAR_0
4467#undef DEF_FUNCTION_TYPE_VAR_1
4468#undef DEF_FUNCTION_TYPE_VAR_2
4469#undef DEF_FUNCTION_TYPE_VAR_3
4470#undef DEF_FUNCTION_TYPE_VAR_4
4471#undef DEF_FUNCTION_TYPE_VAR_5
4472#undef DEF_POINTER_TYPE
4473 builtin_types[(int) BT_LAST] = NULL_TREE;
4474
4475 c_init_attributes ();
4476
4477#define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P, \
4478 NONANSI_P, ATTRS, IMPLICIT, COND) \
4479 if (NAME && COND) \
4480 def_builtin_1 (ENUM, NAME, CLASS, \
4481 builtin_types[(int) TYPE], \
4482 builtin_types[(int) LIBTYPE], \
4483 BOTH_P, FALLBACK_P, NONANSI_P, \
4484 built_in_attributes[(int) ATTRS], IMPLICIT);
4485#include "builtins.def"
4486#undef DEF_BUILTIN
4487
87eb1c28 4488 targetm.init_builtins ();
4489
471eff36 4490 build_common_builtin_nodes ();
dce22712 4491
dce22712 4492 if (flag_mudflap)
4493 mudflap_init ();
4494}
4495
9e6687c8 4496/* Like get_identifier, but avoid warnings about null arguments when
4497 the argument may be NULL for targets where GCC lacks stdint.h type
4498 information. */
4499
4500static inline tree
4501c_get_ident (const char *id)
4502{
4503 return get_identifier (id);
4504}
4505
27213ba3 4506/* Build tree nodes and builtin functions common to both C and C++ language
4507 frontends. */
4508
4509void
4510c_common_nodes_and_builtins (void)
4511{
924bbf02 4512 int char16_type_size;
4513 int char32_type_size;
174fcc61 4514 int wchar_type_size;
4515 tree array_domain_type;
2d47cc32 4516 tree va_list_ref_type_node;
8a15c04a 4517 tree va_list_arg_type_node;
a66c9326 4518
174fcc61 4519 /* Define `int' and `char' first so that dbx will output them first. */
d946ea19 4520 record_builtin_type (RID_INT, NULL, integer_type_node);
174fcc61 4521 record_builtin_type (RID_CHAR, "char", char_type_node);
4522
4523 /* `signed' is the same as `int'. FIXME: the declarations of "signed",
4524 "unsigned long", "long long unsigned" and "unsigned short" were in C++
4525 but not C. Are the conditionals here needed? */
c0f19401 4526 if (c_dialect_cxx ())
d946ea19 4527 record_builtin_type (RID_SIGNED, NULL, integer_type_node);
174fcc61 4528 record_builtin_type (RID_LONG, "long int", long_integer_type_node);
4529 record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node);
4530 record_builtin_type (RID_MAX, "long unsigned int",
4531 long_unsigned_type_node);
6388cfe2 4532 if (int128_integer_type_node != NULL_TREE)
4533 {
4534 record_builtin_type (RID_INT128, "__int128",
4535 int128_integer_type_node);
4536 record_builtin_type (RID_MAX, "__int128 unsigned",
4537 int128_unsigned_type_node);
4538 }
c0f19401 4539 if (c_dialect_cxx ())
174fcc61 4540 record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node);
4541 record_builtin_type (RID_MAX, "long long int",
4542 long_long_integer_type_node);
4543 record_builtin_type (RID_MAX, "long long unsigned int",
4544 long_long_unsigned_type_node);
c0f19401 4545 if (c_dialect_cxx ())
174fcc61 4546 record_builtin_type (RID_MAX, "long long unsigned",
4547 long_long_unsigned_type_node);
4548 record_builtin_type (RID_SHORT, "short int", short_integer_type_node);
4549 record_builtin_type (RID_MAX, "short unsigned int",
4550 short_unsigned_type_node);
c0f19401 4551 if (c_dialect_cxx ())
174fcc61 4552 record_builtin_type (RID_MAX, "unsigned short",
4553 short_unsigned_type_node);
4554
4555 /* Define both `signed char' and `unsigned char'. */
4556 record_builtin_type (RID_MAX, "signed char", signed_char_type_node);
4557 record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node);
4558
771d21fa 4559 /* These are types that c_common_type_for_size and
4560 c_common_type_for_mode use. */
e60a6f7b 4561 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
4562 TYPE_DECL, NULL_TREE,
dc24ddbd 4563 intQI_type_node));
e60a6f7b 4564 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
4565 TYPE_DECL, NULL_TREE,
dc24ddbd 4566 intHI_type_node));
e60a6f7b 4567 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
4568 TYPE_DECL, NULL_TREE,
dc24ddbd 4569 intSI_type_node));
e60a6f7b 4570 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
4571 TYPE_DECL, NULL_TREE,
dc24ddbd 4572 intDI_type_node));
174fcc61 4573#if HOST_BITS_PER_WIDE_INT >= 64
f1515a39 4574 if (targetm.scalar_mode_supported_p (TImode))
e60a6f7b 4575 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
4576 TYPE_DECL,
f1515a39 4577 get_identifier ("__int128_t"),
4578 intTI_type_node));
174fcc61 4579#endif
e60a6f7b 4580 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
4581 TYPE_DECL, NULL_TREE,
dc24ddbd 4582 unsigned_intQI_type_node));
e60a6f7b 4583 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
4584 TYPE_DECL, NULL_TREE,
dc24ddbd 4585 unsigned_intHI_type_node));
e60a6f7b 4586 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
4587 TYPE_DECL, NULL_TREE,
dc24ddbd 4588 unsigned_intSI_type_node));
e60a6f7b 4589 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
4590 TYPE_DECL, NULL_TREE,
dc24ddbd 4591 unsigned_intDI_type_node));
174fcc61 4592#if HOST_BITS_PER_WIDE_INT >= 64
f1515a39 4593 if (targetm.scalar_mode_supported_p (TImode))
e60a6f7b 4594 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
4595 TYPE_DECL,
f1515a39 4596 get_identifier ("__uint128_t"),
4597 unsigned_intTI_type_node));
174fcc61 4598#endif
4599
4600 /* Create the widest literal types. */
4601 widest_integer_literal_type_node
4602 = make_signed_type (HOST_BITS_PER_WIDE_INT * 2);
e60a6f7b 4603 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
4604 TYPE_DECL, NULL_TREE,
dc24ddbd 4605 widest_integer_literal_type_node));
174fcc61 4606
4607 widest_unsigned_literal_type_node
4608 = make_unsigned_type (HOST_BITS_PER_WIDE_INT * 2);
e60a6f7b 4609 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
4610 TYPE_DECL, NULL_TREE,
dc24ddbd 4611 widest_unsigned_literal_type_node));
174fcc61 4612
4613 /* `unsigned long' is the standard type for sizeof.
4614 Note that stddef.h uses `unsigned long',
4615 and this must agree, even if long and int are the same size. */
654ef926 4616 size_type_node =
174fcc61 4617 TREE_TYPE (identifier_global_value (get_identifier (SIZE_TYPE)));
654ef926 4618 signed_size_type_node = c_common_signed_type (size_type_node);
4619 set_sizetype (size_type_node);
174fcc61 4620
73673831 4621 pid_type_node =
4622 TREE_TYPE (identifier_global_value (get_identifier (PID_TYPE)));
4623
174fcc61 4624 build_common_tree_nodes_2 (flag_short_double);
4625
d946ea19 4626 record_builtin_type (RID_FLOAT, NULL, float_type_node);
4627 record_builtin_type (RID_DOUBLE, NULL, double_type_node);
174fcc61 4628 record_builtin_type (RID_MAX, "long double", long_double_type_node);
4629
c4503c0a 4630 /* Only supported decimal floating point extension if the target
4631 actually supports underlying modes. */
48e1416a 4632 if (targetm.scalar_mode_supported_p (SDmode)
c4503c0a 4633 && targetm.scalar_mode_supported_p (DDmode)
4634 && targetm.scalar_mode_supported_p (TDmode))
4635 {
4636 record_builtin_type (RID_DFLOAT32, NULL, dfloat32_type_node);
4637 record_builtin_type (RID_DFLOAT64, NULL, dfloat64_type_node);
4638 record_builtin_type (RID_DFLOAT128, NULL, dfloat128_type_node);
4639 }
4640
9421ebb9 4641 if (targetm.fixed_point_supported_p ())
4642 {
4643 record_builtin_type (RID_MAX, "short _Fract", short_fract_type_node);
4644 record_builtin_type (RID_FRACT, NULL, fract_type_node);
4645 record_builtin_type (RID_MAX, "long _Fract", long_fract_type_node);
4646 record_builtin_type (RID_MAX, "long long _Fract",
4647 long_long_fract_type_node);
4648 record_builtin_type (RID_MAX, "unsigned short _Fract",
4649 unsigned_short_fract_type_node);
4650 record_builtin_type (RID_MAX, "unsigned _Fract",
4651 unsigned_fract_type_node);
4652 record_builtin_type (RID_MAX, "unsigned long _Fract",
4653 unsigned_long_fract_type_node);
4654 record_builtin_type (RID_MAX, "unsigned long long _Fract",
4655 unsigned_long_long_fract_type_node);
4656 record_builtin_type (RID_MAX, "_Sat short _Fract",
4657 sat_short_fract_type_node);
4658 record_builtin_type (RID_MAX, "_Sat _Fract", sat_fract_type_node);
4659 record_builtin_type (RID_MAX, "_Sat long _Fract",
4660 sat_long_fract_type_node);
4661 record_builtin_type (RID_MAX, "_Sat long long _Fract",
4662 sat_long_long_fract_type_node);
4663 record_builtin_type (RID_MAX, "_Sat unsigned short _Fract",
4664 sat_unsigned_short_fract_type_node);
4665 record_builtin_type (RID_MAX, "_Sat unsigned _Fract",
4666 sat_unsigned_fract_type_node);
4667 record_builtin_type (RID_MAX, "_Sat unsigned long _Fract",
4668 sat_unsigned_long_fract_type_node);
4669 record_builtin_type (RID_MAX, "_Sat unsigned long long _Fract",
4670 sat_unsigned_long_long_fract_type_node);
4671 record_builtin_type (RID_MAX, "short _Accum", short_accum_type_node);
4672 record_builtin_type (RID_ACCUM, NULL, accum_type_node);
4673 record_builtin_type (RID_MAX, "long _Accum", long_accum_type_node);
4674 record_builtin_type (RID_MAX, "long long _Accum",
4675 long_long_accum_type_node);
4676 record_builtin_type (RID_MAX, "unsigned short _Accum",
4677 unsigned_short_accum_type_node);
4678 record_builtin_type (RID_MAX, "unsigned _Accum",
4679 unsigned_accum_type_node);
4680 record_builtin_type (RID_MAX, "unsigned long _Accum",
4681 unsigned_long_accum_type_node);
4682 record_builtin_type (RID_MAX, "unsigned long long _Accum",
4683 unsigned_long_long_accum_type_node);
4684 record_builtin_type (RID_MAX, "_Sat short _Accum",
4685 sat_short_accum_type_node);
4686 record_builtin_type (RID_MAX, "_Sat _Accum", sat_accum_type_node);
4687 record_builtin_type (RID_MAX, "_Sat long _Accum",
4688 sat_long_accum_type_node);
4689 record_builtin_type (RID_MAX, "_Sat long long _Accum",
4690 sat_long_long_accum_type_node);
4691 record_builtin_type (RID_MAX, "_Sat unsigned short _Accum",
4692 sat_unsigned_short_accum_type_node);
4693 record_builtin_type (RID_MAX, "_Sat unsigned _Accum",
4694 sat_unsigned_accum_type_node);
4695 record_builtin_type (RID_MAX, "_Sat unsigned long _Accum",
4696 sat_unsigned_long_accum_type_node);
4697 record_builtin_type (RID_MAX, "_Sat unsigned long long _Accum",
4698 sat_unsigned_long_long_accum_type_node);
4699
4700 }
4701
e60a6f7b 4702 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
4703 TYPE_DECL,
dc24ddbd 4704 get_identifier ("complex int"),
4705 complex_integer_type_node));
e60a6f7b 4706 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
4707 TYPE_DECL,
dc24ddbd 4708 get_identifier ("complex float"),
4709 complex_float_type_node));
e60a6f7b 4710 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
4711 TYPE_DECL,
dc24ddbd 4712 get_identifier ("complex double"),
4713 complex_double_type_node));
4714 lang_hooks.decls.pushdecl
e60a6f7b 4715 (build_decl (UNKNOWN_LOCATION,
4716 TYPE_DECL, get_identifier ("complex long double"),
20325f61 4717 complex_long_double_type_node));
174fcc61 4718
e256d445 4719 if (c_dialect_cxx ())
4720 /* For C++, make fileptr_type_node a distinct void * type until
4721 FILE type is defined. */
e086912e 4722 fileptr_type_node = build_variant_type_copy (ptr_type_node);
e256d445 4723
d946ea19 4724 record_builtin_type (RID_VOID, NULL, void_type_node);
174fcc61 4725
6753bca0 4726 /* Set the TYPE_NAME for any variants that were built before
4727 record_builtin_type gave names to the built-in types. */
4728 {
4729 tree void_name = TYPE_NAME (void_type_node);
4730 TYPE_NAME (void_type_node) = NULL_TREE;
4731 TYPE_NAME (build_qualified_type (void_type_node, TYPE_QUAL_CONST))
4732 = void_name;
4733 TYPE_NAME (void_type_node) = void_name;
4734 }
4735
fbf0afd1 4736 /* This node must not be shared. */
7c446c95 4737 void_zero_node = make_node (INTEGER_CST);
d2d4bdde 4738 TREE_TYPE (void_zero_node) = void_type_node;
4739
174fcc61 4740 void_list_node = build_void_list_node ();
4741
4742 /* Make a type to be the domain of a few array types
4743 whose domains don't really matter.
4744 200 is small enough that it always fits in size_t
4745 and large enough that it can hold most function names for the
4746 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
4747 array_domain_type = build_index_type (size_int (200));
4748
4749 /* Make a type for arrays of characters.
4750 With luck nothing will ever really depend on the length of this
4751 array type. */
4752 char_array_type_node
4753 = build_array_type (char_type_node, array_domain_type);
4754
4755 /* Likewise for arrays of ints. */
4756 int_array_type_node
4757 = build_array_type (integer_type_node, array_domain_type);
4758
d2d4bdde 4759 string_type_node = build_pointer_type (char_type_node);
4760 const_string_type_node
4761 = build_pointer_type (build_qualified_type
4762 (char_type_node, TYPE_QUAL_CONST));
4763
174fcc61 4764 /* This is special for C++ so functions can be overloaded. */
18ef7ac2 4765 wchar_type_node = get_identifier (MODIFIED_WCHAR_TYPE);
174fcc61 4766 wchar_type_node = TREE_TYPE (identifier_global_value (wchar_type_node));
4767 wchar_type_size = TYPE_PRECISION (wchar_type_node);
f3449a3c 4768 underlying_wchar_type_node = wchar_type_node;
c0f19401 4769 if (c_dialect_cxx ())
174fcc61 4770 {
78a8ed03 4771 if (TYPE_UNSIGNED (wchar_type_node))
174fcc61 4772 wchar_type_node = make_unsigned_type (wchar_type_size);
4773 else
4774 wchar_type_node = make_signed_type (wchar_type_size);
4775 record_builtin_type (RID_WCHAR, "wchar_t", wchar_type_node);
4776 }
174fcc61 4777
4778 /* This is for wide string constants. */
4779 wchar_array_type_node
4780 = build_array_type (wchar_type_node, array_domain_type);
4781
924bbf02 4782 /* Define 'char16_t'. */
4783 char16_type_node = get_identifier (CHAR16_TYPE);
4784 char16_type_node = TREE_TYPE (identifier_global_value (char16_type_node));
4785 char16_type_size = TYPE_PRECISION (char16_type_node);
4786 if (c_dialect_cxx ())
4787 {
4788 char16_type_node = make_unsigned_type (char16_type_size);
4789
4790 if (cxx_dialect == cxx0x)
4791 record_builtin_type (RID_CHAR16, "char16_t", char16_type_node);
4792 }
4793
4794 /* This is for UTF-16 string constants. */
4795 char16_array_type_node
4796 = build_array_type (char16_type_node, array_domain_type);
4797
4798 /* Define 'char32_t'. */
4799 char32_type_node = get_identifier (CHAR32_TYPE);
4800 char32_type_node = TREE_TYPE (identifier_global_value (char32_type_node));
4801 char32_type_size = TYPE_PRECISION (char32_type_node);
4802 if (c_dialect_cxx ())
4803 {
4804 char32_type_node = make_unsigned_type (char32_type_size);
4805
4806 if (cxx_dialect == cxx0x)
4807 record_builtin_type (RID_CHAR32, "char32_t", char32_type_node);
4808 }
4809
4810 /* This is for UTF-32 string constants. */
4811 char32_array_type_node
4812 = build_array_type (char32_type_node, array_domain_type);
4813
6bf5ed8d 4814 wint_type_node =
4815 TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE)));
4816
4817 intmax_type_node =
4818 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE)));
4819 uintmax_type_node =
4820 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE)));
4821
f3449a3c 4822 if (SIG_ATOMIC_TYPE)
4823 sig_atomic_type_node =
9e6687c8 4824 TREE_TYPE (identifier_global_value (c_get_ident (SIG_ATOMIC_TYPE)));
f3449a3c 4825 if (INT8_TYPE)
4826 int8_type_node =
9e6687c8 4827 TREE_TYPE (identifier_global_value (c_get_ident (INT8_TYPE)));
f3449a3c 4828 if (INT16_TYPE)
4829 int16_type_node =
9e6687c8 4830 TREE_TYPE (identifier_global_value (c_get_ident (INT16_TYPE)));
f3449a3c 4831 if (INT32_TYPE)
4832 int32_type_node =
9e6687c8 4833 TREE_TYPE (identifier_global_value (c_get_ident (INT32_TYPE)));
f3449a3c 4834 if (INT64_TYPE)
4835 int64_type_node =
9e6687c8 4836 TREE_TYPE (identifier_global_value (c_get_ident (INT64_TYPE)));
f3449a3c 4837 if (UINT8_TYPE)
4838 uint8_type_node =
9e6687c8 4839 TREE_TYPE (identifier_global_value (c_get_ident (UINT8_TYPE)));
f3449a3c 4840 if (UINT16_TYPE)
4841 uint16_type_node =
9e6687c8 4842 TREE_TYPE (identifier_global_value (c_get_ident (UINT16_TYPE)));
f3449a3c 4843 if (UINT32_TYPE)
4844 c_uint32_type_node =
9e6687c8 4845 TREE_TYPE (identifier_global_value (c_get_ident (UINT32_TYPE)));
f3449a3c 4846 if (UINT64_TYPE)
4847 c_uint64_type_node =
9e6687c8 4848 TREE_TYPE (identifier_global_value (c_get_ident (UINT64_TYPE)));
f3449a3c 4849 if (INT_LEAST8_TYPE)
4850 int_least8_type_node =
9e6687c8 4851 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST8_TYPE)));
f3449a3c 4852 if (INT_LEAST16_TYPE)
4853 int_least16_type_node =
9e6687c8 4854 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST16_TYPE)));
f3449a3c 4855 if (INT_LEAST32_TYPE)
4856 int_least32_type_node =
9e6687c8 4857 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST32_TYPE)));
f3449a3c 4858 if (INT_LEAST64_TYPE)
4859 int_least64_type_node =
9e6687c8 4860 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST64_TYPE)));
f3449a3c 4861 if (UINT_LEAST8_TYPE)
4862 uint_least8_type_node =
9e6687c8 4863 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST8_TYPE)));
f3449a3c 4864 if (UINT_LEAST16_TYPE)
4865 uint_least16_type_node =
9e6687c8 4866 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST16_TYPE)));
f3449a3c 4867 if (UINT_LEAST32_TYPE)
4868 uint_least32_type_node =
9e6687c8 4869 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST32_TYPE)));
f3449a3c 4870 if (UINT_LEAST64_TYPE)
4871 uint_least64_type_node =
9e6687c8 4872 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST64_TYPE)));
f3449a3c 4873 if (INT_FAST8_TYPE)
4874 int_fast8_type_node =
9e6687c8 4875 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST8_TYPE)));
f3449a3c 4876 if (INT_FAST16_TYPE)
4877 int_fast16_type_node =
9e6687c8 4878 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST16_TYPE)));
f3449a3c 4879 if (INT_FAST32_TYPE)
4880 int_fast32_type_node =
9e6687c8 4881 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST32_TYPE)));
f3449a3c 4882 if (INT_FAST64_TYPE)
4883 int_fast64_type_node =
9e6687c8 4884 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST64_TYPE)));
f3449a3c 4885 if (UINT_FAST8_TYPE)
4886 uint_fast8_type_node =
9e6687c8 4887 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST8_TYPE)));
f3449a3c 4888 if (UINT_FAST16_TYPE)
4889 uint_fast16_type_node =
9e6687c8 4890 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST16_TYPE)));
f3449a3c 4891 if (UINT_FAST32_TYPE)
4892 uint_fast32_type_node =
9e6687c8 4893 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST32_TYPE)));
f3449a3c 4894 if (UINT_FAST64_TYPE)
4895 uint_fast64_type_node =
9e6687c8 4896 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST64_TYPE)));
f3449a3c 4897 if (INTPTR_TYPE)
4898 intptr_type_node =
9e6687c8 4899 TREE_TYPE (identifier_global_value (c_get_ident (INTPTR_TYPE)));
f3449a3c 4900 if (UINTPTR_TYPE)
4901 uintptr_type_node =
9e6687c8 4902 TREE_TYPE (identifier_global_value (c_get_ident (UINTPTR_TYPE)));
f3449a3c 4903
6bf5ed8d 4904 default_function_type = build_function_type (integer_type_node, NULL_TREE);
4905 ptrdiff_type_node
4906 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE)));
11773141 4907 unsigned_ptrdiff_type_node = c_common_unsigned_type (ptrdiff_type_node);
6bf5ed8d 4908
dc24ddbd 4909 lang_hooks.decls.pushdecl
e60a6f7b 4910 (build_decl (UNKNOWN_LOCATION,
4911 TYPE_DECL, get_identifier ("__builtin_va_list"),
20325f61 4912 va_list_type_node));
202d6e5f 4913 if (targetm.enum_va_list_p)
acd6f472 4914 {
4915 int l;
4916 const char *pname;
4917 tree ptype;
5f57a8b1 4918
202d6e5f 4919 for (l = 0; targetm.enum_va_list_p (l, &pname, &ptype); ++l)
acd6f472 4920 {
4921 lang_hooks.decls.pushdecl
4922 (build_decl (UNKNOWN_LOCATION,
4923 TYPE_DECL, get_identifier (pname),
4924 ptype));
4925
4926 }
4927 }
8a15c04a 4928
8a15c04a 4929 if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
2d47cc32 4930 {
4931 va_list_arg_type_node = va_list_ref_type_node =
4932 build_pointer_type (TREE_TYPE (va_list_type_node));
4933 }
8a15c04a 4934 else
2d47cc32 4935 {
4936 va_list_arg_type_node = va_list_type_node;
4937 va_list_ref_type_node = build_reference_type (va_list_type_node);
4938 }
1cae46be 4939
dce22712 4940 if (!flag_preprocess_only)
4941 c_define_builtins (va_list_ref_type_node, va_list_arg_type_node);
ffa8918b 4942
5c62f199 4943 main_identifier_node = get_identifier ("main");
ae84079f 4944
4945 /* Create the built-in __null node. It is important that this is
4946 not shared. */
4947 null_node = make_node (INTEGER_CST);
4948 TREE_TYPE (null_node) = c_common_type_for_size (POINTER_SIZE, 0);
27213ba3 4949
4950 /* Since builtin_types isn't gc'ed, don't export these nodes. */
4951 memset (builtin_types, 0, sizeof (builtin_types));
72040e7e 4952}
a66c9326 4953
79b01846 4954/* The number of named compound-literals generated thus far. */
4955static GTY(()) int compound_literal_number;
4956
4957/* Set DECL_NAME for DECL, a VAR_DECL for a compound-literal. */
4958
4959void
4960set_compound_literal_name (tree decl)
4961{
4962 char *name;
4963 ASM_FORMAT_PRIVATE_NAME (name, "__compound_literal",
4964 compound_literal_number);
4965 compound_literal_number++;
4966 DECL_NAME (decl) = get_identifier (name);
4967}
4968
a66c9326 4969tree
e60a6f7b 4970build_va_arg (location_t loc, tree expr, tree type)
a66c9326 4971{
e60a6f7b 4972 expr = build1 (VA_ARG_EXPR, type, expr);
4973 SET_EXPR_LOCATION (expr, loc);
4974 return expr;
a66c9326 4975}
0d4238dc 4976
4977
dd878098 4978/* Linked list of disabled built-in functions. */
4979
4980typedef struct disabled_builtin
4981{
4982 const char *name;
4983 struct disabled_builtin *next;
4984} disabled_builtin;
4985static disabled_builtin *disabled_builtins = NULL;
4986
1cae46be 4987static bool builtin_function_disabled_p (const char *);
dd878098 4988
4989/* Disable a built-in function specified by -fno-builtin-NAME. If NAME
4990 begins with "__builtin_", give an error. */
4991
4992void
1cae46be 4993disable_builtin_function (const char *name)
dd878098 4994{
4995 if (strncmp (name, "__builtin_", strlen ("__builtin_")) == 0)
b0b1af64 4996 error ("cannot disable built-in function %qs", name);
dd878098 4997 else
4998 {
e85905e5 4999 disabled_builtin *new_disabled_builtin = XNEW (disabled_builtin);
5000 new_disabled_builtin->name = name;
5001 new_disabled_builtin->next = disabled_builtins;
5002 disabled_builtins = new_disabled_builtin;
dd878098 5003 }
5004}
5005
5006
5007/* Return true if the built-in function NAME has been disabled, false
5008 otherwise. */
5009
5010static bool
1cae46be 5011builtin_function_disabled_p (const char *name)
dd878098 5012{
5013 disabled_builtin *p;
5014 for (p = disabled_builtins; p != NULL; p = p->next)
5015 {
5016 if (strcmp (name, p->name) == 0)
5017 return true;
5018 }
5019 return false;
5020}
5021
5022
3237155d 5023/* Worker for DEF_BUILTIN.
5024 Possibly define a builtin function with one or two names.
5025 Does not declare a non-__builtin_ function if flag_no_builtin, or if
5026 nonansi_p and flag_no_nonansi_builtin. */
0d4238dc 5027
3237155d 5028static void
5029def_builtin_1 (enum built_in_function fncode,
5030 const char *name,
5031 enum built_in_class fnclass,
5032 tree fntype, tree libtype,
5033 bool both_p, bool fallback_p, bool nonansi_p,
5034 tree fnattrs, bool implicit_p)
0d4238dc 5035{
3237155d 5036 tree decl;
5037 const char *libname;
5038
27213ba3 5039 if (fntype == error_mark_node)
5040 return;
5041
3237155d 5042 gcc_assert ((!both_p && !fallback_p)
5043 || !strncmp (name, "__builtin_",
5044 strlen ("__builtin_")));
5045
5046 libname = name + strlen ("__builtin_");
54be5d7e 5047 decl = add_builtin_function (name, fntype, fncode, fnclass,
5048 (fallback_p ? libname : NULL),
5049 fnattrs);
3237155d 5050 if (both_p
5051 && !flag_no_builtin && !builtin_function_disabled_p (libname)
dd878098 5052 && !(nonansi_p && flag_no_nonansi_builtin))
54be5d7e 5053 add_builtin_function (libname, libtype, fncode, fnclass,
5054 NULL, fnattrs);
a40609e6 5055
3237155d 5056 built_in_decls[(int) fncode] = decl;
5057 if (implicit_p)
5058 implicit_built_in_decls[(int) fncode] = decl;
0d4238dc 5059}
e94026da 5060\f
d7aeef06 5061/* Nonzero if the type T promotes to int. This is (nearly) the
5062 integral promotions defined in ISO C99 6.3.1.1/2. */
5063
5064bool
9f627b1a 5065c_promoting_integer_type_p (const_tree t)
d7aeef06 5066{
5067 switch (TREE_CODE (t))
5068 {
5069 case INTEGER_TYPE:
5070 return (TYPE_MAIN_VARIANT (t) == char_type_node
5071 || TYPE_MAIN_VARIANT (t) == signed_char_type_node
5072 || TYPE_MAIN_VARIANT (t) == unsigned_char_type_node
5073 || TYPE_MAIN_VARIANT (t) == short_integer_type_node
7aa1e6eb 5074 || TYPE_MAIN_VARIANT (t) == short_unsigned_type_node
5075 || TYPE_PRECISION (t) < TYPE_PRECISION (integer_type_node));
d7aeef06 5076
5077 case ENUMERAL_TYPE:
5078 /* ??? Technically all enumerations not larger than an int
5079 promote to an int. But this is used along code paths
5080 that only want to notice a size change. */
5081 return TYPE_PRECISION (t) < TYPE_PRECISION (integer_type_node);
5082
5083 case BOOLEAN_TYPE:
5084 return 1;
5085
5086 default:
5087 return 0;
5088 }
5089}
5090
e94026da 5091/* Return 1 if PARMS specifies a fixed number of parameters
5092 and none of their types is affected by default promotions. */
5093
5094int
9f627b1a 5095self_promoting_args_p (const_tree parms)
e94026da 5096{
9f627b1a 5097 const_tree t;
e94026da 5098 for (t = parms; t; t = TREE_CHAIN (t))
5099 {
19cb6b50 5100 tree type = TREE_VALUE (t);
43f74bc4 5101
e1d8e198 5102 if (type == error_mark_node)
5103 continue;
5104
e94026da 5105 if (TREE_CHAIN (t) == 0 && type != void_type_node)
5106 return 0;
5107
5108 if (type == 0)
5109 return 0;
5110
5111 if (TYPE_MAIN_VARIANT (type) == float_type_node)
5112 return 0;
5113
d7aeef06 5114 if (c_promoting_integer_type_p (type))
e94026da 5115 return 0;
5116 }
5117 return 1;
5118}
605fb01e 5119
c10de5e7 5120/* Recursively remove any '*' or '&' operator from TYPE. */
5121tree
5122strip_pointer_operator (tree t)
5123{
5124 while (POINTER_TYPE_P (t))
5125 t = TREE_TYPE (t);
5126 return t;
5127}
5128
57a0ed23 5129/* Recursively remove pointer or array type from TYPE. */
5130tree
5131strip_pointer_or_array_types (tree t)
5132{
5133 while (TREE_CODE (t) == ARRAY_TYPE || POINTER_TYPE_P (t))
5134 t = TREE_TYPE (t);
5135 return t;
5136}
5137
e41f0d80 5138/* Used to compare case labels. K1 and K2 are actually tree nodes
5139 representing case labels, or NULL_TREE for a `default' label.
5140 Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after
5141 K2, and 0 if K1 and K2 are equal. */
5142
5143int
1cae46be 5144case_compare (splay_tree_key k1, splay_tree_key k2)
e41f0d80 5145{
5146 /* Consider a NULL key (such as arises with a `default' label) to be
5147 smaller than anything else. */
5148 if (!k1)
5149 return k2 ? -1 : 0;
5150 else if (!k2)
5151 return k1 ? 1 : 0;
5152
5153 return tree_int_cst_compare ((tree) k1, (tree) k2);
5154}
5155
e60a6f7b 5156/* Process a case label, located at LOC, for the range LOW_VALUE
5157 ... HIGH_VALUE. If LOW_VALUE and HIGH_VALUE are both NULL_TREE
5158 then this case label is actually a `default' label. If only
5159 HIGH_VALUE is NULL_TREE, then case label was declared using the
5160 usual C/C++ syntax, rather than the GNU case range extension.
5161 CASES is a tree containing all the case ranges processed so far;
5162 COND is the condition for the switch-statement itself. Returns the
5163 CASE_LABEL_EXPR created, or ERROR_MARK_NODE if no CASE_LABEL_EXPR
5164 is created. */
e41f0d80 5165
5166tree
e60a6f7b 5167c_add_case_label (location_t loc, splay_tree cases, tree cond, tree orig_type,
2ca392fd 5168 tree low_value, tree high_value)
e41f0d80 5169{
5170 tree type;
5171 tree label;
5172 tree case_label;
5173 splay_tree_node node;
5174
5175 /* Create the LABEL_DECL itself. */
e60a6f7b 5176 label = create_artificial_label (loc);
e41f0d80 5177
5178 /* If there was an error processing the switch condition, bail now
5179 before we get more confused. */
5180 if (!cond || cond == error_mark_node)
4ee9c684 5181 goto error_out;
e41f0d80 5182
1cae46be 5183 if ((low_value && TREE_TYPE (low_value)
5184 && POINTER_TYPE_P (TREE_TYPE (low_value)))
e41f0d80 5185 || (high_value && TREE_TYPE (high_value)
5186 && POINTER_TYPE_P (TREE_TYPE (high_value))))
b96dc121 5187 {
e60a6f7b 5188 error_at (loc, "pointers are not permitted as case values");
b96dc121 5189 goto error_out;
5190 }
e41f0d80 5191
5192 /* Case ranges are a GNU extension. */
8864917d 5193 if (high_value)
48e1416a 5194 pedwarn (loc, OPT_pedantic,
8864917d 5195 "range expressions in switch statements are non-standard");
e41f0d80 5196
5197 type = TREE_TYPE (cond);
5198 if (low_value)
5199 {
5200 low_value = check_case_value (low_value);
5201 low_value = convert_and_check (type, low_value);
96722196 5202 if (low_value == error_mark_node)
5203 goto error_out;
e41f0d80 5204 }
5205 if (high_value)
5206 {
5207 high_value = check_case_value (high_value);
5208 high_value = convert_and_check (type, high_value);
96722196 5209 if (high_value == error_mark_node)
5210 goto error_out;
e41f0d80 5211 }
5212
96722196 5213 if (low_value && high_value)
5214 {
5215 /* If the LOW_VALUE and HIGH_VALUE are the same, then this isn't
a0c938f0 5216 really a case range, even though it was written that way.
5217 Remove the HIGH_VALUE to simplify later processing. */
96722196 5218 if (tree_int_cst_equal (low_value, high_value))
5219 high_value = NULL_TREE;
5220 else if (!tree_int_cst_lt (low_value, high_value))
e60a6f7b 5221 warning_at (loc, 0, "empty range specified");
96722196 5222 }
e41f0d80 5223
2ca392fd 5224 /* See if the case is in range of the type of the original testing
5225 expression. If both low_value and high_value are out of range,
5226 don't insert the case label and return NULL_TREE. */
5227 if (low_value
84166705 5228 && !check_case_bounds (type, orig_type,
5229 &low_value, high_value ? &high_value : NULL))
2ca392fd 5230 return NULL_TREE;
5231
e41f0d80 5232 /* Look up the LOW_VALUE in the table of case labels we already
5233 have. */
5234 node = splay_tree_lookup (cases, (splay_tree_key) low_value);
5235 /* If there was not an exact match, check for overlapping ranges.
5236 There's no need to do this if there's no LOW_VALUE or HIGH_VALUE;
5237 that's a `default' label and the only overlap is an exact match. */
5238 if (!node && (low_value || high_value))
5239 {
5240 splay_tree_node low_bound;
5241 splay_tree_node high_bound;
5242
5243 /* Even though there wasn't an exact match, there might be an
5244 overlap between this case range and another case range.
5245 Since we've (inductively) not allowed any overlapping case
5246 ranges, we simply need to find the greatest low case label
5247 that is smaller that LOW_VALUE, and the smallest low case
5248 label that is greater than LOW_VALUE. If there is an overlap
5249 it will occur in one of these two ranges. */
5250 low_bound = splay_tree_predecessor (cases,
5251 (splay_tree_key) low_value);
5252 high_bound = splay_tree_successor (cases,
5253 (splay_tree_key) low_value);
5254
5255 /* Check to see if the LOW_BOUND overlaps. It is smaller than
5256 the LOW_VALUE, so there is no need to check unless the
5257 LOW_BOUND is in fact itself a case range. */
5258 if (low_bound
5259 && CASE_HIGH ((tree) low_bound->value)
5260 && tree_int_cst_compare (CASE_HIGH ((tree) low_bound->value),
5261 low_value) >= 0)
5262 node = low_bound;
5263 /* Check to see if the HIGH_BOUND overlaps. The low end of that
5264 range is bigger than the low end of the current range, so we
5265 are only interested if the current range is a real range, and
5266 not an ordinary case label. */
1cae46be 5267 else if (high_bound
e41f0d80 5268 && high_value
5269 && (tree_int_cst_compare ((tree) high_bound->key,
5270 high_value)
5271 <= 0))
5272 node = high_bound;
5273 }
5274 /* If there was an overlap, issue an error. */
5275 if (node)
5276 {
eaae3b75 5277 tree duplicate = CASE_LABEL ((tree) node->value);
e41f0d80 5278
5279 if (high_value)
5280 {
e60a6f7b 5281 error_at (loc, "duplicate (or overlapping) case value");
5282 error_at (DECL_SOURCE_LOCATION (duplicate),
5283 "this is the first entry overlapping that value");
e41f0d80 5284 }
5285 else if (low_value)
5286 {
e60a6f7b 5287 error_at (loc, "duplicate case value") ;
5288 error_at (DECL_SOURCE_LOCATION (duplicate), "previously used here");
e41f0d80 5289 }
5290 else
5291 {
e60a6f7b 5292 error_at (loc, "multiple default labels in one switch");
5293 error_at (DECL_SOURCE_LOCATION (duplicate),
5294 "this is the first default label");
e41f0d80 5295 }
4ee9c684 5296 goto error_out;
e41f0d80 5297 }
5298
5299 /* Add a CASE_LABEL to the statement-tree. */
e60a6f7b 5300 case_label = add_stmt (build_case_label (loc, low_value, high_value, label));
e41f0d80 5301 /* Register this case label in the splay tree. */
1cae46be 5302 splay_tree_insert (cases,
e41f0d80 5303 (splay_tree_key) low_value,
5304 (splay_tree_value) case_label);
5305
5306 return case_label;
4ee9c684 5307
5308 error_out:
daf6dff5 5309 /* Add a label so that the back-end doesn't think that the beginning of
4ee9c684 5310 the switch is unreachable. Note that we do not add a case label, as
a53ff4c1 5311 that just leads to duplicates and thence to failure later on. */
4ee9c684 5312 if (!cases->root)
5313 {
e60a6f7b 5314 tree t = create_artificial_label (loc);
5315 add_stmt (build_stmt (loc, LABEL_EXPR, t));
4ee9c684 5316 }
5317 return error_mark_node;
5318}
5319
5320/* Subroutines of c_do_switch_warnings, called via splay_tree_foreach.
5321 Used to verify that case values match up with enumerator values. */
5322
5323static void
5324match_case_to_enum_1 (tree key, tree type, tree label)
5325{
5326 char buf[2 + 2*HOST_BITS_PER_WIDE_INT/4 + 1];
5327
5328 /* ??? Not working too hard to print the double-word value.
5329 Should perhaps be done with %lwd in the diagnostic routines? */
5330 if (TREE_INT_CST_HIGH (key) == 0)
5331 snprintf (buf, sizeof (buf), HOST_WIDE_INT_PRINT_UNSIGNED,
5332 TREE_INT_CST_LOW (key));
5333 else if (!TYPE_UNSIGNED (type)
5334 && TREE_INT_CST_HIGH (key) == -1
5335 && TREE_INT_CST_LOW (key) != 0)
5336 snprintf (buf, sizeof (buf), "-" HOST_WIDE_INT_PRINT_UNSIGNED,
5337 -TREE_INT_CST_LOW (key));
5338 else
5339 snprintf (buf, sizeof (buf), HOST_WIDE_INT_PRINT_DOUBLE_HEX,
7df7561b 5340 (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (key),
5341 (unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (key));
4ee9c684 5342
5343 if (TYPE_NAME (type) == 0)
712d2297 5344 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label)),
5345 warn_switch ? OPT_Wswitch : OPT_Wswitch_enum,
5346 "case value %qs not in enumerated type",
5347 buf);
4ee9c684 5348 else
712d2297 5349 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label)),
5350 warn_switch ? OPT_Wswitch : OPT_Wswitch_enum,
5351 "case value %qs not in enumerated type %qT",
5352 buf, type);
4ee9c684 5353}
5354
359d87c6 5355/* Subroutine of c_do_switch_warnings, called via splay_tree_foreach.
5356 Used to verify that case values match up with enumerator values. */
5357
4ee9c684 5358static int
5359match_case_to_enum (splay_tree_node node, void *data)
5360{
5361 tree label = (tree) node->value;
4fd61bc6 5362 tree type = (tree) data;
4ee9c684 5363
5364 /* Skip default case. */
5365 if (!CASE_LOW (label))
5366 return 0;
5367
359d87c6 5368 /* If CASE_LOW_SEEN is not set, that means CASE_LOW did not appear
4ee9c684 5369 when we did our enum->case scan. Reset our scratch bit after. */
359d87c6 5370 if (!CASE_LOW_SEEN (label))
4ee9c684 5371 match_case_to_enum_1 (CASE_LOW (label), type, label);
5372 else
359d87c6 5373 CASE_LOW_SEEN (label) = 0;
4ee9c684 5374
359d87c6 5375 /* If CASE_HIGH is non-null, we have a range. If CASE_HIGH_SEEN is
5376 not set, that means that CASE_HIGH did not appear when we did our
5377 enum->case scan. Reset our scratch bit after. */
4ee9c684 5378 if (CASE_HIGH (label))
5379 {
359d87c6 5380 if (!CASE_HIGH_SEEN (label))
5381 match_case_to_enum_1 (CASE_HIGH (label), type, label);
5382 else
5383 CASE_HIGH_SEEN (label) = 0;
4ee9c684 5384 }
5385
5386 return 0;
5387}
5388
e7911019 5389/* Handle -Wswitch*. Called from the front end after parsing the
5390 switch construct. */
5391/* ??? Should probably be somewhere generic, since other languages
5392 besides C and C++ would want this. At the moment, however, C/C++
5393 are the only tree-ssa languages that support enumerations at all,
5394 so the point is moot. */
4ee9c684 5395
e7911019 5396void
5397c_do_switch_warnings (splay_tree cases, location_t switch_location,
5398 tree type, tree cond)
4ee9c684 5399{
b27ac6b5 5400 splay_tree_node default_node;
359d87c6 5401 splay_tree_node node;
5402 tree chain;
4ee9c684 5403
5404 if (!warn_switch && !warn_switch_enum && !warn_switch_default)
5405 return;
5406
4ee9c684 5407 default_node = splay_tree_lookup (cases, (splay_tree_key) NULL);
8b6866af 5408 if (!default_node)
5fb6a912 5409 warning_at (switch_location, OPT_Wswitch_default,
5410 "switch missing default case");
4ee9c684 5411
359d87c6 5412 /* From here on, we only care about about enumerated types. */
5413 if (!type || TREE_CODE (type) != ENUMERAL_TYPE)
5414 return;
5415
561017b5 5416 /* From here on, we only care about -Wswitch and -Wswitch-enum. */
5417 if (!warn_switch_enum && !warn_switch)
359d87c6 5418 return;
5419
561017b5 5420 /* Check the cases. Warn about case values which are not members of
5421 the enumerated type. For -Wswitch-enum, or for -Wswitch when
5422 there is no default case, check that exactly all enumeration
5423 literals are covered by the cases. */
5424
359d87c6 5425 /* Clearing COND if it is not an integer constant simplifies
5426 the tests inside the loop below. */
5427 if (TREE_CODE (cond) != INTEGER_CST)
5428 cond = NULL_TREE;
5429
5430 /* The time complexity here is O(N*lg(N)) worst case, but for the
5431 common case of monotonically increasing enumerators, it is
5432 O(N), since the nature of the splay tree will keep the next
5433 element adjacent to the root at all times. */
4ee9c684 5434
359d87c6 5435 for (chain = TYPE_VALUES (type); chain; chain = TREE_CHAIN (chain))
5436 {
5437 tree value = TREE_VALUE (chain);
3f00a6c0 5438 if (TREE_CODE (value) == CONST_DECL)
5439 value = DECL_INITIAL (value);
359d87c6 5440 node = splay_tree_lookup (cases, (splay_tree_key) value);
5441 if (node)
4ee9c684 5442 {
359d87c6 5443 /* Mark the CASE_LOW part of the case entry as seen. */
5444 tree label = (tree) node->value;
5445 CASE_LOW_SEEN (label) = 1;
5446 continue;
5447 }
5448
5449 /* Even though there wasn't an exact match, there might be a
f0b5f617 5450 case range which includes the enumerator's value. */
359d87c6 5451 node = splay_tree_predecessor (cases, (splay_tree_key) value);
5452 if (node && CASE_HIGH ((tree) node->value))
5453 {
5454 tree label = (tree) node->value;
5455 int cmp = tree_int_cst_compare (CASE_HIGH (label), value);
5456 if (cmp >= 0)
4ee9c684 5457 {
359d87c6 5458 /* If we match the upper bound exactly, mark the CASE_HIGH
5459 part of the case entry as seen. */
5460 if (cmp == 0)
5461 CASE_HIGH_SEEN (label) = 1;
5462 continue;
4ee9c684 5463 }
5464 }
5465
359d87c6 5466 /* We've now determined that this enumerated literal isn't
5467 handled by the case labels of the switch statement. */
4ee9c684 5468
359d87c6 5469 /* If the switch expression is a constant, we only really care
5470 about whether that constant is handled by the switch. */
5471 if (cond && tree_int_cst_compare (cond, value))
5472 continue;
4ee9c684 5473
6cbbbc89 5474 /* If there is a default_node, the only relevant option is
561017b5 5475 Wswitch-enum. Otherwise, if both are enabled then we prefer
6cbbbc89 5476 to warn using -Wswitch because -Wswitch is enabled by -Wall
5477 while -Wswitch-enum is explicit. */
561017b5 5478 warning_at (switch_location,
5479 (default_node || !warn_switch
5480 ? OPT_Wswitch_enum
5481 : OPT_Wswitch),
5482 "enumeration value %qE not handled in switch",
5483 TREE_PURPOSE (chain));
4ee9c684 5484 }
359d87c6 5485
5486 /* Warn if there are case expressions that don't correspond to
5487 enumerators. This can occur since C and C++ don't enforce
5488 type-checking of assignments to enumeration variables.
5489
5490 The time complexity here is now always O(N) worst case, since
5491 we should have marked both the lower bound and upper bound of
5492 every disjoint case label, with CASE_LOW_SEEN and CASE_HIGH_SEEN
5493 above. This scan also resets those fields. */
6cbbbc89 5494
359d87c6 5495 splay_tree_foreach (cases, match_case_to_enum, type);
e41f0d80 5496}
5497
9dd48740 5498/* Finish an expression taking the address of LABEL (an
dda49785 5499 IDENTIFIER_NODE). Returns an expression for the address.
5500
5501 LOC is the location for the expression returned. */
d0a47c8d 5502
1cae46be 5503tree
dda49785 5504finish_label_address_expr (tree label, location_t loc)
d0a47c8d 5505{
5506 tree result;
5507
21ca8540 5508 pedwarn (input_location, OPT_pedantic, "taking the address of a label is non-standard");
d0a47c8d 5509
9dd48740 5510 if (label == error_mark_node)
5511 return error_mark_node;
5512
d0a47c8d 5513 label = lookup_label (label);
5514 if (label == NULL_TREE)
5515 result = null_pointer_node;
5516 else
5517 {
5518 TREE_USED (label) = 1;
5519 result = build1 (ADDR_EXPR, ptr_type_node, label);
344cd9b2 5520 /* The current function is not necessarily uninlinable.
d0a47c8d 5521 Computed gotos are incompatible with inlining, but the value
5522 here could be used only in a diagnostic, for example. */
dda49785 5523 protected_set_expr_location (result, loc);
d0a47c8d 5524 }
5525
5526 return result;
5527}
4f9a1c9b 5528\f
5529
5530/* Given a boolean expression ARG, return a tree representing an increment
5531 or decrement (as indicated by CODE) of ARG. The front end must check for
5532 invalid cases (e.g., decrement in C++). */
5533tree
1cae46be 5534boolean_increment (enum tree_code code, tree arg)
4f9a1c9b 5535{
5536 tree val;
69db191c 5537 tree true_res = build_int_cst (TREE_TYPE (arg), 1);
c0f19401 5538
4f9a1c9b 5539 arg = stabilize_reference (arg);
5540 switch (code)
5541 {
5542 case PREINCREMENT_EXPR:
14ae0310 5543 val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg, true_res);
4f9a1c9b 5544 break;
5545 case POSTINCREMENT_EXPR:
14ae0310 5546 val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg, true_res);
4f9a1c9b 5547 arg = save_expr (arg);
14ae0310 5548 val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), val, arg);
5549 val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), arg, val);
4f9a1c9b 5550 break;
5551 case PREDECREMENT_EXPR:
14ae0310 5552 val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg,
389dd41b 5553 invert_truthvalue_loc (input_location, arg));
4f9a1c9b 5554 break;
5555 case POSTDECREMENT_EXPR:
14ae0310 5556 val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg,
389dd41b 5557 invert_truthvalue_loc (input_location, arg));
4f9a1c9b 5558 arg = save_expr (arg);
14ae0310 5559 val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), val, arg);
5560 val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), arg, val);
4f9a1c9b 5561 break;
5562 default:
231bd014 5563 gcc_unreachable ();
4f9a1c9b 5564 }
5565 TREE_SIDE_EFFECTS (val) = 1;
5566 return val;
5567}
76a6e674 5568\f
f3449a3c 5569/* Built-in macros for stddef.h and stdint.h, that require macros
5570 defined in this file. */
79cf3ec1 5571void
1cae46be 5572c_stddef_cpp_builtins(void)
1ed9d5f5 5573{
63994318 5574 builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE, 0);
5575 builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE, 0);
5576 builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE, 0);
5577 builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE, 0);
36bccbfc 5578 builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE, 0);
5579 builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE, 0);
b0726616 5580 builtin_define_with_value ("__CHAR16_TYPE__", CHAR16_TYPE, 0);
5581 builtin_define_with_value ("__CHAR32_TYPE__", CHAR32_TYPE, 0);
f3449a3c 5582 if (SIG_ATOMIC_TYPE)
5583 builtin_define_with_value ("__SIG_ATOMIC_TYPE__", SIG_ATOMIC_TYPE, 0);
5584 if (INT8_TYPE)
5585 builtin_define_with_value ("__INT8_TYPE__", INT8_TYPE, 0);
5586 if (INT16_TYPE)
5587 builtin_define_with_value ("__INT16_TYPE__", INT16_TYPE, 0);
5588 if (INT32_TYPE)
5589 builtin_define_with_value ("__INT32_TYPE__", INT32_TYPE, 0);
5590 if (INT64_TYPE)
5591 builtin_define_with_value ("__INT64_TYPE__", INT64_TYPE, 0);
5592 if (UINT8_TYPE)
5593 builtin_define_with_value ("__UINT8_TYPE__", UINT8_TYPE, 0);
5594 if (UINT16_TYPE)
5595 builtin_define_with_value ("__UINT16_TYPE__", UINT16_TYPE, 0);
5596 if (UINT32_TYPE)
5597 builtin_define_with_value ("__UINT32_TYPE__", UINT32_TYPE, 0);
5598 if (UINT64_TYPE)
5599 builtin_define_with_value ("__UINT64_TYPE__", UINT64_TYPE, 0);
5600 if (INT_LEAST8_TYPE)
5601 builtin_define_with_value ("__INT_LEAST8_TYPE__", INT_LEAST8_TYPE, 0);
5602 if (INT_LEAST16_TYPE)
5603 builtin_define_with_value ("__INT_LEAST16_TYPE__", INT_LEAST16_TYPE, 0);
5604 if (INT_LEAST32_TYPE)
5605 builtin_define_with_value ("__INT_LEAST32_TYPE__", INT_LEAST32_TYPE, 0);
5606 if (INT_LEAST64_TYPE)
5607 builtin_define_with_value ("__INT_LEAST64_TYPE__", INT_LEAST64_TYPE, 0);
5608 if (UINT_LEAST8_TYPE)
5609 builtin_define_with_value ("__UINT_LEAST8_TYPE__", UINT_LEAST8_TYPE, 0);
5610 if (UINT_LEAST16_TYPE)
5611 builtin_define_with_value ("__UINT_LEAST16_TYPE__", UINT_LEAST16_TYPE, 0);
5612 if (UINT_LEAST32_TYPE)
5613 builtin_define_with_value ("__UINT_LEAST32_TYPE__", UINT_LEAST32_TYPE, 0);
5614 if (UINT_LEAST64_TYPE)
5615 builtin_define_with_value ("__UINT_LEAST64_TYPE__", UINT_LEAST64_TYPE, 0);
5616 if (INT_FAST8_TYPE)
5617 builtin_define_with_value ("__INT_FAST8_TYPE__", INT_FAST8_TYPE, 0);
5618 if (INT_FAST16_TYPE)
5619 builtin_define_with_value ("__INT_FAST16_TYPE__", INT_FAST16_TYPE, 0);
5620 if (INT_FAST32_TYPE)
5621 builtin_define_with_value ("__INT_FAST32_TYPE__", INT_FAST32_TYPE, 0);
5622 if (INT_FAST64_TYPE)
5623 builtin_define_with_value ("__INT_FAST64_TYPE__", INT_FAST64_TYPE, 0);
5624 if (UINT_FAST8_TYPE)
5625 builtin_define_with_value ("__UINT_FAST8_TYPE__", UINT_FAST8_TYPE, 0);
5626 if (UINT_FAST16_TYPE)
5627 builtin_define_with_value ("__UINT_FAST16_TYPE__", UINT_FAST16_TYPE, 0);
5628 if (UINT_FAST32_TYPE)
5629 builtin_define_with_value ("__UINT_FAST32_TYPE__", UINT_FAST32_TYPE, 0);
5630 if (UINT_FAST64_TYPE)
5631 builtin_define_with_value ("__UINT_FAST64_TYPE__", UINT_FAST64_TYPE, 0);
5632 if (INTPTR_TYPE)
5633 builtin_define_with_value ("__INTPTR_TYPE__", INTPTR_TYPE, 0);
5634 if (UINTPTR_TYPE)
5635 builtin_define_with_value ("__UINTPTR_TYPE__", UINTPTR_TYPE, 0);
574006c3 5636}
5637
7d3b509a 5638static void
1cae46be 5639c_init_attributes (void)
7d3b509a 5640{
5641 /* Fill in the built_in_attributes array. */
7c446c95 5642#define DEF_ATTR_NULL_TREE(ENUM) \
7d3b509a 5643 built_in_attributes[(int) ENUM] = NULL_TREE;
7c446c95 5644#define DEF_ATTR_INT(ENUM, VALUE) \
7016c612 5645 built_in_attributes[(int) ENUM] = build_int_cst (NULL_TREE, VALUE);
7d3b509a 5646#define DEF_ATTR_IDENT(ENUM, STRING) \
5647 built_in_attributes[(int) ENUM] = get_identifier (STRING);
5648#define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
5649 built_in_attributes[(int) ENUM] \
5650 = tree_cons (built_in_attributes[(int) PURPOSE], \
5651 built_in_attributes[(int) VALUE], \
5652 built_in_attributes[(int) CHAIN]);
7d3b509a 5653#include "builtin-attrs.def"
5654#undef DEF_ATTR_NULL_TREE
5655#undef DEF_ATTR_INT
5656#undef DEF_ATTR_IDENT
5657#undef DEF_ATTR_TREE_LIST
76a6e674 5658}
5f3cead1 5659
33199a81 5660/* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain
5661 identifier as an argument, so the front end shouldn't look it up. */
5662
5663bool
47b19b94 5664attribute_takes_identifier_p (const_tree attr_id)
33199a81 5665{
47b19b94 5666 if (is_attribute_p ("mode", attr_id)
5667 || is_attribute_p ("format", attr_id)
5668 || is_attribute_p ("cleanup", attr_id))
5669 return true;
5670 else
5671 return targetm.attribute_takes_identifier_p (attr_id);
33199a81 5672}
5673
f8e93a2e 5674/* Attribute handlers common to C front ends. */
5675
5676/* Handle a "packed" attribute; arguments as in
5677 struct attribute_spec.handler. */
5678
5679static tree
9a03a746 5680handle_packed_attribute (tree *node, tree name, tree ARG_UNUSED (args),
09347743 5681 int flags, bool *no_add_attrs)
f8e93a2e 5682{
f40175cb 5683 if (TYPE_P (*node))
f8e93a2e 5684 {
5685 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
e086912e 5686 *node = build_variant_type_copy (*node);
f40175cb 5687 TYPE_PACKED (*node) = 1;
f8e93a2e 5688 }
5689 else if (TREE_CODE (*node) == FIELD_DECL)
c2ab04f9 5690 {
9fd767c5 5691 if (TYPE_ALIGN (TREE_TYPE (*node)) <= BITS_PER_UNIT
5692 /* Still pack bitfields. */
5693 && ! DECL_INITIAL (*node))
c2ab04f9 5694 warning (OPT_Wattributes,
5695 "%qE attribute ignored for field of type %qT",
5696 name, TREE_TYPE (*node));
5697 else
5698 DECL_PACKED (*node) = 1;
5699 }
f8e93a2e 5700 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
f40175cb 5701 used for DECL_REGISTER. It wouldn't mean anything anyway.
5702 We can't set DECL_PACKED on the type of a TYPE_DECL, because
5703 that changes what the typedef is typing. */
f8e93a2e 5704 else
5705 {
9b2d6d13 5706 warning (OPT_Wattributes, "%qE attribute ignored", name);
f8e93a2e 5707 *no_add_attrs = true;
5708 }
5709
5710 return NULL_TREE;
5711}
5712
5713/* Handle a "nocommon" attribute; arguments as in
5714 struct attribute_spec.handler. */
5715
5716static tree
1cae46be 5717handle_nocommon_attribute (tree *node, tree name,
9a03a746 5718 tree ARG_UNUSED (args),
5719 int ARG_UNUSED (flags), bool *no_add_attrs)
f8e93a2e 5720{
5721 if (TREE_CODE (*node) == VAR_DECL)
5722 DECL_COMMON (*node) = 0;
5723 else
5724 {
9b2d6d13 5725 warning (OPT_Wattributes, "%qE attribute ignored", name);
f8e93a2e 5726 *no_add_attrs = true;
5727 }
5728
5729 return NULL_TREE;
5730}
5731
5732/* Handle a "common" attribute; arguments as in
5733 struct attribute_spec.handler. */
5734
5735static tree
9a03a746 5736handle_common_attribute (tree *node, tree name, tree ARG_UNUSED (args),
5737 int ARG_UNUSED (flags), bool *no_add_attrs)
f8e93a2e 5738{
5739 if (TREE_CODE (*node) == VAR_DECL)
5740 DECL_COMMON (*node) = 1;
5741 else
5742 {
9b2d6d13 5743 warning (OPT_Wattributes, "%qE attribute ignored", name);
f8e93a2e 5744 *no_add_attrs = true;
5745 }
5746
5747 return NULL_TREE;
5748}
5749
5750/* Handle a "noreturn" attribute; arguments as in
5751 struct attribute_spec.handler. */
5752
5753static tree
9a03a746 5754handle_noreturn_attribute (tree *node, tree name, tree ARG_UNUSED (args),
5755 int ARG_UNUSED (flags), bool *no_add_attrs)
f8e93a2e 5756{
5757 tree type = TREE_TYPE (*node);
5758
5759 /* See FIXME comment in c_common_attribute_table. */
8c582e4f 5760 if (TREE_CODE (*node) == FUNCTION_DECL
5761 || objc_method_decl (TREE_CODE (*node)))
f8e93a2e 5762 TREE_THIS_VOLATILE (*node) = 1;
5763 else if (TREE_CODE (type) == POINTER_TYPE
5764 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
5765 TREE_TYPE (*node)
5766 = build_pointer_type
5767 (build_type_variant (TREE_TYPE (type),
71bda45d 5768 TYPE_READONLY (TREE_TYPE (type)), 1));
f8e93a2e 5769 else
5770 {
9b2d6d13 5771 warning (OPT_Wattributes, "%qE attribute ignored", name);
f8e93a2e 5772 *no_add_attrs = true;
5773 }
5774
5775 return NULL_TREE;
5776}
5777
5de92639 5778/* Handle a "hot" and attribute; arguments as in
5779 struct attribute_spec.handler. */
5780
5781static tree
5782handle_hot_attribute (tree *node, tree name, tree ARG_UNUSED (args),
46f8e3b0 5783 int ARG_UNUSED (flags), bool *no_add_attrs)
5de92639 5784{
5785 if (TREE_CODE (*node) == FUNCTION_DECL)
5786 {
5787 if (lookup_attribute ("cold", DECL_ATTRIBUTES (*node)) != NULL)
5788 {
5789 warning (OPT_Wattributes, "%qE attribute conflicts with attribute %s",
5790 name, "cold");
5791 *no_add_attrs = true;
5792 }
24470055 5793 /* Most of the rest of the hot processing is done later with
5794 lookup_attribute. */
5de92639 5795 }
5796 else
5797 {
5798 warning (OPT_Wattributes, "%qE attribute ignored", name);
5799 *no_add_attrs = true;
5800 }
5801
5802 return NULL_TREE;
5803}
5804/* Handle a "cold" and attribute; arguments as in
5805 struct attribute_spec.handler. */
5806
5807static tree
5808handle_cold_attribute (tree *node, tree name, tree ARG_UNUSED (args),
5809 int ARG_UNUSED (flags), bool *no_add_attrs)
5810{
5811 if (TREE_CODE (*node) == FUNCTION_DECL)
5812 {
5813 if (lookup_attribute ("hot", DECL_ATTRIBUTES (*node)) != NULL)
5814 {
5815 warning (OPT_Wattributes, "%qE attribute conflicts with attribute %s",
5816 name, "hot");
5817 *no_add_attrs = true;
5818 }
24470055 5819 /* Most of the rest of the cold processing is done later with
5820 lookup_attribute. */
5de92639 5821 }
5822 else
5823 {
5824 warning (OPT_Wattributes, "%qE attribute ignored", name);
5825 *no_add_attrs = true;
5826 }
5827
5828 return NULL_TREE;
5829}
5830
f8e93a2e 5831/* Handle a "noinline" attribute; arguments as in
5832 struct attribute_spec.handler. */
5833
5834static tree
1cae46be 5835handle_noinline_attribute (tree *node, tree name,
9a03a746 5836 tree ARG_UNUSED (args),
5837 int ARG_UNUSED (flags), bool *no_add_attrs)
f8e93a2e 5838{
5839 if (TREE_CODE (*node) == FUNCTION_DECL)
5840 DECL_UNINLINABLE (*node) = 1;
5841 else
5842 {
9b2d6d13 5843 warning (OPT_Wattributes, "%qE attribute ignored", name);
f8e93a2e 5844 *no_add_attrs = true;
5845 }
5846
5847 return NULL_TREE;
5848}
5849
bdb1f0d1 5850/* Handle a "noclone" attribute; arguments as in
5851 struct attribute_spec.handler. */
5852
5853static tree
5854handle_noclone_attribute (tree *node, tree name,
5855 tree ARG_UNUSED (args),
5856 int ARG_UNUSED (flags), bool *no_add_attrs)
5857{
5858 if (TREE_CODE (*node) != FUNCTION_DECL)
5859 {
5860 warning (OPT_Wattributes, "%qE attribute ignored", name);
5861 *no_add_attrs = true;
5862 }
5863
5864 return NULL_TREE;
5865}
5866
f8e93a2e 5867/* Handle a "always_inline" attribute; arguments as in
5868 struct attribute_spec.handler. */
5869
5870static tree
1cae46be 5871handle_always_inline_attribute (tree *node, tree name,
9a03a746 5872 tree ARG_UNUSED (args),
5873 int ARG_UNUSED (flags),
09347743 5874 bool *no_add_attrs)
f8e93a2e 5875{
5876 if (TREE_CODE (*node) == FUNCTION_DECL)
5877 {
ebb7d626 5878 /* Set the attribute and mark it for disregarding inline
5879 limits. */
5880 DECL_DISREGARD_INLINE_LIMITS (*node) = 1;
f8e93a2e 5881 }
5882 else
5883 {
9b2d6d13 5884 warning (OPT_Wattributes, "%qE attribute ignored", name);
f8e93a2e 5885 *no_add_attrs = true;
541e4101 5886 }
5887
5888 return NULL_TREE;
5889}
5890
5891/* Handle a "gnu_inline" attribute; arguments as in
5892 struct attribute_spec.handler. */
5893
5894static tree
5895handle_gnu_inline_attribute (tree *node, tree name,
5896 tree ARG_UNUSED (args),
5897 int ARG_UNUSED (flags),
5898 bool *no_add_attrs)
5899{
5900 if (TREE_CODE (*node) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (*node))
5901 {
5902 /* Do nothing else, just set the attribute. We'll get at
5903 it later with lookup_attribute. */
5904 }
5905 else
5906 {
5907 warning (OPT_Wattributes, "%qE attribute ignored", name);
5908 *no_add_attrs = true;
7bd95dfd 5909 }
5910
5911 return NULL_TREE;
5912}
5913
5914/* Handle a "leaf" attribute; arguments as in
5915 struct attribute_spec.handler. */
5916
5917static tree
5918handle_leaf_attribute (tree *node, tree name,
5919 tree ARG_UNUSED (args),
5920 int ARG_UNUSED (flags), bool *no_add_attrs)
5921{
5922 if (TREE_CODE (*node) != FUNCTION_DECL)
5923 {
5924 warning (OPT_Wattributes, "%qE attribute ignored", name);
5925 *no_add_attrs = true;
5926 }
5927 if (!TREE_PUBLIC (*node))
5928 {
5929 warning (OPT_Wattributes, "%qE attribute has no effect on unit local functions", name);
5930 *no_add_attrs = true;
f8e93a2e 5931 }
5932
5933 return NULL_TREE;
5934}
5935
1b16fc45 5936/* Handle an "artificial" attribute; arguments as in
5937 struct attribute_spec.handler. */
5938
5939static tree
5940handle_artificial_attribute (tree *node, tree name,
5941 tree ARG_UNUSED (args),
5942 int ARG_UNUSED (flags),
5943 bool *no_add_attrs)
5944{
5945 if (TREE_CODE (*node) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (*node))
5946 {
5947 /* Do nothing else, just set the attribute. We'll get at
5948 it later with lookup_attribute. */
5949 }
5950 else
5951 {
5952 warning (OPT_Wattributes, "%qE attribute ignored", name);
5953 *no_add_attrs = true;
5954 }
5955
5956 return NULL_TREE;
5957}
5958
0cdd9887 5959/* Handle a "flatten" attribute; arguments as in
5960 struct attribute_spec.handler. */
5961
5962static tree
5963handle_flatten_attribute (tree *node, tree name,
a0c938f0 5964 tree args ATTRIBUTE_UNUSED,
5965 int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
0cdd9887 5966{
5967 if (TREE_CODE (*node) == FUNCTION_DECL)
5968 /* Do nothing else, just set the attribute. We'll get at
5969 it later with lookup_attribute. */
5970 ;
5971 else
5972 {
5973 warning (OPT_Wattributes, "%qE attribute ignored", name);
5974 *no_add_attrs = true;
5975 }
5976
5977 return NULL_TREE;
5978}
5979
10fc867f 5980/* Handle a "warning" or "error" attribute; arguments as in
5981 struct attribute_spec.handler. */
5982
5983static tree
5984handle_error_attribute (tree *node, tree name, tree args,
5985 int ARG_UNUSED (flags), bool *no_add_attrs)
5986{
5987 if (TREE_CODE (*node) == FUNCTION_DECL
5988 || TREE_CODE (TREE_VALUE (args)) == STRING_CST)
5989 /* Do nothing else, just set the attribute. We'll get at
5990 it later with lookup_attribute. */
5991 ;
5992 else
5993 {
5994 warning (OPT_Wattributes, "%qE attribute ignored", name);
5995 *no_add_attrs = true;
5996 }
5997
5998 return NULL_TREE;
5999}
0cdd9887 6000
f8e93a2e 6001/* Handle a "used" attribute; arguments as in
6002 struct attribute_spec.handler. */
6003
6004static tree
9a03a746 6005handle_used_attribute (tree *pnode, tree name, tree ARG_UNUSED (args),
6006 int ARG_UNUSED (flags), bool *no_add_attrs)
f8e93a2e 6007{
d0a31bd8 6008 tree node = *pnode;
6009
6010 if (TREE_CODE (node) == FUNCTION_DECL
6011 || (TREE_CODE (node) == VAR_DECL && TREE_STATIC (node)))
f54ed8bc 6012 {
f54ed8bc 6013 TREE_USED (node) = 1;
9423c9b7 6014 DECL_PRESERVE_P (node) = 1;
abc6c64f 6015 if (TREE_CODE (node) == VAR_DECL)
6016 DECL_READ_P (node) = 1;
f54ed8bc 6017 }
f8e93a2e 6018 else
6019 {
9b2d6d13 6020 warning (OPT_Wattributes, "%qE attribute ignored", name);
f8e93a2e 6021 *no_add_attrs = true;
6022 }
6023
6024 return NULL_TREE;
6025}
6026
6027/* Handle a "unused" attribute; arguments as in
6028 struct attribute_spec.handler. */
6029
6030static tree
9a03a746 6031handle_unused_attribute (tree *node, tree name, tree ARG_UNUSED (args),
6032 int flags, bool *no_add_attrs)
f8e93a2e 6033{
6034 if (DECL_P (*node))
6035 {
6036 tree decl = *node;
6037
6038 if (TREE_CODE (decl) == PARM_DECL
6039 || TREE_CODE (decl) == VAR_DECL
6040 || TREE_CODE (decl) == FUNCTION_DECL
6041 || TREE_CODE (decl) == LABEL_DECL
6042 || TREE_CODE (decl) == TYPE_DECL)
abc6c64f 6043 {
6044 TREE_USED (decl) = 1;
6045 if (TREE_CODE (decl) == VAR_DECL
6046 || TREE_CODE (decl) == PARM_DECL)
6047 DECL_READ_P (decl) = 1;
6048 }
f8e93a2e 6049 else
6050 {
9b2d6d13 6051 warning (OPT_Wattributes, "%qE attribute ignored", name);
f8e93a2e 6052 *no_add_attrs = true;
6053 }
6054 }
6055 else
6056 {
6057 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
e086912e 6058 *node = build_variant_type_copy (*node);
f8e93a2e 6059 TREE_USED (*node) = 1;
6060 }
6061
6062 return NULL_TREE;
6063}
6064
62eec3b4 6065/* Handle a "externally_visible" attribute; arguments as in
6066 struct attribute_spec.handler. */
6067
6068static tree
6069handle_externally_visible_attribute (tree *pnode, tree name,
6070 tree ARG_UNUSED (args),
6071 int ARG_UNUSED (flags),
6072 bool *no_add_attrs)
6073{
6074 tree node = *pnode;
6075
ba12ea31 6076 if (TREE_CODE (node) == FUNCTION_DECL || TREE_CODE (node) == VAR_DECL)
62eec3b4 6077 {
ba12ea31 6078 if ((!TREE_STATIC (node) && TREE_CODE (node) != FUNCTION_DECL
6079 && !DECL_EXTERNAL (node)) || !TREE_PUBLIC (node))
6080 {
6081 warning (OPT_Wattributes,
6082 "%qE attribute have effect only on public objects", name);
6083 *no_add_attrs = true;
6084 }
62eec3b4 6085 }
62eec3b4 6086 else
6087 {
6088 warning (OPT_Wattributes, "%qE attribute ignored", name);
6089 *no_add_attrs = true;
6090 }
6091
6092 return NULL_TREE;
6093}
6094
f8e93a2e 6095/* Handle a "const" attribute; arguments as in
6096 struct attribute_spec.handler. */
6097
6098static tree
9a03a746 6099handle_const_attribute (tree *node, tree name, tree ARG_UNUSED (args),
6100 int ARG_UNUSED (flags), bool *no_add_attrs)
f8e93a2e 6101{
6102 tree type = TREE_TYPE (*node);
6103
6104 /* See FIXME comment on noreturn in c_common_attribute_table. */
6105 if (TREE_CODE (*node) == FUNCTION_DECL)
6106 TREE_READONLY (*node) = 1;
6107 else if (TREE_CODE (type) == POINTER_TYPE
6108 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
6109 TREE_TYPE (*node)
6110 = build_pointer_type
6111 (build_type_variant (TREE_TYPE (type), 1,
6112 TREE_THIS_VOLATILE (TREE_TYPE (type))));
6113 else
6114 {
9b2d6d13 6115 warning (OPT_Wattributes, "%qE attribute ignored", name);
f8e93a2e 6116 *no_add_attrs = true;
6117 }
6118
6119 return NULL_TREE;
6120}
6121
6122/* Handle a "transparent_union" attribute; arguments as in
6123 struct attribute_spec.handler. */
6124
6125static tree
1cae46be 6126handle_transparent_union_attribute (tree *node, tree name,
9a03a746 6127 tree ARG_UNUSED (args), int flags,
09347743 6128 bool *no_add_attrs)
f8e93a2e 6129{
881eb642 6130 tree type;
03908818 6131
6132 *no_add_attrs = true;
f8e93a2e 6133
881eb642 6134 if (TREE_CODE (*node) == TYPE_DECL)
6135 node = &TREE_TYPE (*node);
6136 type = *node;
f8e93a2e 6137
03908818 6138 if (TREE_CODE (type) == UNION_TYPE)
f8e93a2e 6139 {
03908818 6140 /* When IN_PLACE is set, leave the check for FIELDS and MODE to
6141 the code in finish_struct. */
f8e93a2e 6142 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
03908818 6143 {
6144 if (TYPE_FIELDS (type) == NULL_TREE
6145 || TYPE_MODE (type) != DECL_MODE (TYPE_FIELDS (type)))
6146 goto ignored;
6147
6148 /* A type variant isn't good enough, since we don't a cast
6149 to such a type removed as a no-op. */
6150 *node = type = build_duplicate_type (type);
6151 }
6152
8df5a43d 6153 TYPE_TRANSPARENT_AGGR (type) = 1;
03908818 6154 return NULL_TREE;
f8e93a2e 6155 }
6156
03908818 6157 ignored:
6158 warning (OPT_Wattributes, "%qE attribute ignored", name);
f8e93a2e 6159 return NULL_TREE;
6160}
6161
9af7fd5b 6162/* Subroutine of handle_{con,de}structor_attribute. Evaluate ARGS to
6163 get the requested priority for a constructor or destructor,
6164 possibly issuing diagnostics for invalid or reserved
6165 priorities. */
6166
6167static priority_type
6168get_priority (tree args, bool is_destructor)
6169{
6170 HOST_WIDE_INT pri;
6c181a06 6171 tree arg;
9af7fd5b 6172
6173 if (!args)
6174 return DEFAULT_INIT_PRIORITY;
48e1416a 6175
28fbc04f 6176 if (!SUPPORTS_INIT_PRIORITY)
6177 {
6178 if (is_destructor)
6179 error ("destructor priorities are not supported");
6180 else
6181 error ("constructor priorities are not supported");
6182 return DEFAULT_INIT_PRIORITY;
6183 }
6184
6c181a06 6185 arg = TREE_VALUE (args);
6186 if (!host_integerp (arg, /*pos=*/0)
6187 || !INTEGRAL_TYPE_P (TREE_TYPE (arg)))
9af7fd5b 6188 goto invalid;
6189
6190 pri = tree_low_cst (TREE_VALUE (args), /*pos=*/0);
6191 if (pri < 0 || pri > MAX_INIT_PRIORITY)
6192 goto invalid;
6193
6194 if (pri <= MAX_RESERVED_INIT_PRIORITY)
6195 {
6196 if (is_destructor)
6197 warning (0,
6198 "destructor priorities from 0 to %d are reserved "
48e1416a 6199 "for the implementation",
9af7fd5b 6200 MAX_RESERVED_INIT_PRIORITY);
6201 else
6202 warning (0,
6203 "constructor priorities from 0 to %d are reserved "
48e1416a 6204 "for the implementation",
9af7fd5b 6205 MAX_RESERVED_INIT_PRIORITY);
6206 }
6207 return pri;
6208
6209 invalid:
6210 if (is_destructor)
6211 error ("destructor priorities must be integers from 0 to %d inclusive",
6212 MAX_INIT_PRIORITY);
6213 else
6214 error ("constructor priorities must be integers from 0 to %d inclusive",
6215 MAX_INIT_PRIORITY);
6216 return DEFAULT_INIT_PRIORITY;
6217}
6218
f8e93a2e 6219/* Handle a "constructor" attribute; arguments as in
6220 struct attribute_spec.handler. */
6221
6222static tree
9af7fd5b 6223handle_constructor_attribute (tree *node, tree name, tree args,
9a03a746 6224 int ARG_UNUSED (flags),
09347743 6225 bool *no_add_attrs)
f8e93a2e 6226{
6227 tree decl = *node;
6228 tree type = TREE_TYPE (decl);
6229
6230 if (TREE_CODE (decl) == FUNCTION_DECL
6231 && TREE_CODE (type) == FUNCTION_TYPE
6232 && decl_function_context (decl) == 0)
6233 {
9af7fd5b 6234 priority_type priority;
f8e93a2e 6235 DECL_STATIC_CONSTRUCTOR (decl) = 1;
9af7fd5b 6236 priority = get_priority (args, /*is_destructor=*/false);
6237 SET_DECL_INIT_PRIORITY (decl, priority);
f8e93a2e 6238 TREE_USED (decl) = 1;
6239 }
6240 else
6241 {
9b2d6d13 6242 warning (OPT_Wattributes, "%qE attribute ignored", name);
f8e93a2e 6243 *no_add_attrs = true;
6244 }
6245
6246 return NULL_TREE;
6247}
6248
6249/* Handle a "destructor" attribute; arguments as in
6250 struct attribute_spec.handler. */
6251
6252static tree
9af7fd5b 6253handle_destructor_attribute (tree *node, tree name, tree args,
9a03a746 6254 int ARG_UNUSED (flags),
09347743 6255 bool *no_add_attrs)
f8e93a2e 6256{
6257 tree decl = *node;
6258 tree type = TREE_TYPE (decl);
6259
6260 if (TREE_CODE (decl) == FUNCTION_DECL
6261 && TREE_CODE (type) == FUNCTION_TYPE
6262 && decl_function_context (decl) == 0)
6263 {
9af7fd5b 6264 priority_type priority;
f8e93a2e 6265 DECL_STATIC_DESTRUCTOR (decl) = 1;
9af7fd5b 6266 priority = get_priority (args, /*is_destructor=*/true);
6267 SET_DECL_FINI_PRIORITY (decl, priority);
f8e93a2e 6268 TREE_USED (decl) = 1;
6269 }
6270 else
6271 {
9b2d6d13 6272 warning (OPT_Wattributes, "%qE attribute ignored", name);
f8e93a2e 6273 *no_add_attrs = true;
6274 }
6275
6276 return NULL_TREE;
6277}
6278
1c58e3f1 6279/* Nonzero if the mode is a valid vector mode for this architecture.
6280 This returns nonzero even if there is no hardware support for the
6281 vector mode, but we can emulate with narrower modes. */
6282
6283static int
6284vector_mode_valid_p (enum machine_mode mode)
6285{
6286 enum mode_class mclass = GET_MODE_CLASS (mode);
6287 enum machine_mode innermode;
6288
6289 /* Doh! What's going on? */
6290 if (mclass != MODE_VECTOR_INT
6291 && mclass != MODE_VECTOR_FLOAT
6292 && mclass != MODE_VECTOR_FRACT
6293 && mclass != MODE_VECTOR_UFRACT
6294 && mclass != MODE_VECTOR_ACCUM
6295 && mclass != MODE_VECTOR_UACCUM)
6296 return 0;
6297
6298 /* Hardware support. Woo hoo! */
6299 if (targetm.vector_mode_supported_p (mode))
6300 return 1;
6301
6302 innermode = GET_MODE_INNER (mode);
6303
6304 /* We should probably return 1 if requesting V4DI and we have no DI,
6305 but we have V2DI, but this is probably very unlikely. */
6306
6307 /* If we have support for the inner mode, we can safely emulate it.
6308 We may not have V2DI, but me can emulate with a pair of DIs. */
6309 return targetm.scalar_mode_supported_p (innermode);
6310}
6311
6312
f8e93a2e 6313/* Handle a "mode" attribute; arguments as in
6314 struct attribute_spec.handler. */
6315
6316static tree
9a03a746 6317handle_mode_attribute (tree *node, tree name, tree args,
6318 int ARG_UNUSED (flags), bool *no_add_attrs)
f8e93a2e 6319{
6320 tree type = *node;
d1dd9ac0 6321 tree ident = TREE_VALUE (args);
f8e93a2e 6322
6323 *no_add_attrs = true;
6324
d1dd9ac0 6325 if (TREE_CODE (ident) != IDENTIFIER_NODE)
9b2d6d13 6326 warning (OPT_Wattributes, "%qE attribute ignored", name);
f8e93a2e 6327 else
6328 {
6329 int j;
d1dd9ac0 6330 const char *p = IDENTIFIER_POINTER (ident);
f8e93a2e 6331 int len = strlen (p);
6332 enum machine_mode mode = VOIDmode;
6333 tree typefm;
b2aef146 6334 bool valid_mode;
f8e93a2e 6335
6336 if (len > 4 && p[0] == '_' && p[1] == '_'
6337 && p[len - 1] == '_' && p[len - 2] == '_')
6338 {
4fd61bc6 6339 char *newp = (char *) alloca (len - 1);
f8e93a2e 6340
6341 strcpy (newp, &p[2]);
6342 newp[len - 4] = '\0';
6343 p = newp;
6344 }
6345
6346 /* Change this type to have a type with the specified mode.
6347 First check for the special modes. */
84166705 6348 if (!strcmp (p, "byte"))
f8e93a2e 6349 mode = byte_mode;
6350 else if (!strcmp (p, "word"))
6351 mode = word_mode;
84166705 6352 else if (!strcmp (p, "pointer"))
f8e93a2e 6353 mode = ptr_mode;
0ef89dfd 6354 else if (!strcmp (p, "libgcc_cmp_return"))
6355 mode = targetm.libgcc_cmp_return_mode ();
6356 else if (!strcmp (p, "libgcc_shift_count"))
6357 mode = targetm.libgcc_shift_count_mode ();
1bd43494 6358 else if (!strcmp (p, "unwind_word"))
6359 mode = targetm.unwind_word_mode ();
f8e93a2e 6360 else
6361 for (j = 0; j < NUM_MACHINE_MODES; j++)
6362 if (!strcmp (p, GET_MODE_NAME (j)))
743a6f47 6363 {
6364 mode = (enum machine_mode) j;
6365 break;
6366 }
f8e93a2e 6367
6368 if (mode == VOIDmode)
4917c376 6369 {
d1dd9ac0 6370 error ("unknown machine mode %qE", ident);
4917c376 6371 return NULL_TREE;
6372 }
6373
b2aef146 6374 valid_mode = false;
6375 switch (GET_MODE_CLASS (mode))
4917c376 6376 {
b2aef146 6377 case MODE_INT:
6378 case MODE_PARTIAL_INT:
6379 case MODE_FLOAT:
c4503c0a 6380 case MODE_DECIMAL_FLOAT:
9421ebb9 6381 case MODE_FRACT:
6382 case MODE_UFRACT:
6383 case MODE_ACCUM:
6384 case MODE_UACCUM:
b2aef146 6385 valid_mode = targetm.scalar_mode_supported_p (mode);
6386 break;
6387
6388 case MODE_COMPLEX_INT:
6389 case MODE_COMPLEX_FLOAT:
6390 valid_mode = targetm.scalar_mode_supported_p (GET_MODE_INNER (mode));
6391 break;
6392
6393 case MODE_VECTOR_INT:
6394 case MODE_VECTOR_FLOAT:
9421ebb9 6395 case MODE_VECTOR_FRACT:
6396 case MODE_VECTOR_UFRACT:
6397 case MODE_VECTOR_ACCUM:
6398 case MODE_VECTOR_UACCUM:
9b2d6d13 6399 warning (OPT_Wattributes, "specifying vector types with "
6400 "__attribute__ ((mode)) is deprecated");
6401 warning (OPT_Wattributes,
6402 "use __attribute__ ((vector_size)) instead");
b2aef146 6403 valid_mode = vector_mode_valid_p (mode);
6404 break;
4917c376 6405
b2aef146 6406 default:
6407 break;
6408 }
6409 if (!valid_mode)
6410 {
1e5fcbe2 6411 error ("unable to emulate %qs", p);
b2aef146 6412 return NULL_TREE;
6413 }
4917c376 6414
b2aef146 6415 if (POINTER_TYPE_P (type))
ead34f59 6416 {
6d5d708e 6417 addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (type));
b2aef146 6418 tree (*fn)(tree, enum machine_mode, bool);
6419
6d5d708e 6420 if (!targetm.addr_space.valid_pointer_mode (mode, as))
ead34f59 6421 {
1e5fcbe2 6422 error ("invalid pointer mode %qs", p);
ead34f59 6423 return NULL_TREE;
6424 }
6425
a0c938f0 6426 if (TREE_CODE (type) == POINTER_TYPE)
b2aef146 6427 fn = build_pointer_type_for_mode;
805e22b2 6428 else
b2aef146 6429 fn = build_reference_type_for_mode;
6430 typefm = fn (TREE_TYPE (type), mode, false);
ead34f59 6431 }
b2aef146 6432 else
9421ebb9 6433 {
6434 /* For fixed-point modes, we need to test if the signness of type
6435 and the machine mode are consistent. */
6436 if (ALL_FIXED_POINT_MODE_P (mode)
6437 && TYPE_UNSIGNED (type) != UNSIGNED_FIXED_POINT_MODE_P (mode))
6438 {
bf776685 6439 error ("signedness of type and machine mode %qs don%'t match", p);
9421ebb9 6440 return NULL_TREE;
6441 }
6442 /* For fixed-point modes, we need to pass saturating info. */
6443 typefm = lang_hooks.types.type_for_mode (mode,
6444 ALL_FIXED_POINT_MODE_P (mode) ? TYPE_SATURATING (type)
6445 : TYPE_UNSIGNED (type));
6446 }
3a648ab9 6447
b2aef146 6448 if (typefm == NULL_TREE)
6449 {
743a6f47 6450 error ("no data type for mode %qs", p);
b2aef146 6451 return NULL_TREE;
6452 }
3a648ab9 6453 else if (TREE_CODE (type) == ENUMERAL_TYPE)
6454 {
6455 /* For enumeral types, copy the precision from the integer
6456 type returned above. If not an INTEGER_TYPE, we can't use
6457 this mode for this type. */
6458 if (TREE_CODE (typefm) != INTEGER_TYPE)
6459 {
743a6f47 6460 error ("cannot use mode %qs for enumeral types", p);
3a648ab9 6461 return NULL_TREE;
6462 }
6463
10080eac 6464 if (flags & ATTR_FLAG_TYPE_IN_PLACE)
6465 {
6466 TYPE_PRECISION (type) = TYPE_PRECISION (typefm);
6467 typefm = type;
6468 }
6469 else
6470 {
6471 /* We cannot build a type variant, as there's code that assumes
6472 that TYPE_MAIN_VARIANT has the same mode. This includes the
6473 debug generators. Instead, create a subrange type. This
6474 results in all of the enumeral values being emitted only once
6475 in the original, and the subtype gets them by reference. */
6476 if (TYPE_UNSIGNED (type))
6477 typefm = make_unsigned_type (TYPE_PRECISION (typefm));
6478 else
6479 typefm = make_signed_type (TYPE_PRECISION (typefm));
6480 TREE_TYPE (typefm) = type;
6481 }
3a648ab9 6482 }
4bf450a1 6483 else if (VECTOR_MODE_P (mode)
6484 ? TREE_CODE (type) != TREE_CODE (TREE_TYPE (typefm))
6485 : TREE_CODE (type) != TREE_CODE (typefm))
743a6f47 6486 {
6487 error ("mode %qs applied to inappropriate type", p);
6488 return NULL_TREE;
6489 }
6490
b2aef146 6491 *node = typefm;
f8e93a2e 6492 }
6493
6494 return NULL_TREE;
6495}
6496
6497/* Handle a "section" attribute; arguments as in
6498 struct attribute_spec.handler. */
6499
6500static tree
9a03a746 6501handle_section_attribute (tree *node, tree ARG_UNUSED (name), tree args,
6502 int ARG_UNUSED (flags), bool *no_add_attrs)
f8e93a2e 6503{
6504 tree decl = *node;
6505
6506 if (targetm.have_named_sections)
6507 {
065efcb1 6508 user_defined_section_attribute = true;
6509
f8e93a2e 6510 if ((TREE_CODE (decl) == FUNCTION_DECL
6511 || TREE_CODE (decl) == VAR_DECL)
6512 && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
6513 {
6514 if (TREE_CODE (decl) == VAR_DECL
6515 && current_function_decl != NULL_TREE
84166705 6516 && !TREE_STATIC (decl))
f8e93a2e 6517 {
48e1416a 6518 error_at (DECL_SOURCE_LOCATION (decl),
712d2297 6519 "section attribute cannot be specified for "
6520 "local variables");
f8e93a2e 6521 *no_add_attrs = true;
6522 }
6523
6524 /* The decl may have already been given a section attribute
6525 from a previous declaration. Ensure they match. */
6526 else if (DECL_SECTION_NAME (decl) != NULL_TREE
6527 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)),
6528 TREE_STRING_POINTER (TREE_VALUE (args))) != 0)
6529 {
3cf8b391 6530 error ("section of %q+D conflicts with previous declaration",
6531 *node);
f8e93a2e 6532 *no_add_attrs = true;
6533 }
38475469 6534 else if (TREE_CODE (decl) == VAR_DECL
6535 && !targetm.have_tls && targetm.emutls.tmpl_section
6536 && DECL_THREAD_LOCAL_P (decl))
6537 {
6538 error ("section of %q+D cannot be overridden", *node);
6539 *no_add_attrs = true;
6540 }
f8e93a2e 6541 else
6542 DECL_SECTION_NAME (decl) = TREE_VALUE (args);
6543 }
6544 else
6545 {
3cf8b391 6546 error ("section attribute not allowed for %q+D", *node);
f8e93a2e 6547 *no_add_attrs = true;
6548 }
6549 }
6550 else
6551 {
712d2297 6552 error_at (DECL_SOURCE_LOCATION (*node),
6553 "section attributes are not supported for this target");
f8e93a2e 6554 *no_add_attrs = true;
6555 }
6556
6557 return NULL_TREE;
6558}
6559
6560/* Handle a "aligned" attribute; arguments as in
6561 struct attribute_spec.handler. */
6562
6563static tree
9a03a746 6564handle_aligned_attribute (tree *node, tree ARG_UNUSED (name), tree args,
09347743 6565 int flags, bool *no_add_attrs)
f8e93a2e 6566{
6567 tree decl = NULL_TREE;
6568 tree *type = NULL;
6569 int is_type = 0;
6570 tree align_expr = (args ? TREE_VALUE (args)
02421213 6571 : size_int (ATTRIBUTE_ALIGNED_VALUE / BITS_PER_UNIT));
f8e93a2e 6572 int i;
6573
6574 if (DECL_P (*node))
6575 {
6576 decl = *node;
6577 type = &TREE_TYPE (decl);
6578 is_type = TREE_CODE (*node) == TYPE_DECL;
6579 }
6580 else if (TYPE_P (*node))
6581 type = node, is_type = 1;
6582
f8e93a2e 6583 if (TREE_CODE (align_expr) != INTEGER_CST)
6584 {
6585 error ("requested alignment is not a constant");
6586 *no_add_attrs = true;
6587 }
6588 else if ((i = tree_log2 (align_expr)) == -1)
6589 {
6590 error ("requested alignment is not a power of 2");
6591 *no_add_attrs = true;
6592 }
7cfdc2f0 6593 else if (i >= HOST_BITS_PER_INT - BITS_PER_UNIT_LOG)
f8e93a2e 6594 {
6595 error ("requested alignment is too large");
6596 *no_add_attrs = true;
6597 }
6598 else if (is_type)
6599 {
2ec3af9c 6600 if ((flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
6601 /* OK, modify the type in place. */;
f8e93a2e 6602 /* If we have a TYPE_DECL, then copy the type, so that we
6603 don't accidentally modify a builtin type. See pushdecl. */
2ec3af9c 6604 else if (decl && TREE_TYPE (decl) != error_mark_node
6605 && DECL_ORIGINAL_TYPE (decl) == NULL_TREE)
f8e93a2e 6606 {
6607 tree tt = TREE_TYPE (decl);
e086912e 6608 *type = build_variant_type_copy (*type);
f8e93a2e 6609 DECL_ORIGINAL_TYPE (decl) = tt;
6610 TYPE_NAME (*type) = decl;
6611 TREE_USED (*type) = TREE_USED (decl);
6612 TREE_TYPE (decl) = *type;
6613 }
2ec3af9c 6614 else
e086912e 6615 *type = build_variant_type_copy (*type);
f8e93a2e 6616
7cfdc2f0 6617 TYPE_ALIGN (*type) = (1U << i) * BITS_PER_UNIT;
f8e93a2e 6618 TYPE_USER_ALIGN (*type) = 1;
6619 }
097b5c8b 6620 else if (! VAR_OR_FUNCTION_DECL_P (decl)
f8e93a2e 6621 && TREE_CODE (decl) != FIELD_DECL)
6622 {
3cf8b391 6623 error ("alignment may not be specified for %q+D", decl);
f8e93a2e 6624 *no_add_attrs = true;
6625 }
097b5c8b 6626 else if (TREE_CODE (decl) == FUNCTION_DECL
7cfdc2f0 6627 && DECL_ALIGN (decl) > (1U << i) * BITS_PER_UNIT)
097b5c8b 6628 {
6629 if (DECL_USER_ALIGN (decl))
6630 error ("alignment for %q+D was previously specified as %d "
6631 "and may not be decreased", decl,
6632 DECL_ALIGN (decl) / BITS_PER_UNIT);
6633 else
6634 error ("alignment for %q+D must be at least %d", decl,
6635 DECL_ALIGN (decl) / BITS_PER_UNIT);
6636 *no_add_attrs = true;
6637 }
f8e93a2e 6638 else
6639 {
7cfdc2f0 6640 DECL_ALIGN (decl) = (1U << i) * BITS_PER_UNIT;
f8e93a2e 6641 DECL_USER_ALIGN (decl) = 1;
6642 }
6643
6644 return NULL_TREE;
6645}
6646
6647/* Handle a "weak" attribute; arguments as in
6648 struct attribute_spec.handler. */
6649
6650static tree
f948b309 6651handle_weak_attribute (tree *node, tree name,
9a03a746 6652 tree ARG_UNUSED (args),
6653 int ARG_UNUSED (flags),
6654 bool * ARG_UNUSED (no_add_attrs))
f8e93a2e 6655{
f948b309 6656 if (TREE_CODE (*node) == FUNCTION_DECL
059a60f3 6657 && DECL_DECLARED_INLINE_P (*node))
6658 {
6659 error ("inline function %q+D cannot be declared weak", *node);
6660 *no_add_attrs = true;
6661 }
85c0a25c 6662 else if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node)))
6663 {
6664 error ("indirect function %q+D cannot be declared weak", *node);
6665 *no_add_attrs = true;
6666 return NULL_TREE;
6667 }
059a60f3 6668 else if (TREE_CODE (*node) == FUNCTION_DECL
6669 || TREE_CODE (*node) == VAR_DECL)
f948b309 6670 declare_weak (*node);
6671 else
6672 warning (OPT_Wattributes, "%qE attribute ignored", name);
f8e93a2e 6673
6674 return NULL_TREE;
6675}
6676
85c0a25c 6677/* Handle an "alias" or "ifunc" attribute; arguments as in
6678 struct attribute_spec.handler, except that IS_ALIAS tells us
6679 whether this is an alias as opposed to ifunc attribute. */
f8e93a2e 6680
6681static tree
85c0a25c 6682handle_alias_ifunc_attribute (bool is_alias, tree *node, tree name, tree args,
6683 bool *no_add_attrs)
f8e93a2e 6684{
6685 tree decl = *node;
6686
85c0a25c 6687 if (TREE_CODE (decl) != FUNCTION_DECL
6688 && (!is_alias || TREE_CODE (decl) != VAR_DECL))
9e830260 6689 {
6690 warning (OPT_Wattributes, "%qE attribute ignored", name);
6691 *no_add_attrs = true;
6692 }
6693 else if ((TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
48e1416a 6694 || (TREE_CODE (decl) != FUNCTION_DECL
0a3ecdc1 6695 && TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl))
6696 /* A static variable declaration is always a tentative definition,
6697 but the alias is a non-tentative definition which overrides. */
48e1416a 6698 || (TREE_CODE (decl) != FUNCTION_DECL
0a3ecdc1 6699 && ! TREE_PUBLIC (decl) && DECL_INITIAL (decl)))
f8e93a2e 6700 {
85c0a25c 6701 error ("%q+D defined both normally and as %qE attribute", decl, name);
f8e93a2e 6702 *no_add_attrs = true;
85c0a25c 6703 return NULL_TREE;
f8e93a2e 6704 }
85c0a25c 6705 else if (!is_alias
6706 && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl))
6707 || lookup_attribute ("weakref", DECL_ATTRIBUTES (decl))))
6708 {
6709 error ("weak %q+D cannot be defined %qE", decl, name);
6710 *no_add_attrs = true;
6711 return NULL_TREE;
6712 }
8c42f0d9 6713
6714 /* Note that the very first time we process a nested declaration,
6715 decl_function_context will not be set. Indeed, *would* never
6716 be set except for the DECL_INITIAL/DECL_EXTERNAL frobbery that
6717 we do below. After such frobbery, pushdecl would set the context.
6718 In any case, this is never what we want. */
6719 else if (decl_function_context (decl) == 0 && current_function_decl == NULL)
f8e93a2e 6720 {
6721 tree id;
6722
6723 id = TREE_VALUE (args);
6724 if (TREE_CODE (id) != STRING_CST)
6725 {
85c0a25c 6726 error ("attribute %qE argument not a string", name);
f8e93a2e 6727 *no_add_attrs = true;
6728 return NULL_TREE;
6729 }
6730 id = get_identifier (TREE_STRING_POINTER (id));
6731 /* This counts as a use of the object pointed to. */
6732 TREE_USED (id) = 1;
6733
6734 if (TREE_CODE (decl) == FUNCTION_DECL)
6735 DECL_INITIAL (decl) = error_mark_node;
6736 else
4ee9c684 6737 {
f4a30bd7 6738 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
6739 DECL_EXTERNAL (decl) = 1;
6740 else
6741 DECL_EXTERNAL (decl) = 0;
4ee9c684 6742 TREE_STATIC (decl) = 1;
6743 }
85c0a25c 6744
6745 if (!is_alias)
6746 /* ifuncs are also aliases, so set that attribute too. */
6747 DECL_ATTRIBUTES (decl)
6748 = tree_cons (get_identifier ("alias"), args, DECL_ATTRIBUTES (decl));
f8e93a2e 6749 }
6750 else
6751 {
9b2d6d13 6752 warning (OPT_Wattributes, "%qE attribute ignored", name);
f8e93a2e 6753 *no_add_attrs = true;
6754 }
6755
6756 return NULL_TREE;
6757}
6758
85c0a25c 6759/* Handle an "alias" or "ifunc" attribute; arguments as in
6760 struct attribute_spec.handler. */
6761
6762static tree
6763handle_ifunc_attribute (tree *node, tree name, tree args,
6764 int ARG_UNUSED (flags), bool *no_add_attrs)
6765{
6766 return handle_alias_ifunc_attribute (false, node, name, args, no_add_attrs);
6767}
6768
6769/* Handle an "alias" or "ifunc" attribute; arguments as in
6770 struct attribute_spec.handler. */
6771
6772static tree
6773handle_alias_attribute (tree *node, tree name, tree args,
6774 int ARG_UNUSED (flags), bool *no_add_attrs)
6775{
6776 return handle_alias_ifunc_attribute (true, node, name, args, no_add_attrs);
6777}
6778
f4a30bd7 6779/* Handle a "weakref" attribute; arguments as in struct
6780 attribute_spec.handler. */
6781
6782static tree
6783handle_weakref_attribute (tree *node, tree ARG_UNUSED (name), tree args,
6784 int flags, bool *no_add_attrs)
6785{
6786 tree attr = NULL_TREE;
6787
83852912 6788 /* We must ignore the attribute when it is associated with
6789 local-scoped decls, since attribute alias is ignored and many
6790 such symbols do not even have a DECL_WEAK field. */
64a7bd81 6791 if (decl_function_context (*node)
6792 || current_function_decl
6793 || (TREE_CODE (*node) != VAR_DECL && TREE_CODE (*node) != FUNCTION_DECL))
83852912 6794 {
6795 warning (OPT_Wattributes, "%qE attribute ignored", name);
6796 *no_add_attrs = true;
6797 return NULL_TREE;
6798 }
6799
85c0a25c 6800 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node)))
6801 {
6802 error ("indirect function %q+D cannot be declared weakref", *node);
6803 *no_add_attrs = true;
6804 return NULL_TREE;
6805 }
6806
f4a30bd7 6807 /* The idea here is that `weakref("name")' mutates into `weakref,
6808 alias("name")', and weakref without arguments, in turn,
6809 implicitly adds weak. */
6810
6811 if (args)
6812 {
6813 attr = tree_cons (get_identifier ("alias"), args, attr);
6814 attr = tree_cons (get_identifier ("weakref"), NULL_TREE, attr);
6815
6816 *no_add_attrs = true;
0a3ecdc1 6817
6818 decl_attributes (node, attr, flags);
f4a30bd7 6819 }
6820 else
6821 {
6822 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node)))
712d2297 6823 error_at (DECL_SOURCE_LOCATION (*node),
6824 "weakref attribute must appear before alias attribute");
f4a30bd7 6825
0a3ecdc1 6826 /* Can't call declare_weak because it wants this to be TREE_PUBLIC,
6827 and that isn't supported; and because it wants to add it to
6828 the list of weak decls, which isn't helpful. */
6829 DECL_WEAK (*node) = 1;
f4a30bd7 6830 }
6831
f4a30bd7 6832 return NULL_TREE;
6833}
6834
f8e93a2e 6835/* Handle an "visibility" attribute; arguments as in
6836 struct attribute_spec.handler. */
6837
6838static tree
1cae46be 6839handle_visibility_attribute (tree *node, tree name, tree args,
9a03a746 6840 int ARG_UNUSED (flags),
4a2849cb 6841 bool *ARG_UNUSED (no_add_attrs))
f8e93a2e 6842{
6843 tree decl = *node;
9c40570a 6844 tree id = TREE_VALUE (args);
4a2849cb 6845 enum symbol_visibility vis;
f8e93a2e 6846
b212f378 6847 if (TYPE_P (*node))
6848 {
4a2849cb 6849 if (TREE_CODE (*node) == ENUMERAL_TYPE)
6850 /* OK */;
6851 else if (TREE_CODE (*node) != RECORD_TYPE && TREE_CODE (*node) != UNION_TYPE)
6852 {
6853 warning (OPT_Wattributes, "%qE attribute ignored on non-class types",
6854 name);
6855 return NULL_TREE;
6856 }
6857 else if (TYPE_FIELDS (*node))
6858 {
6859 error ("%qE attribute ignored because %qT is already defined",
6860 name, *node);
6861 return NULL_TREE;
6862 }
b212f378 6863 }
84166705 6864 else if (decl_function_context (decl) != 0 || !TREE_PUBLIC (decl))
f8e93a2e 6865 {
9b2d6d13 6866 warning (OPT_Wattributes, "%qE attribute ignored", name);
9c40570a 6867 return NULL_TREE;
f8e93a2e 6868 }
f8e93a2e 6869
9c40570a 6870 if (TREE_CODE (id) != STRING_CST)
6871 {
07e3a3d2 6872 error ("visibility argument not a string");
9c40570a 6873 return NULL_TREE;
f8e93a2e 6874 }
b27ac6b5 6875
b212f378 6876 /* If this is a type, set the visibility on the type decl. */
6877 if (TYPE_P (decl))
6878 {
6879 decl = TYPE_NAME (decl);
84166705 6880 if (!decl)
a0c938f0 6881 return NULL_TREE;
e147aab3 6882 if (TREE_CODE (decl) == IDENTIFIER_NODE)
6883 {
9b2d6d13 6884 warning (OPT_Wattributes, "%qE attribute ignored on types",
e147aab3 6885 name);
6886 return NULL_TREE;
6887 }
b212f378 6888 }
f8e93a2e 6889
9c40570a 6890 if (strcmp (TREE_STRING_POINTER (id), "default") == 0)
4a2849cb 6891 vis = VISIBILITY_DEFAULT;
9c40570a 6892 else if (strcmp (TREE_STRING_POINTER (id), "internal") == 0)
4a2849cb 6893 vis = VISIBILITY_INTERNAL;
9c40570a 6894 else if (strcmp (TREE_STRING_POINTER (id), "hidden") == 0)
4a2849cb 6895 vis = VISIBILITY_HIDDEN;
9c40570a 6896 else if (strcmp (TREE_STRING_POINTER (id), "protected") == 0)
4a2849cb 6897 vis = VISIBILITY_PROTECTED;
9c40570a 6898 else
4a2849cb 6899 {
6900 error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
6901 vis = VISIBILITY_DEFAULT;
6902 }
6903
6904 if (DECL_VISIBILITY_SPECIFIED (decl)
098a01e7 6905 && vis != DECL_VISIBILITY (decl))
6906 {
6907 tree attributes = (TYPE_P (*node)
6908 ? TYPE_ATTRIBUTES (*node)
6909 : DECL_ATTRIBUTES (decl));
6910 if (lookup_attribute ("visibility", attributes))
6911 error ("%qD redeclared with different visibility", decl);
6912 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
6913 && lookup_attribute ("dllimport", attributes))
6914 error ("%qD was declared %qs which implies default visibility",
6915 decl, "dllimport");
6916 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
6917 && lookup_attribute ("dllexport", attributes))
6918 error ("%qD was declared %qs which implies default visibility",
6919 decl, "dllexport");
6920 }
4a2849cb 6921
6922 DECL_VISIBILITY (decl) = vis;
b212f378 6923 DECL_VISIBILITY_SPECIFIED (decl) = 1;
6924
4a2849cb 6925 /* Go ahead and attach the attribute to the node as well. This is needed
6926 so we can determine whether we have VISIBILITY_DEFAULT because the
6927 visibility was not specified, or because it was explicitly overridden
6928 from the containing scope. */
9c40570a 6929
f8e93a2e 6930 return NULL_TREE;
6931}
6932
3aa0c315 6933/* Determine the ELF symbol visibility for DECL, which is either a
6934 variable or a function. It is an error to use this function if a
6935 definition of DECL is not available in this translation unit.
6936 Returns true if the final visibility has been determined by this
6937 function; false if the caller is free to make additional
6938 modifications. */
6939
6940bool
6941c_determine_visibility (tree decl)
6942{
1d8fc210 6943 gcc_assert (TREE_CODE (decl) == VAR_DECL
6944 || TREE_CODE (decl) == FUNCTION_DECL);
3aa0c315 6945
6946 /* If the user explicitly specified the visibility with an
6947 attribute, honor that. DECL_VISIBILITY will have been set during
6948 the processing of the attribute. We check for an explicit
6949 attribute, rather than just checking DECL_VISIBILITY_SPECIFIED,
6950 to distinguish the use of an attribute from the use of a "#pragma
6951 GCC visibility push(...)"; in the latter case we still want other
6952 considerations to be able to overrule the #pragma. */
098a01e7 6953 if (lookup_attribute ("visibility", DECL_ATTRIBUTES (decl))
6954 || (TARGET_DLLIMPORT_DECL_ATTRIBUTES
6955 && (lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl))
6956 || lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl)))))
3aa0c315 6957 return true;
6958
4a2849cb 6959 /* Set default visibility to whatever the user supplied with
6960 visibility_specified depending on #pragma GCC visibility. */
6961 if (!DECL_VISIBILITY_SPECIFIED (decl))
6962 {
2d9d8740 6963 if (visibility_options.inpragma
6964 || DECL_VISIBILITY (decl) != default_visibility)
6965 {
6966 DECL_VISIBILITY (decl) = default_visibility;
6967 DECL_VISIBILITY_SPECIFIED (decl) = visibility_options.inpragma;
6968 /* If visibility changed and DECL already has DECL_RTL, ensure
6969 symbol flags are updated. */
6970 if (((TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
6971 || TREE_CODE (decl) == FUNCTION_DECL)
6972 && DECL_RTL_SET_P (decl))
6973 make_decl_rtl (decl);
6974 }
4a2849cb 6975 }
3aa0c315 6976 return false;
6977}
6978
24dfead4 6979/* Handle an "tls_model" attribute; arguments as in
6980 struct attribute_spec.handler. */
6981
6982static tree
1cae46be 6983handle_tls_model_attribute (tree *node, tree name, tree args,
9a03a746 6984 int ARG_UNUSED (flags), bool *no_add_attrs)
24dfead4 6985{
1b53eb20 6986 tree id;
24dfead4 6987 tree decl = *node;
1b53eb20 6988 enum tls_model kind;
24dfead4 6989
1b53eb20 6990 *no_add_attrs = true;
6991
c34f8a78 6992 if (TREE_CODE (decl) != VAR_DECL || !DECL_THREAD_LOCAL_P (decl))
24dfead4 6993 {
9b2d6d13 6994 warning (OPT_Wattributes, "%qE attribute ignored", name);
1b53eb20 6995 return NULL_TREE;
24dfead4 6996 }
24dfead4 6997
1b53eb20 6998 kind = DECL_TLS_MODEL (decl);
6999 id = TREE_VALUE (args);
7000 if (TREE_CODE (id) != STRING_CST)
7001 {
7002 error ("tls_model argument not a string");
7003 return NULL_TREE;
24dfead4 7004 }
7005
1b53eb20 7006 if (!strcmp (TREE_STRING_POINTER (id), "local-exec"))
7007 kind = TLS_MODEL_LOCAL_EXEC;
7008 else if (!strcmp (TREE_STRING_POINTER (id), "initial-exec"))
7009 kind = TLS_MODEL_INITIAL_EXEC;
7010 else if (!strcmp (TREE_STRING_POINTER (id), "local-dynamic"))
7011 kind = optimize ? TLS_MODEL_LOCAL_DYNAMIC : TLS_MODEL_GLOBAL_DYNAMIC;
7012 else if (!strcmp (TREE_STRING_POINTER (id), "global-dynamic"))
7013 kind = TLS_MODEL_GLOBAL_DYNAMIC;
7014 else
7015 error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
7016
7017 DECL_TLS_MODEL (decl) = kind;
24dfead4 7018 return NULL_TREE;
7019}
7020
f8e93a2e 7021/* Handle a "no_instrument_function" attribute; arguments as in
7022 struct attribute_spec.handler. */
7023
7024static tree
1cae46be 7025handle_no_instrument_function_attribute (tree *node, tree name,
9a03a746 7026 tree ARG_UNUSED (args),
7027 int ARG_UNUSED (flags),
09347743 7028 bool *no_add_attrs)
f8e93a2e 7029{
7030 tree decl = *node;
7031
7032 if (TREE_CODE (decl) != FUNCTION_DECL)
7033 {
712d2297 7034 error_at (DECL_SOURCE_LOCATION (decl),
7035 "%qE attribute applies only to functions", name);
f8e93a2e 7036 *no_add_attrs = true;
7037 }
7038 else if (DECL_INITIAL (decl))
7039 {
712d2297 7040 error_at (DECL_SOURCE_LOCATION (decl),
7041 "can%'t set %qE attribute after definition", name);
f8e93a2e 7042 *no_add_attrs = true;
7043 }
7044 else
7045 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl) = 1;
7046
7047 return NULL_TREE;
7048}
7049
7050/* Handle a "malloc" attribute; arguments as in
7051 struct attribute_spec.handler. */
7052
7053static tree
9a03a746 7054handle_malloc_attribute (tree *node, tree name, tree ARG_UNUSED (args),
7055 int ARG_UNUSED (flags), bool *no_add_attrs)
f8e93a2e 7056{
a5147fca 7057 if (TREE_CODE (*node) == FUNCTION_DECL
7058 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node))))
f8e93a2e 7059 DECL_IS_MALLOC (*node) = 1;
f8e93a2e 7060 else
7061 {
9b2d6d13 7062 warning (OPT_Wattributes, "%qE attribute ignored", name);
f8e93a2e 7063 *no_add_attrs = true;
7064 }
7065
7066 return NULL_TREE;
7067}
7068
4a29c97c 7069/* Handle a "alloc_size" attribute; arguments as in
7070 struct attribute_spec.handler. */
7071
7072static tree
7073handle_alloc_size_attribute (tree *node, tree ARG_UNUSED (name), tree args,
7074 int ARG_UNUSED (flags), bool *no_add_attrs)
7075{
2802826e 7076 unsigned arg_count = type_num_arguments (*node);
4a29c97c 7077 for (; args; args = TREE_CHAIN (args))
7078 {
7079 tree position = TREE_VALUE (args);
7080
7081 if (TREE_CODE (position) != INTEGER_CST
48e1416a 7082 || TREE_INT_CST_HIGH (position)
4a29c97c 7083 || TREE_INT_CST_LOW (position) < 1
7084 || TREE_INT_CST_LOW (position) > arg_count )
7085 {
48e1416a 7086 warning (OPT_Wattributes,
4a29c97c 7087 "alloc_size parameter outside range");
7088 *no_add_attrs = true;
7089 return NULL_TREE;
7090 }
7091 }
7092 return NULL_TREE;
7093}
7094
8ce86007 7095/* Handle a "fn spec" attribute; arguments as in
7096 struct attribute_spec.handler. */
7097
7098static tree
7099handle_fnspec_attribute (tree *node ATTRIBUTE_UNUSED, tree ARG_UNUSED (name),
7100 tree args, int ARG_UNUSED (flags),
7101 bool *no_add_attrs ATTRIBUTE_UNUSED)
7102{
7103 gcc_assert (args
7104 && TREE_CODE (TREE_VALUE (args)) == STRING_CST
7105 && !TREE_CHAIN (args));
7106 return NULL_TREE;
7107}
7108
26d1c5ff 7109/* Handle a "returns_twice" attribute; arguments as in
7110 struct attribute_spec.handler. */
7111
7112static tree
7113handle_returns_twice_attribute (tree *node, tree name, tree ARG_UNUSED (args),
7114 int ARG_UNUSED (flags), bool *no_add_attrs)
7115{
7116 if (TREE_CODE (*node) == FUNCTION_DECL)
7117 DECL_IS_RETURNS_TWICE (*node) = 1;
7118 else
7119 {
9b2d6d13 7120 warning (OPT_Wattributes, "%qE attribute ignored", name);
26d1c5ff 7121 *no_add_attrs = true;
7122 }
7123
7124 return NULL_TREE;
7125}
7126
f8e93a2e 7127/* Handle a "no_limit_stack" attribute; arguments as in
7128 struct attribute_spec.handler. */
7129
7130static tree
1cae46be 7131handle_no_limit_stack_attribute (tree *node, tree name,
9a03a746 7132 tree ARG_UNUSED (args),
7133 int ARG_UNUSED (flags),
09347743 7134 bool *no_add_attrs)
f8e93a2e 7135{
7136 tree decl = *node;
7137
7138 if (TREE_CODE (decl) != FUNCTION_DECL)
7139 {
712d2297 7140 error_at (DECL_SOURCE_LOCATION (decl),
7141 "%qE attribute applies only to functions", name);
f8e93a2e 7142 *no_add_attrs = true;
7143 }
7144 else if (DECL_INITIAL (decl))
7145 {
712d2297 7146 error_at (DECL_SOURCE_LOCATION (decl),
7147 "can%'t set %qE attribute after definition", name);
f8e93a2e 7148 *no_add_attrs = true;
7149 }
7150 else
7151 DECL_NO_LIMIT_STACK (decl) = 1;
7152
7153 return NULL_TREE;
7154}
7155
7156/* Handle a "pure" attribute; arguments as in
7157 struct attribute_spec.handler. */
7158
7159static tree
9a03a746 7160handle_pure_attribute (tree *node, tree name, tree ARG_UNUSED (args),
7161 int ARG_UNUSED (flags), bool *no_add_attrs)
f8e93a2e 7162{
7163 if (TREE_CODE (*node) == FUNCTION_DECL)
9c2a0c05 7164 DECL_PURE_P (*node) = 1;
f8e93a2e 7165 /* ??? TODO: Support types. */
7166 else
7167 {
9b2d6d13 7168 warning (OPT_Wattributes, "%qE attribute ignored", name);
f8e93a2e 7169 *no_add_attrs = true;
7170 }
7171
7172 return NULL_TREE;
7173}
7174
fc09b200 7175/* Handle a "no vops" attribute; arguments as in
7176 struct attribute_spec.handler. */
7177
7178static tree
7179handle_novops_attribute (tree *node, tree ARG_UNUSED (name),
7180 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
7181 bool *ARG_UNUSED (no_add_attrs))
7182{
7183 gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
7184 DECL_IS_NOVOPS (*node) = 1;
7185 return NULL_TREE;
7186}
7187
f8e93a2e 7188/* Handle a "deprecated" attribute; arguments as in
7189 struct attribute_spec.handler. */
1cae46be 7190
f8e93a2e 7191static tree
1cae46be 7192handle_deprecated_attribute (tree *node, tree name,
45c4e798 7193 tree args, int flags,
09347743 7194 bool *no_add_attrs)
f8e93a2e 7195{
7196 tree type = NULL_TREE;
7197 int warn = 0;
782858b8 7198 tree what = NULL_TREE;
1cae46be 7199
45c4e798 7200 if (!args)
7201 *no_add_attrs = true;
7202 else if (TREE_CODE (TREE_VALUE (args)) != STRING_CST)
7203 {
7204 error ("deprecated message is not a string");
7205 *no_add_attrs = true;
7206 }
7207
f8e93a2e 7208 if (DECL_P (*node))
7209 {
7210 tree decl = *node;
7211 type = TREE_TYPE (decl);
1cae46be 7212
f8e93a2e 7213 if (TREE_CODE (decl) == TYPE_DECL
7214 || TREE_CODE (decl) == PARM_DECL
7215 || TREE_CODE (decl) == VAR_DECL
7216 || TREE_CODE (decl) == FUNCTION_DECL
40c8d1dd 7217 || TREE_CODE (decl) == FIELD_DECL
7218 || objc_method_decl (TREE_CODE (decl)))
f8e93a2e 7219 TREE_DEPRECATED (decl) = 1;
7220 else
7221 warn = 1;
7222 }
7223 else if (TYPE_P (*node))
7224 {
7225 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
e086912e 7226 *node = build_variant_type_copy (*node);
f8e93a2e 7227 TREE_DEPRECATED (*node) = 1;
7228 type = *node;
7229 }
7230 else
7231 warn = 1;
1cae46be 7232
f8e93a2e 7233 if (warn)
7234 {
7235 *no_add_attrs = true;
7236 if (type && TYPE_NAME (type))
7237 {
7238 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
782858b8 7239 what = TYPE_NAME (*node);
f8e93a2e 7240 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7241 && DECL_NAME (TYPE_NAME (type)))
782858b8 7242 what = DECL_NAME (TYPE_NAME (type));
f8e93a2e 7243 }
7244 if (what)
9b2d6d13 7245 warning (OPT_Wattributes, "%qE attribute ignored for %qE", name, what);
f8e93a2e 7246 else
9b2d6d13 7247 warning (OPT_Wattributes, "%qE attribute ignored", name);
f8e93a2e 7248 }
7249
7250 return NULL_TREE;
7251}
7252
f8e93a2e 7253/* Handle a "vector_size" attribute; arguments as in
7254 struct attribute_spec.handler. */
7255
7256static tree
1cae46be 7257handle_vector_size_attribute (tree *node, tree name, tree args,
9a03a746 7258 int ARG_UNUSED (flags),
09347743 7259 bool *no_add_attrs)
f8e93a2e 7260{
7261 unsigned HOST_WIDE_INT vecsize, nunits;
83e2a11b 7262 enum machine_mode orig_mode;
4917c376 7263 tree type = *node, new_type, size;
f8e93a2e 7264
7265 *no_add_attrs = true;
7266
4917c376 7267 size = TREE_VALUE (args);
4917c376 7268
84166705 7269 if (!host_integerp (size, 1))
f8e93a2e 7270 {
9b2d6d13 7271 warning (OPT_Wattributes, "%qE attribute ignored", name);
f8e93a2e 7272 return NULL_TREE;
7273 }
7274
7275 /* Get the vector size (in bytes). */
4917c376 7276 vecsize = tree_low_cst (size, 1);
f8e93a2e 7277
7278 /* We need to provide for vector pointers, vector arrays, and
7279 functions returning vectors. For example:
7280
7281 __attribute__((vector_size(16))) short *foo;
7282
7283 In this case, the mode is SI, but the type being modified is
7284 HI, so we need to look further. */
7285
7286 while (POINTER_TYPE_P (type)
7287 || TREE_CODE (type) == FUNCTION_TYPE
5bfb0742 7288 || TREE_CODE (type) == METHOD_TYPE
2cb0e5d9 7289 || TREE_CODE (type) == ARRAY_TYPE
7290 || TREE_CODE (type) == OFFSET_TYPE)
f8e93a2e 7291 type = TREE_TYPE (type);
7292
7293 /* Get the mode of the type being modified. */
7294 orig_mode = TYPE_MODE (type);
7295
2cb0e5d9 7296 if ((!INTEGRAL_TYPE_P (type)
7297 && !SCALAR_FLOAT_TYPE_P (type)
7298 && !FIXED_POINT_TYPE_P (type))
cee7491d 7299 || (!SCALAR_FLOAT_MODE_P (orig_mode)
9421ebb9 7300 && GET_MODE_CLASS (orig_mode) != MODE_INT
7301 && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode))
7ec31215 7302 || !host_integerp (TYPE_SIZE_UNIT (type), 1)
7303 || TREE_CODE (type) == BOOLEAN_TYPE)
f8e93a2e 7304 {
782858b8 7305 error ("invalid vector type for attribute %qE", name);
f8e93a2e 7306 return NULL_TREE;
7307 }
7308
39cc3e6d 7309 if (vecsize % tree_low_cst (TYPE_SIZE_UNIT (type), 1))
7310 {
7311 error ("vector size not an integral multiple of component size");
7312 return NULL;
7313 }
7314
7315 if (vecsize == 0)
7316 {
7317 error ("zero vector size");
7318 return NULL;
7319 }
7320
f8e93a2e 7321 /* Calculate how many units fit in the vector. */
7322 nunits = vecsize / tree_low_cst (TYPE_SIZE_UNIT (type), 1);
83e2a11b 7323 if (nunits & (nunits - 1))
f8e93a2e 7324 {
83e2a11b 7325 error ("number of components of the vector not a power of two");
f8e93a2e 7326 return NULL_TREE;
7327 }
7328
83e2a11b 7329 new_type = build_vector_type (type, nunits);
f8e93a2e 7330
7331 /* Build back pointers if needed. */
d991e6e8 7332 *node = lang_hooks.types.reconstruct_complex_type (*node, new_type);
f8e93a2e 7333
7334 return NULL_TREE;
7335}
7336
dbf6c367 7337/* Handle the "nonnull" attribute. */
7338static tree
9a03a746 7339handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name),
7340 tree args, int ARG_UNUSED (flags),
09347743 7341 bool *no_add_attrs)
dbf6c367 7342{
7343 tree type = *node;
7344 unsigned HOST_WIDE_INT attr_arg_num;
7345
7346 /* If no arguments are specified, all pointer arguments should be
d716ce75 7347 non-null. Verify a full prototype is given so that the arguments
dbf6c367 7348 will have the correct types when we actually check them later. */
84166705 7349 if (!args)
dbf6c367 7350 {
a36cf284 7351 if (!prototype_p (type))
dbf6c367 7352 {
7353 error ("nonnull attribute without arguments on a non-prototype");
4ee9c684 7354 *no_add_attrs = true;
dbf6c367 7355 }
7356 return NULL_TREE;
7357 }
7358
7359 /* Argument list specified. Verify that each argument number references
7360 a pointer argument. */
7361 for (attr_arg_num = 1; args; args = TREE_CHAIN (args))
7362 {
7363 tree argument;
4ee9c684 7364 unsigned HOST_WIDE_INT arg_num = 0, ck_num;
dbf6c367 7365
84166705 7366 if (!get_nonnull_operand (TREE_VALUE (args), &arg_num))
dbf6c367 7367 {
07e3a3d2 7368 error ("nonnull argument has invalid operand number (argument %lu)",
dbf6c367 7369 (unsigned long) attr_arg_num);
7370 *no_add_attrs = true;
7371 return NULL_TREE;
7372 }
7373
7374 argument = TYPE_ARG_TYPES (type);
7375 if (argument)
7376 {
7377 for (ck_num = 1; ; ck_num++)
7378 {
84166705 7379 if (!argument || ck_num == arg_num)
dbf6c367 7380 break;
7381 argument = TREE_CHAIN (argument);
7382 }
7383
84166705 7384 if (!argument
dbf6c367 7385 || TREE_CODE (TREE_VALUE (argument)) == VOID_TYPE)
7386 {
07e3a3d2 7387 error ("nonnull argument with out-of-range operand number (argument %lu, operand %lu)",
dbf6c367 7388 (unsigned long) attr_arg_num, (unsigned long) arg_num);
7389 *no_add_attrs = true;
7390 return NULL_TREE;
7391 }
7392
4ee9c684 7393 if (TREE_CODE (TREE_VALUE (argument)) != POINTER_TYPE)
dbf6c367 7394 {
07e3a3d2 7395 error ("nonnull argument references non-pointer operand (argument %lu, operand %lu)",
dbf6c367 7396 (unsigned long) attr_arg_num, (unsigned long) arg_num);
7397 *no_add_attrs = true;
7398 return NULL_TREE;
7399 }
7400 }
7401 }
7402
7403 return NULL_TREE;
7404}
7405
7406/* Check the argument list of a function call for null in argument slots
d01f58f9 7407 that are marked as requiring a non-null pointer argument. The NARGS
7408 arguments are passed in the array ARGARRAY.
7409*/
dbf6c367 7410
7411static void
d01f58f9 7412check_function_nonnull (tree attrs, int nargs, tree *argarray)
dbf6c367 7413{
d01f58f9 7414 tree a, args;
7415 int i;
dbf6c367 7416
7417 for (a = attrs; a; a = TREE_CHAIN (a))
7418 {
7419 if (is_attribute_p ("nonnull", TREE_PURPOSE (a)))
7420 {
4ee9c684 7421 args = TREE_VALUE (a);
dbf6c367 7422
4ee9c684 7423 /* Walk the argument list. If we encounter an argument number we
7424 should check for non-null, do it. If the attribute has no args,
7425 then every pointer argument is checked (in which case the check
dbf6c367 7426 for pointer type is done in check_nonnull_arg). */
d01f58f9 7427 for (i = 0; i < nargs; i++)
4ee9c684 7428 {
d01f58f9 7429 if (!args || nonnull_check_p (args, i + 1))
e4603171 7430 check_function_arguments_recurse (check_nonnull_arg, NULL,
d01f58f9 7431 argarray[i],
7432 i + 1);
4ee9c684 7433 }
dbf6c367 7434 }
7435 }
7436}
7437
50ca527f 7438/* Check that the Nth argument of a function call (counting backwards
d01f58f9 7439 from the end) is a (pointer)0. The NARGS arguments are passed in the
7440 array ARGARRAY. */
bf6c8de0 7441
7442static void
d01f58f9 7443check_function_sentinel (tree attrs, int nargs, tree *argarray, tree typelist)
bf6c8de0 7444{
7445 tree attr = lookup_attribute ("sentinel", attrs);
7446
7447 if (attr)
7448 {
d01f58f9 7449 int len = 0;
7450 int pos = 0;
7451 tree sentinel;
a0c938f0 7452
d01f58f9 7453 /* Skip over the named arguments. */
7454 while (typelist && len < nargs)
a0c938f0 7455 {
d01f58f9 7456 typelist = TREE_CHAIN (typelist);
7457 len++;
7458 }
50ca527f 7459
d01f58f9 7460 if (TREE_VALUE (attr))
7461 {
7462 tree p = TREE_VALUE (TREE_VALUE (attr));
7463 pos = TREE_INT_CST_LOW (p);
7464 }
50ca527f 7465
d01f58f9 7466 /* The sentinel must be one of the varargs, i.e.
7467 in position >= the number of fixed arguments. */
7468 if ((nargs - 1 - pos) < len)
7469 {
7470 warning (OPT_Wformat,
7471 "not enough variable arguments to fit a sentinel");
7472 return;
bf6c8de0 7473 }
d01f58f9 7474
7475 /* Validate the sentinel. */
7476 sentinel = argarray[nargs - 1 - pos];
7477 if ((!POINTER_TYPE_P (TREE_TYPE (sentinel))
7478 || !integer_zerop (sentinel))
7479 /* Although __null (in C++) is only an integer we allow it
7480 nevertheless, as we are guaranteed that it's exactly
7481 as wide as a pointer, and we don't want to force
7482 users to cast the NULL they have written there.
7483 We warn with -Wstrict-null-sentinel, though. */
7484 && (warn_strict_null_sentinel || null_node != sentinel))
7485 warning (OPT_Wformat, "missing sentinel in function call");
bf6c8de0 7486 }
7487}
7488
dbf6c367 7489/* Helper for check_function_nonnull; given a list of operands which
7490 must be non-null in ARGS, determine if operand PARAM_NUM should be
7491 checked. */
7492
7493static bool
1cae46be 7494nonnull_check_p (tree args, unsigned HOST_WIDE_INT param_num)
dbf6c367 7495{
4ee9c684 7496 unsigned HOST_WIDE_INT arg_num = 0;
dbf6c367 7497
7498 for (; args; args = TREE_CHAIN (args))
7499 {
231bd014 7500 bool found = get_nonnull_operand (TREE_VALUE (args), &arg_num);
7501
7502 gcc_assert (found);
dbf6c367 7503
7504 if (arg_num == param_num)
7505 return true;
7506 }
7507 return false;
7508}
7509
7510/* Check that the function argument PARAM (which is operand number
7511 PARAM_NUM) is non-null. This is called by check_function_nonnull
7512 via check_function_arguments_recurse. */
7513
7514static void
9a03a746 7515check_nonnull_arg (void * ARG_UNUSED (ctx), tree param,
1cae46be 7516 unsigned HOST_WIDE_INT param_num)
dbf6c367 7517{
7518 /* Just skip checking the argument if it's not a pointer. This can
7519 happen if the "nonnull" attribute was given without an operand
7520 list (which means to check every pointer argument). */
7521
7522 if (TREE_CODE (TREE_TYPE (param)) != POINTER_TYPE)
7523 return;
7524
7525 if (integer_zerop (param))
155b601b 7526 warning (OPT_Wnonnull, "null argument where non-null required "
7527 "(argument %lu)", (unsigned long) param_num);
dbf6c367 7528}
7529
7530/* Helper for nonnull attribute handling; fetch the operand number
7531 from the attribute argument list. */
7532
7533static bool
1cae46be 7534get_nonnull_operand (tree arg_num_expr, unsigned HOST_WIDE_INT *valp)
dbf6c367 7535{
67409385 7536 /* Verify the arg number is a constant. */
dbf6c367 7537 if (TREE_CODE (arg_num_expr) != INTEGER_CST
7538 || TREE_INT_CST_HIGH (arg_num_expr) != 0)
7539 return false;
7540
7541 *valp = TREE_INT_CST_LOW (arg_num_expr);
7542 return true;
7543}
fa987697 7544
7545/* Handle a "nothrow" attribute; arguments as in
7546 struct attribute_spec.handler. */
7547
7548static tree
9a03a746 7549handle_nothrow_attribute (tree *node, tree name, tree ARG_UNUSED (args),
7550 int ARG_UNUSED (flags), bool *no_add_attrs)
fa987697 7551{
7552 if (TREE_CODE (*node) == FUNCTION_DECL)
7553 TREE_NOTHROW (*node) = 1;
7554 /* ??? TODO: Support types. */
7555 else
7556 {
9b2d6d13 7557 warning (OPT_Wattributes, "%qE attribute ignored", name);
fa987697 7558 *no_add_attrs = true;
7559 }
7560
7561 return NULL_TREE;
7562}
7acb29a3 7563
7564/* Handle a "cleanup" attribute; arguments as in
7565 struct attribute_spec.handler. */
7566
7567static tree
1cae46be 7568handle_cleanup_attribute (tree *node, tree name, tree args,
9a03a746 7569 int ARG_UNUSED (flags), bool *no_add_attrs)
7acb29a3 7570{
7571 tree decl = *node;
7572 tree cleanup_id, cleanup_decl;
7573
7574 /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
7575 for global destructors in C++. This requires infrastructure that
7576 we don't have generically at the moment. It's also not a feature
7577 we'd be missing too much, since we do have attribute constructor. */
7578 if (TREE_CODE (decl) != VAR_DECL || TREE_STATIC (decl))
7579 {
9b2d6d13 7580 warning (OPT_Wattributes, "%qE attribute ignored", name);
7acb29a3 7581 *no_add_attrs = true;
7582 return NULL_TREE;
7583 }
7584
7585 /* Verify that the argument is a function in scope. */
7586 /* ??? We could support pointers to functions here as well, if
7587 that was considered desirable. */
7588 cleanup_id = TREE_VALUE (args);
7589 if (TREE_CODE (cleanup_id) != IDENTIFIER_NODE)
7590 {
07e3a3d2 7591 error ("cleanup argument not an identifier");
7acb29a3 7592 *no_add_attrs = true;
7593 return NULL_TREE;
7594 }
d1c41717 7595 cleanup_decl = lookup_name (cleanup_id);
7acb29a3 7596 if (!cleanup_decl || TREE_CODE (cleanup_decl) != FUNCTION_DECL)
7597 {
07e3a3d2 7598 error ("cleanup argument not a function");
7acb29a3 7599 *no_add_attrs = true;
7600 return NULL_TREE;
7601 }
7602
1cae46be 7603 /* That the function has proper type is checked with the
7acb29a3 7604 eventual call to build_function_call. */
7605
7606 return NULL_TREE;
7607}
8a8cdb8d 7608
7609/* Handle a "warn_unused_result" attribute. No special handling. */
7610
7611static tree
7612handle_warn_unused_result_attribute (tree *node, tree name,
9a03a746 7613 tree ARG_UNUSED (args),
7614 int ARG_UNUSED (flags), bool *no_add_attrs)
8a8cdb8d 7615{
7616 /* Ignore the attribute for functions not returning any value. */
7617 if (VOID_TYPE_P (TREE_TYPE (*node)))
7618 {
9b2d6d13 7619 warning (OPT_Wattributes, "%qE attribute ignored", name);
8a8cdb8d 7620 *no_add_attrs = true;
7621 }
7622
7623 return NULL_TREE;
7624}
bf6c8de0 7625
7626/* Handle a "sentinel" attribute. */
7627
7628static tree
50ca527f 7629handle_sentinel_attribute (tree *node, tree name, tree args,
bf6c8de0 7630 int ARG_UNUSED (flags), bool *no_add_attrs)
7631{
7632 tree params = TYPE_ARG_TYPES (*node);
7633
a36cf284 7634 if (!prototype_p (*node))
bf6c8de0 7635 {
9b2d6d13 7636 warning (OPT_Wattributes,
7637 "%qE attribute requires prototypes with named arguments", name);
bf6c8de0 7638 *no_add_attrs = true;
bf6c8de0 7639 }
50ca527f 7640 else
7641 {
7642 while (TREE_CHAIN (params))
7643 params = TREE_CHAIN (params);
bf6c8de0 7644
50ca527f 7645 if (VOID_TYPE_P (TREE_VALUE (params)))
a0c938f0 7646 {
9b2d6d13 7647 warning (OPT_Wattributes,
7648 "%qE attribute only applies to variadic functions", name);
50ca527f 7649 *no_add_attrs = true;
7650 }
7651 }
a0c938f0 7652
50ca527f 7653 if (args)
bf6c8de0 7654 {
50ca527f 7655 tree position = TREE_VALUE (args);
7656
50ca527f 7657 if (TREE_CODE (position) != INTEGER_CST)
a0c938f0 7658 {
48e1416a 7659 warning (OPT_Wattributes,
01b54db5 7660 "requested position is not an integer constant");
50ca527f 7661 *no_add_attrs = true;
7662 }
7663 else
a0c938f0 7664 {
50ca527f 7665 if (tree_int_cst_lt (position, integer_zero_node))
7666 {
01b54db5 7667 warning (OPT_Wattributes,
7668 "requested position is less than zero");
50ca527f 7669 *no_add_attrs = true;
7670 }
7671 }
bf6c8de0 7672 }
a0c938f0 7673
bf6c8de0 7674 return NULL_TREE;
7675}
b5c26b42 7676
7677/* Handle a "type_generic" attribute. */
7678
7679static tree
7680handle_type_generic_attribute (tree *node, tree ARG_UNUSED (name),
7681 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
7682 bool * ARG_UNUSED (no_add_attrs))
7683{
19fbe3a4 7684 tree params;
48e1416a 7685
19fbe3a4 7686 /* Ensure we have a function type. */
7687 gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE);
48e1416a 7688
19fbe3a4 7689 params = TYPE_ARG_TYPES (*node);
7690 while (params && ! VOID_TYPE_P (TREE_VALUE (params)))
7691 params = TREE_CHAIN (params);
7692
7693 /* Ensure we have a variadic function. */
7694 gcc_assert (!params);
b5c26b42 7695
7696 return NULL_TREE;
7697}
46f8e3b0 7698
24470055 7699/* Handle a "target" attribute. */
46f8e3b0 7700
7701static tree
24470055 7702handle_target_attribute (tree *node, tree name, tree args, int flags,
46f8e3b0 7703 bool *no_add_attrs)
7704{
7705 /* Ensure we have a function type. */
7706 if (TREE_CODE (*node) != FUNCTION_DECL)
7707 {
7708 warning (OPT_Wattributes, "%qE attribute ignored", name);
7709 *no_add_attrs = true;
7710 }
46f8e3b0 7711 else if (! targetm.target_option.valid_attribute_p (*node, name, args,
7712 flags))
7713 *no_add_attrs = true;
7714
7715 return NULL_TREE;
7716}
7717
7718/* Arguments being collected for optimization. */
7719typedef const char *const_char_p; /* For DEF_VEC_P. */
7720DEF_VEC_P(const_char_p);
7721DEF_VEC_ALLOC_P(const_char_p, gc);
7722static GTY(()) VEC(const_char_p, gc) *optimize_args;
7723
7724
7725/* Inner function to convert a TREE_LIST to argv string to parse the optimize
7726 options in ARGS. ATTR_P is true if this is for attribute(optimize), and
7727 false for #pragma GCC optimize. */
7728
7729bool
7730parse_optimize_options (tree args, bool attr_p)
7731{
7732 bool ret = true;
7733 unsigned opt_argc;
7734 unsigned i;
2becf397 7735 int saved_flag_strict_aliasing;
46f8e3b0 7736 const char **opt_argv;
615ef0bb 7737 struct cl_decoded_option *decoded_options;
7738 unsigned int decoded_options_count;
46f8e3b0 7739 tree ap;
7740
7741 /* Build up argv vector. Just in case the string is stored away, use garbage
7742 collected strings. */
7743 VEC_truncate (const_char_p, optimize_args, 0);
7744 VEC_safe_push (const_char_p, gc, optimize_args, NULL);
7745
7746 for (ap = args; ap != NULL_TREE; ap = TREE_CHAIN (ap))
7747 {
7748 tree value = TREE_VALUE (ap);
7749
7750 if (TREE_CODE (value) == INTEGER_CST)
7751 {
7752 char buffer[20];
7753 sprintf (buffer, "-O%ld", (long) TREE_INT_CST_LOW (value));
7754 VEC_safe_push (const_char_p, gc, optimize_args, ggc_strdup (buffer));
7755 }
7756
7757 else if (TREE_CODE (value) == STRING_CST)
7758 {
7759 /* Split string into multiple substrings. */
7760 size_t len = TREE_STRING_LENGTH (value);
7761 char *p = ASTRDUP (TREE_STRING_POINTER (value));
7762 char *end = p + len;
7763 char *comma;
7764 char *next_p = p;
7765
7766 while (next_p != NULL)
7767 {
7768 size_t len2;
7769 char *q, *r;
7770
7771 p = next_p;
7772 comma = strchr (p, ',');
7773 if (comma)
7774 {
7775 len2 = comma - p;
7776 *comma = '\0';
7777 next_p = comma+1;
7778 }
7779 else
7780 {
7781 len2 = end - p;
7782 next_p = NULL;
7783 }
7784
ba72912a 7785 r = q = (char *) ggc_alloc_atomic (len2 + 3);
46f8e3b0 7786
7787 /* If the user supplied -Oxxx or -fxxx, only allow -Oxxx or -fxxx
7788 options. */
7789 if (*p == '-' && p[1] != 'O' && p[1] != 'f')
7790 {
7791 ret = false;
7792 if (attr_p)
7793 warning (OPT_Wattributes,
ebd7c4c1 7794 "bad option %s to optimize attribute", p);
46f8e3b0 7795 else
7796 warning (OPT_Wpragmas,
e44b0a1f 7797 "bad option %s to pragma attribute", p);
46f8e3b0 7798 continue;
7799 }
7800
7801 if (*p != '-')
7802 {
7803 *r++ = '-';
7804
7805 /* Assume that Ox is -Ox, a numeric value is -Ox, a s by
7806 itself is -Os, and any other switch begins with a -f. */
7807 if ((*p >= '0' && *p <= '9')
7808 || (p[0] == 's' && p[1] == '\0'))
7809 *r++ = 'O';
7810 else if (*p != 'O')
7811 *r++ = 'f';
7812 }
7813
7814 memcpy (r, p, len2);
7815 r[len2] = '\0';
7816 VEC_safe_push (const_char_p, gc, optimize_args, q);
7817 }
7818
7819 }
7820 }
7821
7822 opt_argc = VEC_length (const_char_p, optimize_args);
7823 opt_argv = (const char **) alloca (sizeof (char *) * (opt_argc + 1));
7824
7825 for (i = 1; i < opt_argc; i++)
7826 opt_argv[i] = VEC_index (const_char_p, optimize_args, i);
7827
2becf397 7828 saved_flag_strict_aliasing = flag_strict_aliasing;
7829
46f8e3b0 7830 /* Now parse the options. */
f3f006ad 7831 decode_cmdline_options_to_array_default_mask (opt_argc, opt_argv,
7832 &decoded_options,
7833 &decoded_options_count);
7834 decode_options (&global_options, &global_options_set,
3c6c0e40 7835 decoded_options, decoded_options_count,
7836 input_location, global_dc);
46f8e3b0 7837
4bec06b3 7838 targetm.override_options_after_change();
7839
2becf397 7840 /* Don't allow changing -fstrict-aliasing. */
7841 flag_strict_aliasing = saved_flag_strict_aliasing;
7842
46f8e3b0 7843 VEC_truncate (const_char_p, optimize_args, 0);
7844 return ret;
7845}
7846
7847/* For handling "optimize" attribute. arguments as in
7848 struct attribute_spec.handler. */
7849
7850static tree
7851handle_optimize_attribute (tree *node, tree name, tree args,
7852 int ARG_UNUSED (flags), bool *no_add_attrs)
7853{
7854 /* Ensure we have a function type. */
7855 if (TREE_CODE (*node) != FUNCTION_DECL)
7856 {
7857 warning (OPT_Wattributes, "%qE attribute ignored", name);
7858 *no_add_attrs = true;
7859 }
7860 else
7861 {
7862 struct cl_optimization cur_opts;
7863 tree old_opts = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node);
7864
7865 /* Save current options. */
2c5d2e39 7866 cl_optimization_save (&cur_opts, &global_options);
46f8e3b0 7867
7868 /* If we previously had some optimization options, use them as the
7869 default. */
7870 if (old_opts)
2c5d2e39 7871 cl_optimization_restore (&global_options,
7872 TREE_OPTIMIZATION (old_opts));
46f8e3b0 7873
7874 /* Parse options, and update the vector. */
7875 parse_optimize_options (args, true);
7876 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node)
7877 = build_optimization_node ();
7878
7879 /* Restore current options. */
2c5d2e39 7880 cl_optimization_restore (&global_options, &cur_opts);
46f8e3b0 7881 }
7882
7883 return NULL_TREE;
7884}
48b14f50 7885
7886/* Handle a "no_split_stack" attribute. */
7887
7888static tree
7889handle_no_split_stack_attribute (tree *node, tree name,
7890 tree ARG_UNUSED (args),
7891 int ARG_UNUSED (flags),
7892 bool *no_add_attrs)
7893{
7894 tree decl = *node;
7895
7896 if (TREE_CODE (decl) != FUNCTION_DECL)
7897 {
7898 error_at (DECL_SOURCE_LOCATION (decl),
7899 "%qE attribute applies only to functions", name);
7900 *no_add_attrs = true;
7901 }
7902 else if (DECL_INITIAL (decl))
7903 {
7904 error_at (DECL_SOURCE_LOCATION (decl),
7905 "can%'t set %qE attribute after definition", name);
7906 *no_add_attrs = true;
7907 }
7908
7909 return NULL_TREE;
7910}
dbf6c367 7911\f
d01f58f9 7912/* Check for valid arguments being passed to a function.
7913 ATTRS is a list of attributes. There are NARGS arguments in the array
7914 ARGARRAY. TYPELIST is the list of argument types for the function.
7915 */
dbf6c367 7916void
d01f58f9 7917check_function_arguments (tree attrs, int nargs, tree *argarray, tree typelist)
dbf6c367 7918{
7919 /* Check for null being passed in a pointer argument that must be
7920 non-null. We also need to do this if format checking is enabled. */
7921
7922 if (warn_nonnull)
d01f58f9 7923 check_function_nonnull (attrs, nargs, argarray);
dbf6c367 7924
7925 /* Check for errors in format strings. */
7926
95c90e04 7927 if (warn_format || warn_missing_format_attribute)
d01f58f9 7928 check_function_format (attrs, nargs, argarray);
95c90e04 7929
7930 if (warn_format)
d01f58f9 7931 check_function_sentinel (attrs, nargs, argarray, typelist);
dbf6c367 7932}
7933
7934/* Generic argument checking recursion routine. PARAM is the argument to
7935 be checked. PARAM_NUM is the number of the argument. CALLBACK is invoked
7936 once the argument is resolved. CTX is context for the callback. */
7937void
1cae46be 7938check_function_arguments_recurse (void (*callback)
7939 (void *, tree, unsigned HOST_WIDE_INT),
7940 void *ctx, tree param,
7941 unsigned HOST_WIDE_INT param_num)
dbf6c367 7942{
72dd6141 7943 if (CONVERT_EXPR_P (param)
c44afe23 7944 && (TYPE_PRECISION (TREE_TYPE (param))
7945 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (param, 0)))))
dbf6c367 7946 {
7947 /* Strip coercion. */
7948 check_function_arguments_recurse (callback, ctx,
4ee9c684 7949 TREE_OPERAND (param, 0), param_num);
dbf6c367 7950 return;
7951 }
7952
7953 if (TREE_CODE (param) == CALL_EXPR)
7954 {
c2f47e15 7955 tree type = TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (param)));
dbf6c367 7956 tree attrs;
7957 bool found_format_arg = false;
7958
7959 /* See if this is a call to a known internationalization function
7960 that modifies a format arg. Such a function may have multiple
7961 format_arg attributes (for example, ngettext). */
7962
7963 for (attrs = TYPE_ATTRIBUTES (type);
7964 attrs;
7965 attrs = TREE_CHAIN (attrs))
7966 if (is_attribute_p ("format_arg", TREE_PURPOSE (attrs)))
7967 {
c2f47e15 7968 tree inner_arg;
dbf6c367 7969 tree format_num_expr;
7970 int format_num;
7971 int i;
c2f47e15 7972 call_expr_arg_iterator iter;
dbf6c367 7973
7974 /* Extract the argument number, which was previously checked
7975 to be valid. */
7976 format_num_expr = TREE_VALUE (TREE_VALUE (attrs));
dbf6c367 7977
231bd014 7978 gcc_assert (TREE_CODE (format_num_expr) == INTEGER_CST
7979 && !TREE_INT_CST_HIGH (format_num_expr));
dbf6c367 7980
7981 format_num = TREE_INT_CST_LOW (format_num_expr);
7982
c2f47e15 7983 for (inner_arg = first_call_expr_arg (param, &iter), i = 1;
7984 inner_arg != 0;
7985 inner_arg = next_call_expr_arg (&iter), i++)
dbf6c367 7986 if (i == format_num)
7987 {
7988 check_function_arguments_recurse (callback, ctx,
c2f47e15 7989 inner_arg, param_num);
dbf6c367 7990 found_format_arg = true;
7991 break;
7992 }
7993 }
7994
7995 /* If we found a format_arg attribute and did a recursive check,
7996 we are done with checking this argument. Otherwise, we continue
7997 and this will be considered a non-literal. */
7998 if (found_format_arg)
7999 return;
8000 }
8001
8002 if (TREE_CODE (param) == COND_EXPR)
8003 {
8004 /* Check both halves of the conditional expression. */
8005 check_function_arguments_recurse (callback, ctx,
4ee9c684 8006 TREE_OPERAND (param, 1), param_num);
dbf6c367 8007 check_function_arguments_recurse (callback, ctx,
4ee9c684 8008 TREE_OPERAND (param, 2), param_num);
dbf6c367 8009 return;
8010 }
8011
8012 (*callback) (ctx, param, param_num);
8013}
1f3233d1 8014
60cce472 8015/* Checks for a builtin function FNDECL that the number of arguments
8016 NARGS against the required number REQUIRED and issues an error if
8017 there is a mismatch. Returns true if the number of arguments is
8018 correct, otherwise false. */
d43cee80 8019
8020static bool
60cce472 8021builtin_function_validate_nargs (tree fndecl, int nargs, int required)
d43cee80 8022{
8023 if (nargs < required)
8024 {
60cce472 8025 error_at (input_location,
8026 "not enough arguments to function %qE", fndecl);
d43cee80 8027 return false;
8028 }
8029 else if (nargs > required)
8030 {
60cce472 8031 error_at (input_location,
8032 "too many arguments to function %qE", fndecl);
d43cee80 8033 return false;
8034 }
8035 return true;
8036}
8037
8038/* Verifies the NARGS arguments ARGS to the builtin function FNDECL.
8039 Returns false if there was an error, otherwise true. */
8040
8041bool
8042check_builtin_function_arguments (tree fndecl, int nargs, tree *args)
8043{
8044 if (!DECL_BUILT_IN (fndecl)
8045 || DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_NORMAL)
8046 return true;
8047
8048 switch (DECL_FUNCTION_CODE (fndecl))
8049 {
8050 case BUILT_IN_CONSTANT_P:
60cce472 8051 return builtin_function_validate_nargs (fndecl, nargs, 1);
d43cee80 8052
8053 case BUILT_IN_ISFINITE:
8054 case BUILT_IN_ISINF:
c319d56a 8055 case BUILT_IN_ISINF_SIGN:
d43cee80 8056 case BUILT_IN_ISNAN:
8057 case BUILT_IN_ISNORMAL:
60cce472 8058 if (builtin_function_validate_nargs (fndecl, nargs, 1))
d43cee80 8059 {
8060 if (TREE_CODE (TREE_TYPE (args[0])) != REAL_TYPE)
8061 {
8062 error ("non-floating-point argument in call to "
8063 "function %qE", fndecl);
8064 return false;
8065 }
8066 return true;
8067 }
8068 return false;
8069
8070 case BUILT_IN_ISGREATER:
8071 case BUILT_IN_ISGREATEREQUAL:
8072 case BUILT_IN_ISLESS:
8073 case BUILT_IN_ISLESSEQUAL:
8074 case BUILT_IN_ISLESSGREATER:
8075 case BUILT_IN_ISUNORDERED:
60cce472 8076 if (builtin_function_validate_nargs (fndecl, nargs, 2))
d43cee80 8077 {
8078 enum tree_code code0, code1;
8079 code0 = TREE_CODE (TREE_TYPE (args[0]));
8080 code1 = TREE_CODE (TREE_TYPE (args[1]));
8081 if (!((code0 == REAL_TYPE && code1 == REAL_TYPE)
8082 || (code0 == REAL_TYPE && code1 == INTEGER_TYPE)
8083 || (code0 == INTEGER_TYPE && code1 == REAL_TYPE)))
8084 {
8085 error ("non-floating-point arguments in call to "
8086 "function %qE", fndecl);
8087 return false;
8088 }
8089 return true;
8090 }
8091 return false;
8092
19fbe3a4 8093 case BUILT_IN_FPCLASSIFY:
60cce472 8094 if (builtin_function_validate_nargs (fndecl, nargs, 6))
19fbe3a4 8095 {
8096 unsigned i;
48e1416a 8097
19fbe3a4 8098 for (i=0; i<5; i++)
8099 if (TREE_CODE (args[i]) != INTEGER_CST)
8100 {
8101 error ("non-const integer argument %u in call to function %qE",
8102 i+1, fndecl);
8103 return false;
8104 }
8105
8106 if (TREE_CODE (TREE_TYPE (args[5])) != REAL_TYPE)
8107 {
8108 error ("non-floating-point argument in call to function %qE",
8109 fndecl);
8110 return false;
8111 }
8112 return true;
8113 }
8114 return false;
8115
d43cee80 8116 default:
8117 return true;
8118 }
8119}
8120
860251be 8121/* Function to help qsort sort FIELD_DECLs by name order. */
8122
8123int
8124field_decl_cmp (const void *x_p, const void *y_p)
8125{
4fd61bc6 8126 const tree *const x = (const tree *const) x_p;
8127 const tree *const y = (const tree *const) y_p;
8128
860251be 8129 if (DECL_NAME (*x) == DECL_NAME (*y))
8130 /* A nontype is "greater" than a type. */
8131 return (TREE_CODE (*y) == TYPE_DECL) - (TREE_CODE (*x) == TYPE_DECL);
8132 if (DECL_NAME (*x) == NULL_TREE)
8133 return -1;
8134 if (DECL_NAME (*y) == NULL_TREE)
8135 return 1;
8136 if (DECL_NAME (*x) < DECL_NAME (*y))
8137 return -1;
8138 return 1;
8139}
8140
8141static struct {
8142 gt_pointer_operator new_value;
8143 void *cookie;
8144} resort_data;
8145
8146/* This routine compares two fields like field_decl_cmp but using the
8147pointer operator in resort_data. */
8148
8149static int
8150resort_field_decl_cmp (const void *x_p, const void *y_p)
8151{
4fd61bc6 8152 const tree *const x = (const tree *const) x_p;
8153 const tree *const y = (const tree *const) y_p;
860251be 8154
8155 if (DECL_NAME (*x) == DECL_NAME (*y))
8156 /* A nontype is "greater" than a type. */
8157 return (TREE_CODE (*y) == TYPE_DECL) - (TREE_CODE (*x) == TYPE_DECL);
8158 if (DECL_NAME (*x) == NULL_TREE)
8159 return -1;
8160 if (DECL_NAME (*y) == NULL_TREE)
8161 return 1;
8162 {
8163 tree d1 = DECL_NAME (*x);
8164 tree d2 = DECL_NAME (*y);
8165 resort_data.new_value (&d1, resort_data.cookie);
8166 resort_data.new_value (&d2, resort_data.cookie);
8167 if (d1 < d2)
8168 return -1;
8169 }
8170 return 1;
8171}
8172
8173/* Resort DECL_SORTED_FIELDS because pointers have been reordered. */
8174
8175void
8176resort_sorted_fields (void *obj,
9a03a746 8177 void * ARG_UNUSED (orig_obj),
4ee9c684 8178 gt_pointer_operator new_value,
8179 void *cookie)
860251be 8180{
9a03a746 8181 struct sorted_fields_type *sf = (struct sorted_fields_type *) obj;
860251be 8182 resort_data.new_value = new_value;
8183 resort_data.cookie = cookie;
8184 qsort (&sf->elts[0], sf->len, sizeof (tree),
4ee9c684 8185 resort_field_decl_cmp);
860251be 8186}
8187
209c9752 8188/* Subroutine of c_parse_error.
8189 Return the result of concatenating LHS and RHS. RHS is really
8190 a string literal, its first character is indicated by RHS_START and
cfee01e3 8191 RHS_SIZE is its length (including the terminating NUL character).
209c9752 8192
8193 The caller is responsible for deleting the returned pointer. */
8194
8195static char *
8196catenate_strings (const char *lhs, const char *rhs_start, int rhs_size)
8197{
8198 const int lhs_size = strlen (lhs);
8199 char *result = XNEWVEC (char, lhs_size + rhs_size);
8200 strncpy (result, lhs, lhs_size);
8201 strncpy (result + lhs_size, rhs_start, rhs_size);
8202 return result;
8203}
8204
380c6697 8205/* Issue the error given by GMSGID, indicating that it occurred before
92b128ed 8206 TOKEN, which had the associated VALUE. */
8207
8208void
48e1416a 8209c_parse_error (const char *gmsgid, enum cpp_ttype token_type,
ba99525e 8210 tree value, unsigned char token_flags)
92b128ed 8211{
209c9752 8212#define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2))
8213
8214 char *message = NULL;
92b128ed 8215
ba99525e 8216 if (token_type == CPP_EOF)
380c6697 8217 message = catenate_messages (gmsgid, " at end of input");
48e1416a 8218 else if (token_type == CPP_CHAR
8219 || token_type == CPP_WCHAR
ba99525e 8220 || token_type == CPP_CHAR16
8221 || token_type == CPP_CHAR32)
92b128ed 8222 {
8223 unsigned int val = TREE_INT_CST_LOW (value);
924bbf02 8224 const char *prefix;
8225
ba99525e 8226 switch (token_type)
924bbf02 8227 {
8228 default:
8229 prefix = "";
8230 break;
8231 case CPP_WCHAR:
8232 prefix = "L";
8233 break;
8234 case CPP_CHAR16:
8235 prefix = "u";
8236 break;
8237 case CPP_CHAR32:
8238 prefix = "U";
8239 break;
8240 }
8241
92b128ed 8242 if (val <= UCHAR_MAX && ISGRAPH (val))
a0c938f0 8243 message = catenate_messages (gmsgid, " before %s'%c'");
92b128ed 8244 else
a0c938f0 8245 message = catenate_messages (gmsgid, " before %s'\\x%x'");
209c9752 8246
924bbf02 8247 error (message, prefix, val);
209c9752 8248 free (message);
8249 message = NULL;
92b128ed 8250 }
48e1416a 8251 else if (token_type == CPP_STRING
8252 || token_type == CPP_WSTRING
ba99525e 8253 || token_type == CPP_STRING16
538ba11a 8254 || token_type == CPP_STRING32
8255 || token_type == CPP_UTF8STRING)
380c6697 8256 message = catenate_messages (gmsgid, " before string constant");
ba99525e 8257 else if (token_type == CPP_NUMBER)
380c6697 8258 message = catenate_messages (gmsgid, " before numeric constant");
ba99525e 8259 else if (token_type == CPP_NAME)
209c9752 8260 {
380c6697 8261 message = catenate_messages (gmsgid, " before %qE");
782858b8 8262 error (message, value);
209c9752 8263 free (message);
8264 message = NULL;
8265 }
ba99525e 8266 else if (token_type == CPP_PRAGMA)
b75b98aa 8267 message = catenate_messages (gmsgid, " before %<#pragma%>");
ba99525e 8268 else if (token_type == CPP_PRAGMA_EOL)
b75b98aa 8269 message = catenate_messages (gmsgid, " before end of line");
ba99525e 8270 else if (token_type < N_TTYPES)
209c9752 8271 {
380c6697 8272 message = catenate_messages (gmsgid, " before %qs token");
ba99525e 8273 error (message, cpp_type2name (token_type, token_flags));
209c9752 8274 free (message);
8275 message = NULL;
8276 }
92b128ed 8277 else
380c6697 8278 error (gmsgid);
209c9752 8279
8280 if (message)
8281 {
8282 error (message);
8283 free (message);
8284 }
a0c938f0 8285#undef catenate_messages
92b128ed 8286}
8287
3a79f5da 8288/* Mapping for cpp message reasons to the options that enable them. */
8289
8290struct reason_option_codes_t
8291{
8292 const int reason; /* cpplib message reason. */
8293 const int option_code; /* gcc option that controls this message. */
8294};
8295
8296static const struct reason_option_codes_t option_codes[] = {
8297 {CPP_W_DEPRECATED, OPT_Wdeprecated},
67089c6b 8298 {CPP_W_COMMENTS, OPT_Wcomment},
3a79f5da 8299 {CPP_W_TRIGRAPHS, OPT_Wtrigraphs},
8300 {CPP_W_MULTICHAR, OPT_Wmultichar},
8301 {CPP_W_TRADITIONAL, OPT_Wtraditional},
8302 {CPP_W_LONG_LONG, OPT_Wlong_long},
8303 {CPP_W_ENDIF_LABELS, OPT_Wendif_labels},
8304 {CPP_W_VARIADIC_MACROS, OPT_Wvariadic_macros},
8305 {CPP_W_BUILTIN_MACRO_REDEFINED, OPT_Wbuiltin_macro_redefined},
8306 {CPP_W_UNDEF, OPT_Wundef},
8307 {CPP_W_UNUSED_MACROS, OPT_Wunused_macros},
8308 {CPP_W_CXX_OPERATOR_NAMES, OPT_Wc___compat},
8309 {CPP_W_NORMALIZE, OPT_Wnormalized_},
8310 {CPP_W_INVALID_PCH, OPT_Winvalid_pch},
8311 {CPP_W_WARNING_DIRECTIVE, OPT_Wcpp},
8312 {CPP_W_NONE, 0}
8313};
8314
8315/* Return the gcc option code associated with the reason for a cpp
8316 message, or 0 if none. */
8317
8318static int
8319c_option_controlling_cpp_error (int reason)
8320{
8321 const struct reason_option_codes_t *entry;
8322
8323 for (entry = option_codes; entry->reason != CPP_W_NONE; entry++)
8324 {
8325 if (entry->reason == reason)
8326 return entry->option_code;
8327 }
8328 return 0;
8329}
8330
7f5f3953 8331/* Callback from cpp_error for PFILE to print diagnostics from the
3a79f5da 8332 preprocessor. The diagnostic is of type LEVEL, with REASON set
8333 to the reason code if LEVEL is represents a warning, at location
7f5f3953 8334 LOCATION unless this is after lexing and the compiler's location
8335 should be used instead, with column number possibly overridden by
8336 COLUMN_OVERRIDE if not zero; MSG is the translated message and AP
8337 the arguments. Returns true if a diagnostic was emitted, false
8338 otherwise. */
8339
8340bool
3a79f5da 8341c_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level, int reason,
7f5f3953 8342 location_t location, unsigned int column_override,
8343 const char *msg, va_list *ap)
8344{
8345 diagnostic_info diagnostic;
8346 diagnostic_t dlevel;
5ae82d58 8347 bool save_warn_system_headers = global_dc->dc_warn_system_headers;
7f5f3953 8348 bool ret;
8349
8350 switch (level)
8351 {
8352 case CPP_DL_WARNING_SYSHDR:
8353 if (flag_no_output)
8354 return false;
5ae82d58 8355 global_dc->dc_warn_system_headers = 1;
7f5f3953 8356 /* Fall through. */
8357 case CPP_DL_WARNING:
8358 if (flag_no_output)
8359 return false;
8360 dlevel = DK_WARNING;
8361 break;
8362 case CPP_DL_PEDWARN:
8363 if (flag_no_output && !flag_pedantic_errors)
8364 return false;
8365 dlevel = DK_PEDWARN;
8366 break;
8367 case CPP_DL_ERROR:
8368 dlevel = DK_ERROR;
8369 break;
8370 case CPP_DL_ICE:
8371 dlevel = DK_ICE;
8372 break;
8373 case CPP_DL_NOTE:
8374 dlevel = DK_NOTE;
8375 break;
ff903809 8376 case CPP_DL_FATAL:
8377 dlevel = DK_FATAL;
8378 break;
7f5f3953 8379 default:
8380 gcc_unreachable ();
8381 }
8382 if (done_lexing)
8383 location = input_location;
8384 diagnostic_set_info_translated (&diagnostic, msg, ap,
8385 location, dlevel);
8386 if (column_override)
8387 diagnostic_override_column (&diagnostic, column_override);
3a79f5da 8388 diagnostic_override_option_index (&diagnostic,
8389 c_option_controlling_cpp_error (reason));
7f5f3953 8390 ret = report_diagnostic (&diagnostic);
8391 if (level == CPP_DL_WARNING_SYSHDR)
5ae82d58 8392 global_dc->dc_warn_system_headers = save_warn_system_headers;
7f5f3953 8393 return ret;
8394}
8395
624d37a6 8396/* Convert a character from the host to the target execution character
8397 set. cpplib handles this, mostly. */
8398
8399HOST_WIDE_INT
8400c_common_to_target_charset (HOST_WIDE_INT c)
8401{
8402 /* Character constants in GCC proper are sign-extended under -fsigned-char,
8403 zero-extended under -fno-signed-char. cpplib insists that characters
8404 and character constants are always unsigned. Hence we must convert
8405 back and forth. */
8406 cppchar_t uc = ((cppchar_t)c) & ((((cppchar_t)1) << CHAR_BIT)-1);
8407
8408 uc = cpp_host_to_exec_charset (parse_in, uc);
8409
8410 if (flag_signed_char)
8411 return ((HOST_WIDE_INT)uc) << (HOST_BITS_PER_WIDE_INT - CHAR_TYPE_SIZE)
8412 >> (HOST_BITS_PER_WIDE_INT - CHAR_TYPE_SIZE);
8413 else
8414 return uc;
8415}
8416
af28855b 8417/* Build the result of __builtin_offsetof. EXPR is a nested sequence of
d897f7c2 8418 component references, with STOP_REF, or alternatively an INDIRECT_REF of
8419 NULL, at the bottom; much like the traditional rendering of offsetof as a
8420 macro. Returns the folded and properly cast result. */
af28855b 8421
8422static tree
d897f7c2 8423fold_offsetof_1 (tree expr, tree stop_ref)
af28855b 8424{
8425 enum tree_code code = PLUS_EXPR;
8426 tree base, off, t;
8427
d897f7c2 8428 if (expr == stop_ref && TREE_CODE (expr) != ERROR_MARK)
8429 return size_zero_node;
8430
af28855b 8431 switch (TREE_CODE (expr))
8432 {
8433 case ERROR_MARK:
8434 return expr;
8435
6b11d2e3 8436 case VAR_DECL:
8437 error ("cannot apply %<offsetof%> to static data member %qD", expr);
8438 return error_mark_node;
8439
d897f7c2 8440 case CALL_EXPR:
cf1a89a3 8441 case TARGET_EXPR:
d897f7c2 8442 error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded");
8443 return error_mark_node;
8444
d897f7c2 8445 case NOP_EXPR:
8446 case INDIRECT_REF:
64ed018c 8447 if (!integer_zerop (TREE_OPERAND (expr, 0)))
8448 {
8449 error ("cannot apply %<offsetof%> to a non constant address");
8450 return error_mark_node;
8451 }
8452 return size_zero_node;
d897f7c2 8453
af28855b 8454 case COMPONENT_REF:
d897f7c2 8455 base = fold_offsetof_1 (TREE_OPERAND (expr, 0), stop_ref);
af28855b 8456 if (base == error_mark_node)
8457 return base;
8458
8459 t = TREE_OPERAND (expr, 1);
8460 if (DECL_C_BIT_FIELD (t))
8461 {
8462 error ("attempt to take address of bit-field structure "
782858b8 8463 "member %qD", t);
af28855b 8464 return error_mark_node;
8465 }
389dd41b 8466 off = size_binop_loc (input_location, PLUS_EXPR, DECL_FIELD_OFFSET (t),
8467 size_int (tree_low_cst (DECL_FIELD_BIT_OFFSET (t),
8468 1)
8469 / BITS_PER_UNIT));
af28855b 8470 break;
8471
8472 case ARRAY_REF:
d897f7c2 8473 base = fold_offsetof_1 (TREE_OPERAND (expr, 0), stop_ref);
af28855b 8474 if (base == error_mark_node)
8475 return base;
8476
8477 t = TREE_OPERAND (expr, 1);
8478 if (TREE_CODE (t) == INTEGER_CST && tree_int_cst_sgn (t) < 0)
8479 {
8480 code = MINUS_EXPR;
389dd41b 8481 t = fold_build1_loc (input_location, NEGATE_EXPR, TREE_TYPE (t), t);
af28855b 8482 }
8483 t = convert (sizetype, t);
8484 off = size_binop (MULT_EXPR, TYPE_SIZE_UNIT (TREE_TYPE (expr)), t);
64ed018c 8485
8486 /* Check if the offset goes beyond the upper bound of the array. */
e0559d69 8487 if (code == PLUS_EXPR && TREE_CODE (t) == INTEGER_CST)
8488 {
8489 tree upbound = array_ref_up_bound (expr);
8490 if (upbound != NULL_TREE
8491 && TREE_CODE (upbound) == INTEGER_CST
8492 && !tree_int_cst_equal (upbound,
8493 TYPE_MAX_VALUE (TREE_TYPE (upbound))))
8494 {
8495 upbound = size_binop (PLUS_EXPR, upbound,
8496 build_int_cst (TREE_TYPE (upbound), 1));
8497 if (tree_int_cst_lt (upbound, t))
8498 {
8499 tree v;
8500
8501 for (v = TREE_OPERAND (expr, 0);
8502 TREE_CODE (v) == COMPONENT_REF;
8503 v = TREE_OPERAND (v, 0))
8504 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0)))
8505 == RECORD_TYPE)
8506 {
1767a056 8507 tree fld_chain = DECL_CHAIN (TREE_OPERAND (v, 1));
8508 for (; fld_chain; fld_chain = DECL_CHAIN (fld_chain))
e0559d69 8509 if (TREE_CODE (fld_chain) == FIELD_DECL)
8510 break;
8511
8512 if (fld_chain)
8513 break;
8514 }
8515 /* Don't warn if the array might be considered a poor
8516 man's flexible array member with a very permissive
8517 definition thereof. */
8518 if (TREE_CODE (v) == ARRAY_REF
8519 || TREE_CODE (v) == COMPONENT_REF)
8520 warning (OPT_Warray_bounds,
8521 "index %E denotes an offset "
8522 "greater than size of %qT",
8523 t, TREE_TYPE (TREE_OPERAND (expr, 0)));
8524 }
8525 }
8526 }
af28855b 8527 break;
8528
ede90cc2 8529 case COMPOUND_EXPR:
8530 /* Handle static members of volatile structs. */
8531 t = TREE_OPERAND (expr, 1);
8532 gcc_assert (TREE_CODE (t) == VAR_DECL);
8533 return fold_offsetof_1 (t, stop_ref);
8534
af28855b 8535 default:
231bd014 8536 gcc_unreachable ();
af28855b 8537 }
8538
8539 return size_binop (code, base, off);
8540}
8541
8542tree
d897f7c2 8543fold_offsetof (tree expr, tree stop_ref)
af28855b 8544{
8545 /* Convert back from the internal sizetype to size_t. */
d897f7c2 8546 return convert (size_type_node, fold_offsetof_1 (expr, stop_ref));
af28855b 8547}
8548
b9bdfa0b 8549/* Warn for A ?: C expressions (with B omitted) where A is a boolean
8550 expression, because B will always be true. */
8551
8552void
8553warn_for_omitted_condop (location_t location, tree cond)
8554{
8555 if (truth_value_p (TREE_CODE (cond)))
8556 warning_at (location, OPT_Wparentheses,
8557 "the omitted middle operand in ?: will always be %<true%>, "
8558 "suggest explicit middle operand");
8559}
8560
a1f90215 8561/* Give an error for storing into ARG, which is 'const'. USE indicates
8562 how ARG was being used. */
8563
8564void
8565readonly_error (tree arg, enum lvalue_use use)
8566{
8567 gcc_assert (use == lv_assign || use == lv_increment || use == lv_decrement
8568 || use == lv_asm);
8569 /* Using this macro rather than (for example) arrays of messages
8570 ensures that all the format strings are checked at compile
8571 time. */
8572#define READONLY_MSG(A, I, D, AS) (use == lv_assign ? (A) \
8573 : (use == lv_increment ? (I) \
8574 : (use == lv_decrement ? (D) : (AS))))
8575 if (TREE_CODE (arg) == COMPONENT_REF)
8576 {
8577 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg, 0))))
8578 error (READONLY_MSG (G_("assignment of member "
8579 "%qD in read-only object"),
8580 G_("increment of member "
8581 "%qD in read-only object"),
8582 G_("decrement of member "
8583 "%qD in read-only object"),
8584 G_("member %qD in read-only object "
8585 "used as %<asm%> output")),
8586 TREE_OPERAND (arg, 1));
8587 else
8588 error (READONLY_MSG (G_("assignment of read-only member %qD"),
8589 G_("increment of read-only member %qD"),
8590 G_("decrement of read-only member %qD"),
8591 G_("read-only member %qD used as %<asm%> output")),
8592 TREE_OPERAND (arg, 1));
8593 }
8594 else if (TREE_CODE (arg) == VAR_DECL)
8595 error (READONLY_MSG (G_("assignment of read-only variable %qD"),
8596 G_("increment of read-only variable %qD"),
8597 G_("decrement of read-only variable %qD"),
8598 G_("read-only variable %qD used as %<asm%> output")),
8599 arg);
8600 else if (TREE_CODE (arg) == PARM_DECL)
8601 error (READONLY_MSG (G_("assignment of read-only parameter %qD"),
8602 G_("increment of read-only parameter %qD"),
8603 G_("decrement of read-only parameter %qD"),
8604 G_("read-only parameter %qD use as %<asm%> output")),
8605 arg);
8606 else if (TREE_CODE (arg) == RESULT_DECL)
8607 {
8608 gcc_assert (c_dialect_cxx ());
8609 error (READONLY_MSG (G_("assignment of "
8610 "read-only named return value %qD"),
8611 G_("increment of "
8612 "read-only named return value %qD"),
8613 G_("decrement of "
8614 "read-only named return value %qD"),
8615 G_("read-only named return value %qD "
8616 "used as %<asm%>output")),
8617 arg);
8618 }
8619 else if (TREE_CODE (arg) == FUNCTION_DECL)
8620 error (READONLY_MSG (G_("assignment of function %qD"),
8621 G_("increment of function %qD"),
8622 G_("decrement of function %qD"),
8623 G_("function %qD used as %<asm%> output")),
8624 arg);
8625 else
8626 error (READONLY_MSG (G_("assignment of read-only location %qE"),
8627 G_("increment of read-only location %qE"),
8628 G_("decrement of read-only location %qE"),
8629 G_("read-only location %qE used as %<asm%> output")),
8630 arg);
8631}
8632
e35976b1 8633/* Print an error message for an invalid lvalue. USE says
fdd84b77 8634 how the lvalue is being used and so selects the error message. LOC
8635 is the location for the error. */
ab6bb714 8636
e35976b1 8637void
fdd84b77 8638lvalue_error (location_t loc, enum lvalue_use use)
ab6bb714 8639{
e35976b1 8640 switch (use)
ab6bb714 8641 {
e35976b1 8642 case lv_assign:
fdd84b77 8643 error_at (loc, "lvalue required as left operand of assignment");
e35976b1 8644 break;
8645 case lv_increment:
fdd84b77 8646 error_at (loc, "lvalue required as increment operand");
e35976b1 8647 break;
8648 case lv_decrement:
fdd84b77 8649 error_at (loc, "lvalue required as decrement operand");
e35976b1 8650 break;
8651 case lv_addressof:
fdd84b77 8652 error_at (loc, "lvalue required as unary %<&%> operand");
e35976b1 8653 break;
8654 case lv_asm:
fdd84b77 8655 error_at (loc, "lvalue required in asm statement");
e35976b1 8656 break;
8657 default:
8658 gcc_unreachable ();
ab6bb714 8659 }
ab6bb714 8660}
b1bbc8e5 8661
8662/* Print an error message for an invalid indirection of type TYPE.
8663 ERRSTRING is the name of the operator for the indirection. */
8664
8665void
8666invalid_indirection_error (location_t loc, tree type, ref_operator errstring)
8667{
8668 switch (errstring)
8669 {
8670 case RO_NULL:
8671 gcc_assert (c_dialect_cxx ());
8672 error_at (loc, "invalid type argument (have %qT)", type);
8673 break;
8674 case RO_ARRAY_INDEXING:
8675 error_at (loc,
8676 "invalid type argument of array indexing (have %qT)",
8677 type);
8678 break;
8679 case RO_UNARY_STAR:
8680 error_at (loc,
8681 "invalid type argument of unary %<*%> (have %qT)",
8682 type);
8683 break;
8684 case RO_ARROW:
8685 error_at (loc,
8686 "invalid type argument of %<->%> (have %qT)",
8687 type);
8688 break;
8689 case RO_IMPLICIT_CONVERSION:
8690 error_at (loc,
8691 "invalid type argument of implicit conversion (have %qT)",
8692 type);
8693 break;
8694 default:
8695 gcc_unreachable ();
8696 }
8697}
c271bdb2 8698\f
8699/* *PTYPE is an incomplete array. Complete it with a domain based on
8700 INITIAL_VALUE. If INITIAL_VALUE is not present, use 1 if DO_DEFAULT
8701 is true. Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
8702 2 if INITIAL_VALUE was NULL, and 3 if INITIAL_VALUE was empty. */
8703
8704int
8705complete_array_type (tree *ptype, tree initial_value, bool do_default)
8706{
8707 tree maxindex, type, main_type, elt, unqual_elt;
8708 int failure = 0, quals;
6753bca0 8709 hashval_t hashcode = 0;
c271bdb2 8710
8711 maxindex = size_zero_node;
8712 if (initial_value)
8713 {
8714 if (TREE_CODE (initial_value) == STRING_CST)
8715 {
8716 int eltsize
8717 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value)));
8718 maxindex = size_int (TREE_STRING_LENGTH (initial_value)/eltsize - 1);
8719 }
8720 else if (TREE_CODE (initial_value) == CONSTRUCTOR)
8721 {
c75b4594 8722 VEC(constructor_elt,gc) *v = CONSTRUCTOR_ELTS (initial_value);
c271bdb2 8723
c75b4594 8724 if (VEC_empty (constructor_elt, v))
c271bdb2 8725 {
8726 if (pedantic)
8727 failure = 3;
8728 maxindex = integer_minus_one_node;
8729 }
8730 else
8731 {
8732 tree curindex;
c75b4594 8733 unsigned HOST_WIDE_INT cnt;
8734 constructor_elt *ce;
cee43f7e 8735 bool fold_p = false;
c271bdb2 8736
c75b4594 8737 if (VEC_index (constructor_elt, v, 0)->index)
389dd41b 8738 maxindex = fold_convert_loc (input_location, sizetype,
8739 VEC_index (constructor_elt,
8740 v, 0)->index);
c271bdb2 8741 curindex = maxindex;
8742
c75b4594 8743 for (cnt = 1;
8744 VEC_iterate (constructor_elt, v, cnt, ce);
8745 cnt++)
c271bdb2 8746 {
cee43f7e 8747 bool curfold_p = false;
c75b4594 8748 if (ce->index)
cee43f7e 8749 curindex = ce->index, curfold_p = true;
c271bdb2 8750 else
cee43f7e 8751 {
8752 if (fold_p)
8753 curindex = fold_convert (sizetype, curindex);
389dd41b 8754 curindex = size_binop (PLUS_EXPR, curindex,
8755 size_one_node);
cee43f7e 8756 }
c271bdb2 8757 if (tree_int_cst_lt (maxindex, curindex))
cee43f7e 8758 maxindex = curindex, fold_p = curfold_p;
c271bdb2 8759 }
cee43f7e 8760 if (fold_p)
8761 maxindex = fold_convert (sizetype, maxindex);
c271bdb2 8762 }
8763 }
8764 else
8765 {
8766 /* Make an error message unless that happened already. */
8767 if (initial_value != error_mark_node)
8768 failure = 1;
8769 }
8770 }
8771 else
8772 {
8773 failure = 2;
8774 if (!do_default)
8775 return failure;
8776 }
8777
8778 type = *ptype;
8779 elt = TREE_TYPE (type);
8780 quals = TYPE_QUALS (strip_array_types (elt));
8781 if (quals == 0)
8782 unqual_elt = elt;
8783 else
6d5d708e 8784 unqual_elt = c_build_qualified_type (elt, KEEP_QUAL_ADDR_SPACE (quals));
c271bdb2 8785
8786 /* Using build_distinct_type_copy and modifying things afterward instead
8787 of using build_array_type to create a new type preserves all of the
8788 TYPE_LANG_FLAG_? bits that the front end may have set. */
8789 main_type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
8790 TREE_TYPE (main_type) = unqual_elt;
8791 TYPE_DOMAIN (main_type) = build_index_type (maxindex);
8792 layout_type (main_type);
8793
6753bca0 8794 /* Make sure we have the canonical MAIN_TYPE. */
8795 hashcode = iterative_hash_object (TYPE_HASH (unqual_elt), hashcode);
48e1416a 8796 hashcode = iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (main_type)),
6753bca0 8797 hashcode);
8798 main_type = type_hash_canon (hashcode, main_type);
8799
796735dc 8800 /* Fix the canonical type. */
8801 if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type))
8802 || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type)))
8803 SET_TYPE_STRUCTURAL_EQUALITY (main_type);
8804 else if (TYPE_CANONICAL (TREE_TYPE (main_type)) != TREE_TYPE (main_type)
8805 || (TYPE_CANONICAL (TYPE_DOMAIN (main_type))
8806 != TYPE_DOMAIN (main_type)))
48e1416a 8807 TYPE_CANONICAL (main_type)
796735dc 8808 = build_array_type (TYPE_CANONICAL (TREE_TYPE (main_type)),
8809 TYPE_CANONICAL (TYPE_DOMAIN (main_type)));
8810 else
8811 TYPE_CANONICAL (main_type) = main_type;
8812
c271bdb2 8813 if (quals == 0)
8814 type = main_type;
8815 else
8816 type = c_build_qualified_type (main_type, quals);
8817
4f5b8f2a 8818 if (COMPLETE_TYPE_P (type)
8819 && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST
8820 && TREE_OVERFLOW (TYPE_SIZE_UNIT (type)))
8821 {
8822 error ("size of array is too large");
8823 /* If we proceed with the array type as it is, we'll eventually
8824 crash in tree_low_cst(). */
8825 type = error_mark_node;
8826 }
8827
c271bdb2 8828 *ptype = type;
8829 return failure;
8830}
ab6bb714 8831
93426222 8832/* Like c_mark_addressable but don't check register qualifier. */
8833void
8834c_common_mark_addressable_vec (tree t)
8835{
8836 while (handled_component_p (t))
8837 t = TREE_OPERAND (t, 0);
8838 if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL)
8839 return;
8840 TREE_ADDRESSABLE (t) = 1;
8841}
8842
8843
b6a5fc45 8844\f
8845/* Used to help initialize the builtin-types.def table. When a type of
8846 the correct size doesn't exist, use error_mark_node instead of NULL.
8847 The later results in segfaults even when a decl using the type doesn't
8848 get invoked. */
8849
8850tree
8851builtin_type_for_size (int size, bool unsignedp)
8852{
8853 tree type = lang_hooks.types.type_for_size (size, unsignedp);
8854 return type ? type : error_mark_node;
8855}
8856
8857/* A helper function for resolve_overloaded_builtin in resolving the
8858 overloaded __sync_ builtins. Returns a positive power of 2 if the
8859 first operand of PARAMS is a pointer to a supported data type.
8860 Returns 0 if an error is encountered. */
8861
8862static int
b9c74b4d 8863sync_resolve_size (tree function, VEC(tree,gc) *params)
b6a5fc45 8864{
8865 tree type;
8866 int size;
8867
b9c74b4d 8868 if (VEC_empty (tree, params))
b6a5fc45 8869 {
8870 error ("too few arguments to function %qE", function);
8871 return 0;
8872 }
8873
b9c74b4d 8874 type = TREE_TYPE (VEC_index (tree, params, 0));
b6a5fc45 8875 if (TREE_CODE (type) != POINTER_TYPE)
8876 goto incompatible;
8877
8878 type = TREE_TYPE (type);
8879 if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
8880 goto incompatible;
8881
8882 size = tree_low_cst (TYPE_SIZE_UNIT (type), 1);
27213ba3 8883 if (size == 1 || size == 2 || size == 4 || size == 8 || size == 16)
b6a5fc45 8884 return size;
8885
8886 incompatible:
8887 error ("incompatible type for argument %d of %qE", 1, function);
8888 return 0;
8889}
8890
a0c938f0 8891/* A helper function for resolve_overloaded_builtin. Adds casts to
b6a5fc45 8892 PARAMS to make arguments match up with those of FUNCTION. Drops
8893 the variadic arguments at the end. Returns false if some error
8894 was encountered; true on success. */
8895
8896static bool
b9c74b4d 8897sync_resolve_params (tree orig_function, tree function, VEC(tree, gc) *params)
b6a5fc45 8898{
8899 tree arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
8900 tree ptype;
b9c74b4d 8901 unsigned int parmnum;
b6a5fc45 8902
8903 /* We've declared the implementation functions to use "volatile void *"
8904 as the pointer parameter, so we shouldn't get any complaints from the
8905 call to check_function_arguments what ever type the user used. */
8906 arg_types = TREE_CHAIN (arg_types);
b9c74b4d 8907 ptype = TREE_TYPE (TREE_TYPE (VEC_index (tree, params, 0)));
b6a5fc45 8908
8909 /* For the rest of the values, we need to cast these to FTYPE, so that we
8910 don't get warnings for passing pointer types, etc. */
b9c74b4d 8911 parmnum = 0;
b6a5fc45 8912 while (arg_types != void_list_node)
8913 {
8914 tree val;
8915
b9c74b4d 8916 ++parmnum;
8917 if (VEC_length (tree, params) <= parmnum)
b6a5fc45 8918 {
8919 error ("too few arguments to function %qE", orig_function);
8920 return false;
8921 }
8922
8923 /* ??? Ideally for the first conversion we'd use convert_for_assignment
8924 so that we get warnings for anything that doesn't match the pointer
8925 type. This isn't portable across the C and C++ front ends atm. */
b9c74b4d 8926 val = VEC_index (tree, params, parmnum);
b6a5fc45 8927 val = convert (ptype, val);
8928 val = convert (TREE_VALUE (arg_types), val);
b9c74b4d 8929 VEC_replace (tree, params, parmnum, val);
b6a5fc45 8930
8931 arg_types = TREE_CHAIN (arg_types);
b6a5fc45 8932 }
8933
8934 /* The definition of these primitives is variadic, with the remaining
8935 being "an optional list of variables protected by the memory barrier".
8936 No clue what that's supposed to mean, precisely, but we consider all
8937 call-clobbered variables to be protected so we're safe. */
b9c74b4d 8938 VEC_truncate (tree, params, parmnum + 1);
b6a5fc45 8939
8940 return true;
8941}
8942
a0c938f0 8943/* A helper function for resolve_overloaded_builtin. Adds a cast to
b6a5fc45 8944 RESULT to make it match the type of the first pointer argument in
8945 PARAMS. */
8946
8947static tree
b9c74b4d 8948sync_resolve_return (tree first_param, tree result)
b6a5fc45 8949{
b9c74b4d 8950 tree ptype = TREE_TYPE (TREE_TYPE (first_param));
10080eac 8951 ptype = TYPE_MAIN_VARIANT (ptype);
b6a5fc45 8952 return convert (ptype, result);
8953}
8954
8955/* Some builtin functions are placeholders for other expressions. This
8956 function should be called immediately after parsing the call expression
8957 before surrounding code has committed to the type of the expression.
8958
e60a6f7b 8959 LOC is the location of the builtin call.
8960
b6a5fc45 8961 FUNCTION is the DECL that has been invoked; it is known to be a builtin.
8962 PARAMS is the argument list for the call. The return value is non-null
8963 when expansion is complete, and null if normal processing should
8964 continue. */
8965
8966tree
e60a6f7b 8967resolve_overloaded_builtin (location_t loc, tree function, VEC(tree,gc) *params)
b6a5fc45 8968{
8969 enum built_in_function orig_code = DECL_FUNCTION_CODE (function);
65441f6f 8970 switch (DECL_BUILT_IN_CLASS (function))
8971 {
8972 case BUILT_IN_NORMAL:
8973 break;
8974 case BUILT_IN_MD:
8975 if (targetm.resolve_overloaded_builtin)
e60a6f7b 8976 return targetm.resolve_overloaded_builtin (loc, function, params);
65441f6f 8977 else
a0c938f0 8978 return NULL_TREE;
65441f6f 8979 default:
8980 return NULL_TREE;
8981 }
a0c938f0 8982
65441f6f 8983 /* Handle BUILT_IN_NORMAL here. */
b6a5fc45 8984 switch (orig_code)
8985 {
8986 case BUILT_IN_FETCH_AND_ADD_N:
8987 case BUILT_IN_FETCH_AND_SUB_N:
8988 case BUILT_IN_FETCH_AND_OR_N:
8989 case BUILT_IN_FETCH_AND_AND_N:
8990 case BUILT_IN_FETCH_AND_XOR_N:
8991 case BUILT_IN_FETCH_AND_NAND_N:
8992 case BUILT_IN_ADD_AND_FETCH_N:
8993 case BUILT_IN_SUB_AND_FETCH_N:
8994 case BUILT_IN_OR_AND_FETCH_N:
8995 case BUILT_IN_AND_AND_FETCH_N:
8996 case BUILT_IN_XOR_AND_FETCH_N:
8997 case BUILT_IN_NAND_AND_FETCH_N:
8998 case BUILT_IN_BOOL_COMPARE_AND_SWAP_N:
8999 case BUILT_IN_VAL_COMPARE_AND_SWAP_N:
9000 case BUILT_IN_LOCK_TEST_AND_SET_N:
9001 case BUILT_IN_LOCK_RELEASE_N:
9002 {
9003 int n = sync_resolve_size (function, params);
b9c74b4d 9004 tree new_function, first_param, result;
b6a5fc45 9005
9006 if (n == 0)
9007 return error_mark_node;
9008
9009 new_function = built_in_decls[orig_code + exact_log2 (n) + 1];
9010 if (!sync_resolve_params (function, new_function, params))
9011 return error_mark_node;
9012
b9c74b4d 9013 first_param = VEC_index (tree, params, 0);
e60a6f7b 9014 result = build_function_call_vec (loc, new_function, params, NULL);
b6a5fc45 9015 if (orig_code != BUILT_IN_BOOL_COMPARE_AND_SWAP_N
9016 && orig_code != BUILT_IN_LOCK_RELEASE_N)
b9c74b4d 9017 result = sync_resolve_return (first_param, result);
b6a5fc45 9018
9019 return result;
9020 }
9021
9022 default:
65441f6f 9023 return NULL_TREE;
b6a5fc45 9024 }
9025}
9026
491255f5 9027/* Ignoring their sign, return true if two scalar types are the same. */
9028bool
9029same_scalar_type_ignoring_signedness (tree t1, tree t2)
9030{
9031 enum tree_code c1 = TREE_CODE (t1), c2 = TREE_CODE (t2);
9032
9421ebb9 9033 gcc_assert ((c1 == INTEGER_TYPE || c1 == REAL_TYPE || c1 == FIXED_POINT_TYPE)
9034 && (c2 == INTEGER_TYPE || c2 == REAL_TYPE
9035 || c2 == FIXED_POINT_TYPE));
491255f5 9036
9037 /* Equality works here because c_common_signed_type uses
9038 TYPE_MAIN_VARIANT. */
11773141 9039 return c_common_signed_type (t1)
9040 == c_common_signed_type (t2);
491255f5 9041}
9042
be7350e7 9043/* Check for missing format attributes on function pointers. LTYPE is
9044 the new type or left-hand side type. RTYPE is the old type or
9045 right-hand side type. Returns TRUE if LTYPE is missing the desired
9046 attribute. */
9047
9048bool
9049check_missing_format_attribute (tree ltype, tree rtype)
9050{
9051 tree const ttr = TREE_TYPE (rtype), ttl = TREE_TYPE (ltype);
9052 tree ra;
9053
9054 for (ra = TYPE_ATTRIBUTES (ttr); ra; ra = TREE_CHAIN (ra))
9055 if (is_attribute_p ("format", TREE_PURPOSE (ra)))
9056 break;
9057 if (ra)
9058 {
9059 tree la;
9060 for (la = TYPE_ATTRIBUTES (ttl); la; la = TREE_CHAIN (la))
9061 if (is_attribute_p ("format", TREE_PURPOSE (la)))
9062 break;
9063 return !la;
9064 }
9065 else
9066 return false;
9067}
9068
2840aae4 9069/* Subscripting with type char is likely to lose on a machine where
9070 chars are signed. So warn on any machine, but optionally. Don't
9071 warn for unsigned char since that type is safe. Don't warn for
9072 signed char because anyone who uses that must have done so
9073 deliberately. Furthermore, we reduce the false positive load by
9074 warning only for non-constant value of type char. */
9075
9076void
9077warn_array_subscript_with_type_char (tree index)
9078{
9079 if (TYPE_MAIN_VARIANT (TREE_TYPE (index)) == char_type_node
9080 && TREE_CODE (index) != INTEGER_CST)
9081 warning (OPT_Wchar_subscripts, "array subscript has type %<char%>");
9082}
9083
e534436e 9084/* Implement -Wparentheses for the unexpected C precedence rules, to
9085 cover cases like x + y << z which readers are likely to
9086 misinterpret. We have seen an expression in which CODE is a binary
82012ffe 9087 operator used to combine expressions ARG_LEFT and ARG_RIGHT, which
9088 before folding had CODE_LEFT and CODE_RIGHT. CODE_LEFT and
9089 CODE_RIGHT may be ERROR_MARK, which means that that side of the
9090 expression was not formed using a binary or unary operator, or it
9091 was enclosed in parentheses. */
e534436e 9092
9093void
82012ffe 9094warn_about_parentheses (enum tree_code code,
269f7979 9095 enum tree_code code_left, tree arg_left,
82012ffe 9096 enum tree_code code_right, tree arg_right)
e534436e 9097{
9098 if (!warn_parentheses)
9099 return;
9100
82012ffe 9101 /* This macro tests that the expression ARG with original tree code
9102 CODE appears to be a boolean expression. or the result of folding a
9103 boolean expression. */
9104#define APPEARS_TO_BE_BOOLEAN_EXPR_P(CODE, ARG) \
9105 (truth_value_p (TREE_CODE (ARG)) \
9106 || TREE_CODE (TREE_TYPE (ARG)) == BOOLEAN_TYPE \
9107 /* Folding may create 0 or 1 integers from other expressions. */ \
9108 || ((CODE) != INTEGER_CST \
9109 && (integer_onep (ARG) || integer_zerop (ARG))))
9110
48e1416a 9111 switch (code)
e534436e 9112 {
82012ffe 9113 case LSHIFT_EXPR:
9114 if (code_left == PLUS_EXPR || code_right == PLUS_EXPR)
e534436e 9115 warning (OPT_Wparentheses,
82012ffe 9116 "suggest parentheses around %<+%> inside %<<<%>");
9117 else if (code_left == MINUS_EXPR || code_right == MINUS_EXPR)
9118 warning (OPT_Wparentheses,
9119 "suggest parentheses around %<-%> inside %<<<%>");
9120 return;
e534436e 9121
82012ffe 9122 case RSHIFT_EXPR:
9123 if (code_left == PLUS_EXPR || code_right == PLUS_EXPR)
e534436e 9124 warning (OPT_Wparentheses,
82012ffe 9125 "suggest parentheses around %<+%> inside %<>>%>");
9126 else if (code_left == MINUS_EXPR || code_right == MINUS_EXPR)
9127 warning (OPT_Wparentheses,
9128 "suggest parentheses around %<-%> inside %<>>%>");
9129 return;
e534436e 9130
82012ffe 9131 case TRUTH_ORIF_EXPR:
9132 if (code_left == TRUTH_ANDIF_EXPR || code_right == TRUTH_ANDIF_EXPR)
9133 warning (OPT_Wparentheses,
9134 "suggest parentheses around %<&&%> within %<||%>");
9135 return;
9136
9137 case BIT_IOR_EXPR:
e534436e 9138 if (code_left == BIT_AND_EXPR || code_left == BIT_XOR_EXPR
9139 || code_left == PLUS_EXPR || code_left == MINUS_EXPR
9140 || code_right == BIT_AND_EXPR || code_right == BIT_XOR_EXPR
9141 || code_right == PLUS_EXPR || code_right == MINUS_EXPR)
9142 warning (OPT_Wparentheses,
82012ffe 9143 "suggest parentheses around arithmetic in operand of %<|%>");
e534436e 9144 /* Check cases like x|y==z */
82012ffe 9145 else if (TREE_CODE_CLASS (code_left) == tcc_comparison
9146 || TREE_CODE_CLASS (code_right) == tcc_comparison)
e534436e 9147 warning (OPT_Wparentheses,
82012ffe 9148 "suggest parentheses around comparison in operand of %<|%>");
9149 /* Check cases like !x | y */
9150 else if (code_left == TRUTH_NOT_EXPR
9151 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right, arg_right))
96bda40f 9152 warning (OPT_Wparentheses, "suggest parentheses around operand of "
82012ffe 9153 "%<!%> or change %<|%> to %<||%> or %<!%> to %<~%>");
9154 return;
e534436e 9155
82012ffe 9156 case BIT_XOR_EXPR:
e534436e 9157 if (code_left == BIT_AND_EXPR
9158 || code_left == PLUS_EXPR || code_left == MINUS_EXPR
9159 || code_right == BIT_AND_EXPR
9160 || code_right == PLUS_EXPR || code_right == MINUS_EXPR)
9161 warning (OPT_Wparentheses,
82012ffe 9162 "suggest parentheses around arithmetic in operand of %<^%>");
e534436e 9163 /* Check cases like x^y==z */
82012ffe 9164 else if (TREE_CODE_CLASS (code_left) == tcc_comparison
9165 || TREE_CODE_CLASS (code_right) == tcc_comparison)
e534436e 9166 warning (OPT_Wparentheses,
82012ffe 9167 "suggest parentheses around comparison in operand of %<^%>");
9168 return;
e534436e 9169
82012ffe 9170 case BIT_AND_EXPR:
9171 if (code_left == PLUS_EXPR || code_right == PLUS_EXPR)
9172 warning (OPT_Wparentheses,
9173 "suggest parentheses around %<+%> in operand of %<&%>");
9174 else if (code_left == MINUS_EXPR || code_right == MINUS_EXPR)
e534436e 9175 warning (OPT_Wparentheses,
82012ffe 9176 "suggest parentheses around %<-%> in operand of %<&%>");
e534436e 9177 /* Check cases like x&y==z */
82012ffe 9178 else if (TREE_CODE_CLASS (code_left) == tcc_comparison
9179 || TREE_CODE_CLASS (code_right) == tcc_comparison)
e534436e 9180 warning (OPT_Wparentheses,
82012ffe 9181 "suggest parentheses around comparison in operand of %<&%>");
9182 /* Check cases like !x & y */
9183 else if (code_left == TRUTH_NOT_EXPR
9184 && !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right, arg_right))
96bda40f 9185 warning (OPT_Wparentheses, "suggest parentheses around operand of "
82012ffe 9186 "%<!%> or change %<&%> to %<&&%> or %<!%> to %<~%>");
9187 return;
e534436e 9188
82012ffe 9189 case EQ_EXPR:
6ce0c450 9190 if (TREE_CODE_CLASS (code_left) == tcc_comparison
9191 || TREE_CODE_CLASS (code_right) == tcc_comparison)
9192 warning (OPT_Wparentheses,
82012ffe 9193 "suggest parentheses around comparison in operand of %<==%>");
9194 return;
9195 case NE_EXPR:
9196 if (TREE_CODE_CLASS (code_left) == tcc_comparison
9197 || TREE_CODE_CLASS (code_right) == tcc_comparison)
9198 warning (OPT_Wparentheses,
9199 "suggest parentheses around comparison in operand of %<!=%>");
9200 return;
9201
9202 default:
9203 if (TREE_CODE_CLASS (code) == tcc_comparison
9204 && ((TREE_CODE_CLASS (code_left) == tcc_comparison
269f7979 9205 && code_left != NE_EXPR && code_left != EQ_EXPR
9206 && INTEGRAL_TYPE_P (TREE_TYPE (arg_left)))
82012ffe 9207 || (TREE_CODE_CLASS (code_right) == tcc_comparison
269f7979 9208 && code_right != NE_EXPR && code_right != EQ_EXPR
9209 && INTEGRAL_TYPE_P (TREE_TYPE (arg_right)))))
82012ffe 9210 warning (OPT_Wparentheses, "comparisons like %<X<=Y<=Z%> do not "
6ce0c450 9211 "have their mathematical meaning");
82012ffe 9212 return;
6ce0c450 9213 }
82012ffe 9214#undef NOT_A_BOOLEAN_EXPR_P
e534436e 9215}
9216
92fccaaa 9217/* If LABEL (a LABEL_DECL) has not been used, issue a warning. */
9218
9219void
9220warn_for_unused_label (tree label)
9221{
9222 if (!TREE_USED (label))
9223 {
9224 if (DECL_INITIAL (label))
9225 warning (OPT_Wunused_label, "label %q+D defined but not used", label);
9226 else
9227 warning (OPT_Wunused_label, "label %q+D declared but not defined", label);
9228 }
9229}
2840aae4 9230
b9fc964a 9231#ifndef TARGET_HAS_TARGETCM
9232struct gcc_targetcm targetcm = TARGETCM_INITIALIZER;
9233#endif
9234
b6889cb0 9235/* Warn for division by zero according to the value of DIVISOR. LOC
9236 is the location of the division operator. */
f092582b 9237
9238void
b6889cb0 9239warn_for_div_by_zero (location_t loc, tree divisor)
f092582b 9240{
9421ebb9 9241 /* If DIVISOR is zero, and has integral or fixed-point type, issue a warning
9242 about division by zero. Do not issue a warning if DIVISOR has a
f092582b 9243 floating-point type, since we consider 0.0/0.0 a valid way of
9244 generating a NaN. */
48d94ede 9245 if (c_inhibit_evaluation_warnings == 0
9421ebb9 9246 && (integer_zerop (divisor) || fixed_zerop (divisor)))
b6889cb0 9247 warning_at (loc, OPT_Wdiv_by_zero, "division by zero");
f092582b 9248}
9249
13869a99 9250/* Subroutine of build_binary_op. Give warnings for comparisons
9251 between signed and unsigned quantities that may fail. Do the
9252 checking based on the original operand trees ORIG_OP0 and ORIG_OP1,
9253 so that casts will be considered, but default promotions won't
8e70fb09 9254 be.
9255
9256 LOCATION is the location of the comparison operator.
13869a99 9257
9258 The arguments of this function map directly to local variables
9259 of build_binary_op. */
9260
48e1416a 9261void
8e70fb09 9262warn_for_sign_compare (location_t location,
48e1416a 9263 tree orig_op0, tree orig_op1,
9264 tree op0, tree op1,
13869a99 9265 tree result_type, enum tree_code resultcode)
9266{
9267 int op0_signed = !TYPE_UNSIGNED (TREE_TYPE (orig_op0));
9268 int op1_signed = !TYPE_UNSIGNED (TREE_TYPE (orig_op1));
9269 int unsignedp0, unsignedp1;
48e1416a 9270
13869a99 9271 /* In C++, check for comparison of different enum types. */
9272 if (c_dialect_cxx()
9273 && TREE_CODE (TREE_TYPE (orig_op0)) == ENUMERAL_TYPE
9274 && TREE_CODE (TREE_TYPE (orig_op1)) == ENUMERAL_TYPE
9275 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0))
895b662f 9276 != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1)))
13869a99 9277 {
8e70fb09 9278 warning_at (location,
9279 OPT_Wsign_compare, "comparison between types %qT and %qT",
9280 TREE_TYPE (orig_op0), TREE_TYPE (orig_op1));
13869a99 9281 }
9282
9283 /* Do not warn if the comparison is being done in a signed type,
9284 since the signed type will only be chosen if it can represent
9285 all the values of the unsigned type. */
9286 if (!TYPE_UNSIGNED (result_type))
9287 /* OK */;
9288 /* Do not warn if both operands are unsigned. */
9289 else if (op0_signed == op1_signed)
9290 /* OK */;
9291 else
9292 {
895b662f 9293 tree sop, uop, base_type;
13869a99 9294 bool ovf;
895b662f 9295
13869a99 9296 if (op0_signed)
9297 sop = orig_op0, uop = orig_op1;
48e1416a 9298 else
13869a99 9299 sop = orig_op1, uop = orig_op0;
9300
48e1416a 9301 STRIP_TYPE_NOPS (sop);
13869a99 9302 STRIP_TYPE_NOPS (uop);
895b662f 9303 base_type = (TREE_CODE (result_type) == COMPLEX_TYPE
9304 ? TREE_TYPE (result_type) : result_type);
13869a99 9305
9306 /* Do not warn if the signed quantity is an unsuffixed integer
9307 literal (or some static constant expression involving such
9308 literals or a conditional expression involving such literals)
9309 and it is non-negative. */
9310 if (tree_expr_nonnegative_warnv_p (sop, &ovf))
9311 /* OK */;
9312 /* Do not warn if the comparison is an equality operation, the
9313 unsigned quantity is an integral constant, and it would fit
9314 in the result if the result were signed. */
9315 else if (TREE_CODE (uop) == INTEGER_CST
9316 && (resultcode == EQ_EXPR || resultcode == NE_EXPR)
895b662f 9317 && int_fits_type_p (uop, c_common_signed_type (base_type)))
13869a99 9318 /* OK */;
9319 /* In C, do not warn if the unsigned quantity is an enumeration
9320 constant and its maximum value would fit in the result if the
9321 result were signed. */
9322 else if (!c_dialect_cxx() && TREE_CODE (uop) == INTEGER_CST
9323 && TREE_CODE (TREE_TYPE (uop)) == ENUMERAL_TYPE
9324 && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (uop)),
895b662f 9325 c_common_signed_type (base_type)))
13869a99 9326 /* OK */;
48e1416a 9327 else
8e70fb09 9328 warning_at (location,
48e1416a 9329 OPT_Wsign_compare,
8e70fb09 9330 "comparison between signed and unsigned integer expressions");
13869a99 9331 }
48e1416a 9332
13869a99 9333 /* Warn if two unsigned values are being compared in a size larger
9334 than their original size, and one (and only one) is the result of
9335 a `~' operator. This comparison will always fail.
48e1416a 9336
13869a99 9337 Also warn if one operand is a constant, and the constant does not
9338 have all bits set that are set in the ~ operand when it is
9339 extended. */
9340
9341 op0 = get_narrower (op0, &unsignedp0);
9342 op1 = get_narrower (op1, &unsignedp1);
48e1416a 9343
13869a99 9344 if ((TREE_CODE (op0) == BIT_NOT_EXPR)
9345 ^ (TREE_CODE (op1) == BIT_NOT_EXPR))
9346 {
9347 if (TREE_CODE (op0) == BIT_NOT_EXPR)
9348 op0 = get_narrower (TREE_OPERAND (op0, 0), &unsignedp0);
9349 if (TREE_CODE (op1) == BIT_NOT_EXPR)
9350 op1 = get_narrower (TREE_OPERAND (op1, 0), &unsignedp1);
9351
9352 if (host_integerp (op0, 0) || host_integerp (op1, 0))
9353 {
9354 tree primop;
9355 HOST_WIDE_INT constant, mask;
9356 int unsignedp;
9357 unsigned int bits;
48e1416a 9358
13869a99 9359 if (host_integerp (op0, 0))
9360 {
9361 primop = op1;
9362 unsignedp = unsignedp1;
9363 constant = tree_low_cst (op0, 0);
9364 }
9365 else
9366 {
9367 primop = op0;
9368 unsignedp = unsignedp0;
9369 constant = tree_low_cst (op1, 0);
9370 }
48e1416a 9371
13869a99 9372 bits = TYPE_PRECISION (TREE_TYPE (primop));
9373 if (bits < TYPE_PRECISION (result_type)
9374 && bits < HOST_BITS_PER_LONG && unsignedp)
9375 {
9376 mask = (~ (HOST_WIDE_INT) 0) << bits;
9377 if ((mask & constant) != mask)
9378 {
9379 if (constant == 0)
48e1416a 9380 warning (OPT_Wsign_compare,
13869a99 9381 "promoted ~unsigned is always non-zero");
9382 else
48e1416a 9383 warning_at (location, OPT_Wsign_compare,
8e70fb09 9384 "comparison of promoted ~unsigned with constant");
13869a99 9385 }
9386 }
9387 }
9388 else if (unsignedp0 && unsignedp1
9389 && (TYPE_PRECISION (TREE_TYPE (op0))
9390 < TYPE_PRECISION (result_type))
9391 && (TYPE_PRECISION (TREE_TYPE (op1))
9392 < TYPE_PRECISION (result_type)))
8e70fb09 9393 warning_at (location, OPT_Wsign_compare,
13869a99 9394 "comparison of promoted ~unsigned with unsigned");
9395 }
9396}
9397
5ba33bf4 9398/* RESULT_TYPE is the result of converting TYPE1 and TYPE2 to a common
9399 type via c_common_type. If -Wdouble-promotion is in use, and the
9400 conditions for warning have been met, issue a warning. GMSGID is
9401 the warning message. It must have two %T specifiers for the type
9402 that was converted (generally "float") and the type to which it was
9403 converted (generally "double), respectively. LOC is the location
9404 to which the awrning should refer. */
9405
9406void
9407do_warn_double_promotion (tree result_type, tree type1, tree type2,
9408 const char *gmsgid, location_t loc)
9409{
9410 tree source_type;
9411
9412 if (!warn_double_promotion)
9413 return;
9414 /* If the conversion will not occur at run-time, there is no need to
9415 warn about it. */
9416 if (c_inhibit_evaluation_warnings)
9417 return;
9418 if (TYPE_MAIN_VARIANT (result_type) != double_type_node
9419 && TYPE_MAIN_VARIANT (result_type) != complex_double_type_node)
9420 return;
9421 if (TYPE_MAIN_VARIANT (type1) == float_type_node
9422 || TYPE_MAIN_VARIANT (type1) == complex_float_type_node)
9423 source_type = type1;
9424 else if (TYPE_MAIN_VARIANT (type2) == float_type_node
9425 || TYPE_MAIN_VARIANT (type2) == complex_float_type_node)
9426 source_type = type2;
9427 else
9428 return;
9429 warning_at (loc, OPT_Wdouble_promotion, gmsgid, source_type, result_type);
9430}
9431
41771881 9432/* Setup a TYPE_DECL node as a typedef representation.
9433
9434 X is a TYPE_DECL for a typedef statement. Create a brand new
9435 ..._TYPE node (which will be just a variant of the existing
9436 ..._TYPE node with identical properties) and then install X
9437 as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
9438
9439 The whole point here is to end up with a situation where each
9440 and every ..._TYPE node the compiler creates will be uniquely
9441 associated with AT MOST one node representing a typedef name.
9442 This way, even though the compiler substitutes corresponding
9443 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
9444 early on, later parts of the compiler can always do the reverse
9445 translation and get back the corresponding typedef name. For
9446 example, given:
9447
9448 typedef struct S MY_TYPE;
9449 MY_TYPE object;
9450
9451 Later parts of the compiler might only know that `object' was of
9452 type `struct S' if it were not for code just below. With this
9453 code however, later parts of the compiler see something like:
9454
9455 struct S' == struct S
9456 typedef struct S' MY_TYPE;
9457 struct S' object;
9458
9459 And they can then deduce (from the node for type struct S') that
9460 the original object declaration was:
9461
9462 MY_TYPE object;
9463
9464 Being able to do this is important for proper support of protoize,
9465 and also for generating precise symbolic debugging information
9466 which takes full account of the programmer's (typedef) vocabulary.
9467
9468 Obviously, we don't want to generate a duplicate ..._TYPE node if
9469 the TYPE_DECL node that we are now processing really represents a
9470 standard built-in type. */
9471
9472void
9473set_underlying_type (tree x)
9474{
9475 if (x == error_mark_node)
9476 return;
9477 if (DECL_IS_BUILTIN (x))
9478 {
9479 if (TYPE_NAME (TREE_TYPE (x)) == 0)
9480 TYPE_NAME (TREE_TYPE (x)) = x;
9481 }
9482 else if (TREE_TYPE (x) != error_mark_node
9483 && DECL_ORIGINAL_TYPE (x) == NULL_TREE)
9484 {
9485 tree tt = TREE_TYPE (x);
9486 DECL_ORIGINAL_TYPE (x) = tt;
9487 tt = build_variant_type_copy (tt);
9488 TYPE_STUB_DECL (tt) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x));
9489 TYPE_NAME (tt) = x;
9490 TREE_USED (tt) = TREE_USED (x);
9491 TREE_TYPE (x) = tt;
9492 }
9493}
9494
1a4c44c5 9495/* Record the types used by the current global variable declaration
9496 being parsed, so that we can decide later to emit their debug info.
9497 Those types are in types_used_by_cur_var_decl, and we are going to
9498 store them in the types_used_by_vars_hash hash table.
9499 DECL is the declaration of the global variable that has been parsed. */
9500
9501void
9502record_types_used_by_current_var_decl (tree decl)
9503{
9504 gcc_assert (decl && DECL_P (decl) && TREE_STATIC (decl));
9505
aef48c9a 9506 while (!VEC_empty (tree, types_used_by_cur_var_decl))
1a4c44c5 9507 {
aef48c9a 9508 tree type = VEC_pop (tree, types_used_by_cur_var_decl);
9509 types_used_by_var_decl_insert (type, decl);
1a4c44c5 9510 }
9511}
9512
f352a3fb 9513/* The C and C++ parsers both use vectors to hold function arguments.
9514 For efficiency, we keep a cache of unused vectors. This is the
9515 cache. */
9516
9517typedef VEC(tree,gc)* tree_gc_vec;
9518DEF_VEC_P(tree_gc_vec);
9519DEF_VEC_ALLOC_P(tree_gc_vec,gc);
9520static GTY((deletable)) VEC(tree_gc_vec,gc) *tree_vector_cache;
9521
9522/* Return a new vector from the cache. If the cache is empty,
9523 allocate a new vector. These vectors are GC'ed, so it is OK if the
9524 pointer is not released.. */
9525
9526VEC(tree,gc) *
9527make_tree_vector (void)
9528{
9529 if (!VEC_empty (tree_gc_vec, tree_vector_cache))
9530 return VEC_pop (tree_gc_vec, tree_vector_cache);
9531 else
9532 {
9533 /* Passing 0 to VEC_alloc returns NULL, and our callers require
9534 that we always return a non-NULL value. The vector code uses
9535 4 when growing a NULL vector, so we do too. */
9536 return VEC_alloc (tree, gc, 4);
9537 }
9538}
9539
9540/* Release a vector of trees back to the cache. */
9541
9542void
9543release_tree_vector (VEC(tree,gc) *vec)
9544{
9545 if (vec != NULL)
9546 {
9547 VEC_truncate (tree, vec, 0);
9548 VEC_safe_push (tree_gc_vec, gc, tree_vector_cache, vec);
9549 }
9550}
9551
9552/* Get a new tree vector holding a single tree. */
9553
9554VEC(tree,gc) *
9555make_tree_vector_single (tree t)
9556{
9557 VEC(tree,gc) *ret = make_tree_vector ();
9558 VEC_quick_push (tree, ret, t);
9559 return ret;
9560}
9561
9562/* Get a new tree vector which is a copy of an existing one. */
9563
9564VEC(tree,gc) *
9565make_tree_vector_copy (const VEC(tree,gc) *orig)
9566{
9567 VEC(tree,gc) *ret;
9568 unsigned int ix;
9569 tree t;
9570
9571 ret = make_tree_vector ();
9572 VEC_reserve (tree, gc, ret, VEC_length (tree, orig));
48148244 9573 FOR_EACH_VEC_ELT (tree, orig, ix, t)
f352a3fb 9574 VEC_quick_push (tree, ret, t);
9575 return ret;
9576}
9577
a9ffdd35 9578/* Return true if KEYWORD starts a type specifier. */
9579
9580bool
9581keyword_begins_type_specifier (enum rid keyword)
9582{
9583 switch (keyword)
9584 {
9585 case RID_INT:
9586 case RID_CHAR:
9587 case RID_FLOAT:
9588 case RID_DOUBLE:
9589 case RID_VOID:
9590 case RID_INT128:
9591 case RID_UNSIGNED:
9592 case RID_LONG:
9593 case RID_SHORT:
9594 case RID_SIGNED:
9595 case RID_DFLOAT32:
9596 case RID_DFLOAT64:
9597 case RID_DFLOAT128:
9598 case RID_FRACT:
9599 case RID_ACCUM:
9600 case RID_BOOL:
9601 case RID_WCHAR:
9602 case RID_CHAR16:
9603 case RID_CHAR32:
9604 case RID_SAT:
9605 case RID_COMPLEX:
9606 case RID_TYPEOF:
9607 case RID_STRUCT:
9608 case RID_CLASS:
9609 case RID_UNION:
9610 case RID_ENUM:
9611 return true;
9612 default:
9613 return false;
9614 }
9615}
9616
9617/* Return true if KEYWORD names a type qualifier. */
9618
9619bool
9620keyword_is_type_qualifier (enum rid keyword)
9621{
9622 switch (keyword)
9623 {
9624 case RID_CONST:
9625 case RID_VOLATILE:
9626 case RID_RESTRICT:
9627 return true;
9628 default:
9629 return false;
9630 }
9631}
9632
9633/* Return true if KEYWORD names a storage class specifier.
9634
9635 RID_TYPEDEF is not included in this list despite `typedef' being
9636 listed in C99 6.7.1.1. 6.7.1.3 indicates that `typedef' is listed as
9637 such for syntactic convenience only. */
9638
9639bool
9640keyword_is_storage_class_specifier (enum rid keyword)
9641{
9642 switch (keyword)
9643 {
9644 case RID_STATIC:
9645 case RID_EXTERN:
9646 case RID_REGISTER:
9647 case RID_AUTO:
9648 case RID_MUTABLE:
9649 case RID_THREAD:
9650 return true;
9651 default:
9652 return false;
9653 }
9654}
9655
7bedc3a0 9656#include "gt-c-family-c-common.h"