LCOV - code coverage report
Current view: top level - gcc/c-family - c-common.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 91.8 % 4080 3744
Test Date: 2024-03-23 14:05:01 Functions: 96.9 % 160 155
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

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

Generated by: LCOV version 2.0-1

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.