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