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 % 4371 4014
Test Date: 2025-07-12 13:27:34 Functions: 96.9 % 163 158
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-2025 Free Software Foundation, Inc.
       3                 :             : 
       4                 :             : This file is part of GCC.
       5                 :             : 
       6                 :             : GCC is free software; you can redistribute it and/or modify it under
       7                 :             : the terms of the GNU General Public License as published by the Free
       8                 :             : Software Foundation; either version 3, or (at your option) any later
       9                 :             : version.
      10                 :             : 
      11                 :             : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      12                 :             : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13                 :             : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      14                 :             : for more details.
      15                 :             : 
      16                 :             : You should have received a copy of the GNU General Public License
      17                 :             : along with GCC; see the file COPYING3.  If not see
      18                 :             : <http://www.gnu.org/licenses/>.  */
      19                 :             : 
      20                 :             : #define GCC_C_COMMON_C
      21                 :             : 
      22                 :             : #include "config.h"
      23                 :             : #include "system.h"
      24                 :             : #include "coretypes.h"
      25                 :             : #include "target.h"
      26                 :             : #include "function.h"
      27                 :             : #include "tree.h"
      28                 :             : #include "memmodel.h"
      29                 :             : #include "c-common.h"
      30                 :             : #include "gimple-expr.h"
      31                 :             : #include "tm_p.h"
      32                 :             : #include "stringpool.h"
      33                 :             : #include "cgraph.h"
      34                 :             : #include "diagnostic.h"
      35                 :             : #include "intl.h"
      36                 :             : #include "stor-layout.h"
      37                 :             : #include "calls.h"
      38                 :             : #include "attribs.h"
      39                 :             : #include "varasm.h"
      40                 :             : #include "trans-mem.h"
      41                 :             : #include "c-objc.h"
      42                 :             : #include "common/common-target.h"
      43                 :             : #include "langhooks.h"
      44                 :             : #include "tree-inline.h"
      45                 :             : #include "toplev.h"
      46                 :             : #include "tree-iterator.h"
      47                 :             : #include "opts.h"
      48                 :             : #include "gimplify.h"
      49                 :             : #include "substring-locations.h"
      50                 :             : #include "spellcheck.h"
      51                 :             : #include "c-spellcheck.h"
      52                 :             : #include "selftest.h"
      53                 :             : #include "debug.h"
      54                 :             : #include "tree-vector-builder.h"
      55                 :             : #include "vec-perm-indices.h"
      56                 :             : #include "tree-pretty-print-markup.h"
      57                 :             : #include "gcc-rich-location.h"
      58                 :             : #include "gcc-urlifier.h"
      59                 :             : 
      60                 :             : cpp_reader *parse_in;           /* Declared in c-pragma.h.  */
      61                 :             : 
      62                 :             : /* Mode used to build pointers (VOIDmode means ptr_mode).  */
      63                 :             : 
      64                 :             : machine_mode c_default_pointer_mode = VOIDmode;
      65                 :             : 
      66                 :             : /* The following symbols are subsumed in the c_global_trees array, and
      67                 :             :    listed here individually for documentation purposes.
      68                 :             : 
      69                 :             :    INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
      70                 :             : 
      71                 :             :         tree short_integer_type_node;
      72                 :             :         tree long_integer_type_node;
      73                 :             :         tree long_long_integer_type_node;
      74                 :             : 
      75                 :             :         tree short_unsigned_type_node;
      76                 :             :         tree long_unsigned_type_node;
      77                 :             :         tree long_long_unsigned_type_node;
      78                 :             : 
      79                 :             :         tree truthvalue_type_node;
      80                 :             :         tree truthvalue_false_node;
      81                 :             :         tree truthvalue_true_node;
      82                 :             : 
      83                 :             :         tree ptrdiff_type_node;
      84                 :             : 
      85                 :             :         tree unsigned_char_type_node;
      86                 :             :         tree signed_char_type_node;
      87                 :             :         tree wchar_type_node;
      88                 :             : 
      89                 :             :         tree char8_type_node;
      90                 :             :         tree char16_type_node;
      91                 :             :         tree char32_type_node;
      92                 :             : 
      93                 :             :         tree float_type_node;
      94                 :             :         tree double_type_node;
      95                 :             :         tree long_double_type_node;
      96                 :             : 
      97                 :             :         tree complex_integer_type_node;
      98                 :             :         tree complex_float_type_node;
      99                 :             :         tree complex_double_type_node;
     100                 :             :         tree complex_long_double_type_node;
     101                 :             : 
     102                 :             :         tree dfloat32_type_node;
     103                 :             :         tree dfloat64_type_node;
     104                 :             :         tree dfloat128_type_node;
     105                 :             :         tree dfloat64x_type_node; 
     106                 :             : 
     107                 :             :         tree intQI_type_node;
     108                 :             :         tree intHI_type_node;
     109                 :             :         tree intSI_type_node;
     110                 :             :         tree intDI_type_node;
     111                 :             :         tree intTI_type_node;
     112                 :             : 
     113                 :             :         tree unsigned_intQI_type_node;
     114                 :             :         tree unsigned_intHI_type_node;
     115                 :             :         tree unsigned_intSI_type_node;
     116                 :             :         tree unsigned_intDI_type_node;
     117                 :             :         tree unsigned_intTI_type_node;
     118                 :             : 
     119                 :             :         tree widest_integer_literal_type_node;
     120                 :             :         tree widest_unsigned_literal_type_node;
     121                 :             : 
     122                 :             :    Nodes for types `void *' and `const void *'.
     123                 :             : 
     124                 :             :         tree ptr_type_node, const_ptr_type_node;
     125                 :             : 
     126                 :             :    Nodes for types `char *' and `const char *'.
     127                 :             : 
     128                 :             :         tree string_type_node, const_string_type_node;
     129                 :             : 
     130                 :             :    Type `char[SOMENUMBER]'.
     131                 :             :    Used when an array of char is needed and the size is irrelevant.
     132                 :             : 
     133                 :             :         tree char_array_type_node;
     134                 :             : 
     135                 :             :    Type `wchar_t[SOMENUMBER]' or something like it.
     136                 :             :    Used when a wide string literal is created.
     137                 :             : 
     138                 :             :         tree wchar_array_type_node;
     139                 :             : 
     140                 :             :    Type `char8_t[SOMENUMBER]' or something like it.
     141                 :             :    Used when a UTF-8 string literal is created.
     142                 :             : 
     143                 :             :         tree char8_array_type_node;
     144                 :             : 
     145                 :             :    Type `char16_t[SOMENUMBER]' or something like it.
     146                 :             :    Used when a UTF-16 string literal is created.
     147                 :             : 
     148                 :             :         tree char16_array_type_node;
     149                 :             : 
     150                 :             :    Type `char32_t[SOMENUMBER]' or something like it.
     151                 :             :    Used when a UTF-32 string literal is created.
     152                 :             : 
     153                 :             :         tree char32_array_type_node;
     154                 :             : 
     155                 :             :    Type `int ()' -- used for implicit declaration of functions.
     156                 :             : 
     157                 :             :         tree default_function_type;
     158                 :             : 
     159                 :             :    A VOID_TYPE node, packaged in a TREE_LIST.
     160                 :             : 
     161                 :             :         tree void_list_node;
     162                 :             : 
     163                 :             :   The lazily created VAR_DECLs for __FUNCTION__, __PRETTY_FUNCTION__,
     164                 :             :   and __func__. (C doesn't generate __FUNCTION__ and__PRETTY_FUNCTION__
     165                 :             :   VAR_DECLS, but C++ does.)
     166                 :             : 
     167                 :             :         tree function_name_decl_node;
     168                 :             :         tree pretty_function_name_decl_node;
     169                 :             :         tree c99_function_name_decl_node;
     170                 :             : 
     171                 :             :   Stack of nested function name VAR_DECLs.
     172                 :             : 
     173                 :             :         tree saved_function_name_decls;
     174                 :             : 
     175                 :             : */
     176                 :             : 
     177                 :             : tree c_global_trees[CTI_MAX];
     178                 :             : 
     179                 :             : /* Switches common to the C front ends.  */
     180                 :             : 
     181                 :             : /* Nonzero means don't output line number information.  */
     182                 :             : 
     183                 :             : char flag_no_line_commands;
     184                 :             : 
     185                 :             : /* Nonzero causes -E output not to be done, but directives such as
     186                 :             :    #define that have side effects are still obeyed.  */
     187                 :             : 
     188                 :             : char flag_no_output;
     189                 :             : 
     190                 :             : /* Nonzero means dump macros in some fashion.  */
     191                 :             : 
     192                 :             : char flag_dump_macros;
     193                 :             : 
     194                 :             : /* Nonzero means pass #include lines through to the output.  */
     195                 :             : 
     196                 :             : char flag_dump_includes;
     197                 :             : 
     198                 :             : /* Nonzero means process PCH files while preprocessing.  */
     199                 :             : 
     200                 :             : bool flag_pch_preprocess;
     201                 :             : 
     202                 :             : /* The file name to which we should write a precompiled header, or
     203                 :             :    NULL if no header will be written in this compile.  */
     204                 :             : 
     205                 :             : const char *pch_file;
     206                 :             : 
     207                 :             : /* Nonzero if an ISO standard was selected.  It rejects macros in the
     208                 :             :    user's namespace.  */
     209                 :             : int flag_iso;
     210                 :             : 
     211                 :             : /* C/ObjC language option variables.  */
     212                 :             : 
     213                 :             : 
     214                 :             : /* Nonzero means allow type mismatches in conditional expressions;
     215                 :             :    just make their values `void'.  */
     216                 :             : 
     217                 :             : int flag_cond_mismatch;
     218                 :             : 
     219                 :             : /* Nonzero means enable C89 Amendment 1 features.  */
     220                 :             : 
     221                 :             : int flag_isoc94;
     222                 :             : 
     223                 :             : /* Nonzero means use the ISO C99 (or later) dialect of C.  */
     224                 :             : 
     225                 :             : int flag_isoc99;
     226                 :             : 
     227                 :             : /* Nonzero means use the ISO C11 (or later) dialect of C.  */
     228                 :             : 
     229                 :             : int flag_isoc11;
     230                 :             : 
     231                 :             : /* Nonzero means use the ISO C23 (or later) dialect of C.  */
     232                 :             : 
     233                 :             : int flag_isoc23;
     234                 :             : 
     235                 :             : /* Nonzero means use the ISO C2Y (or later) dialect of C.  */
     236                 :             : 
     237                 :             : int flag_isoc2y;
     238                 :             : 
     239                 :             : /* Nonzero means that we have builtin functions, and main is an int.  */
     240                 :             : 
     241                 :             : int flag_hosted = 1;
     242                 :             : 
     243                 :             : 
     244                 :             : /* ObjC language option variables.  */
     245                 :             : 
     246                 :             : 
     247                 :             : /* Tells the compiler that this is a special run.  Do not perform any
     248                 :             :    compiling, instead we are to test some platform dependent features
     249                 :             :    and output a C header file with appropriate definitions.  */
     250                 :             : 
     251                 :             : int print_struct_values;
     252                 :             : 
     253                 :             : /* Tells the compiler what is the constant string class for ObjC.  */
     254                 :             : 
     255                 :             : const char *constant_string_class_name;
     256                 :             : 
     257                 :             : 
     258                 :             : /* C++ language option variables.  */
     259                 :             : 
     260                 :             : /* The reference version of the ABI for -Wabi.  */
     261                 :             : 
     262                 :             : int warn_abi_version = -1;
     263                 :             : 
     264                 :             : /* The C++ dialect being used.  Default set in c_common_post_options.  */
     265                 :             : 
     266                 :             : enum cxx_dialect cxx_dialect = cxx_unset;
     267                 :             : 
     268                 :             : /* Maximum template instantiation depth.  This limit exists to limit the
     269                 :             :    time it takes to notice excessively recursive template instantiations.
     270                 :             : 
     271                 :             :    The default is lower than the 1024 recommended by the C++0x standard
     272                 :             :    because G++ runs out of stack before 1024 with highly recursive template
     273                 :             :    argument deduction substitution (g++.dg/cpp0x/enum11.C).  */
     274                 :             : 
     275                 :             : int max_tinst_depth = 900;
     276                 :             : 
     277                 :             : /* The elements of `ridpointers' are identifier nodes for the reserved
     278                 :             :    type names and storage classes.  It is indexed by a RID_... value.  */
     279                 :             : tree *ridpointers;
     280                 :             : 
     281                 :             : tree (*make_fname_decl) (location_t, tree, int);
     282                 :             : 
     283                 :             : /* Nonzero means don't warn about problems that occur when the code is
     284                 :             :    executed.  */
     285                 :             : int c_inhibit_evaluation_warnings;
     286                 :             : 
     287                 :             : /* Whether we are building a boolean conversion inside
     288                 :             :    convert_for_assignment, or some other late binary operation.  If
     289                 :             :    build_binary_op is called for C (from code shared by C and C++) in
     290                 :             :    this case, then the operands have already been folded and the
     291                 :             :    result will not be folded again, so C_MAYBE_CONST_EXPR should not
     292                 :             :    be generated.  */
     293                 :             : bool in_late_binary_op;
     294                 :             : 
     295                 :             : /* Depending on which phase of processing we are in, we may need
     296                 :             :    to prefer input_location to libcpp's locations.  (Specifically,
     297                 :             :    after the C++ lexer is done lexing tokens, but prior to calling
     298                 :             :    cpp_finish (), we need to do so.  */
     299                 :             : bool override_libcpp_locations;
     300                 :             : 
     301                 :             : /* Information about how a function name is generated.  */
     302                 :             : struct fname_var_t
     303                 :             : {
     304                 :             :   tree *const decl;     /* pointer to the VAR_DECL.  */
     305                 :             :   const unsigned rid;   /* RID number for the identifier.  */
     306                 :             :   const int pretty;     /* How pretty is it? */
     307                 :             : };
     308                 :             : 
     309                 :             : /* The three ways of getting then name of the current function.  */
     310                 :             : 
     311                 :             : const struct fname_var_t fname_vars[] =
     312                 :             : {
     313                 :             :   /* C99 compliant __func__, must be first.  */
     314                 :             :   {&c99_function_name_decl_node, RID_C99_FUNCTION_NAME, 0},
     315                 :             :   /* GCC __FUNCTION__ compliant.  */
     316                 :             :   {&function_name_decl_node, RID_FUNCTION_NAME, 0},
     317                 :             :   /* GCC __PRETTY_FUNCTION__ compliant.  */
     318                 :             :   {&pretty_function_name_decl_node, RID_PRETTY_FUNCTION_NAME, 1},
     319                 :             :   {NULL, 0, 0},
     320                 :             : };
     321                 :             : 
     322                 :             : /* Flags to restrict availability of generic features that
     323                 :             :    are known to __has_{feature,extension}.  */
     324                 :             : 
     325                 :             : enum
     326                 :             : {
     327                 :             :   HF_FLAG_NONE = 0,
     328                 :             :   HF_FLAG_EXT = 1,      /* Available only as an extension.  */
     329                 :             :   HF_FLAG_SANITIZE = 2, /* Availability depends on sanitizer flags.  */
     330                 :             : };
     331                 :             : 
     332                 :             : /* Info for generic features which can be queried through
     333                 :             :    __has_{feature,extension}.  */
     334                 :             : 
     335                 :             : struct hf_feature_info
     336                 :             : {
     337                 :             :   const char *ident;
     338                 :             :   unsigned flags;
     339                 :             :   unsigned mask;
     340                 :             : };
     341                 :             : 
     342                 :             : /* Table of generic features which can be queried through
     343                 :             :    __has_{feature,extension}.  */
     344                 :             : 
     345                 :             : static constexpr hf_feature_info has_feature_table[] =
     346                 :             : {
     347                 :             :   { "address_sanitizer",          HF_FLAG_SANITIZE, SANITIZE_ADDRESS },
     348                 :             :   { "thread_sanitizer",                   HF_FLAG_SANITIZE, SANITIZE_THREAD },
     349                 :             :   { "leak_sanitizer",             HF_FLAG_SANITIZE, SANITIZE_LEAK },
     350                 :             :   { "hwaddress_sanitizer",        HF_FLAG_SANITIZE, SANITIZE_HWADDRESS },
     351                 :             :   { "undefined_behavior_sanitizer", HF_FLAG_SANITIZE, SANITIZE_UNDEFINED },
     352                 :             :   { "attribute_deprecated_with_message",  HF_FLAG_NONE, 0 },
     353                 :             :   { "attribute_unavailable_with_message", HF_FLAG_NONE, 0 },
     354                 :             :   { "enumerator_attributes",            HF_FLAG_NONE, 0 },
     355                 :             :   { "tls",                              HF_FLAG_NONE, 0 },
     356                 :             :   { "gnu_asm_goto_with_outputs",        HF_FLAG_EXT, 0 },
     357                 :             :   { "gnu_asm_goto_with_outputs_full",   HF_FLAG_EXT, 0 }
     358                 :             : };
     359                 :             : 
     360                 :             : /* Global visibility options.  */
     361                 :             : struct visibility_flags visibility_options;
     362                 :             : 
     363                 :             : static tree check_case_value (location_t, tree);
     364                 :             : 
     365                 :             : 
     366                 :             : static void check_nonnull_arg (void *, tree, unsigned HOST_WIDE_INT);
     367                 :             : static bool nonnull_check_p (tree, unsigned HOST_WIDE_INT);
     368                 :             : 
     369                 :             : /* Reserved words.  The third field is a mask: keywords are disabled
     370                 :             :    if they match the mask.
     371                 :             : 
     372                 :             :    Masks for languages:
     373                 :             :    C --std=c89: D_C99 | D_C23 | D_CXXONLY | D_OBJC | D_CXX_OBJC
     374                 :             :    C --std=c99: D_C23 | D_CXXONLY | D_OBJC
     375                 :             :    C --std=c17: D_C23 | D_CXXONLY | D_OBJC
     376                 :             :    C --std=c23: D_CXXONLY | D_OBJC
     377                 :             :    ObjC is like C except that D_OBJC and D_CXX_OBJC are not set
     378                 :             :    C++ --std=c++98: D_CONLY | D_CXX11 | D_CXX20 | D_OBJC
     379                 :             :    C++ --std=c++11: D_CONLY | D_CXX20 | D_OBJC
     380                 :             :    C++ --std=c++20: D_CONLY | D_OBJC
     381                 :             :    ObjC++ is like C++ except that D_OBJC is not set
     382                 :             : 
     383                 :             :    If -fno-asm is used, D_ASM is added to the mask.  If
     384                 :             :    -fno-gnu-keywords is used, D_EXT is added.  If -fno-asm and C in
     385                 :             :    C89 mode, D_EXT89 is added for both -fno-asm and -fno-gnu-keywords.
     386                 :             :    In C with -Wc++-compat, we warn if D_CXXWARN is set.
     387                 :             : 
     388                 :             :    Note the complication of the D_CXX_OBJC keywords.  These are
     389                 :             :    reserved words such as 'class'.  In C++, 'class' is a reserved
     390                 :             :    word.  In Objective-C++ it is too.  In Objective-C, it is a
     391                 :             :    reserved word too, but only if it follows an '@' sign.
     392                 :             : */
     393                 :             : const struct c_common_resword c_common_reswords[] =
     394                 :             : {
     395                 :             :   { "_Alignas",               RID_ALIGNAS,   D_CONLY },
     396                 :             :   { "_Alignof",               RID_ALIGNOF,   D_CONLY },
     397                 :             :   { "_Countof",               RID_COUNTOF,   D_CONLY },
     398                 :             :   { "_Atomic",                RID_ATOMIC,    D_CONLY },
     399                 :             :   { "_BitInt",                RID_BITINT,    D_CONLY },
     400                 :             :   { "_Bool",          RID_BOOL,      D_CONLY },
     401                 :             :   { "_Complex",               RID_COMPLEX,    0 },
     402                 :             :   { "_Imaginary",     RID_IMAGINARY, D_CONLY },
     403                 :             :   { "_Float16",         RID_FLOAT16,    0 },
     404                 :             :   { "_Float32",         RID_FLOAT32,    0 },
     405                 :             :   { "_Float64",         RID_FLOAT64,    0 },
     406                 :             :   { "_Float128",        RID_FLOAT128,   0 },
     407                 :             :   { "_Float32x",        RID_FLOAT32X,   0 },
     408                 :             :   { "_Float64x",        RID_FLOAT64X,   0 },
     409                 :             :   { "_Float128x",       RID_FLOAT128X,  0 },
     410                 :             :   { "_Decimal32",       RID_DFLOAT32,  D_CONLY },
     411                 :             :   { "_Decimal64",       RID_DFLOAT64,  D_CONLY },
     412                 :             :   { "_Decimal128",      RID_DFLOAT128, D_CONLY },
     413                 :             :   { "_Decimal64x",      RID_DFLOAT64X, D_CONLY },
     414                 :             :   { "_Fract",           RID_FRACT,     D_CONLY | D_EXT },
     415                 :             :   { "_Accum",           RID_ACCUM,     D_CONLY | D_EXT },
     416                 :             :   { "_Sat",             RID_SAT,       D_CONLY | D_EXT },
     417                 :             :   { "_Static_assert",   RID_STATIC_ASSERT, D_CONLY },
     418                 :             :   { "_Noreturn",        RID_NORETURN,  D_CONLY },
     419                 :             :   { "_Generic",         RID_GENERIC,   D_CONLY },
     420                 :             :   { "_Thread_local",    RID_THREAD,    D_CONLY },
     421                 :             :   { "__FUNCTION__",   RID_FUNCTION_NAME, 0 },
     422                 :             :   { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
     423                 :             :   { "__alignof",      RID_ALIGNOF,    0 },
     424                 :             :   { "__alignof__",    RID_ALIGNOF,    0 },
     425                 :             :   { "__asm",          RID_ASM,        0 },
     426                 :             :   { "__asm__",                RID_ASM,        0 },
     427                 :             :   { "__attribute",    RID_ATTRIBUTE,  0 },
     428                 :             :   { "__attribute__",  RID_ATTRIBUTE,  0 },
     429                 :             :   { "__auto_type",    RID_AUTO_TYPE,  D_CONLY },
     430                 :             :   { "__builtin_addressof", RID_ADDRESSOF, D_CXXONLY },
     431                 :             :   { "__builtin_assoc_barrier", RID_BUILTIN_ASSOC_BARRIER, 0 },
     432                 :             :   { "__builtin_bit_cast", RID_BUILTIN_BIT_CAST, D_CXXONLY },
     433                 :             :   { "__builtin_call_with_static_chain",
     434                 :             :     RID_BUILTIN_CALL_WITH_STATIC_CHAIN, D_CONLY },
     435                 :             :   { "__builtin_choose_expr", RID_CHOOSE_EXPR, D_CONLY },
     436                 :             :   { "__builtin_complex", RID_BUILTIN_COMPLEX, D_CONLY },
     437                 :             :   { "__builtin_convertvector", RID_BUILTIN_CONVERTVECTOR, 0 },
     438                 :             :   { "__builtin_counted_by_ref", RID_BUILTIN_COUNTED_BY_REF, D_CONLY },
     439                 :             :   { "__builtin_has_attribute", RID_BUILTIN_HAS_ATTRIBUTE, 0 },
     440                 :             :   { "__builtin_launder", RID_BUILTIN_LAUNDER, D_CXXONLY },
     441                 :             :   { "__builtin_operator_new", RID_BUILTIN_OPERATOR_NEW, D_CXXONLY },
     442                 :             :   { "__builtin_operator_delete", RID_BUILTIN_OPERATOR_DELETE, D_CXXONLY },
     443                 :             :   { "__builtin_shuffle", RID_BUILTIN_SHUFFLE, 0 },
     444                 :             :   { "__builtin_shufflevector", RID_BUILTIN_SHUFFLEVECTOR, 0 },
     445                 :             :   { "__builtin_stdc_bit_ceil", RID_BUILTIN_STDC, D_CONLY },
     446                 :             :   { "__builtin_stdc_bit_floor", RID_BUILTIN_STDC, D_CONLY },
     447                 :             :   { "__builtin_stdc_bit_width", RID_BUILTIN_STDC, D_CONLY },
     448                 :             :   { "__builtin_stdc_count_ones", RID_BUILTIN_STDC, D_CONLY },
     449                 :             :   { "__builtin_stdc_count_zeros", RID_BUILTIN_STDC, D_CONLY },
     450                 :             :   { "__builtin_stdc_first_leading_one", RID_BUILTIN_STDC, D_CONLY },
     451                 :             :   { "__builtin_stdc_first_leading_zero", RID_BUILTIN_STDC, D_CONLY },
     452                 :             :   { "__builtin_stdc_first_trailing_one", RID_BUILTIN_STDC, D_CONLY },
     453                 :             :   { "__builtin_stdc_first_trailing_zero", RID_BUILTIN_STDC, D_CONLY },
     454                 :             :   { "__builtin_stdc_has_single_bit", RID_BUILTIN_STDC, D_CONLY },
     455                 :             :   { "__builtin_stdc_leading_ones", RID_BUILTIN_STDC, D_CONLY },
     456                 :             :   { "__builtin_stdc_leading_zeros", RID_BUILTIN_STDC, D_CONLY },
     457                 :             :   { "__builtin_stdc_rotate_left", RID_BUILTIN_STDC, D_CONLY },
     458                 :             :   { "__builtin_stdc_rotate_right", RID_BUILTIN_STDC, D_CONLY },
     459                 :             :   { "__builtin_stdc_trailing_ones", RID_BUILTIN_STDC, D_CONLY },
     460                 :             :   { "__builtin_stdc_trailing_zeros", RID_BUILTIN_STDC, D_CONLY },
     461                 :             :   { "__builtin_tgmath", RID_BUILTIN_TGMATH, D_CONLY },
     462                 :             :   { "__builtin_offsetof", RID_OFFSETOF, 0 },
     463                 :             :   { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, D_CONLY },
     464                 :             :   { "__builtin_c23_va_start", RID_C23_VA_START,       D_C23 },
     465                 :             :   { "__builtin_va_arg",       RID_VA_ARG,     0 },
     466                 :             :   { "__complex",      RID_COMPLEX,    0 },
     467                 :             :   { "__complex__",    RID_COMPLEX,    0 },
     468                 :             :   { "__const",                RID_CONST,      0 },
     469                 :             :   { "__const__",      RID_CONST,      0 },
     470                 :             :   { "__constinit",    RID_CONSTINIT,  D_CXXONLY },
     471                 :             :   { "__decltype",       RID_DECLTYPE,   D_CXXONLY },
     472                 :             :   { "__extension__",  RID_EXTENSION,  0 },
     473                 :             :   { "__func__",               RID_C99_FUNCTION_NAME, 0 },
     474                 :             :   { "__imag",         RID_IMAGPART,   0 },
     475                 :             :   { "__imag__",               RID_IMAGPART,   0 },
     476                 :             :   { "__inline",               RID_INLINE,     0 },
     477                 :             :   { "__inline__",     RID_INLINE,     0 },
     478                 :             :   { "__label__",      RID_LABEL,      0 },
     479                 :             :   { "__null",         RID_NULL,       0 },
     480                 :             :   { "__real",         RID_REALPART,   0 },
     481                 :             :   { "__real__",               RID_REALPART,   0 },
     482                 :             :   { "__restrict",     RID_RESTRICT,   0 },
     483                 :             :   { "__restrict__",   RID_RESTRICT,   0 },
     484                 :             :   { "__signed",               RID_SIGNED,     0 },
     485                 :             :   { "__signed__",     RID_SIGNED,     0 },
     486                 :             :   { "__thread",               RID_THREAD,     0 },
     487                 :             :   { "__transaction_atomic", RID_TRANSACTION_ATOMIC, 0 },
     488                 :             :   { "__transaction_relaxed", RID_TRANSACTION_RELAXED, 0 },
     489                 :             :   { "__transaction_cancel", RID_TRANSACTION_CANCEL, 0 },
     490                 :             :   { "__typeof",               RID_TYPEOF,     0 },
     491                 :             :   { "__typeof__",     RID_TYPEOF,     0 },
     492                 :             :   { "__typeof_unqual",        RID_TYPEOF_UNQUAL, D_CONLY },
     493                 :             :   { "__typeof_unqual__", RID_TYPEOF_UNQUAL, D_CONLY },
     494                 :             :   { "__volatile",     RID_VOLATILE,   0 },
     495                 :             :   { "__volatile__",   RID_VOLATILE,   0 },
     496                 :             :   { "__GIMPLE",               RID_GIMPLE,     D_CONLY },
     497                 :             :   { "__PHI",          RID_PHI,        D_CONLY },
     498                 :             :   { "__RTL",          RID_RTL,        D_CONLY },
     499                 :             :   { "alignas",                RID_ALIGNAS,    D_C23 | D_CXX11 | D_CXXWARN },
     500                 :             :   { "alignof",                RID_ALIGNOF,    D_C23 | D_CXX11 | D_CXXWARN },
     501                 :             :   { "asm",            RID_ASM,        D_ASM },
     502                 :             :   { "auto",           RID_AUTO,       0 },
     503                 :             :   { "bool",           RID_BOOL,       D_C23 | D_CXXWARN },
     504                 :             :   { "break",          RID_BREAK,      0 },
     505                 :             :   { "case",           RID_CASE,       0 },
     506                 :             :   { "catch",          RID_CATCH,      D_CXX_OBJC | D_CXXWARN },
     507                 :             :   { "char",           RID_CHAR,       0 },
     508                 :             :   { "char8_t",                RID_CHAR8,      D_CXX_CHAR8_T_FLAGS | D_CXXWARN },
     509                 :             :   { "char16_t",               RID_CHAR16,     D_CXXONLY | D_CXX11 | D_CXXWARN },
     510                 :             :   { "char32_t",               RID_CHAR32,     D_CXXONLY | D_CXX11 | D_CXXWARN },
     511                 :             :   { "class",          RID_CLASS,      D_CXX_OBJC | D_CXXWARN },
     512                 :             :   { "const",          RID_CONST,      0 },
     513                 :             :   { "consteval",      RID_CONSTEVAL,  D_CXXONLY | D_CXX20 | D_CXXWARN },
     514                 :             :   { "constexpr",      RID_CONSTEXPR,  D_C23 | D_CXX11 | D_CXXWARN },
     515                 :             :   { "constinit",      RID_CONSTINIT,  D_CXXONLY | D_CXX20 | D_CXXWARN },
     516                 :             :   { "const_cast",     RID_CONSTCAST,  D_CXXONLY | D_CXXWARN },
     517                 :             :   { "continue",               RID_CONTINUE,   0 },
     518                 :             :   { "decltype",         RID_DECLTYPE,   D_CXXONLY | D_CXX11 | D_CXXWARN },
     519                 :             :   { "default",                RID_DEFAULT,    0 },
     520                 :             :   { "delete",         RID_DELETE,     D_CXXONLY | D_CXXWARN },
     521                 :             :   { "do",             RID_DO,         0 },
     522                 :             :   { "double",         RID_DOUBLE,     0 },
     523                 :             :   { "dynamic_cast",   RID_DYNCAST,    D_CXXONLY | D_CXXWARN },
     524                 :             :   { "else",           RID_ELSE,       0 },
     525                 :             :   { "enum",           RID_ENUM,       0 },
     526                 :             :   { "explicit",               RID_EXPLICIT,   D_CXXONLY | D_CXXWARN },
     527                 :             :   { "export",         RID_EXPORT,     D_CXXONLY | D_CXXWARN },
     528                 :             :   { "extern",         RID_EXTERN,     0 },
     529                 :             :   { "false",          RID_FALSE,      D_C23 | D_CXXWARN },
     530                 :             :   { "float",          RID_FLOAT,      0 },
     531                 :             :   { "for",            RID_FOR,        0 },
     532                 :             :   { "friend",         RID_FRIEND,     D_CXXONLY | D_CXXWARN },
     533                 :             :   { "goto",           RID_GOTO,       0 },
     534                 :             :   { "if",             RID_IF,         0 },
     535                 :             :   { "inline",         RID_INLINE,     D_EXT89 },
     536                 :             :   { "int",            RID_INT,        0 },
     537                 :             :   { "long",           RID_LONG,       0 },
     538                 :             :   { "mutable",                RID_MUTABLE,    D_CXXONLY | D_CXXWARN },
     539                 :             :   { "namespace",      RID_NAMESPACE,  D_CXXONLY | D_CXXWARN },
     540                 :             :   { "new",            RID_NEW,        D_CXXONLY | D_CXXWARN },
     541                 :             :   { "noexcept",               RID_NOEXCEPT,   D_CXXONLY | D_CXX11 | D_CXXWARN },
     542                 :             :   { "nullptr",                RID_NULLPTR,    D_C23 | D_CXX11 | D_CXXWARN },
     543                 :             :   { "operator",               RID_OPERATOR,   D_CXXONLY | D_CXXWARN },
     544                 :             :   { "private",                RID_PRIVATE,    D_CXX_OBJC | D_CXXWARN },
     545                 :             :   { "protected",      RID_PROTECTED,  D_CXX_OBJC | D_CXXWARN },
     546                 :             :   { "public",         RID_PUBLIC,     D_CXX_OBJC | D_CXXWARN },
     547                 :             :   { "register",               RID_REGISTER,   0 },
     548                 :             :   { "reinterpret_cast",       RID_REINTCAST,  D_CXXONLY | D_CXXWARN },
     549                 :             :   { "restrict",               RID_RESTRICT,   D_CONLY | D_C99 },
     550                 :             :   { "return",         RID_RETURN,     0 },
     551                 :             :   { "short",          RID_SHORT,      0 },
     552                 :             :   { "signed",         RID_SIGNED,     0 },
     553                 :             :   { "sizeof",         RID_SIZEOF,     0 },
     554                 :             :   { "static",         RID_STATIC,     0 },
     555                 :             :   { "static_assert",    RID_STATIC_ASSERT, D_C23 | D_CXX11 | D_CXXWARN },
     556                 :             :   { "static_cast",    RID_STATCAST,   D_CXXONLY | D_CXXWARN },
     557                 :             :   { "struct",         RID_STRUCT,     0 },
     558                 :             :   { "switch",         RID_SWITCH,     0 },
     559                 :             :   { "template",               RID_TEMPLATE,   D_CXXONLY | D_CXXWARN },
     560                 :             :   { "this",           RID_THIS,       D_CXXONLY | D_CXXWARN },
     561                 :             :   { "thread_local",   RID_THREAD,     D_C23 | D_CXX11 | D_CXXWARN },
     562                 :             :   { "throw",          RID_THROW,      D_CXX_OBJC | D_CXXWARN },
     563                 :             :   { "true",           RID_TRUE,       D_C23 | D_CXXWARN },
     564                 :             :   { "try",            RID_TRY,        D_CXX_OBJC | D_CXXWARN },
     565                 :             :   { "typedef",                RID_TYPEDEF,    0 },
     566                 :             :   { "typename",               RID_TYPENAME,   D_CXXONLY | D_CXXWARN },
     567                 :             :   { "typeid",         RID_TYPEID,     D_CXXONLY | D_CXXWARN },
     568                 :             :   { "typeof",         RID_TYPEOF,     D_EXT11 },
     569                 :             :   { "typeof_unqual",  RID_TYPEOF_UNQUAL,      D_CONLY | D_C23 },
     570                 :             :   { "union",          RID_UNION,      0 },
     571                 :             :   { "unsigned",               RID_UNSIGNED,   0 },
     572                 :             :   { "using",          RID_USING,      D_CXXONLY | D_CXXWARN },
     573                 :             :   { "virtual",                RID_VIRTUAL,    D_CXXONLY | D_CXXWARN },
     574                 :             :   { "void",           RID_VOID,       0 },
     575                 :             :   { "volatile",               RID_VOLATILE,   0 },
     576                 :             :   { "wchar_t",                RID_WCHAR,      D_CXXONLY },
     577                 :             :   { "while",          RID_WHILE,      0 },
     578                 :             : 
     579                 :             :   /* C++ transactional memory.  */
     580                 :             :   { "synchronized",   RID_SYNCHRONIZED, D_CXX_OBJC | D_TRANSMEM },
     581                 :             :   { "atomic_noexcept",        RID_ATOMIC_NOEXCEPT, D_CXXONLY | D_TRANSMEM },
     582                 :             :   { "atomic_cancel",  RID_ATOMIC_CANCEL, D_CXXONLY | D_TRANSMEM },
     583                 :             :   { "atomic_commit",  RID_TRANSACTION_ATOMIC, D_CXXONLY | D_TRANSMEM },
     584                 :             : 
     585                 :             :   /* Concepts-related keywords */
     586                 :             :   { "concept",                RID_CONCEPT,    D_CXX_CONCEPTS_FLAGS | D_CXXWARN },
     587                 :             :   { "requires",       RID_REQUIRES,   D_CXX_CONCEPTS_FLAGS | D_CXXWARN },
     588                 :             : 
     589                 :             :   /* Modules-related keywords, these are internal unspellable tokens,
     590                 :             :      created by the preprocessor.  */
     591                 :             :   { "module ",                RID__MODULE,    D_CXX_MODULES_FLAGS | D_CXXWARN },
     592                 :             :   { "import ",                RID__IMPORT,    D_CXX_MODULES_FLAGS | D_CXXWARN },
     593                 :             :   { "export ",                RID__EXPORT,    D_CXX_MODULES_FLAGS | D_CXXWARN },
     594                 :             : 
     595                 :             :   /* Coroutines-related keywords */
     596                 :             :   { "co_await",               RID_CO_AWAIT,   D_CXX_COROUTINES_FLAGS | D_CXXWARN },
     597                 :             :   { "co_yield",               RID_CO_YIELD,   D_CXX_COROUTINES_FLAGS | D_CXXWARN },
     598                 :             :   { "co_return",      RID_CO_RETURN,  D_CXX_COROUTINES_FLAGS | D_CXXWARN },
     599                 :             : 
     600                 :             :   /* These Objective-C keywords are recognized only immediately after
     601                 :             :      an '@'.  */
     602                 :             :   { "compatibility_alias", RID_AT_ALIAS,      D_OBJC },
     603                 :             :   { "defs",           RID_AT_DEFS,            D_OBJC },
     604                 :             :   { "encode",         RID_AT_ENCODE,          D_OBJC },
     605                 :             :   { "end",            RID_AT_END,             D_OBJC },
     606                 :             :   { "implementation", RID_AT_IMPLEMENTATION,  D_OBJC },
     607                 :             :   { "interface",      RID_AT_INTERFACE,       D_OBJC },
     608                 :             :   { "protocol",               RID_AT_PROTOCOL,        D_OBJC },
     609                 :             :   { "selector",               RID_AT_SELECTOR,        D_OBJC },
     610                 :             :   { "finally",                RID_AT_FINALLY,         D_OBJC },
     611                 :             :   { "optional",               RID_AT_OPTIONAL,        D_OBJC },
     612                 :             :   { "required",               RID_AT_REQUIRED,        D_OBJC },
     613                 :             :   { "property",               RID_AT_PROPERTY,        D_OBJC },
     614                 :             :   { "package",                RID_AT_PACKAGE,         D_OBJC },
     615                 :             :   { "synthesize",     RID_AT_SYNTHESIZE,      D_OBJC },
     616                 :             :   { "dynamic",                RID_AT_DYNAMIC,         D_OBJC },
     617                 :             :   /* These are recognized only in protocol-qualifier context
     618                 :             :      (see above) */
     619                 :             :   { "bycopy",         RID_BYCOPY,             D_OBJC },
     620                 :             :   { "byref",          RID_BYREF,              D_OBJC },
     621                 :             :   { "in",             RID_IN,                 D_OBJC },
     622                 :             :   { "inout",          RID_INOUT,              D_OBJC },
     623                 :             :   { "oneway",         RID_ONEWAY,             D_OBJC },
     624                 :             :   { "out",            RID_OUT,                D_OBJC },
     625                 :             :   /* These are recognized inside a property attribute list */
     626                 :             :   { "assign",         RID_ASSIGN,             D_OBJC },
     627                 :             :   { "atomic",         RID_PROPATOMIC,         D_OBJC },
     628                 :             :   { "copy",           RID_COPY,               D_OBJC },
     629                 :             :   { "getter",         RID_GETTER,             D_OBJC },
     630                 :             :   { "nonatomic",      RID_NONATOMIC,          D_OBJC },
     631                 :             :   { "readonly",               RID_READONLY,           D_OBJC },
     632                 :             :   { "readwrite",      RID_READWRITE,          D_OBJC },
     633                 :             :   { "retain",         RID_RETAIN,             D_OBJC },
     634                 :             :   { "setter",         RID_SETTER,             D_OBJC },
     635                 :             :   /* These are Objective C implementation of nullability, accepted only in
     636                 :             :      specific contexts.  */
     637                 :             :   { "null_unspecified", RID_NULL_UNSPECIFIED, D_OBJC },
     638                 :             :   { "nullable",               RID_NULLABLE,           D_OBJC },
     639                 :             :   { "nonnull",                RID_NONNULL,            D_OBJC },
     640                 :             :   { "null_resettable",        RID_NULL_RESETTABLE,    D_OBJC },
     641                 :             : };
     642                 :             : 
     643                 :             : const unsigned int num_c_common_reswords = ARRAY_SIZE (c_common_reswords);
     644                 :             : 
     645                 :             : /* Return identifier for address space AS.  */
     646                 :             : 
     647                 :             : const char *
     648                 :           3 : c_addr_space_name (addr_space_t as)
     649                 :             : {
     650                 :           3 :   int rid = RID_FIRST_ADDR_SPACE + as;
     651                 :           3 :   gcc_assert (ridpointers [rid]);
     652                 :           3 :   return IDENTIFIER_POINTER (ridpointers [rid]);
     653                 :             : }
     654                 :             : 
     655                 :             : /* Push current bindings for the function name VAR_DECLS.  */
     656                 :             : 
     657                 :             : void
     658                 :   176894758 : start_fname_decls (void)
     659                 :             : {
     660                 :   176894758 :   unsigned ix;
     661                 :   176894758 :   tree saved = NULL_TREE;
     662                 :             : 
     663                 :   707579032 :   for (ix = 0; fname_vars[ix].decl; ix++)
     664                 :             :     {
     665                 :   530684274 :       tree decl = *fname_vars[ix].decl;
     666                 :             : 
     667                 :   530684274 :       if (decl)
     668                 :             :         {
     669                 :       47647 :           saved = tree_cons (decl, build_int_cst (integer_type_node, ix),
     670                 :             :                              saved);
     671                 :       47647 :           *fname_vars[ix].decl = NULL_TREE;
     672                 :             :         }
     673                 :             :     }
     674                 :   176894758 :   if (saved || saved_function_name_decls)
     675                 :             :     /* Normally they'll have been NULL, so only push if we've got a
     676                 :             :        stack, or they are non-NULL.  */
     677                 :       65447 :     saved_function_name_decls = tree_cons (saved, NULL_TREE,
     678                 :             :                                            saved_function_name_decls);
     679                 :   176894758 : }
     680                 :             : 
     681                 :             : /* Finish up the current bindings, adding them into the current function's
     682                 :             :    statement tree.  This must be done _before_ finish_stmt_tree is called.
     683                 :             :    If there is no current function, we must be at file scope and no statements
     684                 :             :    are involved. Pop the previous bindings.  */
     685                 :             : 
     686                 :             : void
     687                 :   176782073 : finish_fname_decls (void)
     688                 :             : {
     689                 :   176782073 :   unsigned ix;
     690                 :   176782073 :   tree stmts = NULL_TREE;
     691                 :   176782073 :   tree stack = saved_function_name_decls;
     692                 :             : 
     693                 :   177040710 :   for (; stack && TREE_VALUE (stack); stack = TREE_CHAIN (stack))
     694                 :       96595 :     append_to_statement_list (TREE_VALUE (stack), &stmts);
     695                 :             : 
     696                 :   176782073 :   if (stmts)
     697                 :             :     {
     698                 :       96490 :       tree *bodyp = &DECL_SAVED_TREE (current_function_decl);
     699                 :             : 
     700                 :       96490 :       if (TREE_CODE (*bodyp) == BIND_EXPR)
     701                 :       92155 :         bodyp = &BIND_EXPR_BODY (*bodyp);
     702                 :             : 
     703                 :       96490 :       append_to_statement_list_force (*bodyp, &stmts);
     704                 :       96490 :       *bodyp = stmts;
     705                 :             :     }
     706                 :             : 
     707                 :   707128292 :   for (ix = 0; fname_vars[ix].decl; ix++)
     708                 :   530346219 :     *fname_vars[ix].decl = NULL_TREE;
     709                 :             : 
     710                 :   176782073 :   if (stack)
     711                 :             :     {
     712                 :             :       /* We had saved values, restore them.  */
     713                 :       65447 :       tree saved;
     714                 :             : 
     715                 :      113094 :       for (saved = TREE_PURPOSE (stack); saved; saved = TREE_CHAIN (saved))
     716                 :             :         {
     717                 :       47647 :           tree decl = TREE_PURPOSE (saved);
     718                 :       47647 :           unsigned ix = TREE_INT_CST_LOW (TREE_VALUE (saved));
     719                 :             : 
     720                 :       47647 :           *fname_vars[ix].decl = decl;
     721                 :             :         }
     722                 :       65447 :       stack = TREE_CHAIN (stack);
     723                 :             :     }
     724                 :   176782073 :   saved_function_name_decls = stack;
     725                 :   176782073 : }
     726                 :             : 
     727                 :             : /* Return the text name of the current function, suitably prettified
     728                 :             :    by PRETTY_P.  Return string must be freed by caller.  */
     729                 :             : 
     730                 :             : const char *
     731                 :        3340 : fname_as_string (int pretty_p)
     732                 :             : {
     733                 :        3340 :   const char *name = "top level";
     734                 :        3340 :   char *namep;
     735                 :        3340 :   int vrb = 2, len;
     736                 :        3340 :   cpp_string cstr = { 0, 0 }, strname;
     737                 :             : 
     738                 :        3340 :   if (!pretty_p)
     739                 :             :     {
     740                 :        1867 :       name = "";
     741                 :        1867 :       vrb = 0;
     742                 :             :     }
     743                 :             : 
     744                 :        3340 :   if (current_function_decl)
     745                 :        3333 :     name = lang_hooks.decl_printable_name (current_function_decl, vrb);
     746                 :             : 
     747                 :        3340 :   len = strlen (name) + 3; /* Two for '"'s.  One for NULL.  */
     748                 :             : 
     749                 :        3340 :   namep = XNEWVEC (char, len);
     750                 :        3340 :   snprintf (namep, len, "\"%s\"", name);
     751                 :        3340 :   strname.text = (unsigned char *) namep;
     752                 :        3340 :   strname.len = len - 1;
     753                 :             : 
     754                 :        3340 :   if (cpp_interpret_string (parse_in, &strname, 1, &cstr, CPP_STRING))
     755                 :             :     {
     756                 :        3340 :       XDELETEVEC (namep);
     757                 :        3340 :       return (const char *) cstr.text;
     758                 :             :     }
     759                 :             : 
     760                 :             :   return namep;
     761                 :             : }
     762                 :             : 
     763                 :             : /* Return the VAR_DECL for a const char array naming the current
     764                 :             :    function. If the VAR_DECL has not yet been created, create it
     765                 :             :    now. RID indicates how it should be formatted and IDENTIFIER_NODE
     766                 :             :    ID is its name (unfortunately C and C++ hold the RID values of
     767                 :             :    keywords in different places, so we can't derive RID from ID in
     768                 :             :    this language independent code. LOC is the location of the
     769                 :             :    function.  */
     770                 :             : 
     771                 :             : tree
     772                 :      193315 : fname_decl (location_t loc, unsigned int rid, tree id)
     773                 :             : {
     774                 :      193315 :   unsigned ix;
     775                 :      193315 :   tree decl = NULL_TREE;
     776                 :             : 
     777                 :      559427 :   for (ix = 0; fname_vars[ix].decl; ix++)
     778                 :      559427 :     if (fname_vars[ix].rid == rid)
     779                 :             :       break;
     780                 :             : 
     781                 :      193315 :   decl = *fname_vars[ix].decl;
     782                 :      193315 :   if (!decl)
     783                 :             :     {
     784                 :             :       /* If a tree is built here, it would normally have the lineno of
     785                 :             :          the current statement.  Later this tree will be moved to the
     786                 :             :          beginning of the function and this line number will be wrong.
     787                 :             :          To avoid this problem set the lineno to 0 here; that prevents
     788                 :             :          it from appearing in the RTL.  */
     789                 :       96595 :       tree stmts;
     790                 :       96595 :       location_t saved_location = input_location;
     791                 :       96595 :       input_location = UNKNOWN_LOCATION;
     792                 :             : 
     793                 :       96595 :       stmts = push_stmt_list ();
     794                 :       96595 :       decl = (*make_fname_decl) (loc, id, fname_vars[ix].pretty);
     795                 :       96595 :       stmts = pop_stmt_list (stmts);
     796                 :       96595 :       if (!IS_EMPTY_STMT (stmts))
     797                 :       96595 :         saved_function_name_decls
     798                 :       96595 :           = tree_cons (decl, stmts, saved_function_name_decls);
     799                 :       96595 :       *fname_vars[ix].decl = decl;
     800                 :       96595 :       input_location = saved_location;
     801                 :             :     }
     802                 :      193315 :   if (!ix && !current_function_decl)
     803                 :           4 :     pedwarn (loc, 0, "%qD is not defined outside of function scope", decl);
     804                 :             : 
     805                 :      193315 :   return decl;
     806                 :             : }
     807                 :             : 
     808                 :             : /* Given a STRING_CST, give it a suitable array-of-chars data type.  */
     809                 :             : 
     810                 :             : tree
     811                 :    25123700 : fix_string_type (tree value)
     812                 :             : {
     813                 :    25123700 :   int length = TREE_STRING_LENGTH (value);
     814                 :    25123700 :   int nchars, charsz;
     815                 :    25123700 :   tree e_type, i_type, a_type;
     816                 :             : 
     817                 :             :   /* Compute the number of elements, for the array type.  */
     818                 :    25123700 :   if (TREE_TYPE (value) == char_array_type_node || !TREE_TYPE (value))
     819                 :             :     {
     820                 :    24915548 :       charsz = 1;
     821                 :    24915548 :       e_type = char_type_node;
     822                 :             :     }
     823                 :      208152 :   else if (flag_char8_t && TREE_TYPE (value) == char8_array_type_node)
     824                 :             :     {
     825                 :         376 :       charsz = TYPE_PRECISION (char8_type_node) / BITS_PER_UNIT;
     826                 :         376 :       e_type = char8_type_node;
     827                 :             :     }
     828                 :      207776 :   else if (TREE_TYPE (value) == char16_array_type_node)
     829                 :             :     {
     830                 :         946 :       charsz = TYPE_PRECISION (char16_type_node) / BITS_PER_UNIT;
     831                 :         946 :       e_type = char16_type_node;
     832                 :             :     }
     833                 :      206830 :   else if (TREE_TYPE (value) == char32_array_type_node)
     834                 :             :     {
     835                 :        3050 :       charsz = TYPE_PRECISION (char32_type_node) / BITS_PER_UNIT;
     836                 :        3050 :       e_type = char32_type_node;
     837                 :             :     }
     838                 :             :   else
     839                 :             :     {
     840                 :      203780 :       charsz = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT;
     841                 :      203780 :       e_type = wchar_type_node;
     842                 :             :     }
     843                 :             : 
     844                 :             :   /* This matters only for targets where ssizetype has smaller precision
     845                 :             :      than 32 bits.  */
     846                 :    25123700 :   if (wi::lts_p (wi::to_wide (TYPE_MAX_VALUE (ssizetype)), length))
     847                 :             :     {
     848                 :           0 :       error ("size of string literal is too large");
     849                 :           0 :       length = tree_to_shwi (TYPE_MAX_VALUE (ssizetype)) / charsz * charsz;
     850                 :           0 :       char *str = CONST_CAST (char *, TREE_STRING_POINTER (value));
     851                 :           0 :       memset (str + length, '\0',
     852                 :           0 :               MIN (TREE_STRING_LENGTH (value) - length, charsz));
     853                 :           0 :       TREE_STRING_LENGTH (value) = length;
     854                 :             :     }
     855                 :    25123700 :   nchars = length / charsz;
     856                 :             : 
     857                 :             :   /* C89 2.2.4.1, C99 5.2.4.1 (Translation limits).  The analogous
     858                 :             :      limit in C++98 Annex B is very large (65536) and is not normative,
     859                 :             :      so we do not diagnose it (warn_overlength_strings is forced off
     860                 :             :      in c_common_post_options).  */
     861                 :    25123700 :   if (warn_overlength_strings)
     862                 :             :     {
     863                 :       14925 :       const int nchars_max = flag_isoc99 ? 4095 : 509;
     864                 :       14925 :       const int relevant_std = flag_isoc99 ? 99 : 90;
     865                 :       14925 :       if (nchars - 1 > nchars_max)
     866                 :             :         /* Translators: The %d after 'ISO C' will be 90 or 99.  Do not
     867                 :             :            separate the %d from the 'C'.  'ISO' should not be
     868                 :             :            translated, but it may be moved after 'C%d' in languages
     869                 :             :            where modifiers follow nouns.  */
     870                 :           5 :         pedwarn (input_location, OPT_Woverlength_strings,
     871                 :             :                  "string length %qd is greater than the length %qd "
     872                 :             :                  "ISO C%d compilers are required to support",
     873                 :             :                  nchars - 1, nchars_max, relevant_std);
     874                 :             :     }
     875                 :             : 
     876                 :             :   /* Create the array type for the string constant.  The ISO C++
     877                 :             :      standard says that a string literal has type `const char[N]' or
     878                 :             :      `const wchar_t[N]'.  We use the same logic when invoked as a C
     879                 :             :      front-end with -Wwrite-strings.
     880                 :             :      ??? We should change the type of an expression depending on the
     881                 :             :      state of a warning flag.  We should just be warning -- see how
     882                 :             :      this is handled in the C++ front-end for the deprecated implicit
     883                 :             :      conversion from string literals to `char*' or `wchar_t*'.
     884                 :             : 
     885                 :             :      The C++ front end relies on TYPE_MAIN_VARIANT of a cv-qualified
     886                 :             :      array type being the unqualified version of that type.
     887                 :             :      Therefore, if we are constructing an array of const char, we must
     888                 :             :      construct the matching unqualified array type first.  The C front
     889                 :             :      end does not require this, but it does no harm, so we do it
     890                 :             :      unconditionally.  */
     891                 :    25123700 :   i_type = build_index_type (size_int (nchars - 1));
     892                 :    25123700 :   a_type = build_array_type (e_type, i_type);
     893                 :    25123700 :   if (c_dialect_cxx() || warn_write_strings)
     894                 :    22775394 :     a_type = c_build_qualified_type (a_type, TYPE_QUAL_CONST);
     895                 :             : 
     896                 :    25123700 :   TREE_TYPE (value) = a_type;
     897                 :    25123700 :   TREE_CONSTANT (value) = 1;
     898                 :    25123700 :   TREE_READONLY (value) = 1;
     899                 :    25123700 :   TREE_STATIC (value) = 1;
     900                 :    25123700 :   return value;
     901                 :             : }
     902                 :             : 
     903                 :             : /* Given a string of type STRING_TYPE, determine what kind of string
     904                 :             :    token would give an equivalent execution encoding: CPP_STRING,
     905                 :             :    CPP_STRING16, or CPP_STRING32.  Return CPP_OTHER in case of error.
     906                 :             :    This may not be exactly the string token type that initially created
     907                 :             :    the string, since CPP_WSTRING is indistinguishable from the 16/32 bit
     908                 :             :    string type, and CPP_UTF8STRING is indistinguishable from CPP_STRING
     909                 :             :    at this point.
     910                 :             : 
     911                 :             :    This effectively reverses part of the logic in lex_string and
     912                 :             :    fix_string_type.  */
     913                 :             : 
     914                 :             : static enum cpp_ttype
     915                 :       11260 : get_cpp_ttype_from_string_type (tree string_type)
     916                 :             : {
     917                 :       11260 :   gcc_assert (string_type);
     918                 :       11260 :   if (TREE_CODE (string_type) == POINTER_TYPE)
     919                 :        5973 :     string_type = TREE_TYPE (string_type);
     920                 :             : 
     921                 :       11260 :   if (TREE_CODE (string_type) != ARRAY_TYPE)
     922                 :             :     return CPP_OTHER;
     923                 :             : 
     924                 :       11260 :   tree element_type = TREE_TYPE (string_type);
     925                 :       11260 :   if (TREE_CODE (element_type) != INTEGER_TYPE)
     926                 :             :     return CPP_OTHER;
     927                 :             : 
     928                 :       11260 :   int bits_per_character = TYPE_PRECISION (element_type);
     929                 :       11260 :   switch (bits_per_character)
     930                 :             :     {
     931                 :             :     case 8:
     932                 :             :       return CPP_STRING;  /* It could have also been CPP_UTF8STRING.  */
     933                 :           2 :     case 16:
     934                 :           2 :       return CPP_STRING16;
     935                 :           4 :     case 32:
     936                 :           4 :       return CPP_STRING32;
     937                 :             :     }
     938                 :             : 
     939                 :             :   return CPP_OTHER;
     940                 :             : }
     941                 :             : 
     942                 :             : /* The global record of string concatentations, for use in
     943                 :             :    extracting locations within string literals.  */
     944                 :             : 
     945                 :             : GTY(()) string_concat_db *g_string_concat_db;
     946                 :             : 
     947                 :             : /* Implementation of LANG_HOOKS_GET_SUBSTRING_LOCATION.  */
     948                 :             : 
     949                 :             : const char *
     950                 :       11260 : c_get_substring_location (const substring_loc &substr_loc,
     951                 :             :                           location_t *out_loc)
     952                 :             : {
     953                 :       11260 :   enum cpp_ttype tok_type
     954                 :       11260 :     = get_cpp_ttype_from_string_type (substr_loc.get_string_type ());
     955                 :       11260 :   if (tok_type == CPP_OTHER)
     956                 :             :     return "unrecognized string type";
     957                 :             : 
     958                 :       11260 :   return get_location_within_string (parse_in,
     959                 :             :                                      global_dc->get_file_cache (),
     960                 :             :                                      g_string_concat_db,
     961                 :             :                                      substr_loc.get_fmt_string_loc (),
     962                 :             :                                      tok_type,
     963                 :             :                                      substr_loc.get_caret_idx (),
     964                 :             :                                      substr_loc.get_start_idx (),
     965                 :             :                                      substr_loc.get_end_idx (),
     966                 :       11260 :                                      out_loc);
     967                 :             : }
     968                 :             : 
     969                 :             : 
     970                 :             : /* Return true iff T is a boolean promoted to int.  */
     971                 :             : 
     972                 :             : bool
     973                 :       74819 : bool_promoted_to_int_p (tree t)
     974                 :             : {
     975                 :       57687 :   return (CONVERT_EXPR_P (t)
     976                 :       17232 :           && TREE_TYPE (t) == integer_type_node
     977                 :       74919 :           && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == BOOLEAN_TYPE);
     978                 :             : }
     979                 :             : 
     980                 :             : /* vector_targets_convertible_p is used for vector pointer types.  The
     981                 :             :    callers perform various checks that the qualifiers are satisfactory,
     982                 :             :    while OTOH vector_targets_convertible_p ignores the number of elements
     983                 :             :    in the vectors.  That's fine with vector pointers as we can consider,
     984                 :             :    say, a vector of 8 elements as two consecutive vectors of 4 elements,
     985                 :             :    and that does not require and conversion of the pointer values.
     986                 :             :    In contrast, vector_types_convertible_p and
     987                 :             :    vector_types_compatible_elements_p are used for vector value types.  */
     988                 :             : /* True if pointers to distinct types T1 and T2 can be converted to
     989                 :             :    each other without an explicit cast.  Only returns true for opaque
     990                 :             :    vector types.  */
     991                 :             : bool
     992                 :     1994113 : vector_targets_convertible_p (const_tree t1, const_tree t2)
     993                 :             : {
     994                 :      954145 :   if (VECTOR_TYPE_P (t1) && VECTOR_TYPE_P (t2)
     995                 :      953969 :       && (TYPE_VECTOR_OPAQUE (t1) || TYPE_VECTOR_OPAQUE (t2))
     996                 :     1994113 :       && tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2)))
     997                 :             :     return true;
     998                 :             : 
     999                 :             :   return false;
    1000                 :             : }
    1001                 :             : 
    1002                 :             : /* vector_types_convertible_p is used for vector value types.
    1003                 :             :    It could in principle call vector_targets_convertible_p as a subroutine,
    1004                 :             :    but then the check for vector type would be duplicated with its callers,
    1005                 :             :    and also the purpose of vector_targets_convertible_p would become
    1006                 :             :    muddled.
    1007                 :             :    Where vector_types_convertible_p returns true, a conversion might still be
    1008                 :             :    needed to make the types match.
    1009                 :             :    In contrast, vector_targets_convertible_p is used for vector pointer
    1010                 :             :    values, and vector_types_compatible_elements_p is used specifically
    1011                 :             :    in the context for binary operators, as a check if use is possible without
    1012                 :             :    conversion.  */
    1013                 :             : /* True if vector types T1 and T2 can be converted to each other
    1014                 :             :    without an explicit cast.  If EMIT_LAX_NOTE is true, and T1 and T2
    1015                 :             :    can only be converted with -flax-vector-conversions yet that is not
    1016                 :             :    in effect, emit a note telling the user about that option if such
    1017                 :             :    a note has not previously been emitted.  */
    1018                 :             : bool
    1019                 :    17794090 : vector_types_convertible_p (const_tree t1, const_tree t2, bool emit_lax_note)
    1020                 :             : {
    1021                 :    17794090 :   static bool emitted_lax_note = false;
    1022                 :    17794090 :   bool convertible_lax;
    1023                 :             : 
    1024                 :    35583689 :   if ((TYPE_VECTOR_OPAQUE (t1) || TYPE_VECTOR_OPAQUE (t2))
    1025                 :    17795596 :       && tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2)))
    1026                 :             :     return true;
    1027                 :             : 
    1028                 :    35576302 :   convertible_lax =
    1029                 :    17788151 :     (tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2))
    1030                 :    17784659 :      && (TREE_CODE (TREE_TYPE (t1)) != REAL_TYPE
    1031                 :    10472810 :          || known_eq (TYPE_VECTOR_SUBPARTS (t1),
    1032                 :             :                       TYPE_VECTOR_SUBPARTS (t2)))
    1033                 :    53300801 :      && (INTEGRAL_TYPE_P (TREE_TYPE (t1))
    1034                 :    17756325 :          == INTEGRAL_TYPE_P (TREE_TYPE (t2))));
    1035                 :             : 
    1036                 :    17788151 :   if (!convertible_lax || flag_lax_vector_conversions)
    1037                 :       64699 :     return convertible_lax;
    1038                 :             : 
    1039                 :    17723452 :   if (known_eq (TYPE_VECTOR_SUBPARTS (t1), TYPE_VECTOR_SUBPARTS (t2))
    1040                 :    17723452 :       && lang_hooks.types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1041                 :    16372551 :     return true;
    1042                 :             : 
    1043                 :     1350901 :   if (emit_lax_note && !emitted_lax_note)
    1044                 :             :     {
    1045                 :          10 :       emitted_lax_note = true;
    1046                 :          10 :       inform (input_location, "use %<-flax-vector-conversions%> to permit "
    1047                 :             :               "conversions between vectors with differing "
    1048                 :             :               "element types or numbers of subparts");
    1049                 :             :     }
    1050                 :             : 
    1051                 :             :   return false;
    1052                 :             : }
    1053                 :             : 
    1054                 :             : /* Build a VEC_PERM_EXPR if V0, V1 and MASK are not error_mark_nodes
    1055                 :             :    and have vector types, V0 has the same type as V1, and the number of
    1056                 :             :    elements of V0, V1, MASK is the same.
    1057                 :             : 
    1058                 :             :    In case V1 is a NULL_TREE it is assumed that __builtin_shuffle was
    1059                 :             :    called with two arguments.  In this case implementation passes the
    1060                 :             :    first argument twice in order to share the same tree code.  This fact
    1061                 :             :    could enable the mask-values being twice the vector length.  This is
    1062                 :             :    an implementation accident and this semantics is not guaranteed to
    1063                 :             :    the user.  */
    1064                 :             : tree
    1065                 :      474650 : c_build_vec_perm_expr (location_t loc, tree v0, tree v1, tree mask,
    1066                 :             :                        bool complain)
    1067                 :             : {
    1068                 :      474650 :   tree ret;
    1069                 :      474650 :   bool wrap = true;
    1070                 :      474650 :   bool maybe_const = false;
    1071                 :      474650 :   bool two_arguments = false;
    1072                 :             : 
    1073                 :      474650 :   if (v1 == NULL_TREE)
    1074                 :             :     {
    1075                 :      432581 :       two_arguments = true;
    1076                 :      432581 :       v1 = v0;
    1077                 :             :     }
    1078                 :             : 
    1079                 :      474650 :   if (v0 == error_mark_node || v1 == error_mark_node
    1080                 :      474650 :       || mask == error_mark_node)
    1081                 :             :     return error_mark_node;
    1082                 :             : 
    1083                 :      474650 :   if (!gnu_vector_type_p (TREE_TYPE (mask))
    1084                 :      474650 :       || !VECTOR_INTEGER_TYPE_P (TREE_TYPE (mask)))
    1085                 :             :     {
    1086                 :           3 :       if (complain)
    1087                 :           0 :         error_at (loc, "%<__builtin_shuffle%> last argument must "
    1088                 :             :                        "be an integer vector");
    1089                 :           3 :       return error_mark_node;
    1090                 :             :     }
    1091                 :             : 
    1092                 :      474647 :   if (!gnu_vector_type_p (TREE_TYPE (v0))
    1093                 :      474647 :       || !gnu_vector_type_p (TREE_TYPE (v1)))
    1094                 :             :     {
    1095                 :           0 :       if (complain)
    1096                 :           0 :         error_at (loc, "%<__builtin_shuffle%> arguments must be vectors");
    1097                 :           0 :       return error_mark_node;
    1098                 :             :     }
    1099                 :             : 
    1100                 :      474647 :   if (TYPE_MAIN_VARIANT (TREE_TYPE (v0)) != TYPE_MAIN_VARIANT (TREE_TYPE (v1)))
    1101                 :             :     {
    1102                 :           0 :       if (complain)
    1103                 :           0 :         error_at (loc, "%<__builtin_shuffle%> argument vectors must be of "
    1104                 :             :                        "the same type");
    1105                 :           0 :       return error_mark_node;
    1106                 :             :     }
    1107                 :             : 
    1108                 :      474647 :   if (maybe_ne (TYPE_VECTOR_SUBPARTS (TREE_TYPE (v0)),
    1109                 :      474647 :                 TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask)))
    1110                 :      474647 :       && maybe_ne (TYPE_VECTOR_SUBPARTS (TREE_TYPE (v1)),
    1111                 :           0 :                    TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask))))
    1112                 :             :     {
    1113                 :           0 :       if (complain)
    1114                 :           0 :         error_at (loc, "%<__builtin_shuffle%> number of elements of the "
    1115                 :             :                        "argument vector(s) and the mask vector should "
    1116                 :             :                        "be the same");
    1117                 :           0 :       return error_mark_node;
    1118                 :             :     }
    1119                 :             : 
    1120                 :      474647 :   if (GET_MODE_BITSIZE (SCALAR_TYPE_MODE (TREE_TYPE (TREE_TYPE (v0))))
    1121                 :      949294 :       != GET_MODE_BITSIZE (SCALAR_TYPE_MODE (TREE_TYPE (TREE_TYPE (mask)))))
    1122                 :             :     {
    1123                 :           0 :       if (complain)
    1124                 :           0 :         error_at (loc, "%<__builtin_shuffle%> argument vector(s) inner type "
    1125                 :             :                        "must have the same size as inner type of the mask");
    1126                 :           0 :       return error_mark_node;
    1127                 :             :     }
    1128                 :             : 
    1129                 :      474647 :   if (!c_dialect_cxx ())
    1130                 :             :     {
    1131                 :             :       /* Avoid C_MAYBE_CONST_EXPRs inside VEC_PERM_EXPR.  */
    1132                 :      459922 :       v0 = c_fully_fold (v0, false, &maybe_const);
    1133                 :      459922 :       wrap &= maybe_const;
    1134                 :             : 
    1135                 :      459922 :       if (two_arguments)
    1136                 :      418662 :         v1 = v0 = save_expr (v0);
    1137                 :             :       else
    1138                 :             :         {
    1139                 :       41260 :           v1 = c_fully_fold (v1, false, &maybe_const);
    1140                 :       41260 :           wrap &= maybe_const;
    1141                 :             :         }
    1142                 :             : 
    1143                 :      459922 :       mask = c_fully_fold (mask, false, &maybe_const);
    1144                 :      459922 :       wrap &= maybe_const;
    1145                 :             :     }
    1146                 :       14725 :   else if (two_arguments)
    1147                 :       13916 :     v1 = v0 = save_expr (v0);
    1148                 :             : 
    1149                 :      474647 :   ret = build3_loc (loc, VEC_PERM_EXPR, TREE_TYPE (v0), v0, v1, mask);
    1150                 :             : 
    1151                 :      474647 :   if (!c_dialect_cxx () && !wrap)
    1152                 :      459922 :     ret = c_wrap_maybe_const (ret, true);
    1153                 :             : 
    1154                 :             :   return ret;
    1155                 :             : }
    1156                 :             : 
    1157                 :             : /* Build a VEC_PERM_EXPR if V0, V1 are not error_mark_nodes
    1158                 :             :    and have vector types, V0 has the same element type as V1, and the
    1159                 :             :    number of elements the result is that of MASK.  */
    1160                 :             : tree
    1161                 :     1087105 : c_build_shufflevector (location_t loc, tree v0, tree v1,
    1162                 :             :                        const vec<tree> &mask, bool complain)
    1163                 :             : {
    1164                 :     1087105 :   tree ret;
    1165                 :     1087105 :   bool wrap = true;
    1166                 :     1087105 :   bool maybe_const = false;
    1167                 :             : 
    1168                 :     1087105 :   if (v0 == error_mark_node || v1 == error_mark_node)
    1169                 :             :     return error_mark_node;
    1170                 :             : 
    1171                 :     1087105 :   if (!gnu_vector_type_p (TREE_TYPE (v0))
    1172                 :     1087105 :       || !gnu_vector_type_p (TREE_TYPE (v1)))
    1173                 :             :     {
    1174                 :           4 :       if (complain)
    1175                 :           4 :         error_at (loc, "%<__builtin_shufflevector%> arguments must be vectors");
    1176                 :           4 :       return error_mark_node;
    1177                 :             :     }
    1178                 :             : 
    1179                 :             :   /* ???  In principle one could select a constant part of a variable size
    1180                 :             :      vector but things get a bit awkward with trying to support this here.  */
    1181                 :     1087101 :   unsigned HOST_WIDE_INT v0n, v1n;
    1182                 :     1087101 :   if (!TYPE_VECTOR_SUBPARTS (TREE_TYPE (v0)).is_constant (&v0n)
    1183                 :     1087101 :       || !TYPE_VECTOR_SUBPARTS (TREE_TYPE (v1)).is_constant (&v1n))
    1184                 :             :     {
    1185                 :             :       if (complain)
    1186                 :             :         error_at (loc, "%<__builtin_shufflevector%> arguments must be constant"
    1187                 :             :                   " size vectors");
    1188                 :             :       return error_mark_node;
    1189                 :             :     }
    1190                 :             : 
    1191                 :     1087101 :   if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (v0)))
    1192                 :     1087101 :       != TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (v1))))
    1193                 :             :     {
    1194                 :           4 :       if (complain)
    1195                 :           4 :         error_at (loc, "%<__builtin_shufflevector%> argument vectors must "
    1196                 :             :                   "have the same element type");
    1197                 :           4 :       return error_mark_node;
    1198                 :             :     }
    1199                 :             : 
    1200                 :     1087097 :   if (!pow2p_hwi (mask.length ()))
    1201                 :             :     {
    1202                 :           4 :       if (complain)
    1203                 :           4 :         error_at (loc, "%<__builtin_shufflevector%> must specify a result "
    1204                 :             :                   "with a power of two number of elements");
    1205                 :           4 :       return error_mark_node;
    1206                 :             :     }
    1207                 :             : 
    1208                 :     1087093 :   if (!c_dialect_cxx ())
    1209                 :             :     {
    1210                 :             :       /* Avoid C_MAYBE_CONST_EXPRs inside VEC_PERM_EXPR.  */
    1211                 :     1052669 :       v0 = c_fully_fold (v0, false, &maybe_const);
    1212                 :     1052669 :       wrap &= maybe_const;
    1213                 :             : 
    1214                 :     1052669 :       v1 = c_fully_fold (v1, false, &maybe_const);
    1215                 :     1052669 :       wrap &= maybe_const;
    1216                 :             :     }
    1217                 :             : 
    1218                 :     2174231 :   unsigned HOST_WIDE_INT maskl = MAX (mask.length (), MAX (v0n, v1n));
    1219                 :     1087093 :   unsigned HOST_WIDE_INT pad = (v0n < maskl ? maskl - v0n : 0);
    1220                 :     1087093 :   vec_perm_builder sel (maskl, maskl, 1);
    1221                 :     1087093 :   unsigned i;
    1222                 :    29505498 :   for (i = 0; i < mask.length (); ++i)
    1223                 :             :     {
    1224                 :    13665671 :       tree idx = mask[i];
    1225                 :    13665671 :       if (!tree_fits_shwi_p (idx))
    1226                 :             :         {
    1227                 :           4 :           if (complain)
    1228                 :           4 :             error_at (loc, "invalid element index %qE to "
    1229                 :             :                       "%<__builtin_shufflevector%>", idx);
    1230                 :     1087093 :           return error_mark_node;
    1231                 :             :         }
    1232                 :    13665667 :       HOST_WIDE_INT iidx = tree_to_shwi (idx);
    1233                 :    13665667 :       if (iidx < -1
    1234                 :    13665663 :           || (iidx != -1
    1235                 :    13665583 :               && (unsigned HOST_WIDE_INT) iidx >= v0n + v1n))
    1236                 :             :         {
    1237                 :          11 :           if (complain)
    1238                 :          11 :             error_at (loc, "invalid element index %qE to "
    1239                 :             :                       "%<__builtin_shufflevector%>", idx);
    1240                 :          11 :           return error_mark_node;
    1241                 :             :         }
    1242                 :             :       /* ???  Our VEC_PERM_EXPR does not allow for -1 yet.  */
    1243                 :    13665656 :       if (iidx == -1)
    1244                 :          80 :         iidx = i;
    1245                 :             :       /* ???  Our VEC_PERM_EXPR does not allow different sized inputs,
    1246                 :             :          so pad out a smaller v0.  */
    1247                 :    13665576 :       else if ((unsigned HOST_WIDE_INT) iidx >= v0n)
    1248                 :        1159 :         iidx += pad;
    1249                 :    13665656 :       sel.quick_push (iidx);
    1250                 :             :     }
    1251                 :             :   /* ???  VEC_PERM_EXPR does not support a result that is smaller than
    1252                 :             :      the inputs, so we have to pad id out.  */
    1253                 :     1088206 :   for (; i < maskl; ++i)
    1254                 :        1128 :     sel.quick_push (i);
    1255                 :             : 
    1256                 :     1087078 :   vec_perm_indices indices (sel, 2, maskl);
    1257                 :             : 
    1258                 :     1087078 :   tree ret_type = build_vector_type (TREE_TYPE (TREE_TYPE (v0)), maskl);
    1259                 :     2174156 :   tree mask_type = build_vector_type (build_nonstandard_integer_type
    1260                 :     1087078 :                 (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (ret_type))), 1),
    1261                 :     1087078 :                 maskl);
    1262                 :             :   /* Pad out arguments to the common vector size.  */
    1263                 :     1087078 :   if (v0n < maskl)
    1264                 :             :     {
    1265                 :         125 :       constructor_elt elt = { NULL_TREE, build_zero_cst (TREE_TYPE (v0)) };
    1266                 :         125 :       v0 = build_constructor_single (ret_type, NULL_TREE, v0);
    1267                 :         571 :       for (i = 1; i < maskl / v0n; ++i)
    1268                 :         321 :         vec_safe_push (CONSTRUCTOR_ELTS (v0), elt);
    1269                 :             :     }
    1270                 :     1087078 :   if (v1n < maskl)
    1271                 :             :     {
    1272                 :          95 :       constructor_elt elt = { NULL_TREE, build_zero_cst (TREE_TYPE (v1)) };
    1273                 :          95 :       v1 = build_constructor_single (ret_type, NULL_TREE, v1);
    1274                 :         351 :       for (i = 1; i < maskl / v1n; ++i)
    1275                 :         161 :         vec_safe_push (CONSTRUCTOR_ELTS (v1), elt);
    1276                 :             :     }
    1277                 :     1087078 :   ret = build3_loc (loc, VEC_PERM_EXPR, ret_type, v0, v1,
    1278                 :             :                     vec_perm_indices_to_tree (mask_type, indices));
    1279                 :             :   /* Get the lowpart we are interested in.  */
    1280                 :     2174156 :   if (mask.length () < maskl)
    1281                 :             :     {
    1282                 :         159 :       tree lpartt = build_vector_type (TREE_TYPE (ret_type), mask.length ());
    1283                 :         159 :       ret = build3_loc (loc, BIT_FIELD_REF,
    1284                 :         159 :                         lpartt, ret, TYPE_SIZE (lpartt), bitsize_zero_node);
    1285                 :             :       /* Wrap the lowpart operation in a TARGET_EXPR so it gets a separate
    1286                 :             :          temporary during gimplification.  See PR101530 for cases where
    1287                 :             :          we'd otherwise end up with non-toplevel BIT_FIELD_REFs.  */
    1288                 :         159 :       tree tem = create_tmp_var_raw (lpartt);
    1289                 :         159 :       DECL_CONTEXT (tem) = current_function_decl;
    1290                 :         159 :       ret = build4 (TARGET_EXPR, lpartt, tem, ret, NULL_TREE, NULL_TREE);
    1291                 :         159 :       TREE_SIDE_EFFECTS (ret) = 1;
    1292                 :             :     }
    1293                 :             : 
    1294                 :     1087078 :   if (!c_dialect_cxx () && !wrap)
    1295                 :     1052666 :     ret = c_wrap_maybe_const (ret, true);
    1296                 :             : 
    1297                 :     1087078 :   return ret;
    1298                 :     2174171 : }
    1299                 :             : 
    1300                 :             : /* Build a VEC_CONVERT ifn for __builtin_convertvector builtin.  */
    1301                 :             : 
    1302                 :             : tree
    1303                 :         490 : c_build_vec_convert (location_t loc1, tree expr, location_t loc2, tree type,
    1304                 :             :                      bool complain)
    1305                 :             : {
    1306                 :         490 :   if (error_operand_p (type))
    1307                 :           0 :     return error_mark_node;
    1308                 :         490 :   if (error_operand_p (expr))
    1309                 :           0 :     return error_mark_node;
    1310                 :             : 
    1311                 :         490 :   if (!gnu_vector_type_p (TREE_TYPE (expr))
    1312                 :         490 :       || (!VECTOR_INTEGER_TYPE_P (TREE_TYPE (expr))
    1313                 :         166 :           && !VECTOR_FLOAT_TYPE_P (TREE_TYPE (expr))))
    1314                 :             :     {
    1315                 :           4 :       if (complain)
    1316                 :           4 :         error_at (loc1, "%<__builtin_convertvector%> first argument must "
    1317                 :             :                         "be an integer or floating vector");
    1318                 :           4 :       return error_mark_node;
    1319                 :             :     }
    1320                 :             : 
    1321                 :         486 :   if (!gnu_vector_type_p (type)
    1322                 :         486 :       || (!VECTOR_INTEGER_TYPE_P (type) && !VECTOR_FLOAT_TYPE_P (type)))
    1323                 :             :     {
    1324                 :           4 :       if (complain)
    1325                 :           4 :         error_at (loc2, "%<__builtin_convertvector%> second argument must "
    1326                 :             :                         "be an integer or floating vector type");
    1327                 :           4 :       return error_mark_node;
    1328                 :             :     }
    1329                 :             : 
    1330                 :         482 :   if (maybe_ne (TYPE_VECTOR_SUBPARTS (TREE_TYPE (expr)),
    1331                 :         964 :                 TYPE_VECTOR_SUBPARTS (type)))
    1332                 :             :     {
    1333                 :           8 :       if (complain)
    1334                 :           8 :         error_at (loc1, "%<__builtin_convertvector%> number of elements "
    1335                 :             :                         "of the first argument vector and the second argument "
    1336                 :             :                         "vector type should be the same");
    1337                 :           8 :       return error_mark_node;
    1338                 :             :     }
    1339                 :             : 
    1340                 :         474 :   if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (expr)))
    1341                 :         474 :        == TYPE_MAIN_VARIANT (TREE_TYPE (type)))
    1342                 :         474 :       || (VECTOR_INTEGER_TYPE_P (TREE_TYPE (expr))
    1343                 :         303 :           && VECTOR_INTEGER_TYPE_P (type)
    1344                 :         155 :           && (TYPE_PRECISION (TREE_TYPE (TREE_TYPE (expr)))
    1345                 :         155 :               == TYPE_PRECISION (TREE_TYPE (type)))))
    1346                 :          29 :     return build1_loc (loc1, VIEW_CONVERT_EXPR, type, expr);
    1347                 :             : 
    1348                 :         445 :   bool wrap = true;
    1349                 :         445 :   bool maybe_const = false;
    1350                 :         445 :   tree ret;
    1351                 :         445 :   if (!c_dialect_cxx ())
    1352                 :             :     {
    1353                 :             :       /* Avoid C_MAYBE_CONST_EXPRs inside of VEC_CONVERT argument.  */
    1354                 :         310 :       expr = c_fully_fold (expr, false, &maybe_const);
    1355                 :         310 :       wrap &= maybe_const;
    1356                 :             :     }
    1357                 :             : 
    1358                 :         445 :   ret = build_call_expr_internal_loc (loc1, IFN_VEC_CONVERT, type, 1, expr);
    1359                 :             : 
    1360                 :         445 :   if (!wrap)
    1361                 :         310 :     ret = c_wrap_maybe_const (ret, true);
    1362                 :             : 
    1363                 :             :   return ret;
    1364                 :             : }
    1365                 :             : 
    1366                 :             : /* Like tree.cc:get_narrower, but retain conversion from C++0x scoped enum
    1367                 :             :    to integral type.  */
    1368                 :             : 
    1369                 :             : tree
    1370                 :    63911571 : c_common_get_narrower (tree op, int *unsignedp_ptr)
    1371                 :             : {
    1372                 :    63911571 :   op = get_narrower (op, unsignedp_ptr);
    1373                 :             : 
    1374                 :    63911571 :   if (TREE_CODE (TREE_TYPE (op)) == ENUMERAL_TYPE
    1375                 :    63911571 :       && ENUM_IS_SCOPED (TREE_TYPE (op)))
    1376                 :             :     {
    1377                 :             :       /* C++0x scoped enumerations don't implicitly convert to integral
    1378                 :             :          type; if we stripped an explicit conversion to a larger type we
    1379                 :             :          need to replace it so common_type will still work.  */
    1380                 :     2546927 :       tree type = c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op)),
    1381                 :     2546927 :                                           TYPE_UNSIGNED (TREE_TYPE (op)));
    1382                 :     2546927 :       op = fold_convert (type, op);
    1383                 :             :     }
    1384                 :    63911571 :   return op;
    1385                 :             : }
    1386                 :             : 
    1387                 :             : /* This is a helper function of build_binary_op.
    1388                 :             : 
    1389                 :             :    For certain operations if both args were extended from the same
    1390                 :             :    smaller type, do the arithmetic in that type and then extend.
    1391                 :             : 
    1392                 :             :    BITWISE indicates a bitwise operation.
    1393                 :             :    For them, this optimization is safe only if
    1394                 :             :    both args are zero-extended or both are sign-extended.
    1395                 :             :    Otherwise, we might change the result.
    1396                 :             :    Eg, (short)-1 | (unsigned short)-1 is (int)-1
    1397                 :             :    but calculated in (unsigned short) it would be (unsigned short)-1.
    1398                 :             : */
    1399                 :             : tree
    1400                 :     5172784 : shorten_binary_op (tree result_type, tree op0, tree op1, bool bitwise)
    1401                 :             : {
    1402                 :     5172784 :   int unsigned0, unsigned1;
    1403                 :     5172784 :   tree arg0, arg1;
    1404                 :     5172784 :   int uns;
    1405                 :     5172784 :   tree type;
    1406                 :             : 
    1407                 :             :   /* Do not shorten vector operations.  */
    1408                 :     5172784 :   if (VECTOR_TYPE_P (result_type))
    1409                 :             :     return result_type;
    1410                 :             : 
    1411                 :             :   /* Cast OP0 and OP1 to RESULT_TYPE.  Doing so prevents
    1412                 :             :      excessive narrowing when we call get_narrower below.  For
    1413                 :             :      example, suppose that OP0 is of unsigned int extended
    1414                 :             :      from signed char and that RESULT_TYPE is long long int.
    1415                 :             :      If we explicitly cast OP0 to RESULT_TYPE, OP0 would look
    1416                 :             :      like
    1417                 :             : 
    1418                 :             :      (long long int) (unsigned int) signed_char
    1419                 :             : 
    1420                 :             :      which get_narrower would narrow down to
    1421                 :             : 
    1422                 :             :      (unsigned int) signed char
    1423                 :             : 
    1424                 :             :      If we do not cast OP0 first, get_narrower would return
    1425                 :             :      signed_char, which is inconsistent with the case of the
    1426                 :             :      explicit cast.  */
    1427                 :     5155181 :   op0 = convert (result_type, op0);
    1428                 :     5155181 :   op1 = convert (result_type, op1);
    1429                 :             : 
    1430                 :     5155181 :   arg0 = c_common_get_narrower (op0, &unsigned0);
    1431                 :     5155181 :   arg1 = c_common_get_narrower (op1, &unsigned1);
    1432                 :             : 
    1433                 :             :   /* UNS is 1 if the operation to be done is an unsigned one.  */
    1434                 :     5155181 :   uns = TYPE_UNSIGNED (result_type);
    1435                 :             : 
    1436                 :             :   /* Handle the case that OP0 (or OP1) does not *contain* a conversion
    1437                 :             :      but it *requires* conversion to FINAL_TYPE.  */
    1438                 :             : 
    1439                 :     5155181 :   if ((TYPE_PRECISION (TREE_TYPE (op0))
    1440                 :     5155181 :        == TYPE_PRECISION (TREE_TYPE (arg0)))
    1441                 :     5155181 :       && TREE_TYPE (op0) != result_type)
    1442                 :        2353 :     unsigned0 = TYPE_UNSIGNED (TREE_TYPE (op0));
    1443                 :     5155181 :   if ((TYPE_PRECISION (TREE_TYPE (op1))
    1444                 :     5155181 :        == TYPE_PRECISION (TREE_TYPE (arg1)))
    1445                 :     5155181 :       && TREE_TYPE (op1) != result_type)
    1446                 :      229061 :     unsigned1 = TYPE_UNSIGNED (TREE_TYPE (op1));
    1447                 :             : 
    1448                 :             :   /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE.  */
    1449                 :             : 
    1450                 :             :   /* For bitwise operations, signedness of nominal type
    1451                 :             :      does not matter.  Consider only how operands were extended.  */
    1452                 :     5155181 :   if (bitwise)
    1453                 :     2491864 :     uns = unsigned0;
    1454                 :             : 
    1455                 :             :   /* Note that in all three cases below we refrain from optimizing
    1456                 :             :      an unsigned operation on sign-extended args.
    1457                 :             :      That would not be valid.  */
    1458                 :             : 
    1459                 :             :   /* Both args variable: if both extended in same way
    1460                 :             :      from same width, do it in that width.
    1461                 :             :      Do it unsigned if args were zero-extended.  */
    1462                 :     5155181 :   if ((TYPE_PRECISION (TREE_TYPE (arg0))
    1463                 :     5155181 :        < TYPE_PRECISION (result_type))
    1464                 :      274114 :       && (TYPE_PRECISION (TREE_TYPE (arg1))
    1465                 :      274114 :           == TYPE_PRECISION (TREE_TYPE (arg0)))
    1466                 :      183230 :       && unsigned0 == unsigned1
    1467                 :     5338217 :       && (unsigned0 || !uns))
    1468                 :             :     {
    1469                 :      183018 :       tree ctype = common_type (TREE_TYPE (arg0), TREE_TYPE (arg1));
    1470                 :      183018 :       if (ctype != error_mark_node)
    1471                 :      183018 :         return c_common_signed_or_unsigned_type (unsigned0, ctype);
    1472                 :             :     }
    1473                 :             : 
    1474                 :     4972163 :   else if (TREE_CODE (arg0) == INTEGER_CST
    1475                 :     1765400 :            && (unsigned1 || !uns)
    1476                 :     1507170 :            && (TYPE_PRECISION (TREE_TYPE (arg1))
    1477                 :     1507170 :                < TYPE_PRECISION (result_type))
    1478                 :         280 :            && (type
    1479                 :         280 :                = c_common_signed_or_unsigned_type (unsigned1,
    1480                 :         280 :                                                    TREE_TYPE (arg1)))
    1481                 :         280 :            && !POINTER_TYPE_P (type)
    1482                 :     4972443 :            && int_fits_type_p (arg0, type))
    1483                 :             :     return type;
    1484                 :             : 
    1485                 :     4971933 :   else if (TREE_CODE (arg1) == INTEGER_CST
    1486                 :     3216790 :            && (unsigned0 || !uns)
    1487                 :     2445947 :            && (TYPE_PRECISION (TREE_TYPE (arg0))
    1488                 :     2445947 :                < TYPE_PRECISION (result_type))
    1489                 :       67480 :            && (type
    1490                 :       67480 :                = c_common_signed_or_unsigned_type (unsigned0,
    1491                 :       67480 :                                                    TREE_TYPE (arg0)))
    1492                 :       67480 :            && !POINTER_TYPE_P (type)
    1493                 :     5039413 :            && int_fits_type_p (arg1, type))
    1494                 :             :     return type;
    1495                 :             : 
    1496                 :             :   return result_type;
    1497                 :             : }
    1498                 :             : 
    1499                 :             : /* Returns true iff any integer value of type FROM_TYPE can be represented as
    1500                 :             :    real of type TO_TYPE.  This is a helper function for unsafe_conversion_p.  */
    1501                 :             : 
    1502                 :             : static bool
    1503                 :         101 : int_safely_convertible_to_real_p (const_tree from_type, const_tree to_type)
    1504                 :             : {
    1505                 :         101 :   tree type_low_bound = TYPE_MIN_VALUE (from_type);
    1506                 :         101 :   tree type_high_bound = TYPE_MAX_VALUE (from_type);
    1507                 :         101 :   REAL_VALUE_TYPE real_low_bound =
    1508                 :         101 :           real_value_from_int_cst (0, type_low_bound);
    1509                 :         101 :   REAL_VALUE_TYPE real_high_bound =
    1510                 :         101 :           real_value_from_int_cst (0, type_high_bound);
    1511                 :             : 
    1512                 :         101 :   return exact_real_truncate (TYPE_MODE (to_type), &real_low_bound)
    1513                 :         101 :          && exact_real_truncate (TYPE_MODE (to_type), &real_high_bound);
    1514                 :             : }
    1515                 :             : 
    1516                 :             : /* Checks if expression EXPR of complex/real/integer type cannot be converted
    1517                 :             :    to the complex/real/integer type TYPE.  Function returns non-zero when:
    1518                 :             :         * EXPR is a constant which cannot be exactly converted to TYPE.
    1519                 :             :         * EXPR is not a constant and size of EXPR's type > than size of TYPE,
    1520                 :             :           for EXPR type and TYPE being both integers or both real, or both
    1521                 :             :           complex.
    1522                 :             :         * EXPR is not a constant of complex type and TYPE is a real or
    1523                 :             :           an integer.
    1524                 :             :         * EXPR is not a constant of real type and TYPE is an integer.
    1525                 :             :         * EXPR is not a constant of integer type which cannot be
    1526                 :             :           exactly converted to real type.
    1527                 :             : 
    1528                 :             :    Function allows conversions between types of different signedness if
    1529                 :             :    CHECK_SIGN is false and can return SAFE_CONVERSION (zero) in that
    1530                 :             :    case.  Function can return UNSAFE_SIGN if CHECK_SIGN is true.
    1531                 :             : 
    1532                 :             :    RESULT, when non-null is the result of the conversion.  When constant
    1533                 :             :    it is included in the text of diagnostics.
    1534                 :             : 
    1535                 :             :    Function allows conversions from complex constants to non-complex types,
    1536                 :             :    provided that imaginary part is zero and real part can be safely converted
    1537                 :             :    to TYPE.  */
    1538                 :             : 
    1539                 :             : enum conversion_safety
    1540                 :        9373 : unsafe_conversion_p (tree type, tree expr, tree result, bool check_sign)
    1541                 :             : {
    1542                 :        9373 :   enum conversion_safety give_warning = SAFE_CONVERSION; /* is 0 or false */
    1543                 :        9373 :   tree expr_type = TREE_TYPE (expr);
    1544                 :             : 
    1545                 :        9373 :   expr = fold_for_warn (expr);
    1546                 :             : 
    1547                 :        9373 :   if (TREE_CODE (expr) == REAL_CST || TREE_CODE (expr) == INTEGER_CST)
    1548                 :             :     {
    1549                 :             :       /* If type is complex, we are interested in compatibility with
    1550                 :             :          underlying type.  */
    1551                 :        5380 :       if (TREE_CODE (type) == COMPLEX_TYPE)
    1552                 :         114 :           type = TREE_TYPE (type);
    1553                 :             : 
    1554                 :             :       /* Warn for real constant that is not an exact integer converted
    1555                 :             :          to integer type.  */
    1556                 :        5380 :       if (SCALAR_FLOAT_TYPE_P (expr_type)
    1557                 :         658 :           && (TREE_CODE (type) == INTEGER_TYPE
    1558                 :         658 :               || TREE_CODE (type) == BITINT_TYPE))
    1559                 :             :         {
    1560                 :         283 :           if (!real_isinteger (TREE_REAL_CST_PTR (expr), TYPE_MODE (expr_type)))
    1561                 :         275 :             give_warning = UNSAFE_REAL;
    1562                 :             :         }
    1563                 :             :       /* Warn for an integer constant that does not fit into integer type.  */
    1564                 :        5097 :       else if ((TREE_CODE (expr_type) == INTEGER_TYPE
    1565                 :        5097 :                 || TREE_CODE (expr_type) == BITINT_TYPE)
    1566                 :        4712 :                && (TREE_CODE (type) == INTEGER_TYPE
    1567                 :        4712 :                    || TREE_CODE (type) == BITINT_TYPE)
    1568                 :        3988 :                && !int_fits_type_p (expr, type))
    1569                 :             :         {
    1570                 :         995 :           if (TYPE_UNSIGNED (type) && !TYPE_UNSIGNED (expr_type)
    1571                 :         961 :               && tree_int_cst_sgn (expr) < 0)
    1572                 :             :             {
    1573                 :         264 :               if (check_sign)
    1574                 :        1834 :                 give_warning = UNSAFE_SIGN;
    1575                 :             :             }
    1576                 :         432 :           else if (!TYPE_UNSIGNED (type) && TYPE_UNSIGNED (expr_type))
    1577                 :             :             {
    1578                 :         335 :               if (check_sign)
    1579                 :        1834 :                 give_warning = UNSAFE_SIGN;
    1580                 :             :             }
    1581                 :             :           else
    1582                 :             :             give_warning = UNSAFE_OTHER;
    1583                 :             :         }
    1584                 :        4401 :       else if (SCALAR_FLOAT_TYPE_P (type))
    1585                 :             :         {
    1586                 :             :           /* Warn for an integer constant that does not fit into real type.  */
    1587                 :        1009 :           if (TREE_CODE (expr_type) == INTEGER_TYPE
    1588                 :             :               || TREE_CODE (expr_type) == BITINT_TYPE)
    1589                 :             :             {
    1590                 :         634 :               REAL_VALUE_TYPE a = real_value_from_int_cst (0, expr);
    1591                 :         634 :               if (!exact_real_truncate (TYPE_MODE (type), &a))
    1592                 :          53 :                 give_warning = UNSAFE_REAL;
    1593                 :             :             }
    1594                 :             :           /* Warn for a real constant that does not fit into a smaller
    1595                 :             :              real type.  */
    1596                 :         375 :           else if (SCALAR_FLOAT_TYPE_P (expr_type)
    1597                 :         375 :                    && TYPE_PRECISION (type) < TYPE_PRECISION (expr_type))
    1598                 :             :             {
    1599                 :         227 :               REAL_VALUE_TYPE a = TREE_REAL_CST (expr);
    1600                 :         227 :               if (!exact_real_truncate (TYPE_MODE (type), &a))
    1601                 :          65 :                 give_warning = UNSAFE_REAL;
    1602                 :             :             }
    1603                 :             :         }
    1604                 :             :     }
    1605                 :             : 
    1606                 :        3993 :   else if (TREE_CODE (expr) == COMPLEX_CST)
    1607                 :             :     {
    1608                 :          69 :       tree imag_part = TREE_IMAGPART (expr);
    1609                 :             :       /* Conversion from complex constant with zero imaginary part,
    1610                 :             :          perform check for conversion of real part.  */
    1611                 :          69 :       if ((TREE_CODE (imag_part) == REAL_CST
    1612                 :          29 :            && real_zerop (imag_part))
    1613                 :          80 :           || (TREE_CODE (imag_part) == INTEGER_CST
    1614                 :          40 :               && integer_zerop (imag_part)))
    1615                 :             :         /* Note: in this branch we use recursive call to unsafe_conversion_p
    1616                 :             :            with different type of EXPR, but it is still safe, because when EXPR
    1617                 :             :            is a constant, it's type is not used in text of generated warnings
    1618                 :             :            (otherwise they could sound misleading).  */
    1619                 :          30 :         return unsafe_conversion_p (type, TREE_REALPART (expr), result,
    1620                 :          30 :                                     check_sign);
    1621                 :             :       /* Conversion from complex constant with non-zero imaginary part.  */
    1622                 :             :       else
    1623                 :             :         {
    1624                 :             :           /* Conversion to complex type.
    1625                 :             :              Perform checks for both real and imaginary parts.  */
    1626                 :          39 :           if (TREE_CODE (type) == COMPLEX_TYPE)
    1627                 :             :             {
    1628                 :          33 :               enum conversion_safety re_safety =
    1629                 :          33 :                 unsafe_conversion_p (type, TREE_REALPART (expr),
    1630                 :             :                                      result, check_sign);
    1631                 :          33 :               enum conversion_safety im_safety =
    1632                 :          33 :                 unsafe_conversion_p (type, imag_part, result, check_sign);
    1633                 :             : 
    1634                 :             :               /* Merge the results into appropriate single warning.  */
    1635                 :             : 
    1636                 :             :               /* Note: this case includes SAFE_CONVERSION, i.e. success.  */
    1637                 :          33 :               if (re_safety == im_safety)
    1638                 :             :                 give_warning = re_safety;
    1639                 :           9 :               else if (!re_safety && im_safety)
    1640                 :             :                 give_warning = im_safety;
    1641                 :           4 :               else if (re_safety && !im_safety)
    1642                 :             :                 give_warning = re_safety;
    1643                 :             :               else
    1644                 :         670 :                 give_warning = UNSAFE_OTHER;
    1645                 :             :             }
    1646                 :             :           /* Warn about conversion from complex to real or integer type.  */
    1647                 :             :           else
    1648                 :             :             give_warning = UNSAFE_IMAGINARY;
    1649                 :             :         }
    1650                 :             :     }
    1651                 :             : 
    1652                 :             :   /* Checks for remaining case: EXPR is not constant.  */
    1653                 :             :   else
    1654                 :             :     {
    1655                 :             :       /* Warn for real types converted to integer types.  */
    1656                 :        3924 :       if (SCALAR_FLOAT_TYPE_P (expr_type)
    1657                 :         213 :           && (TREE_CODE (type) == INTEGER_TYPE
    1658                 :         213 :               || TREE_CODE (type) == BITINT_TYPE))
    1659                 :             :         give_warning = UNSAFE_REAL;
    1660                 :             : 
    1661                 :        3895 :       else if ((TREE_CODE (expr_type) == INTEGER_TYPE
    1662                 :        3895 :                 || TREE_CODE (expr_type) == BITINT_TYPE)
    1663                 :        3500 :                && (TREE_CODE (type) == INTEGER_TYPE
    1664                 :        3500 :                    || TREE_CODE (type) == BITINT_TYPE))
    1665                 :             :         {
    1666                 :             :           /* Don't warn about unsigned char y = 0xff, x = (int) y;  */
    1667                 :        3279 :           expr = get_unwidened (expr, 0);
    1668                 :        3279 :           expr_type = TREE_TYPE (expr);
    1669                 :             : 
    1670                 :             :           /* Don't warn for short y; short x = ((int)y & 0xff);  */
    1671                 :        3279 :           if (TREE_CODE (expr) == BIT_AND_EXPR
    1672                 :        3265 :               || TREE_CODE (expr) == BIT_IOR_EXPR
    1673                 :        3224 :               || TREE_CODE (expr) == BIT_XOR_EXPR)
    1674                 :             :             {
    1675                 :             :               /* If both args were extended from a shortest type,
    1676                 :             :                  use that type if that is safe.  */
    1677                 :          59 :               expr_type = shorten_binary_op (expr_type,
    1678                 :          59 :                                              TREE_OPERAND (expr, 0),
    1679                 :          59 :                                              TREE_OPERAND (expr, 1),
    1680                 :             :                                              /* bitwise */1);
    1681                 :             : 
    1682                 :          59 :               if (TREE_CODE (expr) == BIT_AND_EXPR)
    1683                 :             :                 {
    1684                 :          14 :                   tree op0 = TREE_OPERAND (expr, 0);
    1685                 :          14 :                   tree op1 = TREE_OPERAND (expr, 1);
    1686                 :          14 :                   bool unsigned0 = TYPE_UNSIGNED (TREE_TYPE (op0));
    1687                 :          14 :                   bool unsigned1 = TYPE_UNSIGNED (TREE_TYPE (op1));
    1688                 :             : 
    1689                 :             :                   /* If one of the operands is a non-negative constant
    1690                 :             :                      that fits in the target type, then the type of the
    1691                 :             :                      other operand does not matter. */
    1692                 :          14 :                   if ((TREE_CODE (op0) == INTEGER_CST
    1693                 :           0 :                        && int_fits_type_p (op0, c_common_signed_type (type))
    1694                 :           0 :                        && int_fits_type_p (op0, c_common_unsigned_type (type)))
    1695                 :          14 :                       || (TREE_CODE (op1) == INTEGER_CST
    1696                 :           1 :                           && int_fits_type_p (op1, c_common_signed_type (type))
    1697                 :           1 :                           && int_fits_type_p (op1,
    1698                 :           1 :                                               c_common_unsigned_type (type))))
    1699                 :           1 :                     return SAFE_CONVERSION;
    1700                 :             :                   /* If constant is unsigned and fits in the target
    1701                 :             :                      type, then the result will also fit.  */
    1702                 :          13 :                   else if ((TREE_CODE (op0) == INTEGER_CST
    1703                 :           0 :                             && unsigned0
    1704                 :           0 :                             && int_fits_type_p (op0, type))
    1705                 :          13 :                            || (TREE_CODE (op1) == INTEGER_CST
    1706                 :           0 :                                && unsigned1
    1707                 :           0 :                                && int_fits_type_p (op1, type)))
    1708                 :             :                     return SAFE_CONVERSION;
    1709                 :             :                 }
    1710                 :             :             }
    1711                 :             :           /* Warn for integer types converted to smaller integer types.  */
    1712                 :        3278 :           if (TYPE_PRECISION (type) < TYPE_PRECISION (expr_type))
    1713                 :             :             give_warning = UNSAFE_OTHER;
    1714                 :             : 
    1715                 :             :           /* When they are the same width but different signedness,
    1716                 :             :              then the value may change.  */
    1717                 :        2742 :           else if (((TYPE_PRECISION (type) == TYPE_PRECISION (expr_type)
    1718                 :        2213 :                      && TYPE_UNSIGNED (expr_type) != TYPE_UNSIGNED (type))
    1719                 :             :                     /* Even when converted to a bigger type, if the type is
    1720                 :             :                        unsigned but expr is signed, then negative values
    1721                 :             :                        will be changed.  */
    1722                 :        1481 :                     || (TYPE_UNSIGNED (type) && !TYPE_UNSIGNED (expr_type)))
    1723                 :        4054 :                    && check_sign)
    1724                 :             :             give_warning = UNSAFE_SIGN;
    1725                 :             :         }
    1726                 :             : 
    1727                 :             :       /* Warn for integer types converted to real types if and only if
    1728                 :             :          all the range of values of the integer type cannot be
    1729                 :             :          represented by the real type.  */
    1730                 :         616 :       else if ((TREE_CODE (expr_type) == INTEGER_TYPE
    1731                 :             :                 || TREE_CODE (expr_type) == BITINT_TYPE)
    1732                 :         221 :                && SCALAR_FLOAT_TYPE_P (type))
    1733                 :             :         {
    1734                 :             :           /* Don't warn about char y = 0xff; float x = (int) y;  */
    1735                 :         101 :           expr = get_unwidened (expr, 0);
    1736                 :         101 :           expr_type = TREE_TYPE (expr);
    1737                 :             : 
    1738                 :         101 :           if (!int_safely_convertible_to_real_p (expr_type, type))
    1739                 :         670 :             give_warning = UNSAFE_OTHER;
    1740                 :             :         }
    1741                 :             : 
    1742                 :             :       /* Warn for real types converted to smaller real types.  */
    1743                 :         515 :       else if (SCALAR_FLOAT_TYPE_P (expr_type)
    1744                 :         184 :                && SCALAR_FLOAT_TYPE_P (type)
    1745                 :         699 :                && TYPE_PRECISION (type) < TYPE_PRECISION (expr_type))
    1746                 :             :         give_warning = UNSAFE_REAL;
    1747                 :             : 
    1748                 :             :       /* Check conversion between two complex types.  */
    1749                 :         463 :       else if (TREE_CODE (expr_type) == COMPLEX_TYPE
    1750                 :          32 :                && TREE_CODE (type) == COMPLEX_TYPE)
    1751                 :             :         {
    1752                 :             :           /* Extract underlying types (i.e., type of real and imaginary
    1753                 :             :              parts) of expr_type and type.  */
    1754                 :          10 :           tree from_type = TREE_TYPE (expr_type);
    1755                 :          10 :           tree to_type = TREE_TYPE (type);
    1756                 :             : 
    1757                 :             :           /* Warn for real types converted to integer types.  */
    1758                 :          10 :           if (SCALAR_FLOAT_TYPE_P (from_type)
    1759                 :           8 :               && TREE_CODE (to_type) == INTEGER_TYPE)
    1760                 :             :             give_warning = UNSAFE_REAL;
    1761                 :             : 
    1762                 :             :           /* Warn for real types converted to smaller real types.  */
    1763                 :           6 :           else if (SCALAR_FLOAT_TYPE_P (from_type)
    1764                 :           4 :                    && SCALAR_FLOAT_TYPE_P (to_type)
    1765                 :          10 :                    && TYPE_PRECISION (to_type) < TYPE_PRECISION (from_type))
    1766                 :             :             give_warning = UNSAFE_REAL;
    1767                 :             : 
    1768                 :             :           /* Check conversion for complex integer types.  Here implementation
    1769                 :             :              is simpler than for real-domain integers because it does not
    1770                 :             :              involve sophisticated cases, such as bitmasks, casts, etc.  */
    1771                 :           4 :           else if (TREE_CODE (from_type) == INTEGER_TYPE
    1772                 :           2 :                    && TREE_CODE (to_type) == INTEGER_TYPE)
    1773                 :             :             {
    1774                 :             :               /* Warn for integer types converted to smaller integer types.  */
    1775                 :           2 :               if (TYPE_PRECISION (to_type) < TYPE_PRECISION (from_type))
    1776                 :             :                 give_warning = UNSAFE_OTHER;
    1777                 :             : 
    1778                 :             :               /* Check for different signedness, see case for real-domain
    1779                 :             :                  integers (above) for a more detailed comment.  */
    1780                 :           0 :               else if (((TYPE_PRECISION (to_type) == TYPE_PRECISION (from_type)
    1781                 :           0 :                          && TYPE_UNSIGNED (to_type) != TYPE_UNSIGNED (from_type))
    1782                 :           0 :                         || (TYPE_UNSIGNED (to_type) && !TYPE_UNSIGNED (from_type)))
    1783                 :           0 :                        && check_sign)
    1784                 :             :                 give_warning = UNSAFE_SIGN;
    1785                 :             :             }
    1786                 :           2 :           else if (TREE_CODE (from_type) == INTEGER_TYPE
    1787                 :           0 :                    && SCALAR_FLOAT_TYPE_P (to_type)
    1788                 :           2 :                    && !int_safely_convertible_to_real_p (from_type, to_type))
    1789                 :             :             give_warning = UNSAFE_OTHER;
    1790                 :             :         }
    1791                 :             : 
    1792                 :             :       /* Warn for complex types converted to real or integer types.  */
    1793                 :         453 :       else if (TREE_CODE (expr_type) == COMPLEX_TYPE
    1794                 :          22 :                && TREE_CODE (type) != COMPLEX_TYPE)
    1795                 :          28 :         give_warning = UNSAFE_IMAGINARY;
    1796                 :             :     }
    1797                 :             : 
    1798                 :             :   return give_warning;
    1799                 :             : }
    1800                 :             : 
    1801                 :             : 
    1802                 :             : /* Convert EXPR to TYPE, warning about conversion problems with constants.
    1803                 :             :    Invoke this function on every expression that is converted implicitly,
    1804                 :             :    i.e. because of language rules and not because of an explicit cast.
    1805                 :             :    INIT_CONST is true if the conversion is for arithmetic types for a static
    1806                 :             :    initializer and folding must apply accordingly (discarding floating-point
    1807                 :             :    exceptions and assuming the default rounding mode is in effect).  */
    1808                 :             : 
    1809                 :             : tree
    1810                 :    12332218 : convert_and_check (location_t loc, tree type, tree expr, bool init_const)
    1811                 :             : {
    1812                 :    12332218 :   tree result;
    1813                 :    12332218 :   tree expr_for_warning;
    1814                 :             : 
    1815                 :             :   /* Convert from a value with possible excess precision rather than
    1816                 :             :      via the semantic type, but do not warn about values not fitting
    1817                 :             :      exactly in the semantic type.  */
    1818                 :    12332218 :   if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
    1819                 :             :     {
    1820                 :        5963 :       tree orig_type = TREE_TYPE (expr);
    1821                 :        5963 :       expr = TREE_OPERAND (expr, 0);
    1822                 :        5963 :       expr_for_warning = (init_const
    1823                 :        5963 :                           ? convert_init (orig_type, expr)
    1824                 :        5602 :                           : convert (orig_type, expr));
    1825                 :        5963 :       if (orig_type == type)
    1826                 :             :         return expr_for_warning;
    1827                 :             :     }
    1828                 :             :   else
    1829                 :             :     expr_for_warning = expr;
    1830                 :             : 
    1831                 :    12326748 :   if (TREE_TYPE (expr) == type)
    1832                 :             :     return expr;
    1833                 :             : 
    1834                 :    10919522 :   result = init_const ? convert_init (type, expr) : convert (type, expr);
    1835                 :             : 
    1836                 :    10919522 :   if (c_inhibit_evaluation_warnings == 0
    1837                 :    10593165 :       && !TREE_OVERFLOW_P (expr)
    1838                 :    10593139 :       && result != error_mark_node
    1839                 :    21512507 :       && !c_hardbool_type_attr (type))
    1840                 :    10589345 :     warnings_for_convert_and_check (loc, type, expr_for_warning, result);
    1841                 :             : 
    1842                 :             :   return result;
    1843                 :             : }
    1844                 :             : 
    1845                 :             : /* A node in a list that describes references to variables (EXPR), which are
    1846                 :             :    either read accesses if WRITER is zero, or write accesses, in which case
    1847                 :             :    WRITER is the parent of EXPR.  */
    1848                 :             : struct tlist
    1849                 :             : {
    1850                 :             :   struct tlist *next;
    1851                 :             :   tree expr, writer;
    1852                 :             : };
    1853                 :             : 
    1854                 :             : /* Used to implement a cache the results of a call to verify_tree.  We only
    1855                 :             :    use this for SAVE_EXPRs.  */
    1856                 :             : struct tlist_cache
    1857                 :             : {
    1858                 :             :   struct tlist_cache *next;
    1859                 :             :   struct tlist *cache_before_sp;
    1860                 :             :   struct tlist *cache_after_sp;
    1861                 :             :   tree expr;
    1862                 :             : };
    1863                 :             : 
    1864                 :             : /* Obstack to use when allocating tlist structures, and corresponding
    1865                 :             :    firstobj.  */
    1866                 :             : static struct obstack tlist_obstack;
    1867                 :             : static char *tlist_firstobj = 0;
    1868                 :             : 
    1869                 :             : /* Keep track of the identifiers we've warned about, so we can avoid duplicate
    1870                 :             :    warnings.  */
    1871                 :             : static struct tlist *warned_ids;
    1872                 :             : /* SAVE_EXPRs need special treatment.  We process them only once and then
    1873                 :             :    cache the results.  */
    1874                 :             : static struct tlist_cache *save_expr_cache;
    1875                 :             : 
    1876                 :             : static void add_tlist (struct tlist **, struct tlist *, tree, int);
    1877                 :             : static void merge_tlist (struct tlist **, struct tlist *, int);
    1878                 :             : static void verify_tree (tree, struct tlist **, struct tlist **, tree);
    1879                 :             : static bool warning_candidate_p (tree);
    1880                 :             : static bool candidate_equal_p (const_tree, const_tree);
    1881                 :             : static void warn_for_collisions (struct tlist *);
    1882                 :             : static void warn_for_collisions_1 (tree, tree, struct tlist *, int);
    1883                 :             : static struct tlist *new_tlist (struct tlist *, tree, tree);
    1884                 :             : 
    1885                 :             : /* Create a new struct tlist and fill in its fields.  */
    1886                 :             : static struct tlist *
    1887                 :    34245850 : new_tlist (struct tlist *next, tree t, tree writer)
    1888                 :             : {
    1889                 :    34245850 :   struct tlist *l;
    1890                 :    34245850 :   l = XOBNEW (&tlist_obstack, struct tlist);
    1891                 :    34245850 :   l->next = next;
    1892                 :    34245850 :   l->expr = t;
    1893                 :    34245850 :   l->writer = writer;
    1894                 :    34245850 :   return l;
    1895                 :             : }
    1896                 :             : 
    1897                 :             : /* Add duplicates of the nodes found in ADD to the list *TO.  If EXCLUDE_WRITER
    1898                 :             :    is nonnull, we ignore any node we find which has a writer equal to it.  */
    1899                 :             : 
    1900                 :             : static void
    1901                 :    60422565 : add_tlist (struct tlist **to, struct tlist *add, tree exclude_writer, int copy)
    1902                 :             : {
    1903                 :   131420049 :   while (add)
    1904                 :             :     {
    1905                 :    70997484 :       struct tlist *next = add->next;
    1906                 :    13181087 :       if (!copy)
    1907                 :     1894508 :         add->next = *to;
    1908                 :    13181087 :       if (!exclude_writer || !candidate_equal_p (add->writer, exclude_writer))
    1909                 :    68927614 :         *to = copy ? new_tlist (*to, add->expr, add->writer) : add;
    1910                 :             :       add = next;
    1911                 :             :     }
    1912                 :    11902769 : }
    1913                 :             : 
    1914                 :             : /* Merge the nodes of ADD into TO.  This merging process is done so that for
    1915                 :             :    each variable that already exists in TO, no new node is added; however if
    1916                 :             :    there is a write access recorded in ADD, and an occurrence on TO is only
    1917                 :             :    a read access, then the occurrence in TO will be modified to record the
    1918                 :             :    write.  */
    1919                 :             : 
    1920                 :             : static void
    1921                 :    42160984 : merge_tlist (struct tlist **to, struct tlist *add, int copy)
    1922                 :             : {
    1923                 :    42160984 :   struct tlist **end = to;
    1924                 :             : 
    1925                 :    78652214 :   while (*end)
    1926                 :    36491230 :     end = &(*end)->next;
    1927                 :             : 
    1928                 :    57937508 :   while (add)
    1929                 :             :     {
    1930                 :    15776524 :       int found = 0;
    1931                 :    15776524 :       struct tlist *tmp2;
    1932                 :    15776524 :       struct tlist *next = add->next;
    1933                 :             : 
    1934                 :    42994126 :       for (tmp2 = *to; tmp2; tmp2 = tmp2->next)
    1935                 :    27217602 :         if (candidate_equal_p (tmp2->expr, add->expr))
    1936                 :             :           {
    1937                 :     2687962 :             found = 1;
    1938                 :     2687962 :             if (!tmp2->writer)
    1939                 :     2681810 :               tmp2->writer = add->writer;
    1940                 :             :           }
    1941                 :    15776524 :       if (!found)
    1942                 :             :         {
    1943                 :    13102167 :           *end = copy ? new_tlist (NULL, add->expr, add->writer) : add;
    1944                 :    13102167 :           end = &(*end)->next;
    1945                 :    13102167 :           *end = 0;
    1946                 :             :         }
    1947                 :             :       add = next;
    1948                 :             :     }
    1949                 :    42160984 : }
    1950                 :             : 
    1951                 :             : /* WRITTEN is a variable, WRITER is its parent.  Warn if any of the variable
    1952                 :             :    references in list LIST conflict with it, excluding reads if ONLY writers
    1953                 :             :    is nonzero.  */
    1954                 :             : 
    1955                 :             : static void
    1956                 :     5296788 : warn_for_collisions_1 (tree written, tree writer, struct tlist *list,
    1957                 :             :                        int only_writes)
    1958                 :             : {
    1959                 :     5296788 :   struct tlist *tmp;
    1960                 :             : 
    1961                 :             :   /* Avoid duplicate warnings.  */
    1962                 :     5296951 :   for (tmp = warned_ids; tmp; tmp = tmp->next)
    1963                 :         611 :     if (candidate_equal_p (tmp->expr, written))
    1964                 :             :       return;
    1965                 :             : 
    1966                 :    18852936 :   while (list)
    1967                 :             :     {
    1968                 :    13556596 :       if (candidate_equal_p (list->expr, written)
    1969                 :     1562558 :           && !candidate_equal_p (list->writer, writer)
    1970                 :    13695429 :           && (!only_writes || list->writer))
    1971                 :             :         {
    1972                 :         562 :           warned_ids = new_tlist (warned_ids, written, NULL_TREE);
    1973                 :         562 :           warning_at (EXPR_LOC_OR_LOC (writer, input_location),
    1974                 :         562 :                       OPT_Wsequence_point, "operation on %qE may be undefined",
    1975                 :             :                       list->expr);
    1976                 :             :         }
    1977                 :    13556596 :       list = list->next;
    1978                 :             :     }
    1979                 :             : }
    1980                 :             : 
    1981                 :             : /* Given a list LIST of references to variables, find whether any of these
    1982                 :             :    can cause conflicts due to missing sequence points.  */
    1983                 :             : 
    1984                 :             : static void
    1985                 :    19906087 : warn_for_collisions (struct tlist *list)
    1986                 :             : {
    1987                 :    19906087 :   struct tlist *tmp;
    1988                 :             : 
    1989                 :    54752842 :   for (tmp = list; tmp; tmp = tmp->next)
    1990                 :             :     {
    1991                 :    34846755 :       if (tmp->writer)
    1992                 :     1361962 :         warn_for_collisions_1 (tmp->expr, tmp->writer, list, 0);
    1993                 :             :     }
    1994                 :    19906087 : }
    1995                 :             : 
    1996                 :             : /* Return nonzero if X is a tree that can be verified by the sequence point
    1997                 :             :    warnings.  */
    1998                 :             : 
    1999                 :             : static bool
    2000                 :    76132539 : warning_candidate_p (tree x)
    2001                 :             : {
    2002                 :    76132539 :   if (DECL_P (x) && DECL_ARTIFICIAL (x))
    2003                 :             :     return false;
    2004                 :             : 
    2005                 :    68497961 :   if (TREE_CODE (x) == BLOCK)
    2006                 :             :     return false;
    2007                 :             : 
    2008                 :             :   /* VOID_TYPE_P (TREE_TYPE (x)) is workaround for cp/tree.cc
    2009                 :             :      (lvalue_p) crash on TRY/CATCH. */
    2010                 :    68495830 :   if (TREE_TYPE (x) == NULL_TREE || VOID_TYPE_P (TREE_TYPE (x)))
    2011                 :             :     return false;
    2012                 :             : 
    2013                 :    67582598 :   if (!lvalue_p (x))
    2014                 :             :     return false;
    2015                 :             : 
    2016                 :             :   /* No point to track non-const calls, they will never satisfy
    2017                 :             :      operand_equal_p.  */
    2018                 :    24318357 :   if (TREE_CODE (x) == CALL_EXPR && (call_expr_flags (x) & ECF_CONST) == 0)
    2019                 :             :     return false;
    2020                 :             : 
    2021                 :    24278424 :   if (TREE_CODE (x) == STRING_CST)
    2022                 :             :     return false;
    2023                 :             : 
    2024                 :             :   return true;
    2025                 :             : }
    2026                 :             : 
    2027                 :             : /* Return nonzero if X and Y appear to be the same candidate (or NULL) */
    2028                 :             : static bool
    2029                 :    46180039 : candidate_equal_p (const_tree x, const_tree y)
    2030                 :             : {
    2031                 :    46180039 :   return (x == y) || (x && y && operand_equal_p (x, y, 0));
    2032                 :             : }
    2033                 :             : 
    2034                 :             : /* Walk the tree X, and record accesses to variables.  If X is written by the
    2035                 :             :    parent tree, WRITER is the parent.
    2036                 :             :    We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP.  If this
    2037                 :             :    expression or its only operand forces a sequence point, then everything up
    2038                 :             :    to the sequence point is stored in PBEFORE_SP.  Everything else gets stored
    2039                 :             :    in PNO_SP.
    2040                 :             :    Once we return, we will have emitted warnings if any subexpression before
    2041                 :             :    such a sequence point could be undefined.  On a higher level, however, the
    2042                 :             :    sequence point may not be relevant, and we'll merge the two lists.
    2043                 :             : 
    2044                 :             :    Example: (b++, a) + b;
    2045                 :             :    The call that processes the COMPOUND_EXPR will store the increment of B
    2046                 :             :    in PBEFORE_SP, and the use of A in PNO_SP.  The higher-level call that
    2047                 :             :    processes the PLUS_EXPR will need to merge the two lists so that
    2048                 :             :    eventually, all accesses end up on the same list (and we'll warn about the
    2049                 :             :    unordered subexpressions b++ and b.
    2050                 :             : 
    2051                 :             :    A note on merging.  If we modify the former example so that our expression
    2052                 :             :    becomes
    2053                 :             :      (b++, b) + a
    2054                 :             :    care must be taken not simply to add all three expressions into the final
    2055                 :             :    PNO_SP list.  The function merge_tlist takes care of that by merging the
    2056                 :             :    before-SP list of the COMPOUND_EXPR into its after-SP list in a special
    2057                 :             :    way, so that no more than one access to B is recorded.  */
    2058                 :             : 
    2059                 :             : static void
    2060                 :    59828669 : verify_tree (tree x, struct tlist **pbefore_sp, struct tlist **pno_sp,
    2061                 :             :              tree writer)
    2062                 :             : {
    2063                 :    73372660 :   struct tlist *tmp_before, *tmp_nosp, *tmp_list2, *tmp_list3;
    2064                 :    73372660 :   enum tree_code code;
    2065                 :    73372660 :   enum tree_code_class cl;
    2066                 :             : 
    2067                 :    73372660 :  restart:
    2068                 :             :   /* X may be NULL if it is the operand of an empty statement expression
    2069                 :             :      ({ }).  */
    2070                 :    73372660 :   if (x == NULL)
    2071                 :             :     return;
    2072                 :             : 
    2073                 :    72197713 :   code = TREE_CODE (x);
    2074                 :    72197713 :   cl = TREE_CODE_CLASS (code);
    2075                 :             : 
    2076                 :    72197713 :   if (warning_candidate_p (x))
    2077                 :    23015563 :     *pno_sp = new_tlist (*pno_sp, x, writer);
    2078                 :             : 
    2079                 :    72197713 :   switch (code)
    2080                 :             :     {
    2081                 :             :     case CONSTRUCTOR:
    2082                 :             :     case SIZEOF_EXPR:
    2083                 :             :     case PAREN_SIZEOF_EXPR:
    2084                 :             :       return;
    2085                 :             : 
    2086                 :      196570 :     case COMPOUND_EXPR:
    2087                 :      196570 :     case TRUTH_ANDIF_EXPR:
    2088                 :      196570 :     case TRUTH_ORIF_EXPR:
    2089                 :      196570 :     sequenced_binary:
    2090                 :      196570 :       tmp_before = tmp_nosp = tmp_list2 = tmp_list3 = 0;
    2091                 :      196570 :       verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE);
    2092                 :      196570 :       warn_for_collisions (tmp_nosp);
    2093                 :      196570 :       merge_tlist (pbefore_sp, tmp_before, 0);
    2094                 :      196570 :       merge_tlist (pbefore_sp, tmp_nosp, 0);
    2095                 :      196570 :       verify_tree (TREE_OPERAND (x, 1), &tmp_list3, &tmp_list2, NULL_TREE);
    2096                 :      196570 :       warn_for_collisions (tmp_list2);
    2097                 :      196570 :       merge_tlist (pbefore_sp, tmp_list3, 0);
    2098                 :      196570 :       merge_tlist (pno_sp, tmp_list2, 0);
    2099                 :      196570 :       return;
    2100                 :             : 
    2101                 :       66798 :     case COND_EXPR:
    2102                 :       66798 :       tmp_before = tmp_list2 = 0;
    2103                 :       66798 :       verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_list2, NULL_TREE);
    2104                 :       66798 :       warn_for_collisions (tmp_list2);
    2105                 :       66798 :       merge_tlist (pbefore_sp, tmp_before, 0);
    2106                 :       66798 :       merge_tlist (pbefore_sp, tmp_list2, 0);
    2107                 :             : 
    2108                 :       66798 :       tmp_list3 = tmp_nosp = 0;
    2109                 :       66798 :       verify_tree (TREE_OPERAND (x, 1), &tmp_list3, &tmp_nosp, NULL_TREE);
    2110                 :       66798 :       warn_for_collisions (tmp_nosp);
    2111                 :       66798 :       merge_tlist (pbefore_sp, tmp_list3, 0);
    2112                 :             : 
    2113                 :       66798 :       tmp_list3 = tmp_list2 = 0;
    2114                 :       66798 :       verify_tree (TREE_OPERAND (x, 2), &tmp_list3, &tmp_list2, NULL_TREE);
    2115                 :       66798 :       warn_for_collisions (tmp_list2);
    2116                 :       66798 :       merge_tlist (pbefore_sp, tmp_list3, 0);
    2117                 :             :       /* Rather than add both tmp_nosp and tmp_list2, we have to merge the
    2118                 :             :          two first, to avoid warning for (a ? b++ : b++).  */
    2119                 :       66798 :       merge_tlist (&tmp_nosp, tmp_list2, 0);
    2120                 :       66798 :       add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
    2121                 :             :       return;
    2122                 :             : 
    2123                 :      266917 :     case PREDECREMENT_EXPR:
    2124                 :      266917 :     case PREINCREMENT_EXPR:
    2125                 :      266917 :     case POSTDECREMENT_EXPR:
    2126                 :      266917 :     case POSTINCREMENT_EXPR:
    2127                 :      266917 :       verify_tree (TREE_OPERAND (x, 0), pno_sp, pno_sp, x);
    2128                 :      266917 :       return;
    2129                 :             : 
    2130                 :     3934826 :     case MODIFY_EXPR:
    2131                 :     3934826 :       tmp_before = tmp_nosp = tmp_list3 = 0;
    2132                 :     3934826 :       verify_tree (TREE_OPERAND (x, 1), &tmp_before, &tmp_nosp, NULL_TREE);
    2133                 :     3934826 :       verify_tree (TREE_OPERAND (x, 0), &tmp_list3, &tmp_list3, x);
    2134                 :             :       /* Expressions inside the LHS are not ordered wrt. the sequence points
    2135                 :             :          in the RHS.  Example:
    2136                 :             :            *a = (a++, 2)
    2137                 :             :          Despite the fact that the modification of "a" is in the before_sp
    2138                 :             :          list (tmp_before), it conflicts with the use of "a" in the LHS.
    2139                 :             :          We can handle this by adding the contents of tmp_list3
    2140                 :             :          to those of tmp_before, and redoing the collision warnings for that
    2141                 :             :          list.  */
    2142                 :     3934826 :       add_tlist (&tmp_before, tmp_list3, x, 1);
    2143                 :     3934826 :       warn_for_collisions (tmp_before);
    2144                 :             :       /* Exclude the LHS itself here; we first have to merge it into the
    2145                 :             :          tmp_nosp list.  This is done to avoid warning for "a = a"; if we
    2146                 :             :          didn't exclude the LHS, we'd get it twice, once as a read and once
    2147                 :             :          as a write.  */
    2148                 :     3934826 :       add_tlist (pno_sp, tmp_list3, x, 0);
    2149                 :     3934826 :       warn_for_collisions_1 (TREE_OPERAND (x, 0), x, tmp_nosp, 1);
    2150                 :             : 
    2151                 :     3934826 :       merge_tlist (pbefore_sp, tmp_before, 0);
    2152                 :     3934826 :       if (warning_candidate_p (TREE_OPERAND (x, 0)))
    2153                 :      971508 :         merge_tlist (&tmp_nosp, new_tlist (NULL, TREE_OPERAND (x, 0), x), 0);
    2154                 :     3934826 :       add_tlist (pno_sp, tmp_nosp, NULL_TREE, 1);
    2155                 :     3934826 :       return;
    2156                 :             : 
    2157                 :     6232621 :     case CALL_EXPR:
    2158                 :             :       /* We need to warn about conflicts among arguments and conflicts between
    2159                 :             :          args and the function address.  Side effects of the function address,
    2160                 :             :          however, are not ordered by the sequence point of the call.  */
    2161                 :     6232621 :       {
    2162                 :     6232621 :         call_expr_arg_iterator iter;
    2163                 :     6232621 :         tree arg;
    2164                 :     6232621 :         tmp_before = tmp_nosp = 0;
    2165                 :     6232621 :         verify_tree (CALL_EXPR_FN (x), &tmp_before, &tmp_nosp, NULL_TREE);
    2166                 :    27688180 :         FOR_EACH_CALL_EXPR_ARG (arg, iter, x)
    2167                 :             :           {
    2168                 :    15222938 :             tmp_list2 = tmp_list3 = 0;
    2169                 :    15222938 :             verify_tree (arg, &tmp_list2, &tmp_list3, NULL_TREE);
    2170                 :    15222938 :             merge_tlist (&tmp_list3, tmp_list2, 0);
    2171                 :    30445876 :             add_tlist (&tmp_before, tmp_list3, NULL_TREE, 0);
    2172                 :             :           }
    2173                 :     6232621 :         add_tlist (&tmp_before, tmp_nosp, NULL_TREE, 0);
    2174                 :     6232621 :         warn_for_collisions (tmp_before);
    2175                 :     6232621 :         add_tlist (pbefore_sp, tmp_before, NULL_TREE, 0);
    2176                 :     6232621 :         return;
    2177                 :             :       }
    2178                 :             : 
    2179                 :             :     case TREE_LIST:
    2180                 :             :       /* Scan all the list, e.g. indices of multi dimensional array.  */
    2181                 :           6 :       while (x)
    2182                 :             :         {
    2183                 :           3 :           tmp_before = tmp_nosp = 0;
    2184                 :           3 :           verify_tree (TREE_VALUE (x), &tmp_before, &tmp_nosp, NULL_TREE);
    2185                 :           3 :           merge_tlist (&tmp_nosp, tmp_before, 0);
    2186                 :           3 :           add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
    2187                 :           3 :           x = TREE_CHAIN (x);
    2188                 :             :         }
    2189                 :             :       return;
    2190                 :             : 
    2191                 :       98291 :     case SAVE_EXPR:
    2192                 :       98291 :       {
    2193                 :       98291 :         struct tlist_cache *t;
    2194                 :      101989 :         for (t = save_expr_cache; t; t = t->next)
    2195                 :       53656 :           if (candidate_equal_p (t->expr, x))
    2196                 :             :             break;
    2197                 :             : 
    2198                 :       98291 :         if (!t)
    2199                 :             :           {
    2200                 :       48333 :             t = XOBNEW (&tlist_obstack, struct tlist_cache);
    2201                 :       48333 :             t->next = save_expr_cache;
    2202                 :       48333 :             t->expr = x;
    2203                 :       48333 :             save_expr_cache = t;
    2204                 :             : 
    2205                 :       48333 :             tmp_before = tmp_nosp = 0;
    2206                 :       48333 :             verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE);
    2207                 :       48333 :             warn_for_collisions (tmp_nosp);
    2208                 :             : 
    2209                 :       48333 :             tmp_list3 = 0;
    2210                 :       48333 :             merge_tlist (&tmp_list3, tmp_nosp, 0);
    2211                 :       48333 :             t->cache_before_sp = tmp_before;
    2212                 :       48333 :             t->cache_after_sp = tmp_list3;
    2213                 :             :           }
    2214                 :       98291 :         merge_tlist (pbefore_sp, t->cache_before_sp, 1);
    2215                 :       98291 :         add_tlist (pno_sp, t->cache_after_sp, NULL_TREE, 1);
    2216                 :       98291 :         return;
    2217                 :             :       }
    2218                 :             : 
    2219                 :     7067353 :     case ADDR_EXPR:
    2220                 :     7067353 :       x = TREE_OPERAND (x, 0);
    2221                 :     7067353 :       if (DECL_P (x))
    2222                 :             :         return;
    2223                 :      493299 :       writer = 0;
    2224                 :      493299 :       goto restart;
    2225                 :             : 
    2226                 :    11975633 :     case VIEW_CONVERT_EXPR:
    2227                 :    11975633 :       if (location_wrapper_p (x))
    2228                 :             :         {
    2229                 :     2948757 :           x = TREE_OPERAND (x, 0);
    2230                 :     2948757 :           goto restart;
    2231                 :             :         }
    2232                 :     9026876 :       goto do_default;
    2233                 :             : 
    2234                 :      624224 :     case LSHIFT_EXPR:
    2235                 :      624224 :     case RSHIFT_EXPR:
    2236                 :      624224 :     case ARRAY_REF:
    2237                 :      624224 :       if (cxx_dialect >= cxx17)
    2238                 :       47988 :         goto sequenced_binary;
    2239                 :      576236 :       goto do_default;
    2240                 :             : 
    2241                 :     1275729 :     case COMPONENT_REF:
    2242                 :             :       /* Treat as unary, the other operands aren't evaluated.  */
    2243                 :     1275729 :       x = TREE_OPERAND (x, 0);
    2244                 :     1275729 :       writer = 0;
    2245                 :     1275729 :       goto restart;
    2246                 :             : 
    2247                 :    49634283 :     default:
    2248                 :    49634283 :     do_default:
    2249                 :             :       /* For other expressions, simply recurse on their operands.
    2250                 :             :          Manual tail recursion for unary expressions.
    2251                 :             :          Other non-expressions need not be processed.  */
    2252                 :    49634283 :       if (cl == tcc_unary)
    2253                 :             :         {
    2254                 :     8559289 :           x = TREE_OPERAND (x, 0);
    2255                 :     8559289 :           writer = 0;
    2256                 :     8559289 :           goto restart;
    2257                 :             :         }
    2258                 :    41074994 :       else if (IS_EXPR_CODE_CLASS (cl))
    2259                 :             :         {
    2260                 :    14964462 :           int lp;
    2261                 :    14964462 :           int max = TREE_OPERAND_LENGTH (x);
    2262                 :    50693739 :           for (lp = 0; lp < max; lp++)
    2263                 :             :             {
    2264                 :    20764815 :               tmp_before = tmp_nosp = 0;
    2265                 :    20764815 :               verify_tree (TREE_OPERAND (x, lp), &tmp_before, &tmp_nosp, 0);
    2266                 :    20764815 :               merge_tlist (&tmp_nosp, tmp_before, 0);
    2267                 :    41529630 :               add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
    2268                 :             :             }
    2269                 :             :         }
    2270                 :             :       return;
    2271                 :             :     }
    2272                 :             : }
    2273                 :             : 
    2274                 :             : static constexpr size_t verify_sequence_points_limit = 1024;
    2275                 :             : 
    2276                 :             : /* Called from verify_sequence_points via walk_tree.  */
    2277                 :             : 
    2278                 :             : static tree
    2279                 :    89360818 : verify_tree_lim_r (tree *tp, int *walk_subtrees, void *data)
    2280                 :             : {
    2281                 :    89360818 :   if (++*((size_t *) data) > verify_sequence_points_limit)
    2282                 :          57 :     return integer_zero_node;
    2283                 :             : 
    2284                 :    89360761 :   if (TYPE_P (*tp))
    2285                 :        3682 :     *walk_subtrees = 0;
    2286                 :             : 
    2287                 :             :   return NULL_TREE;
    2288                 :             : }
    2289                 :             : 
    2290                 :             : /* Try to warn for undefined behavior in EXPR due to missing sequence
    2291                 :             :    points.  */
    2292                 :             : 
    2293                 :             : void
    2294                 :     9096830 : verify_sequence_points (tree expr)
    2295                 :             : {
    2296                 :     9096830 :   tlist *before_sp = nullptr, *after_sp = nullptr;
    2297                 :             : 
    2298                 :             :   /* verify_tree is highly recursive, and merge_tlist is O(n^2),
    2299                 :             :      so we return early if the expression is too big.  */
    2300                 :     9096830 :   size_t n = 0;
    2301                 :     9096830 :   if (walk_tree (&expr, verify_tree_lim_r, &n, nullptr))
    2302                 :          57 :     return;
    2303                 :             : 
    2304                 :     9096773 :   warned_ids = nullptr;
    2305                 :     9096773 :   save_expr_cache = nullptr;
    2306                 :     9096773 :   if (!tlist_firstobj)
    2307                 :             :     {
    2308                 :        9876 :       gcc_obstack_init (&tlist_obstack);
    2309                 :        9876 :       tlist_firstobj = (char *) obstack_alloc (&tlist_obstack, 0);
    2310                 :             :     }
    2311                 :             : 
    2312                 :     9096773 :   verify_tree (expr, &before_sp, &after_sp, NULL_TREE);
    2313                 :     9096773 :   warn_for_collisions (after_sp);
    2314                 :     9096773 :   obstack_free (&tlist_obstack, tlist_firstobj);
    2315                 :             : }
    2316                 :             : 
    2317                 :             : /* Validate the expression after `case' and apply default promotions.  */
    2318                 :             : 
    2319                 :             : static tree
    2320                 :     2692083 : check_case_value (location_t loc, tree value)
    2321                 :             : {
    2322                 :     2692083 :   if (value == NULL_TREE)
    2323                 :             :     return value;
    2324                 :             : 
    2325                 :     4494716 :   if (INTEGRAL_TYPE_P (TREE_TYPE (value))
    2326                 :     4494613 :       && TREE_CODE (value) == INTEGER_CST)
    2327                 :             :     /* Promote char or short to int.  */
    2328                 :     2691932 :     value = perform_integral_promotions (value);
    2329                 :         151 :   else if (value != error_mark_node)
    2330                 :             :     {
    2331                 :          53 :       error_at (loc, "case label does not reduce to an integer constant");
    2332                 :          53 :       value = error_mark_node;
    2333                 :             :     }
    2334                 :             : 
    2335                 :     2692083 :   constant_expression_warning (value);
    2336                 :             : 
    2337                 :     2692083 :   return value;
    2338                 :             : }
    2339                 :             : 
    2340                 :             : /* Return an integer type with BITS bits of precision,
    2341                 :             :    that is unsigned if UNSIGNEDP is nonzero, otherwise signed.  */
    2342                 :             : 
    2343                 :             : tree
    2344                 :    27810356 : c_common_type_for_size (unsigned int bits, int unsignedp)
    2345                 :             : {
    2346                 :    27810356 :   int i;
    2347                 :             : 
    2348                 :    27810356 :   if (bits == TYPE_PRECISION (integer_type_node))
    2349                 :    18394922 :     return unsignedp ? unsigned_type_node : integer_type_node;
    2350                 :             : 
    2351                 :     9415434 :   if (bits == TYPE_PRECISION (signed_char_type_node))
    2352                 :     2619918 :     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
    2353                 :             : 
    2354                 :     6795516 :   if (bits == TYPE_PRECISION (short_integer_type_node))
    2355                 :      386965 :     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
    2356                 :             : 
    2357                 :     6408551 :   if (bits == TYPE_PRECISION (long_integer_type_node))
    2358                 :     5744847 :     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
    2359                 :             : 
    2360                 :      663704 :   if (bits == TYPE_PRECISION (long_long_integer_type_node))
    2361                 :        8501 :     return (unsignedp ? long_long_unsigned_type_node
    2362                 :        7778 :             : long_long_integer_type_node);
    2363                 :             : 
    2364                 :     1026410 :   for (i = 0; i < NUM_INT_N_ENTS; i ++)
    2365                 :      655203 :     if (int_n_enabled_p[i]
    2366                 :      649031 :         && bits == int_n_data[i].bitsize)
    2367                 :      283996 :       return (unsignedp ? int_n_trees[i].unsigned_type
    2368                 :      283996 :               : int_n_trees[i].signed_type);
    2369                 :             : 
    2370                 :      371207 :   if (bits == TYPE_PRECISION (widest_integer_literal_type_node))
    2371                 :           0 :     return (unsignedp ? widest_unsigned_literal_type_node
    2372                 :           0 :             : widest_integer_literal_type_node);
    2373                 :             : 
    2374                 :     1468907 :   for (tree t = registered_builtin_types; t; t = TREE_CHAIN (t))
    2375                 :             :     {
    2376                 :     1097700 :       tree type = TREE_VALUE (t);
    2377                 :     1097700 :       if (TREE_CODE (type) == INTEGER_TYPE
    2378                 :           0 :           && bits == TYPE_PRECISION (type)
    2379                 :     1097700 :           && !!unsignedp == !!TYPE_UNSIGNED (type))
    2380                 :             :         return type;
    2381                 :             :     }
    2382                 :             : 
    2383                 :      371207 :   if (bits <= TYPE_PRECISION (intQI_type_node))
    2384                 :      310276 :     return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
    2385                 :             : 
    2386                 :       60931 :   if (bits <= TYPE_PRECISION (intHI_type_node))
    2387                 :        9624 :     return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
    2388                 :             : 
    2389                 :       51307 :   if (bits <= TYPE_PRECISION (intSI_type_node))
    2390                 :       20549 :     return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
    2391                 :             : 
    2392                 :       30758 :   if (bits <= TYPE_PRECISION (intDI_type_node))
    2393                 :       24693 :     return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
    2394                 :             : 
    2395                 :        6065 :   if (bits <= TYPE_PRECISION (widest_integer_literal_type_node))
    2396                 :          31 :     return (unsignedp ? widest_unsigned_literal_type_node
    2397                 :          14 :             : widest_integer_literal_type_node);
    2398                 :             : 
    2399                 :             :   return NULL_TREE;
    2400                 :             : }
    2401                 :             : 
    2402                 :             : /* Return a fixed-point type that has at least IBIT ibits and FBIT fbits
    2403                 :             :    that is unsigned if UNSIGNEDP is nonzero, otherwise signed;
    2404                 :             :    and saturating if SATP is nonzero, otherwise not saturating.  */
    2405                 :             : 
    2406                 :             : tree
    2407                 :           0 : c_common_fixed_point_type_for_size (unsigned int ibit, unsigned int fbit,
    2408                 :             :                                     int unsignedp, int satp)
    2409                 :             : {
    2410                 :           0 :   enum mode_class mclass;
    2411                 :           0 :   if (ibit == 0)
    2412                 :           0 :     mclass = unsignedp ? MODE_UFRACT : MODE_FRACT;
    2413                 :             :   else
    2414                 :           0 :     mclass = unsignedp ? MODE_UACCUM : MODE_ACCUM;
    2415                 :             : 
    2416                 :           0 :   opt_scalar_mode opt_mode;
    2417                 :           0 :   scalar_mode mode;
    2418                 :           0 :   FOR_EACH_MODE_IN_CLASS (opt_mode, mclass)
    2419                 :             :     {
    2420                 :           0 :       mode = opt_mode.require ();
    2421                 :           0 :       if (GET_MODE_IBIT (mode) >= ibit && GET_MODE_FBIT (mode) >= fbit)
    2422                 :             :         break;
    2423                 :             :     }
    2424                 :             : 
    2425                 :           0 :   if (!opt_mode.exists (&mode) || !targetm.scalar_mode_supported_p (mode))
    2426                 :             :     {
    2427                 :           0 :       sorry ("GCC cannot support operators with integer types and "
    2428                 :             :              "fixed-point types that have too many integral and "
    2429                 :             :              "fractional bits together");
    2430                 :           0 :       return NULL_TREE;
    2431                 :             :     }
    2432                 :             : 
    2433                 :           0 :   return c_common_type_for_mode (mode, satp);
    2434                 :             : }
    2435                 :             : 
    2436                 :             : /* Used for communication between c_common_type_for_mode and
    2437                 :             :    c_register_builtin_type.  */
    2438                 :             : tree registered_builtin_types;
    2439                 :             : 
    2440                 :             : /* Return a data type that has machine mode MODE.
    2441                 :             :    If the mode is an integer,
    2442                 :             :    then UNSIGNEDP selects between signed and unsigned types.
    2443                 :             :    If the mode is a fixed-point mode,
    2444                 :             :    then UNSIGNEDP selects between saturating and nonsaturating types.  */
    2445                 :             : 
    2446                 :             : tree
    2447                 :    12539721 : c_common_type_for_mode (machine_mode mode, int unsignedp)
    2448                 :             : {
    2449                 :    12539721 :   tree t;
    2450                 :    12539721 :   int i;
    2451                 :             : 
    2452                 :    12539721 :   if (mode == TYPE_MODE (integer_type_node))
    2453                 :     1753925 :     return unsignedp ? unsigned_type_node : integer_type_node;
    2454                 :             : 
    2455                 :    10785796 :   if (mode == TYPE_MODE (signed_char_type_node))
    2456                 :     2116748 :     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
    2457                 :             : 
    2458                 :     8669048 :   if (mode == TYPE_MODE (short_integer_type_node))
    2459                 :      121497 :     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
    2460                 :             : 
    2461                 :     8547551 :   if (mode == TYPE_MODE (long_integer_type_node))
    2462                 :     5401237 :     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
    2463                 :             : 
    2464                 :     3146314 :   if (mode == TYPE_MODE (long_long_integer_type_node))
    2465                 :       82587 :     return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;
    2466                 :             : 
    2467                 :     4803614 :   for (i = 0; i < NUM_INT_N_ENTS; i ++)
    2468                 :     3063727 :     if (int_n_enabled_p[i]
    2469                 :     3063727 :         && mode == int_n_data[i].m)
    2470                 :     1323840 :       return (unsignedp ? int_n_trees[i].unsigned_type
    2471                 :     1323840 :               : int_n_trees[i].signed_type);
    2472                 :             : 
    2473                 :     1739887 :   if (mode == QImode)
    2474                 :           0 :     return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
    2475                 :             : 
    2476                 :     1739887 :   if (mode == HImode)
    2477                 :           0 :     return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
    2478                 :             : 
    2479                 :     1739887 :   if (mode == SImode)
    2480                 :           0 :     return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
    2481                 :             : 
    2482                 :     1739887 :   if (mode == DImode)
    2483                 :           0 :     return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
    2484                 :             : 
    2485                 :             : #if HOST_BITS_PER_WIDE_INT >= 64
    2486                 :     1739887 :   if (mode == TYPE_MODE (intTI_type_node))
    2487                 :           0 :     return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
    2488                 :             : #endif
    2489                 :             : 
    2490                 :     1739887 :   if (mode == TYPE_MODE (float_type_node))
    2491                 :       52333 :     return float_type_node;
    2492                 :             : 
    2493                 :     1687554 :   if (mode == TYPE_MODE (double_type_node))
    2494                 :       45395 :     return double_type_node;
    2495                 :             : 
    2496                 :     1642159 :   if (mode == TYPE_MODE (long_double_type_node))
    2497                 :       18559 :     return long_double_type_node;
    2498                 :             : 
    2499                 :    12362898 :   for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
    2500                 :    10890522 :     if (FLOATN_NX_TYPE_NODE (i) != NULL_TREE
    2501                 :    10890522 :         && mode == TYPE_MODE (FLOATN_NX_TYPE_NODE (i)))
    2502                 :      151224 :       return FLOATN_NX_TYPE_NODE (i);
    2503                 :             : 
    2504                 :     1472376 :   if (mode == TYPE_MODE (void_type_node))
    2505                 :           0 :     return void_type_node;
    2506                 :             : 
    2507                 :     1472376 :   if (mode == TYPE_MODE (build_pointer_type (char_type_node))
    2508                 :     1472376 :       || mode == TYPE_MODE (build_pointer_type (integer_type_node)))
    2509                 :             :     {
    2510                 :           0 :       unsigned int precision
    2511                 :           0 :         = GET_MODE_PRECISION (as_a <scalar_int_mode> (mode));
    2512                 :           0 :       return (unsignedp
    2513                 :           0 :               ? make_unsigned_type (precision)
    2514                 :           0 :               : make_signed_type (precision));
    2515                 :             :     }
    2516                 :             : 
    2517                 :     1472376 :   if (COMPLEX_MODE_P (mode))
    2518                 :             :     {
    2519                 :     1240558 :       machine_mode inner_mode;
    2520                 :     1240558 :       tree inner_type;
    2521                 :             : 
    2522                 :     1240558 :       if (mode == TYPE_MODE (complex_float_type_node))
    2523                 :      207514 :         return complex_float_type_node;
    2524                 :     1033044 :       if (mode == TYPE_MODE (complex_double_type_node))
    2525                 :      206572 :         return complex_double_type_node;
    2526                 :      826472 :       if (mode == TYPE_MODE (complex_long_double_type_node))
    2527                 :      206566 :         return complex_long_double_type_node;
    2528                 :             : 
    2529                 :     2685059 :       for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
    2530                 :     2478760 :         if (COMPLEX_FLOATN_NX_TYPE_NODE (i) != NULL_TREE
    2531                 :     2478760 :             && mode == TYPE_MODE (COMPLEX_FLOATN_NX_TYPE_NODE (i)))
    2532                 :      413607 :           return COMPLEX_FLOATN_NX_TYPE_NODE (i);
    2533                 :             : 
    2534                 :      206299 :       if (mode == TYPE_MODE (complex_integer_type_node) && !unsignedp)
    2535                 :          12 :         return complex_integer_type_node;
    2536                 :             : 
    2537                 :      206287 :       inner_mode = GET_MODE_INNER (mode);
    2538                 :      206287 :       inner_type = c_common_type_for_mode (inner_mode, unsignedp);
    2539                 :      206287 :       if (inner_type != NULL_TREE)
    2540                 :      206287 :         return build_complex_type (inner_type);
    2541                 :             :     }
    2542                 :      231818 :   else if (GET_MODE_CLASS (mode) == MODE_VECTOR_BOOL
    2543                 :      231818 :            && valid_vector_subparts_p (GET_MODE_NUNITS (mode)))
    2544                 :             :     {
    2545                 :           0 :       unsigned int elem_bits = vector_element_size (GET_MODE_PRECISION (mode),
    2546                 :             :                                                     GET_MODE_NUNITS (mode));
    2547                 :           0 :       tree bool_type = build_nonstandard_boolean_type (elem_bits);
    2548                 :           0 :       return build_vector_type_for_mode (bool_type, mode);
    2549                 :             :     }
    2550                 :      220722 :   else if (VECTOR_MODE_P (mode)
    2551                 :      244579 :            && valid_vector_subparts_p (GET_MODE_NUNITS (mode)))
    2552                 :             :     {
    2553                 :       12761 :       machine_mode inner_mode = GET_MODE_INNER (mode);
    2554                 :       12761 :       tree inner_type = c_common_type_for_mode (inner_mode, unsignedp);
    2555                 :       12761 :       if (inner_type != NULL_TREE)
    2556                 :       12761 :         return build_vector_type_for_mode (inner_type, mode);
    2557                 :             :     }
    2558                 :             : 
    2559                 :      219057 :   if (dfloat32_type_node != NULL_TREE
    2560                 :      219057 :       && mode == TYPE_MODE (dfloat32_type_node))
    2561                 :        2784 :     return dfloat32_type_node;
    2562                 :      216273 :   if (dfloat64_type_node != NULL_TREE
    2563                 :      216273 :       && mode == TYPE_MODE (dfloat64_type_node))
    2564                 :        3084 :     return dfloat64_type_node;
    2565                 :      213189 :   if (dfloat128_type_node != NULL_TREE
    2566                 :      213189 :       && mode == TYPE_MODE (dfloat128_type_node))
    2567                 :        2424 :     return dfloat128_type_node;
    2568                 :             : 
    2569                 :      210765 :   if (ALL_SCALAR_FIXED_POINT_MODE_P (mode))
    2570                 :             :     {
    2571                 :           0 :       if (mode == TYPE_MODE (short_fract_type_node))
    2572                 :           0 :         return unsignedp ? sat_short_fract_type_node : short_fract_type_node;
    2573                 :           0 :       if (mode == TYPE_MODE (fract_type_node))
    2574                 :           0 :         return unsignedp ? sat_fract_type_node : fract_type_node;
    2575                 :           0 :       if (mode == TYPE_MODE (long_fract_type_node))
    2576                 :           0 :         return unsignedp ? sat_long_fract_type_node : long_fract_type_node;
    2577                 :           0 :       if (mode == TYPE_MODE (long_long_fract_type_node))
    2578                 :           0 :         return unsignedp ? sat_long_long_fract_type_node
    2579                 :           0 :                          : long_long_fract_type_node;
    2580                 :             : 
    2581                 :           0 :       if (mode == TYPE_MODE (unsigned_short_fract_type_node))
    2582                 :           0 :         return unsignedp ? sat_unsigned_short_fract_type_node
    2583                 :           0 :                          : unsigned_short_fract_type_node;
    2584                 :           0 :       if (mode == TYPE_MODE (unsigned_fract_type_node))
    2585                 :           0 :         return unsignedp ? sat_unsigned_fract_type_node
    2586                 :           0 :                          : unsigned_fract_type_node;
    2587                 :           0 :       if (mode == TYPE_MODE (unsigned_long_fract_type_node))
    2588                 :           0 :         return unsignedp ? sat_unsigned_long_fract_type_node
    2589                 :           0 :                          : unsigned_long_fract_type_node;
    2590                 :           0 :       if (mode == TYPE_MODE (unsigned_long_long_fract_type_node))
    2591                 :           0 :         return unsignedp ? sat_unsigned_long_long_fract_type_node
    2592                 :           0 :                          : unsigned_long_long_fract_type_node;
    2593                 :             : 
    2594                 :           0 :       if (mode == TYPE_MODE (short_accum_type_node))
    2595                 :           0 :         return unsignedp ? sat_short_accum_type_node : short_accum_type_node;
    2596                 :           0 :       if (mode == TYPE_MODE (accum_type_node))
    2597                 :           0 :         return unsignedp ? sat_accum_type_node : accum_type_node;
    2598                 :           0 :       if (mode == TYPE_MODE (long_accum_type_node))
    2599                 :           0 :         return unsignedp ? sat_long_accum_type_node : long_accum_type_node;
    2600                 :           0 :       if (mode == TYPE_MODE (long_long_accum_type_node))
    2601                 :           0 :         return unsignedp ? sat_long_long_accum_type_node
    2602                 :           0 :                          : long_long_accum_type_node;
    2603                 :             : 
    2604                 :           0 :       if (mode == TYPE_MODE (unsigned_short_accum_type_node))
    2605                 :           0 :         return unsignedp ? sat_unsigned_short_accum_type_node
    2606                 :           0 :                          : unsigned_short_accum_type_node;
    2607                 :           0 :       if (mode == TYPE_MODE (unsigned_accum_type_node))
    2608                 :           0 :         return unsignedp ? sat_unsigned_accum_type_node
    2609                 :           0 :                          : unsigned_accum_type_node;
    2610                 :           0 :       if (mode == TYPE_MODE (unsigned_long_accum_type_node))
    2611                 :           0 :         return unsignedp ? sat_unsigned_long_accum_type_node
    2612                 :           0 :                          : unsigned_long_accum_type_node;
    2613                 :           0 :       if (mode == TYPE_MODE (unsigned_long_long_accum_type_node))
    2614                 :           0 :         return unsignedp ? sat_unsigned_long_long_accum_type_node
    2615                 :           0 :                          : unsigned_long_long_accum_type_node;
    2616                 :             : 
    2617                 :           0 :       if (mode == QQmode)
    2618                 :           0 :         return unsignedp ? sat_qq_type_node : qq_type_node;
    2619                 :             :       if (mode == HQmode)
    2620                 :           0 :         return unsignedp ? sat_hq_type_node : hq_type_node;
    2621                 :             :       if (mode == SQmode)
    2622                 :           0 :         return unsignedp ? sat_sq_type_node : sq_type_node;
    2623                 :             :       if (mode == DQmode)
    2624                 :           0 :         return unsignedp ? sat_dq_type_node : dq_type_node;
    2625                 :             :       if (mode == TQmode)
    2626                 :           0 :         return unsignedp ? sat_tq_type_node : tq_type_node;
    2627                 :             : 
    2628                 :             :       if (mode == UQQmode)
    2629                 :           0 :         return unsignedp ? sat_uqq_type_node : uqq_type_node;
    2630                 :             :       if (mode == UHQmode)
    2631                 :           0 :         return unsignedp ? sat_uhq_type_node : uhq_type_node;
    2632                 :             :       if (mode == USQmode)
    2633                 :           0 :         return unsignedp ? sat_usq_type_node : usq_type_node;
    2634                 :             :       if (mode == UDQmode)
    2635                 :           0 :         return unsignedp ? sat_udq_type_node : udq_type_node;
    2636                 :             :       if (mode == UTQmode)
    2637                 :           0 :         return unsignedp ? sat_utq_type_node : utq_type_node;
    2638                 :             : 
    2639                 :             :       if (mode == HAmode)
    2640                 :           0 :         return unsignedp ? sat_ha_type_node : ha_type_node;
    2641                 :             :       if (mode == SAmode)
    2642                 :           0 :         return unsignedp ? sat_sa_type_node : sa_type_node;
    2643                 :             :       if (mode == DAmode)
    2644                 :           0 :         return unsignedp ? sat_da_type_node : da_type_node;
    2645                 :             :       if (mode == TAmode)
    2646                 :           0 :         return unsignedp ? sat_ta_type_node : ta_type_node;
    2647                 :             : 
    2648                 :             :       if (mode == UHAmode)
    2649                 :           0 :         return unsignedp ? sat_uha_type_node : uha_type_node;
    2650                 :             :       if (mode == USAmode)
    2651                 :           0 :         return unsignedp ? sat_usa_type_node : usa_type_node;
    2652                 :             :       if (mode == UDAmode)
    2653                 :           0 :         return unsignedp ? sat_uda_type_node : uda_type_node;
    2654                 :             :       if (mode == UTAmode)
    2655                 :           0 :         return unsignedp ? sat_uta_type_node : uta_type_node;
    2656                 :             :     }
    2657                 :             : 
    2658                 :      213182 :   for (t = registered_builtin_types; t; t = TREE_CHAIN (t))
    2659                 :             :     {
    2660                 :      212391 :       tree type = TREE_VALUE (t);
    2661                 :      212391 :       if (TYPE_MODE (type) == mode
    2662                 :      210077 :           && VECTOR_TYPE_P (type) == VECTOR_MODE_P (mode)
    2663                 :      422468 :           && !!unsignedp == !!TYPE_UNSIGNED (type))
    2664                 :             :         return type;
    2665                 :             :     }
    2666                 :             :   return NULL_TREE;
    2667                 :             : }
    2668                 :             : 
    2669                 :             : tree
    2670                 :     1255508 : c_common_unsigned_type (tree type)
    2671                 :             : {
    2672                 :     1255508 :   return c_common_signed_or_unsigned_type (1, type);
    2673                 :             : }
    2674                 :             : 
    2675                 :             : /* Return a signed type the same as TYPE in other respects.  */
    2676                 :             : 
    2677                 :             : tree
    2678                 :    58704602 : c_common_signed_type (tree type)
    2679                 :             : {
    2680                 :    58704602 :   return c_common_signed_or_unsigned_type (0, type);
    2681                 :             : }
    2682                 :             : 
    2683                 :             : /* Return a type the same as TYPE except unsigned or
    2684                 :             :    signed according to UNSIGNEDP.  */
    2685                 :             : 
    2686                 :             : tree
    2687                 :    62854439 : c_common_signed_or_unsigned_type (int unsignedp, tree type)
    2688                 :             : {
    2689                 :    62854439 :   tree type1;
    2690                 :    62854439 :   int i;
    2691                 :             : 
    2692                 :             :   /* This block of code emulates the behavior of the old
    2693                 :             :      c_common_unsigned_type. In particular, it returns
    2694                 :             :      long_unsigned_type_node if passed a long, even when a int would
    2695                 :             :      have the same size. This is necessary for warnings to work
    2696                 :             :      correctly in archs where sizeof(int) == sizeof(long) */
    2697                 :             : 
    2698                 :    62854439 :   type1 = TYPE_MAIN_VARIANT (type);
    2699                 :    62854439 :   if (type1 == signed_char_type_node || type1 == char_type_node || type1 == unsigned_char_type_node)
    2700                 :     2676487 :     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
    2701                 :    60177952 :   if (type1 == integer_type_node || type1 == unsigned_type_node)
    2702                 :    17567551 :     return unsignedp ? unsigned_type_node : integer_type_node;
    2703                 :    42610401 :   if (type1 == short_integer_type_node || type1 == short_unsigned_type_node)
    2704                 :     5935969 :     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
    2705                 :    36674432 :   if (type1 == long_integer_type_node || type1 == long_unsigned_type_node)
    2706                 :    22496860 :     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
    2707                 :    14177572 :   if (type1 == long_long_integer_type_node || type1 == long_long_unsigned_type_node)
    2708                 :     2532321 :     return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;
    2709                 :             : 
    2710                 :    22619532 :   for (i = 0; i < NUM_INT_N_ENTS; i ++)
    2711                 :    11645251 :     if (int_n_enabled_p[i]
    2712                 :    10194718 :         && (type1 == int_n_trees[i].unsigned_type
    2713                 :     9524450 :             || type1 == int_n_trees[i].signed_type))
    2714                 :      670970 :       return (unsignedp ? int_n_trees[i].unsigned_type
    2715                 :      670970 :               : int_n_trees[i].signed_type);
    2716                 :             : 
    2717                 :             : #if HOST_BITS_PER_WIDE_INT >= 64
    2718                 :    10974281 :   if (type1 == intTI_type_node || type1 == unsigned_intTI_type_node)
    2719                 :           0 :     return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
    2720                 :             : #endif
    2721                 :    10974281 :   if (type1 == intDI_type_node || type1 == unsigned_intDI_type_node)
    2722                 :           0 :     return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
    2723                 :    10974281 :   if (type1 == intSI_type_node || type1 == unsigned_intSI_type_node)
    2724                 :           0 :     return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
    2725                 :    10974281 :   if (type1 == intHI_type_node || type1 == unsigned_intHI_type_node)
    2726                 :           0 :     return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
    2727                 :    10974281 :   if (type1 == intQI_type_node || type1 == unsigned_intQI_type_node)
    2728                 :           0 :     return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
    2729                 :             : 
    2730                 :             : #define C_COMMON_FIXED_TYPES(NAME)          \
    2731                 :             :   if (type1 == short_ ## NAME ## _type_node \
    2732                 :             :       || type1 == unsigned_short_ ## NAME ## _type_node) \
    2733                 :             :     return unsignedp ? unsigned_short_ ## NAME ## _type_node \
    2734                 :             :                      : short_ ## NAME ## _type_node; \
    2735                 :             :   if (type1 == NAME ## _type_node \
    2736                 :             :       || type1 == unsigned_ ## NAME ## _type_node) \
    2737                 :             :     return unsignedp ? unsigned_ ## NAME ## _type_node \
    2738                 :             :                      : NAME ## _type_node; \
    2739                 :             :   if (type1 == long_ ## NAME ## _type_node \
    2740                 :             :       || type1 == unsigned_long_ ## NAME ## _type_node) \
    2741                 :             :     return unsignedp ? unsigned_long_ ## NAME ## _type_node \
    2742                 :             :                      : long_ ## NAME ## _type_node; \
    2743                 :             :   if (type1 == long_long_ ## NAME ## _type_node \
    2744                 :             :       || type1 == unsigned_long_long_ ## NAME ## _type_node) \
    2745                 :             :     return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
    2746                 :             :                      : long_long_ ## NAME ## _type_node;
    2747                 :             : 
    2748                 :             : #define C_COMMON_FIXED_MODE_TYPES(NAME) \
    2749                 :             :   if (type1 == NAME ## _type_node \
    2750                 :             :       || type1 == u ## NAME ## _type_node) \
    2751                 :             :     return unsignedp ? u ## NAME ## _type_node \
    2752                 :             :                      : NAME ## _type_node;
    2753                 :             : 
    2754                 :             : #define C_COMMON_FIXED_TYPES_SAT(NAME) \
    2755                 :             :   if (type1 == sat_ ## short_ ## NAME ## _type_node \
    2756                 :             :       || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
    2757                 :             :     return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
    2758                 :             :                      : sat_ ## short_ ## NAME ## _type_node; \
    2759                 :             :   if (type1 == sat_ ## NAME ## _type_node \
    2760                 :             :       || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
    2761                 :             :     return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
    2762                 :             :                      : sat_ ## NAME ## _type_node; \
    2763                 :             :   if (type1 == sat_ ## long_ ## NAME ## _type_node \
    2764                 :             :       || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
    2765                 :             :     return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
    2766                 :             :                      : sat_ ## long_ ## NAME ## _type_node; \
    2767                 :             :   if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
    2768                 :             :       || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
    2769                 :             :     return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
    2770                 :             :                      : sat_ ## long_long_ ## NAME ## _type_node;
    2771                 :             : 
    2772                 :             : #define C_COMMON_FIXED_MODE_TYPES_SAT(NAME)     \
    2773                 :             :   if (type1 == sat_ ## NAME ## _type_node \
    2774                 :             :       || type1 == sat_ ## u ## NAME ## _type_node) \
    2775                 :             :     return unsignedp ? sat_ ## u ## NAME ## _type_node \
    2776                 :             :                      : sat_ ## NAME ## _type_node;
    2777                 :             : 
    2778                 :    10974281 :   C_COMMON_FIXED_TYPES (fract);
    2779                 :    10974281 :   C_COMMON_FIXED_TYPES_SAT (fract);
    2780                 :    10974281 :   C_COMMON_FIXED_TYPES (accum);
    2781                 :    10974281 :   C_COMMON_FIXED_TYPES_SAT (accum);
    2782                 :             : 
    2783                 :    10974281 :   C_COMMON_FIXED_MODE_TYPES (qq);
    2784                 :    10974281 :   C_COMMON_FIXED_MODE_TYPES (hq);
    2785                 :    10974281 :   C_COMMON_FIXED_MODE_TYPES (sq);
    2786                 :    10974281 :   C_COMMON_FIXED_MODE_TYPES (dq);
    2787                 :    10974281 :   C_COMMON_FIXED_MODE_TYPES (tq);
    2788                 :    10974281 :   C_COMMON_FIXED_MODE_TYPES_SAT (qq);
    2789                 :    10974281 :   C_COMMON_FIXED_MODE_TYPES_SAT (hq);
    2790                 :    10974281 :   C_COMMON_FIXED_MODE_TYPES_SAT (sq);
    2791                 :    10974281 :   C_COMMON_FIXED_MODE_TYPES_SAT (dq);
    2792                 :    10974281 :   C_COMMON_FIXED_MODE_TYPES_SAT (tq);
    2793                 :    10974281 :   C_COMMON_FIXED_MODE_TYPES (ha);
    2794                 :    10974281 :   C_COMMON_FIXED_MODE_TYPES (sa);
    2795                 :    10974281 :   C_COMMON_FIXED_MODE_TYPES (da);
    2796                 :    10974281 :   C_COMMON_FIXED_MODE_TYPES (ta);
    2797                 :    10974281 :   C_COMMON_FIXED_MODE_TYPES_SAT (ha);
    2798                 :    10974281 :   C_COMMON_FIXED_MODE_TYPES_SAT (sa);
    2799                 :    10974281 :   C_COMMON_FIXED_MODE_TYPES_SAT (da);
    2800                 :    10974281 :   C_COMMON_FIXED_MODE_TYPES_SAT (ta);
    2801                 :             : 
    2802                 :             :   /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
    2803                 :             :      the precision; they have precision set to match their range, but
    2804                 :             :      may use a wider mode to match an ABI.  If we change modes, we may
    2805                 :             :      wind up with bad conversions.  For INTEGER_TYPEs in C, must check
    2806                 :             :      the precision as well, so as to yield correct results for
    2807                 :             :      bit-field types.  C++ does not have these separate bit-field
    2808                 :             :      types, and producing a signed or unsigned variant of an
    2809                 :             :      ENUMERAL_TYPE may cause other problems as well.  */
    2810                 :             : 
    2811                 :    10974281 :   if (!INTEGRAL_TYPE_P (type)
    2812                 :    10974281 :       || TYPE_UNSIGNED (type) == unsignedp)
    2813                 :             :     return type;
    2814                 :             : 
    2815                 :    10015849 :   if (TREE_CODE (type) == BITINT_TYPE
    2816                 :             :       /* signed _BitInt(1) is invalid, avoid creating that.  */
    2817                 :    10015849 :       && (unsignedp || TYPE_PRECISION (type) > 1))
    2818                 :     1455173 :     return build_bitint_type (TYPE_PRECISION (type), unsignedp);
    2819                 :             : 
    2820                 :             : #define TYPE_OK(node)                                                       \
    2821                 :             :   (TYPE_MODE (type) == TYPE_MODE (node)                                     \
    2822                 :             :    && TYPE_PRECISION (type) == TYPE_PRECISION (node))
    2823                 :     8560676 :   if (TYPE_OK (signed_char_type_node))
    2824                 :      451926 :     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
    2825                 :     8108750 :   if (TYPE_OK (integer_type_node))
    2826                 :     4069493 :     return unsignedp ? unsigned_type_node : integer_type_node;
    2827                 :     4039257 :   if (TYPE_OK (short_integer_type_node))
    2828                 :      838537 :     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
    2829                 :     3200720 :   if (TYPE_OK (long_integer_type_node))
    2830                 :     2750390 :     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
    2831                 :      450330 :   if (TYPE_OK (long_long_integer_type_node))
    2832                 :      114225 :     return (unsignedp ? long_long_unsigned_type_node
    2833                 :           0 :             : long_long_integer_type_node);
    2834                 :             : 
    2835                 :      653732 :   for (i = 0; i < NUM_INT_N_ENTS; i ++)
    2836                 :      336105 :     if (int_n_enabled_p[i]
    2837                 :      324025 :         && TYPE_MODE (type) == int_n_data[i].m
    2838                 :      354647 :         && TYPE_PRECISION (type) == int_n_data[i].bitsize)
    2839                 :       18478 :       return (unsignedp ? int_n_trees[i].unsigned_type
    2840                 :       18478 :               : int_n_trees[i].signed_type);
    2841                 :             : 
    2842                 :             : #if HOST_BITS_PER_WIDE_INT >= 64
    2843                 :      317627 :   if (TYPE_OK (intTI_type_node))
    2844                 :           0 :     return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
    2845                 :             : #endif
    2846                 :      317627 :   if (TYPE_OK (intDI_type_node))
    2847                 :           0 :     return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
    2848                 :      317627 :   if (TYPE_OK (intSI_type_node))
    2849                 :           0 :     return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
    2850                 :      317627 :   if (TYPE_OK (intHI_type_node))
    2851                 :           0 :     return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
    2852                 :      317627 :   if (TYPE_OK (intQI_type_node))
    2853                 :           0 :     return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
    2854                 :             : #undef TYPE_OK
    2855                 :             : 
    2856                 :      317627 :   return build_nonstandard_integer_type (TYPE_PRECISION (type), unsignedp);
    2857                 :             : }
    2858                 :             : 
    2859                 :             : /* Build a bit-field integer type for the given WIDTH and UNSIGNEDP.  */
    2860                 :             : 
    2861                 :             : tree
    2862                 :      320127 : c_build_bitfield_integer_type (unsigned HOST_WIDE_INT width, int unsignedp)
    2863                 :             : {
    2864                 :      320127 :   int i;
    2865                 :             : 
    2866                 :             :   /* Extended integer types of the same width as a standard type have
    2867                 :             :      lesser rank, so those of the same width as int promote to int or
    2868                 :             :      unsigned int and are valid for printf formats expecting int or
    2869                 :             :      unsigned int.  To avoid such special cases, avoid creating
    2870                 :             :      extended integer types for bit-fields if a standard integer type
    2871                 :             :      is available.  */
    2872                 :      320127 :   if (width == TYPE_PRECISION (integer_type_node))
    2873                 :         138 :     return unsignedp ? unsigned_type_node : integer_type_node;
    2874                 :      319989 :   if (width == TYPE_PRECISION (signed_char_type_node))
    2875                 :        6837 :     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
    2876                 :      313152 :   if (width == TYPE_PRECISION (short_integer_type_node))
    2877                 :        1426 :     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
    2878                 :      311726 :   if (width == TYPE_PRECISION (long_integer_type_node))
    2879                 :           0 :     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
    2880                 :      311726 :   if (width == TYPE_PRECISION (long_long_integer_type_node))
    2881                 :           0 :     return (unsignedp ? long_long_unsigned_type_node
    2882                 :           0 :             : long_long_integer_type_node);
    2883                 :      623452 :   for (i = 0; i < NUM_INT_N_ENTS; i ++)
    2884                 :      311726 :     if (int_n_enabled_p[i]
    2885                 :      304837 :         && width == int_n_data[i].bitsize)
    2886                 :           0 :       return (unsignedp ? int_n_trees[i].unsigned_type
    2887                 :           0 :               : int_n_trees[i].signed_type);
    2888                 :      311726 :   return build_nonstandard_integer_type (width, unsignedp);
    2889                 :             : }
    2890                 :             : 
    2891                 :             : /* The C version of the register_builtin_type langhook.  */
    2892                 :             : 
    2893                 :             : void
    2894                 :      618771 : c_register_builtin_type (tree type, const char* name)
    2895                 :             : {
    2896                 :      618771 :   tree decl;
    2897                 :             : 
    2898                 :      618771 :   decl = build_decl (UNKNOWN_LOCATION,
    2899                 :             :                      TYPE_DECL, get_identifier (name), type);
    2900                 :      618771 :   DECL_ARTIFICIAL (decl) = 1;
    2901                 :      618771 :   if (!TYPE_NAME (type))
    2902                 :      301477 :     TYPE_NAME (type) = decl;
    2903                 :      618771 :   lang_hooks.decls.pushdecl (decl);
    2904                 :             : 
    2905                 :      618771 :   registered_builtin_types = tree_cons (0, type, registered_builtin_types);
    2906                 :      618771 : }
    2907                 :             : 
    2908                 :             : /* Print an error message for invalid operands to arith operation
    2909                 :             :    CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
    2910                 :             :    RICHLOC is a rich location for the message, containing either
    2911                 :             :    three separate locations for each of the operator and operands
    2912                 :             : 
    2913                 :             :       lhs op rhs
    2914                 :             :       ~~~ ^~ ~~~
    2915                 :             : 
    2916                 :             :    (C FE), or one location ranging over all over them
    2917                 :             : 
    2918                 :             :       lhs op rhs
    2919                 :             :       ~~~~^~~~~~
    2920                 :             : 
    2921                 :             :    (C++ FE).  */
    2922                 :             : 
    2923                 :             : void
    2924                 :         558 : binary_op_error (rich_location *richloc, enum tree_code code,
    2925                 :             :                  tree type0, tree type1)
    2926                 :             : {
    2927                 :         558 :   const char *opname;
    2928                 :             : 
    2929                 :         558 :   switch (code)
    2930                 :             :     {
    2931                 :             :     case PLUS_EXPR:
    2932                 :             :       opname = "+"; break;
    2933                 :          14 :     case MINUS_EXPR:
    2934                 :          14 :       opname = "-"; break;
    2935                 :         378 :     case MULT_EXPR:
    2936                 :         378 :       opname = "*"; break;
    2937                 :           0 :     case MAX_EXPR:
    2938                 :           0 :       opname = "max"; break;
    2939                 :           0 :     case MIN_EXPR:
    2940                 :           0 :       opname = "min"; break;
    2941                 :           2 :     case EQ_EXPR:
    2942                 :           2 :       opname = "=="; break;
    2943                 :           2 :     case NE_EXPR:
    2944                 :           2 :       opname = "!="; break;
    2945                 :           0 :     case LE_EXPR:
    2946                 :           0 :       opname = "<="; break;
    2947                 :           0 :     case GE_EXPR:
    2948                 :           0 :       opname = ">="; break;
    2949                 :           1 :     case LT_EXPR:
    2950                 :           1 :       opname = "<"; break;
    2951                 :           1 :     case GT_EXPR:
    2952                 :           1 :       opname = ">"; break;
    2953                 :          21 :     case LSHIFT_EXPR:
    2954                 :          21 :       opname = "<<"; break;
    2955                 :          16 :     case RSHIFT_EXPR:
    2956                 :          16 :       opname = ">>"; break;
    2957                 :           3 :     case TRUNC_MOD_EXPR:
    2958                 :           3 :     case FLOOR_MOD_EXPR:
    2959                 :           3 :       opname = "%"; break;
    2960                 :           6 :     case TRUNC_DIV_EXPR:
    2961                 :           6 :     case FLOOR_DIV_EXPR:
    2962                 :           6 :       opname = "/"; break;
    2963                 :          40 :     case BIT_AND_EXPR:
    2964                 :          40 :       opname = "&"; break;
    2965                 :          21 :     case BIT_IOR_EXPR:
    2966                 :          21 :       opname = "|"; break;
    2967                 :           0 :     case TRUTH_ANDIF_EXPR:
    2968                 :           0 :       opname = "&&"; break;
    2969                 :           0 :     case TRUTH_ORIF_EXPR:
    2970                 :           0 :       opname = "||"; break;
    2971                 :          22 :     case BIT_XOR_EXPR:
    2972                 :          22 :       opname = "^"; break;
    2973                 :           0 :     default:
    2974                 :           0 :       gcc_unreachable ();
    2975                 :             :     }
    2976                 :         558 :   pp_markup::element_quoted_type element_0 (type0, highlight_colors::lhs);
    2977                 :        1116 :   pp_markup::element_quoted_type element_1 (type1, highlight_colors::rhs);
    2978                 :         558 :   error_at (richloc,
    2979                 :             :             "invalid operands to binary %s (have %e and %e)",
    2980                 :             :             opname, &element_0, &element_1);
    2981                 :         558 : }
    2982                 :             : 
    2983                 :             : /* Given an expression as a tree, return its original type.  Do this
    2984                 :             :    by stripping any conversion that preserves the sign and precision.  */
    2985                 :             : static tree
    2986                 :       54595 : expr_original_type (tree expr)
    2987                 :             : {
    2988                 :       54595 :   STRIP_SIGN_NOPS (expr);
    2989                 :       54595 :   return TREE_TYPE (expr);
    2990                 :             : }
    2991                 :             : 
    2992                 :             : /* Subroutine of build_binary_op, used for comparison operations.
    2993                 :             :    See if the operands have both been converted from subword integer types
    2994                 :             :    and, if so, perhaps change them both back to their original type.
    2995                 :             :    This function is also responsible for converting the two operands
    2996                 :             :    to the proper common type for comparison.
    2997                 :             : 
    2998                 :             :    The arguments of this function are all pointers to local variables
    2999                 :             :    of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
    3000                 :             :    RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
    3001                 :             : 
    3002                 :             :    LOC is the location of the comparison.
    3003                 :             : 
    3004                 :             :    If this function returns non-NULL_TREE, it means that the comparison has
    3005                 :             :    a constant value.  What this function returns is an expression for
    3006                 :             :    that value.  */
    3007                 :             : 
    3008                 :             : tree
    3009                 :    26139506 : shorten_compare (location_t loc, tree *op0_ptr, tree *op1_ptr,
    3010                 :             :                  tree *restype_ptr, enum tree_code *rescode_ptr)
    3011                 :             : {
    3012                 :    26139506 :   tree type;
    3013                 :    26139506 :   tree op0 = *op0_ptr;
    3014                 :    26139506 :   tree op1 = *op1_ptr;
    3015                 :    26139506 :   int unsignedp0, unsignedp1;
    3016                 :    26139506 :   int real1, real2;
    3017                 :    26139506 :   tree primop0, primop1;
    3018                 :    26139506 :   enum tree_code code = *rescode_ptr;
    3019                 :             : 
    3020                 :             :   /* Throw away any conversions to wider types
    3021                 :             :      already present in the operands.  */
    3022                 :             : 
    3023                 :    26139506 :   primop0 = c_common_get_narrower (op0, &unsignedp0);
    3024                 :    26139506 :   primop1 = c_common_get_narrower (op1, &unsignedp1);
    3025                 :             : 
    3026                 :             :   /* If primopN is first sign-extended from primopN's precision to opN's
    3027                 :             :      precision, then zero-extended from opN's precision to
    3028                 :             :      *restype_ptr precision, shortenings might be invalid.  */
    3029                 :    26139506 :   if (TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (TREE_TYPE (op0))
    3030                 :     1502648 :       && TYPE_PRECISION (TREE_TYPE (op0)) < TYPE_PRECISION (*restype_ptr)
    3031                 :        5738 :       && !unsignedp0
    3032                 :    26144986 :       && TYPE_UNSIGNED (TREE_TYPE (op0)))
    3033                 :             :     primop0 = op0;
    3034                 :    26139506 :   if (TYPE_PRECISION (TREE_TYPE (primop1)) < TYPE_PRECISION (TREE_TYPE (op1))
    3035                 :      920970 :       && TYPE_PRECISION (TREE_TYPE (op1)) < TYPE_PRECISION (*restype_ptr)
    3036                 :       16726 :       && !unsignedp1
    3037                 :    26150998 :       && TYPE_UNSIGNED (TREE_TYPE (op1)))
    3038                 :             :     primop1 = op1;
    3039                 :             : 
    3040                 :             :   /* Handle the case that OP0 does not *contain* a conversion
    3041                 :             :      but it *requires* conversion to FINAL_TYPE.  */
    3042                 :             : 
    3043                 :    26139506 :   if (op0 == primop0 && TREE_TYPE (op0) != *restype_ptr)
    3044                 :      434595 :     unsignedp0 = TYPE_UNSIGNED (TREE_TYPE (op0));
    3045                 :    26139506 :   if (op1 == primop1 && TREE_TYPE (op1) != *restype_ptr)
    3046                 :     6867373 :     unsignedp1 = TYPE_UNSIGNED (TREE_TYPE (op1));
    3047                 :             : 
    3048                 :             :   /* If one of the operands must be floated, we cannot optimize.  */
    3049                 :    26139506 :   real1 = SCALAR_FLOAT_TYPE_P (TREE_TYPE (primop0));
    3050                 :    26139506 :   real2 = SCALAR_FLOAT_TYPE_P (TREE_TYPE (primop1));
    3051                 :             : 
    3052                 :             :   /* If first arg is constant, swap the args (changing operation
    3053                 :             :      so value is preserved), for canonicalization.  Don't do this if
    3054                 :             :      the second arg is 0.  */
    3055                 :             : 
    3056                 :    26139506 :   if (TREE_CONSTANT (primop0)
    3057                 :     5515355 :       && !integer_zerop (primop1) && !real_zerop (primop1)
    3058                 :    30162908 :       && !fixed_zerop (primop1))
    3059                 :             :     {
    3060                 :     4023402 :       std::swap (primop0, primop1);
    3061                 :     4023402 :       std::swap (op0, op1);
    3062                 :     4023402 :       *op0_ptr = op0;
    3063                 :     4023402 :       *op1_ptr = op1;
    3064                 :     4023402 :       std::swap (unsignedp0, unsignedp1);
    3065                 :     4023402 :       std::swap (real1, real2);
    3066                 :             : 
    3067                 :     4023402 :       switch (code)
    3068                 :             :         {
    3069                 :             :         case LT_EXPR:
    3070                 :             :           code = GT_EXPR;
    3071                 :             :           break;
    3072                 :             :         case GT_EXPR:
    3073                 :             :           code = LT_EXPR;
    3074                 :             :           break;
    3075                 :             :         case LE_EXPR:
    3076                 :             :           code = GE_EXPR;
    3077                 :             :           break;
    3078                 :             :         case GE_EXPR:
    3079                 :             :           code = LE_EXPR;
    3080                 :             :           break;
    3081                 :             :         default:
    3082                 :             :           break;
    3083                 :             :         }
    3084                 :     4023402 :       *rescode_ptr = code;
    3085                 :             :     }
    3086                 :             : 
    3087                 :             :   /* If comparing an integer against a constant more bits wide,
    3088                 :             :      maybe we can deduce a value of 1 or 0 independent of the data.
    3089                 :             :      Or else truncate the constant now
    3090                 :             :      rather than extend the variable at run time.
    3091                 :             : 
    3092                 :             :      This is only interesting if the constant is the wider arg.
    3093                 :             :      Also, it is not safe if the constant is unsigned and the
    3094                 :             :      variable arg is signed, since in this case the variable
    3095                 :             :      would be sign-extended and then regarded as unsigned.
    3096                 :             :      Our technique fails in this case because the lowest/highest
    3097                 :             :      possible unsigned results don't follow naturally from the
    3098                 :             :      lowest/highest possible values of the variable operand.
    3099                 :             :      For just EQ_EXPR and NE_EXPR there is another technique that
    3100                 :             :      could be used: see if the constant can be faithfully represented
    3101                 :             :      in the other operand's type, by truncating it and reextending it
    3102                 :             :      and see if that preserves the constant's value.  */
    3103                 :             : 
    3104                 :    21622207 :   if (!real1 && !real2
    3105                 :    21597680 :       && TREE_CODE (TREE_TYPE (primop0)) != FIXED_POINT_TYPE
    3106                 :    21597680 :       && TREE_CODE (primop1) == INTEGER_CST
    3107                 :    40234721 :       && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr))
    3108                 :             :     {
    3109                 :     1568856 :       int min_gt, max_gt, min_lt, max_lt;
    3110                 :     1568856 :       tree maxval, minval;
    3111                 :             :       /* 1 if comparison is nominally unsigned.  */
    3112                 :     1568856 :       int unsignedp = TYPE_UNSIGNED (*restype_ptr);
    3113                 :     1568856 :       tree val;
    3114                 :             : 
    3115                 :     1568856 :       type = c_common_signed_or_unsigned_type (unsignedp0,
    3116                 :     1568856 :                                                TREE_TYPE (primop0));
    3117                 :             : 
    3118                 :     1568856 :       maxval = TYPE_MAX_VALUE (type);
    3119                 :     1568856 :       minval = TYPE_MIN_VALUE (type);
    3120                 :             : 
    3121                 :     1568856 :       if (unsignedp && !unsignedp0)
    3122                 :      412993 :         *restype_ptr = c_common_signed_type (*restype_ptr);
    3123                 :             : 
    3124                 :     1568856 :       if (TREE_TYPE (primop1) != *restype_ptr)
    3125                 :             :         {
    3126                 :             :           /* Convert primop1 to target type, but do not introduce
    3127                 :             :              additional overflow.  We know primop1 is an int_cst.  */
    3128                 :      413297 :           primop1 = force_fit_type (*restype_ptr,
    3129                 :             :                                     wi::to_wide
    3130                 :      826594 :                                      (primop1,
    3131                 :      413297 :                                       TYPE_PRECISION (*restype_ptr)),
    3132                 :      413297 :                                     0, TREE_OVERFLOW (primop1));
    3133                 :             :         }
    3134                 :     1568856 :       if (type != *restype_ptr)
    3135                 :             :         {
    3136                 :     1568856 :           minval = convert (*restype_ptr, minval);
    3137                 :     1568856 :           maxval = convert (*restype_ptr, maxval);
    3138                 :             :         }
    3139                 :             : 
    3140                 :     1568856 :       min_gt = tree_int_cst_lt (primop1, minval);
    3141                 :     1568856 :       max_gt = tree_int_cst_lt (primop1, maxval);
    3142                 :     1568856 :       min_lt = tree_int_cst_lt (minval, primop1);
    3143                 :     1568856 :       max_lt = tree_int_cst_lt (maxval, primop1);
    3144                 :             : 
    3145                 :     1568856 :       val = 0;
    3146                 :             :       /* This used to be a switch, but Genix compiler can't handle that.  */
    3147                 :     1568856 :       if (code == NE_EXPR)
    3148                 :             :         {
    3149                 :      357801 :           if (max_lt || min_gt)
    3150                 :          23 :             val = truthvalue_true_node;
    3151                 :             :         }
    3152                 :             :       else if (code == EQ_EXPR)
    3153                 :             :         {
    3154                 :      636844 :           if (max_lt || min_gt)
    3155                 :          35 :             val = truthvalue_false_node;
    3156                 :             :         }
    3157                 :             :       else if (code == LT_EXPR)
    3158                 :             :         {
    3159                 :      316607 :           if (max_lt)
    3160                 :          18 :             val = truthvalue_true_node;
    3161                 :      316607 :           if (!min_lt)
    3162                 :        7600 :             val = truthvalue_false_node;
    3163                 :             :         }
    3164                 :             :       else if (code == GT_EXPR)
    3165                 :             :         {
    3166                 :      119474 :           if (min_gt)
    3167                 :           8 :             val = truthvalue_true_node;
    3168                 :      119474 :           if (!max_gt)
    3169                 :           6 :             val = truthvalue_false_node;
    3170                 :             :         }
    3171                 :             :       else if (code == LE_EXPR)
    3172                 :             :         {
    3173                 :       56907 :           if (!max_gt)
    3174                 :          74 :             val = truthvalue_true_node;
    3175                 :       56907 :           if (min_gt)
    3176                 :           7 :             val = truthvalue_false_node;
    3177                 :             :         }
    3178                 :             :       else if (code == GE_EXPR)
    3179                 :             :         {
    3180                 :       81221 :           if (!min_lt)
    3181                 :         179 :             val = truthvalue_true_node;
    3182                 :       81221 :           if (max_lt)
    3183                 :       14970 :             val = truthvalue_false_node;
    3184                 :             :         }
    3185                 :             : 
    3186                 :             :       /* If primop0 was sign-extended and unsigned comparison specd,
    3187                 :             :          we did a signed comparison above using the signed type bounds.
    3188                 :             :          But the comparison we output must be unsigned.
    3189                 :             : 
    3190                 :             :          Also, for inequalities, VAL is no good; but if the signed
    3191                 :             :          comparison had *any* fixed result, it follows that the
    3192                 :             :          unsigned comparison just tests the sign in reverse
    3193                 :             :          (positive values are LE, negative ones GE).
    3194                 :             :          So we can generate an unsigned comparison
    3195                 :             :          against an extreme value of the signed type.  */
    3196                 :             : 
    3197                 :     1568856 :       if (unsignedp && !unsignedp0)
    3198                 :             :         {
    3199                 :      412993 :           if (val != 0)
    3200                 :         112 :             switch (code)
    3201                 :             :               {
    3202                 :          81 :               case LT_EXPR:
    3203                 :          81 :               case GE_EXPR:
    3204                 :          81 :                 primop1 = TYPE_MIN_VALUE (type);
    3205                 :          81 :                 val = 0;
    3206                 :          81 :                 break;
    3207                 :             : 
    3208                 :          30 :               case LE_EXPR:
    3209                 :          30 :               case GT_EXPR:
    3210                 :          30 :                 primop1 = TYPE_MAX_VALUE (type);
    3211                 :          30 :                 val = 0;
    3212                 :          30 :                 break;
    3213                 :             : 
    3214                 :             :               default:
    3215                 :             :                 break;
    3216                 :             :               }
    3217                 :      412993 :           type = c_common_unsigned_type (type);
    3218                 :             :         }
    3219                 :             : 
    3220                 :     1568856 :       if (TREE_CODE (primop0) != INTEGER_CST
    3221                 :             :           /* Don't warn if it's from a (non-system) macro.  */
    3222                 :     1568856 :           && !(from_macro_expansion_at
    3223                 :     1074394 :                (expansion_point_location_if_in_system_header
    3224                 :     1074394 :                 (EXPR_LOCATION (primop0)))))
    3225                 :             :         {
    3226                 :     1034105 :           if (val == truthvalue_false_node)
    3227                 :        7634 :             warning_at (loc, OPT_Wtype_limits,
    3228                 :             :                         "comparison is always false due to limited range of data type");
    3229                 :     1034105 :           if (val == truthvalue_true_node)
    3230                 :         187 :             warning_at (loc, OPT_Wtype_limits,
    3231                 :             :                         "comparison is always true due to limited range of data type");
    3232                 :             :         }
    3233                 :             : 
    3234                 :     1568856 :       if (val != 0)
    3235                 :             :         {
    3236                 :             :           /* Don't forget to evaluate PRIMOP0 if it has side effects.  */
    3237                 :       22809 :           if (TREE_SIDE_EFFECTS (primop0))
    3238                 :          21 :             return build2 (COMPOUND_EXPR, TREE_TYPE (val), primop0, val);
    3239                 :             :           return val;
    3240                 :             :         }
    3241                 :             : 
    3242                 :             :       /* Value is not predetermined, but do the comparison
    3243                 :             :          in the type of the operand that is not constant.
    3244                 :             :          TYPE is already properly set.  */
    3245                 :             :     }
    3246                 :             : 
    3247                 :             :   /* If either arg is decimal float and the other is float, find the
    3248                 :             :      proper common type to use for comparison.  */
    3249                 :     4517299 :   else if (real1 && real2
    3250                 :     4285391 :            && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0)))
    3251                 :    24587198 :            && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1))))
    3252                 :       16547 :     type = common_type (TREE_TYPE (primop0), TREE_TYPE (primop1));
    3253                 :             : 
    3254                 :             :   /* If either arg is decimal float and the other is float, fail.  */
    3255                 :     4500752 :   else if (real1 && real2
    3256                 :    28822947 :            && (DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0)))
    3257                 :     4268843 :                || DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1)))))
    3258                 :             :     {
    3259                 :           2 :       type = *restype_ptr;
    3260                 :           2 :       primop0 = op0;
    3261                 :           2 :       primop1 = op1;
    3262                 :             :     }
    3263                 :             : 
    3264                 :     4500750 :   else if (real1 && real2
    3265                 :    28822943 :            && (TYPE_PRECISION (TREE_TYPE (primop0))
    3266                 :     4268842 :                == TYPE_PRECISION (TREE_TYPE (primop1))))
    3267                 :     4173882 :     type = TREE_TYPE (primop0);
    3268                 :             : 
    3269                 :             :   /* If args' natural types are both narrower than nominal type
    3270                 :             :      and both extend in the same manner, compare them
    3271                 :             :      in the type of the wider arg.
    3272                 :             :      Otherwise must actually extend both to the nominal
    3273                 :             :      common type lest different ways of extending
    3274                 :             :      alter the result.
    3275                 :             :      (eg, (short)-1 == (unsigned short)-1  should be 0.)  */
    3276                 :             : 
    3277                 :    17795074 :   else if (unsignedp0 == unsignedp1 && real1 == real2
    3278                 :    17551583 :            && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr)
    3279                 :      507364 :            && TYPE_PRECISION (TREE_TYPE (primop1)) < TYPE_PRECISION (*restype_ptr)
    3280                 :    20736471 :            && (type = common_type (TREE_TYPE (primop0), TREE_TYPE (primop1)))
    3281                 :      356252 :               != error_mark_node)
    3282                 :             :     {
    3283                 :      356252 :       type = c_common_signed_or_unsigned_type (unsignedp0
    3284                 :      356252 :                                                || TYPE_UNSIGNED (*restype_ptr),
    3285                 :             :                                                type);
    3286                 :             :       /* Make sure shorter operand is extended the right way
    3287                 :             :          to match the longer operand.  */
    3288                 :      356252 :       primop0
    3289                 :      356252 :         = convert (c_common_signed_or_unsigned_type (unsignedp0,
    3290                 :      356252 :                                                      TREE_TYPE (primop0)),
    3291                 :             :                    primop0);
    3292                 :      356252 :       primop1
    3293                 :      356252 :         = convert (c_common_signed_or_unsigned_type (unsignedp1,
    3294                 :      356252 :                                                      TREE_TYPE (primop1)),
    3295                 :             :                    primop1);
    3296                 :             :     }
    3297                 :             :   else
    3298                 :             :     {
    3299                 :             :       /* Here we must do the comparison on the nominal type
    3300                 :             :          using the args exactly as we received them.  */
    3301                 :    20023967 :       type = *restype_ptr;
    3302                 :    20023967 :       primop0 = op0;
    3303                 :    20023967 :       primop1 = op1;
    3304                 :             : 
    3305                 :             :       /* We want to fold unsigned comparisons of >= and < against zero.
    3306                 :             :          For these, we may also issue a warning if we have a non-constant
    3307                 :             :          compared against zero, where the zero was spelled as "0" (rather
    3308                 :             :          than merely folding to it).
    3309                 :             :          If we have at least one constant, then op1 is constant
    3310                 :             :          and we may have a non-constant expression as op0.  */
    3311                 :    19697099 :       if (!real1 && !real2 && integer_zerop (primop1)
    3312                 :    28281781 :           && TYPE_UNSIGNED (*restype_ptr))
    3313                 :             :         {
    3314                 :     2745156 :           tree value = NULL_TREE;
    3315                 :             :           /* All unsigned values are >= 0, so we warn.  However,
    3316                 :             :              if OP0 is a constant that is >= 0, the signedness of
    3317                 :             :              the comparison isn't an issue, so suppress the
    3318                 :             :              warning.  */
    3319                 :     2745156 :           tree folded_op0 = fold_for_warn (op0);
    3320                 :     2745156 :           bool warn =
    3321                 :       70129 :             warn_type_limits && !in_system_header_at (loc)
    3322                 :       63931 :             && !(TREE_CODE (folded_op0) == INTEGER_CST
    3323                 :        9336 :                  && !TREE_OVERFLOW (convert (c_common_signed_type (type),
    3324                 :             :                                              folded_op0)))
    3325                 :             :             /* Do not warn for enumeration types.  */
    3326                 :     2799751 :             && (TREE_CODE (expr_original_type (folded_op0)) != ENUMERAL_TYPE);
    3327                 :             : 
    3328                 :     2745156 :           switch (code)
    3329                 :             :             {
    3330                 :       12092 :             case GE_EXPR:
    3331                 :       12092 :               if (warn)
    3332                 :          56 :                 warning_at (loc, OPT_Wtype_limits,
    3333                 :             :                             "comparison of unsigned expression in %<>= 0%> "
    3334                 :             :                             "is always true");
    3335                 :       12092 :               value = truthvalue_true_node;
    3336                 :       12092 :               break;
    3337                 :             : 
    3338                 :      305964 :             case LT_EXPR:
    3339                 :      305964 :               if (warn)
    3340                 :          55 :                 warning_at (loc, OPT_Wtype_limits,
    3341                 :             :                             "comparison of unsigned expression in %<< 0%> "
    3342                 :             :                             "is always false");
    3343                 :      305964 :               value = truthvalue_false_node;
    3344                 :      305964 :               break;
    3345                 :             : 
    3346                 :             :             default:
    3347                 :             :               break;
    3348                 :             :             }
    3349                 :             : 
    3350                 :      318056 :           if (value != NULL_TREE)
    3351                 :             :             {
    3352                 :             :               /* Don't forget to evaluate PRIMOP0 if it has side effects.  */
    3353                 :      318056 :               if (TREE_SIDE_EFFECTS (primop0))
    3354                 :          47 :                 return build2 (COMPOUND_EXPR, TREE_TYPE (value),
    3355                 :          47 :                                primop0, value);
    3356                 :             :               return value;
    3357                 :             :             }
    3358                 :             :         }
    3359                 :             :     }
    3360                 :             : 
    3361                 :    25798641 :   *op0_ptr = convert (type, primop0);
    3362                 :    25798641 :   *op1_ptr = convert (type, primop1);
    3363                 :             : 
    3364                 :    25798641 :   *restype_ptr = truthvalue_type_node;
    3365                 :             : 
    3366                 :    25798641 :   return NULL_TREE;
    3367                 :             : }
    3368                 :             : 
    3369                 :             : /* Return a tree for the sum or difference (RESULTCODE says which)
    3370                 :             :    of pointer PTROP and integer INTOP.  */
    3371                 :             : 
    3372                 :             : tree
    3373                 :     5398490 : pointer_int_sum (location_t loc, enum tree_code resultcode,
    3374                 :             :                  tree ptrop, tree intop, bool complain)
    3375                 :             : {
    3376                 :     5398490 :   tree size_exp, ret;
    3377                 :             : 
    3378                 :             :   /* The result is a pointer of the same type that is being added.  */
    3379                 :     5398490 :   tree result_type = TREE_TYPE (ptrop);
    3380                 :             : 
    3381                 :     5398490 :   if (VOID_TYPE_P (TREE_TYPE (result_type)))
    3382                 :             :     {
    3383                 :         900 :       if (complain && warn_pointer_arith)
    3384                 :          61 :         pedwarn (loc, OPT_Wpointer_arith,
    3385                 :             :                  "pointer of type %<void *%> used in arithmetic");
    3386                 :             :       else if (!complain)
    3387                 :           0 :         return error_mark_node;
    3388                 :         900 :       size_exp = integer_one_node;
    3389                 :             :     }
    3390                 :     5397590 :   else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE)
    3391                 :             :     {
    3392                 :         118 :       if (complain && warn_pointer_arith)
    3393                 :          49 :         pedwarn (loc, OPT_Wpointer_arith,
    3394                 :             :                  "pointer to a function used in arithmetic");
    3395                 :             :       else if (!complain)
    3396                 :           0 :         return error_mark_node;
    3397                 :         118 :       size_exp = integer_one_node;
    3398                 :             :     }
    3399                 :     5397472 :   else if (!verify_type_context (loc, TCTX_POINTER_ARITH,
    3400                 :     5397472 :                                  TREE_TYPE (result_type)))
    3401                 :           0 :     size_exp = integer_one_node;
    3402                 :             :   else
    3403                 :             :     {
    3404                 :     5397472 :       if (!complain && !COMPLETE_TYPE_P (TREE_TYPE (result_type)))
    3405                 :         108 :         return error_mark_node;
    3406                 :     5397364 :       size_exp = size_in_bytes_loc (loc, TREE_TYPE (result_type));
    3407                 :             :       /* Wrap the pointer expression in a SAVE_EXPR to make sure it
    3408                 :             :          is evaluated first when the size expression may depend
    3409                 :             :          on it for VM types.  */
    3410                 :     5397364 :       if (TREE_SIDE_EFFECTS (size_exp)
    3411                 :        1935 :           && TREE_SIDE_EFFECTS (ptrop)
    3412                 :     5397383 :           && variably_modified_type_p (TREE_TYPE (ptrop), NULL))
    3413                 :             :         {
    3414                 :          19 :           ptrop = save_expr (ptrop);
    3415                 :          19 :           size_exp = build2 (COMPOUND_EXPR, TREE_TYPE (intop), ptrop, size_exp);
    3416                 :             :         }
    3417                 :             :     }
    3418                 :             : 
    3419                 :             :   /* We are manipulating pointer values, so we don't need to warn
    3420                 :             :      about relying on undefined signed overflow.  We disable the
    3421                 :             :      warning here because we use integer types so fold won't know that
    3422                 :             :      they are really pointers.  */
    3423                 :     5398382 :   fold_defer_overflow_warnings ();
    3424                 :             : 
    3425                 :             :   /* If what we are about to multiply by the size of the elements
    3426                 :             :      contains a constant term, apply distributive law
    3427                 :             :      and multiply that constant term separately.
    3428                 :             :      This helps produce common subexpressions.  */
    3429                 :     5398382 :   if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR)
    3430                 :      172879 :       && !TREE_CONSTANT (intop)
    3431                 :      172797 :       && TREE_CONSTANT (TREE_OPERAND (intop, 1))
    3432                 :      138185 :       && TREE_CONSTANT (size_exp)
    3433                 :             :       /* If the constant comes from pointer subtraction,
    3434                 :             :          skip this optimization--it would cause an error.  */
    3435                 :      138184 :       && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop, 0))) == INTEGER_TYPE
    3436                 :             :       /* If the constant is unsigned, and smaller than the pointer size,
    3437                 :             :          then we must skip this optimization.  This is because it could cause
    3438                 :             :          an overflow error if the constant is negative but INTOP is not.  */
    3439                 :      276368 :       && (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (intop))
    3440                 :      118326 :           || (TYPE_PRECISION (TREE_TYPE (intop))
    3441                 :      118326 :               == TYPE_PRECISION (TREE_TYPE (ptrop))))
    3442                 :     5570464 :       && TYPE_PRECISION (TREE_TYPE (intop)) <= TYPE_PRECISION (sizetype))
    3443                 :             :     {
    3444                 :       33898 :       tree intop0 = TREE_OPERAND (intop, 0);
    3445                 :       33898 :       tree intop1 = TREE_OPERAND (intop, 1);
    3446                 :       33898 :       if (TYPE_PRECISION (TREE_TYPE (intop)) != TYPE_PRECISION (sizetype)
    3447                 :       33898 :           || TYPE_UNSIGNED (TREE_TYPE (intop)) != TYPE_UNSIGNED (sizetype))
    3448                 :             :         {
    3449                 :       19858 :           tree optype = c_common_type_for_size (TYPE_PRECISION (sizetype),
    3450                 :       19858 :                                                 TYPE_UNSIGNED (sizetype));
    3451                 :       19858 :           intop0 = convert (optype, intop0);
    3452                 :       19858 :           intop1 = convert (optype, intop1);
    3453                 :             :         }
    3454                 :       33898 :       tree t = fold_build2_loc (loc, MULT_EXPR, TREE_TYPE (intop0), intop0,
    3455                 :       33898 :                                 convert (TREE_TYPE (intop0), size_exp));
    3456                 :       33898 :       intop0 = convert (sizetype, t);
    3457                 :       33898 :       if (TREE_OVERFLOW_P (intop0) && !TREE_OVERFLOW (t))
    3458                 :           0 :         intop0 = wide_int_to_tree (TREE_TYPE (intop0), wi::to_wide (intop0));
    3459                 :       33898 :       t = fold_build2_loc (loc, MULT_EXPR, TREE_TYPE (intop1), intop1,
    3460                 :       33898 :                            convert (TREE_TYPE (intop1), size_exp));
    3461                 :       33898 :       intop1 = convert (sizetype, t);
    3462                 :       33898 :       if (TREE_OVERFLOW_P (intop1) && !TREE_OVERFLOW (t))
    3463                 :           0 :         intop1 = wide_int_to_tree (TREE_TYPE (intop1), wi::to_wide (intop1));
    3464                 :       33898 :       intop = build_binary_op (EXPR_LOCATION (intop), TREE_CODE (intop),
    3465                 :             :                                intop0, intop1, true);
    3466                 :             : 
    3467                 :             :       /* Create the sum or difference.  */
    3468                 :       33898 :       if (resultcode == MINUS_EXPR)
    3469                 :          51 :         intop = fold_build1_loc (loc, NEGATE_EXPR, sizetype, intop);
    3470                 :             : 
    3471                 :       33898 :       ret = fold_build_pointer_plus_loc (loc, ptrop, intop);
    3472                 :             : 
    3473                 :       33898 :       fold_undefer_and_ignore_overflow_warnings ();
    3474                 :             : 
    3475                 :       33898 :       return ret;
    3476                 :             :     }
    3477                 :             : 
    3478                 :             :   /* Convert the integer argument to a type the same size as sizetype
    3479                 :             :      so the multiply won't overflow spuriously.  */
    3480                 :     5364484 :   if (TYPE_PRECISION (TREE_TYPE (intop)) != TYPE_PRECISION (sizetype)
    3481                 :     5364484 :       || TYPE_UNSIGNED (TREE_TYPE (intop)) != TYPE_UNSIGNED (sizetype))
    3482                 :     3708825 :     intop = convert (c_common_type_for_size (TYPE_PRECISION (sizetype),
    3483                 :     3708825 :                                              TYPE_UNSIGNED (sizetype)), intop);
    3484                 :             : 
    3485                 :             :   /* Replace the integer argument with a suitable product by the object size.
    3486                 :             :      Do this multiplication as signed, then convert to the appropriate type
    3487                 :             :      for the pointer operation and disregard an overflow that occurred only
    3488                 :             :      because of the sign-extension change in the latter conversion.  */
    3489                 :     5364484 :   {
    3490                 :     5364484 :     tree t = fold_build2_loc (loc, MULT_EXPR, TREE_TYPE (intop), intop,
    3491                 :     5364484 :                               convert (TREE_TYPE (intop), size_exp));
    3492                 :     5364484 :     intop = convert (sizetype, t);
    3493                 :     5364484 :     if (TREE_OVERFLOW_P (intop) && !TREE_OVERFLOW (t))
    3494                 :           0 :       intop = wide_int_to_tree (TREE_TYPE (intop), wi::to_wide (intop));
    3495                 :             :   }
    3496                 :             : 
    3497                 :             :   /* Create the sum or difference.  */
    3498                 :     5364484 :   if (resultcode == MINUS_EXPR)
    3499                 :      168735 :     intop = fold_build1_loc (loc, NEGATE_EXPR, sizetype, intop);
    3500                 :             : 
    3501                 :     5364484 :   ret = fold_build_pointer_plus_loc (loc, ptrop, intop);
    3502                 :             : 
    3503                 :     5364484 :   fold_undefer_and_ignore_overflow_warnings ();
    3504                 :             : 
    3505                 :     5364484 :   return ret;
    3506                 :             : }
    3507                 :             : 
    3508                 :             : /* Wrap a C_MAYBE_CONST_EXPR around an expression that is fully folded
    3509                 :             :    and if NON_CONST is known not to be permitted in an evaluated part
    3510                 :             :    of a constant expression.  */
    3511                 :             : 
    3512                 :             : tree
    3513                 :     4375693 : c_wrap_maybe_const (tree expr, bool non_const)
    3514                 :             : {
    3515                 :     4375693 :   location_t loc = EXPR_LOCATION (expr);
    3516                 :             : 
    3517                 :             :   /* This should never be called for C++.  */
    3518                 :     4375693 :   if (c_dialect_cxx ())
    3519                 :           0 :     gcc_unreachable ();
    3520                 :             : 
    3521                 :             :   /* The result of folding may have a NOP_EXPR to set TREE_NO_WARNING.  */
    3522                 :     4376439 :   STRIP_TYPE_NOPS (expr);
    3523                 :     4375693 :   expr = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (expr), NULL, expr);
    3524                 :     4375693 :   C_MAYBE_CONST_EXPR_NON_CONST (expr) = non_const;
    3525                 :     4375693 :   protected_set_expr_location (expr, loc);
    3526                 :             : 
    3527                 :     4375693 :   return expr;
    3528                 :             : }
    3529                 :             : 
    3530                 :             : /* Return whether EXPR is a declaration whose address can never be NULL.
    3531                 :             :    The address of the first struct member could be NULL only if it were
    3532                 :             :    accessed through a NULL pointer, and such an access would be invalid.
    3533                 :             :    The address of a weak symbol may be null unless it has a definition.  */
    3534                 :             : 
    3535                 :             : bool
    3536                 :        1409 : decl_with_nonnull_addr_p (const_tree expr)
    3537                 :             : {
    3538                 :        1409 :   if (!DECL_P (expr))
    3539                 :             :     return false;
    3540                 :             : 
    3541                 :        1155 :   if (TREE_CODE (expr) == FIELD_DECL
    3542                 :        1078 :       || TREE_CODE (expr) == PARM_DECL
    3543                 :        1044 :       || TREE_CODE (expr) == LABEL_DECL)
    3544                 :             :     return true;
    3545                 :             : 
    3546                 :        1019 :   if (!VAR_OR_FUNCTION_DECL_P (expr))
    3547                 :             :     return false;
    3548                 :             : 
    3549                 :        1019 :   if (!DECL_WEAK (expr))
    3550                 :             :     /* Ordinary (non-weak) symbols have nonnull addresses.  */
    3551                 :             :     return true;
    3552                 :             : 
    3553                 :         528 :   if (DECL_INITIAL (expr) && DECL_INITIAL (expr) != error_mark_node)
    3554                 :             :     /* Initialized weak symbols have nonnull addresses.  */
    3555                 :             :     return true;
    3556                 :             : 
    3557                 :         475 :   if (DECL_EXTERNAL (expr) || !TREE_STATIC (expr))
    3558                 :             :     /* Uninitialized extern weak symbols and weak symbols with no
    3559                 :             :        allocated storage might have a null address.  */
    3560                 :             :     return false;
    3561                 :             : 
    3562                 :          43 :   tree attribs = DECL_ATTRIBUTES (expr);
    3563                 :          43 :   if (lookup_attribute ("weakref", attribs))
    3564                 :             :     /* Weakref symbols might have a null address unless their referent
    3565                 :             :        is known not to.  Don't bother following weakref targets here.  */
    3566                 :             :     return false;
    3567                 :             : 
    3568                 :             :   return true;
    3569                 :             : }
    3570                 :             : 
    3571                 :             : /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
    3572                 :             :    or for an `if' or `while' statement or ?..: exp.  It should already
    3573                 :             :    have been validated to be of suitable type; otherwise, a bad
    3574                 :             :    diagnostic may result.
    3575                 :             : 
    3576                 :             :    The EXPR is located at LOCATION.
    3577                 :             : 
    3578                 :             :    This preparation consists of taking the ordinary
    3579                 :             :    representation of an expression expr and producing a valid tree
    3580                 :             :    boolean expression describing whether expr is nonzero.  We could
    3581                 :             :    simply always do build_binary_op (NE_EXPR, expr, truthvalue_false_node, 1),
    3582                 :             :    but we optimize comparisons, &&, ||, and !.
    3583                 :             : 
    3584                 :             :    The resulting type should always be `truthvalue_type_node'.  */
    3585                 :             : 
    3586                 :             : tree
    3587                 :    10451363 : c_common_truthvalue_conversion (location_t location, tree expr)
    3588                 :             : {
    3589                 :    11252580 :   STRIP_ANY_LOCATION_WRAPPER (expr);
    3590                 :    11252580 :   switch (TREE_CODE (expr))
    3591                 :             :     {
    3592                 :     2444972 :     case EQ_EXPR:   case NE_EXPR:   case UNEQ_EXPR: case LTGT_EXPR:
    3593                 :     2444972 :     case LE_EXPR:   case GE_EXPR:   case LT_EXPR:   case GT_EXPR:
    3594                 :     2444972 :     case UNLE_EXPR: case UNGE_EXPR: case UNLT_EXPR: case UNGT_EXPR:
    3595                 :     2444972 :     case ORDERED_EXPR: case UNORDERED_EXPR:
    3596                 :     2444972 :       if (TREE_TYPE (expr) == truthvalue_type_node)
    3597                 :             :         return expr;
    3598                 :      397451 :       expr = build2 (TREE_CODE (expr), truthvalue_type_node,
    3599                 :      397451 :                      TREE_OPERAND (expr, 0), TREE_OPERAND (expr, 1));
    3600                 :      397451 :       goto ret;
    3601                 :             : 
    3602                 :      588583 :     case TRUTH_ANDIF_EXPR:
    3603                 :      588583 :     case TRUTH_ORIF_EXPR:
    3604                 :      588583 :     case TRUTH_AND_EXPR:
    3605                 :      588583 :     case TRUTH_OR_EXPR:
    3606                 :      588583 :     case TRUTH_XOR_EXPR:
    3607                 :      588583 :       if (TREE_TYPE (expr) == truthvalue_type_node)
    3608                 :             :         return expr;
    3609                 :          74 :       expr = build2 (TREE_CODE (expr), truthvalue_type_node,
    3610                 :             :                      c_common_truthvalue_conversion (location,
    3611                 :          37 :                                                      TREE_OPERAND (expr, 0)),
    3612                 :             :                      c_common_truthvalue_conversion (location,
    3613                 :          37 :                                                      TREE_OPERAND (expr, 1)));
    3614                 :          37 :       goto ret;
    3615                 :             : 
    3616                 :      322401 :     case TRUTH_NOT_EXPR:
    3617                 :      322401 :       if (TREE_TYPE (expr) == truthvalue_type_node)
    3618                 :             :         return expr;
    3619                 :      319462 :       expr = build1 (TREE_CODE (expr), truthvalue_type_node,
    3620                 :             :                      c_common_truthvalue_conversion (location,
    3621                 :      319462 :                                                      TREE_OPERAND (expr, 0)));
    3622                 :      319462 :       goto ret;
    3623                 :             : 
    3624                 :             :     case ERROR_MARK:
    3625                 :             :       return expr;
    3626                 :             : 
    3627                 :     2605778 :     case INTEGER_CST:
    3628                 :     2605778 :       if (TREE_CODE (TREE_TYPE (expr)) == ENUMERAL_TYPE
    3629                 :      762414 :           && !integer_zerop (expr)
    3630                 :     3085341 :           && !integer_onep (expr))
    3631                 :         914 :         warning_at (location, OPT_Wint_in_bool_context,
    3632                 :             :                     "enum constant in boolean context");
    3633                 :     2605778 :       return integer_zerop (expr) ? truthvalue_false_node
    3634                 :     2605778 :                                   : truthvalue_true_node;
    3635                 :             : 
    3636                 :        1288 :     case REAL_CST:
    3637                 :        1288 :       return real_compare (NE_EXPR, &TREE_REAL_CST (expr), &dconst0)
    3638                 :        1288 :              ? truthvalue_true_node
    3639                 :        1288 :              : truthvalue_false_node;
    3640                 :             : 
    3641                 :           0 :     case FIXED_CST:
    3642                 :           0 :       return fixed_compare (NE_EXPR, &TREE_FIXED_CST (expr),
    3643                 :           0 :                             &FCONST0 (TYPE_MODE (TREE_TYPE (expr))))
    3644                 :           0 :              ? truthvalue_true_node
    3645                 :           0 :              : truthvalue_false_node;
    3646                 :             : 
    3647                 :           0 :     case FUNCTION_DECL:
    3648                 :           0 :       expr = build_unary_op (location, ADDR_EXPR, expr, false);
    3649                 :             :       /* Fall through.  */
    3650                 :             : 
    3651                 :         578 :     case ADDR_EXPR:
    3652                 :         578 :       {
    3653                 :         578 :         tree inner = TREE_OPERAND (expr, 0);
    3654                 :         578 :         if (decl_with_nonnull_addr_p (inner)
    3655                 :             :             /* Check both EXPR and INNER for suppression.  */
    3656                 :         127 :             && !warning_suppressed_p (expr, OPT_Waddress)
    3657                 :         691 :             && !warning_suppressed_p (inner, OPT_Waddress))
    3658                 :             :           {
    3659                 :             :             /* Common Ada programmer's mistake.  */
    3660                 :         107 :             warning_at (location,
    3661                 :         107 :                         OPT_Waddress,
    3662                 :             :                         "the address of %qD will always evaluate as %<true%>",
    3663                 :             :                         inner);
    3664                 :         107 :             suppress_warning (inner, OPT_Waddress);
    3665                 :         107 :             return truthvalue_true_node;
    3666                 :             :           }
    3667                 :             :         break;
    3668                 :             :       }
    3669                 :             : 
    3670                 :         578 :     case COMPLEX_EXPR:
    3671                 :        1734 :       expr = build_binary_op (EXPR_LOCATION (expr),
    3672                 :         578 :                               (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1))
    3673                 :             :                                ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
    3674                 :             :                 c_common_truthvalue_conversion (location,
    3675                 :         578 :                                                 TREE_OPERAND (expr, 0)),
    3676                 :             :                 c_common_truthvalue_conversion (location,
    3677                 :         578 :                                                 TREE_OPERAND (expr, 1)),
    3678                 :             :                               false);
    3679                 :         578 :       goto ret;
    3680                 :             : 
    3681                 :          74 :     case NEGATE_EXPR:
    3682                 :          74 :     case ABS_EXPR:
    3683                 :          74 :     case ABSU_EXPR:
    3684                 :          74 :     case FLOAT_EXPR:
    3685                 :          74 :     case EXCESS_PRECISION_EXPR:
    3686                 :             :       /* These don't change whether an object is nonzero or zero.  */
    3687                 :          74 :       return c_common_truthvalue_conversion (location, TREE_OPERAND (expr, 0));
    3688                 :             : 
    3689                 :           0 :     case LROTATE_EXPR:
    3690                 :           0 :     case RROTATE_EXPR:
    3691                 :             :       /* These don't change whether an object is zero or nonzero, but
    3692                 :             :          we can't ignore them if their second arg has side-effects.  */
    3693                 :           0 :       if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1)))
    3694                 :             :         {
    3695                 :           0 :           expr = build2 (COMPOUND_EXPR, truthvalue_type_node,
    3696                 :           0 :                          TREE_OPERAND (expr, 1),
    3697                 :             :                          c_common_truthvalue_conversion
    3698                 :           0 :                          (location, TREE_OPERAND (expr, 0)));
    3699                 :           0 :           goto ret;
    3700                 :             :         }
    3701                 :             :       else
    3702                 :           0 :         return c_common_truthvalue_conversion (location,
    3703                 :           0 :                                                TREE_OPERAND (expr, 0));
    3704                 :             : 
    3705                 :         502 :     case MULT_EXPR:
    3706                 :         502 :       warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context,
    3707                 :             :                   "%<*%> in boolean context, suggest %<&&%> instead");
    3708                 :         502 :       break;
    3709                 :             : 
    3710                 :         166 :     case LSHIFT_EXPR:
    3711                 :             :       /* We will only warn on signed shifts here, because the majority of
    3712                 :             :          false positive warnings happen in code where unsigned arithmetic
    3713                 :             :          was used in anticipation of a possible overflow.
    3714                 :             :          Furthermore, if we see an unsigned type here we know that the
    3715                 :             :          result of the shift is not subject to integer promotion rules.  */
    3716                 :         166 :       if ((TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
    3717                 :           1 :            || TREE_CODE (TREE_TYPE (expr)) == BITINT_TYPE)
    3718                 :         167 :           && !TYPE_UNSIGNED (TREE_TYPE (expr)))
    3719                 :         150 :         warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context,
    3720                 :             :                     "%<<<%> in boolean context, did you mean %<<%>?");
    3721                 :             :       break;
    3722                 :             : 
    3723                 :       34855 :     case COND_EXPR:
    3724                 :       34855 :       if (warn_int_in_bool_context
    3725                 :       36331 :           && !from_macro_definition_at (EXPR_LOCATION (expr)))
    3726                 :             :         {
    3727                 :         725 :           tree val1 = fold_for_warn (TREE_OPERAND (expr, 1));
    3728                 :         725 :           tree val2 = fold_for_warn (TREE_OPERAND (expr, 2));
    3729                 :         725 :           if (TREE_CODE (val1) == INTEGER_CST
    3730                 :          78 :               && TREE_CODE (val2) == INTEGER_CST
    3731                 :          78 :               && !integer_zerop (val1)
    3732                 :          70 :               && !integer_zerop (val2)
    3733                 :         741 :               && (!integer_onep (val1)
    3734                 :          12 :                   || !integer_onep (val2)))
    3735                 :          12 :             warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context,
    3736                 :             :                         "%<?:%> using integer constants in boolean context, "
    3737                 :             :                         "the expression will always evaluate to %<true%>");
    3738                 :         713 :           else if ((TREE_CODE (val1) == INTEGER_CST
    3739                 :          66 :                     && !integer_zerop (val1)
    3740                 :          58 :                     && !integer_onep (val1))
    3741                 :         779 :                    || (TREE_CODE (val2) == INTEGER_CST
    3742                 :         316 :                        && !integer_zerop (val2)
    3743                 :         258 :                        && !integer_onep (val2)))
    3744                 :           4 :             warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context,
    3745                 :             :                         "%<?:%> using integer constants in boolean context");
    3746                 :             :         }
    3747                 :             :       /* Distribute the conversion into the arms of a COND_EXPR.  */
    3748                 :       34855 :       if (c_dialect_cxx ())
    3749                 :             :         /* Avoid premature folding.  */
    3750                 :             :         break;
    3751                 :             :       else
    3752                 :             :         {
    3753                 :       10044 :           int w = warn_int_in_bool_context;
    3754                 :       10044 :           warn_int_in_bool_context = 0;
    3755                 :             :           /* Folding will happen later for C.  */
    3756                 :       30132 :           expr = build3 (COND_EXPR, truthvalue_type_node,
    3757                 :       10044 :                          TREE_OPERAND (expr, 0),
    3758                 :             :                          c_common_truthvalue_conversion (location,
    3759                 :       10044 :                                                          TREE_OPERAND (expr, 1)),
    3760                 :             :                          c_common_truthvalue_conversion (location,
    3761                 :       10044 :                                                          TREE_OPERAND (expr, 2)));
    3762                 :       10044 :           warn_int_in_bool_context = w;
    3763                 :       10044 :           goto ret;
    3764                 :             :         }
    3765                 :             : 
    3766                 :      584619 :     CASE_CONVERT:
    3767                 :      584619 :       {
    3768                 :      584619 :         tree totype = TREE_TYPE (expr);
    3769                 :      584619 :         tree fromtype = TREE_TYPE (TREE_OPERAND (expr, 0));
    3770                 :             : 
    3771                 :      584619 :         if (POINTER_TYPE_P (totype)
    3772                 :        2016 :             && !c_inhibit_evaluation_warnings
    3773                 :        1848 :             && TREE_CODE (fromtype) == REFERENCE_TYPE)
    3774                 :             :           {
    3775                 :           0 :             tree inner = expr;
    3776                 :           0 :             STRIP_NOPS (inner);
    3777                 :             : 
    3778                 :           0 :             if (DECL_P (inner))
    3779                 :           0 :               warning_at (location,
    3780                 :           0 :                           OPT_Waddress,
    3781                 :             :                           "the compiler can assume that the address of "
    3782                 :             :                           "%qD will always evaluate to %<true%>",
    3783                 :             :                           inner);
    3784                 :             :           }
    3785                 :             : 
    3786                 :             :         /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
    3787                 :             :            since that affects how `default_conversion' will behave.  */
    3788                 :      584619 :         if (TREE_CODE (totype) == REFERENCE_TYPE
    3789                 :      584619 :             || TREE_CODE (fromtype) == REFERENCE_TYPE)
    3790                 :             :           break;
    3791                 :             :         /* Don't strip a conversion from C++0x scoped enum, since they
    3792                 :             :            don't implicitly convert to other types.  */
    3793                 :      584619 :         if (TREE_CODE (fromtype) == ENUMERAL_TYPE
    3794                 :      584619 :             && ENUM_IS_SCOPED (fromtype))
    3795                 :             :           break;
    3796                 :             :         /* If this isn't narrowing the argument, we can ignore it.  */
    3797                 :      584580 :         if (TYPE_PRECISION (totype) >= TYPE_PRECISION (fromtype))
    3798                 :             :           {
    3799                 :      567264 :             tree op0 = TREE_OPERAND (expr, 0);
    3800                 :      567264 :             if ((TREE_CODE (fromtype) == POINTER_TYPE
    3801                 :        1932 :                  && (TREE_CODE (totype) == INTEGER_TYPE
    3802                 :        1932 :                      || TREE_CODE (totype) == BITINT_TYPE))
    3803                 :      569164 :                 || warning_suppressed_p (expr, OPT_Waddress))
    3804                 :             :               /* Suppress -Waddress for casts to intptr_t, propagating
    3805                 :             :                  any suppression from the enclosing expression to its
    3806                 :             :                  operand.  */
    3807                 :          44 :               suppress_warning (op0, OPT_Waddress);
    3808                 :      567264 :             return c_common_truthvalue_conversion (location, op0);
    3809                 :             :           }
    3810                 :             :       }
    3811                 :             :       break;
    3812                 :             : 
    3813                 :        8868 :     case MODIFY_EXPR:
    3814                 :        8868 :       if (!warning_suppressed_p (expr, OPT_Wparentheses)
    3815                 :         305 :           && warn_parentheses
    3816                 :        9173 :           && warning_at (location, OPT_Wparentheses,
    3817                 :             :                          "suggest parentheses around assignment used as "
    3818                 :             :                          "truth value"))
    3819                 :          14 :         suppress_warning (expr, OPT_Wparentheses);
    3820                 :             :       break;
    3821                 :             : 
    3822                 :      233896 :     case CONST_DECL:
    3823                 :      233896 :       {
    3824                 :      233896 :         tree folded_expr = fold_for_warn (expr);
    3825                 :      233896 :         if (folded_expr != expr)
    3826                 :             :           return c_common_truthvalue_conversion (location, folded_expr);
    3827                 :             :       }
    3828                 :             :       break;
    3829                 :             : 
    3830                 :             :     default:
    3831                 :             :       break;
    3832                 :             :     }
    3833                 :             : 
    3834                 :     4477389 :   if (TREE_CODE (TREE_TYPE (expr)) == COMPLEX_TYPE)
    3835                 :             :     {
    3836                 :         405 :       tree t = save_expr (expr);
    3837                 :         405 :       expr = (build_binary_op
    3838                 :         810 :               (EXPR_LOCATION (expr),
    3839                 :         405 :                (TREE_SIDE_EFFECTS (expr)
    3840                 :             :                 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
    3841                 :             :         c_common_truthvalue_conversion
    3842                 :             :                (location,
    3843                 :             :                 build_unary_op (location, REALPART_EXPR, t, false)),
    3844                 :             :         c_common_truthvalue_conversion
    3845                 :             :                (location,
    3846                 :             :                 build_unary_op (location, IMAGPART_EXPR, t, false)),
    3847                 :             :                false));
    3848                 :         405 :       goto ret;
    3849                 :             :     }
    3850                 :             : 
    3851                 :     4476984 :   if (FIXED_POINT_TYPE_P (TREE_TYPE (expr)))
    3852                 :             :     {
    3853                 :           0 :       tree fixed_zero_node = build_fixed (TREE_TYPE (expr),
    3854                 :           0 :                                           FCONST0 (TYPE_MODE
    3855                 :             :                                                    (TREE_TYPE (expr))));
    3856                 :           0 :       return build_binary_op (location, NE_EXPR, expr, fixed_zero_node, true);
    3857                 :             :     }
    3858                 :             :   else
    3859                 :     4476984 :     return build_binary_op (location, NE_EXPR, expr, integer_zero_node, true);
    3860                 :             : 
    3861                 :      727977 :  ret:
    3862                 :      727977 :   protected_set_expr_location (expr, location);
    3863                 :      727977 :   return expr;
    3864                 :             : }
    3865                 :             : 
    3866                 :             : static void def_builtin_1  (enum built_in_function fncode,
    3867                 :             :                             const char *name,
    3868                 :             :                             enum built_in_class fnclass,
    3869                 :             :                             tree fntype, tree libtype,
    3870                 :             :                             bool both_p, bool fallback_p, bool nonansi_p,
    3871                 :             :                             tree fnattrs, bool implicit_p);
    3872                 :             : 
    3873                 :             : 
    3874                 :             : /* Apply the TYPE_QUALS to the new DECL.  */
    3875                 :             : 
    3876                 :             : void
    3877                 :   943248134 : c_apply_type_quals_to_decl (int type_quals, tree decl)
    3878                 :             : {
    3879                 :   943248134 :   tree type = TREE_TYPE (decl);
    3880                 :             : 
    3881                 :   943248134 :   if (type == error_mark_node)
    3882                 :             :     return;
    3883                 :             : 
    3884                 :   943247911 :   if ((type_quals & TYPE_QUAL_CONST)
    3885                 :   608699841 :       || (type && TREE_CODE (type) == REFERENCE_TYPE))
    3886                 :             :     /* We used to check TYPE_NEEDS_CONSTRUCTING here, but now a constexpr
    3887                 :             :        constructor can produce constant init, so rely on cp_finish_decl to
    3888                 :             :        clear TREE_READONLY if the variable has non-constant init.  */
    3889                 :   424665708 :     TREE_READONLY (decl) = 1;
    3890                 :   943247911 :   if (type_quals & TYPE_QUAL_VOLATILE)
    3891                 :             :     {
    3892                 :      134455 :       TREE_SIDE_EFFECTS (decl) = 1;
    3893                 :      134455 :       TREE_THIS_VOLATILE (decl) = 1;
    3894                 :             :     }
    3895                 :   943247911 :   if (type_quals & TYPE_QUAL_RESTRICT)
    3896                 :             :     {
    3897                 :    10772113 :       while (type && TREE_CODE (type) == ARRAY_TYPE)
    3898                 :             :         /* Allow 'restrict' on arrays of pointers.
    3899                 :             :            FIXME currently we just ignore it.  */
    3900                 :           7 :         type = TREE_TYPE (type);
    3901                 :    10772106 :       if (!type
    3902                 :    10772106 :           || !POINTER_TYPE_P (type)
    3903                 :    21544210 :           || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type)))
    3904                 :           3 :         error ("invalid use of %<restrict%>");
    3905                 :             :     }
    3906                 :             : }
    3907                 :             : 
    3908                 :             : /* Return the typed-based alias set for T, which may be an expression
    3909                 :             :    or a type.  Return -1 if we don't do anything special.  */
    3910                 :             : 
    3911                 :             : alias_set_type
    3912                 :   627884925 : c_common_get_alias_set (tree t)
    3913                 :             : {
    3914                 :             :   /* For VLAs, use the alias set of the element type rather than the
    3915                 :             :      default of alias set 0 for types compared structurally.  */
    3916                 :   627884925 :   if (TYPE_P (t) && TYPE_STRUCTURAL_EQUALITY_P (t))
    3917                 :             :     {
    3918                 :      766667 :       if (TREE_CODE (t) == ARRAY_TYPE)
    3919                 :      428349 :         return get_alias_set (TREE_TYPE (t));
    3920                 :             :       return -1;
    3921                 :             :     }
    3922                 :             : 
    3923                 :             :   /* That's all the expressions we handle specially.  */
    3924                 :   627118258 :   if (!TYPE_P (t))
    3925                 :             :     return -1;
    3926                 :             : 
    3927                 :             :   /* Unlike char, char8_t doesn't alias in C++.  (In C, char8_t is not
    3928                 :             :      a distinct type.)  */
    3929                 :   103921704 :   if (flag_char8_t && t == char8_type_node && c_dialect_cxx ())
    3930                 :             :     return -1;
    3931                 :             : 
    3932                 :             :   /* The C standard guarantees that any object may be accessed via an
    3933                 :             :      lvalue that has narrow character type.  */
    3934                 :   103921635 :   if (t == char_type_node
    3935                 :    70002693 :       || t == signed_char_type_node
    3936                 :    66082117 :       || t == unsigned_char_type_node)
    3937                 :             :     return 0;
    3938                 :             : 
    3939                 :             :   /* The C standard specifically allows aliasing between signed and
    3940                 :             :      unsigned variants of the same type.  We treat the signed
    3941                 :             :      variant as canonical.  */
    3942                 :    55267118 :   if ((TREE_CODE (t) == INTEGER_TYPE || TREE_CODE (t) == BITINT_TYPE)
    3943                 :    55267118 :       && TYPE_UNSIGNED (t))
    3944                 :             :     {
    3945                 :    53653992 :       tree t1 = c_common_signed_type (t);
    3946                 :             : 
    3947                 :             :       /* t1 == t can happen for boolean nodes which are always unsigned.  */
    3948                 :    53653992 :       if (t1 != t)
    3949                 :    53653992 :         return get_alias_set (t1);
    3950                 :             :     }
    3951                 :             : 
    3952                 :             :   return -1;
    3953                 :             : }
    3954                 :             : 
    3955                 :             : /* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where
    3956                 :             :    the IS_SIZEOF parameter indicates which operator is being applied.
    3957                 :             :    The COMPLAIN flag controls whether we should diagnose possibly
    3958                 :             :    ill-formed constructs or not.  LOC is the location of the SIZEOF or
    3959                 :             :    TYPEOF operator.  If MIN_ALIGNOF, the least alignment required for
    3960                 :             :    a type in any context should be returned, rather than the normal
    3961                 :             :    alignment for that type.  */
    3962                 :             : 
    3963                 :             : tree
    3964                 :    18726952 : c_sizeof_or_alignof_type (location_t loc,
    3965                 :             :                           tree type, bool is_sizeof, bool min_alignof,
    3966                 :             :                           int complain)
    3967                 :             : {
    3968                 :    18726952 :   const char *op_name;
    3969                 :    18726952 :   tree value = NULL;
    3970                 :    18726952 :   enum tree_code type_code = TREE_CODE (type);
    3971                 :             : 
    3972                 :    18726952 :   op_name = is_sizeof ? "sizeof" : "__alignof__";
    3973                 :             : 
    3974                 :    18726952 :   if (type_code == FUNCTION_TYPE)
    3975                 :             :     {
    3976                 :          64 :       if (is_sizeof)
    3977                 :             :         {
    3978                 :          58 :           if (complain && warn_pointer_arith)
    3979                 :          28 :             pedwarn (loc, OPT_Wpointer_arith,
    3980                 :             :                      "invalid application of %<sizeof%> to a function type");
    3981                 :             :           else if (!complain)
    3982                 :          20 :             return error_mark_node;
    3983                 :          38 :           value = size_one_node;
    3984                 :             :         }
    3985                 :             :       else
    3986                 :             :         {
    3987                 :           6 :           if (complain)
    3988                 :             :             {
    3989                 :           6 :               if (c_dialect_cxx ())
    3990                 :           4 :                 pedwarn (loc, OPT_Wpedantic, "ISO C++ does not permit "
    3991                 :             :                          "%<alignof%> applied to a function type");
    3992                 :             :               else
    3993                 :           2 :                 pedwarn (loc, OPT_Wpedantic, "ISO C does not permit "
    3994                 :             :                          "%<_Alignof%> applied to a function type");
    3995                 :             :             }
    3996                 :           6 :           value = size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
    3997                 :             :         }
    3998                 :             :     }
    3999                 :    18726888 :   else if (type_code == VOID_TYPE || type_code == ERROR_MARK)
    4000                 :             :     {
    4001                 :          79 :       if (type_code == VOID_TYPE
    4002                 :          79 :           && complain && warn_pointer_arith)
    4003                 :          19 :         pedwarn (loc, OPT_Wpointer_arith,
    4004                 :             :                  "invalid application of %qs to a void type", op_name);
    4005                 :          60 :       else if (!complain)
    4006                 :          30 :         return error_mark_node;
    4007                 :          49 :       value = size_one_node;
    4008                 :             :     }
    4009                 :    18726809 :   else if (!COMPLETE_TYPE_P (type)
    4010                 :    18726809 :            && ((!c_dialect_cxx () && !flag_isoc2y)
    4011                 :             :                || is_sizeof
    4012                 :         144 :                || type_code != ARRAY_TYPE))
    4013                 :             :     {
    4014                 :         271 :       if (complain)
    4015                 :         194 :         error_at (loc, "invalid application of %qs to incomplete type %qT",
    4016                 :             :                   op_name, type);
    4017                 :         271 :       return error_mark_node;
    4018                 :             :     }
    4019                 :    18048766 :   else if (c_dialect_cxx () && type_code == ARRAY_TYPE
    4020                 :    19173464 :            && !COMPLETE_TYPE_P (TREE_TYPE (type)))
    4021                 :             :     {
    4022                 :           0 :       if (complain)
    4023                 :           0 :         error_at (loc, "invalid application of %qs to array type %qT of "
    4024                 :             :                   "incomplete element type", op_name, type);
    4025                 :           0 :       return error_mark_node;
    4026                 :             :     }
    4027                 :    19660237 :   else if (!verify_type_context (loc, is_sizeof ? TCTX_SIZEOF : TCTX_ALIGNOF,
    4028                 :             :                                  type, !complain))
    4029                 :             :     {
    4030                 :           0 :       if (!complain)
    4031                 :           0 :         return error_mark_node;
    4032                 :           0 :       value = size_one_node;
    4033                 :             :     }
    4034                 :             :   else
    4035                 :             :     {
    4036                 :    18726538 :       if (is_sizeof)
    4037                 :             :         /* Convert in case a char is more than one unit.  */
    4038                 :    17792839 :         value = size_binop_loc (loc, CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
    4039                 :    17792839 :                                 size_int (TYPE_PRECISION (char_type_node)
    4040                 :             :                                           / BITS_PER_UNIT));
    4041                 :      933699 :       else if (min_alignof)
    4042                 :      726654 :         value = size_int (min_align_of_type (type));
    4043                 :             :       else
    4044                 :      207045 :         value = size_int (TYPE_ALIGN_UNIT (type));
    4045                 :             :     }
    4046                 :             : 
    4047                 :             :   /* VALUE will have the middle-end integer type sizetype.
    4048                 :             :      However, we should really return a value of type `size_t',
    4049                 :             :      which is just a typedef for an ordinary integer type.  */
    4050                 :    18726631 :   value = fold_convert_loc (loc, size_type_node, value);
    4051                 :             : 
    4052                 :    18726631 :   return value;
    4053                 :             : }
    4054                 :             : 
    4055                 :             : /* Implement the __alignof keyword: Return the minimum required
    4056                 :             :    alignment of EXPR, measured in bytes.  For VAR_DECLs,
    4057                 :             :    FUNCTION_DECLs and FIELD_DECLs return DECL_ALIGN (which can be set
    4058                 :             :    from an "aligned" __attribute__ specification).  LOC is the
    4059                 :             :    location of the ALIGNOF operator.  */
    4060                 :             : 
    4061                 :             : tree
    4062                 :       40791 : c_alignof_expr (location_t loc, tree expr)
    4063                 :             : {
    4064                 :       40791 :   tree t;
    4065                 :             : 
    4066                 :       40791 :   if (!verify_type_context (loc, TCTX_ALIGNOF, TREE_TYPE (expr)))
    4067                 :           0 :     t = size_one_node;
    4068                 :             : 
    4069                 :       40791 :   else if (VAR_OR_FUNCTION_DECL_P (expr))
    4070                 :        7245 :     t = size_int (DECL_ALIGN_UNIT (expr));
    4071                 :             : 
    4072                 :       33546 :   else if (TREE_CODE (expr) == COMPONENT_REF
    4073                 :       33546 :            && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1)))
    4074                 :             :     {
    4075                 :           1 :       error_at (loc, "%<__alignof%> applied to a bit-field");
    4076                 :           1 :       t = size_one_node;
    4077                 :             :     }
    4078                 :       33545 :   else if (TREE_CODE (expr) == COMPONENT_REF
    4079                 :       33545 :            && TREE_CODE (TREE_OPERAND (expr, 1)) == FIELD_DECL)
    4080                 :       17569 :     t = size_int (DECL_ALIGN_UNIT (TREE_OPERAND (expr, 1)));
    4081                 :             : 
    4082                 :       15976 :   else if (INDIRECT_REF_P (expr))
    4083                 :             :     {
    4084                 :          55 :       tree t = TREE_OPERAND (expr, 0);
    4085                 :          55 :       tree best = t;
    4086                 :          55 :       int bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
    4087                 :             : 
    4088                 :          55 :       while (CONVERT_EXPR_P (t)
    4089                 :          55 :              && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
    4090                 :             :         {
    4091                 :           0 :           int thisalign;
    4092                 :             : 
    4093                 :           0 :           t = TREE_OPERAND (t, 0);
    4094                 :           0 :           thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
    4095                 :           0 :           if (thisalign > bestalign)
    4096                 :           0 :             best = t, bestalign = thisalign;
    4097                 :             :         }
    4098                 :          55 :       return c_alignof (loc, TREE_TYPE (TREE_TYPE (best)));
    4099                 :             :     }
    4100                 :             :   else
    4101                 :       15921 :     return c_alignof (loc, TREE_TYPE (expr));
    4102                 :             : 
    4103                 :       24815 :   return fold_convert_loc (loc, size_type_node, t);
    4104                 :             : }
    4105                 :             : 
    4106                 :             : /* Implement the _Countof keyword:
    4107                 :             :    Return the number of elements of an array.  */
    4108                 :             : 
    4109                 :             : tree
    4110                 :          70 : c_countof_type (location_t loc, tree type)
    4111                 :             : {
    4112                 :          70 :   enum tree_code type_code;
    4113                 :             : 
    4114                 :          70 :   type_code = TREE_CODE (type);
    4115                 :          70 :   if (type_code != ARRAY_TYPE)
    4116                 :             :     {
    4117                 :          11 :       error_at (loc, "invalid application of %<_Countof%> to type %qT", type);
    4118                 :          11 :       return error_mark_node;
    4119                 :             :     }
    4120                 :          59 :   if (!COMPLETE_TYPE_P (type))
    4121                 :             :     {
    4122                 :           2 :       error_at (loc,
    4123                 :             :                 "invalid application of %<_Countof%> to incomplete type %qT",
    4124                 :             :                 type);
    4125                 :           2 :       return error_mark_node;
    4126                 :             :     }
    4127                 :             : 
    4128                 :          57 :   return array_type_nelts_top (type);
    4129                 :             : }
    4130                 :             : 
    4131                 :             : /* Handle C and C++ default attributes.  */
    4132                 :             : 
    4133                 :             : enum built_in_attribute
    4134                 :             : {
    4135                 :             : #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
    4136                 :             : #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
    4137                 :             : #define DEF_ATTR_STRING(ENUM, VALUE) ENUM,
    4138                 :             : #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
    4139                 :             : #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
    4140                 :             : #include "builtin-attrs.def"
    4141                 :             : #undef DEF_ATTR_NULL_TREE
    4142                 :             : #undef DEF_ATTR_INT
    4143                 :             : #undef DEF_ATTR_STRING
    4144                 :             : #undef DEF_ATTR_IDENT
    4145                 :             : #undef DEF_ATTR_TREE_LIST
    4146                 :             :   ATTR_LAST
    4147                 :             : };
    4148                 :             : 
    4149                 :             : static GTY(()) tree built_in_attributes[(int) ATTR_LAST];
    4150                 :             : 
    4151                 :             : static void c_init_attributes (void);
    4152                 :             : 
    4153                 :             : enum c_builtin_type
    4154                 :             : {
    4155                 :             : #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
    4156                 :             : #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
    4157                 :             : #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
    4158                 :             : #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
    4159                 :             : #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
    4160                 :             : #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
    4161                 :             : #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
    4162                 :             : #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4163                 :             :                             ARG6) NAME,
    4164                 :             : #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4165                 :             :                             ARG6, ARG7) NAME,
    4166                 :             : #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4167                 :             :                             ARG6, ARG7, ARG8) NAME,
    4168                 :             : #define DEF_FUNCTION_TYPE_9(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4169                 :             :                             ARG6, ARG7, ARG8, ARG9) NAME,
    4170                 :             : #define DEF_FUNCTION_TYPE_10(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4171                 :             :                              ARG6, ARG7, ARG8, ARG9, ARG10) NAME,
    4172                 :             : #define DEF_FUNCTION_TYPE_11(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4173                 :             :                              ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) NAME,
    4174                 :             : #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
    4175                 :             : #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
    4176                 :             : #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
    4177                 :             : #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
    4178                 :             : #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
    4179                 :             : #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
    4180                 :             :                                 NAME,
    4181                 :             : #define DEF_FUNCTION_TYPE_VAR_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4182                 :             :                                 ARG6) NAME,
    4183                 :             : #define DEF_FUNCTION_TYPE_VAR_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4184                 :             :                                 ARG6, ARG7) NAME,
    4185                 :             : #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
    4186                 :             : #include "builtin-types.def"
    4187                 :             : #undef DEF_PRIMITIVE_TYPE
    4188                 :             : #undef DEF_FUNCTION_TYPE_0
    4189                 :             : #undef DEF_FUNCTION_TYPE_1
    4190                 :             : #undef DEF_FUNCTION_TYPE_2
    4191                 :             : #undef DEF_FUNCTION_TYPE_3
    4192                 :             : #undef DEF_FUNCTION_TYPE_4
    4193                 :             : #undef DEF_FUNCTION_TYPE_5
    4194                 :             : #undef DEF_FUNCTION_TYPE_6
    4195                 :             : #undef DEF_FUNCTION_TYPE_7
    4196                 :             : #undef DEF_FUNCTION_TYPE_8
    4197                 :             : #undef DEF_FUNCTION_TYPE_9
    4198                 :             : #undef DEF_FUNCTION_TYPE_10
    4199                 :             : #undef DEF_FUNCTION_TYPE_11
    4200                 :             : #undef DEF_FUNCTION_TYPE_VAR_0
    4201                 :             : #undef DEF_FUNCTION_TYPE_VAR_1
    4202                 :             : #undef DEF_FUNCTION_TYPE_VAR_2
    4203                 :             : #undef DEF_FUNCTION_TYPE_VAR_3
    4204                 :             : #undef DEF_FUNCTION_TYPE_VAR_4
    4205                 :             : #undef DEF_FUNCTION_TYPE_VAR_5
    4206                 :             : #undef DEF_FUNCTION_TYPE_VAR_6
    4207                 :             : #undef DEF_FUNCTION_TYPE_VAR_7
    4208                 :             : #undef DEF_POINTER_TYPE
    4209                 :             :   BT_LAST
    4210                 :             : };
    4211                 :             : 
    4212                 :             : typedef enum c_builtin_type builtin_type;
    4213                 :             : 
    4214                 :             : /* A temporary array for c_common_nodes_and_builtins.  Used in
    4215                 :             :    communication with def_fn_type.  */
    4216                 :             : static tree builtin_types[(int) BT_LAST + 1];
    4217                 :             : 
    4218                 :             : /* A helper function for c_common_nodes_and_builtins.  Build function type
    4219                 :             :    for DEF with return type RET and N arguments.  If VAR is true, then the
    4220                 :             :    function should be variadic after those N arguments, or, if N is zero,
    4221                 :             :    unprototyped.
    4222                 :             : 
    4223                 :             :    Takes special care not to ICE if any of the types involved are
    4224                 :             :    error_mark_node, which indicates that said type is not in fact available
    4225                 :             :    (see builtin_type_for_size).  In which case the function type as a whole
    4226                 :             :    should be error_mark_node.  */
    4227                 :             : 
    4228                 :             : static void
    4229                 :   103953528 : def_fn_type (builtin_type def, builtin_type ret, bool var, int n, ...)
    4230                 :             : {
    4231                 :   103953528 :   tree t;
    4232                 :   103953528 :   tree *args = XALLOCAVEC (tree, n);
    4233                 :   103953528 :   va_list list;
    4234                 :   103953528 :   int i;
    4235                 :             : 
    4236                 :   103953528 :   va_start (list, n);
    4237                 :   329296903 :   for (i = 0; i < n; ++i)
    4238                 :             :     {
    4239                 :   228278736 :       builtin_type a = (builtin_type) va_arg (list, int);
    4240                 :   228278736 :       t = builtin_types[a];
    4241                 :   228278736 :       if (t == error_mark_node)
    4242                 :     2935361 :         goto egress;
    4243                 :   225343375 :       args[i] = t;
    4244                 :             :     }
    4245                 :             : 
    4246                 :   101018167 :   t = builtin_types[ret];
    4247                 :   101018167 :   if (t == error_mark_node)
    4248                 :      417821 :     goto egress;
    4249                 :   100600346 :   if (var)
    4250                 :     6182403 :     if (n == 0)
    4251                 :      825028 :       t = build_function_type (t, NULL_TREE);
    4252                 :             :     else
    4253                 :     5357375 :       t = build_varargs_function_type_array (t, n, args);
    4254                 :             :   else
    4255                 :    94417943 :     t = build_function_type_array (t, n, args);
    4256                 :             : 
    4257                 :   103953528 :  egress:
    4258                 :   103953528 :   builtin_types[def] = t;
    4259                 :   103953528 :   va_end (list);
    4260                 :   103953528 : }
    4261                 :             : 
    4262                 :             : /* Build builtin functions common to both C and C++ language
    4263                 :             :    frontends.  */
    4264                 :             : 
    4265                 :             : static void
    4266                 :      206257 : c_define_builtins (tree va_list_ref_type_node, tree va_list_arg_type_node)
    4267                 :             : {
    4268                 :             : #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
    4269                 :             :   builtin_types[ENUM] = VALUE;
    4270                 :             : #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
    4271                 :             :   def_fn_type (ENUM, RETURN, 0, 0);
    4272                 :             : #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
    4273                 :             :   def_fn_type (ENUM, RETURN, 0, 1, ARG1);
    4274                 :             : #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
    4275                 :             :   def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
    4276                 :             : #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
    4277                 :             :   def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
    4278                 :             : #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
    4279                 :             :   def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
    4280                 :             : #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
    4281                 :             :   def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
    4282                 :             : #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4283                 :             :                             ARG6)                                       \
    4284                 :             :   def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
    4285                 :             : #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4286                 :             :                             ARG6, ARG7)                                 \
    4287                 :             :   def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
    4288                 :             : #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4289                 :             :                             ARG6, ARG7, ARG8)                           \
    4290                 :             :   def_fn_type (ENUM, RETURN, 0, 8, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6,  \
    4291                 :             :                ARG7, ARG8);
    4292                 :             : #define DEF_FUNCTION_TYPE_9(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4293                 :             :                             ARG6, ARG7, ARG8, ARG9)                     \
    4294                 :             :   def_fn_type (ENUM, RETURN, 0, 9, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6,  \
    4295                 :             :                ARG7, ARG8, ARG9);
    4296                 :             : #define DEF_FUNCTION_TYPE_10(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4297                 :             :                              ARG6, ARG7, ARG8, ARG9, ARG10)              \
    4298                 :             :   def_fn_type (ENUM, RETURN, 0, 10, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6,  \
    4299                 :             :                ARG7, ARG8, ARG9, ARG10);
    4300                 :             : #define DEF_FUNCTION_TYPE_11(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4301                 :             :                              ARG6, ARG7, ARG8, ARG9, ARG10, ARG11)       \
    4302                 :             :   def_fn_type (ENUM, RETURN, 0, 11, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6,  \
    4303                 :             :                ARG7, ARG8, ARG9, ARG10, ARG11);
    4304                 :             : #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
    4305                 :             :   def_fn_type (ENUM, RETURN, 1, 0);
    4306                 :             : #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
    4307                 :             :   def_fn_type (ENUM, RETURN, 1, 1, ARG1);
    4308                 :             : #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
    4309                 :             :   def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
    4310                 :             : #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
    4311                 :             :   def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
    4312                 :             : #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
    4313                 :             :   def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
    4314                 :             : #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
    4315                 :             :   def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
    4316                 :             : #define DEF_FUNCTION_TYPE_VAR_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4317                 :             :                                 ARG6) \
    4318                 :             :   def_fn_type (ENUM, RETURN, 1, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
    4319                 :             : #define DEF_FUNCTION_TYPE_VAR_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4320                 :             :                                 ARG6, ARG7)                             \
    4321                 :             :   def_fn_type (ENUM, RETURN, 1, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
    4322                 :             : #define DEF_POINTER_TYPE(ENUM, TYPE) \
    4323                 :             :   builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
    4324                 :             : 
    4325                 :             : #include "builtin-types.def"
    4326                 :             : 
    4327                 :             : #undef DEF_PRIMITIVE_TYPE
    4328                 :             : #undef DEF_FUNCTION_TYPE_0
    4329                 :             : #undef DEF_FUNCTION_TYPE_1
    4330                 :             : #undef DEF_FUNCTION_TYPE_2
    4331                 :             : #undef DEF_FUNCTION_TYPE_3
    4332                 :             : #undef DEF_FUNCTION_TYPE_4
    4333                 :             : #undef DEF_FUNCTION_TYPE_5
    4334                 :             : #undef DEF_FUNCTION_TYPE_6
    4335                 :             : #undef DEF_FUNCTION_TYPE_7
    4336                 :             : #undef DEF_FUNCTION_TYPE_8
    4337                 :             : #undef DEF_FUNCTION_TYPE_9
    4338                 :             : #undef DEF_FUNCTION_TYPE_10
    4339                 :             : #undef DEF_FUNCTION_TYPE_11
    4340                 :             : #undef DEF_FUNCTION_TYPE_VAR_0
    4341                 :             : #undef DEF_FUNCTION_TYPE_VAR_1
    4342                 :             : #undef DEF_FUNCTION_TYPE_VAR_2
    4343                 :             : #undef DEF_FUNCTION_TYPE_VAR_3
    4344                 :             : #undef DEF_FUNCTION_TYPE_VAR_4
    4345                 :             : #undef DEF_FUNCTION_TYPE_VAR_5
    4346                 :             : #undef DEF_FUNCTION_TYPE_VAR_6
    4347                 :             : #undef DEF_FUNCTION_TYPE_VAR_7
    4348                 :             : #undef DEF_POINTER_TYPE
    4349                 :      206257 :   builtin_types[(int) BT_LAST] = NULL_TREE;
    4350                 :             : 
    4351                 :      206257 :   c_init_attributes ();
    4352                 :             : 
    4353                 :             : #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P, \
    4354                 :             :                     NONANSI_P, ATTRS, IMPLICIT, COND)                   \
    4355                 :             :   if (NAME && COND)                                                     \
    4356                 :             :     def_builtin_1 (ENUM, NAME, CLASS,                                   \
    4357                 :             :                    builtin_types[(int) TYPE],                           \
    4358                 :             :                    builtin_types[(int) LIBTYPE],                        \
    4359                 :             :                    BOTH_P, FALLBACK_P, NONANSI_P,                       \
    4360                 :             :                    built_in_attributes[(int) ATTRS], IMPLICIT);
    4361                 :             : #include "builtins.def"
    4362                 :             : 
    4363                 :      206257 :   targetm.init_builtins ();
    4364                 :             : 
    4365                 :      206257 :   build_common_builtin_nodes ();
    4366                 :      206257 : }
    4367                 :             : 
    4368                 :             : /* Like get_identifier, but avoid warnings about null arguments when
    4369                 :             :    the argument may be NULL for targets where GCC lacks stdint.h type
    4370                 :             :    information.  */
    4371                 :             : 
    4372                 :             : static inline tree
    4373                 :     5568939 : c_get_ident (const char *id)
    4374                 :             : {
    4375                 :     2475084 :   return get_identifier (id);
    4376                 :             : }
    4377                 :             : 
    4378                 :             : /* Build tree nodes and builtin functions common to both C and C++ language
    4379                 :             :    frontends.  */
    4380                 :             : 
    4381                 :             : void
    4382                 :      206257 : c_common_nodes_and_builtins (void)
    4383                 :             : {
    4384                 :      206257 :   int char8_type_size;
    4385                 :      206257 :   int char16_type_size;
    4386                 :      206257 :   int char32_type_size;
    4387                 :      206257 :   int wchar_type_size;
    4388                 :      206257 :   tree array_domain_type;
    4389                 :      206257 :   tree va_list_ref_type_node;
    4390                 :      206257 :   tree va_list_arg_type_node;
    4391                 :      206257 :   int i;
    4392                 :             : 
    4393                 :      206257 :   build_common_tree_nodes (flag_signed_char);
    4394                 :             : 
    4395                 :             :   /* Define `int' and `char' first so that dbx will output them first.  */
    4396                 :      206257 :   record_builtin_type (RID_INT, NULL, integer_type_node);
    4397                 :      206257 :   record_builtin_type (RID_CHAR, "char", char_type_node);
    4398                 :             : 
    4399                 :             :   /* `signed' is the same as `int'.  FIXME: the declarations of "signed",
    4400                 :             :      "unsigned long", "long long unsigned" and "unsigned short" were in C++
    4401                 :             :      but not C.  Are the conditionals here needed?  */
    4402                 :      206257 :   if (c_dialect_cxx ())
    4403                 :       95198 :     record_builtin_type (RID_SIGNED, NULL, integer_type_node);
    4404                 :      206257 :   record_builtin_type (RID_LONG, "long int", long_integer_type_node);
    4405                 :      206257 :   record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node);
    4406                 :      206257 :   record_builtin_type (RID_MAX, "long unsigned int",
    4407                 :             :                        long_unsigned_type_node);
    4408                 :             : 
    4409                 :      412514 :   for (i = 0; i < NUM_INT_N_ENTS; i ++)
    4410                 :             :     {
    4411                 :      206257 :       char name[25];
    4412                 :             : 
    4413                 :      206257 :       sprintf (name, "__int%d", int_n_data[i].bitsize);
    4414                 :      206257 :       record_builtin_type ((enum rid)(RID_FIRST_INT_N + i), name,
    4415                 :             :                            int_n_trees[i].signed_type);
    4416                 :      206257 :       sprintf (name, "__int%d__", int_n_data[i].bitsize);
    4417                 :      206257 :       record_builtin_type ((enum rid)(RID_FIRST_INT_N + i), name,
    4418                 :             :                            int_n_trees[i].signed_type);
    4419                 :      412514 :       ridpointers[RID_FIRST_INT_N + i]
    4420                 :      206257 :         = DECL_NAME (TYPE_NAME (int_n_trees[i].signed_type));
    4421                 :             : 
    4422                 :      206257 :       sprintf (name, "__int%d unsigned", int_n_data[i].bitsize);
    4423                 :      206257 :       record_builtin_type (RID_MAX, name, int_n_trees[i].unsigned_type);
    4424                 :      206257 :       sprintf (name, "__int%d__ unsigned", int_n_data[i].bitsize);
    4425                 :      206257 :       record_builtin_type (RID_MAX, name, int_n_trees[i].unsigned_type);
    4426                 :             :     }
    4427                 :             : 
    4428                 :      206257 :   if (c_dialect_cxx ())
    4429                 :       95198 :     record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node);
    4430                 :      206257 :   record_builtin_type (RID_MAX, "long long int",
    4431                 :             :                        long_long_integer_type_node);
    4432                 :      206257 :   record_builtin_type (RID_MAX, "long long unsigned int",
    4433                 :             :                        long_long_unsigned_type_node);
    4434                 :      206257 :   if (c_dialect_cxx ())
    4435                 :       95198 :     record_builtin_type (RID_MAX, "long long unsigned",
    4436                 :             :                          long_long_unsigned_type_node);
    4437                 :      206257 :   record_builtin_type (RID_SHORT, "short int", short_integer_type_node);
    4438                 :      206257 :   record_builtin_type (RID_MAX, "short unsigned int",
    4439                 :             :                        short_unsigned_type_node);
    4440                 :      206257 :   if (c_dialect_cxx ())
    4441                 :       95198 :     record_builtin_type (RID_MAX, "unsigned short",
    4442                 :             :                          short_unsigned_type_node);
    4443                 :             : 
    4444                 :             :   /* Define both `signed char' and `unsigned char'.  */
    4445                 :      206257 :   record_builtin_type (RID_MAX, "signed char", signed_char_type_node);
    4446                 :      206257 :   record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node);
    4447                 :             : 
    4448                 :             :   /* These are types that c_common_type_for_size and
    4449                 :             :      c_common_type_for_mode use.  */
    4450                 :      206257 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4451                 :             :                                          TYPE_DECL, NULL_TREE,
    4452                 :             :                                          intQI_type_node));
    4453                 :      206257 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4454                 :             :                                          TYPE_DECL, NULL_TREE,
    4455                 :             :                                          intHI_type_node));
    4456                 :      206257 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4457                 :             :                                          TYPE_DECL, NULL_TREE,
    4458                 :             :                                          intSI_type_node));
    4459                 :      206257 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4460                 :             :                                          TYPE_DECL, NULL_TREE,
    4461                 :             :                                          intDI_type_node));
    4462                 :             : #if HOST_BITS_PER_WIDE_INT >= 64
    4463                 :             :   /* Note that this is different than the __int128 type that's part of
    4464                 :             :      the generic __intN support.  */
    4465                 :      206257 :   if (targetm.scalar_mode_supported_p (TImode))
    4466                 :      200950 :     lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4467                 :             :                                            TYPE_DECL,
    4468                 :             :                                            get_identifier ("__int128_t"),
    4469                 :             :                                            intTI_type_node));
    4470                 :             : #endif
    4471                 :      206257 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4472                 :             :                                          TYPE_DECL, NULL_TREE,
    4473                 :             :                                          unsigned_intQI_type_node));
    4474                 :      206257 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4475                 :             :                                          TYPE_DECL, NULL_TREE,
    4476                 :             :                                          unsigned_intHI_type_node));
    4477                 :      206257 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4478                 :             :                                          TYPE_DECL, NULL_TREE,
    4479                 :             :                                          unsigned_intSI_type_node));
    4480                 :      206257 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4481                 :             :                                          TYPE_DECL, NULL_TREE,
    4482                 :             :                                          unsigned_intDI_type_node));
    4483                 :             : #if HOST_BITS_PER_WIDE_INT >= 64
    4484                 :      206257 :   if (targetm.scalar_mode_supported_p (TImode))
    4485                 :      200950 :     lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4486                 :             :                                            TYPE_DECL,
    4487                 :             :                                            get_identifier ("__uint128_t"),
    4488                 :             :                                            unsigned_intTI_type_node));
    4489                 :             : #endif
    4490                 :             : 
    4491                 :             :   /* Create the widest literal types.  */
    4492                 :      206257 :   if (targetm.scalar_mode_supported_p (TImode))
    4493                 :             :     {
    4494                 :      200950 :       widest_integer_literal_type_node = intTI_type_node;
    4495                 :      200950 :       widest_unsigned_literal_type_node = unsigned_intTI_type_node;
    4496                 :             :     }
    4497                 :             :   else
    4498                 :             :     {
    4499                 :        5307 :       widest_integer_literal_type_node = intDI_type_node;
    4500                 :        5307 :       widest_unsigned_literal_type_node = unsigned_intDI_type_node;
    4501                 :             :     }
    4502                 :             : 
    4503                 :      206257 :   signed_size_type_node = c_common_signed_type (size_type_node);
    4504                 :             : 
    4505                 :      412514 :   pid_type_node =
    4506                 :      206257 :     TREE_TYPE (identifier_global_value (get_identifier (PID_TYPE)));
    4507                 :             : 
    4508                 :      206257 :   record_builtin_type (RID_FLOAT, NULL, float_type_node);
    4509                 :      206257 :   record_builtin_type (RID_DOUBLE, NULL, double_type_node);
    4510                 :      206257 :   record_builtin_type (RID_MAX, "long double", long_double_type_node);
    4511                 :             : 
    4512                 :     1856313 :   for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
    4513                 :             :     {
    4514                 :     1443799 :       if (FLOATN_NX_TYPE_NODE (i) != NULL_TREE)
    4515                 :     1237542 :         record_builtin_type ((enum rid) (RID_FLOATN_NX_FIRST + i), NULL,
    4516                 :             :                              FLOATN_NX_TYPE_NODE (i));
    4517                 :             :     }
    4518                 :             : 
    4519                 :             :   /* For C, let float128t_type_node (__float128 in some backends) be the
    4520                 :             :      same type as float128_type_node (_Float128), for C++ let those
    4521                 :             :      be distinct types that mangle and behave differently.  */
    4522                 :      206257 :   if (c_dialect_cxx ())
    4523                 :       95198 :     float128t_type_node = NULL_TREE;
    4524                 :             : 
    4525                 :             :   /* Only supported decimal floating point extension if the target
    4526                 :             :      actually supports underlying modes. */
    4527                 :      206257 :   if (targetm.scalar_mode_supported_p (SDmode)
    4528                 :      206257 :       && targetm.scalar_mode_supported_p (DDmode)
    4529                 :      412514 :       && targetm.scalar_mode_supported_p (TDmode))
    4530                 :             :     {
    4531                 :      206257 :       record_builtin_type (RID_DFLOAT32, NULL, dfloat32_type_node);
    4532                 :      206257 :       record_builtin_type (RID_DFLOAT64, NULL, dfloat64_type_node);
    4533                 :      206257 :       record_builtin_type (RID_DFLOAT128, NULL, dfloat128_type_node);
    4534                 :      206257 :       record_builtin_type (RID_DFLOAT64X, NULL, dfloat64x_type_node);
    4535                 :             :     }
    4536                 :             : 
    4537                 :      206257 :   if (targetm.fixed_point_supported_p ())
    4538                 :             :     {
    4539                 :           0 :       record_builtin_type (RID_MAX, "short _Fract", short_fract_type_node);
    4540                 :           0 :       record_builtin_type (RID_FRACT, NULL, fract_type_node);
    4541                 :           0 :       record_builtin_type (RID_MAX, "long _Fract", long_fract_type_node);
    4542                 :           0 :       record_builtin_type (RID_MAX, "long long _Fract",
    4543                 :             :                            long_long_fract_type_node);
    4544                 :           0 :       record_builtin_type (RID_MAX, "unsigned short _Fract",
    4545                 :             :                            unsigned_short_fract_type_node);
    4546                 :           0 :       record_builtin_type (RID_MAX, "unsigned _Fract",
    4547                 :             :                            unsigned_fract_type_node);
    4548                 :           0 :       record_builtin_type (RID_MAX, "unsigned long _Fract",
    4549                 :             :                            unsigned_long_fract_type_node);
    4550                 :           0 :       record_builtin_type (RID_MAX, "unsigned long long _Fract",
    4551                 :             :                            unsigned_long_long_fract_type_node);
    4552                 :           0 :       record_builtin_type (RID_MAX, "_Sat short _Fract",
    4553                 :             :                            sat_short_fract_type_node);
    4554                 :           0 :       record_builtin_type (RID_MAX, "_Sat _Fract", sat_fract_type_node);
    4555                 :           0 :       record_builtin_type (RID_MAX, "_Sat long _Fract",
    4556                 :             :                            sat_long_fract_type_node);
    4557                 :           0 :       record_builtin_type (RID_MAX, "_Sat long long _Fract",
    4558                 :             :                            sat_long_long_fract_type_node);
    4559                 :           0 :       record_builtin_type (RID_MAX, "_Sat unsigned short _Fract",
    4560                 :             :                            sat_unsigned_short_fract_type_node);
    4561                 :           0 :       record_builtin_type (RID_MAX, "_Sat unsigned _Fract",
    4562                 :             :                            sat_unsigned_fract_type_node);
    4563                 :           0 :       record_builtin_type (RID_MAX, "_Sat unsigned long _Fract",
    4564                 :             :                            sat_unsigned_long_fract_type_node);
    4565                 :           0 :       record_builtin_type (RID_MAX, "_Sat unsigned long long _Fract",
    4566                 :             :                            sat_unsigned_long_long_fract_type_node);
    4567                 :           0 :       record_builtin_type (RID_MAX, "short _Accum", short_accum_type_node);
    4568                 :           0 :       record_builtin_type (RID_ACCUM, NULL, accum_type_node);
    4569                 :           0 :       record_builtin_type (RID_MAX, "long _Accum", long_accum_type_node);
    4570                 :           0 :       record_builtin_type (RID_MAX, "long long _Accum",
    4571                 :             :                            long_long_accum_type_node);
    4572                 :           0 :       record_builtin_type (RID_MAX, "unsigned short _Accum",
    4573                 :             :                            unsigned_short_accum_type_node);
    4574                 :           0 :       record_builtin_type (RID_MAX, "unsigned _Accum",
    4575                 :             :                            unsigned_accum_type_node);
    4576                 :           0 :       record_builtin_type (RID_MAX, "unsigned long _Accum",
    4577                 :             :                            unsigned_long_accum_type_node);
    4578                 :           0 :       record_builtin_type (RID_MAX, "unsigned long long _Accum",
    4579                 :             :                            unsigned_long_long_accum_type_node);
    4580                 :           0 :       record_builtin_type (RID_MAX, "_Sat short _Accum",
    4581                 :             :                            sat_short_accum_type_node);
    4582                 :           0 :       record_builtin_type (RID_MAX, "_Sat _Accum", sat_accum_type_node);
    4583                 :           0 :       record_builtin_type (RID_MAX, "_Sat long _Accum",
    4584                 :             :                            sat_long_accum_type_node);
    4585                 :           0 :       record_builtin_type (RID_MAX, "_Sat long long _Accum",
    4586                 :             :                           sat_long_long_accum_type_node);
    4587                 :           0 :       record_builtin_type (RID_MAX, "_Sat unsigned short _Accum",
    4588                 :             :                            sat_unsigned_short_accum_type_node);
    4589                 :           0 :       record_builtin_type (RID_MAX, "_Sat unsigned _Accum",
    4590                 :             :                            sat_unsigned_accum_type_node);
    4591                 :           0 :       record_builtin_type (RID_MAX, "_Sat unsigned long _Accum",
    4592                 :             :                            sat_unsigned_long_accum_type_node);
    4593                 :           0 :       record_builtin_type (RID_MAX, "_Sat unsigned long long _Accum",
    4594                 :             :                            sat_unsigned_long_long_accum_type_node);
    4595                 :             : 
    4596                 :             :     }
    4597                 :             : 
    4598                 :      206257 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4599                 :             :                                          TYPE_DECL,
    4600                 :             :                                          get_identifier ("complex int"),
    4601                 :             :                                          complex_integer_type_node));
    4602                 :      206257 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4603                 :             :                                          TYPE_DECL,
    4604                 :             :                                          get_identifier ("complex float"),
    4605                 :             :                                          complex_float_type_node));
    4606                 :      206257 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4607                 :             :                                          TYPE_DECL,
    4608                 :             :                                          get_identifier ("complex double"),
    4609                 :             :                                          complex_double_type_node));
    4610                 :      206257 :   lang_hooks.decls.pushdecl
    4611                 :      206257 :     (build_decl (UNKNOWN_LOCATION,
    4612                 :             :                  TYPE_DECL, get_identifier ("complex long double"),
    4613                 :             :                  complex_long_double_type_node));
    4614                 :             : 
    4615                 :      206257 :   if (!c_dialect_cxx ())
    4616                 :      888472 :     for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
    4617                 :      777413 :       if (COMPLEX_FLOATN_NX_TYPE_NODE (i) != NULL_TREE)
    4618                 :             :         {
    4619                 :      666354 :           char buf[30];
    4620                 :     1332708 :           sprintf (buf, "complex _Float%d%s", floatn_nx_types[i].n,
    4621                 :      666354 :                    floatn_nx_types[i].extended ? "x" : "");
    4622                 :      666354 :           lang_hooks.decls.pushdecl
    4623                 :      666354 :             (build_decl (UNKNOWN_LOCATION,
    4624                 :             :                          TYPE_DECL,
    4625                 :             :                          get_identifier (buf),
    4626                 :             :                          COMPLEX_FLOATN_NX_TYPE_NODE (i)));
    4627                 :             :         }
    4628                 :             : 
    4629                 :             :   /* Make fileptr_type_node a distinct void * type until
    4630                 :             :      FILE type is defined.  Likewise for const struct tm*.  */
    4631                 :     1443799 :   for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
    4632                 :     1237542 :     builtin_structptr_types[i].node
    4633                 :     1237542 :       = build_variant_type_copy (builtin_structptr_types[i].base);
    4634                 :             : 
    4635                 :      206257 :   record_builtin_type (RID_VOID, NULL, void_type_node);
    4636                 :             : 
    4637                 :             :   /* Set the TYPE_NAME for any variants that were built before
    4638                 :             :      record_builtin_type gave names to the built-in types. */
    4639                 :      206257 :   {
    4640                 :      206257 :     tree void_name = TYPE_NAME (void_type_node);
    4641                 :      206257 :     TYPE_NAME (void_type_node) = NULL_TREE;
    4642                 :      206257 :     TYPE_NAME (build_qualified_type (void_type_node, TYPE_QUAL_CONST))
    4643                 :      206257 :       = void_name;
    4644                 :      206257 :     TYPE_NAME (void_type_node) = void_name;
    4645                 :             :   }
    4646                 :             : 
    4647                 :             :   /* Make a type to be the domain of a few array types
    4648                 :             :      whose domains don't really matter.
    4649                 :             :      200 is small enough that it always fits in size_t
    4650                 :             :      and large enough that it can hold most function names for the
    4651                 :             :      initializations of __FUNCTION__ and __PRETTY_FUNCTION__.  */
    4652                 :      206257 :   array_domain_type = build_index_type (size_int (200));
    4653                 :             : 
    4654                 :             :   /* Make a type for arrays of characters.
    4655                 :             :      With luck nothing will ever really depend on the length of this
    4656                 :             :      array type.  */
    4657                 :      206257 :   char_array_type_node
    4658                 :      206257 :     = build_array_type (char_type_node, array_domain_type);
    4659                 :             : 
    4660                 :      206257 :   string_type_node = build_pointer_type (char_type_node);
    4661                 :      206257 :   const_string_type_node
    4662                 :      206257 :     = build_pointer_type (build_qualified_type
    4663                 :             :                           (char_type_node, TYPE_QUAL_CONST));
    4664                 :             : 
    4665                 :             :   /* This is special for C++ so functions can be overloaded.  */
    4666                 :      211668 :   wchar_type_node = get_identifier (MODIFIED_WCHAR_TYPE);
    4667                 :      206257 :   wchar_type_node = TREE_TYPE (identifier_global_value (wchar_type_node));
    4668                 :      206257 :   wchar_type_size = TYPE_PRECISION (wchar_type_node);
    4669                 :      206257 :   underlying_wchar_type_node = wchar_type_node;
    4670                 :      206257 :   if (c_dialect_cxx ())
    4671                 :             :     {
    4672                 :       95198 :       if (TYPE_UNSIGNED (wchar_type_node))
    4673                 :           7 :         wchar_type_node = make_unsigned_type (wchar_type_size);
    4674                 :             :       else
    4675                 :       95191 :         wchar_type_node = make_signed_type (wchar_type_size);
    4676                 :       95198 :       record_builtin_type (RID_WCHAR, "wchar_t", wchar_type_node);
    4677                 :             :     }
    4678                 :             : 
    4679                 :             :   /* This is for wide string constants.  */
    4680                 :      206257 :   wchar_array_type_node
    4681                 :      206257 :     = build_array_type (wchar_type_node, array_domain_type);
    4682                 :             : 
    4683                 :             :   /* Define 'char8_t'.  */
    4684                 :      206257 :   char8_type_node = get_identifier (CHAR8_TYPE);
    4685                 :      206257 :   char8_type_node = TREE_TYPE (identifier_global_value (char8_type_node));
    4686                 :      206257 :   char8_type_size = TYPE_PRECISION (char8_type_node);
    4687                 :      206257 :   if (c_dialect_cxx ())
    4688                 :             :     {
    4689                 :       95198 :       char8_type_node = make_unsigned_type (char8_type_size);
    4690                 :       95198 :       TYPE_STRING_FLAG (char8_type_node) = true;
    4691                 :             : 
    4692                 :       95198 :       if (flag_char8_t)
    4693                 :       30126 :         record_builtin_type (RID_CHAR8, "char8_t", char8_type_node);
    4694                 :             :     }
    4695                 :             : 
    4696                 :             :   /* This is for UTF-8 string constants.  */
    4697                 :      206257 :   char8_array_type_node
    4698                 :      206257 :     = build_array_type (char8_type_node, array_domain_type);
    4699                 :             : 
    4700                 :             :   /* Define 'char16_t'.  */
    4701                 :      206257 :   char16_type_node = get_identifier (CHAR16_TYPE);
    4702                 :      206257 :   char16_type_node = TREE_TYPE (identifier_global_value (char16_type_node));
    4703                 :      206257 :   char16_type_size = TYPE_PRECISION (char16_type_node);
    4704                 :      206257 :   if (c_dialect_cxx ())
    4705                 :             :     {
    4706                 :       95198 :       char16_type_node = make_unsigned_type (char16_type_size);
    4707                 :             : 
    4708                 :       95198 :       if (cxx_dialect >= cxx11)
    4709                 :       81258 :         record_builtin_type (RID_CHAR16, "char16_t", char16_type_node);
    4710                 :             :     }
    4711                 :             : 
    4712                 :             :   /* This is for UTF-16 string constants.  */
    4713                 :      206257 :   char16_array_type_node
    4714                 :      206257 :     = build_array_type (char16_type_node, array_domain_type);
    4715                 :             : 
    4716                 :             :   /* Define 'char32_t'.  */
    4717                 :      206257 :   char32_type_node = get_identifier (CHAR32_TYPE);
    4718                 :      206257 :   char32_type_node = TREE_TYPE (identifier_global_value (char32_type_node));
    4719                 :      206257 :   char32_type_size = TYPE_PRECISION (char32_type_node);
    4720                 :      206257 :   if (c_dialect_cxx ())
    4721                 :             :     {
    4722                 :       95198 :       char32_type_node = make_unsigned_type (char32_type_size);
    4723                 :             : 
    4724                 :       95198 :       if (cxx_dialect >= cxx11)
    4725                 :       81258 :         record_builtin_type (RID_CHAR32, "char32_t", char32_type_node);
    4726                 :             :     }
    4727                 :             : 
    4728                 :             :   /* This is for UTF-32 string constants.  */
    4729                 :      206257 :   char32_array_type_node
    4730                 :      206257 :     = build_array_type (char32_type_node, array_domain_type);
    4731                 :             : 
    4732                 :      206257 :   if (strcmp (WINT_TYPE, "wchar_t") == 0)
    4733                 :             :     wint_type_node = wchar_type_node;
    4734                 :             :   else
    4735                 :      412514 :     wint_type_node =
    4736                 :      206257 :       TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE)));
    4737                 :             : 
    4738                 :      412514 :   intmax_type_node =
    4739                 :      211668 :     TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE)));
    4740                 :      412514 :   uintmax_type_node =
    4741                 :      211668 :     TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE)));
    4742                 :             : 
    4743                 :      206257 :   if (SIG_ATOMIC_TYPE)
    4744                 :      206257 :     sig_atomic_type_node =
    4745                 :      206257 :       TREE_TYPE (identifier_global_value (c_get_ident (SIG_ATOMIC_TYPE)));
    4746                 :      206257 :   if (INT8_TYPE)
    4747                 :      206257 :     int8_type_node =
    4748                 :      206257 :       TREE_TYPE (identifier_global_value (c_get_ident (INT8_TYPE)));
    4749                 :      206257 :   if (INT16_TYPE)
    4750                 :      206257 :     int16_type_node =
    4751                 :      206257 :       TREE_TYPE (identifier_global_value (c_get_ident (INT16_TYPE)));
    4752                 :      206257 :   if (INT32_TYPE)
    4753                 :      206257 :     int32_type_node =
    4754                 :      206257 :       TREE_TYPE (identifier_global_value (c_get_ident (INT32_TYPE)));
    4755                 :      206257 :   if (INT64_TYPE)
    4756                 :      412514 :     int64_type_node =
    4757                 :      412514 :       TREE_TYPE (identifier_global_value (c_get_ident (INT64_TYPE)));
    4758                 :      206257 :   if (UINT8_TYPE)
    4759                 :      206257 :     uint8_type_node =
    4760                 :      206257 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT8_TYPE)));
    4761                 :      206257 :   if (UINT16_TYPE)
    4762                 :      206257 :     c_uint16_type_node = uint16_type_node =
    4763                 :      206257 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT16_TYPE)));
    4764                 :      206257 :   if (UINT32_TYPE)
    4765                 :      206257 :     c_uint32_type_node = uint32_type_node =
    4766                 :      206257 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT32_TYPE)));
    4767                 :      206257 :   if (UINT64_TYPE)
    4768                 :      412514 :     c_uint64_type_node = uint64_type_node =
    4769                 :      412514 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT64_TYPE)));
    4770                 :      206257 :   if (INT_LEAST8_TYPE)
    4771                 :      206257 :     int_least8_type_node =
    4772                 :      206257 :       TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST8_TYPE)));
    4773                 :      206257 :   if (INT_LEAST16_TYPE)
    4774                 :      206257 :     int_least16_type_node =
    4775                 :      206257 :       TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST16_TYPE)));
    4776                 :      206257 :   if (INT_LEAST32_TYPE)
    4777                 :      206257 :     int_least32_type_node =
    4778                 :      206257 :       TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST32_TYPE)));
    4779                 :      206257 :   if (INT_LEAST64_TYPE)
    4780                 :      412514 :     int_least64_type_node =
    4781                 :      412514 :       TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST64_TYPE)));
    4782                 :      206257 :   if (UINT_LEAST8_TYPE)
    4783                 :      206257 :     uint_least8_type_node =
    4784                 :      206257 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST8_TYPE)));
    4785                 :      206257 :   if (UINT_LEAST16_TYPE)
    4786                 :      206257 :     uint_least16_type_node =
    4787                 :      206257 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST16_TYPE)));
    4788                 :      206257 :   if (UINT_LEAST32_TYPE)
    4789                 :      206257 :     uint_least32_type_node =
    4790                 :      206257 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST32_TYPE)));
    4791                 :      206257 :   if (UINT_LEAST64_TYPE)
    4792                 :      412514 :     uint_least64_type_node =
    4793                 :      412514 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST64_TYPE)));
    4794                 :      206257 :   if (INT_FAST8_TYPE)
    4795                 :      206257 :     int_fast8_type_node =
    4796                 :      206257 :       TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST8_TYPE)));
    4797                 :      206257 :   if (INT_FAST16_TYPE)
    4798                 :      412514 :     int_fast16_type_node =
    4799                 :      412514 :       TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST16_TYPE)));
    4800                 :      206257 :   if (INT_FAST32_TYPE)
    4801                 :      412514 :     int_fast32_type_node =
    4802                 :      412514 :       TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST32_TYPE)));
    4803                 :      206257 :   if (INT_FAST64_TYPE)
    4804                 :      412514 :     int_fast64_type_node =
    4805                 :      412514 :       TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST64_TYPE)));
    4806                 :      206257 :   if (UINT_FAST8_TYPE)
    4807                 :      206257 :     uint_fast8_type_node =
    4808                 :      206257 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST8_TYPE)));
    4809                 :      206257 :   if (UINT_FAST16_TYPE)
    4810                 :      412514 :     uint_fast16_type_node =
    4811                 :      412514 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST16_TYPE)));
    4812                 :      206257 :   if (UINT_FAST32_TYPE)
    4813                 :      412514 :     uint_fast32_type_node =
    4814                 :      412514 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST32_TYPE)));
    4815                 :      206257 :   if (UINT_FAST64_TYPE)
    4816                 :      412514 :     uint_fast64_type_node =
    4817                 :      412514 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST64_TYPE)));
    4818                 :      206257 :   if (INTPTR_TYPE)
    4819                 :      412514 :     intptr_type_node =
    4820                 :      412514 :       TREE_TYPE (identifier_global_value (c_get_ident (INTPTR_TYPE)));
    4821                 :      206257 :   if (UINTPTR_TYPE)
    4822                 :      412514 :     uintptr_type_node =
    4823                 :      412514 :       TREE_TYPE (identifier_global_value (c_get_ident (UINTPTR_TYPE)));
    4824                 :             : 
    4825                 :      206257 :   default_function_type = build_function_type (integer_type_node, NULL_TREE);
    4826                 :      206257 :   unsigned_ptrdiff_type_node = c_common_unsigned_type (ptrdiff_type_node);
    4827                 :             : 
    4828                 :      206257 :   lang_hooks.decls.pushdecl
    4829                 :      206257 :     (build_decl (UNKNOWN_LOCATION,
    4830                 :             :                  TYPE_DECL, get_identifier ("__builtin_va_list"),
    4831                 :             :                  va_list_type_node));
    4832                 :      206257 :   if (targetm.enum_va_list_p)
    4833                 :             :     {
    4834                 :             :       int l;
    4835                 :             :       const char *pname;
    4836                 :             :       tree ptype;
    4837                 :             : 
    4838                 :      608157 :       for (l = 0; targetm.enum_va_list_p (l, &pname, &ptype); ++l)
    4839                 :             :         {
    4840                 :      401900 :           lang_hooks.decls.pushdecl
    4841                 :      401900 :             (build_decl (UNKNOWN_LOCATION,
    4842                 :             :                          TYPE_DECL, get_identifier (pname),
    4843                 :             :                          ptype));
    4844                 :             : 
    4845                 :             :         }
    4846                 :             :     }
    4847                 :             : 
    4848                 :      206257 :   if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
    4849                 :             :     {
    4850                 :      401816 :       va_list_arg_type_node = va_list_ref_type_node =
    4851                 :      200908 :         build_pointer_type (TREE_TYPE (va_list_type_node));
    4852                 :             :     }
    4853                 :             :   else
    4854                 :             :     {
    4855                 :        5349 :       va_list_arg_type_node = va_list_type_node;
    4856                 :        5349 :       va_list_ref_type_node = build_reference_type (va_list_type_node);
    4857                 :             :     }
    4858                 :             : 
    4859                 :      206257 :   c_define_builtins (va_list_ref_type_node, va_list_arg_type_node);
    4860                 :             : 
    4861                 :      206257 :   main_identifier_node = get_identifier ("main");
    4862                 :             : 
    4863                 :             :   /* Create the built-in __null node.  It is important that this is
    4864                 :             :      not shared.  */
    4865                 :      206257 :   null_node = make_int_cst (1, 1);
    4866                 :      211668 :   TREE_TYPE (null_node) = c_common_type_for_size (POINTER_SIZE, 0);
    4867                 :             : 
    4868                 :             :   /* Create the built-in nullptr node.  This part of its initialization is
    4869                 :             :      common to C and C++.  The front ends can further adjust its definition
    4870                 :             :      in {c,cxx}_init_decl_processing.  In particular, we aren't setting the
    4871                 :             :      alignment here for C++ backward ABI bug compatibility.  */
    4872                 :      206257 :   nullptr_type_node = make_node (NULLPTR_TYPE);
    4873                 :      412514 :   TYPE_SIZE (nullptr_type_node) = bitsize_int (GET_MODE_BITSIZE (ptr_mode));
    4874                 :      412514 :   TYPE_SIZE_UNIT (nullptr_type_node) = size_int (GET_MODE_SIZE (ptr_mode));
    4875                 :      206257 :   TYPE_UNSIGNED (nullptr_type_node) = 1;
    4876                 :      412514 :   TYPE_PRECISION (nullptr_type_node) = GET_MODE_BITSIZE (ptr_mode);
    4877                 :      206257 :   SET_TYPE_MODE (nullptr_type_node, ptr_mode);
    4878                 :      206257 :   nullptr_node = build_int_cst (nullptr_type_node, 0);
    4879                 :             : 
    4880                 :             :   /* Since builtin_types isn't gc'ed, don't export these nodes.  */
    4881                 :      206257 :   memset (builtin_types, 0, sizeof (builtin_types));
    4882                 :      206257 : }
    4883                 :             : 
    4884                 :             : /* The number of named compound-literals generated thus far.  */
    4885                 :             : static GTY(()) int compound_literal_number;
    4886                 :             : 
    4887                 :             : /* Set DECL_NAME for DECL, a VAR_DECL for a compound-literal.  */
    4888                 :             : 
    4889                 :             : void
    4890                 :         273 : set_compound_literal_name (tree decl)
    4891                 :             : {
    4892                 :         273 :   char *name;
    4893                 :         273 :   ASM_FORMAT_PRIVATE_NAME (name, "__compound_literal",
    4894                 :             :                            compound_literal_number);
    4895                 :         273 :   compound_literal_number++;
    4896                 :         273 :   DECL_NAME (decl) = get_identifier (name);
    4897                 :         273 : }
    4898                 :             : 
    4899                 :             : /* build_va_arg helper function.  Return a VA_ARG_EXPR with location LOC, type
    4900                 :             :    TYPE and operand OP.  */
    4901                 :             : 
    4902                 :             : static tree
    4903                 :       50774 : build_va_arg_1 (location_t loc, tree type, tree op)
    4904                 :             : {
    4905                 :       50774 :   tree expr = build1 (VA_ARG_EXPR, type, op);
    4906                 :       50774 :   SET_EXPR_LOCATION (expr, loc);
    4907                 :       50774 :   return expr;
    4908                 :             : }
    4909                 :             : 
    4910                 :             : /* Return a VA_ARG_EXPR corresponding to a source-level expression
    4911                 :             :    va_arg (EXPR, TYPE) at source location LOC.  */
    4912                 :             : 
    4913                 :             : tree
    4914                 :       50774 : build_va_arg (location_t loc, tree expr, tree type)
    4915                 :             : {
    4916                 :       50774 :   tree va_type = TREE_TYPE (expr);
    4917                 :       50774 :   tree canon_va_type = (va_type == error_mark_node
    4918                 :       50774 :                         ? error_mark_node
    4919                 :       50764 :                         : targetm.canonical_va_list_type (va_type));
    4920                 :             : 
    4921                 :       50774 :   if (va_type == error_mark_node
    4922                 :       50764 :       || canon_va_type == NULL_TREE)
    4923                 :             :     {
    4924                 :          10 :       if (canon_va_type == NULL_TREE)
    4925                 :          12 :         error_at (loc, "first argument to %<va_arg%> not of type %<va_list%>");
    4926                 :             : 
    4927                 :             :       /* Let's handle things neutrally, if expr:
    4928                 :             :          - has undeclared type, or
    4929                 :             :          - is not an va_list type.  */
    4930                 :          22 :       return build_va_arg_1 (loc, type, error_mark_node);
    4931                 :             :     }
    4932                 :             : 
    4933                 :       50752 :   if (TREE_CODE (canon_va_type) != ARRAY_TYPE)
    4934                 :             :     {
    4935                 :             :       /* Case 1: Not an array type.  */
    4936                 :             : 
    4937                 :             :       /* Take the address, to get '&ap'.  Note that &ap is not a va_list
    4938                 :             :          type.  */
    4939                 :         258 :       c_common_mark_addressable_vec (expr);
    4940                 :         258 :       expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (expr)), expr);
    4941                 :             : 
    4942                 :         258 :       return build_va_arg_1 (loc, type, expr);
    4943                 :             :     }
    4944                 :             : 
    4945                 :             :   /* Case 2: Array type.
    4946                 :             : 
    4947                 :             :      Background:
    4948                 :             : 
    4949                 :             :      For contrast, let's start with the simple case (case 1).  If
    4950                 :             :      canon_va_type is not an array type, but say a char *, then when
    4951                 :             :      passing-by-value a va_list, the type of the va_list param decl is
    4952                 :             :      the same as for another va_list decl (all ap's are char *):
    4953                 :             : 
    4954                 :             :      f2_1 (char * ap)
    4955                 :             :        D.1815 = VA_ARG (&ap, 0B, 1);
    4956                 :             :        return D.1815;
    4957                 :             : 
    4958                 :             :      f2 (int i)
    4959                 :             :        char * ap.0;
    4960                 :             :        char * ap;
    4961                 :             :        __builtin_va_start (&ap, 0);
    4962                 :             :        ap.0 = ap;
    4963                 :             :        res = f2_1 (ap.0);
    4964                 :             :        __builtin_va_end (&ap);
    4965                 :             :        D.1812 = res;
    4966                 :             :        return D.1812;
    4967                 :             : 
    4968                 :             :      However, if canon_va_type is ARRAY_TYPE, then when passing-by-value a
    4969                 :             :      va_list the type of the va_list param decl (case 2b, struct * ap) is not
    4970                 :             :      the same as for another va_list decl (case 2a, struct ap[1]).
    4971                 :             : 
    4972                 :             :      f2_1 (struct  * ap)
    4973                 :             :        D.1844 = VA_ARG (ap, 0B, 0);
    4974                 :             :        return D.1844;
    4975                 :             : 
    4976                 :             :      f2 (int i)
    4977                 :             :        struct  ap[1];
    4978                 :             :        __builtin_va_start (&ap, 0);
    4979                 :             :        res = f2_1 (&ap);
    4980                 :             :        __builtin_va_end (&ap);
    4981                 :             :        D.1841 = res;
    4982                 :             :        return D.1841;
    4983                 :             : 
    4984                 :             :      Case 2b is different because:
    4985                 :             :      - on the callee side, the parm decl has declared type va_list, but
    4986                 :             :        grokdeclarator changes the type of the parm decl to a pointer to the
    4987                 :             :        array elem type.
    4988                 :             :      - on the caller side, the pass-by-value uses &ap.
    4989                 :             : 
    4990                 :             :      We unify these two cases (case 2a: va_list is array type,
    4991                 :             :      case 2b: va_list is pointer to array elem type), by adding '&' for the
    4992                 :             :      array type case, such that we have a pointer to array elem in both
    4993                 :             :      cases.  */
    4994                 :             : 
    4995                 :       50494 :   if (TREE_CODE (va_type) == ARRAY_TYPE)
    4996                 :             :     {
    4997                 :             :       /* Case 2a: va_list is array type.  */
    4998                 :             : 
    4999                 :             :       /* Take the address, to get '&ap'.  Make sure it's a pointer to array
    5000                 :             :          elem type.  */
    5001                 :       49747 :       c_common_mark_addressable_vec (expr);
    5002                 :       49747 :       expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (canon_va_type)),
    5003                 :             :                      expr);
    5004                 :             : 
    5005                 :             :       /* Verify that &ap is still recognized as having va_list type.  */
    5006                 :       49747 :       tree canon_expr_type
    5007                 :       49747 :         = targetm.canonical_va_list_type (TREE_TYPE (expr));
    5008                 :       49747 :       gcc_assert (canon_expr_type != NULL_TREE);
    5009                 :             :     }
    5010                 :             :   else
    5011                 :             :     {
    5012                 :             :       /* Case 2b: va_list is pointer to array elem type.  */
    5013                 :         747 :       gcc_assert (POINTER_TYPE_P (va_type));
    5014                 :             : 
    5015                 :             :       /* Comparison as in std_canonical_va_list_type.  */
    5016                 :         747 :       gcc_assert (TYPE_MAIN_VARIANT (TREE_TYPE (va_type))
    5017                 :             :                   == TYPE_MAIN_VARIANT (TREE_TYPE (canon_va_type)));
    5018                 :             : 
    5019                 :             :       /* Don't take the address.  We've already got '&ap'.  */
    5020                 :       50494 :       ;
    5021                 :             :     }
    5022                 :             : 
    5023                 :       50494 :   return build_va_arg_1 (loc, type, expr);
    5024                 :             : }
    5025                 :             : 
    5026                 :             : 
    5027                 :             : /* Linked list of disabled built-in functions.  */
    5028                 :             : 
    5029                 :             : struct disabled_builtin
    5030                 :             : {
    5031                 :             :   const char *name;
    5032                 :             :   struct disabled_builtin *next;
    5033                 :             : };
    5034                 :             : static disabled_builtin *disabled_builtins = NULL;
    5035                 :             : 
    5036                 :             : static bool builtin_function_disabled_p (const char *);
    5037                 :             : 
    5038                 :             : /* Disable a built-in function specified by -fno-builtin-NAME.  If NAME
    5039                 :             :    begins with "__builtin_", give an error.  */
    5040                 :             : 
    5041                 :             : void
    5042                 :         308 : disable_builtin_function (const char *name)
    5043                 :             : {
    5044                 :         308 :   if (startswith (name, "__builtin_"))
    5045                 :           0 :     error ("cannot disable built-in function %qs", name);
    5046                 :             :   else
    5047                 :             :     {
    5048                 :         308 :       disabled_builtin *new_disabled_builtin = XNEW (disabled_builtin);
    5049                 :         308 :       new_disabled_builtin->name = name;
    5050                 :         308 :       new_disabled_builtin->next = disabled_builtins;
    5051                 :         308 :       disabled_builtins = new_disabled_builtin;
    5052                 :             :     }
    5053                 :         308 : }
    5054                 :             : 
    5055                 :             : 
    5056                 :             : /* Return true if the built-in function NAME has been disabled, false
    5057                 :             :    otherwise.  */
    5058                 :             : 
    5059                 :             : static bool
    5060                 :   158892690 : builtin_function_disabled_p (const char *name)
    5061                 :             : {
    5062                 :   158892690 :   disabled_builtin *p;
    5063                 :   159177150 :   for (p = disabled_builtins; p != NULL; p = p->next)
    5064                 :             :     {
    5065                 :      284768 :       if (strcmp (name, p->name) == 0)
    5066                 :             :         return true;
    5067                 :             :     }
    5068                 :             :   return false;
    5069                 :             : }
    5070                 :             : 
    5071                 :             : 
    5072                 :             : /* Worker for DEF_BUILTIN.
    5073                 :             :    Possibly define a builtin function with one or two names.
    5074                 :             :    Does not declare a non-__builtin_ function if flag_no_builtin, or if
    5075                 :             :    nonansi_p and flag_no_nonansi_builtin.  */
    5076                 :             : 
    5077                 :             : static void
    5078                 :   311408169 : def_builtin_1 (enum built_in_function fncode,
    5079                 :             :                const char *name,
    5080                 :             :                enum built_in_class fnclass,
    5081                 :             :                tree fntype, tree libtype,
    5082                 :             :                bool both_p, bool fallback_p, bool nonansi_p,
    5083                 :             :                tree fnattrs, bool implicit_p)
    5084                 :             : {
    5085                 :   311408169 :   tree decl;
    5086                 :   311408169 :   const char *libname;
    5087                 :             : 
    5088                 :   311408169 :   if (fntype == error_mark_node)
    5089                 :             :     return;
    5090                 :             : 
    5091                 :   293494936 :   gcc_assert ((!both_p && !fallback_p)
    5092                 :             :               || startswith (name, "__builtin_"));
    5093                 :             : 
    5094                 :   293494936 :   libname = name + strlen ("__builtin_");
    5095                 :   293494936 :   decl = add_builtin_function (name, fntype, fncode, fnclass,
    5096                 :             :                                (fallback_p ? libname : NULL),
    5097                 :             :                                fnattrs);
    5098                 :             : 
    5099                 :   293494936 :   set_builtin_decl (fncode, decl, implicit_p);
    5100                 :             : 
    5101                 :   293494936 :   if (both_p
    5102                 :   159312506 :       && !flag_no_builtin && !builtin_function_disabled_p (libname)
    5103                 :   452387318 :       && !(nonansi_p && flag_no_nonansi_builtin))
    5104                 :   143625339 :     add_builtin_function (libname, libtype, fncode, fnclass,
    5105                 :             :                           NULL, fnattrs);
    5106                 :             : }
    5107                 :             : 
    5108                 :             : /* Nonzero if the type T promotes to int.  This is (nearly) the
    5109                 :             :    integral promotions defined in ISO C99 6.3.1.1/2.  */
    5110                 :             : 
    5111                 :             : bool
    5112                 :   491822092 : c_promoting_integer_type_p (const_tree t)
    5113                 :             : {
    5114                 :   491822092 :   switch (TREE_CODE (t))
    5115                 :             :     {
    5116                 :   381950359 :     case INTEGER_TYPE:
    5117                 :   381950359 :       return (TYPE_MAIN_VARIANT (t) == char_type_node
    5118                 :   376476704 :               || TYPE_MAIN_VARIANT (t) == signed_char_type_node
    5119                 :   376070453 :               || TYPE_MAIN_VARIANT (t) == unsigned_char_type_node
    5120                 :   361720119 :               || TYPE_MAIN_VARIANT (t) == short_integer_type_node
    5121                 :   360696020 :               || TYPE_MAIN_VARIANT (t) == short_unsigned_type_node
    5122                 :   737237756 :               || TYPE_PRECISION (t) < TYPE_PRECISION (integer_type_node));
    5123                 :             : 
    5124                 :      657530 :     case ENUMERAL_TYPE:
    5125                 :             :       /* ??? Technically all enumerations not larger than an int
    5126                 :             :          promote to an int.  But this is used along code paths
    5127                 :             :          that only want to notice a size change.  */
    5128                 :      657530 :       return TYPE_PRECISION (t) < TYPE_PRECISION (integer_type_node);
    5129                 :             : 
    5130                 :             :     case BOOLEAN_TYPE:
    5131                 :             :       return true;
    5132                 :             : 
    5133                 :             :     default:
    5134                 :             :       return false;
    5135                 :             :     }
    5136                 :             : }
    5137                 :             : 
    5138                 :             : /* Return 1 if PARMS specifies a fixed number of parameters
    5139                 :             :    and none of their types is affected by default promotions.  */
    5140                 :             : 
    5141                 :             : bool
    5142                 :       21746 : self_promoting_args_p (const_tree parms)
    5143                 :             : {
    5144                 :       21746 :   const_tree t;
    5145                 :       64734 :   for (t = parms; t; t = TREE_CHAIN (t))
    5146                 :             :     {
    5147                 :       43519 :       tree type = TREE_VALUE (t);
    5148                 :             : 
    5149                 :       43519 :       if (type == error_mark_node)
    5150                 :           2 :         continue;
    5151                 :             : 
    5152                 :       43517 :       if (TREE_CHAIN (t) == NULL_TREE && type != void_type_node)
    5153                 :             :         return false;
    5154                 :             : 
    5155                 :       43036 :       if (type == NULL_TREE)
    5156                 :             :         return false;
    5157                 :             : 
    5158                 :       43036 :       if (TYPE_MAIN_VARIANT (type) == float_type_node)
    5159                 :             :         return false;
    5160                 :             : 
    5161                 :       42991 :       if (c_promoting_integer_type_p (type))
    5162                 :             :         return false;
    5163                 :             :     }
    5164                 :             :   return true;
    5165                 :             : }
    5166                 :             : 
    5167                 :             : /* Recursively remove any '*' or '&' operator from TYPE.  */
    5168                 :             : tree
    5169                 :    34417392 : strip_pointer_operator (tree t)
    5170                 :             : {
    5171                 :    36556128 :   while (POINTER_TYPE_P (t))
    5172                 :     2138736 :     t = TREE_TYPE (t);
    5173                 :    34417392 :   return t;
    5174                 :             : }
    5175                 :             : 
    5176                 :             : /* Recursively remove pointer or array type from TYPE. */
    5177                 :             : tree
    5178                 :    10455215 : strip_pointer_or_array_types (tree t)
    5179                 :             : {
    5180                 :    15157181 :   while (TREE_CODE (t) == ARRAY_TYPE || POINTER_TYPE_P (t))
    5181                 :     4701966 :     t = TREE_TYPE (t);
    5182                 :    10455215 :   return t;
    5183                 :             : }
    5184                 :             : 
    5185                 :             : /* Used to compare case labels.  K1 and K2 are actually tree nodes
    5186                 :             :    representing case labels, or NULL_TREE for a `default' label.
    5187                 :             :    Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after
    5188                 :             :    K2, and 0 if K1 and K2 are equal.  */
    5189                 :             : 
    5190                 :             : int
    5191                 :    27348510 : case_compare (splay_tree_key k1, splay_tree_key k2)
    5192                 :             : {
    5193                 :             :   /* Consider a NULL key (such as arises with a `default' label) to be
    5194                 :             :      smaller than anything else.  */
    5195                 :    27348510 :   if (!k1)
    5196                 :     3710917 :     return k2 ? -1 : 0;
    5197                 :    24305357 :   else if (!k2)
    5198                 :             :     return k1 ? 1 : 0;
    5199                 :             : 
    5200                 :    23505287 :   return tree_int_cst_compare ((tree) k1, (tree) k2);
    5201                 :             : }
    5202                 :             : 
    5203                 :             : /* Process a case label, located at LOC, for the range LOW_VALUE
    5204                 :             :    ... HIGH_VALUE.  If LOW_VALUE and HIGH_VALUE are both NULL_TREE
    5205                 :             :    then this case label is actually a `default' label.  If only
    5206                 :             :    HIGH_VALUE is NULL_TREE, then case label was declared using the
    5207                 :             :    usual C/C++ syntax, rather than the GNU case range extension.
    5208                 :             :    CASES is a tree containing all the case ranges processed so far;
    5209                 :             :    COND is the condition for the switch-statement itself.
    5210                 :             :    Returns the CASE_LABEL_EXPR created, or ERROR_MARK_NODE if no
    5211                 :             :    CASE_LABEL_EXPR is created.  ATTRS are the attributes to be applied
    5212                 :             :    to the label.  */
    5213                 :             : 
    5214                 :             : tree
    5215                 :     2992770 : c_add_case_label (location_t loc, splay_tree cases, tree cond,
    5216                 :             :                   tree low_value, tree high_value, tree attrs)
    5217                 :             : {
    5218                 :     2992770 :   tree type;
    5219                 :     2992770 :   tree label;
    5220                 :     2992770 :   tree case_label;
    5221                 :     2992770 :   splay_tree_node node;
    5222                 :             : 
    5223                 :             :   /* Create the LABEL_DECL itself.  */
    5224                 :     2992770 :   label = create_artificial_label (loc);
    5225                 :     2992770 :   decl_attributes (&label, attrs, 0);
    5226                 :             : 
    5227                 :             :   /* If there was an error processing the switch condition, bail now
    5228                 :             :      before we get more confused.  */
    5229                 :     2992770 :   if (!cond || cond == error_mark_node)
    5230                 :           0 :     goto error_out;
    5231                 :             : 
    5232                 :     2691645 :   if ((low_value && TREE_TYPE (low_value)
    5233                 :     2691645 :        && POINTER_TYPE_P (TREE_TYPE (low_value)))
    5234                 :     5684414 :       || (high_value && TREE_TYPE (high_value)
    5235                 :         440 :           && POINTER_TYPE_P (TREE_TYPE (high_value))))
    5236                 :             :     {
    5237                 :           1 :       error_at (loc, "pointers are not permitted as case values");
    5238                 :           1 :       goto error_out;
    5239                 :             :     }
    5240                 :             : 
    5241                 :             :   /* Case ranges are a GNU extension.  */
    5242                 :     2992769 :   if (high_value)
    5243                 :             :     {
    5244                 :         440 :       if (c_dialect_cxx ())
    5245                 :         126 :         pedwarn (loc, OPT_Wpedantic,
    5246                 :             :                  "range expressions in switch statements are non-standard");
    5247                 :         314 :       else if (warn_c23_c2y_compat > 0)
    5248                 :             :         {
    5249                 :          13 :           if (pedantic && !flag_isoc2y)
    5250                 :           0 :             pedwarn (loc, OPT_Wc23_c2y_compat,
    5251                 :             :                      "ISO C does not support range expressions in switch "
    5252                 :             :                      "statements before C2Y");
    5253                 :             :           else
    5254                 :          13 :             warning_at (loc, OPT_Wc23_c2y_compat,
    5255                 :             :                         "ISO C does not support range expressions in switch "
    5256                 :             :                         "statements before C2Y");
    5257                 :             :         }
    5258                 :         301 :       else if (warn_c23_c2y_compat && pedantic && !flag_isoc2y)
    5259                 :          28 :         pedwarn (loc, OPT_Wpedantic,
    5260                 :             :                  "ISO C does not support range expressions in switch "
    5261                 :             :                  "statements before C2Y");
    5262                 :             :     }
    5263                 :             : 
    5264                 :     2992769 :   type = TREE_TYPE (cond);
    5265                 :     2992769 :   if (low_value)
    5266                 :             :     {
    5267                 :     2691644 :       low_value = check_case_value (loc, low_value);
    5268                 :     2691644 :       tree tem = NULL_TREE;
    5269                 :     2691644 :       if (high_value
    5270                 :         440 :           && !c_dialect_cxx ()
    5271                 :         314 :           && low_value != error_mark_node
    5272                 :         313 :           && !int_fits_type_p (low_value, type)
    5273                 :     2692084 :           && pedwarn (loc, OPT_Wpedantic,
    5274                 :             :                       "conversion of %qE to %qT in range expression changes "
    5275                 :             :                       "value to %qE", low_value, type,
    5276                 :          20 :                       (tem = fold_convert (type, low_value))))
    5277                 :          20 :         low_value = tem;
    5278                 :     2691644 :       low_value = convert_and_check (loc, type, low_value);
    5279                 :     2691644 :       low_value = fold (low_value);
    5280                 :     2691644 :       if (low_value == error_mark_node)
    5281                 :         147 :         goto error_out;
    5282                 :             :     }
    5283                 :     2992622 :   if (high_value)
    5284                 :             :     {
    5285                 :         439 :       high_value = check_case_value (loc, high_value);
    5286                 :         439 :       tree tem = NULL_TREE;
    5287                 :         439 :       if (!c_dialect_cxx ()
    5288                 :         313 :           && high_value != error_mark_node
    5289                 :         312 :           && !int_fits_type_p (high_value, type)
    5290                 :         752 :           && pedwarn (loc, OPT_Wpedantic,
    5291                 :             :                       "conversion of %qE to %qT in range expression changes "
    5292                 :             :                       "value to %qE", high_value, type,
    5293                 :          20 :                       (tem = fold_convert (type, high_value))))
    5294                 :          20 :         high_value = tem;
    5295                 :         439 :       high_value = convert_and_check (loc, type, high_value);
    5296                 :         439 :       high_value = fold (high_value);
    5297                 :         439 :       if (high_value == error_mark_node)
    5298                 :           4 :         goto error_out;
    5299                 :             :     }
    5300                 :             : 
    5301                 :     2992618 :   if (low_value && high_value)
    5302                 :             :     {
    5303                 :             :       /* If the LOW_VALUE and HIGH_VALUE are the same, then this isn't
    5304                 :             :          really a case range, even though it was written that way.
    5305                 :             :          Remove the HIGH_VALUE to simplify later processing.  */
    5306                 :         435 :       if (tree_int_cst_equal (low_value, high_value))
    5307                 :             :         high_value = NULL_TREE;
    5308                 :         416 :       else if (!tree_int_cst_lt (low_value, high_value))
    5309                 :             :         {
    5310                 :          28 :           warning_at (loc, 0, "empty range specified");
    5311                 :          28 :           goto error_out;
    5312                 :             :         }
    5313                 :             :     }
    5314                 :             : 
    5315                 :             :   /* Look up the LOW_VALUE in the table of case labels we already
    5316                 :             :      have.  */
    5317                 :     2992590 :   node = splay_tree_lookup (cases, (splay_tree_key) low_value);
    5318                 :             :   /* If there was not an exact match, check for overlapping ranges.
    5319                 :             :      There's no need to do this if there's no LOW_VALUE or HIGH_VALUE;
    5320                 :             :      that's a `default' label and the only overlap is an exact match.  */
    5321                 :     2992590 :   if (!node && (low_value || high_value))
    5322                 :             :     {
    5323                 :     2691447 :       splay_tree_node low_bound;
    5324                 :     2691447 :       splay_tree_node high_bound;
    5325                 :             : 
    5326                 :             :       /* Even though there wasn't an exact match, there might be an
    5327                 :             :          overlap between this case range and another case range.
    5328                 :             :          Since we've (inductively) not allowed any overlapping case
    5329                 :             :          ranges, we simply need to find the greatest low case label
    5330                 :             :          that is smaller that LOW_VALUE, and the smallest low case
    5331                 :             :          label that is greater than LOW_VALUE.  If there is an overlap
    5332                 :             :          it will occur in one of these two ranges.  */
    5333                 :     2691447 :       low_bound = splay_tree_predecessor (cases,
    5334                 :             :                                           (splay_tree_key) low_value);
    5335                 :     2691447 :       high_bound = splay_tree_successor (cases,
    5336                 :             :                                          (splay_tree_key) low_value);
    5337                 :             : 
    5338                 :             :       /* Check to see if the LOW_BOUND overlaps.  It is smaller than
    5339                 :             :          the LOW_VALUE, so there is no need to check unless the
    5340                 :             :          LOW_BOUND is in fact itself a case range.  */
    5341                 :     2691447 :       if (low_bound
    5342                 :     1816286 :           && CASE_HIGH ((tree) low_bound->value)
    5343                 :     2691614 :           && tree_int_cst_compare (CASE_HIGH ((tree) low_bound->value),
    5344                 :             :                                     low_value) >= 0)
    5345                 :             :         node = low_bound;
    5346                 :             :       /* Check to see if the HIGH_BOUND overlaps.  The low end of that
    5347                 :             :          range is bigger than the low end of the current range, so we
    5348                 :             :          are only interested if the current range is a real range, and
    5349                 :             :          not an ordinary case label.  */
    5350                 :     2691435 :       else if (high_bound
    5351                 :     2691435 :                && high_value
    5352                 :     2691435 :                && (tree_int_cst_compare ((tree) high_bound->key,
    5353                 :             :                                          high_value)
    5354                 :             :                    <= 0))
    5355                 :             :         node = high_bound;
    5356                 :             :     }
    5357                 :             :   /* If there was an overlap, issue an error.  */
    5358                 :     2992571 :   if (node)
    5359                 :             :     {
    5360                 :          37 :       tree duplicate = CASE_LABEL ((tree) node->value);
    5361                 :             : 
    5362                 :          37 :       if (high_value)
    5363                 :             :         {
    5364                 :          10 :           error_at (loc, "duplicate (or overlapping) case value");
    5365                 :          10 :           inform (DECL_SOURCE_LOCATION (duplicate),
    5366                 :             :                   "this is the first entry overlapping that value");
    5367                 :             :         }
    5368                 :          27 :       else if (low_value)
    5369                 :             :         {
    5370                 :          26 :           error_at (loc, "duplicate case value") ;
    5371                 :          26 :           inform (DECL_SOURCE_LOCATION (duplicate), "previously used here");
    5372                 :             :         }
    5373                 :             :       else
    5374                 :             :         {
    5375                 :           1 :           error_at (loc, "multiple default labels in one switch");
    5376                 :           1 :           inform (DECL_SOURCE_LOCATION (duplicate),
    5377                 :             :                   "this is the first default label");
    5378                 :             :         }
    5379                 :          37 :       goto error_out;
    5380                 :             :     }
    5381                 :             : 
    5382                 :             :   /* Add a CASE_LABEL to the statement-tree.  */
    5383                 :     2992553 :   case_label = add_stmt (build_case_label (low_value, high_value, label));
    5384                 :             :   /* Register this case label in the splay tree.  */
    5385                 :     2992553 :   splay_tree_insert (cases,
    5386                 :             :                      (splay_tree_key) low_value,
    5387                 :             :                      (splay_tree_value) case_label);
    5388                 :             : 
    5389                 :     2992553 :   return case_label;
    5390                 :             : 
    5391                 :         217 :  error_out:
    5392                 :             :   /* Add a label so that the back-end doesn't think that the beginning of
    5393                 :             :      the switch is unreachable.  Note that we do not add a case label, as
    5394                 :             :      that just leads to duplicates and thence to failure later on.  */
    5395                 :         217 :   if (!cases->root)
    5396                 :             :     {
    5397                 :         153 :       tree t = create_artificial_label (loc);
    5398                 :         153 :       add_stmt (build_stmt (loc, LABEL_EXPR, t));
    5399                 :             :     }
    5400                 :         217 :   return error_mark_node;
    5401                 :             : }
    5402                 :             : 
    5403                 :             : /* Subroutine of c_switch_covers_all_cases_p, called via
    5404                 :             :    splay_tree_foreach.  Return 1 if it doesn't cover all the cases.
    5405                 :             :    ARGS[0] is initially NULL and after the first iteration is the
    5406                 :             :    so far highest case label.  ARGS[1] is the minimum of SWITCH_COND's
    5407                 :             :    type.  */
    5408                 :             : 
    5409                 :             : static int
    5410                 :      132663 : c_switch_covers_all_cases_p_1 (splay_tree_node node, void *data)
    5411                 :             : {
    5412                 :      132663 :   tree label = (tree) node->value;
    5413                 :      132663 :   tree *args = (tree *) data;
    5414                 :             : 
    5415                 :             :   /* If there is a default case, we shouldn't have called this.  */
    5416                 :      132663 :   gcc_assert (CASE_LOW (label));
    5417                 :             : 
    5418                 :      132663 :   if (args[0] == NULL_TREE)
    5419                 :             :     {
    5420                 :       46239 :       if (wi::to_widest (args[1]) < wi::to_widest (CASE_LOW (label)))
    5421                 :             :         return 1;
    5422                 :             :     }
    5423                 :       86424 :   else if (wi::add (wi::to_widest (args[0]), 1)
    5424                 :      172848 :            != wi::to_widest (CASE_LOW (label)))
    5425                 :             :     return 1;
    5426                 :      114922 :   if (CASE_HIGH (label))
    5427                 :         109 :     args[0] = CASE_HIGH (label);
    5428                 :             :   else
    5429                 :      114813 :     args[0] = CASE_LOW (label);
    5430                 :             :   return 0;
    5431                 :             : }
    5432                 :             : 
    5433                 :             : /* Return true if switch with CASES and switch condition with type
    5434                 :             :    covers all possible values in the case labels.  */
    5435                 :             : 
    5436                 :             : bool
    5437                 :       79474 : c_switch_covers_all_cases_p (splay_tree cases, tree type)
    5438                 :             : {
    5439                 :             :   /* If there is default:, this is always the case.  */
    5440                 :       79474 :   splay_tree_node default_node
    5441                 :       79474 :     = splay_tree_lookup (cases, (splay_tree_key) NULL);
    5442                 :       79474 :   if (default_node)
    5443                 :             :     return true;
    5444                 :             : 
    5445                 :       46771 :   if (!INTEGRAL_TYPE_P (type))
    5446                 :             :     return false;
    5447                 :             : 
    5448                 :       46704 :   tree args[2] = { NULL_TREE, TYPE_MIN_VALUE (type) };
    5449                 :       46704 :   if (splay_tree_foreach (cases, c_switch_covers_all_cases_p_1, args))
    5450                 :             :     return false;
    5451                 :             : 
    5452                 :             :   /* If there are no cases at all, or if the highest case label
    5453                 :             :      is smaller than TYPE_MAX_VALUE, return false.  */
    5454                 :       28963 :   if (args[0] == NULL_TREE
    5455                 :       28963 :       || wi::to_widest (args[0]) < wi::to_widest (TYPE_MAX_VALUE (type)))
    5456                 :       28917 :     return false;
    5457                 :             : 
    5458                 :             :   return true;
    5459                 :             : }
    5460                 :             : 
    5461                 :             : /* Return true if stmt can fall through.  Used by block_may_fallthru
    5462                 :             :    default case.  */
    5463                 :             : 
    5464                 :             : bool
    5465                 :     1735943 : c_block_may_fallthru (const_tree stmt)
    5466                 :             : {
    5467                 :     1735943 :   switch (TREE_CODE (stmt))
    5468                 :             :     {
    5469                 :         276 :     case SWITCH_STMT:
    5470                 :         276 :       return (!SWITCH_STMT_ALL_CASES_P (stmt)
    5471                 :         184 :               || !SWITCH_STMT_NO_BREAK_P (stmt)
    5472                 :         304 :               || block_may_fallthru (SWITCH_STMT_BODY (stmt)));
    5473                 :             : 
    5474                 :             :     default:
    5475                 :             :       return true;
    5476                 :             :     }
    5477                 :             : }
    5478                 :             : 
    5479                 :             : /* Finish an expression taking the address of LABEL (an
    5480                 :             :    IDENTIFIER_NODE).  Returns an expression for the address.
    5481                 :             : 
    5482                 :             :    LOC is the location for the expression returned.  */
    5483                 :             : 
    5484                 :             : tree
    5485                 :        2117 : finish_label_address_expr (tree label, location_t loc)
    5486                 :             : {
    5487                 :        2117 :   tree result;
    5488                 :             : 
    5489                 :        2117 :   pedwarn (input_location, OPT_Wpedantic, "taking the address of a label is non-standard");
    5490                 :             : 
    5491                 :        2117 :   if (label == error_mark_node)
    5492                 :             :     return error_mark_node;
    5493                 :             : 
    5494                 :        2111 :   label = lookup_label (label);
    5495                 :        2111 :   if (label == NULL_TREE)
    5496                 :           5 :     result = null_pointer_node;
    5497                 :             :   else
    5498                 :             :     {
    5499                 :        2106 :       TREE_USED (label) = 1;
    5500                 :        2106 :       result = build1 (ADDR_EXPR, ptr_type_node, label);
    5501                 :             :       /* The current function is not necessarily uninlinable.
    5502                 :             :          Computed gotos are incompatible with inlining, but the value
    5503                 :             :          here could be used only in a diagnostic, for example.  */
    5504                 :        2106 :       protected_set_expr_location (result, loc);
    5505                 :             :     }
    5506                 :             : 
    5507                 :             :   return result;
    5508                 :             : }
    5509                 :             : 
    5510                 :             : 
    5511                 :             : /* Given a boolean expression ARG, return a tree representing an increment
    5512                 :             :    or decrement (as indicated by CODE) of ARG.  The front end must check for
    5513                 :             :    invalid cases (e.g., decrement in C++).  */
    5514                 :             : tree
    5515                 :          85 : boolean_increment (enum tree_code code, tree arg)
    5516                 :             : {
    5517                 :          85 :   tree val;
    5518                 :          85 :   tree true_res = build_int_cst (TREE_TYPE (arg), 1);
    5519                 :             : 
    5520                 :          85 :   arg = stabilize_reference (arg);
    5521                 :          85 :   switch (code)
    5522                 :             :     {
    5523                 :          28 :     case PREINCREMENT_EXPR:
    5524                 :          28 :       val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg, true_res);
    5525                 :          28 :       break;
    5526                 :          29 :     case POSTINCREMENT_EXPR:
    5527                 :          29 :       val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg, true_res);
    5528                 :          29 :       arg = save_expr (arg);
    5529                 :          29 :       val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), val, arg);
    5530                 :          29 :       val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), arg, val);
    5531                 :          29 :       break;
    5532                 :          14 :     case PREDECREMENT_EXPR:
    5533                 :          14 :       val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg,
    5534                 :             :                     invert_truthvalue_loc (input_location, arg));
    5535                 :          14 :       break;
    5536                 :          14 :     case POSTDECREMENT_EXPR:
    5537                 :          14 :       val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg,
    5538                 :             :                     invert_truthvalue_loc (input_location, arg));
    5539                 :          14 :       arg = save_expr (arg);
    5540                 :          14 :       val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), val, arg);
    5541                 :          14 :       val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), arg, val);
    5542                 :          14 :       break;
    5543                 :           0 :     default:
    5544                 :           0 :       gcc_unreachable ();
    5545                 :             :     }
    5546                 :          85 :   TREE_SIDE_EFFECTS (val) = 1;
    5547                 :          85 :   return val;
    5548                 :             : }
    5549                 :             : 
    5550                 :             : /* Built-in macros for stddef.h and stdint.h, that require macros
    5551                 :             :    defined in this file.  */
    5552                 :             : void
    5553                 :      205731 : c_stddef_cpp_builtins(void)
    5554                 :             : {
    5555                 :      211142 :   builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE, 0);
    5556                 :      211142 :   builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE, 0);
    5557                 :      211142 :   builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE, 0);
    5558                 :             :   /* C++ has wchar_t as a builtin type, C doesn't, so if WINT_TYPE
    5559                 :             :      maps to wchar_t, define it to the underlying WCHAR_TYPE in C, and
    5560                 :             :      to wchar_t in C++, so the desired type equivalence holds.  */
    5561                 :      205731 :   if (!c_dialect_cxx ()
    5562                 :             :       && strcmp (WINT_TYPE, "wchar_t") == 0)
    5563                 :             :     builtin_define_with_value ("__WINT_TYPE__", WCHAR_TYPE, 0);
    5564                 :             :   else
    5565                 :      205731 :     builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE, 0);
    5566                 :      211142 :   builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE, 0);
    5567                 :      211142 :   builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE, 0);
    5568                 :      205731 :   if (flag_char8_t)
    5569                 :      128188 :     builtin_define_with_value ("__CHAR8_TYPE__", CHAR8_TYPE, 0);
    5570                 :      205731 :   builtin_define_with_value ("__CHAR16_TYPE__", CHAR16_TYPE, 0);
    5571                 :      205731 :   builtin_define_with_value ("__CHAR32_TYPE__", CHAR32_TYPE, 0);
    5572                 :      205731 :   if (SIG_ATOMIC_TYPE)
    5573                 :      205731 :     builtin_define_with_value ("__SIG_ATOMIC_TYPE__", SIG_ATOMIC_TYPE, 0);
    5574                 :      205731 :   if (INT8_TYPE)
    5575                 :      205731 :     builtin_define_with_value ("__INT8_TYPE__", INT8_TYPE, 0);
    5576                 :      205731 :   if (INT16_TYPE)
    5577                 :      205731 :     builtin_define_with_value ("__INT16_TYPE__", INT16_TYPE, 0);
    5578                 :      205731 :   if (INT32_TYPE)
    5579                 :      205731 :     builtin_define_with_value ("__INT32_TYPE__", INT32_TYPE, 0);
    5580                 :      205731 :   if (INT64_TYPE)
    5581                 :      211142 :     builtin_define_with_value ("__INT64_TYPE__", INT64_TYPE, 0);
    5582                 :      205731 :   if (UINT8_TYPE)
    5583                 :      205731 :     builtin_define_with_value ("__UINT8_TYPE__", UINT8_TYPE, 0);
    5584                 :      205731 :   if (UINT16_TYPE)
    5585                 :      205731 :     builtin_define_with_value ("__UINT16_TYPE__", UINT16_TYPE, 0);
    5586                 :      205731 :   if (UINT32_TYPE)
    5587                 :      205731 :     builtin_define_with_value ("__UINT32_TYPE__", UINT32_TYPE, 0);
    5588                 :      205731 :   if (UINT64_TYPE)
    5589                 :      211142 :     builtin_define_with_value ("__UINT64_TYPE__", UINT64_TYPE, 0);
    5590                 :      205731 :   if (INT_LEAST8_TYPE)
    5591                 :      205731 :     builtin_define_with_value ("__INT_LEAST8_TYPE__", INT_LEAST8_TYPE, 0);
    5592                 :      205731 :   if (INT_LEAST16_TYPE)
    5593                 :      205731 :     builtin_define_with_value ("__INT_LEAST16_TYPE__", INT_LEAST16_TYPE, 0);
    5594                 :      205731 :   if (INT_LEAST32_TYPE)
    5595                 :      205731 :     builtin_define_with_value ("__INT_LEAST32_TYPE__", INT_LEAST32_TYPE, 0);
    5596                 :      205731 :   if (INT_LEAST64_TYPE)
    5597                 :      211142 :     builtin_define_with_value ("__INT_LEAST64_TYPE__", INT_LEAST64_TYPE, 0);
    5598                 :      205731 :   if (UINT_LEAST8_TYPE)
    5599                 :      205731 :     builtin_define_with_value ("__UINT_LEAST8_TYPE__", UINT_LEAST8_TYPE, 0);
    5600                 :      205731 :   if (UINT_LEAST16_TYPE)
    5601                 :      205731 :     builtin_define_with_value ("__UINT_LEAST16_TYPE__", UINT_LEAST16_TYPE, 0);
    5602                 :      205731 :   if (UINT_LEAST32_TYPE)
    5603                 :      205731 :     builtin_define_with_value ("__UINT_LEAST32_TYPE__", UINT_LEAST32_TYPE, 0);
    5604                 :      205731 :   if (UINT_LEAST64_TYPE)
    5605                 :      211142 :     builtin_define_with_value ("__UINT_LEAST64_TYPE__", UINT_LEAST64_TYPE, 0);
    5606                 :      205731 :   if (INT_FAST8_TYPE)
    5607                 :      205731 :     builtin_define_with_value ("__INT_FAST8_TYPE__", INT_FAST8_TYPE, 0);
    5608                 :      205731 :   if (INT_FAST16_TYPE)
    5609                 :      211142 :     builtin_define_with_value ("__INT_FAST16_TYPE__", INT_FAST16_TYPE, 0);
    5610                 :      205731 :   if (INT_FAST32_TYPE)
    5611                 :      211142 :     builtin_define_with_value ("__INT_FAST32_TYPE__", INT_FAST32_TYPE, 0);
    5612                 :      205731 :   if (INT_FAST64_TYPE)
    5613                 :      211142 :     builtin_define_with_value ("__INT_FAST64_TYPE__", INT_FAST64_TYPE, 0);
    5614                 :      205731 :   if (UINT_FAST8_TYPE)
    5615                 :      205731 :     builtin_define_with_value ("__UINT_FAST8_TYPE__", UINT_FAST8_TYPE, 0);
    5616                 :      205731 :   if (UINT_FAST16_TYPE)
    5617                 :      211142 :     builtin_define_with_value ("__UINT_FAST16_TYPE__", UINT_FAST16_TYPE, 0);
    5618                 :      205731 :   if (UINT_FAST32_TYPE)
    5619                 :      211142 :     builtin_define_with_value ("__UINT_FAST32_TYPE__", UINT_FAST32_TYPE, 0);
    5620                 :      205731 :   if (UINT_FAST64_TYPE)
    5621                 :      211142 :     builtin_define_with_value ("__UINT_FAST64_TYPE__", UINT_FAST64_TYPE, 0);
    5622                 :      205731 :   if (INTPTR_TYPE)
    5623                 :      211142 :     builtin_define_with_value ("__INTPTR_TYPE__", INTPTR_TYPE, 0);
    5624                 :      205731 :   if (UINTPTR_TYPE)
    5625                 :      211142 :     builtin_define_with_value ("__UINTPTR_TYPE__", UINTPTR_TYPE, 0);
    5626                 :             :   /* GIMPLE FE testcases need access to the GCC internal 'sizetype'.
    5627                 :             :      Expose it as __SIZETYPE__.  */
    5628                 :      205731 :   if (flag_gimple)
    5629                 :         215 :     builtin_define_with_value ("__SIZETYPE__", SIZETYPE, 0);
    5630                 :      205731 : }
    5631                 :             : 
    5632                 :             : static void
    5633                 :      206257 : c_init_attributes (void)
    5634                 :             : {
    5635                 :             :   /* Fill in the built_in_attributes array.  */
    5636                 :             : #define DEF_ATTR_NULL_TREE(ENUM)                                \
    5637                 :             :   built_in_attributes[(int) ENUM] = NULL_TREE;
    5638                 :             : #define DEF_ATTR_INT(ENUM, VALUE)                               \
    5639                 :             :   built_in_attributes[(int) ENUM] = build_int_cst (integer_type_node, VALUE);
    5640                 :             : #define DEF_ATTR_STRING(ENUM, VALUE)                            \
    5641                 :             :   built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
    5642                 :             : #define DEF_ATTR_IDENT(ENUM, STRING)                            \
    5643                 :             :   built_in_attributes[(int) ENUM] = get_identifier (STRING);
    5644                 :             : #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
    5645                 :             :   built_in_attributes[(int) ENUM]                       \
    5646                 :             :     = tree_cons (built_in_attributes[(int) PURPOSE],    \
    5647                 :             :                  built_in_attributes[(int) VALUE],      \
    5648                 :             :                  built_in_attributes[(int) CHAIN]);
    5649                 :             : #include "builtin-attrs.def"
    5650                 :             : #undef DEF_ATTR_NULL_TREE
    5651                 :             : #undef DEF_ATTR_INT
    5652                 :             : #undef DEF_ATTR_IDENT
    5653                 :             : #undef DEF_ATTR_TREE_LIST
    5654                 :      206257 : }
    5655                 :             : 
    5656                 :             : /* Check whether the byte alignment ALIGN is a valid user-specified
    5657                 :             :    alignment less than the supported maximum.  If so, return ALIGN's
    5658                 :             :    base-2 log; if not, output an error and return -1.  If OBJFILE
    5659                 :             :    then reject alignments greater than MAX_OFILE_ALIGNMENT when
    5660                 :             :    converted to bits.  Otherwise, consider valid only alignments
    5661                 :             :    that are less than HOST_BITS_PER_INT - LOG2_BITS_PER_UNIT.
    5662                 :             :    Zero is not considered a valid argument (and results in -1 on
    5663                 :             :    return) but it only triggers a warning when WARN_ZERO is set.  */
    5664                 :             : 
    5665                 :             : int
    5666                 :      565330 : check_user_alignment (const_tree align, bool objfile, bool warn_zero)
    5667                 :             : {
    5668                 :      565330 :   if (error_operand_p (align))
    5669                 :             :     return -1;
    5670                 :             : 
    5671                 :      565307 :   if (TREE_CODE (align) != INTEGER_CST
    5672                 :      565307 :       || !INTEGRAL_TYPE_P (TREE_TYPE (align)))
    5673                 :             :     {
    5674                 :          27 :       error ("requested alignment is not an integer constant");
    5675                 :          27 :       return -1;
    5676                 :             :     }
    5677                 :             : 
    5678                 :      565280 :   if (integer_zerop (align))
    5679                 :             :     {
    5680                 :          75 :       if (warn_zero)
    5681                 :          63 :         warning (OPT_Wattributes,
    5682                 :             :                  "requested alignment %qE is not a positive power of 2",
    5683                 :             :                  align);
    5684                 :          75 :       return -1;
    5685                 :             :     }
    5686                 :             : 
    5687                 :             :   /* Log2 of the byte alignment ALIGN.  */
    5688                 :      565205 :   int log2align;
    5689                 :      565205 :   if (tree_int_cst_sgn (align) == -1
    5690                 :      565205 :       || (log2align = tree_log2 (align)) == -1)
    5691                 :             :     {
    5692                 :          36 :       error ("requested alignment %qE is not a positive power of 2",
    5693                 :             :              align);
    5694                 :          36 :       return -1;
    5695                 :             :     }
    5696                 :             : 
    5697                 :      565169 :   if (objfile)
    5698                 :             :     {
    5699                 :       15537 :       unsigned maxalign = MAX_OFILE_ALIGNMENT / BITS_PER_UNIT;
    5700                 :       15537 :       if (!tree_fits_uhwi_p (align) || tree_to_uhwi (align) > maxalign)
    5701                 :             :         {
    5702                 :          10 :           error ("requested alignment %qE exceeds object file maximum %u",
    5703                 :             :                  align, maxalign);
    5704                 :          10 :           return -1;
    5705                 :             :         }
    5706                 :             :     }
    5707                 :             : 
    5708                 :      565159 :   if (log2align >= HOST_BITS_PER_INT - LOG2_BITS_PER_UNIT)
    5709                 :             :     {
    5710                 :          17 :       error ("requested alignment %qE exceeds maximum %u",
    5711                 :             :              align, 1U << (HOST_BITS_PER_INT - LOG2_BITS_PER_UNIT - 1));
    5712                 :          17 :       return -1;
    5713                 :             :     }
    5714                 :             : 
    5715                 :             :   return log2align;
    5716                 :             : }
    5717                 :             : 
    5718                 :             : /* Determine the ELF symbol visibility for DECL, which is either a
    5719                 :             :    variable or a function.  It is an error to use this function if a
    5720                 :             :    definition of DECL is not available in this translation unit.
    5721                 :             :    Returns true if the final visibility has been determined by this
    5722                 :             :    function; false if the caller is free to make additional
    5723                 :             :    modifications.  */
    5724                 :             : 
    5725                 :             : bool
    5726                 :    50397477 : c_determine_visibility (tree decl)
    5727                 :             : {
    5728                 :    50397477 :   gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
    5729                 :             : 
    5730                 :             :   /* If the user explicitly specified the visibility with an
    5731                 :             :      attribute, honor that.  DECL_VISIBILITY will have been set during
    5732                 :             :      the processing of the attribute.  We check for an explicit
    5733                 :             :      attribute, rather than just checking DECL_VISIBILITY_SPECIFIED,
    5734                 :             :      to distinguish the use of an attribute from the use of a "#pragma
    5735                 :             :      GCC visibility push(...)"; in the latter case we still want other
    5736                 :             :      considerations to be able to overrule the #pragma.  */
    5737                 :    50397477 :   if (lookup_attribute ("visibility", DECL_ATTRIBUTES (decl))
    5738                 :             :       || (TARGET_DLLIMPORT_DECL_ATTRIBUTES
    5739                 :             :           && (lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl))
    5740                 :             :               || lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl)))))
    5741                 :             :     return true;
    5742                 :             : 
    5743                 :             :   /* Set default visibility to whatever the user supplied with
    5744                 :             :      visibility_specified depending on #pragma GCC visibility.  */
    5745                 :    49765966 :   if (!DECL_VISIBILITY_SPECIFIED (decl))
    5746                 :             :     {
    5747                 :    49764728 :       if (visibility_options.inpragma
    5748                 :    49764728 :           || DECL_VISIBILITY (decl) != default_visibility)
    5749                 :             :         {
    5750                 :      210184 :           DECL_VISIBILITY (decl) = default_visibility;
    5751                 :      210184 :           DECL_VISIBILITY_SPECIFIED (decl) = visibility_options.inpragma;
    5752                 :             :           /* If visibility changed and DECL already has DECL_RTL, ensure
    5753                 :             :              symbol flags are updated.  */
    5754                 :       14204 :           if (((VAR_P (decl) && TREE_STATIC (decl))
    5755                 :      210132 :                || TREE_CODE (decl) == FUNCTION_DECL)
    5756                 :      406216 :               && DECL_RTL_SET_P (decl))
    5757                 :           0 :             make_decl_rtl (decl);
    5758                 :             :         }
    5759                 :             :     }
    5760                 :             :   return false;
    5761                 :             : }
    5762                 :             : 
    5763                 :             : /* Data to communicate through check_function_arguments_recurse between
    5764                 :             :    check_function_nonnull and check_nonnull_arg.  */
    5765                 :             : 
    5766                 :             : struct nonnull_arg_ctx
    5767                 :             : {
    5768                 :             :   /* Location of the call.  */
    5769                 :             :   location_t loc;
    5770                 :             :   /* The function whose arguments are being checked and its type (used
    5771                 :             :      for calls through function pointers).  */
    5772                 :             :   const_tree fndecl, fntype;
    5773                 :             :   /* For nonnull_if_nonzero, index of the other arguments.  */
    5774                 :             :   unsigned HOST_WIDE_INT other1, other2;
    5775                 :             :   /* True if a warning has been issued.  */
    5776                 :             :   bool warned_p;
    5777                 :             : };
    5778                 :             : 
    5779                 :             : /* Check the argument list of a function call to CTX.FNDECL of CTX.FNTYPE
    5780                 :             :    for null in argument slots that are marked as requiring a non-null
    5781                 :             :    pointer argument.  The NARGS arguments are passed in the array ARGARRAY.
    5782                 :             :    Return true if we have warned.  */
    5783                 :             : 
    5784                 :             : static bool
    5785                 :     6369618 : check_function_nonnull (nonnull_arg_ctx &ctx, int nargs, tree *argarray)
    5786                 :             : {
    5787                 :     6369618 :   int firstarg = 0;
    5788                 :     6369618 :   if (TREE_CODE (ctx.fntype) == METHOD_TYPE)
    5789                 :             :     {
    5790                 :      455884 :       bool closure = false;
    5791                 :      455884 :       if (ctx.fndecl)
    5792                 :             :         {
    5793                 :             :           /* For certain lambda expressions the C++ front end emits calls
    5794                 :             :              that pass a null this pointer as an argument named __closure
    5795                 :             :              to the member operator() of empty function.  Detect those
    5796                 :             :              and avoid checking them, but proceed to check the remaining
    5797                 :             :              arguments.  */
    5798                 :      455733 :           tree arg0 = DECL_ARGUMENTS (ctx.fndecl);
    5799                 :      455733 :           if (tree arg0name = DECL_NAME (arg0))
    5800                 :      455733 :             closure = id_equal (arg0name, "__closure");
    5801                 :             :         }
    5802                 :             : 
    5803                 :             :       /* In calls to C++ non-static member functions check the this
    5804                 :             :          pointer regardless of whether the function is declared with
    5805                 :             :          attribute nonnull.  */
    5806                 :      907500 :       firstarg = 1;
    5807                 :      455733 :       if (!closure)
    5808                 :      451767 :         check_function_arguments_recurse (check_nonnull_arg, &ctx, argarray[0],
    5809                 :             :                                           firstarg, OPT_Wnonnull);
    5810                 :             :     }
    5811                 :             : 
    5812                 :     6369618 :   tree attrs = lookup_attribute ("nonnull", TYPE_ATTRIBUTES (ctx.fntype));
    5813                 :             : 
    5814                 :     6369618 :   tree a = attrs;
    5815                 :             :   /* See if any of the nonnull attributes has no arguments.  If so,
    5816                 :             :      then every pointer argument is checked (in which case the check
    5817                 :             :      for pointer type is done in check_nonnull_arg).  */
    5818                 :    12968790 :   while (a != NULL_TREE && TREE_VALUE (a) != NULL_TREE)
    5819                 :      102126 :     a = lookup_attribute ("nonnull", TREE_CHAIN (a));
    5820                 :             : 
    5821                 :     6369618 :   if (a != NULL_TREE)
    5822                 :       67483 :     for (int i = firstarg; i < nargs; i++)
    5823                 :       42181 :       check_function_arguments_recurse (check_nonnull_arg, &ctx, argarray[i],
    5824                 :       42181 :                                         i + 1, OPT_Wnonnull);
    5825                 :     6344316 :   else if (attrs)
    5826                 :             :     {
    5827                 :             :       /* Walk the argument list.  If we encounter an argument number we
    5828                 :             :          should check for non-null, do it.  */
    5829                 :      343467 :       for (int i = firstarg; i < nargs; i++)
    5830                 :             :         {
    5831                 :      146256 :           for (a = attrs; ; a = TREE_CHAIN (a))
    5832                 :             :             {
    5833                 :      398085 :               a = lookup_attribute ("nonnull", a);
    5834                 :      398085 :               if (a == NULL_TREE || nonnull_check_p (TREE_VALUE (a), i + 1))
    5835                 :             :                 break;
    5836                 :             :             }
    5837                 :             : 
    5838                 :      251829 :           if (a != NULL_TREE)
    5839                 :      122751 :             check_function_arguments_recurse (check_nonnull_arg, &ctx,
    5840                 :      122751 :                                               argarray[i], i + 1,
    5841                 :             :                                               OPT_Wnonnull);
    5842                 :      251829 :           a = NULL_TREE;
    5843                 :             :         }
    5844                 :             :     }
    5845                 :     6369618 :   if (a == NULL_TREE)
    5846                 :     6344316 :     for (attrs = TYPE_ATTRIBUTES (ctx.fntype);
    5847                 :     6400764 :          (attrs = lookup_attribute ("nonnull_if_nonzero", attrs));
    5848                 :       56448 :          attrs = TREE_CHAIN (attrs))
    5849                 :             :       {
    5850                 :       56448 :         tree args = TREE_VALUE (attrs);
    5851                 :       56448 :         unsigned int idx = TREE_INT_CST_LOW (TREE_VALUE (args)) - 1;
    5852                 :       56448 :         unsigned int idx2
    5853                 :       56448 :           = TREE_INT_CST_LOW (TREE_VALUE (TREE_CHAIN (args))) - 1;
    5854                 :       56448 :         unsigned int idx3 = idx2;
    5855                 :       56448 :         if (tree chain2 = TREE_CHAIN (TREE_CHAIN (args)))
    5856                 :         478 :           idx3 = TREE_INT_CST_LOW (TREE_VALUE (chain2)) - 1;
    5857                 :       56448 :         if (idx < (unsigned) nargs - firstarg
    5858                 :       56443 :             && idx2 < (unsigned) nargs - firstarg
    5859                 :       56438 :             && idx3 < (unsigned) nargs - firstarg
    5860                 :       56438 :             && INTEGRAL_TYPE_P (TREE_TYPE (argarray[firstarg + idx2]))
    5861                 :       56365 :             && integer_nonzerop (argarray[firstarg + idx2])
    5862                 :       31685 :             && INTEGRAL_TYPE_P (TREE_TYPE (argarray[firstarg + idx3]))
    5863                 :       88133 :             && integer_nonzerop (argarray[firstarg + idx3]))
    5864                 :             :           {
    5865                 :       31594 :             ctx.other1 = firstarg + idx2 + 1;
    5866                 :       31594 :             ctx.other2 = firstarg + idx3 + 1;
    5867                 :       31594 :             check_function_arguments_recurse (check_nonnull_arg, &ctx,
    5868                 :       31594 :                                               argarray[firstarg + idx],
    5869                 :       31594 :                                               firstarg + idx + 1,
    5870                 :             :                                               OPT_Wnonnull);
    5871                 :       31594 :             ctx.other1 = 0;
    5872                 :       31594 :             ctx.other2 = 0;
    5873                 :             :           }
    5874                 :             :       }
    5875                 :     6369618 :   return ctx.warned_p;
    5876                 :             : }
    5877                 :             : 
    5878                 :             : /* Check that the Nth argument of a function call (counting backwards
    5879                 :             :    from the end) is a (pointer)0.  The NARGS arguments are passed in the
    5880                 :             :    array ARGARRAY.  */
    5881                 :             : 
    5882                 :             : static void
    5883                 :     6355355 : check_function_sentinel (const_tree fntype, int nargs, tree *argarray)
    5884                 :             : {
    5885                 :     6355355 :   tree attr = lookup_attribute ("sentinel", TYPE_ATTRIBUTES (fntype));
    5886                 :             : 
    5887                 :     6355355 :   if (attr)
    5888                 :             :     {
    5889                 :         112 :       int len = 0;
    5890                 :         112 :       int pos = 0;
    5891                 :         112 :       tree sentinel;
    5892                 :         112 :       function_args_iterator iter;
    5893                 :         112 :       tree t;
    5894                 :             : 
    5895                 :             :       /* Skip over the named arguments.  */
    5896                 :         237 :       FOREACH_FUNCTION_ARGS (fntype, t, iter)
    5897                 :             :         {
    5898                 :         125 :           if (len == nargs)
    5899                 :             :             break;
    5900                 :         125 :           len++;
    5901                 :             :         }
    5902                 :             : 
    5903                 :         112 :       if (TREE_VALUE (attr))
    5904                 :             :         {
    5905                 :          59 :           tree p = TREE_VALUE (TREE_VALUE (attr));
    5906                 :          59 :           pos = TREE_INT_CST_LOW (p);
    5907                 :             :         }
    5908                 :             : 
    5909                 :             :       /* The sentinel must be one of the varargs, i.e.
    5910                 :             :          in position >= the number of fixed arguments.  */
    5911                 :         112 :       if ((nargs - 1 - pos) < len)
    5912                 :             :         {
    5913                 :          22 :           warning (OPT_Wformat_,
    5914                 :             :                    "not enough variable arguments to fit a sentinel");
    5915                 :          22 :           return;
    5916                 :             :         }
    5917                 :             : 
    5918                 :             :       /* Validate the sentinel.  */
    5919                 :          90 :       sentinel = fold_for_warn (argarray[nargs - 1 - pos]);
    5920                 :         138 :       if ((!POINTER_TYPE_P (TREE_TYPE (sentinel))
    5921                 :          42 :            || !integer_zerop (sentinel))
    5922                 :          56 :           && TREE_CODE (TREE_TYPE (sentinel)) != NULLPTR_TYPE
    5923                 :             :           /* Although __null (in C++) is only an integer we allow it
    5924                 :             :              nevertheless, as we are guaranteed that it's exactly
    5925                 :             :              as wide as a pointer, and we don't want to force
    5926                 :             :              users to cast the NULL they have written there.
    5927                 :             :              We warn with -Wstrict-null-sentinel, though.  */
    5928                 :         138 :           && (warn_strict_null_sentinel || null_node != sentinel))
    5929                 :          45 :         warning (OPT_Wformat_, "missing sentinel in function call");
    5930                 :             :     }
    5931                 :             : }
    5932                 :             : 
    5933                 :             : /* Check that the same argument isn't passed to two or more
    5934                 :             :    restrict-qualified formal and issue a -Wrestrict warning
    5935                 :             :    if it is.  Return true if a warning has been issued.  */
    5936                 :             : 
    5937                 :             : static bool
    5938                 :    52100810 : check_function_restrict (const_tree fndecl, const_tree fntype,
    5939                 :             :                          int nargs, tree *unfolded_argarray)
    5940                 :             : {
    5941                 :    52100810 :   int i;
    5942                 :    52100810 :   tree parms = TYPE_ARG_TYPES (fntype);
    5943                 :             : 
    5944                 :             :   /* Call fold_for_warn on all of the arguments.  */
    5945                 :    52100810 :   auto_vec<tree> argarray (nargs);
    5946                 :   234868548 :   for (i = 0; i < nargs; i++)
    5947                 :   130666928 :     argarray.quick_push (fold_for_warn (unfolded_argarray[i]));
    5948                 :             : 
    5949                 :    52100810 :   if (fndecl
    5950                 :    51575631 :       && TREE_CODE (fndecl) == FUNCTION_DECL)
    5951                 :             :     {
    5952                 :             :       /* Avoid diagnosing calls built-ins with a zero size/bound
    5953                 :             :          here.  They are checked in more detail elsewhere.  */
    5954                 :    51575631 :       if (fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
    5955                 :     1700395 :           && nargs == 3
    5956                 :      323686 :           && TREE_CODE (argarray[2]) == INTEGER_CST
    5957                 :    51745255 :           && integer_zerop (argarray[2]))
    5958                 :             :         return false;
    5959                 :             : 
    5960                 :    51550029 :       if (DECL_ARGUMENTS (fndecl))
    5961                 :    52075208 :         parms = DECL_ARGUMENTS (fndecl);
    5962                 :             :     }
    5963                 :             : 
    5964                 :   182665330 :   for (i = 0; i < nargs; i++)
    5965                 :   130590122 :     TREE_VISITED (argarray[i]) = 0;
    5966                 :             : 
    5967                 :             :   bool warned = false;
    5968                 :             : 
    5969                 :   181788020 :   for (i = 0; i < nargs && parms && parms != void_list_node; i++)
    5970                 :             :     {
    5971                 :   129712812 :       tree type;
    5972                 :   129712812 :       if (TREE_CODE (parms) == PARM_DECL)
    5973                 :             :         {
    5974                 :    15457159 :           type = TREE_TYPE (parms);
    5975                 :    15457159 :           parms = DECL_CHAIN (parms);
    5976                 :             :         }
    5977                 :             :       else
    5978                 :             :         {
    5979                 :   114255653 :           type = TREE_VALUE (parms);
    5980                 :   114255653 :           parms = TREE_CHAIN (parms);
    5981                 :             :         }
    5982                 :   129712812 :       if (POINTER_TYPE_P (type)
    5983                 :     7836306 :           && TYPE_RESTRICT (type)
    5984                 :   129960189 :           && !TYPE_READONLY (TREE_TYPE (type)))
    5985                 :      248016 :         warned |= warn_for_restrict (i, argarray.address (), nargs);
    5986                 :             :     }
    5987                 :             : 
    5988                 :   182665330 :   for (i = 0; i < nargs; i++)
    5989                 :   130590122 :     TREE_VISITED (argarray[i]) = 0;
    5990                 :             : 
    5991                 :             :   return warned;
    5992                 :    52100810 : }
    5993                 :             : 
    5994                 :             : /* Helper for check_function_nonnull; given a list of operands which
    5995                 :             :    must be non-null in ARGS, determine if operand PARAM_NUM should be
    5996                 :             :    checked.  */
    5997                 :             : 
    5998                 :             : static bool
    5999                 :      269007 : nonnull_check_p (tree args, unsigned HOST_WIDE_INT param_num)
    6000                 :             : {
    6001                 :      269007 :   unsigned HOST_WIDE_INT arg_num = 0;
    6002                 :             : 
    6003                 :      714813 :   for (; args; args = TREE_CHAIN (args))
    6004                 :             :     {
    6005                 :      568557 :       bool found = get_attribute_operand (TREE_VALUE (args), &arg_num);
    6006                 :             : 
    6007                 :      568557 :       gcc_assert (found);
    6008                 :             : 
    6009                 :      568557 :       if (arg_num == param_num)
    6010                 :             :         return true;
    6011                 :             :     }
    6012                 :             :   return false;
    6013                 :             : }
    6014                 :             : 
    6015                 :             : /* Check that the function argument PARAM (which is operand number
    6016                 :             :    PARAM_NUM) is non-null.  This is called by check_function_nonnull
    6017                 :             :    via check_function_arguments_recurse.  */
    6018                 :             : 
    6019                 :             : static void
    6020                 :      647253 : check_nonnull_arg (void *ctx, tree param, unsigned HOST_WIDE_INT param_num)
    6021                 :             : {
    6022                 :      647253 :   struct nonnull_arg_ctx *pctx = (struct nonnull_arg_ctx *) ctx;
    6023                 :             : 
    6024                 :             :   /* Just skip checking the argument if it's not a pointer.  This can
    6025                 :             :      happen if the "nonnull" attribute was given without an operand
    6026                 :             :      list (which means to check every pointer argument).  */
    6027                 :             : 
    6028                 :      647253 :   tree paramtype = TREE_TYPE (param);
    6029                 :      647253 :   if (TREE_CODE (paramtype) != POINTER_TYPE
    6030                 :       57914 :       && TREE_CODE (paramtype) != NULLPTR_TYPE)
    6031                 :      646504 :     return;
    6032                 :             : 
    6033                 :             :   /* Diagnose the simple cases of null arguments.  */
    6034                 :      589345 :   if (!integer_zerop (fold_for_warn (param)))
    6035                 :             :     return;
    6036                 :             : 
    6037                 :         749 :   auto_diagnostic_group adg;
    6038                 :             : 
    6039                 :         749 :   const location_t loc = EXPR_LOC_OR_LOC (param, pctx->loc);
    6040                 :             : 
    6041                 :         749 :   if (TREE_CODE (pctx->fntype) == METHOD_TYPE)
    6042                 :         109 :     --param_num;
    6043                 :             : 
    6044                 :         749 :   bool warned;
    6045                 :         749 :   if (param_num == 0)
    6046                 :             :     {
    6047                 :          30 :       warned = warning_at (loc, OPT_Wnonnull,
    6048                 :             :                            "%qs pointer is null", "this");
    6049                 :          30 :       if (warned && pctx->fndecl)
    6050                 :          27 :         inform (DECL_SOURCE_LOCATION (pctx->fndecl),
    6051                 :             :                 "in a call to non-static member function %qD",
    6052                 :             :                 pctx->fndecl);
    6053                 :             :     }
    6054                 :             :   else
    6055                 :             :     {
    6056                 :         719 :       if (pctx->other1 && pctx->other2 != pctx->other1)
    6057                 :          14 :         warned = warning_at (loc, OPT_Wnonnull,
    6058                 :             :                              "argument %u null where non-null expected "
    6059                 :             :                              "because arguments %u and %u are nonzero",
    6060                 :             :                              (unsigned) param_num,
    6061                 :             :                              TREE_CODE (pctx->fntype) == METHOD_TYPE
    6062                 :           0 :                              ? (unsigned) pctx->other1 - 1
    6063                 :             :                              : (unsigned) pctx->other1,
    6064                 :             :                              TREE_CODE (pctx->fntype) == METHOD_TYPE
    6065                 :           0 :                              ? (unsigned) pctx->other2 - 1
    6066                 :             :                              : (unsigned) pctx->other2);
    6067                 :         705 :       else if (pctx->other1)
    6068                 :          50 :         warned = warning_at (loc, OPT_Wnonnull,
    6069                 :             :                              "argument %u null where non-null expected "
    6070                 :             :                              "because argument %u is nonzero",
    6071                 :             :                              (unsigned) param_num,
    6072                 :             :                              TREE_CODE (pctx->fntype) == METHOD_TYPE
    6073                 :           0 :                              ? (unsigned) pctx->other1 - 1
    6074                 :             :                              : (unsigned) pctx->other1);
    6075                 :             :       else
    6076                 :         655 :         warned = warning_at (loc, OPT_Wnonnull,
    6077                 :             :                              "argument %u null where non-null expected",
    6078                 :             :                              (unsigned) param_num);
    6079                 :         719 :       if (warned && pctx->fndecl)
    6080                 :         688 :         inform (DECL_SOURCE_LOCATION (pctx->fndecl),
    6081                 :             :                 "in a call to function %qD declared %qs",
    6082                 :             :                 pctx->fndecl,
    6083                 :         688 :                 pctx->other1 ? "nonnull_if_nonzero" : "nonnull");
    6084                 :             :     }
    6085                 :             : 
    6086                 :         746 :   if (warned)
    6087                 :         746 :     pctx->warned_p = true;
    6088                 :         749 : }
    6089                 :             : 
    6090                 :             : /* Helper for attribute handling; fetch the operand number from
    6091                 :             :    the attribute argument list.  */
    6092                 :             : 
    6093                 :             : bool
    6094                 :      568557 : get_attribute_operand (tree arg_num_expr, unsigned HOST_WIDE_INT *valp)
    6095                 :             : {
    6096                 :             :   /* Verify the arg number is a small constant.  */
    6097                 :      568557 :   if (tree_fits_uhwi_p (arg_num_expr))
    6098                 :             :     {
    6099                 :      568557 :       *valp = tree_to_uhwi (arg_num_expr);
    6100                 :      568557 :       return true;
    6101                 :             :     }
    6102                 :             :   else
    6103                 :             :     return false;
    6104                 :             : }
    6105                 :             : 
    6106                 :             : /* Arguments being collected for optimization.  */
    6107                 :             : typedef const char *const_char_p;               /* For DEF_VEC_P.  */
    6108                 :             : static GTY(()) vec<const_char_p, va_gc> *optimize_args;
    6109                 :             : 
    6110                 :             : 
    6111                 :             : /* Inner function to convert a TREE_LIST to argv string to parse the optimize
    6112                 :             :    options in ARGS.  ATTR_P is true if this is for attribute(optimize), and
    6113                 :             :    false for #pragma GCC optimize.  */
    6114                 :             : 
    6115                 :             : bool
    6116                 :      327636 : parse_optimize_options (tree args, bool attr_p)
    6117                 :             : {
    6118                 :      327636 :   bool ret = true;
    6119                 :      327636 :   unsigned opt_argc;
    6120                 :      327636 :   unsigned i;
    6121                 :      327636 :   const char **opt_argv;
    6122                 :      327636 :   struct cl_decoded_option *decoded_options;
    6123                 :      327636 :   unsigned int decoded_options_count;
    6124                 :      327636 :   tree ap;
    6125                 :             : 
    6126                 :             :   /* Build up argv vector.  Just in case the string is stored away, use garbage
    6127                 :             :      collected strings.  */
    6128                 :      327636 :   vec_safe_truncate (optimize_args, 0);
    6129                 :      327636 :   vec_safe_push (optimize_args, (const char *) NULL);
    6130                 :             : 
    6131                 :      673971 :   for (ap = args; ap != NULL_TREE; ap = TREE_CHAIN (ap))
    6132                 :             :     {
    6133                 :      346335 :       tree value = TREE_VALUE (ap);
    6134                 :             : 
    6135                 :      346335 :       if (TREE_CODE (value) == INTEGER_CST)
    6136                 :             :         {
    6137                 :         303 :           char buffer[HOST_BITS_PER_LONG / 3 + 4];
    6138                 :         303 :           sprintf (buffer, "-O%ld", (long) TREE_INT_CST_LOW (value));
    6139                 :         303 :           vec_safe_push (optimize_args, ggc_strdup (buffer));
    6140                 :             :         }
    6141                 :             : 
    6142                 :      346032 :       else if (TREE_CODE (value) == STRING_CST)
    6143                 :             :         {
    6144                 :             :           /* Split string into multiple substrings.  */
    6145                 :      346028 :           size_t len = TREE_STRING_LENGTH (value);
    6146                 :      346028 :           char *p = ASTRDUP (TREE_STRING_POINTER (value));
    6147                 :      346028 :           char *end = p + len;
    6148                 :      346028 :           char *comma;
    6149                 :      346028 :           char *next_p = p;
    6150                 :             : 
    6151                 :      692105 :           while (next_p != NULL)
    6152                 :             :             {
    6153                 :      346077 :               size_t len2;
    6154                 :      346077 :               char *q, *r;
    6155                 :             : 
    6156                 :      346077 :               p = next_p;
    6157                 :      346077 :               comma = strchr (p, ',');
    6158                 :      346077 :               if (comma)
    6159                 :             :                 {
    6160                 :          49 :                   len2 = comma - p;
    6161                 :          49 :                   *comma = '\0';
    6162                 :          49 :                   next_p = comma+1;
    6163                 :             :                 }
    6164                 :             :               else
    6165                 :             :                 {
    6166                 :      346028 :                   len2 = end - p;
    6167                 :      346028 :                   next_p = NULL;
    6168                 :             :                 }
    6169                 :             : 
    6170                 :             :               /* If the user supplied -Oxxx or -fxxx, only allow -Oxxx or -fxxx
    6171                 :             :                  options.  */
    6172                 :      346077 :               if (*p == '-' && p[1] != 'O' && p[1] != 'f')
    6173                 :             :                 {
    6174                 :           0 :                   ret = false;
    6175                 :           0 :                   if (attr_p)
    6176                 :             :                     {
    6177                 :           0 :                       auto_urlify_attributes sentinel;
    6178                 :           0 :                       warning (OPT_Wattributes,
    6179                 :             :                                "bad option %qs to attribute %<optimize%>", p);
    6180                 :           0 :                     }
    6181                 :             :                   else
    6182                 :           0 :                     warning (OPT_Wpragmas,
    6183                 :             :                              "bad option %qs to pragma %<optimize%>", p);
    6184                 :           0 :                   continue;
    6185                 :           0 :                 }
    6186                 :             : 
    6187                 :             :               /* Can't use GC memory here, see PR88007.  */
    6188                 :      346077 :               r = q = XOBNEWVEC (&opts_obstack, char, len2 + 3);
    6189                 :             : 
    6190                 :      346077 :               if (*p != '-')
    6191                 :             :                 {
    6192                 :       42751 :                   *r++ = '-';
    6193                 :             : 
    6194                 :             :                   /* Assume that Ox is -Ox, a numeric value is -Ox, a s by
    6195                 :             :                      itself is -Os, and any other switch begins with a -f.  */
    6196                 :       42751 :                   if ((*p >= '0' && *p <= '9')
    6197                 :       42594 :                       || (p[0] == 's' && p[1] == '\0'))
    6198                 :         157 :                     *r++ = 'O';
    6199                 :       42594 :                   else if (*p != 'O')
    6200                 :       23301 :                     *r++ = 'f';
    6201                 :             :                 }
    6202                 :             : 
    6203                 :      346077 :               memcpy (r, p, len2);
    6204                 :      346077 :               r[len2] = '\0';
    6205                 :      346077 :               vec_safe_push (optimize_args, (const char *) q);
    6206                 :             :             }
    6207                 :             : 
    6208                 :             :         }
    6209                 :             :     }
    6210                 :             : 
    6211                 :      327636 :   opt_argc = optimize_args->length ();
    6212                 :      327636 :   opt_argv = (const char **) alloca (sizeof (char *) * (opt_argc + 1));
    6213                 :             : 
    6214                 :      674016 :   for (i = 1; i < opt_argc; i++)
    6215                 :      346380 :     opt_argv[i] = (*optimize_args)[i];
    6216                 :             : 
    6217                 :             :   /* Now parse the options.  */
    6218                 :      327636 :   decode_cmdline_options_to_array_default_mask (opt_argc, opt_argv,
    6219                 :             :                                                 &decoded_options,
    6220                 :             :                                                 &decoded_options_count);
    6221                 :             :   /* Drop non-Optimization options.  */
    6222                 :      327636 :   unsigned j = 1;
    6223                 :      674016 :   for (i = 1; i < decoded_options_count; ++i)
    6224                 :             :     {
    6225                 :      346380 :       if (! (cl_options[decoded_options[i].opt_index].flags & CL_OPTIMIZATION))
    6226                 :             :         {
    6227                 :           3 :           ret = false;
    6228                 :           3 :           if (attr_p)
    6229                 :             :             {
    6230                 :           2 :               auto_urlify_attributes sentinel;
    6231                 :           2 :               warning (OPT_Wattributes,
    6232                 :             :                        "bad option %qs to attribute %<optimize%>",
    6233                 :           2 :                        decoded_options[i].orig_option_with_args_text);
    6234                 :           2 :             }
    6235                 :             :           else
    6236                 :           1 :             warning (OPT_Wpragmas,
    6237                 :             :                      "bad option %qs to pragma %<optimize%>",
    6238                 :             :                      decoded_options[i].orig_option_with_args_text);
    6239                 :           3 :           continue;
    6240                 :           3 :         }
    6241                 :      346377 :       if (i != j)
    6242                 :           0 :         decoded_options[j] = decoded_options[i];
    6243                 :      346377 :       j++;
    6244                 :             :     }
    6245                 :      327636 :   decoded_options_count = j;
    6246                 :             : 
    6247                 :             :   /* Merge the decoded options with save_decoded_options.  */
    6248                 :      327636 :   unsigned save_opt_count = save_opt_decoded_options->length ();
    6249                 :      327636 :   unsigned merged_decoded_options_count
    6250                 :             :     = save_opt_count + decoded_options_count;
    6251                 :      327636 :   cl_decoded_option *merged_decoded_options
    6252                 :      327636 :     = XNEWVEC (cl_decoded_option, merged_decoded_options_count);
    6253                 :             : 
    6254                 :             :   /* Note the first decoded_options is used for the program name.  */
    6255                 :     1874643 :   for (unsigned i = 0; i < save_opt_count; ++i)
    6256                 :     1547007 :     merged_decoded_options[i + 1] = (*save_opt_decoded_options)[i];
    6257                 :      674013 :   for (unsigned i = 1; i < decoded_options_count; ++i)
    6258                 :      346377 :     merged_decoded_options[save_opt_count + i] = decoded_options[i];
    6259                 :             : 
    6260                 :             :    /* And apply them.  */
    6261                 :      327636 :   decode_options (&global_options, &global_options_set,
    6262                 :             :                   merged_decoded_options, merged_decoded_options_count,
    6263                 :             :                   input_location, global_dc, NULL);
    6264                 :      327636 :   free (decoded_options);
    6265                 :             : 
    6266                 :      327636 :   targetm.override_options_after_change();
    6267                 :             : 
    6268                 :      327636 :   optimize_args->truncate (0);
    6269                 :      327636 :   return ret;
    6270                 :             : }
    6271                 :             : 
    6272                 :             : /* Check whether ATTR is a valid attribute fallthrough.  */
    6273                 :             : 
    6274                 :             : bool
    6275                 :   264196329 : attribute_fallthrough_p (tree attr)
    6276                 :             : {
    6277                 :   264196329 :   if (attr == error_mark_node)
    6278                 :             :    return false;
    6279                 :   264196311 :   tree t = lookup_attribute ("", "fallthrough", attr);
    6280                 :   264196311 :   if (t == NULL_TREE)
    6281                 :             :     return false;
    6282                 :       17772 :   auto_urlify_attributes sentinel;
    6283                 :             :   /* It is no longer true that "this attribute shall appear at most once in
    6284                 :             :      each attribute-list", but we still give a warning.  */
    6285                 :       17772 :   if (lookup_attribute ("", "fallthrough", TREE_CHAIN (t)))
    6286                 :           9 :     warning (OPT_Wattributes, "attribute %<fallthrough%> specified multiple "
    6287                 :             :              "times");
    6288                 :             :   /* No attribute-argument-clause shall be present.  */
    6289                 :       17763 :   else if (TREE_VALUE (t) != NULL_TREE)
    6290                 :           4 :     warning (OPT_Wattributes, "%<fallthrough%> attribute specified with "
    6291                 :             :              "a parameter");
    6292                 :             :   /* Warn if other attributes are found.  */
    6293                 :       35570 :   for (t = attr; t != NULL_TREE; t = TREE_CHAIN (t))
    6294                 :             :     {
    6295                 :       17798 :       tree name = get_attribute_name (t);
    6296                 :       17798 :       if (!is_attribute_p ("fallthrough", name)
    6297                 :       17798 :           || !is_attribute_namespace_p ("", t))
    6298                 :             :         {
    6299                 :          17 :           if (!c_dialect_cxx () && get_attribute_namespace (t) == NULL_TREE)
    6300                 :             :             /* The specifications of standard attributes in C mean
    6301                 :             :                this is a constraint violation.  */
    6302                 :           3 :             pedwarn (input_location, OPT_Wattributes, "%qE attribute ignored",
    6303                 :             :                      get_attribute_name (t));
    6304                 :             :           else
    6305                 :          14 :             warning (OPT_Wattributes, "%qE attribute ignored", name);
    6306                 :             :         }
    6307                 :             :     }
    6308                 :       17772 :   return true;
    6309                 :       17772 : }
    6310                 :             : 
    6311                 :             : 
    6312                 :             : /* Check for valid arguments being passed to a function with FNTYPE.
    6313                 :             :    There are NARGS arguments in the array ARGARRAY.  LOC should be used
    6314                 :             :    for diagnostics.  Return true if either -Wnonnull or -Wrestrict has
    6315                 :             :    been issued.
    6316                 :             : 
    6317                 :             :    The arguments in ARGARRAY may not have been folded yet (e.g. for C++,
    6318                 :             :    to preserve location wrappers); checks that require folded arguments
    6319                 :             :    should call fold_for_warn on them.
    6320                 :             : 
    6321                 :             :    Use the frontend-supplied COMP_TYPES when determining if
    6322                 :             :    one type is a subclass of another.  */
    6323                 :             : 
    6324                 :             : bool
    6325                 :    52551088 : check_function_arguments (location_t loc, const_tree fndecl, const_tree fntype,
    6326                 :             :                           int nargs, tree *argarray, vec<location_t> *arglocs,
    6327                 :             :                           bool (*comp_types) (tree, tree))
    6328                 :             : {
    6329                 :    52551088 :   bool warned_p = false;
    6330                 :             : 
    6331                 :    52551088 :   if (c_inhibit_evaluation_warnings)
    6332                 :             :     return warned_p;
    6333                 :             : 
    6334                 :             :   /* Check for null being passed in a pointer argument that must be
    6335                 :             :      non-null.  In C++, this includes the this pointer.  We also need
    6336                 :             :      to do this if format checking is enabled.  */
    6337                 :    52105537 :   if (warn_nonnull)
    6338                 :             :     {
    6339                 :     6369618 :       nonnull_arg_ctx ctx = { loc, fndecl, fntype, 0, 0, false };
    6340                 :     6369618 :       warned_p = check_function_nonnull (ctx, nargs, argarray);
    6341                 :             :     }
    6342                 :             : 
    6343                 :             :   /* Check for errors in format strings.  */
    6344                 :             : 
    6345                 :    52105537 :   if (warn_format || warn_suggest_attribute_format)
    6346                 :     6432218 :     check_function_format (fndecl ? fndecl : fntype, TYPE_ATTRIBUTES (fntype), nargs,
    6347                 :             :                            argarray, arglocs, comp_types);
    6348                 :             : 
    6349                 :    52105537 :   if (warn_format)
    6350                 :     6355355 :     check_function_sentinel (fntype, nargs, argarray);
    6351                 :             : 
    6352                 :    52105537 :   if (fndecl && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
    6353                 :             :     {
    6354                 :     1705122 :       switch (DECL_FUNCTION_CODE (fndecl))
    6355                 :             :         {
    6356                 :             :         case BUILT_IN_SPRINTF:
    6357                 :             :         case BUILT_IN_SPRINTF_CHK:
    6358                 :             :         case BUILT_IN_SNPRINTF:
    6359                 :             :         case BUILT_IN_SNPRINTF_CHK:
    6360                 :             :           /* Let the sprintf pass handle these.  */
    6361                 :             :           return warned_p;
    6362                 :             : 
    6363                 :             :         default:
    6364                 :             :           break;
    6365                 :             :         }
    6366                 :             :     }
    6367                 :             : 
    6368                 :             :   /* check_function_restrict sets the DECL_READ_P for arguments
    6369                 :             :      so it must be called unconditionally.  */
    6370                 :    52100810 :   warned_p |= check_function_restrict (fndecl, fntype, nargs, argarray);
    6371                 :             : 
    6372                 :    52100810 :   return warned_p;
    6373                 :             : }
    6374                 :             : 
    6375                 :             : /* Generic argument checking recursion routine.  PARAM is the argument to
    6376                 :             :    be checked.  PARAM_NUM is the number of the argument.  CALLBACK is invoked
    6377                 :             :    once the argument is resolved.  CTX is context for the callback.
    6378                 :             :    OPT is the warning for which this is done.  */
    6379                 :             : void
    6380                 :      702917 : check_function_arguments_recurse (void (*callback)
    6381                 :             :                                   (void *, tree, unsigned HOST_WIDE_INT),
    6382                 :             :                                   void *ctx, tree param,
    6383                 :             :                                   unsigned HOST_WIDE_INT param_num,
    6384                 :             :                                   opt_code opt)
    6385                 :             : {
    6386                 :     1103584 :   if (opt != OPT_Wformat_ && warning_suppressed_p (param))
    6387                 :             :     return;
    6388                 :             : 
    6389                 :      749317 :   if (CONVERT_EXPR_P (param)
    6390                 :     1216368 :       && (TYPE_PRECISION (TREE_TYPE (param))
    6391                 :      467051 :           == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (param, 0)))))
    6392                 :             :     {
    6393                 :             :       /* Strip coercion.  */
    6394                 :      799940 :       check_function_arguments_recurse (callback, ctx,
    6395                 :      399970 :                                         TREE_OPERAND (param, 0), param_num,
    6396                 :             :                                         opt);
    6397                 :      399970 :       return;
    6398                 :             :     }
    6399                 :             : 
    6400                 :      701933 :   if (TREE_CODE (param) == CALL_EXPR && CALL_EXPR_FN (param))
    6401                 :             :     {
    6402                 :        7905 :       tree type = TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (param)));
    6403                 :        7905 :       tree attrs;
    6404                 :        7905 :       bool found_format_arg = false;
    6405                 :             : 
    6406                 :             :       /* See if this is a call to a known internationalization function
    6407                 :             :          that modifies a format arg.  Such a function may have multiple
    6408                 :             :          format_arg attributes (for example, ngettext).  */
    6409                 :             : 
    6410                 :        7905 :       for (attrs = TYPE_ATTRIBUTES (type);
    6411                 :        8287 :            attrs;
    6412                 :         382 :            attrs = TREE_CHAIN (attrs))
    6413                 :         382 :         if (is_attribute_p ("format_arg", get_attribute_name (attrs)))
    6414                 :             :           {
    6415                 :         226 :             tree inner_arg;
    6416                 :         226 :             tree format_num_expr;
    6417                 :         226 :             int format_num;
    6418                 :         226 :             int i;
    6419                 :         226 :             call_expr_arg_iterator iter;
    6420                 :             : 
    6421                 :             :             /* Extract the argument number, which was previously checked
    6422                 :             :                to be valid.  */
    6423                 :         226 :             format_num_expr = TREE_VALUE (TREE_VALUE (attrs));
    6424                 :             : 
    6425                 :         226 :             format_num = tree_to_uhwi (format_num_expr);
    6426                 :             : 
    6427                 :         226 :             for (inner_arg = first_call_expr_arg (param, &iter), i = 1;
    6428                 :         320 :                  inner_arg != NULL_TREE;
    6429                 :          94 :                  inner_arg = next_call_expr_arg (&iter), i++)
    6430                 :         320 :               if (i == format_num)
    6431                 :             :                 {
    6432                 :         226 :                   check_function_arguments_recurse (callback, ctx,
    6433                 :             :                                                     inner_arg, param_num,
    6434                 :             :                                                     opt);
    6435                 :         226 :                   found_format_arg = true;
    6436                 :         226 :                   break;
    6437                 :             :                 }
    6438                 :             :           }
    6439                 :             : 
    6440                 :             :       /* If we found a format_arg attribute and did a recursive check,
    6441                 :             :          we are done with checking this argument.  Otherwise, we continue
    6442                 :             :          and this will be considered a non-literal.  */
    6443                 :        7905 :       if (found_format_arg)
    6444                 :             :         return;
    6445                 :             :     }
    6446                 :             : 
    6447                 :      701755 :   if (TREE_CODE (param) == COND_EXPR)
    6448                 :             :     {
    6449                 :             :       /* Simplify to avoid warning for an impossible case.  */
    6450                 :         715 :       param = fold_for_warn (param);
    6451                 :         715 :       if (TREE_CODE (param) == COND_EXPR)
    6452                 :             :         {
    6453                 :             :           /* Check both halves of the conditional expression.  */
    6454                 :         697 :           check_function_arguments_recurse (callback, ctx,
    6455                 :         697 :                                             TREE_OPERAND (param, 1),
    6456                 :             :                                             param_num, opt);
    6457                 :        1394 :           check_function_arguments_recurse (callback, ctx,
    6458                 :         697 :                                             TREE_OPERAND (param, 2),
    6459                 :             :                                             param_num, opt);
    6460                 :         697 :           return;
    6461                 :             :         }
    6462                 :             :     }
    6463                 :             : 
    6464                 :      701058 :   (*callback) (ctx, param, param_num);
    6465                 :             : }
    6466                 :             : 
    6467                 :             : /* Checks for a builtin function FNDECL that the number of arguments
    6468                 :             :    NARGS against the required number REQUIRED and issues an error if
    6469                 :             :    there is a mismatch.  Returns true if the number of arguments is
    6470                 :             :    correct, otherwise false.  LOC is the location of FNDECL.  */
    6471                 :             : 
    6472                 :             : static bool
    6473                 :      762360 : builtin_function_validate_nargs (location_t loc, tree fndecl, int nargs,
    6474                 :             :                                  int required, bool complain)
    6475                 :             : {
    6476                 :      762360 :   if (nargs < required)
    6477                 :             :     {
    6478                 :         182 :       if (complain)
    6479                 :         143 :         error_at (loc, "too few arguments to function %qE", fndecl);
    6480                 :         182 :       return false;
    6481                 :             :     }
    6482                 :      762178 :   else if (nargs > required)
    6483                 :             :     {
    6484                 :         138 :       if (complain)
    6485                 :          93 :         error_at (loc, "too many arguments to function %qE", fndecl);
    6486                 :         138 :       return false;
    6487                 :             :     }
    6488                 :             :   return true;
    6489                 :             : }
    6490                 :             : 
    6491                 :             : /* Helper macro for check_builtin_function_arguments.  */
    6492                 :             : #define ARG_LOCATION(N)                                 \
    6493                 :             :   (arg_loc.is_empty ()                                  \
    6494                 :             :    ? EXPR_LOC_OR_LOC (args[(N)], input_location)        \
    6495                 :             :    : expansion_point_location (arg_loc[(N)]))
    6496                 :             : 
    6497                 :             : /* Verifies the NARGS arguments ARGS to the builtin function FNDECL.
    6498                 :             :    Returns false if there was an error, otherwise true.  LOC is the
    6499                 :             :    location of the function; ARG_LOC is a vector of locations of the
    6500                 :             :    arguments.  If FNDECL is the result of resolving an overloaded
    6501                 :             :    target built-in, ORIG_FNDECL is the original function decl,
    6502                 :             :    otherwise it is null.  */
    6503                 :             : 
    6504                 :             : bool
    6505                 :    39335534 : check_builtin_function_arguments (location_t loc, vec<location_t> arg_loc,
    6506                 :             :                                   tree fndecl, tree orig_fndecl, int nargs,
    6507                 :             :                                   tree *args, bool complain)
    6508                 :             : {
    6509                 :    39335534 :   if (!fndecl_built_in_p (fndecl))
    6510                 :             :     return true;
    6511                 :             : 
    6512                 :    39335534 :   if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD)
    6513                 :    32072450 :     return (!targetm.check_builtin_call
    6514                 :    32072450 :             || targetm.check_builtin_call (loc, arg_loc, fndecl, orig_fndecl,
    6515                 :             :                                            nargs, args, complain));
    6516                 :             : 
    6517                 :     7263084 :   if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_FRONTEND)
    6518                 :             :     return true;
    6519                 :             : 
    6520                 :     7234074 :   gcc_assert (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL);
    6521                 :     7234074 :   switch (DECL_FUNCTION_CODE (fndecl))
    6522                 :             :     {
    6523                 :           2 :     case BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX:
    6524                 :           2 :       if (!tree_fits_uhwi_p (args[2]))
    6525                 :             :         {
    6526                 :           0 :           if (complain)
    6527                 :           0 :             error_at (
    6528                 :           0 :               ARG_LOCATION (2),
    6529                 :             :               "third argument to function %qE must be a constant integer",
    6530                 :             :               fndecl);
    6531                 :           0 :           return false;
    6532                 :             :         }
    6533                 :             :       /* fall through */
    6534                 :             : 
    6535                 :         264 :     case BUILT_IN_ALLOCA_WITH_ALIGN:
    6536                 :         264 :       {
    6537                 :             :         /* Get the requested alignment (in bits) if it's a constant
    6538                 :             :            integer expression.  */
    6539                 :         264 :         unsigned HOST_WIDE_INT align
    6540                 :         264 :           = tree_fits_uhwi_p (args[1]) ? tree_to_uhwi (args[1]) : 0;
    6541                 :             : 
    6542                 :             :         /* Determine if the requested alignment is a power of 2.  */
    6543                 :         264 :         if ((align & (align - 1)))
    6544                 :             :           align = 0;
    6545                 :             : 
    6546                 :             :         /* The maximum alignment in bits corresponding to the same
    6547                 :             :            maximum in bytes enforced in check_user_alignment().  */
    6548                 :         315 :         unsigned maxalign = (UINT_MAX >> 1) + 1;
    6549                 :             : 
    6550                 :             :         /* Reject invalid alignments.  */
    6551                 :         181 :         if (align < BITS_PER_UNIT || maxalign < align)
    6552                 :             :           {
    6553                 :         134 :             if (complain)
    6554                 :         169 :               error_at (ARG_LOCATION (1),
    6555                 :             :                         "second argument to function %qE must be a constant "
    6556                 :             :                         "integer power of 2 between %qi and %qu bits",
    6557                 :             :                         fndecl, BITS_PER_UNIT, maxalign);
    6558                 :         134 :             return false;
    6559                 :             :           }
    6560                 :             :         return true;
    6561                 :             :       }
    6562                 :             : 
    6563                 :       93794 :     case BUILT_IN_CONSTANT_P:
    6564                 :       93794 :       return builtin_function_validate_nargs (loc, fndecl, nargs, 1, complain);
    6565                 :             : 
    6566                 :      270988 :     case BUILT_IN_ISFINITE:
    6567                 :      270988 :     case BUILT_IN_ISINF:
    6568                 :      270988 :     case BUILT_IN_ISINF_SIGN:
    6569                 :      270988 :     case BUILT_IN_ISNAN:
    6570                 :      270988 :     case BUILT_IN_ISNORMAL:
    6571                 :      270988 :     case BUILT_IN_ISSIGNALING:
    6572                 :      270988 :     case BUILT_IN_SIGNBIT:
    6573                 :      270988 :       if (builtin_function_validate_nargs (loc, fndecl, nargs, 1, complain))
    6574                 :             :         {
    6575                 :      270953 :           if (TREE_CODE (TREE_TYPE (args[0])) != REAL_TYPE)
    6576                 :             :             {
    6577                 :          37 :               if (complain)
    6578                 :          28 :                 error_at (ARG_LOCATION (0),
    6579                 :             :                           "non-floating-point argument in "
    6580                 :             :                           "call to function %qE",
    6581                 :             :                           fndecl);
    6582                 :          37 :               return false;
    6583                 :             :             }
    6584                 :             :           return true;
    6585                 :             :         }
    6586                 :             :       return false;
    6587                 :             : 
    6588                 :      226076 :     case BUILT_IN_ISGREATER:
    6589                 :      226076 :     case BUILT_IN_ISGREATEREQUAL:
    6590                 :      226076 :     case BUILT_IN_ISLESS:
    6591                 :      226076 :     case BUILT_IN_ISLESSEQUAL:
    6592                 :      226076 :     case BUILT_IN_ISLESSGREATER:
    6593                 :      226076 :     case BUILT_IN_ISUNORDERED:
    6594                 :      226076 :     case BUILT_IN_ISEQSIG:
    6595                 :      226076 :       if (builtin_function_validate_nargs (loc, fndecl, nargs, 2, complain))
    6596                 :             :         {
    6597                 :      226041 :           enum tree_code code0, code1;
    6598                 :      226041 :           code0 = TREE_CODE (TREE_TYPE (args[0]));
    6599                 :      226041 :           code1 = TREE_CODE (TREE_TYPE (args[1]));
    6600                 :      226041 :           if (!((code0 == REAL_TYPE && code1 == REAL_TYPE)
    6601                 :         147 :                 || (code0 == REAL_TYPE
    6602                 :          56 :                     && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
    6603                 :          92 :                 || ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
    6604                 :          81 :                     && code1 == REAL_TYPE)))
    6605                 :             :             {
    6606                 :          39 :               if (complain)
    6607                 :          18 :                 error_at (loc,
    6608                 :             :                           "non-floating-point arguments in call to "
    6609                 :             :                           "function %qE",
    6610                 :             :                           fndecl);
    6611                 :          39 :               return false;
    6612                 :             :             }
    6613                 :             :           return true;
    6614                 :             :         }
    6615                 :             :       return false;
    6616                 :             : 
    6617                 :       38375 :     case BUILT_IN_FPCLASSIFY:
    6618                 :       38375 :       if (builtin_function_validate_nargs (loc, fndecl, nargs, 6, complain))
    6619                 :             :         {
    6620                 :      230178 :           for (unsigned int i = 0; i < 5; i++)
    6621                 :      191819 :             if (TREE_CODE (args[i]) != INTEGER_CST)
    6622                 :             :               {
    6623                 :          12 :                 if (complain)
    6624                 :          12 :                   error_at (ARG_LOCATION (i),
    6625                 :             :                             "non-const integer argument %u in "
    6626                 :             :                             "call to function %qE",
    6627                 :             :                             i + 1, fndecl);
    6628                 :          12 :                 return false;
    6629                 :             :               }
    6630                 :             : 
    6631                 :       38359 :           if (TREE_CODE (TREE_TYPE (args[5])) != REAL_TYPE)
    6632                 :             :             {
    6633                 :           2 :               if (complain)
    6634                 :           4 :                 error_at (ARG_LOCATION (5),
    6635                 :             :                           "non-floating-point argument in "
    6636                 :             :                           "call to function %qE",
    6637                 :             :                           fndecl);
    6638                 :           2 :               return false;
    6639                 :             :             }
    6640                 :             :           return true;
    6641                 :             :         }
    6642                 :             :       return false;
    6643                 :             : 
    6644                 :         414 :     case BUILT_IN_ASSUME_ALIGNED:
    6645                 :         808 :       if (builtin_function_validate_nargs (loc, fndecl, nargs, 2 + (nargs > 2),
    6646                 :             :                                            complain))
    6647                 :             :         {
    6648                 :         412 :           if (nargs >= 3
    6649                 :          18 :               && TREE_CODE (TREE_TYPE (args[2])) != INTEGER_TYPE
    6650                 :         419 :               && TREE_CODE (TREE_TYPE (args[2])) != BITINT_TYPE)
    6651                 :             :             {
    6652                 :           6 :               if (complain)
    6653                 :           6 :                 error_at (ARG_LOCATION (2),
    6654                 :             :                           "non-integer argument 3 in call to "
    6655                 :             :                           "function %qE",
    6656                 :             :                           fndecl);
    6657                 :           6 :               return false;
    6658                 :             :             }
    6659                 :             :           return true;
    6660                 :             :         }
    6661                 :             :       return false;
    6662                 :             : 
    6663                 :       73761 :     case BUILT_IN_ADD_OVERFLOW:
    6664                 :       73761 :     case BUILT_IN_SUB_OVERFLOW:
    6665                 :       73761 :     case BUILT_IN_MUL_OVERFLOW:
    6666                 :       73761 :       if (builtin_function_validate_nargs (loc, fndecl, nargs, 3, complain))
    6667                 :             :         {
    6668                 :             :           unsigned i;
    6669                 :      220827 :           for (i = 0; i < 2; i++)
    6670                 :      147244 :             if (!INTEGRAL_TYPE_P (TREE_TYPE (args[i])))
    6671                 :             :               {
    6672                 :          55 :                 if (complain)
    6673                 :          77 :                   error_at (ARG_LOCATION (i),
    6674                 :             :                             "argument %u in call to function "
    6675                 :             :                             "%qE does not have integral type",
    6676                 :             :                             i + 1, fndecl);
    6677                 :          55 :                 return false;
    6678                 :             :               }
    6679                 :       73583 :           if (TREE_CODE (TREE_TYPE (args[2])) != POINTER_TYPE
    6680                 :       73583 :               || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (args[2]))))
    6681                 :             :             {
    6682                 :          60 :               if (complain)
    6683                 :          75 :                 error_at (ARG_LOCATION (2),
    6684                 :             :                           "argument 3 in call to function %qE "
    6685                 :             :                           "does not have pointer to integral type",
    6686                 :             :                           fndecl);
    6687                 :          60 :               return false;
    6688                 :             :             }
    6689                 :       73523 :           else if (TREE_CODE (TREE_TYPE (TREE_TYPE (args[2]))) == ENUMERAL_TYPE)
    6690                 :             :             {
    6691                 :          16 :               if (complain)
    6692                 :          11 :                 error_at (ARG_LOCATION (2),
    6693                 :             :                           "argument 3 in call to function %qE "
    6694                 :             :                           "has pointer to enumerated type",
    6695                 :             :                           fndecl);
    6696                 :          16 :               return false;
    6697                 :             :             }
    6698                 :       73507 :           else if (TREE_CODE (TREE_TYPE (TREE_TYPE (args[2]))) == BOOLEAN_TYPE)
    6699                 :             :             {
    6700                 :          21 :               if (complain)
    6701                 :          16 :                 error_at (ARG_LOCATION (2),
    6702                 :             :                           "argument 3 in call to function %qE "
    6703                 :             :                           "has pointer to boolean type",
    6704                 :             :                           fndecl);
    6705                 :          21 :               return false;
    6706                 :             :             }
    6707                 :       73486 :           else if (TYPE_READONLY (TREE_TYPE (TREE_TYPE (args[2]))))
    6708                 :             :             {
    6709                 :          30 :               if (complain)
    6710                 :          30 :                 error_at (ARG_LOCATION (2),
    6711                 :             :                           "argument %u in call to function %qE "
    6712                 :             :                           "has pointer to %qs type (%qT)",
    6713                 :          21 :                           3, fndecl, "const", TREE_TYPE (args[2]));
    6714                 :          30 :               return false;
    6715                 :             :             }
    6716                 :       73456 :           else if (TYPE_ATOMIC (TREE_TYPE (TREE_TYPE (args[2]))))
    6717                 :             :             {
    6718                 :           6 :               if (complain)
    6719                 :          12 :                 error_at (ARG_LOCATION (2),
    6720                 :             :                           "argument %u in call to function %qE "
    6721                 :             :                           "has pointer to %qs type (%qT)",
    6722                 :           6 :                           3, fndecl, "_Atomic", TREE_TYPE (args[2]));
    6723                 :           6 :               return false;
    6724                 :             :             }
    6725                 :             :           return true;
    6726                 :             :         }
    6727                 :             :       return false;
    6728                 :             : 
    6729                 :       41854 :     case BUILT_IN_ADD_OVERFLOW_P:
    6730                 :       41854 :     case BUILT_IN_SUB_OVERFLOW_P:
    6731                 :       41854 :     case BUILT_IN_MUL_OVERFLOW_P:
    6732                 :       41854 :       if (builtin_function_validate_nargs (loc, fndecl, nargs, 3, complain))
    6733                 :             :         {
    6734                 :             :           unsigned i;
    6735                 :      167205 :           for (i = 0; i < 3; i++)
    6736                 :      125421 :             if (!INTEGRAL_TYPE_P (TREE_TYPE (args[i])))
    6737                 :             :               {
    6738                 :          37 :                 if (complain)
    6739                 :          35 :                   error_at (ARG_LOCATION (i),
    6740                 :             :                             "argument %u in call to function "
    6741                 :             :                             "%qE does not have integral type",
    6742                 :             :                             i + 1, fndecl);
    6743                 :          37 :                 return false;
    6744                 :             :               }
    6745                 :       41784 :           if (TREE_CODE (TREE_TYPE (args[2])) == ENUMERAL_TYPE)
    6746                 :             :             {
    6747                 :          13 :               if (complain)
    6748                 :           5 :                 error_at (ARG_LOCATION (2),
    6749                 :             :                           "argument %u in call to function "
    6750                 :             :                           "%qE has enumerated type",
    6751                 :             :                           3, fndecl);
    6752                 :          13 :               return false;
    6753                 :             :             }
    6754                 :       41771 :           else if (TREE_CODE (TREE_TYPE (args[2])) == BOOLEAN_TYPE)
    6755                 :             :             {
    6756                 :          13 :               if (complain)
    6757                 :           5 :                 error_at (ARG_LOCATION (2),
    6758                 :             :                           "argument %u in call to function "
    6759                 :             :                           "%qE has boolean type",
    6760                 :             :                           3, fndecl);
    6761                 :          13 :               return false;
    6762                 :             :             }
    6763                 :             :           return true;
    6764                 :             :         }
    6765                 :             :       return false;
    6766                 :             : 
    6767                 :        9938 :     case BUILT_IN_CLEAR_PADDING:
    6768                 :        9938 :       if (builtin_function_validate_nargs (loc, fndecl, nargs, 1, complain))
    6769                 :             :         {
    6770                 :        9923 :           if (!POINTER_TYPE_P (TREE_TYPE (args[0])))
    6771                 :             :             {
    6772                 :           7 :               if (complain)
    6773                 :           5 :                 error_at (ARG_LOCATION (0),
    6774                 :             :                           "argument %u in call to function "
    6775                 :             :                           "%qE does not have pointer type",
    6776                 :             :                           1, fndecl);
    6777                 :           7 :               return false;
    6778                 :             :             }
    6779                 :        9916 :           else if (!COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (args[0]))))
    6780                 :             :             {
    6781                 :          11 :               if (complain)
    6782                 :          10 :                 error_at (ARG_LOCATION (0),
    6783                 :             :                           "argument %u in call to function "
    6784                 :             :                           "%qE points to incomplete type",
    6785                 :             :                           1, fndecl);
    6786                 :          11 :               return false;
    6787                 :             :             }
    6788                 :        9905 :           else if (TYPE_READONLY (TREE_TYPE (TREE_TYPE (args[0]))))
    6789                 :             :             {
    6790                 :           7 :               if (complain)
    6791                 :           5 :                 error_at (ARG_LOCATION (0),
    6792                 :             :                           "argument %u in call to function %qE "
    6793                 :             :                           "has pointer to %qs type (%qT)",
    6794                 :           4 :                           1, fndecl, "const", TREE_TYPE (args[0]));
    6795                 :           7 :               return false;
    6796                 :             :             }
    6797                 :        9898 :           else if (TYPE_ATOMIC (TREE_TYPE (TREE_TYPE (args[0]))))
    6798                 :             :             {
    6799                 :           0 :               if (complain)
    6800                 :           0 :                 error_at (ARG_LOCATION (0),
    6801                 :             :                           "argument %u in call to function %qE "
    6802                 :             :                           "has pointer to %qs type (%qT)",
    6803                 :           0 :                           1, fndecl, "_Atomic", TREE_TYPE (args[0]));
    6804                 :           0 :               return false;
    6805                 :             :             }
    6806                 :             :           return true;
    6807                 :             :         }
    6808                 :             :       return false;
    6809                 :             : 
    6810                 :       57370 :     case BUILT_IN_CLZG:
    6811                 :       57370 :     case BUILT_IN_CTZG:
    6812                 :       57370 :     case BUILT_IN_CLRSBG:
    6813                 :       57370 :     case BUILT_IN_FFSG:
    6814                 :       57370 :     case BUILT_IN_PARITYG:
    6815                 :       57370 :     case BUILT_IN_POPCOUNTG:
    6816                 :       57370 :       if (nargs == 2
    6817                 :       57370 :           && (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CLZG
    6818                 :       16135 :               || DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CTZG))
    6819                 :             :         {
    6820                 :       50210 :           if (!INTEGRAL_TYPE_P (TREE_TYPE (args[1])))
    6821                 :             :             {
    6822                 :          18 :               if (complain)
    6823                 :          15 :                 error_at (ARG_LOCATION (1),
    6824                 :             :                           "argument %u in call to function "
    6825                 :             :                           "%qE does not have integral type",
    6826                 :             :                           2, fndecl);
    6827                 :          18 :               return false;
    6828                 :             :             }
    6829                 :       50192 :           if ((TYPE_PRECISION (TREE_TYPE (args[1]))
    6830                 :       50192 :                > TYPE_PRECISION (integer_type_node))
    6831                 :       50192 :               || (TYPE_PRECISION (TREE_TYPE (args[1]))
    6832                 :       50178 :                   == TYPE_PRECISION (integer_type_node)
    6833                 :       50172 :                   && TYPE_UNSIGNED (TREE_TYPE (args[1]))))
    6834                 :             :             {
    6835                 :          28 :               if (complain)
    6836                 :          26 :                 error_at (ARG_LOCATION (1),
    6837                 :             :                           "argument %u in call to function "
    6838                 :             :                           "%qE does not have %<int%> type",
    6839                 :             :                           2, fndecl);
    6840                 :          28 :               return false;
    6841                 :             :             }
    6842                 :             :         }
    6843                 :        7160 :       else if (!builtin_function_validate_nargs (loc, fndecl, nargs, 1,
    6844                 :             :                                                  complain))
    6845                 :             :         return false;
    6846                 :             : 
    6847                 :       57258 :       if (!INTEGRAL_TYPE_P (TREE_TYPE (args[0])))
    6848                 :             :         {
    6849                 :          82 :           if (complain)
    6850                 :          80 :             error_at (ARG_LOCATION (0),
    6851                 :             :                       "argument %u in call to function "
    6852                 :             :                       "%qE does not have integral type",
    6853                 :             :                       1, fndecl);
    6854                 :          82 :           return false;
    6855                 :             :         }
    6856                 :       57176 :       if (TREE_CODE (TREE_TYPE (args[0])) == ENUMERAL_TYPE)
    6857                 :             :         {
    6858                 :          42 :           if (complain)
    6859                 :          24 :             error_at (ARG_LOCATION (0),
    6860                 :             :                       "argument %u in call to function "
    6861                 :             :                       "%qE has enumerated type",
    6862                 :             :                       1, fndecl);
    6863                 :          42 :           return false;
    6864                 :             :         }
    6865                 :       57134 :       if (TREE_CODE (TREE_TYPE (args[0])) == BOOLEAN_TYPE)
    6866                 :             :         {
    6867                 :          50 :           if (complain)
    6868                 :          40 :             error_at (ARG_LOCATION (0),
    6869                 :             :                       "argument %u in call to function "
    6870                 :             :                       "%qE has boolean type",
    6871                 :             :                       1, fndecl);
    6872                 :          50 :           return false;
    6873                 :             :         }
    6874                 :       57084 :       if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_FFSG
    6875                 :       57084 :           || DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CLRSBG)
    6876                 :             :         {
    6877                 :         288 :           if (TYPE_UNSIGNED (TREE_TYPE (args[0])))
    6878                 :             :             {
    6879                 :          14 :               if (complain)
    6880                 :          10 :                 error_at (ARG_LOCATION (0),
    6881                 :             :                           "argument 1 in call to function "
    6882                 :             :                           "%qE has unsigned type",
    6883                 :             :                           fndecl);
    6884                 :          14 :               return false;
    6885                 :             :             }
    6886                 :             :         }
    6887                 :       56796 :       else if (!TYPE_UNSIGNED (TREE_TYPE (args[0])))
    6888                 :             :         {
    6889                 :          42 :           if (complain)
    6890                 :          42 :             error_at (ARG_LOCATION (0),
    6891                 :             :                       "argument 1 in call to function "
    6892                 :             :                       "%qE has signed type",
    6893                 :             :                       fndecl);
    6894                 :          42 :           return false;
    6895                 :             :         }
    6896                 :             :       return true;
    6897                 :             : 
    6898                 :             :     default:
    6899                 :             :       return true;
    6900                 :             :     }
    6901                 :             : }
    6902                 :             : 
    6903                 :             : /* Subroutine of c_parse_error.
    6904                 :             :    Return the result of concatenating LHS and RHS. RHS is really
    6905                 :             :    a string literal, its first character is indicated by RHS_START and
    6906                 :             :    RHS_SIZE is its length (including the terminating NUL character).
    6907                 :             : 
    6908                 :             :    The caller is responsible for deleting the returned pointer.  */
    6909                 :             : 
    6910                 :             : static char *
    6911                 :        8722 : catenate_strings (const char *lhs, const char *rhs_start, int rhs_size)
    6912                 :             : {
    6913                 :        8722 :   const size_t lhs_size = strlen (lhs);
    6914                 :        8722 :   char *result = XNEWVEC (char, lhs_size + rhs_size);
    6915                 :        8722 :   memcpy (result, lhs, lhs_size);
    6916                 :        8722 :   memcpy (result + lhs_size, rhs_start, rhs_size);
    6917                 :        8722 :   return result;
    6918                 :             : }
    6919                 :             : 
    6920                 :             : /* Issue the error given by GMSGID at RICHLOC, indicating that it occurred
    6921                 :             :    before TOKEN, which had the associated VALUE.  */
    6922                 :             : 
    6923                 :             : void
    6924                 :        8736 : c_parse_error (const char *gmsgid, enum cpp_ttype token_type,
    6925                 :             :                tree value, unsigned char token_flags,
    6926                 :             :                rich_location *richloc)
    6927                 :             : {
    6928                 :             : #define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2))
    6929                 :             : 
    6930                 :        8736 :   char *message = NULL;
    6931                 :             : 
    6932                 :        8736 :   if (token_type == CPP_EOF)
    6933                 :         471 :     message = catenate_messages (gmsgid, " at end of input");
    6934                 :        8265 :   else if (token_type == CPP_CHAR
    6935                 :             :            || token_type == CPP_WCHAR
    6936                 :             :            || token_type == CPP_CHAR16
    6937                 :             :            || token_type == CPP_CHAR32
    6938                 :        8265 :            || token_type == CPP_UTF8CHAR)
    6939                 :             :     {
    6940                 :          24 :       unsigned int val = TREE_INT_CST_LOW (value);
    6941                 :          24 :       const char *prefix;
    6942                 :             : 
    6943                 :          24 :       switch (token_type)
    6944                 :             :         {
    6945                 :             :         default:
    6946                 :             :           prefix = "";
    6947                 :             :           break;
    6948                 :           0 :         case CPP_WCHAR:
    6949                 :           0 :           prefix = "L";
    6950                 :           0 :           break;
    6951                 :           0 :         case CPP_CHAR16:
    6952                 :           0 :           prefix = "u";
    6953                 :           0 :           break;
    6954                 :           0 :         case CPP_CHAR32:
    6955                 :           0 :           prefix = "U";
    6956                 :           0 :           break;
    6957                 :           0 :         case CPP_UTF8CHAR:
    6958                 :           0 :           prefix = "u8";
    6959                 :           0 :           break;
    6960                 :             :         }
    6961                 :             : 
    6962                 :          24 :       if (val <= UCHAR_MAX && ISGRAPH (val))
    6963                 :          20 :         message = catenate_messages (gmsgid, " before %s'%c'");
    6964                 :             :       else
    6965                 :           4 :         message = catenate_messages (gmsgid, " before %s'\\x%x'");
    6966                 :             : 
    6967                 :          24 :       error_at (richloc, message, prefix, val);
    6968                 :          24 :       free (message);
    6969                 :          24 :       message = NULL;
    6970                 :             :     }
    6971                 :        8241 :   else if (token_type == CPP_CHAR_USERDEF
    6972                 :             :            || token_type == CPP_WCHAR_USERDEF
    6973                 :             :            || token_type == CPP_CHAR16_USERDEF
    6974                 :             :            || token_type == CPP_CHAR32_USERDEF
    6975                 :        8241 :            || token_type == CPP_UTF8CHAR_USERDEF)
    6976                 :          12 :     message = catenate_messages (gmsgid,
    6977                 :             :                                  " before user-defined character literal");
    6978                 :        8229 :   else if (token_type == CPP_STRING_USERDEF
    6979                 :             :            || token_type == CPP_WSTRING_USERDEF
    6980                 :             :            || token_type == CPP_STRING16_USERDEF
    6981                 :             :            || token_type == CPP_STRING32_USERDEF
    6982                 :        8229 :            || token_type == CPP_UTF8STRING_USERDEF)
    6983                 :          25 :     message = catenate_messages (gmsgid, " before user-defined string literal");
    6984                 :        8204 :   else if (token_type == CPP_STRING
    6985                 :             :            || token_type == CPP_WSTRING
    6986                 :             :            || token_type == CPP_STRING16
    6987                 :             :            || token_type == CPP_STRING32
    6988                 :        8204 :            || token_type == CPP_UTF8STRING)
    6989                 :          44 :     message = catenate_messages (gmsgid, " before string constant");
    6990                 :        8160 :   else if (token_type == CPP_NUMBER)
    6991                 :         528 :     message = catenate_messages (gmsgid, " before numeric constant");
    6992                 :        7632 :   else if (token_type == CPP_NAME)
    6993                 :             :     {
    6994                 :        2086 :       message = catenate_messages (gmsgid, " before %qE");
    6995                 :        2086 :       error_at (richloc, message, value);
    6996                 :        2086 :       free (message);
    6997                 :        2086 :       message = NULL;
    6998                 :             :     }
    6999                 :        5546 :   else if (token_type == CPP_PRAGMA)
    7000                 :          20 :     message = catenate_messages (gmsgid, " before %<#pragma%>");
    7001                 :        5526 :   else if (token_type == CPP_PRAGMA_EOL)
    7002                 :         466 :     message = catenate_messages (gmsgid, " before end of line");
    7003                 :        5060 :   else if (token_type == CPP_DECLTYPE)
    7004                 :          12 :     message = catenate_messages (gmsgid, " before %<decltype%>");
    7005                 :        5048 :   else if (token_type == CPP_EMBED)
    7006                 :           0 :     message = catenate_messages (gmsgid, " before %<#embed%>");
    7007                 :        5048 :   else if (token_type < N_TTYPES)
    7008                 :             :     {
    7009                 :        5034 :       message = catenate_messages (gmsgid, " before %qs token");
    7010                 :        5034 :       error_at (richloc, message, cpp_type2name (token_type, token_flags));
    7011                 :        5034 :       free (message);
    7012                 :        5034 :       message = NULL;
    7013                 :             :     }
    7014                 :             :   else
    7015                 :          14 :     error_at (richloc, gmsgid);
    7016                 :             : 
    7017                 :        8736 :   if (message)
    7018                 :             :     {
    7019                 :        1578 :       error_at (richloc, message);
    7020                 :        1578 :       free (message);
    7021                 :             :     }
    7022                 :             : #undef catenate_messages
    7023                 :        8736 : }
    7024                 :             : 
    7025                 :             : /* Return the gcc option code associated with the reason for a cpp
    7026                 :             :    message, or 0 if none.  */
    7027                 :             : 
    7028                 :             : static diagnostic_option_id
    7029                 :      143462 : c_option_controlling_cpp_diagnostic (enum cpp_warning_reason reason)
    7030                 :             : {
    7031                 :      143462 :   const struct cpp_reason_option_codes_t *entry;
    7032                 :             : 
    7033                 :     3997924 :   for (entry = cpp_reason_option_codes; entry->reason != CPP_W_NONE; entry++)
    7034                 :             :     {
    7035                 :     3992011 :       if (entry->reason == reason)
    7036                 :      137549 :         return entry->option_code;
    7037                 :             :     }
    7038                 :           0 :   return 0;
    7039                 :             : }
    7040                 :             : 
    7041                 :             : /* Return TRUE if the given option index corresponds to a diagnostic
    7042                 :             :    issued by libcpp.  Linear search seems fine for now.  */
    7043                 :             : bool
    7044                 :     2022361 : c_option_is_from_cpp_diagnostics (int option_index)
    7045                 :             : {
    7046                 :    46814928 :   for (auto entry = cpp_reason_option_codes; entry->reason != CPP_W_NONE;
    7047                 :             :        ++entry)
    7048                 :             :     {
    7049                 :    46061914 :       if (entry->option_code == option_index)
    7050                 :             :         return true;
    7051                 :             :     }
    7052                 :             :   return false;
    7053                 :             : }
    7054                 :             : 
    7055                 :             : /* Callback from cpp_diagnostic for PFILE to print diagnostics from the
    7056                 :             :    preprocessor.  The diagnostic is of type LEVEL, with REASON set
    7057                 :             :    to the reason code if LEVEL is represents a warning, at location
    7058                 :             :    RICHLOC unless this is after lexing and the compiler's location
    7059                 :             :    should be used instead; MSG is the translated message and AP
    7060                 :             :    the arguments.  Returns true if a diagnostic was emitted, false
    7061                 :             :    otherwise.  */
    7062                 :             : 
    7063                 :             : bool
    7064                 :      143472 : c_cpp_diagnostic (cpp_reader *pfile ATTRIBUTE_UNUSED,
    7065                 :             :                   enum cpp_diagnostic_level level,
    7066                 :             :                   enum cpp_warning_reason reason,
    7067                 :             :                   rich_location *richloc,
    7068                 :             :                   const char *msg, va_list *ap)
    7069                 :             : {
    7070                 :      143472 :   diagnostic_info diagnostic;
    7071                 :      143472 :   diagnostic_t dlevel;
    7072                 :      143472 :   bool save_warn_system_headers = global_dc->m_warn_system_headers;
    7073                 :      143472 :   bool ret;
    7074                 :             : 
    7075                 :      143472 :   switch (level)
    7076                 :             :     {
    7077                 :          87 :     case CPP_DL_WARNING_SYSHDR:
    7078                 :          87 :       if (flag_no_output)
    7079                 :             :         return false;
    7080                 :          86 :       global_dc->m_warn_system_headers = 1;
    7081                 :             :       /* Fall through.  */
    7082                 :       24308 :     case CPP_DL_WARNING:
    7083                 :       24308 :       if (flag_no_output)
    7084                 :             :         return false;
    7085                 :             :       dlevel = DK_WARNING;
    7086                 :             :       break;
    7087                 :      114472 :     case CPP_DL_PEDWARN:
    7088                 :      114472 :       if (flag_no_output && !flag_pedantic_errors)
    7089                 :             :         return false;
    7090                 :             :       dlevel = DK_PEDWARN;
    7091                 :             :       break;
    7092                 :             :     case CPP_DL_ERROR:
    7093                 :             :       dlevel = DK_ERROR;
    7094                 :             :       break;
    7095                 :           0 :     case CPP_DL_ICE:
    7096                 :           0 :       dlevel = DK_ICE;
    7097                 :           0 :       break;
    7098                 :         318 :     case CPP_DL_NOTE:
    7099                 :         318 :       dlevel = DK_NOTE;
    7100                 :         318 :       break;
    7101                 :         355 :     case CPP_DL_FATAL:
    7102                 :         355 :       dlevel = DK_FATAL;
    7103                 :         355 :       break;
    7104                 :           0 :     default:
    7105                 :           0 :       gcc_unreachable ();
    7106                 :             :     }
    7107                 :      143462 :   if (override_libcpp_locations)
    7108                 :         247 :     richloc->set_range (0, input_location, SHOW_RANGE_WITH_CARET);
    7109                 :      143462 :   diagnostic_set_info_translated (&diagnostic, msg, ap,
    7110                 :             :                                   richloc, dlevel);
    7111                 :      286924 :   diagnostic_set_option_id (&diagnostic,
    7112                 :             :                             c_option_controlling_cpp_diagnostic (reason));
    7113                 :      143462 :   ret = diagnostic_report_diagnostic (global_dc, &diagnostic);
    7114                 :      143107 :   if (level == CPP_DL_WARNING_SYSHDR)
    7115                 :          86 :     global_dc->m_warn_system_headers = save_warn_system_headers;
    7116                 :             :   return ret;
    7117                 :      143117 : }
    7118                 :             : 
    7119                 :             : /* Convert a character from the host to the target execution character
    7120                 :             :    set.  cpplib handles this, mostly.  */
    7121                 :             : 
    7122                 :             : HOST_WIDE_INT
    7123                 :     6498180 : c_common_to_target_charset (HOST_WIDE_INT c)
    7124                 :             : {
    7125                 :             :   /* Character constants in GCC proper are sign-extended under -fsigned-char,
    7126                 :             :      zero-extended under -fno-signed-char.  cpplib insists that characters
    7127                 :             :      and character constants are always unsigned.  Hence we must convert
    7128                 :             :      back and forth.  */
    7129                 :     6498180 :   cppchar_t uc = ((cppchar_t)c) & ((((cppchar_t)1) << CHAR_BIT)-1);
    7130                 :             : 
    7131                 :     6498180 :   uc = cpp_host_to_exec_charset (parse_in, uc);
    7132                 :             : 
    7133                 :     6498180 :   if (flag_signed_char)
    7134                 :     6498083 :     return ((HOST_WIDE_INT)uc) << (HOST_BITS_PER_WIDE_INT - CHAR_TYPE_SIZE)
    7135                 :     6498083 :                                >> (HOST_BITS_PER_WIDE_INT - CHAR_TYPE_SIZE);
    7136                 :             :   else
    7137                 :          97 :     return uc;
    7138                 :             : }
    7139                 :             : 
    7140                 :             : /* Fold an offsetof-like expression.  EXPR is a nested sequence of component
    7141                 :             :    references with an INDIRECT_REF of a constant at the bottom; much like the
    7142                 :             :    traditional rendering of offsetof as a macro.  TYPE is the desired type of
    7143                 :             :    the whole expression.  Return the folded result.  */
    7144                 :             : 
    7145                 :             : tree
    7146                 :       15084 : fold_offsetof (tree expr, tree type, enum tree_code ctx)
    7147                 :             : {
    7148                 :       15093 :   tree base, off, t;
    7149                 :       15093 :   tree_code code = TREE_CODE (expr);
    7150                 :       15093 :   switch (code)
    7151                 :             :     {
    7152                 :             :     case ERROR_MARK:
    7153                 :             :       return expr;
    7154                 :             : 
    7155                 :          12 :     case VAR_DECL:
    7156                 :          12 :       error ("cannot apply %<offsetof%> to static data member %qD", expr);
    7157                 :          12 :       return error_mark_node;
    7158                 :             : 
    7159                 :           9 :     case CALL_EXPR:
    7160                 :           9 :     case TARGET_EXPR:
    7161                 :           9 :       error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded");
    7162                 :           9 :       return error_mark_node;
    7163                 :             : 
    7164                 :        6626 :     case NOP_EXPR:
    7165                 :        6626 :     case INDIRECT_REF:
    7166                 :        6626 :       if (!TREE_CONSTANT (TREE_OPERAND (expr, 0)))
    7167                 :             :         {
    7168                 :          17 :           error ("cannot apply %<offsetof%> to a non constant address");
    7169                 :          17 :           return error_mark_node;
    7170                 :             :         }
    7171                 :        6609 :       return convert (type, TREE_OPERAND (expr, 0));
    7172                 :             : 
    7173                 :        7214 :     case COMPONENT_REF:
    7174                 :        7214 :       base = fold_offsetof (TREE_OPERAND (expr, 0), type, code);
    7175                 :        7214 :       if (base == error_mark_node)
    7176                 :             :         return base;
    7177                 :             : 
    7178                 :        7211 :       t = TREE_OPERAND (expr, 1);
    7179                 :        7211 :       if (DECL_C_BIT_FIELD (t))
    7180                 :             :         {
    7181                 :           1 :           error ("attempt to take address of bit-field structure "
    7182                 :             :                  "member %qD", t);
    7183                 :           1 :           return error_mark_node;
    7184                 :             :         }
    7185                 :        7210 :       off = size_binop_loc (input_location, PLUS_EXPR, DECL_FIELD_OFFSET (t),
    7186                 :        7210 :                             size_int (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (t))
    7187                 :             :                                       / BITS_PER_UNIT));
    7188                 :        7210 :       break;
    7189                 :             : 
    7190                 :        1222 :     case ARRAY_REF:
    7191                 :        1222 :       base = fold_offsetof (TREE_OPERAND (expr, 0), type, code);
    7192                 :        1222 :       if (base == error_mark_node)
    7193                 :             :         return base;
    7194                 :             : 
    7195                 :        1219 :       t = TREE_OPERAND (expr, 1);
    7196                 :        1219 :       STRIP_ANY_LOCATION_WRAPPER (t);
    7197                 :             : 
    7198                 :             :       /* Check if the offset goes beyond the upper bound of the array.  */
    7199                 :        1219 :       if (TREE_CODE (t) == INTEGER_CST && tree_int_cst_sgn (t) >= 0)
    7200                 :             :         {
    7201                 :         956 :           tree upbound = array_ref_up_bound (expr);
    7202                 :         956 :           if (upbound != NULL_TREE
    7203                 :         844 :               && TREE_CODE (upbound) == INTEGER_CST
    7204                 :        1800 :               && !tree_int_cst_equal (upbound,
    7205                 :         844 :                                       TYPE_MAX_VALUE (TREE_TYPE (upbound))))
    7206                 :             :             {
    7207                 :         835 :               if (ctx != ARRAY_REF && ctx != COMPONENT_REF)
    7208                 :         433 :                 upbound = size_binop (PLUS_EXPR, upbound,
    7209                 :             :                                       build_int_cst (TREE_TYPE (upbound), 1));
    7210                 :         835 :               if (tree_int_cst_lt (upbound, t))
    7211                 :             :                 {
    7212                 :         244 :                   tree v;
    7213                 :             : 
    7214                 :         244 :                   for (v = TREE_OPERAND (expr, 0);
    7215                 :         420 :                        TREE_CODE (v) == COMPONENT_REF;
    7216                 :         176 :                        v = TREE_OPERAND (v, 0))
    7217                 :         280 :                     if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0)))
    7218                 :             :                         == RECORD_TYPE)
    7219                 :             :                       {
    7220                 :         220 :                         tree fld_chain = DECL_CHAIN (TREE_OPERAND (v, 1));
    7221                 :         307 :                         for (; fld_chain; fld_chain = DECL_CHAIN (fld_chain))
    7222                 :         191 :                           if (TREE_CODE (fld_chain) == FIELD_DECL)
    7223                 :             :                             break;
    7224                 :             : 
    7225                 :             :                         if (fld_chain)
    7226                 :             :                           break;
    7227                 :             :                       }
    7228                 :             :                   /* Don't warn if the array might be considered a poor
    7229                 :             :                      man's flexible array member with a very permissive
    7230                 :             :                      definition thereof.  */
    7231                 :         244 :                   if (TREE_CODE (v) == ARRAY_REF
    7232                 :         172 :                       || TREE_CODE (v) == COMPONENT_REF)
    7233                 :         176 :                     warning (OPT_Warray_bounds_,
    7234                 :             :                              "index %E denotes an offset "
    7235                 :             :                              "greater than size of %qT",
    7236                 :         176 :                              t, TREE_TYPE (TREE_OPERAND (expr, 0)));
    7237                 :             :                 }
    7238                 :             :             }
    7239                 :             :         }
    7240                 :             : 
    7241                 :        1219 :       t = convert (sizetype, t);
    7242                 :        1219 :       off = size_binop (MULT_EXPR, TYPE_SIZE_UNIT (TREE_TYPE (expr)), t);
    7243                 :        1219 :       break;
    7244                 :             : 
    7245                 :           9 :     case COMPOUND_EXPR:
    7246                 :             :       /* Handle static members of volatile structs.  */
    7247                 :           9 :       t = TREE_OPERAND (expr, 1);
    7248                 :           9 :       gcc_checking_assert (VAR_P (get_base_address (t)));
    7249                 :             :       return fold_offsetof (t, type);
    7250                 :             : 
    7251                 :           0 :     default:
    7252                 :           0 :       gcc_unreachable ();
    7253                 :             :     }
    7254                 :             : 
    7255                 :        8429 :   if (!POINTER_TYPE_P (type))
    7256                 :        7560 :     return size_binop (PLUS_EXPR, base, convert (type, off));
    7257                 :         869 :   return fold_build_pointer_plus (base, off);
    7258                 :             : }
    7259                 :             : 
    7260                 :             : /* *PTYPE is an incomplete array.  Complete it with a domain based on
    7261                 :             :    INITIAL_VALUE.  If INITIAL_VALUE is not present, use 1 if DO_DEFAULT
    7262                 :             :    is true.  Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
    7263                 :             :    2 if INITIAL_VALUE was NULL, and 3 if INITIAL_VALUE was empty.  */
    7264                 :             : 
    7265                 :             : int
    7266                 :      539471 : complete_array_type (tree *ptype, tree initial_value, bool do_default)
    7267                 :             : {
    7268                 :      539471 :   tree maxindex, type, main_type, elt, unqual_elt;
    7269                 :      539471 :   int failure = 0, quals;
    7270                 :      539471 :   bool overflow_p = false;
    7271                 :             : 
    7272                 :      539471 :   maxindex = size_zero_node;
    7273                 :      539471 :   if (initial_value)
    7274                 :             :     {
    7275                 :      532033 :       STRIP_ANY_LOCATION_WRAPPER (initial_value);
    7276                 :             : 
    7277                 :      532033 :       if (TREE_CODE (initial_value) == STRING_CST)
    7278                 :             :         {
    7279                 :      429361 :           int eltsize
    7280                 :      429361 :             = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value)));
    7281                 :      429361 :           maxindex = size_int (TREE_STRING_LENGTH (initial_value) / eltsize
    7282                 :             :                                - 1);
    7283                 :             :         }
    7284                 :      102672 :       else if (TREE_CODE (initial_value) == CONSTRUCTOR)
    7285                 :             :         {
    7286                 :      101770 :           vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (initial_value);
    7287                 :             : 
    7288                 :      101770 :           if (vec_safe_is_empty (v))
    7289                 :             :             {
    7290                 :         396 :               if (pedantic)
    7291                 :          68 :                 failure = 3;
    7292                 :         396 :               maxindex = ssize_int (-1);
    7293                 :             :             }
    7294                 :             :           else
    7295                 :             :             {
    7296                 :      101374 :               tree curindex;
    7297                 :      101374 :               unsigned HOST_WIDE_INT cnt = 1;
    7298                 :      101374 :               constructor_elt *ce;
    7299                 :      101374 :               bool fold_p = false;
    7300                 :             : 
    7301                 :      101374 :               if ((*v)[0].index)
    7302                 :       88937 :                 maxindex = (*v)[0].index, fold_p = true;
    7303                 :      101374 :               if (TREE_CODE ((*v)[0].value) == RAW_DATA_CST)
    7304                 :           4 :                 cnt = 0;
    7305                 :             : 
    7306                 :             :               curindex = maxindex;
    7307                 :             : 
    7308                 :    15993609 :               for (; vec_safe_iterate (v, cnt, &ce); cnt++)
    7309                 :             :                 {
    7310                 :    15892235 :                   bool curfold_p = false;
    7311                 :    15892235 :                   if (ce->index)
    7312                 :    14668691 :                     curindex = ce->index, curfold_p = true;
    7313                 :    15892235 :                   if (!ce->index || TREE_CODE (ce->value) == RAW_DATA_CST)
    7314                 :             :                     {
    7315                 :     1223903 :                       if (fold_p || curfold_p)
    7316                 :             :                         {
    7317                 :             :                           /* Since we treat size types now as ordinary
    7318                 :             :                              unsigned types, we need an explicit overflow
    7319                 :             :                              check.  */
    7320                 :         359 :                           tree orig = curindex;
    7321                 :         359 :                           curindex = fold_convert (sizetype, curindex);
    7322                 :         359 :                           overflow_p |= tree_int_cst_lt (curindex, orig);
    7323                 :         359 :                           curfold_p = false;
    7324                 :             :                         }
    7325                 :     1223903 :                       if (TREE_CODE (ce->value) == RAW_DATA_CST)
    7326                 :         359 :                         curindex
    7327                 :         718 :                           = size_binop (PLUS_EXPR, curindex,
    7328                 :             :                                         size_int (RAW_DATA_LENGTH (ce->value)
    7329                 :             :                                                   - ((ce->index || !cnt)
    7330                 :             :                                                      ? 1 : 0)));
    7331                 :             :                       else
    7332                 :     1223544 :                         curindex = size_binop (PLUS_EXPR, curindex,
    7333                 :             :                                                size_one_node);
    7334                 :             :                     }
    7335                 :    15892235 :                   if (tree_int_cst_lt (maxindex, curindex))
    7336                 :    15892235 :                     maxindex = curindex, fold_p = curfold_p;
    7337                 :             :                 }
    7338                 :      101374 :               if (fold_p)
    7339                 :             :                 {
    7340                 :       88933 :                   tree orig = maxindex;
    7341                 :       88933 :                   maxindex = fold_convert (sizetype, maxindex);
    7342                 :       88933 :                   overflow_p |= tree_int_cst_lt (maxindex, orig);
    7343                 :             :                 }
    7344                 :             :             }
    7345                 :             :         }
    7346                 :             :       else
    7347                 :             :         {
    7348                 :             :           /* Make an error message unless that happened already.  */
    7349                 :         902 :           if (initial_value != error_mark_node)
    7350                 :          31 :             failure = 1;
    7351                 :             :         }
    7352                 :             :     }
    7353                 :             :   else
    7354                 :             :     {
    7355                 :        7438 :       failure = 2;
    7356                 :        7438 :       if (!do_default)
    7357                 :             :         return failure;
    7358                 :             :     }
    7359                 :             : 
    7360                 :      532118 :   type = *ptype;
    7361                 :      532118 :   elt = TREE_TYPE (type);
    7362                 :      532118 :   quals = TYPE_QUALS (strip_array_types (elt));
    7363                 :      532118 :   if (quals == 0)
    7364                 :             :     unqual_elt = elt;
    7365                 :             :   else
    7366                 :      500828 :     unqual_elt = c_build_qualified_type (elt, KEEP_QUAL_ADDR_SPACE (quals));
    7367                 :             : 
    7368                 :             :   /* Using build_distinct_type_copy and modifying things afterward instead
    7369                 :             :      of using build_array_type to create a new type preserves all of the
    7370                 :             :      TYPE_LANG_FLAG_? bits that the front end may have set.  */
    7371                 :      532118 :   main_type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
    7372                 :      532118 :   TREE_TYPE (main_type) = unqual_elt;
    7373                 :     1064236 :   TYPE_DOMAIN (main_type)
    7374                 :      532118 :     = build_range_type (TREE_TYPE (maxindex),
    7375                 :      532118 :                         build_int_cst (TREE_TYPE (maxindex), 0), maxindex);
    7376                 :      532118 :   TYPE_TYPELESS_STORAGE (main_type) = TYPE_TYPELESS_STORAGE (type);
    7377                 :      532118 :   layout_type (main_type);
    7378                 :             : 
    7379                 :             :   /* Set TYPE_STRUCTURAL_EQUALITY_P early.  */
    7380                 :      532118 :   if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type))
    7381                 :     1063855 :       || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type)))
    7382                 :         381 :     SET_TYPE_STRUCTURAL_EQUALITY (main_type);
    7383                 :             :   else
    7384                 :      531737 :     TYPE_CANONICAL (main_type) = main_type;
    7385                 :             : 
    7386                 :             :   /* Make sure we have the canonical MAIN_TYPE. */
    7387                 :      532118 :   hashval_t hashcode = type_hash_canon_hash (main_type);
    7388                 :      532118 :   main_type = type_hash_canon (hashcode, main_type);
    7389                 :             : 
    7390                 :             :   /* Fix the canonical type.  */
    7391                 :      532118 :   if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type))
    7392                 :     1063855 :       || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type)))
    7393                 :         381 :     gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (main_type));
    7394                 :      531737 :   else if (TYPE_CANONICAL (TREE_TYPE (main_type)) != TREE_TYPE (main_type)
    7395                 :      531737 :            || (TYPE_CANONICAL (TYPE_DOMAIN (main_type))
    7396                 :      515118 :                != TYPE_DOMAIN (main_type)))
    7397                 :       16619 :     TYPE_CANONICAL (main_type)
    7398                 :       33238 :       = build_array_type (TYPE_CANONICAL (TREE_TYPE (main_type)),
    7399                 :       16619 :                           TYPE_CANONICAL (TYPE_DOMAIN (main_type)),
    7400                 :       16619 :                           TYPE_TYPELESS_STORAGE (main_type));
    7401                 :             : 
    7402                 :      532118 :   if (quals == 0)
    7403                 :             :     type = main_type;
    7404                 :             :   else
    7405                 :      500828 :     type = c_build_qualified_type (main_type, quals);
    7406                 :             : 
    7407                 :      532118 :   if (COMPLETE_TYPE_P (type)
    7408                 :      532109 :       && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST
    7409                 :     1064221 :       && (overflow_p || TREE_OVERFLOW (TYPE_SIZE_UNIT (type))))
    7410                 :             :     {
    7411                 :           4 :       error ("size of array is too large");
    7412                 :             :       /* If we proceed with the array type as it is, we'll eventually
    7413                 :             :          crash in tree_to_[su]hwi().  */
    7414                 :           4 :       type = error_mark_node;
    7415                 :             :     }
    7416                 :             : 
    7417                 :      532118 :   *ptype = type;
    7418                 :      532118 :   return failure;
    7419                 :             : }
    7420                 :             : 
    7421                 :             : /* INIT is an constructor of a structure with a flexible array member.
    7422                 :             :    Complete the flexible array member with a domain based on it's value.  */
    7423                 :             : void
    7424                 :     8745158 : complete_flexible_array_elts (tree init)
    7425                 :             : {
    7426                 :     8850153 :   tree elt, type;
    7427                 :             : 
    7428                 :     8850153 :   if (init == NULL_TREE || TREE_CODE (init) != CONSTRUCTOR)
    7429                 :             :     return;
    7430                 :             : 
    7431                 :      106495 :   if (vec_safe_is_empty (CONSTRUCTOR_ELTS (init)))
    7432                 :             :     return;
    7433                 :             : 
    7434                 :      105248 :   elt = CONSTRUCTOR_ELTS (init)->last ().value;
    7435                 :      105248 :   type = TREE_TYPE (elt);
    7436                 :      105248 :   if (TREE_CODE (type) == ARRAY_TYPE
    7437                 :      105248 :       && TYPE_SIZE (type) == NULL_TREE)
    7438                 :         253 :     complete_array_type (&TREE_TYPE (elt), elt, false);
    7439                 :             :   else
    7440                 :             :     complete_flexible_array_elts (elt);
    7441                 :             : }
    7442                 :             : 
    7443                 :             : /* Like c_mark_addressable but don't check register qualifier.  */
    7444                 :             : void
    7445                 :     1097117 : c_common_mark_addressable_vec (tree t)
    7446                 :             : {
    7447                 :     1270203 :   while (handled_component_p (t) || TREE_CODE (t) == C_MAYBE_CONST_EXPR)
    7448                 :             :     {
    7449                 :      173086 :       if (TREE_CODE (t) == C_MAYBE_CONST_EXPR)
    7450                 :          26 :         t = C_MAYBE_CONST_EXPR_EXPR (t);
    7451                 :             :       else
    7452                 :      173060 :         t = TREE_OPERAND (t, 0);
    7453                 :             :     }
    7454                 :     1097117 :   if (!VAR_P (t)
    7455                 :             :       && TREE_CODE (t) != PARM_DECL
    7456                 :             :       && TREE_CODE (t) != COMPOUND_LITERAL_EXPR
    7457                 :             :       && TREE_CODE (t) != TARGET_EXPR)
    7458                 :             :     return;
    7459                 :     1077836 :   if (!VAR_P (t) || !DECL_HARD_REGISTER (t))
    7460                 :     1077767 :     TREE_ADDRESSABLE (t) = 1;
    7461                 :     1077836 :   if (TREE_CODE (t) == COMPOUND_LITERAL_EXPR)
    7462                 :         126 :     TREE_ADDRESSABLE (COMPOUND_LITERAL_EXPR_DECL (t)) = 1;
    7463                 :     1077710 :   else if (TREE_CODE (t) == TARGET_EXPR)
    7464                 :          28 :     TREE_ADDRESSABLE (TARGET_EXPR_SLOT (t)) = 1;
    7465                 :             : }
    7466                 :             : 
    7467                 :             : 
    7468                 :             : 
    7469                 :             : /* Used to help initialize the builtin-types.def table.  When a type of
    7470                 :             :    the correct size doesn't exist, use error_mark_node instead of NULL.
    7471                 :             :    The later results in segfaults even when a decl using the type doesn't
    7472                 :             :    get invoked.  */
    7473                 :             : 
    7474                 :             : tree
    7475                 :     1108610 : builtin_type_for_size (int size, bool unsignedp)
    7476                 :             : {
    7477                 :     1108610 :   tree type = c_common_type_for_size (size, unsignedp);
    7478                 :     1108610 :   return type ? type : error_mark_node;
    7479                 :             : }
    7480                 :             : 
    7481                 :             : /* Work out the size of the first argument of a call to
    7482                 :             :    __builtin_speculation_safe_value.  Only pointers and integral types
    7483                 :             :    are permitted.  Return -1 if the argument type is not supported or
    7484                 :             :    the size is too large; 0 if the argument type is a pointer or the
    7485                 :             :    size if it is integral.  */
    7486                 :             : static enum built_in_function
    7487                 :         155 : speculation_safe_value_resolve_call (tree function, vec<tree, va_gc> *params,
    7488                 :             :                                      bool complain)
    7489                 :             : {
    7490                 :             :   /* Type of the argument.  */
    7491                 :         155 :   tree type;
    7492                 :         155 :   int size;
    7493                 :             : 
    7494                 :         155 :   if (vec_safe_is_empty (params))
    7495                 :             :     {
    7496                 :          10 :       if (complain)
    7497                 :          10 :         error ("too few arguments to function %qE", function);
    7498                 :          10 :       return BUILT_IN_NONE;
    7499                 :             :     }
    7500                 :             : 
    7501                 :         145 :   type = TREE_TYPE ((*params)[0]);
    7502                 :         145 :   if (TREE_CODE (type) == ARRAY_TYPE && c_dialect_cxx ())
    7503                 :             :     {
    7504                 :             :       /* Force array-to-pointer decay for C++.   */
    7505                 :           0 :       (*params)[0] = default_conversion ((*params)[0]);
    7506                 :           0 :       type = TREE_TYPE ((*params)[0]);
    7507                 :             :     }
    7508                 :             : 
    7509                 :         145 :   if (POINTER_TYPE_P (type))
    7510                 :             :     return BUILT_IN_SPECULATION_SAFE_VALUE_PTR;
    7511                 :             : 
    7512                 :         129 :   if (!INTEGRAL_TYPE_P (type))
    7513                 :          42 :     goto incompatible;
    7514                 :             : 
    7515                 :          87 :   if (!COMPLETE_TYPE_P (type))
    7516                 :           0 :     goto incompatible;
    7517                 :             : 
    7518                 :          87 :   size = tree_to_uhwi (TYPE_SIZE_UNIT (type));
    7519                 :          87 :   if (size == 1 || size == 2 || size == 4 || size == 8 || size == 16)
    7520                 :          87 :     return ((enum built_in_function)
    7521                 :         174 :             ((int) BUILT_IN_SPECULATION_SAFE_VALUE_1 + exact_log2 (size)));
    7522                 :             : 
    7523                 :           0 :  incompatible:
    7524                 :             :   /* Issue the diagnostic only if the argument is valid, otherwise
    7525                 :             :      it would be redundant at best and could be misleading.  */
    7526                 :          42 :   if (type != error_mark_node && complain)
    7527                 :           6 :     error ("operand type %qT is incompatible with argument %d of %qE",
    7528                 :             :            type, 1, function);
    7529                 :             : 
    7530                 :             :   return BUILT_IN_NONE;
    7531                 :             : }
    7532                 :             : 
    7533                 :             : /* Validate and coerce PARAMS, the arguments to ORIG_FUNCTION to fit
    7534                 :             :    the prototype for FUNCTION.  The first argument is mandatory, a second
    7535                 :             :    argument, if present, must be type compatible with the first.  */
    7536                 :             : static bool
    7537                 :         103 : speculation_safe_value_resolve_params (location_t loc, tree orig_function,
    7538                 :             :                                        vec<tree, va_gc> *params, bool complain)
    7539                 :             : {
    7540                 :         103 :   tree val;
    7541                 :             : 
    7542                 :         103 :   if (params->length () == 0)
    7543                 :             :     {
    7544                 :           0 :       if (complain)
    7545                 :           0 :         error_at (loc, "too few arguments to function %qE", orig_function);
    7546                 :           0 :       return false;
    7547                 :             :     }
    7548                 :             : 
    7549                 :         103 :   else if (params->length () > 2)
    7550                 :             :     {
    7551                 :          21 :       if (complain)
    7552                 :           0 :         error_at (loc, "too many arguments to function %qE", orig_function);
    7553                 :          21 :       return false;
    7554                 :             :     }
    7555                 :             : 
    7556                 :          82 :   val = (*params)[0];
    7557                 :          82 :   if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE)
    7558                 :           0 :     val = default_conversion (val);
    7559                 :          82 :   if (!(TREE_CODE (TREE_TYPE (val)) == POINTER_TYPE
    7560                 :          66 :         || TREE_CODE (TREE_TYPE (val)) == INTEGER_TYPE))
    7561                 :             :     {
    7562                 :           0 :       if (complain)
    7563                 :           0 :         error_at (loc, "expecting argument of type pointer or of type integer "
    7564                 :             :                        "for argument 1");
    7565                 :           0 :       return false;
    7566                 :             :     }
    7567                 :          82 :   (*params)[0] = val;
    7568                 :             : 
    7569                 :          82 :   if (params->length () == 2)
    7570                 :             :     {
    7571                 :          32 :       tree val2 = (*params)[1];
    7572                 :          32 :       if (TREE_CODE (TREE_TYPE (val2)) == ARRAY_TYPE)
    7573                 :           0 :         val2 = default_conversion (val2);
    7574                 :          32 :       if (error_operand_p (val2))
    7575                 :             :         return false;
    7576                 :          40 :       if (!(TREE_TYPE (val) == TREE_TYPE (val2)
    7577                 :           9 :             || useless_type_conversion_p (TREE_TYPE (val), TREE_TYPE (val2))))
    7578                 :             :         {
    7579                 :           9 :           if (complain)
    7580                 :           0 :             error_at (loc, "both arguments must be compatible");
    7581                 :           9 :           return false;
    7582                 :             :         }
    7583                 :          22 :       (*params)[1] = val2;
    7584                 :             :     }
    7585                 :             : 
    7586                 :             :   return true;
    7587                 :             : }
    7588                 :             : 
    7589                 :             : /* Cast the result of the builtin back to the type of the first argument,
    7590                 :             :    preserving any qualifiers that it might have.  */
    7591                 :             : static tree
    7592                 :          72 : speculation_safe_value_resolve_return (tree first_param, tree result)
    7593                 :             : {
    7594                 :          72 :   tree ptype = TREE_TYPE (first_param);
    7595                 :          72 :   tree rtype = TREE_TYPE (result);
    7596                 :          72 :   ptype = TYPE_MAIN_VARIANT (ptype);
    7597                 :             : 
    7598                 :          72 :   if (tree_int_cst_equal (TYPE_SIZE (ptype), TYPE_SIZE (rtype)))
    7599                 :          72 :     return convert (ptype, result);
    7600                 :             : 
    7601                 :             :   return result;
    7602                 :             : }
    7603                 :             : 
    7604                 :             : /* A helper function for resolve_overloaded_builtin in resolving the
    7605                 :             :    overloaded __sync_ builtins.  Returns a positive power of 2 if the
    7606                 :             :    first operand of PARAMS is a pointer to a supported data type.
    7607                 :             :    Returns 0 if an error is encountered.  Return -1 for _BitInt
    7608                 :             :    __atomic*fetch* with unsupported type which should be handled by
    7609                 :             :    a cas loop.
    7610                 :             :    FETCH is true when FUNCTION is one of the _FETCH_OP_ or _OP_FETCH_
    7611                 :             :    built-ins.  ORIG_FORMAT is for __sync_* rather than __atomic_*
    7612                 :             :    built-ins.  */
    7613                 :             : 
    7614                 :             : static int
    7615                 :      321018 : sync_resolve_size (tree function, vec<tree, va_gc> *params, bool fetch,
    7616                 :             :                    bool orig_format, bool complain)
    7617                 :             : {
    7618                 :             :   /* Type of the argument.  */
    7619                 :      321018 :   tree argtype;
    7620                 :             :   /* Type the argument points to.  */
    7621                 :      321018 :   tree type;
    7622                 :      321018 :   int size;
    7623                 :             : 
    7624                 :      321018 :   if (vec_safe_is_empty (params))
    7625                 :             :     {
    7626                 :         106 :       if (complain)
    7627                 :         106 :         error ("too few arguments to function %qE", function);
    7628                 :         106 :       return 0;
    7629                 :             :     }
    7630                 :             : 
    7631                 :      320912 :   argtype = type = TREE_TYPE ((*params)[0]);
    7632                 :      320912 :   if (TREE_CODE (type) == ARRAY_TYPE && c_dialect_cxx ())
    7633                 :             :     {
    7634                 :             :       /* Force array-to-pointer decay for C++.  */
    7635                 :           3 :       (*params)[0] = default_conversion ((*params)[0]);
    7636                 :           3 :       type = TREE_TYPE ((*params)[0]);
    7637                 :             :     }
    7638                 :      320912 :   if (TREE_CODE (type) != POINTER_TYPE)
    7639                 :        2127 :     goto incompatible;
    7640                 :             : 
    7641                 :      318785 :   type = TREE_TYPE (type);
    7642                 :      318785 :   if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
    7643                 :         288 :     goto incompatible;
    7644                 :             : 
    7645                 :      318497 :   if (!COMPLETE_TYPE_P (type))
    7646                 :           2 :     goto incompatible;
    7647                 :             : 
    7648                 :      318495 :   if (fetch && TREE_CODE (type) == BOOLEAN_TYPE)
    7649                 :          84 :     goto incompatible;
    7650                 :             : 
    7651                 :      318411 :   size = tree_to_uhwi (TYPE_SIZE_UNIT (type));
    7652                 :      318411 :   if (size == 16
    7653                 :        7675 :       && TREE_CODE (type) == BITINT_TYPE
    7654                 :      318937 :       && !targetm.scalar_mode_supported_p (TImode))
    7655                 :             :     {
    7656                 :           0 :       if (fetch && !orig_format)
    7657                 :             :         return -1;
    7658                 :           0 :       goto incompatible;
    7659                 :             :     }
    7660                 :             : 
    7661                 :      318411 :   if (size == 1 || size == 2 || size == 4 || size == 8 || size == 16)
    7662                 :             :     return size;
    7663                 :             : 
    7664                 :         528 :   if (fetch && !orig_format && TREE_CODE (type) == BITINT_TYPE)
    7665                 :             :     return -1;
    7666                 :             : 
    7667                 :           0 :  incompatible:
    7668                 :             :   /* Issue the diagnostic only if the argument is valid, otherwise
    7669                 :             :      it would be redundant at best and could be misleading.  */
    7670                 :        2501 :   if (argtype != error_mark_node && complain)
    7671                 :         920 :     error ("operand type %qT is incompatible with argument %d of %qE",
    7672                 :             :            argtype, 1, function);
    7673                 :             :   return 0;
    7674                 :             : }
    7675                 :             : 
    7676                 :             : /* A helper function for resolve_overloaded_builtin.  Adds casts to
    7677                 :             :    PARAMS to make arguments match up with those of FUNCTION.  Drops
    7678                 :             :    the variadic arguments at the end.  Returns false if some error
    7679                 :             :    was encountered; true on success.  */
    7680                 :             : 
    7681                 :             : static bool
    7682                 :      317883 : sync_resolve_params (location_t loc, tree orig_function, tree function,
    7683                 :             :                      vec<tree, va_gc> *params, bool orig_format, bool complain)
    7684                 :             : {
    7685                 :      317883 :   function_args_iterator iter;
    7686                 :      317883 :   tree ptype;
    7687                 :      317883 :   unsigned int parmnum;
    7688                 :             : 
    7689                 :      317883 :   function_args_iter_init (&iter, TREE_TYPE (function));
    7690                 :             :   /* We've declared the implementation functions to use "volatile void *"
    7691                 :             :      as the pointer parameter, so we shouldn't get any complaints from the
    7692                 :             :      call to check_function_arguments what ever type the user used.  */
    7693                 :      317883 :   function_args_iter_next (&iter);
    7694                 :      317883 :   ptype = TREE_TYPE (TREE_TYPE ((*params)[0]));
    7695                 :      317883 :   ptype = TYPE_MAIN_VARIANT (ptype);
    7696                 :             : 
    7697                 :             :   /* For the rest of the values, we need to cast these to FTYPE, so that we
    7698                 :             :      don't get warnings for passing pointer types, etc.  */
    7699                 :      317883 :   parmnum = 0;
    7700                 :     1783247 :   while (1)
    7701                 :             :     {
    7702                 :     1050565 :       tree val, arg_type;
    7703                 :             : 
    7704                 :     1050565 :       arg_type = function_args_iter_cond (&iter);
    7705                 :             :       /* XXX void_type_node belies the abstraction.  */
    7706                 :     1050565 :       if (arg_type == void_type_node)
    7707                 :             :         break;
    7708                 :             : 
    7709                 :      732740 :       ++parmnum;
    7710                 :      732740 :       if (params->length () <= parmnum)
    7711                 :             :         {
    7712                 :          58 :           if (complain)
    7713                 :           7 :             error_at (loc, "too few arguments to function %qE", orig_function);
    7714                 :          58 :           return false;
    7715                 :             :         }
    7716                 :             : 
    7717                 :             :       /* Only convert parameters if arg_type is unsigned integer type with
    7718                 :             :          new format sync routines, i.e. don't attempt to convert pointer
    7719                 :             :          arguments (e.g. EXPECTED argument of __atomic_compare_exchange_n),
    7720                 :             :          bool arguments (e.g. WEAK argument) or signed int arguments (memmodel
    7721                 :             :          kinds).  */
    7722                 :      732682 :       if (TREE_CODE (arg_type) == INTEGER_TYPE && TYPE_UNSIGNED (arg_type))
    7723                 :             :         {
    7724                 :             :           /* Ideally for the first conversion we'd use convert_for_assignment
    7725                 :             :              so that we get warnings for anything that doesn't match the pointer
    7726                 :             :              type.  This isn't portable across the C and C++ front ends atm.  */
    7727                 :      203441 :           val = (*params)[parmnum];
    7728                 :      203441 :           val = convert (ptype, val);
    7729                 :      203441 :           val = convert (arg_type, val);
    7730                 :      203441 :           (*params)[parmnum] = val;
    7731                 :             :         }
    7732                 :             : 
    7733                 :      732682 :       function_args_iter_next (&iter);
    7734                 :      732682 :     }
    7735                 :             : 
    7736                 :             :   /* __atomic routines are not variadic.  */
    7737                 :      317825 :   if (!orig_format && params->length () != parmnum + 1)
    7738                 :             :     {
    7739                 :         106 :       if (complain)
    7740                 :         103 :         error_at (loc, "too many arguments to function %qE", orig_function);
    7741                 :         106 :       return false;
    7742                 :             :     }
    7743                 :             : 
    7744                 :             :   /* The definition of these primitives is variadic, with the remaining
    7745                 :             :      being "an optional list of variables protected by the memory barrier".
    7746                 :             :      No clue what that's supposed to mean, precisely, but we consider all
    7747                 :             :      call-clobbered variables to be protected so we're safe.  */
    7748                 :      317719 :   params->truncate (parmnum + 1);
    7749                 :             : 
    7750                 :      317719 :   return true;
    7751                 :             : }
    7752                 :             : 
    7753                 :             : /* A helper function for resolve_overloaded_builtin.  Adds a cast to
    7754                 :             :    RESULT to make it match the type of the first pointer argument in
    7755                 :             :    PARAMS.  */
    7756                 :             : 
    7757                 :             : static tree
    7758                 :      210206 : sync_resolve_return (tree first_param, tree result, bool orig_format)
    7759                 :             : {
    7760                 :      210206 :   tree ptype = TREE_TYPE (TREE_TYPE (first_param));
    7761                 :      210206 :   tree rtype = TREE_TYPE (result);
    7762                 :      210206 :   ptype = TYPE_MAIN_VARIANT (ptype);
    7763                 :             : 
    7764                 :             :   /* New format doesn't require casting unless the types are the same size.  */
    7765                 :      210206 :   if (orig_format || tree_int_cst_equal (TYPE_SIZE (ptype), TYPE_SIZE (rtype)))
    7766                 :      210206 :     return convert (ptype, result);
    7767                 :             :   else
    7768                 :             :     return result;
    7769                 :             : }
    7770                 :             : 
    7771                 :             : /* This function verifies the PARAMS to generic atomic FUNCTION.
    7772                 :             :    It returns the size if all the parameters are the same size, otherwise
    7773                 :             :    0 is returned if the parameters are invalid.  */
    7774                 :             : 
    7775                 :             : static int
    7776                 :       82290 : get_atomic_generic_size (location_t loc, tree function,
    7777                 :             :                          vec<tree, va_gc> *params, bool complain)
    7778                 :             : {
    7779                 :       82290 :   unsigned int n_param;
    7780                 :       82290 :   unsigned int n_model;
    7781                 :       82290 :   unsigned int outputs = 0; // bitset of output parameters
    7782                 :       82290 :   unsigned int x;
    7783                 :       82290 :   int size_0;
    7784                 :       82290 :   tree type_0;
    7785                 :             : 
    7786                 :             :   /* Determine the parameter makeup.  */
    7787                 :       82290 :   switch (DECL_FUNCTION_CODE (function))
    7788                 :             :     {
    7789                 :             :     case BUILT_IN_ATOMIC_EXCHANGE:
    7790                 :             :       n_param = 4;
    7791                 :             :       n_model = 1;
    7792                 :             :       outputs = 5;
    7793                 :             :       break;
    7794                 :       49439 :     case BUILT_IN_ATOMIC_LOAD:
    7795                 :       49439 :       n_param = 3;
    7796                 :       49439 :       n_model = 1;
    7797                 :       49439 :       outputs = 2;
    7798                 :       49439 :       break;
    7799                 :       11389 :     case BUILT_IN_ATOMIC_STORE:
    7800                 :       11389 :       n_param = 3;
    7801                 :       11389 :       n_model = 1;
    7802                 :       11389 :       outputs = 1;
    7803                 :       11389 :       break;
    7804                 :       20830 :     case BUILT_IN_ATOMIC_COMPARE_EXCHANGE:
    7805                 :       20830 :       n_param = 6;
    7806                 :       20830 :       n_model = 2;
    7807                 :       20830 :       outputs = 3;
    7808                 :       20830 :       break;
    7809                 :           0 :     default:
    7810                 :           0 :       gcc_unreachable ();
    7811                 :             :     }
    7812                 :             : 
    7813                 :       82290 :   if (vec_safe_length (params) != n_param)
    7814                 :             :     {
    7815                 :         466 :       if (complain)
    7816                 :         247 :         error_at (loc, "incorrect number of arguments to function %qE",
    7817                 :             :                   function);
    7818                 :         466 :       return 0;
    7819                 :             :     }
    7820                 :             : 
    7821                 :             :   /* Get type of first parameter, and determine its size.  */
    7822                 :       81824 :   type_0 = TREE_TYPE ((*params)[0]);
    7823                 :       81824 :   if (TREE_CODE (type_0) == ARRAY_TYPE && c_dialect_cxx ())
    7824                 :             :     {
    7825                 :             :       /* Force array-to-pointer decay for C++.  */
    7826                 :          15 :       (*params)[0] = default_conversion ((*params)[0]);
    7827                 :          15 :       type_0 = TREE_TYPE ((*params)[0]);
    7828                 :             :     }
    7829                 :       81824 :   if (TREE_CODE (type_0) != POINTER_TYPE || VOID_TYPE_P (TREE_TYPE (type_0)))
    7830                 :             :     {
    7831                 :         152 :       if (complain)
    7832                 :          41 :         error_at (loc, "argument 1 of %qE must be a non-void pointer type",
    7833                 :             :                   function);
    7834                 :         152 :       return 0;
    7835                 :             :     }
    7836                 :             : 
    7837                 :       81672 :   if (!COMPLETE_TYPE_P (TREE_TYPE (type_0)))
    7838                 :             :     {
    7839                 :          23 :       if (complain)
    7840                 :           8 :         error_at (loc, "argument 1 of %qE must be a pointer to a complete type",
    7841                 :             :                   function);
    7842                 :          23 :       return 0;
    7843                 :             :     }
    7844                 :             : 
    7845                 :             :   /* Types must be compile time constant sizes. */
    7846                 :       81649 :   if (!tree_fits_uhwi_p ((TYPE_SIZE_UNIT (TREE_TYPE (type_0)))))
    7847                 :             :     {
    7848                 :           1 :       if (complain)
    7849                 :           1 :         error_at (loc,
    7850                 :             :                   "argument 1 of %qE must be a pointer to a constant size type",
    7851                 :             :                   function);
    7852                 :           1 :       return 0;
    7853                 :             :     }
    7854                 :             : 
    7855                 :       81648 :   size_0 = tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type_0)));
    7856                 :             : 
    7857                 :             :   /* Zero size objects are not allowed.  */
    7858                 :       81648 :   if (size_0 == 0)
    7859                 :             :     {
    7860                 :          22 :       if (complain)
    7861                 :           7 :         error_at (
    7862                 :             :           loc, "argument 1 of %qE must be a pointer to a nonzero size object",
    7863                 :             :           function);
    7864                 :          22 :       return 0;
    7865                 :             :     }
    7866                 :             : 
    7867                 :             :   /* Check each other parameter is a pointer and the same size.  */
    7868                 :      286483 :   for (x = 0; x < n_param - n_model; x++)
    7869                 :             :     {
    7870                 :      204996 :       int size;
    7871                 :      204996 :       tree type = TREE_TYPE ((*params)[x]);
    7872                 :             :       /* __atomic_compare_exchange has a bool in the 4th position, skip it.  */
    7873                 :      204996 :       if (n_param == 6 && x == 3)
    7874                 :       20652 :         continue;
    7875                 :      184344 :       if (TREE_CODE (type) == ARRAY_TYPE && c_dialect_cxx ())
    7876                 :             :         {
    7877                 :             :           /* Force array-to-pointer decay for C++.  */
    7878                 :          18 :           (*params)[x] = default_conversion ((*params)[x]);
    7879                 :          18 :           type = TREE_TYPE ((*params)[x]);
    7880                 :             :         }
    7881                 :      184344 :       if (!POINTER_TYPE_P (type))
    7882                 :             :         {
    7883                 :          16 :           if (complain)
    7884                 :          13 :             error_at (loc, "argument %d of %qE must be a pointer type", x + 1,
    7885                 :             :                       function);
    7886                 :          16 :           return 0;
    7887                 :             :         }
    7888                 :      184328 :       else if (TYPE_SIZE_UNIT (TREE_TYPE (type))
    7889                 :      184328 :                && TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type))))
    7890                 :             :                   != INTEGER_CST)
    7891                 :             :         {
    7892                 :           1 :           if (complain)
    7893                 :           1 :             error_at (loc,
    7894                 :             :                       "argument %d of %qE must be a pointer to a constant "
    7895                 :             :                       "size type",
    7896                 :             :                       x + 1, function);
    7897                 :           1 :           return 0;
    7898                 :             :         }
    7899                 :      184327 :       else if (FUNCTION_POINTER_TYPE_P (type))
    7900                 :             :         {
    7901                 :          10 :           if (complain)
    7902                 :           7 :             error_at (loc,
    7903                 :             :                       "argument %d of %qE must not be a pointer to a "
    7904                 :             :                       "function",
    7905                 :             :                       x + 1, function);
    7906                 :          10 :           return 0;
    7907                 :             :         }
    7908                 :      184317 :       tree type_size = TYPE_SIZE_UNIT (TREE_TYPE (type));
    7909                 :      184317 :       size = type_size ? tree_to_uhwi (type_size) : 0;
    7910                 :      184317 :       if (size != size_0)
    7911                 :             :         {
    7912                 :          34 :           if (complain)
    7913                 :          25 :             error_at (loc, "size mismatch in argument %d of %qE", x + 1,
    7914                 :             :                       function);
    7915                 :          34 :           return 0;
    7916                 :             :         }
    7917                 :             : 
    7918                 :      184283 :       {
    7919                 :      184283 :         auto_diagnostic_group d;
    7920                 :      184283 :         int quals = TYPE_QUALS (TREE_TYPE (type));
    7921                 :             :         /* Must not write to an argument of a const-qualified type.  */
    7922                 :      184283 :         if (outputs & (1 << x) && quals & TYPE_QUAL_CONST)
    7923                 :             :           {
    7924                 :          57 :             if (c_dialect_cxx ())
    7925                 :             :               {
    7926                 :          45 :                 if (complain)
    7927                 :          42 :                   error_at (loc,
    7928                 :             :                             "argument %d of %qE must not be a pointer to "
    7929                 :             :                             "a %<const%> type",
    7930                 :             :                             x + 1, function);
    7931                 :          45 :                 return 0;
    7932                 :             :               }
    7933                 :             :             else
    7934                 :          12 :               pedwarn (loc, OPT_Wdiscarded_qualifiers, "argument %d "
    7935                 :             :                        "of %qE discards %<const%> qualifier", x + 1,
    7936                 :             :                        function);
    7937                 :             :           }
    7938                 :             :         /* Only the first argument is allowed to be volatile.  */
    7939                 :      184238 :         if (x > 0 && quals & TYPE_QUAL_VOLATILE)
    7940                 :             :           {
    7941                 :          44 :             if (c_dialect_cxx ())
    7942                 :             :               {
    7943                 :          33 :                 if (complain)
    7944                 :          30 :                   error_at (loc,
    7945                 :             :                             "argument %d of %qE must not be a pointer to "
    7946                 :             :                             "a %<volatile%> type",
    7947                 :             :                             x + 1, function);
    7948                 :          33 :                 return 0;
    7949                 :             :               }
    7950                 :             :             else
    7951                 :          11 :               pedwarn (loc, OPT_Wdiscarded_qualifiers, "argument %d "
    7952                 :             :                        "of %qE discards %<volatile%> qualifier", x + 1,
    7953                 :             :                        function);
    7954                 :             :           }
    7955                 :      184283 :       }
    7956                 :             :     }
    7957                 :             : 
    7958                 :             :   /* Check memory model parameters for validity.  */
    7959                 :      183610 :   for (x = n_param - n_model ; x < n_param; x++)
    7960                 :             :     {
    7961                 :      102139 :       tree p = (*params)[x];
    7962                 :      102139 :       if (!INTEGRAL_TYPE_P (TREE_TYPE (p)))
    7963                 :             :         {
    7964                 :          10 :           if (complain)
    7965                 :           7 :             error_at (loc, "non-integer memory model argument %d of %qE", x + 1,
    7966                 :             :                       function);
    7967                 :          10 :           return 0;
    7968                 :             :         }
    7969                 :      102129 :       p = fold_for_warn (p);
    7970                 :      102129 :       if (TREE_CODE (p) == INTEGER_CST)
    7971                 :             :         {
    7972                 :             :           /* memmodel_base masks the low 16 bits, thus ignore any bits above
    7973                 :             :              it by using TREE_INT_CST_LOW instead of tree_to_*hwi.  Those high
    7974                 :             :              bits will be checked later during expansion in target specific
    7975                 :             :              way.  */
    7976                 :       78722 :           if (memmodel_base (TREE_INT_CST_LOW (p)) >= MEMMODEL_LAST)
    7977                 :             :             {
    7978                 :          20 :               if (complain)
    7979                 :          14 :                 warning_at (loc, OPT_Winvalid_memory_model,
    7980                 :             :                             "invalid memory model argument %d of %qE", x + 1,
    7981                 :             :                             function);
    7982                 :             :               else
    7983                 :             :                 return 0;
    7984                 :             :             }
    7985                 :             :         }
    7986                 :             :     }
    7987                 :             : 
    7988                 :             :   return size_0;
    7989                 :             : }
    7990                 :             : 
    7991                 :             : 
    7992                 :             : /* This will take an __atomic_ generic FUNCTION call, and add a size parameter N
    7993                 :             :    at the beginning of the parameter list PARAMS representing the size of the
    7994                 :             :    objects.  This is to match the library ABI requirement.  LOC is the location
    7995                 :             :    of the function call.
    7996                 :             :    The new function is returned if it needed rebuilding, otherwise NULL_TREE is
    7997                 :             :    returned to allow the external call to be constructed.  */
    7998                 :             : 
    7999                 :             : static tree
    8000                 :        4146 : add_atomic_size_parameter (unsigned n, location_t loc, tree function,
    8001                 :             :                            vec<tree, va_gc> *params)
    8002                 :             : {
    8003                 :        4146 :   tree size_node;
    8004                 :             : 
    8005                 :             :   /* Insert a SIZE_T parameter as the first param.  If there isn't
    8006                 :             :      enough space, allocate a new vector and recursively re-build with that.  */
    8007                 :        4146 :   if (!params->space (1))
    8008                 :             :     {
    8009                 :          33 :       unsigned int z, len;
    8010                 :          33 :       vec<tree, va_gc> *v;
    8011                 :          33 :       tree f;
    8012                 :             : 
    8013                 :          33 :       len = params->length ();
    8014                 :          33 :       vec_alloc (v, len + 1);
    8015                 :          33 :       v->quick_push (build_int_cst (size_type_node, n));
    8016                 :         165 :       for (z = 0; z < len; z++)
    8017                 :         132 :         v->quick_push ((*params)[z]);
    8018                 :          33 :       f = build_function_call_vec (loc, vNULL, function, v, NULL);
    8019                 :          33 :       vec_free (v);
    8020                 :          33 :       return f;
    8021                 :             :     }
    8022                 :             : 
    8023                 :             :   /* Add the size parameter and leave as a function call for processing.  */
    8024                 :        4113 :   size_node = build_int_cst (size_type_node, n);
    8025                 :        4113 :   params->quick_insert (0, size_node);
    8026                 :        4113 :   return NULL_TREE;
    8027                 :             : }
    8028                 :             : 
    8029                 :             : 
    8030                 :             : /* Return whether atomic operations for naturally aligned N-byte
    8031                 :             :    arguments are supported, whether inline or through libatomic.  */
    8032                 :             : static bool
    8033                 :       81471 : atomic_size_supported_p (int n)
    8034                 :             : {
    8035                 :       81471 :   switch (n)
    8036                 :             :     {
    8037                 :             :     case 1:
    8038                 :             :     case 2:
    8039                 :             :     case 4:
    8040                 :             :     case 8:
    8041                 :             :       return true;
    8042                 :             : 
    8043                 :        6968 :     case 16:
    8044                 :        6968 :       return targetm.scalar_mode_supported_p (TImode);
    8045                 :             : 
    8046                 :        4146 :     default:
    8047                 :        4146 :       return false;
    8048                 :             :     }
    8049                 :             : }
    8050                 :             : 
    8051                 :             : /* This will process an __atomic_exchange function call, determine whether it
    8052                 :             :    needs to be mapped to the _N variation, or turned into a library call.
    8053                 :             :    LOC is the location of the builtin call.
    8054                 :             :    FUNCTION is the DECL that has been invoked;
    8055                 :             :    PARAMS is the argument list for the call.  The return value is non-null
    8056                 :             :    TRUE is returned if it is translated into the proper format for a call to the
    8057                 :             :    external library, and NEW_RETURN is set the tree for that function.
    8058                 :             :    FALSE is returned if processing for the _N variation is required, and
    8059                 :             :    NEW_RETURN is set to the return value the result is copied into.  */
    8060                 :             : static bool
    8061                 :         632 : resolve_overloaded_atomic_exchange (location_t loc, tree function,
    8062                 :             :                                     vec<tree, va_gc> *params, tree *new_return,
    8063                 :             :                                     bool complain)
    8064                 :             : {
    8065                 :         632 :   tree p0, p1, p2, p3;
    8066                 :         632 :   tree I_type, I_type_ptr;
    8067                 :         632 :   int n = get_atomic_generic_size (loc, function, params, complain);
    8068                 :             : 
    8069                 :             :   /* Size of 0 is an error condition.  */
    8070                 :         632 :   if (n == 0)
    8071                 :             :     {
    8072                 :         195 :       *new_return = error_mark_node;
    8073                 :         195 :       return true;
    8074                 :             :     }
    8075                 :             : 
    8076                 :             :   /* If not a lock-free size, change to the library generic format.  */
    8077                 :         437 :   if (!atomic_size_supported_p (n))
    8078                 :             :     {
    8079                 :          39 :       *new_return = add_atomic_size_parameter (n, loc, function, params);
    8080                 :          39 :       return true;
    8081                 :             :     }
    8082                 :             : 
    8083                 :             :   /* Otherwise there is a lockfree match, transform the call from:
    8084                 :             :        void fn(T* mem, T* desired, T* return, model)
    8085                 :             :      into
    8086                 :             :        *return = (T) (fn (In* mem, (In) *desired, model))  */
    8087                 :             : 
    8088                 :         398 :   p0 = (*params)[0];
    8089                 :         398 :   p1 = (*params)[1];
    8090                 :         398 :   p2 = (*params)[2];
    8091                 :         398 :   p3 = (*params)[3];
    8092                 :             : 
    8093                 :             :   /* Create pointer to appropriate size.  */
    8094                 :         398 :   I_type = builtin_type_for_size (BITS_PER_UNIT * n, 1);
    8095                 :         398 :   I_type_ptr = build_pointer_type (I_type);
    8096                 :             : 
    8097                 :             :   /* Convert object pointer to required type.  */
    8098                 :         398 :   p0 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p0);
    8099                 :         398 :   (*params)[0] = p0;
    8100                 :             :   /* Convert new value to required type, and dereference it.
    8101                 :             :      If *p1 type can have padding or may involve floating point which
    8102                 :             :      could e.g. be promoted to wider precision and demoted afterwards,
    8103                 :             :      state of padding bits might not be preserved.  */
    8104                 :         398 :   build_indirect_ref (loc, p1, RO_UNARY_STAR);
    8105                 :         398 :   p1 = build2_loc (loc, MEM_REF, I_type,
    8106                 :             :                    build1 (VIEW_CONVERT_EXPR, I_type_ptr, p1),
    8107                 :         398 :                    build_zero_cst (TREE_TYPE (p1)));
    8108                 :         398 :   (*params)[1] = p1;
    8109                 :             : 
    8110                 :             :   /* Move memory model to the 3rd position, and end param list.  */
    8111                 :         398 :   (*params)[2] = p3;
    8112                 :         398 :   params->truncate (3);
    8113                 :             : 
    8114                 :             :   /* Convert return pointer and dereference it for later assignment.  */
    8115                 :         398 :   *new_return = build_indirect_ref (loc, p2, RO_UNARY_STAR);
    8116                 :             : 
    8117                 :         398 :   return false;
    8118                 :             : }
    8119                 :             : 
    8120                 :             : /* This will process an __atomic_compare_exchange function call, determine
    8121                 :             :    whether it needs to be mapped to the _N variation, or turned into a lib call.
    8122                 :             :    LOC is the location of the builtin call.
    8123                 :             :    FUNCTION is the DECL that has been invoked;
    8124                 :             :    PARAMS is the argument list for the call.  The return value is non-null
    8125                 :             :    TRUE is returned if it is translated into the proper format for a call to the
    8126                 :             :    external library, and NEW_RETURN is set the tree for that function.
    8127                 :             :    FALSE is returned if processing for the _N variation is required.  */
    8128                 :             : 
    8129                 :             : static bool
    8130                 :       20830 : resolve_overloaded_atomic_compare_exchange (location_t loc, tree function,
    8131                 :             :                                             vec<tree, va_gc> *params,
    8132                 :             :                                             tree *new_return, bool complain)
    8133                 :             : {
    8134                 :       20830 :   tree p0, p1, p2;
    8135                 :       20830 :   tree I_type, I_type_ptr;
    8136                 :       20830 :   int n = get_atomic_generic_size (loc, function, params, complain);
    8137                 :             : 
    8138                 :             :   /* Size of 0 is an error condition.  */
    8139                 :       20830 :   if (n == 0)
    8140                 :             :     {
    8141                 :         178 :       *new_return = error_mark_node;
    8142                 :         178 :       return true;
    8143                 :             :     }
    8144                 :             : 
    8145                 :             :   /* If not a lock-free size, change to the library generic format.  */
    8146                 :       20652 :   if (!atomic_size_supported_p (n))
    8147                 :             :     {
    8148                 :             :       /* The library generic format does not have the weak parameter, so
    8149                 :             :          remove it from the param list.  Since a parameter has been removed,
    8150                 :             :          we can be sure that there is room for the SIZE_T parameter, meaning
    8151                 :             :          there will not be a recursive rebuilding of the parameter list, so
    8152                 :             :          there is no danger this will be done twice.  */
    8153                 :        1198 :       if (n > 0)
    8154                 :             :         {
    8155                 :        1198 :           (*params)[3] = (*params)[4];
    8156                 :        1198 :           (*params)[4] = (*params)[5];
    8157                 :        1198 :           params->truncate (5);
    8158                 :             :         }
    8159                 :        1198 :       *new_return = add_atomic_size_parameter (n, loc, function, params);
    8160                 :        1198 :       return true;
    8161                 :             :     }
    8162                 :             : 
    8163                 :             :   /* Otherwise, there is a match, so the call needs to be transformed from:
    8164                 :             :        bool fn(T* mem, T* desired, T* return, weak, success, failure)
    8165                 :             :      into
    8166                 :             :        bool fn ((In *)mem, (In *)expected, (In) *desired, weak, succ, fail)  */
    8167                 :             : 
    8168                 :       19454 :   p0 = (*params)[0];
    8169                 :       19454 :   p1 = (*params)[1];
    8170                 :       19454 :   p2 = (*params)[2];
    8171                 :             : 
    8172                 :             :   /* Create pointer to appropriate size.  */
    8173                 :       19454 :   I_type = builtin_type_for_size (BITS_PER_UNIT * n, 1);
    8174                 :       19454 :   I_type_ptr = build_pointer_type (I_type);
    8175                 :             : 
    8176                 :             :   /* Convert object pointer to required type.  */
    8177                 :       19454 :   p0 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p0);
    8178                 :       19454 :   (*params)[0] = p0;
    8179                 :             : 
    8180                 :             :   /* Convert expected pointer to required type.  */
    8181                 :       19454 :   p1 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p1);
    8182                 :       19454 :   (*params)[1] = p1;
    8183                 :             : 
    8184                 :             :   /* Convert desired value to required type, and dereference it.
    8185                 :             :      If *p2 type can have padding or may involve floating point which
    8186                 :             :      could e.g. be promoted to wider precision and demoted afterwards,
    8187                 :             :      state of padding bits might not be preserved.  */
    8188                 :       19454 :   build_indirect_ref (loc, p2, RO_UNARY_STAR);
    8189                 :       19454 :   p2 = build2_loc (loc, MEM_REF, I_type,
    8190                 :             :                    build1 (VIEW_CONVERT_EXPR, I_type_ptr, p2),
    8191                 :       19454 :                    build_zero_cst (TREE_TYPE (p2)));
    8192                 :       19454 :   (*params)[2] = p2;
    8193                 :             : 
    8194                 :             :   /* The rest of the parameters are fine. NULL means no special return value
    8195                 :             :      processing.*/
    8196                 :       19454 :   *new_return = NULL;
    8197                 :       19454 :   return false;
    8198                 :             : }
    8199                 :             : 
    8200                 :             : /* This will process an __atomic_load function call, determine whether it
    8201                 :             :    needs to be mapped to the _N variation, or turned into a library call.
    8202                 :             :    LOC is the location of the builtin call.
    8203                 :             :    FUNCTION is the DECL that has been invoked;
    8204                 :             :    PARAMS is the argument list for the call.  The return value is non-null
    8205                 :             :    TRUE is returned if it is translated into the proper format for a call to the
    8206                 :             :    external library, and NEW_RETURN is set the tree for that function.
    8207                 :             :    FALSE is returned if processing for the _N variation is required, and
    8208                 :             :    NEW_RETURN is set to the return value the result is copied into.  */
    8209                 :             : 
    8210                 :             : static bool
    8211                 :       49439 : resolve_overloaded_atomic_load (location_t loc, tree function,
    8212                 :             :                                 vec<tree, va_gc> *params, tree *new_return,
    8213                 :             :                                 bool complain)
    8214                 :             : {
    8215                 :       49439 :   tree p0, p1, p2;
    8216                 :       49439 :   tree I_type, I_type_ptr;
    8217                 :       49439 :   int n = get_atomic_generic_size (loc, function, params, complain);
    8218                 :             : 
    8219                 :             :   /* Size of 0 is an error condition.  */
    8220                 :       49439 :   if (n == 0)
    8221                 :             :     {
    8222                 :         278 :       *new_return = error_mark_node;
    8223                 :         278 :       return true;
    8224                 :             :     }
    8225                 :             : 
    8226                 :             :   /* If not a lock-free size, change to the library generic format.  */
    8227                 :       49161 :   if (!atomic_size_supported_p (n))
    8228                 :             :     {
    8229                 :        2499 :       *new_return = add_atomic_size_parameter (n, loc, function, params);
    8230                 :        2499 :       return true;
    8231                 :             :     }
    8232                 :             : 
    8233                 :             :   /* Otherwise, there is a match, so the call needs to be transformed from:
    8234                 :             :        void fn(T* mem, T* return, model)
    8235                 :             :      into
    8236                 :             :        *return = (T) (fn ((In *) mem, model))  */
    8237                 :             : 
    8238                 :       46662 :   p0 = (*params)[0];
    8239                 :       46662 :   p1 = (*params)[1];
    8240                 :       46662 :   p2 = (*params)[2];
    8241                 :             : 
    8242                 :             :   /* Create pointer to appropriate size.  */
    8243                 :       46662 :   I_type = builtin_type_for_size (BITS_PER_UNIT * n, 1);
    8244                 :       46662 :   I_type_ptr = build_pointer_type (I_type);
    8245                 :             : 
    8246                 :             :   /* Convert object pointer to required type.  */
    8247                 :       46662 :   p0 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p0);
    8248                 :       46662 :   (*params)[0] = p0;
    8249                 :             : 
    8250                 :             :   /* Move memory model to the 2nd position, and end param list.  */
    8251                 :       46662 :   (*params)[1] = p2;
    8252                 :       46662 :   params->truncate (2);
    8253                 :             : 
    8254                 :             :   /* Convert return pointer and dereference it for later assignment.  */
    8255                 :       46662 :   *new_return = build_indirect_ref (loc, p1, RO_UNARY_STAR);
    8256                 :             : 
    8257                 :       46662 :   return false;
    8258                 :             : }
    8259                 :             : 
    8260                 :             : /* This will process an __atomic_store function call, determine whether it
    8261                 :             :    needs to be mapped to the _N variation, or turned into a library call.
    8262                 :             :    LOC is the location of the builtin call.
    8263                 :             :    FUNCTION is the DECL that has been invoked;
    8264                 :             :    PARAMS is the argument list for the call.  The return value is non-null
    8265                 :             :    TRUE is returned if it is translated into the proper format for a call to the
    8266                 :             :    external library, and NEW_RETURN is set the tree for that function.
    8267                 :             :    FALSE is returned if processing for the _N variation is required, and
    8268                 :             :    NEW_RETURN is set to the return value the result is copied into.  */
    8269                 :             : 
    8270                 :             : static bool
    8271                 :       11389 : resolve_overloaded_atomic_store (location_t loc, tree function,
    8272                 :             :                                  vec<tree, va_gc> *params, tree *new_return,
    8273                 :             :                                  bool complain)
    8274                 :             : {
    8275                 :       11389 :   tree p0, p1;
    8276                 :       11389 :   tree I_type, I_type_ptr;
    8277                 :       11389 :   int n = get_atomic_generic_size (loc, function, params, complain);
    8278                 :             : 
    8279                 :             :   /* Size of 0 is an error condition.  */
    8280                 :       11389 :   if (n == 0)
    8281                 :             :     {
    8282                 :         168 :       *new_return = error_mark_node;
    8283                 :         168 :       return true;
    8284                 :             :     }
    8285                 :             : 
    8286                 :             :   /* If not a lock-free size, change to the library generic format.  */
    8287                 :       11221 :   if (!atomic_size_supported_p (n))
    8288                 :             :     {
    8289                 :         410 :       *new_return = add_atomic_size_parameter (n, loc, function, params);
    8290                 :         410 :       return true;
    8291                 :             :     }
    8292                 :             : 
    8293                 :             :   /* Otherwise, there is a match, so the call needs to be transformed from:
    8294                 :             :        void fn(T* mem, T* value, model)
    8295                 :             :      into
    8296                 :             :        fn ((In *) mem, (In) *value, model)  */
    8297                 :             : 
    8298                 :       10811 :   p0 = (*params)[0];
    8299                 :       10811 :   p1 = (*params)[1];
    8300                 :             : 
    8301                 :             :   /* Create pointer to appropriate size.  */
    8302                 :       10811 :   I_type = builtin_type_for_size (BITS_PER_UNIT * n, 1);
    8303                 :       10811 :   I_type_ptr = build_pointer_type (I_type);
    8304                 :             : 
    8305                 :             :   /* Convert object pointer to required type.  */
    8306                 :       10811 :   p0 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p0);
    8307                 :       10811 :   (*params)[0] = p0;
    8308                 :             : 
    8309                 :             :   /* Convert new value to required type, and dereference it.  */
    8310                 :       10811 :   p1 = build_indirect_ref (loc, p1, RO_UNARY_STAR);
    8311                 :       10811 :   p1 = build1 (VIEW_CONVERT_EXPR, I_type, p1);
    8312                 :       10811 :   (*params)[1] = p1;
    8313                 :             : 
    8314                 :             :   /* The memory model is in the right spot already. Return is void.  */
    8315                 :       10811 :   *new_return = NULL_TREE;
    8316                 :             : 
    8317                 :       10811 :   return false;
    8318                 :             : }
    8319                 :             : 
    8320                 :             : /* Emit __atomic*fetch* on _BitInt which doesn't have a size of
    8321                 :             :    1, 2, 4, 8 or 16 bytes using __atomic_compare_exchange loop.
    8322                 :             :    ORIG_CODE is the DECL_FUNCTION_CODE of ORIG_FUNCTION and
    8323                 :             :    ORIG_PARAMS arguments of the call.  */
    8324                 :             : 
    8325                 :             : static tree
    8326                 :         528 : atomic_bitint_fetch_using_cas_loop (location_t loc,
    8327                 :             :                                     enum built_in_function orig_code,
    8328                 :             :                                     tree orig_function,
    8329                 :             :                                     vec<tree, va_gc> *orig_params)
    8330                 :             : {
    8331                 :         528 :   enum tree_code code = ERROR_MARK;
    8332                 :         528 :   bool return_old_p = false;
    8333                 :         528 :   switch (orig_code)
    8334                 :             :     {
    8335                 :           0 :     case BUILT_IN_ATOMIC_ADD_FETCH_N:
    8336                 :           0 :       code = PLUS_EXPR;
    8337                 :           0 :       break;
    8338                 :           1 :     case BUILT_IN_ATOMIC_SUB_FETCH_N:
    8339                 :           1 :       code = MINUS_EXPR;
    8340                 :           1 :       break;
    8341                 :           0 :     case BUILT_IN_ATOMIC_AND_FETCH_N:
    8342                 :           0 :       code = BIT_AND_EXPR;
    8343                 :           0 :       break;
    8344                 :             :     case BUILT_IN_ATOMIC_NAND_FETCH_N:
    8345                 :             :       break;
    8346                 :           1 :     case BUILT_IN_ATOMIC_XOR_FETCH_N:
    8347                 :           1 :       code = BIT_XOR_EXPR;
    8348                 :           1 :       break;
    8349                 :           0 :     case BUILT_IN_ATOMIC_OR_FETCH_N:
    8350                 :           0 :       code = BIT_IOR_EXPR;
    8351                 :           0 :       break;
    8352                 :         106 :     case BUILT_IN_ATOMIC_FETCH_ADD_N:
    8353                 :         106 :       code = PLUS_EXPR;
    8354                 :         106 :       return_old_p = true;
    8355                 :         106 :       break;
    8356                 :         104 :     case BUILT_IN_ATOMIC_FETCH_SUB_N:
    8357                 :         104 :       code = MINUS_EXPR;
    8358                 :         104 :       return_old_p = true;
    8359                 :         104 :       break;
    8360                 :         105 :     case BUILT_IN_ATOMIC_FETCH_AND_N:
    8361                 :         105 :       code = BIT_AND_EXPR;
    8362                 :         105 :       return_old_p = true;
    8363                 :         105 :       break;
    8364                 :           0 :     case BUILT_IN_ATOMIC_FETCH_NAND_N:
    8365                 :           0 :       return_old_p = true;
    8366                 :           0 :       break;
    8367                 :         104 :     case BUILT_IN_ATOMIC_FETCH_XOR_N:
    8368                 :         104 :       code = BIT_XOR_EXPR;
    8369                 :         104 :       return_old_p = true;
    8370                 :         104 :       break;
    8371                 :         106 :     case BUILT_IN_ATOMIC_FETCH_OR_N:
    8372                 :         106 :       code = BIT_IOR_EXPR;
    8373                 :         106 :       return_old_p = true;
    8374                 :         106 :       break;
    8375                 :           0 :     default:
    8376                 :           0 :       gcc_unreachable ();
    8377                 :             :     }
    8378                 :             : 
    8379                 :         528 :   if (orig_params->length () != 3)
    8380                 :             :     {
    8381                 :           0 :       if (orig_params->length () < 3)
    8382                 :           0 :         error_at (loc, "too few arguments to function %qE", orig_function);
    8383                 :             :       else
    8384                 :           0 :         error_at (loc, "too many arguments to function %qE", orig_function);
    8385                 :           0 :       return error_mark_node;
    8386                 :             :     }
    8387                 :             : 
    8388                 :         528 :   tree stmts = push_stmt_list ();
    8389                 :             : 
    8390                 :         528 :   tree nonatomic_lhs_type = TREE_TYPE (TREE_TYPE ((*orig_params)[0]));
    8391                 :         528 :   nonatomic_lhs_type = TYPE_MAIN_VARIANT (nonatomic_lhs_type);
    8392                 :         528 :   gcc_assert (TREE_CODE (nonatomic_lhs_type) == BITINT_TYPE);
    8393                 :             : 
    8394                 :         528 :   tree lhs_addr = (*orig_params)[0];
    8395                 :         528 :   tree val = convert (nonatomic_lhs_type, (*orig_params)[1]);
    8396                 :         528 :   tree model = convert (integer_type_node, (*orig_params)[2]);
    8397                 :         528 :   if (!c_dialect_cxx ())
    8398                 :             :     {
    8399                 :         528 :       lhs_addr = c_fully_fold (lhs_addr, false, NULL);
    8400                 :         528 :       val = c_fully_fold (val, false, NULL);
    8401                 :         528 :       model = c_fully_fold (model, false, NULL);
    8402                 :             :     }
    8403                 :         528 :   if (TREE_SIDE_EFFECTS (lhs_addr))
    8404                 :             :     {
    8405                 :           1 :       tree var = create_tmp_var_raw (TREE_TYPE (lhs_addr));
    8406                 :           1 :       lhs_addr = build4 (TARGET_EXPR, TREE_TYPE (lhs_addr), var, lhs_addr,
    8407                 :             :                          NULL_TREE, NULL_TREE);
    8408                 :           1 :       add_stmt (lhs_addr);
    8409                 :             :     }
    8410                 :         528 :   if (TREE_SIDE_EFFECTS (val))
    8411                 :             :     {
    8412                 :           1 :       tree var = create_tmp_var_raw (nonatomic_lhs_type);
    8413                 :           1 :       val = build4 (TARGET_EXPR, nonatomic_lhs_type, var, val, NULL_TREE,
    8414                 :             :                     NULL_TREE);
    8415                 :           1 :       add_stmt (val);
    8416                 :             :     }
    8417                 :         528 :   if (TREE_SIDE_EFFECTS (model))
    8418                 :             :     {
    8419                 :           1 :       tree var = create_tmp_var_raw (integer_type_node);
    8420                 :           1 :       model = build4 (TARGET_EXPR, integer_type_node, var, model, NULL_TREE,
    8421                 :             :                       NULL_TREE);
    8422                 :           1 :       add_stmt (model);
    8423                 :             :     }
    8424                 :             : 
    8425                 :         528 :   tree old = create_tmp_var_raw (nonatomic_lhs_type);
    8426                 :         528 :   tree old_addr = build_unary_op (loc, ADDR_EXPR, old, false);
    8427                 :         528 :   TREE_ADDRESSABLE (old) = 1;
    8428                 :         528 :   suppress_warning (old);
    8429                 :             : 
    8430                 :         528 :   tree newval = create_tmp_var_raw (nonatomic_lhs_type);
    8431                 :         528 :   tree newval_addr = build_unary_op (loc, ADDR_EXPR, newval, false);
    8432                 :         528 :   TREE_ADDRESSABLE (newval) = 1;
    8433                 :         528 :   suppress_warning (newval);
    8434                 :             : 
    8435                 :         528 :   tree loop_decl = create_artificial_label (loc);
    8436                 :         528 :   tree loop_label = build1 (LABEL_EXPR, void_type_node, loop_decl);
    8437                 :             : 
    8438                 :         528 :   tree done_decl = create_artificial_label (loc);
    8439                 :         528 :   tree done_label = build1 (LABEL_EXPR, void_type_node, done_decl);
    8440                 :             : 
    8441                 :         528 :   vec<tree, va_gc> *params;
    8442                 :         528 :   vec_alloc (params, 6);
    8443                 :             : 
    8444                 :             :   /* __atomic_load (addr, &old, SEQ_CST).  */
    8445                 :         528 :   tree fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD);
    8446                 :         528 :   params->quick_push (lhs_addr);
    8447                 :         528 :   params->quick_push (old_addr);
    8448                 :         528 :   params->quick_push (build_int_cst (integer_type_node, MEMMODEL_RELAXED));
    8449                 :         528 :   tree func_call = resolve_overloaded_builtin (loc, fndecl, params);
    8450                 :         528 :   if (func_call == NULL_TREE)
    8451                 :         528 :     func_call = build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    8452                 :         528 :   old = build4 (TARGET_EXPR, nonatomic_lhs_type, old, func_call, NULL_TREE,
    8453                 :             :                 NULL_TREE);
    8454                 :         528 :   add_stmt (old);
    8455                 :         528 :   params->truncate (0);
    8456                 :             : 
    8457                 :             :   /* loop:  */
    8458                 :         528 :   add_stmt (loop_label);
    8459                 :             : 
    8460                 :             :   /* newval = old + val;  */
    8461                 :         528 :   tree rhs;
    8462                 :         528 :   switch (code)
    8463                 :             :     {
    8464                 :         211 :     case PLUS_EXPR:
    8465                 :         211 :     case MINUS_EXPR:
    8466                 :         211 :       if (!TYPE_OVERFLOW_WRAPS (nonatomic_lhs_type))
    8467                 :             :         {
    8468                 :         211 :           tree utype
    8469                 :         211 :             = build_bitint_type (TYPE_PRECISION (nonatomic_lhs_type), 1);
    8470                 :         211 :           rhs = convert (nonatomic_lhs_type,
    8471                 :             :                          build2_loc (loc, code, utype,
    8472                 :             :                                      convert (utype, old),
    8473                 :             :                                      convert (utype, val)));
    8474                 :             :         }
    8475                 :             :       else
    8476                 :           0 :         rhs = build2_loc (loc, code, nonatomic_lhs_type, old, val);
    8477                 :             :       break;
    8478                 :         316 :     case BIT_AND_EXPR:
    8479                 :         316 :     case BIT_IOR_EXPR:
    8480                 :         316 :     case BIT_XOR_EXPR:
    8481                 :         316 :       rhs = build2_loc (loc, code, nonatomic_lhs_type, old, val);
    8482                 :         316 :       break;
    8483                 :           1 :     case ERROR_MARK:
    8484                 :           1 :       rhs = build2_loc (loc, BIT_AND_EXPR, nonatomic_lhs_type,
    8485                 :             :                         build1_loc (loc, BIT_NOT_EXPR,
    8486                 :             :                                     nonatomic_lhs_type, old), val);
    8487                 :           1 :       break;
    8488                 :           0 :     default:
    8489                 :           0 :       gcc_unreachable ();
    8490                 :             :     }
    8491                 :         528 :   rhs = build4 (TARGET_EXPR, nonatomic_lhs_type, newval, rhs, NULL_TREE,
    8492                 :             :                 NULL_TREE);
    8493                 :         528 :   SET_EXPR_LOCATION (rhs, loc);
    8494                 :         528 :   add_stmt (rhs);
    8495                 :             : 
    8496                 :             :   /* if (__atomic_compare_exchange (addr, &old, &new, false, model, model))
    8497                 :             :        goto done;  */
    8498                 :         528 :   fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_COMPARE_EXCHANGE);
    8499                 :         528 :   params->quick_push (lhs_addr);
    8500                 :         528 :   params->quick_push (old_addr);
    8501                 :         528 :   params->quick_push (newval_addr);
    8502                 :         528 :   params->quick_push (integer_zero_node);
    8503                 :         528 :   params->quick_push (model);
    8504                 :         528 :   if (tree_fits_uhwi_p (model)
    8505                 :         527 :       && (tree_to_uhwi (model) == MEMMODEL_RELEASE
    8506                 :         447 :           || tree_to_uhwi (model) == MEMMODEL_ACQ_REL))
    8507                 :         129 :     params->quick_push (build_int_cst (integer_type_node, MEMMODEL_RELAXED));
    8508                 :             :   else
    8509                 :         399 :     params->quick_push (model);
    8510                 :         528 :   func_call = resolve_overloaded_builtin (loc, fndecl, params);
    8511                 :         528 :   if (func_call == NULL_TREE)
    8512                 :         528 :     func_call = build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    8513                 :             : 
    8514                 :         528 :   tree goto_stmt = build1 (GOTO_EXPR, void_type_node, done_decl);
    8515                 :         528 :   SET_EXPR_LOCATION (goto_stmt, loc);
    8516                 :             : 
    8517                 :         528 :   tree stmt
    8518                 :         528 :     = build3 (COND_EXPR, void_type_node, func_call, goto_stmt, NULL_TREE);
    8519                 :         528 :   SET_EXPR_LOCATION (stmt, loc);
    8520                 :         528 :   add_stmt (stmt);
    8521                 :             : 
    8522                 :             :   /* goto loop;  */
    8523                 :         528 :   goto_stmt = build1 (GOTO_EXPR, void_type_node, loop_decl);
    8524                 :         528 :   SET_EXPR_LOCATION (goto_stmt, loc);
    8525                 :         528 :   add_stmt (goto_stmt);
    8526                 :             : 
    8527                 :             :   /* done:  */
    8528                 :         528 :   add_stmt (done_label);
    8529                 :             : 
    8530                 :         528 :   tree ret = create_tmp_var_raw (nonatomic_lhs_type);
    8531                 :         531 :   stmt = build2_loc (loc, MODIFY_EXPR, void_type_node, ret,
    8532                 :             :                      return_old_p ? old : newval);
    8533                 :         528 :   add_stmt (stmt);
    8534                 :             : 
    8535                 :             :   /* Finish the compound statement.  */
    8536                 :         528 :   stmts = pop_stmt_list (stmts);
    8537                 :             : 
    8538                 :         528 :   return build4 (TARGET_EXPR, nonatomic_lhs_type, ret, stmts, NULL_TREE,
    8539                 :         528 :                  NULL_TREE);
    8540                 :             : }
    8541                 :             : 
    8542                 :             : 
    8543                 :             : /* Some builtin functions are placeholders for other expressions.  This
    8544                 :             :    function should be called immediately after parsing the call expression
    8545                 :             :    before surrounding code has committed to the type of the expression.
    8546                 :             : 
    8547                 :             :    LOC is the location of the builtin call.
    8548                 :             : 
    8549                 :             :    FUNCTION is the DECL that has been invoked; it is known to be a builtin.
    8550                 :             :    PARAMS is the argument list for the call.  The return value is non-null
    8551                 :             :    when expansion is complete, and null if normal processing should
    8552                 :             :    continue.  */
    8553                 :             : 
    8554                 :             : tree
    8555                 :    56943031 : resolve_overloaded_builtin (location_t loc, tree function,
    8556                 :             :                             vec<tree, va_gc> *params, bool complain)
    8557                 :             : {
    8558                 :             :   /* Is function one of the _FETCH_OP_ or _OP_FETCH_ built-ins?
    8559                 :             :      Those are not valid to call with a pointer to _Bool (or C++ bool)
    8560                 :             :      and so must be rejected.  */
    8561                 :    56943031 :   bool fetch_op = true;
    8562                 :    56943031 :   bool orig_format = true;
    8563                 :    56943031 :   tree new_return = NULL_TREE;
    8564                 :             : 
    8565                 :    56943031 :   switch (DECL_BUILT_IN_CLASS (function))
    8566                 :             :     {
    8567                 :     8729460 :     case BUILT_IN_NORMAL:
    8568                 :     8729460 :       break;
    8569                 :    32072523 :     case BUILT_IN_MD:
    8570                 :    32072523 :       if (targetm.resolve_overloaded_builtin)
    8571                 :           0 :         return targetm.resolve_overloaded_builtin (loc, function, params,
    8572                 :           0 :                                                    complain);
    8573                 :             :       else
    8574                 :             :         return NULL_TREE;
    8575                 :             :     default:
    8576                 :             :       return NULL_TREE;
    8577                 :             :     }
    8578                 :             : 
    8579                 :             :   /* Handle BUILT_IN_NORMAL here.  */
    8580                 :     8729460 :   enum built_in_function orig_code = DECL_FUNCTION_CODE (function);
    8581                 :     8729460 :   switch (orig_code)
    8582                 :             :     {
    8583                 :         155 :     case BUILT_IN_SPECULATION_SAFE_VALUE_N:
    8584                 :         155 :       {
    8585                 :         155 :         tree new_function, first_param, result;
    8586                 :         155 :         enum built_in_function fncode
    8587                 :         155 :           = speculation_safe_value_resolve_call (function, params, complain);
    8588                 :             : 
    8589                 :         155 :         if (fncode == BUILT_IN_NONE)
    8590                 :          52 :           return error_mark_node;
    8591                 :             : 
    8592                 :         103 :         first_param = (*params)[0];
    8593                 :         103 :         if (!speculation_safe_value_resolve_params (loc, function, params,
    8594                 :             :                                                     complain))
    8595                 :          31 :           return error_mark_node;
    8596                 :             : 
    8597                 :          72 :         if (targetm.have_speculation_safe_value (true))
    8598                 :             :           {
    8599                 :          72 :             new_function = builtin_decl_explicit (fncode);
    8600                 :          72 :             result = build_function_call_vec (loc, vNULL, new_function, params,
    8601                 :             :                                               NULL);
    8602                 :             : 
    8603                 :          72 :             if (result == error_mark_node)
    8604                 :             :               return result;
    8605                 :             : 
    8606                 :          72 :             return speculation_safe_value_resolve_return (first_param, result);
    8607                 :             :           }
    8608                 :             :         else
    8609                 :             :           {
    8610                 :             :             /* This target doesn't have, or doesn't need, active mitigation
    8611                 :             :                against incorrect speculative execution.  Simply return the
    8612                 :             :                first parameter to the builtin.  */
    8613                 :           0 :             if (!targetm.have_speculation_safe_value (false))
    8614                 :             :               {
    8615                 :           0 :                 if (complain)
    8616                 :             :                   /* The user has invoked __builtin_speculation_safe_value
    8617                 :             :                      even though __HAVE_SPECULATION_SAFE_VALUE is not
    8618                 :             :                      defined: emit a warning.  */
    8619                 :           0 :                   warning_at (
    8620                 :           0 :                     input_location, 0,
    8621                 :             :                     "this target does not define a speculation barrier; "
    8622                 :             :                     "your program will still execute correctly, "
    8623                 :             :                     "but incorrect speculation may not be "
    8624                 :             :                     "restricted");
    8625                 :             :                 else
    8626                 :           0 :                   return error_mark_node;
    8627                 :             :               }
    8628                 :             : 
    8629                 :             :             /* If the optional second argument is present, handle any side
    8630                 :             :                effects now.  */
    8631                 :           0 :             if (params->length () == 2
    8632                 :           0 :                 && TREE_SIDE_EFFECTS ((*params)[1]))
    8633                 :           0 :               return build2 (COMPOUND_EXPR, TREE_TYPE (first_param),
    8634                 :           0 :                              (*params)[1], first_param);
    8635                 :             : 
    8636                 :             :             return first_param;
    8637                 :             :           }
    8638                 :             :       }
    8639                 :             : 
    8640                 :       82290 :     case BUILT_IN_ATOMIC_EXCHANGE:
    8641                 :       82290 :     case BUILT_IN_ATOMIC_COMPARE_EXCHANGE:
    8642                 :       82290 :     case BUILT_IN_ATOMIC_LOAD:
    8643                 :       82290 :     case BUILT_IN_ATOMIC_STORE:
    8644                 :       82290 :       {
    8645                 :             :         /* Handle these 4 together so that they can fall through to the next
    8646                 :             :            case if the call is transformed to an _N variant.  */
    8647                 :       82290 :         switch (orig_code)
    8648                 :             :           {
    8649                 :         632 :           case BUILT_IN_ATOMIC_EXCHANGE:
    8650                 :         632 :             {
    8651                 :         632 :               if (resolve_overloaded_atomic_exchange (loc, function, params,
    8652                 :             :                                                       &new_return, complain))
    8653                 :         234 :                 return new_return;
    8654                 :             :               /* Change to the _N variant.  */
    8655                 :             :               orig_code = BUILT_IN_ATOMIC_EXCHANGE_N;
    8656                 :             :               break;
    8657                 :             :             }
    8658                 :             : 
    8659                 :       20830 :           case BUILT_IN_ATOMIC_COMPARE_EXCHANGE:
    8660                 :       20830 :             {
    8661                 :       20830 :               if (resolve_overloaded_atomic_compare_exchange (
    8662                 :             :                     loc, function, params, &new_return, complain))
    8663                 :        1376 :                 return new_return;
    8664                 :             :               /* Change to the _N variant.  */
    8665                 :             :               orig_code = BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N;
    8666                 :             :               break;
    8667                 :             :             }
    8668                 :       49439 :           case BUILT_IN_ATOMIC_LOAD:
    8669                 :       49439 :             {
    8670                 :       49439 :               if (resolve_overloaded_atomic_load (loc, function, params,
    8671                 :             :                                                   &new_return, complain))
    8672                 :        2777 :                 return new_return;
    8673                 :             :               /* Change to the _N variant.  */
    8674                 :             :               orig_code = BUILT_IN_ATOMIC_LOAD_N;
    8675                 :             :               break;
    8676                 :             :             }
    8677                 :       11389 :           case BUILT_IN_ATOMIC_STORE:
    8678                 :       11389 :             {
    8679                 :       11389 :               if (resolve_overloaded_atomic_store (loc, function, params,
    8680                 :             :                                                    &new_return, complain))
    8681                 :         578 :                 return new_return;
    8682                 :             :               /* Change to the _N variant.  */
    8683                 :             :               orig_code = BUILT_IN_ATOMIC_STORE_N;
    8684                 :             :               break;
    8685                 :             :             }
    8686                 :           0 :           default:
    8687                 :           0 :             gcc_unreachable ();
    8688                 :             :           }
    8689                 :             :       }
    8690                 :             :       /* FALLTHRU */
    8691                 :             :     case BUILT_IN_ATOMIC_EXCHANGE_N:
    8692                 :             :     case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N:
    8693                 :             :     case BUILT_IN_ATOMIC_LOAD_N:
    8694                 :             :     case BUILT_IN_ATOMIC_STORE_N:
    8695                 :             :       fetch_op = false;
    8696                 :             :       /* FALLTHRU */
    8697                 :             :     case BUILT_IN_ATOMIC_ADD_FETCH_N:
    8698                 :             :     case BUILT_IN_ATOMIC_SUB_FETCH_N:
    8699                 :             :     case BUILT_IN_ATOMIC_AND_FETCH_N:
    8700                 :             :     case BUILT_IN_ATOMIC_NAND_FETCH_N:
    8701                 :             :     case BUILT_IN_ATOMIC_XOR_FETCH_N:
    8702                 :             :     case BUILT_IN_ATOMIC_OR_FETCH_N:
    8703                 :             :     case BUILT_IN_ATOMIC_FETCH_ADD_N:
    8704                 :             :     case BUILT_IN_ATOMIC_FETCH_SUB_N:
    8705                 :             :     case BUILT_IN_ATOMIC_FETCH_AND_N:
    8706                 :             :     case BUILT_IN_ATOMIC_FETCH_NAND_N:
    8707                 :             :     case BUILT_IN_ATOMIC_FETCH_XOR_N:
    8708                 :             :     case BUILT_IN_ATOMIC_FETCH_OR_N:
    8709                 :             :       orig_format = false;
    8710                 :             :       /* FALLTHRU */
    8711                 :             :     case BUILT_IN_SYNC_FETCH_AND_ADD_N:
    8712                 :             :     case BUILT_IN_SYNC_FETCH_AND_SUB_N:
    8713                 :             :     case BUILT_IN_SYNC_FETCH_AND_OR_N:
    8714                 :             :     case BUILT_IN_SYNC_FETCH_AND_AND_N:
    8715                 :             :     case BUILT_IN_SYNC_FETCH_AND_XOR_N:
    8716                 :             :     case BUILT_IN_SYNC_FETCH_AND_NAND_N:
    8717                 :             :     case BUILT_IN_SYNC_ADD_AND_FETCH_N:
    8718                 :             :     case BUILT_IN_SYNC_SUB_AND_FETCH_N:
    8719                 :             :     case BUILT_IN_SYNC_OR_AND_FETCH_N:
    8720                 :             :     case BUILT_IN_SYNC_AND_AND_FETCH_N:
    8721                 :             :     case BUILT_IN_SYNC_XOR_AND_FETCH_N:
    8722                 :             :     case BUILT_IN_SYNC_NAND_AND_FETCH_N:
    8723                 :             :     case BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N:
    8724                 :             :     case BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N:
    8725                 :             :     case BUILT_IN_SYNC_LOCK_TEST_AND_SET_N:
    8726                 :             :     case BUILT_IN_SYNC_LOCK_RELEASE_N:
    8727                 :             :       {
    8728                 :             :         /* The following are not _FETCH_OPs and must be accepted with
    8729                 :             :            pointers to _Bool (or C++ bool).  */
    8730                 :             :         if (fetch_op)
    8731                 :       67663 :           fetch_op = (orig_code != BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
    8732                 :       67663 :                       && orig_code != BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N
    8733                 :       67177 :                       && orig_code != BUILT_IN_SYNC_LOCK_TEST_AND_SET_N
    8734                 :       67663 :                       && orig_code != BUILT_IN_SYNC_LOCK_RELEASE_N);
    8735                 :             : 
    8736                 :      321018 :         int n = sync_resolve_size (function, params, fetch_op, orig_format,
    8737                 :             :                                    complain);
    8738                 :      321018 :         tree new_function, first_param, result;
    8739                 :      321018 :         enum built_in_function fncode;
    8740                 :             : 
    8741                 :      321018 :         if (n == 0)
    8742                 :        2607 :           return error_mark_node;
    8743                 :             : 
    8744                 :      318411 :         if (n == -1)
    8745                 :             :           {
    8746                 :             :             /* complain is related to SFINAE context.
    8747                 :             :                _BitInt is not defined in C++, hence can't enter this clause
    8748                 :             :                with complain unset.  Even if at the abstraction level
    8749                 :             :                this complain is unset that still makes sense (whether
    8750                 :             :                this function should report an error or not if anything is
    8751                 :             :                wrong).
    8752                 :             :                Since can't test avoiding an error when this value is false not
    8753                 :             :                writing the code and instead asserting value is not set.  */
    8754                 :         528 :             gcc_assert (complain);
    8755                 :         528 :             return atomic_bitint_fetch_using_cas_loop (loc, orig_code, function,
    8756                 :         528 :                                                        params);
    8757                 :             :           }
    8758                 :             : 
    8759                 :      317883 :         fncode = (enum built_in_function)((int)orig_code + exact_log2 (n) + 1);
    8760                 :      317883 :         new_function = builtin_decl_explicit (fncode);
    8761                 :      317883 :         if (!sync_resolve_params (loc, function, new_function, params,
    8762                 :             :                                   orig_format, complain))
    8763                 :         164 :           return error_mark_node;
    8764                 :             : 
    8765                 :      317719 :         first_param = (*params)[0];
    8766                 :      317719 :         result = build_function_call_vec (loc, vNULL, new_function, params,
    8767                 :             :                                           NULL);
    8768                 :      317719 :         if (result == error_mark_node)
    8769                 :             :           return result;
    8770                 :      317707 :         if (orig_code != BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
    8771                 :      317707 :             && orig_code != BUILT_IN_SYNC_LOCK_RELEASE_N
    8772                 :      317400 :             && orig_code != BUILT_IN_ATOMIC_STORE_N
    8773                 :      317400 :             && orig_code != BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N)
    8774                 :      210206 :           result = sync_resolve_return (first_param, result, orig_format);
    8775                 :             : 
    8776                 :      317707 :         if (fetch_op)
    8777                 :             :           /* Prevent -Wunused-value warning.  */
    8778                 :       64158 :           TREE_USED (result) = true;
    8779                 :             : 
    8780                 :             :         /* If new_return is set, assign function to that expr and cast the
    8781                 :             :            result to void since the generic interface returned void.  */
    8782                 :      317707 :         if (new_return)
    8783                 :             :           {
    8784                 :             :             /* Cast function result from I{1,2,4,8,16} to the required type.  */
    8785                 :       47060 :             if (TREE_CODE (TREE_TYPE (new_return)) == BITINT_TYPE)
    8786                 :             :               {
    8787                 :         595 :                 struct bitint_info info;
    8788                 :         595 :                 unsigned prec = TYPE_PRECISION (TREE_TYPE (new_return));
    8789                 :         595 :                 targetm.c.bitint_type_info (prec, &info);
    8790                 :         595 :                 if (!info.extended)
    8791                 :             :                   /* For _BitInt which has the padding bits undefined
    8792                 :             :                      convert to the _BitInt type rather than VCE to force
    8793                 :             :                      zero or sign extension.  */
    8794                 :         595 :                   result = build1 (NOP_EXPR, TREE_TYPE (new_return), result);
    8795                 :             :               }
    8796                 :       47060 :             result
    8797                 :       47060 :               = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (new_return), result);
    8798                 :       47060 :             result = build2 (MODIFY_EXPR, TREE_TYPE (new_return), new_return,
    8799                 :             :                              result);
    8800                 :       47060 :             TREE_SIDE_EFFECTS (result) = 1;
    8801                 :       47060 :             protected_set_expr_location (result, loc);
    8802                 :       47060 :             result = convert (void_type_node, result);
    8803                 :             :           }
    8804                 :             :         return result;
    8805                 :             :       }
    8806                 :             : 
    8807                 :             :     default:
    8808                 :             :       return NULL_TREE;
    8809                 :             :     }
    8810                 :             : }
    8811                 :             : 
    8812                 :             : /* vector_types_compatible_elements_p is used in type checks of vectors
    8813                 :             :    values used as operands of binary operators.  Where it returns true, and
    8814                 :             :    the other checks of the caller succeed (being vector types in he first
    8815                 :             :    place, and matching number of elements), we can just treat the types
    8816                 :             :    as essentially the same.
    8817                 :             :    Contrast with vector_targets_convertible_p, which is used for vector
    8818                 :             :    pointer types,  and vector_types_convertible_p, which will allow
    8819                 :             :    language-specific matches under the control of flag_lax_vector_conversions,
    8820                 :             :    and might still require a conversion.  */
    8821                 :             : /* True if vector types T1 and T2 can be inputs to the same binary
    8822                 :             :    operator without conversion.
    8823                 :             :    We don't check the overall vector size here because some of our callers
    8824                 :             :    want to give different error messages when the vectors are compatible
    8825                 :             :    except for the element count.  */
    8826                 :             : 
    8827                 :             : bool
    8828                 :     1591676 : vector_types_compatible_elements_p (tree t1, tree t2)
    8829                 :             : {
    8830                 :     3183076 :   bool opaque = TYPE_VECTOR_OPAQUE (t1) || TYPE_VECTOR_OPAQUE (t2);
    8831                 :     1591676 :   t1 = TREE_TYPE (t1);
    8832                 :     1591676 :   t2 = TREE_TYPE (t2);
    8833                 :             : 
    8834                 :     1591676 :   enum tree_code c1 = TREE_CODE (t1), c2 = TREE_CODE (t2);
    8835                 :             : 
    8836                 :     1591676 :   gcc_assert ((INTEGRAL_TYPE_P (t1)
    8837                 :             :                || c1 == REAL_TYPE
    8838                 :             :                || c1 == FIXED_POINT_TYPE)
    8839                 :             :               && (INTEGRAL_TYPE_P (t2)
    8840                 :             :                   || c2 == REAL_TYPE
    8841                 :             :                   || c2 == FIXED_POINT_TYPE));
    8842                 :             : 
    8843                 :     1591676 :   t1 = c_common_signed_type (t1);
    8844                 :     1591676 :   t2 = c_common_signed_type (t2);
    8845                 :             :   /* Equality works here because c_common_signed_type uses
    8846                 :             :      TYPE_MAIN_VARIANT.  */
    8847                 :     1591676 :   if (t1 == t2)
    8848                 :             :     return true;
    8849                 :          31 :   if (opaque && c1 == c2
    8850                 :           4 :       && (INTEGRAL_TYPE_P (t1) || c1 == REAL_TYPE)
    8851                 :          35 :       && TYPE_PRECISION (t1) == TYPE_PRECISION (t2))
    8852                 :           4 :     return true;
    8853                 :             :   return false;
    8854                 :             : }
    8855                 :             : 
    8856                 :             : /* Check for missing format attributes on function pointers.  LTYPE is
    8857                 :             :    the new type or left-hand side type.  RTYPE is the old type or
    8858                 :             :    right-hand side type.  Returns TRUE if LTYPE is missing the desired
    8859                 :             :    attribute.  */
    8860                 :             : 
    8861                 :             : bool
    8862                 :        9890 : check_missing_format_attribute (tree ltype, tree rtype)
    8863                 :             : {
    8864                 :        9890 :   tree const ttr = TREE_TYPE (rtype), ttl = TREE_TYPE (ltype);
    8865                 :        9890 :   tree ra;
    8866                 :             : 
    8867                 :        9899 :   for (ra = TYPE_ATTRIBUTES (ttr); ra; ra = TREE_CHAIN (ra))
    8868                 :          73 :     if (is_attribute_p ("format", get_attribute_name (ra)))
    8869                 :             :       break;
    8870                 :        9890 :   if (ra)
    8871                 :             :     {
    8872                 :          64 :       tree la;
    8873                 :          64 :       for (la = TYPE_ATTRIBUTES (ttl); la; la = TREE_CHAIN (la))
    8874                 :          24 :         if (is_attribute_p ("format", get_attribute_name (la)))
    8875                 :             :           break;
    8876                 :          64 :       return !la;
    8877                 :             :     }
    8878                 :             :   else
    8879                 :             :     return false;
    8880                 :             : }
    8881                 :             : 
    8882                 :             : /* Setup a TYPE_DECL node as a typedef representation.
    8883                 :             : 
    8884                 :             :    X is a TYPE_DECL for a typedef statement.  Create a brand new
    8885                 :             :    ..._TYPE node (which will be just a variant of the existing
    8886                 :             :    ..._TYPE node with identical properties) and then install X
    8887                 :             :    as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
    8888                 :             : 
    8889                 :             :    The whole point here is to end up with a situation where each
    8890                 :             :    and every ..._TYPE node the compiler creates will be uniquely
    8891                 :             :    associated with AT MOST one node representing a typedef name.
    8892                 :             :    This way, even though the compiler substitutes corresponding
    8893                 :             :    ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
    8894                 :             :    early on, later parts of the compiler can always do the reverse
    8895                 :             :    translation and get back the corresponding typedef name.  For
    8896                 :             :    example, given:
    8897                 :             : 
    8898                 :             :         typedef struct S MY_TYPE;
    8899                 :             :         MY_TYPE object;
    8900                 :             : 
    8901                 :             :    Later parts of the compiler might only know that `object' was of
    8902                 :             :    type `struct S' if it were not for code just below.  With this
    8903                 :             :    code however, later parts of the compiler see something like:
    8904                 :             : 
    8905                 :             :         struct S' == struct S
    8906                 :             :         typedef struct S' MY_TYPE;
    8907                 :             :         struct S' object;
    8908                 :             : 
    8909                 :             :     And they can then deduce (from the node for type struct S') that
    8910                 :             :     the original object declaration was:
    8911                 :             : 
    8912                 :             :                 MY_TYPE object;
    8913                 :             : 
    8914                 :             :     Being able to do this is important for proper support of protoize,
    8915                 :             :     and also for generating precise symbolic debugging information
    8916                 :             :     which takes full account of the programmer's (typedef) vocabulary.
    8917                 :             : 
    8918                 :             :     Obviously, we don't want to generate a duplicate ..._TYPE node if
    8919                 :             :     the TYPE_DECL node that we are now processing really represents a
    8920                 :             :     standard built-in type.  */
    8921                 :             : 
    8922                 :             : void
    8923                 :   168449211 : set_underlying_type (tree x)
    8924                 :             : {
    8925                 :   168449211 :   if (x == error_mark_node || TREE_TYPE (x) == error_mark_node)
    8926                 :             :     return;
    8927                 :   168449183 :   if (DECL_IS_UNDECLARED_BUILTIN (x) && TREE_CODE (TREE_TYPE (x)) != ARRAY_TYPE)
    8928                 :             :     {
    8929                 :     6256376 :       if (TYPE_NAME (TREE_TYPE (x)) == 0)
    8930                 :     4997729 :         TYPE_NAME (TREE_TYPE (x)) = x;
    8931                 :             :     }
    8932                 :   162192807 :   else if (DECL_ORIGINAL_TYPE (x))
    8933                 :      163026 :     gcc_checking_assert (TYPE_NAME (TREE_TYPE (x)) == x);
    8934                 :             :   else
    8935                 :             :     {
    8936                 :   162029781 :       tree tt = TREE_TYPE (x);
    8937                 :   162029781 :       DECL_ORIGINAL_TYPE (x) = tt;
    8938                 :   162029781 :       tt = build_variant_type_copy (tt);
    8939                 :   162029781 :       TYPE_STUB_DECL (tt) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x));
    8940                 :   162029781 :       TYPE_NAME (tt) = x;
    8941                 :             : 
    8942                 :             :       /* Mark the type as used only when its type decl is decorated
    8943                 :             :          with attribute unused.  */
    8944                 :   162029781 :       if (lookup_attribute ("unused", DECL_ATTRIBUTES (x)))
    8945                 :         252 :         TREE_USED (tt) = 1;
    8946                 :             : 
    8947                 :   162029781 :       TREE_TYPE (x) = tt;
    8948                 :             :     }
    8949                 :             : }
    8950                 :             : 
    8951                 :             : /* Return true if it is worth exposing the DECL_ORIGINAL_TYPE of TYPE to
    8952                 :             :    the user in diagnostics, false if it would be better to use TYPE itself.
    8953                 :             :    TYPE is known to satisfy typedef_variant_p.  */
    8954                 :             : 
    8955                 :             : bool
    8956                 :       31068 : user_facing_original_type_p (const_tree type)
    8957                 :             : {
    8958                 :       31068 :   gcc_assert (typedef_variant_p (type));
    8959                 :       31068 :   tree decl = TYPE_NAME (type);
    8960                 :             : 
    8961                 :             :   /* Look through any typedef in "user" code.  */
    8962                 :       31068 :   if (!DECL_IN_SYSTEM_HEADER (decl) && !DECL_IS_UNDECLARED_BUILTIN (decl))
    8963                 :             :     return true;
    8964                 :             : 
    8965                 :             :   /* If the original type is also named and is in the user namespace,
    8966                 :             :      assume it too is a user-facing type.  */
    8967                 :        1565 :   tree orig_type = DECL_ORIGINAL_TYPE (decl);
    8968                 :        1565 :   if (tree orig_id = TYPE_IDENTIFIER (orig_type))
    8969                 :        1437 :     if (!name_reserved_for_implementation_p (IDENTIFIER_POINTER (orig_id)))
    8970                 :             :       return true;
    8971                 :             : 
    8972                 :         710 :   switch (TREE_CODE (orig_type))
    8973                 :             :     {
    8974                 :             :     /* Don't look through to an anonymous vector type, since the syntax
    8975                 :             :        we use for them in diagnostics isn't real C or C++ syntax.
    8976                 :             :        And if ORIG_TYPE is named but in the implementation namespace,
    8977                 :             :        TYPE is likely to be more meaningful to the user.  */
    8978                 :             :     case VECTOR_TYPE:
    8979                 :             :       return false;
    8980                 :             : 
    8981                 :             :     /* Don't expose anonymous tag types that are presumably meant to be
    8982                 :             :        known by their typedef name.  Also don't expose tags that are in
    8983                 :             :        the implementation namespace, such as:
    8984                 :             : 
    8985                 :             :          typedef struct __foo foo;  */
    8986                 :             :     case RECORD_TYPE:
    8987                 :             :     case UNION_TYPE:
    8988                 :             :     case ENUMERAL_TYPE:
    8989                 :             :       return false;
    8990                 :             : 
    8991                 :             :     /* Look through to anything else.  */
    8992                 :             :     default:
    8993                 :             :       return true;
    8994                 :             :     }
    8995                 :             : }
    8996                 :             : 
    8997                 :             : /* Record the types used by the current global variable declaration
    8998                 :             :    being parsed, so that we can decide later to emit their debug info.
    8999                 :             :    Those types are in types_used_by_cur_var_decl, and we are going to
    9000                 :             :    store them in the types_used_by_vars_hash hash table.
    9001                 :             :    DECL is the declaration of the global variable that has been parsed.  */
    9002                 :             : 
    9003                 :             : void
    9004                 :    22230193 : record_types_used_by_current_var_decl (tree decl)
    9005                 :             : {
    9006                 :    22230193 :   gcc_assert (decl && DECL_P (decl) && TREE_STATIC (decl));
    9007                 :             : 
    9008                 :    43328922 :   while (types_used_by_cur_var_decl && !types_used_by_cur_var_decl->is_empty ())
    9009                 :             :     {
    9010                 :    21098729 :       tree type = types_used_by_cur_var_decl->pop ();
    9011                 :    21098729 :       types_used_by_var_decl_insert (type, decl);
    9012                 :             :     }
    9013                 :    22230193 : }
    9014                 :             : 
    9015                 :             : /* The C and C++ parsers both use vectors to hold function arguments.
    9016                 :             :    For efficiency, we keep a cache of unused vectors.  This is the
    9017                 :             :    cache.  */
    9018                 :             : 
    9019                 :             : typedef vec<tree, va_gc> *tree_gc_vec;
    9020                 :             : static GTY((deletable)) vec<tree_gc_vec, va_gc> *tree_vector_cache;
    9021                 :             : 
    9022                 :             : /* Return a new vector from the cache.  If the cache is empty,
    9023                 :             :    allocate a new vector.  These vectors are GC'ed, so it is OK if the
    9024                 :             :    pointer is not released..  */
    9025                 :             : 
    9026                 :             : vec<tree, va_gc> *
    9027                 :  1005639208 : make_tree_vector (void)
    9028                 :             : {
    9029                 :  1005639208 :   if (tree_vector_cache && !tree_vector_cache->is_empty ())
    9030                 :   978412484 :     return tree_vector_cache->pop ();
    9031                 :             :   else
    9032                 :             :     {
    9033                 :             :       /* Passing 0 to vec::alloc returns NULL, and our callers require
    9034                 :             :          that we always return a non-NULL value.  The vector code uses
    9035                 :             :          4 when growing a NULL vector, so we do too.  */
    9036                 :    27226724 :       vec<tree, va_gc> *v;
    9037                 :    27226724 :       vec_alloc (v, 4);
    9038                 :    27226724 :       return v;
    9039                 :             :     }
    9040                 :             : }
    9041                 :             : 
    9042                 :             : /* Release a vector of trees back to the cache.  */
    9043                 :             : 
    9044                 :             : void
    9045                 :  1350528047 : release_tree_vector (vec<tree, va_gc> *vec)
    9046                 :             : {
    9047                 :  1350528047 :   if (vec != NULL)
    9048                 :             :     {
    9049                 :   979844180 :       if (vec->allocated () >= 16)
    9050                 :             :         /* Don't cache vecs that have expanded more than once.  On a p64
    9051                 :             :            target, vecs double in alloc size with each power of 2 elements, e.g
    9052                 :             :            at 16 elements the alloc increases from 128 to 256 bytes.  */
    9053                 :      650720 :         vec_free (vec);
    9054                 :             :       else
    9055                 :             :         {
    9056                 :   979193460 :           vec->truncate (0);
    9057                 :   979193460 :           vec_safe_push (tree_vector_cache, vec);
    9058                 :             :         }
    9059                 :             :     }
    9060                 :  1350528047 : }
    9061                 :             : 
    9062                 :             : /* Get a new tree vector holding a single tree.  */
    9063                 :             : 
    9064                 :             : vec<tree, va_gc> *
    9065                 :    48159096 : make_tree_vector_single (tree t)
    9066                 :             : {
    9067                 :    48159096 :   vec<tree, va_gc> *ret = make_tree_vector ();
    9068                 :    48159096 :   ret->quick_push (t);
    9069                 :    48159096 :   return ret;
    9070                 :             : }
    9071                 :             : 
    9072                 :             : /* Get a new tree vector of the TREE_VALUEs of a TREE_LIST chain.  */
    9073                 :             : 
    9074                 :             : vec<tree, va_gc> *
    9075                 :        4666 : make_tree_vector_from_list (tree list)
    9076                 :             : {
    9077                 :        4666 :   vec<tree, va_gc> *ret = make_tree_vector ();
    9078                 :       13378 :   for (; list; list = TREE_CHAIN (list))
    9079                 :        8712 :     vec_safe_push (ret, TREE_VALUE (list));
    9080                 :        4666 :   return ret;
    9081                 :             : }
    9082                 :             : 
    9083                 :             : /* Append to a tree vector V the values of a CONSTRUCTOR CTOR
    9084                 :             :    and return the new possibly reallocated vector.  */
    9085                 :             : 
    9086                 :             : vec<tree, va_gc> *
    9087                 :     1359784 : append_ctor_to_tree_vector (vec<tree, va_gc> *v, tree ctor)
    9088                 :             : {
    9089                 :     2564640 :   unsigned nelts = vec_safe_length (v) + CONSTRUCTOR_NELTS (ctor);
    9090                 :     1359784 :   vec_safe_reserve (v, CONSTRUCTOR_NELTS (ctor));
    9091                 :     3374131 :   for (unsigned i = 0; i < CONSTRUCTOR_NELTS (ctor); ++i)
    9092                 :     2014347 :     if (TREE_CODE (CONSTRUCTOR_ELT (ctor, i)->value) == RAW_DATA_CST)
    9093                 :             :       {
    9094                 :          24 :         tree raw_data = CONSTRUCTOR_ELT (ctor, i)->value;
    9095                 :          24 :         nelts += RAW_DATA_LENGTH (raw_data) - 1;
    9096                 :          24 :         vec_safe_reserve (v, nelts - v->length ());
    9097                 :          48 :         if (TYPE_PRECISION (TREE_TYPE (raw_data)) > CHAR_BIT
    9098                 :          24 :             || TYPE_UNSIGNED (TREE_TYPE (raw_data)))
    9099                 :        6264 :           for (unsigned j = 0; j < (unsigned) RAW_DATA_LENGTH (raw_data); ++j)
    9100                 :        6240 :             v->quick_push (build_int_cst (TREE_TYPE (raw_data),
    9101                 :        6240 :                                           RAW_DATA_UCHAR_ELT (raw_data, j)));
    9102                 :             :         else
    9103                 :           0 :           for (unsigned j = 0; j < (unsigned) RAW_DATA_LENGTH (raw_data); ++j)
    9104                 :           0 :             v->quick_push (build_int_cst (TREE_TYPE (raw_data),
    9105                 :           0 :                                           RAW_DATA_SCHAR_ELT (raw_data, j)));
    9106                 :             :       }
    9107                 :             :     else
    9108                 :     2014323 :       v->quick_push (CONSTRUCTOR_ELT (ctor, i)->value);
    9109                 :     1359784 :   return v;
    9110                 :             : }
    9111                 :             : 
    9112                 :             : /* Get a new tree vector of the values of a CONSTRUCTOR.  */
    9113                 :             : 
    9114                 :             : vec<tree, va_gc> *
    9115                 :        4769 : make_tree_vector_from_ctor (tree ctor)
    9116                 :             : {
    9117                 :        4769 :   vec<tree,va_gc> *ret
    9118                 :        4769 :     = CONSTRUCTOR_NELTS (ctor) <= 16 ? make_tree_vector () : NULL;
    9119                 :        4769 :   return append_ctor_to_tree_vector (ret, ctor);
    9120                 :             : }
    9121                 :             : 
    9122                 :             : /* Get a new tree vector which is a copy of an existing one.  */
    9123                 :             : 
    9124                 :             : vec<tree, va_gc> *
    9125                 :    28177075 : make_tree_vector_copy (const vec<tree, va_gc> *orig)
    9126                 :             : {
    9127                 :    28177075 :   vec<tree, va_gc> *ret;
    9128                 :    28177075 :   unsigned int ix;
    9129                 :    28177075 :   tree t;
    9130                 :             : 
    9131                 :    28177075 :   ret = make_tree_vector ();
    9132                 :    28177075 :   vec_safe_reserve (ret, vec_safe_length (orig));
    9133                 :    68381332 :   FOR_EACH_VEC_SAFE_ELT (orig, ix, t)
    9134                 :    12027182 :     ret->quick_push (t);
    9135                 :    28177075 :   return ret;
    9136                 :             : }
    9137                 :             : 
    9138                 :             : /* Return true if KEYWORD starts a type specifier.  */
    9139                 :             : 
    9140                 :             : bool
    9141                 :          16 : keyword_begins_type_specifier (enum rid keyword)
    9142                 :             : {
    9143                 :          16 :   switch (keyword)
    9144                 :             :     {
    9145                 :             :     case RID_AUTO_TYPE:
    9146                 :             :     case RID_INT:
    9147                 :             :     case RID_CHAR:
    9148                 :             :     case RID_FLOAT:
    9149                 :             :     case RID_DOUBLE:
    9150                 :             :     case RID_VOID:
    9151                 :             :     case RID_UNSIGNED:
    9152                 :             :     case RID_LONG:
    9153                 :             :     case RID_SHORT:
    9154                 :             :     case RID_SIGNED:
    9155                 :             :     CASE_RID_FLOATN_NX:
    9156                 :             :     case RID_DFLOAT32:
    9157                 :             :     case RID_DFLOAT64:
    9158                 :             :     case RID_DFLOAT128:
    9159                 :             :     case RID_FRACT:
    9160                 :             :     case RID_ACCUM:
    9161                 :             :     case RID_BOOL:
    9162                 :             :     case RID_BITINT:
    9163                 :             :     case RID_WCHAR:
    9164                 :             :     case RID_CHAR8:
    9165                 :             :     case RID_CHAR16:
    9166                 :             :     case RID_CHAR32:
    9167                 :             :     case RID_SAT:
    9168                 :             :     case RID_COMPLEX:
    9169                 :             :     case RID_TYPEOF:
    9170                 :             :     case RID_STRUCT:
    9171                 :             :     case RID_CLASS:
    9172                 :             :     case RID_UNION:
    9173                 :             :     case RID_ENUM:
    9174                 :             :       return true;
    9175                 :           1 :     default:
    9176                 :           1 :       if (keyword >= RID_FIRST_INT_N
    9177                 :             :           && keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS
    9178                 :           0 :           && int_n_enabled_p[keyword-RID_FIRST_INT_N])
    9179                 :             :         return true;
    9180                 :             :       return false;
    9181                 :             :     }
    9182                 :             : }
    9183                 :             : 
    9184                 :             : /* Return true if KEYWORD names a type qualifier.  */
    9185                 :             : 
    9186                 :             : bool
    9187                 :       11684 : keyword_is_type_qualifier (enum rid keyword)
    9188                 :             : {
    9189                 :       11684 :   switch (keyword)
    9190                 :             :     {
    9191                 :             :     case RID_CONST:
    9192                 :             :     case RID_VOLATILE:
    9193                 :             :     case RID_RESTRICT:
    9194                 :             :     case RID_ATOMIC:
    9195                 :             :       return true;
    9196                 :          55 :     default:
    9197                 :          55 :       return false;
    9198                 :             :     }
    9199                 :             : }
    9200                 :             : 
    9201                 :             : /* Return true if KEYWORD names a storage class specifier.
    9202                 :             : 
    9203                 :             :    RID_TYPEDEF is not included in this list despite `typedef' being
    9204                 :             :    listed in C99 6.7.1.1.  6.7.1.3 indicates that `typedef' is listed as
    9205                 :             :    such for syntactic convenience only.  */
    9206                 :             : 
    9207                 :             : bool
    9208                 :       11710 : keyword_is_storage_class_specifier (enum rid keyword)
    9209                 :             : {
    9210                 :       11710 :   switch (keyword)
    9211                 :             :     {
    9212                 :             :     case RID_STATIC:
    9213                 :             :     case RID_EXTERN:
    9214                 :             :     case RID_REGISTER:
    9215                 :             :     case RID_AUTO:
    9216                 :             :     case RID_MUTABLE:
    9217                 :             :     case RID_THREAD:
    9218                 :             :       return true;
    9219                 :       11684 :     default:
    9220                 :       11684 :       return false;
    9221                 :             :     }
    9222                 :             : }
    9223                 :             : 
    9224                 :             : /* Return true if KEYWORD names a function-specifier [dcl.fct.spec].  */
    9225                 :             : 
    9226                 :             : static bool
    9227                 :          55 : keyword_is_function_specifier (enum rid keyword)
    9228                 :             : {
    9229                 :          55 :   switch (keyword)
    9230                 :             :     {
    9231                 :             :     case RID_INLINE:
    9232                 :             :     case RID_NORETURN:
    9233                 :             :     case RID_VIRTUAL:
    9234                 :             :     case RID_EXPLICIT:
    9235                 :             :       return true;
    9236                 :          53 :     default:
    9237                 :           0 :       return false;
    9238                 :             :     }
    9239                 :             : }
    9240                 :             : 
    9241                 :             : /* Return true if KEYWORD names a decl-specifier [dcl.spec] or a
    9242                 :             :    declaration-specifier (C99 6.7).  */
    9243                 :             : 
    9244                 :             : bool
    9245                 :       11710 : keyword_is_decl_specifier (enum rid keyword)
    9246                 :             : {
    9247                 :       11710 :   if (keyword_is_storage_class_specifier (keyword)
    9248                 :       11684 :       || keyword_is_type_qualifier (keyword)
    9249                 :       11710 :       || keyword_is_function_specifier (keyword))
    9250                 :       11657 :     return true;
    9251                 :             : 
    9252                 :          53 :   switch (keyword)
    9253                 :             :     {
    9254                 :             :     case RID_TYPEDEF:
    9255                 :             :     case RID_FRIEND:
    9256                 :             :     case RID_CONSTEXPR:
    9257                 :             :     case RID_CONSTINIT:
    9258                 :             :       return true;
    9259                 :             :     default:
    9260                 :             :       return false;
    9261                 :             :     }
    9262                 :             : }
    9263                 :             : 
    9264                 :             : /* Initialize language-specific-bits of tree_contains_struct.  */
    9265                 :             : 
    9266                 :             : void
    9267                 :      206544 : c_common_init_ts (void)
    9268                 :             : {
    9269                 :      206544 :   MARK_TS_EXP (SIZEOF_EXPR);
    9270                 :      206544 :   MARK_TS_EXP (PAREN_SIZEOF_EXPR);
    9271                 :      206544 :   MARK_TS_EXP (C_MAYBE_CONST_EXPR);
    9272                 :      206544 :   MARK_TS_EXP (EXCESS_PRECISION_EXPR);
    9273                 :      206544 :   MARK_TS_EXP (BREAK_STMT);
    9274                 :      206544 :   MARK_TS_EXP (CONTINUE_STMT);
    9275                 :      206544 :   MARK_TS_EXP (DO_STMT);
    9276                 :      206544 :   MARK_TS_EXP (FOR_STMT);
    9277                 :      206544 :   MARK_TS_EXP (SWITCH_STMT);
    9278                 :      206544 :   MARK_TS_EXP (WHILE_STMT);
    9279                 :             : 
    9280                 :      206544 :   MARK_TS_DECL_COMMON (CONCEPT_DECL);
    9281                 :      206544 : }
    9282                 :             : 
    9283                 :             : /* Build a user-defined numeric literal out of an integer constant type VALUE
    9284                 :             :    with identifier SUFFIX.  */
    9285                 :             : 
    9286                 :             : tree
    9287                 :      925531 : build_userdef_literal (tree suffix_id, tree value,
    9288                 :             :                        enum overflow_type overflow, tree num_string)
    9289                 :             : {
    9290                 :      925531 :   tree literal = make_node (USERDEF_LITERAL);
    9291                 :      925531 :   USERDEF_LITERAL_SUFFIX_ID (literal) = suffix_id;
    9292                 :      925531 :   USERDEF_LITERAL_VALUE (literal) = value;
    9293                 :      925531 :   USERDEF_LITERAL_OVERFLOW (literal) = overflow;
    9294                 :      925531 :   USERDEF_LITERAL_NUM_STRING (literal) = num_string;
    9295                 :      925531 :   return literal;
    9296                 :             : }
    9297                 :             : 
    9298                 :             : /* For vector[index], convert the vector to an array of the underlying type.
    9299                 :             :    Return true if the resulting ARRAY_REF should not be an lvalue.  */
    9300                 :             : 
    9301                 :             : bool
    9302                 :     8638441 : convert_vector_to_array_for_subscript (location_t loc,
    9303                 :             :                                        tree *vecp, tree index)
    9304                 :             : {
    9305                 :     8638441 :   bool ret = false;
    9306                 :     8638441 :   if (gnu_vector_type_p (TREE_TYPE (*vecp)))
    9307                 :             :     {
    9308                 :     1036890 :       tree type = TREE_TYPE (*vecp);
    9309                 :     1036890 :       tree newitype;
    9310                 :             : 
    9311                 :     1036890 :       ret = !lvalue_p (*vecp);
    9312                 :             : 
    9313                 :     1036890 :       index = fold_for_warn (index);
    9314                 :             :       /* Warn out-of-bounds index for vectors only if known.  */
    9315                 :     1036890 :       if (poly_int_tree_p (index))
    9316                 :     1024093 :         if (!tree_fits_poly_uint64_p (index)
    9317                 :     1024093 :             || known_ge (tree_to_poly_uint64 (index),
    9318                 :             :                           TYPE_VECTOR_SUBPARTS (type)))
    9319                 :          82 :             warning_at (loc, OPT_Warray_bounds_, "index value is out of bound");
    9320                 :             : 
    9321                 :             :       /* We are building an ARRAY_REF so mark the vector as addressable
    9322                 :             :          to not run into the gimplifiers premature setting of DECL_GIMPLE_REG_P
    9323                 :             :          for function parameters.  */
    9324                 :     1036890 :       c_common_mark_addressable_vec (*vecp);
    9325                 :             : 
    9326                 :             :       /* Make sure qualifiers are copied from the vector type to the new element
    9327                 :             :          of the array type.  */
    9328                 :     1036890 :       newitype = build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
    9329                 :             : 
    9330                 :     1036890 :       *vecp = build1 (VIEW_CONVERT_EXPR,
    9331                 :             :                       build_array_type_nelts (newitype,
    9332                 :             :                                               TYPE_VECTOR_SUBPARTS (type)),
    9333                 :             :                       *vecp);
    9334                 :             :     }
    9335                 :     8638441 :   return ret;
    9336                 :             : }
    9337                 :             : 
    9338                 :             : /* Determine which of the operands, if any, is a scalar that needs to be
    9339                 :             :    converted to a vector, for the range of operations.  */
    9340                 :             : enum stv_conv
    9341                 :        3418 : scalar_to_vector (location_t loc, enum tree_code code, tree op0, tree op1,
    9342                 :             :                   bool complain)
    9343                 :             : {
    9344                 :        3418 :   tree type0 = TREE_TYPE (op0);
    9345                 :        3418 :   tree type1 = TREE_TYPE (op1);
    9346                 :        3418 :   bool integer_only_op = false;
    9347                 :        3418 :   enum stv_conv ret = stv_firstarg;
    9348                 :             : 
    9349                 :        3418 :   gcc_assert (gnu_vector_type_p (type0) || gnu_vector_type_p (type1));
    9350                 :        3418 :   switch (code)
    9351                 :             :     {
    9352                 :             :       /* Most GENERIC binary expressions require homogeneous arguments.
    9353                 :             :          LSHIFT_EXPR and RSHIFT_EXPR are exceptions and accept a first
    9354                 :             :          argument that is a vector and a second one that is a scalar, so
    9355                 :             :          we never return stv_secondarg for them.  */
    9356                 :         948 :       case RSHIFT_EXPR:
    9357                 :         948 :       case LSHIFT_EXPR:
    9358                 :         948 :         if (TREE_CODE (type0) == INTEGER_TYPE
    9359                 :         948 :             && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE)
    9360                 :             :           {
    9361                 :          50 :             if (unsafe_conversion_p (TREE_TYPE (type1), op0,
    9362                 :             :                                      NULL_TREE, false))
    9363                 :             :               {
    9364                 :           0 :                 if (complain)
    9365                 :           0 :                   error_at (loc, "conversion of scalar %qT to vector %qT "
    9366                 :             :                             "involves truncation", type0, type1);
    9367                 :           0 :                 return stv_error;
    9368                 :             :               }
    9369                 :             :             else
    9370                 :             :               return stv_firstarg;
    9371                 :             :           }
    9372                 :             :         break;
    9373                 :             : 
    9374                 :         311 :       case BIT_IOR_EXPR:
    9375                 :         311 :       case BIT_XOR_EXPR:
    9376                 :         311 :       case BIT_AND_EXPR:
    9377                 :         311 :         integer_only_op = true;
    9378                 :             :         /* fall through */
    9379                 :             : 
    9380                 :        2458 :       case VEC_COND_EXPR:
    9381                 :             : 
    9382                 :        2458 :       case PLUS_EXPR:
    9383                 :        2458 :       case MINUS_EXPR:
    9384                 :        2458 :       case MULT_EXPR:
    9385                 :        2458 :       case TRUNC_DIV_EXPR:
    9386                 :        2458 :       case CEIL_DIV_EXPR:
    9387                 :        2458 :       case FLOOR_DIV_EXPR:
    9388                 :        2458 :       case ROUND_DIV_EXPR:
    9389                 :        2458 :       case EXACT_DIV_EXPR:
    9390                 :        2458 :       case TRUNC_MOD_EXPR:
    9391                 :        2458 :       case FLOOR_MOD_EXPR:
    9392                 :        2458 :       case RDIV_EXPR:
    9393                 :        2458 :       case EQ_EXPR:
    9394                 :        2458 :       case NE_EXPR:
    9395                 :        2458 :       case LE_EXPR:
    9396                 :        2458 :       case GE_EXPR:
    9397                 :        2458 :       case LT_EXPR:
    9398                 :        2458 :       case GT_EXPR:
    9399                 :             :       /* What about UNLT_EXPR?  */
    9400                 :        2458 :         if (gnu_vector_type_p (type0))
    9401                 :             :           {
    9402                 :        1812 :             ret = stv_secondarg;
    9403                 :        1812 :             std::swap (type0, type1);
    9404                 :        1812 :             std::swap (op0, op1);
    9405                 :             :           }
    9406                 :             : 
    9407                 :        2458 :         if (TREE_CODE (type0) == INTEGER_TYPE
    9408                 :        2458 :             && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE)
    9409                 :             :           {
    9410                 :        1748 :             if (unsafe_conversion_p (TREE_TYPE (type1), op0,
    9411                 :             :                                      NULL_TREE, false))
    9412                 :             :               {
    9413                 :          11 :                 if (complain)
    9414                 :           8 :                   error_at (loc, "conversion of scalar %qT to vector %qT "
    9415                 :             :                             "involves truncation", type0, type1);
    9416                 :          11 :                 return stv_error;
    9417                 :             :               }
    9418                 :             :             return ret;
    9419                 :             :           }
    9420                 :         710 :         else if (!integer_only_op
    9421                 :             :                     /* Allow integer --> real conversion if safe.  */
    9422                 :         710 :                  && (SCALAR_FLOAT_TYPE_P (type0)
    9423                 :         468 :                      || TREE_CODE (type0) == INTEGER_TYPE)
    9424                 :        1420 :                  && SCALAR_FLOAT_TYPE_P (TREE_TYPE (type1)))
    9425                 :             :           {
    9426                 :         686 :             if (unsafe_conversion_p (TREE_TYPE (type1), op0,
    9427                 :             :                                      NULL_TREE, false))
    9428                 :             :               {
    9429                 :          22 :                 if (complain)
    9430                 :          22 :                   error_at (loc, "conversion of scalar %qT to vector %qT "
    9431                 :             :                             "involves truncation", type0, type1);
    9432                 :          22 :                 return stv_error;
    9433                 :             :               }
    9434                 :             :             return ret;
    9435                 :             :           }
    9436                 :             :       default:
    9437                 :             :         break;
    9438                 :             :     }
    9439                 :             : 
    9440                 :             :   return stv_nothing;
    9441                 :             : }
    9442                 :             : 
    9443                 :             : /* Return the alignment of std::max_align_t.
    9444                 :             : 
    9445                 :             :    [support.types.layout] The type max_align_t is a POD type whose alignment
    9446                 :             :    requirement is at least as great as that of every scalar type, and whose
    9447                 :             :    alignment requirement is supported in every context.  */
    9448                 :             : 
    9449                 :             : unsigned
    9450                 :      249162 : max_align_t_align ()
    9451                 :             : {
    9452                 :      249162 :   unsigned int max_align = MAX (TYPE_ALIGN (long_long_integer_type_node),
    9453                 :             :                                 TYPE_ALIGN (long_double_type_node));
    9454                 :      249162 :   if (float128_type_node != NULL_TREE)
    9455                 :      249162 :     max_align = MAX (max_align, TYPE_ALIGN (float128_type_node));
    9456                 :      249162 :   return max_align;
    9457                 :             : }
    9458                 :             : 
    9459                 :             : /* Return true iff ALIGN is an integral constant that is a fundamental
    9460                 :             :    alignment, as defined by [basic.align] in the c++-11
    9461                 :             :    specifications.
    9462                 :             : 
    9463                 :             :    That is:
    9464                 :             : 
    9465                 :             :        [A fundamental alignment is represented by an alignment less than or
    9466                 :             :         equal to the greatest alignment supported by the implementation
    9467                 :             :         in all contexts, which is equal to alignof(max_align_t)].  */
    9468                 :             : 
    9469                 :             : bool
    9470                 :           0 : cxx_fundamental_alignment_p (unsigned align)
    9471                 :             : {
    9472                 :           0 :   return (align <= max_align_t_align ());
    9473                 :             : }
    9474                 :             : 
    9475                 :             : /* Return true if T is a pointer to a zero-sized aggregate.  */
    9476                 :             : 
    9477                 :             : bool
    9478                 :     1239910 : pointer_to_zero_sized_aggr_p (tree t)
    9479                 :             : {
    9480                 :     1239910 :   if (!POINTER_TYPE_P (t))
    9481                 :             :     return false;
    9482                 :     1239910 :   t = TREE_TYPE (t);
    9483                 :     1239910 :   return (TYPE_SIZE (t) && integer_zerop (TYPE_SIZE (t)));
    9484                 :             : }
    9485                 :             : 
    9486                 :             : /* For an EXPR of a FUNCTION_TYPE that references a GCC built-in function
    9487                 :             :    with no library fallback or for an ADDR_EXPR whose operand is such type
    9488                 :             :    issues an error pointing to the location LOC.
    9489                 :             :    Returns true when the expression has been diagnosed and false
    9490                 :             :    otherwise.  */
    9491                 :             : 
    9492                 :             : bool
    9493                 :  4322052605 : reject_gcc_builtin (const_tree expr, location_t loc /* = UNKNOWN_LOCATION */)
    9494                 :             : {
    9495                 :  4322052605 :   if (TREE_CODE (expr) == ADDR_EXPR)
    9496                 :   102600081 :     expr = TREE_OPERAND (expr, 0);
    9497                 :             : 
    9498                 :  4322052605 :   STRIP_ANY_LOCATION_WRAPPER (expr);
    9499                 :             : 
    9500                 :  4322052605 :   if (TREE_TYPE (expr)
    9501                 :  4322052463 :       && TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE
    9502                 :     1993655 :       && TREE_CODE (expr) == FUNCTION_DECL
    9503                 :             :       /* The intersection of DECL_BUILT_IN and DECL_IS_UNDECLARED_BUILTIN avoids
    9504                 :             :          false positives for user-declared built-ins such as abs or
    9505                 :             :          strlen, and for C++ operators new and delete.
    9506                 :             :          The c_decl_implicit() test avoids false positives for implicitly
    9507                 :             :          declared built-ins with library fallbacks (such as abs).  */
    9508                 :     1967841 :       && fndecl_built_in_p (expr)
    9509                 :       66621 :       && DECL_IS_UNDECLARED_BUILTIN (expr)
    9510                 :        2372 :       && !c_decl_implicit (expr)
    9511                 :  4322054972 :       && !DECL_ASSEMBLER_NAME_SET_P (expr))
    9512                 :             :     {
    9513                 :         220 :       if (loc == UNKNOWN_LOCATION)
    9514                 :          82 :         loc = EXPR_LOC_OR_LOC (expr, input_location);
    9515                 :             : 
    9516                 :             :       /* Reject arguments that are built-in functions with
    9517                 :             :          no library fallback.  */
    9518                 :         220 :       error_at (loc, "built-in function %qE must be directly called", expr);
    9519                 :             : 
    9520                 :         220 :       return true;
    9521                 :             :     }
    9522                 :             : 
    9523                 :             :   return false;
    9524                 :             : }
    9525                 :             : 
    9526                 :             : /* Issue an ERROR for an invalid SIZE of array NAME which is null
    9527                 :             :    for unnamed arrays.  */
    9528                 :             : 
    9529                 :             : void
    9530                 :        1400 : invalid_array_size_error (location_t loc, cst_size_error error,
    9531                 :             :                           const_tree size, const_tree name)
    9532                 :             : {
    9533                 :        1400 :   tree maxsize = max_object_size ();
    9534                 :        1400 :   switch (error)
    9535                 :             :     {
    9536                 :           0 :     case cst_size_not_constant:
    9537                 :           0 :       if (name)
    9538                 :           0 :         error_at (loc, "size of array %qE is not a constant expression",
    9539                 :             :                   name);
    9540                 :             :       else
    9541                 :           0 :         error_at (loc, "size of array is not a constant expression");
    9542                 :             :       break;
    9543                 :         410 :     case cst_size_negative:
    9544                 :         410 :       if (name)
    9545                 :         119 :         error_at (loc, "size %qE of array %qE is negative",
    9546                 :             :                   size, name);
    9547                 :             :       else
    9548                 :         291 :         error_at (loc, "size %qE of array is negative",
    9549                 :             :                   size);
    9550                 :             :       break;
    9551                 :         930 :     case cst_size_too_big:
    9552                 :         930 :       if (name)
    9553                 :         103 :         error_at (loc, "size %qE of array %qE exceeds maximum "
    9554                 :             :                   "object size %qE", size, name, maxsize);
    9555                 :             :       else
    9556                 :         827 :         error_at (loc, "size %qE of array exceeds maximum "
    9557                 :             :                   "object size %qE", size, maxsize);
    9558                 :             :       break;
    9559                 :          60 :     case cst_size_overflow:
    9560                 :          60 :       if (name)
    9561                 :          39 :         error_at (loc, "size of array %qE exceeds maximum "
    9562                 :             :                   "object size %qE", name, maxsize);
    9563                 :             :       else
    9564                 :          21 :         error_at (loc, "size of array exceeds maximum "
    9565                 :             :                   "object size %qE", maxsize);
    9566                 :             :       break;
    9567                 :           0 :     default:
    9568                 :           0 :       gcc_unreachable ();
    9569                 :             :     }
    9570                 :        1400 : }
    9571                 :             : 
    9572                 :             : /* Check if array size calculations overflow or if the array covers more
    9573                 :             :    than half of the address space.  Return true if the size of the array
    9574                 :             :    is valid, false otherwise.  T is either the type of the array or its
    9575                 :             :    size, and NAME is the name of the array, or null for unnamed arrays.  */
    9576                 :             : 
    9577                 :             : bool
    9578                 :     7280904 : valid_array_size_p (location_t loc, const_tree t, tree name, bool complain)
    9579                 :             : {
    9580                 :     7280904 :   if (t == error_mark_node)
    9581                 :             :     return true;
    9582                 :             : 
    9583                 :     7280763 :   const_tree size;
    9584                 :     7280763 :   if (TYPE_P (t))
    9585                 :             :     {
    9586                 :     5215325 :       if (!COMPLETE_TYPE_P (t))
    9587                 :             :         return true;
    9588                 :     2749705 :       size = TYPE_SIZE_UNIT (t);
    9589                 :             :     }
    9590                 :             :   else
    9591                 :             :     size = t;
    9592                 :             : 
    9593                 :     4815143 :   if (TREE_CODE (size) != INTEGER_CST)
    9594                 :             :     return true;
    9595                 :             : 
    9596                 :     4790911 :   cst_size_error error;
    9597                 :     4790911 :   if (valid_constant_size_p (size, &error))
    9598                 :             :     return true;
    9599                 :             : 
    9600                 :        1091 :   if (!complain)
    9601                 :             :     return false;
    9602                 :             : 
    9603                 :        1076 :   if (TREE_CODE (TREE_TYPE (size)) == ENUMERAL_TYPE)
    9604                 :             :     /* Show the value of the enumerator rather than its name.  */
    9605                 :          16 :     size = convert (ssizetype, const_cast<tree> (size));
    9606                 :             : 
    9607                 :        1076 :   invalid_array_size_error (loc, error, size, name);
    9608                 :        1076 :   return false;
    9609                 :             : }
    9610                 :             : 
    9611                 :             : /* Read SOURCE_DATE_EPOCH from environment to have a deterministic
    9612                 :             :    timestamp to replace embedded current dates to get reproducible
    9613                 :             :    results.  Returns -1 if SOURCE_DATE_EPOCH is not defined.  */
    9614                 :             : 
    9615                 :             : time_t
    9616                 :        2418 : cb_get_source_date_epoch (cpp_reader *pfile ATTRIBUTE_UNUSED)
    9617                 :             : {
    9618                 :        2418 :   char *source_date_epoch;
    9619                 :        2418 :   int64_t epoch;
    9620                 :        2418 :   char *endptr;
    9621                 :             : 
    9622                 :        2418 :   source_date_epoch = getenv ("SOURCE_DATE_EPOCH");
    9623                 :        2418 :   if (!source_date_epoch)
    9624                 :             :     return (time_t) -1;
    9625                 :             : 
    9626                 :           3 :   errno = 0;
    9627                 :             : #if defined(INT64_T_IS_LONG)
    9628                 :           3 :   epoch = strtol (source_date_epoch, &endptr, 10);
    9629                 :             : #else
    9630                 :             :   epoch = strtoll (source_date_epoch, &endptr, 10);
    9631                 :             : #endif
    9632                 :           3 :   if (errno != 0 || endptr == source_date_epoch || *endptr != '\0'
    9633                 :           2 :       || epoch < 0 || epoch > MAX_SOURCE_DATE_EPOCH)
    9634                 :             :     {
    9635                 :           1 :       error_at (input_location, "environment variable %qs must "
    9636                 :             :                 "expand to a non-negative integer less than or equal to %wd",
    9637                 :             :                 "SOURCE_DATE_EPOCH", MAX_SOURCE_DATE_EPOCH);
    9638                 :           1 :       return (time_t) -1;
    9639                 :             :     }
    9640                 :             : 
    9641                 :             :   return (time_t) epoch;
    9642                 :             : }
    9643                 :             : 
    9644                 :             : /* Callback for libcpp for offering spelling suggestions for misspelled
    9645                 :             :    directives.  GOAL is an unrecognized string; CANDIDATES is a
    9646                 :             :    NULL-terminated array of candidate strings.  Return the closest
    9647                 :             :    match to GOAL within CANDIDATES, or NULL if none are good
    9648                 :             :    suggestions.  */
    9649                 :             : 
    9650                 :             : const char *
    9651                 :          19 : cb_get_suggestion (cpp_reader *, const char *goal,
    9652                 :             :                    const char *const *candidates)
    9653                 :             : {
    9654                 :          19 :   best_match<const char *, const char *> bm (goal);
    9655                 :         204 :   while (*candidates)
    9656                 :         166 :     bm.consider (*candidates++);
    9657                 :          19 :   return bm.get_best_meaningful_candidate ();
    9658                 :             : }
    9659                 :             : 
    9660                 :             : /* Return the latice point which is the wider of the two FLT_EVAL_METHOD
    9661                 :             :    modes X, Y.  This isn't just  >, as the FLT_EVAL_METHOD values added
    9662                 :             :    by C TS 18661-3 for interchange  types that are computed in their
    9663                 :             :    native precision are larger than the C11 values for evaluating in the
    9664                 :             :    precision of float/double/long double.  If either mode is
    9665                 :             :    FLT_EVAL_METHOD_UNPREDICTABLE, return that.  */
    9666                 :             : 
    9667                 :             : enum flt_eval_method
    9668                 :      523014 : excess_precision_mode_join (enum flt_eval_method x,
    9669                 :             :                             enum flt_eval_method y)
    9670                 :             : {
    9671                 :      523014 :   if (x == FLT_EVAL_METHOD_UNPREDICTABLE
    9672                 :      523014 :       || y == FLT_EVAL_METHOD_UNPREDICTABLE)
    9673                 :             :     return FLT_EVAL_METHOD_UNPREDICTABLE;
    9674                 :             : 
    9675                 :             :   /* GCC only supports one interchange type right now, _Float16.  If
    9676                 :             :      we're evaluating _Float16 in 16-bit precision, then flt_eval_method
    9677                 :             :      will be FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16.  */
    9678                 :      522690 :   if (x == FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16)
    9679                 :             :     return y;
    9680                 :      520587 :   if (y == FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16)
    9681                 :             :     return x;
    9682                 :             : 
    9683                 :             :   /* Other values for flt_eval_method are directly comparable, and we want
    9684                 :             :      the maximum.  */
    9685                 :      520575 :   return MAX (x, y);
    9686                 :             : }
    9687                 :             : 
    9688                 :             : /* Return the value that should be set for FLT_EVAL_METHOD in the
    9689                 :             :    context of ISO/IEC TS 18861-3.
    9690                 :             : 
    9691                 :             :    This relates to the effective excess precision seen by the user,
    9692                 :             :    which is the join point of the precision the target requests for
    9693                 :             :    -fexcess-precision={standard,fast,16} and the implicit excess precision
    9694                 :             :    the target uses.  */
    9695                 :             : 
    9696                 :             : static enum flt_eval_method
    9697                 :      411462 : c_ts18661_flt_eval_method (void)
    9698                 :             : {
    9699                 :      411462 :   enum flt_eval_method implicit
    9700                 :      411462 :     = targetm.c.excess_precision (EXCESS_PRECISION_TYPE_IMPLICIT);
    9701                 :             : 
    9702                 :      300160 :   enum excess_precision_type flag_type
    9703                 :      411462 :     = (flag_excess_precision == EXCESS_PRECISION_STANDARD
    9704                 :      411462 :        ? EXCESS_PRECISION_TYPE_STANDARD
    9705                 :             :        : (flag_excess_precision == EXCESS_PRECISION_FLOAT16
    9706                 :      300172 :           ? EXCESS_PRECISION_TYPE_FLOAT16
    9707                 :             :           : EXCESS_PRECISION_TYPE_FAST));
    9708                 :             : 
    9709                 :      411462 :   enum flt_eval_method requested
    9710                 :      411462 :     = targetm.c.excess_precision (flag_type);
    9711                 :             : 
    9712                 :      411462 :   return excess_precision_mode_join (implicit, requested);
    9713                 :             : }
    9714                 :             : 
    9715                 :             : /* As c_cpp_ts18661_flt_eval_method, but clamps the expected values to
    9716                 :             :    those that were permitted by C11.  That is to say, eliminates
    9717                 :             :    FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16.  */
    9718                 :             : 
    9719                 :             : static enum flt_eval_method
    9720                 :      100534 : c_c11_flt_eval_method (void)
    9721                 :             : {
    9722                 :      100534 :   return excess_precision_mode_join (c_ts18661_flt_eval_method (),
    9723                 :      100534 :                                      FLT_EVAL_METHOD_PROMOTE_TO_FLOAT);
    9724                 :             : }
    9725                 :             : 
    9726                 :             : /* Return the value that should be set for FLT_EVAL_METHOD.
    9727                 :             :    MAYBE_C11_ONLY_P is TRUE if we should check
    9728                 :             :    FLAG_PERMITTED_EVAL_METHODS as to whether we should limit the possible
    9729                 :             :    values we can return to those from C99/C11, and FALSE otherwise.
    9730                 :             :    See the comments on c_ts18661_flt_eval_method for what value we choose
    9731                 :             :    to set here.  */
    9732                 :             : 
    9733                 :             : int
    9734                 :      411462 : c_flt_eval_method (bool maybe_c11_only_p)
    9735                 :             : {
    9736                 :      411462 :   if (maybe_c11_only_p
    9737                 :      205731 :       && flag_permitted_flt_eval_methods
    9738                 :             :           == PERMITTED_FLT_EVAL_METHODS_C11)
    9739                 :      100534 :     return c_c11_flt_eval_method ();
    9740                 :             :   else
    9741                 :      310928 :     return c_ts18661_flt_eval_method ();
    9742                 :             : }
    9743                 :             : 
    9744                 :             : /* An enum for get_missing_token_insertion_kind for describing the best
    9745                 :             :    place to insert a missing token, if there is one.  */
    9746                 :             : 
    9747                 :             : enum missing_token_insertion_kind
    9748                 :             : {
    9749                 :             :   MTIK_IMPOSSIBLE,
    9750                 :             :   MTIK_INSERT_BEFORE_NEXT,
    9751                 :             :   MTIK_INSERT_AFTER_PREV
    9752                 :             : };
    9753                 :             : 
    9754                 :             : /* Given a missing token of TYPE, determine if it is reasonable to
    9755                 :             :    emit a fix-it hint suggesting the insertion of the token, and,
    9756                 :             :    if so, where the token should be inserted relative to other tokens.
    9757                 :             : 
    9758                 :             :    It only makes sense to do this for values of TYPE that are symbols.
    9759                 :             : 
    9760                 :             :    Some symbols should go before the next token, e.g. in:
    9761                 :             :      if flag)
    9762                 :             :    we want to insert the missing '(' immediately before "flag",
    9763                 :             :    giving:
    9764                 :             :      if (flag)
    9765                 :             :    rather than:
    9766                 :             :      if( flag)
    9767                 :             :    These use MTIK_INSERT_BEFORE_NEXT.
    9768                 :             : 
    9769                 :             :    Other symbols should go after the previous token, e.g. in:
    9770                 :             :      if (flag
    9771                 :             :        do_something ();
    9772                 :             :    we want to insert the missing ')' immediately after the "flag",
    9773                 :             :    giving:
    9774                 :             :      if (flag)
    9775                 :             :        do_something ();
    9776                 :             :    rather than:
    9777                 :             :      if (flag
    9778                 :             :        )do_something ();
    9779                 :             :    These use MTIK_INSERT_AFTER_PREV.  */
    9780                 :             : 
    9781                 :             : static enum missing_token_insertion_kind
    9782                 :        3225 : get_missing_token_insertion_kind (enum cpp_ttype type)
    9783                 :             : {
    9784                 :        3225 :   switch (type)
    9785                 :             :     {
    9786                 :             :       /* Insert missing "opening" brackets immediately
    9787                 :             :          before the next token.  */
    9788                 :             :     case CPP_OPEN_SQUARE:
    9789                 :             :     case CPP_OPEN_PAREN:
    9790                 :             :       return MTIK_INSERT_BEFORE_NEXT;
    9791                 :             : 
    9792                 :             :       /* Insert other missing symbols immediately after
    9793                 :             :          the previous token.  */
    9794                 :        1954 :     case CPP_CLOSE_PAREN:
    9795                 :        1954 :     case CPP_CLOSE_SQUARE:
    9796                 :        1954 :     case CPP_SEMICOLON:
    9797                 :        1954 :     case CPP_COMMA:
    9798                 :        1954 :     case CPP_COLON:
    9799                 :        1954 :       return MTIK_INSERT_AFTER_PREV;
    9800                 :             : 
    9801                 :             :       /* Other kinds of token don't get fix-it hints.  */
    9802                 :         987 :     default:
    9803                 :         987 :       return MTIK_IMPOSSIBLE;
    9804                 :             :     }
    9805                 :             : }
    9806                 :             : 
    9807                 :             : /* Given RICHLOC, a location for a diagnostic describing a missing token
    9808                 :             :    of kind TOKEN_TYPE, potentially add a fix-it hint suggesting the
    9809                 :             :    insertion of the token.
    9810                 :             : 
    9811                 :             :    The location of the attempted fix-it hint depends on TOKEN_TYPE:
    9812                 :             :    it will either be:
    9813                 :             :      (a) immediately after PREV_TOKEN_LOC, or
    9814                 :             : 
    9815                 :             :      (b) immediately before the primary location within RICHLOC (taken to
    9816                 :             :          be that of the token following where the token was expected).
    9817                 :             : 
    9818                 :             :    If we manage to add a fix-it hint, then the location of the
    9819                 :             :    fix-it hint is likely to be more useful as the primary location
    9820                 :             :    of the diagnostic than that of the following token, so we swap
    9821                 :             :    these locations.
    9822                 :             : 
    9823                 :             :    For example, given this bogus code:
    9824                 :             :        123456789012345678901234567890
    9825                 :             :    1 | int missing_semicolon (void)
    9826                 :             :    2 | {
    9827                 :             :    3 |   return 42
    9828                 :             :    4 | }
    9829                 :             : 
    9830                 :             :    we will emit:
    9831                 :             : 
    9832                 :             :      "expected ';' before '}'"
    9833                 :             : 
    9834                 :             :    RICHLOC's primary location is at the closing brace, so before "swapping"
    9835                 :             :    we would emit the error at line 4 column 1:
    9836                 :             : 
    9837                 :             :        123456789012345678901234567890
    9838                 :             :    3 |   return 42  |< fix-it hint emitted for this line
    9839                 :             :      |            ; |
    9840                 :             :    4 | }            |< "expected ';' before '}'" emitted at this line
    9841                 :             :      | ^            |
    9842                 :             : 
    9843                 :             :    It's more useful for the location of the diagnostic to be at the
    9844                 :             :    fix-it hint, so we swap the locations, so the primary location
    9845                 :             :    is at the fix-it hint, with the old primary location inserted
    9846                 :             :    as a secondary location, giving this, with the error at line 3
    9847                 :             :    column 12:
    9848                 :             : 
    9849                 :             :        123456789012345678901234567890
    9850                 :             :    3 |   return 42   |< "expected ';' before '}'" emitted at this line,
    9851                 :             :      |            ^  |   with fix-it hint
    9852                 :             :    4 |            ;  |
    9853                 :             :      | }             |< secondary range emitted here
    9854                 :             :      | ~             |.  */
    9855                 :             : 
    9856                 :             : void
    9857                 :        3225 : maybe_suggest_missing_token_insertion (rich_location *richloc,
    9858                 :             :                                        enum cpp_ttype token_type,
    9859                 :             :                                        location_t prev_token_loc)
    9860                 :             : {
    9861                 :        3225 :   gcc_assert (richloc);
    9862                 :             : 
    9863                 :        3225 :   enum missing_token_insertion_kind mtik
    9864                 :        3225 :     = get_missing_token_insertion_kind (token_type);
    9865                 :             : 
    9866                 :        3225 :   switch (mtik)
    9867                 :             :     {
    9868                 :             :     default:
    9869                 :             :       gcc_unreachable ();
    9870                 :             :       break;
    9871                 :             : 
    9872                 :             :     case MTIK_IMPOSSIBLE:
    9873                 :             :       return;
    9874                 :             : 
    9875                 :         284 :     case MTIK_INSERT_BEFORE_NEXT:
    9876                 :             :       /* Attempt to add the fix-it hint before the primary location
    9877                 :             :          of RICHLOC.  */
    9878                 :         284 :       richloc->add_fixit_insert_before (cpp_type2name (token_type, 0));
    9879                 :         284 :       break;
    9880                 :             : 
    9881                 :        1954 :     case MTIK_INSERT_AFTER_PREV:
    9882                 :             :       /* Attempt to add the fix-it hint after PREV_TOKEN_LOC.  */
    9883                 :        1954 :       richloc->add_fixit_insert_after (prev_token_loc,
    9884                 :             :                                        cpp_type2name (token_type, 0));
    9885                 :        1954 :       break;
    9886                 :             :     }
    9887                 :             : 
    9888                 :             :   /* If we were successful, use the fix-it hint's location as the
    9889                 :             :      primary location within RICHLOC, adding the old primary location
    9890                 :             :      back as a secondary location.  */
    9891                 :        2238 :   if (!richloc->seen_impossible_fixit_p ())
    9892                 :             :     {
    9893                 :        2234 :       fixit_hint *hint = richloc->get_last_fixit_hint ();
    9894                 :        2234 :       location_t hint_loc = hint->get_start_loc ();
    9895                 :        2234 :       location_t old_loc = richloc->get_loc ();
    9896                 :             : 
    9897                 :        2234 :       richloc->set_range (0, hint_loc, SHOW_RANGE_WITH_CARET);
    9898                 :        2234 :       richloc->add_range (old_loc);
    9899                 :             :     }
    9900                 :             : }
    9901                 :             : 
    9902                 :             : /* Potentially emit a note about likely missing '&' or '*',
    9903                 :             :    depending on EXPR and EXPECTED_TYPE.  */
    9904                 :             : 
    9905                 :             : void
    9906                 :        2184 : maybe_emit_indirection_note (location_t loc,
    9907                 :             :                              tree expr, tree expected_type)
    9908                 :             : {
    9909                 :        2184 :   gcc_assert (expr);
    9910                 :        2184 :   gcc_assert (expected_type);
    9911                 :             : 
    9912                 :        2184 :   tree actual_type = TREE_TYPE (expr);
    9913                 :             : 
    9914                 :             :   /* Missing '&'.  */
    9915                 :        2184 :   if (TREE_CODE (expected_type) == POINTER_TYPE
    9916                 :        1224 :       && compatible_types_for_indirection_note_p (actual_type,
    9917                 :        1224 :                                                   TREE_TYPE (expected_type))
    9918                 :        2262 :       && lvalue_p (expr))
    9919                 :             :     {
    9920                 :          43 :       gcc_rich_location richloc (loc);
    9921                 :          43 :       richloc.add_fixit_insert_before ("&");
    9922                 :          43 :       inform (&richloc, "possible fix: take the address with %qs", "&");
    9923                 :          43 :     }
    9924                 :             : 
    9925                 :             :   /* Missing '*'.  */
    9926                 :        2184 :   if (TREE_CODE (actual_type) == POINTER_TYPE
    9927                 :        2184 :       && compatible_types_for_indirection_note_p (TREE_TYPE (actual_type),
    9928                 :             :                                                   expected_type))
    9929                 :             :     {
    9930                 :          78 :       gcc_rich_location richloc (loc);
    9931                 :          78 :       richloc.add_fixit_insert_before ("*");
    9932                 :          78 :       inform (&richloc, "possible fix: dereference with %qs", "*");
    9933                 :          78 :     }
    9934                 :        2184 : }
    9935                 :             : 
    9936                 :             : #if CHECKING_P
    9937                 :             : 
    9938                 :             : namespace selftest {
    9939                 :             : 
    9940                 :             : /* Verify that fold_for_warn on error_mark_node is safe.  */
    9941                 :             : 
    9942                 :             : static void
    9943                 :           3 : test_fold_for_warn ()
    9944                 :             : {
    9945                 :           3 :   ASSERT_EQ (error_mark_node, fold_for_warn (error_mark_node));
    9946                 :           3 : }
    9947                 :             : 
    9948                 :             : /* Run all of the selftests within this file.  */
    9949                 :             : 
    9950                 :             : static void
    9951                 :           3 : c_common_cc_tests ()
    9952                 :             : {
    9953                 :           0 :   test_fold_for_warn ();
    9954                 :           0 : }
    9955                 :             : 
    9956                 :             : /* Run all of the tests within c-family.  */
    9957                 :             : 
    9958                 :             : void
    9959                 :           3 : c_family_tests (void)
    9960                 :             : {
    9961                 :           3 :   c_common_cc_tests ();
    9962                 :           3 :   c_format_cc_tests ();
    9963                 :           3 :   c_indentation_cc_tests ();
    9964                 :           3 :   c_pretty_print_cc_tests ();
    9965                 :           3 :   c_spellcheck_cc_tests ();
    9966                 :           3 :   c_diagnostic_cc_tests ();
    9967                 :           3 :   c_opt_problem_cc_tests ();
    9968                 :           3 : }
    9969                 :             : 
    9970                 :             : } // namespace selftest
    9971                 :             : 
    9972                 :             : #endif /* #if CHECKING_P */
    9973                 :             : 
    9974                 :             : /* Attempt to locate a suitable location within FILE for a
    9975                 :             :    #include directive to be inserted before.
    9976                 :             :    LOC is the location of the relevant diagnostic.
    9977                 :             : 
    9978                 :             :    Attempt to return the location within FILE immediately
    9979                 :             :    after the last #include within that file, or the start of
    9980                 :             :    that file if it has no #include directives.
    9981                 :             : 
    9982                 :             :    Return UNKNOWN_LOCATION if no suitable location is found,
    9983                 :             :    or if an error occurs.  */
    9984                 :             : 
    9985                 :             : static location_t
    9986                 :         427 : try_to_locate_new_include_insertion_point (const char *file, location_t loc)
    9987                 :             : {
    9988                 :             :   /* Locate the last ordinary map within FILE that ended with a #include.  */
    9989                 :         427 :   const line_map_ordinary *last_include_ord_map = NULL;
    9990                 :             : 
    9991                 :             :   /* ...and the next ordinary map within FILE after that one.  */
    9992                 :         427 :   const line_map_ordinary *last_ord_map_after_include = NULL;
    9993                 :             : 
    9994                 :             :   /* ...and the first ordinary map within FILE.  */
    9995                 :         427 :   const line_map_ordinary *first_ord_map_in_file = NULL;
    9996                 :             : 
    9997                 :             :   /*  Get ordinary map containing LOC (or its expansion).  */
    9998                 :         427 :   const line_map_ordinary *ord_map_for_loc = NULL;
    9999                 :         427 :   linemap_resolve_location (line_table, loc, LRK_MACRO_EXPANSION_POINT,
   10000                 :             :                             &ord_map_for_loc);
   10001                 :         427 :   gcc_assert (ord_map_for_loc);
   10002                 :             : 
   10003                 :       11973 :   for (unsigned int i = 0; i < LINEMAPS_ORDINARY_USED (line_table); i++)
   10004                 :             :     {
   10005                 :       11973 :       const line_map_ordinary *ord_map
   10006                 :       11973 :         = LINEMAPS_ORDINARY_MAP_AT (line_table, i);
   10007                 :             : 
   10008                 :       23946 :       if (const line_map_ordinary *from
   10009                 :       11973 :           = linemap_included_from_linemap (line_table, ord_map))
   10010                 :             :         /* We cannot use pointer equality, because with preprocessed
   10011                 :             :            input all filename strings are unique.  */
   10012                 :        9599 :         if (0 == strcmp (from->to_file, file))
   10013                 :             :           {
   10014                 :       11973 :             last_include_ord_map = from;
   10015                 :       11973 :             last_ord_map_after_include = NULL;
   10016                 :             :           }
   10017                 :             : 
   10018                 :             :       /* Likewise, use strcmp, and reject any line-zero introductory
   10019                 :             :          map.  */
   10020                 :       11973 :       if (ord_map->to_line && 0 == strcmp (ord_map->to_file, file))
   10021                 :             :         {
   10022                 :         669 :           if (!first_ord_map_in_file)
   10023                 :         427 :             first_ord_map_in_file = ord_map;
   10024                 :         669 :           if (last_include_ord_map && !last_ord_map_after_include)
   10025                 :         166 :             last_ord_map_after_include = ord_map;
   10026                 :             :         }
   10027                 :             : 
   10028                 :             :       /* Stop searching when reaching the ord_map containing LOC,
   10029                 :             :          as it makes no sense to provide fix-it hints that appear
   10030                 :             :          after the diagnostic in question.  */
   10031                 :       11973 :       if (ord_map == ord_map_for_loc)
   10032                 :             :         break;
   10033                 :             :     }
   10034                 :             : 
   10035                 :             :   /* Determine where to insert the #include.  */
   10036                 :         427 :   const line_map_ordinary *ord_map_for_insertion;
   10037                 :             : 
   10038                 :             :   /* We want the next ordmap in the file after the last one that's a
   10039                 :             :      #include, but failing that, the start of the file.  */
   10040                 :         427 :   if (last_ord_map_after_include)
   10041                 :             :     ord_map_for_insertion = last_ord_map_after_include;
   10042                 :             :   else
   10043                 :         263 :     ord_map_for_insertion = first_ord_map_in_file;
   10044                 :             : 
   10045                 :         263 :   if (!ord_map_for_insertion)
   10046                 :             :     return UNKNOWN_LOCATION;
   10047                 :             : 
   10048                 :             :   /* The "start_location" is column 0, meaning "the whole line".
   10049                 :             :      rich_location and edit_context can't cope with this, so use
   10050                 :             :      column 1 instead.  */
   10051                 :         427 :   location_t col_0 = ord_map_for_insertion->start_location;
   10052                 :         427 :   return linemap_position_for_loc_and_offset (line_table, col_0, 1);
   10053                 :             : }
   10054                 :             : 
   10055                 :             : /* A map from filenames to sets of headers added to them, for
   10056                 :             :    ensuring idempotency within maybe_add_include_fixit.  */
   10057                 :             : 
   10058                 :             : /* The values within the map.  We need string comparison as there's
   10059                 :             :    no guarantee that two different diagnostics that are recommending
   10060                 :             :    adding e.g. "<stdio.h>" are using the same buffer.  */
   10061                 :             : 
   10062                 :             : typedef hash_set <const char *, false, nofree_string_hash> per_file_includes_t;
   10063                 :             : 
   10064                 :             : /* The map itself.  We don't need string comparison for the filename keys,
   10065                 :             :    as they come from libcpp.  */
   10066                 :             : 
   10067                 :             : typedef hash_map <const char *, per_file_includes_t *> added_includes_t;
   10068                 :             : static added_includes_t *added_includes;
   10069                 :             : 
   10070                 :             : /* Attempt to add a fix-it hint to RICHLOC, adding "#include HEADER\n"
   10071                 :             :    in a suitable location within the file of RICHLOC's primary
   10072                 :             :    location.
   10073                 :             : 
   10074                 :             :    This function is idempotent: a header will be added at most once to
   10075                 :             :    any given file.
   10076                 :             : 
   10077                 :             :    If OVERRIDE_LOCATION is true, then if a fix-it is added and will be
   10078                 :             :    printed, then RICHLOC's primary location will be replaced by that of
   10079                 :             :    the fix-it hint (for use by "inform" notes where the location of the
   10080                 :             :    issue has already been reported).  */
   10081                 :             : 
   10082                 :             : void
   10083                 :         879 : maybe_add_include_fixit (rich_location *richloc, const char *header,
   10084                 :             :                          bool override_location)
   10085                 :             : {
   10086                 :         879 :   location_t loc = richloc->get_loc ();
   10087                 :         879 :   const char *file = LOCATION_FILE (loc);
   10088                 :         879 :   if (!file)
   10089                 :         452 :     return;
   10090                 :             : 
   10091                 :             :   /* Idempotency: don't add the same header more than once to a given file.  */
   10092                 :         879 :   if (!added_includes)
   10093                 :         344 :     added_includes = new added_includes_t ();
   10094                 :         879 :   per_file_includes_t *&set = added_includes->get_or_insert (file);
   10095                 :         879 :   if (set)
   10096                 :         535 :     if (set->contains (header))
   10097                 :             :       /* ...then we've already added HEADER to that file.  */
   10098                 :             :       return;
   10099                 :         427 :   if (!set)
   10100                 :         344 :     set = new per_file_includes_t ();
   10101                 :         427 :   set->add (header);
   10102                 :             : 
   10103                 :             :   /* Attempt to locate a suitable place for the new directive.  */
   10104                 :         427 :   location_t include_insert_loc
   10105                 :         427 :     = try_to_locate_new_include_insertion_point (file, loc);
   10106                 :         427 :   if (include_insert_loc == UNKNOWN_LOCATION)
   10107                 :             :     return;
   10108                 :             : 
   10109                 :         427 :   char *text = xasprintf ("#include %s\n", header);
   10110                 :         427 :   richloc->add_fixit_insert_before (include_insert_loc, text);
   10111                 :         427 :   free (text);
   10112                 :             : 
   10113                 :         427 :   if (override_location && global_dc->m_source_printing.enabled)
   10114                 :             :     {
   10115                 :             :       /* Replace the primary location with that of the insertion point for the
   10116                 :             :          fix-it hint.
   10117                 :             : 
   10118                 :             :          We use SHOW_LINES_WITHOUT_RANGE so that we don't meaningless print a
   10119                 :             :          caret for the insertion point (or colorize it).
   10120                 :             : 
   10121                 :             :          Hence we print e.g.:
   10122                 :             : 
   10123                 :             :          ../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:74:1: note: msg 2
   10124                 :             :           73 | # include <debug/vector>
   10125                 :             :          +++ |+#include <vector>
   10126                 :             :           74 | #endif
   10127                 :             : 
   10128                 :             :          rather than:
   10129                 :             : 
   10130                 :             :          ../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:74:1: note: msg 2
   10131                 :             :           73 | # include <debug/vector>
   10132                 :             :          +++ |+#include <vector>
   10133                 :             :           74 | #endif
   10134                 :             :              | ^
   10135                 :             : 
   10136                 :             :          avoiding the caret on the first column of line 74.  */
   10137                 :         177 :       richloc->set_range (0, include_insert_loc, SHOW_LINES_WITHOUT_RANGE);
   10138                 :             :     }
   10139                 :             : }
   10140                 :             : 
   10141                 :             : /* Attempt to convert a braced array initializer list CTOR for array
   10142                 :             :    TYPE into a STRING_CST for convenience and efficiency.  Return
   10143                 :             :    the converted string on success or the original ctor on failure.
   10144                 :             :    Also, for non-convertable CTORs which contain RAW_DATA_CST values
   10145                 :             :    among the elts try to extend the range of RAW_DATA_CSTs.  */
   10146                 :             : 
   10147                 :             : static tree
   10148                 :       44211 : braced_list_to_string (tree type, tree ctor, bool member)
   10149                 :             : {
   10150                 :             :   /* Ignore non-members with unknown size like arrays with unspecified
   10151                 :             :      bound.  */
   10152                 :       44211 :   tree typesize = TYPE_SIZE_UNIT (type);
   10153                 :       44211 :   if (!member && !tree_fits_uhwi_p (typesize))
   10154                 :             :     return ctor;
   10155                 :             : 
   10156                 :             :   /* If the target char size differs from the host char size, we'd risk
   10157                 :             :      loosing data and getting object sizes wrong by converting to
   10158                 :             :      host chars.  */
   10159                 :       44196 :   if (TYPE_PRECISION (char_type_node) != CHAR_BIT)
   10160                 :             :     return ctor;
   10161                 :             : 
   10162                 :             :   /* STRING_CST doesn't support wide characters.  */
   10163                 :       44196 :   gcc_checking_assert (TYPE_PRECISION (TREE_TYPE (type)) == CHAR_BIT);
   10164                 :             : 
   10165                 :             :   /* If the array has an explicit bound, use it to constrain the size
   10166                 :             :      of the string.  If it doesn't, be sure to create a string that's
   10167                 :             :      as long as implied by the index of the last zero specified via
   10168                 :             :      a designator, as in:
   10169                 :             :        const char a[] = { [7] = 0 };  */
   10170                 :       44196 :   unsigned HOST_WIDE_INT maxelts;
   10171                 :       44196 :   if (typesize)
   10172                 :             :     {
   10173                 :       44117 :       maxelts = tree_to_uhwi (typesize);
   10174                 :       44117 :       maxelts /= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type)));
   10175                 :             :     }
   10176                 :             :   else
   10177                 :             :     maxelts = HOST_WIDE_INT_M1U;
   10178                 :             : 
   10179                 :             :   /* Avoid converting initializers for zero-length arrays (but do
   10180                 :             :      create them for flexible array members).  */
   10181                 :       44117 :   if (!maxelts)
   10182                 :             :     return ctor;
   10183                 :             : 
   10184                 :       44047 :   unsigned HOST_WIDE_INT nelts = CONSTRUCTOR_NELTS (ctor);
   10185                 :             : 
   10186                 :       44047 :   auto_vec<char> str;
   10187                 :       44047 :   str.reserve (nelts + 1);
   10188                 :             : 
   10189                 :       44047 :   unsigned HOST_WIDE_INT i, j = HOST_WIDE_INT_M1U;
   10190                 :       44047 :   tree index, value;
   10191                 :       44047 :   bool check_raw_data = false;
   10192                 :             : 
   10193                 :      627828 :   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), i, index, value)
   10194                 :             :     {
   10195                 :      583781 :       if (check_raw_data)
   10196                 :             :         {
   10197                 :             :           /* The preprocessor always surrounds CPP_EMBED tokens in between
   10198                 :             :              CPP_NUMBER and CPP_COMMA tokens.  Try to undo that here now that
   10199                 :             :              the whole initializer is parsed.  E.g. if we have
   10200                 :             :              [0] = 'T', [1] = "his is a #embed tex", [20] = 't'
   10201                 :             :              where the middle value is RAW_DATA_CST and in its owner this is
   10202                 :             :              surrounded by 'T' and 't' characters, we can create from it just
   10203                 :             :              [0] = "This is a #embed text"
   10204                 :             :              Similarly if a RAW_DATA_CST needs to be split into two parts
   10205                 :             :              because of designated init store but the stored value is actually
   10206                 :             :              the same as in the RAW_DATA_OWNER's memory we can merge multiple
   10207                 :             :              RAW_DATA_CSTs.  */
   10208                 :        1169 :           if (TREE_CODE (value) == RAW_DATA_CST
   10209                 :         531 :               && index
   10210                 :         531 :               && tree_fits_uhwi_p (index))
   10211                 :             :             {
   10212                 :         531 :               tree owner = RAW_DATA_OWNER (value);
   10213                 :         531 :               unsigned int start, end, k;
   10214                 :         531 :               if (TREE_CODE (owner) == STRING_CST)
   10215                 :             :                 {
   10216                 :         205 :                   start
   10217                 :         205 :                     = RAW_DATA_POINTER (value) - TREE_STRING_POINTER (owner);
   10218                 :         205 :                   end = TREE_STRING_LENGTH (owner) - RAW_DATA_LENGTH (value);
   10219                 :             :                 }
   10220                 :             :               else
   10221                 :             :                 {
   10222                 :         326 :                   gcc_checking_assert (TREE_CODE (owner) == RAW_DATA_CST);
   10223                 :         326 :                   start
   10224                 :         326 :                     = RAW_DATA_POINTER (value) - RAW_DATA_POINTER (owner);
   10225                 :         326 :                   end = RAW_DATA_LENGTH (owner) - RAW_DATA_LENGTH (value);
   10226                 :             :                 }
   10227                 :         531 :               end -= start;
   10228                 :         531 :               unsigned HOST_WIDE_INT l = j == HOST_WIDE_INT_M1U ? i : j;
   10229                 :         947 :               for (k = 0; k < start && k < l; ++k)
   10230                 :             :                 {
   10231                 :         442 :                   constructor_elt *elt = CONSTRUCTOR_ELT (ctor, l - k - 1);
   10232                 :         884 :                   if (elt->index == NULL_TREE
   10233                 :         442 :                       || !tree_fits_uhwi_p (elt->index)
   10234                 :         442 :                       || !tree_fits_shwi_p (elt->value)
   10235                 :        1321 :                       || wi::to_widest (index) != (wi::to_widest (elt->index)
   10236                 :        1316 :                                                    + (k + 1)))
   10237                 :             :                     break;
   10238                 :         437 :                   if (TYPE_UNSIGNED (TREE_TYPE (value)))
   10239                 :             :                     {
   10240                 :         361 :                       if (tree_to_shwi (elt->value)
   10241                 :         361 :                           != *((const unsigned char *)
   10242                 :         361 :                                RAW_DATA_POINTER (value) - k - 1))
   10243                 :             :                         break;
   10244                 :             :                     }
   10245                 :          76 :                   else if (tree_to_shwi (elt->value)
   10246                 :          76 :                            != *((const signed char *)
   10247                 :          76 :                                 RAW_DATA_POINTER (value) - k - 1))
   10248                 :             :                     break;
   10249                 :             :                 }
   10250                 :         531 :               start = k;
   10251                 :         531 :               l = 0;
   10252                 :        1382 :               for (k = 0; k < end && k + 1 < CONSTRUCTOR_NELTS (ctor) - i; ++k)
   10253                 :             :                 {
   10254                 :         432 :                   constructor_elt *elt = CONSTRUCTOR_ELT (ctor, i + k + 1);
   10255                 :         864 :                   if (elt->index == NULL_TREE
   10256                 :         432 :                       || !tree_fits_uhwi_p (elt->index)
   10257                 :        1296 :                       || (wi::to_widest (elt->index)
   10258                 :         864 :                           != (wi::to_widest (index)
   10259                 :        1296 :                               + (RAW_DATA_LENGTH (value) + l))))
   10260                 :             :                     break;
   10261                 :         432 :                   if (TREE_CODE (elt->value) == RAW_DATA_CST
   10262                 :           2 :                       && RAW_DATA_OWNER (elt->value) == RAW_DATA_OWNER (value)
   10263                 :         432 :                       && (RAW_DATA_POINTER (elt->value)
   10264                 :           2 :                           == RAW_DATA_POINTER (value) + l))
   10265                 :             :                     {
   10266                 :           0 :                       l += RAW_DATA_LENGTH (elt->value);
   10267                 :           0 :                       end -= RAW_DATA_LENGTH (elt->value) - 1;
   10268                 :           0 :                       continue;
   10269                 :             :                     }
   10270                 :         432 :                   if (!tree_fits_shwi_p (elt->value))
   10271                 :             :                     break;
   10272                 :         429 :                   if (TYPE_UNSIGNED (TREE_TYPE (value)))
   10273                 :             :                     {
   10274                 :         375 :                       if (tree_to_shwi (elt->value)
   10275                 :         375 :                           != *((const unsigned char *)
   10276                 :         375 :                                RAW_DATA_POINTER (value)
   10277                 :         375 :                                + RAW_DATA_LENGTH (value) + k))
   10278                 :             :                         break;
   10279                 :             :                     }
   10280                 :          54 :                   else if (tree_to_shwi (elt->value)
   10281                 :          54 :                            != *((const signed char *)
   10282                 :          54 :                                 RAW_DATA_POINTER (value)
   10283                 :          54 :                                 + RAW_DATA_LENGTH (value) + k))
   10284                 :             :                     break;
   10285                 :         394 :                   ++l;
   10286                 :             :                 }
   10287                 :         531 :               end = k;
   10288                 :         531 :               if (start != 0 || end != 0)
   10289                 :             :                 {
   10290                 :         438 :                   if (j == HOST_WIDE_INT_M1U)
   10291                 :         400 :                     j = i - start;
   10292                 :             :                   else
   10293                 :          38 :                     j -= start;
   10294                 :         438 :                   RAW_DATA_POINTER (value) -= start;
   10295                 :         438 :                   RAW_DATA_LENGTH (value) += start + end;
   10296                 :         438 :                   i += end;
   10297                 :         438 :                   if (start == 0)
   10298                 :          22 :                     CONSTRUCTOR_ELT (ctor, j)->index = index;
   10299                 :         438 :                   CONSTRUCTOR_ELT (ctor, j)->value = value;
   10300                 :         438 :                   ++j;
   10301                 :         438 :                   continue;
   10302                 :             :                 }
   10303                 :             :             }
   10304                 :         731 :           if (j != HOST_WIDE_INT_M1U)
   10305                 :             :             {
   10306                 :         175 :               CONSTRUCTOR_ELT (ctor, j)->index = index;
   10307                 :         175 :               CONSTRUCTOR_ELT (ctor, j)->value = value;
   10308                 :         175 :               ++j;
   10309                 :             :             }
   10310                 :         731 :           continue;
   10311                 :         731 :         }
   10312                 :             : 
   10313                 :      582612 :       unsigned HOST_WIDE_INT idx = i;
   10314                 :      582612 :       if (index)
   10315                 :             :         {
   10316                 :      582612 :           if (!tree_fits_uhwi_p (index))
   10317                 :             :             {
   10318                 :          22 :               check_raw_data = true;
   10319                 :          22 :               continue;
   10320                 :             :             }
   10321                 :      582590 :           idx = tree_to_uhwi (index);
   10322                 :             :         }
   10323                 :             : 
   10324                 :             :       /* auto_vec is limited to UINT_MAX elements.  */
   10325                 :      582590 :       if (idx > UINT_MAX)
   10326                 :             :         {
   10327                 :           0 :           check_raw_data = true;
   10328                 :           0 :           continue;
   10329                 :             :         }
   10330                 :             : 
   10331                 :             :       /* Avoid non-constant initializers.  */
   10332                 :      582590 :       if (!tree_fits_shwi_p (value))
   10333                 :             :         {
   10334                 :         635 :           check_raw_data = true;
   10335                 :         635 :           --i;
   10336                 :         635 :           continue;
   10337                 :             :         }
   10338                 :             : 
   10339                 :             :       /* Skip over embedded nuls except the last one (initializer
   10340                 :             :          elements are in ascending order of indices).  */
   10341                 :      581955 :       HOST_WIDE_INT val = tree_to_shwi (value);
   10342                 :      581955 :       if (!val && i + 1 < nelts)
   10343                 :        5936 :         continue;
   10344                 :             : 
   10345                 :      576019 :       if (idx < str.length ())
   10346                 :             :         {
   10347                 :           0 :           check_raw_data = true;
   10348                 :           0 :           continue;
   10349                 :             :         }
   10350                 :             : 
   10351                 :             :       /* Bail if the CTOR has a block of more than 256 embedded nuls
   10352                 :             :          due to implicitly initialized elements.  */
   10353                 :      576019 :       unsigned nchars = (idx - str.length ()) + 1;
   10354                 :      576019 :       if (nchars > 256)
   10355                 :             :         {
   10356                 :           3 :           check_raw_data = true;
   10357                 :           3 :           continue;
   10358                 :             :         }
   10359                 :             : 
   10360                 :      576016 :       if (nchars > 1)
   10361                 :             :         {
   10362                 :        3642 :           str.reserve (idx);
   10363                 :        3642 :           str.quick_grow_cleared (idx);
   10364                 :             :         }
   10365                 :             : 
   10366                 :      576016 :       if (idx >= maxelts)
   10367                 :             :         {
   10368                 :           0 :           check_raw_data = true;
   10369                 :           0 :           continue;
   10370                 :             :         }
   10371                 :             : 
   10372                 :      576016 :       str.safe_insert (idx, val);
   10373                 :             :     }
   10374                 :             : 
   10375                 :       44047 :   if (check_raw_data)
   10376                 :             :     {
   10377                 :         660 :       if (j != HOST_WIDE_INT_M1U)
   10378                 :         400 :         CONSTRUCTOR_ELTS (ctor)->truncate (j);
   10379                 :         660 :       return ctor;
   10380                 :             :     }
   10381                 :             : 
   10382                 :             :   /* Append a nul string termination.  */
   10383                 :       86697 :   if (maxelts != HOST_WIDE_INT_M1U && str.length () < maxelts)
   10384                 :       16896 :     str.safe_push (0);
   10385                 :             : 
   10386                 :             :   /* Build a STRING_CST with the same type as the array.  */
   10387                 :      130161 :   tree res = build_string (str.length (), str.begin ());
   10388                 :       43387 :   TREE_TYPE (res) = type;
   10389                 :       43387 :   return res;
   10390                 :       44047 : }
   10391                 :             : 
   10392                 :             : /* Implementation of the two-argument braced_lists_to_string withe
   10393                 :             :    the same arguments plus MEMBER which is set for struct members
   10394                 :             :    to allow initializers for flexible member arrays.  */
   10395                 :             : 
   10396                 :             : static tree
   10397                 :   173493415 : braced_lists_to_strings (tree type, tree ctor, bool member)
   10398                 :             : {
   10399                 :   173493415 :   if (TREE_CODE (ctor) != CONSTRUCTOR)
   10400                 :             :     return ctor;
   10401                 :             : 
   10402                 :     4995688 :   tree_code code = TREE_CODE (type);
   10403                 :             : 
   10404                 :     4995688 :   tree ttp;
   10405                 :     4995688 :   if (code == ARRAY_TYPE)
   10406                 :      199650 :     ttp = TREE_TYPE (type);
   10407                 :     4796038 :   else if (code == RECORD_TYPE)
   10408                 :             :     {
   10409                 :     4751328 :       ttp = TREE_TYPE (ctor);
   10410                 :     4751328 :       if (TREE_CODE (ttp) == ARRAY_TYPE)
   10411                 :             :         {
   10412                 :      214976 :           type = ttp;
   10413                 :      214976 :           ttp = TREE_TYPE (ttp);
   10414                 :             :         }
   10415                 :             :     }
   10416                 :             :   else
   10417                 :             :     return ctor;
   10418                 :             : 
   10419                 :     4949090 :   if ((TREE_CODE (ttp) == ARRAY_TYPE || TREE_CODE (ttp) == INTEGER_TYPE)
   10420                 :     5219445 :       && TYPE_STRING_FLAG (ttp))
   10421                 :       44211 :     return braced_list_to_string (type, ctor, member);
   10422                 :             : 
   10423                 :     4906767 :   code = TREE_CODE (ttp);
   10424                 :     4906767 :   if (code == ARRAY_TYPE || RECORD_OR_UNION_TYPE_P (ttp))
   10425                 :             :     {
   10426                 :     4588451 :       bool rec = RECORD_OR_UNION_TYPE_P (ttp);
   10427                 :             : 
   10428                 :             :       /* Handle array of arrays or struct member initializers.  */
   10429                 :     4588451 :       tree val;
   10430                 :     4588451 :       unsigned HOST_WIDE_INT idx;
   10431                 :    14973608 :       FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), idx, val)
   10432                 :             :         {
   10433                 :    10385157 :           val = braced_lists_to_strings (ttp, val, rec);
   10434                 :    10385157 :           CONSTRUCTOR_ELT (ctor, idx)->value = val;
   10435                 :             :         }
   10436                 :             :     }
   10437                 :             : 
   10438                 :             :   return ctor;
   10439                 :             : }
   10440                 :             : 
   10441                 :             : /* Attempt to convert a CTOR containing braced array initializer lists
   10442                 :             :    for array TYPE into one containing STRING_CSTs, for convenience and
   10443                 :             :    efficiency.  Recurse for arrays of arrays and member initializers.
   10444                 :             :    Return the converted CTOR or STRING_CST on success or the original
   10445                 :             :    CTOR otherwise.  */
   10446                 :             : 
   10447                 :             : tree
   10448                 :   163108258 : braced_lists_to_strings (tree type, tree ctor)
   10449                 :             : {
   10450                 :   163108258 :   return braced_lists_to_strings (type, ctor, false);
   10451                 :             : }
   10452                 :             : 
   10453                 :             : 
   10454                 :             : /* Emit debug for functions before finalizing early debug.  */
   10455                 :             : 
   10456                 :             : void
   10457                 :      177072 : c_common_finalize_early_debug (void)
   10458                 :             : {
   10459                 :             :   /* Emit early debug for reachable functions, and by consequence,
   10460                 :             :      locally scoped symbols.  Also emit debug for extern declared
   10461                 :             :      functions that are still reachable at this point.  */
   10462                 :      177072 :   struct cgraph_node *cnode;
   10463                 :     8392510 :   FOR_EACH_FUNCTION (cnode)
   10464                 :     3651644 :     if (!cnode->alias && !cnode->thunk
   10465                 :     7667774 :         && (cnode->has_gimple_body_p ()
   10466                 :     1267913 :             || !DECL_IS_UNDECLARED_BUILTIN (cnode->decl)))
   10467                 :     3436506 :       (*debug_hooks->early_global_decl) (cnode->decl);
   10468                 :      177072 : }
   10469                 :             : 
   10470                 :             : /* Determine whether TYPE is an ISO C99 flexible array member type "[]".  */
   10471                 :             : bool
   10472                 :     7512325 : c_flexible_array_member_type_p (const_tree type)
   10473                 :             : {
   10474                 :     7512325 :   if (TREE_CODE (type) == ARRAY_TYPE
   10475                 :     2663014 :       && TYPE_SIZE (type) == NULL_TREE
   10476                 :      324466 :       && TYPE_DOMAIN (type) != NULL_TREE
   10477                 :     7836791 :       && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE)
   10478                 :      324466 :     return true;
   10479                 :             : 
   10480                 :             :   return false;
   10481                 :             : }
   10482                 :             : 
   10483                 :             : /* Get the LEVEL of the strict_flex_array for the ARRAY_FIELD based on the
   10484                 :             :    values of attribute strict_flex_array and the flag_strict_flex_arrays.  */
   10485                 :             : unsigned int
   10486                 :      537747 : c_strict_flex_array_level_of (tree array_field)
   10487                 :             : {
   10488                 :      537747 :   gcc_assert (TREE_CODE (array_field) == FIELD_DECL);
   10489                 :      537747 :   unsigned int strict_flex_array_level = flag_strict_flex_arrays;
   10490                 :             : 
   10491                 :      537747 :   tree attr_strict_flex_array
   10492                 :      537747 :     = lookup_attribute ("strict_flex_array", DECL_ATTRIBUTES (array_field));
   10493                 :             :   /* If there is a strict_flex_array attribute attached to the field,
   10494                 :             :      override the flag_strict_flex_arrays.  */
   10495                 :      537747 :   if (attr_strict_flex_array)
   10496                 :             :     {
   10497                 :             :       /* Get the value of the level first from the attribute.  */
   10498                 :           6 :       unsigned HOST_WIDE_INT attr_strict_flex_array_level = 0;
   10499                 :           6 :       gcc_assert (TREE_VALUE (attr_strict_flex_array) != NULL_TREE);
   10500                 :           6 :       attr_strict_flex_array = TREE_VALUE (attr_strict_flex_array);
   10501                 :           6 :       gcc_assert (TREE_VALUE (attr_strict_flex_array) != NULL_TREE);
   10502                 :           6 :       attr_strict_flex_array = TREE_VALUE (attr_strict_flex_array);
   10503                 :           6 :       gcc_assert (tree_fits_uhwi_p (attr_strict_flex_array));
   10504                 :           6 :       attr_strict_flex_array_level = tree_to_uhwi (attr_strict_flex_array);
   10505                 :             : 
   10506                 :             :       /* The attribute has higher priority than flag_struct_flex_array.  */
   10507                 :           6 :       strict_flex_array_level = attr_strict_flex_array_level;
   10508                 :             :     }
   10509                 :      537747 :   return strict_flex_array_level;
   10510                 :             : }
   10511                 :             : 
   10512                 :             : /* Map from identifiers to booleans.  Value is true for features, and
   10513                 :             :    false for extensions.  Used to implement __has_{feature,extension}.  */
   10514                 :             : 
   10515                 :             : using feature_map_t = hash_map <tree, bool>;
   10516                 :             : static feature_map_t *feature_map;
   10517                 :             : 
   10518                 :             : /* Register a feature for __has_{feature,extension}.  FEATURE_P is true
   10519                 :             :    if the feature identified by NAME is a feature (as opposed to an
   10520                 :             :    extension).  */
   10521                 :             : 
   10522                 :             : void
   10523                 :     1403181 : c_common_register_feature (const char *name, bool feature_p)
   10524                 :             : {
   10525                 :     1403181 :   bool dup = feature_map->put (get_identifier (name), feature_p);
   10526                 :     1403181 :   gcc_checking_assert (!dup);
   10527                 :     1403181 : }
   10528                 :             : 
   10529                 :             : /* Lazily initialize hash table for __has_{feature,extension},
   10530                 :             :    dispatching to the appropriate front end to register language-specific
   10531                 :             :    features.  */
   10532                 :             : 
   10533                 :             : static void
   10534                 :       45839 : init_has_feature ()
   10535                 :             : {
   10536                 :       45839 :   gcc_checking_assert (!feature_map);
   10537                 :       45839 :   feature_map = new feature_map_t;
   10538                 :             : 
   10539                 :      550068 :   for (unsigned i = 0; i < ARRAY_SIZE (has_feature_table); i++)
   10540                 :             :     {
   10541                 :      504229 :       const hf_feature_info *info = has_feature_table + i;
   10542                 :             : 
   10543                 :      504229 :       if ((info->flags & HF_FLAG_SANITIZE) && !(flag_sanitize & info->mask))
   10544                 :      228358 :         continue;
   10545                 :             : 
   10546                 :      275871 :       const bool feature_p = !(info->flags & HF_FLAG_EXT);
   10547                 :      275871 :       c_common_register_feature (info->ident, feature_p);
   10548                 :             :     }
   10549                 :             : 
   10550                 :             :   /* Register language-specific features.  */
   10551                 :       45839 :   c_family_register_lang_features ();
   10552                 :       45839 : }
   10553                 :             : 
   10554                 :             : /* If STRICT_P is true, evaluate __has_feature (IDENT).
   10555                 :             :    Otherwise, evaluate __has_extension (IDENT).  */
   10556                 :             : 
   10557                 :             : bool
   10558                 :      124441 : has_feature_p (const char *ident, bool strict_p)
   10559                 :             : {
   10560                 :      124441 :   if (!feature_map)
   10561                 :       45839 :     init_has_feature ();
   10562                 :             : 
   10563                 :      124441 :   tree name = canonicalize_attr_name (get_identifier (ident));
   10564                 :      124441 :   bool *feat_p = feature_map->get (name);
   10565                 :      124441 :   if (!feat_p)
   10566                 :             :     return false;
   10567                 :             : 
   10568                 :       71144 :   return !strict_p || *feat_p;
   10569                 :             : }
   10570                 :             : 
   10571                 :             : /* This is the slow path of c-common.h's c_hardbool_type_attr.  */
   10572                 :             : 
   10573                 :             : tree
   10574                 :       40675 : c_hardbool_type_attr_1 (tree type, tree *false_value, tree *true_value)
   10575                 :             : {
   10576                 :       40675 :   tree attr = lookup_attribute ("hardbool", TYPE_ATTRIBUTES (type));
   10577                 :       40675 :   if (!attr)
   10578                 :             :     return attr;
   10579                 :             : 
   10580                 :       11932 :   if (false_value)
   10581                 :        7729 :     *false_value = TREE_VALUE (TYPE_VALUES (type));
   10582                 :             : 
   10583                 :       11932 :   if (true_value)
   10584                 :        7729 :     *true_value = TREE_VALUE (TREE_CHAIN (TYPE_VALUES (type)));
   10585                 :             : 
   10586                 :             :   return attr;
   10587                 :             : }
   10588                 :             : 
   10589                 :             : #include "gt-c-family-c-common.h"
        

Generated by: LCOV version 2.1-beta

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