1 /* Subroutines shared by all languages that are variants of C.
2 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* FIXME: Still need to include rtl.h here (via expr.h) in a front-end file.
23 Pretend this is a back-end file. */
24 #undef IN_GCC_FRONTEND
28 #include "coretypes.h"
41 #include "langhooks.h"
42 #include "tree-inline.h"
44 #include "diagnostic.h"
45 #include "tree-iterator.h"
47 #include "tree-mudflap.h"
50 #include "target-def.h"
53 #include "expr.h" /* For vector_mode_valid_p */
55 /* FIXME: Needed for TARGET_ENUM_VA_LIST, which should be a target hook. */
58 cpp_reader *parse_in; /* Declared in c-pragma.h. */
60 /* The following symbols are subsumed in the c_global_trees array, and
61 listed here individually for documentation purposes.
63 INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
65 tree short_integer_type_node;
66 tree long_integer_type_node;
67 tree long_long_integer_type_node;
68 tree int128_integer_type_node;
70 tree short_unsigned_type_node;
71 tree long_unsigned_type_node;
72 tree long_long_unsigned_type_node;
73 tree int128_unsigned_type_node;
75 tree truthvalue_type_node;
76 tree truthvalue_false_node;
77 tree truthvalue_true_node;
79 tree ptrdiff_type_node;
81 tree unsigned_char_type_node;
82 tree signed_char_type_node;
85 tree char16_type_node;
86 tree char32_type_node;
89 tree double_type_node;
90 tree long_double_type_node;
92 tree complex_integer_type_node;
93 tree complex_float_type_node;
94 tree complex_double_type_node;
95 tree complex_long_double_type_node;
97 tree dfloat32_type_node;
98 tree dfloat64_type_node;
99 tree_dfloat128_type_node;
101 tree intQI_type_node;
102 tree intHI_type_node;
103 tree intSI_type_node;
104 tree intDI_type_node;
105 tree intTI_type_node;
107 tree unsigned_intQI_type_node;
108 tree unsigned_intHI_type_node;
109 tree unsigned_intSI_type_node;
110 tree unsigned_intDI_type_node;
111 tree unsigned_intTI_type_node;
113 tree widest_integer_literal_type_node;
114 tree widest_unsigned_literal_type_node;
116 Nodes for types `void *' and `const void *'.
118 tree ptr_type_node, const_ptr_type_node;
120 Nodes for types `char *' and `const char *'.
122 tree string_type_node, const_string_type_node;
124 Type `char[SOMENUMBER]'.
125 Used when an array of char is needed and the size is irrelevant.
127 tree char_array_type_node;
129 Type `int[SOMENUMBER]' or something like it.
130 Used when an array of int needed and the size is irrelevant.
132 tree int_array_type_node;
134 Type `wchar_t[SOMENUMBER]' or something like it.
135 Used when a wide string literal is created.
137 tree wchar_array_type_node;
139 Type `char16_t[SOMENUMBER]' or something like it.
140 Used when a UTF-16 string literal is created.
142 tree char16_array_type_node;
144 Type `char32_t[SOMENUMBER]' or something like it.
145 Used when a UTF-32 string literal is created.
147 tree char32_array_type_node;
149 Type `int ()' -- used for implicit declaration of functions.
151 tree default_function_type;
153 A VOID_TYPE node, packaged in a TREE_LIST.
157 The lazily created VAR_DECLs for __FUNCTION__, __PRETTY_FUNCTION__,
158 and __func__. (C doesn't generate __FUNCTION__ and__PRETTY_FUNCTION__
159 VAR_DECLS, but C++ does.)
161 tree function_name_decl_node;
162 tree pretty_function_name_decl_node;
163 tree c99_function_name_decl_node;
165 Stack of nested function name VAR_DECLs.
167 tree saved_function_name_decls;
171 tree c_global_trees[CTI_MAX];
173 /* Switches common to the C front ends. */
175 /* Nonzero if preprocessing only. */
177 int flag_preprocess_only;
179 /* Nonzero means don't output line number information. */
181 char flag_no_line_commands;
183 /* Nonzero causes -E output not to be done, but directives such as
184 #define that have side effects are still obeyed. */
188 /* Nonzero means dump macros in some fashion. */
190 char flag_dump_macros;
192 /* Nonzero means pass #include lines through to the output. */
194 char flag_dump_includes;
196 /* Nonzero means process PCH files while preprocessing. */
198 bool flag_pch_preprocess;
200 /* The file name to which we should write a precompiled header, or
201 NULL if no header will be written in this compile. */
203 const char *pch_file;
205 /* Nonzero if an ISO standard was selected. It rejects macros in the
209 /* Nonzero if -undef was given. It suppresses target built-in macros
213 /* Nonzero means don't recognize the non-ANSI builtin functions. */
217 /* Nonzero means don't recognize the non-ANSI builtin functions.
220 int flag_no_nonansi_builtin;
222 /* Nonzero means give `double' the same size as `float'. */
224 int flag_short_double;
226 /* Nonzero means give `wchar_t' the same size as `short'. */
228 int flag_short_wchar;
230 /* Nonzero means allow implicit conversions between vectors with
231 differing numbers of subparts and/or differing element types. */
232 int flag_lax_vector_conversions;
234 /* Nonzero means allow Microsoft extensions without warnings or errors. */
235 int flag_ms_extensions;
237 /* Nonzero means don't recognize the keyword `asm'. */
241 /* Nonzero means to treat bitfields as signed unless they say `unsigned'. */
243 int flag_signed_bitfields = 1;
245 /* Warn about #pragma directives that are not recognized. */
247 int warn_unknown_pragmas; /* Tri state variable. */
249 /* Warn about format/argument anomalies in calls to formatted I/O functions
250 (*printf, *scanf, strftime, strfmon, etc.). */
254 /* Warn about using __null (as NULL in C++) as sentinel. For code compiled
255 with GCC this doesn't matter as __null is guaranteed to have the right
258 int warn_strict_null_sentinel;
260 /* Zero means that faster, ...NonNil variants of objc_msgSend...
261 calls will be used in ObjC; passing nil receivers to such calls
262 will most likely result in crashes. */
263 int flag_nil_receivers = 1;
265 /* Nonzero means that code generation will be altered to support
266 "zero-link" execution. This currently affects ObjC only, but may
267 affect other languages in the future. */
268 int flag_zero_link = 0;
270 /* Nonzero means emit an '__OBJC, __image_info' for the current translation
271 unit. It will inform the ObjC runtime that class definition(s) herein
272 contained are to replace one(s) previously loaded. */
273 int flag_replace_objc_classes = 0;
275 /* C/ObjC language option variables. */
278 /* Nonzero means allow type mismatches in conditional expressions;
279 just make their values `void'. */
281 int flag_cond_mismatch;
283 /* Nonzero means enable C89 Amendment 1 features. */
287 /* Nonzero means use the ISO C99 (or C1X) dialect of C. */
291 /* Nonzero means use the ISO C1X dialect of C. */
295 /* Nonzero means that we have builtin functions, and main is an int. */
300 /* ObjC language option variables. */
303 /* Open and close the file for outputting class declarations, if
306 int flag_gen_declaration;
308 /* Tells the compiler that this is a special run. Do not perform any
309 compiling, instead we are to test some platform dependent features
310 and output a C header file with appropriate definitions. */
312 int print_struct_values;
314 /* Tells the compiler what is the constant string class for ObjC. */
316 const char *constant_string_class_name;
319 /* C++ language option variables. */
322 /* Nonzero means don't recognize any extension keywords. */
324 int flag_no_gnu_keywords;
326 /* Nonzero means do emit exported implementations of functions even if
327 they can be inlined. */
329 int flag_implement_inlines = 1;
331 /* Nonzero means that implicit instantiations will be emitted if needed. */
333 int flag_implicit_templates = 1;
335 /* Nonzero means that implicit instantiations of inline templates will be
336 emitted if needed, even if instantiations of non-inline templates
339 int flag_implicit_inline_templates = 1;
341 /* Nonzero means generate separate instantiation control files and
342 juggle them at link time. */
344 int flag_use_repository;
346 /* Nonzero if we want to issue diagnostics that the standard says are not
349 int flag_optional_diags = 1;
351 /* Nonzero means we should attempt to elide constructors when possible. */
353 int flag_elide_constructors = 1;
355 /* Nonzero means that member functions defined in class scope are
356 inline by default. */
358 int flag_default_inline = 1;
360 /* Controls whether compiler generates 'type descriptor' that give
361 run-time type information. */
365 /* Nonzero if we want to conserve space in the .o files. We do this
366 by putting uninitialized data and runtime initialized data into
367 .common instead of .data at the expense of not flagging multiple
370 int flag_conserve_space;
372 /* Nonzero if we want to obey access control semantics. */
374 int flag_access_control = 1;
376 /* Nonzero if we want to check the return value of new and avoid calling
377 constructors if it is a null pointer. */
381 /* The C++ dialect being used. C++98 is the default. */
383 enum cxx_dialect cxx_dialect = cxx98;
385 /* Nonzero if we want the new ISO rules for pushing a new scope for `for'
386 initialization variables.
387 0: Old rules, set by -fno-for-scope.
388 2: New ISO rules, set by -ffor-scope.
389 1: Try to implement new ISO rules, but with backup compatibility
390 (and warnings). This is the default, for now. */
392 int flag_new_for_scope = 1;
394 /* Nonzero if we want to emit defined symbols with common-like linkage as
395 weak symbols where possible, in order to conform to C++ semantics.
396 Otherwise, emit them as local symbols. */
400 /* 0 means we want the preprocessor to not emit line directives for
401 the current working directory. 1 means we want it to do it. -1
402 means we should decide depending on whether debugging information
403 is being emitted or not. */
405 int flag_working_directory = -1;
407 /* Nonzero to use __cxa_atexit, rather than atexit, to register
408 destructors for local statics and global objects. '2' means it has been
409 set nonzero as a default, not by a command-line flag. */
411 int flag_use_cxa_atexit = DEFAULT_USE_CXA_ATEXIT;
413 /* Nonzero to use __cxa_get_exception_ptr in C++ exception-handling
414 code. '2' means it has not been set explicitly on the command line. */
416 int flag_use_cxa_get_exception_ptr = 2;
418 /* Nonzero means to implement standard semantics for exception
419 specifications, calling unexpected if an exception is thrown that
420 doesn't match the specification. Zero means to treat them as
421 assertions and optimize accordingly, but not check them. */
423 int flag_enforce_eh_specs = 1;
425 /* Nonzero means to generate thread-safe code for initializing local
428 int flag_threadsafe_statics = 1;
430 /* Nonzero if we want to pretty-print template specializations as the
431 template signature followed by the arguments. */
433 int flag_pretty_templates = 1;
435 /* Maximum template instantiation depth. This limit exists to limit the
436 time it takes to notice infinite template instantiations; the default
437 value of 1024 is likely to be in the next C++ standard. */
439 int max_tinst_depth = 1024;
443 /* The elements of `ridpointers' are identifier nodes for the reserved
444 type names and storage classes. It is indexed by a RID_... value. */
447 tree (*make_fname_decl) (location_t, tree, int);
449 /* Nonzero means don't warn about problems that occur when the code is
451 int c_inhibit_evaluation_warnings;
453 /* Whether lexing has been completed, so subsequent preprocessor
454 errors should use the compiler's input_location. */
455 bool done_lexing = false;
457 /* Information about how a function name is generated. */
460 tree *const decl; /* pointer to the VAR_DECL. */
461 const unsigned rid; /* RID number for the identifier. */
462 const int pretty; /* How pretty is it? */
465 /* The three ways of getting then name of the current function. */
467 const struct fname_var_t fname_vars[] =
469 /* C99 compliant __func__, must be first. */
470 {&c99_function_name_decl_node, RID_C99_FUNCTION_NAME, 0},
471 /* GCC __FUNCTION__ compliant. */
472 {&function_name_decl_node, RID_FUNCTION_NAME, 0},
473 /* GCC __PRETTY_FUNCTION__ compliant. */
474 {&pretty_function_name_decl_node, RID_PRETTY_FUNCTION_NAME, 1},
478 static tree c_fully_fold_internal (tree expr, bool, bool *, bool *);
479 static tree check_case_value (tree);
480 static bool check_case_bounds (tree, tree, tree *, tree *);
482 static tree handle_packed_attribute (tree *, tree, tree, int, bool *);
483 static tree handle_nocommon_attribute (tree *, tree, tree, int, bool *);
484 static tree handle_common_attribute (tree *, tree, tree, int, bool *);
485 static tree handle_noreturn_attribute (tree *, tree, tree, int, bool *);
486 static tree handle_hot_attribute (tree *, tree, tree, int, bool *);
487 static tree handle_cold_attribute (tree *, tree, tree, int, bool *);
488 static tree handle_noinline_attribute (tree *, tree, tree, int, bool *);
489 static tree handle_noclone_attribute (tree *, tree, tree, int, bool *);
490 static tree handle_always_inline_attribute (tree *, tree, tree, int,
492 static tree handle_gnu_inline_attribute (tree *, tree, tree, int, bool *);
493 static tree handle_artificial_attribute (tree *, tree, tree, int, bool *);
494 static tree handle_flatten_attribute (tree *, tree, tree, int, bool *);
495 static tree handle_error_attribute (tree *, tree, tree, int, bool *);
496 static tree handle_used_attribute (tree *, tree, tree, int, bool *);
497 static tree handle_unused_attribute (tree *, tree, tree, int, bool *);
498 static tree handle_externally_visible_attribute (tree *, tree, tree, int,
500 static tree handle_const_attribute (tree *, tree, tree, int, bool *);
501 static tree handle_transparent_union_attribute (tree *, tree, tree,
503 static tree handle_constructor_attribute (tree *, tree, tree, int, bool *);
504 static tree handle_destructor_attribute (tree *, tree, tree, int, bool *);
505 static tree handle_mode_attribute (tree *, tree, tree, int, bool *);
506 static tree handle_section_attribute (tree *, tree, tree, int, bool *);
507 static tree handle_aligned_attribute (tree *, tree, tree, int, bool *);
508 static tree handle_weak_attribute (tree *, tree, tree, int, bool *) ;
509 static tree handle_alias_attribute (tree *, tree, tree, int, bool *);
510 static tree handle_weakref_attribute (tree *, tree, tree, int, bool *) ;
511 static tree handle_visibility_attribute (tree *, tree, tree, int,
513 static tree handle_tls_model_attribute (tree *, tree, tree, int,
515 static tree handle_no_instrument_function_attribute (tree *, tree,
517 static tree handle_malloc_attribute (tree *, tree, tree, int, bool *);
518 static tree handle_returns_twice_attribute (tree *, tree, tree, int, bool *);
519 static tree handle_no_limit_stack_attribute (tree *, tree, tree, int,
521 static tree handle_pure_attribute (tree *, tree, tree, int, bool *);
522 static tree handle_novops_attribute (tree *, tree, tree, int, bool *);
523 static tree handle_deprecated_attribute (tree *, tree, tree, int,
525 static tree handle_vector_size_attribute (tree *, tree, tree, int,
527 static tree handle_nonnull_attribute (tree *, tree, tree, int, bool *);
528 static tree handle_nothrow_attribute (tree *, tree, tree, int, bool *);
529 static tree handle_cleanup_attribute (tree *, tree, tree, int, bool *);
530 static tree handle_warn_unused_result_attribute (tree *, tree, tree, int,
532 static tree handle_sentinel_attribute (tree *, tree, tree, int, bool *);
533 static tree handle_type_generic_attribute (tree *, tree, tree, int, bool *);
534 static tree handle_alloc_size_attribute (tree *, tree, tree, int, bool *);
535 static tree handle_target_attribute (tree *, tree, tree, int, bool *);
536 static tree handle_optimize_attribute (tree *, tree, tree, int, bool *);
537 static tree handle_fnspec_attribute (tree *, tree, tree, int, bool *);
539 static void check_function_nonnull (tree, int, tree *);
540 static void check_nonnull_arg (void *, tree, unsigned HOST_WIDE_INT);
541 static bool nonnull_check_p (tree, unsigned HOST_WIDE_INT);
542 static bool get_nonnull_operand (tree, unsigned HOST_WIDE_INT *);
543 static int resort_field_decl_cmp (const void *, const void *);
545 /* Reserved words. The third field is a mask: keywords are disabled
546 if they match the mask.
549 C --std=c89: D_C99 | D_CXXONLY | D_OBJC | D_CXX_OBJC
550 C --std=c99: D_CXXONLY | D_OBJC
551 ObjC is like C except that D_OBJC and D_CXX_OBJC are not set
552 C++ --std=c98: D_CONLY | D_CXXOX | D_OBJC
553 C++ --std=c0x: D_CONLY | D_OBJC
554 ObjC++ is like C++ except that D_OBJC is not set
556 If -fno-asm is used, D_ASM is added to the mask. If
557 -fno-gnu-keywords is used, D_EXT is added. If -fno-asm and C in
558 C89 mode, D_EXT89 is added for both -fno-asm and -fno-gnu-keywords.
559 In C with -Wc++-compat, we warn if D_CXXWARN is set. */
561 const struct c_common_resword c_common_reswords[] =
563 { "_Bool", RID_BOOL, D_CONLY },
564 { "_Complex", RID_COMPLEX, 0 },
565 { "_Imaginary", RID_IMAGINARY, D_CONLY },
566 { "_Decimal32", RID_DFLOAT32, D_CONLY | D_EXT },
567 { "_Decimal64", RID_DFLOAT64, D_CONLY | D_EXT },
568 { "_Decimal128", RID_DFLOAT128, D_CONLY | D_EXT },
569 { "_Fract", RID_FRACT, D_CONLY | D_EXT },
570 { "_Accum", RID_ACCUM, D_CONLY | D_EXT },
571 { "_Sat", RID_SAT, D_CONLY | D_EXT },
572 { "_Static_assert", RID_STATIC_ASSERT, D_CONLY },
573 { "__FUNCTION__", RID_FUNCTION_NAME, 0 },
574 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
575 { "__alignof", RID_ALIGNOF, 0 },
576 { "__alignof__", RID_ALIGNOF, 0 },
577 { "__asm", RID_ASM, 0 },
578 { "__asm__", RID_ASM, 0 },
579 { "__attribute", RID_ATTRIBUTE, 0 },
580 { "__attribute__", RID_ATTRIBUTE, 0 },
581 { "__builtin_choose_expr", RID_CHOOSE_EXPR, D_CONLY },
582 { "__builtin_offsetof", RID_OFFSETOF, 0 },
583 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, D_CONLY },
584 { "__builtin_va_arg", RID_VA_ARG, 0 },
585 { "__complex", RID_COMPLEX, 0 },
586 { "__complex__", RID_COMPLEX, 0 },
587 { "__const", RID_CONST, 0 },
588 { "__const__", RID_CONST, 0 },
589 { "__decltype", RID_DECLTYPE, D_CXXONLY },
590 { "__extension__", RID_EXTENSION, 0 },
591 { "__func__", RID_C99_FUNCTION_NAME, 0 },
592 { "__has_nothrow_assign", RID_HAS_NOTHROW_ASSIGN, D_CXXONLY },
593 { "__has_nothrow_constructor", RID_HAS_NOTHROW_CONSTRUCTOR, D_CXXONLY },
594 { "__has_nothrow_copy", RID_HAS_NOTHROW_COPY, D_CXXONLY },
595 { "__has_trivial_assign", RID_HAS_TRIVIAL_ASSIGN, D_CXXONLY },
596 { "__has_trivial_constructor", RID_HAS_TRIVIAL_CONSTRUCTOR, D_CXXONLY },
597 { "__has_trivial_copy", RID_HAS_TRIVIAL_COPY, D_CXXONLY },
598 { "__has_trivial_destructor", RID_HAS_TRIVIAL_DESTRUCTOR, D_CXXONLY },
599 { "__has_virtual_destructor", RID_HAS_VIRTUAL_DESTRUCTOR, D_CXXONLY },
600 { "__int128", RID_INT128, 0 },
601 { "__is_abstract", RID_IS_ABSTRACT, D_CXXONLY },
602 { "__is_base_of", RID_IS_BASE_OF, D_CXXONLY },
603 { "__is_class", RID_IS_CLASS, D_CXXONLY },
604 { "__is_convertible_to", RID_IS_CONVERTIBLE_TO, D_CXXONLY },
605 { "__is_empty", RID_IS_EMPTY, D_CXXONLY },
606 { "__is_enum", RID_IS_ENUM, D_CXXONLY },
607 { "__is_pod", RID_IS_POD, D_CXXONLY },
608 { "__is_polymorphic", RID_IS_POLYMORPHIC, D_CXXONLY },
609 { "__is_standard_layout", RID_IS_STD_LAYOUT, D_CXXONLY },
610 { "__is_trivial", RID_IS_TRIVIAL, D_CXXONLY },
611 { "__is_union", RID_IS_UNION, D_CXXONLY },
612 { "__imag", RID_IMAGPART, 0 },
613 { "__imag__", RID_IMAGPART, 0 },
614 { "__inline", RID_INLINE, 0 },
615 { "__inline__", RID_INLINE, 0 },
616 { "__label__", RID_LABEL, 0 },
617 { "__null", RID_NULL, 0 },
618 { "__real", RID_REALPART, 0 },
619 { "__real__", RID_REALPART, 0 },
620 { "__restrict", RID_RESTRICT, 0 },
621 { "__restrict__", RID_RESTRICT, 0 },
622 { "__signed", RID_SIGNED, 0 },
623 { "__signed__", RID_SIGNED, 0 },
624 { "__thread", RID_THREAD, 0 },
625 { "__typeof", RID_TYPEOF, 0 },
626 { "__typeof__", RID_TYPEOF, 0 },
627 { "__volatile", RID_VOLATILE, 0 },
628 { "__volatile__", RID_VOLATILE, 0 },
629 { "alignof", RID_ALIGNOF, D_CXXONLY | D_CXX0X | D_CXXWARN },
630 { "asm", RID_ASM, D_ASM },
631 { "auto", RID_AUTO, 0 },
632 { "bool", RID_BOOL, D_CXXONLY | D_CXXWARN },
633 { "break", RID_BREAK, 0 },
634 { "case", RID_CASE, 0 },
635 { "catch", RID_CATCH, D_CXX_OBJC | D_CXXWARN },
636 { "char", RID_CHAR, 0 },
637 { "char16_t", RID_CHAR16, D_CXXONLY | D_CXX0X | D_CXXWARN },
638 { "char32_t", RID_CHAR32, D_CXXONLY | D_CXX0X | D_CXXWARN },
639 { "class", RID_CLASS, D_CXX_OBJC | D_CXXWARN },
640 { "const", RID_CONST, 0 },
641 { "constexpr", RID_CONSTEXPR, D_CXXONLY | D_CXX0X | D_CXXWARN },
642 { "const_cast", RID_CONSTCAST, D_CXXONLY | D_CXXWARN },
643 { "continue", RID_CONTINUE, 0 },
644 { "decltype", RID_DECLTYPE, D_CXXONLY | D_CXX0X | D_CXXWARN },
645 { "default", RID_DEFAULT, 0 },
646 { "delete", RID_DELETE, D_CXXONLY | D_CXXWARN },
648 { "double", RID_DOUBLE, 0 },
649 { "dynamic_cast", RID_DYNCAST, D_CXXONLY | D_CXXWARN },
650 { "else", RID_ELSE, 0 },
651 { "enum", RID_ENUM, 0 },
652 { "explicit", RID_EXPLICIT, D_CXXONLY | D_CXXWARN },
653 { "export", RID_EXPORT, D_CXXONLY | D_CXXWARN },
654 { "extern", RID_EXTERN, 0 },
655 { "false", RID_FALSE, D_CXXONLY | D_CXXWARN },
656 { "float", RID_FLOAT, 0 },
657 { "for", RID_FOR, 0 },
658 { "friend", RID_FRIEND, D_CXXONLY | D_CXXWARN },
659 { "goto", RID_GOTO, 0 },
661 { "inline", RID_INLINE, D_EXT89 },
662 { "int", RID_INT, 0 },
663 { "long", RID_LONG, 0 },
664 { "mutable", RID_MUTABLE, D_CXXONLY | D_CXXWARN },
665 { "namespace", RID_NAMESPACE, D_CXXONLY | D_CXXWARN },
666 { "new", RID_NEW, D_CXXONLY | D_CXXWARN },
667 { "nullptr", RID_NULLPTR, D_CXXONLY | D_CXX0X | D_CXXWARN },
668 { "operator", RID_OPERATOR, D_CXXONLY | D_CXXWARN },
669 { "private", RID_PRIVATE, D_CXX_OBJC | D_CXXWARN },
670 { "protected", RID_PROTECTED, D_CXX_OBJC | D_CXXWARN },
671 { "public", RID_PUBLIC, D_CXX_OBJC | D_CXXWARN },
672 { "register", RID_REGISTER, 0 },
673 { "reinterpret_cast", RID_REINTCAST, D_CXXONLY | D_CXXWARN },
674 { "restrict", RID_RESTRICT, D_CONLY | D_C99 },
675 { "return", RID_RETURN, 0 },
676 { "short", RID_SHORT, 0 },
677 { "signed", RID_SIGNED, 0 },
678 { "sizeof", RID_SIZEOF, 0 },
679 { "static", RID_STATIC, 0 },
680 { "static_assert", RID_STATIC_ASSERT, D_CXXONLY | D_CXX0X | D_CXXWARN },
681 { "static_cast", RID_STATCAST, D_CXXONLY | D_CXXWARN },
682 { "struct", RID_STRUCT, 0 },
683 { "switch", RID_SWITCH, 0 },
684 { "template", RID_TEMPLATE, D_CXXONLY | D_CXXWARN },
685 { "this", RID_THIS, D_CXXONLY | D_CXXWARN },
686 { "throw", RID_THROW, D_CXX_OBJC | D_CXXWARN },
687 { "true", RID_TRUE, D_CXXONLY | D_CXXWARN },
688 { "try", RID_TRY, D_CXX_OBJC | D_CXXWARN },
689 { "typedef", RID_TYPEDEF, 0 },
690 { "typename", RID_TYPENAME, D_CXXONLY | D_CXXWARN },
691 { "typeid", RID_TYPEID, D_CXXONLY | D_CXXWARN },
692 { "typeof", RID_TYPEOF, D_ASM | D_EXT },
693 { "union", RID_UNION, 0 },
694 { "unsigned", RID_UNSIGNED, 0 },
695 { "using", RID_USING, D_CXXONLY | D_CXXWARN },
696 { "virtual", RID_VIRTUAL, D_CXXONLY | D_CXXWARN },
697 { "void", RID_VOID, 0 },
698 { "volatile", RID_VOLATILE, 0 },
699 { "wchar_t", RID_WCHAR, D_CXXONLY },
700 { "while", RID_WHILE, 0 },
701 /* These Objective-C keywords are recognized only immediately after
703 { "compatibility_alias", RID_AT_ALIAS, D_OBJC },
704 { "defs", RID_AT_DEFS, D_OBJC },
705 { "encode", RID_AT_ENCODE, D_OBJC },
706 { "end", RID_AT_END, D_OBJC },
707 { "implementation", RID_AT_IMPLEMENTATION, D_OBJC },
708 { "interface", RID_AT_INTERFACE, D_OBJC },
709 { "protocol", RID_AT_PROTOCOL, D_OBJC },
710 { "selector", RID_AT_SELECTOR, D_OBJC },
711 { "finally", RID_AT_FINALLY, D_OBJC },
712 { "synchronized", RID_AT_SYNCHRONIZED, D_OBJC },
713 /* These are recognized only in protocol-qualifier context
715 { "bycopy", RID_BYCOPY, D_OBJC },
716 { "byref", RID_BYREF, D_OBJC },
717 { "in", RID_IN, D_OBJC },
718 { "inout", RID_INOUT, D_OBJC },
719 { "oneway", RID_ONEWAY, D_OBJC },
720 { "out", RID_OUT, D_OBJC },
723 const unsigned int num_c_common_reswords =
724 sizeof c_common_reswords / sizeof (struct c_common_resword);
726 /* Table of machine-independent attributes common to all C-like languages. */
727 const struct attribute_spec c_common_attribute_table[] =
729 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
730 { "packed", 0, 0, false, false, false,
731 handle_packed_attribute },
732 { "nocommon", 0, 0, true, false, false,
733 handle_nocommon_attribute },
734 { "common", 0, 0, true, false, false,
735 handle_common_attribute },
736 /* FIXME: logically, noreturn attributes should be listed as
737 "false, true, true" and apply to function types. But implementing this
738 would require all the places in the compiler that use TREE_THIS_VOLATILE
739 on a decl to identify non-returning functions to be located and fixed
740 to check the function type instead. */
741 { "noreturn", 0, 0, true, false, false,
742 handle_noreturn_attribute },
743 { "volatile", 0, 0, true, false, false,
744 handle_noreturn_attribute },
745 { "noinline", 0, 0, true, false, false,
746 handle_noinline_attribute },
747 { "noclone", 0, 0, true, false, false,
748 handle_noclone_attribute },
749 { "always_inline", 0, 0, true, false, false,
750 handle_always_inline_attribute },
751 { "gnu_inline", 0, 0, true, false, false,
752 handle_gnu_inline_attribute },
753 { "artificial", 0, 0, true, false, false,
754 handle_artificial_attribute },
755 { "flatten", 0, 0, true, false, false,
756 handle_flatten_attribute },
757 { "used", 0, 0, true, false, false,
758 handle_used_attribute },
759 { "unused", 0, 0, false, false, false,
760 handle_unused_attribute },
761 { "externally_visible", 0, 0, true, false, false,
762 handle_externally_visible_attribute },
763 /* The same comments as for noreturn attributes apply to const ones. */
764 { "const", 0, 0, true, false, false,
765 handle_const_attribute },
766 { "transparent_union", 0, 0, false, false, false,
767 handle_transparent_union_attribute },
768 { "constructor", 0, 1, true, false, false,
769 handle_constructor_attribute },
770 { "destructor", 0, 1, true, false, false,
771 handle_destructor_attribute },
772 { "mode", 1, 1, false, true, false,
773 handle_mode_attribute },
774 { "section", 1, 1, true, false, false,
775 handle_section_attribute },
776 { "aligned", 0, 1, false, false, false,
777 handle_aligned_attribute },
778 { "weak", 0, 0, true, false, false,
779 handle_weak_attribute },
780 { "alias", 1, 1, true, false, false,
781 handle_alias_attribute },
782 { "weakref", 0, 1, true, false, false,
783 handle_weakref_attribute },
784 { "no_instrument_function", 0, 0, true, false, false,
785 handle_no_instrument_function_attribute },
786 { "malloc", 0, 0, true, false, false,
787 handle_malloc_attribute },
788 { "returns_twice", 0, 0, true, false, false,
789 handle_returns_twice_attribute },
790 { "no_stack_limit", 0, 0, true, false, false,
791 handle_no_limit_stack_attribute },
792 { "pure", 0, 0, true, false, false,
793 handle_pure_attribute },
794 /* For internal use (marking of builtins) only. The name contains space
795 to prevent its usage in source code. */
796 { "no vops", 0, 0, true, false, false,
797 handle_novops_attribute },
798 { "deprecated", 0, 1, false, false, false,
799 handle_deprecated_attribute },
800 { "vector_size", 1, 1, false, true, false,
801 handle_vector_size_attribute },
802 { "visibility", 1, 1, false, false, false,
803 handle_visibility_attribute },
804 { "tls_model", 1, 1, true, false, false,
805 handle_tls_model_attribute },
806 { "nonnull", 0, -1, false, true, true,
807 handle_nonnull_attribute },
808 { "nothrow", 0, 0, true, false, false,
809 handle_nothrow_attribute },
810 { "may_alias", 0, 0, false, true, false, NULL },
811 { "cleanup", 1, 1, true, false, false,
812 handle_cleanup_attribute },
813 { "warn_unused_result", 0, 0, false, true, true,
814 handle_warn_unused_result_attribute },
815 { "sentinel", 0, 1, false, true, true,
816 handle_sentinel_attribute },
817 /* For internal use (marking of builtins) only. The name contains space
818 to prevent its usage in source code. */
819 { "type generic", 0, 0, false, true, true,
820 handle_type_generic_attribute },
821 { "alloc_size", 1, 2, false, true, true,
822 handle_alloc_size_attribute },
823 { "cold", 0, 0, true, false, false,
824 handle_cold_attribute },
825 { "hot", 0, 0, true, false, false,
826 handle_hot_attribute },
827 { "warning", 1, 1, true, false, false,
828 handle_error_attribute },
829 { "error", 1, 1, true, false, false,
830 handle_error_attribute },
831 { "target", 1, -1, true, false, false,
832 handle_target_attribute },
833 { "optimize", 1, -1, true, false, false,
834 handle_optimize_attribute },
835 /* For internal use (marking of builtins and runtime functions) only.
836 The name contains space to prevent its usage in source code. */
837 { "fn spec", 1, 1, false, true, true,
838 handle_fnspec_attribute },
839 { NULL, 0, 0, false, false, false, NULL }
842 /* Give the specifications for the format attributes, used by C and all
845 const struct attribute_spec c_common_format_attribute_table[] =
847 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
848 { "format", 3, 3, false, true, true,
849 handle_format_attribute },
850 { "format_arg", 1, 1, false, true, true,
851 handle_format_arg_attribute },
852 { NULL, 0, 0, false, false, false, NULL }
855 /* Return identifier for address space AS. */
858 c_addr_space_name (addr_space_t as)
860 int rid = RID_FIRST_ADDR_SPACE + as;
861 gcc_assert (ridpointers [rid]);
862 return IDENTIFIER_POINTER (ridpointers [rid]);
865 /* Push current bindings for the function name VAR_DECLS. */
868 start_fname_decls (void)
871 tree saved = NULL_TREE;
873 for (ix = 0; fname_vars[ix].decl; ix++)
875 tree decl = *fname_vars[ix].decl;
879 saved = tree_cons (decl, build_int_cst (NULL_TREE, ix), saved);
880 *fname_vars[ix].decl = NULL_TREE;
883 if (saved || saved_function_name_decls)
884 /* Normally they'll have been NULL, so only push if we've got a
885 stack, or they are non-NULL. */
886 saved_function_name_decls = tree_cons (saved, NULL_TREE,
887 saved_function_name_decls);
890 /* Finish up the current bindings, adding them into the current function's
891 statement tree. This must be done _before_ finish_stmt_tree is called.
892 If there is no current function, we must be at file scope and no statements
893 are involved. Pop the previous bindings. */
896 finish_fname_decls (void)
899 tree stmts = NULL_TREE;
900 tree stack = saved_function_name_decls;
902 for (; stack && TREE_VALUE (stack); stack = TREE_CHAIN (stack))
903 append_to_statement_list (TREE_VALUE (stack), &stmts);
907 tree *bodyp = &DECL_SAVED_TREE (current_function_decl);
909 if (TREE_CODE (*bodyp) == BIND_EXPR)
910 bodyp = &BIND_EXPR_BODY (*bodyp);
912 append_to_statement_list_force (*bodyp, &stmts);
916 for (ix = 0; fname_vars[ix].decl; ix++)
917 *fname_vars[ix].decl = NULL_TREE;
921 /* We had saved values, restore them. */
924 for (saved = TREE_PURPOSE (stack); saved; saved = TREE_CHAIN (saved))
926 tree decl = TREE_PURPOSE (saved);
927 unsigned ix = TREE_INT_CST_LOW (TREE_VALUE (saved));
929 *fname_vars[ix].decl = decl;
931 stack = TREE_CHAIN (stack);
933 saved_function_name_decls = stack;
936 /* Return the text name of the current function, suitably prettified
937 by PRETTY_P. Return string must be freed by caller. */
940 fname_as_string (int pretty_p)
942 const char *name = "top level";
945 cpp_string cstr = { 0, 0 }, strname;
953 if (current_function_decl)
954 name = lang_hooks.decl_printable_name (current_function_decl, vrb);
956 len = strlen (name) + 3; /* Two for '"'s. One for NULL. */
958 namep = XNEWVEC (char, len);
959 snprintf (namep, len, "\"%s\"", name);
960 strname.text = (unsigned char *) namep;
961 strname.len = len - 1;
963 if (cpp_interpret_string (parse_in, &strname, 1, &cstr, CPP_STRING))
966 return (const char *) cstr.text;
972 /* Return the VAR_DECL for a const char array naming the current
973 function. If the VAR_DECL has not yet been created, create it
974 now. RID indicates how it should be formatted and IDENTIFIER_NODE
975 ID is its name (unfortunately C and C++ hold the RID values of
976 keywords in different places, so we can't derive RID from ID in
977 this language independent code. LOC is the location of the
981 fname_decl (location_t loc, unsigned int rid, tree id)
984 tree decl = NULL_TREE;
986 for (ix = 0; fname_vars[ix].decl; ix++)
987 if (fname_vars[ix].rid == rid)
990 decl = *fname_vars[ix].decl;
993 /* If a tree is built here, it would normally have the lineno of
994 the current statement. Later this tree will be moved to the
995 beginning of the function and this line number will be wrong.
996 To avoid this problem set the lineno to 0 here; that prevents
997 it from appearing in the RTL. */
999 location_t saved_location = input_location;
1000 input_location = UNKNOWN_LOCATION;
1002 stmts = push_stmt_list ();
1003 decl = (*make_fname_decl) (loc, id, fname_vars[ix].pretty);
1004 stmts = pop_stmt_list (stmts);
1005 if (!IS_EMPTY_STMT (stmts))
1006 saved_function_name_decls
1007 = tree_cons (decl, stmts, saved_function_name_decls);
1008 *fname_vars[ix].decl = decl;
1009 input_location = saved_location;
1011 if (!ix && !current_function_decl)
1012 pedwarn (loc, 0, "%qD is not defined outside of function scope", decl);
1017 /* Given a STRING_CST, give it a suitable array-of-chars data type. */
1020 fix_string_type (tree value)
1022 int length = TREE_STRING_LENGTH (value);
1024 tree e_type, i_type, a_type;
1026 /* Compute the number of elements, for the array type. */
1027 if (TREE_TYPE (value) == char_array_type_node || !TREE_TYPE (value))
1030 e_type = char_type_node;
1032 else if (TREE_TYPE (value) == char16_array_type_node)
1034 nchars = length / (TYPE_PRECISION (char16_type_node) / BITS_PER_UNIT);
1035 e_type = char16_type_node;
1037 else if (TREE_TYPE (value) == char32_array_type_node)
1039 nchars = length / (TYPE_PRECISION (char32_type_node) / BITS_PER_UNIT);
1040 e_type = char32_type_node;
1044 nchars = length / (TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT);
1045 e_type = wchar_type_node;
1048 /* C89 2.2.4.1, C99 5.2.4.1 (Translation limits). The analogous
1049 limit in C++98 Annex B is very large (65536) and is not normative,
1050 so we do not diagnose it (warn_overlength_strings is forced off
1051 in c_common_post_options). */
1052 if (warn_overlength_strings)
1054 const int nchars_max = flag_isoc99 ? 4095 : 509;
1055 const int relevant_std = flag_isoc99 ? 99 : 90;
1056 if (nchars - 1 > nchars_max)
1057 /* Translators: The %d after 'ISO C' will be 90 or 99. Do not
1058 separate the %d from the 'C'. 'ISO' should not be
1059 translated, but it may be moved after 'C%d' in languages
1060 where modifiers follow nouns. */
1061 pedwarn (input_location, OPT_Woverlength_strings,
1062 "string length %qd is greater than the length %qd "
1063 "ISO C%d compilers are required to support",
1064 nchars - 1, nchars_max, relevant_std);
1067 /* Create the array type for the string constant. The ISO C++
1068 standard says that a string literal has type `const char[N]' or
1069 `const wchar_t[N]'. We use the same logic when invoked as a C
1070 front-end with -Wwrite-strings.
1071 ??? We should change the type of an expression depending on the
1072 state of a warning flag. We should just be warning -- see how
1073 this is handled in the C++ front-end for the deprecated implicit
1074 conversion from string literals to `char*' or `wchar_t*'.
1076 The C++ front end relies on TYPE_MAIN_VARIANT of a cv-qualified
1077 array type being the unqualified version of that type.
1078 Therefore, if we are constructing an array of const char, we must
1079 construct the matching unqualified array type first. The C front
1080 end does not require this, but it does no harm, so we do it
1082 i_type = build_index_type (build_int_cst (NULL_TREE, nchars - 1));
1083 a_type = build_array_type (e_type, i_type);
1084 if (c_dialect_cxx() || warn_write_strings)
1085 a_type = c_build_qualified_type (a_type, TYPE_QUAL_CONST);
1087 TREE_TYPE (value) = a_type;
1088 TREE_CONSTANT (value) = 1;
1089 TREE_READONLY (value) = 1;
1090 TREE_STATIC (value) = 1;
1094 /* Fully fold EXPR, an expression that was not folded (beyond integer
1095 constant expressions and null pointer constants) when being built
1096 up. If IN_INIT, this is in a static initializer and certain
1097 changes are made to the folding done. Clear *MAYBE_CONST if
1098 MAYBE_CONST is not NULL and EXPR is definitely not a constant
1099 expression because it contains an evaluated operator (in C99) or an
1100 operator outside of sizeof returning an integer constant (in C90)
1101 not permitted in constant expressions, or because it contains an
1102 evaluated arithmetic overflow. (*MAYBE_CONST should typically be
1103 set to true by callers before calling this function.) Return the
1104 folded expression. Function arguments have already been folded
1105 before calling this function, as have the contents of SAVE_EXPR,
1106 TARGET_EXPR, BIND_EXPR, VA_ARG_EXPR, OBJ_TYPE_REF and
1107 C_MAYBE_CONST_EXPR. */
1110 c_fully_fold (tree expr, bool in_init, bool *maybe_const)
1113 tree eptype = NULL_TREE;
1115 bool maybe_const_itself = true;
1116 location_t loc = EXPR_LOCATION (expr);
1118 /* This function is not relevant to C++ because C++ folds while
1119 parsing, and may need changes to be correct for C++ when C++
1120 stops folding while parsing. */
1121 if (c_dialect_cxx ())
1125 maybe_const = &dummy;
1126 if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
1128 eptype = TREE_TYPE (expr);
1129 expr = TREE_OPERAND (expr, 0);
1131 ret = c_fully_fold_internal (expr, in_init, maybe_const,
1132 &maybe_const_itself);
1134 ret = fold_convert_loc (loc, eptype, ret);
1135 *maybe_const &= maybe_const_itself;
1139 /* Internal helper for c_fully_fold. EXPR and IN_INIT are as for
1140 c_fully_fold. *MAYBE_CONST_OPERANDS is cleared because of operands
1141 not permitted, while *MAYBE_CONST_ITSELF is cleared because of
1142 arithmetic overflow (for C90, *MAYBE_CONST_OPERANDS is carried from
1143 both evaluated and unevaluated subexpressions while
1144 *MAYBE_CONST_ITSELF is carried from only evaluated
1148 c_fully_fold_internal (tree expr, bool in_init, bool *maybe_const_operands,
1149 bool *maybe_const_itself)
1152 enum tree_code code = TREE_CODE (expr);
1153 enum tree_code_class kind = TREE_CODE_CLASS (code);
1154 location_t loc = EXPR_LOCATION (expr);
1155 tree op0, op1, op2, op3;
1156 tree orig_op0, orig_op1, orig_op2;
1157 bool op0_const = true, op1_const = true, op2_const = true;
1158 bool op0_const_self = true, op1_const_self = true, op2_const_self = true;
1159 bool nowarning = TREE_NO_WARNING (expr);
1162 /* This function is not relevant to C++ because C++ folds while
1163 parsing, and may need changes to be correct for C++ when C++
1164 stops folding while parsing. */
1165 if (c_dialect_cxx ())
1168 /* Constants, declarations, statements, errors, SAVE_EXPRs and
1169 anything else not counted as an expression cannot usefully be
1170 folded further at this point. */
1171 if (!IS_EXPR_CODE_CLASS (kind)
1172 || kind == tcc_statement
1173 || code == SAVE_EXPR)
1176 /* Operands of variable-length expressions (function calls) have
1177 already been folded, as have __builtin_* function calls, and such
1178 expressions cannot occur in constant expressions. */
1179 if (kind == tcc_vl_exp)
1181 *maybe_const_operands = false;
1186 if (code == C_MAYBE_CONST_EXPR)
1188 tree pre = C_MAYBE_CONST_EXPR_PRE (expr);
1189 tree inner = C_MAYBE_CONST_EXPR_EXPR (expr);
1190 if (C_MAYBE_CONST_EXPR_NON_CONST (expr))
1191 *maybe_const_operands = false;
1192 if (C_MAYBE_CONST_EXPR_INT_OPERANDS (expr))
1193 *maybe_const_itself = false;
1194 if (pre && !in_init)
1195 ret = build2 (COMPOUND_EXPR, TREE_TYPE (expr), pre, inner);
1201 /* Assignment, increment, decrement, function call and comma
1202 operators, and statement expressions, cannot occur in constant
1203 expressions if evaluated / outside of sizeof. (Function calls
1204 were handled above, though VA_ARG_EXPR is treated like a function
1205 call here, and statement expressions are handled through
1206 C_MAYBE_CONST_EXPR to avoid folding inside them.) */
1210 case PREDECREMENT_EXPR:
1211 case PREINCREMENT_EXPR:
1212 case POSTDECREMENT_EXPR:
1213 case POSTINCREMENT_EXPR:
1215 *maybe_const_operands = false;
1222 *maybe_const_operands = false;
1230 /* Fold individual tree codes as appropriate. */
1233 case COMPOUND_LITERAL_EXPR:
1234 /* Any non-constancy will have been marked in a containing
1235 C_MAYBE_CONST_EXPR; there is no more folding to do here. */
1239 orig_op0 = op0 = TREE_OPERAND (expr, 0);
1240 op1 = TREE_OPERAND (expr, 1);
1241 op2 = TREE_OPERAND (expr, 2);
1242 op0 = c_fully_fold_internal (op0, in_init, maybe_const_operands,
1243 maybe_const_itself);
1244 STRIP_TYPE_NOPS (op0);
1245 if (op0 != orig_op0)
1246 ret = build3 (COMPONENT_REF, TREE_TYPE (expr), op0, op1, op2);
1249 TREE_READONLY (ret) = TREE_READONLY (expr);
1250 TREE_THIS_VOLATILE (ret) = TREE_THIS_VOLATILE (expr);
1255 orig_op0 = op0 = TREE_OPERAND (expr, 0);
1256 orig_op1 = op1 = TREE_OPERAND (expr, 1);
1257 op2 = TREE_OPERAND (expr, 2);
1258 op3 = TREE_OPERAND (expr, 3);
1259 op0 = c_fully_fold_internal (op0, in_init, maybe_const_operands,
1260 maybe_const_itself);
1261 STRIP_TYPE_NOPS (op0);
1262 op1 = c_fully_fold_internal (op1, in_init, maybe_const_operands,
1263 maybe_const_itself);
1264 STRIP_TYPE_NOPS (op1);
1265 op1 = decl_constant_value_for_optimization (op1);
1266 if (op0 != orig_op0 || op1 != orig_op1)
1267 ret = build4 (ARRAY_REF, TREE_TYPE (expr), op0, op1, op2, op3);
1270 TREE_READONLY (ret) = TREE_READONLY (expr);
1271 TREE_SIDE_EFFECTS (ret) = TREE_SIDE_EFFECTS (expr);
1272 TREE_THIS_VOLATILE (ret) = TREE_THIS_VOLATILE (expr);
1279 case PREDECREMENT_EXPR:
1280 case PREINCREMENT_EXPR:
1281 case POSTDECREMENT_EXPR:
1282 case POSTINCREMENT_EXPR:
1286 case POINTER_PLUS_EXPR:
1287 case TRUNC_DIV_EXPR:
1289 case FLOOR_DIV_EXPR:
1290 case TRUNC_MOD_EXPR:
1292 case EXACT_DIV_EXPR:
1305 case TRUTH_AND_EXPR:
1307 case TRUTH_XOR_EXPR:
1308 case UNORDERED_EXPR:
1315 /* Binary operations evaluating both arguments (increment and
1316 decrement are binary internally in GCC). */
1317 orig_op0 = op0 = TREE_OPERAND (expr, 0);
1318 orig_op1 = op1 = TREE_OPERAND (expr, 1);
1319 op0 = c_fully_fold_internal (op0, in_init, maybe_const_operands,
1320 maybe_const_itself);
1321 STRIP_TYPE_NOPS (op0);
1322 if (code != MODIFY_EXPR
1323 && code != PREDECREMENT_EXPR
1324 && code != PREINCREMENT_EXPR
1325 && code != POSTDECREMENT_EXPR
1326 && code != POSTINCREMENT_EXPR)
1327 op0 = decl_constant_value_for_optimization (op0);
1328 /* The RHS of a MODIFY_EXPR was fully folded when building that
1329 expression for the sake of conversion warnings. */
1330 if (code != MODIFY_EXPR)
1331 op1 = c_fully_fold_internal (op1, in_init, maybe_const_operands,
1332 maybe_const_itself);
1333 STRIP_TYPE_NOPS (op1);
1334 op1 = decl_constant_value_for_optimization (op1);
1335 if (op0 != orig_op0 || op1 != orig_op1 || in_init)
1337 ? fold_build2_initializer_loc (loc, code, TREE_TYPE (expr), op0, op1)
1338 : fold_build2_loc (loc, code, TREE_TYPE (expr), op0, op1);
1341 if (TREE_OVERFLOW_P (ret)
1342 && !TREE_OVERFLOW_P (op0)
1343 && !TREE_OVERFLOW_P (op1))
1344 overflow_warning (EXPR_LOCATION (expr), ret);
1348 case FIX_TRUNC_EXPR:
1351 case NON_LVALUE_EXPR:
1354 case TRUTH_NOT_EXPR:
1359 /* Unary operations. */
1360 orig_op0 = op0 = TREE_OPERAND (expr, 0);
1361 op0 = c_fully_fold_internal (op0, in_init, maybe_const_operands,
1362 maybe_const_itself);
1363 STRIP_TYPE_NOPS (op0);
1364 if (code != ADDR_EXPR && code != REALPART_EXPR && code != IMAGPART_EXPR)
1365 op0 = decl_constant_value_for_optimization (op0);
1366 if (op0 != orig_op0 || in_init)
1368 ? fold_build1_initializer_loc (loc, code, TREE_TYPE (expr), op0)
1369 : fold_build1_loc (loc, code, TREE_TYPE (expr), op0);
1372 if (code == INDIRECT_REF
1374 && TREE_CODE (ret) == INDIRECT_REF)
1376 TREE_READONLY (ret) = TREE_READONLY (expr);
1377 TREE_SIDE_EFFECTS (ret) = TREE_SIDE_EFFECTS (expr);
1378 TREE_THIS_VOLATILE (ret) = TREE_THIS_VOLATILE (expr);
1382 case FIX_TRUNC_EXPR:
1385 /* Don't warn about explicit conversions. We will already
1386 have warned about suspect implicit conversions. */
1390 if (TREE_OVERFLOW_P (ret) && !TREE_OVERFLOW_P (op0))
1391 overflow_warning (EXPR_LOCATION (expr), ret);
1396 case TRUTH_ANDIF_EXPR:
1397 case TRUTH_ORIF_EXPR:
1398 /* Binary operations not necessarily evaluating both
1400 orig_op0 = op0 = TREE_OPERAND (expr, 0);
1401 orig_op1 = op1 = TREE_OPERAND (expr, 1);
1402 op0 = c_fully_fold_internal (op0, in_init, &op0_const, &op0_const_self);
1403 STRIP_TYPE_NOPS (op0);
1405 unused_p = (op0 == (code == TRUTH_ANDIF_EXPR
1406 ? truthvalue_false_node
1407 : truthvalue_true_node));
1408 c_inhibit_evaluation_warnings += unused_p;
1409 op1 = c_fully_fold_internal (op1, in_init, &op1_const, &op1_const_self);
1410 STRIP_TYPE_NOPS (op1);
1411 c_inhibit_evaluation_warnings -= unused_p;
1413 if (op0 != orig_op0 || op1 != orig_op1 || in_init)
1415 ? fold_build2_initializer_loc (loc, code, TREE_TYPE (expr), op0, op1)
1416 : fold_build2_loc (loc, code, TREE_TYPE (expr), op0, op1);
1419 *maybe_const_operands &= op0_const;
1420 *maybe_const_itself &= op0_const_self;
1424 && (code == TRUTH_ANDIF_EXPR
1425 ? op0 == truthvalue_false_node
1426 : op0 == truthvalue_true_node)))
1427 *maybe_const_operands &= op1_const;
1430 && (code == TRUTH_ANDIF_EXPR
1431 ? op0 == truthvalue_false_node
1432 : op0 == truthvalue_true_node)))
1433 *maybe_const_itself &= op1_const_self;
1437 orig_op0 = op0 = TREE_OPERAND (expr, 0);
1438 orig_op1 = op1 = TREE_OPERAND (expr, 1);
1439 orig_op2 = op2 = TREE_OPERAND (expr, 2);
1440 op0 = c_fully_fold_internal (op0, in_init, &op0_const, &op0_const_self);
1442 STRIP_TYPE_NOPS (op0);
1443 c_inhibit_evaluation_warnings += (op0 == truthvalue_false_node);
1444 op1 = c_fully_fold_internal (op1, in_init, &op1_const, &op1_const_self);
1445 STRIP_TYPE_NOPS (op1);
1446 c_inhibit_evaluation_warnings -= (op0 == truthvalue_false_node);
1448 c_inhibit_evaluation_warnings += (op0 == truthvalue_true_node);
1449 op2 = c_fully_fold_internal (op2, in_init, &op2_const, &op2_const_self);
1450 STRIP_TYPE_NOPS (op2);
1451 c_inhibit_evaluation_warnings -= (op0 == truthvalue_true_node);
1453 if (op0 != orig_op0 || op1 != orig_op1 || op2 != orig_op2)
1454 ret = fold_build3_loc (loc, code, TREE_TYPE (expr), op0, op1, op2);
1457 *maybe_const_operands &= op0_const;
1458 *maybe_const_itself &= op0_const_self;
1462 && op0 == truthvalue_false_node))
1463 *maybe_const_operands &= op1_const;
1466 && op0 == truthvalue_false_node))
1467 *maybe_const_itself &= op1_const_self;
1471 && op0 == truthvalue_true_node))
1472 *maybe_const_operands &= op2_const;
1475 && op0 == truthvalue_true_node))
1476 *maybe_const_itself &= op2_const_self;
1479 case EXCESS_PRECISION_EXPR:
1480 /* Each case where an operand with excess precision may be
1481 encountered must remove the EXCESS_PRECISION_EXPR around
1482 inner operands and possibly put one around the whole
1483 expression or possibly convert to the semantic type (which
1484 c_fully_fold does); we cannot tell at this stage which is
1485 appropriate in any particular case. */
1489 /* Various codes may appear through folding built-in functions
1490 and their arguments. */
1495 /* Some folding may introduce NON_LVALUE_EXPRs; all lvalue checks
1496 have been done by this point, so remove them again. */
1497 nowarning |= TREE_NO_WARNING (ret);
1498 STRIP_TYPE_NOPS (ret);
1499 if (nowarning && !TREE_NO_WARNING (ret))
1501 if (!CAN_HAVE_LOCATION_P (ret))
1502 ret = build1 (NOP_EXPR, TREE_TYPE (ret), ret);
1503 TREE_NO_WARNING (ret) = 1;
1506 protected_set_expr_location (ret, loc);
1510 /* If not optimizing, EXP is not a VAR_DECL, or EXP has array type,
1511 return EXP. Otherwise, return either EXP or its known constant
1512 value (if it has one), but return EXP if EXP has mode BLKmode. ???
1513 Is the BLKmode test appropriate? */
1516 decl_constant_value_for_optimization (tree exp)
1520 /* This function is only used by C, for c_fully_fold and other
1521 optimization, and may not be correct for C++. */
1522 if (c_dialect_cxx ())
1526 || TREE_CODE (exp) != VAR_DECL
1527 || TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
1528 || DECL_MODE (exp) == BLKmode)
1531 ret = decl_constant_value (exp);
1532 /* Avoid unwanted tree sharing between the initializer and current
1533 function's body where the tree can be modified e.g. by the
1535 if (ret != exp && TREE_STATIC (exp))
1536 ret = unshare_expr (ret);
1540 /* Print a warning if a constant expression had overflow in folding.
1541 Invoke this function on every expression that the language
1542 requires to be a constant expression.
1543 Note the ANSI C standard says it is erroneous for a
1544 constant expression to overflow. */
1547 constant_expression_warning (tree value)
1549 if (warn_overflow && pedantic
1550 && (TREE_CODE (value) == INTEGER_CST || TREE_CODE (value) == REAL_CST
1551 || TREE_CODE (value) == FIXED_CST
1552 || TREE_CODE (value) == VECTOR_CST
1553 || TREE_CODE (value) == COMPLEX_CST)
1554 && TREE_OVERFLOW (value))
1555 pedwarn (input_location, OPT_Woverflow, "overflow in constant expression");
1558 /* The same as above but print an unconditional error. */
1560 constant_expression_error (tree value)
1562 if ((TREE_CODE (value) == INTEGER_CST || TREE_CODE (value) == REAL_CST
1563 || TREE_CODE (value) == FIXED_CST
1564 || TREE_CODE (value) == VECTOR_CST
1565 || TREE_CODE (value) == COMPLEX_CST)
1566 && TREE_OVERFLOW (value))
1567 error ("overflow in constant expression");
1570 /* Print a warning if an expression had overflow in folding and its
1573 Invoke this function on every expression that
1574 (1) appears in the source code, and
1575 (2) is a constant expression that overflowed, and
1576 (3) is not already checked by convert_and_check;
1577 however, do not invoke this function on operands of explicit casts
1578 or when the expression is the result of an operator and any operand
1579 already overflowed. */
1582 overflow_warning (location_t loc, tree value)
1584 if (c_inhibit_evaluation_warnings != 0)
1587 switch (TREE_CODE (value))
1590 warning_at (loc, OPT_Woverflow, "integer overflow in expression");
1594 warning_at (loc, OPT_Woverflow,
1595 "floating point overflow in expression");
1599 warning_at (loc, OPT_Woverflow, "fixed-point overflow in expression");
1603 warning_at (loc, OPT_Woverflow, "vector overflow in expression");
1607 if (TREE_CODE (TREE_REALPART (value)) == INTEGER_CST)
1608 warning_at (loc, OPT_Woverflow,
1609 "complex integer overflow in expression");
1610 else if (TREE_CODE (TREE_REALPART (value)) == REAL_CST)
1611 warning_at (loc, OPT_Woverflow,
1612 "complex floating point overflow in expression");
1620 /* Warn about uses of logical || / && operator in a context where it
1621 is likely that the bitwise equivalent was intended by the
1622 programmer. We have seen an expression in which CODE is a binary
1623 operator used to combine expressions OP_LEFT and OP_RIGHT, which before folding
1624 had CODE_LEFT and CODE_RIGHT, into an expression of type TYPE. */
1626 warn_logical_operator (location_t location, enum tree_code code, tree type,
1627 enum tree_code code_left, tree op_left,
1628 enum tree_code ARG_UNUSED (code_right), tree op_right)
1630 int or_op = (code == TRUTH_ORIF_EXPR || code == TRUTH_OR_EXPR);
1631 int in0_p, in1_p, in_p;
1632 tree low0, low1, low, high0, high1, high, lhs, rhs, tem;
1633 bool strict_overflow_p = false;
1635 if (code != TRUTH_ANDIF_EXPR
1636 && code != TRUTH_AND_EXPR
1637 && code != TRUTH_ORIF_EXPR
1638 && code != TRUTH_OR_EXPR)
1641 /* Warn if &&/|| are being used in a context where it is
1642 likely that the bitwise equivalent was intended by the
1643 programmer. That is, an expression such as op && MASK
1644 where op should not be any boolean expression, nor a
1645 constant, and mask seems to be a non-boolean integer constant. */
1646 if (!truth_value_p (code_left)
1647 && INTEGRAL_TYPE_P (TREE_TYPE (op_left))
1648 && !CONSTANT_CLASS_P (op_left)
1649 && !TREE_NO_WARNING (op_left)
1650 && TREE_CODE (op_right) == INTEGER_CST
1651 && !integer_zerop (op_right)
1652 && !integer_onep (op_right))
1655 warning_at (location, OPT_Wlogical_op, "logical %<or%>"
1656 " applied to non-boolean constant");
1658 warning_at (location, OPT_Wlogical_op, "logical %<and%>"
1659 " applied to non-boolean constant");
1660 TREE_NO_WARNING (op_left) = true;
1664 /* We do not warn for constants because they are typical of macro
1665 expansions that test for features. */
1666 if (CONSTANT_CLASS_P (op_left) || CONSTANT_CLASS_P (op_right))
1669 /* This warning only makes sense with logical operands. */
1670 if (!(truth_value_p (TREE_CODE (op_left))
1671 || INTEGRAL_TYPE_P (TREE_TYPE (op_left)))
1672 || !(truth_value_p (TREE_CODE (op_right))
1673 || INTEGRAL_TYPE_P (TREE_TYPE (op_right))))
1676 lhs = make_range (op_left, &in0_p, &low0, &high0, &strict_overflow_p);
1677 rhs = make_range (op_right, &in1_p, &low1, &high1, &strict_overflow_p);
1679 if (lhs && TREE_CODE (lhs) == C_MAYBE_CONST_EXPR)
1680 lhs = C_MAYBE_CONST_EXPR_EXPR (lhs);
1682 if (rhs && TREE_CODE (rhs) == C_MAYBE_CONST_EXPR)
1683 rhs = C_MAYBE_CONST_EXPR_EXPR (rhs);
1685 /* If this is an OR operation, invert both sides; we will invert
1686 again at the end. */
1688 in0_p = !in0_p, in1_p = !in1_p;
1690 /* If both expressions are the same, if we can merge the ranges, and we
1691 can build the range test, return it or it inverted. */
1692 if (lhs && rhs && operand_equal_p (lhs, rhs, 0)
1693 && merge_ranges (&in_p, &low, &high, in0_p, low0, high0,
1695 && 0 != (tem = build_range_check (UNKNOWN_LOCATION,
1696 type, lhs, in_p, low, high)))
1698 if (TREE_CODE (tem) != INTEGER_CST)
1702 warning_at (location, OPT_Wlogical_op,
1704 "of collectively exhaustive tests is always true");
1706 warning_at (location, OPT_Wlogical_op,
1708 "of mutually exclusive tests is always false");
1713 /* Print a warning about casts that might indicate violation
1714 of strict aliasing rules if -Wstrict-aliasing is used and
1715 strict aliasing mode is in effect. OTYPE is the original
1716 TREE_TYPE of EXPR, and TYPE the type we're casting to. */
1719 strict_aliasing_warning (tree otype, tree type, tree expr)
1721 /* Strip pointer conversion chains and get to the correct original type. */
1723 otype = TREE_TYPE (expr);
1725 if (!(flag_strict_aliasing
1726 && POINTER_TYPE_P (type)
1727 && POINTER_TYPE_P (otype)
1728 && !VOID_TYPE_P (TREE_TYPE (type)))
1729 /* If the type we are casting to is a ref-all pointer
1730 dereferencing it is always valid. */
1731 || TYPE_REF_CAN_ALIAS_ALL (type))
1734 if ((warn_strict_aliasing > 1) && TREE_CODE (expr) == ADDR_EXPR
1735 && (DECL_P (TREE_OPERAND (expr, 0))
1736 || handled_component_p (TREE_OPERAND (expr, 0))))
1738 /* Casting the address of an object to non void pointer. Warn
1739 if the cast breaks type based aliasing. */
1740 if (!COMPLETE_TYPE_P (TREE_TYPE (type)) && warn_strict_aliasing == 2)
1742 warning (OPT_Wstrict_aliasing, "type-punning to incomplete type "
1743 "might break strict-aliasing rules");
1748 /* warn_strict_aliasing >= 3. This includes the default (3).
1749 Only warn if the cast is dereferenced immediately. */
1750 alias_set_type set1 =
1751 get_alias_set (TREE_TYPE (TREE_OPERAND (expr, 0)));
1752 alias_set_type set2 = get_alias_set (TREE_TYPE (type));
1754 if (set1 != set2 && set2 != 0
1755 && (set1 == 0 || !alias_sets_conflict_p (set1, set2)))
1757 warning (OPT_Wstrict_aliasing, "dereferencing type-punned "
1758 "pointer will break strict-aliasing rules");
1761 else if (warn_strict_aliasing == 2
1762 && !alias_sets_must_conflict_p (set1, set2))
1764 warning (OPT_Wstrict_aliasing, "dereferencing type-punned "
1765 "pointer might break strict-aliasing rules");
1771 if ((warn_strict_aliasing == 1) && !VOID_TYPE_P (TREE_TYPE (otype)))
1773 /* At this level, warn for any conversions, even if an address is
1774 not taken in the same statement. This will likely produce many
1775 false positives, but could be useful to pinpoint problems that
1776 are not revealed at higher levels. */
1777 alias_set_type set1 = get_alias_set (TREE_TYPE (otype));
1778 alias_set_type set2 = get_alias_set (TREE_TYPE (type));
1779 if (!COMPLETE_TYPE_P (type)
1780 || !alias_sets_must_conflict_p (set1, set2))
1782 warning (OPT_Wstrict_aliasing, "dereferencing type-punned "
1783 "pointer might break strict-aliasing rules");
1791 /* Warn for unlikely, improbable, or stupid DECL declarations
1795 check_main_parameter_types (tree decl)
1800 for (args = TYPE_ARG_TYPES (TREE_TYPE (decl)); args;
1801 args = TREE_CHAIN (args))
1803 tree type = args ? TREE_VALUE (args) : 0;
1805 if (type == void_type_node || type == error_mark_node )
1812 if (TYPE_MAIN_VARIANT (type) != integer_type_node)
1813 pedwarn (input_location, OPT_Wmain, "first argument of %q+D should be %<int%>",
1818 if (TREE_CODE (type) != POINTER_TYPE
1819 || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
1820 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
1822 pedwarn (input_location, OPT_Wmain, "second argument of %q+D should be %<char **%>",
1827 if (TREE_CODE (type) != POINTER_TYPE
1828 || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
1829 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
1831 pedwarn (input_location, OPT_Wmain, "third argument of %q+D should probably be "
1832 "%<char **%>", decl);
1837 /* It is intentional that this message does not mention the third
1838 argument because it's only mentioned in an appendix of the
1840 if (argct > 0 && (argct < 2 || argct > 3))
1841 pedwarn (input_location, OPT_Wmain, "%q+D takes only zero or two arguments", decl);
1844 /* True if pointers to distinct types T1 and T2 can be converted to
1845 each other without an explicit cast. Only returns true for opaque
1848 vector_targets_convertible_p (const_tree t1, const_tree t2)
1850 if (TREE_CODE (t1) == VECTOR_TYPE && TREE_CODE (t2) == VECTOR_TYPE
1851 && (TYPE_VECTOR_OPAQUE (t1) || TYPE_VECTOR_OPAQUE (t2))
1852 && tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2)))
1858 /* True if vector types T1 and T2 can be converted to each other
1859 without an explicit cast. If EMIT_LAX_NOTE is true, and T1 and T2
1860 can only be converted with -flax-vector-conversions yet that is not
1861 in effect, emit a note telling the user about that option if such
1862 a note has not previously been emitted. */
1864 vector_types_convertible_p (const_tree t1, const_tree t2, bool emit_lax_note)
1866 static bool emitted_lax_note = false;
1867 bool convertible_lax;
1869 if ((TYPE_VECTOR_OPAQUE (t1) || TYPE_VECTOR_OPAQUE (t2))
1870 && tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2)))
1874 (tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2))
1875 && (TREE_CODE (TREE_TYPE (t1)) != REAL_TYPE ||
1876 TYPE_PRECISION (t1) == TYPE_PRECISION (t2))
1877 && (INTEGRAL_TYPE_P (TREE_TYPE (t1))
1878 == INTEGRAL_TYPE_P (TREE_TYPE (t2))));
1880 if (!convertible_lax || flag_lax_vector_conversions)
1881 return convertible_lax;
1883 if (TYPE_VECTOR_SUBPARTS (t1) == TYPE_VECTOR_SUBPARTS (t2)
1884 && lang_hooks.types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2)))
1887 if (emit_lax_note && !emitted_lax_note)
1889 emitted_lax_note = true;
1890 inform (input_location, "use -flax-vector-conversions to permit "
1891 "conversions between vectors with differing "
1892 "element types or numbers of subparts");
1898 /* This is a helper function of build_binary_op.
1900 For certain operations if both args were extended from the same
1901 smaller type, do the arithmetic in that type and then extend.
1903 BITWISE indicates a bitwise operation.
1904 For them, this optimization is safe only if
1905 both args are zero-extended or both are sign-extended.
1906 Otherwise, we might change the result.
1907 Eg, (short)-1 | (unsigned short)-1 is (int)-1
1908 but calculated in (unsigned short) it would be (unsigned short)-1.
1910 tree shorten_binary_op (tree result_type, tree op0, tree op1, bool bitwise)
1912 int unsigned0, unsigned1;
1917 /* Cast OP0 and OP1 to RESULT_TYPE. Doing so prevents
1918 excessive narrowing when we call get_narrower below. For
1919 example, suppose that OP0 is of unsigned int extended
1920 from signed char and that RESULT_TYPE is long long int.
1921 If we explicitly cast OP0 to RESULT_TYPE, OP0 would look
1924 (long long int) (unsigned int) signed_char
1926 which get_narrower would narrow down to
1928 (unsigned int) signed char
1930 If we do not cast OP0 first, get_narrower would return
1931 signed_char, which is inconsistent with the case of the
1933 op0 = convert (result_type, op0);
1934 op1 = convert (result_type, op1);
1936 arg0 = get_narrower (op0, &unsigned0);
1937 arg1 = get_narrower (op1, &unsigned1);
1939 /* UNS is 1 if the operation to be done is an unsigned one. */
1940 uns = TYPE_UNSIGNED (result_type);
1942 /* Handle the case that OP0 (or OP1) does not *contain* a conversion
1943 but it *requires* conversion to FINAL_TYPE. */
1945 if ((TYPE_PRECISION (TREE_TYPE (op0))
1946 == TYPE_PRECISION (TREE_TYPE (arg0)))
1947 && TREE_TYPE (op0) != result_type)
1948 unsigned0 = TYPE_UNSIGNED (TREE_TYPE (op0));
1949 if ((TYPE_PRECISION (TREE_TYPE (op1))
1950 == TYPE_PRECISION (TREE_TYPE (arg1)))
1951 && TREE_TYPE (op1) != result_type)
1952 unsigned1 = TYPE_UNSIGNED (TREE_TYPE (op1));
1954 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
1956 /* For bitwise operations, signedness of nominal type
1957 does not matter. Consider only how operands were extended. */
1961 /* Note that in all three cases below we refrain from optimizing
1962 an unsigned operation on sign-extended args.
1963 That would not be valid. */
1965 /* Both args variable: if both extended in same way
1966 from same width, do it in that width.
1967 Do it unsigned if args were zero-extended. */
1968 if ((TYPE_PRECISION (TREE_TYPE (arg0))
1969 < TYPE_PRECISION (result_type))
1970 && (TYPE_PRECISION (TREE_TYPE (arg1))
1971 == TYPE_PRECISION (TREE_TYPE (arg0)))
1972 && unsigned0 == unsigned1
1973 && (unsigned0 || !uns))
1974 return c_common_signed_or_unsigned_type
1975 (unsigned0, common_type (TREE_TYPE (arg0), TREE_TYPE (arg1)));
1977 else if (TREE_CODE (arg0) == INTEGER_CST
1978 && (unsigned1 || !uns)
1979 && (TYPE_PRECISION (TREE_TYPE (arg1))
1980 < TYPE_PRECISION (result_type))
1982 = c_common_signed_or_unsigned_type (unsigned1,
1984 && !POINTER_TYPE_P (type)
1985 && int_fits_type_p (arg0, type))
1988 else if (TREE_CODE (arg1) == INTEGER_CST
1989 && (unsigned0 || !uns)
1990 && (TYPE_PRECISION (TREE_TYPE (arg0))
1991 < TYPE_PRECISION (result_type))
1993 = c_common_signed_or_unsigned_type (unsigned0,
1995 && !POINTER_TYPE_P (type)
1996 && int_fits_type_p (arg1, type))
2002 /* Warns if the conversion of EXPR to TYPE may alter a value.
2003 This is a helper function for warnings_for_convert_and_check. */
2006 conversion_warning (tree type, tree expr)
2008 bool give_warning = false;
2011 const int expr_num_operands = TREE_OPERAND_LENGTH (expr);
2012 tree expr_type = TREE_TYPE (expr);
2014 if (!warn_conversion && !warn_sign_conversion)
2017 /* If any operand is artificial, then this expression was generated
2018 by the compiler and we do not warn. */
2019 for (i = 0; i < expr_num_operands; i++)
2021 tree op = TREE_OPERAND (expr, i);
2022 if (op && DECL_P (op) && DECL_ARTIFICIAL (op))
2026 switch (TREE_CODE (expr))
2034 case TRUTH_ANDIF_EXPR:
2035 case TRUTH_ORIF_EXPR:
2036 case TRUTH_AND_EXPR:
2038 case TRUTH_XOR_EXPR:
2039 case TRUTH_NOT_EXPR:
2040 /* Conversion from boolean to a signed:1 bit-field (which only
2041 can hold the values 0 and -1) doesn't lose information - but
2042 it does change the value. */
2043 if (TYPE_PRECISION (type) == 1 && !TYPE_UNSIGNED (type))
2044 warning (OPT_Wconversion,
2045 "conversion to %qT from boolean expression", type);
2051 /* Warn for real constant that is not an exact integer converted
2053 if (TREE_CODE (expr_type) == REAL_TYPE
2054 && TREE_CODE (type) == INTEGER_TYPE)
2056 if (!real_isinteger (TREE_REAL_CST_PTR (expr), TYPE_MODE (expr_type)))
2057 give_warning = true;
2059 /* Warn for an integer constant that does not fit into integer type. */
2060 else if (TREE_CODE (expr_type) == INTEGER_TYPE
2061 && TREE_CODE (type) == INTEGER_TYPE
2062 && !int_fits_type_p (expr, type))
2064 if (TYPE_UNSIGNED (type) && !TYPE_UNSIGNED (expr_type)
2065 && tree_int_cst_sgn (expr) < 0)
2066 warning (OPT_Wsign_conversion,
2067 "negative integer implicitly converted to unsigned type");
2068 else if (!TYPE_UNSIGNED (type) && TYPE_UNSIGNED (expr_type))
2069 warning (OPT_Wsign_conversion, "conversion of unsigned constant "
2070 "value to negative integer");
2072 give_warning = true;
2074 else if (TREE_CODE (type) == REAL_TYPE)
2076 /* Warn for an integer constant that does not fit into real type. */
2077 if (TREE_CODE (expr_type) == INTEGER_TYPE)
2079 REAL_VALUE_TYPE a = real_value_from_int_cst (0, expr);
2080 if (!exact_real_truncate (TYPE_MODE (type), &a))
2081 give_warning = true;
2083 /* Warn for a real constant that does not fit into a smaller
2085 else if (TREE_CODE (expr_type) == REAL_TYPE
2086 && TYPE_PRECISION (type) < TYPE_PRECISION (expr_type))
2088 REAL_VALUE_TYPE a = TREE_REAL_CST (expr);
2089 if (!exact_real_truncate (TYPE_MODE (type), &a))
2090 give_warning = true;
2095 warning (OPT_Wconversion,
2096 "conversion to %qT alters %qT constant value",
2103 /* In case of COND_EXPR, if both operands are constants or
2104 COND_EXPR, then we do not care about the type of COND_EXPR,
2105 only about the conversion of each operand. */
2106 tree op1 = TREE_OPERAND (expr, 1);
2107 tree op2 = TREE_OPERAND (expr, 2);
2109 if ((TREE_CODE (op1) == REAL_CST || TREE_CODE (op1) == INTEGER_CST
2110 || TREE_CODE (op1) == COND_EXPR)
2111 && (TREE_CODE (op2) == REAL_CST || TREE_CODE (op2) == INTEGER_CST
2112 || TREE_CODE (op2) == COND_EXPR))
2114 conversion_warning (type, op1);
2115 conversion_warning (type, op2);
2121 default: /* 'expr' is not a constant. */
2123 /* Warn for real types converted to integer types. */
2124 if (TREE_CODE (expr_type) == REAL_TYPE
2125 && TREE_CODE (type) == INTEGER_TYPE)
2126 give_warning = true;
2128 else if (TREE_CODE (expr_type) == INTEGER_TYPE
2129 && TREE_CODE (type) == INTEGER_TYPE)
2131 /* Don't warn about unsigned char y = 0xff, x = (int) y; */
2132 expr = get_unwidened (expr, 0);
2133 expr_type = TREE_TYPE (expr);
2135 /* Don't warn for short y; short x = ((int)y & 0xff); */
2136 if (TREE_CODE (expr) == BIT_AND_EXPR
2137 || TREE_CODE (expr) == BIT_IOR_EXPR
2138 || TREE_CODE (expr) == BIT_XOR_EXPR)
2140 /* If both args were extended from a shortest type,
2141 use that type if that is safe. */
2142 expr_type = shorten_binary_op (expr_type,
2143 TREE_OPERAND (expr, 0),
2144 TREE_OPERAND (expr, 1),
2147 if (TREE_CODE (expr) == BIT_AND_EXPR)
2149 tree op0 = TREE_OPERAND (expr, 0);
2150 tree op1 = TREE_OPERAND (expr, 1);
2151 bool unsigned0 = TYPE_UNSIGNED (TREE_TYPE (op0));
2152 bool unsigned1 = TYPE_UNSIGNED (TREE_TYPE (op1));
2154 /* If one of the operands is a non-negative constant
2155 that fits in the target type, then the type of the
2156 other operand does not matter. */
2157 if ((TREE_CODE (op0) == INTEGER_CST
2158 && int_fits_type_p (op0, c_common_signed_type (type))
2159 && int_fits_type_p (op0, c_common_unsigned_type (type)))
2160 || (TREE_CODE (op1) == INTEGER_CST
2161 && int_fits_type_p (op1, c_common_signed_type (type))
2162 && int_fits_type_p (op1,
2163 c_common_unsigned_type (type))))
2165 /* If constant is unsigned and fits in the target
2166 type, then the result will also fit. */
2167 else if ((TREE_CODE (op0) == INTEGER_CST
2169 && int_fits_type_p (op0, type))
2170 || (TREE_CODE (op1) == INTEGER_CST
2172 && int_fits_type_p (op1, type)))
2176 /* Warn for integer types converted to smaller integer types. */
2177 if (TYPE_PRECISION (type) < TYPE_PRECISION (expr_type))
2178 give_warning = true;
2180 /* When they are the same width but different signedness,
2181 then the value may change. */
2182 else if ((TYPE_PRECISION (type) == TYPE_PRECISION (expr_type)
2183 && TYPE_UNSIGNED (expr_type) != TYPE_UNSIGNED (type))
2184 /* Even when converted to a bigger type, if the type is
2185 unsigned but expr is signed, then negative values
2187 || (TYPE_UNSIGNED (type) && !TYPE_UNSIGNED (expr_type)))
2188 warning (OPT_Wsign_conversion, "conversion to %qT from %qT "
2189 "may change the sign of the result",
2193 /* Warn for integer types converted to real types if and only if
2194 all the range of values of the integer type cannot be
2195 represented by the real type. */
2196 else if (TREE_CODE (expr_type) == INTEGER_TYPE
2197 && TREE_CODE (type) == REAL_TYPE)
2199 tree type_low_bound, type_high_bound;
2200 REAL_VALUE_TYPE real_low_bound, real_high_bound;
2202 /* Don't warn about char y = 0xff; float x = (int) y; */
2203 expr = get_unwidened (expr, 0);
2204 expr_type = TREE_TYPE (expr);
2206 type_low_bound = TYPE_MIN_VALUE (expr_type);
2207 type_high_bound = TYPE_MAX_VALUE (expr_type);
2208 real_low_bound = real_value_from_int_cst (0, type_low_bound);
2209 real_high_bound = real_value_from_int_cst (0, type_high_bound);
2211 if (!exact_real_truncate (TYPE_MODE (type), &real_low_bound)
2212 || !exact_real_truncate (TYPE_MODE (type), &real_high_bound))
2213 give_warning = true;
2216 /* Warn for real types converted to smaller real types. */
2217 else if (TREE_CODE (expr_type) == REAL_TYPE
2218 && TREE_CODE (type) == REAL_TYPE
2219 && TYPE_PRECISION (type) < TYPE_PRECISION (expr_type))
2220 give_warning = true;
2224 warning (OPT_Wconversion,
2225 "conversion to %qT from %qT may alter its value",
2230 /* Produce warnings after a conversion. RESULT is the result of
2231 converting EXPR to TYPE. This is a helper function for
2232 convert_and_check and cp_convert_and_check. */
2235 warnings_for_convert_and_check (tree type, tree expr, tree result)
2237 if (TREE_CODE (expr) == INTEGER_CST
2238 && (TREE_CODE (type) == INTEGER_TYPE
2239 || TREE_CODE (type) == ENUMERAL_TYPE)
2240 && !int_fits_type_p (expr, type))
2242 /* Do not diagnose overflow in a constant expression merely
2243 because a conversion overflowed. */
2244 if (TREE_OVERFLOW (result))
2245 TREE_OVERFLOW (result) = TREE_OVERFLOW (expr);
2247 if (TYPE_UNSIGNED (type))
2249 /* This detects cases like converting -129 or 256 to
2251 if (!int_fits_type_p (expr, c_common_signed_type (type)))
2252 warning (OPT_Woverflow,
2253 "large integer implicitly truncated to unsigned type");
2255 conversion_warning (type, expr);
2257 else if (!int_fits_type_p (expr, c_common_unsigned_type (type)))
2258 warning (OPT_Woverflow,
2259 "overflow in implicit constant conversion");
2260 /* No warning for converting 0x80000000 to int. */
2262 && (TREE_CODE (TREE_TYPE (expr)) != INTEGER_TYPE
2263 || TYPE_PRECISION (TREE_TYPE (expr))
2264 != TYPE_PRECISION (type)))
2265 warning (OPT_Woverflow,
2266 "overflow in implicit constant conversion");
2269 conversion_warning (type, expr);
2271 else if ((TREE_CODE (result) == INTEGER_CST
2272 || TREE_CODE (result) == FIXED_CST) && TREE_OVERFLOW (result))
2273 warning (OPT_Woverflow,
2274 "overflow in implicit constant conversion");
2276 conversion_warning (type, expr);
2280 /* Convert EXPR to TYPE, warning about conversion problems with constants.
2281 Invoke this function on every expression that is converted implicitly,
2282 i.e. because of language rules and not because of an explicit cast. */
2285 convert_and_check (tree type, tree expr)
2288 tree expr_for_warning;
2290 /* Convert from a value with possible excess precision rather than
2291 via the semantic type, but do not warn about values not fitting
2292 exactly in the semantic type. */
2293 if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
2295 tree orig_type = TREE_TYPE (expr);
2296 expr = TREE_OPERAND (expr, 0);
2297 expr_for_warning = convert (orig_type, expr);
2298 if (orig_type == type)
2299 return expr_for_warning;
2302 expr_for_warning = expr;
2304 if (TREE_TYPE (expr) == type)
2307 result = convert (type, expr);
2309 if (c_inhibit_evaluation_warnings == 0
2310 && !TREE_OVERFLOW_P (expr)
2311 && result != error_mark_node)
2312 warnings_for_convert_and_check (type, expr_for_warning, result);
2317 /* A node in a list that describes references to variables (EXPR), which are
2318 either read accesses if WRITER is zero, or write accesses, in which case
2319 WRITER is the parent of EXPR. */
2326 /* Used to implement a cache the results of a call to verify_tree. We only
2327 use this for SAVE_EXPRs. */
2330 struct tlist_cache *next;
2331 struct tlist *cache_before_sp;
2332 struct tlist *cache_after_sp;
2336 /* Obstack to use when allocating tlist structures, and corresponding
2338 static struct obstack tlist_obstack;
2339 static char *tlist_firstobj = 0;
2341 /* Keep track of the identifiers we've warned about, so we can avoid duplicate
2343 static struct tlist *warned_ids;
2344 /* SAVE_EXPRs need special treatment. We process them only once and then
2345 cache the results. */
2346 static struct tlist_cache *save_expr_cache;
2348 static void add_tlist (struct tlist **, struct tlist *, tree, int);
2349 static void merge_tlist (struct tlist **, struct tlist *, int);
2350 static void verify_tree (tree, struct tlist **, struct tlist **, tree);
2351 static int warning_candidate_p (tree);
2352 static bool candidate_equal_p (const_tree, const_tree);
2353 static void warn_for_collisions (struct tlist *);
2354 static void warn_for_collisions_1 (tree, tree, struct tlist *, int);
2355 static struct tlist *new_tlist (struct tlist *, tree, tree);
2357 /* Create a new struct tlist and fill in its fields. */
2358 static struct tlist *
2359 new_tlist (struct tlist *next, tree t, tree writer)
2362 l = XOBNEW (&tlist_obstack, struct tlist);
2369 /* Add duplicates of the nodes found in ADD to the list *TO. If EXCLUDE_WRITER
2370 is nonnull, we ignore any node we find which has a writer equal to it. */
2373 add_tlist (struct tlist **to, struct tlist *add, tree exclude_writer, int copy)
2377 struct tlist *next = add->next;
2380 if (!exclude_writer || !candidate_equal_p (add->writer, exclude_writer))
2381 *to = copy ? new_tlist (*to, add->expr, add->writer) : add;
2386 /* Merge the nodes of ADD into TO. This merging process is done so that for
2387 each variable that already exists in TO, no new node is added; however if
2388 there is a write access recorded in ADD, and an occurrence on TO is only
2389 a read access, then the occurrence in TO will be modified to record the
2393 merge_tlist (struct tlist **to, struct tlist *add, int copy)
2395 struct tlist **end = to;
2398 end = &(*end)->next;
2404 struct tlist *next = add->next;
2406 for (tmp2 = *to; tmp2; tmp2 = tmp2->next)
2407 if (candidate_equal_p (tmp2->expr, add->expr))
2411 tmp2->writer = add->writer;
2415 *end = copy ? add : new_tlist (NULL, add->expr, add->writer);
2416 end = &(*end)->next;
2423 /* WRITTEN is a variable, WRITER is its parent. Warn if any of the variable
2424 references in list LIST conflict with it, excluding reads if ONLY writers
2428 warn_for_collisions_1 (tree written, tree writer, struct tlist *list,
2433 /* Avoid duplicate warnings. */
2434 for (tmp = warned_ids; tmp; tmp = tmp->next)
2435 if (candidate_equal_p (tmp->expr, written))
2440 if (candidate_equal_p (list->expr, written)
2441 && !candidate_equal_p (list->writer, writer)
2442 && (!only_writes || list->writer))
2444 warned_ids = new_tlist (warned_ids, written, NULL_TREE);
2445 warning_at (EXPR_HAS_LOCATION (writer)
2446 ? EXPR_LOCATION (writer) : input_location,
2447 OPT_Wsequence_point, "operation on %qE may be undefined",
2454 /* Given a list LIST of references to variables, find whether any of these
2455 can cause conflicts due to missing sequence points. */
2458 warn_for_collisions (struct tlist *list)
2462 for (tmp = list; tmp; tmp = tmp->next)
2465 warn_for_collisions_1 (tmp->expr, tmp->writer, list, 0);
2469 /* Return nonzero if X is a tree that can be verified by the sequence point
2472 warning_candidate_p (tree x)
2474 /* !VOID_TYPE_P (TREE_TYPE (x)) is workaround for cp/tree.c
2475 (lvalue_p) crash on TRY/CATCH. */
2476 return !(DECL_P (x) && DECL_ARTIFICIAL (x))
2477 && TREE_TYPE (x) && !VOID_TYPE_P (TREE_TYPE (x)) && lvalue_p (x);
2480 /* Return nonzero if X and Y appear to be the same candidate (or NULL) */
2482 candidate_equal_p (const_tree x, const_tree y)
2484 return (x == y) || (x && y && operand_equal_p (x, y, 0));
2487 /* Walk the tree X, and record accesses to variables. If X is written by the
2488 parent tree, WRITER is the parent.
2489 We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP. If this
2490 expression or its only operand forces a sequence point, then everything up
2491 to the sequence point is stored in PBEFORE_SP. Everything else gets stored
2493 Once we return, we will have emitted warnings if any subexpression before
2494 such a sequence point could be undefined. On a higher level, however, the
2495 sequence point may not be relevant, and we'll merge the two lists.
2497 Example: (b++, a) + b;
2498 The call that processes the COMPOUND_EXPR will store the increment of B
2499 in PBEFORE_SP, and the use of A in PNO_SP. The higher-level call that
2500 processes the PLUS_EXPR will need to merge the two lists so that
2501 eventually, all accesses end up on the same list (and we'll warn about the
2502 unordered subexpressions b++ and b.
2504 A note on merging. If we modify the former example so that our expression
2507 care must be taken not simply to add all three expressions into the final
2508 PNO_SP list. The function merge_tlist takes care of that by merging the
2509 before-SP list of the COMPOUND_EXPR into its after-SP list in a special
2510 way, so that no more than one access to B is recorded. */
2513 verify_tree (tree x, struct tlist **pbefore_sp, struct tlist **pno_sp,
2516 struct tlist *tmp_before, *tmp_nosp, *tmp_list2, *tmp_list3;
2517 enum tree_code code;
2518 enum tree_code_class cl;
2520 /* X may be NULL if it is the operand of an empty statement expression
2526 code = TREE_CODE (x);
2527 cl = TREE_CODE_CLASS (code);
2529 if (warning_candidate_p (x))
2530 *pno_sp = new_tlist (*pno_sp, x, writer);
2538 case TRUTH_ANDIF_EXPR:
2539 case TRUTH_ORIF_EXPR:
2540 tmp_before = tmp_nosp = tmp_list3 = 0;
2541 verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE);
2542 warn_for_collisions (tmp_nosp);
2543 merge_tlist (pbefore_sp, tmp_before, 0);
2544 merge_tlist (pbefore_sp, tmp_nosp, 0);
2545 verify_tree (TREE_OPERAND (x, 1), &tmp_list3, pno_sp, NULL_TREE);
2546 merge_tlist (pbefore_sp, tmp_list3, 0);
2550 tmp_before = tmp_list2 = 0;
2551 verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_list2, NULL_TREE);
2552 warn_for_collisions (tmp_list2);
2553 merge_tlist (pbefore_sp, tmp_before, 0);
2554 merge_tlist (pbefore_sp, tmp_list2, 1);
2556 tmp_list3 = tmp_nosp = 0;
2557 verify_tree (TREE_OPERAND (x, 1), &tmp_list3, &tmp_nosp, NULL_TREE);
2558 warn_for_collisions (tmp_nosp);
2559 merge_tlist (pbefore_sp, tmp_list3, 0);
2561 tmp_list3 = tmp_list2 = 0;
2562 verify_tree (TREE_OPERAND (x, 2), &tmp_list3, &tmp_list2, NULL_TREE);
2563 warn_for_collisions (tmp_list2);
2564 merge_tlist (pbefore_sp, tmp_list3, 0);
2565 /* Rather than add both tmp_nosp and tmp_list2, we have to merge the
2566 two first, to avoid warning for (a ? b++ : b++). */
2567 merge_tlist (&tmp_nosp, tmp_list2, 0);
2568 add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
2571 case PREDECREMENT_EXPR:
2572 case PREINCREMENT_EXPR:
2573 case POSTDECREMENT_EXPR:
2574 case POSTINCREMENT_EXPR:
2575 verify_tree (TREE_OPERAND (x, 0), pno_sp, pno_sp, x);
2579 tmp_before = tmp_nosp = tmp_list3 = 0;
2580 verify_tree (TREE_OPERAND (x, 1), &tmp_before, &tmp_nosp, NULL_TREE);
2581 verify_tree (TREE_OPERAND (x, 0), &tmp_list3, &tmp_list3, x);
2582 /* Expressions inside the LHS are not ordered wrt. the sequence points
2583 in the RHS. Example:
2585 Despite the fact that the modification of "a" is in the before_sp
2586 list (tmp_before), it conflicts with the use of "a" in the LHS.
2587 We can handle this by adding the contents of tmp_list3
2588 to those of tmp_before, and redoing the collision warnings for that
2590 add_tlist (&tmp_before, tmp_list3, x, 1);
2591 warn_for_collisions (tmp_before);
2592 /* Exclude the LHS itself here; we first have to merge it into the
2593 tmp_nosp list. This is done to avoid warning for "a = a"; if we
2594 didn't exclude the LHS, we'd get it twice, once as a read and once
2596 add_tlist (pno_sp, tmp_list3, x, 0);
2597 warn_for_collisions_1 (TREE_OPERAND (x, 0), x, tmp_nosp, 1);
2599 merge_tlist (pbefore_sp, tmp_before, 0);
2600 if (warning_candidate_p (TREE_OPERAND (x, 0)))
2601 merge_tlist (&tmp_nosp, new_tlist (NULL, TREE_OPERAND (x, 0), x), 0);
2602 add_tlist (pno_sp, tmp_nosp, NULL_TREE, 1);
2606 /* We need to warn about conflicts among arguments and conflicts between
2607 args and the function address. Side effects of the function address,
2608 however, are not ordered by the sequence point of the call. */
2610 call_expr_arg_iterator iter;
2612 tmp_before = tmp_nosp = 0;
2613 verify_tree (CALL_EXPR_FN (x), &tmp_before, &tmp_nosp, NULL_TREE);
2614 FOR_EACH_CALL_EXPR_ARG (arg, iter, x)
2616 tmp_list2 = tmp_list3 = 0;
2617 verify_tree (arg, &tmp_list2, &tmp_list3, NULL_TREE);
2618 merge_tlist (&tmp_list3, tmp_list2, 0);
2619 add_tlist (&tmp_before, tmp_list3, NULL_TREE, 0);
2621 add_tlist (&tmp_before, tmp_nosp, NULL_TREE, 0);
2622 warn_for_collisions (tmp_before);
2623 add_tlist (pbefore_sp, tmp_before, NULL_TREE, 0);
2628 /* Scan all the list, e.g. indices of multi dimensional array. */
2631 tmp_before = tmp_nosp = 0;
2632 verify_tree (TREE_VALUE (x), &tmp_before, &tmp_nosp, NULL_TREE);
2633 merge_tlist (&tmp_nosp, tmp_before, 0);
2634 add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
2641 struct tlist_cache *t;
2642 for (t = save_expr_cache; t; t = t->next)
2643 if (candidate_equal_p (t->expr, x))
2648 t = XOBNEW (&tlist_obstack, struct tlist_cache);
2649 t->next = save_expr_cache;
2651 save_expr_cache = t;
2653 tmp_before = tmp_nosp = 0;
2654 verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE);
2655 warn_for_collisions (tmp_nosp);
2660 struct tlist *t = tmp_nosp;
2662 merge_tlist (&tmp_list3, t, 0);
2664 t->cache_before_sp = tmp_before;
2665 t->cache_after_sp = tmp_list3;
2667 merge_tlist (pbefore_sp, t->cache_before_sp, 1);
2668 add_tlist (pno_sp, t->cache_after_sp, NULL_TREE, 1);
2673 x = TREE_OPERAND (x, 0);
2680 /* For other expressions, simply recurse on their operands.
2681 Manual tail recursion for unary expressions.
2682 Other non-expressions need not be processed. */
2683 if (cl == tcc_unary)
2685 x = TREE_OPERAND (x, 0);
2689 else if (IS_EXPR_CODE_CLASS (cl))
2692 int max = TREE_OPERAND_LENGTH (x);
2693 for (lp = 0; lp < max; lp++)
2695 tmp_before = tmp_nosp = 0;
2696 verify_tree (TREE_OPERAND (x, lp), &tmp_before, &tmp_nosp, 0);
2697 merge_tlist (&tmp_nosp, tmp_before, 0);
2698 add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
2705 /* Try to warn for undefined behavior in EXPR due to missing sequence
2709 verify_sequence_points (tree expr)
2711 struct tlist *before_sp = 0, *after_sp = 0;
2714 save_expr_cache = 0;
2715 if (tlist_firstobj == 0)
2717 gcc_obstack_init (&tlist_obstack);
2718 tlist_firstobj = (char *) obstack_alloc (&tlist_obstack, 0);
2721 verify_tree (expr, &before_sp, &after_sp, 0);
2722 warn_for_collisions (after_sp);
2723 obstack_free (&tlist_obstack, tlist_firstobj);
2726 /* Validate the expression after `case' and apply default promotions. */
2729 check_case_value (tree value)
2731 if (value == NULL_TREE)
2734 /* ??? Can we ever get nops here for a valid case value? We
2736 STRIP_TYPE_NOPS (value);
2737 /* In C++, the following is allowed:
2740 switch (...) { case i: ... }
2742 So, we try to reduce the VALUE to a constant that way. */
2743 if (c_dialect_cxx ())
2745 value = decl_constant_value (value);
2746 STRIP_TYPE_NOPS (value);
2747 value = fold (value);
2750 if (TREE_CODE (value) == INTEGER_CST)
2751 /* Promote char or short to int. */
2752 value = perform_integral_promotions (value);
2753 else if (value != error_mark_node)
2755 error ("case label does not reduce to an integer constant");
2756 value = error_mark_node;
2759 constant_expression_warning (value);
2764 /* See if the case values LOW and HIGH are in the range of the original
2765 type (i.e. before the default conversion to int) of the switch testing
2767 TYPE is the promoted type of the testing expression, and ORIG_TYPE is
2768 the type before promoting it. CASE_LOW_P is a pointer to the lower
2769 bound of the case label, and CASE_HIGH_P is the upper bound or NULL
2770 if the case is not a case range.
2771 The caller has to make sure that we are not called with NULL for
2772 CASE_LOW_P (i.e. the default case).
2773 Returns true if the case label is in range of ORIG_TYPE (saturated or
2774 untouched) or false if the label is out of range. */
2777 check_case_bounds (tree type, tree orig_type,
2778 tree *case_low_p, tree *case_high_p)
2780 tree min_value, max_value;
2781 tree case_low = *case_low_p;
2782 tree case_high = case_high_p ? *case_high_p : case_low;
2784 /* If there was a problem with the original type, do nothing. */
2785 if (orig_type == error_mark_node)
2788 min_value = TYPE_MIN_VALUE (orig_type);
2789 max_value = TYPE_MAX_VALUE (orig_type);
2791 /* Case label is less than minimum for type. */
2792 if (tree_int_cst_compare (case_low, min_value) < 0
2793 && tree_int_cst_compare (case_high, min_value) < 0)
2795 warning (0, "case label value is less than minimum value for type");
2799 /* Case value is greater than maximum for type. */
2800 if (tree_int_cst_compare (case_low, max_value) > 0
2801 && tree_int_cst_compare (case_high, max_value) > 0)
2803 warning (0, "case label value exceeds maximum value for type");
2807 /* Saturate lower case label value to minimum. */
2808 if (tree_int_cst_compare (case_high, min_value) >= 0
2809 && tree_int_cst_compare (case_low, min_value) < 0)
2811 warning (0, "lower value in case label range"
2812 " less than minimum value for type");
2813 case_low = min_value;
2816 /* Saturate upper case label value to maximum. */
2817 if (tree_int_cst_compare (case_low, max_value) <= 0
2818 && tree_int_cst_compare (case_high, max_value) > 0)
2820 warning (0, "upper value in case label range"
2821 " exceeds maximum value for type");
2822 case_high = max_value;
2825 if (*case_low_p != case_low)
2826 *case_low_p = convert (type, case_low);
2827 if (case_high_p && *case_high_p != case_high)
2828 *case_high_p = convert (type, case_high);
2833 /* Return an integer type with BITS bits of precision,
2834 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
2837 c_common_type_for_size (unsigned int bits, int unsignedp)
2839 if (bits == TYPE_PRECISION (integer_type_node))
2840 return unsignedp ? unsigned_type_node : integer_type_node;
2842 if (bits == TYPE_PRECISION (signed_char_type_node))
2843 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
2845 if (bits == TYPE_PRECISION (short_integer_type_node))
2846 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
2848 if (bits == TYPE_PRECISION (long_integer_type_node))
2849 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
2851 if (bits == TYPE_PRECISION (long_long_integer_type_node))
2852 return (unsignedp ? long_long_unsigned_type_node
2853 : long_long_integer_type_node);
2855 if (int128_integer_type_node
2856 && bits == TYPE_PRECISION (int128_integer_type_node))
2857 return (unsignedp ? int128_unsigned_type_node
2858 : int128_integer_type_node);
2860 if (bits == TYPE_PRECISION (widest_integer_literal_type_node))
2861 return (unsignedp ? widest_unsigned_literal_type_node
2862 : widest_integer_literal_type_node);
2864 if (bits <= TYPE_PRECISION (intQI_type_node))
2865 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
2867 if (bits <= TYPE_PRECISION (intHI_type_node))
2868 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
2870 if (bits <= TYPE_PRECISION (intSI_type_node))
2871 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
2873 if (bits <= TYPE_PRECISION (intDI_type_node))
2874 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
2879 /* Return a fixed-point type that has at least IBIT ibits and FBIT fbits
2880 that is unsigned if UNSIGNEDP is nonzero, otherwise signed;
2881 and saturating if SATP is nonzero, otherwise not saturating. */
2884 c_common_fixed_point_type_for_size (unsigned int ibit, unsigned int fbit,
2885 int unsignedp, int satp)
2887 enum machine_mode mode;
2889 mode = unsignedp ? UQQmode : QQmode;
2891 mode = unsignedp ? UHAmode : HAmode;
2893 for (; mode != VOIDmode; mode = GET_MODE_WIDER_MODE (mode))
2894 if (GET_MODE_IBIT (mode) >= ibit && GET_MODE_FBIT (mode) >= fbit)
2897 if (mode == VOIDmode || !targetm.scalar_mode_supported_p (mode))
2899 sorry ("GCC cannot support operators with integer types and "
2900 "fixed-point types that have too many integral and "
2901 "fractional bits together");
2905 return c_common_type_for_mode (mode, satp);
2908 /* Used for communication between c_common_type_for_mode and
2909 c_register_builtin_type. */
2910 static GTY(()) tree registered_builtin_types;
2912 /* Return a data type that has machine mode MODE.
2913 If the mode is an integer,
2914 then UNSIGNEDP selects between signed and unsigned types.
2915 If the mode is a fixed-point mode,
2916 then UNSIGNEDP selects between saturating and nonsaturating types. */
2919 c_common_type_for_mode (enum machine_mode mode, int unsignedp)
2923 if (mode == TYPE_MODE (integer_type_node))
2924 return unsignedp ? unsigned_type_node : integer_type_node;
2926 if (mode == TYPE_MODE (signed_char_type_node))
2927 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
2929 if (mode == TYPE_MODE (short_integer_type_node))
2930 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
2932 if (mode == TYPE_MODE (long_integer_type_node))
2933 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
2935 if (mode == TYPE_MODE (long_long_integer_type_node))
2936 return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;
2938 if (int128_integer_type_node
2939 && mode == TYPE_MODE (int128_integer_type_node))
2940 return unsignedp ? int128_unsigned_type_node : int128_integer_type_node;
2942 if (mode == TYPE_MODE (widest_integer_literal_type_node))
2943 return unsignedp ? widest_unsigned_literal_type_node
2944 : widest_integer_literal_type_node;
2947 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
2950 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
2953 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
2956 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
2958 #if HOST_BITS_PER_WIDE_INT >= 64
2959 if (mode == TYPE_MODE (intTI_type_node))
2960 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
2963 if (mode == TYPE_MODE (float_type_node))
2964 return float_type_node;
2966 if (mode == TYPE_MODE (double_type_node))
2967 return double_type_node;
2969 if (mode == TYPE_MODE (long_double_type_node))
2970 return long_double_type_node;
2972 if (mode == TYPE_MODE (void_type_node))
2973 return void_type_node;
2975 if (mode == TYPE_MODE (build_pointer_type (char_type_node)))
2977 ? make_unsigned_type (GET_MODE_PRECISION (mode))
2978 : make_signed_type (GET_MODE_PRECISION (mode)));
2980 if (mode == TYPE_MODE (build_pointer_type (integer_type_node)))
2982 ? make_unsigned_type (GET_MODE_PRECISION (mode))
2983 : make_signed_type (GET_MODE_PRECISION (mode)));
2985 if (COMPLEX_MODE_P (mode))
2987 enum machine_mode inner_mode;
2990 if (mode == TYPE_MODE (complex_float_type_node))
2991 return complex_float_type_node;
2992 if (mode == TYPE_MODE (complex_double_type_node))
2993 return complex_double_type_node;
2994 if (mode == TYPE_MODE (complex_long_double_type_node))
2995 return complex_long_double_type_node;
2997 if (mode == TYPE_MODE (complex_integer_type_node) && !unsignedp)
2998 return complex_integer_type_node;
3000 inner_mode = GET_MODE_INNER (mode);
3001 inner_type = c_common_type_for_mode (inner_mode, unsignedp);
3002 if (inner_type != NULL_TREE)
3003 return build_complex_type (inner_type);
3005 else if (VECTOR_MODE_P (mode))
3007 enum machine_mode inner_mode = GET_MODE_INNER (mode);
3008 tree inner_type = c_common_type_for_mode (inner_mode, unsignedp);
3009 if (inner_type != NULL_TREE)
3010 return build_vector_type_for_mode (inner_type, mode);
3013 if (mode == TYPE_MODE (dfloat32_type_node))
3014 return dfloat32_type_node;
3015 if (mode == TYPE_MODE (dfloat64_type_node))
3016 return dfloat64_type_node;
3017 if (mode == TYPE_MODE (dfloat128_type_node))
3018 return dfloat128_type_node;
3020 if (ALL_SCALAR_FIXED_POINT_MODE_P (mode))
3022 if (mode == TYPE_MODE (short_fract_type_node))
3023 return unsignedp ? sat_short_fract_type_node : short_fract_type_node;
3024 if (mode == TYPE_MODE (fract_type_node))
3025 return unsignedp ? sat_fract_type_node : fract_type_node;
3026 if (mode == TYPE_MODE (long_fract_type_node))
3027 return unsignedp ? sat_long_fract_type_node : long_fract_type_node;
3028 if (mode == TYPE_MODE (long_long_fract_type_node))
3029 return unsignedp ? sat_long_long_fract_type_node
3030 : long_long_fract_type_node;
3032 if (mode == TYPE_MODE (unsigned_short_fract_type_node))
3033 return unsignedp ? sat_unsigned_short_fract_type_node
3034 : unsigned_short_fract_type_node;
3035 if (mode == TYPE_MODE (unsigned_fract_type_node))
3036 return unsignedp ? sat_unsigned_fract_type_node
3037 : unsigned_fract_type_node;
3038 if (mode == TYPE_MODE (unsigned_long_fract_type_node))
3039 return unsignedp ? sat_unsigned_long_fract_type_node
3040 : unsigned_long_fract_type_node;
3041 if (mode == TYPE_MODE (unsigned_long_long_fract_type_node))
3042 return unsignedp ? sat_unsigned_long_long_fract_type_node
3043 : unsigned_long_long_fract_type_node;
3045 if (mode == TYPE_MODE (short_accum_type_node))
3046 return unsignedp ? sat_short_accum_type_node : short_accum_type_node;
3047 if (mode == TYPE_MODE (accum_type_node))
3048 return unsignedp ? sat_accum_type_node : accum_type_node;
3049 if (mode == TYPE_MODE (long_accum_type_node))
3050 return unsignedp ? sat_long_accum_type_node : long_accum_type_node;
3051 if (mode == TYPE_MODE (long_long_accum_type_node))
3052 return unsignedp ? sat_long_long_accum_type_node
3053 : long_long_accum_type_node;
3055 if (mode == TYPE_MODE (unsigned_short_accum_type_node))
3056 return unsignedp ? sat_unsigned_short_accum_type_node
3057 : unsigned_short_accum_type_node;
3058 if (mode == TYPE_MODE (unsigned_accum_type_node))
3059 return unsignedp ? sat_unsigned_accum_type_node
3060 : unsigned_accum_type_node;
3061 if (mode == TYPE_MODE (unsigned_long_accum_type_node))
3062 return unsignedp ? sat_unsigned_long_accum_type_node
3063 : unsigned_long_accum_type_node;
3064 if (mode == TYPE_MODE (unsigned_long_long_accum_type_node))
3065 return unsignedp ? sat_unsigned_long_long_accum_type_node
3066 : unsigned_long_long_accum_type_node;
3069 return unsignedp ? sat_qq_type_node : qq_type_node;
3071 return unsignedp ? sat_hq_type_node : hq_type_node;
3073 return unsignedp ? sat_sq_type_node : sq_type_node;
3075 return unsignedp ? sat_dq_type_node : dq_type_node;
3077 return unsignedp ? sat_tq_type_node : tq_type_node;
3079 if (mode == UQQmode)
3080 return unsignedp ? sat_uqq_type_node : uqq_type_node;
3081 if (mode == UHQmode)
3082 return unsignedp ? sat_uhq_type_node : uhq_type_node;
3083 if (mode == USQmode)
3084 return unsignedp ? sat_usq_type_node : usq_type_node;
3085 if (mode == UDQmode)
3086 return unsignedp ? sat_udq_type_node : udq_type_node;
3087 if (mode == UTQmode)
3088 return unsignedp ? sat_utq_type_node : utq_type_node;
3091 return unsignedp ? sat_ha_type_node : ha_type_node;
3093 return unsignedp ? sat_sa_type_node : sa_type_node;
3095 return unsignedp ? sat_da_type_node : da_type_node;
3097 return unsignedp ? sat_ta_type_node : ta_type_node;
3099 if (mode == UHAmode)
3100 return unsignedp ? sat_uha_type_node : uha_type_node;
3101 if (mode == USAmode)
3102 return unsignedp ? sat_usa_type_node : usa_type_node;
3103 if (mode == UDAmode)
3104 return unsignedp ? sat_uda_type_node : uda_type_node;
3105 if (mode == UTAmode)
3106 return unsignedp ? sat_uta_type_node : uta_type_node;
3109 for (t = registered_builtin_types; t; t = TREE_CHAIN (t))
3110 if (TYPE_MODE (TREE_VALUE (t)) == mode)
3111 return TREE_VALUE (t);
3117 c_common_unsigned_type (tree type)
3119 return c_common_signed_or_unsigned_type (1, type);
3122 /* Return a signed type the same as TYPE in other respects. */
3125 c_common_signed_type (tree type)
3127 return c_common_signed_or_unsigned_type (0, type);
3130 /* Return a type the same as TYPE except unsigned or
3131 signed according to UNSIGNEDP. */
3134 c_common_signed_or_unsigned_type (int unsignedp, tree type)
3138 /* This block of code emulates the behavior of the old
3139 c_common_unsigned_type. In particular, it returns
3140 long_unsigned_type_node if passed a long, even when a int would
3141 have the same size. This is necessary for warnings to work
3142 correctly in archs where sizeof(int) == sizeof(long) */
3144 type1 = TYPE_MAIN_VARIANT (type);
3145 if (type1 == signed_char_type_node || type1 == char_type_node || type1 == unsigned_char_type_node)
3146 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
3147 if (type1 == integer_type_node || type1 == unsigned_type_node)
3148 return unsignedp ? unsigned_type_node : integer_type_node;
3149 if (type1 == short_integer_type_node || type1 == short_unsigned_type_node)
3150 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
3151 if (type1 == long_integer_type_node || type1 == long_unsigned_type_node)
3152 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
3153 if (type1 == long_long_integer_type_node || type1 == long_long_unsigned_type_node)
3154 return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;
3155 if (int128_integer_type_node
3156 && (type1 == int128_integer_type_node
3157 || type1 == int128_unsigned_type_node))
3158 return unsignedp ? int128_unsigned_type_node : int128_integer_type_node;
3159 if (type1 == widest_integer_literal_type_node || type1 == widest_unsigned_literal_type_node)
3160 return unsignedp ? widest_unsigned_literal_type_node : widest_integer_literal_type_node;
3161 #if HOST_BITS_PER_WIDE_INT >= 64
3162 if (type1 == intTI_type_node || type1 == unsigned_intTI_type_node)
3163 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
3165 if (type1 == intDI_type_node || type1 == unsigned_intDI_type_node)
3166 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
3167 if (type1 == intSI_type_node || type1 == unsigned_intSI_type_node)
3168 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
3169 if (type1 == intHI_type_node || type1 == unsigned_intHI_type_node)
3170 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
3171 if (type1 == intQI_type_node || type1 == unsigned_intQI_type_node)
3172 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
3174 #define C_COMMON_FIXED_TYPES(NAME) \
3175 if (type1 == short_ ## NAME ## _type_node \
3176 || type1 == unsigned_short_ ## NAME ## _type_node) \
3177 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
3178 : short_ ## NAME ## _type_node; \
3179 if (type1 == NAME ## _type_node \
3180 || type1 == unsigned_ ## NAME ## _type_node) \
3181 return unsignedp ? unsigned_ ## NAME ## _type_node \
3182 : NAME ## _type_node; \
3183 if (type1 == long_ ## NAME ## _type_node \
3184 || type1 == unsigned_long_ ## NAME ## _type_node) \
3185 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
3186 : long_ ## NAME ## _type_node; \
3187 if (type1 == long_long_ ## NAME ## _type_node \
3188 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
3189 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
3190 : long_long_ ## NAME ## _type_node;
3192 #define C_COMMON_FIXED_MODE_TYPES(NAME) \
3193 if (type1 == NAME ## _type_node \
3194 || type1 == u ## NAME ## _type_node) \
3195 return unsignedp ? u ## NAME ## _type_node \
3196 : NAME ## _type_node;
3198 #define C_COMMON_FIXED_TYPES_SAT(NAME) \
3199 if (type1 == sat_ ## short_ ## NAME ## _type_node \
3200 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
3201 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
3202 : sat_ ## short_ ## NAME ## _type_node; \
3203 if (type1 == sat_ ## NAME ## _type_node \
3204 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
3205 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
3206 : sat_ ## NAME ## _type_node; \
3207 if (type1 == sat_ ## long_ ## NAME ## _type_node \
3208 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
3209 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
3210 : sat_ ## long_ ## NAME ## _type_node; \
3211 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
3212 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
3213 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
3214 : sat_ ## long_long_ ## NAME ## _type_node;
3216 #define C_COMMON_FIXED_MODE_TYPES_SAT(NAME) \
3217 if (type1 == sat_ ## NAME ## _type_node \
3218 || type1 == sat_ ## u ## NAME ## _type_node) \
3219 return unsignedp ? sat_ ## u ## NAME ## _type_node \
3220 : sat_ ## NAME ## _type_node;
3222 C_COMMON_FIXED_TYPES (fract);
3223 C_COMMON_FIXED_TYPES_SAT (fract);
3224 C_COMMON_FIXED_TYPES (accum);
3225 C_COMMON_FIXED_TYPES_SAT (accum);
3227 C_COMMON_FIXED_MODE_TYPES (qq);
3228 C_COMMON_FIXED_MODE_TYPES (hq);
3229 C_COMMON_FIXED_MODE_TYPES (sq);
3230 C_COMMON_FIXED_MODE_TYPES (dq);
3231 C_COMMON_FIXED_MODE_TYPES (tq);
3232 C_COMMON_FIXED_MODE_TYPES_SAT (qq);
3233 C_COMMON_FIXED_MODE_TYPES_SAT (hq);
3234 C_COMMON_FIXED_MODE_TYPES_SAT (sq);
3235 C_COMMON_FIXED_MODE_TYPES_SAT (dq);
3236 C_COMMON_FIXED_MODE_TYPES_SAT (tq);
3237 C_COMMON_FIXED_MODE_TYPES (ha);
3238 C_COMMON_FIXED_MODE_TYPES (sa);
3239 C_COMMON_FIXED_MODE_TYPES (da);
3240 C_COMMON_FIXED_MODE_TYPES (ta);
3241 C_COMMON_FIXED_MODE_TYPES_SAT (ha);
3242 C_COMMON_FIXED_MODE_TYPES_SAT (sa);
3243 C_COMMON_FIXED_MODE_TYPES_SAT (da);
3244 C_COMMON_FIXED_MODE_TYPES_SAT (ta);
3246 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
3247 the precision; they have precision set to match their range, but
3248 may use a wider mode to match an ABI. If we change modes, we may
3249 wind up with bad conversions. For INTEGER_TYPEs in C, must check
3250 the precision as well, so as to yield correct results for
3251 bit-field types. C++ does not have these separate bit-field
3252 types, and producing a signed or unsigned variant of an
3253 ENUMERAL_TYPE may cause other problems as well. */
3255 if (!INTEGRAL_TYPE_P (type)
3256 || TYPE_UNSIGNED (type) == unsignedp)
3259 #define TYPE_OK(node) \
3260 (TYPE_MODE (type) == TYPE_MODE (node) \
3261 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
3262 if (TYPE_OK (signed_char_type_node))
3263 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
3264 if (TYPE_OK (integer_type_node))
3265 return unsignedp ? unsigned_type_node : integer_type_node;
3266 if (TYPE_OK (short_integer_type_node))
3267 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
3268 if (TYPE_OK (long_integer_type_node))
3269 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
3270 if (TYPE_OK (long_long_integer_type_node))
3271 return (unsignedp ? long_long_unsigned_type_node
3272 : long_long_integer_type_node);
3273 if (int128_integer_type_node && TYPE_OK (int128_integer_type_node))
3274 return (unsignedp ? int128_unsigned_type_node
3275 : int128_integer_type_node);
3276 if (TYPE_OK (widest_integer_literal_type_node))
3277 return (unsignedp ? widest_unsigned_literal_type_node
3278 : widest_integer_literal_type_node);
3280 #if HOST_BITS_PER_WIDE_INT >= 64
3281 if (TYPE_OK (intTI_type_node))
3282 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
3284 if (TYPE_OK (intDI_type_node))
3285 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
3286 if (TYPE_OK (intSI_type_node))
3287 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
3288 if (TYPE_OK (intHI_type_node))
3289 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
3290 if (TYPE_OK (intQI_type_node))
3291 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
3294 return build_nonstandard_integer_type (TYPE_PRECISION (type), unsignedp);
3297 /* Build a bit-field integer type for the given WIDTH and UNSIGNEDP. */
3300 c_build_bitfield_integer_type (unsigned HOST_WIDE_INT width, int unsignedp)
3302 /* Extended integer types of the same width as a standard type have
3303 lesser rank, so those of the same width as int promote to int or
3304 unsigned int and are valid for printf formats expecting int or
3305 unsigned int. To avoid such special cases, avoid creating
3306 extended integer types for bit-fields if a standard integer type
3308 if (width == TYPE_PRECISION (integer_type_node))
3309 return unsignedp ? unsigned_type_node : integer_type_node;
3310 if (width == TYPE_PRECISION (signed_char_type_node))
3311 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
3312 if (width == TYPE_PRECISION (short_integer_type_node))
3313 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
3314 if (width == TYPE_PRECISION (long_integer_type_node))
3315 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
3316 if (width == TYPE_PRECISION (long_long_integer_type_node))
3317 return (unsignedp ? long_long_unsigned_type_node
3318 : long_long_integer_type_node);
3319 if (int128_integer_type_node
3320 && width == TYPE_PRECISION (int128_integer_type_node))
3321 return (unsignedp ? int128_unsigned_type_node
3322 : int128_integer_type_node);
3323 return build_nonstandard_integer_type (width, unsignedp);
3326 /* The C version of the register_builtin_type langhook. */
3329 c_register_builtin_type (tree type, const char* name)
3333 decl = build_decl (UNKNOWN_LOCATION,
3334 TYPE_DECL, get_identifier (name), type);
3335 DECL_ARTIFICIAL (decl) = 1;
3336 if (!TYPE_NAME (type))
3337 TYPE_NAME (type) = decl;
3340 registered_builtin_types = tree_cons (0, type, registered_builtin_types);
3343 /* Print an error message for invalid operands to arith operation
3344 CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
3345 LOCATION is the location of the message. */
3348 binary_op_error (location_t location, enum tree_code code,
3349 tree type0, tree type1)
3356 opname = "+"; break;
3358 opname = "-"; break;
3360 opname = "*"; break;
3362 opname = "max"; break;
3364 opname = "min"; break;
3366 opname = "=="; break;
3368 opname = "!="; break;
3370 opname = "<="; break;
3372 opname = ">="; break;
3374 opname = "<"; break;
3376 opname = ">"; break;
3378 opname = "<<"; break;
3380 opname = ">>"; break;
3381 case TRUNC_MOD_EXPR:
3382 case FLOOR_MOD_EXPR:
3383 opname = "%"; break;
3384 case TRUNC_DIV_EXPR:
3385 case FLOOR_DIV_EXPR:
3386 opname = "/"; break;
3388 opname = "&"; break;
3390 opname = "|"; break;
3391 case TRUTH_ANDIF_EXPR:
3392 opname = "&&"; break;
3393 case TRUTH_ORIF_EXPR:
3394 opname = "||"; break;
3396 opname = "^"; break;
3401 "invalid operands to binary %s (have %qT and %qT)", opname,
3405 /* Subroutine of build_binary_op, used for comparison operations.
3406 See if the operands have both been converted from subword integer types
3407 and, if so, perhaps change them both back to their original type.
3408 This function is also responsible for converting the two operands
3409 to the proper common type for comparison.
3411 The arguments of this function are all pointers to local variables
3412 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
3413 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
3415 If this function returns nonzero, it means that the comparison has
3416 a constant value. What this function returns is an expression for
3420 shorten_compare (tree *op0_ptr, tree *op1_ptr, tree *restype_ptr,
3421 enum tree_code *rescode_ptr)
3424 tree op0 = *op0_ptr;
3425 tree op1 = *op1_ptr;
3426 int unsignedp0, unsignedp1;
3428 tree primop0, primop1;
3429 enum tree_code code = *rescode_ptr;
3431 /* Throw away any conversions to wider types
3432 already present in the operands. */
3434 primop0 = get_narrower (op0, &unsignedp0);
3435 primop1 = get_narrower (op1, &unsignedp1);
3437 /* Handle the case that OP0 does not *contain* a conversion
3438 but it *requires* conversion to FINAL_TYPE. */
3440 if (op0 == primop0 && TREE_TYPE (op0) != *restype_ptr)
3441 unsignedp0 = TYPE_UNSIGNED (TREE_TYPE (op0));
3442 if (op1 == primop1 && TREE_TYPE (op1) != *restype_ptr)
3443 unsignedp1 = TYPE_UNSIGNED (TREE_TYPE (op1));
3445 /* If one of the operands must be floated, we cannot optimize. */
3446 real1 = TREE_CODE (TREE_TYPE (primop0)) == REAL_TYPE;
3447 real2 = TREE_CODE (TREE_TYPE (primop1)) == REAL_TYPE;
3449 /* If first arg is constant, swap the args (changing operation
3450 so value is preserved), for canonicalization. Don't do this if
3451 the second arg is 0. */
3453 if (TREE_CONSTANT (primop0)
3454 && !integer_zerop (primop1) && !real_zerop (primop1)
3455 && !fixed_zerop (primop1))
3458 int temi = unsignedp0;
3466 unsignedp0 = unsignedp1;
3489 *rescode_ptr = code;
3492 /* If comparing an integer against a constant more bits wide,
3493 maybe we can deduce a value of 1 or 0 independent of the data.
3494 Or else truncate the constant now
3495 rather than extend the variable at run time.
3497 This is only interesting if the constant is the wider arg.
3498 Also, it is not safe if the constant is unsigned and the
3499 variable arg is signed, since in this case the variable
3500 would be sign-extended and then regarded as unsigned.
3501 Our technique fails in this case because the lowest/highest
3502 possible unsigned results don't follow naturally from the
3503 lowest/highest possible values of the variable operand.
3504 For just EQ_EXPR and NE_EXPR there is another technique that
3505 could be used: see if the constant can be faithfully represented
3506 in the other operand's type, by truncating it and reextending it
3507 and see if that preserves the constant's value. */
3509 if (!real1 && !real2
3510 && TREE_CODE (TREE_TYPE (primop0)) != FIXED_POINT_TYPE
3511 && TREE_CODE (primop1) == INTEGER_CST
3512 && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr))
3514 int min_gt, max_gt, min_lt, max_lt;
3515 tree maxval, minval;
3516 /* 1 if comparison is nominally unsigned. */
3517 int unsignedp = TYPE_UNSIGNED (*restype_ptr);
3520 type = c_common_signed_or_unsigned_type (unsignedp0,
3521 TREE_TYPE (primop0));
3523 maxval = TYPE_MAX_VALUE (type);
3524 minval = TYPE_MIN_VALUE (type);
3526 if (unsignedp && !unsignedp0)
3527 *restype_ptr = c_common_signed_type (*restype_ptr);
3529 if (TREE_TYPE (primop1) != *restype_ptr)
3531 /* Convert primop1 to target type, but do not introduce
3532 additional overflow. We know primop1 is an int_cst. */
3533 primop1 = force_fit_type_double (*restype_ptr,
3534 TREE_INT_CST_LOW (primop1),
3535 TREE_INT_CST_HIGH (primop1), 0,
3536 TREE_OVERFLOW (primop1));
3538 if (type != *restype_ptr)
3540 minval = convert (*restype_ptr, minval);
3541 maxval = convert (*restype_ptr, maxval);
3544 if (unsignedp && unsignedp0)
3546 min_gt = INT_CST_LT_UNSIGNED (primop1, minval);
3547 max_gt = INT_CST_LT_UNSIGNED (primop1, maxval);
3548 min_lt = INT_CST_LT_UNSIGNED (minval, primop1);
3549 max_lt = INT_CST_LT_UNSIGNED (maxval, primop1);
3553 min_gt = INT_CST_LT (primop1, minval);
3554 max_gt = INT_CST_LT (primop1, maxval);
3555 min_lt = INT_CST_LT (minval, primop1);
3556 max_lt = INT_CST_LT (maxval, primop1);
3560 /* This used to be a switch, but Genix compiler can't handle that. */
3561 if (code == NE_EXPR)
3563 if (max_lt || min_gt)
3564 val = truthvalue_true_node;
3566 else if (code == EQ_EXPR)
3568 if (max_lt || min_gt)
3569 val = truthvalue_false_node;
3571 else if (code == LT_EXPR)
3574 val = truthvalue_true_node;
3576 val = truthvalue_false_node;
3578 else if (code == GT_EXPR)
3581 val = truthvalue_true_node;
3583 val = truthvalue_false_node;
3585 else if (code == LE_EXPR)
3588 val = truthvalue_true_node;
3590 val = truthvalue_false_node;
3592 else if (code == GE_EXPR)
3595 val = truthvalue_true_node;
3597 val = truthvalue_false_node;
3600 /* If primop0 was sign-extended and unsigned comparison specd,
3601 we did a signed comparison above using the signed type bounds.
3602 But the comparison we output must be unsigned.
3604 Also, for inequalities, VAL is no good; but if the signed
3605 comparison had *any* fixed result, it follows that the
3606 unsigned comparison just tests the sign in reverse
3607 (positive values are LE, negative ones GE).
3608 So we can generate an unsigned comparison
3609 against an extreme value of the signed type. */
3611 if (unsignedp && !unsignedp0)
3618 primop1 = TYPE_MIN_VALUE (type);
3624 primop1 = TYPE_MAX_VALUE (type);
3631 type = c_common_unsigned_type (type);
3634 if (TREE_CODE (primop0) != INTEGER_CST)
3636 if (val == truthvalue_false_node)
3637 warning (OPT_Wtype_limits, "comparison is always false due to limited range of data type");
3638 if (val == truthvalue_true_node)
3639 warning (OPT_Wtype_limits, "comparison is always true due to limited range of data type");
3644 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
3645 if (TREE_SIDE_EFFECTS (primop0))
3646 return build2 (COMPOUND_EXPR, TREE_TYPE (val), primop0, val);
3650 /* Value is not predetermined, but do the comparison
3651 in the type of the operand that is not constant.
3652 TYPE is already properly set. */
3655 /* If either arg is decimal float and the other is float, find the
3656 proper common type to use for comparison. */
3657 else if (real1 && real2
3658 && (DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0)))
3659 || DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1)))))
3660 type = common_type (TREE_TYPE (primop0), TREE_TYPE (primop1));
3662 else if (real1 && real2
3663 && (TYPE_PRECISION (TREE_TYPE (primop0))
3664 == TYPE_PRECISION (TREE_TYPE (primop1))))
3665 type = TREE_TYPE (primop0);
3667 /* If args' natural types are both narrower than nominal type
3668 and both extend in the same manner, compare them
3669 in the type of the wider arg.
3670 Otherwise must actually extend both to the nominal
3671 common type lest different ways of extending
3673 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
3675 else if (unsignedp0 == unsignedp1 && real1 == real2
3676 && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr)
3677 && TYPE_PRECISION (TREE_TYPE (primop1)) < TYPE_PRECISION (*restype_ptr))
3679 type = common_type (TREE_TYPE (primop0), TREE_TYPE (primop1));
3680 type = c_common_signed_or_unsigned_type (unsignedp0
3681 || TYPE_UNSIGNED (*restype_ptr),
3683 /* Make sure shorter operand is extended the right way
3684 to match the longer operand. */
3686 = convert (c_common_signed_or_unsigned_type (unsignedp0,
3687 TREE_TYPE (primop0)),
3690 = convert (c_common_signed_or_unsigned_type (unsignedp1,
3691 TREE_TYPE (primop1)),
3696 /* Here we must do the comparison on the nominal type
3697 using the args exactly as we received them. */
3698 type = *restype_ptr;
3702 if (!real1 && !real2 && integer_zerop (primop1)
3703 && TYPE_UNSIGNED (*restype_ptr))
3709 /* All unsigned values are >= 0, so we warn. However,
3710 if OP0 is a constant that is >= 0, the signedness of
3711 the comparison isn't an issue, so suppress the
3713 if (warn_type_limits && !in_system_header
3714 && !(TREE_CODE (primop0) == INTEGER_CST
3715 && !TREE_OVERFLOW (convert (c_common_signed_type (type),
3717 warning (OPT_Wtype_limits,
3718 "comparison of unsigned expression >= 0 is always true");
3719 value = truthvalue_true_node;
3723 if (warn_type_limits && !in_system_header
3724 && !(TREE_CODE (primop0) == INTEGER_CST
3725 && !TREE_OVERFLOW (convert (c_common_signed_type (type),
3727 warning (OPT_Wtype_limits,
3728 "comparison of unsigned expression < 0 is always false");
3729 value = truthvalue_false_node;
3738 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
3739 if (TREE_SIDE_EFFECTS (primop0))
3740 return build2 (COMPOUND_EXPR, TREE_TYPE (value),
3747 *op0_ptr = convert (type, primop0);
3748 *op1_ptr = convert (type, primop1);
3750 *restype_ptr = truthvalue_type_node;
3755 /* Return a tree for the sum or difference (RESULTCODE says which)
3756 of pointer PTROP and integer INTOP. */
3759 pointer_int_sum (location_t loc, enum tree_code resultcode,
3760 tree ptrop, tree intop)
3764 /* The result is a pointer of the same type that is being added. */
3765 tree result_type = TREE_TYPE (ptrop);
3767 if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE)
3769 pedwarn (loc, pedantic ? OPT_pedantic : OPT_Wpointer_arith,
3770 "pointer of type %<void *%> used in arithmetic");
3771 size_exp = integer_one_node;
3773 else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE)
3775 pedwarn (loc, pedantic ? OPT_pedantic : OPT_Wpointer_arith,
3776 "pointer to a function used in arithmetic");
3777 size_exp = integer_one_node;
3779 else if (TREE_CODE (TREE_TYPE (result_type)) == METHOD_TYPE)
3781 pedwarn (loc, pedantic ? OPT_pedantic : OPT_Wpointer_arith,
3782 "pointer to member function used in arithmetic");
3783 size_exp = integer_one_node;
3786 size_exp = size_in_bytes (TREE_TYPE (result_type));
3788 /* We are manipulating pointer values, so we don't need to warn
3789 about relying on undefined signed overflow. We disable the
3790 warning here because we use integer types so fold won't know that
3791 they are really pointers. */
3792 fold_defer_overflow_warnings ();
3794 /* If what we are about to multiply by the size of the elements
3795 contains a constant term, apply distributive law
3796 and multiply that constant term separately.
3797 This helps produce common subexpressions. */
3798 if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR)
3799 && !TREE_CONSTANT (intop)
3800 && TREE_CONSTANT (TREE_OPERAND (intop, 1))
3801 && TREE_CONSTANT (size_exp)
3802 /* If the constant comes from pointer subtraction,
3803 skip this optimization--it would cause an error. */
3804 && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop, 0))) == INTEGER_TYPE
3805 /* If the constant is unsigned, and smaller than the pointer size,
3806 then we must skip this optimization. This is because it could cause
3807 an overflow error if the constant is negative but INTOP is not. */
3808 && (!TYPE_UNSIGNED (TREE_TYPE (intop))
3809 || (TYPE_PRECISION (TREE_TYPE (intop))
3810 == TYPE_PRECISION (TREE_TYPE (ptrop)))))
3812 enum tree_code subcode = resultcode;
3813 tree int_type = TREE_TYPE (intop);
3814 if (TREE_CODE (intop) == MINUS_EXPR)
3815 subcode = (subcode == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR);
3816 /* Convert both subexpression types to the type of intop,
3817 because weird cases involving pointer arithmetic
3818 can result in a sum or difference with different type args. */
3819 ptrop = build_binary_op (EXPR_LOCATION (TREE_OPERAND (intop, 1)),
3821 convert (int_type, TREE_OPERAND (intop, 1)), 1);
3822 intop = convert (int_type, TREE_OPERAND (intop, 0));
3825 /* Convert the integer argument to a type the same size as sizetype
3826 so the multiply won't overflow spuriously. */
3827 if (TYPE_PRECISION (TREE_TYPE (intop)) != TYPE_PRECISION (sizetype)
3828 || TYPE_UNSIGNED (TREE_TYPE (intop)) != TYPE_UNSIGNED (sizetype))
3829 intop = convert (c_common_type_for_size (TYPE_PRECISION (sizetype),
3830 TYPE_UNSIGNED (sizetype)), intop);
3832 /* Replace the integer argument with a suitable product by the object size.
3833 Do this multiplication as signed, then convert to the appropriate type
3834 for the pointer operation and disregard an overflow that occured only
3835 because of the sign-extension change in the latter conversion. */
3837 tree t = build_binary_op (loc,
3839 convert (TREE_TYPE (intop), size_exp), 1);
3840 intop = convert (sizetype, t);
3841 if (TREE_OVERFLOW_P (intop) && !TREE_OVERFLOW (t))
3842 intop = build_int_cst_wide (TREE_TYPE (intop), TREE_INT_CST_LOW (intop),
3843 TREE_INT_CST_HIGH (intop));
3846 /* Create the sum or difference. */
3847 if (resultcode == MINUS_EXPR)
3848 intop = fold_build1_loc (loc, NEGATE_EXPR, sizetype, intop);
3850 ret = fold_build2_loc (loc, POINTER_PLUS_EXPR, result_type, ptrop, intop);
3852 fold_undefer_and_ignore_overflow_warnings ();
3857 /* Wrap a C_MAYBE_CONST_EXPR around an expression that is fully folded
3858 and if NON_CONST is known not to be permitted in an evaluated part
3859 of a constant expression. */
3862 c_wrap_maybe_const (tree expr, bool non_const)
3864 bool nowarning = TREE_NO_WARNING (expr);
3865 location_t loc = EXPR_LOCATION (expr);
3867 /* This should never be called for C++. */
3868 if (c_dialect_cxx ())
3871 /* The result of folding may have a NOP_EXPR to set TREE_NO_WARNING. */
3872 STRIP_TYPE_NOPS (expr);
3873 expr = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (expr), NULL, expr);
3874 C_MAYBE_CONST_EXPR_NON_CONST (expr) = non_const;
3876 TREE_NO_WARNING (expr) = 1;
3877 protected_set_expr_location (expr, loc);
3882 /* Wrap a SAVE_EXPR around EXPR, if appropriate. Like save_expr, but
3883 for C folds the inside expression and wraps a C_MAYBE_CONST_EXPR
3884 around the SAVE_EXPR if needed so that c_fully_fold does not need
3885 to look inside SAVE_EXPRs. */
3888 c_save_expr (tree expr)
3890 bool maybe_const = true;
3891 if (c_dialect_cxx ())
3892 return save_expr (expr);
3893 expr = c_fully_fold (expr, false, &maybe_const);
3894 expr = save_expr (expr);
3896 expr = c_wrap_maybe_const (expr, true);
3900 /* Return whether EXPR is a declaration whose address can never be
3904 decl_with_nonnull_addr_p (const_tree expr)
3906 return (DECL_P (expr)
3907 && (TREE_CODE (expr) == PARM_DECL
3908 || TREE_CODE (expr) == LABEL_DECL
3909 || !DECL_WEAK (expr)));
3912 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
3913 or for an `if' or `while' statement or ?..: exp. It should already
3914 have been validated to be of suitable type; otherwise, a bad
3915 diagnostic may result.
3917 The EXPR is located at LOCATION.
3919 This preparation consists of taking the ordinary
3920 representation of an expression expr and producing a valid tree
3921 boolean expression describing whether expr is nonzero. We could
3922 simply always do build_binary_op (NE_EXPR, expr, truthvalue_false_node, 1),
3923 but we optimize comparisons, &&, ||, and !.
3925 The resulting type should always be `truthvalue_type_node'. */
3928 c_common_truthvalue_conversion (location_t location, tree expr)
3930 switch (TREE_CODE (expr))
3932 case EQ_EXPR: case NE_EXPR: case UNEQ_EXPR: case LTGT_EXPR:
3933 case LE_EXPR: case GE_EXPR: case LT_EXPR: case GT_EXPR:
3934 case UNLE_EXPR: case UNGE_EXPR: case UNLT_EXPR: case UNGT_EXPR:
3935 case ORDERED_EXPR: case UNORDERED_EXPR:
3936 if (TREE_TYPE (expr) == truthvalue_type_node)
3938 expr = build2 (TREE_CODE (expr), truthvalue_type_node,
3939 TREE_OPERAND (expr, 0), TREE_OPERAND (expr, 1));
3942 case TRUTH_ANDIF_EXPR:
3943 case TRUTH_ORIF_EXPR:
3944 case TRUTH_AND_EXPR:
3946 case TRUTH_XOR_EXPR:
3947 if (TREE_TYPE (expr) == truthvalue_type_node)
3949 expr = build2 (TREE_CODE (expr), truthvalue_type_node,
3950 c_common_truthvalue_conversion (location,
3951 TREE_OPERAND (expr, 0)),
3952 c_common_truthvalue_conversion (location,
3953 TREE_OPERAND (expr, 1)));
3956 case TRUTH_NOT_EXPR:
3957 if (TREE_TYPE (expr) == truthvalue_type_node)
3959 expr = build1 (TREE_CODE (expr), truthvalue_type_node,
3960 c_common_truthvalue_conversion (location,
3961 TREE_OPERAND (expr, 0)));
3968 return integer_zerop (expr) ? truthvalue_false_node
3969 : truthvalue_true_node;
3972 return real_compare (NE_EXPR, &TREE_REAL_CST (expr), &dconst0)
3973 ? truthvalue_true_node
3974 : truthvalue_false_node;
3977 return fixed_compare (NE_EXPR, &TREE_FIXED_CST (expr),
3978 &FCONST0 (TYPE_MODE (TREE_TYPE (expr))))
3979 ? truthvalue_true_node
3980 : truthvalue_false_node;
3983 expr = build_unary_op (location, ADDR_EXPR, expr, 0);
3988 tree inner = TREE_OPERAND (expr, 0);
3989 if (decl_with_nonnull_addr_p (inner))
3991 /* Common Ada/Pascal programmer's mistake. */
3992 warning_at (location,
3994 "the address of %qD will always evaluate as %<true%>",
3996 return truthvalue_true_node;
3999 /* If we still have a decl, it is possible for its address to
4000 be NULL, so we cannot optimize. */
4003 gcc_assert (DECL_WEAK (inner));
4007 if (TREE_SIDE_EFFECTS (inner))
4009 expr = build2 (COMPOUND_EXPR, truthvalue_type_node,
4010 inner, truthvalue_true_node);
4014 return truthvalue_true_node;
4018 expr = build_binary_op (EXPR_LOCATION (expr),
4019 (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1))
4020 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
4021 c_common_truthvalue_conversion (location,
4022 TREE_OPERAND (expr, 0)),
4023 c_common_truthvalue_conversion (location,