LCOV - code coverage report
Current view: top level - gcc/c-family - c-common.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 91.9 % 4406 4049
Test Date: 2026-06-20 15:32:29 Functions: 98.8 % 165 163
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Subroutines shared by all languages that are variants of C.
       2              :    Copyright (C) 1992-2026 Free Software Foundation, Inc.
       3              : 
       4              : This file is part of GCC.
       5              : 
       6              : GCC is free software; you can redistribute it and/or modify it under
       7              : the terms of the GNU General Public License as published by the Free
       8              : Software Foundation; either version 3, or (at your option) any later
       9              : version.
      10              : 
      11              : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      12              : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13              : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      14              : for more details.
      15              : 
      16              : You should have received a copy of the GNU General Public License
      17              : along with GCC; see the file COPYING3.  If not see
      18              : <http://www.gnu.org/licenses/>.  */
      19              : 
      20              : #define GCC_C_COMMON_C
      21              : 
      22              : #include "config.h"
      23              : #include "system.h"
      24              : #include "coretypes.h"
      25              : #include "target.h"
      26              : #include "function.h"
      27              : #include "tree.h"
      28              : #include "memmodel.h"
      29              : #include "c-common.h"
      30              : #include "gimple-expr.h"
      31              : #include "tm_p.h"
      32              : #include "stringpool.h"
      33              : #include "cgraph.h"
      34              : #include "diagnostic.h"
      35              : #include "intl.h"
      36              : #include "stor-layout.h"
      37              : #include "calls.h"
      38              : #include "attribs.h"
      39              : #include "varasm.h"
      40              : #include "trans-mem.h"
      41              : #include "c-objc.h"
      42              : #include "common/common-target.h"
      43              : #include "langhooks.h"
      44              : #include "tree-inline.h"
      45              : #include "toplev.h"
      46              : #include "tree-iterator.h"
      47              : #include "opts.h"
      48              : #include "gimplify.h"
      49              : #include "substring-locations.h"
      50              : #include "spellcheck.h"
      51              : #include "c-spellcheck.h"
      52              : #include "selftest.h"
      53              : #include "debug.h"
      54              : #include "tree-vector-builder.h"
      55              : #include "vec-perm-indices.h"
      56              : #include "tree-pretty-print-markup.h"
      57              : #include "gcc-rich-location.h"
      58              : #include "gcc-urlifier.h"
      59              : #include "diagnostics/diagnostics-selftests.h"
      60              : 
      61              : cpp_reader *parse_in;           /* Declared in c-pragma.h.  */
      62              : 
      63              : /* Mode used to build pointers (VOIDmode means ptr_mode).  */
      64              : 
      65              : machine_mode c_default_pointer_mode = VOIDmode;
      66              : 
      67              : /* The following symbols are subsumed in the c_global_trees array, and
      68              :    listed here individually for documentation purposes.
      69              : 
      70              :    INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
      71              : 
      72              :         tree short_integer_type_node;
      73              :         tree long_integer_type_node;
      74              :         tree long_long_integer_type_node;
      75              : 
      76              :         tree short_unsigned_type_node;
      77              :         tree long_unsigned_type_node;
      78              :         tree long_long_unsigned_type_node;
      79              : 
      80              :         tree truthvalue_type_node;
      81              :         tree truthvalue_false_node;
      82              :         tree truthvalue_true_node;
      83              : 
      84              :         tree ptrdiff_type_node;
      85              : 
      86              :         tree unsigned_char_type_node;
      87              :         tree signed_char_type_node;
      88              :         tree wchar_type_node;
      89              : 
      90              :         tree char8_type_node;
      91              :         tree char16_type_node;
      92              :         tree char32_type_node;
      93              : 
      94              :         tree float_type_node;
      95              :         tree double_type_node;
      96              :         tree long_double_type_node;
      97              : 
      98              :         tree complex_integer_type_node;
      99              :         tree complex_float_type_node;
     100              :         tree complex_double_type_node;
     101              :         tree complex_long_double_type_node;
     102              : 
     103              :         tree dfloat32_type_node;
     104              :         tree dfloat64_type_node;
     105              :         tree dfloat128_type_node;
     106              :         tree dfloat64x_type_node;
     107              : 
     108              :         tree intQI_type_node;
     109              :         tree intHI_type_node;
     110              :         tree intSI_type_node;
     111              :         tree intDI_type_node;
     112              :         tree intTI_type_node;
     113              : 
     114              :         tree unsigned_intQI_type_node;
     115              :         tree unsigned_intHI_type_node;
     116              :         tree unsigned_intSI_type_node;
     117              :         tree unsigned_intDI_type_node;
     118              :         tree unsigned_intTI_type_node;
     119              : 
     120              :         tree widest_integer_literal_type_node;
     121              :         tree widest_unsigned_literal_type_node;
     122              : 
     123              :    Nodes for types `void *' and `const void *'.
     124              : 
     125              :         tree ptr_type_node, const_ptr_type_node;
     126              : 
     127              :    Nodes for types `char *' and `const char *'.
     128              : 
     129              :         tree string_type_node, const_string_type_node;
     130              : 
     131              :    Type `char[SOMENUMBER]'.
     132              :    Used when an array of char is needed and the size is irrelevant.
     133              : 
     134              :         tree char_array_type_node;
     135              : 
     136              :    Type `wchar_t[SOMENUMBER]' or something like it.
     137              :    Used when a wide string literal is created.
     138              : 
     139              :         tree wchar_array_type_node;
     140              : 
     141              :    Type `char8_t[SOMENUMBER]' or something like it.
     142              :    Used when a UTF-8 string literal is created.
     143              : 
     144              :         tree char8_array_type_node;
     145              : 
     146              :    Type `char16_t[SOMENUMBER]' or something like it.
     147              :    Used when a UTF-16 string literal is created.
     148              : 
     149              :         tree char16_array_type_node;
     150              : 
     151              :    Type `char32_t[SOMENUMBER]' or something like it.
     152              :    Used when a UTF-32 string literal is created.
     153              : 
     154              :         tree char32_array_type_node;
     155              : 
     156              :    Type `int ()' -- used for implicit declaration of functions.
     157              : 
     158              :         tree default_function_type;
     159              : 
     160              :    A VOID_TYPE node, packaged in a TREE_LIST.
     161              : 
     162              :         tree void_list_node;
     163              : 
     164              :   The lazily created VAR_DECLs for __FUNCTION__, __PRETTY_FUNCTION__,
     165              :   and __func__. (C doesn't generate __FUNCTION__ and__PRETTY_FUNCTION__
     166              :   VAR_DECLS, but C++ does.)
     167              : 
     168              :         tree function_name_decl_node;
     169              :         tree pretty_function_name_decl_node;
     170              :         tree c99_function_name_decl_node;
     171              : 
     172              :   Stack of nested function name VAR_DECLs.
     173              : 
     174              :         tree saved_function_name_decls;
     175              : 
     176              : */
     177              : 
     178              : tree c_global_trees[CTI_MAX];
     179              : 
     180              : /* Switches common to the C front ends.  */
     181              : 
     182              : /* Nonzero means don't output line number information.  */
     183              : 
     184              : char flag_no_line_commands;
     185              : 
     186              : /* Nonzero causes -E output not to be done, but directives such as
     187              :    #define that have side effects are still obeyed.  */
     188              : 
     189              : char flag_no_output;
     190              : 
     191              : /* Nonzero means dump macros in some fashion.  */
     192              : 
     193              : char flag_dump_macros;
     194              : 
     195              : /* Nonzero means pass #include lines through to the output.  */
     196              : 
     197              : char flag_dump_includes;
     198              : 
     199              : /* Nonzero means process PCH files while preprocessing.  */
     200              : 
     201              : bool flag_pch_preprocess;
     202              : 
     203              : /* The file name to which we should write a precompiled header, or
     204              :    NULL if no header will be written in this compile.  */
     205              : 
     206              : const char *pch_file;
     207              : 
     208              : /* Nonzero if an ISO standard was selected.  It rejects macros in the
     209              :    user's namespace.  */
     210              : int flag_iso;
     211              : 
     212              : /* C/ObjC language option variables.  */
     213              : 
     214              : 
     215              : /* Nonzero means allow type mismatches in conditional expressions;
     216              :    just make their values `void'.  */
     217              : 
     218              : int flag_cond_mismatch;
     219              : 
     220              : /* Nonzero means enable C89 Amendment 1 features.  */
     221              : 
     222              : int flag_isoc94;
     223              : 
     224              : /* Nonzero means use the ISO C99 (or later) dialect of C.  */
     225              : 
     226              : int flag_isoc99;
     227              : 
     228              : /* Nonzero means use the ISO C11 (or later) dialect of C.  */
     229              : 
     230              : int flag_isoc11;
     231              : 
     232              : /* Nonzero means use the ISO C23 (or later) dialect of C.  */
     233              : 
     234              : int flag_isoc23;
     235              : 
     236              : /* Nonzero means use the ISO C2Y (or later) dialect of C.  */
     237              : 
     238              : int flag_isoc2y;
     239              : 
     240              : /* Nonzero means that we have builtin functions, and main is an int.  */
     241              : 
     242              : int flag_hosted = 1;
     243              : 
     244              : 
     245              : /* ObjC language option variables.  */
     246              : 
     247              : 
     248              : /* Tells the compiler that this is a special run.  Do not perform any
     249              :    compiling, instead we are to test some platform dependent features
     250              :    and output a C header file with appropriate definitions.  */
     251              : 
     252              : int print_struct_values;
     253              : 
     254              : /* Tells the compiler what is the constant string class for ObjC.  */
     255              : 
     256              : const char *constant_string_class_name;
     257              : 
     258              : 
     259              : /* C++ language option variables.  */
     260              : 
     261              : /* The reference version of the ABI for -Wabi.  */
     262              : 
     263              : int warn_abi_version = -1;
     264              : 
     265              : /* The C++ dialect being used.  Default set in c_common_init_options.  */
     266              : 
     267              : enum cxx_dialect cxx_dialect = cxx_unset;
     268              : 
     269              : /* Maximum template instantiation depth.  This limit exists to limit the
     270              :    time it takes to notice excessively recursive template instantiations.
     271              : 
     272              :    The default is lower than the 1024 recommended by the C++0x standard
     273              :    because G++ runs out of stack before 1024 with highly recursive template
     274              :    argument deduction substitution (g++.dg/cpp0x/enum11.C).  */
     275              : 
     276              : int max_tinst_depth = 900;
     277              : 
     278              : /* The elements of `ridpointers' are identifier nodes for the reserved
     279              :    type names and storage classes.  It is indexed by a RID_... value.  */
     280              : tree *ridpointers;
     281              : 
     282              : tree (*make_fname_decl) (location_t, tree, int);
     283              : 
     284              : /* Nonzero means don't warn about problems that occur when the code is
     285              :    executed.  */
     286              : int c_inhibit_evaluation_warnings;
     287              : 
     288              : /* Whether we are building a boolean conversion inside
     289              :    convert_for_assignment, or some other late binary operation.  If
     290              :    build_binary_op is called for C (from code shared by C and C++) in
     291              :    this case, then the operands have already been folded and the
     292              :    result will not be folded again, so C_MAYBE_CONST_EXPR should not
     293              :    be generated.  */
     294              : bool in_late_binary_op;
     295              : 
     296              : /* Depending on which phase of processing we are in, we may need
     297              :    to prefer input_location to libcpp's locations.  (Specifically,
     298              :    after the C++ lexer is done lexing tokens, but prior to calling
     299              :    cpp_finish (), we need to do so.  */
     300              : bool override_libcpp_locations;
     301              : 
     302              : /* Information about how a function name is generated.  */
     303              : struct fname_var_t
     304              : {
     305              :   tree *const decl;     /* pointer to the VAR_DECL.  */
     306              :   const unsigned rid;   /* RID number for the identifier.  */
     307              :   const int pretty;     /* How pretty is it? */
     308              : };
     309              : 
     310              : /* The three ways of getting then name of the current function.  */
     311              : 
     312              : const struct fname_var_t fname_vars[] =
     313              : {
     314              :   /* C99 compliant __func__, must be first.  */
     315              :   {&c99_function_name_decl_node, RID_C99_FUNCTION_NAME, 0},
     316              :   /* GCC __FUNCTION__ compliant.  */
     317              :   {&function_name_decl_node, RID_FUNCTION_NAME, 0},
     318              :   /* GCC __PRETTY_FUNCTION__ compliant.  */
     319              :   {&pretty_function_name_decl_node, RID_PRETTY_FUNCTION_NAME, 1},
     320              :   {NULL, 0, 0},
     321              : };
     322              : 
     323              : /* Flags to restrict availability of generic features that
     324              :    are known to __has_{feature,extension}.  */
     325              : 
     326              : enum
     327              : {
     328              :   HF_FLAG_NONE = 0,
     329              :   HF_FLAG_EXT = 1,      /* Available only as an extension.  */
     330              :   HF_FLAG_SANITIZE = 2, /* Availability depends on sanitizer flags.  */
     331              : };
     332              : 
     333              : /* Info for generic features which can be queried through
     334              :    __has_{feature,extension}.  */
     335              : 
     336              : struct hf_feature_info
     337              : {
     338              :   const char *ident;
     339              :   unsigned flags;
     340              :   unsigned mask;
     341              : };
     342              : 
     343              : /* Table of generic features which can be queried through
     344              :    __has_{feature,extension}.  */
     345              : 
     346              : static constexpr hf_feature_info has_feature_table[] =
     347              : {
     348              :   { "address_sanitizer",          HF_FLAG_SANITIZE, SANITIZE_ADDRESS },
     349              :   { "thread_sanitizer",                   HF_FLAG_SANITIZE, SANITIZE_THREAD },
     350              :   { "leak_sanitizer",             HF_FLAG_SANITIZE, SANITIZE_LEAK },
     351              :   { "hwaddress_sanitizer",        HF_FLAG_SANITIZE, SANITIZE_HWADDRESS },
     352              :   { "undefined_behavior_sanitizer", HF_FLAG_SANITIZE, SANITIZE_UNDEFINED },
     353              :   { "attribute_deprecated_with_message",  HF_FLAG_NONE, 0 },
     354              :   { "attribute_unavailable_with_message", HF_FLAG_NONE, 0 },
     355              :   { "enumerator_attributes",            HF_FLAG_NONE, 0 },
     356              :   { "tls",                              HF_FLAG_NONE, 0 },
     357              :   { "gnu_asm_goto_with_outputs",        HF_FLAG_EXT, 0 },
     358              :   { "gnu_asm_goto_with_outputs_full",   HF_FLAG_EXT, 0 }
     359              : };
     360              : 
     361              : /* Global visibility options.  */
     362              : struct visibility_flags visibility_options;
     363              : 
     364              : static tree check_case_value (location_t, tree);
     365              : 
     366              : 
     367              : static void check_nonnull_arg (void *, tree, unsigned HOST_WIDE_INT);
     368              : static bool nonnull_check_p (tree, unsigned HOST_WIDE_INT);
     369              : 
     370              : /* Reserved words.  The third field is a mask: keywords are disabled
     371              :    if they match the mask.
     372              : 
     373              :    Masks for languages:
     374              :    C --std=c89: D_C99 | D_C23 | D_CXXONLY | D_OBJC | D_CXX_OBJC
     375              :    C --std=c99: D_C23 | D_CXXONLY | D_OBJC
     376              :    C --std=c17: D_C23 | D_CXXONLY | D_OBJC
     377              :    C --std=c23: D_CXXONLY | D_OBJC
     378              :    ObjC is like C except that D_OBJC and D_CXX_OBJC are not set
     379              :    C++ --std=c++98: D_CONLY | D_CXX11 | D_CXX20 | D_CXX26 | D_OBJC
     380              :    C++ --std=c++11: D_CONLY | D_CXX20 | D_CXX26 | D_OBJC
     381              :    C++ --std=c++20: D_CONLY | D_CXX26 | D_OBJC
     382              :    C++ --std=c++26: D_CONLY | D_OBJC
     383              :    ObjC++ is like C++ except that D_OBJC is not set
     384              : 
     385              :    If -fno-asm is used, D_ASM is added to the mask.  If
     386              :    -fno-gnu-keywords is used, D_EXT is added.  If -fno-asm and C in
     387              :    C89 mode, D_EXT89 is added for both -fno-asm and -fno-gnu-keywords.
     388              :    In C with -Wc++-compat, we warn if D_CXXWARN is set.
     389              : 
     390              :    Note the complication of the D_CXX_OBJC keywords.  These are
     391              :    reserved words such as 'class'.  In C++, 'class' is a reserved
     392              :    word.  In Objective-C++ it is too.  In Objective-C, it is a
     393              :    reserved word too, but only if it follows an '@' sign.
     394              : */
     395              : const struct c_common_resword c_common_reswords[] =
     396              : {
     397              :   { "_Alignas",               RID_ALIGNAS,   D_CONLY },
     398              :   { "_Alignof",               RID_ALIGNOF,   D_CONLY },
     399              :   { "_Countof",               RID_COUNTOF,   D_CONLY },
     400              :   { "_Maxof",         RID_MAXOF,     D_CONLY },
     401              :   { "_Minof",         RID_MINOF,     D_CONLY },
     402              :   { "_Atomic",                RID_ATOMIC,    D_CONLY },
     403              :   { "_BitInt",                RID_BITINT,    D_CONLY },
     404              :   { "_Bool",          RID_BOOL,      D_CONLY },
     405              :   { "_Complex",               RID_COMPLEX,    0 },
     406              :   { "_Imaginary",     RID_IMAGINARY, D_CONLY },
     407              :   { "_Float16",         RID_FLOAT16,    0 },
     408              :   { "_Float32",         RID_FLOAT32,    0 },
     409              :   { "_Float64",         RID_FLOAT64,    0 },
     410              :   { "_Float128",        RID_FLOAT128,   0 },
     411              :   { "_Float32x",        RID_FLOAT32X,   0 },
     412              :   { "_Float64x",        RID_FLOAT64X,   0 },
     413              :   { "_Float128x",       RID_FLOAT128X,  0 },
     414              :   { "_Decimal32",       RID_DFLOAT32,  D_CONLY },
     415              :   { "_Decimal64",       RID_DFLOAT64,  D_CONLY },
     416              :   { "_Decimal128",      RID_DFLOAT128, D_CONLY },
     417              :   { "_Decimal64x",      RID_DFLOAT64X, D_CONLY },
     418              :   { "_Fract",           RID_FRACT,     D_CONLY | D_EXT },
     419              :   { "_Accum",           RID_ACCUM,     D_CONLY | D_EXT },
     420              :   { "_Sat",             RID_SAT,       D_CONLY | D_EXT },
     421              :   { "_Static_assert",   RID_STATIC_ASSERT, D_CONLY },
     422              :   { "_Noreturn",        RID_NORETURN,  D_CONLY },
     423              :   { "_Generic",         RID_GENERIC,   D_CONLY },
     424              :   { "_Thread_local",    RID_THREAD,    D_CONLY },
     425              :   { "__FUNCTION__",   RID_FUNCTION_NAME, 0 },
     426              :   { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
     427              :   { "__alignof",      RID_ALIGNOF,    0 },
     428              :   { "__alignof__",    RID_ALIGNOF,    0 },
     429              :   { "__asm",          RID_ASM,        0 },
     430              :   { "__asm__",                RID_ASM,        0 },
     431              :   { "__attribute",    RID_ATTRIBUTE,  0 },
     432              :   { "__attribute__",  RID_ATTRIBUTE,  0 },
     433              :   { "__auto_type",    RID_AUTO_TYPE,  D_CONLY },
     434              :   { "__builtin_addressof", RID_ADDRESSOF, D_CXXONLY },
     435              :   { "__builtin_assoc_barrier", RID_BUILTIN_ASSOC_BARRIER, 0 },
     436              :   { "__builtin_bitreverseg", RID_BUILTIN_BITREVERSEG, 0 },
     437              :   { "__builtin_bit_cast", RID_BUILTIN_BIT_CAST, D_CXXONLY },
     438              :   { "__builtin_bswapg", RID_BUILTIN_BSWAPG, 0 },
     439              :   { "__builtin_call_with_static_chain",
     440              :     RID_BUILTIN_CALL_WITH_STATIC_CHAIN, D_CONLY },
     441              :   { "__builtin_choose_expr", RID_CHOOSE_EXPR, D_CONLY },
     442              :   { "__builtin_complex", RID_BUILTIN_COMPLEX, D_CONLY },
     443              :   { "__builtin_convertvector", RID_BUILTIN_CONVERTVECTOR, 0 },
     444              :   { "__builtin_counted_by_ref", RID_BUILTIN_COUNTED_BY_REF, D_CONLY },
     445              :   { "__builtin_has_attribute", RID_BUILTIN_HAS_ATTRIBUTE, 0 },
     446              :   { "__builtin_launder", RID_BUILTIN_LAUNDER, D_CXXONLY },
     447              :   { "__builtin_operator_new", RID_BUILTIN_OPERATOR_NEW, D_CXXONLY },
     448              :   { "__builtin_operator_delete", RID_BUILTIN_OPERATOR_DELETE, D_CXXONLY },
     449              :   { "__builtin_shuffle", RID_BUILTIN_SHUFFLE, 0 },
     450              :   { "__builtin_shufflevector", RID_BUILTIN_SHUFFLEVECTOR, 0 },
     451              :   { "__builtin_stdc_bit_ceil", RID_BUILTIN_STDC, D_CONLY },
     452              :   { "__builtin_stdc_bit_floor", RID_BUILTIN_STDC, D_CONLY },
     453              :   { "__builtin_stdc_bit_width", RID_BUILTIN_STDC, D_CONLY },
     454              :   { "__builtin_stdc_count_ones", RID_BUILTIN_STDC, D_CONLY },
     455              :   { "__builtin_stdc_count_zeros", RID_BUILTIN_STDC, D_CONLY },
     456              :   { "__builtin_stdc_first_leading_one", RID_BUILTIN_STDC, D_CONLY },
     457              :   { "__builtin_stdc_first_leading_zero", RID_BUILTIN_STDC, D_CONLY },
     458              :   { "__builtin_stdc_first_trailing_one", RID_BUILTIN_STDC, D_CONLY },
     459              :   { "__builtin_stdc_first_trailing_zero", RID_BUILTIN_STDC, D_CONLY },
     460              :   { "__builtin_stdc_has_single_bit", RID_BUILTIN_STDC, D_CONLY },
     461              :   { "__builtin_stdc_leading_ones", RID_BUILTIN_STDC, D_CONLY },
     462              :   { "__builtin_stdc_leading_zeros", RID_BUILTIN_STDC, D_CONLY },
     463              :   { "__builtin_stdc_rotate_left", RID_BUILTIN_STDC, D_CONLY },
     464              :   { "__builtin_stdc_rotate_right", RID_BUILTIN_STDC, D_CONLY },
     465              :   { "__builtin_stdc_trailing_ones", RID_BUILTIN_STDC, D_CONLY },
     466              :   { "__builtin_stdc_trailing_zeros", RID_BUILTIN_STDC, D_CONLY },
     467              :   { "__builtin_tgmath", RID_BUILTIN_TGMATH, D_CONLY },
     468              :   { "__builtin_offsetof", RID_OFFSETOF, 0 },
     469              :   { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, D_CONLY },
     470              :   { "__builtin_c23_va_start", RID_C23_VA_START,       D_C23 | D_CXX26 },
     471              :   { "__builtin_va_arg",       RID_VA_ARG,     0 },
     472              :   { "__complex",      RID_COMPLEX,    0 },
     473              :   { "__complex__",    RID_COMPLEX,    0 },
     474              :   { "__const",                RID_CONST,      0 },
     475              :   { "__const__",      RID_CONST,      0 },
     476              :   { "__constinit",    RID_CONSTINIT,  D_CXXONLY },
     477              :   { "__contract_assert", RID_CONTASSERT, D_CXXONLY | D_CXXWARN  },
     478              :   { "__decltype",       RID_DECLTYPE,   D_CXXONLY },
     479              :   { "__extension__",  RID_EXTENSION,  0 },
     480              :   { "__func__",               RID_C99_FUNCTION_NAME, 0 },
     481              :   { "__imag",         RID_IMAGPART,   0 },
     482              :   { "__imag__",               RID_IMAGPART,   0 },
     483              :   { "__inline",               RID_INLINE,     0 },
     484              :   { "__inline__",     RID_INLINE,     0 },
     485              :   { "__label__",      RID_LABEL,      0 },
     486              :   { "__null",         RID_NULL,       0 },
     487              :   { "__real",         RID_REALPART,   0 },
     488              :   { "__real__",               RID_REALPART,   0 },
     489              :   { "__restrict",     RID_RESTRICT,   0 },
     490              :   { "__restrict__",   RID_RESTRICT,   0 },
     491              :   { "__signed",               RID_SIGNED,     0 },
     492              :   { "__signed__",     RID_SIGNED,     0 },
     493              :   { "__thread",               RID_THREAD,     0 },
     494              :   { "__transaction_atomic", RID_TRANSACTION_ATOMIC, 0 },
     495              :   { "__transaction_relaxed", RID_TRANSACTION_RELAXED, 0 },
     496              :   { "__transaction_cancel", RID_TRANSACTION_CANCEL, 0 },
     497              :   { "__typeof",               RID_TYPEOF,     0 },
     498              :   { "__typeof__",     RID_TYPEOF,     0 },
     499              :   { "__typeof_unqual",        RID_TYPEOF_UNQUAL, D_CONLY },
     500              :   { "__typeof_unqual__", RID_TYPEOF_UNQUAL, D_CONLY },
     501              :   { "__volatile",     RID_VOLATILE,   0 },
     502              :   { "__volatile__",   RID_VOLATILE,   0 },
     503              :   { "__GIMPLE",               RID_GIMPLE,     D_CONLY },
     504              :   { "__PHI",          RID_PHI,        D_CONLY },
     505              :   { "__RTL",          RID_RTL,        D_CONLY },
     506              :   { "alignas",                RID_ALIGNAS,    D_C23 | D_CXX11 | D_CXXWARN },
     507              :   { "alignof",                RID_ALIGNOF,    D_C23 | D_CXX11 | D_CXXWARN },
     508              :   { "asm",            RID_ASM,        D_ASM },
     509              :   { "auto",           RID_AUTO,       0 },
     510              :   { "bool",           RID_BOOL,       D_C23 | D_CXXWARN },
     511              :   { "break",          RID_BREAK,      0 },
     512              :   { "case",           RID_CASE,       0 },
     513              :   { "catch",          RID_CATCH,      D_CXX_OBJC | D_CXXWARN },
     514              :   { "char",           RID_CHAR,       0 },
     515              :   { "char8_t",                RID_CHAR8,      D_CXX_CHAR8_T_FLAGS | D_CXXWARN },
     516              :   { "char16_t",               RID_CHAR16,     D_CXXONLY | D_CXX11 | D_CXXWARN },
     517              :   { "char32_t",               RID_CHAR32,     D_CXXONLY | D_CXX11 | D_CXXWARN },
     518              :   { "class",          RID_CLASS,      D_CXX_OBJC | D_CXXWARN },
     519              :   { "const",          RID_CONST,      0 },
     520              :   { "consteval",      RID_CONSTEVAL,  D_CXXONLY | D_CXX20 | D_CXXWARN },
     521              :   { "constexpr",      RID_CONSTEXPR,  D_C23 | D_CXX11 | D_CXXWARN },
     522              :   { "constinit",      RID_CONSTINIT,  D_CXXONLY | D_CXX20 | D_CXXWARN },
     523              :   { "const_cast",     RID_CONSTCAST,  D_CXXONLY | D_CXXWARN },
     524              :   { "continue",               RID_CONTINUE,   0 },
     525              :   { "contract_assert",        RID_CONTASSERT, D_CXXONLY | D_CXXWARN | D_CXX26 },
     526              :   { "decltype",         RID_DECLTYPE,   D_CXXONLY | D_CXX11 | D_CXXWARN },
     527              :   { "default",                RID_DEFAULT,    0 },
     528              :   { "delete",         RID_DELETE,     D_CXXONLY | D_CXXWARN },
     529              :   { "do",             RID_DO,         0 },
     530              :   { "double",         RID_DOUBLE,     0 },
     531              :   { "dynamic_cast",   RID_DYNCAST,    D_CXXONLY | D_CXXWARN },
     532              :   { "else",           RID_ELSE,       0 },
     533              :   { "enum",           RID_ENUM,       0 },
     534              :   { "explicit",               RID_EXPLICIT,   D_CXXONLY | D_CXXWARN },
     535              :   { "export",         RID_EXPORT,     D_CXXONLY | D_CXXWARN },
     536              :   { "extern",         RID_EXTERN,     0 },
     537              :   { "false",          RID_FALSE,      D_C23 | D_CXXWARN },
     538              :   { "float",          RID_FLOAT,      0 },
     539              :   { "for",            RID_FOR,        0 },
     540              :   { "friend",         RID_FRIEND,     D_CXXONLY | D_CXXWARN },
     541              :   { "goto",           RID_GOTO,       0 },
     542              :   { "if",             RID_IF,         0 },
     543              :   { "inline",         RID_INLINE,     D_EXT89 },
     544              :   { "int",            RID_INT,        0 },
     545              :   { "long",           RID_LONG,       0 },
     546              :   { "mutable",                RID_MUTABLE,    D_CXXONLY | D_CXXWARN },
     547              :   { "namespace",      RID_NAMESPACE,  D_CXXONLY | D_CXXWARN },
     548              :   { "new",            RID_NEW,        D_CXXONLY | D_CXXWARN },
     549              :   { "noexcept",               RID_NOEXCEPT,   D_CXXONLY | D_CXX11 | D_CXXWARN },
     550              :   { "nullptr",                RID_NULLPTR,    D_C23 | D_CXX11 | D_CXXWARN },
     551              :   { "operator",               RID_OPERATOR,   D_CXXONLY | D_CXXWARN },
     552              :   { "private",                RID_PRIVATE,    D_CXX_OBJC | D_CXXWARN },
     553              :   { "protected",      RID_PROTECTED,  D_CXX_OBJC | D_CXXWARN },
     554              :   { "public",         RID_PUBLIC,     D_CXX_OBJC | D_CXXWARN },
     555              :   { "register",               RID_REGISTER,   0 },
     556              :   { "reinterpret_cast",       RID_REINTCAST,  D_CXXONLY | D_CXXWARN },
     557              :   { "restrict",               RID_RESTRICT,   D_CONLY | D_C99 },
     558              :   { "return",         RID_RETURN,     0 },
     559              :   { "short",          RID_SHORT,      0 },
     560              :   { "signed",         RID_SIGNED,     0 },
     561              :   { "sizeof",         RID_SIZEOF,     0 },
     562              :   { "static",         RID_STATIC,     0 },
     563              :   { "static_assert",    RID_STATIC_ASSERT, D_C23 | D_CXX11 | D_CXXWARN },
     564              :   { "static_cast",    RID_STATCAST,   D_CXXONLY | D_CXXWARN },
     565              :   { "struct",         RID_STRUCT,     0 },
     566              :   { "switch",         RID_SWITCH,     0 },
     567              :   { "template",               RID_TEMPLATE,   D_CXXONLY | D_CXXWARN },
     568              :   { "this",           RID_THIS,       D_CXXONLY | D_CXXWARN },
     569              :   { "thread_local",   RID_THREAD,     D_C23 | D_CXX11 | D_CXXWARN },
     570              :   { "throw",          RID_THROW,      D_CXX_OBJC | D_CXXWARN },
     571              :   { "true",           RID_TRUE,       D_C23 | D_CXXWARN },
     572              :   { "try",            RID_TRY,        D_CXX_OBJC | D_CXXWARN },
     573              :   { "typedef",                RID_TYPEDEF,    0 },
     574              :   { "typename",               RID_TYPENAME,   D_CXXONLY | D_CXXWARN },
     575              :   { "typeid",         RID_TYPEID,     D_CXXONLY | D_CXXWARN },
     576              :   { "typeof",         RID_TYPEOF,     D_EXT11 },
     577              :   { "typeof_unqual",  RID_TYPEOF_UNQUAL,      D_CONLY | D_C23 },
     578              :   { "union",          RID_UNION,      0 },
     579              :   { "unsigned",               RID_UNSIGNED,   0 },
     580              :   { "using",          RID_USING,      D_CXXONLY | D_CXXWARN },
     581              :   { "virtual",                RID_VIRTUAL,    D_CXXONLY | D_CXXWARN },
     582              :   { "void",           RID_VOID,       0 },
     583              :   { "volatile",               RID_VOLATILE,   0 },
     584              :   { "wchar_t",                RID_WCHAR,      D_CXXONLY },
     585              :   { "while",          RID_WHILE,      0 },
     586              : 
     587              :   /* C++ transactional memory.  */
     588              :   { "synchronized",   RID_SYNCHRONIZED, D_CXX_OBJC | D_TRANSMEM },
     589              :   { "atomic_noexcept",        RID_ATOMIC_NOEXCEPT, D_CXXONLY | D_TRANSMEM },
     590              :   { "atomic_cancel",  RID_ATOMIC_CANCEL, D_CXXONLY | D_TRANSMEM },
     591              :   { "atomic_commit",  RID_TRANSACTION_ATOMIC, D_CXXONLY | D_TRANSMEM },
     592              : 
     593              :   /* Concepts-related keywords */
     594              :   { "concept",                RID_CONCEPT,    D_CXX_CONCEPTS_FLAGS | D_CXXWARN },
     595              :   { "requires",       RID_REQUIRES,   D_CXX_CONCEPTS_FLAGS | D_CXXWARN },
     596              : 
     597              :   /* Modules-related keywords, these are internal unspellable tokens,
     598              :      created by the preprocessor.  */
     599              :   { "module ",                RID__MODULE,    D_CXX_MODULES_FLAGS | D_CXXWARN },
     600              :   { "import ",                RID__IMPORT,    D_CXX_MODULES_FLAGS | D_CXXWARN },
     601              :   { "export ",                RID__EXPORT,    D_CXX_MODULES_FLAGS | D_CXXWARN },
     602              : 
     603              :   /* Coroutines-related keywords */
     604              :   { "co_await",               RID_CO_AWAIT,   D_CXX_COROUTINES_FLAGS | D_CXXWARN },
     605              :   { "co_yield",               RID_CO_YIELD,   D_CXX_COROUTINES_FLAGS | D_CXXWARN },
     606              :   { "co_return",      RID_CO_RETURN,  D_CXX_COROUTINES_FLAGS | D_CXXWARN },
     607              : 
     608              :   /* These Objective-C keywords are recognized only immediately after
     609              :      an '@'.  */
     610              :   { "compatibility_alias", RID_AT_ALIAS,      D_OBJC },
     611              :   { "defs",           RID_AT_DEFS,            D_OBJC },
     612              :   { "encode",         RID_AT_ENCODE,          D_OBJC },
     613              :   { "end",            RID_AT_END,             D_OBJC },
     614              :   { "implementation", RID_AT_IMPLEMENTATION,  D_OBJC },
     615              :   { "interface",      RID_AT_INTERFACE,       D_OBJC },
     616              :   { "protocol",               RID_AT_PROTOCOL,        D_OBJC },
     617              :   { "selector",               RID_AT_SELECTOR,        D_OBJC },
     618              :   { "finally",                RID_AT_FINALLY,         D_OBJC },
     619              :   { "optional",               RID_AT_OPTIONAL,        D_OBJC },
     620              :   { "required",               RID_AT_REQUIRED,        D_OBJC },
     621              :   { "property",               RID_AT_PROPERTY,        D_OBJC },
     622              :   { "package",                RID_AT_PACKAGE,         D_OBJC },
     623              :   { "synthesize",     RID_AT_SYNTHESIZE,      D_OBJC },
     624              :   { "dynamic",                RID_AT_DYNAMIC,         D_OBJC },
     625              :   /* These are recognized only in protocol-qualifier context
     626              :      (see above) */
     627              :   { "bycopy",         RID_BYCOPY,             D_OBJC },
     628              :   { "byref",          RID_BYREF,              D_OBJC },
     629              :   { "in",             RID_IN,                 D_OBJC },
     630              :   { "inout",          RID_INOUT,              D_OBJC },
     631              :   { "oneway",         RID_ONEWAY,             D_OBJC },
     632              :   { "out",            RID_OUT,                D_OBJC },
     633              :   /* These are recognized inside a property attribute list */
     634              :   { "assign",         RID_ASSIGN,             D_OBJC },
     635              :   { "atomic",         RID_PROPATOMIC,         D_OBJC },
     636              :   { "copy",           RID_COPY,               D_OBJC },
     637              :   { "getter",         RID_GETTER,             D_OBJC },
     638              :   { "nonatomic",      RID_NONATOMIC,          D_OBJC },
     639              :   { "readonly",               RID_READONLY,           D_OBJC },
     640              :   { "readwrite",      RID_READWRITE,          D_OBJC },
     641              :   { "retain",         RID_RETAIN,             D_OBJC },
     642              :   { "setter",         RID_SETTER,             D_OBJC },
     643              :   /* These are Objective C implementation of nullability, accepted only in
     644              :      specific contexts.  */
     645              :   { "null_unspecified", RID_NULL_UNSPECIFIED, D_OBJC },
     646              :   { "nullable",               RID_NULLABLE,           D_OBJC },
     647              :   { "nonnull",                RID_NONNULL,            D_OBJC },
     648              :   { "null_resettable",        RID_NULL_RESETTABLE,    D_OBJC },
     649              : };
     650              : 
     651              : const unsigned int num_c_common_reswords = ARRAY_SIZE (c_common_reswords);
     652              : 
     653              : /* Return identifier for address space AS.  */
     654              : 
     655              : const char *
     656            3 : c_addr_space_name (addr_space_t as)
     657              : {
     658            3 :   int rid = RID_FIRST_ADDR_SPACE + as;
     659            3 :   gcc_assert (ridpointers [rid]);
     660            3 :   return IDENTIFIER_POINTER (ridpointers [rid]);
     661              : }
     662              : 
     663              : /* Push current bindings for the function name VAR_DECLS.  */
     664              : 
     665              : void
     666    195784132 : start_fname_decls (void)
     667              : {
     668    195784132 :   unsigned ix;
     669    195784132 :   tree saved = NULL_TREE;
     670              : 
     671    783136528 :   for (ix = 0; fname_vars[ix].decl; ix++)
     672              :     {
     673    587352396 :       tree decl = *fname_vars[ix].decl;
     674              : 
     675    587352396 :       if (decl)
     676              :         {
     677        56398 :           saved = tree_cons (decl, build_int_cst (integer_type_node, ix),
     678              :                              saved);
     679        56398 :           *fname_vars[ix].decl = NULL_TREE;
     680              :         }
     681              :     }
     682    195784132 :   if (saved || saved_function_name_decls)
     683              :     /* Normally they'll have been NULL, so only push if we've got a
     684              :        stack, or they are non-NULL.  */
     685        73638 :     saved_function_name_decls = tree_cons (saved, NULL_TREE,
     686              :                                            saved_function_name_decls);
     687    195784132 : }
     688              : 
     689              : /* Finish up the current bindings, adding them into the current function's
     690              :    statement tree.  This must be done _before_ finish_stmt_tree is called.
     691              :    If there is no current function, we must be at file scope and no statements
     692              :    are involved. Pop the previous bindings.  */
     693              : 
     694              : void
     695    195665798 : finish_fname_decls (void)
     696              : {
     697    195665798 :   unsigned ix;
     698    195665798 :   tree stmts = NULL_TREE;
     699    195665798 :   tree stack = saved_function_name_decls;
     700              : 
     701    196126344 :   for (; stack && TREE_VALUE (stack); stack = TREE_CHAIN (stack))
     702       193454 :     append_to_statement_list (TREE_VALUE (stack), &stmts);
     703              : 
     704    195665798 :   if (stmts)
     705              :     {
     706       193349 :       tree *bodyp = &DECL_SAVED_TREE (current_function_decl);
     707              : 
     708       193349 :       if (TREE_CODE (*bodyp) == BIND_EXPR)
     709       183548 :         bodyp = &BIND_EXPR_BODY (*bodyp);
     710              : 
     711       193349 :       append_to_statement_list_force (*bodyp, &stmts);
     712       193349 :       *bodyp = stmts;
     713              :     }
     714              : 
     715    782663192 :   for (ix = 0; fname_vars[ix].decl; ix++)
     716    586997394 :     *fname_vars[ix].decl = NULL_TREE;
     717              : 
     718    195665798 :   if (stack)
     719              :     {
     720              :       /* We had saved values, restore them.  */
     721        73638 :       tree saved;
     722              : 
     723       130036 :       for (saved = TREE_PURPOSE (stack); saved; saved = TREE_CHAIN (saved))
     724              :         {
     725        56398 :           tree decl = TREE_PURPOSE (saved);
     726        56398 :           unsigned ix = TREE_INT_CST_LOW (TREE_VALUE (saved));
     727              : 
     728        56398 :           *fname_vars[ix].decl = decl;
     729              :         }
     730        73638 :       stack = TREE_CHAIN (stack);
     731              :     }
     732    195665798 :   saved_function_name_decls = stack;
     733    195665798 : }
     734              : 
     735              : /* Return the text name of the current function, suitably prettified
     736              :    by PRETTY_P.  Return string must be freed by caller.  */
     737              : 
     738              : const char *
     739         3542 : fname_as_string (int pretty_p)
     740              : {
     741         3542 :   const char *name = "top level";
     742         3542 :   char *namep;
     743         3542 :   int vrb = 2, len;
     744         3542 :   cpp_string cstr = { 0, 0 }, strname;
     745              : 
     746         3542 :   if (!pretty_p)
     747              :     {
     748         1874 :       name = "";
     749         1874 :       vrb = 0;
     750              :     }
     751              : 
     752         3542 :   if (current_function_decl)
     753         3535 :     name = lang_hooks.decl_printable_name (current_function_decl, vrb);
     754              : 
     755         3542 :   len = strlen (name) + 3; /* Two for '"'s.  One for NULL.  */
     756              : 
     757         3542 :   namep = XNEWVEC (char, len);
     758         3542 :   snprintf (namep, len, "\"%s\"", name);
     759         3542 :   strname.text = (unsigned char *) namep;
     760         3542 :   strname.len = len - 1;
     761              : 
     762         3542 :   if (cpp_interpret_string (parse_in, &strname, 1, &cstr, CPP_STRING))
     763              :     {
     764         3542 :       XDELETEVEC (namep);
     765         3542 :       return (const char *) cstr.text;
     766              :     }
     767              : 
     768              :   return namep;
     769              : }
     770              : 
     771              : /* Return the VAR_DECL for a const char array naming the current
     772              :    function. If the VAR_DECL has not yet been created, create it
     773              :    now. RID indicates how it should be formatted and IDENTIFIER_NODE
     774              :    ID is its name (unfortunately C and C++ hold the RID values of
     775              :    keywords in different places, so we can't derive RID from ID in
     776              :    this language independent code. LOC is the location of the
     777              :    function.  */
     778              : 
     779              : tree
     780       297653 : fname_decl (location_t loc, unsigned int rid, tree id)
     781              : {
     782       297653 :   unsigned ix;
     783       297653 :   tree decl = NULL_TREE;
     784              : 
     785       871887 :   for (ix = 0; fname_vars[ix].decl; ix++)
     786       871887 :     if (fname_vars[ix].rid == rid)
     787              :       break;
     788              : 
     789       297653 :   decl = *fname_vars[ix].decl;
     790       297653 :   if (!decl)
     791              :     {
     792              :       /* If a tree is built here, it would normally have the lineno of
     793              :          the current statement.  Later this tree will be moved to the
     794              :          beginning of the function and this line number will be wrong.
     795              :          To avoid this problem set the lineno to 0 here; that prevents
     796              :          it from appearing in the RTL.  */
     797       193454 :       tree stmts;
     798       193454 :       location_t saved_location = input_location;
     799       193454 :       input_location = UNKNOWN_LOCATION;
     800              : 
     801       193454 :       stmts = push_stmt_list ();
     802       193454 :       decl = (*make_fname_decl) (loc, id, fname_vars[ix].pretty);
     803       193454 :       stmts = pop_stmt_list (stmts);
     804       193454 :       if (!IS_EMPTY_STMT (stmts))
     805       193454 :         saved_function_name_decls
     806       193454 :           = tree_cons (decl, stmts, saved_function_name_decls);
     807       193454 :       *fname_vars[ix].decl = decl;
     808       193454 :       input_location = saved_location;
     809              :     }
     810       297653 :   if (!ix && !current_function_decl)
     811            4 :     pedwarn (loc, 0, "%qD is not defined outside of function scope", decl);
     812              : 
     813       297653 :   return decl;
     814              : }
     815              : 
     816              : /* Given a STRING_CST, give it a suitable array-of-chars data type.  */
     817              : 
     818              : tree
     819     28899143 : fix_string_type (tree value)
     820              : {
     821     28899143 :   int length = TREE_STRING_LENGTH (value);
     822     28899143 :   int nchars, charsz;
     823     28899143 :   tree e_type, i_type, a_type;
     824              : 
     825              :   /* Compute the number of elements, for the array type.  */
     826     28899143 :   if (TREE_TYPE (value) == char_array_type_node || !TREE_TYPE (value))
     827              :     {
     828     27936921 :       charsz = 1;
     829     27936921 :       e_type = char_type_node;
     830              :     }
     831       962222 :   else if (flag_char8_t && TREE_TYPE (value) == char8_array_type_node)
     832              :     {
     833         2151 :       charsz = TYPE_PRECISION (char8_type_node) / BITS_PER_UNIT;
     834         2151 :       e_type = char8_type_node;
     835              :     }
     836       960071 :   else if (TREE_TYPE (value) == char16_array_type_node)
     837              :     {
     838          980 :       charsz = TYPE_PRECISION (char16_type_node) / BITS_PER_UNIT;
     839          980 :       e_type = char16_type_node;
     840              :     }
     841       959091 :   else if (TREE_TYPE (value) == char32_array_type_node)
     842              :     {
     843         3087 :       charsz = TYPE_PRECISION (char32_type_node) / BITS_PER_UNIT;
     844         3087 :       e_type = char32_type_node;
     845              :     }
     846              :   else
     847              :     {
     848       956004 :       charsz = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT;
     849       956004 :       e_type = wchar_type_node;
     850              :     }
     851              : 
     852              :   /* This matters only for targets where ssizetype has smaller precision
     853              :      than 32 bits.  */
     854     28899143 :   if (wi::lts_p (wi::to_wide (TYPE_MAX_VALUE (ssizetype)), length))
     855              :     {
     856            0 :       error ("size of string literal is too large");
     857            0 :       length = tree_to_shwi (TYPE_MAX_VALUE (ssizetype)) / charsz * charsz;
     858            0 :       char *str = const_cast<char *> (TREE_STRING_POINTER (value));
     859            0 :       memset (str + length, '\0',
     860            0 :               MIN (TREE_STRING_LENGTH (value) - length, charsz));
     861            0 :       TREE_STRING_LENGTH (value) = length;
     862              :     }
     863     28899143 :   nchars = length / charsz;
     864              : 
     865              :   /* C89 2.2.4.1, C99 5.2.4.1 (Translation limits).  The analogous
     866              :      limit in C++98 Annex B is very large (65536) and is not normative,
     867              :      so we do not diagnose it (warn_overlength_strings is forced off
     868              :      in c_common_post_options).  */
     869     28899143 :   if (warn_overlength_strings)
     870              :     {
     871        15220 :       const int nchars_max = flag_isoc99 ? 4095 : 509;
     872        15220 :       const int relevant_std = flag_isoc99 ? 99 : 90;
     873        15220 :       if (nchars - 1 > nchars_max)
     874              :         /* Translators: The %d after 'ISO C' will be 90 or 99.  Do not
     875              :            separate the %d from the 'C'.  'ISO' should not be
     876              :            translated, but it may be moved after 'C%d' in languages
     877              :            where modifiers follow nouns.  */
     878            5 :         pedwarn (input_location, OPT_Woverlength_strings,
     879              :                  "string length %qd is greater than the length %qd "
     880              :                  "ISO C%d compilers are required to support",
     881              :                  nchars - 1, nchars_max, relevant_std);
     882              :     }
     883              : 
     884              :   /* Create the array type for the string constant.  The ISO C++
     885              :      standard says that a string literal has type `const char[N]' or
     886              :      `const wchar_t[N]'.  We use the same logic when invoked as a C
     887              :      front-end with -Wwrite-strings.
     888              :      ??? We should change the type of an expression depending on the
     889              :      state of a warning flag.  We should just be warning -- see how
     890              :      this is handled in the C++ front-end for the deprecated implicit
     891              :      conversion from string literals to `char*' or `wchar_t*'.
     892              : 
     893              :      The C++ front end relies on TYPE_MAIN_VARIANT of a cv-qualified
     894              :      array type being the unqualified version of that type.
     895              :      Therefore, if we are constructing an array of const char, we must
     896              :      construct the matching unqualified array type first.  The C front
     897              :      end does not require this, but it does no harm, so we do it
     898              :      unconditionally.  */
     899     28899143 :   i_type = build_index_type (size_int (nchars - 1));
     900     28899143 :   a_type = build_array_type (e_type, i_type);
     901     28899143 :   if (c_dialect_cxx() || warn_write_strings)
     902     26491614 :     a_type = c_build_qualified_type (a_type, TYPE_QUAL_CONST);
     903              : 
     904     28899143 :   TREE_TYPE (value) = a_type;
     905     28899143 :   TREE_CONSTANT (value) = 1;
     906     28899143 :   TREE_READONLY (value) = 1;
     907     28899143 :   TREE_STATIC (value) = 1;
     908     28899143 :   return value;
     909              : }
     910              : 
     911              : /* Given a string of type STRING_TYPE, determine what kind of string
     912              :    token would give an equivalent execution encoding: CPP_STRING,
     913              :    CPP_STRING16, or CPP_STRING32.  Return CPP_OTHER in case of error.
     914              :    This may not be exactly the string token type that initially created
     915              :    the string, since CPP_WSTRING is indistinguishable from the 16/32 bit
     916              :    string type, and CPP_UTF8STRING is indistinguishable from CPP_STRING
     917              :    at this point.
     918              : 
     919              :    This effectively reverses part of the logic in lex_string and
     920              :    fix_string_type.  */
     921              : 
     922              : static enum cpp_ttype
     923        11105 : get_cpp_ttype_from_string_type (tree string_type)
     924              : {
     925        11105 :   gcc_assert (string_type);
     926        11105 :   if (TREE_CODE (string_type) == POINTER_TYPE)
     927         5966 :     string_type = TREE_TYPE (string_type);
     928              : 
     929        11105 :   if (TREE_CODE (string_type) != ARRAY_TYPE)
     930              :     return CPP_OTHER;
     931              : 
     932        11105 :   tree element_type = TREE_TYPE (string_type);
     933        11105 :   if (TREE_CODE (element_type) != INTEGER_TYPE)
     934              :     return CPP_OTHER;
     935              : 
     936        11105 :   int bits_per_character = TYPE_PRECISION (element_type);
     937        11105 :   switch (bits_per_character)
     938              :     {
     939              :     case 8:
     940              :       return CPP_STRING;  /* It could have also been CPP_UTF8STRING.  */
     941            2 :     case 16:
     942            2 :       return CPP_STRING16;
     943            4 :     case 32:
     944            4 :       return CPP_STRING32;
     945              :     }
     946              : 
     947              :   return CPP_OTHER;
     948              : }
     949              : 
     950              : /* The global record of string concatenations, for use in
     951              :    extracting locations within string literals.  */
     952              : 
     953              : GTY(()) string_concat_db *g_string_concat_db;
     954              : 
     955              : /* Implementation of LANG_HOOKS_GET_SUBSTRING_LOCATION.  */
     956              : 
     957              : const char *
     958        11105 : c_get_substring_location (const substring_loc &substr_loc,
     959              :                           location_t *out_loc)
     960              : {
     961        11105 :   enum cpp_ttype tok_type
     962        11105 :     = get_cpp_ttype_from_string_type (substr_loc.get_string_type ());
     963        11105 :   if (tok_type == CPP_OTHER)
     964              :     return "unrecognized string type";
     965              : 
     966        11105 :   return get_location_within_string (parse_in,
     967              :                                      global_dc->get_file_cache (),
     968              :                                      g_string_concat_db,
     969              :                                      substr_loc.get_fmt_string_loc (),
     970              :                                      tok_type,
     971              :                                      substr_loc.get_caret_idx (),
     972              :                                      substr_loc.get_start_idx (),
     973              :                                      substr_loc.get_end_idx (),
     974        11105 :                                      out_loc);
     975              : }
     976              : 
     977              : 
     978              : /* Return true iff T is a boolean promoted to int.  */
     979              : 
     980              : bool
     981        93464 : bool_promoted_to_int_p (tree t)
     982              : {
     983        76333 :   return (CONVERT_EXPR_P (t)
     984        17231 :           && TREE_TYPE (t) == integer_type_node
     985        93564 :           && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == BOOLEAN_TYPE);
     986              : }
     987              : 
     988              : /* vector_targets_convertible_p is used for vector pointer types.  The
     989              :    callers perform various checks that the qualifiers are satisfactory,
     990              :    while OTOH vector_targets_convertible_p ignores the number of elements
     991              :    in the vectors.  That's fine with vector pointers as we can consider,
     992              :    say, a vector of 8 elements as two consecutive vectors of 4 elements,
     993              :    and that does not require and conversion of the pointer values.
     994              :    In contrast, vector_types_convertible_p and
     995              :    vector_types_compatible_elements_p are used for vector value types.  */
     996              : /* True if pointers to distinct types T1 and T2 can be converted to
     997              :    each other without an explicit cast.  Only returns true for opaque
     998              :    vector types.  */
     999              : bool
    1000      2041510 : vector_targets_convertible_p (const_tree t1, const_tree t2)
    1001              : {
    1002       981673 :   if (VECTOR_TYPE_P (t1) && VECTOR_TYPE_P (t2)
    1003       981497 :       && (TYPE_VECTOR_OPAQUE (t1) || TYPE_VECTOR_OPAQUE (t2))
    1004      2041510 :       && tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2)))
    1005              :     return true;
    1006              : 
    1007              :   return false;
    1008              : }
    1009              : 
    1010              : /* vector_types_convertible_p is used for vector value types.
    1011              :    It could in principle call vector_targets_convertible_p as a subroutine,
    1012              :    but then the check for vector type would be duplicated with its callers,
    1013              :    and also the purpose of vector_targets_convertible_p would become
    1014              :    muddled.
    1015              :    Where vector_types_convertible_p returns true, a conversion might still be
    1016              :    needed to make the types match.
    1017              :    In contrast, vector_targets_convertible_p is used for vector pointer
    1018              :    values, and vector_types_compatible_elements_p is used specifically
    1019              :    in the context for binary operators, as a check if use is possible without
    1020              :    conversion.  */
    1021              : /* True if vector types T1 and T2 can be converted to each other
    1022              :    without an explicit cast.  If EMIT_LAX_NOTE is true, and T1 and T2
    1023              :    can only be converted with -flax-vector-conversions yet that is not
    1024              :    in effect, emit a note telling the user about that option if such
    1025              :    a note has not previously been emitted.  */
    1026              : bool
    1027     18612481 : vector_types_convertible_p (const_tree t1, const_tree t2, bool emit_lax_note)
    1028              : {
    1029     18612481 :   static bool emitted_lax_note = false;
    1030     18612481 :   bool convertible_lax;
    1031              : 
    1032     37219803 :   if ((TYPE_VECTOR_OPAQUE (t1) || TYPE_VECTOR_OPAQUE (t2))
    1033     18614282 :       && tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2)))
    1034              :     return true;
    1035              : 
    1036     37211158 :   convertible_lax =
    1037     18605579 :     (tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2))
    1038     18600384 :      && (TREE_CODE (TREE_TYPE (t1)) != REAL_TYPE
    1039     10801024 :          || known_eq (TYPE_VECTOR_SUBPARTS (t1),
    1040              :                       TYPE_VECTOR_SUBPARTS (t2)))
    1041     55738395 :      && (INTEGRAL_TYPE_P (TREE_TYPE (t1))
    1042     18566408 :          == INTEGRAL_TYPE_P (TREE_TYPE (t2))));
    1043              : 
    1044     18605579 :   if (!convertible_lax || flag_lax_vector_conversions)
    1045        75785 :     return convertible_lax;
    1046              : 
    1047     18529794 :   if (known_eq (TYPE_VECTOR_SUBPARTS (t1), TYPE_VECTOR_SUBPARTS (t2))
    1048     18529794 :       && lang_hooks.types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1049     16946363 :     return true;
    1050              : 
    1051      1583431 :   if (emit_lax_note && !emitted_lax_note)
    1052              :     {
    1053           10 :       emitted_lax_note = true;
    1054           10 :       inform (input_location, "use %<-flax-vector-conversions%> to permit "
    1055              :               "conversions between vectors with differing "
    1056              :               "element types or numbers of subparts");
    1057              :     }
    1058              : 
    1059              :   return false;
    1060              : }
    1061              : 
    1062              : /* Build a VEC_PERM_EXPR if V0, V1 and MASK are not error_mark_nodes
    1063              :    and have vector types, V0 has the same type as V1, and the number of
    1064              :    elements of V0, V1, MASK is the same.
    1065              : 
    1066              :    In case V1 is a NULL_TREE it is assumed that __builtin_shuffle was
    1067              :    called with two arguments.  In this case implementation passes the
    1068              :    first argument twice in order to share the same tree code.  This fact
    1069              :    could enable the mask-values being twice the vector length.  This is
    1070              :    an implementation accident and this semantics is not guaranteed to
    1071              :    the user.  */
    1072              : tree
    1073       488169 : c_build_vec_perm_expr (location_t loc, tree v0, tree v1, tree mask,
    1074              :                        bool complain)
    1075              : {
    1076       488169 :   tree ret;
    1077       488169 :   bool wrap = true;
    1078       488169 :   bool maybe_const = false;
    1079       488169 :   bool two_arguments = false;
    1080              : 
    1081       488169 :   if (v1 == NULL_TREE)
    1082              :     {
    1083       445786 :       two_arguments = true;
    1084       445786 :       v1 = v0;
    1085              :     }
    1086              : 
    1087       488169 :   if (v0 == error_mark_node || v1 == error_mark_node
    1088       488169 :       || mask == error_mark_node)
    1089              :     return error_mark_node;
    1090              : 
    1091       488169 :   if (!gnu_vector_type_p (TREE_TYPE (mask))
    1092       488169 :       || !VECTOR_INTEGER_TYPE_P (TREE_TYPE (mask)))
    1093              :     {
    1094            3 :       if (complain)
    1095            0 :         error_at (loc, "%<__builtin_shuffle%> last argument must "
    1096              :                        "be an integer vector");
    1097            3 :       return error_mark_node;
    1098              :     }
    1099              : 
    1100       488166 :   if (!gnu_vector_type_p (TREE_TYPE (v0))
    1101       488166 :       || !gnu_vector_type_p (TREE_TYPE (v1)))
    1102              :     {
    1103            0 :       if (complain)
    1104            0 :         error_at (loc, "%<__builtin_shuffle%> arguments must be vectors");
    1105            0 :       return error_mark_node;
    1106              :     }
    1107              : 
    1108       488166 :   if (TYPE_MAIN_VARIANT (TREE_TYPE (v0)) != TYPE_MAIN_VARIANT (TREE_TYPE (v1)))
    1109              :     {
    1110            0 :       if (complain)
    1111            0 :         error_at (loc, "%<__builtin_shuffle%> argument vectors must be of "
    1112              :                        "the same type");
    1113            0 :       return error_mark_node;
    1114              :     }
    1115              : 
    1116       488166 :   if (maybe_ne (TYPE_VECTOR_SUBPARTS (TREE_TYPE (v0)),
    1117       488166 :                 TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask)))
    1118       488166 :       && maybe_ne (TYPE_VECTOR_SUBPARTS (TREE_TYPE (v1)),
    1119            0 :                    TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask))))
    1120              :     {
    1121            0 :       if (complain)
    1122            0 :         error_at (loc, "%<__builtin_shuffle%> number of elements of the "
    1123              :                        "argument vector(s) and the mask vector should "
    1124              :                        "be the same");
    1125            0 :       return error_mark_node;
    1126              :     }
    1127              : 
    1128       488166 :   if (GET_MODE_BITSIZE (SCALAR_TYPE_MODE (TREE_TYPE (TREE_TYPE (v0))))
    1129       976332 :       != GET_MODE_BITSIZE (SCALAR_TYPE_MODE (TREE_TYPE (TREE_TYPE (mask)))))
    1130              :     {
    1131            0 :       if (complain)
    1132            0 :         error_at (loc, "%<__builtin_shuffle%> argument vector(s) inner type "
    1133              :                        "must have the same size as inner type of the mask");
    1134            0 :       return error_mark_node;
    1135              :     }
    1136              : 
    1137       488166 :   if (!c_dialect_cxx ())
    1138              :     {
    1139              :       /* Avoid C_MAYBE_CONST_EXPRs inside VEC_PERM_EXPR.  */
    1140       470589 :       v0 = c_fully_fold (v0, false, &maybe_const);
    1141       470589 :       wrap &= maybe_const;
    1142              : 
    1143       470589 :       if (two_arguments)
    1144       429077 :         v1 = v0 = save_expr (v0);
    1145              :       else
    1146              :         {
    1147        41512 :           v1 = c_fully_fold (v1, false, &maybe_const);
    1148        41512 :           wrap &= maybe_const;
    1149              :         }
    1150              : 
    1151       470589 :       mask = c_fully_fold (mask, false, &maybe_const);
    1152       470589 :       wrap &= maybe_const;
    1153              :     }
    1154        17577 :   else if (two_arguments)
    1155        16706 :     v1 = v0 = save_expr (v0);
    1156              : 
    1157       488166 :   ret = build3_loc (loc, VEC_PERM_EXPR, TREE_TYPE (v0), v0, v1, mask);
    1158              : 
    1159       488166 :   if (!c_dialect_cxx () && !wrap)
    1160       470589 :     ret = c_wrap_maybe_const (ret, true);
    1161              : 
    1162              :   return ret;
    1163              : }
    1164              : 
    1165              : /* Build a VEC_PERM_EXPR if V0, V1 are not error_mark_nodes
    1166              :    and have vector types, V0 has the same element type as V1, and the
    1167              :    number of elements the result is that of MASK.  */
    1168              : tree
    1169      1121329 : c_build_shufflevector (location_t loc, tree v0, tree v1,
    1170              :                        const vec<tree> &mask, bool complain)
    1171              : {
    1172      1121329 :   tree ret;
    1173      1121329 :   bool wrap = true;
    1174      1121329 :   bool maybe_const = false;
    1175              : 
    1176      1121329 :   if (v0 == error_mark_node || v1 == error_mark_node)
    1177              :     return error_mark_node;
    1178              : 
    1179      1121329 :   if (!gnu_vector_type_p (TREE_TYPE (v0))
    1180      1121329 :       || !gnu_vector_type_p (TREE_TYPE (v1)))
    1181              :     {
    1182            4 :       if (complain)
    1183            4 :         error_at (loc, "%<__builtin_shufflevector%> arguments must be vectors");
    1184            4 :       return error_mark_node;
    1185              :     }
    1186              : 
    1187              :   /* ???  In principle one could select a constant part of a variable size
    1188              :      vector but things get a bit awkward with trying to support this here.  */
    1189      1121325 :   unsigned HOST_WIDE_INT v0n, v1n;
    1190      1121325 :   if (!TYPE_VECTOR_SUBPARTS (TREE_TYPE (v0)).is_constant (&v0n)
    1191      1121325 :       || !TYPE_VECTOR_SUBPARTS (TREE_TYPE (v1)).is_constant (&v1n))
    1192              :     {
    1193              :       if (complain)
    1194              :         error_at (loc, "%<__builtin_shufflevector%> arguments must be constant"
    1195              :                   " size vectors");
    1196              :       return error_mark_node;
    1197              :     }
    1198              : 
    1199      1121325 :   if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (v0)))
    1200      1121325 :       != TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (v1))))
    1201              :     {
    1202            4 :       if (complain)
    1203            4 :         error_at (loc, "%<__builtin_shufflevector%> argument vectors must "
    1204              :                   "have the same element type");
    1205            4 :       return error_mark_node;
    1206              :     }
    1207              : 
    1208      1121321 :   if (!pow2p_hwi (mask.length ()))
    1209              :     {
    1210            4 :       if (complain)
    1211            4 :         error_at (loc, "%<__builtin_shufflevector%> must specify a result "
    1212              :                   "with a power of two number of elements");
    1213            4 :       return error_mark_node;
    1214              :     }
    1215              : 
    1216      1121317 :   if (!c_dialect_cxx ())
    1217              :     {
    1218              :       /* Avoid C_MAYBE_CONST_EXPRs inside VEC_PERM_EXPR.  */
    1219      1079616 :       v0 = c_fully_fold (v0, false, &maybe_const);
    1220      1079616 :       wrap &= maybe_const;
    1221              : 
    1222      1079616 :       v1 = c_fully_fold (v1, false, &maybe_const);
    1223      1079616 :       wrap &= maybe_const;
    1224              :     }
    1225              : 
    1226      2242734 :   unsigned HOST_WIDE_INT maskl = MAX (mask.length (), MAX (v0n, v1n));
    1227      1121317 :   unsigned HOST_WIDE_INT pad = (v0n < maskl ? maskl - v0n : 0);
    1228      1121317 :   vec_perm_builder sel (maskl, maskl, 1);
    1229      1121317 :   unsigned i;
    1230     30433910 :   for (i = 0; i < mask.length (); ++i)
    1231              :     {
    1232     14095653 :       tree idx = mask[i];
    1233     14095653 :       if (!tree_fits_shwi_p (idx))
    1234              :         {
    1235            4 :           if (complain)
    1236            4 :             error_at (loc, "invalid element index %qE to "
    1237              :                       "%<__builtin_shufflevector%>", idx);
    1238      1121317 :           return error_mark_node;
    1239              :         }
    1240     14095649 :       HOST_WIDE_INT iidx = tree_to_shwi (idx);
    1241     14095649 :       if (iidx < -1
    1242     14095645 :           || (iidx != -1
    1243     14095399 :               && (unsigned HOST_WIDE_INT) iidx >= v0n + v1n))
    1244              :         {
    1245           11 :           if (complain)
    1246           11 :             error_at (loc, "invalid element index %qE to "
    1247              :                       "%<__builtin_shufflevector%>", idx);
    1248           11 :           return error_mark_node;
    1249              :         }
    1250              :       /* ???  Our VEC_PERM_EXPR does not allow for -1 yet.  */
    1251     14095638 :       if (iidx == -1)
    1252          246 :         iidx = i;
    1253              :       /* ???  Our VEC_PERM_EXPR does not allow different sized inputs,
    1254              :          so pad out a smaller v0.  */
    1255     14095392 :       else if ((unsigned HOST_WIDE_INT) iidx >= v0n)
    1256         2715 :         iidx += pad;
    1257     14095638 :       sel.quick_push (iidx);
    1258              :     }
    1259              :   /* ???  VEC_PERM_EXPR does not support a result that is smaller than
    1260              :      the inputs, so we have to pad id out.  */
    1261      1123372 :   for (; i < maskl; ++i)
    1262         2070 :     sel.quick_push (i);
    1263              : 
    1264      1121302 :   vec_perm_indices indices (sel, 2, maskl);
    1265              : 
    1266      1121302 :   tree ret_type = build_vector_type (TREE_TYPE (TREE_TYPE (v0)), maskl);
    1267      1121302 :   tree mask_type = build_vector_type (ssizetype, maskl);
    1268              :   /* Pad out arguments to the common vector size.  */
    1269      1121302 :   if (v0n < maskl)
    1270              :     {
    1271          182 :       constructor_elt elt = { NULL_TREE, build_zero_cst (TREE_TYPE (v0)) };
    1272          182 :       v0 = build_constructor_single (ret_type, NULL_TREE, v0);
    1273         1730 :       for (i = 1; i < maskl / v0n; ++i)
    1274         1366 :         vec_safe_push (CONSTRUCTOR_ELTS (v0), elt);
    1275              :     }
    1276      1121302 :   if (v1n < maskl)
    1277              :     {
    1278          161 :       constructor_elt elt = { NULL_TREE, build_zero_cst (TREE_TYPE (v1)) };
    1279          161 :       v1 = build_constructor_single (ret_type, NULL_TREE, v1);
    1280         1549 :       for (i = 1; i < maskl / v1n; ++i)
    1281         1227 :         vec_safe_push (CONSTRUCTOR_ELTS (v1), elt);
    1282              :     }
    1283      1121302 :   ret = build3_loc (loc, VEC_PERM_EXPR, ret_type, v0, v1,
    1284              :                     vec_perm_indices_to_tree (mask_type, indices));
    1285              :   /* Get the lowpart we are interested in.  */
    1286      2242604 :   if (mask.length () < maskl)
    1287              :     {
    1288          283 :       tree lpartt = build_vector_type (TREE_TYPE (ret_type), mask.length ());
    1289          283 :       ret = build3_loc (loc, BIT_FIELD_REF,
    1290          283 :                         lpartt, ret, TYPE_SIZE (lpartt), bitsize_zero_node);
    1291              :       /* Wrap the lowpart operation in a TARGET_EXPR so it gets a separate
    1292              :          temporary during gimplification.  See PR101530 for cases where
    1293              :          we'd otherwise end up with non-toplevel BIT_FIELD_REFs.  */
    1294          283 :       tree tem = create_tmp_var_raw (lpartt);
    1295          283 :       DECL_CONTEXT (tem) = current_function_decl;
    1296          283 :       ret = build4 (TARGET_EXPR, lpartt, tem, ret, NULL_TREE, NULL_TREE);
    1297          283 :       TREE_SIDE_EFFECTS (ret) = 1;
    1298              :     }
    1299              : 
    1300      1121302 :   if (!c_dialect_cxx () && !wrap)
    1301      1079613 :     ret = c_wrap_maybe_const (ret, true);
    1302              : 
    1303      1121302 :   return ret;
    1304      2242619 : }
    1305              : 
    1306              : /* Build a VEC_CONVERT ifn for __builtin_convertvector builtin.  */
    1307              : 
    1308              : tree
    1309          658 : c_build_vec_convert (location_t loc1, tree expr, location_t loc2, tree type,
    1310              :                      bool complain)
    1311              : {
    1312          658 :   if (error_operand_p (type))
    1313            0 :     return error_mark_node;
    1314          658 :   if (error_operand_p (expr))
    1315            0 :     return error_mark_node;
    1316              : 
    1317          658 :   if (!gnu_vector_type_p (TREE_TYPE (expr))
    1318          658 :       || (!VECTOR_INTEGER_TYPE_P (TREE_TYPE (expr))
    1319          173 :           && !VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (expr))
    1320          173 :           && !VECTOR_FLOAT_TYPE_P (TREE_TYPE (expr))))
    1321              :     {
    1322            4 :       if (complain)
    1323            4 :         error_at (loc1, "%<__builtin_convertvector%> first argument must "
    1324              :                         "be an integer or floating vector");
    1325            4 :       return error_mark_node;
    1326              :     }
    1327              : 
    1328          654 :   if (!gnu_vector_type_p (type)
    1329          654 :       || (!VECTOR_INTEGER_TYPE_P (type) && !VECTOR_FLOAT_TYPE_P (type)
    1330            0 :           && !VECTOR_BOOLEAN_TYPE_P (type)))
    1331              :     {
    1332            4 :       if (complain)
    1333            4 :         error_at (loc2, "%<__builtin_convertvector%> second argument must "
    1334              :                         "be an integer or floating vector type");
    1335            4 :       return error_mark_node;
    1336              :     }
    1337              : 
    1338          650 :   if (maybe_ne (TYPE_VECTOR_SUBPARTS (TREE_TYPE (expr)),
    1339         1300 :                 TYPE_VECTOR_SUBPARTS (type)))
    1340              :     {
    1341            8 :       if (complain)
    1342            8 :         error_at (loc1, "%<__builtin_convertvector%> number of elements "
    1343              :                         "of the first argument vector and the second argument "
    1344              :                         "vector type should be the same");
    1345            8 :       return error_mark_node;
    1346              :     }
    1347              : 
    1348          642 :   if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (expr)))
    1349          642 :        == TYPE_MAIN_VARIANT (TREE_TYPE (type)))
    1350          642 :       || (VECTOR_INTEGER_TYPE_P (TREE_TYPE (expr))
    1351          458 :           && VECTOR_INTEGER_TYPE_P (type)
    1352          299 :           && (TYPE_PRECISION (TREE_TYPE (TREE_TYPE (expr)))
    1353          299 :               == TYPE_PRECISION (TREE_TYPE (type)))))
    1354           55 :     return build1_loc (loc1, VIEW_CONVERT_EXPR, type, expr);
    1355              : 
    1356          587 :   bool wrap = true;
    1357          587 :   bool maybe_const = false;
    1358          587 :   tree ret;
    1359          587 :   if (!c_dialect_cxx ())
    1360              :     {
    1361              :       /* Avoid C_MAYBE_CONST_EXPRs inside of VEC_CONVERT argument.  */
    1362          363 :       expr = c_fully_fold (expr, false, &maybe_const);
    1363          363 :       wrap &= maybe_const;
    1364              :     }
    1365              : 
    1366          587 :   ret = build_call_expr_internal_loc (loc1, IFN_VEC_CONVERT, type, 1, expr);
    1367              : 
    1368          587 :   if (!wrap)
    1369          363 :     ret = c_wrap_maybe_const (ret, true);
    1370              : 
    1371              :   return ret;
    1372              : }
    1373              : 
    1374              : /* Like tree.cc:get_narrower, but retain conversion from C++0x scoped enum
    1375              :    to integral type.  */
    1376              : 
    1377              : tree
    1378     79681705 : c_common_get_narrower (tree op, int *unsignedp_ptr)
    1379              : {
    1380     79681705 :   op = get_narrower (op, unsignedp_ptr);
    1381              : 
    1382     79681705 :   if (TREE_CODE (TREE_TYPE (op)) == ENUMERAL_TYPE
    1383     79681705 :       && ENUM_IS_SCOPED (TREE_TYPE (op)))
    1384              :     {
    1385      2802438 :       if (BITINT_TYPE_P (TREE_TYPE (op)))
    1386            0 :         return fold_convert (ENUM_UNDERLYING_TYPE (TREE_TYPE (op)), op);
    1387              : 
    1388              :       /* C++0x scoped enumerations don't implicitly convert to integral
    1389              :          type; if we stripped an explicit conversion to a larger type we
    1390              :          need to replace it so common_type will still work.  */
    1391      2802438 :       tree type = c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op)),
    1392      2802438 :                                           TYPE_UNSIGNED (TREE_TYPE (op)));
    1393      2802438 :       op = fold_convert (type, op);
    1394              :     }
    1395              :   return op;
    1396              : }
    1397              : 
    1398              : /* This is a helper function of build_binary_op.
    1399              : 
    1400              :    For certain operations if both args were extended from the same
    1401              :    smaller type, do the arithmetic in that type and then extend.
    1402              : 
    1403              :    BITWISE indicates a bitwise operation.
    1404              :    For them, this optimization is safe only if
    1405              :    both args are zero-extended or both are sign-extended.
    1406              :    Otherwise, we might change the result.
    1407              :    Eg, (short)-1 | (unsigned short)-1 is (int)-1
    1408              :    but calculated in (unsigned short) it would be (unsigned short)-1.
    1409              : */
    1410              : tree
    1411      7975765 : shorten_binary_op (tree result_type, tree op0, tree op1, bool bitwise)
    1412              : {
    1413      7975765 :   int unsigned0, unsigned1;
    1414      7975765 :   tree arg0, arg1;
    1415      7975765 :   int uns;
    1416      7975765 :   tree type;
    1417              : 
    1418              :   /* Do not shorten vector operations.  */
    1419      7975765 :   if (VECTOR_TYPE_P (result_type))
    1420              :     return result_type;
    1421              : 
    1422              :   /* Cast OP0 and OP1 to RESULT_TYPE.  Doing so prevents
    1423              :      excessive narrowing when we call get_narrower below.  For
    1424              :      example, suppose that OP0 is of unsigned int extended
    1425              :      from signed char and that RESULT_TYPE is long long int.
    1426              :      If we explicitly cast OP0 to RESULT_TYPE, OP0 would look
    1427              :      like
    1428              : 
    1429              :      (long long int) (unsigned int) signed_char
    1430              : 
    1431              :      which get_narrower would narrow down to
    1432              : 
    1433              :      (unsigned int) signed char
    1434              : 
    1435              :      If we do not cast OP0 first, get_narrower would return
    1436              :      signed_char, which is inconsistent with the case of the
    1437              :      explicit cast.  */
    1438      7954586 :   op0 = convert (result_type, op0);
    1439      7954586 :   op1 = convert (result_type, op1);
    1440              : 
    1441      7954586 :   arg0 = c_common_get_narrower (op0, &unsigned0);
    1442      7954586 :   arg1 = c_common_get_narrower (op1, &unsigned1);
    1443              : 
    1444              :   /* UNS is 1 if the operation to be done is an unsigned one.  */
    1445      7954586 :   uns = TYPE_UNSIGNED (result_type);
    1446              : 
    1447              :   /* Handle the case that OP0 (or OP1) does not *contain* a conversion
    1448              :      but it *requires* conversion to FINAL_TYPE.  */
    1449              : 
    1450      7954586 :   if ((TYPE_PRECISION (TREE_TYPE (op0))
    1451      7954586 :        == TYPE_PRECISION (TREE_TYPE (arg0)))
    1452      7954586 :       && TREE_TYPE (op0) != result_type)
    1453         9027 :     unsigned0 = TYPE_UNSIGNED (TREE_TYPE (op0));
    1454      7954586 :   if ((TYPE_PRECISION (TREE_TYPE (op1))
    1455      7954586 :        == TYPE_PRECISION (TREE_TYPE (arg1)))
    1456      7954586 :       && TREE_TYPE (op1) != result_type)
    1457       360265 :     unsigned1 = TYPE_UNSIGNED (TREE_TYPE (op1));
    1458              : 
    1459              :   /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE.  */
    1460              : 
    1461              :   /* For bitwise operations, signedness of nominal type
    1462              :      does not matter.  Consider only how operands were extended.  */
    1463      7954586 :   if (bitwise)
    1464      2866567 :     uns = unsigned0;
    1465              : 
    1466              :   /* Note that in all three cases below we refrain from optimizing
    1467              :      an unsigned operation on sign-extended args.
    1468              :      That would not be valid.  */
    1469              : 
    1470              :   /* Both args variable: if both extended in same way
    1471              :      from same width, do it in that width.
    1472              :      Do it unsigned if args were zero-extended.  */
    1473      7954586 :   if ((TYPE_PRECISION (TREE_TYPE (arg0))
    1474      7954586 :        < TYPE_PRECISION (result_type))
    1475       408790 :       && (TYPE_PRECISION (TREE_TYPE (arg1))
    1476       408790 :           == TYPE_PRECISION (TREE_TYPE (arg0)))
    1477       318811 :       && unsigned0 == unsigned1
    1478      8273204 :       && (unsigned0 || !uns))
    1479              :     {
    1480       318600 :       tree ctype = common_type (TREE_TYPE (arg0), TREE_TYPE (arg1));
    1481       318600 :       if (ctype != error_mark_node)
    1482       318600 :         return c_common_signed_or_unsigned_type (unsigned0, ctype);
    1483              :     }
    1484              : 
    1485      7635986 :   else if (TREE_CODE (arg0) == INTEGER_CST
    1486      3762853 :            && (unsigned1 || !uns)
    1487      3402077 :            && (TYPE_PRECISION (TREE_TYPE (arg1))
    1488      3402077 :                < TYPE_PRECISION (result_type))
    1489          302 :            && (type
    1490          302 :                = c_common_signed_or_unsigned_type (unsigned1,
    1491          302 :                                                    TREE_TYPE (arg1)))
    1492          302 :            && !POINTER_TYPE_P (type)
    1493      7636288 :            && int_fits_type_p (arg0, type))
    1494              :     return type;
    1495              : 
    1496      7635737 :   else if (TREE_CODE (arg1) == INTEGER_CST
    1497      5415997 :            && (unsigned0 || !uns)
    1498      4444573 :            && (TYPE_PRECISION (TREE_TYPE (arg0))
    1499      4444573 :                < TYPE_PRECISION (result_type))
    1500        42442 :            && (type
    1501        42442 :                = c_common_signed_or_unsigned_type (unsigned0,
    1502        42442 :                                                    TREE_TYPE (arg0)))
    1503        42442 :            && !POINTER_TYPE_P (type)
    1504      7678179 :            && int_fits_type_p (arg1, type))
    1505              :     return type;
    1506              : 
    1507              :   return result_type;
    1508              : }
    1509              : 
    1510              : /* Returns true iff any integer value of type FROM_TYPE can be represented as
    1511              :    real of type TO_TYPE.  This is a helper function for unsafe_conversion_p.  */
    1512              : 
    1513              : static bool
    1514          101 : int_safely_convertible_to_real_p (const_tree from_type, const_tree to_type)
    1515              : {
    1516          101 :   tree type_low_bound = TYPE_MIN_VALUE (from_type);
    1517          101 :   tree type_high_bound = TYPE_MAX_VALUE (from_type);
    1518          101 :   REAL_VALUE_TYPE real_low_bound =
    1519          101 :           real_value_from_int_cst (0, type_low_bound);
    1520          101 :   REAL_VALUE_TYPE real_high_bound =
    1521          101 :           real_value_from_int_cst (0, type_high_bound);
    1522              : 
    1523          101 :   return exact_real_truncate (TYPE_MODE (to_type), &real_low_bound)
    1524          101 :          && exact_real_truncate (TYPE_MODE (to_type), &real_high_bound);
    1525              : }
    1526              : 
    1527              : /* Checks if expression EXPR of complex/real/integer type cannot be converted
    1528              :    to the complex/real/integer type TYPE.  Function returns non-zero when:
    1529              :         * EXPR is a constant which cannot be exactly converted to TYPE.
    1530              :         * EXPR is not a constant and size of EXPR's type > than size of TYPE,
    1531              :           for EXPR type and TYPE being both integers or both real, or both
    1532              :           complex.
    1533              :         * EXPR is not a constant of complex type and TYPE is a real or
    1534              :           an integer.
    1535              :         * EXPR is not a constant of real type and TYPE is an integer.
    1536              :         * EXPR is not a constant of integer type which cannot be
    1537              :           exactly converted to real type.
    1538              : 
    1539              :    Function allows conversions between types of different signedness if
    1540              :    CHECK_SIGN is false and can return SAFE_CONVERSION (zero) in that
    1541              :    case.  Function can return UNSAFE_SIGN if CHECK_SIGN is true.
    1542              : 
    1543              :    RESULT, when non-null is the result of the conversion.  When constant
    1544              :    it is included in the text of diagnostics.
    1545              : 
    1546              :    Function allows conversions from complex constants to non-complex types,
    1547              :    provided that imaginary part is zero and real part can be safely converted
    1548              :    to TYPE.  */
    1549              : 
    1550              : enum conversion_safety
    1551        10085 : unsafe_conversion_p (tree type, tree expr, tree result, bool check_sign)
    1552              : {
    1553        10085 :   enum conversion_safety give_warning = SAFE_CONVERSION; /* is 0 or false */
    1554        10085 :   tree expr_type = TREE_TYPE (expr);
    1555              : 
    1556        10085 :   expr = fold_for_warn (expr);
    1557              : 
    1558        10085 :   if (TREE_CODE (expr) == REAL_CST || TREE_CODE (expr) == INTEGER_CST)
    1559              :     {
    1560              :       /* If type is complex, we are interested in compatibility with
    1561              :          underlying type.  */
    1562         5833 :       if (TREE_CODE (type) == COMPLEX_TYPE)
    1563          114 :           type = TREE_TYPE (type);
    1564              : 
    1565              :       /* Warn for real constant that is not an exact integer converted
    1566              :          to integer type.  */
    1567         5833 :       if (SCALAR_FLOAT_TYPE_P (expr_type)
    1568          685 :           && (TREE_CODE (type) == INTEGER_TYPE
    1569          685 :               || TREE_CODE (type) == BITINT_TYPE))
    1570              :         {
    1571          283 :           if (!real_isinteger (TREE_REAL_CST_PTR (expr), TYPE_MODE (expr_type)))
    1572          275 :             give_warning = UNSAFE_REAL;
    1573              :         }
    1574              :       /* Warn for an integer constant that does not fit into integer type.  */
    1575         5550 :       else if ((TREE_CODE (expr_type) == INTEGER_TYPE
    1576         5550 :                 || TREE_CODE (expr_type) == BITINT_TYPE)
    1577         5138 :                && (TREE_CODE (type) == INTEGER_TYPE
    1578         5138 :                    || TREE_CODE (type) == BITINT_TYPE)
    1579         4412 :                && !int_fits_type_p (expr, type))
    1580              :         {
    1581          997 :           if (TYPE_UNSIGNED (type) && !TYPE_UNSIGNED (expr_type)
    1582          963 :               && tree_int_cst_sgn (expr) < 0)
    1583              :             {
    1584          265 :               if (check_sign)
    1585         1834 :                 give_warning = UNSAFE_SIGN;
    1586              :             }
    1587          432 :           else if (!TYPE_UNSIGNED (type) && TYPE_UNSIGNED (expr_type))
    1588              :             {
    1589          335 :               if (check_sign)
    1590         1834 :                 give_warning = UNSAFE_SIGN;
    1591              :             }
    1592              :           else
    1593              :             give_warning = UNSAFE_OTHER;
    1594              :         }
    1595         4853 :       else if (SCALAR_FLOAT_TYPE_P (type))
    1596              :         {
    1597              :           /* Warn for an integer constant that does not fit into real type.  */
    1598         1038 :           if (TREE_CODE (expr_type) == INTEGER_TYPE
    1599              :               || TREE_CODE (expr_type) == BITINT_TYPE)
    1600              :             {
    1601          636 :               REAL_VALUE_TYPE a = real_value_from_int_cst (0, expr);
    1602          636 :               if (!exact_real_truncate (TYPE_MODE (type), &a))
    1603           53 :                 give_warning = UNSAFE_REAL;
    1604              :             }
    1605              :           /* Warn for a real constant that does not fit into a smaller
    1606              :              real type.  */
    1607          402 :           else if (SCALAR_FLOAT_TYPE_P (expr_type)
    1608          402 :                    && TYPE_PRECISION (type) < TYPE_PRECISION (expr_type))
    1609              :             {
    1610          227 :               REAL_VALUE_TYPE a = TREE_REAL_CST (expr);
    1611          227 :               if (!exact_real_truncate (TYPE_MODE (type), &a))
    1612           65 :                 give_warning = UNSAFE_REAL;
    1613              :             }
    1614              :         }
    1615              :     }
    1616              : 
    1617         4252 :   else if (TREE_CODE (expr) == COMPLEX_CST)
    1618              :     {
    1619           69 :       tree imag_part = TREE_IMAGPART (expr);
    1620              :       /* Conversion from complex constant with zero imaginary part,
    1621              :          perform check for conversion of real part.  */
    1622           69 :       if ((TREE_CODE (imag_part) == REAL_CST
    1623           29 :            && real_zerop (imag_part))
    1624           80 :           || (TREE_CODE (imag_part) == INTEGER_CST
    1625           40 :               && integer_zerop (imag_part)))
    1626              :         /* Note: in this branch we use recursive call to unsafe_conversion_p
    1627              :            with different type of EXPR, but it is still safe, because when EXPR
    1628              :            is a constant, it's type is not used in text of generated warnings
    1629              :            (otherwise they could sound misleading).  */
    1630           30 :         return unsafe_conversion_p (type, TREE_REALPART (expr), result,
    1631           30 :                                     check_sign);
    1632              :       /* Conversion from complex constant with non-zero imaginary part.  */
    1633              :       else
    1634              :         {
    1635              :           /* Conversion to complex type.
    1636              :              Perform checks for both real and imaginary parts.  */
    1637           39 :           if (TREE_CODE (type) == COMPLEX_TYPE)
    1638              :             {
    1639           33 :               enum conversion_safety re_safety =
    1640           33 :                 unsafe_conversion_p (type, TREE_REALPART (expr),
    1641              :                                      result, check_sign);
    1642           33 :               enum conversion_safety im_safety =
    1643           33 :                 unsafe_conversion_p (type, imag_part, result, check_sign);
    1644              : 
    1645              :               /* Merge the results into appropriate single warning.  */
    1646              : 
    1647              :               /* Note: this case includes SAFE_CONVERSION, i.e. success.  */
    1648           33 :               if (re_safety == im_safety)
    1649              :                 give_warning = re_safety;
    1650            9 :               else if (!re_safety && im_safety)
    1651              :                 give_warning = im_safety;
    1652            4 :               else if (re_safety && !im_safety)
    1653              :                 give_warning = re_safety;
    1654              :               else
    1655          670 :                 give_warning = UNSAFE_OTHER;
    1656              :             }
    1657              :           /* Warn about conversion from complex to real or integer type.  */
    1658              :           else
    1659              :             give_warning = UNSAFE_IMAGINARY;
    1660              :         }
    1661              :     }
    1662              : 
    1663              :   /* Checks for remaining case: EXPR is not constant.  */
    1664              :   else
    1665              :     {
    1666              :       /* Warn for real types converted to integer types.  */
    1667         4183 :       if (SCALAR_FLOAT_TYPE_P (expr_type)
    1668          244 :           && (TREE_CODE (type) == INTEGER_TYPE
    1669          244 :               || TREE_CODE (type) == BITINT_TYPE))
    1670              :         give_warning = UNSAFE_REAL;
    1671              : 
    1672         4154 :       else if ((TREE_CODE (expr_type) == INTEGER_TYPE
    1673         4154 :                 || TREE_CODE (expr_type) == BITINT_TYPE)
    1674         3728 :                && (TREE_CODE (type) == INTEGER_TYPE
    1675         3728 :                    || TREE_CODE (type) == BITINT_TYPE))
    1676              :         {
    1677              :           /* Don't warn about unsigned char y = 0xff, x = (int) y;  */
    1678         3507 :           expr = get_unwidened (expr, 0);
    1679         3507 :           expr_type = TREE_TYPE (expr);
    1680              : 
    1681              :           /* Don't warn for short y; short x = ((int)y & 0xff);  */
    1682         3507 :           if (TREE_CODE (expr) == BIT_AND_EXPR
    1683         3493 :               || TREE_CODE (expr) == BIT_IOR_EXPR
    1684         3452 :               || TREE_CODE (expr) == BIT_XOR_EXPR)
    1685              :             {
    1686              :               /* If both args were extended from a shortest type,
    1687              :                  use that type if that is safe.  */
    1688           59 :               expr_type = shorten_binary_op (expr_type,
    1689           59 :                                              TREE_OPERAND (expr, 0),
    1690           59 :                                              TREE_OPERAND (expr, 1),
    1691              :                                              /* bitwise */1);
    1692              : 
    1693           59 :               if (TREE_CODE (expr) == BIT_AND_EXPR)
    1694              :                 {
    1695           14 :                   tree op0 = TREE_OPERAND (expr, 0);
    1696           14 :                   tree op1 = TREE_OPERAND (expr, 1);
    1697           14 :                   bool unsigned0 = TYPE_UNSIGNED (TREE_TYPE (op0));
    1698           14 :                   bool unsigned1 = TYPE_UNSIGNED (TREE_TYPE (op1));
    1699              : 
    1700              :                   /* If one of the operands is a non-negative constant
    1701              :                      that fits in the target type, then the type of the
    1702              :                      other operand does not matter. */
    1703           14 :                   if ((TREE_CODE (op0) == INTEGER_CST
    1704            0 :                        && int_fits_type_p (op0, c_common_signed_type (type))
    1705            0 :                        && int_fits_type_p (op0, c_common_unsigned_type (type)))
    1706           14 :                       || (TREE_CODE (op1) == INTEGER_CST
    1707            1 :                           && int_fits_type_p (op1, c_common_signed_type (type))
    1708            1 :                           && int_fits_type_p (op1,
    1709            1 :                                               c_common_unsigned_type (type))))
    1710            1 :                     return SAFE_CONVERSION;
    1711              :                   /* If constant is unsigned and fits in the target
    1712              :                      type, then the result will also fit.  */
    1713           13 :                   else if ((TREE_CODE (op0) == INTEGER_CST
    1714            0 :                             && unsigned0
    1715            0 :                             && int_fits_type_p (op0, type))
    1716           13 :                            || (TREE_CODE (op1) == INTEGER_CST
    1717            0 :                                && unsigned1
    1718            0 :                                && int_fits_type_p (op1, type)))
    1719              :                     return SAFE_CONVERSION;
    1720              :                 }
    1721              :             }
    1722              :           /* Warn for integer types converted to smaller integer types.  */
    1723         3506 :           if (TYPE_PRECISION (type) < TYPE_PRECISION (expr_type))
    1724              :             give_warning = UNSAFE_OTHER;
    1725              : 
    1726              :           /* When they are the same width but different signedness,
    1727              :              then the value may change.  */
    1728         2970 :           else if (((TYPE_PRECISION (type) == TYPE_PRECISION (expr_type)
    1729         2414 :                      && TYPE_UNSIGNED (expr_type) != TYPE_UNSIGNED (type))
    1730              :                     /* Even when converted to a bigger type, if the type is
    1731              :                        unsigned but expr is signed, then negative values
    1732              :                        will be changed.  */
    1733         1707 :                     || (TYPE_UNSIGNED (type) && !TYPE_UNSIGNED (expr_type)))
    1734         4289 :                    && check_sign)
    1735              :             give_warning = UNSAFE_SIGN;
    1736              :         }
    1737              : 
    1738              :       /* Warn for integer types converted to real types if and only if
    1739              :          all the range of values of the integer type cannot be
    1740              :          represented by the real type.  */
    1741          647 :       else if ((TREE_CODE (expr_type) == INTEGER_TYPE
    1742              :                 || TREE_CODE (expr_type) == BITINT_TYPE)
    1743          221 :                && SCALAR_FLOAT_TYPE_P (type))
    1744              :         {
    1745              :           /* Don't warn about char y = 0xff; float x = (int) y;  */
    1746          101 :           expr = get_unwidened (expr, 0);
    1747          101 :           expr_type = TREE_TYPE (expr);
    1748              : 
    1749          101 :           if (!int_safely_convertible_to_real_p (expr_type, type))
    1750          670 :             give_warning = UNSAFE_OTHER;
    1751              :         }
    1752              : 
    1753              :       /* Warn for real types converted to smaller real types.  */
    1754          546 :       else if (SCALAR_FLOAT_TYPE_P (expr_type)
    1755          215 :                && SCALAR_FLOAT_TYPE_P (type)
    1756          761 :                && TYPE_PRECISION (type) < TYPE_PRECISION (expr_type))
    1757              :         give_warning = UNSAFE_REAL;
    1758              : 
    1759              :       /* Check conversion between two complex types.  */
    1760          494 :       else if (TREE_CODE (expr_type) == COMPLEX_TYPE
    1761           32 :                && TREE_CODE (type) == COMPLEX_TYPE)
    1762              :         {
    1763              :           /* Extract underlying types (i.e., type of real and imaginary
    1764              :              parts) of expr_type and type.  */
    1765           10 :           tree from_type = TREE_TYPE (expr_type);
    1766           10 :           tree to_type = TREE_TYPE (type);
    1767              : 
    1768              :           /* Warn for real types converted to integer types.  */
    1769           10 :           if (SCALAR_FLOAT_TYPE_P (from_type)
    1770            8 :               && TREE_CODE (to_type) == INTEGER_TYPE)
    1771              :             give_warning = UNSAFE_REAL;
    1772              : 
    1773              :           /* Warn for real types converted to smaller real types.  */
    1774            6 :           else if (SCALAR_FLOAT_TYPE_P (from_type)
    1775            4 :                    && SCALAR_FLOAT_TYPE_P (to_type)
    1776           10 :                    && TYPE_PRECISION (to_type) < TYPE_PRECISION (from_type))
    1777              :             give_warning = UNSAFE_REAL;
    1778              : 
    1779              :           /* Check conversion for complex integer types.  Here implementation
    1780              :              is simpler than for real-domain integers because it does not
    1781              :              involve sophisticated cases, such as bitmasks, casts, etc.  */
    1782            4 :           else if (TREE_CODE (from_type) == INTEGER_TYPE
    1783            2 :                    && TREE_CODE (to_type) == INTEGER_TYPE)
    1784              :             {
    1785              :               /* Warn for integer types converted to smaller integer types.  */
    1786            2 :               if (TYPE_PRECISION (to_type) < TYPE_PRECISION (from_type))
    1787              :                 give_warning = UNSAFE_OTHER;
    1788              : 
    1789              :               /* Check for different signedness, see case for real-domain
    1790              :                  integers (above) for a more detailed comment.  */
    1791            0 :               else if (((TYPE_PRECISION (to_type) == TYPE_PRECISION (from_type)
    1792            0 :                          && TYPE_UNSIGNED (to_type) != TYPE_UNSIGNED (from_type))
    1793            0 :                         || (TYPE_UNSIGNED (to_type) && !TYPE_UNSIGNED (from_type)))
    1794            0 :                        && check_sign)
    1795              :                 give_warning = UNSAFE_SIGN;
    1796              :             }
    1797            2 :           else if (TREE_CODE (from_type) == INTEGER_TYPE
    1798            0 :                    && SCALAR_FLOAT_TYPE_P (to_type)
    1799            2 :                    && !int_safely_convertible_to_real_p (from_type, to_type))
    1800              :             give_warning = UNSAFE_OTHER;
    1801              :         }
    1802              : 
    1803              :       /* Warn for complex types converted to real or integer types.  */
    1804          484 :       else if (TREE_CODE (expr_type) == COMPLEX_TYPE
    1805           22 :                && TREE_CODE (type) != COMPLEX_TYPE)
    1806           28 :         give_warning = UNSAFE_IMAGINARY;
    1807              :     }
    1808              : 
    1809              :   return give_warning;
    1810              : }
    1811              : 
    1812              : 
    1813              : /* Convert EXPR to TYPE, warning about conversion problems with constants.
    1814              :    Invoke this function on every expression that is converted implicitly,
    1815              :    i.e. because of language rules and not because of an explicit cast.
    1816              :    INIT_CONST is true if the conversion is for arithmetic types for a static
    1817              :    initializer and folding must apply accordingly (discarding floating-point
    1818              :    exceptions and assuming the default rounding mode is in effect).  */
    1819              : 
    1820              : tree
    1821     12210452 : convert_and_check (location_t loc, tree type, tree expr, bool init_const)
    1822              : {
    1823     12210452 :   tree result;
    1824     12210452 :   tree expr_for_warning;
    1825              : 
    1826              :   /* Convert from a value with possible excess precision rather than
    1827              :      via the semantic type, but do not warn about values not fitting
    1828              :      exactly in the semantic type.  */
    1829     12210452 :   if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
    1830              :     {
    1831         5985 :       tree orig_type = TREE_TYPE (expr);
    1832         5985 :       expr = TREE_OPERAND (expr, 0);
    1833         5985 :       expr_for_warning = (init_const
    1834         5985 :                           ? convert_init (orig_type, expr)
    1835         5624 :                           : convert (orig_type, expr));
    1836         5985 :       if (orig_type == type)
    1837              :         return expr_for_warning;
    1838              :     }
    1839              :   else
    1840              :     expr_for_warning = expr;
    1841              : 
    1842     12204960 :   if (TREE_TYPE (expr) == type)
    1843              :     return expr;
    1844              : 
    1845     10890147 :   result = init_const ? convert_init (type, expr) : convert (type, expr);
    1846              : 
    1847     10890147 :   if (c_inhibit_evaluation_warnings == 0
    1848     10556329 :       && !TREE_OVERFLOW_P (expr)
    1849     10556303 :       && result != error_mark_node
    1850     21446296 :       && !c_hardbool_type_attr (type))
    1851     10548802 :     warnings_for_convert_and_check (loc, type, expr_for_warning, result);
    1852              : 
    1853              :   return result;
    1854              : }
    1855              : 
    1856              : /* A node in a list that describes references to variables (EXPR), which are
    1857              :    either read accesses if WRITER is zero, or write accesses, in which case
    1858              :    WRITER is the parent of EXPR.  */
    1859              : struct tlist
    1860              : {
    1861              :   struct tlist *next;
    1862              :   tree expr, writer;
    1863              : };
    1864              : 
    1865              : /* Used to implement a cache the results of a call to verify_tree.  We only
    1866              :    use this for SAVE_EXPRs.  */
    1867              : struct tlist_cache
    1868              : {
    1869              :   struct tlist_cache *next;
    1870              :   struct tlist *cache_before_sp;
    1871              :   struct tlist *cache_after_sp;
    1872              :   tree expr;
    1873              : };
    1874              : 
    1875              : /* Obstack to use when allocating tlist structures, and corresponding
    1876              :    firstobj.  */
    1877              : static struct obstack tlist_obstack;
    1878              : static char *tlist_firstobj = 0;
    1879              : 
    1880              : /* Keep track of the identifiers we've warned about, so we can avoid duplicate
    1881              :    warnings.  */
    1882              : static struct tlist *warned_ids;
    1883              : /* SAVE_EXPRs need special treatment.  We process them only once and then
    1884              :    cache the results.  */
    1885              : static struct tlist_cache *save_expr_cache;
    1886              : 
    1887              : static void add_tlist (struct tlist **, struct tlist *, tree, int);
    1888              : static void merge_tlist (struct tlist **, struct tlist *, int);
    1889              : static void verify_tree (tree, struct tlist **, struct tlist **, tree);
    1890              : static bool warning_candidate_p (tree);
    1891              : static bool candidate_equal_p (const_tree, const_tree);
    1892              : static void warn_for_collisions (struct tlist *);
    1893              : static void warn_for_collisions_1 (tree, tree, struct tlist *, int);
    1894              : static struct tlist *new_tlist (struct tlist *, tree, tree);
    1895              : 
    1896              : /* Create a new struct tlist and fill in its fields.  */
    1897              : static struct tlist *
    1898     34704724 : new_tlist (struct tlist *next, tree t, tree writer)
    1899              : {
    1900     34704724 :   struct tlist *l;
    1901     34704724 :   l = XOBNEW (&tlist_obstack, struct tlist);
    1902     34704724 :   l->next = next;
    1903     34704724 :   l->expr = t;
    1904     34704724 :   l->writer = writer;
    1905     34704724 :   return l;
    1906              : }
    1907              : 
    1908              : /* Add duplicates of the nodes found in ADD to the list *TO.  If EXCLUDE_WRITER
    1909              :    is nonnull, we ignore any node we find which has a writer equal to it.  */
    1910              : 
    1911              : static void
    1912     61232964 : add_tlist (struct tlist **to, struct tlist *add, tree exclude_writer, int copy)
    1913              : {
    1914    133104464 :   while (add)
    1915              :     {
    1916     71871500 :       struct tlist *next = add->next;
    1917     13226875 :       if (!copy)
    1918      1902943 :         add->next = *to;
    1919     13226875 :       if (!exclude_writer || !candidate_equal_p (add->writer, exclude_writer))
    1920     69827724 :         *to = copy ? new_tlist (*to, add->expr, add->writer) : add;
    1921              :       add = next;
    1922              :     }
    1923     11878830 : }
    1924              : 
    1925              : /* Merge the nodes of ADD into TO.  This merging process is done so that for
    1926              :    each variable that already exists in TO, no new node is added; however if
    1927              :    there is a write access recorded in ADD, and an occurrence on TO is only
    1928              :    a read access, then the occurrence in TO will be modified to record the
    1929              :    write.  */
    1930              : 
    1931              : static void
    1932     42860434 : merge_tlist (struct tlist **to, struct tlist *add, int copy)
    1933              : {
    1934     42860434 :   struct tlist **end = to;
    1935              : 
    1936     79954748 :   while (*end)
    1937     37094314 :     end = &(*end)->next;
    1938              : 
    1939     58856620 :   while (add)
    1940              :     {
    1941     15996186 :       int found = 0;
    1942     15996186 :       struct tlist *tmp2;
    1943     15996186 :       struct tlist *next = add->next;
    1944              : 
    1945     43565983 :       for (tmp2 = *to; tmp2; tmp2 = tmp2->next)
    1946     27569797 :         if (candidate_equal_p (tmp2->expr, add->expr))
    1947              :           {
    1948      2754944 :             found = 1;
    1949      2754944 :             if (!tmp2->writer)
    1950      2748290 :               tmp2->writer = add->writer;
    1951              :           }
    1952     15996186 :       if (!found)
    1953              :         {
    1954     13255440 :           *end = copy ? new_tlist (NULL, add->expr, add->writer) : add;
    1955     13255440 :           end = &(*end)->next;
    1956     13255440 :           *end = 0;
    1957              :         }
    1958              :       add = next;
    1959              :     }
    1960     42860434 : }
    1961              : 
    1962              : /* WRITTEN is a variable, WRITER is its parent.  Warn if any of the variable
    1963              :    references in list LIST conflict with it, excluding reads if ONLY writers
    1964              :    is nonzero.  */
    1965              : 
    1966              : static void
    1967      5278655 : warn_for_collisions_1 (tree written, tree writer, struct tlist *list,
    1968              :                        int only_writes)
    1969              : {
    1970      5278655 :   struct tlist *tmp;
    1971              : 
    1972              :   /* Avoid duplicate warnings.  */
    1973      5278818 :   for (tmp = warned_ids; tmp; tmp = tmp->next)
    1974          611 :     if (candidate_equal_p (tmp->expr, written))
    1975              :       return;
    1976              : 
    1977     18965908 :   while (list)
    1978              :     {
    1979     13687701 :       if (candidate_equal_p (list->expr, written)
    1980      1562809 :           && !candidate_equal_p (list->writer, writer)
    1981     13830462 :           && (!only_writes || list->writer))
    1982              :         {
    1983          562 :           warned_ids = new_tlist (warned_ids, written, NULL_TREE);
    1984          562 :           warning_at (EXPR_LOC_OR_LOC (writer, input_location),
    1985          562 :                       OPT_Wsequence_point, "operation on %qE may be undefined",
    1986              :                       list->expr);
    1987              :         }
    1988     13687701 :       list = list->next;
    1989              :     }
    1990              : }
    1991              : 
    1992              : /* Given a list LIST of references to variables, find whether any of these
    1993              :    can cause conflicts due to missing sequence points.  */
    1994              : 
    1995              : static void
    1996     20184196 : warn_for_collisions (struct tlist *list)
    1997              : {
    1998     20184196 :   struct tlist *tmp;
    1999              : 
    2000     55593282 :   for (tmp = list; tmp; tmp = tmp->next)
    2001              :     {
    2002     35409086 :       if (tmp->writer)
    2003      1352047 :         warn_for_collisions_1 (tmp->expr, tmp->writer, list, 0);
    2004              :     }
    2005     20184196 : }
    2006              : 
    2007              : /* Return nonzero if X is a tree that can be verified by the sequence point
    2008              :    warnings.  */
    2009              : 
    2010              : static bool
    2011     77380660 : warning_candidate_p (tree x)
    2012              : {
    2013     77380660 :   if (DECL_P (x) && DECL_ARTIFICIAL (x))
    2014              :     return false;
    2015              : 
    2016     69634420 :   if (TREE_CODE (x) == BLOCK)
    2017              :     return false;
    2018              : 
    2019              :   /* VOID_TYPE_P (TREE_TYPE (x)) is workaround for cp/tree.cc
    2020              :      (lvalue_p) crash on TRY/CATCH. */
    2021     69632227 :   if (TREE_TYPE (x) == NULL_TREE || VOID_TYPE_P (TREE_TYPE (x)))
    2022              :     return false;
    2023              : 
    2024     68707151 :   if (!lvalue_p (x))
    2025              :     return false;
    2026              : 
    2027              :   /* No point to track non-const calls, they will never satisfy
    2028              :      operand_equal_p.  */
    2029     24744147 :   if (TREE_CODE (x) == CALL_EXPR && (call_expr_flags (x) & ECF_CONST) == 0)
    2030              :     return false;
    2031              : 
    2032     24698779 :   if (TREE_CODE (x) == STRING_CST)
    2033              :     return false;
    2034              : 
    2035              :   return true;
    2036              : }
    2037              : 
    2038              : /* Return nonzero if X and Y appear to be the same candidate (or NULL) */
    2039              : static bool
    2040     46680894 : candidate_equal_p (const_tree x, const_tree y)
    2041              : {
    2042     46680894 :   return (x == y) || (x && y && operand_equal_p (x, y, 0));
    2043              : }
    2044              : 
    2045              : /* Walk the tree X, and record accesses to variables.  If X is written by the
    2046              :    parent tree, WRITER is the parent.
    2047              :    We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP.  If this
    2048              :    expression or its only operand forces a sequence point, then everything up
    2049              :    to the sequence point is stored in PBEFORE_SP.  Everything else gets stored
    2050              :    in PNO_SP.
    2051              :    Once we return, we will have emitted warnings if any subexpression before
    2052              :    such a sequence point could be undefined.  On a higher level, however, the
    2053              :    sequence point may not be relevant, and we'll merge the two lists.
    2054              : 
    2055              :    Example: (b++, a) + b;
    2056              :    The call that processes the COMPOUND_EXPR will store the increment of B
    2057              :    in PBEFORE_SP, and the use of A in PNO_SP.  The higher-level call that
    2058              :    processes the PLUS_EXPR will need to merge the two lists so that
    2059              :    eventually, all accesses end up on the same list (and we'll warn about the
    2060              :    unordered subexpressions b++ and b.
    2061              : 
    2062              :    A note on merging.  If we modify the former example so that our expression
    2063              :    becomes
    2064              :      (b++, b) + a
    2065              :    care must be taken not simply to add all three expressions into the final
    2066              :    PNO_SP list.  The function merge_tlist takes care of that by merging the
    2067              :    before-SP list of the COMPOUND_EXPR into its after-SP list in a special
    2068              :    way, so that no more than one access to B is recorded.  */
    2069              : 
    2070              : static void
    2071     60728030 : verify_tree (tree x, struct tlist **pbefore_sp, struct tlist **pno_sp,
    2072              :              tree writer)
    2073              : {
    2074     74686644 :   struct tlist *tmp_before, *tmp_nosp, *tmp_list2, *tmp_list3;
    2075     74686644 :   enum tree_code code;
    2076     74686644 :   enum tree_code_class cl;
    2077              : 
    2078     74686644 :  restart:
    2079              :   /* X may be NULL if it is the operand of an empty statement expression
    2080              :      ({ }).  */
    2081     74686644 :   if (x == NULL)
    2082              :     return;
    2083              : 
    2084     73454052 :   code = TREE_CODE (x);
    2085     73454052 :   cl = TREE_CODE_CLASS (code);
    2086              : 
    2087     73454052 :   if (warning_candidate_p (x))
    2088     23441684 :     *pno_sp = new_tlist (*pno_sp, x, writer);
    2089              : 
    2090     73454052 :   switch (code)
    2091              :     {
    2092              :     case CONSTRUCTOR:
    2093              :     case SIZEOF_EXPR:
    2094              :     case PAREN_SIZEOF_EXPR:
    2095              :       return;
    2096              : 
    2097       216658 :     case COMPOUND_EXPR:
    2098       216658 :     case TRUTH_ANDIF_EXPR:
    2099       216658 :     case TRUTH_ORIF_EXPR:
    2100       216658 :     sequenced_binary:
    2101       216658 :       tmp_before = tmp_nosp = tmp_list2 = tmp_list3 = 0;
    2102       216658 :       verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE);
    2103       216658 :       warn_for_collisions (tmp_nosp);
    2104       216658 :       merge_tlist (pbefore_sp, tmp_before, 0);
    2105       216658 :       merge_tlist (pbefore_sp, tmp_nosp, 0);
    2106       216658 :       verify_tree (TREE_OPERAND (x, 1), &tmp_list3, &tmp_list2, NULL_TREE);
    2107       216658 :       warn_for_collisions (tmp_list2);
    2108       216658 :       merge_tlist (pbefore_sp, tmp_list3, 0);
    2109       216658 :       merge_tlist (pno_sp, tmp_list2, 0);
    2110       216658 :       return;
    2111              : 
    2112        69682 :     case COND_EXPR:
    2113        69682 :       tmp_before = tmp_list2 = 0;
    2114        69682 :       verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_list2, NULL_TREE);
    2115        69682 :       warn_for_collisions (tmp_list2);
    2116        69682 :       merge_tlist (pbefore_sp, tmp_before, 0);
    2117        69682 :       merge_tlist (pbefore_sp, tmp_list2, 0);
    2118              : 
    2119        69682 :       tmp_list3 = tmp_nosp = 0;
    2120        69682 :       verify_tree (TREE_OPERAND (x, 1), &tmp_list3, &tmp_nosp, NULL_TREE);
    2121        69682 :       warn_for_collisions (tmp_nosp);
    2122        69682 :       merge_tlist (pbefore_sp, tmp_list3, 0);
    2123              : 
    2124        69682 :       tmp_list3 = tmp_list2 = 0;
    2125        69682 :       verify_tree (TREE_OPERAND (x, 2), &tmp_list3, &tmp_list2, NULL_TREE);
    2126        69682 :       warn_for_collisions (tmp_list2);
    2127        69682 :       merge_tlist (pbefore_sp, tmp_list3, 0);
    2128              :       /* Rather than add both tmp_nosp and tmp_list2, we have to merge the
    2129              :          two first, to avoid warning for (a ? b++ : b++).  */
    2130        69682 :       merge_tlist (&tmp_nosp, tmp_list2, 0);
    2131        69682 :       add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
    2132              :       return;
    2133              : 
    2134       270209 :     case PREDECREMENT_EXPR:
    2135       270209 :     case PREINCREMENT_EXPR:
    2136       270209 :     case POSTDECREMENT_EXPR:
    2137       270209 :     case POSTINCREMENT_EXPR:
    2138       270209 :       verify_tree (TREE_OPERAND (x, 0), pno_sp, pno_sp, x);
    2139       270209 :       return;
    2140              : 
    2141      3926608 :     case MODIFY_EXPR:
    2142      3926608 :       tmp_before = tmp_nosp = tmp_list3 = 0;
    2143      3926608 :       verify_tree (TREE_OPERAND (x, 1), &tmp_before, &tmp_nosp, NULL_TREE);
    2144      3926608 :       verify_tree (TREE_OPERAND (x, 0), &tmp_list3, &tmp_list3, x);
    2145              :       /* Expressions inside the LHS are not ordered wrt. the sequence points
    2146              :          in the RHS.  Example:
    2147              :            *a = (a++, 2)
    2148              :          Despite the fact that the modification of "a" is in the before_sp
    2149              :          list (tmp_before), it conflicts with the use of "a" in the LHS.
    2150              :          We can handle this by adding the contents of tmp_list3
    2151              :          to those of tmp_before, and redoing the collision warnings for that
    2152              :          list.  */
    2153      3926608 :       add_tlist (&tmp_before, tmp_list3, x, 1);
    2154      3926608 :       warn_for_collisions (tmp_before);
    2155              :       /* Exclude the LHS itself here; we first have to merge it into the
    2156              :          tmp_nosp list.  This is done to avoid warning for "a = a"; if we
    2157              :          didn't exclude the LHS, we'd get it twice, once as a read and once
    2158              :          as a write.  */
    2159      3926608 :       add_tlist (pno_sp, tmp_list3, x, 0);
    2160      3926608 :       warn_for_collisions_1 (TREE_OPERAND (x, 0), x, tmp_nosp, 1);
    2161              : 
    2162      3926608 :       merge_tlist (pbefore_sp, tmp_before, 0);
    2163      3926608 :       if (warning_candidate_p (TREE_OPERAND (x, 0)))
    2164       953785 :         merge_tlist (&tmp_nosp, new_tlist (NULL, TREE_OPERAND (x, 0), x), 0);
    2165      3926608 :       add_tlist (pno_sp, tmp_nosp, NULL_TREE, 1);
    2166      3926608 :       return;
    2167              : 
    2168      6333613 :     case CALL_EXPR:
    2169              :       /* We need to warn about conflicts among arguments and conflicts between
    2170              :          args and the function address.  Side effects of the function address,
    2171              :          however, are not ordered by the sequence point of the call.  */
    2172      6333613 :       {
    2173      6333613 :         call_expr_arg_iterator iter;
    2174      6333613 :         tree arg;
    2175      6333613 :         tmp_before = tmp_nosp = 0;
    2176      6333613 :         verify_tree (CALL_EXPR_FN (x), &tmp_before, &tmp_nosp, NULL_TREE);
    2177     28055729 :         FOR_EACH_CALL_EXPR_ARG (arg, iter, x)
    2178              :           {
    2179     15388503 :             tmp_list2 = tmp_list3 = 0;
    2180     15388503 :             verify_tree (arg, &tmp_list2, &tmp_list3, NULL_TREE);
    2181     15388503 :             merge_tlist (&tmp_list3, tmp_list2, 0);
    2182     30777006 :             add_tlist (&tmp_before, tmp_list3, NULL_TREE, 0);
    2183              :           }
    2184      6333613 :         add_tlist (&tmp_before, tmp_nosp, NULL_TREE, 0);
    2185      6333613 :         warn_for_collisions (tmp_before);
    2186      6333613 :         add_tlist (pbefore_sp, tmp_before, NULL_TREE, 0);
    2187      6333613 :         return;
    2188              :       }
    2189              : 
    2190              :     case TREE_LIST:
    2191              :       /* Scan all the list, e.g. indices of multi dimensional array.  */
    2192            6 :       while (x)
    2193              :         {
    2194            3 :           tmp_before = tmp_nosp = 0;
    2195            3 :           verify_tree (TREE_VALUE (x), &tmp_before, &tmp_nosp, NULL_TREE);
    2196            3 :           merge_tlist (&tmp_nosp, tmp_before, 0);
    2197            3 :           add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
    2198            3 :           x = TREE_CHAIN (x);
    2199              :         }
    2200              :       return;
    2201              : 
    2202        99006 :     case SAVE_EXPR:
    2203        99006 :       {
    2204        99006 :         struct tlist_cache *t;
    2205       102857 :         for (t = save_expr_cache; t; t = t->next)
    2206        54090 :           if (candidate_equal_p (t->expr, x))
    2207              :             break;
    2208              : 
    2209        99006 :         if (!t)
    2210              :           {
    2211        48767 :             t = XOBNEW (&tlist_obstack, struct tlist_cache);
    2212        48767 :             t->next = save_expr_cache;
    2213        48767 :             t->expr = x;
    2214        48767 :             save_expr_cache = t;
    2215              : 
    2216        48767 :             tmp_before = tmp_nosp = 0;
    2217        48767 :             verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE);
    2218        48767 :             warn_for_collisions (tmp_nosp);
    2219              : 
    2220        48767 :             tmp_list3 = 0;
    2221        48767 :             merge_tlist (&tmp_list3, tmp_nosp, 0);
    2222        48767 :             t->cache_before_sp = tmp_before;
    2223        48767 :             t->cache_after_sp = tmp_list3;
    2224              :           }
    2225        99006 :         merge_tlist (pbefore_sp, t->cache_before_sp, 1);
    2226        99006 :         add_tlist (pno_sp, t->cache_after_sp, NULL_TREE, 1);
    2227        99006 :         return;
    2228              :       }
    2229              : 
    2230      7224120 :     case ADDR_EXPR:
    2231      7224120 :       x = TREE_OPERAND (x, 0);
    2232      7224120 :       if (DECL_P (x))
    2233              :         return;
    2234       521426 :       writer = 0;
    2235       521426 :       goto restart;
    2236              : 
    2237     12114897 :     case VIEW_CONVERT_EXPR:
    2238     12114897 :       if (location_wrapper_p (x))
    2239              :         {
    2240      3067606 :           x = TREE_OPERAND (x, 0);
    2241      3067606 :           goto restart;
    2242              :         }
    2243      9047291 :       goto do_default;
    2244              : 
    2245       629531 :     case LSHIFT_EXPR:
    2246       629531 :     case RSHIFT_EXPR:
    2247       629531 :     case ARRAY_REF:
    2248       629531 :       if (cxx_dialect >= cxx17)
    2249        51683 :         goto sequenced_binary;
    2250       577848 :       goto do_default;
    2251              : 
    2252      1328629 :     case COMPONENT_REF:
    2253              :       /* Treat as unary, the other operands aren't evaluated.  */
    2254      1328629 :       x = TREE_OPERAND (x, 0);
    2255      1328629 :       writer = 0;
    2256      1328629 :       goto restart;
    2257              : 
    2258     50476439 :     default:
    2259     50476439 :     do_default:
    2260              :       /* For other expressions, simply recurse on their operands.
    2261              :          Manual tail recursion for unary expressions.
    2262              :          Other non-expressions need not be processed.  */
    2263     50476439 :       if (cl == tcc_unary)
    2264              :         {
    2265      8770744 :           x = TREE_OPERAND (x, 0);
    2266      8770744 :           writer = 0;
    2267      8770744 :           goto restart;
    2268              :         }
    2269     41705695 :       else if (IS_EXPR_CODE_CLASS (cl))
    2270              :         {
    2271     15174328 :           int lp;
    2272     15174328 :           int max = TREE_OPERAND_LENGTH (x);
    2273     51577376 :           for (lp = 0; lp < max; lp++)
    2274              :             {
    2275     21228720 :               tmp_before = tmp_nosp = 0;
    2276     21228720 :               verify_tree (TREE_OPERAND (x, lp), &tmp_before, &tmp_nosp, 0);
    2277     21228720 :               merge_tlist (&tmp_nosp, tmp_before, 0);
    2278     42457440 :               add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
    2279              :             }
    2280              :         }
    2281              :       return;
    2282              :     }
    2283              : }
    2284              : 
    2285              : static constexpr size_t verify_sequence_points_limit = 1024;
    2286              : 
    2287              : /* Called from verify_sequence_points via walk_tree.  */
    2288              : 
    2289              : static tree
    2290     90931303 : verify_tree_lim_r (tree *tp, int *walk_subtrees, void *data)
    2291              : {
    2292     90931303 :   if (++*((size_t *) data) > verify_sequence_points_limit)
    2293           57 :     return integer_zero_node;
    2294              : 
    2295     90931246 :   if (TYPE_P (*tp))
    2296         7460 :     *walk_subtrees = 0;
    2297              : 
    2298              :   return NULL_TREE;
    2299              : }
    2300              : 
    2301              : /* Try to warn for undefined behavior in EXPR due to missing sequence
    2302              :    points.  */
    2303              : 
    2304              : void
    2305      9232903 : verify_sequence_points (tree expr)
    2306              : {
    2307      9232903 :   tlist *before_sp = nullptr, *after_sp = nullptr;
    2308              : 
    2309              :   /* verify_tree is highly recursive, and merge_tlist is O(n^2),
    2310              :      so we return early if the expression is too big.  */
    2311      9232903 :   size_t n = 0;
    2312      9232903 :   if (walk_tree (&expr, verify_tree_lim_r, &n, nullptr))
    2313           57 :     return;
    2314              : 
    2315      9232846 :   warned_ids = nullptr;
    2316      9232846 :   save_expr_cache = nullptr;
    2317      9232846 :   if (!tlist_firstobj)
    2318              :     {
    2319        10044 :       gcc_obstack_init (&tlist_obstack);
    2320        10044 :       tlist_firstobj = (char *) obstack_alloc (&tlist_obstack, 0);
    2321              :     }
    2322              : 
    2323      9232846 :   verify_tree (expr, &before_sp, &after_sp, NULL_TREE);
    2324      9232846 :   warn_for_collisions (after_sp);
    2325      9232846 :   obstack_free (&tlist_obstack, tlist_firstobj);
    2326              : }
    2327              : 
    2328              : /* Validate the expression after `case' and apply default promotions.  */
    2329              : 
    2330              : static tree
    2331      2352048 : check_case_value (location_t loc, tree value)
    2332              : {
    2333      2352048 :   if (value == NULL_TREE)
    2334              :     return value;
    2335              : 
    2336      4269865 :   if (INTEGRAL_TYPE_P (TREE_TYPE (value))
    2337      4269762 :       && TREE_CODE (value) == INTEGER_CST)
    2338              :     /* Promote char or short to int.  */
    2339      2351897 :     value = perform_integral_promotions (value);
    2340          151 :   else if (value != error_mark_node)
    2341              :     {
    2342           53 :       error_at (loc, "case label does not reduce to an integer constant");
    2343           53 :       value = error_mark_node;
    2344              :     }
    2345              : 
    2346      2352048 :   constant_expression_warning (value);
    2347              : 
    2348      2352048 :   return value;
    2349              : }
    2350              : 
    2351              : /* Return an integer type with BITS bits of precision,
    2352              :    that is unsigned if UNSIGNEDP is nonzero, otherwise signed.  */
    2353              : 
    2354              : tree
    2355     31363278 : c_common_type_for_size (unsigned int bits, int unsignedp)
    2356              : {
    2357     31363278 :   int i;
    2358              : 
    2359     31363278 :   if (bits == TYPE_PRECISION (integer_type_node))
    2360     20622678 :     return unsignedp ? unsigned_type_node : integer_type_node;
    2361              : 
    2362     10740600 :   if (bits == TYPE_PRECISION (signed_char_type_node))
    2363      2778763 :     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
    2364              : 
    2365      7961837 :   if (bits == TYPE_PRECISION (short_integer_type_node))
    2366       479813 :     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
    2367              : 
    2368      7482024 :   if (bits == TYPE_PRECISION (long_integer_type_node))
    2369      6632704 :     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
    2370              : 
    2371       849320 :   if (bits == TYPE_PRECISION (long_long_integer_type_node))
    2372         9675 :     return (unsignedp ? long_long_unsigned_type_node
    2373         8910 :             : long_long_integer_type_node);
    2374              : 
    2375      1154437 :   for (i = 0; i < NUM_INT_N_ENTS; i ++)
    2376       839645 :     if (int_n_enabled_p[i]
    2377       832723 :         && bits == int_n_data[i].bitsize)
    2378       524853 :       return (unsignedp ? int_n_trees[i].unsigned_type
    2379       524853 :               : int_n_trees[i].signed_type);
    2380              : 
    2381       314792 :   if (bits == TYPE_PRECISION (widest_integer_literal_type_node))
    2382            0 :     return (unsignedp ? widest_unsigned_literal_type_node
    2383            0 :             : widest_integer_literal_type_node);
    2384              : 
    2385      1243052 :   for (tree t = registered_builtin_types; t; t = TREE_CHAIN (t))
    2386              :     {
    2387       928260 :       tree type = TREE_VALUE (t);
    2388       928260 :       if (TREE_CODE (type) == INTEGER_TYPE
    2389            0 :           && bits == TYPE_PRECISION (type)
    2390       928260 :           && !!unsignedp == !!TYPE_UNSIGNED (type))
    2391              :         return type;
    2392              :     }
    2393              : 
    2394       314792 :   if (bits <= TYPE_PRECISION (intQI_type_node))
    2395       251498 :     return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
    2396              : 
    2397        63294 :   if (bits <= TYPE_PRECISION (intHI_type_node))
    2398         9669 :     return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
    2399              : 
    2400        53625 :   if (bits <= TYPE_PRECISION (intSI_type_node))
    2401        19198 :     return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
    2402              : 
    2403        34427 :   if (bits <= TYPE_PRECISION (intDI_type_node))
    2404        28283 :     return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
    2405              : 
    2406         6144 :   if (bits <= TYPE_PRECISION (widest_integer_literal_type_node))
    2407           33 :     return (unsignedp ? widest_unsigned_literal_type_node
    2408           16 :             : widest_integer_literal_type_node);
    2409              : 
    2410              :   return NULL_TREE;
    2411              : }
    2412              : 
    2413              : /* Return a fixed-point type that has at least IBIT ibits and FBIT fbits
    2414              :    that is unsigned if UNSIGNEDP is nonzero, otherwise signed;
    2415              :    and saturating if SATP is nonzero, otherwise not saturating.  */
    2416              : 
    2417              : tree
    2418            0 : c_common_fixed_point_type_for_size (unsigned int ibit, unsigned int fbit,
    2419              :                                     int unsignedp, int satp)
    2420              : {
    2421            0 :   enum mode_class mclass;
    2422            0 :   if (ibit == 0)
    2423            0 :     mclass = unsignedp ? MODE_UFRACT : MODE_FRACT;
    2424              :   else
    2425            0 :     mclass = unsignedp ? MODE_UACCUM : MODE_ACCUM;
    2426              : 
    2427            0 :   opt_scalar_mode opt_mode;
    2428            0 :   scalar_mode mode;
    2429            0 :   FOR_EACH_MODE_IN_CLASS (opt_mode, mclass)
    2430              :     {
    2431            0 :       mode = opt_mode.require ();
    2432            0 :       if (GET_MODE_IBIT (mode) >= ibit && GET_MODE_FBIT (mode) >= fbit)
    2433              :         break;
    2434              :     }
    2435              : 
    2436            0 :   if (!opt_mode.exists (&mode) || !targetm.scalar_mode_supported_p (mode))
    2437              :     {
    2438            0 :       sorry ("GCC cannot support operators with integer types and "
    2439              :              "fixed-point types that have too many integral and "
    2440              :              "fractional bits together");
    2441            0 :       return NULL_TREE;
    2442              :     }
    2443              : 
    2444            0 :   return c_common_type_for_mode (mode, satp);
    2445              : }
    2446              : 
    2447              : /* Used for communication between c_common_type_for_mode and
    2448              :    c_register_builtin_type.  */
    2449              : tree registered_builtin_types;
    2450              : 
    2451              : /* Return a data type that has machine mode MODE.
    2452              :    If the mode is an integer,
    2453              :    then UNSIGNEDP selects between signed and unsigned types.
    2454              :    If the mode is a fixed-point mode,
    2455              :    then UNSIGNEDP selects between saturating and nonsaturating types.  */
    2456              : 
    2457              : tree
    2458     12918846 : c_common_type_for_mode (machine_mode mode, int unsignedp)
    2459              : {
    2460     12918846 :   tree t;
    2461     12918846 :   int i;
    2462              : 
    2463     12918846 :   if (mode == TYPE_MODE (integer_type_node))
    2464      1869775 :     return unsignedp ? unsigned_type_node : integer_type_node;
    2465              : 
    2466     11049071 :   if (mode == TYPE_MODE (signed_char_type_node))
    2467      1998268 :     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
    2468              : 
    2469      9050803 :   if (mode == TYPE_MODE (short_integer_type_node))
    2470       147277 :     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
    2471              : 
    2472      8903526 :   if (mode == TYPE_MODE (long_integer_type_node))
    2473      5420473 :     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
    2474              : 
    2475      3483053 :   if (mode == TYPE_MODE (long_long_integer_type_node))
    2476        84411 :     return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;
    2477              : 
    2478      5316113 :   for (i = 0; i < NUM_INT_N_ENTS; i ++)
    2479      3398642 :     if (int_n_enabled_p[i]
    2480      3398642 :         && mode == int_n_data[i].m)
    2481      1481171 :       return (unsignedp ? int_n_trees[i].unsigned_type
    2482      1481171 :               : int_n_trees[i].signed_type);
    2483              : 
    2484      1917471 :   if (mode == QImode)
    2485            0 :     return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
    2486              : 
    2487      1917471 :   if (mode == HImode)
    2488            0 :     return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
    2489              : 
    2490      1917471 :   if (mode == SImode)
    2491            0 :     return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
    2492              : 
    2493      1917471 :   if (mode == DImode)
    2494            0 :     return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
    2495              : 
    2496              : #if HOST_BITS_PER_WIDE_INT >= 64
    2497      1917471 :   if (mode == TYPE_MODE (intTI_type_node))
    2498            0 :     return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
    2499              : #endif
    2500              : 
    2501      1917471 :   if (mode == TYPE_MODE (float_type_node))
    2502        48608 :     return float_type_node;
    2503              : 
    2504      1868863 :   if (mode == TYPE_MODE (double_type_node))
    2505        43024 :     return double_type_node;
    2506              : 
    2507      1825839 :   if (mode == TYPE_MODE (long_double_type_node))
    2508        17539 :     return long_double_type_node;
    2509              : 
    2510     13412474 :   for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
    2511     11862833 :     if (FLOATN_NX_TYPE_NODE (i) != NULL_TREE
    2512     11862833 :         && mode == TYPE_MODE (FLOATN_NX_TYPE_NODE (i)))
    2513       258659 :       return FLOATN_NX_TYPE_NODE (i);
    2514              : 
    2515      1549641 :   if (mode == TYPE_MODE (void_type_node))
    2516            0 :     return void_type_node;
    2517              : 
    2518      1549641 :   if (mode == TYPE_MODE (build_pointer_type (char_type_node))
    2519      1549641 :       || mode == TYPE_MODE (build_pointer_type (integer_type_node)))
    2520              :     {
    2521            0 :       unsigned int precision
    2522            0 :         = GET_MODE_PRECISION (as_a <scalar_int_mode> (mode));
    2523            0 :       return (unsignedp
    2524            0 :               ? make_unsigned_type (precision)
    2525            0 :               : make_signed_type (precision));
    2526              :     }
    2527              : 
    2528      1549641 :   if (COMPLEX_MODE_P (mode))
    2529              :     {
    2530      1300856 :       machine_mode inner_mode;
    2531      1300856 :       tree inner_type;
    2532              : 
    2533      1300856 :       if (mode == TYPE_MODE (complex_float_type_node))
    2534       217563 :         return complex_float_type_node;
    2535      1083293 :       if (mode == TYPE_MODE (complex_double_type_node))
    2536       216622 :         return complex_double_type_node;
    2537       866671 :       if (mode == TYPE_MODE (complex_long_double_type_node))
    2538       216615 :         return complex_long_double_type_node;
    2539              : 
    2540      2815709 :       for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
    2541      2599360 :         if (COMPLEX_FLOATN_NX_TYPE_NODE (i) != NULL_TREE
    2542      2599360 :             && mode == TYPE_MODE (COMPLEX_FLOATN_NX_TYPE_NODE (i)))
    2543       433707 :           return COMPLEX_FLOATN_NX_TYPE_NODE (i);
    2544              : 
    2545       216349 :       if (mode == TYPE_MODE (complex_integer_type_node) && !unsignedp)
    2546           12 :         return complex_integer_type_node;
    2547              : 
    2548       216337 :       inner_mode = GET_MODE_INNER (mode);
    2549       216337 :       inner_type = c_common_type_for_mode (inner_mode, unsignedp);
    2550       216337 :       if (inner_type != NULL_TREE)
    2551       216337 :         return build_complex_type (inner_type);
    2552              :     }
    2553       248785 :   else if (GET_MODE_CLASS (mode) == MODE_VECTOR_BOOL
    2554       248785 :            && valid_vector_subparts_p (GET_MODE_NUNITS (mode)))
    2555              :     {
    2556            0 :       unsigned int elem_bits = vector_element_size (GET_MODE_PRECISION (mode),
    2557              :                                                     GET_MODE_NUNITS (mode));
    2558            0 :       tree bool_type = build_nonstandard_boolean_type (elem_bits);
    2559            0 :       return build_vector_type_for_mode (bool_type, mode);
    2560              :     }
    2561       232233 :   else if (VECTOR_MODE_P (mode)
    2562       268538 :            && valid_vector_subparts_p (GET_MODE_NUNITS (mode)))
    2563              :     {
    2564        19753 :       machine_mode inner_mode = GET_MODE_INNER (mode);
    2565        19753 :       tree inner_type = c_common_type_for_mode (inner_mode, unsignedp);
    2566        19753 :       if (inner_type != NULL_TREE)
    2567        19753 :         return build_vector_type_for_mode (inner_type, mode);
    2568              :     }
    2569              : 
    2570       229032 :   if (dfloat32_type_node != NULL_TREE
    2571       229032 :       && mode == TYPE_MODE (dfloat32_type_node))
    2572         2794 :     return dfloat32_type_node;
    2573       226238 :   if (dfloat64_type_node != NULL_TREE
    2574       226238 :       && mode == TYPE_MODE (dfloat64_type_node))
    2575         3199 :     return dfloat64_type_node;
    2576       223039 :   if (dfloat128_type_node != NULL_TREE
    2577       223039 :       && mode == TYPE_MODE (dfloat128_type_node))
    2578         2437 :     return dfloat128_type_node;
    2579              : 
    2580       220602 :   if (ALL_SCALAR_FIXED_POINT_MODE_P (mode))
    2581              :     {
    2582            0 :       if (mode == TYPE_MODE (short_fract_type_node))
    2583            0 :         return unsignedp ? sat_short_fract_type_node : short_fract_type_node;
    2584            0 :       if (mode == TYPE_MODE (fract_type_node))
    2585            0 :         return unsignedp ? sat_fract_type_node : fract_type_node;
    2586            0 :       if (mode == TYPE_MODE (long_fract_type_node))
    2587            0 :         return unsignedp ? sat_long_fract_type_node : long_fract_type_node;
    2588            0 :       if (mode == TYPE_MODE (long_long_fract_type_node))
    2589            0 :         return unsignedp ? sat_long_long_fract_type_node
    2590            0 :                          : long_long_fract_type_node;
    2591              : 
    2592            0 :       if (mode == TYPE_MODE (unsigned_short_fract_type_node))
    2593            0 :         return unsignedp ? sat_unsigned_short_fract_type_node
    2594            0 :                          : unsigned_short_fract_type_node;
    2595            0 :       if (mode == TYPE_MODE (unsigned_fract_type_node))
    2596            0 :         return unsignedp ? sat_unsigned_fract_type_node
    2597            0 :                          : unsigned_fract_type_node;
    2598            0 :       if (mode == TYPE_MODE (unsigned_long_fract_type_node))
    2599            0 :         return unsignedp ? sat_unsigned_long_fract_type_node
    2600            0 :                          : unsigned_long_fract_type_node;
    2601            0 :       if (mode == TYPE_MODE (unsigned_long_long_fract_type_node))
    2602            0 :         return unsignedp ? sat_unsigned_long_long_fract_type_node
    2603            0 :                          : unsigned_long_long_fract_type_node;
    2604              : 
    2605            0 :       if (mode == TYPE_MODE (short_accum_type_node))
    2606            0 :         return unsignedp ? sat_short_accum_type_node : short_accum_type_node;
    2607            0 :       if (mode == TYPE_MODE (accum_type_node))
    2608            0 :         return unsignedp ? sat_accum_type_node : accum_type_node;
    2609            0 :       if (mode == TYPE_MODE (long_accum_type_node))
    2610            0 :         return unsignedp ? sat_long_accum_type_node : long_accum_type_node;
    2611            0 :       if (mode == TYPE_MODE (long_long_accum_type_node))
    2612            0 :         return unsignedp ? sat_long_long_accum_type_node
    2613            0 :                          : long_long_accum_type_node;
    2614              : 
    2615            0 :       if (mode == TYPE_MODE (unsigned_short_accum_type_node))
    2616            0 :         return unsignedp ? sat_unsigned_short_accum_type_node
    2617            0 :                          : unsigned_short_accum_type_node;
    2618            0 :       if (mode == TYPE_MODE (unsigned_accum_type_node))
    2619            0 :         return unsignedp ? sat_unsigned_accum_type_node
    2620            0 :                          : unsigned_accum_type_node;
    2621            0 :       if (mode == TYPE_MODE (unsigned_long_accum_type_node))
    2622            0 :         return unsignedp ? sat_unsigned_long_accum_type_node
    2623            0 :                          : unsigned_long_accum_type_node;
    2624            0 :       if (mode == TYPE_MODE (unsigned_long_long_accum_type_node))
    2625            0 :         return unsignedp ? sat_unsigned_long_long_accum_type_node
    2626            0 :                          : unsigned_long_long_accum_type_node;
    2627              : 
    2628            0 :       if (mode == QQmode)
    2629            0 :         return unsignedp ? sat_qq_type_node : qq_type_node;
    2630              :       if (mode == HQmode)
    2631            0 :         return unsignedp ? sat_hq_type_node : hq_type_node;
    2632              :       if (mode == SQmode)
    2633            0 :         return unsignedp ? sat_sq_type_node : sq_type_node;
    2634              :       if (mode == DQmode)
    2635            0 :         return unsignedp ? sat_dq_type_node : dq_type_node;
    2636              :       if (mode == TQmode)
    2637            0 :         return unsignedp ? sat_tq_type_node : tq_type_node;
    2638              : 
    2639              :       if (mode == UQQmode)
    2640            0 :         return unsignedp ? sat_uqq_type_node : uqq_type_node;
    2641              :       if (mode == UHQmode)
    2642            0 :         return unsignedp ? sat_uhq_type_node : uhq_type_node;
    2643              :       if (mode == USQmode)
    2644            0 :         return unsignedp ? sat_usq_type_node : usq_type_node;
    2645              :       if (mode == UDQmode)
    2646            0 :         return unsignedp ? sat_udq_type_node : udq_type_node;
    2647              :       if (mode == UTQmode)
    2648            0 :         return unsignedp ? sat_utq_type_node : utq_type_node;
    2649              : 
    2650              :       if (mode == HAmode)
    2651            0 :         return unsignedp ? sat_ha_type_node : ha_type_node;
    2652              :       if (mode == SAmode)
    2653            0 :         return unsignedp ? sat_sa_type_node : sa_type_node;
    2654              :       if (mode == DAmode)
    2655            0 :         return unsignedp ? sat_da_type_node : da_type_node;
    2656              :       if (mode == TAmode)
    2657            0 :         return unsignedp ? sat_ta_type_node : ta_type_node;
    2658              : 
    2659              :       if (mode == UHAmode)
    2660            0 :         return unsignedp ? sat_uha_type_node : uha_type_node;
    2661              :       if (mode == USAmode)
    2662            0 :         return unsignedp ? sat_usa_type_node : usa_type_node;
    2663              :       if (mode == UDAmode)
    2664            0 :         return unsignedp ? sat_uda_type_node : uda_type_node;
    2665              :       if (mode == UTAmode)
    2666            0 :         return unsignedp ? sat_uta_type_node : uta_type_node;
    2667              :     }
    2668              : 
    2669       222821 :   for (t = registered_builtin_types; t; t = TREE_CHAIN (t))
    2670              :     {
    2671       222096 :       tree type = TREE_VALUE (t);
    2672       222096 :       if (TYPE_MODE (type) == mode
    2673       219980 :           && VECTOR_TYPE_P (type) == VECTOR_MODE_P (mode)
    2674       442076 :           && !!unsignedp == !!TYPE_UNSIGNED (type))
    2675              :         return type;
    2676              :     }
    2677              :   return NULL_TREE;
    2678              : }
    2679              : 
    2680              : tree
    2681      1743087 : c_common_unsigned_type (tree type)
    2682              : {
    2683      1743087 :   return c_common_signed_or_unsigned_type (1, type);
    2684              : }
    2685              : 
    2686              : /* Return a signed type the same as TYPE in other respects.  */
    2687              : 
    2688              : tree
    2689      5572622 : c_common_signed_type (tree type)
    2690              : {
    2691      5572622 :   return c_common_signed_or_unsigned_type (0, type);
    2692              : }
    2693              : 
    2694              : /* Return a type the same as TYPE except unsigned or
    2695              :    signed according to UNSIGNEDP.  */
    2696              : 
    2697              : tree
    2698     11486760 : c_common_signed_or_unsigned_type (int unsignedp, tree type)
    2699              : {
    2700     11486760 :   tree type1;
    2701     11486760 :   int i;
    2702              : 
    2703              :   /* This block of code emulates the behavior of the old
    2704              :      c_common_unsigned_type. In particular, it returns
    2705              :      long_unsigned_type_node if passed a long, even when a int would
    2706              :      have the same size. This is necessary for warnings to work
    2707              :      correctly in archs where sizeof(int) == sizeof(long) */
    2708              : 
    2709     11486760 :   type1 = TYPE_MAIN_VARIANT (type);
    2710     11486760 :   if (type1 == signed_char_type_node || type1 == char_type_node || type1 == unsigned_char_type_node)
    2711      3077288 :     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
    2712      8409472 :   if (type1 == integer_type_node || type1 == unsigned_type_node)
    2713      2623833 :     return unsignedp ? unsigned_type_node : integer_type_node;
    2714      5785639 :   if (type1 == short_integer_type_node || type1 == short_unsigned_type_node)
    2715      1723742 :     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
    2716      4061897 :   if (type1 == long_integer_type_node || type1 == long_unsigned_type_node)
    2717      1135966 :     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
    2718      2925931 :   if (type1 == long_long_integer_type_node || type1 == long_long_unsigned_type_node)
    2719       529142 :     return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;
    2720              : 
    2721      4717937 :   for (i = 0; i < NUM_INT_N_ENTS; i ++)
    2722      2396789 :     if (int_n_enabled_p[i]
    2723      2214859 :         && (type1 == int_n_trees[i].unsigned_type
    2724      2177233 :             || type1 == int_n_trees[i].signed_type))
    2725        75641 :       return (unsignedp ? int_n_trees[i].unsigned_type
    2726        75641 :               : int_n_trees[i].signed_type);
    2727              : 
    2728              : #if HOST_BITS_PER_WIDE_INT >= 64
    2729      2321148 :   if (type1 == intTI_type_node || type1 == unsigned_intTI_type_node)
    2730            0 :     return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
    2731              : #endif
    2732      2321148 :   if (type1 == intDI_type_node || type1 == unsigned_intDI_type_node)
    2733            0 :     return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
    2734      2321148 :   if (type1 == intSI_type_node || type1 == unsigned_intSI_type_node)
    2735            0 :     return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
    2736      2321148 :   if (type1 == intHI_type_node || type1 == unsigned_intHI_type_node)
    2737            0 :     return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
    2738      2321148 :   if (type1 == intQI_type_node || type1 == unsigned_intQI_type_node)
    2739            0 :     return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
    2740              : 
    2741              : #define C_COMMON_FIXED_TYPES(NAME)          \
    2742              :   if (type1 == short_ ## NAME ## _type_node \
    2743              :       || type1 == unsigned_short_ ## NAME ## _type_node) \
    2744              :     return unsignedp ? unsigned_short_ ## NAME ## _type_node \
    2745              :                      : short_ ## NAME ## _type_node; \
    2746              :   if (type1 == NAME ## _type_node \
    2747              :       || type1 == unsigned_ ## NAME ## _type_node) \
    2748              :     return unsignedp ? unsigned_ ## NAME ## _type_node \
    2749              :                      : NAME ## _type_node; \
    2750              :   if (type1 == long_ ## NAME ## _type_node \
    2751              :       || type1 == unsigned_long_ ## NAME ## _type_node) \
    2752              :     return unsignedp ? unsigned_long_ ## NAME ## _type_node \
    2753              :                      : long_ ## NAME ## _type_node; \
    2754              :   if (type1 == long_long_ ## NAME ## _type_node \
    2755              :       || type1 == unsigned_long_long_ ## NAME ## _type_node) \
    2756              :     return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
    2757              :                      : long_long_ ## NAME ## _type_node;
    2758              : 
    2759              : #define C_COMMON_FIXED_MODE_TYPES(NAME) \
    2760              :   if (type1 == NAME ## _type_node \
    2761              :       || type1 == u ## NAME ## _type_node) \
    2762              :     return unsignedp ? u ## NAME ## _type_node \
    2763              :                      : NAME ## _type_node;
    2764              : 
    2765              : #define C_COMMON_FIXED_TYPES_SAT(NAME) \
    2766              :   if (type1 == sat_ ## short_ ## NAME ## _type_node \
    2767              :       || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
    2768              :     return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
    2769              :                      : sat_ ## short_ ## NAME ## _type_node; \
    2770              :   if (type1 == sat_ ## NAME ## _type_node \
    2771              :       || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
    2772              :     return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
    2773              :                      : sat_ ## NAME ## _type_node; \
    2774              :   if (type1 == sat_ ## long_ ## NAME ## _type_node \
    2775              :       || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
    2776              :     return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
    2777              :                      : sat_ ## long_ ## NAME ## _type_node; \
    2778              :   if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
    2779              :       || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
    2780              :     return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
    2781              :                      : sat_ ## long_long_ ## NAME ## _type_node;
    2782              : 
    2783              : #define C_COMMON_FIXED_MODE_TYPES_SAT(NAME)     \
    2784              :   if (type1 == sat_ ## NAME ## _type_node \
    2785              :       || type1 == sat_ ## u ## NAME ## _type_node) \
    2786              :     return unsignedp ? sat_ ## u ## NAME ## _type_node \
    2787              :                      : sat_ ## NAME ## _type_node;
    2788              : 
    2789      2321148 :   C_COMMON_FIXED_TYPES (fract);
    2790      2321148 :   C_COMMON_FIXED_TYPES_SAT (fract);
    2791      2321148 :   C_COMMON_FIXED_TYPES (accum);
    2792      2321148 :   C_COMMON_FIXED_TYPES_SAT (accum);
    2793              : 
    2794      2321148 :   C_COMMON_FIXED_MODE_TYPES (qq);
    2795      2321148 :   C_COMMON_FIXED_MODE_TYPES (hq);
    2796      2321148 :   C_COMMON_FIXED_MODE_TYPES (sq);
    2797      2321148 :   C_COMMON_FIXED_MODE_TYPES (dq);
    2798      2321148 :   C_COMMON_FIXED_MODE_TYPES (tq);
    2799      2321148 :   C_COMMON_FIXED_MODE_TYPES_SAT (qq);
    2800      2321148 :   C_COMMON_FIXED_MODE_TYPES_SAT (hq);
    2801      2321148 :   C_COMMON_FIXED_MODE_TYPES_SAT (sq);
    2802      2321148 :   C_COMMON_FIXED_MODE_TYPES_SAT (dq);
    2803      2321148 :   C_COMMON_FIXED_MODE_TYPES_SAT (tq);
    2804      2321148 :   C_COMMON_FIXED_MODE_TYPES (ha);
    2805      2321148 :   C_COMMON_FIXED_MODE_TYPES (sa);
    2806      2321148 :   C_COMMON_FIXED_MODE_TYPES (da);
    2807      2321148 :   C_COMMON_FIXED_MODE_TYPES (ta);
    2808      2321148 :   C_COMMON_FIXED_MODE_TYPES_SAT (ha);
    2809      2321148 :   C_COMMON_FIXED_MODE_TYPES_SAT (sa);
    2810      2321148 :   C_COMMON_FIXED_MODE_TYPES_SAT (da);
    2811      2321148 :   C_COMMON_FIXED_MODE_TYPES_SAT (ta);
    2812              : 
    2813              :   /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
    2814              :      the precision; they have precision set to match their range, but
    2815              :      may use a wider mode to match an ABI.  If we change modes, we may
    2816              :      wind up with bad conversions.  For INTEGER_TYPEs in C, must check
    2817              :      the precision as well, so as to yield correct results for
    2818              :      bit-field types.  C++ does not have these separate bit-field
    2819              :      types, and producing a signed or unsigned variant of an
    2820              :      ENUMERAL_TYPE may cause other problems as well.  */
    2821              : 
    2822      2321148 :   if (!INTEGRAL_TYPE_P (type)
    2823      2321148 :       || TYPE_UNSIGNED (type) == unsignedp)
    2824              :     return type;
    2825              : 
    2826      1197334 :   if (BITINT_TYPE_P (type)
    2827              :       /* signed _BitInt(1) is invalid before C2Y, avoid creating that.  */
    2828      1199573 :       && (unsignedp || flag_isoc2y || TYPE_PRECISION (type) > 1))
    2829         2239 :     return build_bitint_type (TYPE_PRECISION (type), unsignedp);
    2830              : 
    2831              : #define TYPE_OK(node)                                                       \
    2832              :   (TYPE_MODE (type) == TYPE_MODE (node)                                     \
    2833              :    && TYPE_PRECISION (type) == TYPE_PRECISION (node))
    2834      1197334 :   if (TYPE_OK (signed_char_type_node))
    2835        15606 :     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
    2836      1181728 :   if (TYPE_OK (integer_type_node))
    2837       185269 :     return unsignedp ? unsigned_type_node : integer_type_node;
    2838       996459 :   if (TYPE_OK (short_integer_type_node))
    2839        13701 :     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
    2840       982758 :   if (TYPE_OK (long_integer_type_node))
    2841       975221 :     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
    2842         7537 :   if (TYPE_OK (long_long_integer_type_node))
    2843           43 :     return (unsignedp ? long_long_unsigned_type_node
    2844            4 :             : long_long_integer_type_node);
    2845              : 
    2846        14732 :   for (i = 0; i < NUM_INT_N_ENTS; i ++)
    2847         7494 :     if (int_n_enabled_p[i]
    2848         6998 :         && TYPE_MODE (type) == int_n_data[i].m
    2849         7782 :         && TYPE_PRECISION (type) == int_n_data[i].bitsize)
    2850          256 :       return (unsignedp ? int_n_trees[i].unsigned_type
    2851          256 :               : int_n_trees[i].signed_type);
    2852              : 
    2853              : #if HOST_BITS_PER_WIDE_INT >= 64
    2854         7238 :   if (TYPE_OK (intTI_type_node))
    2855            0 :     return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
    2856              : #endif
    2857         7238 :   if (TYPE_OK (intDI_type_node))
    2858            0 :     return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
    2859         7238 :   if (TYPE_OK (intSI_type_node))
    2860            0 :     return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
    2861         7238 :   if (TYPE_OK (intHI_type_node))
    2862            0 :     return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
    2863         7238 :   if (TYPE_OK (intQI_type_node))
    2864            0 :     return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
    2865              : #undef TYPE_OK
    2866              : 
    2867         7238 :   return build_nonstandard_integer_type (TYPE_PRECISION (type), unsignedp);
    2868              : }
    2869              : 
    2870              : /* Build a bit-field integer type for the given WIDTH and UNSIGNEDP.  */
    2871              : 
    2872              : tree
    2873       540178 : c_build_bitfield_integer_type (unsigned HOST_WIDE_INT width, int unsignedp)
    2874              : {
    2875       540178 :   int i;
    2876              : 
    2877              :   /* Extended integer types of the same width as a standard type have
    2878              :      lesser rank, so those of the same width as int promote to int or
    2879              :      unsigned int and are valid for printf formats expecting int or
    2880              :      unsigned int.  To avoid such special cases, avoid creating
    2881              :      extended integer types for bit-fields if a standard integer type
    2882              :      is available.  */
    2883       540178 :   if (width == TYPE_PRECISION (integer_type_node))
    2884          138 :     return unsignedp ? unsigned_type_node : integer_type_node;
    2885       540040 :   if (width == TYPE_PRECISION (signed_char_type_node))
    2886        20267 :     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
    2887       519773 :   if (width == TYPE_PRECISION (short_integer_type_node))
    2888         1428 :     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
    2889       518345 :   if (width == TYPE_PRECISION (long_integer_type_node))
    2890            0 :     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
    2891       518345 :   if (width == TYPE_PRECISION (long_long_integer_type_node))
    2892            0 :     return (unsignedp ? long_long_unsigned_type_node
    2893            0 :             : long_long_integer_type_node);
    2894      1036690 :   for (i = 0; i < NUM_INT_N_ENTS; i ++)
    2895       518345 :     if (int_n_enabled_p[i]
    2896       511062 :         && width == int_n_data[i].bitsize)
    2897            0 :       return (unsignedp ? int_n_trees[i].unsigned_type
    2898            0 :               : int_n_trees[i].signed_type);
    2899       518345 :   return build_nonstandard_integer_type (width, unsignedp);
    2900              : }
    2901              : 
    2902              : /* The C version of the register_builtin_type langhook.  */
    2903              : 
    2904              : void
    2905       648921 : c_register_builtin_type (tree type, const char* name)
    2906              : {
    2907       648921 :   tree decl;
    2908              : 
    2909       648921 :   decl = build_decl (UNKNOWN_LOCATION,
    2910              :                      TYPE_DECL, get_identifier (name), type);
    2911       648921 :   DECL_ARTIFICIAL (decl) = 1;
    2912       648921 :   if (!TYPE_NAME (type))
    2913       316008 :     TYPE_NAME (type) = decl;
    2914       648921 :   lang_hooks.decls.pushdecl (decl);
    2915              : 
    2916       648921 :   registered_builtin_types = tree_cons (0, type, registered_builtin_types);
    2917       648921 : }
    2918              : 
    2919              : /* Print an error message for invalid operands to arith operation
    2920              :    CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
    2921              :    RICHLOC is a rich location for the message, containing either
    2922              :    three separate locations for each of the operator and operands
    2923              : 
    2924              :       lhs op rhs
    2925              :       ~~~ ^~ ~~~
    2926              : 
    2927              :    (C FE), or one location ranging over all over them
    2928              : 
    2929              :       lhs op rhs
    2930              :       ~~~~^~~~~~
    2931              : 
    2932              :    (C++ FE).  */
    2933              : 
    2934              : void
    2935          564 : binary_op_error (rich_location *richloc, enum tree_code code,
    2936              :                  tree type0, tree type1)
    2937              : {
    2938          564 :   const char *opname;
    2939              : 
    2940          564 :   switch (code)
    2941              :     {
    2942              :     case PLUS_EXPR:
    2943              :       opname = "+"; break;
    2944           14 :     case MINUS_EXPR:
    2945           14 :       opname = "-"; break;
    2946          378 :     case MULT_EXPR:
    2947          378 :       opname = "*"; break;
    2948            0 :     case MAX_EXPR:
    2949            0 :       opname = "max"; break;
    2950            0 :     case MIN_EXPR:
    2951            0 :       opname = "min"; break;
    2952            2 :     case EQ_EXPR:
    2953            2 :       opname = "=="; break;
    2954            2 :     case NE_EXPR:
    2955            2 :       opname = "!="; break;
    2956            0 :     case LE_EXPR:
    2957            0 :       opname = "<="; break;
    2958            0 :     case GE_EXPR:
    2959            0 :       opname = ">="; break;
    2960            1 :     case LT_EXPR:
    2961            1 :       opname = "<"; break;
    2962            1 :     case GT_EXPR:
    2963            1 :       opname = ">"; break;
    2964           21 :     case LSHIFT_EXPR:
    2965           21 :       opname = "<<"; break;
    2966           16 :     case RSHIFT_EXPR:
    2967           16 :       opname = ">>"; break;
    2968            3 :     case TRUNC_MOD_EXPR:
    2969            3 :     case FLOOR_MOD_EXPR:
    2970            3 :       opname = "%"; break;
    2971            6 :     case TRUNC_DIV_EXPR:
    2972            6 :     case FLOOR_DIV_EXPR:
    2973            6 :       opname = "/"; break;
    2974           40 :     case BIT_AND_EXPR:
    2975           40 :       opname = "&"; break;
    2976           21 :     case BIT_IOR_EXPR:
    2977           21 :       opname = "|"; break;
    2978            0 :     case TRUTH_ANDIF_EXPR:
    2979            0 :       opname = "&&"; break;
    2980            0 :     case TRUTH_ORIF_EXPR:
    2981            0 :       opname = "||"; break;
    2982           22 :     case BIT_XOR_EXPR:
    2983           22 :       opname = "^"; break;
    2984            0 :     default:
    2985            0 :       gcc_unreachable ();
    2986              :     }
    2987          564 :   pp_markup::element_quoted_type element_0 (type0, highlight_colors::lhs);
    2988         1128 :   pp_markup::element_quoted_type element_1 (type1, highlight_colors::rhs);
    2989          564 :   error_at (richloc,
    2990              :             "invalid operands to binary %s (have %e and %e)",
    2991              :             opname, &element_0, &element_1);
    2992          564 : }
    2993              : 
    2994              : /* Given an expression as a tree, return its original type.  Do this
    2995              :    by stripping any conversion that preserves the sign and precision.  */
    2996              : static tree
    2997        57073 : expr_original_type (tree expr)
    2998              : {
    2999        57073 :   STRIP_SIGN_NOPS (expr);
    3000        57073 :   return TREE_TYPE (expr);
    3001              : }
    3002              : 
    3003              : /* Subroutine of build_binary_op, used for comparison operations.
    3004              :    See if the operands have both been converted from subword integer types
    3005              :    and, if so, perhaps change them both back to their original type.
    3006              :    This function is also responsible for converting the two operands
    3007              :    to the proper common type for comparison.
    3008              : 
    3009              :    The arguments of this function are all pointers to local variables
    3010              :    of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
    3011              :    RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
    3012              : 
    3013              :    LOC is the location of the comparison.
    3014              : 
    3015              :    If this function returns non-NULL_TREE, it means that the comparison has
    3016              :    a constant value.  What this function returns is an expression for
    3017              :    that value.  */
    3018              : 
    3019              : tree
    3020     31190440 : shorten_compare (location_t loc, tree *op0_ptr, tree *op1_ptr,
    3021              :                  tree *restype_ptr, enum tree_code *rescode_ptr)
    3022              : {
    3023     31190440 :   tree type;
    3024     31190440 :   tree op0 = *op0_ptr;
    3025     31190440 :   tree op1 = *op1_ptr;
    3026     31190440 :   int unsignedp0, unsignedp1;
    3027     31190440 :   int real1, real2;
    3028     31190440 :   tree primop0, primop1;
    3029     31190440 :   enum tree_code code = *rescode_ptr;
    3030              : 
    3031              :   /* Throw away any conversions to wider types
    3032              :      already present in the operands.  */
    3033              : 
    3034     31190440 :   primop0 = c_common_get_narrower (op0, &unsignedp0);
    3035     31190440 :   primop1 = c_common_get_narrower (op1, &unsignedp1);
    3036              : 
    3037              :   /* If primopN is first sign-extended from primopN's precision to opN's
    3038              :      precision, then zero-extended from opN's precision to
    3039              :      *restype_ptr precision, shortenings might be invalid.  */
    3040     31190440 :   if (TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (TREE_TYPE (op0))
    3041      1735979 :       && TYPE_PRECISION (TREE_TYPE (op0)) < TYPE_PRECISION (*restype_ptr)
    3042         2580 :       && !unsignedp0
    3043     31192738 :       && TYPE_UNSIGNED (TREE_TYPE (op0)))
    3044              :     primop0 = op0;
    3045     31190440 :   if (TYPE_PRECISION (TREE_TYPE (primop1)) < TYPE_PRECISION (TREE_TYPE (op1))
    3046      1039356 :       && TYPE_PRECISION (TREE_TYPE (op1)) < TYPE_PRECISION (*restype_ptr)
    3047         8168 :       && !unsignedp1
    3048     31195577 :       && TYPE_UNSIGNED (TREE_TYPE (op1)))
    3049              :     primop1 = op1;
    3050              : 
    3051              :   /* Handle the case that OP0 does not *contain* a conversion
    3052              :      but it *requires* conversion to FINAL_TYPE.  */
    3053              : 
    3054     31190440 :   if (op0 == primop0 && TREE_TYPE (op0) != *restype_ptr)
    3055       460193 :     unsignedp0 = TYPE_UNSIGNED (TREE_TYPE (op0));
    3056     31190440 :   if (op1 == primop1 && TREE_TYPE (op1) != *restype_ptr)
    3057      9041120 :     unsignedp1 = TYPE_UNSIGNED (TREE_TYPE (op1));
    3058              : 
    3059              :   /* If one of the operands must be floated, we cannot optimize.  */
    3060     31190440 :   real1 = SCALAR_FLOAT_TYPE_P (TREE_TYPE (primop0));
    3061     31190440 :   real2 = SCALAR_FLOAT_TYPE_P (TREE_TYPE (primop1));
    3062              : 
    3063              :   /* If first arg is constant, swap the args (changing operation
    3064              :      so value is preserved), for canonicalization.  Don't do this if
    3065              :      the second arg is 0.  */
    3066              : 
    3067     31190440 :   if (TREE_CONSTANT (primop0)
    3068      8015193 :       && !integer_zerop (primop1) && !real_zerop (primop1)
    3069     37180330 :       && !fixed_zerop (primop1))
    3070              :     {
    3071      5989890 :       std::swap (primop0, primop1);
    3072      5989890 :       std::swap (op0, op1);
    3073      5989890 :       *op0_ptr = op0;
    3074      5989890 :       *op1_ptr = op1;
    3075      5989890 :       std::swap (unsignedp0, unsignedp1);
    3076      5989890 :       std::swap (real1, real2);
    3077              : 
    3078      5989890 :       switch (code)
    3079              :         {
    3080              :         case LT_EXPR:
    3081              :           code = GT_EXPR;
    3082              :           break;
    3083              :         case GT_EXPR:
    3084              :           code = LT_EXPR;
    3085              :           break;
    3086              :         case LE_EXPR:
    3087              :           code = GE_EXPR;
    3088              :           break;
    3089              :         case GE_EXPR:
    3090              :           code = LE_EXPR;
    3091              :           break;
    3092              :         default:
    3093              :           break;
    3094              :         }
    3095      5989890 :       *rescode_ptr = code;
    3096              :     }
    3097              : 
    3098              :   /* If comparing an integer against a constant more bits wide,
    3099              :      maybe we can deduce a value of 1 or 0 independent of the data.
    3100              :      Or else truncate the constant now
    3101              :      rather than extend the variable at run time.
    3102              : 
    3103              :      This is only interesting if the constant is the wider arg.
    3104              :      Also, it is not safe if the constant is unsigned and the
    3105              :      variable arg is signed, since in this case the variable
    3106              :      would be sign-extended and then regarded as unsigned.
    3107              :      Our technique fails in this case because the lowest/highest
    3108              :      possible unsigned results don't follow naturally from the
    3109              :      lowest/highest possible values of the variable operand.
    3110              :      For just EQ_EXPR and NE_EXPR there is another technique that
    3111              :      could be used: see if the constant can be faithfully represented
    3112              :      in the other operand's type, by truncating it and reextending it
    3113              :      and see if that preserves the constant's value.  */
    3114              : 
    3115     26751091 :   if (!real1 && !real2
    3116     26727896 :       && TREE_CODE (TREE_TYPE (primop0)) != FIXED_POINT_TYPE
    3117     26727896 :       && TREE_CODE (primop1) == INTEGER_CST
    3118     48982478 :       && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr))
    3119              :     {
    3120      2636826 :       int min_gt, max_gt, min_lt, max_lt;
    3121      2636826 :       tree maxval, minval;
    3122              :       /* 1 if comparison is nominally unsigned.  */
    3123      2636826 :       int unsignedp = TYPE_UNSIGNED (*restype_ptr);
    3124      2636826 :       tree val;
    3125              : 
    3126      2636826 :       type = c_common_signed_or_unsigned_type (unsignedp0,
    3127      2636826 :                                                TREE_TYPE (primop0));
    3128              : 
    3129      2636826 :       maxval = TYPE_MAX_VALUE (type);
    3130      2636826 :       minval = TYPE_MIN_VALUE (type);
    3131              : 
    3132      2636826 :       if (unsignedp && !unsignedp0)
    3133       574957 :         *restype_ptr = c_common_signed_type (*restype_ptr);
    3134              : 
    3135      2636826 :       if (TREE_TYPE (primop1) != *restype_ptr)
    3136              :         {
    3137              :           /* Convert primop1 to target type, but do not introduce
    3138              :              additional overflow.  We know primop1 is an int_cst.  */
    3139       584253 :           primop1 = force_fit_type (*restype_ptr,
    3140              :                                     wi::to_wide
    3141      1168506 :                                      (primop1,
    3142       584253 :                                       TYPE_PRECISION (*restype_ptr)),
    3143       584253 :                                     0, TREE_OVERFLOW (primop1));
    3144              :         }
    3145      2636826 :       if (type != *restype_ptr)
    3146              :         {
    3147      2636826 :           minval = convert (*restype_ptr, minval);
    3148      2636826 :           maxval = convert (*restype_ptr, maxval);
    3149              :         }
    3150              : 
    3151      2636826 :       min_gt = tree_int_cst_lt (primop1, minval);
    3152      2636826 :       max_gt = tree_int_cst_lt (primop1, maxval);
    3153      2636826 :       min_lt = tree_int_cst_lt (minval, primop1);
    3154      2636826 :       max_lt = tree_int_cst_lt (maxval, primop1);
    3155              : 
    3156      2636826 :       val = 0;
    3157              :       /* This used to be a switch, but Genix compiler can't handle that.  */
    3158      2636826 :       if (code == NE_EXPR)
    3159              :         {
    3160       327491 :           if (max_lt || min_gt)
    3161           23 :             val = truthvalue_true_node;
    3162              :         }
    3163              :       else if (code == EQ_EXPR)
    3164              :         {
    3165      1353639 :           if (max_lt || min_gt)
    3166           28 :             val = truthvalue_false_node;
    3167              :         }
    3168              :       else if (code == LT_EXPR)
    3169              :         {
    3170       447629 :           if (max_lt)
    3171           54 :             val = truthvalue_true_node;
    3172       447629 :           if (!min_lt)
    3173         2841 :             val = truthvalue_false_node;
    3174              :         }
    3175              :       else if (code == GT_EXPR)
    3176              :         {
    3177       158652 :           if (min_gt)
    3178            8 :             val = truthvalue_true_node;
    3179       158652 :           if (!max_gt)
    3180            5 :             val = truthvalue_false_node;
    3181              :         }
    3182              :       else if (code == LE_EXPR)
    3183              :         {
    3184       128042 :           if (!max_gt)
    3185           77 :             val = truthvalue_true_node;
    3186       128042 :           if (min_gt)
    3187            7 :             val = truthvalue_false_node;
    3188              :         }
    3189              :       else if (code == GE_EXPR)
    3190              :         {
    3191       221369 :           if (!min_lt)
    3192          208 :             val = truthvalue_true_node;
    3193       221369 :           if (max_lt)
    3194        14964 :             val = truthvalue_false_node;
    3195              :         }
    3196              : 
    3197              :       /* If primop0 was sign-extended and unsigned comparison specd,
    3198              :          we did a signed comparison above using the signed type bounds.
    3199              :          But the comparison we output must be unsigned.
    3200              : 
    3201              :          Also, for inequalities, VAL is no good; but if the signed
    3202              :          comparison had *any* fixed result, it follows that the
    3203              :          unsigned comparison just tests the sign in reverse
    3204              :          (positive values are LE, negative ones GE).
    3205              :          So we can generate an unsigned comparison
    3206              :          against an extreme value of the signed type.  */
    3207              : 
    3208      2636826 :       if (unsignedp && !unsignedp0)
    3209              :         {
    3210       574957 :           if (val != 0)
    3211          111 :             switch (code)
    3212              :               {
    3213           81 :               case LT_EXPR:
    3214           81 :               case GE_EXPR:
    3215           81 :                 primop1 = TYPE_MIN_VALUE (type);
    3216           81 :                 val = 0;
    3217           81 :                 break;
    3218              : 
    3219           29 :               case LE_EXPR:
    3220           29 :               case GT_EXPR:
    3221           29 :                 primop1 = TYPE_MAX_VALUE (type);
    3222           29 :                 val = 0;
    3223           29 :                 break;
    3224              : 
    3225              :               default:
    3226              :                 break;
    3227              :               }
    3228       574957 :           type = c_common_unsigned_type (type);
    3229              :         }
    3230              : 
    3231      2636826 :       if (TREE_CODE (primop0) != INTEGER_CST
    3232              :           /* Don't warn if it's from a (non-system) macro.  */
    3233      2636826 :           && !(from_macro_expansion_at
    3234      1539885 :                (expansion_point_location_if_in_system_header
    3235      1539885 :                 (EXPR_LOCATION (primop0)))))
    3236              :         {
    3237      1497637 :           if (val == truthvalue_false_node)
    3238         2875 :             warning_at (loc, OPT_Wtype_limits,
    3239              :                         "comparison is always false due to limited range of data type");
    3240      1497637 :           if (val == truthvalue_true_node)
    3241          255 :             warning_at (loc, OPT_Wtype_limits,
    3242              :                         "comparison is always true due to limited range of data type");
    3243              :         }
    3244              : 
    3245      2636826 :       if (val != 0)
    3246              :         {
    3247              :           /* Don't forget to evaluate PRIMOP0 if it has side effects.  */
    3248        18105 :           if (TREE_SIDE_EFFECTS (primop0))
    3249           11 :             return build2 (COMPOUND_EXPR, TREE_TYPE (val), primop0, val);
    3250              :           return val;
    3251              :         }
    3252              : 
    3253              :       /* Value is not predetermined, but do the comparison
    3254              :          in the type of the operand that is not constant.
    3255              :          TYPE is already properly set.  */
    3256              :     }
    3257              : 
    3258              :   /* If either arg is decimal float and the other is float, find the
    3259              :      proper common type to use for comparison.  */
    3260      4439349 :   else if (real1 && real2
    3261      4110788 :            && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0)))
    3262     28570162 :            && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1))))
    3263        16547 :     type = common_type (TREE_TYPE (primop0), TREE_TYPE (primop1));
    3264              : 
    3265              :   /* If either arg is decimal float and the other is float, fail.  */
    3266      4422802 :   else if (real1 && real2
    3267     32631308 :            && (DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0)))
    3268      4094240 :                || DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1)))))
    3269              :     {
    3270            2 :       type = *restype_ptr;
    3271            2 :       primop0 = op0;
    3272            2 :       primop1 = op1;
    3273              :     }
    3274              : 
    3275      4422800 :   else if (real1 && real2
    3276     32631304 :            && (TYPE_PRECISION (TREE_TYPE (primop0))
    3277      4094239 :                == TYPE_PRECISION (TREE_TYPE (primop1))))
    3278      3996495 :     type = TREE_TYPE (primop0);
    3279              : 
    3280              :   /* If args' natural types are both narrower than nominal type
    3281              :      and both extend in the same manner, compare them
    3282              :      in the type of the wider arg.
    3283              :      Otherwise must actually extend both to the nominal
    3284              :      common type lest different ways of extending
    3285              :      alter the result.
    3286              :      (eg, (short)-1 == (unsigned short)-1  should be 0.)  */
    3287              : 
    3288     21708772 :   else if (unsignedp0 == unsignedp1 && real1 == real2
    3289     21369378 :            && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr)
    3290       598741 :            && TYPE_PRECISION (TREE_TYPE (primop1)) < TYPE_PRECISION (*restype_ptr)
    3291     24929890 :            && (type = common_type (TREE_TYPE (primop0), TREE_TYPE (primop1)))
    3292       389320 :               != error_mark_node)
    3293              :     {
    3294       389320 :       type = c_common_signed_or_unsigned_type (unsignedp0
    3295       389320 :                                                || TYPE_UNSIGNED (*restype_ptr),
    3296              :                                                type);
    3297              :       /* Make sure shorter operand is extended the right way
    3298              :          to match the longer operand.  */
    3299       389320 :       primop0
    3300       389320 :         = convert (c_common_signed_or_unsigned_type (unsignedp0,
    3301       389320 :                                                      TREE_TYPE (primop0)),
    3302              :                    primop0);
    3303       389320 :       primop1
    3304       389320 :         = convert (c_common_signed_or_unsigned_type (unsignedp1,
    3305       389320 :                                                      TREE_TYPE (primop1)),
    3306              :                    primop1);
    3307              :     }
    3308              :   else
    3309              :     {
    3310              :       /* Here we must do the comparison on the nominal type
    3311              :          using the args exactly as we received them.  */
    3312     24151250 :       type = *restype_ptr;
    3313     24151250 :       primop0 = op0;
    3314     24151250 :       primop1 = op1;
    3315              : 
    3316              :       /* We want to fold unsigned comparisons of >= and < against zero.
    3317              :          For these, we may also issue a warning if we have a non-constant
    3318              :          compared against zero, where the zero was spelled as "0" (rather
    3319              :          than merely folding to it).
    3320              :          If we have at least one constant, then op1 is constant
    3321              :          and we may have a non-constant expression as op0.  */
    3322     23724945 :       if (!real1 && !real2 && integer_zerop (primop1)
    3323     33994331 :           && TYPE_UNSIGNED (*restype_ptr))
    3324              :         {
    3325      3423398 :           tree value = NULL_TREE;
    3326              :           /* All unsigned values are >= 0, so we warn.  However,
    3327              :              if OP0 is a constant that is >= 0, the signedness of
    3328              :              the comparison isn't an issue, so suppress the
    3329              :              warning.  */
    3330      3423398 :           tree folded_op0 = fold_for_warn (op0);
    3331      3423398 :           bool warn =
    3332        73151 :             warn_type_limits && !in_system_header_at (loc)
    3333        66863 :             && !(TREE_CODE (folded_op0) == INTEGER_CST
    3334         9790 :                  && !TREE_OVERFLOW (convert (c_common_signed_type (type),
    3335              :                                              folded_op0)))
    3336              :             /* Do not warn for enumeration types.  */
    3337      3480471 :             && (TREE_CODE (expr_original_type (folded_op0)) != ENUMERAL_TYPE);
    3338              : 
    3339      3423398 :           switch (code)
    3340              :             {
    3341        11985 :             case GE_EXPR:
    3342        11985 :               if (warn)
    3343           62 :                 warning_at (loc, OPT_Wtype_limits,
    3344              :                             "comparison of unsigned expression in %<>= 0%> "
    3345              :                             "is always true");
    3346        11985 :               value = truthvalue_true_node;
    3347        11985 :               break;
    3348              : 
    3349       364857 :             case LT_EXPR:
    3350       364857 :               if (warn)
    3351           55 :                 warning_at (loc, OPT_Wtype_limits,
    3352              :                             "comparison of unsigned expression in %<< 0%> "
    3353              :                             "is always false");
    3354       364857 :               value = truthvalue_false_node;
    3355       364857 :               break;
    3356              : 
    3357              :             default:
    3358              :               break;
    3359              :             }
    3360              : 
    3361       376842 :           if (value != NULL_TREE)
    3362              :             {
    3363              :               /* Don't forget to evaluate PRIMOP0 if it has side effects.  */
    3364       376842 :               if (TREE_SIDE_EFFECTS (primop0))
    3365          444 :                 return build2 (COMPOUND_EXPR, TREE_TYPE (value),
    3366          444 :                                primop0, value);
    3367              :               return value;
    3368              :             }
    3369              :         }
    3370              :     }
    3371              : 
    3372     30795493 :   *op0_ptr = convert (type, primop0);
    3373     30795493 :   *op1_ptr = convert (type, primop1);
    3374              : 
    3375     30795493 :   *restype_ptr = truthvalue_type_node;
    3376              : 
    3377     30795493 :   return NULL_TREE;
    3378              : }
    3379              : 
    3380              : /* Return a tree for the sum or difference (RESULTCODE says which)
    3381              :    of pointer PTROP and integer INTOP.  */
    3382              : 
    3383              : tree
    3384      6718978 : pointer_int_sum (location_t loc, enum tree_code resultcode,
    3385              :                  tree ptrop, tree intop, bool complain)
    3386              : {
    3387      6718978 :   tree size_exp, ret;
    3388              : 
    3389              :   /* The result is a pointer of the same type that is being added.  */
    3390      6718978 :   tree result_type = TREE_TYPE (ptrop);
    3391              : 
    3392      6718978 :   if (VOID_TYPE_P (TREE_TYPE (result_type)))
    3393              :     {
    3394         1107 :       if (complain && warn_pointer_arith)
    3395           67 :         pedwarn (loc, OPT_Wpointer_arith,
    3396              :                  "pointer of type %<void *%> used in arithmetic");
    3397              :       else if (!complain)
    3398            0 :         return error_mark_node;
    3399         1107 :       size_exp = integer_one_node;
    3400              :     }
    3401      6717871 :   else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE)
    3402              :     {
    3403          118 :       if (complain && warn_pointer_arith)
    3404           49 :         pedwarn (loc, OPT_Wpointer_arith,
    3405              :                  "pointer to a function used in arithmetic");
    3406              :       else if (!complain)
    3407            0 :         return error_mark_node;
    3408          118 :       size_exp = integer_one_node;
    3409              :     }
    3410      6717753 :   else if (!verify_type_context (loc, TCTX_POINTER_ARITH,
    3411      6717753 :                                  TREE_TYPE (result_type)))
    3412            0 :     size_exp = integer_one_node;
    3413              :   else
    3414              :     {
    3415      6717753 :       if (!complain && !COMPLETE_TYPE_P (TREE_TYPE (result_type)))
    3416          108 :         return error_mark_node;
    3417      6717645 :       size_exp = size_in_bytes_loc (loc, TREE_TYPE (result_type));
    3418              :       /* Wrap the pointer expression in a SAVE_EXPR to make sure it
    3419              :          is evaluated first when the size expression may depend
    3420              :          on it for VM types.  */
    3421      6717645 :       if (TREE_SIDE_EFFECTS (size_exp)
    3422         1935 :           && TREE_SIDE_EFFECTS (ptrop)
    3423      6717664 :           && variably_modified_type_p (TREE_TYPE (ptrop), NULL))
    3424              :         {
    3425           19 :           ptrop = save_expr (ptrop);
    3426           19 :           size_exp = build2 (COMPOUND_EXPR, TREE_TYPE (intop), ptrop, size_exp);
    3427              :         }
    3428              :     }
    3429              : 
    3430              :   /* If what we are about to multiply by the size of the elements
    3431              :      contains a constant term, apply distributive law
    3432              :      and multiply that constant term separately.
    3433              :      This helps produce common subexpressions.  */
    3434      6718870 :   if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR)
    3435       177002 :       && !TREE_CONSTANT (intop)
    3436       176920 :       && TREE_CONSTANT (TREE_OPERAND (intop, 1))
    3437       141715 :       && TREE_CONSTANT (size_exp)
    3438              :       /* If the constant comes from pointer subtraction,
    3439              :          skip this optimization--it would cause an error.  */
    3440       141714 :       && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop, 0))) == INTEGER_TYPE
    3441              :       /* If the constant is unsigned, and smaller than the pointer size,
    3442              :          then we must skip this optimization.  This is because it could cause
    3443              :          an overflow error if the constant is negative but INTOP is not.  */
    3444       283428 :       && (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (intop))
    3445       121982 :           || (TYPE_PRECISION (TREE_TYPE (intop))
    3446       121982 :               == TYPE_PRECISION (TREE_TYPE (ptrop))))
    3447      6894601 :       && TYPE_PRECISION (TREE_TYPE (intop)) <= TYPE_PRECISION (sizetype))
    3448              :     {
    3449        34017 :       tree intop0 = TREE_OPERAND (intop, 0);
    3450        34017 :       tree intop1 = TREE_OPERAND (intop, 1);
    3451        34017 :       if (TYPE_PRECISION (TREE_TYPE (intop)) != TYPE_PRECISION (sizetype)
    3452        34017 :           || TYPE_UNSIGNED (TREE_TYPE (intop)) != TYPE_UNSIGNED (sizetype))
    3453              :         {
    3454        19732 :           tree optype = c_common_type_for_size (TYPE_PRECISION (sizetype),
    3455        19732 :                                                 TYPE_UNSIGNED (sizetype));
    3456        19732 :           intop0 = convert (optype, intop0);
    3457        19732 :           intop1 = convert (optype, intop1);
    3458              :         }
    3459        34017 :       tree t = fold_build2_loc (loc, MULT_EXPR, TREE_TYPE (intop0), intop0,
    3460        34017 :                                 convert (TREE_TYPE (intop0), size_exp));
    3461        34017 :       intop0 = convert (sizetype, t);
    3462        34017 :       if (TREE_OVERFLOW_P (intop0) && !TREE_OVERFLOW (t))
    3463            0 :         intop0 = wide_int_to_tree (TREE_TYPE (intop0), wi::to_wide (intop0));
    3464        34017 :       t = fold_build2_loc (loc, MULT_EXPR, TREE_TYPE (intop1), intop1,
    3465        34017 :                            convert (TREE_TYPE (intop1), size_exp));
    3466        34017 :       intop1 = convert (sizetype, t);
    3467        34017 :       if (TREE_OVERFLOW_P (intop1) && !TREE_OVERFLOW (t))
    3468            0 :         intop1 = wide_int_to_tree (TREE_TYPE (intop1), wi::to_wide (intop1));
    3469        34017 :       intop = build_binary_op (EXPR_LOCATION (intop), TREE_CODE (intop),
    3470              :                                intop0, intop1, true);
    3471              : 
    3472              :       /* Create the sum or difference.  */
    3473        34017 :       if (resultcode == MINUS_EXPR)
    3474           51 :         intop = fold_build1_loc (loc, NEGATE_EXPR, sizetype, intop);
    3475              : 
    3476        34017 :       ret = fold_build_pointer_plus_loc (loc, ptrop, intop);
    3477              : 
    3478        34017 :       return ret;
    3479              :     }
    3480              : 
    3481              :   /* Convert the integer argument to a type the same size as sizetype
    3482              :      so the multiply won't overflow spuriously.  */
    3483      6684853 :   if (TYPE_PRECISION (TREE_TYPE (intop)) != TYPE_PRECISION (sizetype)
    3484      6684853 :       || TYPE_UNSIGNED (TREE_TYPE (intop)) != TYPE_UNSIGNED (sizetype))
    3485      4551227 :     intop = convert (c_common_type_for_size (TYPE_PRECISION (sizetype),
    3486      4551227 :                                              TYPE_UNSIGNED (sizetype)), intop);
    3487              : 
    3488              :   /* Replace the integer argument with a suitable product by the object size.
    3489              :      Do this multiplication as signed, then convert to the appropriate type
    3490              :      for the pointer operation and disregard an overflow that occurred only
    3491              :      because of the sign-extension change in the latter conversion.  */
    3492      6684853 :   {
    3493      6684853 :     tree t = fold_build2_loc (loc, MULT_EXPR, TREE_TYPE (intop), intop,
    3494      6684853 :                               convert (TREE_TYPE (intop), size_exp));
    3495      6684853 :     intop = convert (sizetype, t);
    3496      6684853 :     if (TREE_OVERFLOW_P (intop) && !TREE_OVERFLOW (t))
    3497            0 :       intop = wide_int_to_tree (TREE_TYPE (intop), wi::to_wide (intop));
    3498              :   }
    3499              : 
    3500              :   /* Create the sum or difference.  */
    3501      6684853 :   if (resultcode == MINUS_EXPR)
    3502       323613 :     intop = fold_build1_loc (loc, NEGATE_EXPR, sizetype, intop);
    3503              : 
    3504      6684853 :   ret = fold_build_pointer_plus_loc (loc, ptrop, intop);
    3505              : 
    3506      6684853 :   return ret;
    3507              : }
    3508              : 
    3509              : /* Wrap a C_MAYBE_CONST_EXPR around an expression that is fully folded
    3510              :    and if NON_CONST is known not to be permitted in an evaluated part
    3511              :    of a constant expression.  */
    3512              : 
    3513              : tree
    3514      4502507 : c_wrap_maybe_const (tree expr, bool non_const)
    3515              : {
    3516      4502507 :   location_t loc = EXPR_LOCATION (expr);
    3517              : 
    3518              :   /* This should never be called for C++.  */
    3519      4502507 :   if (c_dialect_cxx ())
    3520            0 :     gcc_unreachable ();
    3521              : 
    3522              :   /* The result of folding may have a NOP_EXPR to set TREE_NO_WARNING.  */
    3523      4503253 :   STRIP_TYPE_NOPS (expr);
    3524      4502507 :   expr = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (expr), NULL, expr);
    3525      4502507 :   C_MAYBE_CONST_EXPR_NON_CONST (expr) = non_const;
    3526      4502507 :   protected_set_expr_location (expr, loc);
    3527              : 
    3528      4502507 :   return expr;
    3529              : }
    3530              : 
    3531              : /* Return whether EXPR is a declaration whose address can never be NULL.
    3532              :    The address of the first struct member could be NULL only if it were
    3533              :    accessed through a NULL pointer, and such an access would be invalid.
    3534              :    The address of a weak symbol may be null unless it has a definition.  */
    3535              : 
    3536              : bool
    3537         1412 : decl_with_nonnull_addr_p (const_tree expr)
    3538              : {
    3539         1412 :   if (!DECL_P (expr))
    3540              :     return false;
    3541              : 
    3542         1158 :   if (TREE_CODE (expr) == FIELD_DECL
    3543         1081 :       || TREE_CODE (expr) == PARM_DECL
    3544         1047 :       || TREE_CODE (expr) == LABEL_DECL)
    3545              :     return true;
    3546              : 
    3547         1022 :   if (!VAR_OR_FUNCTION_DECL_P (expr))
    3548              :     return false;
    3549              : 
    3550         1022 :   if (!DECL_WEAK (expr))
    3551              :     /* Ordinary (non-weak) symbols have nonnull addresses.  */
    3552              :     return true;
    3553              : 
    3554          531 :   if (DECL_INITIAL (expr) && DECL_INITIAL (expr) != error_mark_node)
    3555              :     /* Initialized weak symbols have nonnull addresses.  */
    3556              :     return true;
    3557              : 
    3558          478 :   if (DECL_EXTERNAL (expr) || !TREE_STATIC (expr))
    3559              :     /* Uninitialized extern weak symbols and weak symbols with no
    3560              :        allocated storage might have a null address.  */
    3561              :     return false;
    3562              : 
    3563           43 :   tree attribs = DECL_ATTRIBUTES (expr);
    3564           43 :   if (lookup_attribute ("weakref", attribs))
    3565              :     /* Weakref symbols might have a null address unless their referent
    3566              :        is known not to.  Don't bother following weakref targets here.  */
    3567              :     return false;
    3568              : 
    3569              :   return true;
    3570              : }
    3571              : 
    3572              : /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
    3573              :    or for an `if' or `while' statement or ?..: exp.  It should already
    3574              :    have been validated to be of suitable type; otherwise, a bad
    3575              :    diagnostic may result.
    3576              : 
    3577              :    The EXPR is located at LOCATION.
    3578              : 
    3579              :    This preparation consists of taking the ordinary
    3580              :    representation of an expression expr and producing a valid tree
    3581              :    boolean expression describing whether expr is nonzero.  We could
    3582              :    simply always do build_binary_op (NE_EXPR, expr, truthvalue_false_node, 1),
    3583              :    but we optimize comparisons, &&, ||, and !.
    3584              : 
    3585              :    The resulting type should always be `truthvalue_type_node'.  */
    3586              : 
    3587              : tree
    3588     11067891 : c_common_truthvalue_conversion (location_t location, tree expr)
    3589              : {
    3590     12054518 :   STRIP_ANY_LOCATION_WRAPPER (expr);
    3591     12054518 :   switch (TREE_CODE (expr))
    3592              :     {
    3593      2416182 :     case EQ_EXPR:   case NE_EXPR:   case UNEQ_EXPR: case LTGT_EXPR:
    3594      2416182 :     case LE_EXPR:   case GE_EXPR:   case LT_EXPR:   case GT_EXPR:
    3595      2416182 :     case UNLE_EXPR: case UNGE_EXPR: case UNLT_EXPR: case UNGT_EXPR:
    3596      2416182 :     case ORDERED_EXPR: case UNORDERED_EXPR:
    3597      2416182 :       if (TREE_TYPE (expr) == truthvalue_type_node)
    3598              :         return expr;
    3599       311487 :       expr = build2 (TREE_CODE (expr), truthvalue_type_node,
    3600       311487 :                      TREE_OPERAND (expr, 0), TREE_OPERAND (expr, 1));
    3601       311487 :       goto ret;
    3602              : 
    3603       607988 :     case TRUTH_ANDIF_EXPR:
    3604       607988 :     case TRUTH_ORIF_EXPR:
    3605       607988 :     case TRUTH_AND_EXPR:
    3606       607988 :     case TRUTH_OR_EXPR:
    3607       607988 :     case TRUTH_XOR_EXPR:
    3608       607988 :       if (TREE_TYPE (expr) == truthvalue_type_node)
    3609              :         return expr;
    3610           74 :       expr = build2 (TREE_CODE (expr), truthvalue_type_node,
    3611              :                      c_common_truthvalue_conversion (location,
    3612           37 :                                                      TREE_OPERAND (expr, 0)),
    3613              :                      c_common_truthvalue_conversion (location,
    3614           37 :                                                      TREE_OPERAND (expr, 1)));
    3615           37 :       goto ret;
    3616              : 
    3617       246751 :     case TRUTH_NOT_EXPR:
    3618       246751 :       if (TREE_TYPE (expr) == truthvalue_type_node)
    3619              :         return expr;
    3620       243819 :       expr = build1 (TREE_CODE (expr), truthvalue_type_node,
    3621              :                      c_common_truthvalue_conversion (location,
    3622       243819 :                                                      TREE_OPERAND (expr, 0)));
    3623       243819 :       goto ret;
    3624              : 
    3625              :     case ERROR_MARK:
    3626              :       return expr;
    3627              : 
    3628      2592380 :     case INTEGER_CST:
    3629      2592380 :       if (TREE_CODE (TREE_TYPE (expr)) == ENUMERAL_TYPE
    3630       628890 :           && !integer_zerop (expr)
    3631      2977173 :           && !integer_onep (expr))
    3632          869 :         warning_at (location, OPT_Wint_in_bool_context,
    3633              :                     "enum constant in boolean context");
    3634      2592380 :       return integer_zerop (expr) ? truthvalue_false_node
    3635      2592380 :                                   : truthvalue_true_node;
    3636              : 
    3637         1288 :     case REAL_CST:
    3638         1288 :       return real_compare (NE_EXPR, &TREE_REAL_CST (expr), &dconst0)
    3639         1288 :              ? truthvalue_true_node
    3640         1288 :              : truthvalue_false_node;
    3641              : 
    3642            0 :     case FIXED_CST:
    3643            0 :       return fixed_compare (NE_EXPR, &TREE_FIXED_CST (expr),
    3644            0 :                             &FCONST0 (TYPE_MODE (TREE_TYPE (expr))))
    3645            0 :              ? truthvalue_true_node
    3646            0 :              : truthvalue_false_node;
    3647              : 
    3648            0 :     case FUNCTION_DECL:
    3649            0 :       expr = build_unary_op (location, ADDR_EXPR, expr, false);
    3650              :       /* Fall through.  */
    3651              : 
    3652          581 :     case ADDR_EXPR:
    3653          581 :       {
    3654          581 :         tree inner = TREE_OPERAND (expr, 0);
    3655          581 :         if (decl_with_nonnull_addr_p (inner)
    3656              :             /* Check both EXPR and INNER for suppression.  */
    3657          127 :             && !warning_suppressed_p (expr, OPT_Waddress)
    3658          694 :             && !warning_suppressed_p (inner, OPT_Waddress))
    3659              :           {
    3660              :             /* Common Ada programmer's mistake.  */
    3661          107 :             warning_at (location,
    3662          107 :                         OPT_Waddress,
    3663              :                         "the address of %qD will always evaluate as %<true%>",
    3664              :                         inner);
    3665          107 :             suppress_warning (inner, OPT_Waddress);
    3666          107 :             return truthvalue_true_node;
    3667              :           }
    3668              :         break;
    3669              :       }
    3670              : 
    3671          578 :     case COMPLEX_EXPR:
    3672         1734 :       expr = build_binary_op (EXPR_LOCATION (expr),
    3673          578 :                               (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1))
    3674              :                                ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
    3675              :                 c_common_truthvalue_conversion (location,
    3676          578 :                                                 TREE_OPERAND (expr, 0)),
    3677              :                 c_common_truthvalue_conversion (location,
    3678          578 :                                                 TREE_OPERAND (expr, 1)),
    3679              :                               false);
    3680          578 :       goto ret;
    3681              : 
    3682           74 :     case NEGATE_EXPR:
    3683           74 :     case ABS_EXPR:
    3684           74 :     case ABSU_EXPR:
    3685           74 :     case FLOAT_EXPR:
    3686           74 :     case EXCESS_PRECISION_EXPR:
    3687              :       /* These don't change whether an object is nonzero or zero.  */
    3688           74 :       return c_common_truthvalue_conversion (location, TREE_OPERAND (expr, 0));
    3689              : 
    3690            0 :     case LROTATE_EXPR:
    3691            0 :     case RROTATE_EXPR:
    3692              :       /* These don't change whether an object is zero or nonzero, but
    3693              :          we can't ignore them if their second arg has side-effects.  */
    3694            0 :       if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1)))
    3695              :         {
    3696            0 :           expr = build2 (COMPOUND_EXPR, truthvalue_type_node,
    3697            0 :                          TREE_OPERAND (expr, 1),
    3698              :                          c_common_truthvalue_conversion
    3699            0 :                          (location, TREE_OPERAND (expr, 0)));
    3700            0 :           goto ret;
    3701              :         }
    3702              :       else
    3703            0 :         return c_common_truthvalue_conversion (location,
    3704            0 :                                                TREE_OPERAND (expr, 0));
    3705              : 
    3706          502 :     case MULT_EXPR:
    3707          502 :       warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context,
    3708              :                   "%<*%> in boolean context, suggest %<&&%> instead");
    3709          502 :       break;
    3710              : 
    3711          166 :     case LSHIFT_EXPR:
    3712              :       /* We will only warn on signed shifts here, because the majority of
    3713              :          false positive warnings happen in code where unsigned arithmetic
    3714              :          was used in anticipation of a possible overflow.
    3715              :          Furthermore, if we see an unsigned type here we know that the
    3716              :          result of the shift is not subject to integer promotion rules.  */
    3717          166 :       if ((TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
    3718            1 :            || TREE_CODE (TREE_TYPE (expr)) == BITINT_TYPE)
    3719          167 :           && !TYPE_UNSIGNED (TREE_TYPE (expr)))
    3720          150 :         warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context,
    3721              :                     "%<<<%> in boolean context, did you mean %<<%>?");
    3722              :       break;
    3723              : 
    3724        57002 :     case COND_EXPR:
    3725        57002 :       if (warn_int_in_bool_context
    3726        58698 :           && !from_macro_definition_at (EXPR_LOCATION (expr)))
    3727              :         {
    3728          929 :           tree val1 = fold_for_warn (TREE_OPERAND (expr, 1));
    3729          929 :           tree val2 = fold_for_warn (TREE_OPERAND (expr, 2));
    3730          929 :           if (TREE_CODE (val1) == INTEGER_CST
    3731           82 :               && TREE_CODE (val2) == INTEGER_CST
    3732           82 :               && !integer_zerop (val1)
    3733           74 :               && !integer_zerop (val2)
    3734          945 :               && (!integer_onep (val1)
    3735           12 :                   || !integer_onep (val2)))
    3736           12 :             warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context,
    3737              :                         "%<?:%> using integer constants in boolean context, "
    3738              :                         "the expression will always evaluate to %<true%>");
    3739          917 :           else if ((TREE_CODE (val1) == INTEGER_CST
    3740           70 :                     && !integer_zerop (val1)
    3741           62 :                     && !integer_onep (val1))
    3742          987 :                    || (TREE_CODE (val2) == INTEGER_CST
    3743          336 :                        && !integer_zerop (val2)
    3744          274 :                        && !integer_onep (val2)))
    3745            4 :             warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context,
    3746              :                         "%<?:%> using integer constants in boolean context");
    3747              :         }
    3748              :       /* Distribute the conversion into the arms of a COND_EXPR.  */
    3749        57002 :       if (c_dialect_cxx ())
    3750              :         /* Avoid premature folding.  */
    3751              :         break;
    3752              :       else
    3753              :         {
    3754        19807 :           int w = warn_int_in_bool_context;
    3755        19807 :           warn_int_in_bool_context = 0;
    3756              :           /* Folding will happen later for C.  */
    3757        59421 :           expr = build3 (COND_EXPR, truthvalue_type_node,
    3758        19807 :                          TREE_OPERAND (expr, 0),
    3759              :                          c_common_truthvalue_conversion (location,
    3760        19807 :                                                          TREE_OPERAND (expr, 1)),
    3761              :                          c_common_truthvalue_conversion (location,
    3762        19807 :                                                          TREE_OPERAND (expr, 2)));
    3763        19807 :           warn_int_in_bool_context = w;
    3764        19807 :           goto ret;
    3765              :         }
    3766              : 
    3767       846213 :     CASE_CONVERT:
    3768       846213 :       {
    3769       846213 :         tree totype = TREE_TYPE (expr);
    3770       846213 :         tree fromtype = TREE_TYPE (TREE_OPERAND (expr, 0));
    3771              : 
    3772       846213 :         if (POINTER_TYPE_P (totype)
    3773         2209 :             && !c_inhibit_evaluation_warnings
    3774         2041 :             && TREE_CODE (fromtype) == REFERENCE_TYPE)
    3775              :           {
    3776            0 :             tree inner = expr;
    3777            0 :             STRIP_NOPS (inner);
    3778              : 
    3779            0 :             if (DECL_P (inner))
    3780            0 :               warning_at (location,
    3781            0 :                           OPT_Waddress,
    3782              :                           "the compiler can assume that the address of "
    3783              :                           "%qD will always evaluate to %<true%>",
    3784              :                           inner);
    3785              :           }
    3786              : 
    3787              :         /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
    3788              :            since that affects how `default_conversion' will behave.  */
    3789       846213 :         if (TREE_CODE (totype) == REFERENCE_TYPE
    3790       846213 :             || TREE_CODE (fromtype) == REFERENCE_TYPE)
    3791              :           break;
    3792              :         /* Don't strip a conversion from C++0x scoped enum, since they
    3793              :            don't implicitly convert to other types.  */
    3794       846213 :         if (TREE_CODE (fromtype) == ENUMERAL_TYPE
    3795       846213 :             && ENUM_IS_SCOPED (fromtype))
    3796              :           break;
    3797              :         /* If this isn't narrowing the argument, we can ignore it.  */
    3798       846104 :         if (TYPE_PRECISION (totype) >= TYPE_PRECISION (fromtype))
    3799              :           {
    3800       828786 :             tree op0 = TREE_OPERAND (expr, 0);
    3801       828786 :             if ((TREE_CODE (fromtype) == POINTER_TYPE
    3802         2125 :                  && (TREE_CODE (totype) == INTEGER_TYPE
    3803         2125 :                      || TREE_CODE (totype) == BITINT_TYPE))
    3804       830879 :                 || warning_suppressed_p (expr, OPT_Waddress))
    3805              :               /* Suppress -Waddress for casts to intptr_t, propagating
    3806              :                  any suppression from the enclosing expression to its
    3807              :                  operand.  */
    3808           44 :               suppress_warning (op0, OPT_Waddress);
    3809       828786 :             return c_common_truthvalue_conversion (location, op0);
    3810              :           }
    3811              :       }
    3812              :       break;
    3813              : 
    3814         9073 :     case MODIFY_EXPR:
    3815         9073 :       if (!warning_suppressed_p (expr, OPT_Wparentheses)
    3816          269 :           && warn_parentheses
    3817         9342 :           && warning_at (location, OPT_Wparentheses,
    3818              :                          "suggest parentheses around assignment used as "
    3819              :                          "truth value"))
    3820           14 :         suppress_warning (expr, OPT_Wparentheses);
    3821              :       break;
    3822              : 
    3823       157836 :     case CONST_DECL:
    3824       157836 :       {
    3825       157836 :         tree folded_expr = fold_for_warn (expr);
    3826       157836 :         if (folded_expr != expr)
    3827              :           return c_common_truthvalue_conversion (location, folded_expr);
    3828              :       }
    3829              :       break;
    3830              : 
    3831              :     default:
    3832              :       break;
    3833              :     }
    3834              : 
    3835      5182589 :   if (TREE_CODE (TREE_TYPE (expr)) == COMPLEX_TYPE)
    3836              :     {
    3837          406 :       tree t = save_expr (expr);
    3838          406 :       expr = (build_binary_op
    3839          812 :               (EXPR_LOCATION (expr),
    3840          406 :                (TREE_SIDE_EFFECTS (expr)
    3841              :                 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
    3842              :         c_common_truthvalue_conversion
    3843              :                (location,
    3844              :                 build_unary_op (location, REALPART_EXPR, t, false)),
    3845              :         c_common_truthvalue_conversion
    3846              :                (location,
    3847              :                 build_unary_op (location, IMAGPART_EXPR, t, false)),
    3848              :                false));
    3849          406 :       goto ret;
    3850              :     }
    3851              : 
    3852      5182183 :   if (FIXED_POINT_TYPE_P (TREE_TYPE (expr)))
    3853              :     {
    3854            0 :       tree fixed_zero_node = build_fixed (TREE_TYPE (expr),
    3855            0 :                                           FCONST0 (TYPE_MODE
    3856              :                                                    (TREE_TYPE (expr))));
    3857            0 :       return build_binary_op (location, NE_EXPR, expr, fixed_zero_node, true);
    3858              :     }
    3859              :   else
    3860      5182183 :     return build_binary_op (location, NE_EXPR, expr, integer_zero_node, true);
    3861              : 
    3862       576134 :  ret:
    3863       576134 :   protected_set_expr_location (expr, location);
    3864       576134 :   return expr;
    3865              : }
    3866              : 
    3867              : static void def_builtin_1  (enum built_in_function fncode,
    3868              :                             const char *name,
    3869              :                             enum built_in_class fnclass,
    3870              :                             tree fntype, tree libtype,
    3871              :                             bool both_p, bool fallback_p, bool nonansi_p,
    3872              :                             tree fnattrs, bool implicit_p);
    3873              : 
    3874              : 
    3875              : /* Apply the TYPE_QUALS to the new DECL.  */
    3876              : 
    3877              : void
    3878   1066086547 : c_apply_type_quals_to_decl (int type_quals, tree decl)
    3879              : {
    3880   1066086547 :   tree type = TREE_TYPE (decl);
    3881              : 
    3882   1066086547 :   if (type == error_mark_node)
    3883              :     return;
    3884              : 
    3885   1066086318 :   if ((type_quals & TYPE_QUAL_CONST)
    3886    673698001 :       || (type && TREE_CODE (type) == REFERENCE_TYPE))
    3887              :     /* We used to check TYPE_NEEDS_CONSTRUCTING here, but now a constexpr
    3888              :        constructor can produce constant init, so rely on cp_finish_decl to
    3889              :        clear TREE_READONLY if the variable has non-constant init.  */
    3890    498592731 :     TREE_READONLY (decl) = 1;
    3891   1066086318 :   if (type_quals & TYPE_QUAL_VOLATILE)
    3892              :     {
    3893       135168 :       TREE_SIDE_EFFECTS (decl) = 1;
    3894       135168 :       TREE_THIS_VOLATILE (decl) = 1;
    3895              :     }
    3896   1066086318 :   if (type_quals & TYPE_QUAL_RESTRICT)
    3897              :     {
    3898     10934384 :       while (type && TREE_CODE (type) == ARRAY_TYPE)
    3899              :         /* Allow 'restrict' on arrays of pointers.
    3900              :            FIXME currently we just ignore it.  */
    3901            7 :         type = TREE_TYPE (type);
    3902     10934377 :       if (!type
    3903     10934377 :           || !POINTER_TYPE_P (type)
    3904     21868751 :           || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type)))
    3905            4 :         error ("invalid use of %<restrict%>");
    3906              :     }
    3907              : }
    3908              : 
    3909              : /* Return the typed-based alias set for T, which may be an expression
    3910              :    or a type.  Return -1 if we don't do anything special.  */
    3911              : 
    3912              : alias_set_type
    3913    569101020 : c_common_get_alias_set (tree t)
    3914              : {
    3915              :   /* For VLAs, use the alias set of the element type rather than the
    3916              :      default of alias set 0 for types compared structurally.  */
    3917    569101020 :   if (TYPE_P (t) && TYPE_STRUCTURAL_EQUALITY_P (t))
    3918              :     {
    3919       918524 :       if (TREE_CODE (t) == ARRAY_TYPE)
    3920       461109 :         return get_alias_set (TREE_TYPE (t));
    3921              :       return -1;
    3922              :     }
    3923              : 
    3924              :   /* That's all the expressions we handle specially.  */
    3925    568182496 :   if (!TYPE_P (t))
    3926              :     return -1;
    3927              : 
    3928              :   /* Unlike char, char8_t doesn't alias in C++.  (In C, char8_t is not
    3929              :      a distinct type.)  */
    3930     47435986 :   if (flag_char8_t && t == char8_type_node && c_dialect_cxx ())
    3931              :     return -1;
    3932              : 
    3933              :   /* The C standard guarantees that any object may be accessed via an
    3934              :      lvalue that has narrow character type.  */
    3935     47435845 :   if (t == char_type_node
    3936     16213294 :       || t == signed_char_type_node
    3937     12545279 :       || t == unsigned_char_type_node)
    3938              :     return 0;
    3939              : 
    3940              :   /* The C standard specifically allows aliasing between signed and
    3941              :      unsigned variants of the same type.  We treat the signed
    3942              :      variant as canonical.  */
    3943      1890403 :   if (TREE_CODE (t) == INTEGER_TYPE || TREE_CODE (t) == BITINT_TYPE)
    3944              :     {
    3945              :       /* For normal INTEGER_TYPEs (except ones built by
    3946              :          build_nonstandard_integer_type), both signed and unsigned variants
    3947              :          of the type are always reachable from GTY roots, so just calling
    3948              :          get_alias_set on the signed type is ok.  For BITINT_TYPE and
    3949              :          non-standard INTEGER_TYPEs, only unsigned could be used and the
    3950              :          corresponding signed type could be created on demand and garbage
    3951              :          collected as unused, so the alias set of unsigned type could keep
    3952              :          changing.
    3953              :          Avoid that by remembering the signed type alias set in
    3954              :          TYPE_ALIAS_SET and also when being asked about !TYPE_UNSIGNED
    3955              :          check if there isn't a corresponding unsigned type with
    3956              :          TYPE_ALIAS_SET_KNOWN_P.  */
    3957       524805 :       if (TYPE_UNSIGNED (t))
    3958              :         {
    3959              :           /* There is no signed _BitInt(1) before C2Y.  */
    3960       227003 :           if (TREE_CODE (t) == BITINT_TYPE
    3961          581 :               && !flag_isoc2y
    3962       227583 :               && TYPE_PRECISION (t) == 1)
    3963              :             return -1;
    3964       226996 :           tree t1 = c_common_signed_type (t);
    3965       226996 :           gcc_checking_assert (t != t1);
    3966       226996 :           TYPE_ALIAS_SET (t) = get_alias_set (t1);
    3967       226996 :           return TYPE_ALIAS_SET (t);
    3968              :         }
    3969              :       else
    3970              :         {
    3971       297802 :           tree t1 = c_common_unsigned_type (t);
    3972       297802 :           gcc_checking_assert (t != t1);
    3973       297802 :           if (TYPE_ALIAS_SET_KNOWN_P (t1))
    3974              :             {
    3975          316 :               TYPE_ALIAS_SET (t) = TYPE_ALIAS_SET (t1);
    3976          316 :               return TYPE_ALIAS_SET (t);
    3977              :             }
    3978              :         }
    3979              :     }
    3980              : 
    3981              :   return -1;
    3982              : }
    3983              : 
    3984              : /* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where
    3985              :    the IS_SIZEOF parameter indicates which operator is being applied.
    3986              :    The COMPLAIN flag controls whether we should diagnose possibly
    3987              :    ill-formed constructs or not.  LOC is the location of the SIZEOF or
    3988              :    TYPEOF operator.  If MIN_ALIGNOF, the least alignment required for
    3989              :    a type in any context should be returned, rather than the normal
    3990              :    alignment for that type.  */
    3991              : 
    3992              : tree
    3993     23314629 : c_sizeof_or_alignof_type (location_t loc,
    3994              :                           tree type, bool is_sizeof, bool min_alignof,
    3995              :                           int complain)
    3996              : {
    3997     23314629 :   const char *op_name;
    3998     23314629 :   tree value = NULL;
    3999     23314629 :   enum tree_code type_code = TREE_CODE (type);
    4000              : 
    4001     23314629 :   op_name = is_sizeof ? "sizeof" : "__alignof__";
    4002              : 
    4003     23314629 :   if (type_code == FUNCTION_TYPE)
    4004              :     {
    4005           61 :       if (is_sizeof)
    4006              :         {
    4007           56 :           if (complain && warn_pointer_arith)
    4008           26 :             pedwarn (loc, OPT_Wpointer_arith,
    4009              :                      "invalid application of %<sizeof%> to a function type");
    4010              :           else if (!complain)
    4011           20 :             return error_mark_node;
    4012           36 :           value = size_one_node;
    4013              :         }
    4014              :       else
    4015              :         {
    4016            5 :           if (complain)
    4017              :             {
    4018            5 :               if (c_dialect_cxx ())
    4019            3 :                 pedwarn (loc, OPT_Wpedantic, "ISO C++ does not permit "
    4020              :                          "%<alignof%> applied to a function type");
    4021              :               else
    4022            2 :                 pedwarn (loc, OPT_Wpedantic, "ISO C does not permit "
    4023              :                          "%<_Alignof%> applied to a function type");
    4024              :             }
    4025            5 :           value = size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
    4026              :         }
    4027              :     }
    4028     23314568 :   else if (type_code == VOID_TYPE || type_code == ERROR_MARK)
    4029              :     {
    4030           98 :       if (type_code == VOID_TYPE
    4031           98 :           && complain && warn_pointer_arith)
    4032           22 :         pedwarn (loc, OPT_Wpointer_arith,
    4033              :                  "invalid application of %qs to a void type", op_name);
    4034           76 :       else if (!complain)
    4035           37 :         return error_mark_node;
    4036           61 :       value = size_one_node;
    4037              :     }
    4038     23314470 :   else if (!COMPLETE_TYPE_P (type)
    4039     23314470 :            && ((!c_dialect_cxx () && !flag_isoc2y)
    4040              :                || is_sizeof
    4041          148 :                || type_code != ARRAY_TYPE))
    4042              :     {
    4043          275 :       if (complain)
    4044          192 :         error_at (loc, "invalid application of %qs to incomplete type %qT",
    4045              :                   op_name, type);
    4046          275 :       return error_mark_node;
    4047              :     }
    4048     22619958 :   else if (c_dialect_cxx () && type_code == ARRAY_TYPE
    4049     23574375 :            && !COMPLETE_TYPE_P (TREE_TYPE (type)))
    4050              :     {
    4051            0 :       if (complain)
    4052            0 :         error_at (loc, "invalid application of %qs to array type %qT of "
    4053              :                   "incomplete element type", op_name, type);
    4054            0 :       return error_mark_node;
    4055              :     }
    4056     24246586 :   else if (!verify_type_context (loc, is_sizeof ? TCTX_SIZEOF : TCTX_ALIGNOF,
    4057              :                                  type, !complain))
    4058              :     {
    4059            0 :       if (!complain)
    4060            0 :         return error_mark_node;
    4061            0 :       value = size_one_node;
    4062              :     }
    4063              :   else
    4064              :     {
    4065     23314195 :       if (is_sizeof)
    4066              :         /* Convert in case a char is more than one unit.  */
    4067     22381804 :         value = size_binop_loc (loc, CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
    4068     22381804 :                                 size_int (TYPE_PRECISION (char_type_node)
    4069              :                                           / BITS_PER_UNIT));
    4070       932391 :       else if (min_alignof)
    4071       713055 :         value = size_int (min_align_of_type (type));
    4072              :       else
    4073       219336 :         value = size_int (TYPE_ALIGN_UNIT (type));
    4074              :     }
    4075              : 
    4076              :   /* VALUE will have the middle-end integer type sizetype.
    4077              :      However, we should really return a value of type `size_t',
    4078              :      which is just a typedef for an ordinary integer type.  */
    4079     23314297 :   value = fold_convert_loc (loc, size_type_node, value);
    4080              : 
    4081     23314297 :   return value;
    4082              : }
    4083              : 
    4084              : /* Implement the __alignof keyword: Return the minimum required
    4085              :    alignment of EXPR, measured in bytes.  For VAR_DECLs,
    4086              :    FUNCTION_DECLs and FIELD_DECLs return DECL_ALIGN (which can be set
    4087              :    from an "aligned" __attribute__ specification).  LOC is the
    4088              :    location of the ALIGNOF operator.  */
    4089              : 
    4090              : tree
    4091        40801 : c_alignof_expr (location_t loc, tree expr)
    4092              : {
    4093        40801 :   tree t;
    4094              : 
    4095        40801 :   if (!verify_type_context (loc, TCTX_ALIGNOF, TREE_TYPE (expr)))
    4096            0 :     t = size_one_node;
    4097              : 
    4098        40801 :   else if (VAR_OR_FUNCTION_DECL_P (expr))
    4099         7245 :     t = size_int (DECL_ALIGN_UNIT (expr));
    4100              : 
    4101        33556 :   else if (TREE_CODE (expr) == COMPONENT_REF
    4102        33556 :            && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1)))
    4103              :     {
    4104            1 :       error_at (loc, "%<__alignof%> applied to a bit-field");
    4105            1 :       t = size_one_node;
    4106              :     }
    4107        33555 :   else if (TREE_CODE (expr) == COMPONENT_REF
    4108        33555 :            && TREE_CODE (TREE_OPERAND (expr, 1)) == FIELD_DECL)
    4109        17577 :     t = size_int (DECL_ALIGN_UNIT (TREE_OPERAND (expr, 1)));
    4110              : 
    4111        15978 :   else if (INDIRECT_REF_P (expr))
    4112              :     {
    4113           57 :       tree t = TREE_OPERAND (expr, 0);
    4114           57 :       tree best = t;
    4115           57 :       int bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
    4116              : 
    4117           57 :       while (CONVERT_EXPR_P (t)
    4118           57 :              && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
    4119              :         {
    4120            0 :           int thisalign;
    4121              : 
    4122            0 :           t = TREE_OPERAND (t, 0);
    4123            0 :           thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
    4124            0 :           if (thisalign > bestalign)
    4125            0 :             best = t, bestalign = thisalign;
    4126              :         }
    4127           57 :       return c_alignof (loc, TREE_TYPE (TREE_TYPE (best)));
    4128              :     }
    4129              :   else
    4130        15921 :     return c_alignof (loc, TREE_TYPE (expr));
    4131              : 
    4132        24823 :   return fold_convert_loc (loc, size_type_node, t);
    4133              : }
    4134              : 
    4135              : /* Implement the _Countof keyword:
    4136              :    Return the number of elements of an array.  */
    4137              : 
    4138              : tree
    4139           71 : c_countof_type (location_t loc, tree type)
    4140              : {
    4141           71 :   enum tree_code type_code;
    4142           71 :   tree value;
    4143              : 
    4144           71 :   type_code = TREE_CODE (type);
    4145           71 :   if (type_code != ARRAY_TYPE)
    4146              :     {
    4147           11 :       error_at (loc, "invalid application of %<_Countof%> to type %qT", type);
    4148           11 :       return error_mark_node;
    4149              :     }
    4150           60 :   if (!COMPLETE_TYPE_P (type))
    4151              :     {
    4152            2 :       error_at (loc,
    4153              :                 "invalid application of %<_Countof%> to incomplete type %qT",
    4154              :                 type);
    4155            2 :       return error_mark_node;
    4156              :     }
    4157              : 
    4158           58 :   value = array_type_nelts_top (type);
    4159              :   /* VALUE will have the middle-end integer type sizetype.
    4160              :      However, we should really return a value of type `size_t',
    4161              :      which is just a typedef for an ordinary integer type.  */
    4162           58 :   value = fold_convert_loc (loc, size_type_node, value);
    4163           58 :   return value;
    4164              : }
    4165              : 
    4166              : /* Implement the _Maxof operator:
    4167              :    Return the maximum representable value of an integer type.  */
    4168              : 
    4169              : tree
    4170           46 : c_maxof_type (location_t loc, tree type)
    4171              : {
    4172           46 :   if (!INTEGRAL_TYPE_P (type))
    4173              :     {
    4174            3 :       error_at (loc, "invalid application of %<_Maxof%> to type %qT", type);
    4175            3 :       return error_mark_node;
    4176              :     }
    4177           43 :   if (!COMPLETE_TYPE_P (type))
    4178              :     {
    4179            1 :       error_at (loc, "invalid application of %<_Maxof%> to incomplete type %qT",
    4180              :                 type);
    4181            1 :       return error_mark_node;
    4182              :     }
    4183              : 
    4184           42 :   return TYPE_MAX_VALUE (type);
    4185              : }
    4186              : 
    4187              : /* Implement the _Minof operator:
    4188              :    Return the minimum representable value of an integer type.  */
    4189              : 
    4190              : tree
    4191           46 : c_minof_type (location_t loc, tree type)
    4192              : {
    4193           46 :   if (!INTEGRAL_TYPE_P (type))
    4194              :     {
    4195            3 :       error_at (loc, "invalid application of %<_Minof%> to type %qT", type);
    4196            3 :       return error_mark_node;
    4197              :     }
    4198           43 :   if (!COMPLETE_TYPE_P (type))
    4199              :     {
    4200            1 :       error_at (loc, "invalid application of %<_Minof%> to incomplete type %qT",
    4201              :                 type);
    4202            1 :       return error_mark_node;
    4203              :     }
    4204              : 
    4205           42 :   return TYPE_MIN_VALUE (type);
    4206              : }
    4207              : 
    4208              : /* Handle C and C++ default attributes.  */
    4209              : 
    4210              : enum built_in_attribute
    4211              : {
    4212              : #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
    4213              : #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
    4214              : #define DEF_ATTR_STRING(ENUM, VALUE) ENUM,
    4215              : #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
    4216              : #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
    4217              : #include "builtin-attrs.def"
    4218              : #undef DEF_ATTR_NULL_TREE
    4219              : #undef DEF_ATTR_INT
    4220              : #undef DEF_ATTR_STRING
    4221              : #undef DEF_ATTR_IDENT
    4222              : #undef DEF_ATTR_TREE_LIST
    4223              :   ATTR_LAST
    4224              : };
    4225              : 
    4226              : static GTY(()) tree built_in_attributes[(int) ATTR_LAST];
    4227              : 
    4228              : static void c_init_attributes (void);
    4229              : 
    4230              : enum c_builtin_type
    4231              : {
    4232              : #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
    4233              : #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
    4234              : #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
    4235              : #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
    4236              : #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
    4237              : #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
    4238              : #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
    4239              : #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4240              :                             ARG6) NAME,
    4241              : #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4242              :                             ARG6, ARG7) NAME,
    4243              : #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4244              :                             ARG6, ARG7, ARG8) NAME,
    4245              : #define DEF_FUNCTION_TYPE_9(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4246              :                             ARG6, ARG7, ARG8, ARG9) NAME,
    4247              : #define DEF_FUNCTION_TYPE_10(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4248              :                              ARG6, ARG7, ARG8, ARG9, ARG10) NAME,
    4249              : #define DEF_FUNCTION_TYPE_11(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4250              :                              ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) NAME,
    4251              : #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
    4252              : #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
    4253              : #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
    4254              : #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
    4255              : #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
    4256              : #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
    4257              :                                 NAME,
    4258              : #define DEF_FUNCTION_TYPE_VAR_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4259              :                                 ARG6) NAME,
    4260              : #define DEF_FUNCTION_TYPE_VAR_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4261              :                                 ARG6, ARG7) NAME,
    4262              : #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
    4263              : #include "builtin-types.def"
    4264              : #undef DEF_PRIMITIVE_TYPE
    4265              : #undef DEF_FUNCTION_TYPE_0
    4266              : #undef DEF_FUNCTION_TYPE_1
    4267              : #undef DEF_FUNCTION_TYPE_2
    4268              : #undef DEF_FUNCTION_TYPE_3
    4269              : #undef DEF_FUNCTION_TYPE_4
    4270              : #undef DEF_FUNCTION_TYPE_5
    4271              : #undef DEF_FUNCTION_TYPE_6
    4272              : #undef DEF_FUNCTION_TYPE_7
    4273              : #undef DEF_FUNCTION_TYPE_8
    4274              : #undef DEF_FUNCTION_TYPE_9
    4275              : #undef DEF_FUNCTION_TYPE_10
    4276              : #undef DEF_FUNCTION_TYPE_11
    4277              : #undef DEF_FUNCTION_TYPE_VAR_0
    4278              : #undef DEF_FUNCTION_TYPE_VAR_1
    4279              : #undef DEF_FUNCTION_TYPE_VAR_2
    4280              : #undef DEF_FUNCTION_TYPE_VAR_3
    4281              : #undef DEF_FUNCTION_TYPE_VAR_4
    4282              : #undef DEF_FUNCTION_TYPE_VAR_5
    4283              : #undef DEF_FUNCTION_TYPE_VAR_6
    4284              : #undef DEF_FUNCTION_TYPE_VAR_7
    4285              : #undef DEF_POINTER_TYPE
    4286              :   BT_LAST
    4287              : };
    4288              : 
    4289              : typedef enum c_builtin_type builtin_type;
    4290              : 
    4291              : /* A temporary array for c_common_nodes_and_builtins.  Used in
    4292              :    communication with def_fn_type.  */
    4293              : static tree builtin_types[(int) BT_LAST + 1];
    4294              : 
    4295              : /* A helper function for c_common_nodes_and_builtins.  Build function type
    4296              :    for DEF with return type RET and N arguments.  If VAR is true, then the
    4297              :    function should be variadic after those N arguments, or, if N is zero,
    4298              :    unprototyped.
    4299              : 
    4300              :    Takes special care not to ICE if any of the types involved are
    4301              :    error_mark_node, which indicates that said type is not in fact available
    4302              :    (see builtin_type_for_size).  In which case the function type as a whole
    4303              :    should be error_mark_node.  */
    4304              : 
    4305              : static void
    4306    109235035 : def_fn_type (builtin_type def, builtin_type ret, bool var, int n, ...)
    4307              : {
    4308    109235035 :   tree t;
    4309    109235035 :   tree *args = XALLOCAVEC (tree, n);
    4310    109235035 :   va_list list;
    4311    109235035 :   int i;
    4312              : 
    4313    109235035 :   va_start (list, n);
    4314    345778197 :   for (i = 0; i < n; ++i)
    4315              :     {
    4316    239619808 :       builtin_type a = (builtin_type) va_arg (list, int);
    4317    239619808 :       t = builtin_types[a];
    4318    239619808 :       if (t == error_mark_node)
    4319      3076646 :         goto egress;
    4320    236543162 :       args[i] = t;
    4321              :     }
    4322              : 
    4323    106158389 :   t = builtin_types[ret];
    4324    106158389 :   if (t == error_mark_node)
    4325       437986 :     goto egress;
    4326    105720403 :   if (var)
    4327      6483838 :     if (n == 0)
    4328       865228 :       t = build_function_type (t, NULL_TREE);
    4329              :     else
    4330      5618610 :       t = build_varargs_function_type_array (t, n, args);
    4331              :   else
    4332     99236565 :     t = build_function_type_array (t, n, args);
    4333              : 
    4334    109235035 :  egress:
    4335    109235035 :   builtin_types[def] = t;
    4336    109235035 :   va_end (list);
    4337    109235035 : }
    4338              : 
    4339              : /* Build builtin functions common to both C and C++ language
    4340              :    frontends.  */
    4341              : 
    4342              : static void
    4343       216307 : c_define_builtins (tree va_list_ref_type_node, tree va_list_arg_type_node)
    4344              : {
    4345              : #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
    4346              :   builtin_types[ENUM] = VALUE;
    4347              : #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
    4348              :   def_fn_type (ENUM, RETURN, 0, 0);
    4349              : #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
    4350              :   def_fn_type (ENUM, RETURN, 0, 1, ARG1);
    4351              : #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
    4352              :   def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
    4353              : #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
    4354              :   def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
    4355              : #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
    4356              :   def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
    4357              : #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
    4358              :   def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
    4359              : #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4360              :                             ARG6)                                       \
    4361              :   def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
    4362              : #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4363              :                             ARG6, ARG7)                                 \
    4364              :   def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
    4365              : #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4366              :                             ARG6, ARG7, ARG8)                           \
    4367              :   def_fn_type (ENUM, RETURN, 0, 8, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6,  \
    4368              :                ARG7, ARG8);
    4369              : #define DEF_FUNCTION_TYPE_9(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4370              :                             ARG6, ARG7, ARG8, ARG9)                     \
    4371              :   def_fn_type (ENUM, RETURN, 0, 9, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6,  \
    4372              :                ARG7, ARG8, ARG9);
    4373              : #define DEF_FUNCTION_TYPE_10(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4374              :                              ARG6, ARG7, ARG8, ARG9, ARG10)              \
    4375              :   def_fn_type (ENUM, RETURN, 0, 10, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6,  \
    4376              :                ARG7, ARG8, ARG9, ARG10);
    4377              : #define DEF_FUNCTION_TYPE_11(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4378              :                              ARG6, ARG7, ARG8, ARG9, ARG10, ARG11)       \
    4379              :   def_fn_type (ENUM, RETURN, 0, 11, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6,  \
    4380              :                ARG7, ARG8, ARG9, ARG10, ARG11);
    4381              : #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
    4382              :   def_fn_type (ENUM, RETURN, 1, 0);
    4383              : #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
    4384              :   def_fn_type (ENUM, RETURN, 1, 1, ARG1);
    4385              : #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
    4386              :   def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
    4387              : #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
    4388              :   def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
    4389              : #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
    4390              :   def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
    4391              : #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
    4392              :   def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
    4393              : #define DEF_FUNCTION_TYPE_VAR_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4394              :                                 ARG6) \
    4395              :   def_fn_type (ENUM, RETURN, 1, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
    4396              : #define DEF_FUNCTION_TYPE_VAR_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4397              :                                 ARG6, ARG7)                             \
    4398              :   def_fn_type (ENUM, RETURN, 1, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
    4399              : #define DEF_POINTER_TYPE(ENUM, TYPE) \
    4400              :   builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
    4401              : 
    4402              : #include "builtin-types.def"
    4403              : 
    4404              : #undef DEF_PRIMITIVE_TYPE
    4405              : #undef DEF_FUNCTION_TYPE_0
    4406              : #undef DEF_FUNCTION_TYPE_1
    4407              : #undef DEF_FUNCTION_TYPE_2
    4408              : #undef DEF_FUNCTION_TYPE_3
    4409              : #undef DEF_FUNCTION_TYPE_4
    4410              : #undef DEF_FUNCTION_TYPE_5
    4411              : #undef DEF_FUNCTION_TYPE_6
    4412              : #undef DEF_FUNCTION_TYPE_7
    4413              : #undef DEF_FUNCTION_TYPE_8
    4414              : #undef DEF_FUNCTION_TYPE_9
    4415              : #undef DEF_FUNCTION_TYPE_10
    4416              : #undef DEF_FUNCTION_TYPE_11
    4417              : #undef DEF_FUNCTION_TYPE_VAR_0
    4418              : #undef DEF_FUNCTION_TYPE_VAR_1
    4419              : #undef DEF_FUNCTION_TYPE_VAR_2
    4420              : #undef DEF_FUNCTION_TYPE_VAR_3
    4421              : #undef DEF_FUNCTION_TYPE_VAR_4
    4422              : #undef DEF_FUNCTION_TYPE_VAR_5
    4423              : #undef DEF_FUNCTION_TYPE_VAR_6
    4424              : #undef DEF_FUNCTION_TYPE_VAR_7
    4425              : #undef DEF_POINTER_TYPE
    4426       216307 :   builtin_types[(int) BT_LAST] = NULL_TREE;
    4427              : 
    4428       216307 :   c_init_attributes ();
    4429              : 
    4430              : #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P, \
    4431              :                     NONANSI_P, ATTRS, IMPLICIT, COND)                   \
    4432              :   if (NAME && COND)                                                     \
    4433              :     def_builtin_1 (ENUM, NAME, CLASS,                                   \
    4434              :                    builtin_types[(int) TYPE],                           \
    4435              :                    builtin_types[(int) LIBTYPE],                        \
    4436              :                    BOTH_P, FALLBACK_P, NONANSI_P,                       \
    4437              :                    built_in_attributes[(int) ATTRS], IMPLICIT);
    4438              : #include "builtins.def"
    4439              : 
    4440       216307 :   targetm.init_builtins ();
    4441              : 
    4442       216307 :   build_common_builtin_nodes ();
    4443       216307 : }
    4444              : 
    4445              : /* Like get_identifier, but avoid warnings about null arguments when
    4446              :    the argument may be NULL for targets where GCC lacks stdint.h type
    4447              :    information.  */
    4448              : 
    4449              : static inline tree
    4450      5840289 : c_get_ident (const char *id)
    4451              : {
    4452      2595684 :   return get_identifier (id);
    4453              : }
    4454              : 
    4455              : /* Build tree nodes and builtin functions common to both C and C++ language
    4456              :    frontends.  */
    4457              : 
    4458              : void
    4459       216307 : c_common_nodes_and_builtins (void)
    4460              : {
    4461       216307 :   int char8_type_size;
    4462       216307 :   int char16_type_size;
    4463       216307 :   int char32_type_size;
    4464       216307 :   int wchar_type_size;
    4465       216307 :   tree array_domain_type;
    4466       216307 :   tree va_list_ref_type_node;
    4467       216307 :   tree va_list_arg_type_node;
    4468       216307 :   int i;
    4469              : 
    4470       216307 :   build_common_tree_nodes (flag_signed_char);
    4471              : 
    4472              :   /* Define `int' and `char' first so that dbx will output them first.  */
    4473       216307 :   record_builtin_type (RID_INT, NULL, integer_type_node);
    4474       216307 :   record_builtin_type (RID_CHAR, "char", char_type_node);
    4475              : 
    4476              :   /* `signed' is the same as `int'.  FIXME: the declarations of "signed",
    4477              :      "unsigned long", "long long unsigned" and "unsigned short" were in C++
    4478              :      but not C.  Are the conditionals here needed?  */
    4479       216307 :   if (c_dialect_cxx ())
    4480        99679 :     record_builtin_type (RID_SIGNED, NULL, integer_type_node);
    4481       216307 :   record_builtin_type (RID_LONG, "long int", long_integer_type_node);
    4482       216307 :   record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node);
    4483       216307 :   record_builtin_type (RID_MAX, "long unsigned int",
    4484              :                        long_unsigned_type_node);
    4485              : 
    4486       432614 :   for (i = 0; i < NUM_INT_N_ENTS; i ++)
    4487              :     {
    4488       216307 :       char name[25];
    4489              : 
    4490       216307 :       sprintf (name, "__int%d", int_n_data[i].bitsize);
    4491       216307 :       record_builtin_type ((enum rid)(RID_FIRST_INT_N + i), name,
    4492              :                            int_n_trees[i].signed_type);
    4493       216307 :       sprintf (name, "__int%d__", int_n_data[i].bitsize);
    4494       216307 :       record_builtin_type ((enum rid)(RID_FIRST_INT_N + i), name,
    4495              :                            int_n_trees[i].signed_type);
    4496       432614 :       ridpointers[RID_FIRST_INT_N + i]
    4497       216307 :         = DECL_NAME (TYPE_NAME (int_n_trees[i].signed_type));
    4498              : 
    4499       216307 :       sprintf (name, "__int%d unsigned", int_n_data[i].bitsize);
    4500       216307 :       record_builtin_type (RID_MAX, name, int_n_trees[i].unsigned_type);
    4501       216307 :       sprintf (name, "__int%d__ unsigned", int_n_data[i].bitsize);
    4502       216307 :       record_builtin_type (RID_MAX, name, int_n_trees[i].unsigned_type);
    4503              :     }
    4504              : 
    4505       216307 :   if (c_dialect_cxx ())
    4506        99679 :     record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node);
    4507       216307 :   record_builtin_type (RID_MAX, "long long int",
    4508              :                        long_long_integer_type_node);
    4509       216307 :   record_builtin_type (RID_MAX, "long long unsigned int",
    4510              :                        long_long_unsigned_type_node);
    4511       216307 :   if (c_dialect_cxx ())
    4512        99679 :     record_builtin_type (RID_MAX, "long long unsigned",
    4513              :                          long_long_unsigned_type_node);
    4514       216307 :   record_builtin_type (RID_SHORT, "short int", short_integer_type_node);
    4515       216307 :   record_builtin_type (RID_MAX, "short unsigned int",
    4516              :                        short_unsigned_type_node);
    4517       216307 :   if (c_dialect_cxx ())
    4518        99679 :     record_builtin_type (RID_MAX, "unsigned short",
    4519              :                          short_unsigned_type_node);
    4520              : 
    4521              :   /* Define both `signed char' and `unsigned char'.  */
    4522       216307 :   record_builtin_type (RID_MAX, "signed char", signed_char_type_node);
    4523       216307 :   record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node);
    4524              : 
    4525              :   /* These are types that c_common_type_for_size and
    4526              :      c_common_type_for_mode use.  */
    4527       216307 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4528              :                                          TYPE_DECL, NULL_TREE,
    4529              :                                          intQI_type_node));
    4530       216307 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4531              :                                          TYPE_DECL, NULL_TREE,
    4532              :                                          intHI_type_node));
    4533       216307 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4534              :                                          TYPE_DECL, NULL_TREE,
    4535              :                                          intSI_type_node));
    4536       216307 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4537              :                                          TYPE_DECL, NULL_TREE,
    4538              :                                          intDI_type_node));
    4539              : #if HOST_BITS_PER_WIDE_INT >= 64
    4540              :   /* Note that this is different than the __int128 type that's part of
    4541              :      the generic __intN support.  */
    4542       216307 :   if (targetm.scalar_mode_supported_p (TImode))
    4543       210935 :     lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4544              :                                            TYPE_DECL,
    4545              :                                            get_identifier ("__int128_t"),
    4546              :                                            intTI_type_node));
    4547              : #endif
    4548       216307 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4549              :                                          TYPE_DECL, NULL_TREE,
    4550              :                                          unsigned_intQI_type_node));
    4551       216307 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4552              :                                          TYPE_DECL, NULL_TREE,
    4553              :                                          unsigned_intHI_type_node));
    4554       216307 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4555              :                                          TYPE_DECL, NULL_TREE,
    4556              :                                          unsigned_intSI_type_node));
    4557       216307 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4558              :                                          TYPE_DECL, NULL_TREE,
    4559              :                                          unsigned_intDI_type_node));
    4560              : #if HOST_BITS_PER_WIDE_INT >= 64
    4561       216307 :   if (targetm.scalar_mode_supported_p (TImode))
    4562       210935 :     lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4563              :                                            TYPE_DECL,
    4564              :                                            get_identifier ("__uint128_t"),
    4565              :                                            unsigned_intTI_type_node));
    4566              : #endif
    4567              : 
    4568              :   /* Create the widest literal types.  */
    4569       216307 :   if (targetm.scalar_mode_supported_p (TImode))
    4570              :     {
    4571       210935 :       widest_integer_literal_type_node = intTI_type_node;
    4572       210935 :       widest_unsigned_literal_type_node = unsigned_intTI_type_node;
    4573              :     }
    4574              :   else
    4575              :     {
    4576         5372 :       widest_integer_literal_type_node = intDI_type_node;
    4577         5372 :       widest_unsigned_literal_type_node = unsigned_intDI_type_node;
    4578              :     }
    4579              : 
    4580       216307 :   signed_size_type_node = c_common_signed_type (size_type_node);
    4581              : 
    4582       432614 :   pid_type_node =
    4583       216307 :     TREE_TYPE (identifier_global_value (get_identifier (PID_TYPE)));
    4584              : 
    4585       216307 :   record_builtin_type (RID_FLOAT, NULL, float_type_node);
    4586       216307 :   record_builtin_type (RID_DOUBLE, NULL, double_type_node);
    4587       216307 :   record_builtin_type (RID_MAX, "long double", long_double_type_node);
    4588              : 
    4589      1946763 :   for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
    4590              :     {
    4591      1514149 :       if (FLOATN_NX_TYPE_NODE (i) != NULL_TREE)
    4592      1297842 :         record_builtin_type ((enum rid) (RID_FLOATN_NX_FIRST + i), NULL,
    4593              :                              FLOATN_NX_TYPE_NODE (i));
    4594              :     }
    4595              : 
    4596              :   /* For C, let float128t_type_node (__float128 in some backends) be the
    4597              :      same type as float128_type_node (_Float128), for C++ let those
    4598              :      be distinct types that mangle and behave differently.  */
    4599       216307 :   if (c_dialect_cxx ())
    4600        99679 :     float128t_type_node = NULL_TREE;
    4601              : 
    4602              :   /* Only supported decimal floating point extension if the target
    4603              :      actually supports underlying modes. */
    4604       216307 :   if (targetm.scalar_mode_supported_p (SDmode)
    4605       216307 :       && targetm.scalar_mode_supported_p (DDmode)
    4606       432614 :       && targetm.scalar_mode_supported_p (TDmode))
    4607              :     {
    4608       216307 :       record_builtin_type (RID_DFLOAT32, NULL, dfloat32_type_node);
    4609       216307 :       record_builtin_type (RID_DFLOAT64, NULL, dfloat64_type_node);
    4610       216307 :       record_builtin_type (RID_DFLOAT128, NULL, dfloat128_type_node);
    4611       216307 :       record_builtin_type (RID_DFLOAT64X, NULL, dfloat64x_type_node);
    4612              :     }
    4613              : 
    4614       216307 :   if (targetm.fixed_point_supported_p ())
    4615              :     {
    4616            0 :       record_builtin_type (RID_MAX, "short _Fract", short_fract_type_node);
    4617            0 :       record_builtin_type (RID_FRACT, NULL, fract_type_node);
    4618            0 :       record_builtin_type (RID_MAX, "long _Fract", long_fract_type_node);
    4619            0 :       record_builtin_type (RID_MAX, "long long _Fract",
    4620              :                            long_long_fract_type_node);
    4621            0 :       record_builtin_type (RID_MAX, "unsigned short _Fract",
    4622              :                            unsigned_short_fract_type_node);
    4623            0 :       record_builtin_type (RID_MAX, "unsigned _Fract",
    4624              :                            unsigned_fract_type_node);
    4625            0 :       record_builtin_type (RID_MAX, "unsigned long _Fract",
    4626              :                            unsigned_long_fract_type_node);
    4627            0 :       record_builtin_type (RID_MAX, "unsigned long long _Fract",
    4628              :                            unsigned_long_long_fract_type_node);
    4629            0 :       record_builtin_type (RID_MAX, "_Sat short _Fract",
    4630              :                            sat_short_fract_type_node);
    4631            0 :       record_builtin_type (RID_MAX, "_Sat _Fract", sat_fract_type_node);
    4632            0 :       record_builtin_type (RID_MAX, "_Sat long _Fract",
    4633              :                            sat_long_fract_type_node);
    4634            0 :       record_builtin_type (RID_MAX, "_Sat long long _Fract",
    4635              :                            sat_long_long_fract_type_node);
    4636            0 :       record_builtin_type (RID_MAX, "_Sat unsigned short _Fract",
    4637              :                            sat_unsigned_short_fract_type_node);
    4638            0 :       record_builtin_type (RID_MAX, "_Sat unsigned _Fract",
    4639              :                            sat_unsigned_fract_type_node);
    4640            0 :       record_builtin_type (RID_MAX, "_Sat unsigned long _Fract",
    4641              :                            sat_unsigned_long_fract_type_node);
    4642            0 :       record_builtin_type (RID_MAX, "_Sat unsigned long long _Fract",
    4643              :                            sat_unsigned_long_long_fract_type_node);
    4644            0 :       record_builtin_type (RID_MAX, "short _Accum", short_accum_type_node);
    4645            0 :       record_builtin_type (RID_ACCUM, NULL, accum_type_node);
    4646            0 :       record_builtin_type (RID_MAX, "long _Accum", long_accum_type_node);
    4647            0 :       record_builtin_type (RID_MAX, "long long _Accum",
    4648              :                            long_long_accum_type_node);
    4649            0 :       record_builtin_type (RID_MAX, "unsigned short _Accum",
    4650              :                            unsigned_short_accum_type_node);
    4651            0 :       record_builtin_type (RID_MAX, "unsigned _Accum",
    4652              :                            unsigned_accum_type_node);
    4653            0 :       record_builtin_type (RID_MAX, "unsigned long _Accum",
    4654              :                            unsigned_long_accum_type_node);
    4655            0 :       record_builtin_type (RID_MAX, "unsigned long long _Accum",
    4656              :                            unsigned_long_long_accum_type_node);
    4657            0 :       record_builtin_type (RID_MAX, "_Sat short _Accum",
    4658              :                            sat_short_accum_type_node);
    4659            0 :       record_builtin_type (RID_MAX, "_Sat _Accum", sat_accum_type_node);
    4660            0 :       record_builtin_type (RID_MAX, "_Sat long _Accum",
    4661              :                            sat_long_accum_type_node);
    4662            0 :       record_builtin_type (RID_MAX, "_Sat long long _Accum",
    4663              :                           sat_long_long_accum_type_node);
    4664            0 :       record_builtin_type (RID_MAX, "_Sat unsigned short _Accum",
    4665              :                            sat_unsigned_short_accum_type_node);
    4666            0 :       record_builtin_type (RID_MAX, "_Sat unsigned _Accum",
    4667              :                            sat_unsigned_accum_type_node);
    4668            0 :       record_builtin_type (RID_MAX, "_Sat unsigned long _Accum",
    4669              :                            sat_unsigned_long_accum_type_node);
    4670            0 :       record_builtin_type (RID_MAX, "_Sat unsigned long long _Accum",
    4671              :                            sat_unsigned_long_long_accum_type_node);
    4672              : 
    4673              :     }
    4674              : 
    4675       216307 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4676              :                                          TYPE_DECL,
    4677              :                                          get_identifier ("complex int"),
    4678              :                                          complex_integer_type_node));
    4679       216307 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4680              :                                          TYPE_DECL,
    4681              :                                          get_identifier ("complex float"),
    4682              :                                          complex_float_type_node));
    4683       216307 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4684              :                                          TYPE_DECL,
    4685              :                                          get_identifier ("complex double"),
    4686              :                                          complex_double_type_node));
    4687       216307 :   lang_hooks.decls.pushdecl
    4688       216307 :     (build_decl (UNKNOWN_LOCATION,
    4689              :                  TYPE_DECL, get_identifier ("complex long double"),
    4690              :                  complex_long_double_type_node));
    4691              : 
    4692       216307 :   if (!c_dialect_cxx ())
    4693       933024 :     for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
    4694       816396 :       if (COMPLEX_FLOATN_NX_TYPE_NODE (i) != NULL_TREE)
    4695              :         {
    4696       699768 :           char buf[30];
    4697      1399536 :           sprintf (buf, "complex _Float%d%s", floatn_nx_types[i].n,
    4698       699768 :                    floatn_nx_types[i].extended ? "x" : "");
    4699       699768 :           lang_hooks.decls.pushdecl
    4700       699768 :             (build_decl (UNKNOWN_LOCATION,
    4701              :                          TYPE_DECL,
    4702              :                          get_identifier (buf),
    4703              :                          COMPLEX_FLOATN_NX_TYPE_NODE (i)));
    4704              :         }
    4705              : 
    4706              :   /* Make fileptr_type_node a distinct void * type until
    4707              :      FILE type is defined.  Likewise for const struct tm*.  */
    4708      1514149 :   for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
    4709      1297842 :     builtin_structptr_types[i].node
    4710      1297842 :       = build_variant_type_copy (builtin_structptr_types[i].base);
    4711              : 
    4712       216307 :   record_builtin_type (RID_VOID, NULL, void_type_node);
    4713              : 
    4714              :   /* Set the TYPE_NAME for any variants that were built before
    4715              :      record_builtin_type gave names to the built-in types. */
    4716       216307 :   {
    4717       216307 :     tree void_name = TYPE_NAME (void_type_node);
    4718       216307 :     TYPE_NAME (void_type_node) = NULL_TREE;
    4719       216307 :     TYPE_NAME (build_qualified_type (void_type_node, TYPE_QUAL_CONST))
    4720       216307 :       = void_name;
    4721       216307 :     TYPE_NAME (void_type_node) = void_name;
    4722              :   }
    4723              : 
    4724              :   /* Make a type to be the domain of a few array types
    4725              :      whose domains don't really matter.
    4726              :      200 is small enough that it always fits in size_t
    4727              :      and large enough that it can hold most function names for the
    4728              :      initializations of __FUNCTION__ and __PRETTY_FUNCTION__.  */
    4729       216307 :   array_domain_type = build_index_type (size_int (200));
    4730              : 
    4731              :   /* Make a type for arrays of characters.
    4732              :      With luck nothing will ever really depend on the length of this
    4733              :      array type.  */
    4734       216307 :   char_array_type_node
    4735       216307 :     = build_array_type (char_type_node, array_domain_type);
    4736              : 
    4737       216307 :   string_type_node = build_pointer_type (char_type_node);
    4738       216307 :   const_string_type_node
    4739       216307 :     = build_pointer_type (build_qualified_type
    4740              :                           (char_type_node, TYPE_QUAL_CONST));
    4741              : 
    4742              :   /* This is special for C++ so functions can be overloaded.  */
    4743       221781 :   wchar_type_node = get_identifier (MODIFIED_WCHAR_TYPE);
    4744       216307 :   wchar_type_node = TREE_TYPE (identifier_global_value (wchar_type_node));
    4745       216307 :   wchar_type_size = TYPE_PRECISION (wchar_type_node);
    4746       216307 :   underlying_wchar_type_node = wchar_type_node;
    4747       216307 :   if (c_dialect_cxx ())
    4748              :     {
    4749        99679 :       if (TYPE_UNSIGNED (wchar_type_node))
    4750            7 :         wchar_type_node = make_unsigned_type (wchar_type_size);
    4751              :       else
    4752        99672 :         wchar_type_node = make_signed_type (wchar_type_size);
    4753        99679 :       record_builtin_type (RID_WCHAR, "wchar_t", wchar_type_node);
    4754              :     }
    4755              : 
    4756              :   /* This is for wide string constants.  */
    4757       216307 :   wchar_array_type_node
    4758       216307 :     = build_array_type (wchar_type_node, array_domain_type);
    4759              : 
    4760              :   /* Define 'char8_t'.  */
    4761       216307 :   char8_type_node = get_identifier (CHAR8_TYPE);
    4762       216307 :   char8_type_node = TREE_TYPE (identifier_global_value (char8_type_node));
    4763       216307 :   char8_type_size = TYPE_PRECISION (char8_type_node);
    4764       216307 :   if (c_dialect_cxx ())
    4765              :     {
    4766        99679 :       char8_type_node = make_unsigned_type (char8_type_size);
    4767        99679 :       TYPE_STRING_FLAG (char8_type_node) = true;
    4768              : 
    4769        99679 :       if (flag_char8_t)
    4770        74342 :         record_builtin_type (RID_CHAR8, "char8_t", char8_type_node);
    4771              :     }
    4772              : 
    4773              :   /* This is for UTF-8 string constants.  */
    4774       216307 :   char8_array_type_node
    4775       216307 :     = build_array_type (char8_type_node, array_domain_type);
    4776              : 
    4777              :   /* Define 'char16_t'.  */
    4778       216307 :   char16_type_node = get_identifier (CHAR16_TYPE);
    4779       216307 :   char16_type_node = TREE_TYPE (identifier_global_value (char16_type_node));
    4780       216307 :   char16_type_size = TYPE_PRECISION (char16_type_node);
    4781       216307 :   if (c_dialect_cxx ())
    4782              :     {
    4783        99679 :       char16_type_node = make_unsigned_type (char16_type_size);
    4784              : 
    4785        99679 :       if (cxx_dialect >= cxx11)
    4786        85494 :         record_builtin_type (RID_CHAR16, "char16_t", char16_type_node);
    4787              :     }
    4788              : 
    4789              :   /* This is for UTF-16 string constants.  */
    4790       216307 :   char16_array_type_node
    4791       216307 :     = build_array_type (char16_type_node, array_domain_type);
    4792              : 
    4793              :   /* Define 'char32_t'.  */
    4794       216307 :   char32_type_node = get_identifier (CHAR32_TYPE);
    4795       216307 :   char32_type_node = TREE_TYPE (identifier_global_value (char32_type_node));
    4796       216307 :   char32_type_size = TYPE_PRECISION (char32_type_node);
    4797       216307 :   if (c_dialect_cxx ())
    4798              :     {
    4799        99679 :       char32_type_node = make_unsigned_type (char32_type_size);
    4800              : 
    4801        99679 :       if (cxx_dialect >= cxx11)
    4802        85494 :         record_builtin_type (RID_CHAR32, "char32_t", char32_type_node);
    4803              :     }
    4804              : 
    4805              :   /* This is for UTF-32 string constants.  */
    4806       216307 :   char32_array_type_node
    4807       216307 :     = build_array_type (char32_type_node, array_domain_type);
    4808              : 
    4809       216307 :   if (strcmp (WINT_TYPE, "wchar_t") == 0)
    4810              :     wint_type_node = wchar_type_node;
    4811              :   else
    4812       432614 :     wint_type_node =
    4813       216307 :       TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE)));
    4814              : 
    4815       432614 :   intmax_type_node =
    4816       221781 :     TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE)));
    4817       432614 :   uintmax_type_node =
    4818       221781 :     TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE)));
    4819              : 
    4820       216307 :   if (SIG_ATOMIC_TYPE)
    4821       216307 :     sig_atomic_type_node =
    4822       216307 :       TREE_TYPE (identifier_global_value (c_get_ident (SIG_ATOMIC_TYPE)));
    4823       216307 :   if (INT8_TYPE)
    4824       216307 :     int8_type_node =
    4825       216307 :       TREE_TYPE (identifier_global_value (c_get_ident (INT8_TYPE)));
    4826       216307 :   if (INT16_TYPE)
    4827       216307 :     int16_type_node =
    4828       216307 :       TREE_TYPE (identifier_global_value (c_get_ident (INT16_TYPE)));
    4829       216307 :   if (INT32_TYPE)
    4830       216307 :     int32_type_node =
    4831       216307 :       TREE_TYPE (identifier_global_value (c_get_ident (INT32_TYPE)));
    4832       216307 :   if (INT64_TYPE)
    4833       432614 :     int64_type_node =
    4834       432614 :       TREE_TYPE (identifier_global_value (c_get_ident (INT64_TYPE)));
    4835       216307 :   if (UINT8_TYPE)
    4836       216307 :     uint8_type_node =
    4837       216307 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT8_TYPE)));
    4838       216307 :   if (UINT16_TYPE)
    4839       216307 :     c_uint16_type_node = uint16_type_node =
    4840       216307 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT16_TYPE)));
    4841       216307 :   if (UINT32_TYPE)
    4842       216307 :     c_uint32_type_node = uint32_type_node =
    4843       216307 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT32_TYPE)));
    4844       216307 :   if (UINT64_TYPE)
    4845       432614 :     c_uint64_type_node = uint64_type_node =
    4846       432614 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT64_TYPE)));
    4847       216307 :   if (INT_LEAST8_TYPE)
    4848       216307 :     int_least8_type_node =
    4849       216307 :       TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST8_TYPE)));
    4850       216307 :   if (INT_LEAST16_TYPE)
    4851       216307 :     int_least16_type_node =
    4852       216307 :       TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST16_TYPE)));
    4853       216307 :   if (INT_LEAST32_TYPE)
    4854       216307 :     int_least32_type_node =
    4855       216307 :       TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST32_TYPE)));
    4856       216307 :   if (INT_LEAST64_TYPE)
    4857       432614 :     int_least64_type_node =
    4858       432614 :       TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST64_TYPE)));
    4859       216307 :   if (UINT_LEAST8_TYPE)
    4860       216307 :     uint_least8_type_node =
    4861       216307 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST8_TYPE)));
    4862       216307 :   if (UINT_LEAST16_TYPE)
    4863       216307 :     uint_least16_type_node =
    4864       216307 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST16_TYPE)));
    4865       216307 :   if (UINT_LEAST32_TYPE)
    4866       216307 :     uint_least32_type_node =
    4867       216307 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST32_TYPE)));
    4868       216307 :   if (UINT_LEAST64_TYPE)
    4869       432614 :     uint_least64_type_node =
    4870       432614 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST64_TYPE)));
    4871       216307 :   if (INT_FAST8_TYPE)
    4872       216307 :     int_fast8_type_node =
    4873       216307 :       TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST8_TYPE)));
    4874       216307 :   if (INT_FAST16_TYPE)
    4875       432614 :     int_fast16_type_node =
    4876       432614 :       TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST16_TYPE)));
    4877       216307 :   if (INT_FAST32_TYPE)
    4878       432614 :     int_fast32_type_node =
    4879       432614 :       TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST32_TYPE)));
    4880       216307 :   if (INT_FAST64_TYPE)
    4881       432614 :     int_fast64_type_node =
    4882       432614 :       TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST64_TYPE)));
    4883       216307 :   if (UINT_FAST8_TYPE)
    4884       216307 :     uint_fast8_type_node =
    4885       216307 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST8_TYPE)));
    4886       216307 :   if (UINT_FAST16_TYPE)
    4887       432614 :     uint_fast16_type_node =
    4888       432614 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST16_TYPE)));
    4889       216307 :   if (UINT_FAST32_TYPE)
    4890       432614 :     uint_fast32_type_node =
    4891       432614 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST32_TYPE)));
    4892       216307 :   if (UINT_FAST64_TYPE)
    4893       432614 :     uint_fast64_type_node =
    4894       432614 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST64_TYPE)));
    4895       216307 :   if (INTPTR_TYPE)
    4896       432614 :     intptr_type_node =
    4897       432614 :       TREE_TYPE (identifier_global_value (c_get_ident (INTPTR_TYPE)));
    4898       216307 :   if (UINTPTR_TYPE)
    4899       432614 :     uintptr_type_node =
    4900       432614 :       TREE_TYPE (identifier_global_value (c_get_ident (UINTPTR_TYPE)));
    4901              : 
    4902       216307 :   default_function_type = build_function_type (integer_type_node, NULL_TREE);
    4903       216307 :   unsigned_ptrdiff_type_node = c_common_unsigned_type (ptrdiff_type_node);
    4904              : 
    4905       216307 :   lang_hooks.decls.pushdecl
    4906       216307 :     (build_decl (UNKNOWN_LOCATION,
    4907              :                  TYPE_DECL, get_identifier ("__builtin_va_list"),
    4908              :                  va_list_type_node));
    4909       216307 :   if (targetm.enum_va_list_p)
    4910              :     {
    4911              :       int l;
    4912              :       const char *pname;
    4913              :       tree ptype;
    4914              : 
    4915       638177 :       for (l = 0; targetm.enum_va_list_p (l, &pname, &ptype); ++l)
    4916              :         {
    4917       421870 :           lang_hooks.decls.pushdecl
    4918       421870 :             (build_decl (UNKNOWN_LOCATION,
    4919              :                          TYPE_DECL, get_identifier (pname),
    4920              :                          ptype));
    4921              : 
    4922              :         }
    4923              :     }
    4924              : 
    4925       216307 :   if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
    4926              :     {
    4927       421786 :       va_list_arg_type_node = va_list_ref_type_node =
    4928       210893 :         build_pointer_type (TREE_TYPE (va_list_type_node));
    4929              :     }
    4930              :   else
    4931              :     {
    4932         5414 :       va_list_arg_type_node = va_list_type_node;
    4933         5414 :       va_list_ref_type_node = build_reference_type (va_list_type_node);
    4934              :     }
    4935              : 
    4936       216307 :   c_define_builtins (va_list_ref_type_node, va_list_arg_type_node);
    4937              : 
    4938       216307 :   main_identifier_node = get_identifier ("main");
    4939              : 
    4940              :   /* Create the built-in __null node.  It is important that this is
    4941              :      not shared.  */
    4942       216307 :   null_node = make_int_cst (1, 1);
    4943       221781 :   TREE_TYPE (null_node) = c_common_type_for_size (POINTER_SIZE, 0);
    4944              : 
    4945              :   /* Create the built-in nullptr node.  This part of its initialization is
    4946              :      common to C and C++.  The front ends can further adjust its definition
    4947              :      in {c,cxx}_init_decl_processing.  In particular, we aren't setting the
    4948              :      alignment here for C++ backward ABI bug compatibility.  */
    4949       216307 :   nullptr_type_node = make_node (NULLPTR_TYPE);
    4950       432614 :   TYPE_SIZE (nullptr_type_node) = bitsize_int (GET_MODE_BITSIZE (ptr_mode));
    4951       432614 :   TYPE_SIZE_UNIT (nullptr_type_node) = size_int (GET_MODE_SIZE (ptr_mode));
    4952       216307 :   TYPE_UNSIGNED (nullptr_type_node) = 1;
    4953       432614 :   TYPE_PRECISION (nullptr_type_node) = GET_MODE_BITSIZE (ptr_mode);
    4954       216307 :   SET_TYPE_MODE (nullptr_type_node, ptr_mode);
    4955       216307 :   nullptr_node = build_int_cst (nullptr_type_node, 0);
    4956              : 
    4957              :   /* Since builtin_types isn't gc'ed, don't export these nodes.  */
    4958       216307 :   memset (builtin_types, 0, sizeof (builtin_types));
    4959       216307 : }
    4960              : 
    4961              : /* The number of named compound-literals generated thus far.  */
    4962              : static GTY(()) int compound_literal_number;
    4963              : 
    4964              : /* Set DECL_NAME for DECL, a VAR_DECL for a compound-literal.  */
    4965              : 
    4966              : void
    4967          279 : set_compound_literal_name (tree decl)
    4968              : {
    4969          279 :   char *name;
    4970          279 :   ASM_FORMAT_PRIVATE_NAME (name, "__compound_literal",
    4971              :                            compound_literal_number);
    4972          279 :   compound_literal_number++;
    4973          279 :   DECL_NAME (decl) = get_identifier (name);
    4974          279 : }
    4975              : 
    4976              : /* build_va_arg helper function.  Return a VA_ARG_EXPR with location LOC, type
    4977              :    TYPE and operand OP.  */
    4978              : 
    4979              : static tree
    4980        51136 : build_va_arg_1 (location_t loc, tree type, tree op)
    4981              : {
    4982        51136 :   tree expr = build1 (VA_ARG_EXPR, type, op);
    4983        51136 :   SET_EXPR_LOCATION (expr, loc);
    4984        51136 :   return expr;
    4985              : }
    4986              : 
    4987              : /* Return a VA_ARG_EXPR corresponding to a source-level expression
    4988              :    va_arg (EXPR, TYPE) at source location LOC.  */
    4989              : 
    4990              : tree
    4991        51136 : build_va_arg (location_t loc, tree expr, tree type)
    4992              : {
    4993        51136 :   tree va_type = TREE_TYPE (expr);
    4994        51136 :   tree canon_va_type = (va_type == error_mark_node
    4995        51136 :                         ? error_mark_node
    4996        51126 :                         : targetm.canonical_va_list_type (va_type));
    4997              : 
    4998        51136 :   if (va_type == error_mark_node
    4999        51126 :       || canon_va_type == NULL_TREE)
    5000              :     {
    5001           10 :       if (canon_va_type == NULL_TREE)
    5002           12 :         error_at (loc, "first argument to %<va_arg%> not of type %<va_list%>");
    5003              : 
    5004              :       /* Let's handle things neutrally, if expr:
    5005              :          - has undeclared type, or
    5006              :          - is not an va_list type.  */
    5007           22 :       return build_va_arg_1 (loc, type, error_mark_node);
    5008              :     }
    5009              : 
    5010        51114 :   if (TREE_CODE (canon_va_type) != ARRAY_TYPE)
    5011              :     {
    5012              :       /* Case 1: Not an array type.  */
    5013              : 
    5014              :       /* Take the address, to get '&ap'.  Note that &ap is not a va_list
    5015              :          type.  */
    5016          258 :       c_common_mark_addressable_vec (expr);
    5017          258 :       expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (expr)), expr);
    5018              : 
    5019          258 :       return build_va_arg_1 (loc, type, expr);
    5020              :     }
    5021              : 
    5022              :   /* Case 2: Array type.
    5023              : 
    5024              :      Background:
    5025              : 
    5026              :      For contrast, let's start with the simple case (case 1).  If
    5027              :      canon_va_type is not an array type, but say a char *, then when
    5028              :      passing-by-value a va_list, the type of the va_list param decl is
    5029              :      the same as for another va_list decl (all ap's are char *):
    5030              : 
    5031              :      f2_1 (char * ap)
    5032              :        D.1815 = VA_ARG (&ap, 0B, 1);
    5033              :        return D.1815;
    5034              : 
    5035              :      f2 (int i)
    5036              :        char * ap.0;
    5037              :        char * ap;
    5038              :        __builtin_va_start (&ap, 0);
    5039              :        ap.0 = ap;
    5040              :        res = f2_1 (ap.0);
    5041              :        __builtin_va_end (&ap);
    5042              :        D.1812 = res;
    5043              :        return D.1812;
    5044              : 
    5045              :      However, if canon_va_type is ARRAY_TYPE, then when passing-by-value a
    5046              :      va_list the type of the va_list param decl (case 2b, struct * ap) is not
    5047              :      the same as for another va_list decl (case 2a, struct ap[1]).
    5048              : 
    5049              :      f2_1 (struct  * ap)
    5050              :        D.1844 = VA_ARG (ap, 0B, 0);
    5051              :        return D.1844;
    5052              : 
    5053              :      f2 (int i)
    5054              :        struct  ap[1];
    5055              :        __builtin_va_start (&ap, 0);
    5056              :        res = f2_1 (&ap);
    5057              :        __builtin_va_end (&ap);
    5058              :        D.1841 = res;
    5059              :        return D.1841;
    5060              : 
    5061              :      Case 2b is different because:
    5062              :      - on the callee side, the parm decl has declared type va_list, but
    5063              :        grokdeclarator changes the type of the parm decl to a pointer to the
    5064              :        array elem type.
    5065              :      - on the caller side, the pass-by-value uses &ap.
    5066              : 
    5067              :      We unify these two cases (case 2a: va_list is array type,
    5068              :      case 2b: va_list is pointer to array elem type), by adding '&' for the
    5069              :      array type case, such that we have a pointer to array elem in both
    5070              :      cases.  */
    5071              : 
    5072        50856 :   if (TREE_CODE (va_type) == ARRAY_TYPE)
    5073              :     {
    5074              :       /* Case 2a: va_list is array type.  */
    5075              : 
    5076              :       /* Take the address, to get '&ap'.  Make sure it's a pointer to array
    5077              :          elem type.  */
    5078        50109 :       c_common_mark_addressable_vec (expr);
    5079        50109 :       expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (canon_va_type)),
    5080              :                      expr);
    5081              : 
    5082              :       /* Verify that &ap is still recognized as having va_list type.  */
    5083        50109 :       tree canon_expr_type
    5084        50109 :         = targetm.canonical_va_list_type (TREE_TYPE (expr));
    5085        50109 :       gcc_assert (canon_expr_type != NULL_TREE);
    5086              :     }
    5087              :   else
    5088              :     {
    5089              :       /* Case 2b: va_list is pointer to array elem type.  */
    5090          747 :       gcc_assert (POINTER_TYPE_P (va_type));
    5091              : 
    5092              :       /* Comparison as in std_canonical_va_list_type.  */
    5093          747 :       gcc_assert (TYPE_MAIN_VARIANT (TREE_TYPE (va_type))
    5094              :                   == TYPE_MAIN_VARIANT (TREE_TYPE (canon_va_type)));
    5095              : 
    5096              :       /* Don't take the address.  We've already got '&ap'.  */
    5097        50856 :       ;
    5098              :     }
    5099              : 
    5100        50856 :   return build_va_arg_1 (loc, type, expr);
    5101              : }
    5102              : 
    5103              : 
    5104              : /* Linked list of disabled built-in functions.  */
    5105              : 
    5106              : struct disabled_builtin
    5107              : {
    5108              :   const char *name;
    5109              :   struct disabled_builtin *next;
    5110              : };
    5111              : static disabled_builtin *disabled_builtins = NULL;
    5112              : 
    5113              : static bool builtin_function_disabled_p (const char *);
    5114              : 
    5115              : /* Disable a built-in function specified by -fno-builtin-NAME.  If NAME
    5116              :    begins with "__builtin_", give an error.  */
    5117              : 
    5118              : void
    5119          308 : disable_builtin_function (const char *name)
    5120              : {
    5121          308 :   if (startswith (name, "__builtin_"))
    5122            0 :     error ("cannot disable built-in function %qs", name);
    5123              :   else
    5124              :     {
    5125          308 :       disabled_builtin *new_disabled_builtin = XNEW (disabled_builtin);
    5126          308 :       new_disabled_builtin->name = name;
    5127          308 :       new_disabled_builtin->next = disabled_builtins;
    5128          308 :       disabled_builtins = new_disabled_builtin;
    5129              :     }
    5130          308 : }
    5131              : 
    5132              : 
    5133              : /* Return true if the built-in function NAME has been disabled, false
    5134              :    otherwise.  */
    5135              : 
    5136              : static bool
    5137    166901791 : builtin_function_disabled_p (const char *name)
    5138              : {
    5139    166901791 :   disabled_builtin *p;
    5140    167186807 :   for (p = disabled_builtins; p != NULL; p = p->next)
    5141              :     {
    5142       285324 :       if (strcmp (name, p->name) == 0)
    5143              :         return true;
    5144              :     }
    5145              :   return false;
    5146              : }
    5147              : 
    5148              : 
    5149              : /* Worker for DEF_BUILTIN.
    5150              :    Possibly define a builtin function with one or two names.
    5151              :    Does not declare a non-__builtin_ function if flag_no_builtin, or if
    5152              :    nonansi_p and flag_no_nonansi_builtin.  */
    5153              : 
    5154              : static void
    5155    328085015 : def_builtin_1 (enum built_in_function fncode,
    5156              :                const char *name,
    5157              :                enum built_in_class fnclass,
    5158              :                tree fntype, tree libtype,
    5159              :                bool both_p, bool fallback_p, bool nonansi_p,
    5160              :                tree fnattrs, bool implicit_p)
    5161              : {
    5162    328085015 :   tree decl;
    5163    328085015 :   const char *libname;
    5164              : 
    5165    328085015 :   if (fntype == error_mark_node)
    5166              :     return;
    5167              : 
    5168    309299965 :   gcc_assert ((!both_p && !fallback_p)
    5169              :               || startswith (name, "__builtin_"));
    5170              : 
    5171    309299965 :   libname = name + strlen ("__builtin_");
    5172    309299965 :   decl = add_builtin_function (name, fntype, fncode, fnclass,
    5173              :                                (fallback_p ? libname : NULL),
    5174              :                                fnattrs);
    5175              : 
    5176    309299965 :   set_builtin_decl (fncode, decl, implicit_p);
    5177              : 
    5178    309299965 :   if (both_p
    5179    167341007 :       && !flag_no_builtin && !builtin_function_disabled_p (libname)
    5180    476201448 :       && !(nonansi_p && flag_no_nonansi_builtin))
    5181    150366793 :     add_builtin_function (libname, libtype, fncode, fnclass,
    5182              :                           NULL, fnattrs);
    5183              : }
    5184              : 
    5185              : /* Nonzero if the type T promotes to int.  This is (nearly) the
    5186              :    integral promotions defined in ISO C99 6.3.1.1/2.  */
    5187              : 
    5188              : bool
    5189    602546170 : c_promoting_integer_type_p (const_tree t)
    5190              : {
    5191    602546170 :   switch (TREE_CODE (t))
    5192              :     {
    5193    493779989 :     case INTEGER_TYPE:
    5194    493779989 :       return (TYPE_MAIN_VARIANT (t) == char_type_node
    5195    487446229 :               || TYPE_MAIN_VARIANT (t) == signed_char_type_node
    5196    486751759 :               || TYPE_MAIN_VARIANT (t) == unsigned_char_type_node
    5197    471379539 :               || TYPE_MAIN_VARIANT (t) == short_integer_type_node
    5198    470294315 :               || TYPE_MAIN_VARIANT (t) == short_unsigned_type_node
    5199    958213019 :               || TYPE_PRECISION (t) < TYPE_PRECISION (integer_type_node));
    5200              : 
    5201       676896 :     case ENUMERAL_TYPE:
    5202              :       /* ??? Technically all enumerations not larger than an int
    5203              :          promote to an int.  But this is used along code paths
    5204              :          that only want to notice a size change.  */
    5205       676896 :       return TYPE_PRECISION (t) < TYPE_PRECISION (integer_type_node);
    5206              : 
    5207              :     case BOOLEAN_TYPE:
    5208              :       return true;
    5209              : 
    5210              :     default:
    5211              :       return false;
    5212              :     }
    5213              : }
    5214              : 
    5215              : /* Return 1 if PARMS specifies a fixed number of parameters
    5216              :    and none of their types is affected by default promotions.  */
    5217              : 
    5218              : bool
    5219        23870 : self_promoting_args_p (const_tree parms)
    5220              : {
    5221        23870 :   const_tree t;
    5222        71108 :   for (t = parms; t; t = TREE_CHAIN (t))
    5223              :     {
    5224        47771 :       tree type = TREE_VALUE (t);
    5225              : 
    5226        47771 :       if (type == error_mark_node)
    5227            2 :         continue;
    5228              : 
    5229        47769 :       if (TREE_CHAIN (t) == NULL_TREE && type != void_type_node)
    5230              :         return false;
    5231              : 
    5232        47286 :       if (type == NULL_TREE)
    5233              :         return false;
    5234              : 
    5235        47286 :       if (TYPE_MAIN_VARIANT (type) == float_type_node)
    5236              :         return false;
    5237              : 
    5238        47241 :       if (c_promoting_integer_type_p (type))
    5239              :         return false;
    5240              :     }
    5241              :   return true;
    5242              : }
    5243              : 
    5244              : /* Recursively remove any '*' or '&' operator from TYPE.  */
    5245              : tree
    5246     29118812 : strip_pointer_operator (tree t)
    5247              : {
    5248     30014884 :   while (POINTER_TYPE_P (t))
    5249       896072 :     t = TREE_TYPE (t);
    5250     29118812 :   return t;
    5251              : }
    5252              : 
    5253              : /* Recursively remove pointer or array type from TYPE. */
    5254              : tree
    5255     12017512 : strip_pointer_or_array_types (tree t)
    5256              : {
    5257     17016070 :   while (TREE_CODE (t) == ARRAY_TYPE || POINTER_TYPE_P (t))
    5258      4998558 :     t = TREE_TYPE (t);
    5259     12017512 :   return t;
    5260              : }
    5261              : 
    5262              : /* Used to compare case labels.  K1 and K2 are actually tree nodes
    5263              :    representing case labels, or NULL_TREE for a `default' label.
    5264              :    Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after
    5265              :    K2, and 0 if K1 and K2 are equal.  */
    5266              : 
    5267              : int
    5268     23095819 : case_compare (splay_tree_key k1, splay_tree_key k2)
    5269              : {
    5270              :   /* Consider a NULL key (such as arises with a `default' label) to be
    5271              :      smaller than anything else.  */
    5272     23095819 :   if (!k1)
    5273      3302352 :     return k2 ? -1 : 0;
    5274     20399075 :   else if (!k2)
    5275              :     return k1 ? 1 : 0;
    5276              : 
    5277     19701925 :   return tree_int_cst_compare ((tree) k1, (tree) k2);
    5278              : }
    5279              : 
    5280              : /* Process a case label, located at LOC, for the range LOW_VALUE
    5281              :    ... HIGH_VALUE.  If LOW_VALUE and HIGH_VALUE are both NULL_TREE
    5282              :    then this case label is actually a `default' label.  If only
    5283              :    HIGH_VALUE is NULL_TREE, then case label was declared using the
    5284              :    usual C/C++ syntax, rather than the GNU case range extension.
    5285              :    CASES is a tree containing all the case ranges processed so far;
    5286              :    COND is the condition for the switch-statement itself.
    5287              :    Returns the CASE_LABEL_EXPR created, or ERROR_MARK_NODE if no
    5288              :    CASE_LABEL_EXPR is created.  ATTRS are the attributes to be applied
    5289              :    to the label.  */
    5290              : 
    5291              : tree
    5292      2620842 : c_add_case_label (location_t loc, splay_tree cases, tree cond,
    5293              :                   tree low_value, tree high_value, tree attrs)
    5294              : {
    5295      2620842 :   tree type;
    5296      2620842 :   tree label;
    5297      2620842 :   tree case_label;
    5298      2620842 :   splay_tree_node node;
    5299              : 
    5300              :   /* Create the LABEL_DECL itself.  */
    5301      2620842 :   label = create_artificial_label (loc);
    5302      2620842 :   decl_attributes (&label, attrs, 0);
    5303              : 
    5304              :   /* If there was an error processing the switch condition, bail now
    5305              :      before we get more confused.  */
    5306      2620842 :   if (!cond || cond == error_mark_node)
    5307            0 :     goto error_out;
    5308              : 
    5309      2351610 :   if ((low_value && TREE_TYPE (low_value)
    5310      2351610 :        && POINTER_TYPE_P (TREE_TYPE (low_value)))
    5311      4972451 :       || (high_value && TREE_TYPE (high_value)
    5312          440 :           && POINTER_TYPE_P (TREE_TYPE (high_value))))
    5313              :     {
    5314            1 :       error_at (loc, "pointers are not permitted as case values");
    5315            1 :       goto error_out;
    5316              :     }
    5317              : 
    5318              :   /* Case ranges are a GNU extension.  */
    5319      2620841 :   if (high_value)
    5320              :     {
    5321          440 :       if (c_dialect_cxx ())
    5322          126 :         pedwarn (loc, OPT_Wpedantic,
    5323              :                  "range expressions in switch statements are non-standard");
    5324          314 :       else if (warn_c23_c2y_compat > 0)
    5325              :         {
    5326           13 :           if (pedantic && !flag_isoc2y)
    5327            0 :             pedwarn (loc, OPT_Wc23_c2y_compat,
    5328              :                      "ISO C does not support range expressions in switch "
    5329              :                      "statements before C2Y");
    5330              :           else
    5331           13 :             warning_at (loc, OPT_Wc23_c2y_compat,
    5332              :                         "ISO C does not support range expressions in switch "
    5333              :                         "statements before C2Y");
    5334              :         }
    5335          301 :       else if (warn_c23_c2y_compat && pedantic && !flag_isoc2y)
    5336           28 :         pedwarn (loc, OPT_Wpedantic,
    5337              :                  "ISO C does not support range expressions in switch "
    5338              :                  "statements before C2Y");
    5339              :     }
    5340              : 
    5341      2620841 :   type = TREE_TYPE (cond);
    5342      2620841 :   if (low_value)
    5343              :     {
    5344      2351609 :       low_value = check_case_value (loc, low_value);
    5345      2351609 :       tree tem = NULL_TREE;
    5346      2351609 :       if (high_value
    5347          440 :           && !c_dialect_cxx ()
    5348          314 :           && low_value != error_mark_node
    5349          313 :           && !int_fits_type_p (low_value, type)
    5350      2352049 :           && pedwarn (loc, OPT_Wpedantic,
    5351              :                       "conversion of %qE to %qT in range expression changes "
    5352              :                       "value to %qE", low_value, type,
    5353           20 :                       (tem = fold_convert (type, low_value))))
    5354           20 :         low_value = tem;
    5355      2351609 :       low_value = convert_and_check (loc, type, low_value);
    5356      2351609 :       low_value = fold (low_value);
    5357      2351609 :       if (low_value == error_mark_node)
    5358          147 :         goto error_out;
    5359              :     }
    5360      2620694 :   if (high_value)
    5361              :     {
    5362          439 :       high_value = check_case_value (loc, high_value);
    5363          439 :       tree tem = NULL_TREE;
    5364          439 :       if (!c_dialect_cxx ()
    5365          313 :           && high_value != error_mark_node
    5366          312 :           && !int_fits_type_p (high_value, type)
    5367          752 :           && pedwarn (loc, OPT_Wpedantic,
    5368              :                       "conversion of %qE to %qT in range expression changes "
    5369              :                       "value to %qE", high_value, type,
    5370           20 :                       (tem = fold_convert (type, high_value))))
    5371           20 :         high_value = tem;
    5372          439 :       high_value = convert_and_check (loc, type, high_value);
    5373          439 :       high_value = fold (high_value);
    5374          439 :       if (high_value == error_mark_node)
    5375            4 :         goto error_out;
    5376              :     }
    5377              : 
    5378      2620690 :   if (low_value && high_value)
    5379              :     {
    5380              :       /* If the LOW_VALUE and HIGH_VALUE are the same, then this isn't
    5381              :          really a case range, even though it was written that way.
    5382              :          Remove the HIGH_VALUE to simplify later processing.  */
    5383          435 :       if (tree_int_cst_equal (low_value, high_value))
    5384              :         high_value = NULL_TREE;
    5385          416 :       else if (!tree_int_cst_lt (low_value, high_value))
    5386              :         {
    5387           28 :           warning_at (loc, 0, "empty range specified");
    5388           28 :           goto error_out;
    5389              :         }
    5390              :     }
    5391              : 
    5392              :   /* Look up the LOW_VALUE in the table of case labels we already
    5393              :      have.  */
    5394      2620662 :   node = splay_tree_lookup (cases, (splay_tree_key) low_value);
    5395              :   /* If there was not an exact match, check for overlapping ranges.
    5396              :      There's no need to do this if there's no LOW_VALUE or HIGH_VALUE;
    5397              :      that's a `default' label and the only overlap is an exact match.  */
    5398      2620662 :   if (!node && (low_value || high_value))
    5399              :     {
    5400      2351412 :       splay_tree_node low_bound;
    5401      2351412 :       splay_tree_node high_bound;
    5402              : 
    5403              :       /* Even though there wasn't an exact match, there might be an
    5404              :          overlap between this case range and another case range.
    5405              :          Since we've (inductively) not allowed any overlapping case
    5406              :          ranges, we simply need to find the greatest low case label
    5407              :          that is smaller that LOW_VALUE, and the smallest low case
    5408              :          label that is greater than LOW_VALUE.  If there is an overlap
    5409              :          it will occur in one of these two ranges.  */
    5410      2351412 :       low_bound = splay_tree_predecessor (cases,
    5411              :                                           (splay_tree_key) low_value);
    5412      2351412 :       high_bound = splay_tree_successor (cases,
    5413              :                                          (splay_tree_key) low_value);
    5414              : 
    5415              :       /* Check to see if the LOW_BOUND overlaps.  It is smaller than
    5416              :          the LOW_VALUE, so there is no need to check unless the
    5417              :          LOW_BOUND is in fact itself a case range.  */
    5418      2351412 :       if (low_bound
    5419      1567119 :           && CASE_HIGH ((tree) low_bound->value)
    5420      2351579 :           && tree_int_cst_compare (CASE_HIGH ((tree) low_bound->value),
    5421              :                                     low_value) >= 0)
    5422              :         node = low_bound;
    5423              :       /* Check to see if the HIGH_BOUND overlaps.  The low end of that
    5424              :          range is bigger than the low end of the current range, so we
    5425              :          are only interested if the current range is a real range, and
    5426              :          not an ordinary case label.  */
    5427      2351400 :       else if (high_bound
    5428      2351400 :                && high_value
    5429      2351400 :                && (tree_int_cst_compare ((tree) high_bound->key,
    5430              :                                          high_value)
    5431              :                    <= 0))
    5432              :         node = high_bound;
    5433              :     }
    5434              :   /* If there was an overlap, issue an error.  */
    5435      2620643 :   if (node)
    5436              :     {
    5437           37 :       tree duplicate = CASE_LABEL ((tree) node->value);
    5438              : 
    5439           37 :       if (high_value)
    5440              :         {
    5441           10 :           error_at (loc, "duplicate (or overlapping) case value");
    5442           10 :           inform (DECL_SOURCE_LOCATION (duplicate),
    5443              :                   "this is the first entry overlapping that value");
    5444              :         }
    5445           27 :       else if (low_value)
    5446              :         {
    5447           26 :           error_at (loc, "duplicate case value") ;
    5448           26 :           inform (DECL_SOURCE_LOCATION (duplicate), "previously used here");
    5449              :         }
    5450              :       else
    5451              :         {
    5452            1 :           error_at (loc, "multiple default labels in one switch");
    5453            1 :           inform (DECL_SOURCE_LOCATION (duplicate),
    5454              :                   "this is the first default label");
    5455              :         }
    5456           37 :       goto error_out;
    5457              :     }
    5458              : 
    5459              :   /* Add a CASE_LABEL to the statement-tree.  */
    5460      2620625 :   case_label = add_stmt (build_case_label (low_value, high_value, label));
    5461              :   /* Register this case label in the splay tree.  */
    5462      2620625 :   splay_tree_insert (cases,
    5463              :                      (splay_tree_key) low_value,
    5464              :                      (splay_tree_value) case_label);
    5465              : 
    5466      2620625 :   return case_label;
    5467              : 
    5468          217 :  error_out:
    5469              :   /* Add a label so that the back-end doesn't think that the beginning of
    5470              :      the switch is unreachable.  Note that we do not add a case label, as
    5471              :      that just leads to duplicates and thence to failure later on.  */
    5472          217 :   if (!cases->root)
    5473              :     {
    5474          153 :       tree t = create_artificial_label (loc);
    5475          153 :       add_stmt (build_stmt (loc, LABEL_EXPR, t));
    5476              :     }
    5477          217 :   return error_mark_node;
    5478              : }
    5479              : 
    5480              : /* Subroutine of c_switch_covers_all_cases_p, called via
    5481              :    splay_tree_foreach.  Return 1 if it doesn't cover all the cases.
    5482              :    ARGS[0] is initially NULL and after the first iteration is the
    5483              :    so far highest case label.  ARGS[1] is the minimum of SWITCH_COND's
    5484              :    type.  */
    5485              : 
    5486              : static int
    5487       120192 : c_switch_covers_all_cases_p_1 (splay_tree_node node, void *data)
    5488              : {
    5489       120192 :   tree label = (tree) node->value;
    5490       120192 :   tree *args = (tree *) data;
    5491              : 
    5492              :   /* If there is a default case, we shouldn't have called this.  */
    5493       120192 :   gcc_assert (CASE_LOW (label));
    5494              : 
    5495       120192 :   if (args[0] == NULL_TREE)
    5496              :     {
    5497        42901 :       if (wi::to_widest (args[1]) < wi::to_widest (CASE_LOW (label)))
    5498              :         return 1;
    5499              :     }
    5500        77291 :   else if (wi::add (wi::to_widest (args[0]), 1)
    5501       154582 :            != wi::to_widest (CASE_LOW (label)))
    5502              :     return 1;
    5503       101471 :   if (CASE_HIGH (label))
    5504          109 :     args[0] = CASE_HIGH (label);
    5505              :   else
    5506       101362 :     args[0] = CASE_LOW (label);
    5507              :   return 0;
    5508              : }
    5509              : 
    5510              : /* Return true if switch with CASES and switch condition with type
    5511              :    covers all possible values in the case labels.  */
    5512              : 
    5513              : bool
    5514        76968 : c_switch_covers_all_cases_p (splay_tree cases, tree type)
    5515              : {
    5516              :   /* If there is default:, this is always the case.  */
    5517        76968 :   splay_tree_node default_node
    5518        76968 :     = splay_tree_lookup (cases, (splay_tree_key) NULL);
    5519        76968 :   if (default_node)
    5520              :     return true;
    5521              : 
    5522        43450 :   if (!INTEGRAL_TYPE_P (type))
    5523              :     return false;
    5524              : 
    5525        43383 :   tree args[2] = { NULL_TREE, TYPE_MIN_VALUE (type) };
    5526        43383 :   if (splay_tree_foreach (cases, c_switch_covers_all_cases_p_1, args))
    5527              :     return false;
    5528              : 
    5529              :   /* If there are no cases at all, or if the highest case label
    5530              :      is smaller than TYPE_MAX_VALUE, return false.  */
    5531        24662 :   if (args[0] == NULL_TREE
    5532        24662 :       || wi::to_widest (args[0]) < wi::to_widest (TYPE_MAX_VALUE (type)))
    5533        24615 :     return false;
    5534              : 
    5535              :   return true;
    5536              : }
    5537              : 
    5538              : /* Return true if stmt can fall through.  Used by block_may_fallthru
    5539              :    default case.  */
    5540              : 
    5541              : bool
    5542      2636392 : c_block_may_fallthru (const_tree stmt)
    5543              : {
    5544      2636392 :   switch (TREE_CODE (stmt))
    5545              :     {
    5546        18575 :     case SWITCH_STMT:
    5547        18575 :       return (!SWITCH_STMT_ALL_CASES_P (stmt)
    5548          220 :               || !SWITCH_STMT_NO_BREAK_P (stmt)
    5549        18603 :               || block_may_fallthru (SWITCH_STMT_BODY (stmt)));
    5550              : 
    5551              :     default:
    5552              :       return true;
    5553              :     }
    5554              : }
    5555              : 
    5556              : /* Finish an expression taking the address of LABEL (an
    5557              :    IDENTIFIER_NODE).  Returns an expression for the address.
    5558              : 
    5559              :    LOC is the location for the expression returned.  */
    5560              : 
    5561              : tree
    5562         2155 : finish_label_address_expr (tree label, location_t loc)
    5563              : {
    5564         2155 :   tree result;
    5565              : 
    5566         2155 :   pedwarn (input_location, OPT_Wpedantic, "taking the address of a label is non-standard");
    5567              : 
    5568         2155 :   if (label == error_mark_node)
    5569              :     return error_mark_node;
    5570              : 
    5571         2149 :   label = lookup_label (label);
    5572         2149 :   if (label == NULL_TREE)
    5573            5 :     result = null_pointer_node;
    5574              :   else
    5575              :     {
    5576         2144 :       TREE_USED (label) = 1;
    5577         2144 :       result = build1 (ADDR_EXPR, ptr_type_node, label);
    5578              :       /* The current function is not necessarily uninlinable.
    5579              :          Computed gotos are incompatible with inlining, but the value
    5580              :          here could be used only in a diagnostic, for example.  */
    5581         2144 :       protected_set_expr_location (result, loc);
    5582              :     }
    5583              : 
    5584              :   return result;
    5585              : }
    5586              : 
    5587              : 
    5588              : /* Given a boolean expression ARG, return a tree representing an increment
    5589              :    or decrement (as indicated by CODE) of ARG.  The front end must check for
    5590              :    invalid cases (e.g., decrement in C++).  */
    5591              : tree
    5592           93 : boolean_increment (enum tree_code code, tree arg)
    5593              : {
    5594           93 :   tree val;
    5595           93 :   tree true_res = build_int_cst (TREE_TYPE (arg), 1);
    5596              : 
    5597           93 :   arg = stabilize_reference (arg);
    5598           93 :   switch (code)
    5599              :     {
    5600           28 :     case PREINCREMENT_EXPR:
    5601           28 :       val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg, true_res);
    5602           28 :       break;
    5603           29 :     case POSTINCREMENT_EXPR:
    5604           29 :       val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg, true_res);
    5605           29 :       arg = save_expr (arg);
    5606           29 :       val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), val, arg);
    5607           29 :       val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), arg, val);
    5608           29 :       break;
    5609           22 :     case PREDECREMENT_EXPR:
    5610           22 :       val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg,
    5611              :                     invert_truthvalue_loc (input_location, arg));
    5612           22 :       break;
    5613           14 :     case POSTDECREMENT_EXPR:
    5614           14 :       val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg,
    5615              :                     invert_truthvalue_loc (input_location, arg));
    5616           14 :       arg = save_expr (arg);
    5617           14 :       val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), val, arg);
    5618           14 :       val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), arg, val);
    5619           14 :       break;
    5620            0 :     default:
    5621            0 :       gcc_unreachable ();
    5622              :     }
    5623           93 :   TREE_SIDE_EFFECTS (val) = 1;
    5624           93 :   return val;
    5625              : }
    5626              : 
    5627              : /* Built-in macros for stddef.h and stdint.h, that require macros
    5628              :    defined in this file.  */
    5629              : void
    5630       215769 : c_stddef_cpp_builtins(void)
    5631              : {
    5632       221243 :   builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE, 0);
    5633       221243 :   builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE, 0);
    5634       221243 :   builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE, 0);
    5635              :   /* C++ has wchar_t as a builtin type, C doesn't, so if WINT_TYPE
    5636              :      maps to wchar_t, define it to the underlying WCHAR_TYPE in C, and
    5637              :      to wchar_t in C++, so the desired type equivalence holds.  */
    5638       215769 :   if (!c_dialect_cxx ()
    5639              :       && strcmp (WINT_TYPE, "wchar_t") == 0)
    5640              :     builtin_define_with_value ("__WINT_TYPE__", WCHAR_TYPE, 0);
    5641              :   else
    5642       215769 :     builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE, 0);
    5643       221243 :   builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE, 0);
    5644       221243 :   builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE, 0);
    5645       215769 :   if (flag_char8_t)
    5646       177292 :     builtin_define_with_value ("__CHAR8_TYPE__", CHAR8_TYPE, 0);
    5647       215769 :   builtin_define_with_value ("__CHAR16_TYPE__", CHAR16_TYPE, 0);
    5648       215769 :   builtin_define_with_value ("__CHAR32_TYPE__", CHAR32_TYPE, 0);
    5649       215769 :   if (SIG_ATOMIC_TYPE)
    5650       215769 :     builtin_define_with_value ("__SIG_ATOMIC_TYPE__", SIG_ATOMIC_TYPE, 0);
    5651       215769 :   if (INT8_TYPE)
    5652       215769 :     builtin_define_with_value ("__INT8_TYPE__", INT8_TYPE, 0);
    5653       215769 :   if (INT16_TYPE)
    5654       215769 :     builtin_define_with_value ("__INT16_TYPE__", INT16_TYPE, 0);
    5655       215769 :   if (INT32_TYPE)
    5656       215769 :     builtin_define_with_value ("__INT32_TYPE__", INT32_TYPE, 0);
    5657       215769 :   if (INT64_TYPE)
    5658       221243 :     builtin_define_with_value ("__INT64_TYPE__", INT64_TYPE, 0);
    5659       215769 :   if (UINT8_TYPE)
    5660       215769 :     builtin_define_with_value ("__UINT8_TYPE__", UINT8_TYPE, 0);
    5661       215769 :   if (UINT16_TYPE)
    5662       215769 :     builtin_define_with_value ("__UINT16_TYPE__", UINT16_TYPE, 0);
    5663       215769 :   if (UINT32_TYPE)
    5664       215769 :     builtin_define_with_value ("__UINT32_TYPE__", UINT32_TYPE, 0);
    5665       215769 :   if (UINT64_TYPE)
    5666       221243 :     builtin_define_with_value ("__UINT64_TYPE__", UINT64_TYPE, 0);
    5667       215769 :   if (INT_LEAST8_TYPE)
    5668       215769 :     builtin_define_with_value ("__INT_LEAST8_TYPE__", INT_LEAST8_TYPE, 0);
    5669       215769 :   if (INT_LEAST16_TYPE)
    5670       215769 :     builtin_define_with_value ("__INT_LEAST16_TYPE__", INT_LEAST16_TYPE, 0);
    5671       215769 :   if (INT_LEAST32_TYPE)
    5672       215769 :     builtin_define_with_value ("__INT_LEAST32_TYPE__", INT_LEAST32_TYPE, 0);
    5673       215769 :   if (INT_LEAST64_TYPE)
    5674       221243 :     builtin_define_with_value ("__INT_LEAST64_TYPE__", INT_LEAST64_TYPE, 0);
    5675       215769 :   if (UINT_LEAST8_TYPE)
    5676       215769 :     builtin_define_with_value ("__UINT_LEAST8_TYPE__", UINT_LEAST8_TYPE, 0);
    5677       215769 :   if (UINT_LEAST16_TYPE)
    5678       215769 :     builtin_define_with_value ("__UINT_LEAST16_TYPE__", UINT_LEAST16_TYPE, 0);
    5679       215769 :   if (UINT_LEAST32_TYPE)
    5680       215769 :     builtin_define_with_value ("__UINT_LEAST32_TYPE__", UINT_LEAST32_TYPE, 0);
    5681       215769 :   if (UINT_LEAST64_TYPE)
    5682       221243 :     builtin_define_with_value ("__UINT_LEAST64_TYPE__", UINT_LEAST64_TYPE, 0);
    5683       215769 :   if (INT_FAST8_TYPE)
    5684       215769 :     builtin_define_with_value ("__INT_FAST8_TYPE__", INT_FAST8_TYPE, 0);
    5685       215769 :   if (INT_FAST16_TYPE)
    5686       221243 :     builtin_define_with_value ("__INT_FAST16_TYPE__", INT_FAST16_TYPE, 0);
    5687       215769 :   if (INT_FAST32_TYPE)
    5688       221243 :     builtin_define_with_value ("__INT_FAST32_TYPE__", INT_FAST32_TYPE, 0);
    5689       215769 :   if (INT_FAST64_TYPE)
    5690       221243 :     builtin_define_with_value ("__INT_FAST64_TYPE__", INT_FAST64_TYPE, 0);
    5691       215769 :   if (UINT_FAST8_TYPE)
    5692       215769 :     builtin_define_with_value ("__UINT_FAST8_TYPE__", UINT_FAST8_TYPE, 0);
    5693       215769 :   if (UINT_FAST16_TYPE)
    5694       221243 :     builtin_define_with_value ("__UINT_FAST16_TYPE__", UINT_FAST16_TYPE, 0);
    5695       215769 :   if (UINT_FAST32_TYPE)
    5696       221243 :     builtin_define_with_value ("__UINT_FAST32_TYPE__", UINT_FAST32_TYPE, 0);
    5697       215769 :   if (UINT_FAST64_TYPE)
    5698       221243 :     builtin_define_with_value ("__UINT_FAST64_TYPE__", UINT_FAST64_TYPE, 0);
    5699       215769 :   if (INTPTR_TYPE)
    5700       221243 :     builtin_define_with_value ("__INTPTR_TYPE__", INTPTR_TYPE, 0);
    5701       215769 :   if (UINTPTR_TYPE)
    5702       221243 :     builtin_define_with_value ("__UINTPTR_TYPE__", UINTPTR_TYPE, 0);
    5703              :   /* GIMPLE FE testcases need access to the GCC internal 'sizetype'.
    5704              :      Expose it as __SIZETYPE__.  */
    5705       215769 :   if (flag_gimple)
    5706          350 :     builtin_define_with_value ("__SIZETYPE__", SIZETYPE, 0);
    5707       215769 : }
    5708              : 
    5709              : static void
    5710       216307 : c_init_attributes (void)
    5711              : {
    5712              :   /* Fill in the built_in_attributes array.  */
    5713              : #define DEF_ATTR_NULL_TREE(ENUM)                                \
    5714              :   built_in_attributes[(int) ENUM] = NULL_TREE;
    5715              : #define DEF_ATTR_INT(ENUM, VALUE)                               \
    5716              :   built_in_attributes[(int) ENUM] = build_int_cst (integer_type_node, VALUE);
    5717              : #define DEF_ATTR_STRING(ENUM, VALUE)                            \
    5718              :   built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
    5719              : #define DEF_ATTR_IDENT(ENUM, STRING)                            \
    5720              :   built_in_attributes[(int) ENUM] = get_identifier (STRING);
    5721              : #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
    5722              :   built_in_attributes[(int) ENUM]                       \
    5723              :     = tree_cons (built_in_attributes[(int) PURPOSE],    \
    5724              :                  built_in_attributes[(int) VALUE],      \
    5725              :                  built_in_attributes[(int) CHAIN]);
    5726              : #include "builtin-attrs.def"
    5727              : #undef DEF_ATTR_NULL_TREE
    5728              : #undef DEF_ATTR_INT
    5729              : #undef DEF_ATTR_IDENT
    5730              : #undef DEF_ATTR_TREE_LIST
    5731       216307 : }
    5732              : 
    5733              : /* Check whether the byte alignment ALIGN is a valid user-specified
    5734              :    alignment less than the supported maximum.  If so, return ALIGN's
    5735              :    base-2 log; if not, output an error and return -1.  If OBJFILE
    5736              :    then reject alignments greater than MAX_OFILE_ALIGNMENT when
    5737              :    converted to bits.  Otherwise, consider valid only alignments
    5738              :    that are less than HOST_BITS_PER_INT - LOG2_BITS_PER_UNIT.
    5739              :    Zero is not considered a valid argument (and results in -1 on
    5740              :    return) but it only triggers a warning when WARN_ZERO is set.  */
    5741              : 
    5742              : int
    5743       641625 : check_user_alignment (const_tree align, bool objfile, bool warn_zero)
    5744              : {
    5745       641625 :   if (error_operand_p (align))
    5746              :     return -1;
    5747              : 
    5748       641602 :   if (TREE_CODE (align) != INTEGER_CST
    5749       641602 :       || !INTEGRAL_TYPE_P (TREE_TYPE (align)))
    5750              :     {
    5751           27 :       error ("requested alignment is not an integer constant");
    5752           27 :       return -1;
    5753              :     }
    5754              : 
    5755       641575 :   if (integer_zerop (align))
    5756              :     {
    5757           75 :       if (warn_zero)
    5758           63 :         warning (OPT_Wattributes,
    5759              :                  "requested alignment %qE is not a positive power of 2",
    5760              :                  align);
    5761           75 :       return -1;
    5762              :     }
    5763              : 
    5764              :   /* Log2 of the byte alignment ALIGN.  */
    5765       641500 :   int log2align;
    5766       641500 :   if (tree_int_cst_sgn (align) == -1
    5767       641500 :       || (log2align = tree_log2 (align)) == -1)
    5768              :     {
    5769           36 :       error ("requested alignment %qE is not a positive power of 2",
    5770              :              align);
    5771           36 :       return -1;
    5772              :     }
    5773              : 
    5774       641464 :   if (objfile)
    5775              :     {
    5776        14976 :       unsigned maxalign = MAX_OFILE_ALIGNMENT / BITS_PER_UNIT;
    5777        14976 :       if (!tree_fits_uhwi_p (align) || tree_to_uhwi (align) > maxalign)
    5778              :         {
    5779           10 :           error ("requested alignment %qE exceeds object file maximum %u",
    5780              :                  align, maxalign);
    5781           10 :           return -1;
    5782              :         }
    5783              :     }
    5784              : 
    5785       641454 :   if (log2align >= HOST_BITS_PER_INT - LOG2_BITS_PER_UNIT)
    5786              :     {
    5787           17 :       error ("requested alignment %qE exceeds maximum %u",
    5788              :              align, 1U << (HOST_BITS_PER_INT - LOG2_BITS_PER_UNIT - 1));
    5789           17 :       return -1;
    5790              :     }
    5791              : 
    5792              :   return log2align;
    5793              : }
    5794              : 
    5795              : /* Determine the ELF symbol visibility for DECL, which is either a
    5796              :    variable or a function.  It is an error to use this function if a
    5797              :    definition of DECL is not available in this translation unit.
    5798              :    Returns true if the final visibility has been determined by this
    5799              :    function; false if the caller is free to make additional
    5800              :    modifications.  */
    5801              : 
    5802              : bool
    5803     52556520 : c_determine_visibility (tree decl)
    5804              : {
    5805     52556520 :   gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
    5806              : 
    5807              :   /* If the user explicitly specified the visibility with an
    5808              :      attribute, honor that.  DECL_VISIBILITY will have been set during
    5809              :      the processing of the attribute.  We check for an explicit
    5810              :      attribute, rather than just checking DECL_VISIBILITY_SPECIFIED,
    5811              :      to distinguish the use of an attribute from the use of a "#pragma
    5812              :      GCC visibility push(...)"; in the latter case we still want other
    5813              :      considerations to be able to overrule the #pragma.  */
    5814     52556520 :   if (lookup_attribute ("visibility", DECL_ATTRIBUTES (decl))
    5815              :       || (TARGET_DLLIMPORT_DECL_ATTRIBUTES
    5816              :           && (lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl))
    5817              :               || lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl)))))
    5818              :     return true;
    5819              : 
    5820              :   /* Set default visibility to whatever the user supplied with
    5821              :      visibility_specified depending on #pragma GCC visibility.  */
    5822     51915729 :   if (!DECL_VISIBILITY_SPECIFIED (decl))
    5823              :     {
    5824     51914475 :       if (visibility_options.inpragma
    5825     51914475 :           || DECL_VISIBILITY (decl) != default_visibility)
    5826              :         {
    5827       214862 :           DECL_VISIBILITY (decl) = default_visibility;
    5828       214862 :           DECL_VISIBILITY_SPECIFIED (decl) = visibility_options.inpragma;
    5829              :           /* If visibility changed and DECL already has DECL_RTL, ensure
    5830              :              symbol flags are updated.  */
    5831        14468 :           if (((VAR_P (decl) && TREE_STATIC (decl))
    5832       214810 :                || TREE_CODE (decl) == FUNCTION_DECL)
    5833       415308 :               && DECL_RTL_SET_P (decl))
    5834            0 :             make_decl_rtl (decl);
    5835              :         }
    5836              :     }
    5837              :   return false;
    5838              : }
    5839              : 
    5840              : /* Data to communicate through check_function_arguments_recurse between
    5841              :    check_function_nonnull and check_nonnull_arg.  */
    5842              : 
    5843              : struct nonnull_arg_ctx
    5844              : {
    5845              :   /* Location of the call.  */
    5846              :   location_t loc;
    5847              :   /* The function whose arguments are being checked and its type (used
    5848              :      for calls through function pointers).  */
    5849              :   const_tree fndecl, fntype;
    5850              :   /* For nonnull_if_nonzero, index of the other arguments.  */
    5851              :   unsigned HOST_WIDE_INT other1, other2;
    5852              :   /* True if a warning has been issued.  */
    5853              :   bool warned_p;
    5854              : };
    5855              : 
    5856              : /* Check the argument list of a function call to CTX.FNDECL of CTX.FNTYPE
    5857              :    for null in argument slots that are marked as requiring a non-null
    5858              :    pointer argument.  The NARGS arguments are passed in the array ARGARRAY.
    5859              :    Return true if we have warned.  */
    5860              : 
    5861              : static bool
    5862      6488981 : check_function_nonnull (nonnull_arg_ctx &ctx, int nargs, tree *argarray)
    5863              : {
    5864      6488981 :   int firstarg = 0;
    5865      6488981 :   if (TREE_CODE (ctx.fntype) == METHOD_TYPE)
    5866              :     {
    5867       504886 :       bool closure = false;
    5868       504886 :       if (ctx.fndecl)
    5869              :         {
    5870              :           /* For certain lambda expressions the C++ front end emits calls
    5871              :              that pass a null this pointer as an argument named __closure
    5872              :              to the member operator() of empty function.  Detect those
    5873              :              and avoid checking them, but proceed to check the remaining
    5874              :              arguments.  */
    5875       504736 :           tree arg0 = DECL_ARGUMENTS (ctx.fndecl);
    5876       504736 :           if (tree arg0name = DECL_NAME (arg0))
    5877       504736 :             closure = id_equal (arg0name, "__closure");
    5878              :         }
    5879              : 
    5880              :       /* In calls to C++ non-static member functions check the this
    5881              :          pointer regardless of whether the function is declared with
    5882              :          attribute nonnull.  */
    5883      1004614 :       firstarg = 1;
    5884       504736 :       if (!closure)
    5885       499878 :         check_function_arguments_recurse (check_nonnull_arg, &ctx, argarray[0],
    5886              :                                           firstarg, OPT_Wnonnull);
    5887              :     }
    5888              : 
    5889      6488981 :   tree attrs = lookup_attribute ("nonnull", TYPE_ATTRIBUTES (ctx.fntype));
    5890              : 
    5891      6488981 :   tree a = attrs;
    5892              :   /* See if any of the nonnull attributes has no arguments.  If so,
    5893              :      then every pointer argument is checked (in which case the check
    5894              :      for pointer type is done in check_nonnull_arg).  */
    5895     13217313 :   while (a != NULL_TREE && TREE_VALUE (a) != NULL_TREE)
    5896       106172 :     a = lookup_attribute ("nonnull", TREE_CHAIN (a));
    5897              : 
    5898      6488981 :   if (a != NULL_TREE)
    5899        71718 :     for (int i = firstarg; i < nargs; i++)
    5900        44711 :       check_function_arguments_recurse (check_nonnull_arg, &ctx, argarray[i],
    5901        44711 :                                         i + 1, OPT_Wnonnull);
    5902      6461974 :   else if (attrs)
    5903              :     {
    5904              :       /* Walk the argument list.  If we encounter an argument number we
    5905              :          should check for non-null, do it.  */
    5906       355931 :       for (int i = firstarg; i < nargs; i++)
    5907              :         {
    5908       150917 :           for (a = attrs; ; a = TREE_CHAIN (a))
    5909              :             {
    5910       411367 :               a = lookup_attribute ("nonnull", a);
    5911       411367 :               if (a == NULL_TREE || nonnull_check_p (TREE_VALUE (a), i + 1))
    5912              :                 break;
    5913              :             }
    5914              : 
    5915       260450 :           if (a != NULL_TREE)
    5916       126959 :             check_function_arguments_recurse (check_nonnull_arg, &ctx,
    5917       126959 :                                               argarray[i], i + 1,
    5918              :                                               OPT_Wnonnull);
    5919       260450 :           a = NULL_TREE;
    5920              :         }
    5921              :     }
    5922      6488981 :   if (a == NULL_TREE)
    5923      6461974 :     for (attrs = TYPE_ATTRIBUTES (ctx.fntype);
    5924      6520538 :          (attrs = lookup_attribute ("nonnull_if_nonzero", attrs));
    5925        58564 :          attrs = TREE_CHAIN (attrs))
    5926              :       {
    5927        58564 :         tree args = TREE_VALUE (attrs);
    5928        58564 :         unsigned int idx = TREE_INT_CST_LOW (TREE_VALUE (args)) - 1;
    5929        58564 :         unsigned int idx2
    5930        58564 :           = TREE_INT_CST_LOW (TREE_VALUE (TREE_CHAIN (args))) - 1;
    5931        58564 :         unsigned int idx3 = idx2;
    5932        58564 :         if (tree chain2 = TREE_CHAIN (TREE_CHAIN (args)))
    5933          485 :           idx3 = TREE_INT_CST_LOW (TREE_VALUE (chain2)) - 1;
    5934        58564 :         if (idx < (unsigned) nargs - firstarg
    5935        58559 :             && idx2 < (unsigned) nargs - firstarg
    5936        58554 :             && idx3 < (unsigned) nargs - firstarg
    5937        58554 :             && INTEGRAL_TYPE_P (TREE_TYPE (argarray[firstarg + idx2]))
    5938        58481 :             && integer_nonzerop (argarray[firstarg + idx2])
    5939        31986 :             && INTEGRAL_TYPE_P (TREE_TYPE (argarray[firstarg + idx3]))
    5940        90550 :             && integer_nonzerop (argarray[firstarg + idx3]))
    5941              :           {
    5942        31888 :             ctx.other1 = firstarg + idx2 + 1;
    5943        31888 :             ctx.other2 = firstarg + idx3 + 1;
    5944        31888 :             check_function_arguments_recurse (check_nonnull_arg, &ctx,
    5945        31888 :                                               argarray[firstarg + idx],
    5946        31888 :                                               firstarg + idx + 1,
    5947              :                                               OPT_Wnonnull);
    5948        31888 :             ctx.other1 = 0;
    5949        31888 :             ctx.other2 = 0;
    5950              :           }
    5951              :       }
    5952      6488981 :   return ctx.warned_p;
    5953              : }
    5954              : 
    5955              : /* Check that the Nth argument of a function call (counting backwards
    5956              :    from the end) is a (pointer)0.  The NARGS arguments are passed in the
    5957              :    array ARGARRAY.  */
    5958              : 
    5959              : static void
    5960      6475299 : check_function_sentinel (const_tree fntype, int nargs, tree *argarray)
    5961              : {
    5962      6475299 :   tree attr = lookup_attribute ("sentinel", TYPE_ATTRIBUTES (fntype));
    5963              : 
    5964      6475299 :   if (attr)
    5965              :     {
    5966          112 :       int len = 0;
    5967          112 :       int pos = 0;
    5968          112 :       tree sentinel;
    5969          112 :       function_args_iterator iter;
    5970          112 :       tree t;
    5971              : 
    5972              :       /* Skip over the named arguments.  */
    5973          237 :       FOREACH_FUNCTION_ARGS (fntype, t, iter)
    5974              :         {
    5975          125 :           if (len == nargs)
    5976              :             break;
    5977          125 :           len++;
    5978              :         }
    5979              : 
    5980          112 :       if (TREE_VALUE (attr))
    5981              :         {
    5982           59 :           tree p = TREE_VALUE (TREE_VALUE (attr));
    5983           59 :           pos = TREE_INT_CST_LOW (p);
    5984              :         }
    5985              : 
    5986              :       /* The sentinel must be one of the varargs, i.e.
    5987              :          in position >= the number of fixed arguments.  */
    5988          112 :       if ((nargs - 1 - pos) < len)
    5989              :         {
    5990           22 :           warning (OPT_Wformat_,
    5991              :                    "not enough variable arguments to fit a sentinel");
    5992           22 :           return;
    5993              :         }
    5994              : 
    5995              :       /* Validate the sentinel.  */
    5996           90 :       sentinel = fold_for_warn (argarray[nargs - 1 - pos]);
    5997          138 :       if ((!POINTER_TYPE_P (TREE_TYPE (sentinel))
    5998           42 :            || !integer_zerop (sentinel))
    5999           56 :           && TREE_CODE (TREE_TYPE (sentinel)) != NULLPTR_TYPE
    6000              :           /* Although __null (in C++) is only an integer we allow it
    6001              :              nevertheless, as we are guaranteed that it's exactly
    6002              :              as wide as a pointer, and we don't want to force
    6003              :              users to cast the NULL they have written there.
    6004              :              We warn with -Wstrict-null-sentinel, though.  */
    6005          138 :           && (warn_strict_null_sentinel || null_node != sentinel))
    6006           45 :         warning (OPT_Wformat_, "missing sentinel in function call");
    6007              :     }
    6008              : }
    6009              : 
    6010              : /* Check that the same argument isn't passed to two or more
    6011              :    restrict-qualified formal and issue a -Wrestrict warning
    6012              :    if it is.  Return true if a warning has been issued.  */
    6013              : 
    6014              : static bool
    6015     53746438 : check_function_restrict (const_tree fndecl, const_tree fntype,
    6016              :                          int nargs, tree *unfolded_argarray)
    6017              : {
    6018     53746438 :   int i;
    6019     53746438 :   tree parms = TYPE_ARG_TYPES (fntype);
    6020              : 
    6021              :   /* Call fold_for_warn on all of the arguments.  */
    6022     53746438 :   auto_vec<tree> argarray (nargs);
    6023    242143312 :   for (i = 0; i < nargs; i++)
    6024    134650436 :     argarray.quick_push (fold_for_warn (unfolded_argarray[i]));
    6025              : 
    6026     53746438 :   if (fndecl
    6027     53228058 :       && TREE_CODE (fndecl) == FUNCTION_DECL)
    6028              :     {
    6029              :       /* Avoid diagnosing calls built-ins with a zero size/bound
    6030              :          here.  They are checked in more detail elsewhere.  */
    6031     53228058 :       if (fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
    6032      1824045 :           && nargs == 3
    6033       363056 :           && TREE_CODE (argarray[2]) == INTEGER_CST
    6034     53398355 :           && integer_zerop (argarray[2]))
    6035              :         return false;
    6036              : 
    6037     53202429 :       if (DECL_ARGUMENTS (fndecl))
    6038     53720809 :         parms = DECL_ARGUMENTS (fndecl);
    6039              :     }
    6040              : 
    6041    188294358 :   for (i = 0; i < nargs; i++)
    6042    134573549 :     TREE_VISITED (argarray[i]) = 0;
    6043              : 
    6044              :   bool warned = false;
    6045              : 
    6046    187408698 :   for (i = 0; i < nargs && parms && parms != void_list_node; i++)
    6047              :     {
    6048    133687889 :       tree type;
    6049    133687889 :       if (TREE_CODE (parms) == PARM_DECL)
    6050              :         {
    6051     16045262 :           type = TREE_TYPE (parms);
    6052     16045262 :           parms = DECL_CHAIN (parms);
    6053              :         }
    6054              :       else
    6055              :         {
    6056    117642627 :           type = TREE_VALUE (parms);
    6057    117642627 :           parms = TREE_CHAIN (parms);
    6058              :         }
    6059    133687889 :       if (POINTER_TYPE_P (type)
    6060      8312192 :           && TYPE_RESTRICT (type)
    6061    133942934 :           && !TYPE_READONLY (TREE_TYPE (type)))
    6062       253454 :         warned |= warn_for_restrict (i, argarray.address (), nargs);
    6063              :     }
    6064              : 
    6065    188294358 :   for (i = 0; i < nargs; i++)
    6066    134573549 :     TREE_VISITED (argarray[i]) = 0;
    6067              : 
    6068              :   return warned;
    6069     53746438 : }
    6070              : 
    6071              : /* Helper for check_function_nonnull; given a list of operands which
    6072              :    must be non-null in ARGS, determine if operand PARAM_NUM should be
    6073              :    checked.  */
    6074              : 
    6075              : static bool
    6076       277876 : nonnull_check_p (tree args, unsigned HOST_WIDE_INT param_num)
    6077              : {
    6078       277876 :   unsigned HOST_WIDE_INT arg_num = 0;
    6079              : 
    6080       728920 :   for (; args; args = TREE_CHAIN (args))
    6081              :     {
    6082       578003 :       bool found = get_attribute_operand (TREE_VALUE (args), &arg_num);
    6083              : 
    6084       578003 :       gcc_assert (found);
    6085              : 
    6086       578003 :       if (arg_num == param_num)
    6087              :         return true;
    6088              :     }
    6089              :   return false;
    6090              : }
    6091              : 
    6092              : /* Check that the function argument PARAM (which is operand number
    6093              :    PARAM_NUM) is non-null.  This is called by check_function_nonnull
    6094              :    via check_function_arguments_recurse.  */
    6095              : 
    6096              : static void
    6097       702432 : check_nonnull_arg (void *ctx, tree param, unsigned HOST_WIDE_INT param_num)
    6098              : {
    6099       702432 :   struct nonnull_arg_ctx *pctx = (struct nonnull_arg_ctx *) ctx;
    6100              : 
    6101              :   /* Just skip checking the argument if it's not a pointer.  This can
    6102              :      happen if the "nonnull" attribute was given without an operand
    6103              :      list (which means to check every pointer argument).  */
    6104              : 
    6105       702432 :   tree paramtype = TREE_TYPE (param);
    6106       702432 :   if (TREE_CODE (paramtype) != POINTER_TYPE
    6107        62212 :       && TREE_CODE (paramtype) != NULLPTR_TYPE)
    6108       701695 :     return;
    6109              : 
    6110              :   /* Diagnose the simple cases of null arguments.  */
    6111       640226 :   if (!integer_zerop (fold_for_warn (param)))
    6112              :     return;
    6113              : 
    6114          737 :   auto_diagnostic_group adg;
    6115              : 
    6116          737 :   const location_t loc = EXPR_LOC_OR_LOC (param, pctx->loc);
    6117              : 
    6118          737 :   if (TREE_CODE (pctx->fntype) == METHOD_TYPE)
    6119           97 :     --param_num;
    6120              : 
    6121          737 :   bool warned;
    6122          737 :   if (param_num == 0)
    6123              :     {
    6124           30 :       warned = warning_at (loc, OPT_Wnonnull,
    6125              :                            "%qs pointer is null", "this");
    6126           30 :       if (warned && pctx->fndecl)
    6127           27 :         inform (DECL_SOURCE_LOCATION (pctx->fndecl),
    6128              :                 "in a call to non-static member function %qD",
    6129              :                 pctx->fndecl);
    6130              :     }
    6131              :   else
    6132              :     {
    6133          707 :       if (pctx->other1 && pctx->other2 != pctx->other1)
    6134           14 :         warned = warning_at (loc, OPT_Wnonnull,
    6135              :                              "argument %u null where non-null expected "
    6136              :                              "because arguments %u and %u are nonzero",
    6137              :                              (unsigned) param_num,
    6138              :                              TREE_CODE (pctx->fntype) == METHOD_TYPE
    6139            0 :                              ? (unsigned) pctx->other1 - 1
    6140              :                              : (unsigned) pctx->other1,
    6141              :                              TREE_CODE (pctx->fntype) == METHOD_TYPE
    6142            0 :                              ? (unsigned) pctx->other2 - 1
    6143              :                              : (unsigned) pctx->other2);
    6144          693 :       else if (pctx->other1)
    6145           50 :         warned = warning_at (loc, OPT_Wnonnull,
    6146              :                              "argument %u null where non-null expected "
    6147              :                              "because argument %u is nonzero",
    6148              :                              (unsigned) param_num,
    6149              :                              TREE_CODE (pctx->fntype) == METHOD_TYPE
    6150            0 :                              ? (unsigned) pctx->other1 - 1
    6151              :                              : (unsigned) pctx->other1);
    6152              :       else
    6153          643 :         warned = warning_at (loc, OPT_Wnonnull,
    6154              :                              "argument %u null where non-null expected",
    6155              :                              (unsigned) param_num);
    6156          707 :       if (warned && pctx->fndecl)
    6157          676 :         inform (DECL_SOURCE_LOCATION (pctx->fndecl),
    6158              :                 "in a call to function %qD declared %qs",
    6159              :                 pctx->fndecl,
    6160          676 :                 pctx->other1 ? "nonnull_if_nonzero" : "nonnull");
    6161              :     }
    6162              : 
    6163          734 :   if (warned)
    6164          734 :     pctx->warned_p = true;
    6165          737 : }
    6166              : 
    6167              : /* Helper for attribute handling; fetch the operand number from
    6168              :    the attribute argument list.  */
    6169              : 
    6170              : bool
    6171       578003 : get_attribute_operand (tree arg_num_expr, unsigned HOST_WIDE_INT *valp)
    6172              : {
    6173              :   /* Verify the arg number is a small constant.  */
    6174       578003 :   if (tree_fits_uhwi_p (arg_num_expr))
    6175              :     {
    6176       578003 :       *valp = tree_to_uhwi (arg_num_expr);
    6177       578003 :       return true;
    6178              :     }
    6179              :   else
    6180              :     return false;
    6181              : }
    6182              : 
    6183              : /* Arguments being collected for optimization.  */
    6184              : typedef const char *const_char_p;               /* For DEF_VEC_P.  */
    6185              : static GTY(()) vec<const_char_p, va_gc> *optimize_args;
    6186              : 
    6187              : 
    6188              : /* Inner function to convert a TREE_LIST to argv string to parse the optimize
    6189              :    options in ARGS.  ATTR_P is true if this is for attribute(optimize), and
    6190              :    false for #pragma GCC optimize.  */
    6191              : 
    6192              : bool
    6193       345650 : parse_optimize_options (tree args, bool attr_p)
    6194              : {
    6195       345650 :   bool ret = true;
    6196       345650 :   unsigned opt_argc;
    6197       345650 :   unsigned i;
    6198       345650 :   const char **opt_argv;
    6199       345650 :   struct cl_decoded_option *decoded_options;
    6200       345650 :   unsigned int decoded_options_count;
    6201       345650 :   tree ap;
    6202              : 
    6203              :   /* Build up argv vector.  Just in case the string is stored away, use garbage
    6204              :      collected strings.  */
    6205       345650 :   vec_safe_truncate (optimize_args, 0);
    6206       345650 :   vec_safe_push (optimize_args, (const char *) NULL);
    6207              : 
    6208       710047 :   for (ap = args; ap != NULL_TREE; ap = TREE_CHAIN (ap))
    6209              :     {
    6210       364397 :       tree value = TREE_VALUE (ap);
    6211              : 
    6212       364397 :       if (TREE_CODE (value) == INTEGER_CST)
    6213              :         {
    6214          377 :           char buffer[HOST_BITS_PER_LONG / 3 + 4];
    6215          377 :           sprintf (buffer, "-O%ld", (long) TREE_INT_CST_LOW (value));
    6216          377 :           vec_safe_push (optimize_args, ggc_strdup (buffer));
    6217              :         }
    6218              : 
    6219       364020 :       else if (TREE_CODE (value) == STRING_CST)
    6220              :         {
    6221              :           /* Split string into multiple substrings.  */
    6222       364016 :           size_t len = TREE_STRING_LENGTH (value);
    6223       364016 :           char *p = ASTRDUP (TREE_STRING_POINTER (value));
    6224       364016 :           char *end = p + len;
    6225       364016 :           char *comma;
    6226       364016 :           char *next_p = p;
    6227              : 
    6228       728081 :           while (next_p != NULL)
    6229              :             {
    6230       364065 :               size_t len2;
    6231       364065 :               char *q, *r;
    6232              : 
    6233       364065 :               p = next_p;
    6234       364065 :               comma = strchr (p, ',');
    6235       364065 :               if (comma)
    6236              :                 {
    6237           49 :                   len2 = comma - p;
    6238           49 :                   *comma = '\0';
    6239           49 :                   next_p = comma+1;
    6240              :                 }
    6241              :               else
    6242              :                 {
    6243       364016 :                   len2 = end - p;
    6244       364016 :                   next_p = NULL;
    6245              :                 }
    6246              : 
    6247              :               /* If the user supplied -Oxxx or -fxxx, only allow -Oxxx or -fxxx
    6248              :                  options.  */
    6249       364065 :               if (*p == '-' && p[1] != 'O' && p[1] != 'f')
    6250              :                 {
    6251            0 :                   ret = false;
    6252            0 :                   if (attr_p)
    6253              :                     {
    6254            0 :                       auto_urlify_attributes sentinel;
    6255            0 :                       warning (OPT_Wattributes,
    6256              :                                "bad option %qs to attribute %<optimize%>", p);
    6257            0 :                     }
    6258              :                   else
    6259            0 :                     warning (OPT_Wpragmas,
    6260              :                              "bad option %qs to pragma %<optimize%>", p);
    6261            0 :                   continue;
    6262            0 :                 }
    6263              : 
    6264              :               /* Can't use GC memory here, see PR88007.  */
    6265       364065 :               r = q = XOBNEWVEC (&opts_obstack, char, len2 + 3);
    6266              : 
    6267       364065 :               if (*p != '-')
    6268              :                 {
    6269        42916 :                   *r++ = '-';
    6270              : 
    6271              :                   /* Assume that Ox is -Ox, a numeric value is -Ox, a s by
    6272              :                      itself is -Os, and any other switch begins with a -f.  */
    6273        42916 :                   if ((*p >= '0' && *p <= '9')
    6274        42703 :                       || (p[0] == 's' && p[1] == '\0'))
    6275          213 :                     *r++ = 'O';
    6276        42703 :                   else if (*p != 'O')
    6277        23382 :                     *r++ = 'f';
    6278              :                 }
    6279              : 
    6280       364065 :               memcpy (r, p, len2);
    6281       364065 :               r[len2] = '\0';
    6282       364065 :               vec_safe_push (optimize_args, (const char *) q);
    6283              :             }
    6284              : 
    6285              :         }
    6286              :     }
    6287              : 
    6288       345650 :   opt_argc = optimize_args->length ();
    6289       345650 :   opt_argv = (const char **) alloca (sizeof (char *) * (opt_argc + 1));
    6290              : 
    6291       710092 :   for (i = 1; i < opt_argc; i++)
    6292       364442 :     opt_argv[i] = (*optimize_args)[i];
    6293              : 
    6294              :   /* Now parse the options.  */
    6295       345650 :   decode_cmdline_options_to_array_default_mask (opt_argc, opt_argv,
    6296              :                                                 &decoded_options,
    6297              :                                                 &decoded_options_count);
    6298              :   /* Drop non-Optimization options.  */
    6299       345650 :   unsigned j = 1;
    6300       710092 :   for (i = 1; i < decoded_options_count; ++i)
    6301              :     {
    6302       364442 :       if (! (cl_options[decoded_options[i].opt_index].flags & CL_OPTIMIZATION))
    6303              :         {
    6304            3 :           ret = false;
    6305            3 :           if (attr_p)
    6306              :             {
    6307            2 :               auto_urlify_attributes sentinel;
    6308            2 :               warning (OPT_Wattributes,
    6309              :                        "bad option %qs to attribute %<optimize%>",
    6310            2 :                        decoded_options[i].orig_option_with_args_text);
    6311            2 :             }
    6312              :           else
    6313            1 :             warning (OPT_Wpragmas,
    6314              :                      "bad option %qs to pragma %<optimize%>",
    6315              :                      decoded_options[i].orig_option_with_args_text);
    6316            3 :           continue;
    6317            3 :         }
    6318       364439 :       if (i != j)
    6319            0 :         decoded_options[j] = decoded_options[i];
    6320       364439 :       j++;
    6321              :     }
    6322       345650 :   decoded_options_count = j;
    6323              : 
    6324              :   /* Merge the decoded options with save_decoded_options.  */
    6325       345650 :   unsigned save_opt_count = save_opt_decoded_options->length ();
    6326       345650 :   unsigned merged_decoded_options_count
    6327              :     = save_opt_count + decoded_options_count;
    6328       345650 :   cl_decoded_option *merged_decoded_options
    6329       345650 :     = XNEWVEC (cl_decoded_option, merged_decoded_options_count);
    6330              : 
    6331              :   /* Note the first decoded_options is used for the program name.  */
    6332      1988531 :   for (unsigned i = 0; i < save_opt_count; ++i)
    6333      1642881 :     merged_decoded_options[i + 1] = (*save_opt_decoded_options)[i];
    6334       710089 :   for (unsigned i = 1; i < decoded_options_count; ++i)
    6335       364439 :     merged_decoded_options[save_opt_count + i] = decoded_options[i];
    6336              : 
    6337              :    /* And apply them.  */
    6338       345650 :   decode_options (&global_options, &global_options_set,
    6339              :                   merged_decoded_options, merged_decoded_options_count,
    6340              :                   input_location, global_dc, NULL);
    6341       345650 :   free (decoded_options);
    6342              : 
    6343       345650 :   targetm.override_options_after_change();
    6344              : 
    6345       345650 :   optimize_args->truncate (0);
    6346       345650 :   return ret;
    6347              : }
    6348              : 
    6349              : /* Check whether ATTR is a valid attribute fallthrough.  */
    6350              : 
    6351              : bool
    6352    298622188 : attribute_fallthrough_p (tree attr)
    6353              : {
    6354    298622188 :   if (attr == error_mark_node)
    6355              :    return false;
    6356    298622170 :   tree t = lookup_attribute ("", "fallthrough", attr);
    6357    298622170 :   if (t == NULL_TREE)
    6358              :     return false;
    6359        82689 :   auto_urlify_attributes sentinel;
    6360              :   /* It is no longer true that "this attribute shall appear at most once in
    6361              :      each attribute-list", but we still give a warning.  */
    6362        82689 :   if (lookup_attribute ("", "fallthrough", TREE_CHAIN (t)))
    6363            9 :     warning (OPT_Wattributes, "attribute %<fallthrough%> specified multiple "
    6364              :              "times");
    6365              :   /* No attribute-argument-clause shall be present.  */
    6366        82680 :   else if (TREE_VALUE (t) != NULL_TREE)
    6367            4 :     warning (OPT_Wattributes, "%<fallthrough%> attribute specified with "
    6368              :              "a parameter");
    6369              :   /* Warn if other attributes are found.  */
    6370       165404 :   for (t = attr; t != NULL_TREE; t = TREE_CHAIN (t))
    6371              :     {
    6372        82715 :       tree name = get_attribute_name (t);
    6373        82715 :       if (!is_attribute_p ("fallthrough", name)
    6374        82715 :           || !is_attribute_namespace_p ("", t))
    6375              :         {
    6376           17 :           if (!c_dialect_cxx () && get_attribute_namespace (t) == NULL_TREE)
    6377              :             /* The specifications of standard attributes in C mean
    6378              :                this is a constraint violation.  */
    6379            3 :             pedwarn (input_location, OPT_Wattributes, "%qE attribute ignored",
    6380              :                      get_attribute_name (t));
    6381              :           else
    6382           14 :             warning (OPT_Wattributes, "%qE attribute ignored", name);
    6383              :         }
    6384              :     }
    6385        82689 :   return true;
    6386        82689 : }
    6387              : 
    6388              : 
    6389              : /* Check for valid arguments being passed to a function with FNTYPE.
    6390              :    There are NARGS arguments in the array ARGARRAY.  LOC should be used
    6391              :    for diagnostics.  Return true if either -Wnonnull or -Wrestrict has
    6392              :    been issued.
    6393              : 
    6394              :    The arguments in ARGARRAY may not have been folded yet (e.g. for C++,
    6395              :    to preserve location wrappers); checks that require folded arguments
    6396              :    should call fold_for_warn on them.
    6397              : 
    6398              :    Use the frontend-supplied COMP_TYPES when determining if
    6399              :    one type is a subclass of another.  */
    6400              : 
    6401              : bool
    6402     55089293 : check_function_arguments (location_t loc, const_tree fndecl, const_tree fntype,
    6403              :                           int nargs, tree *argarray, vec<location_t> *arglocs,
    6404              :                           bool (*comp_types) (tree, tree))
    6405              : {
    6406     55089293 :   bool warned_p = false;
    6407              : 
    6408     55089293 :   if (c_inhibit_evaluation_warnings)
    6409              :     return warned_p;
    6410              : 
    6411              :   /* Check for null being passed in a pointer argument that must be
    6412              :      non-null.  In C++, this includes the this pointer.  We also need
    6413              :      to do this if format checking is enabled.  */
    6414     53751320 :   if (warn_nonnull)
    6415              :     {
    6416      6488981 :       nonnull_arg_ctx ctx = { loc, fndecl, fntype, 0, 0, false };
    6417      6488981 :       warned_p = check_function_nonnull (ctx, nargs, argarray);
    6418              :     }
    6419              : 
    6420              :   /* Check for errors in format strings.  */
    6421              : 
    6422     53751320 :   if (warn_format || warn_suggest_attribute_format)
    6423      6552935 :     check_function_format (fndecl ? fndecl : fntype, TYPE_ATTRIBUTES (fntype), nargs,
    6424              :                            argarray, arglocs, comp_types);
    6425              : 
    6426     53751320 :   if (warn_format)
    6427      6475299 :     check_function_sentinel (fntype, nargs, argarray);
    6428              : 
    6429     53751320 :   if (fndecl && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
    6430              :     {
    6431      1828927 :       switch (DECL_FUNCTION_CODE (fndecl))
    6432              :         {
    6433              :         case BUILT_IN_SPRINTF:
    6434              :         case BUILT_IN_SPRINTF_CHK:
    6435              :         case BUILT_IN_SNPRINTF:
    6436              :         case BUILT_IN_SNPRINTF_CHK:
    6437              :           /* Let the sprintf pass handle these.  */
    6438              :           return warned_p;
    6439              : 
    6440              :         default:
    6441              :           break;
    6442              :         }
    6443              :     }
    6444              : 
    6445              :   /* check_function_restrict sets the DECL_READ_P for arguments
    6446              :      so it must be called unconditionally.  */
    6447     53746438 :   warned_p |= check_function_restrict (fndecl, fntype, nargs, argarray);
    6448              : 
    6449     53746438 :   return warned_p;
    6450              : }
    6451              : 
    6452              : /* Generic argument checking recursion routine.  PARAM is the argument to
    6453              :    be checked.  PARAM_NUM is the number of the argument.  CALLBACK is invoked
    6454              :    once the argument is resolved.  CTX is context for the callback.
    6455              :    OPT is the warning for which this is done.  */
    6456              : void
    6457       761455 : check_function_arguments_recurse (void (*callback)
    6458              :                                   (void *, tree, unsigned HOST_WIDE_INT),
    6459              :                                   void *ctx, tree param,
    6460              :                                   unsigned HOST_WIDE_INT param_num,
    6461              :                                   opt_code opt)
    6462              : {
    6463      1190122 :   if (opt != OPT_Wformat_ && warning_suppressed_p (param))
    6464              :     return;
    6465              : 
    6466       811468 :   if (CONVERT_EXPR_P (param)
    6467      1317856 :       && (TYPE_PRECISION (TREE_TYPE (param))
    6468       506388 :           == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (param, 0)))))
    6469              :     {
    6470              :       /* Strip coercion.  */
    6471       855748 :       check_function_arguments_recurse (callback, ctx,
    6472       427874 :                                         TREE_OPERAND (param, 0), param_num,
    6473              :                                         opt);
    6474       427874 :       return;
    6475              :     }
    6476              : 
    6477       760507 :   if (TREE_CODE (param) == CALL_EXPR && CALL_EXPR_FN (param))
    6478              :     {
    6479         8229 :       tree type = TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (param)));
    6480         8229 :       tree attrs;
    6481         8229 :       bool found_format_arg = false;
    6482              : 
    6483              :       /* See if this is a call to a known internationalization function
    6484              :          that modifies a format arg.  Such a function may have multiple
    6485              :          format_arg attributes (for example, ngettext).  */
    6486              : 
    6487         8229 :       for (attrs = TYPE_ATTRIBUTES (type);
    6488         8618 :            attrs;
    6489          389 :            attrs = TREE_CHAIN (attrs))
    6490          389 :         if (is_attribute_p ("format_arg", get_attribute_name (attrs)))
    6491              :           {
    6492          226 :             tree inner_arg;
    6493          226 :             tree format_num_expr;
    6494          226 :             int format_num;
    6495          226 :             int i;
    6496          226 :             call_expr_arg_iterator iter;
    6497              : 
    6498              :             /* Extract the argument number, which was previously checked
    6499              :                to be valid.  */
    6500          226 :             format_num_expr = TREE_VALUE (TREE_VALUE (attrs));
    6501              : 
    6502          226 :             format_num = tree_to_uhwi (format_num_expr);
    6503              : 
    6504          226 :             for (inner_arg = first_call_expr_arg (param, &iter), i = 1;
    6505          320 :                  inner_arg != NULL_TREE;
    6506           94 :                  inner_arg = next_call_expr_arg (&iter), i++)
    6507          320 :               if (i == format_num)
    6508              :                 {
    6509          226 :                   check_function_arguments_recurse (callback, ctx,
    6510              :                                                     inner_arg, param_num,
    6511              :                                                     opt);
    6512          226 :                   found_format_arg = true;
    6513          226 :                   break;
    6514              :                 }
    6515              :           }
    6516              : 
    6517              :       /* If we found a format_arg attribute and did a recursive check,
    6518              :          we are done with checking this argument.  Otherwise, we continue
    6519              :          and this will be considered a non-literal.  */
    6520         8229 :       if (found_format_arg)
    6521              :         return;
    6522              :     }
    6523              : 
    6524       760329 :   if (TREE_CODE (param) == COND_EXPR)
    6525              :     {
    6526              :       /* Simplify to avoid warning for an impossible case.  */
    6527          811 :       param = fold_for_warn (param);
    6528          811 :       if (TREE_CODE (param) == COND_EXPR)
    6529              :         {
    6530              :           /* Check both halves of the conditional expression.  */
    6531          793 :           check_function_arguments_recurse (callback, ctx,
    6532          793 :                                             TREE_OPERAND (param, 1),
    6533              :                                             param_num, opt);
    6534         1586 :           check_function_arguments_recurse (callback, ctx,
    6535          793 :                                             TREE_OPERAND (param, 2),
    6536              :                                             param_num, opt);
    6537          793 :           return;
    6538              :         }
    6539              :     }
    6540              : 
    6541       759536 :   (*callback) (ctx, param, param_num);
    6542              : }
    6543              : 
    6544              : /* Checks for a builtin function FNDECL that the number of arguments
    6545              :    NARGS against the required number REQUIRED and issues an error if
    6546              :    there is a mismatch.  Returns true if the number of arguments is
    6547              :    correct, otherwise false.  LOC is the location of FNDECL.  */
    6548              : 
    6549              : static bool
    6550       852985 : builtin_function_validate_nargs (location_t loc, tree fndecl, int nargs,
    6551              :                                  int required, bool complain)
    6552              : {
    6553       852985 :   if (nargs < required)
    6554              :     {
    6555          182 :       if (complain)
    6556          143 :         error_at (loc, "too few arguments to function %qE", fndecl);
    6557          182 :       return false;
    6558              :     }
    6559       852803 :   else if (nargs > required)
    6560              :     {
    6561          138 :       if (complain)
    6562           93 :         error_at (loc, "too many arguments to function %qE", fndecl);
    6563          138 :       return false;
    6564              :     }
    6565              :   return true;
    6566              : }
    6567              : 
    6568              : /* Helper macro for check_builtin_function_arguments.  */
    6569              : #define ARG_LOCATION(N)                                 \
    6570              :   (arg_loc.is_empty ()                                  \
    6571              :    ? EXPR_LOC_OR_LOC (args[(N)], input_location)        \
    6572              :    : expansion_point_location (arg_loc[(N)]))
    6573              : 
    6574              : /* Verifies the NARGS arguments ARGS to the builtin function FNDECL.
    6575              :    Returns false if there was an error, otherwise true.  LOC is the
    6576              :    location of the function; ARG_LOC is a vector of locations of the
    6577              :    arguments.  If FNDECL is the result of resolving an overloaded
    6578              :    target built-in, ORIG_FNDECL is the original function decl,
    6579              :    otherwise it is null.  */
    6580              : 
    6581              : bool
    6582     40423689 : check_builtin_function_arguments (location_t loc, vec<location_t> arg_loc,
    6583              :                                   tree fndecl, tree orig_fndecl, int nargs,
    6584              :                                   tree *args, bool complain)
    6585              : {
    6586     40423689 :   if (!fndecl_built_in_p (fndecl))
    6587              :     return true;
    6588              : 
    6589     40423689 :   if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD)
    6590     33099714 :     return (!targetm.check_builtin_call
    6591     33099714 :             || targetm.check_builtin_call (loc, arg_loc, fndecl, orig_fndecl,
    6592              :                                            nargs, args, complain));
    6593              : 
    6594      7323975 :   if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_FRONTEND)
    6595              :     return true;
    6596              : 
    6597      7256210 :   gcc_assert (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL);
    6598      7256210 :   switch (DECL_FUNCTION_CODE (fndecl))
    6599              :     {
    6600            2 :     case BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX:
    6601            2 :       if (!tree_fits_uhwi_p (args[2]))
    6602              :         {
    6603            0 :           if (complain)
    6604            0 :             error_at (
    6605            0 :               ARG_LOCATION (2),
    6606              :               "third argument to function %qE must be a constant integer",
    6607              :               fndecl);
    6608            0 :           return false;
    6609              :         }
    6610              :       /* fall through */
    6611              : 
    6612          264 :     case BUILT_IN_ALLOCA_WITH_ALIGN:
    6613          264 :       {
    6614              :         /* Get the requested alignment (in bits) if it's a constant
    6615              :            integer expression.  */
    6616          264 :         unsigned HOST_WIDE_INT align
    6617          264 :           = tree_fits_uhwi_p (args[1]) ? tree_to_uhwi (args[1]) : 0;
    6618              : 
    6619              :         /* Determine if the requested alignment is a power of 2.  */
    6620          264 :         if ((align & (align - 1)))
    6621              :           align = 0;
    6622              : 
    6623              :         /* The maximum alignment in bits corresponding to the same
    6624              :            maximum in bytes enforced in check_user_alignment().  */
    6625          315 :         unsigned maxalign = (UINT_MAX >> 1) + 1;
    6626              : 
    6627              :         /* Reject invalid alignments.  */
    6628          181 :         if (align < BITS_PER_UNIT || maxalign < align)
    6629              :           {
    6630          134 :             if (complain)
    6631          169 :               error_at (ARG_LOCATION (1),
    6632              :                         "second argument to function %qE must be a constant "
    6633              :                         "integer power of 2 between %qi and %qu bits",
    6634              :                         fndecl, BITS_PER_UNIT, maxalign);
    6635          134 :             return false;
    6636              :           }
    6637              :         return true;
    6638              :       }
    6639              : 
    6640       185653 :     case BUILT_IN_CONSTANT_P:
    6641       185653 :       return builtin_function_validate_nargs (loc, fndecl, nargs, 1, complain);
    6642              : 
    6643       193479 :     case BUILT_IN_ISFINITE:
    6644       193479 :     case BUILT_IN_ISINF:
    6645       193479 :     case BUILT_IN_ISINF_SIGN:
    6646       193479 :     case BUILT_IN_ISNAN:
    6647       193479 :     case BUILT_IN_ISNORMAL:
    6648       193479 :     case BUILT_IN_ISSIGNALING:
    6649       193479 :     case BUILT_IN_SIGNBIT:
    6650       193479 :       if (builtin_function_validate_nargs (loc, fndecl, nargs, 1, complain))
    6651              :         {
    6652       193444 :           if (TREE_CODE (TREE_TYPE (args[0])) != REAL_TYPE)
    6653              :             {
    6654           37 :               if (complain)
    6655           28 :                 error_at (ARG_LOCATION (0),
    6656              :                           "non-floating-point argument in "
    6657              :                           "call to function %qE",
    6658              :                           fndecl);
    6659           37 :               return false;
    6660              :             }
    6661              :           return true;
    6662              :         }
    6663              :       return false;
    6664              : 
    6665       193720 :     case BUILT_IN_ISGREATER:
    6666       193720 :     case BUILT_IN_ISGREATEREQUAL:
    6667       193720 :     case BUILT_IN_ISLESS:
    6668       193720 :     case BUILT_IN_ISLESSEQUAL:
    6669       193720 :     case BUILT_IN_ISLESSGREATER:
    6670       193720 :     case BUILT_IN_ISUNORDERED:
    6671       193720 :     case BUILT_IN_ISEQSIG:
    6672       193720 :       if (builtin_function_validate_nargs (loc, fndecl, nargs, 2, complain))
    6673              :         {
    6674       193685 :           enum tree_code code0, code1;
    6675       193685 :           code0 = TREE_CODE (TREE_TYPE (args[0]));
    6676       193685 :           code1 = TREE_CODE (TREE_TYPE (args[1]));
    6677       193685 :           if (!((code0 == REAL_TYPE && code1 == REAL_TYPE)
    6678          154 :                 || (code0 == REAL_TYPE
    6679           56 :                     && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
    6680           99 :                 || ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
    6681           88 :                     && code1 == REAL_TYPE)))
    6682              :             {
    6683           39 :               if (complain)
    6684           18 :                 error_at (loc,
    6685              :                           "non-floating-point arguments in call to "
    6686              :                           "function %qE",
    6687              :                           fndecl);
    6688           39 :               return false;
    6689              :             }
    6690              :           return true;
    6691              :         }
    6692              :       return false;
    6693              : 
    6694        33004 :     case BUILT_IN_FPCLASSIFY:
    6695        33004 :       if (builtin_function_validate_nargs (loc, fndecl, nargs, 6, complain))
    6696              :         {
    6697       197952 :           for (unsigned int i = 0; i < 5; i++)
    6698       164964 :             if (TREE_CODE (args[i]) != INTEGER_CST)
    6699              :               {
    6700           12 :                 if (complain)
    6701           12 :                   error_at (ARG_LOCATION (i),
    6702              :                             "non-const integer argument %u in "
    6703              :                             "call to function %qE",
    6704              :                             i + 1, fndecl);
    6705           12 :                 return false;
    6706              :               }
    6707              : 
    6708        32988 :           if (TREE_CODE (TREE_TYPE (args[5])) != REAL_TYPE)
    6709              :             {
    6710            2 :               if (complain)
    6711            4 :                 error_at (ARG_LOCATION (5),
    6712              :                           "non-floating-point argument in "
    6713              :                           "call to function %qE",
    6714              :                           fndecl);
    6715            2 :               return false;
    6716              :             }
    6717              :           return true;
    6718              :         }
    6719              :       return false;
    6720              : 
    6721          435 :     case BUILT_IN_ASSUME_ALIGNED:
    6722          850 :       if (builtin_function_validate_nargs (loc, fndecl, nargs, 2 + (nargs > 2),
    6723              :                                            complain))
    6724              :         {
    6725          433 :           if (nargs >= 3
    6726           18 :               && TREE_CODE (TREE_TYPE (args[2])) != INTEGER_TYPE
    6727          440 :               && TREE_CODE (TREE_TYPE (args[2])) != BITINT_TYPE)
    6728              :             {
    6729            6 :               if (complain)
    6730            6 :                 error_at (ARG_LOCATION (2),
    6731              :                           "non-integer argument 3 in call to "
    6732              :                           "function %qE",
    6733              :                           fndecl);
    6734            6 :               return false;
    6735              :             }
    6736              :           return true;
    6737              :         }
    6738              :       return false;
    6739              : 
    6740       151348 :     case BUILT_IN_ADD_OVERFLOW:
    6741       151348 :     case BUILT_IN_SUB_OVERFLOW:
    6742       151348 :     case BUILT_IN_MUL_OVERFLOW:
    6743       151348 :       if (builtin_function_validate_nargs (loc, fndecl, nargs, 3, complain))
    6744              :         {
    6745              :           unsigned i;
    6746       453588 :           for (i = 0; i < 2; i++)
    6747       302418 :             if (!INTEGRAL_TYPE_P (TREE_TYPE (args[i])))
    6748              :               {
    6749           55 :                 if (complain)
    6750           77 :                   error_at (ARG_LOCATION (i),
    6751              :                             "argument %u in call to function "
    6752              :                             "%qE does not have integral type",
    6753              :                             i + 1, fndecl);
    6754           55 :                 return false;
    6755              :               }
    6756       151170 :           if (TREE_CODE (TREE_TYPE (args[2])) != POINTER_TYPE
    6757       151170 :               || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (args[2]))))
    6758              :             {
    6759           60 :               if (complain)
    6760           75 :                 error_at (ARG_LOCATION (2),
    6761              :                           "argument 3 in call to function %qE "
    6762              :                           "does not have pointer to integral type",
    6763              :                           fndecl);
    6764           60 :               return false;
    6765              :             }
    6766       151110 :           else if (TREE_CODE (TREE_TYPE (TREE_TYPE (args[2]))) == ENUMERAL_TYPE)
    6767              :             {
    6768           16 :               if (complain)
    6769           11 :                 error_at (ARG_LOCATION (2),
    6770              :                           "argument 3 in call to function %qE "
    6771              :                           "has pointer to enumerated type",
    6772              :                           fndecl);
    6773           16 :               return false;
    6774              :             }
    6775       151094 :           else if (TREE_CODE (TREE_TYPE (TREE_TYPE (args[2]))) == BOOLEAN_TYPE)
    6776              :             {
    6777           21 :               if (complain)
    6778           16 :                 error_at (ARG_LOCATION (2),
    6779              :                           "argument 3 in call to function %qE "
    6780              :                           "has pointer to boolean type",
    6781              :                           fndecl);
    6782           21 :               return false;
    6783              :             }
    6784       151073 :           else if (TYPE_READONLY (TREE_TYPE (TREE_TYPE (args[2]))))
    6785              :             {
    6786           30 :               if (complain)
    6787           30 :                 error_at (ARG_LOCATION (2),
    6788              :                           "argument %u in call to function %qE "
    6789              :                           "has pointer to %qs type (%qT)",
    6790           21 :                           3, fndecl, "const", TREE_TYPE (args[2]));
    6791           30 :               return false;
    6792              :             }
    6793       151043 :           else if (TYPE_ATOMIC (TREE_TYPE (TREE_TYPE (args[2]))))
    6794              :             {
    6795            6 :               if (complain)
    6796           12 :                 error_at (ARG_LOCATION (2),
    6797              :                           "argument %u in call to function %qE "
    6798              :                           "has pointer to %qs type (%qT)",
    6799            6 :                           3, fndecl, "_Atomic", TREE_TYPE (args[2]));
    6800            6 :               return false;
    6801              :             }
    6802              :           return true;
    6803              :         }
    6804              :       return false;
    6805              : 
    6806        41868 :     case BUILT_IN_ADD_OVERFLOW_P:
    6807        41868 :     case BUILT_IN_SUB_OVERFLOW_P:
    6808        41868 :     case BUILT_IN_MUL_OVERFLOW_P:
    6809        41868 :       if (builtin_function_validate_nargs (loc, fndecl, nargs, 3, complain))
    6810              :         {
    6811              :           unsigned i;
    6812       167261 :           for (i = 0; i < 3; i++)
    6813       125463 :             if (!INTEGRAL_TYPE_P (TREE_TYPE (args[i])))
    6814              :               {
    6815           37 :                 if (complain)
    6816           35 :                   error_at (ARG_LOCATION (i),
    6817              :                             "argument %u in call to function "
    6818              :                             "%qE does not have integral type",
    6819              :                             i + 1, fndecl);
    6820           37 :                 return false;
    6821              :               }
    6822        41798 :           if (TREE_CODE (TREE_TYPE (args[2])) == ENUMERAL_TYPE)
    6823              :             {
    6824           13 :               if (complain)
    6825            5 :                 error_at (ARG_LOCATION (2),
    6826              :                           "argument %u in call to function "
    6827              :                           "%qE has enumerated type",
    6828              :                           3, fndecl);
    6829           13 :               return false;
    6830              :             }
    6831        41785 :           else if (TREE_CODE (TREE_TYPE (args[2])) == BOOLEAN_TYPE)
    6832              :             {
    6833           13 :               if (complain)
    6834            5 :                 error_at (ARG_LOCATION (2),
    6835              :                           "argument %u in call to function "
    6836              :                           "%qE has boolean type",
    6837              :                           3, fndecl);
    6838           13 :               return false;
    6839              :             }
    6840              :           return true;
    6841              :         }
    6842              :       return false;
    6843              : 
    6844        13105 :     case BUILT_IN_CLEAR_PADDING:
    6845        13105 :       if (builtin_function_validate_nargs (loc, fndecl, nargs, 1, complain))
    6846              :         {
    6847        13090 :           if (!POINTER_TYPE_P (TREE_TYPE (args[0])))
    6848              :             {
    6849            7 :               if (complain)
    6850            5 :                 error_at (ARG_LOCATION (0),
    6851              :                           "argument %u in call to function "
    6852              :                           "%qE does not have pointer type",
    6853              :                           1, fndecl);
    6854            7 :               return false;
    6855              :             }
    6856        13083 :           else if (!COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (args[0]))))
    6857              :             {
    6858           11 :               if (complain)
    6859           10 :                 error_at (ARG_LOCATION (0),
    6860              :                           "argument %u in call to function "
    6861              :                           "%qE points to incomplete type",
    6862              :                           1, fndecl);
    6863           11 :               return false;
    6864              :             }
    6865        13072 :           else if (TYPE_READONLY (TREE_TYPE (TREE_TYPE (args[0]))))
    6866              :             {
    6867            7 :               if (complain)
    6868            5 :                 error_at (ARG_LOCATION (0),
    6869              :                           "argument %u in call to function %qE "
    6870              :                           "has pointer to %qs type (%qT)",
    6871            4 :                           1, fndecl, "const", TREE_TYPE (args[0]));
    6872            7 :               return false;
    6873              :             }
    6874        13065 :           else if (TYPE_ATOMIC (TREE_TYPE (TREE_TYPE (args[0]))))
    6875              :             {
    6876            0 :               if (complain)
    6877            0 :                 error_at (ARG_LOCATION (0),
    6878              :                           "argument %u in call to function %qE "
    6879              :                           "has pointer to %qs type (%qT)",
    6880            0 :                           1, fndecl, "_Atomic", TREE_TYPE (args[0]));
    6881            0 :               return false;
    6882              :             }
    6883              :           return true;
    6884              :         }
    6885              :       return false;
    6886              : 
    6887        95787 :     case BUILT_IN_CLZG:
    6888        95787 :     case BUILT_IN_CTZG:
    6889        95787 :     case BUILT_IN_CLRSBG:
    6890        95787 :     case BUILT_IN_FFSG:
    6891        95787 :     case BUILT_IN_PARITYG:
    6892        95787 :     case BUILT_IN_POPCOUNTG:
    6893        95787 :       if (nargs == 2
    6894        95787 :           && (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CLZG
    6895        20970 :               || DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CTZG))
    6896              :         {
    6897        55414 :           if (!INTEGRAL_TYPE_P (TREE_TYPE (args[1])))
    6898              :             {
    6899           18 :               if (complain)
    6900           15 :                 error_at (ARG_LOCATION (1),
    6901              :                           "argument %u in call to function "
    6902              :                           "%qE does not have integral type",
    6903              :                           2, fndecl);
    6904           18 :               return false;
    6905              :             }
    6906        55396 :           if ((TYPE_PRECISION (TREE_TYPE (args[1]))
    6907        55396 :                > TYPE_PRECISION (integer_type_node))
    6908        55396 :               || (TYPE_PRECISION (TREE_TYPE (args[1]))
    6909        55382 :                   == TYPE_PRECISION (integer_type_node)
    6910        55376 :                   && TYPE_UNSIGNED (TREE_TYPE (args[1]))))
    6911              :             {
    6912           28 :               if (complain)
    6913           26 :                 error_at (ARG_LOCATION (1),
    6914              :                           "argument %u in call to function "
    6915              :                           "%qE does not have %<int%> type",
    6916              :                           2, fndecl);
    6917           28 :               return false;
    6918              :             }
    6919              :         }
    6920        40373 :       else if (!builtin_function_validate_nargs (loc, fndecl, nargs, 1,
    6921              :                                                  complain))
    6922              :         return false;
    6923              : 
    6924        95675 :       if (!INTEGRAL_TYPE_P (TREE_TYPE (args[0])))
    6925              :         {
    6926           82 :           if (complain)
    6927           80 :             error_at (ARG_LOCATION (0),
    6928              :                       "argument %u in call to function "
    6929              :                       "%qE does not have integral type",
    6930              :                       1, fndecl);
    6931           82 :           return false;
    6932              :         }
    6933        95593 :       if (TREE_CODE (TREE_TYPE (args[0])) == ENUMERAL_TYPE)
    6934              :         {
    6935          202 :           if (complain)
    6936          224 :             error_at (ARG_LOCATION (0),
    6937              :                       "argument %u in call to function "
    6938              :                       "%qE has enumerated type",
    6939              :                       1, fndecl);
    6940          202 :           return false;
    6941              :         }
    6942        95391 :       if (TREE_CODE (TREE_TYPE (args[0])) == BOOLEAN_TYPE)
    6943              :         {
    6944           50 :           if (complain)
    6945           40 :             error_at (ARG_LOCATION (0),
    6946              :                       "argument %u in call to function "
    6947              :                       "%qE has boolean type",
    6948              :                       1, fndecl);
    6949           50 :           return false;
    6950              :         }
    6951        95341 :       if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_FFSG
    6952        95341 :           || DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CLRSBG)
    6953              :         {
    6954          290 :           if (TYPE_UNSIGNED (TREE_TYPE (args[0])))
    6955              :             {
    6956           14 :               if (complain)
    6957           10 :                 error_at (ARG_LOCATION (0),
    6958              :                           "argument 1 in call to function "
    6959              :                           "%qE has unsigned type",
    6960              :                           fndecl);
    6961           14 :               return false;
    6962              :             }
    6963              :         }
    6964        95051 :       else if (!TYPE_UNSIGNED (TREE_TYPE (args[0])))
    6965              :         {
    6966           42 :           if (complain)
    6967           42 :             error_at (ARG_LOCATION (0),
    6968              :                       "argument 1 in call to function "
    6969              :                       "%qE has signed type",
    6970              :                       fndecl);
    6971           42 :           return false;
    6972              :         }
    6973              :       return true;
    6974              : 
    6975              :     default:
    6976              :       return true;
    6977              :     }
    6978              : }
    6979              : 
    6980              : /* Subroutine of c_parse_error.
    6981              :    Return the result of concatenating LHS and RHS. RHS is really
    6982              :    a string literal, its first character is indicated by RHS_START and
    6983              :    RHS_SIZE is its length (including the terminating NUL character).
    6984              : 
    6985              :    The caller is responsible for deleting the returned pointer.  */
    6986              : 
    6987              : static char *
    6988         8992 : catenate_strings (const char *lhs, const char *rhs_start, int rhs_size)
    6989              : {
    6990         8992 :   const size_t lhs_size = strlen (lhs);
    6991         8992 :   char *result = XNEWVEC (char, lhs_size + rhs_size);
    6992         8992 :   memcpy (result, lhs, lhs_size);
    6993         8992 :   memcpy (result + lhs_size, rhs_start, rhs_size);
    6994         8992 :   return result;
    6995              : }
    6996              : 
    6997              : /* Issue the error given by GMSGID at RICHLOC, indicating that it occurred
    6998              :    before TOKEN, which had the associated VALUE.  */
    6999              : 
    7000              : void
    7001         9005 : c_parse_error (const char *gmsgid, enum cpp_ttype token_type,
    7002              :                tree value, unsigned char token_flags,
    7003              :                rich_location *richloc)
    7004              : {
    7005              : #define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2))
    7006              : 
    7007         9005 :   char *message = NULL;
    7008              : 
    7009         9005 :   if (token_type == CPP_EOF)
    7010          508 :     message = catenate_messages (gmsgid, " at end of input");
    7011         8497 :   else if (token_type == CPP_CHAR
    7012              :            || token_type == CPP_WCHAR
    7013              :            || token_type == CPP_CHAR16
    7014              :            || token_type == CPP_CHAR32
    7015         8497 :            || token_type == CPP_UTF8CHAR)
    7016              :     {
    7017           24 :       unsigned int val = TREE_INT_CST_LOW (value);
    7018           24 :       const char *prefix;
    7019              : 
    7020           24 :       switch (token_type)
    7021              :         {
    7022              :         default:
    7023              :           prefix = "";
    7024              :           break;
    7025            0 :         case CPP_WCHAR:
    7026            0 :           prefix = "L";
    7027            0 :           break;
    7028            0 :         case CPP_CHAR16:
    7029            0 :           prefix = "u";
    7030            0 :           break;
    7031            0 :         case CPP_CHAR32:
    7032            0 :           prefix = "U";
    7033            0 :           break;
    7034            0 :         case CPP_UTF8CHAR:
    7035            0 :           prefix = "u8";
    7036            0 :           break;
    7037              :         }
    7038              : 
    7039           24 :       if (val <= UCHAR_MAX && ISGRAPH (val))
    7040           20 :         message = catenate_messages (gmsgid, " before %s'%c'");
    7041              :       else
    7042            4 :         message = catenate_messages (gmsgid, " before %s'\\x%x'");
    7043              : 
    7044           24 :       error_at (richloc, message, prefix, val);
    7045           24 :       free (message);
    7046           24 :       message = NULL;
    7047              :     }
    7048         8473 :   else if (token_type == CPP_CHAR_USERDEF
    7049              :            || token_type == CPP_WCHAR_USERDEF
    7050              :            || token_type == CPP_CHAR16_USERDEF
    7051              :            || token_type == CPP_CHAR32_USERDEF
    7052         8473 :            || token_type == CPP_UTF8CHAR_USERDEF)
    7053           12 :     message = catenate_messages (gmsgid,
    7054              :                                  " before user-defined character literal");
    7055         8461 :   else if (token_type == CPP_STRING_USERDEF
    7056              :            || token_type == CPP_WSTRING_USERDEF
    7057              :            || token_type == CPP_STRING16_USERDEF
    7058              :            || token_type == CPP_STRING32_USERDEF
    7059         8461 :            || token_type == CPP_UTF8STRING_USERDEF)
    7060           25 :     message = catenate_messages (gmsgid, " before user-defined string literal");
    7061         8436 :   else if (token_type == CPP_STRING
    7062              :            || token_type == CPP_WSTRING
    7063              :            || token_type == CPP_STRING16
    7064              :            || token_type == CPP_STRING32
    7065         8436 :            || token_type == CPP_UTF8STRING)
    7066           44 :     message = catenate_messages (gmsgid, " before string constant");
    7067         8392 :   else if (token_type == CPP_NUMBER)
    7068          539 :     message = catenate_messages (gmsgid, " before numeric constant");
    7069         7853 :   else if (token_type == CPP_NAME)
    7070              :     {
    7071         2139 :       message = catenate_messages (gmsgid, " before %qE");
    7072         2139 :       error_at (richloc, message, value);
    7073         2139 :       free (message);
    7074         2139 :       message = NULL;
    7075              :     }
    7076         5714 :   else if (token_type == CPP_PRAGMA)
    7077           20 :     message = catenate_messages (gmsgid, " before %<#pragma%>");
    7078         5694 :   else if (token_type == CPP_PRAGMA_EOL)
    7079          474 :     message = catenate_messages (gmsgid, " before end of line");
    7080         5220 :   else if (token_type == CPP_DECLTYPE)
    7081           12 :     message = catenate_messages (gmsgid, " before %<decltype%>");
    7082         5208 :   else if (token_type == CPP_EMBED)
    7083            0 :     message = catenate_messages (gmsgid, " before %<#embed%>");
    7084         5208 :   else if (token_type < N_TTYPES)
    7085              :     {
    7086         5195 :       message = catenate_messages (gmsgid, " before %qs token");
    7087         5195 :       error_at (richloc, message, cpp_type2name (token_type, token_flags));
    7088         5195 :       free (message);
    7089         5195 :       message = NULL;
    7090              :     }
    7091              :   else
    7092           13 :     error_at (richloc, gmsgid);
    7093              : 
    7094         9005 :   if (message)
    7095              :     {
    7096         1634 :       error_at (richloc, message);
    7097         1634 :       free (message);
    7098              :     }
    7099              : #undef catenate_messages
    7100         9005 : }
    7101              : 
    7102              : /* Return the gcc option code associated with the reason for a cpp
    7103              :    message, or 0 if none.  */
    7104              : 
    7105              : static diagnostics::option_id
    7106       144452 : c_option_controlling_cpp_diagnostic (enum cpp_warning_reason reason)
    7107              : {
    7108       144452 :   const struct cpp_reason_option_codes_t *entry;
    7109              : 
    7110      4158637 :   for (entry = cpp_reason_option_codes; entry->reason != CPP_W_NONE; entry++)
    7111              :     {
    7112      4151520 :       if (entry->reason == reason)
    7113       137335 :         return entry->option_code;
    7114              :     }
    7115            0 :   return 0;
    7116              : }
    7117              : 
    7118              : /* Return TRUE if the given option index corresponds to a diagnostic
    7119              :    issued by libcpp.  Linear search seems fine for now.  */
    7120              : bool
    7121      2470423 : c_option_is_from_cpp_diagnostics (int option_index)
    7122              : {
    7123     57123509 :   for (auto entry = cpp_reason_option_codes; entry->reason != CPP_W_NONE;
    7124              :        ++entry)
    7125              :     {
    7126     56217214 :       if (entry->option_code == option_index)
    7127              :         return true;
    7128              :     }
    7129              :   return false;
    7130              : }
    7131              : 
    7132              : /* Callback from cpp_diagnostic for PFILE to print diagnostics from the
    7133              :    preprocessor.  The diagnostic is of type LEVEL, with REASON set
    7134              :    to the reason code if LEVEL is represents a warning, at location
    7135              :    RICHLOC unless this is after lexing and the compiler's location
    7136              :    should be used instead; MSG is the translated message and AP
    7137              :    the arguments.  Returns true if a diagnostic was emitted, false
    7138              :    otherwise.  */
    7139              : 
    7140              : bool
    7141       144462 : c_cpp_diagnostic (cpp_reader *pfile ATTRIBUTE_UNUSED,
    7142              :                   enum cpp_diagnostic_level level,
    7143              :                   enum cpp_warning_reason reason,
    7144              :                   rich_location *richloc,
    7145              :                   const char *msg, va_list *ap)
    7146              : {
    7147       144462 :   diagnostics::diagnostic_info diagnostic;
    7148       144462 :   enum diagnostics::kind dlevel;
    7149       144462 :   bool save_warn_system_headers = global_dc->m_warn_system_headers;
    7150       144462 :   bool ret;
    7151              : 
    7152       144462 :   switch (level)
    7153              :     {
    7154           97 :     case CPP_DL_WARNING_SYSHDR:
    7155           97 :       if (flag_no_output)
    7156              :         return false;
    7157           96 :       global_dc->m_warn_system_headers = 1;
    7158              :       /* Fall through.  */
    7159        24679 :     case CPP_DL_WARNING:
    7160        24679 :       if (flag_no_output)
    7161              :         return false;
    7162              :       dlevel = diagnostics::kind::warning;
    7163              :       break;
    7164       114530 :     case CPP_DL_PEDWARN:
    7165       114530 :       if (flag_no_output && !flag_pedantic_errors)
    7166              :         return false;
    7167              :       dlevel = diagnostics::kind::pedwarn;
    7168              :       break;
    7169              :     case CPP_DL_ERROR:
    7170              :       dlevel = diagnostics::kind::error;
    7171              :       break;
    7172            0 :     case CPP_DL_ICE:
    7173            0 :       dlevel = diagnostics::kind::ice;
    7174            0 :       break;
    7175          605 :     case CPP_DL_NOTE:
    7176          605 :       dlevel = diagnostics::kind::note;
    7177          605 :       break;
    7178          377 :     case CPP_DL_FATAL:
    7179          377 :       dlevel = diagnostics::kind::fatal;
    7180          377 :       break;
    7181            0 :     default:
    7182            0 :       gcc_unreachable ();
    7183              :     }
    7184       144452 :   if (override_libcpp_locations)
    7185          263 :     richloc->set_range (0, input_location, SHOW_RANGE_WITH_CARET);
    7186       144452 :   diagnostic_set_info_translated (&diagnostic, msg, ap,
    7187              :                                   richloc, dlevel);
    7188       288904 :   diagnostic_set_option_id (&diagnostic,
    7189              :                             c_option_controlling_cpp_diagnostic (reason));
    7190       144452 :   ret = diagnostic_report_diagnostic (global_dc, &diagnostic);
    7191       144075 :   if (level == CPP_DL_WARNING_SYSHDR)
    7192           96 :     global_dc->m_warn_system_headers = save_warn_system_headers;
    7193              :   return ret;
    7194       144085 : }
    7195              : 
    7196              : /* Convert a character from the host to the target execution character
    7197              :    set.  cpplib handles this, mostly.  */
    7198              : 
    7199              : HOST_WIDE_INT
    7200      6601185 : c_common_to_target_charset (HOST_WIDE_INT c)
    7201              : {
    7202              :   /* Character constants in GCC proper are sign-extended under -fsigned-char,
    7203              :      zero-extended under -fno-signed-char.  cpplib insists that characters
    7204              :      and character constants are always unsigned.  Hence we must convert
    7205              :      back and forth.  */
    7206      6601185 :   cppchar_t uc = ((cppchar_t)c) & ((((cppchar_t)1) << CHAR_BIT)-1);
    7207              : 
    7208      6601185 :   uc = cpp_host_to_exec_charset (parse_in, uc);
    7209              : 
    7210      6601185 :   if (flag_signed_char)
    7211      6601088 :     return ((HOST_WIDE_INT)uc) << (HOST_BITS_PER_WIDE_INT - CHAR_TYPE_SIZE)
    7212      6601088 :                                >> (HOST_BITS_PER_WIDE_INT - CHAR_TYPE_SIZE);
    7213              :   else
    7214           97 :     return uc;
    7215              : }
    7216              : 
    7217              : /* Fold an offsetof-like expression.  EXPR is a nested sequence of component
    7218              :    references with an INDIRECT_REF of a constant at the bottom; much like the
    7219              :    traditional rendering of offsetof as a macro.  TYPE is the desired type of
    7220              :    the whole expression.  Return the folded result.  */
    7221              : 
    7222              : tree
    7223        15245 : fold_offsetof (tree expr, tree type, enum tree_code ctx)
    7224              : {
    7225        15255 :   tree base, off, t;
    7226        15255 :   tree_code code = TREE_CODE (expr);
    7227        15255 :   switch (code)
    7228              :     {
    7229              :     case ERROR_MARK:
    7230              :       return expr;
    7231              : 
    7232            1 :     case REALPART_EXPR:
    7233            1 :      return fold_offsetof (TREE_OPERAND (expr, 0), type, code);
    7234              : 
    7235            1 :     case IMAGPART_EXPR:
    7236            1 :      base = fold_offsetof (TREE_OPERAND (expr, 0), type, code);
    7237            1 :      if (base == error_mark_node)
    7238              :         return base;
    7239            1 :      off = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (TREE_OPERAND (expr, 0))));
    7240            1 :      break;
    7241              : 
    7242           12 :     case VAR_DECL:
    7243           12 :       error ("cannot apply %<offsetof%> to static data member %qD", expr);
    7244           12 :       return error_mark_node;
    7245              : 
    7246            9 :     case CALL_EXPR:
    7247            9 :     case TARGET_EXPR:
    7248            9 :       error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded");
    7249            9 :       return error_mark_node;
    7250              : 
    7251         6702 :     case NOP_EXPR:
    7252         6702 :     case INDIRECT_REF:
    7253         6702 :       if (!TREE_CONSTANT (TREE_OPERAND (expr, 0)))
    7254              :         {
    7255           17 :           error ("cannot apply %<offsetof%> to a non constant address");
    7256           17 :           return error_mark_node;
    7257              :         }
    7258         6685 :       return convert (type, TREE_OPERAND (expr, 0));
    7259              : 
    7260         7290 :     case COMPONENT_REF:
    7261         7290 :       base = fold_offsetof (TREE_OPERAND (expr, 0), type, code);
    7262         7290 :       if (base == error_mark_node)
    7263              :         return base;
    7264              : 
    7265         7287 :       t = TREE_OPERAND (expr, 1);
    7266         7287 :       if (DECL_C_BIT_FIELD (t))
    7267              :         {
    7268            1 :           error ("attempt to take address of bit-field structure "
    7269              :                  "member %qD", t);
    7270            1 :           return error_mark_node;
    7271              :         }
    7272         7286 :       off = size_binop_loc (input_location, PLUS_EXPR, DECL_FIELD_OFFSET (t),
    7273         7286 :                             size_int (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (t))
    7274              :                                       / BITS_PER_UNIT));
    7275         7286 :       break;
    7276              : 
    7277         1230 :     case ARRAY_REF:
    7278         1230 :       base = fold_offsetof (TREE_OPERAND (expr, 0), type, code);
    7279         1230 :       if (base == error_mark_node)
    7280              :         return base;
    7281              : 
    7282         1227 :       t = TREE_OPERAND (expr, 1);
    7283         1227 :       STRIP_ANY_LOCATION_WRAPPER (t);
    7284              : 
    7285              :       /* Check if the offset goes beyond the upper bound of the array.  */
    7286         1227 :       if (TREE_CODE (t) == INTEGER_CST && tree_int_cst_sgn (t) >= 0)
    7287              :         {
    7288          956 :           tree upbound = array_ref_up_bound (expr);
    7289          956 :           if (upbound != NULL_TREE
    7290          844 :               && TREE_CODE (upbound) == INTEGER_CST
    7291         1800 :               && !tree_int_cst_equal (upbound,
    7292          844 :                                       TYPE_MAX_VALUE (TREE_TYPE (upbound))))
    7293              :             {
    7294          835 :               if (ctx != ARRAY_REF && ctx != COMPONENT_REF)
    7295          433 :                 upbound = size_binop (PLUS_EXPR, upbound,
    7296              :                                       build_int_cst (TREE_TYPE (upbound), 1));
    7297          835 :               if (tree_int_cst_lt (upbound, t))
    7298              :                 {
    7299          244 :                   tree v;
    7300              : 
    7301          244 :                   for (v = TREE_OPERAND (expr, 0);
    7302          420 :                        TREE_CODE (v) == COMPONENT_REF;
    7303          176 :                        v = TREE_OPERAND (v, 0))
    7304          280 :                     if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0)))
    7305              :                         == RECORD_TYPE)
    7306              :                       {
    7307          220 :                         tree fld_chain = DECL_CHAIN (TREE_OPERAND (v, 1));
    7308          307 :                         for (; fld_chain; fld_chain = DECL_CHAIN (fld_chain))
    7309          191 :                           if (TREE_CODE (fld_chain) == FIELD_DECL)
    7310              :                             break;
    7311              : 
    7312              :                         if (fld_chain)
    7313              :                           break;
    7314              :                       }
    7315              :                   /* Don't warn if the array might be considered a poor
    7316              :                      man's flexible array member with a very permissive
    7317              :                      definition thereof.  */
    7318          244 :                   if (TREE_CODE (v) == ARRAY_REF
    7319          172 :                       || TREE_CODE (v) == COMPONENT_REF)
    7320          176 :                     warning (OPT_Warray_bounds_,
    7321              :                              "index %E denotes an offset "
    7322              :                              "greater than size of %qT",
    7323          176 :                              t, TREE_TYPE (TREE_OPERAND (expr, 0)));
    7324              :                 }
    7325              :             }
    7326              :         }
    7327              : 
    7328         1227 :       t = convert (sizetype, t);
    7329         1227 :       off = size_binop (MULT_EXPR, TYPE_SIZE_UNIT (TREE_TYPE (expr)), t);
    7330         1227 :       break;
    7331              : 
    7332            9 :     case COMPOUND_EXPR:
    7333              :       /* Handle static members of volatile structs.  */
    7334            9 :       t = TREE_OPERAND (expr, 1);
    7335            9 :       gcc_checking_assert (VAR_P (get_base_address (t)));
    7336              :       return fold_offsetof (t, type);
    7337              : 
    7338            0 :     default:
    7339            0 :       gcc_unreachable ();
    7340              :     }
    7341              : 
    7342         8514 :   if (!POINTER_TYPE_P (type))
    7343         7642 :     return size_binop (PLUS_EXPR, base, convert (type, off));
    7344          872 :   return fold_build_pointer_plus (base, off);
    7345              : }
    7346              : 
    7347              : /* *PTYPE is an incomplete array.  Complete it with a domain based on
    7348              :    INITIAL_VALUE.  If INITIAL_VALUE is not present, use 1 if DO_DEFAULT
    7349              :    is true.  Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
    7350              :    2 if INITIAL_VALUE was NULL, and 3 if INITIAL_VALUE was empty.  */
    7351              : 
    7352              : int
    7353       621132 : complete_array_type (tree *ptype, tree initial_value, bool do_default)
    7354              : {
    7355       621132 :   tree maxindex, type, main_type, elt, unqual_elt;
    7356       621132 :   int failure = 0, quals;
    7357       621132 :   bool overflow_p = false;
    7358              : 
    7359       621132 :   maxindex = size_zero_node;
    7360       621132 :   if (initial_value)
    7361              :     {
    7362       613642 :       STRIP_ANY_LOCATION_WRAPPER (initial_value);
    7363              : 
    7364       613642 :       if (TREE_CODE (initial_value) == STRING_CST)
    7365              :         {
    7366       460626 :           int eltsize
    7367       460626 :             = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value)));
    7368       460626 :           maxindex = size_int (TREE_STRING_LENGTH (initial_value) / eltsize
    7369              :                                - 1);
    7370              :         }
    7371       153016 :       else if (TREE_CODE (initial_value) == CONSTRUCTOR)
    7372              :         {
    7373       152081 :           vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (initial_value);
    7374              : 
    7375       152081 :           if (vec_safe_is_empty (v))
    7376              :             {
    7377          430 :               if (pedantic)
    7378           71 :                 failure = 3;
    7379          430 :               maxindex = ssize_int (-1);
    7380              :             }
    7381              :           else
    7382              :             {
    7383       151651 :               tree curindex;
    7384       151651 :               unsigned HOST_WIDE_INT cnt = 1;
    7385       151651 :               constructor_elt *ce;
    7386       151651 :               bool fold_p = false;
    7387              : 
    7388       151651 :               if ((*v)[0].index)
    7389       142064 :                 maxindex = (*v)[0].index, fold_p = true;
    7390       151651 :               if (TREE_CODE ((*v)[0].value) == RAW_DATA_CST)
    7391            4 :                 cnt = 0;
    7392              : 
    7393              :               curindex = maxindex;
    7394              : 
    7395     47699463 :               for (; vec_safe_iterate (v, cnt, &ce); cnt++)
    7396              :                 {
    7397     47547812 :                   bool curfold_p = false;
    7398     47547812 :                   if (ce->index)
    7399     47536949 :                     curindex = ce->index, curfold_p = true;
    7400     47547812 :                   if (!ce->index || TREE_CODE (ce->value) == RAW_DATA_CST)
    7401              :                     {
    7402        11239 :                       if (fold_p || curfold_p)
    7403              :                         {
    7404              :                           /* Since we treat size types now as ordinary
    7405              :                              unsigned types, we need an explicit overflow
    7406              :                              check.  */
    7407          376 :                           tree orig = curindex;
    7408          376 :                           curindex = fold_convert (sizetype, curindex);
    7409          376 :                           overflow_p |= tree_int_cst_lt (curindex, orig);
    7410          376 :                           curfold_p = false;
    7411              :                         }
    7412        11239 :                       if (TREE_CODE (ce->value) == RAW_DATA_CST)
    7413          376 :                         curindex
    7414          752 :                           = size_binop (PLUS_EXPR, curindex,
    7415              :                                         size_int (RAW_DATA_LENGTH (ce->value)
    7416              :                                                   - ((ce->index || !cnt)
    7417              :                                                      ? 1 : 0)));
    7418              :                       else
    7419        10863 :                         curindex = size_binop (PLUS_EXPR, curindex,
    7420              :                                                size_one_node);
    7421              :                     }
    7422     47547812 :                   if (tree_int_cst_lt (maxindex, curindex))
    7423     47547812 :                     maxindex = curindex, fold_p = curfold_p;
    7424              :                 }
    7425       151651 :               if (fold_p)
    7426              :                 {
    7427       142060 :                   tree orig = maxindex;
    7428       142060 :                   maxindex = fold_convert (sizetype, maxindex);
    7429       142060 :                   overflow_p |= tree_int_cst_lt (maxindex, orig);
    7430              :                 }
    7431              :             }
    7432              :         }
    7433              :       else
    7434              :         {
    7435              :           /* Make an error message unless that happened already.  */
    7436          935 :           if (initial_value != error_mark_node)
    7437           29 :             failure = 1;
    7438              :         }
    7439              :     }
    7440              :   else
    7441              :     {
    7442         7490 :       failure = 2;
    7443         7490 :       if (!do_default)
    7444              :         return failure;
    7445              :     }
    7446              : 
    7447       613738 :   type = *ptype;
    7448       613738 :   elt = TREE_TYPE (type);
    7449       613738 :   quals = TYPE_QUALS (strip_array_types (elt));
    7450       613738 :   if (quals == 0)
    7451              :     unqual_elt = elt;
    7452              :   else
    7453       586598 :     unqual_elt = c_build_qualified_type (elt, KEEP_QUAL_ADDR_SPACE (quals));
    7454              : 
    7455              :   /* Using build_distinct_type_copy and modifying things afterward instead
    7456              :      of using build_array_type to create a new type preserves all of the
    7457              :      TYPE_LANG_FLAG_? bits that the front end may have set.  */
    7458       613738 :   main_type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
    7459       613738 :   TREE_TYPE (main_type) = unqual_elt;
    7460      1227476 :   TYPE_DOMAIN (main_type)
    7461       613738 :     = build_range_type (TREE_TYPE (maxindex),
    7462       613738 :                         build_int_cst (TREE_TYPE (maxindex), 0), maxindex);
    7463       613738 :   TYPE_TYPELESS_STORAGE (main_type) = TYPE_TYPELESS_STORAGE (type);
    7464       613738 :   layout_type (main_type);
    7465              : 
    7466              :   /* Set TYPE_STRUCTURAL_EQUALITY_P early.  */
    7467       613738 :   if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type))
    7468      1227086 :       || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type)))
    7469          390 :     SET_TYPE_STRUCTURAL_EQUALITY (main_type);
    7470              :   else
    7471       613348 :     TYPE_CANONICAL (main_type) = main_type;
    7472              : 
    7473              :   /* Make sure we have the canonical MAIN_TYPE. */
    7474       613738 :   hashval_t hashcode = type_hash_canon_hash (main_type);
    7475       613738 :   main_type = type_hash_canon (hashcode, main_type);
    7476              : 
    7477              :   /* Fix the canonical type.  */
    7478       613738 :   if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type))
    7479      1227086 :       || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type)))
    7480          390 :     gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (main_type));
    7481       613348 :   else if (TYPE_CANONICAL (TREE_TYPE (main_type)) != TREE_TYPE (main_type)
    7482       613348 :            || (TYPE_CANONICAL (TYPE_DOMAIN (main_type))
    7483       569565 :                != TYPE_DOMAIN (main_type)))
    7484        43783 :     TYPE_CANONICAL (main_type)
    7485        87566 :       = build_array_type (TYPE_CANONICAL (TREE_TYPE (main_type)),
    7486        43783 :                           TYPE_CANONICAL (TYPE_DOMAIN (main_type)),
    7487        43783 :                           TYPE_TYPELESS_STORAGE (main_type));
    7488              : 
    7489       613738 :   if (quals == 0)
    7490              :     type = main_type;
    7491              :   else
    7492       586598 :     type = c_build_qualified_type (main_type, quals);
    7493              : 
    7494       613738 :   if (COMPLETE_TYPE_P (type)
    7495       613729 :       && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST
    7496      1227458 :       && (overflow_p || TREE_OVERFLOW (TYPE_SIZE_UNIT (type))))
    7497              :     {
    7498            4 :       error ("size of array is too large");
    7499              :       /* If we proceed with the array type as it is, we'll eventually
    7500              :          crash in tree_to_[su]hwi().  */
    7501            4 :       type = error_mark_node;
    7502              :     }
    7503              : 
    7504       613738 :   *ptype = type;
    7505       613738 :   return failure;
    7506              : }
    7507              : 
    7508              : /* INIT is an constructor of a structure with a flexible array member.
    7509              :    Complete the flexible array member with a domain based on it's value.  */
    7510              : void
    7511      8929908 : complete_flexible_array_elts (tree init)
    7512              : {
    7513      9037544 :   tree elt, type;
    7514              : 
    7515      9037544 :   if (init == NULL_TREE || TREE_CODE (init) != CONSTRUCTOR)
    7516              :     return;
    7517              : 
    7518       109369 :   if (vec_safe_is_empty (CONSTRUCTOR_ELTS (init)))
    7519              :     return;
    7520              : 
    7521       107890 :   elt = CONSTRUCTOR_ELTS (init)->last ().value;
    7522       107890 :   type = TREE_TYPE (elt);
    7523       107890 :   if (TREE_CODE (type) == ARRAY_TYPE
    7524       107890 :       && TYPE_SIZE (type) == NULL_TREE)
    7525          254 :     complete_array_type (&TREE_TYPE (elt), elt, false);
    7526              :   else
    7527              :     complete_flexible_array_elts (elt);
    7528              : }
    7529              : 
    7530              : /* Like c_mark_addressable but don't check register qualifier.  */
    7531              : void
    7532      1144654 : c_common_mark_addressable_vec (tree t)
    7533              : {
    7534      1327247 :   while (handled_component_p (t) || TREE_CODE (t) == C_MAYBE_CONST_EXPR)
    7535              :     {
    7536       182593 :       if (TREE_CODE (t) == C_MAYBE_CONST_EXPR)
    7537           37 :         t = C_MAYBE_CONST_EXPR_EXPR (t);
    7538              :       else
    7539       182556 :         t = TREE_OPERAND (t, 0);
    7540              :     }
    7541      1144654 :   if (!VAR_P (t)
    7542              :       && TREE_CODE (t) != PARM_DECL
    7543              :       && TREE_CODE (t) != COMPOUND_LITERAL_EXPR
    7544              :       && TREE_CODE (t) != TARGET_EXPR)
    7545              :     return;
    7546      1110560 :   if (!VAR_P (t) || !DECL_HARD_REGISTER (t))
    7547      1110491 :     TREE_ADDRESSABLE (t) = 1;
    7548      1110560 :   if (TREE_CODE (t) == COMPOUND_LITERAL_EXPR)
    7549          134 :     TREE_ADDRESSABLE (COMPOUND_LITERAL_EXPR_DECL (t)) = 1;
    7550      1110426 :   else if (TREE_CODE (t) == TARGET_EXPR)
    7551           29 :     TREE_ADDRESSABLE (TARGET_EXPR_SLOT (t)) = 1;
    7552              : }
    7553              : 
    7554              : 
    7555              : 
    7556              : /* Used to help initialize the builtin-types.def table.  When a type of
    7557              :    the correct size doesn't exist, use error_mark_node instead of NULL.
    7558              :    The later results in segfaults even when a decl using the type doesn't
    7559              :    get invoked.  */
    7560              : 
    7561              : tree
    7562      1206494 : builtin_type_for_size (int size, bool unsignedp)
    7563              : {
    7564      1206494 :   tree type = c_common_type_for_size (size, unsignedp);
    7565      1206494 :   return type ? type : error_mark_node;
    7566              : }
    7567              : 
    7568              : /* Work out the size of the first argument of a call to
    7569              :    __builtin_speculation_safe_value.  Only pointers and integral types
    7570              :    are permitted.  Return -1 if the argument type is not supported or
    7571              :    the size is too large; 0 if the argument type is a pointer or the
    7572              :    size if it is integral.  */
    7573              : static enum built_in_function
    7574          154 : speculation_safe_value_resolve_call (tree function, vec<tree, va_gc> *params,
    7575              :                                      bool complain)
    7576              : {
    7577              :   /* Type of the argument.  */
    7578          154 :   tree type;
    7579          154 :   int size;
    7580              : 
    7581          154 :   if (vec_safe_is_empty (params))
    7582              :     {
    7583           10 :       if (complain)
    7584           10 :         error ("too few arguments to function %qE", function);
    7585           10 :       return BUILT_IN_NONE;
    7586              :     }
    7587              : 
    7588          144 :   type = TREE_TYPE ((*params)[0]);
    7589          144 :   if (TREE_CODE (type) == ARRAY_TYPE && c_dialect_cxx ())
    7590              :     {
    7591              :       /* Force array-to-pointer decay for C++.   */
    7592            0 :       (*params)[0] = default_conversion ((*params)[0]);
    7593            0 :       type = TREE_TYPE ((*params)[0]);
    7594              :     }
    7595              : 
    7596          144 :   if (POINTER_TYPE_P (type))
    7597              :     return BUILT_IN_SPECULATION_SAFE_VALUE_PTR;
    7598              : 
    7599          128 :   if (!INTEGRAL_TYPE_P (type))
    7600           42 :     goto incompatible;
    7601              : 
    7602           86 :   if (!COMPLETE_TYPE_P (type))
    7603            0 :     goto incompatible;
    7604              : 
    7605           86 :   size = tree_to_uhwi (TYPE_SIZE_UNIT (type));
    7606           86 :   if (size == 1 || size == 2 || size == 4 || size == 8 || size == 16)
    7607           86 :     return ((enum built_in_function)
    7608          172 :             ((int) BUILT_IN_SPECULATION_SAFE_VALUE_1 + exact_log2 (size)));
    7609              : 
    7610            0 :  incompatible:
    7611              :   /* Issue the diagnostic only if the argument is valid, otherwise
    7612              :      it would be redundant at best and could be misleading.  */
    7613           42 :   if (type != error_mark_node && complain)
    7614            6 :     error ("operand type %qT is incompatible with argument %d of %qE",
    7615              :            type, 1, function);
    7616              : 
    7617              :   return BUILT_IN_NONE;
    7618              : }
    7619              : 
    7620              : /* Validate and coerce PARAMS, the arguments to ORIG_FUNCTION to fit
    7621              :    the prototype for FUNCTION.  The first argument is mandatory, a second
    7622              :    argument, if present, must be type compatible with the first.  */
    7623              : static bool
    7624          102 : speculation_safe_value_resolve_params (location_t loc, tree orig_function,
    7625              :                                        vec<tree, va_gc> *params, bool complain)
    7626              : {
    7627          102 :   tree val;
    7628              : 
    7629          102 :   if (params->length () == 0)
    7630              :     {
    7631            0 :       if (complain)
    7632            0 :         error_at (loc, "too few arguments to function %qE", orig_function);
    7633            0 :       return false;
    7634              :     }
    7635              : 
    7636          102 :   else if (params->length () > 2)
    7637              :     {
    7638           21 :       if (complain)
    7639            0 :         error_at (loc, "too many arguments to function %qE", orig_function);
    7640           21 :       return false;
    7641              :     }
    7642              : 
    7643           81 :   val = (*params)[0];
    7644           81 :   if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE)
    7645            0 :     val = default_conversion (val);
    7646           81 :   if (!(TREE_CODE (TREE_TYPE (val)) == POINTER_TYPE
    7647           65 :         || TREE_CODE (TREE_TYPE (val)) == INTEGER_TYPE))
    7648              :     {
    7649            0 :       if (complain)
    7650            0 :         error_at (loc, "expecting argument of type pointer or of type integer "
    7651              :                        "for argument 1");
    7652            0 :       return false;
    7653              :     }
    7654           81 :   (*params)[0] = val;
    7655              : 
    7656           81 :   if (params->length () == 2)
    7657              :     {
    7658           32 :       tree val2 = (*params)[1];
    7659           32 :       if (TREE_CODE (TREE_TYPE (val2)) == ARRAY_TYPE)
    7660            0 :         val2 = default_conversion (val2);
    7661           32 :       if (error_operand_p (val2))
    7662              :         return false;
    7663           40 :       if (!(TREE_TYPE (val) == TREE_TYPE (val2)
    7664            9 :             || useless_type_conversion_p (TREE_TYPE (val), TREE_TYPE (val2))))
    7665              :         {
    7666            9 :           if (complain)
    7667            0 :             error_at (loc, "both arguments must be compatible");
    7668            9 :           return false;
    7669              :         }
    7670           22 :       (*params)[1] = val2;
    7671              :     }
    7672              : 
    7673              :   return true;
    7674              : }
    7675              : 
    7676              : /* Cast the result of the builtin back to the type of the first argument,
    7677              :    preserving any qualifiers that it might have.  */
    7678              : static tree
    7679           71 : speculation_safe_value_resolve_return (tree first_param, tree result)
    7680              : {
    7681           71 :   tree ptype = TREE_TYPE (first_param);
    7682           71 :   tree rtype = TREE_TYPE (result);
    7683           71 :   ptype = TYPE_MAIN_VARIANT (ptype);
    7684              : 
    7685           71 :   if (tree_int_cst_equal (TYPE_SIZE (ptype), TYPE_SIZE (rtype)))
    7686           71 :     return convert (ptype, result);
    7687              : 
    7688              :   return result;
    7689              : }
    7690              : 
    7691              : /* A helper function for resolve_overloaded_builtin in resolving the
    7692              :    overloaded __sync_ builtins.  Returns a positive power of 2 if the
    7693              :    first operand of PARAMS is a pointer to a supported data type.
    7694              :    Returns 0 if an error is encountered.  Return -1 for _BitInt
    7695              :    __atomic*fetch* with unsupported type which should be handled by
    7696              :    a cas loop.
    7697              :    FETCH is true when FUNCTION is one of the _FETCH_OP_ or _OP_FETCH_
    7698              :    built-ins.  ORIG_FORMAT is for __sync_* rather than __atomic_*
    7699              :    built-ins.  */
    7700              : 
    7701              : static int
    7702       417858 : sync_resolve_size (tree function, vec<tree, va_gc> *params, bool fetch,
    7703              :                    bool orig_format, bool complain)
    7704              : {
    7705              :   /* Type of the argument.  */
    7706       417858 :   tree argtype;
    7707              :   /* Type the argument points to.  */
    7708       417858 :   tree type;
    7709       417858 :   int size;
    7710              : 
    7711       417858 :   if (vec_safe_is_empty (params))
    7712              :     {
    7713          106 :       if (complain)
    7714          106 :         error ("too few arguments to function %qE", function);
    7715          106 :       return 0;
    7716              :     }
    7717              : 
    7718       417752 :   argtype = type = TREE_TYPE ((*params)[0]);
    7719       417752 :   if (TREE_CODE (type) == ARRAY_TYPE && c_dialect_cxx ())
    7720              :     {
    7721              :       /* Force array-to-pointer decay for C++.  */
    7722            3 :       (*params)[0] = default_conversion ((*params)[0]);
    7723            3 :       type = TREE_TYPE ((*params)[0]);
    7724              :     }
    7725       417752 :   if (TREE_CODE (type) != POINTER_TYPE)
    7726         2127 :     goto incompatible;
    7727              : 
    7728       415625 :   type = TREE_TYPE (type);
    7729       415625 :   if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
    7730          265 :     goto incompatible;
    7731              : 
    7732       415360 :   if (!COMPLETE_TYPE_P (type))
    7733            2 :     goto incompatible;
    7734              : 
    7735       415358 :   if (fetch && TREE_CODE (type) == BOOLEAN_TYPE)
    7736           84 :     goto incompatible;
    7737              : 
    7738       415274 :   size = tree_to_uhwi (TYPE_SIZE_UNIT (type));
    7739       415274 :   if (size == 16
    7740         7678 :       && BITINT_TYPE_P (type)
    7741       415800 :       && !targetm.scalar_mode_supported_p (TImode))
    7742              :     {
    7743            0 :       if (fetch && !orig_format)
    7744              :         return -1;
    7745            0 :       goto incompatible;
    7746              :     }
    7747              : 
    7748       415274 :   if (size == 1 || size == 2 || size == 4 || size == 8 || size == 16)
    7749              :     return size;
    7750              : 
    7751          528 :   if (fetch && !orig_format && BITINT_TYPE_P (type))
    7752              :     return -1;
    7753              : 
    7754         2478 :  incompatible:
    7755              :   /* Issue the diagnostic only if the argument is valid, otherwise
    7756              :      it would be redundant at best and could be misleading.  */
    7757         2478 :   if (argtype != error_mark_node && complain)
    7758          920 :     error ("operand type %qT is incompatible with argument %d of %qE",
    7759              :            argtype, 1, function);
    7760              :   return 0;
    7761              : }
    7762              : 
    7763              : /* A helper function for resolve_overloaded_builtin.  Adds casts to
    7764              :    PARAMS to make arguments match up with those of FUNCTION.  Drops
    7765              :    the variadic arguments at the end.  Returns false if some error
    7766              :    was encountered; true on success.  */
    7767              : 
    7768              : static bool
    7769       414746 : sync_resolve_params (location_t loc, tree orig_function, tree function,
    7770              :                      vec<tree, va_gc> *params, bool orig_format, bool complain)
    7771              : {
    7772       414746 :   function_args_iterator iter;
    7773       414746 :   tree ptype;
    7774       414746 :   unsigned int parmnum;
    7775              : 
    7776       414746 :   function_args_iter_init (&iter, TREE_TYPE (function));
    7777              :   /* We've declared the implementation functions to use "volatile void *"
    7778              :      as the pointer parameter, so we shouldn't get any complaints from the
    7779              :      call to check_function_arguments what ever type the user used.  */
    7780       414746 :   function_args_iter_next (&iter);
    7781       414746 :   ptype = TREE_TYPE (TREE_TYPE ((*params)[0]));
    7782       414746 :   ptype = TYPE_MAIN_VARIANT (ptype);
    7783              : 
    7784              :   /* For the rest of the values, we need to cast these to FTYPE, so that we
    7785              :      don't get warnings for passing pointer types, etc.  */
    7786       414746 :   parmnum = 0;
    7787      2335268 :   while (1)
    7788              :     {
    7789      1375007 :       tree val, arg_type;
    7790              : 
    7791      1375007 :       arg_type = function_args_iter_cond (&iter);
    7792              :       /* XXX void_type_node belies the abstraction.  */
    7793      1375007 :       if (arg_type == void_type_node)
    7794              :         break;
    7795              : 
    7796       960319 :       ++parmnum;
    7797       960319 :       if (params->length () <= parmnum)
    7798              :         {
    7799           58 :           if (complain)
    7800            7 :             error_at (loc, "too few arguments to function %qE", orig_function);
    7801           58 :           return false;
    7802              :         }
    7803              : 
    7804              :       /* Only convert parameters if arg_type is unsigned integer type with
    7805              :          new format sync routines, i.e. don't attempt to convert pointer
    7806              :          arguments (e.g. EXPECTED argument of __atomic_compare_exchange_n),
    7807              :          bool arguments (e.g. WEAK argument) or signed int arguments (memmodel
    7808              :          kinds).  */
    7809       960261 :       if (TREE_CODE (arg_type) == INTEGER_TYPE && TYPE_UNSIGNED (arg_type))
    7810              :         {
    7811              :           /* Ideally for the first conversion we'd use convert_for_assignment
    7812              :              so that we get warnings for anything that doesn't match the pointer
    7813              :              type.  This isn't portable across the C and C++ front ends atm.  */
    7814       262966 :           val = (*params)[parmnum];
    7815       262966 :           val = convert (ptype, val);
    7816       262966 :           val = convert (arg_type, val);
    7817       262966 :           (*params)[parmnum] = val;
    7818              :         }
    7819              : 
    7820       960261 :       function_args_iter_next (&iter);
    7821       960261 :     }
    7822              : 
    7823              :   /* __atomic routines are not variadic.  */
    7824       414688 :   if (!orig_format && params->length () != parmnum + 1)
    7825              :     {
    7826          106 :       if (complain)
    7827          103 :         error_at (loc, "too many arguments to function %qE", orig_function);
    7828          106 :       return false;
    7829              :     }
    7830              : 
    7831              :   /* The definition of these primitives is variadic, with the remaining
    7832              :      being "an optional list of variables protected by the memory barrier".
    7833              :      No clue what that's supposed to mean, precisely, but we consider all
    7834              :      call-clobbered variables to be protected so we're safe.  */
    7835       414582 :   params->truncate (parmnum + 1);
    7836              : 
    7837       414582 :   return true;
    7838              : }
    7839              : 
    7840              : /* A helper function for resolve_overloaded_builtin.  Adds a cast to
    7841              :    RESULT to make it match the type of the first pointer argument in
    7842              :    PARAMS.  */
    7843              : 
    7844              : static tree
    7845       277624 : sync_resolve_return (tree first_param, tree result, bool orig_format)
    7846              : {
    7847       277624 :   tree ptype = TREE_TYPE (TREE_TYPE (first_param));
    7848       277624 :   tree rtype = TREE_TYPE (result);
    7849       277624 :   ptype = TYPE_MAIN_VARIANT (ptype);
    7850              : 
    7851              :   /* New format doesn't require casting unless the types are the same size.  */
    7852       277624 :   if (orig_format || tree_int_cst_equal (TYPE_SIZE (ptype), TYPE_SIZE (rtype)))
    7853       277624 :     return convert (ptype, result);
    7854              :   else
    7855              :     return result;
    7856              : }
    7857              : 
    7858              : /* This function verifies the PARAMS to generic atomic FUNCTION.
    7859              :    It returns the size if all the parameters are the same size, otherwise
    7860              :    0 is returned if the parameters are invalid.  */
    7861              : 
    7862              : static int
    7863       129924 : get_atomic_generic_size (location_t loc, tree function,
    7864              :                          vec<tree, va_gc> *params, bool complain)
    7865              : {
    7866       129924 :   unsigned int n_param;
    7867       129924 :   unsigned int n_model;
    7868       129924 :   unsigned int outputs = 0; // bitset of output parameters
    7869       129924 :   unsigned int x;
    7870       129924 :   int size_0;
    7871       129924 :   tree type_0;
    7872              : 
    7873              :   /* Determine the parameter makeup.  */
    7874       129924 :   switch (DECL_FUNCTION_CODE (function))
    7875              :     {
    7876              :     case BUILT_IN_ATOMIC_EXCHANGE:
    7877              :       n_param = 4;
    7878              :       n_model = 1;
    7879              :       outputs = 5;
    7880              :       break;
    7881        76886 :     case BUILT_IN_ATOMIC_LOAD:
    7882        76886 :       n_param = 3;
    7883        76886 :       n_model = 1;
    7884        76886 :       outputs = 2;
    7885        76886 :       break;
    7886        11482 :     case BUILT_IN_ATOMIC_STORE:
    7887        11482 :       n_param = 3;
    7888        11482 :       n_model = 1;
    7889        11482 :       outputs = 1;
    7890        11482 :       break;
    7891        40925 :     case BUILT_IN_ATOMIC_COMPARE_EXCHANGE:
    7892        40925 :       n_param = 6;
    7893        40925 :       n_model = 2;
    7894        40925 :       outputs = 3;
    7895        40925 :       break;
    7896            0 :     default:
    7897            0 :       gcc_unreachable ();
    7898              :     }
    7899              : 
    7900       129924 :   if (vec_safe_length (params) != n_param)
    7901              :     {
    7902          466 :       if (complain)
    7903          247 :         error_at (loc, "incorrect number of arguments to function %qE",
    7904              :                   function);
    7905          466 :       return 0;
    7906              :     }
    7907              : 
    7908              :   /* Get type of first parameter, and determine its size.  */
    7909       129458 :   type_0 = TREE_TYPE ((*params)[0]);
    7910       129458 :   if (TREE_CODE (type_0) == ARRAY_TYPE && c_dialect_cxx ())
    7911              :     {
    7912              :       /* Force array-to-pointer decay for C++.  */
    7913           15 :       (*params)[0] = default_conversion ((*params)[0]);
    7914           15 :       type_0 = TREE_TYPE ((*params)[0]);
    7915              :     }
    7916       129458 :   if (TREE_CODE (type_0) != POINTER_TYPE || VOID_TYPE_P (TREE_TYPE (type_0)))
    7917              :     {
    7918          152 :       if (complain)
    7919           41 :         error_at (loc, "argument 1 of %qE must be a non-void pointer type",
    7920              :                   function);
    7921          152 :       return 0;
    7922              :     }
    7923              : 
    7924       129306 :   if (!COMPLETE_TYPE_P (TREE_TYPE (type_0)))
    7925              :     {
    7926           23 :       if (complain)
    7927            8 :         error_at (loc, "argument 1 of %qE must be a pointer to a complete type",
    7928              :                   function);
    7929           23 :       return 0;
    7930              :     }
    7931              : 
    7932              :   /* Types must be compile time constant sizes. */
    7933       129283 :   if (!tree_fits_uhwi_p ((TYPE_SIZE_UNIT (TREE_TYPE (type_0)))))
    7934              :     {
    7935            1 :       if (complain)
    7936            1 :         error_at (loc,
    7937              :                   "argument 1 of %qE must be a pointer to a constant size type",
    7938              :                   function);
    7939            1 :       return 0;
    7940              :     }
    7941              : 
    7942       129282 :   size_0 = tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type_0)));
    7943              : 
    7944              :   /* Zero size objects are not allowed.  */
    7945       129282 :   if (size_0 == 0)
    7946              :     {
    7947           22 :       if (complain)
    7948            7 :         error_at (
    7949              :           loc, "argument 1 of %qE must be a pointer to a nonzero size object",
    7950              :           function);
    7951           22 :       return 0;
    7952              :     }
    7953              : 
    7954              :   /* Check each other parameter is a pointer and the same size.  */
    7955       469574 :   for (x = 0; x < n_param - n_model; x++)
    7956              :     {
    7957       340453 :       int size;
    7958       340453 :       tree type = TREE_TYPE ((*params)[x]);
    7959              :       /* __atomic_compare_exchange has a bool in the 4th position, skip it.  */
    7960       340453 :       if (n_param == 6 && x == 3)
    7961        40747 :         continue;
    7962       299706 :       if (TREE_CODE (type) == ARRAY_TYPE && c_dialect_cxx ())
    7963              :         {
    7964              :           /* Force array-to-pointer decay for C++.  */
    7965           18 :           (*params)[x] = default_conversion ((*params)[x]);
    7966           18 :           type = TREE_TYPE ((*params)[x]);
    7967              :         }
    7968       299706 :       if (!POINTER_TYPE_P (type))
    7969              :         {
    7970           16 :           if (complain)
    7971           13 :             error_at (loc, "argument %d of %qE must be a pointer type", x + 1,
    7972              :                       function);
    7973           16 :           return 0;
    7974              :         }
    7975       299690 :       else if (TYPE_SIZE_UNIT (TREE_TYPE (type))
    7976       299690 :                && TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type))))
    7977              :                   != INTEGER_CST)
    7978              :         {
    7979            1 :           if (complain)
    7980            1 :             error_at (loc,
    7981              :                       "argument %d of %qE must be a pointer to a constant "
    7982              :                       "size type",
    7983              :                       x + 1, function);
    7984            1 :           return 0;
    7985              :         }
    7986       299689 :       else if (FUNCTION_POINTER_TYPE_P (type))
    7987              :         {
    7988           10 :           if (complain)
    7989            7 :             error_at (loc,
    7990              :                       "argument %d of %qE must not be a pointer to a "
    7991              :                       "function",
    7992              :                       x + 1, function);
    7993           10 :           return 0;
    7994              :         }
    7995       299679 :       tree type_size = TYPE_SIZE_UNIT (TREE_TYPE (type));
    7996       299679 :       size = type_size ? tree_to_uhwi (type_size) : 0;
    7997       299679 :       if (size != size_0)
    7998              :         {
    7999           34 :           if (complain)
    8000           25 :             error_at (loc, "size mismatch in argument %d of %qE", x + 1,
    8001              :                       function);
    8002           34 :           return 0;
    8003              :         }
    8004              : 
    8005       299645 :       {
    8006       299645 :         auto_diagnostic_group d;
    8007       299645 :         int quals = TYPE_QUALS (TREE_TYPE (type));
    8008              :         /* Must not write to an argument of a const-qualified type.  */
    8009       299645 :         if (outputs & (1 << x) && quals & TYPE_QUAL_CONST)
    8010              :           {
    8011           57 :             if (c_dialect_cxx ())
    8012              :               {
    8013           45 :                 if (complain)
    8014           42 :                   error_at (loc,
    8015              :                             "argument %d of %qE must not be a pointer to "
    8016              :                             "a %<const%> type",
    8017              :                             x + 1, function);
    8018           45 :                 return 0;
    8019              :               }
    8020              :             else
    8021           12 :               pedwarn (loc, OPT_Wdiscarded_qualifiers, "argument %d "
    8022              :                        "of %qE discards %<const%> qualifier", x + 1,
    8023              :                        function);
    8024              :           }
    8025              :         /* Only the first argument is allowed to be volatile.  */
    8026       299600 :         if (x > 0 && quals & TYPE_QUAL_VOLATILE)
    8027              :           {
    8028           44 :             if (c_dialect_cxx ())
    8029              :               {
    8030           33 :                 if (complain)
    8031           30 :                   error_at (loc,
    8032              :                             "argument %d of %qE must not be a pointer to "
    8033              :                             "a %<volatile%> type",
    8034              :                             x + 1, function);
    8035           33 :                 return 0;
    8036              :               }
    8037              :             else
    8038           11 :               pedwarn (loc, OPT_Wdiscarded_qualifiers, "argument %d "
    8039              :                        "of %qE discards %<volatile%> qualifier", x + 1,
    8040              :                        function);
    8041              :           }
    8042       299645 :       }
    8043              :     }
    8044              : 
    8045              :   /* Check memory model parameters for validity.  */
    8046       298973 :   for (x = n_param - n_model ; x < n_param; x++)
    8047              :     {
    8048       169868 :       tree p = (*params)[x];
    8049       169868 :       if (!INTEGRAL_TYPE_P (TREE_TYPE (p)))
    8050              :         {
    8051           10 :           if (complain)
    8052            7 :             error_at (loc, "non-integer memory model argument %d of %qE", x + 1,
    8053              :                       function);
    8054           10 :           return 0;
    8055              :         }
    8056       169858 :       p = fold_for_warn (p);
    8057       169858 :       if (TREE_CODE (p) == INTEGER_CST)
    8058              :         {
    8059              :           /* memmodel_base masks the low 16 bits, thus ignore any bits above
    8060              :              it by using TREE_INT_CST_LOW instead of tree_to_*hwi.  Those high
    8061              :              bits will be checked later during expansion in target specific
    8062              :              way.  */
    8063        79422 :           if (memmodel_base (TREE_INT_CST_LOW (p)) >= MEMMODEL_LAST)
    8064              :             {
    8065           20 :               if (complain)
    8066           14 :                 warning_at (loc, OPT_Winvalid_memory_model,
    8067              :                             "invalid memory model argument %d of %qE", x + 1,
    8068              :                             function);
    8069              :               else
    8070              :                 return 0;
    8071              :             }
    8072              :         }
    8073              :     }
    8074              : 
    8075              :   return size_0;
    8076              : }
    8077              : 
    8078              : 
    8079              : /* This will take an __atomic_ generic FUNCTION call, and add a size parameter N
    8080              :    at the beginning of the parameter list PARAMS representing the size of the
    8081              :    objects.  This is to match the library ABI requirement.  LOC is the location
    8082              :    of the function call.
    8083              :    The new function is returned if it needed rebuilding, otherwise NULL_TREE is
    8084              :    returned to allow the external call to be constructed.  */
    8085              : 
    8086              : static tree
    8087         4146 : add_atomic_size_parameter (unsigned n, location_t loc, tree function,
    8088              :                            vec<tree, va_gc> *params)
    8089              : {
    8090         4146 :   tree size_node;
    8091              : 
    8092              :   /* Insert a SIZE_T parameter as the first param.  If there isn't
    8093              :      enough space, allocate a new vector and recursively re-build with that.  */
    8094         4146 :   if (!params->space (1))
    8095              :     {
    8096           33 :       unsigned int z, len;
    8097           33 :       vec<tree, va_gc> *v;
    8098           33 :       tree f;
    8099              : 
    8100           33 :       len = params->length ();
    8101           33 :       vec_alloc (v, len + 1);
    8102           33 :       v->quick_push (build_int_cst (size_type_node, n));
    8103          165 :       for (z = 0; z < len; z++)
    8104          132 :         v->quick_push ((*params)[z]);
    8105           33 :       f = build_function_call_vec (loc, vNULL, function, v, NULL);
    8106           33 :       vec_free (v);
    8107           33 :       return f;
    8108              :     }
    8109              : 
    8110              :   /* Add the size parameter and leave as a function call for processing.  */
    8111         4113 :   size_node = build_int_cst (size_type_node, n);
    8112         4113 :   params->quick_insert (0, size_node);
    8113         4113 :   return NULL_TREE;
    8114              : }
    8115              : 
    8116              : 
    8117              : /* Return whether atomic operations for naturally aligned N-byte
    8118              :    arguments are supported, whether inline or through libatomic.  */
    8119              : static bool
    8120       129105 : atomic_size_supported_p (int n)
    8121              : {
    8122       129105 :   switch (n)
    8123              :     {
    8124              :     case 1:
    8125              :     case 2:
    8126              :     case 4:
    8127              :     case 8:
    8128              :       return true;
    8129              : 
    8130         6971 :     case 16:
    8131         6971 :       return targetm.scalar_mode_supported_p (TImode);
    8132              : 
    8133         4146 :     default:
    8134         4146 :       return false;
    8135              :     }
    8136              : }
    8137              : 
    8138              : /* This will process an __atomic_exchange function call, determine whether it
    8139              :    needs to be mapped to the _N variation, or turned into a library call.
    8140              :    LOC is the location of the builtin call.
    8141              :    FUNCTION is the DECL that has been invoked;
    8142              :    PARAMS is the argument list for the call.  The return value is non-null
    8143              :    TRUE is returned if it is translated into the proper format for a call to the
    8144              :    external library, and NEW_RETURN is set the tree for that function.
    8145              :    FALSE is returned if processing for the _N variation is required, and
    8146              :    NEW_RETURN is set to the return value the result is copied into.  */
    8147              : static bool
    8148          631 : resolve_overloaded_atomic_exchange (location_t loc, tree function,
    8149              :                                     vec<tree, va_gc> *params, tree *new_return,
    8150              :                                     bool complain)
    8151              : {
    8152          631 :   tree p0, p1, p2, p3;
    8153          631 :   tree I_type, I_type_ptr;
    8154          631 :   int n = get_atomic_generic_size (loc, function, params, complain);
    8155              : 
    8156              :   /* Size of 0 is an error condition.  */
    8157          631 :   if (n == 0)
    8158              :     {
    8159          195 :       *new_return = error_mark_node;
    8160          195 :       return true;
    8161              :     }
    8162              : 
    8163              :   /* If not a lock-free size, change to the library generic format.  */
    8164          436 :   if (!atomic_size_supported_p (n))
    8165              :     {
    8166           39 :       *new_return = add_atomic_size_parameter (n, loc, function, params);
    8167           39 :       return true;
    8168              :     }
    8169              : 
    8170              :   /* Otherwise there is a lockfree match, transform the call from:
    8171              :        void fn(T* mem, T* desired, T* return, model)
    8172              :      into
    8173              :        *return = (T) (fn (In* mem, (In) *desired, model))  */
    8174              : 
    8175          397 :   p0 = (*params)[0];
    8176          397 :   p1 = (*params)[1];
    8177          397 :   p2 = (*params)[2];
    8178          397 :   p3 = (*params)[3];
    8179              : 
    8180              :   /* Create pointer to appropriate size.  */
    8181          397 :   I_type = builtin_type_for_size (BITS_PER_UNIT * n, 1);
    8182          397 :   I_type_ptr = build_pointer_type (I_type);
    8183              : 
    8184              :   /* Convert object pointer to required type.  */
    8185          397 :   p0 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p0);
    8186          397 :   (*params)[0] = p0;
    8187              :   /* Convert new value to required type, and dereference it.
    8188              :      If *p1 type can have padding or may involve floating point which
    8189              :      could e.g. be promoted to wider precision and demoted afterwards,
    8190              :      state of padding bits might not be preserved.  */
    8191          397 :   build_indirect_ref (loc, p1, RO_UNARY_STAR);
    8192          397 :   p1 = build2_loc (loc, MEM_REF, I_type,
    8193              :                    build1 (VIEW_CONVERT_EXPR, I_type_ptr, p1),
    8194          397 :                    build_zero_cst (TREE_TYPE (p1)));
    8195          397 :   (*params)[1] = p1;
    8196              : 
    8197              :   /* Move memory model to the 3rd position, and end param list.  */
    8198          397 :   (*params)[2] = p3;
    8199          397 :   params->truncate (3);
    8200              : 
    8201              :   /* Convert return pointer and dereference it for later assignment.  */
    8202          397 :   *new_return = build_indirect_ref (loc, p2, RO_UNARY_STAR);
    8203              : 
    8204          397 :   return false;
    8205              : }
    8206              : 
    8207              : /* This will process an __atomic_compare_exchange function call, determine
    8208              :    whether it needs to be mapped to the _N variation, or turned into a lib call.
    8209              :    LOC is the location of the builtin call.
    8210              :    FUNCTION is the DECL that has been invoked;
    8211              :    PARAMS is the argument list for the call.  The return value is non-null
    8212              :    TRUE is returned if it is translated into the proper format for a call to the
    8213              :    external library, and NEW_RETURN is set the tree for that function.
    8214              :    FALSE is returned if processing for the _N variation is required.  */
    8215              : 
    8216              : static bool
    8217        40925 : resolve_overloaded_atomic_compare_exchange (location_t loc, tree function,
    8218              :                                             vec<tree, va_gc> *params,
    8219              :                                             tree *new_return, bool complain)
    8220              : {
    8221        40925 :   tree p0, p1, p2;
    8222        40925 :   tree I_type, I_type_ptr;
    8223        40925 :   int n = get_atomic_generic_size (loc, function, params, complain);
    8224              : 
    8225              :   /* Size of 0 is an error condition.  */
    8226        40925 :   if (n == 0)
    8227              :     {
    8228          178 :       *new_return = error_mark_node;
    8229          178 :       return true;
    8230              :     }
    8231              : 
    8232              :   /* If not a lock-free size, change to the library generic format.  */
    8233        40747 :   if (!atomic_size_supported_p (n))
    8234              :     {
    8235              :       /* The library generic format does not have the weak parameter, so
    8236              :          remove it from the param list.  Since a parameter has been removed,
    8237              :          we can be sure that there is room for the SIZE_T parameter, meaning
    8238              :          there will not be a recursive rebuilding of the parameter list, so
    8239              :          there is no danger this will be done twice.  */
    8240         1198 :       if (n > 0)
    8241              :         {
    8242         1198 :           (*params)[3] = (*params)[4];
    8243         1198 :           (*params)[4] = (*params)[5];
    8244         1198 :           params->truncate (5);
    8245              :         }
    8246         1198 :       *new_return = add_atomic_size_parameter (n, loc, function, params);
    8247         1198 :       return true;
    8248              :     }
    8249              : 
    8250              :   /* Otherwise, there is a match, so the call needs to be transformed from:
    8251              :        bool fn(T* mem, T* desired, T* return, weak, success, failure)
    8252              :      into
    8253              :        bool fn ((In *)mem, (In *)expected, (In) *desired, weak, succ, fail)  */
    8254              : 
    8255        39549 :   p0 = (*params)[0];
    8256        39549 :   p1 = (*params)[1];
    8257        39549 :   p2 = (*params)[2];
    8258              : 
    8259              :   /* Create pointer to appropriate size.  */
    8260        39549 :   I_type = builtin_type_for_size (BITS_PER_UNIT * n, 1);
    8261        39549 :   I_type_ptr = build_pointer_type (I_type);
    8262              : 
    8263              :   /* Convert object pointer to required type.  */
    8264        39549 :   p0 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p0);
    8265        39549 :   (*params)[0] = p0;
    8266              : 
    8267              :   /* Convert expected pointer to required type.  */
    8268        39549 :   p1 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p1);
    8269        39549 :   (*params)[1] = p1;
    8270              : 
    8271              :   /* Convert desired value to required type, and dereference it.
    8272              :      If *p2 type can have padding or may involve floating point which
    8273              :      could e.g. be promoted to wider precision and demoted afterwards,
    8274              :      state of padding bits might not be preserved.  */
    8275        39549 :   build_indirect_ref (loc, p2, RO_UNARY_STAR);
    8276        39549 :   p2 = build2_loc (loc, MEM_REF, I_type,
    8277              :                    build1 (VIEW_CONVERT_EXPR, I_type_ptr, p2),
    8278        39549 :                    build_zero_cst (TREE_TYPE (p2)));
    8279        39549 :   (*params)[2] = p2;
    8280              : 
    8281              :   /* The rest of the parameters are fine. NULL means no special return value
    8282              :      processing.*/
    8283        39549 :   *new_return = NULL;
    8284        39549 :   return false;
    8285              : }
    8286              : 
    8287              : /* This will process an __atomic_load function call, determine whether it
    8288              :    needs to be mapped to the _N variation, or turned into a library call.
    8289              :    LOC is the location of the builtin call.
    8290              :    FUNCTION is the DECL that has been invoked;
    8291              :    PARAMS is the argument list for the call.  The return value is non-null
    8292              :    TRUE is returned if it is translated into the proper format for a call to the
    8293              :    external library, and NEW_RETURN is set the tree for that function.
    8294              :    FALSE is returned if processing for the _N variation is required, and
    8295              :    NEW_RETURN is set to the return value the result is copied into.  */
    8296              : 
    8297              : static bool
    8298        76886 : resolve_overloaded_atomic_load (location_t loc, tree function,
    8299              :                                 vec<tree, va_gc> *params, tree *new_return,
    8300              :                                 bool complain)
    8301              : {
    8302        76886 :   tree p0, p1, p2;
    8303        76886 :   tree I_type, I_type_ptr;
    8304        76886 :   int n = get_atomic_generic_size (loc, function, params, complain);
    8305              : 
    8306              :   /* Size of 0 is an error condition.  */
    8307        76886 :   if (n == 0)
    8308              :     {
    8309          278 :       *new_return = error_mark_node;
    8310          278 :       return true;
    8311              :     }
    8312              : 
    8313              :   /* If not a lock-free size, change to the library generic format.  */
    8314        76608 :   if (!atomic_size_supported_p (n))
    8315              :     {
    8316         2499 :       *new_return = add_atomic_size_parameter (n, loc, function, params);
    8317         2499 :       return true;
    8318              :     }
    8319              : 
    8320              :   /* Otherwise, there is a match, so the call needs to be transformed from:
    8321              :        void fn(T* mem, T* return, model)
    8322              :      into
    8323              :        *return = (T) (fn ((In *) mem, model))  */
    8324              : 
    8325        74109 :   p0 = (*params)[0];
    8326        74109 :   p1 = (*params)[1];
    8327        74109 :   p2 = (*params)[2];
    8328              : 
    8329              :   /* Create pointer to appropriate size.  */
    8330        74109 :   I_type = builtin_type_for_size (BITS_PER_UNIT * n, 1);
    8331        74109 :   I_type_ptr = build_pointer_type (I_type);
    8332              : 
    8333              :   /* Convert object pointer to required type.  */
    8334        74109 :   p0 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p0);
    8335        74109 :   (*params)[0] = p0;
    8336              : 
    8337              :   /* Move memory model to the 2nd position, and end param list.  */
    8338        74109 :   (*params)[1] = p2;
    8339        74109 :   params->truncate (2);
    8340              : 
    8341              :   /* Convert return pointer and dereference it for later assignment.  */
    8342        74109 :   *new_return = build_indirect_ref (loc, p1, RO_UNARY_STAR);
    8343              : 
    8344        74109 :   return false;
    8345              : }
    8346              : 
    8347              : /* This will process an __atomic_store function call, determine whether it
    8348              :    needs to be mapped to the _N variation, or turned into a library call.
    8349              :    LOC is the location of the builtin call.
    8350              :    FUNCTION is the DECL that has been invoked;
    8351              :    PARAMS is the argument list for the call.  The return value is non-null
    8352              :    TRUE is returned if it is translated into the proper format for a call to the
    8353              :    external library, and NEW_RETURN is set the tree for that function.
    8354              :    FALSE is returned if processing for the _N variation is required, and
    8355              :    NEW_RETURN is set to the return value the result is copied into.  */
    8356              : 
    8357              : static bool
    8358        11482 : resolve_overloaded_atomic_store (location_t loc, tree function,
    8359              :                                  vec<tree, va_gc> *params, tree *new_return,
    8360              :                                  bool complain)
    8361              : {
    8362        11482 :   tree p0, p1;
    8363        11482 :   tree I_type, I_type_ptr;
    8364        11482 :   int n = get_atomic_generic_size (loc, function, params, complain);
    8365              : 
    8366              :   /* Size of 0 is an error condition.  */
    8367        11482 :   if (n == 0)
    8368              :     {
    8369          168 :       *new_return = error_mark_node;
    8370          168 :       return true;
    8371              :     }
    8372              : 
    8373              :   /* If not a lock-free size, change to the library generic format.  */
    8374        11314 :   if (!atomic_size_supported_p (n))
    8375              :     {
    8376          410 :       *new_return = add_atomic_size_parameter (n, loc, function, params);
    8377          410 :       return true;
    8378              :     }
    8379              : 
    8380              :   /* Otherwise, there is a match, so the call needs to be transformed from:
    8381              :        void fn(T* mem, T* value, model)
    8382              :      into
    8383              :        fn ((In *) mem, (In) *value, model)  */
    8384              : 
    8385        10904 :   p0 = (*params)[0];
    8386        10904 :   p1 = (*params)[1];
    8387              : 
    8388              :   /* Create pointer to appropriate size.  */
    8389        10904 :   I_type = builtin_type_for_size (BITS_PER_UNIT * n, 1);
    8390        10904 :   I_type_ptr = build_pointer_type (I_type);
    8391              : 
    8392              :   /* Convert object pointer to required type.  */
    8393        10904 :   p0 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p0);
    8394        10904 :   (*params)[0] = p0;
    8395              : 
    8396              :   /* Convert new value to required type, and dereference it.  */
    8397        10904 :   p1 = build_indirect_ref (loc, p1, RO_UNARY_STAR);
    8398        10904 :   p1 = build1 (VIEW_CONVERT_EXPR, I_type, p1);
    8399        10904 :   (*params)[1] = p1;
    8400              : 
    8401              :   /* The memory model is in the right spot already. Return is void.  */
    8402        10904 :   *new_return = NULL_TREE;
    8403              : 
    8404        10904 :   return false;
    8405              : }
    8406              : 
    8407              : /* Emit __atomic*fetch* on _BitInt which doesn't have a size of
    8408              :    1, 2, 4, 8 or 16 bytes using __atomic_compare_exchange loop.
    8409              :    ORIG_CODE is the DECL_FUNCTION_CODE of ORIG_FUNCTION and
    8410              :    ORIG_PARAMS arguments of the call.  */
    8411              : 
    8412              : static tree
    8413          528 : atomic_bitint_fetch_using_cas_loop (location_t loc,
    8414              :                                     enum built_in_function orig_code,
    8415              :                                     tree orig_function,
    8416              :                                     vec<tree, va_gc> *orig_params)
    8417              : {
    8418          528 :   enum tree_code code = ERROR_MARK;
    8419          528 :   bool return_old_p = false;
    8420          528 :   switch (orig_code)
    8421              :     {
    8422            0 :     case BUILT_IN_ATOMIC_ADD_FETCH_N:
    8423            0 :       code = PLUS_EXPR;
    8424            0 :       break;
    8425            1 :     case BUILT_IN_ATOMIC_SUB_FETCH_N:
    8426            1 :       code = MINUS_EXPR;
    8427            1 :       break;
    8428            0 :     case BUILT_IN_ATOMIC_AND_FETCH_N:
    8429            0 :       code = BIT_AND_EXPR;
    8430            0 :       break;
    8431              :     case BUILT_IN_ATOMIC_NAND_FETCH_N:
    8432              :       break;
    8433            1 :     case BUILT_IN_ATOMIC_XOR_FETCH_N:
    8434            1 :       code = BIT_XOR_EXPR;
    8435            1 :       break;
    8436            0 :     case BUILT_IN_ATOMIC_OR_FETCH_N:
    8437            0 :       code = BIT_IOR_EXPR;
    8438            0 :       break;
    8439          106 :     case BUILT_IN_ATOMIC_FETCH_ADD_N:
    8440          106 :       code = PLUS_EXPR;
    8441          106 :       return_old_p = true;
    8442          106 :       break;
    8443          104 :     case BUILT_IN_ATOMIC_FETCH_SUB_N:
    8444          104 :       code = MINUS_EXPR;
    8445          104 :       return_old_p = true;
    8446          104 :       break;
    8447          105 :     case BUILT_IN_ATOMIC_FETCH_AND_N:
    8448          105 :       code = BIT_AND_EXPR;
    8449          105 :       return_old_p = true;
    8450          105 :       break;
    8451            0 :     case BUILT_IN_ATOMIC_FETCH_NAND_N:
    8452            0 :       return_old_p = true;
    8453            0 :       break;
    8454          104 :     case BUILT_IN_ATOMIC_FETCH_XOR_N:
    8455          104 :       code = BIT_XOR_EXPR;
    8456          104 :       return_old_p = true;
    8457          104 :       break;
    8458          106 :     case BUILT_IN_ATOMIC_FETCH_OR_N:
    8459          106 :       code = BIT_IOR_EXPR;
    8460          106 :       return_old_p = true;
    8461          106 :       break;
    8462            0 :     default:
    8463            0 :       gcc_unreachable ();
    8464              :     }
    8465              : 
    8466          528 :   if (orig_params->length () != 3)
    8467              :     {
    8468            0 :       if (orig_params->length () < 3)
    8469            0 :         error_at (loc, "too few arguments to function %qE", orig_function);
    8470              :       else
    8471            0 :         error_at (loc, "too many arguments to function %qE", orig_function);
    8472            0 :       return error_mark_node;
    8473              :     }
    8474              : 
    8475          528 :   tree stmts = push_stmt_list ();
    8476              : 
    8477          528 :   tree nonatomic_lhs_type = TREE_TYPE (TREE_TYPE ((*orig_params)[0]));
    8478          528 :   nonatomic_lhs_type = TYPE_MAIN_VARIANT (nonatomic_lhs_type);
    8479          528 :   gcc_assert (BITINT_TYPE_P (nonatomic_lhs_type));
    8480              : 
    8481          528 :   tree lhs_addr = (*orig_params)[0];
    8482          528 :   tree val = convert (nonatomic_lhs_type, (*orig_params)[1]);
    8483          528 :   tree model = convert (integer_type_node, (*orig_params)[2]);
    8484          528 :   if (!c_dialect_cxx ())
    8485              :     {
    8486          528 :       lhs_addr = c_fully_fold (lhs_addr, false, NULL);
    8487          528 :       val = c_fully_fold (val, false, NULL);
    8488          528 :       model = c_fully_fold (model, false, NULL);
    8489              :     }
    8490          528 :   if (TREE_SIDE_EFFECTS (lhs_addr))
    8491              :     {
    8492            1 :       tree var = create_tmp_var_raw (TREE_TYPE (lhs_addr));
    8493            1 :       lhs_addr = build4 (TARGET_EXPR, TREE_TYPE (lhs_addr), var, lhs_addr,
    8494              :                          NULL_TREE, NULL_TREE);
    8495            1 :       add_stmt (lhs_addr);
    8496              :     }
    8497          528 :   if (TREE_SIDE_EFFECTS (val))
    8498              :     {
    8499            1 :       tree var = create_tmp_var_raw (nonatomic_lhs_type);
    8500            1 :       val = build4 (TARGET_EXPR, nonatomic_lhs_type, var, val, NULL_TREE,
    8501              :                     NULL_TREE);
    8502            1 :       add_stmt (val);
    8503              :     }
    8504          528 :   if (TREE_SIDE_EFFECTS (model))
    8505              :     {
    8506            1 :       tree var = create_tmp_var_raw (integer_type_node);
    8507            1 :       model = build4 (TARGET_EXPR, integer_type_node, var, model, NULL_TREE,
    8508              :                       NULL_TREE);
    8509            1 :       add_stmt (model);
    8510              :     }
    8511              : 
    8512          528 :   tree old = create_tmp_var_raw (nonatomic_lhs_type);
    8513          528 :   tree old_addr = build_unary_op (loc, ADDR_EXPR, old, false);
    8514          528 :   TREE_ADDRESSABLE (old) = 1;
    8515          528 :   suppress_warning (old);
    8516              : 
    8517          528 :   tree newval = create_tmp_var_raw (nonatomic_lhs_type);
    8518          528 :   tree newval_addr = build_unary_op (loc, ADDR_EXPR, newval, false);
    8519          528 :   TREE_ADDRESSABLE (newval) = 1;
    8520          528 :   suppress_warning (newval);
    8521              : 
    8522          528 :   tree loop_decl = create_artificial_label (loc);
    8523          528 :   tree loop_label = build1 (LABEL_EXPR, void_type_node, loop_decl);
    8524              : 
    8525          528 :   tree done_decl = create_artificial_label (loc);
    8526          528 :   tree done_label = build1 (LABEL_EXPR, void_type_node, done_decl);
    8527              : 
    8528          528 :   vec<tree, va_gc> *params;
    8529          528 :   vec_alloc (params, 6);
    8530              : 
    8531              :   /* __atomic_load (addr, &old, SEQ_CST).  */
    8532          528 :   tree fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD);
    8533          528 :   params->quick_push (lhs_addr);
    8534          528 :   params->quick_push (old_addr);
    8535          528 :   params->quick_push (build_int_cst (integer_type_node, MEMMODEL_RELAXED));
    8536          528 :   tree func_call = resolve_overloaded_builtin (loc, fndecl, params);
    8537          528 :   if (func_call == NULL_TREE)
    8538          528 :     func_call = build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    8539          528 :   old = build4 (TARGET_EXPR, nonatomic_lhs_type, old, func_call, NULL_TREE,
    8540              :                 NULL_TREE);
    8541          528 :   add_stmt (old);
    8542          528 :   params->truncate (0);
    8543              : 
    8544              :   /* loop:  */
    8545          528 :   add_stmt (loop_label);
    8546              : 
    8547              :   /* newval = old + val;  */
    8548          528 :   tree rhs;
    8549          528 :   switch (code)
    8550              :     {
    8551          211 :     case PLUS_EXPR:
    8552          211 :     case MINUS_EXPR:
    8553          211 :       if (!TYPE_OVERFLOW_WRAPS (nonatomic_lhs_type))
    8554              :         {
    8555          211 :           tree utype
    8556          211 :             = build_bitint_type (TYPE_PRECISION (nonatomic_lhs_type), 1);
    8557          211 :           rhs = convert (nonatomic_lhs_type,
    8558              :                          build2_loc (loc, code, utype,
    8559              :                                      convert (utype, old),
    8560              :                                      convert (utype, val)));
    8561              :         }
    8562              :       else
    8563            0 :         rhs = build2_loc (loc, code, nonatomic_lhs_type, old, val);
    8564              :       break;
    8565          316 :     case BIT_AND_EXPR:
    8566          316 :     case BIT_IOR_EXPR:
    8567          316 :     case BIT_XOR_EXPR:
    8568          316 :       rhs = build2_loc (loc, code, nonatomic_lhs_type, old, val);
    8569          316 :       break;
    8570            1 :     case ERROR_MARK:
    8571            1 :       rhs = build2_loc (loc, BIT_AND_EXPR, nonatomic_lhs_type,
    8572              :                         build1_loc (loc, BIT_NOT_EXPR,
    8573              :                                     nonatomic_lhs_type, old), val);
    8574            1 :       break;
    8575            0 :     default:
    8576            0 :       gcc_unreachable ();
    8577              :     }
    8578          528 :   rhs = build4 (TARGET_EXPR, nonatomic_lhs_type, newval, rhs, NULL_TREE,
    8579              :                 NULL_TREE);
    8580          528 :   SET_EXPR_LOCATION (rhs, loc);
    8581          528 :   add_stmt (rhs);
    8582              : 
    8583              :   /* if (__atomic_compare_exchange (addr, &old, &new, false, model, model))
    8584              :        goto done;  */
    8585          528 :   fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_COMPARE_EXCHANGE);
    8586          528 :   params->quick_push (lhs_addr);
    8587          528 :   params->quick_push (old_addr);
    8588          528 :   params->quick_push (newval_addr);
    8589          528 :   params->quick_push (integer_zero_node);
    8590          528 :   params->quick_push (model);
    8591          528 :   if (tree_fits_uhwi_p (model)
    8592          527 :       && (tree_to_uhwi (model) == MEMMODEL_RELEASE
    8593          447 :           || tree_to_uhwi (model) == MEMMODEL_ACQ_REL))
    8594          129 :     params->quick_push (build_int_cst (integer_type_node, MEMMODEL_RELAXED));
    8595              :   else
    8596          399 :     params->quick_push (model);
    8597          528 :   func_call = resolve_overloaded_builtin (loc, fndecl, params);
    8598          528 :   if (func_call == NULL_TREE)
    8599          528 :     func_call = build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    8600              : 
    8601          528 :   tree goto_stmt = build1 (GOTO_EXPR, void_type_node, done_decl);
    8602          528 :   SET_EXPR_LOCATION (goto_stmt, loc);
    8603              : 
    8604          528 :   tree stmt
    8605          528 :     = build3 (COND_EXPR, void_type_node, func_call, goto_stmt, NULL_TREE);
    8606          528 :   SET_EXPR_LOCATION (stmt, loc);
    8607          528 :   add_stmt (stmt);
    8608              : 
    8609              :   /* goto loop;  */
    8610          528 :   goto_stmt = build1 (GOTO_EXPR, void_type_node, loop_decl);
    8611          528 :   SET_EXPR_LOCATION (goto_stmt, loc);
    8612          528 :   add_stmt (goto_stmt);
    8613              : 
    8614              :   /* done:  */
    8615          528 :   add_stmt (done_label);
    8616              : 
    8617          528 :   tree ret = create_tmp_var_raw (nonatomic_lhs_type);
    8618          531 :   stmt = build2_loc (loc, MODIFY_EXPR, void_type_node, ret,
    8619              :                      return_old_p ? old : newval);
    8620          528 :   add_stmt (stmt);
    8621              : 
    8622              :   /* Finish the compound statement.  */
    8623          528 :   stmts = pop_stmt_list (stmts);
    8624              : 
    8625          528 :   return build4 (TARGET_EXPR, nonatomic_lhs_type, ret, stmts, NULL_TREE,
    8626          528 :                  NULL_TREE);
    8627              : }
    8628              : 
    8629              : 
    8630              : /* Some builtin functions are placeholders for other expressions.  This
    8631              :    function should be called immediately after parsing the call expression
    8632              :    before surrounding code has committed to the type of the expression.
    8633              : 
    8634              :    LOC is the location of the builtin call.
    8635              : 
    8636              :    FUNCTION is the DECL that has been invoked; it is known to be a builtin.
    8637              :    PARAMS is the argument list for the call.  The return value is non-null
    8638              :    when expansion is complete, and null if normal processing should
    8639              :    continue.  */
    8640              : 
    8641              : tree
    8642     58838128 : resolve_overloaded_builtin (location_t loc, tree function,
    8643              :                             vec<tree, va_gc> *params, bool complain)
    8644              : {
    8645              :   /* Is function one of the _FETCH_OP_ or _OP_FETCH_ built-ins?
    8646              :      Those are not valid to call with a pointer to _Bool (or C++ bool)
    8647              :      and so must be rejected.  */
    8648     58838128 :   bool fetch_op = true;
    8649     58838128 :   bool orig_format = true;
    8650     58838128 :   tree new_return = NULL_TREE;
    8651              : 
    8652     58838128 :   switch (DECL_BUILT_IN_CLASS (function))
    8653              :     {
    8654      9158648 :     case BUILT_IN_NORMAL:
    8655      9158648 :       break;
    8656     33099956 :     case BUILT_IN_MD:
    8657     33099956 :       if (targetm.resolve_overloaded_builtin)
    8658            0 :         return targetm.resolve_overloaded_builtin (loc, function, params,
    8659            0 :                                                    complain);
    8660              :       else
    8661              :         return NULL_TREE;
    8662              :     default:
    8663              :       return NULL_TREE;
    8664              :     }
    8665              : 
    8666              :   /* Handle BUILT_IN_NORMAL here.  */
    8667      9158648 :   enum built_in_function orig_code = DECL_FUNCTION_CODE (function);
    8668      9158648 :   switch (orig_code)
    8669              :     {
    8670          154 :     case BUILT_IN_SPECULATION_SAFE_VALUE_N:
    8671          154 :       {
    8672          154 :         tree new_function, first_param, result;
    8673          154 :         enum built_in_function fncode
    8674          154 :           = speculation_safe_value_resolve_call (function, params, complain);
    8675              : 
    8676          154 :         if (fncode == BUILT_IN_NONE)
    8677           52 :           return error_mark_node;
    8678              : 
    8679          102 :         first_param = (*params)[0];
    8680          102 :         if (!speculation_safe_value_resolve_params (loc, function, params,
    8681              :                                                     complain))
    8682           31 :           return error_mark_node;
    8683              : 
    8684           71 :         if (targetm.have_speculation_safe_value (true))
    8685              :           {
    8686           71 :             new_function = builtin_decl_explicit (fncode);
    8687           71 :             result = build_function_call_vec (loc, vNULL, new_function, params,
    8688              :                                               NULL);
    8689              : 
    8690           71 :             if (result == error_mark_node)
    8691              :               return result;
    8692              : 
    8693           71 :             return speculation_safe_value_resolve_return (first_param, result);
    8694              :           }
    8695              :         else
    8696              :           {
    8697              :             /* This target doesn't have, or doesn't need, active mitigation
    8698              :                against incorrect speculative execution.  Simply return the
    8699              :                first parameter to the builtin.  */
    8700            0 :             if (!targetm.have_speculation_safe_value (false))
    8701              :               {
    8702            0 :                 if (complain)
    8703              :                   /* The user has invoked __builtin_speculation_safe_value
    8704              :                      even though __HAVE_SPECULATION_SAFE_VALUE is not
    8705              :                      defined: emit a warning.  */
    8706            0 :                   warning_at (
    8707            0 :                     input_location, 0,
    8708              :                     "this target does not define a speculation barrier; "
    8709              :                     "your program will still execute correctly, "
    8710              :                     "but incorrect speculation may not be "
    8711              :                     "restricted");
    8712              :                 else
    8713            0 :                   return error_mark_node;
    8714              :               }
    8715              : 
    8716              :             /* If the optional second argument is present, handle any side
    8717              :                effects now.  */
    8718            0 :             if (params->length () == 2
    8719            0 :                 && TREE_SIDE_EFFECTS ((*params)[1]))
    8720            0 :               return build2 (COMPOUND_EXPR, TREE_TYPE (first_param),
    8721            0 :                              (*params)[1], first_param);
    8722              : 
    8723              :             return first_param;
    8724              :           }
    8725              :       }
    8726              : 
    8727       129924 :     case BUILT_IN_ATOMIC_EXCHANGE:
    8728       129924 :     case BUILT_IN_ATOMIC_COMPARE_EXCHANGE:
    8729       129924 :     case BUILT_IN_ATOMIC_LOAD:
    8730       129924 :     case BUILT_IN_ATOMIC_STORE:
    8731       129924 :       {
    8732              :         /* Handle these 4 together so that they can fall through to the next
    8733              :            case if the call is transformed to an _N variant.  */
    8734       129924 :         switch (orig_code)
    8735              :           {
    8736          631 :           case BUILT_IN_ATOMIC_EXCHANGE:
    8737          631 :             {
    8738          631 :               if (resolve_overloaded_atomic_exchange (loc, function, params,
    8739              :                                                       &new_return, complain))
    8740          234 :                 return new_return;
    8741              :               /* Change to the _N variant.  */
    8742              :               orig_code = BUILT_IN_ATOMIC_EXCHANGE_N;
    8743              :               break;
    8744              :             }
    8745              : 
    8746        40925 :           case BUILT_IN_ATOMIC_COMPARE_EXCHANGE:
    8747        40925 :             {
    8748        40925 :               if (resolve_overloaded_atomic_compare_exchange (
    8749              :                     loc, function, params, &new_return, complain))
    8750         1376 :                 return new_return;
    8751              :               /* Change to the _N variant.  */
    8752              :               orig_code = BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N;
    8753              :               break;
    8754              :             }
    8755        76886 :           case BUILT_IN_ATOMIC_LOAD:
    8756        76886 :             {
    8757        76886 :               if (resolve_overloaded_atomic_load (loc, function, params,
    8758              :                                                   &new_return, complain))
    8759         2777 :                 return new_return;
    8760              :               /* Change to the _N variant.  */
    8761              :               orig_code = BUILT_IN_ATOMIC_LOAD_N;
    8762              :               break;
    8763              :             }
    8764        11482 :           case BUILT_IN_ATOMIC_STORE:
    8765        11482 :             {
    8766        11482 :               if (resolve_overloaded_atomic_store (loc, function, params,
    8767              :                                                    &new_return, complain))
    8768          578 :                 return new_return;
    8769              :               /* Change to the _N variant.  */
    8770              :               orig_code = BUILT_IN_ATOMIC_STORE_N;
    8771              :               break;
    8772              :             }
    8773            0 :           default:
    8774            0 :             gcc_unreachable ();
    8775              :           }
    8776              :       }
    8777              :       /* FALLTHRU */
    8778              :     case BUILT_IN_ATOMIC_EXCHANGE_N:
    8779              :     case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N:
    8780              :     case BUILT_IN_ATOMIC_LOAD_N:
    8781              :     case BUILT_IN_ATOMIC_STORE_N:
    8782              :       fetch_op = false;
    8783              :       /* FALLTHRU */
    8784              :     case BUILT_IN_ATOMIC_ADD_FETCH_N:
    8785              :     case BUILT_IN_ATOMIC_SUB_FETCH_N:
    8786              :     case BUILT_IN_ATOMIC_AND_FETCH_N:
    8787              :     case BUILT_IN_ATOMIC_NAND_FETCH_N:
    8788              :     case BUILT_IN_ATOMIC_XOR_FETCH_N:
    8789              :     case BUILT_IN_ATOMIC_OR_FETCH_N:
    8790              :     case BUILT_IN_ATOMIC_FETCH_ADD_N:
    8791              :     case BUILT_IN_ATOMIC_FETCH_SUB_N:
    8792              :     case BUILT_IN_ATOMIC_FETCH_AND_N:
    8793              :     case BUILT_IN_ATOMIC_FETCH_NAND_N:
    8794              :     case BUILT_IN_ATOMIC_FETCH_XOR_N:
    8795              :     case BUILT_IN_ATOMIC_FETCH_OR_N:
    8796              :       orig_format = false;
    8797              :       /* FALLTHRU */
    8798              :     case BUILT_IN_SYNC_FETCH_AND_ADD_N:
    8799              :     case BUILT_IN_SYNC_FETCH_AND_SUB_N:
    8800              :     case BUILT_IN_SYNC_FETCH_AND_OR_N:
    8801              :     case BUILT_IN_SYNC_FETCH_AND_AND_N:
    8802              :     case BUILT_IN_SYNC_FETCH_AND_XOR_N:
    8803              :     case BUILT_IN_SYNC_FETCH_AND_NAND_N:
    8804              :     case BUILT_IN_SYNC_ADD_AND_FETCH_N:
    8805              :     case BUILT_IN_SYNC_SUB_AND_FETCH_N:
    8806              :     case BUILT_IN_SYNC_OR_AND_FETCH_N:
    8807              :     case BUILT_IN_SYNC_AND_AND_FETCH_N:
    8808              :     case BUILT_IN_SYNC_XOR_AND_FETCH_N:
    8809              :     case BUILT_IN_SYNC_NAND_AND_FETCH_N:
    8810              :     case BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N:
    8811              :     case BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N:
    8812              :     case BUILT_IN_SYNC_LOCK_TEST_AND_SET_N:
    8813              :     case BUILT_IN_SYNC_LOCK_RELEASE_N:
    8814              :       {
    8815              :         /* The following are not _FETCH_OPs and must be accepted with
    8816              :            pointers to _Bool (or C++ bool).  */
    8817              :         if (fetch_op)
    8818        99565 :           fetch_op = (orig_code != BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
    8819        99565 :                       && orig_code != BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N
    8820        99079 :                       && orig_code != BUILT_IN_SYNC_LOCK_TEST_AND_SET_N
    8821        99565 :                       && orig_code != BUILT_IN_SYNC_LOCK_RELEASE_N);
    8822              : 
    8823       417858 :         int n = sync_resolve_size (function, params, fetch_op, orig_format,
    8824              :                                    complain);
    8825       417858 :         tree new_function, first_param, result;
    8826       417858 :         enum built_in_function fncode;
    8827              : 
    8828       417858 :         if (n == 0)
    8829         2584 :           return error_mark_node;
    8830              : 
    8831       415274 :         if (n == -1)
    8832              :           {
    8833              :             /* complain is related to SFINAE context.
    8834              :                _BitInt is not defined in C++, hence can't enter this clause
    8835              :                with complain unset.  Even if at the abstraction level
    8836              :                this complain is unset that still makes sense (whether
    8837              :                this function should report an error or not if anything is
    8838              :                wrong).
    8839              :                Since can't test avoiding an error when this value is false not
    8840              :                writing the code and instead asserting value is not set.  */
    8841          528 :             gcc_assert (complain);
    8842          528 :             return atomic_bitint_fetch_using_cas_loop (loc, orig_code, function,
    8843          528 :                                                        params);
    8844              :           }
    8845              : 
    8846       414746 :         fncode = (enum built_in_function)((int)orig_code + exact_log2 (n) + 1);
    8847       414746 :         new_function = builtin_decl_explicit (fncode);
    8848       414746 :         if (!sync_resolve_params (loc, function, new_function, params,
    8849              :                                   orig_format, complain))
    8850          164 :           return error_mark_node;
    8851              : 
    8852       414582 :         first_param = (*params)[0];
    8853       414582 :         result = build_function_call_vec (loc, vNULL, new_function, params,
    8854              :                                           NULL);
    8855       414582 :         if (result == error_mark_node)
    8856              :           return result;
    8857       414570 :         if (orig_code != BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
    8858       414570 :             && orig_code != BUILT_IN_SYNC_LOCK_RELEASE_N
    8859       414263 :             && orig_code != BUILT_IN_ATOMIC_STORE_N
    8860       414263 :             && orig_code != BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N)
    8861       277624 :           result = sync_resolve_return (first_param, result, orig_format);
    8862              : 
    8863       414570 :         if (fetch_op)
    8864              :           /* Prevent -Wunused-value warning.  */
    8865        96083 :           TREE_USED (result) = true;
    8866              : 
    8867              :         /* If new_return is set, assign function to that expr and cast the
    8868              :            result to void since the generic interface returned void.  */
    8869       414570 :         if (new_return)
    8870              :           {
    8871              :             /* Cast function result from I{1,2,4,8,16} to the required type.  */
    8872        74506 :             if (BITINT_TYPE_P (TREE_TYPE (new_return)))
    8873              :               {
    8874          599 :                 struct bitint_info info;
    8875          599 :                 unsigned prec = TYPE_PRECISION (TREE_TYPE (new_return));
    8876          599 :                 targetm.c.bitint_type_info (prec, &info);
    8877          599 :                 if (!info.extended)
    8878              :                   /* For _BitInt which has the padding bits undefined
    8879              :                      convert to the _BitInt type rather than VCE to force
    8880              :                      zero or sign extension.  */
    8881          599 :                   result = build1 (NOP_EXPR, TREE_TYPE (new_return), result);
    8882              :               }
    8883        74506 :             result
    8884        74506 :               = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (new_return), result);
    8885        74506 :             result = build2 (MODIFY_EXPR, TREE_TYPE (new_return), new_return,
    8886              :                              result);
    8887        74506 :             TREE_SIDE_EFFECTS (result) = 1;
    8888        74506 :             protected_set_expr_location (result, loc);
    8889        74506 :             result = convert (void_type_node, result);
    8890              :           }
    8891              :         return result;
    8892              :       }
    8893              : 
    8894              :     default:
    8895              :       return NULL_TREE;
    8896              :     }
    8897              : }
    8898              : 
    8899              : /* vector_types_compatible_elements_p is used in type checks of vectors
    8900              :    values used as operands of binary operators.  Where it returns true, and
    8901              :    the other checks of the caller succeed (being vector types in he first
    8902              :    place, and matching number of elements), we can just treat the types
    8903              :    as essentially the same.
    8904              :    Contrast with vector_targets_convertible_p, which is used for vector
    8905              :    pointer types,  and vector_types_convertible_p, which will allow
    8906              :    language-specific matches under the control of flag_lax_vector_conversions,
    8907              :    and might still require a conversion.  */
    8908              : /* True if vector types T1 and T2 can be inputs to the same binary
    8909              :    operator without conversion.
    8910              :    We don't check the overall vector size here because some of our callers
    8911              :    want to give different error messages when the vectors are compatible
    8912              :    except for the element count.  */
    8913              : 
    8914              : bool
    8915      1640058 : vector_types_compatible_elements_p (tree t1, tree t2)
    8916              : {
    8917      3279840 :   bool opaque = TYPE_VECTOR_OPAQUE (t1) || TYPE_VECTOR_OPAQUE (t2);
    8918      1640058 :   t1 = TREE_TYPE (t1);
    8919      1640058 :   t2 = TREE_TYPE (t2);
    8920              : 
    8921      1640058 :   enum tree_code c1 = TREE_CODE (t1), c2 = TREE_CODE (t2);
    8922              : 
    8923      1640058 :   gcc_assert ((INTEGRAL_TYPE_P (t1)
    8924              :                || c1 == REAL_TYPE
    8925              :                || c1 == FIXED_POINT_TYPE)
    8926              :               && (INTEGRAL_TYPE_P (t2)
    8927              :                   || c2 == REAL_TYPE
    8928              :                   || c2 == FIXED_POINT_TYPE));
    8929              : 
    8930      1640058 :   t1 = c_common_signed_type (t1);
    8931      1640058 :   t2 = c_common_signed_type (t2);
    8932              :   /* Equality works here because c_common_signed_type uses
    8933              :      TYPE_MAIN_VARIANT.  */
    8934      1640058 :   if (t1 == t2)
    8935              :     return true;
    8936           31 :   if (opaque && c1 == c2
    8937            4 :       && (INTEGRAL_TYPE_P (t1) || c1 == REAL_TYPE)
    8938           35 :       && TYPE_PRECISION (t1) == TYPE_PRECISION (t2))
    8939            4 :     return true;
    8940              :   return false;
    8941              : }
    8942              : 
    8943              : /* Check for missing format attributes on function pointers.  LTYPE is
    8944              :    the new type or left-hand side type.  RTYPE is the old type or
    8945              :    right-hand side type.  Returns TRUE if LTYPE is missing the desired
    8946              :    attribute.  */
    8947              : 
    8948              : bool
    8949        10184 : check_missing_format_attribute (tree ltype, tree rtype)
    8950              : {
    8951        10184 :   tree const ttr = TREE_TYPE (rtype), ttl = TREE_TYPE (ltype);
    8952        10184 :   tree ra;
    8953              : 
    8954        10193 :   for (ra = TYPE_ATTRIBUTES (ttr); ra; ra = TREE_CHAIN (ra))
    8955           73 :     if (is_attribute_p ("format", get_attribute_name (ra)))
    8956              :       break;
    8957        10184 :   if (ra)
    8958              :     {
    8959           64 :       tree la;
    8960           64 :       for (la = TYPE_ATTRIBUTES (ttl); la; la = TREE_CHAIN (la))
    8961           24 :         if (is_attribute_p ("format", get_attribute_name (la)))
    8962              :           break;
    8963           64 :       return !la;
    8964              :     }
    8965              :   else
    8966              :     return false;
    8967              : }
    8968              : 
    8969              : /* Setup a TYPE_DECL node as a typedef representation.
    8970              : 
    8971              :    X is a TYPE_DECL for a typedef statement.  Create a brand new
    8972              :    ..._TYPE node (which will be just a variant of the existing
    8973              :    ..._TYPE node with identical properties) and then install X
    8974              :    as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
    8975              : 
    8976              :    The whole point here is to end up with a situation where each
    8977              :    and every ..._TYPE node the compiler creates will be uniquely
    8978              :    associated with AT MOST one node representing a typedef name.
    8979              :    This way, even though the compiler substitutes corresponding
    8980              :    ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
    8981              :    early on, later parts of the compiler can always do the reverse
    8982              :    translation and get back the corresponding typedef name.  For
    8983              :    example, given:
    8984              : 
    8985              :         typedef struct S MY_TYPE;
    8986              :         MY_TYPE object;
    8987              : 
    8988              :    Later parts of the compiler might only know that `object' was of
    8989              :    type `struct S' if it were not for code just below.  With this
    8990              :    code however, later parts of the compiler see something like:
    8991              : 
    8992              :         struct S' == struct S
    8993              :         typedef struct S' MY_TYPE;
    8994              :         struct S' object;
    8995              : 
    8996              :     And they can then deduce (from the node for type struct S') that
    8997              :     the original object declaration was:
    8998              : 
    8999              :                 MY_TYPE object;
    9000              : 
    9001              :     Being able to do this is important for proper support of protoize,
    9002              :     and also for generating precise symbolic debugging information
    9003              :     which takes full account of the programmer's (typedef) vocabulary.
    9004              : 
    9005              :     Obviously, we don't want to generate a duplicate ..._TYPE node if
    9006              :     the TYPE_DECL node that we are now processing really represents a
    9007              :     standard built-in type.  */
    9008              : 
    9009              : void
    9010    204522019 : set_underlying_type (tree x)
    9011              : {
    9012    204522019 :   if (x == error_mark_node || TREE_TYPE (x) == error_mark_node)
    9013              :     return;
    9014    204521990 :   if (DECL_IS_UNDECLARED_BUILTIN (x) && TREE_CODE (TREE_TYPE (x)) != ARRAY_TYPE)
    9015              :     {
    9016      6567280 :       if (TYPE_NAME (TREE_TYPE (x)) == 0)
    9017      5246287 :         TYPE_NAME (TREE_TYPE (x)) = x;
    9018              :     }
    9019    197954710 :   else if (DECL_ORIGINAL_TYPE (x))
    9020       166092 :     gcc_checking_assert (TYPE_NAME (TREE_TYPE (x)) == x);
    9021              :   else
    9022              :     {
    9023    197788618 :       tree tt = TREE_TYPE (x);
    9024    197788618 :       DECL_ORIGINAL_TYPE (x) = tt;
    9025    197788618 :       tt = build_variant_type_copy (tt);
    9026    197788618 :       TYPE_STUB_DECL (tt) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x));
    9027    197788618 :       TYPE_NAME (tt) = x;
    9028              : 
    9029              :       /* Mark the type as used only when its type decl is decorated
    9030              :          with attribute unused.  */
    9031    197788618 :       if (lookup_attribute ("unused", DECL_ATTRIBUTES (x)))
    9032          263 :         TREE_USED (tt) = 1;
    9033              : 
    9034    197788618 :       TREE_TYPE (x) = tt;
    9035              :     }
    9036              : }
    9037              : 
    9038              : /* Return true if it is worth exposing the DECL_ORIGINAL_TYPE of TYPE to
    9039              :    the user in diagnostics, false if it would be better to use TYPE itself.
    9040              :    TYPE is known to satisfy typedef_variant_p.  */
    9041              : 
    9042              : bool
    9043        36199 : user_facing_original_type_p (const_tree type)
    9044              : {
    9045        36643 :   gcc_assert (typedef_variant_p (type));
    9046        36643 :   tree decl = TYPE_NAME (type);
    9047              : 
    9048              :   /* Look through any typedef in "user" code.  */
    9049        36643 :   if (!DECL_IN_SYSTEM_HEADER (decl) && !DECL_IS_UNDECLARED_BUILTIN (decl))
    9050              :     return true;
    9051              : 
    9052              :   /* If the original type is also named and is in the user namespace,
    9053              :      assume it too is a user-facing type.  */
    9054         2161 :   tree orig_type = DECL_ORIGINAL_TYPE (decl);
    9055         2161 :   if (tree orig_id = TYPE_IDENTIFIER (orig_type))
    9056         2033 :     if (!name_reserved_for_implementation_p (IDENTIFIER_POINTER (orig_id)))
    9057              :       return true;
    9058              : 
    9059          712 :   if (typedef_variant_p (orig_type))
    9060              :     return user_facing_original_type_p (orig_type);
    9061              : 
    9062          268 :   switch (TREE_CODE (orig_type))
    9063              :     {
    9064              :     /* Don't look through to an anonymous vector type, since the syntax
    9065              :        we use for them in diagnostics isn't real C or C++ syntax.
    9066              :        And if ORIG_TYPE is named but in the implementation namespace,
    9067              :        TYPE is likely to be more meaningful to the user.  */
    9068              :     case VECTOR_TYPE:
    9069              :       return false;
    9070              : 
    9071              :     /* Don't expose anonymous tag types that are presumably meant to be
    9072              :        known by their typedef name.  Also don't expose tags that are in
    9073              :        the implementation namespace, such as:
    9074              : 
    9075              :          typedef struct __foo foo;  */
    9076              :     case RECORD_TYPE:
    9077              :     case UNION_TYPE:
    9078              :     case ENUMERAL_TYPE:
    9079              :       return false;
    9080              : 
    9081              :     /* Look through to anything else.  */
    9082              :     default:
    9083              :       return true;
    9084              :     }
    9085              : }
    9086              : 
    9087              : /* Record the types used by the current global variable declaration
    9088              :    being parsed, so that we can decide later to emit their debug info.
    9089              :    Those types are in types_used_by_cur_var_decl, and we are going to
    9090              :    store them in the types_used_by_vars_hash hash table.
    9091              :    DECL is the declaration of the global variable that has been parsed.  */
    9092              : 
    9093              : void
    9094     36208504 : record_types_used_by_current_var_decl (tree decl)
    9095              : {
    9096     36208504 :   gcc_assert (decl && DECL_P (decl) && TREE_STATIC (decl));
    9097              : 
    9098     62546143 :   while (types_used_by_cur_var_decl && !types_used_by_cur_var_decl->is_empty ())
    9099              :     {
    9100     26337639 :       tree type = types_used_by_cur_var_decl->pop ();
    9101     26337639 :       types_used_by_var_decl_insert (type, decl);
    9102              :     }
    9103     36208504 : }
    9104              : 
    9105              : /* The C and C++ parsers both use vectors to hold function arguments.
    9106              :    For efficiency, we keep a cache of unused vectors.  This is the
    9107              :    cache.  */
    9108              : 
    9109              : typedef vec<tree, va_gc> *tree_gc_vec;
    9110              : static GTY((deletable)) vec<tree_gc_vec, va_gc> *tree_vector_cache;
    9111              : 
    9112              : /* Return a new vector from the cache.  If the cache is empty,
    9113              :    allocate a new vector.  These vectors are GC'ed, so it is OK if the
    9114              :    pointer is not released..  */
    9115              : 
    9116              : vec<tree, va_gc> *
    9117   1327518814 : make_tree_vector (void)
    9118              : {
    9119   1327518814 :   if (tree_vector_cache && !tree_vector_cache->is_empty ())
    9120   1284965664 :     return tree_vector_cache->pop ();
    9121              :   else
    9122              :     {
    9123              :       /* Passing 0 to vec::alloc returns NULL, and our callers require
    9124              :          that we always return a non-NULL value.  The vector code uses
    9125              :          4 when growing a NULL vector, so we do too.  */
    9126     42553150 :       vec<tree, va_gc> *v;
    9127     42553150 :       vec_alloc (v, 4);
    9128     42553150 :       return v;
    9129              :     }
    9130              : }
    9131              : 
    9132              : /* Release a vector of trees back to the cache.  */
    9133              : 
    9134              : void
    9135   1808036593 : release_tree_vector (vec<tree, va_gc> *vec)
    9136              : {
    9137   1808036593 :   if (vec != NULL)
    9138              :     {
    9139   1288072397 :       if (vec->allocated () >= 16)
    9140              :         /* Don't cache vecs that have expanded more than once.  On a p64
    9141              :            target, vecs double in alloc size with each power of 2 elements, e.g
    9142              :            at 16 elements the alloc increases from 128 to 256 bytes.  */
    9143      2235471 :         vec_free (vec);
    9144              :       else
    9145              :         {
    9146   1285836926 :           vec->truncate (0);
    9147   1285836926 :           vec_safe_push (tree_vector_cache, vec);
    9148              :         }
    9149              :     }
    9150   1808036593 : }
    9151              : 
    9152              : /* Get a new tree vector holding a single tree.  */
    9153              : 
    9154              : vec<tree, va_gc> *
    9155     68135608 : make_tree_vector_single (tree t)
    9156              : {
    9157     68135608 :   vec<tree, va_gc> *ret = make_tree_vector ();
    9158     68135608 :   ret->quick_push (t);
    9159     68135608 :   return ret;
    9160              : }
    9161              : 
    9162              : /* Get a new tree vector of the TREE_VALUEs of a TREE_LIST chain.  */
    9163              : 
    9164              : vec<tree, va_gc> *
    9165         7863 : make_tree_vector_from_list (tree list)
    9166              : {
    9167         7863 :   vec<tree, va_gc> *ret = make_tree_vector ();
    9168        21714 :   for (; list; list = TREE_CHAIN (list))
    9169        13851 :     vec_safe_push (ret, TREE_VALUE (list));
    9170         7863 :   return ret;
    9171              : }
    9172              : 
    9173              : /* Append to a tree vector V the values of a CONSTRUCTOR CTOR
    9174              :    and return the new possibly reallocated vector.  */
    9175              : 
    9176              : vec<tree, va_gc> *
    9177      2416328 : append_ctor_to_tree_vector (vec<tree, va_gc> *v, tree ctor)
    9178              : {
    9179      4603382 :   unsigned nelts = vec_safe_length (v) + CONSTRUCTOR_NELTS (ctor);
    9180      2416328 :   vec_safe_reserve (v, CONSTRUCTOR_NELTS (ctor));
    9181      5750011 :   for (unsigned i = 0; i < CONSTRUCTOR_NELTS (ctor); ++i)
    9182      3333683 :     if (TREE_CODE (CONSTRUCTOR_ELT (ctor, i)->value) == RAW_DATA_CST)
    9183              :       {
    9184           24 :         tree raw_data = CONSTRUCTOR_ELT (ctor, i)->value;
    9185           24 :         nelts += RAW_DATA_LENGTH (raw_data) - 1;
    9186           24 :         vec_safe_reserve (v, nelts - v->length ());
    9187           48 :         if (TYPE_PRECISION (TREE_TYPE (raw_data)) > CHAR_BIT
    9188           24 :             || TYPE_UNSIGNED (TREE_TYPE (raw_data)))
    9189         6264 :           for (unsigned j = 0; j < (unsigned) RAW_DATA_LENGTH (raw_data); ++j)
    9190         6240 :             v->quick_push (build_int_cst (TREE_TYPE (raw_data),
    9191         6240 :                                           RAW_DATA_UCHAR_ELT (raw_data, j)));
    9192              :         else
    9193            0 :           for (unsigned j = 0; j < (unsigned) RAW_DATA_LENGTH (raw_data); ++j)
    9194            0 :             v->quick_push (build_int_cst (TREE_TYPE (raw_data),
    9195            0 :                                           RAW_DATA_SCHAR_ELT (raw_data, j)));
    9196              :       }
    9197              :     else
    9198      3333659 :       v->quick_push (CONSTRUCTOR_ELT (ctor, i)->value);
    9199      2416328 :   return v;
    9200              : }
    9201              : 
    9202              : /* Get a new tree vector of the values of a CONSTRUCTOR.  */
    9203              : 
    9204              : vec<tree, va_gc> *
    9205         6430 : make_tree_vector_from_ctor (tree ctor)
    9206              : {
    9207         6430 :   vec<tree,va_gc> *ret
    9208         6430 :     = CONSTRUCTOR_NELTS (ctor) <= 16 ? make_tree_vector () : NULL;
    9209         6430 :   return append_ctor_to_tree_vector (ret, ctor);
    9210              : }
    9211              : 
    9212              : /* Get a new tree vector which is a copy of an existing one.  */
    9213              : 
    9214              : vec<tree, va_gc> *
    9215     28744618 : make_tree_vector_copy (const vec<tree, va_gc> *orig)
    9216              : {
    9217     28744618 :   vec<tree, va_gc> *ret;
    9218     28744618 :   unsigned int ix;
    9219     28744618 :   tree t;
    9220              : 
    9221     28744618 :   ret = make_tree_vector ();
    9222     28744618 :   vec_safe_reserve (ret, vec_safe_length (orig));
    9223     71554382 :   FOR_EACH_VEC_SAFE_ELT (orig, ix, t)
    9224     14065146 :     ret->quick_push (t);
    9225     28744618 :   return ret;
    9226              : }
    9227              : 
    9228              : /* Return true if KEYWORD starts a type specifier.  */
    9229              : 
    9230              : bool
    9231           22 : keyword_begins_type_specifier (enum rid keyword)
    9232              : {
    9233           22 :   switch (keyword)
    9234              :     {
    9235              :     case RID_AUTO_TYPE:
    9236              :     case RID_INT:
    9237              :     case RID_CHAR:
    9238              :     case RID_FLOAT:
    9239              :     case RID_DOUBLE:
    9240              :     case RID_VOID:
    9241              :     case RID_UNSIGNED:
    9242              :     case RID_LONG:
    9243              :     case RID_SHORT:
    9244              :     case RID_SIGNED:
    9245              :     CASE_RID_FLOATN_NX:
    9246              :     case RID_DFLOAT32:
    9247              :     case RID_DFLOAT64:
    9248              :     case RID_DFLOAT128:
    9249              :     case RID_FRACT:
    9250              :     case RID_ACCUM:
    9251              :     case RID_BOOL:
    9252              :     case RID_BITINT:
    9253              :     case RID_WCHAR:
    9254              :     case RID_CHAR8:
    9255              :     case RID_CHAR16:
    9256              :     case RID_CHAR32:
    9257              :     case RID_SAT:
    9258              :     case RID_COMPLEX:
    9259              :     case RID_TYPEOF:
    9260              :     case RID_STRUCT:
    9261              :     case RID_CLASS:
    9262              :     case RID_UNION:
    9263              :     case RID_ENUM:
    9264              :       return true;
    9265            7 :     default:
    9266            7 :       if (keyword >= RID_FIRST_INT_N
    9267              :           && keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS
    9268            0 :           && int_n_enabled_p[keyword-RID_FIRST_INT_N])
    9269              :         return true;
    9270              :       return false;
    9271              :     }
    9272              : }
    9273              : 
    9274              : /* Return true if KEYWORD names a type qualifier.  */
    9275              : 
    9276              : bool
    9277        12122 : keyword_is_type_qualifier (enum rid keyword)
    9278              : {
    9279        12122 :   switch (keyword)
    9280              :     {
    9281              :     case RID_CONST:
    9282              :     case RID_VOLATILE:
    9283              :     case RID_RESTRICT:
    9284              :     case RID_ATOMIC:
    9285              :       return true;
    9286           64 :     default:
    9287           64 :       return false;
    9288              :     }
    9289              : }
    9290              : 
    9291              : /* Return true if KEYWORD names a storage class specifier.
    9292              : 
    9293              :    RID_TYPEDEF is not included in this list despite `typedef' being
    9294              :    listed in C99 6.7.1.1.  6.7.1.3 indicates that `typedef' is listed as
    9295              :    such for syntactic convenience only.  */
    9296              : 
    9297              : bool
    9298        12155 : keyword_is_storage_class_specifier (enum rid keyword)
    9299              : {
    9300        12155 :   switch (keyword)
    9301              :     {
    9302              :     case RID_STATIC:
    9303              :     case RID_EXTERN:
    9304              :     case RID_REGISTER:
    9305              :     case RID_AUTO:
    9306              :     case RID_MUTABLE:
    9307              :     case RID_THREAD:
    9308              :       return true;
    9309        12122 :     default:
    9310        12122 :       return false;
    9311              :     }
    9312              : }
    9313              : 
    9314              : /* Return true if KEYWORD names a function-specifier [dcl.fct.spec].  */
    9315              : 
    9316              : static bool
    9317           64 : keyword_is_function_specifier (enum rid keyword)
    9318              : {
    9319           64 :   switch (keyword)
    9320              :     {
    9321              :     case RID_INLINE:
    9322              :     case RID_NORETURN:
    9323              :     case RID_VIRTUAL:
    9324              :     case RID_EXPLICIT:
    9325              :       return true;
    9326           62 :     default:
    9327            0 :       return false;
    9328              :     }
    9329              : }
    9330              : 
    9331              : /* Return true if KEYWORD names a decl-specifier [dcl.spec] or a
    9332              :    declaration-specifier (C99 6.7).  */
    9333              : 
    9334              : bool
    9335        12155 : keyword_is_decl_specifier (enum rid keyword)
    9336              : {
    9337        12155 :   if (keyword_is_storage_class_specifier (keyword)
    9338        12122 :       || keyword_is_type_qualifier (keyword)
    9339        12155 :       || keyword_is_function_specifier (keyword))
    9340        12093 :     return true;
    9341              : 
    9342           62 :   switch (keyword)
    9343              :     {
    9344              :     case RID_TYPEDEF:
    9345              :     case RID_FRIEND:
    9346              :     case RID_CONSTEXPR:
    9347              :     case RID_CONSTINIT:
    9348              :       return true;
    9349              :     default:
    9350              :       return false;
    9351              :     }
    9352              : }
    9353              : 
    9354              : /* Initialize language-specific-bits of tree_contains_struct.  */
    9355              : 
    9356              : void
    9357       216649 : c_common_init_ts (void)
    9358              : {
    9359       216649 :   MARK_TS_EXP (SIZEOF_EXPR);
    9360       216649 :   MARK_TS_EXP (PAREN_SIZEOF_EXPR);
    9361       216649 :   MARK_TS_EXP (C_MAYBE_CONST_EXPR);
    9362       216649 :   MARK_TS_EXP (EXCESS_PRECISION_EXPR);
    9363       216649 :   MARK_TS_EXP (BREAK_STMT);
    9364       216649 :   MARK_TS_EXP (CONTINUE_STMT);
    9365       216649 :   MARK_TS_EXP (DO_STMT);
    9366       216649 :   MARK_TS_EXP (FOR_STMT);
    9367       216649 :   MARK_TS_EXP (SWITCH_STMT);
    9368       216649 :   MARK_TS_EXP (WHILE_STMT);
    9369              : 
    9370       216649 :   MARK_TS_DECL_COMMON (CONCEPT_DECL);
    9371       216649 : }
    9372              : 
    9373              : /* Build a user-defined numeric literal out of an integer constant type VALUE
    9374              :    with identifier SUFFIX.  */
    9375              : 
    9376              : tree
    9377      1126885 : build_userdef_literal (tree suffix_id, tree value,
    9378              :                        enum overflow_type overflow, tree num_string)
    9379              : {
    9380      1126885 :   tree literal = make_node (USERDEF_LITERAL);
    9381      1126885 :   USERDEF_LITERAL_SUFFIX_ID (literal) = suffix_id;
    9382      1126885 :   USERDEF_LITERAL_VALUE (literal) = value;
    9383      1126885 :   USERDEF_LITERAL_OVERFLOW (literal) = overflow;
    9384      1126885 :   USERDEF_LITERAL_NUM_STRING (literal) = num_string;
    9385      1126885 :   return literal;
    9386              : }
    9387              : 
    9388              : /* For vector[index], convert the vector to an array of the underlying type.
    9389              :    Return true if the resulting ARRAY_REF should not be an lvalue.  */
    9390              : 
    9391              : bool
    9392      9406851 : convert_vector_to_array_for_subscript (location_t loc,
    9393              :                                        tree *vecp, tree index)
    9394              : {
    9395      9406851 :   bool ret = false;
    9396      9406851 :   if (gnu_vector_type_p (TREE_TYPE (*vecp)))
    9397              :     {
    9398      1083632 :       tree type = TREE_TYPE (*vecp);
    9399      1083632 :       tree newitype;
    9400              : 
    9401      1083632 :       ret = !lvalue_p (*vecp);
    9402              : 
    9403      1083632 :       index = fold_for_warn (index);
    9404              :       /* Warn out-of-bounds index for vectors only if known.  */
    9405      1083632 :       if (poly_int_tree_p (index))
    9406      1070203 :         if (!tree_fits_poly_uint64_p (index)
    9407      1070203 :             || known_ge (tree_to_poly_uint64 (index),
    9408              :                           TYPE_VECTOR_SUBPARTS (type)))
    9409           84 :             warning_at (loc, OPT_Warray_bounds_, "index value is out of bound");
    9410              : 
    9411              :       /* We are building an ARRAY_REF so mark the vector as addressable
    9412              :          to not run into the gimplifiers premature setting of DECL_GIMPLE_REG_P
    9413              :          for function parameters.  */
    9414      1083632 :       c_common_mark_addressable_vec (*vecp);
    9415              : 
    9416              :       /* Make sure qualifiers are copied from the vector type to the new element
    9417              :          of the array type.  */
    9418      1083632 :       newitype = build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
    9419              : 
    9420      1083632 :       *vecp = build1 (VIEW_CONVERT_EXPR,
    9421              :                       build_array_type_nelts (newitype,
    9422              :                                               TYPE_VECTOR_SUBPARTS (type)),
    9423              :                       *vecp);
    9424              :     }
    9425      9406851 :   return ret;
    9426              : }
    9427              : 
    9428              : /* Determine which of the operands, if any, is a scalar that needs to be
    9429              :    converted to a vector, for the range of operations.  */
    9430              : enum stv_conv
    9431         3694 : scalar_to_vector (location_t loc, enum tree_code code, tree op0, tree op1,
    9432              :                   bool complain)
    9433              : {
    9434         3694 :   tree type0 = TREE_TYPE (op0);
    9435         3694 :   tree type1 = TREE_TYPE (op1);
    9436         3694 :   bool integer_only_op = false;
    9437         3694 :   enum stv_conv ret = stv_firstarg;
    9438              : 
    9439         3694 :   gcc_assert (gnu_vector_type_p (type0) || gnu_vector_type_p (type1));
    9440         3694 :   switch (code)
    9441              :     {
    9442              :       /* Most GENERIC binary expressions require homogeneous arguments.
    9443              :          LSHIFT_EXPR and RSHIFT_EXPR are exceptions and accept a first
    9444              :          argument that is a vector and a second one that is a scalar, so
    9445              :          we never return stv_secondarg for them.  */
    9446          986 :       case RSHIFT_EXPR:
    9447          986 :       case LSHIFT_EXPR:
    9448          986 :         if (TREE_CODE (type0) == INTEGER_TYPE
    9449          986 :             && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE)
    9450              :           {
    9451           50 :             if (unsafe_conversion_p (TREE_TYPE (type1), op0,
    9452              :                                      NULL_TREE, false))
    9453              :               {
    9454            0 :                 if (complain)
    9455            0 :                   error_at (loc, "conversion of scalar %qT to vector %qT "
    9456              :                             "involves truncation", type0, type1);
    9457            0 :                 return stv_error;
    9458              :               }
    9459              :             else
    9460              :               return stv_firstarg;
    9461              :           }
    9462              :         break;
    9463              : 
    9464          315 :       case BIT_IOR_EXPR:
    9465          315 :       case BIT_XOR_EXPR:
    9466          315 :       case BIT_AND_EXPR:
    9467          315 :         integer_only_op = true;
    9468              :         /* fall through */
    9469              : 
    9470         2696 :       case VEC_COND_EXPR:
    9471              : 
    9472         2696 :       case PLUS_EXPR:
    9473         2696 :       case MINUS_EXPR:
    9474         2696 :       case MULT_EXPR:
    9475         2696 :       case TRUNC_DIV_EXPR:
    9476         2696 :       case CEIL_DIV_EXPR:
    9477         2696 :       case FLOOR_DIV_EXPR:
    9478         2696 :       case ROUND_DIV_EXPR:
    9479         2696 :       case EXACT_DIV_EXPR:
    9480         2696 :       case TRUNC_MOD_EXPR:
    9481         2696 :       case FLOOR_MOD_EXPR:
    9482         2696 :       case RDIV_EXPR:
    9483         2696 :       case EQ_EXPR:
    9484         2696 :       case NE_EXPR:
    9485         2696 :       case LE_EXPR:
    9486         2696 :       case GE_EXPR:
    9487         2696 :       case LT_EXPR:
    9488         2696 :       case GT_EXPR:
    9489              :       /* What about UNLT_EXPR?  */
    9490         2696 :         if (gnu_vector_type_p (type0))
    9491              :           {
    9492         2031 :             ret = stv_secondarg;
    9493         2031 :             std::swap (type0, type1);
    9494         2031 :             std::swap (op0, op1);
    9495              :           }
    9496              : 
    9497         2696 :         if (TREE_CODE (type0) == INTEGER_TYPE
    9498         2696 :             && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE)
    9499              :           {
    9500         1980 :             if (unsafe_conversion_p (TREE_TYPE (type1), op0,
    9501              :                                      NULL_TREE, false))
    9502              :               {
    9503           11 :                 if (complain)
    9504            8 :                   error_at (loc, "conversion of scalar %qT to vector %qT "
    9505              :                             "involves truncation", type0, type1);
    9506           11 :                 return stv_error;
    9507              :               }
    9508              :             return ret;
    9509              :           }
    9510          716 :         else if (!integer_only_op
    9511              :                     /* Allow integer --> real conversion if safe.  */
    9512          716 :                  && (SCALAR_FLOAT_TYPE_P (type0)
    9513          470 :                      || TREE_CODE (type0) == INTEGER_TYPE)
    9514         1432 :                  && SCALAR_FLOAT_TYPE_P (TREE_TYPE (type1)))
    9515              :           {
    9516          692 :             if (unsafe_conversion_p (TREE_TYPE (type1), op0,
    9517              :                                      NULL_TREE, false))
    9518              :               {
    9519           22 :                 if (complain)
    9520           22 :                   error_at (loc, "conversion of scalar %qT to vector %qT "
    9521              :                             "involves truncation", type0, type1);
    9522           22 :                 return stv_error;
    9523              :               }
    9524              :             return ret;
    9525              :           }
    9526              :       default:
    9527              :         break;
    9528              :     }
    9529              : 
    9530              :   return stv_nothing;
    9531              : }
    9532              : 
    9533              : /* Return the alignment of std::max_align_t.
    9534              : 
    9535              :    [support.types.layout] The type max_align_t is a POD type whose alignment
    9536              :    requirement is at least as great as that of every scalar type, and whose
    9537              :    alignment requirement is supported in every context.  */
    9538              : 
    9539              : unsigned
    9540       262135 : max_align_t_align ()
    9541              : {
    9542       262135 :   unsigned int max_align = MAX (TYPE_ALIGN (long_long_integer_type_node),
    9543              :                                 TYPE_ALIGN (long_double_type_node));
    9544       262135 :   if (float128_type_node != NULL_TREE)
    9545       262135 :     max_align = MAX (max_align, TYPE_ALIGN (float128_type_node));
    9546       262135 :   return max_align;
    9547              : }
    9548              : 
    9549              : /* Return true iff ALIGN is an integral constant that is a fundamental
    9550              :    alignment, as defined by [basic.align] in the c++-11
    9551              :    specifications.
    9552              : 
    9553              :    That is:
    9554              : 
    9555              :        [A fundamental alignment is represented by an alignment less than or
    9556              :         equal to the greatest alignment supported by the implementation
    9557              :         in all contexts, which is equal to alignof(max_align_t)].  */
    9558              : 
    9559              : bool
    9560            0 : cxx_fundamental_alignment_p (unsigned align)
    9561              : {
    9562            0 :   return (align <= max_align_t_align ());
    9563              : }
    9564              : 
    9565              : /* Return true if T is a pointer to a zero-sized aggregate.  */
    9566              : 
    9567              : bool
    9568      1464990 : pointer_to_zero_sized_aggr_p (tree t)
    9569              : {
    9570      1464990 :   if (!POINTER_TYPE_P (t))
    9571              :     return false;
    9572      1464990 :   t = TREE_TYPE (t);
    9573      1464990 :   return (TYPE_SIZE (t) && integer_zerop (TYPE_SIZE (t)));
    9574              : }
    9575              : 
    9576              : /* For an EXPR of a FUNCTION_TYPE that references a GCC built-in function
    9577              :    with no library fallback or for an ADDR_EXPR whose operand is such type
    9578              :    issues an error pointing to the location LOC.
    9579              :    Returns true when the expression has been diagnosed and false
    9580              :    otherwise.  */
    9581              : 
    9582              : bool
    9583   5903654424 : reject_gcc_builtin (const_tree expr, location_t loc /* = UNKNOWN_LOCATION */)
    9584              : {
    9585   5903654424 :   if (TREE_CODE (expr) == ADDR_EXPR)
    9586    164650466 :     expr = TREE_OPERAND (expr, 0);
    9587              : 
    9588   5903654424 :   STRIP_ANY_LOCATION_WRAPPER (expr);
    9589              : 
    9590   5903654424 :   if (TREE_TYPE (expr)
    9591   5903654164 :       && TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE
    9592      2697629 :       && TREE_CODE (expr) == FUNCTION_DECL
    9593              :       /* The intersection of DECL_BUILT_IN and DECL_IS_UNDECLARED_BUILTIN avoids
    9594              :          false positives for user-declared built-ins such as abs or
    9595              :          strlen, and for C++ operators new and delete.
    9596              :          The c_decl_implicit() test avoids false positives for implicitly
    9597              :          declared built-ins with library fallbacks (such as abs).  */
    9598      2664821 :       && fndecl_built_in_p (expr)
    9599        99953 :       && DECL_IS_UNDECLARED_BUILTIN (expr)
    9600         2408 :       && !c_decl_implicit (expr)
    9601   5903656827 :       && !DECL_ASSEMBLER_NAME_SET_P (expr))
    9602              :     {
    9603          220 :       if (loc == UNKNOWN_LOCATION)
    9604           83 :         loc = EXPR_LOC_OR_LOC (expr, input_location);
    9605              : 
    9606              :       /* Reject arguments that are built-in functions with
    9607              :          no library fallback.  */
    9608          220 :       error_at (loc, "built-in function %qE must be directly called", expr);
    9609              : 
    9610          220 :       return true;
    9611              :     }
    9612              : 
    9613              :   return false;
    9614              : }
    9615              : 
    9616              : /* Issue an ERROR for an invalid SIZE of array NAME which is null
    9617              :    for unnamed arrays.  */
    9618              : 
    9619              : void
    9620         1429 : invalid_array_size_error (location_t loc, cst_size_error error,
    9621              :                           const_tree size, const_tree name)
    9622              : {
    9623         1429 :   tree maxsize = max_object_size ();
    9624         1429 :   switch (error)
    9625              :     {
    9626            0 :     case cst_size_not_constant:
    9627            0 :       if (name)
    9628            0 :         error_at (loc, "size of array %qE is not a constant expression",
    9629              :                   name);
    9630              :       else
    9631            0 :         error_at (loc, "size of array is not a constant expression");
    9632              :       break;
    9633          439 :     case cst_size_negative:
    9634          439 :       if (name)
    9635          148 :         error_at (loc, "size %qE of array %qE is negative",
    9636              :                   size, name);
    9637              :       else
    9638          291 :         error_at (loc, "size %qE of array is negative",
    9639              :                   size);
    9640              :       break;
    9641          930 :     case cst_size_too_big:
    9642          930 :       if (name)
    9643          103 :         error_at (loc, "size %qE of array %qE exceeds maximum "
    9644              :                   "object size %qE", size, name, maxsize);
    9645              :       else
    9646          827 :         error_at (loc, "size %qE of array exceeds maximum "
    9647              :                   "object size %qE", size, maxsize);
    9648              :       break;
    9649           60 :     case cst_size_overflow:
    9650           60 :       if (name)
    9651           39 :         error_at (loc, "size of array %qE exceeds maximum "
    9652              :                   "object size %qE", name, maxsize);
    9653              :       else
    9654           21 :         error_at (loc, "size of array exceeds maximum "
    9655              :                   "object size %qE", maxsize);
    9656              :       break;
    9657            0 :     default:
    9658            0 :       gcc_unreachable ();
    9659              :     }
    9660         1429 : }
    9661              : 
    9662              : /* Check if array size calculations overflow or if the array covers more
    9663              :    than half of the address space.  Return true if the size of the array
    9664              :    is valid, false otherwise.  T is either the type of the array or its
    9665              :    size, and NAME is the name of the array, or null for unnamed arrays.  */
    9666              : 
    9667              : bool
    9668      9645658 : valid_array_size_p (location_t loc, const_tree t, tree name, bool complain)
    9669              : {
    9670      9645658 :   if (t == error_mark_node)
    9671              :     return true;
    9672              : 
    9673      9645517 :   const_tree size;
    9674      9645517 :   if (TYPE_P (t))
    9675              :     {
    9676      7135587 :       if (!COMPLETE_TYPE_P (t))
    9677              :         return true;
    9678      3033036 :       size = TYPE_SIZE_UNIT (t);
    9679              :     }
    9680              :   else
    9681              :     size = t;
    9682              : 
    9683      5542966 :   if (TREE_CODE (size) != INTEGER_CST)
    9684              :     return true;
    9685              : 
    9686      5518383 :   cst_size_error error;
    9687      5518383 :   if (valid_constant_size_p (size, &error))
    9688              :     return true;
    9689              : 
    9690         1120 :   if (!complain)
    9691              :     return false;
    9692              : 
    9693         1105 :   if (TREE_CODE (TREE_TYPE (size)) == ENUMERAL_TYPE)
    9694              :     /* Show the value of the enumerator rather than its name.  */
    9695           16 :     size = convert (ssizetype, const_cast<tree> (size));
    9696              : 
    9697         1105 :   invalid_array_size_error (loc, error, size, name);
    9698         1105 :   return false;
    9699              : }
    9700              : 
    9701              : /* Read SOURCE_DATE_EPOCH from environment to have a deterministic
    9702              :    timestamp to replace embedded current dates to get reproducible
    9703              :    results.  Returns -1 if SOURCE_DATE_EPOCH is not defined.  */
    9704              : 
    9705              : time_t
    9706         2777 : cb_get_source_date_epoch (cpp_reader *pfile ATTRIBUTE_UNUSED)
    9707              : {
    9708         2777 :   char *source_date_epoch;
    9709         2777 :   int64_t epoch;
    9710         2777 :   char *endptr;
    9711              : 
    9712         2777 :   source_date_epoch = getenv ("SOURCE_DATE_EPOCH");
    9713         2777 :   if (!source_date_epoch)
    9714              :     return (time_t) -1;
    9715              : 
    9716            3 :   errno = 0;
    9717              : #if defined(INT64_T_IS_LONG)
    9718            3 :   epoch = strtol (source_date_epoch, &endptr, 10);
    9719              : #else
    9720              :   epoch = strtoll (source_date_epoch, &endptr, 10);
    9721              : #endif
    9722            3 :   if (errno != 0 || endptr == source_date_epoch || *endptr != '\0'
    9723            2 :       || epoch < 0 || epoch > MAX_SOURCE_DATE_EPOCH)
    9724              :     {
    9725            1 :       error_at (input_location, "environment variable %qs must "
    9726              :                 "expand to a non-negative integer less than or equal to %wd",
    9727              :                 "SOURCE_DATE_EPOCH", MAX_SOURCE_DATE_EPOCH);
    9728            1 :       return (time_t) -1;
    9729              :     }
    9730              : 
    9731              :   return (time_t) epoch;
    9732              : }
    9733              : 
    9734              : /* Callback for libcpp for offering spelling suggestions for misspelled
    9735              :    directives.  GOAL is an unrecognized string; CANDIDATES is a
    9736              :    NULL-terminated array of candidate strings.  Return the closest
    9737              :    match to GOAL within CANDIDATES, or NULL if none are good
    9738              :    suggestions.  */
    9739              : 
    9740              : const char *
    9741           19 : cb_get_suggestion (cpp_reader *, const char *goal,
    9742              :                    const char *const *candidates)
    9743              : {
    9744           19 :   best_match<const char *, const char *> bm (goal);
    9745          204 :   while (*candidates)
    9746          166 :     bm.consider (*candidates++);
    9747           19 :   return bm.get_best_meaningful_candidate ();
    9748              : }
    9749              : 
    9750              : /* Return the lattice point which is the wider of the two FLT_EVAL_METHOD
    9751              :    modes X, Y.  This isn't just  >, as the FLT_EVAL_METHOD values added
    9752              :    by C TS 18661-3 for interchange  types that are computed in their
    9753              :    native precision are larger than the C11 values for evaluating in the
    9754              :    precision of float/double/long double.  If either mode is
    9755              :    FLT_EVAL_METHOD_UNPREDICTABLE, return that.  */
    9756              : 
    9757              : enum flt_eval_method
    9758       549770 : excess_precision_mode_join (enum flt_eval_method x,
    9759              :                             enum flt_eval_method y)
    9760              : {
    9761       549770 :   if (x == FLT_EVAL_METHOD_UNPREDICTABLE
    9762       549770 :       || y == FLT_EVAL_METHOD_UNPREDICTABLE)
    9763              :     return FLT_EVAL_METHOD_UNPREDICTABLE;
    9764              : 
    9765              :   /* GCC only supports one interchange type right now, _Float16.  If
    9766              :      we're evaluating _Float16 in 16-bit precision, then flt_eval_method
    9767              :      will be FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16.  */
    9768       549444 :   if (x == FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16)
    9769              :     return y;
    9770       547091 :   if (y == FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16)
    9771              :     return x;
    9772              : 
    9773              :   /* Other values for flt_eval_method are directly comparable, and we want
    9774              :      the maximum.  */
    9775       547079 :   return MAX (x, y);
    9776              : }
    9777              : 
    9778              : /* Return the value that should be set for FLT_EVAL_METHOD in the
    9779              :    context of ISO/IEC TS 18861-3.
    9780              : 
    9781              :    This relates to the effective excess precision seen by the user,
    9782              :    which is the join point of the precision the target requests for
    9783              :    -fexcess-precision={standard,fast,16} and the implicit excess precision
    9784              :    the target uses.  */
    9785              : 
    9786              : static enum flt_eval_method
    9787       431538 : c_ts18661_flt_eval_method (void)
    9788              : {
    9789       431538 :   enum flt_eval_method implicit
    9790       431538 :     = targetm.c.excess_precision (EXCESS_PRECISION_TYPE_IMPLICIT);
    9791              : 
    9792       312228 :   enum excess_precision_type flag_type
    9793       431538 :     = (flag_excess_precision == EXCESS_PRECISION_STANDARD
    9794       431538 :        ? EXCESS_PRECISION_TYPE_STANDARD
    9795              :        : (flag_excess_precision == EXCESS_PRECISION_FLOAT16
    9796       312240 :           ? EXCESS_PRECISION_TYPE_FLOAT16
    9797              :           : EXCESS_PRECISION_TYPE_FAST));
    9798              : 
    9799       431538 :   enum flt_eval_method requested
    9800       431538 :     = targetm.c.excess_precision (flag_type);
    9801              : 
    9802       431538 :   return excess_precision_mode_join (implicit, requested);
    9803              : }
    9804              : 
    9805              : /* As c_cpp_ts18661_flt_eval_method, but clamps the expected values to
    9806              :    those that were permitted by C11.  That is to say, eliminates
    9807              :    FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16.  */
    9808              : 
    9809              : static enum flt_eval_method
    9810       105744 : c_c11_flt_eval_method (void)
    9811              : {
    9812       105744 :   return excess_precision_mode_join (c_ts18661_flt_eval_method (),
    9813       105744 :                                      FLT_EVAL_METHOD_PROMOTE_TO_FLOAT);
    9814              : }
    9815              : 
    9816              : /* Return the value that should be set for FLT_EVAL_METHOD.
    9817              :    MAYBE_C11_ONLY_P is TRUE if we should check
    9818              :    FLAG_PERMITTED_EVAL_METHODS as to whether we should limit the possible
    9819              :    values we can return to those from C99/C11, and FALSE otherwise.
    9820              :    See the comments on c_ts18661_flt_eval_method for what value we choose
    9821              :    to set here.  */
    9822              : 
    9823              : int
    9824       431538 : c_flt_eval_method (bool maybe_c11_only_p)
    9825              : {
    9826       431538 :   if (maybe_c11_only_p
    9827       215769 :       && flag_permitted_flt_eval_methods
    9828              :           == PERMITTED_FLT_EVAL_METHODS_C11)
    9829       105744 :     return c_c11_flt_eval_method ();
    9830              :   else
    9831       325794 :     return c_ts18661_flt_eval_method ();
    9832              : }
    9833              : 
    9834              : /* An enum for get_missing_token_insertion_kind for describing the best
    9835              :    place to insert a missing token, if there is one.  */
    9836              : 
    9837              : enum missing_token_insertion_kind
    9838              : {
    9839              :   MTIK_IMPOSSIBLE,
    9840              :   MTIK_INSERT_BEFORE_NEXT,
    9841              :   MTIK_INSERT_AFTER_PREV
    9842              : };
    9843              : 
    9844              : /* Given a missing token of TYPE, determine if it is reasonable to
    9845              :    emit a fix-it hint suggesting the insertion of the token, and,
    9846              :    if so, where the token should be inserted relative to other tokens.
    9847              : 
    9848              :    It only makes sense to do this for values of TYPE that are symbols.
    9849              : 
    9850              :    Some symbols should go before the next token, e.g. in:
    9851              :      if flag)
    9852              :    we want to insert the missing '(' immediately before "flag",
    9853              :    giving:
    9854              :      if (flag)
    9855              :    rather than:
    9856              :      if( flag)
    9857              :    These use MTIK_INSERT_BEFORE_NEXT.
    9858              : 
    9859              :    Other symbols should go after the previous token, e.g. in:
    9860              :      if (flag
    9861              :        do_something ();
    9862              :    we want to insert the missing ')' immediately after the "flag",
    9863              :    giving:
    9864              :      if (flag)
    9865              :        do_something ();
    9866              :    rather than:
    9867              :      if (flag
    9868              :        )do_something ();
    9869              :    These use MTIK_INSERT_AFTER_PREV.  */
    9870              : 
    9871              : static enum missing_token_insertion_kind
    9872         3346 : get_missing_token_insertion_kind (enum cpp_ttype type)
    9873              : {
    9874         3346 :   switch (type)
    9875              :     {
    9876              :       /* Insert missing "opening" brackets immediately
    9877              :          before the next token.  */
    9878              :     case CPP_OPEN_SQUARE:
    9879              :     case CPP_OPEN_PAREN:
    9880              :       return MTIK_INSERT_BEFORE_NEXT;
    9881              : 
    9882              :       /* Insert other missing symbols immediately after
    9883              :          the previous token.  */
    9884         2021 :     case CPP_CLOSE_PAREN:
    9885         2021 :     case CPP_CLOSE_SQUARE:
    9886         2021 :     case CPP_SEMICOLON:
    9887         2021 :     case CPP_COMMA:
    9888         2021 :     case CPP_COLON:
    9889         2021 :       return MTIK_INSERT_AFTER_PREV;
    9890              : 
    9891              :       /* Other kinds of token don't get fix-it hints.  */
    9892         1023 :     default:
    9893         1023 :       return MTIK_IMPOSSIBLE;
    9894              :     }
    9895              : }
    9896              : 
    9897              : /* Given RICHLOC, a location for a diagnostic describing a missing token
    9898              :    of kind TOKEN_TYPE, potentially add a fix-it hint suggesting the
    9899              :    insertion of the token.
    9900              : 
    9901              :    The location of the attempted fix-it hint depends on TOKEN_TYPE:
    9902              :    it will either be:
    9903              :      (a) immediately after PREV_TOKEN_LOC, or
    9904              : 
    9905              :      (b) immediately before the primary location within RICHLOC (taken to
    9906              :          be that of the token following where the token was expected).
    9907              : 
    9908              :    If we manage to add a fix-it hint, then the location of the
    9909              :    fix-it hint is likely to be more useful as the primary location
    9910              :    of the diagnostic than that of the following token, so we swap
    9911              :    these locations.
    9912              : 
    9913              :    For example, given this bogus code:
    9914              :        123456789012345678901234567890
    9915              :    1 | int missing_semicolon (void)
    9916              :    2 | {
    9917              :    3 |   return 42
    9918              :    4 | }
    9919              : 
    9920              :    we will emit:
    9921              : 
    9922              :      "expected ';' before '}'"
    9923              : 
    9924              :    RICHLOC's primary location is at the closing brace, so before "swapping"
    9925              :    we would emit the error at line 4 column 1:
    9926              : 
    9927              :        123456789012345678901234567890
    9928              :    3 |   return 42  |< fix-it hint emitted for this line
    9929              :      |            ; |
    9930              :    4 | }            |< "expected ';' before '}'" emitted at this line
    9931              :      | ^            |
    9932              : 
    9933              :    It's more useful for the location of the diagnostic to be at the
    9934              :    fix-it hint, so we swap the locations, so the primary location
    9935              :    is at the fix-it hint, with the old primary location inserted
    9936              :    as a secondary location, giving this, with the error at line 3
    9937              :    column 12:
    9938              : 
    9939              :        123456789012345678901234567890
    9940              :    3 |   return 42   |< "expected ';' before '}'" emitted at this line,
    9941              :      |            ^  |   with fix-it hint
    9942              :    4 |            ;  |
    9943              :      | }             |< secondary range emitted here
    9944              :      | ~             |.  */
    9945              : 
    9946              : void
    9947         3346 : maybe_suggest_missing_token_insertion (rich_location *richloc,
    9948              :                                        enum cpp_ttype token_type,
    9949              :                                        location_t prev_token_loc)
    9950              : {
    9951         3346 :   gcc_assert (richloc);
    9952              : 
    9953         3346 :   enum missing_token_insertion_kind mtik
    9954         3346 :     = get_missing_token_insertion_kind (token_type);
    9955              : 
    9956         3346 :   switch (mtik)
    9957              :     {
    9958              :     default:
    9959              :       gcc_unreachable ();
    9960              :       break;
    9961              : 
    9962              :     case MTIK_IMPOSSIBLE:
    9963              :       return;
    9964              : 
    9965          302 :     case MTIK_INSERT_BEFORE_NEXT:
    9966              :       /* Attempt to add the fix-it hint before the primary location
    9967              :          of RICHLOC.  */
    9968          302 :       richloc->add_fixit_insert_before (cpp_type2name (token_type, 0));
    9969          302 :       break;
    9970              : 
    9971         2021 :     case MTIK_INSERT_AFTER_PREV:
    9972              :       /* Attempt to add the fix-it hint after PREV_TOKEN_LOC.  */
    9973         2021 :       richloc->add_fixit_insert_after (prev_token_loc,
    9974              :                                        cpp_type2name (token_type, 0));
    9975         2021 :       break;
    9976              :     }
    9977              : 
    9978              :   /* If we were successful, use the fix-it hint's location as the
    9979              :      primary location within RICHLOC, adding the old primary location
    9980              :      back as a secondary location.  */
    9981         2323 :   if (!richloc->seen_impossible_fixit_p ())
    9982              :     {
    9983         2319 :       fixit_hint *hint = richloc->get_last_fixit_hint ();
    9984         2319 :       location_t hint_loc = hint->get_start_loc ();
    9985         2319 :       location_t old_loc = richloc->get_loc ();
    9986              : 
    9987         2319 :       richloc->set_range (0, hint_loc, SHOW_RANGE_WITH_CARET);
    9988         2319 :       richloc->add_range (old_loc);
    9989              :     }
    9990              : }
    9991              : 
    9992              : /* Potentially emit a note about likely missing '&' or '*',
    9993              :    depending on EXPR and EXPECTED_TYPE.  */
    9994              : 
    9995              : void
    9996         2142 : maybe_emit_indirection_note (location_t loc,
    9997              :                              tree expr, tree expected_type)
    9998              : {
    9999         2142 :   gcc_assert (expr);
   10000         2142 :   gcc_assert (expected_type);
   10001              : 
   10002         2142 :   tree actual_type = TREE_TYPE (expr);
   10003              : 
   10004              :   /* Missing '&'.  */
   10005         2142 :   if (TREE_CODE (expected_type) == POINTER_TYPE
   10006         1218 :       && compatible_types_for_indirection_note_p (actual_type,
   10007         1218 :                                                   TREE_TYPE (expected_type))
   10008         2223 :       && lvalue_p (expr))
   10009              :     {
   10010           43 :       gcc_rich_location richloc (loc);
   10011           43 :       richloc.add_fixit_insert_before ("&");
   10012           43 :       inform (&richloc, "possible fix: take the address with %qs", "&");
   10013           43 :     }
   10014              : 
   10015              :   /* Missing '*'.  */
   10016         2142 :   if (TREE_CODE (actual_type) == POINTER_TYPE
   10017         2142 :       && compatible_types_for_indirection_note_p (TREE_TYPE (actual_type),
   10018              :                                                   expected_type))
   10019              :     {
   10020           78 :       gcc_rich_location richloc (loc);
   10021           78 :       richloc.add_fixit_insert_before ("*");
   10022           78 :       inform (&richloc, "possible fix: dereference with %qs", "*");
   10023           78 :     }
   10024         2142 : }
   10025              : 
   10026              : #if CHECKING_P
   10027              : 
   10028              : namespace selftest {
   10029              : 
   10030              : /* Verify that fold_for_warn on error_mark_node is safe.  */
   10031              : 
   10032              : static void
   10033            3 : test_fold_for_warn ()
   10034              : {
   10035            3 :   ASSERT_EQ (error_mark_node, fold_for_warn (error_mark_node));
   10036            3 : }
   10037              : 
   10038              : /* Run all of the selftests within this file.  */
   10039              : 
   10040              : static void
   10041            3 : c_common_cc_tests ()
   10042              : {
   10043            0 :   test_fold_for_warn ();
   10044            0 : }
   10045              : 
   10046              : /* Run all of the tests within c-family.  */
   10047              : 
   10048              : void
   10049            3 : c_family_tests (void)
   10050              : {
   10051            3 :   c_common_cc_tests ();
   10052            3 :   c_format_cc_tests ();
   10053            3 :   c_indentation_cc_tests ();
   10054            3 :   c_pretty_print_cc_tests ();
   10055            3 :   c_spellcheck_cc_tests ();
   10056            3 :   c_opt_problem_cc_tests ();
   10057              : 
   10058              :   /* According to https://gcc.gnu.org/pipermail/gcc/2021-November/237703.html
   10059              :      this has some language-specific assumptions, so we run it here.  */
   10060            3 :   diagnostics::selftest::context_cc_tests ();
   10061            3 : }
   10062              : 
   10063              : } // namespace selftest
   10064              : 
   10065              : #endif /* #if CHECKING_P */
   10066              : 
   10067              : /* Attempt to locate a suitable location within FILE for a
   10068              :    #include directive to be inserted before.
   10069              :    LOC is the location of the relevant diagnostic.
   10070              : 
   10071              :    Attempt to return the location within FILE immediately
   10072              :    after the last #include within that file, or the start of
   10073              :    that file if it has no #include directives.
   10074              : 
   10075              :    Return UNKNOWN_LOCATION if no suitable location is found,
   10076              :    or if an error occurs.  */
   10077              : 
   10078              : static location_t
   10079          432 : try_to_locate_new_include_insertion_point (const char *file, location_t loc)
   10080              : {
   10081              :   /* Locate the last ordinary map within FILE that ended with a #include.  */
   10082          432 :   const line_map_ordinary *last_include_ord_map = NULL;
   10083              : 
   10084              :   /* ...and the next ordinary map within FILE after that one.  */
   10085          432 :   const line_map_ordinary *last_ord_map_after_include = NULL;
   10086              : 
   10087              :   /* ...and the first ordinary map within FILE.  */
   10088          432 :   const line_map_ordinary *first_ord_map_in_file = NULL;
   10089              : 
   10090              :   /*  Get ordinary map containing LOC (or its expansion).  */
   10091          432 :   const line_map_ordinary *ord_map_for_loc = NULL;
   10092          432 :   linemap_resolve_location (line_table, loc, LRK_MACRO_EXPANSION_POINT,
   10093              :                             &ord_map_for_loc);
   10094          432 :   gcc_assert (ord_map_for_loc);
   10095              : 
   10096        12651 :   for (unsigned int i = 0; i < LINEMAPS_ORDINARY_USED (line_table); i++)
   10097              :     {
   10098        12651 :       const line_map_ordinary *ord_map
   10099        12651 :         = LINEMAPS_ORDINARY_MAP_AT (line_table, i);
   10100              : 
   10101        25302 :       if (const line_map_ordinary *from
   10102        12651 :           = linemap_included_from_linemap (line_table, ord_map))
   10103              :         /* We cannot use pointer equality, because with preprocessed
   10104              :            input all filename strings are unique.  */
   10105        10251 :         if (0 == strcmp (from->to_file, file))
   10106              :           {
   10107        12651 :             last_include_ord_map = from;
   10108        12651 :             last_ord_map_after_include = NULL;
   10109              :           }
   10110              : 
   10111              :       /* Likewise, use strcmp, and reject any line-zero introductory
   10112              :          map.  */
   10113        12651 :       if (ord_map->to_line && 0 == strcmp (ord_map->to_file, file))
   10114              :         {
   10115          674 :           if (!first_ord_map_in_file)
   10116          432 :             first_ord_map_in_file = ord_map;
   10117          674 :           if (last_include_ord_map && !last_ord_map_after_include)
   10118          166 :             last_ord_map_after_include = ord_map;
   10119              :         }
   10120              : 
   10121              :       /* Stop searching when reaching the ord_map containing LOC,
   10122              :          as it makes no sense to provide fix-it hints that appear
   10123              :          after the diagnostic in question.  */
   10124        12651 :       if (ord_map == ord_map_for_loc)
   10125              :         break;
   10126              :     }
   10127              : 
   10128              :   /* Determine where to insert the #include.  */
   10129          432 :   const line_map_ordinary *ord_map_for_insertion;
   10130              : 
   10131              :   /* We want the next ordmap in the file after the last one that's a
   10132              :      #include, but failing that, the start of the file.  */
   10133          432 :   if (last_ord_map_after_include)
   10134              :     ord_map_for_insertion = last_ord_map_after_include;
   10135              :   else
   10136          268 :     ord_map_for_insertion = first_ord_map_in_file;
   10137              : 
   10138          268 :   if (!ord_map_for_insertion)
   10139              :     return UNKNOWN_LOCATION;
   10140              : 
   10141              :   /* The "start_location" is column 0, meaning "the whole line".
   10142              :      rich_location and diagnostics::changes can't cope with this, so use
   10143              :      column 1 instead.  */
   10144          432 :   location_t col_0 = ord_map_for_insertion->start_location;
   10145          432 :   return linemap_position_for_loc_and_offset (line_table, col_0, 1);
   10146              : }
   10147              : 
   10148              : /* A map from filenames to sets of headers added to them, for
   10149              :    ensuring idempotency within maybe_add_include_fixit.  */
   10150              : 
   10151              : /* The values within the map.  We need string comparison as there's
   10152              :    no guarantee that two different diagnostics that are recommending
   10153              :    adding e.g. "<stdio.h>" are using the same buffer.  */
   10154              : 
   10155              : typedef hash_set <const char *, false, nofree_string_hash> per_file_includes_t;
   10156              : 
   10157              : /* The map itself.  We don't need string comparison for the filename keys,
   10158              :    as they come from libcpp.  */
   10159              : 
   10160              : typedef hash_map <const char *, per_file_includes_t *> added_includes_t;
   10161              : static added_includes_t *added_includes;
   10162              : 
   10163              : /* Attempt to add a fix-it hint to RICHLOC, adding "#include HEADER\n"
   10164              :    in a suitable location within the file of RICHLOC's primary
   10165              :    location.
   10166              : 
   10167              :    This function is idempotent: a header will be added at most once to
   10168              :    any given file.
   10169              : 
   10170              :    If OVERRIDE_LOCATION is true, then if a fix-it is added and will be
   10171              :    printed, then RICHLOC's primary location will be replaced by that of
   10172              :    the fix-it hint (for use by "inform" notes where the location of the
   10173              :    issue has already been reported).  */
   10174              : 
   10175              : void
   10176          884 : maybe_add_include_fixit (rich_location *richloc, const char *header,
   10177              :                          bool override_location)
   10178              : {
   10179          884 :   location_t loc = richloc->get_loc ();
   10180          884 :   const char *file = LOCATION_FILE (loc);
   10181          884 :   if (!file)
   10182          452 :     return;
   10183              : 
   10184              :   /* Idempotency: don't add the same header more than once to a given file.  */
   10185          884 :   if (!added_includes)
   10186          349 :     added_includes = new added_includes_t ();
   10187          884 :   per_file_includes_t *&set = added_includes->get_or_insert (file);
   10188          884 :   if (set)
   10189          535 :     if (set->contains (header))
   10190              :       /* ...then we've already added HEADER to that file.  */
   10191              :       return;
   10192          432 :   if (!set)
   10193          349 :     set = new per_file_includes_t ();
   10194          432 :   set->add (header);
   10195              : 
   10196              :   /* Attempt to locate a suitable place for the new directive.  */
   10197          432 :   location_t include_insert_loc
   10198          432 :     = try_to_locate_new_include_insertion_point (file, loc);
   10199          432 :   if (include_insert_loc == UNKNOWN_LOCATION)
   10200              :     return;
   10201              : 
   10202          432 :   char *text = xasprintf ("#include %s\n", header);
   10203          432 :   richloc->add_fixit_insert_before (include_insert_loc, text);
   10204          432 :   free (text);
   10205              : 
   10206          432 :   if (override_location && global_dc->get_source_printing_options ().enabled)
   10207              :     {
   10208              :       /* Replace the primary location with that of the insertion point for the
   10209              :          fix-it hint.
   10210              : 
   10211              :          We use SHOW_LINES_WITHOUT_RANGE so that we don't meaningless print a
   10212              :          caret for the insertion point (or colorize it).
   10213              : 
   10214              :          Hence we print e.g.:
   10215              : 
   10216              :          ../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:74:1: note: msg 2
   10217              :           73 | # include <debug/vector>
   10218              :          +++ |+#include <vector>
   10219              :           74 | #endif
   10220              : 
   10221              :          rather than:
   10222              : 
   10223              :          ../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:74:1: note: msg 2
   10224              :           73 | # include <debug/vector>
   10225              :          +++ |+#include <vector>
   10226              :           74 | #endif
   10227              :              | ^
   10228              : 
   10229              :          avoiding the caret on the first column of line 74.  */
   10230          177 :       richloc->set_range (0, include_insert_loc, SHOW_LINES_WITHOUT_RANGE);
   10231              :     }
   10232              : }
   10233              : 
   10234              : /* Attempt to convert a braced array initializer list CTOR for array
   10235              :    TYPE into a STRING_CST for convenience and efficiency.  Return
   10236              :    the converted string on success or the original ctor on failure.
   10237              :    Also, for non-convertible CTORs which contain RAW_DATA_CST values
   10238              :    among the elts try to extend the range of RAW_DATA_CSTs.  */
   10239              : 
   10240              : static tree
   10241        57775 : braced_list_to_string (tree type, tree ctor, bool member)
   10242              : {
   10243              :   /* Ignore non-members with unknown size like arrays with unspecified
   10244              :      bound.  */
   10245        57775 :   tree typesize = TYPE_SIZE_UNIT (type);
   10246        57775 :   if (!member && !tree_fits_uhwi_p (typesize))
   10247              :     return ctor;
   10248              : 
   10249              :   /* If the target char size differs from the host char size, we'd risk
   10250              :      loosing data and getting object sizes wrong by converting to
   10251              :      host chars.  */
   10252        57750 :   if (TYPE_PRECISION (char_type_node) != CHAR_BIT)
   10253              :     return ctor;
   10254              : 
   10255              :   /* STRING_CST doesn't support wide characters.  */
   10256        57750 :   gcc_checking_assert (TYPE_PRECISION (TREE_TYPE (type)) == CHAR_BIT);
   10257              : 
   10258              :   /* If the array has an explicit bound, use it to constrain the size
   10259              :      of the string.  If it doesn't, be sure to create a string that's
   10260              :      as long as implied by the index of the last zero specified via
   10261              :      a designator, as in:
   10262              :        const char a[] = { [7] = 0 };  */
   10263        57750 :   unsigned HOST_WIDE_INT maxelts;
   10264        57750 :   if (typesize)
   10265              :     {
   10266        57671 :       maxelts = tree_to_uhwi (typesize);
   10267        57671 :       maxelts /= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type)));
   10268              :     }
   10269              :   else
   10270              :     maxelts = HOST_WIDE_INT_M1U;
   10271              : 
   10272              :   /* Avoid converting initializers for zero-length arrays (but do
   10273              :      create them for flexible array members).  */
   10274        57671 :   if (!maxelts)
   10275              :     return ctor;
   10276              : 
   10277        57600 :   unsigned HOST_WIDE_INT nelts = CONSTRUCTOR_NELTS (ctor);
   10278              : 
   10279        57600 :   auto_vec<char> str;
   10280        57600 :   str.reserve (nelts + 1);
   10281              : 
   10282        57600 :   unsigned HOST_WIDE_INT i, j = HOST_WIDE_INT_M1U;
   10283        57600 :   tree index, value;
   10284        57600 :   bool check_raw_data = false;
   10285              : 
   10286       657481 :   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), i, index, value)
   10287              :     {
   10288       599881 :       if (check_raw_data)
   10289              :         {
   10290              :           /* The preprocessor always surrounds CPP_EMBED tokens in between
   10291              :              CPP_NUMBER and CPP_COMMA tokens.  Try to undo that here now that
   10292              :              the whole initializer is parsed.  E.g. if we have
   10293              :              [0] = 'T', [1] = "his is a #embed tex", [20] = 't'
   10294              :              where the middle value is RAW_DATA_CST and in its owner this is
   10295              :              surrounded by 'T' and 't' characters, we can create from it just
   10296              :              [0] = "This is a #embed text"
   10297              :              Similarly if a RAW_DATA_CST needs to be split into two parts
   10298              :              because of designated init store but the stored value is actually
   10299              :              the same as in the RAW_DATA_OWNER's memory we can merge multiple
   10300              :              RAW_DATA_CSTs.  */
   10301         1213 :           if (TREE_CODE (value) == RAW_DATA_CST
   10302          567 :               && index
   10303          567 :               && tree_fits_uhwi_p (index))
   10304              :             {
   10305          567 :               tree owner = RAW_DATA_OWNER (value);
   10306          567 :               unsigned int start, end, k;
   10307          567 :               if (TREE_CODE (owner) == STRING_CST)
   10308              :                 {
   10309          221 :                   start
   10310          221 :                     = RAW_DATA_POINTER (value) - TREE_STRING_POINTER (owner);
   10311          221 :                   end = TREE_STRING_LENGTH (owner) - RAW_DATA_LENGTH (value);
   10312              :                 }
   10313              :               else
   10314              :                 {
   10315          346 :                   gcc_checking_assert (TREE_CODE (owner) == RAW_DATA_CST);
   10316          346 :                   start
   10317          346 :                     = RAW_DATA_POINTER (value) - RAW_DATA_POINTER (owner);
   10318          346 :                   end = RAW_DATA_LENGTH (owner) - RAW_DATA_LENGTH (value);
   10319              :                 }
   10320          567 :               end -= start;
   10321          567 :               unsigned HOST_WIDE_INT l = j == HOST_WIDE_INT_M1U ? i : j;
   10322         1019 :               for (k = 0; k < start && k < l; ++k)
   10323              :                 {
   10324          478 :                   constructor_elt *elt = CONSTRUCTOR_ELT (ctor, l - k - 1);
   10325          956 :                   if (elt->index == NULL_TREE
   10326          478 :                       || !tree_fits_uhwi_p (elt->index)
   10327          478 :                       || !tree_fits_shwi_p (elt->value)
   10328         1429 :                       || wi::to_widest (index) != (wi::to_widest (elt->index)
   10329         1424 :                                                    + (k + 1)))
   10330              :                     break;
   10331          473 :                   if (TYPE_UNSIGNED (TREE_TYPE (value)))
   10332              :                     {
   10333          393 :                       if (tree_to_shwi (elt->value)
   10334          393 :                           != *((const unsigned char *)
   10335          393 :                                RAW_DATA_POINTER (value) - k - 1))
   10336              :                         break;
   10337              :                     }
   10338           80 :                   else if (tree_to_shwi (elt->value)
   10339           80 :                            != *((const signed char *)
   10340           80 :                                 RAW_DATA_POINTER (value) - k - 1))
   10341              :                     break;
   10342              :                 }
   10343          567 :               start = k;
   10344          567 :               l = 0;
   10345         1478 :               for (k = 0; k < end && k + 1 < CONSTRUCTOR_NELTS (ctor) - i; ++k)
   10346              :                 {
   10347          462 :                   constructor_elt *elt = CONSTRUCTOR_ELT (ctor, i + k + 1);
   10348          924 :                   if (elt->index == NULL_TREE
   10349          462 :                       || !tree_fits_uhwi_p (elt->index)
   10350         1386 :                       || (wi::to_widest (elt->index)
   10351          924 :                           != (wi::to_widest (index)
   10352         1386 :                               + (RAW_DATA_LENGTH (value) + l))))
   10353              :                     break;
   10354          462 :                   if (TREE_CODE (elt->value) == RAW_DATA_CST
   10355            2 :                       && RAW_DATA_OWNER (elt->value) == RAW_DATA_OWNER (value)
   10356          462 :                       && (RAW_DATA_POINTER (elt->value)
   10357            2 :                           == RAW_DATA_POINTER (value) + l))
   10358              :                     {
   10359            0 :                       l += RAW_DATA_LENGTH (elt->value);
   10360            0 :                       end -= RAW_DATA_LENGTH (elt->value) - 1;
   10361            0 :                       continue;
   10362              :                     }
   10363          462 :                   if (!tree_fits_shwi_p (elt->value))
   10364              :                     break;
   10365          459 :                   if (TYPE_UNSIGNED (TREE_TYPE (value)))
   10366              :                     {
   10367          401 :                       if (tree_to_shwi (elt->value)
   10368          401 :                           != *((const unsigned char *)
   10369          401 :                                RAW_DATA_POINTER (value)
   10370          401 :                                + RAW_DATA_LENGTH (value) + k))
   10371              :                         break;
   10372              :                     }
   10373           58 :                   else if (tree_to_shwi (elt->value)
   10374           58 :                            != *((const signed char *)
   10375           58 :                                 RAW_DATA_POINTER (value)
   10376           58 :                                 + RAW_DATA_LENGTH (value) + k))
   10377              :                     break;
   10378          424 :                   ++l;
   10379              :                 }
   10380          567 :               end = k;
   10381          567 :               if (start != 0 || end != 0)
   10382              :                 {
   10383          474 :                   if (j == HOST_WIDE_INT_M1U)
   10384          436 :                     j = i - start;
   10385              :                   else
   10386           38 :                     j -= start;
   10387          474 :                   value = copy_node (value);
   10388          474 :                   RAW_DATA_POINTER (value) -= start;
   10389          474 :                   RAW_DATA_LENGTH (value) += start + end;
   10390          474 :                   i += end;
   10391          474 :                   if (start == 0)
   10392           22 :                     CONSTRUCTOR_ELT (ctor, j)->index = index;
   10393          474 :                   CONSTRUCTOR_ELT (ctor, j)->value = value;
   10394          474 :                   ++j;
   10395          474 :                   continue;
   10396              :                 }
   10397              :             }
   10398          739 :           if (j != HOST_WIDE_INT_M1U)
   10399              :             {
   10400          177 :               CONSTRUCTOR_ELT (ctor, j)->index = index;
   10401          177 :               CONSTRUCTOR_ELT (ctor, j)->value = value;
   10402          177 :               ++j;
   10403              :             }
   10404          739 :           continue;
   10405          739 :         }
   10406              : 
   10407       598668 :       unsigned HOST_WIDE_INT idx = i;
   10408       598668 :       if (index)
   10409              :         {
   10410       598668 :           if (!tree_fits_uhwi_p (index))
   10411              :             {
   10412           23 :               check_raw_data = true;
   10413           23 :               continue;
   10414              :             }
   10415       598645 :           idx = tree_to_uhwi (index);
   10416              :         }
   10417              : 
   10418              :       /* auto_vec is limited to UINT_MAX elements.  */
   10419       598645 :       if (idx > UINT_MAX)
   10420              :         {
   10421            0 :           check_raw_data = true;
   10422            0 :           continue;
   10423              :         }
   10424              : 
   10425              :       /* Avoid non-constant initializers.  */
   10426       598645 :       if (!tree_fits_shwi_p (value))
   10427              :         {
   10428          673 :           check_raw_data = true;
   10429          673 :           --i;
   10430          673 :           continue;
   10431              :         }
   10432              : 
   10433              :       /* Skip over embedded nuls except the last one (initializer
   10434              :          elements are in ascending order of indices).  */
   10435       597972 :       HOST_WIDE_INT val = tree_to_shwi (value);
   10436       597972 :       if (!val && i + 1 < nelts)
   10437         5970 :         continue;
   10438              : 
   10439       592002 :       if (idx < str.length ())
   10440              :         {
   10441            0 :           check_raw_data = true;
   10442            0 :           continue;
   10443              :         }
   10444              : 
   10445              :       /* Bail if the CTOR has a block of more than 256 embedded nuls
   10446              :          due to implicitly initialized elements.  */
   10447       592002 :       unsigned nchars = (idx - str.length ()) + 1;
   10448       592002 :       if (nchars > 256)
   10449              :         {
   10450            3 :           check_raw_data = true;
   10451            3 :           continue;
   10452              :         }
   10453              : 
   10454       591999 :       if (nchars > 1)
   10455              :         {
   10456         3661 :           str.reserve (idx);
   10457         3661 :           str.quick_grow_cleared (idx);
   10458              :         }
   10459              : 
   10460       591999 :       if (idx >= maxelts)
   10461              :         {
   10462            0 :           check_raw_data = true;
   10463            0 :           continue;
   10464              :         }
   10465              : 
   10466       591999 :       str.safe_insert (idx, val);
   10467              :     }
   10468              : 
   10469        57600 :   if (check_raw_data)
   10470              :     {
   10471          699 :       if (j != HOST_WIDE_INT_M1U)
   10472          436 :         CONSTRUCTOR_ELTS (ctor)->truncate (j);
   10473          699 :       return ctor;
   10474              :     }
   10475              : 
   10476              :   /* Append a nul string termination.  */
   10477       113725 :   if (maxelts != HOST_WIDE_INT_M1U && str.length () < maxelts)
   10478        29757 :     str.safe_push (0);
   10479              : 
   10480              :   /* Build a STRING_CST with the same type as the array.  */
   10481       170703 :   tree res = build_string (str.length (), str.begin ());
   10482        56901 :   TREE_TYPE (res) = type;
   10483        56901 :   return res;
   10484        57600 : }
   10485              : 
   10486              : /* Implementation of the two-argument braced_lists_to_string withe
   10487              :    the same arguments plus MEMBER which is set for struct members
   10488              :    to allow initializers for flexible member arrays.  */
   10489              : 
   10490              : static tree
   10491    190232921 : braced_lists_to_strings (tree type, tree ctor, bool member)
   10492              : {
   10493    190232921 :   if (TREE_CODE (ctor) != CONSTRUCTOR)
   10494              :     return ctor;
   10495              : 
   10496      5712385 :   tree_code code = TREE_CODE (type);
   10497              : 
   10498      5712385 :   tree ttp;
   10499      5712385 :   if (code == ARRAY_TYPE)
   10500       273536 :     ttp = TREE_TYPE (type);
   10501      5438849 :   else if (code == RECORD_TYPE)
   10502              :     {
   10503      5391068 :       ttp = TREE_TYPE (ctor);
   10504      5391068 :       if (TREE_CODE (ttp) == ARRAY_TYPE)
   10505              :         {
   10506       246684 :           type = ttp;
   10507       246684 :           ttp = TREE_TYPE (ttp);
   10508              :         }
   10509              :     }
   10510              :   else
   10511              :     return ctor;
   10512              : 
   10513      5662106 :   if ((TREE_CODE (ttp) == ARRAY_TYPE || TREE_CODE (ttp) == INTEGER_TYPE)
   10514      6021570 :       && TYPE_STRING_FLAG (ttp))
   10515        57775 :     return braced_list_to_string (type, ctor, member);
   10516              : 
   10517      5606829 :   code = TREE_CODE (ttp);
   10518      5606829 :   if (code == ARRAY_TYPE || RECORD_OR_UNION_TYPE_P (ttp))
   10519              :     {
   10520      5211185 :       bool rec = RECORD_OR_UNION_TYPE_P (ttp);
   10521              : 
   10522              :       /* Handle array of arrays or struct member initializers.  */
   10523      5211185 :       tree val;
   10524      5211185 :       unsigned HOST_WIDE_INT idx;
   10525     13439895 :       FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), idx, val)
   10526              :         {
   10527      8228710 :           val = braced_lists_to_strings (ttp, val, rec);
   10528      8228710 :           CONSTRUCTOR_ELT (ctor, idx)->value = val;
   10529              :         }
   10530              :     }
   10531              : 
   10532              :   return ctor;
   10533              : }
   10534              : 
   10535              : /* Attempt to convert a CTOR containing braced array initializer lists
   10536              :    for array TYPE into one containing STRING_CSTs, for convenience and
   10537              :    efficiency.  Recurse for arrays of arrays and member initializers.
   10538              :    Return the converted CTOR or STRING_CST on success or the original
   10539              :    CTOR otherwise.  */
   10540              : 
   10541              : tree
   10542    182004211 : braced_lists_to_strings (tree type, tree ctor)
   10543              : {
   10544    182004211 :   return braced_lists_to_strings (type, ctor, false);
   10545              : }
   10546              : 
   10547              : 
   10548              : /* Emit debug for functions before finalizing early debug.  */
   10549              : 
   10550              : void
   10551       184775 : c_common_finalize_early_debug (void)
   10552              : {
   10553              :   /* Emit early debug for reachable functions, and by consequence,
   10554              :      locally scoped symbols.  Also emit debug for extern declared
   10555              :      functions that are still reachable at this point.  */
   10556       184775 :   struct cgraph_node *cnode;
   10557      4129919 :   FOR_EACH_FUNCTION (cnode)
   10558      3610466 :     if (!cnode->alias && !cnode->thunk
   10559      7552576 :         && (cnode->has_gimple_body_p ()
   10560      1272023 :             || !DECL_IS_UNDECLARED_BUILTIN (cnode->decl)))
   10561      3390134 :       (*debug_hooks->early_global_decl) (cnode->decl);
   10562       184775 : }
   10563              : 
   10564              : /* Determine whether TYPE is an ISO C99 flexible array member type "[]".  */
   10565              : bool
   10566     10421862 : c_flexible_array_member_type_p (const_tree type)
   10567              : {
   10568     10421862 :   if (TREE_CODE (type) == ARRAY_TYPE
   10569      3596831 :       && TYPE_SIZE (type) == NULL_TREE
   10570       470514 :       && TYPE_DOMAIN (type) != NULL_TREE
   10571     10892376 :       && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE)
   10572       470514 :     return true;
   10573              : 
   10574              :   return false;
   10575              : }
   10576              : 
   10577              : /* Get the LEVEL of the strict_flex_array for the ARRAY_FIELD based on the
   10578              :    values of attribute strict_flex_array and the flag_strict_flex_arrays.  */
   10579              : unsigned int
   10580       536241 : c_strict_flex_array_level_of (tree array_field)
   10581              : {
   10582       536241 :   gcc_assert (TREE_CODE (array_field) == FIELD_DECL);
   10583       536241 :   unsigned int strict_flex_array_level = flag_strict_flex_arrays;
   10584              : 
   10585       536241 :   tree attr_strict_flex_array
   10586       536241 :     = lookup_attribute ("strict_flex_array", DECL_ATTRIBUTES (array_field));
   10587              :   /* If there is a strict_flex_array attribute attached to the field,
   10588              :      override the flag_strict_flex_arrays.  */
   10589       536241 :   if (attr_strict_flex_array)
   10590              :     {
   10591              :       /* Get the value of the level first from the attribute.  */
   10592            6 :       unsigned HOST_WIDE_INT attr_strict_flex_array_level = 0;
   10593            6 :       gcc_assert (TREE_VALUE (attr_strict_flex_array) != NULL_TREE);
   10594            6 :       attr_strict_flex_array = TREE_VALUE (attr_strict_flex_array);
   10595            6 :       gcc_assert (TREE_VALUE (attr_strict_flex_array) != NULL_TREE);
   10596            6 :       attr_strict_flex_array = TREE_VALUE (attr_strict_flex_array);
   10597            6 :       gcc_assert (tree_fits_uhwi_p (attr_strict_flex_array));
   10598            6 :       attr_strict_flex_array_level = tree_to_uhwi (attr_strict_flex_array);
   10599              : 
   10600              :       /* The attribute has higher priority than flag_struct_flex_array.  */
   10601            6 :       strict_flex_array_level = attr_strict_flex_array_level;
   10602              :     }
   10603       536241 :   return strict_flex_array_level;
   10604              : }
   10605              : 
   10606              : /* Map from identifiers to booleans.  Value is true for features, and
   10607              :    false for extensions.  Used to implement __has_{feature,extension}.  */
   10608              : 
   10609              : using feature_map_t = hash_map <tree, bool>;
   10610              : static feature_map_t *feature_map;
   10611              : 
   10612              : /* Register a feature for __has_{feature,extension}.  FEATURE_P is true
   10613              :    if the feature identified by NAME is a feature (as opposed to an
   10614              :    extension).  */
   10615              : 
   10616              : void
   10617      1441800 : c_common_register_feature (const char *name, bool feature_p)
   10618              : {
   10619      1441800 :   bool dup = feature_map->put (get_identifier (name), feature_p);
   10620      1441800 :   gcc_checking_assert (!dup);
   10621      1441800 : }
   10622              : 
   10623              : /* Lazily initialize hash table for __has_{feature,extension},
   10624              :    dispatching to the appropriate front end to register language-specific
   10625              :    features.  */
   10626              : 
   10627              : static void
   10628        47190 : init_has_feature ()
   10629              : {
   10630        47190 :   gcc_checking_assert (!feature_map);
   10631        47190 :   feature_map = new feature_map_t;
   10632              : 
   10633       566280 :   for (unsigned i = 0; i < ARRAY_SIZE (has_feature_table); i++)
   10634              :     {
   10635       519090 :       const hf_feature_info *info = has_feature_table + i;
   10636              : 
   10637       519090 :       if ((info->flags & HF_FLAG_SANITIZE) && !(flag_sanitize & info->mask))
   10638       235026 :         continue;
   10639              : 
   10640       284064 :       const bool feature_p = !(info->flags & HF_FLAG_EXT);
   10641       284064 :       c_common_register_feature (info->ident, feature_p);
   10642              :     }
   10643              : 
   10644              :   /* Register language-specific features.  */
   10645        47190 :   c_family_register_lang_features ();
   10646        47190 : }
   10647              : 
   10648              : /* If STRICT_P is true, evaluate __has_feature (IDENT).
   10649              :    Otherwise, evaluate __has_extension (IDENT).  */
   10650              : 
   10651              : bool
   10652       127896 : has_feature_p (const char *ident, bool strict_p)
   10653              : {
   10654       127896 :   if (!feature_map)
   10655        47190 :     init_has_feature ();
   10656              : 
   10657       127896 :   tree name = canonicalize_attr_name (get_identifier (ident));
   10658       127896 :   bool *feat_p = feature_map->get (name);
   10659       127896 :   if (!feat_p)
   10660              :     return false;
   10661              : 
   10662        73297 :   return !strict_p || *feat_p;
   10663              : }
   10664              : 
   10665              : /* This is the slow path of c-common.h's c_hardbool_type_attr.  */
   10666              : 
   10667              : tree
   10668        70016 : c_hardbool_type_attr_1 (tree type, tree *false_value, tree *true_value)
   10669              : {
   10670        70016 :   tree attr = lookup_attribute ("hardbool", TYPE_ATTRIBUTES (type));
   10671        70016 :   if (!attr)
   10672              :     return attr;
   10673              : 
   10674        35391 :   if (false_value)
   10675        18461 :     *false_value = TREE_VALUE (TYPE_VALUES (type));
   10676              : 
   10677        35391 :   if (true_value)
   10678        18825 :     *true_value = TREE_VALUE (TREE_CHAIN (TYPE_VALUES (type)));
   10679              : 
   10680              :   return attr;
   10681              : }
   10682              : 
   10683              : #include "gt-c-family-c-common.h"
        

Generated by: LCOV version 2.4-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.